Sketcher: fix an issue with autoconstraints and improve implementation
This commit is contained in:
parent
beb4fe82b4
commit
227cb0ebc8
|
@ -1160,7 +1160,8 @@ public:
|
||||||
setPositionText(onSketchPos, text);
|
setPositionText(onSketchPos, text);
|
||||||
|
|
||||||
sketchgui->drawEdit(EditCurve);
|
sketchgui->drawEdit(EditCurve);
|
||||||
if (seekAutoConstraint(sugConstr2, onSketchPos, Base::Vector2D(0.f,0.f), CURVE)) {
|
if (seekAutoConstraint(sugConstr2, onSketchPos, Base::Vector2D(0.f,0.f),
|
||||||
|
AutoConstraint::CURVE)) {
|
||||||
renderSuggestConstraintsCursor(sugConstr2);
|
renderSuggestConstraintsCursor(sugConstr2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,8 @@ void DrawSketchHandler::unsetCursor(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint> &suggestedConstraints,
|
int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint> &suggestedConstraints,
|
||||||
const Base::Vector2D& Pos, const Base::Vector2D& Dir, Type type)
|
const Base::Vector2D& Pos, const Base::Vector2D& Dir,
|
||||||
|
AutoConstraint::TargetType type)
|
||||||
{
|
{
|
||||||
suggestedConstraints.clear();
|
suggestedConstraints.clear();
|
||||||
|
|
||||||
|
@ -138,31 +139,31 @@ int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint> &suggested
|
||||||
return 0; // If Autoconstraints property is not set quit
|
return 0; // If Autoconstraints property is not set quit
|
||||||
|
|
||||||
// Get Preselection
|
// Get Preselection
|
||||||
|
int preSelPnt = sketchgui->getPreselectPoint();
|
||||||
|
int preSelCrv = sketchgui->getPreselectCurve();
|
||||||
|
int GeoId = Constraint::GeoUndef;
|
||||||
|
Sketcher::PointPos PosId = Sketcher::none;
|
||||||
|
if (preSelPnt != -1)
|
||||||
|
sketchgui->getSketchObject()->getGeoVertexIndex(preSelPnt, GeoId, PosId);
|
||||||
|
else if (preSelCrv != -1)
|
||||||
|
GeoId = preSelCrv;
|
||||||
|
|
||||||
// Currently only considers objects in current Sketcher
|
// Currently only considers objects in current Sketcher
|
||||||
if (type == VERTEX && sketchgui->getPreselectPoint() != -1) {
|
AutoConstraint constr;
|
||||||
AutoConstraint coincident;
|
constr.Type = Sketcher::None;
|
||||||
coincident.Type = Sketcher::Coincident;
|
constr.GeoId = GeoId;
|
||||||
coincident.Index = sketchgui->getPreselectPoint();
|
constr.PosId = PosId;
|
||||||
suggestedConstraints.push_back(coincident);
|
if (type == AutoConstraint::VERTEX && preSelPnt != -1)
|
||||||
}
|
constr.Type = Sketcher::Coincident;
|
||||||
else if (type == CURVE && sketchgui->getPreselectPoint() != -1) {
|
else if (type == AutoConstraint::CURVE && preSelPnt != -1)
|
||||||
AutoConstraint pointOnObject;
|
constr.Type = Sketcher::PointOnObject;
|
||||||
pointOnObject.Type = Sketcher::PointOnObject;
|
else if (type == AutoConstraint::VERTEX && preSelCrv != -1)
|
||||||
pointOnObject.Index = sketchgui->getPreselectPoint();
|
constr.Type = Sketcher::PointOnObject;
|
||||||
suggestedConstraints.push_back(pointOnObject);
|
else if (type == AutoConstraint::CURVE && preSelCrv != -1)
|
||||||
}
|
constr.Type = Sketcher::Tangent;
|
||||||
else if (type == VERTEX && sketchgui->getPreselectCurve() != -1) {
|
|
||||||
AutoConstraint pointOnObject;
|
if (constr.Type != Sketcher::None)
|
||||||
pointOnObject.Type = Sketcher::PointOnObject;
|
suggestedConstraints.push_back(constr);
|
||||||
pointOnObject.Index = sketchgui->getPreselectCurve();
|
|
||||||
suggestedConstraints.push_back(pointOnObject);
|
|
||||||
}
|
|
||||||
else if (type == CURVE && sketchgui->getPreselectCurve() != -1) {
|
|
||||||
AutoConstraint tangent;
|
|
||||||
tangent.Type = Sketcher::Tangent;
|
|
||||||
tangent.Index = sketchgui->getPreselectCurve();
|
|
||||||
suggestedConstraints.push_back(tangent);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Dir.Length() < 1)
|
if (Dir.Length() < 1)
|
||||||
// Direction not set so return;
|
// Direction not set so return;
|
||||||
|
@ -174,21 +175,19 @@ int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint> &suggested
|
||||||
const double angleDev = 2;
|
const double angleDev = 2;
|
||||||
const double angleDevRad = angleDev * M_PI / 180.;
|
const double angleDevRad = angleDev * M_PI / 180.;
|
||||||
|
|
||||||
|
constr.Type = Sketcher::None;
|
||||||
|
constr.GeoId = Constraint::GeoUndef;
|
||||||
|
constr.PosId = Sketcher::none;
|
||||||
double angle = std::abs(atan2(Dir.fY, Dir.fX));
|
double angle = std::abs(atan2(Dir.fY, Dir.fX));
|
||||||
if (angle < angleDevRad || (M_PI - angle) < angleDevRad ) {
|
if (angle < angleDevRad || (M_PI - angle) < angleDevRad )
|
||||||
// Suggest horizontal constraint
|
// Suggest horizontal constraint
|
||||||
AutoConstraint horConstr;
|
constr.Type = Sketcher::Horizontal;
|
||||||
horConstr.Index = -1;
|
else if (std::abs(angle - M_PI_2) < angleDevRad)
|
||||||
horConstr.Type = Horizontal;
|
|
||||||
suggestedConstraints.push_back(horConstr);
|
|
||||||
}
|
|
||||||
else if (std::abs(angle - M_PI_2) < angleDevRad) {
|
|
||||||
// Suggest vertical constraint
|
// Suggest vertical constraint
|
||||||
AutoConstraint vertConstr;
|
constr.Type = Sketcher::Vertical;
|
||||||
vertConstr.Index = -1;
|
|
||||||
vertConstr.Type = Vertical;
|
if (constr.Type != Sketcher::None)
|
||||||
suggestedConstraints.push_back(vertConstr);
|
suggestedConstraints.push_back(constr);
|
||||||
}
|
|
||||||
|
|
||||||
// Find if there are tangent constraints (currently arcs and circles)
|
// Find if there are tangent constraints (currently arcs and circles)
|
||||||
// FIXME needs to consider when zooming out?
|
// FIXME needs to consider when zooming out?
|
||||||
|
@ -257,10 +256,10 @@ int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint> &suggested
|
||||||
if (tangId > getHighestCurveIndex()) // external Geometry
|
if (tangId > getHighestCurveIndex()) // external Geometry
|
||||||
tangId = getHighestCurveIndex() - tangId;
|
tangId = getHighestCurveIndex() - tangId;
|
||||||
// Suggest vertical constraint
|
// Suggest vertical constraint
|
||||||
AutoConstraint tangConstr;
|
constr.Type = Tangent;
|
||||||
tangConstr.Index = tangId;
|
constr.GeoId = tangId;
|
||||||
tangConstr.Type = Tangent;
|
constr.PosId = Sketcher::none;
|
||||||
suggestedConstraints.push_back(tangConstr);
|
suggestedConstraints.push_back(constr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return suggestedConstraints.size();
|
return suggestedConstraints.size();
|
||||||
|
@ -285,26 +284,23 @@ void DrawSketchHandler::createAutoConstraints(const std::vector<AutoConstraint>
|
||||||
if (posId1 == Sketcher::none)
|
if (posId1 == Sketcher::none)
|
||||||
continue;
|
continue;
|
||||||
// If the auto constraint has a point create a coincident otherwise it is an edge on a point
|
// If the auto constraint has a point create a coincident otherwise it is an edge on a point
|
||||||
Sketcher::PointPos posId2;
|
|
||||||
int geoId2;
|
|
||||||
sketchgui->getSketchObject()->getGeoVertexIndex(it->Index, geoId2, posId2);
|
|
||||||
|
|
||||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident',%i,%i,%i,%i)) "
|
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident',%i,%i,%i,%i)) "
|
||||||
,sketchgui->getObject()->getNameInDocument()
|
,sketchgui->getObject()->getNameInDocument()
|
||||||
,geoId1, posId1, geoId2, posId2
|
,geoId1, posId1, it->GeoId, it->PosId
|
||||||
);
|
);
|
||||||
} break;
|
} break;
|
||||||
case Sketcher::PointOnObject: {
|
case Sketcher::PointOnObject: {
|
||||||
int index = it->Index;
|
int geoId2 = it->GeoId;
|
||||||
|
Sketcher::PointPos posId2 = it->PosId;
|
||||||
if (posId1 == Sketcher::none) {
|
if (posId1 == Sketcher::none) {
|
||||||
// Auto constraining an edge so swap parameters
|
// Auto constraining an edge so swap parameters
|
||||||
index = geoId1;
|
std::swap(geoId1,geoId2);
|
||||||
sketchgui->getSketchObject()->getGeoVertexIndex(it->Index, geoId1, posId1);
|
std::swap(posId1,posId2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%i,%i,%i)) "
|
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%i,%i,%i)) "
|
||||||
,sketchgui->getObject()->getNameInDocument()
|
,sketchgui->getObject()->getNameInDocument()
|
||||||
,geoId1, posId1, index
|
,geoId1, posId1, geoId2
|
||||||
);
|
);
|
||||||
} break;
|
} break;
|
||||||
case Sketcher::Horizontal: {
|
case Sketcher::Horizontal: {
|
||||||
|
@ -322,7 +318,7 @@ void DrawSketchHandler::createAutoConstraints(const std::vector<AutoConstraint>
|
||||||
case Sketcher::Tangent: {
|
case Sketcher::Tangent: {
|
||||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Tangent',%i, %i)) "
|
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Tangent',%i, %i)) "
|
||||||
,sketchgui->getObject()->getNameInDocument()
|
,sketchgui->getObject()->getNameInDocument()
|
||||||
,geoId1, it->Index
|
,geoId1, it->GeoId
|
||||||
);
|
);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,14 +47,14 @@ class ViewProviderSketch;
|
||||||
// A Simple data type to hold basic information for suggested constraints
|
// A Simple data type to hold basic information for suggested constraints
|
||||||
struct AutoConstraint
|
struct AutoConstraint
|
||||||
{
|
{
|
||||||
Sketcher::ConstraintType Type;
|
enum TargetType
|
||||||
int Index;
|
{
|
||||||
};
|
|
||||||
|
|
||||||
enum Type
|
|
||||||
{
|
|
||||||
VERTEX,
|
VERTEX,
|
||||||
CURVE
|
CURVE
|
||||||
|
};
|
||||||
|
Sketcher::ConstraintType Type;
|
||||||
|
int GeoId;
|
||||||
|
Sketcher::PointPos PosId;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Handler to create new sketch geometry
|
/** Handler to create new sketch geometry
|
||||||
|
@ -84,7 +84,8 @@ public:
|
||||||
int getHighestCurveIndex(void);
|
int getHighestCurveIndex(void);
|
||||||
|
|
||||||
int seekAutoConstraint(std::vector<AutoConstraint> &suggestedConstraints,
|
int seekAutoConstraint(std::vector<AutoConstraint> &suggestedConstraints,
|
||||||
const Base::Vector2D &Pos, const Base::Vector2D &Dir, Type selType = VERTEX);
|
const Base::Vector2D &Pos, const Base::Vector2D &Dir,
|
||||||
|
AutoConstraint::TargetType type = AutoConstraint::VERTEX);
|
||||||
void createAutoConstraints(const std::vector<AutoConstraint> &autoConstrs,
|
void createAutoConstraints(const std::vector<AutoConstraint> &autoConstrs,
|
||||||
int geoId, Sketcher::PointPos pointPos=Sketcher::none);
|
int geoId, Sketcher::PointPos pointPos=Sketcher::none);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user