Debian Codegraph @

src/App/PropertyLinks.h

raw
1 /***************************************************************************
2 * Copyright (c) 2002 Jürgen Riegel <[email protected]> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #ifndef APP_PROPERTYLINKS_H
25 #define APP_PROPERTYLINKS_H
26
27 #include <list>
28 #include <map>
29 #include <string>
30 #include <vector>
31 #include <unordered_set>
32 #include <unordered_map>
33
34 #include "Property.h"
35
36 namespace Base
37 {
38 class Writer;
39 }
40
41 namespace App
42 {
43 class DocumentObject;
44 class Document;
45 class GeoFeature;
46 class SubObjectT;
47
48 class DocInfo;
49 using DocInfoPtr = std::shared_ptr<DocInfo>;
50
51 class PropertyXLink;
52
53 /**
54 * @brief Defines different scopes for which a link can be valid
55 * The scopes defined in this enum describe the different possibilities of where a link can point
56 * to. Local: links are valid only within the same GeoFeatureGroup as the linkowner is in or in
57 * none. Child: links are valid within the same or any sub GeoFeatureGroup Global: all possible
58 * links are valid Hidden: links are not included in dependency calculation
59 */
60 enum class LinkScope
61 {
62 Local,
63 Child,
64 Global,
65 Hidden,
66 };
67
68 /**
69 * @brief Enables scope handling for links
70 * This class is a base for all link properties and enables them to handle scopes of the linked
71 * objects. The possible scopes are defined by LinkScope enum class. The default value is Local. The
72 * scope of a property is not saved in the document. It is a value that needs to be fixed when the
73 * object holding the property is loaded. That is possible with two methods:
74 * 1. Set the scope value in the constructor of the link property
75 * 2. Use setScope to change the scope in the constructor of the link property
76 *
77 * The second option is only available in c++, not in python, as setscope is not exposed. It would
78 * not make sense to expose it there, as restoring python objects does not call the constructor
79 * again. Hence in python the only way to create a LinkProperty with different scope than local is
80 * to use a specialized property for that. In c++ existing properties can simply be changed via
81 * setScope in the objects constructor.
82 */
83 class AppExport ScopedLink
84 {
85
86 public:
87 /**
88 * @brief Set the links scope
89 * Allows to define what kind of links are allowed. Only in the Local GeoFeatureGroup, in this
90 * and all Childs or to all objects within the Glocal scope.
91 */
92 void setScope(LinkScope scope)
93 {
94 _pcScope = scope;
95 }
96 /**
97 * @brief Get the links scope
98 * Retrieve what kind of links are allowed. Only in the Local GeoFeatureGroup, in this and
99 * all Childs or to all objects within the Glocal scope.
100 */
101 LinkScope getScope() const
102 {
103 return _pcScope;
104 }
105
106 protected:
107 LinkScope _pcScope = LinkScope::Local;
108 };
109
110 /// Parent class of all link type properties
111 class AppExport PropertyLinkBase: public Property, public ScopedLink
112 {
113 TYPESYSTEM_HEADER_WITH_OVERRIDE();
114
115 public:
116 using ShadowSub = ElementNamePair;
117
118 PropertyLinkBase();
119 ~PropertyLinkBase() override;
120
121 friend class DocInfo;
122
123 /** Link type property interface APIs
124 * These APIs are moved here so that any type of property can have the
125 * property link behavior, e.g. the PropertyExpressionEngine
126 */
127 //@{
128
129 /** Called to update the element reference of this link property
130 *
131 * @sa _updateElementReference()
132 */
133 virtual void
134 updateElementReference(App::DocumentObject* feature, bool reverse = false, bool notify = false)
135 {
136 (void)feature;
137 (void)reverse;
138 (void)notify;
139 }
140
141 /// Clear internal element reference registration
142 void unregisterElementReference();
143
144 /** Register label reference for future object relabel update
145 *
146 * @param labels: labels to be registered
147 * @param reset: if true, then calls unregisterLabelReference() before
148 * registering
149 */
150 void registerLabelReferences(std::vector<std::string>&& labels, bool reset = true);
151
152 /** Check subnames for label registration
153 *
154 * @param subs: subname references
155 * @param reset: if true, then calls unregisterLabelReference() before
156 * registering
157 *
158 * Check the give subname references and extract any label reference
159 * inside (by calling getLabelReferences()), and register them.
160 */
161 void checkLabelReferences(const std::vector<std::string>& subs, bool reset = true);
162
163 /// Clear internal label references registration
164 void unregisterLabelReferences();
165
166 /// Test if the element reference has changed after restore
167 virtual bool referenceChanged() const
168 {
169 return false;
170 }
171
172 /** Test if the link is restored unchanged
173 *
174 * @param msg: optional error message
175 *
176 * @return For external linked object, return 2 in case the link is
177 * missing, and 1 if the time stamp has changed.
178 */
179 virtual int checkRestore(std::string* msg = nullptr) const
180 {
181 (void)msg;
182 return 0;
183 }
184
185 /** Obtain the linked objects
186 *
187 * @param objs: hold the returned linked objects on output
188 * @param all: if true, then return all the linked object regardless of
189 * this LinkScope. If false, then return only if the LinkScope
190 * is not hidden.
191 * @param sub: if given, then return subname references.
192 * @param newStyle: whether to return new or old style subname reference
193 */
194 virtual void getLinks(std::vector<App::DocumentObject*>& objs,
195 bool all = false,
196 std::vector<std::string>* subs = nullptr,
197 bool newStyle = true) const = 0;
198
199 /** Obtain identifiers from this link property that link to a given object
200 * @param identifiers: holds the returned identifier to reference the given object
201 * @param obj: the referenced object
202 * @param subname: optional subname reference
203 * @param all: if true, then return all the references regardless of
204 * this LinkScope. If false, then return only if the LinkScope
205 * is not hidden.
206 */
207 virtual void getLinksTo(std::vector<App::ObjectIdentifier>& identifiers,
208 App::DocumentObject* obj,
209 const char* subname = nullptr,
210 bool all = false) const = 0;
211
212 /** Called to reset this link property
213 *
214 * @param obj: reset link property if it is linked to this object
215 * @param clear: if true, then also reset property if the owner of this property is \a obj
216 *
217 * @sa breakLinks()
218 */
219 virtual void breakLink(App::DocumentObject* obj, bool clear) = 0;
220
221 /** Called to adjust the link to avoid potential cyclic dependency
222 *
223 * @param inList: recursive in-list of the would-be parent
224 *
225 * @return Return whether the link has been adjusted
226 *
227 * This function tries to correct the link to avoid any (sub)object inside
228 * in-list. If the adjustment is impossible, exception will be raised
229 */
230 virtual bool adjustLink(const std::set<App::DocumentObject*>& inList) = 0;
231
232 /** Return a copy of the property if the link replacement affects this property
233 *
234 * @param owner: the parent object whose link property is to be replace.
235 * Note that The parent may not be the container of this
236 * property. Link sub property can use this opportunity to
237 * adjust its relative links.
238 * @param oldObj: object to be replaced
239 * @param newObj: object to replace with
240 *
241 * @return Return a copy of the property that is adjusted for the link
242 * replacement operation.
243 */
244 virtual Property* CopyOnLinkReplace(const App::DocumentObject* parent,
245 App::DocumentObject* oldObj,
246 App::DocumentObject* newObj) const = 0;
247
248 /** Return a copy of the property if any changes caused by importing external linked object
249 *
250 * @param nameMap: a map from the original external object name to the
251 * imported new object name
252 *
253 * @return Returns a copy of the property with the updated link reference if
254 * affected. The copy will later be assgiend to this property by calling its
255 * Paste().
256 */
257 virtual Property* CopyOnImportExternal(const std::map<std::string, std::string>& nameMap) const
258 {
259 (void)nameMap;
260 return nullptr;
261 }
262
263 /** Update object label reference in this property
264 *
265 * @param obj: the object owner of the changing label
266 * @param ref: subname reference to old label
267 * @param newLabel: the future new label
268 *
269 * @return Returns a copy of the property if its link reference is affected.
270 * The copy will later be assgiend to this property by calling its Paste().
271 */
272 virtual Property*
273 CopyOnLabelChange(App::DocumentObject* obj, const std::string& ref, const char* newLabel) const
274 {
275 (void)obj;
276 (void)ref;
277 (void)newLabel;
278 return nullptr;
279 }
280
281 /// Helper function to return all linked objects of this property
282 std::vector<App::DocumentObject*> linkedObjects(bool all = false) const
283 {
284 std::vector<App::DocumentObject*> ret;
285 getLinks(ret, all);
286 return ret;
287 }
288
289 /// Helper function to return linked objects using an std::inserter
290 template<class T>
291 void getLinkedObjects(T& inserter, bool all = false) const
292 {
293 std::vector<App::DocumentObject*> ret;
294 getLinks(ret, all);
295 std::copy(ret.begin(), ret.end(), inserter);
296 }
297
298 /// Helper function to return a map of linked object and its subname references
299 void getLinkedElements(std::map<App::DocumentObject*, std::vector<std::string>>& elements,
300 bool newStyle = true,
301 bool all = false) const
302 {
303 std::vector<App::DocumentObject*> ret;
304 std::vector<std::string> subs;
305 getLinks(ret, all, &subs, newStyle);
306 assert(ret.size() == subs.size());
307 int i = 0;
308 for (auto obj : ret) {
309 elements[obj].push_back(subs[i++]);
310 }
311 }
312
313 /// Helper function to return a map of linked object and its subname references
314 std::map<App::DocumentObject*, std::vector<std::string>> linkedElements(bool newStyle = true,
315 bool all = false) const
316 {
317 std::map<App::DocumentObject*, std::vector<std::string>> ret;
318 getLinkedElements(ret, newStyle, all);
319 return ret;
320 }
321 //@}
322
323 bool isSame(const Property& other) const override;
324
325 /** Enable/disable temporary holding external object without throwing exception
326 *
327 * Warning, non-PropertyXLink related property does not have internal
328 * tracking of external objects, therefore the link will not by auto broken
329 * when external document is closed. Only use this for temporary case, or
330 * if you handle signalDeleteDocument yourself, or use one of the
331 * PropertyXLink related property.
332 */
333 void setAllowExternal(bool allow);
334
335 /// Helper functions
336 //@{
337
338 /** Helper function to check and replace a link
339 *
340 * @param owner: the owner of the current property
341 * @param obj: the current linked object
342 * @param parent: the parent of the changing link property, may or may not
343 * be equal to \c owner
344 * @param oldObj: the object to be replaced
345 * @param newObj: the object to replace with
346 * @param sub: optional the current subname reference
347 *
348 * @return Returns a pair(obj,subname). If no replacement is found,
349 * pair.first will be NULL
350 *
351 * Say a group has one of its child object replaced with another. Any
352 * existing link sub reference that refer to the original child object
353 * through the group will be broken. This helper function is used to check
354 * and correct any link sub reference.
355 */
356 static std::pair<App::DocumentObject*, std::string>
357 tryReplaceLink(const App::PropertyContainer* owner,
358 App::DocumentObject* obj,
359 const App::DocumentObject* parent,
360 App::DocumentObject* oldObj,
361 App::DocumentObject* newObj,
362 const char* sub = nullptr);
363
364 /** Helper function to check and replace a link with multiple subname references
365 *
366 * @param owner: the owner of the current property
367 * @param obj: the current linked object
368 * @param parent: the parent of the changing link property, may or may not
369 * be equal to \c owner
370 * @param oldObj: the object to be replaced
371 * @param newObj: the object to replace with
372 * @param subs: the current subname references
373 *
374 * @return Returns the a pair(obj,subs). If no replacement is found,
375 * pair.first will be NULL
376 * @sa tryReplaceLink()
377 */
378 static std::pair<App::DocumentObject*, std::vector<std::string>>
379 tryReplaceLinkSubs(const App::PropertyContainer* owner,
380 App::DocumentObject* obj,
381 const App::DocumentObject* parent,
382 App::DocumentObject* oldObj,
383 App::DocumentObject* newObj,
384 const std::vector<std::string>& subs);
385
386 /// Update all element references in all link properties of \a feature
387 static void updateElementReferences(DocumentObject* feature, bool reverse = false);
388
389 /// Update all element references in the _ElementRefMap
390 static void updateAllElementReferences(bool reverse = false);
391
392 /// Obtain link properties that contain element references to a given object
393 static const std::unordered_set<PropertyLinkBase*>& getElementReferences(DocumentObject*);
394
395 /** Helper function for update individual element reference
396 *
397 * @param feature: if given, than only update element reference belonging
398 * to this feature. If not, then update geometry element
399 * references.
400 * @param sub: the subname reference to be updated.
401 * @param shadow: a pair of new and old style element references to be updated.
402 * @param reverse: if true, then use the old style, i.e. non-mapped element
403 * reference to query for the new style, i.e. mapped
404 * element reference when update. If false, then the other
405 * way around.
406 * @param notify: if true, call aboutToSetValue() before change
407 *
408 * This helper function is to be called by each link property in the event of
409 * geometry element reference change due to geometry model changes.
410 */
411 bool _updateElementReference(App::DocumentObject* feature,
412 App::DocumentObject* obj,
413 std::string& sub,
414 ShadowSub& shadow,
415 bool reverse,
416 bool notify = false);
417
418 /** Helper function to register geometry element reference
419 *
420 * @param obj: the linked object
421 * @param sub: the subname reference
422 * @param shadow: a pair of new and old style element references to be updated.
423 *
424 * Search for any geometry element reference inside the subname, and
425 * register for future update in case of geometry model update.
426 */
427 void _registerElementReference(App::DocumentObject* obj, std::string& sub, ShadowSub& shadow);
428
429 /** Helper function for breaking link properties
430 *
431 * @param link: reset link property if it is linked to this object
432 * @param objs: the objects to check for the link properties
433 * @param clear: if true, then also reset property if the owner of the link property is \a link
434 *
435 * App::Document::breakDependency() calls this function to break the link property
436 */
437 static void breakLinks(App::DocumentObject* link,
438 const std::vector<App::DocumentObject*>& objs,
439 bool clear);
440
441 /** Helper function for link import operation
442 *
443 * @param obj: the linked object
444 * @param sub: subname reference
445 * @param doc: importing document
446 * @param nameMap: a name map from source object to its imported counter part
447 *
448 * @return Return a changed subname reference, or empty string if no change.
449 *
450 * Link import operation will go through all link property and imports all
451 * externally linked object. After import, the link property must be
452 * changed to point to the newly imported objects, which should happen inside
453 * the API CopyOnImportExternal(). This function helps to rewrite subname
454 * reference to point to the correct sub objects that are imported.
455 */
456 static std::string tryImportSubName(const App::DocumentObject* obj,
457 const char* sub,
458 const App::Document* doc,
459 const std::map<std::string, std::string>& nameMap);
460
461 /** Helper function for link import operation
462 *
463 * @param doc: owner document of the imported objects
464 * @param obj: the linked object
465 * @param nameMap: a name map from source object to its imported counter part
466 *
467 * @return Return the imported object if found, or the input \c obj if no change.
468 * @sa tryImportSubNames
469 *
470 * This function searches for the name map and tries to find the imported
471 * object from the given source object.
472 */
473 static App::DocumentObject* tryImport(const App::Document* doc,
474 const App::DocumentObject* obj,
475 const std::map<std::string, std::string>& nameMap);
476
477 /** Helper function to export a subname reference
478 *
479 * @param output: output subname if the subname is modified
480 * @param obj: linked object
481 * @param sub: input subname reference
482 * @param first_obj: if true, then the first object referenced in subname
483 * is obtained by searching the owner document of obj,
484 * otherwise the subname search among obj's sub-objects.
485 *
486 * @return Return output.c_str() if the subname is modified for exporting
487 * otherwise, return the input subname
488 *
489 * @sa importSubName(), restoreLabelReference()
490 *
491 * The function go through the input subname reference and changes any sub
492 * object references inside for exporting. If the sub object is referenced
493 * by its internal object name, then the reference is changed from
494 * 'objName' to 'objName@docName'. If referenced by label, then it will be
495 * changed to 'objName@docName@' instead. importSubName() and
496 * restoreLabelReference() can be used together to restore the reference
497 * during import.
498 */
499 static const char* exportSubName(std::string& output,
500 const App::DocumentObject* obj,
501 const char* subname,
502 bool first_obj = false);
503
504 /** Helper function to import a subname reference
505 *
506 * @param reader: the import reader
507 * @param sub: input subname reference
508 * @param restoreLabel: output indicate whether post process is required
509 * after restore.
510 *
511 * @sa exportSubName(), restoreLabelReference()
512 *
513 * @return return either an updated subname reference or the input
514 * reference if no change. If restoreLabel is set to true on output, it
515 * means there are some label reference changes that must be corrected
516 * after restore, by calling restoreLabelReference() in property's
517 * afterRestore().
518 */
519 static std::string importSubName(Base::XMLReader& reader, const char* sub, bool& restoreLabel);
520
521 /** Helper function to restore label references during import
522 *
523 * @param obj: linked object
524 * @param sub: subname reference
525 * @param shadow: optional shadow subname reference
526 *
527 * @sa exportSubName(), importSubName()
528 *
529 * When exporting and importing (i.e. copy and paste) objects into the same
530 * document, the new object must be renamed, both the internal name and the
531 * label. Therefore, the link reference of the new objects must be
532 * corrected accordingly. The basic idea is that when exporting object, all
533 * object name references are changed to 'objName@docName', and label
534 * references are changed to 'objName@docName@'. During import,
535 * MergeDocument will maintain a map from objName@docName to object's new
536 * name. Object name reference can be restored on spot by consulting the
537 * map, while label reference will be restored later in property's
538 * afterRestore() function, which calls this function to do the string
539 * parsing.
540 */
541 static void restoreLabelReference(const App::DocumentObject* obj,
542 std::string& sub,
543 ShadowSub* shadow = nullptr);
544
545 /** Helper function to extract labels from a subname reference
546 *
547 * @param labels: output vector of extracted labels
548 * @param subname: subname reference
549 *
550 * @sa registerLabelReferences()
551 *
552 * This function is used to extract label from subname reference for
553 * registering of label changes.
554 */
555 static void getLabelReferences(std::vector<std::string>& labels, const char* subname);
556
557 /** Helper function to collect changed property when an object re-label
558 *
559 * @param obj: the object that owns the label
560 * @param newLabel: the new label
561 *
562 * @return return a map from the affected property to a copy of it with
563 * updated subname references
564 */
565 static std::vector<std::pair<Property*, std::unique_ptr<Property>>>
566 updateLabelReferences(App::DocumentObject* obj, const char* newLabel);
567
568 /** Helper function to update subname reference on label change
569 *
570 * @param linked: linked object
571 * @param subname: subname reference
572 * @param obj: the object that owns the label
573 * @param ref: label reference in the format of '$<old_label>.', which is
574 * the format used in subname reference for label reference.
575 * This parameter is provided for easy search of label
576 * reference.
577 * @param newLabel: new label
578 *
579 * @return Returns an updated subname reference, or empty string if no change.
580 *
581 * This function helps to update subname reference on label change. It is
582 * usually called inside CopyOnLabelChange(), the API for handling label
583 * change, which is called just before label change. In other word, when
584 * called, the sub object can still be reached using the original label
585 * references, but not the new labels.
586 */
587 static std::string updateLabelReference(const App::DocumentObject* linked,
588 const char* subname,
589 const App::DocumentObject* obj,
590 const std::string& ref,
591 const char* newLabel);
592 //@}
593
594 enum LinkFlags
595 {
596 LinkAllowExternal,
597 LinkDetached,
598 LinkRestoring,
599 LinkAllowPartial,
600 LinkRestoreLabel,
601 LinkSyncSubObject, // used by DlgPropertyLink
602 LinkNewElement, // return new element name in getPyObject
603 LinkSilentRestore, // do not report error on restore (e.g. missing external link)
604 };
605 inline bool testFlag(int flag) const
606 {
607 return _Flags.test((std::size_t)flag);
608 }
609
610 virtual void setAllowPartial(bool enable)
611 {
612 (void)enable;
613 }
614
615 void setReturnNewElement(bool enable);
616
617 void setSilentRestore(bool enable);
618
619 boost::signals2::signal<void(const std::string&, const std::string&)>
620 signalUpdateElementReference;
621
622 protected:
623 void hasSetValue() override;
624
625 protected:
626 std::bitset<32> _Flags;
627 inline void setFlag(int flag, bool value = true)
628 {
629 _Flags.set((std::size_t)flag, value);
630 }
631
632 void _getLinksTo(std::vector<App::ObjectIdentifier>& identifiers,
633 App::DocumentObject* obj,
634 const char* subname,
635 const std::vector<std::string>& subs,
636 const std::vector<PropertyLinkBase::ShadowSub>& shadows) const;
637
638 private:
639 std::set<std::string> _LabelRefs;
640 std::set<App::DocumentObject*> _ElementRefs;
641 };
642
643 /** The general Link Property
644 * Main Purpose of this property is to Link Objects and Features in a document. Like all links this
645 * property is scope aware, meaning it does define which objects are allowed to be linked depending
646 * of the GeoFeatureGroup where it is in. Default is Local.
647 *
648 * @note Links that are invalid in respect to the scope of this property is set to are not
649 * rejected. They are only detected to be invalid and prevent the feature from recomputing.
650 */
651 class AppExport PropertyLink: public PropertyLinkBase
652 {
653 TYPESYSTEM_HEADER_WITH_OVERRIDE();
654
655 public:
656 /**
657 * A constructor.
658 * A more elaborate description of the constructor.
659 */
660 PropertyLink();
661
662 /**
663 * A destructor.
664 * A more elaborate description of the destructor.
665 */
666 ~PropertyLink() override;
667
668 void resetLink();
669
670 /** Sets the property
671 */
672 virtual void setValue(App::DocumentObject*);
673
674 /** This method returns the linked DocumentObject
675 */
676 App::DocumentObject* getValue() const;
677
678 /** Returns the link type checked
679 */
680 App::DocumentObject* getValue(Base::Type t) const;
681
682 /** Returns the link type checked
683 */
684 template<typename _type>
685 inline _type getValue() const
686 {
687 return _pcLink ? dynamic_cast<_type>(_pcLink) : 0;
688 }
689
690 PyObject* getPyObject() override;
691 void setPyObject(PyObject* value) override;
692
693 void Save(Base::Writer& writer) const override;
694 void Restore(Base::XMLReader& reader) override;
695
696 Property* Copy() const override;
697 void Paste(const Property& from) override;
698
699 unsigned int getMemSize() const override
700 {
701 return sizeof(App::DocumentObject*);
702 }
703 const char* getEditorName() const override
704 {
705 return "Gui::PropertyEditor::PropertyLinkItem";
706 }
707
708 void getLinks(std::vector<App::DocumentObject*>& objs,
709 bool all = false,
710 std::vector<std::string>* subs = nullptr,
711 bool newStyle = true) const override;
712
713 void getLinksTo(std::vector<App::ObjectIdentifier>& identifiers,
714 App::DocumentObject* obj,
715 const char* subname = nullptr,
716 bool all = false) const override;
717
718 void breakLink(App::DocumentObject* obj, bool clear) override;
719
720 bool adjustLink(const std::set<App::DocumentObject*>& inList) override;
721
722 Property* CopyOnLinkReplace(const App::DocumentObject* parent,
723 App::DocumentObject* oldObj,
724 App::DocumentObject* newObj) const override;
725
726 protected:
727 App::DocumentObject* _pcLink {nullptr};
728 };
729
730 /** The general Link Property with Child scope
731 */
732 class AppExport PropertyLinkChild: public PropertyLink
733 {
734 TYPESYSTEM_HEADER();
735
736 public:
737 PropertyLinkChild()
738 {
739 _pcScope = LinkScope::Child;
740 }
741 };
742
743 /** The general Link Property with Global scope
744 */
745 class AppExport PropertyLinkGlobal: public PropertyLink
746 {
747 TYPESYSTEM_HEADER();
748
749 public:
750 PropertyLinkGlobal()
751 {
752 _pcScope = LinkScope::Global;
753 }
754 };
755
756 /** The general Link Property that are hidden from dependency checking
757 */
758 class AppExport PropertyLinkHidden: public PropertyLink
759 {
760 TYPESYSTEM_HEADER();
761
762 public:
763 PropertyLinkHidden()
764 {
765 _pcScope = LinkScope::Hidden;
766 }
767 };
768
769
770 class AppExport PropertyLinkListBase: public PropertyLinkBase, public PropertyListsBase
771 {
772 TYPESYSTEM_HEADER_WITH_OVERRIDE();
773
774 public:
775 void setPyObject(PyObject* obj) override
776 {
777 _setPyObject(obj);
778 }
779 };
780
781 class AppExport PropertyLinkList
782 : public PropertyListsT<DocumentObject*, std::vector<DocumentObject*>, PropertyLinkListBase>
783 {
784 TYPESYSTEM_HEADER_WITH_OVERRIDE();
785 using inherited =
786 PropertyListsT<DocumentObject*, std::vector<DocumentObject*>, PropertyLinkListBase>;
787
788 public:
789 /**
790 * A constructor.
791 * A more elaborate description of the constructor.
792 */
793 PropertyLinkList();
794
795 /**
796 * A destructor.
797 * A more elaborate description of the destructor.
798 */
799 ~PropertyLinkList() override;
800
801 void setSize(int newSize) override;
802 void setSize(int newSize, const_reference def) override;
803
804 /** Sets the property
805 */
806 void setValues(const std::vector<DocumentObject*>& value) override;
807
808 void set1Value(int idx, DocumentObject* const& value) override;
809
810 PyObject* getPyObject() override;
811
812 void Save(Base::Writer& writer) const override;
813 void Restore(Base::XMLReader& reader) override;
814
815 Property* Copy() const override;
816 void Paste(const Property& from) override;
817
818 unsigned int getMemSize() const override;
819 const char* getEditorName() const override
820 {
821 return "Gui::PropertyEditor::PropertyLinkListItem";
822 }
823
824 void getLinks(std::vector<App::DocumentObject*>& objs,
825 bool all = false,
826 std::vector<std::string>* subs = nullptr,
827 bool newStyle = true) const override;
828
829 void getLinksTo(std::vector<App::ObjectIdentifier>& identifiers,
830 App::DocumentObject* obj,
831 const char* subname = nullptr,
832 bool all = false) const override;
833
834 void breakLink(App::DocumentObject* obj, bool clear) override;
835
836 bool adjustLink(const std::set<App::DocumentObject*>& inList) override;
837
838 Property* CopyOnLinkReplace(const App::DocumentObject* parent,
839 App::DocumentObject* oldObj,
840 App::DocumentObject* newObj) const override;
841
842 DocumentObject* findUsingMap(const std::string&, int* pindex = nullptr) const;
843 DocumentObject* find(const char* sub, int* pindex = nullptr) const;
844
845 protected:
846 DocumentObject* getPyValue(PyObject* item) const override;
847
848 protected:
849 mutable std::map<std::string, int> _nameMap;
850 };
851
852 /** The general Link Property with Child scope
853 */
854 class AppExport PropertyLinkListChild: public PropertyLinkList
855 {
856 TYPESYSTEM_HEADER();
857
858 public:
859 PropertyLinkListChild()
860 {
861 _pcScope = LinkScope::Child;
862 }
863 };
864
865 /** The general Link Property with Global scope
866 */
867 class AppExport PropertyLinkListGlobal: public PropertyLinkList
868 {
869 TYPESYSTEM_HEADER();
870
871 public:
872 PropertyLinkListGlobal()
873 {
874 _pcScope = LinkScope::Global;
875 }
876 };
877
878 /** The general Link Property that are hidden from dependency checking
879 */
880 class AppExport PropertyLinkListHidden: public PropertyLinkList
881 {
882 TYPESYSTEM_HEADER();
883
884 public:
885 PropertyLinkListHidden()
886 {
887 _pcScope = LinkScope::Hidden;
888 }
889 };
890
891 /** the Link Property with sub elements
892 * This property links an object and a defined sequence of
893 * sub elements. These subelements (like Edges of a Shape)
894 * are stored as names, which can be resolved by the
895 * ComplexGeoDataType interface to concrete sub objects.
896 */
897 class AppExport PropertyLinkSub: public PropertyLinkBase
898 {
899 TYPESYSTEM_HEADER_WITH_OVERRIDE();
900
901 public:
902 /**
903 * A constructor.
904 * A more elaborate description of the constructor.
905 */
906 PropertyLinkSub();
907
908 /**
909 * A destructor.
910 * A more elaborate description of the destructor.
911 */
912 ~PropertyLinkSub() override;
913
914 void afterRestore() override;
915 void onContainerRestored() override;
916
917 /** Sets the property
918 */
919 void setValue(App::DocumentObject*,
920 const std::vector<std::string>& SubList,
921 std::vector<ShadowSub>&& ShadowSubList = {});
922 void setValue(App::DocumentObject*,
923 std::vector<std::string>&& SubList = {},
924 std::vector<ShadowSub>&& ShadowSubList = {});
925
926 /** This method returns the linked DocumentObject
927 */
928 App::DocumentObject* getValue() const;
929
930 /// return the list of sub elements
931 const std::vector<std::string>& getSubValues() const;
932
933 /// return the list of sub elements with mapped names
934 const std::vector<ShadowSub>& getShadowSubs() const
935 {
936 return _ShadowSubList;
937 }
938
939 std::vector<std::string> getSubValues(bool newStyle) const;
940
941 /// return the list of sub elements starts with a special string
942 std::vector<std::string> getSubValuesStartsWith(const char*, bool newStyle = false) const;
943
944 /** Returns the link type checked
945 */
946 App::DocumentObject* getValue(Base::Type t) const;
947
948 /** Returns the link type checked
949 */
950 template<typename _type>
951 inline _type getValue() const
952 {
953 return _pcLinkSub ? dynamic_cast<_type>(_pcLinkSub) : 0;
954 }
955
956 PyObject* getPyObject() override;
957 void setPyObject(PyObject* value) override;
958
959 void Save(Base::Writer& writer) const override;
960 void Restore(Base::XMLReader& reader) override;
961
962 Property* Copy() const override;
963 void Paste(const Property& from) override;
964
965 const char* getEditorName() const override
966 {
967 return "Gui::PropertyEditor::PropertyLinkItem";
968 }
969
970 /// Return a copy of the property if any changes caused by importing external object
971 Property*
972 CopyOnImportExternal(const std::map<std::string, std::string>& nameMap) const override;
973
974 Property* CopyOnLabelChange(App::DocumentObject* obj,
975 const std::string& ref,
976 const char* newLabel) const override;
977
978 Property* CopyOnLinkReplace(const App::DocumentObject* parent,
979 App::DocumentObject* oldObj,
980 App::DocumentObject* newObj) const override;
981
982 unsigned int getMemSize() const override
983 {
984 return sizeof(App::DocumentObject*);
985 }
986
987 void updateElementReference(DocumentObject* feature,
988 bool reverse = false,
989 bool notify = false) override;
990
991 bool referenceChanged() const override;
992
993 void getLinks(std::vector<App::DocumentObject*>& objs,
994 bool all = false,
995 std::vector<std::string>* subs = nullptr,
996 bool newStyle = true) const override;
997
998 void getLinksTo(std::vector<App::ObjectIdentifier>& identifiers,
999 App::DocumentObject* obj,
1000 const char* subname = nullptr,
1001 bool all = false) const override;
1002
1003 void breakLink(App::DocumentObject* obj, bool clear) override;
1004
1005 bool adjustLink(const std::set<App::DocumentObject*>& inList) override;
1006
1007 void setSyncSubObject(bool enable);
1008
1009 protected:
1010 App::DocumentObject* _pcLinkSub {nullptr};
1011 std::vector<std::string> _cSubList;
1012 std::vector<ShadowSub> _ShadowSubList;
1013 std::vector<int> _mapped;
1014 bool _restoreLabel {false};
1015 };
1016
1017 /** The general Link Property with Child scope
1018 */
1019 class AppExport PropertyLinkSubChild: public PropertyLinkSub
1020 {
1021 TYPESYSTEM_HEADER();
1022
1023 public:
1024 PropertyLinkSubChild()
1025 {
1026 _pcScope = LinkScope::Child;
1027 }
1028 };
1029
1030 /** The general Link Property with Global scope
1031 */
1032 class AppExport PropertyLinkSubGlobal: public PropertyLinkSub
1033 {
1034 TYPESYSTEM_HEADER();
1035
1036 public:
1037 PropertyLinkSubGlobal()
1038 {
1039 _pcScope = LinkScope::Global;
1040 }
1041 };
1042
1043 /** The general Link Property that are hidden from dependency checking
1044 */
1045 class AppExport PropertyLinkSubHidden: public PropertyLinkSub
1046 {
1047 TYPESYSTEM_HEADER();
1048
1049 public:
1050 PropertyLinkSubHidden()
1051 {
1052 _pcScope = LinkScope::Hidden;
1053 }
1054 };
1055
1056 class AppExport PropertyLinkSubList: public PropertyLinkBase
1057 {
1058 TYPESYSTEM_HEADER_WITH_OVERRIDE();
1059
1060 public:
1061 using SubSet = std::pair<DocumentObject*, std::vector<std::string>>;
1062 /**
1063 * A constructor.
1064 * A more elaborate description of the constructor.
1065 */
1066 PropertyLinkSubList();
1067
1068 /**
1069 * A destructor.
1070 * A more elaborate description of the destructor.
1071 */
1072 ~PropertyLinkSubList() override;
1073
1074 void afterRestore() override;
1075 void onContainerRestored() override;
1076
1077 int getSize() const;
1078 void setSize(int newSize);
1079
1080 /** Sets the property.
1081 * setValue(0, whatever) clears the property
1082 */
1083 void setValue(DocumentObject*, const char*);
1084 void setValues(const std::vector<DocumentObject*>&, const std::vector<const char*>&);
1085 void setValues(const std::vector<DocumentObject*>&,
1086 const std::vector<std::string>&,
1087 std::vector<ShadowSub>&& ShadowSubList = {});
1088 void setValues(std::vector<DocumentObject*>&&,
1089 std::vector<std::string>&& subs,
1090 std::vector<ShadowSub>&& ShadowSubList = {});
1091
1092 /**
1093 * @brief setValue: PropertyLinkSub-compatible overload
1094 * @param SubList
1095 */
1096 void setValue(App::DocumentObject* lValue,
1097 const std::vector<std::string>& SubList = std::vector<std::string>());
1098
1099 void addValue(App::DocumentObject* obj,
1100 const std::vector<std::string>& SubList = {},
1101 bool reset = false);
1102
1103 const std::vector<DocumentObject*>& getValues() const
1104 {
1105 return _lValueList;
1106 }
1107
1108 const std::string getPyReprString() const;
1109
1110 /**
1111 * @brief getValue emulates the action of a single-object link.
1112 * @return reference to object, if the link is to only one object. NULL if
1113 * the link is empty, or links to subelements of more than one document
1114 * object.
1115 */
1116 DocumentObject* getValue() const;
1117
1118 const std::vector<std::string>& getSubValues() const
1119 {
1120 return _lSubList;
1121 }
1122
1123 std::vector<std::string> getSubValues(bool newStyle) const;
1124
1125 const std::vector<ShadowSub>& getShadowSubs() const
1126 {
1127 return _ShadowSubList;
1128 }
1129
1130 /**
1131 * @brief Removes all occurrences of \a lValue in the property
1132 * together with its sub-elements and returns the number of entries removed.
1133 */
1134 int removeValue(App::DocumentObject* lValue);
1135
1136 void setSubListValues(const std::vector<SubSet>&);
1137 std::vector<SubSet> getSubListValues(bool newStyle = false) const;
1138
1139 PyObject* getPyObject() override;
1140 void setPyObject(PyObject*) override;
1141
1142 void Save(Base::Writer& writer) const override;
1143 void Restore(Base::XMLReader& reader) override;
1144 bool upgrade(Base::XMLReader& reader, const char* typeName);
1145
1146 Property* Copy() const override;
1147 void Paste(const Property& from) override;
1148
1149 const char* getEditorName() const override
1150 {
1151 return "Gui::PropertyEditor::PropertyLinkListItem";
1152 }
1153
1154 /// Return a copy of the property if any changes caused by importing external object
1155 Property*
1156 CopyOnImportExternal(const std::map<std::string, std::string>& nameMap) const override;
1157
1158 Property* CopyOnLabelChange(App::DocumentObject* obj,
1159 const std::string& ref,
1160 const char* newLabel) const override;
1161
1162 Property* CopyOnLinkReplace(const App::DocumentObject* parent,
1163 App::DocumentObject* oldObj,
1164 App::DocumentObject* newObj) const override;
1165
1166 unsigned int getMemSize() const override;
1167
1168 void updateElementReference(DocumentObject* feature,
1169 bool reverse = false,
1170 bool notify = false) override;
1171
1172 bool referenceChanged() const override;
1173
1174 void getLinks(std::vector<App::DocumentObject*>& objs,
1175 bool all = false,
1176 std::vector<std::string>* subs = nullptr,
1177 bool newStyle = true) const override;
1178
1179 void getLinksTo(std::vector<App::ObjectIdentifier>& identifiers,
1180 App::DocumentObject* obj,
1181 const char* subname = nullptr,
1182 bool all = false) const override;
1183
1184 void breakLink(App::DocumentObject* obj, bool clear) override;
1185
1186 bool adjustLink(const std::set<App::DocumentObject*>& inList) override;
1187
1188 void setSyncSubObject(bool enable);
1189
1190 private:
1191 void verifyObject(App::DocumentObject*, App::DocumentObject*);
1192
1193 private:
1194 // FIXME: Do not make two independent lists because this will lead to some inconsistencies!
1195 std::vector<DocumentObject*> _lValueList;
1196 std::vector<std::string> _lSubList;
1197 std::vector<ShadowSub> _ShadowSubList;
1198 std::vector<int> _mapped;
1199 };
1200
1201 /** The general Link Property with Child scope
1202 */
1203 class AppExport PropertyLinkSubListChild: public PropertyLinkSubList
1204 {
1205 TYPESYSTEM_HEADER();
1206
1207 public:
1208 PropertyLinkSubListChild()
1209 {
1210 _pcScope = LinkScope::Child;
1211 }
1212 };
1213
1214 /** The general Link Property with Global scope
1215 */
1216 class AppExport PropertyLinkSubListGlobal: public PropertyLinkSubList
1217 {
1218 TYPESYSTEM_HEADER();
1219
1220 public:
1221 PropertyLinkSubListGlobal()
1222 {
1223 _pcScope = LinkScope::Global;
1224 }
1225 };
1226
1227 /** The general Link Property that are hidden from dependency checking
1228 */
1229 class AppExport PropertyLinkSubListHidden: public PropertyLinkSubList
1230 {
1231 TYPESYSTEM_HEADER();
1232
1233 public:
1234 PropertyLinkSubListHidden()
1235 {
1236 _pcScope = LinkScope::Hidden;
1237 }
1238 };
1239
1240 class PropertyXLinkSubList;
1241
1242 /** Link to an (sub)object in the same or different document
1243 */
1244 class AppExport PropertyXLink: public PropertyLinkGlobal
1245 {
1246 TYPESYSTEM_HEADER_WITH_OVERRIDE();
1247
1248 public:
1249 explicit PropertyXLink(bool allowPartial = false, PropertyLinkBase* parent = nullptr);
1250
1251 ~PropertyXLink() override;
1252
1253 PropertyLinkBase* parent() const
1254 {
1255 return parentProp;
1256 }
1257
1258 void afterRestore() override;
1259 void onContainerRestored() override;
1260
1261 void setValue(App::DocumentObject*) override;
1262 void setValue(App::DocumentObject*, const char* subname);
1263
1264 void setValue(std::string&& filePath,
1265 std::string&& objectName,
1266 std::vector<std::string>&& SubList,
1267 std::vector<ShadowSub>&& ShadowSubList = {});
1268
1269 void setValue(App::DocumentObject*,
1270 std::vector<std::string>&& SubList,
1271 std::vector<ShadowSub>&& ShadowSubList = {});
1272
1273 void setValue(App::DocumentObject*,
1274 const std::vector<std::string>& SubList,
1275 std::vector<ShadowSub>&& ShadowSubList = {});
1276
1277 void setSubValues(std::vector<std::string>&& SubList,
1278 std::vector<ShadowSub>&& ShadowSubList = {});
1279
1280 const char* getSubName(bool newStyle = true) const;
1281 void setSubName(const char* subname);
1282
1283 bool hasSubName() const
1284 {
1285 return !_SubList.empty();
1286 }
1287
1288 App::Document* getDocument() const;
1289 const char* getDocumentPath() const;
1290 const char* getObjectName() const;
1291
1292 int checkRestore(std::string* msg = nullptr) const override;
1293
1294 void Save(Base::Writer& writer) const override;
1295 void Restore(Base::XMLReader& reader) override;
1296
1297 Property* Copy() const override;
1298 void Paste(const Property& from) override;
1299
1300 /// Return a copy of the property if any changes caused by importing external object
1301 Property*
1302 CopyOnImportExternal(const std::map<std::string, std::string>& nameMap) const override;
1303
1304 Property* CopyOnLabelChange(App::DocumentObject* obj,
1305 const std::string& ref,
1306 const char* newLabel) const override;
1307
1308 Property* CopyOnLinkReplace(const App::DocumentObject* parent,
1309 App::DocumentObject* oldObj,
1310 App::DocumentObject* newObj) const override;
1311
1312 PyObject* getPyObject() override;
1313 void setPyObject(PyObject*) override;
1314
1315 friend class DocInfo;
1316
1317 static bool supportXLink(const App::Property* prop);
1318 static bool hasXLink(const App::Document* doc);
1319 static bool hasXLink(const std::vector<App::DocumentObject*>& objs,
1320 std::vector<App::Document*>* unsaved = nullptr);
1321 static std::map<App::Document*, std::set<App::Document*>>
1322 getDocumentOutList(App::Document* doc = nullptr);
1323 static std::map<App::Document*, std::set<App::Document*>>
1324 getDocumentInList(App::Document* doc = nullptr);
1325 static void restoreDocument(const App::Document& doc);
1326
1327 void updateElementReference(DocumentObject* feature,
1328 bool reverse = false,
1329 bool notify = false) override;
1330
1331 bool referenceChanged() const override;
1332
1333 void getLinks(std::vector<App::DocumentObject*>& objs,
1334 bool all = false,
1335 std::vector<std::string>* subs = nullptr,
1336 bool newStyle = true) const override;
1337
1338 void getLinksTo(std::vector<App::ObjectIdentifier>& identifiers,
1339 App::DocumentObject* obj,
1340 const char* subname = nullptr,
1341 bool all = false) const override;
1342
1343 bool adjustLink(const std::set<App::DocumentObject*>& inList) override;
1344
1345 const std::vector<std::string>& getSubValues() const
1346 {
1347 return _SubList;
1348 }
1349 const std::vector<ShadowSub>& getShadowSubs() const
1350 {
1351 return _ShadowSubList;
1352 }
1353 std::vector<std::string> getSubValues(bool newStyle) const;
1354 std::vector<std::string> getSubValuesStartsWith(const char*, bool newStyle = false) const;
1355
1356 void setAllowPartial(bool enable) override;
1357
1358 const char* getFilePath() const
1359 {
1360 return filePath.c_str();
1361 }
1362
1363 virtual bool upgrade(Base::XMLReader& reader, const char* typeName);
1364
1365 void setSyncSubObject(bool enable);
1366
1367 protected:
1368 void unlink();
1369 void detach();
1370
1371 void restoreLink(App::DocumentObject*);
1372
1373 void copyTo(PropertyXLink& other,
1374 App::DocumentObject* linked = nullptr,
1375 std::vector<std::string>* subs = nullptr) const;
1376
1377 void aboutToSetValue() override;
1378
1379 void hasSetValue() override;
1380
1381 friend class PropertyXLinkSubList;
1382
1383 protected:
1384 DocInfoPtr docInfo;
1385 std::string filePath;
1386 std::string docName;
1387 std::string objectName;
1388 std::string stamp;
1389 std::vector<std::string> _SubList;
1390 std::vector<ShadowSub> _ShadowSubList;
1391 std::vector<int> _mapped;
1392 PropertyLinkBase* parentProp;
1393 mutable std::string tmpShadow;
1394 };
1395
1396
1397 /** Link to one or more (sub)object from the same or different document
1398 */
1399 class AppExport PropertyXLinkSub: public PropertyXLink
1400 {
1401 TYPESYSTEM_HEADER_WITH_OVERRIDE();
1402
1403 public:
1404 explicit PropertyXLinkSub(bool allowPartial = false, PropertyLinkBase* parent = nullptr);
1405
1406 ~PropertyXLinkSub() override;
1407
1408 bool upgrade(Base::XMLReader& reader, const char* typeName) override;
1409
1410 PyObject* getPyObject() override;
1411
1412 const char* getEditorName() const override
1413 {
1414 return "Gui::PropertyEditor::PropertyLinkItem";
1415 }
1416 };
1417
1418 /** The PropertyXLinkSub that is hidden from dependency checking
1419 */
1420 class AppExport PropertyXLinkSubHidden: public PropertyXLinkSub
1421 {
1422 TYPESYSTEM_HEADER();
1423
1424 public:
1425 PropertyXLinkSubHidden()
1426 {
1427 _pcScope = LinkScope::Hidden;
1428 }
1429 };
1430
1431 /** Link to one or more (sub)object(s) of one or more object(s) from the same or different document
1432 */
1433 class AppExport PropertyXLinkSubList: public PropertyLinkBase,
1434 public AtomicPropertyChangeInterface<PropertyXLinkSubList>
1435 {
1436 TYPESYSTEM_HEADER_WITH_OVERRIDE();
1437
1438 public:
1439 using atomic_change =
1440 typename AtomicPropertyChangeInterface<PropertyXLinkSubList>::AtomicPropertyChange;
1441 friend atomic_change;
1442
1443 PropertyXLinkSubList();
1444 ~PropertyXLinkSubList() override;
1445
1446 void afterRestore() override;
1447 void onContainerRestored() override;
1448
1449 int getSize() const;
1450
1451 /** Sets the property.
1452 * setValue(0, whatever) clears the property
1453 */
1454 void setValue(DocumentObject*, const char*);
1455 void setValues(const std::vector<DocumentObject*>&);
1456 void set1Value(int idx, DocumentObject* value, const std::vector<std::string>& SubList = {});
1457
1458 void setValues(const std::vector<DocumentObject*>&, const std::vector<const char*>&);
1459 void setValues(const std::vector<DocumentObject*>&, const std::vector<std::string>&);
1460 void setValues(std::map<App::DocumentObject*, std::vector<std::string>>&&);
1461 void setValues(const std::map<App::DocumentObject*, std::vector<std::string>>&);
1462
1463 void addValue(App::DocumentObject* obj,
1464 const std::vector<std::string>& SubList = {},
1465 bool reset = false);
1466 void
1467 addValue(App::DocumentObject* obj, std::vector<std::string>&& SubList = {}, bool reset = false);
1468
1469 /**
1470 * @brief setValue: PropertyLinkSub-compatible overload
1471 * @param SubList
1472 */
1473 void setValue(App::DocumentObject* lValue, const std::vector<std::string>& SubList = {});
1474
1475 std::vector<DocumentObject*> getValues() const;
1476
1477 const std::string getPyReprString() const;
1478
1479 DocumentObject* getValue() const;
1480
1481 const std::vector<std::string>& getSubValues(App::DocumentObject* obj) const;
1482
1483 std::vector<std::string> getSubValues(App::DocumentObject* obj, bool newStyle) const;
1484
1485 const std::vector<ShadowSub>& getShadowSubs(App::DocumentObject* obj) const;
1486
1487 /**
1488 * @brief Removes all occurrences of \a lValue in the property
1489 * together with its sub-elements and returns the number of entries removed.
1490 */
1491 int removeValue(App::DocumentObject* lValue);
1492
1493 void setSubListValues(const std::vector<PropertyLinkSubList::SubSet>&);
1494
1495 const std::list<PropertyXLinkSub>& getSubListValues() const
1496 {
1497 return _Links;
1498 }
1499
1500 PyObject* getPyObject() override;
1501 void setPyObject(PyObject* value) override;
1502
1503 void Save(Base::Writer& writer) const override;
1504 void Restore(Base::XMLReader& reader) override;
1505
1506 Property* Copy() const override;
1507 void Paste(const Property& from) override;
1508
1509 const char* getEditorName() const override
1510 {
1511 return "Gui::PropertyEditor::PropertyLinkListItem";
1512 }
1513
1514 Property*
1515 CopyOnImportExternal(const std::map<std::string, std::string>& nameMap) const override;
1516
1517 Property* CopyOnLabelChange(App::DocumentObject* obj,
1518 const std::string& ref,
1519 const char* newLabel) const override;
1520
1521 Property* CopyOnLinkReplace(const App::DocumentObject* parent,
1522 App::DocumentObject* oldObj,
1523 App::DocumentObject* newObj) const override;
1524
1525 unsigned int getMemSize() const override;
1526
1527 void updateElementReference(DocumentObject* feature,
1528 bool reverse = false,
1529 bool notify = false) override;
1530
1531 bool referenceChanged() const override;
1532
1533 void getLinks(std::vector<App::DocumentObject*>& objs,
1534 bool all = false,
1535 std::vector<std::string>* subs = nullptr,
1536 bool newStyle = true) const override;
1537
1538 void getLinksTo(std::vector<App::ObjectIdentifier>& identifiers,
1539 App::DocumentObject* obj,
1540 const char* subname = nullptr,
1541 bool all = false) const override;
1542
1543 void breakLink(App::DocumentObject* obj, bool clear) override;
1544
1545 bool adjustLink(const std::set<App::DocumentObject*>& inList) override;
1546
1547 bool upgrade(Base::XMLReader& reader, const char* typeName);
1548
1549 int checkRestore(std::string* msg = nullptr) const override;
1550
1551 void setAllowPartial(bool enable) override;
1552
1553 void hasSetChildValue(Property&) override;
1554 void aboutToSetChildValue(Property&) override;
1555
1556 void setSyncSubObject(bool enable);
1557
1558 protected:
1559 void _getLinksToList(std::vector<App::ObjectIdentifier>& identifiers,
1560 App::DocumentObject* obj,
1561 const char* subname,
1562 const std::vector<std::string>& subs,
1563 const std::vector<PropertyLinkBase::ShadowSub>& shadows) const;
1564
1565 protected:
1566 std::list<PropertyXLinkSub> _Links;
1567 };
1568
1569
1570 /** Link to one or more (sub)object(s) of one or more object(s) from the same or different document
1571 *
1572 * The only difference for PropertyXLinkList and PropertyXLinkSubList is in
1573 * their getPyObject(). PropertyXLinkList will return a list of object is
1574 * there is no sub-object/sub-elements in the property.
1575 */
1576 class AppExport PropertyXLinkList: public PropertyXLinkSubList
1577 {
1578 TYPESYSTEM_HEADER_WITH_OVERRIDE();
1579
1580 public:
1581 PropertyXLinkList();
1582 ~PropertyXLinkList() override;
1583
1584 PyObject* getPyObject() override;
1585 void setPyObject(PyObject*) override;
1586 };
1587
1588
1589 /** Abstract property that can link to multiple external objects
1590 *
1591 * @sa See PropertyExpressionEngine for example usage
1592 */
1593 class AppExport PropertyXLinkContainer: public PropertyLinkBase
1594 {
1595 TYPESYSTEM_HEADER_WITH_OVERRIDE();
1596
1597 public:
1598 PropertyXLinkContainer();
1599 ~PropertyXLinkContainer() override;
1600
1601 void afterRestore() override;
1602 int checkRestore(std::string* msg = nullptr) const override;
1603 void Save(Base::Writer& writer) const override;
1604 void Restore(Base::XMLReader& reader) override;
1605 void breakLink(App::DocumentObject* obj, bool clear) override;
1606 void getLinks(std::vector<App::DocumentObject*>& objs,
1607 bool all = false,
1608 std::vector<std::string>* subs = nullptr,
1609 bool newStyle = true) const override;
1610
1611 bool isLinkedToDocument(const App::Document& doc) const;
1612
1613 protected:
1614 void aboutToSetChildValue(App::Property& prop) override;
1615 virtual PropertyXLink* createXLink();
1616 virtual void onBreakLink(App::DocumentObject* obj);
1617 virtual void onAddDep(App::DocumentObject*)
1618 {}
1619 virtual void onRemoveDep(App::DocumentObject*)
1620 {}
1621 void updateDeps(std::map<DocumentObject*, bool>&& newDeps);
1622 void clearDeps();
1623
1624 void _onBreakLink(App::DocumentObject* obj);
1625
1626 protected:
1627 std::map<App::DocumentObject*, bool> _Deps;
1628 std::map<std::string, std::unique_ptr<PropertyXLink>> _XLinks;
1629 std::map<std::string, std::string> _DocMap;
1630 bool _LinkRestored;
1631
1632 private:
1633 struct RestoreInfo
1634 {
1635 std::unique_ptr<PropertyXLink> xlink;
1636 std::string docName;
1637 std::string docLabel;
1638 bool hidden = false;
1639 };
1640 std::unique_ptr<std::vector<RestoreInfo>> _XLinkRestores;
1641 };
1642
1643 } // namespace App
1644
1645
1646 #endif // APP_PROPERTYLINKS_H