File: BrowserDiagram.cpp

package info (click to toggle)
bouml 4.21-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 73,336 kB
  • ctags: 55,459
  • sloc: cpp: 290,644; makefile: 228; sh: 13
file content (215 lines) | stat: -rw-r--r-- 6,080 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// *************************************************************************
//
// Copyright 2004-2010 Bruno PAGES  .
//
// This file is part of the BOUML Uml Toolkit.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// e-mail : bouml@free.fr
// home   : http://bouml.free.fr
//
// *************************************************************************





#include "BrowserDiagram.h"
#include "BrowserClassDiagram.h"
#include "BrowserSeqDiagram.h"
#include "BrowserColDiagram.h"
#include "BrowserUseCaseDiagram.h"
#include "BrowserStateDiagram.h"
#include "BrowserActivityDiagram.h"
#include "BrowserComponentDiagram.h"
#include "BrowserDeploymentDiagram.h"
#include "BrowserObjectDiagram.h"
#include "BrowserActivityDiagram.h"
#include "BrowserView.h"
#include "Settings.h"
#include "UmlWindow.h"
#include "myio.h"

// use the same extension for all the diagrams : must share dict
IdDict<BrowserDiagram> BrowserDiagram::all(257, __FILE__);

BrowserDiagram::BrowserDiagram(QString s, BrowserNode * parent, int id)
    : BrowserNode(s, parent), Labeled<BrowserDiagram>(all, id) {
  canvas_size = UmlWindow::default_format();
  
  if (id == 0) {
    // delete files in case one re-use the id of
    // a previously deleted diagram
    QString fn = 
      BrowserView::get_dir().absFilePath(QString::number(get_ident()) + ".d");
    
    QFile::remove(fn);
    QFile::remove(fn + "iagram");
  }
}

BrowserDiagram::BrowserDiagram(int id)
    : BrowserNode(), Labeled<BrowserDiagram>(all, id) {
  canvas_size = IsoA4;
}

BrowserDiagram::~BrowserDiagram() {
}

BrowserNodeList & BrowserDiagram::instances(BrowserNodeList & result, bool sort)
{
  IdIterator<BrowserDiagram> it(all);
  BrowserDiagram * d;

  while ((d = it.current()) != 0) {
    if (!d->deletedp())
      result.append(d);
    ++it;
  }

  if (sort)
    result.sort_it();

  return result;
}

void BrowserDiagram::package_modified() {
  if (!on_load_diagram()) {
    is_modified = TRUE;
    BrowserNode::package_modified();
  }
}

void BrowserDiagram::read_stereotypes(char * & st, char * & k)
{
  BrowserClassDiagram::read_stereotypes(st, k);		// updates k
  BrowserSeqDiagram::read_stereotypes(st, k);		// updates k
  BrowserColDiagram::read_stereotypes(st, k);		// updates k
  BrowserUseCaseDiagram::read_stereotypes(st, k);	// updates k
  if (read_file_format() >= 21)
    BrowserStateDiagram::read_stereotypes(st, k);	// updates k
  if (read_file_format() >= 25)
    BrowserActivityDiagram::read_stereotypes(st, k);	// updates k
  BrowserComponentDiagram::read_stereotypes(st, k);	// updates k
  BrowserDeploymentDiagram::read_stereotypes(st, k);	// updates k
}

void BrowserDiagram::save_stereotypes(QTextStream & st)
{
  BrowserClassDiagram::save_stereotypes(st);
  BrowserSeqDiagram::save_stereotypes(st);
  BrowserColDiagram::save_stereotypes(st);
  BrowserUseCaseDiagram::save_stereotypes(st);
  BrowserStateDiagram::save_stereotypes(st);
  BrowserActivityDiagram::save_stereotypes(st);
  BrowserComponentDiagram::save_stereotypes(st);
  BrowserDeploymentDiagram::save_stereotypes(st);
}
 
void BrowserDiagram::save() {
  // diagram is modified
  char * diagram_def = 
    read_definition(get_ident(), "d");
  
  if (diagram_def != 0) {
    save_definition(get_ident(), "diagram", diagram_def, is_new);
    delete [] diagram_def;
  }
}

void BrowserDiagram::clear(bool old)
{
  all.clear(old);
}

void BrowserDiagram::update_idmax_for_root()
{
  all.update_idmax_for_root();
}

void BrowserDiagram::prepare_update_lib() const {
  all.memo_id_oid(get_ident(), original_id);
}

void BrowserDiagram::support_file(QDict<char> & files, bool add) const {
  QString s;
  
  s = s.setNum(get_ident()) + ".diagram";
  
  if (add)
    files.insert(s, (char *) 1);
  else
    files.remove(s);
  
  for (QListViewItem * child = firstChild();
       child != 0;
       child = child->nextSibling())
    ((BrowserNode *) child)->support_file(files, add);
}
    
void BrowserDiagram::import()
{
  BrowserClassDiagram::import();
  BrowserComponentDiagram::import();
  BrowserDeploymentDiagram::import();
  BrowserUseCaseDiagram::import();
  BrowserSeqDiagram::import();
  BrowserColDiagram::import();  
  BrowserStateDiagram::import();
  BrowserObjectDiagram::import();
  BrowserActivityDiagram::import();
}

BrowserNode * BrowserDiagram::read_any_ref(char * & st, char * k) {
  BrowserNode * bn;

  if (((bn = BrowserClassDiagram::read(st, k, 0)) == 0) &&
      ((bn = BrowserColDiagram::read(st, k, 0)) == 0) &&
      ((bn = BrowserSeqDiagram::read(st, k, 0)) == 0) &&
      ((bn = BrowserUseCaseDiagram::read(st, k, 0)) == 0) &&
      ((bn = BrowserComponentDiagram::read(st, k, 0)) == 0) &&
      ((bn = BrowserDeploymentDiagram::read(st, k, 0)) == 0) &&
      ((bn = BrowserStateDiagram::read(st, k, 0)) == 0) &&
      ((bn = BrowserObjectDiagram::read(st, k, 0)) == 0))
    bn = BrowserActivityDiagram::read(st, k, 0);

  return bn;
}

BrowserNode * BrowserDiagram::read_diagram_ref(char * & st)
{
  char * k = read_keyword(st);
  BrowserNode * bn = read_any_ref(st, k);
  
  if (bn == 0)
    unknown_keyword(k);
  
  return bn;  
}

void BrowserDiagram::get_componentdrawingsettings(ComponentDrawingSettings &) const {
  // never called
}

bool BrowserDiagram::get_classinstwritehorizontally() const {
  // never called
  return FALSE;
}

ShowContextMode BrowserDiagram::get_classinstshowmode() const {
  // never called
  return noContext;
}