Move isLink and isLinkGroup from AssemblyObject to DocumentObject
This commit is contained in:
@@ -442,6 +442,12 @@ public:
|
||||
/* Return true to cause PropertyView to show linked object's property */
|
||||
virtual bool canLinkProperties() const {return true;}
|
||||
|
||||
/* Return whether this object is a link */
|
||||
virtual bool isLink() const {return false;};
|
||||
|
||||
/* Return whether this object is a link group */
|
||||
virtual bool isLinkGroup() const {return false;};
|
||||
|
||||
/* Return true to bypass duplicate label checking */
|
||||
virtual bool allowDuplicateLabel() const {return false;}
|
||||
|
||||
|
||||
@@ -308,7 +308,7 @@ Base::Placement GeoFeature::getGlobalPlacement(App::DocumentObject* targetObj,
|
||||
if (obj == targetObj) {
|
||||
return plc;
|
||||
}
|
||||
if (obj->isDerivedFrom<App::Link>()) {
|
||||
if (obj->isLink()) {
|
||||
// Update doc in case its an external link.
|
||||
doc = obj->getLinkedObject()->getDocument();
|
||||
}
|
||||
|
||||
@@ -2282,6 +2282,16 @@ bool Link::canLinkProperties() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Link::isLink() const
|
||||
{
|
||||
return ElementCount.getValue() == 0;
|
||||
}
|
||||
|
||||
bool Link::isLinkGroup() const
|
||||
{
|
||||
return ElementCount.getValue() > 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace App {
|
||||
@@ -2309,6 +2319,11 @@ bool LinkElement::canDelete() const {
|
||||
return !owner || !owner->getDocument()->getObjectByID(_LinkOwner.getValue());
|
||||
}
|
||||
|
||||
bool LinkElement::isLink() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
App::Link* LinkElement::getLinkGroup() const
|
||||
{
|
||||
std::vector<App::DocumentObject*> inList = getInList();
|
||||
|
||||
@@ -556,6 +556,10 @@ public:
|
||||
}
|
||||
|
||||
bool canLinkProperties() const override;
|
||||
|
||||
bool isLink() const override;
|
||||
|
||||
bool isLinkGroup() const override;
|
||||
};
|
||||
|
||||
using LinkPython = App::FeaturePythonT<Link>;
|
||||
@@ -600,6 +604,8 @@ public:
|
||||
_handleChangedPropertyName(reader,TypeName,PropName);
|
||||
}
|
||||
|
||||
bool isLink() const override;
|
||||
|
||||
App::Link* getLinkGroup() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -111,39 +111,6 @@ static void printPlacement(Base::Placement plc, const char* name)
|
||||
angle);
|
||||
}*/
|
||||
|
||||
static bool isLink(App::DocumentObject* obj)
|
||||
{
|
||||
if (!obj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* link = dynamic_cast<App::Link*>(obj);
|
||||
if (link) {
|
||||
return link->ElementCount.getValue() == 0;
|
||||
}
|
||||
|
||||
auto* linkEl = dynamic_cast<App::LinkElement*>(obj);
|
||||
if (linkEl) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool isLinkGroup(App::DocumentObject* obj)
|
||||
{
|
||||
if (!obj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* link = dynamic_cast<App::Link*>(obj);
|
||||
if (link) {
|
||||
return link->ElementCount.getValue() > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ================================ Assembly Object ============================
|
||||
|
||||
PROPERTY_SOURCE(Assembly::AssemblyObject, App::Part)
|
||||
@@ -1733,7 +1700,7 @@ void AssemblyObject::ensureIdentityPlacements()
|
||||
std::vector<App::DocumentObject*> group = Group.getValues();
|
||||
for (auto* obj : group) {
|
||||
// When used in assembly, link groups must have identity placements.
|
||||
if (isLinkGroup(obj)) {
|
||||
if (obj->isLinkGroup()) {
|
||||
auto* link = dynamic_cast<App::Link*>(obj);
|
||||
auto* pPlc = dynamic_cast<App::PropertyPlacement*>(obj->getPropertyByName("Placement"));
|
||||
if (!pPlc || !link) {
|
||||
@@ -2185,7 +2152,7 @@ App::DocumentObject* AssemblyObject::getObjFromRef(App::DocumentObject* obj, std
|
||||
|
||||
App::Document* doc = obj->getDocument();
|
||||
|
||||
std::vector<std::string> names = splitSubName(sub);
|
||||
std::vector<std::string> names = Base::Tools::splitSubName(sub);
|
||||
|
||||
// Lambda function to check if the typeId is a BodySubObject
|
||||
auto isBodySubObject = [](App::DocumentObject* obj) -> bool {
|
||||
@@ -2227,7 +2194,7 @@ App::DocumentObject* AssemblyObject::getObjFromRef(App::DocumentObject* obj, std
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (obj->isDerivedFrom<App::Part>() || isLinkGroup(obj)) {
|
||||
if (obj->isDerivedFrom<App::Part>() || obj->isLinkGroup()) {
|
||||
continue;
|
||||
}
|
||||
else if (obj->isDerivedFrom<PartDesign::Body>()) {
|
||||
@@ -2237,7 +2204,7 @@ App::DocumentObject* AssemblyObject::getObjFromRef(App::DocumentObject* obj, std
|
||||
// Primitive, fastener, gear, etc.
|
||||
return obj;
|
||||
}
|
||||
else if (isLink(obj)) {
|
||||
else if (obj->isLink()) {
|
||||
App::DocumentObject* linked_obj = obj->getLinkedObject();
|
||||
if (linked_obj->isDerivedFrom<PartDesign::Body>()) {
|
||||
auto* retObj = handlePartDesignBody(linked_obj, it);
|
||||
@@ -2302,7 +2269,7 @@ App::DocumentObject* AssemblyObject::getMovingPartFromRef(App::DocumentObject* o
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isLink(obj)) { // update the document if necessary for next object
|
||||
if (obj->isLink()) { // update the document if necessary for next object
|
||||
doc = obj->getLinkedObject()->getDocument();
|
||||
}
|
||||
|
||||
@@ -2319,7 +2286,7 @@ App::DocumentObject* AssemblyObject::getMovingPartFromRef(App::DocumentObject* o
|
||||
continue; // we ignore groups.
|
||||
}
|
||||
|
||||
if (isLinkGroup(obj)) {
|
||||
if (obj->isLinkGroup()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user