~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to xmetanet/find.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright INRIA */
 
2
#include <X11/Intrinsic.h>
 
3
 
 
4
#include "metaconst.h"
 
5
#include "list.h"
 
6
#include "graph.h"
 
7
#include "metio.h"
 
8
#include "graphics.h"
 
9
 
 
10
extern void CenterDraw();
 
11
extern void GetDrawGeometry();
 
12
extern void UnhiliteAll();
 
13
 
 
14
int ArcVisible();
 
15
int NodeVisible();
 
16
 
 
17
void FindNode()
 
18
{
 
19
  char strn[MAXNAM];
 
20
  int n;
 
21
  mylink *p; node *nod, *nod1;
 
22
  char *label = "Give an internal number or a name";
 
23
  char *init[2];
 
24
  char *result[2];
 
25
  char *description[2];
 
26
 
 
27
  if (theGraph->node_number == 0) return;
 
28
 
 
29
  init[0]="0";
 
30
  init[1]="";
 
31
  description[0]="Node internal number";
 
32
  description[1]="Node name";
 
33
  if ((result[0] = (char*)malloc((unsigned)MAXNAM * sizeof(char))) == NULL) {
 
34
    fprintf(stderr,"Running out of memory\n");
 
35
    return;
 
36
  } 
 
37
  if ((result[1] = (char*)malloc((unsigned)MAXNAM * sizeof(char))) == NULL) {
 
38
    fprintf(stderr,"Running out of memory\n");
 
39
    return;
 
40
  } 
 
41
 
 
42
  if (MetanetDialogs(2,init,result,description,label)) {
 
43
    sscanf(result[0],"%d",&n);
 
44
    if (n != 0) {
 
45
      if (n <= 0 || n > theGraph->node_number) {
 
46
        sprintf(Description,"%d is not an internal node number",n);
 
47
        MetanetAlert(Description);
 
48
        return;
 
49
      }
 
50
      p = theGraph->nodes->first;
 
51
      nod = 0;
 
52
      while (p) {
 
53
        if (((node*)(p->element))->number == n) {
 
54
          nod = (node*)(p->element);
 
55
          break;
 
56
        }
 
57
        p = p->next;
 
58
      }
 
59
      if (nod == 0) {
 
60
        sprintf(Description,"%s is not an internal node number",strn);
 
61
        MetanetAlert(Description);
 
62
        return;
 
63
      }
 
64
    } else {
 
65
      strcpy(strn,result[1]);
 
66
      p = theGraph->nodes->first;
 
67
      nod = 0;
 
68
      while (p) {
 
69
        nod1 = (node*)(p->element);
 
70
        if (nod1->name != 0 && !strcmp(nod1->name,strn)) {
 
71
          nod = nod1;
 
72
          break;
 
73
        }
 
74
        p = p->next;
 
75
      }
 
76
      if (nod == 0) {
 
77
        sprintf(Description,"%s is not a node name",strn);
 
78
        MetanetAlert(Description);
 
79
        return;
 
80
      }
 
81
    }
 
82
 
 
83
    if (!NodeVisible(nod))
 
84
      CenterDraw(nod->x + NodeDiam(nod)/2,nod->y + NodeDiam(nod)/2);
 
85
  
 
86
    UnhiliteAll();
 
87
    HiliteNode(nod);
 
88
  }
 
89
}
 
90
 
 
91
int NodeVisible(n)
 
92
node *n;
 
93
{
 
94
  int dx, dy, w, h;
 
95
  
 
96
  GetDrawGeometry(&dx,&dy,&w,&h);
 
97
 
 
98
  if ((int)(metaScale*n->x) >= dx &&
 
99
      (int)(metaScale*(n->x + NodeDiam(n))) <= dx + w &&
 
100
      (int)(metaScale*n->y) >= dy && 
 
101
      (int)(metaScale*(n->y + NodeDiam(n))) <= dy + h)
 
102
    return 1;
 
103
  else return 0;
 
104
}
 
105
 
 
106
void FindArc()
 
107
{
 
108
  char strn[MAXNAM];
 
109
  int n;
 
110
  mylink *p; arc *a,*a1;
 
111
  char *label = "Give an internal number or a name";
 
112
  char *init[2];
 
113
  char *result[2];
 
114
  char *description[2];
 
115
 
 
116
  if (theGraph->arc_number == 0) return;
 
117
 
 
118
  init[0]="0";
 
119
  init[1]="";
 
120
  description[0]="Arc internal number";
 
121
  description[1]="Arc name";
 
122
  if ((result[0] = (char*)malloc((unsigned)MAXNAM * sizeof(char))) == NULL) {
 
123
    fprintf(stderr,"Running out of memory\n");
 
124
    return;
 
125
  } 
 
126
  if ((result[1] = (char*)malloc((unsigned)MAXNAM * sizeof(char))) == NULL) {
 
127
    fprintf(stderr,"Running out of memory\n");
 
128
    return;
 
129
  } 
 
130
 
 
131
  if (MetanetDialogs(2,init,result,description,label)) {
 
132
    sscanf(result[0],"%d",&n);
 
133
    if (n != 0) {
 
134
      if (n <= 0 || n > theGraph->arc_number) {
 
135
        sprintf(Description,"%d is not an internal arc number",n);
 
136
        MetanetAlert(Description);
 
137
        return;
 
138
      }
 
139
      p = theGraph->arcs->first;
 
140
      a = 0;
 
141
      while (p) {
 
142
        a1 = (arc*)(p->element);
 
143
        if (a1->number == n) {
 
144
          a = a1;
 
145
          break;
 
146
        }
 
147
        p = p->next;
 
148
      }
 
149
      if (a == 0) {
 
150
        sprintf(Description,"%s is not an internal arc number",strn);
 
151
        MetanetAlert(Description);
 
152
        return;
 
153
      }
 
154
    }
 
155
    else {
 
156
      strcpy(strn,result[1]);
 
157
      p = theGraph->arcs->first;
 
158
      a = 0;
 
159
      while (p) {
 
160
        a1 = (arc*)(p->element);
 
161
        if (a1->name != 0 && !strcmp(a1->name,strn)) {
 
162
          a = a1;
 
163
          break;
 
164
        }
 
165
        p = p->next;
 
166
      }
 
167
      if (a == 0) {
 
168
        sprintf(Description,"%s is not an arc name",strn);
 
169
        MetanetAlert(Description);
 
170
        return;
 
171
      }
 
172
    }
 
173
    
 
174
    if (!ArcVisible(a))
 
175
      CenterDraw(a->xmax,a->ymax);
 
176
 
 
177
    UnhiliteAll();
 
178
    HiliteArc(a);
 
179
  }
 
180
}
 
181
 
 
182
int ArcVisible(a)
 
183
arc *a;
 
184
{
 
185
  int dx, dy, w, h;
 
186
  
 
187
  GetDrawGeometry(&dx,&dy,&w,&h);
 
188
 
 
189
  if (NodeVisible(a->tail) && NodeVisible(a->head) &&
 
190
      (int)(metaScale*a->xmax) >= dx && (int)(metaScale*a->xmax) <= dx + w &&
 
191
      (int)(metaScale*a->ymax) >= dy && (int)(metaScale*a->ymax) <= dy + h)
 
192
    return 1;
 
193
  else return 0;
 
194
}