From de2c826f86acfc09dd84d0f097ecbb04fd86ca6e Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sat, 6 May 2017 02:37:38 +0800 Subject: [PATCH] Path.Area: use FC tag based logging --- src/Mod/Path/App/Area.cpp | 127 ++++++++++++++++--------------- src/Mod/Path/App/Area.h | 81 -------------------- src/Mod/Path/App/FeatureArea.cpp | 6 +- 3 files changed, 71 insertions(+), 143 deletions(-) diff --git a/src/Mod/Path/App/Area.cpp b/src/Mod/Path/App/Area.cpp index e00c5da93d..e3ab1bbdda 100644 --- a/src/Mod/Path/App/Area.cpp +++ b/src/Mod/Path/App/Area.cpp @@ -97,6 +97,15 @@ typedef bgi::linear<16> RParameters; BOOST_GEOMETRY_REGISTER_POINT_3D_GET_SET( gp_Pnt,double,bg::cs::cartesian,X,Y,Z,SetX,SetY,SetZ) +#define AREA_LOG FC_LOG +#define AREA_WARN FC_WARN +#define AREA_ERR FC_ERR +#define AREA_TRACE FC_TRACE +#define AREA_XYZ FC_XYZ +#define AREA_XY AREA_XY + +FC_LOG_LEVEL_INIT("Path.Area",true,true) + using namespace Path; CAreaParams::CAreaParams() @@ -976,7 +985,7 @@ TopoDS_Shape Area::findPlane(const TopoDS_Shape &shape, gp_Trsf &trsf) int Area::project(TopoDS_Shape &shape_out, const TopoDS_Shape &shape_in, const AreaParams *params) { - TIME_INIT2(t,t1); + FC_TIME_INIT2(t,t1); Handle_HLRBRep_Algo brep_hlr = NULL; gp_Dir dir(0,0,1); try { @@ -990,7 +999,7 @@ int Area::project(TopoDS_Shape &shape_out, AREA_ERR("error occurred while projecting shape"); return -1; } - TIME_PRINT(t1,"HLRBrep_Algo"); + FC_TIME_LOG(t1,"HLRBrep_Algo"); WireJoiner joiner; try { #define ADD_HLR_SHAPE(_name) \ @@ -1011,16 +1020,16 @@ int Area::project(TopoDS_Shape &shape_out, AREA_ERR("error occurred while extracting edges"); return -1; } - TIME_PRINT(t1,"WireJoiner init"); + FC_TIME_LOG(t1,"WireJoiner init"); joiner.splitEdges(); - TIME_PRINT(t1,"WireJoiner splitEdges"); + 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"); } int skips = joiner.findClosedWires(); - TIME_PRINT(t1,"WireJoiner findClosedWires"); + FC_TIME_LOG(t1,"WireJoiner findClosedWires"); Area area(params); area.myParams.Explode = false; @@ -1034,8 +1043,8 @@ int Area::project(TopoDS_Shape &shape_out, const TopoDS_Shape &shape = area.getShape(); showShape(shape,"projected"); - TIME_PRINT(t1,"Clipper wire union"); - TIME_PRINT(t,"project total"); + FC_TIME_LOG(t1,"Clipper wire union"); + FC_TIME_LOG(t,"project total"); if(shape.IsNull()) { AREA_ERR("poject failed"); @@ -1061,7 +1070,7 @@ std::vector > Area::makeSections( if(plane.IsNull()) throw Base::ValueError("failed to obtain section plane"); - TIME_INIT2(t,t1); + FC_TIME_INIT2(t,t1); TopLoc_Location loc(trsf); @@ -1272,7 +1281,7 @@ std::vector > Area::makeSections( } if(area->myShapes.size()){ sections.push_back(area); - TIME_PRINT(t1,"makeSection " << z); + FC_TIME_LOG(t1,"makeSection " << z); break; } if(retried) { @@ -1285,7 +1294,7 @@ std::vector > Area::makeSections( } } } - TIME_PRINT(t,"makeSection count: " << sections.size()<<", total"); + FC_TIME_LOG(t,"makeSection count: " << sections.size()<<", total"); return std::move(sections); } @@ -1348,7 +1357,7 @@ void Area::build() { return; } - TIME_INIT(t); + FC_TIME_INIT(t); gp_Trsf trsf; getPlane(&trsf); @@ -1434,7 +1443,7 @@ void Area::build() { } } - TIME_TRACE(t,"prepare"); + FC_TIME_TRACE(t,"prepare"); }catch(...) { clean(); @@ -1517,7 +1526,7 @@ TopoDS_Shape Area::getShape(int index) { return myShape; } - TIME_INIT(t); + FC_TIME_INIT(t); // do offset first, then pocket the inner most offseted shape std::list > areas; @@ -1551,19 +1560,19 @@ TopoDS_Shape Area::getShape(int index) { builder.MakeCompound(compound); short fill = myParams.Thicken?FillFace:FillNone; - TIME_INIT(t2); - DURATION_INIT(d); + FC_TIME_INIT(t2); + FC_DURATION_DECL_INIT(d); for(shared_ptr area : areas) { if(myParams.Thicken){ area->Thicken(myParams.ToolRadius); - DURATION_PLUS(d,t2); + FC_DURATION_PLUS(d,t2); } const TopoDS_Shape &shape = toShape(*area,fill); if(shape.IsNull()) continue; builder.Add(compound,shape); } if(myParams.Thicken) - DURATION_PRINT(d,"Thicken"); + FC_DURATION_LOG(d,"Thicken"); // make sure the compound has at least one edge for(TopExp_Explorer it(compound,TopAbs_EDGE);it.More();) { @@ -1573,7 +1582,7 @@ TopoDS_Shape Area::getShape(int index) { break; } myShapeDone = true; - TIME_PRINT(t,"total"); + FC_TIME_LOG(t,"total"); return myShape; } @@ -1586,9 +1595,9 @@ TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET if(areas.empty()) { if(myParams.Thicken && myParams.ToolRadius>Precision::Confusion()) { CArea area(*myArea); - TIME_INIT(t); + FC_TIME_INIT(t); area.Thicken(myParams.ToolRadius); - TIME_PRINT(t,"Thicken"); + FC_TIME_LOG(t,"Thicken"); return toShape(area,FillFace,reorient); } return TopoDS_Shape(); @@ -1596,8 +1605,8 @@ TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET BRep_Builder builder; TopoDS_Compound compound; builder.MakeCompound(compound); - TIME_INIT(t); - DURATION_INIT(d); + FC_TIME_INIT(t); + FC_DURATION_DECL_INIT(d); bool thicken = myParams.Thicken && myParams.ToolRadius>Precision::Confusion(); @@ -1605,7 +1614,7 @@ TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET short fill; if(thicken){ area->Thicken(myParams.ToolRadius); - DURATION_PLUS(d,t); + FC_DURATION_PLUS(d,t); fill = FillFace; }else if(areas.size()==1) fill = myParams.Fill; @@ -1616,7 +1625,7 @@ TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET builder.Add(compound,shape); } if(thicken) - DURATION_PRINT(d,"Thicken"); + FC_DURATION_LOG(d,"Thicken"); for(TopExp_Explorer it(compound,TopAbs_EDGE);it.More();) return compound; return TopoDS_Shape(); @@ -1628,7 +1637,7 @@ void Area::makeOffset(list > &areas, if(fabs(offset) > &areas, } #endif if(count>1) - TIME_PRINT(t1,"makeOffset " << i << '/' << count); + FC_TIME_LOG(t1,"makeOffset " << i << '/' << count); if(area.m_curves.empty()) return; } - TIME_PRINT(t,"makeOffset count: " << count); + FC_TIME_LOG(t,"makeOffset count: " << count); } TopoDS_Shape Area::makePocket(int index, PARAM_ARGS(PARAM_FARG,AREA_PARAMS_POCKET)) { @@ -1709,7 +1718,7 @@ TopoDS_Shape Area::makePocket(int index, PARAM_ARGS(PARAM_FARG,AREA_PARAMS_POCKE build(); AREA_SECTION(makePocket,index,PARAM_FIELDS(PARAM_FARG,AREA_PARAMS_POCKET)); - TIME_INIT(t); + FC_TIME_INIT(t); bool done = false; if(index>=0) { @@ -1818,12 +1827,12 @@ TopoDS_Shape Area::makePocket(int index, PARAM_ARGS(PARAM_FARG,AREA_PARAMS_POCKE in.MakePocketToolpath(out.m_curves,params); } - TIME_PRINT(t,"makePocket"); + FC_TIME_LOG(t,"makePocket"); if(myParams.Thicken){ - TIME_INIT(t); + FC_TIME_INIT(t); out.Thicken(tool_radius); - TIME_PRINT(t,"thicken"); + FC_TIME_LOG(t,"thicken"); return toShape(out,FillFace); }else return toShape(out,FillNone); @@ -1924,7 +1933,7 @@ TopoDS_Shape Area::toShape(const CArea &area, bool fill, const gp_Trsf *trsf, in if(!xp.More()) return TopoDS_Shape(); if(fill) { try{ - TIME_INIT(t); + FC_TIME_INIT(t); Part::FaceMakerBullseye mkFace; if(trsf) mkFace.setPlane(gp_Pln().Transformed(*trsf)); @@ -1933,7 +1942,7 @@ TopoDS_Shape Area::toShape(const CArea &area, bool fill, const gp_Trsf *trsf, in mkFace.Build(); if (mkFace.Shape().IsNull()) AREA_WARN("FaceMakerBullseye returns null shape"); - TIME_PRINT(t,"makeFace"); + FC_TIME_LOG(t,"makeFace"); return mkFace.Shape(); }catch (Base::Exception &e){ AREA_WARN("FaceMakerBullseye failed: "<pstart()); @@ -2336,10 +2343,10 @@ struct ShapeInfo{ wires.push_back(myBestWire->wire); pend = myBestWire->pend(); } - TIME_INIT(t); + FC_TIME_INIT(t); for(size_t i=0,count=myBestWire->points.size();i Area::sortWires(const std::list &shapes, ShapeParams rparams(abscissa,nearest_k>0?nearest_k:1,orientation,direction); std::list shape_list; - TIME_INIT2(t,t1); + FC_TIME_INIT2(t,t1); gp_Trsf trsf; bool arcPlaneFound = false; @@ -2551,7 +2558,7 @@ std::list Area::sortWires(const std::list &shapes, arcPlaneFound,arc_plane,trsf,shape_list,rparams)); } } - TIME_PRINT(t1,"plane finding"); + FC_TIME_LOG(t1,"plane finding"); } if(shape_list.empty()) @@ -2602,10 +2609,10 @@ std::list Area::sortWires(const std::list &shapes, it->myShape = comp; } } - TIME_PRINT(t,"plane merging"); + FC_TIME_LOG(t,"plane merging"); } - DURATION_INIT(td); + FC_DURATION_DECL_INIT(td); if(use_bound) { bounds.SetGap(0.0); @@ -2638,11 +2645,11 @@ std::list Area::sortWires(const std::list &shapes, shape_list.erase(best_it); } if(_pend) *_pend = pend; - DURATION_PRINT(rparams.bd,"rtree build"); - DURATION_PRINT(rparams.qd,"rtree query"); - DURATION_PRINT(rparams.rd,"rtree clean"); - DURATION_PRINT(rparams.xd,"BRepExtrema"); - TIME_PRINT(t,"sortWires total"); + 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 std::move(wires); } diff --git a/src/Mod/Path/App/Area.h b/src/Mod/Path/App/Area.h index 281d963f41..043108e6bd 100644 --- a/src/Mod/Path/App/Area.h +++ b/src/Mod/Path/App/Area.h @@ -42,87 +42,6 @@ namespace Part { extern PartExport Py::Object shape2pyshape(const TopoDS_Shape &shape); } -#define _AREA_LOG(_l,_msg) do {\ - if(Area::_l##Enabled()){\ - std::stringstream str;\ - str << _msg;\ - const char *_f = strrchr(__FILE__, '/');\ - Base::Console()._l("%s:(%d): %s\n",_f?_f+1:__FILE__,__LINE__,str.str().c_str());\ - }\ - QCoreApplication::sendPostedEvents();\ - if(Area::aborting()) {\ - Area::abort(false);\ - throw Base::AbortException("operation aborted");\ - }\ -}while(0) - -#define AREA_LOG(_msg) _AREA_LOG(Log,_msg) -#define AREA_WARN(_msg) _AREA_LOG(Warning,_msg) -#define AREA_ERR(_msg) _AREA_LOG(Error,_msg) -#define AREA_XYZ(_pt) '('<<(_pt).X()<<", " << (_pt).Y()<<", " << (_pt).Z()<<')' -#define AREA_XY(_pt) '('<<(_pt).x<<", " << (_pt).y<<')' - -#define AREA_TRACE(_msg) do{\ - if(Area::TraceEnabled()) AREA_LOG(_msg);\ -}while(0) - -#define AREA_DBG AREA_WARN - -#define AREA_TIME_ENABLE - -#ifdef AREA_TIME_ENABLE -#define TIME_UNIT duration -#define TIME_CLOCK high_resolution_clock -#define TIME_POINT std::chrono::TIME_CLOCK::time_point -#define TIME_DURATION std::chrono::TIME_UNIT - -#define _TIME_INIT(_t) _t=std::chrono::TIME_CLOCK::now() -#define TIME_INIT(_t) TIME_POINT _TIME_INIT(_t) -#define TIME_INIT2(_t1,_t2) TIME_INIT(_t1),_t2=_t1 -#define TIME_INIT3(_t1,_t2,_t3) TIME_INIT(_t1),_t2=_t1,_t3=_t1 - -#define _DURATION_PRINT(_l,_d,_msg) \ - AREA_##_l(_msg<< " time: " << _d.count()<<'s'); - -#define DURATION_PRINT(_d,_msg) _DURATION_PRINT(LOG,_d,_msg) - -#define TIME_PRINT(_t,_msg) \ - DURATION_PRINT(Path::getDuration(_t),_msg); - -#define TIME_TRACE(_t,_msg) \ - _DURATION_PRINT(TRACE,Path::getDuration(_t),_msg); - -#define DURATION_INIT(_d) \ - TIME_DURATION _d(0) - -#define DURATION_INIT2(_d1,_d2) DURATION_INIT(_d1),_d2(0) - -namespace Path { -inline std::chrono::TIME_UNIT getDuration(TIME_POINT &t) -{ - auto tnow = std::chrono::TIME_CLOCK::now(); - auto d = std::chrono::duration_cast(tnow-t); - t = tnow; - return d; -} -} - -#define DURATION_PLUS(_d,_t) _d += Path::getDuration(_t) - -#else -#define TIME_POINT -#define _TIME_INIT(...) do{}while(0) -#define TIME_INIT(...) do{}while(0) -#define TIME_INIT2(...) do{}while(0) -#define TIME_INIT3(...) do{}while(0) -#define TIME_PRINT(...) do{}while(0) -#define DURATION_PRINT(...) do{}while(0) -#define DURATION_INIT(...) do{}while(0) -#define DURATION_INIT2(...) do{}while(0) -#define DURATION_PLUS(...) do{}while(0) - -#endif - class CArea; class CCurve; class Bnd_Box; diff --git a/src/Mod/Path/App/FeatureArea.cpp b/src/Mod/Path/App/FeatureArea.cpp index 9e159a5f8d..4f8b1b3dc6 100644 --- a/src/Mod/Path/App/FeatureArea.cpp +++ b/src/Mod/Path/App/FeatureArea.cpp @@ -34,6 +34,8 @@ #include #include +FC_LOG_LEVEL_INIT("Path.Area",true,true) + using namespace Path; PROPERTY_SOURCE(Path::FeatureArea, Part::Feature) @@ -84,7 +86,7 @@ App::DocumentObjectExecReturn *FeatureArea::execute(void) return new App::DocumentObjectExecReturn("Linked shape object is empty"); } - TIME_INIT(t); + FC_TIME_INIT(t); AreaParams params; @@ -129,7 +131,7 @@ App::DocumentObjectExecReturn *FeatureArea::execute(void) Shape.setValue(compound); } - TIME_PRINT(t,"feature execute"); + FC_TIME_LOG(t,"feature execute"); if(!hasShape) return new App::DocumentObjectExecReturn("no output shape");