TMSFMXLinearGauge with Carriage Box on needle

Hello,


I am trying to get a carriage box that follows the needle on the linear gauge that will display the needles value.  So I have a linear gauge that goes from 0 to 120, all of the hash marks are on the right side, and the needles follow the left side of the hash marks.  I need to know if there is a way I can grab the position of that needle as far as the x, y position coordinates or if I can directly attach a box to that needle.  Updating the text in the box wont be a problem as I can use livebindings.  I am just trying to find the best way to do this.

Any advice would be great.  Thank you.

Sean Mackey

Oh, I forgot to mention that I am using C++ Builder XE8 with the TMS Instruments for FireMonkey Addon.  The Linear Gauges are working fine.  I just want to make sure there is no noticeable lag between the needle and the carriage box.  This needs to look fluid as it is for a mechanical engineering project.  THanks again.


Sean Mackey

Hi, 


You can get the needle with TMSFMXLinearGauge1->GetNeedle() in the OnApplyStyleLookup.
The needle is a control, and thus, the position property can be used to determine it's location.
You could create a carriage box and insert it as a child of the needle, or update the position of the carriagebox needle value when the OnValueChanging event is called.

Kind Regards, 
Pieter

Thank you very much Pieter.  You have been a great help multiple times.  I will let you know if I have any more issues or this does not work as planned.


Thanks again.

Sean M.

Also, when you say insert it as a child of the needle, how do you do that?  In the design view I just see Extra Needles, Sections, and Set Points.   When I drag my rectangle box in there, I can't really make it a child element of any of those things.


Thanks again.

Hi, 


The rectangle box needs to be a firemonkey object and can be added as a child of the needle object that is returned when calling the GetNeedle method. Doing so, will automatically move the box, but it could be possible that you will experience issues with clipping. Alternatively, you could simply add the rectangle box as a child of the TTMSFMXLinearGauge instead of the needle object and manually change the position of the box in the OnValueChanging event. The position of the box can be set to the position of the needle, minus the height of the rectangle box. If you are having troubles implementing this technique, let me know and I will take a look at preparing some sample code to achieve this.

Kind Regards, 
Pieter 

Pieter Scheldeman2015-09-30 16:01:21

Hi Pieter,


Thanks again.  I will post my findings and how I get everything working.  Is there a section on the site that allows people to post code/examples?  I would love to share this with others when I get it finished, at least the methodology on how I got it working.  The linear gauge is a great add-on if I can get it working the way we need too.

Regards,

Sean M.

And as I am new to the TMS addons, sample code would always be great to have.   Thanks again Pieter.  We are currently looking into buying other addons we may need as well if we can get these working

You are welcome to share the complete sample, we will add it to the tips page (http://tmssoftware.com/site/tmsfmxpack.asp?s=faq) and include it in our knowledge base news letter.


Here is a sample in C++ to start with:

TForm1 *Form1;
TRectangle *r;
TText t;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  r = new TRectangle(TMSFMXLinearGauge1);
  t = new TText(r);
  t->Parent = r;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TMSFMXLinearGauge1ApplyStyleLookup(TObject *Sender)
{
TMSFMXLinearGauge1->GetOuterElement()->ClipChildren = False;
TTMSFMXNeedleShape *n = TMSFMXLinearGauge1->GetNeedle();
r->Parent = n;
r->Position->Y = -r->Height;
r->Position->X = - r->Width / 2 + n->Width / 2;
t->Text = FloatToStr(TMSFMXLinearGauge1->Value);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TMSFMXLinearGauge1ValueChanging(TObject *Sender, float Value)
{
  TTMSFMXNeedleShape *n = TMSFMXLinearGauge1->GetNeedle();
  if (r && t && n) {
t->Text = FloatToStr(TMSFMXLinearGauge1->Value);
this->Invalidate();
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TMSFMXLinearGauge1->Value = Random(100);
}

Kind Regards, 
Pieter

Pieter Scheldeman2015-09-30 16:36:06

Thank you much for this Pieter.  I will let you know how it goes!

This seems to be working good, but I need the carriage box to be on the opposite side of the needle.  The linear gauge is vertical, with the hash marks on the right edge, and the needle to the left of the hash marks.  I need the carriage box to be on the left of the needle.  I keep getting an out of range error when I try to adjust.  Can you advise?


Thanks,

Sean M

Also, another train of though when you get back to me.  Since the LinearGauge is vertical, the text that is being applied to the Rectangle is backwards.  When I adjust the scale of the text to -1 to flip it around, the positioning gets way off of the Rectangle.  Also, when I change the size of the rectangle, the text gets way off center.  If I try to rotate the Rectangle instead of the text, then the position requirements seem to get messed up, like the center point just flys out the window.


Other than that, I think this is working good.   I just need to figure out the best way to get this text reading the right way and stay centered within the Rectangle.  Thanks again for your help!

Here is what my code looks like:

void __fastcall TCentralGaugeFrame::TMSFMXLinearGauge2ApplyStyleLookup(TObject *Sender)

{
TMSFMXLinearGauge2->GetOuterElement()->ClipChildren = False;
TTMSFMXNeedleShape *n = TMSFMXLinearGauge2->GetNeedle();
r->Parent = n;
r->Height = 33;
r->Width = 25;
    r->Fill->Color = TAlphaColor(claWhite);
r->Position->Y = -r->Height + 45;
r->Position->X = - r->Width / 2 + n->Width / 2;
t->Text = FloatToStr(TMSFMXLinearGauge2->Value);
}
//---------------------------------------------------------------------------

I have tried adding t->Scale->Y = -1 to flip the text, but the positioning off the box gets messed up.  If I could lock the text center into the rectangle without having to adjust much else, that would be great.

Hi, 


To set it centered, you could simply apply TAlignLayout.Center to the Align property of the text.
This should also solve the flipping issue.

Kind Regards, 

Pieter