OpenASIP 2.2
Loading...
Searching...
No Matches
UnitPortFactory.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file UnitPortFactory.cc
26 *
27 * Definition of UnitPortFactory class.
28 *
29 * @author Ari Metsähalme 2003 (ari.metsahalme-no.spam-tut.fi)
30 * @note rating: yellow
31 * @note reviewed Jul 14 2004 by jm, ll, jn, am
32 */
33
34#include <vector>
35
36#include "Application.hh"
37#include "UnitPortFactory.hh"
38#include "FUPort.hh"
39#include "Port.hh"
40#include "EditPart.hh"
41#include "UnitPortFigure.hh"
42#include "SocketFactory.hh"
44#include "Socket.hh"
45#include "EditPolicyFactory.hh"
47
48using std::vector;
49using namespace TTAMachine;
50
51/**
52 * The Constructor.
53 */
55 EditPartFactory(editPolicyFactory) {
56
57 registerFactory(new SocketFactory(editPolicyFactory));
58}
59
60/**
61 * The Destructor.
62 */
65
66/**
67 * Returns an EditPart corresponding to a port.
68 *
69 * @param component Port of which to create the EditPart.
70 * @return NULL if the parameter is not an instance of the Port class.
71 */
74
75 Port* port = dynamic_cast<Port*>(component);
76 EditPart* portEditPart = NULL;
77
78 if (port != NULL) {
79
80 portEditPart = new EditPart();
81 portEditPart->setModel(port);
82
83 Figure* fig = NULL;
84
85 FUPort* fuPort = dynamic_cast<FUPort*>(component);
86 if (fuPort != NULL && fuPort->isTriggering()) {
87 fig = new TriggeringPortFigure(port->name(), port->width());
88 } else {
89 fig = new UnitPortFigure(port->name(), port->width());
90 }
91
92 portEditPart->setFigure(fig);
93
94 if (port->inputSocket() != NULL) {
95 addSocket(portEditPart, port->inputSocket());
96 }
97
98 if (port->outputSocket() != NULL) {
99 addSocket(portEditPart, port->outputSocket());
100 }
101
102 // number of possible unconnected sockets
103 int unconnectedSockets = 2 - portEditPart->childCount();
104
105 while (unconnectedSockets > 0) {
106 if (port->unconnectedSocket(unconnectedSockets - 1) != NULL) {
107 addSocket(
108 portEditPart,
109 port->unconnectedSocket(unconnectedSockets - 1));
110 }
111 unconnectedSockets--;
112 }
113 } else {
114 return NULL;
115 }
116
117 portEditPart->setSelectable(true);
118
119 // Install editpolicy common to all ports.
121 if (editPolicy != NULL) {
122 portEditPart->installEditPolicy(editPolicy);
123 }
124
125 return portEditPart;
126}
127
128/**
129 * Creates an EditPart of a socket and adds it as a child to the given
130 * EditPart.
131 *
132 * @param socket Socket of which to create the EditPart.
133 * @param portEditPart Port in which to add the socket as a child.
134 */
135void
137 EditPart* portEditPart,
138 MachinePart* socket) const {
139
140 EditPart* socketEditPart = NULL;
141 vector<Factory*>::const_iterator i = factories_.begin();
142
143 while (socketEditPart == NULL && i != factories_.end()) {
144 socketEditPart = (*i)->createEditPart(socket);
145 i++;
146 }
147
148 assert(socketEditPart != NULL);
149
150 SocketPortConnFactory connFactory;
151
152 socketEditPart->addChild(
153 connFactory.createConnection(
154 portEditPart, socketEditPart));
155 portEditPart->addChild(socketEditPart);
156}
#define assert(condition)
void registerFactory(Factory *factory)
std::vector< Factory * > factories_
Registered factories.
EditPolicyFactory & editPolicyFactory_
Factory which creates edit policies for edit parts.
void setModel(TTAMachine::MachinePart *model)
void installEditPolicy(EditPolicy *editpolicy)
Definition EditPart.cc:247
void setFigure(Figure *figure)
void setSelectable(bool selectable)
int childCount() const
void addChild(EditPart *child)
Definition EditPart.cc:260
virtual EditPolicy * createPortEditPolicy()
virtual EditPart * createConnection(EditPart *source, EditPart *target) const
virtual bool isTriggering() const
Definition FUPort.cc:182
virtual Socket * outputSocket() const
Definition Port.cc:281
virtual Socket * unconnectedSocket(int index) const
Definition Port.cc:323
virtual int width() const =0
virtual Socket * inputSocket() const
Definition Port.cc:261
virtual std::string name() const
Definition Port.cc:141
virtual EditPart * createEditPart(TTAMachine::MachinePart *component)
UnitPortFactory(EditPolicyFactory &editPolicyFactory)
virtual ~UnitPortFactory()
void addSocket(EditPart *portEditPart, TTAMachine::MachinePart *socket) const