1
/* $Id: selection.c,v 1.3 2008/03/03 23:03:38 arif Exp $ $Revision: 1.3 $ */
2
/* vim:set shiftwidth=4 ts=8: */
4
/**********************************************************
5
* This software is part of the graphviz package *
6
* http://www.graphviz.org/ *
8
* Copyright (c) 1994-2004 AT&T Corp. *
9
* and is licensed under the *
10
* Common Public License, Version 1.0 *
13
* Information and Software Systems Research *
14
* AT&T Research, Florham Park NJ *
15
**********************************************************/
17
#include "selection.h"
19
int rectintersects(float x,float y,float W,float H)
21
//returns 1 if rect is completely in the clip rect
23
//-1 if completely out
26
s[0]=( ((x >=view->Selection.X)&& (x <= (view->Selection.X + view->Selection.W) ))) ? 1:0;
27
s[1]=( (((x+W) >=view->Selection.X)&& ((x+W) <= (view->Selection.X + view->Selection.W) ))) ? 1:0;
29
s[2]=( ((y >=view->Selection.Y)&& (y <= (view->Selection.Y + view->Selection.H) ))) ? 1:0;
30
s[3]=( (((y+H) >=view->Selection.Y)&& ((y+H) <= (view->Selection.Y + view->Selection.H) ))) ? 1:0;
33
if (s[0] && s[1] && s[2] && s[3])
35
if (s[0] || s[1] || s[2] || s[3])
40
int lineintersects(float X1,float X2,float Y1,float Y2)
46
//RX,RY lower left corner of rectangle
47
//RW width of rectangle
48
//RH height of ractangle
49
//returns 1 if line segment is completely in the rect
51
//-1 if completely out
59
if((is_point_in_rectangle(X1,Y1,RX,RY,RW,RH)) && (is_point_in_rectangle(X2,Y2,RX,RY,RW,RH)))
61
if((is_point_in_rectangle(X1,Y1,RX,RY,RW,RH)) || (is_point_in_rectangle(X2,Y2,RX,RY,RW,RH)))
63
//to be absolute or not to be one
75
iter=RW/(float)SELECTION_SEGMENT_DIVIDER;
84
if ( !is_point_in_rectangle(x,y,RX,RY,RW,RH))
96
int is_point_in_rectangle(float X,float Y,float RX,float RY,float RW,float RH)
98
if ((X >= RX) && (X <= (RX+RW) ) && (Y >= RY) && (Y <= (RY+RH)))
106
int SelectBeziers(xdot_op* op)
108
if(!view->Selection.Active)
110
switch (view->Selection.Type)
113
if (view->Selection.AlreadySelected)
115
if( spline_x_rect(op))
117
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==0)
119
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
120
select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
121
view->Selection.AlreadySelected=1;
125
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=0;
126
deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
127
view->Selection.AlreadySelected=1;
132
// if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==1)
134
if( ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag != -1 ) && (spline_in_rect(op)) )
136
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=1;
137
// select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
138
view->Selection.AlreadySelected=1;
142
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=0;
143
// deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
144
view->Selection.AlreadySelected=1;
145
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag = -1;
149
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==1)
151
if(spline_x_rect(op))
153
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
154
select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
155
view->Selection.AlreadySelected=1;
165
int SelectPolygon(xdot_op* op)
168
if(!view->Selection.Active)
170
switch (view->Selection.Type)
173
if (view->Selection.AlreadySelected)
177
if ((point_within_polygon( op)) || (polygon_x_rect(op)))
180
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==0)
182
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
183
select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
184
view->Selection.AlreadySelected=1;
189
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=0;
190
deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
191
view->Selection.AlreadySelected=1;
197
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==1)
199
if( ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag != -1 ) && (polygon_in_rect(op)) )
201
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=1;
202
// select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
203
// view->Selection.AlreadySelected=1;
208
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=0;
209
// deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
210
view->Selection.AlreadySelected=1;
211
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag = -1;
217
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==1)
219
if(polygon_x_rect(op))
221
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
222
select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
223
view->Selection.AlreadySelected=1;
233
int SelectPolyline(xdot_op* op)
235
if(!view->Selection.Active)
237
switch (view->Selection.Type)
240
if (view->Selection.AlreadySelected)
244
if ( polyline_x_rect(op) )
247
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==0)
249
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
250
select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
251
view->Selection.AlreadySelected=1;
256
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=0;
257
deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
258
view->Selection.AlreadySelected=1;
264
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==1)
266
if( ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag != -1 ) && (polyline_in_rect(op)) )
268
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=1;
273
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=0;
274
view->Selection.AlreadySelected=1;
275
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag = -1;
281
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==1)
283
if(polyline_x_rect(op))
285
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
286
select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
287
view->Selection.AlreadySelected=1;
298
int SelectEllipse(xdot_op* op)
300
if(!view->Selection.Active)
302
switch (view->Selection.Type)
305
if (view->Selection.AlreadySelected)
308
if( point_within_ellipse(op))
310
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==0)
312
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
313
select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
314
view->Selection.AlreadySelected=1;
319
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=0;
320
deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
321
view->Selection.AlreadySelected=1;
325
else if( ellipse_x_rect(op))
328
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==0)
330
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
331
select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
332
view->Selection.AlreadySelected=1;
337
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=0;
338
deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
339
view->Selection.AlreadySelected=1;
345
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==1)
347
if( ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag != -1 ) && (ellipse_in_rect(op)) )
349
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=1;
350
view->Selection.AlreadySelected=1;
355
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=0;
356
view->Selection.AlreadySelected=1;
357
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag = -1;
362
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==1)
364
if(ellipse_x_rect(op))
366
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
367
select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
368
view->Selection.AlreadySelected=1;
379
int SelectText(xdot_op* op)
381
if(!view->Selection.Active)
383
switch (view->Selection.Type)
386
if (view->Selection.AlreadySelected)
391
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==0)
392
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
394
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=0;
398
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==1)
402
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
403
select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
404
view->Selection.AlreadySelected=1;
409
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==1)
413
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
414
select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
415
view->Selection.AlreadySelected=1;
425
int SelectImage(xdot_op* op)
427
if(!view->Selection.Active)
429
switch (view->Selection.Type)
432
if (view->Selection.AlreadySelected)
434
if( image_x_rect(op))
437
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==0)
439
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
440
select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
441
view->Selection.AlreadySelected=1;
444
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=0;
448
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==1)
450
if(image_in_rect(op))
451
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
454
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==1)
457
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
469
int spline_in_rect(xdot_op* op)
471
//JUST SEND ALL CONTROL POINTS IN 3D ARRAYS
477
for (i=0;i < op->u.bezier.cnt ; i= i + 1)
481
if(!within_bezier(tempX,tempY,tempZ,0))
483
tempX[0]=(float)op->u.bezier.pts[i-1].x;
484
tempY[0]=(float)op->u.bezier.pts[i-1].y;
485
tempZ[0]=(float)op->u.bezier.pts[i-1].z;
487
tempX[temp]=(float)op->u.bezier.pts[i].x;
488
tempY[temp]=(float)op->u.bezier.pts[i].y;
489
tempZ[temp]=(float)op->u.bezier.pts[i].z;
494
tempX[temp]=(float)op->u.bezier.pts[i].x;
495
tempY[temp]=(float)op->u.bezier.pts[i].y;
496
tempZ[temp]=(float)op->u.bezier.pts[i].z;
500
if(!within_bezier(tempX,tempY,tempZ,0))
505
int spline_x_rect(xdot_op* op)
507
//JUST SEND ALL CONTROL POINTS IN 3D ARRAYS
513
for (i=0;i < op->u.bezier.cnt ; i= i + 1)
517
if(within_bezier(tempX,tempY,tempZ,1))
519
tempX[0]=(float)op->u.bezier.pts[i-1].x;
520
tempY[0]=(float)op->u.bezier.pts[i-1].y;
521
tempZ[0]=(float)op->u.bezier.pts[i-1].z;
523
tempX[temp]=(float)op->u.bezier.pts[i].x;
524
tempY[temp]=(float)op->u.bezier.pts[i].y;
525
tempZ[temp]=(float)op->u.bezier.pts[i].z;
530
tempX[temp]=(float)op->u.bezier.pts[i].x;
531
tempY[temp]=(float)op->u.bezier.pts[i].y;
532
tempZ[temp]=(float)op->u.bezier.pts[i].z;
536
if(within_bezier(tempX,tempY,tempZ,1))
541
int polygon_in_rect(xdot_op* op)
544
for (ind=0;ind < op->u.polygon.cnt-1;ind ++)
546
if( lineintersects((float)op->u.polygon.pts[ind].x,(float)op->u.polygon.pts[ind+1].x,(float)op->u.polygon.pts[ind].y,(float)op->u.polygon.pts[ind+1].y)!=1)
551
int polygon_x_rect(xdot_op* op)
554
for (ind=0;ind < op->u.polygon.cnt-1;ind ++)
556
if( lineintersects((float)op->u.polygon.pts[ind].x,(float)op->u.polygon.pts[ind+1].x,(float)op->u.polygon.pts[ind].y,(float)op->u.polygon.pts[ind+1].y)>=0)
561
int polyline_in_rect(xdot_op* op)
564
for (ind=0;ind < op->u.polygon.cnt-1;ind ++)
566
if( lineintersects((float)op->u.polygon.pts[ind].x,(float)op->u.polygon.pts[ind+1].x,(float)op->u.polygon.pts[ind].y,(float)op->u.polygon.pts[ind+1].y)!=1)
571
int polyline_x_rect(xdot_op* op)
574
for (ind=0;ind < op->u.polygon.cnt-1;ind ++)
576
if( lineintersects((float)op->u.polygon.pts[ind].x,(float)op->u.polygon.pts[ind+1].x,(float)op->u.polygon.pts[ind].y,(float)op->u.polygon.pts[ind+1].y)>=1)
581
int text_in_rect(xdot_op* op)
583
if( rectintersects((float)op->u.text.x,(float)op->u.text.y,(float)op->u.text.x+op->u.text.width,(float)op->u.text.y+(float)op->u.text.size)==1 )
588
int text_x_rect(xdot_op* op)
590
if( rectintersects((float)op->u.text.x,(float)op->u.text.y,(float)op->u.text.x+op->u.text.width,(float)op->u.text.y+(float)op->u.text.size)>=1 )
595
int image_in_rect(xdot_op* op)
597
if( rectintersects((float)op->u.image.pos.x ,(float)op->u.image.pos.y,(float)op->u.image.pos.w,(float)op->u.image.pos.h)==1)
601
int image_x_rect(xdot_op* op)
603
if( rectintersects((float)op->u.image.pos.x ,(float)op->u.image.pos.y,(float)op->u.image.pos.w,(float)op->u.image.pos.h)>=0)
608
int within_bezier(GLfloat* xp,GLfloat* yp,GLfloat* zp,int isx)
610
double Ax = xp[0]; double Ay = yp[0]; double Az = zp[0];
611
double Bx = xp[1]; double By = yp[1]; double Bz = zp[1];
612
double Cx = xp[2]; double Cy = yp[2]; double Cz = zp[2];
613
double Dx = xp[3]; double Dy = yp[3]; double Dz = zp[3];
620
int i = 0;//loop index
626
for(i = 0; i <= 20; i++)
628
// Get a point on the curve
629
X = Ax*a*a*a + Bx*3*a*a*b + Cx*3*a*b*b + Dx*b*b*b;
630
Y = Ay*a*a*a + By*3*a*a*b + Cy*3*a*b*b + Dy*b*b*b;
631
Z = Az*a*a*a + Bz*3*a*a*b + Cz*3*a*b*b + Dz*b*b*b;
634
if(lineintersects((float)Xprev,(float)X,(float)Yprev,(float)Y) >=0) //intersection
639
if(!(lineintersects((float)Xprev,(float)X,(float)Yprev,(float)Y)==1)) //withing the rect
660
int ellipse_x_rect(xdot_op* op)
662
float x,y,xradius,yradius;
669
x=(float)op->u.ellipse.x;
670
y=(float)op->u.ellipse.y;
671
xradius=(float)op->u.ellipse.w;
672
yradius=(float)op->u.ellipse.h;
673
for (i=0; i < 360; i=i+1)
675
//convert degrees into radians
676
float degInRad = i*(float)DEG2RAD;
679
if(lineintersects((float)Xprev,x+(float)cos(degInRad)*xradius,(float)Yprev,y+(float)sin(degInRad)*yradius) >=0) //intersection
683
Xprev=x+cos(degInRad)*xradius;
684
Yprev=y+sin(degInRad)*yradius;
690
int ellipse_in_rect(xdot_op* op)
692
float x,y,xradius,yradius;
699
x=(float)op->u.ellipse.x;
700
y=(float)op->u.ellipse.y;
701
xradius=(float)op->u.ellipse.w;
702
yradius=(float)op->u.ellipse.h;
703
for (i=0; i < 360; i=i+1)
705
//convert degrees into radians
706
float degInRad = (float)i*(float)DEG2RAD;
709
if(!(lineintersects((float)Xprev,(float)x+(float)cos(degInRad)*xradius,(float)Yprev,y+(float)sin(degInRad)*yradius)==1)) //withing the rect
713
Xprev=x+cos(degInRad)*xradius;
714
Yprev=y+sin(degInRad)*yradius;
720
int point_within_ellipse( xdot_op* op)
723
float dx,dy,ex,ey,ea,eb,px,py ;
726
ex=(float)op->u.ellipse.x;
727
ey=(float)op->u.ellipse.y;
728
ea=(float)op->u.ellipse.w;
729
eb=(float)op->u.ellipse.h;
730
px=view->Selection.X+(float)SINGLE_SELECTION_WIDTH/(float)2;
731
py=view->Selection.Y+(float)SINGLE_SELECTION_WIDTH/(float)2;
734
a=(dx*dx)/(ea*ea) + (dy*dy)/(eb*eb);
738
int point_within_polygon(xdot_op* op)
739
//int pnpoly(int npol, float *xp, float *yp, float x, float y)
742
int npol=op->u.polygon.cnt;
744
op->u.polygon.pts[i].y;
745
op->u.polygon.pts[i].x;
746
x=view->Selection.X+SINGLE_SELECTION_WIDTH/2;
747
y=view->Selection.Y+SINGLE_SELECTION_WIDTH/2;
749
for (i = 0, j = npol-1; i < npol; j = i++) {
752
if ((((op->u.polygon.pts[i].y <= y) && (y < op->u.polygon.pts[j].y)) ||
753
((op->u.polygon.pts[j].y <= y) && (y < op->u.polygon.pts[i].y))) &&
754
(x < (op->u.polygon.pts[j].x - op->u.polygon.pts[i].x) * (y - op->u.polygon.pts[i].y) / (op->u.polygon.pts[j].y - op->u.polygon.pts[i].y) + op->u.polygon.pts[i].x))
762
int select_node(Agraph_t* g,Agnode_t* N)
765
//check if in the list
766
for (ind=0;ind < ((custom_graph_data*)AGDATA(g))->selectedNodesCount ; ind ++ )
768
if( ((custom_graph_data*)AGDATA(g))->selectedNodes[ind] == N)
771
//for single selections i think realloc is ok, for mass selections i ll figure out something else
772
((custom_graph_data*)AGDATA(g))->selectedNodes=realloc(((custom_graph_data*)AGDATA(g))->selectedNodes,sizeof(Agnode_t*)*(((custom_graph_data*)AGDATA(g))->selectedNodesCount+1));
773
((custom_graph_data*)AGDATA(g))->selectedNodes[((custom_graph_data*)AGDATA(g))->selectedNodesCount]=N;
774
((custom_graph_data*)AGDATA(g))->selectedNodesCount++;
775
((custom_object_data*)AGDATA(N))->Selected=1;
778
int select_edge(Agraph_t* g,Agedge_t* E)
781
//check if in the list
782
for (ind=0;ind < ((custom_graph_data*)AGDATA(g))->selectedEdgesCount ; ind ++ )
784
if(((custom_graph_data*)AGDATA(g))->selectedEdges[ind] == E)
787
//for single selections i think realloc is ok, for mass selections i ll figure out something else
788
((custom_graph_data*)AGDATA(g))->selectedEdges=realloc(((custom_graph_data*)AGDATA(g))->selectedEdges,sizeof(Agnode_t*)*(((custom_graph_data*)AGDATA(g))->selectedEdgesCount+1));
789
((custom_graph_data*)AGDATA(g))->selectedEdges[((custom_graph_data*)AGDATA(g))->selectedEdgesCount]=E;
790
((custom_graph_data*)AGDATA(g))->selectedEdgesCount++;
791
((custom_object_data*)AGDATA(E))->Selected=1;
795
int select_object (Agraph_t* g,void* obj)
813
int deselect_object (Agraph_t* g,void* obj)
818
deselect_node(g,obj);
821
deselect_edge(g,obj);
824
deselect_graph(g,obj);
833
int select_graph(Agraph_t* g,Agraph_t* G)
836
//check if in the list
837
for (ind=0;ind < ((custom_graph_data*)AGDATA(g))->selectedGraphsCount ; ind ++ )
839
if(((custom_graph_data*)AGDATA(g))->selectedGraphs[ind] == G)
842
//for single selections i think realloc is ok, for mass selections i ll figure out something else
843
((custom_graph_data*)AGDATA(g))->selectedGraphs=realloc(((custom_graph_data*)AGDATA(g))->selectedGraphs,sizeof(Agnode_t*)*(((custom_graph_data*)AGDATA(g))->selectedGraphsCount+1));
844
((custom_graph_data*)AGDATA(g))->selectedGraphs[((custom_graph_data*)AGDATA(g))->selectedGraphsCount]=G;
845
((custom_graph_data*)AGDATA(g))->selectedGraphsCount++;
846
((custom_object_data*)AGDATA(G))->Selected=1;
849
int deselect_node(Agraph_t* g,Agnode_t* N)
853
//check if in the list
854
for (ind=0;ind < ((custom_graph_data*)AGDATA(g))->selectedNodesCount ; ind ++ )
857
((custom_graph_data*)AGDATA(g))->selectedNodes[ind-1]=((custom_graph_data*)AGDATA(g))->selectedNodes[ind];
858
if( ((custom_graph_data*)AGDATA(g))->selectedNodes[ind] == N)
861
//for single selections i think realloc is ok, for mass selections i ll figure out something else
864
((custom_graph_data*)AGDATA(g))->selectedNodes=realloc(((custom_graph_data*)AGDATA(g))->selectedNodes,sizeof(Agnode_t*)*(((custom_graph_data*)AGDATA(g))->selectedNodesCount-1));
865
((custom_graph_data*)AGDATA(g))->selectedNodesCount--;
866
((custom_object_data*)AGDATA(N))->Selected=0;
867
((custom_object_data*)AGDATA(N))->selectionflag=0;
872
int deselect_edge(Agraph_t* g,Agedge_t* E)
876
//check if in the list
877
for (ind=0;ind < ((custom_graph_data*)AGDATA(g))->selectedEdgesCount ; ind ++ )
880
((custom_graph_data*)AGDATA(g))->selectedEdges[ind-1]=((custom_graph_data*)AGDATA(g))->selectedEdges[ind];
881
if( ((custom_graph_data*)AGDATA(g))->selectedEdges[ind] == E)
884
//for single selections i think realloc is ok, for mass selections i ll figure out something else
887
((custom_graph_data*)AGDATA(g))->selectedEdges=realloc(((custom_graph_data*)AGDATA(g))->selectedEdges,sizeof(Agnode_t*)*(((custom_graph_data*)AGDATA(g))->selectedEdgesCount-1));
888
((custom_graph_data*)AGDATA(g))->selectedEdgesCount--;
889
((custom_object_data*)AGDATA(E))->Selected=0;
890
((custom_object_data*)AGDATA(E))->selectionflag=0;
895
int deselect_graph(Agraph_t* g,Agraph_t* G)
899
//check if in the list
900
for (ind=0;ind < ((custom_graph_data*)AGDATA(g))->selectedGraphsCount ; ind ++ )
903
((custom_graph_data*)AGDATA(g))->selectedGraphs[ind-1]=((custom_graph_data*)AGDATA(g))->selectedGraphs[ind];
904
if( ((custom_graph_data*)AGDATA(g))->selectedGraphs[ind] == G)
907
//for single selections i think realloc is ok, for mass selections i ll figure out something else
910
((custom_graph_data*)AGDATA(g))->selectedGraphs=realloc(((custom_graph_data*)AGDATA(g))->selectedGraphs,sizeof(Agnode_t*)*(((custom_graph_data*)AGDATA(g))->selectedGraphsCount-1));
911
((custom_graph_data*)AGDATA(g))->selectedGraphsCount--;
912
((custom_object_data*)AGDATA(G))->Selected=0;
913
((custom_object_data*)AGDATA(G))->selectionflag=0;
919
int select_all_nodes(Agraph_t* g)
922
for (n = agfstnode(g); n; n = agnxtnode(g, n))
929
int select_all_edges(Agraph_t* g)
937
for (n = agfstnode(g); n; n = agnxtnode(g, n))
939
for (e = agfstout(g,n) ; e ; e = agnxtout (g,e))
947
int select_all_graphs(Agraph_t* g)
950
for (s = agfstsubg(g); s; s = agnxtsubg(s))
955
int deselect_all_nodes(Agraph_t* g)
963
for (n = agfstnode(g); n; n = agnxtnode(g, n))
971
int deselect_all_edges(Agraph_t* g)
977
for (n = agfstnode(g); n; n = agnxtnode(g, n))
979
for (e = agfstout(g,n) ; e ; e = agnxtout (g,e))
989
int deselect_all_graphs(Agraph_t* g)
992
for (s = agfstsubg(g); s; s = agnxtsubg(s))
996
int select_all(Agraph_t* g)
1000
select_all_graphs(g);
1004
int deselect_all(Agraph_t* g)
1006
deselect_all_nodes(g);
1007
deselect_all_edges(g);
1008
deselect_all_graphs(g);
1011
int line_intersects (float* x,float* y,float* X,float* Y)
1013
//x,y are arrayf of float for two lines parameters theyt hold 4 points with x and y
1014
//limitx and limity are float arrays with two points, thse points are the end points of the second line
1015
//X,Y are the variables to put intersection point coordinates in
1016
pointf pA,pB,pC,pD,pX;
1017
pA.x=x[0];pA.y=y[0];
1018
pB.x=x[1];pB.y=y[1];
1019
pC.x=x[2];pC.y=y[2];
1020
pD.x=x[3];pD.y=y[3];
1022
if(intersect (pA, pB, pC, pD, &pX))
1026
if ( (pX.x >=x[2]-0.01) && (pX.x <x[3]+0.01) &&
1027
(pX.y >=y[2]-0.01) && (pX.x <y[3]+0.01))
1040
int point_within_ellips_with_coords(float ex,float ey,float ea,float eb,float px,float py)
1047
a=(dx*dx)/(ea*ea) + (dy*dy)/(eb*eb);