[chronojump] DB: 1.51 triggers can be activated at start capture or at first trigger



commit 0fe34556376e96a2f9efb589a74cdffec3a40094
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jan 12 18:36:13 2018 +0100

    DB: 1.51 triggers can be activated at start capture or at first trigger

 encoder/call_capture.R      |    7 --
 encoder/capture.R           |    8 +-
 encoder/graph.R             |   42 ++++---
 encoder/util.R              |    7 +-
 glade/preferences_win.glade |  251 +++++++++++++++++++++++++++++++++++++++++--
 images/md/trigger_2x.xcf    |  Bin 8509 -> 9513 bytes
 images/md/trigger_no_2x.png |  Bin 0 -> 1601 bytes
 src/Makefile.am             |    1 +
 src/encoderCapture.cs       |   67 ++++++++----
 src/encoderRProc.cs         |    4 +-
 src/gui/encoder.cs          |   18 ++--
 src/gui/preferences.cs      |   79 ++++++++++++--
 src/preferences.cs          |    3 +-
 src/sqlite/main.cs          |   17 +++-
 src/sqlite/preferences.cs   |    5 +-
 src/trigger.cs              |    6 +-
 16 files changed, 422 insertions(+), 93 deletions(-)
---
diff --git a/encoder/call_capture.R b/encoder/call_capture.R
index 2fc54c4..2add526 100644
--- a/encoder/call_capture.R
+++ b/encoder/call_capture.R
@@ -29,13 +29,6 @@ DebugFileName <- paste(options[5], "/chronojump-debug.txt", sep="")
 
 CROSSVALIDATESMOOTH <- FALSE
 
-if(options[33] == 1) {
-       cutByTriggers <- TRUE
-} else {
-       cutByTriggers <- FALSE
-}
-
-
 f <- file("stdin")
 open(f)
 
diff --git a/encoder/capture.R b/encoder/capture.R
index 2b46719..6d0f5a2 100644
--- a/encoder/capture.R
+++ b/encoder/capture.R
@@ -16,8 +16,6 @@ g = 9.81
 
 #debug = FALSE
 
-cutByTriggers <- NULL
-
 filenameCompose <- function(curveNum)
 {
        if(curveNum > 99)
@@ -43,8 +41,8 @@ calcule <- function(displacement, op, curveNum, startInSet)
        if(length(displacement) < 4)
                return (curveNum)
 
-       #minHeight is checked when ! cutByTriggers
-       if(! cutByTriggers && abs(sum(displacement)) < op$MinHeight)
+       #minHeight is checked when ! using triggers
+       if(op$TriggersOnList != -1 && abs(sum(displacement)) < op$MinHeight)
                return (curveNum)
 
 
@@ -226,7 +224,7 @@ doProcess <- function(options)
 
                start = NULL
                end = NULL
-               if(cutByTriggers)
+               if(op$TriggersOnList != -1)
                {
                        start = 1
                        end = length(displacement)
diff --git a/encoder/graph.R b/encoder/graph.R
index f3d93e3..3e94be5 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -124,23 +124,28 @@ translateVector <- function(englishVector) {
         return(translatedVector)
 }
 
-#this function is called if there are two or more triggersOn
-findCurvesByTriggers <- function(displacement, triggersOn)
+findCurvesByTriggers <- function(displacement, triggersOnList)
 {
         position <- cumsum(displacement)
         
-        start  <- 0
-        end    <- 0
-        startH <- 0
-        
-        #TODO: check problems if there's only on triggerOn
-        print(c("triggersOn:", triggersOn))
-        
-        for( i in 1:(length(triggersOn) -1) )
+        start          <- 0
+        end            <- 0
+        startH         <- 0
+
+        print(c("triggersOnList:", triggersOnList))
+
+       start[1]  <- 1
+       startH[1] <- 0
+       end[1]    <- (triggersOnList[1] -1)
+
+       if(length(triggersOnList) == 1)
+               return(as.data.frame(cbind(start, end, startH)))
+
+       for( i in 1:(length(triggersOnList) -1) )
         {
-                start[i]  <- triggersOn[i]
-                startH[i] <- position[triggersOn[i]]
-                end[i]    <- (triggersOn[i+1] -1)
+                start[i+1]  <- triggersOnList[i]
+                startH[i+1] <- position[triggersOnList[i]]
+                end[i+1]    <- (triggersOnList[i+1] -1)
         }
         
         return(as.data.frame(cbind(start, end, startH)))
@@ -2714,9 +2719,10 @@ doProcess <- function(options)
                 }
                 
                 position=cumsum(displacement)
-                
-                if(length(op$TriggersOn) >= 2)
-                        curves <- findCurvesByTriggers(displacement, op$TriggersOn)
+
+               #if(usingTriggers)
+               if(op$TriggersOnList != -1)
+                        curves <- findCurvesByTriggers(displacement, op$TriggersOnList)
                 else
                         curves <- findCurvesNew(displacement, op$Eccon,
                                                 isInertial(op$EncoderConfigurationName), op$MinHeight)
@@ -2740,8 +2746,8 @@ doProcess <- function(options)
                 
                 for(i in 1:n)
                 {
-                        #reduceCurveBySpeed only when ! triggers
-                        if(length(op$TriggersOn) < 2)
+                       #reduceCurveBySpeed only when ! triggers
+                       if(op$TriggersOnList == -1)
                         {
                                 reduceTemp = reduceCurveBySpeed(op$Eccon,
                                                                 curves[i,1], curves[i,3], #startT, startH
diff --git a/encoder/util.R b/encoder/util.R
index d0d7d3c..9a0ed84 100644
--- a/encoder/util.R
+++ b/encoder/util.R
@@ -80,9 +80,10 @@ assignOptions <- function(options) {
                    OperatingSystem     = options[28],  #if this changes, change it also at call_graph.R
                    Debug               = options[31],
                    CrossValidate       = options[32],
-                   TriggersOn          = as.numeric(unlist(strsplit(options[33], "\\;")))
-                   #TriggerOn on capture is +1/-1 to indicate use or not.
-                   #On analyze is first ms where trigger is pressed at each repetition, or -1 if they are 
not going to be used
+                   TriggersOnList      = as.numeric(unlist(strsplit(options[33], "\\;")))
+                   #TriggersOnList:
+                   #   at capture is +1/-1 to indicate use or not.
+                   #   at graph.R is first ms where trigger is pressed at each repetition, or -1 if they are 
not going to be used
 
                    #Unassigned here:
                    #   englishWords [29]
diff --git a/glade/preferences_win.glade b/glade/preferences_win.glade
index dfeafcd..c184a13 100644
--- a/glade/preferences_win.glade
+++ b/glade/preferences_win.glade
@@ -2631,30 +2631,261 @@ It starts before and arrives there with some speed.</property>
                               </packing>
                             </child>
                             <child>
-                              <widget class="GtkButton" id="button_encoder_capture_cut_by_triggers_help">
+                              <placeholder/>
+                            </child>
+                          </widget>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">5</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkFrame" id="frame9">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label_xalign">0</property>
+                            <property name="label_yalign">0.69999998807907104</property>
+                            <property name="shadow_type">out</property>
+                            <child>
+                              <widget class="GtkAlignment" id="alignment18">
                                 <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="receives_default">True</property>
-                                <signal name="clicked" 
handler="on_button_encoder_capture_cut_by_triggers_help_clicked" swapped="no"/>
+                                <property name="can_focus">False</property>
+                                <property name="left_padding">12</property>
                                 <child>
-                                  <widget class="GtkImage" id="image_encoder_capture_cut_by_triggers_help">
+                                  <widget class="GtkVBox" id="vbox35">
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
-                                    <property name="stock">gtk-missing-image</property>
+                                    <property name="border_width">8</property>
+                                    <property name="spacing">12</property>
+                                    <child>
+                                      <widget class="GtkHBox" id="hbox39">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="spacing">20</property>
+                                        <child>
+                                          <widget class="GtkImage" id="image_encoder_triggers">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="stock">gtk-missing-image</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">False</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkVBox" id="vbox36">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="spacing">8</property>
+                                            <child>
+                                              <widget class="GtkHBox" id="hbox42">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="spacing">8</property>
+                                                <child>
+                                                  <widget class="GtkRadioButton" 
id="radio_encoder_triggers_no">
+                                                    <property name="label" translatable="yes">Do not use 
triggers</property>
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">True</property>
+                                                    <property name="receives_default">False</property>
+                                                    <property name="active">True</property>
+                                                    <property name="draw_indicator">True</property>
+                                                    <signal name="toggled" 
handler="on_radio_encoder_triggers_toggled" swapped="no"/>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <widget class="GtkHBox" id="hbox43">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <child>
+                                                      <widget class="GtkLabel" id="label115">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="label">(</property>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="fill">False</property>
+                                                        <property name="position">0</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <widget class="GtkLabel" id="label116">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="label" 
translatable="yes">Recommended</property>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="fill">False</property>
+                                                        <property name="position">1</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <widget class="GtkLabel" id="label117">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="label">)</property>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="fill">False</property>
+                                                        <property name="position">2</property>
+                                                      </packing>
+                                                    </child>
+                                                  </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="hbox44">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="spacing">8</property>
+                                                <child>
+                                                  <widget class="GtkRadioButton" 
id="radio_encoder_triggers_yes">
+                                                    <property name="label" translatable="yes">Cut sets into 
repetitions using triggers</property>
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">True</property>
+                                                    <property name="receives_default">False</property>
+                                                    <property name="active">True</property>
+                                                    <property name="draw_indicator">True</property>
+                                                    <property 
name="group">radio_encoder_triggers_no</property>
+                                                    <signal name="toggled" 
handler="on_radio_encoder_triggers_toggled" swapped="no"/>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <widget class="GtkButton" 
id="button_encoder_capture_cut_by_triggers_help">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">True</property>
+                                                    <property name="receives_default">True</property>
+                                                    <signal name="clicked" 
handler="on_button_encoder_capture_cut_by_triggers_help_clicked" swapped="no"/>
+                                                    <child>
+                                                      <widget class="GtkImage" 
id="image_encoder_capture_cut_by_triggers_help">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="stock">gtk-missing-image</property>
+                                                      </widget>
+                                                    </child>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</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>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">True</property>
+                                            <property name="fill">True</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="GtkAlignment" id="alignment_encoder_triggers_yes">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="left_padding">90</property>
+                                        <child>
+                                          <widget class="GtkVBox" id="vbox_encoder_triggers_yes">
+                                            <property name="can_focus">False</property>
+                                            <property name="spacing">8</property>
+                                            <child>
+                                              <widget class="GtkRadioButton" 
id="radio_encoder_triggers_yes_start_at_capture">
+                                                <property name="label" translatable="yes">First repetition 
starts when "capture" button is pressed</property>
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">True</property>
+                                                <property name="receives_default">False</property>
+                                                <property name="active">True</property>
+                                                <property name="draw_indicator">True</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">True</property>
+                                                <property name="fill">True</property>
+                                                <property name="position">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkRadioButton" 
id="radio_encoder_triggers_yes_start_at_first_trigger">
+                                                <property name="label" translatable="yes">First repetition 
starts when trigger button is pressed</property>
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">True</property>
+                                                <property name="receives_default">False</property>
+                                                <property name="draw_indicator">True</property>
+                                                <property 
name="group">radio_encoder_triggers_yes_start_at_capture</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">True</property>
+                                                <property name="fill">True</property>
+                                                <property name="position">1</property>
+                                              </packing>
+                                            </child>
+                                          </widget>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
                                   </widget>
                                 </child>
                               </widget>
+                            </child>
+                            <child>
+                              <widget class="GtkLabel" id="label114">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="label" translatable="yes">Cut sets into repetitions using 
triggers</property>
+                                <property name="use_markup">True</property>
+                              </widget>
                               <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">False</property>
-                                <property name="position">1</property>
+                                <property name="type">label_item</property>
                               </packing>
                             </child>
                           </widget>
                           <packing>
                             <property name="expand">True</property>
                             <property name="fill">True</property>
-                            <property name="position">5</property>
+                            <property name="position">6</property>
                           </packing>
                         </child>
                       </widget>
diff --git a/images/md/trigger_2x.xcf b/images/md/trigger_2x.xcf
index a691843..4a2f1a4 100644
Binary files a/images/md/trigger_2x.xcf and b/images/md/trigger_2x.xcf differ
diff --git a/images/md/trigger_no_2x.png b/images/md/trigger_no_2x.png
new file mode 100644
index 0000000..2bbcd74
Binary files /dev/null and b/images/md/trigger_no_2x.png differ
diff --git a/src/Makefile.am b/src/Makefile.am
index fc490c4..3bfad3d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -433,6 +433,7 @@ RESOURCES = \
        ../images/md/ic_folder_check_blue_24dp_1x.png,folder_check.png \
        ../images/md/ic_zoom_blue_24dp_1x.png,zoom.png \
        ../images/md/trigger_2x.png,image_encoder_triggers.png \
+       ../images/md/trigger_no_2x.png,image_encoder_triggers_no.png \
        ../images/chronojump_icon.png,chronojump_icon.png \
        ../images/chronojump_icon_graph.png,chronojump_icon_graph.png \
        ../images/stock_right.png,stock_right.png \
diff --git a/src/encoderCapture.cs b/src/encoderCapture.cs
index a09fe7a..99a6adc 100644
--- a/src/encoderCapture.cs
+++ b/src/encoderCapture.cs
@@ -211,7 +211,8 @@ public abstract class EncoderCapture
                inertialCalibrated = false;
        }
 
-       public bool Capture(string outputData1, EncoderRProcCapture encoderRProcCapture, bool compujump, bool 
cutByTriggers)
+       public bool Capture(string outputData1, EncoderRProcCapture encoderRProcCapture,
+                       bool compujump, Preferences.TriggerTypes cutByTriggers)
        {
                /*
                 * removed at 1.7.0
@@ -225,6 +226,9 @@ public abstract class EncoderCapture
                lastTriggerOn = 0;
                inertialCalibratedFirstCross0Pos = 0;
 
+               //only for cutByTriggers == Preferences.TriggerTypes.START_AT_FIRST_ON
+               bool firstTriggerHappened = false;
+
                if(capturingInertialBG)
                {
                        /*
@@ -257,7 +261,19 @@ public abstract class EncoderCapture
                                        continue;
                                }
 
-                               if(cutByTriggers)
+                               //TriggerTypes.START_AT_FIRST_ON starts capture at first trigger. So when 
this happens, reset capture
+                               if(cutByTriggers == Preferences.TriggerTypes.START_AT_FIRST_ON && ! 
firstTriggerHappened)
+                               {
+                                       LogB.Information("Cleaning on capture");
+
+                                       startCaptureFromHere();
+
+                                       firstTriggerHappened = true;
+                                       i = -1; //will be 0 on next loop start
+                                       continue;
+                               }
+
+                               if(cutByTriggers != Preferences.TriggerTypes.NO_TRIGGERS)
                                {
                                        ecc = new EncoderCaptureCurve(lastTriggerOn, i);
                                        lastTriggerOn = i;
@@ -316,23 +332,7 @@ public abstract class EncoderCapture
                                                //remove this time on existing trigger records
                                                triggerList.Substract(consecutiveZeros);
 
-                                               consecutiveZeros = -1;
-                                               encoderReadedInertialDisc = new List<int>();
-                                               encoderReaded = new List<int>();
-
-                                               if(capturingInertialBG)
-                                               {
-                                                       //empty 
EncoderCaptureInertialBackgroundStatic.ListCaptured
-                                                       EncoderCaptureInertialBackgroundStatic.Initialize();
-                                               }
-
-                                               if(! showOnlyBars)
-                                               {
-                                                       EncoderCapturePoints = new List<Gdk.Point>();
-                                                       EncoderCapturePointsInertialDisc = new 
List<Gdk.Point>();
-                                                       EncoderCapturePointsCaptured = 0;
-                                                       EncoderCapturePointsPainted = -1;       //-1 means 
delete screen
-                                               }
+                                               startCaptureFromHere();
 
                                                i = -1; //will be 0 on next loop start
                                                continue;
@@ -429,7 +429,7 @@ public abstract class EncoderCapture
                                        sendCurveMaybe = false;
 
                                //if cutByTriggers, triggers send the curve at the beginning of this method
-                               if(cutByTriggers)
+                               if(cutByTriggers != Preferences.TriggerTypes.NO_TRIGGERS)
                                        sendCurveMaybe = false;
 
                                if(sendCurveMaybe)
@@ -597,6 +597,27 @@ public abstract class EncoderCapture
        }
        */
 
+       private void startCaptureFromHere()
+       {
+               consecutiveZeros = -1;
+               encoderReadedInertialDisc = new List<int>();
+               encoderReaded = new List<int>();
+
+               if(capturingInertialBG)
+               {
+                       //empty EncoderCaptureInertialBackgroundStatic.ListCaptured
+                       EncoderCaptureInertialBackgroundStatic.Initialize();
+               }
+
+               if(! showOnlyBars)
+               {
+                       EncoderCapturePoints = new List<Gdk.Point>();
+                       EncoderCapturePointsInertialDisc = new List<Gdk.Point>();
+                       EncoderCapturePointsCaptured = 0;
+                       EncoderCapturePointsPainted = -1;       //-1 means delete screen
+               }
+       }
+
        private bool simulatedGoingUp = false;
        private int simulatedMaxValue = 400;
        private int simulatedLength;
@@ -798,13 +819,13 @@ public abstract class EncoderCapture
        }
 
        /*
-        * graph.R will findCurvesByTriggers if (length(op$TriggersOn) >= 2)
+        * graph.R will findCurvesByTriggers if (length(op$TriggersOn) >= 1)
         * else will findCurvesNew (like if not capturing by triggers)
         * We need to know what graph.R will do to show a message to user
         */
-       public bool MinimumTwoTriggersOn()
+       public bool MinimumOneTriggersOn()
        {
-               return triggerList.MinimumTwoOn();
+               return triggerList.MinimumOneOn();
        }
 
        public string Eccon {
diff --git a/src/encoderRProc.cs b/src/encoderRProc.cs
index 08f7061..9ffd46a 100644
--- a/src/encoderRProc.cs
+++ b/src/encoderRProc.cs
@@ -143,7 +143,7 @@ public abstract class EncoderRProc
 
 public class EncoderRProcCapture : EncoderRProc 
 {
-       public bool CutByTriggers;
+       public Preferences.TriggerTypes CutByTriggers;
 
        public EncoderRProcCapture()
        {
@@ -270,7 +270,7 @@ public class EncoderRProcCapture : EncoderRProc
        {
                //just use triggeres tp cut sets into repetitions, or not.
                //Cut is done in C# but this will change minHeight behaviour and reduceCurveBySpeed
-               if(CutByTriggers)
+               if(CutByTriggers != Preferences.TriggerTypes.NO_TRIGGERS)
                        return "1";
                else
                        return TriggerList.TriggersNotFoundString;
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 33cfbf6..6bed0c0 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -2546,7 +2546,7 @@ public partial class ChronoJumpWindow
                                UtilEncoder.GetEncoderDataTempFileName(),
                                encoderRProcCapture,
                                false,  //compujump
-                               false   //cutByTriggers
+                               Preferences.TriggerTypes.NO_TRIGGERS
                                );
 
                //wait to ensure capture thread has ended
@@ -5243,15 +5243,16 @@ public partial class ChronoJumpWindow
                                                eCaptureInertialBG.SimulatedReset();
                                }
 
-                               bool cutByTriggers = false;
                                //triggers only work on gravitatory, concentric
-                               if(preferences.encoderCaptureCutByTriggers &&
+                               Preferences.TriggerTypes reallyCutByTriggers = 
Preferences.TriggerTypes.NO_TRIGGERS;
+
+                               if(preferences.encoderCaptureCutByTriggers != 
Preferences.TriggerTypes.NO_TRIGGERS &&
                                                currentEncoderGI == Constants.EncoderGI.GRAVITATORY && 
eCapture.Eccon == "c")
                                {
-                                       cutByTriggers = true;
+                                       reallyCutByTriggers = preferences.encoderCaptureCutByTriggers;
                                        notebook_encoder_signal_comment_and_triggers.Page = 1;
                                }
-                               encoderRProcCapture.CutByTriggers = cutByTriggers;
+                               encoderRProcCapture.CutByTriggers = reallyCutByTriggers;
 
                                encoderThread = new Thread(new ThreadStart(encoderDoCaptureCsharp));
                                GLib.Idle.Add (new GLib.IdleHandler (pulseGTKEncoderCaptureAndCurves));
@@ -5272,7 +5273,7 @@ public partial class ChronoJumpWindow
                                                false
                                                );
 
-                               encoderRProcCapture.CutByTriggers = false; //do not cutByTriggers on 
inertial, yet.
+                               encoderRProcCapture.CutByTriggers = Preferences.TriggerTypes.NO_TRIGGERS; 
//do not cutByTriggers on inertial, yet.
 
                                encoderThread = new Thread(new ThreadStart(encoderDoCaptureCsharpIM));
                                GLib.Idle.Add (new GLib.IdleHandler (pulseGTKEncoderCaptureIM));
@@ -6216,11 +6217,12 @@ public partial class ChronoJumpWindow
                                                
eCapture.SaveTriggers(Convert.ToInt32(encoderSignalUniqueID)); //dbcon is closed
                                                showTriggersAndTab();
 
-                                               if(encoderRProcCapture.CutByTriggers && ! 
eCapture.MinimumTwoTriggersOn())
+                                               if(encoderRProcCapture.CutByTriggers != 
Preferences.TriggerTypes.NO_TRIGGERS &&
+                                                               ! eCapture.MinimumOneTriggersOn())
                                                        new DialogMessage(
                                                                        "Chronojump",
                                                                        Constants.MessageTypes.WARNING,
-                                                                       "Trigger has not been pressed a 
minimum of two times." + "\n\n" +
+                                                                       "Not found enought triggers to cut 
repetitions." + "\n\n" +
                                                                        "Repetitions have been cut 
automatically.");
 
                                                //2) send the json to server
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index 4c975f4..64be622 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -108,6 +108,7 @@ public class PreferencesWindow
        [Widget] Gtk.ComboBox combo_main_variable;
        [Widget] Gtk.Image image_encoder_gravitatory;
        [Widget] Gtk.Image image_encoder_inertial;
+       [Widget] Gtk.Image image_encoder_triggers;
        [Widget] Gtk.Notebook notebook_encoder_capture_gi;
        [Widget] Gtk.VBox vbox_encoder_inertial; //change Visible param to not have a vertical big first page 
with only one row of info
        [Widget] Gtk.SpinButton spin_encoder_capture_min_height_gravitatory;
@@ -121,7 +122,11 @@ public class PreferencesWindow
        [Widget] Gtk.RadioButton radio_encoder_auto_save_curve_none;
        [Widget] Gtk.SpinButton spin_encoder_capture_barplot_font_size;
        [Widget] Gtk.CheckButton check_show_start_and_duration;
-       [Widget] Gtk.CheckButton check_encoder_capture_cut_by_triggers;
+       [Widget] Gtk.RadioButton radio_encoder_triggers_no;
+       [Widget] Gtk.RadioButton radio_encoder_triggers_yes;
+       [Widget] Gtk.VBox vbox_encoder_triggers_yes;
+       [Widget] Gtk.RadioButton radio_encoder_triggers_yes_start_at_capture;
+       [Widget] Gtk.RadioButton radio_encoder_triggers_yes_start_at_first_trigger;
        [Widget] Gtk.Image image_encoder_inactivity_help;
        [Widget] Gtk.Image image_encoder_capture_cut_by_triggers_help;
        
@@ -462,6 +467,8 @@ public class PreferencesWindow
                PreferencesWindowBox.image_encoder_gravitatory.Pixbuf = pixbuf;
                pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "image_inertia.png");
                PreferencesWindowBox.image_encoder_inertial.Pixbuf = pixbuf;
+               pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "image_encoder_triggers_no.png");
+               PreferencesWindowBox.image_encoder_triggers.Pixbuf = pixbuf;
 
                if(menu_mode == Constants.Menuitem_modes.POWERGRAVITATORY)
                {
@@ -491,7 +498,16 @@ public class PreferencesWindow
 
                PreferencesWindowBox.spin_encoder_capture_barplot_font_size.Value = 
preferences.encoderCaptureBarplotFontSize;
                PreferencesWindowBox.check_show_start_and_duration.Active = 
preferences.encoderShowStartAndDuration;
-               PreferencesWindowBox.check_encoder_capture_cut_by_triggers.Active = 
preferences.encoderCaptureCutByTriggers;
+
+               if(preferences.encoderCaptureCutByTriggers == Preferences.TriggerTypes.NO_TRIGGERS)
+                       PreferencesWindowBox.radio_encoder_triggers_no.Active = true;
+               else {
+                       PreferencesWindowBox.radio_encoder_triggers_yes.Active = true;
+                       if(preferences.encoderCaptureCutByTriggers == 
Preferences.TriggerTypes.START_AT_CAPTURE)
+                               PreferencesWindowBox.radio_encoder_triggers_yes_start_at_capture.Active = 
true;
+                       else
+                               PreferencesWindowBox.radio_encoder_triggers_yes_start_at_first_trigger.Active 
= true;
+               }
 
 
                //encoder other -->
@@ -544,18 +560,45 @@ public class PreferencesWindow
                vbox_encoder_inertial.Visible = (PreferencesWindowBox.notebook_encoder_capture_gi.CurrentPage 
== 1);
        }
 
+       /*
+        * triggers stuff
+        */
+
+       private void on_radio_encoder_triggers_toggled (object obj, EventArgs args)
+       {
+               Pixbuf pixbuf;
+               if(radio_encoder_triggers_no.Active)
+               {
+                       vbox_encoder_triggers_yes.Visible = false;
+                       pixbuf = new Pixbuf (null, Util.GetImagePath(false) + 
"image_encoder_triggers_no.png");
+               PreferencesWindowBox.image_encoder_triggers.Pixbuf = pixbuf;
+               } else {
+                       vbox_encoder_triggers_yes.Visible = true;
+                       pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "image_encoder_triggers.png");
+               }
+
+               image_encoder_triggers.Pixbuf = pixbuf;
+       }
+
        private void on_button_encoder_capture_cut_by_triggers_help_clicked (object o, EventArgs args)
        {
-               new DialogMessage(Constants.MessageTypes.WARNING,
+               new DialogMessage(
+                               "Chronojump triggers",
+                               Constants.MessageTypes.INFO,
                                "If active, repetitions will be cut from set using triggers." + "\n" +
                                "Triggers will be produced by a button connected to the Chronopic." + "\n\n" +
-                               "This will be only used on gravitatory mode, concentric contraction.");
+                               "This will be only used on gravitatory mode, concentric contraction." + 
"\n\n" +
+                               "If inactive, repetitions will be cut automatically (default behaviour).");
                /*
                 * not on ecc-con because we cannot guaranteee that there will be an ecc and con phase,
                 * and then R findECPhases() will fail
                 */
        }
-       
+
+       /*
+        * end of triggers stuff
+        */
+
        private void createComboEncoderCaptureMainVariable(string v) {
                combo_main_variable = ComboBox.NewText ();
                string [] values = Constants.EncoderVariablesCaptureList;
@@ -1655,11 +1698,27 @@ public class PreferencesWindow
                                "encoderShowStartAndDuration",
                                preferences.encoderShowStartAndDuration,
                                PreferencesWindowBox.check_show_start_and_duration.Active);
-               
-               preferences.encoderCaptureCutByTriggers = preferencesChange(
-                               "encoderCaptureCutByTriggers",
-                               preferences.encoderCaptureCutByTriggers,
-                               PreferencesWindowBox.check_encoder_capture_cut_by_triggers.Active);
+
+               if(PreferencesWindowBox.radio_encoder_triggers_no.Active &&
+                               preferences.encoderCaptureCutByTriggers != 
Preferences.TriggerTypes.NO_TRIGGERS)
+               {
+                       SqlitePreferences.Update("encoderCaptureCutByTriggers", 
Preferences.TriggerTypes.NO_TRIGGERS.ToString(), true);
+                       preferences.encoderCaptureCutByTriggers = Preferences.TriggerTypes.NO_TRIGGERS;
+               }
+               else if(PreferencesWindowBox.radio_encoder_triggers_yes.Active &&
+                               PreferencesWindowBox.radio_encoder_triggers_yes_start_at_capture.Active &&
+                               preferences.encoderCaptureCutByTriggers != 
Preferences.TriggerTypes.START_AT_CAPTURE)
+               {
+                       SqlitePreferences.Update("encoderCaptureCutByTriggers", 
Preferences.TriggerTypes.START_AT_CAPTURE.ToString(), true);
+                       preferences.encoderCaptureCutByTriggers = Preferences.TriggerTypes.START_AT_CAPTURE;
+               }
+               else if(PreferencesWindowBox.radio_encoder_triggers_yes.Active &&
+                               PreferencesWindowBox.radio_encoder_triggers_yes_start_at_first_trigger.Active 
&&
+                               preferences.encoderCaptureCutByTriggers != 
Preferences.TriggerTypes.START_AT_FIRST_ON)
+               {
+                       SqlitePreferences.Update("encoderCaptureCutByTriggers", 
Preferences.TriggerTypes.START_AT_FIRST_ON.ToString(), true);
+                       preferences.encoderCaptureCutByTriggers = Preferences.TriggerTypes.START_AT_FIRST_ON;
+               }
 
                //---- end of encoder capture
                
diff --git a/src/preferences.cs b/src/preferences.cs
index bc059f9..58b6eac 100644
--- a/src/preferences.cs
+++ b/src/preferences.cs
@@ -64,7 +64,8 @@ public class Preferences
        public Constants.EncoderAutoSaveCurve encoderAutoSaveCurve;
        public int encoderCaptureBarplotFontSize;
        public bool encoderShowStartAndDuration;
-       public bool encoderCaptureCutByTriggers;
+       public enum TriggerTypes { NO_TRIGGERS, START_AT_CAPTURE, START_AT_FIRST_ON};
+       public TriggerTypes encoderCaptureCutByTriggers;
        
        //encoder other
        public bool encoderPropulsive;
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index f6a6b89..b0eea00 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -125,7 +125,7 @@ class Sqlite
        /*
         * Important, change this if there's any update to database
         */
-       static string lastChronojumpDatabaseVersion = "1.50";
+       static string lastChronojumpDatabaseVersion = "1.51";
 
        public Sqlite() {
        }
@@ -2270,6 +2270,20 @@ class Sqlite
 
                                currentVersion = updateVersion("1.50");
                        }
+                       if(currentVersion == "1.50")
+                       {
+                               LogB.SQL("Updated encoderCaptureCutByTriggers variable");
+
+                               string cutStr = SqlitePreferences.Select("encoderCaptureCutByTriggers", true);
+                               if(cutStr == "True")
+                                       SqlitePreferences.Update ("encoderCaptureCutByTriggers",
+                                                       Preferences.TriggerTypes.START_AT_CAPTURE.ToString(), 
true);
+                               else
+                                       SqlitePreferences.Update ("encoderCaptureCutByTriggers",
+                                                       Preferences.TriggerTypes.NO_TRIGGERS.ToString(), 
true);
+
+                               currentVersion = updateVersion("1.51");
+                       }
 
 
 
@@ -2452,6 +2466,7 @@ class Sqlite
                SqlitePreferences.initializeTable(lastChronojumpDatabaseVersion, creatingBlankDatabase);
 
                //changes [from - to - desc]
+               //1.50 - 1.51 Converted DB to 1.51 Updated encoderCaptureCutByTriggers variable
                //1.49 - 1.50 Converted DB to 1.50 Updated preferences: added crashLogLanguage
                //1.48 - 1.49 Converted DB to 1.49 Updated preferences: added force sensor tare/calibration 
stuff
                //1.47 - 1.48 Converted DB to 1.48 Updated preferences: added gstreamer
diff --git a/src/sqlite/preferences.cs b/src/sqlite/preferences.cs
index a233bf4..55811b2 100644
--- a/src/sqlite/preferences.cs
+++ b/src/sqlite/preferences.cs
@@ -119,7 +119,7 @@ class SqlitePreferences : Sqlite
                                Insert ("encoderCaptureCheckFullyExtendedValue", "4", dbcmdTr);
                                Insert ("encoderCaptureBarplotFontSize", "14", dbcmdTr);
                                Insert ("encoderShowStartAndDuration", "False", dbcmdTr);
-                               Insert ("encoderCaptureCutByTriggers", "False", dbcmdTr);
+                               Insert ("encoderCaptureCutByTriggers", 
Preferences.TriggerTypes.NO_TRIGGERS.ToString(), dbcmdTr);
                                Insert ("encoderPropulsive", "True", dbcmdTr);
                                Insert ("encoderSmoothEccCon", "0.6", dbcmdTr);
                                Insert ("encoderSmoothCon", "0.7", dbcmdTr);
@@ -299,7 +299,8 @@ class SqlitePreferences : Sqlite
                        else if(reader[0].ToString() == "encoderShowStartAndDuration")
                                preferences.encoderShowStartAndDuration = reader[1].ToString() == "True";
                        else if(reader[0].ToString() == "encoderCaptureCutByTriggers")
-                               preferences.encoderCaptureCutByTriggers = reader[1].ToString() == "True";
+                               preferences.encoderCaptureCutByTriggers = (Preferences.TriggerTypes)
+                                       Enum.Parse(typeof(Preferences.TriggerTypes), reader[1].ToString());
                        //encoder other
                        else if(reader[0].ToString() == "encoderPropulsive")
                                preferences.encoderPropulsive = reader[1].ToString() == "True";
diff --git a/src/trigger.cs b/src/trigger.cs
index e03881b..873f198 100644
--- a/src/trigger.cs
+++ b/src/trigger.cs
@@ -214,10 +214,10 @@ public class TriggerList
                return countOn;
        }
 
-       //see encoderCapture.MinimumTwoTriggersOn()
-       public bool MinimumTwoOn()
+       //see encoderCapture.MinimumOneTriggersOn()
+       public bool MinimumOneOn()
        {
-               if(countOn() >= 2)
+               if(countOn() >= 1)
                        return true;
 
                return false;



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