void CEdge::Blend(double radius, bool chamfer_not_fillet){ try{ CShape* body = GetParentBody(); if(body){ if(chamfer_not_fillet) { BRepFilletAPI_MakeChamfer chamfer(body->Shape()); for(std::list<CFace*>::iterator It = m_faces.begin(); It != m_faces.end(); It++) { CFace* face = *It; chamfer.Add(radius, m_topods_edge, TopoDS::Face(face->Face())); } TopoDS_Shape new_shape = chamfer.Shape(); wxGetApp().AddUndoably(new CSolid(*((TopoDS_Solid*)(&new_shape)), _("Solid with edge chamfer"), *(body->GetColor()), body->GetOpacity()), NULL, NULL); } else { BRepFilletAPI_MakeFillet fillet(body->Shape()); fillet.Add(radius, m_topods_edge); TopoDS_Shape new_shape = fillet.Shape(); wxGetApp().AddUndoably(new CSolid(*((TopoDS_Solid*)(&new_shape)), _("Solid with edge blend"), *(body->GetColor()), body->GetOpacity()), NULL, NULL); } wxGetApp().DeleteUndoably(body); } } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); wxMessageBox(wxString(chamfer_not_fillet ?_("Error making fillet"):_("Error making fillet")) + _T(": ") + Ctt(e->GetMessageString())); } catch(...) { wxMessageBox(chamfer_not_fillet ? _("A fatal error happened during Chamfer"):_("A fatal error happened during Blend")); } }// end Blend function
CFace* CShape::find(const TopoDS_Face &face) { for(HeeksObj* object = m_faces->GetFirstChild(); object; object = m_faces->GetNextChild()) { CFace* f = (CFace*)object; if(f->Face() == face)return f; } return NULL; }
void CShape::FilletOrChamferEdges(std::list<HeeksObj*> &list, double radius, bool chamfer_not_fillet) { // make a map with a list of edges for each solid std::map< HeeksObj*, std::list< HeeksObj* > > solid_edge_map; for(std::list<HeeksObj*>::const_iterator It = list.begin(); It != list.end(); It++){ HeeksObj* edge = *It; if(edge->GetType() == EdgeType) { HeeksObj* solid = edge->HEEKSOBJ_OWNER->HEEKSOBJ_OWNER; if(solid && solid->GetType() == SolidType) { std::map< HeeksObj*, std::list< HeeksObj* > >::iterator FindIt = solid_edge_map.find(solid); if(FindIt == solid_edge_map.end()) { std::list< HeeksObj* > empty_list; solid_edge_map.insert( make_pair(solid, empty_list) ); FindIt = solid_edge_map.find(solid); } std::list< HeeksObj* > &list = FindIt->second; list.push_back(edge); } } } // do each solid for(std::map< HeeksObj*, std::list< HeeksObj* > >::iterator It = solid_edge_map.begin(); It != solid_edge_map.end(); It++) { HeeksObj* solid = It->first; std::list< HeeksObj* > &list = It->second; try{ if(chamfer_not_fillet) { BRepFilletAPI_MakeChamfer chamfer(((CShape*)solid)->Shape()); for(std::list< HeeksObj* >::iterator It2 = list.begin(); It2 != list.end(); It2++) { CEdge* edge = (CEdge*)(*It2); for(CFace* face = (CFace*)(edge->GetFirstFace()); face; face = (CFace*)(edge->GetNextFace())) { chamfer.Add(radius, TopoDS::Edge(edge->Edge()), TopoDS::Face(face->Face())); } } TopoDS_Shape new_shape = chamfer.Shape(); wxGetApp().Add(new CSolid(*((TopoDS_Solid*)(&new_shape)), _("Solid with edge blend"), *(solid->GetColor()), ((CShape*)solid)->m_opacity), NULL); wxGetApp().Remove(solid); } else { BRepFilletAPI_MakeFillet fillet(((CShape*)solid)->Shape()); for(std::list< HeeksObj* >::iterator It2 = list.begin(); It2 != list.end(); It2++) { fillet.Add(radius, TopoDS::Edge(((CEdge*)(*It2))->Edge())); } TopoDS_Shape new_shape = fillet.Shape(); wxGetApp().Add(new CSolid(*((TopoDS_Solid*)(&new_shape)), _("Solid with edge blend"), *(solid->GetColor()), ((CShape*)solid)->m_opacity), NULL); wxGetApp().Remove(solid); } } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); wxMessageBox(wxString(_("Error making fillet")) + _T(": ") + Ctt(e->GetMessageString())); } catch(...) { wxMessageBox(_("A fatal error happened during Blend")); } } wxGetApp().Repaint(); }
void CreateFacesAndEdges(TopoDS_Shape shape, CFaceList* faces, CEdgeList* edges, CVertexList* vertices) { // create index maps TopTools_IndexedMapOfShape faceMap; TopTools_IndexedMapOfShape edgeMap; TopTools_IndexedMapOfShape vertexMap; for (TopExp_Explorer explorer(shape, TopAbs_FACE); explorer.More(); explorer.Next()) { faceMap.Add(explorer.Current()); } for (TopExp_Explorer explorer(shape, TopAbs_EDGE); explorer.More(); explorer.Next()) { edgeMap.Add(explorer.Current()); } for (TopExp_Explorer explorer(shape, TopAbs_VERTEX); explorer.More(); explorer.Next()) { vertexMap.Add(explorer.Current()); } std::vector<CFace*> face_array; face_array.resize(faceMap.Extent() + 1); std::vector<CEdge*> edge_array; edge_array.resize(edgeMap.Extent() + 1); std::vector<CVertex*> vertex_array; vertex_array.resize(vertexMap.Extent() + 1); // create the edge objects for(int i = 1;i<=edgeMap.Extent();i++) { const TopoDS_Shape &s = edgeMap(i); CEdge* new_object = new CEdge(TopoDS::Edge(s)); edge_array[i] = new_object; } // create the vertex objects for(int i = 1;i<=vertexMap.Extent();i++) { const TopoDS_Shape &s = vertexMap(i); CVertex* new_object = new CVertex(TopoDS::Vertex(s)); vertex_array[i] = new_object; } // add the edges in their face loop order std::set<CEdge*> edges_added; std::set<CVertex*> vertices_added; // create the face objects for(int i = 1;i<=faceMap.Extent();i++) { const TopoDS_Shape &s = faceMap(i); CFace* new_face_object = new CFace(TopoDS::Face(s)); faces->Add(new_face_object, NULL); face_array[i] = new_face_object; // create the loop objects TopTools_IndexedMapOfShape loopMap; for (TopExp_Explorer explorer(s, TopAbs_WIRE); explorer.More(); explorer.Next()) { loopMap.Add(explorer.Current()); } TopoDS_Wire outerWire=BRepTools::OuterWire(new_face_object->Face()); int outer_index = loopMap.FindIndex(outerWire); for(int i = 1;i<=loopMap.Extent();i++) { const TopoDS_Shape &s = loopMap(i); CLoop* new_loop_object = new CLoop(TopoDS::Wire(s)); new_face_object->m_loops.push_back(new_loop_object); if(outer_index == i)new_loop_object->m_is_outer = true; new_loop_object->m_pface = new_face_object; // find the loop's edges for(BRepTools_WireExplorer explorer(TopoDS::Wire(s)); explorer.More(); explorer.Next()) { CEdge* e = edge_array[edgeMap.FindIndex(explorer.Current())]; new_loop_object->m_edges.push_back(e); // add the edge if(edges_added.find(e) == edges_added.end()) { edges->Add(e, NULL); edges_added.insert(e); } // add the vertex CVertex* v = vertex_array[vertexMap.FindIndex(explorer.CurrentVertex())]; if(vertices_added.find(v) == vertices_added.end()) { vertices->Add(v, NULL); vertices_added.insert(v); } } } } // find the vertices' edges for(unsigned int i = 1; i<vertex_array.size(); i++) { CVertex* v = vertex_array[i]; TopTools_IndexedMapOfShape vertexEdgeMap; for (TopExp_Explorer expEdge(v->Vertex(), TopAbs_EDGE); expEdge.More(); expEdge.Next()) { vertexEdgeMap.Add(expEdge.Current()); } for(int i = 1; i<=vertexEdgeMap.Extent(); i++) { const TopoDS_Shape &s = vertexEdgeMap(i); CEdge* e = edge_array[edgeMap.FindIndex(s)]; v->m_edges.push_back(e); } } // find the faces' edges for(unsigned int i = 1; i<face_array.size(); i++) { CFace* face = face_array[i]; TopTools_IndexedMapOfShape faceEdgeMap; for (TopExp_Explorer expEdge(face->Face(), TopAbs_EDGE); expEdge.More(); expEdge.Next()) { faceEdgeMap.Add(expEdge.Current()); } for(int i = 1; i<=faceEdgeMap.Extent(); i++) { const TopoDS_Shape &s = faceEdgeMap(i); CEdge* e = edge_array[edgeMap.FindIndex(s)]; face->m_edges.push_back(e); e->m_faces.push_back(face); bool sense = (s.IsEqual(e->Edge()) == Standard_True); e->m_face_senses.push_back(sense); } } }