FreeCAD

Форк
0
/
Workbench.cpp 
315 строк · 10.3 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
#include <QGroupBox>
26
#include <QLabel>
27
#endif
28

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>
36

37
#include "Workbench.h"
38

39

40
using namespace MeshGui;
41

42
#if 0  // needed for Qt's lupdate utility
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");
53
#endif
54

55
/// @namespace MeshGui @class Workbench
56
TYPESYSTEM_SOURCE(MeshGui::Workbench, Gui::StdWorkbench)
57

58
Workbench::Workbench() = default;
59

60
class MeshInfoWatcher: public Gui::TaskView::TaskWatcher, public Gui::SelectionObserver
61
{
62
public:
63
    MeshInfoWatcher()
64
        : TaskWatcher(nullptr)
65
    {
66
        // NOLINTBEGIN
67
        labelPoints = new QLabel();
68
        labelPoints->setText(tr("Number of points:"));
69

70
        labelFacets = new QLabel();
71
        labelFacets->setText(tr("Number of facets:"));
72

73
        numPoints = new QLabel();
74
        numFacets = new QLabel();
75

76
        labelMin = new QLabel();
77
        labelMin->setText(tr("Minimum bound:"));
78

79
        labelMax = new QLabel();
80
        labelMax->setText(tr("Maximum bound:"));
81

82
        numMin = new QLabel();
83
        numMax = new QLabel();
84
        // NOLINTEND
85

86
        QGroupBox* box = new QGroupBox();
87
        box->setTitle(tr("Mesh info box"));
88
        box->setWindowTitle(tr("Mesh info"));
89
        // box->setAutoFillBackground(true);
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);
95

96
        grid->addWidget(labelMin, 2, 0);
97
        grid->addWidget(numMin, 2, 1);
98
        grid->addWidget(labelMax, 3, 0);
99
        grid->addWidget(numMax, 3, 1);
100

101
        addTaskBox(box, false);
102
    }
103
    bool shouldShow() override
104
    {
105
        return true;
106
    }
107
    void onSelectionChanged(const Gui::SelectionChanges&) override
108
    {
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());
116
        }
117

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));
123
        }
124
        else {
125
            numPoints->setText(QString::fromLatin1(""));
126
            numFacets->setText(QString::fromLatin1(""));
127
            numMin->setText(QString::fromLatin1(""));
128
            numMax->setText(QString::fromLatin1(""));
129
        }
130
    }
131

132
private:
133
    QLabel* labelPoints;
134
    QLabel* numPoints;
135
    QLabel* labelFacets;
136
    QLabel* numFacets;
137
    QLabel* labelMin;
138
    QLabel* numMin;
139
    QLabel* labelMax;
140
    QLabel* numMax;
141
};
142

143
void Workbench::activated()
144
{
145
    Gui::Workbench::activated();
146

147
    std::vector<Gui::TaskView::TaskWatcher*> Watcher;
148
    Watcher.push_back(new MeshInfoWatcher);
149
    addTaskWatcher(Watcher);
150
}
151

152
void Workbench::deactivated()
153
{
154
    Gui::Workbench::deactivated();
155
    removeTaskWatcher();
156
}
157

158
void Workbench::setupContextMenu(const char* recipient, Gui::MenuItem* item) const
159
{
160
    StdWorkbench::setupContextMenu(recipient, item);
161
    if (Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0) {
162
        *item << "Separator"
163
              << "Mesh_Import"
164
              << "Mesh_Export"
165
              << "Mesh_VertexCurvature";
166
    }
167
}
168

169
Gui::MenuItem* Workbench::setupMenuBar() const
170
{
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);
175

176
    // analyze
177
    Gui::MenuItem* analyze = new Gui::MenuItem;
178
    analyze->setCommand("Analyze");
179
    *analyze << "Mesh_Evaluation"
180
             << "Mesh_EvaluateFacet"
181
             << "Mesh_CurvatureInfo"
182
             << "Separator"
183
             << "Mesh_EvaluateSolid"
184
             << "Mesh_BoundingBox";
185

186
    // boolean
187
    Gui::MenuItem* boolean = new Gui::MenuItem;
188
    boolean->setCommand("Boolean");
189
    *boolean << "Mesh_Union"
190
             << "Mesh_Intersection"
191
             << "Mesh_Difference";
192

193
    // cutting
194
    Gui::MenuItem* cutting = new Gui::MenuItem;
195
    cutting->setCommand("Cutting");
196
    *cutting << "Mesh_PolyCut"
197
             << "Mesh_PolyTrim"
198
             //<< "Mesh_PolySegm"
199
             << "Mesh_TrimByPlane"
200
             << "Mesh_SectionByPlane"
201
             << "Mesh_CrossSections";
202

203
    mesh->setCommand("&Meshes");
204
    *mesh << "Mesh_Import"
205
          << "Mesh_Export"
206
          << "Mesh_FromPartShape"
207
          << "Mesh_RemeshGmsh"
208
          << "Separator" << analyze << "Mesh_VertexCurvature"
209
          << "Mesh_HarmonizeNormals"
210
          << "Mesh_FlipNormals"
211
          << "Separator"
212
          << "Mesh_FillupHoles"
213
          << "Mesh_FillInteractiveHole"
214
          << "Mesh_AddFacet"
215
          << "Mesh_RemoveComponents"
216
          << "Mesh_RemoveCompByHand"
217
          << "Mesh_Segmentation"
218
          << "Mesh_SegmentationBestFit"
219
          << "Separator"
220
          << "Mesh_Smoothing"
221
          << "Mesh_Decimating"
222
          << "Mesh_Scale"
223
          << "Separator"
224
          << "Mesh_BuildRegularSolid" << boolean << cutting << "Separator"
225
          << "Mesh_Merge"
226
          << "Mesh_SplitComponents"
227
          << "Separator";
228
    Gui::CommandManager& mgr = Gui::Application::Instance->commandManager();
229
    if (mgr.getCommandByName("MeshPart_CreateFlatMesh")) {
230
        *mesh << "MeshPart_CreateFlatMesh";
231
    }
232
    if (mgr.getCommandByName("MeshPart_CreateFlatFace")) {
233
        *mesh << "MeshPart_CreateFlatFace";
234
    }
235
    return root;
236
}
237

238
Gui::ToolBarItem* Workbench::setupToolBars() const
239
{
240
    Gui::ToolBarItem* root = StdWorkbench::setupToolBars();
241

242
    Gui::ToolBarItem* mesh = new Gui::ToolBarItem(root);
243
    mesh->setCommand("Mesh tools");
244
    *mesh << "Mesh_Import"
245
          << "Mesh_Export"
246
          << "Mesh_FromPartShape"
247
          << "Mesh_BuildRegularSolid";
248

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"
255
               << "Mesh_AddFacet"
256
               << "Mesh_RemoveComponents"
257
               << "Mesh_Smoothing"
258
               << "Mesh_RemeshGmsh"
259
               << "Mesh_Decimating"
260
               << "Mesh_Scale";
261

262
    Gui::ToolBarItem* boolean = new Gui::ToolBarItem(root);
263
    boolean->setCommand("Mesh boolean");
264
    *boolean << "Mesh_Union"
265
             << "Mesh_Intersection"
266
             << "Mesh_Difference";
267

268
    Gui::ToolBarItem* cutting = new Gui::ToolBarItem(root);
269
    cutting->setCommand("Mesh cutting");
270
    *cutting << "Mesh_PolyCut"
271
             << "Mesh_PolyTrim"
272
             << "Mesh_TrimByPlane"
273
             << "Mesh_SectionByPlane"
274
             << "Mesh_CrossSections";
275

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";
282

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";
291

292

293
    return root;
294
}
295

296
Gui::ToolBarItem* Workbench::setupCommandBars() const
297
{
298
    // Mesh tools
299
    Gui::ToolBarItem* root = new Gui::ToolBarItem;
300
    Gui::ToolBarItem* mesh;
301

302
    mesh = new Gui::ToolBarItem(root);
303
    mesh->setCommand("Mesh tools");
304
    *mesh << "Mesh_Import"
305
          << "Mesh_Export"
306
          << "Mesh_PolyCut";
307

308
    mesh = new Gui::ToolBarItem(root);
309
    mesh->setCommand("Mesh test suite");
310
    *mesh << "Mesh_Demolding"
311
          << "Mesh_Transform"
312
          << "Separator";
313

314
    return root;
315
}
316

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.