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

« back to all changes in this revision

Viewing changes to src/sd/bv/scdiagram.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 2002, Universiteit Twente.
 
5
// Author: David Jansen (dnjansen@cs.utwente.nl).
 
6
//         Rik Eshuis (eshuis@cs.utwente.nl)
 
7
//         Jose Canete (canete@lsi.us.es)
 
8
//
 
9
// TCM is free software; you can redistribute it and/or modify
 
10
// it under the terms of the GNU General Public License as published by
 
11
// the Free Software Foundation; either version 2 of the License, or
 
12
// (at your option) any later version.
 
13
//
 
14
// TCM 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.  See the
 
17
// GNU General Public License for more details.
 
18
//
 
19
// You should have received a copy of the GNU General Public License
 
20
// along with TCM; if not, write to the Free Software
 
21
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
22
// 02111-1307, USA.
 
23
//-----------------------------------------------------------------------------
 
24
#ifndef _SCDIAGRAM_H
 
25
#define _SCDIAGRAM_H
 
26
 
 
27
#include "diagram.h"
 
28
class SCGraph;
 
29
class SCWindow;
 
30
class SCViewer;
 
31
//class Transition;
 
32
//class InitialState;
 
33
#ifdef MODELCHECK
 
34
class ModelCheckDialog;
 
35
class SCDTransitionEdge;
 
36
class AbstractSequenceDiagram;
 
37
class ConcreteSequenceDiagram;
 
38
#endif
 
39
#include <stdio.h>
 
40
 
 
41
/// state transition diagram class
 
42
class SCDiagram: public Diagram {
 
43
/*@Doc: {\large {\bf scope:} TSCD} */
 
44
public:
 
45
        ///
 
46
        SCDiagram(Config *, SCWindow *, SCViewer *, SCGraph *);
 
47
        ///
 
48
        virtual ~SCDiagram();
 
49
        ///
 
50
        virtual void Initialize();
 
51
        ///
 
52
        Node *CreateNode();
 
53
        ///
 
54
        Edge *CreateEdge(Subject *n1, Subject *n2);
 
55
        ///
 
56
        NodeShape *CreateNodeShape(Node *node, int x, int y);
 
57
        ///
 
58
        Line *CreateLine(Edge *edge, GShape *fromShape, 
 
59
                GShape *toShape, List<Point *> *line);
 
60
        ///
 
61
        void UpdateNodeType(int n);
 
62
        ///
 
63
        void UpdateEdgeType(int n);
 
64
 
 
65
        ///
 
66
        void CheckDocument();
 
67
#ifdef MODELCHECK
 
68
        ///
 
69
        /* virtual */ void ModelCheckProperty();
 
70
#endif
 
71
 
 
72
        ///
 
73
        void ProvideFeedback(SCGraph *ah);
 
74
 
 
75
protected:
 
76
        ///
 
77
        Thing *CreateThing(int classNr);
 
78
        ///
 
79
        bool CheckEdgeConstraints(Subject *s1, Subject *s2);
 
80
        ///
 
81
        bool CheckAndEdgeConstraints(Subject *s1, Subject *s2);
 
82
 
 
83
private:
 
84
#ifdef MODELCHECK
 
85
        ///
 
86
        void DoModelCheckDocument(const string *internal,
 
87
                const string *formula, const string *clock);
 
88
        /// callback for model check document dialog
 
89
        static void ModelCheckDocumentOKCB(Widget, XtPointer,
 
90
                                                        XtPointer);
 
91
        /// saves the current diagram in the model checker formal to *path.
 
92
        void SaveForModelChecker(const string *path, const string *internal,
 
93
                const string *clock, const string *formula);
 
94
        /// calls the model checker for a diagram saved in *path.
 
95
        bool ExecuteModelChecker(const string *path, const string *formula);
 
96
 
 
97
        /// computes the current step of firing transitions.
 
98
        List<SCDTransitionEdge *> ComputeMicroStep (SCGraph *gr, int state);
 
99
 
 
100
        /// Creates the abstract representation for a sequence diagram from
 
101
        /// NuSMV counterexample. This method should be called after the counterexample
 
102
        /// has been produced!
 
103
        AbstractSequenceDiagram * GenerateAbstractSequenceDiagram ();
 
104
        ///
 
105
        bool IsBroadcast (string event, List<SCDTransitionEdge *> step);
 
106
        /// Creates a possible layout from the abstract representation of the sequence diagram.
 
107
        ConcreteSequenceDiagram * GenerateConcreteSeqDiag (AbstractSequenceDiagram *asd);
 
108
        /// Generates the file with the sequence diagram.
 
109
        void GenerateSeqDiagFile (ConcreteSequenceDiagram *csd, const string *formula);
 
110
        ///
 
111
        void GenerateGraphNodes (ConcreteSequenceDiagram *csd, OutputFile *fp);
 
112
        ///
 
113
        void GenerateComments (ConcreteSequenceDiagram *csd, OutputFile *fp);
 
114
        ///
 
115
        void GenerateGraphEdges (ConcreteSequenceDiagram *csd, OutputFile *fp);
 
116
        ///
 
117
        void GenerateObjectBoxes (ConcreteSequenceDiagram *csd, OutputFile *fp);
 
118
        ///
 
119
        void GenerateT4Lines (ConcreteSequenceDiagram *csd, OutputFile *fp);
 
120
        ///
 
121
        void GenerateTextBoxes (ConcreteSequenceDiagram *csd, OutputFile *fp);
 
122
        ///
 
123
        void GenerateNote (ConcreteSequenceDiagram *csd, OutputFile *fp, const string *formula);
 
124
        ///
 
125
        void GenerateNoteBox (ConcreteSequenceDiagram *csd, OutputFile *fp);
 
126
        /// used for model checking
 
127
        ModelCheckDialog *promptDialog;
 
128
#endif
 
129
}; // end class SCDiagram
 
130
 
 
131
 
 
132
/*
 
133
 *
 
134
 * Classes for generating a Sequence Diagram. They should be moved to on a separate file.
 
135
 *
 
136
 *
 
137
 *
 
138
 */
 
139
 
 
140
 
 
141
class PairObjEv
 
142
{
 
143
 public:
 
144
  PairObjEv (int object, string event) : obj(object), ev(event) {}
 
145
  int GetObj () {return obj;}
 
146
  string GetEv () {return ev;}
 
147
  void PrintIt () {
 
148
        std::cout << "(" << obj << "," << ev.getstr() << ")" << std::endl; }
 
149
 
 
150
 private:
 
151
  int obj;
 
152
  string ev;
 
153
};
 
154
 
 
155
class InteractionParticipant
 
156
{
 
157
 public:
 
158
  int GetNumberOfEvents () {return eventsToSend.count();}
 
159
  void AddPairObjEv (int object, string event);
 
160
  PairObjEv * GetPairObjEv (int i) {if (i<0 || i>static_cast<int>(eventsToSend.count()-1)) return NULL; else return eventsToSend[i];}
 
161
  void SetId (int i) {id= i;}
 
162
  int GetId () {return id;}
 
163
  void PrintIt ();
 
164
 private:
 
165
   List<PairObjEv *> eventsToSend;
 
166
   int id; //the id of the participant in the abstract sequence diagram
 
167
 
 
168
};
 
169
 
 
170
class InteractionRow
 
171
{
 
172
 public:
 
173
 
 
174
  InteractionParticipant * participants; //array [numObj] of InteractionParticipant
 
175
 
 
176
  InteractionRow (int n, int cs) : numObj(n), currentState(cs) {
 
177
      participants= new InteractionParticipant[numObj];
 
178
      for (int i=0; i< numObj; i++)
 
179
           participants[i].SetId(i);
 
180
  }
 
181
  int GetNumberOfParticipants () {return numObj;}
 
182
  int GetCurrentState () {return currentState;}
 
183
  void PrintIt ();
 
184
 private:
 
185
  int numObj;
 
186
  int currentState;
 
187
};
 
188
 
 
189
 
 
190
 
 
191
class AbstractSequenceDiagram
 
192
{
 
193
 public:
 
194
  List<InteractionRow *> rows;
 
195
  List<string> objNames;
 
196
  int numObjs;
 
197
 
 
198
  AbstractSequenceDiagram () : numObjs(0) {}
 
199
 
 
200
  void AddParticipant (string name) {objNames.add(name); numObjs++; }
 
201
  InteractionRow * AddRow (int cs); 
 
202
 
 
203
  void PrintIt ();
 
204
};
 
205
 
 
206
 
 
207
 
 
208
class ConcreteParticipant;
 
209
 
 
210
class StimulusInfo
 
211
{
 
212
 public:
 
213
  ConcreteParticipant *sender;
 
214
  ConcreteParticipant *receiver;
 
215
  string label;
 
216
  int logicalId; // logical id in the seq.diag.
 
217
  int shapeId; // shape id in the seq.diag.
 
218
  int y;  //the place of the stimulus in the temporal line
 
219
  bool isComment; //if True, this is a false stimulus, i.e. a comment: "stable" and "microstep"
 
220
};
 
221
 
 
222
 
 
223
class Stimulus
 
224
{
 
225
 public:
 
226
  bool isSender;
 
227
  StimulusInfo *info;
 
228
};
 
229
 
 
230
 
 
231
class ConcreteParticipant
 
232
{
 
233
 public:
 
234
  string name;
 
235
  int logicalId;
 
236
  int shapeId;
 
237
  int x, y;
 
238
  List<Stimulus *> anchors;
 
239
};
 
240
 
 
241
 
 
242
 
 
243
class ConcreteSequenceDiagram
 
244
{
 
245
  int counter;
 
246
 
 
247
 public:
 
248
  List<ConcreteParticipant *> participants;
 
249
  List<StimulusInfo *> stimuli;
 
250
  int lineLength; //end position of the lifelines
 
251
 
 
252
  ConcreteSequenceDiagram() : counter(1) {}
 
253
 
 
254
  int NextId () { counter++; return counter;}
 
255
 
 
256
 
 
257
};
 
258
 
 
259
 
 
260
 
 
261
 
 
262
#endif