Skip to content

Commit

Permalink
Sketcher: fix polyline closing when coincident points are involved
Browse files Browse the repository at this point in the history
  • Loading branch information
logari81 committed Feb 12, 2014
1 parent 9c8df98 commit 4d918d1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
19 changes: 19 additions & 0 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -1460,6 +1460,25 @@ void SketchObject::getCoincidentPoints(int VertexId, std::vector<int> &GeoIdList
getCoincidentPoints(GeoId, PosId, GeoIdList, PosIdList);
}

bool SketchObject::arePointsCoincident(int GeoId1, PointPos PosId1,
int GeoId2, PointPos PosId2)
{
if (GeoId1 == GeoId2 && PosId1 == PosId2)
return true;

const std::vector<Constraint *> &constraints = this->Constraints.getValues();
for (std::vector<Constraint *>::const_iterator it=constraints.begin();
it != constraints.end(); ++it) {
if ((*it)->Type == Sketcher::Coincident)
if (((*it)->First == GeoId1 && (*it)->FirstPos == PosId1 &&
(*it)->Second == GeoId2 && (*it)->SecondPos == PosId2) ||
((*it)->First == GeoId2 && (*it)->FirstPos == PosId2 &&
(*it)->Second == GeoId1 && (*it)->SecondPos == PosId1))
return true;
}
return false;
}

void SketchObject::appendConflictMsg(const std::vector<int> &conflicting, std::string &msg)
{
std::stringstream ss;
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Sketcher/App/SketchObject.h
Expand Up @@ -136,6 +136,7 @@ class SketcherExport SketchObject : public Part::Part2DObject
void getCoincidentPoints(int GeoId, PointPos PosId, std::vector<int> &GeoIdList,
std::vector<PointPos> &PosIdList);
void getCoincidentPoints(int VertexId, std::vector<int> &GeoIdList, std::vector<PointPos> &PosIdList);
bool arePointsCoincident(int GeoId1, PointPos PosId1, int GeoId2, PointPos PosId2);

/// generates a warning message about constraint conflicts and appends it to the given message
static void appendConflictMsg(const std::vector<int> &conflicting, std::string &msg);
Expand Down
41 changes: 22 additions & 19 deletions src/Mod/Sketcher/Gui/CommandCreateGeo.cpp
Expand Up @@ -502,7 +502,8 @@ class DrawSketchHandlerLineSet: public DrawSketchHandler
DrawSketchHandlerLineSet()
: Mode(STATUS_SEEK_First),SegmentMode(SEGMENT_MODE_Line),
TransitionMode(TRANSITION_MODE_Free),suppressTransition(false),EditCurve(2),
firstVertex(-1),firstCurve(-1),previousCurve(-1),previousPosId(Sketcher::none) {}
firstCurve(-1),previousCurve(-1),
firstPosId(Sketcher::none),previousPosId(Sketcher::none) {}
virtual ~DrawSketchHandlerLineSet() {}
/// mode table
enum SELECT_MODE {
Expand Down Expand Up @@ -748,13 +749,9 @@ class DrawSketchHandlerLineSet: public DrawSketchHandler
}
}

// in case a transition is set up, firstCurve and firstVertex should
// remain set to -1 in order to disable closing the wire
if (previousCurve == -1) {
// remember our first point
firstVertex = getHighestVertexIndex() + 1;
firstCurve = getHighestCurveIndex() + 1;
}
// remember our first point (even if we are doing a transition from a previous curve)
firstCurve = getHighestCurveIndex() + 1;
firstPosId = Sketcher::start;

if (SegmentMode == SEGMENT_MODE_Line)
EditCurve.resize(TransitionMode == TRANSITION_MODE_Free ? 2 : 3);
Expand All @@ -771,10 +768,20 @@ class DrawSketchHandlerLineSet: public DrawSketchHandler
sketchgui->drawEdit(EditCurve);
sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider
}
if (sketchgui->getPreselectPoint() == firstVertex && firstVertex != -1)
Mode = STATUS_Close;
else
Mode = STATUS_Do;

Mode = STATUS_Do;
if (sketchgui->getPreselectPoint() != -1 && firstPosId != Sketcher::none) {
int GeoId;
Sketcher::PointPos PosId;
sketchgui->getSketchObject()->getGeoVertexIndex(sketchgui->getPreselectPoint(),GeoId,PosId);
if (sketchgui->getSketchObject()->arePointsCoincident(GeoId,PosId,firstCurve,firstPosId))
Mode = STATUS_Close;
}
else if (sketchgui->getPreselectCross() == 0 && firstPosId != Sketcher::none) {
// close line started at root point
if (sketchgui->getSketchObject()->arePointsCoincident(-1,Sketcher::start,firstCurve,firstPosId))
Mode = STATUS_Close;
}
}
return true;
}
Expand Down Expand Up @@ -806,15 +813,15 @@ class DrawSketchHandlerLineSet: public DrawSketchHandler
std::min(startAngle,endAngle), std::max(startAngle,endAngle));
}
// issue the constraint
if (previousCurve != -1) {
if (previousPosId != Sketcher::none) {
int lastCurve = getHighestCurveIndex();
Sketcher::PointPos lastStartPosId = (SegmentMode == SEGMENT_MODE_Arc && startAngle > endAngle) ?
Sketcher::end : Sketcher::start;
Sketcher::PointPos lastEndPosId = (SegmentMode == SEGMENT_MODE_Arc && startAngle > endAngle) ?
Sketcher::start : Sketcher::end;
// in case of a tangency constraint, the coincident constraint is redundant
std::string constrType = "Coincident";
if (!suppressTransition) {
if (!suppressTransition && previousCurve != -1) {
if (TransitionMode == TRANSITION_MODE_Tangent)
constrType = "Tangent";
else if (TransitionMode == TRANSITION_MODE_Perpendicular_L ||
Expand All @@ -826,10 +833,6 @@ class DrawSketchHandlerLineSet: public DrawSketchHandler
sketchgui->getObject()->getNameInDocument(), constrType.c_str(),
previousCurve, previousPosId, lastCurve, lastStartPosId);
if (Mode == STATUS_Close) {
int firstGeoId;
Sketcher::PointPos firstPosId;
sketchgui->getSketchObject()->getGeoVertexIndex(firstVertex, firstGeoId, firstPosId);
//assert(firstCurve == firstGeoId);
// close the loop by constrain to the first curve point
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident',%i,%i,%i,%i)) ",
Expand Down Expand Up @@ -907,9 +910,9 @@ class DrawSketchHandlerLineSet: public DrawSketchHandler
bool suppressTransition;

std::vector<Base::Vector2D> EditCurve;
int firstVertex;
int firstCurve;
int previousCurve;
Sketcher::PointPos firstPosId;
Sketcher::PointPos previousPosId;
std::vector<AutoConstraint> sugConstr1, sugConstr2;

Expand Down

0 comments on commit 4d918d1

Please sign in to comment.