~ubuntu-branches/ubuntu/utopic/tcm/utopic

« back to all changes in this revision

Viewing changes to src/ed/document.h

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//------------------------------------------------------------------------------
 
2
// 
 
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
 
4
// (c) copyright 1995, Vrije Universiteit Amsterdam.
 
5
// Author: Frank Dehne (frank@cs.vu.nl).
 
6
//
 
7
// TCM is free software; you can redistribute it and/or modify
 
8
// it under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation; either version 2 of the License, or
 
10
// (at your option) any later version.
 
11
//
 
12
// TCM is distributed in the hope that it will be useful,
 
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
// GNU General Public License for more details.
 
16
//
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with TCM; if not, write to the Free Software
 
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
20
// 02111-1307, USA.
 
21
//-----------------------------------------------------------------------------
 
22
#ifndef _DOCUMENT_H
 
23
#define _DOCUMENT_H
 
24
 
 
25
#include "llist.h"
 
26
#include "point.h"
 
27
#include "messagedialog.h"
 
28
#include "drawwindow.h"
 
29
class TextViewDialog;
 
30
class TextEditDialog;
 
31
class FileSelectionDialog;
 
32
class FindDialog;
 
33
class ReplaceDialog;
 
34
class InputFile;
 
35
class OutputFile;
 
36
class Viewer;
 
37
 
 
38
/// (abstract) document class; generalization of diagram, tree, table, etc.
 
39
class Document {
 
40
/*@Doc: {\large {\bf scope:} editor} */
 
41
public:
 
42
        /// 
 
43
        Document(Config *c, EditWindow *d, Viewer *v); 
 
44
        ///
 
45
        virtual ~Document();
 
46
 
 
47
        /// opens new document called untitled.'suffix'.
 
48
        void New();             
 
49
 
 
50
        /// popup file selector dialog for loading a file.
 
51
        virtual void Load();            
 
52
 
 
53
        /// same as load but old document remains unchanged.
 
54
        virtual void Append();  
 
55
 
 
56
        /// save document to file.
 
57
        void Save();
 
58
 
 
59
        /// popup file selector dialog for saving to a file.
 
60
        void SaveAs();          
 
61
 
 
62
        /// popup file selector dialog for saving selection to a file.
 
63
        void SaveSelectionAs();
 
64
 
 
65
        /// closes document (asks confirmation) and quits application.
 
66
        void Quit();            
 
67
 
 
68
        /// popup info dialog containing information about this document.
 
69
        void ShowDocInfo();     
 
70
 
 
71
        /// popup text edit dialog with document source from file.
 
72
        void ShowSource();
 
73
        /// save edited source back to file.
 
74
        void SaveSource();
 
75
 
 
76
        /// popup info dialog containing summary of contents of this document.
 
77
        virtual void ShowSummary(); 
 
78
 
 
79
        /// popup warning dialog containing soft constraint violations (syntactic)
 
80
        virtual void CheckDocument(); 
 
81
 
 
82
        /// popup dialog to model check a temporal logic property (semantic check)
 
83
        virtual void ModelCheckProperty(); 
 
84
 
 
85
       /// clear error trace
 
86
 
 
87
        virtual void ClearTrace();
 
88
 
 
89
        /// popup text edit dialog in which doc. annotation can be given.
 
90
        void Annotate();
 
91
                                
 
92
        /// called from file selector dialog callbacks.
 
93
        void LoadSave(const string *file); 
 
94
 
 
95
        /// load document from file.
 
96
        virtual void DoLoad(const string *file);
 
97
 
 
98
        ///
 
99
        void DoSaveAs(const string *file);
 
100
        ///
 
101
        void DoSaveSelectionAs(const string *file);
 
102
 
 
103
        /// return format that was found in file that is read in.
 
104
        double GetLoadFormat() const {return loadFormat;}
 
105
 
 
106
        /// perform some document type specific initialization.
 
107
        virtual void Initialize();
 
108
 
 
109
        /// Checks if file is legal and opens new document with file as name.
 
110
        void NewFile(const string *file);
 
111
 
 
112
        /// Delete contents of the document.
 
113
        virtual void RemoveAll() = 0; 
 
114
 
 
115
        /// Checks if newname is legal, and if so, changes name of document.
 
116
        bool NewName(const string *newname);
 
117
 
 
118
        /// 
 
119
        void SetName(const string *newname) {name = *newname;}
 
120
 
 
121
        /// 
 
122
        const string *GetName() const {return &name;}
 
123
 
 
124
        /// 
 
125
        const string *GetDocType() const {return &docType;}
 
126
 
 
127
        /// 
 
128
        const string *GetSuffix() const {return &suffix;}
 
129
 
 
130
        ///
 
131
        const string *GetToolName() const {return &toolName;}
 
132
 
 
133
        ///
 
134
        const string *GetAuthor() const {return &author;}
 
135
 
 
136
        ///
 
137
        const string *GetCreationTime() const {return &createdOn;}
 
138
 
 
139
        /// return whether doc.name is the default name.
 
140
        bool IsDefault();
 
141
 
 
142
        /// Checks if newdir is legal, and if so, changes current directory.
 
143
        void NewDir(const string *newdir);
 
144
 
 
145
        /// 
 
146
        void SetDir(const string *newdir) {dir = *newdir;}
 
147
 
 
148
        /// 
 
149
        const string *GetDir() const {return &dir;}
 
150
 
 
151
        /// Set dir from file selector.
 
152
        void SetFSDir();
 
153
 
 
154
        /// increases number of changes.
 
155
        void IncChanges();      
 
156
 
 
157
        /// decrease number of changes.
 
158
        void DecChanges();      
 
159
 
 
160
        /// 
 
161
        int GetChanges() const {return changes;}
 
162
 
 
163
        /// set inline edit (doc. type specific).
 
164
        virtual void SetInlineEdit(bool) {}
 
165
 
 
166
        ///
 
167
        enum MoveType {UP, DOWN, LEFT, RIGHT, CENTER};
 
168
 
 
169
        /// move document in mainwindow.
 
170
        virtual void Move(MoveType) {}
 
171
 
 
172
        /// 
 
173
        bool IsModified() const {return changes > 0;} 
 
174
        /// 
 
175
        void SetModified(bool set) { if (set) changes=1; else changes=0;}
 
176
        ///
 
177
        bool IsLoaded() const {return loaded;}
 
178
 
 
179
        /// ask user to confirm that a file may be overwritten
 
180
        bool MayWrite(const string *path); 
 
181
 
 
182
        /// set main window status message to msg.
 
183
        void SetStatus(const char *msg) {mainwindow->SetStatus(msg);}
 
184
        ///
 
185
        void SetStatus(const string *msg) {mainwindow->SetStatus(msg);}
 
186
 
 
187
        /// set document annotation text to s.
 
188
        void SetAnnotation(const string *s);
 
189
 
 
190
        /// is the document hierarchic?
 
191
        bool IsHierarchic() const {return isHierarchic;}
 
192
        /// sets the hierarchic (editor mode) for the document
 
193
        virtual void SetHierarchic(bool set);
 
194
        /// is it allowed to switch to hierarchic mode? 
 
195
        virtual bool AllowHierarchic() const { return False; }
 
196
 
 
197
        /// find all strings.
 
198
        virtual void FindAll(const string *, bool, bool, bool)=0;
 
199
 
 
200
        /// find next string.
 
201
        virtual void FindNext(const string *, bool, bool, bool) =0;
 
202
 
 
203
        /// replace all strings.
 
204
        virtual void ReplaceAll(const string *, const string *, 
 
205
                bool, bool, bool)=0;
 
206
 
 
207
        /// replace next string.
 
208
        virtual void ReplaceNext(const string *, const string *, 
 
209
                bool, bool, bool)=0;
 
210
 
 
211
        /// issue a popup dialog for getting a search string.
 
212
        virtual void Find();
 
213
 
 
214
        /// issue a popup dialog for search and replace strings.
 
215
        virtual void Replace();
 
216
 
 
217
        /// update main window document text fields
 
218
        void UpdateWindow();
 
219
 
 
220
        /// 
 
221
        EditWindow *GetMainWindow() const {return mainwindow;}
 
222
        ///
 
223
        Config *GetConfig() const {return config;}
 
224
        ///
 
225
        Viewer *GetViewer() const {return viewer;}
 
226
        ///
 
227
        InputFile *GetInputFile() const {return ifile;}
 
228
        ///
 
229
        OutputFile *GetOutputFile() const {return ofile;}
 
230
 
 
231
        ///
 
232
        TextEditDialog *GetSourceEditDialog() const {
 
233
                return sourceEditDialog;}
 
234
        ///
 
235
        TextEditDialog *GetDocAnnotationDialog() const {
 
236
                return docAnnotationDialog;}
 
237
        ///
 
238
        TextEditDialog *GetEltAnnotationDialog() const {
 
239
                return eltAnnotationDialog;}
 
240
        ///
 
241
        FileSelectionDialog *GetFileSelectionDialog() const {
 
242
                return fileSelectionDialog;}
 
243
        ///
 
244
        FindDialog *GetFindDialog() const {return findDialog;}
 
245
 
 
246
        ///
 
247
        ReplaceDialog *GetReplaceDialog() const {return replaceDialog;}
 
248
protected:
 
249
        /// ...
 
250
        virtual void LoadEntries() = 0;
 
251
        /// ...
 
252
        virtual void SaveEntries()=0; 
 
253
        ///
 
254
        bool IsAppending() const {return appending;}
 
255
        ///
 
256
        bool IsSaveSelection() const {return saveSelection;}
 
257
 
 
258
        /// Set directory in all dialogs.
 
259
        virtual void UpdateDirectory(const string *s);
 
260
 
 
261
        ///
 
262
        void ShowDialog(MessageDialog::DialogType t,
 
263
                const char *title, const char *text) const;
 
264
        ///
 
265
        void ShowDialog(MessageDialog::DialogType t,
 
266
                                const char *title, const string *text) const {
 
267
                ShowDialog(t, title, text->getstr());
 
268
        }
 
269
 
 
270
        /// Give results of Check Document in popup dialog.
 
271
        void ReportCheck(int errors, const string *msg);
 
272
 
 
273
        /// message string filled by Check Document.
 
274
        string chkbuf;          
 
275
 
 
276
private:
 
277
// attributes of current tool.
 
278
        /// 
 
279
        EditWindow *mainwindow;
 
280
        ///
 
281
        Viewer *viewer;
 
282
        ///
 
283
        Widget mwwidget;
 
284
 
 
285
        ///
 
286
        TextEditDialog *sourceEditDialog;
 
287
        ///
 
288
        TextEditDialog *docAnnotationDialog;
 
289
        ///
 
290
        TextEditDialog *eltAnnotationDialog;
 
291
        ///
 
292
        FileSelectionDialog *fileSelectionDialog;
 
293
        ///
 
294
        TextViewDialog *checkDialog;
 
295
        ///
 
296
        TextViewDialog *infoDialog;
 
297
        ///
 
298
        FindDialog *findDialog;
 
299
        ///
 
300
        ReplaceDialog *replaceDialog;
 
301
 
 
302
        ///
 
303
        Config *config;
 
304
 
 
305
        ///
 
306
        InputFile *ifile;
 
307
        ///
 
308
        OutputFile *ofile;
 
309
 
 
310
        /// is document currently modified ?
 
311
        int changes;
 
312
 
 
313
        /// is document loaded or created.
 
314
        bool loaded;
 
315
 
 
316
        /// is document loaded (overwritten) or appended.
 
317
        bool appending;
 
318
 
 
319
        /// is selection saved or entire document;
 
320
        bool saveSelection;
 
321
 
 
322
        /// current tool.
 
323
        Toolkit::ToolType tool;
 
324
 
 
325
        /// current document suffix
 
326
        string suffix;
 
327
 
 
328
        /// login of person who runs tool.
 
329
        string login;
 
330
 
 
331
        /// name of the current tool.
 
332
        string toolName;
 
333
 
 
334
        /// current working directory.
 
335
        string dir;
 
336
 
 
337
        /// current version of file format (format that will be written).
 
338
        double fileFormat;
 
339
 
 
340
        ///
 
341
        bool isHierarchic;
 
342
 
 
343
// attributes of document contents.
 
344
        /// current document name.
 
345
        string name;    
 
346
 
 
347
        /// current document type.
 
348
        string docType;
 
349
 
 
350
        /// initial author of the document.
 
351
        string author;  
 
352
 
 
353
        /// creation time and date.
 
354
        string createdOn;
 
355
 
 
356
// attributes of loaded document.
 
357
        /// file name from which document is loaded.
 
358
        string fileName; 
 
359
 
 
360
        /// file format of loaded document.
 
361
        double loadFormat;      
 
362
 
 
363
        /// tool that wrote loaded document.
 
364
        string generatedFrom;
 
365
 
 
366
        /// writing time and date of loaded document.
 
367
        string writtenOn;       
 
368
 
 
369
        /// login that wrote document to file.
 
370
        string writtenBy;       
 
371
 
 
372
        /// document annotation text.
 
373
        string annotation;
 
374
 
 
375
        /// file in which document is saved.
 
376
        string saveName; 
 
377
 
 
378
        /// Create all popup dialog for document class.
 
379
        void CreateDialogs();
 
380
 
 
381
        /// function needed for loading document from file.
 
382
        bool AskSave();         
 
383
 
 
384
        /// ...
 
385
        bool Load(const string *file);
 
386
 
 
387
        /// ...
 
388
        bool LoadDocInfo();
 
389
 
 
390
        /// ...
 
391
        bool CheckDocInfo();
 
392
 
 
393
        ///
 
394
        virtual bool LoadHeader();
 
395
 
 
396
        /// ...
 
397
        virtual bool LoadEditInfo() {return True;}
 
398
 
 
399
        /// ...
 
400
        virtual bool CheckEditInfo() {return True;}
 
401
 
 
402
        /// ...
 
403
        bool CheckFormat();
 
404
 
 
405
        /// ...
 
406
        bool CheckDocumentType();
 
407
 
 
408
protected:
 
409
        /// function needed for saving to file.
 
410
        bool Save(const string *file);
 
411
 
 
412
private:
 
413
        /// ...
 
414
        virtual void SaveDocInfo();
 
415
 
 
416
        /// ...
 
417
        virtual void SaveEditInfo();
 
418
 
 
419
        ///
 
420
        void PrepareSaveDialog();
 
421
};
 
422
#endif