Skip to content

Commit

Permalink
PartDesign: Chamfer feature corrections and improvements
Browse files Browse the repository at this point in the history
========================================================

- Correction to mustExecute() to account for the new properties
- Make properties not used by the mode as read-only.
- Gui: apply() only for construction mode valid features
  • Loading branch information
abdullahtahiriyo committed May 23, 2020
1 parent e1240fb commit e4a5d8b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 10 deletions.
55 changes: 54 additions & 1 deletion src/Mod/PartDesign/App/FeatureChamfer.cpp
Expand Up @@ -76,11 +76,29 @@ Chamfer::Chamfer()
Angle.setConstraints(&floatAngle);

ADD_PROPERTY(FlipDirection, (false));

updateProperties();
}

short Chamfer::mustExecute() const
{
if (Placement.isTouched() || Size.isTouched())
bool touched = false;

auto chamferType = ChamferType.getValue();

switch (chamferType) {
case 0: // "Equal distance"
touched = Size.isTouched() || ChamferType.isTouched();
break;
case 1: // "Two distances"
touched = Size.isTouched() || ChamferType.isTouched() || Size2.isTouched();
break;
case 2: // "Distance and Angle"
touched = Size.isTouched() || ChamferType.isTouched() || Angle.isTouched();
break;
}

if (Placement.isTouched() || touched)
return 1;
return DressUp::mustExecute();
}
Expand Down Expand Up @@ -212,6 +230,39 @@ void Chamfer::Restore(Base::XMLReader &reader)
reader.readEndElement("Properties");
}

void Chamfer::onChanged(const App::Property* prop)
{
if (prop == &ChamferType) {
updateProperties();
}

DressUp::onChanged(prop);
}

void Chamfer::updateProperties()
{
auto chamferType = ChamferType.getValue();

auto disableproperty = [](App::Property * prop, bool on) {
prop->setStatus(App::Property::ReadOnly, on);
};

switch (chamferType) {
case 0: // "Equal distance"
disableproperty(&this->Angle, true);
disableproperty(&this->Size2, true);
break;
case 1: // "Two distances"
disableproperty(&this->Angle, true);
disableproperty(&this->Size2, false);
break;
case 2: // "Distance and Angle"
disableproperty(&this->Angle, false);
disableproperty(&this->Size2, true);
break;
}
}

static App::DocumentObjectExecReturn *validateParameters(int chamferType, double size, double size2, double angle)
{
// Size is common to all chamfer types.
Expand All @@ -237,3 +288,5 @@ static App::DocumentObjectExecReturn *validateParameters(int chamferType, double

return App::DocumentObject::StdReturn;
}


15 changes: 9 additions & 6 deletions src/Mod/PartDesign/App/FeatureChamfer.h
Expand Up @@ -34,7 +34,7 @@ namespace PartDesign

class PartDesignExport Chamfer : public DressUp
{
PROPERTY_HEADER(PartDesign::Chamfer);
PROPERTY_HEADER_WITH_OVERRIDE(PartDesign::Chamfer);

public:
Chamfer();
Expand All @@ -48,17 +48,20 @@ class PartDesignExport Chamfer : public DressUp
/** @name methods override feature */
//@{
/// recalculate the feature
App::DocumentObjectExecReturn *execute(void);
short mustExecute() const;
App::DocumentObjectExecReturn *execute(void) override;
short mustExecute() const override;
/// returns the type name of the view provider
const char* getViewProviderName(void) const {
const char* getViewProviderName(void) const override {
return "PartDesignGui::ViewProviderChamfer";
}
//@}

protected:
void Restore(Base::XMLReader &reader);
virtual void onChanged(const App::Property* /*prop*/) override;

void updateProperties();

protected:
void Restore(Base::XMLReader &reader) override;
};

} //namespace Part
Expand Down
22 changes: 19 additions & 3 deletions src/Mod/PartDesign/Gui/TaskChamferParameters.cpp
Expand Up @@ -320,9 +320,25 @@ void TaskChamferParameters::apply()
std::string name = DressUpView->getObject()->getNameInDocument();

//Gui::Command::openCommand("Chamfer changed");
ui->chamferSize->apply();
ui->chamferSize2->apply();
ui->chamferAngle->apply();

PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());

const int chamfertype = pcChamfer->ChamferType.getValue();

switch(chamfertype) {

case 0: // "Equal distance"
ui->chamferSize->apply();
break;
case 1: // "Two distances"
ui->chamferSize->apply();
ui->chamferSize2->apply();
break;
case 2: // "Distance and Angle"
ui->chamferSize->apply();
ui->chamferAngle->apply();
break;
}
}

//**************************************************************************
Expand Down

0 comments on commit e4a5d8b

Please sign in to comment.