From e23bcdb7158352619139eadae30ed446b033087d Mon Sep 17 00:00:00 2001 From: arif Date: Wed, 3 Mar 2010 23:35:19 +0000 Subject: [PATCH] nodes and edges can be selected seperately --- cmd/smyrna/glexpose.c | 2 +- cmd/smyrna/gltemplate.c | 2 +- cmd/smyrna/gui/appmouse.c | 4 ++-- cmd/smyrna/gui/glcompui.c | 28 ++++++++++++++++++++++++- cmd/smyrna/selectionfuncs.c | 22 ++++++++++++-------- cmd/smyrna/smyrnadefs.h | 41 +++++++------------------------------ cmd/smyrna/topviewfuncs.c | 8 ++++++-- lib/glcomp/glcompbutton.c | 12 ++++++++--- lib/glcomp/glcompdefs.h | 1 + lib/glcomp/glcompfont.c | 24 +++++++++++++++++++--- 10 files changed, 88 insertions(+), 56 deletions(-) diff --git a/cmd/smyrna/glexpose.c b/cmd/smyrna/glexpose.c index e35fa2082..b715db208 100644 --- a/cmd/smyrna/glexpose.c +++ b/cmd/smyrna/glexpose.c @@ -181,7 +181,7 @@ int glexpose_main(ViewInfo * view) // drawRotatingTools(); // draw_cube(); drawRotatingAxis(); - draw_selpoly(&view->Topview->selPoly); + draw_selpoly(&view->Topview->sel.selPoly); // draw_stuff(); // test_color_pallete(); // drawtestpoly(); diff --git a/cmd/smyrna/gltemplate.c b/cmd/smyrna/gltemplate.c index 33ecc7943..c3e9d4c01 100755 --- a/cmd/smyrna/gltemplate.c +++ b/cmd/smyrna/gltemplate.c @@ -397,7 +397,7 @@ static gboolean motion_notify_event(GtkWidget * widget, appmouse_middle_drag(view,(int)event->x,(int)event->y); redraw = TRUE; } - if(view->Topview->selPoly.cnt > 0) + if(view->Topview->sel.selPoly.cnt > 0) redraw=TRUE; diff --git a/cmd/smyrna/gui/appmouse.c b/cmd/smyrna/gui/appmouse.c index 6d12a14b1..4e686449c 100644 --- a/cmd/smyrna/gui/appmouse.c +++ b/cmd/smyrna/gui/appmouse.c @@ -65,7 +65,7 @@ static void apply_actions(ViewInfo* v,int x,int y) if(a==MM_POLYGON_SELECT) { - add_selpoly(view->g[view->activeGraph],&view->Topview->selPoly,view->mouse.GLfinalPos); + add_selpoly(view->g[view->activeGraph],&view->Topview->sel.selPoly,view->mouse.GLfinalPos); } @@ -231,7 +231,7 @@ void appmouse_key_release(ViewInfo* v,int key) int action=get_key_action(v,key); if(lastAction==MM_POLYGON_SELECT) { - clear_selpoly(&view->Topview->selPoly); + clear_selpoly(&view->Topview->sel.selPoly); glexpose(); } v->keymap.down=0; diff --git a/cmd/smyrna/gui/glcompui.c b/cmd/smyrna/gui/glcompui.c index 5e795621b..e6fc26236 100644 --- a/cmd/smyrna/gui/glcompui.c +++ b/cmd/smyrna/gui/glcompui.c @@ -183,6 +183,22 @@ void glCompMouseMove(glCompObj *obj, GLfloat x, GLfloat y) glexpose(); } } +void selectedges(glCompObj *obj, GLfloat x, GLfloat y) +{ + if(view->Topview->sel.selectEdges==0) + view->Topview->sel.selectEdges=1; + else + view->Topview->sel.selectEdges=0; + +} +void selectnodes(glCompObj *obj, GLfloat x, GLfloat y) +{ + if(view->Topview->sel.selectNodes==0) + view->Topview->sel.selectNodes=1; + else + view->Topview->sel.selectNodes=0; + +} glCompSet *glcreate_gl_topview_menu(void) @@ -239,6 +255,16 @@ glCompSet *glcreate_gl_topview_menu(void) glCompButtonHide(b); to2DBtn = b; + y=y+off; + b = glCompButtonNew((glCompObj *) p, 1, y, 42, 42, "N"); + b->common.callbacks.click = selectnodes; + b->groupid=-1; + b->status=1; + + y=y+off; + b = glCompButtonNew((glCompObj *) p, 1, y, 42, 42, "E"); + b->common.callbacks.click = selectedges; + b->groupid=-1; @@ -317,7 +343,7 @@ glCompSet *glcreate_gl_topview_menu(void) - p = glCompPanelNew((glCompObj *) p, 25, 0, 52, 110); + p = glCompPanelNew((glCompObj *) p, 25, 0, 52, 110); p->common.align = glAlignTop; p->common.data = 0; p->common.color.A = 0; diff --git a/cmd/smyrna/selectionfuncs.c b/cmd/smyrna/selectionfuncs.c index 75e751083..eab6e4b35 100644 --- a/cmd/smyrna/selectionfuncs.c +++ b/cmd/smyrna/selectionfuncs.c @@ -88,17 +88,21 @@ static void pick_objects_in_rect(Agraph_t* g,GLfloat x1,GLfloat y1,GLfloat x2,GL for (v = agfstnode(g); v; v = agnxtnode(g, v)) { - posN=((nodeRec*)(aggetrec(v,"nodeRec",0)))->A; - if(is_point_in_rectangle(posN.x,posN.y,x1,y1,x2-x1,y2-y1)) - select_node(g,v,0); - for (e = agfstout(g, v); e; e = agnxtout(g, e)) + if(view->Topview->sel.selectNodes==1) { - posT=((edgeRec*)(aggetrec(e,"edgeRec",0)))->posTail; - posH=((edgeRec*)(aggetrec(e,"edgeRec",0)))->posHead; - if(is_point_in_rectangle(posT.x,posT.y,x1,y1,x2-x1,y2-y1)) - if(is_point_in_rectangle(posH.x,posH.y,x1,y1,x2-x1,y2-y1)) - select_edge(g,e,0); + posN=((nodeRec*)(aggetrec(v,"nodeRec",0)))->A; + if(is_point_in_rectangle(posN.x,posN.y,x1,y1,x2-x1,y2-y1)) + select_node(g,v,0); } + if(view->Topview->sel.selectEdges==1) + for (e = agfstout(g, v); e; e = agnxtout(g, e)) + { + posT=((edgeRec*)(aggetrec(e,"edgeRec",0)))->posTail; + posH=((edgeRec*)(aggetrec(e,"edgeRec",0)))->posHead; + if(is_point_in_rectangle(posT.x,posT.y,x1,y1,x2-x1,y2-y1)) + if(is_point_in_rectangle(posH.x,posH.y,x1,y1,x2-x1,y2-y1)) + select_edge(g,e,0); + } } } diff --git a/cmd/smyrna/smyrnadefs.h b/cmd/smyrna/smyrnadefs.h index 32547d32b..6f9f05816 100644 --- a/cmd/smyrna/smyrnadefs.h +++ b/cmd/smyrna/smyrnadefs.h @@ -295,22 +295,6 @@ typedef struct int TVref; //topview data structure reference } temp_node_record; -/*#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) (p->data.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)*/ - #define OD_Visible(p) (p.data.Visible) #define OD_Locked(p) (p.data.Locked) #define OD_Highlighted(p) (p.data.Highlighted) @@ -417,6 +401,11 @@ typedef struct int printLabel; }edgeRec; + typedef struct _selection { + glCompPoly selPoly; + int selectNodes; + int selectEdges; + } selection; typedef struct { topview_node *Nodes; @@ -457,10 +446,8 @@ typedef struct topviewcache cache; int xdotId; - glCompPoly selPoly; - - - + selection sel; + } topview; @@ -503,20 +490,6 @@ typedef struct } attribute; -/* typedef struct _selection { - int Active; //0 there is no selection need to be applied - char Type; //0 single selection , 1 rectangle , 2 rectangleX - int PickingType; //0 normal, union,2 subtract 3 intersection - float X, Y, W, H; //selection boundries - int Anti; //subtract selections if 1 - int AlreadySelected; //for single selections to avoid selecting more than one object - glCompColor SelectionColor; - float node_distance; //to get the closest node , this value is updated for each node, distance between selection coords and node coords, smallest gets to be selected - topview_node *single_selected_node; //pointer to selected node in a single node/edge selection cycle,after each node loop this value is checked and if it is in the limits that node is selected or deselected - //before the node/edge loop this value is nulled - topview_edge *single_selected_edge; //pointer to selected/picked edge - - } selection;*/ typedef struct _magnifier { float x, y; float kts; //zoom X diff --git a/cmd/smyrna/topviewfuncs.c b/cmd/smyrna/topviewfuncs.c index 3fccd7d53..1c9bfdceb 100644 --- a/cmd/smyrna/topviewfuncs.c +++ b/cmd/smyrna/topviewfuncs.c @@ -646,8 +646,8 @@ void updateSmGraph(Agraph_t * g,topview* t) t->picked_edge_count = 0; t->picked_edges = '\0'; t->global_z=0; - t->selPoly.cnt=0; - t->selPoly.pts=NULL; + t->sel.selPoly.cnt=0; + t->sel.selPoly.pts=NULL; if(!t) return ; @@ -684,6 +684,7 @@ topview* initSmGraph(Agraph_t * g) { topview* rv=(topview*)malloc(sizeof(topview)); rv->maxnodedegree = 1; + /*create glcomp menu system */ view->widgets = glcreate_gl_topview_menu(); @@ -703,6 +704,9 @@ topview* initSmGraph(Agraph_t * g) rv->cache.selnode_id=-1; rv->cache.edge_id=-1; rv->cache.seledge_id=-1; + rv->sel.selectEdges=0; + rv->sel.selectNodes=1; + updateSmGraph(g,rv); return rv; } diff --git a/lib/glcomp/glcompbutton.c b/lib/glcomp/glcompbutton.c index 3a58d6ce9..f523ea1ea 100644 --- a/lib/glcomp/glcompbutton.c +++ b/lib/glcomp/glcompbutton.c @@ -154,16 +154,19 @@ void glCompButtonClick(glCompObj * o, GLfloat x, GLfloat y, glCompObj *obj; glCompSet *s = o->common.compset; int ind = 0; - if (p->groupid > 0) { + ((glCompButton *) o)->status=((glCompButton *) o)->refStatus ; + if (p->groupid > 0) + { for (; ind < s->objcnt; ind++) { obj = s->obj[ind]; - if (obj->objType == glButtonObj) { + if ((obj->objType == glButtonObj)&&(obj!=o)) { if (((glCompButton *) obj)->groupid == p->groupid) ((glCompButton *) obj)->status = 0; } } p->status = 1; - } else { + } + else { if (p->groupid == -1) { if (p->status == 0) p->status = 1; @@ -189,6 +192,8 @@ void glCompButtonMouseDown(glCompObj * obj, GLfloat x, GLfloat y, { /*Put your internal code here */ + + ((glCompButton *) obj)->refStatus = ((glCompButton *) obj)->status; ((glCompButton *) obj)->status = 1; if (((glCompButton *) obj)->common.callbacks.mousedown) ((glCompButton *) obj)->common.callbacks.mousedown(obj, x, y, t); @@ -219,6 +224,7 @@ void glCompButtonMouseUp(glCompObj * obj, GLfloat x, GLfloat y, glMouseButtonType t) { /*Put your internal code here */ + if (((glCompButton *) obj)->common.callbacks.mouseup) ((glCompButton *) obj)->common.callbacks.mouseup(obj, x, y, t); } diff --git a/lib/glcomp/glcompdefs.h b/lib/glcomp/glcompdefs.h index 16c145452..ce171b4d4 100644 --- a/lib/glcomp/glcompdefs.h +++ b/lib/glcomp/glcompdefs.h @@ -307,6 +307,7 @@ extern "C" { GLfloat width, height; glCompLabel *label; int status; //0 not pressed 1 pressed; + int refStatus; //0 not pressed 1 pressed; int groupid; glCompImage *image; /*glyph */ glCompButtonGlyph glyphPos; diff --git a/lib/glcomp/glcompfont.c b/lib/glcomp/glcompfont.c index 46d4fbb3d..17433cbdb 100644 --- a/lib/glcomp/glcompfont.c +++ b/lib/glcomp/glcompfont.c @@ -399,11 +399,28 @@ void glCompDrawText3D(glCompFont * f,GLfloat x,GLfloat y,GLfloat z,GLfloat w,GLf } /*bitmap base 2D text rendering */ +static void change_fontC(unsigned char* d,int w,int h,glCompColor* c) +{ + int size=w*h*4; + int ind=0; + for (ind;ind <=size; ind=ind+4) + { + if(d[ind+3] != 0) + { + d[ind]=c->R*255; + d[ind+1]=c->G*255; + d[ind+2]=c->B*255; + d[ind+3]=c->A*255; + } + } +} + + void glCompDrawText(glCompFont * f,GLfloat x,GLfloat y) { + change_fontC(f->tex->data,f->tex->width,f->tex->height,&f->color); glRasterPos2f(x, y); - glDrawPixels(f->tex->width, f->tex->height, GL_RGBA, GL_UNSIGNED_BYTE, - f->tex->data); + glDrawPixels(f->tex->width, f->tex->height, GL_RGBA, GL_UNSIGNED_BYTE, f->tex->data); } /*text rendering functions, depends on a globject to retrieve stats*/ @@ -419,7 +436,8 @@ void glCompRenderText(glCompFont * f, glCompObj * parentObj) h = f->tex->height; ref = parentObj->common; z = ref.pos.z; - switch (f->justify.HJustify) { + switch (f->justify.HJustify) + { case glFontHJustifyNone: case glFontHJustifyLeft: x = ref.refPos.x; -- 2.40.0