~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/sd/bv/pschecks.c

  • 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 1997, 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
#include "pschecks.h"
 
23
#include "graph.h"
 
24
#include "edge.h"
 
25
#include "gshape.h"
 
26
#include "psprocess.h"
 
27
#include "diagramviewer.h"
 
28
#include "diagram.h"
 
29
 
 
30
PSChecks::PSChecks(Diagram *d, Graph *g): DiagramChecks(d, g) { }
 
31
 
 
32
unsigned PSChecks::CheckRootOperator(PSProcess *p, string &chkbuf) {
 
33
        unsigned errors = 0;
 
34
        chkbuf +="* Remark: process '";
 
35
        chkbuf += *p->GetName();
 
36
        chkbuf += "' is considered as the root\n";
 
37
        char c;
 
38
        if ((c = p->GetOperator()) != ' ') {
 
39
                chkbuf +="* Error: root process '";
 
40
                chkbuf += *p->GetName();
 
41
                chkbuf += "' has the illegal operator '";
 
42
                chkbuf.add(c);
 
43
                chkbuf += "'\n";
 
44
                GetDiagram()->SelectSubject(p);
 
45
                errors++;
 
46
        }
 
47
        return errors;
 
48
}
 
49
 
 
50
unsigned PSChecks::CheckChildPositions(DiagramViewer *dviewer,
 
51
                PSProcess *parent, List<Subject *> *children, string &chkbuf){
 
52
        unsigned errors = 0;
 
53
        Shape *pshape = dviewer->GetShape(parent);
 
54
        Point ppos = *pshape->GetPosition();
 
55
        for (children->first(); !children->done(); children->next()) {
 
56
                Subject *child = children->cur();
 
57
                Shape *cshape = dviewer->GetShape(child);
 
58
                Point cpos = *cshape->GetPosition();
 
59
                // child is not lower than the parent.
 
60
                if (cpos.y <= ppos.y) {
 
61
                        chkbuf +="* Warning: the process '";
 
62
                        chkbuf += *parent->GetName();
 
63
                        chkbuf += "' should better be positioned ";
 
64
                        chkbuf += "above its child process '";
 
65
                        chkbuf += *child->GetName();
 
66
                        chkbuf += "'\n";
 
67
                        GetDiagram()->SelectSubject(parent);
 
68
                        GetDiagram()->SelectSubject(child);
 
69
                        errors++;
 
70
                        break;
 
71
                }
 
72
        }
 
73
        return errors;
 
74
}
 
75
 
 
76
unsigned PSChecks::CheckChildOperators(PSProcess *parent, 
 
77
                List<Subject *> *children, string &chkbuf){
 
78
        unsigned errors = 0;
 
79
        // There are no children.
 
80
        if (!children->first())
 
81
                return 0;
 
82
        else if (*parent->GetName() %= "QUIT") {
 
83
                chkbuf +="* Error: a '";
 
84
                chkbuf += *parent->GetName();
 
85
                chkbuf += "' process should not have children\n";
 
86
                GetDiagram()->SelectSubject(parent);
 
87
                errors++;
 
88
                return errors;
 
89
        }
 
90
        PSProcess *child = (PSProcess *)children->cur();
 
91
        char basis_c = child->GetOperator();
 
92
        if (basis_c == ' ') { // all remaining children should be a 'sequence'.
 
93
                while (children->next()) {
 
94
                        child = (PSProcess *)children->cur();
 
95
                        char c = child->GetOperator();
 
96
                        if (c != basis_c) {
 
97
                                if (c == '*') {
 
98
                                        chkbuf +="* Error: process '";
 
99
                                        chkbuf += *parent->GetName();
 
100
                                        chkbuf += "' has a non-single '*'"; 
 
101
                                        chkbuf += "(iteration) child\n";
 
102
                                }
 
103
                                else {
 
104
                                        chkbuf +="* Error: some children of process '";
 
105
                                        chkbuf += *parent->GetName();
 
106
                                        chkbuf +="' have different operators '";
 
107
                                        chkbuf.add(basis_c);
 
108
                                        chkbuf += "' and '";
 
109
                                        chkbuf.add(c);
 
110
                                        chkbuf += "'\n";
 
111
                                }
 
112
                                errors++;
 
113
                                break;
 
114
                        }
 
115
                }
 
116
        }
 
117
        else if (basis_c == '*') { // there should be no other children.
 
118
                if (children->next()) {
 
119
                        chkbuf +="* Error: process '";
 
120
                        chkbuf += *parent->GetName();
 
121
                        chkbuf += "' has a non-single '*'"; 
 
122
                        chkbuf += " (iteration) child\n";
 
123
                        errors++;
 
124
                }
 
125
        }
 
126
        else if (basis_c == 'o') { // >= 1 remaining children. All children should be choices.
 
127
                if (!children->next()) {
 
128
                        chkbuf +="* Error: process '";
 
129
                        chkbuf += *parent->GetName();
 
130
                        chkbuf += "' has a single 'o' (choice) child\n";
 
131
                        errors++;
 
132
                }
 
133
                else {
 
134
                        for (children->first(); !children->done(); children->next()) {
 
135
                                child = (PSProcess *)children->cur();
 
136
                                char c = child->GetOperator();
 
137
                                if (c != basis_c) {
 
138
                                        if (c == '*') {
 
139
                                                chkbuf +="* Error: process '";
 
140
                                                chkbuf += *parent->GetName();
 
141
                                                chkbuf += "' has a non-single ";
 
142
                                                chkbuf += "'*' (iteration) child";
 
143
                                        }
 
144
                                        else {
 
145
                                                chkbuf +="* Error: the ";
 
146
                                                chkbuf += "children of process '";
 
147
                                                chkbuf += *parent->GetName();
 
148
                                                chkbuf += "' have different operators '";
 
149
                                                chkbuf.add(basis_c);
 
150
                                                chkbuf += "' and '";
 
151
                                                chkbuf.add(c);
 
152
                                                chkbuf += "'\n";
 
153
                                        }
 
154
                                        errors++;
 
155
                                        break;
 
156
                                }
 
157
                        }
 
158
                }
 
159
        }
 
160
        else if (basis_c == '?') { // the name is 'POSIT'. The other child is named 'ADMIT'.
 
161
                if (! parent->IsRoot()) {
 
162
                        chkbuf +="* Error: non-root process '";
 
163
                        chkbuf += *parent->GetName();
 
164
                        chkbuf += "' should not have children with a '?'\n";
 
165
                        errors++;
 
166
                }
 
167
 
 
168
                string s = *(child->GetName());
 
169
                if (! (s %= "POSIT")) {
 
170
                        chkbuf +="* Error: the first child of process '";
 
171
                        chkbuf += *parent->GetName();
 
172
                        chkbuf +="' is expected to have as name 'POSIT'\n";
 
173
                        errors++;
 
174
                }
 
175
                else if (!children->next() || 
 
176
                         !(*children->cur()->GetName() %= "ADMIT") || 
 
177
                        (((PSProcess *)(children->cur()))->GetOperator() != '?')) {
 
178
                        chkbuf +="* Error: process '";
 
179
                        chkbuf += *parent->GetName();
 
180
                        chkbuf += "' is expected to have a second "; 
 
181
                        chkbuf += "child named 'ADMIT' with a '?'\n";
 
182
                        errors++;
 
183
                }
 
184
                else if (children->next()) {
 
185
                        chkbuf +="* Error: process '";
 
186
                        chkbuf += *parent->GetName();
 
187
                        chkbuf +="' is expected to have exactly two children\n"; 
 
188
                        errors++;
 
189
                }
 
190
        }
 
191
        else if (basis_c == '!') { // the name is [qQ][Uu][Ii][Tt]
 
192
                string s = *(child->GetName());
 
193
                if (! (s %= "QUIT")) {
 
194
                        chkbuf +="* Error: the child of process '";
 
195
                        chkbuf += *parent->GetName();
 
196
                        chkbuf += "' is expected to have name 'QUIT'\n";
 
197
                        errors++;
 
198
                }
 
199
                else if (children->next()) {
 
200
                        chkbuf +="* Error: process '";
 
201
                        chkbuf += *parent->GetName();
 
202
                        chkbuf += "' is expected to have a ";
 
203
                        chkbuf += "single child\n"; 
 
204
                        errors++;
 
205
                }
 
206
        }
 
207
        else {
 
208
                chkbuf +="* Error: process '";
 
209
                chkbuf += *parent->GetName();
 
210
                chkbuf += "' has the illegal operator '";
 
211
                chkbuf.add(basis_c);
 
212
                chkbuf += "'\n";
 
213
                errors++;
 
214
        }
 
215
        if (errors > 0) {
 
216
                GetDiagram()->SelectSubject(parent);
 
217
                GetDiagram()->SelectSubjects(children);
 
218
        }
 
219
        return errors;
 
220
}
 
221
 
 
222
unsigned PSChecks::CheckDoubleProcessNames(string &chkbuf) {
 
223
        unsigned total = 0;
 
224
        int nodetype = Code::PS_PROCESS;
 
225
        List<Subject *> nodes;
 
226
        List<Subject *> doublenodes;
 
227
        List<string> strings_got;
 
228
        GetGraph()->GetNodes(&nodes, nodetype);
 
229
        for (nodes.first(); !nodes.done(); nodes.next()) {
 
230
                PSProcess *proc = (PSProcess *) nodes.cur();
 
231
                const string *s = proc->GetName();
 
232
                if (*s != "" && strings_got.find(*s) == -1) {
 
233
                        doublenodes.empty();
 
234
                        GetGraph()->GetNodes(&doublenodes, s, nodetype);
 
235
                        if (doublenodes.count() > 1) {
 
236
                                for (doublenodes.first(); !doublenodes.done(); 
 
237
                                     doublenodes.next()) {
 
238
                                        PSProcess *p = (PSProcess *)doublenodes.cur();
 
239
                                        // all double names processes should 
 
240
                                        // be leaves (actions).
 
241
                                        if (!p->IsAction()) {
 
242
                                                chkbuf += "* Error: "; 
 
243
                                                chkbuf += doublenodes.count();
 
244
                                                chkbuf += " processes";
 
245
                                                chkbuf += " are named '";
 
246
                                                chkbuf += *s;
 
247
                                                chkbuf += "' but they are not all actions\n";
 
248
                                                GetDiagram()->SelectSubjects(&doublenodes);
 
249
                                                total++;
 
250
                                                break;
 
251
                                        }
 
252
                                }
 
253
                        }
 
254
                        strings_got.add(*s);
 
255
                }
 
256
        }
 
257
        return total;
 
258
}