diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 354535cb00..b64002112e 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -1250,9 +1250,17 @@ void Application::initTypes(void) App ::PropertyFont ::init(); App ::PropertyStringList ::init(); App ::PropertyLink ::init(); + App ::PropertyLinkChild ::init(); + App ::PropertyLinkGlobal ::init(); App ::PropertyLinkSub ::init(); + App ::PropertyLinkSubChild ::init(); + App ::PropertyLinkSubGlobal ::init(); App ::PropertyLinkList ::init(); + App ::PropertyLinkListChild ::init(); + App ::PropertyLinkListGlobal ::init(); App ::PropertyLinkSubList ::init(); + App ::PropertyLinkSubListChild ::init(); + App ::PropertyLinkSubListGlobal ::init(); App ::PropertyMatrix ::init(); App ::PropertyVector ::init(); App ::PropertyVectorDistance ::init(); diff --git a/src/App/GeoFeatureGroupExtension.cpp b/src/App/GeoFeatureGroupExtension.cpp index e8e90df186..062d9d1c4c 100644 --- a/src/App/GeoFeatureGroupExtension.cpp +++ b/src/App/GeoFeatureGroupExtension.cpp @@ -360,7 +360,7 @@ bool GeoFeatureGroupExtension::areLinksValid(DocumentObject* obj) { //for links with scope SubGroup we need to check if all features are part of subgroups if(group) { - result = getScopedObjectsFromLinks(obj, LinkScope::SubGroup); + result = getScopedObjectsFromLinks(obj, LinkScope::Child); auto groupExt = group->getExtensionByType(); for(auto link : result) { if(!groupExt->hasObject(link, true)) diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index 728ad59344..4e9a278e7e 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -51,6 +51,8 @@ using namespace std; //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TYPESYSTEM_SOURCE(App::PropertyLink , App::Property) +TYPESYSTEM_SOURCE(App::PropertyLinkChild , App::PropertyLink) +TYPESYSTEM_SOURCE(App::PropertyLinkGlobal , App::PropertyLink) //************************************************************************** // Construction/Destruction @@ -181,6 +183,8 @@ void PropertyLink::Paste(const Property &from) //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TYPESYSTEM_SOURCE(App::PropertyLinkList, App::PropertyLists) +TYPESYSTEM_SOURCE(App::PropertyLinkListChild , App::PropertyLinkList) +TYPESYSTEM_SOURCE(App::PropertyLinkListGlobal , App::PropertyLinkList) //************************************************************************** // Construction/Destruction @@ -373,6 +377,8 @@ unsigned int PropertyLinkList::getMemSize(void) const //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TYPESYSTEM_SOURCE(App::PropertyLinkSub , App::Property) +TYPESYSTEM_SOURCE(App::PropertyLinkSubChild , App::PropertyLinkSub) +TYPESYSTEM_SOURCE(App::PropertyLinkSubGlobal , App::PropertyLinkSub) //************************************************************************** // Construction/Destruction @@ -565,6 +571,8 @@ void PropertyLinkSub::Paste(const Property &from) //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TYPESYSTEM_SOURCE(App::PropertyLinkSubList , App::PropertyLists) +TYPESYSTEM_SOURCE(App::PropertyLinkSubListChild , App::PropertyLinkSubList) +TYPESYSTEM_SOURCE(App::PropertyLinkSubListGlobal , App::PropertyLinkSubList) //************************************************************************** // Construction/Destruction diff --git a/src/App/PropertyLinks.h b/src/App/PropertyLinks.h index 27a932a4be..efa11ed95d 100644 --- a/src/App/PropertyLinks.h +++ b/src/App/PropertyLinks.h @@ -39,21 +39,63 @@ namespace App { class DocumentObject; +/** + * @brief Defines different scopes for which a link can be valid + * The scopes defined in this enum describe the different possibilities of where a link can point to. + * Local: links are valid only within the same GeoFeatureGroup as the linkowner is in or in none. + * Child: links are valid within the same or any sub GeoFeatureGroup + * Global: all possible links are valid + */ enum class LinkScope { Local, - SubGroup, + Child, Global }; +/** + * @brief Enables scope handling for links + * This class is a base for all link properties and enables them to handle scopes of the linked objects. + * The possible scopes are defined by LinkScope enum class. The default value is Local. + * The scope of a property is not saved in the document. It is a value that needs to be fixed when + * the object holding the property is loaded. That is possible with two methods: + * 1. Set the scope value in the constructor of the link property + * 2. Use setScope to change the scope in the constructor of the link property + * + * The second option is only available in c++, not in python, as setscope is not exposed. It would + * not make sense to expose it there, as restoring python objects does not call the constructor again. + * Hence in python the only way to create a LinkProperty with different scope than local is to use a + * specialized property for that. In c++ existing properties can simply be changed via setScope in the + * objects constructor. + */ +class AppExport ScopedLink { + +public: + /** + * @brief Set the links scope + * Allows to define what kind of links are allowed. Only in the Local GeoFeatureGroup, in this and + * all Childs or to all objects within the Glocal scope. + */ + void setScope(LinkScope scope) {_pcScope = scope;}; + /** + * @brief Get the links scope + * Retreive what kind of links are allowed. Only in the Local GeoFeatureGroup, in this and + * all Childs or to all objects within the Glocal scope. + */ + LinkScope getScope() {return _pcScope;}; + +protected: + LinkScope _pcScope = LinkScope::Local; +}; + /** The general Link Property * Main Purpose of this property is to Link Objects and Feautures in a document. Like all links this * property is scope aware, meaning it does define which objects are allowed to be linked depending - * of the GeoFeatureGroup where it is in. + * of the GeoFeatureGroup where it is in. Default is Local. * - * @note Links that invalid in respect to the scope this property is set to are not rejected. They - * are only detected to be invalid and prevent the feature from recomputing. + * @note Links that are invalid in respect to the scope of this property is set to are not rejected. + * They are only detected to be invalid and prevent the feature from recomputing. */ -class AppExport PropertyLink : public Property +class AppExport PropertyLink : public Property, public ScopedLink { TYPESYSTEM_HEADER(); @@ -103,26 +145,30 @@ public: } virtual const char* getEditorName(void) const { return "Gui::PropertyEditor::PropertyLinkItem"; } - - /** - * @brief Set the links scope - * Allows to define what kind of links are allowed. Only in the Local GeoFeatureGroup, in this an - * all SubGroups or to all object within the Glocal scope. - */ - void setScope(LinkScope scope) {_pcScope = scope;}; - /** - * @brief Get the links scope - * Retreive what kind of links are allowed. Only in the Local GeoFeatureGroup, in this an - * all SubGroups or to all object within the Glocal scope. - */ - LinkScope getScope() {return _pcScope;}; protected: App::DocumentObject *_pcLink; - LinkScope _pcScope = LinkScope::Local; }; -class AppExport PropertyLinkList : public PropertyLists +/** The general Link Property with Child scope + */ +class AppExport PropertyLinkChild : public PropertyLink +{ + TYPESYSTEM_HEADER(); +public: + PropertyLinkChild() {_pcScope = LinkScope::Child;}; +}; + +/** The general Link Property with Global scope + */ +class AppExport PropertyLinkGlobal : public PropertyLink +{ + TYPESYSTEM_HEADER(); +public: + PropertyLinkGlobal() {_pcScope = LinkScope::Global;}; +}; + +class AppExport PropertyLinkList : public PropertyLists, public ScopedLink { TYPESYSTEM_HEADER(); @@ -172,22 +218,26 @@ public: virtual unsigned int getMemSize(void) const; - /** - * @brief Set the links scope - * Allows to define what kind of links are allowed. Only in the Local GeoFeatureGroup, in this an - * all SubGroups or to all object within the Glocal scope. - */ - void setScope(LinkScope scope) {_pcScope = scope;}; - /** - * @brief Get the links scope - * Retreive what kind of links are allowed. Only in the Local GeoFeatureGroup, in this an - * all SubGroups or to all object within the Glocal scope. - */ - LinkScope getScope() {return _pcScope;}; - private: std::vector _lValueList; - LinkScope _pcScope = LinkScope::Local; +}; + +/** The general Link Property with Child scope + */ +class AppExport PropertyLinkListChild : public PropertyLinkList +{ + TYPESYSTEM_HEADER(); +public: + PropertyLinkListChild() {_pcScope = LinkScope::Child;}; +}; + +/** The general Link Property with Global scope + */ +class AppExport PropertyLinkListGlobal : public PropertyLinkList +{ + TYPESYSTEM_HEADER(); +public: + PropertyLinkListGlobal() {_pcScope = LinkScope::Global;}; }; /** the Link Poperty with sub elements @@ -196,7 +246,7 @@ private: * are stored as names, which can be resolved by the * ComplexGeoDataType interface to concrete sub objects. */ -class AppExport PropertyLinkSub: public Property +class AppExport PropertyLinkSub: public Property, public ScopedLink { TYPESYSTEM_HEADER(); @@ -250,27 +300,31 @@ public: virtual unsigned int getMemSize (void) const{ return sizeof(App::DocumentObject *); } - - /** - * @brief Set the links scope - * Allows to define what kind of links are allowed. Only in the Local GeoFeatureGroup, in this an - * all SubGroups or to all object within the Glocal scope. - */ - void setScope(LinkScope scope) {_pcScope = scope;}; - /** - * @brief Get the links scope - * Retreive what kind of links are allowed. Only in the Local GeoFeatureGroup, in this an - * all SubGroups or to all object within the Glocal scope. - */ - LinkScope getScope() {return _pcScope;}; protected: App::DocumentObject* _pcLinkSub; std::vector _cSubList; - LinkScope _pcScope = LinkScope::Local; }; -class AppExport PropertyLinkSubList: public PropertyLists +/** The general Link Property with Child scope + */ +class AppExport PropertyLinkSubChild : public PropertyLinkSub +{ + TYPESYSTEM_HEADER(); +public: + PropertyLinkSubChild() {_pcScope = LinkScope::Child;}; +}; + +/** The general Link Property with Global scope + */ +class AppExport PropertyLinkSubGlobal : public PropertyLinkSub +{ + TYPESYSTEM_HEADER(); +public: + PropertyLinkSubGlobal() {_pcScope = LinkScope::Global;}; +}; + +class AppExport PropertyLinkSubList: public PropertyLists, public ScopedLink { TYPESYSTEM_HEADER(); @@ -335,25 +389,29 @@ public: virtual void Paste(const Property &from); virtual unsigned int getMemSize (void) const; - - /** - * @brief Set the links scope - * Allows to define what kind of links are allowed. Only in the Local GeoFeatureGroup, in this an - * all SubGroups or to all object within the Glocal scope. - */ - void setScope(LinkScope scope) {_pcScope = scope;}; - /** - * @brief Get the links scope - * Retreive what kind of links are allowed. Only in the Local GeoFeatureGroup, in this an - * all SubGroups or to all object within the Glocal scope. - */ - LinkScope getScope() {return _pcScope;}; private: //FIXME: Do not make two independent lists because this will lead to some inconsistencies! std::vector _lValueList; std::vector _lSubList; - LinkScope _pcScope = LinkScope::Local; +}; + +/** The general Link Property with Child scope + */ +class AppExport PropertyLinkSubListChild : public PropertyLinkSubList +{ + TYPESYSTEM_HEADER(); +public: + PropertyLinkSubListChild() {_pcScope = LinkScope::Child;}; +}; + +/** The general Link Property with Global scope + */ +class AppExport PropertyLinkSubListGlobal : public PropertyLinkSubList +{ + TYPESYSTEM_HEADER(); +public: + PropertyLinkSubListGlobal() {_pcScope = LinkScope::Global;}; }; } // namespace App