PartDesign: Refactor pattern features and gui
- remove StdDirection,StdAxis and StdMirrorPlane properties - support sketch H_Axis, V_Axis, N_axis as valid references in patterns - polish reference selection gui (unified for standard axes and custom references)
This commit is contained in:
@@ -93,14 +93,8 @@ TaskMirroredParameters::TaskMirroredParameters(TaskMultiTransformParameters *par
|
||||
|
||||
void TaskMirroredParameters::setupUI()
|
||||
{
|
||||
connect(ui->buttonXY, SIGNAL(pressed()),
|
||||
this, SLOT(onButtonXY()));
|
||||
connect(ui->buttonXZ, SIGNAL(pressed()),
|
||||
this, SLOT(onButtonXZ()));
|
||||
connect(ui->buttonYZ, SIGNAL(pressed()),
|
||||
this, SLOT(onButtonYZ()));
|
||||
connect(ui->buttonReference, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onButtonReference(bool)));
|
||||
connect(ui->comboPlane, SIGNAL(activated(int)),
|
||||
this, SLOT(onPlaneChanged(int)));
|
||||
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onUpdateView(bool)));
|
||||
|
||||
@@ -119,11 +113,7 @@ void TaskMirroredParameters::setupUI()
|
||||
}
|
||||
// ---------------------
|
||||
|
||||
ui->buttonXY->setEnabled(true);
|
||||
ui->buttonXZ->setEnabled(true);
|
||||
ui->buttonYZ->setEnabled(true);
|
||||
ui->buttonReference->setEnabled(true);
|
||||
ui->lineReference->setEnabled(false); // This is never enabled since it is for optical feed-back only
|
||||
ui->comboPlane->setEnabled(true);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
@@ -132,35 +122,33 @@ void TaskMirroredParameters::updateUI()
|
||||
if (blockUpdate)
|
||||
return;
|
||||
blockUpdate = true;
|
||||
|
||||
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
|
||||
|
||||
App::DocumentObject* mirrorPlaneFeature = pcMirrored->MirrorPlane.getValue();
|
||||
std::vector<std::string> mirrorPlanes = pcMirrored->MirrorPlane.getSubValues();
|
||||
std::string stdMirrorPlane = pcMirrored->StdMirrorPlane.getValue();
|
||||
|
||||
for (int i=ui->comboPlane->count()-1; i >= 2; i--)
|
||||
ui->comboPlane->removeItem(i);
|
||||
|
||||
ui->buttonReference->setChecked(referenceSelectionMode);
|
||||
if (!stdMirrorPlane.empty())
|
||||
{
|
||||
ui->buttonXY->setAutoExclusive(true);
|
||||
ui->buttonXZ->setAutoExclusive(true);
|
||||
ui->buttonYZ->setAutoExclusive(true);
|
||||
ui->buttonXY->setChecked(stdMirrorPlane == "XY");
|
||||
ui->buttonXZ->setChecked(stdMirrorPlane == "XZ");
|
||||
ui->buttonYZ->setChecked(stdMirrorPlane == "YZ");
|
||||
ui->lineReference->setText(tr(""));
|
||||
} else if (mirrorPlaneFeature != NULL && !mirrorPlanes.empty()) {
|
||||
ui->buttonXY->setAutoExclusive(false);
|
||||
ui->buttonXZ->setAutoExclusive(false);
|
||||
ui->buttonYZ->setAutoExclusive(false);
|
||||
ui->buttonXY->setChecked(false);
|
||||
ui->buttonXZ->setChecked(false);
|
||||
ui->buttonYZ->setChecked(false);
|
||||
ui->lineReference->setText(QString::fromAscii(mirrorPlanes.front().c_str()));
|
||||
if (mirrorPlaneFeature != NULL && !mirrorPlanes.empty()) {
|
||||
if (mirrorPlanes.front() == "H_Axis")
|
||||
ui->comboPlane->setCurrentIndex(0);
|
||||
else if (mirrorPlanes.front() == "V_Axis")
|
||||
ui->comboPlane->setCurrentIndex(1);
|
||||
else if (mirrorPlaneFeature != NULL && !mirrorPlanes.empty()) {
|
||||
ui->comboPlane->addItem(QString::fromAscii(mirrorPlanes.front().c_str()));
|
||||
ui->comboPlane->setCurrentIndex(2);
|
||||
}
|
||||
} else {
|
||||
// Error message?
|
||||
ui->lineReference->setText(tr(""));
|
||||
}
|
||||
if (referenceSelectionMode)
|
||||
ui->lineReference->setText(tr("Select a plane"));
|
||||
|
||||
if (referenceSelectionMode) {
|
||||
ui->comboPlane->addItem(tr("Select a face"));
|
||||
ui->comboPlane->setCurrentIndex(ui->comboPlane->count() - 1);
|
||||
} else
|
||||
ui->comboPlane->addItem(tr("Select reference..."));
|
||||
|
||||
blockUpdate = false;
|
||||
}
|
||||
@@ -186,55 +174,48 @@ void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg
|
||||
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()));
|
||||
for (int i=ui->comboPlane->count()-1; i >= 2; i--)
|
||||
ui->comboPlane->removeItem(i);
|
||||
|
||||
ui->comboPlane->addItem(QString::fromAscii(subName.c_str()));
|
||||
ui->comboPlane->setCurrentIndex(2);
|
||||
ui->comboPlane->addItem(tr("Select reference..."));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TaskMirroredParameters::onStdMirrorPlane(const std::string &plane) {
|
||||
void TaskMirroredParameters::onPlaneChanged(int num) {
|
||||
if (blockUpdate)
|
||||
return;
|
||||
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
|
||||
pcMirrored->StdMirrorPlane.setValue(plane.c_str());
|
||||
pcMirrored->MirrorPlane.setValue(NULL);
|
||||
|
||||
exitSelectionMode();
|
||||
updateUI();
|
||||
recomputeFeature();
|
||||
}
|
||||
|
||||
void TaskMirroredParameters::onButtonXY() {
|
||||
onStdMirrorPlane("XY");
|
||||
}
|
||||
|
||||
void TaskMirroredParameters::onButtonXZ() {
|
||||
onStdMirrorPlane("XZ");
|
||||
}
|
||||
|
||||
void TaskMirroredParameters::onButtonYZ() {
|
||||
onStdMirrorPlane("YZ");
|
||||
}
|
||||
|
||||
void TaskMirroredParameters::onButtonReference(bool checked)
|
||||
{
|
||||
if (checked ) {
|
||||
if (num == 0) {
|
||||
pcMirrored->MirrorPlane.setValue(getSketchObject(), std::vector<std::string>(1,"H_Axis"));
|
||||
exitSelectionMode();
|
||||
}
|
||||
else if (num == 1) {
|
||||
pcMirrored->MirrorPlane.setValue(getSketchObject(), std::vector<std::string>(1,"V_Axis"));
|
||||
exitSelectionMode();
|
||||
}
|
||||
else if (num == ui->comboPlane->count() - 1) {
|
||||
// enter reference selection mode
|
||||
hideObject();
|
||||
showOriginals();
|
||||
referenceSelectionMode = true;
|
||||
Gui::Selection().clearSelection();
|
||||
addReferenceSelectionGate(false, true);
|
||||
} else {
|
||||
exitSelectionMode();
|
||||
}
|
||||
else if (num == 2)
|
||||
exitSelectionMode();
|
||||
|
||||
updateUI();
|
||||
recomputeFeature();
|
||||
}
|
||||
|
||||
void TaskMirroredParameters::onUpdateView(bool on)
|
||||
@@ -247,37 +228,28 @@ void TaskMirroredParameters::onUpdateView(bool on)
|
||||
std::string mirrorPlane = getMirrorPlane();
|
||||
if (!mirrorPlane.empty()) {
|
||||
std::vector<std::string> planes(1,mirrorPlane);
|
||||
pcMirrored->MirrorPlane.setValue(getSupportObject(),planes);
|
||||
if (mirrorPlane == "H_Axis" || mirrorPlane == "V_Axis")
|
||||
pcMirrored->MirrorPlane.setValue(getSketchObject(),planes);
|
||||
else
|
||||
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
|
||||
{
|
||||
if (ui->buttonXY->isChecked())
|
||||
return std::string("XY");
|
||||
else if (ui->buttonYZ->isChecked())
|
||||
return std::string("YZ");
|
||||
else if (ui->buttonXZ->isChecked())
|
||||
return std::string("XZ");
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
const std::string TaskMirroredParameters::getMirrorPlane(void) const
|
||||
{
|
||||
return ui->lineReference->text().toStdString();
|
||||
if (ui->comboPlane->currentIndex() == 0)
|
||||
return "H_Axis";
|
||||
else if (ui->comboPlane->currentIndex() == 1)
|
||||
return "V_Axis";
|
||||
else if (ui->comboPlane->count() > 3 && ui->comboPlane->currentIndex() == 2)
|
||||
return ui->comboPlane->currentText().toStdString();
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
|
||||
TaskMirroredParameters::~TaskMirroredParameters()
|
||||
{
|
||||
delete ui;
|
||||
@@ -321,13 +293,14 @@ bool TaskDlgMirroredParameters::accept()
|
||||
std::string mirrorPlane = mirrorParameter->getMirrorPlane();
|
||||
if (!mirrorPlane.empty()) {
|
||||
QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
|
||||
buf = buf.arg(QString::fromUtf8(mirrorParameter->getSupportObject()->getNameInDocument()));
|
||||
if (mirrorPlane == "H_Axis" || mirrorPlane == "V_Axis")
|
||||
buf = buf.arg(QString::fromUtf8(mirrorParameter->getSketchObject()->getNameInDocument()));
|
||||
else
|
||||
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();
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user