PartDesign: Chamfer with multiple creation modes
This commit is contained in:
committed by
abdullahtahiriyo
parent
3231bac1c2
commit
262841bb3c
@@ -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);
|
||||
@@ -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
|
||||
@@ -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();
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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++)
|
||||
@@ -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)),
|
||||
@@ -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
|
||||
@@ -208,7 +221,16 @@ 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();
|
||||
@@ -216,9 +238,12 @@ void TaskChamferParameters::onLengthChanged(double 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)
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include "ViewProviderChamfer.h"
|
||||
|
||||
class Ui_TaskChamferParameters;
|
||||
namespace PartDesign {
|
||||
class Chamfer;
|
||||
}
|
||||
|
||||
namespace PartDesignGui {
|
||||
|
||||
@@ -42,7 +45,9 @@ public:
|
||||
virtual void apply();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onLengthChanged(double);
|
||||
void onTypeChanged(int);
|
||||
void onSizeChanged(double);
|
||||
void onSize2Changed(double);
|
||||
void onAngleChanged(double);
|
||||
void onRefDeleted(void);
|
||||
|
||||
@@ -51,10 +56,15 @@ protected:
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>182</width>
|
||||
<height>185</height>
|
||||
<width>263</width>
|
||||
<height>240</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -57,49 +57,130 @@ click again to end selection</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="typeLabel">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="chamferType">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Equal distance</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Two distances</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Distance and angle</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout_4">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="sizeLabel_2">
|
||||
<property name="text">
|
||||
<string>Size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::QuantitySpinBox" name="chamferDistance" native="true" />
|
||||
<item row="0" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="chamferSize" native="true">
|
||||
<property name="value">
|
||||
<number>1.000000000000000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label3">
|
||||
<property name="text">
|
||||
<string>Angle</string>
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page_1"/>
|
||||
<widget class="QWidget" name="page_2">
|
||||
<layout class="QFormLayout" name="formLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::QuantitySpinBox" name="chamferAngle" native="true">
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true">deg</string>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="minimum" stdset="0">
|
||||
<double>0.000000000000000</double>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maximum" stdset="0">
|
||||
<double>180.000000000000000</double>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="singleStep" stdset="0">
|
||||
<double>0.100000000000000</double>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="sizeLabel">
|
||||
<property name="text">
|
||||
<string>Size 2</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="chamferSize2" native="true">
|
||||
<property name="value">
|
||||
<number>1.000000000000000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_3">
|
||||
<layout class="QFormLayout" name="formLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="value" stdset="0">
|
||||
<double>45.000000000000000</double>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="angleLabel">
|
||||
<property name="text">
|
||||
<string>Angle</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="chamferAngle" native="true">
|
||||
<property name="minimum">
|
||||
<number>0.000000000000000</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>180.000000000000000</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>0.100000000000000</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>45.000000000000000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@@ -111,5 +192,22 @@ click again to end selection</string>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>chamferType</sender>
|
||||
<signal>currentIndexChanged(int)</signal>
|
||||
<receiver>stackedWidget</receiver>
|
||||
<slot>setCurrentIndex(int)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>149</x>
|
||||
<y>196</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>131</x>
|
||||
<y>222</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user