Prod.: Engine, ver.: 6, ID: 60000396, HowTo : Window select triangles of a groundsurface object

HowTo : Window select triangles of a groundsurface object

Article60000396
TypeHowTo
ProductEngine
Version6
Date Added1/22/2008
Submitted byGiorspyros Vissarion
Keywords

Subject

Window select triangles of a groundsurface object

Summary

How can I select/get some of the triangles with a window select of a vdGroundSurface object ?

Solution

In a new C# project add a vdFramedControl and add a code like :
        private void Form1_Load(object sender, EventArgs e)
        {
            vdFramedControl.CommandLine.CommandExecute += new VectorDraw.Professional.vdCommandLine.CommandExecuteEventHandler(CommandLine_CommandExecute);
        }

        void CommandLine_CommandExecute(string commandname, bool isDefaultImplemented, ref bool success)
        {
            if (isDefaultImplemented) return;
            if (string.Compare(commandname, "test", true) == 0)
            {

                success = true;
                vdDocument document = vdFramedControl.BaseControl.ActiveDocument;
                Box rectInViewCS = null;
                document.Prompt("Pick a window select");
                StatusCode sc = document.ActionUtility.getUserRectViewCS(null, out rectInViewCS);
                document.Prompt(null);
                if (sc != StatusCode.Success) return;
                gPoints pts = new gPoints();
                pts.Add(rectInViewCS.Min);
                pts.Add(rectInViewCS.Max);
                vdSelection set = new vdSelection();
                set.SetUnRegisterDocument(document);
                vdFilterObject filterselect = new vdFilterObject();
                filterselect.Types.AddItem("vdGroundSurface");
                set.Select(RenderSelect.SelectingMode.CrossingWindowRectangle,pts);
                set.ApplyFilter(filterselect);
                if (set.Count == 0) return;
                vdGroundSurface gsf = set[0] as vdGroundSurface;
                gTriangles triangles = gsf.Triangles;
                VectorDraw.Render.Region rgn = new VectorDraw.Render.Region(rectInViewCS);
                int trigid = 0;
                VectorDraw.Generics.vdArray trgiIds = new vdArray();
                gPoint p1, p2, p3;
                
                foreach (gTriangle trig in triangles)
                {
                    p1 = document.World2ViewMatrix.Transform(trig.P1);
                    p2 = document.World2ViewMatrix.Transform(trig.P2);
                    p3 = document.World2ViewMatrix.Transform(trig.P3);
                    if (rgn.IsLineInside(p1, p2) || rgn.IsLineIntersect(p1, p2)) trgiIds.AddItem(trigid);
                    trigid++;
                    if (rgn.IsLineInside(p2, p3) || rgn.IsLineIntersect(p2, p3)) trgiIds.AddItem(trigid);
                    trigid++;
                    if (rgn.IsLineInside(p3, p1) || rgn.IsLineIntersect(p3, p1)) trgiIds.AddItem(trigid);
                    trigid++;
                }

                //test geting triangles from trgiIds
                foreach (int var in trgiIds)
                {
                    gTriangle trig = triangles[(var + 1) / 3];
                    int trigline = var % 3;//0 is p1,p2  -   1 is p1,p2   -   2 = p3,p1
                }
            }
            
        }
You can load a drawing that has a complex Groundsurface object and then in the command prompt write "test" to run the code.