Allow selecting and removing fillet and chamfer references in the dialog

This commit is contained in:
jrheinlaender
2013-10-02 21:35:40 +02:00
committed by Stefan Tröger
parent 8b19d2cf16
commit ee7f50a554
13 changed files with 441 additions and 330 deletions

View File

@@ -50,8 +50,8 @@ using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskChamferParameters */
TaskChamferParameters::TaskChamferParameters(ViewProviderChamfer *ChamferView,QWidget *parent)
: TaskBox(Gui::BitmapFactory().pixmap("Part_Chamfer"),tr("Chamfer parameters"),true, parent),ChamferView(ChamferView)
TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView,QWidget *parent)
: TaskDressUpParameters(DressUpView, parent)
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
@@ -61,10 +61,14 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderChamfer *ChamferView,QW
connect(ui->chamferDistance, SIGNAL(valueChanged(double)),
this, SLOT(onLengthChanged(double)));
connect(ui->buttonRefAdd, SIGNAL(toggled(bool)),
this, SLOT(onButtonRefAdd(bool)));
connect(ui->buttonRefRemove, SIGNAL(toggled(bool)),
this, SLOT(onButtonRefRemove(bool)));
this->groupLayout()->addWidget(proxy);
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(ChamferView->getObject());
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
double r = pcChamfer->Size.getValue();
ui->chamferDistance->setUnit(Base::Unit::Length);
@@ -73,11 +77,55 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderChamfer *ChamferView,QW
ui->chamferDistance->selectNumber();
ui->chamferDistance->bind(pcChamfer->Size);
QMetaObject::invokeMethod(ui->chamferDistance, "setFocus", Qt::QueuedConnection);
std::vector<std::string> strings = pcChamfer->Base.getSubValues();
for (std::vector<std::string>::const_iterator i = strings.begin(); i != strings.end(); i++)
{
ui->listWidgetReferences->insertItem(0, QString::fromStdString(*i));
}
// Create context menu
QAction* action = new QAction(tr("Remove"), this);
ui->listWidgetReferences->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(onRefDeleted()));
ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu);
}
void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (selectionMode == none)
return;
if (msg.Type == Gui::SelectionChanges::AddSelection) {
if (referenceSelected(msg)) {
if (selectionMode == refAdd)
ui->listWidgetReferences->insertItem(0, QString::fromStdString(msg.pSubName));
else
removeItemFromListWidget(ui->listWidgetReferences, msg.pSubName);
clearButtons(none);
exitSelectionMode();
}
}
}
void TaskChamferParameters::clearButtons(const selectionModes notThis)
{
if (notThis != refAdd) ui->buttonRefAdd->setChecked(false);
if (notThis != refRemove) ui->buttonRefRemove->setChecked(false);
}
void TaskChamferParameters::onRefDeleted(void)
{
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
App::DocumentObject* base = pcChamfer->Base.getValue();
std::vector<std::string> refs = pcChamfer->Base.getSubValues();
refs.erase(refs.begin() + ui->listWidgetReferences->currentRow());
pcChamfer->Base.setValue(base, refs);
ui->listWidgetReferences->model()->removeRow(ui->listWidgetReferences->currentRow());
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
}
void TaskChamferParameters::onLengthChanged(double len)
{
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(ChamferView->getObject());
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
pcChamfer->Size.setValue(len);
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
}
@@ -89,6 +137,7 @@ double TaskChamferParameters::getLength(void) const
TaskChamferParameters::~TaskChamferParameters()
{
Gui::Selection().rmvSelectionGate();
delete ui;
}
@@ -102,12 +151,13 @@ void TaskChamferParameters::changeEvent(QEvent *e)
void TaskChamferParameters::apply()
{
std::string name = ChamferView->getObject()->getNameInDocument();
std::string name = DressUpView->getObject()->getNameInDocument();
//Gui::Command::openCommand("Chamfer changed");
ui->chamferDistance->apply();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
@@ -116,11 +166,10 @@ void TaskChamferParameters::apply()
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgChamferParameters::TaskDlgChamferParameters(ViewProviderChamfer *ChamferView)
: TaskDialog(),ChamferView(ChamferView)
TaskDlgChamferParameters::TaskDlgChamferParameters(ViewProviderChamfer *DressUpView)
: TaskDlgDressUpParameters(DressUpView)
{
assert(ChamferView);
parameter = new TaskChamferParameters(ChamferView);
parameter = new TaskChamferParameters(DressUpView);
Content.push_back(parameter);
}
@@ -133,48 +182,20 @@ TaskDlgChamferParameters::~TaskDlgChamferParameters()
//==== calls from the TaskView ===============================================================
void TaskDlgChamferParameters::open()
{
// a transaction is already open at creation time of the chamfer
if (!Gui::Command::hasPendingCommand()) {
QString msg = tr("Edit chamfer");
Gui::Command::openCommand((const char*)msg.toUtf8());
}
}
void TaskDlgChamferParameters::clicked(int)
{
}
//void TaskDlgChamferParameters::open()
//{
// // a transaction is already open at creation time of the chamfer
// if (!Gui::Command::hasPendingCommand()) {
// QString msg = tr("Edit chamfer");
// Gui::Command::openCommand((const char*)msg.toUtf8());
// }
//}
bool TaskDlgChamferParameters::accept()
{
parameter->showObject();
parameter->apply();
return true;
return TaskDlgDressUpParameters::accept();
}
bool TaskDlgChamferParameters::reject()
{
// role back the done things
Gui::Command::abortCommand();
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
// Body housekeeping
if (ActivePartObject != NULL) {
// Make the new Tip and the previous solid feature visible again
App::DocumentObject* tip = ActivePartObject->Tip.getValue();
App::DocumentObject* prev = ActivePartObject->getPrevSolidFeature();
if (tip != NULL) {
Gui::Application::Instance->getViewProvider(tip)->show();
if ((tip != prev) && (prev != NULL))
Gui::Application::Instance->getViewProvider(prev)->show();
}
}
return true;
}
#include "moc_TaskChamferParameters.cpp"