| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| |
|
| | #ifndef APP_DOCUMENTOBSERVER_H
|
| | #define APP_DOCUMENTOBSERVER_H
|
| |
|
| | #include <Base/BaseClass.h>
|
| | #include <Base/Bitmask.h>
|
| | #include <fastsignals/signal.h>
|
| | #include <memory>
|
| | #include <set>
|
| | #include <string>
|
| | #include <FCGlobal.h>
|
| |
|
| |
|
| | namespace App
|
| | {
|
| | class Document;
|
| | class DocumentObject;
|
| | class Property;
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | class AppExport DocumentT
|
| | {
|
| | public:
|
| |
|
| | DocumentT();
|
| |
|
| | DocumentT(Document*);
|
| |
|
| | explicit DocumentT(const std::string&);
|
| |
|
| | DocumentT(const DocumentT&);
|
| |
|
| | ~DocumentT();
|
| |
|
| | void operator=(const DocumentT&);
|
| |
|
| | void operator=(const Document*);
|
| |
|
| | void operator=(const std::string&);
|
| |
|
| | bool operator==(const DocumentT& other) const
|
| | {
|
| | return document == other.document;
|
| | }
|
| |
|
| | bool operator<(const DocumentT& other) const
|
| | {
|
| | return document < other.document;
|
| | }
|
| |
|
| |
|
| | Document* getDocument() const;
|
| |
|
| | const std::string& getDocumentName() const;
|
| |
|
| | std::string getDocumentPython() const;
|
| |
|
| | private:
|
| | std::string document;
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | class AppExport DocumentObjectT
|
| | {
|
| | public:
|
| |
|
| | DocumentObjectT();
|
| |
|
| | DocumentObjectT(const DocumentObjectT&);
|
| |
|
| | DocumentObjectT(DocumentObjectT&&);
|
| |
|
| | explicit DocumentObjectT(const DocumentObject*);
|
| |
|
| | DocumentObjectT(const Document*, const std::string& objName);
|
| |
|
| | DocumentObjectT(const char* docName, const char* objName);
|
| |
|
| | explicit DocumentObjectT(const Property*);
|
| |
|
| | ~DocumentObjectT();
|
| |
|
| | DocumentObjectT& operator=(const DocumentObjectT&);
|
| |
|
| | DocumentObjectT& operator=(DocumentObjectT&&);
|
| |
|
| | void operator=(const DocumentObject*);
|
| |
|
| | void operator=(const Property*);
|
| |
|
| | bool operator==(const DocumentObjectT&) const;
|
| |
|
| |
|
| | Document* getDocument() const;
|
| |
|
| | const std::string& getDocumentName() const;
|
| |
|
| | std::string getDocumentPython() const;
|
| |
|
| | DocumentObject* getObject() const;
|
| |
|
| | Property* getProperty() const;
|
| |
|
| | const std::string& getObjectName() const;
|
| |
|
| | const std::string& getObjectLabel() const;
|
| |
|
| | const std::string& getPropertyName() const;
|
| |
|
| | std::string getObjectPython() const;
|
| |
|
| | std::string getPropertyPython() const;
|
| | |
| |
|
| | template<typename T>
|
| | inline T* getObjectAs() const
|
| | {
|
| | return freecad_cast<T*>(getObject());
|
| | }
|
| | template<typename T>
|
| | inline T* getPropertyAs() const
|
| | {
|
| | return freecad_cast<T*>(getProperty());
|
| | }
|
| |
|
| | private:
|
| | std::string document;
|
| | std::string object;
|
| | std::string label;
|
| | std::string property;
|
| | };
|
| |
|
| | class AppExport SubObjectT: public DocumentObjectT
|
| | {
|
| | public:
|
| |
|
| | SubObjectT();
|
| |
|
| |
|
| | SubObjectT(const SubObjectT&);
|
| |
|
| |
|
| | SubObjectT(SubObjectT&&);
|
| |
|
| |
|
| | SubObjectT(const DocumentObjectT& obj, const char* subname);
|
| |
|
| |
|
| | SubObjectT(const DocumentObject*, const char* subname);
|
| |
|
| |
|
| | SubObjectT(const DocumentObject*);
|
| |
|
| |
|
| | SubObjectT(const char* docName, const char* objName, const char* subname);
|
| |
|
| |
|
| | SubObjectT& operator=(const SubObjectT&);
|
| |
|
| |
|
| | SubObjectT& operator=(SubObjectT&&);
|
| |
|
| |
|
| | SubObjectT& operator=(const DocumentObjectT&);
|
| |
|
| |
|
| | SubObjectT& operator=(const App::DocumentObject*);
|
| |
|
| |
|
| | bool operator==(const SubObjectT&) const;
|
| |
|
| |
|
| | void setSubName(const char* subname);
|
| |
|
| |
|
| | void setSubName(const std::string& subname)
|
| | {
|
| | setSubName(subname.c_str());
|
| | }
|
| |
|
| |
|
| | const std::string& getSubName() const;
|
| |
|
| | |
| | |
| | |
| |
|
| | std::string getObjectFullName(const char* docName = nullptr) const;
|
| |
|
| | |
| | |
| | |
| |
|
| | std::string getSubObjectFullName(const char* docName = nullptr) const;
|
| |
|
| | std::string getSubNameNoElement() const;
|
| |
|
| |
|
| | const char* getElementName() const;
|
| |
|
| |
|
| | bool hasSubObject() const;
|
| |
|
| |
|
| | bool hasSubElement() const;
|
| |
|
| |
|
| | std::string getNewElementName() const;
|
| |
|
| | |
| | |
| |
|
| | std::string getOldElementName(int* index = nullptr) const;
|
| |
|
| |
|
| | DocumentObject* getSubObject() const;
|
| |
|
| |
|
| | std::vector<DocumentObject*> getSubObjectList() const;
|
| |
|
| | bool operator<(const SubObjectT& other) const;
|
| |
|
| | std::string getSubObjectPython(bool force = true) const;
|
| |
|
| |
|
| | enum class NormalizeOption : uint8_t
|
| | {
|
| |
|
| | NoElement = 0x01,
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | NoFlatten = 0x02,
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | KeepSubName = 0x04,
|
| |
|
| |
|
| | ConvertIndex = 0x08,
|
| | };
|
| | using NormalizeOptions = Base::Flags<NormalizeOption>;
|
| |
|
| | |
| | |
| |
|
| | bool normalize(NormalizeOptions options = NormalizeOption());
|
| |
|
| |
|
| | SubObjectT normalized(NormalizeOptions options = NormalizeOption()) const;
|
| |
|
| | private:
|
| | std::string subname;
|
| | };
|
| |
|
| | |
| | |
| |
|
| | class AppExport PropertyLinkT
|
| | {
|
| | public:
|
| |
|
| | PropertyLinkT();
|
| |
|
| |
|
| | explicit PropertyLinkT(DocumentObject* obj);
|
| |
|
| |
|
| | PropertyLinkT(DocumentObject* obj, const std::vector<std::string>& subNames);
|
| |
|
| |
|
| | explicit PropertyLinkT(const std::vector<DocumentObject*>& objs);
|
| |
|
| |
|
| | PropertyLinkT(const std::vector<DocumentObject*>& objs,
|
| | const std::vector<std::string>& subNames);
|
| |
|
| |
|
| | std::string getPropertyPython() const;
|
| |
|
| | private:
|
| | std::string toPython;
|
| | };
|
| |
|
| | |
| | |
| |
|
| | class AppExport DocumentWeakPtrT
|
| | {
|
| | public:
|
| | explicit DocumentWeakPtrT(App::Document*) noexcept;
|
| | ~DocumentWeakPtrT();
|
| |
|
| | |
| | |
| | |
| |
|
| | void reset() noexcept;
|
| | |
| | |
| | |
| |
|
| | bool expired() const noexcept;
|
| | |
| | |
| | |
| |
|
| | App::Document* operator*() const noexcept;
|
| | |
| | |
| | |
| |
|
| | App::Document* operator->() const noexcept;
|
| |
|
| |
|
| | DocumentWeakPtrT(const DocumentWeakPtrT&) = delete;
|
| | DocumentWeakPtrT& operator=(const DocumentWeakPtrT&) = delete;
|
| |
|
| | private:
|
| | class Private;
|
| | std::unique_ptr<Private> d;
|
| | };
|
| |
|
| | |
| | |
| |
|
| | class AppExport DocumentObjectWeakPtrT
|
| | {
|
| | public:
|
| | explicit DocumentObjectWeakPtrT(App::DocumentObject*);
|
| | ~DocumentObjectWeakPtrT();
|
| |
|
| |
|
| | DocumentObjectWeakPtrT(const DocumentObjectWeakPtrT &) = delete;
|
| | DocumentObjectWeakPtrT &operator=(const DocumentObjectWeakPtrT &) = delete;
|
| |
|
| |
|
| | DocumentObjectWeakPtrT(DocumentObjectWeakPtrT &&);
|
| | DocumentObjectWeakPtrT &operator=(DocumentObjectWeakPtrT &&);
|
| |
|
| | |
| | |
| | |
| |
|
| | void reset();
|
| | |
| | |
| | |
| |
|
| | bool expired() const noexcept;
|
| | |
| | |
| | |
| |
|
| | DocumentObjectWeakPtrT& operator=(App::DocumentObject* p);
|
| | |
| | |
| | |
| |
|
| | App::DocumentObject* operator*() const noexcept;
|
| | |
| | |
| | |
| |
|
| | App::DocumentObject* operator->() const noexcept;
|
| | |
| | |
| | |
| |
|
| | bool operator==(const DocumentObjectWeakPtrT& p) const noexcept;
|
| | |
| | |
| | |
| |
|
| | bool operator!=(const DocumentObjectWeakPtrT& p) const noexcept;
|
| |
|
| | template<typename T>
|
| | inline T* get() const noexcept
|
| | {
|
| | return freecad_cast<T*>(_get());
|
| | }
|
| |
|
| | private:
|
| | App::DocumentObject* _get() const noexcept;
|
| |
|
| | private:
|
| | class Private;
|
| | std::unique_ptr<Private> d;
|
| | };
|
| |
|
| | |
| | |
| |
|
| | template<class T>
|
| | class WeakPtrT
|
| | {
|
| | public:
|
| | explicit WeakPtrT(T* t)
|
| | : ptr(t)
|
| | {}
|
| | ~WeakPtrT() = default;
|
| |
|
| | |
| | |
| | |
| |
|
| | void reset()
|
| | {
|
| | ptr.reset();
|
| | }
|
| | |
| | |
| | |
| |
|
| | bool expired() const
|
| | {
|
| | return ptr.expired();
|
| | }
|
| | |
| | |
| | |
| |
|
| | WeakPtrT<T>& operator=(T* p)
|
| | {
|
| | ptr = p;
|
| | return *this;
|
| | }
|
| | |
| | |
| | |
| |
|
| | T* operator*() const
|
| | {
|
| | return ptr.get<T>();
|
| | }
|
| | |
| | |
| | |
| |
|
| | T* operator->() const
|
| | {
|
| | return ptr.get<T>();
|
| | }
|
| | |
| | |
| | |
| |
|
| | bool operator==(const WeakPtrT<T>& p) const
|
| | {
|
| | return ptr == p.ptr;
|
| | }
|
| | |
| | |
| | |
| |
|
| | bool operator!=(const WeakPtrT<T>& p) const
|
| | {
|
| | return ptr != p.ptr;
|
| | }
|
| |
|
| | T* get() const noexcept
|
| | {
|
| | return ptr.get<T>();
|
| | }
|
| |
|
| |
|
| | WeakPtrT(const WeakPtrT&) = delete;
|
| | WeakPtrT& operator=(const WeakPtrT&) = delete;
|
| |
|
| | private:
|
| | DocumentObjectWeakPtrT ptr;
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | class AppExport DocumentObserver
|
| | {
|
| |
|
| | public:
|
| |
|
| | DocumentObserver();
|
| | explicit DocumentObserver(Document*);
|
| | virtual ~DocumentObserver();
|
| |
|
| | |
| | |
| |
|
| | void attachDocument(Document*);
|
| | |
| | |
| |
|
| | void detachDocument();
|
| |
|
| | private:
|
| |
|
| | virtual void slotCreatedDocument(const App::Document& Doc);
|
| |
|
| | virtual void slotDeletedDocument(const App::Document& Doc);
|
| |
|
| | virtual void slotActivateDocument(const App::Document& Doc);
|
| |
|
| | virtual void slotCreatedObject(const App::DocumentObject& Obj);
|
| |
|
| | virtual void slotDeletedObject(const App::DocumentObject& Obj);
|
| |
|
| | virtual void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop);
|
| |
|
| | virtual void slotRecomputedObject(const App::DocumentObject& Obj);
|
| |
|
| | virtual void slotRecomputedDocument(const App::Document& Doc);
|
| |
|
| | protected:
|
| | Document* getDocument() const;
|
| |
|
| | private:
|
| | App::Document* _document;
|
| | using Connection = fastsignals::connection;
|
| | Connection connectApplicationCreatedDocument;
|
| | Connection connectApplicationDeletedDocument;
|
| | Connection connectApplicationActivateDocument;
|
| | Connection connectDocumentCreatedObject;
|
| | Connection connectDocumentDeletedObject;
|
| | Connection connectDocumentChangedObject;
|
| | Connection connectDocumentRecomputedObject;
|
| | Connection connectDocumentRecomputed;
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | class AppExport DocumentObjectObserver: public DocumentObserver
|
| | {
|
| |
|
| | public:
|
| | using const_iterator = std::set<App::DocumentObject*>::const_iterator;
|
| |
|
| |
|
| | DocumentObjectObserver();
|
| | ~DocumentObjectObserver() override;
|
| |
|
| | const_iterator begin() const;
|
| | const_iterator end() const;
|
| | void addToObservation(App::DocumentObject*);
|
| | void removeFromObservation(App::DocumentObject*);
|
| |
|
| | private:
|
| |
|
| | void slotCreatedDocument(const App::Document& Doc) override;
|
| |
|
| | void slotDeletedDocument(const App::Document& Doc) override;
|
| |
|
| | void slotCreatedObject(const App::DocumentObject& Obj) override;
|
| |
|
| | void slotDeletedObject(const App::DocumentObject& Obj) override;
|
| |
|
| | void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop) override;
|
| | |
| | |
| | |
| |
|
| | virtual void cancelObservation();
|
| |
|
| | private:
|
| | std::set<App::DocumentObject*> _objects;
|
| | };
|
| |
|
| | }
|
| |
|
| | template<>
|
| | struct std::hash<App::DocumentObjectWeakPtrT>
|
| | {
|
| | std::size_t operator()(const App::DocumentObjectWeakPtrT& ptr) const noexcept
|
| | {
|
| | return std::hash<App::DocumentObject*>{}(*ptr);
|
| | }
|
| | };
|
| |
|
| | ENABLE_BITMASK_OPERATORS(App::SubObjectT::NormalizeOption)
|
| |
|
| | #endif
|
| |
|