Sketcher: Implement related constraint command for non edges

This commit is contained in:
Karliss
2025-06-17 12:29:39 +03:00
committed by Chris Hennes
parent f6f75a6a0d
commit 732501d89d

View File

@@ -375,7 +375,7 @@ void CmdSketcherSelectConstraints::activated(int iMsg)
// get the needed lists and objects
const std::vector<std::string>& SubNames = selection[0].getSubNames();
Sketcher::SketchObject* Obj = static_cast<Sketcher::SketchObject*>(selection[0].getObject());
const std::vector<Sketcher::Constraint*>& vals = Obj->Constraints.getValues();
const std::vector<Sketcher::Constraint*>& constraints = Obj->Constraints.getValues();
std::string doc_name = Obj->getDocument()->getName();
std::string obj_name = Obj->getNameInDocument();
@@ -384,23 +384,26 @@ void CmdSketcherSelectConstraints::activated(int iMsg)
std::vector<std::string> constraintSubNames;
// go through the selected subelements
for (std::vector<std::string>::const_iterator it = SubNames.begin(); it != SubNames.end();
++it) {
// only handle edges
if (it->size() > 4 && it->substr(0, 4) == "Edge") {
int GeoId = std::atoi(it->substr(4, 4000).c_str()) - 1;
// push all the constraints
int i = 0;
for (std::vector<Sketcher::Constraint*>::const_iterator it = vals.begin();
it != vals.end();
++it, ++i) {
if ((*it)->First == GeoId || (*it)->Second == GeoId || (*it)->Third == GeoId) {
constraintSubNames.push_back(
Sketcher::PropertyConstraintList::getConstraintName(i));
}
int i = 0;
for (auto const& constraint : constraints) {
auto isRelated = [&] (const std::string& subName){
int geoId;
PointPos pointPos;
Data::IndexedName name = Obj->checkSubName(subName.c_str());
if (!Obj->geoIdFromShapeType(name, geoId, pointPos)) {
return false;
}
if (pointPos != PointPos::none) {
return constraint->involvesGeoIdAndPosId(geoId, pointPos);
} else {
return constraint->involvesGeoId(geoId);
}
};
if (std::ranges::any_of(SubNames, isRelated)) {
constraintSubNames.push_back(PropertyConstraintList::getConstraintName(i));
}
++i;
}
if (!constraintSubNames.empty())