#include "c3dwidget.h" #include #include #include #include #include "AIS_ViewCube.hxx" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Geom_Axis2Placement.hxx" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //strore the data from the stepfile. std::vector Shape; std::vector ais_Shape; //store the colors from the stepfile in a struct vector. void C3DWidget::draw_line(gp_Pnt point1, gp_Pnt point2){ //make a point //gp_Pnt point1(0,0,0); //make a vertex from the point TopoDS_Vertex vertex1 = BRepBuilderAPI_MakeVertex(point1); //make one more point //gp_Pnt point2(100,0,0); //make an edge from the two points TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge(point1,point2); //display the vertex Handle(AIS_Shape) aisBody1 = new AIS_Shape(vertex1); //aisBody1->SetLocalTransformation(ChainVec.back().WorkFrameVec.back().MyTrsf); m_context->SetColor(aisBody1,Quantity_NOC_LAVENDER,Standard_False); m_context->SetMaterial(aisBody1,Graphic3d_NOM_PLASTIC,Standard_False); m_context->Display(aisBody1,Standard_False); //display the edge Handle(AIS_Shape) aisBody2 = new AIS_Shape(edge1); //Gcode workframe test: aisBody2->SetLocalTransformation(ChainVec.back().WorkFrameVec.back().MyTrsf); m_context->SetColor(aisBody2,Quantity_NOC_BLUE4,Standard_False); m_context->SetMaterial(aisBody2,Graphic3d_NOM_PLASTIC,Standard_False); m_context->Display(aisBody2,Standard_False); } void C3DWidget::draw_circle(gp_Pnt center,double radius){ //draw circle : gp_Dir dir(0,0,1); // you can change this gp_Circ circle(gp_Ax2( center, dir),radius); BRepBuilderAPI_MakeEdge makeEdge(circle); Handle(AIS_Shape) shape = new AIS_Shape(TopoDS_Edge()); m_context->SetColor(shape,Quantity_NOC_BLUE4,Standard_False); m_context->SetMaterial(shape,Graphic3d_NOM_PLASTIC,Standard_False); shape ->Set(makeEdge.Edge()); //Gcode workframe test: shape->SetLocalTransformation(ChainVec.back().WorkFrameVec.back().MyTrsf); m_context->Display(shape , 1); } void C3DWidget::draw_3p_arc(gp_Pnt point1,gp_Pnt point2,gp_Pnt point3){ //gp_Pnt point1(0,0,0); //gp_Pnt point2(50,50,0); //gp_Pnt point3(100,0,0); Handle(Geom_TrimmedCurve) aArcOfCircle = GC_MakeArcOfCircle(point1,point2,point3); TopoDS_Edge aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle); //display the edge Handle(AIS_Shape) aisBody2 = new AIS_Shape(aEdge2); //Gcode workframe test: aisBody2->SetLocalTransformation(ChainVec.back().WorkFrameVec.back().MyTrsf); m_context->SetColor(aisBody2,Quantity_NOC_BLUE4,Standard_False); m_context->SetMaterial(aisBody2,Graphic3d_NOM_PLASTIC,Standard_False); m_context->Display(aisBody2,Standard_False); } void C3DWidget::draw_cp_arc(gp_Pnt center, gp_Pnt point1, gp_Pnt point2){ double radius=center.Distance(point2); //std::cout<<"radius:"<SetLocalTransformation(ChainVec.back().WorkFrameVec.back().MyTrsf); m_context->SetColor(aisBody2,Quantity_NOC_BLUE4,Standard_False); m_context->SetMaterial(aisBody2,Graphic3d_NOM_PLASTIC,Standard_False); m_context->Display(aisBody2,Standard_False); } void Opencascade::write_text(std::string str, int textheight, double x, double y, double rot_deg){ //https://www.youtube.com/watch?v=31SXQLpdNyE m_context->EraseAll(0); const char *chartext=str.c_str(); if(textheight==0 || textheight<0){textheight=1;} Font_BRepFont aBrepFont("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", textheight); Font_BRepTextBuilder aTextBuilder; TopoDS_Shape Text_Shape = aTextBuilder.Perform(aBrepFont, NCollection_String(chartext)); Handle(AIS_Shape) Text_ais_Shape = new AIS_Shape(Text_Shape); gp_Trsf MyTrsf_rot; MyTrsf_rot.SetRotation(gp_Ax1(gp_Pnt( 0, 0, 0), gp_Dir( 0, //rotation flag x 0, //rotation flag y 1)), rot_deg * M_PI /180); gp_Trsf MyTrsf_trans; MyTrsf_trans.SetTranslation(gp_Pnt(0,0,0),gp_Pnt(x,y,0)); Text_ais_Shape->SetLocalTransformation(MyTrsf_trans*MyTrsf_rot); m_context->SetColor(Text_ais_Shape,Quantity_NOC_BLACK,Standard_False); //m_context->SetMaterial(aisBody2,Graphic3d_NOM_PLASTIC,Standard_False); m_context->Display(Text_ais_Shape,Standard_True); view_top(); m_view->ZFitAll(); m_view->FitAll(); m_view->Redraw(); } void Opencascade::Clear() { m_context->EraseAll(0); m_view->FitAll(); m_view->Redraw(); } void Opencascade::view_front() { m_view->SetProj( V3d_Yneg ); } void Opencascade::view_back() { m_view->SetProj( V3d_Ypos ); } void Opencascade::view_top() { m_view->SetProj( V3d_Zpos ); } void Opencascade::view_bottom() { m_view->SetProj( V3d_Zneg ); } void Opencascade::view_left() { m_view->SetProj( V3d_Xneg ); } void Opencascade::view_right() { m_view->SetProj( V3d_Xpos ); }