OpenASIP 2.2
Loading...
Searching...
No Matches
BusFactory.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 BusFactory.cc
26 *
27 * Definition of BusFactory 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 "MachinePart.hh"
37#include "Bus.hh"
38#include "Segment.hh"
39#include "BusFigure.hh"
40#include "BusFactory.hh"
41#include "EditPart.hh"
42#include "SegmentFactory.hh"
43#include "EditPolicyFactory.hh"
44
45using std::vector;
46using namespace TTAMachine;
47
48/**
49 * The Constructor.
50 */
52 EditPartFactory(editPolicyFactory) {
53
54 registerFactory(new SegmentFactory(editPolicyFactory));
55}
56
57/**
58 * The Destructor.
59 */
62
63/**
64 * Returns an EditPart corresponding to a bus.
65 *
66 * @param component Bus of which to create the EditPart.
67 * @return NULL if the parameter is not an instance of the
68 * Bus class.
69 */
72
73 EditPart* busEditPart = EditPartFactory::checkCache(component);
74
75 if (busEditPart != NULL) {
76 return busEditPart;
77 }
78
79 Bus* bus = dynamic_cast<Bus*>(component);
80
81 if (bus != NULL) {
82
83 busEditPart = new EditPart();
84 busEditPart->setModel(bus);
85
86 BusFigure* fig = new BusFigure(bus->position());
87 busEditPart->setFigure(fig);
88
89 for (int i = 0; i < bus->segmentCount(); i++) {
90 vector<Factory*>::const_iterator iter = factories_.begin();
91 while (iter != factories_.end()) {
92 EditPart* segEditPart =
93 (*iter)->createEditPart((MachinePart*)bus->segment(i));
94 if (segEditPart != NULL) {
95 busEditPart->addChild(segEditPart);
96 segEditPart->setSelectable(true);
97 segEditPart->setParent(busEditPart);
98 }
99 iter++;
100 }
101 }
102
103 busEditPart->setSelectable(true);
104
106 if (editPolicy != NULL) {
107 busEditPart->installEditPolicy(editPolicy);
108 }
110 return busEditPart;
111
112 } else {
113 return NULL;
114 }
115}
virtual EditPart * createEditPart(TTAMachine::MachinePart *component)
Definition BusFactory.cc:71
virtual ~BusFactory()
Definition BusFactory.cc:60
BusFactory(EditPolicyFactory &editPolicyFactory)
Definition BusFactory.cc:51
void registerFactory(Factory *factory)
std::vector< Factory * > factories_
Registered factories.
EditPart * checkCache(const TTAMachine::MachinePart *component) const
EditPolicyFactory & editPolicyFactory_
Factory which creates edit policies for edit parts.
void writeToCache(EditPart *editPart)
void setModel(TTAMachine::MachinePart *model)
void installEditPolicy(EditPolicy *editpolicy)
Definition EditPart.cc:247
void setFigure(Figure *figure)
void setSelectable(bool selectable)
void setParent(EditPart *parent)
void addChild(EditPart *child)
Definition EditPart.cc:260
virtual EditPolicy * createBusEditPolicy()
virtual Segment * segment(int index) const
Definition Bus.cc:329
virtual int position() const
Definition Bus.cc:127
virtual int segmentCount() const
Definition Bus.cc:385