~pac72/ubuntu/lucid/ddd/devel

« back to all changes in this revision

Viewing changes to ddd/plotter.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: plotter.C,v 1.46 2001/04/26 11:08:07 zeller Exp $ -*- C++ -*-
 
1
// $Id$ -*- C++ -*-
2
2
// Create a plotter interface
3
3
 
4
4
// Copyright (C) 1998 Technische Universitaet Braunschweig, Germany.
27
27
// or send a mail to the DDD developers <ddd@gnu.org>.
28
28
 
29
29
char plotter_rcsid[] = 
30
 
    "$Id: plotter.C,v 1.46 2001/04/26 11:08:07 zeller Exp $";
31
 
 
32
 
#ifdef __GNUG__
33
 
#pragma implementation
34
 
#endif
 
30
    "$Id$";
35
31
 
36
32
#include "plotter.h"
37
33
 
70
66
#include "TimeOut.h"
71
67
 
72
68
#include <stdio.h>
73
 
#include <fstream.h>
 
69
#include <fstream>
74
70
 
75
71
#include <Xm/Command.h>
76
72
#include <Xm/MainW.h>
140
136
    {}
141
137
 
142
138
private:
143
 
    PlotWindowInfo(const PlotWindowInfo&)
144
 
        : source(0), window_name(""),
145
 
          plotter(0), area(0), shell(0), working_dialog(0), swallower(0),
146
 
          vsb(0), hsb(0), command(0), command_dialog(0), 
147
 
          export_dialog(0), active(false), swallow_timer(0), 
148
 
          settings(""), settings_timer(0), settings_file(""), settings_delay(0)
149
 
    {
150
 
        assert(0);
151
 
    }
152
 
 
153
 
    PlotWindowInfo& operator=(const PlotWindowInfo&)
154
 
    {
155
 
        assert(0);
156
 
        return *this;
157
 
    }
 
139
    PlotWindowInfo(const PlotWindowInfo&);
 
140
    PlotWindowInfo& operator=(const PlotWindowInfo&);
158
141
};
159
142
 
160
143
 
269
252
 
270
253
static void slurp_file(const string& filename, string& target)
271
254
{
272
 
    ifstream is(filename.chars());
 
255
    std::ifstream is(filename.chars());
273
256
    if (is.bad())
274
257
    {
275
258
        target = "";
276
259
        return;
277
260
    }
278
261
 
279
 
    ostrstream s;
 
262
    std::ostringstream s;
280
263
    int c;
281
264
    while ((c = is.get()) != EOF)
282
265
        s << (unsigned char)c;
410
393
    const StringArray& sources = plot->plotter->data_files();
411
394
    for (i = 0; i < sources.size(); i++)
412
395
    {
413
 
        if (sources[i] != "")
 
396
        if (!sources[i].empty())
414
397
        {
415
398
            if (have_source)
416
399
                can_export  = false; // Multiple source files
423
406
    set_sensitive(export_w, can_export);
424
407
 
425
408
    // The remainder requires settings
426
 
    if (plot->settings == "")
 
409
    if (plot->settings.empty())
427
410
    {
428
411
        // No settings yet
429
412
        if (plot->settings_timer == 0)
768
751
    XtSetArg(args[arg], XmNmessageString, msg.xmstring()); arg++;
769
752
    Widget dialog = 
770
753
        verify(XmCreateErrorDialog(find_shell(),
771
 
                                   CONST_CAST(char *,"no_plotter_dialog"), args, arg));
 
754
                                   XMST("no_plotter_dialog"), args, arg));
772
755
    XtUnmanageChild(XmMessageBoxGetChild
773
756
                    (dialog, XmDIALOG_CANCEL_BUTTON));
774
757
    XtAddCallback(dialog, XmNhelpCallback, ImmediateHelpCB, XtPointer(0));
818
801
 
819
802
        arg = 0;
820
803
        Widget main_window = XmCreateMainWindow(plot->shell, 
821
 
                                                CONST_CAST(char *,"main_window"), 
 
804
                                                XMST("main_window"), 
822
805
                                                args, arg);
823
806
        XtManageChild(main_window);
824
807
 
836
819
        XtSetArg(args[arg], XmNscrollingPolicy, XmAPPLICATION_DEFINED); arg++;
837
820
        XtSetArg(args[arg], XmNvisualPolicy,    XmVARIABLE);            arg++;
838
821
        Widget scroll = 
839
 
            XmCreateScrolledWindow(main_window, CONST_CAST(char *,"scroll"), args, arg);
 
822
            XmCreateScrolledWindow(main_window, XMST("scroll"), args, arg);
840
823
        XtManageChild(scroll);
841
824
 
842
825
        // Create work window
847
830
            // xlib type - create plot area to draw plot commands
848
831
            arg = 0;
849
832
            work = XmCreateDrawingArea(scroll, 
850
 
                                       CONST_CAST(char *,PLOT_AREA_NAME), args, arg);
 
833
                                       XMST(PLOT_AREA_NAME), args, arg);
851
834
            XtManageChild(work);
852
835
 
853
836
            plot->area = 
879
862
        XtSetArg(args[arg], XmNorientation, XmHORIZONTAL);      arg++;
880
863
        XtSetArg(args[arg], XmNminimum,     0);                 arg++;
881
864
        XtSetArg(args[arg], XmNmaximum,     360 + slider_size); arg++;
882
 
        plot->hsb = XmCreateScrollBar(scroll, CONST_CAST(char *,"hsb"), args, arg);
 
865
        plot->hsb = XmCreateScrollBar(scroll, XMST("hsb"), args, arg);
883
866
        XtManageChild(plot->hsb);
884
867
 
885
868
        arg = 0;
886
869
        XtSetArg(args[arg], XmNorientation, XmVERTICAL);        arg++;
887
870
        XtSetArg(args[arg], XmNminimum,     0);                 arg++;
888
871
        XtSetArg(args[arg], XmNmaximum,     180 + slider_size); arg++;
889
 
        plot->vsb = XmCreateScrollBar(scroll, CONST_CAST(char *,"vsb"), args, arg);
 
872
        plot->vsb = XmCreateScrollBar(scroll, XMST("vsb"), args, arg);
890
873
        XtManageChild(plot->vsb);
891
874
 
892
875
        XtAddCallback(plot->hsb, XmNvalueChangedCallback,
956
939
        }
957
940
    }
958
941
 
959
 
    static VoidArray empty;
 
942
    static const VoidArray empty;
960
943
    plot_infos = empty;
961
944
}
962
945
 
991
974
        Arg args[10];
992
975
        Cardinal arg = 0;
993
976
        dialog = verify(XmCreateWorkingDialog(find_shell(),
994
 
                                              CONST_CAST(char *,"launch_plot_dialog"), 
 
977
                                              XMST("launch_plot_dialog"), 
995
978
                                              args, arg));
996
979
        XtUnmanageChild(XmMessageBoxGetChild(dialog,
997
980
                                             XmDIALOG_OK_BUTTON));
1028
1011
 
1029
1012
    string init = app_data.plot_init_commands;
1030
1013
    init.prepend("set term " + string(app_data.plot_term_type) + "\n");
1031
 
    if (init != "" && !init.contains('\n', -1))
 
1014
    if (!init.empty() && !init.contains('\n', -1))
1032
1015
        init += '\n';
1033
1016
 
1034
1017
    // Add trace handlers
1130
1113
        cmd_s = XmTextFieldGetString(text);
1131
1114
    else if (XmIsText(text))
1132
1115
        cmd_s = XmTextGetString(text);
1133
 
    else
1134
 
        assert(0);
 
1116
    else {
 
1117
        assert(0);
 
1118
        ::abort();
 
1119
    }
1135
1120
 
1136
1121
    string cmd = cmd_s;
1137
1122
    XtFree(cmd_s);
1157
1142
        Cardinal arg = 0;
1158
1143
        Widget dialog = 
1159
1144
            verify(XmCreatePromptDialog(plot->shell,
1160
 
                                        CONST_CAST(char *,"plot_command_dialog"),
 
1145
                                        XMST("plot_command_dialog"),
1161
1146
                                        args, arg));
1162
1147
        Delay::register_shell(dialog);
1163
1148
        plot->command_dialog = dialog;
1178
1163
 
1179
1164
        arg = 0;
1180
1165
        Widget command = 
1181
 
            verify(XmCreateCommand(dialog, CONST_CAST(char *,"plot_command"), args, arg));
 
1166
            verify(XmCreateCommand(dialog, XMST("plot_command"), args, arg));
1182
1167
        plot->command = command;
1183
1168
        XtManageChild(command);
1184
1169
 
1209
1194
 
1210
1195
    PlotWindowInfo *plot = (PlotWindowInfo *)client_data;
1211
1196
    string target = get_file(w, client_data, call_data);
1212
 
    if (target == "")
 
1197
    if (target.empty())
1213
1198
        return;
1214
1199
 
1215
1200
    const StringArray& titles  = plot->plotter->data_titles();
1217
1202
 
1218
1203
    string source = "";
1219
1204
    string title  = "";
1220
 
    for (int i = 0; source == "" && i < sources.size(); i++)
 
1205
    for (int i = 0; source.empty() && i < sources.size(); i++)
1221
1206
    {
1222
 
        if (sources[i] != "")
 
1207
        if (!sources[i].empty())
1223
1208
        {
1224
1209
            source = sources[i];
1225
1210
            title  = titles[i];
1226
1211
        }
1227
1212
    }
1228
1213
    
1229
 
    if (source == "")
 
1214
    if (source.empty())
1230
1215
        return;                 // This should not happen
1231
1216
 
1232
1217
    if (access(target.chars(), W_OK) == 0 && is_regular_file(target))
1242
1227
                 XmDIALOG_FULL_APPLICATION_MODAL); arg++;
1243
1228
        confirm_overwrite_dialog = 
1244
1229
            verify(XmCreateQuestionDialog(plot->shell,
1245
 
                                          CONST_CAST(char *,"confirm_overwrite_dialog"), 
 
1230
                                          XMST("confirm_overwrite_dialog"), 
1246
1231
                                          args, arg));
1247
1232
        Delay::register_shell(confirm_overwrite_dialog);
1248
1233
 
1273
1258
    StatusDelay delay("Saving " + title + " data to " + quote(target));
1274
1259
 
1275
1260
    // Copy SOURCE to TARGET
1276
 
    ifstream is(source.chars());
1277
 
    ofstream os(target.chars());
 
1261
    std::ifstream is(source.chars());
 
1262
    std::ofstream os(target.chars());
1278
1263
 
1279
1264
    if (os.bad())
1280
1265
    {
1307
1292
        Cardinal arg = 0;
1308
1293
        Widget dialog = 
1309
1294
            verify(XmCreateFileSelectionDialog(plot->shell, 
1310
 
                                               CONST_CAST(char *,"export_data"), 
 
1295
                                               XMST("export_data"), 
1311
1296
                                               args, arg));
1312
1297
        plot->export_dialog = dialog;
1313
1298
 
1461
1446
        XmCommandError(plot->command, xmsg.xmstring());
1462
1447
    }
1463
1448
 
1464
 
    while (s != "")
 
1449
    while (!s.empty())
1465
1450
    {
1466
1451
        string line;
1467
1452
        if (s.contains('\n'))
1471
1456
        s = s.after('\n');
1472
1457
        strip_space(line);
1473
1458
 
1474
 
        if (line != "")
 
1459
        if (!line.empty())
1475
1460
            set_status(line);
1476
1461
    }
1477
1462
}
1493
1478
    }
1494
1479
 
1495
1480
    s = quote(s);
1496
 
    string nl = string("\\n\"\n") + replicate(string(' '), strlen(prefix)) + "\"";
 
1481
    string nl = "\\n\"\n";
 
1482
    nl += replicate(' ', strlen(prefix));
 
1483
    nl += "\"";
1497
1484
    s.gsub("\\n", nl);
1498
1485
 
1499
1486
    if (s_ends_with_nl)