Skip to content

Commit

Permalink
[PD] add along length option for pad
Browse files Browse the repository at this point in the history
- as discussed here: https://forum.freecadweb.org/viewtopic.php?f=17&t=50466&start=10#p433327
this PR is the first step for new Pad features.
It implements 3 features requested by users:
1. an option to measure the pad length along its direction if there is a custom direction
2. when there are two lengths, the reverse feature should be active
3. the pad dialog shows now always the used pad direction, no matter if it is a custom one or the sketch's normal

- Furthermore there are some code improvements (avoid rounding and blocking signals)

- Also adapt TestPad.py because its test used the case two lengths + reversed but this was not possible before this PR - the reverse option was not take into account for two lengths in FeatureSketchBased.cpp)
Now it is and therefore the test must be updated:
In the test the second sketch has the normal vector 0, -1, 0. As the reverse option is set the pad direction is 0, 1, 0. So in y direction is the length (1mm) and in -y direction is length2 (2mm). This gives together with the other pad of volume 1, a total volume of 4.

- fix UI issue: either reversed or midplane
As noticed by @chennes, when the pad uses symmetric, reversed is not sensible and vice versa.
This commit fixes the missing Gui side for the case midplane is checked and the App side.

- the PR also fix two typos
  • Loading branch information
donovaly authored and wwmayer committed Mar 22, 2021
1 parent 5e90c07 commit cf11f38
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 137 deletions.
29 changes: 22 additions & 7 deletions src/Mod/PartDesign/App/FeaturePad.cpp
Expand Up @@ -56,7 +56,7 @@

using namespace PartDesign;

const char* Pad::TypeEnums[]= {"Length","UpToLast","UpToFirst","UpToFace","TwoLengths",NULL};
const char* Pad::TypeEnums[]= {"Length", "UpToLast", "UpToFirst", "UpToFace", "TwoLengths", NULL};

PROPERTY_SOURCE(PartDesign::Pad, PartDesign::ProfileBased)

Expand All @@ -70,6 +70,7 @@ Pad::Pad()
ADD_PROPERTY_TYPE(Length2, (100.0), "Pad", App::Prop_None,"Second Pad length");
ADD_PROPERTY_TYPE(UseCustomVector, (0), "Pad", App::Prop_None, "Use custom vector for pad direction");
ADD_PROPERTY_TYPE(Direction, (Base::Vector3d(1.0, 1.0, 1.0)), "Pad", App::Prop_None, "Pad direction vector");
ADD_PROPERTY_TYPE(AlongCustomVector, (1), "Pad", App::Prop_None, "Measure length along custom direction vector");
ADD_PROPERTY_TYPE(UpToFace, (0), "Pad", App::Prop_None, "Face where pad will end");
ADD_PROPERTY_TYPE(Offset, (0.0), "Pad", App::Prop_None, "Offset from face in which pad will end");
static const App::PropertyQuantityConstraint::Constraints signedLengthConstraint = {-DBL_MAX, DBL_MAX, 1.0};
Expand All @@ -88,6 +89,7 @@ short Pad::mustExecute() const
Length2.isTouched() ||
UseCustomVector.isTouched() ||
Direction.isTouched() ||
AlongCustomVector.isTouched() ||
Offset.isTouched() ||
UpToFace.isTouched())
return 1;
Expand All @@ -104,6 +106,12 @@ App::DocumentObjectExecReturn *Pad::execute(void)
if ((std::string(Type.getValueAsString()) == "TwoLengths") && (L < Precision::Confusion()))
return new App::DocumentObjectExecReturn("Second length of pad too small");

// if midplane is true, disable reversed and vice versa
bool hasMidplane = Midplane.getValue();
bool hasReversed = Reversed.getValue();
Midplane.setReadOnly(hasReversed);
Reversed.setReadOnly(hasMidplane);

Part::Feature* obj = 0;
TopoDS_Shape sketchshape;
try {
Expand Down Expand Up @@ -133,12 +141,13 @@ App::DocumentObjectExecReturn *Pad::execute(void)
base.Move(invObjLoc);

Base::Vector3d paddingDirection;

// use the given vector if necessary

if (!UseCustomVector.getValue()) {
// use sketch's normal vector for direction
paddingDirection = SketchVector;
}
else {
// use the given vector
// if null vector, use SketchVector
if ( (fabs(Direction.getValue().x) < Precision::Confusion())
&& (fabs(Direction.getValue().y) < Precision::Confusion())
Expand Down Expand Up @@ -168,9 +177,15 @@ App::DocumentObjectExecReturn *Pad::execute(void)
if (factor < Precision::Confusion())
return new App::DocumentObjectExecReturn("Pad: Creation failed because direction is orthogonal to sketch's normal vector");

// perform the length correction
L = L / factor;
L2 = L2 / factor;
// perform the length correction if not along custom vector
if (AlongCustomVector.getValue()) {
L = L / factor;
L2 = L2 / factor;
}

// explicitly set the Direction so that the dialog shows also the used direction
// if the sketch's normal vector was used
Direction.setValue(paddingDirection);

dir.Transform(invObjLoc.Transformation());

Expand Down Expand Up @@ -306,7 +321,7 @@ App::DocumentObjectExecReturn *Pad::execute(void)
}
} else {
generatePrism(prism, sketchshape, method, dir, L, L2,
Midplane.getValue(), Reversed.getValue());
hasMidplane, hasReversed);
}

if (prism.IsNull())
Expand Down
1 change: 1 addition & 0 deletions src/Mod/PartDesign/App/FeaturePad.h
Expand Up @@ -45,6 +45,7 @@ class PartDesignExport Pad : public ProfileBased
App::PropertyLength Length2;
App::PropertyBool UseCustomVector;
App::PropertyVector Direction;
App::PropertyBool AlongCustomVector;
App::PropertyLength Offset;

/** @name methods override feature */
Expand Down
5 changes: 4 additions & 1 deletion src/Mod/PartDesign/App/FeatureSketchBased.cpp
Expand Up @@ -587,8 +587,11 @@ void ProfileBased::generatePrism(TopoDS_Shape& prism,

if (method == "TwoLengths") {
// midplane makes no sense here
Loffset = -L2;
Ltotal += L2;
if (reversed)
Loffset = -L;
else
Loffset = -L2;
} else if (midplane)
Loffset = -Ltotal/2;

Expand Down
108 changes: 74 additions & 34 deletions src/Mod/PartDesign/Gui/TaskPadParameters.cpp
Expand Up @@ -34,15 +34,15 @@
#include "TaskPadParameters.h"
#include <App/Application.h>
#include <App/Document.h>
#include <Base/Console.h>
#include <Base/UnitsApi.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/Document.h>
#include <Gui/Selection.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Mod/PartDesign/App/FeaturePad.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include "TaskSketchBasedParameters.h"
Expand Down Expand Up @@ -75,6 +75,7 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView, QWidget *parent,
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
Base::Quantity l = pcPad->Length.getQuantityValue();
Base::Quantity l2 = pcPad->Length2.getQuantityValue();
bool alongCustom = pcPad->AlongCustomVector.getValue();
bool useCustom = pcPad->UseCustomVector.getValue();
double xs = pcPad->Direction.getValue().x;
double ys = pcPad->Direction.getValue().y;
Expand All @@ -93,10 +94,18 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView, QWidget *parent,
faceId = std::atoi(&upToFace[4]);
}

// set decimals for the direction edits
// do this here before the edits are filed to avoid rounding mistakes
int UserDecimals = Base::UnitsApi::getDecimals();
ui->XDirectionEdit->setDecimals(UserDecimals);
ui->YDirectionEdit->setDecimals(UserDecimals);
ui->ZDirectionEdit->setDecimals(UserDecimals);

// Fill data into dialog elements
ui->lengthEdit->setValue(l);
ui->lengthEdit2->setValue(l2);
ui->groupBoxDirection->setChecked(useCustom);
ui->checkBoxAlongDirection->setChecked(alongCustom);
ui->XDirectionEdit->setValue(xs);
ui->YDirectionEdit->setValue(ys);
ui->ZDirectionEdit->setValue(zs);
Expand All @@ -105,23 +114,16 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView, QWidget *parent,
// Bind input fields to properties
ui->lengthEdit->bind(pcPad->Length);
ui->lengthEdit2->bind(pcPad->Length2);

ui->XDirectionEdit->bind(App::ObjectIdentifier::parse(pcPad, std::string("Direction.x")));
ui->YDirectionEdit->bind(App::ObjectIdentifier::parse(pcPad, std::string("Direction.y")));
ui->ZDirectionEdit->bind(App::ObjectIdentifier::parse(pcPad, std::string("Direction.z")));

ui->offsetEdit->bind(pcPad->Offset);

ui->checkBoxMidplane->setChecked(midplane);
// According to bug #0000521 the reversed option
// shouldn't be de-activated if the pad has a support face
ui->checkBoxReversed->setChecked(reversed);

// set decimals for the direction edits
int UserDecimals = Base::UnitsApi::getDecimals();
ui->XDirectionEdit->setDecimals(UserDecimals);
ui->YDirectionEdit->setDecimals(UserDecimals);
ui->ZDirectionEdit->setDecimals(UserDecimals);

// Set object labels
if (obj && PartDesign::Feature::isDatum(obj)) {
ui->lineFaceName->setText(QString::fromUtf8(obj->Label.getValue()));
Expand All @@ -138,7 +140,6 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView, QWidget *parent,
ui->lineFaceName->clear();
ui->lineFaceName->setProperty("FeatureName", QVariant());
}

ui->lineFaceName->setProperty("FaceName", QByteArray(upToFace.c_str()));

ui->changeMode->clear();
Expand All @@ -155,6 +156,8 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView, QWidget *parent,
this, SLOT(onLengthChanged(double)));
connect(ui->lengthEdit2, SIGNAL(valueChanged(double)),
this, SLOT(onLength2Changed(double)));
connect(ui->checkBoxAlongDirection, SIGNAL(toggled(bool)),
this, SLOT(onCBAlongDirectionChanged(bool)));
connect(ui->groupBoxDirection, SIGNAL(toggled(bool)),
this, SLOT(onGBDirectionChanged(bool)));
connect(ui->XDirectionEdit, SIGNAL(valueChanged(double)),
Expand Down Expand Up @@ -197,16 +200,17 @@ void TaskPadParameters::updateUI(int index)
{
// disable/hide everything unless we are sure we don't need it
// exception: the direction parameters are in any case visible
bool isLengthEditVisable = false;
bool isLengthEdit2Visable = false;
bool isOffsetEditVisable = false;
bool isLengthEditVisible = false;
bool isLengthEdit2Visible = false;
bool isOffsetEditVisible = false;
bool isMidplateEnabled = false;
bool isReversedEnabled = false;
bool isReversedEnabled = true;
bool isReversedVisible = true;
bool isFaceEditEnabled = false;

// dimension
if (index == 0) {
isLengthEditVisable = true;
isLengthEditVisible = true;
ui->lengthEdit->selectNumber();
// Make sure that the spin box has the focus to get key events
// Calling setFocus() directly doesn't work because the spin box is not
Expand All @@ -218,39 +222,44 @@ void TaskPadParameters::updateUI(int index)
}
// up to first/last
else if (index == 1 || index == 2) {
isOffsetEditVisable = true;
isReversedEnabled = true;
isOffsetEditVisible = true;
isReversedEnabled = false;
isReversedVisible = false;
}
// up to face
else if (index == 3) {
isOffsetEditVisable = true;
isFaceEditEnabled = true;
isOffsetEditVisible = true;
isFaceEditEnabled = true;
isReversedEnabled = false;
isReversedVisible = false;
QMetaObject::invokeMethod(ui->lineFaceName, "setFocus", Qt::QueuedConnection);
// Go into reference selection mode if no face has been selected yet
if (ui->lineFaceName->property("FeatureName").isNull())
onButtonFace(true);
}
// two dimensions
else {
isLengthEditVisable = true;
isLengthEdit2Visable = true;
isLengthEditVisible = true;
isLengthEdit2Visible = true;
}

ui->lengthEdit->setVisible( isLengthEditVisable );
ui->lengthEdit->setEnabled( isLengthEditVisable );
ui->labelLength->setVisible( isLengthEditVisable );
ui->lengthEdit->setVisible( isLengthEditVisible );
ui->lengthEdit->setEnabled( isLengthEditVisible );
ui->labelLength->setVisible( isLengthEditVisible );
ui->checkBoxAlongDirection->setVisible( isLengthEditVisible );

ui->offsetEdit->setVisible( isOffsetEditVisable );
ui->offsetEdit->setEnabled( isOffsetEditVisable );
ui->labelOffset->setVisible( isOffsetEditVisable );
ui->offsetEdit->setVisible( isOffsetEditVisible );
ui->offsetEdit->setEnabled( isOffsetEditVisible );
ui->labelOffset->setVisible( isOffsetEditVisible );

ui->checkBoxMidplane->setEnabled( isMidplateEnabled );

ui->checkBoxReversed->setEnabled( isReversedEnabled );
ui->checkBoxReversed->setVisible( isReversedVisible );

ui->lengthEdit2->setVisible( isLengthEdit2Visable );
ui->lengthEdit2->setEnabled( isLengthEdit2Visable );
ui->labelLength2->setVisible( isLengthEdit2Visable );
ui->lengthEdit2->setVisible( isLengthEdit2Visible );
ui->lengthEdit2->setEnabled( isLengthEdit2Visible );
ui->labelLength2->setVisible( isLengthEdit2Visible );

ui->buttonFace->setEnabled( isFaceEditEnabled );
ui->lineFaceName->setEnabled( isFaceEditEnabled );
Expand Down Expand Up @@ -301,11 +310,26 @@ void TaskPadParameters::onLength2Changed(double len)
recomputeFeature();
}

void TaskPadParameters::onCBAlongDirectionChanged(bool on)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
pcPad->AlongCustomVector.setValue(on);
recomputeFeature();
}

void TaskPadParameters::onGBDirectionChanged(bool on)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
pcPad->UseCustomVector.setValue(on);
// dis/enable length direction
ui->checkBoxAlongDirection->setEnabled(on);
if (!on)
ui->checkBoxAlongDirection->setChecked(!on);
recomputeFeature();
// the calculation of the sketch's normal vector is done in FeaturePad.cpp
// if this vector was used for the recomputation we must fill the direction
// vector edit fields. Therefore update
updateDirectionEdits();
}

void TaskPadParameters::onXDirectionEditChanged(double len)
Expand All @@ -319,7 +343,6 @@ void TaskPadParameters::onXDirectionEditChanged(double len)
updateDirectionEdits();
}


void TaskPadParameters::onYDirectionEditChanged(double len)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
Expand All @@ -339,9 +362,16 @@ void TaskPadParameters::onZDirectionEditChanged(double len)
void TaskPadParameters::updateDirectionEdits(void)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
// we don't want to execute the onChanged edits, but just update their contents
ui->XDirectionEdit->blockSignals(true);
ui->YDirectionEdit->blockSignals(true);
ui->ZDirectionEdit->blockSignals(true);
ui->XDirectionEdit->setValue(pcPad->Direction.getValue().x);
ui->YDirectionEdit->setValue(pcPad->Direction.getValue().y);
ui->ZDirectionEdit->setValue(pcPad->Direction.getValue().z);
ui->XDirectionEdit->blockSignals(false);
ui->YDirectionEdit->blockSignals(false);
ui->ZDirectionEdit->blockSignals(false);
}

void TaskPadParameters::onOffsetChanged(double len)
Expand All @@ -355,6 +385,7 @@ void TaskPadParameters::onMidplaneChanged(bool on)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
pcPad->Midplane.setValue(on);
// reversed is not sensible when midplane
ui->checkBoxReversed->setEnabled(!on);
recomputeFeature();
}
Expand All @@ -363,6 +394,8 @@ void TaskPadParameters::onReversedChanged(bool on)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
pcPad->Reversed.setValue(on);
// midplane is not sensible when reversed
ui->checkBoxMidplane->setEnabled(!on);
recomputeFeature();
}

Expand Down Expand Up @@ -391,6 +424,7 @@ void TaskPadParameters::onButtonFace(const bool pressed)
{
this->blockConnection(!pressed);

// only faces are allowed
TaskSketchBasedParameters::onSelectReference(pressed, false, true, false);

// Update button if onButtonFace() is called explicitly
Expand Down Expand Up @@ -432,6 +466,11 @@ double TaskPadParameters::getLength2(void) const
return ui->lengthEdit2->value().getValue();
}

bool TaskPadParameters::getAlongCustom(void) const
{
return ui->checkBoxAlongDirection->isChecked();
}

bool TaskPadParameters::getCustom(void) const
{
return ui->groupBoxDirection->isChecked();
Expand Down Expand Up @@ -563,6 +602,7 @@ void TaskPadParameters::apply()
FCMD_OBJ_CMD(obj, "UseCustomVector = " << (getCustom() ? 1 : 0));
FCMD_OBJ_CMD(obj, "Direction = ("
<< getXDirection() << ", " << getYDirection() << ", " << getZDirection() << ")");
FCMD_OBJ_CMD(obj, "AlongCustomVector = " << (getAlongCustom() ? 1 : 0));
FCMD_OBJ_CMD(obj,"Type = " << getMode());
QString facename = getFaceName();
FCMD_OBJ_CMD(obj,"UpToFace = " << facename.toLatin1().data());
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/PartDesign/Gui/TaskPadParameters.h
Expand Up @@ -58,6 +58,7 @@ class TaskPadParameters : public TaskSketchBasedParameters
private Q_SLOTS:
void onLengthChanged(double);
void onLength2Changed(double);
void onCBAlongDirectionChanged(bool);
void onGBDirectionChanged(bool);
void onXDirectionEditChanged(double);
void onYDirectionEditChanged(double);
Expand All @@ -75,6 +76,7 @@ private Q_SLOTS:
private:
double getLength(void) const;
double getLength2(void) const;
bool getAlongCustom(void) const;
bool getCustom(void) const;
double getXDirection(void) const;
double getYDirection(void) const;
Expand Down

0 comments on commit cf11f38

Please sign in to comment.