Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev-quantity'
Browse files Browse the repository at this point in the history
  • Loading branch information
jriegel committed Nov 9, 2013
2 parents 909f7d6 + 46db0c2 commit 3e8a20a
Show file tree
Hide file tree
Showing 14 changed files with 623 additions and 37 deletions.
8 changes: 4 additions & 4 deletions src/App/FeatureTest.cpp
Expand Up @@ -98,10 +98,10 @@ FeatureTest::FeatureTest()

ADD_PROPERTY(QuantityLength,(1.0));
QuantityLength.setUnit(Base::Unit::Length);
ADD_PROPERTY(QuantityMass,(1.0));
QuantityMass.setUnit(Base::Unit::Mass);
ADD_PROPERTY(QuantityAngle,(1.0));
QuantityAngle.setUnit(Base::Unit::Angle);
//ADD_PROPERTY(QuantityMass,(1.0));
//QuantityMass.setUnit(Base::Unit::Mass);
//ADD_PROPERTY(QuantityAngle,(1.0));
//QuantityAngle.setUnit(Base::Unit::Angle);

}

Expand Down
4 changes: 2 additions & 2 deletions src/App/FeatureTest.h
Expand Up @@ -94,8 +94,8 @@ class FeatureTest : public DocumentObject
App::PropertyInteger TypeTransient;

App::PropertyQuantity QuantityLength;
App::PropertyQuantity QuantityMass;
App::PropertyQuantity QuantityAngle;
//App::PropertyQuantity QuantityMass;
//App::PropertyQuantity QuantityAngle;

/** @name methods overide Feature */
//@{
Expand Down
42 changes: 36 additions & 6 deletions src/Base/Quantity.cpp
Expand Up @@ -38,6 +38,13 @@
# pragma warning(disable : 4335) // disable MAC file format warning on VC
#endif

#ifndef DOUBLE_MAX
# define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/
#endif
#ifndef DOUBLE_MIN
# define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/
#endif

using namespace Base;

Quantity::Quantity()
Expand Down Expand Up @@ -113,18 +120,41 @@ double Quantity::getUserPrefered(QString &unitString)const
return Base::UnitsApi::schemaPrefUnit(_Unit,unitString).getValue() * _Value;
}

std::string Quantity::getUserString(void)const
{
std::stringstream sstream;
sstream << _Value << _Unit.getString();
//TODO: implementing
return sstream.str();
}

/// true if it has a number without a unit
bool Quantity::isDimensionless(void)const
{
return _Value != DOUBLE_MIN && _Unit.isEmpty();
}
// true if it has a number and a valid unit
bool Quantity::isQuantity(void)const
{
return _Value != DOUBLE_MIN && !_Unit.isEmpty();
}
// true if it has a number with or without a unit
bool Quantity::isValid(void)const
{
return _Value != DOUBLE_MIN ;
}

void Quantity::setInvalid(void)
{
_Value = DOUBLE_MIN ;
}

// === Parser & Scanner stuff ===============================================

// include the Scanner and the Parser for the Quantitys

Quantity QuantResult;

#ifndef DOUBLE_MAX
# define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/
#endif
#ifndef DOUBLE_MIN
# define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/
#endif


// error func
Expand Down
10 changes: 10 additions & 0 deletions src/Base/Quantity.h
Expand Up @@ -66,6 +66,16 @@ class BaseExport Quantity
double getValue(void) const{return _Value;}
void setValue(double val){_Value = val;}

/// true if it has a number without a unit
bool isDimensionless(void)const;
/// true if it has a number and a valid unit
bool isQuantity(void)const;
/// true if it has a number with or without a unit
bool isValid(void)const;
/// sets the quantity invalid
void setInvalid(void);


protected:
double _Value;
Unit _Unit;
Expand Down
5 changes: 5 additions & 0 deletions src/Gui/CMakeLists.txt
Expand Up @@ -129,6 +129,7 @@ set(Gui_MOC_HDRS
DownloadManager.h
DlgActionsImp.h
DlgActivateWindowImp.h
DlgUnitsCalculatorImp.h
DlgCommandsImp.h
DlgCustomizeImp.h
DlgCustomizeSpaceball.h
Expand Down Expand Up @@ -219,6 +220,7 @@ SET(Gui_UIC_SRCS
DemoMode.ui
DlgActions.ui
DlgActivateWindow.ui
DlgUnitsCalculator.ui
DlgAuthorization.ui
DlgChooseIcon.ui
DlgCommands.ui
Expand Down Expand Up @@ -295,6 +297,7 @@ SET(Dialog_CPP_SRCS
Clipping.cpp
DemoMode.cpp
DlgActivateWindowImp.cpp
DlgUnitsCalculatorImp.cpp
DlgDisplayPropertiesImp.cpp
DlgInputDialogImp.cpp
DlgMacroExecuteImp.cpp
Expand Down Expand Up @@ -323,6 +326,7 @@ SET(Dialog_HPP_SRCS
Clipping.h
DemoMode.h
DlgActivateWindowImp.h
DlgUnitsCalculatorImp.h
DlgDisplayPropertiesImp.h
DlgInputDialogImp.h
DlgMacroExecuteImp.h
Expand Down Expand Up @@ -354,6 +358,7 @@ SET(Dialog_SRCS
Clipping.ui
DemoMode.ui
DlgActivateWindow.ui
DlgUnitsCalculator.ui
DlgAuthorization.ui
DlgDisplayProperties.ui
DlgInputDialog.ui
Expand Down
24 changes: 24 additions & 0 deletions src/Gui/CommandStd.cpp
Expand Up @@ -61,6 +61,7 @@
#include "WorkbenchManager.h"
#include "Workbench.h"
#include "Selection.h"
#include "DlgUnitsCalculatorImp.h"

using Base::Console;
using Base::Sequencer;
Expand Down Expand Up @@ -647,6 +648,28 @@ void StdCmdMeasurementSimple::activated(int iMsg)
updateActive();
commitCommand();
}
//===========================================================================
// Std_UnitsCalculater
//===========================================================================
DEF_STD_CMD(StdCmdUnitsCalculator);

StdCmdUnitsCalculator::StdCmdUnitsCalculator()
: Command("Std_UnitsCalculater")
{
sGroup = QT_TR_NOOP("Tools");
sMenuText = QT_TR_NOOP("&Units calculator...");
sToolTipText = QT_TR_NOOP("Start the units calculator");
sWhatsThis = QT_TR_NOOP("Start the units calculator");
sStatusTip = QT_TR_NOOP("Start the units calculator");
//sPixmap = "";
eType = 0;
}

void StdCmdUnitsCalculator::activated(int iMsg)
{
Gui::Dialog::DlgUnitsCalculator *dlg = new Gui::Dialog::DlgUnitsCalculator( getMainWindow() );
dlg->show();
}

namespace Gui {

Expand All @@ -673,6 +696,7 @@ void CreateStdCommands(void)
rcCmdMgr.addCommand(new StdCmdFreeCADForum());
rcCmdMgr.addCommand(new StdCmdFreeCADFAQ());
rcCmdMgr.addCommand(new StdCmdPythonWebsite());
rcCmdMgr.addCommand(new StdCmdUnitsCalculator());
//rcCmdMgr.addCommand(new StdCmdMeasurementSimple());
//rcCmdMgr.addCommand(new StdCmdDownloadOnlineHelp());
//rcCmdMgr.addCommand(new StdCmdDescription());
Expand Down
124 changes: 124 additions & 0 deletions src/Gui/DlgUnitsCalculator.ui
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DlgUnitCalculator</class>
<widget class="QWidget" name="DlgUnitCalculator">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>375</width>
<height>139</height>
</rect>
</property>
<property name="windowTitle">
<string>Units calculater</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="Gui::InputField" name="ValueInput">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>as:</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::InputField" name="UnitInput">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>=&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="ValueOutput">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTextEdit" name="textEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton_Help">
<property name="text">
<string>Help</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_Copy">
<property name="text">
<string>Copy</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_Close">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::InputField</class>
<extends>QLineEdit</extends>
<header>Gui/InputField.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit 3e8a20a

Please sign in to comment.