Skip to content

Commit

Permalink
Path.Area: force CW orientation on pocket mode offset
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder authored and wwmayer committed May 13, 2017
1 parent 997200d commit dd36a9f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
44 changes: 31 additions & 13 deletions src/Mod/Path/App/Area.cpp
Expand Up @@ -1380,7 +1380,7 @@ void Area::build() {
}
}

TopoDS_Shape Area::toShape(CArea &area, short fill) {
TopoDS_Shape Area::toShape(CArea &area, short fill, int reorient) {
gp_Trsf trsf(myTrsf.Inverted());
bool bFill;
switch(fill){
Expand All @@ -1397,11 +1397,11 @@ TopoDS_Shape Area::toShape(CArea &area, short fill) {
if(&area == myArea.get()) {
CArea copy(area);
copy.FitArcs();
return toShape(copy,bFill,&trsf);
return toShape(copy,bFill,&trsf,reorient);
}
area.FitArcs();
}
return toShape(area,bFill,&trsf);
return toShape(area,bFill,&trsf,reorient);
}


Expand Down Expand Up @@ -1515,9 +1515,9 @@ TopoDS_Shape Area::getShape(int index) {
return myShape;
}

TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET)) {
TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET),int reorient) {
build();
AREA_SECTION(makeOffset,index,PARAM_FIELDS(PARAM_FARG,AREA_PARAMS_OFFSET));
AREA_SECTION(makeOffset,index,PARAM_FIELDS(PARAM_FARG,AREA_PARAMS_OFFSET),reorient);

std::list<shared_ptr<CArea> > areas;
makeOffset(areas,PARAM_FIELDS(PARAM_FARG,AREA_PARAMS_OFFSET));
Expand All @@ -1527,7 +1527,7 @@ TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET
TIME_INIT(t);
area.Thicken(myParams.ToolRadius);
TIME_PRINT(t,"Thicken");
return toShape(area,FillFace);
return toShape(area,FillFace,reorient);
}
return TopoDS_Shape();
}
Expand All @@ -1536,21 +1536,24 @@ TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET
builder.MakeCompound(compound);
TIME_INIT(t);
DURATION_INIT(d);

bool thicken = myParams.Thicken && myParams.ToolRadius>Precision::Confusion();

for(shared_ptr<CArea> area : areas) {
short fill;
if(myParams.Thicken && myParams.ToolRadius>Precision::Confusion()) {
if(thicken){
area->Thicken(myParams.ToolRadius);
DURATION_PLUS(d,t);
fill = FillFace;
}else if(areas.size()==1)
fill = myParams.Fill;
else
fill = FillNone;
const TopoDS_Shape &shape = toShape(*area,fill);
const TopoDS_Shape &shape = toShape(*area,fill,reorient);
if(shape.IsNull()) continue;
builder.Add(compound,shape);
}
if(myParams.Thicken && myParams.ToolRadius>Precision::Confusion())
if(thicken)
DURATION_PRINT(d,"Thicken");
for(TopExp_Explorer it(compound,TopAbs_EDGE);it.More();)
return compound;
Expand Down Expand Up @@ -1686,7 +1689,8 @@ TopoDS_Shape Area::makePocket(int index, PARAM_ARGS(PARAM_FARG,AREA_PARAMS_POCKE
Offset = -tool_radius-extra_offset-shift;
ExtraPass = -1;
Stepover = -stepover;
return makeOffset(index,PARAM_FIELDS(PARAM_FNAME,AREA_PARAMS_OFFSET));
// make offset and make sure the loop is CW (i.e. inner wires)
return makeOffset(index,PARAM_FIELDS(PARAM_FNAME,AREA_PARAMS_OFFSET),-1);
}case Area::PocketModeZigZagOffset:
pm = ZigZagThenSingleOffsetPocketMode;
break;
Expand Down Expand Up @@ -1767,8 +1771,22 @@ 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_Wire Area::toShape(const CCurve &c, const gp_Trsf *trsf) {
TopoDS_Wire Area::toShape(const CCurve &_c, const gp_Trsf *trsf, int reorient) {
BRepBuilderAPI_MakeWire mkWire;

CCurve cReversed;
if(reorient) {
if(_c.IsClosed() &&
((reorient>0 && _c.IsClockwise()) ||
(reorient<0 && !_c.IsClockwise())))
{
cReversed = _c;
cReversed.Reverse();
}else
reorient = 0;
}
const CCurve &c = reorient?cReversed:_c;

gp_Pnt pstart,pt;
bool first = true;
for(const CVertex &v : c.m_vertices){
Expand Down Expand Up @@ -1830,13 +1848,13 @@ TopoDS_Wire Area::toShape(const CCurve &c, const gp_Trsf *trsf) {
return mkWire.Wire();
}

TopoDS_Shape Area::toShape(const CArea &area, bool fill, const gp_Trsf *trsf) {
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 TopoDS_Wire &wire = toShape(c,trsf);
const TopoDS_Wire &wire = toShape(c,trsf,reorient);
if(!wire.IsNull())
builder.Add(compound,wire);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Mod/Path/App/Area.h
Expand Up @@ -227,7 +227,7 @@ class PathExport Area: public Base::BaseClass {
void addToBuild(CArea &area, const TopoDS_Shape &shape);

/** Called internally to obtain the combained children shapes */
TopoDS_Shape toShape(CArea &area, short fill);
TopoDS_Shape toShape(CArea &area, short fill, int reorient=0);

/** Obtain a list of offseted areas
*
Expand Down Expand Up @@ -299,7 +299,7 @@ class PathExport Area: public Base::BaseClass {
* 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));
TopoDS_Shape makeOffset(int index=-1, PARAM_ARGS_DEF(PARAM_FARG,AREA_PARAMS_OFFSET), int reoirent=0);

/** Make a pocket of the combined shape
*
Expand Down Expand Up @@ -401,15 +401,15 @@ class PathExport Area: public Base::BaseClass {
* its original position.
* */
static TopoDS_Shape toShape(const CArea &area, bool fill,
const gp_Trsf *trsf=NULL);
const gp_Trsf *trsf=NULL, int reoirent=0);

/** Convert a single curve into an OCC wire
*
* \arg \c curve: input curve object
* \arg \c trsf: optional transform matrix to transform the shape back into
* its original position.
* */
static TopoDS_Wire toShape(const CCurve &curve, const gp_Trsf *trsf=NULL);
static TopoDS_Wire toShape(const CCurve &curve, const gp_Trsf *trsf=NULL, int reorient=0);

/** Check if two OCC shape is coplanar */
static bool isCoplanar(const TopoDS_Shape &s1, const TopoDS_Shape &s2);
Expand Down

0 comments on commit dd36a9f

Please sign in to comment.