Logo Search packages:      
Sourcecode: v-sim version File versions  Download package

gtkAtomic.c

/*   EXTRAITS DE LA LICENCE
      Copyright CEA, contributeurs : Luc BILLARD et Damien
      CALISTE, laboratoire L_Sim, (2001-2005)
  
      Adresse mèl :
      BILLARD, non joignable par mèl ;
      CALISTE, damien P caliste AT cea P fr.

      Ce logiciel est un programme informatique servant à visualiser des
      structures atomiques dans un rendu pseudo-3D. 

      Ce logiciel est régi par la licence CeCILL soumise au droit français et
      respectant les principes de diffusion des logiciels libres. Vous pouvez
      utiliser, modifier et/ou redistribuer ce programme sous les conditions
      de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA 
      sur le site "http://www.cecill.info".

      Le fait que vous puissiez accéder à cet en-tête signifie que vous avez 
      pris connaissance de la licence CeCILL, et que vous en avez accepté les
      termes (cf. le fichier Documentation/licence.fr.txt fourni avec ce logiciel).
*/

/*   LICENCE SUM UP
      Copyright CEA, contributors : Luc BILLARD et Damien
      CALISTE, laboratoire L_Sim, (2001-2005)

      E-mail address:
      BILLARD, not reachable any more ;
      CALISTE, damien P caliste AT cea P fr.

      This software is a computer program whose purpose is to visualize atomic
      configurations in 3D.

      This software is governed by the CeCILL  license under French law and
      abiding by the rules of distribution of free software.  You can  use, 
      modify and/ or redistribute the software under the terms of the CeCILL
      license as circulated by CEA, CNRS and INRIA at the following URL
      "http://www.cecill.info". 

      The fact that you are presently reading this means that you have had
      knowledge of the CeCILL license and that you accept its terms. You can
      find a copy of this licence shipped with this software at Documentation/licence.en.txt.
*/
#include <math.h>

#include "gtkAtomic.h"

#include <renderingMethods/renderingAtomic.h>
#include "panelElements.h"
#include "visuConfig.h"
#include <gtk_main.h>
#include <renderingBackend/visu_windowInterface.h>

#define SPIN_ATOMIC_RADIUS_UPPER (gdouble)5.
#define SPIN_ATOMIC_RADIUS_LOWER (gdouble)0.001
#define SPIN_ATOMIC_RADIUS_STEP  (gdouble)0.05
#define LABEL_RADIUS      _("Radius:")
#define LABEL_RADIUS_MULT _("Radius <span style=\"italic\" size=\"smaller\" foreground=\"red\">\303\227 mult.</span>: ")

/* the spin button to control the radius. */
static GtkWidget *spinRadius;
static GtkWidget *entryShape;
static GtkWidget *labelRadius;
static GtkWidget *spinRatio;
static GtkWidget *spinPhi;
static GtkWidget *spinTheta;

enum
  {
    paramRadius,
    paramShape,
    paramRatio,
    paramPhi,
    paramTheta
  };

/* Pointer on a list to all selected elements. */
GList *currentListElement;

GtkWidget* createAtomicSpecificOpenWidget(void);

/* Callbacks */
void paramChanged(GtkSpinButton* button, gpointer data);
void shapeChanged(GtkComboBox *box, gpointer data);
void onSpinBoundsChanged(GObject *obj, gfloat val, gpointer data);


/***************/
/* Public part */
/***************/

/* Initialise the specific area in the element panel
   for the atomic rendering method. */
void initAtomic_gtkPanel()
{
  panelElements_setInterfaceMethods(pointerOnRenderingAtomicMethod,
                           onElementChange_atomicMethod,
                           createGtkInterfaceForAtomicMethod);
  currentListElement = (GList*)0;
}

/* Initialise the gtk methods associated with
   the atomic rendering method. */
void initAtomic_gtkMain()
{
  gtkMainSet_renderingSpecificMethods(pointerOnRenderingAtomicMethod,
                              createAtomicSpecificOpenWidget,
                              (createGtkLoadWidgetFunc)0);
}

GtkWidget* createAtomicSpecificOpenWidget(void)
{
  GtkWidget *label;

  label = gtk_label_new("Coucou");
  gtk_widget_show(label);
  return label;
}




/* Create the gtk widgets (a hbox with a spin with
   positive values) and return it. */
GtkWidget* createGtkInterfaceForAtomicMethod()
{
  GtkWidget* hbox, *vbox;
  GtkWidget* label;
  GtkObject *adj;
  GtkWidget *comboShape;
  const char **names;
  int i;

  DBG_fprintf(stderr, "GTK Atomic : create the gtk interface.\n");

  vbox = gtk_vbox_new(FALSE, 0);

  hbox = gtk_hbox_new(FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);

  labelRadius = gtk_label_new("");
  if (panelConfigGet_spinBoundsValue() == 1.)
    gtk_label_set_text(GTK_LABEL(labelRadius), LABEL_RADIUS);
  else
    {
      gtk_label_set_text(GTK_LABEL(labelRadius), LABEL_RADIUS_MULT);
      gtk_label_set_use_markup(GTK_LABEL(labelRadius), TRUE);
    }
  gtk_box_pack_start(GTK_BOX(hbox), labelRadius, FALSE, FALSE, 1);

  adj = gtk_adjustment_new(1.0, SPIN_ATOMIC_RADIUS_LOWER,
                     SPIN_ATOMIC_RADIUS_UPPER, SPIN_ATOMIC_RADIUS_STEP,
                     0.1, 0.1);
  spinRadius = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 0.01, 3);
  gtk_box_pack_start(GTK_BOX(hbox), spinRadius, FALSE,FALSE, 3);

  label = gtk_label_new(_("Shape: "));
  gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 1);
  gtk_misc_set_alignment(GTK_MISC(label), 1., 0.5);

  comboShape = gtk_combo_box_new_text();
  names = renderingAtomicGet_allShapesI18n();
  if (names)
    for (i = 0; names[i]; i++)
      gtk_combo_box_append_text(GTK_COMBO_BOX(comboShape), names[i]);
  else
    gtk_combo_box_append_text(GTK_COMBO_BOX(comboShape),
                        (char*)renderingAtomicGet_shapeNameDefault());
  gtk_combo_box_set_active(GTK_COMBO_BOX(comboShape), 0);
  entryShape = comboShape;
  /* set callback for the combo button. */
  g_signal_connect(G_OBJECT(entryShape), "changed",
               G_CALLBACK(shapeChanged), (gpointer)0);
  gtk_box_pack_start(GTK_BOX(hbox), comboShape, FALSE, FALSE, 3);

  /* set callback for the spin button. */
  g_signal_connect((gpointer)spinRadius, "value-changed",
               G_CALLBACK(paramChanged), GINT_TO_POINTER(paramRadius));

  g_signal_connect(G_OBJECT(visuGtkObject), "spinBoundsChanged",
               G_CALLBACK(onSpinBoundsChanged), (gpointer)0);

  /* Set widgets for the elipsoid parameters. */
  label = gtk_label_new("");
  gtk_label_set_markup(GTK_LABEL(label), _("<i>Parameters for elipsoid shape</i>"));
  gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5);
  gtk_misc_set_alignment(GTK_MISC(label), 0., 0.5);
  gtk_misc_set_padding(GTK_MISC(label), 10, 0);
  hbox = gtk_hbox_new(FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Ratio: "));
  gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
  gtk_misc_set_alignment(GTK_MISC(label), 0., 0.5);
  spinRatio = gtk_spin_button_new_with_range(1., 3., 0.1);
  gtk_box_pack_start(GTK_BOX(hbox), spinRatio, FALSE, FALSE, 0);
  label = gtk_label_new(_("Phi: "));
  gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
  gtk_misc_set_alignment(GTK_MISC(label), 1., 0.5);
  spinPhi = gtk_spin_button_new_with_range(-180., 180., 1.);
  gtk_box_pack_start(GTK_BOX(hbox), spinPhi, FALSE, FALSE, 0);
  label = gtk_label_new(_("Theta: "));
  gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
  gtk_misc_set_alignment(GTK_MISC(label), 1., 0.5);
  spinTheta = gtk_spin_button_new_with_range(-180., 180., 1.);
  gtk_box_pack_start(GTK_BOX(hbox), spinTheta, FALSE, FALSE, 0);

  g_signal_connect((gpointer)spinRatio, "value-changed",
               G_CALLBACK(paramChanged), GINT_TO_POINTER(paramRatio));
  g_signal_connect((gpointer)spinPhi, "value-changed",
               G_CALLBACK(paramChanged), GINT_TO_POINTER(paramPhi));
  g_signal_connect((gpointer)spinTheta, "value-changed",
               G_CALLBACK(paramChanged), GINT_TO_POINTER(paramTheta));
  

  gtk_widget_show_all(vbox);
  return vbox;
}

/* This function is called whenever an element is changed. */
void onElementChange_atomicMethod(GList *eleList)
{
  float radius, ratio, phi, theta;
  int shape;
  gdouble mult;
  VisuElement *ele;
  GList *tmpLst;

  g_return_if_fail(eleList);

  if (currentListElement)
    g_list_free(currentListElement);
  currentListElement = (GList*)0;

  tmpLst = eleList;
  while (tmpLst)
    {
      currentListElement = g_list_prepend(currentListElement, tmpLst->data);
      tmpLst = g_list_next(tmpLst);
    }
  
  /* If the list has only one element, we continue
     and update the values on the widgets. */
  if (g_list_next(eleList))
    return;

  ele = (VisuElement*)eleList->data;
  /* Change the radius for the new element. */
  radius = renderingAtomicGet_radius(ele);
  mult = panelConfigGet_spinBoundsValue();
  if (radius >= 0.)
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinRadius),
                        radius / mult);
  else
    {
      g_warning("Can't find a value for radius of element '%s'.\n", ele->name);
      gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinRadius),
                        renderingAtomicGet_radiusDefault() / mult);
    }
  /* Change the shape for the new element. */
  shape = renderingAtomicGet_shape(ele);
  if (shape >= 0)
    gtk_combo_box_set_active(GTK_COMBO_BOX(entryShape), shape);
  else
    {
      g_warning("Can't find the shape of element '%s'.\n", ele->name);
      gtk_combo_box_set_active(GTK_COMBO_BOX(entryShape), renderingAtomicGet_shapeDefault());
    }
  /* Change the elipsoid parameters. */
  ratio = renderingAtomicGet_elipsoidRatio(ele);
  gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinRatio), ratio);
  phi = renderingAtomicGet_elipsoidPhi(ele);
  gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinPhi), phi);
  theta = renderingAtomicGet_elipsoidTheta(ele);
  gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinTheta), theta);
}




/****************/
/* Private part */
/****************/

void onSpinBoundsChanged(GObject *obj, gfloat mult, gpointer data)
{
  float val;
  int i, id;
  VisuData *dataObj;

  if (getRenderingMethodInUse() != pointerOnRenderingAtomicMethod)
    return;

  DBG_fprintf(stderr, "Panel Atomic : catch the 'spinBoundsChanged' signal,"
            " should adjust the radius bounds (multiplier : %f).\n", mult);

  if (panelConfigGet_spinBoundsValue() == 1.)
    gtk_label_set_text(GTK_LABEL(labelRadius), LABEL_RADIUS);
  else
    {
      gtk_label_set_text(GTK_LABEL(labelRadius), LABEL_RADIUS_MULT);
      gtk_label_set_use_markup(GTK_LABEL(labelRadius), TRUE);
    }

  dataObj = toolPanelGet_visuData(TOOL_PANEL(panelElements));
  if (dataObj)
    for (i = 0; i < dataObj->ntype; i++)
      {
      val = renderingAtomicGet_radius(dataObj->fromIntToVisuElement[i]);
      if (renderingAtomicSet_radius(dataObj->fromIntToVisuElement[i],
                              val * mult))
        {
          id = renderingAtomic_createShape(dataObj,
                                   dataObj->fromIntToVisuElement[i]);
          dataObj->fromIntToVisuElement[i]->openGLIdentifier = id;
        }
      }
}
   
void shapeChanged(GtkComboBox *box, gpointer data)
{
  int shape;
  GList *tmpLst;
  gboolean refresh;
  VisuElement *ele;
  int id;

  g_return_if_fail(currentListElement);

  shape = (int)gtk_combo_box_get_active(box);

  refresh = FALSE;
  tmpLst = currentListElement;
  while (tmpLst)
    {
      ele = (VisuElement*)tmpLst->data;
      if (renderingAtomicSet_shape(ele, shape))
      {
        id = renderingAtomic_createShape
          (toolPanelGet_visuData(TOOL_PANEL(panelElements)), ele);
        ele->openGLIdentifier = id;
        refresh = TRUE;
      }
      tmpLst = g_list_next(tmpLst);
    }
  if (refresh)
    g_signal_emit(visu, VISU_GET_CLASS (visu)->OpenGLAskForReDraw_signal_id,
              0 , NULL);
}

void paramChanged(GtkSpinButton* button, gpointer data)
{
  int param, id;
  float value;
  gdouble mult;
  VisuElement *ele;
  VisuData *dataObj;
  GList *tmpLst;
  gboolean refresh, res;

  g_return_if_fail(currentListElement);

  dataObj = toolPanelGet_visuData(TOOL_PANEL(panelElements));

  param = GPOINTER_TO_INT(data);
  value = gtk_spin_button_get_value(button);

  refresh = FALSE;
  tmpLst = currentListElement;
  while (tmpLst)
    {
      ele = (VisuElement*)tmpLst->data;
      switch (param)
      {
      case paramRadius:
        mult = panelConfigGet_spinBoundsValue();
        res = renderingAtomicSet_radius(ele, value * mult);
        break;
      case paramRatio:
        res = renderingAtomicSet_elipsoidRatio(ele, value);
        break;
      case paramPhi:
        res = renderingAtomicSet_elipsoidPhi(ele, value);
        break;
      case paramTheta:
        res = renderingAtomicSet_elipsoidTheta(ele, value);
        break;
      default:
        res = FALSE;
      }
      if (res)
      {
        id = renderingAtomic_createShape(dataObj, ele);
        ele->openGLIdentifier = id;
        refresh = TRUE;
      }
      tmpLst = g_list_next(tmpLst);
    }
  if (refresh)
    g_signal_emit(visu, VISU_GET_CLASS (visu)->OpenGLAskForReDraw_signal_id,
              0 , NULL);
}

Generated by  Doxygen 1.6.0   Back to index