PartDesign: Make groove work via Revolution ui

Purpose: remove duplicate code.
Remaining: wrong title and icon in task dialog.
This commit is contained in:
DeepSOIC 2015-07-21 18:53:19 +03:00 committed by Stefan Tröger
parent 9776d30b87
commit 125dda4d70
7 changed files with 91 additions and 795 deletions

View File

@ -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

View File

@ -1,479 +0,0 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
******************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include "ui_TaskGrooveParameters.h"
#include "TaskGrooveParameters.h"
#include <Base/UnitsApi.h>
#include <App/Application.h>
#include <App/Document.h>
#include <App/Part.h>
#include <App/Origin.h>
#include <App/Line.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Gui/ViewProviderOrigin.h>
#include <Mod/PartDesign/App/DatumLine.h>
#include <Mod/PartDesign/App/FeatureGroove.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include <Mod/PartDesign/App/Body.h>
#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<PartDesign::Groove*>(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<ViewProviderOrigin*>(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<PartDesign::Groove*>(vp->getObject());
App::DocumentObject* pcReferenceAxis = pcGroove->ReferenceAxis.getValue();
std::vector<std::string> sub = pcGroove->ReferenceAxis.getSubValues();
// Add user-defined sketch axes to the reference selection combo box
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(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<App::Line*>(pcReferenceAxis)->LineType.getValue(), App::Part::BaselineTypes[0])==0)
ui->axis->setCurrentIndex(0);
else if(is_base_line && strcmp(static_cast<App::Line*>(pcReferenceAxis)->LineType.getValue(), App::Part::BaselineTypes[1])==0)
ui->axis->setCurrentIndex(1);
else if(is_base_line && strcmp(static_cast<App::Line*>(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<PartDesign::Groove*>(vp->getObject());
exitSelectionMode();
if (!blockUpdate) {
std::vector<std::string> axis;
App::DocumentObject* selObj;
getReferencedSelection(pcGroove, msg, selObj, axis);
pcGroove->ReferenceAxis.setValue(selObj, axis);
recomputeFeature();
updateUI();
}
else {
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(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<std::string> 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<PartDesign::Groove*>(vp->getObject());
pcGroove->Angle.setValue(len);
exitSelectionMode();
recomputeFeature();
}
void TaskGrooveParameters::onAxisChanged(int num)
{
if (blockUpdate)
return;
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(vp->getObject());
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcGroove->Sketch.getValue());
if (pcSketch) {
App::DocumentObject *oldRefAxis = pcGroove->ReferenceAxis.getValue();
std::vector<std::string> oldSubRefAxis = pcGroove->ReferenceAxis.getSubValues();
int maxcount = pcSketch->getAxisCount()+2;
if (num == 0) {
pcGroove->ReferenceAxis.setValue(getPartLines(App::Part::BaselineTypes[0]),
std::vector<std::string>(1,""));
}
else if (num == 1) {
pcGroove->ReferenceAxis.setValue(getPartLines(App::Part::BaselineTypes[1]),
std::vector<std::string>(1,""));
}
else if (num == 2) {
pcGroove->ReferenceAxis.setValue(getPartLines(App::Part::BaselineTypes[2]),
std::vector<std::string>(1,""));
}
else if (num == 3) {
pcGroove->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,"H_Axis"));
exitSelectionMode();
} else if (num == 4) {
pcGroove->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(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<std::string>(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<std::string> &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<PartDesign::Groove*>(vp->getObject());
pcGroove->Midplane.setValue(on);
recomputeFeature();
}
void TaskGrooveParameters::onReversed(bool on)
{
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(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<std::string>& sub) const
{
// get the support and Sketch
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(vp->getObject());
obj = static_cast<Sketcher::SketchObject*>(pcGroove->Sketch.getValue());
sub = std::vector<std::string>(1,"");
int maxcount=5;
if (obj)
maxcount += static_cast<Part::Part2DObject*>(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<ViewProviderOrigin*>(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<PartDesign::Groove*>(groove)->Sketch.getValue<Sketcher::SketchObject*>();
support = static_cast<PartDesign::Groove*>(groove)->getBaseObject();
}
//Gui::Command::openCommand("Groove changed");
ui->grooveAngle->apply();
std::vector<std::string> 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<ViewProviderGroove*>(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<PartDesign::Groove*>(vp->getObject());
Sketcher::SketchObject *pcSketch = 0;
if (pcGroove->Sketch.getValue()) {
pcSketch = static_cast<Sketcher::SketchObject*>(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"

View File

@ -1,109 +0,0 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
******************************************************************************/
#ifndef GUI_TASKVIEW_TaskGrooveParameters_H
#define GUI_TASKVIEW_TaskGrooveParameters_H
#include <Gui/TaskView/TaskView.h>
#include <Gui/Selection.h>
#include <Gui/TaskView/TaskDialog.h>
#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<std::string> &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<ViewProviderGroove*>(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

View File

@ -1,137 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PartDesignGui::TaskGrooveParameters</class>
<widget class="QWidget" name="PartDesignGui::TaskGrooveParameters">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>278</width>
<height>195</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="textLabel1">
<property name="text">
<string>Axis:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="axis">
<item>
<property name="text">
<string>Base X axis</string>
</property>
</item>
<item>
<property name="text">
<string>Base Y axis</string>
</property>
</item>
<item>
<property name="text">
<string>Base Z axis</string>
</property>
</item>
<item>
<property name="text">
<string>Horizontal sketch axis</string>
</property>
</item>
<item>
<property name="text">
<string>Vertical sketch axis</string>
</property>
</item>
<item>
<property name="text">
<string>Select reference...</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Angle:</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::QuantitySpinBox" name="grooveAngle" native="true">
<property name="unit" stdset="0">
<string notr="true">deg</string>
</property>
<property name="minimum" stdset="0">
<double>0.000000000000000</double>
</property>
<property name="maximum" stdset="0">
<double>360.000000000000000</double>
</property>
<property name="singleStep" stdset="0">
<double>10.000000000000000</double>
</property>
<property name="value" stdset="0">
<double>360.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxMidplane">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Symmetric to plane</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxReversed">
<property name="text">
<string>Reversed</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxUpdateView">
<property name="text">
<string>Update view</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -45,6 +45,7 @@
#include <Gui/ViewProviderOrigin.h>
#include <Mod/PartDesign/App/DatumLine.h>
#include <Mod/PartDesign/App/FeatureRevolution.h>
#include <Mod/PartDesign/App/FeatureGroove.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include <Mod/PartDesign/App/Body.h>
#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<PartDesign::Revolution*>(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<PartDesign::SketchBased*>(vp->getObject());
if (pcFeat->isDerivedFrom(PartDesign::Revolution::getClassTypeId())) {
PartDesign::Revolution* rev = static_cast<PartDesign::Revolution*>(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<PartDesign::Groove*>(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<PartDesign::SketchBased*>(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<PartDesign::Revolution *> ( sketchBased )->Angle);
} else if ( sketchBased->isDerivedFrom(PartDesign::Groove::getClassTypeId() ) ) {
ui->revolveAngle->bind(static_cast<PartDesign::Groove *> ( 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<PartDesign::Revolution*>(vp->getObject());
Part::Part2DObject* pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
PartDesign::SketchBased* pcFeat = static_cast<PartDesign::Revolution*>(vp->getObject());
Part::Part2DObject* pcSketch = static_cast<Part::Part2DObject*>(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<PartDesign::Revolution*>(vp->getObject());
//first, figure out the item number for current axis
int indexOfCurrent = -1;
App::DocumentObject* ax = pcRevolution->ReferenceAxis.getValue();
const std::vector<std::string> &subList = pcRevolution->ReferenceAxis.getSubValues();
App::DocumentObject* ax = propReferenceAxis->getValue();
const std::vector<std::string> &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<std::string> &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<PartDesign::Revolution*>(vp->getObject());
exitSelectionMode();
std::vector<std::string> 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<PartDesign::Revolution*>(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<PartDesign::Revolution*>(vp->getObject());
PartDesign::SketchBased* pcRevolution = static_cast<PartDesign::SketchBased*>(vp->getObject());
if(axesInList.size() == 0)
return;
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
if (pcSketch) {
App::DocumentObject *oldRefAxis = pcRevolution->ReferenceAxis.getValue();
std::vector<std::string> oldSubRefAxis = pcRevolution->ReferenceAxis.getSubValues();
App::DocumentObject *oldRefAxis = propReferenceAxis->getValue();
std::vector<std::string> 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<std::string> &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<std::string> &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<PartDesign::Revolution*>(pcRevolution)->suggestReversed();
if(pcRevolution->isDerivedFrom(PartDesign::Groove::getClassTypeId()))
reversed = static_cast<PartDesign::Groove*>(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<PartDesign::Revolution*>(vp->getObject());
pcRevolution->Midplane.setValue(on);
propMidPlane->setValue(on);
recomputeFeature();
}
void TaskRevolutionParameters::onReversed(bool on)
{
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(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<PartDesign::Revolution*>(vp->getObject());
PartDesign::SketchBased* pcRevolution = static_cast<PartDesign::SketchBased*>(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);

View File

@ -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<ViewProviderRevolution*>(vp); }
ViewProvider* getRevolutionView() const
{ return vp; }
public:
/// is called by the framework if the dialog is accepted (Ok)

View File

@ -36,7 +36,7 @@
#include <Gui/Application.h>
#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<TaskDlgGrooveParameters *>(dlg);
if (padDlg && padDlg->getGrooveView() != this)
TaskDlgRevolutionParameters *padDlg = qobject_cast<TaskDlgRevolutionParameters *>(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;
}