[TD]prevent use of non-exist/hidden tab in exports

This commit is contained in:
wandererfan
2024-11-19 17:59:28 -05:00
committed by WandererFan
parent 8581cd01e2
commit 797c1180b0
5 changed files with 76 additions and 83 deletions

View File

@@ -37,7 +37,6 @@
#include <Mod/TechDraw/App/DrawPagePy.h>
#include <Mod/TechDraw/App/DrawViewPy.h> // generated from DrawViewPy.xml
#include "MDIViewPage.h"
#include "QGIView.h"
#include "QGSPage.h"
#include "ViewProviderPage.h"
@@ -131,25 +130,30 @@ private:
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
PyObject* item = (*it).ptr();
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
App::DocumentObject* obj =
static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
if (obj->isDerivedFrom<TechDraw::DrawPage>()) {
page = static_cast<TechDraw::DrawPage*>(obj);
Gui::Document* activeGui = Gui::Application::Instance->getDocument(page->getDocument());
Gui::Document* activeGui =
Gui::Application::Instance->getDocument(page->getDocument());
Gui::ViewProvider* vp = activeGui->getViewProvider(obj);
ViewProviderPage* dvp = dynamic_cast<ViewProviderPage*>(vp);
if ( !(dvp && dvp->getMDIViewPage()) ) {
ViewProviderPage* vpPage = dynamic_cast<ViewProviderPage*>(vp);
if (!vpPage) {
throw Py::TypeError("TechDraw can not find Page");
}
Base::FileInfo fi_out(EncodedName.c_str());
if (fi_out.hasExtension("svg")) {
dvp->getMDIViewPage()->saveSVG(EncodedName);
} else if (fi_out.hasExtension("dxf")) {
dvp->getMDIViewPage()->saveDXF(EncodedName);
} else if (fi_out.hasExtension("pdf")) {
dvp->getMDIViewPage()->savePDF(EncodedName);
} else {
PagePrinter::saveSVG(vpPage, EncodedName);
}
else if (fi_out.hasExtension("dxf")) {
PagePrinter::saveDXF(vpPage, EncodedName);
}
else if (fi_out.hasExtension("pdf")) {
PagePrinter::savePDF(vpPage, EncodedName);
}
else {
throw Py::TypeError("TechDraw can not export this file format");
}
}
@@ -175,30 +179,22 @@ private:
PyMem_Free(name);
try {
App::DocumentObject* obj = nullptr;
Gui::ViewProvider* vp = nullptr;
MDIViewPage* mdi = nullptr;
if (PyObject_TypeCheck(pageObj, &(App::DocumentObjectPy::Type))) {
obj = static_cast<App::DocumentObjectPy*>(pageObj)->getDocumentObjectPtr();
vp = Gui::Application::Instance->getViewProvider(obj);
if (vp) {
TechDrawGui::ViewProviderPage* vpp = dynamic_cast<TechDrawGui::ViewProviderPage*>(vp);
if (vpp) {
mdi = vpp->getMDIViewPage();
if (mdi) {
mdi->savePDF(filePath);
} else {
vpp->showMDIViewPage();
mdi = vpp->getMDIViewPage();
if (mdi) {
mdi->savePDF(filePath);
} else {
throw Py::TypeError("Page not available! Is it Hidden?");
}
}
}
}
}
App::DocumentObject* obj = nullptr;
Gui::ViewProvider* vp = nullptr;
if (PyObject_TypeCheck(pageObj, &(App::DocumentObjectPy::Type))) {
obj = static_cast<App::DocumentObjectPy*>(pageObj)->getDocumentObjectPtr();
vp = Gui::Application::Instance->getViewProvider(obj);
if (vp) {
TechDrawGui::ViewProviderPage* vpPage =
dynamic_cast<TechDrawGui::ViewProviderPage*>(vp);
if (vpPage) {
PagePrinter::savePDF(vpPage, filePath);
}
else {
throw Py::TypeError("Page not available! Is it Hidden?");
}
}
}
}
catch (Base::Exception &e) {
e.setPyException();
@@ -221,30 +217,22 @@ private:
PyMem_Free(name);
try {
App::DocumentObject* obj = nullptr;
Gui::ViewProvider* vp = nullptr;
MDIViewPage* mdi = nullptr;
if (PyObject_TypeCheck(pageObj, &(App::DocumentObjectPy::Type))) {
obj = static_cast<App::DocumentObjectPy*>(pageObj)->getDocumentObjectPtr();
vp = Gui::Application::Instance->getViewProvider(obj);
if (vp) {
TechDrawGui::ViewProviderPage* vpp = dynamic_cast<TechDrawGui::ViewProviderPage*>(vp);
if (vpp) {
mdi = vpp->getMDIViewPage();
if (mdi) {
mdi->saveSVG(filePath);
} else {
vpp->showMDIViewPage();
mdi = vpp->getMDIViewPage();
if (mdi) {
mdi->saveSVG(filePath);
} else {
throw Py::TypeError("Page not available! Is it Hidden?");
}
}
}
}
}
App::DocumentObject* obj = nullptr;
Gui::ViewProvider* vp = nullptr;
if (PyObject_TypeCheck(pageObj, &(App::DocumentObjectPy::Type))) {
obj = static_cast<App::DocumentObjectPy*>(pageObj)->getDocumentObjectPtr();
vp = Gui::Application::Instance->getViewProvider(obj);
if (vp) {
TechDrawGui::ViewProviderPage* vpPage =
dynamic_cast<TechDrawGui::ViewProviderPage*>(vp);
if (vpPage) {
PagePrinter::saveSVG(vpPage, filePath);
}
else {
throw Py::TypeError("Page not available! Is it Hidden?");
}
}
}
}
catch (Base::Exception &e) {
e.setPyException();