~pac72/ubuntu/lucid/ddd/devel

« back to all changes in this revision

Viewing changes to ddd/test-graph.C

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Schepler
  • Date: 2004-07-22 03:49:37 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040722034937-cysl08t1jvba4jrx
Tags: 1:3.3.9-3
USERINFO has been renamed to USERINFO.txt; adjust debian/rules code
to match, to get correct information on the About DDD dialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: test-graph.C,v 1.14 2001/04/26 11:08:07 zeller Exp $
2
 
// Graph test
3
 
 
4
 
// Copyright (C) 1995 Technische Universitaet Braunschweig, Germany.
5
 
// Written by Andreas Zeller <zeller@gnu.org>.
6
 
// 
7
 
// This file is part of DDD.
8
 
// 
9
 
// DDD is free software; you can redistribute it and/or
10
 
// modify it under the terms of the GNU General Public
11
 
// License as published by the Free Software Foundation; either
12
 
// version 2 of the License, or (at your option) any later version.
13
 
// 
14
 
// DDD is distributed in the hope that it will be useful,
15
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
 
// See the GNU General Public License for more details.
18
 
// 
19
 
// You should have received a copy of the GNU General Public
20
 
// License along with DDD -- see the file COPYING.
21
 
// If not, write to the Free Software Foundation, Inc.,
22
 
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
 
// 
24
 
// DDD is the data display debugger.
25
 
// For details, see the DDD World-Wide-Web page, 
26
 
// `http://www.gnu.org/software/ddd/',
27
 
// or send a mail to the DDD developers <ddd@gnu.org>.
28
 
 
29
 
char test_graph_rcsid[] = 
30
 
    "$Id: test-graph.C,v 1.14 2001/04/26 11:08:07 zeller Exp $";
31
 
 
32
 
#include "assert.h"
33
 
#include <iostream.h>
34
 
#include <string.h>
35
 
#include <stdlib.h>
36
 
 
37
 
#include <Xm/Xm.h>
38
 
#include <Xm/ScrolledW.h>
39
 
#include <Xm/RowColumn.h>
40
 
#include <X11/Shell.h>
41
 
#include "ScrolledGE.h"
42
 
#include "PannedGE.h"
43
 
#include "GraphEdit.h"
44
 
 
45
 
#include "converters.h"
46
 
#include "MakeMenu.h"
47
 
#include "longName.h"
48
 
 
49
 
#include "StringBox.h"
50
 
#include "AlignBox.h"
51
 
 
52
 
#include "Graph.h"
53
 
#include "BoxGraphN.h"
54
 
#include "HintGraphN.h"
55
 
#include "ArcGraphE.h"
56
 
#include "BoxEdgeA.h"
57
 
 
58
 
#ifndef EXIT_SUCCESS
59
 
#define EXIT_SUCCESS 0
60
 
#endif
61
 
 
62
 
#ifndef EXIT_FAILURE
63
 
#define EXIT_FAILURE 1
64
 
#endif
65
 
 
66
 
// Build a simple graph
67
 
Graph *myGraph()
68
 
{
69
 
    MarkBox *hugo    = new MarkBox(new StringBox("Select"));
70
 
    Box *berta       = new StringBox("Me");
71
 
    HAlignBox *hbox  = new HAlignBox();
72
 
    *hbox &= hugo;
73
 
    *hbox &= berta;
74
 
 
75
 
    GraphNode *n0 = new BoxGraphNode(hbox, BoxPoint(50, 50), hugo);
76
 
 
77
 
    GraphNode *n1 =
78
 
        new HintGraphNode(BoxPoint(65, 65));
79
 
    GraphNode *n2 =
80
 
        new BoxGraphNode(new StringBox("30, 30"), BoxPoint(30, 30));
81
 
    GraphNode *n3 =
82
 
        new BoxGraphNode(new StringBox("100, 30"), BoxPoint(100, 30));
83
 
    GraphNode *n4 =
84
 
        new BoxGraphNode(new StringBox("30, 100"), BoxPoint(30, 100));
85
 
    GraphNode *n5 =
86
 
        new BoxGraphNode(new StringBox("100, 100"), BoxPoint(100, 100));
87
 
    GraphNode *n6 =
88
 
        new BoxGraphNode(new StringBox("100, 100 a"), BoxPoint(100, 100));
89
 
    HintGraphNode *n7 =
90
 
        new HintGraphNode(BoxPoint(100, 50));
91
 
    GraphNode *n8 =
92
 
        new BoxGraphNode(new StringBox("100, 100 b"), BoxPoint(100, 100));
93
 
 
94
 
    BoxEdgeAnnotation *a1 = new BoxEdgeAnnotation(new StringBox("a1"));
95
 
    BoxEdgeAnnotation *a2 = new BoxEdgeAnnotation(new StringBox("a2"));
96
 
 
97
 
    n2->selected() = True;
98
 
 
99
 
    Graph *g = new Graph;
100
 
    assert(g->OK());
101
 
 
102
 
    *g += n0;
103
 
    assert(g->OK());
104
 
 
105
 
    *g += n1;
106
 
    assert(g->OK());
107
 
 
108
 
    *g += n2;
109
 
    assert(g->OK());
110
 
 
111
 
    *g += n3;
112
 
    assert(g->OK());
113
 
 
114
 
    *g += n4;
115
 
    assert(g->OK());
116
 
 
117
 
    *g += n5;
118
 
    assert(g->OK());
119
 
 
120
 
    *g += n6;
121
 
    assert(g->OK());
122
 
 
123
 
    *g += n7;
124
 
    assert(g->OK());
125
 
 
126
 
    *g += n8;
127
 
    assert(g->OK());
128
 
 
129
 
    *g += new LineGraphEdge(n0, n0);
130
 
    assert(g->OK());
131
 
 
132
 
    *g += new LineGraphEdge(n1, n2);
133
 
    assert(g->OK());
134
 
 
135
 
    *g += new LineGraphEdge(n1, n3);
136
 
    assert(g->OK());
137
 
 
138
 
    *g += new LineGraphEdge(n1, n4);
139
 
    assert(g->OK());
140
 
 
141
 
    *g += new LineGraphEdge(n1, n5);
142
 
    assert(g->OK());
143
 
 
144
 
    *g += new LineGraphEdge(n2, n3);
145
 
    assert(g->OK());
146
 
 
147
 
    *g += new LineGraphEdge(n2, n4);
148
 
    assert(g->OK());
149
 
 
150
 
    *g += new LineGraphEdge(n2, n5);
151
 
    assert(g->OK());
152
 
 
153
 
    *g += new LineGraphEdge(n3, n4);
154
 
    assert(g->OK());
155
 
 
156
 
    *g += new LineGraphEdge(n3, n5);
157
 
    assert(g->OK());
158
 
 
159
 
    *g += new LineGraphEdge(n4, n5, a1);
160
 
    assert(g->OK());
161
 
 
162
 
    GraphEdge *e67 = new ArcGraphEdge(n6, n7); 
163
 
    *g += e67;
164
 
    assert(g->OK());
165
 
 
166
 
    GraphEdge *e78 = new ArcGraphEdge(n7, n8, a2);
167
 
    *g += e78;
168
 
    assert(g->OK());
169
 
 
170
 
    GraphEdge *e56 = new LineGraphEdge(n5, n6); 
171
 
    *g += e56;
172
 
    assert(g->OK());
173
 
 
174
 
    Graph *g2 = g->dup();
175
 
    assert(g->OK());
176
 
    assert(g2->OK());
177
 
 
178
 
    return g2;
179
 
}
180
 
 
181
 
static String fallback_resources[] = {
182
 
    "*allowShellResize: True",
183
 
    0
184
 
};
185
 
 
186
 
void PositionChanged(Widget, XtPointer, XtPointer call_data)
187
 
{
188
 
    GraphEditPositionChangedInfo *info = 
189
 
        (GraphEditPositionChangedInfo *)call_data;
190
 
 
191
 
    clog << "Moving node " << *info->node << " from " << 
192
 
        info->old_position << " to " << info->new_position;
193
 
    if (info->is_last)
194
 
    {
195
 
        clog << " (last)";
196
 
    }
197
 
 
198
 
    clog << "\n";
199
 
}
200
 
 
201
 
 
202
 
static void OneCB(Widget widget, XtPointer, XtPointer)
203
 
{
204
 
    cout << longName(widget) << "\n";
205
 
}
206
 
 
207
 
static void TwoCB(Widget widget, XtPointer, XtPointer)
208
 
{
209
 
    cout << longName(widget) << "\n";
210
 
}
211
 
 
212
 
static void ThreeCB(Widget widget, XtPointer, XtPointer)
213
 
{
214
 
    cout << longName(widget) << "\n";
215
 
}
216
 
 
217
 
static MMDesc simpleMenu[] =
218
 
{
219
 
    { "menu",  MMLabel },
220
 
    MMSep,
221
 
    { "one",   MMPush, { OneCB } },
222
 
    { "two",   MMPush, { TwoCB } },
223
 
    { "three", MMPush, { ThreeCB } },
224
 
    MMEnd
225
 
};
226
 
 
227
 
void Popup(Widget w, XEvent *event, String *, Cardinal *)
228
 
{
229
 
    if (event->type != ButtonPress && event->type != ButtonRelease)
230
 
    {
231
 
        cerr << "popup(): may only be used with button events\n";
232
 
        return;
233
 
    }
234
 
 
235
 
    static Widget popup = 0;
236
 
 
237
 
    if (popup == 0)
238
 
    {
239
 
        popup = MMcreatePopupMenu(w, "popup", simpleMenu);
240
 
        MMaddCallbacks(simpleMenu);
241
 
    }
242
 
 
243
 
    XmMenuPosition(popup, &event->xbutton);
244
 
    XtManageChild(popup);
245
 
}
246
 
 
247
 
XtActionsRec actions[] = {
248
 
    { "popup", Popup },
249
 
};
250
 
 
251
 
 
252
 
int main(int argc, char *argv[])
253
 
{
254
 
    Arg args[10];
255
 
    int arg;
256
 
    XtAppContext app_context;
257
 
 
258
 
    // Initialize it all
259
 
    Widget toplevel = XtAppInitialize(&app_context, "Test-graph",
260
 
        XtPointer(0), 0, &argc, argv, fallback_resources, XtPointer(0), 0);
261
 
 
262
 
    // register additional converters...
263
 
    registerOwnConverters();
264
 
 
265
 
    // register own actions...
266
 
    XtAppAddActions(app_context, actions, XtNumber(actions));
267
 
 
268
 
    // Build the font table...
269
 
    StringBox::fontTable = new FontTable(XtDisplay(toplevel));
270
 
 
271
 
    // Build a graph editor
272
 
    Graph *graph = myGraph();
273
 
    arg = 0;
274
 
    XtSetArg(args[arg], XtNgraph, graph); arg++;
275
 
    Widget editor = createPannedGraphEdit(toplevel, "graphEdit", 
276
 
                                          args, arg);
277
 
    XtManageChild(editor);
278
 
 
279
 
    XtAddCallback(editor, XtNpositionChangedCallback, 
280
 
                  PositionChanged, XtPointer(0));
281
 
 
282
 
    XtRealizeWidget(toplevel);
283
 
    XtAppMainLoop(app_context);
284
 
 
285
 
    return EXIT_SUCCESS;
286
 
}