Ejemplo n.º 1
0
        private void BuildAndEnterSketch(Document document)
        {
            var sketchCreator     = new SketchCreator(document);
            var currentSketch     = sketchCreator.CurrentSketch;
            var sketchNodeBuilder = new NodeBuilder(currentSketch);

            Document.Transact();

            Log.InfoFormat("StartSketch - Command line input");
            var firstvector    = new gpDir(Points[1].GpPnt.X - Points[0].GpPnt.X, Points[1].GpPnt.Y - Points[0].GpPnt.Y, Points[1].GpPnt.Z - Points[0].GpPnt.Z);
            var secondvector   = new gpDir(Points[2].GpPnt.X - Points[0].GpPnt.X, Points[2].GpPnt.Y - Points[0].GpPnt.Y, Points[2].GpPnt.Z - Points[0].GpPnt.Z);
            var normal         = firstvector.Crossed(secondvector);
            var _normalOnPlane = new gpAx1(Points[0].GpPnt, normal);
            var sketchAx2      = new gpAx2();

            sketchAx2.Axis = (_normalOnPlane);
            var plane = new gpPln(new gpAx3(sketchAx2));

            Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.SetPlane, plane);
            sketchNodeBuilder[0].Axis3D = new Axis(sketchNodeBuilder[0].Axis3D.Location, new Point3D(new gpPnt(_normalOnPlane.Direction.XYZ)));
            HighlightCurrentSketchNodes(sketchNodeBuilder.Node);
            NodeBuilderUtils.HidePlanes(Document);
            Document.Commit("sketch created");
            AddNodeToTree(sketchNodeBuilder.Node);
            Document.Transact();
            Document.Root.Get <DocumentContextInterpreter>().ActiveSketch = sketchNodeBuilder.Node.Index;
            _sketchButton.Block();
            Document.Commit("Started editing sketch");
        }
Ejemplo n.º 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);
        }
        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);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        public static void AddRectangleToNode(Document document, int point1, int point2)
        {
            if (!document.Root.Children.ContainsKey(point1) || !document.Root.Children.ContainsKey(point2))
            {
                return;
            }
            var sketchNode = AutoGroupLogic.FindSketchNode(document.Root[point1]);
            var axis       = new gpAx2();

            axis.Axis = (sketchNode.Children[1].Get <Axis3DInterpreter>().Axis.GpAxis);
            var pointLinker   = new SketchCreator(document).PointLinker;
            var point3Ds      = new List <Point3D>();
            var nb1           = new NodeBuilder(document.Root[point1]);
            var nb2           = new NodeBuilder(document.Root[point2]);
            var _firstPoint   = nb1.Dependency[1].TransformedPoint3D;
            var _secondPoint  = nb2.Dependency[1].TransformedPoint3D;
            var firstPoint2D  = _firstPoint.ToPoint2D(axis);
            var secondPoint2D = _secondPoint.ToPoint2D(axis);
            var x1            = firstPoint2D.X;
            var y1            = firstPoint2D.Y;
            var x2            = secondPoint2D.X;
            var y2            = secondPoint2D.Y;

            point3Ds.Add(GeomUtils.Point2DTo3D(axis, x1, y1));
            point3Ds.Add(GeomUtils.Point2DTo3D(axis, x2, y1));
            point3Ds.Add(GeomUtils.Point2DTo3D(axis, x2, y2));
            point3Ds.Add(GeomUtils.Point2DTo3D(axis, x1, y2));
            document.Root.Remove(nb1.Node.Index);
            document.Root.Remove(nb2.Node.Index);
            BuildLine(document, pointLinker, point3Ds[0], point3Ds[1]);
            BuildLine(document, pointLinker, point3Ds[1], point3Ds[2]);
            BuildLine(document, pointLinker, point3Ds[2], point3Ds[3]);
            BuildLine(document, pointLinker, point3Ds[3], point3Ds[0]);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public gpPnt2d ToPoint2D(gpAx2 ax2)
        {
            var pointPlane = new gpPln(new gpAx3(ax2));
            var point2D    = ProjLib.Project(pointPlane, GpPnt);

            return(point2D);
        }
Ejemplo n.º 8
0
        public static Point3D ConvertToGlobal(Axis normalOnSketch, Point3D coordinate)
        {
            var normal = new gpAx2();

            normal.Axis = normalOnSketch.GpAxis;
            return(new Point3D(GeomUtils.Point2DTo3D(normal, new gpPnt2d(coordinate.X, coordinate.Y))));
        }
        public override gpAx2 GetPointLocation(int index)
        {
            var gizmoOrientation = new gpAx2();
            var nodeBuilder      = new NodeBuilder(Node);

            var gravityCenter = GeomUtils.ExtractGravityCenter(nodeBuilder.Shape);

            switch (index)
            {
            case 0:
                gizmoOrientation.Direction  = gp.OX.Direction;
                gizmoOrientation.XDirection = gp.OY.Direction;
                break;

            case 1:
                gizmoOrientation.Direction  = gp.OY.Direction.Reversed;
                gizmoOrientation.XDirection = gp.OZ.Direction;
                break;

            case 2:
                gizmoOrientation.Direction  = gp.OZ.Direction.Reversed;
                gizmoOrientation.XDirection = gp.OX.Direction;
                break;

            default:
                return(null);
            }

            gizmoOrientation.Location = gravityCenter.GpPnt;
            return(gizmoOrientation);
        }
        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));
        }
        public override gpAx2 GetPointLocation(int index)
        {
            var axis = new gpAx2
            {
                Direction = (gp.OZ.Direction),
                Location  = (Dependency[index].TransformedPoint3D.GpPnt)
            };

            return(axis);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///   Builds a circle with the parameters passed and extracts a point locted on the circle
        /// </summary>
        protected static gpPnt GetPointOnCircle(gpAx1 axis, double radius, gpTrsf trsf)
        {
            var centerCoord = new gpAx2();

            centerCoord.Axis = (axis);
            var circle = new GeomCircle(centerCoord, radius);

            // Get the first point on the circle's parametric curve
            return(circle.Value(circle.FirstParameter));//.Transformed(trsf);
        }
        /// <summary>
        ///   Build a cicle knowing the axis that describe the center (location and direction)
        ///   and also the radius value
        /// </summary>
        public static TopoDSWire CreateWireCircle(gpAx1 centerAxis, double radius)
        {
            var centerCoord = new gpAx2 {
                Axis = (centerAxis)
            };
            var circle = new gpCirc(centerCoord, radius);

            var edge = new BRepBuilderAPIMakeEdge(circle).Edge;
            var wire = new BRepBuilderAPIMakeWire(edge).Wire;

            return(wire);
        }
Ejemplo n.º 14
0
        private List <NodeBuilder> PreviewRectangleLines(Document document, Node sketchNode)
        {
            _firstPoint  = Points[0];
            _secondPoint = Points[1];
            if (_firstPoint.IsEqual(_secondPoint))
            {
                return(null);
            }
            //   var axis1 = new gpAx2();
            //   axis1.Axis = (sketchNode.Children[1].Get<Axis3DInterpreter>().Axis.GpAxis);
            ////   var transformedAxsi = axis1.Transformed(sketchNode.Get<TransformationInterpreter>().CurrTransform);

            //   var location = axis1.Axis.Location.Transformed(sketchNode.Get<TransformationInterpreter>().CurrTransform);
            //   var direction = axis1.Axis.Direction.Transformed(sketchNode.Get<TransformationInterpreter>().CurrTransform);
            //   var sketchNodeBuilder = new NodeBuilder(sketchNode);
            //   var axisBase = new gpAx1(location, direction);
            //   if (sketchNodeBuilder.Dependency[2].ReferenceBuilder != null &&
            //      sketchNodeBuilder.Dependency[2].ReferenceBuilder.Node != null)
            //   {
            //       var baseSketch =
            //           new NodeBuilder(sketchNodeBuilder.Dependency[2].ReferenceBuilder.Node).Dependency[0].ReferenceBuilder;
            //      axisBase = axisBase.Transformed(baseSketch.Node.Get<TransformationInterpreter>().CurrTransform);
            //   }
            //   //var axis = new gpAx2(location, direction);
            //   var axis = new gpAx2(axisBase.Location, axisBase.Direction);
            // var axis = new gpAx2(axis1.Location, axis1.Direction);

            var axisAll       = NodeBuilderUtils.GetTransformedAxis(new NodeBuilder(sketchNode));
            var axis          = new gpAx2(axisAll.Location, axisAll.Direction);
            var point3Ds      = new List <Point3D>();
            var firstPoint2D  = _firstPoint.ToPoint2D(axis);
            var secondPoint2D = _secondPoint.ToPoint2D(axis);

            var x1 = firstPoint2D.X;
            var y1 = firstPoint2D.Y;
            var x2 = secondPoint2D.X;
            var y2 = secondPoint2D.Y;

            point3Ds.Add(GeomUtils.Point2DTo3D(axis, x1, y1));
            point3Ds.Add(GeomUtils.Point2DTo3D(axis, x2, y1));
            point3Ds.Add(GeomUtils.Point2DTo3D(axis, x2, y2));
            point3Ds.Add(GeomUtils.Point2DTo3D(axis, x1, y2));
            var pointLinker = new SketchCreator(document).PointLinker;
            var lines       = new List <NodeBuilder>
            {
                BuildLine(Document, pointLinker, point3Ds[0], point3Ds[1]),
                BuildLine(Document, pointLinker, point3Ds[1], point3Ds[2]),
                BuildLine(Document, pointLinker, point3Ds[2], point3Ds[3]),
                BuildLine(Document, pointLinker, point3Ds[3], point3Ds[0])
            };

            return(lines);
        }
        public override gpAx2 GetPointLocation(int index)
        {
            var ax2       = new gpAx2();
            var axis      = new gpAx1();
            var point     = new gpPnt();
            var transform = NodeBuilderUtils.GetGlobalTransformation(new NodeBuilder(NodeBuilderUtils.FindSketchNode(Node)));

            point          = Dependency[0].Name == InterpreterNames.Reference ? Dependency[index].RefTransformedPoint3D.GpPnt : Dependency[index].TransformedPoint3D.GpPnt;
            axis.Location  = (point);
            axis.Direction = axis.Direction.Transformed(transform);
            ax2.Axis       = (axis);
            return(ax2);
        }
Ejemplo n.º 16
0
        public override bool Execute()
        {
            var mainAxis            = Dependency[0].Axis3D.GpAxis;
            var xAxis               = Dependency[1].Axis3D.GpAxis;
            var rectangleEdgeLength = Dependency[2].Real * CoreGlobalPreferencesSingleton.Instance.EditingHandlerZoom;
            var ax2 = new gpAx2(mainAxis.Location, mainAxis.Direction);

            ax2.XDirection = (xAxis.Direction);

            Shape = BuildTopoDsShapeHandle(ax2, rectangleEdgeLength);

            return(true);
        }
        public override bool Execute()
        {
            var mainAxis           = Dependency[0].Axis3D.GpAxis;
            var xAxis              = Dependency[1].Axis3D.GpAxis;
            var triangleEdgeLength = Dependency[2].Real;
            var ax2 = new gpAx2(mainAxis.Location, mainAxis.Direction)
            {
                XDirection = xAxis.Direction
            };

            Shape = BuildTopoDsShapeHandle(ax2, triangleEdgeLength);

            return(true);
        }
Ejemplo n.º 18
0
        private List <NodeBuilder> PreviewRectangle(Document document, Node sketchNode)
        {
            //var axis1 = new gpAx2();
            //axis1.Axis = (sketchNode.Children[1].Get<Axis3DInterpreter>().Axis.GpAxis);
            //var location = axis1.Axis.Location.Transformed(sketchNode.Get<TransformationInterpreter>().CurrTransform);
            //var direction = axis1.Axis.Direction.Transformed(sketchNode.Get<TransformationInterpreter>().CurrTransform);
            //var axis = new gpAx2(location, direction);

            var   axisAll = NodeBuilderUtils.GetTransformedAxis(new NodeBuilder(sketchNode));
            var   axis    = new gpAx2(axisAll.Location, axisAll.Direction);
            var   vec     = new gpVec(Points[0].GpPnt, Points[1].GpPnt);
            gpVec v2      = vec.Normalized;

            v2.Rotate(axis.Axis, Math.PI / 2.0);

            var parallelLine    = new gceMakeLin(Points[1].GpPnt, new gpDir(v2)).Value;
            var geomLine        = new GeomLine(parallelLine);
            var projectionPoint = new GeomAPIProjectPointOnCurve(Points[2].GpPnt, geomLine);

            var thirdPoint = new Point3D(projectionPoint.NearestPoint);

            var firstPoint2D  = Points[0].ToPoint2D(axis);
            var secondPoint2D = Points[1].ToPoint2D(axis);
            var thirdPoint2D  = thirdPoint.ToPoint2D(axis);

            var parallelLine2    = new gceMakeLin(Points[2].GpPnt, new gpDir(vec)).Value;
            var geomLine2        = new GeomLine(parallelLine2);
            var projectionPoint2 = new GeomAPIProjectPointOnCurve(Points[0].GpPnt, geomLine2);

            var fourthPoint   = new Point3D(projectionPoint2.NearestPoint);
            var fourthPoint2D = fourthPoint.ToPoint2D(axis);

            var point3Ds = new List <Point3D>();

            point3Ds.Add(GeomUtils.Point2DTo3D(axis, firstPoint2D.X, firstPoint2D.Y));
            point3Ds.Add(GeomUtils.Point2DTo3D(axis, secondPoint2D.X, secondPoint2D.Y));
            point3Ds.Add(GeomUtils.Point2DTo3D(axis, thirdPoint2D.X, thirdPoint2D.Y));
            point3Ds.Add(GeomUtils.Point2DTo3D(axis, fourthPoint2D.X, fourthPoint2D.Y));
            var pointLinker = new SketchCreator(document).PointLinker;

            var lines = new List <NodeBuilder>
            {
                BuildLine(Document, pointLinker, point3Ds[0], point3Ds[1]),
                BuildLine(Document, pointLinker, point3Ds[1], point3Ds[2]),
                BuildLine(Document, pointLinker, point3Ds[2], point3Ds[3]),
                BuildLine(Document, pointLinker, point3Ds[3], point3Ds[0])
            };

            return(lines);
        }
        public override gpAx2 GetPointLocation(int index)
        {
            if (index != 0)
            {
                return(base.GetPointLocation(index));
            }
            var prevPoint = new NodeBuilder(Dependency[0].Reference).Dependency[3].TransformedPoint3D;
            var ax2       = new gpAx2();
            var axis      = new gpAx1 {
                Location = (prevPoint.GpPnt)
            };

            ax2.Axis = (axis);
            return(ax2);
        }
        public override gpAx2 GetPointLocation(int index)
        {
            if (index < 0 || index > 2)
            {
                return(null);
            }
            var ax2          = new gpAx2();
            var transform    = NodeBuilderUtils.GetGlobalTransformation(new NodeBuilder(NodeBuilderUtils.FindSketchNode(Node)));
            var arcLocation  = Dependency[index].RefTransformedPoint3D.GpPnt;
            var pointBuilder = Dependency[0].ReferenceBuilder;
            var arcNormal    = pointBuilder[0].Reference.Children[1].Get <Axis3DInterpreter>().Axis.Direction;

            ax2.Axis = new gpAx1(arcLocation, new gpDir(arcNormal.GpPnt.XYZ).Transformed(transform));

            return(ax2);
        }
Ejemplo n.º 21
0
        public static Node AddSketchNode(Document document, Point3D point1, Point3D point2, Point3D point3)
        {
            //var sketchCreator = new SketchCreator(document);
            //var currentSketch = sketchCreator.CurrentSketch;
            var sketchNodeBuilder = new NodeBuilder(document, FunctionNames.Sketch);
            var firstvector       = new gpDir(point2.GpPnt.X - point1.GpPnt.X, point2.GpPnt.Y - point1.GpPnt.Y, point2.GpPnt.Z - point1.GpPnt.Z);
            var secondvector      = new gpDir(point3.GpPnt.X - point1.GpPnt.X, point3.GpPnt.Y - point1.GpPnt.Y, point3.GpPnt.Z - point1.GpPnt.Z);
            var normal            = firstvector.Crossed(secondvector);
            var _normalOnPlane    = new gpAx1(point1.GpPnt, normal);
            var sketchAx2         = new gpAx2();

            sketchAx2.Axis = (_normalOnPlane);
            sketchNodeBuilder[0].TransformedAxis3D = _normalOnPlane;

            return(!sketchNodeBuilder.ExecuteFunction() ? null : sketchNodeBuilder.Node);
        }
        /// <summary>
        ///   Builds an ellipse from 3 points in space
        /// </summary>
        private static TopoDSWire BuildEllipse(Point3D center, Point3D secondPoint, Point3D thirdPoint)
        {
            double minorRadius;
            double majorRadius;
            bool   reversed;
            gpDir  dirX = null;
            gpDir  dirY = null;

            if (secondPoint.GpPnt.Distance(thirdPoint.GpPnt) < Precision.Confusion)
            {
                return(null);
            }


            if (!TreeUtils.ComputeEllipseRadiuses(center, secondPoint, thirdPoint,
                                                  out minorRadius, out majorRadius, out reversed,
                                                  ref dirX, ref dirY))
            {
                return(null);
            }
            // Build a plane from the 3 points
            var plane = GeomUtils.BuildPlane(center, secondPoint, thirdPoint);
            var ax1   = plane.Axis;
            var ax2   = new gpAx2();

            ax2.Axis     = (ax1);
            ax2.Location = (center.GpPnt);

            // If major and minor radius are reversed also their directions arereversed
            if (!reversed)
            {
                ax2.XDirection = (dirX);
                ax2.YDirection = (dirY);
            }
            else
            {
                ax2.XDirection = (dirY);
                ax2.YDirection = (dirX);
            }

            var ellipse = new GeomEllipse(ax2, majorRadius, minorRadius);
            var edge    = new BRepBuilderAPIMakeEdge(ellipse).Edge;
            var wire    = new BRepBuilderAPIMakeWire(edge).Wire;

            return(wire);
        }
        private List <TopoDSWire> GetConstraintWires(Point3D firstPoint, Point3D secondPoint)
        {
            var axis2 = new gpAx2 {
                Axis = Dependency[2].TransformedAxis3D
            };
            var point3D      = GeomUtils.ComputeMidPoint(firstPoint, secondPoint);
            var pointOnplane = point3D.ToPoint2D(axis2);

            var constraintTypes = GetConstraintTypes();


            var wires    = new List <TopoDSWire>();
            var currentX = pointOnplane.X + 1;
            var currentY = pointOnplane.Y + 1;

            if (constraintTypes[2])
            {
                wires.Add(Wire(GeomUtils.Point2DTo3D(axis2, currentX + 1.5, currentY + 1.5),
                               GeomUtils.Point2DTo3D(axis2, currentX + 2.5, currentY + 1.5)));
                wires.Add(Wire(GeomUtils.Point2DTo3D(axis2, currentX + 1.5, currentY + 1),
                               GeomUtils.Point2DTo3D(axis2, currentX + 2.5, currentY + 1)));
                currentX += 1.5;
            }
            if (constraintTypes[3])
            {
                wires.Add(Wire(GeomUtils.Point2DTo3D(axis2, currentX + 1.5, currentY + 1.5),
                               GeomUtils.Point2DTo3D(axis2, currentX + 2.5, currentY + 1.5)));

                wires.Add(Wire(GeomUtils.Point2DTo3D(axis2, currentX + 2, currentY + 0.5),
                               GeomUtils.Point2DTo3D(axis2, currentX + 2, currentY + 1.5)));
                currentX += 1.5;
            }
            if (constraintTypes[0])
            {
                wires.Add(Wire(GeomUtils.Point2DTo3D(axis2, currentX + 1.5, currentY + 2.5),
                               GeomUtils.Point2DTo3D(axis2, currentX + 2.5, currentY + 2.5)));
                currentX += 1.5;
            }
            if (constraintTypes[1])
            {
                wires.Add(Wire(GeomUtils.Point2DTo3D(axis2, currentX + 2, currentY + 0.5),
                               GeomUtils.Point2DTo3D(axis2, currentX + 2, currentY + 1.5)));
                currentX += 1.5;
            }
            return(wires);
        }
        private List <TopoDSWire> GetConstraintWires(Point3D point)
        {
            var axis2 = new gpAx2 {
                Axis = Dependency[2].TransformedAxis3D
            };
            var pointOnplane = point.ToPoint2D(axis2);

            var constraintTypes = GetConstraintTypes();


            var wires    = new List <TopoDSWire>();
            var currentX = pointOnplane.X + 1;
            var currentY = pointOnplane.Y + 1;

            //if (constraintTypes[2])
            //{
            //    wires.Add(Wire(GeomUtils.Point2DTo3D(axis2, currentX + 1.5, currentY + 1.5),
            //             GeomUtils.Point2DTo3D(axis2, currentX + 2.5, currentY + 1.5)));
            //    wires.Add(Wire(GeomUtils.Point2DTo3D(axis2, currentX + 1.5, currentY + 1),
            //             GeomUtils.Point2DTo3D(axis2, currentX + 2.5, currentY + 1)));
            //    currentX += 1.5;
            //}
            //if (constraintTypes[3])
            //{
            //    wires.Add(Wire(GeomUtils.Point2DTo3D(axis2, currentX + 1.5, currentY + 1.5),
            //                   GeomUtils.Point2DTo3D(axis2, currentX + 2.5, currentY + 1.5)));

            //    wires.Add(Wire(GeomUtils.Point2DTo3D(axis2, currentX + 2, currentY + 0.5),
            //                   GeomUtils.Point2DTo3D(axis2, currentX + 2, currentY + 1.5)));
            //    currentX += 1.5;
            //}
            //if (constraintTypes[0])
            //{
            //    wires.Add(Wire(GeomUtils.Point2DTo3D(axis2, currentX + 1.5, currentY + 2.5),
            //                   GeomUtils.Point2DTo3D(axis2, currentX + 2.5, currentY + 2.5)));
            //    currentX += 1.5;
            //}
            //if (constraintTypes[1])
            //{
            //    wires.Add(Wire(GeomUtils.Point2DTo3D(axis2, currentX + 2, currentY + 0.5),
            //        GeomUtils.Point2DTo3D(axis2, currentX + 2, currentY + 1.5)));
            //    currentX += 1.5;
            //}
            return(wires);
        }
Ejemplo n.º 25
0
        public override bool Execute()
        {
            var mainAxis = Dependency[0].Axis3D.GpAxis;
            var xAxis    = Dependency[1].Axis3D.GpAxis;
            var radius   = Dependency[2].Real;
            var radius2  = Dependency[3].Real;
            var ax2      = new gpAx2(mainAxis.Location, mainAxis.Direction)
            {
                XDirection = xAxis.Direction
            };

            var torusShape = new BRepPrimAPIMakeTorus(ax2, radius * 3, radius2 / 3, 2 * Math.PI);

            Shape = torusShape.Shape;
            //Shape = GeomUtils.CreateWireCircle(mainAxis, radius * 3);

            return(true);
        }
Ejemplo n.º 26
0
        public override gpAx2 GetPointLocation(int index)
        {
            var gizmoOrientation = new gpAx2();

            switch (index)
            {
            case 0:
                gizmoOrientation.Direction  = (gp.OZ.Direction);
                gizmoOrientation.XDirection = (gp.OX.Direction);
                break;

            case 1:
                gizmoOrientation.Direction  = (gp.OZ.Direction.Reversed);
                gizmoOrientation.XDirection = (gp.OY.Direction);
                break;

            case 2:
                gizmoOrientation.Direction  = (gp.OX.Direction.Reversed);
                gizmoOrientation.XDirection = (gp.OZ.Direction);
                break;

            case 3:
                gizmoOrientation.Direction  = (gp.OZ.Direction);
                gizmoOrientation.XDirection = (gp.OX.Direction);
                break;

            case 4:
                gizmoOrientation.Direction  = (gp.OX.Direction);
                gizmoOrientation.XDirection = (gp.OY.Direction);
                break;

            case 5:
                gizmoOrientation.Direction  = (gp.OY.Direction);
                gizmoOrientation.XDirection = (gp.OZ.Direction);
                break;

            default:
                return(null);
            }

            gizmoOrientation.Location = (Node.Set <TransformationInterpreter>().Translate);
            return(gizmoOrientation);
        }
Ejemplo n.º 27
0
        private void ShowHinter(Document _document, List <SolverPreviewObject> _solverGeometry, Mouse3DPosition mouseData, gpPln sketchPlane)
        {
            var axis = sketchPlane.Axis;

            axis.Location = new Point3D(0, 0, 0).GpPnt;
            var axis2 = new gpAx2();

            axis2.Axis = axis;
            var point3D         = mouseData.Point;
            var pointOnplane    = point3D.ToPoint2D(axis2);
            var constraintHints = new bool[] { false, false, false, false };

            for (int i = 0; i < _solverGeometry.Count; i++)
            {
                if (_solverGeometry[i] is SolverEdgeTwoPointsResult)
                {
                    switch (_solverGeometry[i].Type)
                    {
                    case ("Parallel X"):
                        constraintHints[0] = true;
                        break;

                    case ("Parallel Y"):
                        constraintHints[1] = true;
                        break;

                    case ("Parallel Line"):
                        constraintHints[2] = true;
                        break;

                    case ("Perpendicular Line"):
                        constraintHints[3] = true;
                        break;
                    }
                }
            }
            var currentX = pointOnplane.X;
            var currentY = pointOnplane.Y;

            NodeBuilderUtils.DrawConstraints(_document, axis2, currentX, currentY, constraintHints);
        }
Ejemplo n.º 28
0
        public override bool Execute()
        {
            var centerAxis = Dependency[0].Axis3D;
            var ax2        = new gpAx2 {
                Axis = (centerAxis.GpAxis)
            };
            var radius1 = Dependency[1].Real;
            var radius2 = Dependency[2].Real;

            //BRepPrimAPIMakeTorus cylinderShape = new BRepPrimAPIMakeTorus(
            //    p, radius1, radius2, angle1, angle2, angle);
            var torusShape = new BRepPrimAPIMakeTorus(ax2, radius1, radius2, 2 * Math.PI);

            //if (!torusShape.IsDone())
            //    return false;

            //Pivot = centerAxis.Location;
            Shape = torusShape.Shape;

            return(true);
        }
Ejemplo n.º 29
0
        private void DrawSelectionRectangle(gpAx2 axis, Point3D _firstPoint, Point3D _secondPoint)
        {
            _document.Transact();
            var point3Ds      = new List <Point3D>();
            var firstPoint2D  = _firstPoint.ToPoint2D(axis);
            var secondPoint2D = _secondPoint.ToPoint2D(axis);

            var x1    = firstPoint2D.X;
            var y1    = firstPoint2D.Y;
            var x2    = secondPoint2D.X;
            var y2    = secondPoint2D.Y;
            var color = x1 < x2 ? Color.Gold : Color.White;

            point3Ds.Add(GeomUtils.Point2DTo3D(axis, x1, y1));
            point3Ds.Add(GeomUtils.Point2DTo3D(axis, x2, y1));
            point3Ds.Add(GeomUtils.Point2DTo3D(axis, x2, y2));
            point3Ds.Add(GeomUtils.Point2DTo3D(axis, x1, y2));
            var pointLinker = new SketchCreator(_document).PointLinker;

            lines = new List <NodeBuilder>
            {
                BuildLine(_document, pointLinker, point3Ds[0], point3Ds[1]),
                BuildLine(_document, pointLinker, point3Ds[1], point3Ds[2]),
                BuildLine(_document, pointLinker, point3Ds[2], point3Ds[3]),
                BuildLine(_document, pointLinker, point3Ds[3], point3Ds[0])
            };
            var sseList = new List <SceneSelectedEntity>();

            foreach (var line in lines)
            {
                var sse = new SceneSelectedEntity(line.Node);
                sseList.Add(sse);
            }
            var builder = new NodeBuilder(_document, FunctionNames.Face);

            builder[0].ReferenceList = sseList;
            builder.Color            = color;
            builder.ExecuteFunction();
            selectionFace = builder.Shape;
        }
        public override bool Execute()
        {
            var planeAxis       = Dependency[0].Axis3D.GpAxis;
            var xAxis           = Dependency[1].Axis3D.GpAxis;
            var rectangleLength = Dependency[2].Real * CoreGlobalPreferencesSingleton.Instance.EditingHandlerZoom;

            var ax2 = new gpAx2();

            ax2.Axis       = (planeAxis);
            ax2.XDirection = (xAxis.Direction);

            var wire = BuildPlane(ax2, 2 * rectangleLength);

            if ((wire == null) || (wire.IsNull))
            {
                return(false);
            }

            Shape = wire;

            return(true);
        }