PartDesign: fix bug in checkbox "Update View" of pattern features and do some code refactoring

This commit is contained in:
logari81 2012-09-13 15:46:46 +02:00
parent e1727b6c16
commit f0917eff39
12 changed files with 277 additions and 328 deletions

View File

@ -29,6 +29,7 @@
#include "ui_TaskLinearPatternParameters.h"
#include "TaskLinearPatternParameters.h"
#include "TaskMultiTransformParameters.h"
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
@ -41,7 +42,6 @@
#include <Gui/Command.h>
#include <Mod/PartDesign/App/FeatureLinearPattern.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include "TaskMultiTransformParameters.h"
using namespace PartDesignGui;
using namespace Gui;
@ -64,7 +64,7 @@ TaskLinearPatternParameters::TaskLinearPatternParameters(ViewProviderTransformed
referenceSelectionMode = false;
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
@ -87,7 +87,7 @@ TaskLinearPatternParameters::TaskLinearPatternParameters(TaskMultiTransformParam
referenceSelectionMode = false;
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
@ -138,9 +138,9 @@ void TaskLinearPatternParameters::setupUI()
void TaskLinearPatternParameters::updateUI()
{
if (updateUIinProgress)
if (blockUpdate)
return;
updateUIinProgress = true;
blockUpdate = true;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
@ -177,39 +177,45 @@ void TaskLinearPatternParameters::updateUI()
ui->lineReference->setText(tr("Select an edge or a face"));
// Note: These three lines would trigger onLength(), on Occurrences() and another updateUI() if we
// didn't check for updateUIinProgress
// didn't check for blockUpdate
ui->checkReverse->setChecked(reverse);
ui->spinLength->setValue(length);
ui->spinOccurrences->setValue(occurrences);
updateUIinProgress = false;
blockUpdate = false;
}
void TaskLinearPatternParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (msg.Type == Gui::SelectionChanges::AddSelection) {
if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0)
return;
std::string subName(msg.pSubName);
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
if (originalSelectionMode) {
App::DocumentObject* selectedObject = pcLinearPattern->getDocument()->getActiveObject();
if ((selectedObject == NULL) || !selectedObject->isDerivedFrom(Part::Feature::getClassTypeId()))
return;
if (originalSelected(msg))
ui->lineOriginal->setText(QString::fromAscii(selectedObject->getNameInDocument()));
if (originalSelected(msg)) {
ui->lineOriginal->setText(QString::fromAscii(msg.pObjectName));
} else if (referenceSelectionMode &&
((subName.size() > 4 && subName.substr(0,4) == "Edge") ||
(subName.size() > 4 && subName.substr(0,4) == "Face"))) {
std::vector<std::string> directions;
directions.push_back(subName.c_str());
pcLinearPattern->Direction.setValue(getOriginalObject(), directions);
pcLinearPattern->StdDirection.setValue("");
if (updateView())
recomputeFeature();
if (strcmp(msg.pObjectName, getSupportObject()->getNameInDocument()) != 0)
return;
exitSelectionMode();
updateUI();
if (!blockUpdate) {
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
std::vector<std::string> directions(1,subName);
pcLinearPattern->Direction.setValue(getSupportObject(), directions);
pcLinearPattern->StdDirection.setValue("");
recomputeFeature();
updateUI();
}
else {
ui->buttonReference->setChecked(referenceSelectionMode);
ui->lineReference->setText(QString::fromAscii(subName.c_str()));
}
}
}
}
@ -227,43 +233,40 @@ void TaskLinearPatternParameters::onButtonZ() {
}
void TaskLinearPatternParameters::onCheckReverse(const bool on) {
if (updateUIinProgress)
if (blockUpdate)
return;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
pcLinearPattern->Reversed.setValue(on);
exitSelectionMode();
updateUI();
if (updateView())
recomputeFeature();
recomputeFeature();
}
void TaskLinearPatternParameters::onLength(const double l) {
if (updateUIinProgress)
if (blockUpdate)
return;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
pcLinearPattern->Length.setValue(l);
exitSelectionMode();
updateUI();
if (updateView())
recomputeFeature();
recomputeFeature();
}
void TaskLinearPatternParameters::onOccurrences(const int n) {
if (updateUIinProgress)
if (blockUpdate)
return;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
pcLinearPattern->Occurrences.setValue(n);
exitSelectionMode();
updateUI();
if (updateView())
recomputeFeature();
recomputeFeature();
}
void TaskLinearPatternParameters::onStdDirection(const std::string& dir) {
if (updateUIinProgress)
if (blockUpdate)
return;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
pcLinearPattern->StdDirection.setValue(dir.c_str());
@ -271,14 +274,11 @@ void TaskLinearPatternParameters::onStdDirection(const std::string& dir) {
exitSelectionMode();
updateUI();
if (updateView())
recomputeFeature();
recomputeFeature();
}
void TaskLinearPatternParameters::onButtonReference(bool checked)
{
if (updateUIinProgress)
return;
if (checked ) {
hideObject();
showOriginals();
@ -292,49 +292,46 @@ void TaskLinearPatternParameters::onButtonReference(bool checked)
void TaskLinearPatternParameters::onUpdateView(bool on)
{
ui->buttonX->blockSignals(!on);
ui->buttonY->blockSignals(!on);
ui->buttonZ->blockSignals(!on);
ui->checkReverse->blockSignals(!on);
ui->spinLength->blockSignals(!on);
ui->spinOccurrences->blockSignals(!on);
blockUpdate = !on;
if (on) {
// Do the same like in TaskDlgLinearPatternParameters::accept() but without doCommand
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
std::string direction = getDirection();
if (!direction.empty()) {
std::vector<std::string> directions(1,direction);
pcLinearPattern->Direction.setValue(getSupportObject(), directions);
} else
pcLinearPattern->Direction.setValue(NULL);
std::string stdDirection = getStdDirection();
if (!stdDirection.empty())
pcLinearPattern->StdDirection.setValue(stdDirection.c_str());
else
pcLinearPattern->StdDirection.setValue(NULL);
pcLinearPattern->Reversed.setValue(getReverse());
pcLinearPattern->Length.setValue(getLength());
pcLinearPattern->Occurrences.setValue(getOccurrences());
recomputeFeature();
}
}
const std::string TaskLinearPatternParameters::getStdDirection(void) const
{
std::string stdDirection;
if (ui->buttonX->isChecked())
stdDirection = "X";
return std::string("X");
else if (ui->buttonY->isChecked())
stdDirection = "Y";
return std::string("Y");
else if (ui->buttonZ->isChecked())
stdDirection = "Z";
if (!stdDirection.empty())
return std::string("\"") + stdDirection + "\"";
else
return std::string("");
return std::string("Z");
return std::string("");
}
const QString TaskLinearPatternParameters::getDirection(void) const
const std::string TaskLinearPatternParameters::getDirection(void) const
{
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
App::DocumentObject* feature = pcLinearPattern->Direction.getValue();
if (feature == NULL)
return QString::fromUtf8("");
std::vector<std::string> directions = pcLinearPattern->Direction.getSubValues();
QString buf;
if ((feature != NULL) && !directions.empty()) {
buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(feature->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(directions.front().c_str()));
}
else
buf = QString::fromUtf8("");
return buf;
return ui->lineReference->text().toStdString();
}
const bool TaskLinearPatternParameters::getReverse(void) const
@ -352,14 +349,6 @@ const unsigned TaskLinearPatternParameters::getOccurrences(void) const
return ui->spinOccurrences->value();
}
const bool TaskLinearPatternParameters::updateView() const
{
if (insideMultiTransform)
return parentTask->updateView();
else
return ui->checkBoxUpdateView->isChecked();
}
void TaskLinearPatternParameters::exitSelectionMode()
{
originalSelectionMode = false;
@ -409,12 +398,16 @@ bool TaskDlgLinearPatternParameters::accept()
return false;
TaskLinearPatternParameters* linearpatternParameter = static_cast<TaskLinearPatternParameters*>(parameter);
std::string direction = linearpatternParameter->getDirection().toStdString();
if (!direction.empty())
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = %s", name.c_str(), direction.c_str());
std::string direction = linearpatternParameter->getDirection();
if (!direction.empty()) {
QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(linearpatternParameter->getSupportObject()->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(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());
std::string stdDirection = linearpatternParameter->getStdDirection();
if (!stdDirection.empty())
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdDirection = %s",name.c_str(),stdDirection.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdDirection = \"%s\"",name.c_str(),stdDirection.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());

View File

@ -56,12 +56,11 @@ public:
TaskLinearPatternParameters(TaskMultiTransformParameters *parentTask, QLayout *layout);
virtual ~TaskLinearPatternParameters();
const QString getDirection(void) const;
const std::string getStdDirection(void) const;
const std::string getDirection(void) const;
const bool getReverse(void) const;
const double getLength(void) const;
const unsigned getOccurrences(void) const;
const bool updateView() const;
private Q_SLOTS:
void onStdDirection(const std::string& dir);

View File

@ -43,7 +43,6 @@
#include <Mod/PartDesign/App/FeatureMirrored.h>
#include <Mod/Sketcher/App/SketchObject.h>
using namespace PartDesignGui;
using namespace Gui;
@ -65,7 +64,7 @@ TaskMirroredParameters::TaskMirroredParameters(ViewProviderTransformed *Transfor
referenceSelectionMode = false;
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
@ -88,7 +87,7 @@ TaskMirroredParameters::TaskMirroredParameters(TaskMultiTransformParameters *par
referenceSelectionMode = false;
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
@ -130,9 +129,9 @@ void TaskMirroredParameters::setupUI()
void TaskMirroredParameters::updateUI()
{
if (updateUIinProgress)
if (blockUpdate)
return;
updateUIinProgress = true;
blockUpdate = true;
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
App::DocumentObject* mirrorPlaneFeature = pcMirrored->MirrorPlane.getValue();
std::vector<std::string> mirrorPlanes = pcMirrored->MirrorPlane.getSubValues();
@ -163,39 +162,45 @@ void TaskMirroredParameters::updateUI()
if (referenceSelectionMode)
ui->lineReference->setText(tr("Select a plane"));
updateUIinProgress = false;
blockUpdate = false;
}
void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (msg.Type == Gui::SelectionChanges::AddSelection) {
if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0)
return;
std::string subName(msg.pSubName);
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
if (originalSelectionMode) {
App::DocumentObject* selectedObject = pcMirrored->getDocument()->getActiveObject();
if ((selectedObject == NULL) || !selectedObject->isDerivedFrom(Part::Feature::getClassTypeId()))
return;
if (originalSelected(msg))
ui->lineOriginal->setText(QString::fromAscii(selectedObject->getNameInDocument()));
if (originalSelected(msg)) {
ui->lineOriginal->setText(QString::fromAscii(msg.pObjectName));
} else if (referenceSelectionMode &&
(subName.size() > 4 && subName.substr(0,4) == "Face")) {
std::vector<std::string> mirrorPlanes;
mirrorPlanes.push_back(subName.c_str());
pcMirrored->MirrorPlane.setValue(getOriginalObject(), mirrorPlanes);
pcMirrored->StdMirrorPlane.setValue("");
if (updateView())
recomputeFeature();
if (strcmp(msg.pObjectName, getSupportObject()->getNameInDocument()) != 0)
return;
exitSelectionMode();
updateUI();
if (!blockUpdate) {
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
std::vector<std::string> mirrorPlanes(1,subName);
pcMirrored->MirrorPlane.setValue(getSupportObject(), mirrorPlanes);
pcMirrored->StdMirrorPlane.setValue("");
recomputeFeature();
updateUI();
}
else {
ui->buttonReference->setChecked(referenceSelectionMode);
ui->lineReference->setText(QString::fromAscii(subName.c_str()));
}
}
}
}
void TaskMirroredParameters::onStdMirrorPlane(const std::string &plane) {
if (updateUIinProgress)
if (blockUpdate)
return;
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
pcMirrored->StdMirrorPlane.setValue(plane.c_str());
@ -203,8 +208,7 @@ void TaskMirroredParameters::onStdMirrorPlane(const std::string &plane) {
exitSelectionMode();
updateUI();
if (updateView())
recomputeFeature();
recomputeFeature();
}
void TaskMirroredParameters::onButtonXY() {
@ -221,8 +225,6 @@ void TaskMirroredParameters::onButtonYZ() {
void TaskMirroredParameters::onButtonReference(bool checked)
{
if (updateUIinProgress)
return;
if (checked ) {
hideObject();
showOriginals();
@ -236,54 +238,42 @@ void TaskMirroredParameters::onButtonReference(bool checked)
void TaskMirroredParameters::onUpdateView(bool on)
{
ui->buttonXY->blockSignals(!on);
ui->buttonYZ->blockSignals(!on);
ui->buttonXZ->blockSignals(!on);
blockUpdate = !on;
if (on) {
// Do the same like in TaskDlgMirroredParameters::accept() but without doCommand
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
std::string mirrorPlane = getMirrorPlane();
if (!mirrorPlane.empty()) {
std::vector<std::string> planes(1,mirrorPlane);
pcMirrored->MirrorPlane.setValue(getSupportObject(),planes);
} else
pcMirrored->MirrorPlane.setValue(NULL);
std::string stdMirrorPlane = getStdMirrorPlane();
if (!stdMirrorPlane.empty())
pcMirrored->StdMirrorPlane.setValue(stdMirrorPlane.c_str());
else
pcMirrored->StdMirrorPlane.setValue(NULL);
recomputeFeature();
}
}
const std::string TaskMirroredParameters::getStdMirrorPlane(void) const
{
std::string stdMirrorPlane;
if (ui->buttonXY->isChecked())
stdMirrorPlane = "XY";
return std::string("XY");
else if (ui->buttonYZ->isChecked())
stdMirrorPlane = "YZ";
return std::string("YZ");
else if (ui->buttonXZ->isChecked())
stdMirrorPlane = "XZ";
if (!stdMirrorPlane.empty())
return std::string("\"") + stdMirrorPlane + "\"";
else
return std::string("");
return std::string("XZ");
return std::string("");
}
const QString TaskMirroredParameters::getMirrorPlane(void) const
const std::string TaskMirroredParameters::getMirrorPlane(void) const
{
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
App::DocumentObject* feature = pcMirrored->MirrorPlane.getValue();
if (feature == NULL)
return QString::fromUtf8("");
std::vector<std::string> mirrorPlanes = pcMirrored->MirrorPlane.getSubValues();
QString buf;
if ((feature != NULL) && !mirrorPlanes.empty()) {
buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(feature->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(mirrorPlanes.front().c_str()));
}
else
buf = QString::fromUtf8("");
return buf;
}
const bool TaskMirroredParameters::updateView() const
{
if (insideMultiTransform)
return parentTask->updateView();
else
return ui->checkBoxUpdateView->isChecked();
return ui->lineReference->text().toStdString();
}
void TaskMirroredParameters::exitSelectionMode()
@ -335,12 +325,16 @@ bool TaskDlgMirroredParameters::accept()
return false;
TaskMirroredParameters* mirrorParameter = static_cast<TaskMirroredParameters*>(parameter);
std::string mirrorPlane = mirrorParameter->getMirrorPlane().toStdString();
if (!mirrorPlane.empty())
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = %s", name.c_str(), mirrorPlane.c_str());
std::string mirrorPlane = mirrorParameter->getMirrorPlane();
if (!mirrorPlane.empty()) {
QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(mirrorParameter->getSupportObject()->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(mirrorPlane.c_str()));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = %s", name.c_str(), buf.toStdString().c_str());
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = None", name.c_str());
std::string stdMirrorPlane = mirrorParameter->getStdMirrorPlane();
if (!stdMirrorPlane.empty())
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdMirrorPlane = %s",name.c_str(),stdMirrorPlane.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdMirrorPlane = \"%s\"",name.c_str(),stdMirrorPlane.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!TransformedView->getObject()->isValid())
throw Base::Exception(TransformedView->getObject()->getStatusString());

View File

@ -57,9 +57,8 @@ public:
virtual ~TaskMirroredParameters();
const QString getMirrorPlane(void) const;
const std::string getStdMirrorPlane(void) const;
const bool updateView() const;
const std::string getMirrorPlane(void) const;
private Q_SLOTS:
void onButtonXY();

View File

@ -101,8 +101,6 @@ TaskMultiTransformParameters::TaskMultiTransformParameters(ViewProviderTransform
this, SLOT(onMoveDown()));
ui->listTransformFeatures->addAction(action);
ui->listTransformFeatures->setContextMenuPolicy(Qt::ActionsContextMenu);
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
connect(ui->listTransformFeatures, SIGNAL(activated(QModelIndex)),
this, SLOT(onTransformActivated(QModelIndex)));
@ -144,20 +142,16 @@ TaskMultiTransformParameters::TaskMultiTransformParameters(ViewProviderTransform
void TaskMultiTransformParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject());
App::DocumentObject* selectedObject = pcMultiTransform->getDocument()->getActiveObject();
if ((selectedObject == NULL) || !selectedObject->isDerivedFrom(Part::Feature::getClassTypeId()))
return;
if (originalSelectionMode) {
if (originalSelected(msg))
ui->lineOriginal->setText(QString::fromAscii(selectedObject->getNameInDocument()));
if (originalSelected(msg)) {
App::DocumentObject* selectedObject = TransformedView->getObject()->getDocument()->getActiveObject();
ui->lineOriginal->setText(QString::fromAscii(selectedObject->getNameInDocument()));
}
}
void TaskMultiTransformParameters::closeSubTask()
{
if (subTask) {
disconnect(ui->checkBoxUpdateView, 0, subTask, 0);
delete subTask;
subTask = NULL;
}
@ -175,9 +169,10 @@ void TaskMultiTransformParameters::onTransformDelete()
closeSubTask();
transformFeatures.erase(transformFeatures.begin() + row);
pcMultiTransform->Transformations.setValues(transformFeatures);
if (ui->checkBoxUpdateView->isChecked())
pcMultiTransform->getDocument()->recomputeFeature(pcMultiTransform);
pcMultiTransform->Transformations.setValues(transformFeatures);
// Note: When the last transformation is deleted, recomputeFeature does nothing, because Transformed::execute()
// says: "No transformations defined, exit silently"
recomputeFeature();
ui->listTransformFeatures->model()->removeRow(row);
ui->listTransformFeatures->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
@ -203,6 +198,9 @@ void TaskMultiTransformParameters::onTransformEdit()
subTask = new TaskScaledParameters(this, ui->verticalLayout);
else
return; // TODO: Show an error?
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
subTask, SLOT(onUpdateView(bool)));
}
void TaskMultiTransformParameters::onTransformActivated(const QModelIndex& index) {
@ -300,8 +298,7 @@ void TaskMultiTransformParameters::finishAdd(std::string &newFeatName)
}
pcMultiTransform->Transformations.setValues(transformFeatures);
if (ui->checkBoxUpdateView->isChecked())
pcMultiTransform->getDocument()->recomputeFeature(pcMultiTransform);
recomputeFeature();
// Set state to hidden - only the MultiTransform should be visible
Gui::Command::doCommand(
@ -341,8 +338,7 @@ void TaskMultiTransformParameters::moveTransformFeature(const int increment)
}
pcMultiTransform->Transformations.setValues(transformFeatures);
if (ui->checkBoxUpdateView->isChecked())
pcMultiTransform->getDocument()->recomputeFeature(pcMultiTransform);
recomputeFeature();
}
void TaskMultiTransformParameters::onMoveUp()
@ -359,10 +355,6 @@ void TaskMultiTransformParameters::onSubTaskButtonOK() {
closeSubTask();
}
void TaskMultiTransformParameters::onUpdateView(bool on)
{
}
const std::vector<App::DocumentObject*> TaskMultiTransformParameters::getTransformFeatures(void) const
{
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject());
@ -385,16 +377,6 @@ void TaskMultiTransformParameters::changeEvent(QEvent *e)
}
}
void TaskMultiTransformParameters::recomputeFeature() {
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject());
pcMultiTransform->getDocument()->recomputeFeature(pcMultiTransform);
}
const bool TaskMultiTransformParameters::updateView() const
{
return ui->checkBoxUpdateView->isChecked();
}
//**************************************************************************
//**************************************************************************
// TaskDialog

View File

@ -62,11 +62,6 @@ public:
/// Return the currently active subFeature
PartDesign::Transformed* getSubFeature(void) { return subFeature; }
/// Recompute the feature associated with this task
void recomputeFeature();
/// Tell the subtask whether the view should be updated
const bool updateView() const;
private Q_SLOTS:
void onTransformDelete();
void onTransformEdit();
@ -77,7 +72,6 @@ private Q_SLOTS:
void onTransformAddScaled();
void onMoveUp();
void onMoveDown();
virtual void onUpdateView(bool);
/// User finished editing a subFeature
virtual void onSubTaskButtonOK();
// Note: There is no Cancel button because I couldn't work out how to save the state of

View File

@ -29,6 +29,7 @@
#include "ui_TaskPolarPatternParameters.h"
#include "TaskPolarPatternParameters.h"
#include "TaskMultiTransformParameters.h"
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
@ -41,7 +42,6 @@
#include <Gui/Command.h>
#include <Mod/PartDesign/App/FeaturePolarPattern.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include "TaskMultiTransformParameters.h"
using namespace PartDesignGui;
using namespace Gui;
@ -64,7 +64,7 @@ TaskPolarPatternParameters::TaskPolarPatternParameters(ViewProviderTransformed *
referenceSelectionMode = false;
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
@ -87,7 +87,7 @@ TaskPolarPatternParameters::TaskPolarPatternParameters(TaskMultiTransformParamet
referenceSelectionMode = false;
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
@ -138,9 +138,9 @@ void TaskPolarPatternParameters::setupUI()
void TaskPolarPatternParameters::updateUI()
{
if (updateUIinProgress)
if (blockUpdate)
return;
updateUIinProgress = true;
blockUpdate = true;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
@ -180,33 +180,39 @@ void TaskPolarPatternParameters::updateUI()
ui->spinAngle->setValue(angle);
ui->spinOccurrences->setValue(occurrences);
updateUIinProgress = false;
blockUpdate = false;
}
void TaskPolarPatternParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (msg.Type == Gui::SelectionChanges::AddSelection) {
if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0)
return;
std::string subName(msg.pSubName);
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
if (originalSelectionMode) {
App::DocumentObject* selectedObject = pcPolarPattern->getDocument()->getActiveObject();
if ((selectedObject == NULL) || !selectedObject->isDerivedFrom(Part::Feature::getClassTypeId()))
return;
if (originalSelected(msg))
ui->lineOriginal->setText(QString::fromAscii(selectedObject->getNameInDocument()));
if (originalSelected(msg)) {
ui->lineOriginal->setText(QString::fromAscii(msg.pObjectName));
} else if (referenceSelectionMode &&
(subName.size() > 4 && subName.substr(0,4) == "Edge")) {
std::vector<std::string> axes;
axes.push_back(subName.c_str());
pcPolarPattern->Axis.setValue(getOriginalObject(), axes);
pcPolarPattern->StdAxis.setValue("");
if (updateView())
recomputeFeature();
if (strcmp(msg.pObjectName, getSupportObject()->getNameInDocument()) != 0)
return;
exitSelectionMode();
updateUI();
if (!blockUpdate) {
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
std::vector<std::string> axes(1,subName);
pcPolarPattern->Axis.setValue(getSupportObject(), axes);
pcPolarPattern->StdAxis.setValue("");
recomputeFeature();
updateUI();
}
else {
ui->buttonReference->setChecked(referenceSelectionMode);
ui->lineReference->setText(QString::fromAscii(subName.c_str()));
}
}
}
}
@ -224,43 +230,40 @@ void TaskPolarPatternParameters::onButtonZ() {
}
void TaskPolarPatternParameters::onCheckReverse(const bool on) {
if (updateUIinProgress)
if (blockUpdate)
return;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
pcPolarPattern->Reversed.setValue(on);
exitSelectionMode();
updateUI();
if (updateView())
recomputeFeature();
recomputeFeature();
}
void TaskPolarPatternParameters::onAngle(const double a) {
if (updateUIinProgress)
if (blockUpdate)
return;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
pcPolarPattern->Angle.setValue(a);
exitSelectionMode();
updateUI();
if (updateView())
recomputeFeature();
recomputeFeature();
}
void TaskPolarPatternParameters::onOccurrences(const int n) {
if (updateUIinProgress)
if (blockUpdate)
return;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
pcPolarPattern->Occurrences.setValue(n);
exitSelectionMode();
updateUI();
if (updateView())
recomputeFeature();
recomputeFeature();
}
void TaskPolarPatternParameters::onStdAxis(const std::string& axis) {
if (updateUIinProgress)
if (blockUpdate)
return;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
pcPolarPattern->StdAxis.setValue(axis.c_str());
@ -268,14 +271,11 @@ void TaskPolarPatternParameters::onStdAxis(const std::string& axis) {
exitSelectionMode();
updateUI();
if (updateView())
recomputeFeature();
recomputeFeature();
}
void TaskPolarPatternParameters::onButtonReference(bool checked)
{
if (updateUIinProgress)
return;
if (checked ) {
hideObject();
showOriginals();
@ -289,51 +289,48 @@ void TaskPolarPatternParameters::onButtonReference(bool checked)
void TaskPolarPatternParameters::onUpdateView(bool on)
{
ui->buttonX->blockSignals(!on);
ui->buttonY->blockSignals(!on);
ui->buttonZ->blockSignals(!on);
ui->checkReverse->blockSignals(!on);
ui->spinAngle->blockSignals(!on);
ui->spinOccurrences->blockSignals(!on);
blockUpdate = !on;
if (on) {
// Do the same like in TaskDlgPolarPatternParameters::accept() but without doCommand
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
std::string axis = getAxis();
if (!axis.empty()) {
std::vector<std::string> axes(1,axis);
pcPolarPattern->Axis.setValue(getSupportObject(),axes);
} else
pcPolarPattern->Axis.setValue(NULL);
std::string stdAxis = getStdAxis();
if (!stdAxis.empty())
pcPolarPattern->StdAxis.setValue(stdAxis.c_str());
else
pcPolarPattern->StdAxis.setValue(NULL);
pcPolarPattern->Reversed.setValue(getReverse());
pcPolarPattern->Angle.setValue(getAngle());
pcPolarPattern->Occurrences.setValue(getOccurrences());
recomputeFeature();
}
}
const std::string TaskPolarPatternParameters::getStdAxis(void) const
{
std::string stdAxis;
if (ui->buttonX->isChecked())
stdAxis = "X";
return std::string("X");
else if (ui->buttonY->isChecked())
stdAxis = "Y";
return std::string("Y");
else if (ui->buttonZ->isChecked())
stdAxis = "Z";
if (!stdAxis.empty())
return std::string("\"") + stdAxis + "\"";
else
return std::string("");
return std::string("Z");
return std::string("");
}
const QString TaskPolarPatternParameters::getAxis(void) const
const std::string TaskPolarPatternParameters::getAxis(void) const
{
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
App::DocumentObject* feature = pcPolarPattern->Axis.getValue();
if (feature == NULL)
return QString::fromUtf8("");
std::vector<std::string> axes = pcPolarPattern->Axis.getSubValues();
QString buf;
if ((feature != NULL) && !axes.empty()) {
buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(feature->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(axes.front().c_str()));
}
else
buf = QString::fromUtf8("");
return buf;
return ui->lineReference->text().toStdString();
}
const bool TaskPolarPatternParameters::getReverse(void) const
{
return ui->checkReverse->isChecked();
@ -349,14 +346,6 @@ const unsigned TaskPolarPatternParameters::getOccurrences(void) const
return ui->spinOccurrences->value();
}
const bool TaskPolarPatternParameters::updateView() const
{
if (insideMultiTransform)
return parentTask->updateView();
else
return ui->checkBoxUpdateView->isChecked();
}
void TaskPolarPatternParameters::exitSelectionMode()
{
originalSelectionMode = false;
@ -406,12 +395,16 @@ bool TaskDlgPolarPatternParameters::accept()
return false;
TaskPolarPatternParameters* polarpatternParameter = static_cast<TaskPolarPatternParameters*>(parameter);
std::string axis = polarpatternParameter->getAxis().toStdString();
if (!axis.empty())
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = %s", name.c_str(), axis.c_str());
std::string axis = polarpatternParameter->getAxis();
if (!axis.empty()) {
QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(polarpatternParameter->getSupportObject()->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(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());
std::string stdAxis = polarpatternParameter->getStdAxis();
if (!stdAxis.empty())
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdAxis = %s",name.c_str(),stdAxis.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdAxis = \"%s\"",name.c_str(),stdAxis.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());

View File

@ -56,12 +56,11 @@ public:
TaskPolarPatternParameters(TaskMultiTransformParameters *parentTask, QLayout *layout);
virtual ~TaskPolarPatternParameters();
const QString getAxis(void) const;
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;
const bool updateView() const;
private Q_SLOTS:
void onStdAxis(const std::string& axis);

View File

@ -29,6 +29,7 @@
#include "ui_TaskScaledParameters.h"
#include "TaskScaledParameters.h"
#include "TaskMultiTransformParameters.h"
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
@ -41,7 +42,6 @@
#include <Gui/Command.h>
#include <Mod/PartDesign/App/FeatureScaled.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include "TaskMultiTransformParameters.h"
using namespace PartDesignGui;
using namespace Gui;
@ -62,7 +62,7 @@ TaskScaledParameters::TaskScaledParameters(ViewProviderTransformed *TransformedV
ui->buttonOK->hide();
ui->checkBoxUpdateView->setEnabled(true);
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
@ -83,7 +83,7 @@ TaskScaledParameters::TaskScaledParameters(TaskMultiTransformParameters *parentT
ui->lineOriginal->hide();
ui->checkBoxUpdateView->hide();
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
@ -119,8 +119,9 @@ void TaskScaledParameters::setupUI()
void TaskScaledParameters::updateUI()
{
if (updateUIinProgress) return;
updateUIinProgress = true;
if (blockUpdate)
return;
blockUpdate = true;
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
@ -130,44 +131,45 @@ void TaskScaledParameters::updateUI()
ui->spinFactor->setValue(factor);
ui->spinOccurrences->setValue(occurrences);
updateUIinProgress = false;
blockUpdate = false;
}
void TaskScaledParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
App::DocumentObject* selectedObject = pcScaled->getDocument()->getActiveObject();
if ((selectedObject == NULL) || !selectedObject->isDerivedFrom(Part::Feature::getClassTypeId()))
return;
if (originalSelectionMode) {
if (originalSelected(msg))
ui->lineOriginal->setText(QString::fromAscii(selectedObject->getNameInDocument()));
if (originalSelected(msg)) {
App::DocumentObject* selectedObject = TransformedView->getObject()->getDocument()->getActiveObject();
ui->lineOriginal->setText(QString::fromAscii(selectedObject->getNameInDocument()));
}
}
void TaskScaledParameters::onFactor(const double f) {
if (updateUIinProgress) return;
if (blockUpdate)
return;
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
pcScaled->Factor.setValue(f);
updateUI();
if (updateView())
recomputeFeature();
recomputeFeature();
}
void TaskScaledParameters::onOccurrences(const int n) {
if (updateUIinProgress) return;
if (blockUpdate)
return;
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
pcScaled->Occurrences.setValue(n);
updateUI();
if (updateView())
recomputeFeature();
recomputeFeature();
}
void TaskScaledParameters::onUpdateView(bool on)
{
ui->spinFactor->blockSignals(!on);
ui->spinOccurrences->blockSignals(!on);
blockUpdate = !on;
if (on) {
// Do the same like in TaskDlgScaledParameters::accept() but without doCommand
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
pcScaled->Factor.setValue(getFactor());
pcScaled->Occurrences.setValue(getOccurrences());
recomputeFeature();
}
}
const double TaskScaledParameters::getFactor(void) const
@ -180,13 +182,6 @@ const unsigned TaskScaledParameters::getOccurrences(void) const
return ui->spinOccurrences->value();
}
const bool TaskScaledParameters::updateView() const
{
if (insideMultiTransform)
return parentTask->updateView();
else
return ui->checkBoxUpdateView->isChecked();
}
TaskScaledParameters::~TaskScaledParameters()
{

View File

@ -58,7 +58,6 @@ public:
const double getFactor(void) const;
const unsigned getOccurrences(void) const;
const bool updateView() const;
private Q_SLOTS:
void onFactor(const double f);

View File

@ -55,7 +55,7 @@ TaskTransformedParameters::TaskTransformedParameters(ViewProviderTransformed *Tr
TransformedView(TransformedView),
parentTask(NULL),
insideMultiTransform(false),
updateUIinProgress(false)
blockUpdate(false)
{
originalSelectionMode = false;
}
@ -65,7 +65,7 @@ TaskTransformedParameters::TaskTransformedParameters(TaskMultiTransformParameter
TransformedView(NULL),
parentTask(parentTask),
insideMultiTransform(true),
updateUIinProgress(false)
blockUpdate(false)
{
// Original feature selection makes no sense inside a MultiTransform
originalSelectionMode = false;
@ -73,22 +73,21 @@ TaskTransformedParameters::TaskTransformedParameters(TaskMultiTransformParameter
const bool TaskTransformedParameters::originalSelected(const Gui::SelectionChanges& msg)
{
if (originalSelectionMode && (msg.Type == Gui::SelectionChanges::AddSelection)) {
PartDesign::Transformed* pcTransformed = static_cast<PartDesign::Transformed*>(TransformedView->getObject());
App::DocumentObject* selectedObject = pcTransformed->getDocument()->getActiveObject();
if (!selectedObject->isDerivedFrom(PartDesign::Additive::getClassTypeId()) &&
!selectedObject->isDerivedFrom(PartDesign::Subtractive::getClassTypeId()))
return false;
if (TransformedView->getObject() == pcTransformed)
if (msg.Type == Gui::SelectionChanges::AddSelection && originalSelectionMode) {
if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0)
return false;
std::vector<App::DocumentObject*> originals = pcTransformed->Originals.getValues();
PartDesign::Transformed* pcTransformed = getObject();
App::DocumentObject* selectedObject = pcTransformed->getDocument()->getObject(msg.pObjectName);
if (selectedObject->isDerivedFrom(PartDesign::Additive::getClassTypeId()) ||
selectedObject->isDerivedFrom(PartDesign::Subtractive::getClassTypeId())) {
// Do the same like in TaskDlgTransformedParameters::accept() but without doCommand
std::vector<App::DocumentObject*> originals(1,selectedObject);
pcTransformed->Originals.setValues(originals);
recomputeFeature();
if (std::find(originals.begin(), originals.end(), selectedObject) == originals.end()) {
Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().%s.Originals = [App.activeDocument().%s]",
getObject()->getNameInDocument(),
selectedObject->getNameInDocument() );
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
originalSelectionMode = false;
return true;
}
@ -109,8 +108,9 @@ PartDesign::Transformed *TaskTransformedParameters::getObject() const
void TaskTransformedParameters::recomputeFeature()
{
if (insideMultiTransform) {
// redirect recompute and let the parent decide if recompute has to be blocked
parentTask->recomputeFeature();
} else {
} else if (!blockRecompute) {
PartDesign::Transformed* pcTransformed = static_cast<PartDesign::Transformed*>(TransformedView->getObject());
pcTransformed->getDocument()->recomputeFeature(pcTransformed);
}
@ -128,10 +128,10 @@ const std::vector<App::DocumentObject*> TaskTransformedParameters::getOriginals(
}
}
App::DocumentObject* TaskTransformedParameters::getOriginalObject() const
App::DocumentObject* TaskTransformedParameters::getSupportObject() const
{
if (insideMultiTransform) {
return parentTask->getOriginalObject();
return parentTask->getSupportObject();
} else {
PartDesign::Transformed* pcTransformed = static_cast<PartDesign::Transformed*>(TransformedView->getObject());
return pcTransformed->getOriginalObject();

View File

@ -59,6 +59,8 @@ public:
{}
const std::vector<App::DocumentObject*> getOriginals(void) const;
/// Get the support object either of the object associated with this feature or with the parent feature (MultiTransform mode)
App::DocumentObject* getSupportObject() const;
protected Q_SLOTS:
@ -71,8 +73,6 @@ protected:
/// Get the TransformedFeature object associated with this task
// Either through the ViewProvider or the currently active subFeature of the parentTask
PartDesign::Transformed *getObject() const;
/// Get the original object either of the object associated with this feature or with the parent feature (MultiTransform mode)
App::DocumentObject* getOriginalObject() const;
/// Recompute either this feature or the parent feature (MultiTransform mode)
void recomputeFeature();
@ -94,8 +94,10 @@ protected:
TaskMultiTransformParameters* parentTask;
/// Flag indicating whether this object is a container for MultiTransform
bool insideMultiTransform;
/// Lock updateUI() so that no unnecessary recomputeFeatures() are triggered
bool updateUIinProgress;
/// Lock updateUI() and applying changes to the underlying feature
bool blockUpdate;
/// Lock recomputeFeature()
bool blockRecompute;
};
/// simulation dialog for the TaskView