Page 1 of 1
Drawing arc over circular meter control
Posted: Fri May 11, 2012 8:29 am
by BobLivingston
Is it possible to draw an arc using script over a circular meter control?
I have a circular meter that I would like to have changing regions. I know the regions cannot change on the control itself, so I'd like to be able to draw a few arcs over the control that I can redraw based on tags. Is there some control I could use to draw the arc? Maybe the polyline control?
Re: Drawing arc over circular meter control
Posted: Fri May 11, 2012 10:19 am
by mark.monroe
Hi Bob,
I would recommend making the Circular control transparent and even turn off the scale. Then create a series of scales yourself in GIMP or some other photo editing application. You can then use the multipicture control to control which scale picture you use based on a tag value.
Another way would be for you to create little pictures that you could overlay onto the scale and then once again use the multipicture to change which one is shown based on a tag value. You could also change whether or not they are visible in the "Dynamics" group.
- Snap 2012-05-11 at 10.10.13.png (147.18 KiB) Viewed 10631 times
- Snap 2012-05-11 at 10.10.44.png (103.06 KiB) Viewed 10631 times
Re: Drawing arc over circular meter control
Posted: Fri May 11, 2012 10:32 am
by BobLivingston
I managed to find a way to display the range arc I wanted by tweaking a Polyline control when my range tags change.
sample code:
private void Update_KWrange(System.Object sender, System.EventArgs e)
{
const double Meter_Min = 0; // Smallest unit on meter
const double Meter_Range = 400; // Range of unit on meter
const double Meter_StartAngle = 230; // Start angle of meter
const double Meter_FullAngle = 280; // degrees between start and end angle of meter
const double Arc_Radius = 106; // radius of range arc
double KWmin = Globals.Tags.KW_Min.Value; // range min tag
double KWmax = Globals.Tags.KW_Max.Value; // range max tag
double Angle_Start, Angle_Range;
int Num_Steps;
// Calculate start angle and range of arc
Angle_Start = Meter_StartAngle - (KWmin - Meter_Min) / Meter_Range * Meter_FullAngle;
Angle_Range = (KWmax - KWmin) / Meter_Range * Meter_FullAngle;
Num_Steps = (int)(Math.Abs(Angle_Range * Arc_Radius / 90.0f) + 0.5f);
// Compute start angle and step rate for arc
Angle_Range = (Angle_Range * Math.PI) / (180.0f * ((double)Num_Steps)); // calculate range of steps (in radians)
Angle_Start *= Math.PI / 180.0f; // convert angle to radians
// The following assumes meter has a width/height of 290
PointD[] Points = new PointD[Num_Steps + 1];
for (int i = 0; ; i++)
{
Points = new PointD(
145.5f + Math.Cos(Angle_Start) * Arc_Radius, // X
145.5f - Math.Sin(Angle_Start) * Arc_Radius // Y
);
if (i >= Num_Steps) break;
Angle_Start -= Angle_Range; // move to the next point
}
// tweak polyline control
this.m_KWrange.Points = new Neo.ApplicationFramework.Common.Collections.PointDList(Points);
}
Re: Drawing arc over circular meter control
Posted: Mon May 14, 2012 1:02 pm
by BobLivingston
Does the Polyline control have an anti-aliasing option/setting?
Re: Drawing arc over circular meter control
Posted: Mon May 14, 2012 1:15 pm
by mark.monroe
Hi Bob,
No it does not have an anti-aliasing option.