From e99c6e2a8111868e7d911b0efa1e9fdff7bfb559 Mon Sep 17 00:00:00 2001 From: erg Date: Wed, 9 Apr 2008 21:06:09 +0000 Subject: [PATCH] Add macros for custom_object_data and custom_graph_data; clean up warnings; add macros for malloc and realloc --- cmd/smyrna/gui/gui.c | 104 +++---- cmd/smyrna/gui/menucallbacks.c | 19 +- cmd/smyrna/gui/topviewsettings.c | 8 +- cmd/smyrna/hier.c | 2 +- cmd/smyrna/smyrnadefs.h | 30 +- cmd/smyrna/topviewdata.c | 16 +- cmd/smyrna/tvnodes.c | 138 +++------ cmd/smyrna/viewport.c | 224 ++++++-------- cmd/smyrna/viewportcamera.c | 493 +++++++++++++++++-------------- 9 files changed, 488 insertions(+), 546 deletions(-) diff --git a/cmd/smyrna/gui/gui.c b/cmd/smyrna/gui/gui.c index e2870f5c4..a221165fb 100755 --- a/cmd/smyrna/gui/gui.c +++ b/cmd/smyrna/gui/gui.c @@ -14,11 +14,7 @@ * AT&T Research, Florham Park NJ * **********************************************************/ - - - #include - #include "compat.h" #include #include "gui.h" @@ -27,6 +23,7 @@ #include #include #include "viewport.h" +#include "memory.h" static char guibuffer[255]; //general purpose buffer @@ -186,28 +183,22 @@ void load_graph_properties(Agraph_t * graph) //dlgOpenGraph , GtkDialog gtk_entry_set_text((GtkEntry *) glade_xml_get_widget(xml, "entryGraphName"), - ((custom_graph_data *) AGDATA(graph))->GraphName); + GD_GraphName(graph)); gtk_entry_set_text((GtkEntry *) glade_xml_get_widget(xml, "entryGraphFileName"), - ((custom_graph_data *) AGDATA(graph))-> - GraphFileName); - + GD_GraphFileName(graph)); gtk_combo_box_set_active((GtkComboBox *) glade_xml_get_widget(xml, "cbLayout"), - ((custom_graph_data *) AGDATA(graph))-> - Engine); + GD_Engine(graph)); gtk_toggle_button_set_active((GtkToggleButton *) glade_xml_get_widget(xml, "chkVisible"), - ((custom_graph_data *) AGDATA(graph))-> - AlwaysShow); + GD_AlwaysShow(graph)); gtk_toggle_button_set_active((GtkToggleButton *) glade_xml_get_widget(xml, "chkLocked"), - ((custom_graph_data *) AGDATA(graph))-> - Locked); + GD_Locked(graph)); gtk_toggle_button_set_active((GtkToggleButton *) glade_xml_get_widget(xml, "chkTopView"), - ((custom_graph_data *) AGDATA(graph))-> - TopView); + GD_TopView(graph)); } int update_graph_properties(Agraph_t * graph) //updates graph from gui @@ -219,10 +210,9 @@ int update_graph_properties(Agraph_t * graph) //updates graph from gui for (id = 0; id < view->graphCount; id++) { if (graph != view->g[id]) { if (strcasecmp - (gtk_entry_get_text - ((GtkEntry *) + (gtk_entry_get_text ((GtkEntry *) glade_xml_get_widget(xml, "entryGraphName")), - ((custom_graph_data *) AGDATA(view->g[id]))->GraphName) == + GD_GraphName(view->g[id])) == 0) { Dlg = (GtkMessageDialog *) gtk_message_dialog_new(NULL, @@ -243,7 +233,7 @@ int update_graph_properties(Agraph_t * graph) //updates graph from gui if (strcasecmp (gtk_entry_get_text ((GtkEntry *) glade_xml_get_widget(xml, "entryGraphFileName")), - ((custom_graph_data *) AGDATA(graph))->GraphFileName) != 0) { + GD_GraphFileName(graph)) != 0) { if ((file = @@ -289,34 +279,31 @@ int update_graph_properties(Agraph_t * graph) //updates graph from gui //if it comes so far graph deserves new values - - - ((custom_graph_data *) AGDATA(graph))->GraphName = + GD_GraphName(graph) = (char *) gtk_entry_get_text((GtkEntry *) glade_xml_get_widget(xml, "entryGraphName")); - ((custom_graph_data *) AGDATA(graph))->GraphFileName = + GD_GraphFileName(graph) = (char *) gtk_entry_get_text((GtkEntry *) glade_xml_get_widget(xml, "entryGraphFileName")); - ((custom_graph_data *) AGDATA(graph))->AlwaysShow = + GD_AlwaysShow(graph) = gtk_toggle_button_get_active((GtkToggleButton *) glade_xml_get_widget(xml, "chkVisible")); - ((custom_graph_data *) AGDATA(graph))->Locked = + GD_Locked(graph) = gtk_toggle_button_get_active((GtkToggleButton *) glade_xml_get_widget(xml, "chkLocked")); - ((custom_graph_data *) AGDATA(graph))->TopView = + GD_TopView(graph) = gtk_toggle_button_get_active((GtkToggleButton *) glade_xml_get_widget(xml, "chkTopView")); //check if the engine has been changed, if so do new layout - if (((custom_graph_data *) AGDATA(graph))->Engine != - gtk_combo_box_get_active((GtkComboBox *) + if (GD_Engine(graph) != gtk_combo_box_get_active((GtkComboBox *) glade_xml_get_widget(xml, "cbLayout"))) { Dlg = (GtkMessageDialog *) gtk_message_dialog_new(NULL, @@ -365,13 +352,13 @@ int load_object_properties(int typeIndex, Agraph_t * g) //load from object to g switch (typeIndex) //typeindex 0 means new object { case 1: //graph sub graph (cluster) - obj = ((custom_graph_data *) AGDATA(g))->selectedGraphs[0]; + obj = GD_selectedGraphs(g)[0]; break; case 2: //Node - obj = ((custom_graph_data *) AGDATA(g))->selectedNodes[0]; + obj = GD_selectedNodes(g)[0]; break; case 3: //Edge - obj = ((custom_graph_data *) AGDATA(g))->selectedEdges[0]; + obj = GD_selectedEdges(g)[0]; break; } for (widgetcounter = 0; widgetcounter < MAXIMUM_WIDGET_COUNT; @@ -477,10 +464,10 @@ int load_object_properties(int typeIndex, Agraph_t * g) //load from object to g //first part, common attributes - sprintf(buf, "%i", ((custom_object_data *) AGDATA(obj))->ID); + sprintf(buf, "%i", OD_ID(obj)); gtk_entry_set_text((GtkEntry *) glade_xml_get_widget(xml, "objEntryName"), - ((custom_object_data *) AGDATA(obj))->ObjName); + OD_ObjName(obj)); gtk_entry_set_text((GtkEntry *) glade_xml_get_widget(xml, "objEntryLabel"), agnameof(obj)); @@ -488,27 +475,19 @@ int load_object_properties(int typeIndex, Agraph_t * g) //load from object to g gtk_toggle_button_set_active((GtkToggleButton *) glade_xml_get_widget(xml, "frmObjectchkVisible"), - ((custom_object_data *) AGDATA(obj))-> - Visible); + OD_Visible(obj)); gtk_toggle_button_set_active((GtkToggleButton *) glade_xml_get_widget(xml, "frmObjectchkLocked"), - ((custom_object_data *) AGDATA(obj))-> - Locked); + OD_Locked(obj)); gtk_toggle_button_set_active((GtkToggleButton *) glade_xml_get_widget(xml, "frmObjectchkHighlighted"), - ((custom_object_data *) AGDATA(obj))-> - Highlighted); + OD_Highlighted(obj)); //get the position info // show only one item is selected - if (((((custom_graph_data *) AGDATA(g))->selectedNodesCount == 1) - && (typeIndex == 2)) - || ((((custom_graph_data *) AGDATA(g))->selectedEdgesCount == 1) - && (typeIndex == 3)) - || ((((custom_graph_data *) AGDATA(g))->selectedGraphsCount == 1) - && (typeIndex == 3)) - - ) { + if (((GD_selectedNodesCount(g) == 1) && (typeIndex == 2)) + || ((GD_selectedEdgesCount(g) == 1) && (typeIndex == 3)) + || ((GD_selectedGraphsCount(g) == 1) && (typeIndex == 3))) { sprintf(line, "%s", agget(obj, "pos")); a = (float) atof(strtok(line, ",")); b = (float) atof(strtok(NULL, ",")); @@ -620,11 +599,8 @@ void change_selected_graph_attributes(Agraph_t * g, char *attrname, int ind = 0; agattr(g, AGRAPH, attrname, ""); - for (ind = 0; - ind < ((custom_graph_data *) AGDATA(g))->selectedGraphsCount; - ind++) { - agset(((custom_graph_data *) AGDATA(g))->selectedGraphs[ind], - attrname, attrvalue); + for (ind = 0; ind < GD_selectedGraphsCount(g); ind++) { + agset(GD_selectedGraphs(g)[ind], attrname, attrvalue); } @@ -634,11 +610,9 @@ void change_selected_node_attributes(Agraph_t * g, char *attrname, { int ind = 0; agattr(g, AGNODE, attrname, ""); - for (ind = 0; - ind < ((custom_graph_data *) AGDATA(g))->selectedNodesCount; - ind++) { - agset(((custom_graph_data *) AGDATA(g))->selectedNodes[ind], - attrname, attrvalue); + + for (ind = 0; ind < GD_selectedNodesCount(g); ind++) { + agset(GD_selectedNodes(g)[ind], attrname, attrvalue); } } void change_selected_edge_attributes(Agraph_t * g, char *attrname, @@ -646,11 +620,9 @@ void change_selected_edge_attributes(Agraph_t * g, char *attrname, { int ind = 0; agattr(g, AGEDGE, attrname, ""); - for (ind = 0; - ind < ((custom_graph_data *) AGDATA(g))->selectedEdgesCount; - ind++) { - agset(((custom_graph_data *) AGDATA(g))->selectedEdges[ind], - attrname, attrvalue); + + for (ind = 0; ind < GD_selectedEdgesCount(g); ind++) { + agset(GD_selectedEdges(g)[ind], attrname, attrvalue); } } @@ -730,9 +702,8 @@ void load_attributes() break; default: attr[attrcount].ComboValues = - realloc(attr[attrcount].ComboValues, - sizeof(char **) * - attr[attrcount].ComboValuesCount); + RALLOC(attr[attrcount].ComboValuesCount, + attr[attrcount].ComboValues, char*); attr[attrcount].ComboValues[attr[attrcount]. ComboValuesCount] = strdup(ss); @@ -745,3 +716,4 @@ void load_attributes() } } } + diff --git a/cmd/smyrna/gui/menucallbacks.c b/cmd/smyrna/gui/menucallbacks.c index bb9dc8a37..9c96211df 100755 --- a/cmd/smyrna/gui/menucallbacks.c +++ b/cmd/smyrna/gui/menucallbacks.c @@ -74,18 +74,16 @@ void mQuitSlot(GtkWidget * widget, gpointer user_data) { //1 check all graphs 1 by 1 to see any unsaved int respond; - int gIndex = 0; + int gIndex; #ifdef UNUSED int active_graph = view->activeGraph; //stores the active graph in case quit aborted #endif - for (gIndex; gIndex < view->graphCount; gIndex++) { + for (gIndex = 0; gIndex < view->graphCount; gIndex++) { view->activeGraph = gIndex; - if (((custom_graph_data *) AGDATA(view->g[view->activeGraph]))-> - Modified) { + if (GD_Modified(view->g[view->activeGraph])) { sprintf(buf, "graph %s has been modified \n , would you like to save it before quitting the the program?", - ((custom_graph_data *) - AGDATA(view->g[view->activeGraph]))->GraphName); + GD_GraphName(view->g[view->activeGraph])); Dlg = (GtkMessageDialog *) gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, @@ -198,8 +196,7 @@ void mGraphPropertiesSlot(GtkWidget * widget, gpointer user_data) } void mClusterPropertiesSlot(GtkWidget * widget, gpointer user_data) { - if (((custom_graph_data *) AGDATA(view->g[view->activeGraph]))-> - selectedGraphsCount > 0) { + if (GD_selectedGraphsCount(view->g[view->activeGraph]) > 0) { gtk_widget_hide(glade_xml_get_widget(xml, "frmObject")); gtk_widget_show(glade_xml_get_widget(xml, "frmObject")); load_object_properties(1, view->g[view->activeGraph]); @@ -216,8 +213,7 @@ void mClusterPropertiesSlot(GtkWidget * widget, gpointer user_data) } void mNodePropertiesSlot(GtkWidget * widget, gpointer user_data) { - if (((custom_graph_data *) AGDATA(view->g[view->activeGraph]))-> - selectedNodesCount > 0) { + if (GD_selectedNodesCount(view->g[view->activeGraph]) > 0) { gtk_widget_hide(glade_xml_get_widget(xml, "frmObject")); gtk_widget_show(glade_xml_get_widget(xml, "frmObject")); load_object_properties(2, view->g[view->activeGraph]); @@ -234,8 +230,7 @@ void mNodePropertiesSlot(GtkWidget * widget, gpointer user_data) } void mEdgePropertiesSlot(GtkWidget * widget, gpointer user_data) { - if (((custom_graph_data *) AGDATA(view->g[view->activeGraph]))-> - selectedEdgesCount > 0) { + if (GD_selectedEdgesCount(view->g[view->activeGraph]) > 0) { gtk_widget_hide(glade_xml_get_widget(xml, "frmObject")); gtk_widget_show(glade_xml_get_widget(xml, "frmObject")); load_object_properties(3, view->g[view->activeGraph]); diff --git a/cmd/smyrna/gui/topviewsettings.c b/cmd/smyrna/gui/topviewsettings.c index 8efae1b76..75ec9afcd 100644 --- a/cmd/smyrna/gui/topviewsettings.c +++ b/cmd/smyrna/gui/topviewsettings.c @@ -15,9 +15,9 @@ #include "topviewsettings.h" #include "gui.h" -#include "color.h" - - +#include "colorprocs.h" +#include "viewport.h" +#include "memory.h" void on_settingsOKBtn_clicked(GtkWidget * widget, gpointer user_data) { @@ -61,7 +61,7 @@ static int get_color_button_widget_to_attribute(char *attribute, Agraph_t * g) { GdkColor color; - char *buf = malloc(256); + char *buf = N_GNEW(256,char); gtk_color_button_get_color((GtkColorButton *) glade_xml_get_widget(xml, widget_name), &color); diff --git a/cmd/smyrna/hier.c b/cmd/smyrna/hier.c index 8fe9f75c5..3524dc037 100644 --- a/cmd/smyrna/hier.c +++ b/cmd/smyrna/hier.c @@ -180,7 +180,7 @@ vtx_data *makeGraph(topview * tv, int *nedges) vp = (tp == np ? hp : tp); ne++; i_nedges++; - *edges++ = ((custom_object_data *) AGDATA(vp))->TVRef; + *edges++ = OD_TVRef(vp); } graph[i].nedges = i_nedges; diff --git a/cmd/smyrna/smyrnadefs.h b/cmd/smyrna/smyrnadefs.h index 48bfeba23..84db10475 100644 --- a/cmd/smyrna/smyrnadefs.h +++ b/cmd/smyrna/smyrnadefs.h @@ -223,9 +223,20 @@ typedef struct _custom_graph_data { int selectedEdgesCount; } custom_graph_data; -#define GD_Engine(g) (((custom_graph_data*)AGDATA(g))->Engine) -#define GD_GraphFileName(g) (((custom_graph_data*)AGDATA(g))->GraphFileName) -#define GD_Modified(g) (((custom_graph_data*)AGDATA(g))->Modified) +#define GD_data(g) ((custom_graph_data*)AGDATA(g)) +#define GD_TopView(g) (GD_data(g)->TopView) +#define GD_Engine(g) (GD_data(g)->Engine) +#define GD_GraphFileName(g) (GD_data(g)->GraphFileName) +#define GD_GraphName(g) (GD_data(g)->GraphName) +#define GD_AlwaysShow(g) (GD_data(g)->AlwaysShow) +#define GD_Locked(g) (GD_data(g)->Locked) +#define GD_Modified(g) (GD_data(g)->Modified) +#define GD_selectedGraphs(g) (GD_data(g)->selectedGraphs) +#define GD_selectedGraphsCount(g) (GD_data(g)->selectedGraphsCount) +#define GD_selectedNodesCount(g) (GD_data(g)->selectedNodesCount) +#define GD_selectedNodes(g) (GD_data(g)->selectedNodes) +#define GD_selectedEdgesCount(g) (GD_data(g)->selectedEdgesCount) +#define GD_selectedEdges(g) (GD_data(g)->selectedEdges) typedef enum { GEpixels, GEinches, GEmm } GEunit; @@ -251,10 +262,21 @@ typedef struct _custom_object_data //has to be attached to every Node, Edge, Gra } custom_object_data; -#define OD_id(p) (((custom_object_data*)AGDATA(p))->TVRef) +#define OD_ID(p) (((custom_object_data*)AGDATA(p))->ID) +#define OD_ObjName(p) (((custom_object_data*)AGDATA(p))->ObjName) +#define OD_ObjType(p) (((custom_object_data*)AGDATA(p))->ObjType) +#define OD_Layer(p) (((custom_object_data*)AGDATA(p))->Layer) +#define OD_Visible(p) (((custom_object_data*)AGDATA(p))->Visible) +#define OD_Locked(p) (((custom_object_data*)AGDATA(p))->Locked) +#define OD_Highlighted(p) (((custom_object_data*)AGDATA(p))->Highlighted) +#define OD_NumDataCount(p) (((custom_object_data*)AGDATA(p))->NumDataCount) +#define OD_NumData(p) (((custom_object_data*)AGDATA(p))->NumData) +#define OD_StrDataCount(p) (((custom_object_data*)AGDATA(p))->StrDataCount) +#define OD_StrData(p) (((custom_object_data*)AGDATA(p))->StrData) #define OD_Selected(p) (((custom_object_data*)AGDATA(p))->Selected) #define OD_Preselected(p) (((custom_object_data*)AGDATA(p))->Preselected) #define OD_SelFlag(p) (((custom_object_data*)AGDATA(p))->selectionflag) +#define OD_TVRef(p) (((custom_object_data*)AGDATA(p))->TVRef) typedef struct _selection { int Active; //0 there is no selection need to be applied diff --git a/cmd/smyrna/topviewdata.c b/cmd/smyrna/topviewdata.c index 946a96482..9cf57a057 100644 --- a/cmd/smyrna/topviewdata.c +++ b/cmd/smyrna/topviewdata.c @@ -14,17 +14,17 @@ **********************************************************/ #include "topviewdata.h" - +#include int prepare_nodes_for_groups(topview * t, topviewdata * td, int groupindex) { GdkColor color; - int i = 0; + int i; int count = 0; tv_node tvn; gtk_color_button_get_color(td->gtkhostcolor[0], &color); - for (i; i < t->Nodecount; i++) { + for (i = 0; i < t->Nodecount; i++) { tvn.index = i; if (validate_group_node(&tvn, td->hostregex[groupindex])) { count++; @@ -68,10 +68,9 @@ int load_host_buttons(topview * t, Agraph_t * g, glCompSet * s) // Graph [hostbtncaption1="AT&T",hostbtnregex1="*.ATT*",hostbtncolorR1="1",hostbtncolorG1="0",hostbtncolorB1="0",hostbtncolorA1="1"]; - t->TopviewData->hostregex = malloc(sizeof(char **) * btncount); - t->TopviewData->gtkhostbtn = malloc(sizeof(GtkButton *) * btncount); - t->TopviewData->gtkhostcolor = - malloc(sizeof(GtkColorButton *) * btncount); + t->TopviewData->hostregex = N_GNEW(btncount, char *); + t->TopviewData->gtkhostbtn = N_GNEW(btncount, GtkButton *); + t->TopviewData->gtkhostcolor = N_GNEW(btncount, GtkColorButton *); t->TopviewData->gtkhostbtncount = btncount; if (btncount > 0) { p = glCompPanelNew(25, 75, 165, 400); @@ -112,8 +111,7 @@ int load_host_buttons(topview * t, Agraph_t * g, glCompSet * s) b->data = i; glCompSetAddButton(s, b); - t->TopviewData->gtkhostbtn[i] = - (GtkButton *) + t->TopviewData->gtkhostbtn[i] = (GtkButton *) gtk_button_new_with_label(agget(g, hostbtncaption)); g_signal_connect((gpointer) t->TopviewData->gtkhostbtn[i], "clicked", G_CALLBACK(host_button_clicked_Slot), diff --git a/cmd/smyrna/tvnodes.c b/cmd/smyrna/tvnodes.c index baf5184d2..51df2cf57 100755 --- a/cmd/smyrna/tvnodes.c +++ b/cmd/smyrna/tvnodes.c @@ -19,6 +19,8 @@ #include "btree.h" #include "viewport.h" #include "selection.h" +#include "memory.h" + tv_nodes TV_Nodes; static char buf[255]; int MP_Flag = 0; @@ -42,7 +44,7 @@ static tv_filter *create_tv_filter() { tv_filter *f; - f = (tv_filter *) malloc(sizeof(tv_filter)); + f = NEW(tv_filter); clear_tv_filter(f); return f; } @@ -105,8 +107,7 @@ int reverse_selection() { int i = 0; for (i; i < view->Topview->Nodecount; i++) { - if (((custom_object_data *) AGDATA(view->Topview->Nodes[i].Node))-> - Selected) + if (OD_Selected(view->Topview->Nodes[i].Node)) deselect_node(view->g[view->activeGraph], view->Topview->Nodes[i].Node); else @@ -114,8 +115,7 @@ int reverse_selection() view->Topview->Nodes[i].Node); } for (i = 0; i < view->Topview->Edgecount; i++) { - if (((custom_object_data *) AGDATA(view->Topview->Edges[i].Edge))-> - Selected) + if (OD_Selected(view->Topview->Edges[i].Edge)) deselect_edge(view->g[view->activeGraph], view->Topview->Edges[i].Edge); else @@ -182,23 +182,20 @@ int validate_node(tv_node * TV_Node) valid = evaluate_expresions(TV_Node, n); //if show only highlighted if (TV_Nodes.filter.highlighted >= 0) { - if (((custom_object_data *) - AGDATA(view->Topview->Nodes[TV_Node->index].Node))-> - Highlighted != TV_Nodes.filter.highlighted) + if (OD_Highlighted(view->Topview->Nodes[TV_Node->index].Node) + != TV_Nodes.filter.highlighted) valid = 0; } //if show only visibles if (TV_Nodes.filter.visible >= 0) { - if (((custom_object_data *) - AGDATA(view->Topview->Nodes[TV_Node->index].Node))-> - Visible != TV_Nodes.filter.visible) + if (OD_Visible(view->Topview->Nodes[TV_Node->index].Node) + != TV_Nodes.filter.visible) valid = 0; } //if show only selected if (TV_Nodes.filter.selected >= 0) { - if (((custom_object_data *) - AGDATA(view->Topview->Nodes[TV_Node->index].Node))-> - Selected != TV_Nodes.filter.selected) + if (OD_Selected(view->Topview->Nodes[TV_Node->index].Node) + != TV_Nodes.filter.selected) valid = 0; } return valid; @@ -227,10 +224,7 @@ static int update_node_gui_objects(tv_node * TV_Node) } gtk_widget_show((GtkWidget *) TV_Node->chkSelected); gtk_toggle_button_set_active((GtkToggleButton *) TV_Node->chkSelected, - ((custom_object_data *) - AGDATA(view->Topview-> - Nodes[TV_Node->index].Node))-> - Selected); + OD_Selected(view->Topview-> Nodes[TV_Node->index].Node)); //Id Label if (!TV_Node->IDLabel) { @@ -251,10 +245,7 @@ static int update_node_gui_objects(tv_node * TV_Node) gtk_widget_show((GtkWidget *) TV_Node->chkVisible); gtk_toggle_button_set_active((GtkToggleButton *) TV_Node->chkVisible, - ((custom_object_data *) - AGDATA(view->Topview-> - Nodes[TV_Node->index].Node))-> - Visible); + OD_Visible(view->Topview->Nodes[TV_Node->index].Node)); //highlighted if (!TV_Node->chkHighlighted) { TV_Node->chkHighlighted = @@ -263,12 +254,8 @@ static int update_node_gui_objects(tv_node * TV_Node) LOCATION_X_CHKHIGHLIGHTED, TV_Nodes.Y); } gtk_widget_show((GtkWidget *) TV_Node->chkHighlighted); - gtk_toggle_button_set_active((GtkToggleButton *) TV_Node-> - chkHighlighted, - ((custom_object_data *) - AGDATA(view->Topview-> - Nodes[TV_Node->index].Node))-> - Highlighted); + gtk_toggle_button_set_active((GtkToggleButton*)TV_Node-> chkHighlighted, + OD_Highlighted(view->Topview->Nodes[TV_Node->index].Node)); //DATA 1 @@ -426,18 +413,15 @@ int reset_page_History() }*/ TV_Nodes.page_history_count = 0; TV_Nodes.page_history = - realloc(TV_Nodes.page_history, - sizeof(int) * TV_Nodes.page_history_count); + RALLOC(TV_Nodes.page_history_count, TV_Nodes.page_history, int); return 1; - - } + static int push_to_page_history(int index) { TV_Nodes.page_history_count++; TV_Nodes.page_history = - realloc(TV_Nodes.page_history, - sizeof(int) * TV_Nodes.page_history_count); + RALLOC(TV_Nodes.page_history_count, TV_Nodes.page_history, int); TV_Nodes.page_history[TV_Nodes.page_history_count - 1] = index; return 1; } @@ -451,8 +435,7 @@ static int pop_from_page_history() TV_Nodes.page_history[TV_Nodes.page_history_count - 1]; TV_Nodes.page_history_count--; TV_Nodes.page_history = - realloc(TV_Nodes.page_history, - sizeof(int) * TV_Nodes.page_history_count); + RALLOC(TV_Nodes.page_history_count, TV_Nodes.page_history, int); return return_value; } return 0; @@ -496,7 +479,7 @@ int prepare_page_history() { GtkLabel *lblTVPage; GtkSpinButton *spn; - int i = 0; + int i; int count = 0; tv_node tvn; TV_Nodes.pagecount = 0; @@ -504,7 +487,7 @@ int prepare_page_history() reset_page_History(); push_to_page_history(0); - for (i; i < view->Topview->Nodecount; i++) { + for (i = 0; i < view->Topview->Nodecount; i++) { tvn.index = i; if (validate_node(&tvn)) { count++; @@ -532,7 +515,7 @@ int prepare_page_history() int update_TV_data_from_gui() { - int i = 0; + int i; int index = 0; char *data_attr1; char *data_attr2; @@ -540,56 +523,37 @@ int update_TV_data_from_gui() data_attr1 = agget(view->g[view->activeGraph], "DataAttribute1"); data_attr2 = agget(view->g[view->activeGraph], "DataAttribute2"); - for (i; i < TV_Nodes.recordperpage; i++) { + for (i = 0; i < TV_Nodes.recordperpage; i++) { index = TV_Nodes.TV_Node[i].index; if (index < view->Topview->Nodecount) { // apply if selected if (gtk_toggle_button_get_active ((GtkToggleButton *) TV_Nodes.TV_Node[i].chkSelected)) { - if (! - ((custom_object_data *) - AGDATA(view->Topview->Nodes[index].Node))->Selected) + if (!OD_Selected(view->Topview->Nodes[index].Node)) select_node(view->g[view->activeGraph], view->Topview->Nodes[index].Node); } else { - if (((custom_object_data *) - AGDATA(view->Topview->Nodes[index].Node))->Selected) + if (OD_Selected(view->Topview->Nodes[index].Node)) deselect_node(view->g[view->activeGraph], view->Topview->Nodes[index].Node); } // apply if Visible if (gtk_toggle_button_get_active ((GtkToggleButton *) TV_Nodes.TV_Node[i].chkVisible)) { - if (! - ((custom_object_data *) - AGDATA(view->Topview->Nodes[index].Node))->Visible) - ((custom_object_data *) - AGDATA(view->Topview->Nodes[index].Node))->Visible = - 1; + if (!OD_Visible(view->Topview->Nodes[index].Node)) + OD_Visible(view->Topview->Nodes[index].Node) = 1; } else { - if (((custom_object_data *) - AGDATA(view->Topview->Nodes[index].Node))->Visible) - ((custom_object_data *) - AGDATA(view->Topview->Nodes[index].Node))->Visible = - 0; + if (OD_Visible(view->Topview->Nodes[index].Node)) + OD_Visible(view->Topview->Nodes[index].Node) = 0; } // apply if Highlighted if (gtk_toggle_button_get_active ((GtkToggleButton *) TV_Nodes.TV_Node[i].chkHighlighted)) { - if (! - ((custom_object_data *) - AGDATA(view->Topview->Nodes[index].Node))-> - Highlighted) - ((custom_object_data *) - AGDATA(view->Topview->Nodes[index].Node))-> - Highlighted = 1; + if (!OD_Highlighted(view->Topview->Nodes[index].Node)) + OD_Highlighted(view->Topview->Nodes[index].Node) = 1; } else { - if (((custom_object_data *) - AGDATA(view->Topview->Nodes[index].Node))-> - Highlighted) - ((custom_object_data *) - AGDATA(view->Topview->Nodes[index].Node))-> - Highlighted = 0; + if (OD_Highlighted(view->Topview->Nodes[index].Node)) + OD_Highlighted(view->Topview->Nodes[index].Node) = 0; } //Data1 agset((void *) view->Topview->Nodes[index].Node, data_attr1, @@ -671,8 +635,8 @@ int tv_select_all() { tv_node tvn; - int i = 0; - for (i; i < view->Topview->Nodecount; i++) { + int i; + for (i = 0; i < view->Topview->Nodecount; i++) { tvn.index = i; if (validate_node(&tvn)) { select_node(view->g[view->activeGraph], @@ -688,8 +652,8 @@ int tv_unselect_all() { tv_node tvn; - int i = 0; - for (i; i < view->Topview->Nodecount; i++) { + int i; + for (i = 0; i < view->Topview->Nodecount; i++) { tvn.index = i; if (validate_node(&tvn)) { deselect_node(view->g[view->activeGraph], @@ -704,12 +668,11 @@ int tv_unselect_all() int tv_highligh_all() { tv_node tvn; - int i = 0; - for (i; i < view->Topview->Nodecount; i++) { + int i; + for (i = 0; i < view->Topview->Nodecount; i++) { tvn.index = i; if (validate_node(&tvn)) { - ((custom_object_data *) AGDATA(view->Topview->Nodes[i].Node))-> - Highlighted = 1; + OD_Highlighted(view->Topview->Nodes[i].Node) = 1; } } apply_filter_from_gui(); @@ -721,12 +684,11 @@ int tv_highligh_all() int tv_unhighligh_all() { tv_node tvn; - int i = 0; - for (i; i < view->Topview->Nodecount; i++) { + int i; + for (i = 0; i < view->Topview->Nodecount; i++) { tvn.index = i; if (validate_node(&tvn)) { - ((custom_object_data *) AGDATA(view->Topview->Nodes[i].Node))-> - Highlighted = 0; + OD_Highlighted(view->Topview->Nodes[i].Node) = 0; } } apply_filter_from_gui(); @@ -737,12 +699,11 @@ int tv_unhighligh_all() int tv_show_all() { tv_node tvn; - int i = 0; - for (i; i < view->Topview->Nodecount; i++) { + int i; + for (i = 0; i < view->Topview->Nodecount; i++) { tvn.index = i; if (validate_node(&tvn)) { - ((custom_object_data *) AGDATA(view->Topview->Nodes[i].Node))-> - Visible = 1; + OD_Visible(view->Topview->Nodes[i].Node) = 1; } } apply_filter_from_gui(); @@ -755,12 +716,11 @@ int tv_show_all() int tv_hide_all() { tv_node tvn; - int i = 0; - for (i; i < view->Topview->Nodecount; i++) { + int i; + for (i = 0; i < view->Topview->Nodecount; i++) { tvn.index = i; if (validate_node(&tvn)) { - ((custom_object_data *) AGDATA(view->Topview->Nodes[i].Node))-> - Visible = 0; + OD_Visible(view->Topview->Nodes[i].Node) = 0; } } apply_filter_from_gui(); diff --git a/cmd/smyrna/viewport.c b/cmd/smyrna/viewport.c index a09a4e93a..a2553ae90 100755 --- a/cmd/smyrna/viewport.c +++ b/cmd/smyrna/viewport.c @@ -61,10 +61,9 @@ static char *get_attribute_value(char *attr, ViewInfo * view, Agraph_t * g) { char *buf; buf = agget(g, attr); - if ((!buf) || (strcmp(buf, "") == 0)) + if ((!buf) || (*buf == '\0')) buf = agget(view->default_attributes, attr); return buf; - } void @@ -337,7 +336,7 @@ void init_viewport(ViewInfo * view) view->Selection.SelectionColor.B = 1; view->Selection.SelectionColor.A = 1; view->Selection.Anti = 0; - view->Topview = malloc(sizeof(topview)); + view->Topview = GNEW(topview); view->Topview->topviewmenu = '\0'; view->cameras='\0';; view->camera_count=0; @@ -352,54 +351,48 @@ void init_viewport(ViewInfo * view) */ static void load_graph_params(Agraph_t * graph) { + char* s; //file may or may have not gl edit attributes //first defaults are set in loading function //here file is checked for previously saved gledit attributes - if (agget(graph, "GraphName")) //Graph Name + if ((s == agget(graph, "GraphName"))) //Graph Name { - ((custom_graph_data *) AGDATA(graph))->GraphName = - (char *) malloc((strlen(agget(graph, "GraphName")) + 1) * - sizeof(char)); - strcpy(((custom_graph_data *) AGDATA(graph))->GraphName, - agget(graph, "GraphName")); + GD_GraphName(graph) = N_GNEW(strlen(s)+1,char); + strcpy(GD_GraphName(graph), s); } - if (agget(graph, "AlwaysShow")) //Graph Name - ((custom_graph_data *) AGDATA(graph))->AlwaysShow = - atoi(agget(graph, "AlwaysShow")); + if ((s = agget(graph, "AlwaysShow"))) + GD_AlwaysShow(graph) = atoi(s); else - ((custom_graph_data *) AGDATA(graph))->AlwaysShow = 0; + GD_AlwaysShow(graph) = 0; - if (agget(graph, "TopView")) //Graph Name - ((custom_graph_data *) AGDATA(graph))->TopView = - atoi(agget(graph, "TopView")); + if ((s = agget(graph, "TopView"))) + GD_TopView(graph) = atoi(s); else - ((custom_graph_data *) AGDATA(graph))->TopView = 0; - if (agget(graph, "Locked")) //Graph Name - ((custom_graph_data *) AGDATA(graph))->Locked = - atoi(agget(graph, "Locked")); + GD_TopView(graph) = 0; + if ((s = agget(graph, "Locked"))) + GD_Locked(graph) = atoi(s); else - ((custom_graph_data *) AGDATA(graph))->Locked = 0; - if (agget(graph, "Engine")) //Graph Name - ((custom_graph_data *) AGDATA(graph))->Engine = - atoi(agget(graph, "Engine")); + GD_Locked(graph) = 0; + if ((s = agget(graph, "Engine"))) + GD_Engine(graph) = atoi(s); else - ((custom_graph_data *) AGDATA(graph))->Engine = 0; //DOT - - ((custom_graph_data *) AGDATA(graph))->Modified = 0; //not modified yet - ((custom_graph_data *) AGDATA(graph))->selectedEdges = '\0'; - ((custom_graph_data *) AGDATA(graph))->selectedNodes = '\0'; - ((custom_graph_data *) AGDATA(graph))->selectedGraphs = '\0'; + GD_Engine(graph) = 0; - ((custom_graph_data *) AGDATA(graph))->selectedNodesCount = 0; - ((custom_graph_data *) AGDATA(graph))->selectedEdgesCount = 0; - ((custom_graph_data *) AGDATA(graph))->selectedGraphsCount = 0; + GD_Modified(graph) = 0; //not modified yet + GD_selectedEdges(graph) = NULL; + GD_selectedNodes(graph) = NULL; + GD_selectedGraphs(graph) = NULL; + GD_selectedNodesCount(graph) = 0; + GD_selectedEdgesCount(graph) = 0; + GD_selectedGraphsCount(graph) = 0; - -/* if(agget((void*)g, "xdotversion")) //xdot exists - ((custom_graph_data*)AGDATA(g))->view->Topview=0; //need to check xdot version attribute - else //we dont know if it is view->Topview or simply a graph with no xdot, for testing i ll use view->Topview - ((custom_graph_data*)AGDATA(g))->view->Topview=1; */ +#if 0 + if((s = agget(graph, "xdotversion"))) + ((custom_graph_data*)AGDATA(g))->view->Topview=0; //need to check xdot version attribute + else //we dont know if it is view->Topview or simply a graph with no xdot, for testing i ll use view->Topview + ((custom_graph_data*)AGDATA(g))->view->Topview=1; +#endif } @@ -436,21 +429,16 @@ static int attach_object_custom_data_to_graph(Agraph_t * graph) static void update_graph_params(Agraph_t * graph) { char tempString[100]; - agattr(graph, AGRAPH, "GraphFileName", - ((custom_graph_data *) (AGDATA(graph)))->GraphFileName); - agattr(graph, AGRAPH, "GraphName", - ((custom_graph_data *) (AGDATA(graph)))->GraphName); - sprintf(tempString, "%i", - ((custom_graph_data *) (AGDATA(graph)))->AlwaysShow); + + agattr(graph, AGRAPH, "GraphFileName", GD_GraphFileName(graph)); + agattr(graph, AGRAPH, "GraphName", GD_GraphName(graph)); + sprintf(tempString, "%i", GD_AlwaysShow(graph)); agattr(graph, AGRAPH, "AlwaysShow", tempString); - sprintf(tempString, "%i", - ((custom_graph_data *) (AGDATA(graph)))->TopView); + sprintf(tempString, "%i", GD_TopView(graph)); agattr(graph, AGRAPH, "TopView", tempString); - sprintf(tempString, "%i", - ((custom_graph_data *) (AGDATA(graph)))->Locked); + sprintf(tempString, "%i", GD_Locked(graph)); agattr(graph, AGRAPH, "Locked", tempString); - sprintf(tempString, "%i", - ((custom_graph_data *) (AGDATA(graph)))->Engine); + sprintf(tempString, "%i", GD_Engine(graph)); agattr(graph, AGRAPH, "Engine", tempString); } @@ -732,9 +720,7 @@ void refreshControls(ViewInfo * v) widget = get_SelectGraph(); //load graph names to combobox for (i = 0; i < v->graphCount; i++) { - gtk_combo_box_append_text(widget, - ((custom_graph_data - *) (AGDATA(v->g[i])))->GraphFileName); + gtk_combo_box_append_text(widget, GD_GraphFileName(v->g[i])); } view->SignalBlock = 1; //HACK gtk_combo_box_set_active(widget, view->activeGraph); @@ -749,36 +735,24 @@ void refreshControls(ViewInfo * v) Color_Widget_bg("gray", glade_xml_get_widget(xml, "btnFdp")); - switch (((custom_graph_data *) (AGDATA(view->g[view->activeGraph])))-> - Engine) { - case 0: + switch (GD_Engine(view->g[view->activeGraph])) { + case GVK_DOT : Color_Widget_bg("red", glade_xml_get_widget(xml, "btnDot")); break; - - case 1: + case GVK_NEATO : Color_Widget_bg("red", glade_xml_get_widget(xml, "btnNeato")); break; - - case 2: + case GVK_TWOPI : Color_Widget_bg("red", glade_xml_get_widget(xml, "btnTwopi")); break; - - case 3: + case GVK_CIRCO : Color_Widget_bg("red", glade_xml_get_widget(xml, "btnCirco")); break; - - case 4: + case GVK_FDP : Color_Widget_bg("red", glade_xml_get_widget(xml, "btnFdp")); break; - - } glexpose(); - - - - - } /* save_graph_with_file_name: @@ -790,21 +764,20 @@ static int save_graph_with_file_name(Agraph_t * graph, char *fileName) update_graph_params(graph); if (fileName) output_file = fopen(fileName, "w"); + else if (GD_GraphFileName(graph)) + output_file = fopen(GD_GraphFileName(graph), "w"); else { - if (((custom_graph_data *) (AGDATA(graph)))->GraphFileName) - output_file = - fopen(((custom_graph_data *) (AGDATA(graph)))-> - GraphFileName, "w"); - else { - g_print("there is no file name to save! Programmer error\n"); - return 0; - } + g_print("there is no file name to save! Programmer error\n"); + return 0; } + if (output_file == NULL) { g_print("Cannot create file \n"); return 0; - } else if (agwrite(graph, (void *) output_file)) { - g_print("%s sucessfully saved \n", fileName); + } + + if (agwrite(graph, (void *) output_file)) { + g_print("%s successfully saved \n", fileName); return 1; } return 0; @@ -818,14 +791,10 @@ int save_graph() //check if there is an active graph if (view->activeGraph > -1) { //check if active graph has a file name - if (((custom_graph_data *) AGDATA(view->g[view->activeGraph]))-> - GraphFileName) { - return save_graph_with_file_name(view->g[view->activeGraph], - ((custom_graph_data *) - AGDATA(view-> - g[view-> - activeGraph]))-> - GraphFileName); + if (GD_GraphFileName(view->g[view->activeGraph])) { + return save_graph_with_file_name( + view->g[view->activeGraph], + GD_GraphFileName(view->g[view-> activeGraph])); } else return save_as_graph(); } @@ -967,17 +936,17 @@ static int init_object_custom_data(Agraph_t * graph, void *obj) { agdelrec(graph, "custom_object_data"); agbindrec(obj, "custom_object_data", sizeof(custom_object_data), TRUE); - ((custom_object_data *) AGDATA(obj))->ID = 0; - ((custom_object_data *) AGDATA(obj))->ObjName = NULL; - ((custom_object_data *) AGDATA(obj))->ObjType = AGTYPE(obj); - ((custom_object_data *) AGDATA(obj))->Layer = -1; - ((custom_object_data *) AGDATA(obj))->Visible = 1; - ((custom_object_data *) AGDATA(obj))->Locked = 0; - ((custom_object_data *) AGDATA(obj))->Highlighted = 0; - ((custom_object_data *) AGDATA(obj))->NumDataCount = 0; - ((custom_object_data *) AGDATA(obj))->NumData = NULL; - ((custom_object_data *) AGDATA(obj))->StrDataCount = 0; - ((custom_object_data *) AGDATA(obj))->StrData = NULL; + OD_ID(obj) = 0; + OD_ObjName(obj) = NULL; + OD_ObjType(obj) = AGTYPE(obj); + OD_Layer(obj) = -1; + OD_Visible(obj) = 1; + OD_Locked(obj) = 0; + OD_Highlighted(obj) = 0; + OD_NumDataCount(obj) = 0; + OD_NumData(obj) = NULL; + OD_StrDataCount(obj) = 0; + OD_StrData(obj) = NULL; return 1; } @@ -986,12 +955,10 @@ static int clear_string_data_from_object_custom_data(void *obj) { if (obj != NULL) { int ind = 0; - for (ind = 0; - ind < ((custom_object_data *) AGDATA(obj))->StrDataCount; - ind++) { - free(((custom_object_data *) AGDATA(obj))->StrData[ind]); + for (ind = 0; ind < OD_StrDataCount(obj); ind++) { + free(OD_StrData(obj)[ind]); } - free(((custom_object_data *) AGDATA(obj))->StrData); + free(OD_StrData(obj); return 1; } return 0; @@ -1003,7 +970,7 @@ static int clear_string_data_from_object_custom_data(void *obj) static int clear_numeric_data_from_object_custom_data(void *obj) { if (obj != NULL) { - free(((custom_object_data *) AGDATA(obj))->NumData); + free(OD_NumData(obj); return 1; } return 0; @@ -1018,18 +985,10 @@ static int clear_object_custom_data(void *obj) static int add_string_data_to_object_custom_data(void *obj, char *data) { if ((obj != NULL) && (data != NULL)) { - ((custom_object_data *) AGDATA(obj))->StrData = - realloc(((custom_object_data *) AGDATA(obj))->StrData, - sizeof(char *) * - (((custom_object_data *) AGDATA(obj))->StrDataCount + - 1)); - ((custom_object_data *) AGDATA(obj))-> - StrData[((custom_object_data *) AGDATA(obj))->StrDataCount] = - malloc((strlen(data) + 1) * sizeof(char)); - strcpy(((custom_object_data *) AGDATA(obj))-> - StrData[((custom_object_data *) AGDATA(obj))->StrDataCount], - data); - ((custom_object_data *) AGDATA(obj))->StrDataCount++; + OD_StrData(obj) = RALLOC(OD_StrDataCount(obj)+1,OD_StrData(obj), char*); + OD_StrData(obj)[OD_StrDataCount(obj)] = N_GNEW((strlen(data)+1), char); + strcpy(OD_StrData(obj)[OD_StrDataCount(obj)], data); + OD_StrDataCount(obj)++; return 1; } return 0; @@ -1038,15 +997,9 @@ static int add_string_data_to_object_custom_data(void *obj, char *data) int add_numeric_data_to_object_custom_data(void *obj, float data) { if (obj != NULL) { - ((custom_object_data *) AGDATA(obj))->NumData = - realloc(((custom_object_data *) AGDATA(obj))->StrData, - sizeof(char *) * - (((custom_object_data *) AGDATA(obj))->NumDataCount + - 1)); - ((custom_object_data *) AGDATA(obj))-> - NumData[((custom_object_data *) AGDATA(obj))->NumDataCount] = - data; - ((custom_object_data *) AGDATA(obj))->NumDataCount++; + OD_NumData(obj) = RALLOC(OD_NumDataCount(obj)+1,OD_NumData(obj), char*); + OD_NumData(obj)[OD_NumDataCount(obj)] = data; + OD_NumDataCount(obj)++; return 1; } return 0; @@ -1152,12 +1105,8 @@ static char *offset_spline(xdot * x, float dx, float dy, float headx, case xd_filled_bezier: case xd_unfilled_bezier: case xd_polyline: - if (((custom_object_data *) AGDATA((headn)->obj))->Selected == - 1) - &&((custom_object_data *) AGDATA((tailn)->obj))-> - Selected == 1)) { + if (OD_Selected((headn)->obj) && OD_Selected((tailn)->obj)) { for (j = 0; j < x->ops[i].u.polygon.cnt; j++) { - x->ops[i].u.polygon.pts[j].x = x->ops[i].u.polygon.pts[j].x + dx; x->ops[i].u.polygon.pts[j].y = @@ -1165,7 +1114,7 @@ static char *offset_spline(xdot * x, float dx, float dy, float headx, x->ops[i].u.polygon.pts[j].z = x->ops[i].u.polygon.pts[j].z + dz; } - } + } break; } } @@ -1186,12 +1135,9 @@ void move_nodes(Agraph_t * g) dx = view->GLx - view->GLx2; dy = view->GLy - view->GLy2; - if (((custom_graph_data *) AGDATA(view->g[view->activeGraph]))-> - TopView == 0) { - for (i = 0; - i < ((custom_graph_data *) AGDATA(g))->selectedNodesCount; - i++) { - obj = ((custom_graph_data *) AGDATA(g))->selectedNodes[i]; + if (GD_TopView(view->g[view->activeGraph]) == 0) { + for (i = 0; i < GD_selectedNodesCount(g); i++) { + obj = GD_selectedNodes(g)[i]; bf = parseXDot(agget(obj, "_draw_")); agset(obj, "_draw_", move_xdot(obj, bf, (int) dx, (int) dy, 0)); diff --git a/cmd/smyrna/viewportcamera.c b/cmd/smyrna/viewportcamera.c index 8044dd982..4d214b87b 100644 --- a/cmd/smyrna/viewportcamera.c +++ b/cmd/smyrna/viewportcamera.c @@ -1,138 +1,153 @@ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + #include "viewportcamera.h" #include "gui.h" #include "math.h" +#include "memory.h" -static viewport_camera* new_viewport_camera(ViewInfo * view) +static viewport_camera *new_viewport_camera(ViewInfo * view) { - viewport_camera* c=malloc(sizeof(viewport_camera)); - return c; + return NEW(viewport_camera); } -static void viewport_update_camera_indexes(ViewInfo* view) +static void viewport_update_camera_indexes(ViewInfo * view) { - int ind=0; - for(ind=0;ind < view->camera_count;ind ++) - { - view->cameras[ind]->index=ind; - } + int ind = 0; + for (ind = 0; ind < view->camera_count; ind++) { + view->cameras[ind]->index = ind; + } } -viewport_camera* add_camera_to_viewport(ViewInfo * view) +viewport_camera *add_camera_to_viewport(ViewInfo * view) { - view->camera_count++; - view->cameras=(viewport_camera**)realloc(view->cameras,sizeof(viewport_camera *)*view->camera_count); - view->cameras[view->camera_count-1]=new_viewport_camera(view); - view->active_camera=view->camera_count-1; - viewport_update_camera_indexes(view); - return view->cameras[view->camera_count-1]; + view->camera_count++; + view->cameras = + RALLOC(view->camera_count, view->cameras, viewport_camera *); + view->cameras[view->camera_count - 1] = new_viewport_camera(view); + view->active_camera = view->camera_count - 1; + viewport_update_camera_indexes(view); + return view->cameras[view->camera_count - 1]; } -void set_camera_x_y(viewport_camera* c) + +void set_camera_x_y(viewport_camera * c) { - c->x=c->r*cos((float)DEG2RAD*c->anglexy)*sin((float)DEG2RAD*c->anglexyz)+view->panx; - c->y=c->r*sin(DEG2RAD*c->anglexy)*sin(DEG2RAD*c->anglexyz)+view->pany; - c->z=c->r*cos(DEG2RAD*c->anglexyz); + c->x = + c->r * cos((float) DEG2RAD * c->anglexy) * sin((float) DEG2RAD * + c->anglexyz) + + view->panx; + c->y = + c->r * sin(DEG2RAD * c->anglexy) * sin(DEG2RAD * c->anglexyz) + + view->pany; + c->z = c->r * cos(DEG2RAD * c->anglexyz); } - - -int delete_camera_from_viewport(ViewInfo * view,viewport_camera* c) +int delete_camera_from_viewport(ViewInfo * view, viewport_camera * c) { - int ind = 0; + int ind; int found = 0; - for (ind; ind < view->camera_count ; ind++) - { - if ((view->cameras[ind] == c) && found == 0) - found = 1; - if ((found == 1)&&(ind < (view->camera_count-1))) - view->cameras[ind] =view->cameras[ind + 1]; + for (ind = 0; ind < view->camera_count; ind++) { + if ((view->cameras[ind] == c) && found == 0) + found = 1; + if ((found == 1) && (ind < (view->camera_count - 1))) + view->cameras[ind] = view->cameras[ind + 1]; } - if (found) - { - free(c); - view->camera_count--; - view->cameras = - realloc(view->cameras, sizeof(viewport_camera*) * view->camera_count); - viewport_update_camera_indexes(view); - view->active_camera--; - return 1; + if (found) { + free(c); + view->camera_count--; + view->cameras = + RALLOC(view->camera_count, view->cameras, viewport_camera *); + viewport_update_camera_indexes(view); + view->active_camera--; + return 1; } return 0; } -int activate_viewport_camera (ViewInfo * view,int cam_index) +int activate_viewport_camera(ViewInfo * view, int cam_index) { - if (cam_index < view->camera_count) - { - view->active_camera=cam_index; - return 1; - } - else - return 0; + if (cam_index < view->camera_count) { + view->active_camera = cam_index; + return 1; + } else + return 0; } -int refresh_viewport_camera (ViewInfo * view) + +int refresh_viewport_camera(ViewInfo * view) { - if(view->active_camera >=0) - { - + if (view->active_camera >= 0) { + /* view->panx=view->cameras[view->active_camera]->panx; view->pany=view->cameras[view->active_camera]->pany; view->panz=view->cameras[view->active_camera]->panz; view->zoom=view->cameras[view->active_camera]->zoom;*/ - return 1; - } - else - return 0; + return 1; + } else + return 0; } void menu_click_add_camera(void *p) { - viewport_camera* c; - /*add test cameras*/ - c=add_camera_to_viewport(view); - c->targetx=view->panx; - c->targety=view->pany; - c->targetz=view->panz; - c->x=view->panx; - c->y=view->pany; - c->z=view->zoom; - c->camera_vectorx=0; - c->camera_vectory=1; - c->camera_vectorz=0; - - c->anglexy=90; - c->anglexyz=0; - c->anglex=0; - c->angley=0; - - c->r=view->zoom*-1; -// set_camera_x_y(c); - attach_camera_widget(view); + viewport_camera *c; + /*add test cameras */ + c = add_camera_to_viewport(view); + c->targetx = view->panx; + c->targety = view->pany; + c->targetz = view->panz; + c->x = view->panx; + c->y = view->pany; + c->z = view->zoom; + c->camera_vectorx = 0; + c->camera_vectory = 1; + c->camera_vectorz = 0; + + c->anglexy = 90; + c->anglexyz = 0; + c->anglex = 0; + c->angley = 0; + + c->r = view->zoom * -1; +// set_camera_x_y(c); + attach_camera_widget(view); } -int blocksignal=0; -void menu_click_2d (void *p) +int blocksignal = 0; +void menu_click_2d(void *p) { - view->active_camera=-1; + view->active_camera = -1; } void menu_click_camera_select(void *p) { - view->active_camera=((glCompButton*)p)->data; + view->active_camera = ((glCompButton *) p)->data; } void menu_click_camera_remove(void *p) { - delete_camera_from_viewport(view,view->cameras[(int)((glCompButton*)p)->data]); - attach_camera_widget(view); + delete_camera_from_viewport(view, + view->cameras[(int) ((glCompButton *) p)-> + data]); + attach_camera_widget(view); } void menu_click_camera_edit(void *p) { - show_camera_settings(view->cameras - [(int)((glCompButton*)p)->data] - ); + show_camera_settings(view->cameras[(int) ((glCompButton *) p)->data] + ); } @@ -141,186 +156,220 @@ void attach_camera_widget(ViewInfo * view) #define PANEL_PADDING 5 #define CAMERA_BUTTON_HEIGHT 25 -#define CAMERA_BUTTON_WIDTH 75 +#define CAMERA_BUTTON_WIDTH 75 - int ind,ind2,x,y; - char* buf[256]; - glCompPanel *p; + int ind, ind2, x, y; + char buf[256]; + glCompPanel *p; glCompButton *b; - glCompLabel *l; glCompSet *s = view->Topview->topviewmenu; - int p_height; - /*first we need to get rid of the old menu*/ - for (ind=0;ind < s->panelcount; ind ++) - { - if (s->panels[ind]->data==3) - { - /*remove buttons in the panel*/ - for (ind2=0;ind2 < s->buttoncount;ind2++) - { - if(s->buttons[ind2]->panel==s->panels[ind]) - { - glCompSetRemoveButton(s,s->buttons[ind2]); - ind2--; - } - } - /*remove panel itself*/ - glCompSetRemovePanel(s,s->panels[ind]); - break; + int p_height; + /*first we need to get rid of the old menu */ + for (ind = 0; ind < s->panelcount; ind++) { + if (s->panels[ind]->data == 3) { + /*remove buttons in the panel */ + for (ind2 = 0; ind2 < s->buttoncount; ind2++) { + if (s->buttons[ind2]->panel == s->panels[ind]) { + glCompSetRemoveButton(s, s->buttons[ind2]); + ind2--; } + } + /*remove panel itself */ + glCompSetRemovePanel(s, s->panels[ind]); + break; } + } - /*calculate height of panel*/ - p_height=2*PANEL_PADDING+view->camera_count*(CAMERA_BUTTON_HEIGHT+PANEL_PADDING)+CAMERA_BUTTON_HEIGHT; + /*calculate height of panel */ + p_height = + 2 * PANEL_PADDING + view->camera_count * (CAMERA_BUTTON_HEIGHT + + PANEL_PADDING) + + CAMERA_BUTTON_HEIGHT; - /*container for camera buttons*/ - p = glCompPanelNew((GLfloat)25, (GLfloat)75, (GLfloat)4*PANEL_PADDING+3*CAMERA_BUTTON_WIDTH,(GLfloat)p_height); + /*container for camera buttons */ + p = glCompPanelNew((GLfloat) 25, (GLfloat) 75, + (GLfloat) 4 * PANEL_PADDING + + 3 * CAMERA_BUTTON_WIDTH, (GLfloat) p_height); p->data = 3; glCompSetAddPanel(s, p); - b = glCompButtonNew((GLfloat)PANEL_PADDING,(GLfloat)PANEL_PADDING, (GLfloat)CAMERA_BUTTON_WIDTH, (GLfloat)CAMERA_BUTTON_HEIGHT, "ADD", '\0', 0, 0); + b = glCompButtonNew((GLfloat) PANEL_PADDING, (GLfloat) PANEL_PADDING, + (GLfloat) CAMERA_BUTTON_WIDTH, + (GLfloat) CAMERA_BUTTON_HEIGHT, "ADD", '\0', 0, 0); b->panel = p; b->groupid = 0; b->customptr = view; glCompSetAddButton(s, b); b->callbackfunc = menu_click_add_camera; - b = glCompButtonNew((GLfloat)PANEL_PADDING*2+(GLfloat)CAMERA_BUTTON_WIDTH,(GLfloat)PANEL_PADDING, (GLfloat)CAMERA_BUTTON_WIDTH, (GLfloat)CAMERA_BUTTON_HEIGHT, "2D", '\0', 0, 0); + b = glCompButtonNew((GLfloat) PANEL_PADDING * 2 + + (GLfloat) CAMERA_BUTTON_WIDTH, + (GLfloat) PANEL_PADDING, + (GLfloat) CAMERA_BUTTON_WIDTH, + (GLfloat) CAMERA_BUTTON_HEIGHT, "2D", '\0', 0, 0); b->panel = p; - b->groupid = 4; //4 is assigned to all camera buttons + b->groupid = 4; //4 is assigned to all camera buttons b->customptr = view; glCompSetAddButton(s, b); b->callbackfunc = menu_click_2d; - for (ind=0;ind < view->camera_count;ind ++) - { - y=p->height-((GLfloat)PANEL_PADDING + ind*((GLfloat)CAMERA_BUTTON_HEIGHT+(GLfloat)PANEL_PADDING))-CAMERA_BUTTON_HEIGHT; - x=PANEL_PADDING; - sprintf(buf,"CAM%i",ind+1); - b = glCompButtonNew(x,y, (GLfloat)CAMERA_BUTTON_WIDTH, (GLfloat)CAMERA_BUTTON_HEIGHT, buf, '\0', 0, 0); - b->panel = p; - b->groupid = 4; //4 is assigned to all camera buttons - b->data=ind; //assign camera id to custom data to use single call back - b->customptr = view; - glCompSetAddButton(s, b); - b->callbackfunc = menu_click_camera_select; - - x=PANEL_PADDING*2+CAMERA_BUTTON_WIDTH; - b = glCompButtonNew(x,y, (GLfloat)CAMERA_BUTTON_WIDTH, (GLfloat)CAMERA_BUTTON_HEIGHT, "Remove", '\0', 0, 0); - b->panel = p; - b->groupid = 0; - b->data=ind; //assign camera id to custom data to use single call back - b->customptr = view; - glCompSetAddButton(s, b); - b->callbackfunc = menu_click_camera_remove; - - x=PANEL_PADDING*3+CAMERA_BUTTON_WIDTH*2; - b = glCompButtonNew((GLfloat)x,(GLfloat)y, (GLfloat)CAMERA_BUTTON_WIDTH, (GLfloat)CAMERA_BUTTON_HEIGHT, "Edit", '\0', 0, 0); - b->panel = p; - b->groupid = 0; - b->data=ind; //assign camera id to custom data to use single call back - b->customptr = view; - glCompSetAddButton(s, b); - b->callbackfunc = menu_click_camera_edit; - } + for (ind = 0; ind < view->camera_count; ind++) { + y = p->height - ((GLfloat) PANEL_PADDING + + ind * ((GLfloat) CAMERA_BUTTON_HEIGHT + + (GLfloat) PANEL_PADDING)) - + CAMERA_BUTTON_HEIGHT; + x = PANEL_PADDING; + sprintf(buf, "CAM%i", ind + 1); + b = glCompButtonNew(x, y, (GLfloat) CAMERA_BUTTON_WIDTH, + (GLfloat) CAMERA_BUTTON_HEIGHT, buf, '\0', 0, + 0); + b->panel = p; + b->groupid = 4; //4 is assigned to all camera buttons + b->data = ind; //assign camera id to custom data to use single call back + b->customptr = view; + glCompSetAddButton(s, b); + b->callbackfunc = menu_click_camera_select; + + x = PANEL_PADDING * 2 + CAMERA_BUTTON_WIDTH; + b = glCompButtonNew(x, y, (GLfloat) CAMERA_BUTTON_WIDTH, + (GLfloat) CAMERA_BUTTON_HEIGHT, "Remove", '\0', + 0, 0); + b->panel = p; + b->groupid = 0; + b->data = ind; //assign camera id to custom data to use single call back + b->customptr = view; + glCompSetAddButton(s, b); + b->callbackfunc = menu_click_camera_remove; + + x = PANEL_PADDING * 3 + CAMERA_BUTTON_WIDTH * 2; + b = glCompButtonNew((GLfloat) x, (GLfloat) y, + (GLfloat) CAMERA_BUTTON_WIDTH, + (GLfloat) CAMERA_BUTTON_HEIGHT, "Edit", '\0', + 0, 0); + b->panel = p; + b->groupid = 0; + b->data = ind; //assign camera id to custom data to use single call back + b->customptr = view; + glCompSetAddButton(s, b); + b->callbackfunc = menu_click_camera_edit; + } } -int show_camera_settings(viewport_camera* c) +int show_camera_settings(viewport_camera * c) { - char buf[50]; - sprintf(buf,"Camera:%i",c->index); - gtk_label_set_text((GtkLabel*)glade_xml_get_widget(xml,"dlgcameralabel1"),buf); - gtk_spin_button_set_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton1"), - c->x); - gtk_spin_button_set_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton2"), - c->y); - gtk_spin_button_set_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton3"), - c->z); - gtk_spin_button_set_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton4"), - c->targetx); - gtk_spin_button_set_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton5"), - c->targety); - gtk_spin_button_set_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton6"), - c->targetz); - - - gtk_spin_button_set_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton7"), - c->camera_vectorx*360.0); - gtk_spin_button_set_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton8"), - c->camera_vectory*360.0); - gtk_spin_button_set_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton9"), - c->camera_vectorz*360.0); - - - - - - gtk_widget_hide(glade_xml_get_widget(xml, "dlgCamera")); + char buf[50]; + sprintf(buf, "Camera:%i", c->index); + gtk_label_set_text((GtkLabel *) + glade_xml_get_widget(xml, "dlgcameralabel1"), buf); + gtk_spin_button_set_value((GtkSpinButton *) + glade_xml_get_widget(xml, + "dlgcameraspinbutton1"), + c->x); + gtk_spin_button_set_value((GtkSpinButton *) + glade_xml_get_widget(xml, + "dlgcameraspinbutton2"), + c->y); + gtk_spin_button_set_value((GtkSpinButton *) + glade_xml_get_widget(xml, + "dlgcameraspinbutton3"), + c->z); + gtk_spin_button_set_value((GtkSpinButton *) + glade_xml_get_widget(xml, + "dlgcameraspinbutton4"), + c->targetx); + gtk_spin_button_set_value((GtkSpinButton *) + glade_xml_get_widget(xml, + "dlgcameraspinbutton5"), + c->targety); + gtk_spin_button_set_value((GtkSpinButton *) + glade_xml_get_widget(xml, + "dlgcameraspinbutton6"), + c->targetz); + + + gtk_spin_button_set_value((GtkSpinButton *) + glade_xml_get_widget(xml, + "dlgcameraspinbutton7"), + c->camera_vectorx * 360.0); + gtk_spin_button_set_value((GtkSpinButton *) + glade_xml_get_widget(xml, + "dlgcameraspinbutton8"), + c->camera_vectory * 360.0); + gtk_spin_button_set_value((GtkSpinButton *) + glade_xml_get_widget(xml, + "dlgcameraspinbutton9"), + c->camera_vectorz * 360.0); + + + + + + gtk_widget_hide(glade_xml_get_widget(xml, "dlgCamera")); gtk_widget_show(glade_xml_get_widget(xml, "dlgCamera")); gtk_window_set_keep_above((GtkWindow *) glade_xml_get_widget(xml, "dlgCamera"), 1); - view->selected_camera=c; + view->selected_camera = c; return 1; } -int save_camera_settings(viewport_camera* c) + +int save_camera_settings(viewport_camera * c) { - float value; - c->x = (float) gtk_spin_button_get_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton1" )); - c->y = (float) gtk_spin_button_get_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton2" )); - c->z = (float) gtk_spin_button_get_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton3" )); - c->targetx = (float) gtk_spin_button_get_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton4" )); - c->targety = (float) gtk_spin_button_get_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton5" )); - c->targetz = (float) gtk_spin_button_get_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton6" )); - - c->camera_vectorx = (float) gtk_spin_button_get_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton7" ))/360; - c->camera_vectory = (float) gtk_spin_button_get_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton8" ))/360; - c->camera_vectorz = (float) gtk_spin_button_get_value((GtkSpinButton *) - glade_xml_get_widget(xml,"dlgcameraspinbutton9" ))/360; + c->x = (float) gtk_spin_button_get_value((GtkSpinButton *) + glade_xml_get_widget(xml, + "dlgcameraspinbutton1")); + c->y = (float) gtk_spin_button_get_value((GtkSpinButton *) + glade_xml_get_widget(xml, + "dlgcameraspinbutton2")); + c->z = (float) gtk_spin_button_get_value((GtkSpinButton *) + glade_xml_get_widget(xml, + "dlgcameraspinbutton3")); + c->targetx = (float) gtk_spin_button_get_value((GtkSpinButton *) + glade_xml_get_widget + (xml, + "dlgcameraspinbutton4")); + c->targety = (float) gtk_spin_button_get_value((GtkSpinButton *) + glade_xml_get_widget + (xml, + "dlgcameraspinbutton5")); + c->targetz = (float) gtk_spin_button_get_value((GtkSpinButton *) + glade_xml_get_widget + (xml, + "dlgcameraspinbutton6")); + + c->camera_vectorx = (float) gtk_spin_button_get_value((GtkSpinButton *) + glade_xml_get_widget + (xml, + "dlgcameraspinbutton7")) + / 360; + c->camera_vectory = (float) gtk_spin_button_get_value((GtkSpinButton *) + glade_xml_get_widget + (xml, + "dlgcameraspinbutton8")) + / 360; + c->camera_vectorz = (float) gtk_spin_button_get_value((GtkSpinButton *) + glade_xml_get_widget + (xml, + "dlgcameraspinbutton9")) + / 360; - return 1; + return 1; } -void dlgcameraokbutton_clicked_cb -(GtkWidget * widget, gpointer user_data) -{ - gtk_widget_hide(glade_xml_get_widget(xml, "dlgCamera")); - save_camera_settings(view->selected_camera) ; +void dlgcameraokbutton_clicked_cb(GtkWidget * widget, gpointer user_data) { + gtk_widget_hide(glade_xml_get_widget(xml, "dlgCamera")); + save_camera_settings(view->selected_camera); } void dlgcameracancelbutton_clicked_cb -(GtkWidget * widget, gpointer user_data) -{ - gtk_widget_hide(glade_xml_get_widget(xml, "dlgCamera")); + (GtkWidget * widget, gpointer user_data) { + gtk_widget_hide(glade_xml_get_widget(xml, "dlgCamera")); } - - - - - - -- 2.40.0