Skip to content

Commit

Permalink
PartDesign: Chamfer with multiple creation modes
Browse files Browse the repository at this point in the history
  • Loading branch information
armandas authored and abdullahtahiriyo committed May 23, 2020
1 parent 3231bac commit 262841b
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 61 deletions.
44 changes: 36 additions & 8 deletions src/Mod/PartDesign/App/FeatureChamfer.cpp
Expand Up @@ -52,14 +52,23 @@ using namespace PartDesign;

PROPERTY_SOURCE(PartDesign::Chamfer, PartDesign::DressUp)

const char* ChamferTypeEnums[] = {"Equal distance", "Two distances", "Distance and Angle", NULL};
const App::PropertyQuantityConstraint::Constraints floatSize = {0.0,FLT_MAX,0.1};
const App::PropertyAngle::Constraints floatAngle = {0.0,180.0,0.1};

Chamfer::Chamfer()
{
ADD_PROPERTY(ChamferType, ((long)0));
ChamferType.setEnums(ChamferTypeEnums);

ADD_PROPERTY(Size,(1.0));
Size.setUnit(Base::Unit::Length);
Size.setConstraints(&floatSize);

ADD_PROPERTY(Size2,(1.0));
Size2.setUnit(Base::Unit::Length);
Size2.setConstraints(&floatSize);

ADD_PROPERTY(Angle,(45.0));
Angle.setUnit(Base::Unit::Angle);
Angle.setConstraints(&floatAngle);
Expand Down Expand Up @@ -89,13 +98,10 @@ App::DocumentObjectExecReturn *Chamfer::execute(void)
if (SubNames.size() == 0)
return new App::DocumentObjectExecReturn("No edges specified");

double size = Size.getValue();
if (size <= 0)
return new App::DocumentObjectExecReturn("Size must be greater than zero");

double angle = Base::toRadians(Angle.getValue());
if (angle <= 0 || angle >= 180.0)
return new App::DocumentObjectExecReturn("Angle must be greater than 0 and less than 180");
const int chamferType = ChamferType.getValue();
const double size = Size.getValue();
const double size2 = Size2.getValue();
const double angle = Base::toRadians(Angle.getValue());

this->positionByBaseFeature();
// create an untransformed copy of the basefeature shape
Expand All @@ -112,7 +118,29 @@ App::DocumentObjectExecReturn *Chamfer::execute(void)
for (std::vector<std::string>::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) {
TopoDS_Edge edge = TopoDS::Edge(baseShape.getSubShape(it->c_str()));
const TopoDS_Face& face = TopoDS::Face(mapEdgeFace.FindFromKey(edge).First());
mkChamfer.AddDA(size, angle, edge, face);
switch (chamferType) {
case 0:
if (size <= 0) {
return new App::DocumentObjectExecReturn("Size must be greater than zero");
} else {
mkChamfer.Add(size, size, edge, face);
}
break;
case 1:
if (size <= 0 || size2 <= 0) {
return new App::DocumentObjectExecReturn("Sizes must be greater than zero");
} else {
mkChamfer.Add(size, size2, edge, face);
}
break;
case 2:
if (angle <= 0 || angle >= 180.0) {
return new App::DocumentObjectExecReturn("Angle must be greater than 0 and less than 180");
} else {
mkChamfer.AddDA(size, angle, edge, face);
}
break;
}
}

mkChamfer.Build();
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/PartDesign/App/FeatureChamfer.h
Expand Up @@ -39,7 +39,9 @@ class PartDesignExport Chamfer : public DressUp
public:
Chamfer();

App::PropertyEnumeration ChamferType;
App::PropertyQuantityConstraint Size;
App::PropertyQuantityConstraint Size2;
App::PropertyAngle Angle;

/** @name methods override feature */
Expand Down
86 changes: 64 additions & 22 deletions src/Mod/PartDesign/Gui/TaskChamferParameters.cpp
Expand Up @@ -64,22 +64,8 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q

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

double r = pcChamfer->Size.getValue();
ui->chamferDistance->setUnit(Base::Unit::Length);
ui->chamferDistance->setValue(r);
ui->chamferDistance->setMinimum(0);
ui->chamferDistance->selectNumber();
ui->chamferDistance->bind(pcChamfer->Size);
QMetaObject::invokeMethod(ui->chamferDistance, "setFocus", Qt::QueuedConnection);

double a = pcChamfer->Angle.getValue();
ui->chamferAngle->setUnit(Base::Unit::Angle);
ui->chamferAngle->setValue(a);
ui->chamferAngle->setMinimum(0.0);
ui->chamferAngle->setMaximum(180.0);
ui->chamferAngle->selectAll();
ui->chamferAngle->bind(pcChamfer->Angle);
QMetaObject::invokeMethod(ui->chamferAngle, "setFocus", Qt::QueuedConnection);
setUpUI(pcChamfer);
QMetaObject::invokeMethod(ui->chamferSize, "setFocus", Qt::QueuedConnection);

std::vector<std::string> strings = pcChamfer->Base.getSubValues();
for (std::vector<std::string>::const_iterator i = strings.begin(); i != strings.end(); i++)
Expand All @@ -89,8 +75,12 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q

QMetaObject::connectSlotsByName(this);

connect(ui->chamferDistance, SIGNAL(valueChanged(double)),
this, SLOT(onLengthChanged(double)));
connect(ui->chamferType, SIGNAL(currentIndexChanged(int)),
this, SLOT(onTypeChanged(int)));
connect(ui->chamferSize, SIGNAL(valueChanged(double)),
this, SLOT(onSizeChanged(double)));
connect(ui->chamferSize2, SIGNAL(valueChanged(double)),
this, SLOT(onSize2Changed(double)));
connect(ui->chamferAngle, SIGNAL(valueChanged(double)),
this, SLOT(onAngleChanged(double)));
connect(ui->buttonRefAdd, SIGNAL(toggled(bool)),
Expand All @@ -110,6 +100,29 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q
this, SLOT(doubleClicked(QListWidgetItem*)));
}

void TaskChamferParameters::setUpUI(PartDesign::Chamfer* pcChamfer)
{
const int index = pcChamfer->ChamferType.getValue();
ui->chamferType->setCurrentIndex(index);

ui->chamferSize->setUnit(Base::Unit::Length);
ui->chamferSize->setMinimum(0);
ui->chamferSize->setValue(pcChamfer->Size.getValue());
ui->chamferSize->bind(pcChamfer->Size);
ui->chamferSize->selectNumber();

ui->chamferSize2->setUnit(Base::Unit::Length);
ui->chamferSize2->setMinimum(0);
ui->chamferSize2->setValue(pcChamfer->Size2.getValue());
ui->chamferSize2->bind(pcChamfer->Size2);

ui->chamferAngle->setUnit(Base::Unit::Angle);
ui->chamferAngle->setMinimum(0.0);
ui->chamferAngle->setMaximum(180.0);
ui->chamferAngle->setValue(pcChamfer->Angle.getValue());
ui->chamferAngle->bind(pcChamfer->Angle);
}

void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
// executed when the user selected something in the CAD object
Expand Down Expand Up @@ -208,17 +221,29 @@ void TaskChamferParameters::onRefDeleted(void)
}
}

void TaskChamferParameters::onLengthChanged(double len)
void TaskChamferParameters::onTypeChanged(int index)
{
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
pcChamfer->ChamferType.setValue(index);
ui->stackedWidget->setCurrentIndex(index);
ui->stackedWidget->setFixedHeight(ui->chamferSize2->sizeHint().height());
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
}

void TaskChamferParameters::onSizeChanged(double len)
{
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
setupTransaction();
pcChamfer->Size.setValue(len);
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
}

double TaskChamferParameters::getLength(void) const
void TaskChamferParameters::onSize2Changed(double len)
{
return ui->chamferDistance->value().getValue();
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
setupTransaction();
pcChamfer->Size2.setValue(len);
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
}

void TaskChamferParameters::onAngleChanged(double angle)
Expand All @@ -229,6 +254,21 @@ void TaskChamferParameters::onAngleChanged(double angle)
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
}

int TaskChamferParameters::getType(void) const
{
return ui->chamferType->currentIndex();
}

double TaskChamferParameters::getSize(void) const
{
return ui->chamferSize->value().getValue();
}

double TaskChamferParameters::getSize2(void) const
{
return ui->chamferSize2->value().getValue();
}

double TaskChamferParameters::getAngle(void) const
{
return ui->chamferAngle->value().getValue();
Expand Down Expand Up @@ -260,7 +300,9 @@ void TaskChamferParameters::apply()
std::string name = DressUpView->getObject()->getNameInDocument();

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

//**************************************************************************
Expand Down
14 changes: 12 additions & 2 deletions src/Mod/PartDesign/Gui/TaskChamferParameters.h
Expand Up @@ -28,6 +28,9 @@
#include "ViewProviderChamfer.h"

class Ui_TaskChamferParameters;
namespace PartDesign {
class Chamfer;
}

namespace PartDesignGui {

Expand All @@ -42,7 +45,9 @@ class TaskChamferParameters : public TaskDressUpParameters
virtual void apply();

private Q_SLOTS:
void onLengthChanged(double);
void onTypeChanged(int);
void onSizeChanged(double);
void onSize2Changed(double);
void onAngleChanged(double);
void onRefDeleted(void);

Expand All @@ -51,10 +56,15 @@ private Q_SLOTS:
bool event(QEvent *e);
void changeEvent(QEvent *e);
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
double getLength(void) const;

int getType(void) const;
double getSize(void) const;
double getSize2(void) const;
double getAngle(void) const;

private:
void setUpUI(PartDesign::Chamfer* pcChamfer);

Ui_TaskChamferParameters* ui;
};

Expand Down

0 comments on commit 262841b

Please sign in to comment.