diff --git a/src/Mod/Path/App/Area.cpp b/src/Mod/Path/App/Area.cpp
index ee650e0383..731cf744f6 100644
--- a/src/Mod/Path/App/Area.cpp
+++ b/src/Mod/Path/App/Area.cpp
@@ -114,7 +114,7 @@ namespace bgi = boost::geometry::index;
typedef bgi::linear<16> RParameters;
BOOST_GEOMETRY_REGISTER_POINT_3D_GET_SET(
- gp_Pnt,double,bg::cs::cartesian,X,Y,Z,SetX,SetY,SetZ)
+ gp_Pnt, double, bg::cs::cartesian, X, Y, Z, SetX, SetY, SetZ)
#define AREA_LOG FC_LOG
#define AREA_WARN FC_WARN
@@ -129,42 +129,41 @@ BOOST_GEOMETRY_REGISTER_POINT_3D_GET_SET(
# define AREA_DBG(...) do{}while(0)
#endif
-FC_LOG_LEVEL_INIT("Path.Area",true,true)
+FC_LOG_LEVEL_INIT("Path.Area", true, true)
using namespace Path;
CAreaParams::CAreaParams()
- :PARAM_INIT(PARAM_FNAME,AREA_PARAMS_CAREA)
+ :PARAM_INIT(PARAM_FNAME, AREA_PARAMS_CAREA)
{}
AreaParams::AreaParams()
- :PARAM_INIT(PARAM_FNAME,AREA_PARAMS_AREA)
+ : PARAM_INIT(PARAM_FNAME, AREA_PARAMS_AREA)
{}
-void AreaParams::dump(const char *msg) const {
+void AreaParams::dump(const char* msg) const {
#define AREA_PARAM_PRINT(_param) \
ss << PARAM_FNAME_STR(_param) << " = " << PARAM_FNAME(_param) << '\n';
- if(FC_LOG_INSTANCE.level()>FC_LOGLEVEL_TRACE) {
+ if (FC_LOG_INSTANCE.level() > FC_LOGLEVEL_TRACE) {
std::ostringstream ss;
ss << msg << '\n';
- PARAM_FOREACH(AREA_PARAM_PRINT, AREA_PARAMS_AREA)
-
+ PARAM_FOREACH(AREA_PARAM_PRINT, AREA_PARAMS_AREA);
FC_MSG(ss.str());
}
}
-CAreaConfig::CAreaConfig(const CAreaParams &p, bool noFitArcs)
+CAreaConfig::CAreaConfig(const CAreaParams& p, bool noFitArcs)
{
#define AREA_CONF_SAVE_AND_APPLY(_param) \
PARAM_FNAME(_param) = BOOST_PP_CAT(CArea::get_,PARAM_FARG(_param))();\
BOOST_PP_CAT(CArea::set_,PARAM_FARG(_param))(p.PARAM_FNAME(_param));
- PARAM_FOREACH(AREA_CONF_SAVE_AND_APPLY,AREA_PARAMS_CAREA)
+ PARAM_FOREACH(AREA_CONF_SAVE_AND_APPLY, AREA_PARAMS_CAREA);
// Arc fitting is lossy. We shall reduce the number of unnecessary fit
- if(noFitArcs)
+ if (noFitArcs)
CArea::set_fit_arcs(false);
}
@@ -174,7 +173,7 @@ CAreaConfig::~CAreaConfig() {
#define AREA_CONF_RESTORE(_param) \
BOOST_PP_CAT(CArea::set_,PARAM_FARG(_param))(PARAM_FNAME(_param));
- PARAM_FOREACH(AREA_CONF_RESTORE,AREA_PARAMS_CAREA)
+ PARAM_FOREACH(AREA_CONF_RESTORE, AREA_PARAMS_CAREA);
}
//////////////////////////////////////////////////////////////////////////////
@@ -183,71 +182,71 @@ TYPESYSTEM_SOURCE(Path::Area, Base::BaseClass)
bool Area::s_aborting;
-Area::Area(const AreaParams *params)
-:myParams(s_params)
-,myHaveFace(false)
-,myHaveSolid(false)
-,myShapeDone(false)
-,myProjecting(false)
-,mySkippedShapes(0)
+Area::Area(const AreaParams* params)
+ :myParams(s_params)
+ , myHaveFace(false)
+ , myHaveSolid(false)
+ , myShapeDone(false)
+ , myProjecting(false)
+ , mySkippedShapes(0)
{
- if(params)
+ if (params)
setParams(*params);
}
-Area::Area(const Area &other, bool deep_copy)
-:Base::BaseClass(other)
-,myShapes(other.myShapes)
-,myTrsf(other.myTrsf)
-,myParams(other.myParams)
-,myWorkPlane(other.myWorkPlane)
-,myHaveFace(other.myHaveFace)
-,myHaveSolid(other.myHaveSolid)
-,myShapeDone(false)
-,myProjecting(false)
-,mySkippedShapes(0)
+Area::Area(const Area& other, bool deep_copy)
+ :Base::BaseClass(other)
+ , myShapes(other.myShapes)
+ , myTrsf(other.myTrsf)
+ , myParams(other.myParams)
+ , myWorkPlane(other.myWorkPlane)
+ , myHaveFace(other.myHaveFace)
+ , myHaveSolid(other.myHaveSolid)
+ , myShapeDone(false)
+ , myProjecting(false)
+ , mySkippedShapes(0)
{
- if(!deep_copy || !other.isBuilt())
+ if (!deep_copy || !other.isBuilt())
return;
- if(other.myArea)
+ if (other.myArea)
myArea.reset(new CArea(*other.myArea));
myShapePlane = other.myShapePlane;
myShape = other.myShape;
myShapeDone = other.myShapeDone;
mySections.reserve(other.mySections.size());
- for(shared_ptr area:other.mySections)
- mySections.push_back(make_shared(*area,true));
+ for (shared_ptr area : other.mySections)
+ mySections.push_back(make_shared(*area, true));
}
Area::~Area() {
clean();
}
-void Area::setPlane(const TopoDS_Shape &shape) {
+void Area::setPlane(const TopoDS_Shape& shape) {
clean();
- if(shape.IsNull()) {
+ if (shape.IsNull()) {
myWorkPlane.Nullify();
return;
}
gp_Trsf trsf;
- TopoDS_Shape plane = findPlane(shape,trsf);
+ TopoDS_Shape plane = findPlane(shape, trsf);
if (plane.IsNull())
throw Base::ValueError("shape is not planar");
myWorkPlane = plane;
myTrsf = trsf;
}
-static bool getShapePlane(const TopoDS_Shape &shape, gp_Pln &pln) {
- if(shape.IsNull())
+static bool getShapePlane(const TopoDS_Shape& shape, gp_Pln& pln) {
+ if (shape.IsNull())
return false;
- if(shape.ShapeType() == TopAbs_FACE) {
+ if (shape.ShapeType() == TopAbs_FACE) {
BRepAdaptor_Surface adapt(TopoDS::Face(shape));
- if(adapt.GetType() != GeomAbs_Plane)
+ if (adapt.GetType() != GeomAbs_Plane)
return false;
pln = adapt.Plane();
return true;
}
- BRepLib_FindSurface finder(shape.Located(TopLoc_Location()),-1,Standard_True);
+ BRepLib_FindSurface finder(shape.Located(TopLoc_Location()), -1, Standard_True);
if (!finder.Found())
return false;
@@ -265,35 +264,35 @@ static bool getShapePlane(const TopoDS_Shape &shape, gp_Pln &pln) {
return true;
}
-bool Area::isCoplanar(const TopoDS_Shape &s1, const TopoDS_Shape &s2) {
- if(s1.IsNull() || s2.IsNull())
+bool Area::isCoplanar(const TopoDS_Shape& s1, const TopoDS_Shape& s2) {
+ if (s1.IsNull() || s2.IsNull())
return false;
- if(s1.IsSame(s2))
+ if (s1.IsSame(s2))
return true;
- gp_Pln pln1,pln2;
- if(!getShapePlane(s1,pln1) || !getShapePlane(s2,pln2))
+ gp_Pln pln1, pln2;
+ if (!getShapePlane(s1, pln1) || !getShapePlane(s2, pln2))
return false;
- return pln1.Position().IsCoplanar(pln2.Position(),Precision::Confusion(),Precision::Confusion());
+ return pln1.Position().IsCoplanar(pln2.Position(), Precision::Confusion(), Precision::Confusion());
}
-int Area::addShape(CArea &area, const TopoDS_Shape &shape, const gp_Trsf *trsf,
- double deflection, const TopoDS_Shape *plane, bool force_coplanar,
- CArea *areaOpen, bool to_edges, bool reorient)
+int Area::addShape(CArea& area, const TopoDS_Shape& shape, const gp_Trsf* trsf,
+ double deflection, const TopoDS_Shape* plane, bool force_coplanar,
+ CArea* areaOpen, bool to_edges, bool reorient)
{
bool haveShape = false;
int skipped = 0;
for (TopExp_Explorer it(shape, TopAbs_FACE); it.More(); it.Next()) {
haveShape = true;
- const TopoDS_Face &face = TopoDS::Face(it.Current());
- if(plane && !isCoplanar(face,*plane)) {
+ const TopoDS_Face& face = TopoDS::Face(it.Current());
+ if (plane && !isCoplanar(face, *plane)) {
++skipped;
- if(force_coplanar) continue;
+ if (force_coplanar) continue;
}
for (TopExp_Explorer it(face, TopAbs_WIRE); it.More(); it.Next())
- addWire(area,TopoDS::Wire(it.Current()),trsf,deflection);
+ addWire(area, TopoDS::Wire(it.Current()), trsf, deflection);
}
- if(haveShape)
+ if (haveShape)
return skipped;
CArea _area;
@@ -301,53 +300,54 @@ int Area::addShape(CArea &area, const TopoDS_Shape &shape, const gp_Trsf *trsf,
for (TopExp_Explorer it(shape, TopAbs_WIRE); it.More(); it.Next()) {
haveShape = true;
- const TopoDS_Wire &wire = TopoDS::Wire(it.Current());
- if(plane && !isCoplanar(wire,*plane)) {
+ const TopoDS_Wire& wire = TopoDS::Wire(it.Current());
+ if (plane && !isCoplanar(wire, *plane)) {
++skipped;
- if(force_coplanar) continue;
+ if (force_coplanar) continue;
}
- if(BRep_Tool::IsClosed(wire))
- addWire(_area,wire,trsf,deflection);
- else if(to_edges) {
+ if (BRep_Tool::IsClosed(wire))
+ addWire(_area, wire, trsf, deflection);
+ else if (to_edges) {
for (TopExp_Explorer it(wire, TopAbs_EDGE); it.More(); it.Next())
- addWire(_areaOpen,BRepBuilderAPI_MakeWire(
- TopoDS::Edge(it.Current())).Wire(),trsf,deflection,true);
- }else
- addWire(_areaOpen,wire,trsf,deflection);
+ addWire(_areaOpen, BRepBuilderAPI_MakeWire(
+ TopoDS::Edge(it.Current())).Wire(), trsf, deflection, true);
+ }
+ else
+ addWire(_areaOpen, wire, trsf, deflection);
}
- if(!haveShape) {
+ if (!haveShape) {
for (TopExp_Explorer it(shape, TopAbs_EDGE); it.More(); it.Next()) {
- if(plane && !isCoplanar(it.Current(),*plane)) {
+ if (plane && !isCoplanar(it.Current(), *plane)) {
++skipped;
- if(force_coplanar) continue;
+ if (force_coplanar) continue;
}
TopoDS_Wire wire = BRepBuilderAPI_MakeWire(
- TopoDS::Edge(it.Current())).Wire();
- addWire(BRep_Tool::IsClosed(wire)?_area:_areaOpen,wire,trsf,deflection);
+ TopoDS::Edge(it.Current())).Wire();
+ addWire(BRep_Tool::IsClosed(wire) ? _area : _areaOpen, wire, trsf, deflection);
}
}
- if(reorient)
+ if (reorient)
_area.Reorder();
- area.m_curves.splice(area.m_curves.end(),_area.m_curves);
- if(areaOpen)
- areaOpen->m_curves.splice(areaOpen->m_curves.end(),_areaOpen.m_curves);
+ area.m_curves.splice(area.m_curves.end(), _area.m_curves);
+ if (areaOpen)
+ areaOpen->m_curves.splice(areaOpen->m_curves.end(), _areaOpen.m_curves);
else
- area.m_curves.splice(area.m_curves.end(),_areaOpen.m_curves);
+ area.m_curves.splice(area.m_curves.end(), _areaOpen.m_curves);
return skipped;
}
-static std::vector discretize(const TopoDS_Edge &edge, double deflection) {
+static std::vector discretize(const TopoDS_Edge& edge, double deflection) {
std::vector ret;
BRepAdaptor_Curve curve(edge);
- Standard_Real efirst,elast;
+ Standard_Real efirst, elast;
efirst = curve.FirstParameter();
elast = curve.LastParameter();
- bool reversed = (edge.Orientation()==TopAbs_REVERSED);
+ bool reversed = (edge.Orientation() == TopAbs_REVERSED);
// push the first point
- ret.push_back(curve.Value(reversed?elast:efirst));
+ ret.push_back(curve.Value(reversed ? elast : efirst));
// NOTE: QuasiUniformDeflection has trouble with some B-Spline, see
// https://forum.freecadweb.org/viewtopic.php?f=15&t=42628
@@ -355,79 +355,80 @@ static std::vector discretize(const TopoDS_Edge &edge, double deflection
// GCPnts_QuasiUniformDeflection discretizer(curve, deflection, first, last);
//
GCPnts_UniformDeflection discretizer(curve, deflection, efirst, elast);
- if (!discretizer.IsDone ())
+ if (!discretizer.IsDone())
Standard_Failure::Raise("Curve discretization failed");
- if(discretizer.NbPoints () > 1) {
- int nbPoints = discretizer.NbPoints ();
+ if (discretizer.NbPoints() > 1) {
+ int nbPoints = discretizer.NbPoints();
//strangely OCC discretizer points are one-based, not zero-based, why?
- if(reversed) {
- for (int i=nbPoints-1; i>=1; --i) {
+ if (reversed) {
+ for (int i = nbPoints - 1; i >= 1; --i) {
ret.push_back(discretizer.Value(i));
}
- }else{
- for (int i=2; i<=nbPoints; i++) {
+ }
+ else {
+ for (int i = 2; i <= nbPoints; i++) {
ret.push_back(discretizer.Value(i));
}
}
}
// push the last point
- ret.push_back(curve.Value(reversed?efirst:elast));
+ ret.push_back(curve.Value(reversed ? efirst : elast));
return ret;
}
-void Area::addWire(CArea &area, const TopoDS_Wire& wire,
- const gp_Trsf *trsf, double deflection, bool to_edges)
+void Area::addWire(CArea& area, const TopoDS_Wire& wire,
+ const gp_Trsf* trsf, double deflection, bool to_edges)
{
CCurve ccurve;
- BRepTools_WireExplorer xp(trsf?TopoDS::Wire(
- wire.Moved(TopLoc_Location(*trsf))):wire);
+ BRepTools_WireExplorer xp(trsf ? TopoDS::Wire(
+ wire.Moved(TopLoc_Location(*trsf))) : wire);
- if(!xp.More()) {
+ if (!xp.More()) {
AREA_TRACE("empty wire");
return;
}
gp_Pnt p = BRep_Tool::Pnt(xp.CurrentVertex());
- ccurve.append(CVertex(Point(p.X(),p.Y())));
+ ccurve.append(CVertex(Point(p.X(), p.Y())));
- for (;xp.More();xp.Next()) {
- const TopoDS_Edge &edge = TopoDS::Edge(xp.Current());
+ for (; xp.More(); xp.Next()) {
+ const TopoDS_Edge& edge = TopoDS::Edge(xp.Current());
BRepAdaptor_Curve curve(edge);
- bool reversed = (xp.Current().Orientation()==TopAbs_REVERSED);
+ bool reversed = (xp.Current().Orientation() == TopAbs_REVERSED);
- p = curve.Value(reversed?curve.FirstParameter():curve.LastParameter());
+ p = curve.Value(reversed ? curve.FirstParameter() : curve.LastParameter());
switch (curve.GetType()) {
case GeomAbs_Line: {
- ccurve.append(CVertex(Point(p.X(),p.Y())));
- if(to_edges) {
+ ccurve.append(CVertex(Point(p.X(), p.Y())));
+ if (to_edges) {
area.append(ccurve);
ccurve.m_vertices.pop_front();
}
break;
- } case GeomAbs_Circle:{
+ } case GeomAbs_Circle: {
double first = curve.FirstParameter();
double last = curve.LastParameter();
gp_Circ circle = curve.Circle();
gp_Dir dir = circle.Axis().Direction();
gp_Pnt center = circle.Location();
- int type = dir.Z()<0?-1:1;
- if(reversed) type = -type;
- if(fabs(first-last)>M_PI) {
+ int type = dir.Z() < 0 ? -1 : 1;
+ if (reversed) type = -type;
+ if (fabs(first - last) > M_PI) {
// Split arc(circle) larger than half circle. Because gcode
// can't handle full circle?
- gp_Pnt mid = curve.Value((last-first)*0.5+first);
- ccurve.append(CVertex(type,Point(mid.X(),mid.Y()),
- Point(center.X(),center.Y())));
+ gp_Pnt mid = curve.Value((last - first) * 0.5 + first);
+ ccurve.append(CVertex(type, Point(mid.X(), mid.Y()),
+ Point(center.X(), center.Y())));
}
- ccurve.append(CVertex(type,Point(p.X(),p.Y()),
- Point(center.X(),center.Y())));
- if(to_edges) {
+ ccurve.append(CVertex(type, Point(p.X(), p.Y()),
+ Point(center.X(), center.Y())));
+ if (to_edges) {
ccurve.UnFitArcs();
CCurve c;
c.append(ccurve.m_vertices.front());
auto it = ccurve.m_vertices.begin();
- for(++it;it!=ccurve.m_vertices.end();++it) {
+ for (++it; it != ccurve.m_vertices.end(); ++it) {
c.append(*it);
area.append(c);
c.m_vertices.pop_front();
@@ -438,19 +439,20 @@ void Area::addWire(CArea &area, const TopoDS_Wire& wire,
break;
} default: {
// Discretize all other type of curves
- const auto &pts = discretize(edge,deflection);
- for(size_t i=1;im_curves.splice(myAreaOpen->m_curves.end(),areaOpen.m_curves);
+ if (areaOpen.m_curves.size()) {
+ if (&area == myArea.get() || myParams.OpenMode == OpenModeNone)
+ myAreaOpen->m_curves.splice(myAreaOpen->m_curves.end(), areaOpen.m_curves);
else
AREA_WARN("open wires discarded in clipping shapes");
}
}
-static inline void getEndPoints(const TopoDS_Edge &e, gp_Pnt &p1, gp_Pnt &p2) {
+static inline void getEndPoints(const TopoDS_Edge& e, gp_Pnt& p1, gp_Pnt& p2) {
p1 = BRep_Tool::Pnt(TopExp::FirstVertex(e));
p2 = BRep_Tool::Pnt(TopExp::LastVertex(e));
}
-static inline void getEndPoints(const TopoDS_Wire &wire, gp_Pnt &p1, gp_Pnt &p2) {
+static inline void getEndPoints(const TopoDS_Wire& wire, gp_Pnt& p1, gp_Pnt& p2) {
BRepTools_WireExplorer xp(wire);
p1 = BRep_Tool::Pnt(TopoDS::Vertex(xp.CurrentVertex()));
- for(;xp.More();xp.Next());
+ for (; xp.More(); xp.Next());
p2 = BRep_Tool::Pnt(TopoDS::Vertex(xp.CurrentVertex()));
}
@@ -572,18 +574,18 @@ struct WireJoiner {
typedef bg::model::box Box;
- static bool getBBox(const TopoDS_Edge &e, Box &box) {
+ static bool getBBox(const TopoDS_Edge& e, Box& box) {
Bnd_Box bound;
- BRepBndLib::Add(e,bound);
+ BRepBndLib::Add(e, bound);
bound.SetGap(0.1);
if (bound.IsVoid()) {
- if(FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG))
+ if (FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG))
AREA_WARN("failed to get bound of edge");
return false;
}
Standard_Real xMin, yMin, zMin, xMax, yMax, zMax;
bound.Get(xMin, yMin, zMin, xMax, yMax, zMax);
- box = Box(gp_Pnt(xMin,yMin,zMin), gp_Pnt(xMax,yMax,zMax));
+ box = Box(gp_Pnt(xMin, yMin, zMin), gp_Pnt(xMax, yMax, zMax));
return true;
}
@@ -597,18 +599,18 @@ struct WireJoiner {
int iEnd[2]; // adjacent list index end
bool used;
bool hasBox;
- EdgeInfo(const TopoDS_Edge &e, bool bbox)
- :edge(e),hasBox(false)
+ EdgeInfo(const TopoDS_Edge& e, bool bbox)
+ :edge(e), hasBox(false)
{
- getEndPoints(e,p1,p2);
- if(bbox) hasBox= getBBox(e,box);
+ getEndPoints(e, p1, p2);
+ if (bbox) hasBox = getBBox(e, box);
reset();
}
- EdgeInfo(const TopoDS_Edge &e, const gp_Pnt &pt1,
- const gp_Pnt &pt2, bool bbox)
- :edge(e),p1(pt1),p2(pt2),hasBox(false)
+ EdgeInfo(const TopoDS_Edge& e, const gp_Pnt& pt1,
+ const gp_Pnt& pt2, bool bbox)
+ :edge(e), p1(pt1), p2(pt2), hasBox(false)
{
- if(bbox) hasBox= getBBox(e,box);
+ if (bbox) hasBox = getBBox(e, box);
reset();
}
void reset() {
@@ -625,28 +627,28 @@ struct WireJoiner {
Edges::iterator it;
bool start;
VertexInfo(Edges::iterator it, bool start)
- :it(it),start(start)
+ :it(it), start(start)
{}
- bool operator==(const VertexInfo &other) const {
- return it==other.it && start==other.start;
+ bool operator==(const VertexInfo& other) const {
+ return it == other.it && start == other.start;
}
- const gp_Pnt &pt() const {
- return start?it->p1:it->p2;
+ const gp_Pnt& pt() const {
+ return start ? it->p1 : it->p2;
}
- const gp_Pnt &ptOther() const {
- return start?it->p2:it->p1;
+ const gp_Pnt& ptOther() const {
+ return start ? it->p2 : it->p1;
}
};
struct PntGetter
{
typedef const gp_Pnt& result_type;
- result_type operator()(const VertexInfo &v) const {
+ result_type operator()(const VertexInfo& v) const {
return v.pt();
}
};
- bgi::rtree vmap;
+ bgi::rtree vmap;
struct BoxGetter
{
@@ -655,7 +657,7 @@ struct WireJoiner {
return it->box;
}
};
- bgi::rtree boxMap;
+ bgi::rtree boxMap;
BRep_Builder builder;
TopoDS_Compound comp;
@@ -665,21 +667,21 @@ struct WireJoiner {
}
void remove(Edges::iterator it) {
- if(it->hasBox)
+ if (it->hasBox)
boxMap.remove(it);
- vmap.remove(VertexInfo(it,true));
- vmap.remove(VertexInfo(it,false));
+ vmap.remove(VertexInfo(it, true));
+ vmap.remove(VertexInfo(it, false));
edges.erase(it);
}
void add(Edges::iterator it) {
- vmap.insert(VertexInfo(it,true));
- vmap.insert(VertexInfo(it,false));
- if(it->hasBox)
+ vmap.insert(VertexInfo(it, true));
+ vmap.insert(VertexInfo(it, false));
+ if (it->hasBox)
boxMap.insert(it);
}
- void add(const TopoDS_Edge &e, bool bbox=false) {
+ void add(const TopoDS_Edge& e, bool bbox = false) {
// if(BRep_Tool::IsClosed(e)){
// BRepBuilderAPI_MakeWire mkWire;
// mkWire.Add(e);
@@ -687,17 +689,17 @@ struct WireJoiner {
// builder.Add(comp,wire);
// return;
// }
- gp_Pnt p1,p2;
- getEndPoints(e,p1,p2);
+ gp_Pnt p1, p2;
+ getEndPoints(e, p1, p2);
// if(p1.SquareDistance(p2) < Precision::SquareConfusion())
// return;
- edges.emplace_front(e,p1,p2,bbox);
+ edges.emplace_front(e, p1, p2, bbox);
add(edges.begin());
}
- void add(const TopoDS_Shape &shape, bool bbox=false) {
- for(TopExp_Explorer xp(shape,TopAbs_EDGE); xp.More(); xp.Next())
- add(TopoDS::Edge(xp.Current()),bbox);
+ void add(const TopoDS_Shape& shape, bool bbox = false) {
+ for (TopExp_Explorer xp(shape, TopAbs_EDGE); xp.More(); xp.Next())
+ add(TopoDS::Edge(xp.Current()), bbox);
}
//This algorithm tries to join connected edges into wires
@@ -707,65 +709,68 @@ struct WireJoiner {
//the results of rounding issue.
//
void join(double tol) {
- tol = tol*tol;
- while(edges.size()) {
+ tol = tol * tol;
+ while (edges.size()) {
auto it = edges.begin();
BRepBuilderAPI_MakeWire mkWire;
mkWire.Add(it->edge);
- gp_Pnt pstart(it->p1),pend(it->p2);
+ gp_Pnt pstart(it->p1), pend(it->p2);
remove(it);
bool done = false;
- for(int idx=0;!done&&idx<2;++idx) {
- while(edges.size()) {
+ for (int idx = 0; !done && idx < 2; ++idx) {
+ while (edges.size()) {
std::vector ret;
ret.reserve(1);
- const gp_Pnt &pt = idx==0?pstart:pend;
- vmap.query(bgi::nearest(pt,1),std::back_inserter(ret));
- assert(ret.size()==1);
+ const gp_Pnt& pt = idx == 0 ? pstart : pend;
+ vmap.query(bgi::nearest(pt, 1), std::back_inserter(ret));
+ assert(ret.size() == 1);
double d = ret[0].pt().SquareDistance(pt);
- if(d > tol) break;
+ if (d > tol) break;
- const auto &info = *ret[0].it;
+ const auto& info = *ret[0].it;
bool start = ret[0].start;
- if(d > Precision::SquareConfusion()) {
+ if (d > Precision::SquareConfusion()) {
// insert a filling edge to solve the tolerance problem
- const gp_Pnt &pt = ret[idx].pt();
- if(idx)
- mkWire.Add(BRepBuilderAPI_MakeEdge(pend,pt).Edge());
+ const gp_Pnt& pt = ret[idx].pt();
+ if (idx)
+ mkWire.Add(BRepBuilderAPI_MakeEdge(pend, pt).Edge());
else
- mkWire.Add(BRepBuilderAPI_MakeEdge(pt,pstart).Edge());
+ mkWire.Add(BRepBuilderAPI_MakeEdge(pt, pstart).Edge());
}
- if(idx==1 && start) {
+ if (idx == 1 && start) {
pend = info.p2;
mkWire.Add(info.edge);
- }else if(idx==0 && !start) {
+ }
+ else if (idx == 0 && !start) {
pstart = info.p1;
mkWire.Add(info.edge);
- }else if(idx==0 && start) {
+ }
+ else if (idx == 0 && start) {
pstart = info.p2;
mkWire.Add(TopoDS::Edge(info.edge.Reversed()));
- }else {
+ }
+ else {
pend = info.p1;
mkWire.Add(TopoDS::Edge(info.edge.Reversed()));
}
remove(ret[0].it);
- if(pstart.SquareDistance(pend)<=Precision::SquareConfusion()){
+ if (pstart.SquareDistance(pend) <= Precision::SquareConfusion()) {
done = true;
break;
}
}
}
- builder.Add(comp,mkWire.Wire());
+ builder.Add(comp, mkWire.Wire());
}
}
// split any edges that are intersected by other edge's end point in the middle
void splitEdges() {
- for(auto it=edges.begin();it!=edges.end();) {
- const auto &info = *it;
- if(!info.hasBox) {
+ for (auto it = edges.begin(); it != edges.end();) {
+ const auto& info = *it;
+ if (!info.hasBox) {
++it;
continue;
}
@@ -775,65 +780,67 @@ struct WireJoiner {
gp_Pnt pt;
bool intersects = false;
- for(auto vit=boxMap.qbegin(bgi::intersects(info.box));
- !intersects && vit!=boxMap.qend();
+ for (auto vit = boxMap.qbegin(bgi::intersects(info.box));
+ !intersects && vit != boxMap.qend();
++vit)
{
- const auto &other = *(*vit);
- if(info.edge.IsSame(other.edge)) continue;
+ const auto& other = *(*vit);
+ if (info.edge.IsSame(other.edge)) continue;
- for(int i=0; i<2; ++i) {
- const gp_Pnt &p = i?other.p1:other.p2;
- if(pstart.SquareDistance(p)<=Precision::SquareConfusion() ||
- pend.SquareDistance(p)<=Precision::SquareConfusion())
+ for (int i = 0; i < 2; ++i) {
+ const gp_Pnt& p = i ? other.p1 : other.p2;
+ if (pstart.SquareDistance(p) <= Precision::SquareConfusion() ||
+ pend.SquareDistance(p) <= Precision::SquareConfusion())
continue;
BRepExtrema_DistShapeShape extss(
- BRepBuilderAPI_MakeVertex(p),info.edge);
- if(extss.IsDone() && extss.NbSolution()) {
- const gp_Pnt &pp = extss.PointOnShape2(1);
- if(pp.SquareDistance(p)<=Precision::SquareConfusion()) {
+ BRepBuilderAPI_MakeVertex(p), info.edge);
+ if (extss.IsDone() && extss.NbSolution()) {
+ const gp_Pnt& pp = extss.PointOnShape2(1);
+ if (pp.SquareDistance(p) <= Precision::SquareConfusion()) {
pt = pp;
intersects = true;
break;
}
- }else if(FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG))
+ }
+ else if (FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG))
AREA_WARN("BRepExtrema_DistShapeShape failed");
}
}
- if(!intersects) {
+ if (!intersects) {
++it;
continue;
}
- Standard_Real first,last;
+ Standard_Real first, last;
Handle_Geom_Curve curve = BRep_Tool::Curve(it->edge, first, last);
- bool reversed = pstart.SquareDistance(curve->Value(last))<=
+ bool reversed = pstart.SquareDistance(curve->Value(last)) <=
Precision::SquareConfusion();
- BRepBuilderAPI_MakeEdge mkEdge1,mkEdge2;
- if(reversed) {
+ BRepBuilderAPI_MakeEdge mkEdge1, mkEdge2;
+ if (reversed) {
mkEdge1.Init(curve, pt, pstart);
mkEdge2.Init(curve, pend, pt);
- }else{
+ }
+ else {
mkEdge1.Init(curve, pstart, pt);
mkEdge2.Init(curve, pt, pend);
}
- if(!mkEdge1.IsDone() || !mkEdge2.IsDone()) {
- if(FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG))
- AREA_WARN((reversed?"reversed ":"")<<"edge split failed "<<
- AREA_XYZ(pstart)<<", " << AREA_XYZ(pt)<< ", "<= 0x070000
- if(BRep_Tool::IsClosed(info.edge))
+ if (BRep_Tool::IsClosed(info.edge))
#else
- if(info.p1.SquareDistance(info.p2)=0)
+ for (int i = 0; i < 2; ++i) {
+ if (info.iStart[i] >= 0)
continue;
info.iEnd[i] = info.iStart[i] = (int)adjacentList.size();
// populate adjacent list
- for(auto vit=vmap.qbegin(bgi::nearest(pt[i],INT_MAX));vit!=vmap.qend();++vit) {
+ for (auto vit = vmap.qbegin(bgi::nearest(pt[i], INT_MAX)); vit != vmap.qend(); ++vit) {
++rcount;
- if(vit->pt().SquareDistance(pt[i]) > tol)
+ if (vit->pt().SquareDistance(pt[i]) > tol)
break;
- auto &vinfo = *vit;
+ auto& vinfo = *vit;
// yes, we push ourself too, because other edges require
// this info in the adjacent list. We'll do filtering later.
adjacentList.push_back(vinfo);
++info.iEnd[i];
}
// copy the adjacent indices to all connected edges
- for(int j=info.iStart[i];j stack;
std::vector vertexStack;
- for(int iteration=1;edgesToVisit.size();++iteration) {
- EdgeInfo *currentInfo = *edgesToVisit.begin();
+ for (int iteration = 1; edgesToVisit.size(); ++iteration) {
+ EdgeInfo* currentInfo = *edgesToVisit.begin();
int currentIdx = 1; // used to tell whether search connection from the start(0) or end(1)
- TopoDS_Edge &e = currentInfo->edge;
+ TopoDS_Edge& e = currentInfo->edge;
edgesToVisit.erase(edgesToVisit.begin());
- gp_Pnt pstart=currentInfo->p1;
- gp_Pnt pend=currentInfo->p2;
+ gp_Pnt pstart = currentInfo->p1;
+ gp_Pnt pend = currentInfo->p2;
currentInfo->used = true;
currentInfo->iteration = iteration;
stack.clear();
vertexStack.clear();
// pstart and pend is the start and end vertex of the current wire
- while(true) {
+ while (true) {
// push a new stack entry
stack.emplace_back(vertexStack.size());
- auto &r = stack.back();
+ auto& r = stack.back();
// this loop is to find all edges connected to pend, and save them into stack.back()
- for(int i=currentInfo->iStart[currentIdx];iiEnd[currentIdx];++i) {
- auto &info = *adjacentList[i].it;
- if(info.iteration!=iteration) {
+ for (int i = currentInfo->iStart[currentIdx]; i < currentInfo->iEnd[currentIdx]; ++i) {
+ auto& info = *adjacentList[i].it;
+ if (info.iteration != iteration) {
info.iteration = iteration;
vertexStack.push_back(adjacentList[i]);
++r.iEnd;
}
}
- while(true) {
- auto &r = stack.back();
- if(r.iCurrent tol) {
+ if (pstart.SquareDistance(pend) > tol) {
// if the wire is not closed yet, continue search for the
// next connected edge
continue;
@@ -978,37 +986,38 @@ struct WireJoiner {
Handle(ShapeExtend_WireData) wireData = new ShapeExtend_WireData();
wireData->Add(e);
- for(auto &r : stack) {
- const auto &v = vertexStack[r.iCurrent];
- auto &info = *v.it;
- if(v.start)
+ for (auto& r : stack) {
+ const auto& v = vertexStack[r.iCurrent];
+ auto& info = *v.it;
+ if (v.start)
wireData->Add(info.edge);
else
wireData->Add(TopoDS::Edge(info.edge.Reversed()));
}
// TechDraw even uses 0.1 as tolerance. Really? Why?
- TopoDS_Wire wire = makeCleanWire(wireData,0.01);
- if(!BRep_Tool::IsClosed(wire)) {
+ TopoDS_Wire wire = makeCleanWire(wireData, 0.01);
+ if (!BRep_Tool::IsClosed(wire)) {
FC_WARN("failed to close some projection wire");
- Area::showShape(wire,"failed");
+ Area::showShape(wire, "failed");
++skips;
- }else{
- for(auto &r : stack) {
- const auto &v = vertexStack[r.iCurrent];
- auto &info = *v.it;
- if(!info.used) {
+ }
+ else {
+ for (auto& r : stack) {
+ const auto& v = vertexStack[r.iCurrent];
+ auto& info = *v.it;
+ if (!info.used) {
info.used = true;
edgesToVisit.erase(&info);
}
}
- Area::showShape(wire,"joined");
- builder.Add(comp,wire);
+ Area::showShape(wire, "joined");
+ builder.Add(comp, wire);
++count;
}
break;
}
}
- FC_TIME_LOG(t,"found " << count << " closed wires, skipped " << skips << "edges. ");
+ FC_TIME_LOG(t, "found " << count << " closed wires, skipped " << skips << "edges. ");
return skips;
}
@@ -1028,7 +1037,7 @@ struct WireJoiner {
fixer->FixConnected(Precision::Confusion());
fixer->FixClosed(Precision::Confusion());
- for (int i = 1; i <= wireData->NbEdges(); i ++) {
+ for (int i = 1; i <= wireData->NbEdges(); i++) {
TopoDS_Edge edge = fixer->WireData()->Edge(i);
sTol.SetTolerance(edge, tol, TopAbs_VERTEX);
mkWire.Add(edge);
@@ -1040,151 +1049,151 @@ struct WireJoiner {
};
-void Area::explode(const TopoDS_Shape &shape) {
- const TopoDS_Shape &plane = getPlane();
+void Area::explode(const TopoDS_Shape& shape) {
+ const TopoDS_Shape& plane = getPlane();
bool haveShape = false;
- for(TopExp_Explorer it(shape, TopAbs_FACE); it.More(); it.Next()) {
+ for (TopExp_Explorer it(shape, TopAbs_FACE); it.More(); it.Next()) {
haveShape = true;
- if(myParams.Coplanar!=CoplanarNone && !isCoplanar(it.Current(),plane)){
+ if (myParams.Coplanar != CoplanarNone && !isCoplanar(it.Current(), plane)) {
++mySkippedShapes;
- if(myParams.Coplanar == CoplanarForce)
+ if (myParams.Coplanar == CoplanarForce)
continue;
}
- for(TopExp_Explorer itw(it.Current(), TopAbs_WIRE); itw.More(); itw.Next()) {
- for(BRepTools_WireExplorer xp(TopoDS::Wire(itw.Current()));xp.More();xp.Next())
- addWire(*myArea,BRepBuilderAPI_MakeWire(
- TopoDS::Edge(xp.Current())).Wire(),&myTrsf,myParams.Deflection,true);
+ for (TopExp_Explorer itw(it.Current(), TopAbs_WIRE); itw.More(); itw.Next()) {
+ for (BRepTools_WireExplorer xp(TopoDS::Wire(itw.Current())); xp.More(); xp.Next())
+ addWire(*myArea, BRepBuilderAPI_MakeWire(
+ TopoDS::Edge(xp.Current())).Wire(), &myTrsf, myParams.Deflection, true);
}
}
- if(haveShape)
+ if (haveShape)
return;
- for(TopExp_Explorer it(shape, TopAbs_EDGE); it.More(); it.Next()) {
- if(myParams.Coplanar!=CoplanarNone && !isCoplanar(it.Current(),plane)){
+ for (TopExp_Explorer it(shape, TopAbs_EDGE); it.More(); it.Next()) {
+ if (myParams.Coplanar != CoplanarNone && !isCoplanar(it.Current(), plane)) {
++mySkippedShapes;
- if(myParams.Coplanar == CoplanarForce)
+ if (myParams.Coplanar == CoplanarForce)
continue;
}
- addWire(*myArea,BRepBuilderAPI_MakeWire(
- TopoDS::Edge(it.Current())).Wire(),&myTrsf,myParams.Deflection,true);
+ addWire(*myArea, BRepBuilderAPI_MakeWire(
+ TopoDS::Edge(it.Current())).Wire(), &myTrsf, myParams.Deflection, true);
}
}
-void Area::showShape(const TopoDS_Shape &shape, const char *name, const char *fmt, ...) {
- if(FC_LOG_INSTANCE.level()>FC_LOGLEVEL_TRACE) {
- App::Document *pcDoc = App::GetApplication().getActiveDocument();
+void Area::showShape(const TopoDS_Shape& shape, const char* name, const char* fmt, ...) {
+ if (FC_LOG_INSTANCE.level() > FC_LOGLEVEL_TRACE) {
+ App::Document* pcDoc = App::GetApplication().getActiveDocument();
if (!pcDoc)
pcDoc = App::GetApplication().newDocument();
char buf[256];
- if(!name && fmt) {
+ if (!name && fmt) {
va_list args;
va_start(args, fmt);
- vsnprintf(buf,sizeof(buf), fmt, args);
- va_end (args);
+ vsnprintf(buf, sizeof(buf), fmt, args);
+ va_end(args);
name = buf;
}
- Part::Feature *pcFeature = (Part::Feature *)pcDoc->addObject("Part::Feature", name);
+ Part::Feature* pcFeature = (Part::Feature*)pcDoc->addObject("Part::Feature", name);
pcFeature->Shape.setValue(shape);
}
}
template
-static void showShapes(const T &shapes, const char *name, const char *fmt=nullptr, ...) {
- if(FC_LOG_INSTANCE.level()>FC_LOGLEVEL_TRACE) {
+static void showShapes(const T& shapes, const char* name, const char* fmt = nullptr, ...) {
+ if (FC_LOG_INSTANCE.level() > FC_LOGLEVEL_TRACE) {
BRep_Builder builder;
TopoDS_Compound comp;
builder.MakeCompound(comp);
- for(auto &s : shapes) {
- if(s.IsNull()) continue;
- builder.Add(comp,s);
+ for (auto& s : shapes) {
+ if (s.IsNull()) continue;
+ builder.Add(comp, s);
}
char buf[256];
- if(!name && fmt) {
+ if (!name && fmt) {
va_list args;
va_start(args, fmt);
- vsnprintf(buf,sizeof(buf), fmt, args);
- va_end (args);
+ vsnprintf(buf, sizeof(buf), fmt, args);
+ va_end(args);
name = buf;
}
- Area::showShape(comp,name);
+ Area::showShape(comp, name);
}
}
template
-static int foreachSubshape(const TopoDS_Shape &shape,
- Func func, int type=TopAbs_FACE, bool groupOpenEdges=false)
+static int foreachSubshape(const TopoDS_Shape& shape,
+ Func func, int type = TopAbs_FACE, bool groupOpenEdges = false)
{
int res = -1;
std::vector openShapes;
- switch(type) {
+ switch (type) {
case TopAbs_SOLID:
- for(TopExp_Explorer it(shape,TopAbs_SOLID); it.More(); it.Next()) {
+ for (TopExp_Explorer it(shape, TopAbs_SOLID); it.More(); it.Next()) {
res = TopAbs_SOLID;
- func(it.Current(),TopAbs_SOLID);
+ func(it.Current(), TopAbs_SOLID);
}
- if(res>=0) break;
+ if (res >= 0) break;
//fall through
case TopAbs_FACE:
- for(TopExp_Explorer it(shape,TopAbs_FACE); it.More(); it.Next()) {
+ for (TopExp_Explorer it(shape, TopAbs_FACE); it.More(); it.Next()) {
res = TopAbs_FACE;
- func(it.Current(),TopAbs_FACE);
+ func(it.Current(), TopAbs_FACE);
}
- if(res>=0) break;
+ if (res >= 0) break;
//fall through
case TopAbs_WIRE:
- for(TopExp_Explorer it(shape, TopAbs_WIRE); it.More(); it.Next()) {
+ for (TopExp_Explorer it(shape, TopAbs_WIRE); it.More(); it.Next()) {
res = TopAbs_WIRE;
- if(groupOpenEdges && !BRep_Tool::IsClosed(TopoDS::Wire(it.Current())))
+ if (groupOpenEdges && !BRep_Tool::IsClosed(TopoDS::Wire(it.Current())))
openShapes.push_back(it.Current());
else
- func(it.Current(),TopAbs_WIRE);
+ func(it.Current(), TopAbs_WIRE);
}
- if(res>=0) break;
+ if (res >= 0) break;
//fall through
default:
- for(TopExp_Explorer it(shape,TopAbs_EDGE); it.More(); it.Next()) {
+ for (TopExp_Explorer it(shape, TopAbs_EDGE); it.More(); it.Next()) {
res = TopAbs_EDGE;
- if(groupOpenEdges) {
+ if (groupOpenEdges) {
TopoDS_Edge e = TopoDS::Edge(it.Current());
- gp_Pnt p1,p2;
- getEndPoints(e,p1,p2);
- if(p1.SquareDistance(p2) > Precision::SquareConfusion()) {
+ gp_Pnt p1, p2;
+ getEndPoints(e, p1, p2);
+ if (p1.SquareDistance(p2) > Precision::SquareConfusion()) {
openShapes.push_back(it.Current());
continue;
}
}
- func(it.Current(),TopAbs_EDGE);
+ func(it.Current(), TopAbs_EDGE);
}
}
- if(openShapes.empty())
+ if (openShapes.empty())
return res;
BRep_Builder builder;
TopoDS_Compound comp;
builder.MakeCompound(comp);
- for(auto &s : openShapes)
- builder.Add(comp,s);
+ for (auto& s : openShapes)
+ builder.Add(comp, s);
func(comp, TopAbs_COMPOUND);
return TopAbs_COMPOUND;
}
struct FindPlane {
- TopoDS_Shape &myPlaneShape;
- gp_Trsf &myTrsf;
- double &myZ;
- FindPlane(TopoDS_Shape &s, gp_Trsf &t, double &z)
- :myPlaneShape(s),myTrsf(t),myZ(z)
+ TopoDS_Shape& myPlaneShape;
+ gp_Trsf& myTrsf;
+ double& myZ;
+ FindPlane(TopoDS_Shape& s, gp_Trsf& t, double& z)
+ :myPlaneShape(s), myTrsf(t), myZ(z)
{}
- void operator()(const TopoDS_Shape &shape, int) {
+ void operator()(const TopoDS_Shape& shape, int) {
gp_Trsf trsf;
gp_Pln pln;
- if(!getShapePlane(shape,pln))
+ if (!getShapePlane(shape, pln))
return;
gp_Ax3 pos = pln.Position();
AREA_TRACE("plane pos " << AREA_XYZ(pos.Location()) << ", " << AREA_XYZ(pos.Direction()));
// We only use right hand coordinate, hence gp_Ax2 instead of gp_Ax3
- if(!pos.Direct()) {
+ if (!pos.Direct()) {
AREA_WARN("left hand coordinate");
pos = gp_Ax3(pos.Ax2());
}
@@ -1193,62 +1202,64 @@ struct FindPlane {
// To make things more 'normalized', we force the plane to face positive
// axis direction if it parallels to either X, Y or Z plane.
- bool x0 = fabs(dir.X()) pt.Z())
+ if (x0 && y0) {
+ TopExp_Explorer it(shape, TopAbs_VERTEX);
+ const auto& pt = BRep_Tool::Pnt(TopoDS::Vertex(it.Current()));
+ if (!myPlaneShape.IsNull() && myZ > pt.Z())
return;
myZ = pt.Z();
- }else if(!myPlaneShape.IsNull())
+ }
+ else if (!myPlaneShape.IsNull())
return;
myPlaneShape = shape;
myTrsf = trsf;
AREA_TRACE("plane pos " << AREA_XYZ(pos.Location()) <<
- ", " << AREA_XYZ(pos.Direction()));
+ ", " << AREA_XYZ(pos.Direction()));
}
};
-TopoDS_Shape Area::findPlane(const TopoDS_Shape &shape, gp_Trsf &trsf)
+TopoDS_Shape Area::findPlane(const TopoDS_Shape& shape, gp_Trsf& trsf)
{
TopoDS_Shape plane;
double top_z;
- foreachSubshape(shape,FindPlane(plane,trsf,top_z));
+ foreachSubshape(shape, FindPlane(plane, trsf, top_z));
return plane;
}
-int Area::project(TopoDS_Shape &shape_out,
- const TopoDS_Shape &shape_in,
- const AreaParams *params,
- const TopoDS_Shape *work_plane)
+int Area::project(TopoDS_Shape& shape_out,
+ const TopoDS_Shape& shape_in,
+ const AreaParams* params,
+ const TopoDS_Shape* work_plane)
{
- FC_TIME_INIT2(t,t1);
+ FC_TIME_INIT2(t, t1);
Handle_HLRBRep_Algo brep_hlr;
- gp_Dir dir(0,0,1);
+ gp_Dir dir(0, 0, 1);
try {
brep_hlr = new HLRBRep_Algo();
brep_hlr->Add(shape_in, 0);
- HLRAlgo_Projector projector(gp_Ax2(gp_Pnt(),dir));
+ HLRAlgo_Projector projector(gp_Ax2(gp_Pnt(), dir));
brep_hlr->Projector(projector);
brep_hlr->Update();
brep_hlr->Hide();
- } catch (...) {
+ }
+ catch (...) {
AREA_ERR("error occurred while projecting shape");
return -1;
}
- FC_TIME_LOG(t1,"HLRBrep_Algo");
+ FC_TIME_LOG(t1, "HLRBrep_Algo");
WireJoiner joiner;
try {
#define ADD_HLR_SHAPE(_name) \
@@ -1260,7 +1271,7 @@ int Area::project(TopoDS_Shape &shape_out,
}
TopoDS_Shape shape;
HLRBRep_HLRToShape hlrToShape(brep_hlr);
- ADD_HLR_SHAPE(V)
+ ADD_HLR_SHAPE(V);
ADD_HLR_SHAPE(OutLineV);
// ADD_HLR_SHAPE(Rg1LineV);
// ADD_HLR_SHAPE(RgNLineV);
@@ -1275,19 +1286,19 @@ int Area::project(TopoDS_Shape &shape_out,
AREA_ERR("error occurred while extracting edges");
return -1;
}
- FC_TIME_LOG(t1,"WireJoiner init");
+ FC_TIME_LOG(t1, "WireJoiner init");
joiner.splitEdges();
- FC_TIME_LOG(t1,"WireJoiner splitEdges");
- for(const auto &v : joiner.edges) {
+ FC_TIME_LOG(t1, "WireJoiner splitEdges");
+ for (const auto& v : joiner.edges) {
// joiner.builder.Add(joiner.comp,BRepBuilderAPI_MakeWire(v.edge).Wire());
- showShape(v.edge,"split");
+ showShape(v.edge, "split");
}
double tolerance = params ? params->Tolerance : Precision::Confusion();
int skips = joiner.findClosedWires(tolerance);
- FC_TIME_LOG(t1,"WireJoiner findClosedWires");
+ FC_TIME_LOG(t1, "WireJoiner findClosedWires");
- showShape(joiner.comp,"pre_project");
+ showShape(joiner.comp, "pre_project");
Area area(params);
area.myParams.SectionCount = 0;
@@ -1297,23 +1308,23 @@ int Area::project(TopoDS_Shape &shape_out,
area.myParams.FitArcs = false;
area.myParams.Reorient = false;
area.myParams.Outline = true;
- area.myParams.Fill = TopExp_Explorer(shape_in,TopAbs_FACE).More()?FillFace:FillNone;
+ area.myParams.Fill = TopExp_Explorer(shape_in, TopAbs_FACE).More() ? FillFace : FillNone;
area.myParams.Coplanar = CoplanarNone;
area.myProjecting = true;
if (work_plane) {
area.myWorkPlane = *work_plane;
}
area.add(joiner.comp, OperationUnion);
- const TopoDS_Shape &shape = area.getShape();
+ const TopoDS_Shape& shape = area.getShape();
area.myParams.dump("project");
- showShape(shape,"projected");
+ showShape(shape, "projected");
- FC_TIME_LOG(t1,"Clipper wire union");
- FC_TIME_LOG(t,"project total");
+ FC_TIME_LOG(t1, "Clipper wire union");
+ FC_TIME_LOG(t, "project total");
- if(shape.IsNull()) {
+ if (shape.IsNull()) {
AREA_ERR("project failed");
return -1;
}
@@ -1322,103 +1333,109 @@ int Area::project(TopoDS_Shape &shape_out,
}
std::vector > Area::makeSections(
- PARAM_ARGS(PARAM_FARG,AREA_PARAMS_SECTION_EXTRA),
- const std::vector &_heights,
- const TopoDS_Shape §ion_plane)
+ PARAM_ARGS(PARAM_FARG, AREA_PARAMS_SECTION_EXTRA),
+ const std::vector& _heights,
+ const TopoDS_Shape& section_plane)
{
TopoDS_Shape plane;
gp_Trsf trsf;
- if(!section_plane.IsNull())
- plane = findPlane(section_plane,trsf);
+ if (!section_plane.IsNull())
+ plane = findPlane(section_plane, trsf);
else
plane = getPlane(&trsf);
- if(plane.IsNull())
+ if (plane.IsNull())
throw Base::ValueError("failed to obtain section plane");
- FC_TIME_INIT2(t,t1);
+ FC_TIME_INIT2(t, t1);
TopLoc_Location loc(trsf);
Bnd_Box bounds;
- for(const Shape &s : myShapes) {
- const TopoDS_Shape &shape = s.shape.Moved(loc);
+ for (const Shape& s : myShapes) {
+ const TopoDS_Shape& shape = s.shape.Moved(loc);
BRepBndLib::Add(shape, bounds, Standard_False);
}
bounds.SetGap(0.0);
Standard_Real xMin, yMin, zMin, xMax, yMax, zMax;
bounds.Get(xMin, yMin, zMin, xMax, yMax, zMax);
- AREA_TRACE("section bounds X("< heights;
double tolerance = 0.0;
- if(_heights.empty()) {
+ if (_heights.empty()) {
double z;
double d = fabs(myParams.Stepdown);
- if(myParams.SectionCount>1 && d 1 && d < Precision::Confusion())
throw Base::ValueError("invalid stepdown");
- if(mode == SectionModeBoundBox) {
- if(myParams.Stepdown > 0.0)
- z = zMax-myParams.SectionOffset;
+ if (mode == SectionModeBoundBox) {
+ if (myParams.Stepdown > 0.0)
+ z = zMax - myParams.SectionOffset;
else
- z = zMin+myParams.SectionOffset;
- }else if(mode == SectionModeWorkplane){
+ z = zMin + myParams.SectionOffset;
+ }
+ else if (mode == SectionModeWorkplane) {
// Because we've transformed the shapes using the work plane so
// that the work plane is aligned with xy0 plane, the starting Z
// value shall be 0 minus the given section offset. Note the
// section offset is relative to the starting Z
- if(myParams.Stepdown > 0.0)
+ if (myParams.Stepdown > 0.0)
z = -myParams.SectionOffset;
else
z = myParams.SectionOffset;
- } else {
- gp_Pnt pt(0,0,myParams.SectionOffset);
+ }
+ else {
+ gp_Pnt pt(0, 0, myParams.SectionOffset);
z = pt.Transformed(loc).Z();
}
- if(z > zMax)
+ if (z > zMax)
z = zMax;
- else if(z < zMin)
+ else if (z < zMin)
z = zMin;
double dz;
- if(myParams.Stepdown>0.0) {
+ if (myParams.Stepdown > 0.0) {
dz = z - zMin;
tolerance = myParams.SectionTolerance;
- }else{
+ }
+ else {
dz = zMax - z;
tolerance = -myParams.SectionTolerance;
}
int count = myParams.SectionCount;
- if(count<0 || count*d > dz)
- count = floor(dz/d)+1;
+ if (count<0 || count * d > dz)
+ count = floor(dz / d) + 1;
heights.reserve(count);
- for(int i=0;i0.0) break;
- }else if(zMax-z 0.0) break;
+ }
+ else if (zMax - z < myParams.SectionTolerance) {
+ height = zMax - myParams.SectionTolerance;
+ if (FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG))
+ AREA_WARN("hit top " << z << ',' << zMax << ',' << height);
heights.push_back(height);
- if(myParams.Stepdown<0.0) break;
- }else
+ if (myParams.Stepdown < 0.0) break;
+ }
+ else
heights.push_back(height);
}
- }else{
+ }
+ else {
heights.reserve(_heights.size());
bool hitMax = false, hitMin = false;
- for(double z : _heights) {
- switch(mode) {
+ for (double z : _heights) {
+ switch (mode) {
case SectionModeAbsolute: {
- gp_Pnt pt(0,0,z);
+ gp_Pnt pt(0, 0, z);
z = pt.Transformed(loc).Z();
break;
}case SectionModeBoundBox:
@@ -1430,79 +1447,80 @@ std::vector > Area::makeSections(
default:
throw Base::ValueError("invalid section mode");
}
- if(z-zMin > sections;
sections.reserve(heights.size());
std::list projectedShapes;
- if(project) {
- projectedShapes = getProjectedShapes(trsf,false);
- if(projectedShapes.empty()) {
+ if (project) {
+ projectedShapes = getProjectedShapes(trsf, false);
+ if (projectedShapes.empty()) {
AREA_ERR("empty projection");
return sections;
}
}
tolerance *= 2.0;
- bool can_retry = fabs(tolerance)>Precision::Confusion();
+ bool can_retry = fabs(tolerance) > Precision::Confusion();
TopLoc_Location locInverse(loc.Inverted());
- for(size_t i=0;i area(std::make_shared(&myParams));
area->myParams.Outline = false;
area->setPlane(face.Moved(locInverse));
- if(project) {
- for(const auto &s : projectedShapes) {
+ if (project) {
+ for (const auto& s : projectedShapes) {
gp_Trsf t;
- t.SetTranslation(gp_Vec(0,0,-d));
+ t.SetTranslation(gp_Vec(0, 0, -d));
TopLoc_Location wloc(t);
- area->add(s.shape.Moved(wloc).Moved(locInverse),s.op);
+ area->add(s.shape.Moved(wloc).Moved(locInverse), s.op);
}
sections.push_back(area);
break;
}
- for(auto it=myShapes.begin();it!=myShapes.end();++it) {
- const auto &s = *it;
+ for (auto it = myShapes.begin(); it != myShapes.end(); ++it) {
+ const auto& s = *it;
BRep_Builder builder;
TopoDS_Compound comp;
builder.MakeCompound(comp);
- for(TopExp_Explorer xp(s.shape.Moved(loc), TopAbs_SOLID); xp.More(); xp.Next()) {
- showShape(xp.Current(),nullptr,"section_%u_shape",i);
+ for (TopExp_Explorer xp(s.shape.Moved(loc), TopAbs_SOLID); xp.More(); xp.Next()) {
+ showShape(xp.Current(), nullptr, "section_%u_shape", i);
std::list wires;
- Part::CrossSection section(a,b,c,xp.Current());
+ Part::CrossSection section(a, b, c, xp.Current());
wires = section.slice(-d);
- showShapes(wires,nullptr,"section_%u_wire",i);
- if(wires.empty()) {
+ showShapes(wires, nullptr, "section_%u_wire", i);
+ if (wires.empty()) {
AREA_LOG("Section returns no wires");
continue;
}
@@ -1510,85 +1528,88 @@ std::vector > Area::makeSections(
// always try to make face to normalize wire orientation
Part::FaceMakerBullseye mkFace;
mkFace.setPlane(pln);
- for(const TopoDS_Wire &wire : wires) {
- if(BRep_Tool::IsClosed(wire))
+ for (const TopoDS_Wire& wire : wires) {
+ if (BRep_Tool::IsClosed(wire))
mkFace.addWire(wire);
}
try {
mkFace.Build();
- const TopoDS_Shape &shape = mkFace.Shape();
+ const TopoDS_Shape& shape = mkFace.Shape();
if (shape.IsNull())
AREA_WARN("FaceMakerBullseye return null shape on section");
else {
- showShape(shape,nullptr,"section_%u_face",i);
- for(auto it=wires.begin(),itNext=it;it!=wires.end();it=itNext) {
+ showShape(shape, nullptr, "section_%u_face", i);
+ for (auto it = wires.begin(), itNext = it; it != wires.end(); it = itNext) {
++itNext;
- if(BRep_Tool::IsClosed(*it))
+ if (BRep_Tool::IsClosed(*it))
wires.erase(it);
}
- for(TopExp_Explorer xp(shape,myParams.Fill==FillNone?TopAbs_WIRE:TopAbs_FACE);
- xp.More();xp.Next())
+ for (TopExp_Explorer xp(shape, myParams.Fill == FillNone ? TopAbs_WIRE : TopAbs_FACE);
+ xp.More(); xp.Next())
{
- builder.Add(comp,xp.Current());
+ builder.Add(comp, xp.Current());
}
}
- }catch (Base::Exception &e){
+ }
+ catch (Base::Exception& e) {
AREA_WARN("FaceMakerBullseye failed on section: " << e.what());
}
- for(const TopoDS_Wire &wire : wires)
- builder.Add(comp,wire);
+ for (const TopoDS_Wire& wire : wires)
+ builder.Add(comp, wire);
}
// Make sure the compound has at least one edge
- if(TopExp_Explorer(comp,TopAbs_EDGE).More()) {
- const TopoDS_Shape &shape = comp.Moved(locInverse);
- showShape(shape,nullptr,"section_%u_result",i);
- area->add(shape,s.op);
- }else if(area->myShapes.empty()){
+ if (TopExp_Explorer(comp, TopAbs_EDGE).More()) {
+ const TopoDS_Shape& shape = comp.Moved(locInverse);
+ showShape(shape, nullptr, "section_%u_result", i);
+ area->add(shape, s.op);
+ }
+ else if (area->myShapes.empty()) {
auto itNext = it;
- if(++itNext != myShapes.end() &&
- (itNext->op==OperationIntersection ||
- itNext->op==OperationDifference))
+ if (++itNext != myShapes.end() &&
+ (itNext->op == OperationIntersection ||
+ itNext->op == OperationDifference))
{
break;
}
}
}
- if(area->myShapes.size()){
+ if (area->myShapes.size()) {
sections.push_back(area);
- FC_TIME_LOG(t1,"makeSection " << z);
- showShape(area->getShape(),nullptr,"section_%u_final",i);
+ FC_TIME_LOG(t1, "makeSection " << z);
+ showShape(area->getShape(), nullptr, "section_%u_final", i);
break;
}
- if(retried) {
+ if (retried) {
AREA_WARN("Discard empty section");
break;
- }else{
- AREA_TRACE("retry section " <"<" << z + tolerance);
z += tolerance;
retried = true;
}
}
}
- FC_TIME_LOG(t,"makeSection count: " << sections.size()<<", total");
+ FC_TIME_LOG(t, "makeSection count: " << sections.size() << ", total");
return sections;
}
-TopoDS_Shape Area::getPlane(gp_Trsf *trsf) {
- if(!myWorkPlane.IsNull()) {
- if(trsf) *trsf = myTrsf;
+TopoDS_Shape Area::getPlane(gp_Trsf* trsf) {
+ if (!myWorkPlane.IsNull()) {
+ if (trsf) *trsf = myTrsf;
return myWorkPlane;
}
- if(myShapePlane.IsNull()) {
- if(myShapes.empty())
+ if (myShapePlane.IsNull()) {
+ if (myShapes.empty())
throw Base::ValueError("no shape added");
double top_z;
- for(auto &s : myShapes)
- foreachSubshape(s.shape,FindPlane(myShapePlane,myTrsf,top_z));
- if(myShapePlane.IsNull())
+ for (auto& s : myShapes)
+ foreachSubshape(s.shape, FindPlane(myShapePlane, myTrsf, top_z));
+ if (myShapePlane.IsNull())
throw Base::ValueError("shapes are not planar");
}
- if(trsf) *trsf = myTrsf;
+ if (trsf) *trsf = myTrsf;
return myShapePlane;
}
@@ -1596,42 +1617,43 @@ bool Area::isBuilt() const {
return (myArea || mySections.size());
}
-std::list Area::getProjectedShapes(const gp_Trsf &trsf, bool inverse) const
+std::list Area::getProjectedShapes(const gp_Trsf& trsf, bool inverse) const
{
std::list ret;
TopLoc_Location loc(trsf);
TopLoc_Location locInverse(loc.Inverted());
mySkippedShapes = 0;
- for(auto &s : myShapes) {
+ for (auto& s : myShapes) {
TopoDS_Shape out;
int skipped =
Area::project(out, s.shape.Moved(loc), &myParams, &myWorkPlane);
- if(skipped < 0) {
+ if (skipped < 0) {
++mySkippedShapes;
continue;
- }else
+ }
+ else
mySkippedShapes += skipped;
- if(!out.IsNull())
- ret.emplace_back(s.op,inverse?out.Moved(locInverse):out);
+ if (!out.IsNull())
+ ret.emplace_back(s.op, inverse ? out.Moved(locInverse) : out);
}
- if(mySkippedShapes)
+ if (mySkippedShapes)
AREA_WARN("skipped " << mySkippedShapes << " sub shapes during projection");
return ret;
}
void Area::build() {
- if(isBuilt())
+ if (isBuilt())
return;
- if(myShapes.empty())
+ if (myShapes.empty())
throw Base::ValueError("no shape added");
#define AREA_MY(_param) myParams.PARAM_FNAME(_param)
- PARAM_ENUM_CONVERT(AREA_MY,PARAM_FNAME,PARAM_ENUM_EXCEPT,AREA_PARAMS_CLIPPER_FILL);
+ PARAM_ENUM_CONVERT(AREA_MY, PARAM_FNAME, PARAM_ENUM_EXCEPT, AREA_PARAMS_CLIPPER_FILL);
- if(myHaveSolid && myParams.SectionCount) {
- mySections = makeSections(PARAM_FIELDS(AREA_MY,AREA_PARAMS_SECTION_EXTRA));
+ if (myHaveSolid && myParams.SectionCount) {
+ mySections = makeSections(PARAM_FIELDS(AREA_MY, AREA_PARAMS_SECTION_EXTRA));
return;
}
@@ -1650,51 +1672,52 @@ void Area::build() {
short op = OperationUnion;
bool pending = false;
bool exploding = myParams.Explode;
- const auto &shapes = (myParams.Outline&&!myProjecting)?getProjectedShapes(trsf):myShapes;
- for(const Shape &s : shapes) {
- if(exploding) {
+ const auto& shapes = (myParams.Outline && !myProjecting) ? getProjectedShapes(trsf) : myShapes;
+ for (const Shape& s : shapes) {
+ if (exploding) {
exploding = false;
explode(s.shape);
continue;
- }else if(op!=s.op) {
- if(myParams.OpenMode!=OpenModeNone)
- myArea->m_curves.splice(myArea->m_curves.end(),myAreaOpen->m_curves);
+ }
+ else if (op != s.op) {
+ if (myParams.OpenMode != OpenModeNone)
+ myArea->m_curves.splice(myArea->m_curves.end(), myAreaOpen->m_curves);
pending = false;
- if(areaClip.m_curves.size()) {
- if(op == OperationCompound)
- myArea->m_curves.splice(myArea->m_curves.end(),areaClip.m_curves);
- else{
- myArea->Clip(toClipperOp(op),&areaClip,SubjectFill,ClipFill);
+ if (areaClip.m_curves.size()) {
+ if (op == OperationCompound)
+ myArea->m_curves.splice(myArea->m_curves.end(), areaClip.m_curves);
+ else {
+ myArea->Clip(toClipperOp(op), &areaClip, SubjectFill, ClipFill);
areaClip.m_curves.clear();
}
}
- op=s.op;
+ op = s.op;
}
- addToBuild(op==OperationUnion?*myArea:areaClip,s.shape);
+ addToBuild(op == OperationUnion ? *myArea : areaClip, s.shape);
pending = true;
}
- if(mySkippedShapes && !myHaveSolid)
- AREA_WARN((myParams.Coplanar==CoplanarForce?"Skipped ":"Found ")<<
- mySkippedShapes<<" non coplanar shapes");
+ if (mySkippedShapes && !myHaveSolid)
+ AREA_WARN((myParams.Coplanar == CoplanarForce ? "Skipped " : "Found ") <<
+ mySkippedShapes << " non coplanar shapes");
- if(pending){
- if(myParams.OpenMode!=OpenModeNone)
- myArea->m_curves.splice(myArea->m_curves.end(),myAreaOpen->m_curves);
- if(op == OperationCompound)
- myArea->m_curves.splice(myArea->m_curves.end(),areaClip.m_curves);
- else{
- myArea->Clip(toClipperOp(op),&areaClip,SubjectFill,ClipFill);
+ if (pending) {
+ if (myParams.OpenMode != OpenModeNone)
+ myArea->m_curves.splice(myArea->m_curves.end(), myAreaOpen->m_curves);
+ if (op == OperationCompound)
+ myArea->m_curves.splice(myArea->m_curves.end(), areaClip.m_curves);
+ else {
+ myArea->Clip(toClipperOp(op), &areaClip, SubjectFill, ClipFill);
}
}
- myArea->m_curves.splice(myArea->m_curves.end(),myAreaOpen->m_curves);
+ myArea->m_curves.splice(myArea->m_curves.end(), myAreaOpen->m_curves);
//Reassemble wires after explode
- if(myParams.Explode) {
+ if (myParams.Explode) {
WireJoiner joiner;
gp_Trsf trsf(myTrsf.Inverted());
- for(const auto &c : myArea->m_curves) {
- auto wire = toShape(c,&trsf);
- if(!wire.IsNull())
+ for (const auto& c : myArea->m_curves) {
+ auto wire = toShape(c, &trsf);
+ if (!wire.IsNull())
joiner.add(wire);
}
joiner.join(Precision::Confusion());
@@ -1703,36 +1726,37 @@ void Area::build() {
area.myParams.Explode = false;
area.myParams.Coplanar = CoplanarNone;
area.myWorkPlane = getPlane(&area.myTrsf);
- area.add(joiner.comp,OperationCompound);
+ area.add(joiner.comp, OperationCompound);
area.build();
myArea = std::move(area.myArea);
}
- if(myParams.Outline) {
+ if (myParams.Outline) {
myArea->Reorder();
- for(auto it=myArea->m_curves.begin(),itNext=it;
- it!=myArea->m_curves.end();
- it=itNext)
+ for (auto it = myArea->m_curves.begin(), itNext = it;
+ it != myArea->m_curves.end();
+ it = itNext)
{
++itNext;
- auto &curve = *it;
- if(curve.IsClosed() && curve.IsClockwise())
+ auto& curve = *it;
+ if (curve.IsClosed() && curve.IsClockwise())
myArea->m_curves.erase(it);
}
}
- FC_TIME_TRACE(t,"prepare");
+ FC_TIME_TRACE(t, "prepare");
- }catch(...) {
+ }
+ catch (...) {
clean();
throw;
}
}
-TopoDS_Shape Area::toShape(CArea &area, short fill, int reorient) {
+TopoDS_Shape Area::toShape(CArea& area, short fill, int reorient) {
gp_Trsf trsf(myTrsf.Inverted());
bool bFill;
- switch(fill){
+ switch (fill) {
case Area::FillAuto:
bFill = myHaveFace;
break;
@@ -1742,15 +1766,15 @@ TopoDS_Shape Area::toShape(CArea &area, short fill, int reorient) {
default:
bFill = false;
}
- if(myParams.FitArcs) {
- if(&area == myArea.get()) {
+ if (myParams.FitArcs) {
+ if (&area == myArea.get()) {
CArea copy(area);
copy.FitArcs();
- return toShape(copy,bFill,&trsf,reorient);
+ return toShape(copy, bFill, &trsf, reorient);
}
area.FitArcs();
}
- return toShape(area,bFill,&trsf,reorient);
+ return toShape(area, bFill, &trsf, reorient);
}
@@ -1777,31 +1801,31 @@ TopoDS_Shape Area::toShape(CArea &area, short fill, int reorient) {
TopoDS_Shape Area::getShape(int index) {
build();
- AREA_SECTION(getShape,index);
+ AREA_SECTION(getShape, index);
- if(myShapeDone)
+ if (myShapeDone)
return myShape;
- if(!myArea)
+ if (!myArea)
return TopoDS_Shape();
CAreaConfig conf(myParams);
// if no offset, try pocket
- if(fabs(myParams.Offset) < Precision::Confusion()) {
- if(myParams.PocketMode == PocketModeNone) {
- myShape = toShape(*myArea,myParams.Fill);
+ if (fabs(myParams.Offset) < Precision::Confusion()) {
+ if (myParams.PocketMode == PocketModeNone) {
+ myShape = toShape(*myArea, myParams.Fill);
myShapeDone = true;
return myShape;
}
- myShape = makePocket(index,PARAM_FIELDS(AREA_MY,AREA_PARAMS_POCKET));
+ myShape = makePocket(index, PARAM_FIELDS(AREA_MY, AREA_PARAMS_POCKET));
myShapeDone = true;
return myShape;
}
// if no pocket, do offset or thicken
- if(myParams.PocketMode == PocketModeNone){
- myShape = makeOffset(index,PARAM_FIELDS(AREA_MY,AREA_PARAMS_OFFSET));
+ if (myParams.PocketMode == PocketModeNone) {
+ myShape = makeOffset(index, PARAM_FIELDS(AREA_MY, AREA_PARAMS_OFFSET));
myShapeDone = true;
return myShape;
}
@@ -1810,28 +1834,29 @@ TopoDS_Shape Area::getShape(int index) {
// do offset first, then pocket the inner most offset shape
std::list > areas;
- makeOffset(areas,PARAM_FIELDS(AREA_MY,AREA_PARAMS_OFFSET));
+ makeOffset(areas, PARAM_FIELDS(AREA_MY, AREA_PARAMS_OFFSET));
- if(areas.empty())
+ if (areas.empty())
areas.push_back(make_shared(*myArea));
Area areaPocket(&myParams);
bool front = true;
- if(areas.size()>1) {
+ if (areas.size() > 1) {
double step = myParams.Stepover;
- if(fabs(step)0;
+ front = step > 0;
}
// for pocketing, we discard the outer most offset wire in order to achieve
// the effect of offsetting shape first than pocket, where the actual offset
// path is not wanted. For extra outline profiling, add extra_offset
- if(front) {
- areaPocket.add(toShape(*areas.front(),myParams.Fill));
+ if (front) {
+ areaPocket.add(toShape(*areas.front(), myParams.Fill));
areas.pop_back();
- }else{
- areaPocket.add(toShape(*areas.back(),myParams.Fill));
+ }
+ else {
+ areaPocket.add(toShape(*areas.back(), myParams.Fill));
areas.pop_front();
}
@@ -1839,47 +1864,47 @@ TopoDS_Shape Area::getShape(int index) {
TopoDS_Compound compound;
builder.MakeCompound(compound);
- short fill = myParams.Thicken?FillFace:FillNone;
+ short fill = myParams.Thicken ? FillFace : FillNone;
FC_TIME_INIT(t2);
FC_DURATION_DECL_INIT(d);
- for(shared_ptr area : areas) {
- if(myParams.Thicken){
+ for (shared_ptr area : areas) {
+ if (myParams.Thicken) {
area->Thicken(myParams.ToolRadius);
- FC_DURATION_PLUS(d,t2);
+ FC_DURATION_PLUS(d, t2);
}
- const TopoDS_Shape &shape = toShape(*area,fill);
- if(shape.IsNull()) continue;
- builder.Add(compound,shape);
+ const TopoDS_Shape& shape = toShape(*area, fill);
+ if (shape.IsNull()) continue;
+ builder.Add(compound, shape);
}
- if(myParams.Thicken)
- FC_DURATION_LOG(d,"Thicken");
+ if (myParams.Thicken)
+ FC_DURATION_LOG(d, "Thicken");
// make sure the compound has at least one edge
- if(TopExp_Explorer(compound,TopAbs_EDGE).More()) {
- builder.Add(compound,areaPocket.makePocket(
- -1,PARAM_FIELDS(AREA_MY,AREA_PARAMS_POCKET)));
+ if (TopExp_Explorer(compound, TopAbs_EDGE).More()) {
+ builder.Add(compound, areaPocket.makePocket(
+ -1, PARAM_FIELDS(AREA_MY, AREA_PARAMS_POCKET)));
myShape = compound;
}
myShapeDone = true;
- FC_TIME_LOG(t,"total");
+ FC_TIME_LOG(t, "total");
return myShape;
}
-TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET),
- int reorient, bool from_center)
+TopoDS_Shape Area::makeOffset(int index, PARAM_ARGS(PARAM_FARG, AREA_PARAMS_OFFSET),
+ int reorient, bool from_center)
{
build();
- AREA_SECTION(makeOffset,index,PARAM_FIELDS(PARAM_FARG,AREA_PARAMS_OFFSET),reorient,from_center);
+ AREA_SECTION(makeOffset, index, PARAM_FIELDS(PARAM_FARG, AREA_PARAMS_OFFSET), reorient, from_center);
std::list > areas;
- makeOffset(areas,PARAM_FIELDS(PARAM_FARG,AREA_PARAMS_OFFSET),from_center);
- if(areas.empty()) {
- if(myParams.Thicken && myParams.ToolRadius>Precision::Confusion()) {
+ makeOffset(areas, PARAM_FIELDS(PARAM_FARG, AREA_PARAMS_OFFSET), from_center);
+ if (areas.empty()) {
+ if (myParams.Thicken && myParams.ToolRadius > Precision::Confusion()) {
CArea area(*myArea);
FC_TIME_INIT(t);
area.Thicken(myParams.ToolRadius);
- FC_TIME_LOG(t,"Thicken");
- return toShape(area,FillFace,reorient);
+ FC_TIME_LOG(t, "Thicken");
+ return toShape(area, FillFace, reorient);
}
return TopoDS_Shape();
}
@@ -1889,116 +1914,120 @@ TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET
FC_TIME_INIT(t);
FC_DURATION_DECL_INIT(d);
- bool thicken = myParams.Thicken && myParams.ToolRadius>Precision::Confusion();
+ bool thicken = myParams.Thicken && myParams.ToolRadius > Precision::Confusion();
- for(shared_ptr area : areas) {
+ for (shared_ptr area : areas) {
short fill;
- if(thicken){
+ if (thicken) {
area->Thicken(myParams.ToolRadius);
- FC_DURATION_PLUS(d,t);
+ FC_DURATION_PLUS(d, t);
fill = FillFace;
- }else if(areas.size()==1)
+ }
+ else if (areas.size() == 1)
fill = myParams.Fill;
else
fill = FillNone;
- const TopoDS_Shape &shape = toShape(*area,fill,reorient);
- if(shape.IsNull()) continue;
- builder.Add(compound,shape);
+ const TopoDS_Shape& shape = toShape(*area, fill, reorient);
+ if (shape.IsNull()) continue;
+ builder.Add(compound, shape);
}
- if(thicken)
- FC_DURATION_LOG(d,"Thicken");
- if(TopExp_Explorer(compound,TopAbs_EDGE).More()) {
+ if (thicken)
+ FC_DURATION_LOG(d, "Thicken");
+ if (TopExp_Explorer(compound, TopAbs_EDGE).More()) {
return TopoDS_Shape(std::move(compound));
}
return TopoDS_Shape();
}
-void Area::makeOffset(list > &areas,
- PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET), bool from_center)
+void Area::makeOffset(list >& areas,
+ PARAM_ARGS(PARAM_FARG, AREA_PARAMS_OFFSET), bool from_center)
{
- if(fabs(offset) 0) {
+ if (extra_pass > 0) {
count += extra_pass;
- }else{
- if(stepover>0 || offset>0)
+ }
+ else {
+ if (stepover > 0 || offset > 0)
throw Base::ValueError("invalid extra count");
// In this case, we loop until no outputs from clipper
- count=-1;
+ count = -1;
}
}
- PARAM_ENUM_CONVERT(AREA_MY,PARAM_FNAME,PARAM_ENUM_EXCEPT,AREA_PARAMS_OFFSET_CONF);
+ PARAM_ENUM_CONVERT(AREA_MY, PARAM_FNAME, PARAM_ENUM_EXCEPT, AREA_PARAMS_OFFSET_CONF);
#ifdef AREA_OFFSET_ALGO
- PARAM_ENUM_CONVERT(AREA_MY,PARAM_FNAME,PARAM_ENUM_EXCEPT,AREA_PARAMS_CLIPPER_FILL);
+ PARAM_ENUM_CONVERT(AREA_MY, PARAM_FNAME, PARAM_ENUM_EXCEPT, AREA_PARAMS_CLIPPER_FILL);
#endif
- if(offset<0) {
+ if (offset < 0) {
stepover = -fabs(stepover);
- if(count<0) {
- if(!last_stepover)
- last_stepover = offset*0.5;
+ if (count < 0) {
+ if (!last_stepover)
+ last_stepover = offset * 0.5;
else
last_stepover = -fabs(last_stepover);
- }else
+ }
+ else
last_stepover = 0;
}
- for(int i=0;count<0||i());
else
areas.push_back(make_shared());
- CArea &area = from_center?(*areas.front()):(*areas.back());
+ CArea& area = from_center ? (*areas.front()) : (*areas.back());
CArea areaOpen;
#ifdef AREA_OFFSET_ALGO
- if(myParams.Algo == Area::Algolibarea) {
- for(const CCurve &c : myArea->m_curves) {
- if(c.IsClosed())
+ if (myParams.Algo == Area::Algolibarea) {
+ for (const CCurve& c : myArea->m_curves) {
+ if (c.IsClosed())
area.append(c);
else
areaOpen.append(c);
}
- }else
+ }
+ else
#endif
area = *myArea;
#ifdef AREA_OFFSET_ALGO
- switch(myParams.Algo){
+ switch (myParams.Algo) {
case Area::Algolibarea:
// libarea somehow fails offset without Reorder, but ClipperOffset
// works okay. Don't know why
area.Reorder();
area.Offset(-offset);
- if(areaOpen.m_curves.size()) {
+ if (areaOpen.m_curves.size()) {
areaOpen.Thicken(offset);
- area.Clip(ClipperLib::ctUnion,&areaOpen,SubjectFill,ClipFill);
+ area.Clip(ClipperLib::ctUnion, &areaOpen, SubjectFill, ClipFill);
}
break;
case Area::AlgoClipperOffset:
#endif
- area.OffsetWithClipper(offset,JoinType,EndType,
- myParams.MiterLimit,myParams.RoundPrecision);
+ area.OffsetWithClipper(offset, JoinType, EndType,
+ myParams.MiterLimit, myParams.RoundPrecision);
#ifdef AREA_OFFSET_ALGO
break;
}
#endif
- if(count>1)
- FC_TIME_LOG(t1,"makeOffset " << i << '/' << count);
- if(area.m_curves.empty()) {
- if(from_center)
+ if (count > 1)
+ FC_TIME_LOG(t1, "makeOffset " << i << '/' << count);
+ if (area.m_curves.empty()) {
+ if (from_center)
areas.pop_front();
else
areas.pop_back();
- if(areas.empty())
+ if (areas.empty())
break;
- if(last_stepover && last_stepover>stepover) {
+ if (last_stepover && last_stepover > stepover) {
offset -= stepover;
stepover = last_stepover;
--i;
@@ -2007,48 +2036,48 @@ void Area::makeOffset(list > &areas,
return;
}
}
- FC_TIME_LOG(t,"makeOffset count: " << count);
+ FC_TIME_LOG(t, "makeOffset count: " << count);
}
-TopoDS_Shape Area::makePocket(int index, PARAM_ARGS(PARAM_FARG,AREA_PARAMS_POCKET)) {
- if(tool_radius < Precision::Confusion())
+TopoDS_Shape Area::makePocket(int index, PARAM_ARGS(PARAM_FARG, AREA_PARAMS_POCKET)) {
+ if (tool_radius < Precision::Confusion())
throw Base::ValueError("tool radius too small");
- if(stepover == 0.0)
+ if (stepover == 0.0)
stepover = tool_radius;
- if(stepover < Precision::Confusion())
+ if (stepover < Precision::Confusion())
throw Base::ValueError("stepover too small");
- if(mode == Area::PocketModeNone)
+ if (mode == Area::PocketModeNone)
return TopoDS_Shape();
build();
- AREA_SECTION(makePocket,index,PARAM_FIELDS(PARAM_FARG,AREA_PARAMS_POCKET));
+ AREA_SECTION(makePocket, index, PARAM_FIELDS(PARAM_FARG, AREA_PARAMS_POCKET));
FC_TIME_INIT(t);
bool done = false;
- if(index>=0) {
- if(fabs(angle_shift) >= Precision::Confusion())
- angle += index*angle_shift;
+ if (index >= 0) {
+ if (fabs(angle_shift) >= Precision::Confusion())
+ angle += index * angle_shift;
- if(fabs(shift)>=Precision::Confusion())
+ if (fabs(shift) >= Precision::Confusion())
shift *= index;
}
- if(angle<-360.0)
- angle += ceil(fabs(angle)/360.0)*360.0;
- else if(angle>360.0)
- angle -= floor(angle/360.0)*360.0;
- else if(angle<0.0)
+ if (angle < -360.0)
+ angle += ceil(fabs(angle) / 360.0) * 360.0;
+ else if (angle > 360.0)
+ angle -= floor(angle / 360.0) * 360.0;
+ else if (angle < 0.0)
angle += 360.0;
- if(shift<-stepover)
- shift += ceil(fabs(shift)/stepover)*stepover;
- else if(shift>stepover)
- shift -= floor(shift/stepover)*stepover;
- else if(shift<0.0)
+ if (shift < -stepover)
+ shift += ceil(fabs(shift) / stepover) * stepover;
+ else if (shift > stepover)
+ shift -= floor(shift / stepover) * stepover;
+ else if (shift < 0.0)
shift += stepover;
CAreaConfig conf(myParams);
@@ -2056,7 +2085,7 @@ TopoDS_Shape Area::makePocket(int index, PARAM_ARGS(PARAM_FARG,AREA_PARAMS_POCKE
CArea out;
PocketMode pm;
- switch(mode) {
+ switch (mode) {
case Area::PocketModeZigZag:
pm = ZigZagPocketMode;
break;
@@ -2064,165 +2093,172 @@ TopoDS_Shape Area::makePocket(int index, PARAM_ARGS(PARAM_FARG,AREA_PARAMS_POCKE
pm = SpiralPocketMode;
break;
case Area::PocketModeOffset: {
- PARAM_DECLARE_INIT(PARAM_FNAME,AREA_PARAMS_OFFSET);
- Offset = -tool_radius-extra_offset-shift;
+ PARAM_DECLARE_INIT(PARAM_FNAME, AREA_PARAMS_OFFSET);
+ Offset = -tool_radius - extra_offset - shift;
ExtraPass = -1;
Stepover = -stepover;
LastStepover = -last_stepover;
// make offset and make sure the loop is CW (i.e. inner wires)
- return makeOffset(index,PARAM_FIELDS(PARAM_FNAME,AREA_PARAMS_OFFSET),-1,from_center);
+ return makeOffset(index, PARAM_FIELDS(PARAM_FNAME, AREA_PARAMS_OFFSET), -1, from_center);
}case Area::PocketModeZigZagOffset:
pm = ZigZagThenSingleOffsetPocketMode;
break;
case Area::PocketModeLine:
case Area::PocketModeGrid:
- case Area::PocketModeTriangle:{
+ case Area::PocketModeTriangle: {
CBox2D box;
myArea->GetBox(box);
- if(!box.m_valid)
+ if (!box.m_valid)
throw Base::ValueError("failed to get bound box");
double angles[4];
- int count=1;
+ int count = 1;
angles[0] = 0.0;
- if(mode == Area::PocketModeGrid){
- angles[1]=90.0;
- count=2;
- if(shift 0 )
+ double r = box.Radius() + stepover;
+ if (extra_offset > 0)
r += extra_offset;
- int steps = (int)ceil(r*2.0/stepover);
- for(int i=0;i360.0) a-=360.0;
- double offset = -r+shift;
- for(int j=0;j Precision::Confusion()) {
- double r = a*M_PI/180.0;
+ if (a > 360.0) a -= 360.0;
+ double offset = -r + shift;
+ for (int j = 0; j < steps; ++j, offset += stepover) {
+ Point p1(-r, offset), p2(r, offset);
+ if (a > Precision::Confusion()) {
+ double r = a * M_PI / 180.0;
p1.Rotate(r);
p2.Rotate(r);
}
out.m_curves.emplace_back();
- CCurve &curve = out.m_curves.back();
- curve.m_vertices.emplace_back(p1+center);
- curve.m_vertices.emplace_back(p2+center);
+ CCurve& curve = out.m_curves.back();
+ curve.m_vertices.emplace_back(p1 + center);
+ curve.m_vertices.emplace_back(p2 + center);
}
}
- PARAM_ENUM_CONVERT(AREA_MY,PARAM_FNAME,PARAM_ENUM_EXCEPT,AREA_PARAMS_CLIPPER_FILL);
- PARAM_ENUM_CONVERT(AREA_MY,PARAM_FNAME,PARAM_ENUM_EXCEPT,AREA_PARAMS_OFFSET_CONF);
+ PARAM_ENUM_CONVERT(AREA_MY, PARAM_FNAME, PARAM_ENUM_EXCEPT, AREA_PARAMS_CLIPPER_FILL);
+ PARAM_ENUM_CONVERT(AREA_MY, PARAM_FNAME, PARAM_ENUM_EXCEPT, AREA_PARAMS_OFFSET_CONF);
auto area = *myArea;
- area.OffsetWithClipper(-tool_radius-extra_offset,JoinType,EndType,
- myParams.MiterLimit,myParams.RoundPrecision);
- out.Clip(toClipperOp(OperationIntersection),&area,SubjectFill,ClipFill);
+ area.OffsetWithClipper(-tool_radius - extra_offset, JoinType, EndType,
+ myParams.MiterLimit, myParams.RoundPrecision);
+ out.Clip(toClipperOp(OperationIntersection), &area, SubjectFill, ClipFill);
done = true;
break;
}default:
throw Base::ValueError("unknown pocket mode");
}
- if(!done) {
+ if (!done) {
CAreaPocketParams params(
- tool_radius,extra_offset,stepover,from_center,pm,angle);
+ tool_radius, extra_offset, stepover, from_center, pm, angle);
CArea in(*myArea);
// MakePocketToolPath internally uses libarea Offset which somehow demands
// reorder before input, otherwise nothing is shown.
in.Reorder();
- in.MakePocketToolpath(out.m_curves,params);
+ in.MakePocketToolpath(out.m_curves, params);
}
- FC_TIME_LOG(t,"makePocket");
+ FC_TIME_LOG(t, "makePocket");
- if(myParams.Thicken){
+ if (myParams.Thicken) {
FC_TIME_INIT(t);
out.Thicken(tool_radius);
- FC_TIME_LOG(t,"thicken");
- return toShape(out,FillFace);
- }else
- return toShape(out,FillNone);
+ FC_TIME_LOG(t, "thicken");
+ return toShape(out, FillFace);
+ }
+ else
+ return toShape(out, FillNone);
}
-static inline bool IsLeft(const gp_Pnt &a, const gp_Pnt &b, const gp_Pnt &c) {
- return ((b.X() - a.X())*(c.Y() - a.Y()) - (b.Y() - a.Y())*(c.X() - a.X())) > 0;
+static inline bool IsLeft(const gp_Pnt& a, const gp_Pnt& b, const gp_Pnt& c) {
+ return ((b.X() - a.X()) * (c.Y() - a.Y()) - (b.Y() - a.Y()) * (c.X() - a.X())) > 0;
}
-TopoDS_Shape Area::toShape(const CCurve &_c, const gp_Trsf *trsf, int reorient) {
+TopoDS_Shape Area::toShape(const CCurve& _c, const gp_Trsf* trsf, int reorient) {
Handle(TopTools_HSequenceOfShape) hEdges = new TopTools_HSequenceOfShape();
Handle(TopTools_HSequenceOfShape) hWires = new TopTools_HSequenceOfShape();
CCurve cReversed;
- if(reorient) {
- if(_c.IsClosed() &&
- ((reorient>0 && _c.IsClockwise()) ||
- (reorient<0 && !_c.IsClockwise())))
+ if (reorient) {
+ if (_c.IsClosed() &&
+ ((reorient > 0 && _c.IsClockwise()) ||
+ (reorient < 0 && !_c.IsClockwise())))
{
cReversed = _c;
cReversed.Reverse();
- }else
+ }
+ else
reorient = 0;
}
- const CCurve &c = reorient?cReversed:_c;
+ const CCurve& c = reorient ? cReversed : _c;
TopoDS_Shape shape;
- gp_Pnt pstart,pt;
+ gp_Pnt pstart, pt;
bool first = true;
- for(const CVertex &v : c.m_vertices){
- if(first){
+ for (const CVertex& v : c.m_vertices) {
+ if (first) {
first = false;
- pstart = pt = gp_Pnt(v.m_p.x,v.m_p.y,0);
+ pstart = pt = gp_Pnt(v.m_p.x, v.m_p.y, 0);
continue;
}
- gp_Pnt pnext(v.m_p.x,v.m_p.y,0);
- if(pnext.SquareDistance(pt)<=Precision::SquareConfusion())
+ gp_Pnt pnext(v.m_p.x, v.m_p.y, 0);
+ if (pnext.SquareDistance(pt) <= Precision::SquareConfusion())
continue;
- if(v.m_type == 0) {
- auto edge = BRepBuilderAPI_MakeEdge(pt,pnext).Edge();
+ if (v.m_type == 0) {
+ auto edge = BRepBuilderAPI_MakeEdge(pt, pnext).Edge();
hEdges->Append(edge);
- } else {
- gp_Pnt center(v.m_c.x,v.m_c.y,0);
+ }
+ else {
+ gp_Pnt center(v.m_c.x, v.m_c.y, 0);
double r = center.Distance(pt);
double r2 = center.Distance(pnext);
- bool fix_arc = fabs(r-r2) > Precision::Confusion();
- while(1) {
- if(fix_arc) {
+ bool fix_arc = fabs(r - r2) > Precision::Confusion();
+ while (1) {
+ if (fix_arc) {
double d = pt.Distance(pnext);
- double rr = r*r;
- double dd = d*d*0.25;
- double q = rr<=dd?0:sqrt(rr-dd);
- double x = (pt.X()+pnext.X())*0.5;
- double y = (pt.Y()+pnext.Y())*0.5;
- double dx = q*(pt.Y()-pnext.Y())/d;
- double dy = q*(pnext.X()-pt.X())/d;
- gp_Pnt newCenter(x + dx, y + dy,0);
- if(IsLeft(pt,pnext,center) != IsLeft(pt,pnext,newCenter)) {
+ double rr = r * r;
+ double dd = d * d * 0.25;
+ double q = rr <= dd ? 0 : sqrt(rr - dd);
+ double x = (pt.X() + pnext.X()) * 0.5;
+ double y = (pt.Y() + pnext.Y()) * 0.5;
+ double dx = q * (pt.Y() - pnext.Y()) / d;
+ double dy = q * (pnext.X() - pt.X()) / d;
+ gp_Pnt newCenter(x + dx, y + dy, 0);
+ if (IsLeft(pt, pnext, center) != IsLeft(pt, pnext, newCenter)) {
newCenter.SetX(x - dx);
newCenter.SetY(y - dy);
}
- AREA_WARN("Arc correction: "<"<" << AREA_XYZ(newCenter));
center = newCenter;
}
- gp_Ax2 axis(center, gp_Dir(0,0,v.m_type));
+ gp_Ax2 axis(center, gp_Dir(0, 0, v.m_type));
try {
- auto edge = BRepBuilderAPI_MakeEdge(gp_Circ(axis,r),pt,pnext).Edge();
+ auto edge = BRepBuilderAPI_MakeEdge(gp_Circ(axis, r), pt, pnext).Edge();
hEdges->Append(edge);
break;
- } catch(Standard_Failure &e) {
- if(!fix_arc) {
+ }
+ catch (Standard_Failure& e) {
+ if (!fix_arc) {
fix_arc = true;
AREA_WARN("OCC exception on making arc: " << e.GetMessageString());
- }else {
+ }
+ else {
AREA_ERR("OCC exception on making arc: " << e.GetMessageString());
throw;
}
@@ -2233,7 +2269,7 @@ TopoDS_Shape Area::toShape(const CCurve &_c, const gp_Trsf *trsf, int reorient)
}
#if 0
- if(c.IsClosed() && !BRep_Tool::IsClosed(mkWire.Wire())){
+ if (c.IsClosed() && !BRep_Tool::IsClosed(mkWire.Wire())) {
// This should never happen after changing libarea's
// Point::tolerance to be the same as Precision::Confusion().
// Just leave it here in case.
@@ -2241,60 +2277,61 @@ TopoDS_Shape Area::toShape(const CCurve &_c, const gp_Trsf *trsf, int reorient)
gp_Pnt p1(curve.Value(curve.FirstParameter()));
gp_Pnt p2(curve.Value(curve.LastParameter()));
AREA_WARN("warning: patch open wire type " <<
- c.m_vertices.back().m_type<Length())
+ hEdges, Precision::Confusion(), Standard_False, hWires);
+ if (!hWires->Length())
return shape;
- if(hWires->Length()==1)
+ if (hWires->Length() == 1)
shape = hWires->Value(1);
else {
BRep_Builder builder;
TopoDS_Compound compound;
builder.MakeCompound(compound);
- for(int i=1;i<=hWires->Length();++i)
- builder.Add(compound,hWires->Value(i));
+ for (int i = 1; i <= hWires->Length(); ++i)
+ builder.Add(compound, hWires->Value(i));
shape = compound;
}
- if(trsf)
+ if (trsf)
shape.Move(TopLoc_Location(*trsf));
return shape;
}
-TopoDS_Shape Area::toShape(const CArea &area, bool fill, const gp_Trsf *trsf, int reorient) {
+TopoDS_Shape Area::toShape(const CArea& area, bool fill, const gp_Trsf* trsf, int reorient) {
BRep_Builder builder;
TopoDS_Compound compound;
builder.MakeCompound(compound);
- for(const CCurve &c : area.m_curves) {
- const auto &wire = toShape(c,trsf,reorient);
- if(!wire.IsNull())
- builder.Add(compound,wire);
+ for (const CCurve& c : area.m_curves) {
+ const auto& wire = toShape(c, trsf, reorient);
+ if (!wire.IsNull())
+ builder.Add(compound, wire);
}
- TopExp_Explorer xp(compound,TopAbs_EDGE);
- if(!xp.More())
+ TopExp_Explorer xp(compound, TopAbs_EDGE);
+ if (!xp.More())
return TopoDS_Shape();
- if(fill) {
- try{
+ if (fill) {
+ try {
FC_TIME_INIT(t);
Part::FaceMakerBullseye mkFace;
- if(trsf)
+ if (trsf)
mkFace.setPlane(gp_Pln().Transformed(*trsf));
- for(TopExp_Explorer it(compound, TopAbs_WIRE); it.More(); it.Next())
+ for (TopExp_Explorer it(compound, TopAbs_WIRE); it.More(); it.Next())
mkFace.addWire(TopoDS::Wire(it.Current()));
mkFace.Build();
if (mkFace.Shape().IsNull())
AREA_WARN("FaceMakerBullseye returns null shape");
- FC_TIME_LOG(t,"makeFace");
+ FC_TIME_LOG(t, "makeFace");
return mkFace.Shape();
- }catch (Base::Exception &e){
- AREA_WARN("FaceMakerBullseye failed: "< Wires;
-typedef std::pair RValue;
+typedef std::pair RValue;
struct RGetter
{
typedef const gp_Pnt& result_type;
- result_type operator()(const RValue &v) const { return v.first->points[v.second]; }
+ result_type operator()(const RValue& v) const { return v.first->points[v.second]; }
};
-typedef bgi::rtree RTree;
+typedef bgi::rtree RTree;
struct ShapeParams {
double abscissa;
@@ -2335,86 +2372,87 @@ struct ShapeParams {
FC_DURATION_DECLARE(xd); //BRepExtrema_DistShapeShape duration
ShapeParams(double _a, int _k, short o, short d)
- :abscissa(_a),k(_k),orientation(o),direction(d)
+ :abscissa(_a), k(_k), orientation(o), direction(d)
{
- FC_DURATION_INIT3(qd,bd,rd);
+ FC_DURATION_INIT3(qd, bd, rd);
FC_DURATION_INIT(xd);
}
};
-bool operator<(const Wires::iterator &a, const Wires::iterator &b) {
+bool operator<(const Wires::iterator& a, const Wires::iterator& b) {
return &(*a) < &(*b);
}
-typedef std::map RResults;
+typedef std::map RResults;
struct GetWires {
- Wires &wires;
- RTree &rtree;
- ShapeParams ¶ms;
- GetWires(std::list &ws, RTree &rt, ShapeParams &rp)
- :wires(ws),rtree(rt),params(rp)
+ Wires& wires;
+ RTree& rtree;
+ ShapeParams& params;
+ GetWires(std::list& ws, RTree& rt, ShapeParams& rp)
+ :wires(ws), rtree(rt), params(rp)
{}
- void operator()(const TopoDS_Shape &shape, int type) {
+ void operator()(const TopoDS_Shape& shape, int type) {
wires.emplace_back();
- WireInfo &info = wires.back();
- if(type == TopAbs_WIRE)
+ WireInfo& info = wires.back();
+ if (type == TopAbs_WIRE)
info.wire = TopoDS::Wire(shape);
else
info.wire = BRepBuilderAPI_MakeWire(TopoDS::Edge(shape)).Wire();
info.isClosed = BRep_Tool::IsClosed(info.wire);
- if(info.isClosed && params.orientation == Area::OrientationReversed)
+ if (info.isClosed && params.orientation == Area::OrientationReversed)
info.wire.Reverse();
FC_TIME_INIT(t);
- if(params.abscissap2.X();
+ reverse = p1.X() > p2.X();
break;
case Area::DirectionXNegative:
- reverse = p1.X()p2.Y();
+ reverse = p1.Y() > p2.Y();
break;
case Area::DirectionYNegative:
- reverse = p1.Y()p2.Z();
+ reverse = p1.Z() > p2.Z();
break;
case Area::DirectionZNegative:
- reverse = p1.Z()points.size();ipoints.size(); i < count; ++i)
+ rtree.insert(RValue(it, i));
+ FC_DURATION_PLUS(params.bd, t);
}
};
-struct ShapeInfo{
+struct ShapeInfo {
gp_Pln myPln;
Wires myWires;
RTree myRTree;
@@ -2448,17 +2487,17 @@ struct ShapeInfo{
gp_Pnt myStartPt;
Wires::iterator myBestWire;
TopoDS_Shape mySupport;
- ShapeParams &myParams;
+ ShapeParams& myParams;
Standard_Real myBestParameter;
bool mySupportEdge;
bool myPlanar;
bool myRebase;
bool myStart;
- ShapeInfo(const gp_Pln &pln, const TopoDS_Shape &shape, ShapeParams ¶ms)
+ ShapeInfo(const gp_Pln& pln, const TopoDS_Shape& shape, ShapeParams& params)
: myPln(pln)
, myShape(shape)
- , myStartPt(1e20,1e20,1e20)
+ , myStartPt(1e20, 1e20, 1e20)
, myParams(params)
, myBestParameter(0)
, mySupportEdge(false)
@@ -2467,9 +2506,9 @@ struct ShapeInfo{
, myStart(false)
{}
- ShapeInfo(const TopoDS_Shape &shape, ShapeParams ¶ms)
+ ShapeInfo(const TopoDS_Shape& shape, ShapeParams& params)
: myShape(shape)
- , myStartPt(1e20,1e20,1e20)
+ , myStartPt(1e20, 1e20, 1e20)
, myParams(params)
, myBestParameter(0)
, mySupportEdge(false)
@@ -2477,11 +2516,11 @@ struct ShapeInfo{
, myRebase(false)
, myStart(false)
{}
- double nearest(const gp_Pnt &pt) {
+ double nearest(const gp_Pnt& pt) {
myStartPt = pt;
- if(myWires.empty())
- foreachSubshape(myShape,GetWires(myWires,myRTree,myParams),TopAbs_WIRE);
+ if (myWires.empty())
+ foreachSubshape(myShape, GetWires(myWires, myRTree, myParams), TopAbs_WIRE);
// Now find the true nearest point among the wires returned. Currently
// only closed wire has a true nearest point, using OCC's
@@ -2492,66 +2531,69 @@ struct ShapeInfo{
RResults ret;
{
FC_TIME_INIT(t);
- myRTree.query(bgi::nearest(pt,myParams.k),bgi::inserter(ret));
- FC_DURATION_PLUS(myParams.qd,t);
+ myRTree.query(bgi::nearest(pt, myParams.k), bgi::inserter(ret));
+ FC_DURATION_PLUS(myParams.qd, t);
}
TopoDS_Shape v = BRepBuilderAPI_MakeVertex(pt);
bool first = true;
- double best_d=1e20;
+ double best_d = 1e20;
myBestWire = myWires.begin();
- for(auto r : ret) {
+ for (auto r : ret) {
Wires::iterator it = r.first;
- const TopoDS_Shape &wire = it->wire;
+ const TopoDS_Shape& wire = it->wire;
TopoDS_Shape support;
bool support_edge;
double d = 0;
gp_Pnt p;
bool done = false;
bool is_start = false;
- if(BRep_Tool::IsClosed(wire)) {
+ if (BRep_Tool::IsClosed(wire)) {
FC_TIME_INIT(t);
- BRepExtrema_DistShapeShape extss(v,wire);
- if(extss.IsDone() && extss.NbSolution()) {
+ BRepExtrema_DistShapeShape extss(v, wire);
+ if (extss.IsDone() && extss.NbSolution()) {
d = extss.Value();
d *= d;
p = extss.PointOnShape2(1);
support = extss.SupportOnShape2(1);
- support_edge = extss.SupportTypeShape2(1)==BRepExtrema_IsOnEdge;
- if(support_edge)
- extss.ParOnEdgeS2(1,myBestParameter);
+ support_edge = extss.SupportTypeShape2(1) == BRepExtrema_IsOnEdge;
+ if (support_edge)
+ extss.ParOnEdgeS2(1, myBestParameter);
done = true;
- }else
+ }
+ else
AREA_WARN("BRepExtrema_DistShapeShape failed");
- FC_DURATION_PLUS(myParams.xd,t);
+ FC_DURATION_PLUS(myParams.xd, t);
}
- if(!done){
+ if (!done) {
double d1 = pt.SquareDistance(it->pstart());
- if(myParams.direction!=Area::DirectionNone) {
+ if (myParams.direction != Area::DirectionNone) {
d = d1;
p = it->pstart();
is_start = true;
- }else{
+ }
+ else {
double d2 = pt.SquareDistance(it->pend());
- if(d1pstart();
is_start = true;
- }else{
+ }
+ else {
d = d2;
p = it->pend();
is_start = false;
}
}
}
- if(!first && d>=best_d) continue;
+ if (!first && d >= best_d) continue;
first = false;
myBestPt = p;
myBestWire = it;
best_d = d;
myRebase = done;
myStart = is_start;
- if(done) {
+ if (done) {
mySupport = support;
mySupportEdge = support_edge;
}
@@ -2561,77 +2603,79 @@ struct ShapeInfo{
//Assumes nearest() has been called. Rebased the best wire
//to begin with the best point. Currently only works with closed wire
- TopoDS_Shape rebaseWire(gp_Pnt &pend, double min_dist) {
+ TopoDS_Shape rebaseWire(gp_Pnt& pend, double min_dist) {
min_dist *= min_dist;
BRepBuilderAPI_MakeWire mkWire;
TopoDS_Shape estart;
TopoDS_Edge eend;
- for(int state=0;state<3;++state) {
+ for (int state = 0; state < 3; ++state) {
BRepTools_WireExplorer xp(TopoDS::Wire(myBestWire->wire));
gp_Pnt pprev(BRep_Tool::Pnt(xp.CurrentVertex()));
//checking the case of bestpoint == wire start
- if(state==0 && !mySupportEdge &&
- pprev.SquareDistance(myBestPt)<=Precision::SquareConfusion()) {
+ if (state == 0 && !mySupportEdge &&
+ pprev.SquareDistance(myBestPt) <= Precision::SquareConfusion()) {
pend = myBestWire->pend();
return myBestWire->wire;
}
gp_Pnt pt;
- for(;xp.More();xp.Next(),pprev=pt) {
- const auto &edge = xp.Current();
+ for (; xp.More(); xp.Next(), pprev = pt) {
+ const auto& edge = xp.Current();
//state==2 means we are in second pass. estart marks the new
//start of the wire. so seeing estart means we're done
- if(state==2 && estart.IsEqual(edge))
+ if (state == 2 && estart.IsEqual(edge))
break;
// Edge split not working if using BRepAdaptor_Curve.
// BRepBuilderAPI_MakeEdge always fails with
// PointProjectionFailed. Why??
- Standard_Real first,last;
+ Standard_Real first, last;
Handle_Geom_Curve curve = BRep_Tool::Curve(edge, first, last);
pt = curve->Value(last);
bool reversed;
- if(pprev.SquareDistance(pt)<=Precision::SquareConfusion()) {
+ if (pprev.SquareDistance(pt) <= Precision::SquareConfusion()) {
reversed = true;
pt = curve->Value(first);
- }else
+ }
+ else
reversed = false;
//state!=0 means we've found the new start of wire, now just
//keep adding new edges
- if(state) {
+ if (state) {
mkWire.Add(edge);
continue;
}
//state==0 means we are looking for the new start
- if(mySupportEdge) {
+ if (mySupportEdge) {
//if best point is on some edge, split the edge in half
- if(edge.IsEqual(mySupport)) {
+ if (edge.IsEqual(mySupport)) {
//to fix PointProjectionFailed.
GeomAPI_ProjectPointOnCurve gpp;
gpp.Init(myBestPt, curve);
gpp.Perform(myBestPt);
myBestPt = gpp.NearestPoint();
-
+
gpp.Perform(pprev);
pprev = gpp.NearestPoint();
-
+
gpp.Perform(pt);
pt = gpp.NearestPoint();
-
+
double d1 = pprev.SquareDistance(myBestPt);
double d2 = pt.SquareDistance(myBestPt);
- if(d1>min_dist && d2>min_dist) {
- BRepBuilderAPI_MakeEdge mkEdge1,mkEdge2;
- if(reversed) {
+ if (d1 > min_dist && d2 > min_dist) {
+ BRepBuilderAPI_MakeEdge mkEdge1, mkEdge2;
+ if (reversed) {
mkEdge1.Init(curve, myBestPt, pprev);
mkEdge2.Init(curve, pt, myBestPt);
- }else{
+ }
+ else {
mkEdge1.Init(curve, pprev, myBestPt);
mkEdge2.Init(curve, myBestPt, pt);
}
@@ -2643,11 +2687,12 @@ struct ShapeInfo{
// mkEdge1.Init(curve, first, myBestParameter);
// mkEdge2.Init(curve, myBestParameter, last);
// }
- if(mkEdge1.IsDone() && mkEdge2.IsDone()) {
- if(reversed) {
+ if (mkEdge1.IsDone() && mkEdge2.IsDone()) {
+ if (reversed) {
eend = TopoDS::Edge(mkEdge1.Edge().Reversed());
mkWire.Add(TopoDS::Edge(mkEdge2.Edge().Reversed()));
- }else{
+ }
+ else {
eend = mkEdge1.Edge();
mkWire.Add(mkEdge2.Edge());
}
@@ -2659,25 +2704,27 @@ struct ShapeInfo{
// first<<", " << myBestParameter << ", " << last<<')');
continue;
}
- AREA_WARN((reversed?"reversed ":"")<<"edge split failed "<start");
estart = edge;
state = 1;
mkWire.Add(edge);
- }else{
+ }
+ else {
// AREA_TRACE("split edge->end");
mySupportEdge = false;
myBestPt = pt;
continue;
}
}
- }else if(myBestPt.SquareDistance(pprev)<=Precision::SquareConfusion()){
+ }
+ else if (myBestPt.SquareDistance(pprev) <= Precision::SquareConfusion()) {
pend = pprev;
// AREA_TRACE("break vertex");
//if best point is on some vertex
@@ -2687,57 +2734,59 @@ struct ShapeInfo{
}
}
- if(state==0) {
+ if (state == 0) {
AREA_WARN("edge break point not found");
pend = myBestWire->pend();
return myBestWire->wire;
}
}
- if(!eend.IsNull())
+ if (!eend.IsNull())
mkWire.Add(eend);
- if(mkWire.IsDone())
+ if (mkWire.IsDone())
return mkWire.Wire();
AREA_WARN("wire rebase failed");
pend = myBestWire->pend();
return myBestWire->wire;
}
- std::list sortWires(const gp_Pnt &pstart, gp_Pnt &pend,
- double min_dist, double max_dist, gp_Pnt *pentry) {
+ std::list sortWires(const gp_Pnt& pstart, gp_Pnt& pend,
+ double min_dist, double max_dist, gp_Pnt* pentry) {
std::list wires;
- if(myWires.empty() ||
- pstart.SquareDistance(myStartPt)>Precision::SquareConfusion())
+ if (myWires.empty() ||
+ pstart.SquareDistance(myStartPt) > Precision::SquareConfusion())
{
nearest(pstart);
- if(myWires.empty())
+ if (myWires.empty())
return wires;
}
- if(pentry) *pentry = myBestPt;
+ if (pentry) *pentry = myBestPt;
- if(min_dist < 0.01)
+ if (min_dist < 0.01)
min_dist = 0.01;
- while(true) {
- if(myRebase) {
+ while (true) {
+ if (myRebase) {
pend = myBestPt;
- wires.push_back(rebaseWire(pend,min_dist));
- }else if(!myStart){
+ wires.push_back(rebaseWire(pend, min_dist));
+ }
+ else if (!myStart) {
wires.push_back(myBestWire->wire.Reversed());
pend = myBestWire->pstart();
- }else{
+ }
+ else {
wires.push_back(myBestWire->wire);
pend = myBestWire->pend();
}
FC_TIME_INIT(t);
- for(size_t i=0,count=myBestWire->points.size();ipoints.size(); i < count; ++i)
+ myRTree.remove(RValue(myBestWire, i));
+ FC_DURATION_PLUS(myParams.rd, t);
myWires.erase(myBestWire);
- if(myWires.empty()) break;
+ if (myWires.empty()) break;
double d = nearest(pend);
- if(max_dist>0 && d>max_dist)
+ if (max_dist > 0 && d > max_dist)
break;
}
return wires;
@@ -2745,94 +2794,101 @@ struct ShapeInfo{
};
struct ShapeInfoBuilder {
- std::list &myList;
- gp_Trsf &myTrsf;
- short &myArcPlane;
- bool &myArcPlaneFound;
- ShapeParams &myParams;
+ std::list& myList;
+ gp_Trsf& myTrsf;
+ short& myArcPlane;
+ bool& myArcPlaneFound;
+ ShapeParams& myParams;
- ShapeInfoBuilder(bool &plane_found, short &arc_plane, gp_Trsf &trsf,
- std::list &list, ShapeParams ¶ms)
- :myList(list) ,myTrsf(trsf) ,myArcPlane(arc_plane)
- ,myArcPlaneFound(plane_found), myParams(params)
+ ShapeInfoBuilder(bool& plane_found, short& arc_plane, gp_Trsf& trsf,
+ std::list& list, ShapeParams& params)
+ :myList(list), myTrsf(trsf), myArcPlane(arc_plane)
+ , myArcPlaneFound(plane_found), myParams(params)
{}
- void operator()(const TopoDS_Shape &shape, int type) {
+ void operator()(const TopoDS_Shape& shape, int type) {
gp_Pln pln;
- if(!getShapePlane(shape,pln)){
- myList.emplace_back(shape,myParams);
+ if (!getShapePlane(shape, pln)) {
+ myList.emplace_back(shape, myParams);
return;
}
- myList.emplace_back(pln,shape,myParams);
- if(myArcPlaneFound ||
- myArcPlane==Area::ArcPlaneNone ||
- myArcPlane==Area::ArcPlaneVariable)
+ myList.emplace_back(pln, shape, myParams);
+ if (myArcPlaneFound ||
+ myArcPlane == Area::ArcPlaneNone ||
+ myArcPlane == Area::ArcPlaneVariable)
return;
- if(type == TopAbs_EDGE) {
+ if (type == TopAbs_EDGE) {
BRepAdaptor_Curve curve(TopoDS::Edge(shape));
- if(curve.GetType()!=GeomAbs_Circle)
+ if (curve.GetType() != GeomAbs_Circle)
return;
- }else{
+ }
+ else {
bool found = false;
- for(TopExp_Explorer it(shape,TopAbs_EDGE);it.More();it.Next()) {
+ for (TopExp_Explorer it(shape, TopAbs_EDGE); it.More(); it.Next()) {
BRepAdaptor_Curve curve(TopoDS::Edge(it.Current()));
- if(curve.GetType()==GeomAbs_Circle) {
+ if (curve.GetType() == GeomAbs_Circle) {
found = true;
break;
}
}
- if(!found)
+ if (!found)
return;
}
gp_Ax3 pos = myList.back().myPln.Position();
- if(!pos.Direct()) pos = gp_Ax3(pos.Ax2());
- const gp_Dir &dir = pos.Direction();
+ if (!pos.Direct()) pos = gp_Ax3(pos.Ax2());
+ const gp_Dir& dir = pos.Direction();
gp_Ax3 dstPos;
- bool x0 = fabs(dir.X())<=Precision::Confusion();
- bool y0 = fabs(dir.Y())<=Precision::Confusion();
- bool z0 = fabs(dir.Z())<=Precision::Confusion();
- switch(myArcPlane) {
+ bool x0 = fabs(dir.X()) <= Precision::Confusion();
+ bool y0 = fabs(dir.Y()) <= Precision::Confusion();
+ bool z0 = fabs(dir.Z()) <= Precision::Confusion();
+ switch (myArcPlane) {
case Area::ArcPlaneAuto: {
- if(x0&&y0){
+ if (x0 && y0) {
AREA_TRACE("found arc plane XY");
myArcPlane = Area::ArcPlaneXY;
- } else if(x0&&z0) {
+ }
+ else if (x0 && z0) {
AREA_TRACE("found arc plane ZX");
myArcPlane = Area::ArcPlaneZX;
- } else if(z0&&y0) {
+ }
+ else if (z0 && y0) {
AREA_TRACE("found arc plane YZ");
myArcPlane = Area::ArcPlaneYZ;
- } else {
+ }
+ else {
myArcPlane = Area::ArcPlaneXY;
- dstPos = gp_Ax3(pos.Location(),gp_Dir(0,0,1));
+ dstPos = gp_Ax3(pos.Location(), gp_Dir(0, 0, 1));
break;
}
myArcPlaneFound = true;
return;
}case Area::ArcPlaneXY:
- if(x0&&y0) {myArcPlaneFound=true;
+ if (x0 && y0) {
+ myArcPlaneFound = true;
return;
}
- dstPos = gp_Ax3(pos.Location(),gp_Dir(0,0,1));
+ dstPos = gp_Ax3(pos.Location(), gp_Dir(0, 0, 1));
break;
case Area::ArcPlaneZX:
- if(x0&&z0) {myArcPlaneFound=true;
+ if (x0 && z0) {
+ myArcPlaneFound = true;
return;
}
- dstPos = gp_Ax3(pos.Location(),gp_Dir(0,1,0));
+ dstPos = gp_Ax3(pos.Location(), gp_Dir(0, 1, 0));
break;
case Area::ArcPlaneYZ:
- if(z0&&y0) {myArcPlaneFound=true;
+ if (z0 && y0) {
+ myArcPlaneFound = true;
return;
}
- dstPos = gp_Ax3(pos.Location(),gp_Dir(1,0,0));
+ dstPos = gp_Ax3(pos.Location(), gp_Dir(1, 0, 0));
break;
default:
return;
}
AREA_WARN("force arc plane " << AREA_XYZ(dir) <<
- " to " << AREA_XYZ(dstPos.Direction()));
+ " to " << AREA_XYZ(dstPos.Direction()));
myTrsf.SetTransformation(pos);
gp_Trsf trsf;
trsf.SetTransformation(dstPos);
@@ -2842,72 +2898,73 @@ struct ShapeInfoBuilder {
};
struct WireOrienter {
- std::list &wires;
- const gp_Dir &dir;
+ std::list& wires;
+ const gp_Dir& dir;
short orientation;
short direction;
- WireOrienter(std::list &ws, const gp_Dir &dir, short o, short d)
- :wires(ws),dir(dir),orientation(o),direction(d)
+ WireOrienter(std::list& ws, const gp_Dir& dir, short o, short d)
+ :wires(ws), dir(dir), orientation(o), direction(d)
{}
- void operator()(const TopoDS_Shape &shape, int type) {
- if(type == TopAbs_WIRE)
+ void operator()(const TopoDS_Shape& shape, int type) {
+ if (type == TopAbs_WIRE)
wires.push_back(shape);
else
wires.push_back(BRepBuilderAPI_MakeWire(TopoDS::Edge(shape)).Wire());
- TopoDS_Shape &wire = wires.back();
+ TopoDS_Shape& wire = wires.back();
- if(BRep_Tool::IsClosed(wire)) {
- if(orientation==Area::OrientationReversed)
+ if (BRep_Tool::IsClosed(wire)) {
+ if (orientation == Area::OrientationReversed)
wire.Reverse();
- }else if(direction!=Area::DirectionNone) {
- gp_Pnt p1,p2;
- getEndPoints(TopoDS::Wire(wire),p1,p2);
+ }
+ else if (direction != Area::DirectionNone) {
+ gp_Pnt p1, p2;
+ getEndPoints(TopoDS::Wire(wire), p1, p2);
bool reverse = false;
- switch(direction) {
+ switch (direction) {
case Area::DirectionXPositive:
- reverse = p1.X()>p2.X();
+ reverse = p1.X() > p2.X();
break;
case Area::DirectionXNegative:
- reverse = p1.X()p2.Y();
+ reverse = p1.Y() > p2.Y();
break;
case Area::DirectionYNegative:
- reverse = p1.Y()p2.Z();
+ reverse = p1.Z() > p2.Z();
break;
case Area::DirectionZNegative:
- reverse = p1.Z() Area::sortWires(const std::list &shapes,
- bool has_start, gp_Pnt *_pstart, gp_Pnt *_pend,
- double *stepdown_hint, short *_parc_plane,
- PARAM_ARGS(PARAM_FARG,AREA_PARAMS_SORT))
+std::list Area::sortWires(const std::list& shapes,
+ bool has_start, gp_Pnt* _pstart, gp_Pnt* _pend,
+ double* stepdown_hint, short* _parc_plane,
+ PARAM_ARGS(PARAM_FARG, AREA_PARAMS_SORT))
{
std::list wires;
- if(shapes.empty())
+ if (shapes.empty())
return wires;
AxisGetter getter;
AxisSetter setter;
- switch(retract_axis) {
+ switch (retract_axis) {
case RetractAxisX:
getter = &gp_Pnt::X;
setter = &gp_Pnt::SetX;
@@ -2921,115 +2978,116 @@ std::list Area::sortWires(const std::list &shapes,
setter = &gp_Pnt::SetZ;
}
- if(sort_mode==SortModeGreedy && threshold0?nearest_k:1,orientation,direction);
+ ShapeParams rparams(abscissa, nearest_k > 0 ? nearest_k : 1, orientation, direction);
std::list shape_list;
- FC_TIME_INIT2(t,t1);
+ FC_TIME_INIT2(t, t1);
gp_Trsf trsf;
bool arcPlaneFound = false;
- if(sort_mode == SortMode3D) {
+ if (sort_mode == SortMode3D) {
TopoDS_Builder builder;
TopoDS_Compound comp;
builder.MakeCompound(comp);
- for(auto &shape : shapes) {
- if(!shape.IsNull())
- builder.Add(comp,shape);
+ for (auto& shape : shapes) {
+ if (!shape.IsNull())
+ builder.Add(comp, shape);
}
- TopExp_Explorer xp(comp,TopAbs_EDGE);
- if(xp.More())
- shape_list.emplace_back(comp,rparams);
- }else{
+ TopExp_Explorer xp(comp, TopAbs_EDGE);
+ if (xp.More())
+ shape_list.emplace_back(comp, rparams);
+ }
+ else {
//first pass, find plane of each shape
- for(auto &shape : shapes) {
+ for (auto& shape : shapes) {
//explode the shape
- if(!shape.IsNull()){
- foreachSubshape(shape,ShapeInfoBuilder(
- arcPlaneFound,arc_plane,trsf,shape_list,rparams),TopAbs_FACE,true);
+ if (!shape.IsNull()) {
+ foreachSubshape(shape, ShapeInfoBuilder(
+ arcPlaneFound, arc_plane, trsf, shape_list, rparams), TopAbs_FACE, true);
}
}
- FC_TIME_LOG(t1,"plane finding");
+ FC_TIME_LOG(t1, "plane finding");
}
- if(shape_list.empty())
+ if (shape_list.empty())
return wires;
Bnd_Box bounds;
- gp_Pnt pstart,pend;
- if(_pstart)
+ gp_Pnt pstart, pend;
+ if (_pstart)
pstart = *_pstart;
- bool use_bound = !has_start || _pstart==nullptr;
+ bool use_bound = !has_start || _pstart == nullptr;
//Second stage, group shape by its plane, and find overall boundary
- for(auto &info : shape_list) {
- if(arcPlaneFound) {
+ for (auto& info : shape_list) {
+ if (arcPlaneFound) {
info.myShape.Move(trsf);
- if(info.myPlanar) info.myPln.Transform(trsf);
+ if (info.myPlanar) info.myPln.Transform(trsf);
}
BRepBndLib::Add(info.myShape, bounds, Standard_False);
}
- if(use_bound || sort_mode == SortMode2D5 || sort_mode == SortModeGreedy) {
+ if (use_bound || sort_mode == SortMode2D5 || sort_mode == SortModeGreedy) {
- for(auto itNext=shape_list.begin(),it=itNext;it!=shape_list.end();it=itNext) {
+ for (auto itNext = shape_list.begin(), it = itNext; it != shape_list.end(); it = itNext) {
++itNext;
- if(!it->myPlanar) continue;
+ if (!it->myPlanar) continue;
TopoDS_Builder builder;
TopoDS_Compound comp;
builder.MakeCompound(comp);
bool empty = true;
- for(auto itNext3=itNext,itNext2=itNext;itNext2!=shape_list.end();itNext2=itNext3) {
+ for (auto itNext3 = itNext, itNext2 = itNext; itNext2 != shape_list.end(); itNext2 = itNext3) {
++itNext3;
- if(!itNext2->myPlanar ||
- !it->myPln.Position().IsCoplanar(itNext2->myPln.Position(),
- Precision::Confusion(),Precision::Confusion()))
+ if (!itNext2->myPlanar ||
+ !it->myPln.Position().IsCoplanar(itNext2->myPln.Position(),
+ Precision::Confusion(), Precision::Confusion()))
continue;
- if(itNext == itNext2) ++itNext;
- builder.Add(comp,itNext2->myShape);
+ if (itNext == itNext2) ++itNext;
+ builder.Add(comp, itNext2->myShape);
shape_list.erase(itNext2);
empty = false;
}
- if(!empty) {
- builder.Add(comp,it->myShape);
+ if (!empty) {
+ builder.Add(comp, it->myShape);
it->myShape = comp;
}
}
- FC_TIME_LOG(t,"plane merging");
+ FC_TIME_LOG(t, "plane merging");
}
//FC_DURATION_DECL_INIT(td);
@@ -3037,30 +3095,31 @@ std::list Area::sortWires(const std::list &shapes,
bounds.SetGap(0.0);
Standard_Real xMin, yMin, zMin, xMax, yMax, zMax;
bounds.Get(xMin, yMin, zMin, xMax, yMax, zMax);
- AREA_TRACE("bound (" << xMin<<", "< Area::sortWires(const std::list &shapes,
bool hint_first = true;
auto current_it = shape_list.end();
double current_height = (pstart.*getter)();
- double max_dist = sort_mode==SortModeGreedy?threshold*threshold:0;
- while(shape_list.size()) {
+ double max_dist = sort_mode == SortModeGreedy ? threshold * threshold : 0;
+ while (shape_list.size()) {
AREA_TRACE("sorting " << shape_list.size() << ' ' << AREA_XYZ(pstart));
double best_d = DBL_MAX;
auto best_it = shape_list.begin();
- for(auto it=best_it;it!=shape_list.end();++it) {
+ for (auto it = best_it; it != shape_list.end(); ++it) {
double d;
gp_Pnt pt;
- if(it->myPlanar && current_it==shape_list.end())
+ if (it->myPlanar && current_it == shape_list.end())
d = it->myPln.SquareDistance(pstart);
else
d = it->nearest(pstart);
- if(d < best_d) {
+ if (d < best_d) {
best_it = it;
best_d = d;
}
}
gp_Pnt pentry;
- if(sort_mode==SortModeGreedy) {
+ if (sort_mode == SortModeGreedy) {
// greedy sort will go down to the next layer even if the current
// layer is not finished, as long as the path jump distance is
// within the threshold.
- if(current_it==shape_list.end()) {
+ if (current_it == shape_list.end()) {
current_it = best_it;
current_height = (pstart.*getter)();
- } else if(best_d>max_dist) {
+ }
+ else if (best_d > max_dist) {
// If the path jumps beyond the threshold, bail out and go back
// to the first unfinished layer.
(pstart.*setter)(current_height);
@@ -3104,18 +3164,18 @@ std::list Area::sortWires(const std::list &shapes,
}
wires.splice(wires.end(),
- best_it->sortWires(pstart,pend,min_dist,max_dist,&pentry));
+ best_it->sortWires(pstart, pend, min_dist, max_dist, &pentry));
- if(use_bound && _pstart) {
+ if (use_bound && _pstart) {
use_bound = false;
*_pstart = pentry;
}
- if((sort_mode==SortMode2D5||sort_mode==SortMode3D) && stepdown_hint) {
- if(!best_it->myPlanar)
+ if ((sort_mode == SortMode2D5 || sort_mode == SortMode3D) && stepdown_hint) {
+ if (!best_it->myPlanar)
hint_first = true;
- else if(hint_first)
+ else if (hint_first)
hint_first = false;
- else{
+ else {
// Calculate distance of two gp_pln.
//
// Can't use gp_pln.Distance(), because it only calculate
@@ -3124,114 +3184,115 @@ std::list Area::sortWires(const std::list &shapes,
// defined as DBL_MIN (min double) in Standard_Real.hxx.
// Really? Is that a bug?
const gp_Pnt& P = pln.Position().Location();
- const gp_Pnt& loc = best_it->myPln.Position().Location ();
+ const gp_Pnt& loc = best_it->myPln.Position().Location();
const gp_Dir& dir = best_it->myPln.Position().Direction();
double d = (dir.X() * (P.X() - loc.X()) +
- dir.Y() * (P.Y() - loc.Y()) +
- dir.Z() * (P.Z() - loc.Z()));
+ dir.Y() * (P.Y() - loc.Y()) +
+ dir.Z() * (P.Z() - loc.Z()));
if (d < 0) d = -d;
- if(d>hint)
+ if (d > hint)
hint = d;
}
pln = best_it->myPln;
}
pstart = pend;
- if(best_it->myWires.empty()) {
- if(current_it == best_it)
+ if (best_it->myWires.empty()) {
+ if (current_it == best_it)
current_it = shape_list.end();
shape_list.erase(best_it);
}
}
- if(stepdown_hint && hint!=0.0)
+ if (stepdown_hint && hint != 0.0)
*stepdown_hint = hint;
- if(_pend) *_pend = pend;
- FC_DURATION_LOG(rparams.bd,"rtree build");
- FC_DURATION_LOG(rparams.qd,"rtree query");
- FC_DURATION_LOG(rparams.rd,"rtree clean");
- FC_DURATION_LOG(rparams.xd,"BRepExtrema");
- FC_TIME_LOG(t,"sortWires total");
+ if (_pend) *_pend = pend;
+ FC_DURATION_LOG(rparams.bd, "rtree build");
+ FC_DURATION_LOG(rparams.qd, "rtree query");
+ FC_DURATION_LOG(rparams.rd, "rtree clean");
+ FC_DURATION_LOG(rparams.xd, "BRepExtrema");
+ FC_TIME_LOG(t, "sortWires total");
return wires;
}
-static inline void addParameter(bool verbose, Command &cmd, const char *name,
- double last, double next, bool relative=false)
+static inline void addParameter(bool verbose, Command& cmd, const char* name,
+ double last, double next, bool relative = false)
{
- double d = next-last;
- if(verbose || fabs(d)>Precision::Confusion())
- cmd.Parameters[name] = relative?d:next;
+ double d = next - last;
+ if (verbose || fabs(d) > Precision::Confusion())
+ cmd.Parameters[name] = relative ? d : next;
}
-static inline void addGCode(bool verbose, Toolpath &path, const gp_Pnt &last,
- const gp_Pnt &next, const char *name)
+static inline void addGCode(bool verbose, Toolpath& path, const gp_Pnt& last,
+ const gp_Pnt& next, const char* name)
{
Command cmd;
cmd.Name = name;
- addParameter(verbose,cmd,"X",last.X(),next.X());
- addParameter(verbose,cmd,"Y",last.Y(),next.Y());
- addParameter(verbose,cmd,"Z",last.Z(),next.Z());
+ addParameter(verbose, cmd, "X", last.X(), next.X());
+ addParameter(verbose, cmd, "Y", last.Y(), next.Y());
+ addParameter(verbose, cmd, "Z", last.Z(), next.Z());
path.addCommand(cmd);
return;
}
-static inline void addG1(bool verbose,Toolpath &path, const gp_Pnt &last,
- const gp_Pnt &next, double f, double &last_f)
+static inline void addG1(bool verbose, Toolpath& path, const gp_Pnt& last,
+ const gp_Pnt& next, double f, double& last_f)
{
- addGCode(verbose,path,last,next,"G1");
- if(f>Precision::Confusion()) {
- Command *cmd = path.getCommands().back();
- addParameter(verbose,*cmd,"F",last_f,f);
+ addGCode(verbose, path, last, next, "G1");
+ if (f > Precision::Confusion()) {
+ Command* cmd = path.getCommands().back();
+ addParameter(verbose, *cmd, "F", last_f, f);
last_f = f;
}
return;
}
-static void addG0(bool verbose, Toolpath &path,
- gp_Pnt last, const gp_Pnt &next,
- AxisSetter setter, double height)
+static void addG0(bool verbose, Toolpath& path,
+ gp_Pnt last, const gp_Pnt& next,
+ AxisSetter setter, double height)
{
gp_Pnt pt(next);
(pt.*setter)(height);
- if(!last.IsEqual(pt, Precision::Confusion())){
- addGCode(verbose,path,last,pt,"G0");
+ if (!last.IsEqual(pt, Precision::Confusion())) {
+ addGCode(verbose, path, last, pt, "G0");
}
}
-static void addGArc(bool verbose,bool abs_center, Toolpath &path,
- const gp_Pnt &pstart, const gp_Pnt &pend, const gp_Pnt ¢er,
- bool clockwise, double f, double &last_f)
+static void addGArc(bool verbose, bool abs_center, Toolpath& path,
+ const gp_Pnt& pstart, const gp_Pnt& pend, const gp_Pnt& center,
+ bool clockwise, double f, double& last_f)
{
Command cmd;
- cmd.Name = clockwise?"G2":"G3";
- if(abs_center) {
- addParameter(verbose,cmd,"I",0.0,center.X());
- addParameter(verbose,cmd,"J",0.0,center.Y());
- addParameter(verbose,cmd,"K",0.0,center.Z());
- }else{
- addParameter(verbose,cmd,"I",pstart.X(),center.X(),true);
- addParameter(verbose,cmd,"J",pstart.Y(),center.Y(),true);
- addParameter(verbose,cmd,"K",pstart.Z(),center.Z(),true);
+ cmd.Name = clockwise ? "G2" : "G3";
+ if (abs_center) {
+ addParameter(verbose, cmd, "I", 0.0, center.X());
+ addParameter(verbose, cmd, "J", 0.0, center.Y());
+ addParameter(verbose, cmd, "K", 0.0, center.Z());
}
- addParameter(verbose,cmd,"X",pstart.X(),pend.X());
- addParameter(verbose,cmd,"Y",pstart.Y(),pend.Y());
- addParameter(verbose,cmd,"Z",pstart.Z(),pend.Z());
- if(f>Precision::Confusion()) {
- addParameter(verbose,cmd,"F",last_f,f);
+ else {
+ addParameter(verbose, cmd, "I", pstart.X(), center.X(), true);
+ addParameter(verbose, cmd, "J", pstart.Y(), center.Y(), true);
+ addParameter(verbose, cmd, "K", pstart.Z(), center.Z(), true);
+ }
+ addParameter(verbose, cmd, "X", pstart.X(), pend.X());
+ addParameter(verbose, cmd, "Y", pstart.Y(), pend.Y());
+ addParameter(verbose, cmd, "Z", pstart.Z(), pend.Z());
+ if (f > Precision::Confusion()) {
+ addParameter(verbose, cmd, "F", last_f, f);
last_f = f;
}
path.addCommand(cmd);
}
-static inline void addGCode(Toolpath &path, const char *name) {
+static inline void addGCode(Toolpath& path, const char* name) {
Command cmd;
cmd.Name = name;
path.addCommand(cmd);
}
-void Area::setWireOrientation(TopoDS_Wire &wire, const gp_Dir &dir, bool wire_ccw) {
+void Area::setWireOrientation(TopoDS_Wire& wire, const gp_Dir& dir, bool wire_ccw) {
//make a test face
BRepBuilderAPI_MakeFace mkFace(wire, /*onlyplane=*/Standard_True);
- if(!mkFace.IsDone()) {
+ if (!mkFace.IsDone()) {
AREA_WARN("setWireOrientation: failed to make test face");
return;
}
@@ -3244,46 +3305,46 @@ void Area::setWireOrientation(TopoDS_Wire &wire, const gp_Dir &dir, bool wire_cc
TopoDS_Iterator it(tmpFace, /*CumOri=*/Standard_False);
ccw ^= it.Value().Orientation() != wire.Orientation();
- if(ccw != wire_ccw)
+ if (ccw != wire_ccw)
wire.Reverse();
}
-void Area::toPath(Toolpath &path, const std::list &shapes,
- const gp_Pnt *_pstart, gp_Pnt *pend, PARAM_ARGS(PARAM_FARG,AREA_PARAMS_PATH))
+void Area::toPath(Toolpath& path, const std::list& shapes,
+ const gp_Pnt* _pstart, gp_Pnt* pend, PARAM_ARGS(PARAM_FARG, AREA_PARAMS_PATH))
{
std::list wires;
gp_Pnt pstart;
- if(_pstart) pstart = *_pstart;
+ if (_pstart) pstart = *_pstart;
double stepdown_hint = 1.0;
- wires = sortWires(shapes,_pstart!=nullptr,&pstart,pend,&stepdown_hint,
- PARAM_REF(PARAM_FARG,AREA_PARAMS_ARC_PLANE),
- PARAM_FIELDS(PARAM_FARG,AREA_PARAMS_SORT));
+ wires = sortWires(shapes, _pstart != nullptr, &pstart, pend, &stepdown_hint,
+ PARAM_REF(PARAM_FARG, AREA_PARAMS_ARC_PLANE),
+ PARAM_FIELDS(PARAM_FARG, AREA_PARAMS_SORT));
if (wires.size() == 0)
return;
short currentArcPlane = arc_plane;
if (preamble) {
- // absolute mode
- addGCode(path,"G90");
- if(abs_center)
- addGCode(path,"G90.1"); // absolute center for arc move
+ // absolute mode
+ addGCode(path, "G90");
+ if (abs_center)
+ addGCode(path, "G90.1"); // absolute center for arc move
- if(arc_plane==ArcPlaneZX)
- addGCode(path,"G18");
- else if(arc_plane==ArcPlaneYZ)
- addGCode(path,"G19");
- else {
- currentArcPlane=ArcPlaneXY;
- addGCode(path,"G17");
- }
+ if (arc_plane == ArcPlaneZX)
+ addGCode(path, "G18");
+ else if (arc_plane == ArcPlaneYZ)
+ addGCode(path, "G19");
+ else {
+ currentArcPlane = ArcPlaneXY;
+ addGCode(path, "G17");
+ }
}
AxisGetter getter;
AxisSetter setter;
- switch(retract_axis) {
+ switch (retract_axis) {
case RetractAxisX:
getter = &gp_Pnt::X;
setter = &gp_Pnt::SetX;
@@ -3298,31 +3359,31 @@ void Area::toPath(Toolpath &path, const std::list &shapes,
}
threshold = fabs(threshold);
- if(threshold < Precision::Confusion())
+ if (threshold < Precision::Confusion())
threshold = Precision::Confusion();
threshold *= threshold;
// in case the user didn't specify feed start, sortWire() will choose one
// based on the bound. We'll further adjust that according to resume height
- if(!_pstart || pstart.SquareDistance(*_pstart)>Precision::SquareConfusion())
+ if (!_pstart || pstart.SquareDistance(*_pstart) > Precision::SquareConfusion())
(pstart.*setter)(resume_height);
- gp_Pnt plast,p;
+ gp_Pnt plast, p;
// initial vertical rapid pull up to retraction (or start Z height if higher)
- (p.*setter)(std::max(retraction,(pstart.*getter)()));
- addGCode(false,path,plast,p,"G0");
+ (p.*setter)(std::max(retraction, (pstart.*getter)()));
+ addGCode(false, path, plast, p, "G0");
plast = p;
p = pstart;
// rapid horizontal move to start point
gp_Pnt tmpPlast = plast;
(tmpPlast.*setter)((p.*getter)());
- if(_pstart && p.IsEqual(tmpPlast, Precision::Confusion())){
+ if (_pstart && p.IsEqual(tmpPlast, Precision::Confusion())) {
plast.SetCoord(10.0, 10.0, 10.0);
(plast.*setter)(retraction);
}
(p.*setter)(retraction);
- addGCode(false,path,plast,p,"G0");
+ addGCode(false, path, plast, p, "G0");
plast = p;
@@ -3331,14 +3392,14 @@ void Area::toPath(Toolpath &path, const std::list &shapes,
double cur_f = 0.0; // current feed rate
double nf = fabs(feedrate); // user specified normal move feed rate
double vf = fabs(feedrate_v); // user specified vertical move feed rate
- if(vf < Precision::Confusion()) vf = nf;
+ if (vf < Precision::Confusion()) vf = nf;
- for(const TopoDS_Shape &wire : wires) {
+ for (const TopoDS_Shape& wire : wires) {
BRepTools_WireExplorer xp(TopoDS::Wire(wire));
p = BRep_Tool::Pnt(xp.CurrentVertex());
- gp_Pnt pTmp(p),plastTmp(plast);
+ gp_Pnt pTmp(p), plastTmp(plast);
// Assuming the stepdown direction is the same as retraction direction.
// We don't want to count step down distance in stepdown direction,
// because it is always safe to go in that direction in feed move
@@ -3346,101 +3407,106 @@ void Area::toPath(Toolpath &path, const std::list &shapes,
(pTmp.*setter)(0.0);
(plastTmp.*setter)(0.0);
- if(first) {
+ if (first) {
// G0 to initial at retraction to handle if start point was set
- addG0(false,path,plast,p,setter, retraction);
+ addG0(false, path, plast, p, setter, retraction);
// rapid to plunge height
- addG0(false,path,plast,p,setter, resume_height);
- }else if(pTmp.SquareDistance(plastTmp)>threshold){
- // raise to retraction height
- addG0(false,path,plast,plast,setter, retraction);
- // move to new location
- addG0(false,path,plast,p,setter, retraction);
- // lower to plunge height
- addG0(false,path,plast,p,setter, resume_height);
+ addG0(false, path, plast, p, setter, resume_height);
}
- addG1(verbose,path,plast,p,vf,cur_f);
+ else if (pTmp.SquareDistance(plastTmp) > threshold) {
+ // raise to retraction height
+ addG0(false, path, plast, plast, setter, retraction);
+ // move to new location
+ addG0(false, path, plast, p, setter, retraction);
+ // lower to plunge height
+ addG0(false, path, plast, p, setter, resume_height);
+ }
+ addG1(verbose, path, plast, p, vf, cur_f);
plast = p;
first = false;
- for(;xp.More();xp.Next(),plast=p) {
- const auto &edge = xp.Current();
+ for (; xp.More(); xp.Next(), plast = p) {
+ const auto& edge = xp.Current();
BRepAdaptor_Curve curve(edge);
- bool reversed = (edge.Orientation()==TopAbs_REVERSED);
- p = curve.Value(reversed?curve.FirstParameter():curve.LastParameter());
+ bool reversed = (edge.Orientation() == TopAbs_REVERSED);
+ p = curve.Value(reversed ? curve.FirstParameter() : curve.LastParameter());
switch (curve.GetType()) {
case GeomAbs_Line: {
- if(segmentation > Precision::Confusion()) {
+ if (segmentation > Precision::Confusion()) {
GCPnts_UniformAbscissa discretizer(curve, segmentation,
- curve.FirstParameter(), curve.LastParameter());
- if (discretizer.IsDone () && discretizer.NbPoints () > 2) {
- int nbPoints = discretizer.NbPoints ();
- if(reversed) {
- for (int i=nbPoints-1; i>=1; --i) {
+ curve.FirstParameter(), curve.LastParameter());
+ if (discretizer.IsDone() && discretizer.NbPoints() > 2) {
+ int nbPoints = discretizer.NbPoints();
+ if (reversed) {
+ for (int i = nbPoints - 1; i >= 1; --i) {
gp_Pnt pt = curve.Value(discretizer.Parameter(i));
- addG1(verbose,path,plast,pt,nf,cur_f);
+ addG1(verbose, path, plast, pt, nf, cur_f);
plast = pt;
}
- }else{
- for (int i=2; i<=nbPoints; i++) {
+ }
+ else {
+ for (int i = 2; i <= nbPoints; i++) {
gp_Pnt pt = curve.Value(discretizer.Parameter(i));
- addG1(verbose,path,plast,pt,nf,cur_f);
+ addG1(verbose, path, plast, pt, nf, cur_f);
plast = pt;
}
}
break;
}
}
- addG1(verbose,path,plast,p,nf,cur_f);
+ addG1(verbose, path, plast, p, nf, cur_f);
break;
- } case GeomAbs_Circle:{
- const gp_Circ &circle = curve.Circle();
- const gp_Dir &dir = circle.Axis().Direction();
+ } case GeomAbs_Circle: {
+ const gp_Circ& circle = curve.Circle();
+ const gp_Dir& dir = circle.Axis().Direction();
short arcPlane = ArcPlaneNone;
bool clockwise;
- const char *cmd;
- if(fabs(dir.X()) Precision::Confusion()) {
- GCPnts_UniformAbscissa discretizer(curve,segmentation,first,last);
- if (discretizer.IsDone () && discretizer.NbPoints () > 2) {
- int nbPoints = discretizer.NbPoints ();
- if(reversed) {
- for (int i=nbPoints-1; i>=1; --i) {
+ if (segmentation > Precision::Confusion()) {
+ GCPnts_UniformAbscissa discretizer(curve, segmentation, first, last);
+ if (discretizer.IsDone() && discretizer.NbPoints() > 2) {
+ int nbPoints = discretizer.NbPoints();
+ if (reversed) {
+ for (int i = nbPoints - 1; i >= 1; --i) {
gp_Pnt pt = curve.Value(discretizer.Parameter(i));
- addGArc(verbose,abs_center,path,plast,pt,center,clockwise,nf,cur_f);
+ addGArc(verbose, abs_center, path, plast, pt, center, clockwise, nf, cur_f);
plast = pt;
}
- }else{
- for (int i=2; i<=nbPoints; i++) {
+ }
+ else {
+ for (int i = 2; i <= nbPoints; i++) {
gp_Pnt pt = curve.Value(discretizer.Parameter(i));
- addGArc(verbose,abs_center,path,plast,pt,center,clockwise,nf,cur_f);
+ addGArc(verbose, abs_center, path, plast, pt, center, clockwise, nf, cur_f);
plast = pt;
}
}
@@ -3448,31 +3514,32 @@ void Area::toPath(Toolpath &path, const std::list &shapes,
}
}
- if(fabs(first-last)>M_PI) {
+ if (fabs(first - last) > M_PI) {
// Split arc(circle) larger than half circle.
- gp_Pnt mid = curve.Value((last-first)*0.5+first);
- addGArc(verbose,abs_center,path,plast,mid,center,clockwise,nf,cur_f);
+ gp_Pnt mid = curve.Value((last - first) * 0.5 + first);
+ addGArc(verbose, abs_center, path, plast, mid, center, clockwise, nf, cur_f);
plast = mid;
}
- addGArc(verbose,abs_center,path,plast,p,center,clockwise,nf,cur_f);
+ addGArc(verbose, abs_center, path, plast, p, center, clockwise, nf, cur_f);
break;
}
- if(!arcWarned){
+ if (!arcWarned) {
arcWarned = true;
AREA_WARN("arc plane not aligned, force discretization");
}
AREA_TRACE("arc discretize " << AREA_XYZ(dir));
}
- /* FALLTHRU */
+ /* FALLTHRU */
default: {
- const auto &pts = discretize(edge,deflection);
- for(size_t i=1;i > &areas,
- PARAM_ARGS_DEF(PARAM_FARG,AREA_PARAMS_OFFSET), bool from_center=false);
+ void makeOffset(std::list >& areas,
+ PARAM_ARGS_DEF(PARAM_FARG, AREA_PARAMS_OFFSET), bool from_center = false);
/** Make a pocket of the combined shape
*
@@ -160,18 +160,18 @@ protected:
*/
TopoDS_Shape makePocket();
- void explode(const TopoDS_Shape &shape);
+ void explode(const TopoDS_Shape& shape);
- TopoDS_Shape findPlane(const TopoDS_Shape &shape, gp_Trsf &trsf);
+ TopoDS_Shape findPlane(const TopoDS_Shape& shape, gp_Trsf& trsf);
- std::list getProjectedShapes(const gp_Trsf &trsf, bool inverse=true) const;
+ std::list getProjectedShapes(const gp_Trsf& trsf, bool inverse = true) const;
public:
/** Declare all parameters defined in #AREA_PARAMS_ALL as member variable */
- PARAM_ENUM_DECLARE(AREA_PARAMS_ALL)
+ PARAM_ENUM_DECLARE(AREA_PARAMS_ALL);
- Area(const AreaParams *params = nullptr);
- Area(const Area &other, bool deep_copy=true);
+ Area(const AreaParams* params = nullptr);
+ Area(const Area& other, bool deep_copy = true);
virtual ~Area();
bool isBuilt() const;
@@ -187,7 +187,7 @@ public:
* If no working plane are set, Area will try to find a working plane from
* the added children shape using the same algorithm
*/
- void setPlane(const TopoDS_Shape &shape);
+ void setPlane(const TopoDS_Shape& shape);
/** Return the current active workplane
*
@@ -197,7 +197,7 @@ public:
* If no workplane is set using setPlane(), the active workplane is derived from
* the added children shapes using the same algorithm empolyed by setPlane().
*/
- TopoDS_Shape getPlane(gp_Trsf *trsf=nullptr);
+ TopoDS_Shape getPlane(gp_Trsf* trsf = nullptr);
/** Add a child shape with given operation code
*
@@ -208,7 +208,7 @@ public:
* \arg \c shape: the child shape
* \arg \c op: operation code, see #AREA_PARAMS_OPCODE
*/
- void add(const TopoDS_Shape &shape,PARAM_ARGS_DEF(PARAM_FARG,AREA_PARAMS_OPCODE));
+ void add(const TopoDS_Shape& shape, PARAM_ARGS_DEF(PARAM_FARG, AREA_PARAMS_OPCODE));
/** Generate an offset of the combined shape
@@ -217,14 +217,14 @@ public:
* If more than one offset is requested, a compound shape is return
* containing all offset shapes as wires regardless of \c Fill setting.
*/
- TopoDS_Shape makeOffset(int index=-1, PARAM_ARGS_DEF(PARAM_FARG,AREA_PARAMS_OFFSET),
- int reoirent=0, bool from_center=false);
+ TopoDS_Shape makeOffset(int index = -1, PARAM_ARGS_DEF(PARAM_FARG, AREA_PARAMS_OFFSET),
+ int reoirent = 0, bool from_center = false);
/** Make a pocket of the combined shape
*
* See #AREA_PARAMS_POCKET for description of the arguments.
*/
- TopoDS_Shape makePocket(int index=-1, PARAM_ARGS_DEF(PARAM_FARG,AREA_PARAMS_POCKET));
+ TopoDS_Shape makePocket(int index = -1, PARAM_ARGS_DEF(PARAM_FARG, AREA_PARAMS_POCKET));
/** Make a pocket of the combined shape
*
@@ -239,12 +239,12 @@ public:
* is only one argument, namely \c mode for section mode.
*/
std::vector > makeSections(
- PARAM_ARGS_DEF(PARAM_FARG,AREA_PARAMS_SECTION_EXTRA),
- const std::vector &heights = std::vector(),
- const TopoDS_Shape &plane = TopoDS_Shape());
+ PARAM_ARGS_DEF(PARAM_FARG, AREA_PARAMS_SECTION_EXTRA),
+ const std::vector& heights = std::vector(),
+ const TopoDS_Shape& plane = TopoDS_Shape());
/** Config this Area object */
- void setParams(const AreaParams ¶ms);
+ void setParams(const AreaParams& params);
const std::list getChildren() const {
@@ -252,7 +252,7 @@ public:
}
/** Get the current configuration */
- const AreaParams &getParams() const {
+ const AreaParams& getParams() const {
return myParams;
}
@@ -263,13 +263,13 @@ public:
*
* \arg \c deleteShapes: if true, delete all children shapes.
*/
- void clean(bool deleteShapes=false);
+ void clean(bool deleteShapes = false);
/** Get the combined shape
* \arg \c index: index of the section, -1 for all sections. No effect on
* non-sectioned area.
*/
- TopoDS_Shape getShape(int index=-1);
+ TopoDS_Shape getShape(int index = -1);
/** Return the number of sections */
std::size_t getSectionCount() {
@@ -287,8 +287,8 @@ public:
* \arg \c to_edges: if true, discretize all curves, and insert as open
* line segments
* */
- static void addWire(CArea &area, const TopoDS_Wire &wire, const gp_Trsf *trsf=nullptr,
- double deflection=0.01, bool to_edges=false);
+ static void addWire(CArea& area, const TopoDS_Wire& wire, const gp_Trsf* trsf = nullptr,
+ double deflection = 0.01, bool to_edges = false);
/** Add a OCC generic shape to CArea
*
@@ -307,10 +307,10 @@ public:
* \return Returns the number of non coplaner. Planar testing only happens
* if \c plane is supplied
* */
- static int addShape(CArea &area, const TopoDS_Shape &shape, const gp_Trsf *trsf=nullptr,
- double deflection=0.01,const TopoDS_Shape *plane = nullptr,
- bool force_coplanar=true, CArea *areaOpen=nullptr, bool to_edges=false,
- bool reorient=true);
+ static int addShape(CArea& area, const TopoDS_Shape& shape, const gp_Trsf* trsf = nullptr,
+ double deflection = 0.01, const TopoDS_Shape* plane = nullptr,
+ bool force_coplanar = true, CArea* areaOpen = nullptr, bool to_edges = false,
+ bool reorient = true);
/** Convert curves in CArea into an OCC shape
*
@@ -319,8 +319,8 @@ public:
* \arg \c trsf: optional transform matrix to transform the shape back into
* its original position.
* */
- static TopoDS_Shape toShape(const CArea &area, bool fill,
- const gp_Trsf *trsf=nullptr, int reoirent=0);
+ static TopoDS_Shape toShape(const CArea& area, bool fill,
+ const gp_Trsf* trsf = nullptr, int reoirent = 0);
/** Convert a single curve into an OCC wire
*
@@ -328,10 +328,10 @@ public:
* \arg \c trsf: optional transform matrix to transform the shape back into
* its original position.
* */
- static TopoDS_Shape toShape(const CCurve &curve, const gp_Trsf *trsf=nullptr, int reorient=0);
+ static TopoDS_Shape toShape(const CCurve& curve, const gp_Trsf* trsf = nullptr, int reorient = 0);
/** Check if two OCC shape is coplanar */
- static bool isCoplanar(const TopoDS_Shape &s1, const TopoDS_Shape &s2);
+ static bool isCoplanar(const TopoDS_Shape& s1, const TopoDS_Shape& s2);
/** Group shapes by their plane, and return a list of sorted wires
*
@@ -353,9 +353,9 @@ public:
*
* \return sorted wires
*/
- static std::list sortWires(const std::list &shapes,
- bool has_start=false, gp_Pnt *pstart=nullptr, gp_Pnt *pend=nullptr, double *stepdown_hint=nullptr,
- short *arc_plane = nullptr, PARAM_ARGS_DEF(PARAM_FARG,AREA_PARAMS_SORT));
+ static std::list sortWires(const std::list& shapes,
+ bool has_start = false, gp_Pnt* pstart = nullptr, gp_Pnt* pend = nullptr, double* stepdown_hint = nullptr,
+ short* arc_plane = nullptr, PARAM_ARGS_DEF(PARAM_FARG, AREA_PARAMS_SORT));
/** Convert a list of wires to gcode
*
@@ -366,25 +366,25 @@ public:
*
* See #AREA_PARAMS_PATH for other arguments
*/
- static void toPath(Toolpath &path, const std::list &shapes,
- const gp_Pnt *pstart=nullptr, gp_Pnt *pend=nullptr,
- PARAM_ARGS_DEF(PARAM_FARG,AREA_PARAMS_PATH));
+ static void toPath(Toolpath& path, const std::list& shapes,
+ const gp_Pnt* pstart = nullptr, gp_Pnt* pend = nullptr,
+ PARAM_ARGS_DEF(PARAM_FARG, AREA_PARAMS_PATH));
- static int project(TopoDS_Shape &out, const TopoDS_Shape &in,
- const AreaParams *params = nullptr,
- const TopoDS_Shape *work_plane = nullptr);
+ static int project(TopoDS_Shape& out, const TopoDS_Shape& in,
+ const AreaParams* params = nullptr,
+ const TopoDS_Shape* work_plane = nullptr);
- static void setWireOrientation(TopoDS_Wire& wire, const gp_Dir &dir, bool ccw);
+ static void setWireOrientation(TopoDS_Wire& wire, const gp_Dir& dir, bool ccw);
- PARAM_ENUM_DECLARE(AREA_PARAMS_PATH)
+ PARAM_ENUM_DECLARE(AREA_PARAMS_PATH);
static void abort(bool aborting);
static bool aborting();
- static void setDefaultParams(const AreaStaticParams ¶ms);
- static const AreaStaticParams &getDefaultParams();
+ static void setDefaultParams(const AreaStaticParams& params);
+ static const AreaStaticParams& getDefaultParams();
- static void showShape(const TopoDS_Shape &shape, const char *name, const char *fmt=nullptr, ...);
+ static void showShape(const TopoDS_Shape& shape, const char* name, const char* fmt = nullptr, ...);
};
} //namespace Path