Add program options --output and --hidden and implement PDF as export format
This commit is contained in:
parent
ee3201793c
commit
fcb4d396a1
|
@ -1220,6 +1220,32 @@ void Application::processCmdLineFiles(void)
|
|||
Console().Error("Unknown exception while processing file: %s \n", File.filePath().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
const std::map<std::string,std::string>& cfg = Application::Config();
|
||||
std::map<std::string,std::string>::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<std::string> 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<string> >(), "input file")
|
||||
("input-file", boost::program_options::value< vector<string> >(), "input file")
|
||||
("output", boost::program_options::value<string>(),"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<string>();
|
||||
mConfig["SaveFile"] = file;
|
||||
}
|
||||
|
||||
if (vm.count("hidden")) {
|
||||
mConfig["StartHidden"] = "1";
|
||||
}
|
||||
|
||||
if (vm.count("write-log")) {
|
||||
mConfig["LoggingFile"] = "1";
|
||||
//mConfig["LoggingFileName"] = vm["write-log"].as<string>();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#ifndef _PreComp_
|
||||
# include <qfileinfo.h>
|
||||
# include <qdir.h>
|
||||
# include <QPrinter>
|
||||
#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<View3DInventor*>(view);
|
||||
if (view3d)
|
||||
view3d->viewAll();
|
||||
QPrinter printer(QPrinter::ScreenResolution);
|
||||
printer.setOutputFormat(QPrinter::PdfFormat);
|
||||
printer.setOutputFileName(fileName);
|
||||
view->print(&printer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} PY_CATCH;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
# include <QEvent>
|
||||
# include <QCloseEvent>
|
||||
# include <QMdiSubWindow>
|
||||
#include <iostream>
|
||||
#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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1151,6 +1151,13 @@ void MainWindow::delayedStartup()
|
|||
// processing all command line files
|
||||
App::Application::processCmdLineFiles();
|
||||
|
||||
const std::map<std::string,std::string>& cfg = App::Application::Config();
|
||||
std::map<std::string,std::string>::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)) {
|
||||
|
|
|
@ -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* );
|
||||
|
|
|
@ -92,8 +92,6 @@ public:
|
|||
void print();
|
||||
void printPdf();
|
||||
void printPreview();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void print(QPrinter* printer);
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue
Block a user