Beispiel #1
0
        //--------------------------------------------------------------------------------------------------

        void _PreviewBaseRect(ToolAction toolAction)
        {
            if (!(toolAction is PointAction pointAction))
            {
                return;
            }

            _ClearPreviews();

            _PointPlane2 = pointAction.PointOnPlane;

            if (_PointPlane1.IsEqual(_PointPlane2, Double.Epsilon))
            {
                return;
            }

            var face = new BRepBuilderAPI_MakeFace(WorkspaceController.Workspace.WorkingPlane,
                                                   Math.Min(_PointPlane1.X, _PointPlane2.X),
                                                   Math.Max(_PointPlane1.X, _PointPlane2.X),
                                                   Math.Min(_PointPlane1.Y, _PointPlane2.Y),
                                                   Math.Max(_PointPlane1.Y, _PointPlane2.Y)).Face();

            _AisPreviewEdges = new AIS_Shape(face);
            _AisPreviewEdges.SetDisplayMode(0);
            WorkspaceController.Workspace.AisContext.Display(_AisPreviewEdges, false);
            WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewEdges);

            _AisPreviewSolid = new AIS_Shape(face);
            _AisPreviewSolid.SetDisplayMode(1);
            WorkspaceController.Workspace.AisContext.Display(_AisPreviewSolid, false);
            WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewSolid);

            var dim1 = Math.Abs(_PointPlane1.X - _PointPlane2.X);
            var dim2 = Math.Abs(_PointPlane1.Y - _PointPlane2.Y);

            StatusText = $"Select opposite corner point. Size: {dim1:0.00} x {dim2:0.00}";

            if (_Coord2DHudElement != null)
            {
                _Coord2DHudElement.CoordinateX = pointAction.PointOnPlane.X;
                _Coord2DHudElement.CoordinateY = pointAction.PointOnPlane.Y;
            }

            if (_MultiValueHudElement != null)
            {
                _MultiValueHudElement.Value1 = dim1;
                _MultiValueHudElement.Value2 = dim2;
            }

            WorkspaceController.Invalidate();
        }
Beispiel #2
0
        //--------------------------------------------------------------------------------------------------

        public static TopoDS_Shape CreateFacesFromWires(TopoDS_Shape sourceShape, Pln plane)
        {
            var wires = sourceShape.Wires();

            // Create faces from closed wires
            var openWireCount   = 0;
            var closedWireCount = 0;
            var makeFace        = new BRepBuilderAPI_MakeFace(plane);

            foreach (var wire in wires)
            {
                var checkWire = new BRepCheck_Wire(wire);
                if (checkWire.Closed() != BRepCheck_Status.BRepCheck_NoError)
                {
                    openWireCount++;
                    continue;
                }
                makeFace.Add(wire);
                closedWireCount++;
            }

            if (openWireCount > 0)
            {
                Messages.Warning("Source shape has " + openWireCount + " unclosed wires, which will be ignored.");
            }

            if (closedWireCount == 0)
            {
                Messages.Warning("Source shape has no closed wires.");
                return(new TopoDS_Face());
            }

            if (!makeFace.IsDone())
            {
                Messages.Error("Generating faces from source wires failed.");
                return(null);
            }

            // Fix orientation of that faces
            var shapeFix = new ShapeFix_Shape(makeFace.Face());

            shapeFix.Perform();

            return(shapeFix.Shape());
        }
Beispiel #3
0
        public override void Build()
        {
            double wallThick = wallThickness.Meters;
            double diam      = diameter.Meters;
            double crownRad  = crownRadius.Meters;
            double knucleRad = knucleRadius.Meters;
            double totalH    = totalHeight.Meters;
            double use1      = useless1.Meters;
            double use2      = useless2.Bars;
            string use3      = useless3;

            //  can't work if P == O
            if (crownRadius == knucleRadius)
            {
                return;
            }

            // _____________curved part_____________
            // on va définir un certain nombre de points
            // certains avec des intersections de cercles, donc va y avoir un peu de calculs...
            gp_Pnt A = new gp_Pnt(wallThick, 0, 0);                                                                                                            // point à droite de la base
            gp_Pnt B = new gp_Pnt(0, 0, 0);                                                                                                                    // point à gauche de la base
            gp_Pnt C = new gp_Pnt(0, totalH, 0);                                                                                                               // debut de l'arc exterieur
            gp_Pnt H = new gp_Pnt(wallThick, totalH, 0);                                                                                                       // debut de l'arc intérieur
            gp_Pnt P = new gp_Pnt(wallThick + crownRad, totalH, 0);                                                                                            // centre du petit cercle formant l'arc
            gp_Pnt O = new gp_Pnt(wallThick + knucleRad, totalH, 0);                                                                                           // centre du grand cercle formant le capot

            gp_Pnt a1 = new gp_Pnt(crownRad * Math.Cos(3 * Math.PI / 4) + P.X(), crownRad * Math.Sin(3 * Math.PI / 4) + P.Y(), 0);                             // point de l'arc de cercle intérieur
            gp_Pnt a2 = new gp_Pnt((crownRad + wallThick) * Math.Cos(3 * Math.PI / 4) + P.X(), (crownRad + wallThick) * Math.Sin(3 * Math.PI / 4) + P.Y(), 0); // point de l'arc de cercle extérieur
            // pour a3 et a4 c'est compliqué, je crois que je dois choisir un angle au hasard et que potentiellement ça peut tout niquer (si R2 trop petit comparé à R1)
            //gp_Pnt a3 = new gp_Pnt(-radius2 * Math.Cos(3 * Math.PI / 4) + thickness + radius2, radius2* Math.Sin(3 * Math.PI / 4)+ totalHeight - thickness - radius2, 0); // point de l'arc du capot intérieur
            //gp_Pnt a4 = new gp_Pnt(-(radius2 + thickness) * Math.Cos(3 * Math.PI / 4) + thickness + radius2, (radius2 + thickness) * Math.Sin(3 * Math.PI / 4) + totalHeight - thickness - radius2, 0); // point de l'arc du capot extérieur
            gp_Pnt E = new gp_Pnt(O.X(), O.Y() + knucleRad + wallThick, 0); // haut du capot
            gp_Pnt F = new gp_Pnt(O.X(), O.Y() + knucleRad, 0);             // haut du capot mais côté intérieur
            // maintenant il faut définir les intersections des arcs de cercle et du capot
            // soit l'intersection du cercle de rayon myRadius1(R1) et de centre P (que l'on va abréger P(R1) ) avec O(R2)
            // et également (myThickness=T) P(R1+T) avec O(R2+T)



            gp_Pnt G = new gp_Pnt(P.X(), P.Y() + crownRad, 0);             // point de l'arc de cercle intérieur
            gp_Pnt D = new gp_Pnt(P.X(), P.Y() + crownRad + wallThick, 0); // point de l'arc de cercle extérieur


            // maintenant qu'on a tous nos points faut les relier ;)
            TopoDS_Edge AB = new BRepBuilderAPI_MakeEdge(A, B).Edge();
            TopoDS_Edge BC = new BRepBuilderAPI_MakeEdge(B, C).Edge();

            GC_MakeArcOfCircle      Ca2D   = new GC_MakeArcOfCircle(C, a2, D);
            BRepBuilderAPI_MakeEdge meCa2D = new BRepBuilderAPI_MakeEdge(Ca2D.Value());
            TopoDS_Edge             CD     = meCa2D.Edge();

            TopoDS_Edge DE = new BRepBuilderAPI_MakeEdge(D, E).Edge();
            TopoDS_Edge EF = new BRepBuilderAPI_MakeEdge(E, F).Edge();
            TopoDS_Edge FG = new BRepBuilderAPI_MakeEdge(F, G).Edge();

            GC_MakeArcOfCircle      Ga1H   = new GC_MakeArcOfCircle(G, a1, H);
            BRepBuilderAPI_MakeEdge meGa1H = new BRepBuilderAPI_MakeEdge(Ga1H.Value());
            TopoDS_Edge             GH     = meGa1H.Edge();

            TopoDS_Edge HA = new BRepBuilderAPI_MakeEdge(H, A).Edge();


            // creating the wire
            BRepBuilderAPI_MakeWire aMakeWire = new BRepBuilderAPI_MakeWire(AB, BC, CD, DE);
            TopoDS_Wire             aWire     = aMakeWire.Wire();

            aMakeWire = new BRepBuilderAPI_MakeWire(aWire, EF);
            aWire     = aMakeWire.Wire();
            aMakeWire = new BRepBuilderAPI_MakeWire(aWire, FG);
            aWire     = aMakeWire.Wire();
            aMakeWire = new BRepBuilderAPI_MakeWire(aWire, GH);
            aWire     = aMakeWire.Wire();
            aMakeWire = new BRepBuilderAPI_MakeWire(aWire, HA);
            aWire     = aMakeWire.Wire();//*/


            // rotation du wire
            gp_Ax1 Axis = new gp_Ax1(new gp_Pnt(wallThick + knucleRad, 0, 0), new gp_Dir(0, 1, 0)); // origine 0,0,0 avec dir 0,1,0
            BRepBuilderAPI_MakeFace aMakeFace  = new BRepBuilderAPI_MakeFace(aWire);
            TopoDS_Face             face       = aMakeFace.Face();
            BRepPrimAPI_MakeRevol   aMakeRevol = new BRepPrimAPI_MakeRevol(face, Axis, 2 * Math.PI);

            aMakeRevol.Build();
            TopoDS_Shape aRotatedShape = aMakeRevol.Shape();


            // _____________triangulation_____________
            SetMyFaces(Triangulation(aRotatedShape, 0.007f));
            //*/
        }
        //--------------------------------------------------------------------------------------------------

        void _PreviewRadius(ToolAction toolAction)
        {
            if (!(toolAction is PointAction pointAction))
            {
                return;
            }

            _ClearPreviews();

            _PointPlane2 = pointAction.PointOnPlane;

            if (_PointPlane1.IsEqual(_PointPlane2, Double.Epsilon))
            {
                return;
            }

            _Radius = new Vec2d(_PointPlane1, _PointPlane2).Magnitude();
            if (_Radius <= Double.Epsilon)
            {
                return;
            }

            var makeCircle = new gce_MakeCirc(_PivotPoint, _Plane.Axis.Direction, _Radius);

            if (!makeCircle.IsDone())
            {
                return;
            }

            var makeEdge = new BRepBuilderAPI_MakeEdge(makeCircle.Value());

            if (!makeEdge.IsDone())
            {
                return;
            }

            var makeWire = new BRepBuilderAPI_MakeWire(makeEdge.Edge());

            if (!makeWire.IsDone())
            {
                return;
            }

            var makeFace = new BRepBuilderAPI_MakeFace(makeWire.Wire(), true);

            if (!makeFace.IsDone())
            {
                return;
            }

            _AisPreviewEdges = new AIS_Shape(makeFace.Face());
            _AisPreviewEdges.SetDisplayMode(0);
            WorkspaceController.Workspace.AisContext.Display(_AisPreviewEdges, false);
            WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewEdges);

            _AisPreviewSolid = new AIS_Shape(makeFace.Face());
            _AisPreviewSolid.SetDisplayMode(1);
            WorkspaceController.Workspace.AisContext.Display(_AisPreviewSolid, false);
            WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewSolid);

            StatusText = $"Select radius: {_Radius:0.00}";
            if (_ValueHudElement != null)
            {
                _ValueHudElement.Value = _Radius;
            }

            if (_Coord2DHudElement != null)
            {
                _Coord2DHudElement.CoordinateX = pointAction.PointOnPlane.X;
                _Coord2DHudElement.CoordinateY = pointAction.PointOnPlane.Y;
            }
        }
Beispiel #5
0
        //--------------------------------------------------------------------------------------------------

        bool _DoOffset(MakeContext context)
        {
            if (_Offset <= 0)
            {
                return(false);
            }

            // Move neutral plane
            var newPlane = context.NeutralPlane.Translated(context.Direction.ToVec().Multiplied(_Offset));

            // Create section edge
            var faceOfPlane = new BRepBuilderAPI_MakeFace(new Geom_Plane(newPlane), Precision.Confusion()).Shape();
            var section     = new BRepAlgoAPI_Section(context.Face, faceOfPlane);

            section.Build();
            if (!section.IsDone())
            {
                Messages.Warning("The offset can not be performed, section operation failed.");
                return(false);
            }
            var newEdge = section.Shape().Edges().FirstOrDefault();

            if (!section.IsDone() || newEdge == null)
            {
                Messages.Warning("The offset value seems to be out of range.");
                return(false);
            }

            if (context.ReversedFaceSense)
            {
                newEdge.Orientation(TopAbs_Orientation.TopAbs_REVERSED);
            }

            // Split face with section edge
            var splitShape = new BRepFeat_SplitShape(context.Source);

            splitShape.Add(newEdge, context.Face);
            splitShape.Build();
            if (!splitShape.IsDone())
            {
                Messages.Warning("The offset can not be performed, the face split operation failed.");
                return(false);
            }
            var newShape = splitShape.Shape();
            var newFace  = splitShape.DirectLeft().First().ToFace();

            // Reduce continuity of new edge to C0 to allow the draft algo to make a sharp corner
            var(face1, face2) = EdgeAlgo.FindAdjacentFaces(newShape, newEdge);
            if (face1 == null || face2 == null)
            {
                Messages.Warning("The offset can not be performed, invalid face count after split operation.");
                return(false);
            }
            var builder = new BRep_Builder();

            builder.Continuity(newEdge, face1, face2, GeomAbs_Shape.GeomAbs_C0);

            // Set results
            context.NeutralPlane = newPlane;
            context.Source       = newShape;
            context.Face         = newFace;
            UpdateModifiedSubshapes(context.Source, splitShape);

            return(true);
        }