Пример #1
0
        private static TopoDSShape BuildTopoDsShapeHandle(gpAx2 axis, double edgeLength)
        {
            var axisLocation      = axis.Location;
            var translationVector = new gpVec(axis.XDirection);

            translationVector.Normalize();
            translationVector.Multiply(edgeLength * Math.Sqrt(2) / 2);
            translationVector.Rotate(axis.Axis, Math.PI / 4);

            var firstPoint = new Point3D(axisLocation.Translated(translationVector));

            translationVector.Rotate(axis.Axis, Math.PI / 2);
            var secondPoint = new Point3D(axisLocation.Translated(translationVector));

            translationVector.Rotate(axis.Axis, Math.PI / 2);
            var thirdPoint = new Point3D(axisLocation.Translated(translationVector));

            translationVector.Rotate(axis.Axis, Math.PI / 2);
            var fourthPoint = new Point3D(axisLocation.Translated(translationVector));

            var firstLine  = GeomUtils.BuildLine(firstPoint, secondPoint);
            var secondLine = GeomUtils.BuildLine(secondPoint, thirdPoint);
            var thirdLine  = GeomUtils.BuildLine(thirdPoint, fourthPoint);
            var fourthLine = GeomUtils.BuildLine(fourthPoint, firstPoint);

            var wireList = new List <TopoDSWire> {
                firstLine, secondLine, thirdLine, fourthLine
            };
            var face = GeomUtils.MakeFace(wireList);

            return(face);
        }
        private static TopoDSShape BuildTopoDsShapeHandle(gpAx2 coordinate, double edgeLength)
        {
            var axisLocation     = coordinate.Location;
            var thirdPointVector = new gpVec(coordinate.XDirection);

            thirdPointVector.Multiply(edgeLength);
            var thirdPoint = new Point3D(axisLocation.Translated(thirdPointVector));

            var secondPointVector = new gpVec(coordinate.YDirection);

            secondPointVector.Multiply(edgeLength);
            var secondPoint = new Point3D(axisLocation.Translated(secondPointVector));
            var firstPoint  = new Point3D(axisLocation.Translated(secondPointVector.Reversed));

            var firstLine  = GeomUtils.BuildLine(firstPoint, secondPoint);
            var secondLine = GeomUtils.BuildLine(secondPoint, thirdPoint);
            var thirdLine  = GeomUtils.BuildLine(thirdPoint, firstPoint);

            var wireList = new List <TopoDSWire> {
                firstLine, secondLine, thirdLine
            };
            var face            = GeomUtils.MakeFace(wireList);
            var extrusionVector = new gpVec(coordinate.Direction);

            extrusionVector.Normalize();
            extrusionVector.Multiply(edgeLength / 2);
            return(new BRepPrimAPIMakePrism(face, extrusionVector, false, true).Shape);
        }
Пример #3
0
        public override gpAx2 GetPointLocation(int index)
        {
            var transform = Node.Get <TransformationInterpreter>().CurrTransform;

            var ax2 = new gpAx2();

            ax2.Location = Dependency[0].TransformedPoint3D.GpPnt;

            var circleCenter = Dependency[0].TransformedPoint3D.GpPnt;
            var circleAxis   = new gpAx1();

            circleAxis.Location = (Dependency[0].TransformedPoint3D.GpPnt);
            var pointOnCircle = GetPointOnCircle(circleAxis, Dependency[1].Real, transform);
            var radius        = pointOnCircle.Distance(circleCenter);

            var leftArrowVector = new gpVec(circleCenter, pointOnCircle);

            leftArrowVector.Normalize();
            leftArrowVector.Multiply(radius + DistanceToObject);
            var leftArrowLocation = circleCenter.Translated(leftArrowVector);

            var rightArrowVector   = leftArrowVector.Reversed;
            var rightArrowLocation = circleCenter.Translated(rightArrowVector);

            var topArrowVector = new gpVec(leftArrowVector.XYZ);

            topArrowVector.Cross(new gpVec(ax2.Direction));
            topArrowVector.Normalize();
            topArrowVector.Multiply(radius + DistanceToObject);
            var topArrowLocation = circleCenter.Translated(topArrowVector);

            var bottomArrowVector   = topArrowVector.Reversed;
            var bottomArrowLocation = circleCenter.Translated(bottomArrowVector);

            switch (index)
            {
            case 0:
                ax2.Location   = (leftArrowLocation);
                ax2.XDirection = (new gpDir(leftArrowVector));
                return(ax2);

            case 1:
                ax2.Location   = (topArrowLocation);
                ax2.XDirection = (new gpDir(topArrowVector));
                return(ax2);

            case 2:
                ax2.Location   = (rightArrowLocation);
                ax2.XDirection = (new gpDir(rightArrowVector));
                return(ax2);

            case 3:
                ax2.Location   = (bottomArrowLocation);
                ax2.XDirection = (new gpDir(bottomArrowVector));
                return(ax2);

            default:
                return(null);
            }
        }
Пример #4
0
        private static TopoDSShape BuildTopoDsShapeHandle(gpAx2 coordinate, double edgeLength)
        {
            var axisLocation = coordinate.Location;
            var firstPoint   = new Point3D(axisLocation);

            var secondPointVector = new gpVec(coordinate.Direction);

            secondPointVector.Multiply(edgeLength);
            var secondPoint = new Point3D(axisLocation.Translated(secondPointVector));

            var thirdPointVector = new gpVec(coordinate.XDirection);

            thirdPointVector.Multiply(edgeLength);
            var thirdPoint = new Point3D(axisLocation.Translated(thirdPointVector));

            var firstLine  = GeomUtils.BuildLine(firstPoint, secondPoint);
            var secondLine = GeomUtils.BuildLine(secondPoint, thirdPoint);
            var thirdLine  = GeomUtils.BuildLine(thirdPoint, firstPoint);

            var wireList = new List <TopoDSWire> {
                firstLine, secondLine, thirdLine
            };
            var face = GeomUtils.MakeFace(wireList);

            return(face);
        }
Пример #5
0
        public static void DisplayTemporaryDimension(Document animationDocument, Node baseNode, Node extrusion, Mouse3DPosition mouseData, bool enableSelection)
        {
            var subShape = new NodeBuilder(animationDocument, FunctionNames.SubShape);

            subShape[0].Reference = extrusion;
            subShape[1].Integer   = 1;
            subShape[2].Integer   = (int)TopAbsShapeEnum.TopAbs_EDGE;
            subShape.ExecuteFunction();

            if (subShape.Shape == null)
            {
                return;
            }

            var edge            = TopoDS.Edge(subShape.Shape);
            var baseNodeBuilder = new NodeBuilder(baseNode);
            var gravityCenter   = GeomUtils.ExtractGravityCenter(baseNodeBuilder.Shape);

            var firstPoint           = new Point3D();
            var firstPointCalculated = GeomUtils.CalculateEdgeFirstPoint(edge);

            if (firstPointCalculated != null)
            {
                firstPoint = (Point3D)firstPointCalculated;
            }

            var secondPoint           = new Point3D();
            var secondPointCalculated = GeomUtils.CalculateEdgeLastPoint(edge);

            if (secondPointCalculated != null)
            {
                secondPoint = (Point3D)secondPointCalculated;
            }

            var middlePoint = GeomUtils.ComputeMidPoint(firstPoint, secondPoint);

            // Translate the dimenion text at some distance from the extrude
            var vector = new gpVec(firstPoint.GpPnt, gravityCenter.GpPnt);

            vector.Reverse();
            vector.Normalize();
            vector.Multiply(2);
            middlePoint = GeomUtils.BuildTranslation(middlePoint, vector);

            subShape.Visibility = ObjectVisibility.Hidden;

            // Build a distance dimension just for animation purposes
            var animationBuilder = new NodeBuilder(animationDocument, FunctionNames.PointsDimension);

            animationBuilder[0].TransformedPoint3D = firstPoint;
            animationBuilder[1].TransformedPoint3D = secondPoint;
            animationBuilder[2].TransformedPoint3D = middlePoint;
            animationBuilder[3].Integer            = (int)DsgPrsArrowSide.DsgPrs_AS_FIRSTPT_LASTAR;
            animationBuilder[4].Real         = 1;
            animationBuilder.EnableSelection = false;
            animationBuilder.Color           = Color.Black;
            animationBuilder.ExecuteFunction();
        }
        private static TopoDSFace BuildPlane(gpAx2 orientation, double rectangleLength)
        {
            var diagonalVector = new gpVec(orientation.XDirection);

            diagonalVector.Multiply(rectangleLength * Math.Sqrt(2));
            var secondPoint = GeomUtils.BuildTranslation(new Point3D(orientation.Location), diagonalVector);

            return(OccShapeCreatorCode.BuildRectangle(orientation.Location, secondPoint.GpPnt, orientation.Direction));
        }
Пример #7
0
        /// <summary>
        ///   Builds a box receiving three points that describe the base rectangle and one being the height
        /// </summary>
        /// <param name = "axis"></param>
        /// <param name = "secondPoint"></param>
        /// <param name = "height"></param>
        /// <returns></returns>
        private static TopoDSShape MakeBox(gpAx1 axis, Point3D secondPoint, double height)
        {
            var face = OccShapeCreatorCode.BuildRectangle(axis.Location, secondPoint.GpPnt, axis.Direction);
            // Get the direction
            var dir    = GeomUtils.ExtractDirection(face);
            var vector = new gpVec(dir);

            vector.Multiply(height);

            return(new BRepPrimAPIMakePrism(face, vector, false, true).Shape);
        }
Пример #8
0
        private static Point3D CalculateEndPointOnArc(Point3D center, Point3D startPoint, Point3D currentEndPoint)
        {
            var radius = center.Distance(startPoint);

            Ensure.IsTrue(radius > 0);
            var endPointVector = new gpVec(center.GpPnt, currentEndPoint.GpPnt);

            endPointVector.Normalize();
            endPointVector.Multiply(radius);
            return(GeomUtils.BuildTranslation(center, endPointVector));
        }
        public void ApplyGeneralCircularPattern(gpAx1 axis, double angle, double heigth)
        {
            GeneralRotationWithoutPivot(axis, angle);
            var transformation = ConvertgpTrsfToMatrix3DTransform();
            var heightToAdd    = new gpVec(axis.Direction);

            heightToAdd.Normalize();
            heightToAdd.Multiply(heigth);
            SetTranslationValuesAndPivot(ref transformation,
                                         new Vector3D(heightToAdd.X, heightToAdd.Y, heightToAdd.Z));
            OnModified();
        }
Пример #10
0
        public static void ParalelogramSetWidthPoints(Node node, double width)
        {
            if (width < Precision.Confusion)
            {
                return;
            }
            var builder        = new NodeBuilder(node);
            var initialWidth   = builder[1].TransformedPoint3D.Distance(builder[2].TransformedPoint3D);
            var widthToAdd     = width - initialWidth;
            var widthDirection = new gpVec(builder[1].TransformedPoint3D.GpPnt, builder[2].TransformedPoint3D.GpPnt);

            widthDirection.Normalize();
            widthDirection.Multiply(widthToAdd);
            builder[2].TransformedPoint3D = new Point3D(builder[2].TransformedPoint3D.GpPnt.Translated(widthDirection));
        }
        private static TopoDSShape BuildAxisShapeHandle(gpAx1 mainAxis, double arrowLength, double arrowWidth)
        {
            var cylinderShape = GeomUtils.MakeCylinder(mainAxis, arrowWidth, arrowLength * 3 / 4,
                                                       GeomUtils.DegreesToRadians(360));
            var coneVector = new gpVec(mainAxis.Direction);

            coneVector.Multiply(arrowLength * 3 / 4);
            var coneLocation = mainAxis.Translated(coneVector);
            var cone         = GeomUtils.MakeCone(coneLocation, arrowWidth * 1.5, 0, arrowLength / 4,
                                                  GeomUtils.DegreesToRadians(360));

            var fuse = new BRepAlgoAPIFuse(cylinderShape, cone);

            return(fuse.Shape);
        }
        /// <summary>
        ///   Make an extrusion starting from a shape until a height.
        /// </summary>
        /// <param name = "originalShape"></param>
        /// <param name = "height"></param>
        /// <returns></returns>
        private static TopoDSShape ExtrudeMidPlane(TopoDSShape originalShape, double height)
        {
            TopoDSShape prismShape = null;

            // Make the Extrusion
            if (originalShape != null)
            {
                try
                {
                    // Get the Face to be extruded
                    var face = originalShape;// OCTopoDS.Face(originalShape);

                    // Get the direction
                    var dir = GeomUtils.ExtractDirection(face);
                    if (dir == null)
                    {
                        return(null);
                    }

                    // Build the translated shape
                    var translationVector = new gpVec(dir);
                    translationVector.Multiply(-1 * height / 2);
                    var transformation = new gpTrsf();
                    transformation.SetTranslation(translationVector);
                    var brepTrans       = new BRepBuilderAPITransform(originalShape, transformation, false);
                    var translatedShape = brepTrans.Shape;

                    // Extract the face of the translated shape
                    //baseEx.Init(translatedShape, TopAbsShapeEnum.TopAbs_FACE, TopAbsShapeEnum.TopAbs_SHAPE);
                    //baseEx.Next();
                    var translatedFace = translatedShape;// OCTopoDS.Face(translatedShape);

                    // Describe the height through a vector
                    var vector = new gpVec(dir);
                    vector.Multiply(height);

                    // Make the prism
                    prismShape = new BRepPrimAPIMakePrism(translatedFace, vector, false, true).Shape;
                }
                catch (Exception ex)
                {
                    Log.Error("Error on extrude: " + ex.Message);
                    return(null);
                }
            }

            return(prismShape);
        }
Пример #13
0
        public static void ParalelogramSetHeightPoints(Node node, double height)
        {
            if (height < Precision.Confusion)
            {
                return;
            }

            var builder         = new NodeBuilder(node);
            var initialHeight   = builder[0].TransformedPoint3D.Distance(builder[1].TransformedPoint3D);
            var heigthToAdd     = height - initialHeight;
            var heigthDirection = new gpVec(builder[0].TransformedPoint3D.GpPnt, builder[1].TransformedPoint3D.GpPnt);

            heigthDirection.Normalize();
            heigthDirection.Multiply(heigthToAdd);
            builder[1].TransformedPoint3D = new Point3D(builder[1].TransformedPoint3D.GpPnt.Translated(heigthDirection));
            builder[2].TransformedPoint3D = new Point3D(builder[2].TransformedPoint3D.GpPnt.Translated(heigthDirection));
        }
        public void ApplyGeneralArrayPattern(gpAx1 rowAxis, gpAx1 colomnAxis, double rowLength,
                                             double colomnLength)
        {
            var transformation = ConvertgpTrsfToMatrix3DTransform();
            var rowLengthToAdd = new gpVec(rowAxis.Direction);

            rowLengthToAdd.Normalize();
            rowLengthToAdd.Multiply(rowLength);
            SetTranslationValuesAndPivot(ref transformation,
                                         new Vector3D(rowLengthToAdd.X, rowLengthToAdd.Y, rowLengthToAdd.Z));
            var colomnLengthToAdd = new gpVec(colomnAxis.Direction);

            colomnLengthToAdd.Normalize();
            colomnLengthToAdd.Multiply(colomnLength);
            SetTranslationValuesAndPivot(ref transformation,
                                         new Vector3D(colomnLengthToAdd.X, colomnLengthToAdd.Y,
                                                      colomnLengthToAdd.Z));
            OnModified();
        }
        private void BuildDragAxis(Document document, TopoDSShape shape, double extrudeSize)
        {
            var gravityCenter = GeomUtils.ExtractGravityCenter(shape);
            var dir           = GeomUtils.ExtractDirection(shape);

            if (dir.XYZ.Z < 0)
            {
                dir.Reverse();
            }
            var vec = new gpVec(dir);

            vec.Normalize();
            vec.Multiply(extrudeSize);

            gravityCenter = GeomUtils.BuildTranslation(gravityCenter, vec);
            var point       = new gpPnt(dir.XYZ);
            var gravityAxis = new Axis(gravityCenter, new Point3D(point));

            DrawDragAxis(document, gravityAxis, 5, 2);
            // _normalPlane = BuildNormalPlane(dir, gravityAxis);
        }
        /// <summary>
        ///   Make an extrusion starting from a shape until a height.
        /// </summary>
        /// <param name = "originalShape"></param>
        /// <param name = "height"></param>
        /// <returns></returns>
        private static TopoDSShape ExtrudeToDepth(TopoDSShape originalShape, double height)
        {
            TopoDSShape prismShape = null;

            // Make the Extrusion
            if (originalShape != null)
            {
                try
                {
                    var face = originalShape;// OCTopoDS.Face(originalShape);

                    // Get the direction
                    var dir = GeomUtils.ExtractDirection(face);

                    if (dir == null)
                    {
                        return(null);
                    }
                    if (dir.XYZ.Z < 0)
                    {
                        dir.Reverse();
                    }
                    // Describe the height through a vector
                    var vector = new gpVec(dir);
                    vector.Multiply(height);

                    // Make the prism
                    return(new BRepPrimAPIMakePrism(face, vector, false, true).Shape);
                }
                catch (Exception ex)
                {
                    Log.Error("Error on extrude: " + ex.Message);
                    return(null);
                }
            }

            return(prismShape);
        }
Пример #17
0
        public override gpAx2 GetPointLocation(int index)
        {
            //var transform = Node.Get<TransformationInterpreter>().CurrTransform;
            var transform  = NodeBuilderUtils.GetGlobalTransformation(new NodeBuilder(NodeBuilderUtils.FindSketchNode(Node)));
            var ax2        = new gpAx2();
            var centerAxis = new gpAx1();

            if (Dependency[0].Name == InterpreterNames.Reference)
            {
                var circleLocation = Dependency[0].RefTransformedPoint3D.GpPnt;
                var pointBuilder   = Dependency[0].ReferenceBuilder;
                var circleNormal   = pointBuilder[0].Reference.Children[1].Get <Axis3DInterpreter>().Axis.Direction;

                centerAxis = new gpAx1(circleLocation, new gpDir(circleNormal.GpPnt.XYZ).Transformed(transform));
                ax2.Axis   = (centerAxis);
            }
            if (Dependency[0].Name == InterpreterNames.Axis3D)
            {
                centerAxis = Dependency[0].TransformedAxis3D;
                ax2.Axis   = (centerAxis);
            }
            var circleCenter  = centerAxis;
            var pointOnCircle = GetPointOnCircle(centerAxis, Dependency[1].Real, transform);
            var radius        = pointOnCircle.Distance(circleCenter.Location);

            var leftArrowVector = new gpVec(circleCenter.Location, pointOnCircle);

            leftArrowVector.Normalize();
            leftArrowVector.Multiply(radius + DistanceToObject);
            var leftArrowLocation = circleCenter.Location.Translated(leftArrowVector);

            var rightArrowVector   = leftArrowVector.Reversed;
            var rightArrowLocation = circleCenter.Location.Translated(rightArrowVector);

            var topArrowVector = new gpVec(leftArrowVector.XYZ);

            topArrowVector.Cross(new gpVec(ax2.Direction));
            topArrowVector.Normalize();
            topArrowVector.Multiply(radius + DistanceToObject);
            var topArrowLocation = circleCenter.Location.Translated(topArrowVector);

            var bottomArrowVector   = topArrowVector.Reversed;
            var bottomArrowLocation = circleCenter.Location.Translated(bottomArrowVector);

            switch (index)
            {
            case 0:
                ax2.Location   = (leftArrowLocation);
                ax2.XDirection = (new gpDir(leftArrowVector));
                return(ax2);

            case 1:
                ax2.Location   = (topArrowLocation);
                ax2.XDirection = (new gpDir(topArrowVector));
                return(ax2);

            case 2:
                ax2.Location   = (rightArrowLocation);
                ax2.XDirection = (new gpDir(rightArrowVector));
                return(ax2);

            case 3:
                ax2.Location   = (bottomArrowLocation);
                ax2.XDirection = (new gpDir(bottomArrowVector));
                return(ax2);

            default:
                return(null);
            }
        }
        private void ConeHeight(bool updateShape)
        {
            double height;

            if (Dependency.Steps[3].Data is Mouse3DPosition)
            {
                // If point received from mouse, recalculate the axis direction
                var plane = new GeomPlane(Dependency.Steps[0].Get <gpAx1>().Location,
                                          Dependency.Steps[0].Get <gpAx1>().Direction);
                height = GeomUtils.PointPosition(plane.Pln, Dependency.Steps[3].Get <Mouse3DPosition>().Point.GpPnt);
                Dependency.Steps[3].Data = height;
            }
            else
            {
                // If height received from command line
                height = Dependency.Steps[3].Get <double>();
            }

            if (Math.Abs(height) < 0.01)
            {
                height = 1;
            }
            var axis = Dependency.Steps[0].Get <gpAx1>();

            if (height > 0)
            {
                axis = axis.Reversed;
                Dependency.Steps[0].Data = axis;
            }

            // Prevent the mouse from generating point on the base
            var basePoint     = axis.Location;
            var excludedPlane = new GeomPlane(basePoint, axis.Direction);

            Dependency.Inputs.Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.ExcludedPlane,
                                                                        excludedPlane.Pln);
            // After the base is drawn disable the face picker
            Dependency.Inputs.Inputs[InputNames.FacePickerPlane].Send(NotificationNames.Suspend);
            Dependency.AnimationNodeBuilder = new NodeBuilder(Dependency.AnimationDocument, FunctionNames.Cone);
            var builder = Dependency.AnimationNodeBuilder;

            DrawCone(ref builder, Dependency.Steps[1].Get <double>(), height, axis, true, false);

            // Build a distance dimension just for animation purposes
            var animationBuilder      = new NodeBuilder(Dependency.AnimationDocument, FunctionNames.PointsDimension);
            var firstTransformedPoint = axis.Location;
            var firstPoint            = new Point3D(firstTransformedPoint);

            animationBuilder[0].TransformedPoint3D = firstPoint;
            var translationVector = new gpVec(axis.Direction);

            translationVector.Normalize();
            translationVector.Multiply(height);
            var secondPoint = firstPoint.GpPnt.Translated(translationVector.Reversed);

            animationBuilder[1].TransformedPoint3D = new Point3D(secondPoint);
            var textLocation = new Point3D(secondPoint);

            textLocation.X++;
            textLocation.Y++;
            textLocation.Z++;
            animationBuilder[2].TransformedPoint3D = textLocation;
            animationBuilder[3].Integer            = (int)DsgPrsArrowSide.DsgPrs_AS_FIRSTPT_LASTAR;
            animationBuilder.EnableSelection       = false;
            animationBuilder.ExecuteFunction();
            Dependency.AnimationNodeBuilder = animationBuilder;
        }
Пример #19
0
        // The rectangle is like the following:
        //   vertex2------vertex3
        //   vertex1------vertex4
        public override gpAx2 GetPointLocation(int index)
        {
            var firstPoint  = Dependency[0].TransformedPoint3D;
            var secondPoint = Dependency[1].TransformedPoint3D;
            var thirdPoint  = Dependency[2].TransformedPoint3D;

            var vectorV2V1               = new gpVec(secondPoint.GpPnt, firstPoint.GpPnt);
            var vectorV2V3               = new gpVec(secondPoint.GpPnt, thirdPoint.GpPnt);
            var rectangleNormalVector    = vectorV2V1.Crossed(vectorV2V3);
            var rectangleNormalDirection = new gpDir(rectangleNormalVector);

            var rectangleCenter = new gpPnt((firstPoint.X + thirdPoint.X) / 2, (firstPoint.Y + thirdPoint.Y) / 2,
                                            (firstPoint.Z + thirdPoint.Z) / 2);

            vectorV2V3.Normalize();
            vectorV2V1.Normalize();
            vectorV2V3.Multiply(DistanceToObject);
            vectorV2V1.Multiply(DistanceToObject);

            var leftArrowVector   = vectorV2V3.Reversed;
            var leftArrowMidPoint = GeomUtils.ComputeMidPoint(firstPoint, secondPoint);
            var leftArrowPoint    = GeomUtils.BuildTranslation(leftArrowMidPoint, leftArrowVector);
            var leftArrowAxis     = new gpAx2(leftArrowPoint.GpPnt, rectangleNormalDirection)
            {
                XDirection = (new gpDir(leftArrowVector))
            };

            var topArrowVector   = vectorV2V1.Reversed;
            var topArrowMidPoint = GeomUtils.ComputeMidPoint(secondPoint, thirdPoint);
            var topArrowPoint    = GeomUtils.BuildTranslation(topArrowMidPoint, topArrowVector);
            var topArrowAxis     = new gpAx2(topArrowPoint.GpPnt, rectangleNormalDirection);

            topArrowAxis.XDirection = (new gpDir(topArrowVector));

            var bottomArrowPoint = new gpPnt(2 * rectangleCenter.X - topArrowPoint.X,
                                             2 * rectangleCenter.Y - topArrowPoint.Y,
                                             2 * rectangleCenter.Z - topArrowPoint.Z);
            var bottomArrowAxis = new gpAx2(bottomArrowPoint, rectangleNormalDirection);

            bottomArrowAxis.XDirection = (new gpDir(topArrowVector.Reversed));

            var rightArrowPoint = new gpPnt(2 * rectangleCenter.X - leftArrowPoint.X,
                                            2 * rectangleCenter.Y - leftArrowPoint.Y,
                                            2 * rectangleCenter.Z - leftArrowPoint.Z);
            var rightArrowAxis = new gpAx2(rightArrowPoint, rectangleNormalDirection);

            rightArrowAxis.XDirection = new gpDir(leftArrowVector.Reversed);

            var pointLocation = new gpAx2();

            pointLocation.Direction = rectangleNormalDirection;

            switch (index)
            {
            case 0:
                pointLocation.Location   = (firstPoint.GpPnt);
                pointLocation.XDirection = (new gpDir(vectorV2V3));
                return(pointLocation);

            case 1:
                pointLocation.Location   = (thirdPoint.GpPnt);
                pointLocation.XDirection = (new gpDir(vectorV2V3));
                return(pointLocation);

            case 2:
                return(leftArrowAxis);

            case 3:
                return(topArrowAxis);

            case 4:
                return(rightArrowAxis);

            case 5:
                return(bottomArrowAxis);

            default:
                return(null);
            }
        }
Пример #20
0
        public override bool Execute()
        {
            // Get the reference nodes to see if Cut was applied or it is the first time
            var cutShapes = Dependency[3].ReferenceList;

            if (cutShapes == null)
            {
                return(false);
            }
            var rootNode = Parent.Root;
            // Get the Cut dependencies (cutting shape, cut depth and cut type)
            var cuttingShape = Dependency[0].ReferedShape;
            var sketchNode   = Dependency[0].ReferenceBuilder.Node;
            var faces        = AutoGroupLogic.BuildAutoFaces(sketchNode, rootNode.Get <DocumentContextInterpreter>().Document);
            var depth        = Dependency[1].Real;
            var cutType      = (CutTypes)Dependency[2].Integer;

            cuttingShape = faces.First(); // firstFace.Shape;
            // Test the cutting shape
            if (cuttingShape == null || cuttingShape.IsNull)
            {
                return(false);
            }

            var dir = GeomUtils.ExtractDirection(cuttingShape) ??
                      sketchNode.Children[1].Get <Axis3DInterpreter>().Axis.GpAxis.Direction;

            // Build a list with the cutting prisms used to Cut the objects
            var cuttingPrisms = new List <TopoDSShape>();

            var depthM = cutType == CutTypes.ToDepth ? depth : 7000;

            if (Math.Abs(depthM) < Precision.Confusion)
            {
                depthM = 0.1;
            }
            foreach (var face in faces)
            {
                TopoDSShape cutPrismShape     = null;
                var         translationVector = new gpVec(dir);
                translationVector.Multiply(-1 * depthM / 2);
                var transformation = new gpTrsf();
                transformation.SetTranslation(translationVector);
                var brepTrans       = new BRepBuilderAPITransform(face, transformation, false);
                var translatedShape = brepTrans.Shape;
                var translatedFace  = translatedShape;

                // Describe the height through a vector
                var vector = new gpVec(dir);
                vector.Multiply(depthM);

                // Make the prism
                cutPrismShape = new BRepPrimAPIMakePrism(translatedFace, vector, false, true).Shape;

                cuttingPrisms.Add(cutPrismShape);
            }
            if (cuttingPrisms.Count == 0)
            {
                return(false);
            }
            var document  = rootNode.Get <DocumentContextInterpreter>().Document;
            var shapeList = new List <int>();

            if (Dependency[3].ReferenceList.Count > 0)
            {
                shapeList.AddRange(Dependency[3].ReferenceList.Select(sse => sse.Node.Index));
            }
            else
            {
                shapeList.AddRange(NodeUtils.GetDocumentSolids(document));
                shapeList.Remove(Parent.Index);
            }
            TopoDSShape resShape = null;

            foreach (var cuttingPrism in cuttingPrisms)
            {
                // If the Cut is executed first time
                if (cutShapes.Count <= 0 || resShape == null)
                {
                    // Put back the shapes
                    // Cut them again
                    var cutModifiedNodes = new List <SceneSelectedEntity>();
                    resShape = CutThroughAll(rootNode, cuttingPrism, cutModifiedNodes, shapeList);
                    Dependency[3].ReferenceList = cutModifiedNodes;
                    cutShapes = Dependency[3].ReferenceList;
                }
                else
                {
                    // Execute Cut on the shapes from ReferenceList
                    resShape = CutThroughShape(resShape, cuttingPrism);
                }
            }

            if (resShape == null)
            {
                return(false);
            }

            // Show the new Cut shape
            Shape = resShape;

            return(true);
        }