示例#1
0
        public override SolverPreviewObject InterestingShapeAroundPoint(gpPln planeOfTheView, Point3D currentPoint,
                                                                        Point3D initialPosition)
        {
            if (currentPoint.IsEqual(initialPosition))
            {
                return(null);
            }

            var qosLock = QosFactory.Instance.Get(QosNames.ParallelLineLock);

            qosLock.Begin();

            var vec = new gpVec(initialPosition.GpPnt, currentPoint.GpPnt);

            foreach (var solverGeometricObject in Geometry)
            {
                if (solverGeometricObject.ParallelAxis.Count == 0)
                {
                    continue;
                }
                foreach (var axis in solverGeometricObject.ParallelAxis)
                {
                    if (vec.IsNormal(axis.Vector, _precision))
                    {
                        var   planeNormal     = vec.Crossed(axis.Vector);
                        var   planeNormalAxis = new gpAx1(initialPosition.GpPnt, new gpDir(planeNormal));
                        gpVec v2 = axis.Vector.Normalized;
                        v2.Rotate(planeNormalAxis, Math.PI / 2.0);

                        var parallelLine    = new gceMakeLin(initialPosition.GpPnt, new gpDir(v2)).Value;
                        var geomLine        = new GeomLine(parallelLine);
                        var projectionPoint = new GeomAPIProjectPointOnCurve(currentPoint.GpPnt, geomLine);

                        if (projectionPoint.NbPoints <= 0)
                        {
                            return(null);
                        }
                        var secondPoint = new Point3D(projectionPoint.NearestPoint);
                        var solverPoint = new SolverEdgeTwoPointsResult(secondPoint, initialPosition, Color.Black)
                        {
                            Type = "Perpendicular Line"
                        };
                        return(solverPoint);
                    }
                }
            }
            qosLock.End();

            return(null);
        }
        public static Point3D?ProjectPointOnLine(Point3D firstLinePoint, gpDir lineDirection, Point3D pointToProject)
        {
            // Make a parallel line with this line starting from the initial point
            var projectionLine  = new gceMakeLin(firstLinePoint.GpPnt, lineDirection).Value;
            var geomLine        = new GeomLine(projectionLine);
            var projectionPoint = new GeomAPIProjectPointOnCurve(pointToProject.GpPnt, geomLine);

            if (projectionPoint.NbPoints > 0)
            {
                return(new Point3D(projectionPoint.NearestPoint));
            }

            return(null);
        }
        private Point3D?GetOtherPoint(Point3D firstLinePoint, Point3D secondLinePoint,
                                      gpDir direction)
        {
            // Make a parallel line with this line starting from the initial point
            var parallelLine    = new gceMakeLin(firstLinePoint.GpPnt, direction).Value;
            var geomLine        = new GeomLine(parallelLine);
            var projectionPoint = new GeomAPIProjectPointOnCurve(secondLinePoint.GpPnt, geomLine);

            if (projectionPoint.NbPoints <= 0)
            {
                return(null);
            }
            return(new Point3D(projectionPoint.NearestPoint));
        }
示例#4
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);
        }
        /// <summary>
        ///   Calculates the projection of the second line point on the direction so that the line created from
        ///   [first point, projection] is parallel with direction.
        /// </summary>
        /// <param name = "firstLinePoint"></param>
        /// <param name = "secondLinePoint"></param>
        /// <param name = "direction"></param>
        /// <param name = "color"></param>
        /// <returns></returns>
        public static SolverPreviewObject ProjectPointOnDirection(Point3D firstLinePoint, Point3D secondLinePoint,
                                                                  gpDir direction, Color color)
        {
            // Make a parallel line with this line starting from the initial point
            var parallelLine    = new gceMakeLin(firstLinePoint.GpPnt, direction).Value;
            var geomLine        = new GeomLine(parallelLine);
            var projectionPoint = new GeomAPIProjectPointOnCurve(secondLinePoint.GpPnt, geomLine);

            if (projectionPoint.NbPoints <= 0)
            {
                return(null);
            }
            var firstParallelPoint  = new Point3D(projectionPoint.NearestPoint);
            var secondParallelPoint = firstLinePoint;
            var solverPoint         = new SolverEdgeTwoPointsResult(firstParallelPoint, secondParallelPoint, color)
            {
                Type = "Parallel Line"
            };

            return(solverPoint);
        }