[chronojump] Code clean



commit f02fe65c2f03cb9b2bc612542aa8aaa3c8434853
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jan 24 14:14:14 2014 +0100

    Code clean

 src/Makefile.am    |    1 +
 src/encoder.cs     |  366 ++++++++++++++++++++--------------------------------
 src/gui/encoder.cs |  231 +--------------------------------
 src/utilEncoder.cs |   43 ++++++-
 4 files changed, 193 insertions(+), 448 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index f731446..c2cf29e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,7 @@ SOURCES = \
        gui/chronopic.cs\
        gui/confirm.cs\
        gui/encoder.cs\
+       gui/encoderConfiguration.cs\
        gui/error.cs\
        gui/eventExecute.cs\
        gui/eventGraphConfigure.cs\
diff --git a/src/encoder.cs b/src/encoder.cs
index 19480a8..41b9892 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -591,240 +591,158 @@ public class EncoderCaptureCurveArray {
        ~EncoderCaptureCurveArray() {}
 }
 
-public class EncoderModeSelectionList 
-{
-       public ArrayList list;
-
-       public EncoderModeSelectionList(string type) 
-       {
-               list = new ArrayList();
-               EncoderModeSelection enc = new EncoderModeSelection();
-               
-               if(type == Constants.EncoderType.LINEAR.ToString()) {
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.LINEAR.ToString(),
-                                       Constants.FileNameEncoderLinearFreeWeight,
-                                       Constants.DefaultEncoderConfigurationCode,
-                                       "Linear encoder attached to a barbell.",
-                                       false,  //d
-                                       false,  //d2
-                                       false,  //angle
-                                       false   //inertia
-                                       ); 
-                       list.Add(enc);
-
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.LINEARINVERTED.ToString(),
-                                       Constants.FileNameEncoderLinearFreeWeightInv,
-                                       "Linear inv - barbell",
-                                       "Linear encoder inverted attached to a barbell.",
-                                       false,  //d
-                                       false,  //d2
-                                       false,  //angle
-                                       false   //inertia
-                                       );
-                       list.Add(enc);
-                       
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.LINEARINERTIAL.ToString(),
-                                       Constants.FileNameEncoderLinearInertial,
-                                       "Linear - inertial machine",
-                                       "Linear encoder on inertia machine. NOT Recommended!",
-                                       false,  //d
-                                       false,  //d2
-                                       false,  //angle
-                                       true    //inertia
-                                       );      
-                       list.Add(enc);
-
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYLINEARONPERSON1.ToString(),
-                                       Constants.FileNameEncoderWeightedMovPulleyOnPerson1,
-                                       "Linear - barbell - moving pulley",
-                                       "Linear encoder attached to a barbell. Barbell is connected to a 
weighted moving pulley.",
-                                       false,  //d
-                                       false,  //d2
-                                       false,  //angle
-                                       false   //inertia
-                                       ); 
-                       list.Add(enc);
-
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYLINEARONPERSON1INV.ToString(),
-                                       Constants.FileNameEncoderWeightedMovPulleyOnPerson1Inv,
-                                       "Linear inv - barbell - moving pulley",
-                                       "Linear encoder inverted attached to a barbell. Barbell is connected 
to a weighted moving pulley.",
-                                       false,  //d
-                                       false,  //d2
-                                       false,  //angle
-                                       false   //inertia
-                                       ); 
-                       list.Add(enc);
-
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYLINEARONPERSON2.ToString(),
-                                       Constants.FileNameEncoderWeightedMovPulleyOnPerson2,
-                                       "Linear - barbell - pulley - moving pulley",
-                                       "Linear encoder attached to a barbell. Barbell is connected to a 
fixed pulley that is connected to a weighted moving pulley.",
-                                       false,  //d
-                                       false,  //d2
-                                       false,  //angle
-                                       false   //inertia
-                                       ); 
-                       list.Add(enc);
-
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYLINEARONPERSON2INV.ToString(),
-                                       Constants.FileNameEncoderWeightedMovPulleyOnPerson2Inv,
-                                       "Linear inv - barbell - pulley - moving pulley",
-                                       "Linear encoder inverted attached to a barbell. Barbell is connected 
to a fixed pulley that is connected to a weighted moving pulley.",
-                                       false,  //d
-                                       false,  //d2
-                                       false,  //angle
-                                       false   //inertia
-                                       ); 
-                       list.Add(enc);
-
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYONLINEARENCODER.ToString(),
-                                       Constants.FileNameEncoderWeightedMovPulleyOnLinearEncoder,
-                                       "Linear - moving pulley",
-                                       "Linear encoder attached to a weighted moving pulley.",
-                                       false,  //d
-                                       false,  //d2
-                                       false,  //angle
-                                       false   //inertia
-                                       ); 
-                       list.Add(enc);
-
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.LINEARONPLANE.ToString(),
-                                       Constants.FileNameEncoderLinearOnPlane,
-                                       "Linear - inclinated plane",
-                                       "Linear encoder on a inclinated plane.",
-                                       false,  //d
-                                       false,  //d2
-                                       true,   //angle
-                                       false   //inertia
-                                       ); 
-                       list.Add(enc);
-               }
-               else if(type == Constants.EncoderType.ROTARYFRICTION.ToString()) {
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.ROTARYFRICTIONSIDE.ToString(),
-                                       Constants.FileNameEncoderFrictionSide,
-                                       "Rotary friction - pulley",
-                                       "Rotary friction encoder on pulley.",
-                                       false,  //d
-                                       false,  //d2
-                                       false,  //angle
-                                       false   //inertia
-                                       ); 
-                       list.Add(enc);
-
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.ROTARYFRICTIONAXIS.ToString(),
-                                       Constants.FileNameEncoderFrictionAxis ,
-                                       "Rotary friction - pulley axis",
-                                       "Rotary friction encoder on pulley axis.",
-                                       true,   //d
-                                       true,   //d2
-                                       false,  //angle
-                                       false   //inertia
-                                       ); 
-                       list.Add(enc);
-
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.ROTARYFRICTIONINERTIAL.ToString(),
-                                       Constants.FileNameEncoderFrictionInertial ,
-                                       "Rotary friction - inertial machine",
-                                       "Rotary friction encoder on inertial machine.",
-                                       false,  //d
-                                       false,  //d2
-                                       false,  //angle
-                                       true    //inertia
-                                       ); 
-                       list.Add(enc);
-
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYROTARYFRICTION.ToString(),
-                                       Constants.FileNameEncoderFrictionWithMovPulley ,
-                                       "Rotary friction - moving pulley",
-                                       "Rotary friction encoder on weighted moving pulley.",
-                                       false,  //d
-                                       false,  //d2
-                                       false,  //angle
-                                       false   //inertia
-                                       ); 
-                       list.Add(enc);
-
-               }
-               else {  // (type == Constants.EncoderType.ROTARYAXIS.ToString())
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.ROTARYAXIS.ToString(),
-                                       Constants.FileNameEncoderRotaryAxisOnAxis ,
-                                       "Rotary axis - pulley axis",
-                                       "Rotary axis encoder on pulley axis.",
-                                       true,   //d
-                                       false,  //d2
-                                       false,  //angle
-                                       false   //inertia
-                                       ); 
-                       list.Add(enc);
-
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.ROTARYAXISINERTIAL.ToString(),
-                                       Constants.FileNameEncoderAxisInertial ,
-                                       "Rotary axis - inertial machine",
-                                       "Rotary axis encoder on inertial machine.",
-                                       false,  //d
-                                       false,  //d2
-                                       false,  //angle
-                                       true    //inertia
-                                       ); 
-                       list.Add(enc);
-
-                       enc = new EncoderModeSelection(
-                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYROTARYAXIS.ToString(),
-                                       Constants.FileNameEncoderAxisWithMovPulley ,
-                                       "Rotary axis - moving pulley",
-                                       "Rotary axis encoder on weighted moving pulley.",
-                                       false,  //d
-                                       false,  //d2
-                                       false,  //angle
-                                       false   //inertia
-                                       ); 
-                       list.Add(enc);
-               }
-       }
-
-}
 
 public class EncoderModeSelection {
-       public string encoderMode;
+       public Constants.EncoderMode encoderMode;
+       public Constants.EncoderType type;
+       public int position;
        public string image;
        public string code;     //this code will be stored untranslated but will be translated just to be 
shown
-                               //TODO: decide if use this or Constants.EncoderMode
-                               //maybe this code has problems when sent to R (spaces, "-")
        public string text;
        public bool d;
        public bool d2;
        public bool angle;
        public bool inertia;
-       
-       public EncoderModeSelection() {
-       }
 
-       public EncoderModeSelection(
-                       string encoderMode, string image, string code, string text,
-                       bool d, bool d2, bool angle, bool inertia) {
+       
+       /* note: if this changes, change also in:
+        * Constants.EncoderModeSelectionList(enum encoderType)
+        */
+       public EncoderModeSelection(Constants.EncoderMode encoderMode) {
                this.encoderMode = encoderMode;
-               this.image = image;
-               this.code = code;
-               this.text = text;
-               this.d = d;
-               this.d2 = d2;
-               this.angle = angle;
-               this.inertia = inertia;
+               d = false;
+               d2 = false;
+               angle = false;
+               inertia = false;
+
+               if(encoderMode == Constants.EncoderMode.LINEAR) {
+                       type = Constants.EncoderType.LINEAR;
+                       position = 0;
+                       image = Constants.FileNameEncoderLinearFreeWeight;
+                       code = Constants.DefaultEncoderConfigurationCode;
+                       text = "Linear encoder attached to a barbell.";
+               }
+               else if(encoderMode == Constants.EncoderMode.LINEARINVERTED) {
+                       type = Constants.EncoderType.LINEAR;
+                       position = 1;
+                       image =Constants.FileNameEncoderLinearFreeWeightInv;
+                       code = "Linear inv - barbell";
+                       text = "Linear encoder inverted attached to a barbell.";
+               }
+               else if(encoderMode == Constants.EncoderMode.LINEARINERTIAL) {
+                       type = Constants.EncoderType.LINEAR;
+                       position = 2;
+                       image = Constants.FileNameEncoderLinearInertial;
+                       code = "Linear - inertial machine";
+                       text = "Linear encoder on inertia machine." + " " + "NOT Recommended!";
+                       
+                       inertia = true;
+               }
+               else if(encoderMode == Constants.EncoderMode.WEIGHTEDMOVPULLEYLINEARONPERSON1) {
+                       type = Constants.EncoderType.LINEAR;
+                       position = 3;
+                       image = Constants.FileNameEncoderWeightedMovPulleyOnPerson1;
+                       code = "Linear - barbell - moving pulley";
+                       text = "Linear encoder attached to a barbell." + " " + 
+                               "Barbell is connected to a weighted moving pulley.";
+               }
+               else if(encoderMode == Constants.EncoderMode.WEIGHTEDMOVPULLEYLINEARONPERSON1INV) {
+                       type = Constants.EncoderType.LINEAR;
+                       position = 4;
+                       image = Constants.FileNameEncoderWeightedMovPulleyOnPerson1Inv;
+                       code = "Linear inv - barbell - moving pulley";
+                       text = "Linear encoder inverted attached to a barbell." + " " + 
+                               "Barbell is connected to a weighted moving pulley.";
+               }
+               else if(encoderMode == Constants.EncoderMode.WEIGHTEDMOVPULLEYLINEARONPERSON2) {
+                       type = Constants.EncoderType.LINEAR;
+                       position = 5;
+                       image = Constants.FileNameEncoderWeightedMovPulleyOnPerson2;
+                       code = "Linear - barbell - pulley - moving pulley";
+                       text = "Linear encoder attached to a barbell." + " " + 
+                               "Barbell is connected to a fixed pulley that is connected to a weighted 
moving pulley.";
+               }
+               else if(encoderMode == Constants.EncoderMode.WEIGHTEDMOVPULLEYLINEARONPERSON2INV) {
+                       type = Constants.EncoderType.LINEAR;
+                       position = 6;
+                       image = Constants.FileNameEncoderWeightedMovPulleyOnPerson2Inv;
+                       code = "Linear inv - barbell - pulley - moving pulley";
+                       text = "Linear encoder inverted attached to a barbell." + " " + 
+                               "Barbell is connected to a fixed pulley that is connected to a weighted 
moving pulley.";
+               }
+               else if(encoderMode == Constants.EncoderMode.WEIGHTEDMOVPULLEYONLINEARENCODER) {
+                       type = Constants.EncoderType.LINEAR;
+                       position = 7;
+                       image = Constants.FileNameEncoderWeightedMovPulleyOnLinearEncoder;
+                       code = "Linear - moving pulley";
+                       text = "Linear encoder attached to a weighted moving pulley.";
+               }
+               else if(encoderMode == Constants.EncoderMode.LINEARONPLANE) {
+                       type = Constants.EncoderType.LINEAR;
+                       position = 8;
+                       image = Constants.FileNameEncoderLinearOnPlane;
+                       code = "Linear - inclinated plane";
+                       text = "Linear encoder on a inclinated plane.";
+                       
+                       angle = true;
+               }
+               else if(encoderMode == Constants.EncoderMode.ROTARYFRICTIONSIDE) {
+                       type = Constants.EncoderType.ROTARYFRICTION;
+                       position = 0;
+                       image = Constants.FileNameEncoderFrictionSide;
+                       code = "Rotary friction - pulley";
+                       text = "Rotary friction encoder on pulley.";
+               }
+               else if(encoderMode == Constants.EncoderMode.ROTARYFRICTIONAXIS) {
+                       type = Constants.EncoderType.ROTARYFRICTION;
+                       position = 1;
+                       image = Constants.FileNameEncoderFrictionAxis;
+                       code = "Rotary friction - pulley axis";
+                       text = "Rotary friction encoder on pulley axis.";
+
+                       d = true;
+                       d2 = true;
+               }
+               else if(encoderMode == Constants.EncoderMode.ROTARYFRICTIONINERTIAL) {
+                       type = Constants.EncoderType.ROTARYFRICTION;
+                       position = 2;
+                       image = Constants.FileNameEncoderFrictionInertial;
+                       code = "Rotary friction - inertial machine";
+                       text = "Rotary friction encoder on inertial machine.";
+
+                       inertia = true;
+               }
+               else if(encoderMode == Constants.EncoderMode.WEIGHTEDMOVPULLEYROTARYFRICTION) {
+                       type = Constants.EncoderType.ROTARYFRICTION;
+                       position = 3;
+                       image = Constants.FileNameEncoderFrictionWithMovPulley;
+                       code = "Rotary friction - moving pulley";
+                       text = "Rotary friction encoder on weighted moving pulley.";
+               }
+               else if(encoderMode == Constants.EncoderMode.ROTARYAXIS) {
+                       type = Constants.EncoderType.ROTARYAXIS;
+                       position = 0;
+                       image = Constants.FileNameEncoderRotaryAxisOnAxis;
+                       code = "Rotary axis - pulley axis";
+                       text = "Rotary axis encoder on pulley axis.";
+
+                       d = true;
+               }
+               else if(encoderMode == Constants.EncoderMode.ROTARYAXISINERTIAL) {
+                       type = Constants.EncoderType.ROTARYAXIS;
+                       position = 1;
+                       image = Constants.FileNameEncoderAxisInertial;
+                       code = "Rotary axis - inertial machine";
+                       text = "Rotary axis encoder on inertial machine.";
+
+                       inertia = true;
+               }
+               else if(encoderMode == Constants.EncoderMode.WEIGHTEDMOVPULLEYROTARYAXIS) {
+                       type = Constants.EncoderType.ROTARYAXIS;
+                       position = 2;
+                       image = Constants.FileNameEncoderAxisWithMovPulley;
+                       code = "Rotary axis - moving pulley";
+                       text = "Rotary axis encoder on weighted moving pulley.";
+               }
        }
 }
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 53a579c..62ded85 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Copyright (C) 2004-2012   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2014   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -178,6 +178,8 @@ public partial class ChronoJumpWindow
        EncoderCaptureOptionsWindow encoderCaptureOptionsWin;
        EncoderConfigurationWindow encoder_configuration_win;
 
+       EncoderModeSelection encoderModeSelectionCurrent;
+
        /* 
         * this contains last EncoderSQL captured, recalculated or loaded
         * 
@@ -227,7 +229,8 @@ public partial class ChronoJumpWindow
                encoder_pulsebar_analyze.Fraction = 1;
                encoder_pulsebar_analyze.Text = "";
        
-               label_encoder_selected.Text = Constants.DefaultEncoderConfigurationCode;
+               encoderModeSelectionCurrent = new EncoderModeSelection(Constants.EncoderMode.LINEAR);
+               label_encoder_selected.Text = encoderModeSelectionCurrent.code; 
                
                encoderCaptureListStore = new Gtk.ListStore (typeof (EncoderCurve));
 
@@ -249,7 +252,7 @@ public partial class ChronoJumpWindow
 
        void on_button_encoder_select_clicked (object o, EventArgs args) {
                encoder_configuration_win = EncoderConfigurationWindow.View(
-                               label_encoder_selected.Text,
+                               encoderModeSelectionCurrent,
                                encoderConfigurationWindowDiameter,
                                encoderConfigurationWindowDiameter2,
                                encoderConfigurationWindowAngle,
@@ -261,7 +264,8 @@ public partial class ChronoJumpWindow
        void on_encoder_configuration_win_accepted (object o, EventArgs args) {
                encoder_configuration_win.Button_accept.Clicked -= new 
EventHandler(on_encoder_configuration_win_accepted);
                
-               label_encoder_selected.Text = encoder_configuration_win.GetSelected();
+               encoderModeSelectionCurrent = encoder_configuration_win.GetSelected();
+               label_encoder_selected.Text = encoderModeSelectionCurrent.code;
                
                encoderConfigurationWindowDiameter = encoder_configuration_win.GetDiameter();
                encoderConfigurationWindowDiameter2 = encoder_configuration_win.GetDiameter2();
@@ -4624,222 +4628,3 @@ public class EncoderCaptureOptionsWindow {
                args.RetVal = true;
        }
 }
-
-public class EncoderConfigurationWindow {
-       [Widget] Gtk.Window encoder_configuration;
-       [Widget] Gtk.Image image_encoder_linear;
-       [Widget] Gtk.Image image_encoder_rotary_friction;
-       [Widget] Gtk.Image image_encoder_rotary_axis;
-       [Widget] Gtk.Image image_encoder_configuration;
-       [Widget] Gtk.RadioButton radio_linear;
-       [Widget] Gtk.RadioButton radio_rotary_friction;
-       [Widget] Gtk.RadioButton radio_rotary_axis;
-       [Widget] Gtk.Label label_count;
-       [Widget] Gtk.TextView textview;
-       [Widget] Gtk.Box hbox_d;
-       [Widget] Gtk.Box hbox_d2;
-       [Widget] Gtk.Box hbox_angle;
-       [Widget] Gtk.Box hbox_inertia;
-       [Widget] Gtk.Box hbox_inertia2;
-
-       [Widget] Gtk.SpinButton spin_d;
-       [Widget] Gtk.SpinButton spin_d2;
-       [Widget] Gtk.SpinButton spin_angle;
-       [Widget] Gtk.SpinButton spin_inertia;
-
-       [Widget] Gtk.Button button_accept;
-
-       static EncoderConfigurationWindow EncoderConfigurationWindowBox;
-       
-       EncoderModeSelectionList encoderModeSelectionList;
-
-       ArrayList list;
-       int listCurrent = 0; //current item on list
-       Pixbuf pixbuf;
-
-       EncoderConfigurationWindow () {
-               Glade.XML gladeXML;
-               gladeXML = Glade.XML.FromAssembly (Util.GetGladePath() + "chronojump.glade", 
"encoder_configuration", null);
-               gladeXML.Autoconnect(this);
-               
-               //three encoder types   
-               pixbuf = new Pixbuf (null, Util.GetImagePath(false) + Constants.FileNameEncoderTypeLinear);
-               image_encoder_linear.Pixbuf = pixbuf;
-
-               pixbuf = new Pixbuf (null, Util.GetImagePath(false) + 
Constants.FileNameEncoderTypeRotaryFriction);
-               image_encoder_rotary_friction.Pixbuf = pixbuf;
-
-               pixbuf = new Pixbuf (null, Util.GetImagePath(false) + 
Constants.FileNameEncoderTypeRotaryAxis);
-               image_encoder_rotary_axis.Pixbuf = pixbuf;
-
-               //put an icon to window
-               UtilGtk.IconWindow(encoder_configuration);
-       }
-       
-       static public EncoderConfigurationWindow View (string code, double d, double d2, int angle, int 
inertia) {
-               if (EncoderConfigurationWindowBox == null) {
-                       EncoderConfigurationWindowBox = new EncoderConfigurationWindow ();
-               }
-               
-               string type = EncoderConfigurationWindowBox.encoderModeSelectionListFindType(code);
-               //activate default radiobutton
-               if(type == Constants.EncoderType.ROTARYFRICTION.ToString())
-                       EncoderConfigurationWindowBox.radio_rotary_friction.Active = true;
-               else if(type == Constants.EncoderType.ROTARYAXIS.ToString())
-                       EncoderConfigurationWindowBox.radio_rotary_axis.Active = true;
-               else    //linear
-                       EncoderConfigurationWindowBox.radio_linear.Active = true;
-
-
-               int position = EncoderConfigurationWindowBox.encoderModeSelectionListFindPosition(type, code);
-               EncoderConfigurationWindowBox.initializeList(type, position);
-               
-               EncoderConfigurationWindowBox.updateValues(d, d2, angle, inertia);
-       
-               EncoderConfigurationWindowBox.encoder_configuration.Show ();
-               return EncoderConfigurationWindowBox;
-       }
-       
-       //finds with type of encoder is a code
-       private string encoderModeSelectionListFindType(string code) {
-               string [] types = { 
-                       Constants.EncoderType.LINEAR.ToString(), 
-                       Constants.EncoderType.ROTARYFRICTION.ToString(), 
-                       Constants.EncoderType.ROTARYAXIS.ToString()
-                       };
-
-               for(int i=0; i < types.Length; i++) {
-                       EncoderModeSelectionList eMSL = new EncoderModeSelectionList(types[i]);
-                       ArrayList l = eMSL.list;
-                       for(int j=0; j < l.Count ; j++)
-                               if( ( (EncoderModeSelection) l[j]).code == code)
-                                       return types[i];
-               }
-               //default if error
-               return types[0];
-       }
-       
-       //finds which position belongs to a code in a list
-       private int encoderModeSelectionListFindPosition(string type, string code) {
-               EncoderModeSelectionList eMSL = new EncoderModeSelectionList(type);
-               ArrayList l = eMSL.list;
-
-               for(int i=0; i < l.Count; i++)
-                       if( ( (EncoderModeSelection) l[i]).code == code)
-                               return i;
-               
-               //default if error
-               return 0;
-       }
-       
-       
-       private void on_radio_encoder_type_linear_toggled (object obj, EventArgs args) {
-               if(radio_linear.Active)
-                       initializeList(Constants.EncoderType.LINEAR.ToString(), 0);
-       }
-       private void on_radio_encoder_type_rotary_friction_toggled (object obj, EventArgs args) {
-               if(radio_rotary_friction.Active)
-                       initializeList(Constants.EncoderType.ROTARYFRICTION.ToString(), 0);
-       }
-       private void on_radio_encoder_type_rotary_axis_toggled (object obj, EventArgs args) {
-               if(radio_rotary_axis.Active)
-                       initializeList(Constants.EncoderType.ROTARYAXIS.ToString(), 0);
-       }
-       
-       private void initializeList(string type, int position) {
-               EncoderModeSelectionList encoderModeSelectionList = new EncoderModeSelectionList(type);
-               list = encoderModeSelectionList.list;
-               listCurrent = position; //current item on list
-               
-               updateImageAndConfigurationGUI();
-       }
-       
-       private void on_button_previous_clicked (object o, EventArgs args) {
-               listCurrent --;
-               if(listCurrent < 0)
-                       listCurrent = list.Count -1;
-               
-               updateImageAndConfigurationGUI();
-       }
-
-       private void on_button_next_clicked (object o, EventArgs args) {
-               listCurrent ++;
-               if(listCurrent > list.Count -1)
-                       listCurrent = 0;
-
-               updateImageAndConfigurationGUI();
-       }
-       
-       private void updateImageAndConfigurationGUI() {
-               EncoderModeSelection sel = (EncoderModeSelection) list[listCurrent];
-               
-               pixbuf = new Pixbuf (null, Util.GetImagePath(false) + sel.image);
-               image_encoder_configuration.Pixbuf = pixbuf;
-                       
-               TextBuffer tb1 = new TextBuffer (new TextTagTable());
-               tb1.Text = "[" + sel.code + "]\n" + sel.text;
-               textview.Buffer = tb1;
-               
-               hbox_d.Visible = sel.d;
-               hbox_d2.Visible = sel.d2;
-               hbox_angle.Visible = sel.angle;
-               hbox_inertia.Visible = sel.inertia;
-               hbox_inertia2.Visible = sel.inertia;
-               
-               label_count.Text = (listCurrent + 1).ToString() + " / " + list.Count.ToString();
-       }
-       
-       private void updateValues(double d, double d2, int angle, int inertia) {
-               if(d != -1)
-                       spin_d.Value = d;
-               if(d2 != -1)
-                       spin_d2.Value = d2;
-               if(angle != -1)
-                       spin_angle.Value = angle;
-               if(inertia != -1)
-                       spin_inertia.Value = inertia;
-       }
-       
-       public string GetSelected() {
-               EncoderModeSelection sel = (EncoderModeSelection) list[listCurrent];
-               return sel.code;
-       }
-       
-       public double GetDiameter() {
-               return (double) spin_d.Value; 
-       }
-       public double GetDiameter2() {
-               return (double) spin_d2.Value; 
-       }
-       public int GetAngle() {
-               return (int) spin_angle.Value; 
-       }
-       public int GetInertia() {
-               return (int) spin_inertia.Value; 
-       }
-       
-       
-       private void on_button_cancel_clicked (object o, EventArgs args)
-       {
-               EncoderConfigurationWindowBox.encoder_configuration.Hide();
-               EncoderConfigurationWindowBox = null;
-       }
-       
-       private void on_button_accept_clicked (object o, EventArgs args)
-       {
-               EncoderConfigurationWindowBox.encoder_configuration.Hide();
-       }
-       
-       protected void on_delete_event (object o, DeleteEventArgs args)
-       {
-               args.RetVal = true;
-                       
-               EncoderConfigurationWindowBox.encoder_configuration.Hide();
-               EncoderConfigurationWindowBox = null;
-       }
-
-       public Button Button_accept {
-               get { return button_accept; }
-       }
-               
-}
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index 477c72b..30ba3be 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -455,6 +455,47 @@ public class UtilEncoder
                //Log.Write(" " + byteReaded + ":" + byteConverted);
 
                return byteConverted;
-       }       
+       }
+
+       public static ArrayList EncoderModeSelectionList(Constants.EncoderType encoderType) {
+               ArrayList list = new ArrayList();
+               if(encoderType == Constants.EncoderType.LINEAR) {
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.LINEAR));
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.LINEARINVERTED));
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.LINEARINERTIAL));
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYLINEARONPERSON1));
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYLINEARONPERSON1INV));
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYLINEARONPERSON2));
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYLINEARONPERSON2INV));
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYONLINEARENCODER));
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.LINEARONPLANE));
+               } else if(encoderType == Constants.EncoderType.ROTARYFRICTION) {
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.ROTARYFRICTIONSIDE));
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.ROTARYFRICTIONAXIS));
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.ROTARYFRICTIONINERTIAL));
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYROTARYFRICTION));
+               } else if(encoderType == Constants.EncoderType.ROTARYAXIS) {
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.ROTARYAXIS));
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.ROTARYAXISINERTIAL));
+                       list.Add(new EncoderModeSelection(
+                                       Constants.EncoderMode.WEIGHTEDMOVPULLEYROTARYAXIS));
+               }
+               return list;
+       }
 
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]