Skip to content

Commit

Permalink
Merge branch 'master' of ssh://git.code.sf.net/p/free-cad/code
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Feb 9, 2014
2 parents 9d235d7 + a97f53a commit 1ec1033
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 46 deletions.
8 changes: 8 additions & 0 deletions src/Gui/InputField.cpp
Expand Up @@ -201,6 +201,14 @@ std::vector<QString> InputField::getHistory(void)
return res;
}

void InputField::setToLastUsedValue(void)
{
std::vector<QString> hist = getHistory();
if(hist.size()>0)
this->setText(hist[0]);
}


void InputField::pushToSavedValues(const QString &valueq)
{
std::string value;
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/InputField.h
Expand Up @@ -70,6 +70,8 @@ class GuiExport InputField : public QLineEdit
*/
void setUnit(const Base::Unit&);

/// set the input field to the last used value (works only if the setParamGrpPath() was called)
void setToLastUsedValue(void);
/// get the value of the singleStep property
double singleStep(void)const;
/// set the value of the singleStep property
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/PartDesign/App/FeaturePad.cpp
Expand Up @@ -58,7 +58,9 @@ Pad::Pad()
ADD_PROPERTY(Type,((long)0));
Type.setEnums(TypeEnums);
ADD_PROPERTY(Length,(100.0));
Length.setUnit(Base::Unit::Length);
ADD_PROPERTY(Length2,(100.0));
Length2.setUnit(Base::Unit::Length);
ADD_PROPERTY_TYPE(UpToFace,(0),"Pad",(App::PropertyType)(App::Prop_None),"Face where feature will end");
}

Expand Down
5 changes: 3 additions & 2 deletions src/Mod/PartDesign/App/FeaturePad.h
Expand Up @@ -26,6 +26,7 @@

#include <App/PropertyUnits.h>
#include <App/PropertyStandard.h>
#include <App/PropertyUnits.h>
#include "FeatureAdditive.h"

namespace PartDesign
Expand All @@ -39,8 +40,8 @@ class PartDesignExport Pad : public Additive
Pad();

App::PropertyEnumeration Type;
App::PropertyLength Length;
App::PropertyLength Length2;
App::PropertyQuantity Length;
App::PropertyQuantity Length2;
App::PropertyLinkSub UpToFace;

/** @name methods override feature */
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/Gui/Command.cpp
Expand Up @@ -211,7 +211,7 @@ void CmdPartDesignPad::activated(int iMsg)
if (support)
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument());
}
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
doCommand(Gui,"Gui.activeDocument().setEdit('%s',1)",FeatName.c_str());

//commitCommand();
adjustCameraPosition();
Expand Down
95 changes: 58 additions & 37 deletions src/Mod/PartDesign/Gui/TaskPadParameters.cpp
Expand Up @@ -52,7 +52,7 @@ using namespace Gui;

/* TRANSLATOR PartDesignGui::TaskPadParameters */

TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,bool newObj, QWidget *parent)
: TaskBox(Gui::BitmapFactory().pixmap("PartDesign_Pad"),tr("Pad parameters"),true, parent),PadView(PadView)
{
// we need a separate container widget to add all controls to
Expand All @@ -61,13 +61,13 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);

connect(ui->doubleSpinBox, SIGNAL(valueChanged(double)),
connect(ui->lengthEdit, SIGNAL(valueChanged(double)),
this, SLOT(onLengthChanged(double)));
connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)),
this, SLOT(onMidplane(bool)));
connect(ui->checkBoxReversed, SIGNAL(toggled(bool)),
this, SLOT(onReversed(bool)));
connect(ui->doubleSpinBox2, SIGNAL(valueChanged(double)),
connect(ui->lengthEdit2, SIGNAL(valueChanged(double)),
this, SLOT(onLength2Changed(double)));
connect(ui->changeMode, SIGNAL(currentIndexChanged(int)),
this, SLOT(onModeChanged(int)));
Expand All @@ -81,20 +81,24 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
this->groupLayout()->addWidget(proxy);

// Temporarily prevent unnecessary feature recomputes
ui->doubleSpinBox->blockSignals(true);
ui->doubleSpinBox2->blockSignals(true);
ui->lengthEdit->blockSignals(true);
ui->lengthEdit2->blockSignals(true);
ui->checkBoxMidplane->blockSignals(true);
ui->checkBoxReversed->blockSignals(true);
ui->buttonFace->blockSignals(true);
ui->lineFaceName->blockSignals(true);
ui->changeMode->blockSignals(true);

// set the history path
ui->lengthEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/PadLength"));
ui->lengthEdit2->setParamGrpPath(QByteArray("User parameter:BaseApp/History/PadLength2"));

// Get the feature data
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
double l = pcPad->Length.getValue();
Base::Quantity l = pcPad->Length.getQuantityValue();
bool midplane = pcPad->Midplane.getValue();
bool reversed = pcPad->Reversed.getValue();
double l2 = pcPad->Length2.getValue();
Base::Quantity l2 = pcPad->Length2.getQuantityValue();
int index = pcPad->Type.getValue(); // must extract value here, clear() kills it!
std::vector<std::string> subStrings = pcPad->UpToFace.getSubValues();
std::string upToFace;
Expand All @@ -106,12 +110,19 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
}

// Fill data into dialog elements
ui->doubleSpinBox->setMinimum(0);
ui->doubleSpinBox->setMaximum(INT_MAX);
ui->doubleSpinBox->setValue(l);
ui->doubleSpinBox2->setMinimum(0);
ui->doubleSpinBox2->setMaximum(INT_MAX);
ui->doubleSpinBox2->setValue(l2);
ui->lengthEdit->setMinimum(0);
ui->lengthEdit->setMaximum(INT_MAX);
ui->lengthEdit->setValue(l);
ui->lengthEdit2->setMinimum(0);
ui->lengthEdit2->setMaximum(INT_MAX);
ui->lengthEdit2->setValue(l2);

// if it is a newly created object use the last value of the history
if(newObj){
ui->lengthEdit->setToLastUsedValue();
ui->lengthEdit2->setToLastUsedValue();
}

ui->checkBoxMidplane->setChecked(midplane);
// According to bug #0000521 the reversed option
// shouldn't be de-activated if the pad has a support face
Expand All @@ -129,8 +140,8 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
ui->changeMode->setCurrentIndex(index);

// activate and de-activate dialog elements as appropriate
ui->doubleSpinBox->blockSignals(false);
ui->doubleSpinBox2->blockSignals(false);
ui->lengthEdit->blockSignals(false);
ui->lengthEdit2->blockSignals(false);
ui->checkBoxMidplane->blockSignals(false);
ui->checkBoxReversed->blockSignals(false);
ui->buttonFace->blockSignals(false);
Expand All @@ -142,45 +153,45 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
void TaskPadParameters::updateUI(int index)
{
if (index == 0) { // dimension
ui->doubleSpinBox->setEnabled(true);
ui->doubleSpinBox->selectAll();
ui->lengthEdit->setEnabled(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
// yet visible.
QMetaObject::invokeMethod(ui->doubleSpinBox, "setFocus", Qt::QueuedConnection);
QMetaObject::invokeMethod(ui->lengthEdit, "setFocus", Qt::QueuedConnection);
ui->checkBoxMidplane->setEnabled(true);
// Reverse only makes sense if Midplane is not true
ui->checkBoxReversed->setEnabled(!ui->checkBoxMidplane->isChecked());
ui->doubleSpinBox2->setEnabled(false);
ui->lengthEdit2->setEnabled(false);
ui->buttonFace->setEnabled(false);
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
} else if (index == 1 || index == 2) { // up to first/last
ui->doubleSpinBox->setEnabled(false);
ui->lengthEdit->setEnabled(false);
ui->checkBoxMidplane->setEnabled(false);
ui->checkBoxReversed->setEnabled(true);
ui->doubleSpinBox2->setEnabled(false);
ui->lengthEdit2->setEnabled(false);
ui->buttonFace->setEnabled(false);
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
} else if (index == 3) { // up to face
ui->doubleSpinBox->setEnabled(false);
ui->lengthEdit->setEnabled(false);
ui->checkBoxMidplane->setEnabled(false);
ui->checkBoxReversed->setEnabled(false);
ui->doubleSpinBox2->setEnabled(false);
ui->lengthEdit2->setEnabled(false);
ui->buttonFace->setEnabled(true);
ui->lineFaceName->setEnabled(true);
QMetaObject::invokeMethod(ui->lineFaceName, "setFocus", Qt::QueuedConnection);
// Go into reference selection mode if no face has been selected yet
if (ui->lineFaceName->text().isEmpty())
onButtonFace(true);
} else { // two dimensions
ui->doubleSpinBox->setEnabled(true);
ui->doubleSpinBox->selectAll();
QMetaObject::invokeMethod(ui->doubleSpinBox, "setFocus", Qt::QueuedConnection);
ui->lengthEdit->setEnabled(true);
ui->lengthEdit->selectAll();
QMetaObject::invokeMethod(ui->lengthEdit, "setFocus", Qt::QueuedConnection);
ui->checkBoxMidplane->setEnabled(false);
ui->checkBoxReversed->setEnabled(false);
ui->doubleSpinBox2->setEnabled(true);
ui->lengthEdit2->setEnabled(true);
ui->buttonFace->setEnabled(false);
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
Expand Down Expand Up @@ -273,8 +284,8 @@ void TaskPadParameters::onModeChanged(int index)
case 0:
pcPad->Type.setValue("Length");
// Avoid error message
if (ui->doubleSpinBox->value() < Precision::Confusion())
ui->doubleSpinBox->setValue(5.0);
if (ui->lengthEdit->getQuantity() < Precision::Confusion())
ui->lengthEdit->setValue(5.0);
break;
case 1: pcPad->Type.setValue("UpToLast"); break;
case 2: pcPad->Type.setValue("UpToFirst"); break;
Expand Down Expand Up @@ -357,7 +368,7 @@ void TaskPadParameters::onUpdateView(bool on)

double TaskPadParameters::getLength(void) const
{
return ui->doubleSpinBox->value();
return ui->lengthEdit->getQuantity().getValue();
}

bool TaskPadParameters::getReversed(void) const
Expand All @@ -372,7 +383,7 @@ bool TaskPadParameters::getMidplane(void) const

double TaskPadParameters::getLength2(void) const
{
return ui->doubleSpinBox2->value();
return ui->lengthEdit2->getQuantity().getValue();
}

int TaskPadParameters::getMode(void) const
Expand All @@ -399,8 +410,8 @@ void TaskPadParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->doubleSpinBox->blockSignals(true);
ui->doubleSpinBox2->blockSignals(true);
ui->lengthEdit->blockSignals(true);
ui->lengthEdit2->blockSignals(true);
ui->lineFaceName->blockSignals(true);
ui->changeMode->blockSignals(true);
int index = ui->changeMode->currentIndex();
Expand All @@ -422,23 +433,30 @@ void TaskPadParameters::changeEvent(QEvent *e)
ui->lineFaceName->setText(ok ?
tr("Face") + QString::number(faceId) :
tr("No face selected"));
ui->doubleSpinBox->blockSignals(false);
ui->doubleSpinBox2->blockSignals(false);
ui->lengthEdit->blockSignals(false);
ui->lengthEdit2->blockSignals(false);
ui->lineFaceName->blockSignals(false);
ui->changeMode->blockSignals(false);
}
}

void TaskPadParameters::saveHistory(void)
{
// save the user values to history
ui->lengthEdit->pushToHistory();
ui->lengthEdit2->pushToHistory();
}

//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

TaskDlgPadParameters::TaskDlgPadParameters(ViewProviderPad *PadView)
TaskDlgPadParameters::TaskDlgPadParameters(ViewProviderPad *PadView,bool newObj)
: TaskDialog(),PadView(PadView)
{
assert(PadView);
parameter = new TaskPadParameters(PadView);
parameter = new TaskPadParameters(PadView,newObj);

Content.push_back(parameter);
}
Expand All @@ -465,6 +483,9 @@ bool TaskDlgPadParameters::accept()
{
std::string name = PadView->getObject()->getNameInDocument();

// save the history
parameter->saveHistory();

try {
//Gui::Command::openCommand("Pad changed");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Length = %f",name.c_str(),parameter->getLength());
Expand Down
5 changes: 3 additions & 2 deletions src/Mod/PartDesign/Gui/TaskPadParameters.h
Expand Up @@ -49,7 +49,7 @@ class TaskPadParameters : public Gui::TaskView::TaskBox, public Gui::SelectionOb
Q_OBJECT

public:
TaskPadParameters(ViewProviderPad *PadView,QWidget *parent = 0);
TaskPadParameters(ViewProviderPad *PadView,bool newObj=false,QWidget *parent = 0);
~TaskPadParameters();

int getMode(void) const;
Expand All @@ -59,6 +59,7 @@ class TaskPadParameters : public Gui::TaskView::TaskBox, public Gui::SelectionOb
bool getMidplane(void) const;
QByteArray getFaceName(void) const;
const bool updateView() const;
void saveHistory(void);

private Q_SLOTS:
void onLengthChanged(double);
Expand Down Expand Up @@ -89,7 +90,7 @@ class TaskDlgPadParameters : public Gui::TaskView::TaskDialog
Q_OBJECT

public:
TaskDlgPadParameters(ViewProviderPad *PadView);
TaskDlgPadParameters(ViewProviderPad *PadView,bool newObj=false);
~TaskDlgPadParameters();

ViewProviderPad* getPadView() const
Expand Down
11 changes: 9 additions & 2 deletions src/Mod/PartDesign/Gui/TaskPadParameters.ui
Expand Up @@ -44,7 +44,7 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox">
<widget class="Gui::InputField" name="lengthEdit">
<property name="minimum">
<double>0.000000000000000</double>
</property>
Expand Down Expand Up @@ -88,7 +88,7 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox2">
<widget class="Gui::InputField" name="lengthEdit2">
<property name="minimum">
<double>0.000000000000000</double>
</property>
Expand Down Expand Up @@ -139,5 +139,12 @@
</layout>
</widget>
<resources/>
<customwidgets>
<customwidget>
<class>Gui::InputField</class>
<extends>QLineEdit</extends>
<header>Gui/InputField.h</header>
</customwidget>
</customwidgets>
<connections/>
</ui>
4 changes: 2 additions & 2 deletions src/Mod/PartDesign/Gui/ViewProviderPad.cpp
Expand Up @@ -65,7 +65,7 @@ void ViewProviderPad::setupContextMenu(QMenu* menu, QObject* receiver, const cha

bool ViewProviderPad::setEdit(int ModNum)
{
if (ModNum == ViewProvider::Default ) {
if (ModNum == ViewProvider::Default || ModNum == 1 ) {
// When double-clicking on the item for this pad the
// object unsets and sets its edit mode without closing
// the task panel
Expand Down Expand Up @@ -95,7 +95,7 @@ bool ViewProviderPad::setEdit(int ModNum)
if (padDlg)
Gui::Control().showDialog(padDlg);
else
Gui::Control().showDialog(new TaskDlgPadParameters(this));
Gui::Control().showDialog(new TaskDlgPadParameters(this,ModNum == 1));

return true;
}
Expand Down

0 comments on commit 1ec1033

Please sign in to comment.