Add viewport refresh function;
authorerg <devnull@localhost>
Wed, 24 Jun 2009 22:43:58 +0000 (22:43 +0000)
committererg <devnull@localhost>
Wed, 24 Jun 2009 22:43:58 +0000 (22:43 +0000)
add name argument when new graph is added;
fix memory leaks;
clean up code, putting common code into functions

cmd/smyrna/viewport.c
cmd/smyrna/viewport.h

index 5240f64746a1a0038372a6c26bc37452b221795b..e56f0722e25cd4401f652a6d343fab4d6bea9d2a 100755 (executable)
@@ -465,7 +465,7 @@ void init_viewport(ViewInfo * view)
     set_viewport_settings_from_template(view, view->default_attributes);
     view->dfltViewType = VT_NONE;
     view->dfltEngine = GVK_NONE;
-       view->Topview->Graphdata.GraphFileName=(char*)0;
+       view->Topview->Graphdata.GraphFileName = (char*)0;
        view->Topview->Graphdata.Modified=0;
        view->colschms=NULL;
        view->flush=1;
@@ -569,8 +569,9 @@ static Agraph_t *loadGraph(char *filename)
                fclose (input_file);
                return 0;
     }
-       view->Topview->Graphdata.GraphFileName = strdup (filename);
-       return g;
+    free (view->Topview->Graphdata.GraphFileName);
+    view->Topview->Graphdata.GraphFileName = strdup (filename);
+    return g;
 }
 #ifdef UNUSED
 static void refresh_borders(Agraph_t* g)
@@ -588,45 +589,54 @@ int add_graph_to_viewport_from_file(char *fileName)
 {
     Agraph_t *graph = loadGraph(fileName);
 
-    return add_graph_to_viewport (graph);
+    return add_graph_to_viewport (graph, fileName);
 }
 
-int add_graph_to_viewport(Agraph_t* graph)
+void
+refreshViewport (int doClear)
 {
-    if (graph) 
-       {
-               view->graphCount = view->graphCount + 1;
-               view->g =(Agraph_t **) realloc(view->g,sizeof(Agraph_t *) * view->graphCount);
-               view->g[view->graphCount - 1] = graph;
-               view->activeGraph = view->graphCount - 1;
-               load_settings_from_graph(view->g[view->activeGraph]);
-               update_graph_from_settings(view->g[view->activeGraph]);
-               set_viewport_settings_from_template(view, view->g[view->activeGraph]);
-               update_topview(graph, view->Topview,1);
-               gtk_combo_box_append_text(view->graphComboBox,view->Topview->Graphdata.GraphFileName);
-               fill_key(view->orig_key,get_md5_key(graph));
-               expose_event(view->drawing_area, NULL, NULL);
-               return 1;
+    Agraph_t* graph = view->g[view->activeGraph];
+
+    load_settings_from_graph(graph);
+    update_graph_from_settings(graph);
+    set_viewport_settings_from_template(view, graph);
+    if (doClear)
+       cleartopview(view->Topview);
+    update_topview(graph, view->Topview,1);
+    fill_key(view->orig_key,get_md5_key(graph));
+    expose_event(view->drawing_area, NULL, NULL);
+}
+
+static void
+activate (int id, int doClear)
+{
+    view->activeGraph = id;
+    refreshViewport (doClear);
+}
+
+int add_graph_to_viewport(Agraph_t* graph, char* id)
+{
+    if (graph) {
+       view->graphCount = view->graphCount + 1;
+       view->g =(Agraph_t **) realloc(view->g,sizeof(Agraph_t *) * view->graphCount);
+       view->g[view->graphCount - 1] = graph;
+
+       gtk_combo_box_append_text(view->graphComboBox,id);
+
+       activate (view->graphCount - 1, 0);
+       return 1;
     } 
-    else 
-       {
-               return 0;
+    else {
+       return 0;
     }
 
 }
 void switch_graph(int graphId)
 {
-       if (graphId >= view->graphCount)
-               return;/*wrong entry*/
-       view->activeGraph = graphId;
-       load_settings_from_graph(view->g[view->activeGraph]);
-       update_graph_from_settings(view->g[view->activeGraph]);
-       set_viewport_settings_from_template(view, view->g[view->activeGraph]);
-       cleartopview(view->Topview);
-       update_topview(view->g[view->activeGraph], view->Topview,1);
-       fill_key(view->orig_key,get_md5_key(view->g[view->activeGraph]));
-       expose_event(view->drawing_area, NULL, NULL);
-
+    if (graphId >= view->graphCount)
+       return;/*wrong entry*/
+    else
+       activate (graphId, 1);
 }
 
 #if 0
index c75f1970946ca19dac8ecc0cd7c5b737aa4e006c..4d7cf6bf230860d2a03a0bce2a41be79824ae0c2 100755 (executable)
@@ -26,8 +26,9 @@
 void init_viewport(ViewInfo * view);
 void set_viewport_settings_from_template(ViewInfo * view, Agraph_t *);
 void clear_viewport(ViewInfo * view);
+void refreshViewport (int doClear);
 int add_graph_to_viewport_from_file(char *fileName);
-int add_graph_to_viewport(Agraph_t* graph);
+int add_graph_to_viewport(Agraph_t* graph, char*);
 int close_graph(ViewInfo * view,int graphid);
 int save_graph(void);
 int save_graph_with_file_name(Agraph_t * graph, char *fileName);
@@ -41,6 +42,7 @@ void move_nodes(Agraph_t * g);
 void please_wait(void);
 void please_dont_wait(void);
 extern md5_byte_t* get_md5_key(Agraph_t* graph);
+void fill_key(md5_byte_t* b,md5_byte_t* data);
 colorschemaset* create_color_theme(int themeid);
 extern void getcolorfromschema(colorschemaset* sc,float l,float maxl,RGBColor* c);