/// <summary>
        /// Adds all entities on this level to the selection.
        /// </summary>
        /// <param name="keepPreviousSelection">If true keeps the previous selection in PowerShape.</param>
        public void AddContentsToSelection(bool keepPreviousSelection = false)
        {
            // Get current selection for restoration if required
            List <PSEntity> previouslySelected = new List <PSEntity>();

            if (keepPreviousSelection)
            {
                foreach (PSEntity selectedEntity in _powerSHAPE.ActiveModel.SelectedItems)
                {
                    previouslySelected.Add(selectedEntity);
                }
            }

            // Add entities to selection
            _powerSHAPE.DoCommand("FILTERBUTTON FILTERITEMS");
            _powerSHAPE.DoCommand("ALLTYPES", "ALLSTYLES", "ALLLEVELS", "INVERTLEVEL");
            _powerSHAPE.DoCommand("SELECTLEVEL " + Number, "ALL", "ACCEPT");
            _powerSHAPE.DoCommand("EVERYTHING PARTIALBOX");

            // Restore previous selection, if required
            foreach (PSEntity selectedEntity in previouslySelected)
            {
                selectedEntity.AddToSelection(false);
            }
        }
        /// <summary>
        /// Starts the Move operation.
        /// </summary>
        /// <param name="entitiesToMove">The group of entities that are to be moved.</param>
        /// <param name="copiesToCreate">The number of copies to create.</param>
        private static void SetupMove(List <IPSMoveable> entitiesToMove, int copiesToCreate)
        {
            // Get PowerSHAPE instance
            _powerSHAPE = ((PSEntity)entitiesToMove[0]).PowerSHAPE;

            // Add all IMovables
            ((PSEntity)entitiesToMove[0]).AddToSelection(true);
            int numberOfEntities = entitiesToMove.Count();

            for (int i = 1; i <= numberOfEntities - 1; i++)
            {
                ((PSEntity)entitiesToMove[i]).AddToSelection(false);
            }

            // Clear created items
            _powerSHAPE.ActiveModel.ClearCreatedItems();

            // Start move operation
            _powerSHAPE.DoCommand("EDIT MOVE");

            // Determine whether a copy is to be created
            if (copiesToCreate == 0)
            {
                _powerSHAPE.DoCommand("NOKEEP");
            }
            else
            {
                _powerSHAPE.DoCommand("KEEP");
                _powerSHAPE.DoCommand("COPIES " + copiesToCreate);
            }
        }
        /// <summary>
        /// This operation will cycle to the next solution for the last limit function. To accept call AcceptLimit.
        /// </summary>
        /// <param name="entityToLimit">The entity to limit.</param>
        /// <remarks></remarks>
        public static void NextSolution(IPSLimitable entityToLimit)
        {
            _powerSHAPE.DoCommand("NEXT SOLUTION");

            // Doing this changes the id but the name stays the same so get the new ID
            ((PSEntity)entityToLimit).Id =
                _powerSHAPE.ReadIntValue(((PSEntity)entityToLimit).Identifier + "['" + ((PSEntity)entityToLimit).Name +
                                         "'].ID");
        }
        /// <summary>
        /// Does not work as created.number is not updated.
        /// </summary>
        /// <param name="entityToLimit">The entity to limit.</param>
        /// <param name="keepOption">Keep option, by default KeepOne.</param>
        /// <returns>The limited entity.</returns>
        /// <remarks></remarks>
        internal static PSEntity LimitEntityUsingDynamicCutter(
            IPSLimitable entityToLimit,
            LimitingKeepOptions keepOption = LimitingKeepOptions.KeepOne)
        {
            // Get PowerSHAPE instance
            _powerSHAPE = ((PSEntity)entityToLimit).PowerSHAPE;

            // Create a list of the single entity
            PSEntity entity = (PSEntity)entityToLimit;

            _powerSHAPE.ActiveModel.ClearCreatedItems();

            entity.AddToSelection(true);

            _powerSHAPE.DoCommand("EDIT SELECTION");
            _powerSHAPE.DoCommand(keepOption.ToString());

            _powerSHAPE.DoCommand("Cutter_Dynamic On");

            bool    limitingHappened = false;
            PSModel model            = _powerSHAPE.ActiveModel;
            var     interval         = 1000;

            // Keep looping and picking points
            while (limitingHappened == false)
            {
                // Wait for a second to see if a limit has happened yet.  The item will no longer be selected when it has
                System.Threading.Thread.Sleep(interval);

                // See if the user finished creating the curve yet
                int selectedCount = 1;
                try
                {
                    selectedCount = _powerSHAPE.ReadIntValue("SELECTION.NUMBER");
                }
                catch
                {
                    selectedCount = 1;
                }
                if (selectedCount == 0)
                {
                    foreach (PSEntity newEntity in _powerSHAPE.ActiveModel.CreatedItems)
                    {
                        newEntity.Id = _powerSHAPE.ReadIntValue(newEntity.Identifier + "['" + newEntity.Name + "'].ID");
                        _powerSHAPE.ActiveModel.Add(newEntity);
                    }
                    limitingHappened = true;
                }
            }

            // When the limit happens we get a new entity with a new id but it has the same name as the original
            // So change the id of the entity we wanted to limit so things work as normal
            entity.Id = _powerSHAPE.ReadIntValue(entity.Identifier + "['" + entity.Name + "'].ID");

            return(entity);
        }
        /// <summary>
        /// Executes the next line in the macro and increments the index marker.
        /// </summary>
        /// <param name="hideDialogs">If true, hides any dialogs while running commands.</param>
        public override void RunStep(bool hideDialogs = true)
        {
            string command  = _lines[_localIndex];
            string trimLine = "";

            // Run the command
            _localIndex += 1;
            _totalIndex += 1;

            _executedCommands.Add(command);
            _powerSHAPE.DoCommand(command);
        }
 /// <summary>
 /// This constructor creates a new material in PowerSHAPE with the specified values.
 /// </summary>
 /// <param name="powerSHAPE">The PowerSHAPE Automation object.</param>
 /// <param name="name">The name of the material.</param>
 /// <param name="polish">The polish of the material.</param>
 /// <param name="emission">The emission of the material.</param>
 /// <param name="transparency">The transparency of the material.</param>
 /// <param name="reflectance">The reflectance of the material.</param>
 /// <param name="colourR">The red colour of the material.  Between 0 and 255.</param>
 /// <param name="colourG">The green colour of the material.  Between 0 and 255.</param>
 /// <param name="colourB">The blue colour of the material.  Between 0 and 255.</param>
 internal PSMaterial(
     PSAutomation powerSHAPE,
     string name,
     double polish,
     double emission,
     double transparency,
     double reflectance,
     byte colourR,
     byte colourG,
     byte colourB) : this(powerSHAPE, name)
 {
     _powerSHAPE.DoCommand("FORMAT MATERIALSTABLE",
                           "MODE WRITE",
                           "//-----------------------------------------------------------------------------",
                           "PRINT '" + name + "'",
                           "\"" + name + "\" \"Custom\" Create",
                           "POLISH " + polish / 100.0,
                           "EMISSION " + emission / 100.0,
                           "TRANSPARENCY " + transparency / 100.0,
                           "REFLECTANCE " + reflectance / 100.0,
                           "RED " + colourR / 255.0,
                           "GREEN " + colourG / 255.0,
                           "BLUE " + colourB / 255.0,
                           "SCALE 1.0",
                           "ACCEPT",
                           "MODE READ",
                           "RELOAD",
                           "ACCEPT");
 }
        /// <summary>
        /// Moves a group of entities by a specified relative amount.
        /// </summary>
        /// <param name="entitiesToMove">The group of entities that are to be moved.</param>
        /// <param name="moveVector">The relative amount by which each entity will be moved.</param>
        /// <param name="copiesToCreate">The number of copies that should be created by the operation.</param>
        /// <returns>A list containing any created copies of the original entities.  If copiesToCreate is 0, the operation returns an empty list.</returns>
        public static List <PSEntity> MoveEntitiesByVector(
            List <IPSMoveable> entitiesToMove,
            Geometry.Vector moveVector,
            int copiesToCreate)
        {
            SetupMove(entitiesToMove, copiesToCreate);

            // Carry out the process
            if (_powerSHAPE.Version >= new Version("11.2"))
            {
                _powerSHAPE.DoCommand("X " + moveVector.I.ToString(),
                                      "Y " + moveVector.J.ToString(),
                                      "Z " + moveVector.K.ToString());
                _powerSHAPE.DoCommand("APPLY", "DISMISS");
            }
            else
            {
                _powerSHAPE.DoCommand(moveVector.I.ToString() + " " + moveVector.J.ToString() + " " + moveVector.K.ToString());
                _powerSHAPE.DoCommand("CANCEL");
            }

            return(FinishMove());
        }
        /// <summary>
        /// Cuts a single entity at a defined point.
        /// </summary>
        /// <param name="entityToCut">The entity to cut.</param>
        /// <param name="pointAtWhichToCut">The point at which to cut the entity, which must lie on the entity.</param>
        /// <returns>A piece of the original entity.</returns>
        public static PSEntity CutEntity(PSEntity entityToCut, Geometry.Point pointAtWhichToCut)
        {
            // Get PowerSHAPE instance
            _powerSHAPE = entityToCut.PowerSHAPE;

            // Cut entity
            entityToCut.AddToSelection(true);
            _powerSHAPE.DoCommand("EDIT LIMIT CUTS");
            _powerSHAPE.DoCommand(pointAtWhichToCut.ToString());
            _powerSHAPE.DoCommand("EDIT LIMIT CUTS OFF");

            // Check that operation worked
            if (_powerSHAPE.ActiveModel.CreatedItems.Count == 0)
            {
                throw new ApplicationException("Cut operation did not function correctly");
            }

            // Get created entity
            PSEntity newEntity = _powerSHAPE.ActiveModel.CreatedItems[0];

            newEntity.Id = _powerSHAPE.ReadIntValue(newEntity.Identifier + "['" + newEntity.Name + "'].ID");
            _powerSHAPE.ActiveModel.Add(newEntity);
            return(newEntity);
        }
 /// <summary>
 /// Activates all Levels.
 /// </summary>
 public void ActivateAllLevels()
 {
     _powerSHAPE.DoCommand("LEVEL OPTIONS ACTIVATE_ALL");
 }
        /// <summary>
        /// Limits entities using a list of entities.
        /// </summary>
        /// <param name="entitiesToLimit">The entities on which to perform the limiting operation.</param>
        /// <param name="limitingEntities">The entities with which to perform the limiting operation.</param>
        /// <param name="limitingMode">The mode in which to carry out the operation.</param>
        /// <param name="keepOption">Whether to keep one or both sides of the limit.</param>
        /// <param name="trimOption">Whether to trim one or all of the entities.</param>
        internal static List <PSEntity> LimitEntities(
            List <IPSLimitable> entitiesToLimit,
            List <PSEntity> limitingEntities,
            LimitingModes limitingMode     = LimitingModes.LimitMode,
            LimitingKeepOptions keepOption = LimitingKeepOptions.KeepOne,
            LimitingTrimOptions trimOption = LimitingTrimOptions.LimitOne,
            bool finishOperation           = true)
        {
            // Get PowerSHAPE instance
            _powerSHAPE = ((PSEntity)entitiesToLimit[0]).PowerSHAPE;

            // Clear the selection
            _powerSHAPE.ActiveModel.ClearSelectedItems();

            // Select all the entities with which to do the limit
            foreach (PSEntity entity in limitingEntities)
            {
                entity.AddToSelection(false);
            }

            // Do the limit
            _powerSHAPE.DoCommand("EDIT SELECTION");
            _powerSHAPE.DoCommand(keepOption.ToString());
            if (trimOption == LimitingTrimOptions.LimitOne)
            {
                _powerSHAPE.DoCommand("TRIM ONE");
            }
            else
            {
                _powerSHAPE.DoCommand("TRIM BOTH");
            }
            switch (limitingMode)
            {
            case LimitingModes.LimitMode:
                _powerSHAPE.DoCommand("PROFILING LIMIT");
                break;

            case LimitingModes.ProjectMode:
                _powerSHAPE.DoCommand("PROFILING PROJECT");
                break;

            case LimitingModes.ProjectViewMode:
                _powerSHAPE.DoCommand("PROFILING PROJECT_VIEW");
                break;

            case LimitingModes.ProjectSurfaceNormalMode:
                _powerSHAPE.DoCommand("PROFILING MAKEPCU");
                break;

            case LimitingModes.IntersectCurveMode:
                _powerSHAPE.DoCommand("PROFILING SURFCURVEINT");
                break;
            }

            // Select all the entities on which to perform the limit
            foreach (PSEntity entity in entitiesToLimit)
            {
                entity.AddToSelection(false);
            }

            // Add any new entities to the list of entities
            List <PSEntity> newEntities = new List <PSEntity>();

            if (_powerSHAPE.ActiveModel.CreatedItems.Count == 0)
            {
                return(newEntities);
            }
            foreach (PSEntity newEntity in _powerSHAPE.ActiveModel.CreatedItems)
            {
                newEntity.Id = _powerSHAPE.ReadIntValue(newEntity.Identifier + "['" + newEntity.Name + "'].ID");
                _powerSHAPE.ActiveModel.Add(newEntity);
                newEntities.Add(newEntity);
            }

            //Ensure also updated entities are retrieved too when keep both is selected
            if (keepOption == LimitingKeepOptions.KeepBoth)
            {
                foreach (PSEntity itme in _powerSHAPE.ActiveModel.UpdatedItems)
                {
                    var updatedEntity = itme;
                    updatedEntity.Id = _powerSHAPE.ReadIntValue(updatedEntity.Identifier + "['" + updatedEntity.Name + "'].ID");
                    if (!newEntities.Exists(x => x.Id == updatedEntity.Id))
                    {
                        newEntities.Add(updatedEntity);
                    }
                }
            }

            // Finish operation
            if (finishOperation)
            {
                _powerSHAPE.DoCommand("EDIT SELECTION OFF");
            }

            // Doing this changes the ID of the new entities but the names stay the same so get the new IDs
            foreach (PSEntity limitedEntity in entitiesToLimit)
            {
                limitedEntity.Id = _powerSHAPE.ReadIntValue(limitedEntity.Identifier + "['" + limitedEntity.Name + "'].ID");
            }

            return(newEntities);
        }
        /// <summary>
        /// Offsets a group of entities by a specified distance.
        /// </summary>
        /// <param name="entitiesToOffset">The group of entities that are to be offset.</param>
        /// <param name="offsetDistance">The distance the entities are to be offset by.</param>
        /// <param name="copiesToCreate">The number of copies to create of the origina.l entities.</param>
        /// <returns>A list of entities created by the operation.  If numberOfCopies is 0, an empty list is returned.</returns>
        public static List <PSEntity> OffsetEntities(
            List <IPSOffsetable> entitiesToOffset,
            Geometry.MM offsetDistance,
            int copiesToCreate)
        {
            // Get PowerSHAPE instance
            _powerSHAPE = ((PSEntity)entitiesToOffset[0]).PowerSHAPE;

            // Add all IPSOffsetables
            ((PSEntity)entitiesToOffset[0]).AddToSelection(true);
            int numberOfEntities = entitiesToOffset.Count();

            for (int i = 1; i <= numberOfEntities - 1; i++)
            {
                ((PSEntity)entitiesToOffset[i]).AddToSelection(false);
            }

            // Carry out operation
            _powerSHAPE.DoCommand("EDIT OFFSET");

            // Determine whether a copy is to be created
            if (copiesToCreate == 0)
            {
                _powerSHAPE.DoCommand("NOKEEP");
            }
            else
            {
                _powerSHAPE.DoCommand("KEEP");
                _powerSHAPE.DoCommand("COPIES " + copiesToCreate);
            }

            // Enter offset distance
            _powerSHAPE.DoCommand("DISTANCE " + offsetDistance.ToString());
            _powerSHAPE.DoCommand("CANCEL");

            // If no copies were made, return an empty list
            if (copiesToCreate == 0)
            {
                // If any of the entities were meshes, curve, compcurve or arcs then we need to reassign the Ids
                var resultEntities = _powerSHAPE.ActiveModel.SelectedItems;
                foreach (PSEntity entity in entitiesToOffset)
                {
                    if (entity is PSMesh)
                    {
                        foreach (PSEntity newEntity in resultEntities)
                        {
                            if (newEntity is PSMesh && newEntity.Name == entity.Name)
                            {
                                entity.Id = newEntity.Id;
                                break; // TODO: might not be correct. Was : Exit For
                            }
                        }
                    }
                    if (entity is PSArc)
                    {
                        foreach (PSEntity newEntity in resultEntities)
                        {
                            if (newEntity is PSArc && newEntity.Name == entity.Name)
                            {
                                entity.Id = newEntity.Id;
                                break; // TODO: might not be correct. Was : Exit For
                            }
                        }
                    }
                    if (entity is PSCompCurve)
                    {
                        foreach (PSEntity newEntity in resultEntities)
                        {
                            if (newEntity is PSCompCurve && newEntity.Name == entity.Name)
                            {
                                entity.Id = newEntity.Id;
                                break; // TODO: might not be correct. Was : Exit For
                            }
                        }
                    }
                    if (entity is PSCurve)
                    {
                        foreach (PSEntity newEntity in resultEntities)
                        {
                            if (newEntity is PSCurve && newEntity.Name == entity.Name)
                            {
                                entity.Id = newEntity.Id;
                                break; // TODO: might not be correct. Was : Exit For
                            }
                        }
                    }
                }
                return(new List <PSEntity>());
            }

            // If copies were made, add them to their appropriate collections and return new entities
            List <PSEntity> copiedEntities = new List <PSEntity>();

            foreach (PSEntity copiedEntity in _powerSHAPE.ActiveModel.CreatedItems)
            {
                _powerSHAPE.ActiveModel.Add(copiedEntity);
                copiedEntities.Add(copiedEntity);
            }

            return(copiedEntities);
        }
示例#12
0
        private void CreateText(
            PSAutomation powerSHAPE,
            double height,
            string fontName,
            double pitch,
            TextOrigins textOrigin,
            TextJustifications textJustification,
            Point position,
            string text)
        {
            //Clear the list of CreatedItems
            _powerSHAPE.ActiveModel.ClearCreatedItems();

            //Set preferences to be able to introduce text by commands
            powerSHAPE.DoCommand("TOOLS PREFERENCES");
            powerSHAPE.DoCommand("UNITPREFS");
            powerSHAPE.DoCommand("TEXTPREFS");
            powerSHAPE.DoCommand("TEXT LIVETEXT OFF");
            powerSHAPE.DoCommand("ACCEPT");

            //Create the text
            powerSHAPE.SetActivePlane(Planes.XY);
            powerSHAPE.DoCommand("CREATE TEXT TEXT HORIZONTAL YES");
            powerSHAPE.DoCommand(string.Format("TEXT HEIGHT {0}", height));
            powerSHAPE.DoCommand(string.Format("TEXT FONT {0}", fontName));
            powerSHAPE.DoCommand(string.Format("TEXT PITCH {0}", pitch));
            powerSHAPE.DoCommand(string.Format("TEXT ORIGIN {0}", ConvertToString(textOrigin)));
            powerSHAPE.DoCommand(string.Format("TEXT JUSTIFICATION {0}", ConvertToString(textJustification)));
            powerSHAPE.DoCommand(string.Format("{0} {1} {2}", position.X, position.Y, position.Z));
            powerSHAPE.DoCommand(string.Format("ScrolledText {0}", text));
            powerSHAPE.DoCommand("ACCEPT");
        }
        /// <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>
        /// Mirrors entities about the specifed plane.
        /// </summary>
        /// <param name="entitiesToMirror">The entities that are to be mirrored.</param>
        /// <param name="mirrorPlane">The plane about which to mirror the entities.</param>
        /// <param name="mirrorPoint">The origin of the mirror plane.</param>
        public static void MirrorEntities(
            List <IPSMirrorable> entitiesToMirror,
            Planes mirrorPlane,
            Geometry.Point mirrorPoint)
        {
            // Get PowerSHAPE instance
            _powerSHAPE = ((PSEntity)entitiesToMirror[0]).PowerSHAPE;

            // Carry out operation
            // Create a temporary workplane (store the current workplane, to restore after mirror)
            PSWorkplane activeWP = _powerSHAPE.ActiveModel.ActiveWorkplane;

            _powerSHAPE.SetActivePlane(Planes.XY);

            // Ensures that the orientation of tempWP matches activeWP
            _powerSHAPE.ActiveModel.CreateTemporaryWorkplane(mirrorPoint);

            // Add all IPSMirrorables to selection
            ((PSEntity)entitiesToMirror[0]).AddToSelection(true);
            int numberOfEntities = entitiesToMirror.Count();

            for (int i = 0; i <= numberOfEntities - 1; i++)
            {
                ((PSEntity)entitiesToMirror[i]).AddToSelection(false);
            }

            // Clear updated items
            _powerSHAPE.ActiveModel.ClearUpdatedItems();

            // Mirror in this temporary workplane
            _powerSHAPE.DoCommand("EDIT MIRROR");
            _powerSHAPE.DoCommand("NOKEEP");

            _powerSHAPE.DoCommand(mirrorPlane.ToString());

            // This command is needed only for build 11 upward
            if (_powerSHAPE.Version >= new Version("11.2"))
            {
                _powerSHAPE.DoCommand("APPLY");
            }
            _powerSHAPE.DoCommand("CANCEL");

            int numberOfNonSolids = 0;

            for (int i = 0; i <= numberOfEntities - 1; i++)
            {
                if (!(entitiesToMirror[i] is PSSolid))
                {
                    numberOfNonSolids += 1;
                }
            }

            // Check that entities were mirrored, but only if non-solids were passed in, as powershape does not add altered solids to the updated set
            if (numberOfNonSolids > 0)
            {
                if (_powerSHAPE.ActiveModel.UpdatedItems.Count == 0)
                {
                    throw new ApplicationException("No entities were mirrored");
                }
                if (_powerSHAPE.ActiveModel.UpdatedItems.Count != numberOfNonSolids)
                {
                    throw new ApplicationException("Not all entities were mirrored");
                }
            }

            // Delete the temporary workplane that was created for the operation
            _powerSHAPE.ActiveModel.DeleteTemporaryWorkplane();

            // Restore the active workplane
            _powerSHAPE.ActiveModel.ActiveWorkplane = activeWP;
        }
        /// <summary>
        /// Rotates a group of entities by a specified angle around a specified axis.
        /// </summary>
        /// <param name="entitiesToRotate">The group of entities that are to be rotated.</param>
        /// <param name="rotationAxis">The axis around which the entities are to be rotated.</param>
        /// <param name="rotationAngle">The angle by which the entities are to be rotated.</param>
        /// <param name="copiesToCreate">The number of copies to create of the original entities.</param>
        /// <param name="rotationOrigin">The origin of the rotation axis.</param>
        /// <returns>A list of entities created by the operation.  If numberOfCopies is 0, an .empty list is returned.</returns>
        public static List <PSEntity> RotateEntities(
            List <IPSRotateable> entitiesToRotate,
            Axes rotationAxis,
            DG.Degree rotationAngle,
            int copiesToCreate,
            DG.Point rotationOrigin = null)
        {
            // Get PowerSHAPE instance
            _powerSHAPE = ((PSEntity)entitiesToRotate.First()).PowerSHAPE;

            // Add all IRotatables
            ((PSEntity)entitiesToRotate.First()).AddToSelection(true);
            int numberOfEntities = entitiesToRotate.Count();

            for (int i = 1; i <= numberOfEntities - 1; i++)
            {
                ((PSEntity)entitiesToRotate[i]).AddToSelection(false);
            }

            // Carry out operation
            _powerSHAPE.DoCommand("EDIT ROTATE");

            // Determine whether a copy is to be created
            if (copiesToCreate == 0)
            {
                _powerSHAPE.DoCommand("NOKEEP");
            }
            else
            {
                _powerSHAPE.DoCommand("KEEP");
                _powerSHAPE.DoCommand("COPIES " + copiesToCreate);
            }

            // If a different rotation origin has been defined, set it within PowerSHAPE
            if (rotationOrigin != null)
            {
                _powerSHAPE.DoCommand("AXIS");
                _powerSHAPE.DoCommand(rotationOrigin.ToString());
            }

            // Set the active plane, which determines the axis of rotation
            _powerSHAPE.SetActivePlane(rotationAxis.AxisToPlane());

            // Enter rotation angle
            _powerSHAPE.DoCommand("ANGLE " + rotationAngle);
            if (_powerSHAPE.Version >= new Version("11.2"))
            {
                _powerSHAPE.DoCommand("APPLY", "DISMISS");
            }
            else
            {
                _powerSHAPE.DoCommand("CANCEL");
            }

            // If no copies were made, return an empty list
            if (copiesToCreate == 0)
            {
                return(new List <PSEntity>());
            }

            // If copies were made, add them to their appropriate collections and return new entities
            List <PSEntity> copiedEntities = new List <PSEntity>();

            foreach (PSEntity copiedEntity in _powerSHAPE.ActiveModel.CreatedItems)
            {
                _powerSHAPE.ActiveModel.Add(copiedEntity);
                copiedEntities.Add(copiedEntity);
            }

            return(copiedEntities);
        }
示例#16
0
        /// <summary>
        /// Removes a material from the collection and from PowerShape.
        /// </summary>
        /// <param name="material">The material to remove.</param>
        public new bool Remove(PSMaterial material)
        {
            _powerSHAPE.DoCommand("FORMAT MATERIAL", "CUSTOM", "SELECT " + material.Name, "DELETE", "APPLY", "ACCEPT");

            return(base.Remove(material));
        }
        /// <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>
        /// 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");
            }
        }
        /// <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");
            }
        }
示例#20
0
        /// <summary>
        /// Lets you resize selected objects in a uniform manner, making them larger or smaller equally in all directions. You can also lock the scaling factor in any of the directions.
        /// </summary>
        /// <param name="entityToScale">The entity to scale.</param>
        /// <param name="scaleFactor">The scale value.</param>
        /// <param name="lockX">Locked in x if true.</param>
        /// <param name="lockY">Locked in y if true.</param>
        /// <param name="lockZ">Locked in z if true.</param>
        /// <param name="scaleOrigin">Objects are scaled relative to the scale origin.</param>
        /// <remarks></remarks>
        public static void ScaleUniform(
            IPSScalable entityToScale,
            double scaleFactor,
            bool lockX,
            bool lockY,
            bool lockZ,
            Geometry.Point scaleOrigin = null)
        {
            _powerSHAPE = ((PSEntity)entityToScale).PowerSHAPE;

            ((PSEntity)entityToScale).AddToSelection(true);

            _powerSHAPE.DoCommand("EDIT SCALE");

            _powerSHAPE.DoCommand("UNIFORM");

            _powerSHAPE.DoCommand("VALUE " + scaleFactor);

            if (lockX)
            {
                _powerSHAPE.DoCommand("LOCK X ON");
            }
            else
            {
                _powerSHAPE.DoCommand("LOCK X OFF");
            }
            if (lockY)
            {
                _powerSHAPE.DoCommand("LOCK Y ON");
            }
            else
            {
                _powerSHAPE.DoCommand("LOCK Y OFF");
            }
            if (lockZ)
            {
                _powerSHAPE.DoCommand("LOCK Z ON");
            }
            else
            {
                _powerSHAPE.DoCommand("LOCK Z OFF");
            }

            if (scaleOrigin != null)
            {
                _powerSHAPE.DoCommand("SCALEORIGIN");
                _powerSHAPE.DoCommand(scaleOrigin.ToString());
            }

            if (_powerSHAPE.Version.Major > 11)
            {
                _powerSHAPE.DoCommand("APPLY");
                _powerSHAPE.DoCommand("DISMISS");
            }
            else
            {
                _powerSHAPE.DoCommand("CANCEL");
            }
        }
示例#21
0
        /// <summary>
        /// Resizes surfaces and solids according to their volume as projected on to the active workplane.
        /// </summary>
        /// <param name="entityToScale">The entity to scale.</param>
        /// <param name="newVolume">The new projected volume.</param>
        /// <param name="lockX">Locked in x if true.</param>
        /// <param name="lockY">Locked in y if true.</param>
        /// <param name="lockZ">Locked in z if true.</param>
        /// <param name="scaleOrigin">Objects are scaled relative to the scale origin.</param>
        /// <remarks></remarks>
        public static void ScaleProjectedVolume(
            IPSScalable entityToScale,
            double newVolume,
            bool lockX,
            bool lockY,
            bool lockZ,
            Geometry.Point scaleOrigin = null)
        {
            _powerSHAPE = ((PSEntity)entityToScale).PowerSHAPE;

            ((PSEntity)entityToScale).AddToSelection(true);

            _powerSHAPE.DoCommand("EDIT SCALE");

            _powerSHAPE.DoCommand("UNIFORM");

            _powerSHAPE.DoCommand("VALUE " + newVolume);

            if (lockX)
            {
                _powerSHAPE.DoCommand("LOCK X ON");
            }
            else
            {
                _powerSHAPE.DoCommand("LOCK X OFF");
            }
            if (lockY)
            {
                _powerSHAPE.DoCommand("LOCK Y ON");
            }
            else
            {
                _powerSHAPE.DoCommand("LOCK Y OFF");
            }
            if (lockZ)
            {
                _powerSHAPE.DoCommand("LOCK Z ON");
            }
            else
            {
                _powerSHAPE.DoCommand("LOCK Z OFF");
            }

            if (scaleOrigin != null)
            {
                _powerSHAPE.DoCommand("SCALEORIGIN");
                _powerSHAPE.DoCommand(scaleOrigin.ToString());
            }

            _powerSHAPE.DoCommand("APPLY");
            _powerSHAPE.DoCommand("DISMISS");
        }