Exemple #1
0
        /// <summary>
        /// Creates an extruded solid from wireframe.
        /// </summary>
        /// <param name="wireframe">The wireframe from which an extruded solid will be created.</param>
        /// <param name="length">The length of the extruded solid.</param>
        /// <param name="negLength">The negative length of the extruded solid.</param>
        /// <returns>The created solid.</returns>
        public PSSolidExtrusion CreateSolidExtrusionFromWireframe(PSWireframe wireframe, MM length, MM negLength)
        {
            // Add wireframe to selection
            _powerSHAPE.ActiveModel.ClearCreatedItems();
            wireframe.AddToSelection(true);

            // Extrude to make solid
            _powerSHAPE.DoCommand("CREATE SOLID EXTRUSION");

            // Get created solid
            PSSolidExtrusion createdSolid = null;

            try
            {
                createdSolid = (PSSolidExtrusion)_powerSHAPE.ActiveModel.CreatedItems[0];
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Failed to create solid extrusion");
            }

            // Edit length/negative length to be as required
            createdSolid.NegativeLength = negLength;
            createdSolid.Length         = length;

            // Return created solid
            Add(createdSolid);
            return(createdSolid);
        }
        /// <summary>
        /// Creates an extruded surface from wireframe.
        /// </summary>
        /// <param name="wireframe">The wireframe from which an extruded surface will be created.</param>
        /// <param name="length">The length of the extruded surface.</param>
        /// <param name="negLength">The negative length of the extruded surface.</param>
        /// <returns>The new surface.</returns>
        public PSSurface CreateExtrudedSurface(PSWireframe wireframe, Geometry.MM length, Geometry.MM negLength)
        {
            // Add wireframe to selection
            _powerSHAPE.ActiveModel.ClearCreatedItems();
            wireframe.AddToSelection(true);

            // Extrude to make solid
            _powerSHAPE.DoCommand("CREATE SURFACE EXTRUSION");

            // Get created surface
            PSSurface createdSurface = null;

            try
            {
                createdSurface = (PSSurface)_powerSHAPE.ActiveModel.CreatedItems[0];
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Failed to create surface extrusion");
            }

            // Edit length/negative length to be as required. Set NEGLENGTH initially in case the desired LENGTH is 0, as can't have
            // two lengths of 0 within the form
            _powerSHAPE.DoCommand("MODIFY", "NEGLENGTH " + negLength.ToString(), "LENGTH " + length.ToString(), "ACCEPT");

            // Return created solid
            Add(createdSurface);
            return(createdSurface);
        }
        /// <summary>
        /// Creates a revolved surface from a list of wireframe.
        /// </summary>
        /// <param name="rotationAxis">The axis around which to revolve the surface.</param>
        /// <param name="angleOfRevolution">The angle round which to revolve.</param>
        /// <param name="wireframe">The wireframe representing the profile of the surface.</param>
        /// <returns>A revolved surface.</returns>
        public PSSurfaceRevolution CreateRevolvedSurface(
            Axes rotationAxis,
            Geometry.Degree angleOfRevolution,
            PSWireframe wireframe)
        {
            // Set the principal plane
            _powerSHAPE.SetActivePlane(rotationAxis.AxisToPlane());

            // Select the wireframe
            wireframe.AddToSelection(true);

            // Create revolved surface
            _powerSHAPE.DoCommand("CREATE SURFACE REVOLUTION");

            // Check that surface has been created
            PSSurfaceRevolution createdSurface = null;

            if (_powerSHAPE.ActiveModel.SelectedItems.Count == 0)
            {
                throw new ApplicationException("No surface was created from the revolution");
            }
            createdSurface = (PSSurfaceRevolution)_powerSHAPE.ActiveModel.SelectedItems[0];

            // Change the revolution angle if required
            if (angleOfRevolution != 360)
            {
                createdSurface.Angle = angleOfRevolution;
            }

            return(createdSurface);
        }
        /// <summary>
        /// Creates a new compcurve from Wireframe
        /// </summary>
        /// <param name="wireframe">The wireframe to turn into a CompCurve (arc, compcurve, curve or line)</param>
        /// <returns>The CompCurve created from the wireframe</returns>
        public PSCompCurve CreateCompCurveFromWireframe(PSWireframe[] wireframe)
        {
            // Loop through wireframe
            List <PSWireframe> duplicatedWireframe = new List <PSWireframe>();

            foreach (PSWireframe entity in wireframe)
            {
                // Duplicate the arc as it will delete the original
                PSWireframe newWireframe = (PSWireframe)entity.Duplicate();
                duplicatedWireframe.Add(newWireframe);
            }

            // Add all to wireframe selection
            _powerSHAPE.ActiveModel.ClearSelectedItems();
            foreach (PSWireframe entity in wireframe)
            {
                entity.AddToSelection(false);
            }

            _powerSHAPE.DoCommand("CONVERT COMPCURVE");

            //Add the new CompCurve to the collection of CompCurves
            PSCompCurve compCurve = null;

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

            // Delete the duplicate arc from any lists
            foreach (PSWireframe entity in duplicatedWireframe)
            {
                entity.Delete();
            }

            return(compCurve);
        }