PartDesign: Chamfer feature corrections and improvements

========================================================

- 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
This commit is contained in:
Abdullah Tahiri
2020-05-14 19:35:40 +02:00
committed by abdullahtahiriyo
parent e1240fb18d
commit e4a5d8b862
3 changed files with 82 additions and 10 deletions

View File

@@ -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();
}
@@ -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.
@@ -237,3 +288,5 @@ static App::DocumentObjectExecReturn *validateParameters(int chamferType, double
return App::DocumentObject::StdReturn;
}

View File

@@ -34,7 +34,7 @@ namespace PartDesign
class PartDesignExport Chamfer : public DressUp
{
PROPERTY_HEADER(PartDesign::Chamfer);
PROPERTY_HEADER_WITH_OVERRIDE(PartDesign::Chamfer);
public:
Chamfer();
@@ -48,17 +48,20 @@ public:
/** @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

View File

@@ -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;
}
}
//**************************************************************************