/** Accumulate a list of TopoDS_Edge objects along with their lengths. We will use this repeatedly while we're rendering this text string. We don't want to re-aquire this information for every point of every character. Cache it here. This method should be called once before each rendering session for the text string. */ void COrientationModifier::InitializeFromSketch() { m_edges.clear(); m_total_edge_length = 0.0; if (GetNumChildren() > 0) { std::list<TopoDS_Shape> wires; if (::ConvertSketchToFaceOrWire( GetFirstChild(), wires, false)) { // Aggregate a list of TopoDS_Edge objects and each of their lengths. We can // use this list to skip through edges that we're not interested in. i.e. the // text won't sit on top of them. for (std::list<TopoDS_Shape>::iterator itWire = wires.begin(); itWire != wires.end(); itWire++) { TopoDS_Wire wire(TopoDS::Wire(*itWire)); for(BRepTools_WireExplorer expEdge(TopoDS::Wire(wire)); expEdge.More(); expEdge.Next()) { TopoDS_Edge edge(TopoDS_Edge(expEdge.Current())); BRepAdaptor_Curve curve(edge); double edge_length = GCPnts_AbscissaPoint::Length(curve); m_edges.push_back( std::make_pair(edge,edge_length) ); m_total_edge_length += edge_length; } // End for } // End for } // End if - then } // End if - then }
/* static */ std::vector<TopoDS_Edge> SimplifySketchTool::SortEdges( const TopoDS_Wire & wire ) { std::vector<TopoDS_Edge> edges; for(BRepTools_WireExplorer expEdge(TopoDS::Wire(wire)); expEdge.More(); expEdge.Next()) { edges.push_back( TopoDS_Edge(expEdge.Current()) ); } // End for for (std::vector<TopoDS_Edge>::iterator l_itEdge = edges.begin(); l_itEdge != edges.end(); l_itEdge++) { if (l_itEdge == edges.begin()) { // It's the first edge. Find the edge whose endpoint is closest to gp_Pnt(0,0,0) so that // the resutls of this sorting are consistent. When we just use the first edge in the // wire, we end up with different results every time. We want consistency so that, if we // use this Contour operation as a location for drilling a relief hole (one day), we want // to be sure the machining will begin from a consistently known location. std::vector<TopoDS_Edge>::iterator l_itStartingEdge = edges.begin(); gp_Pnt closest_point = GetStart(*l_itStartingEdge); if (GetEnd(*l_itStartingEdge).Distance(gp_Pnt(0,0,0)) < closest_point.Distance(gp_Pnt(0,0,0))) { closest_point = GetEnd(*l_itStartingEdge); } for (std::vector<TopoDS_Edge>::iterator l_itCheck = edges.begin(); l_itCheck != edges.end(); l_itCheck++) { if (GetStart(*l_itCheck).Distance(gp_Pnt(0,0,0)) < closest_point.Distance(gp_Pnt(0,0,0))) { closest_point = GetStart(*l_itCheck); l_itStartingEdge = l_itCheck; } if (GetEnd(*l_itCheck).Distance(gp_Pnt(0,0,0)) < closest_point.Distance(gp_Pnt(0,0,0))) { closest_point = GetEnd(*l_itCheck); l_itStartingEdge = l_itCheck; } } EdgeComparison compare( *l_itStartingEdge ); std::sort( edges.begin(), edges.end(), compare ); } // End if - then else { // We've already begun. Just sort based on the previous point's location. std::vector<TopoDS_Edge>::iterator l_itNextEdge = l_itEdge; l_itNextEdge++; if (l_itNextEdge != edges.end()) { EdgeComparison compare( *l_itEdge ); std::sort( l_itNextEdge, edges.end(), compare ); } // End if - then } // End if - else } // End for return(edges); } // End SortEdges() method
TopoDS_Edge GetEdge(const TopoDS_Shape &shape, int iEdge) { TopTools_IndexedMapOfShape edgeMap; TopExp::MapShapes(shape, TopAbs_EDGE, edgeMap); if (iEdge < 0 || iEdge >= edgeMap.Extent()) { return TopoDS_Edge(); } else { return TopoDS::Edge(edgeMap(iEdge+1)); } }
#define X_Key 0x58 #define Y_Key 0x59 #define Z_Key 0x5A #define ModelClipping #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //gp_Pnt ConvertClickToPoint(Standard_Real x, Standard_Real y, Handle(V3d_View) aView); gp_Pnt p1,p2,p3; Handle(AIS_Shape) spotConeShape=new AIS_Shape(TopoDS_Solid()); Handle(AIS_Shape) directionalEdgeShape=new AIS_Shape(TopoDS_Edge()); ///////////////////////////////////////////////////////////////////////////// // CViewer3dView IMPLEMENT_DYNCREATE(CViewer3dView, CView) BEGIN_MESSAGE_MAP(CViewer3dView, CView) //{{AFX_MSG_MAP(CViewer3dView) ON_COMMAND(ID_BUTTONAxo, OnBUTTONAxo) ON_COMMAND(ID_BUTTONBack, OnBUTTONBack) ON_COMMAND(ID_BUTTONBottom, OnBUTTONBottom) ON_COMMAND(ID_BUTTONFront, OnBUTTONFront) ON_COMMAND(ID_BUTTONHlrOff, OnBUTTONHlrOff) ON_COMMAND(ID_BUTTONHlrOn, OnBUTTONHlrOn) ON_COMMAND(ID_BUTTONLeft, OnBUTTONLeft)