From a2359adb2e512e536302a810106a8b7bcb473c9b Mon Sep 17 00:00:00 2001 From: jrheinlaender Date: Mon, 30 Sep 2013 21:50:05 +0200 Subject: [PATCH] Unify code of Dressup features (part 1: Draft) --- src/Mod/PartDesign/Gui/AppPartDesignGui.cpp | 4 + src/Mod/PartDesign/Gui/CMakeLists.txt | 5 + .../PartDesign/Gui/TaskDraftParameters.cpp | 279 ++++----------- .../Gui/TaskDraftParameters.cpp.orig | 332 ++++++++++++++++++ src/Mod/PartDesign/Gui/TaskDraftParameters.h | 61 +--- .../PartDesign/Gui/TaskDraftParameters.h.orig | 96 +++++ src/Mod/PartDesign/Gui/TaskDraftParameters.ui | 8 +- .../PartDesign/Gui/TaskDressUpParameters.cpp | 252 +++++++++++++ .../PartDesign/Gui/TaskDressUpParameters.h | 112 ++++++ src/Mod/PartDesign/Gui/ViewProviderDraft.cpp | 4 +- src/Mod/PartDesign/Gui/ViewProviderDraft.h | 4 +- .../PartDesign/Gui/ViewProviderDressUp.cpp | 121 +++++++ src/Mod/PartDesign/Gui/ViewProviderDressUp.h | 70 ++++ 13 files changed, 1065 insertions(+), 283 deletions(-) create mode 100644 src/Mod/PartDesign/Gui/TaskDraftParameters.cpp.orig create mode 100644 src/Mod/PartDesign/Gui/TaskDraftParameters.h.orig create mode 100644 src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp create mode 100644 src/Mod/PartDesign/Gui/TaskDressUpParameters.h create mode 100644 src/Mod/PartDesign/Gui/ViewProviderDressUp.cpp create mode 100644 src/Mod/PartDesign/Gui/ViewProviderDressUp.h diff --git a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp index ac2ec7f27..58e146b83 100644 --- a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp +++ b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp @@ -41,6 +41,7 @@ #include "ViewProviderChamfer.h" #include "ViewProviderFillet.h" #include "ViewProviderDraft.h" +#include "ViewProviderDressUp.h" #include "ViewProviderRevolution.h" #include "ViewProviderGroove.h" #include "ViewProviderMirrored.h" @@ -48,6 +49,7 @@ #include "ViewProviderPolarPattern.h" #include "ViewProviderScaled.h" #include "ViewProviderMultiTransform.h" +#include "ViewProviderTransformed.h" #include "ViewProviderDatumPoint.h" #include "ViewProviderDatumLine.h" #include "ViewProviderDatumPlane.h" @@ -114,10 +116,12 @@ PyMODINIT_FUNC initPartDesignGui() PartDesignGui::ViewProviderPocket ::init(); PartDesignGui::ViewProviderPad ::init(); PartDesignGui::ViewProviderRevolution ::init(); + PartDesignGui::ViewProviderDressUp ::init(); PartDesignGui::ViewProviderGroove ::init(); PartDesignGui::ViewProviderChamfer ::init(); PartDesignGui::ViewProviderFillet ::init(); PartDesignGui::ViewProviderDraft ::init(); + PartDesignGui::ViewProviderTransformed ::init(); PartDesignGui::ViewProviderMirrored ::init(); PartDesignGui::ViewProviderLinearPattern ::init(); PartDesignGui::ViewProviderPolarPattern ::init(); diff --git a/src/Mod/PartDesign/Gui/CMakeLists.txt b/src/Mod/PartDesign/Gui/CMakeLists.txt index 7fa5810d6..f29459322 100644 --- a/src/Mod/PartDesign/Gui/CMakeLists.txt +++ b/src/Mod/PartDesign/Gui/CMakeLists.txt @@ -35,6 +35,7 @@ set(PartDesignGui_MOC_HDRS TaskChamferParameters.h TaskFilletParameters.h TaskDraftParameters.h + TaskDressUpParameters.h TaskHoleParameters.h TaskRevolutionParameters.h TaskGrooveParameters.h @@ -91,6 +92,8 @@ SET(PartDesignGuiViewProvider_SRCS ViewProviderFillet.h ViewProviderDraft.cpp ViewProviderDraft.h + ViewProviderDressUp.cpp + ViewProviderDressUp.h ViewProviderRevolution.cpp ViewProviderRevolution.h ViewProviderGroove.cpp @@ -143,6 +146,8 @@ SET(PartDesignGuiTaskDlgs_SRCS TaskDraftParameters.ui TaskDraftParameters.cpp TaskDraftParameters.h + TaskDressUpParameters.cpp + TaskDressUpParameters.h TaskRevolutionParameters.ui TaskRevolutionParameters.cpp TaskRevolutionParameters.h diff --git a/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp index 2bc3ca7d3..a967509c6 100644 --- a/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp @@ -43,8 +43,6 @@ #include #include #include -#include -#include #include using namespace PartDesignGui; @@ -52,11 +50,9 @@ using namespace Gui; /* TRANSLATOR PartDesignGui::TaskDraftParameters */ -TaskDraftParameters::TaskDraftParameters(ViewProviderDraft *DraftView,QWidget *parent) - : TaskBox(Gui::BitmapFactory().pixmap("PartDesign_Draft"),tr("Draft parameters"),true, parent),DraftView(DraftView) +TaskDraftParameters::TaskDraftParameters(ViewProviderDressUp *DressUpView,QWidget *parent) + : TaskDressUpParameters(DressUpView, parent) { - selectionMode = none; - // we need a separate container widget to add all controls to proxy = new QWidget(this); ui = new Ui_TaskDraftParameters(); @@ -67,10 +63,10 @@ TaskDraftParameters::TaskDraftParameters(ViewProviderDraft *DraftView,QWidget *p this, SLOT(onAngleChanged(double))); connect(ui->checkReverse, SIGNAL(toggled(bool)), this, SLOT(onReversedChanged(bool))); - connect(ui->buttonFaceAdd, SIGNAL(toggled(bool)), - this, SLOT(onButtonFaceAdd(bool))); - connect(ui->buttonFaceRemove, SIGNAL(toggled(bool)), - this, SLOT(onButtonFaceRemove(bool))); + connect(ui->buttonRefAdd, SIGNAL(toggled(bool)), + this, SLOT(onButtonRefAdd(bool))); + connect(ui->buttonRefRemove, SIGNAL(toggled(bool)), + this, SLOT(onButtonRefRemove(bool))); connect(ui->buttonPlane, SIGNAL(toggled(bool)), this, SLOT(onButtonPlane(bool))); connect(ui->buttonLine, SIGNAL(toggled(bool)), @@ -78,7 +74,7 @@ TaskDraftParameters::TaskDraftParameters(ViewProviderDraft *DraftView,QWidget *p this->groupLayout()->addWidget(proxy); - PartDesign::Draft* pcDraft = static_cast(DraftView->getObject()); + PartDesign::Draft* pcDraft = static_cast(DressUpView->getObject()); double a = pcDraft->Angle.getValue(); ui->draftAngle->setMinimum(0.0); @@ -93,13 +89,13 @@ TaskDraftParameters::TaskDraftParameters(ViewProviderDraft *DraftView,QWidget *p std::vector strings = pcDraft->Base.getSubValues(); for (std::vector::const_iterator i = strings.begin(); i != strings.end(); ++i) { - ui->listWidgetFaces->insertItem(0, QString::fromStdString(*i)); + ui->listWidgetReferences->insertItem(0, QString::fromStdString(*i)); } // Create context menu QAction* action = new QAction(tr("Remove"), this); - ui->listWidgetFaces->addAction(action); - connect(action, SIGNAL(triggered()), this, SLOT(onFaceDeleted())); - ui->listWidgetFaces->setContextMenuPolicy(Qt::ActionsContextMenu); + ui->listWidgetReferences->addAction(action); + connect(action, SIGNAL(triggered()), this, SLOT(onRefDeleted())); + ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu); App::DocumentObject* ref = pcDraft->NeutralPlane.getValue(); strings = pcDraft->NeutralPlane.getSubValues(); @@ -116,55 +112,15 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg) return; if (msg.Type == Gui::SelectionChanges::AddSelection) { - - if (strcmp(msg.pDocName, DraftView->getObject()->getDocument()->getName()) != 0) - return; - - PartDesign::Draft* pcDraft = static_cast(DraftView->getObject()); - App::DocumentObject* base = this->getBase(); - // TODO: Must we make a copy here instead of assigning to const char* ? - const char* fname = base->getNameInDocument(); - std::string subName(msg.pSubName); - - if ((selectionMode == faceAdd) && (subName.size() > 4 && subName.substr(0,4) == "Face")) { - - if (strcmp(msg.pObjectName, fname) != 0) - return; - - std::vector faces = pcDraft->Base.getSubValues(); - if (std::find(faces.begin(), faces.end(), subName) == faces.end()) { - faces.push_back(subName); - pcDraft->Base.setValue(base, faces); - ui->listWidgetFaces->insertItem(0, QString::fromStdString(subName)); - - clearButtons(NULL); - DraftView->highlightReferences(false); - exitSelectionMode(); - pcDraft->getDocument()->recomputeFeature(pcDraft); - } - } else if ((selectionMode == faceRemove) && (subName.size() > 4 && subName.substr(0,4) == "Face")) { - - if (strcmp(msg.pObjectName, fname) != 0) - return; - - std::vector faces = pcDraft->Base.getSubValues(); - std::vector::iterator f = std::find(faces.begin(), faces.end(), subName); - if (f != faces.end()) { - faces.erase(f); - pcDraft->Base.setValue(base, faces); - QList items = ui->listWidgetFaces->findItems(QString::fromStdString(subName), Qt::MatchExactly); - if (!items.empty()) { - for (QList::const_iterator i = items.begin(); i != items.end(); ++i) { - QListWidgetItem* it = ui->listWidgetFaces->takeItem(ui->listWidgetFaces->row(*i)); - delete it; - } - } - clearButtons(NULL); - DraftView->highlightReferences(false); - exitSelectionMode(); - pcDraft->getDocument()->recomputeFeature(pcDraft); - } - } else if ((selectionMode == plane)) { + if (referenceSelected(msg)) { + if (selectionMode == refAdd) + ui->listWidgetReferences->insertItem(0, QString::fromStdString(msg.pSubName)); + else + removeItemFromListWidget(ui->listWidgetReferences, msg.pSubName); + clearButtons(none); + exitSelectionMode(); + } else if (selectionMode == plane) { + PartDesign::Draft* pcDraft = static_cast(DressUpView->getObject()); std::vector planes; App::DocumentObject* selObj; getReferencedSelection(pcDraft, msg, selObj, planes); @@ -172,9 +128,10 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg) ui->linePlane->setText(getRefStr(selObj, planes)); pcDraft->getDocument()->recomputeFeature(pcDraft); - ui->buttonPlane->setChecked(false); + clearButtons(none); exitSelectionMode(); - } else if ((selectionMode == line) && (subName.size() > 4 && subName.substr(0,4) == "Edge")) { + } else if (selectionMode == line) { + PartDesign::Draft* pcDraft = static_cast(DressUpView->getObject()); std::vector edges; App::DocumentObject* selObj; getReferencedSelection(pcDraft, msg, selObj, edges); @@ -182,90 +139,50 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg) ui->lineLine->setText(getRefStr(selObj, edges)); pcDraft->getDocument()->recomputeFeature(pcDraft); - ui->buttonLine->setChecked(false); + clearButtons(none); exitSelectionMode(); } } } -void TaskDraftParameters::clearButtons(const QToolButton* notThis) +void TaskDraftParameters::clearButtons(const selectionModes notThis) { - if (ui->buttonFaceAdd != notThis) ui->buttonFaceAdd->setChecked(false); - if (ui->buttonFaceRemove != notThis) ui->buttonFaceRemove->setChecked(false); - if (ui->buttonLine != notThis) ui->buttonLine->setChecked(false); - if (ui->buttonPlane != notThis) ui->buttonPlane->setChecked(false); -} - -void TaskDraftParameters::onButtonFaceAdd(bool checked) -{ - if (checked) { - clearButtons(ui->buttonFaceAdd); - hideObject(); - selectionMode = faceAdd; - Gui::Selection().clearSelection(); - Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), false, true, false)); - DraftView->highlightReferences(true); - } else { - exitSelectionMode(); - } -} - -void TaskDraftParameters::onButtonFaceRemove(bool checked) -{ - if (checked) { - clearButtons(ui->buttonFaceRemove); - hideObject(); - selectionMode = faceRemove; - Gui::Selection().clearSelection(); - Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), false, true, false)); - DraftView->highlightReferences(true); - } else { - exitSelectionMode(); - } + if (notThis != refAdd) ui->buttonRefAdd->setChecked(false); + if (notThis != refRemove) ui->buttonRefRemove->setChecked(false); + if (notThis != line) ui->buttonLine->setChecked(false); + if (notThis != plane) ui->buttonPlane->setChecked(false); } void TaskDraftParameters::onButtonPlane(bool checked) { if (checked) { - clearButtons(ui->buttonPlane); + clearButtons(plane); hideObject(); selectionMode = plane; Gui::Selection().clearSelection(); Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), true, true, true)); - } else { - exitSelectionMode(); } } void TaskDraftParameters::onButtonLine(bool checked) { if (checked) { - clearButtons(ui->buttonLine); + clearButtons(line); hideObject(); selectionMode = line; Gui::Selection().clearSelection(); Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), true, false, true)); - } else { - exitSelectionMode(); } } -const std::vector TaskDraftParameters::getFaces(void) const +void TaskDraftParameters::onRefDeleted(void) { - std::vector result; - for (int i = 0; i < ui->listWidgetFaces->count(); i++) - result.push_back(ui->listWidgetFaces->item(i)->text().toStdString()); - return result; -} - -void TaskDraftParameters::onFaceDeleted(void) -{ - PartDesign::Draft* pcDraft = static_cast(DraftView->getObject()); + PartDesign::Draft* pcDraft = static_cast(DressUpView->getObject()); App::DocumentObject* base = pcDraft->Base.getValue(); std::vector faces = pcDraft->Base.getSubValues(); - faces.erase(faces.begin() + ui->listWidgetFaces->currentRow()); + faces.erase(faces.begin() + ui->listWidgetReferences->currentRow()); pcDraft->Base.setValue(base, faces); - ui->listWidgetFaces->model()->removeRow(ui->listWidgetFaces->currentRow()); + ui->listWidgetReferences->model()->removeRow(ui->listWidgetReferences->currentRow()); pcDraft->getDocument()->recomputeFeature(pcDraft); } @@ -273,7 +190,7 @@ void TaskDraftParameters::getPlane(App::DocumentObject*& obj, std::vector(1,""); QStringList parts = ui->linePlane->text().split(QChar::fromAscii(':')); - obj = DraftView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str()); + obj = DressUpView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str()); if (parts.size() > 1) sub[0] = parts[1].toStdString(); } @@ -282,35 +199,15 @@ void TaskDraftParameters::getLine(App::DocumentObject*& obj, std::vector(1,""); QStringList parts = ui->lineLine->text().split(QChar::fromAscii(':')); - obj = DraftView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str()); + obj = DressUpView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str()); if (parts.size() > 1) sub[0] = parts[1].toStdString(); } -void TaskDraftParameters::hideObject() -{ - Gui::Document* doc = Gui::Application::Instance->activeDocument(); - App::DocumentObject* base = getBase(); - if (doc != NULL && base != NULL) { - doc->setHide(DraftView->getObject()->getNameInDocument()); - doc->setShow(base->getNameInDocument()); - } -} - -void TaskDraftParameters::showObject() -{ - Gui::Document* doc = Gui::Application::Instance->activeDocument(); - App::DocumentObject* base = getBase(); - if (doc != NULL && base != NULL) { - doc->setShow(DraftView->getObject()->getNameInDocument()); - doc->setHide(base->getNameInDocument()); - } -} - void TaskDraftParameters::onAngleChanged(double angle) { - clearButtons(NULL); - PartDesign::Draft* pcDraft = static_cast(DraftView->getObject()); + clearButtons(none); + PartDesign::Draft* pcDraft = static_cast(DressUpView->getObject()); pcDraft->Angle.setValue(angle); pcDraft->getDocument()->recomputeFeature(pcDraft); } @@ -321,8 +218,8 @@ const double TaskDraftParameters::getAngle(void) const } void TaskDraftParameters::onReversedChanged(const bool on) { - clearButtons(NULL); - PartDesign::Draft* pcDraft = static_cast(DraftView->getObject()); + clearButtons(none); + PartDesign::Draft* pcDraft = static_cast(DressUpView->getObject()); pcDraft->Reversed.setValue(on); pcDraft->getDocument()->recomputeFeature(pcDraft); } @@ -332,12 +229,6 @@ const bool TaskDraftParameters::getReversed(void) const return ui->checkReverse->isChecked(); } -App::DocumentObject* TaskDraftParameters::getBase(void) const -{ - PartDesign::Draft* pcDraft = static_cast(DraftView->getObject()); - return pcDraft->Base.getValue(); -} - TaskDraftParameters::~TaskDraftParameters() { Gui::Selection().rmvSelectionGate(); @@ -352,24 +243,16 @@ void TaskDraftParameters::changeEvent(QEvent *e) } } -void TaskDraftParameters::exitSelectionMode() -{ - selectionMode = none; - Gui::Selection().rmvSelectionGate(); - Gui::Selection().clearSelection(); - showObject(); -} //************************************************************************** //************************************************************************** // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgDraftParameters::TaskDlgDraftParameters(ViewProviderDraft *DraftView) - : TaskDialog(),DraftView(DraftView) +TaskDlgDraftParameters::TaskDlgDraftParameters(ViewProviderDraft *DressUpView) + : TaskDlgDressUpParameters(DressUpView) { - assert(DraftView); - parameter = new TaskDraftParameters(DraftView); + parameter = new TaskDraftParameters(DressUpView); Content.push_back(parameter); } @@ -382,19 +265,14 @@ TaskDlgDraftParameters::~TaskDlgDraftParameters() //==== calls from the TaskView =============================================================== -void TaskDlgDraftParameters::open() -{ - // a transaction is already open at creation time of the draft - if (!Gui::Command::hasPendingCommand()) { - QString msg = QObject::tr("Edit draft"); - Gui::Command::openCommand((const char*)msg.toUtf8()); - } -} - -void TaskDlgDraftParameters::clicked(int) -{ - -} +//void TaskDlgDraftParameters::open() +//{ +// // a transaction is already open at creation time of the draft +// if (!Gui::Command::hasPendingCommand()) { +// QString msg = QObject::tr("Edit draft"); +// Gui::Command::openCommand((const char*)msg.toUtf8()); +// } +//} bool TaskDlgDraftParameters::accept() { @@ -403,7 +281,8 @@ bool TaskDlgDraftParameters::accept() // Force the user to select a neutral plane std::vector strings; App::DocumentObject* obj; - parameter->getPlane(obj, strings); + TaskDraftParameters* draftparameter = static_cast(parameter); + draftparameter->getPlane(obj, strings); std::string neutralPlane = getPythonStr(obj, strings); if (neutralPlane.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Missing neutral plane"), @@ -411,62 +290,22 @@ bool TaskDlgDraftParameters::accept() return false; } - std::string name = DraftView->getObject()->getNameInDocument(); + std::string name = DressUpView->getObject()->getNameInDocument(); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),parameter->getAngle()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),parameter->getReversed()); - try { - std::vector faces = parameter->getFaces(); - std::stringstream str; - str << "App.ActiveDocument." << name.c_str() << ".Base = (App.ActiveDocument." - << parameter->getBase()->getNameInDocument() << ",["; - for (std::vector::const_iterator it = faces.begin(); it != faces.end(); ++it) - str << "\"" << *it << "\","; - str << "])"; - Gui::Command::doCommand(Gui::Command::Doc,str.str().c_str()); - } - catch (const Base::Exception& e) { - QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); - return false; - } + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),draftparameter->getAngle()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),draftparameter->getReversed()); if (!neutralPlane.empty()) { Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = %s", name.c_str(), neutralPlane.c_str()); } else Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = None", name.c_str()); - parameter->getLine(obj, strings); + draftparameter->getLine(obj, strings); std::string pullDirection = getPythonStr(obj, strings); if (!pullDirection.empty()) { Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = %s", name.c_str(), pullDirection.c_str()); } else Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = None", name.c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); - Gui::Command::commitCommand(); - return true; + return TaskDlgDressUpParameters::accept(); } -bool TaskDlgDraftParameters::reject() -{ - // roll 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_TaskDraftParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp.orig b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp.orig new file mode 100644 index 000000000..37cd97bfd --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp.orig @@ -0,0 +1,332 @@ +/*************************************************************************** + * Copyright (c) 2012 Jan Rheinländer * + * * + * 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 +#endif + +#include "ui_TaskDraftParameters.h" +#include "TaskDraftParameters.h" +#include "Workbench.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace PartDesignGui; +using namespace Gui; + +/* TRANSLATOR PartDesignGui::TaskDraftParameters */ + +TaskDraftParameters::TaskDraftParameters(ViewProviderDressUp *DressUpView,QWidget *parent) + : TaskDressUpParameters(DressUpView, parent) +{ + // we need a separate container widget to add all controls to + proxy = new QWidget(this); + ui = new Ui_TaskDraftParameters(); + ui->setupUi(proxy); + QMetaObject::connectSlotsByName(this); + + connect(ui->draftAngle, SIGNAL(valueChanged(double)), + this, SLOT(onAngleChanged(double))); + connect(ui->checkReverse, SIGNAL(toggled(bool)), + this, SLOT(onReversedChanged(bool))); + connect(ui->buttonRefAdd, SIGNAL(toggled(bool)), + this, SLOT(onButtonRefAdd(bool))); + connect(ui->buttonRefRemove, SIGNAL(toggled(bool)), + this, SLOT(onButtonRefRemove(bool))); + connect(ui->buttonPlane, SIGNAL(toggled(bool)), + this, SLOT(onButtonPlane(bool))); + connect(ui->buttonLine, SIGNAL(toggled(bool)), + this, SLOT(onButtonLine(bool))); + + this->groupLayout()->addWidget(proxy); + + PartDesign::Draft* pcDraft = static_cast(DressUpView->getObject()); + double a = pcDraft->Angle.getValue(); + + ui->draftAngle->setMinimum(0.0); + ui->draftAngle->setMaximum(89.99); + ui->draftAngle->setValue(a); + ui->draftAngle->selectAll(); + QMetaObject::invokeMethod(ui->draftAngle, "setFocus", Qt::QueuedConnection); + + bool r = pcDraft->Reversed.getValue(); + ui->checkReverse->setChecked(r); + + std::vector strings = pcDraft->Base.getSubValues(); + for (std::vector::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); + + App::DocumentObject* ref = pcDraft->NeutralPlane.getValue(); + strings = pcDraft->NeutralPlane.getSubValues(); + ui->linePlane->setText(getRefStr(ref, strings)); + + ref = pcDraft->PullDirection.getValue(); + strings = pcDraft->PullDirection.getSubValues(); + ui->lineLine->setText(getRefStr(ref, strings)); +} + +void TaskDraftParameters::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(); + } else if (selectionMode == plane) { + PartDesign::Draft* pcDraft = static_cast(DressUpView->getObject()); + std::vector planes; + App::DocumentObject* selObj; + getReferencedSelection(pcDraft, msg, selObj, planes); + pcDraft->NeutralPlane.setValue(selObj, planes); + ui->linePlane->setText(getRefStr(selObj, planes)); + + pcDraft->getDocument()->recomputeFeature(pcDraft); + clearButtons(none); + exitSelectionMode(); + } else if (selectionMode == line) { + PartDesign::Draft* pcDraft = static_cast(DressUpView->getObject()); + std::vector edges; + App::DocumentObject* selObj; + getReferencedSelection(pcDraft, msg, selObj, edges); + pcDraft->PullDirection.setValue(selObj, edges); + ui->lineLine->setText(getRefStr(selObj, edges)); + + pcDraft->getDocument()->recomputeFeature(pcDraft); + clearButtons(none); + exitSelectionMode(); + } + } +} + +void TaskDraftParameters::clearButtons(const selectionModes notThis) +{ + if (notThis != refAdd) ui->buttonRefAdd->setChecked(false); + if (notThis != refRemove) ui->buttonRefRemove->setChecked(false); + if (notThis != line) ui->buttonLine->setChecked(false); + if (notThis != plane) ui->buttonPlane->setChecked(false); +} + +void TaskDraftParameters::onButtonPlane(bool checked) +{ + if (checked) { + clearButtons(plane); + hideObject(); + selectionMode = plane; + Gui::Selection().clearSelection(); + Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), true, true, true)); + } +} + +void TaskDraftParameters::onButtonLine(bool checked) +{ + if (checked) { + clearButtons(line); + hideObject(); + selectionMode = line; + Gui::Selection().clearSelection(); + Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), true, false, true)); + } +} + +void TaskDraftParameters::onRefDeleted(void) +{ + PartDesign::Draft* pcDraft = static_cast(DressUpView->getObject()); + App::DocumentObject* base = pcDraft->Base.getValue(); + std::vector faces = pcDraft->Base.getSubValues(); + faces.erase(faces.begin() + ui->listWidgetReferences->currentRow()); + pcDraft->Base.setValue(base, faces); + ui->listWidgetReferences->model()->removeRow(ui->listWidgetReferences->currentRow()); + pcDraft->getDocument()->recomputeFeature(pcDraft); +} + +void TaskDraftParameters::getPlane(App::DocumentObject*& obj, std::vector& sub) const +{ + sub = std::vector(1,""); + QStringList parts = ui->linePlane->text().split(QChar::fromAscii(':')); + obj = DressUpView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str()); + if (parts.size() > 1) + sub[0] = parts[1].toStdString(); +} + +void TaskDraftParameters::getLine(App::DocumentObject*& obj, std::vector& sub) const +{ + sub = std::vector(1,""); + QStringList parts = ui->lineLine->text().split(QChar::fromAscii(':')); + obj = DressUpView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str()); + if (parts.size() > 1) + sub[0] = parts[1].toStdString(); +} + +void TaskDraftParameters::onAngleChanged(double angle) +{ + clearButtons(none); + PartDesign::Draft* pcDraft = static_cast(DressUpView->getObject()); + pcDraft->Angle.setValue(angle); + pcDraft->getDocument()->recomputeFeature(pcDraft); +} + +const double TaskDraftParameters::getAngle(void) const +{ + return ui->draftAngle->value().getValue(); +} + +void TaskDraftParameters::onReversedChanged(const bool on) { + clearButtons(none); + PartDesign::Draft* pcDraft = static_cast(DressUpView->getObject()); + pcDraft->Reversed.setValue(on); + pcDraft->getDocument()->recomputeFeature(pcDraft); +} + +const bool TaskDraftParameters::getReversed(void) const +{ + return ui->checkReverse->isChecked(); +} + +TaskDraftParameters::~TaskDraftParameters() +{ + Gui::Selection().rmvSelectionGate(); + delete ui; +} + +void TaskDraftParameters::changeEvent(QEvent *e) +{ + TaskBox::changeEvent(e); + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(proxy); + } +} + + +//************************************************************************** +//************************************************************************** +// TaskDialog +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TaskDlgDraftParameters::TaskDlgDraftParameters(ViewProviderDraft *DressUpView) + : TaskDlgDressUpParameters(DressUpView) +{ + parameter = new TaskDraftParameters(DressUpView); + + Content.push_back(parameter); +} + +TaskDlgDraftParameters::~TaskDlgDraftParameters() +{ + +} + +//==== calls from the TaskView =============================================================== + + +//void TaskDlgDraftParameters::open() +//{ +// // a transaction is already open at creation time of the draft +// if (!Gui::Command::hasPendingCommand()) { +// QString msg = QObject::tr("Edit draft"); +// Gui::Command::openCommand((const char*)msg.toUtf8()); +// } +//} + +bool TaskDlgDraftParameters::accept() +{ + parameter->showObject(); + + // Force the user to select a neutral plane + std::vector strings; + App::DocumentObject* obj; + TaskDraftParameters* draftparameter = static_cast(parameter); + draftparameter->getPlane(obj, strings); + std::string neutralPlane = getPythonStr(obj, strings); + if (neutralPlane.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Missing neutral plane"), + QObject::tr("Please select a plane or an edge plus a pull direction")); + return false; + } + +<<<<<<< 7e34fb3b6f610a533bbd50991d4b09cf063cda7b + std::string name = DraftView->getObject()->getNameInDocument(); + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),parameter->getAngle()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),parameter->getReversed()); + try { + std::vector faces = parameter->getFaces(); + std::stringstream str; + str << "App.ActiveDocument." << name.c_str() << ".Base = (App.ActiveDocument." + << parameter->getBase()->getNameInDocument() << ",["; + for (std::vector::const_iterator it = faces.begin(); it != faces.end(); ++it) + str << "\"" << *it << "\","; + str << "])"; + Gui::Command::doCommand(Gui::Command::Doc,str.str().c_str()); + } + catch (const Base::Exception& e) { + QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); + return false; + } +======= + std::string name = DressUpView->getObject()->getNameInDocument(); + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),draftparameter->getAngle()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),draftparameter->getReversed()); +>>>>>>> Unify code of Dressup features (part 1: Draft) + if (!neutralPlane.empty()) { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = %s", name.c_str(), neutralPlane.c_str()); + } else + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = None", name.c_str()); + draftparameter->getLine(obj, strings); + std::string pullDirection = getPythonStr(obj, strings); + if (!pullDirection.empty()) { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = %s", name.c_str(), pullDirection.c_str()); + } else + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = None", name.c_str()); + + return TaskDlgDressUpParameters::accept(); +} + +#include "moc_TaskDraftParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskDraftParameters.h b/src/Mod/PartDesign/Gui/TaskDraftParameters.h index 2b8c60636..e09b08283 100644 --- a/src/Mod/PartDesign/Gui/TaskDraftParameters.h +++ b/src/Mod/PartDesign/Gui/TaskDraftParameters.h @@ -24,31 +24,19 @@ #ifndef GUI_TASKVIEW_TaskDraftParameters_H #define GUI_TASKVIEW_TaskDraftParameters_H -#include -#include -#include - +#include "TaskDressUpParameters.h" #include "ViewProviderDraft.h" class Ui_TaskDraftParameters; -namespace App { -class Property; -} - -namespace Gui { -class ViewProvider; -} - - namespace PartDesignGui { -class TaskDraftParameters : public Gui::TaskView::TaskBox, public Gui::SelectionObserver +class TaskDraftParameters : public TaskDressUpParameters { Q_OBJECT public: - TaskDraftParameters(ViewProviderDraft *DraftView, QWidget *parent=0); + TaskDraftParameters(ViewProviderDressUp *DressUpView, QWidget *parent=0); ~TaskDraftParameters(); const double getAngle(void) const; @@ -56,41 +44,25 @@ public: const std::vector getFaces(void) const; void getPlane(App::DocumentObject*& obj, std::vector& sub) const; void getLine(App::DocumentObject*& obj, std::vector& sub) const; - App::DocumentObject *getBase(void) const; - - void hideObject(); - void showObject(); private Q_SLOTS: void onAngleChanged(double angle); void onReversedChanged(bool reversed); - void onButtonFaceAdd(const bool checked); - void onButtonFaceRemove(const bool checked); void onButtonPlane(const bool checked); void onButtonLine(const bool checked); - void onFaceDeleted(void); - -protected: - void exitSelectionMode(); + void onRefDeleted(void); protected: + virtual void clearButtons(const selectionModes notThis); void changeEvent(QEvent *e); virtual void onSelectionChanged(const Gui::SelectionChanges& msg); private: - void clearButtons(const QToolButton* notThis); - -private: - QWidget* proxy; Ui_TaskDraftParameters* ui; - ViewProviderDraft *DraftView; - - enum selectionModes { none, faceAdd, faceRemove, plane, line }; - selectionModes selectionMode; }; /// simulation dialog for the TaskView -class TaskDlgDraftParameters : public Gui::TaskView::TaskDialog +class TaskDlgDraftParameters : public TaskDlgDressUpParameters { Q_OBJECT @@ -98,30 +70,9 @@ public: TaskDlgDraftParameters(ViewProviderDraft *DraftView); ~TaskDlgDraftParameters(); - ViewProviderDraft* getDraftView() const - { return DraftView; } - - public: - /// is called the TaskView when the dialog is opened - virtual void open(); - /// is called by the framework if an button is clicked which has no accept or reject role - virtual void clicked(int); /// is called by the framework if the dialog is accepted (Ok) virtual bool accept(); - /// is called by the framework if the dialog is rejected (Cancel) - virtual bool reject(); - virtual bool isAllowedAlterDocument(void) const - { return false; } - - /// returns for Close and Help button - virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const - { return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; } - -protected: - ViewProviderDraft *DraftView; - - TaskDraftParameters *parameter; }; } //namespace PartDesignGui diff --git a/src/Mod/PartDesign/Gui/TaskDraftParameters.h.orig b/src/Mod/PartDesign/Gui/TaskDraftParameters.h.orig new file mode 100644 index 000000000..87b605263 --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskDraftParameters.h.orig @@ -0,0 +1,96 @@ +/*************************************************************************** + * Copyright (c) 2012 Jan Rheinländer * + * * + * 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 * + * * + ***************************************************************************/ + + +#ifndef GUI_TASKVIEW_TaskDraftParameters_H +#define GUI_TASKVIEW_TaskDraftParameters_H + +#include "TaskDressUpParameters.h" +#include "ViewProviderDraft.h" + +class Ui_TaskDraftParameters; + +namespace PartDesignGui { + +class TaskDraftParameters : public TaskDressUpParameters +{ + Q_OBJECT + +public: + TaskDraftParameters(ViewProviderDressUp *DressUpView, QWidget *parent=0); + ~TaskDraftParameters(); + + const double getAngle(void) const; + const bool getReversed(void) const; + const std::vector getFaces(void) const; + void getPlane(App::DocumentObject*& obj, std::vector& sub) const; + void getLine(App::DocumentObject*& obj, std::vector& sub) const; + +private Q_SLOTS: + void onAngleChanged(double angle); + void onReversedChanged(bool reversed); + void onButtonPlane(const bool checked); + void onButtonLine(const bool checked); + void onRefDeleted(void); + +protected: + virtual void clearButtons(const selectionModes notThis); + void changeEvent(QEvent *e); + virtual void onSelectionChanged(const Gui::SelectionChanges& msg); + +private: + Ui_TaskDraftParameters* ui; +}; + +/// simulation dialog for the TaskView +class TaskDlgDraftParameters : public TaskDlgDressUpParameters +{ + Q_OBJECT + +public: + TaskDlgDraftParameters(ViewProviderDraft *DraftView); + ~TaskDlgDraftParameters(); + +public: + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept(); +<<<<<<< 7e34fb3b6f610a533bbd50991d4b09cf063cda7b + /// is called by the framework if the dialog is rejected (Cancel) + virtual bool reject(); + virtual bool isAllowedAlterDocument(void) const + { return false; } + + /// returns for Close and Help button + virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const + { return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; } + +protected: + ViewProviderDraft *DraftView; + + TaskDraftParameters *parameter; +======= +>>>>>>> Unify code of Dressup features (part 1: Draft) +}; + +} //namespace PartDesignGui + +#endif // GUI_TASKVIEW_TASKAPPERANCE_H diff --git a/src/Mod/PartDesign/Gui/TaskDraftParameters.ui b/src/Mod/PartDesign/Gui/TaskDraftParameters.ui index 9e5703bc6..32b5fa4ac 100644 --- a/src/Mod/PartDesign/Gui/TaskDraftParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskDraftParameters.ui @@ -17,7 +17,7 @@ - + Add face @@ -27,7 +27,7 @@ - + Remove face @@ -39,7 +39,7 @@ - + @@ -114,7 +114,7 @@ checkReverse - listWidgetFaces + listWidgetReferences diff --git a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp new file mode 100644 index 000000000..7420b3a83 --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp @@ -0,0 +1,252 @@ +/*************************************************************************** + * Copyright (c) 2012 Jan Rheinländer * + * * + * 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 +# include +#endif + +#include "TaskDressUpParameters.h" +#include "Workbench.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace PartDesignGui; +using namespace Gui; + +/* TRANSLATOR PartDesignGui::TaskDressUpParameters */ + +TaskDressUpParameters::TaskDressUpParameters(ViewProviderDressUp *DressUpView,QWidget *parent) + : TaskBox(Gui::BitmapFactory().pixmap((std::string("PartDesign_") + DressUpView->featureName).c_str()), + QString::fromAscii((DressUpView->featureName + " parameters").c_str()), + true, + parent), + DressUpView(DressUpView) +{ + selectionMode = none; +} + +TaskDressUpParameters::~TaskDressUpParameters() +{ + // make sure to remove selection gate in all cases + Gui::Selection().rmvSelectionGate(); +} + +const bool TaskDressUpParameters::referenceSelected(const Gui::SelectionChanges& msg) +{ + if ((msg.Type == Gui::SelectionChanges::AddSelection) && ( + (selectionMode == refAdd) || (selectionMode == refRemove))) { + + if (strcmp(msg.pDocName, DressUpView->getObject()->getDocument()->getName()) != 0) + return false; + + PartDesign::DressUp* pcDressUp = static_cast(DressUpView->getObject()); + App::DocumentObject* base = this->getBase(); + // TODO: Must we make a copy here instead of assigning to const char* ? + const char* fname = base->getNameInDocument(); + if (strcmp(msg.pObjectName, fname) != 0) + return false; + + std::string subName(msg.pSubName); + std::vector refs = pcDressUp->Base.getSubValues(); + std::vector::iterator f = std::find(refs.begin(), refs.end(), subName); + + if (selectionMode == refAdd) { + if (f == refs.end()) + refs.push_back(subName); + else + return false; // duplicate selection + } else { + if (f != refs.end()) + refs.erase(f); + else + return false; + } + pcDressUp->Base.setValue(base, refs); + DressUpView->highlightReferences(false); + pcDressUp->getDocument()->recomputeFeature(pcDressUp); + + return true; + } + + return false; +} + +void TaskDressUpParameters::onButtonRefAdd(bool checked) +{ + if (checked) { + clearButtons(refAdd); + hideObject(); + selectionMode = refAdd; + Gui::Selection().clearSelection(); + Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), false, true, false)); + DressUpView->highlightReferences(true); + } +} + +void TaskDressUpParameters::onButtonRefRemove(const bool checked) +{ + if (checked) { + clearButtons(refRemove); + hideObject(); + selectionMode = refRemove; + Gui::Selection().clearSelection(); + Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), false, true, false)); + DressUpView->highlightReferences(true); + } +} + +const std::vector TaskDressUpParameters::getReferences() const +{ + PartDesign::DressUp* pcDressUp = static_cast(DressUpView->getObject()); + std::vector result = pcDressUp->Base.getSubValues(); + return result; +} + +// TODO: This code is identical with TaskTransformedParameters::removeItemFromListWidget() +void TaskDressUpParameters::removeItemFromListWidget(QListWidget* widget, const char* itemstr) +{ + QList items = widget->findItems(QString::fromAscii(itemstr), Qt::MatchExactly); + if (!items.empty()) { + for (QList::const_iterator i = items.begin(); i != items.end(); i++) { + QListWidgetItem* it = widget->takeItem(widget->row(*i)); + delete it; + } + } +} + +void TaskDressUpParameters::hideObject() +{ + Gui::Document* doc = Gui::Application::Instance->activeDocument(); + App::DocumentObject* base = getBase(); + if (doc != NULL && base != NULL) { + doc->setHide(DressUpView->getObject()->getNameInDocument()); + doc->setShow(base->getNameInDocument()); + } +} + +void TaskDressUpParameters::showObject() +{ + Gui::Document* doc = Gui::Application::Instance->activeDocument(); + App::DocumentObject* base = getBase(); + if (doc != NULL && base != NULL) { + doc->setShow(DressUpView->getObject()->getNameInDocument()); + doc->setHide(base->getNameInDocument()); + } +} + +App::DocumentObject* TaskDressUpParameters::getBase(void) const +{ + PartDesign::DressUp* pcDressUp = static_cast(DressUpView->getObject()); + return pcDressUp->Base.getValue(); +} + +void TaskDressUpParameters::exitSelectionMode() +{ + selectionMode = none; + Gui::Selection().rmvSelectionGate(); + Gui::Selection().clearSelection(); + showObject(); +} + +//************************************************************************** +//************************************************************************** +// TaskDialog +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TaskDlgDressUpParameters::TaskDlgDressUpParameters(ViewProviderDressUp *DressUpView) + : TaskDialog(),DressUpView(DressUpView) +{ + assert(DressUpView); +} + +TaskDlgDressUpParameters::~TaskDlgDressUpParameters() +{ + +} + +//==== calls from the TaskView =============================================================== + +bool TaskDlgDressUpParameters::accept() +{ + std::string name = DressUpView->getObject()->getNameInDocument(); + + try { + std::vector refs = parameter->getReferences(); + std::stringstream str; + str << "App.ActiveDocument." << name.c_str() << ".Base = (App.ActiveDocument." + << parameter->getBase()->getNameInDocument() << ",["; + for (std::vector::const_iterator it = refs.begin(); it != refs.end(); ++it) + str << "\"" << *it << "\","; + str << "])"; + Gui::Command::doCommand(Gui::Command::Doc,str.str().c_str()); + } + catch (const Base::Exception& e) { + QMessageBox::warning(parameter, tr("Input error"), QString::fromAscii(e.what())); + return false; + } + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::Command::commitCommand(); + + return true; +} + +bool TaskDlgDressUpParameters::reject() +{ + // roll 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_TaskDressUpParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskDressUpParameters.h b/src/Mod/PartDesign/Gui/TaskDressUpParameters.h new file mode 100644 index 000000000..ce69f94a4 --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskDressUpParameters.h @@ -0,0 +1,112 @@ +/*************************************************************************** + * Copyright (c) 2012 Jan Rheinländer * + * * + * 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 * + * * + ***************************************************************************/ + + +#ifndef GUI_TASKVIEW_TaskDressUpParameters_H +#define GUI_TASKVIEW_TaskDressUpParameters_H + +#include +#include +#include + +#include "ViewProviderDressUp.h" + +class QListWidget; + +namespace PartDesignGui { + +class TaskDressUpParameters : public Gui::TaskView::TaskBox, public Gui::SelectionObserver +{ + Q_OBJECT + +public: + TaskDressUpParameters(ViewProviderDressUp *DressUpView, QWidget *parent=0); + virtual ~TaskDressUpParameters(); + + const std::vector getReferences(void) const; + App::DocumentObject *getBase(void) const; + + void hideObject(); + void showObject(); + +protected Q_SLOTS: + void onButtonRefAdd(const bool checked); + void onButtonRefRemove(const bool checked); + virtual void onRefDeleted(void)=0; + +protected: + void exitSelectionMode(); + const bool referenceSelected(const Gui::SelectionChanges& msg); + +protected: + enum selectionModes { none, refAdd, refRemove, plane, line }; + virtual void clearButtons(const selectionModes notThis) = 0; + virtual void changeEvent(QEvent *e) = 0; + static void removeItemFromListWidget(QListWidget* widget, const char* itemstr); + +protected: + QWidget* proxy; + ViewProviderDressUp *DressUpView; + + + selectionModes selectionMode; +}; + +/// simulation dialog for the TaskView +class TaskDlgDressUpParameters : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgDressUpParameters(ViewProviderDressUp *DressUpView); + virtual ~TaskDlgDressUpParameters(); + + ViewProviderDressUp* getDressUpView() const + { return DressUpView; } + + +public: + /// is called the TaskView when the dialog is opened + virtual void open() {} + /// is called by the framework if an button is clicked which has no accept or reject role + virtual void clicked(int) {} + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept(); + /// is called by the framework if the dialog is rejected (Cancel) + virtual bool reject(); + /// is called by the framework if the user presses the help button + virtual bool isAllowedAlterDocument(void) const + { return false; } + + /// returns for Close and Help button + virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const + { return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; } + +protected: + ViewProviderDressUp *DressUpView; + + TaskDressUpParameters *parameter; +}; + +} //namespace PartDesignGui + +#endif // GUI_TASKVIEW_TaskDressUpParameters_H diff --git a/src/Mod/PartDesign/Gui/ViewProviderDraft.cpp b/src/Mod/PartDesign/Gui/ViewProviderDraft.cpp index dd82ec2aa..f4394776f 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDraft.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDraft.cpp @@ -42,7 +42,7 @@ using namespace PartDesignGui; -PROPERTY_SOURCE(PartDesignGui::ViewProviderDraft,PartDesignGui::ViewProvider) +PROPERTY_SOURCE(PartDesignGui::ViewProviderDraft,PartDesignGui::ViewProviderDressUp) ViewProviderDraft::ViewProviderDraft() { @@ -70,7 +70,7 @@ bool ViewProviderDraft::setEdit(int ModNum) // the task panel Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); TaskDlgDraftParameters *draftDlg = qobject_cast(dlg); - if (draftDlg && draftDlg->getDraftView() != this) + if (draftDlg && draftDlg->getDressUpView() != this) draftDlg = 0; // another pad left open its task panel if (dlg && !draftDlg) { QMessageBox msgBox; diff --git a/src/Mod/PartDesign/Gui/ViewProviderDraft.h b/src/Mod/PartDesign/Gui/ViewProviderDraft.h index 16b03f6c7..694a078d7 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDraft.h +++ b/src/Mod/PartDesign/Gui/ViewProviderDraft.h @@ -24,12 +24,12 @@ #ifndef PARTGUI_ViewProviderDraft_H #define PARTGUI_ViewProviderDraft_H -#include "ViewProvider.h" +#include "ViewProviderDressUp.h" namespace PartDesignGui { -class PartDesignGuiExport ViewProviderDraft : public ViewProvider +class PartDesignGuiExport ViewProviderDraft : public ViewProviderDressUp { PROPERTY_HEADER(PartDesignGui::ViewProviderDraft); diff --git a/src/Mod/PartDesign/Gui/ViewProviderDressUp.cpp b/src/Mod/PartDesign/Gui/ViewProviderDressUp.cpp new file mode 100644 index 000000000..c55bac981 --- /dev/null +++ b/src/Mod/PartDesign/Gui/ViewProviderDressUp.cpp @@ -0,0 +1,121 @@ +/*************************************************************************** + * Copyright (c) 2012 Jan Rheinländer * + * * + * 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 +# include +# include +# include +# include +# include +#endif + +#include "ViewProviderDressUp.h" +#include "TaskDressUpParameters.h" +#include +#include +#include +#include +#include + + +using namespace PartDesignGui; + +PROPERTY_SOURCE(PartDesignGui::ViewProviderDressUp,PartDesignGui::ViewProvider) + +void ViewProviderDressUp::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) +{ + QAction* act; + act = menu->addAction(QObject::tr((std::string("Edit ") + featureName + " feature").c_str()), receiver, member); + act->setData(QVariant((int)ViewProvider::Default)); + PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member); +} + +const bool ViewProviderDressUp::checkDlgOpen(TaskDlgDressUpParameters* dressUpDlg) { + // When double-clicking on the item for this feature the + // object unsets and sets its edit mode without closing + // the task panel + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + dressUpDlg = qobject_cast(dlg); + + if ((dressUpDlg != NULL) && (dressUpDlg->getDressUpView() != this)) + dressUpDlg = NULL; // another transformed feature left open its task panel + + if ((dlg != NULL) && (dressUpDlg == NULL)) { + QMessageBox msgBox; + msgBox.setText(QObject::tr("A dialog is already open in the task panel")); + msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?")); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + int ret = msgBox.exec(); + if (ret == QMessageBox::Yes) + Gui::Control().closeDialog(); + else + return false; + } + + // clear the selection (convenience) + Gui::Selection().clearSelection(); + + // Continue (usually in virtual method setEdit()) + return true; +} + +bool ViewProviderDressUp::onDelete(const std::vector &s) +{ + return ViewProvider::onDelete(s); +} + +void ViewProviderDressUp::highlightReferences(const bool on) +{ + PartDesign::DressUp* pcDressUp = static_cast(getObject()); + Part::Feature* base = static_cast(pcDressUp->Base.getValue()); + if (base == NULL) return; + PartGui::ViewProviderPart* vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(base)); + if (vp == NULL) return; + + if (on) { + std::vector SubVals = pcDressUp->Base.getSubValuesStartsWith("Face"); + if (SubVals.size() == 0) return; + + TopTools_IndexedMapOfShape fMap; + TopExp::MapShapes(base->Shape.getValue(), TopAbs_FACE, fMap); + + originalColors = vp->DiffuseColor.getValues(); + std::vector colors = originalColors; + colors.resize(fMap.Extent(), ShapeColor.getValue()); + + for (std::vector::const_iterator f = SubVals.begin(); f != SubVals.end(); f++) { + int idx = atoi(f->substr(4).c_str()) - 1; + // TODO: Find a better colour + colors[idx] = App::Color(0.2,1,0.2); + } + vp->DiffuseColor.setValues(colors); + } else { + vp->DiffuseColor.setValues(originalColors); + } +} + diff --git a/src/Mod/PartDesign/Gui/ViewProviderDressUp.h b/src/Mod/PartDesign/Gui/ViewProviderDressUp.h new file mode 100644 index 000000000..723dd2312 --- /dev/null +++ b/src/Mod/PartDesign/Gui/ViewProviderDressUp.h @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright (c) 2012 Jan Rheinländer * + * * + * 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 * + * * + ***************************************************************************/ + + +#ifndef PARTGUI_ViewProviderDressUp_H +#define PARTGUI_ViewProviderDressUp_H + +#include "ViewProvider.h" + + +namespace PartDesignGui { + +class TaskDlgDressUpParameters; + +class PartDesignGuiExport ViewProviderDressUp : public ViewProvider +{ + PROPERTY_HEADER(PartDesignGui::ViewProviderDressUp); + +public: + /// constructor + ViewProviderDressUp() + : featureName("undefined") {} + /// destructor + virtual ~ViewProviderDressUp() + {} + + /// grouping handling + void setupContextMenu(QMenu*, QObject*, const char*); + + virtual bool onDelete(const std::vector &); + + /// Highlight the references that have been selected + void highlightReferences(const bool on); + + // The feature name of the subclass + std::string featureName; + +protected: + const bool checkDlgOpen(TaskDlgDressUpParameters* dressUpDlg); + +private: + std::vector originalColors; + +}; + + + +} // namespace PartDesignGui + + +#endif // PARTGUI_ViewProviderDressUp_H