Add setting to export compressed/uncompressed AMFs

This commit is contained in:
Ian Rees 2016-01-24 11:58:30 +13:00 committed by wmayer
parent e178d93c61
commit 3792f259d3
4 changed files with 79 additions and 34 deletions

View File

@ -84,9 +84,13 @@ public:
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 @@ private:
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) );
if (!PyArg_ParseTuple(args.ptr(), "Oet|f", &object, "utf-8", &Name, &fTolerance))
int exportAmfCompressed( hGrp->GetBool("ExportAmfCompressed", true) );
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> exporter;
if (exportFormat == MeshIO::AMF) {
std::map<std::string, std::string> meta;
meta["cad"] = App::Application::Config()["ExeName"] + " " +
App::Application::Config()["ExeVersion"];
meta[App::Application::Config()["ExeName"] + "-buildRevisionHash"] =
App::Application::Config()["BuildRevisionHash"];
std::map<std::string, std::string> 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 @@ private:
return Py::None();
}
Py::Object show(const Py::Tuple& args)
{
PyObject *pcObj;

View File

@ -91,7 +91,7 @@ class AmfExporter : public Exporter
*/
AmfExporter(std::string fileName,
const std::map<std::string, std::string> &meta,
bool compress = false);
bool compress = true);
/// Writes AMF footer
~AmfExporter();

View File

@ -35,19 +35,6 @@
<layout class="QGridLayout">
<item row="0" column="0">
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="textLabel1">
<property name="toolTip">
<string>Defines the deviation of tessellation to the actual surface</string>
</property>
<property name="whatsThis">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;/head&gt;&lt;body style=&quot; white-space: pre-wrap; font-family:MS Shell Dlg 2; font-size:7.8pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Tessellation&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;&quot;&gt;&lt;span style=&quot; font-weight:400;&quot;&gt;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.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Maximum mesh deviation</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::QuantitySpinBox" name="maxDeviationExport">
<property name="unit" stdset="0">
@ -67,6 +54,39 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="textLabel1">
<property name="toolTip">
<string>Defines the deviation of tessellation to the actual surface</string>
</property>
<property name="whatsThis">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;/head&gt;&lt;body style=&quot; white-space: pre-wrap; font-family:MS Shell Dlg 2; font-size:7.8pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Tessellation&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;&quot;&gt;&lt;span style=&quot; font-weight:400;&quot;&gt;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.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Maximum mesh deviation</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="textLabel2">
<property name="text">
<string>Export AMF files using compression</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::PrefCheckBox" name="exportAmfCompressed">
<property name="text">
<string/>
</property>
<property name="prefEntry" stdset="0">
<cstring>ExportAmfCompressed</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Mesh</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@ -79,6 +99,11 @@
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>

View File

@ -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();
}
/**