ifdef for EXTRA_CHECK, and precalculate time_width_double
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Fri, 13 Aug 2004 21:30:15 +0000 (21:30 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Fri, 13 Aug 2004 21:30:15 +0000 (21:30 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@733 04897980-b3bd-0310-b5e0-8ef037075253

ltt/branches/poly/ltt/time.h
ltt/branches/poly/lttv/modules/gui/controlflow/drawing.c
ltt/branches/poly/lttv/modules/gui/controlflow/drawing.h
ltt/branches/poly/lttv/modules/gui/controlflow/eventhooks.c
ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c
ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/mainwindow.h

index 642328e9001d9ac0c5ad08e5a98e4a16748e432d..db85c69c7dc6ccda5ef508502ba66afeacf90f83 100644 (file)
@@ -90,7 +90,7 @@ static inline double ltt_time_to_double(LttTime t1)
   if(t1.tv_sec > MAX_TV_SEC_TO_DOUBLE)
     g_warning("Precision loss in conversion LttTime to double");
 #endif //EXTRA_CHECK
-  return ((double)t1.tv_sec * NANOSECONDS_PER_SECOND) + (double)t1.tv_nsec;
+  return ((double)t1.tv_sec * (double)NANOSECONDS_PER_SECOND) + (double)t1.tv_nsec;
 }
 
 
index 3a15130c9cccd404cc27e579bb52e41a57605659..ee42d907416bc987e8fc92faf4c697cacb39699a 100644 (file)
@@ -138,15 +138,11 @@ void drawing_data_request(Drawing_t *drawing,
   g_debug("x is : %i, x+width is : %i", x, x+width);
 
   convert_pixels_to_time(drawing->width, x,
-        time_window.start_time,
-        time_window.time_width,
-        window_end,
+        time_window,
         &start);
 
   convert_pixels_to_time(drawing->width, x+width,
-        time_window.start_time,
-        time_window.time_width,
-        window_end,
+        time_window,
         &time_end);
 
   lttvwindow_events_request_remove_all(tab,
@@ -406,9 +402,7 @@ void drawing_data_request_begin(EventsRequest *events_request, LttvTracesetState
   cfd->drawing->last_start = events_request->start_time;
 
   convert_time_to_pixels(
-          time_window.start_time,
-          time_window.time_width,
-          end_time,
+          time_window,
           events_request->start_time,
           width,
           &x);
@@ -448,18 +442,14 @@ void drawing_request_expose(EventsRequest *events_request,
 
 #if 0
   convert_time_to_pixels(
-        time_window.start_time,
-        time_window.time_width,
-        window_end,
+        time_window,
         cfd->drawing->last_start,
         drawing->width,
         &x);
 
 #endif //0
   convert_time_to_pixels(
-        time_window.start_time,
-        time_window.time_width,
-        window_end,
+        time_window,
         end_time,
         drawing->width,
         &x_end);
@@ -614,9 +604,7 @@ expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
   {
     /* Draw the dotted lines */
     convert_time_to_pixels(
-          time_window.start_time,
-          time_window.time_width,
-          window_end,
+          time_window,
           current_time,
           drawing->width,
           &cursor_x);
@@ -704,9 +692,7 @@ button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer user_data
     g_debug("x click is : %f", event->x);
 
     convert_pixels_to_time(drawing->width, (guint)event->x,
-        time_window.start_time,
-        time_window.time_width,
-        window_end,
+        time_window,
         &time);
 
     lttvwindow_report_current_time(control_flow_data->tab, time);
@@ -933,44 +919,39 @@ GtkWidget *drawing_get_widget(Drawing_t *drawing)
 __inline void convert_pixels_to_time(
     gint width,
     guint x,
-    LttTime window_time_begin,
-    LttTime window_time_interval,
-    LttTime window_time_end,
+    TimeWindow time_window,
     LttTime *time)
 {
   double time_d;
   
-  time_d = ltt_time_to_double(window_time_interval);
+  time_d = time_window.time_width_double;
   time_d = time_d / (double)width * (double)x;
   *time = ltt_time_from_double(time_d);
-  *time = ltt_time_add(window_time_begin, *time);
+  *time = ltt_time_add(time_window.start_time, *time);
 }
 
 
 __inline void convert_time_to_pixels(
-    LttTime window_time_begin,
-    LttTime window_time_interval,
-    LttTime window_time_end,
+    TimeWindow time_window,
     LttTime time,
     int width,
     guint *x)
 {
-  double time_d, interval_d;
+  double time_d;
 #ifdef EXTRA_CHECK 
   g_assert(ltt_time_compare(window_time_begin, time) <= 0 &&
            ltt_time_compare(window_time_end, time) >= 0);
 #endif //EXTRA_CHECK
   
-  time = ltt_time_sub(time, window_time_begin);
+  time = ltt_time_sub(time, time_window.start_time);
   
   time_d = ltt_time_to_double(time);
-  interval_d = ltt_time_to_double(window_time_interval);
   
-  if(interval_d == 0.0) {
+  if(time_window.time_width_double == 0.0) {
     g_assert(time_d == 0.0);
     *x = 0;
   } else {
-    *x = (guint)(time_d / interval_d * (double)width);
+    *x = (guint)(time_d / time_window.time_width_double * (double)width);
   }
   
 }
index d07ed4e771e1262fd6c15526a5d426cf3722210a..69840a1a75f5f51d07d229dc271a102261bc7165 100644 (file)
@@ -137,15 +137,11 @@ void drawing_remove_square(Drawing_t *drawing,
 __inline void convert_pixels_to_time(
     gint width,
     guint x,
-    LttTime window_time_begin,
-    LttTime window_time_interval,
-    LttTime window_time_end,
+    TimeWindow time_window,
     LttTime *time);
 
 __inline void convert_time_to_pixels(
-    LttTime window_time_begin,
-    LttTime window_time_interval,
-    LttTime window_time_end,
+    TimeWindow time_window,
     LttTime time,
     gint width,
     guint *x);
index f4b77bcec22f5816c20ba6b47934494e0fd19715..02674d6af616bd6eb52cc3f425a6c71d1f848aa8 100644 (file)
@@ -395,10 +395,11 @@ int before_schedchange_hook(void *hook_data, void *call_data)
     lttvwindow_get_time_window(control_flow_data->tab);
 
   LttTime end_time = time_window.end_time;
-
+#ifdef EXTRA_CHECK
   if(ltt_time_compare(evtime, time_window.start_time) == -1
         || ltt_time_compare(evtime, end_time) == 1)
             return;
+#endif //EXTRA_CHECK
   guint width = drawing->width;
 
   /* we are in a schedchange, before the state update. We must draw the
@@ -483,9 +484,7 @@ int before_schedchange_hook(void *hook_data, void *call_data)
       {
         guint x;
         convert_time_to_pixels(
-                  time_window.start_time,
-                  time_window.time_width,
-                  end_time,
+                  time_window,
                   evtime,
                   width,
                   &x);
@@ -608,9 +607,7 @@ int before_schedchange_hook(void *hook_data, void *call_data)
         guint x;
 
         convert_time_to_pixels(
-                  time_window.start_time,
-                  time_window.time_width,
-                  end_time,
+                  time_window,
                   evtime,
                   width,
                   &x);
@@ -799,14 +796,10 @@ int before_schedchange_hook(void *hook_data, void *call_data)
 
     LttTime time = ltt_event_time(e);
 
-    LttTime window_end = ltt_time_add(time_window.time_width,
-                          time_window.start_time);
-
+    LttTime window_end = time_window.end_time;
     
     convert_time_to_pixels(
-        time_window.start_time,
-        time_window.time_width,
-        window_end,
+        time_window,
         time,
         width,
         &x);
@@ -1312,9 +1305,11 @@ int after_schedchange_hook(void *hook_data, void *call_data)
 
   LttTime end_time = time_window.end_time;
 
+#ifdef EXTRA_CHECK
   if(ltt_time_compare(evtime, time_window.start_time) == -1
         || ltt_time_compare(evtime, end_time) == 1)
             return;
+#endif //EXTRA_CHECK
 
   guint width = control_flow_data->drawing->width;
 
@@ -1381,9 +1376,7 @@ int after_schedchange_hook(void *hook_data, void *call_data)
   guint new_x;
   
   convert_time_to_pixels(
-      time_window.start_time,
-      time_window.time_width,
-      end_time,
+      time_window,
       evtime,
       width,
       &new_x);
@@ -1530,14 +1523,11 @@ int after_schedchange_hook(void *hook_data, void *call_data)
 
     //LttTime time = ltt_event_time(e);
 
-    //LttTime window_end = ltt_time_add(time_window->time_width,
-    //                      time_window->start_time);
+    //LttTime window_end = time_window->end_time;
 
     
     //convert_time_to_pixels(
-    //    time_window->start_time,
-    //    time_window.time_width,
-    //    window_end,
+    //    *time_window,
     //    time,
     //    width,
     //    &x);
@@ -1925,9 +1915,11 @@ int before_execmode_hook(void *hook_data, void *call_data)
 
   LttTime end_time = time_window.end_time;
 
+#ifdef EXTRA_CHECK
   if(ltt_time_compare(evtime, time_window.start_time) == -1
         || ltt_time_compare(evtime, end_time) == 1)
             return;
+#endif //EXTRA_CHECK
 
   guint width = drawing->width;
 
@@ -1996,9 +1988,7 @@ int before_execmode_hook(void *hook_data, void *call_data)
     guint x;
 
     convert_time_to_pixels(
-        time_window.start_time,
-        time_window.time_width,
-        end_time,
+        time_window,
         evtime,
         width,
         &x);
@@ -2085,9 +2075,11 @@ int after_execmode_hook(void *hook_data, void *call_data)
 
   LttTime end_time = time_window.end_time;
 
+#ifdef EXTRA_CHECK
   if(ltt_time_compare(evtime, time_window.start_time) == -1
         || ltt_time_compare(evtime, end_time) == 1)
             return;
+#endif //EXTRA_CHECK
 
   guint width = control_flow_data->drawing->width;
 
@@ -2143,9 +2135,7 @@ int after_execmode_hook(void *hook_data, void *call_data)
   guint new_x;
   
   convert_time_to_pixels(
-      time_window.start_time,
-      time_window.time_width,
-      end_time,
+      time_window,
       evtime,
       width,
       &new_x);
@@ -2191,9 +2181,11 @@ int before_process_hook(void *hook_data, void *call_data)
 
   LttTime end_time = time_window.end_time;
 
+#ifdef EXTRA_CHECK
   if(ltt_time_compare(evtime, time_window.start_time) == -1
         || ltt_time_compare(evtime, end_time) == 1)
             return;
+#endif //EXTRA_CHECK
 
   guint width = control_flow_data->drawing->width;
 
@@ -2266,9 +2258,7 @@ int before_process_hook(void *hook_data, void *call_data)
       guint x;
 
       convert_time_to_pixels(
-          time_window.start_time,
-          time_window.time_width,
-          end_time,
+          time_window,
           evtime,
           width,
           &x);
@@ -2363,9 +2353,11 @@ int after_process_hook(void *hook_data, void *call_data)
 
   LttTime end_time = time_window.end_time;
 
+#ifdef EXTRA_CHECK
   if(ltt_time_compare(evtime, time_window.start_time) == -1
         || ltt_time_compare(evtime, end_time) == 1)
             return;
+#endif //EXTRA_CHECK
 
   guint width = control_flow_data->drawing->width;
 
@@ -2432,9 +2424,7 @@ int after_process_hook(void *hook_data, void *call_data)
 
     guint new_x;
     convert_time_to_pixels(
-        time_window.start_time,
-        time_window.time_width,
-        end_time,
+        time_window,
         evtime,
         width,
         &new_x);
@@ -2505,9 +2495,7 @@ int after_process_hook(void *hook_data, void *call_data)
 
     guint new_x;
     convert_time_to_pixels(
-        time_window.start_time,
-        time_window.time_width,
-        end_time,
+        time_window,
         evtime,
         width,
         &new_x);
@@ -2583,9 +2571,7 @@ gint update_time_window_hook(void *hook_data, void *call_data)
       guint x = 0;
       guint width = control_flow_data->drawing->width;
       convert_time_to_pixels(
-          *os,
-          *ow,
-          old_end,
+          *old_time_window,
           *ns,
           width,
           &x);
@@ -2637,9 +2623,7 @@ gint update_time_window_hook(void *hook_data, void *call_data)
         guint x = 0;
         guint width = control_flow_data->drawing->width;
         convert_time_to_pixels(
-            *ns,
-            *nw,
-            new_end,
+            *new_time_window,
             *os,
             width,
             &x);
@@ -2895,6 +2879,7 @@ gint update_current_time_hook(void *hook_data, void *call_data)
   
     new_time_window.start_time = time_begin;
     new_time_window.time_width = width;
+    new_time_window.time_width_double = ltt_time_to_double(width);
     new_time_window.end_time = ltt_time_add(time_begin, width);
 
     lttvwindow_report_time_window(control_flow_data->tab, new_time_window);
@@ -2910,6 +2895,7 @@ gint update_current_time_hook(void *hook_data, void *call_data)
   
     new_time_window.start_time = time_begin;
     new_time_window.time_width = width;
+    new_time_window.time_width_double = ltt_time_to_double(width);
     new_time_window.end_time = ltt_time_add(time_begin, width);
 
     lttvwindow_report_time_window(control_flow_data->tab, new_time_window);
@@ -2950,9 +2936,11 @@ void draw_closure(gpointer key, gpointer value, gpointer user_data)
 
   LttTime end_time = time_window.end_time;
 
+#ifdef EXTRA_CHECK
   if(ltt_time_compare(evtime, time_window.start_time) == -1
         || ltt_time_compare(evtime, end_time) == 1)
             return;
+#endif //EXTRA_CHECK
 
   guint width = drawing->width;
 
@@ -3012,9 +3000,7 @@ void draw_closure(gpointer key, gpointer value, gpointer user_data)
         guint x;
 
         convert_time_to_pixels(
-            time_window.start_time,
-            time_window.time_width,
-            end_time,
+            time_window,
             evtime,
             width,
             &x);
index e4c497d401e5e2f27a0ba550f42a54bd1f3b737b..be473deafd31b25bfae1465e6d6fa251d475f22a 100644 (file)
@@ -485,6 +485,7 @@ int SetTraceset(Tab * tab, LttvTraceset *traceset)
       tmp_time.tv_sec = time_span.end_time.tv_sec;
     tmp_time.tv_nsec = 0;
     new_time_window.time_width = tmp_time ;
+    new_time_window.time_width_double = ltt_time_to_double(tmp_time);
     new_time_window.end_time = ltt_time_add(new_time_window.start_time,
                                             new_time_window.time_width) ;
   }
@@ -2284,14 +2285,18 @@ void zoom(GtkWidget * widget, double size)
   if(size == 0){
     new_time_window.start_time = time_span.start_time;
     new_time_window.time_width = time_delta;
+    new_time_window.time_width_double = ltt_time_to_double(time_delta);
     new_time_window.end_time = ltt_time_add(new_time_window.start_time,
                                             new_time_window.time_width) ;
   }else{
     new_time_window.time_width = ltt_time_div(new_time_window.time_width, size);
+    new_time_window.time_width_double = 
+                   ltt_time_to_double(new_time_window.time_width);
     if(ltt_time_compare(new_time_window.time_width,time_delta) > 0)
     { /* Case where zoom out is bigger than trace length */
       new_time_window.start_time = time_span.start_time;
       new_time_window.time_width = time_delta;
+      new_time_window.time_width_double = ltt_time_to_double(time_delta);
       new_time_window.end_time = ltt_time_add(new_time_window.start_time,
                                             new_time_window.time_width) ;
     }
@@ -2299,7 +2304,8 @@ void zoom(GtkWidget * widget, double size)
     {
       /* Center the image on the current time */
       new_time_window.start_time = 
-        ltt_time_sub(current_time, ltt_time_div(new_time_window.time_width, 2.0));
+        ltt_time_sub(current_time,
+            ltt_time_from_double(new_time_window.time_width_double/2.0));
       new_time_window.end_time = ltt_time_add(new_time_window.start_time,
                                             new_time_window.time_width) ;
       /* If on borders, don't fall off */
@@ -3466,13 +3472,13 @@ void time_change_manager               (Tab *tab,
                "upper",
                ltt_time_to_double(upper), /* upper */
                "step_increment",
-               ltt_time_to_double(new_time_window.time_width)
+               new_time_window.time_width_double
                              / SCROLL_STEP_PER_PAGE, /* step increment */
                "page_increment",
-               ltt_time_to_double(new_time_window.time_width)
+               new_time_window.time_width_double
                                                      /* page increment */
                "page_size",
-               ltt_time_to_double(new_time_window.time_width), /* page size */
+               new_time_window.time_width_double, /* page size */
                NULL);
   gtk_adjustment_changed(adjustment);
 
@@ -3609,6 +3615,9 @@ on_MEntry1_value_changed               (GtkSpinButton *spinbutton,
   /* Fix the time width to fit start time and end time */
   new_time_window.time_width = ltt_time_sub(end_time,
                                             new_time_window.start_time);
+  new_time_window.time_width_double =
+              ltt_time_to_double(new_time_window.time_width);
+
   new_time_window.end_time = end_time;
 
   time_change_manager(tab, new_time_window);
@@ -3642,6 +3651,8 @@ on_MEntry2_value_changed               (GtkSpinButton *spinbutton,
   /* Fix the time width to fit start time and end time */
   new_time_window.time_width = ltt_time_sub(end_time,
                                             new_time_window.start_time);
+  new_time_window.time_width_double =
+              ltt_time_to_double(new_time_window.time_width);
 
   new_time_window.end_time = end_time;
 
@@ -3694,6 +3705,8 @@ on_MEntry3_value_changed               (GtkSpinButton *spinbutton,
   /* Fix the time width to fit start time and end time */
   new_time_window.time_width = ltt_time_sub(end_time,
                                             new_time_window.start_time);
+  new_time_window.time_width_double =
+              ltt_time_to_double(new_time_window.time_width);
 
   new_time_window.end_time = end_time;
   
@@ -3729,6 +3742,8 @@ on_MEntry4_value_changed               (GtkSpinButton *spinbutton,
   /* Fix the time width to fit start time and end time */
   new_time_window.time_width = ltt_time_sub(end_time,
                                             new_time_window.start_time);
+  new_time_window.time_width_double =
+              ltt_time_to_double(new_time_window.time_width);
   new_time_window.end_time = end_time;
 
   time_change_manager(tab, new_time_window);
@@ -3855,6 +3870,9 @@ void scroll_value_changed_cb(GtkWidget *scrollbar,
   new_time_window.time_width = 
     ltt_time_from_double(page_size);
 
+  new_time_window.time_width_double =
+              page_size;
+
   new_time_window.end_time = ltt_time_add(new_time_window.start_time, 
                                           new_time_window.time_width);
 
index 5dcc85ffbc1bee4f63c271e97a27d921364a240e..9874d0d9091edd20f048e3d34842b640938f7456 100644 (file)
@@ -30,6 +30,7 @@ typedef struct _TracesetInfo TracesetInfo;
 struct _TimeWindow {
        LttTime start_time;
        LttTime time_width;
+  double time_width_double;
        LttTime end_time;
 }; 
 
This page took 0.031597 seconds and 4 git commands to generate.