/* Method set_from_TreeModel */
void ClusterSettings::set_from_TreeModel (Glib::RefPtr<Gtk::ListStore> 
                                          list_store)
{
  /* Get list store contents */
  list_store->foreach_iter (sigc::mem_fun (*this,
                             &ClusterSettings::on_foreach_iter));
}
示例#2
0
/* Method TreeModel_to_XML */
void ClusterSettings::TreeModel_to_XML (const Glib::ustring& filename,
                                Glib::RefPtr<Gtk::ListStore> sensors_list)
{
  /* Get ListStore contents */
  sensors_list->foreach_iter (sigc::mem_fun (*this,
                             &ClusterSettings::on_foreach_iter));

  /* Create xml document */
  xmlpp::Document doc;

  /* Create root node */
  xmlpp::Element *root_node = doc.create_root_node ("SensorsClusterSettings");

  /* Add root comment */
  Glib::ustring message;
  message.assign ("File created by ComLibSim at [");
  message.append (filename);
  message.append ("]");
  root_node->add_child_comment (message);

  /* Create and set cluster node */
  xmlpp::Element *cluster_node = root_node->add_child ("Cluster");
  cluster_node->set_attribute ("name", m_Name);

  /* Create and set sensor elements */
  std::list<SensorSettings>::iterator iter;
  for (iter=m_Sensors.begin (); iter != m_Sensors.end (); iter++)
  {
    const SensorSettings& sensor_iter = *iter;

    /* Sensor element */
    xmlpp::Element *sensor_element = cluster_node->add_child ("Sensor");

    /* Set sensor attributes */
    sensor_element->set_attribute ("tag", iter->get_tag ());
    sensor_element->set_attribute ("online", iter->get_online_as_string ());
    Glib::ustring tmp;
    tmp = Glib::ustring::format (std::fixed, std::setprecision (6),
                                 iter->get_x ());
    sensor_element->set_attribute ("x", tmp);
    tmp = Glib::ustring::format (std::fixed, std::setprecision (6),
                                 iter->get_y ());
    sensor_element->set_attribute ("y", tmp);
    tmp = Glib::ustring::format (std::fixed, std::setprecision (0),
                                 iter->get_adata ());
    sensor_element->set_attribute ("adata", tmp);
    sensor_element->set_attribute ("type", iter->get_type ());
  }

  /* Save to xml file */
  doc.write_to_file (filename);
}