App: add New APIs for future Link function
DocumentObject: * getSubObject(): the most important API for Link to work with hierarchies. The function is a inspired from and replaces the getPySubObjects(). It returns a child object following a dot separated subname reference, and can optionally return accumulated transformation, and/or a python object of the refered sub-object/element. The default implementation here is to look for link type property, and search for the referenced object. This patch also include other specialized implementation of this API, such as (GeoFeature)GroupExtension (through extensionGetSubObject()), PartDesign::Body, and so on. A link type object is expected to call the linked object's getSubObject() for resolving. * getSubObjectList(): helper function to return a list of object referenced in the given subname. * getSubObjects(): return a list of subname references of all children objects. The purpose of this function is similar to ViewProvider::claimChildren(). Container type object is expected to implement this function. The reason it returns subname references instead of just object is to allow the container to skip hierarchies. For example, the Assembly3 container uses this to skip the constraint and element group. * getLinkedObject(), obtain the linked object, and optionally with the accumulated transformation. It is expected to return a linked object or the object itself if it is not a link. In case there are multiple levels of linking involved, this function allows the caller to retrieve the linked object recursively. * hasChildElement(), set/isElementVisible(), controls the children visibility for a group type object. Because the child object may be claimed by other objects, it is essential to have independent control of children visibilities. These APIs are designed to abstract how group manages the child visibility. For performance reason, these function are meant to control only the immediate child object. * resolve(), helper function to parse subname reference and resolve the final object, and optionally the immediate parent of the final object, the final object reference name (for calling `set/isElementVisible()`), and the subname reference if there is one. * touch(), add optional argument 'noRecompute' for better backward compatibility with the NoRecompute flag. By default, touch() causes recompute unless noRecompute is true * signalChanged/signalBeforeChange, two new signal for tracking changes of a specific object. * getViewProviderNameOverride(), return a string of the view provider type of this object. This allows Python class to override the view provider of an object. This feature will be used by ViewProviderLink which is designed to work with any object that has LinkBaseExtension. * canLinkProperties(), will be used by Gui::PropertyView to display linked object properties together with the object's own properties. * redirectSubname(), will be used by Gui::Tree to allow an object to redirect selection to some other object when (pre)selected in the tree view. * Visibility, new property serve as the same purpose as view provider property of the same name. It is added here so that App namespace code can check for visibility without Gui module. This is useful, for example, when constructing a compound shape of a container that respects the children visibility. * (has)hasHiddenMarker(), return or check for a special sub-element name used as marker for overriding sub-object visibility. Will be used by Gui::ViewProvider, it is put here for the same reason as adding Visibility property. * getID(), return object internal identifier. Each object is now assigned an integer identifier that is unique within its containing document. Document: * ShowHidden, new property to tell tree view whether to show hidden object items. * signalTouchedObject, new signal triggered when manually touch an object when calling its touch() function * getObjectByID(), get object by its identifier * addObject() is modified to allow overriding view provider * has/getLinksTo(), helper function to obtain links to a given object. Application: * checkLinkDepth(), helper function to check recursive depth for link traversal. The depth is checked against the total object count of all opened documents. The count (_objCount) is internally updated whenever object is added or removed. * has/getLinksTo(), same as Document::has/getLinksTo() but return links from all opened documents. GroupExtension/OriginGroupExtension/DatumFeature/DatumCS/Part::Feature: implement sepcialized getSubObject/getSubObjects().
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include "Origin.h"
|
||||
#include "OriginGroupExtension.h"
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Tools.h>
|
||||
//#include "GeoFeatureGroupPy.h"
|
||||
//#include "FeaturePythonPyImp.h"
|
||||
|
||||
@@ -100,11 +101,9 @@ DocumentObject* GeoFeatureGroupExtension::getGroupOfObject(const DocumentObject*
|
||||
//There is a chance that a derived geofeaturegroup links with a local link and hence is not
|
||||
//the parent group even though it links to the object. We use hasObject as one and only truth
|
||||
//if it has the object within the group
|
||||
if(inObj->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId()) &&
|
||||
inObj->getExtensionByType<GeoFeatureGroupExtension>()->hasObject(obj)) {
|
||||
|
||||
auto group = inObj->getExtensionByType<GeoFeatureGroupExtension>(true);
|
||||
if(group && group->hasObject(obj))
|
||||
return inObj;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
@@ -124,10 +123,9 @@ Base::Placement GeoFeatureGroupExtension::recursiveGroupPlacement(GeoFeatureGrou
|
||||
|
||||
auto inList = group->getExtendedObject()->getInList();
|
||||
for(auto* link : inList) {
|
||||
if(link->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId())){
|
||||
if (link->getExtensionByType<GeoFeatureGroupExtension>()->hasObject(group->getExtendedObject()))
|
||||
return recursiveGroupPlacement(link->getExtensionByType<GeoFeatureGroupExtension>()) * group->placement().getValue();
|
||||
}
|
||||
auto parent = link->getExtensionByType<GeoFeatureGroupExtension>(true);
|
||||
if(parent && parent->hasObject(group->getExtendedObject()))
|
||||
return recursiveGroupPlacement(parent) * group->placement().getValue();
|
||||
}
|
||||
|
||||
return group->placement().getValue();
|
||||
@@ -205,9 +203,10 @@ void GeoFeatureGroupExtension::extensionOnChanged(const Property* p) {
|
||||
//would return anyone of it and hence it is possible that we miss an error. We need a custom check
|
||||
auto list = obj->getInList();
|
||||
for (auto in : list) {
|
||||
if(in->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId()) && //is GeoFeatureGroup?
|
||||
in != getExtendedObject() && //is a different one?
|
||||
in->getExtensionByType<App::GeoFeatureGroupExtension>()->hasObject(obj)) { //is not a non-grouping link?
|
||||
if(in == getExtendedObject())
|
||||
continue;
|
||||
auto parent = in->getExtensionByType<GeoFeatureGroupExtension>(true);
|
||||
if(parent && parent->hasObject(obj)) {
|
||||
error = true;
|
||||
corrected.erase(std::remove(corrected.begin(), corrected.end(), obj), corrected.end());
|
||||
}
|
||||
@@ -285,8 +284,6 @@ std::vector< DocumentObject* > GeoFeatureGroupExtension::getScopedObjectsFromLin
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GeoFeatureGroupExtension::getCSOutList(const App::DocumentObject* obj,
|
||||
std::vector< DocumentObject* >& vec) {
|
||||
|
||||
@@ -373,6 +370,59 @@ void GeoFeatureGroupExtension::recursiveCSRelevantLinks(const DocumentObject* ob
|
||||
}
|
||||
}
|
||||
|
||||
bool GeoFeatureGroupExtension::extensionGetSubObject(DocumentObject *&ret, const char *subname,
|
||||
PyObject **pyObj, Base::Matrix4D *mat, bool transform, int depth) const
|
||||
{
|
||||
ret = 0;
|
||||
const char *dot;
|
||||
if(!subname || *subname==0) {
|
||||
auto obj = dynamic_cast<const DocumentObject*>(getExtendedContainer());
|
||||
ret = const_cast<DocumentObject*>(obj);
|
||||
if(mat && transform)
|
||||
*mat *= const_cast<GeoFeatureGroupExtension*>(this)->placement().getValue().toMatrix();
|
||||
}else if((dot=strchr(subname,'.'))) {
|
||||
if(subname[0]!='$')
|
||||
ret = Group.find(std::string(subname,dot));
|
||||
else{
|
||||
std::string name = std::string(subname+1,dot);
|
||||
for(auto child : Group.getValues()) {
|
||||
if(name == child->Label.getStrValue()){
|
||||
ret = child;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(ret) {
|
||||
if(dot) ++dot;
|
||||
if(dot && *dot && !ret->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId())) {
|
||||
// Consider this
|
||||
// Body
|
||||
// | -- Pad
|
||||
// | -- Sketch
|
||||
//
|
||||
// Suppose we want to getSubObject(Body,"Pad.Sketch.")
|
||||
// Because of the special property of geo feature group, both
|
||||
// Pad and Sketch are children of Body, so we can't call
|
||||
// getSubObject(Pad,"Sketch.") as this will transform Sketch
|
||||
// using Pad's placement.
|
||||
//
|
||||
const char *next = strchr(dot,'.');
|
||||
if(next) {
|
||||
App::DocumentObject *nret=0;
|
||||
extensionGetSubObject(nret,dot,pyObj,mat,transform,depth+1);
|
||||
if(nret) {
|
||||
ret = nret;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(mat && transform)
|
||||
*mat *= const_cast<GeoFeatureGroupExtension*>(this)->placement().getValue().toMatrix();
|
||||
ret = ret->getSubObject(dot?dot:"",pyObj,mat,true,depth+1);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeoFeatureGroupExtension::areLinksValid(const DocumentObject* obj) {
|
||||
|
||||
@@ -448,6 +498,14 @@ void GeoFeatureGroupExtension::getInvalidLinkObjects(const DocumentObject* obj,
|
||||
}
|
||||
}
|
||||
|
||||
bool GeoFeatureGroupExtension::extensionGetSubObjects(std::vector<std::string> &ret, int) const {
|
||||
for(auto obj : Group.getValues()) {
|
||||
if(obj && obj->getNameInDocument() && !obj->testStatus(ObjectStatus::GeoExcluded))
|
||||
ret.push_back(std::string(obj->getNameInDocument())+'.');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Python feature ---------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user