Fix #3800 Connect TD export to FC Gui Export
- TD did not define export types for the general Export command in Gui.
This commit is contained in:
@@ -41,10 +41,12 @@
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/DocumentObjectPy.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/ViewProvider.h>
|
||||
|
||||
|
||||
#include <Mod/Part/App/OCCError.h>
|
||||
#include <Mod/TechDraw/App/DrawPage.h>
|
||||
|
||||
#include "MDIViewPage.h"
|
||||
#include "ViewProviderPage.h"
|
||||
@@ -60,7 +62,10 @@ class Module : public Py::ExtensionModule<Module>
|
||||
public:
|
||||
Module() : Py::ExtensionModule<Module>("TechDrawGui")
|
||||
{
|
||||
add_varargs_method("exportPageAsPdf",&Module::exportPageAsPdf,
|
||||
add_varargs_method("export",&Module::exporter,
|
||||
"TechDraw hook for FC Gui exporter."
|
||||
);
|
||||
add_varargs_method("exportPageAsPdf",&Module::exportPageAsPdf,
|
||||
"exportPageAsPdf(DrawPageObject,FilePath) -- print page as Pdf to file."
|
||||
);
|
||||
add_varargs_method("exportPageAsSvg",&Module::exportPageAsSvg,
|
||||
@@ -104,6 +109,53 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
//! hook for FC Gui export function
|
||||
Py::Object exporter(const Py::Tuple& args)
|
||||
{
|
||||
PyObject* object;
|
||||
char* Name;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "Oet",&object,"utf-8",&Name))
|
||||
throw Py::Exception();
|
||||
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
|
||||
TechDraw::DrawPage* page = nullptr;
|
||||
Py::Sequence list(object);
|
||||
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();
|
||||
if (obj->getTypeId().isDerivedFrom(TechDraw::DrawPage::getClassTypeId())) {
|
||||
page = static_cast<TechDraw::DrawPage*>(obj);
|
||||
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()) ) {
|
||||
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 {
|
||||
throw Py::TypeError("TechDraw can not export this file format");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw Py::TypeError("Export of this object type is not supported by TechDraw module");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
//!exportPageAsPdf(PageObject,FullPath)
|
||||
Py::Object exportPageAsPdf(const Py::Tuple& args)
|
||||
{
|
||||
|
||||
@@ -118,6 +118,12 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget*
|
||||
m_exportSVGAction = new QAction(tr("&Export SVG"), this);
|
||||
connect(m_exportSVGAction, SIGNAL(triggered()), this, SLOT(saveSVG()));
|
||||
|
||||
m_exportDXFAction = new QAction(tr("Export DXF"), this);
|
||||
connect(m_exportDXFAction, SIGNAL(triggered()), this, SLOT(saveDXF()));
|
||||
|
||||
m_exportPDFAction = new QAction(tr("Export PDF"), this);
|
||||
connect(m_exportPDFAction, SIGNAL(triggered()), this, SLOT(savePDF()));
|
||||
|
||||
isSelectionBlocked = false;
|
||||
|
||||
QString tabText = QString::fromUtf8(pageVp->getDrawPage()->getNameInDocument());
|
||||
@@ -763,6 +769,8 @@ void MDIViewPage::contextMenuEvent(QContextMenuEvent *event)
|
||||
menu.addAction(m_toggleFrameAction);
|
||||
menu.addAction(m_toggleKeepUpdatedAction);
|
||||
menu.addAction(m_exportSVGAction);
|
||||
menu.addAction(m_exportDXFAction);
|
||||
menu.addAction(m_exportPDFAction);
|
||||
menu.exec(event->globalPos());
|
||||
}
|
||||
|
||||
@@ -809,6 +817,43 @@ void MDIViewPage::saveSVG(std::string file)
|
||||
m_view->saveSvg(filename);
|
||||
}
|
||||
|
||||
void MDIViewPage::saveDXF()
|
||||
{
|
||||
// TechDraw::DrawPage* page = m_vpPage->getDrawPage();
|
||||
QString defaultDir;
|
||||
QString fileName = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(),
|
||||
QString::fromUtf8(QT_TR_NOOP("Save Dxf File ")),
|
||||
defaultDir,
|
||||
QString::fromUtf8(QT_TR_NOOP("Dxf (*.dxf)")));
|
||||
if (fileName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string sFileName = fileName.toUtf8().constData();
|
||||
saveDXF(sFileName);
|
||||
}
|
||||
|
||||
void MDIViewPage::saveDXF(std::string fileName)
|
||||
{
|
||||
TechDraw::DrawPage* page = m_vpPage->getDrawPage();
|
||||
std::string PageName = page->getNameInDocument();
|
||||
Gui::Command::openCommand("Save page to dxf");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"import TechDraw");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"TechDraw.writeDXFPage(App.activeDocument().%s,u\"%s\")",
|
||||
PageName.c_str(),(const char*)fileName.c_str());
|
||||
Gui::Command::updateActive();
|
||||
Gui::Command::commitCommand();
|
||||
}
|
||||
|
||||
void MDIViewPage::savePDF()
|
||||
{
|
||||
printPdf();
|
||||
}
|
||||
|
||||
void MDIViewPage::savePDF(std::string file)
|
||||
{
|
||||
printPdf(file);
|
||||
}
|
||||
|
||||
/////////////// Selection Routines ///////////////////
|
||||
// wf: this is never executed???
|
||||
|
||||
@@ -80,6 +80,8 @@ public:
|
||||
void printPreview();
|
||||
|
||||
void saveSVG(std::string file);
|
||||
void saveDXF(std::string file);
|
||||
void savePDF(std::string file);
|
||||
|
||||
void setFrameState(bool state);
|
||||
bool getFrameState(void) {return m_frameState;};
|
||||
@@ -104,6 +106,8 @@ public:
|
||||
public Q_SLOTS:
|
||||
void viewAll();
|
||||
void saveSVG(void);
|
||||
void saveDXF(void);
|
||||
void savePDF(void);
|
||||
void toggleFrame(void);
|
||||
void toggleKeepUpdated(void);
|
||||
// void testAction(void);
|
||||
@@ -137,6 +141,8 @@ private:
|
||||
QAction *m_toggleFrameAction;
|
||||
QAction *m_toggleKeepUpdatedAction;
|
||||
QAction *m_exportSVGAction;
|
||||
QAction *m_exportDXFAction;
|
||||
QAction *m_exportPDFAction;
|
||||
// QAction* m_testAction;
|
||||
|
||||
std::string m_objectName;
|
||||
|
||||
@@ -45,3 +45,6 @@ class TechDrawWorkbench (Workbench):
|
||||
return "TechDrawGui::Workbench"
|
||||
|
||||
Gui.addWorkbench(TechDrawWorkbench())
|
||||
|
||||
# Append the export handler
|
||||
FreeCAD.addExportType("Technical Drawing (*.svg *.dxf *.pdf)","TechDrawGui")
|
||||
|
||||
Reference in New Issue
Block a user