OpenASIP  2.0
ContentsFigure.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 ContentsFigure.cc
26  *
27  * Definition of ContentsFigure class.
28  *
29  * @author Ari Metsähalme 2003 (ari.metsahalme-no.spam-tut.fi)
30  * @note rating: yellow
31  * @note reviewed Jul 22 2004 by tr, ml, jm, am
32  */
33 
34 #include <vector>
35 
36 #include "Application.hh"
37 #include "ContentsFigure.hh"
38 #include "UnitContainerFigure.hh"
39 #include "BusContainerFigure.hh"
40 #include "SocketContainerFigure.hh"
42 
43 using std::vector;
44 
45 /**
46  * The Constructor.
47  */
49  Figure(), units_(NULL), buses_(NULL), sockets_(NULL) {
50 }
51 
52 /**
53  * The Destructor.
54  */
56 }
57 
58 /**
59  * Overloaded implementation allows only addition of certain types of
60  * Figures for layout purposes.
61  *
62  * These are UnitContainerFigure, BusContainerFigure and
63  * SocketContainerFigure.
64  *
65  * @param figure Child figure to add.
66  */
67 void
69 
70  Figure::addChild(figure);
71 
72  UnitContainerFigure* units = dynamic_cast<UnitContainerFigure*>(figure);
73  if (units != NULL) {
74  units_ = units;
75  return;
76  }
77 
78  BusContainerFigure* buses = dynamic_cast<BusContainerFigure*>(figure);
79  if (buses != NULL) {
80  buses_ = buses;
81  return;
82  }
83 
84  SocketContainerFigure* sockets =
85  dynamic_cast<SocketContainerFigure*>(figure);
86  if (sockets != NULL) {
87  sockets_ = sockets;
88  return;
89  }
90 
91  // added a non supported type of a child figure
92  assert(false);
93 }
94 
95 /**
96  * Draws figure on a given device context.
97  *
98  * Figure::draw() is overridden to enseure that the containers are drawn
99  * in the correct order. (sockets over busses)
100  *
101  * @param dc Device context to draw figures on.
102  */
103 void
105  if (units_ != NULL) {
106  units_->draw(dc);
107  }
108  if (buses_ != NULL) {
109  buses_->draw(dc);
110  }
111  if (sockets_ != NULL) {
112  sockets_->draw(dc);
113  }
114 }
115 
116 /**
117  * Lays out the subcontainers.
118  *
119  * @param dc Device context.
120  */
121 void
123 
124  int containerX =
126  int containerY =
128 
129  // first layout units if there are any
130 
131  if (units_ != NULL) {
132  units_->setLocation(wxPoint(containerX, containerY));
133  units_->layout(dc);
134  containerY += units_->bounds().GetHeight() +
136  }
137 
138  // then layout buses
139 
140  if (buses_ != NULL) {
141 
143  wxPoint(containerX,
145 
146  if (units_ != NULL && units_->bounds().GetWidth() >
148  buses_->setWidth(units_->bounds().GetWidth());
149  } else {
151  }
152 
153  buses_->layout(dc);
154  }
155 
156  // layout sockets
157 
158  if (sockets_ != NULL) {
159 
160  sockets_->setLocation(wxPoint(containerX, containerY));
161 
162  if (buses_ != NULL) {
163  sockets_->setHeight(buses_->bounds().GetHeight() +
165  sockets_->setWidth(buses_->bounds().GetWidth() +
167  } else if (units_ != NULL) {
168  sockets_->setWidth(units_->bounds().GetWidth() +
170  }
171 
172  sockets_->layout(dc);
173 
174  if (buses_ != NULL) {
175  buses_->setWidth(sockets_->bounds().GetWidth());
176  buses_->layout(dc);
177  }
178  }
179 }
180 
181 /**
182  * Calculates and sets the size of the container.
183  *
184  * Depends on the sizes of the child containers: height will be equal
185  * to the size of the unit container plus the height of the socket or
186  * the bus container, whichever is higher. Width will be equal to the
187  * width of the unit container, or the socket container if it is
188  * wider.
189  */
190 void
192 
193  int width = 0;
194  int height = 0;
195 
196  if (units_ != NULL) {
197  width = units_->bounds().GetWidth();
198  height = units_->bounds().GetHeight();
199  }
200 
201  int higher = 0;
202 
203  if (sockets_ != NULL) {
204  higher = sockets_->bounds().GetHeight();
205  if (sockets_->bounds().GetWidth() > width) {
206  width = sockets_->bounds().GetWidth();
207  }
208  }
209 
210  if (buses_ != NULL) {
211  if (buses_->bounds().GetHeight() > higher) {
212  higher = buses_->bounds().GetHeight();
213  }
214  if (buses_->bounds().GetWidth() > width) {
215  width = buses_->bounds().GetWidth();
216  }
217  }
218 
219  height += higher + MachineCanvasLayoutConstraints::VIEW_MARGIN * 2;
221 
222  if (units_ != NULL && (buses_ != NULL || sockets_ != NULL)) {
224  }
225 
226  size_.SetWidth(width);
227  size_.SetHeight(height);
228 }
ContentsFigure::~ContentsFigure
virtual ~ContentsFigure()
Definition: ContentsFigure.cc:55
ContentsFigure::units_
UnitContainerFigure * units_
Contains all the units.
Definition: ContentsFigure.hh:67
ContentsFigure.hh
Figure::setLocation
void setLocation(wxPoint point)
Figure::bounds
virtual wxRect bounds() const
MachineCanvasLayoutConstraints::BUS_MIN_WIDTH
static const int BUS_MIN_WIDTH
Minimum width of a bus.
Definition: MachineCanvasLayoutConstraints.hh:71
Figure::setWidth
void setWidth(int width)
Definition: Figure.cc:81
BusContainerFigure
Definition: BusContainerFigure.hh:47
SocketContainerFigure
Definition: SocketContainerFigure.hh:46
BusContainerFigure.hh
UnitContainerFigure.hh
ContentsFigure::buses_
BusContainerFigure * buses_
Contains all the buses.
Definition: ContentsFigure.hh:69
assert
#define assert(condition)
Definition: Application.hh:86
Figure::size_
wxSize size_
wxSize of the Figure's bounding rectangle.
Definition: Figure.hh:86
Figure::addChild
virtual void addChild(Figure *child)
ContentsFigure::addChild
virtual void addChild(Figure *child)
Definition: ContentsFigure.cc:68
ContentsFigure::draw
virtual void draw(wxDC *dc)
Definition: ContentsFigure.cc:104
ContentsFigure::sockets_
SocketContainerFigure * sockets_
Contains all the sockets.
Definition: ContentsFigure.hh:71
ContentsFigure::layoutSelf
virtual void layoutSelf(wxDC *)
Definition: ContentsFigure.cc:191
MachineCanvasLayoutConstraints::CONNECTIONS_SPACE
static const int CONNECTIONS_SPACE
Space reserved for port-socket-connections.
Definition: MachineCanvasLayoutConstraints.hh:87
ContentsFigure::ContentsFigure
ContentsFigure()
Definition: ContentsFigure.cc:48
Figure
Definition: Figure.hh:50
Application.hh
Figure::location_
wxPoint location_
Top-left location of the Figure's bounding rectangle.
Definition: Figure.hh:84
UnitContainerFigure
Definition: UnitContainerFigure.hh:46
ContentsFigure::layoutChildren
virtual void layoutChildren(wxDC *)
Definition: ContentsFigure.cc:122
MachineCanvasLayoutConstraints::VIEW_MARGIN
static const int VIEW_MARGIN
Top margin for the whole processor view.
Definition: MachineCanvasLayoutConstraints.hh:83
MachineCanvasLayoutConstraints::BUS_SPACE
static const int BUS_SPACE
Space between buses and bus chains.
Definition: MachineCanvasLayoutConstraints.hh:75
SocketContainerFigure.hh
Figure::draw
virtual void draw(wxDC *dc)
Definition: Figure.cc:138
MachineCanvasLayoutConstraints::VIEW_LEFT_MARGIN
static const int VIEW_LEFT_MARGIN
Left margin.
Definition: MachineCanvasLayoutConstraints.hh:85
Figure::layout
virtual void layout(wxDC *dc)
Definition: Figure.cc:109
MachineCanvasLayoutConstraints.hh
Figure::setHeight
void setHeight(int height)
Definition: Figure.cc:95