238 lines
8.4 KiB
C++
238 lines
8.4 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 (std::vector<std::string>::const_iterator i = strings.begin(); i != strings.end(); i++)
|
|
{
|
|
ui->listWidgetReferences->addItem(QString::fromStdString(*i));
|
|
}
|
|
|
|
QMetaObject::connectSlotsByName(this);
|
|
|
|
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);
|
|
|
|
if (strings.size() == 0)
|
|
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 (checked)
|
|
setSelectionMode(none);
|
|
PartDesign::Fillet* pcFillet = static_cast<PartDesign::Fillet*>(DressUpView->getObject());
|
|
ui->buttonRefSel->setEnabled(!checked);
|
|
ui->listWidgetReferences->setEnabled(!checked);
|
|
pcFillet->UseAllEdges.setValue(checked);
|
|
pcFillet->getDocument()->recomputeFeature(pcFillet);
|
|
}
|
|
|
|
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)
|
|
{
|
|
setSelectionMode(none);
|
|
PartDesign::Fillet* pcFillet = static_cast<PartDesign::Fillet*>(DressUpView->getObject());
|
|
setupTransaction();
|
|
pcFillet->Radius.setValue(len);
|
|
pcFillet->getDocument()->recomputeFeature(pcFillet);
|
|
// 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()
|
|
{
|
|
std::string name = getDressUpView()->getObject()->getNameInDocument();
|
|
|
|
//Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Fillet changed"));
|
|
ui->filletRadius->apply();
|
|
|
|
//Alert user if he created an empty feature
|
|
if(ui->listWidgetReferences->count() == 0)
|
|
Base::Console().Warning(tr("Empty fillet created !\n").toStdString().c_str());
|
|
}
|
|
|
|
//**************************************************************************
|
|
//**************************************************************************
|
|
// TaskDialog
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
TaskDlgFilletParameters::TaskDlgFilletParameters(ViewProviderFillet *DressUpView)
|
|
: TaskDlgDressUpParameters(DressUpView)
|
|
{
|
|
parameter = new TaskFilletParameters(DressUpView);
|
|
|
|
Content.push_back(parameter);
|
|
}
|
|
|
|
TaskDlgFilletParameters::~TaskDlgFilletParameters()
|
|
{
|
|
|
|
}
|
|
|
|
//==== calls from the TaskView ===============================================================
|
|
|
|
|
|
//void TaskDlgFilletParameters::open()
|
|
//{
|
|
// // a transaction is already open at creation time of the fillet
|
|
// if (!Gui::Command::hasPendingCommand()) {
|
|
// QString msg = tr("Edit fillet");
|
|
// Gui::Command::openCommand((const char*)msg.toUtf8());
|
|
// }
|
|
//}
|
|
bool TaskDlgFilletParameters::accept()
|
|
{
|
|
auto obj = vp->getObject();
|
|
if (!obj->isError())
|
|
parameter->showObject();
|
|
|
|
parameter->apply();
|
|
|
|
return TaskDlgDressUpParameters::accept();
|
|
}
|
|
|
|
#include "moc_TaskFilletParameters.cpp"
|