diff --git a/mg/mglib.h b/mg/mglib.h index 04fbc63ff..0365dc47e 100755 --- a/mg/mglib.h +++ b/mg/mglib.h @@ -125,7 +125,7 @@ public: const char * first_um() const { return um().rows() > 0 ? um()[1].get(UMART_UM) : ""; } static void round_um(real& v, const char* to_um); - real convert_to_um(const real& v, const char* to_um, const char* from_um = NULL, bool arrotonda = true); + real convert_to_um(const real& v, const TString& to_um, const TString& from_um = EMPTY_STRING, bool arrotonda = true); TRecord_array & um() const { return body(LF_UMART); } TRecord_array & deslin() const { return body(LF_DESLIN); } diff --git a/mg/mglib02.cpp b/mg/mglib02.cpp index 72204c687..e79277fe6 100755 --- a/mg/mglib02.cpp +++ b/mg/mglib02.cpp @@ -342,18 +342,17 @@ void TArticolo::round_um(real& r, const char* to_um) } } -real TArticolo::convert_to_um(const real& v, const char* to_um, const char* from_um, bool arrotonda) +real TArticolo::convert_to_um(const real& v, const TString& to_um, const TString& from_um, bool arrotonda) { - // Inutile convertire valori nulli ed - // altrettanto inutile convertire un'unica unita' di misura - if (v.is_zero() || um().rows() <= 1) + // Inutile convertire valori nulli + if (v.is_zero() || to_um == from_um) // (|| um().rows() <= 1) Non funzionerebbe coi pesi che non appartengano a LF_UMART return v; // Se from_um non specificato significa che la qta che si desidera convertire e' in UM base // Gli indici delle unita; di misura valide partono da 1 - int i1 = (to_um && *to_um) ? find_um(to_um) : 1; - int i2 = (from_um && *from_um) ? find_um(from_um) : 1; - if (i1 == i2) // Inutile convertire in se stessi + int i1 = to_um.full() ? find_um(to_um) : 1; + int i2 = from_um.full() ? find_um(from_um) : 1; + if (i1 == i2 && i1 > 0) // Inutile convertire in se stessi return v; fraction f(v, UNO); @@ -369,7 +368,7 @@ real TArticolo::convert_to_um(const real& v, const char* to_um, const char* from const TRectype& fromum = cache().get("%UMS", from_um); if (fromum.get("S7") == to_um) { - fc2 = fromum.get_real(UMART_FC); + fc2 = fromum.get_real("R10"); i1 = 1; // La conversione termina qui: non moltiplicare per fc1! } }