Skip to content

Commit

Permalink
[PD] fix dressup feature display when broken
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
donovaly authored and wwmayer committed Feb 19, 2021
1 parent c107ca3 commit e0d0725
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/Mod/PartDesign/Gui/Command.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 15 additions & 1 deletion src/Mod/PartDesign/Gui/TaskChamferParameters.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -389,7 +404,6 @@ TaskDlgChamferParameters::~TaskDlgChamferParameters()
//}
bool TaskDlgChamferParameters::accept()
{
parameter->showObject();
parameter->apply();

return TaskDlgDressUpParameters::accept();
Expand Down
15 changes: 13 additions & 2 deletions src/Mod/PartDesign/Gui/TaskDraftParameters.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/Mod/PartDesign/Gui/TaskDressUpParameters.h
Expand Up @@ -77,6 +77,7 @@ protected Q_SLOTS:
bool referenceSelected(const Gui::SelectionChanges& msg);
bool wasDoubleClicked = false;
bool KeyEvent(QEvent *e);
void hideOnError();

protected:
enum selectionModes { none, refAdd, refRemove, plane, line };
Expand Down
8 changes: 7 additions & 1 deletion src/Mod/PartDesign/Gui/TaskFilletParameters.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -274,7 +281,6 @@ TaskDlgFilletParameters::~TaskDlgFilletParameters()
//}
bool TaskDlgFilletParameters::accept()
{
parameter->showObject();
parameter->apply();

return TaskDlgDressUpParameters::accept();
Expand Down
18 changes: 15 additions & 3 deletions src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -285,7 +300,6 @@ int TaskThicknessParameters::getMode(void) const {
return ui->modeComboBox->currentIndex();
}


TaskThicknessParameters::~TaskThicknessParameters()
{
try {
Expand Down Expand Up @@ -349,8 +363,6 @@ TaskDlgThicknessParameters::~TaskDlgThicknessParameters()

bool TaskDlgThicknessParameters::accept()
{
parameter->showObject();

TaskThicknessParameters* draftparameter = static_cast<TaskThicknessParameters*>(parameter);

auto obj = vp->getObject();
Expand Down

0 comments on commit e0d0725

Please sign in to comment.