← Back to team overview

kicad-developers team mailing list archive

Cleaning up unit conversion from string, makes sense?

 

    I was searching how to convert a string (or double) from user
defined units to internal units value,
and discovered that that functionality was in base_units.cpp,

    Would it make sense to add something like this? (As it's done in
int ReturnValueFromTextCtrl)  .

    It would remove the dependency to global g_UserUnit in the code
segments where we make use of it.

    For me it makes a lot of sense, but may be it was kept like this
for other reason I don't see, probably
I shouldn't be asking for such tiny things :)


    Greetings,
Mike

ajo@vaio:~/work/kicad.testing$ bzr diff
=== modified file 'common/base_units.cpp'
--- common/base_units.cpp	2012-06-25 20:59:19 +0000
+++ common/base_units.cpp	2012-07-22 13:31:26 +0000
@@ -245,6 +245,15 @@
 }


+int ReturnValueFromString( const wxString& aTextValue )
+{
+    int      value;
+
+    value = ReturnValueFromString( g_UserUnit, aTextValue);
+
+    return value;
+}
+
 int ReturnValueFromTextCtrl( const wxTextCtrl& aTextCtr )
 {
     int      value;

=== modified file 'include/base_units.h'
--- include/base_units.h	2012-04-27 14:15:11 +0000
+++ include/base_units.h	2012-07-22 14:12:37 +0000
@@ -108,7 +108,7 @@
 double From_User_Unit( EDA_UNITS_T aUnit, double aValue );

 /**
- * Function ReturnValueFromeString
+ * Function ReturnValueFromString
  * converts \a aTextValue in \a aUnits to internal units used by the
application.
  *
  * @param aUnits The units of \a aTextValue.
@@ -118,6 +118,18 @@
 int ReturnValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue );

 /**
+ * Function ReturnValueFromString
+
+ * converts \a aTextValue in \a aUnits to internal units used by the
application,
+ * unit type will be obtained from g_UserUnit.
+ *
+ * @param aTextValue A reference to a wxString object containing the
string to convert.
+ * @return The string from Value, according to units (inch, mm ...)
for display,
+ */
+
+int ReturnValueFromString( const wxString& aTextValue );
+
+/**
  * Convert the number Value in a string according to the internal units
  *  and the selected unit (g_UserUnit) and put it in the wxTextCtrl TextCtrl
  */


-- 

Miguel Angel Ajo Pelayo
http://www.nbee.es
+34 636 52 25 69
skype: ajoajoajo


Follow ups