void HRuler::glCommands(bool select, bool marked, bool no_color) { double m[16]; extract_transposed(m_trsf, m); glPushMatrix(); glMultMatrixd(m); if(m_gl_list) { glCallList(m_gl_list); } else{ m_gl_list = glGenLists(1); glNewList(m_gl_list, GL_COMPILE_AND_EXECUTE); // draw a filled white rectangle glDisable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0, 0.0); glColor4ub(255, 255, 255, 120); // white wxGetApp().EnableBlend(); glDepthMask(0); gp_Pnt point[4]; GetFourCorners(point); glBegin(GL_TRIANGLES); glVertex3d(point[0].X(), point[0].Y(), point[0].Z()); glVertex3d(point[1].X(), point[1].Y(), point[1].Z()); glVertex3d(point[2].X(), point[2].Y(), point[2].Z()); glVertex3d(point[0].X(), point[0].Y(), point[0].Z()); glVertex3d(point[2].X(), point[2].Y(), point[2].Z()); glVertex3d(point[3].X(), point[3].Y(), point[3].Z()); glEnd(); wxGetApp().DisableBlend(); glDepthMask(1); // draw a black rectangle border glColor4ub(0, 0, 0, 255); // black glBegin(GL_LINE_STRIP); glVertex3d(point[0].X(), point[0].Y(), point[0].Z()); glVertex3d(point[1].X(), point[1].Y(), point[1].Z()); glVertex3d(point[2].X(), point[2].Y(), point[2].Z()); glVertex3d(point[3].X(), point[3].Y(), point[3].Z()); glVertex3d(point[0].X(), point[0].Y(), point[0].Z()); glEnd(); // draw the marks ( with their numbers ) std::list<RulerMark> marks; CalculateMarks(marks); for(std::list<RulerMark>::iterator It = marks.begin(); It != marks.end(); It++) { RulerMark& mark = *It; mark.glCommands(GetUnits()); } glEnable(GL_POLYGON_OFFSET_FILL); glEndList(); } glPopMatrix(); }
void HDimension::RenderText(const wxString &text, const gp_Pnt& p, const gp_Dir& xdir, const gp_Dir& ydir, double scale) { float width, height; if(!wxGetApp().get_text_size(text, &width, &height))return; // make a matrix at top left of text gp_Pnt text_top_left( p.XYZ() + ydir.XYZ() * (scale * height) ); gp_Trsf text_matrix = make_matrix(text_top_left, xdir, ydir); glPushMatrix(); double m[16]; extract_transposed(text_matrix, m); glMultMatrixd(m); if(DrawFlat) { //Try and draw this ortho. must find the origin point in screen coordinates double x, y, z; // arrays to hold matrix information double model_view[16]; glGetDoublev(GL_MODELVIEW_MATRIX, model_view); double projection[16]; glGetDoublev(GL_PROJECTION_MATRIX, projection); int viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); // get 3D coordinates based on window coordinates gluProject(0,0,0, model_view, projection, viewport, &x, &y, &z); wxGetApp().render_screen_text_at(text, scale*8,x,y,atan2(xdir.Y(),xdir.X()) * 180 / M_PI); } else { wxGetApp().render_text(text); } glPopMatrix(); }
void CEdge::glCommands(bool select, bool marked, bool no_color){ if(!no_color){ wxGetApp().glColorEnsuringContrast(HeeksColor(0, 0, 0)); } if(m_owner && m_owner->m_owner && m_owner->m_owner->GetType() == SolidType) { // triangulate a face on the edge first if(this->m_faces.size() > 0) { TopLoc_Location fL; Handle_Poly_Triangulation facing = BRep_Tool::Triangulation(m_faces.front()->Face(),fL); if(!facing.IsNull()) { // Get polygon Handle_Poly_PolygonOnTriangulation polygon = BRep_Tool::PolygonOnTriangulation(m_topods_edge, facing, fL); gp_Trsf tr = fL; double m[16]; extract_transposed(tr, m); glPushMatrix(); glMultMatrixd(m); if (!polygon.IsNull()) { glBegin(GL_LINE_STRIP); const TColStd_Array1OfInteger& Nodes = polygon->Nodes(); const TColgp_Array1OfPnt& FNodes = facing->Nodes(); int nnn = polygon->NbNodes(); for (int nn = 1; nn <= nnn; nn++) { gp_Pnt v = FNodes(Nodes(nn)); glVertex3d(v.X(), v.Y(), v.Z()); } glEnd(); } glPopMatrix(); } } } else { bool glwidth_done = false; GLfloat save_depth_range[2]; if(m_owner == NULL || m_owner->m_owner == NULL || m_owner->m_owner->GetType() != WireType) { BRepTools::Clean(m_topods_edge); double pixels_per_mm = wxGetApp().GetPixelScale(); BRepMesh_IncrementalMesh(m_topods_edge, 1/pixels_per_mm); if(marked){ glGetFloatv(GL_DEPTH_RANGE, save_depth_range); glDepthRange(0, 0); glLineWidth(2); glwidth_done = true; } } TopLoc_Location L; Handle(Poly_Polygon3D) Polyg = BRep_Tool::Polygon3D(m_topods_edge, L); if (!Polyg.IsNull()) { const TColgp_Array1OfPnt& Points = Polyg->Nodes(); Standard_Integer po; glBegin(GL_LINE_STRIP); for (po = Points.Lower(); po <= Points.Upper(); po++) { gp_Pnt p = (Points.Value(po)).Transformed(L); glVertex3d(p.X(), p.Y(), p.Z()); } glEnd(); } if(glwidth_done) { glLineWidth(1); glDepthRange(save_depth_range[0], save_depth_range[1]); } } }