diff --git a/src/Mod/PartDesign/Gui/CMakeLists.txt b/src/Mod/PartDesign/Gui/CMakeLists.txt index 0913059bce..84d97295da 100644 --- a/src/Mod/PartDesign/Gui/CMakeLists.txt +++ b/src/Mod/PartDesign/Gui/CMakeLists.txt @@ -39,7 +39,6 @@ set(PartDesignGui_MOC_HDRS TaskDressUpParameters.h #TaskHoleParameters.h TaskRevolutionParameters.h - TaskGrooveParameters.h TaskTransformedMessages.h TaskTransformedParameters.h TaskMirroredParameters.h @@ -69,7 +68,6 @@ set(PartDesignGui_UIC_SRCS TaskBooleanParameters.ui #TaskHoleParameters.ui TaskRevolutionParameters.ui - TaskGrooveParameters.ui TaskTransformedMessages.ui TaskMirroredParameters.ui TaskLinearPatternParameters.ui @@ -176,9 +174,6 @@ SET(PartDesignGuiTaskDlgs_SRCS TaskRevolutionParameters.ui TaskRevolutionParameters.cpp TaskRevolutionParameters.h - TaskGrooveParameters.ui - TaskGrooveParameters.cpp - TaskGrooveParameters.h TaskTransformedMessages.ui TaskTransformedMessages.cpp TaskTransformedMessages.h diff --git a/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp b/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp deleted file mode 100644 index 13c3c76671..0000000000 --- a/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp +++ /dev/null @@ -1,479 +0,0 @@ -/****************************************************************************** - * Copyright (c)2012 Jan Rheinlaender * - * * - * 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_ -#endif - -#include "ui_TaskGrooveParameters.h" -#include "TaskGrooveParameters.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "Workbench.h" -#include "ReferenceSelection.h" -#include "TaskSketchBasedParameters.h" - -using namespace PartDesignGui; -using namespace Gui; - -/* TRANSLATOR PartDesignGui::TaskGrooveParameters */ - -TaskGrooveParameters::TaskGrooveParameters(ViewProviderGroove *GrooveView,QWidget *parent) - : TaskSketchBasedParameters(GrooveView, parent, "PartDesign_Groove",tr("Groove parameters")) -{ - // we need a separate container widget to add all controls to - proxy = new QWidget(this); - ui = new Ui_TaskGrooveParameters(); - ui->setupUi(proxy); - QMetaObject::connectSlotsByName(this); - - connect(ui->grooveAngle, SIGNAL(valueChanged(double)), - this, SLOT(onAngleChanged(double))); - connect(ui->axis, SIGNAL(activated(int)), - this, SLOT(onAxisChanged(int))); - connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)), - this, SLOT(onMidplane(bool))); - connect(ui->checkBoxReversed, SIGNAL(toggled(bool)), - this, SLOT(onReversed(bool))); - connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)), - this, SLOT(onUpdateView(bool))); - - this->groupLayout()->addWidget(proxy); - - // Temporarily prevent unnecessary feature updates - ui->grooveAngle->blockSignals(true); - ui->axis->blockSignals(true); - ui->checkBoxMidplane->blockSignals(true); - ui->checkBoxReversed->blockSignals(true); - - PartDesign::Groove* pcGroove = static_cast(vp->getObject()); - double l = pcGroove->Angle.getValue(); - bool mirrored = pcGroove->Midplane.getValue(); - bool reversed = pcGroove->Reversed.getValue(); - - ui->grooveAngle->setValue(l); - ui->grooveAngle->bind(pcGroove->Angle); - - blockUpdate = false; - updateUI(); - - ui->checkBoxMidplane->setChecked(mirrored); - ui->checkBoxReversed->setChecked(reversed); - - ui->grooveAngle->blockSignals(false); - ui->axis->blockSignals(false); - ui->checkBoxMidplane->blockSignals(false); - ui->checkBoxReversed->blockSignals(false); - - setFocus (); - - //show the parts coordinate system axis for selection - App::Part* part = getPartFor(vp->getObject(), false); - if(part) { - auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(!app_origin.empty()) { - ViewProviderOrigin* origin; - origin = static_cast(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0])); - origin->setTemporaryVisibilityMode(true, Gui::Application::Instance->activeDocument()); - origin->setTemporaryVisibilityAxis(true); - } - } -} - -void TaskGrooveParameters::updateUI() -{ - if (blockUpdate) - return; - blockUpdate = true; - - PartDesign::Groove* pcGroove = static_cast(vp->getObject()); - - App::DocumentObject* pcReferenceAxis = pcGroove->ReferenceAxis.getValue(); - std::vector sub = pcGroove->ReferenceAxis.getSubValues(); - - // Add user-defined sketch axes to the reference selection combo box - Sketcher::SketchObject *pcSketch = static_cast(pcGroove->Sketch.getValue()); - int maxcount=5; - if (pcSketch) - maxcount += pcSketch->getAxisCount(); - - for (int i=ui->axis->count()-1; i >= 5; i--) - ui->axis->removeItem(i); - for (int i=ui->axis->count(); i < maxcount; i++) - ui->axis->addItem(QString::fromAscii("Sketch axis %1").arg(i-5)); - - bool undefined = false; - if (pcReferenceAxis != NULL) { - - bool is_base_line = pcReferenceAxis->isDerivedFrom(App::Line::getClassTypeId()); - - if(is_base_line && strcmp(static_cast(pcReferenceAxis)->LineType.getValue(), App::Part::BaselineTypes[0])==0) - ui->axis->setCurrentIndex(0); - else if(is_base_line && strcmp(static_cast(pcReferenceAxis)->LineType.getValue(), App::Part::BaselineTypes[1])==0) - ui->axis->setCurrentIndex(1); - else if(is_base_line && strcmp(static_cast(pcReferenceAxis)->LineType.getValue(), App::Part::BaselineTypes[2])==0) - ui->axis->setCurrentIndex(2); - else if (!sub.empty() && sub.front() == "H_Axis") - ui->axis->setCurrentIndex(3); - else if (!sub.empty() && sub.front() == "V_Axis") - ui->axis->setCurrentIndex(4); - else if (!sub.empty() && sub.front().size() > 4 && sub.front().substr(0,4) == "Axis") { - int pos = 5 + std::atoi(sub.front().substr(4,4000).c_str()); - if (pos <= maxcount) - ui->axis->setCurrentIndex(pos); - else - undefined = true; - } else { - ui->axis->addItem(getRefStr(pcReferenceAxis, sub)); - ui->axis->setCurrentIndex(maxcount); - } - } else { - undefined = true; - } - - ui->axis->addItem(tr("Select reference...")); - - blockUpdate = false; -} - -void TaskGrooveParameters::onSelectionChanged(const Gui::SelectionChanges& msg) -{ - if (msg.Type == Gui::SelectionChanges::AddSelection) { - PartDesign::Groove* pcGroove = static_cast(vp->getObject()); - - exitSelectionMode(); - if (!blockUpdate) { - std::vector axis; - App::DocumentObject* selObj; - getReferencedSelection(pcGroove, msg, selObj, axis); - pcGroove->ReferenceAxis.setValue(selObj, axis); - - - recomputeFeature(); - updateUI(); - } - else { - Sketcher::SketchObject *pcSketch = static_cast(pcGroove->Sketch.getValue()); - int maxcount=2; - if (pcSketch) - maxcount += pcSketch->getAxisCount(); - for (int i=ui->axis->count()-1; i >= maxcount; i--) - ui->axis->removeItem(i); - - std::vector sub; - App::DocumentObject* selObj; - getReferencedSelection(pcGroove, msg, selObj, sub); - ui->axis->addItem(getRefStr(selObj, sub)); - ui->axis->setCurrentIndex(maxcount); - ui->axis->addItem(tr("Select reference...")); - } - } -} - -void TaskGrooveParameters::onAngleChanged(double len) -{ - PartDesign::Groove* pcGroove = static_cast(vp->getObject()); - pcGroove->Angle.setValue(len); - exitSelectionMode(); - recomputeFeature(); -} - -void TaskGrooveParameters::onAxisChanged(int num) -{ - if (blockUpdate) - return; - PartDesign::Groove* pcGroove = static_cast(vp->getObject()); - Sketcher::SketchObject *pcSketch = static_cast(pcGroove->Sketch.getValue()); - if (pcSketch) { - App::DocumentObject *oldRefAxis = pcGroove->ReferenceAxis.getValue(); - std::vector oldSubRefAxis = pcGroove->ReferenceAxis.getSubValues(); - - int maxcount = pcSketch->getAxisCount()+2; - if (num == 0) { - pcGroove->ReferenceAxis.setValue(getPartLines(App::Part::BaselineTypes[0]), - std::vector(1,"")); - } - else if (num == 1) { - pcGroove->ReferenceAxis.setValue(getPartLines(App::Part::BaselineTypes[1]), - std::vector(1,"")); - } - else if (num == 2) { - pcGroove->ReferenceAxis.setValue(getPartLines(App::Part::BaselineTypes[2]), - std::vector(1,"")); - } - else if (num == 3) { - pcGroove->ReferenceAxis.setValue(pcSketch, std::vector(1,"H_Axis")); - exitSelectionMode(); - } else if (num == 4) { - pcGroove->ReferenceAxis.setValue(pcSketch, std::vector(1,"V_Axis")); - exitSelectionMode(); - } else if (num >= 5 && num < maxcount) { - QString buf = QString::fromUtf8("Axis%1").arg(num-2); - std::string str = buf.toStdString(); - pcGroove->ReferenceAxis.setValue(pcSketch, std::vector(1,str)); - exitSelectionMode(); - } else if (num == ui->axis->count() - 1) { - // enter reference selection mode - TaskSketchBasedParameters::onSelectReference(true, true, false, true); - } else if (num == maxcount) - exitSelectionMode(); - - App::DocumentObject *newRefAxis = pcGroove->ReferenceAxis.getValue(); - const std::vector &newSubRefAxis = pcGroove->ReferenceAxis.getSubValues(); - if (oldRefAxis != newRefAxis || - oldSubRefAxis.size() != newSubRefAxis.size() || - oldSubRefAxis[0] != newSubRefAxis[0]) { - bool reversed = pcGroove->suggestReversed(); - if (reversed != pcGroove->Reversed.getValue()) { - pcGroove->Reversed.setValue(reversed); - ui->checkBoxReversed->blockSignals(true); - ui->checkBoxReversed->setChecked(reversed); - ui->checkBoxReversed->blockSignals(false); - } - } - } - - updateUI(); - recomputeFeature(); -} - -void TaskGrooveParameters::onMidplane(bool on) -{ - PartDesign::Groove* pcGroove = static_cast(vp->getObject()); - pcGroove->Midplane.setValue(on); - recomputeFeature(); -} - -void TaskGrooveParameters::onReversed(bool on) -{ - PartDesign::Groove* pcGroove = static_cast(vp->getObject()); - pcGroove->Reversed.setValue(on); - recomputeFeature(); -} - -double TaskGrooveParameters::getAngle(void) const -{ - return ui->grooveAngle->value().getValue(); -} - -void TaskGrooveParameters::getReferenceAxis(App::DocumentObject*& obj, std::vector& sub) const -{ - // get the support and Sketch - PartDesign::Groove* pcGroove = static_cast(vp->getObject()); - obj = static_cast(pcGroove->Sketch.getValue()); - sub = std::vector(1,""); - int maxcount=5; - if (obj) - maxcount += static_cast(obj)->getAxisCount(); - - if (obj) { - int num = ui->axis->currentIndex(); - if(num == 0) - obj = getPartLines(App::Part::BaselineTypes[0]); - else if(num == 1) - obj = getPartLines(App::Part::BaselineTypes[1]); - else if(num == 2) - obj = getPartLines(App::Part::BaselineTypes[2]); - else if (num == 3) - sub[0] = "H_Axis"; - else if (num == 4) - sub[0] = "V_Axis"; - else if (num >= 5 && num < maxcount) { - QString buf = QString::fromUtf8("Axis%1").arg(num-2); - sub[0] = buf.toStdString(); - } else if (num == maxcount && ui->axis->count() == maxcount + 2) { - QStringList parts = ui->axis->currentText().split(QChar::fromAscii(':')); - obj = vp->getObject()->getDocument()->getObject(parts[0].toStdString().c_str()); - if (parts.size() > 1) - sub[0] = parts[1].toStdString(); - } else { - obj = NULL; - } - } - else - obj = NULL; -} - -bool TaskGrooveParameters::getMidplane(void) const -{ - return ui->checkBoxMidplane->isChecked(); -} - -bool TaskGrooveParameters::getReversed(void) const -{ - return ui->checkBoxReversed->isChecked(); -} - -TaskGrooveParameters::~TaskGrooveParameters() -{ - //hide the parts coordinate system axis for selection - App::Part* part = getPartFor(vp->getObject(), false); - if(part) { - auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(!app_origin.empty()) { - ViewProviderOrigin* origin; - origin = static_cast(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0])); - origin->setTemporaryVisibilityMode(false); - } - } - - delete ui; -} - -void TaskGrooveParameters::changeEvent(QEvent *e) -{ - TaskBox::changeEvent(e); - if (e->type() == QEvent::LanguageChange) { - ui->retranslateUi(proxy); - } -} - -void TaskGrooveParameters::apply() -{ - App::DocumentObject* groove = vp->getObject(); - std::string name = groove->getNameInDocument(); - - // retrieve sketch and its support object - App::DocumentObject* sketch = 0; - App::DocumentObject* support = 0; - if (groove->getTypeId().isDerivedFrom(PartDesign::Groove::getClassTypeId())) { - sketch = static_cast(groove)->Sketch.getValue(); - support = static_cast(groove)->getBaseObject(); - } - - //Gui::Command::openCommand("Groove changed"); - ui->grooveAngle->apply(); - std::vector sub; - App::DocumentObject* obj; - getReferenceAxis(obj, sub); - std::string axis = getPythonStr(obj, sub); - 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 (groove->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(); - } - -//************************************************************************** -//************************************************************************** -// TaskDialog -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -TaskDlgGrooveParameters::TaskDlgGrooveParameters(ViewProviderGroove *GrooveView) - : TaskDlgSketchBasedParameters(GrooveView) -{ - assert(vp); - parameter = new TaskGrooveParameters(static_cast(vp)); - - Content.push_back(parameter); -} - -TaskDlgGrooveParameters::~TaskDlgGrooveParameters() -{ - -} - -//==== calls from the TaskView =============================================================== - - -void TaskDlgGrooveParameters::open() -{ - // a transaction is already open at creation time of the groove - if (!Gui::Command::hasPendingCommand()) { - QString msg = QObject::tr("Edit groove"); - Gui::Command::openCommand((const char*)msg.toUtf8()); - } -} - -void TaskDlgGrooveParameters::clicked(int) -{ - -} - -bool TaskDlgGrooveParameters::accept() -{ - parameter->apply(); - return true; -} - -bool TaskDlgGrooveParameters::reject() -{ - // get the support and Sketch - PartDesign::Groove* pcGroove = static_cast(vp->getObject()); - Sketcher::SketchObject *pcSketch = 0; - if (pcGroove->Sketch.getValue()) { - pcSketch = static_cast(pcGroove->Sketch.getValue()); - } - - // role back the done things - Gui::Command::abortCommand(); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); - - // if abort command deleted the object the support is visible again - if (!Gui::Application::Instance->getViewProvider(pcGroove)) { - if (pcSketch && Gui::Application::Instance->getViewProvider(pcSketch)) - Gui::Application::Instance->getViewProvider(pcSketch)->show(); - } - -// // 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_TaskGrooveParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskGrooveParameters.h b/src/Mod/PartDesign/Gui/TaskGrooveParameters.h deleted file mode 100644 index e4511475c6..0000000000 --- a/src/Mod/PartDesign/Gui/TaskGrooveParameters.h +++ /dev/null @@ -1,109 +0,0 @@ -/****************************************************************************** - * Copyright (c)2012 Jan Rheinlaender * - * * - * 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_TaskGrooveParameters_H -#define GUI_TASKVIEW_TaskGrooveParameters_H - -#include -#include -#include - -#include "ViewProviderGroove.h" -#include "TaskSketchBasedParameters.h" - -class Ui_TaskGrooveParameters; - -namespace App { -class Property; -} - -namespace Gui { -class ViewProvider; -} - -namespace PartDesignGui { - - - -class TaskGrooveParameters : public TaskSketchBasedParameters -{ - Q_OBJECT - -public: - TaskGrooveParameters(ViewProviderGroove *GrooveView,QWidget *parent = 0); - ~TaskGrooveParameters(); - - void apply(); - -private Q_SLOTS: - void onAngleChanged(double); - void onAxisChanged(int); - void onMidplane(bool); - void onReversed(bool); - -protected: - void onSelectionChanged(const Gui::SelectionChanges& msg); - void changeEvent(QEvent *e); - void getReferenceAxis(App::DocumentObject *&obj, std::vector &sub) const; - double getAngle(void) const; - bool getMidplane(void) const; - bool getReversed(void) const; - const bool updateView() const; - -private: - void updateUI(); - -private: - QWidget* proxy; - Ui_TaskGrooveParameters* ui; -}; - -/// simulation dialog for the TaskView -class TaskDlgGrooveParameters : public TaskDlgSketchBasedParameters -{ - Q_OBJECT - -public: - TaskDlgGrooveParameters(ViewProviderGroove *GrooveView); - ~TaskDlgGrooveParameters(); - - ViewProviderGroove* getGrooveView() const - { return static_cast(vp); } - -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^M - 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(); - -protected: - TaskGrooveParameters *parameter; -}; - -} //namespace PartDesignGui - -#endif // GUI_TASKVIEW_TASKAPPERANCE_H diff --git a/src/Mod/PartDesign/Gui/TaskGrooveParameters.ui b/src/Mod/PartDesign/Gui/TaskGrooveParameters.ui deleted file mode 100644 index 9dec961ff3..0000000000 --- a/src/Mod/PartDesign/Gui/TaskGrooveParameters.ui +++ /dev/null @@ -1,137 +0,0 @@ - - - PartDesignGui::TaskGrooveParameters - - - - 0 - 0 - 278 - 195 - - - - Form - - - - - - - - Axis: - - - - - - - - Base X axis - - - - - Base Y axis - - - - - Base Z axis - - - - - Horizontal sketch axis - - - - - Vertical sketch axis - - - - - Select reference... - - - - - - - - - - - - Angle: - - - - - - - deg - - - 0.000000000000000 - - - 360.000000000000000 - - - 10.000000000000000 - - - 360.000000000000000 - - - - - - - - - true - - - Symmetric to plane - - - - - - - Reversed - - - - - - - Qt::Horizontal - - - - - - - Update view - - - true - - - - - - - - Gui::QuantitySpinBox - QWidget -
Gui/QuantitySpinBox.h
-
-
- - -
diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index 3e6cda3786..83d9c04343 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include "ReferenceSelection.h" @@ -57,7 +58,7 @@ using namespace Gui; /* TRANSLATOR PartDesignGui::TaskRevolutionParameters */ -TaskRevolutionParameters::TaskRevolutionParameters(ViewProviderRevolution *RevolutionView,QWidget *parent) +TaskRevolutionParameters::TaskRevolutionParameters(PartDesignGui::ViewProvider* RevolutionView, QWidget *parent) : TaskSketchBasedParameters(RevolutionView, parent, "PartDesign_Revolution",tr("Revolution parameters")) { // we need a separate container widget to add all controls to @@ -85,18 +86,42 @@ TaskRevolutionParameters::TaskRevolutionParameters(ViewProviderRevolution *Revol ui->checkBoxMidplane->blockSignals(true); ui->checkBoxReversed->blockSignals(true); - PartDesign::Revolution* pcRevolution = static_cast(vp->getObject()); - double l = pcRevolution->Angle.getValue(); - bool mirrored = pcRevolution->Midplane.getValue(); - bool reversed = pcRevolution->Reversed.getValue(); + //bind property mirrors + PartDesign::SketchBased* pcFeat = static_cast(vp->getObject()); + if (pcFeat->isDerivedFrom(PartDesign::Revolution::getClassTypeId())) { + PartDesign::Revolution* rev = static_cast(vp->getObject()); + this->propAngle = &(rev->Angle); + this->propMidPlane = &(rev->Midplane); + this->propReferenceAxis = &(rev->ReferenceAxis); + this->propReversed = &(rev->Reversed); + } else { + assert(pcFeat->isDerivedFrom(PartDesign::Groove::getClassTypeId())); + PartDesign::Groove* rev = static_cast(vp->getObject()); + this->propAngle = &(rev->Angle); + this->propMidPlane = &(rev->Midplane); + this->propReferenceAxis = &(rev->ReferenceAxis); + this->propReversed = &(rev->Reversed); + } + + double l = propAngle->getValue(); + bool mirrored = propMidPlane->getValue(); + bool reversed = propReversed->getValue(); ui->revolveAngle->setValue(l); blockUpdate = false; updateUI(); + ui->checkBoxMidplane->setChecked(mirrored); ui->checkBoxReversed->setChecked(reversed); - ui->revolveAngle->bind(pcRevolution->Angle); + + PartDesign::SketchBased* sketchBased = static_cast(vp->getObject()); + // TODO This is quite ugly better redo it (2015-11-02, Fat-Zer) + if ( sketchBased->isDerivedFrom(PartDesign::Revolution::getClassTypeId() ) ) { + ui->revolveAngle->bind(static_cast ( sketchBased )->Angle); + } else if ( sketchBased->isDerivedFrom(PartDesign::Groove::getClassTypeId() ) ) { + ui->revolveAngle->bind(static_cast ( sketchBased )->Angle); + } ui->revolveAngle->blockSignals(false); ui->axis->blockSignals(false); @@ -135,8 +160,8 @@ void TaskRevolutionParameters::fillAxisCombo(bool forceRefill) this->axesInList.clear(); //add sketch axes - PartDesign::Revolution* pcRevolution = static_cast(vp->getObject()); - Part::Part2DObject* pcSketch = static_cast(pcRevolution->Sketch.getValue()); + PartDesign::SketchBased* pcFeat = static_cast(vp->getObject()); + Part::Part2DObject* pcSketch = static_cast(pcFeat->Sketch.getValue()); if (pcSketch){ addAxisToCombo(pcSketch,"V_Axis",QObject::tr("Vertical sketch axis")); addAxisToCombo(pcSketch,"H_Axis",QObject::tr("Horizontal sketch axis")); @@ -165,22 +190,20 @@ void TaskRevolutionParameters::fillAxisCombo(bool forceRefill) }//endif forceRefill //add current link, if not in list - PartDesign::Revolution* pcRevolution = static_cast(vp->getObject()); //first, figure out the item number for current axis int indexOfCurrent = -1; - App::DocumentObject* ax = pcRevolution->ReferenceAxis.getValue(); - const std::vector &subList = pcRevolution->ReferenceAxis.getSubValues(); + App::DocumentObject* ax = propReferenceAxis->getValue(); + const std::vector &subList = propReferenceAxis->getSubValues(); for(int i = 0 ; i < axesInList.size() ; i++) { if(ax == axesInList[i]->getValue() && subList == axesInList[i]->getSubValues()) indexOfCurrent = i; } if ( indexOfCurrent == -1 && ax ){ - const std::vector &sublist = pcRevolution->ReferenceAxis.getSubValues(); - assert(sublist.size() <= 1); + assert(subList.size() <= 1); std::string sub; - if (sublist.size()>0) - sub = sublist[0]; - addAxisToCombo(ax, sub, getRefStr(ax, sublist)); + if (subList.size()>0) + sub = subList[0]; + addAxisToCombo(ax, sub, getRefStr(ax, subList)); indexOfCurrent = axesInList.size()-1; } @@ -215,13 +238,12 @@ void TaskRevolutionParameters::updateUI() void TaskRevolutionParameters::onSelectionChanged(const Gui::SelectionChanges& msg) { if (msg.Type == Gui::SelectionChanges::AddSelection) { - PartDesign::Revolution* pcRevolution = static_cast(vp->getObject()); exitSelectionMode(); std::vector axis; App::DocumentObject* selObj; - getReferencedSelection(pcRevolution, msg, selObj, axis); - pcRevolution->ReferenceAxis.setValue(selObj, axis); + getReferencedSelection(vp->getObject(), msg, selObj, axis); + propReferenceAxis->setValue(selObj, axis); recomputeFeature(); updateUI(); @@ -231,8 +253,7 @@ void TaskRevolutionParameters::onSelectionChanged(const Gui::SelectionChanges& m void TaskRevolutionParameters::onAngleChanged(double len) { - PartDesign::Revolution* pcRevolution = static_cast(vp->getObject()); - pcRevolution->Angle.setValue(len); + propAngle->setValue(len); exitSelectionMode(); recomputeFeature(); } @@ -241,59 +262,58 @@ void TaskRevolutionParameters::onAxisChanged(int num) { if (blockUpdate) return; - PartDesign::Revolution* pcRevolution = static_cast(vp->getObject()); + PartDesign::SketchBased* pcRevolution = static_cast(vp->getObject()); if(axesInList.size() == 0) return; - Sketcher::SketchObject *pcSketch = static_cast(pcRevolution->Sketch.getValue()); - if (pcSketch) { - App::DocumentObject *oldRefAxis = pcRevolution->ReferenceAxis.getValue(); - std::vector oldSubRefAxis = pcRevolution->ReferenceAxis.getSubValues(); + App::DocumentObject *oldRefAxis = propReferenceAxis->getValue(); + std::vector oldSubRefAxis = propReferenceAxis->getSubValues(); - App::PropertyLinkSub &lnk = *(axesInList[num]); - if(lnk.getValue() == 0){ - // enter reference selection mode - TaskSketchBasedParameters::onSelectReference(true, true, false, true); - } else { - if (! pcRevolution->getDocument()->isIn(lnk.getValue())){ - Base::Console().Error("Object was deleted\n"); - return; - } - pcRevolution->ReferenceAxis.Paste(lnk); - exitSelectionMode(); + App::PropertyLinkSub &lnk = *(axesInList[num]); + if(lnk.getValue() == 0){ + // enter reference selection mode + TaskSketchBasedParameters::onSelectReference(true, true, false, true); + } else { + if (! pcRevolution->getDocument()->isIn(lnk.getValue())){ + Base::Console().Error("Object was deleted\n"); + return; } + propReferenceAxis->Paste(lnk); + exitSelectionMode(); + } - App::DocumentObject *newRefAxis = pcRevolution->ReferenceAxis.getValue(); - const std::vector &newSubRefAxis = pcRevolution->ReferenceAxis.getSubValues(); - if (oldRefAxis != newRefAxis || - oldSubRefAxis.size() != newSubRefAxis.size() || - oldSubRefAxis[0] != newSubRefAxis[0]) { - bool reversed = pcRevolution->suggestReversed(); - if (reversed != pcRevolution->Reversed.getValue()) { - pcRevolution->Reversed.setValue(reversed); - ui->checkBoxReversed->blockSignals(true); - ui->checkBoxReversed->setChecked(reversed); - ui->checkBoxReversed->blockSignals(false); - } + App::DocumentObject *newRefAxis = propReferenceAxis->getValue(); + const std::vector &newSubRefAxis = propReferenceAxis->getSubValues(); + if (oldRefAxis != newRefAxis || + oldSubRefAxis.size() != newSubRefAxis.size() || + oldSubRefAxis[0] != newSubRefAxis[0]) { + bool reversed = propReversed->getValue(); + if(pcRevolution->isDerivedFrom(PartDesign::Revolution::getClassTypeId())) + reversed = static_cast(pcRevolution)->suggestReversed(); + if(pcRevolution->isDerivedFrom(PartDesign::Groove::getClassTypeId())) + reversed = static_cast(pcRevolution)->suggestReversed(); + + if (reversed != propReversed->getValue()) { + propReversed->setValue(reversed); + ui->checkBoxReversed->blockSignals(true); + ui->checkBoxReversed->setChecked(reversed); + ui->checkBoxReversed->blockSignals(false); } } - updateUI(); recomputeFeature(); } void TaskRevolutionParameters::onMidplane(bool on) { - PartDesign::Revolution* pcRevolution = static_cast(vp->getObject()); - pcRevolution->Midplane.setValue(on); + propMidPlane->setValue(on); recomputeFeature(); } void TaskRevolutionParameters::onReversed(bool on) { - PartDesign::Revolution* pcRevolution = static_cast(vp->getObject()); - pcRevolution->Reversed.setValue(on); + propReversed->setValue(on); recomputeFeature(); } @@ -312,7 +332,7 @@ void TaskRevolutionParameters::getReferenceAxis(App::DocumentObject*& obj, std:: if(lnk.getValue() == 0){ throw Base::Exception("Still in reference selection mode; reference wasn't selected yet"); } else { - PartDesign::Revolution* pcRevolution = static_cast(vp->getObject()); + PartDesign::SketchBased* pcRevolution = static_cast(vp->getObject()); if (! pcRevolution->getDocument()->isIn(lnk.getValue())){ throw Base::Exception("Object was deleted"); return; @@ -401,8 +421,7 @@ void TaskRevolutionParameters::apply() //************************************************************************** // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -TaskDlgRevolutionParameters::TaskDlgRevolutionParameters(ViewProviderRevolution *RevolutionView) +TaskDlgRevolutionParameters::TaskDlgRevolutionParameters(PartDesignGui::ViewProvider *RevolutionView) : TaskDlgSketchBasedParameters(RevolutionView) { assert(RevolutionView); diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h index 0a18b0cacf..4839a521d4 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h @@ -50,7 +50,7 @@ class TaskRevolutionParameters : public TaskSketchBasedParameters Q_OBJECT public: - TaskRevolutionParameters(ViewProviderRevolution *RevolutionView,QWidget *parent = 0); + TaskRevolutionParameters(ViewProvider* RevolutionView,QWidget *parent = 0); ~TaskRevolutionParameters(); void apply(); @@ -79,6 +79,13 @@ protected: bool getMidplane(void) const; bool getReversed(void) const; + //mirrors of revolution's or groove's properties + //should have been done by inheriting revolution and groove from common class... + App::PropertyAngle* propAngle; + App::PropertyBool* propReversed; + App::PropertyBool* propMidPlane; + App::PropertyLinkSub* propReferenceAxis; + private: void updateUI(); @@ -103,11 +110,11 @@ class TaskDlgRevolutionParameters : public TaskDlgSketchBasedParameters Q_OBJECT public: - TaskDlgRevolutionParameters(ViewProviderRevolution *RevolutionView); + TaskDlgRevolutionParameters(PartDesignGui::ViewProvider *RevolutionView); ~TaskDlgRevolutionParameters(); - ViewProviderRevolution* getRevolutionView() const - { return static_cast(vp); } + ViewProvider* getRevolutionView() const + { return vp; } public: /// is called by the framework if the dialog is accepted (Ok) diff --git a/src/Mod/PartDesign/Gui/ViewProviderGroove.cpp b/src/Mod/PartDesign/Gui/ViewProviderGroove.cpp index e87c6db1ff..bb443fb88a 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderGroove.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderGroove.cpp @@ -36,7 +36,7 @@ #include #include "ViewProviderGroove.h" -#include "TaskGrooveParameters.h" +#include "TaskRevolutionParameters.h" using namespace PartDesignGui; @@ -86,8 +86,8 @@ bool ViewProviderGroove::setEdit(int ModNum) // object unsets and sets its edit mode without closing // the task panel Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); - TaskDlgGrooveParameters *padDlg = qobject_cast(dlg); - if (padDlg && padDlg->getGrooveView() != this) + TaskDlgRevolutionParameters *padDlg = qobject_cast(dlg); + if (padDlg && padDlg->getRevolutionView() != this) padDlg = 0; // another pad left open its task panel if (dlg && !padDlg) { QMessageBox msgBox; @@ -112,7 +112,7 @@ bool ViewProviderGroove::setEdit(int ModNum) if (padDlg) Gui::Control().showDialog(padDlg); else - Gui::Control().showDialog(new TaskDlgGrooveParameters(this)); + Gui::Control().showDialog(new TaskDlgRevolutionParameters(this)); return true; }