Core: Add getPlacementOf replacing previous getGlobalPlacement logic. (#26059)
* Core: Add getPlacementOf replacing previous getGlobalPlacement logic. * Update src/App/DocumentObject.cpp Co-authored-by: Kacper Donat <kadet1090@gmail.com> * Update DocumentObject.cpp * Fix error when called from python with targetObj == None --------- Co-authored-by: Kacper Donat <kadet1090@gmail.com>
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Matrix.h>
|
||||
#include <Base/Placement.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Writer.h>
|
||||
|
||||
@@ -1615,3 +1616,31 @@ void DocumentObject::onPropertyStatusChanged(const Property& prop, unsigned long
|
||||
getDocument()->signalChangePropertyEditor(*getDocument(), prop);
|
||||
}
|
||||
}
|
||||
|
||||
Base::Placement DocumentObject::getPlacementOf(const std::string& sub, DocumentObject* targetObj)
|
||||
{
|
||||
Base::Placement plc;
|
||||
auto* propPlacement = freecad_cast<App::PropertyPlacement*>(getPropertyByName("Placement"));
|
||||
if (propPlacement) {
|
||||
// If the object has no placement (like a Group), plc stays identity so we can proceed.
|
||||
plc = propPlacement->getValue();
|
||||
}
|
||||
|
||||
std::vector<std::string> names = Base::Tools::splitSubName(sub);
|
||||
|
||||
if (names.empty() || this == targetObj) {
|
||||
return plc;
|
||||
}
|
||||
|
||||
DocumentObject* subObj = getDocument()->getObject(names.front().c_str());
|
||||
|
||||
if (!subObj) {
|
||||
return plc;
|
||||
}
|
||||
|
||||
std::vector<std::string> newNames(names.begin() + 1, names.end());
|
||||
std::string newSub = Base::Tools::joinList(newNames, ".");
|
||||
|
||||
return plc * subObj->getPlacementOf(newSub, targetObj);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user