partial work on the convertion tab
git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@54 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
f59f1e1580
commit
d33a6925b1
|
@ -74,7 +74,10 @@ unsigned __stdcall CalculationsProcedure(void *)
|
|||
// at the end we're printing the result
|
||||
// if there was a stop signal we continue the main loop without printing any values
|
||||
if( ! GetPrgRes()->GetThreadController()->WasStopSignal() )
|
||||
parser_manager.PrintResult();
|
||||
if( parser_manager.PrintResult() )
|
||||
PostMessage(main_window, WM_SET_LAST_ERROR, (WPARAM)parser_manager.GetLastCode(), 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -446,7 +446,7 @@ void Languages::ConvertingAddType(const char * name)
|
|||
}
|
||||
|
||||
|
||||
void Languages::ConvertingAddUnit(const char * name)
|
||||
void Languages::ConvertingAddUnit(const char * name, double v)
|
||||
{
|
||||
if( converting_type.empty() || converting_type.back().empty() || converting_unit.empty() )
|
||||
return;
|
||||
|
@ -454,6 +454,7 @@ void Languages::ConvertingAddUnit(const char * name)
|
|||
ConvUnit temp;
|
||||
temp.name = name;
|
||||
temp.type = static_cast<int>(converting_type.back().size()-1);
|
||||
temp.value = v;
|
||||
|
||||
converting_unit.back().push_back(temp);
|
||||
}
|
||||
|
@ -468,15 +469,16 @@ void Languages::InitConverting()
|
|||
ConvertingAddType("none");
|
||||
|
||||
ConvertingAddType("length");
|
||||
ConvertingAddUnit("metre");
|
||||
ConvertingAddUnit("mile");
|
||||
ConvertingAddUnit("metre", 1);
|
||||
ConvertingAddUnit("mile", 1600);
|
||||
|
||||
ConvertingAddType("area");
|
||||
ConvertingAddUnit("are");
|
||||
ConvertingAddUnit("square metre");
|
||||
ConvertingAddUnit("are", 10);
|
||||
ConvertingAddUnit("square metre", 1);
|
||||
|
||||
|
||||
// pl
|
||||
// the 'value' param we're using only from the english
|
||||
converting_type.push_back( std::vector<ConvType>() );
|
||||
converting_unit.push_back( std::vector<ConvUnit>() );
|
||||
|
||||
|
@ -596,3 +598,16 @@ int Languages::ConvertingUnitType(int id)
|
|||
{
|
||||
return ConvertingUnitType(current_country, id);
|
||||
}
|
||||
|
||||
// value is taken only from english
|
||||
double Languages::ConvertingUnitValue(int id)
|
||||
{
|
||||
if( converting_unit.empty() )
|
||||
InitConverting();
|
||||
|
||||
if( id >= static_cast<int>(converting_unit[0].size()) )
|
||||
return -1.0;
|
||||
|
||||
return converting_unit[0][id].value;
|
||||
}
|
||||
|
||||
|
|
|
@ -157,6 +157,7 @@ public:
|
|||
std::string name;
|
||||
// int id;
|
||||
int type;
|
||||
double value;
|
||||
};
|
||||
|
||||
|
||||
|
@ -177,7 +178,7 @@ private:
|
|||
std::vector<std::vector<ConvUnit> > converting_unit;
|
||||
|
||||
void ConvertingAddType(const char * name);
|
||||
void ConvertingAddUnit(const char * name);
|
||||
void ConvertingAddUnit(const char * name, double v = 1);
|
||||
|
||||
void InitConverting();
|
||||
|
||||
|
@ -215,6 +216,7 @@ public:
|
|||
int ConvertingTypeSize();
|
||||
int ConvertingUnitSize();
|
||||
|
||||
double ConvertingUnitValue(int id);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ void ParserManager::Init()
|
|||
}
|
||||
|
||||
|
||||
void ParserManager::PrintResult()
|
||||
int ParserManager::PrintResult()
|
||||
{
|
||||
if( code == ttmath::err_ok )
|
||||
{
|
||||
|
@ -222,4 +222,7 @@ void ParserManager::PrintResult()
|
|||
GetPrgRes()->GetLanguages()->ErrorMessage(country, code) );
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ public:
|
|||
this method prints result
|
||||
(a correct value if was or an error instead)
|
||||
*/
|
||||
void PrintResult();
|
||||
int PrintResult();
|
||||
|
||||
|
||||
private:
|
||||
|
@ -128,8 +128,42 @@ private:
|
|||
ttmath::ErrorCode code;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class ValueType>
|
||||
void PrintResult(ttmath::Parser<ValueType> & matparser)
|
||||
int Conversion(ValueType & result)
|
||||
{
|
||||
int convtype = GetPrgRes()->GetConvType();
|
||||
int c = 0;
|
||||
|
||||
if( convtype != 0 )
|
||||
{
|
||||
int input, output;
|
||||
GetPrgRes()->GetConvUnit(convtype, input, output);
|
||||
|
||||
if( input!=-1 && output!=-1 && input!=output )
|
||||
{
|
||||
double vinput = GetPrgRes()->GetLanguages()->ConvertingUnitValue(input);
|
||||
double voutput = GetPrgRes()->GetLanguages()->ConvertingUnitValue(output);
|
||||
|
||||
ValueType vinputbig, voutputbig;
|
||||
vinputbig.FromDouble(vinput);
|
||||
voutputbig.FromDouble(voutput);
|
||||
|
||||
c += result.Mul(voutputbig);
|
||||
c += result.Div(vinputbig);
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
// 1 if carry
|
||||
template<class ValueType>
|
||||
int PrintResult(ttmath::Parser<ValueType> & matparser)
|
||||
{
|
||||
std::string result, part;
|
||||
unsigned int i = 0;
|
||||
|
@ -139,7 +173,14 @@ private:
|
|||
{
|
||||
try
|
||||
{
|
||||
if( matparser.stack[i].value.ToString(part,base_output, always_scientific, when_scientific, rounding) )
|
||||
ValueType result = matparser.stack[i].value;
|
||||
if( Conversion(result) )
|
||||
{
|
||||
code = ttmath::err_overflow;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( result.ToString(part,base_output, always_scientific, when_scientific, rounding) )
|
||||
{
|
||||
// we shouldn't have had this error in the new version of ToStrign(...)
|
||||
// (where we're using a bigger type for calculating)
|
||||
|
@ -158,6 +199,8 @@ private:
|
|||
}
|
||||
|
||||
SetDlgItemText(GetPrgRes()->GetMainWindow(),IDC_OUTPUT_EDIT,result.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -538,7 +538,10 @@ HWND list1 = GetDlgItem(hWnd, IDC_LIST_UNIT_TYPE);
|
|||
if( !ListView_GetItem(list1, &item) )
|
||||
return;
|
||||
|
||||
GetPrgRes()->GetThreadController()->StopCalculating();
|
||||
GetPrgRes()->SetConvType( (int)item.lParam );
|
||||
GetPrgRes()->GetThreadController()->StartCalculating();
|
||||
|
||||
TabConvertFillUpUnitLists(hWnd);
|
||||
}
|
||||
|
||||
|
@ -564,8 +567,11 @@ HWND list2b = GetDlgItem(hWnd, IDC_LIST_UNIT_INPUT2);
|
|||
|
||||
int convtype = GetPrgRes()->GetConvType();
|
||||
int input, output;
|
||||
|
||||
GetPrgRes()->GetThreadController()->StopCalculating();
|
||||
GetPrgRes()->GetConvUnit(convtype, input, output);
|
||||
GetPrgRes()->SetConvUnit(convtype, (int)item.lParam, output );
|
||||
GetPrgRes()->GetThreadController()->StartCalculating();
|
||||
}
|
||||
|
||||
|
||||
|
@ -591,8 +597,11 @@ HWND list3b = GetDlgItem(hWnd, IDC_LIST_UNIT_OUTPUT2);
|
|||
|
||||
int convtype = GetPrgRes()->GetConvType();
|
||||
int input, output;
|
||||
|
||||
GetPrgRes()->GetThreadController()->StopCalculating();
|
||||
GetPrgRes()->GetConvUnit(convtype, input, output);
|
||||
GetPrgRes()->SetConvUnit(convtype, input, (int)item.lParam );
|
||||
GetPrgRes()->GetThreadController()->StartCalculating();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue