23
#include "PreCompiled.h"
29
#include <Gui/Application.h>
30
#include <Gui/Command.h>
31
#include <Gui/MenuManager.h>
32
#include <Gui/Selection.h>
33
#include <Gui/TaskView/TaskView.h>
34
#include <Gui/ToolBarManager.h>
35
#include <Mod/Mesh/App/MeshFeature.h>
40
using namespace MeshGui;
43
qApp->translate("Workbench", "Analyze");
44
qApp->translate("Workbench", "Boolean");
45
qApp->translate("Workbench", "&Meshes");
46
qApp->translate("Workbench", "Cutting");
47
qApp->translate("Workbench", "Mesh tools");
48
qApp->translate("Workbench", "Mesh modify");
49
qApp->translate("Workbench", "Mesh boolean");
50
qApp->translate("Workbench", "Mesh cutting");
51
qApp->translate("Workbench", "Mesh segmentation");
52
qApp->translate("Workbench", "Mesh analyze");
56
TYPESYSTEM_SOURCE(MeshGui::Workbench, Gui::StdWorkbench)
58
Workbench::Workbench() = default;
60
class MeshInfoWatcher: public Gui::TaskView::TaskWatcher, public Gui::SelectionObserver
64
: TaskWatcher(nullptr)
67
labelPoints = new QLabel();
68
labelPoints->setText(tr("Number of points:"));
70
labelFacets = new QLabel();
71
labelFacets->setText(tr("Number of facets:"));
73
numPoints = new QLabel();
74
numFacets = new QLabel();
76
labelMin = new QLabel();
77
labelMin->setText(tr("Minimum bound:"));
79
labelMax = new QLabel();
80
labelMax->setText(tr("Maximum bound:"));
82
numMin = new QLabel();
83
numMax = new QLabel();
86
QGroupBox* box = new QGroupBox();
87
box->setTitle(tr("Mesh info box"));
88
box->setWindowTitle(tr("Mesh info"));
90
QGridLayout* grid = new QGridLayout(box);
91
grid->addWidget(labelPoints, 0, 0);
92
grid->addWidget(numPoints, 0, 1);
93
grid->addWidget(labelFacets, 1, 0);
94
grid->addWidget(numFacets, 1, 1);
96
grid->addWidget(labelMin, 2, 0);
97
grid->addWidget(numMin, 2, 1);
98
grid->addWidget(labelMax, 3, 0);
99
grid->addWidget(numMax, 3, 1);
101
addTaskBox(box, false);
103
bool shouldShow() override
107
void onSelectionChanged(const Gui::SelectionChanges&) override
109
Base::BoundBox3d bbox;
110
unsigned long countPoints = 0, countFacets = 0;
111
std::vector<Mesh::Feature*> mesh = Gui::Selection().getObjectsOfType<Mesh::Feature>();
112
for (auto it : mesh) {
113
countPoints += it->Mesh.getValue().countPoints();
114
countFacets += it->Mesh.getValue().countFacets();
115
bbox.Add(it->Mesh.getBoundingBox());
118
if (countPoints > 0) {
119
numPoints->setText(QString::number(countPoints));
120
numFacets->setText(QString::number(countFacets));
121
numMin->setText(tr("X: %1\tY: %2\tZ: %3").arg(bbox.MinX).arg(bbox.MinY).arg(bbox.MinZ));
122
numMax->setText(tr("X: %1\tY: %2\tZ: %3").arg(bbox.MaxX).arg(bbox.MaxY).arg(bbox.MaxZ));
125
numPoints->setText(QString::fromLatin1(""));
126
numFacets->setText(QString::fromLatin1(""));
127
numMin->setText(QString::fromLatin1(""));
128
numMax->setText(QString::fromLatin1(""));
143
void Workbench::activated()
145
Gui::Workbench::activated();
147
std::vector<Gui::TaskView::TaskWatcher*> Watcher;
148
Watcher.push_back(new MeshInfoWatcher);
149
addTaskWatcher(Watcher);
152
void Workbench::deactivated()
154
Gui::Workbench::deactivated();
158
void Workbench::setupContextMenu(const char* recipient, Gui::MenuItem* item) const
160
StdWorkbench::setupContextMenu(recipient, item);
161
if (Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0) {
165
<< "Mesh_VertexCurvature";
169
Gui::MenuItem* Workbench::setupMenuBar() const
171
Gui::MenuItem* root = StdWorkbench::setupMenuBar();
172
Gui::MenuItem* item = root->findItem("&Windows");
173
Gui::MenuItem* mesh = new Gui::MenuItem;
174
root->insertItem(item, mesh);
177
Gui::MenuItem* analyze = new Gui::MenuItem;
178
analyze->setCommand("Analyze");
179
*analyze << "Mesh_Evaluation"
180
<< "Mesh_EvaluateFacet"
181
<< "Mesh_CurvatureInfo"
183
<< "Mesh_EvaluateSolid"
184
<< "Mesh_BoundingBox";
187
Gui::MenuItem* boolean = new Gui::MenuItem;
188
boolean->setCommand("Boolean");
189
*boolean << "Mesh_Union"
190
<< "Mesh_Intersection"
191
<< "Mesh_Difference";
194
Gui::MenuItem* cutting = new Gui::MenuItem;
195
cutting->setCommand("Cutting");
196
*cutting << "Mesh_PolyCut"
199
<< "Mesh_TrimByPlane"
200
<< "Mesh_SectionByPlane"
201
<< "Mesh_CrossSections";
203
mesh->setCommand("&Meshes");
204
*mesh << "Mesh_Import"
206
<< "Mesh_FromPartShape"
208
<< "Separator" << analyze << "Mesh_VertexCurvature"
209
<< "Mesh_HarmonizeNormals"
210
<< "Mesh_FlipNormals"
212
<< "Mesh_FillupHoles"
213
<< "Mesh_FillInteractiveHole"
215
<< "Mesh_RemoveComponents"
216
<< "Mesh_RemoveCompByHand"
217
<< "Mesh_Segmentation"
218
<< "Mesh_SegmentationBestFit"
224
<< "Mesh_BuildRegularSolid" << boolean << cutting << "Separator"
226
<< "Mesh_SplitComponents"
228
Gui::CommandManager& mgr = Gui::Application::Instance->commandManager();
229
if (mgr.getCommandByName("MeshPart_CreateFlatMesh")) {
230
*mesh << "MeshPart_CreateFlatMesh";
232
if (mgr.getCommandByName("MeshPart_CreateFlatFace")) {
233
*mesh << "MeshPart_CreateFlatFace";
238
Gui::ToolBarItem* Workbench::setupToolBars() const
240
Gui::ToolBarItem* root = StdWorkbench::setupToolBars();
242
Gui::ToolBarItem* mesh = new Gui::ToolBarItem(root);
243
mesh->setCommand("Mesh tools");
244
*mesh << "Mesh_Import"
246
<< "Mesh_FromPartShape"
247
<< "Mesh_BuildRegularSolid";
249
Gui::ToolBarItem* modifying = new Gui::ToolBarItem(root);
250
modifying->setCommand("Mesh modify");
251
*modifying << "Mesh_HarmonizeNormals"
252
<< "Mesh_FlipNormals"
253
<< "Mesh_FillupHoles"
254
<< "Mesh_FillInteractiveHole"
256
<< "Mesh_RemoveComponents"
262
Gui::ToolBarItem* boolean = new Gui::ToolBarItem(root);
263
boolean->setCommand("Mesh boolean");
264
*boolean << "Mesh_Union"
265
<< "Mesh_Intersection"
266
<< "Mesh_Difference";
268
Gui::ToolBarItem* cutting = new Gui::ToolBarItem(root);
269
cutting->setCommand("Mesh cutting");
270
*cutting << "Mesh_PolyCut"
272
<< "Mesh_TrimByPlane"
273
<< "Mesh_SectionByPlane"
274
<< "Mesh_CrossSections";
276
Gui::ToolBarItem* compseg = new Gui::ToolBarItem(root);
277
compseg->setCommand("Mesh segmentation");
278
*compseg << "Mesh_Merge"
279
<< "Mesh_SplitComponents"
280
<< "Mesh_Segmentation"
281
<< "Mesh_SegmentationBestFit";
283
Gui::ToolBarItem* analyze = new Gui::ToolBarItem(root);
284
analyze->setCommand("Mesh analyze");
285
*analyze << "Mesh_Evaluation"
286
<< "Mesh_EvaluateFacet"
287
<< "Mesh_VertexCurvature"
288
<< "Mesh_CurvatureInfo"
289
<< "Mesh_EvaluateSolid"
290
<< "Mesh_BoundingBox";
296
Gui::ToolBarItem* Workbench::setupCommandBars() const
299
Gui::ToolBarItem* root = new Gui::ToolBarItem;
300
Gui::ToolBarItem* mesh;
302
mesh = new Gui::ToolBarItem(root);
303
mesh->setCommand("Mesh tools");
304
*mesh << "Mesh_Import"
308
mesh = new Gui::ToolBarItem(root);
309
mesh->setCommand("Mesh test suite");
310
*mesh << "Mesh_Demolding"