// //======================================================================= //function : AngleWithRef //purpose : //======================================================================= Standard_Real AngleWithRef(const gp_Dir& theD1, const gp_Dir& theD2, const gp_Dir& theDRef) { Standard_Real aCosinus, aSinus, aBeta, aHalfPI, aScPr; gp_XYZ aXYZ; // aHalfPI=0.5*M_PI; // const gp_XYZ& aXYZ1=theD1.XYZ(); const gp_XYZ& aXYZ2=theD2.XYZ(); aXYZ=aXYZ1.Crossed(aXYZ2); aSinus=aXYZ.Modulus(); aCosinus=theD1*theD2; // aBeta=0.; if (aSinus>=0.) { aBeta=aHalfPI*(1.-aCosinus); } else { aBeta=2.*M_PI-aHalfPI*(3.+aCosinus); } // aScPr=aXYZ.Dot(theDRef.XYZ()); if (aScPr<0.) { aBeta=-aBeta; } return aBeta; }
void PositionSettingsWidget::setDirection(const gp_Dir& dir) { if (dir.IsParallel(gp::DX(), 0)) cbDirection->setCurrentIndex(0); else if (dir.IsParallel(gp::DY(), 0)) cbDirection->setCurrentIndex(1); else if (dir.IsParallel(gp::DZ(), 0)) cbDirection->setCurrentIndex(2); }
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 OrthoViews::set_primary(gp_Dir facing, gp_Dir right) // set the orientation of the primary view { primary.SetDirection(facing); primary.SetXDirection(right); gp_Dir up = primary.YDirection(); // compute dimensions of part when orientated according to primary view width = abs(right.X() * bbox.LengthX() + right.Y() * bbox.LengthY() + right.Z() * bbox.LengthZ()); height = abs(up.X() * bbox.LengthX() + up.Y() * bbox.LengthY() + up.Z() * bbox.LengthZ()); depth = abs(facing.X() * bbox.LengthX() + facing.Y() * bbox.LengthY() + facing.Z() * bbox.LengthZ()); if (views.size() == 0) add_view(0, 0); else { views[0]->set_projection(primary); set_all_orientations(); // reorient all other views appropriately process_views(); } }
// static void HDimension::draw_arrow_line(DimensionMode mode, const gp_Pnt &p0, const gp_Pnt &p1, const gp_Pnt &p2, const gp_Dir &xdir, const gp_Dir &ydir, double width, double scale) { double short_line_length = 5.0 * scale; double long_line_extra = 2.0 * scale; double y0 = gp_Vec(p2.XYZ()) * gp_Vec(ydir.XYZ()) - gp_Vec(p0.XYZ()) * gp_Vec(ydir.XYZ()); double y1 = gp_Vec(p2.XYZ()) * gp_Vec(ydir.XYZ()) - gp_Vec(p1.XYZ()) * gp_Vec(ydir.XYZ()); gp_Pnt vt0( p0.XYZ() + ydir.XYZ() * y0); gp_Pnt vt1( p1.XYZ() + ydir.XYZ() * y1); gp_Pnt vt2 = p2; gp_Dir along_dir = make_vector(gp_Pnt(p0), gp_Pnt(p1)); gp_Dir xdir_along = xdir; if(along_dir * xdir < 0)xdir_along = -xdir; gp_Pnt new_vt0 = vt0; gp_Pnt new_vt1 = vt1; gp_Pnt middle_text_point = p2.XYZ() + along_dir.XYZ() * (width/2 * scale); double x0 = gp_Vec(p0.XYZ()) * gp_Vec(xdir_along.XYZ()); double x1 = gp_Vec(p1.XYZ()) * gp_Vec(xdir_along.XYZ()); double xm = gp_Vec(middle_text_point.XYZ()) * gp_Vec(xdir_along.XYZ()); double arrow_head_scale = scale; if(xm < x0 || xm > x1) { arrow_head_scale *= -1; } double distance = vt0.Distance(vt1); // draw arrow heads, if there's room if((distance > 2 * scale + wxGetApp().m_geom_tol) || (xm < x0) || (xm > x1)) { gp_XYZ t[2][3]; t[0][0] = vt0.XYZ(); t[0][1] = vt0.XYZ() + xdir_along.XYZ() * arrow_head_scale + ydir.XYZ() * (arrow_head_scale * (-0.4)); t[0][2] = vt0.XYZ() + xdir_along.XYZ() * arrow_head_scale + ydir.XYZ() * (arrow_head_scale * 0.4); t[1][0] = vt1.XYZ(); t[1][1] = vt1.XYZ() + xdir_along.XYZ() * (-arrow_head_scale) + ydir.XYZ() * (arrow_head_scale * 0.4); t[1][2] = vt1.XYZ() + xdir_along.XYZ() * (-arrow_head_scale) + ydir.XYZ() * (arrow_head_scale * (-0.4)); // adjust line vertices new_vt0 = gp_Pnt(vt0.XYZ() + xdir_along.XYZ() * arrow_head_scale); new_vt1 = gp_Pnt(vt1.XYZ() + xdir_along.XYZ() * (-arrow_head_scale)); // draw two triangles for(int i = 0; i<2; i++) { glBegin(GL_LINE_STRIP); glVertex3d(t[i][0].X(), t[i][0].Y(), t[i][0].Z()); glVertex3d(t[i][1].X(), t[i][1].Y(), t[i][1].Z()); glVertex3d(t[i][2].X(), t[i][2].Y(), t[i][2].Z()); glVertex3d(t[i][0].X(), t[i][0].Y(), t[i][0].Z()); glEnd(); } } // draw side lines glBegin(GL_LINES); glVertex3d(p0.X(), p0.Y(), p0.Z()); glVertex3d(vt0.X(), vt0.Y(), vt0.Z()); glVertex3d(p1.X(), p1.Y(), p1.Z()); glVertex3d(vt1.X(), vt1.Y(), vt1.Z()); glEnd(); if(xm < x0) { // long line first gp_Pnt vt4 = vt2.XYZ() + xdir_along.XYZ() * (-long_line_extra); glBegin(GL_LINES); glVertex3d(vt2.X(), vt2.Y(), vt2.Z()); glVertex3d(new_vt0.X(), new_vt0.Y(), new_vt0.Z()); glEnd(); // little line gp_Pnt vt3 = new_vt1.XYZ() + xdir_along.XYZ() * short_line_length; glBegin(GL_LINES); glVertex3d(new_vt1.X(), new_vt1.Y(), new_vt1.Z()); glVertex3d(vt3.X(), vt3.Y(), vt3.Z()); glEnd(); } else if(xm > x1) { // little first gp_Pnt vt3 = new_vt0.XYZ() - xdir_along.XYZ() * short_line_length; glBegin(GL_LINES); glVertex3d(vt3.X(), vt3.Y(), vt3.Z()); glVertex3d(new_vt0.X(), new_vt0.Y(), new_vt0.Z()); glEnd(); // long line glBegin(GL_LINES); gp_Pnt vt4 = vt2.XYZ() + xdir_along.XYZ() * (width * scale + long_line_extra); glVertex3d(vt1.X(), vt1.Y(), vt1.Z()); glVertex3d(vt4.X(), vt4.Y(), vt4.Z()); glEnd(); } else { // draw the arrow line glBegin(GL_LINES); glVertex3d(new_vt0.X(), new_vt0.Y(), new_vt0.Z()); glVertex3d(new_vt1.X(), new_vt1.Y(), new_vt1.Z()); glEnd(); } }
//======================================================================= //function : GetApproxNormalToFaceOnEdge //purpose : //======================================================================= void GetApproxNormalToFaceOnEdge (const TopoDS_Edge& aEx, const TopoDS_Face& aFx, Standard_Real aT, gp_Pnt& aPF, gp_Dir& aDNF, IntTools_Context& aCtx) { Standard_Boolean bReverse; Standard_Real aT1, aT2, dT, aU, aV; gp_Dir aDTT, aDNFT, aDBT; gp_Pnt aPFT, aPFx; Handle(Geom_Curve) aC3D; Handle(Geom_Surface) aS; GeomAdaptor_Surface aGAS; GeomAbs_SurfaceType aTS; TopoDS_Face aF; TopoDS_Edge aE; // bReverse=Standard_False; aF=aFx; aE=aEx; if (aF.Orientation()==TopAbs_REVERSED){ bReverse=!bReverse; aE.Reverse(); // aF.Orientation(TopAbs_FORWARD); } // // Point at aT aC3D =BRep_Tool::Curve(aE, aT1, aT2); aC3D->D0(aT, aPFT); // // Normal at aT BOPTools_Tools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNFT); // Tangent at aT BOPTools_Tools3D::GetTangentToEdge(aE, aT, aDTT); // // Binormal at aT aDBT=aDNFT^aDTT; // dT=BOPTools_Tools3D::MinStepIn2d();//~1.e-5; dT=10.*dT; //---------------------------------------------- { aS=BRep_Tool::Surface(aF); aGAS.Load(aS); aTS=aGAS.GetType(); if (aTS==GeomAbs_BSplineSurface || aTS==GeomAbs_BezierSurface || aTS==GeomAbs_Plane) { Standard_Real aTolEx, aTolFx, aTol, dUR, dVR, dR; // aTolEx=BRep_Tool::Tolerance(aEx); aTolFx=BRep_Tool::Tolerance(aFx); aTol=2.*aTolEx+aTolFx; dUR=aGAS.UResolution(aTol); dVR=aGAS.VResolution(aTol); dR=(dUR>dVR)? dUR : dVR; if (dR>dT) { dT=dR; } } //modified by NIZNHY-PKV Thu Dec 02 10:39:09 2010f else if (GeomAbs_Torus || aTS==GeomAbs_Cylinder){ Standard_Real aTolEx, aTolFx, aTol; // aTolEx=BRep_Tool::Tolerance(aEx); aTolFx=BRep_Tool::Tolerance(aFx); aTol=2.*aTolEx+aTolFx; if (aTol>dT) { dT=aTol; } } //modified by NIZNHY-PKV Thu Dec 02 10:39:13 2010t } //---------------------------------------------- // aPFx.SetXYZ(aPFT.XYZ()+dT*aDBT.XYZ()); // aPF=aPFx; aDNF=aDNFT; if (bReverse) { aDNF.Reverse(); } // GeomAPI_ProjectPointOnSurf& aProjector=aCtx.ProjPS(aF); // aProjector.Perform(aPFx); if(aProjector.IsDone()) { aProjector.LowerDistanceParameters (aU, aV); aS->D0(aU, aV, aPF); BOPTools_Tools3D::GetNormalToSurface (aS, aU, aV, aDNF); if (bReverse){ aDNF.Reverse(); } } }