371
374
//select functions
372
static int select_graph(Agraph_t * g, Agraph_t * G)
375
//check if in the list
376
for (ind = 0; ind < GD_selectedGraphsCount(g); ind++) {
377
if (GD_selectedGraphs(g)[ind] == G)
380
//for single selections i think realloc is ok, for mass selections i ll figure out something else
381
GD_selectedGraphs(g) = RALLOC(GD_selectedGraphsCount(g)+1,
382
GD_selectedGraphs(g), Agraph_t*);
383
GD_selectedGraphs(g)[GD_selectedGraphsCount(g)] = G;
384
GD_selectedGraphsCount(g)++;
389
int select_node(Agraph_t * g, Agnode_t * N)
392
//check if in the list
393
for (ind = 0; ind < GD_selectedNodesCount(g); ind++) {
394
if (GD_selectedNodes(g)[ind] == N)
397
//for single selections i think realloc is ok, for mass selections i ll figure out something else
398
GD_selectedNodes(g) =
399
RALLOC(GD_selectedNodesCount(g)+2,GD_selectedNodes(g), Agnode_t*);
400
GD_selectedNodes(g)[GD_selectedNodesCount(g)] = N;
401
GD_selectedNodesCount(g)++;
406
int select_edge(Agraph_t * g, Agedge_t * E)
409
//check if in the list
410
for (ind = 0; ind < GD_selectedEdgesCount(g); ind++) {
411
if (GD_selectedEdges(g)[ind] == E)
414
//for single selections i think realloc is ok, for mass selections i ll figure out something else
415
GD_selectedEdges(g) =
416
RALLOC(GD_selectedEdgesCount(g)+1,GD_selectedEdges(g), Agedge_t*);
417
GD_selectedEdges(g)[GD_selectedEdgesCount(g)] = E;
418
GD_selectedEdgesCount(g)++;
423
int select_object(Agraph_t * g, void *obj)
425
switch (AGTYPE(obj)) {
433
select_graph(g, obj);
441
int deselect_node(Agraph_t * g, Agnode_t * N)
445
//check if in the list
446
for (ind = 0; ind < GD_selectedNodesCount(g); ind++) {
448
GD_selectedNodes(g)[ind - 1] = GD_selectedNodes(g)[ind];
449
if (GD_selectedNodes(g)[ind] == N)
452
//for single selections i think realloc is ok, for mass selections i ll figure out something else
454
GD_selectedNodes(g) =
455
RALLOC(GD_selectedNodesCount(g)-1,GD_selectedNodes(g), Agnode_t*);
456
GD_selectedNodesCount(g)--;
464
int deselect_edge(Agraph_t * g, Agedge_t * E)
468
//check if in the list
469
for (ind = 0; ind < GD_selectedEdgesCount(g); ind++) {
471
GD_selectedEdges(g)[ind-1] = GD_selectedEdges(g)[ind];
472
if (GD_selectedEdges(g)[ind] == E)
475
//for single selections i think realloc is ok, for mass selections i ll figure out something else
477
GD_selectedEdges(g) =
478
RALLOC(GD_selectedEdgesCount(g)-1,GD_selectedEdges(g), Agedge_t*);
479
GD_selectedEdgesCount(g)--;
486
static int deselect_graph(Agraph_t * g, Agraph_t * G)
490
//check if in the list
491
for (ind = 0; ind < GD_selectedGraphsCount(g); ind++) {
493
GD_selectedGraphs(g)[ind-1] = GD_selectedGraphs(g)[ind];
494
if (GD_selectedGraphs(g)[ind] == G)
497
//for single selections i think realloc is ok, for mass selections i ll figure out something else
499
GD_selectedGraphs(g) =
500
RALLOC(GD_selectedGraphsCount(g)-1,GD_selectedGraphs(g), Agraph_t*);
501
GD_selectedGraphsCount(g)--;
507
int deselect_object(Agraph_t * g, void *obj)
509
switch (AGTYPE(obj)) {
511
deselect_node(g, obj);
514
deselect_edge(g, obj);
517
deselect_graph(g, obj);
376
static Agsym_t *getNodeSelectedAttr(Agraph_t * g)
378
static Agraph_t *saveg;
379
static Agsym_t *saveattr;
383
if (!(saveattr = agattr(saveg, AGNODE, "selected", 0))) {
384
saveattr = agattr(saveg, AGNODE, "selected", "0");
390
static Agsym_t *getEdgeSelectedAttr(Agraph_t * g)
392
static Agraph_t *saveg;
393
static Agsym_t *saveattr;
397
if (!(saveattr = agattr(saveg, AGEDGE, "selected", 0))) {
398
saveattr = agattr(saveg, AGEDGE, "selected", "0");
404
int select_node(topview_node * N)
406
Agsym_t *a = getNodeSelectedAttr(N->Node->root);
408
N->data.Selected = 1;
409
return agxset(N->Node, a, "1");
412
int select_edge(topview_edge * E)
414
Agsym_t *a = getEdgeSelectedAttr(aghead(E->Edge)->root);
416
E->data.Selected = 1;
417
return agxset(E->Edge, a, "1");
420
int deselect_node(topview_node * N)
422
Agsym_t *a = getNodeSelectedAttr(N->Node->root);
424
N->data.Selected = 0;
425
return agxset(N->Node, a, "0");
428
int deselect_edge(topview_edge * E)
430
Agsym_t *a = getEdgeSelectedAttr(aghead(E->Edge)->root);
432
E->data.Selected = 0;
433
return agxset(E->Edge, a, "0");
437
static void update_cgraph_pos(topview_node * N)
441
Agnode_t *obj = N->Node;
443
if ((pos = agattrsym(obj, "pos"))) {
444
sprintf(buf, "%lf,%lf", N->distorted_x, N->distorted_y);
445
agxset(obj, pos, buf);
525
450
int select_all_nodes(Agraph_t * g)
528
for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
453
//check if in the list
454
for (ind = 0; ind < view->Topview->Nodecount; ind++) {
455
select_node(&view->Topview->Nodes[ind]);
535
460
int select_all_edges(Agraph_t * g)
543
for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
544
for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
463
//check if in the list
464
for (ind = 0; ind < view->Topview->Edgecount; ind++) {
465
select_edge(&view->Topview->Edges[ind]);
552
int select_all_graphs(Agraph_t * g)
555
for (s = agfstsubg(g); s; s = agnxtsubg(s))
560
472
int deselect_all_nodes(Agraph_t * g)
568
for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
475
//check if in the list
476
for (ind = 0; ind < view->Topview->Nodecount; ind++) {
477
deselect_node(&view->Topview->Nodes[ind]);
576
483
int deselect_all_edges(Agraph_t * g)
582
for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
583
for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
486
//check if in the list
487
for (ind = 0; ind < view->Topview->Edgecount; ind++) {
488
deselect_edge(&view->Topview->Edges[ind]);
592
int deselect_all_graphs(Agraph_t * g)
595
for (s = agfstsubg(g); s; s = agnxtsubg(s))
596
deselect_graph(g, s);
600
494
int select_all(Agraph_t * g)
602
496
select_all_nodes(g);
603
497
select_all_edges(g);
604
select_all_graphs(g);
684
int SelectBeziers(sdot_op * op)
686
if (!view->Selection.Active)
688
switch (view->Selection.Type) {
690
if (view->Selection.AlreadySelected)
692
if (spline_x_rect((xdot_op *) op)) {
693
if (OD_Selected(op->obj) == 0) {
694
OD_Selected(op->obj) = 1;
695
select_object(view->g[view->activeGraph], op->obj);
696
view->Selection.AlreadySelected = 1;
698
OD_Selected(op->obj) = 0;
699
deselect_object(view->g[view->activeGraph], op->obj);
700
view->Selection.AlreadySelected = 1;
706
if (OD_Selected(((xdot*)(op->parentxdot))->obj) == 1)
709
if ((OD_SelFlag(op->obj) != -1) && spline_in_rect((xdot_op *) op)) {
710
OD_Preselected(op->obj) = 1;
711
// select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
712
view->Selection.AlreadySelected = 1;
714
OD_Preselected(op->obj) = 0;
715
// deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
716
view->Selection.AlreadySelected = 1;
717
OD_SelFlag(op->obj) = -1;
721
if (OD_Selected(op->obj) == 1)
723
if (spline_x_rect((xdot_op *) op)) {
724
OD_Selected(op->obj) = 1;
725
select_object(view->g[view->activeGraph], op->obj);
726
view->Selection.AlreadySelected = 1;
736
int SelectPolygon(sdot_op * op)
739
if (!view->Selection.Active)
741
switch (view->Selection.Type) {
743
if (view->Selection.AlreadySelected)
745
if ((point_within_polygon((xdot_op *) op))
746
|| (polygon_x_rect((xdot_op *) op))) {
747
if (OD_Selected(op->obj) == 0) {
748
OD_Selected(op->obj) = 1;
749
select_object(view->g[view->activeGraph], op->obj);
750
view->Selection.AlreadySelected = 1;
752
OD_Selected(op->obj) = 0;
753
deselect_object(view->g[view->activeGraph], op->obj);
754
view->Selection.AlreadySelected = 1;
759
if (OD_Selected(op->obj) == 1)
761
if ((OD_SelFlag(op->obj) != -1) && polygon_in_rect((xdot_op *) op)) {
762
OD_Preselected(op->obj) = 1;
763
// select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
764
// view->Selection.AlreadySelected=1;
766
OD_Selected(op->obj) = 1;
767
OD_Preselected(op->obj) = 0;
768
// deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
769
view->Selection.AlreadySelected = 1;
770
OD_SelFlag(op->obj) = -1;
774
if (OD_Selected(op->obj) == 1)
776
if (polygon_x_rect((xdot_op *) op)) {
777
OD_Selected(op->obj) = 1;
778
select_object(view->g[view->activeGraph], op->obj);
779
view->Selection.AlreadySelected = 1;
788
int SelectPolyline(sdot_op * op)
790
if (!view->Selection.Active)
792
switch (view->Selection.Type) {
794
if (view->Selection.AlreadySelected)
797
if (polyline_x_rect((xdot_op *) op)) {
798
if (OD_Selected(op->obj) == 0) {
799
OD_Selected(op->obj) = 1;
800
select_object(view->g[view->activeGraph], op->obj);
801
view->Selection.AlreadySelected = 1;
803
OD_Selected(op->obj) = 0;
804
deselect_object(view->g[view->activeGraph], op->obj);
805
view->Selection.AlreadySelected = 1;
810
if (OD_Selected(op->obj) == 1)
812
if ((OD_SelFlag(op->obj) != -1)
813
&& polyline_in_rect((xdot_op *) op)) {
814
OD_Preselected(op->obj) = 1;
816
OD_Preselected(op->obj) = 0;
817
view->Selection.AlreadySelected = 1;
818
OD_SelFlag(op->obj) = -1;
824
if (OD_Selected(op->obj) == 1)
826
if (polyline_x_rect((xdot_op *) op)) {
827
OD_Selected(op->obj) = 1;
828
select_object(view->g[view->activeGraph], op->obj);
829
view->Selection.AlreadySelected = 1;
840
int SelectEllipse(sdot_op * op)
842
if (!view->Selection.Active)
844
switch (view->Selection.Type) {
846
if (view->Selection.AlreadySelected)
849
if (point_within_ellipse((xdot_op *) op)) {
850
if (OD_Selected(op->obj) == 0) {
851
OD_Selected(op->obj) = 1;
852
select_object(view->g[view->activeGraph], op->obj);
853
view->Selection.AlreadySelected = 1;
856
OD_Selected(op->obj) = 0;
857
deselect_object(view->g[view->activeGraph], op->obj);
858
view->Selection.AlreadySelected = 1;
861
} else if (ellipse_x_rect((xdot_op *) op)) {
862
if (OD_Selected(op->obj) == 0) {
863
OD_Selected(op->obj) = 1;
864
select_object(view->g[view->activeGraph], op->obj);
865
view->Selection.AlreadySelected = 1;
867
OD_Selected(op->obj) = 0;
868
deselect_object(view->g[view->activeGraph], op->obj);
869
view->Selection.AlreadySelected = 1;
874
if (OD_Selected(op->obj) == 1)
876
if ((OD_SelFlag(op->obj) != -1) && ellipse_in_rect((xdot_op *) op)) {
877
OD_Preselected(op->obj) = 1;
878
view->Selection.AlreadySelected = 1;
880
OD_Preselected(op->obj) = 0;
881
view->Selection.AlreadySelected = 1;
882
OD_SelFlag(op->obj) = -1;
886
if (OD_Selected(op->obj) == 1)
888
if (ellipse_x_rect((xdot_op *) op)) {
889
OD_Selected(op->obj) = 1;
890
select_object(view->g[view->activeGraph], op->obj);
891
view->Selection.AlreadySelected = 1;
901
int SelectText(sdot_op * op)
903
if (!view->Selection.Active)
905
switch (view->Selection.Type) {
907
if (view->Selection.AlreadySelected)
909
if (text_x_rect(op)) {
910
if (OD_Selected(op->obj) == 0)
911
OD_Selected(op->obj) = 1;
913
OD_Selected(op->obj) = 0;
917
if (OD_Selected(op->obj) == 1)
919
if (text_in_rect(op)) {
920
OD_Selected(op->obj) = 1;
921
select_object(view->g[view->activeGraph], op->obj);
922
view->Selection.AlreadySelected = 1;
926
if (OD_Selected(op->obj) == 1)
928
if (text_x_rect(op)) {
929
OD_Selected(op->obj) = 1;
930
select_object(view->g[view->activeGraph], op->obj);
931
view->Selection.AlreadySelected = 1;
941
int SelectImage(sdot_op * op)
943
if (!view->Selection.Active)
945
switch (view->Selection.Type) {
947
if (view->Selection.AlreadySelected)
949
if (image_x_rect((xdot_op *) op)) {
950
if (OD_Selected(op->obj) == 0) {
951
OD_Selected(op->obj) = 1;
952
select_object(view->g[view->activeGraph], op->obj);
953
view->Selection.AlreadySelected = 1;
955
OD_Selected(op->obj) = 0;
959
if (OD_Selected(op->obj) == 1)
961
if (image_in_rect((xdot_op *) op))
962
OD_Selected(op->obj) = 1;
965
if (OD_Selected(op->obj) == 1)
967
if (image_x_rect((xdot_op *) op))
968
OD_Selected(op->obj) = 1;
580
static void select_topview_node(topview_node * n)
582
static float x1,y1,x2,y2,x,y;
585
if(view->mouse.GLfinalPos.x > view->mouse.GLinitPos.x)
587
x1=view->mouse.GLinitPos.x;
588
x2=view->mouse.GLfinalPos.x;
592
x2=view->mouse.GLinitPos.x;
593
x1=view->mouse.GLfinalPos.x;
596
if(view->mouse.GLfinalPos.y > view->mouse.GLinitPos.y)
598
y1=view->mouse.GLinitPos.y;
599
y2=view->mouse.GLfinalPos.y;
603
y2=view->mouse.GLinitPos.y;
604
y1=view->mouse.GLfinalPos.y;
606
if(is_point_in_rectangle(x,y,x1,y1,x2-x1,y2-y1))
608
agset(n->Node,"selected","1");
613
static void select_topview_edge(topview_edge* e)
615
static float x1,y1,x2,y2,n1x,n1y,n2x,n2y;
616
n1x=e->Node1->distorted_x;
617
n1y=e->Node1->distorted_y;
618
n2x=e->Node2->distorted_x;
619
n2y=e->Node2->distorted_y;
620
if(view->mouse.GLfinalPos.x > view->mouse.GLinitPos.x)
622
x1=view->mouse.GLinitPos.x;
623
x2=view->mouse.GLfinalPos.x;
627
x2=view->mouse.GLinitPos.x;
628
x1=view->mouse.GLfinalPos.x;
631
if(view->mouse.GLfinalPos.y > view->mouse.GLinitPos.y)
633
y1=view->mouse.GLinitPos.y;
634
y2=view->mouse.GLfinalPos.y;
638
y2=view->mouse.GLinitPos.y;
639
y1=view->mouse.GLfinalPos.y;
641
if((is_point_in_rectangle(n1x,n1y,x1,y1,x2-x1,y2-y1))
643
(is_point_in_rectangle(n2x,n2y,x1,y1,x2-x1,y2-y1)) )
645
agset(e->Edge,"selected","1");
650
static void node_rectangle_select(ViewInfo* v)
655
for (ind = 0; ind < v->Topview->Nodecount; ind++)
657
n = v->Topview->Nodes + ind;
658
select_topview_node(n);
662
static void edge_rectangle_select(ViewInfo* v)
667
for (ind = 0; ind < v->Topview->Edgecount; ind++)
669
e = v->Topview->Edges + ind;
670
select_topview_edge(e);
674
void rectangle_select(ViewInfo* v)
676
int selnodes=atoi(agget(view->g[view->activeGraph],"nodesselectable"));
677
int seledges=atoi(agget(view->g[view->activeGraph],"edgesselectable"));
679
node_rectangle_select(v);
681
edge_rectangle_select(v);
683
int linesegmentsintersects(float X1, float X2, float Y1, float Y2)
689
//RX,RY lower left corner of rectangle
690
//RW width of rectangle
691
//RH height of ractangle
692
//returns 1 if line segment is completely in the rect
693
//0 if they intersect
694
//-1 if completely out
696
float RX, RY, RW, RH;
698
RX = view->Selection.X;
699
RY = view->Selection.Y;
700
RH=view->Selection.H;
701
RW=view->Selection.W;
702
if ((is_point_in_rectangle(X1, Y1, RX, RY, RW, RH))
703
&& (is_point_in_rectangle(X2, Y2, RX, RY, RW, RH)))
705
if ((is_point_in_rectangle(X1, Y1, RX, RY, RW, RH))
706
|| (is_point_in_rectangle(X2, Y2, RX, RY, RW, RH)))
708
//to be absolute or not to be one
719
iter = RW / (float) SELECTION_SEGMENT_DIVIDER;
720
m = (Y2 - Y1) / (X2 - X1);
726
y = Y1 + m * (x - X1);
727
if (!is_point_in_rectangle(x, y, RX, RY, RW, RH))
978
761
static int line_intersects(float *x, float *y, float *X, float *Y)
980
763
//x,y are arrayf of float for two lines parameters theyt hold 4 points with x and y