[PD] fix dressup feature display when broken
As discussed in https://forum.freecadweb.org/viewtopic.php?p=479647#p479377 the user can end up without either seeing nothing or an inexisting dressup feature. This PR fixes this.
This commit is contained in:
@@ -61,6 +61,7 @@
|
||||
#include <Mod/PartDesign/App/DatumPoint.h>
|
||||
#include <Mod/PartDesign/App/DatumLine.h>
|
||||
#include <Mod/PartDesign/App/DatumPlane.h>
|
||||
#include <Mod/PartDesign/App/FeatureDressUp.h>
|
||||
#include <Mod/PartDesign/App/ShapeBinder.h>
|
||||
|
||||
#include "TaskFeaturePick.h"
|
||||
@@ -1889,6 +1890,15 @@ void finishDressupFeature(const Gui::Command* cmd, const std::string& which,
|
||||
FCMD_OBJ_CMD(Feat,"Base = " << str.str());
|
||||
cmd->doCommand(cmd->Gui,"Gui.Selection.clearSelection()");
|
||||
finishFeature(cmd, Feat, base);
|
||||
|
||||
App::DocumentObject* baseFeature = static_cast<PartDesign::DressUp*>(Feat)->Base.getValue();
|
||||
if (baseFeature) {
|
||||
PartDesignGui::ViewProvider* view = dynamic_cast<PartDesignGui::ViewProvider*>(Gui::Application::Instance->getViewProvider(baseFeature));
|
||||
// in case there is an error, for example when a fillet is larger than the available space
|
||||
// display the base feature to avoid that the user sees nothing
|
||||
if (view && Feat->isError())
|
||||
view->Visibility.setValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
void makeChamferOrFillet(Gui::Command* cmd, const std::string& which)
|
||||
|
||||
@@ -102,6 +102,9 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q
|
||||
this, SLOT(setSelection(QListWidgetItem*)));
|
||||
connect(ui->listWidgetReferences, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(doubleClicked(QListWidgetItem*)));
|
||||
|
||||
// the dialog can be called on a broken chamfer, then hide the chamfer
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
void TaskChamferParameters::setUpUI(PartDesign::Chamfer* pcChamfer)
|
||||
@@ -231,6 +234,8 @@ void TaskChamferParameters::onRefDeleted(void)
|
||||
pcChamfer->Base.setValue(base, refs);
|
||||
// recompute the feature
|
||||
pcChamfer->recomputeFeature();
|
||||
// hide the chamfer if there was a computation error
|
||||
hideOnError();
|
||||
|
||||
// if there is only one item left, it cannot be deleted
|
||||
if (ui->listWidgetReferences->count() == 1) {
|
||||
@@ -248,6 +253,8 @@ void TaskChamferParameters::onTypeChanged(int index)
|
||||
ui->stackedWidget->setCurrentIndex(index);
|
||||
ui->flipDirection->setEnabled(index != 0); // Enable if type is not "Equal distance"
|
||||
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
|
||||
// hide the chamfer if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
void TaskChamferParameters::onSizeChanged(double len)
|
||||
@@ -256,6 +263,8 @@ void TaskChamferParameters::onSizeChanged(double len)
|
||||
setupTransaction();
|
||||
pcChamfer->Size.setValue(len);
|
||||
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
|
||||
// hide the chamfer if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
void TaskChamferParameters::onSize2Changed(double len)
|
||||
@@ -264,6 +273,8 @@ void TaskChamferParameters::onSize2Changed(double len)
|
||||
setupTransaction();
|
||||
pcChamfer->Size2.setValue(len);
|
||||
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
|
||||
// hide the chamfer if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
void TaskChamferParameters::onAngleChanged(double angle)
|
||||
@@ -272,6 +283,8 @@ void TaskChamferParameters::onAngleChanged(double angle)
|
||||
setupTransaction();
|
||||
pcChamfer->Angle.setValue(angle);
|
||||
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
|
||||
// hide the chamfer if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
void TaskChamferParameters::onFlipDirection(bool flip)
|
||||
@@ -280,6 +293,8 @@ void TaskChamferParameters::onFlipDirection(bool flip)
|
||||
setupTransaction();
|
||||
pcChamfer->FlipDirection.setValue(flip);
|
||||
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
|
||||
// hide the chamfer if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
int TaskChamferParameters::getType(void) const
|
||||
@@ -389,7 +404,6 @@ TaskDlgChamferParameters::~TaskDlgChamferParameters()
|
||||
//}
|
||||
bool TaskDlgChamferParameters::accept()
|
||||
{
|
||||
parameter->showObject();
|
||||
parameter->apply();
|
||||
|
||||
return TaskDlgDressUpParameters::accept();
|
||||
|
||||
@@ -118,6 +118,9 @@ TaskDraftParameters::TaskDraftParameters(ViewProviderDressUp *DressUpView, QWidg
|
||||
ref = pcDraft->PullDirection.getValue();
|
||||
strings = pcDraft->PullDirection.getSubValues();
|
||||
ui->lineLine->setText(getRefStr(ref, strings));
|
||||
|
||||
// the dialog can be called on a broken draft, then hide the draft
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
@@ -171,6 +174,8 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
// highlight existing references for possible further selections
|
||||
DressUpView->highlightReferences(true);
|
||||
// hide the draft if there was a computation error
|
||||
hideOnError();
|
||||
} else if (selectionMode == line) {
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
|
||||
std::vector<std::string> edges;
|
||||
@@ -185,6 +190,8 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
// highlight existing references for possible further selections
|
||||
DressUpView->highlightReferences(true);
|
||||
// hide the draft if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,6 +267,8 @@ void TaskDraftParameters::onRefDeleted(void)
|
||||
pcDraft->Base.setValue(base, refs);
|
||||
// recompute the feature
|
||||
pcDraft->recomputeFeature();
|
||||
// hide the draft if there was a computation error
|
||||
hideOnError();
|
||||
|
||||
// if there is only one item left, it cannot be deleted
|
||||
if (ui->listWidgetReferences->count() == 1) {
|
||||
@@ -295,6 +304,8 @@ void TaskDraftParameters::onAngleChanged(double angle)
|
||||
setupTransaction();
|
||||
pcDraft->Angle.setValue(angle);
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
// hide the draft if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
double TaskDraftParameters::getAngle(void) const
|
||||
@@ -308,6 +319,8 @@ void TaskDraftParameters::onReversedChanged(const bool on) {
|
||||
setupTransaction();
|
||||
pcDraft->Reversed.setValue(on);
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
// hide the draft if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
bool TaskDraftParameters::getReversed(void) const
|
||||
@@ -373,8 +386,6 @@ TaskDlgDraftParameters::~TaskDlgDraftParameters()
|
||||
|
||||
bool TaskDlgDraftParameters::accept()
|
||||
{
|
||||
parameter->showObject();
|
||||
|
||||
std::vector<std::string> strings;
|
||||
App::DocumentObject* obj;
|
||||
TaskDraftParameters* draftparameter = static_cast<TaskDraftParameters*>(parameter);
|
||||
|
||||
@@ -291,6 +291,15 @@ void TaskDressUpParameters::removeItemFromListWidget(QListWidget* widget, const
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDressUpParameters::hideOnError()
|
||||
{
|
||||
App::DocumentObject* dressup = DressUpView->getObject();
|
||||
if (dressup->isError())
|
||||
hideObject();
|
||||
else
|
||||
showObject();
|
||||
}
|
||||
|
||||
void TaskDressUpParameters::hideObject()
|
||||
{
|
||||
App::DocumentObject* base = getBase();
|
||||
|
||||
@@ -77,6 +77,7 @@ protected:
|
||||
bool referenceSelected(const Gui::SelectionChanges& msg);
|
||||
bool wasDoubleClicked = false;
|
||||
bool KeyEvent(QEvent *e);
|
||||
void hideOnError();
|
||||
|
||||
protected:
|
||||
enum selectionModes { none, refAdd, refRemove, plane, line };
|
||||
|
||||
@@ -96,6 +96,9 @@ TaskFilletParameters::TaskFilletParameters(ViewProviderDressUp *DressUpView, QWi
|
||||
this, SLOT(setSelection(QListWidgetItem*)));
|
||||
connect(ui->listWidgetReferences, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(doubleClicked(QListWidgetItem*)));
|
||||
|
||||
// the dialog can be called on a broken fillet, then hide the fillet
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
void TaskFilletParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
@@ -186,6 +189,8 @@ void TaskFilletParameters::onRefDeleted(void)
|
||||
pcFillet->Base.setValue(base, refs);
|
||||
// recompute the feature
|
||||
pcFillet->recomputeFeature();
|
||||
// hide the fillet if there was a computation error
|
||||
hideOnError();
|
||||
|
||||
// if there is only one item left, it cannot be deleted
|
||||
if (ui->listWidgetReferences->count() == 1) {
|
||||
@@ -203,6 +208,8 @@ void TaskFilletParameters::onLengthChanged(double len)
|
||||
setupTransaction();
|
||||
pcFillet->Radius.setValue(len);
|
||||
pcFillet->getDocument()->recomputeFeature(pcFillet);
|
||||
// hide the fillet if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
double TaskFilletParameters::getLength(void) const
|
||||
@@ -274,7 +281,6 @@ TaskDlgFilletParameters::~TaskDlgFilletParameters()
|
||||
//}
|
||||
bool TaskDlgFilletParameters::accept()
|
||||
{
|
||||
parameter->showObject();
|
||||
parameter->apply();
|
||||
|
||||
return TaskDlgDressUpParameters::accept();
|
||||
|
||||
@@ -118,6 +118,9 @@ TaskThicknessParameters::TaskThicknessParameters(ViewProviderDressUp *DressUpVie
|
||||
|
||||
int join = pcThickness->Join.getValue();
|
||||
ui->joinComboBox->setCurrentIndex(join);
|
||||
|
||||
// the dialog can be called on a broken thickness, then hide the thickness
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
void TaskThicknessParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
@@ -208,6 +211,8 @@ void TaskThicknessParameters::onRefDeleted(void)
|
||||
pcThickness->Base.setValue(base, refs);
|
||||
// recompute the feature
|
||||
pcThickness->recomputeFeature();
|
||||
// hide the thickness if there was a computation error
|
||||
hideOnError();
|
||||
|
||||
// if there is only one item left, it cannot be deleted
|
||||
if (ui->listWidgetReferences->count() == 1) {
|
||||
@@ -225,6 +230,8 @@ void TaskThicknessParameters::onValueChanged(double angle)
|
||||
setupTransaction();
|
||||
pcThickness->Value.setValue(angle);
|
||||
pcThickness->getDocument()->recomputeFeature(pcThickness);
|
||||
// hide the thickness if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
void TaskThicknessParameters::onJoinTypeChanged(int join) {
|
||||
@@ -234,6 +241,8 @@ void TaskThicknessParameters::onJoinTypeChanged(int join) {
|
||||
setupTransaction();
|
||||
pcThickness->Join.setValue(join);
|
||||
pcThickness->getDocument()->recomputeFeature(pcThickness);
|
||||
// hide the thickness if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
void TaskThicknessParameters::onModeChanged(int mode) {
|
||||
@@ -243,6 +252,8 @@ void TaskThicknessParameters::onModeChanged(int mode) {
|
||||
setupTransaction();
|
||||
pcThickness->Mode.setValue(mode);
|
||||
pcThickness->getDocument()->recomputeFeature(pcThickness);
|
||||
// hide the thickness if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
double TaskThicknessParameters::getValue(void) const
|
||||
@@ -256,6 +267,8 @@ void TaskThicknessParameters::onReversedChanged(const bool on) {
|
||||
setupTransaction();
|
||||
pcThickness->Reversed.setValue(on);
|
||||
pcThickness->getDocument()->recomputeFeature(pcThickness);
|
||||
// hide the thickness if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
bool TaskThicknessParameters::getReversed(void) const
|
||||
@@ -268,6 +281,8 @@ void TaskThicknessParameters::onIntersectionChanged(const bool on) {
|
||||
PartDesign::Thickness* pcThickness = static_cast<PartDesign::Thickness*>(DressUpView->getObject());
|
||||
pcThickness->Intersection.setValue(on);
|
||||
pcThickness->getDocument()->recomputeFeature(pcThickness);
|
||||
// hide the thickness if there was a computation error
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
bool TaskThicknessParameters::getIntersection(void) const
|
||||
@@ -285,7 +300,6 @@ int TaskThicknessParameters::getMode(void) const {
|
||||
return ui->modeComboBox->currentIndex();
|
||||
}
|
||||
|
||||
|
||||
TaskThicknessParameters::~TaskThicknessParameters()
|
||||
{
|
||||
try {
|
||||
@@ -349,8 +363,6 @@ TaskDlgThicknessParameters::~TaskDlgThicknessParameters()
|
||||
|
||||
bool TaskDlgThicknessParameters::accept()
|
||||
{
|
||||
parameter->showObject();
|
||||
|
||||
TaskThicknessParameters* draftparameter = static_cast<TaskThicknessParameters*>(parameter);
|
||||
|
||||
auto obj = vp->getObject();
|
||||
|
||||
Reference in New Issue
Block a user