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);
        }
Example #2
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);
        }
Example #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);
            }
        }
        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();
        }
Example #5
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();
        }
        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));
        }
        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);
        }
Example #11
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;
        }
Example #13
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);
            }
        }