FreeCAD

Форк
0
/
RemoveComponents.cpp 
275 строк · 8.5 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2009 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 <QPushButton>
26
#endif
27

28
#include <Gui/Application.h>
29
#include <Gui/Document.h>
30
#include <Gui/Selection.h>
31

32
#include "RemoveComponents.h"
33
#include "ui_RemoveComponents.h"
34

35

36
using namespace MeshGui;
37

38
RemoveComponents::RemoveComponents(QWidget* parent, Qt::WindowFlags fl)
39
    : QWidget(parent, fl)
40
    , ui(new Ui_RemoveComponents)
41
{
42
    ui->setupUi(this);
43
    setupConnections();
44
    ui->spSelectComp->setRange(1, INT_MAX);
45
    ui->spSelectComp->setValue(10);
46
    ui->spDeselectComp->setRange(1, INT_MAX);
47
    ui->spDeselectComp->setValue(10);
48

49
    Gui::Selection().clearSelection();
50
    meshSel.setCheckOnlyVisibleTriangles(ui->visibleTriangles->isChecked());
51
    meshSel.setCheckOnlyPointToUserTriangles(ui->screenTriangles->isChecked());
52
    meshSel.setEnabledViewerSelection(false);
53
}
54

55
RemoveComponents::~RemoveComponents()
56
{
57
    // no need to delete child widgets, Qt does it all for us
58
    delete ui;
59
}
60

61
void RemoveComponents::setupConnections()
62
{
63
    // clang-format off
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);
88
    // clang-format on
89
}
90

91
void RemoveComponents::changeEvent(QEvent* e)
92
{
93
    if (e->type() == QEvent::LanguageChange) {
94
        ui->retranslateUi(this);
95
    }
96
    QWidget::changeEvent(e);
97
}
98

99
void RemoveComponents::onSelectRegionClicked()
100
{
101
    meshSel.startSelection();
102
}
103

104
void RemoveComponents::onDeselectRegionClicked()
105
{
106
    meshSel.startDeselection();
107
}
108

109
void RemoveComponents::onSelectAllClicked()
110
{
111
    // select the complete meshes
112
    meshSel.fullSelection();
113
}
114

115
void RemoveComponents::onDeselectAllClicked()
116
{
117
    // deselect all meshes
118
    meshSel.clearSelection();
119
}
120

121
void RemoveComponents::onSelectComponentsClicked()
122
{
123
    // select components up to a certain size
124
    int size = ui->spSelectComp->value();
125
    meshSel.selectComponent(size);
126
}
127

128
void RemoveComponents::onDeselectComponentsClicked()
129
{
130
    // deselect components from a certain size on
131
    int size = ui->spDeselectComp->value();
132
    meshSel.deselectComponent(size);
133
}
134

135
void RemoveComponents::onVisibleTrianglesToggled(bool on)
136
{
137
    meshSel.setCheckOnlyVisibleTriangles(on);
138
}
139

140
void RemoveComponents::onScreenTrianglesToggled(bool on)
141
{
142
    meshSel.setCheckOnlyPointToUserTriangles(on);
143
}
144

145
void RemoveComponents::onSelectCompToggled(bool on)
146
{
147
    meshSel.setAddComponentOnClick(on);
148
}
149

150
void RemoveComponents::onDeselectCompToggled(bool on)
151
{
152
    meshSel.setRemoveComponentOnClick(on);
153
}
154

155
void RemoveComponents::deleteSelection()
156
{
157
    Gui::Document* doc = Gui::Application::Instance->activeDocument();
158
    if (!doc) {
159
        return;
160
    }
161
    // delete all selected faces
162
    doc->openCommand(QT_TRANSLATE_NOOP("Command", "Delete selection"));
163
    bool ok = meshSel.deleteSelection();
164
    if (!ok) {
165
        doc->abortCommand();
166
    }
167
    else {
168
        doc->commitCommand();
169
    }
170
}
171

172
void RemoveComponents::invertSelection()
173
{
174
    meshSel.invertSelection();
175
}
176

177
void RemoveComponents::onSelectTriangleClicked()
178
{
179
    meshSel.selectTriangle();
180
    meshSel.setAddComponentOnClick(ui->cbSelectComp->isChecked());
181
}
182

183
void RemoveComponents::onDeselectTriangleClicked()
184
{
185
    meshSel.deselectTriangle();
186
    meshSel.setRemoveComponentOnClick(ui->cbDeselectComp->isChecked());
187
}
188

189
void RemoveComponents::reject()
190
{
191
    // deselect all meshes
192
    meshSel.clearSelection();
193
    meshSel.setEnabledViewerSelection(true);
194
}
195

196
// -------------------------------------------------
197

198
RemoveComponentsDialog::RemoveComponentsDialog(QWidget* parent, Qt::WindowFlags fl)
199
    : QDialog(parent, fl)
200
{
201
    widget = new RemoveComponents(this);  // NOLINT
202
    this->setWindowTitle(widget->windowTitle());
203

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);
210

211
    connect(buttonBox, &QDialogButtonBox::clicked, this, &RemoveComponentsDialog::clicked);
212

213
    hboxLayout->addWidget(widget);
214
    hboxLayout->addWidget(buttonBox);
215
}
216

217
RemoveComponentsDialog::~RemoveComponentsDialog() = default;
218

219
void RemoveComponentsDialog::reject()
220
{
221
    widget->reject();
222
    QDialog::reject();
223
}
224

225
void RemoveComponentsDialog::clicked(QAbstractButton* btn)
226
{
227
    QDialogButtonBox* buttonBox = qobject_cast<QDialogButtonBox*>(sender());
228
    QDialogButtonBox::StandardButton id = buttonBox->standardButton(btn);
229
    if (id == QDialogButtonBox::Ok) {
230
        widget->deleteSelection();
231
    }
232
    else if (id == QDialogButtonBox::Close) {
233
        this->reject();
234
    }
235
    else if (id == QDialogButtonBox::NoButton) {
236
        widget->invertSelection();
237
    }
238
}
239

240
// ---------------------------------------
241

242
/* TRANSLATOR MeshGui::TaskRemoveComponents */
243

244
TaskRemoveComponents::TaskRemoveComponents()
245
{
246
    widget = new RemoveComponents();  // NOLINT
247
    addTaskBox(widget, false);
248
}
249

250
void TaskRemoveComponents::modifyStandardButtons(QDialogButtonBox* box)
251
{
252
    QPushButton* btn = box->button(QDialogButtonBox::Ok);
253
    btn->setText(tr("Delete"));
254
    box->addButton(tr("Invert"), QDialogButtonBox::ActionRole);
255
}
256

257
bool TaskRemoveComponents::accept()
258
{
259
    return false;
260
}
261

262
void TaskRemoveComponents::clicked(int id)
263
{
264
    if (id == QDialogButtonBox::Ok) {
265
        widget->deleteSelection();
266
    }
267
    else if (id == QDialogButtonBox::Close) {
268
        widget->reject();
269
    }
270
    else if (id == QDialogButtonBox::NoButton) {
271
        widget->invertSelection();
272
    }
273
}
274

275
#include "moc_RemoveComponents.cpp"
276

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

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

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

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