[chronojump] Encoder calcule curves do not crash if no R



commit 0e0e0700c3a99eeec0ed6f65b995e4de2a0d20ef
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Oct 15 11:48:15 2013 +0200

    Encoder calcule curves do not crash if no R

 src/chronojump.cs  |    2 ++
 src/gui/encoder.cs |   25 +++++++++++++++++++------
 src/util.cs        |   26 ++++++++++++++++----------
 3 files changed, 37 insertions(+), 16 deletions(-)
---
diff --git a/src/chronojump.cs b/src/chronojump.cs
index 65e3fbd..0c2dd50 100644
--- a/src/chronojump.cs
+++ b/src/chronojump.cs
@@ -78,6 +78,7 @@ public class ChronoJump
                Environment.SetEnvironmentVariable ("R_HOME", @"/usr/lib/R");
                Environment.SetEnvironmentVariable ("PATH", envPath + Path.PathSeparator + rBinPath);
 
+               /*
                using (REngine engine = REngine.CreateInstance("RDotNet"))
                {
                        // From v1.5, REngine requires explicit initialization.
@@ -99,6 +100,7 @@ public class ChronoJump
                        Console.WriteLine("P-value = {0:0.000}", p);
                }
                Environment.Exit(1);
+               */
                
                
                
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 56d6939..bd2e630 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -151,6 +151,7 @@ public partial class ChronoJumpWindow
        private static int encoderCapturePointsCaptured;                //stored to be realtime displayed
        private static int encoderCapturePointsPainted;                 //stored to be realtime displayed
        private static bool encoderProcessCancel;
+       private static bool encoderProcessProblems;
        private static bool encoderProcessFinish;
 
        //smooth preferences on Sqlite since 1.3.7
@@ -694,15 +695,19 @@ public partial class ChronoJumpWindow
                                "",     //SpecialData
                                ep);
                
-               Util.RunEncoderGraph(
+               bool result = Util.RunEncoderGraph(
                                Util.ChangeSpaceAndMinusForUnderscore(currentPerson.Name) + "-" + 
                                
Util.ChangeSpaceAndMinusForUnderscore(UtilGtk.ComboGetActive(combo_encoder_exercise)) + 
                                "-(" + Util.ConvertToPoint(findMassFromCombo(true)) + "Kg)",
                                es);
 
-               //store this to show 1,2,3,4,... or 1e,1c,2e,2c,... in RenderN
-               //if is not stored, it can change when changed eccon radiobutton on cursor is in treeview
-               ecconLast = findEccon(false);
+               if(result)
+                       //store this to show 1,2,3,4,... or 1e,1c,2e,2c,... in RenderN
+                       //if is not stored, it can change when changed eccon radiobutton on cursor is in 
treeview
+                       ecconLast = findEccon(false);
+               else {
+                       encoderProcessProblems = true;
+               }
        }
        
        void on_button_encoder_analyze_data_select_curves_clicked (object o, EventArgs args) 
@@ -3804,13 +3809,21 @@ Log.WriteLine(str);
                        
                        //save video will be later at encoderSaveSignalOrCurve, because there 
encoderSignalUniqueID will be known
                        
-                       if(encoderProcessCancel) {
+                       if(encoderProcessCancel || encoderProcessProblems) {
                                //encoderButtonsSensitive(encoderSensEnum.DONEYESSIGNAL);
                                encoderButtonsSensitive(encoderSensEnumStored);
-                               encoder_pulsebar_capture.Text = Catalog.GetString("Cancelled");
                                if(notebook_encoder_capture.CurrentPage == 0 )
                                        notebook_encoder_capture.NextPage();
                                encoder_pulsebar_capture.Fraction = 1;
+                       
+                               if(encoderProcessProblems) {
+                                       new DialogMessage(Constants.MessageTypes.WARNING, 
+                                                       Catalog.GetString("Sorry. Error doing graph.") + 
+                                                       "\n" + Catalog.GetString("Maybe R is not installed.") 
+ 
+                                                       "\n\nhttp://www.r-project.org/";);
+                                       encoderProcessProblems = false;
+                               } else
+                                       encoder_pulsebar_capture.Text = Catalog.GetString("Cancelled");
                        }
                        else if(mode == encoderModes.CAPTURE && encoderProcessFinish) {
                                //encoderButtonsSensitive(encoderSensEnum.DONEYESSIGNAL);
diff --git a/src/util.cs b/src/util.cs
index 11573bd..b0e75c4 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1146,7 +1146,7 @@ public class Util
                while ( ! ( File.Exists(outputFileCheck) || CancelRScript) );
        }
        
-       public static void RunEncoderGraph(string title, EncoderStruct es) 
+       public static bool RunEncoderGraph(string title, EncoderStruct es) 
        {
                CancelRScript = false;
 
@@ -1260,16 +1260,22 @@ public class Util
                //delete 1RM data if exists
                if (File.Exists(es.SpecialData))
                        File.Delete(es.SpecialData);
-       
-               p = new Process();
-               p.StartInfo = pinfo;
-               p.Start();
-               p.WaitForExit();
 
-               if(outputFileCheck2 == "")
-                       while ( ! ( File.Exists(outputFileCheck) || CancelRScript) );
-               else
-                       while ( ! ( (File.Exists(outputFileCheck) && File.Exists(outputFileCheck2)) || 
CancelRScript ) );
+               try {   
+                       p = new Process();
+                       p.StartInfo = pinfo;
+                       p.Start();
+                       p.WaitForExit();
+
+                       if(outputFileCheck2 == "")
+                               while ( ! ( File.Exists(outputFileCheck) || CancelRScript) );
+                       else
+                               while ( ! ( (File.Exists(outputFileCheck) && File.Exists(outputFileCheck2)) 
|| CancelRScript ) );
+               } catch {
+                       return false;
+               }
+
+               return true;
        }
 
        private static string [] encoderFindPos(string contents, int start, int duration) {


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