//--------------------------------------------------------- bool CCMD_Module::_Get_Parameters(CSG_Parameters *pParameters) { if( !pParameters || m_CMD.Parse(false) != 0 ) { return( false ); } //----------------------------------------------------- int i; for(i=0; i<pParameters->Get_Count(); i++) { CSG_Parameter *pParameter = pParameters->Get_Parameter(i); if( pParameter->is_Input() ) { // nop now, loading options first } else if( pParameter->is_Output() ) { if( pParameter->is_DataObject() && pParameter->is_Optional() && !pParameter->asDataObject() && m_CMD.Found(_Get_ID(pParameter)) ) { pParameter->Set_Value(DATAOBJECT_CREATE); } } else if( pParameter->is_Option() && !pParameter->is_Information() ) { long l; double d; wxString s; switch( pParameter->Get_Type() ) { default: break; case PARAMETER_TYPE_Parameters: _Get_Parameters(pParameter->asParameters()); break; case PARAMETER_TYPE_Bool: pParameter->Set_Value(m_CMD.Found(_Get_ID(pParameter)) ? 1 : 0); break; case PARAMETER_TYPE_Int: if( m_CMD.Found(_Get_ID(pParameter), &l) ) { pParameter->Set_Value((int)l); } break; case PARAMETER_TYPE_Choice: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { if( s.ToLong(&l) ) { pParameter->Set_Value((int)l); } else { pParameter->Set_Value(CSG_String(&s)); } } break; case PARAMETER_TYPE_Double: case PARAMETER_TYPE_Degree: if( m_CMD.Found(_Get_ID(pParameter), &s) && s.ToDouble(&d) ) { pParameter->Set_Value(d); } break; case PARAMETER_TYPE_Range: if( m_CMD.Found(_Get_ID(pParameter, wxT("MIN")), &s) && s.ToDouble(&d) ) { pParameter->asRange()->Set_LoVal(d); } if( m_CMD.Found(_Get_ID(pParameter, wxT("MAX")), &s) && s.ToDouble(&d) ) { pParameter->asRange()->Set_HiVal(d); } break; case PARAMETER_TYPE_String: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { pParameter->Set_Value(CSG_String(&s)); } break; case PARAMETER_TYPE_Text: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { CSG_File Stream; if( Stream.Open(CSG_String(&s)) ) { CSG_String t; Stream.Read(t, Stream.Length()); pParameter->Set_Value(t.c_str()); } else { pParameter->Set_Value(CSG_String(&s)); } } break; case PARAMETER_TYPE_FilePath: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { if( pParameter->asFilePath()->is_Multiple() ) { s.Prepend(wxT("\"")); s.Replace(wxT(";"), wxT("\" \"")); s.Append (wxT("\"")); } pParameter->Set_Value(CSG_String(&s)); } break; case PARAMETER_TYPE_FixedTable: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { CSG_Table Table(&s); pParameter->asTable()->Assign_Values(&Table); } break; case PARAMETER_TYPE_Grid_System: if( pParameter->Get_Children_Count() == 0 ) { long nx, ny; double d, x, y; if( !m_CMD.Found(_Get_ID(pParameter, wxT("NX")), &nx) || !m_CMD.Found(_Get_ID(pParameter, wxT("NY")), &ny) || !m_CMD.Found(_Get_ID(pParameter, wxT( "X")), &s) || !s.ToDouble(&x) || !m_CMD.Found(_Get_ID(pParameter, wxT( "Y")), &s) || !s.ToDouble(&y) || !m_CMD.Found(_Get_ID(pParameter, wxT( "D")), &s) || !s.ToDouble(&d) ) { pParameter->asGrid_System()->Assign(-1, 0.0, 0.0, 0, 0); } else { pParameter->asGrid_System()->Assign(d, x, y, (int)nx, (int)ny); } } break; } } } m_pModule->Update_Parameter_States(); //----------------------------------------------------- for(i=0; i<pParameters->Get_Count(); i++) { CSG_Parameter *pParameter = pParameters->Get_Parameter(i); if( pParameter->is_Input() ) { if( !_Load_Input(pParameters->Get_Parameter(i)) ) { CMD_Print_Error(pParameters->Get_Parameter(i)->Get_Name()); return( false ); } } else if( pParameter->is_Option() && !pParameter->is_Information() ) { long l; wxString s; switch( pParameter->Get_Type() ) { case PARAMETER_TYPE_Table_Field: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { if( s.ToLong(&l) ) { pParameter->Set_Value((int)l); } else { pParameter->Set_Value(CSG_String(&s)); } } break; case PARAMETER_TYPE_Table_Fields: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { pParameter->Set_Value(CSG_String(&s)); } break; } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CCMD_Module::_Set_Parameters(CSG_Parameters *pParameters, bool bOptional) { if( !pParameters ) { return( false ); } //----------------------------------------------------- for(int i=0; i<pParameters->Get_Count(); i++) { CSG_Parameter *pParameter = pParameters->Get_Parameter(i); wxString Description = pParameter->Get_Description( PARAMETER_DESCRIPTION_NAME|PARAMETER_DESCRIPTION_TYPE|PARAMETER_DESCRIPTION_PROPERTIES, SG_T("\n\t") ).c_str(); Description.Replace(wxT("\xb2"), wxT("2")); // unicode problem: quick'n'dirty bug fix, to be replaced if( pParameter->is_Input() || pParameter->is_Output() ) { m_CMD.AddOption(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_NEEDS_SEPARATOR | (pParameter->is_Optional() || pParameter->is_Output() || bOptional ? wxCMD_LINE_PARAM_OPTIONAL : wxCMD_LINE_OPTION_MANDATORY )); } else if( pParameter->is_Option() && !pParameter->is_Information() ) { switch( pParameter->Get_Type() ) { default: break; case PARAMETER_TYPE_Parameters: _Set_Parameters(pParameter->asParameters(), true); break; case PARAMETER_TYPE_Bool: m_CMD.AddSwitch(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_Int: m_CMD.AddOption(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_Choice: case PARAMETER_TYPE_Table_Field: case PARAMETER_TYPE_Table_Fields: m_CMD.AddOption(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_Double: case PARAMETER_TYPE_Degree: m_CMD.AddOption(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_Range: m_CMD.AddOption(_Get_ID(pParameter, wxT("MIN")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); m_CMD.AddOption(_Get_ID(pParameter, wxT("MAX")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_String: case PARAMETER_TYPE_Text: case PARAMETER_TYPE_FilePath: m_CMD.AddOption(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_FixedTable: m_CMD.AddOption(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_Grid_System: if( pParameter->Get_Children_Count() == 0 ) { m_CMD.AddOption(_Get_ID(pParameter, wxT("NX")), wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL); m_CMD.AddOption(_Get_ID(pParameter, wxT("NY")), wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL); m_CMD.AddOption(_Get_ID(pParameter, wxT( "X")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); m_CMD.AddOption(_Get_ID(pParameter, wxT( "Y")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); m_CMD.AddOption(_Get_ID(pParameter, wxT( "D")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); } break; } } } return( true ); }