[PD] allow to pad in any direction

It saves a lot of work if one can directly pad in any direction and OCC allows this.

This PR adds the possibility to define a custom vector for the padding direction.
This commit is contained in:
donovaly
2020-08-09 16:23:07 +02:00
committed by wmayer
parent 6bbab49723
commit 91ef59fdbe
6 changed files with 324 additions and 39 deletions

View File

@@ -34,6 +34,7 @@
#include "TaskPadParameters.h"
#include <App/Application.h>
#include <App/Document.h>
#include <Base/UnitsApi.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
@@ -74,6 +75,10 @@ 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 useCustom = pcPad->UseCustomVector.getValue();
double xs = pcPad->Direction.getValue().x;
double ys = pcPad->Direction.getValue().y;
double zs = pcPad->Direction.getValue().z;
Base::Quantity off = pcPad->Offset.getQuantityValue();
bool midplane = pcPad->Midplane.getValue();
bool reversed = pcPad->Reversed.getValue();
@@ -91,17 +96,32 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView, QWidget *parent,
// Fill data into dialog elements
ui->lengthEdit->setValue(l);
ui->lengthEdit2->setValue(l2);
ui->groupBoxDirection->setChecked(useCustom);
ui->XDirectionEdit->setValue(xs);
ui->YDirectionEdit->setValue(ys);
ui->ZDirectionEdit->setValue(zs);
ui->offsetEdit->setValue(off);
// 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()));
@@ -135,6 +155,14 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView, QWidget *parent,
this, SLOT(onLengthChanged(double)));
connect(ui->lengthEdit2, SIGNAL(valueChanged(double)),
this, SLOT(onLength2Changed(double)));
connect(ui->groupBoxDirection, SIGNAL(toggled(bool)),
this, SLOT(onGBDirectionChanged(bool)));
connect(ui->XDirectionEdit, SIGNAL(valueChanged(double)),
this, SLOT(onXDirectionEditChanged(double)));
connect(ui->YDirectionEdit, SIGNAL(valueChanged(double)),
this, SLOT(onYDirectionEditChanged(double)));
connect(ui->ZDirectionEdit, SIGNAL(valueChanged(double)),
this, SLOT(onZDirectionEditChanged(double)));
connect(ui->offsetEdit, SIGNAL(valueChanged(double)),
this, SLOT(onOffsetChanged(double)));
connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)),
@@ -168,6 +196,7 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView, QWidget *parent,
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;
@@ -272,6 +301,49 @@ void TaskPadParameters::onLength2Changed(double len)
recomputeFeature();
}
void TaskPadParameters::onGBDirectionChanged(bool on)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
pcPad->UseCustomVector.setValue(on);
recomputeFeature();
}
void TaskPadParameters::onXDirectionEditChanged(double len)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
pcPad->Direction.setValue(len, pcPad->Direction.getValue().y, pcPad->Direction.getValue().z);
recomputeFeature();
// checking for case of a null vector is done in FeaturePad.cpp
// if there was a null vector, the normal vector of the sketch is used.
// therefore the vector component edits must be updated
updateDirectionEdits();
}
void TaskPadParameters::onYDirectionEditChanged(double len)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
pcPad->Direction.setValue(pcPad->Direction.getValue().x, len, pcPad->Direction.getValue().z);
recomputeFeature();
updateDirectionEdits();
}
void TaskPadParameters::onZDirectionEditChanged(double len)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
pcPad->Direction.setValue(pcPad->Direction.getValue().x, pcPad->Direction.getValue().y, len);
recomputeFeature();
updateDirectionEdits();
}
void TaskPadParameters::updateDirectionEdits(void)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
ui->XDirectionEdit->setValue(pcPad->Direction.getValue().x);
ui->YDirectionEdit->setValue(pcPad->Direction.getValue().y);
ui->ZDirectionEdit->setValue(pcPad->Direction.getValue().z);
}
void TaskPadParameters::onOffsetChanged(double len)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
@@ -360,6 +432,26 @@ double TaskPadParameters::getLength2(void) const
return ui->lengthEdit2->value().getValue();
}
bool TaskPadParameters::getCustom(void) const
{
return ui->groupBoxDirection->isChecked();
}
double TaskPadParameters::getXDirection(void) const
{
return ui->XDirectionEdit->value();
}
double TaskPadParameters::getYDirection(void) const
{
return ui->YDirectionEdit->value();
}
double TaskPadParameters::getZDirection(void) const
{
return ui->ZDirectionEdit->value();
}
double TaskPadParameters::getOffset(void) const
{
return ui->offsetEdit->value().getValue();
@@ -404,6 +496,9 @@ void TaskPadParameters::changeEvent(QEvent *e)
if (e->type() == QEvent::LanguageChange) {
ui->lengthEdit->blockSignals(true);
ui->lengthEdit2->blockSignals(true);
ui->XDirectionEdit->blockSignals(true);
ui->YDirectionEdit->blockSignals(true);
ui->ZDirectionEdit->blockSignals(true);
ui->offsetEdit->blockSignals(true);
ui->lineFaceName->blockSignals(true);
ui->changeMode->blockSignals(true);
@@ -443,6 +538,9 @@ void TaskPadParameters::changeEvent(QEvent *e)
ui->lengthEdit->blockSignals(false);
ui->lengthEdit2->blockSignals(false);
ui->XDirectionEdit->blockSignals(false);
ui->YDirectionEdit->blockSignals(false);
ui->ZDirectionEdit->blockSignals(false);
ui->offsetEdit->blockSignals(false);
ui->lineFaceName->blockSignals(false);
ui->changeMode->blockSignals(false);
@@ -463,10 +561,11 @@ void TaskPadParameters::apply()
ui->lengthEdit->apply();
ui->lengthEdit2->apply();
FCMD_OBJ_CMD(obj, "UseCustomVector = " << (getCustom() ? 1 : 0));
FCMD_OBJ_CMD(obj, "Direction = ("
<< getXDirection() << ", " << getYDirection() << ", " << getZDirection() << ")");
FCMD_OBJ_CMD(obj,"Type = " << getMode());
QString facename = getFaceName();
FCMD_OBJ_CMD(obj,"UpToFace = " << facename.toLatin1().data());
FCMD_OBJ_CMD(obj,"Reversed = " << (getReversed()?1:0));
FCMD_OBJ_CMD(obj,"Midplane = " << (getMidplane()?1:0));