[chronojump] Encoder configuration anchorage list (different diameters) WIP



commit 3169f3f373f9d6735127db565dfc3382ca8119d0
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Jul 29 16:54:30 2015 +0200

    Encoder configuration anchorage list (different diameters) WIP

 glade/chronojump.glade          |  151 ++++++++++++++++++++++++++++++++++++---
 src/encoder.cs                  |   30 ++++++++-
 src/gui/encoderConfiguration.cs |   94 ++++++++++++++++++++++++-
 3 files changed, 263 insertions(+), 12 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 96378d1..a533847 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -7636,6 +7636,9 @@ after time</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             </child>
                                                             <child>
@@ -9026,6 +9029,9 @@ after time</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">2</property>
@@ -10057,6 +10063,9 @@ after time</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">4</property>
@@ -21541,6 +21550,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -22471,6 +22483,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -23893,6 +23908,9 @@ by you</property>
               <placeholder/>
             </child>
             <child>
+              <placeholder/>
+            </child>
+            <child>
               <widget class="GtkButton" id="button_video_url">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -24372,6 +24390,9 @@ by you</property>
             <child>
               <placeholder/>
             </child>
+            <child>
+              <placeholder/>
+            </child>
           </widget>
           <packing>
             <property name="expand">True</property>
@@ -27080,6 +27101,79 @@ comments</property>
                                               </packing>
                                             </child>
                                             <child>
+                                              <widget class="GtkVBox" id="vbox_d">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="spacing">10</property>
+                                                <child>
+                                                  <widget class="GtkHBox" id="hbox10">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <property name="spacing">8</property>
+                                                    <child>
+                                                      <widget class="GtkLabel" id="label1">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="label" translatable="yes">Number of 
anchorages</property>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="fill">False</property>
+                                                        <property name="position">0</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <widget class="GtkComboBox" id="combo_d_num">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="items">1
+2
+3
+4
+5
+6
+7
+8
+9
+10</property>
+                                                        <signal name="changed" 
handler="on_combo_d_num_changed" swapped="no"/>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="fill">False</property>
+                                                        <property name="position">1</property>
+                                                      </packing>
+                                                    </child>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">True</property>
+                                                    <property name="fill">True</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <widget class="GtkHBox" id="hbox_list_d">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <property name="spacing">4</property>
+                                                    <child>
+                                                      <placeholder/>
+                                                    </child>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">True</property>
+                                                    <property name="fill">True</property>
+                                                    <property name="position">1</property>
+                                                  </packing>
+                                                </child>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">1</property>
+                                              </packing>
+                                            </child>
+                                            <child>
                                               <widget class="GtkHBox" id="hbox_D">
                                                 <property name="can_focus">False</property>
                                                 <property name="spacing">8</property>
@@ -27135,7 +27229,7 @@ comments</property>
                                               <packing>
                                                 <property name="expand">False</property>
                                                 <property name="fill">False</property>
-                                                <property name="position">1</property>
+                                                <property name="position">2</property>
                                               </packing>
                                             </child>
                                             <child>
@@ -27192,7 +27286,7 @@ comments</property>
                                               <packing>
                                                 <property name="expand">False</property>
                                                 <property name="fill">False</property>
-                                                <property name="position">2</property>
+                                                <property name="position">3</property>
                                               </packing>
                                             </child>
                                             <child>
@@ -27249,7 +27343,7 @@ comments</property>
                                               <packing>
                                                 <property name="expand">False</property>
                                                 <property name="fill">False</property>
-                                                <property name="position">3</property>
+                                                <property name="position">4</property>
                                               </packing>
                                             </child>
                                             <child>
@@ -27309,7 +27403,7 @@ comments</property>
                                               <packing>
                                                 <property name="expand">False</property>
                                                 <property name="fill">False</property>
-                                                <property name="position">4</property>
+                                                <property name="position">5</property>
                                               </packing>
                                             </child>
                                             <child>
@@ -27368,7 +27462,7 @@ comments</property>
                                               <packing>
                                                 <property name="expand">False</property>
                                                 <property name="fill">False</property>
-                                                <property name="position">5</property>
+                                                <property name="position">6</property>
                                               </packing>
                                             </child>
                                             <child>
@@ -27429,7 +27523,7 @@ to the center of the loads.</property>
                                               <packing>
                                                 <property name="expand">False</property>
                                                 <property name="fill">False</property>
-                                                <property name="position">6</property>
+                                                <property name="position">7</property>
                                               </packing>
                                             </child>
                                           </widget>
@@ -35746,6 +35840,24 @@ options</property>
                             <child>
                               <placeholder/>
                             </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
                           </widget>
                         </child>
                       </widget>
@@ -37429,6 +37541,18 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -38799,9 +38923,6 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                                       <placeholder/>
                                     </child>
                                     <child>
-                                      <placeholder/>
-                                    </child>
-                                    <child>
                                       <widget class="GtkLabel" id="label218">
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
@@ -39731,6 +39852,9 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                                     <child>
                                       <placeholder/>
                                     </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
                                   </widget>
                                 </child>
                               </widget>
@@ -43448,6 +43572,9 @@ It starts before and arrives there with some speed.</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                       <packing>
                         <property name="left_attach">2</property>
@@ -44042,6 +44169,9 @@ It starts before and arrives there with some speed.</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -44651,6 +44781,9 @@ It starts before and arrives there with some speed.</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
diff --git a/src/encoder.cs b/src/encoder.cs
index df458e3..468f539 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -23,6 +23,7 @@ using System.Data;
 using System.Text; //StringBuilder
 using System.IO;   //for Path
 using System.Collections; //ArrayList
+using System.Collections.Generic; //List<T>
 using Mono.Unix;
 
 public class EncoderParams
@@ -924,6 +925,8 @@ public class EncoderConfiguration {
        public int extraWeightN; //how much extra weights (inertia)
        public int extraWeightGrams; //weight of each extra weight (inertia)
        public double extraWeightLength; //length from center to center (cm) (inertia)
+       
+       public List<double> list_d;     //list of diameters depending on the anchorage position 
 
 
        public string textDefault = Catalog.GetString("Linear encoder attached to a barbell.") + "\n" + 
@@ -953,6 +956,7 @@ public class EncoderConfiguration {
                extraWeightN = 0;
                extraWeightGrams = 0;
                extraWeightLength = 1;
+               list_d = new List<double>(); 
        }
 
        // note: if this changes, change also in:
@@ -967,6 +971,7 @@ public class EncoderConfiguration {
                has_inertia = false;
                rotaryFrictionOnAxis = false;
                gearedDown = 1;
+               list_d = new List<double>(); 
 
                // ---- LINEAR ----
                // ---- not inertial
@@ -1266,6 +1271,8 @@ public class EncoderConfiguration {
                        this.extraWeightN =     Convert.ToInt32(strFull[8]);
                        this.extraWeightGrams = Convert.ToInt32(strFull[9]);
                        this.extraWeightLength = Convert.ToDouble(Util.ChangeDecimalSeparator(strFull[10]));
+                       if(strFull.Length > 11) //this param starts at 1.5.3
+                               list_d = readList_d(strFull[11]);
                } else {
                        this.inertiaTotal =     inertiaMachine;
                        this.extraWeightN =     0;
@@ -1273,6 +1280,17 @@ public class EncoderConfiguration {
                        this.extraWeightLength = 1;
                }
        }
+       //list_d contains the different diameters (byt eh anchorages). They are stored as '='
+       private List<double> readList_d(string listFromSQL) 
+       {
+               List<double> l = new List<double>(); 
+               string [] strFull = listFromSQL.Split(new char[] {'='});
+               foreach (string s in strFull) {
+                       double d = Convert.ToDouble(Util.ChangeDecimalSeparator(s));
+                       l.Add(d);
+               }
+               return l;
+       }
 
        //called on capture, recalculate, load
        public void SQLUpdate()
@@ -1328,10 +1346,20 @@ public class EncoderConfiguration {
                                inertiaTotal.ToString() + sep + 
                                extraWeightN.ToString() + sep + 
                                extraWeightGrams.ToString() + sep +
-                               extraWeightLength.ToString()
+                               extraWeightLength.ToString() + sep +
+                               writeList_d(list_d)
                                ;
                }
        }
+       private string writeList_d(List<double> l) {
+               string str = "";
+               string sep = "";
+               foreach(double d in l) {
+                       str += sep + Util.ConvertToPoint(d);
+                       sep = "=";
+               }
+               return str;
+       }
        
        //just to show on a treeview    
        public string ToStringPretty() {
diff --git a/src/gui/encoderConfiguration.cs b/src/gui/encoderConfiguration.cs
index 7b0d9fd..9973872 100644
--- a/src/gui/encoderConfiguration.cs
+++ b/src/gui/encoderConfiguration.cs
@@ -50,7 +50,22 @@ public class EncoderConfigurationWindow
        [Widget] Gtk.Label label_count;
 
        [Widget] Gtk.TextView textview;
-       [Widget] Gtk.Box hbox_d;
+
+       [Widget] Gtk.Box hbox_d; //TODO: this will be deprecated
+       [Widget] Gtk.Box vbox_d;
+       [Widget] Gtk.Box hbox_list_d;
+       [Widget] Gtk.ComboBox combo_d_num;
+       [Widget] Gtk.SpinButton spin_d_0;
+       [Widget] Gtk.SpinButton spin_d_1;
+       [Widget] Gtk.SpinButton spin_d_2;
+       [Widget] Gtk.SpinButton spin_d_3;
+       [Widget] Gtk.SpinButton spin_d_4;
+       [Widget] Gtk.SpinButton spin_d_5;
+       [Widget] Gtk.SpinButton spin_d_6;
+       [Widget] Gtk.SpinButton spin_d_7;
+       [Widget] Gtk.SpinButton spin_d_8;
+       [Widget] Gtk.SpinButton spin_d_9;
+
        [Widget] Gtk.Box hbox_D;
        [Widget] Gtk.Box hbox_angle_push;
        [Widget] Gtk.Box hbox_angle_weight;
@@ -59,7 +74,7 @@ public class EncoderConfigurationWindow
        [Widget] Gtk.Box hbox_inertia_length;
        [Widget] Gtk.Box vbox_inertia_calcule;
 
-       [Widget] Gtk.SpinButton spin_d;
+       [Widget] Gtk.SpinButton spin_d; //TODO: this will be deprecated
        [Widget] Gtk.SpinButton spin_D;
        [Widget] Gtk.SpinButton spin_angle_push;
        [Widget] Gtk.SpinButton spin_angle_weight;
@@ -137,6 +152,8 @@ public class EncoderConfigurationWindow
 
 
                EncoderConfigurationWindowBox.initializeList(ec.type, ec.has_inertia, 
ec.rotaryFrictionOnAxis, ec.position);
+       
+               EncoderConfigurationWindowBox.create_list_d_spinbutton();
                
                EncoderConfigurationWindowBox.putValuesStoredPreviously(
                                ec.d, ec.D, ec.anglePush, ec.angleWeight, 
@@ -249,6 +266,7 @@ public class EncoderConfigurationWindow
                textview.Buffer = tb1;
                
                hbox_d.Visible = ec.has_d;
+               vbox_d.Visible = ec.has_d;
                hbox_D.Visible = ec.has_D;
                hbox_angle_push.Visible = ec.has_angle_push;
                hbox_angle_weight.Visible = ec.has_angle_weight;
@@ -282,6 +300,78 @@ public class EncoderConfigurationWindow
                spin_inertia_length.Value = extraWeightLength;
        }
        
+       private void create_list_d_spinbutton () {
+               /*
+                * adjustment definition:
+                * initial value
+                * minimum value
+                * maximum value
+                * increment for a single step (e.g. one click on an arrow)
+                * increment for a page-up or page-down keypress
+                * page size (using any value other than 0 for this parameter is deprecated) 
+                * 
+                * spinbutton creation (adjustment, climb rate, decimals)
+                */
+               spin_d_0 = new Gtk.SpinButton(new Adjustment(4, .5f, 80.0f, .01f, 10.0f, 0f), 1, 2);
+               spin_d_1 = new Gtk.SpinButton(new Adjustment(4, .5f, 80.0f, .01f, 10.0f, 0f), 1, 2);
+               spin_d_2 = new Gtk.SpinButton(new Adjustment(4, .5f, 80.0f, .01f, 10.0f, 0f), 1, 2);
+               spin_d_3 = new Gtk.SpinButton(new Adjustment(4, .5f, 80.0f, .01f, 10.0f, 0f), 1, 2);
+               spin_d_4 = new Gtk.SpinButton(new Adjustment(4, .5f, 80.0f, .01f, 10.0f, 0f), 1, 2);
+               spin_d_5 = new Gtk.SpinButton(new Adjustment(4, .5f, 80.0f, .01f, 10.0f, 0f), 1, 2);
+               spin_d_6 = new Gtk.SpinButton(new Adjustment(4, .5f, 80.0f, .01f, 10.0f, 0f), 1, 2);
+               spin_d_7 = new Gtk.SpinButton(new Adjustment(4, .5f, 80.0f, .01f, 10.0f, 0f), 1, 2);
+               spin_d_8 = new Gtk.SpinButton(new Adjustment(4, .5f, 80.0f, .01f, 10.0f, 0f), 1, 2);
+               spin_d_9 = new Gtk.SpinButton(new Adjustment(4, .5f, 80.0f, .01f, 10.0f, 0f), 1, 2);
+               
+               reset_hbox_list_d (1);
+       }
+
+       private void on_combo_d_num_changed (object o, EventArgs args) {
+               reset_hbox_list_d(Convert.ToInt32(UtilGtk.ComboGetActive(combo_d_num)));
+       }
+       
+       void reset_hbox_list_d (int colsNum) 
+       {
+               foreach(Gtk.SpinButton sp in hbox_list_d.Children)
+                       hbox_list_d.Remove(sp);
+
+               for (int i = 0; i < colsNum; i ++) {
+                       switch(i) {
+                               case 0: 
+                                       hbox_list_d.PackStart(spin_d_0, false, false, 0);
+                                       break;
+                               case 1: 
+                                       hbox_list_d.PackStart(spin_d_1, false, false, 0);
+                                       break;
+                               case 2: 
+                                       hbox_list_d.PackStart(spin_d_2, false, false, 0);
+                                       break;
+                               case 3: 
+                                       hbox_list_d.PackStart(spin_d_3, false, false, 0);
+                                       break;
+                               case 4: 
+                                       hbox_list_d.PackStart(spin_d_4, false, false, 0);
+                                       break;
+                               case 5: 
+                                       hbox_list_d.PackStart(spin_d_5, false, false, 0);
+                                       break;
+                               case 6: 
+                                       hbox_list_d.PackStart(spin_d_6, false, false, 0);
+                                       break;
+                               case 7: 
+                                       hbox_list_d.PackStart(spin_d_7, false, false, 0);
+                                       break;
+                               case 8: 
+                                       hbox_list_d.PackStart(spin_d_8, false, false, 0);
+                                       break;
+                               case 9: 
+                                       hbox_list_d.PackStart(spin_d_9, false, false, 0);
+                                       break;
+                       }
+               }
+               hbox_list_d.ShowAll();
+       }
+       
        /*
         * Use this to retrieve values after accept
         * do not use to know current encoder configuration


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