-
Notifications
You must be signed in to change notification settings - Fork 2
/
DocumentEntryFactory.h
133 lines (112 loc) · 3.62 KB
/
DocumentEntryFactory.h
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
#ifndef DOCUMENTENTRYFACTORY_H
#define DOCUMENTENTRYFACTORY_H
#include <QMap>
#include <QList>
#include <QPointF>
namespace q2d {
class Document;
class DocumentEntry;
namespace metamodel {
class ComponentDescriptor;
} // namespace metamodel
namespace model {
namespace enums {
enum class PortDirection;
} // namespace enums
} // namespace model
namespace factories {
class DocumentEntryFactory {
private:
// TODO instance counts should probably be document-dependent
static QMap<QString, unsigned int> instanceCount;
static unsigned int wireCount;
/**
* @brief countInstance is an accessor to the component instance count.
* It increments the actual count for the type and returns the new count.
* @param typeName
* @return
*/
static unsigned int countInstance(QString typeName);
static unsigned int countWire();
// --- ID generators ---
static QString generateComponentId(q2d::metamodel::ComponentDescriptor* type);
static QString generateWireId();
// --- instantiation helpers ---
/**
* @brief instantiatePorts instantiates all ports
* as described in the provided component descriptor.
* @param document
* @param type
* @param parentComponent
* @return A list with containing a DocumentEntry for each instantiated port
*/
static QList<DocumentEntry*> instantiatePorts(
Document* document,
metamodel::ComponentDescriptor* type,
DocumentEntry* parentComponent);
public:
/**
* @brief instantiateModulePort is a helper method. It does not do everything needed, but a subset,
* so do not call it on its own, if you do not know what you are doing.
* Instead use instantiateInputPort() or instantiateOutputPort() respectively.
* @param document
* @param position
* @param id
* @param direction
* @return
*/
static DocumentEntry* instantiateModuleInterface(
Document* document,
QPointF position,
model::enums::PortDirection direction,
QString id);
/**
* @brief ComponentFactory::instentiatePort
* Instantiates a single Port and adds it to the document as DocumentEntry.
* The schematic item of the parent entry is required to provide
* <code> void signal_posChanged() </code>
* A tooltip for the new ports schematic item will be set, containing its ID.
* @param parentComponent
* @param position
* @param direction
* @param id
* @return
*/
static DocumentEntry* instantiatePort(
Document* document,
DocumentEntry* parentComponent,
QPointF position,
model::enums::PortDirection direction,
QString id);
/**
* @brief instantiateComponent
* The instantiated Component will be wrapped into a DocumentEntry
* and added to the document.
* @param document
* @param type
* @param scenePosition
* @param id
* @return
*/
static DocumentEntry* instantiateComponent(Document* document,
metamodel::ComponentDescriptor* type,
QPointF scenePosition,
QString id = "",
bool autoInstancePorts = true);
static DocumentEntry* instantiateWire(
Document* document,
DocumentEntry* sender,
DocumentEntry* receiver,
QString id = "");
static DocumentEntry* instantiateInputPort(
Document* document,
QPointF position,
QString id);
static DocumentEntry* instantiateOutputPort(
Document* document,
QPointF position,
QString id);
};
} // namespcae factories
} // namespace q2d
#endif // DOCUMENTENTRYFACTORY_H