PartDesign: Added support for expressions.

This commit is contained in:
Eivind Kvedalen 2015-06-23 00:47:09 +02:00 committed by wmayer
parent 897f8b78b8
commit ddfbe349cf
28 changed files with 346 additions and 284 deletions

View File

@ -25,9 +25,9 @@
#define PARTDESIGN_FeatureLinearPattern_H
#include <App/PropertyStandard.h>
#include <App/PropertyUnits.h>
#include "FeatureTransformed.h"
namespace PartDesign
{
@ -40,7 +40,7 @@ public:
App::PropertyLinkSub Direction;
App::PropertyBool Reversed;
App::PropertyFloat Length;
App::PropertyLength Length;
App::PropertyInteger Occurrences;
/** @name methods override feature */

View File

@ -25,6 +25,7 @@
#define PARTDESIGN_FeaturePolarPattern_H
#include <App/PropertyStandard.h>
#include <App/PropertyUnits.h>
#include "FeatureTransformed.h"
@ -40,7 +41,7 @@ public:
App::PropertyLinkSub Axis;
App::PropertyBool Reversed;
App::PropertyFloat Angle;
App::PropertyAngle Angle;
App::PropertyInteger Occurrences;
/** @name methods override feature */

View File

@ -69,6 +69,7 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderChamfer *ChamferView,QW
ui->chamferDistance->setValue(r);
ui->chamferDistance->setMinimum(0);
ui->chamferDistance->selectNumber();
ui->chamferDistance->bind(pcChamfer->Size);
QMetaObject::invokeMethod(ui->chamferDistance, "setFocus", Qt::QueuedConnection);
}
@ -97,6 +98,17 @@ void TaskChamferParameters::changeEvent(QEvent *e)
}
}
void TaskChamferParameters::apply()
{
std::string name = ChamferView->getObject()->getNameInDocument();
//Gui::Command::openCommand("Chamfer changed");
ui->chamferDistance->apply();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
@ -135,13 +147,7 @@ void TaskDlgChamferParameters::clicked(int)
bool TaskDlgChamferParameters::accept()
{
std::string name = ChamferView->getObject()->getNameInDocument();
//Gui::Command::openCommand("Chamfer changed");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Size = %f",name.c_str(),parameter->getLength());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
parameter->apply();
return true;
}

View File

@ -51,13 +51,14 @@ public:
TaskChamferParameters(ViewProviderChamfer *ChamferView, QWidget *parent=0);
~TaskChamferParameters();
double getLength(void) const;
void apply();
private Q_SLOTS:
void onLengthChanged(double);
protected:
void changeEvent(QEvent *e);
double getLength(void) const;
private:

View File

@ -69,6 +69,7 @@ TaskFilletParameters::TaskFilletParameters(ViewProviderFillet *FilletView,QWidge
ui->filletRadius->setValue(r);
ui->filletRadius->setMinimum(0);
ui->filletRadius->selectNumber();
ui->filletRadius->bind(pcFillet->Radius);
QMetaObject::invokeMethod(ui->filletRadius, "setFocus", Qt::QueuedConnection);
}
@ -97,6 +98,17 @@ void TaskFilletParameters::changeEvent(QEvent *e)
}
}
void TaskFilletParameters::apply()
{
std::string name = FilletView->getObject()->getNameInDocument();
//Gui::Command::openCommand("Fillet changed");
ui->filletRadius->apply();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
@ -135,13 +147,7 @@ void TaskDlgFilletParameters::clicked(int)
bool TaskDlgFilletParameters::accept()
{
std::string name = FilletView->getObject()->getNameInDocument();
//Gui::Command::openCommand("Fillet changed");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Radius = %f",name.c_str(),parameter->getLength());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
parameter->apply();
return true;
}

View File

@ -51,12 +51,13 @@ public:
TaskFilletParameters(ViewProviderFillet *FilletView, QWidget *parent=0);
~TaskFilletParameters();
double getLength(void) const;
void apply();
private Q_SLOTS:
void onLengthChanged(double);
protected:
double getLength(void) const;
void changeEvent(QEvent *e);
private:

View File

@ -82,6 +82,7 @@ TaskGrooveParameters::TaskGrooveParameters(ViewProviderGroove *GrooveView,QWidge
bool reversed = pcGroove->Reversed.getValue();
ui->grooveAngle->setValue(l);
ui->grooveAngle->bind(pcGroove->Angle);
int count=pcGroove->getSketchAxisCount();
@ -250,6 +251,38 @@ void TaskGrooveParameters::changeEvent(QEvent *e)
}
}
void TaskGrooveParameters::apply()
{
App::DocumentObject* groove = GrooveView->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*>();
if (sketch) {
support = static_cast<Sketcher::SketchObject*>(sketch)->Support.getValue();
}
}
//Gui::Command::openCommand("Groove changed");
ui->grooveAngle->apply();
std::string axis = getReferenceAxis().toStdString();
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
@ -288,35 +321,7 @@ void TaskDlgGrooveParameters::clicked(int)
bool TaskDlgGrooveParameters::accept()
{
App::DocumentObject* groove = GrooveView->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*>();
if (sketch) {
support = static_cast<Sketcher::SketchObject*>(sketch)->Support.getValue();
}
}
//Gui::Command::openCommand("Groove changed");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),parameter->getAngle());
std::string axis = parameter->getReferenceAxis().toStdString();
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(),parameter->getMidplane()?1:0);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i",name.c_str(),parameter->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();
parameter->apply();
return true;
}

View File

@ -52,11 +52,7 @@ public:
TaskGrooveParameters(ViewProviderGroove *GrooveView,QWidget *parent = 0);
~TaskGrooveParameters();
QString getReferenceAxis(void) const;
double getAngle(void) const;
bool getMidplane(void) const;
bool getReversed(void) const;
const bool updateView() const;
void apply();
private Q_SLOTS:
void onAngleChanged(double);
@ -67,6 +63,11 @@ private Q_SLOTS:
protected:
void changeEvent(QEvent *e);
QString getReferenceAxis(void) const;
double getAngle(void) const;
bool getMidplane(void) const;
bool getReversed(void) const;
const bool updateView() const;
private:

View File

@ -107,8 +107,8 @@ void TaskLinearPatternParameters::setupUI()
this, SLOT(onCheckReverse(bool)));
connect(ui->spinLength, SIGNAL(valueChanged(double)),
this, SLOT(onLength(double)));
connect(ui->spinOccurrences, SIGNAL(valueChanged(int)),
this, SLOT(onOccurrences(int)));
connect(ui->spinOccurrences, SIGNAL(valueChanged(double)),
this, SLOT(onOccurrences(double)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
@ -127,6 +127,9 @@ void TaskLinearPatternParameters::setupUI()
}
// ---------------------
ui->spinLength->bind(pcLinearPattern->Length);
ui->spinOccurrences->bind(pcLinearPattern->Occurrences);
ui->comboDirection->setEnabled(true);
ui->checkReverse->setEnabled(true);
ui->spinLength->blockSignals(true);
@ -271,11 +274,11 @@ void TaskLinearPatternParameters::onLength(const double l) {
kickUpdateViewTimer();
}
void TaskLinearPatternParameters::onOccurrences(const int n) {
void TaskLinearPatternParameters::onOccurrences(const double n) {
if (blockUpdate)
return;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
pcLinearPattern->Occurrences.setValue(n);
pcLinearPattern->Occurrences.setValue(round(n));
exitSelectionMode();
kickUpdateViewTimer();
@ -375,9 +378,9 @@ const double TaskLinearPatternParameters::getLength(void) const
return ui->spinLength->value().getValue();
}
const unsigned TaskLinearPatternParameters::getOccurrences(void) const
const unsigned TaskLinearPatternParameters::getOccurrences(void) const
{
return ui->spinOccurrences->value();
return round(ui->spinOccurrences->value().getValue());
}
@ -396,6 +399,39 @@ void TaskLinearPatternParameters::changeEvent(QEvent *e)
}
}
void TaskLinearPatternParameters::apply()
{
std::string name = TransformedView->getObject()->getNameInDocument();
std::string direction = getDirection();
if (!direction.empty()) {
App::DocumentObject* sketch = 0;
if (direction == "H_Axis" || direction == "V_Axis" ||
(direction.size() > 4 && direction.substr(0,4) == "Axis"))
sketch = getSketchObject();
else
sketch = getSupportObject();
if (sketch) {
QString buf = QString::fromLatin1("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromLatin1(sketch->getNameInDocument()));
buf = buf.arg(QString::fromLatin1(direction.c_str()));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = %s", name.c_str(), buf.toStdString().c_str());
}
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = None", name.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),getReverse());
ui->spinLength->apply();
ui->spinOccurrences->apply();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!TransformedView->getObject()->isValid())
throw Base::Exception(TransformedView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
@ -413,40 +449,13 @@ TaskDlgLinearPatternParameters::TaskDlgLinearPatternParameters(ViewProviderLinea
bool TaskDlgLinearPatternParameters::accept()
{
std::string name = TransformedView->getObject()->getNameInDocument();
try {
//Gui::Command::openCommand("LinearPattern changed");
// Handle Originals
if (!TaskDlgTransformedParameters::accept())
return false;
TaskLinearPatternParameters* linearpatternParameter = static_cast<TaskLinearPatternParameters*>(parameter);
std::string direction = linearpatternParameter->getDirection();
if (!direction.empty()) {
App::DocumentObject* sketch = 0;
if (direction == "H_Axis" || direction == "V_Axis" ||
(direction.size() > 4 && direction.substr(0,4) == "Axis"))
sketch = linearpatternParameter->getSketchObject();
else
sketch = linearpatternParameter->getSupportObject();
if (sketch) {
QString buf = QString::fromLatin1("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromLatin1(sketch->getNameInDocument()));
buf = buf.arg(QString::fromLatin1(direction.c_str()));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = %s", name.c_str(), buf.toStdString().c_str());
}
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = None", name.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),linearpatternParameter->getReverse());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Length = %f",name.c_str(),linearpatternParameter->getLength());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Occurrences = %u",name.c_str(),linearpatternParameter->getOccurrences());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!TransformedView->getObject()->isValid())
throw Base::Exception(TransformedView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
parameter->apply();
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromAscii(e.what()));

View File

@ -57,22 +57,23 @@ public:
TaskLinearPatternParameters(TaskMultiTransformParameters *parentTask, QLayout *layout);
virtual ~TaskLinearPatternParameters();
const std::string getDirection(void) const;
const bool getReverse(void) const;
const double getLength(void) const;
const unsigned getOccurrences(void) const;
virtual void apply();
private Q_SLOTS:
void onUpdateViewTimer();
void onDirectionChanged(int num);
void onCheckReverse(const bool on);
void onLength(const double l);
void onOccurrences(const int n);
void onOccurrences(const double n);
virtual void onUpdateView(bool);
protected:
virtual void changeEvent(QEvent *e);
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
const std::string getDirection(void) const;
const bool getReverse(void) const;
const double getLength(void) const;
const unsigned getOccurrences(void) const;
private:
void setupUI();

View File

@ -75,11 +75,11 @@
</widget>
</item>
<item>
<widget class="Gui::QuantitySpinBox" name="spinLength">
<widget class="Gui::QuantitySpinBox" name="spinLength" native="true">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="value">
<property name="value" stdset="0">
<double>100.000000000000000</double>
</property>
</widget>
@ -96,14 +96,7 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinOccurrences">
<property name="minimum">
<number>2</number>
</property>
<property name="maximum">
<number>99999</number>
</property>
</widget>
<widget class="Gui::QuantitySpinBox" name="spinOccurrences" native="true"/>
</item>
</layout>
</item>

View File

@ -291,6 +291,10 @@ const std::string TaskMirroredParameters::getMirrorPlane(void) const
return std::string("");
}
void TaskMirroredParameters::apply()
{
}
TaskMirroredParameters::~TaskMirroredParameters()
{
delete ui;

View File

@ -59,6 +59,8 @@ public:
const std::string getMirrorPlane(void) const;
virtual void apply();
private Q_SLOTS:
void onPlaneChanged(int num);
virtual void onUpdateView(bool);

View File

@ -382,6 +382,10 @@ const std::vector<App::DocumentObject*> TaskMultiTransformParameters::getTransfo
return pcMultiTransform->Transformations.getValues();
}
void TaskMultiTransformParameters::apply()
{
}
TaskMultiTransformParameters::~TaskMultiTransformParameters()
{
closeSubTask();

View File

@ -63,6 +63,8 @@ public:
/// Return the currently active subFeature
PartDesign::Transformed* getSubFeature(void) { return subFeature; }
virtual void apply();
private Q_SLOTS:
void onTransformDelete();
void onTransformEdit();

View File

@ -117,6 +117,9 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,bool newObj, QWidg
ui->lengthEdit2->setMaximum(INT_MAX);
ui->lengthEdit2->setValue(l2);
// 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
@ -290,7 +293,7 @@ void TaskPadParameters::onModeChanged(int index)
case 0:
pcPad->Type.setValue("Length");
// Avoid error message
if (ui->lengthEdit->value().getValue() < Precision::Confusion())
if (ui->lengthEdit->value() < Precision::Confusion())
ui->lengthEdit->setValue(5.0);
break;
case 1: pcPad->Type.setValue("UpToLast"); break;
@ -457,6 +460,37 @@ void TaskPadParameters::saveHistory(void)
ui->lengthEdit2->pushToHistory();
}
void TaskPadParameters::apply()
{
std::string name = PadView->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());
std::string facename = getFaceName().data();
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
Part::Feature* support = pcPad->getSupport();
if (support != NULL && !facename.empty()) {
QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(support->getNameInDocument()));
buf = buf.arg(QString::fromStdString(facename));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", cname, buf.toStdString().c_str());
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", cname);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!PadView->getObject()->isValid())
throw Base::Exception(PadView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
@ -494,34 +528,13 @@ void TaskDlgPadParameters::clicked(int)
bool TaskDlgPadParameters::accept()
{
std::string name = PadView->getObject()->getNameInDocument();
// save the history
parameter->saveHistory();
try {
//Gui::Command::openCommand("Pad changed");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Length = %f",name.c_str(),parameter->getLength());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i",name.c_str(),parameter->getReversed()?1:0);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Midplane = %i",name.c_str(),parameter->getMidplane()?1:0);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Length2 = %f",name.c_str(),parameter->getLength2());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u",name.c_str(),parameter->getMode());
std::string facename = parameter->getFaceName().data();
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
Part::Feature* support = pcPad->getSupport();
if (support != NULL && !facename.empty()) {
QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(support->getNameInDocument()));
buf = buf.arg(QString::fromStdString(facename));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", name.c_str(), buf.toStdString().c_str());
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", name.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!PadView->getObject()->isValid())
throw Base::Exception(PadView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
parameter->apply();
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromAscii(e.what()));

View File

@ -52,14 +52,9 @@ public:
TaskPadParameters(ViewProviderPad *PadView,bool newObj=false,QWidget *parent = 0);
~TaskPadParameters();
int getMode(void) const;
double getLength(void) const;
double getLength2(void) const;
bool getReversed(void) const;
bool getMidplane(void) const;
QByteArray getFaceName(void) const;
const bool updateView() const;
void saveHistory(void);
void apply();
private Q_SLOTS:
void onLengthChanged(double);
@ -75,6 +70,12 @@ protected:
void changeEvent(QEvent *e);
private:
int getMode(void) const;
double getLength(void) const;
double getLength2(void) const;
bool getReversed(void) const;
bool getMidplane(void) const;
QByteArray getFaceName(void) const;
void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI(int index);

View File

@ -120,6 +120,9 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge
ui->changeMode->setCurrentIndex(index);
ui->checkBoxMidplane->setChecked(midplane);
// Bind input fields to properties
ui->pocketLength->bind(pcPocket->Length);
ui->pocketLength->blockSignals(false);
ui->checkBoxMidplane->blockSignals(false);
ui->checkBoxReversed->blockSignals(false);
@ -412,6 +415,30 @@ void TaskPocketParameters::changeEvent(QEvent *e)
}
}
void TaskPocketParameters::apply()
{
std::string name = PocketView->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());
std::string facename = getFaceName().data();
PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(PocketView->getObject());
Part::Feature* support = pcPocket->getSupport();
if (support != NULL && !facename.empty()) {
QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(support->getNameInDocument()));
buf = buf.arg(QString::fromStdString(facename));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", name.c_str(), buf.toStdString().c_str());
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", name.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!PocketView->getObject()->isValid())
throw Base::Exception(PocketView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
@ -450,27 +477,8 @@ void TaskDlgPocketParameters::clicked(int)
bool TaskDlgPocketParameters::accept()
{
std::string name = PocketView->getObject()->getNameInDocument();
try {
//Gui::Command::openCommand("Pocket changed");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Length = %f",name.c_str(),parameter->getLength());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u",name.c_str(),parameter->getMode());
std::string facename = parameter->getFaceName().data();
PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(PocketView->getObject());
Part::Feature* support = pcPocket->getSupport();
if (support != NULL && !facename.empty()) {
QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(support->getNameInDocument()));
buf = buf.arg(QString::fromStdString(facename));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", name.c_str(), buf.toStdString().c_str());
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", name.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!PocketView->getObject()->isValid())
throw Base::Exception(PocketView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
parameter->apply();
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromAscii(e.what()));

View File

@ -52,11 +52,9 @@ public:
TaskPocketParameters(ViewProviderPocket *PocketView,QWidget *parent = 0);
~TaskPocketParameters();
double getLength(void) const;
bool getMidplane(void) const;
int getMode(void) const;
QByteArray getFaceName(void) const;
const bool updateView() const;
void apply();
private Q_SLOTS:
void onLengthChanged(double);
@ -71,6 +69,9 @@ protected:
void changeEvent(QEvent *e);
private:
double getLength(void) const;
bool getMidplane(void) const;
int getMode(void) const;
void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI(int index);

View File

@ -107,8 +107,8 @@ void TaskPolarPatternParameters::setupUI()
this, SLOT(onCheckReverse(bool)));
connect(ui->polarAngle, SIGNAL(valueChanged(double)),
this, SLOT(onAngle(double)));
connect(ui->spinOccurrences, SIGNAL(valueChanged(int)),
this, SLOT(onOccurrences(int)));
connect(ui->spinOccurrences, SIGNAL(valueChanged(double)),
this, SLOT(onOccurrences(double)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
@ -127,6 +127,9 @@ void TaskPolarPatternParameters::setupUI()
}
// ---------------------
ui->polarAngle->bind(pcPolarPattern->Angle);
ui->spinOccurrences->bind(pcPolarPattern->Occurrences);
ui->comboAxis->setEnabled(true);
ui->checkReverse->setEnabled(true);
ui->polarAngle->setEnabled(true);
@ -244,12 +247,12 @@ void TaskPolarPatternParameters::onAngle(const double a) {
kickUpdateViewTimer();
}
void TaskPolarPatternParameters::onOccurrences(const int n) {
void TaskPolarPatternParameters::onOccurrences(const double n) {
if (blockUpdate)
return;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
pcPolarPattern->Occurrences.setValue(n);
pcPolarPattern->Occurrences.setValue(round(n));
exitSelectionMode();
kickUpdateViewTimer();
}
@ -323,7 +326,7 @@ const double TaskPolarPatternParameters::getAngle(void) const
const unsigned TaskPolarPatternParameters::getOccurrences(void) const
{
return ui->spinOccurrences->value();
return round(ui->spinOccurrences->value().getValue());
}
@ -342,6 +345,36 @@ void TaskPolarPatternParameters::changeEvent(QEvent *e)
}
}
void TaskPolarPatternParameters::apply()
{
std::string name = TransformedView->getObject()->getNameInDocument();
std::string axis = getAxis();
if (!axis.empty()) {
App::DocumentObject* sketch = 0;
if (axis == "N_Axis")
sketch = getSketchObject();
else
sketch = getSupportObject();
if (sketch) {
QString buf = QString::fromLatin1("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromLatin1(sketch->getNameInDocument()));
buf = buf.arg(QString::fromLatin1(axis.c_str()));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = %s", name.c_str(), buf.toStdString().c_str());
}
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = None", name.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),getReverse());
ui->polarAngle->apply();
ui->spinOccurrences->apply();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!TransformedView->getObject()->isValid())
throw Base::Exception(TransformedView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
@ -358,39 +391,13 @@ TaskDlgPolarPatternParameters::TaskDlgPolarPatternParameters(ViewProviderPolarPa
bool TaskDlgPolarPatternParameters::accept()
{
std::string name = TransformedView->getObject()->getNameInDocument();
try {
//Gui::Command::openCommand("PolarPattern changed");
// Handle Originals
if (!TaskDlgTransformedParameters::accept())
return false;
TaskPolarPatternParameters* polarpatternParameter = static_cast<TaskPolarPatternParameters*>(parameter);
std::string axis = polarpatternParameter->getAxis();
if (!axis.empty()) {
App::DocumentObject* sketch = 0;
if (axis == "N_Axis")
sketch = polarpatternParameter->getSketchObject();
else
sketch = polarpatternParameter->getSupportObject();
if (sketch) {
QString buf = QString::fromLatin1("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromLatin1(sketch->getNameInDocument()));
buf = buf.arg(QString::fromLatin1(axis.c_str()));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = %s", name.c_str(), buf.toStdString().c_str());
}
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = None", name.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),polarpatternParameter->getReverse());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),polarpatternParameter->getAngle());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Occurrences = %u",name.c_str(),polarpatternParameter->getOccurrences());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!TransformedView->getObject()->isValid())
throw Base::Exception(TransformedView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
parameter->apply();
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromAscii(e.what()));

View File

@ -57,23 +57,23 @@ public:
TaskPolarPatternParameters(TaskMultiTransformParameters *parentTask, QLayout *layout);
virtual ~TaskPolarPatternParameters();
const std::string getStdAxis(void) const;
const std::string getAxis(void) const;
const bool getReverse(void) const;
const double getAngle(void) const;
const unsigned getOccurrences(void) const;
void apply();
private Q_SLOTS:
void onUpdateViewTimer();
void onAxisChanged(int num);
void onCheckReverse(const bool on);
void onAngle(const double a);
void onOccurrences(const int n);
void onOccurrences(const double n);
virtual void onUpdateView(bool);
protected:
virtual void changeEvent(QEvent *e);
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
const std::string getStdAxis(void) const;
const std::string getAxis(void) const;
const bool getReverse(void) const;
const double getAngle(void) const;
const unsigned getOccurrences(void) const;
private:
void setupUI();

View File

@ -70,17 +70,17 @@
</widget>
</item>
<item>
<widget class="Gui::QuantitySpinBox" name="polarAngle">
<widget class="Gui::QuantitySpinBox" name="polarAngle" native="true">
<property name="unit" stdset="0">
<string notr="true">deg</string>
</property>
<property name="minimum">
<property name="minimum" stdset="0">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<property name="maximum" stdset="0">
<double>360.000000000000000</double>
</property>
<property name="value">
<property name="value" stdset="0">
<double>360.000000000000000</double>
</property>
</widget>
@ -97,14 +97,7 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinOccurrences">
<property name="minimum">
<number>2</number>
</property>
<property name="maximum">
<number>99999</number>
</property>
</widget>
<widget class="Gui::QuantitySpinBox" name="spinOccurrences" native="true"/>
</item>
</layout>
</item>

View File

@ -113,6 +113,7 @@ TaskRevolutionParameters::TaskRevolutionParameters(ViewProviderRevolution *Revol
ui->checkBoxMidplane->setChecked(mirrored);
ui->checkBoxReversed->setChecked(reversed);
ui->revolveAngle->bind(pcRevolution->Angle);
ui->revolveAngle->blockSignals(false);
ui->axis->blockSignals(false);
@ -250,6 +251,38 @@ void TaskRevolutionParameters::changeEvent(QEvent *e)
}
}
void TaskRevolutionParameters::apply()
{
App::DocumentObject* revolve = RevolutionView->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<PartDesign::Revolution*>(revolve)->Sketch.getValue<Sketcher::SketchObject*>();
if (sketch) {
support = static_cast<Sketcher::SketchObject*>(sketch)->Support.getValue();
}
}
//Gui::Command::openCommand("Revolution changed");
ui->revolveAngle->apply();
std::string axis = getReferenceAxis().toStdString();
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();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
@ -288,35 +321,7 @@ void TaskDlgRevolutionParameters::clicked(int)
bool TaskDlgRevolutionParameters::accept()
{
App::DocumentObject* revolve = RevolutionView->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<PartDesign::Revolution*>(revolve)->Sketch.getValue<Sketcher::SketchObject*>();
if (sketch) {
support = static_cast<Sketcher::SketchObject*>(sketch)->Support.getValue();
}
}
//Gui::Command::openCommand("Revolution changed");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),parameter->getAngle());
std::string axis = parameter->getReferenceAxis().toStdString();
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(),parameter->getMidplane()?1:0);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i",name.c_str(),parameter->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();
parameter->apply();
return true;
}

View File

@ -52,11 +52,7 @@ public:
TaskRevolutionParameters(ViewProviderRevolution *RevolutionView,QWidget *parent = 0);
~TaskRevolutionParameters();
QString getReferenceAxis(void) const;
double getAngle(void) const;
bool getMidplane(void) const;
bool getReversed(void) const;
const bool updateView() const;
void apply();
private Q_SLOTS:
void onAngleChanged(double);
@ -67,6 +63,11 @@ private Q_SLOTS:
protected:
void changeEvent(QEvent *e);
const bool updateView() const;
QString getReferenceAxis(void) const;
double getAngle(void) const;
bool getMidplane(void) const;
bool getReversed(void) const;
private:

View File

@ -92,8 +92,8 @@ void TaskScaledParameters::setupUI()
{
connect(ui->spinFactor, SIGNAL(valueChanged(double)),
this, SLOT(onFactor(double)));
connect(ui->spinOccurrences, SIGNAL(valueChanged(int)),
this, SLOT(onOccurrences(int)));
connect(ui->spinOccurrences, SIGNAL(valueChanged(double)),
this, SLOT(onOccurrences(double)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
@ -112,9 +112,11 @@ void TaskScaledParameters::setupUI()
}
// ---------------------
ui->spinFactor->bind(pcScaled->Factor);
ui->spinOccurrences->bind(pcScaled->Occurrences);
ui->spinFactor->setEnabled(true);
ui->spinOccurrences->setEnabled(true);
ui->spinFactor->setDecimals(Base::UnitsApi::getDecimals());
//ui->spinFactor->setDecimals(Base::UnitsApi::getDecimals());
updateUI();
}
@ -144,7 +146,8 @@ void TaskScaledParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
}
}
void TaskScaledParameters::onFactor(const double f) {
void TaskScaledParameters::onFactor(const double f)
{
if (blockUpdate)
return;
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
@ -152,11 +155,12 @@ void TaskScaledParameters::onFactor(const double f) {
recomputeFeature();
}
void TaskScaledParameters::onOccurrences(const int n) {
void TaskScaledParameters::onOccurrences(const double n)
{
if (blockUpdate)
return;
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
pcScaled->Occurrences.setValue(n);
pcScaled->Occurrences.setValue(round(n));
recomputeFeature();
}
@ -174,15 +178,14 @@ void TaskScaledParameters::onUpdateView(bool on)
const double TaskScaledParameters::getFactor(void) const
{
return ui->spinFactor->value();
return ui->spinFactor->value().getValue();
}
const unsigned TaskScaledParameters::getOccurrences(void) const
{
return ui->spinOccurrences->value();
return round(ui->spinOccurrences->value().getValue());
}
TaskScaledParameters::~TaskScaledParameters()
{
delete ui;
@ -198,6 +201,19 @@ void TaskScaledParameters::changeEvent(QEvent *e)
}
}
void TaskScaledParameters::apply()
{
std::string name = TransformedView->getObject()->getNameInDocument();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Factor = %f",name.c_str(), getFactor());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Occurrences = %u",name.c_str(), getOccurrences());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!TransformedView->getObject()->isValid())
throw Base::Exception(TransformedView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
@ -214,22 +230,13 @@ TaskDlgScaledParameters::TaskDlgScaledParameters(ViewProviderScaled *ScaledView)
bool TaskDlgScaledParameters::accept()
{
std::string name = TransformedView->getObject()->getNameInDocument();
try {
//Gui::Command::openCommand("Scaled changed");
// Handle Originals
if (!TaskDlgTransformedParameters::accept())
return false;
TaskScaledParameters* scaledParameter = static_cast<TaskScaledParameters*>(parameter);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Factor = %f",name.c_str(),scaledParameter->getFactor());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Occurrences = %u",name.c_str(),scaledParameter->getOccurrences());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!TransformedView->getObject()->isValid())
throw Base::Exception(TransformedView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
parameter->apply();
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromAscii(e.what()));

View File

@ -56,17 +56,18 @@ public:
TaskScaledParameters(TaskMultiTransformParameters *parentTask, QLayout *layout);
virtual ~TaskScaledParameters();
const double getFactor(void) const;
const unsigned getOccurrences(void) const;
virtual void apply();
private Q_SLOTS:
void onFactor(const double f);
void onOccurrences(const int n);
void onOccurrences(const double n);
virtual void onUpdateView(bool);
protected:
virtual void changeEvent(QEvent *e);
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
const double getFactor(void) const;
const unsigned getOccurrences(void) const;
private:
void setupUI();

View File

@ -38,20 +38,7 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="spinFactor">
<property name="decimals">
<number>3</number>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="singleStep">
<double>0.500000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>
</widget>
<widget class="Gui::QuantitySpinBox" name="spinFactor" native="true"/>
</item>
</layout>
</item>
@ -65,14 +52,7 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinOccurrences">
<property name="minimum">
<number>2</number>
</property>
<property name="maximum">
<number>99999</number>
</property>
</widget>
<widget class="Gui::QuantitySpinBox" name="spinOccurrences" native="true"/>
</item>
</layout>
</item>
@ -112,6 +92,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -66,6 +66,8 @@ public:
void exitSelectionMode();
virtual void apply() = 0;
protected Q_SLOTS:
/// Connect the subTask OK button to the MultiTransform task
virtual void onSubTaskButtonOK() {}