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

« back to all changes in this revision

Viewing changes to src/st/fetable.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 1996, 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 "fewindow.h"
 
23
#include "feviewer.h"
 
24
#include "fetable.h"
 
25
#include "cellrow.h"
 
26
#include "cellcolumn.h"
 
27
#include "cell.h"
 
28
#include "messagedialog.h"
 
29
 
 
30
FETable::FETable(Config *c, FEWindow *t, FEViewer *v): Matrix(c, t, v) { }
 
31
 
 
32
bool FETable::CheckTextString(Cell *c, const string *text) {
 
33
        if (!Matrix::CheckTextString(c, text))
 
34
                return False;
 
35
        // Check for crud entries.
 
36
        if (c->GetRow()->GetNumber() >=1 && c->GetColumn()->GetNumber() >= 1) {
 
37
                if (IsCRUD(text))
 
38
                        return True;
 
39
                ShowDialog(MessageDialog::ERROR, "Error", 
 
40
                                "A `CRUD' string is expected here");
 
41
                return False;
 
42
        }
 
43
        return True;
 
44
}
 
45
 
 
46
bool FETable::IsCRUD(const string *text) {
 
47
        bool C=False, D=False, U=False, R=False;
 
48
        for (unsigned i=0;i<text->length();i++) {
 
49
                switch((*text)[i]) {
 
50
                case 'C': if (C) return False; C=True; break;
 
51
                case 'D': if (D) return False; D=True; break;
 
52
                case 'U': if (U) return False; U=True; break;
 
53
                case 'R': if (R) return False; R=True; break;
 
54
                default: return False;
 
55
                }
 
56
        }
 
57
        return True;
 
58
}
 
59
 
 
60
unsigned FETable::CountCEntries(unsigned n) {
 
61
        unsigned total = 0;
 
62
        CellRow *row = GetTableViewer()->GiveRow(n);
 
63
        Cell *cell;
 
64
        if (row && (cell=row->FirstCell())) {
 
65
                while ((cell=row->NextCell())) {
 
66
                        const string *s = cell->GetText();
 
67
                        for (unsigned i=0; i<s->length(); i++) {
 
68
                                if ((*s)[i] == 'C')
 
69
                                        total++;
 
70
                        }
 
71
                }
 
72
        }
 
73
        return total;
 
74
}
 
75
 
 
76
void FETable::CheckDocument() {
 
77
        chkbuf = "";
 
78
        unsigned total = 0;
 
79
        // Check missing entity type names.
 
80
        unsigned n = CheckEmptyRowEntries(0);
 
81
        if (n > 0) {
 
82
                chkbuf += "* Error: ";
 
83
                chkbuf += n;
 
84
                chkbuf += " entity type";
 
85
                if (n!=1)
 
86
                        chkbuf += "s";
 
87
                chkbuf += " in column 0 ";
 
88
                (n == 1) ? (chkbuf += "is"): (chkbuf += "are");
 
89
                chkbuf += " still empty\n";
 
90
                total += n;
 
91
        }
 
92
        // Check missing function names.
 
93
        n = CheckEmptyColumnEntries(0);
 
94
        if (n > 0) {
 
95
                chkbuf += "* Error: ";
 
96
                chkbuf += n;
 
97
                chkbuf += " function";
 
98
                if (n!=1)
 
99
                        chkbuf += "s";
 
100
                chkbuf += " in row 0 ";
 
101
                (n == 1) ? (chkbuf += "is"): (chkbuf += "are");
 
102
                chkbuf += " still empty\n";
 
103
                total += n;
 
104
        }
 
105
        // Check for functions without entries (warning).
 
106
        unsigned i;
 
107
        for (i=1; i<GetTableViewer()->GetNumberOfColumns(); i++) {
 
108
                CellColumn *column = GetTableViewer()->GiveColumn(i);
 
109
                if (column && *column->FirstCell()->GetText() != "") {
 
110
                        unsigned j = CheckEmptyRowEntries(i);
 
111
                        if (j == GetTableViewer()->GetNumberOfRows()-1) {
 
112
                                chkbuf += "* Warning: the function in column ";
 
113
                                chkbuf += i;
 
114
                                chkbuf += " does not do anything\n";
 
115
                                GetTableViewer()->SelectCell(column->FirstCell());
 
116
                                total += 1;
 
117
                        }
 
118
                }
 
119
        }
 
120
        // Check for entity types without a C.
 
121
        for (i=1; i<GetTableViewer()->GetNumberOfRows(); i++) {
 
122
                CellRow *row = GetTableViewer()->GiveRow(i);
 
123
                if (row && *row->FirstCell()->GetText() != "") {
 
124
                        unsigned j = CountCEntries(i);
 
125
                        if (j == 0) {
 
126
                                chkbuf += "* Warning: the entity type in row ";
 
127
                                chkbuf += i;
 
128
                                chkbuf += " does not have a creation\n";
 
129
                                GetTableViewer()->SelectCell(row->FirstCell());
 
130
                                total += 1;
 
131
                        }
 
132
                }
 
133
        }
 
134
        // Check for entries that are no CRUD strings.
 
135
        for (i=1; i<GetTableViewer()->GetNumberOfRows(); i++) {
 
136
                CellRow *row = GetTableViewer()->GiveRow(i);
 
137
                for (unsigned j=1; 
 
138
                                j<GetTableViewer()->GetNumberOfColumns(); j++) {
 
139
                        if (check(row)) {
 
140
                                Cell *cell = row->NthCell(j);
 
141
                                if (check(cell)) {
 
142
                                        const string *s = cell->GetText();
 
143
                                        if (!IsCRUD(s)) {
 
144
                                                chkbuf += "* Error: cell ";
 
145
                                                chkbuf += i;
 
146
                                                chkbuf += ",";
 
147
                                                chkbuf += j;
 
148
                                                chkbuf += " does not contain";
 
149
                                                chkbuf += " a CRUD string\n";
 
150
                                                GetTableViewer()->SelectCell(cell);
 
151
                                                total += 1;
 
152
                                        }
 
153
                                }
 
154
                        }
 
155
                        
 
156
                }
 
157
        }
 
158
        ReportCheck(total, &chkbuf);
 
159
}