bool New_property_group::init( std::string& parameters, GsTL_project* proj, Error_messages_handler* errors ){ std::vector< std::string > params = String_Op::decompose_string( parameters, Actions::separator, Actions::unique ); if( params.size() < 2 ) { errors->report( "Must have at least 2 parameters, name of the grid and name the group" ); return false; } // Get the grid std::string grid_name = params[0]; SmartPtr<Named_interface> ni = Root::instance()->interface( gridModels_manager + "/" + grid_name); Geostat_grid* grid = dynamic_cast<Geostat_grid*>( ni.raw_ptr() ); if(!grid) { errors->report( "The grid "+params[0]+" does not exist" ); return false; } GsTLGridPropertyGroup* group = grid->get_group(params[1]); if(group) { errors->report( "The goup "+params[1]+" already exist; hence cannot be created" ); return false; } std::string type = ""; if( params.size() == 3 ) { if( params[2] == "General" ) type = ""; else type = params[2]; } group = grid->add_group(params[1],type); if(!group) { errors->report( "The goup "+params[1]+" could no be created; possibly type undefined" ); return false; } for(int i=3; i< params.size(); i++) { Grid_continuous_property* prop = grid->property(params[i]); if(prop == NULL) { errors->report( "The property "+params[i]+" does not exist" ); return false; } } for(int i=3; i< params.size(); i++) { group->add_property(grid->property(params[i])); } proj->update(); return true; }
bool Remove_properties_from_group::init( std::string& parameters, GsTL_project* proj, Error_messages_handler* errors ){ std::vector< std::string > params = String_Op::decompose_string( parameters, Actions::separator, Actions::unique ); if( params.size() < 3 ) { errors->report( "Must have at least 3 parameters, name of the grid and name the group and at least one property" ); return false; } // Get the grid SmartPtr<Named_interface> ni = Root::instance()->interface( gridModels_manager + "/" + params[0] ); Geostat_grid* grid = dynamic_cast<Geostat_grid*>( ni.raw_ptr() ); if(!grid) { errors->report( "The grid "+params[0]+" does not exist" ); return false; } GsTLGridPropertyGroup* group = grid->get_group(params[1]); if(!group) { errors->report( "The goup "+params[1]+" does not exist" ); return false; } for(int i=2; i< params.size(); i++) { Grid_continuous_property* prop = grid->property(params[i]); if(prop == NULL) { errors->report( "The property "+params[i]+" does not exist" ); return false; } } for(int i=2; i< params.size(); i++) { if( group->is_member_property( params[i] ) ) group->remove_property(grid->property(params[i])); } return true; }
Grid_continuous_property* QPplot_control_panel::get_property( const PropertySelector* object_selector ) { std::string grid_name( qstring2string(object_selector->selectedGrid()) ); if( grid_name.empty() ) return 0; Geostat_grid* grid = dynamic_cast<Geostat_grid*>( Root::instance()->interface( gridModels_manager + "/" + grid_name ).raw_ptr() ); appli_assert( grid ); std::string prop_name( qstring2string(object_selector->selectedProperty()) ); Grid_continuous_property* prop = grid->property( prop_name ); appli_assert( prop ); return prop; }
GsTLGridProperty* Histogram_control_panel::get_property( const PropertySelector* object_selector ) { if( object_selector->selectedGrid().isEmpty() || object_selector->selectedProperty().isEmpty() ) return 0; std::string grid_name( object_selector->selectedGrid().latin1() ); Geostat_grid* grid = dynamic_cast<Geostat_grid*>( Root::instance()->interface( gridModels_manager + "/" + grid_name ).raw_ptr() ); appli_assert( grid ); std::string prop_name( object_selector->selectedProperty().latin1() ); GsTLGridProperty* prop = grid->property( prop_name ); appli_assert( prop ); return prop; }
/* Convert_continuous_to_categorical_property grid_name::prop1::[prop2::] * will copy convert the property from continuous to categorical */ bool Convert_continuous_to_categorical_property:: init( std::string& parameters, GsTL_project* proj, Error_messages_handler* errors ) { std::vector< std::string > params = String_Op::decompose_string( parameters, Actions::separator, Actions::unique ); if( params.size() <2 ) { errors->report( "some parameters are missing, Needs at least two parameters (grid + property)" ); return false; } SmartPtr<Named_interface> grid_ni = Root::instance()->interface( gridModels_manager + "/" + params[0] ); Geostat_grid* grid = dynamic_cast<Geostat_grid*>( grid_ni.raw_ptr() ); if( !grid ) { std::ostringstream message; message << "No grid called \"" << params[0] << "\" was found"; errors->report( message.str() ); return false; } for(int i=1; i<params.size(); ++i) { Grid_categorical_property* cprop = grid->categorical_property(params[i]); if(cprop) continue; Grid_continuous_property* prop = grid->property(params[i]); if(prop == 0) continue; std::set<int> cat_codes; std::string prop_name = prop->name()+" - categorical"; cprop = grid->add_categorical_property(prop_name); while(!cprop) { prop_name.append("_0"); cprop = grid->add_categorical_property(prop_name); } for(int nodeid=0; nodeid < prop->size(); ++nodeid) { if( prop->is_informed(nodeid)) { int code = static_cast<int>(prop->get_value(nodeid)); cprop->set_value(code,nodeid); cat_codes.insert(code); } } // Check is sequential coding bool is_sequential_coding = false; std::set<int>::iterator it = cat_codes.begin(); if( *it == 0 ) { std::advance(it, cat_codes.size()-1); if( *it == cat_codes.size()-1 ) { is_sequential_coding = true; } } if( !is_sequential_coding ) { // Need to build a categorical definition CategoricalPropertyDefinitionName* cat_def = 0; std::string catdef_name = grid->name()+"-"+prop->name(); while(!cat_def) { SmartPtr<Named_interface> ni = Root::instance()->new_interface( "categoricaldefinition://"+catdef_name,categoricalDefinition_manager +"/"+catdef_name ); cat_def = dynamic_cast<CategoricalPropertyDefinitionName*>(ni.raw_ptr()); if(!cat_def) catdef_name.append("_0"); } std::set<int>::iterator it_cat_codes = cat_codes.begin(); for(; it_cat_codes != cat_codes.end(); ++it_cat_codes) { cat_def->add_category(*it_cat_codes, QString("Code %1").arg(*it_cat_codes).toStdString() ); } cprop->set_category_definition( cat_def ); } } proj->update( params[0] ); return true; }
bool Save_scatterplot::init( std::string& parameters, GsTL_project* proj, Error_messages_handler* errors ) { std::vector< std::string > params = String_Op::decompose_string( parameters, Actions::separator, Actions::unique ); if( params.size() < 4 ) { errors->report( "Usage: SaveScatterplot grid prop1 prop2 file [format " "stats_flag grid_flag logY logX]" ); return false; } SmartPtr<Named_interface> grid_ni = Root::instance()->interface( gridModels_manager + "/" + params[0] ); Geostat_grid* grid = dynamic_cast<Geostat_grid*>( grid_ni.raw_ptr() ); if( !grid ) { std::ostringstream message; message << "No grid called \"" << params[0] << "\" was found"; errors->report( message.str() ); return false; } GsTLGridProperty* prop1 = grid->property( params[1] ); GsTLGridProperty* prop2 = grid->property( params[2] ); if( !prop1 || !prop2 ) { std::ostringstream message; message << "Grid \"" << params[0] << "\" has no property called \"" ; if (!prop1 ) message << params[1] << "\" "; if (!prop2 ) message << params[2] << "\" "; errors->report( message.str() ); return false; } // check if we can write to the requested file QFile file( params[3].c_str() ); if( !file.open( IO_WriteOnly ) ) { std::ostringstream message; message << "Can't open file " << params[3]; errors->report( message.str() ); return false; } file.close(); Scatterplot_gui* scplot = new Scatterplot_gui( proj, 0 ); scplot->get_var1_data_from( prop1 ); scplot->get_var2_data_from( prop2 ); std::string format = "PNG"; bool show_stats = true; bool show_grid = false; // check if other options were input if( params.size() >= 5 ) { format = params[4] ; } if( params.size() >= 6 ) { show_stats = String_Op::to_number<bool>( params[5] ); } if( params.size() >= 7 ) { show_grid = String_Op::to_number<bool>( params[6] ); } if( params.size() >= 8 ) { bool ylog = String_Op::to_number<bool>( params[7] ); scplot->set_y_axis_logscale( ylog ); } if( params.size() >= 8 ) { bool xlog = String_Op::to_number<bool>( params[7] ); scplot->set_x_axis_logscale( xlog ); } scplot->show(); scplot->save_as_image( params[3].c_str(), format.c_str(), show_stats, show_grid ); scplot->hide(); delete scplot; return true; }
bool Save_histogram::init( std::string& parameters, GsTL_project* proj, Error_messages_handler* errors ) { std::vector< std::string > params = String_Op::decompose_string( parameters, Actions::separator, Actions::unique ); // TL modified if( params.size() < 3 ) { errors->report( "Usage: SaveHistogram grid prop file [format #bins " "logscaling_flag show_stats_flag show_grid_flag cdf_flag]" ); return false; } SmartPtr<Named_interface> grid_ni = Root::instance()->interface( gridModels_manager + "/" + params[0] ); Geostat_grid* grid = dynamic_cast<Geostat_grid*>( grid_ni.raw_ptr() ); if( !grid ) { std::ostringstream message; message << "No grid called \"" << params[0] << "\" was found"; errors->report( message.str() ); return false; } GsTLGridProperty* prop = grid->property( params[1] ); if( !prop ) { std::ostringstream message; message << "Grid \"" << params[0] << "\" has no property called \"" << params[1] << "\""; errors->report( message.str() ); return false; } // check if we can write to the requested file QFile file( params[2].c_str() ); if( !file.open( IO_WriteOnly ) ) { std::ostringstream message; message << "Can't open file " << params[2]; errors->report( message.str() ); return false; } file.close(); //TL modified bool cdf_flag = true; if (params.size() == 9) { if (params[8] == "0") { appli_message("Turning off cdf"); cdf_flag = false; } } Histogram_gui* histog = new Histogram_gui( proj, 0 ); //TL modified if (cdf_flag) histog->changeCurve("pdf+cdf"); else histog->changeCurve("pdf"); histog->get_data_from( prop ); std::string format = "PNG"; bool show_stats = true; bool show_grid = false; // check if other options were input if( params.size() >= 4 ) { format = params[3] ; } if( params.size() >= 5 ) { int bins = String_Op::to_number<int>( params[4] ); histog->update_bins( bins ); } if( params.size() >= 6 ) { bool logscale = String_Op::to_number<bool>( params[5] ); histog->set_x_axis_logscale( logscale ); } if( params.size() >= 7 ) { show_stats = String_Op::to_number<bool>( params[6] ); } if( params.size() >= 8 ) { show_grid = String_Op::to_number<bool>( params[7] ); } histog->show(); histog->save_as_image( params[2].c_str(), format.c_str(), show_stats, show_grid ); histog->hide(); delete histog; return true; }
bool Show_histogram::init( std::string& parameters, GsTL_project* proj, Error_messages_handler* errors ) { std::vector< std::string > params = String_Op::decompose_string( parameters, Actions::separator, Actions::unique ); if( params.size() < 2 ) { // TL modified errors->report( "Usage: ShowHistogram grid prop [#bins " "logscaling_flag cdf_flag]" ); return false; } SmartPtr<Named_interface> grid_ni = Root::instance()->interface( gridModels_manager + "/" + params[0] ); Geostat_grid* grid = dynamic_cast<Geostat_grid*>( grid_ni.raw_ptr() ); if( !grid ) { std::ostringstream message; message << "No grid called \"" << params[0] << "\" was found"; errors->report( message.str() ); return false; } GsTLGridProperty* prop = grid->property( params[1] ); if( !prop ) { std::ostringstream message; message << "Grid \"" << params[0] << "\" has no property called \"" << params[1] << "\""; errors->report( message.str() ); return false; } //TL modified bool cdf_flag = true; if (params.size() == 5) { if (params[4] == "0") { appli_message("Turning off cdf"); cdf_flag = false; } } Histogram_gui* histog = new Histogram_gui( proj, 0 ); if (cdf_flag) histog->changeCurve("pdf+cdf"); else histog->changeCurve("pdf"); histog->get_data_from( prop ); // check if other options were input if( params.size() >= 3 ) { int bins = String_Op::to_number<int>( params[2] ); histog->update_bins( bins ); if( params.size() >= 4 ) { bool logscale = String_Op::to_number<bool>( params[3] ); histog->set_x_axis_logscale( logscale ); } } histog->show(); return true; }