Prod.: Engine, ver.: 6, ID: 60000960, HowTo : How can I calculate and draw some entities after a user draw command

HowTo : How can I calculate and draw some entities after a user draw command

Article60000960
TypeHowTo
ProductEngine
Version6
Date Added9/16/2009
Submitted byJong Lee
Keywords

Subject

How can I calculate and draw some entities after a user draw command

Summary

How can I calculate and draw some entities after a user draw command ? For example I want to draw 2 lines that will represent the radius and the diameter of the circle that the user draw using an automatic command like cmdCircle.

Solution

cmdCircle  (and almost all command actions) returns a boolean if it was successful or not, so after cmdCircle returned true, you can get the last-added entity to the entities collection (that will be the circle your user drawn) and get the centerpoint and radius. With these values you can calculate two points and either add/draw a diameter dimension or a line.
 
For example see the code below (C# VS2005):

private void button2_Click(object sender, EventArgs e)
{
    VectorDraw.Professional.vdObjects.vdDocument doc = vdFramedControl1.BaseControl.ActiveDocument;
//ask the user to draw the circle
   
bool cir_success=doc.CommandAction.CmdCircle(null, null);
    if (cir_success)
    {
// cmdCircle is successful
       
VectorDraw.Professional.vdFigures.vdCircle circ = (VectorDraw.Professional.vdFigures.vdCircle) doc.ActiveLayOut.Entities[doc.ActiveLayOut.Entities.Count - 1];
        if (circ == null) return;
        VectorDraw.Geometry.gPoint pt_center = new VectorDraw.Geometry.gPoint(circ.Center);
// got the circle and its properties
       
double radius = circ.Radius;

        //calculate the points @ 45, 135 and 225 degrees
        VectorDraw.Geometry.gPoint pt_45 = pt_center.Polar(VectorDraw.Geometry.Globals.HALF_PI/2.0d, radius);
        VectorDraw.Geometry.gPoint pt_225 = pt_center.Polar(5.0d*VectorDraw.Geometry.Globals.HALF_PI/2.0d, radius);
        VectorDraw.Geometry.gPoint pt_135 = pt_center.Polar(3.0d * VectorDraw.Geometry.Globals.HALF_PI / 2.0d, radius);

       
// draw the lines
        VectorDraw.Professional.vdFigures.vdLine line = new VectorDraw.Professional.vdFigures.vdLine();
//diameter "blue" line
        line.SetUnRegisterDocument(doc);
        line.setDocumentDefaults();
        line.StartPoint = pt_45;
        line.EndPoint = pt_225;
        line.PenColor.FromSystemColor(Color.Blue);
        doc.ActiveLayOut.Entities.AddItem(line);
        line.Invalidate();

        line = new VectorDraw.Professional.vdFigures.vdLine();//radius "red" line
        line.SetUnRegisterDocument(doc);
        line.setDocumentDefaults();
        line.StartPoint = pt_center;
        line.EndPoint = pt_135;
        line.PenColor.FromSystemColor(Color.Red);
        doc.ActiveLayOut.Entities.AddItem(line);
        line.Invalidate();
    }
}