示例#1
0
void VariogramInput_accessor::clear() {
  varg_input_->set_nugget( 0 );
  varg_input_->update_structures_count( 1 );
  Variogram_structure_input* structure = varg_input_->structure( 0 );
  structure->set_contribution( 0 );
  structure->set_ranges( 0,0,0 );
  structure->set_angles( 0,0,0 );
  
}
bool VariogramInput::init_values_from_xml_string( QString& qstr ) {

  

  // qstr is just an element of an xml file, hence can not be parsed

  // by QDomDocument. We need to add a root element.

  qstr = "<root>" + qstr + "</root>";

  QDomDocument doc;

  bool parsed = doc.setContent( qstr );

  appli_assert( parsed );



  QDomElement root_element = doc.documentElement();

  QDomElement elem = root_element.firstChild().toElement();

  

  // Get the nugget value and the number of structures

  QString val = elem.attribute( "nugget" );

  this->set_nugget( val.toFloat() );

  val = elem.attribute( "structures_count" );

  this->update_structures_count( val.toInt() );



  // work on each structure

  for( int i=0; i < this->structures_count() ; i++ ) {

    Variogram_structure_input* structure = this->structure( i );

    appli_assert( structure );

    

    // Get the node describing the structure and initialize the contribution

    // and variogram type values

    QString id;

    id.setNum( i+1 );

    QString structure_tagname = "structure_" + id;

    QDomNodeList nodes = elem.elementsByTagName( structure_tagname );

    if( nodes.count() == 0 ) {

      QByteArray tmp = structure_tagname.toLatin1();

      appli_warning( "No element called \"" << tmp.constData()  << "\"" << std::endl

		    << "Aborting" );

      return false;

    }

    QDomNode structure_node = nodes.item(0);

    appli_assert( structure_node.isElement() );

    QDomElement structure_elem = structure_node.toElement();



    val = structure_elem.attribute( "contribution" );

    structure->set_contribution( val.toFloat() );

    structure->set_variogram_type( structure_elem.attribute( "type" ) );





    // Get the ranges

    QDomNodeList ranges_node_list = structure_elem.elementsByTagName( "ranges" );

    if( ranges_node_list.count() == 0 ) {

      appli_warning( "No element called \"ranges\"" << std::endl

		    << "Aborting" );

      return false;

    }

    QDomNode ranges_node = ranges_node_list.item(0);

    appli_assert( ranges_node.isElement() );

    QDomElement ranges_elem = ranges_node.toElement();

    

    val = ranges_elem.attribute( "max" );

    structure->max_range( val.toFloat() );

    val = ranges_elem.attribute( "medium" );

    structure->medium_range( val.toFloat() );

    val = ranges_elem.attribute( "min" );

    structure->min_range( val.toFloat() );



    

    // Get the angles

    QDomNodeList angles_node_list = structure_elem.elementsByTagName( "angles" );

    if( angles_node_list.count() == 0 ) {

      appli_warning( "No element called \"angles\"" << std::endl

		    << "Aborting" );

      return false;

    }

    QDomNode angles_node = angles_node_list.item(0);

    appli_assert( angles_node.isElement() );

    QDomElement angles_elem = angles_node.toElement();

    

    val = angles_elem.attribute( "x" );

    structure->x_angle( val.toFloat() );

    val = angles_elem.attribute( "y" );

    structure->y_angle( val.toFloat() );

    val = angles_elem.attribute( "z" );

    structure->z_angle( val.toFloat() );



  }



  return true;

}
void VariogramInput::update_structures_count(int val ) {

  int current_count = structures_.size();

  if( current_count == val ) return;



  if( current_count < val ) {

    // add one (or more) new structure(s)

    for( int i=0; i < val - current_count; i ++ ) {

      

      QString count_str;

      count_str.setNum( current_count + i + 1 );



      Line_separator* separator =

      	new Line_separator( "Structure " + count_str);

      Variogram_structure_input* structure = 

	      new Variogram_structure_input();

      

      structures_frame_->layout()->addWidget(separator);

      structures_frame_->layout()->addWidget(structure);

      

      structure->show();

      separator->show();

      structures_.push_back( std::make_pair( separator, structure ) );

    }

  }

  else {

    // remove one (or more) structure(s)

    for( int j = current_count-1; j >= val  ; j -- ) {

      delete structures_[ j ].first;

      delete structures_[ j ].second;

      structures_.pop_back(); 

      

    }

  }



  structures_count_->setValue( val );

}