예제 #1
0
static void element_row_activated(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, XmiMsimGuiLayerDialog *dialog) {
  GtkTreeIter iter;
  gchar *element;
  double weight;
  GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dialog->compositionTreeView)));

  gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
  gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, SYMBOL_COLUMN,  &element, WEIGHT_COLUMN, &weight, -1);

  GtkWidget *compound_dialog = xmi_msim_gui_compound_dialog_new(GTK_WINDOW(dialog), XMI_MSIM_GUI_COMPOUND_DIALOG_TYPE_EDIT);
  xmi_msim_gui_compound_dialog_set_compound(XMI_MSIM_GUI_COMPOUND_DIALOG(compound_dialog), element);
  xmi_msim_gui_compound_dialog_set_weight(XMI_MSIM_GUI_COMPOUND_DIALOG(compound_dialog), weight);

  int rv = gtk_dialog_run(GTK_DIALOG(compound_dialog));

  if (rv == GTK_RESPONSE_ACCEPT) {
    // weight has been modified by user
    weight = xmi_msim_gui_compound_dialog_get_weight(XMI_MSIM_GUI_COMPOUND_DIALOG(compound_dialog));
    // update model
    gtk_list_store_set(store, &iter,
      WEIGHT_COLUMN, weight,
      -1);
    update_sum(dialog);
  }

  g_free(element);

  gtk_widget_destroy(compound_dialog);

  return;
}
예제 #2
0
static void add_button_clicked(GtkButton *button, XmiMsimGuiLayerDialog *dialog) {
  //make entries empty and disable OK button
  GtkWidget *compound_dialog = xmi_msim_gui_compound_dialog_new(GTK_WINDOW(dialog), XMI_MSIM_GUI_COMPOUND_DIALOG_TYPE_ADD);

  int rv = gtk_dialog_run(GTK_DIALOG(compound_dialog));

  if (rv == GTK_RESPONSE_ACCEPT) {
    //something was changed
    gchar *compound = xmi_msim_gui_compound_dialog_get_compound(XMI_MSIM_GUI_COMPOUND_DIALOG(compound_dialog));
    gdouble compound_weight = xmi_msim_gui_compound_dialog_get_weight(XMI_MSIM_GUI_COMPOUND_DIALOG(compound_dialog));

    struct compoundData *cd, *cd2, *cdsum;
    cd2 = CompoundParser(compound);

    //get current composition
    int n_elements, *Z;
    double *weight;
    xmi_msim_gui_layer_dialog_get_composition(dialog, &n_elements, &Z, &weight);
    if (n_elements > 0) {
      xmi_layer layer = {n_elements, Z, weight, 0.0, 0.0};

      //copy xmi_layer to compoundData and add current contents
      cd = xmi_layer2compoundData(&layer);
      //calculate sum
      cdsum = add_compound_data(*cd, 1.0, *cd2, compound_weight/100.0);
      xmi_msim_gui_layer_dialog_set_composition(dialog, cdsum->nElements, cdsum->Elements, cdsum->massFractions);
      g_free(Z);
      g_free(weight);
      FreeCompoundData(cdsum);
      FreeCompoundData(cd);
    }
    else {
      //list is empty!
      xmi_scale_double(cd2->massFractions, cd2->nElements, compound_weight/100.0);
      if (cd2->nElements == 1) {
        // if compound
        double density = ElementDensity(cd2->Elements[0]);
        gchar *buffer = g_strdup_printf("%f", density);
        g_signal_handler_block(G_OBJECT(dialog->densityEntry), dialog->density_changed);
        gtk_entry_set_text(GTK_ENTRY(dialog->densityEntry), buffer);
        g_signal_handler_unblock(G_OBJECT(dialog->densityEntry), dialog->density_changed);
	g_free(buffer);
      }
      xmi_msim_gui_layer_dialog_set_composition(dialog, cd2->nElements, cd2->Elements, cd2->massFractions);
    }
    FreeCompoundData(cd2);
  }

  gtk_widget_destroy(compound_dialog);

  return;
}
예제 #3
0
static void edit_button_clicked(GtkButton *button, XmiMsimGuiLayerDialog *dialog) {
  GtkTreeIter iter;
  GtkTreeModel *model;
  gchar *element;
  double weight;
  GList *paths;
  GtkTreeSelection *select = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->compositionTreeView));

  //get selection
  paths = gtk_tree_selection_get_selected_rows(select, &model);
  GtkTreePath *path = (GtkTreePath *) g_list_nth_data(paths, 0);
  gtk_tree_model_get_iter(model, &iter, path);

  //get data from selected
  gtk_tree_model_get(model, &iter, SYMBOL_COLUMN,  &element, WEIGHT_COLUMN, &weight,  -1);

  //put it in dialog
  GtkWidget *compound_dialog = xmi_msim_gui_compound_dialog_new(GTK_WINDOW(dialog), XMI_MSIM_GUI_COMPOUND_DIALOG_TYPE_EDIT);
  xmi_msim_gui_compound_dialog_set_compound(XMI_MSIM_GUI_COMPOUND_DIALOG(compound_dialog), element);
  xmi_msim_gui_compound_dialog_set_weight(XMI_MSIM_GUI_COMPOUND_DIALOG(compound_dialog), weight);

  int rv = gtk_dialog_run(GTK_DIALOG(compound_dialog));

  if (rv == GTK_RESPONSE_ACCEPT) {
    //something was changed
    weight = xmi_msim_gui_compound_dialog_get_weight(XMI_MSIM_GUI_COMPOUND_DIALOG(compound_dialog));
    // update model
    gtk_list_store_set(GTK_LIST_STORE(model), &iter,
      WEIGHT_COLUMN, weight,
      -1);
    update_sum(dialog);
  }

  g_free(element);
  g_list_free_full(paths, (GDestroyNotify) gtk_tree_path_free);

  gtk_widget_destroy(compound_dialog);

  return;
}
예제 #4
0
static void xmi_msim_compound_dialog_get_property(GObject *object, guint prop_id, GValue *value,  GParamSpec *pspec) {

  XmiMsimGuiCompoundDialog *dialog = XMI_MSIM_GUI_COMPOUND_DIALOG(object);

  switch (prop_id) {
    case PROP_COMPOUND_DIALOG_TYPE:
      dialog->compound_dialog_type = g_value_get_enum(value);
      g_value_set_enum (value, (XmiMsimGuiCompoundDialogType) dialog->compound_dialog_type);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  }
}
예제 #5
0
static void xmi_msim_compound_dialog_set_property(GObject *object, guint prop_id, const GValue *value,  GParamSpec *pspec) {

  XmiMsimGuiCompoundDialog *dialog = XMI_MSIM_GUI_COMPOUND_DIALOG(object);

  switch (prop_id) {
    case PROP_COMPOUND_DIALOG_TYPE:
      dialog->compound_dialog_type = g_value_get_enum(value);
      if (dialog->compound_dialog_type == XMI_MSIM_GUI_COMPOUND_DIALOG_ADD) {
        gtk_window_set_title(GTK_WINDOW(dialog), "Enter a compound");
        gtk_widget_set_sensitive(gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT), FALSE);
	gtk_editable_set_editable(GTK_EDITABLE(dialog->compoundEntry), TRUE);
      }
      else if (dialog->compound_dialog_type == XMI_MSIM_GUI_COMPOUND_DIALOG_EDIT) {
        gtk_window_set_title(GTK_WINDOW(dialog), "Modify a compound");
	gtk_editable_set_editable(GTK_EDITABLE(dialog->compoundEntry), FALSE);
	gtk_widget_set_sensitive(dialog->compoundEntry, FALSE);
      }
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  }

}