[chronojump] ForceSensor elastic manage multiple of each fixture



commit 2aa5f2fdb323b815a180d34df7750a537100d97f
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Oct 24 14:09:35 2019 +0200

    ForceSensor elastic manage multiple of each fixture

 diagrams/sqlite/chronojump_sqlite.dia  | Bin 19239 -> 19279 bytes
 glade/force_sensor_elastic_bands.glade | 344 +++++++++++++++++++++------------
 src/forceSensor.cs                     |  23 ++-
 src/gui/forceSensor.cs                 |   3 +
 src/gui/forceSensorElasticBands.cs     | 141 +++++---------
 src/sqlite/forceSensor.cs              |   8 +-
 6 files changed, 283 insertions(+), 236 deletions(-)
---
diff --git a/diagrams/sqlite/chronojump_sqlite.dia b/diagrams/sqlite/chronojump_sqlite.dia
index 9a604153..52926b88 100644
Binary files a/diagrams/sqlite/chronojump_sqlite.dia and b/diagrams/sqlite/chronojump_sqlite.dia differ
diff --git a/glade/force_sensor_elastic_bands.glade b/glade/force_sensor_elastic_bands.glade
index d2271ac0..c9dc70b3 100644
--- a/glade/force_sensor_elastic_bands.glade
+++ b/glade/force_sensor_elastic_bands.glade
@@ -171,60 +171,240 @@
               <widget class="GtkVBox" id="vbox1">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="border_width">10</property>
+                <property name="border_width">12</property>
+                <property name="spacing">20</property>
                 <child>
-                  <widget class="GtkHBox" id="hbox1">
+                  <widget class="GtkHBox" id="hbox4">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="spacing">20</property>
+                    <property name="spacing">30</property>
                     <child>
-                      <widget class="GtkTable" id="table_add_edit">
+                      <widget class="GtkHBox" id="hbox6">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="border_width">10</property>
-                        <property name="n_rows">4</property>
-                        <property name="n_columns">2</property>
-                        <property name="column_spacing">12</property>
-                        <property name="row_spacing">8</property>
+                        <property name="spacing">20</property>
                         <child>
-                          <widget class="GtkLabel" id="label2">
+                          <widget class="GtkCheckButton" id="check_active">
+                            <property name="label" translatable="yes">Active</property>
                             <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes">Brand</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="draw_indicator">True</property>
+                            <signal name="toggled" handler="on_check_active_toggled" swapped="no"/>
                           </widget>
                           <packing>
-                            <property name="x_options">GTK_FILL</property>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkLabel" id="label_entry2">
-                            <property name="visible">True</property>
+                          <widget class="GtkHBox" id="hbox_active">
                             <property name="can_focus">False</property>
-                            <property name="xalign">0</property>
-                            <property name="label">Color</property>
+                            <property name="spacing">6</property>
+                            <child>
+                              <widget class="GtkLabel" id="label6">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="label" translatable="yes">Active units</property>
+                              </widget>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <widget class="GtkSpinButton" id="spin_active_units">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="invisible_char">●</property>
+                                <property name="primary_icon_activatable">False</property>
+                                <property name="secondary_icon_activatable">False</property>
+                                <property name="primary_icon_sensitive">True</property>
+                                <property name="secondary_icon_sensitive">True</property>
+                                <property name="adjustment">1 1 99 1 10 0</property>
+                                <property name="numeric">True</property>
+                                <signal name="value_changed" handler="on_spin_active_units_value_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="top_attach">1</property>
-                            <property name="bottom_attach">2</property>
-                            <property name="x_options">GTK_FILL</property>
+                            <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="GtkVButtonBox" id="vbuttonbox1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="layout_style">spread</property>
                         <child>
-                          <widget class="GtkLabel" id="label_entry1">
+                          <widget class="GtkButton" id="button_save">
+                            <property name="label">gtk-save</property>
                             <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="xalign">0</property>
-                            <property name="label">Stiffness</property>
+                            <property name="sensitive">False</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <property name="use_stock">True</property>
+                            <signal name="clicked" handler="on_button_save_clicked" swapped="no"/>
                           </widget>
                           <packing>
-                            <property name="top_attach">2</property>
-                            <property name="bottom_attach">3</property>
-                            <property name="x_options">GTK_FILL</property>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
                           </packing>
                         </child>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="pack_type">end</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkTable" id="table_add_edit">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="n_rows">4</property>
+                    <property name="n_columns">2</property>
+                    <property name="column_spacing">12</property>
+                    <property name="row_spacing">8</property>
+                    <child>
+                      <widget class="GtkEntry" id="entry_comments">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="invisible_char">●</property>
+                        <property name="invisible_char_set">True</property>
+                        <property name="primary_icon_activatable">False</property>
+                        <property name="secondary_icon_activatable">False</property>
+                        <property name="primary_icon_sensitive">True</property>
+                        <property name="secondary_icon_sensitive">True</property>
+                        <signal name="changed" handler="on_entries_changed" swapped="no"/>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkLabel" id="label_entry4">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label">Comments</property>
+                      </widget>
+                      <packing>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
+                        <property name="x_options">GTK_FILL</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkLabel" id="label2">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Brand</property>
+                      </widget>
+                      <packing>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkLabel" id="label_entry2">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label">Color</property>
+                      </widget>
+                      <packing>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
+                        <property name="x_options">GTK_FILL</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkEntry" id="entry_brand">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="invisible_char">●</property>
+                        <property name="invisible_char_set">True</property>
+                        <property name="primary_icon_activatable">False</property>
+                        <property name="secondary_icon_activatable">False</property>
+                        <property name="primary_icon_sensitive">True</property>
+                        <property name="secondary_icon_sensitive">True</property>
+                        <signal name="changed" handler="on_entries_changed" swapped="no"/>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkEntry" id="entry_color">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="invisible_char">●</property>
+                        <property name="invisible_char_set">True</property>
+                        <property name="primary_icon_activatable">False</property>
+                        <property name="secondary_icon_activatable">False</property>
+                        <property name="primary_icon_sensitive">True</property>
+                        <property name="secondary_icon_sensitive">True</property>
+                        <signal name="changed" handler="on_entries_changed" swapped="no"/>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkLabel" id="label5">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Stiffness</property>
+                      </widget>
+                      <packing>
+                        <property name="x_options">GTK_FILL</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkHBox" id="hbox8">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="spacing">20</property>
                         <child>
-                          <widget class="GtkHBox" id="hbox4">
+                          <widget class="GtkHBox" id="hbox1">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
                             <property name="spacing">6</property>
@@ -244,7 +424,7 @@
                                 <property name="numeric">True</property>
                               </widget>
                               <packing>
-                                <property name="expand">False</property>
+                                <property name="expand">True</property>
                                 <property name="fill">True</property>
                                 <property name="position">0</property>
                               </packing>
@@ -263,120 +443,34 @@
                             </child>
                           </widget>
                           <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
-                            <property name="top_attach">2</property>
-                            <property name="bottom_attach">3</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <widget class="GtkEntry" id="entry_color">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="invisible_char">●</property>
-                            <property name="invisible_char_set">True</property>
-                            <property name="primary_icon_activatable">False</property>
-                            <property name="secondary_icon_activatable">False</property>
-                            <property name="primary_icon_sensitive">True</property>
-                            <property name="secondary_icon_sensitive">True</property>
-                            <signal name="changed" handler="on_entries_changed" swapped="no"/>
-                          </widget>
-                          <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
-                            <property name="top_attach">1</property>
-                            <property name="bottom_attach">2</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <widget class="GtkEntry" id="entry_brand">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="invisible_char">●</property>
-                            <property name="invisible_char_set">True</property>
-                            <property name="primary_icon_activatable">False</property>
-                            <property name="secondary_icon_activatable">False</property>
-                            <property name="primary_icon_sensitive">True</property>
-                            <property name="secondary_icon_sensitive">True</property>
-                            <signal name="changed" handler="on_entries_changed" swapped="no"/>
-                          </widget>
-                          <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <widget class="GtkEntry" id="entry_comments">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="invisible_char">●</property>
-                            <property name="invisible_char_set">True</property>
-                            <property name="primary_icon_activatable">False</property>
-                            <property name="secondary_icon_activatable">False</property>
-                            <property name="primary_icon_sensitive">True</property>
-                            <property name="secondary_icon_sensitive">True</property>
-                            <signal name="changed" handler="on_entries_changed" swapped="no"/>
-                          </widget>
-                          <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
-                            <property name="top_attach">3</property>
-                            <property name="bottom_attach">4</property>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkLabel" id="label_entry4">
+                          <widget class="GtkLabel" id="label_stiffness_of_each_fixture">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
-                            <property name="xalign">0</property>
-                            <property name="label">Comments</property>
-                          </widget>
-                          <packing>
-                            <property name="top_attach">3</property>
-                            <property name="bottom_attach">4</property>
-                            <property name="x_options">GTK_FILL</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="GtkVButtonBox" id="vbuttonbox1">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="layout_style">spread</property>
-                        <child>
-                          <widget class="GtkButton" id="button_save">
-                            <property name="label">gtk-save</property>
-                            <property name="visible">True</property>
-                            <property name="sensitive">False</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
-                            <property name="use_stock">True</property>
-                            <signal name="clicked" handler="on_button_save_clicked" swapped="no"/>
+                            <property name="label" translatable="yes">(of each fixture)</property>
                           </widget>
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">0</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>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
                       </packing>
                     </child>
                   </widget>
                   <packing>
                     <property name="expand">True</property>
                     <property name="fill">True</property>
-                    <property name="position">0</property>
+                    <property name="position">1</property>
                   </packing>
                 </child>
               </widget>
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 048ac471..b881c59f 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -437,7 +437,7 @@ public class ForceSensorExercise
 public class ForceSensorElasticBand
 {
        private int uniqueID;
-       private bool active;
+       private int active;
        private string brand;
        private string color;
        private double stiffness;
@@ -451,7 +451,7 @@ public class ForceSensorElasticBand
                uniqueID = -1; //undefined
        }
 
-       public ForceSensorElasticBand(int uniqueID, bool active, string brand, string color, double 
stiffness, string comments)
+       public ForceSensorElasticBand(int uniqueID, int active, string brand, string color, double stiffness, 
string comments)
        {
                this.uniqueID = uniqueID;
                this.active = active;
@@ -463,15 +463,9 @@ public class ForceSensorElasticBand
 
        // public methods ----
 
-       /*
-       public void UpdateActive (bool active)
+       public void Update(int active, string brand, string color, double stiffness, string comments)
        {
                this.active = active;
-       }
-       */
-
-       public void Update(string brand, string color, double stiffness, string comments)
-       {
                this.brand = brand;
                this.color = color;
                this.stiffness = stiffness;
@@ -486,7 +480,7 @@ public class ForceSensorElasticBand
 
                LogB.Information("stiffness is: " + stiffness.ToString());
                return
-                       uniqueIDStr + ", " + Util.BoolToInt(active).ToString() +
+                       uniqueIDStr + ", " + active.ToString() +
                        ", \"" + brand + "\", \"" + color + "\", " +
                        Util.ConvertToPoint(stiffness) + ", \"" + comments + "\"";
        }
@@ -498,9 +492,9 @@ public class ForceSensorElasticBand
                int i=0;
                str[i++] = uniqueID.ToString();
                str[i++] = active.ToString();
+               str[i++] = stiffness.ToString();
                str[i++] = brand;
                str[i++] = color;
-               str[i++] = stiffness.ToString();
                str[i++] = comments;
 
                return str;
@@ -530,11 +524,16 @@ public class ForceSensorElasticBand
                return str;
        }
 
+       //stiffnessString is the string of a loaded set
+       public static void UpdateBandsStatus (List<ForceSensorElasticBand> list_at_db, string stiffnessString)
+       {
+       }
+
        public int UniqueID
        {
                get { return uniqueID; }
        }
-       public bool Active
+       public int Active
        {
                get { return active; }
        }
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index 3a9f76b7..36a1ee9b 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -1539,6 +1539,7 @@ LogB.Information(" fs R ");
 
                assignCurrentForceSensorExercise();
 
+               // stiffness 1: change button_force_sensor_stiffness
                if(currentForceSensorExercise.ComputeAsElastic)
                {
                        setStiffnessButtonLabel(fs.Stiffness);
@@ -1548,6 +1549,8 @@ LogB.Information(" fs R ");
                        button_force_sensor_stiffness.Label = "0";
                        button_force_sensor_stiffness.Visible = false;
                }
+               // stiffness 2: update elastic bands table
+
 
                forceSensorCopyTempAndDoGraphs();
 
diff --git a/src/gui/forceSensorElasticBands.cs b/src/gui/forceSensorElasticBands.cs
index 502df4c8..f2f61e1d 100644
--- a/src/gui/forceSensorElasticBands.cs
+++ b/src/gui/forceSensorElasticBands.cs
@@ -30,19 +30,22 @@ public class ForceSensorElasticBandsWindow
 {
        [Widget] Gtk.Window force_sensor_elastic_bands;
        [Widget] Gtk.Label label_header;
-       //[Widget] Gtk.VBox vbox_bands;
        //[Widget] Gtk.ScrolledWindow scrolled_window_treeview;
        [Widget] Gtk.TreeView treeview;
        [Widget] Gtk.Button button_save;
        [Widget] Gtk.Button button_delete;
        [Widget] Gtk.Button button_close;
+       [Widget] Gtk.CheckButton check_active;
+       [Widget] Gtk.HBox hbox_active;
+       [Widget] Gtk.SpinButton spin_active_units;
+       [Widget] Gtk.SpinButton spin_stiffness;
+       [Widget] Gtk.Label label_stiffness_of_each_fixture;
        [Widget] Gtk.Label label_total_stiffness_value;
        [Widget] Gtk.Frame frame_add_edit;
        [Widget] Gtk.Label label_edit_or_add;
        [Widget] Gtk.Entry entry_brand;
        [Widget] Gtk.Entry entry_color;
        [Widget] Gtk.Entry entry_comments;
-       [Widget] Gtk.SpinButton spin_stiffness;
 
        [Widget] Gtk.Button fakeButton_stiffness_changed;
 
@@ -50,13 +53,6 @@ public class ForceSensorElasticBandsWindow
        
        private TreeStore store;
 
-       //used to read data, see if it's ok, and print an error message.
-       //if all is ok, destroy it with HideAndNull()
-       //public bool HideOnAccept;
-       
-       //used when we don't need to read data, 
-       //and we want to ensure next window will be created at needed size
-       //public bool DestroyOnAccept;
        public int TreeviewSelectedUniqueID;
 
        public int uniqueID;                    //used on encoder & forceSensor edit exercise
@@ -126,9 +122,11 @@ public class ForceSensorElasticBandsWindow
                        
        private ForceSensorElasticBand getForceSensorElasticBand(TreeIter iter)
        {
+               LogB.Information("getForceSensorElasticBand uniqueID: " + Convert.ToInt32(store.GetValue 
(iter, 0)).ToString());
                return new ForceSensorElasticBand(
                                Convert.ToInt32(store.GetValue (iter, 0)),
-                               (bool) store.GetValue (iter, 1),
+                               //(bool) store.GetValue (iter, 1),
+                               Convert.ToInt32(store.GetValue (iter, 1)), //active
                                store.GetValue (iter, 2).ToString(), //brand
                                store.GetValue (iter, 3).ToString(), //color
                                Convert.ToDouble(store.GetValue (iter, stiffnessColumn)),
@@ -138,6 +136,8 @@ public class ForceSensorElasticBandsWindow
 
        private void empty_frame()
        {
+               check_active.Active = false;
+               spin_active_units.Value = 1;
                entry_brand.Text = "";
                entry_color.Text = "";
                entry_comments.Text = "";
@@ -145,6 +145,15 @@ public class ForceSensorElasticBandsWindow
        }
        private void fill_frame(ForceSensorElasticBand fseb)
        {
+               if(fseb.Active == 0) {
+                       check_active.Active = false;
+                       spin_active_units.Value = 1;
+               }
+               else {
+                       check_active.Active = true;
+                       spin_active_units.Value = fseb.Active;
+               }
+
                entry_brand.Text = fseb.Brand;
                entry_color.Text = fseb.Color;
                entry_comments.Text = fseb.Comments;
@@ -157,11 +166,13 @@ public class ForceSensorElasticBandsWindow
                string [] columnsString = new string [] {
                        //Catalog.GetString("ID"),
                        "ID",
-                       Catalog.GetString("Selected"),  //checkboxes
-                       Catalog.GetString("Brand"), Catalog.GetString("Color"),
-                               Catalog.GetString("Stiffness"), Catalog.GetString("Comments") 
+                       Catalog.GetString("Active"),    //checkboxes
+                       Catalog.GetString("Stiffness"),
+                       Catalog.GetString("Brand"),
+                       Catalog.GetString("Color"),
+                       Catalog.GetString("Comments")
                };
-               stiffnessColumn = 4;
+               stiffnessColumn = 2;
 
                store = getStore(columnsString.Length); 
                treeview.Model = store;
@@ -187,34 +198,16 @@ public class ForceSensorElasticBandsWindow
                        store.AppendValues (fseb.ToStringArray());
                }
 
-               markActiveRows(list_fseb);
                stiffnessTotalUpdate();
        }
 
-       private void markActiveRows(List<ForceSensorElasticBand> list_fseb) 
-       {
-               int count = 0;
-               Gtk.TreeIter iter;
-               bool okIter = store.GetIterFirst(out iter);
-               if(okIter) {
-                       do {
-                               foreach(ForceSensorElasticBand fseb in list_fseb)
-                                       if(fseb.Active && fseb.UniqueID == Convert.ToInt32(store.GetValue 
(iter, 0)))
-                                               store.SetValue (iter, 1, true);
-                       } while ( store.IterNext(ref iter) );
-               }
-       }
-       
        private TreeStore getStore (int columns)
        {
                //prepares the TreeStore for required columns
                Type [] types = new Type [columns];
 
                for (int i=0; i < columns; i++) {
-                       if(i == 1)
-                               types[1] = typeof (bool);
-                       else
-                               types[i] = typeof (string);
+                       types[i] = typeof (string);
                }
                TreeStore myStore = new TreeStore(types);
                return myStore;
@@ -227,10 +220,7 @@ public class ForceSensorElasticBandsWindow
                int i=0;
                bool visible = false;
                foreach(string myCol in columnsString) {
-                       if(i == 1)
-                               createCheckboxes(treeview, columnsString[1]);
-                       else
-                               UtilGtk.CreateCols(treeview, store, myCol, i, visible);
+                       UtilGtk.CreateCols(treeview, store, myCol, i, visible);
 //                     if(i == 1)      //first columns: ID, is hidden
 //                             store.SetSortFunc (0, UtilGtk.IdColumnCompare);
                        visible = true;
@@ -262,11 +252,15 @@ public class ForceSensorElasticBandsWindow
        }
        private void on_button_save_clicked (object o, EventArgs args)
        {
+               int active = 0;
+               if(check_active.Active)
+                       active = Convert.ToInt32(spin_active_units.Value);
+
                //1) insert on SQL
                if(currentMode == modes.ADDING)
                {
                        //create fseb from frame_add_edit
-                       ForceSensorElasticBand fseb = new ForceSensorElasticBand(-1, false, entry_brand.Text, 
entry_color.Text, spin_stiffness.Value, entry_comments.Text);
+                       ForceSensorElasticBand fseb = new ForceSensorElasticBand(-1, active, 
entry_brand.Text, entry_color.Text, spin_stiffness.Value, entry_comments.Text);
 
                        //insert on SQL
                        SqliteForceSensorElasticBand.Insert(false, fseb);
@@ -280,7 +274,7 @@ public class ForceSensorElasticBandsWindow
                        ForceSensorElasticBand fseb = getSelectedForceSensorElasticBand();
 
                        //change the params on frame_add_edit
-                       fseb.Update(entry_brand.Text, entry_color.Text, spin_stiffness.Value, 
entry_comments.Text);
+                       fseb.Update(active, entry_brand.Text, entry_color.Text, spin_stiffness.Value, 
entry_comments.Text);
 
                        //update SQL
                        SqliteForceSensorElasticBand.Update(false, fseb);
@@ -311,39 +305,6 @@ public class ForceSensorElasticBandsWindow
                button_delete.Sensitive = false;
        }
 
-       private void createCheckboxes(TreeView tv, string headerName) 
-       {
-               CellRendererToggle crt = new CellRendererToggle();
-               crt.Visible = true;
-               crt.Activatable = true;
-               crt.Active = true;
-               crt.Toggled += ItemToggled;
-
-               TreeViewColumn column = new TreeViewColumn (headerName, crt, "active", 1);
-               column.Clickable = true;
-               tv.AppendColumn (column);
-               
-       }
-
-       private void ItemToggled(object o, ToggledArgs args)
-       {
-               int column = 1;
-               TreeIter iter;
-               if (store.GetIter (out iter, new TreePath(args.Path))) 
-               {
-                       //Log.WriteLine(args.Path);
-                       bool val = (bool) store.GetValue (iter, column);
-                       //Log.WriteLine (string.Format("toggled {0} with value {1}", args.Path, !val));
-
-                       store.SetValue (iter, column, !val);
-
-                       ForceSensorElasticBand fseb = getForceSensorElasticBand(iter);
-                       SqliteForceSensorElasticBand.Update(false, fseb);
-               }
-
-               stiffnessTotalUpdate();
-       }
-
        private void stiffnessTotalUpdate()
        {
                double sum = 0;
@@ -351,14 +312,25 @@ public class ForceSensorElasticBandsWindow
                bool okIter = store.GetIterFirst(out iter);
                if(okIter) {
                        do {
-                               if((bool) store.GetValue (iter, 1))
-                                       sum += Convert.ToDouble(store.GetValue (iter, stiffnessColumn));
+                               int mult = Convert.ToInt32(store.GetValue (iter, 1));
+                               sum += mult * Convert.ToDouble(store.GetValue (iter, stiffnessColumn));
                        } while ( store.IterNext(ref iter) );
                }
                label_total_stiffness_value.Text = sum.ToString();
                fakeButton_stiffness_changed.Click();
        }
 
+       private void on_check_active_toggled (object o, EventArgs args)
+       {
+               hbox_active.Visible = check_active.Active;
+               on_spin_active_units_value_changed (new object (), new EventArgs ());
+       }
+
+       private void on_spin_active_units_value_changed (object o, EventArgs args)
+       {
+               label_stiffness_of_each_fixture.Visible = (Convert.ToInt32(spin_active_units.Value) > 1);
+       }
+
        private void on_entries_changed (object o, EventArgs args)
        {
                Gtk.Entry entry = o as Gtk.Entry;
@@ -386,27 +358,6 @@ public class ForceSensorElasticBandsWindow
                ForceSensorElasticBandsWindowBox = null;
        }
 
-
-       /*      
-       //when ! HideOnAccept, use this to close window
-       //also is better to call it always tat is closed clicking on accept (after data has been readed)
-       public void HideAndNull()
-       {
-               //this check is extra safety if there are extra EventHandlers opened with +=
-               if(ForceSensorElasticBandsWindowBox.force_sensor_elastic_bands != null)
-                       ForceSensorElasticBandsWindowBox.force_sensor_elastic_bands.Hide();
-
-               ForceSensorElasticBandsWindowBox = null;
-       }
-       */
-
-       /*      
-       public Button Button_accept {
-               set { button_accept = value; }
-               get { return button_accept; }
-       }
-       */
-
        public double TotalStiffness
        {
                get {
diff --git a/src/sqlite/forceSensor.cs b/src/sqlite/forceSensor.cs
index 9a0d21d3..630eacec 100644
--- a/src/sqlite/forceSensor.cs
+++ b/src/sqlite/forceSensor.cs
@@ -630,7 +630,7 @@ class SqliteForceSensorElasticBand : Sqlite
                dbcmd.CommandText =
                        "CREATE TABLE " + table + " ( " +
                        "uniqueID INTEGER PRIMARY KEY AUTOINCREMENT, " +
-                       "active INT, " +        //bool
+                       "active INT, " +        //0 inactive, 3 using 3 like this now
                        "brand TEXT, " +
                        "color TEXT, " +
                        "stiffness FLOAT, " +
@@ -666,7 +666,7 @@ class SqliteForceSensorElasticBand : Sqlite
                        Sqlite.Open();
 
                dbcmd.CommandText = "UPDATE " + table + " SET " +
-                       " active = " + Util.BoolToInt(eb.Active).ToString() +
+                       " active = " + eb.Active.ToString() +
                        ", brand = \"" + eb.Brand +
                        "\", color = \"" + eb.Color +
                        "\", stiffness = " + Util.ConvertToPoint(eb.Stiffness) +
@@ -698,7 +698,7 @@ class SqliteForceSensorElasticBand : Sqlite
 
                dbcmd.CommandText = "SELECT * FROM " + table;
                if(onlyActive)
-                       dbcmd.CommandText += " WHERE active = 1";
+                       dbcmd.CommandText += " WHERE active > 0";
 
                LogB.SQL(dbcmd.CommandText.ToString());
 
@@ -711,7 +711,7 @@ class SqliteForceSensorElasticBand : Sqlite
                while(reader.Read()) {
                        ForceSensorElasticBand fseb = new ForceSensorElasticBand (
                                        Convert.ToInt32(reader[0].ToString()),  //uniqueID
-                                       Util.IntToBool(Convert.ToInt32(reader[1])),     //active
+                                       Convert.ToInt32(reader[1].ToString()),  //active
                                        reader[2].ToString(),                   //brand
                                        reader[3].ToString(),                   //color
                                        Convert.ToDouble(Util.ChangeDecimalSeparator(reader[4].ToString())),



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