PartDesign: Extension of Pocket Feature to have two dimensions

fixes #2915
This commit is contained in:
Abdullah Tahiri
2018-01-19 21:43:49 +01:00
committed by wmayer
parent f6825a2686
commit 663e4ee369
5 changed files with 71 additions and 4 deletions

View File

@@ -52,7 +52,7 @@
using namespace PartDesign;
const char* Pocket::TypeEnums[]= {"Length","ThroughAll","UpToFirst","UpToFace",NULL};
const char* Pocket::TypeEnums[]= {"Length","ThroughAll","UpToFirst","UpToFace","TwoLengths",NULL};
PROPERTY_SOURCE(PartDesign::Pocket, PartDesign::ProfileBased)
@@ -63,6 +63,7 @@ Pocket::Pocket()
ADD_PROPERTY_TYPE(Type,((long)0),"Pocket",App::Prop_None,"Pocket type");
Type.setEnums(TypeEnums);
ADD_PROPERTY_TYPE(Length,(100.0),"Pocket",App::Prop_None,"Pocket length");
ADD_PROPERTY_TYPE(Length2,(100.0),"Pocket",App::Prop_None,"P");
ADD_PROPERTY_TYPE(UpToFace,(0),"Pocket",App::Prop_None,"Face where pocket will end");
ADD_PROPERTY_TYPE(Offset,(0.0),"Pocket",App::Prop_None,"Offset from face in which pocket will end");
static const App::PropertyQuantityConstraint::Constraints signedLengthConstraint = {-DBL_MAX, DBL_MAX, 1.0};
@@ -74,6 +75,7 @@ short Pocket::mustExecute() const
if (Placement.isTouched() ||
Type.isTouched() ||
Length.isTouched() ||
Length2.isTouched() ||
Offset.isTouched() ||
UpToFace.isTouched())
return 1;
@@ -93,6 +95,10 @@ App::DocumentObjectExecReturn *Pocket::execute(void)
if ((std::string(Type.getValueAsString()) == "Length") && (L < Precision::Confusion()))
return new App::DocumentObjectExecReturn("Pocket: Length of pocket too small");
double L2 = Length2.getValue();
if ((std::string(Type.getValueAsString()) == "TwoLengths") && (L < Precision::Confusion()))
return new App::DocumentObjectExecReturn("Pocket: Second length of pocket too small");
Part::Feature* obj = 0;
TopoDS_Shape profileshape;
try {
@@ -178,8 +184,9 @@ App::DocumentObjectExecReturn *Pocket::execute(void)
this->Shape.setValue(getSolid(prism));
} else {
TopoDS_Shape prism;
generatePrism(prism, profileshape, method, dir, L, 0.0,
Midplane.getValue(), Reversed.getValue());
generatePrism(prism, profileshape, method, dir, L, L2,
Midplane.getValue(), Reversed.getValue());
if (prism.IsNull())
return new App::DocumentObjectExecReturn("Pocket: Resulting shape is empty");

View File

@@ -39,6 +39,7 @@ public:
App::PropertyEnumeration Type;
App::PropertyLength Length;
App::PropertyLength Length2;
App::PropertyLength Offset;
/** @name methods override feature */

View File

@@ -68,11 +68,13 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge
// set the history path
ui->lengthEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/PocketLength"));
ui->lengthEdit2->setParamGrpPath(QByteArray("User parameter:BaseApp/History/PocketLength2"));
ui->offsetEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/PocketOffset"));
// Get the feature data
PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(vp->getObject());
Base::Quantity l = pcPocket->Length.getQuantityValue();
Base::Quantity l2 = pcPocket->Length2.getQuantityValue();
Base::Quantity off = pcPocket->Offset.getQuantityValue();
bool midplane = pcPocket->Midplane.getValue();
bool reversed = pcPocket->Reversed.getValue();
@@ -89,6 +91,7 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge
// Fill data into dialog elements
ui->lengthEdit->setValue(l);
ui->lengthEdit2->setValue(l2);
ui->offsetEdit->setValue(off);
ui->checkBoxMidplane->setChecked(midplane);
ui->checkBoxReversed->setChecked(reversed);
@@ -117,15 +120,19 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge
ui->changeMode->insertItem(1, tr("Through all"));
ui->changeMode->insertItem(2, tr("To first"));
ui->changeMode->insertItem(3, tr("Up to face"));
ui->changeMode->insertItem(4, tr("Two dimensions"));
ui->changeMode->setCurrentIndex(index);
// Bind input fields to properties
ui->lengthEdit->bind(pcPocket->Length);
ui->lengthEdit2->bind(pcPocket->Length2);
QMetaObject::connectSlotsByName(this);
connect(ui->lengthEdit, SIGNAL(valueChanged(double)),
this, SLOT(onLengthChanged(double)));
connect(ui->lengthEdit2, SIGNAL(valueChanged(double)),
this, SLOT(onLength2Changed(double)));
connect(ui->offsetEdit, SIGNAL(valueChanged(double)),
this, SLOT(onOffsetChanged(double)));
connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)),
@@ -149,6 +156,8 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge
if(newObj){
ui->lengthEdit->setToLastUsedValue();
ui->lengthEdit->selectNumber();
ui->lengthEdit2->setToLastUsedValue();
ui->lengthEdit2->selectNumber();
ui->offsetEdit->setToLastUsedValue();
ui->offsetEdit->selectNumber();
}
@@ -158,6 +167,7 @@ void TaskPocketParameters::updateUI(int index)
{
// disable/hide everything unless we are sure we don't need it
bool isLengthEditVisable = false;
bool isLengthEdit2Visable = false;
bool isOffsetEditVisable = false;
bool isOffsetEditEnabled = true;
bool isMidplateEnabled = false;
@@ -200,11 +210,20 @@ void TaskPocketParameters::updateUI(int index)
if (ui->lineFaceName->property("FeatureName").isNull())
onButtonFace(true);
}
// two dimensions
else {
isLengthEditVisable = true;
isLengthEdit2Visable = true;
}
ui->lengthEdit->setVisible( isLengthEditVisable );
ui->lengthEdit->setEnabled( isLengthEditVisable );
ui->labelLength->setVisible( isLengthEditVisable );
ui->lengthEdit2->setVisible( isLengthEdit2Visable );
ui->lengthEdit2->setEnabled( isLengthEdit2Visable );
ui->labelLength2->setVisible( isLengthEdit2Visable );
ui->offsetEdit->setVisible( isOffsetEditVisable );
ui->offsetEdit->setEnabled( isOffsetEditVisable && isOffsetEditEnabled );
ui->labelOffset->setVisible( isOffsetEditVisable );
@@ -255,6 +274,13 @@ void TaskPocketParameters::onLengthChanged(double len)
recomputeFeature();
}
void TaskPocketParameters::onLength2Changed(double len)
{
PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(vp->getObject());
pcPocket->Length2.setValue(len);
recomputeFeature();
}
void TaskPocketParameters::onOffsetChanged(double len)
{
PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(vp->getObject());
@@ -288,6 +314,7 @@ void TaskPocketParameters::onModeChanged(int index)
oldLength = 5.0;
pcPocket->Length.setValue(oldLength);
ui->lengthEdit->setValue(oldLength);
pcPocket->Type.setValue("Length");
break;
case 1:
oldLength = pcPocket->Length.getValue();
@@ -305,7 +332,9 @@ void TaskPocketParameters::onModeChanged(int index)
pcPocket->Length.setValue(0.0);
ui->lengthEdit->setValue(0.0);
break;
default: pcPocket->Type.setValue("Length"); break;
default:
oldLength = pcPocket->Length.getValue();
pcPocket->Type.setValue("TwoLengths");
}
updateUI(index);
@@ -352,6 +381,11 @@ double TaskPocketParameters::getLength(void) const
return ui->lengthEdit->value().getValue();
}
double TaskPocketParameters::getLength2(void) const
{
return ui->lengthEdit2->value().getValue();
}
double TaskPocketParameters::getOffset(void) const
{
return ui->offsetEdit->value().getValue();
@@ -395,6 +429,7 @@ void TaskPocketParameters::changeEvent(QEvent *e)
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->lengthEdit->blockSignals(true);
ui->lengthEdit2->blockSignals(true);
ui->offsetEdit->blockSignals(true);
ui->lineFaceName->blockSignals(true);
ui->changeMode->blockSignals(true);
@@ -405,6 +440,7 @@ void TaskPocketParameters::changeEvent(QEvent *e)
ui->changeMode->addItem(tr("Through all"));
ui->changeMode->addItem(tr("To first"));
ui->changeMode->addItem(tr("Up to face"));
ui->changeMode->addItem(tr("Two dimensions"));
ui->changeMode->setCurrentIndex(index);
#if QT_VERSION >= 0x040700
@@ -432,6 +468,7 @@ void TaskPocketParameters::changeEvent(QEvent *e)
}
ui->lengthEdit->blockSignals(false);
ui->lengthEdit2->blockSignals(false);
ui->offsetEdit->blockSignals(false);
ui->lineFaceName->blockSignals(false);
ui->changeMode->blockSignals(false);
@@ -442,6 +479,7 @@ void TaskPocketParameters::saveHistory(void)
{
// save the user values to history
ui->lengthEdit->pushToHistory();
ui->lengthEdit2->pushToHistory();
ui->offsetEdit->pushToHistory();
}
@@ -451,6 +489,7 @@ void TaskPocketParameters::apply()
const char * cname = name.c_str();
ui->lengthEdit->apply();
ui->lengthEdit2->apply();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u", cname, getMode());
QString facename = getFaceName();

View File

@@ -57,6 +57,7 @@ public:
private Q_SLOTS:
void onLengthChanged(double);
void onLength2Changed(double);
void onOffsetChanged(double);
void onMidplaneChanged(bool);
void onReversedChanged(bool);
@@ -69,6 +70,7 @@ protected:
private:
double getLength(void) const;
double getLength2(void) const;
double getOffset(void) const;
int getMode(void) const;
bool getMidplane(void) const;

View File

@@ -83,6 +83,24 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="labelLength2">
<property name="text">
<string>2nd length</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefQuantitySpinBox" name="lengthEdit2">
<property name="minimum">
<double>0.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>