OpenASIP  2.0
Figure.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 Figure.cc
26  *
27  * Definition of Figure 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 "Figure.hh"
38 
39 using std::vector;
40 
41 /**
42  * The Constructor.
43  */
45  location_(wxPoint(0,0)), size_(wxSize(0,0)), minSize_(wxSize(0,0)),
46  xSet_(false), laidOut_(false), drawn_(false), highlight_(*wxRED),
47  highlighted_(false), options_(NULL) {
48 }
49 
50 /**
51  * The Destructor.
52  */
54 }
55 
56 /**
57  * Sets the size of the Figure's bounding rectangle.
58  *
59  * @param bounds New size.
60  */
61 void
62 Figure::setBounds(wxSize bounds) {
63  if (bounds.GetHeight() < size_.GetHeight()) {
64  size_.SetHeight(minSize_.GetHeight());
65  } else {
66  size_.SetHeight(bounds.GetHeight());
67  }
68  if (bounds.GetWidth() < size_.GetWidth()) {
69  size_.SetWidth(minSize_.GetWidth());
70  } else {
71  size_.SetWidth(bounds.GetWidth());
72  }
73 }
74 
75 /**
76  * Sets the width of the Figure.
77  *
78  * @param width New width.
79  */
80 void
81 Figure::setWidth(int width) {
82  if (width < minSize_.GetWidth()) {
83  size_.SetWidth(minSize_.GetWidth());
84  } else {
85  size_.SetWidth(width);
86  }
87 }
88 
89 /**
90  * Sets the height of the Figure.
91  *
92  * @param height New height.
93  */
94 void
95 Figure::setHeight(int height) {
96  if (height < minSize_.GetHeight()) {
97  size_.SetHeight(minSize_.GetHeight());
98  } else {
99  size_.SetHeight(height);
100  }
101 }
102 
103 /**
104  * Lays out the Figure and its children.
105  *
106  * @param dc The device context to layout children on.
107  */
108 void
109 Figure::layout(wxDC* dc) {
110  layoutChildren(dc);
111  layoutSelf(dc);
112  laidOut_ = true;
113 }
114 
115 /**
116  * Empty default implementation that can be used if no specific laying
117  * out needs to be done or the Figure doesn't have children.
118  *
119  * Tells all children to layout themselves.
120  *
121  * @param dc Device context.
122  */
123 void
125  vector<Figure*>::iterator i = children_.begin();
126  for (; i != children_.end(); i++) {
127  (*i)->layout(dc);
128  }
129 }
130 
131 /**
132  * Draws the Figure and its children on the given device context.
133  *
134  * @param dc The device context to draw the Figure on.
135  * @note The Figure must be laid out before drawing!
136  */
137 void
138 Figure::draw(wxDC* dc) {
139  assert(laidOut_ == true);
140  drawSelf(dc);
141  drawChildren(dc);
142  drawn_ = true;
143 }
144 
145 /**
146  * Draws the Figure's children.
147  *
148  * @param dc The device context to draw the children on.
149  */
150 void
152  vector<Figure*>::iterator i = children_.begin();
153  for (; i != children_.end(); i++) {
154  (*i)->draw(dc);
155  }
156 }
157 
158 /**
159  * Clears highlighting of the figure.
160  *
161  * The highlight is cleared next time the figure is drawn.
162  * This function has no effect if the figure isn't highlighted.
163  */
164 void
166  highlighted_ = false;
167  // Clear highlighting of child figures.
168  vector<Figure*>::iterator i = children_.begin();
169  for (; i != children_.end(); i++) {
170  (*i)->clearHighlight();
171  }
172 }
173 
174 /**
175  * Highlights the figure with given colour.
176  *
177  * The figure is highlighted next time it's drawn.
178  *
179  * @param colour Highlight colour.
180  */
181 void
182 Figure::highlight(const wxColour& colour) {
183 
184  highlight_ = colour;
185  highlighted_ = true;
186  // Highlight child figures.
187  vector<Figure*>::iterator i = children_.begin();
188  for (; i != children_.end(); i++) {
189  (*i)->highlight(colour);
190  }
191 }
192 
193 /**
194  * Returns the options object used by this figure and it's children.
195  *
196  * @return Current figure options.
197  */
200  return options_;
201 }
202 
203 
204 /**
205  * Sets the options object used for setting drawing options.
206  *
207  * Options are set recursively for figure children.
208  *
209  * @param options Options to set.
210  */
211 void
213  vector<Figure*>::iterator i = children_.begin();
214  for (; i != children_.end(); i++) {
215  (*i)->setOptions(options);
216  }
217  options_ = options;
218 }
Figure::setBounds
void setBounds(wxSize bounds)
Definition: Figure.cc:62
Figure::drawSelf
virtual void drawSelf(wxDC *dc)
Figure::bounds
virtual wxRect bounds() const
Figure::laidOut_
bool laidOut_
Tells whether the Figure and its children have been laid out or not.
Definition: Figure.hh:95
Figure::highlight
void highlight(const wxColour &colour)
Definition: Figure.cc:182
Figure::setWidth
void setWidth(int width)
Definition: Figure.cc:81
Figure::drawChildren
void drawChildren(wxDC *dc)
Definition: Figure.cc:151
Figure::children_
std::vector< Figure * > children_
Figure's children.
Definition: Figure.hh:90
Figure::highlight_
wxColour highlight_
Highlight colour.
Definition: Figure.hh:99
Figure::layoutSelf
virtual void layoutSelf(wxDC *)
Figure::setOptions
void setOptions(MachineCanvasOptions *options)
Definition: Figure.cc:212
Figure.hh
Figure::options_
MachineCanvasOptions * options_
Options which are used for customizing figures.
Definition: Figure.hh:104
MachineCanvasOptions
Definition: MachineCanvasOptions.hh:42
assert
#define assert(condition)
Definition: Application.hh:86
Figure::size_
wxSize size_
wxSize of the Figure's bounding rectangle.
Definition: Figure.hh:86
Application.hh
Figure::clearHighlight
void clearHighlight()
Definition: Figure.cc:165
Figure::~Figure
virtual ~Figure()
Definition: Figure.cc:53
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
Figure::highlighted_
bool highlighted_
Tells if the figure is highlighted.
Definition: Figure.hh:101
Figure::draw
virtual void draw(wxDC *dc)
Definition: Figure.cc:138
Figure::minSize_
wxSize minSize_
Figure's minimum size.
Definition: Figure.hh:88
Figure::Figure
Figure()
Definition: Figure.cc:44
Figure::layout
virtual void layout(wxDC *dc)
Definition: Figure.cc:109
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
Figure::setHeight
void setHeight(int height)
Definition: Figure.cc:95
Figure::options
MachineCanvasOptions * options()
Definition: Figure.cc:199
Figure::drawn_
bool drawn_
Tells whether the Figure and its children have been drawn or not.
Definition: Figure.hh:97
Figure::layoutChildren
virtual void layoutChildren(wxDC *)
Definition: Figure.cc:124