diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 7f9eeea17..7bf52ff02 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -1220,6 +1220,32 @@ void Application::processCmdLineFiles(void) Console().Error("Unknown exception while processing file: %s \n", File.filePath().c_str()); } } + + const std::map& cfg = Application::Config(); + std::map::const_iterator it = cfg.find("SaveFile"); + if (it != cfg.end()) { + std::string output = it->second; + Base::FileInfo fi(output); + std::string ext = fi.extension(); + try { + std::vector mods = App::GetApplication().getExportModules(ext.c_str()); + if (!mods.empty()) { + Base::Interpreter().loadModule(mods.front().c_str()); + Base::Interpreter().runStringArg("import %s",mods.front().c_str()); + Base::Interpreter().runStringArg("%s.export(App.ActiveDocument.Objects, '%s')" + ,mods.front().c_str(),output.c_str()); + } + else { + Console().Warning("File format not supported: %s \n", output.c_str()); + } + } + catch (const Base::Exception& e) { + Console().Error("Exception while saving to file: %s [%s]\n", output.c_str(), e.what()); + } + catch (...) { + Console().Error("Unknown exception while saving to file: %s \n", output.c_str()); + } + } } void Application::runApplication() @@ -1419,7 +1445,9 @@ void Application::ParseOptions(int ac, char ** av) // in config file, but will not be shown to the user. boost::program_options::options_description hidden("Hidden options"); hidden.add_options() - ("input-file", boost::program_options::value< vector >(), "input file") + ("input-file", boost::program_options::value< vector >(), "input file") + ("output", boost::program_options::value(),"output file") + ("hidden", "don't show the main window") // this are to ignore for the window system (QApplication) ("style", boost::program_options::value< string >(), "set the application GUI style") ("display", boost::program_options::value< string >(), "set the X-Server") @@ -1548,6 +1576,15 @@ void Application::ParseOptions(int ac, char ** av) mConfig["OpenFileCount"] = buffer.str(); } + if (vm.count("output")) { + string file = vm["output"].as(); + mConfig["SaveFile"] = file; + } + + if (vm.count("hidden")) { + mConfig["StartHidden"] = "1"; + } + if (vm.count("write-log")) { mConfig["LoggingFile"] = "1"; //mConfig["LoggingFileName"] = vm["write-log"].as(); diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 2dbc4b2c8..995f291ca 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -1620,9 +1620,15 @@ void Application::runApplication(void) logo->setFrameShape(QFrame::NoFrame); } } + bool hidden = false; + it = cfg.find("StartHidden"); + if (it != cfg.end()) { + hidden = true; + } // show splasher while initializing the GUI - mw.startSplasher(); + if (!hidden) + mw.startSplasher(); // running the GUI init script try { @@ -1656,8 +1662,10 @@ void Application::runApplication(void) app.activateWorkbench(start.c_str()); // show the main window - Base::Console().Log("Init: Showing main window\n"); - mw.loadWindowSettings(); + if (!hidden) { + Base::Console().Log("Init: Showing main window\n"); + mw.loadWindowSettings(); + } //initialize spaceball. mainApp.initSpaceball(&mw); diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index 2703823fa..9ca9ee3af 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -26,6 +26,7 @@ #ifndef _PreComp_ # include # include +# include #endif @@ -36,6 +37,7 @@ #include "MainWindow.h" #include "EditorView.h" #include "PythonEditor.h" +#include "View3DInventor.h" #include "WidgetFactory.h" #include "Workbench.h" #include "WorkbenchManager.h" @@ -362,6 +364,21 @@ PyObject* Application::sExport(PyObject * /*self*/, PyObject *args,PyObject * /* ).arg(QLatin1String(doc->getName())).arg(fi.absoluteFilePath()); Base::Interpreter().runString(cmd.toUtf8()); } + else if (ext == QLatin1String("pdf")) { + Gui::Document* gui_doc = Application::Instance->getDocument(doc); + if (gui_doc) { + Gui::MDIView* view = gui_doc->getActiveView(); + if (view) { + View3DInventor* view3d = qobject_cast(view); + if (view3d) + view3d->viewAll(); + QPrinter printer(QPrinter::ScreenResolution); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setOutputFileName(fileName); + view->print(&printer); + } + } + } } } PY_CATCH; diff --git a/src/Gui/EditorView.h b/src/Gui/EditorView.h index d72630866..096733ba9 100644 --- a/src/Gui/EditorView.h +++ b/src/Gui/EditorView.h @@ -74,6 +74,7 @@ public: void print (); void printPdf(); void printPreview(); + void print(QPrinter*); //@} QStringList undoActions() const; @@ -88,7 +89,6 @@ private Q_SLOTS: void contentsChange(int position, int charsRemoved, int charsAdded); void undoAvailable(bool); void redoAvailable(bool); - void print(QPrinter*); private: void setCurrentFileName(const QString &fileName); diff --git a/src/Gui/FreeCADGuiInit.py b/src/Gui/FreeCADGuiInit.py index 4f60213f0..68296d2f1 100644 --- a/src/Gui/FreeCADGuiInit.py +++ b/src/Gui/FreeCADGuiInit.py @@ -169,6 +169,7 @@ FreeCAD.addExportType("Inventor V2.1 (*.iv)","FreeCADGui") FreeCAD.addExportType("VRML V2.0 (*.wrl *.vrml *.wrz *.wrl.gz)","FreeCADGui") #FreeCAD.addExportType("IDTF (for 3D PDF) (*.idtf)","FreeCADGui") FreeCAD.addExportType("3D View (*.svg)","FreeCADGui") +FreeCAD.addExportType("Portable Document Format (*.pdf)","FreeCADGui") del(InitApplications) del(NoneWorkbench) diff --git a/src/Gui/MDIView.cpp b/src/Gui/MDIView.cpp index 3b7c07b60..c47e628f8 100644 --- a/src/Gui/MDIView.cpp +++ b/src/Gui/MDIView.cpp @@ -29,6 +29,7 @@ # include # include # include +#include #endif @@ -168,22 +169,24 @@ void MDIView::windowStateChanged( MDIView* ) { } +void MDIView::print(QPrinter* printer) +{ + std::cerr << "Printing not implemented for " << this->metaObject()->className() << std::endl; +} + void MDIView::print() { - // print command specified but print method not overriden! - assert(0); + std::cerr << "Printing not implemented for " << this->metaObject()->className() << std::endl; } void MDIView::printPdf() { - // print command specified but print method not overriden! - assert(0); + std::cerr << "Printing PDF not implemented for " << this->metaObject()->className() << std::endl; } void MDIView::printPreview() { - // print command specified but print method not overriden! - assert(0); + std::cerr << "Printing preview not implemented for " << this->metaObject()->className() << std::endl; } QSize MDIView::minimumSizeHint () const diff --git a/src/Gui/MDIView.h b/src/Gui/MDIView.h index c96c4daa2..e96f7e172 100644 --- a/src/Gui/MDIView.h +++ b/src/Gui/MDIView.h @@ -74,10 +74,18 @@ public: virtual bool canClose(void); /// delete itself virtual void deleteSelf(); - /// print function of the view + /** @name Printing */ + //@{ +public Q_SLOTS: + virtual void print(QPrinter* printer); +public: + /** Print content of view */ virtual void print(); + /** Print to PDF file */ virtual void printPdf(); + /** Show a preview dialog */ virtual void printPreview(); + //@} QSize minimumSizeHint () const; diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index 05f5c8f47..a3bebb9b0 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -1151,6 +1151,13 @@ void MainWindow::delayedStartup() // processing all command line files App::Application::processCmdLineFiles(); + const std::map& cfg = App::Application::Config(); + std::map::const_iterator it = cfg.find("StartHidden"); + if (it != cfg.end()) { + QApplication::quit(); + return; + } + // Create new document? ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Document"); if (hGrp->GetBool("CreateNewDoc", false)) { diff --git a/src/Gui/View3DInventor.h b/src/Gui/View3DInventor.h index 7fc9b3dd2..cfc1f9253 100644 --- a/src/Gui/View3DInventor.h +++ b/src/Gui/View3DInventor.h @@ -85,6 +85,7 @@ public: virtual void print(); virtual void printPdf(); virtual void printPreview(); + virtual void print(QPrinter*); virtual PyObject *getPyObject(void); /** @@ -113,7 +114,6 @@ public Q_SLOTS: protected Q_SLOTS: void stopAnimating(); - void print(QPrinter*); public: bool eventFilter(QObject*, QEvent* ); diff --git a/src/Mod/Drawing/Gui/DrawingView.h b/src/Mod/Drawing/Gui/DrawingView.h index 8e1e84f2d..2b864090b 100644 --- a/src/Mod/Drawing/Gui/DrawingView.h +++ b/src/Mod/Drawing/Gui/DrawingView.h @@ -92,8 +92,6 @@ public: void print(); void printPdf(); void printPreview(); - -protected Q_SLOTS: void print(QPrinter* printer); protected: