Move getGlobalPlacement from AssemblyObject to GeoFeature
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
|
||||
#include <App/GeoFeaturePy.h>
|
||||
|
||||
#include <Base/Tools.h>
|
||||
|
||||
#include "ComplexGeoData.h"
|
||||
#include "Document.h"
|
||||
#include "GeoFeature.h"
|
||||
@@ -270,3 +272,61 @@ GeoFeature::getHigherElements(const char *element, bool silent) const
|
||||
return {};
|
||||
return prop->getComplexData()->getHigherElements(element, silent);
|
||||
}
|
||||
|
||||
Base::Placement GeoFeature::getPlacementFromProp(App::DocumentObject* obj, const char* propName)
|
||||
{
|
||||
Base::Placement plc = Base::Placement();
|
||||
auto* propPlacement = dynamic_cast<App::PropertyPlacement*>(obj->getPropertyByName(propName));
|
||||
if (propPlacement) {
|
||||
plc = propPlacement->getValue();
|
||||
}
|
||||
return plc;
|
||||
}
|
||||
|
||||
Base::Placement GeoFeature::getGlobalPlacement(App::DocumentObject* targetObj,
|
||||
App::DocumentObject* rootObj,
|
||||
const std::string& sub)
|
||||
{
|
||||
if (!targetObj || !rootObj || sub.empty()) {
|
||||
return Base::Placement();
|
||||
}
|
||||
std::vector<std::string> names = Base::Tools::splitSubName(sub);
|
||||
|
||||
App::Document* doc = rootObj->getDocument();
|
||||
Base::Placement plc = getPlacementFromProp(rootObj, "Placement");
|
||||
|
||||
for (auto& name : names) {
|
||||
App::DocumentObject* obj = doc->getObject(name.c_str());
|
||||
if (!obj) {
|
||||
return Base::Placement();
|
||||
}
|
||||
|
||||
plc = plc * getPlacementFromProp(obj, "Placement");
|
||||
|
||||
if (obj == targetObj) {
|
||||
return plc;
|
||||
}
|
||||
if (obj->isDerivedFrom<App::Link>()) {
|
||||
// Update doc in case its an external link.
|
||||
doc = obj->getLinkedObject()->getDocument();
|
||||
}
|
||||
}
|
||||
|
||||
// If targetObj has not been found there's a problem
|
||||
return Base::Placement();
|
||||
}
|
||||
|
||||
Base::Placement GeoFeature::getGlobalPlacement(App::DocumentObject* targetObj,
|
||||
App::PropertyXLinkSub* prop)
|
||||
{
|
||||
if (!targetObj || !prop) {
|
||||
return Base::Placement();
|
||||
}
|
||||
|
||||
std::vector<std::string> subs = prop->getSubValues();
|
||||
if (subs.empty()) {
|
||||
return Base::Placement();
|
||||
}
|
||||
|
||||
return getGlobalPlacement(targetObj, prop->getValue(), subs[0]);
|
||||
}
|
||||
|
||||
@@ -179,6 +179,10 @@ public:
|
||||
/// Return the higher level element names of the given element
|
||||
virtual std::vector<Data::IndexedName> getHigherElements(const char *name, bool silent=false) const;
|
||||
|
||||
static Base::Placement getPlacementFromProp(DocumentObject* obj, const char* propName);
|
||||
static Base::Placement getGlobalPlacement(DocumentObject* targetObj, DocumentObject* rootObj, const std::string& sub);
|
||||
static Base::Placement getGlobalPlacement(DocumentObject* targetObj, PropertyXLinkSub* prop);
|
||||
|
||||
protected:
|
||||
void onChanged(const Property* prop) override;
|
||||
// void onDocumentRestored() override;
|
||||
|
||||
@@ -2078,6 +2078,7 @@ void AssemblyObject::setJointActivated(App::DocumentObject* joint, bool val)
|
||||
propActivated->setValue(val);
|
||||
}
|
||||
}
|
||||
|
||||
bool AssemblyObject::getJointActivated(App::DocumentObject* joint)
|
||||
{
|
||||
auto* propActivated = dynamic_cast<App::PropertyBool*>(joint->getPropertyByName("Activated"));
|
||||
@@ -2087,65 +2088,6 @@ bool AssemblyObject::getJointActivated(App::DocumentObject* joint)
|
||||
return false;
|
||||
}
|
||||
|
||||
Base::Placement AssemblyObject::getPlacementFromProp(App::DocumentObject* obj, const char* propName)
|
||||
{
|
||||
Base::Placement plc = Base::Placement();
|
||||
auto* propPlacement = dynamic_cast<App::PropertyPlacement*>(obj->getPropertyByName(propName));
|
||||
if (propPlacement) {
|
||||
plc = propPlacement->getValue();
|
||||
}
|
||||
return plc;
|
||||
}
|
||||
|
||||
|
||||
Base::Placement AssemblyObject::getGlobalPlacement(App::DocumentObject* targetObj,
|
||||
App::DocumentObject* rootObj,
|
||||
const std::string& sub)
|
||||
{
|
||||
if (!targetObj || !rootObj || sub == "") {
|
||||
return Base::Placement();
|
||||
}
|
||||
std::vector<std::string> names = Base::Tools::splitSubName(sub);
|
||||
|
||||
App::Document* doc = rootObj->getDocument();
|
||||
Base::Placement plc = getPlacementFromProp(rootObj, "Placement");
|
||||
|
||||
for (auto& name : names) {
|
||||
App::DocumentObject* obj = doc->getObject(name.c_str());
|
||||
if (!obj) {
|
||||
return Base::Placement();
|
||||
}
|
||||
|
||||
plc = plc * getPlacementFromProp(obj, "Placement");
|
||||
|
||||
if (obj == targetObj) {
|
||||
return plc;
|
||||
}
|
||||
if (isLink(obj)) {
|
||||
// Update doc in case its an external link.
|
||||
doc = obj->getLinkedObject()->getDocument();
|
||||
}
|
||||
}
|
||||
|
||||
// If targetObj has not been found there's a problem
|
||||
return Base::Placement();
|
||||
}
|
||||
|
||||
Base::Placement AssemblyObject::getGlobalPlacement(App::DocumentObject* targetObj,
|
||||
App::PropertyXLinkSub* prop)
|
||||
{
|
||||
if (!targetObj || !prop) {
|
||||
return Base::Placement();
|
||||
}
|
||||
|
||||
std::vector<std::string> subs = prop->getSubValues();
|
||||
if (subs.empty()) {
|
||||
return Base::Placement();
|
||||
}
|
||||
|
||||
return getGlobalPlacement(targetObj, prop->getValue(), subs[0]);
|
||||
}
|
||||
|
||||
double AssemblyObject::getJointDistance(App::DocumentObject* joint)
|
||||
{
|
||||
double distance = 0.0;
|
||||
|
||||
@@ -280,13 +280,6 @@ public:
|
||||
const char* propName);
|
||||
static std::vector<std::string> getSubAsList(App::PropertyXLinkSub* prop);
|
||||
static std::vector<std::string> getSubAsList(App::DocumentObject* joint, const char* propName);
|
||||
static Base::Placement getPlacementFromProp(App::DocumentObject* obj, const char* propName);
|
||||
|
||||
static Base::Placement getGlobalPlacement(App::DocumentObject* targetObj,
|
||||
App::DocumentObject* rootObj,
|
||||
const std::string& sub);
|
||||
static Base::Placement getGlobalPlacement(App::DocumentObject* targetObj,
|
||||
App::PropertyXLinkSub* prop);
|
||||
};
|
||||
|
||||
// using AssemblyObjectPython = App::FeaturePythonT<AssemblyObject>;
|
||||
|
||||
@@ -766,7 +766,7 @@ ViewProviderAssembly::DragMode ViewProviderAssembly::findDragMode()
|
||||
const char* plcPropName = (pName == "Reference1") ? "Placement1" : "Placement2";
|
||||
|
||||
// jcsPlc is relative to the Object
|
||||
jcsPlc = AssemblyObject::getPlacementFromProp(movingJoint, plcPropName);
|
||||
jcsPlc = App::GeoFeature::getPlacementFromProp(movingJoint, plcPropName);
|
||||
|
||||
// Make jcsGlobalPlc relative to the origin of the doc
|
||||
auto* ref =
|
||||
@@ -775,7 +775,7 @@ ViewProviderAssembly::DragMode ViewProviderAssembly::findDragMode()
|
||||
return DragMode::Translation;
|
||||
}
|
||||
auto* obj = assemblyPart->getObjFromRef(movingJoint, pName.c_str());
|
||||
Base::Placement global_plc = AssemblyObject::getGlobalPlacement(obj, ref);
|
||||
Base::Placement global_plc = App::GeoFeature::getGlobalPlacement(obj, ref);
|
||||
jcsGlobalPlc = global_plc * jcsPlc;
|
||||
|
||||
// Add downstream parts so that they move together
|
||||
@@ -922,7 +922,7 @@ void ViewProviderAssembly::initMoveDragger()
|
||||
App::DocumentObject* part = docsToMove[0].obj;
|
||||
|
||||
draggerInitPlc =
|
||||
AssemblyObject::getGlobalPlacement(part, docsToMove[0].rootObj, docsToMove[0].sub);
|
||||
App::GeoFeature::getGlobalPlacement(part, docsToMove[0].rootObj, docsToMove[0].sub);
|
||||
std::vector<App::DocumentObject*> listOfObjs;
|
||||
std::vector<App::PropertyXLinkSub*> listOfRefs;
|
||||
for (auto& movingObj : docsToMove) {
|
||||
@@ -1132,11 +1132,11 @@ ViewProviderAssembly::getCenterOfBoundingBox(const std::vector<MovingObject>& mo
|
||||
// bboxCenter does not take into account obj global placement
|
||||
Base::Placement plc(bboxCenter, Base::Rotation());
|
||||
// Change plc to be relative to the object placement.
|
||||
Base::Placement objPlc = AssemblyObject::getPlacementFromProp(movingObj.obj, "Placement");
|
||||
Base::Placement objPlc = App::GeoFeature::getPlacementFromProp(movingObj.obj, "Placement");
|
||||
plc = objPlc.inverse() * plc;
|
||||
// Change plc to be relative to the origin of the document.
|
||||
Base::Placement global_plc =
|
||||
AssemblyObject::getGlobalPlacement(movingObj.obj, movingObj.rootObj, movingObj.sub);
|
||||
App::GeoFeature::getGlobalPlacement(movingObj.obj, movingObj.rootObj, movingObj.sub);
|
||||
plc = global_plc * plc;
|
||||
bboxCenter = plc.getPosition();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user