Ejemplo n.º 1
0
        public void AllocDeallocSimpleTest()
        {
            //NaroMessage.Show("start test");
            //Console.WriteLine("---- wrapper start test ----");
            var watch = new Stopwatch();

            watch.Start();
            for (var i = 0; i < 300000; i++)
            {
                var         pnt   = new gpPnt(i, i, i);
                var         pnt2  = new gpPnt(i + 10, i + 10, i + 10);
                var         aEdge = new BRepBuilderAPIMakeEdge(pnt, pnt2).Edge;
                var         wire  = new BRepBuilderAPIMakeWire(aEdge).Wire;
                TopoDSShape shape = wire;
                new AISShape(shape);

                var pln     = new gpPln(i + 10, i + 10, i + 10, i + 10);
                var geomPln = new GeomPlane(pln);
                var trsf    = new gpTrsf();
                geomPln.Transform(trsf);
            }

            watch.Stop();
            //Console.WriteLine("---- wrapper end test - took {0} ms ----", watch.ElapsedMilliseconds);

            //NaroMessage.Show(String.Format("---- wrapper end test - took {0} ms ----", watch.ElapsedMilliseconds));
        }
        private TopoDSWire Wire(Point3D firstPoint, Point3D secondPoint)
        {
            var aEdge2 = new BRepBuilderAPIMakeEdge(firstPoint.GpPnt, secondPoint.GpPnt).Edge;
            var wire   = new BRepBuilderAPIMakeWire(aEdge2).Wire;

            return(wire);
        }
Ejemplo n.º 3
0
        public override bool Execute()
        {
            var dependency       = Builder.Node.Get <FunctionInterpreter>().Dependency;
            var firstData        = dependency[Constant.StepIndexBeamFirstNode].ReferenceData;
            var firstNode        = firstData.Node;
            var firstIndex       = firstData.ShapeCount;
            var firstPointValue  = ShapeUtils.ExtractShapesPoint(firstNode, firstIndex);
            var secondData       = dependency[Constant.StepIndexBeamSecondNode].ReferenceData;
            var secondNode       = secondData.Node;
            var secondIndex      = secondData.ShapeCount;
            var secondPointValue = ShapeUtils.ExtractShapesPoint(secondNode, secondIndex);

            if (firstPointValue.IsEqual(secondPointValue, Precision.Confusion))
            {
                return(false);
            }

            NodeUtils.Hide(firstNode);
            NodeUtils.Hide(secondNode);

            var aEdge = new BRepBuilderAPIMakeEdge(firstPointValue, secondPointValue).Edge;
            var wire  = new BRepBuilderAPIMakeWire(aEdge).Wire;

            Shape = wire;

            return(true);
        }
Ejemplo n.º 4
0
        public override bool Execute()
        {
            var edge1 = new BRepBuilderAPIMakeEdge(Dependency[0].TransformedPoint3D.GpPnt, Dependency[1].TransformedPoint3D.GpPnt).Edge;
            var edge2 = new BRepBuilderAPIMakeEdge(Dependency[1].TransformedPoint3D.GpPnt, Dependency[2].TransformedPoint3D.GpPnt).Edge;
            var edge3 = new BRepBuilderAPIMakeEdge(Dependency[2].TransformedPoint3D.GpPnt, Dependency[3].TransformedPoint3D.GpPnt).Edge;
            var edge4 = new BRepBuilderAPIMakeEdge(Dependency[3].TransformedPoint3D.GpPnt, Dependency[0].TransformedPoint3D.GpPnt).Edge;

            var mkWire = new BRepBuilderAPIMakeWire();

            mkWire.Add(edge1);
            mkWire.Add(edge2);
            mkWire.Add(edge3);
            mkWire.Add(edge4);
            TopoDSFace faceProfile = null;

            if (mkWire.IsDone)
            {
                var wireProfile = mkWire.Wire;
                if (!wireProfile.IsNull)
                {
                    faceProfile = new BRepBuilderAPIMakeFace(wireProfile, false).Face;
                }
            }

            Shape = faceProfile;

            return(true);
        }
        /// <summary>
        ///   Builds a rectangle from 3 points received as parameter
        ///   Rectangle:
        ///   P2--------P3
        ///   P1--------P4
        /// </summary>
        public static TopoDSFace BuildRectangle(Point3D firstPoint, Point3D secondPoint, Point3D thirdPoint)
        {
            var fourth = new gpPnt();

            GeomUtils.CalculateRectangleVertexes(firstPoint.GpPnt, secondPoint.GpPnt, thirdPoint.GpPnt, ref fourth);
            var fourthPoint = new Point3D(fourth);

            // Check for point coincidence
            if (firstPoint.IsEqual(secondPoint) ||
                secondPoint.IsEqual(thirdPoint) ||
                thirdPoint.IsEqual(fourthPoint) ||
                fourthPoint.IsEqual(firstPoint))
            {
                return(null);
            }

            var aEdge1 = new BRepBuilderAPIMakeEdge(firstPoint.GpPnt, secondPoint.GpPnt).Edge;
            var aEdge2 = new BRepBuilderAPIMakeEdge(secondPoint.GpPnt, thirdPoint.GpPnt).Edge;
            var aEdge3 = new BRepBuilderAPIMakeEdge(thirdPoint.GpPnt, fourthPoint.GpPnt).Edge;
            var aEdge4 = new BRepBuilderAPIMakeEdge(fourthPoint.GpPnt, firstPoint.GpPnt).Edge;

            var aWire = new BRepBuilderAPIMakeWire(aEdge1, aEdge2, aEdge3, aEdge4).Wire;

            if (aWire.IsNull)
            {
                return(null);
            }

            var faceProfile = new BRepBuilderAPIMakeFace(aWire, false).Face;

            return(faceProfile.IsNull ? null : faceProfile);
        }
        /// <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.º 7
0
        public static TopoDSFace ComposeWires(List <SceneSelectedEntity> cutShapes, bool skipFaceValidityCheck)
        {
            if (cutShapes.Count > 0)
            {
                alreadyDone.Add(cutShapes[0].Node);
                var mkWire = new BRepBuilderAPIMakeWire();
                foreach (var cutShape in cutShapes)
                {
                    var node  = cutShape.Node;
                    var shape = node.Get <TopoDsShapeInterpreter>().Shape;
                    if (shape == null)
                    {
                        break;
                    }
                    if (shape.ShapeType != TopAbsShapeEnum.TopAbs_WIRE)
                    {
                        continue;
                    }
                    var wire = TopoDS.Wire(shape);
                    mkWire.Add(wire);
                }

                if (mkWire.IsDone)
                {
                    // If the wire generation succeeded generate a Face from it
                    var wireProfile = mkWire.Wire;
                    if (!wireProfile.IsNull)
                    {
                        var faceProfile = new BRepBuilderAPIMakeFace(wireProfile, true).Face;
                        if (!faceProfile.IsNull)
                        {
                            // The face is generated not checking if it is a valid face
                            if (skipFaceValidityCheck)
                            {
                                return(faceProfile);
                            }

                            // Check if it is a valid shape
                            var analyzer = new BRepCheckAnalyzer(faceProfile, true);
                            if (analyzer.IsValid())
                            {
                                return(faceProfile);
                            }
                        }
                    }
                }
            }

            return(null);
        }
        /// <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);
        }
        public override bool Execute()
        {
            var firstPoint       = Dependency[0].TransformedPoint3D;
            var secondPoint      = Dependency[1].TransformedPoint3D;
            var colorOrientation = Dependency[2].Integer;
            var color            = QuantityNameOfColor.Quantity_NOC_RED;
            var aEdge            = new BRepBuilderAPIMakeEdge(firstPoint.GpPnt, secondPoint.GpPnt).Edge;
            var wire             = new BRepBuilderAPIMakeWire(aEdge).Wire;
            var temporaryShape   = new AISShape(wire);
            var drawer           = temporaryShape.Attributes;

            //need fixed the coloring
            //     drawer.WireAspect = (new Prs3dLineAspect(color, AspectTypeOfLine.Aspect_TOL_DOT,3));

            Interactive = temporaryShape;
            return(true);
        }
Ejemplo n.º 10
0
        public override bool Execute()
        {
            var firstPoint  = Dependency[0].RefTransformedPoint3D;
            var secondPoint = Dependency[1].RefTransformedPoint3D;

            if (firstPoint.IsEqual(secondPoint))
            {
                return(false);
            }

            var aEdge = new BRepBuilderAPIMakeEdge(firstPoint.GpPnt, secondPoint.GpPnt).Edge;
            var wire  = new BRepBuilderAPIMakeWire(aEdge).Wire;

            Shape = wire;

            return(true);
        }
        public static TopoDSShape CreateArcShape(Point3D point1, Point3D point2, Point3D point3)
        {
            if (point1.IsEqual(point2) || point1.IsEqual(point3) || point2.IsEqual(point3))
            {
                return(null);
            }

            var line = new gpLin(point1.GpPnt, new gpDir(new gpVec(point1.GpPnt, point2.GpPnt)));

            if (line.Distance(point3.GpPnt) < Precision.Confusion)
            {
                return(null);
            }

            var gceCirc    = new gceMakeCirc(point1.GpPnt, point2.GpPnt, point3.GpPnt);
            var circle     = gceCirc.Value;
            var arc        = new GCMakeArcOfCircle(circle, point2.GpPnt, point1.GpPnt, true);
            var curve      = arc.Value;
            var edge       = new BRepBuilderAPIMakeEdge(curve).Edge;
            var circleWire = new BRepBuilderAPIMakeWire(edge).Wire;

            return(circleWire);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///   Apply fillet on a list of wires. The common endpoints of wires are considered the fillet vertexes.
        /// </summary>
        private static TopoDSWire ApplyFilletOnWires(IEnumerable <SceneSelectedEntity> filletNodes, double radius,
                                                     int filletChamferType)
        {
            // This method processes only fillet2D and chamfer2D operations
            if ((filletChamferType != (int)FilletChamferTypes.SimpleFillet2D) &&
                (filletChamferType != (int)FilletChamferTypes.SimpleChamfer2D))
            {
                return(null);
            }

            try
            {
                // Make a face fom the wires
                var wires = new List <SceneSelectedEntity>();
                foreach (var node in filletNodes)
                {
                    wires.Add(node);
                }
                var face = MakeFaceFunction.ComposeWires(wires, true);

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

                var fillet = new BRepFilletAPIMakeFillet2d();
                // Initialize a fillet with the face made from the 2 wires
                fillet.Init(face);

                // Fillet the common vertexes
                Node previousNode = null;
                foreach (var node in filletNodes)
                {
                    if (previousNode != null)
                    {
                        var wire1 = previousNode.Get <NamedShapeInterpreter>().Shape;
                        var wire2 = node.Node.Get <NamedShapeInterpreter>().Shape;
                        var listOfCommonVertex = GeomUtils.CommonVertexes(wire1, wire2);
                        if (listOfCommonVertex.Count >= 1)
                        {
                            foreach (var vertex in listOfCommonVertex)
                            {
                                if (filletChamferType == (int)FilletChamferTypes.SimpleFillet2D)
                                {
                                    // If the operation is a fillet
                                    fillet.AddFillet(vertex, radius);
                                }
                                else
                                {
                                    // Map all edges to faces
                                    var map = new TopToolsIndexedDataMapOfShapeListOfShape(1);
                                    TopExp.MapShapesAndAncestors(wire1, TopAbsShapeEnum.TopAbs_VERTEX,
                                                                 TopAbsShapeEnum.TopAbs_EDGE, map);

                                    // Locate an ancestor face
                                    for (var i = 1; i <= map.Extent; i++)
                                    {
                                        var localVertex = TopoDS.Vertex(map.FindKey(i));
                                        if (!vertex.IsSame(localVertex))
                                        {
                                            continue;
                                        }
                                        // We found an ancestor edge
                                        var edge = TopoDS.Edge(map.FindFromIndex(i).First);
                                        // Add the vertex and edge on the chamfer algorithm
                                        //fillet.AddChamfer(TopoDS.Edge(edge), TopoDS.Edge(edge2), radius, radius);
                                        fillet.AddChamfer(TopoDS.Edge(edge), vertex, radius,
                                                          GeomUtils.DegreesToRadians(45));
                                    }
                                }
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    previousNode = node.Node;
                }

                // Test if the operation succeeded
                if (fillet.Status != ChFi2dConstructionError.ChFi2d_IsDone)
                {
                    return(null);
                }

                var shape = fillet.Shape;
                if ((shape == null) || (shape.IsNull))
                {
                    return(null);
                }

                var aMap = new TopToolsIndexedMapOfShape(1);
                TopExp.MapShapes(fillet.Shape, TopAbsShapeEnum.TopAbs_WIRE, aMap);
                if (aMap.Extent != 1)
                {
                    return(null);
                }

                var newWire = new BRepBuilderAPIMakeWire();
                var ex      = new BRepToolsWireExplorer(TopoDS.Wire(aMap.FindKey(1)));
                for (; ex.More; ex.Next())
                {
                    newWire.Add(ex.Current);
                }

                return(newWire.Wire);
            }
            catch (Exception ex)
            {
                Log.Error("Apply Fillet2D error: " + ex.Message);
            }

            return(null);
        }
Ejemplo n.º 13
0
        public override bool Execute()
        {
            var wireToTrim = Dependency[1].ReferenceData;
            //if (wireToTrim.ShapeType() != OCTopAbs_ShapeEnum.TopAbs_WIRE)
            //    return false;
            var   trimmingWires = Dependency[0].ReferenceList;
            gpPnt clickPoint;

            try
            {
                clickPoint = Dependency[2].ReferenceBuilder[1].TransformedPoint3D.GpPnt;
            }
            catch (Exception)
            {
                // trim action is called when other shapes are updated
                return(false);
            }

            var profileLocation          = wireToTrim.TargetShape().Location();
            var profileTranslation       = new gpTrsf();
            var profileTranslationVector = profileLocation.Transformation.TranslationPart.Reversed;

            profileTranslation.TranslationPart = (profileTranslationVector);
            var newProfileLocation = new TopLocLocation(profileTranslation);

            foreach (var wire in trimmingWires)
            {
                wire.Node.Get <TopoDsShapeInterpreter>().Shape.Move(newProfileLocation);
            }
            wireToTrim.Node.Get <TopoDsShapeInterpreter>().Shape.Move(newProfileLocation);
            clickPoint.Translate(profileTranslationVector);

            var trimmingEdges = new List <TopoDSEdge>();

            foreach (var trimming in trimmingWires)
            {
                //if (trimming.ShapeType != OCTopAbs_ShapeEnum.TopAbs_WIRE)
                //    return false;
                var trimmingE = GeomUtils.ExtractEdges(trimming.TargetShape());
                if (trimmingE.Count > 0)
                {
                    trimmingEdges.AddRange(trimmingE);
                }
            }
            if (trimmingEdges.Count <= 0)
            {
                return(false);
            }

            var edgesToTrim = GeomUtils.ExtractEdges(wireToTrim.TargetShape());

            if (edgesToTrim.Count <= 0)
            {
                return(false);
            }

            var resultShapes = GeomUtils.TrimGenericShape(trimmingEdges, edgesToTrim[0], new Point3D(clickPoint));

            if (resultShapes.Count <= 0)
            {
                return(false);
            }

            var finalWire = new BRepBuilderAPIMakeWire();

            foreach (var edge in resultShapes)
            {
                finalWire.Add(edge);
            }

            /*
             * foreach (var wire in trimmingWires)
             * {
             *  wire.Node.Get<TopoDsShapeInterpreter>().Shape.Move(newProfileLocation.Inverted);
             * }
             * wireToTrim.Node.Get<TopoDsShapeInterpreter>().Shape.Move(newProfileLocation.Inverted);
             * clickPoint.Translate(profileTranslationVector.Reversed);
             */
            Shape = finalWire.Wire;

            return(true);
        }