Ejemplo n.º 1
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");
            }
        }
        /// <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);
        }
        /// <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();
            }
        }