PartDesign: Added support for expressions.

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

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()));