/// <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]);
        }
Exemple #2
0
        /// <summary>
        /// Creates a solid from a mesh.
        /// </summary>
        /// <param name="meshToConvert">The mesh to be converted to a solid.</param>
        /// <returns>The solid created from the mesh.</returns>
        public PSSolid CreateSolidFromMesh(PSMesh meshToConvert)
        {
            PSSolid createdSolid = new PSSolid(_powerSHAPE, meshToConvert);

            Add(createdSolid);

            // Return new solid
            return(createdSolid);
        }
        /// <summary>
        /// Initialises the new instance with the mesh to work with and the base instance to interact with PowerShape.
        /// The feature type to recognise is set to plane.
        /// </summary>
        /// <param name="mesh">The mesh to fit a surface to.</param>
        /// <remarks></remarks>
        public ManualFitSurfaceToMeshTool(PSMesh mesh)
        {
            _mesh                   = mesh;
            _powershape             = mesh.PowerSHAPE;
            _trianglePicker         = new PSMeshTrianglePicker(mesh);
            _featureTypeToRecognise = FeatureTypes.Plane;

            // Only chose this because Powershape defaults to Plane
        }
Exemple #4
0
        /// <summary>
        /// Creates a new Mesh from a DMT Model.
        /// </summary>
        /// <param name="powerSHAPE">This is the PowerSHAPE Automation object.</param>
        /// <param name="model">The DMT model from which to create the model.</param>
        internal PSMesh(PSAutomation powerSHAPE, DMTModel model) : base(powerSHAPE)
        {
            // Write the DMT to a temporary file
            FileSystem.File tempFile = FileSystem.File.CreateTemporaryFile("dmt");
            DMTModelWriter.WriteFile(model, tempFile);

            // Import the DMT into PowerSHAPE
            _powerSHAPE.DoCommand("FILE IMPORT '" + tempFile.Path + "'");

            // Delete the temporary file
            tempFile.Delete();

            PSMesh newMesh = (PSMesh)_powerSHAPE.ActiveModel.CreatedItems[0];

            // Set the Id
            _id = newMesh.Id;
        }
Exemple #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");
            }
        }
Exemple #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;
        }
        /// <summary>
        /// Creates CompCurves from an intersection between a surface and a mesh.
        /// </summary>
        /// <param name="surface">The surface to intersect.</param>
        /// <param name="mesh">The mesh to intersect.</param>
        /// <returns>The list of the created CompCurves.</returns>
        /// <remarks></remarks>
        public List <PSCompCurve> CreateCompCurvesFromIntersectionOfSurfaceAndMesh(PSSurface surface, PSMesh mesh)
        {
            // Create lists from individual surfaces
            List <PSEntity> firstList  = new List <PSEntity>();
            List <PSEntity> secondList = new List <PSEntity>();

            firstList.Add(surface);
            secondList.Add(mesh);

            // Carry out operation
            return(CreateCompCurvesFromIntersectionOfTwoSetsOfEntities(firstList, secondList));
        }
 /// <summary>
 /// Creates new instance.
 /// </summary>
 /// <param name="mesh">Initialises the mesh.</param>
 /// <param name="pickMode">Initialises the pick mode.</param>
 /// <remarks></remarks>
 public PSMeshTrianglePicker(PSMesh mesh, TrianglePickMode pickMode = TrianglePickMode.ContinuousLasso)
 {
     _mesh       = mesh;
     _powershape = mesh.PowerSHAPE;
     _pickMode   = pickMode;
 }
 /// <summary>
 /// Creates a new instance. Initialises the mesh and the base instance to interact with PowerShape.
 /// </summary>
 /// <param name="mesh">Initialises with the mesh used to create the surfaces.</param>
 /// <remarks></remarks>
 public AutomaticFitSurfacesToMeshTool(PSMesh mesh)
 {
     _mesh       = mesh;
     _powershape = mesh.PowerSHAPE;
 }