diff --git a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp index 0e1a7bede..a6a2562f8 100644 --- a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp @@ -25,7 +25,6 @@ #ifndef _PreComp_ # include -# include #endif #include "TaskDressUpParameters.h" @@ -156,7 +155,7 @@ void TaskDressUpParameters::hideObject() if (doc != NULL && base != NULL) { doc->setHide(DressUpView->getObject()->getNameInDocument()); doc->setShow(base->getNameInDocument()); - } + } } void TaskDressUpParameters::showObject() @@ -206,25 +205,16 @@ bool TaskDlgDressUpParameters::accept() std::string name = vp->getObject()->getNameInDocument(); getDressUpView()->highlightReferences(false); - 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(); + 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()); - return true; + return TaskDlgFeatureParameters::accept(); } #include "moc_TaskDressUpParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp b/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp index 4cc6f2ce5..9b575811d 100644 --- a/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp @@ -22,6 +22,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +#include #endif #include @@ -48,6 +49,40 @@ TaskDlgFeatureParameters::~TaskDlgFeatureParameters() } +bool TaskDlgFeatureParameters::accept() { + App::DocumentObject* feature = vp->getObject(); + + try { + // Make sure the feature is what we are expecting + // Should be fine but you never know... + if ( !feature->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId()) ) { + throw Base::Exception("Bad object processed in the feature dialog."); + } + + App::DocumentObject* support = static_cast(feature)->BaseFeature.getValue(); + + if (support) { + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().hide(\"%s\")", + support->getNameInDocument()); + } + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); + + if (!feature->isValid()) { + throw Base::Exception(vp->getObject()->getStatusString()); + } + + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::Command::commitCommand(); + } catch (const Base::Exception& e) { + // Generally the only thing that should fail is feature->isValid() others should be fine + QMessageBox::warning( 0, tr("Input error"), QString::fromAscii(e.what())); + return false; + } + + return true; +} + bool TaskDlgFeatureParameters::reject() { PartDesign::Feature* feature = static_cast(vp->getObject()); diff --git a/src/Mod/PartDesign/Gui/TaskFeatureParameters.h b/src/Mod/PartDesign/Gui/TaskFeatureParameters.h index ce207478d..41305cc39 100644 --- a/src/Mod/PartDesign/Gui/TaskFeatureParameters.h +++ b/src/Mod/PartDesign/Gui/TaskFeatureParameters.h @@ -41,7 +41,7 @@ public: public: /// is called by the framework if the dialog is accepted (Ok) - virtual bool accept()=0; + virtual bool accept(); /// is called by the framework if the dialog is rejected (Cancel) virtual bool reject(); diff --git a/src/Mod/PartDesign/Gui/TaskPadParameters.cpp b/src/Mod/PartDesign/Gui/TaskPadParameters.cpp index 6a64b407f..d90d18d05 100644 --- a/src/Mod/PartDesign/Gui/TaskPadParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPadParameters.cpp @@ -373,12 +373,15 @@ int TaskPadParameters::getMode(void) const return ui->changeMode->currentIndex(); } -QByteArray TaskPadParameters::getFaceName(void) const +QString TaskPadParameters::getFaceName(void) const { - if (getMode() == 3) - return getFaceReference(ui->lineFaceName->text(), ui->lineFaceName->property("FaceName").toString()).toLatin1(); - else - return ""; + if (getMode() == 3) { + QString faceName = ui->lineFaceName->property("FaceName").toString(); + if (!faceName.isEmpty()) { + return getFaceReference(ui->lineFaceName->text(), faceName); + } + } + return QString(); } TaskPadParameters::~TaskPadParameters() @@ -446,18 +449,15 @@ void TaskPadParameters::apply() ui->lengthEdit2->apply(); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u",cname,getMode()); - std::string facename = getFaceName().data(); + QString facename = getFaceName(); - if (!facename.empty()) { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", name.c_str(), facename.c_str()); - } else + if (!facename.isEmpty()) { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", + cname, facename.toLatin1().data()); + } else { Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", cname); + } Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Offset = %f", name.c_str(), getOffset()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); - if (!vp->getObject()->isValid()) - throw Base::Exception(vp->getObject()->getStatusString()); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); - Gui::Command::commitCommand(); } //************************************************************************** @@ -483,20 +483,11 @@ TaskDlgPadParameters::~TaskDlgPadParameters() bool TaskDlgPadParameters::accept() { - // save the history parameter->saveHistory(); + parameter->apply(); - try { - //Gui::Command::openCommand("Pad changed"); - parameter->apply(); - } - catch (const Base::Exception& e) { - QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); - return false; - } - - return true; + return TaskDlgSketchBasedParameters::accept(); } diff --git a/src/Mod/PartDesign/Gui/TaskPadParameters.cpp.orig b/src/Mod/PartDesign/Gui/TaskPadParameters.cpp.orig new file mode 100644 index 000000000..ec9d7c4ed --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskPadParameters.cpp.orig @@ -0,0 +1,507 @@ +/*************************************************************************** + * Copyright (c) 2011 Juergen Riegel * + * * + * 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 +#endif + +#include "ui_TaskPadParameters.h" +#include "TaskPadParameters.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "TaskSketchBasedParameters.h" +#include "ReferenceSelection.h" +#include "Workbench.h" + +using namespace PartDesignGui; +using namespace Gui; + +/* TRANSLATOR PartDesignGui::TaskPadParameters */ + +TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,bool newObj, QWidget *parent) + : TaskSketchBasedParameters(PadView, parent, "PartDesign_Pad",tr("Pad parameters")) +{ + // we need a separate container widget to add all controls to + proxy = new QWidget(this); + ui = new Ui_TaskPadParameters(); + ui->setupUi(proxy); + QMetaObject::connectSlotsByName(this); + + connect(ui->lengthEdit, SIGNAL(valueChanged(double)), + this, SLOT(onLengthChanged(double))); + connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)), + this, SLOT(onMidplane(bool))); + connect(ui->checkBoxReversed, SIGNAL(toggled(bool)), + this, SLOT(onReversed(bool))); + connect(ui->lengthEdit2, SIGNAL(valueChanged(double)), + this, SLOT(onLength2Changed(double))); + connect(ui->spinOffset, SIGNAL(valueChanged(double)), + this, SLOT(onOffsetChanged(double))); + connect(ui->changeMode, SIGNAL(currentIndexChanged(int)), + this, SLOT(onModeChanged(int))); + connect(ui->buttonFace, SIGNAL(clicked()), + this, SLOT(onButtonFace())); + connect(ui->lineFaceName, SIGNAL(textEdited(QString)), + this, SLOT(onFaceName(QString))); + connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)), + this, SLOT(onUpdateView(bool))); + + this->groupLayout()->addWidget(proxy); + + // Temporarily prevent unnecessary feature recomputes + ui->lengthEdit->blockSignals(true); + ui->lengthEdit2->blockSignals(true); + ui->spinOffset->blockSignals(true); + ui->checkBoxMidplane->blockSignals(true); + ui->checkBoxReversed->blockSignals(true); + ui->buttonFace->blockSignals(true); + ui->lineFaceName->blockSignals(true); + ui->changeMode->blockSignals(true); + + // set the history path + ui->lengthEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/PadLength")); + ui->lengthEdit2->setParamGrpPath(QByteArray("User parameter:BaseApp/History/PadLength2")); + + // Get the feature data + PartDesign::Pad* pcPad = static_cast(vp->getObject()); + Base::Quantity l = pcPad->Length.getQuantityValue(); + bool midplane = pcPad->Midplane.getValue(); + bool reversed = pcPad->Reversed.getValue(); + Base::Quantity l2 = pcPad->Length2.getQuantityValue(); + double off = pcPad->Offset.getValue(); + int index = pcPad->Type.getValue(); // must extract value here, clear() kills it! + App::DocumentObject* obj = pcPad->UpToFace.getValue(); + std::vector subStrings = pcPad->UpToFace.getSubValues(); + std::string upToFace; + int faceId = -1; + if ((obj != NULL) && !subStrings.empty()) { + upToFace = subStrings.front(); + if (upToFace.substr(0,4) == "Face") + faceId = std::atoi(&upToFace[4]); + } + + // Fill data into dialog elements + ui->lengthEdit->setMinimum(0); + ui->lengthEdit->setMaximum(INT_MAX); + ui->lengthEdit->setValue(l); + ui->lengthEdit2->setMinimum(0); + ui->lengthEdit2->setMaximum(INT_MAX); + ui->lengthEdit2->setValue(l2); + ui->spinOffset->setMaximum(INT_MAX); + ui->spinOffset->setMinimum(-INT_MAX); + ui->spinOffset->setValue(off); + + // Bind input fields to properties + ui->lengthEdit->bind(pcPad->Length); + ui->lengthEdit2->bind(pcPad->Length2); + ui->checkBoxMidplane->setChecked(midplane); + // According to bug #0000521 the reversed option + // shouldn't be de-activated if the pad has a support face + ui->checkBoxReversed->setChecked(reversed); + if ((obj != NULL) && PartDesign::Feature::isDatum(obj)) + ui->lineFaceName->setText(QString::fromAscii(obj->getNameInDocument())); + else if (faceId >= 0) + ui->lineFaceName->setText(QString::fromAscii(obj->getNameInDocument()) + QString::fromAscii(":") + tr("Face") + + QString::number(faceId)); + else + ui->lineFaceName->setText(tr("No face selected")); + ui->lineFaceName->setProperty("FaceName", QByteArray(upToFace.c_str())); + ui->changeMode->clear(); + ui->changeMode->insertItem(0, tr("Dimension")); + ui->changeMode->insertItem(1, tr("To last")); + ui->changeMode->insertItem(2, tr("To first")); + ui->changeMode->insertItem(3, tr("Up to face")); + ui->changeMode->insertItem(4, tr("Two dimensions")); + ui->changeMode->setCurrentIndex(index); + + // activate and de-activate dialog elements as appropriate + ui->lengthEdit->blockSignals(false); + ui->lengthEdit2->blockSignals(false); + ui->spinOffset->blockSignals(false); + ui->checkBoxMidplane->blockSignals(false); + ui->checkBoxReversed->blockSignals(false); + ui->buttonFace->blockSignals(false); + ui->lineFaceName->blockSignals(false); + ui->changeMode->blockSignals(false); + updateUI(index); + + // if it is a newly created object use the last value of the history + if(newObj){ + ui->lengthEdit->setToLastUsedValue(); + ui->lengthEdit->selectNumber(); + ui->lengthEdit2->setToLastUsedValue(); + ui->lengthEdit2->selectNumber(); + } +} + +void TaskPadParameters::updateUI(int index) +{ + if (index == 0) { // dimension + ui->lengthEdit->setVisible(true); + ui->lengthEdit->setEnabled(true); + ui->lengthEdit->selectNumber(); + ui->labelLength->setVisible(true); + ui->spinOffset->setVisible(false); + ui->spinOffset->setEnabled(false); + ui->labelOffset->setVisible(false); + // Make sure that the spin box has the focus to get key events + // Calling setFocus() directly doesn't work because the spin box is not + // yet visible. + QMetaObject::invokeMethod(ui->lengthEdit, "setFocus", Qt::QueuedConnection); + ui->checkBoxMidplane->setEnabled(true); + // Reverse only makes sense if Midplane is not true + ui->checkBoxReversed->setEnabled(!ui->checkBoxMidplane->isChecked()); + ui->labelLength2->setVisible(false); + ui->lengthEdit2->setVisible(false); + ui->lengthEdit2->setEnabled(false); + ui->buttonFace->setEnabled(false); + ui->lineFaceName->setEnabled(false); + onButtonFace(false); + } else if (index == 1 || index == 2) { // up to first/last + ui->lengthEdit->setVisible(false); + ui->lengthEdit->setEnabled(false); + ui->labelLength->setVisible(false); + ui->spinOffset->setVisible(true); + ui->spinOffset->setEnabled(true); + ui->labelOffset->setVisible(true); + ui->checkBoxMidplane->setEnabled(false); + ui->checkBoxReversed->setEnabled(true); + ui->labelLength2->setVisible(false); + ui->lengthEdit2->setVisible(false); + ui->lengthEdit2->setEnabled(false); + ui->buttonFace->setEnabled(false); + ui->lineFaceName->setEnabled(false); + onButtonFace(false); + } else if (index == 3) { // up to face + ui->lengthEdit->setVisible(false); + ui->lengthEdit->setEnabled(false); + ui->labelLength->setVisible(false); + ui->spinOffset->setVisible(true); + ui->spinOffset->setEnabled(true); + ui->labelOffset->setVisible(true); + ui->checkBoxMidplane->setEnabled(false); + ui->checkBoxReversed->setEnabled(false); + ui->labelLength2->setVisible(false); + ui->lengthEdit2->setVisible(false); + ui->lengthEdit2->setEnabled(false); + ui->buttonFace->setEnabled(true); + ui->lineFaceName->setEnabled(true); + QMetaObject::invokeMethod(ui->lineFaceName, "setFocus", Qt::QueuedConnection); + // Go into reference selection mode if no face has been selected yet + if (ui->lineFaceName->text().isEmpty() || (ui->lineFaceName->text() == tr("No face selected"))) + onButtonFace(true); + } else { // two dimensions + ui->lengthEdit->setEnabled(true); + ui->lengthEdit->setVisible(true); + ui->lengthEdit->selectNumber(); + QMetaObject::invokeMethod(ui->lengthEdit, "setFocus", Qt::QueuedConnection); + ui->labelLength->setVisible(true); + ui->spinOffset->setVisible(false); + ui->spinOffset->setEnabled(false); + ui->labelOffset->setVisible(false); + ui->checkBoxMidplane->setEnabled(false); + ui->checkBoxReversed->setEnabled(false); + ui->labelLength2->setVisible(true); + ui->lengthEdit2->setVisible(true); + ui->lengthEdit2->setEnabled(true); + ui->buttonFace->setEnabled(false); + ui->lineFaceName->setEnabled(false); + onButtonFace(false); + } +} + +void TaskPadParameters::onSelectionChanged(const Gui::SelectionChanges& msg) +{ + if (msg.Type == Gui::SelectionChanges::AddSelection) { + QString refText = onAddSelection(msg); + if (refText.length() != 0) { + ui->lineFaceName->blockSignals(true); + ui->lineFaceName->setText(refText); + ui->lineFaceName->setProperty("FaceName", QByteArray(msg.pSubName)); + ui->lineFaceName->blockSignals(false); + // Turn off reference selection mode + onButtonFace(false); + } else { + ui->lineFaceName->blockSignals(true); + ui->lineFaceName->setText(tr("No face selected")); + ui->lineFaceName->setProperty("FaceName", QByteArray()); + ui->lineFaceName->blockSignals(false); + } + } + + else if (msg.Type == Gui::SelectionChanges::ClrSelection) { + ui->lineFaceName->blockSignals(true); + ui->lineFaceName->setText(tr("")); + ui->lineFaceName->setProperty("FaceName", QByteArray()); + ui->lineFaceName->blockSignals(false); + } +} + +void TaskPadParameters::onLengthChanged(double len) +{ + PartDesign::Pad* pcPad = static_cast(vp->getObject()); + pcPad->Length.setValue(len); + recomputeFeature(); +} + +void TaskPadParameters::onMidplane(bool on) +{ + PartDesign::Pad* pcPad = static_cast(vp->getObject()); + pcPad->Midplane.setValue(on); + ui->checkBoxReversed->setEnabled(!on); + recomputeFeature(); +} + +void TaskPadParameters::onReversed(bool on) +{ + PartDesign::Pad* pcPad = static_cast(vp->getObject()); + pcPad->Reversed.setValue(on); + recomputeFeature(); +} + +void TaskPadParameters::onLength2Changed(double len) +{ + PartDesign::Pad* pcPad = static_cast(vp->getObject()); + pcPad->Length2.setValue(len); + recomputeFeature(); +} + +void TaskPadParameters::onOffsetChanged(double len) +{ + PartDesign::Pad* pcPad = static_cast(vp->getObject()); + pcPad->Offset.setValue(len); + recomputeFeature(); +} + +void TaskPadParameters::onModeChanged(int index) +{ + PartDesign::Pad* pcPad = static_cast(vp->getObject()); + + switch (index) { + case 0: + pcPad->Type.setValue("Length"); + // Avoid error message + if (ui->lengthEdit->value() < Precision::Confusion()) + ui->lengthEdit->setValue(5.0); + break; + case 1: pcPad->Type.setValue("UpToLast"); break; + case 2: pcPad->Type.setValue("UpToFirst"); break; + case 3: pcPad->Type.setValue("UpToFace"); break; + default: pcPad->Type.setValue("TwoLengths"); + } + + updateUI(index); + recomputeFeature(); +} + +void TaskPadParameters::onButtonFace(const bool pressed) +{ + TaskSketchBasedParameters::onSelectReference(pressed, false, true, false); + + // Update button if onButtonFace() is called explicitly + ui->buttonFace->setChecked(pressed); +} + +void TaskPadParameters::onFaceName(const QString& text) +{ + ui->lineFaceName->setProperty("FaceName", TaskSketchBasedParameters::onFaceName(text)); +} + +double TaskPadParameters::getLength(void) const +{ + return ui->lengthEdit->value().getValue(); +} + +bool TaskPadParameters::getReversed(void) const +{ + return ui->checkBoxReversed->isChecked(); +} + +bool TaskPadParameters::getMidplane(void) const +{ + return ui->checkBoxMidplane->isChecked(); +} + +double TaskPadParameters::getLength2(void) const +{ + return ui->lengthEdit2->value().getValue(); +} + +double TaskPadParameters::getOffset(void) const +{ + return ui->spinOffset->value(); +} + +int TaskPadParameters::getMode(void) const +{ + return ui->changeMode->currentIndex(); +} + +QString TaskPadParameters::getFaceName(void) const +{ + if (getMode() == 3) { + QString faceName = ui->lineFaceName->property("FaceName").toString(); + if (!faceName.isEmpty()) { + return getFaceReference(ui->lineFaceName->text(), faceName); + } + } + return QString(); +} + +TaskPadParameters::~TaskPadParameters() +{ + delete ui; +} + +void TaskPadParameters::changeEvent(QEvent *e) +{ + TaskBox::changeEvent(e); + if (e->type() == QEvent::LanguageChange) { + ui->lengthEdit->blockSignals(true); + ui->lengthEdit2->blockSignals(true); + ui->spinOffset->blockSignals(true); + ui->lineFaceName->blockSignals(true); + ui->changeMode->blockSignals(true); + int index = ui->changeMode->currentIndex(); + ui->retranslateUi(proxy); + ui->changeMode->clear(); + ui->changeMode->addItem(tr("Dimension")); + ui->changeMode->addItem(tr("To last")); + ui->changeMode->addItem(tr("To first")); + ui->changeMode->addItem(tr("Up to face")); + ui->changeMode->addItem(tr("Two dimensions")); + ui->changeMode->setCurrentIndex(index); + + QStringList parts = ui->lineFaceName->text().split(QChar::fromAscii(':')); + QByteArray upToFace = ui->lineFaceName->property("FaceName").toByteArray(); + int faceId = -1; + bool ok = false; + if (upToFace.indexOf("Face") == 0) { + faceId = upToFace.remove(0,4).toInt(&ok); + } +#if QT_VERSION >= 0x040700 + ui->lineFaceName->setPlaceholderText(tr("No face selected")); +#endif + ui->lineFaceName->setText(ok ? + parts[0] + QString::fromAscii(":") + tr("Face") + QString::number(faceId) : + QString()); + ui->lengthEdit->blockSignals(false); + ui->lengthEdit2->blockSignals(false); + ui->spinOffset->blockSignals(false); + ui->lineFaceName->blockSignals(false); + ui->changeMode->blockSignals(false); + } +} + +void TaskPadParameters::saveHistory(void) +{ + // save the user values to history + ui->lengthEdit->pushToHistory(); + ui->lengthEdit2->pushToHistory(); +} + +void TaskPadParameters::apply() +{ + std::string name = vp->getObject()->getNameInDocument(); + const char * cname = name.c_str(); + + ui->lengthEdit->apply(); + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i",cname,getReversed()?1:0); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Midplane = %i",cname,getMidplane()?1:0); + + ui->lengthEdit2->apply(); + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u",cname,getMode()); + QString facename = getFaceName(); + + if (!facename.isEmpty()) { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", + cname, facename.toLatin1().data()); + } else { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", cname); + } + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Offset = %f", name.c_str(), getOffset()); +} + +//************************************************************************** +//************************************************************************** +// TaskDialog +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TaskDlgPadParameters::TaskDlgPadParameters(ViewProviderPad *PadView,bool newObj) + : TaskDlgSketchBasedParameters(PadView) +{ + assert(PadView); + parameter = new TaskPadParameters(static_cast(PadView)); + + Content.push_back(parameter); +} + +TaskDlgPadParameters::~TaskDlgPadParameters() +{ + +} + +//==== calls from the TaskView =============================================================== + +bool TaskDlgPadParameters::accept() +{ + // save the history + parameter->saveHistory(); + parameter->apply(); + +<<<<<<< b551f892abed242e90afa77240bbdd7dcf7fc45c + try { + //Gui::Command::openCommand("Pad changed"); + parameter->apply(); + } + catch (const Base::Exception& e) { + QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); + return false; + } + + return true; +======= + return TaskDlgSketchBasedParameters::accept(); +>>>>>>> PartDesignGui: Make DressUp and SketchSupport propertie dialogs use common accept() structure +} + + +#include "moc_TaskPadParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskPadParameters.h b/src/Mod/PartDesign/Gui/TaskPadParameters.h index 60bfe0136..61cdb9938 100644 --- a/src/Mod/PartDesign/Gui/TaskPadParameters.h +++ b/src/Mod/PartDesign/Gui/TaskPadParameters.h @@ -44,7 +44,6 @@ class ViewProvider; namespace PartDesignGui { - class TaskPadParameters : public TaskSketchBasedParameters { Q_OBJECT @@ -76,7 +75,7 @@ private: double getLength2(void) const; bool getReversed(void) const; bool getMidplane(void) const; - QByteArray getFaceName(void) const; + QString getFaceName(void) const; void onSelectionChanged(const Gui::SelectionChanges& msg); void updateUI(int index); diff --git a/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp index ddf65731d..0976ba8dc 100644 --- a/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp @@ -27,7 +27,6 @@ # include # include # include -# include # include #endif @@ -147,7 +146,7 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge ui->checkBoxReversed->setVisible(true); updateUI(index); - + //// check if the sketch has support //Sketcher::SketchObject *pcSketch; //if (pcPocket->Sketch.getValue()) { @@ -161,7 +160,7 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge } void TaskPocketParameters::updateUI(int index) -{ +{ if (index == 0) { // Only this option requires a numeric value // Dimension ui->pocketLength->setVisible(true); ui->pocketLength->setEnabled(true); @@ -191,7 +190,7 @@ void TaskPocketParameters::updateUI(int index) ui->pocketLength->setEnabled(false); ui->pocketLength->setVisible(false); ui->checkBoxMidplane->setEnabled(false); // Can't have a midplane to a single face - ui->checkBoxReversed->setEnabled(false); // Will change the direction it seeks for its first face? + ui->checkBoxReversed->setEnabled(false); // Will change the direction it seeks for its first face? // Doesnt work so is currently disabled. Fix probably lies // somwhere in IF block on line 125 of FeaturePocket.cpp ui->labelLength->setVisible(false); @@ -343,12 +342,16 @@ int TaskPocketParameters::getMode(void) const return ui->changeMode->currentIndex(); } -QByteArray TaskPocketParameters::getFaceName(void) const +QString TaskPocketParameters::getFaceName(void) const { - if (getMode() == 3) - return getFaceReference(ui->lineFaceName->text(), ui->lineFaceName->property("FaceName").toString()).toLatin1(); - else - return ""; + // TODO Make it return None rather than empty string (2015-11-03, Fat-Zer) + if (getMode() == 3) { + QString faceName = ui->lineFaceName->property("FaceName").toString(); + if (!faceName.isEmpty()) { + return getFaceReference(ui->lineFaceName->text(), faceName); + } + } + return QString (); } TaskPocketParameters::~TaskPocketParameters() @@ -397,19 +400,15 @@ void TaskPocketParameters::apply() //Gui::Command::openCommand("Pocket changed"); ui->pocketLength->apply(); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u",name.c_str(),getMode()); - std::string facename = getFaceName().data(); + QString facename = getFaceName(); - if (!facename.empty()) { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", name.c_str(), facename.c_str()); + if (!facename.isEmpty()) { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", + name.c_str(), facename.toLatin1().data() ); } else Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", name.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i", name.c_str(), getReversed()?1:0); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Offset = %f", name.c_str(), getOffset()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); - if (!vp->getObject()->isValid()) - throw Base::Exception(vp->getObject()->getStatusString()); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); - Gui::Command::commitCommand(); } //************************************************************************** @@ -435,15 +434,9 @@ TaskDlgPocketParameters::~TaskDlgPocketParameters() bool TaskDlgPocketParameters::accept() { - try { - parameter->apply(); - } - catch (const Base::Exception& e) { - QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); - return false; - } + parameter->apply(); - return true; + return TaskDlgSketchBasedParameters::accept(); } diff --git a/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp.orig b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp.orig new file mode 100644 index 000000000..507be8e45 --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp.orig @@ -0,0 +1,453 @@ +/*************************************************************************** + * Copyright (c) 2011 Juergen Riegel * + * * + * 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 +#endif + +#include "ui_TaskPocketParameters.h" +#include "TaskPocketParameters.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "TaskSketchBasedParameters.h" +#include "ReferenceSelection.h" +#include "Workbench.h" + +using namespace PartDesignGui; +using namespace Gui; + +/* TRANSLATOR PartDesignGui::TaskPocketParameters */ + +TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidget *parent) + : TaskSketchBasedParameters(PocketView, parent, "PartDesign_Pocket",tr("Pocket parameters")) +{ + // we need a separate container widget to add all controls to + proxy = new QWidget(this); + ui = new Ui_TaskPocketParameters(); + ui->setupUi(proxy); + QMetaObject::connectSlotsByName(this); + + connect(ui->pocketLength, SIGNAL(valueChanged(double)), + this, SLOT(onLengthChanged(double))); + connect(ui->spinOffset, SIGNAL(valueChanged(double)), + this, SLOT(onOffsetChanged(double))); + connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)), + this, SLOT(onMidplaneChanged(bool))); + connect(ui->checkBoxReversed, SIGNAL(toggled(bool)), + this, SLOT(onReversedChanged(bool))); + connect(ui->changeMode, SIGNAL(currentIndexChanged(int)), + this, SLOT(onModeChanged(int))); + connect(ui->buttonFace, SIGNAL(pressed()), + this, SLOT(onButtonFace())); + connect(ui->lineFaceName, SIGNAL(textEdited(QString)), + this, SLOT(onFaceName(QString))); + connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)), + this, SLOT(onUpdateView(bool))); + + this->groupLayout()->addWidget(proxy); + + // Temporarily prevent unnecessary feature recomputes + ui->pocketLength->blockSignals(true); + ui->spinOffset->blockSignals(true); + ui->checkBoxMidplane->blockSignals(true); + ui->checkBoxReversed->blockSignals(true); + ui->buttonFace->blockSignals(true); + ui->lineFaceName->blockSignals(true); + ui->changeMode->blockSignals(true); + + // Get the feature data + PartDesign::Pocket* pcPocket = static_cast(vp->getObject()); + double l = pcPocket->Length.getValue(); + double off = pcPocket->Offset.getValue(); + bool midplane = pcPocket->Midplane.getValue(); + bool reversed = pcPocket->Reversed.getValue(); + int index = pcPocket->Type.getValue(); // must extract value here, clear() kills it! + App::DocumentObject* obj = pcPocket->UpToFace.getValue(); + std::vector subStrings = pcPocket->UpToFace.getSubValues(); + std::string upToFace; + int faceId = -1; + if ((obj != NULL) && !subStrings.empty()) { + upToFace = subStrings.front(); + if (upToFace.substr(0,4) == "Face") + faceId = std::atoi(&upToFace[4]); + } + + // Fill data into dialog elements + ui->pocketLength->setMinimum(0); + ui->pocketLength->setMaximum(INT_MAX); + ui->pocketLength->setValue(l); + ui->spinOffset->setMinimum(-INT_MAX); + ui->spinOffset->setMaximum(INT_MAX); + ui->spinOffset->setValue(off); + ui->checkBoxMidplane->setChecked(midplane); + ui->checkBoxReversed->setChecked(reversed); + if ((obj != NULL) && PartDesign::Feature::isDatum(obj)) + ui->lineFaceName->setText(QString::fromAscii(obj->getNameInDocument())); + else if (faceId >= 0) + ui->lineFaceName->setText(QString::fromAscii(obj->getNameInDocument()) + QString::fromAscii(":") + tr("Face") + + QString::number(faceId)); + else + ui->lineFaceName->setText(tr("No face selected")); + ui->lineFaceName->setProperty("FaceName", QByteArray(upToFace.c_str())); + ui->changeMode->clear(); + ui->changeMode->insertItem(0, tr("Dimension")); + ui->changeMode->insertItem(1, tr("Through all")); + ui->changeMode->insertItem(2, tr("To first")); + ui->changeMode->insertItem(3, tr("Up to face")); + ui->changeMode->setCurrentIndex(index); + + // Bind input fields to properties + ui->pocketLength->bind(pcPocket->Length); + + ui->pocketLength->blockSignals(false); + ui->spinOffset->blockSignals(false); + ui->checkBoxMidplane->blockSignals(false); + ui->checkBoxReversed->blockSignals(false); + ui->buttonFace->blockSignals(false); + ui->lineFaceName->blockSignals(false); + ui->changeMode->blockSignals(false); + + ui->checkBoxReversed->setVisible(true); + + updateUI(index); + + //// check if the sketch has support + //Sketcher::SketchObject *pcSketch; + //if (pcPocket->Sketch.getValue()) { + // pcSketch = static_cast(pcPocket->Sketch.getValue()); + // if (pcSketch->Support.getValue()) + // // in case of sketch with support, reverse makes no sense (goes into the part) + // ui->checkBoxReversed->setEnabled(0); + // else + // ui->checkBoxReversed->setChecked(reversed); + //} +} + +void TaskPocketParameters::updateUI(int index) +{ + if (index == 0) { // Only this option requires a numeric value // Dimension + ui->pocketLength->setVisible(true); + ui->pocketLength->setEnabled(true); + ui->pocketLength->selectAll(); + QMetaObject::invokeMethod(ui->pocketLength, "setFocus", Qt::QueuedConnection); + ui->spinOffset->setVisible(false); + ui->spinOffset->setEnabled(false); + ui->spinOffset->setEnabled(false); + ui->checkBoxMidplane->setEnabled(true); + // Reverse only makes sense if Midplane is not true + ui->checkBoxReversed->setEnabled(!ui->checkBoxMidplane->isChecked()); // Will flip direction of dimension + ui->buttonFace->setEnabled(false); + ui->lineFaceName->setEnabled(false); + onButtonFace(false); + } else if (index == 1) { // Through all + ui->checkBoxMidplane->setEnabled(true); + ui->checkBoxReversed->setEnabled(!ui->checkBoxMidplane->isChecked()); // Will flip direction of through all + ui->pocketLength->setVisible(false); + ui->pocketLength->setEnabled(false); + ui->spinOffset->setVisible(false); + ui->spinOffset->setVisible(false); + ui->spinOffset->setEnabled(false); + ui->buttonFace->setEnabled(false); + ui->lineFaceName->setEnabled(false); + onButtonFace(false); + } else if (index == 2) { // Neither value nor face required // To First + ui->pocketLength->setEnabled(false); + ui->pocketLength->setVisible(false); + ui->checkBoxMidplane->setEnabled(false); // Can't have a midplane to a single face + ui->checkBoxReversed->setEnabled(false); // Will change the direction it seeks for its first face? + // Doesnt work so is currently disabled. Fix probably lies + // somwhere in IF block on line 125 of FeaturePocket.cpp + ui->labelLength->setVisible(false); + ui->spinOffset->setVisible(true); + ui->spinOffset->setEnabled(true); + ui->labelOffset->setVisible(true); + ui->buttonFace->setEnabled(false); + ui->lineFaceName->setEnabled(false); + onButtonFace(false); + } else if (index == 3) { // Only this option requires to select a face // Up to face + ui->pocketLength->setEnabled(false); + ui->pocketLength->setVisible(false); + ui->labelLength->setVisible(false); + ui->spinOffset->setVisible(true); + ui->spinOffset->setEnabled(true); + ui->labelOffset->setVisible(true); + ui->checkBoxMidplane->setEnabled(false); + ui->checkBoxReversed->setEnabled(false); // No need for reverse since user-chosen face will dtermine direction + ui->buttonFace->setEnabled(true); + ui->lineFaceName->setEnabled(true); + QMetaObject::invokeMethod(ui->lineFaceName, "setFocus", Qt::QueuedConnection); + // Go into reference selection mode if no face has been selected yet + if (ui->lineFaceName->text().isEmpty() || (ui->lineFaceName->text() == tr("No face selected"))) + onButtonFace(true); + } +} + +void TaskPocketParameters::onSelectionChanged(const Gui::SelectionChanges& msg) +{ + if (msg.Type == Gui::SelectionChanges::AddSelection) { + QString refText = onAddSelection(msg); + if (refText.length() > 0) { + ui->lineFaceName->blockSignals(true); + ui->lineFaceName->setText(refText); + ui->lineFaceName->setProperty("FaceName", QByteArray(msg.pSubName)); + ui->lineFaceName->blockSignals(false); + // Turn off reference selection mode + onButtonFace(false); + } else { + ui->lineFaceName->blockSignals(true); + ui->lineFaceName->setText(tr("No face selected")); + ui->lineFaceName->setProperty("FaceName", QByteArray()); + ui->lineFaceName->blockSignals(false); + } + } + else if (msg.Type == Gui::SelectionChanges::ClrSelection) { + ui->lineFaceName->blockSignals(true); + ui->lineFaceName->setText(tr("No face selected")); + ui->lineFaceName->setProperty("FaceName", QByteArray()); + ui->lineFaceName->blockSignals(false); + } +} + +void TaskPocketParameters::onLengthChanged(double len) +{ + PartDesign::Pocket* pcPocket = static_cast(vp->getObject()); + pcPocket->Length.setValue(len); + recomputeFeature(); +} + +void TaskPocketParameters::onOffsetChanged(double len) +{ + PartDesign::Pocket* pcPocket = static_cast(vp->getObject()); + pcPocket->Offset.setValue(len); + recomputeFeature(); +} + +void TaskPocketParameters::onMidplaneChanged(bool on) +{ + PartDesign::Pocket* pcPocket = static_cast(vp->getObject()); + pcPocket->Midplane.setValue(on); + ui->checkBoxReversed->setEnabled(!on); + recomputeFeature(); +} + +void TaskPocketParameters::onReversedChanged(bool on) +{ + PartDesign::Pocket* pcPocket = static_cast(vp->getObject()); + pcPocket->Reversed.setValue(on); + recomputeFeature(); +} + +void TaskPocketParameters::onModeChanged(int index) +{ + PartDesign::Pocket* pcPocket = static_cast(vp->getObject()); + + switch (index) { + case 0: + // Why? See below for "UpToFace" + pcPocket->Type.setValue("Length"); + if (oldLength < Precision::Confusion()) + oldLength = 5.0; + pcPocket->Length.setValue(oldLength); + ui->pocketLength->setValue(oldLength); + break; + case 1: + oldLength = pcPocket->Length.getValue(); + pcPocket->Type.setValue("ThroughAll"); + break; + case 2: + oldLength = pcPocket->Length.getValue(); + pcPocket->Type.setValue("UpToFirst"); + break; + case 3: + // Because of the code at the begining of Pocket::execute() which is used to detect + // broken legacy parts, we must set the length to zero here! + oldLength = pcPocket->Length.getValue(); + pcPocket->Type.setValue("UpToFace"); + pcPocket->Length.setValue(0.0); + ui->pocketLength->setValue(0.0); + break; + default: + pcPocket->Type.setValue("Length"); + } + + updateUI(index); + recomputeFeature(); +} + +void TaskPocketParameters::onButtonFace(const bool pressed) { + TaskSketchBasedParameters::onSelectReference(pressed, false, true, false); + + // Update button if onButtonFace() is called explicitly + ui->buttonFace->setChecked(pressed); +} + +void TaskPocketParameters::onFaceName(const QString& text) +{ + ui->lineFaceName->setProperty("FaceName", TaskSketchBasedParameters::onFaceName(text)); +} + +double TaskPocketParameters::getLength(void) const +{ + return ui->pocketLength->value().getValue(); +} + +double TaskPocketParameters::getOffset(void) const +{ + return ui->spinOffset->value(); +} + +bool TaskPocketParameters::getReversed(void) const +{ + return ui->checkBoxReversed->isChecked(); +} + +int TaskPocketParameters::getMode(void) const +{ + return ui->changeMode->currentIndex(); +} + +QString TaskPocketParameters::getFaceName(void) const +{ + // TODO Make it return None rather than empty string (2015-11-03, Fat-Zer) + if (getMode() == 3) { + QString faceName = ui->lineFaceName->property("FaceName").toString(); + if (!faceName.isEmpty()) { + return getFaceReference(ui->lineFaceName->text(), faceName); + } + } + return QString (); +} + +TaskPocketParameters::~TaskPocketParameters() +{ + delete ui; +} + +void TaskPocketParameters::changeEvent(QEvent *e) +{ + TaskBox::changeEvent(e); + if (e->type() == QEvent::LanguageChange) { + ui->pocketLength->blockSignals(true); + ui->spinOffset->blockSignals(true); + ui->lineFaceName->blockSignals(true); + ui->changeMode->blockSignals(true); + int index = ui->changeMode->currentIndex(); + ui->retranslateUi(proxy); + ui->changeMode->clear(); + ui->changeMode->addItem(tr("Dimension")); + ui->changeMode->addItem(tr("Through all")); + ui->changeMode->addItem(tr("To first")); + ui->changeMode->addItem(tr("Up to face")); + ui->changeMode->setCurrentIndex(index); + + QStringList parts = ui->lineFaceName->text().split(QChar::fromAscii(':')); + QByteArray upToFace = ui->lineFaceName->property("FaceName").toByteArray(); + int faceId = -1; + bool ok = false; + if (upToFace.indexOf("Face") == 0) { + faceId = upToFace.remove(0,4).toInt(&ok); + } + ui->lineFaceName->setText(ok ? + parts[0] + QString::fromAscii(":") + tr("Face") + QString::number(faceId) : + tr("No face selected")); + ui->pocketLength->blockSignals(false); + ui->spinOffset->blockSignals(false); + ui->lineFaceName->blockSignals(false); + ui->changeMode->blockSignals(false); + } +} + +void TaskPocketParameters::apply() +{ + std::string name = vp->getObject()->getNameInDocument(); + + //Gui::Command::openCommand("Pocket changed"); + ui->pocketLength->apply(); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u",name.c_str(),getMode()); + QString facename = getFaceName(); + + if (!facename.isEmpty()) { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", + name.c_str(), facename.toLatin1().data() ); + } else + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", name.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i", name.c_str(), getReversed()?1:0); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Offset = %f", name.c_str(), getOffset()); +} + +//************************************************************************** +//************************************************************************** +// TaskDialog +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TaskDlgPocketParameters::TaskDlgPocketParameters(ViewProviderPocket *PocketView) + : TaskDlgSketchBasedParameters(PocketView) +{ + assert(vp); + parameter = new TaskPocketParameters(static_cast(vp)); + + Content.push_back(parameter); +} + +TaskDlgPocketParameters::~TaskDlgPocketParameters() +{ + +} + +//==== calls from the TaskView =============================================================== + +bool TaskDlgPocketParameters::accept() +{ +<<<<<<< b551f892abed242e90afa77240bbdd7dcf7fc45c + try { + parameter->apply(); + } + catch (const Base::Exception& e) { + QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); + return false; + } +======= + parameter->apply(); +>>>>>>> PartDesignGui: Make DressUp and SketchSupport propertie dialogs use common accept() structure + + return TaskDlgSketchBasedParameters::accept(); +} + + +#include "moc_TaskPocketParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskPocketParameters.h b/src/Mod/PartDesign/Gui/TaskPocketParameters.h index 53359d2ed..343142c0a 100644 --- a/src/Mod/PartDesign/Gui/TaskPocketParameters.h +++ b/src/Mod/PartDesign/Gui/TaskPocketParameters.h @@ -53,9 +53,6 @@ public: TaskPocketParameters(ViewProviderPocket *PocketView,QWidget *parent = 0); ~TaskPocketParameters(); - double getOffset(void) const; - bool getReversed(void) const; - QByteArray getFaceName(void) const; void apply(); private Q_SLOTS: @@ -74,6 +71,10 @@ private: double getLength(void) const; bool getMidplane(void) const; int getMode(void) const; + double getOffset(void) const; + bool getReversed(void) const; + QString getFaceName(void) const; + void onSelectionChanged(const Gui::SelectionChanges& msg); void updateUI(int index); diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index 83d9c0434..2e3b5d57b 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -382,20 +382,7 @@ void TaskRevolutionParameters::changeEvent(QEvent *e) void TaskRevolutionParameters::apply() { - App::DocumentObject* revolve = vp->getObject(); - std::string name = revolve->getNameInDocument(); - - // retrieve sketch and its support object - App::DocumentObject* sketch = 0; - App::DocumentObject* support = 0; - if (revolve->getTypeId().isDerivedFrom(PartDesign::Revolution::getClassTypeId())) { - sketch = static_cast(revolve)->Sketch.getValue(); - try{//throws if no base - support = static_cast(revolve)->getBaseObject(); - } catch (Base::Exception) { - support = NULL; - } - } + std::string name = vp->getObject()->getNameInDocument(); //Gui::Command::openCommand("Revolution changed"); ui->revolveAngle->apply(); @@ -406,15 +393,6 @@ void TaskRevolutionParameters::apply() Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.ReferenceAxis = %s",name.c_str(),axis.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Midplane = %i",name.c_str(), getMidplane() ? 1 : 0); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i",name.c_str(), getReversed() ? 1 : 0); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); - if (revolve->isValid()) { - if (sketch) - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument()); - if (support) - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument()); - } - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); - Gui::Command::commitCommand(); } //************************************************************************** @@ -440,7 +418,7 @@ TaskDlgRevolutionParameters::~TaskDlgRevolutionParameters() bool TaskDlgRevolutionParameters::accept() { parameter->apply(); - return true; + return TaskDlgSketchBasedParameters::accept(); } diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp index cdf1ad32c..1b6a4f3c6 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp @@ -27,7 +27,6 @@ # include # include # include -# include # include #endif @@ -283,13 +282,32 @@ TaskDlgSketchBasedParameters::~TaskDlgSketchBasedParameters() //==== calls from the TaskView =============================================================== + +bool TaskDlgSketchBasedParameters::accept() { + App::DocumentObject* feature = vp->getObject(); + + // Make sure the feature is what we are expecting + // Should be fine but you never know... + if ( !feature->getTypeId().isDerivedFrom(PartDesign::SketchBased::getClassTypeId()) ) { + throw Base::Exception("Bad object processed in the sketch based dialog."); + } + + App::DocumentObject* sketch = static_cast(feature)->Sketch.getValue(); + + if (sketch) { + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().hide(\"%s\")", sketch->getNameInDocument()); + } + + return TaskDlgFeatureParameters::accept(); +} + bool TaskDlgSketchBasedParameters::reject() { PartDesign::SketchBased* pcSketchBased = static_cast(vp->getObject()); // get the Sketch Sketcher::SketchObject *pcSketch = static_cast(pcSketchBased->Sketch.getValue()); bool rv; - + // rv should be true anyway but to be on the safe side dur to thurver changes better respect it. rv = TaskDlgFeatureParameters::reject(); diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h index af3e62507..35b7f6521 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h @@ -34,7 +34,7 @@ namespace App { class Property; } -namespace PartDesignGui { +namespace PartDesignGui { /// Convenience class to collect common methods for all SketchBased features @@ -55,7 +55,7 @@ protected: const QByteArray onFaceName(const QString& text); QString getFaceReference(const QString& obj, const QString& sub) const; void recomputeFeature(); - + App::DocumentObject* getPartPlanes(const char* str) const; App::DocumentObject* getPartLines(const char* str) const; @@ -77,6 +77,8 @@ public: ~TaskDlgSketchBasedParameters(); public: + /// 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(); };