add/extend helper classes to safely access documents, document objects or view providers
This commit is contained in:
@@ -83,7 +83,7 @@ std::string DocumentT::getDocumentName() const
|
||||
return document;
|
||||
}
|
||||
|
||||
std::string DocumentT::getDocumentPython() const
|
||||
std::string DocumentT::getGuiDocumentPython() const
|
||||
{
|
||||
std::stringstream str;
|
||||
Document* doc = Application::Instance->activeDocument();
|
||||
@@ -98,6 +98,21 @@ std::string DocumentT::getDocumentPython() const
|
||||
return str.str();
|
||||
}
|
||||
|
||||
std::string DocumentT::getAppDocumentPython() const
|
||||
{
|
||||
std::stringstream str;
|
||||
Document* doc = Application::Instance->activeDocument();
|
||||
if (doc && document == doc->getDocument()->getName()) {
|
||||
str << "App.ActiveDocument";
|
||||
}
|
||||
else {
|
||||
str << "App.getDocument(\""
|
||||
<< document
|
||||
<< "\")";
|
||||
}
|
||||
return str.str();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ViewProviderT::ViewProviderT()
|
||||
@@ -138,19 +153,16 @@ std::string ViewProviderT::getDocumentName() const
|
||||
return document;
|
||||
}
|
||||
|
||||
std::string ViewProviderT::getDocumentPython() const
|
||||
std::string ViewProviderT::getGuiDocumentPython() const
|
||||
{
|
||||
std::stringstream str;
|
||||
Document* doc = Application::Instance->activeDocument();
|
||||
if (doc && document == doc->getDocument()->getName()) {
|
||||
str << "Gui.ActiveDocument";
|
||||
}
|
||||
else {
|
||||
str << "Gui.getDocument(\""
|
||||
<< document
|
||||
<< "\")";
|
||||
}
|
||||
return str.str();
|
||||
DocumentT doct(document);
|
||||
return doct.getGuiDocumentPython();
|
||||
}
|
||||
|
||||
std::string ViewProviderT::getAppDocumentPython() const
|
||||
{
|
||||
DocumentT doct(document);
|
||||
return doct.getAppDocumentPython();
|
||||
}
|
||||
|
||||
ViewProviderDocumentObject* ViewProviderT::getViewProvider() const
|
||||
|
||||
@@ -62,8 +62,10 @@ public:
|
||||
Document* getDocument() const;
|
||||
/*! Get the name of the document. */
|
||||
std::string getDocumentName() const;
|
||||
/*! Get the document as Python command. */
|
||||
std::string getDocumentPython() const;
|
||||
/*! Get the Gui::Document as Python command. */
|
||||
std::string getGuiDocumentPython() const;
|
||||
/*! Get the App::Document as Python command. */
|
||||
std::string getAppDocumentPython() const;
|
||||
|
||||
private:
|
||||
std::string document;
|
||||
@@ -94,8 +96,10 @@ public:
|
||||
Document* getDocument() const;
|
||||
/*! Get the name of the document. */
|
||||
std::string getDocumentName() const;
|
||||
/*! Get the document as Python command. */
|
||||
std::string getDocumentPython() const;
|
||||
/*! Get the Gui::Document as Python command. */
|
||||
std::string getGuiDocumentPython() const;
|
||||
/*! Get the App::Document as Python command. */
|
||||
std::string getAppDocumentPython() const;
|
||||
/*! Get a pointer to the document object or 0 if it doesn't exist any more. */
|
||||
ViewProviderDocumentObject* getViewProvider() const;
|
||||
/*! Get the name of the document object. */
|
||||
|
||||
Reference in New Issue
Block a user