/// <summary>
        /// Creates an Oblique curve against either a mesh, solid or surface.
        /// </summary>
        /// <param name="entityToOblique">The entity to be cut by the oblique curve.</param>
        /// <param name="UsePlane">Sets the principal plane.</param>
        /// <param name="position">Distance along plane to drop curve on.</param>
        /// <exception cref="ApplicationException">No curves were created from intersection operation.</exception>
        /// <exception cref="ApplicationException">Entity must be Mesh, Surface or Solid.</exception>
        /// <returns>List of CompCurves.</returns>
        public List <PSCompCurve> CreateObliqueCurve(PSEntity entityToOblique, Planes UsePlane, Geometry.MM position)
        {
            List <PSCompCurve> createdCurves = new List <PSCompCurve>();

            if (entityToOblique is PSMesh || entityToOblique is PSSolid || entityToOblique is PSSurface)
            {
                // Set the principal plane
                _powerSHAPE.SetActivePlane(UsePlane);
                entityToOblique.AddToSelection(true);
                _powerSHAPE.DoCommand("create curve Oblique", "DISTANCE " + position.Value, "ACCEPT");

                // Add created curves to collection
                if (_powerSHAPE.ActiveModel.CreatedItems.Count == 0)
                {
                    throw new ApplicationException("No curves were created from intersection operation");
                }
                foreach (PSCompCurve createdCurve in _powerSHAPE.ActiveModel.CreatedItems)
                {
                    createdCurves.Add(createdCurve);
                    _powerSHAPE.ActiveModel.CompCurves.Add(createdCurve);
                }
            }
            else
            {
                throw new ApplicationException("Entity must be Mesh, Surface or Solid");
            }

            // Return created curves
            return(createdCurves);
        }
Beispiel #2
0
        /// <summary>
        /// Copies and pastes the Entity.
        /// NB:Any dependencies are also copied and cause an exception to be thrown.
        /// </summary>
        /// <exception cref="NotImplementedException">Doesn't yet support multiple pasted objects</exception>
        /// <exception cref="Exception">Item in clipboard is not a PowerSHAPE, or the expected object</exception>
        public virtual PSEntity Duplicate()
        {
            Copy();
            _powerSHAPE.ActiveModel.ClearSelectedItems();
            _powerSHAPE.DoCommand("PASTE");

            int nSelectedItemsCount = _powerSHAPE.ActiveModel.SelectedItems.Count;

            //only need count once

            // No object has been pasted within PowerSHAPE
            if (nSelectedItemsCount == 0)
            {
                throw new Exception("Item in clipboard is not a PowerSHAPE object");

                // One object has been pasted in PowerSHAPE
            }
            if (nSelectedItemsCount == 1)
            {
                PSEntity newEntity = _powerSHAPE.ActiveModel.SelectedItems[0];
                if (newEntity.Identifier != Identifier)
                {
                    // The pasted object is not of the required type
                    // Delete the incorrect object
                    newEntity.AddToSelection(true);
                    _powerSHAPE.DoCommand("DELETE");
                    throw new Exception("Item in clipboard is not a " + Identifier);
                }
                _powerSHAPE.ActiveModel.Add(newEntity);
                return(newEntity);

                // More than one item was pasted in PowerSHAPE
            }
            throw new NotImplementedException("Doesn't yet support multiple pasted objects!");
        }
        /// <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);
        }
Beispiel #4
0
        /// <summary>
        /// Shifts the entity from being relative to one workplane to being relative to another
        /// </summary>
        /// <param name="toWorkplane">The workplane to rebase to</param>
        /// <param name="fromWorkplane">Optional parameter.  The workplane to rebase from.  Default of Nothing is world.</param>
        /// <exception cref="NotImplementedException">Doesn't yet support multiple pasted objects</exception>
        /// <exception cref="Exception">Item in clipboard is not a PowerSHAPE, or the expected object</exception>
        public virtual void RebaseToWorkplane(PSWorkplane toWorkplane, PSWorkplane fromWorkplane = null)
        {
            // Activate the from workplane (default is world)
            _powerSHAPE.ActiveModel.ActiveWorkplane = fromWorkplane;

            Copy();
            _powerSHAPE.ActiveModel.ClearSelectedItems();

            // Activate the to workplane
            _powerSHAPE.ActiveModel.ActiveWorkplane = toWorkplane;
            _powerSHAPE.DoCommand("PASTE");

            // No object has been pasted within PowerSHAPE
            if (_powerSHAPE.ActiveModel.SelectedItems.Count == 0)
            {
                throw new Exception("Item in clipboard is not a PowerSHAPE object");

                // One object has been pasted in PowerSHAPE
            }
            if (_powerSHAPE.ActiveModel.SelectedItems.Count == 1)
            {
                PSEntity newEntity = _powerSHAPE.ActiveModel.SelectedItems[0];
                if (newEntity.Identifier != Identifier)
                {
                    // The pasted object is not of the required type
                    // Delete the incorrect object
                    newEntity.AddToSelection(true);
                    _powerSHAPE.DoCommand("DELETE");
                    throw new Exception("Item in clipboard is not a " + Identifier);
                }

                // Delete the original item and link this entity to the new one
                AddToSelection(true);
                _powerSHAPE.DoCommand("DELETE");
                _id   = newEntity.Id;
                _name = newEntity.Name;

                // More than one item was pasted in PowerSHAPE
            }
            else
            {
                throw new NotImplementedException("Doesn't yet support multiple pasted objects!");
            }
        }
        /// <summary>
        /// Projects a Curve onto a surface.
        /// </summary>
        /// <param name="surface">The surface to wrap onto.</param>
        /// <param name="projectionType">The type of projection to be carried out.</param>
        /// <param name="keepOriginal">If true, it deletes the original entity.</param>
        /// <remarks>The old CompCurve is removed, and this object's ID set to be the new ID.</remarks>
        /// <returns>List of entities created by the operation.</returns>
        public virtual List <PSCompCurve> ProjectOntoSurface(PSEntity surface, ProjectionType projectionType, bool keepOriginal)
        {
            // Add necessary components to the selection
            AddToSelection(true);
            surface.AddToSelection(false);

            _powerSHAPE.ActiveModel.ClearCreatedItems();
            _powerSHAPE.DoCommand("CREATE CURVE PROJECT");

            // Select correct projection type
            switch (projectionType)
            {
            case ProjectionType.AlongPrincipalAxis:
                _powerSHAPE.DoCommand("PRINCIPAL");
                break;

            case ProjectionType.AlongSurfaceNormal:
                _powerSHAPE.DoCommand("NORMAL");
                break;

            case ProjectionType.ThroughSurface:
                _powerSHAPE.DoCommand("THRU");
                break;
            }

            _powerSHAPE.DoCommand("ACCEPT");

            List <PSCompCurve> newEntities = new List <PSCompCurve>();

            foreach (PSCompCurve newEntity in _powerSHAPE.ActiveModel.CreatedItems)
            {
                _powerSHAPE.ActiveModel.Add(newEntity);
                newEntities.Add(newEntity);
            }

            if (keepOriginal == false)
            {
                AddToSelection(true);
                _powerSHAPE.DoCommand("DELETE");
            }

            return(newEntities);
        }
Beispiel #6
0
        /// <summary>
        /// Creates a workplane aligned to an entity
        /// </summary>
        internal PSWorkplane(PSAutomation powerSHAPE, PSEntity entity, Geometry.Point origin) : base(powerSHAPE)
        {
            // Select the entity
            entity.AddToSelection(true);

            // Create the workplane
            _powerSHAPE.DoCommand("CREATE WORKPLANE NORMALSINGLE");
            _powerSHAPE.DoCommand(origin.ToString());

            // Try to get workplane details
            try
            {
                PSWorkplane newWorkplane = (PSWorkplane)_powerSHAPE.ActiveModel.CreatedItems[0];
                _name = newWorkplane.Name;
                _id   = newWorkplane.Id;
            }
            catch
            {
                throw new ApplicationException("Failed to create Workplane");
            }
        }
Beispiel #7
0
        /// <summary>
        /// Creates a workplane that doesn't need an origin
        /// </summary>
        internal PSWorkplane(
            PSAutomation powerSHAPE,
            PSEntity entity,
            NewWorkplaneInEntityPositions workplanePosition) : base(powerSHAPE)
        {
            // Select the entity
            entity.AddToSelection(true);

            // Create the workplane
            string position = "";

            switch (workplanePosition)
            {
            case NewWorkplaneInEntityPositions.Centre:
                position = "SELECTIONCENTRE";
                break;

            case NewWorkplaneInEntityPositions.Bottom:
                position = "SELECTIONBOTTOM";
                break;

            case NewWorkplaneInEntityPositions.Top:
                position = "SELECTIONTOP";
                break;
            }
            _powerSHAPE.DoCommand("CREATE WORKPLANE " + position);

            // Try to get workplane details
            try
            {
                PSWorkplane newWorkplane = (PSWorkplane)_powerSHAPE.ActiveModel.CreatedItems[0];
                _name = newWorkplane.Name;
                _id   = newWorkplane.Id;
            }
            catch
            {
                throw new ApplicationException("Failed to create Workplane");
            }
        }
Beispiel #8
0
        /// <summary>
        /// Intersects an entity with another entity
        /// </summary>
        /// <param name="entityToIntersect">Entity to intersect</param>
        /// <param name="copeWithCoincidentFaces">Optional boolean defaults to False</param>
        /// <returns>Entity created from the intersection</returns>
        public PSEntity IntersectEntityWithEntity(IPSIntersectable entityToIntersect, bool copeWithCoincidentFaces = false)
        {
            // In order to force the dialog to appear, the command is sent before doing the selection of the entity
            _powerSHAPE.ActiveModel.ClearSelectedItems();
            _powerSHAPE.DoCommand("CREATE FEATURE INTERSECTION");

            // Select this item
            _powerSHAPE.DoCommand("PRIMARY ON");
            AddToSelection(false);

            // Add addition solid to selection
            PSEntity entity = (PSEntity)entityToIntersect;

            entity.AddToSelection(false);

            if (copeWithCoincidentFaces)
            {
                _powerSHAPE.DoCommand("TOLERANCE ON");
            }
            else
            {
                _powerSHAPE.DoCommand("TOLERANCE OFF");
            }

            // Fill in options on the dialog and accept it to complete the operation.  The YES at the end is to handle the question about deleting the solid tree
            _powerSHAPE.DoCommand("KEEP OFF", "ACCEPT", "YES");

            if (_powerSHAPE.ActiveModel.SelectedItems.Count == 0)
            {
                return(null);
            }

            // Remove the lost solids
            entity.Delete();

            // Return this Mesh
            return(this);
        }
        /// <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);
        }