summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/association.h
blob: a97628d3057cd02e4ecba985a8410e595b28d8e1 (plain)
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
/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   copyright (C) 2003-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

#ifndef ASSOCIATION_H
#define ASSOCIATION_H

#include <tqdom.h>
#include "umlnamespace.h"
#include "umlobject.h"

class UMLRole;

/**
 * This class contains the non-graphic representation of an association.
 * An association can be a generalization, realization, simple association,
 * directed association, aggregation, or composition.
 *
 * @short Sets up association information.
 * @author Oliver Kellogg <okellogg@users.sourceforge.net>
 * @see UMLObject
 * Bugs and comments to uml-devel@lists.sf.net or http://bugs.trinitydesktop.org
 */

class UMLAssociation : public UMLObject {
    Q_OBJECT
  
    friend class AssociationWidget;
public:
    /**
     * Sets up an association.
     * A new unique ID is assigned internally.
     *
     * @param type              The Uml::Association_Type to construct.
     * @param roleA             Pointer to the UMLObject in role A.
     * @param roleB             Pointer to the UMLObject in role B.
     */
    UMLAssociation(Uml::Association_Type type, UMLObject *roleA, UMLObject *roleB);

    /**
     * Constructs an association - for loading only.
     * This constructor should not normally be used as it constructs
     * an incomplete association (i.e. the role objects are missing.)
     *
     * @param type              The Uml::Association_Type to construct.
     *                  Default: Uml::at_Unknown.
     */
    UMLAssociation(Uml::Association_Type type = Uml::at_Unknown);

    /**
     * Overloaded '==' operator
     */
    bool operator==(UMLAssociation &rhs);

    /**
     * Standard deconstructor.
     */
    virtual ~UMLAssociation();

    /**
     * Returns a String representation of this UMLAssociation.
     */
    TQString toString( ) const;

    /**
     * Converts a Uml::Association_Type to its string representation.
     *
     * @param atype             The Association_Type enum value to convert.
     * @return  The string representation of the Association_Type.
     */
    static TQString typeAsString(Uml::Association_Type atype);

    /**
     * Returns true if the given Association_Type has a representation as a
     * UMLAssociation.
     */
    static bool assocTypeHasUMLRepresentation(Uml::Association_Type atype);

    /**
     * Returns the Association_Type of the UMLAssociation.
     *
     * @return  The Association_Type of the UMLAssociation.
     */
    Uml::Association_Type getAssocType() const;

    /**
     * Returns the UMLObject assigned to the given role.
     *
     * @return  Pointer to the UMLObject in the given role.
     */
    UMLObject* getObject(Uml::Role_Type role);

    /**
     * Returns the ID of the UMLObject assigned to the given role.
     * Shorthand for getObject(role)->getID().
     *
     * @return  ID of the UMLObject in the given role.
     */
    Uml::IDType getObjectId(Uml::Role_Type role);

    /*
     * Returns the ID of the UMLObject assigned to the given role.
     * CURRENTLY UNUSED.
     *
     * @return  ID of the UMLObject of the given role.
    Uml::IDType getRoleId(Uml::Role_Type role) const;
     */

    /**
     * Returns the Changeablity of the given role.
     *
     * @return  Changeability_Type of the given role.
     */
    Uml::Changeability_Type getChangeability(Uml::Role_Type role) const;

    /**
     * Returns the Visibility of the given role.
     *
     * @return  Visibility of the given role.
     */
    Uml::Visibility getVisibility(Uml::Role_Type role) const;

    /**
     * Returns the multiplicity assigned to the given role.
     *
     * @return  The multiplicity assigned to the given role.
     */
    TQString getMulti(Uml::Role_Type role) const;

    /**
     * Returns the name assigned to the role A.
     *
     * @return  The name assigned to the given role.
     */
    TQString getRoleName(Uml::Role_Type role) const;

    /**
     * Returns the documentation assigned to the given role.
     *
     * @return  Documentation text of given role.
     */
    TQString getRoleDoc(Uml::Role_Type role) const;

    /**
     * Sets the assocType of the UMLAssociation.
     *
     * @param assocType The Association_Type of the UMLAssociation.
     */
    void setAssocType(Uml::Association_Type assocType);

    /**
     * Sets the UMLObject playing the given role in the association.
     *
     * @param obj  Pointer to the UMLObject of the given role.
     * @param role The Uml::Role_Type played by the association
     */
    void setObject(UMLObject *obj, Uml::Role_Type role);

    /**
     * Sets the visibility of the given role of the UMLAssociation.
     *
     * @param value  Visibility of role.
     * @param role   The Uml::Role_Type to which the visibility is being applied 
     */
    void setVisibility(Uml::Visibility value, Uml::Role_Type role);

    /**
     * Sets the changeability of the given role of the UMLAssociation.
     *
     * @param value     Changeability_Type of the given role.
     * @param role      The Uml::Role_Type to which the changeability is being set
     */
    void setChangeability(Uml::Changeability_Type value, Uml::Role_Type role);

    /**
     * Sets the multiplicity of the given role of the UMLAssociation.
     *
     * @param multi    The multiplicity of the given role.
     * @param role     The Uml::Role_Type to which the multiplicity is being applied
     */
    void setMulti(const TQString &multi, Uml::Role_Type role);

    /**
     * Sets the name of the given role of the UMLAssociation.
     *
     * @param roleName  The name to set for the given role.
     * @param role      The Uml::Role_Type for which to set the name.
     */
    void setRoleName(const TQString &roleName, Uml::Role_Type role);

    /**
     * Sets the documentation on the given role in the association.
     *
     * @param doc      The string with the documentation.
     * @param role     The Uml::Role_Type to which the documentation is being applied         
     */
    void setRoleDoc(const TQString &doc, Uml::Role_Type role);

    /**
     * Convert Changeability_Type value into TQString representation.
     *
     * @param type              The Changeability_Type enum value to convert.
     */
    static TQString ChangeabilityToString(Uml::Changeability_Type type);

    /**
     * Get the underlying UMLRole object for the given role.
     *
     * @return  Pointer to the UMLRole object for the given role.
     */
    UMLRole * getUMLRole(Uml::Role_Type role);

    /**
     * Set backward compatibility flag for loading version 1.3.x files.
     * This flag is necessary because the handling of the isNavigable
     * attribute of <UML:AssociationEnd> was incorrect.
     */
    void setOldLoadMode(bool value = true);

    /**
     * Return the backward compatibility flag for loading files.
     */
    bool getOldLoadMode() const;

    /**
     * Make a clone of this object.
     * Cloning associations is not supported yet.
     */
    virtual UMLObject* clone() const { return NULL; }

    /**
     * Resolve types. Required when dealing with foreign XMI files.
     * Needs to be called after all UML objects are loaded from file.
     * Overrides the method from UMLObject.
     * Calls resolveRef() for each role.
     *
     * @return  True for success.
     */
    virtual bool resolveRef();

    /**
     * Creates the <UML:Generalization> or <UML:Association> XMI element
     * including its role objects.
     */
    void saveToXMI(TQDomDocument& qDoc, TQDomElement& qElement);

protected:
    /**
     * Creates the <UML:Generalization> or <UML:Association> XMI element
     * including its role objects.
     */
    bool load(TQDomElement& element);

    // keep track of number of parent widgets
    int nrof_parent_widgets;

    /**
     * Common initializations at construction time.
     *
     * @param type              The Association_Type to represent.
     * @param roleAObj  Pointer to the role A UMLObject.
     * @param roleBObj  Pointer to the role B UMLObject.
     */
    void init(Uml::Association_Type type, UMLObject *roleAObj, UMLObject *roleBObj);

    /* If the type Uml::Association_Type is changed then also the following
       must be changed accordingly:
       atypeFirst, atypeLast, assocTypeStr[], toAssocType(), toString().
       The ordering within assocTypeStr must match the enumeration
       order of Uml::Association_Type.
     */
    static const Uml::Association_Type atypeFirst;
    static const Uml::Association_Type atypeLast;
    static const unsigned int nAssocTypes;
    static const TQString assocTypeStr[];

    UMLRole * m_pRole[2];

    Uml::Association_Type m_AssocType;
    TQString m_Name;
    bool m_bOldLoadMode;
};

#endif