Performed edge creation, wire creation, and curve offset functions through wires, as well as display functions.
void ViewWindow::OnGen2dCurve() { // Clear All _ctrlUi->listView->Clear(); try { //Construct a line segment GC_MakeSegment Segment1(gp_Pnt(20, 0, 0), gp_Pnt(30, 0, 0)); //Construct an edge based on the line segment BRepBuilderAPI_MakeEdge anEdge(Segment1.Value()); BRepBuilderAPI_MakeEdge anEdge2(gp_Pnt(30, 0, 0), gp_Pnt(30, 20, 0)); \t\t BRepBuilderAPI_MakeEdge anEdge3(gp_Pnt(30, 20, 0), gp_Pnt(20, 0, 0)); //aWire.Add(anEdge3.Edge()); GC_MakeArcOfCircle arc4(gp_Pnt(30, 20, 0), gp_Pnt(34.651, 31.229, 0), gp_Pnt(45.88, 35.88, 0)); BRepBuilderAPI_MakeEdge anEdge4(arc4.Value()); construct a circle double dr5 = 49.4178; double dAngelS5 = 98.82; double dAngelE5 = 94.4815; double dCenterX5 = 41.2769; double dCenterY5 = -12.4703; double dx5 = dr5 * cos(((dAngelE5 - dAngelS5) / 2 + dAngelS5) * M_PI / 180) + dCenterX5; double dy5 = dr5 * sin(((dAngelE5 - dAngelS5) / 2 + dAngelS5) * M_PI / 180) + dCenterY5; double dxs5 = dr5 * cos(dAngelS5 * M_PI / 180) + dCenterX5; double dys5 = dr5 * sin(dAngelS5 * M_PI / 180) + dCenterY5; double dxe5 = dr5 * cos(dAngelE5 * M_PI / 180) + dCenterX5; double dye5 = dr5 * sin(dAngelE5 * M_PI / 180) + dCenterY5; //GC_MakeArcOfCircle arc5(gp_Pnt(33.7, 36.363, 0), gp_Pnt(35.554, 36.615, 0),gp_Pnt(37.416, 36.796, 0)); GC_MakeArcOfCircle arc5(gp_Pnt(dxs5, dys5, 0), gp_Pnt(dx5, dy5, 0), gp_Pnt(dxe5, dye5, 0)); BRepBuilderAPI_MakeEdge anEdge5(arc5.Value()); // gp_Circ circle55(gp_Ax2(gp_Pnt(41.277, -12.470, 0), gp_Dir(0, 0, 1)), 49.418); // //Construct an arc edge // GC_MakeArcOfCircle arc55(circle55, 94.481*M_PI/180, 98.82 * M_PI / 180,Standard_True); // const Handle(Geom_TrimmedCurve) TrimmedCurve5 = arc55.Value(); // //Find the midpoint position // Standard_Real first5 = TrimmedCurve5->FirstParameter(); // Standard_Real Last5 = TrimmedCurve5->LastParameter(); // Standard_Real mid5 = (Last5 - first5) / 2 + first5; //GC_MakeArcOfCircle arc5(TrimmedCurve5->Value(first5), // TrimmedCurve5->Value(mid5), // TrimmedCurve5->Value(Last5)); //BRepBuilderAPI_MakeEdge anEdge5(arc5.Value()); Standard_Real fBegin5 = 0, fEnd5 = 0; Handle(Geom_Curve) hCurveEdge5 = BRep_Tool::Curve(anEdge5, fBegin5, fEnd5); Handle(Geom_Circle) circle5 = Handle_Geom_Circle::DownCast(hCurveEdge5); // handle circle objects here qDebug() << "Circle5"; //Read the arc starting point and end point coordinates qDebug() << "start5:[" << circle5->Value(fBegin5).X() << "," << circle5->Value(fBegin5).Y() << ", " << circle5->Value(fBegin5).Z() << "]"; qDebug() << "end5:[" << circle5->Value(fEnd5).X() << "," << circle5->Value(fEnd5).Y() << ", " << circle5->Value(fEnd5).Z() << "]"; qDebug() << "mid5:[" << circle5->Value((fEnd5- fBegin5)/2 + fBegin5).X() << "," << circle5->Value((fEnd5 - fBegin5) / 2 + fBegin5).Y() << "," << circle5->Value((fEnd5 - fBegin5) / 2 + fBegin5).Z() << "]"; qDebug() << "R5:" << circle5->Radius(); const gp_Circ & amp; circ5 = circle5->Circ(); const gp_Pnt & amp; center5 = circ5.Location(); // Get the coordinates of the circle center qDebug() << "Center5:[" << center5.X() << "," << center5.Y() << "," << center5.Z() << "]"; //gp_Circ circle66(gp_Ax2(gp_Pnt(41.329, -13.129, 0), gp_Dir(0, 0, 1)), 50.078); Construct an arc edge //GC_MakeArcOfCircle arc66(circle66, 90.199 * M_PI / 180,94.481 * M_PI / 180, Standard_True); //const Handle(Geom_TrimmedCurve) TrimmedCurve6 = arc66.Value(); Find the position of the midpoint //Standard_Real first6 = TrimmedCurve6->FirstParameter(); //Standard_Real Last6 = TrimmedCurve6->LastParameter(); //Standard_Real mid6 = (Last6 - first6) / 2 + first6; //GC_MakeArcOfCircle arc6(TrimmedCurve6->Value(first6), // TrimmedCurve6->Value(mid6), // TrimmedCurve6->Value(Last6)); double dr6 = 50.0781; double dAngelS6 = 94.4815; double dAngelE6 = 90.1993; double dCenterX6 = 41.3285; double dCenterY6 = -13.1286; double dx6 = dr6 * cos(((dAngelE6 - dAngelS6) / 2 + dAngelS6) * M_PI / 180) + dCenterX6; double dy6 = dr6 * sin(((dAngelE6 - dAngelS6) / 2 + dAngelS6) * M_PI / 180) + dCenterY6; double dxs6 = dr6 * cos(dAngelS6 * M_PI / 180) + dCenterX6; double dys6 = dr6 * sin(dAngelS6 * M_PI / 180) + dCenterY6; double dxe6 = dr6 * cos(dAngelE6 * M_PI / 180) + dCenterX6; double dye6 = dr6 * sin(dAngelE6 * M_PI / 180) + dCenterY6; //GC_MakeArcOfCircle arc6(gp_Pnt(37.416, 36.796, 0), gp_Pnt(39.283, 36.908, 0), gp_Pnt(41.154, 36.949, 0)); GC_MakeArcOfCircle arc6(gp_Pnt(dxe5, dye5, 0), gp_Pnt(dx6, dy6, 0), gp_Pnt(dxe6, dye6, 0)); BRepBuilderAPI_MakeEdge anEdge6(arc6.Value()); Standard_Real fBegin6 = 0, fEnd6 = 0; Handle(Geom_Curve) hCurveEdge6 = BRep_Tool::Curve(anEdge6, fBegin6, fEnd6); Handle(Geom_Circle) circle6 = Handle_Geom_Circle::DownCast(hCurveEdge6); // handle circle objects here qDebug() << "Circle6"; //Read the arc starting point and end point coordinates qDebug() << "start6:[" << circle6->Value(fBegin6).X() << "," << circle6->Value(fBegin6).Y() << ", " << circle6->Value(fBegin6).Z() << "]"; qDebug() << "end6:[" << circle6->Value(fEnd6).X() << "," << circle6->Value(fEnd6).Y() << ", " << circle6->Value(fEnd6).Z() << "]"; qDebug() << "R6:" << circle6->Radius(); const gp_Circ & amp; circ6 = circle6->Circ(); const gp_Pnt & amp; center6 = circ6.Location(); // Get the coordinates of the center of the circle qDebug() << "Center6:[" << center6.X() << "," << center6.Y() << "," << center6.Z() << "]"; Handle(Geom2d_Circle) circle = new Geom2d_Circle(gp_Ax2d(gp_Pnt2d(center6.X(), center6.Y()) , gp_Dir2d(1, 0)), dr6); Handle(Geom2d_TrimmedCurve) trimmedCurve61 = new Geom2d_TrimmedCurve(circle, dAngelS6*M_PI/180, dAngelE6 * M_PI / 180); Geom2d_OffsetCurve OffsetCurve61(trimmedCurve61, -0.2); // Get the starting point and ending point gp_Pnt2d startPoint66 = OffsetCurve61.Value(OffsetCurve61.FirstParameter()); gp_Pnt2d endPoint66 = OffsetCurve61.Value(OffsetCurve61.LastParameter()); qDebug() << "startPoint66:(" << startPoint66.X() << "," << startPoint66.Y() << ")"; qDebug() << "endPoint66:(" << endPoint66.X() << "," << endPoint66.Y() << ")"; GC_MakeSegment Segment7(gp_Pnt(dxe6, dye6, 0), gp_Pnt(41.901, 37.697, 0)); BRepBuilderAPI_MakeEdge anEdge7(Segment7.Value()); gp_Pnt2d piont71(dxe6, dye6); gp_Pnt2d piont72(41.901, 37.697); GCE2d_MakeSegment seg71(piont71, piont72); Geom2d_OffsetCurve OffsetCurve71(seg71.Value(), 0.2); // Get the starting point and ending point gp_Pnt2d startPoint77 = OffsetCurve71.Value(OffsetCurve71.FirstParameter()); gp_Pnt2d endPoint77 = OffsetCurve71.Value(OffsetCurve71.LastParameter()); qDebug() << "startPoint77:(" << startPoint77.X() << "," << startPoint77.Y() << ")"; qDebug() << "endPoint77:(" << endPoint77.X() << "," << endPoint77.Y() << ")"; //GC_MakeSegment Segment8(gp_Pnt(41.901, 37.697, 0), gp_Pnt(41.901, 40.162, 0)); GC_MakeSegment Segment8(Segment7.Value()->EndPoint(), gp_Pnt(Segment7.Value()->EndPoint().X(), Segment7.Value()->EndPoint().Y() + 10, 0) ); BRepBuilderAPI_MakeEdge anEdge8(Segment8.Value()); GC_MakeSegment Segment9(Segment8.Value()->EndPoint(), gp_Pnt(dxs5, Segment8.Value()->EndPoint().Y(), 0)); BRepBuilderAPI_MakeEdge anEdge9(Segment9.Value()); GC_MakeSegment Segment10(gp_Pnt(dxs5, Segment8.Value()->EndPoint().Y(), 0), gp_Pnt(dxs5, dys5, 0)); BRepBuilderAPI_MakeEdge anEdge10(Segment10.Value()); // TopTools_ListOfShape listEdge; listEdge.Append(anEdge5.Edge()); listEdge.Append(anEdge6.Edge()); listEdge.Append(anEdge7.Edge()); listEdge.Append(anEdge8.Edge()); listEdge.Append(anEdge9.Edge()); listEdge.Append(anEdge10.Edge()); //Construct a wireframe based on an edge BRepBuilderAPI_MakeWire aWire; //aWire.Add(anEdge.Edge()); //aWire.Add(anEdge2.Edge()); //Add to wireframe //aWire.Add(anEdge4.Edge()); aWire.Add(listEdge); // aWire.Build(); if (!aWire.IsDone()) { if (aWire.Error()== BRepBuilderAPI_WireError::BRepBuilderAPI_EmptyWire) { qDebug() << "Wire failed-EmptyWire!\\ "; } else if (aWire.Error() == BRepBuilderAPI_WireError::BRepBuilderAPI_DisconnectedWire) { qDebug() << "Wire failed-DisconnectedWire!\\ "; } else if (aWire.Error() == BRepBuilderAPI_WireError::BRepBuilderAPI_NonManifoldWire) { qDebug() << "Wire failed-NonManifoldWire!\\ "; } else { qDebug() << "Wire failed!\\ "; } //return; } //Create a ShapeFix_Wireframe object and pass in the wireframe // Handle(ShapeFix_Wireframe) aFixWire = new ShapeFix_Wireframe(aWire.Shape()); aFixWire->SetPrecision(thePrec); //aFixWire->SetMaxTolerance(0.01); // aFixWire->FixWireGaps(); Handle(AIS_Shape) wire_shape = new AIS_Shape(aWire.Shape()); _ctrlUi->listView->RecordModel(wire_shape, QString("wire shape")); wire_shape->SetColor(Quantity_NOC_YELLOW); //offset shape //Wireframe offset distance BRepOffsetAPI_MakeOffset mk_offset; mk_offset.AddWire(aWire.Wire()); //mk_offset.SetApprox(true); mk_offset.Init(GeomAbs_Arc, Standard_False); Standard_Real offset = _ctrlUi->doubleSpinBox_offsetDist->value(); mk_offset.Perform(offset); if (!mk_offset.IsDone()) { qDebug() << "Offset failed!\\ "; } else { const TopoDS_Shape & amp; offsetShape = mk_offset.Shape(); if (offsetShape.IsNull()) { qDebug() << "offsetShape is null!\\ "; return; } Handle(AIS_Shape) offset_shape = new AIS_Shape(offsetShape); _ctrlUi->listView->RecordModel(offset_shape, QString("offset shape")); offset_shape->SetColor(Quantity_NOC_RED); //Convert topological data to geometric data TopTools_IndexedMapOfShape aEdgeMap; TopExp::MapShapes(offsetShape, TopAbs_EDGE, aEdgeMap); qDebug() << "edge count is " << aEdgeMap.Extent(); //Iterate through the results for (int i = 1; i <= aEdgeMap.Extent(); + + i) { const TopoDS_Edge & amp; aEdge = TopoDS::Edge(aEdgeMap(i)); const TopoDS_Vertex & amp; aFirstVertex = TopExp::FirstVertex(aEdge); const TopoDS_Vertex & amp; aLastVertex = TopExp::LastVertex(aEdge); Standard_Real fBegin = 0, fEnd = 0; Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge, fBegin, fEnd); if (!hCurve.IsNull()) { if (hCurve->IsKind(STANDARD_TYPE(Geom_Line))) { // is a straight line Handle(Geom_Line) line = Handle_Geom_Line::DownCast(hCurve); // Handle straight line objects here qDebug() << "Line"; //Read the coordinates of the starting point and end point of the straight line qDebug() << "start:[" << line->Value(fBegin).X() << "," << line->Value(fBegin).Y() << ", " << line->Value(fBegin).Z() << "]"; qDebug() << "end:[" << line->Value(fEnd).X() << "," << line->Value(fEnd).Y() << ", " << line->Value(fEnd).Z() << "]"; } else if (hCurve->IsKind(STANDARD_TYPE(Geom_Circle))) { // is a circle Handle(Geom_Circle) circle = Handle_Geom_Circle::DownCast(hCurve); // handle circle objects here qDebug() << "Circle"; //Read the arc starting point and end point coordinates qDebug() << "start:[" << circle->Value(fBegin).X() << "," << circle->Value(fBegin).Y() << ", " << circle->Value(fBegin).Z() << "]"; qDebug() << "end:[" << circle->Value(fEnd).X() << "," << circle->Value(fEnd).Y() << ", " << circle->Value(fEnd).Z() << "]"; qDebug() << "R:" << circle->Radius(); const gp_Circ & amp; circ = circle->Circ(); const gp_Pnt & amp; center = circ.Location(); // Get the coordinates of the center of the circle qDebug() << "Center:[" << center.X() << "," << center.Y() << "," << center.Z() << "]"; } else if (hCurve->IsKind(STANDARD_TYPE(Geom_BezierCurve))) { // is a Bezier curve Handle(Geom_BezierCurve) bezierCurve = Handle_Geom_BezierCurve::DownCast(hCurve); // Handle Bezier curve objects here qDebug() << "BezierCurve"; } else if (hCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) { // It is a B-spline curve Handle(Geom_BSplineCurve) bsplineCurve = Handle_Geom_BSplineCurve::DownCast(hCurve); // Handle B-spline curve objects here qDebug() << "SplineCurve"; } else { // Other types of curves // Handle other types of curve objects here qDebug() << "OtherCurve"; } } } } _view->fitAll(); //_context->Activate(ViewHelper::SM_FACE); //_context->Activate(ViewHelper::SM_WIRE); } catch (Standard_Failure const & amp; theFailure) { qDebug() << "info: " <<theFailure.GetMessageString() << "\\ "; } }
The knowledge points of the article match the official knowledge files, and you can further learn related knowledge. Algorithm skill tree Home page Overview 56997 people are learning the system