0001232: Create Mesh from geometry / Export mesh
This commit is contained in:
parent
12046e91c2
commit
43cb48caec
|
@ -209,7 +209,6 @@ Gui::MenuItem* Workbench::setupMenuBar() const
|
|||
mesh->setCommand("&Meshes");
|
||||
*mesh << "Mesh_Import"
|
||||
<< "Mesh_Export"
|
||||
<< "Mesh_FromGeometry"
|
||||
<< "MeshPart_Mesher"
|
||||
<< "Separator"
|
||||
<< analyze
|
||||
|
|
|
@ -185,7 +185,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
|
|||
*boolean << "Mesh_Union" << "Mesh_Intersection" << "Mesh_Difference";
|
||||
|
||||
mesh->setCommand("&Meshes");
|
||||
*mesh << "Mesh_Import" << "Mesh_Export" << "Mesh_FromGeometry" << "Separator"
|
||||
*mesh << "Mesh_Import" << "Mesh_Export" << "MeshPart_Mesher" << "Separator"
|
||||
<< analyze << "Mesh_HarmonizeNormals" << "Mesh_FlipNormals" << "Separator"
|
||||
<< "Mesh_FillupHoles" << "Mesh_FillInteractiveHole" << "Mesh_RemoveComponents"
|
||||
<< "Mesh_RemoveCompByHand" << "Mesh_AddFacet" << "Mesh_Smoothing" << "Separator"
|
||||
|
|
|
@ -69,6 +69,10 @@ class MeshWorkbench ( Workbench ):
|
|||
def Initialize(self):
|
||||
# load the module
|
||||
import MeshGui
|
||||
try:
|
||||
import MeshPartGui
|
||||
except:
|
||||
pass
|
||||
def GetClassName(self):
|
||||
return "MeshGui::Workbench"
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <Gui/Command.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/ViewProvider.h>
|
||||
#include <Gui/WaitCursor.h>
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
|
@ -48,7 +49,7 @@ Tessellation::Tessellation(QWidget* parent)
|
|||
: QWidget(parent), ui(new Ui_Tessellation)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
Gui::Command::doCommand(Gui::Command::Doc, "import MeshPart");
|
||||
Gui::Command::doCommand(Gui::Command::Doc, "import Mesh, MeshPart");
|
||||
findShapes();
|
||||
}
|
||||
|
||||
|
@ -56,6 +57,20 @@ Tessellation::~Tessellation()
|
|||
{
|
||||
}
|
||||
|
||||
void Tessellation::on_checkSimpleMethod_toggled(bool on)
|
||||
{
|
||||
if (!on) {
|
||||
if (ui->checkMaxEdgeLength->isChecked()) {
|
||||
ui->checkMaxEdgeLength->setEnabled(true);
|
||||
ui->spinMaxEdgeLength->setEnabled(true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui->checkMaxEdgeLength->setEnabled(false);
|
||||
ui->spinMaxEdgeLength->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void Tessellation::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
|
@ -74,6 +89,8 @@ void Tessellation::findShapes()
|
|||
this->document = QString::fromAscii(activeDoc->getName());
|
||||
std::vector<Part::Feature*> objs = activeDoc->getObjectsOfType<Part::Feature>();
|
||||
|
||||
double edgeLen = 0;
|
||||
bool foundSelection = false;
|
||||
for (std::vector<Part::Feature*>::iterator it = objs.begin(); it!=objs.end(); ++it) {
|
||||
const TopoDS_Shape& shape = (*it)->Shape.getValue();
|
||||
if (shape.IsNull()) continue;
|
||||
|
@ -85,6 +102,10 @@ void Tessellation::findShapes()
|
|||
}
|
||||
|
||||
if (hasfaces) {
|
||||
Base::BoundBox3d bbox = (*it)->Shape.getBoundingBox();
|
||||
edgeLen = std::max<double>(edgeLen, bbox.LengthX());
|
||||
edgeLen = std::max<double>(edgeLen, bbox.LengthY());
|
||||
edgeLen = std::max<double>(edgeLen, bbox.LengthZ());
|
||||
QString label = QString::fromUtf8((*it)->Label.getValue());
|
||||
QString name = QString::fromAscii((*it)->getNameInDocument());
|
||||
|
||||
|
@ -95,8 +116,16 @@ void Tessellation::findShapes()
|
|||
Gui::ViewProvider* vp = activeGui->getViewProvider(*it);
|
||||
if (vp) child->setIcon(0, vp->getIcon());
|
||||
ui->treeWidget->addTopLevelItem(child);
|
||||
if (Gui::Selection().isSelected(*it)) {
|
||||
child->setSelected(true);
|
||||
foundSelection = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ui->spinMaxEdgeLength->setValue(edgeLen/10);
|
||||
if (foundSelection)
|
||||
ui->treeWidget->hide();
|
||||
}
|
||||
|
||||
bool Tessellation::accept()
|
||||
|
@ -117,7 +146,19 @@ bool Tessellation::accept()
|
|||
try {
|
||||
QString shape, label;
|
||||
Gui::WaitCursor wc;
|
||||
|
||||
|
||||
bool simple = ui->checkSimpleMethod->isChecked();
|
||||
double devFace = ui->spinDeviation->value();
|
||||
if (!ui->spinDeviation->isEnabled()) {
|
||||
if (simple)
|
||||
devFace = 0.1;
|
||||
else
|
||||
devFace = 0;
|
||||
}
|
||||
double maxEdge = ui->spinMaxEdgeLength->value();
|
||||
if (!ui->spinMaxEdgeLength->isEnabled())
|
||||
maxEdge = 0;
|
||||
|
||||
activeDoc->openTransaction("Meshing");
|
||||
QList<QTreeWidgetItem *> items = ui->treeWidget->selectedItems();
|
||||
std::vector<Part::Feature*> shapes = Gui::Selection().getObjectsOfType<Part::Feature>();
|
||||
|
@ -125,17 +166,32 @@ bool Tessellation::accept()
|
|||
shape = (*it)->data(0, Qt::UserRole).toString();
|
||||
label = (*it)->text(0);
|
||||
|
||||
QString cmd = QString::fromAscii(
|
||||
"__doc__=FreeCAD.getDocument(\"%1\")\n"
|
||||
"__mesh__=__doc__.addObject(\"Mesh::Feature\",\"Mesh\")\n"
|
||||
"__mesh__.Mesh=MeshPart.meshFromShape(__doc__.getObject(\"%2\").Shape,%3,0,0,%4)\n"
|
||||
"__mesh__.Label=\"%5 (Meshed)\"\n"
|
||||
"del __doc__, __mesh__\n")
|
||||
.arg(this->document)
|
||||
.arg(shape)
|
||||
.arg(ui->spinMaxEdgeLength->value())
|
||||
.arg(ui->spinDeviation->value())
|
||||
.arg(label);
|
||||
QString cmd;
|
||||
if (simple) {
|
||||
cmd = QString::fromAscii(
|
||||
"__doc__=FreeCAD.getDocument(\"%1\")\n"
|
||||
"__mesh__=__doc__.addObject(\"Mesh::Feature\",\"Mesh\")\n"
|
||||
"__mesh__.Mesh=Mesh.Mesh(__doc__.getObject(\"%2\").Shape.tessellate(%3))\n"
|
||||
"__mesh__.Label=\"%4 (Meshed)\"\n"
|
||||
"del __doc__, __mesh__\n")
|
||||
.arg(this->document)
|
||||
.arg(shape)
|
||||
.arg(devFace)
|
||||
.arg(label);
|
||||
}
|
||||
else {
|
||||
cmd = QString::fromAscii(
|
||||
"__doc__=FreeCAD.getDocument(\"%1\")\n"
|
||||
"__mesh__=__doc__.addObject(\"Mesh::Feature\",\"Mesh\")\n"
|
||||
"__mesh__.Mesh=MeshPart.meshFromShape(__doc__.getObject(\"%2\").Shape,%3,0,0,%4)\n"
|
||||
"__mesh__.Label=\"%5 (Meshed)\"\n"
|
||||
"del __doc__, __mesh__\n")
|
||||
.arg(this->document)
|
||||
.arg(shape)
|
||||
.arg(maxEdge)
|
||||
.arg(devFace)
|
||||
.arg(label);
|
||||
}
|
||||
Gui::Command::doCommand(Gui::Command::Doc, (const char*)cmd.toAscii());
|
||||
}
|
||||
activeDoc->commitTransaction();
|
||||
|
|
|
@ -47,6 +47,9 @@ protected:
|
|||
private:
|
||||
void findShapes();
|
||||
|
||||
private Q_SLOTS:
|
||||
void on_checkSimpleMethod_toggled(bool);
|
||||
|
||||
private:
|
||||
QString document;
|
||||
std::auto_ptr<Ui_Tessellation> ui;
|
||||
|
|
|
@ -31,58 +31,69 @@
|
|||
<property name="title">
|
||||
<string>Settings</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="checkDeviation">
|
||||
<property name="text">
|
||||
<string>Surface deviation:</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QDoubleSpinBox" name="spinDeviation">
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>0.001000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="checkMaxEdgeLength">
|
||||
<property name="text">
|
||||
<string>Max. edge length:</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDoubleSpinBox" name="spinMaxEdgeLength">
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>0.001000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="checkDeviation">
|
||||
<property name="text">
|
||||
<string>Surface deviation:</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QDoubleSpinBox" name="spinDeviation">
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>0.001000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="checkSimpleMethod">
|
||||
<property name="text">
|
||||
<string>Use simplified mesh generation method</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="checkMaxEdgeLength">
|
||||
<property name="text">
|
||||
<string>Max. edge length:</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QDoubleSpinBox" name="spinMaxEdgeLength">
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>0.001000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
@ -93,6 +104,7 @@
|
|||
<tabstop>treeWidget</tabstop>
|
||||
<tabstop>checkDeviation</tabstop>
|
||||
<tabstop>spinDeviation</tabstop>
|
||||
<tabstop>checkSimpleMethod</tabstop>
|
||||
<tabstop>checkMaxEdgeLength</tabstop>
|
||||
<tabstop>spinMaxEdgeLength</tabstop>
|
||||
</tabstops>
|
||||
|
@ -105,12 +117,12 @@
|
|||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>84</x>
|
||||
<y>375</y>
|
||||
<x>104</x>
|
||||
<y>359</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>219</x>
|
||||
<y>380</y>
|
||||
<x>308</x>
|
||||
<y>360</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
|
|
Loading…
Reference in New Issue
Block a user