Prod.: Engine, ver.: 6, ID: 60001213, HowTo : Usage of ActionEntity for Text Arc Ellipse and Dimension objects

HowTo : Usage of ActionEntity for Text Arc Ellipse and Dimension objects

Article60001213
TypeHowTo
ProductEngine
Version6
Date Added9/2/2010
Submitted byMoti Kumar
Keywords

Subject

Usage of ActionEntity for Text Arc Ellipse and Dimension objects

Summary

Usage of ActionEntity for Text Arc Ellipse and Dimension objects

Solution

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using VectorDraw.Professional.vdObjects;
using VectorDraw.Professional.vdFigures;
using VectorDraw.Professional.vdPrimaries;
using VectorDraw.Generics;
using VectorDraw.Geometry;
using VectorDraw.Professional.vdCollections;
using VectorDraw.Actions;
using VectorDraw.Render;
using VectorDraw.Professional.Actions;
using VectorDraw.Serialize;

namespace vdtest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private vdDocument doc { get { return vdFramedControl1.BaseControl.ActiveDocument; } }

        private void CmdText_Click(object sender, EventArgs e)
        {
            #region example of prompt the user to type a text on VectorDraw screen
            doc.Prompt("Text Insertion Point:");
            gPoint pt = doc.ActionUtility.getUserPoint() as gPoint;
            doc.Prompt(null);
            if (pt == null) return;

            VectorDraw.Professional.CommandActions.ActionText aFig = new VectorDraw.Professional.CommandActions.ActionText(pt, 0.0d, doc.ActionLayout);
            doc.Prompt("Text string:");
            doc.ActionAdd(aFig);
            StatusCode scode = aFig.WaitToFinish();
            doc.Prompt(null);
            if (scode != StatusCode.Success) return;
            string text = aFig.Value as string;
            if (text == null) return;

            vdText vdtext = new vdText();
            vdtext.SetUnRegisterDocument(doc);
            vdtext.setDocumentDefaults();
            vdtext.InsertionPoint = pt;
            vdtext.Rotation = 0.0d;
            vdtext.TextString = text;
            vdtext.Transformby(doc.User2WorldMatrix);
            doc.ActionLayout.Entities.AddItem(vdtext);
            doc.ActionDrawFigure(vdtext);

            #endregion

        }

        private void CmdArc_Click(object sender, EventArgs e)
        {
            #region example of prompt the user to select arc properties  on VectorDraw screen
            doc.Prompt("Arc center Point:");
            gPoint arccen = doc.ActionUtility.getUserPoint() as gPoint;
            doc.Prompt(null);
            if (arccen == null) return;

            doc.Prompt("Arc radius:");
            object arcrad = doc.ActionUtility.getUserDist(arccen);
            doc.Prompt(null);
            if (arcrad == null) return;

            doc.Prompt("Arc StartAngle:");
            object arcSangle = doc.ActionUtility.getUserAngle(arccen);
            doc.Prompt(null);
            if (arcSangle == null) return;

            doc.Prompt("Arc EndAngle:");
            object arcEAngle = doc.ActionUtility.getUserActionEntity(new VectorDraw.Professional.CommandActions.ActionArc(arccen, (double)arcrad, (double)arcSangle, doc.ActionLayout));
            doc.Prompt(null);
            if (arcEAngle == null) return;

            vdArc vdarc = new vdArc();
            vdarc.SetUnRegisterDocument(doc);
            vdarc.setDocumentDefaults();
            vdarc.Center = arccen;
            vdarc.Radius = (double)arcrad;
            vdarc.StartAngle = (double)arcSangle;
            vdarc.EndAngle = (double)arcEAngle;
            vdarc.Transformby(doc.User2WorldMatrix);
            doc.ActionLayout.Entities.AddItem(vdarc);
            doc.ActionDrawFigure(vdarc);

            #endregion

        }

        private void CmdEllipse_Click(object sender, EventArgs e)
        {
            #region example of prompt the user to select ellipse properties  on VectorDraw screen
            doc.Prompt("Ellipse Center Point:");
            gPoint ellCen = doc.ActionUtility.getUserPoint() as gPoint;
            doc.Prompt(null);
            if (ellCen == null) return;


            doc.Prompt("Ellipse First Axis End Point:");
            gPoint ellAxis1End = doc.ActionUtility.getUserRefPoint(ellCen as gPoint) as gPoint;
            doc.Prompt(null);
            if (ellAxis1End == null) return;

            doc.Prompt("Ellipse Second Axis Distance:");
            object ellMajorLen = doc.ActionUtility.getUserActionEntity(new VectorDraw.Professional.CommandActions.ActionEllipse(ellCen, ellAxis1End, doc.ActionLayout));
            doc.Prompt(null);
            if (ellMajorLen == null) return;
            vdEllipse ell = new vdEllipse();
            ell.SetUnRegisterDocument(doc);
            ell.setDocumentDefaults();
            ell.Center = ellCen;
            ell.MajorAngle = VectorDraw.Geometry.Globals.GetAngle(ellCen, ellAxis1End);
            ell.MajorLength = VectorDraw.Geometry.gPoint.Distance3D(ellCen, ellAxis1End);
            ell.MinorLength = (double)ellMajorLen;
            ell.Transformby(doc.User2WorldMatrix);
            doc.ActionLayout.Entities.AddItem(ell);
            doc.ActionDrawFigure(ell);
            #endregion

        }

        private void CmdDim_Click(object sender, EventArgs e)
        {
            #region example of prompt the user to select aligned dimension  on VectorDraw screen
            doc.Prompt("Dimension First Point:");
            gPoint dimPt1 = doc.ActionUtility.getUserPoint() as gPoint;
            doc.Prompt(null);
            if (dimPt1 == null) return;

            doc.Prompt("Dimension Second Point:");
            gPoint dimPt2 = doc.ActionUtility.getUserRefPoint(dimPt1) as gPoint;
            doc.Prompt(null);
            if (dimPt2 == null) return;

            doc.Prompt("Dimension Location:");
            gPoint dimPt3 = doc.ActionUtility.getUserActionEntity(new VectorDraw.Professional.CommandActions.ActionDimension(VectorDraw.Professional.Constants.VdConstDimType.dim_Aligned, dimPt1, dimPt2, dimPt2, 0.0d, doc.ActionLayout)) as gPoint;
            doc.Prompt(null);
            if (dimPt3 == null) return;

            vdDimension dim = new vdDimension();
            dim.SetUnRegisterDocument(doc);
            dim.setDocumentDefaults();
            dim.dimType = VectorDraw.Professional.Constants.VdConstDimType.dim_Aligned;
            dim.DefPoint1 = dimPt1;
            dim.DefPoint2 = dimPt2;
            dim.LinePosition = dimPt3;
            dim.Transformby(doc.User2WorldMatrix);
            doc.ActionLayout.Entities.AddItem(dim);
            doc.ActionDrawFigure(dim);
            #endregion

        }
    }
}