[chronojump] Encoder: autosave signal capture, delete signal. ...



commit acaf36340d28ba01b1587b09f5349ab305840ae1
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Jun 5 14:11:02 2012 +0200

    Encoder: autosave signal capture, delete signal. ...

 glade/chronojump.glade       |  126 ++++++++++++++++++++++++++---------------
 src/encoder.cs               |    5 ++
 src/gui/chronojump.cs        |   14 ++--
 src/gui/encoder.cs           |  125 +++++++++++++++++++++++++++++++-----------
 src/gui/jump.cs              |    2 +-
 src/gui/pulse.cs             |    2 +-
 src/gui/run.cs               |    2 +-
 src/sqlite/encoder.cs        |   21 ++++---
 src/sqlite/jump.cs           |   10 ---
 src/sqlite/main.cs           |   18 +++++-
 src/sqlite/multiChronopic.cs |    8 ---
 src/sqlite/person.cs         |   10 ---
 src/sqlite/personSession.cs  |    2 +-
 src/sqlite/pulse.cs          |    8 ---
 src/sqlite/reactionTime.cs   |    8 ---
 src/sqlite/run.cs            |    9 ---
 src/util.cs                  |   43 +++++++++-----
 17 files changed, 246 insertions(+), 167 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 283d5d9..0202cd7 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -24683,14 +24683,40 @@ Evaluator can use real name or nickname.</property>
                                         <child>
                                           <widget class="GtkHBox" id="hbox78">
                                             <property name="visible">True</property>
-                                            <property name="spacing">20</property>
+                                            <property name="spacing">10</property>
                                             <child>
-                                              <widget class="GtkButton" id="button_encoder_delete_curve">
-                                                <property name="label">Delete curve</property>
+                                              <widget class="GtkVBox" id="vbox2">
                                                 <property name="visible">True</property>
-                                                <property name="can_focus">True</property>
-                                                <property name="receives_default">True</property>
-                                                <signal name="clicked" handler="on_button_encoder_delete_curve_clicked"/>
+                                                <property name="spacing">6</property>
+                                                <child>
+                                                  <widget class="GtkButton" id="button_encoder_delete_curve">
+                                                    <property name="label">Delete selected curve</property>
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">True</property>
+                                                    <property name="receives_default">True</property>
+                                                    <signal name="clicked" handler="on_button_encoder_delete_curve_clicked"/>
+                                                  </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_delete_signal">
+                                                    <property name="label">Delete signal</property>
+                                                    <property name="visible">True</property>
+                                                    <property name="sensitive">False</property>
+                                                    <property name="can_focus">True</property>
+                                                    <property name="receives_default">True</property>
+                                                    <signal name="clicked" handler="on_button_encoder_delete_signal_clicked"/>
+                                                  </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>
@@ -24699,16 +24725,19 @@ Evaluator can use real name or nickname.</property>
                                               </packing>
                                             </child>
                                             <child>
-                                              <widget class="GtkHBox" id="hbox80">
+                                              <widget class="GtkTable" id="table7">
                                                 <property name="visible">True</property>
-                                                <property name="spacing">8</property>
+                                                <property name="n_rows">2</property>
+                                                <property name="n_columns">2</property>
+                                                <property name="column_spacing">20</property>
+                                                <property name="row_spacing">6</property>
                                                 <child>
                                                   <widget class="GtkLabel" id="label_encoder_capture_comment">
                                                     <property name="visible">True</property>
                                                     <property name="label" translatable="yes">Add comment</property>
                                                   </widget>
                                                   <packing>
-                                                    <property name="position">0</property>
+                                                    <property name="x_options"></property>
                                                   </packing>
                                                 </child>
                                                 <child>
@@ -24718,58 +24747,63 @@ Evaluator can use real name or nickname.</property>
                                                     <property name="invisible_char">â</property>
                                                   </widget>
                                                   <packing>
-                                                    <property name="position">1</property>
+                                                    <property name="top_attach">1</property>
+                                                    <property name="bottom_attach">2</property>
+                                                    <property name="x_options"></property>
                                                   </packing>
                                                 </child>
                                                 <child>
-                                                  <widget class="GtkButton" id="button_encoder_save_curve">
-                                                    <property name="label">Save curve</property>
+                                                  <widget class="GtkButton" id="button_encoder_update_signal">
+                                                    <property name="label">Update signal</property>
                                                     <property name="visible">True</property>
                                                     <property name="can_focus">True</property>
                                                     <property name="receives_default">True</property>
                                                     <signal name="clicked" handler="on_button_encoder_save_clicked"/>
                                                   </widget>
                                                   <packing>
-                                                    <property name="expand">False</property>
-                                                    <property name="fill">False</property>
-                                                    <property name="position">2</property>
+                                                    <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="GtkButton" id="button_encoder_save_all_curves">
-                                                    <property name="label">Save all curves</property>
+                                                  <widget class="GtkHBox" id="hbox80">
                                                     <property name="visible">True</property>
-                                                    <property name="can_focus">True</property>
-                                                    <property name="receives_default">True</property>
-                                                    <signal name="clicked" handler="on_button_encoder_save_clicked"/>
-                                                  </widget>
-                                                  <packing>
-                                                    <property name="expand">False</property>
-                                                    <property name="fill">False</property>
-                                                    <property name="position">3</property>
-                                                  </packing>
-                                                </child>
-                                                <child>
-                                                  <widget class="GtkVSeparator" id="vseparator2">
-                                                    <property name="visible">True</property>
-                                                  </widget>
-                                                  <packing>
-                                                    <property name="expand">False</property>
-                                                    <property name="position">4</property>
-                                                  </packing>
-                                                </child>
-                                                <child>
-                                                  <widget class="GtkButton" id="button_encoder_save_signal">
-                                                    <property name="label">Save signal</property>
-                                                    <property name="visible">True</property>
-                                                    <property name="can_focus">True</property>
-                                                    <property name="receives_default">True</property>
-                                                    <signal name="clicked" handler="on_button_encoder_save_clicked"/>
+                                                    <property name="spacing">8</property>
+                                                    <child>
+                                                      <widget class="GtkButton" id="button_encoder_save_curve">
+                                                        <property name="label">Save curve</property>
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">True</property>
+                                                        <property name="receives_default">True</property>
+                                                        <signal name="clicked" handler="on_button_encoder_save_clicked"/>
+                                                      </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_save_all_curves">
+                                                        <property name="label">Save all curves</property>
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">True</property>
+                                                        <property name="receives_default">True</property>
+                                                        <signal name="clicked" handler="on_button_encoder_save_clicked"/>
+                                                      </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">5</property>
+                                                    <property name="left_attach">1</property>
+                                                    <property name="right_attach">2</property>
+                                                    <property name="x_options"></property>
                                                   </packing>
                                                 </child>
                                               </widget>
diff --git a/src/encoder.cs b/src/encoder.cs
index 06985ab..ece053d 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -21,6 +21,7 @@
 using System;
 using System.Data;
 using System.Text; //StringBuilder
+using System.IO;   //for Path
 
 using Mono.Unix;
 
@@ -244,6 +245,10 @@ public class EncoderSQL
 		return date;
 	}
 
+	public string GetFullURL() {
+		return url + Path.DirectorySeparatorChar + filename;
+	}
+
 	public string [] ToStringArray (int count) {
 		string [] str = new String [7];
 		str[0] = uniqueID;
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index a4cb446..057ee38 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -4514,7 +4514,7 @@ Console.WriteLine("X");
 		Log.WriteLine("accept delete this jump");
 		int id = myTreeViewJumps.EventSelectedID;
 		
-		SqliteJump.Delete( "jump", id.ToString() );
+		Sqlite.Delete(Constants.JumpTable, id);
 		
 		myTreeViewJumps.DelEvent(id);
 		showHideActionEventButtons(false, "Jump");
@@ -4540,7 +4540,7 @@ Console.WriteLine("X");
 		Log.WriteLine("accept delete this jump");
 		int id = myTreeViewJumpsRj.EventSelectedID;
 		
-		SqliteJump.Delete("jumpRj", id.ToString());
+		Sqlite.Delete(Constants.JumpRjTable, id);
 		
 		myTreeViewJumpsRj.DelEvent(id);
 		showHideActionEventButtons(false, "JumpRj");
@@ -4597,7 +4597,7 @@ Console.WriteLine("X");
 		Log.WriteLine("accept delete this run");
 		int id = myTreeViewRuns.EventSelectedID;
 		
-		SqliteRun.Delete( "run", id.ToString() );
+		Sqlite.Delete(Constants.RunTable, id);
 		
 		myTreeViewRuns.DelEvent(id);
 		showHideActionEventButtons(false, "Run");
@@ -4619,7 +4619,7 @@ Console.WriteLine("X");
 		Log.WriteLine("accept delete this run");
 		int id = myTreeViewRunsInterval.EventSelectedID;
 		
-		SqliteRun.Delete( Constants.RunIntervalTable, id.ToString() );
+		Sqlite.Delete(Constants.RunIntervalTable, id);
 		
 		myTreeViewRunsInterval.DelEvent(id);
 		showHideActionEventButtons(false, "RunInterval");
@@ -4659,7 +4659,7 @@ Console.WriteLine("X");
 		Log.WriteLine("accept delete this reaction time");
 		int id = myTreeViewReactionTimes.EventSelectedID;
 		
-		SqliteJump.Delete( "reactiontime", id.ToString() );
+		Sqlite.Delete(Constants.ReactionTimeTable, id);
 		
 		myTreeViewReactionTimes.DelEvent(id);
 		showHideActionEventButtons(false, "ReactionTime");
@@ -4696,7 +4696,7 @@ Console.WriteLine("X");
 		Log.WriteLine("accept delete this pulse");
 		int id = myTreeViewPulses.EventSelectedID;
 		
-		SqliteJump.Delete( "pulse", id.ToString() );
+		Sqlite.Delete(Constants.PulseTable, id);
 		
 		myTreeViewPulses.DelEvent(id);
 		showHideActionEventButtons(false, "Pulse");
@@ -4731,7 +4731,7 @@ Console.WriteLine("X");
 		Log.WriteLine("accept delete this multi chronopic");
 		int id = myTreeViewMultiChronopic.EventSelectedID;
 		
-		SqliteMultiChronopic.Delete( id.ToString() );
+		Sqlite.Delete(Constants.MultiChronopicTable, id);
 		
 		myTreeViewMultiChronopic.DelEvent(id);
 		showHideActionEventButtons(false, Constants.MultiChronopicName);
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 4e16cef..c022a72 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -49,7 +49,8 @@ public partial class ChronoJumpWindow
 	[Widget] Gtk.Button button_encoder_delete_curve;
 	[Widget] Gtk.Button button_encoder_save_curve;
 	[Widget] Gtk.Button button_encoder_save_all_curves;
-	[Widget] Gtk.Button button_encoder_save_signal;
+	[Widget] Gtk.Button button_encoder_update_signal;
+	[Widget] Gtk.Button button_encoder_delete_signal;
 	
 	[Widget] Gtk.Box hbox_combo_encoder_exercise;
 	[Widget] Gtk.ComboBox combo_encoder_exercise;
@@ -100,7 +101,9 @@ public partial class ChronoJumpWindow
 	private string ecconLast;
 	private string encoderTimeStamp;
 	private string encoderSignalUniqueID;
-	enum encoderModes { CAPTURE, ANALYZE }
+	
+	//difference between CAPTURE and RECALCULATE_OR_LOAD is: CAPTURE does a autosave at end
+	enum encoderModes { CAPTURE, RECALCULATE_OR_LOAD, ANALYZE } 
 	enum encoderSensEnum { 
 		NOSESSION, NOPERSON, YESPERSON, PROCESSING, DONENOSIGNAL, DONEYESSIGNAL, SELECTEDCURVE }
 	private static bool encoderProcessCancel;
@@ -125,18 +128,19 @@ public partial class ChronoJumpWindow
 	//
 	//TODO: Alert if signal captured is not saved. alert when:
 	//	- Change person, load another session, doing another capture, load another signal, closing the software.
-	//	- Or autosave every signal after capturing, and put a delete signal button, 
-	//	and convert the save signal to update signal
 	//
 	//TODO: if a signal is loaded, exercise has to be updated on combo. (use exerciseID in database)
 	//
 	//TODO: do the graphical capturing with pygame
 	//
 	//TODO: allow gui/generic.cs to select rows on treeview. return an array of selected uniqueIDs or curveID
+	//TODO: allow gui/generic.cs to select rows on treeview to be deleted
 	//
 	//TODO: calling to R should give feedback during the process
 	//
 	//TODO: fix problem that on saving maybe dirs are not created
+	//
+	//TODO: on session load, show encoder stuff
 
 	
 	private void encoderInitializeStuff() {
@@ -229,7 +233,7 @@ public partial class ChronoJumpWindow
 	void on_button_encoder_recalculate_clicked (object o, EventArgs args) 
 	{
 		if (File.Exists(Util.GetEncoderDataTempFileName()))
-			encoderThreadStart(encoderModes.CAPTURE);
+			encoderThreadStart(encoderModes.RECALCULATE_OR_LOAD);
 		else
 			encoder_pulsebar_capture.Text = Catalog.GetString("Missing data.");
 	}
@@ -258,6 +262,9 @@ public partial class ChronoJumpWindow
 		Gtk.TreeViewColumn [] myColumns = treeview_encoder_curves.Columns;
 		foreach (Gtk.TreeViewColumn column in myColumns) 
 			treeview_encoder_curves.RemoveColumn (column);
+
+		//blank the encoderListStore
+		encoderListStore = new Gtk.ListStore (typeof (EncoderCurve));
 	}
 
 
@@ -380,6 +387,28 @@ public partial class ChronoJumpWindow
 		//force a recalculate
 		on_button_encoder_recalculate_clicked (o, args); 
 	}
+	
+	void on_button_encoder_delete_signal_clicked (object o, EventArgs args) 
+	{
+		ConfirmWindow confirmWin = ConfirmWindow.Show(Catalog.GetString(
+					"Are you sure you want to delete this signal?"), "", "");
+		confirmWin.Button_accept.Clicked += new EventHandler(on_button_encoder_delete_signal_accepted);
+	}	
+
+	void on_button_encoder_delete_signal_accepted (object o, EventArgs args) 
+	{
+		EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(
+				false, Convert.ToInt32(encoderSignalUniqueID), 0, 0, "")[0];
+		//remove the file
+		bool deletedOk = Util.FileDelete(eSQL.GetFullURL());
+		if(deletedOk) {
+			Sqlite.Delete(Constants.EncoderTable, Convert.ToInt32(encoderSignalUniqueID));
+			encoderSignalUniqueID = "-1";
+			treeviewEncoderRemoveColumns();
+			encoderButtonsSensitive(encoderSensEnum.DONENOSIGNAL);
+			encoder_pulsebar_capture.Text = Catalog.GetString("Signal deleted");
+		}
+	}
 
 	void on_button_encoder_delete_curve_clicked (object o, EventArgs args) 
 	{
@@ -404,7 +433,7 @@ public partial class ChronoJumpWindow
 
 		if(curve.Start != null) {
 			//Log.WriteLine(curveStart + "->" + duration);
-			Util.EncoderDeleteCurve(Util.GetEncoderDataTempFileName(), curveStart, duration);
+			Util.EncoderDeleteCurveFromSignal(Util.GetEncoderDataTempFileName(), curveStart, duration);
 		}
 		//force a recalculate
 		on_button_encoder_recalculate_clicked (o, args); 
@@ -413,18 +442,22 @@ public partial class ChronoJumpWindow
 	void on_button_encoder_save_clicked (object o, EventArgs args) 
 	{
 		Gtk.Button button = (Gtk.Button) o;
-		if(button == button_encoder_save_curve) {
-			int selectedID = treeviewEncoderCurvesEventSelectedID();
-			encoder_pulsebar_capture.Text = encoderSaveSignalOrCurve("curve", selectedID);
-		} else if(button == button_encoder_save_all_curves) 
-			for(int i=1; i <= UtilGtk.CountRows(encoderListStore); i++)
-				encoder_pulsebar_capture.Text = encoderSaveSignalOrCurve("allCurves", i);
-		else 	//(button == button_encoder_save_signal) 
+
+		if(button == button_encoder_update_signal) 
 			encoder_pulsebar_capture.Text = encoderSaveSignalOrCurve("signal", 0);
+		else {
+			if(button == button_encoder_save_curve) {
+				int selectedID = treeviewEncoderCurvesEventSelectedID();
+				encoder_pulsebar_capture.Text = encoderSaveSignalOrCurve("curve", selectedID);
+			} else if(button == button_encoder_save_all_curves) 
+				for(int i=1; i <= UtilGtk.CountRows(encoderListStore); i++)
+					encoder_pulsebar_capture.Text = encoderSaveSignalOrCurve("allCurves", i);
 
-		ArrayList data = SqliteEncoder.Select(false, -1, currentPerson.UniqueID, currentSession.UniqueID, "curve");
-		label_encoder_user_curves_num.Text = data.Count.ToString();
-		spin_encoder_analyze_curve_num.SetRange(1, data.Count);
+			ArrayList data = SqliteEncoder.Select(false, -1, 
+					currentPerson.UniqueID, currentSession.UniqueID, "curve");
+			label_encoder_user_curves_num.Text = data.Count.ToString();
+			spin_encoder_analyze_curve_num.SetRange(1, data.Count);
+		}
 	}
 
 	string encoderSaveSignalOrCurve (string mode, int selectedID) 
@@ -602,7 +635,7 @@ public partial class ChronoJumpWindow
 
 				writer.WriteLine(ex.name + "," + Util.ConvertToPoint(mass).ToString() + "," + 
 						Util.ConvertToPoint(eSQL.smooth) + "," + eSQL.GetDate(true) + "," + 
-						eSQL.url + Path.DirectorySeparatorChar + eSQL.filename + "," +
+						eSQL.GetFullURL() + "," +
 						eSQL.eccon	//this is the eccon of every curve
 						);
 			}
@@ -1322,8 +1355,8 @@ public partial class ChronoJumpWindow
 		//c0 button_encoder_capture
 		//c1 button_encoder_recalculate
 		//c2 button_encoder_load_signal
-		//c3 button_encoder_save_all_curves , button_encoder_save_signal && 
-		//	label_encoder_capture_comment , entry_encoder_capture_comment
+		//c3 button_encoder_save_all_curves , button_encoder_update_signal, button_encoder_delete_signal,
+		//	label_encoder_capture_comment , entry_encoder_capture_comment,
 		//	and images: image_encoder_capture , image_encoder_analyze.Sensitive
 		//c4 button_encoder_delete_curve , button_encoder_save_curve
 		//c5 button_encoder_analyze
@@ -1332,7 +1365,8 @@ public partial class ChronoJumpWindow
 
 		//other dependencies
 		//c5 True needs 
-		//	(signal || (! radiobutton_encoder_analyze_data_current_signal.Active && user has curves))
+		//	(signal && treeviewEncoder has rows) || 
+		//	(! radiobutton_encoder_analyze_data_current_signal.Active && user has curves))
 		//c6 True needs ! radiobutton_encoder_analyze_data_current_signal.Active
 		
 		//columns		 0  1  2  3  4  5  6  7
@@ -1340,7 +1374,7 @@ public partial class ChronoJumpWindow
 		int [] noPerson = 	{0, 0, 0, 0, 0, 0, 0, 0};
 		int [] yesPerson = 	{1, 0, 1, 0, 0, 1, 1, 0};
 		int [] processing = 	{0, 0, 0, 0, 0, 0, 0, 1};
-		int [] doneNoSignal = 	{1, 1, 1, 0, 0, 1, 1, 0};
+		int [] doneNoSignal = 	{1, 0, 1, 0, 0, 1, 1, 0};
 		int [] doneYesSignal = 	{1, 1, 1, 1, 0, 1, 1, 0};
 		int [] selectedCurve = 	{1, 1, 1, 1, 1, 1, 1, 0};
 		int [] table = new int[7];
@@ -1374,7 +1408,8 @@ public partial class ChronoJumpWindow
 		button_encoder_load_signal.Sensitive = Util.IntToBool(table[2]);
 		
 		button_encoder_save_all_curves.Sensitive = Util.IntToBool(table[3]);
-		button_encoder_save_signal.Sensitive = Util.IntToBool(table[3]);
+		button_encoder_update_signal.Sensitive = Util.IntToBool(table[3]);
+		button_encoder_delete_signal.Sensitive = Util.IntToBool(table[3]);
 		label_encoder_capture_comment.Sensitive = Util.IntToBool(table[3]);
 		entry_encoder_capture_comment.Sensitive = Util.IntToBool(table[3]);
 		image_encoder_capture.Sensitive = Util.IntToBool(table[3]);
@@ -1402,7 +1437,7 @@ public partial class ChronoJumpWindow
 	/* thread stuff */
 
 	private void encoderThreadStart(encoderModes mode) {
-		if(mode == encoderModes.CAPTURE) {
+		if(mode == encoderModes.CAPTURE || mode == encoderModes.RECALCULATE_OR_LOAD) {
 			//image is inside (is smaller than) viewport
 			image_encoder_width = UtilGtk.WidgetWidth(viewport_image_encoder_capture)-3; 
 			image_encoder_height = UtilGtk.WidgetHeight(viewport_image_encoder_capture)-3;
@@ -1410,8 +1445,11 @@ public partial class ChronoJumpWindow
 			encoder_pulsebar_capture.Text = Catalog.GetString("Please, wait.");
 			treeview_encoder_curves.Sensitive = false;
 			encoderThread = new Thread(new ThreadStart(encoderCreateCurvesGraphR));
-			GLib.Idle.Add (new GLib.IdleHandler (pulseGTKEncoderCapture));
-		} else {
+			if(mode == encoderModes.CAPTURE)
+				GLib.Idle.Add (new GLib.IdleHandler (pulseGTKEncoderCapture));
+			else // mode == encoderModes.RECALCULATE_OR_LOAD
+				GLib.Idle.Add (new GLib.IdleHandler (pulseGTKEncoderRecalculateOrLoad));
+		} else { //encoderModes.ANALYZE
 			//the -3 is because image is inside (is smaller than) viewport
 			image_encoder_width = UtilGtk.WidgetWidth(viewport_image_encoder_analyze)-3; 
 			image_encoder_height = UtilGtk.WidgetHeight(viewport_image_encoder_analyze)-3;
@@ -1442,6 +1480,23 @@ public partial class ChronoJumpWindow
 		return true;
 	}
 	
+	private bool pulseGTKEncoderRecalculateOrLoad ()
+	{
+		if(! encoderThread.IsAlive || encoderProcessCancel) {
+			if(encoderProcessCancel){
+				Util.CancelRScript = true;
+			}
+
+			finishPulsebar(encoderModes.RECALCULATE_OR_LOAD);
+			Log.Write("dying");
+			return false;
+		}
+		updatePulsebar(encoderModes.CAPTURE); //activity on pulsebar
+		Thread.Sleep (50);
+		Log.Write(encoderThread.ThreadState.ToString());
+		return true;
+	}
+	
 	private bool pulseGTKEncoderAnalyze ()
 	{
 		if(! encoderThread.IsAlive || encoderProcessCancel) {
@@ -1460,39 +1515,45 @@ public partial class ChronoJumpWindow
 	}
 	
 	private void updatePulsebar (encoderModes mode) {
-		if(mode == encoderModes.CAPTURE) 
+		if(mode == encoderModes.CAPTURE || mode == encoderModes.RECALCULATE_OR_LOAD) 
 			encoder_pulsebar_capture.Pulse();
 		else
 			encoder_pulsebar_analyze.Pulse();
 	}
 	
 	private void finishPulsebar(encoderModes mode) {
-		if(mode == encoderModes.CAPTURE) {
+		if(mode == encoderModes.CAPTURE || mode == encoderModes.RECALCULATE_OR_LOAD) {
 			if(encoderProcessCancel) {
 				encoderProcessCancel = false;
-			
 				encoderButtonsSensitive(encoderSensEnum.DONEYESSIGNAL);
+				encoder_pulsebar_capture.Text = Catalog.GetString("Cancelled");
 			} else {
 				Pixbuf pixbuf = new Pixbuf (Util.GetEncoderGraphTempFileName()); //from a file
 				image_encoder_capture.Pixbuf = pixbuf;
 				encoderUpdateTreeView();
+		
+				//autosave signal (but not in recalculate or load)
+				if(mode == encoderModes.CAPTURE)
+					encoder_pulsebar_capture.Text = encoderSaveSignalOrCurve("signal", 0);
+				else
+					encoder_pulsebar_capture.Text = "";
 			}
 
 			encoder_pulsebar_capture.Fraction = 1;
-			encoder_pulsebar_capture.Text = "";
 
 		} else {
-			if(encoderProcessCancel) 
+			if(encoderProcessCancel) {
 				encoderProcessCancel = false;
-			else {
+				encoder_pulsebar_capture.Text = Catalog.GetString("Cancelled");
+			} else {
 				//TODO pensar en si s'ha de fer 1er amb mida petita i despres amb gran (en el zoom),
 				//o si es una sola i fa alguna edicio
 				Pixbuf pixbuf = new Pixbuf (Util.GetEncoderGraphTempFileName()); //from a file
 				image_encoder_analyze.Pixbuf = pixbuf;
+				encoder_pulsebar_analyze.Text = "";
 			}
 
 			encoder_pulsebar_analyze.Fraction = 1;
-			encoder_pulsebar_analyze.Text = "";
 			
 			encoderButtonsSensitive(encoderSensEnum.DONEYESSIGNAL);
 		}
diff --git a/src/gui/jump.cs b/src/gui/jump.cs
index f84a691..30197d7 100644
--- a/src/gui/jump.cs
+++ b/src/gui/jump.cs
@@ -752,7 +752,7 @@ public class RepairJumpRjWindow
 		}
 
 		//save it deleting the old first for having the same uniqueID
-		SqliteJump.Delete("jumpRj", jumpRj.UniqueID.ToString());
+		SqliteJump.Delete("jumpRj", jumpRj.UniqueID);
 		jumpRj.InsertAtDB(false, Constants.JumpRjTable); 
 		/*
 		SqliteJump.InsertRj("jumpRj", jumpRj.UniqueID.ToString(), jumpRj.PersonID, jumpRj.SessionID, 
diff --git a/src/gui/pulse.cs b/src/gui/pulse.cs
index cf97c61..bfc55cc 100644
--- a/src/gui/pulse.cs
+++ b/src/gui/pulse.cs
@@ -462,7 +462,7 @@ public class RepairPulseWindow
 		myPulse.TimesString = timeString;
 
 		//save it deleting the old first for having the same uniqueID
-		SqlitePulse.Delete(myPulse.UniqueID.ToString());
+		Sqlite.Delete(Constants.PulseTable,myPulse.UniqueID);
 
 		myPulse.InsertAtDB(false, Constants.PulseTable);
 		/*
diff --git a/src/gui/run.cs b/src/gui/run.cs
index 4e42af1..6428526 100644
--- a/src/gui/run.cs
+++ b/src/gui/run.cs
@@ -841,7 +841,7 @@ public class RepairRunIntervalWindow
 		}
 
 		//save it deleting the old first for having the same uniqueID
-		SqliteRun.Delete(Constants.RunIntervalTable, runInterval.UniqueID.ToString());
+		SqliteRun.Delete(Constants.RunIntervalTable, runInterval.UniqueID);
 		runInterval.InsertAtDB(false, Constants.RunIntervalTable); 
 		/*
 		SqliteRun.InsertInterval(false, Constants.RunIntervalTable, runInterval.UniqueID.ToString(), 
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index 7f22eb4..df5f357 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -130,25 +130,30 @@ class SqliteEncoder : Sqlite
 			dbcon.Close();
 	}
 	
-	
+	//pass uniqueID value and then will return one record. do like this:
+	//EncoderSQL = (EncoderSQL) SqliteEncoder.Select(false, myYniqueID, 0, 0, "")[0];
+	//or
+	//pass uniqueID==-1 and personID, sessioID, signalOrCurve values, and will return some records
 	public static ArrayList Select (bool dbconOpened, 
 			int uniqueID, int personID, int sessionID, string signalOrCurve)
 	{
 		if(! dbconOpened)
 			dbcon.Open();
 
-		string uniqueIDStr = "";
+		string selectStr = "";
 		if(uniqueID != -1)
-			uniqueIDStr = " AND " + Constants.EncoderTable + ".uniqueID = " + uniqueID;
+			selectStr = Constants.EncoderTable + ".uniqueID = " + uniqueID;
+		else
+			selectStr = "personID = " + personID + " AND sessionID = " + sessionID + 
+			" AND signalOrCurve = '" + signalOrCurve + "'";
 
 		dbcmd.CommandText = "SELECT " + 
 			Constants.EncoderTable + ".*, " + Constants.EncoderExerciseTable + ".name FROM " + 
 			Constants.EncoderTable  + ", " + Constants.EncoderExerciseTable  + 
-			" WHERE personID = " + personID + " AND sessionID = " + sessionID + 
-			" AND signalOrCurve = '" + signalOrCurve + 
-			"' AND " + Constants.EncoderTable + ".exerciseID = " + 
-			Constants.EncoderExerciseTable + ".uniqueID " +
-			uniqueIDStr;
+			" WHERE " + selectStr +
+			" AND " + Constants.EncoderTable + ".exerciseID = " + 
+			Constants.EncoderExerciseTable + ".uniqueID ";
+
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		
 		SqliteDataReader reader;
diff --git a/src/sqlite/jump.cs b/src/sqlite/jump.cs
index b7ec0e2..6d443a9 100644
--- a/src/sqlite/jump.cs
+++ b/src/sqlite/jump.cs
@@ -225,16 +225,6 @@ class SqliteJump : Sqlite
 		dbcon.Close();
 	}
 
-	public static void Delete(string jumpTable, string uniqueID)
-	{
-		dbcon.Open();
-		dbcmd.CommandText = "Delete FROM " + jumpTable +
-			" WHERE uniqueID == " + uniqueID;
-		Log.WriteLine(dbcmd.CommandText.ToString());
-		dbcmd.ExecuteNonQuery();
-		dbcon.Close();
-	}
-
 	//onle for change SJ+ CMJ+ and ABK+ to SJl...
 	public static void ChangeWeightToL()
 	{
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index abbd06e..052ef02 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -1644,7 +1644,7 @@ class Sqlite
 		foreach(int personID in myArray) {
 			//if person is not in other sessions, delete it from DB
 			if(! SqlitePersonSession.PersonExistsInPS(personID))
-				SqlitePerson.Delete(personID);
+				Delete(Constants.PersonTable, personID);
 		}
 	}
 				
@@ -1971,7 +1971,7 @@ Console.WriteLine("5" + tableName);
 		//6th drop temp table
 		Sqlite.dropTable(Constants.ConvertTempTable);
 	}
-	
+
 	protected static string [] DataReaderToStringArray (SqliteDataReader reader, int columns) {
 		string [] myReaderStr = new String[columns];
 		for (int i=0; i < columns; i ++)
@@ -1979,6 +1979,8 @@ Console.WriteLine("5" + tableName);
 		return myReaderStr;
 	}
 
+	/* methods for different classes */
+
 	public static int Max (string tableName, string column, bool dbconOpened)
 	{
 		if(!dbconOpened)
@@ -2042,6 +2044,18 @@ Console.WriteLine("5" + tableName);
 		return myReturn;
 	}
 
+	public static void Delete(string tableName, int uniqueID)
+	{
+		dbcon.Open();
+		dbcmd.CommandText = "Delete FROM " + tableName +
+			" WHERE uniqueID == " + uniqueID.ToString();
+		Log.WriteLine(dbcmd.CommandText.ToString());
+		dbcmd.ExecuteNonQuery();
+		dbcon.Close();
+	}
+
+
+	/* end of methods for different classes */
 	
 	/* 
 	 * SERVER STUFF
diff --git a/src/sqlite/multiChronopic.cs b/src/sqlite/multiChronopic.cs
index 5159866..0c1cc16 100644
--- a/src/sqlite/multiChronopic.cs
+++ b/src/sqlite/multiChronopic.cs
@@ -244,12 +244,4 @@ class SqliteMultiChronopic : Sqlite
 		dbcon.Close();
 	}
 
-	public static void Delete(string uniqueID)
-	{
-		dbcon.Open();
-		dbcmd.CommandText = "Delete FROM " + Constants.MultiChronopicTable + " WHERE uniqueID == " + uniqueID;
-		Log.WriteLine(dbcmd.CommandText.ToString());
-		dbcmd.ExecuteNonQuery();
-		dbcon.Close();
-	}
 }
diff --git a/src/sqlite/person.cs b/src/sqlite/person.cs
index 8e8ffa8..476f7ee 100644
--- a/src/sqlite/person.cs
+++ b/src/sqlite/person.cs
@@ -514,14 +514,4 @@ finishForeach:
 		dbcon.Close();
 	}
 
-
-	public static void Delete(int uniqueID)
-	{
-		dbcmd.CommandText = "Delete FROM " + Constants.PersonTable +
-			" WHERE uniqueID == " + uniqueID.ToString();
-		Log.WriteLine(dbcmd.CommandText.ToString());
-		dbcmd.ExecuteNonQuery();
-	}
-
-
 }
diff --git a/src/sqlite/personSession.cs b/src/sqlite/personSession.cs
index 5bdd118..b2c03db 100644
--- a/src/sqlite/personSession.cs
+++ b/src/sqlite/personSession.cs
@@ -357,7 +357,7 @@ class SqlitePersonSession : Sqlite
 
 		//if person is not in other sessions, delete it from DB
 		if(! PersonExistsInPS(Convert.ToInt32(personID))) {
-			SqlitePerson.Delete(Convert.ToInt32(personID));
+			Delete(Constants.PersonTable, Convert.ToInt32(personID));
 
 			//delete photos if any
 			if(File.Exists(Util.GetPhotoFileName(false, Convert.ToInt32(personID))))
diff --git a/src/sqlite/pulse.cs b/src/sqlite/pulse.cs
index c1b881b..8f45795 100644
--- a/src/sqlite/pulse.cs
+++ b/src/sqlite/pulse.cs
@@ -175,12 +175,4 @@ class SqlitePulse : Sqlite
 		dbcon.Close();
 	}
 
-	public static void Delete(string uniqueID)
-	{
-		dbcon.Open();
-		dbcmd.CommandText = "Delete FROM " + Constants.PulseTable + " WHERE uniqueID == " + uniqueID;
-		Log.WriteLine(dbcmd.CommandText.ToString());
-		dbcmd.ExecuteNonQuery();
-		dbcon.Close();
-	}
 }
diff --git a/src/sqlite/reactionTime.cs b/src/sqlite/reactionTime.cs
index a2374c7..e7528d5 100644
--- a/src/sqlite/reactionTime.cs
+++ b/src/sqlite/reactionTime.cs
@@ -172,12 +172,4 @@ class SqliteReactionTime : Sqlite
 		dbcon.Close();
 	}
 
-	public static void Delete(string uniqueID)
-	{
-		dbcon.Open();
-		dbcmd.CommandText = "Delete FROM " + Constants.ReactionTimeTable + " WHERE uniqueID == " + uniqueID;
-		Log.WriteLine(dbcmd.CommandText.ToString());
-		dbcmd.ExecuteNonQuery();
-		dbcon.Close();
-	}
 }
diff --git a/src/sqlite/run.cs b/src/sqlite/run.cs
index d78539a..f089e77 100644
--- a/src/sqlite/run.cs
+++ b/src/sqlite/run.cs
@@ -190,14 +190,5 @@ class SqliteRun : Sqlite
 		dbcon.Close();
 	}
 
-	public static void Delete(string runTable, string uniqueID)
-	{
-		dbcon.Open();
-		dbcmd.CommandText = "Delete FROM " + runTable + 
-			" WHERE uniqueID == " + uniqueID;
-		Log.WriteLine(dbcmd.CommandText.ToString());
-		dbcmd.ExecuteNonQuery();
-		dbcon.Close();
-	}
 }
 
diff --git a/src/util.cs b/src/util.cs
index 108656c..d2f6560 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -28,6 +28,8 @@ using System.IO; 		//for detect OS
 //this class tries to be a space for methods that are used in different classes
 public class Util
 {
+	public static bool CancelRScript;
+
 	//all numbers are saved in database with '.' as decimal separator (method for numbers)
 	public static string ConvertToPoint (double myDouble)
 	{
@@ -887,6 +889,7 @@ public class Util
 	}
 	
 	
+	
 	/********** end of encoder paths ************/
 
 	public static string GetManualDir() {
@@ -939,7 +942,29 @@ public class Util
 		}
 	}
 	
-	public static bool CancelRScript;
+	public static bool FileDelete(string fileName) {
+		try {
+			if(File.Exists(fileName)) {
+				File.Delete(fileName);
+				return true;
+			}
+		} catch {}
+		return false;
+	}
+
+	public static string ReadFile(string fileName)
+	{
+		try {
+			StreamReader reader = File.OpenText(fileName);
+			string contents = reader.ReadToEnd ();
+			reader.Close();
+			return contents;
+		} catch {
+			return null;
+		}
+	}
+
+	
 	public static void RunRScript(string rScript){
 		CancelRScript = false;
 
@@ -1020,19 +1045,7 @@ public class Util
 		p.WaitForExit();
 		while ( ! ( File.Exists(outputFileCheck) || CancelRScript) );
 	}
-
-	public static string ReadFile(string fileName)
-	{
-		try {
-			StreamReader reader = File.OpenText(fileName);
-			string contents = reader.ReadToEnd ();
-			reader.Close();
-			return contents;
-		} catch {
-			return null;
-		}
-	}
-
+	
 	private static string [] encoderFindPos(string contents, int start, int duration) {
 		int startPos = 0;
 		int durationPos = 0;
@@ -1073,7 +1086,7 @@ public class Util
 		return returnStr;
 	}
 
-	public static void EncoderDeleteCurve(string fileName, int start, int duration) {
+	public static void EncoderDeleteCurveFromSignal(string fileName, int start, int duration) {
 		string contents = ReadFile(fileName);
 		string [] startAndDuration = encoderFindPos(contents, start, duration);
 



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