Fully implement Units in PartDesign Pad

This commit is contained in:
jriegel 2014-02-09 16:22:40 +01:00
parent 3f9642136c
commit a97f53a5e7
8 changed files with 48 additions and 13 deletions

View File

@ -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;

View File

@ -70,6 +70,8 @@ public:
*/
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

View File

@ -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");
}

View File

@ -26,6 +26,7 @@
#include <App/PropertyUnits.h>
#include <App/PropertyStandard.h>
#include <App/PropertyUnits.h>
#include "FeatureAdditive.h"
namespace PartDesign
@ -39,8 +40,8 @@ public:
Pad();
App::PropertyEnumeration Type;
App::PropertyLength Length;
App::PropertyLength Length2;
App::PropertyQuantity Length;
App::PropertyQuantity Length2;
App::PropertyLinkSub UpToFace;
/** @name methods override feature */

View File

@ -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();

View File

@ -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
@ -89,12 +89,16 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
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;
@ -112,6 +116,13 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
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
@ -143,7 +154,7 @@ void TaskPadParameters::updateUI(int index)
{
if (index == 0) { // dimension
ui->lengthEdit->setEnabled(true);
ui->lengthEdit->selectAll();
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.
@ -429,16 +440,23 @@ void TaskPadParameters::changeEvent(QEvent *e)
}
}
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);
}
@ -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());

View File

@ -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;
@ -59,6 +59,7 @@ public:
bool getMidplane(void) const;
QByteArray getFaceName(void) const;
const bool updateView() const;
void saveHistory(void);
private Q_SLOTS:
void onLengthChanged(double);
@ -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

View File

@ -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
@ -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;
}