1
/***************************************************************************
2
* Copyright (c) 2009 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
23
#include "PreCompiled.h"
28
#include <Gui/Application.h>
29
#include <Gui/Document.h>
30
#include <Gui/Selection.h>
32
#include "RemoveComponents.h"
33
#include "ui_RemoveComponents.h"
36
using namespace MeshGui;
38
RemoveComponents::RemoveComponents(QWidget* parent, Qt::WindowFlags fl)
40
, ui(new Ui_RemoveComponents)
44
ui->spSelectComp->setRange(1, INT_MAX);
45
ui->spSelectComp->setValue(10);
46
ui->spDeselectComp->setRange(1, INT_MAX);
47
ui->spDeselectComp->setValue(10);
49
Gui::Selection().clearSelection();
50
meshSel.setCheckOnlyVisibleTriangles(ui->visibleTriangles->isChecked());
51
meshSel.setCheckOnlyPointToUserTriangles(ui->screenTriangles->isChecked());
52
meshSel.setEnabledViewerSelection(false);
55
RemoveComponents::~RemoveComponents()
57
// no need to delete child widgets, Qt does it all for us
61
void RemoveComponents::setupConnections()
64
connect(ui->selectRegion, &QPushButton::clicked,
65
this, &RemoveComponents::onSelectRegionClicked);
66
connect(ui->selectAll, &QPushButton::clicked,
67
this, &RemoveComponents::onSelectAllClicked);
68
connect(ui->selectComponents, &QPushButton::clicked,
69
this, &RemoveComponents::onSelectComponentsClicked);
70
connect(ui->selectTriangle, &QPushButton::clicked,
71
this, &RemoveComponents::onSelectTriangleClicked);
72
connect(ui->deselectRegion, &QPushButton::clicked,
73
this, &RemoveComponents::onDeselectRegionClicked);
74
connect(ui->deselectAll, &QPushButton::clicked,
75
this, &RemoveComponents::onDeselectAllClicked);
76
connect(ui->deselectComponents, &QPushButton::clicked,
77
this, &RemoveComponents::onDeselectComponentsClicked);
78
connect(ui->deselectTriangle, &QPushButton::clicked,
79
this, &RemoveComponents::onDeselectTriangleClicked);
80
connect(ui->visibleTriangles, &QCheckBox::toggled,
81
this, &RemoveComponents::onVisibleTrianglesToggled);
82
connect(ui->screenTriangles, &QCheckBox::toggled,
83
this, &RemoveComponents::onScreenTrianglesToggled);
84
connect(ui->cbSelectComp, &QCheckBox::toggled,
85
this, &RemoveComponents::onSelectCompToggled);
86
connect(ui->cbDeselectComp, &QCheckBox::toggled,
87
this, &RemoveComponents::onDeselectCompToggled);
91
void RemoveComponents::changeEvent(QEvent* e)
93
if (e->type() == QEvent::LanguageChange) {
94
ui->retranslateUi(this);
96
QWidget::changeEvent(e);
99
void RemoveComponents::onSelectRegionClicked()
101
meshSel.startSelection();
104
void RemoveComponents::onDeselectRegionClicked()
106
meshSel.startDeselection();
109
void RemoveComponents::onSelectAllClicked()
111
// select the complete meshes
112
meshSel.fullSelection();
115
void RemoveComponents::onDeselectAllClicked()
117
// deselect all meshes
118
meshSel.clearSelection();
121
void RemoveComponents::onSelectComponentsClicked()
123
// select components up to a certain size
124
int size = ui->spSelectComp->value();
125
meshSel.selectComponent(size);
128
void RemoveComponents::onDeselectComponentsClicked()
130
// deselect components from a certain size on
131
int size = ui->spDeselectComp->value();
132
meshSel.deselectComponent(size);
135
void RemoveComponents::onVisibleTrianglesToggled(bool on)
137
meshSel.setCheckOnlyVisibleTriangles(on);
140
void RemoveComponents::onScreenTrianglesToggled(bool on)
142
meshSel.setCheckOnlyPointToUserTriangles(on);
145
void RemoveComponents::onSelectCompToggled(bool on)
147
meshSel.setAddComponentOnClick(on);
150
void RemoveComponents::onDeselectCompToggled(bool on)
152
meshSel.setRemoveComponentOnClick(on);
155
void RemoveComponents::deleteSelection()
157
Gui::Document* doc = Gui::Application::Instance->activeDocument();
161
// delete all selected faces
162
doc->openCommand(QT_TRANSLATE_NOOP("Command", "Delete selection"));
163
bool ok = meshSel.deleteSelection();
168
doc->commitCommand();
172
void RemoveComponents::invertSelection()
174
meshSel.invertSelection();
177
void RemoveComponents::onSelectTriangleClicked()
179
meshSel.selectTriangle();
180
meshSel.setAddComponentOnClick(ui->cbSelectComp->isChecked());
183
void RemoveComponents::onDeselectTriangleClicked()
185
meshSel.deselectTriangle();
186
meshSel.setRemoveComponentOnClick(ui->cbDeselectComp->isChecked());
189
void RemoveComponents::reject()
191
// deselect all meshes
192
meshSel.clearSelection();
193
meshSel.setEnabledViewerSelection(true);
196
// -------------------------------------------------
198
RemoveComponentsDialog::RemoveComponentsDialog(QWidget* parent, Qt::WindowFlags fl)
199
: QDialog(parent, fl)
201
widget = new RemoveComponents(this); // NOLINT
202
this->setWindowTitle(widget->windowTitle());
204
QVBoxLayout* hboxLayout = new QVBoxLayout(this);
205
QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
206
buttonBox->setStandardButtons(QDialogButtonBox::Close | QDialogButtonBox::Ok);
207
QPushButton* okButton = buttonBox->button(QDialogButtonBox::Ok);
208
okButton->setText(MeshGui::TaskRemoveComponents::tr("Delete"));
209
buttonBox->addButton(MeshGui::TaskRemoveComponents::tr("Invert"), QDialogButtonBox::ActionRole);
211
connect(buttonBox, &QDialogButtonBox::clicked, this, &RemoveComponentsDialog::clicked);
213
hboxLayout->addWidget(widget);
214
hboxLayout->addWidget(buttonBox);
217
RemoveComponentsDialog::~RemoveComponentsDialog() = default;
219
void RemoveComponentsDialog::reject()
225
void RemoveComponentsDialog::clicked(QAbstractButton* btn)
227
QDialogButtonBox* buttonBox = qobject_cast<QDialogButtonBox*>(sender());
228
QDialogButtonBox::StandardButton id = buttonBox->standardButton(btn);
229
if (id == QDialogButtonBox::Ok) {
230
widget->deleteSelection();
232
else if (id == QDialogButtonBox::Close) {
235
else if (id == QDialogButtonBox::NoButton) {
236
widget->invertSelection();
240
// ---------------------------------------
242
/* TRANSLATOR MeshGui::TaskRemoveComponents */
244
TaskRemoveComponents::TaskRemoveComponents()
246
widget = new RemoveComponents(); // NOLINT
247
addTaskBox(widget, false);
250
void TaskRemoveComponents::modifyStandardButtons(QDialogButtonBox* box)
252
QPushButton* btn = box->button(QDialogButtonBox::Ok);
253
btn->setText(tr("Delete"));
254
box->addButton(tr("Invert"), QDialogButtonBox::ActionRole);
257
bool TaskRemoveComponents::accept()
262
void TaskRemoveComponents::clicked(int id)
264
if (id == QDialogButtonBox::Ok) {
265
widget->deleteSelection();
267
else if (id == QDialogButtonBox::Close) {
270
else if (id == QDialogButtonBox::NoButton) {
271
widget->invertSelection();
275
#include "moc_RemoveComponents.cpp"