Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }