/// <summary>
        /// Creates a surface from triangles using the specified parameters
        /// </summary>
        /// <param name="mesh">The mesh from which to create the surface</param>
        /// <param name="pointsProportion">The points proportion. Defaults to 25.0</param>
        /// <param name="orientationAngle">The orientation angle of the surface.  Defaults to 0.0</param>
        /// <param name="numberOfPatches">The number of surface patches.  Defaults to 10</param>
        /// <returns>The created surface.</returns>
        /// <exception cref="Exception">Failed to create surface from Mesh.</exception>
        public PSSurface CreateSurfaceFromTriangles(
            PSMesh mesh,
            List <PSGenericCurve> boundariesAndIslands = null,
            double pointsProportion = 25.0,
            double orientationAngle = 0.0,
            int numberOfPatches     = 10)
        {
            mesh.AddToSelection(true);
            if (boundariesAndIslands != null)
            {
                boundariesAndIslands.ForEach(x => x.AddToSelection());
            }

            _powerSHAPE.DoCommand("CREATE SURFACE AUTOSURF",
                                  "METHOD FROMTRIANGLES",
                                  "ADVANCED",
                                  "SETPOINTS " + pointsProportion.ToString("0.######"),
                                  "SETPATCHES " + numberOfPatches,
                                  "SETANGLE " + orientationAngle.ToString("0.######"),
                                  "APPLY");
            var createdItems = _powerSHAPE.ActiveModel.CreatedItems;

            _powerSHAPE.DoCommand("ACCEPT", "ACCEPT");
            if (createdItems.Count != 1)
            {
                throw new Exception("Failed to create surface from Mesh");
            }

            return((PSSurface)createdItems[0]);
        }
        /// <summary>
        /// Starts the picking operation.
        /// </summary>
        /// <remarks></remarks>
        public void StartPicking()
        {
            _mesh.AddToSelection(true);
            switch (_pickMode)
            {
            case TrianglePickMode.Box:
                _powershape.DoCommand("BOX_SELECT_TRIS");
                break;

            case TrianglePickMode.ContinuousLasso:
                _powershape.DoCommand("LASSO_CONTINUOUS");
                break;

            case TrianglePickMode.DiscreteLasso:
                _powershape.DoCommand("LASSO_DISCRETE");
                break;

            case TrianglePickMode.ToDiscontinuityAngle:
                _powershape.DoCommand("AREA_TO_DISCONTINUITY");
                _powershape.DoCommand(string.Format("MSHVALUE SCALEVALUE {0}", _angle * (100.0 / 180.0)));
                break;

            case TrianglePickMode.ToHorizonAngle:
                _powershape.DoCommand("AREA_TO_LOCAL_HORIZON");
                _powershape.DoCommand(string.Format("MSHVALUE SCALEVALUE {0}", _angle * (100.0 / 180.0)));
                break;
            }

            _isToolCurrentlyPicking = true;
        }
        /// <summary>
        /// Start operation.
        /// </summary>
        /// <remarks></remarks>
        public void Start()
        {
            _mesh.AddToSelection(true);
            _powershape.DoCommand("Segmenter");
            _isToolCurrentlyActive = true;

            _powershape.DoCommand(string.Format("Similarity Sliderval {0}", _similarityAngle));
            _powershape.DoCommand(string.Format("Tolerance {0}", _tolerance));
            RecogniseTypes(_featureTypesToRecognise);
            if (_blankKeptFeatures)
            {
                _powershape.DoCommand("Blanking on");
            }
            else
            {
                _powershape.DoCommand("Blanking off");
            }
            if (_displayFeaturesAsTransparent)
            {
                _powershape.DoCommand("Transparency 1");
            }
            else
            {
                _powershape.DoCommand("Transparency 0");
            }
            if (_generateFeaturesAsSolids)
            {
                _powershape.DoCommand("MakeSolids yes");
            }
            else
            {
                _powershape.DoCommand("MakeSolids no");
            }
        }
        /// <summary>
        /// Starts manual segment mesh operation in PowerShape.
        /// </summary>
        /// <remarks></remarks>
        public void StartTool()
        {
            _mesh.AddToSelection(true);
            _powershape.DoCommand("Segmenter ManualSegment");
            _trianglePicker.StartPicking();
            _isToolCurrentlyActive = true;

            RecogniseType(_featureTypeToRecognise);
            if (_generateFeaturesAsSolids)
            {
                _powershape.DoCommand("MakeSolids yes");
            }
            else
            {
                _powershape.DoCommand("MakeSolids no");
            }
        }
Example #5
0
        /// <summary>
        /// Allows the user to select a hole on the mesh and fill it
        /// </summary>
        public void FillHole()
        {
            // Pick a point that will define where the hole is
            Point pickedPoint = _powerSHAPE.PickPoint();

            // Create a CompCurve around the hole
            _powerSHAPE.DoCommand("CREATE CURVE COMPCURVE");
            _powerSHAPE.DoCommand(pickedPoint.X.ToString() + " " + pickedPoint.Y.ToString() + " " + pickedPoint.Z.ToString());
            _powerSHAPE.DoCommand("FASTFORWARDS");
            _powerSHAPE.DoCommand("SAVE");

            PSCompCurve createdCompCurve = (PSCompCurve)_powerSHAPE.ActiveModel.CreatedItems[0];

            createdCompCurve.AddToSelection(true);

            // The curve must be closed for this to work
            if (createdCompCurve.IsClosed)
            {
                _powerSHAPE.DialogsOff();

                // Create a fillin surface from the curve
                PSSurface fillinSurface = _powerSHAPE.ActiveModel.Surfaces.CreateFillInSurface(createdCompCurve);
                PSMesh    fillinMesh    = _powerSHAPE.ActiveModel.Meshes.CreateMeshFromSurface(fillinSurface);
                fillinSurface.Delete();
                fillinMesh.AddToSelection(true);

                // Append the fillin mesh to this mesh
                Append(fillinMesh);

                // Delete the curve that was created
                createdCompCurve.Delete();

                _powerSHAPE.DialogsOn();
            }
            else
            {
                // Delete the curve that was created and throw an exception
                createdCompCurve.Delete();
                _powerSHAPE.DialogsOn();
                throw new Exception("Unable to create closed curve");
            }
        }
Example #6
0
        /// <summary>
        /// Appends the specified Mesh to this Mesh. It will leave a single
        /// Mesh, deleting the specified one.
        /// </summary>
        /// <param name="meshToAppend">The mesh to be appended to this mesh</param>
        public void Append(PSMesh meshToAppend)
        {
            // Append the two meshes
            AddToSelection(true);
            meshToAppend.AddToSelection();
            _powerSHAPE.DoCommand("TRIAPPEND");

            // This creates a brand new mesh (the original two are now deleted)
            // Remove the specified one from the list of meshes
            _powerSHAPE.ActiveModel.Meshes.Remove(meshToAppend);

            // Get the new one
            PSMesh objNewMesh = (PSMesh)_powerSHAPE.ActiveModel.SelectedItems[0];

            // This mesh is now deleted so put the new one into this one so it appears to the user
            // as though the mesh is the original one
            _id = objNewMesh.Id;

            // Set the name of the new mesh to be the name this one was before it got deleted
            objNewMesh.Name = _name;
        }