PartDesign: Fix use of App::Planes to create sketches (#20453)
This commit is contained in:
@@ -311,6 +311,101 @@ std::vector<SelectionSingleton::SelObj> SelectionSingleton::getPickedList(const
|
||||
return temp;
|
||||
}
|
||||
|
||||
std::vector<Gui::SelectionObject> SelectionSingleton::getSelectionIn(App::DocumentObject* container,
|
||||
Base::Type typeId, bool single) const
|
||||
{
|
||||
if (!container) {
|
||||
return getSelectionEx(nullptr, typeId, ResolveMode::NoResolve, single);
|
||||
}
|
||||
|
||||
std::vector<SelectionObject> sels = getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(), ResolveMode::NoResolve, single);
|
||||
|
||||
std::vector<SelectionObject> ret;
|
||||
std::map<App::DocumentObject*, size_t> SortMap;
|
||||
|
||||
for (auto& sel : sels) {
|
||||
auto* rootObj = sel.getObject();
|
||||
App::Document* doc = rootObj->getDocument();
|
||||
std::vector<std::string> subs = sel.getSubNames();
|
||||
bool objPassed = false;
|
||||
|
||||
for (size_t i = 0; i < subs.size(); ++i) {
|
||||
auto& sub = subs[i];
|
||||
App::DocumentObject* newRootObj = nullptr;
|
||||
std::string newSub = "";
|
||||
|
||||
std::vector<std::string> names = Base::Tools::splitSubName(sub);
|
||||
|
||||
if (container == rootObj) {
|
||||
objPassed = true;
|
||||
}
|
||||
|
||||
if (rootObj->isLink()) {
|
||||
// Update doc in case its an external link.
|
||||
doc = rootObj->getLinkedObject()->getDocument();
|
||||
}
|
||||
|
||||
for (auto& name : names) {
|
||||
App::DocumentObject* obj = doc->getObject(name.c_str());
|
||||
if (!obj) { // We reached the element name (for example 'edge1')
|
||||
newSub += name;
|
||||
break;
|
||||
}
|
||||
|
||||
if (objPassed) {
|
||||
if (!newRootObj) {
|
||||
// We are the first object after the container is passed.
|
||||
newRootObj = obj;
|
||||
}
|
||||
else {
|
||||
newSub += name + ".";
|
||||
}
|
||||
}
|
||||
|
||||
if (obj == container) {
|
||||
objPassed = true;
|
||||
}
|
||||
if (obj->isLink()) {
|
||||
// Update doc in case its an external link.
|
||||
doc = obj->getLinkedObject()->getDocument();
|
||||
}
|
||||
}
|
||||
|
||||
if (newRootObj) {
|
||||
// Make sure selected object is of correct type
|
||||
auto* lastObj = newRootObj->resolve(newSub.c_str());
|
||||
if (!lastObj || !lastObj->isDerivedFrom(typeId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto it = SortMap.find(newRootObj);
|
||||
if (it != SortMap.end()) {
|
||||
// only add sub-element
|
||||
if (newSub != "") {
|
||||
ret[it->second].SubNames.emplace_back(newSub);
|
||||
ret[it->second].SelPoses.emplace_back(sel.SelPoses[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (single && !ret.empty()) {
|
||||
ret.clear();
|
||||
break;
|
||||
}
|
||||
// create a new entry
|
||||
ret.emplace_back(newRootObj);
|
||||
if (newSub != "") {
|
||||
ret.back().SubNames.emplace_back(newSub);
|
||||
ret.back().SelPoses.emplace_back(sel.SelPoses[i]);
|
||||
}
|
||||
SortMap.insert(std::make_pair(newRootObj, ret.size() - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<SelectionObject> SelectionSingleton::getSelectionEx(const char* pDocName, Base::Type typeId,
|
||||
ResolveMode resolve, bool single) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user