Add setting to export compressed/uncompressed AMFs
This commit is contained in:
parent
e178d93c61
commit
3792f259d3
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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><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></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><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></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>
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user