protected override void OnExecute(Command command, ExecutionContext context, Rectangle buttonRect)
        {
            /*
             * Provide dialogue box and user inputs what they want to locate
             * These selections are Tori, Small Holes or Small Volumes
             * For Small Volumes and Holes the user will need to input a value
             * Each will be handled seperately and find matching bodies in all part design bodies
             * All will be then added to a final selection list for the user
             */

            // Instance common functions class
            InstanceClasses.CommonSpaceClaimFunctions FunctionsClass = new InstanceClasses.CommonSpaceClaimFunctions();

            // Variables
            Window window = Window.ActiveWindow;

            window.SetTool(new ToolClass());
            Document           doc          = window.Document;
            Part               rootPart     = doc.MainPart;
            InteractionContext interContext = window.ActiveContext;

            List <IDesignBody>        selectionBodies  = new List <IDesignBody>();
            List <IDesignBody>        matchingBodies   = new List <IDesignBody>();
            List <Face>               facesList        = new List <Face>();
            List <IDesignFace>        iFacesList       = new List <IDesignFace>();
            List <IDesignFace>        ifinalFacesList  = new List <IDesignFace>();
            ICollection <IDesignFace> IcollectionFaces = null;

            double minradius;
            double minVolume;
            double minFace;

            bool findCone   = false;
            bool findTori   = false;
            bool findHoles  = false;
            bool findVolume = false;
            bool findFace   = false;

#pragma warning disable CS0219 // The variable 'faceCounter' is assigned but its value is never used
            int faceCounter = 0;
#pragma warning restore CS0219 // The variable 'faceCounter' is assigned but its value is never used


#pragma warning disable CS0219 // The variable 'intMode' is assigned but its value is never used
            InteractionMode intMode = InteractionMode.Solid;
#pragma warning restore CS0219 // The variable 'intMode' is assigned but its value is never used



            if (window == null)
            {
                return;
            }

            #region Dialogue

            // Create dialogue box
            using (var dialogue = new UI.BodySelectForm())
            {
                if (dialogue.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var nameAndRendering = new List <KeyValuePair <string, Graphic> >();
                var partToGraphic    = new Dictionary <Part, Graphic>();

                var style = new GraphicStyle
                {
                    EnableDepthBuffer = true
                };

                findCone   = dialogue.LocateCone;
                findTori   = dialogue.LocateTori;
                findHoles  = dialogue.LocateHoles;
                findVolume = dialogue.LocateVolume;
                findFace   = dialogue.LocateFace;

                minradius = dialogue.minRadius;
                minVolume = dialogue.minVolume;
                minFace   = dialogue.minFace;
            }

            #endregion

            // Gather all design bodies
            //-----------------------------------------------
            selectionBodies.AddRange(FunctionsClass.GatherAllVisibleBodies(rootPart, window));

            // Check if each body fits wanted criteria
            //-----------------------------------------------
            foreach (IDesignBody iDesBod in selectionBodies)
            {
                DesignBody master = iDesBod.Master;
                Body       body   = master.Shape;

                var faces = body.Faces;
                facesList.AddRange(faces);
                var iFaces = iDesBod.Faces;
                iFacesList.AddRange(iFaces);

                Matrix masterTrans  = iDesBod.TransformToMaster;
                Matrix reverseTrans = masterTrans.Inverse;

                // If body fits volume criteria
                //----------------------------------------
                if (findVolume && body.Volume * 1e6 < minVolume)
                {
                    matchingBodies.Add(iDesBod);
                }
                else
                {
                    // If body fits tori or hole criteria
                    //----------------------------------------
                    for (int i = 0; i < iFacesList.Count; i++)
                    {
                        IDesignFace face = iFacesList[i];

                        if (face.Area * 1e4 < minFace)
                        {
                            ifinalFacesList.Clear();
                            ifinalFacesList.Add(face);
                            window.ActiveTool.CreateIndicator(ifinalFacesList);
                        }

                        if (face.Shape.GetGeometry <Cone>() != null && findCone)
                        {
                            ifinalFacesList.Clear();
                            ifinalFacesList.Add(face);
                            window.ActiveTool.CreateIndicator(ifinalFacesList);
                        }

                        if (face.Shape.GetGeometry <Torus>() != null && findTori)
                        {
                            ifinalFacesList.Clear();
                            ifinalFacesList.Add(face);
                            window.ActiveTool.CreateIndicator(ifinalFacesList);
                        }
                        else if (face.Shape.GetGeometry <Cylinder>() != null && face.Shape.GetGeometry <Cylinder>().Radius * 1e2 < minradius && findHoles)
                        {
                            //FunctionsClass.ColourFace(facesList[i], master);
                            ifinalFacesList.Clear();
                            ifinalFacesList.Add(face);
                            window.ActiveTool.CreateIndicator(ifinalFacesList);
                            var radius = face.Shape.GetGeometry <Cylinder>().Radius;

                            /*
                             * if (IsHole(face, radius))
                             * {
                             *  ifinalFacesList.Clear();
                             *  ifinalFacesList.Add(face);
                             *  window.ActiveTool.CreateIndicator(ifinalFacesList);
                             * }
                             */
                        }
                        else
                        {
                            // Set all the other face to slightly translucent
                            //FunctionsClass.SetFacetranslucent(face, master);
                        }
                    }
                }

                facesList.Clear();
                iFacesList.Clear();
            }
            //ICollection<IDocObject> bodyCollection = null;

            // For each matching body change the colour to red
            //----------------------------------------------------
            foreach (IDesignBody finalBody in matchingBodies)
            {
                //bodyCollection.Add(finalBody);
                DesignBody finalMaster = finalBody.Master;
                finalMaster.SetColor(null, Color.Red);
            }
            var point = Point.Create(1, 1, 1);
            IcollectionFaces = ifinalFacesList;

            // Also set them as selected by the user
            //----------------------------------------------------
            //interContext.Selection = bodyCollection;
        }
Пример #2
0
        protected override void OnExecute(Command command, ExecutionContext context, Rectangle buttonRect)
        {
            /*
             * Max Surface Tool
             * A. Burns 06/11/2017
             * Read user inuput max surfaces per body
             * Hightlight body with greater number of faces
             * Optionally can chnage the bodies colour
             * as well as highlighting
             */



            // Instance common functions class
            InstanceClasses.CommonSpaceClaimFunctions FunctionsClass = new InstanceClasses.CommonSpaceClaimFunctions();

            // Essential Variables
            Window             window       = Window.ActiveWindow;
            Document           doc          = window.Document;
            Part               rootPart     = doc.MainPart;
            InteractionContext interContext = window.ActiveContext;

            // Other Variables
            List <IDesignBody> allBodies       = new List <IDesignBody>();
            List <IDesignFace> ifinalFacesList = new List <IDesignFace>();

            window.SetTool(new ToolClass());

            int    faceCount;
            int    maxFaces;
            bool   changeColours;
            string colourString;

            using (var dialogue = new UI.MaxSurfacesForm())
            {
                if (dialogue.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var nameAndRendering = new List <KeyValuePair <string, Graphic> >();
                var partToGraphic    = new Dictionary <Part, Graphic>();

                var style = new GraphicStyle
                {
                    EnableDepthBuffer = true
                };

                maxFaces      = (int)dialogue.MaxSurfaces;
                changeColours = dialogue.ChangeColour;
                colourString  = dialogue.ColourSelection;
            }

            if (window == null)
            {
                return;
            }

            allBodies.AddRange(FunctionsClass.GatherAllVisibleBodies(rootPart, window));


            foreach (IDesignBody iDesBody in allBodies)
            {
                DesignBody desBody = iDesBody.Master;
                Body       body    = desBody.Shape.Copy();

                var faces  = body.Faces;
                var iFaces = iDesBody.Faces;
                // ifinalFacesList.AddRange(iDesBody.Faces);
                faceCount = faces.Count;

                if (faceCount > maxFaces)
                {
                    window.ActiveTool.CreateIndicator(iFaces);
                    if (changeColours)
                    {
                        if (colourString == "Blue")
                        {
                            desBody.SetColor(null, Color.Blue);
                        }
                        else if (colourString == "Red")
                        {
                            desBody.SetColor(null, Color.Red);
                        }
                        else if (colourString == "Green")
                        {
                            desBody.SetColor(null, Color.Green);
                        }
                        else if (colourString == "Orange")
                        {
                            desBody.SetColor(null, Color.Orange);
                        }
                        else if (colourString == "Black")
                        {
                            desBody.SetColor(null, Color.Black);
                        }
                        else if (colourString == "Yellow")
                        {
                            desBody.SetColor(null, Color.Yellow);
                        }
                        else if (colourString == "Salmon Pink")
                        {
                            desBody.SetColor(null, Color.Salmon);
                        }
                    }
                }
            }
        }