/// <summary>
        /// Persist the selected features.
        /// </summary>
        /// <remarks></remarks>
        public List <PSSurface> ExtractSelectedFeatures()
        {
            if (!_isToolCurrentlyActive)
            {
                throw new Exception("Tool has not been started.");
            }

            _powershape.DoCommand("Apply");

            // Process any new entities
            List <PSSurface> newEntities = new List <PSSurface>();

            if (_powershape.ActiveModel.CreatedItems.Count > 0)
            {
                foreach (PSSurface newEntity in _powershape.ActiveModel.CreatedItems)
                {
                    newEntity.Id = _powershape.ReadIntValue(newEntity.Identifier + "['" + newEntity.Name + "'].ID");
                    _powershape.ActiveModel.Add(newEntity);
                    newEntities.Add(newEntity);
                }
                _powershape.ActiveModel.ClearCreatedItems();
            }

            return(newEntities);
        }
        /// <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);
        }
示例#4
0
        /// <summary>
        /// Connects to PowerSHAPE and a specific entity using its name
        /// </summary>
        internal PSLateral(PSAutomation powerSHAPE, string name, PSSurface surface) : base(powerSHAPE, surface)
        {
            _powerSHAPE = powerSHAPE;
            _name       = name;
            _surface    = surface;

            _id         = _powerSHAPE.ReadIntValue(Identifier + "[" + name + "].ID");
            _internalId = Guid.NewGuid();
        }
        /// <summary>
        /// Return the last generated surface.
        /// </summary>
        /// <returns>The last surface that was generated from the mesh.</returns>
        public PSSurface Extract()
        {
            if (!_isToolCurrentlyActive)
            {
                throw new Exception("Tool has not been started.");
            }

            _powershape.DoCommand("Apply");

            // Process any new entities
            PSSurface newEntity = null;

            if (_powershape.ActiveModel.CreatedItems.Count == 1)
            {
                newEntity    = (PSSurface)_powershape.ActiveModel.CreatedItems[0];
                newEntity.Id = _powershape.ReadIntValue(newEntity.Identifier + "['" + newEntity.Name + "'].ID");
            }

            return(newEntity);
        }
        /// <summary>
        /// This constructor connects to PowerSHAPE
        /// </summary>
        internal PSpCurve(PSAutomation powerSHAPE, PSSurface surface, string name) : base(powerSHAPE)
        {
            _powerSHAPE = powerSHAPE;
            _surface    = surface;

            // A pCurve can't be evaluated in PowerSHAPE using its ID, so the ID is set from its name
            _name = name;
            _id   = _powerSHAPE.ReadIntValue(Identifier + "['" + name + "'].ID");

            // Because many properties of the pCurve are not available through the PowerSHAPE interface, a polyline
            // is created internally to emulate it
            _polyLine = new Polyline(Points);
        }
        /// <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>
        /// 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);
        }