PartDesign, 758, 766, 773, 775: several improvements, fixes and code refactoring for Pad and Pocket
This commit is contained in:
@@ -25,9 +25,10 @@
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
# include <QMessageBox>
|
||||
# include <QRegExp>
|
||||
# include <QTextStream>
|
||||
# include <QMessageBox>
|
||||
# include <Precision.hxx>
|
||||
#endif
|
||||
|
||||
#include "ui_TaskPadParameters.h"
|
||||
@@ -44,7 +45,7 @@
|
||||
#include <Gui/Command.h>
|
||||
#include <Mod/PartDesign/App/FeaturePad.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
|
||||
#include "ReferenceSelection.h"
|
||||
|
||||
using namespace PartDesignGui;
|
||||
using namespace Gui;
|
||||
@@ -70,6 +71,8 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
|
||||
this, SLOT(onLength2Changed(double)));
|
||||
connect(ui->changeMode, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(onModeChanged(int)));
|
||||
connect(ui->buttonFace, SIGNAL(pressed()),
|
||||
this, SLOT(onButtonFace()));
|
||||
connect(ui->lineFaceName, SIGNAL(textEdited(QString)),
|
||||
this, SLOT(onFaceName(QString)));
|
||||
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
|
||||
@@ -77,6 +80,15 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
|
||||
|
||||
this->groupLayout()->addWidget(proxy);
|
||||
|
||||
// Temporarily prevent unnecessary feature recomputes
|
||||
ui->doubleSpinBox->blockSignals(true);
|
||||
ui->doubleSpinBox2->blockSignals(true);
|
||||
ui->checkBoxMidplane->blockSignals(true);
|
||||
ui->checkBoxReversed->blockSignals(true);
|
||||
ui->buttonFace->blockSignals(true);
|
||||
ui->lineFaceName->blockSignals(true);
|
||||
ui->changeMode->blockSignals(true);
|
||||
|
||||
// Get the feature data
|
||||
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
|
||||
double l = pcPad->Length.getValue();
|
||||
@@ -84,7 +96,14 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
|
||||
bool reversed = pcPad->Reversed.getValue();
|
||||
double l2 = pcPad->Length2.getValue();
|
||||
int index = pcPad->Type.getValue(); // must extract value here, clear() kills it!
|
||||
const char* upToFace = pcPad->FaceName.getValue();
|
||||
std::vector<std::string> subStrings = pcPad->UpToFace.getSubValues();
|
||||
std::string upToFace;
|
||||
int faceId = -1;
|
||||
if (!subStrings.empty()) {
|
||||
upToFace = subStrings.front();
|
||||
if (upToFace.substr(0,4) == "Face")
|
||||
faceId = std::atoi(&upToFace[4]);
|
||||
}
|
||||
|
||||
// Fill data into dialog elements
|
||||
ui->doubleSpinBox->setMinimum(0);
|
||||
@@ -97,8 +116,10 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
|
||||
// According to bug #0000521 the reversed option
|
||||
// shouldn't be de-activated if the pad has a support face
|
||||
ui->checkBoxReversed->setChecked(reversed);
|
||||
ui->lineFaceName->setText(pcPad->FaceName.isEmpty() ? tr("No face selected") : tr(upToFace));
|
||||
ui->lineFaceName->setProperty("FaceName", QByteArray(upToFace));
|
||||
ui->lineFaceName->setText(faceId >= 0 ?
|
||||
tr("Face") + QString::number(faceId) :
|
||||
tr("No face selected"));
|
||||
ui->lineFaceName->setProperty("FaceName", QByteArray(upToFace.c_str()));
|
||||
ui->changeMode->clear();
|
||||
ui->changeMode->insertItem(0, tr("Dimension"));
|
||||
ui->changeMode->insertItem(1, tr("To last"));
|
||||
@@ -108,6 +129,13 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
|
||||
ui->changeMode->setCurrentIndex(index);
|
||||
|
||||
// activate and de-activate dialog elements as appropriate
|
||||
ui->doubleSpinBox->blockSignals(false);
|
||||
ui->doubleSpinBox2->blockSignals(false);
|
||||
ui->checkBoxMidplane->blockSignals(false);
|
||||
ui->checkBoxReversed->blockSignals(false);
|
||||
ui->buttonFace->blockSignals(false);
|
||||
ui->lineFaceName->blockSignals(false);
|
||||
ui->changeMode->blockSignals(false);
|
||||
updateUI(index);
|
||||
}
|
||||
|
||||
@@ -121,22 +149,31 @@ void TaskPadParameters::updateUI(int index)
|
||||
// yet visible.
|
||||
QMetaObject::invokeMethod(ui->doubleSpinBox, "setFocus", Qt::QueuedConnection);
|
||||
ui->checkBoxMidplane->setEnabled(true);
|
||||
ui->checkBoxReversed->setEnabled(true);
|
||||
// Reverse only makes sense if Midplane is not true
|
||||
ui->checkBoxReversed->setEnabled(!ui->checkBoxMidplane->isChecked());
|
||||
ui->doubleSpinBox2->setEnabled(false);
|
||||
ui->buttonFace->setEnabled(false);
|
||||
ui->lineFaceName->setEnabled(false);
|
||||
} else if ((index == 1) || (index == 2)) { // up to first/last
|
||||
onButtonFace(false);
|
||||
} else if (index == 1 || index == 2) { // up to first/last
|
||||
ui->doubleSpinBox->setEnabled(false);
|
||||
ui->checkBoxMidplane->setEnabled(false);
|
||||
ui->checkBoxReversed->setEnabled(false);
|
||||
ui->doubleSpinBox2->setEnabled(false);
|
||||
ui->buttonFace->setEnabled(false);
|
||||
ui->lineFaceName->setEnabled(false);
|
||||
onButtonFace(false);
|
||||
} else if (index == 3) { // up to face
|
||||
ui->doubleSpinBox->setEnabled(false);
|
||||
ui->checkBoxMidplane->setEnabled(false);
|
||||
ui->checkBoxReversed->setEnabled(false);
|
||||
ui->doubleSpinBox2->setEnabled(false);
|
||||
ui->buttonFace->setEnabled(true);
|
||||
ui->lineFaceName->setEnabled(true);
|
||||
QMetaObject::invokeMethod(ui->lineFaceName, "setFocus", Qt::QueuedConnection);
|
||||
// Go into reference selection mode if no face has been selected yet
|
||||
if (ui->lineFaceName->text().isEmpty())
|
||||
onButtonFace(true);
|
||||
} else { // two dimensions
|
||||
ui->doubleSpinBox->setEnabled(true);
|
||||
ui->doubleSpinBox->selectAll();
|
||||
@@ -144,70 +181,88 @@ void TaskPadParameters::updateUI(int index)
|
||||
ui->checkBoxMidplane->setEnabled(false);
|
||||
ui->checkBoxReversed->setEnabled(false);
|
||||
ui->doubleSpinBox2->setEnabled(true);
|
||||
ui->buttonFace->setEnabled(false);
|
||||
ui->lineFaceName->setEnabled(false);
|
||||
onButtonFace(false);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskPadParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
{
|
||||
if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
||||
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
|
||||
if (pcPad->Type.getValue() != 3) // ignore user selections if mode is not upToFace
|
||||
// Don't allow selection in other document
|
||||
if (strcmp(msg.pDocName, PadView->getObject()->getDocument()->getName()) != 0)
|
||||
return;
|
||||
|
||||
if (!msg.pSubName || msg.pSubName[0] == '\0')
|
||||
return;
|
||||
std::string element(msg.pSubName);
|
||||
if (element.substr(0,4) != "Face")
|
||||
std::string subName(msg.pSubName);
|
||||
if (subName.substr(0,4) != "Face")
|
||||
return;
|
||||
int faceId = std::atoi(&subName[4]);
|
||||
|
||||
int index=std::atoi(&element[4]);
|
||||
pcPad->FaceName.setValue(element);
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
ui->lineFaceName->setText(tr("Face") + QString::number(index));
|
||||
ui->lineFaceName->setProperty("FaceName", QByteArray(element.c_str()));
|
||||
// Don't allow selection outside support
|
||||
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
|
||||
Part::Feature* support = pcPad->getSupport();
|
||||
if (support == NULL) {
|
||||
// There is no support, so we can't select from it...
|
||||
// Turn off reference selection mode
|
||||
onButtonFace(false);
|
||||
return;
|
||||
}
|
||||
if (strcmp(msg.pObjectName, support->getNameInDocument()) != 0)
|
||||
return;
|
||||
|
||||
std::vector<std::string> upToFaces(1,subName);
|
||||
pcPad->UpToFace.setValue(support, upToFaces);
|
||||
if (updateView())
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
ui->lineFaceName->blockSignals(true);
|
||||
ui->lineFaceName->setText(tr("Face") + QString::number(faceId));
|
||||
ui->lineFaceName->setProperty("FaceName", QByteArray(subName.c_str()));
|
||||
ui->lineFaceName->blockSignals(false);
|
||||
// Turn off reference selection mode
|
||||
onButtonFace(false);
|
||||
}
|
||||
else if (msg.Type == Gui::SelectionChanges::ClrSelection) {
|
||||
ui->lineFaceName->blockSignals(true);
|
||||
ui->lineFaceName->setText(tr("No face selected"));
|
||||
ui->lineFaceName->setProperty("FaceName", QByteArray());
|
||||
ui->lineFaceName->blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskPadParameters::onUpdateView(bool on)
|
||||
{
|
||||
ui->changeMode->blockSignals(!on);
|
||||
ui->doubleSpinBox->blockSignals(!on);
|
||||
ui->checkBoxMidplane->blockSignals(!on);
|
||||
ui->checkBoxReversed->blockSignals(!on);
|
||||
ui->doubleSpinBox2->blockSignals(!on);
|
||||
}
|
||||
|
||||
void TaskPadParameters::onLengthChanged(double len)
|
||||
{
|
||||
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
|
||||
pcPad->Length.setValue((float)len);
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
if (updateView())
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
}
|
||||
|
||||
void TaskPadParameters::onMidplane(bool on)
|
||||
{
|
||||
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
|
||||
pcPad->Midplane.setValue(on);
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
ui->checkBoxReversed->setEnabled(!on);
|
||||
if (updateView())
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
}
|
||||
|
||||
void TaskPadParameters::onReversed(bool on)
|
||||
{
|
||||
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
|
||||
pcPad->Reversed.setValue(on);
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
if (updateView())
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
}
|
||||
|
||||
void TaskPadParameters::onLength2Changed(double len)
|
||||
{
|
||||
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
|
||||
pcPad->Length2.setValue((float)len);
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
if (updateView())
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
}
|
||||
|
||||
void TaskPadParameters::onModeChanged(int index)
|
||||
@@ -215,7 +270,12 @@ void TaskPadParameters::onModeChanged(int index)
|
||||
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
|
||||
|
||||
switch (index) {
|
||||
case 0: pcPad->Type.setValue("Length"); break;
|
||||
case 0:
|
||||
pcPad->Type.setValue("Length");
|
||||
// Avoid error message
|
||||
if (ui->doubleSpinBox->value() < Precision::Confusion())
|
||||
ui->doubleSpinBox->setValue(5.0);
|
||||
break;
|
||||
case 1: pcPad->Type.setValue("UpToLast"); break;
|
||||
case 2: pcPad->Type.setValue("UpToFirst"); break;
|
||||
case 3: pcPad->Type.setValue("UpToFace"); break;
|
||||
@@ -224,7 +284,38 @@ void TaskPadParameters::onModeChanged(int index)
|
||||
|
||||
updateUI(index);
|
||||
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
if (updateView())
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
}
|
||||
|
||||
void TaskPadParameters::onButtonFace(const bool pressed) {
|
||||
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
|
||||
Part::Feature* support = pcPad->getSupport();
|
||||
if (support == NULL) {
|
||||
// There is no support, so we can't select from it...
|
||||
return;
|
||||
}
|
||||
|
||||
if (pressed) {
|
||||
Gui::Document* doc = Gui::Application::Instance->activeDocument();
|
||||
if (doc) {
|
||||
doc->setHide(PadView->getObject()->getNameInDocument());
|
||||
doc->setShow(support->getNameInDocument());
|
||||
}
|
||||
Gui::Selection().clearSelection();
|
||||
Gui::Selection().addSelectionGate
|
||||
(new ReferenceSelection(support, false, true, false));
|
||||
} else {
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
Gui::Document* doc = Gui::Application::Instance->activeDocument();
|
||||
if (doc) {
|
||||
doc->setShow(PadView->getObject()->getNameInDocument());
|
||||
doc->setHide(support->getNameInDocument());
|
||||
}
|
||||
}
|
||||
|
||||
// Update button if onButtonFace() is called explicitly
|
||||
ui->buttonFace->setChecked(pressed);
|
||||
}
|
||||
|
||||
void TaskPadParameters::onFaceName(const QString& text)
|
||||
@@ -239,14 +330,29 @@ void TaskPadParameters::onFaceName(const QString& text)
|
||||
return;
|
||||
}
|
||||
|
||||
int index = rx.cap(1).toInt();
|
||||
int faceId = rx.cap(1).toInt();
|
||||
std::stringstream ss;
|
||||
ss << "Face" << index;
|
||||
ss << "Face" << faceId;
|
||||
ui->lineFaceName->setProperty("FaceName", QByteArray(ss.str().c_str()));
|
||||
|
||||
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
|
||||
pcPad->FaceName.setValue(ss.str().c_str());
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
Part::Feature* support = pcPad->getSupport();
|
||||
if (support == NULL) {
|
||||
// There is no support, so we can't select from it...
|
||||
return;
|
||||
}
|
||||
std::vector<std::string> upToFaces(1,ss.str());
|
||||
pcPad->UpToFace.setValue(support, upToFaces);
|
||||
if (updateView())
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
}
|
||||
|
||||
void TaskPadParameters::onUpdateView(bool on)
|
||||
{
|
||||
if (on) {
|
||||
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
|
||||
pcPad->getDocument()->recomputeFeature(pcPad);
|
||||
}
|
||||
}
|
||||
|
||||
double TaskPadParameters::getLength(void) const
|
||||
@@ -279,6 +385,11 @@ QByteArray TaskPadParameters::getFaceName(void) const
|
||||
return ui->lineFaceName->property("FaceName").toByteArray();
|
||||
}
|
||||
|
||||
const bool TaskPadParameters::updateView() const
|
||||
{
|
||||
return ui->checkBoxUpdateView->isChecked();
|
||||
}
|
||||
|
||||
TaskPadParameters::~TaskPadParameters()
|
||||
{
|
||||
delete ui;
|
||||
@@ -335,7 +446,17 @@ bool TaskDlgPadParameters::accept()
|
||||
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());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.FaceName = \"%s\"",name.c_str(),parameter->getFaceName().data());
|
||||
const char* facename = parameter->getFaceName().data();
|
||||
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
|
||||
Part::Feature* support = pcPad->getSupport();
|
||||
|
||||
if (support != NULL && facename && facename[0] != '\0') {
|
||||
QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
|
||||
buf = buf.arg(QString::fromUtf8(support->getNameInDocument()));
|
||||
buf = buf.arg(QString::fromUtf8(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());
|
||||
@@ -361,7 +482,7 @@ bool TaskDlgPadParameters::reject()
|
||||
pcSupport = pcSketch->Support.getValue();
|
||||
}
|
||||
|
||||
// role back the done things
|
||||
// roll back the done things
|
||||
Gui::Command::abortCommand();
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user