[chronojump] Encoder: done remove selected curve
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Encoder: done remove selected curve
- Date: Mon, 28 May 2012 18:41:07 +0000 (UTC)
commit 25def2e032dab2a1d141fe7690c5ce380afb8199
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon May 28 20:39:10 2012 +0200
Encoder: done remove selected curve
glade/chronojump.glade | 5 +-
src/encoder.cs | 9 +++-
src/gui/encoder.cs | 97 ++++++++++++++++++++++++++++++++++++++++++-----
src/util.cs | 45 ++++++++++++++++++++++
4 files changed, 140 insertions(+), 16 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 24cbd1b..746eb02 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -24475,6 +24475,7 @@ Evaluator can use real name or nickname.</property>
<property name="pulse_step">0.10000000149</property>
</widget>
<packing>
+ <property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
@@ -24563,7 +24564,7 @@ Evaluator can use real name or nickname.</property>
<property name="spacing">20</property>
<child>
<widget class="GtkButton" id="button_encoder_delete_selected">
- <property name="label">Delete selected row</property>
+ <property name="label">Delete selected</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -24581,7 +24582,7 @@ Evaluator can use real name or nickname.</property>
<property name="spacing">12</property>
<child>
<widget class="GtkButton" id="button_encoder_save_selected">
- <property name="label">Save selected row</property>
+ <property name="label">Save selected</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
diff --git a/src/encoder.cs b/src/encoder.cs
index a1ec397..49107cc 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -141,12 +141,15 @@ public class EncoderStruct
//used on TreeView
public class EncoderCurve
{
- public EncoderCurve (string n, string start, string width, string height, string meanSpeed, string maxSpeed,
+ public EncoderCurve () {
+ }
+
+ public EncoderCurve (string n, string start, string duration, string height, string meanSpeed, string maxSpeed,
string meanPower, string peakPower, string peakPowerT, string PP_PPT)
{
this.N = n;
this.Start = start;
- this.Width = width;
+ this.Duration = duration;
this.Height = height;
this.MeanSpeed = meanSpeed;
this.MaxSpeed = maxSpeed;
@@ -158,7 +161,7 @@ public class EncoderCurve
public string N;
public string Start;
- public string Width;
+ public string Duration;
public string Height;
public string MeanSpeed;
public string MaxSpeed;
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index c485d29..f1a05c6 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -35,6 +35,7 @@ public partial class ChronoJumpWindow
[Widget] Gtk.SpinButton spin_encoder_smooth;
[Widget] Gtk.Button button_encoder_capture;
+ [Widget] Gtk.Button button_encoder_recalculate;
[Widget] Gtk.Label label_encoder_person_weight;
[Widget] Gtk.RadioButton radiobutton_encoder_concentric;
[Widget] Gtk.RadioButton radiobutton_encoder_capture_bar;
@@ -80,7 +81,7 @@ public partial class ChronoJumpWindow
GenericWindow genericWinForEncoder;
- //TODO: store encoder data: auto save, and show on a treeview. Put button to delete current (or should be called "last")
+ //TODO: store encoder data: auto save, and show on a treeview.
//TODO: put chronopic detection in a generic place. Done But:
//TODO: solve the problem of connecting two different chronopics
@@ -242,7 +243,40 @@ public partial class ChronoJumpWindow
void on_button_encoder_delete_selected_clicked (object o, EventArgs args)
{
- Log.WriteLine("TODO: Delete selected");
+ //concentric stuff
+ int duration;
+ int selectedID = treeviewEncoderCurvesEventSelectedID();
+
+ if(ecconLast != "c") {
+ bool isEven = (selectedID % 2 == 0); //check if it's even (in spanish "par")
+ if(isEven)
+ selectedID --;
+ }
+
+ EncoderCurve curve = treeviewEncoderCurvesGetCurve(selectedID);
+
+ //some start at ,5 because of the spline filtering
+ int curveStart = Convert.ToInt32(decimal.Truncate(Convert.ToDecimal(curve.Start)));
+
+ if( (ecconLast == "c" && selectedID == encoderCurves.Count) ||
+ (ecconLast != "c" && selectedID+1 == encoderCurves.Count) )
+ duration = -1; //until the end
+ else {
+ EncoderCurve curveNext = treeviewEncoderCurvesGetCurve(selectedID+1);
+ if(ecconLast != "c")
+ curveNext = treeviewEncoderCurvesGetCurve(selectedID+2);
+
+ int curveNextStart = Convert.ToInt32(decimal.Truncate(Convert.ToDecimal(curveNext.Start)));
+
+ duration = curveNextStart - curveStart;
+ }
+
+ if(curve.Start != null) {
+ Log.WriteLine(curveStart + "->" + duration);
+ Util.EncoderDeleteRow(Util.GetEncoderDataTempFileName(), curveStart, duration);
+ }
+ //force a recalculate
+ on_button_encoder_recalculate_clicked (o, args);
}
void on_button_encoder_save_selected_clicked (object o, EventArgs args)
@@ -390,7 +424,7 @@ public partial class ChronoJumpWindow
Catalog.GetString("Duration") + "\n (s)",
Catalog.GetString("Height") + "\n (cm)",
Catalog.GetString("MeanSpeed") + "\n (m/s)",
- Catalog.GetString("MaxSpeed") + "\n (m/s)", //duration (s): width
+ Catalog.GetString("MaxSpeed") + "\n (m/s)",
Catalog.GetString("MeanPower") + "\n (W)",
Catalog.GetString("PeakPower") + "\n (W)",
Catalog.GetString("PeakPowerTime") + "\n (s)",
@@ -415,7 +449,6 @@ public partial class ChronoJumpWindow
string [] cells = line.Split(new char[] {','});
cells = fixDecimals(cells);
- //iter = encoderStore.AppendValues(cells);
encoderCurves.Add (new EncoderCurve (cells[0], cells[1], cells[2],
cells[3], cells[4], cells[5], cells[6],
@@ -430,7 +463,7 @@ public partial class ChronoJumpWindow
}
treeview_encoder_curves.Model = encoderListStore;
-
+
treeview_encoder_curves.HeadersVisible=true;
int i=0;
@@ -451,7 +484,7 @@ public partial class ChronoJumpWindow
aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc (RenderStart));
break;
case 2:
- aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc (RenderWidth));
+ aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc (RenderDuration));
break;
case 3:
aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc (RenderHeight));
@@ -531,12 +564,12 @@ public partial class ChronoJumpWindow
(cell as Gtk.CellRendererText).Text =
String.Format(UtilGtk.TVNumPrint(myStart.ToString(),6,3),myStart);
}
- private void RenderWidth (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
+ private void RenderDuration (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
EncoderCurve curve = (EncoderCurve) model.GetValue (iter, 0);
- double myWidth = Convert.ToDouble(curve.Width)/1000; //ms->s
+ double myDuration = Convert.ToDouble(curve.Duration)/1000; //ms->s
(cell as Gtk.CellRendererText).Text =
- String.Format(UtilGtk.TVNumPrint(myWidth.ToString(),5,3),myWidth);
+ String.Format(UtilGtk.TVNumPrint(myDuration.ToString(),5,3),myDuration);
}
private void RenderHeight (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
@@ -661,19 +694,61 @@ public partial class ChronoJumpWindow
private int treeviewEncoderCurvesEventSelectedID() {
TreeIter iter = new TreeIter();
TreeModel myModel = treeview_encoder_curves.Model;
+
if (treeview_encoder_curves.Selection.GetSelected (out myModel, out iter))
return Convert.ToInt32(((EncoderCurve) (treeview_encoder_curves.Model.GetValue (iter, 0))).N);
- //this return an int, also in ec
+ //this return an int, also in ec
else
return 0;
}
+ private EncoderCurve treeviewEncoderCurvesGetCurve(int row) {
+ TreeIter iter = new TreeIter();
+ bool iterOk = encoderListStore.GetIterFirst(out iter);
+ if(iterOk) {
+ int count=1;
+ do {
+ if(count==row)
+ return (EncoderCurve) treeview_encoder_curves.Model.GetValue (iter, 0);
+ count ++;
+ } while (encoderListStore.IterNext (ref iter));
+ }
+ EncoderCurve curve = new EncoderCurve();
+ return curve;
+ }
+
+
private void on_treeview_encoder_curves_cursor_changed (object o, EventArgs args) {
if (treeviewEncoderCurvesEventSelectedID() == 0)
sensitiveEncoderRowButtons(false);
else {
sensitiveEncoderRowButtons(true);
- Log.WriteLine(treeviewEncoderCurvesEventSelectedID().ToString());
+ /*
+ * TODO: try that on eccon != "c", two lines get selected
+ int line = Convert.ToInt32(treeviewEncoderCurvesEventSelectedID());
+
+ //on ecc-con select both lines
+ if(ecconLast != "c") {
+ treeview_encoder_curves.CursorChanged -= on_treeview_encoder_curves_cursor_changed;
+
+ TreeIter iter;
+ treeview_encoder_curves.Model.GetIterFirst ( out iter ) ;
+ bool isEven = (line % 2 == 0); //check if it's even (in spanish "par")
+ if(isEven) {
+ //select also previous row
+ for(int i=1; i < line -1; i++)
+ treeview_encoder_curves.Model.IterNext (ref iter);
+ }
+ else {
+ //select also next row
+ for(int i=1; i < line +1; i++)
+ treeview_encoder_curves.Model.IterNext (ref iter);
+ }
+
+ treeview_encoder_curves.Selection.SelectIter(iter);
+ treeview_encoder_curves.CursorChanged += on_treeview_encoder_curves_cursor_changed;
+ }
+ */
}
}
diff --git a/src/util.cs b/src/util.cs
index 188caa2..2671204 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1005,6 +1005,51 @@ public class Util
}
}
+ public static void EncoderDeleteRow(string fileName, int start, int duration) {
+ string contents = ReadFile(fileName);
+ int startPos = 0;
+ int durationPos = 0;
+ int i,digits;
+ for(i=0, digits=0; i < contents.Length; i++) {
+ if(Char.IsDigit(contents[i])) {
+ digits ++;
+ if(digits==start) {
+ startPos = i;
+ //but digit can be negative, check previous char if it was a '-'
+ if(contents[i-1] == '-')
+ startPos = i-1;
+ //duration == -1 means: until the end
+ if(duration == -1) {
+ //when removing from startPos until the end,
+ //the ',' before startPos will be in the end of the file
+ //and then chronojump will try to read after that comma
+ //because it reads in a Split (',')
+ //for this reason we need to start removing that comma if exists
+ if(contents[startPos-1] == ',')
+ startPos --;
+
+ durationPos = contents.Length - startPos;
+ break;
+ }
+ }
+ if(startPos > 0 && digits == start + duration)
+ durationPos = i-startPos;
+ }
+ }
+ Log.WriteLine("s "+ startPos.ToString());
+ Log.WriteLine("d "+ durationPos.ToString());
+ Log.WriteLine("i " + i.ToString());
+
+ StringBuilder myStringBuilder = new StringBuilder(contents);
+ myStringBuilder.Remove(startPos, durationPos);
+ contents = myStringBuilder.ToString();
+
+ TextWriter writer = File.CreateText(fileName);
+ writer.Write(contents);
+ writer.Flush();
+ ((IDisposable)writer).Dispose();
+ }
+
/*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]