Sketcher: allow mass selection for Point-on-object constraint
This commit is contained in:
parent
605e8cd72c
commit
24797fb65e
|
@ -396,6 +396,11 @@ void SketcherGui::makeTangentToArcOfEllipseviaNewPoint(const Sketcher::SketchObj
|
||||||
|
|
||||||
namespace SketcherGui {
|
namespace SketcherGui {
|
||||||
|
|
||||||
|
struct SelIdPair{
|
||||||
|
int GeoId;
|
||||||
|
Sketcher::PointPos PosId;
|
||||||
|
};
|
||||||
|
|
||||||
struct SketchSelection{
|
struct SketchSelection{
|
||||||
enum GeoType {
|
enum GeoType {
|
||||||
Point,
|
Point,
|
||||||
|
@ -1011,50 +1016,47 @@ void CmdSketcherConstrainPointOnObject::activated(int iMsg)
|
||||||
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
||||||
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
|
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
|
||||||
|
|
||||||
if (SubNames.size() < 1 || SubNames.size() > 2) {
|
//count curves and points
|
||||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
std::vector<SelIdPair> points;
|
||||||
QObject::tr("Select exactly one point and one object from the sketch."));
|
std::vector<SelIdPair> curves;
|
||||||
return;
|
for (int i = 0 ; i < SubNames.size() ; i++){
|
||||||
|
SelIdPair id;
|
||||||
|
getIdsFromName(SubNames[i], Obj, id.GeoId, id.PosId);
|
||||||
|
if (isEdge(id.GeoId, id.PosId))
|
||||||
|
curves.push_back(id);
|
||||||
|
if (isVertex(id.GeoId, id.PosId))
|
||||||
|
points.push_back(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GeoId1, GeoId2=Constraint::GeoUndef;
|
if (points.size() == 1 && curves.size() >= 1
|
||||||
Sketcher::PointPos PosId1, PosId2=Sketcher::none;
|
|| points.size() >= 1 && curves.size() == 1) {
|
||||||
getIdsFromName(SubNames[0], Obj, GeoId1, PosId1);
|
|
||||||
if (SubNames.size() == 2)
|
|
||||||
getIdsFromName(SubNames[1], Obj, GeoId2, PosId2);
|
|
||||||
|
|
||||||
if (checkBothExternal(GeoId1, GeoId2))
|
openCommand("add point on object constraint");
|
||||||
return;
|
int cnt = 0;
|
||||||
|
for (int iPnt = 0 ; iPnt < points.size() ; iPnt++)
|
||||||
if ((isVertex(GeoId1,PosId1) && isEdge(GeoId2,PosId2)) ||
|
for (int iCrv = 0 ; iCrv < curves.size() ; iCrv++){
|
||||||
(isEdge(GeoId1,PosId1) && isVertex(GeoId2,PosId2))) {
|
if (checkBothExternal(points[iPnt].GeoId, curves[iCrv].GeoId))
|
||||||
if (isVertex(GeoId2,PosId2)) {
|
continue;
|
||||||
std::swap(GeoId1,GeoId2);
|
if (points[iPnt].GeoId == curves[iCrv].GeoId)
|
||||||
std::swap(PosId1,PosId2);
|
continue; //constraining a point of an element onto the element is a bad idea...
|
||||||
}
|
cnt++;
|
||||||
|
|
||||||
const Part::Geometry *geom = Obj->getGeometry(GeoId2);
|
|
||||||
|
|
||||||
// Currently only accepts line segments and circles
|
|
||||||
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId() ||
|
|
||||||
geom->getTypeId() == Part::GeomCircle::getClassTypeId() ||
|
|
||||||
geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() ||
|
|
||||||
geom->getTypeId() == Part::GeomEllipse::getClassTypeId() ||
|
|
||||||
geom->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() ) {
|
|
||||||
|
|
||||||
openCommand("add point on object constraint");
|
|
||||||
Gui::Command::doCommand(
|
Gui::Command::doCommand(
|
||||||
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ",
|
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ",
|
||||||
selection[0].getFeatName(),GeoId1,PosId1,GeoId2);
|
selection[0].getFeatName(),points[iPnt].GeoId, points[iPnt].PosId, curves[iCrv].GeoId);
|
||||||
commitCommand();
|
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (cnt) {
|
||||||
|
commitCommand();
|
||||||
|
getSelection().clearSelection();
|
||||||
|
} else {
|
||||||
|
abortCommand();
|
||||||
|
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||||
|
QObject::tr("None of the selected points were constrained onto the respective curves, either because they are parts of the same element, or because they are both external geometry."));
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||||
QObject::tr("Select exactly one point and one object from the sketch."));
|
QObject::tr("Select either one point and several curves, or one curve and several points. You have selected %1 curves and %2 points.").arg(curves.size()).arg(points.size()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user