"Fossies" - the Fresh Open Source Software Archive

Member "gfsview-snapshot-121130/view/gfkgl3D.h" (30 Nov 2012, 13345 Bytes) of package /linux/privat/gfsview-snapshot-121130.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "gfkgl3D.h" see the Fossies "Dox" file reference documentation.

    1 /* Gerris - The GNU Flow Solver
    2  * Copyright (C) 2001-2004 National Institute of Water and Atmospheric
    3  * Research
    4  *
    5  * This program is free software; you can redistribute it and/or
    6  * modify it under the terms of the GNU General Public License as
    7  * published by the Free Software Foundation; either version 2 of the
    8  * License, or (at your option) any later version.
    9  *
   10  * This program is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   13  * General Public License for more details.
   14  *
   15  * You should have received a copy of the GNU General Public License
   16  * along with this program; if not, write to the Free Software
   17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   18  * 02111-1307, USA.  
   19  */
   20 
   21 /* GfkGl2D: Object */
   22 
   23 static gchar * gl2D_pickinfo (GfkGl * gl, gboolean motion)
   24 {
   25   FttVector p = GFS_GL2D (gl->gl)->pickedpos;
   26   GfkGl2D * gl2 = GFK_GL2D (gl);
   27 
   28   g_free (gl2->pickinfo);
   29   if (fabs (p.x) < 1e-10) p.x = 0.;
   30   if (fabs (p.y) < 1e-10) p.y = 0.;
   31   if (fabs (p.z) < 1e-10) p.z = 0.;
   32   gfs_simulation_map_inverse (gl->gl->sim, &p);
   33   gl2->pickinfo = g_strdup_printf ("(%.8f,%.8f,%.8f)", p.x, p.y, p.z);
   34   return gl2->pickinfo;
   35 }
   36 
   37 static void gl2D_init (GfkGl2D * object)
   38 {
   39   object->params = create_gl2D_params ();
   40   object->n.x = 0.; object->n.y = 0.; object->n.z = 1.;
   41   gfk_gl_prepend_params (GFK_GL (object), object->params, gtk_label_new ("2D Plane"));
   42   gtk_widget_show (object->params);
   43 }
   44 
   45 /* GfkGlSolid: Object */
   46 
   47 static void update_solid_scalar (GfkGl * gl)
   48 {
   49   gfk_gl_set_sensitive (gl, GFK_GL_SCALAR (gl)->scalar, TRUE);
   50   gfk_gl_update_properties (gl);
   51   gtk_widget_set_sensitive (lookup_widget_params (gl->properties, "default_color_label"), 
   52                 FALSE);
   53   gtk_widget_set_sensitive (lookup_widget_params (gl->properties, "default_color"), 
   54                 FALSE);
   55 }
   56 
   57 static void gl_solid_read (GtsObject ** o, GtsFile * fp)
   58 {
   59   GtkWidget * solid = GFK_GL_SOLID (*o)->solid;
   60   GfsGlSolid * gl = GFS_GL_SOLID (GFK_GL (*o)->gl);
   61 
   62   (* GTS_OBJECT_CLASS (gfk_gl_solid_class ())->parent_class->read) (o, fp);
   63   if (fp->type == GTS_ERROR)
   64     return;
   65 
   66   if (gl->reversed) {
   67     gl->reversed = FALSE;
   68     gtk_toggle_button_set_active (lookup_widget_params (solid, "reversed"), TRUE);
   69   }
   70 
   71   if (gl->use_scalar) {
   72     gtk_option_menu_set_history (lookup_widget_params (solid, "color"), 1);
   73     update_solid_scalar (GFK_GL (*o));
   74   }
   75 }
   76 
   77 static gchar * gl_solid_name (GfkGlClass * klass)
   78 {
   79   static gchar name[] = "Solid";
   80   return name;
   81 }
   82 
   83 static GtkWidget * gl_solid_icon (GfkGlClass * klass)
   84 {
   85   return create_pixmap (NULL, "solid-16x16.png");
   86 }
   87 
   88 static gchar * gl_solid_properties (GfkGl * gl)
   89 {
   90   gchar * s = GFS_GL_SOLID (gl->gl)->use_scalar ? 
   91     g_strdup ((* gfk_gl_scalar_class ()->properties) (gl)) :
   92     g_strdup ("");
   93 
   94   g_free (gl->props);
   95   gl->props = s;
   96   return gl->props;
   97 }
   98 
   99 static void set_solid_color (GtkWidget * color, GfkGl * gl)
  100 {
  101   gfk_gl_set_sensitive (gl, GFK_GL_SCALAR (gl)->scalar, FALSE);
  102   gfk_gl_update_properties (gl);
  103   gtk_widget_set_sensitive (lookup_widget_params (gl->properties, "default_color_label"), 
  104                 TRUE);
  105   gtk_widget_set_sensitive (lookup_widget_params (gl->properties, "default_color"), TRUE);
  106   GFS_GL_SOLID (gl->gl)->use_scalar = NULL;
  107   gfk_gl_expose (gl);
  108 }
  109 
  110 static void set_solid_scalar (GtkWidget * scalar, GfkGl * gl)
  111 {
  112   GFS_GL_SOLID (gl->gl)->use_scalar = GFS_GL_SCALAR (gl->gl)->v;
  113   update_solid_scalar (gl);
  114   gfs_gl_solid_reset (GFS_GL_SOLID (gl->gl));
  115   gfk_gl_expose (gl);
  116 }
  117 
  118 static void gl_solid_post_init (GfkGl * object)
  119 {
  120   GtkWidget * m = gtk_menu_new (), * i;
  121   GfkGlSolid * gls = GFK_GL_SOLID (object);
  122   
  123   if (GFK_GL_CLASS (GTS_OBJECT_CLASS (gfk_gl_solid_class ())->parent_class)->post_init)
  124     (*GFK_GL_CLASS (GTS_OBJECT_CLASS (gfk_gl_solid_class ())->parent_class)->post_init)
  125       (object);
  126   
  127   gfk_gl_set_sensitive (GFK_GL (gls), GFK_GL_SCALAR (gls)->scalar, FALSE);
  128   m = gtk_menu_new ();
  129   i = gtk_menu_item_new_with_label ("Default");
  130   g_signal_connect (G_OBJECT (i), "activate", GTK_SIGNAL_FUNC (set_solid_color), object);
  131   gtk_menu_append (m, i);
  132   gtk_widget_show (i);
  133 
  134   i = gtk_menu_item_new_with_label ("Scalar");
  135   g_signal_connect (G_OBJECT (i), "activate", GTK_SIGNAL_FUNC (set_solid_scalar), object);
  136   gtk_menu_append (m, i);
  137   gtk_widget_show (i);
  138   
  139   gtk_option_menu_set_menu (lookup_widget_params (gls->solid, "color"), m);
  140   gtk_widget_show (m);
  141 
  142   gtk_widget_hide (GFK_GL2D (object)->params);
  143 }
  144 
  145 static void gl_solid_class_init (GfkGlClass * klass)
  146 {
  147   GTS_OBJECT_CLASS (klass)->read = gl_solid_read;
  148   klass->gl_class = gfs_gl_solid_class ();
  149   klass->post_init = gl_solid_post_init;
  150   klass->name = gl_solid_name;
  151   klass->icon = gl_solid_icon;
  152   klass->properties = gl_solid_properties;
  153 }
  154 
  155 static void gl_solid_init (GfkGl * gl)
  156 {
  157   GfkGlSolid * gli = GFK_GL_SOLID (gl);
  158 
  159   gli->solid = create_solid_params ();
  160   gfk_gl_prepend_params (gl, gli->solid, gtk_label_new ("Solid"));
  161   gtk_widget_show (gli->solid);
  162 }
  163 
  164 GfkGlClass * gfk_gl_solid_class (void)
  165 {
  166   static GfkGlClass * klass = NULL;
  167 
  168   if (klass == NULL) {
  169     GtsObjectClassInfo gfk_gl_solid_info = {
  170       "GfkGlSolid",
  171       sizeof (GfkGlSolid),
  172       sizeof (GfkGlClass),
  173       (GtsObjectClassInitFunc) gl_solid_class_init,
  174       (GtsObjectInitFunc) gl_solid_init,
  175       (GtsArgSetFunc) NULL,
  176       (GtsArgGetFunc) NULL
  177     };
  178     klass = gts_object_class_new (GTS_OBJECT_CLASS (gfk_gl_scalar_class ()),
  179                   &gfk_gl_solid_info);
  180   }
  181 
  182   return klass;
  183 }
  184 
  185 /* GfkGlFractions: Object */
  186 
  187 static void gl_fractions_init (GfkGl * gl)
  188 {
  189 }
  190 
  191 /* GfkGlIsosurface: Object */
  192 
  193 static void update_isosurface_scalar (GfkGl * gl)
  194 {
  195   gfk_gl_set_sensitive (gl, GFK_GL_SCALAR (gl)->scalar, TRUE);
  196   gfk_gl_update_properties (gl);
  197   gtk_widget_set_sensitive (lookup_widget_params (gl->properties, "default_color_label"), FALSE);
  198   gtk_widget_set_sensitive (lookup_widget_params (gl->properties, "default_color"), FALSE);
  199 }
  200 
  201 static void gl_isosurface_read (GtsObject ** o, GtsFile * fp)
  202 {
  203   GtkWidget * scalar = GFK_GL_ISOSURFACE (*o)->scalar;
  204   GfsGlIsosurface * gl = GFS_GL_ISOSURFACE (GFK_GL (*o)->gl);
  205   GtkSpinButton * level = lookup_widget_params (scalar, "spinbuttonlevel");
  206   GtkAdjustment * alevel = gtk_spin_button_get_adjustment (level);
  207 
  208   (* GTS_OBJECT_CLASS (gfk_gl_isosurface_class ())->parent_class->read) (o, fp);
  209   if (fp->type == GTS_ERROR)
  210     return;
  211 
  212   alevel->value = gl->level;
  213   if (alevel->value > alevel->upper)
  214     alevel->upper = alevel->value;
  215   if (alevel->value < alevel->lower)
  216     alevel->lower = alevel->value;
  217   gtk_spin_button_set_adjustment (level, alevel);
  218 
  219   if (gl->reversed) {
  220     gl->reversed = FALSE;
  221     gtk_toggle_button_set_active (lookup_widget_params (scalar, "reversed"), TRUE);
  222   }
  223 
  224   if (gl->use_scalar) {
  225     gtk_option_menu_set_history (lookup_widget_params (scalar, "color"), 1);
  226     update_isosurface_scalar (GFK_GL (*o));
  227   }
  228 }
  229 
  230 static gchar * gl_isosurface_name (GfkGlClass * klass)
  231 {
  232   static gchar name[] = "Isosurface";
  233   return name;
  234 }
  235 
  236 static GtkWidget * gl_isosurface_icon (GfkGlClass * klass)
  237 {
  238   return create_pixmap (NULL, "isosurface-16x16.png");
  239 }
  240 
  241 static void gl_isosurface_update_interface (GfkGl * g)
  242 {
  243   GfkGlIsosurface * gl = GFK_GL_ISOSURFACE (g);
  244   GtkSpinButton * level = lookup_widget_params (gl->scalar, "spinbuttonlevel");
  245   GfsGlIsosurface * gli = GFS_GL_ISOSURFACE (GFK_GL (gl)->gl);
  246   GtkEntry * scalar = lookup_widget_params (gl->scalar, "scalar");
  247 
  248   if (!GFK_IS_EDITED (scalar))
  249     gtk_entry_set_text (scalar, gli->expr->str);
  250 
  251   if (gli->maxv > gli->minv) {
  252     gdouble step = (gli->maxv - gli->minv)/500.;
  253     guint digits = gfk_decimal_digits (step, 2);
  254     GtkAdjustment * alevel = gtk_spin_button_get_adjustment (level);
  255 
  256     alevel->upper = gli->maxv;
  257     alevel->lower = gli->minv;
  258     alevel->step_increment = step;
  259     alevel->page_increment = step*10.;
  260     if (alevel->value > alevel->upper || alevel->value < alevel->lower)
  261       alevel->value = (alevel->upper + alevel->lower)/2.;
  262     if (!GFK_IS_EDITED (level))
  263       gtk_spin_button_configure (level, alevel, 2.*step, digits);
  264   }
  265   gfk_gl_update_properties (GFK_GL (gl));
  266   gfk_gl_expose (GFK_GL (gl));
  267 }
  268 
  269 static void gl_isosurface_set_simulation (GfkGl * object, GfsSimulation * sim)
  270 {
  271   (*GFK_GL_CLASS (GTS_OBJECT_CLASS (gfk_gl_isosurface_class ())->parent_class)->set_simulation)
  272     (object, sim);
  273   
  274   gl_isosurface_update_interface (object);
  275 }
  276 
  277 static void set_isosurface_scalar (GtkWidget * scalar, GfkGl * gl)
  278 {
  279   GFS_GL_ISOSURFACE (gl->gl)->use_scalar = GFS_GL_SCALAR (gl->gl)->v;
  280   update_isosurface_scalar (gl);
  281   gfs_gl_isosurface_reset (GFS_GL_ISOSURFACE (gl->gl));
  282   gfk_gl_expose (gl);
  283 }
  284 
  285 static void set_isosurface_color (GtkWidget * color, GfkGlIsosurface * gl)
  286 {
  287   GFS_GL_ISOSURFACE (GFK_GL (gl)->gl)->use_scalar = NULL;
  288   gfk_gl_set_sensitive (GFK_GL (gl), GFK_GL_SCALAR (gl)->scalar, FALSE);
  289   gfk_gl_update_properties (GFK_GL (gl));
  290   gtk_widget_set_sensitive (lookup_widget_params (GFK_GL (gl)->properties, "default_color_label"), 
  291                 TRUE);
  292   gtk_widget_set_sensitive (lookup_widget_params (GFK_GL (gl)->properties, "default_color"), TRUE);
  293   gfk_gl_expose (GFK_GL (gl));
  294 }
  295 
  296 static GtsFile * gl_isosurface_set (GfkGl * gl, const char * s)
  297 {
  298   return gfs_gl_isosurface_set (GFS_GL_ISOSURFACE (gl->gl), s);
  299 }
  300 
  301 static void gl_isosurface_post_init (GfkGl * object)
  302 {
  303   GfkGlIsosurface * gli = GFK_GL_ISOSURFACE (object);
  304 
  305   (*GFK_GL_CLASS (GTS_OBJECT_CLASS (gfk_gl_isosurface_class ())->parent_class)->post_init)
  306     (object);
  307 
  308   GtkWidget * scalar = gfk_function (gli->scalar, object, "scalar", gl_isosurface_set);
  309   gtk_widget_show (scalar);
  310   gtk_table_attach (GTK_TABLE (lookup_widget_params (gli->scalar, "table1")),
  311             scalar, 1, 3, 0, 1,
  312                     (GtkAttachOptions) (GTK_FILL),
  313                     (GtkAttachOptions) (0), 0, 0);
  314   
  315   gl_isosurface_update_interface (object);
  316 }
  317 
  318 static gchar * gl_isosurface_properties (GfkGl * gl)
  319 {
  320   gchar * s = g_strjoin (" ",
  321              GFS_GL_ISOSURFACE (gl->gl)->expr->str,
  322              GFS_GL_ISOSURFACE (gl->gl)->use_scalar ?
  323              ((* gfk_gl_scalar_class ()->properties) (gl)) : NULL, 
  324              NULL);
  325   g_free (gl->props);
  326   gl->props = s;
  327   return gl->props;
  328 }
  329 
  330 static void gl_isosurface_class_init (GfkGlClass * klass)
  331 {
  332   GTS_OBJECT_CLASS (klass)->read = gl_isosurface_read;
  333   klass->gl_class = gfs_gl_isosurface_class ();
  334   klass->set_simulation = gl_isosurface_set_simulation;
  335   klass->update_interface = gl_isosurface_update_interface;
  336   klass->post_init = gl_isosurface_post_init;
  337   klass->properties = gl_isosurface_properties;
  338   klass->name = gl_isosurface_name;
  339   klass->icon = gl_isosurface_icon;
  340 }
  341 
  342 static void gl_isosurface_init (GfkGl * gl)
  343 {
  344   GfkGlIsosurface * gli = GFK_GL_ISOSURFACE (gl);
  345 
  346   gli->scalar = create_isosurface_params ();
  347 
  348   gfk_gl_set_sensitive (gl, GFK_GL_SCALAR (gl)->scalar, FALSE);
  349 
  350   GtkWidget * m = gtk_menu_new ();
  351   GtkWidget * i = gtk_menu_item_new_with_label ("Default");
  352   g_signal_connect (G_OBJECT (i), "activate", GTK_SIGNAL_FUNC (set_isosurface_color), gl);
  353   gtk_menu_append (m, i);
  354   gtk_widget_show (i);
  355 
  356   i = gtk_menu_item_new_with_label ("Scalar");
  357   g_signal_connect (G_OBJECT (i), "activate", GTK_SIGNAL_FUNC (set_isosurface_scalar), gl);
  358   gtk_menu_append (m, i);
  359   gtk_widget_show (i);
  360   
  361   gtk_option_menu_set_menu (lookup_widget_params (gli->scalar, "color"), m);
  362   gtk_widget_show (m);
  363 
  364   gtk_widget_hide (GFK_GL2D (gl)->params);
  365 
  366   gfk_gl_prepend_params (gl, gli->scalar, gtk_label_new ("Isosurface"));
  367   gtk_widget_show (gli->scalar);
  368 }
  369 
  370 GfkGlClass * gfk_gl_isosurface_class (void)
  371 {
  372   static GfkGlClass * klass = NULL;
  373 
  374   if (klass == NULL) {
  375     GtsObjectClassInfo gfk_gl_isosurface_info = {
  376       "GfkGlIsosurface",
  377       sizeof (GfkGlIsosurface),
  378       sizeof (GfkGlClass),
  379       (GtsObjectClassInitFunc) gl_isosurface_class_init,
  380       (GtsObjectInitFunc) gl_isosurface_init,
  381       (GtsArgSetFunc) NULL,
  382       (GtsArgGetFunc) NULL
  383     };
  384     klass = gts_object_class_new (GTS_OBJECT_CLASS (gfk_gl_scalar_class ()),
  385                   &gfk_gl_isosurface_info);
  386   }
  387 
  388   return klass;
  389 }
  390 
  391 /* GfkGlCutPlane: Object */
  392 
  393 static gchar * gl_cut_plane_name (GfkGlClass * klass)
  394 {
  395   static gchar name[] = "Cut";
  396   return name;
  397 }
  398 
  399 static GtkWidget * gl_cut_plane_icon (GfkGlClass * klass)
  400 {
  401   return create_pixmap (NULL, "cut-16x16.png");
  402 }
  403 
  404 static void gl_cut_plane_class_init (GfkGlClass * klass)
  405 {
  406   klass->gl_class = gfs_gl_cut_plane_class ();
  407   klass->name = gl_cut_plane_name;
  408   klass->icon = gl_cut_plane_icon;
  409   klass->pickinfo = NULL;
  410 }
  411 
  412 static void gl_cut_plane_init (GfkGl * gl)
  413 {
  414   gtk_widget_set_sensitive (lookup_widget_params (gl->properties, "shading_label"), FALSE);
  415   gtk_widget_set_sensitive (lookup_widget_params (gl->properties, "shading"), FALSE);
  416 }
  417 
  418 GfkGlClass * gfk_gl_cut_plane_class (void)
  419 {
  420   static GfkGlClass * klass = NULL;
  421 
  422   if (klass == NULL) {
  423     GtsObjectClassInfo gfk_gl_cut_plane_info = {
  424       "GfkGlCutPlane",
  425       sizeof (GfkGl2D),
  426       sizeof (GfkGlClass),
  427       (GtsObjectClassInitFunc) gl_cut_plane_class_init,
  428       (GtsObjectInitFunc) gl_cut_plane_init,
  429       (GtsArgSetFunc) NULL,
  430       (GtsArgGetFunc) NULL
  431     };
  432     klass = gts_object_class_new (GTS_OBJECT_CLASS (gfk_gl2D_class ()), &gfk_gl_cut_plane_info);
  433   }
  434 
  435   return klass;
  436 }