Пример #1
0
        /// <summary>
        /// Calls the parent surface's AddSurfaceCurveToSelection operation.
        /// </summary>
        /// <param name="emptySelectionFirst">Determines whether previous surface curve additions are to be disregarded.</param>
        public override void AddToSelection(bool emptySelectionFirst = false)
        {
            // Add surface to selection. If set to empty selection first, only need to add the
            // surface.  If adding surface curves to a selection already containing surface curves,
            // check that the surface is the only item selected
            if (emptySelectionFirst)
            {
                _surface.AddToSelection(true);
            }
            else
            {
                if ((_powerSHAPE.ActiveModel.SelectedItems.Contains(_surface) == false) |
                    (_powerSHAPE.ActiveModel.SelectedItems.Count != 1))
                {
                    _surface.AddToSelection(true);
                }
            }

            // Check that the surface curve exists
            if (Exists == false)
            {
                throw new ApplicationException("Surface curve does not exist");
            }

            // Add surface curve
            _powerSHAPE.DoCommand("SELECT_" + ShortType + "S " + _name);
        }
        /// <summary>
        /// This operation creates a new PSPoint at the point of intersection of a surface and a wireframe.
        /// Note that if the two do not intersect then a point will be created at the origin of the active workplane.
        /// The user should be sure that the surface and wireframe intersect before calling this function
        /// </summary>
        /// <param name="surface">The surface to create a point on where the wireframe intersects</param>
        /// <param name="wireframe">The wireframe that intersects the surface</param>
        /// <returns>The created PSPoint at the point of intersection</returns>
        public PSPoint CreatePointAtIntersectionOfSurfaceAndWireframe(PSSurface surface, PSWireframe wireframe)
        {
            _powerSHAPE.ActiveModel.ClearSelectedItems();
            _powerSHAPE.DoCommand("CREATE POINT SINGLE", "POSITION", "INTERSECT");
            wireframe.AddToSelection();
            surface.AddToSelection();
            _powerSHAPE.DoCommand("ACCEPT");

            PSPoint point = (PSPoint)_powerSHAPE.ActiveModel.SelectedItems[0];

            AddNoChecks(point);

            return(point);
        }
        /// <summary>
        /// Creates a new Mesh from a Surface
        /// </summary>
        /// <param name="surface">The Surface from which to create the mesh</param>
        /// <returns>Mesh created by operation</returns>
        public PSMesh CreateMeshFromSurface(PSSurface surface)
        {
            PSSurface newSurface = (PSSurface)surface.Duplicate();

            newSurface.AddToSelection(true);

            // Carry out operation
            _powerSHAPE.ActiveModel.ClearCreatedItems();
            _powerSHAPE.DoCommand("CONVERT MESH");

            // Add new Mesh to collection of Meshes
            PSMesh newMesh = (PSMesh)_powerSHAPE.ActiveModel.CreatedItems[0];

            _powerSHAPE.ActiveModel.Meshes.Add(newMesh);

            // Remove this Surface from the collection of surfaces
            newSurface.Delete();

            return(newMesh);
        }
Пример #4
0
        /// <summary>
        /// Projects the Point onto the specified surface
        /// </summary>
        /// <param name="surface">The surface onto which the Point is to be projected</param>
        /// <returns>A boolean indicating whether the proection was successful</returns>
        public bool ProjectPointOntoSurface(PSSurface surface)
        {
            // Get original point coordinates
            Point originalCoordinates = ToPoint();

            // Select point and surface
            AddToSelection(true);
            surface.AddToSelection(false);

            // Carry out projection
            _powerSHAPE.ActiveModel.ClearCreatedItems();
            _powerSHAPE.DoCommand("EDIT PROJECTPOINT");

            // Check whether projection occurred
            if (ToPoint() == originalCoordinates)
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Morphs surfaces between a control and reference surface.  Note that you can morph one surface if it is a PowerSurface but you
        /// must morph more than one surface if it is not a PowerSurface.  Also, the control and reference surfaces must have the same number
        /// of laterals and longitudinals
        /// </summary>
        /// <param name="surfacesToMorph">The surfaces to be morphed</param>
        /// <param name="referenceSurface">The reference surface</param>
        /// <param name="controlSurface"></param>
        /// <param name="decayDefinitionOption"></param>
        /// <param name="decayDefinitionBlend"></param>
        /// <param name="keepReferenceAndControlSurfaces"></param>
        /// <param name="normalOffsetting"></param>
        /// <param name="decaySelection"></param>
        /// <param name="decayLimit"></param>
        /// <param name="decayValue"></param>
        public static void MorphSurfacesBetweenTwoSurfaces(
            List <PSSurface> surfacesToMorph,
            PSSurface referenceSurface,
            PSSurface controlSurface,
            DecayDefinitionOptions decayDefinitionOption,
            DecayDefinitionBlend decayDefinitionBlend = DecayDefinitionBlend.Quartic,
            bool keepReferenceAndControlSurfaces      = false,
            bool normalOffsetting     = false,
            PSSurface decaySurface    = null,
            PSGenericCurve decayCurve = null,
            int decayLimit            = 100,
            double decayValue         = 0.5)
        {
            _powerSHAPE = referenceSurface.PowerSHAPE;
            var activeModel = _powerSHAPE.ActiveModel;

            activeModel.ClearSelectedItems();
            surfacesToMorph.ForEach(x => x.AddToSelection());

            _powerSHAPE.DoCommand("MORPH", "TWOSURFS", "REFERENCE ON");
            referenceSurface.AddToSelection();
            _powerSHAPE.DoCommand("CONTROL ON");
            controlSurface.AddToSelection();

            // Always keep the surfaces as they are only actually hidden from view but kept in the database. If
            // the user wants to lose them then we can delete them afterwards.
            _powerSHAPE.DoCommand("KEEP ON", "WRAP " + normalOffsetting.ToOnOff(), "DECAY " + decayDefinitionOption);

            if (decayDefinitionOption != DecayDefinitionOptions.None)
            {
                _powerSHAPE.DoCommand("BLEND " + decayDefinitionBlend);
                if (decayDefinitionOption == DecayDefinitionOptions.Distance)
                {
                    if (decayValue < 0.05)
                    {
                        decayValue = 0.05;
                    }
                    if (decayValue > 0.5)
                    {
                        decayValue = 0.5;
                    }
                    _powerSHAPE.DoCommand("LIMIT " + decayLimit, "HALFLIFE " + decayValue);
                }
                else
                {
                    _powerSHAPE.DoCommand("DECAYSELECT ON");
                    if (decaySurface != null)
                    {
                        decaySurface.AddToSelection();
                    }
                    if (decayCurve != null)
                    {
                        decayCurve.AddToSelection();
                    }
                }
            }

            _powerSHAPE.DoCommand("ACCEPT");

            // Delete the reference and control surfaces if chosen to
            if (keepReferenceAndControlSurfaces == false)
            {
                referenceSurface.Delete();
                controlSurface.Delete();
            }
        }
        /// <summary>
        /// Creates new curves and compcurves by projecting wireframe onto a surface
        /// </summary>
        /// <param name="surfaceToWrapTo">The surface that will have wireframe wrapped onto it</param>
        /// <param name="wireframeToWrap">The curves and compcurves that will be wrapped</param>
        /// <param name="rotation">The desired rotation or the wireframe before wrapping</param>
        /// <returns>A list of the created curves and compcurves</returns>
        public List <PSGenericCurve> CreateCurvesFromWrap(
            PSSurface surfaceToWrapTo,
            IEnumerable <PSGenericCurve> wireframeToWrap,
            Degree rotation)
        {
            // First page is to select the object to wrap to
            surfaceToWrapTo.AddToSelection(true);

            // Raise the dialog (but not really)
            _powerSHAPE.DoCommand("CREATE CURVE WRAPWIRE");

            // Next page
            _powerSHAPE.DoCommand("NEXT");

            // Select the items to wrap
            foreach (PSGenericCurve wireframe in wireframeToWrap)
            {
                wireframe.AddToSelection(false);
            }

            // Next page
            _powerSHAPE.DoCommand("NEXT");

            // Select workplane
            _powerSHAPE.DoCommand("SELECTWORKPLANE REFERENCE");

            // Next page
            _powerSHAPE.DoCommand("NEXT");

            // Select method
            _powerSHAPE.DoCommand("METHOD CHORD");

            // Next page
            _powerSHAPE.DoCommand("NEXT");

            // Select distortion
            _powerSHAPE.DoCommand("MINDISTORTION X_AXIS");

            // Next page
            _powerSHAPE.DoCommand("NEXT");

            // Set rotation angle
            _powerSHAPE.DoCommand("ROTATE " + rotation);

            // Next page
            _powerSHAPE.DoCommand("NEXT");

            // Next page
            _powerSHAPE.DoCommand("FINISH");

            // Get the list of everything selected
            List <PSGenericCurve> wrappedCurves = new List <PSGenericCurve>();

            foreach (PSGenericCurve wrappedCurve in _powerSHAPE.ActiveModel.SelectedItems)
            {
                wrappedCurves.Add(wrappedCurve);
            }

            // Need to find out if any workplanes got created and add them to the workplanes collection
            _powerSHAPE.DoCommand("SELECT WORKPLANES");
            int numberOfWorkplanes = _powerSHAPE.ActiveModel.SelectedItems.Count;

            for (int i = 0; i <= numberOfWorkplanes - 1; i++)
            {
                // Get new workplane
                PSWorkplane workplane = (PSWorkplane)_powerSHAPE.ActiveModel.SelectedItems[i];

                // The workplane is added to the active collection only if it is not already in there
                _powerSHAPE.ActiveModel.Workplanes.Add(workplane);
            }

            // Return the curves
            return(wrappedCurves);
        }