CrossSection.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <BRepAlgoAPI_Section.hxx>
00027 # include <BRepBuilderAPI_MakeWire.hxx>
00028 # include <gp_Pln.hxx>
00029 # include <TopExp_Explorer.hxx>
00030 # include <TopoDS.hxx>
00031 # include <TopoDS_Edge.hxx>
00032 # include <TopoDS_Wire.hxx>
00033 #endif
00034
00035 #include "CrossSection.h"
00036
00037 using namespace Part;
00038
00039
00040 CrossSection::CrossSection(double a, double b, double c, const TopoDS_Shape& s)
00041 : a(a), b(b), c(c), s(s)
00042 {
00043 }
00044
00045 std::list<TopoDS_Wire> CrossSection::section(double d) const
00046 {
00047 std::list<TopoDS_Wire> wires;
00048 BRepAlgoAPI_Section cs(s, gp_Pln(a,b,c,-d));
00049 if (cs.IsDone()) {
00050 std::list<TopoDS_Edge> edges;
00051 TopExp_Explorer xp;
00052 for (xp.Init(cs.Shape(), TopAbs_EDGE); xp.More(); xp.Next())
00053 edges.push_back(TopoDS::Edge(xp.Current()));
00054 connectEdges(edges, wires);
00055 }
00056
00057 return wires;
00058 }
00059
00060 void CrossSection::connectEdges (const std::list<TopoDS_Edge>& edges, std::list<TopoDS_Wire>& wires) const
00061 {
00062 std::list<TopoDS_Edge> edge_list = edges;
00063 while (edge_list.size() > 0) {
00064 BRepBuilderAPI_MakeWire mkWire;
00065
00066 mkWire.Add(edge_list.front());
00067 edge_list.erase(edge_list.begin());
00068
00069 TopoDS_Wire new_wire = mkWire.Wire();
00070
00071
00072 bool found = false;
00073 do {
00074 found = false;
00075 for (std::list<TopoDS_Edge>::iterator pE = edge_list.begin(); pE != edge_list.end();++pE) {
00076 mkWire.Add(*pE);
00077 if (mkWire.Error() != BRepBuilderAPI_DisconnectedWire) {
00078
00079 found = true;
00080 edge_list.erase(pE);
00081 new_wire = mkWire.Wire();
00082 break;
00083 }
00084 }
00085 }
00086 while (found);
00087 wires.push_back(new_wire);
00088 }
00089 }