static void
gnc_column_view_edit_size_cb(GtkButton * button, gpointer user_data)
{
    gnc_column_view_edit * r = user_data;
    GtkWidget * rowspin;
    GtkWidget * colspin;
    GtkWidget * dlg;
    GladeXML *xml;
    SCM current;
    int length;
    int dlg_ret;

    xml = gnc_glade_xml_new ("report.glade", "Edit Report Size");
    dlg = glade_xml_get_widget (xml, "Edit Report Size");

    /* get the spinner widgets */
    rowspin = glade_xml_get_widget (xml, "row_spin");
    colspin = glade_xml_get_widget (xml, "col_spin");

    length = scm_ilength(r->contents_list);
    if (length > r->contents_selected)
    {
        current = scm_list_ref(r->contents_list,
                               scm_int2num(r->contents_selected));
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(colspin),
                                  (float)scm_num2int(SCM_CADR(current),
                                          SCM_ARG1, G_STRFUNC));
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(rowspin),
                                  (float)scm_num2int(SCM_CADDR(current),
                                          SCM_ARG1, G_STRFUNC));

        dlg_ret = gtk_dialog_run(GTK_DIALOG(dlg));
        gtk_widget_hide(dlg);

        if (dlg_ret == GTK_RESPONSE_OK)
        {
            current = SCM_LIST4(SCM_CAR(current),
                                scm_int2num(gtk_spin_button_get_value_as_int
                                            (GTK_SPIN_BUTTON(colspin))),
                                scm_int2num(gtk_spin_button_get_value_as_int
                                            (GTK_SPIN_BUTTON(rowspin))),
                                SCM_BOOL_F);
            scm_gc_unprotect_object(r->contents_list);
            r->contents_list = scm_list_set_x(r->contents_list,
                                              scm_int2num(r->contents_selected),
                                              current);
            scm_gc_protect_object(r->contents_list);
            gnc_options_dialog_changed (r->optwin);
            update_display_lists(r);
        }
        gtk_widget_destroy(dlg);
    }
}
Exemple #2
0
/********************************************************************\
 * gnc_trans_scm_get_split_scm                                      *
 *   get the indexth scheme split of a scheme transaction.          *
 *                                                                  *
 * Args: trans_scm - the scheme transaction                         *
 *       index     - the index of the split to get                  *
 * Returns: scheme split to get, or SCM_UNDEFINED if none           *
\********************************************************************/
SCM
gnc_trans_scm_get_split_scm(SCM trans_scm, int index)
{
    SCM arg;

    initialize_scm_functions();

    if (!gnc_is_trans_scm(trans_scm))
        return SCM_UNDEFINED;

    arg = scm_int2num(index);

    return scm_call_2(getters.trans_scm_split_scm, trans_scm, arg);
}
static void
gnc_column_view_edit_add_cb(GtkButton * button, gpointer user_data)
{
    gnc_column_view_edit * r = user_data;
    SCM make_report = scm_c_eval_string("gnc:make-report");
    SCM mark_report = scm_c_eval_string("gnc:report-set-needs-save?!");
    SCM template_name;
    SCM new_report;
    SCM newlist = SCM_EOL;
    SCM oldlist = r->contents_list;
    int count;
    int oldlength, id;

    if (scm_is_list(r->available_list) &&
            (scm_ilength(r->available_list) > r->available_selected))
    {
        template_name = scm_list_ref(r->available_list,
                                     scm_int2num(r->available_selected));
        new_report = scm_call_1(make_report, template_name);
        id = scm_num2int(new_report, SCM_ARG1, G_STRFUNC);
        scm_call_2(mark_report, gnc_report_find(id), SCM_BOOL_T);
        oldlength = scm_ilength(r->contents_list);

        if (oldlength > r->contents_selected)
        {
            for (count = 0; count < r->contents_selected; count++)
            {
                newlist = scm_cons(SCM_CAR(oldlist), newlist);
                oldlist = SCM_CDR(oldlist);
            }
            newlist = scm_append
                      (scm_listify(scm_reverse(scm_cons(SCM_LIST4(new_report,
                                               scm_int2num(1),
                                               scm_int2num(1),
                                               SCM_BOOL_F),
                                               newlist)),
                                   oldlist,
                                   SCM_UNDEFINED));
        }
        else
        {
            newlist = scm_append
                      (scm_listify(oldlist,
                                   SCM_LIST1(SCM_LIST4(new_report,
                                             scm_int2num(1),
                                             scm_int2num(1),
                                             SCM_BOOL_F)),
                                   SCM_UNDEFINED));
            r->contents_selected = oldlength;
        }

        scm_gc_unprotect_object(r->contents_list);
        r->contents_list = newlist;
        scm_gc_protect_object(r->contents_list);

        gnc_column_view_set_option(r->odb, "__general", "report-list",
                                   r->contents_list);
        gnc_options_dialog_changed (r->optwin);
    }

    update_display_lists(r);
}
static void
update_display_lists(gnc_column_view_edit * view)
{
    SCM   get_names = scm_c_eval_string("gnc:all-report-template-names");
    SCM   template_menu_name = scm_c_eval_string("gnc:report-template-menu-name/report-guid");
    SCM   report_menu_name = scm_c_eval_string("gnc:report-menu-name");
    SCM   names = scm_call_0(get_names);
    SCM   contents =
        gnc_option_db_lookup_option(view->odb, "__general", "report-list",
                                    SCM_BOOL_F);
    SCM   this_report;
    SCM   selection;
    const gchar *name;
    int   row, i, id;
    GtkListStore *store;
    GtkTreeIter iter;
    GtkTreePath *path;
    GtkTreeSelection *tree_selection;


    /* Update the list of available reports (left selection box). */
    row = view->available_selected;

    if (scm_is_list(view->available_list) && !scm_is_null (view->available_list))
    {
        row = MIN (row, scm_ilength (view->available_list) - 1);
        selection = scm_list_ref (view->available_list, scm_int2num (row));
    }
    else
    {
        selection = SCM_UNDEFINED;
    }

    scm_gc_unprotect_object(view->available_list);
    view->available_list = names;
    scm_gc_protect_object(view->available_list);

    store = GTK_LIST_STORE(gtk_tree_view_get_model(view->available));
    gtk_list_store_clear(store);

    if (scm_is_list(names))
    {
        for (i = 0; !scm_is_null(names); names = SCM_CDR(names), i++)
        {
            char * str;

            if (scm_is_equal (SCM_CAR(names), selection))
                row = i;
            scm_dynwind_begin (0); 
            str = scm_to_locale_string (scm_call_2(template_menu_name, SCM_CAR(names),
                                          SCM_BOOL_F));
            name = _(g_strdup (str));
            scm_dynwind_free (str); 
            scm_dynwind_end (); 
            gtk_list_store_append(store, &iter);
            gtk_list_store_set(store, &iter,
                               AVAILABLE_COL_NAME, name,
                               AVAILABLE_COL_ROW, i,
                               -1);
        }

    }

    tree_selection = gtk_tree_view_get_selection(view->available);
    path = gtk_tree_path_new_from_indices(row, -1);
    gtk_tree_selection_select_path(tree_selection, path);
    gtk_tree_path_free(path);


    /* Update the list of selected reports (right selection box). */
    row = view->contents_selected;

    if (scm_is_list(view->contents_list) && !scm_is_null (view->contents_list))
    {
        row = MIN (row, scm_ilength (view->contents_list) - 1);
        selection = scm_list_ref (view->contents_list, scm_int2num (row));
    }
    else
    {
        selection = SCM_UNDEFINED;
    }

    scm_gc_unprotect_object(view->contents_list);
    view->contents_list = contents;
    scm_gc_protect_object(view->contents_list);

    store = GTK_LIST_STORE(gtk_tree_view_get_model(view->contents));
    gtk_list_store_clear(store);
    if (scm_is_list(contents))
    {
        for (i = 0; !scm_is_null(contents); contents = SCM_CDR(contents), i++)
        {
            char * str;

            if (scm_is_equal (SCM_CAR(contents), selection))
                row = i;

            id = scm_num2int(SCM_CAAR(contents), SCM_ARG1, G_STRFUNC);
            this_report = gnc_report_find(id);
            scm_dynwind_begin (0); 
            str = scm_to_locale_string (scm_call_1(report_menu_name, this_report));
            name = _(g_strdup (str));
            scm_dynwind_free (str); 
            scm_dynwind_end (); 

            gtk_list_store_append(store, &iter);
            gtk_list_store_set
            (store, &iter,
             CONTENTS_COL_NAME, name,
             CONTENTS_COL_ROW, i,
             CONTENTS_COL_REPORT_COLS, scm_num2int(SCM_CADR(SCM_CAR(contents)),
                                                   SCM_ARG1, G_STRFUNC),
             CONTENTS_COL_REPORT_ROWS, scm_num2int(SCM_CADDR(SCM_CAR(contents)),
                                                   SCM_ARG1, G_STRFUNC),
             -1);
        }
    }

    tree_selection = gtk_tree_view_get_selection(view->contents);
    path = gtk_tree_path_new_from_indices(row, -1);
    gtk_tree_selection_select_path(tree_selection, path);
    //  gtk_tree_view_scroll_to_cell(view->contents, path, NULL, TRUE, 0.5, 0.0);
    gtk_tree_path_free(path);
}
/* get confinement from SCM
 * in SCM, confinement is given by one of these:
 * for spherical confinement,
 *  (define confinement '(
 *    10.0 ;; LJ parameter epsilon in kT (so this is dimensionless value)
 *    1.0  ;; LJ parameter r0 in "length" (so this is dimensionless value)
 *    "sphere"
 *    10.0 ;; radius of the cavity at (0, 0, 0)
 *  ))
 * for spherical confinement with a hole,
 *  (define confinement '(
 *    10.0 ;; LJ parameter epsilon in kT (so this is dimensionless value)
 *    1.0  ;; LJ parameter r0 in "length" (so this is dimensionless value)
 *    "sphere+hole"
 *    10.0 ;; radius of the cavity at (0, 0, 0)
 *    1.0  ;; radius of the hole at (0, 0, 1) direction
 *  ))
 * for cylindrical confinement,
 *  (define confinement '(
 *    10.0 ;; LJ parameter epsilon in kT (so this is dimensionless value)
 *    1.0  ;; LJ parameter r0 in "length" (so this is dimensionless value)
 *    "cylinder"    ;; the cylinder center goes through (0, 0, 0) and (x, y, z).
 *    10.0          ;; radius of the cylinder
 *    1.0  0.0  0.0 ;; direction vector (x, y, z) of the cylinder
 *  ))
 * for dumbbell confinement,
 *  (define confinement '(
 *    10.0 ;; LJ parameter epsilon in kT (so this is dimensionless value)
 *    1.0  ;; LJ parameter r0 in "length" (so this is dimensionless value)
 *    "dumbbell" ;; the origin is at the center of the cylinder
 *    10.0       ;; left cavity radius centered at (center1, 0, 0)
 *    10.0       ;; right cavity radius centered at (center2, 0, 0)
 *    2.0        ;; length of the cylinder
 *    1.0        ;; cylinder radius
 *  ))
 * for 2D hexagonal confinement with cylinder pipe,
 *  (define confinement '(
 *    10.0 ;; LJ parameter epsilon in kT (so this is dimensionless value)
 *    1.0  ;; LJ parameter r0 in "length" (so this is dimensionless value)
 *    "hex2d"
 *    10.0    ;; cavity radius
 *    1.0     ;; cylinder radius
 *    12.0    ;; lattice spacing
 *  ))
 * for porous media (outside of the 3D hexagonal particle array)
 *  (define confinement '(
 *    10.0 ;; LJ parameter epsilon in kT (so this is dimensionless value)
 *    1.0  ;; LJ parameter r0 in "length" (so this is dimensionless value)
 *    "porous"
 *    10.0    ;; particle radius
 *    20.0    ;; lattice spacing in x (2R for touching case)
 *  ))
 * INPUT
 *  var : name of the variable.
 *        in the above example, set "confinement".
 * OUTPUT
 *  returned value : struct confinement
 *                   if NULL is returned, it failed (not defined)
 */
struct confinement *
CF_guile_get (const char *var)
{
  if (guile_check_symbol (var) == 0)
    {
      fprintf (stderr, "CF_guile_get: %s is not defined\n", var);
      return (NULL);
    }

  SCM scm_symbol
    = scm_c_lookup (var);

  SCM scm_confinement
    = scm_variable_ref (scm_symbol);

  if (!SCM_NFALSEP (scm_list_p (scm_confinement)))
    {
      fprintf (stderr, "CF_guile_get: %s is not a list\n", var);
      return (NULL);
    }


  struct confinement *cf = NULL;

  unsigned long len
    = scm_num2ulong (scm_length (scm_confinement),
		     0, "CF_guile_get");
  if (len == 0)
    {
      // no confinement
      return (cf);
    }
  else if (len < 4)
    {
      fprintf (stderr, "CF_guile_get: %s is too short\n", var);
      return (NULL);
    }

  double epsilon
    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (0)),
		   "CF_guile_get");
  double r0
    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (1)),
		   "CF_guile_get");

  // get the string
  char *str_cf = NULL;
  SCM scm_conf = scm_list_ref (scm_confinement, scm_int2num (2));
#ifdef GUILE16
  size_t str_len;
  if (gh_string_p (scm_conf))
    {
      str_cf = gh_scm2newstr (scm_conf, &str_len);
    }
#else // !GUILE16
  if (scm_is_string (scm_conf))
    {
      str_cf = scm_to_locale_string (scm_conf);
    }
#endif // GUILE16
  if (strcmp (str_cf, "sphere") == 0)
    {
      if (len != 4)
	{
	  fprintf (stderr, "CF_guile_get:"
		   " for sphere, number of parameter must be 1\n");
	}
      else
	{
	  double R
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (3)),
			   "CF_guile_get");
	  cf = CF_init (0, // sphere
			R,
			0.0, // r
			0.0, 0.0, 0.0, // x, y, z
			0.0, // R2
			0.0, // L
			0, // flag_LJ
			epsilon,
			r0);
	  CHECK_MALLOC (cf, "CF_guile_get");
	}
    }
  else if (strcmp (str_cf, "sphere+hole") == 0)
    {
      if (len != 5)
	{
	  fprintf (stderr, "CF_guile_get:"
		   " for sphere+hole, number of parameter must be 2\n");
	}
      else
	{
	  double R
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (3)),
			   "CF_guile_get");
	  double r
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (4)),
			   "CF_guile_get");
	  cf = CF_init (1, // sphere+hole
			R,
			r,
			0.0, 0.0, 0.0, // x, y, z
			0.0, // R2
			0.0, // L
			0, // flag_LJ
			epsilon,
			r0);
	  CHECK_MALLOC (cf, "CF_guile_get");
	}
    }
  else if (strcmp (str_cf, "cylinder") == 0)
    {
      if (len != 7)
	{
	  fprintf (stderr, "CF_guile_get:"
		   " for cylinder, number of parameter must be 4\n");
	}
      else
	{
	  double r
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (3)),
			   "CF_guile_get");
	  double x
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (4)),
			   "CF_guile_get");
	  double y
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (5)),
			   "CF_guile_get");
	  double z
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (6)),
			   "CF_guile_get");
	  cf = CF_init (2, // cylinder
			0.0, // R,
			r,
			x, y, z,
			0.0, // R2
			0.0, // L
			0, // flag_LJ
			epsilon,
			r0);
	  CHECK_MALLOC (cf, "CF_guile_get");
	}
    }
  else if (strcmp (str_cf, "dumbbell") == 0)
    {
      if (len != 7)
	{
	  fprintf (stderr, "CF_guile_get:"
		   " for dumbbell, number of parameter must be 4\n");
	}
      else
	{
	  double R
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (3)),
			   "CF_guile_get");
	  double R2
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (4)),
			   "CF_guile_get");
	  double L
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (5)),
			   "CF_guile_get");
	  double r
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (6)),
			   "CF_guile_get");
	  cf = CF_init (3, // dumbbell
			R,
			r,
			0.0, 0.0, 0.0, // x, y, z
			R2,
			L,
			0, // flag_LJ
			epsilon,
			r0);
	  CHECK_MALLOC (cf, "CF_guile_get");
	}
    }
  else if (strcmp (str_cf, "hex2d") == 0)
    {
      if (len != 6)
	{
	  fprintf (stderr, "CF_guile_get:"
		   " for hex2d, number of parameter must be 3\n");
	}
      else
	{
	  double R
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (3)),
			   "CF_guile_get");
	  double r
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (4)),
			   "CF_guile_get");
	  double L
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (5)),
			   "CF_guile_get");
	  cf = CF_init (4, // hex2d
			R,
			r,
			0.0, 0.0, 0.0, // x, y, z
			0.0, // R2
			L,
			0, // flag_LJ
			epsilon,
			r0);
	  CHECK_MALLOC (cf, "CF_guile_get");
	}
    }
  else if (strcmp (str_cf, "porous") == 0)
    {
      if (len != 5)
	{
	  fprintf (stderr, "CF_guile_get:"
		   " for hex2d, number of parameter must be 2\n");
	}
      else
	{
	  double R
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (3)),
			   "CF_guile_get");
	  double L
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (4)),
			   "CF_guile_get");
	  cf = CF_init (5, // porous
			R,
			0.0,
			0.0, 0.0, 0.0, // x, y, z
			0.0, // R2
			L,
			0, // flag_LJ
			epsilon,
			r0);
	  CHECK_MALLOC (cf, "CF_guile_get");
	}
    }
  else
    {
      fprintf (stderr, "CF_guile_get: invalid confinement %s\n",
	       str_cf);
    }
  free (str_cf);

  return (cf); // success
}
Exemple #6
0
SCM scm_from_int32 (int n) {
	return scm_int2num (n);
}