void New_region_from_property_dialog::populate_categories(){
  if( !isCategorical_ ) return;

  QString grid_name = selected_grid();
  QString prop_name = selected_property();
  if(grid_name.isEmpty() || prop_name.isEmpty()) return;
  SmartPtr< Named_interface > ni =
	Root::instance()->interface( gridModels_manager + "/" + grid_name.toStdString() );
  Geostat_grid* grid = dynamic_cast<Geostat_grid*>(ni.raw_ptr());
  Grid_categorical_property *prop = grid->categorical_property(prop_name.toStdString());

  if(!prop) return;

  const CategoricalPropertyDefinition* cat_def = prop->get_category_definition();
  const CategoricalPropertyDefinitionName* cat_def_name =
	  dynamic_cast<const CategoricalPropertyDefinitionName*>(cat_def);

  if( cat_def_name ) {
    cat_selector_->show_categories( cat_def_name->name().c_str() );
  }
  else {
    cat_selector_->show_default_categories( prop->get_number_of_category() );
  }

}
bool Set_not_informed_dialog::execute(){
	  QString grid_name = selected_grid();
	  QString prop_name = selected_property();

	  if( grid_name.isEmpty() || prop_name.isEmpty()) return false;


	  QApplication::setOverrideCursor( Qt::WaitCursor );

	  QString sep = Actions::separator.c_str();
	  QStringList list;
	  list.append( grid_name );
	  list.append( prop_name );

	  std::string command;

		list.append( this->get_min_filter_value() );
		list.append( this->get_max_filter_value() );
		command = "ClearPropertyValueIf";

	  std::string parameters = list.join( sep ).toStdString();
	  if( parameters.empty() ) {
	    GsTLcerr << "Errors with the parameters selected";
	    GsTLcerr << gstlIO::end;
		return false;
	  }

	  // call the DeleteObjectProperties action
	  Error_messages_handler error_messages;



	  bool ok = project_->execute( command, parameters, &error_messages );

	  if( !ok ) {
	    GsTLcerr << "Command " << command << " could not be performed. \n";
	    if( !error_messages.empty() ) {
	      GsTLcerr << error_messages.errors();
	    }
	    GsTLcerr << gstlIO::end;
		return false;
	  }

	  QApplication::restoreOverrideCursor();
	  project_->update();
	  return true;

}
void New_region_from_property_dialog::set_filter_type(){
  QString grid_name = selected_grid();
  QString prop_name = selected_property();
  if(grid_name.isEmpty() || prop_name.isEmpty()) return;
  SmartPtr< Named_interface > ni =
	Root::instance()->interface( gridModels_manager + "/" + grid_name.toStdString() );
  Geostat_grid* grid = dynamic_cast<Geostat_grid*>(ni.raw_ptr());
  Grid_categorical_property *prop = grid->categorical_property(prop_name.toStdString());
  if(prop) {
	  min_max_box_->setHidden(true);
	  category_box_->setVisible(true);
	  isCategorical_ = true;
  } else {
	  category_box_->setHidden(true);
	  min_max_box_->setVisible(true);
	  isCategorical_ = false;
  }

}
bool New_region_from_property_dialog::create_region(){
	  QString grid_name = selected_grid();
	  QString prop_name = selected_property();
	  QString region_name = new_region_name();

	  if( grid_name.isEmpty() || prop_name.isEmpty()) return false;

	  if( region_name.isEmpty() ) {
	    GsTLcerr << "Must provide a name for the region.";
	    GsTLcerr << gstlIO::end;
		  return false;
	  }



	  QApplication::setOverrideCursor( Qt::WaitCursor );

	  QString sep = Actions::separator.c_str();
	  QStringList list;
	  list.append( grid_name );
	  list.append(region_name);
	  list.append( prop_name );

	  std::string command;
	  if(this->isCategorical()) {
		 list.append(this->get_selected_categories());
		 command = "SetRegionFromCategoricalPropertyIf";
	  }
	  else	{
		list.append( this->get_min_filter_value() );
		list.append( this->get_max_filter_value() );
		command = "SetRegionFromPropertyIf";
	  }
	  std::string parameters = list.join( sep ).toStdString();
	  if( parameters.empty() ) {
	    GsTLcerr << "Errors with the parameters selected";
	    GsTLcerr << gstlIO::end;
      QApplication::restoreOverrideCursor();
		  return false;
	  }

	  // call the DeleteObjectProperties action
	  Error_messages_handler error_messages;



	  bool ok = project_->execute( command, parameters, &error_messages );

	  if( !ok ) {
	    GsTLcerr << "Command " << command << " could not be performed. \n";
	    if( !error_messages.empty() ) {
	      GsTLcerr << error_messages.errors();
	    }
	    GsTLcerr << gstlIO::end;
      QApplication::restoreOverrideCursor();
		  return false;
	  }

	  QApplication::restoreOverrideCursor();
	  project_->update();
	  return true;

}