From 3792f259d38db65493e088c601068ae810725cb4 Mon Sep 17 00:00:00 2001 From: Ian Rees Date: Sun, 24 Jan 2016 11:58:30 +1300 Subject: [PATCH] Add setting to export compressed/uncompressed AMFs --- src/Mod/Mesh/App/AppMeshPy.cpp | 56 ++++++++++++------- src/Mod/Mesh/App/Exporter.h | 2 +- src/Mod/Mesh/Gui/DlgSettingsImportExport.ui | 51 ++++++++++++----- .../Mesh/Gui/DlgSettingsImportExportImp.cpp | 4 ++ 4 files changed, 79 insertions(+), 34 deletions(-) diff --git a/src/Mod/Mesh/App/AppMeshPy.cpp b/src/Mod/Mesh/App/AppMeshPy.cpp index 646096f12f9d..af26e74aa631 100644 --- a/src/Mod/Mesh/App/AppMeshPy.cpp +++ b/src/Mod/Mesh/App/AppMeshPy.cpp @@ -84,9 +84,13 @@ class Module : public Py::ExtensionModule add_varargs_method("insert",&Module::importer, "insert(string|mesh,[string]) -- Load or insert a mesh into the given or active document." ); - add_varargs_method("export",&Module::exporter, - "export(list,string,[tolerance]) -- Export a list of objects into a single file. tolerance is in mm\n" - "and specifies the maximum acceptable deviation between the specified objects and the exported mesh." + add_keyword_method("export",&Module::exporter, + "export(objects, filename, [tolerance=0.1, exportAmfCompressed=True])\n" + "Export a list of objects into a single file identified by filename.\n" + "tolerance is in mm and specifies the maximum acceptable deviation\n" + "between the specified objects and the exported mesh.\n" + "exportAmfCompressed specifies whether exported AMF files should be\n" + "compressed.\n" ); add_varargs_method("show",&Module::show, "Put a mesh object in the active document or creates one if needed" @@ -284,44 +288,55 @@ class Module : public Py::ExtensionModule return Py::None(); } - Py::Object exporter(const Py::Tuple& args) + + Py::Object exporter(const Py::Tuple &args, const Py::Dict &keywds) { - PyObject *object; - char *Name; + PyObject *objects; + char *fileNamePy; // If tolerance is specified via python interface, use that. // If not, use the preference, if that exists, else default to 0.1mm. - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Mesh"); - float fTolerance = hGrp->GetFloat( "MaxDeviationExport", 0.1f ); + auto hGrp( App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Mesh") ); + auto fTolerance( hGrp->GetFloat("MaxDeviationExport", 0.1f) ); + + int exportAmfCompressed( hGrp->GetBool("ExportAmfCompressed", true) ); - if (!PyArg_ParseTuple(args.ptr(), "Oet|f", &object, "utf-8", &Name, &fTolerance)) + static char *kwList[] = {"objectList", "filename", "tolerance", + "exportAmfCompressed", NULL}; + + // NOTE FOR PYTHON 3: Should switch exportAmfCompressed from using integer 'i' to bool 'p' + // TODO Deal with above nicely, and double check that the docstring is correct with regards to tol's default + if (!PyArg_ParseTupleAndKeywords( args.ptr(), keywds.ptr(), "Oet|fi", kwList, &objects, + "utf-8", &fileNamePy, + &fTolerance, &exportAmfCompressed )) { throw Py::Exception(); + } - std::string EncodedName = std::string(Name); - PyMem_Free(Name); + std::string outputFileName(fileNamePy); + PyMem_Free(fileNamePy); MeshObject global_mesh; - auto exportFormat( MeshOutput::GetFormat(EncodedName.c_str()) ); + auto exportFormat( MeshOutput::GetFormat(outputFileName.c_str()) ); std::unique_ptr exporter; if (exportFormat == MeshIO::AMF) { - std::map meta; - meta["cad"] = App::Application::Config()["ExeName"] + " " + - App::Application::Config()["ExeVersion"]; - meta[App::Application::Config()["ExeName"] + "-buildRevisionHash"] = - App::Application::Config()["BuildRevisionHash"]; + std::map meta; + meta["cad"] = App::Application::Config()["ExeName"] + " " + + App::Application::Config()["ExeVersion"]; + meta[App::Application::Config()["ExeName"] + "-buildRevisionHash"] = + App::Application::Config()["BuildRevisionHash"]; - exporter.reset( new AmfExporter(EncodedName, meta) ); + exporter.reset( new AmfExporter(outputFileName, meta, exportAmfCompressed) ); } else { // TODO: How do we handle unknown exportFormats? - exporter.reset( new MergeExporter(EncodedName, exportFormat) ); + exporter.reset( new MergeExporter(outputFileName, exportFormat) ); } Base::Type meshId = Base::Type::fromName("Mesh::Feature"); Base::Type partId = Base::Type::fromName("Part::Feature"); - Py::Sequence list(object); + Py::Sequence list(objects); for (auto it : list) { PyObject* item = it.ptr(); if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { @@ -340,6 +355,7 @@ class Module : public Py::ExtensionModule return Py::None(); } + Py::Object show(const Py::Tuple& args) { PyObject *pcObj; diff --git a/src/Mod/Mesh/App/Exporter.h b/src/Mod/Mesh/App/Exporter.h index bd12cef15591..b2bc15cf80ea 100644 --- a/src/Mod/Mesh/App/Exporter.h +++ b/src/Mod/Mesh/App/Exporter.h @@ -91,7 +91,7 @@ class AmfExporter : public Exporter */ AmfExporter(std::string fileName, const std::map &meta, - bool compress = false); + bool compress = true); /// Writes AMF footer ~AmfExporter(); diff --git a/src/Mod/Mesh/Gui/DlgSettingsImportExport.ui b/src/Mod/Mesh/Gui/DlgSettingsImportExport.ui index 6b1024869748..925fb121ade3 100644 --- a/src/Mod/Mesh/Gui/DlgSettingsImportExport.ui +++ b/src/Mod/Mesh/Gui/DlgSettingsImportExport.ui @@ -35,19 +35,6 @@ - - - - Defines the deviation of tessellation to the actual surface - - - <html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg 2; font-size:7.8pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Tessellation</span></p><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;"></p><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;"><span style=" font-weight:400;">Defines the maximum deviation of the tessellated mesh to the surface. The smaller the value is the slower the render speed and the nicer the appearance are.</span></p></body></html> - - - Maximum mesh deviation - - - @@ -67,6 +54,39 @@ + + + + Defines the deviation of tessellation to the actual surface + + + <html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg 2; font-size:7.8pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Tessellation</span></p><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;"></p><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;"><span style=" font-weight:400;">Defines the maximum deviation of the tessellated mesh to the surface. The smaller the value is the slower the render speed and the nicer the appearance are.</span></p></body></html> + + + Maximum mesh deviation + + + + + + + Export AMF files using compression + + + + + + + + + + ExportAmfCompressed + + + Mod/Mesh + + + @@ -79,6 +99,11 @@ Gui::QuantitySpinBox QWidget +
Gui/PrefWidgets.h
+
+ + Gui::PrefCheckBox + QCheckBox
Gui/PrefWidgets.h
diff --git a/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.cpp b/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.cpp index c03988c0a089..72746c417403 100644 --- a/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.cpp +++ b/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.cpp @@ -46,6 +46,8 @@ void DlgSettingsImportExport::saveSettings() ("User parameter:BaseApp/Preferences/Mod/Mesh"); double value = ui->maxDeviationExport->value().getValue(); handle->SetFloat("MaxDeviationExport", value); + + ui->exportAmfCompressed->onSave(); } void DlgSettingsImportExport::loadSettings() @@ -55,6 +57,8 @@ void DlgSettingsImportExport::loadSettings() double value = ui->maxDeviationExport->value().getValue(); value = handle->GetFloat("MaxDeviationExport", value); ui->maxDeviationExport->setValue(value); + + ui->exportAmfCompressed->onRestore(); } /**