Skip to content

Commit

Permalink
Added chamfer angle support to PartDesign.
Browse files Browse the repository at this point in the history
  • Loading branch information
armandas authored and abdullahtahiriyo committed May 10, 2020
1 parent 29c5528 commit cc82cf3
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 14 deletions.
15 changes: 10 additions & 5 deletions src/Mod/PartDesign/App/FeatureChamfer.cpp
Expand Up @@ -41,6 +41,7 @@
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Reader.h>
#include <Base/Tools.h>
#include <Mod/Part/App/TopoShape.h>

#include "FeatureChamfer.h"
Expand All @@ -52,12 +53,16 @@ using namespace PartDesign;
PROPERTY_SOURCE(PartDesign::Chamfer, PartDesign::DressUp)

const App::PropertyQuantityConstraint::Constraints floatSize = {0.0,FLT_MAX,0.1};
const App::PropertyAngle::Constraints floatAngle = {0.0,89.99,0.1};

Chamfer::Chamfer()
{
ADD_PROPERTY(Size,(1.0));
Size.setUnit(Base::Unit::Length);
Size.setConstraints(&floatSize);
ADD_PROPERTY(Angle,(45.0));
Size.setUnit(Base::Unit::Angle);
Angle.setConstraints(&floatAngle);
}

short Chamfer::mustExecute() const
Expand Down Expand Up @@ -88,6 +93,10 @@ App::DocumentObjectExecReturn *Chamfer::execute(void)
if (size <= 0)
return new App::DocumentObjectExecReturn("Size must be greater than zero");

double angle = Base::toRadians(Angle.getValue());
if (angle <= 0 || angle > 89.99)
return new App::DocumentObjectExecReturn("Angle must be between 0 and 89.99");

this->positionByBaseFeature();
// create an untransformed copy of the basefeature shape
Part::TopoShape baseShape(TopShape);
Expand All @@ -103,11 +112,7 @@ 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());
#if OCC_VERSION_HEX > 0x070300
mkChamfer.Add(size, size, edge, face);
#else
mkChamfer.Add(size, edge, face);
#endif
mkChamfer.AddDA(size, angle, edge, face);
}

mkChamfer.Build();
Expand Down
1 change: 1 addition & 0 deletions src/Mod/PartDesign/App/FeatureChamfer.h
Expand Up @@ -40,6 +40,7 @@ class PartDesignExport Chamfer : public DressUp
Chamfer();

App::PropertyQuantityConstraint Size;
App::PropertyAngle Angle;

/** @name methods override feature */
//@{
Expand Down
29 changes: 27 additions & 2 deletions src/Mod/PartDesign/Gui/TaskChamferParameters.cpp
Expand Up @@ -63,14 +63,24 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q
this->groupLayout()->addWidget(proxy);

PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
double r = pcChamfer->Size.getValue();

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(89.99);
ui->chamferAngle->selectAll();
ui->chamferAngle->bind(pcChamfer->Angle);
QMetaObject::invokeMethod(ui->chamferAngle, "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 @@ -81,6 +91,8 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q

connect(ui->chamferDistance, SIGNAL(valueChanged(double)),
this, SLOT(onLengthChanged(double)));
connect(ui->chamferAngle, SIGNAL(valueChanged(double)),
this, SLOT(onAngleChanged(double)));
connect(ui->buttonRefAdd, SIGNAL(toggled(bool)),
this, SLOT(onButtonRefAdd(bool)));
connect(ui->buttonRefRemove, SIGNAL(toggled(bool)),
Expand Down Expand Up @@ -179,7 +191,7 @@ void TaskChamferParameters::onRefDeleted(void)
// erase the reference
refs.erase(refs.begin() + rowNumber);
// remove from the list
ui->listWidgetReferences->model()->removeRow(rowNumber);
ui->listWidgetReferences->model()->removeRow(rowNumber);
}

// update the object
Expand Down Expand Up @@ -209,6 +221,19 @@ double TaskChamferParameters::getLength(void) const
return ui->chamferDistance->value().getValue();
}

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

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

TaskChamferParameters::~TaskChamferParameters()
{
Gui::Selection().clearSelection();
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/PartDesign/Gui/TaskChamferParameters.h
Expand Up @@ -43,6 +43,7 @@ class TaskChamferParameters : public TaskDressUpParameters

private Q_SLOTS:
void onLengthChanged(double);
void onAngleChanged(double);
void onRefDeleted(void);

protected:
Expand All @@ -51,6 +52,7 @@ private Q_SLOTS:
void changeEvent(QEvent *e);
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
double getLength(void) const;
double getAngle(void) const;

private:
Ui_TaskChamferParameters* ui;
Expand Down
48 changes: 41 additions & 7 deletions src/Mod/PartDesign/Gui/TaskChamferParameters.ui
Expand Up @@ -57,15 +57,49 @@ click again to end selection</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::QuantitySpinBox" name="chamferDistance" native="true"/>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Size</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::QuantitySpinBox" name="chamferDistance" native="true" />
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Size:</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Angle</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::QuantitySpinBox" name="chamferAngle" native="true">
<property name="unit" stdset="0">
<string notr="true">deg</string>
</property>
<property name="minimum" stdset="0">
<double>0.000000000000000</double>
</property>
<property name="maximum" stdset="0">
<double>89.999999999999986</double>
</property>
<property name="singleStep" stdset="0">
<double>0.100000000000000</double>
</property>
<property name="value" stdset="0">
<double>45.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down

0 comments on commit cc82cf3

Please sign in to comment.