File: workbench_physical_model_impl.cpp

package info (click to toggle)
mysql-workbench 6.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 113,932 kB
  • ctags: 87,814
  • sloc: ansic: 955,521; cpp: 427,465; python: 59,728; yacc: 59,129; xml: 54,204; sql: 7,091; objc: 965; makefile: 638; sh: 613; java: 237; perl: 30; ruby: 6; php: 1
file content (361 lines) | stat: -rw-r--r-- 11,524 bytes parent folder | download | duplicates (2)
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/* 
 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
 *
 * 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; version 2 of the
 * License.
 * 
 * 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., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#include "workbench_physical_model_impl.h"
#include "workbench_physical_diagram_impl.h"
#include "workbench_physical_connection_impl.h"

#include "grt/grt_manager.h"

#include "table_figure_wb.h"
#include "table_figure_idef1x.h"
#include "table_figure_simple.h"



workbench_physical_Model::ImplData::ImplData(workbench_physical_Model *self)
: super(self)
{
  _relationship_notation= PRCrowFoofnotation;
  _figure_notation= PFWorkbenchNotation;
  
  scoped_connect(self->signal_changed(),boost::bind(&ImplData::member_changed_comm, this, _1, _2));
  
  scoped_connect(self->signal_list_changed(),boost::bind(&ImplData::list_changed, this, _1, _2, _3));
  scoped_connect(self->signal_dict_changed(),boost::bind(&ImplData::dict_changed, this, _1, _2, _3));
  grt::GRTNotificationCenter::get()->add_grt_observer(this, "GRNPreferencesDidClose");
  
  if (self->tags().count() > 0) g_warning("tagcount in model starts > 0");
}

void workbench_physical_Model::ImplData::handle_grt_notification(const std::string &name, grt::ObjectRef sender, grt::DictRef info)
{
//  if (name == "GRNPreferencesDidClose" && info.get_int("saved") == 1)
  {
//    run_later(boost::bind(&workbench_physical_Model::ImplData::reset_figures, this));
//    run_later(boost::bind(&workbench_physical_Model::ImplData::reset_connections, this));
  }
}

workbench_physical_Model::ImplData::~ImplData()
{
  grt::GRTNotificationCenter::get()->remove_grt_observer(this);
}

void workbench_physical_Model::ImplData::member_changed_comm(const std::string &name, const grt::ValueRef &ovalue)
{
  PhysicalRelationshipNotation rnot;
  PhysicalFigureNotation fnot;
  if (name == "connectionNotation")
  {
    std::string s= self()->_connectionNotation;
    if (s == "classic") rnot= PRClassicNotation;
    else if (s == "idef1x") rnot= PRIdef1xNotation;
    else if (s == "crowsfoot" || s == "ie") rnot= PRCrowFoofnotation;
    else if (s == "barker") rnot= PRBarkerNotation;
    else if (s == "uml") rnot= PRUMLNotation;
    else if (s == "fromcolumn") rnot= PRFromColumnNotation;
    else rnot= PRCrowFoofnotation;
    if (_relationship_notation != rnot)
    {
      _relationship_notation= rnot;
      run_later(boost::bind(&workbench_physical_Model::ImplData::reset_connections, this));
    }
  }
  else if (name == "figureNotation")
  {
    std::string s= self()->_figureNotation;
    if (s == "workbench" || s == "workbench/default") fnot= PFWorkbenchNotation;
    else if (s == "workbench/simple") fnot= PFWorkbenchSimpleNotation;
    else if (s == "workbench/pkonly") fnot= PFWorkbenchPKOnlyNotation;
    else if (s == "idef1x") fnot= PFIdef1xNotation;
    else if (s == "classic") fnot= PFClassicNotation;
    else if (s == "barker") fnot= PFBarkerNotation;
    else fnot= PFWorkbenchNotation;
    if (_figure_notation != fnot)
    {
      _figure_notation= fnot;
      run_later(boost::bind(&workbench_physical_Model::ImplData::reset_figures, this));
      run_later(boost::bind(&workbench_physical_Model::ImplData::reset_connections, this));  /* needed to restore the connection attachments */ 
    }
  }
}


mdc::LineEndType workbench_physical_Model::ImplData::get_line_end_type(bool mand, bool many, bool start)
{
  switch (_relationship_notation)
  {
  case PRIdef1xNotation:
    if (start)
      return mdc::FilledCircleEnd;
    else
      if (!mand) return mdc::HollowDiamondEnd; else return mdc::NormalEnd;
  case PRCrowFoofnotation:
    if (mand && many) return mdc::ChickenFoot1End;
    else if (!mand && many) return mdc::ChickenFoot0End;
    else if (mand && !many) return mdc::Cross1End;
    else return mdc::Cross0End;
  case PRBarkerNotation:
    if (many) return mdc::ChickenFootEnd;
    else return mdc::NormalEnd;
  case PRFromColumnNotation:
    return mdc::BoldStickEnd;
  case PRClassicNotation:
  case PRUMLNotation:
    return mdc::NormalEnd;
  }
  return mdc::NormalEnd;
}


std::string workbench_physical_Model::ImplData::get_line_end_caption(bool mand, bool many, bool start)
{
  switch (_relationship_notation)
  {
  case PRIdef1xNotation:
    if (start)
    {
      if (!mand && many) return "";
      else if (!mand && !many) return "Z";
      else if (mand && many)  return "P";
      else if (mand && !many) return "1";
    }
    break;

  case PRFromColumnNotation:
    //TODO: if else has same code is this intentional
    if (start)
    {
      if (many) return "\xe2\x88\x9e";
      else return "1";
    }
    else
    {
      if (many) return "\xe2\x88\x9e";
      else return "1";
    }
    break;
  case PRCrowFoofnotation:
  case PRBarkerNotation:
    break;

  case PRClassicNotation:
  case PRUMLNotation:
    //TODO: if else has same code is this intentional
    if (start)
    {
      if (!mand && many) return "0..*";
      else if (!mand && !many) return "0..1";
      else if (mand && many)  return "1..*";
      else if (mand && !many) return "1";
    }
    else
    {
      if (!mand && many) return "0..*";
      else if (!mand && !many) return "0..1";
      else if (mand && many) return "1..*";
      else if (mand && !many) return "1";
    }
    break;
  }
  return "";
}


void workbench_physical_Model::ImplData::update_relationship_figure(model_Connection::ImplData *cfig, bool imandatory, bool imany, bool fmandatory, bool fmany)
{
  wbfig::Connection *conn= dynamic_cast<wbfig::Connection*>(cfig->get_canvas_item());
  if (conn)
  {
    conn->set_end_type(get_line_end_type(imandatory, imany, true),
                       get_line_end_type(fmandatory, fmany, false));
    
    cfig->set_start_caption(get_line_end_caption(imandatory, imany, true));
    cfig->set_end_caption(get_line_end_caption(fmandatory, fmany, false));
    
    if (_relationship_notation == PRBarkerNotation)
    {
      conn->set_start_dashed(imandatory);
      conn->set_end_dashed(fmandatory);
    }
    else if (_relationship_notation == PRClassicNotation)
    {
      if (imany && fmany)
        conn->set_diamond_type(wbfig::Connection::Filled);
      else if (imany && !fmany)
        conn->set_diamond_type(wbfig::Connection::RightEmpty);
      else if (!imany && fmany)
        conn->set_diamond_type(wbfig::Connection::LeftEmpty);
      else
        conn->set_diamond_type(wbfig::Connection::Empty);
    }
    else if (_relationship_notation == PRFromColumnNotation)
    {
    }
    else
    {
      conn->set_start_dashed(false);
      conn->set_end_dashed(false);
    }
  }
}


wbfig::Table *workbench_physical_Model::ImplData::create_table_figure(mdc::Layer *layer, 
                                                                      const model_DiagramRef &diagram,
                                                                      const model_ObjectRef &forTable)
{
  switch (_figure_notation)
  {
  case PFWorkbenchNotation:
    return new wbfig::WBTable(layer, diagram->get_data(), forTable);

  case PFWorkbenchSimpleNotation:
    {
      wbfig::WBTable *table= new wbfig::WBTable(layer, diagram->get_data(), forTable);
      table->hide_indices();
      table->hide_triggers();
      return table;
    }

  case PFWorkbenchPKOnlyNotation:
    {
      wbfig::WBTable *table= new wbfig::WBTable(layer, diagram->get_data(), forTable);
      table->hide_columns();
      table->hide_indices();
      table->hide_triggers();
      return table;
    }

  case PFIdef1xNotation:
    return new wbfig::Idef1xTable(layer, diagram->get_data(), forTable);

  case PFClassicNotation:
    return new wbfig::SimpleTable(layer, diagram->get_data(), forTable);

  case PFBarkerNotation:
  {
    wbfig::SimpleTable *table= new wbfig::SimpleTable(layer, diagram->get_data(), forTable);
    table->set_barker_notation(true);
    return table;
  }
  default:
    return 0;
  }
}


void workbench_physical_Model::ImplData::tag_list_changed(grt::internal::OwnedList *list, bool added, const grt::ValueRef &value,
                                                          const meta_TagRef &tag)
{
  if (list == tag->objects().valueptr())
  {
    meta_TaggedObjectRef to(meta_TaggedObjectRef::cast_from(value));
    if (added)
    {
      db_DatabaseObjectRef dbobj(to->object());
      model_FigureRef figure;
      
      for (grt::ListRef<workbench_physical_Diagram>::const_iterator end= self()->diagrams().end(), diag= self()->diagrams().begin();
           diag != end; ++diag)
      {
        figure= (*diag)->get_data()->get_figure_for_dbobject(dbobj);
        if (figure.is_valid())
        {
          (*diag)->get_data()->add_tag_badge_to_figure(figure, tag);
        }
      }
    }
    else
    {
      db_DatabaseObjectRef dbobj(to->object());
      model_FigureRef figure;
      
      for (grt::ListRef<workbench_physical_Diagram>::const_iterator end=self()->diagrams().end(), diag= self()->diagrams().begin();
           diag != end; ++diag)
      {
        figure= (*diag)->get_data()->get_figure_for_dbobject(dbobj);
        if (figure.is_valid())
        {
          (*diag)->get_data()->remove_tag_badge_from_figure(figure, tag);
        }
      }      
    }
  }
}


void workbench_physical_Model::ImplData::list_changed(grt::internal::OwnedList *list, bool added, const grt::ValueRef &value)
{
  if (list == self()->_tags.valueptr())
  {
    if (added)
    {
      meta_TagRef tag(meta_TagRef::cast_from(value));
      
      // monitor changes to list of objects tagged
      _tag_connections[tag.id()]=
          tag->signal_list_changed()->connect(boost::bind(&ImplData::tag_list_changed, this, _1, _2, _3, tag));
    }
    else
    {
      meta_TagRef tag(meta_TagRef::cast_from(value));
      
      if (_tag_connections.find(tag.id()) != _tag_connections.end())
      {
        _tag_connections[tag.id()].disconnect();
        _tag_connections.erase(_tag_connections.find(tag.id()));
      }
    }
  }
}


void workbench_physical_Model::ImplData::dict_changed(grt::internal::OwnedDict *dict, bool added, const std::string &key)
{
  if (g_str_has_prefix(key.c_str(), "workbench.physical.TableFigure:") 
      || g_str_has_prefix(key.c_str(), "workbench.physical.ViewFigure:")
      || g_str_has_prefix(key.c_str(), "workbench.physical.RoutineGroupFigure:"))
  {
    run_later(boost::bind(&workbench_physical_Model::ImplData::reset_figures, this));
  }
}


std::list<meta_TagRef> workbench_physical_Model::ImplData::get_tags_for_dbobject(const db_DatabaseObjectRef &dbobject)
{
  std::list<meta_TagRef> list;
  
  for (grt::ListRef<meta_Tag>::const_iterator end= self()->tags().end(), tag= self()->tags().begin();
       tag != end; ++tag)
  {
    for (grt::ListRef<meta_TaggedObject>::const_iterator oend= (*tag)->objects().end(), oiter= (*tag)->objects().begin();
         oiter != oend; ++oiter)
    {
      if ((*oiter)->object() == dbobject)
      {
        list.push_back(*tag);
        break;
      }
    }
  }
  return list;
}