* PartDesign: Prepare for clang-format * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
233 lines
8.0 KiB
C++
233 lines
8.0 KiB
C++
/***************************************************************************
|
|
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
|
* *
|
|
* This file is part of the FreeCAD CAx development system. *
|
|
* *
|
|
* This library is free software; you can redistribute it and/or *
|
|
* modify it under the terms of the GNU Library General Public *
|
|
* License as published by the Free Software Foundation; either *
|
|
* version 2 of the License, or (at your option) any later version. *
|
|
* *
|
|
* This library is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU Library General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU Library General Public *
|
|
* License along with this library; see the file COPYING.LIB. If not, *
|
|
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
|
* Suite 330, Boston, MA 02111-1307, USA *
|
|
* *
|
|
***************************************************************************/
|
|
|
|
|
|
#include "PreCompiled.h"
|
|
|
|
#ifndef _PreComp_
|
|
#include <QAction>
|
|
#include <QListWidget>
|
|
#include <QMessageBox>
|
|
#endif
|
|
|
|
#include <Base/Interpreter.h>
|
|
#include <App/Document.h>
|
|
#include <App/DocumentObject.h>
|
|
#include <Gui/Selection.h>
|
|
#include <Gui/ViewProvider.h>
|
|
#include <Mod/PartDesign/App/FeatureFillet.h>
|
|
|
|
#include "ui_TaskFilletParameters.h"
|
|
#include "TaskFilletParameters.h"
|
|
|
|
|
|
using namespace PartDesignGui;
|
|
using namespace Gui;
|
|
|
|
/* TRANSLATOR PartDesignGui::TaskFilletParameters */
|
|
|
|
TaskFilletParameters::TaskFilletParameters(ViewProviderDressUp* DressUpView, QWidget* parent)
|
|
: TaskDressUpParameters(DressUpView, true, true, parent)
|
|
, ui(new Ui_TaskFilletParameters)
|
|
{
|
|
// we need a separate container widget to add all controls to
|
|
proxy = new QWidget(this);
|
|
ui->setupUi(proxy);
|
|
this->groupLayout()->addWidget(proxy);
|
|
|
|
PartDesign::Fillet* pcFillet = static_cast<PartDesign::Fillet*>(DressUpView->getObject());
|
|
bool useAllEdges = pcFillet->UseAllEdges.getValue();
|
|
ui->checkBoxUseAllEdges->setChecked(useAllEdges);
|
|
ui->buttonRefSel->setEnabled(!useAllEdges);
|
|
ui->listWidgetReferences->setEnabled(!useAllEdges);
|
|
double r = pcFillet->Radius.getValue();
|
|
|
|
ui->filletRadius->setUnit(Base::Unit::Length);
|
|
ui->filletRadius->setValue(r);
|
|
ui->filletRadius->setMinimum(0);
|
|
ui->filletRadius->selectNumber();
|
|
ui->filletRadius->bind(pcFillet->Radius);
|
|
QMetaObject::invokeMethod(ui->filletRadius, "setFocus", Qt::QueuedConnection);
|
|
std::vector<std::string> strings = pcFillet->Base.getSubValues();
|
|
for (const auto& string : strings) {
|
|
ui->listWidgetReferences->addItem(QString::fromStdString(string));
|
|
}
|
|
|
|
QMetaObject::connectSlotsByName(this);
|
|
|
|
// clang-format off
|
|
connect(ui->filletRadius, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
|
|
this, &TaskFilletParameters::onLengthChanged);
|
|
connect(ui->buttonRefSel, &QToolButton::toggled,
|
|
this, &TaskFilletParameters::onButtonRefSel);
|
|
connect(ui->checkBoxUseAllEdges, &QToolButton::toggled,
|
|
this, &TaskFilletParameters::onCheckBoxUseAllEdgesToggled);
|
|
|
|
// Create context menu
|
|
createDeleteAction(ui->listWidgetReferences);
|
|
connect(deleteAction, &QAction::triggered, this, &TaskFilletParameters::onRefDeleted);
|
|
|
|
createAddAllEdgesAction(ui->listWidgetReferences);
|
|
connect(addAllEdgesAction, &QAction::triggered, this, &TaskFilletParameters::onAddAllEdges);
|
|
|
|
connect(ui->listWidgetReferences, &QListWidget::currentItemChanged,
|
|
this, &TaskFilletParameters::setSelection);
|
|
connect(ui->listWidgetReferences, &QListWidget::itemClicked,
|
|
this, &TaskFilletParameters::setSelection);
|
|
connect(ui->listWidgetReferences, &QListWidget::itemDoubleClicked,
|
|
this, &TaskFilletParameters::doubleClicked);
|
|
// clang-format on
|
|
|
|
if (strings.empty()) {
|
|
setSelectionMode(refSel);
|
|
}
|
|
else {
|
|
hideOnError();
|
|
}
|
|
}
|
|
|
|
void TaskFilletParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
|
{
|
|
// executed when the user selected something in the CAD object
|
|
// adds/deletes the selection accordingly
|
|
|
|
if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
|
if (selectionMode == refSel) {
|
|
referenceSelected(msg, ui->listWidgetReferences);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TaskFilletParameters::onCheckBoxUseAllEdgesToggled(bool checked)
|
|
{
|
|
if (auto fillet = getObject<PartDesign::Fillet>()) {
|
|
if (checked) {
|
|
setSelectionMode(none);
|
|
}
|
|
|
|
ui->buttonRefSel->setEnabled(!checked);
|
|
ui->listWidgetReferences->setEnabled(!checked);
|
|
fillet->UseAllEdges.setValue(checked);
|
|
fillet->recomputeFeature();
|
|
}
|
|
}
|
|
|
|
void TaskFilletParameters::setButtons(const selectionModes mode)
|
|
{
|
|
ui->buttonRefSel->setChecked(mode == refSel);
|
|
ui->buttonRefSel->setText(mode == refSel ? btnPreviewStr() : btnSelectStr());
|
|
}
|
|
|
|
void TaskFilletParameters::onRefDeleted()
|
|
{
|
|
TaskDressUpParameters::deleteRef(ui->listWidgetReferences);
|
|
}
|
|
|
|
void TaskFilletParameters::onAddAllEdges()
|
|
{
|
|
TaskDressUpParameters::addAllEdges(ui->listWidgetReferences);
|
|
}
|
|
|
|
void TaskFilletParameters::onLengthChanged(double len)
|
|
{
|
|
if (auto fillet = getObject<PartDesign::Fillet>()) {
|
|
setSelectionMode(none);
|
|
setupTransaction();
|
|
fillet->Radius.setValue(len);
|
|
fillet->recomputeFeature();
|
|
// hide the fillet if there was a computation error
|
|
hideOnError();
|
|
}
|
|
}
|
|
|
|
double TaskFilletParameters::getLength() const
|
|
{
|
|
return ui->filletRadius->value().getValue();
|
|
}
|
|
|
|
TaskFilletParameters::~TaskFilletParameters()
|
|
{
|
|
try {
|
|
Gui::Selection().clearSelection();
|
|
Gui::Selection().rmvSelectionGate();
|
|
}
|
|
catch (const Py::Exception&) {
|
|
Base::PyException e; // extract the Python error text
|
|
e.ReportException();
|
|
}
|
|
}
|
|
|
|
bool TaskFilletParameters::event(QEvent* e)
|
|
{
|
|
return TaskDressUpParameters::KeyEvent(e);
|
|
}
|
|
|
|
void TaskFilletParameters::changeEvent(QEvent* e)
|
|
{
|
|
TaskBox::changeEvent(e);
|
|
if (e->type() == QEvent::LanguageChange) {
|
|
ui->retranslateUi(proxy);
|
|
}
|
|
}
|
|
|
|
void TaskFilletParameters::apply()
|
|
{
|
|
ui->filletRadius->apply();
|
|
|
|
// Alert user if he created an empty feature
|
|
if (ui->listWidgetReferences->count() == 0) {
|
|
std::string text = tr("Empty fillet created!").toStdString();
|
|
Base::Console().Warning("%s\n", text.c_str());
|
|
}
|
|
}
|
|
|
|
//**************************************************************************
|
|
//**************************************************************************
|
|
// TaskDialog
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
TaskDlgFilletParameters::TaskDlgFilletParameters(ViewProviderFillet* DressUpView)
|
|
: TaskDlgDressUpParameters(DressUpView)
|
|
{
|
|
parameter = new TaskFilletParameters(DressUpView);
|
|
|
|
Content.push_back(parameter);
|
|
}
|
|
|
|
TaskDlgFilletParameters::~TaskDlgFilletParameters() = default;
|
|
|
|
//==== calls from the TaskView ===============================================================
|
|
|
|
bool TaskDlgFilletParameters::accept()
|
|
{
|
|
auto obj = getObject();
|
|
if (!obj->isError()) {
|
|
parameter->showObject();
|
|
}
|
|
|
|
parameter->apply();
|
|
|
|
return TaskDlgDressUpParameters::accept();
|
|
}
|
|
|
|
#include "moc_TaskFilletParameters.cpp"
|