Merge pull request #78 from ianrrees/20160119-mesh-export-tolerance-preference

Added ability to change mesh export tolerance.
This commit is contained in:
Yorik van Havre 2016-01-19 10:52:21 -02:00
commit 5364a17c50
6 changed files with 231 additions and 5 deletions

View File

@ -190,14 +190,20 @@ static PyObject * importer(PyObject *self, PyObject *args)
static PyObject * exporter(PyObject *self, PyObject *args) static PyObject * exporter(PyObject *self, PyObject *args)
{ {
PyObject* object; PyObject *object;
char* Name; char *Name;
if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name))
// If tolerance is specified via python interface, use that.
// If not, use the preference, if that exists, else default to 0.1mm.
auto hGrp(App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Mesh") );
float fTolerance = hGrp->GetFloat( "MaxDeviationExport", 0.1f );
if (!PyArg_ParseTuple(args, "Oet|f", &object, "utf-8", &Name, &fTolerance))
return NULL; return NULL;
std::string EncodedName = std::string(Name); std::string EncodedName = std::string(Name);
PyMem_Free(Name); PyMem_Free(Name);
float fTolerance = 0.1f;
MeshObject global_mesh; MeshObject global_mesh;
PY_TRY { PY_TRY {
@ -535,7 +541,8 @@ PyDoc_STRVAR(inst_doc,
"insert(string|mesh,[string]) -- Load or insert a mesh into the given or active document."); "insert(string|mesh,[string]) -- Load or insert a mesh into the given or active document.");
PyDoc_STRVAR(export_doc, PyDoc_STRVAR(export_doc,
"export(list,string) -- Export a list of objects into a single file."); "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.");
PyDoc_STRVAR(calculateEigenTransform_doc, PyDoc_STRVAR(calculateEigenTransform_doc,
"calculateEigenTransform(seq(Base.Vector)) -- Calculates the eigen Transformation from a list of points.\n" "calculateEigenTransform(seq(Base.Vector)) -- Calculates the eigen Transformation from a list of points.\n"

View File

@ -39,6 +39,7 @@
#include "DlgEvaluateMeshImp.h" #include "DlgEvaluateMeshImp.h"
#include "PropertyEditorMesh.h" #include "PropertyEditorMesh.h"
#include "DlgSettingsMeshView.h" #include "DlgSettingsMeshView.h"
#include "DlgSettingsImportExportImp.h"
#include "SoFCMeshObject.h" #include "SoFCMeshObject.h"
#include "SoFCIndexedFaceSet.h" #include "SoFCIndexedFaceSet.h"
#include "SoPolygon.h" #include "SoPolygon.h"
@ -96,6 +97,7 @@ void MeshGuiExport initMeshGui()
// register preferences pages // register preferences pages
(void)new Gui::PrefPageProducer<MeshGui::DlgSettingsMeshView> ("Display"); (void)new Gui::PrefPageProducer<MeshGui::DlgSettingsMeshView> ("Display");
(void)new Gui::PrefPageProducer<MeshGui::DlgSettingsImportExport> ( QT_TRANSLATE_NOOP("QObject", "Import-Export") );
MeshGui::SoFCMeshObjectElement ::initClass(); MeshGui::SoFCMeshObjectElement ::initClass();
MeshGui::SoSFMeshObject ::initClass(); MeshGui::SoSFMeshObject ::initClass();

View File

@ -19,6 +19,8 @@ set(Mesh_MOC_HDRS
DlgEvaluateMeshImp.h DlgEvaluateMeshImp.h
DlgRegularSolidImp.h DlgRegularSolidImp.h
DlgSettingsMeshView.h DlgSettingsMeshView.h
DlgSettingsImportExportImp.h
DlgSmoothing.h DlgSmoothing.h
MeshEditor.h MeshEditor.h
PropertyEditorMesh.h PropertyEditorMesh.h
@ -32,6 +34,7 @@ set(Dialogs_UIC_SRCS
DlgEvaluateMesh.ui DlgEvaluateMesh.ui
DlgRegularSolid.ui DlgRegularSolid.ui
DlgSettingsMeshView.ui DlgSettingsMeshView.ui
DlgSettingsImportExport.ui
DlgSmoothing.ui DlgSmoothing.ui
RemoveComponents.ui RemoveComponents.ui
Segmentation.ui Segmentation.ui
@ -49,6 +52,8 @@ SET(Dialogs_SRCS
DlgSettingsMeshView.ui DlgSettingsMeshView.ui
DlgSettingsMeshView.cpp DlgSettingsMeshView.cpp
DlgSettingsMeshView.h DlgSettingsMeshView.h
DlgSettingsImportExportImp.cpp
DlgSettingsImportExportImp.h
DlgSmoothing.ui DlgSmoothing.ui
DlgSmoothing.cpp DlgSmoothing.cpp
DlgSmoothing.h DlgSmoothing.h

View File

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MeshGui::DlgSettingsImportExport</class>
<widget class="QWidget" name="MeshGui::DlgSettingsImportExport">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>539</width>
<height>339</height>
</rect>
</property>
<property name="windowTitle">
<string>Mesh Formats</string>
</property>
<layout class="QGridLayout">
<item row="1" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>61</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="GroupBox12">
<property name="title">
<string>Export</string>
</property>
<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::PrefDoubleSpinBox" name="maxDeviationExport">
<property name="suffix">
<string>mm</string>
</property>
<property name="decimals">
<number>4</number>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>100000000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
<property name="value">
<double>0.100000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<cstring>MaxDeviationExport</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Mesh</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>Gui::PrefDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,60 @@
/***************************************************************************
* Copyright (c) 2016 Ian Rees <ian.rees@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#include "DlgSettingsImportExportImp.h"
#include "ui_DlgSettingsImportExport.h"
using namespace MeshGui;
DlgSettingsImportExport::DlgSettingsImportExport(QWidget* parent)
: PreferencePage(parent), ui(new Ui_DlgSettingsImportExport)
{
ui->setupUi(this);
}
void DlgSettingsImportExport::saveSettings()
{
ui->maxDeviationExport->onSave();
}
void DlgSettingsImportExport::loadSettings()
{
ui->maxDeviationExport->onRestore();
}
/**
* Sets the strings of the subwidgets using the current language.
*/
void DlgSettingsImportExport::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(this);
}
else {
QWidget::changeEvent(e);
}
}
#include "moc_DlgSettingsImportExportImp.cpp"

View File

@ -0,0 +1,56 @@
/***************************************************************************
* Copyright (c) 2016 Ian Rees <ian.rees@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef MESHGUI_DLGSETTINGSIMPORTEXPORTIMP_H
#define MESHGUI_DLGSETTINGSIMPORTEXPORTIMP_H
#include <Gui/PropertyPage.h>
namespace MeshGui {
class Ui_DlgSettingsImportExport;
/**
* The DlgSettingsImportExportImp class implements a preference page to change settings
* for Importing and Exporting mesh objects.
*/
class DlgSettingsImportExport : public Gui::Dialog::PreferencePage
{
Q_OBJECT
public:
DlgSettingsImportExport(QWidget *parent=nullptr);
~DlgSettingsImportExport() = default;
protected:
void saveSettings();
void loadSettings();
void changeEvent(QEvent *e);
private:
std::auto_ptr<Ui_DlgSettingsImportExport> ui;
}; // end class DlgSettingsImportExport
} // namespace MeshGui
#endif // MESHGUI_DLGSETTINGSIMPORTEXPORTIMP_H