add/extend helper classes to savely access document, document objects or view providers

This commit is contained in:
wmayer
2018-10-31 11:24:45 +01:00
parent c50f6aea53
commit 42601fc4e4
4 changed files with 251 additions and 6 deletions

View File

@@ -46,6 +46,11 @@ DocumentT::DocumentT(Document* doc)
document = doc->getName();
}
DocumentT::DocumentT(const std::string& name)
{
document = name;
}
DocumentT::~DocumentT()
{
}
@@ -62,6 +67,11 @@ void DocumentT::operator=(const Document* doc)
document = doc->getName();
}
void DocumentT::operator=(const std::string& name)
{
document = name;
}
Document* DocumentT::getDocument() const
{
return GetApplication().getDocument(document.c_str());
@@ -77,10 +87,10 @@ std::string DocumentT::getDocumentPython() const
std::stringstream str;
Document* doc = GetApplication().getActiveDocument();
if (doc && document == doc->getName()) {
str << "FreeCAD.ActiveDocument";
str << "App.ActiveDocument";
}
else {
str << "FreeCAD.getDocument(\""
str << "App.getDocument(\""
<< document
<< "\")";
}
@@ -135,10 +145,10 @@ std::string DocumentObjectT::getDocumentPython() const
std::stringstream str;
Document* doc = GetApplication().getActiveDocument();
if (doc && document == doc->getName()) {
str << "FreeCAD.ActiveDocument";
str << "App.ActiveDocument";
}
else {
str << "FreeCAD.getDocument(\""
str << "App.getDocument(\""
<< document
<< "\")";
}
@@ -170,10 +180,10 @@ std::string DocumentObjectT::getObjectPython() const
std::stringstream str;
Document* doc = GetApplication().getActiveDocument();
if (doc && document == doc->getName()) {
str << "FreeCAD.ActiveDocument.";
str << "App.ActiveDocument.";
}
else {
str << "FreeCAD.getDocument(\""
str << "App.getDocument(\""
<< document
<< "\").";
}