1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 Jochen Becher
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #include "dfactory.h"
27 
28 #include "qmt/diagram/delement.h"
29 #include "qmt/diagram/dobject.h"
30 #include "qmt/diagram/dpackage.h"
31 #include "qmt/diagram/dclass.h"
32 #include "qmt/diagram/dcomponent.h"
33 #include "qmt/diagram/ddiagram.h"
34 #include "qmt/diagram/ditem.h"
35 #include "qmt/diagram/drelation.h"
36 #include "qmt/diagram/dinheritance.h"
37 #include "qmt/diagram/ddependency.h"
38 #include "qmt/diagram/dassociation.h"
39 #include "qmt/diagram/dconnection.h"
40 
41 #include "qmt/model/melement.h"
42 #include "qmt/model/mobject.h"
43 #include "qmt/model/mclass.h"
44 #include "qmt/model/mcomponent.h"
45 #include "qmt/model/mpackage.h"
46 #include "qmt/model/mdiagram.h"
47 #include "qmt/model/mcanvasdiagram.h"
48 #include "qmt/model/mitem.h"
49 #include "qmt/model/mrelation.h"
50 #include "qmt/model/massociation.h"
51 #include "qmt/model/mdependency.h"
52 #include "qmt/model/minheritance.h"
53 
54 namespace qmt {
55 
DFactory()56 DFactory::DFactory()
57 {
58 }
59 
visitMElement(const MElement * element)60 void DFactory::visitMElement(const MElement *element)
61 {
62     Q_UNUSED(element)
63     QMT_CHECK(m_product);
64 }
65 
visitMObject(const MObject * object)66 void DFactory::visitMObject(const MObject *object)
67 {
68     auto diagramObject = dynamic_cast<DObject *>(m_product);
69     QMT_ASSERT(diagramObject, return);
70     diagramObject->setModelUid(object->uid());
71     visitMElement(object);
72 }
73 
visitMPackage(const MPackage * package)74 void DFactory::visitMPackage(const MPackage *package)
75 {
76     QMT_CHECK(!m_product);
77     auto diagramPackage = new DPackage();
78     m_product = diagramPackage;
79     visitMObject(package);
80 }
81 
visitMClass(const MClass * klass)82 void DFactory::visitMClass(const MClass *klass)
83 {
84     QMT_CHECK(!m_product);
85     auto diagramKlass = new DClass();
86     m_product = diagramKlass;
87     visitMObject(klass);
88 }
89 
visitMComponent(const MComponent * component)90 void DFactory::visitMComponent(const MComponent *component)
91 {
92     QMT_CHECK(!m_product);
93     auto diagramComponent = new DComponent();
94     m_product = diagramComponent;
95     visitMObject(component);
96 }
97 
visitMDiagram(const MDiagram * diagram)98 void DFactory::visitMDiagram(const MDiagram *diagram)
99 {
100     QMT_CHECK(!m_product);
101     auto diagramDiagram = new DDiagram();
102     m_product = diagramDiagram;
103     visitMObject(diagram);
104 }
105 
visitMCanvasDiagram(const MCanvasDiagram * diagram)106 void DFactory::visitMCanvasDiagram(const MCanvasDiagram *diagram)
107 {
108     QMT_CHECK(!m_product);
109     visitMDiagram(diagram);
110 }
111 
visitMItem(const MItem * item)112 void DFactory::visitMItem(const MItem *item)
113 {
114     QMT_CHECK(!m_product);
115     auto diagramItem = new DItem();
116     m_product = diagramItem;
117     visitMObject(item);
118 }
119 
visitMRelation(const MRelation * relation)120 void DFactory::visitMRelation(const MRelation *relation)
121 {
122     auto diagramRelation = dynamic_cast<DRelation *>(m_product);
123     QMT_ASSERT(diagramRelation, return);
124     diagramRelation->setModelUid(relation->uid());
125     visitMElement(relation);
126 }
127 
visitMDependency(const MDependency * dependency)128 void DFactory::visitMDependency(const MDependency *dependency)
129 {
130     QMT_CHECK(!m_product);
131     auto diagramDependency = new DDependency();
132     m_product = diagramDependency;
133     visitMRelation(dependency);
134 }
135 
visitMInheritance(const MInheritance * inheritance)136 void DFactory::visitMInheritance(const MInheritance *inheritance)
137 {
138     QMT_CHECK(!m_product);
139     auto diagramInheritance = new DInheritance();
140     m_product = diagramInheritance;
141     visitMRelation(inheritance);
142 }
143 
visitMAssociation(const MAssociation * association)144 void DFactory::visitMAssociation(const MAssociation *association)
145 {
146     QMT_CHECK(!m_product);
147     auto diagramAssociation = new DAssociation();
148     m_product = diagramAssociation;
149     visitMRelation(association);
150 }
151 
visitMConnection(const MConnection * connection)152 void DFactory::visitMConnection(const MConnection *connection)
153 {
154     QMT_CHECK(!m_product);
155     auto diagramConnection = new DConnection();
156     m_product = diagramConnection;
157     visitMRelation(connection);
158 }
159 
160 } // namespace qmt
161