OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
UnitFigure Class Reference

#include <UnitFigure.hh>

Inheritance diagram for UnitFigure:
Inheritance graph
Collaboration diagram for UnitFigure:
Collaboration graph

Public Member Functions

 UnitFigure ()
 
virtual ~UnitFigure ()
 
void setName (const wxString &name)
 
void setInfo (const wxString &info)
 
- Public Member Functions inherited from Figure
 Figure ()
 
virtual ~Figure ()
 
wxPoint location () const
 
void setLocation (wxPoint point)
 
void setX (int x)
 
void setY (int y)
 
void setPreferredX (int x)
 
bool xSet () const
 
void clearXSetFlag ()
 
virtual wxRect bounds () const
 
virtual wxRect virtualBounds () const
 
void setBounds (wxSize bounds)
 
void setWidth (int width)
 
void setHeight (int height)
 
virtual void addChild (Figure *child)
 
int childCount () const
 
Figurechild (int index) const
 
virtual void draw (wxDC *dc)
 
void highlight (const wxColour &colour)
 
void clearHighlight ()
 
void setOptions (MachineCanvasOptions *options)
 
MachineCanvasOptionsoptions ()
 

Protected Member Functions

virtual void layout (wxDC *)
 
virtual void layoutSelf (wxDC *)
 
virtual void layoutChildren (wxDC *)
 
virtual void drawSelf (wxDC *)
 
- Protected Member Functions inherited from Figure
void drawChildren (wxDC *dc)
 

Private Member Functions

UnitFigureoperator= (UnitFigure &old)
 Assignment not allowed.
 
 UnitFigure (UnitFigure &old)
 Copying not allowed.
 

Private Attributes

wxString type_
 Type identifier of the unit.
 
wxString name_
 Name of the unit.
 
wxString info_
 Extra information string describing the unit.
 

Static Private Attributes

static const wxColour DEFAULT_COLOUR = wxColour(0, 0, 0)
 Default colour for the figure.
 
static const wxColour DEFAULT_BG_COLOUR = wxColour(255, 255, 255)
 Default background colour for the figure.
 
static const wxColour DEFAULT_INFO_TEXT_COLOUR = wxColour(150, 150, 150)
 Default info string colour for the figure.
 
static const int MARGIN = 5
 Top and bottom margin in pixels.
 
static const int SPACING = 5
 Space between text rows in pixels.
 

Additional Inherited Members

- Protected Attributes inherited from Figure
wxPoint location_
 Top-left location of the Figure's bounding rectangle.
 
wxSize size_
 wxSize of the Figure's bounding rectangle.
 
wxSize minSize_
 Figure's minimum size.
 
std::vector< Figure * > children_
 Figure's children.
 
bool xSet_
 Tells if x-coordinate has been fixed.
 
bool laidOut_
 Tells whether the Figure and its children have been laid out or not.
 
bool drawn_
 Tells whether the Figure and its children have been drawn or not.
 
wxColour highlight_
 Highlight colour.
 
bool highlighted_
 Tells if the figure is highlighted.
 
MachineCanvasOptionsoptions_
 Options which are used for customizing figures.
 

Detailed Description

Figure of a unit.

Definition at line 46 of file UnitFigure.hh.

Constructor & Destructor Documentation

◆ UnitFigure() [1/2]

UnitFigure::UnitFigure ( )

The Constructor.

Definition at line 60 of file UnitFigure.cc.

60 : Figure() {
61 minSize_ = wxSize(
65}
wxSize minSize_
Figure's minimum size.
Definition Figure.hh:88
Figure()
Definition Figure.cc:44
wxSize size_
wxSize of the Figure's bounding rectangle.
Definition Figure.hh:86
static const int UNIT_HEIGHT
Minimum unit height.
static const int UNIT_WIDTH
Minimum unit width.

References Figure::minSize_, Figure::size_, MachineCanvasLayoutConstraints::UNIT_HEIGHT, and MachineCanvasLayoutConstraints::UNIT_WIDTH.

◆ ~UnitFigure()

UnitFigure::~UnitFigure ( )
virtual

The Destructor.

Definition at line 70 of file UnitFigure.cc.

70 {
71}

◆ UnitFigure() [2/2]

UnitFigure::UnitFigure ( UnitFigure old)
private

Copying not allowed.

Member Function Documentation

◆ drawSelf()

void UnitFigure::drawSelf ( wxDC *  dc)
protectedvirtual

Draws the function unit's Figure on the given device context.

Parameters
dcThe device context.

Reimplemented from Figure.

Definition at line 80 of file UnitFigure.cc.

80 {
81
82 wxPen pen = wxPen(DEFAULT_COLOUR, 1, wxSOLID);
83 dc->SetPen(pen);
84 wxBrush brush = wxBrush(DEFAULT_BG_COLOUR, wxSOLID);
85 if (highlighted_) {
86 brush = wxBrush(highlight_, wxSOLID);
87 }
88 dc->SetBrush(brush);
89
90 const bool drawInfoRow =
91 (options() != NULL &&
94
95 if (type_ == _T("FU:")) {
96 if (!highlighted_) {
97 if (info_.StartsWith(_T("{ AS:"))) {
98 dc->SetBrush(wxBrush(wxColour(170,255,170),wxSOLID));
99 } else {
100 dc->SetBrush(wxBrush(wxColour(205,205,255),wxSOLID));
101 }
102 } else {
103 if (info_.StartsWith(_T("{ AS:"))) {
104 dc->SetBrush(wxBrush(wxColour((53+highlight_.Red()*2)/3,
105 (82+highlight_.Green()*2)/3,
106 (53+highlight_.Blue()*2)/3),
107 wxSOLID));
108 } else {
109 dc->SetBrush(wxBrush(wxColour((68+highlight_.Red()*2)/3,
110 (68+highlight_.Green()*2)/3,
111 (82+highlight_.Blue()*2)/3),
112 wxSOLID));
113 }
114 }
115 dc->DrawRoundedRectangle(
116 location_.x, location_.y, size_.GetWidth(),
117 size_.GetHeight(), size_.GetHeight()*0.25);
118 } else if (type_ == _T("GCU:")) {
119 dc->SetBrush(wxBrush(wxColour(250,145,255), wxSOLID));
120 dc->DrawRoundedRectangle(
121 location_.x, location_.y, size_.GetWidth(),
122 size_.GetHeight(), size_.GetHeight()*0.4);
123 } else if (type_ == _T("IMM:")) {
124 dc->SetBrush(wxBrush(wxColour(255,168,140),wxSOLID));
125 wxPoint points[4];
126 points[0] = wxPoint(size_.GetWidth()/2-10, size_.GetHeight());
127 points[1] = wxPoint(size_.GetWidth()/2+10, size_.GetHeight());
128 points[2] = wxPoint(size_.GetWidth(),0);
129 points[3] = wxPoint(0,0);
130 dc->DrawPolygon(
131 4, points,
132 location_.x, location_.y,
133 wxODDEVEN_RULE);
134 } else { // register file
135 dc->SetBrush(wxBrush(wxColour(240,230,150),wxSOLID));
136 dc->DrawRectangle(
137 location_.x, location_.y, size_.GetWidth(),
138 size_.GetHeight());
139 }
140
141 dc->SetBackgroundMode(wxTRANSPARENT);
142 dc->SetTextForeground(DEFAULT_COLOUR);
143
144 int typeWidth = 0;
145 int typeHeight = 0;
146 if (drawInfoRow) {
147 dc->GetTextExtent(type_, &typeWidth, &typeHeight);
148
149 int typeX = location_.x + size_.GetWidth() / 2 - typeWidth / 2;
150 int typeY = location_.y + MARGIN;
151
152 dc->DrawText(type_, typeX, typeY);
153 }
154
155 int nameWidth;
156 int nameHeight;
157
158 wxFont oldFont = dc->GetFont();
159 if (!drawInfoRow) {
160 // In case we do not write the details (operation set) to the unit,
161 // print the name of the unit larger.
162 dc->SetFont(wxFont(16, wxDEFAULT, wxNORMAL, wxNORMAL));
163 }
164 dc->GetTextExtent(name_, &nameWidth, &nameHeight);
165
166 int nameX = location_.x + size_.GetWidth() / 2 - nameWidth / 2;
167 int nameY = location_.y + MARGIN + typeHeight + SPACING;
168 dc->DrawText(name_, nameX, nameY);
169
170 if (!drawInfoRow) {
171 dc->SetFont(oldFont);
172 }
173
174 if (drawInfoRow) {
175
176 int infoWidth;
177 int infoHeight;
178
179 dc->GetTextExtent(info_, &infoWidth, &infoHeight);
180
181 int infoX = location_.x + size_.GetWidth() / 2 - infoWidth / 2;
182 int infoY =
183 location_.y + MARGIN + typeHeight + SPACING + nameHeight + SPACING;
184
185 dc->SetTextForeground(DEFAULT_INFO_TEXT_COLOUR);
186 dc->DrawText(info_, infoX, infoY);
187 }
188}
MachineCanvasOptions * options()
Definition Figure.cc:199
wxColour highlight_
Highlight colour.
Definition Figure.hh:99
bool highlighted_
Tells if the figure is highlighted.
Definition Figure.hh:101
wxPoint location_
Top-left location of the Figure's bounding rectangle.
Definition Figure.hh:84
static const std::string SHOW_UNIT_INFO_STRING
Option name for the unit info string visibility flag.
virtual bool isFlagOn() const
OptionValue & optionValue(const string &name, int index=0)
Definition Options.cc:115
static const wxColour DEFAULT_BG_COLOUR
Default background colour for the figure.
Definition UnitFigure.hh:76
static const wxColour DEFAULT_COLOUR
Default colour for the figure.
Definition UnitFigure.hh:74
static const wxColour DEFAULT_INFO_TEXT_COLOUR
Default info string colour for the figure.
Definition UnitFigure.hh:78
wxString type_
Type identifier of the unit.
Definition UnitFigure.hh:67
static const int SPACING
Space between text rows in pixels.
Definition UnitFigure.hh:82
static const int MARGIN
Top and bottom margin in pixels.
Definition UnitFigure.hh:80
wxString name_
Name of the unit.
Definition UnitFigure.hh:69
wxString info_
Extra information string describing the unit.
Definition UnitFigure.hh:71

References DEFAULT_BG_COLOUR, DEFAULT_COLOUR, DEFAULT_INFO_TEXT_COLOUR, Figure::highlight_, Figure::highlighted_, info_, OptionValue::isFlagOn(), Figure::location_, MARGIN, name_, Figure::options(), Options::optionValue(), MachineCanvasOptions::SHOW_UNIT_INFO_STRING, Figure::size_, SPACING, and type_.

Here is the call graph for this function:

◆ layout()

void UnitFigure::layout ( wxDC *  dc)
protectedvirtual

Lays the figure out.

Figure of the unit is laid out before it's children, so that the port Y-coordinate can be set correctly when laying out the ports.

Parameters
dcDevice cotnext to lay the figure out on.

Reimplemented from Figure.

Definition at line 336 of file UnitFigure.cc.

336 {
337 layoutSelf(dc);
338 layoutChildren(dc);
339 laidOut_ = true;
340}
bool laidOut_
Tells whether the Figure and its children have been laid out or not.
Definition Figure.hh:95
virtual void layoutChildren(wxDC *)
virtual void layoutSelf(wxDC *)

References Figure::laidOut_, layoutChildren(), and layoutSelf().

Here is the call graph for this function:

◆ layoutChildren()

void UnitFigure::layoutChildren ( wxDC *  dc)
protectedvirtual

Lays out the ports to the bottom of the fu's Figure, spaced evenly.

Parameters
dcDevice context.

Reimplemented from Figure.

Definition at line 196 of file UnitFigure.cc.

196 {
197
198 // Sort port child figures to containers based on port directions.
199 // Map with portname, figure pairs is used so that the ports
200 // are automatically ordered by the port name.
201 map<std::string, Figure*> inputPorts;
202 map<std::string, Figure*> outputPorts;
203 map<std::string, Figure*> bidirPorts;
204 map<std::string, Figure*> trigPorts;
205 map<std::string, Figure*> nodirPorts;
206
207 vector<Figure*>::iterator i = children_.begin();
208 for(; i != children_.end(); i++) {
209 UnitPortFigure* fig = dynamic_cast<UnitPortFigure*>(*i);
210 assert(fig != NULL);
211 bool input = false;
212 bool output = false;
213 for (int j = 0; j < (fig->childCount()); j++) {
214 Figure* socketFig = fig->child(j);
215 if (dynamic_cast<InputSocketFigure*>(socketFig) != NULL) {
216 input = true;
217 } else if (dynamic_cast<OutputSocketFigure*>(socketFig) != NULL) {
218 output = true;
219 }
220 }
221 if (input && dynamic_cast<TriggeringPortFigure*>(fig) != NULL) {
222 trigPorts[fig->name()] = fig;
223 } else if (input && output) {
224 bidirPorts[fig->name()] = fig;
225 } else if (input) {
226 inputPorts[fig->name()] = fig;
227 } else if (output) {
228 outputPorts[fig->name()] = fig;
229 } else {
230 nodirPorts[fig->name()] = fig;
231 }
232 }
233
235 int portY = location_.y + size_.GetHeight();
236
237 // if only single port, put it to middle.
238 if (children_.size() == 1) {
239 portX = location_.x + (size_.GetWidth()- children_[0]->bounds().GetWidth()) / 2;
240 }
241
242 // Layout input ports.
243 map<std::string, Figure*>::iterator inIter = inputPorts.begin();
244 for (; inIter != inputPorts.end(); inIter++) {
245 portY -= (*inIter).second->bounds().GetHeight()/2;
246 (*inIter).second->setLocation(wxPoint(portX, portY));
247 (*inIter).second->layout(dc);
248 portY = location_.y + size_.GetHeight();
249 portX += (*inIter).second->bounds().GetWidth() +
251 }
252
253 // Layout triggering ports.
254 map<std::string, Figure*>::iterator trigIter = trigPorts.begin();
255 for (; trigIter != trigPorts.end(); trigIter++) {
256 portY -= (*trigIter).second->bounds().GetHeight()/2;
257 (*trigIter).second->setLocation(wxPoint(portX, portY));
258 (*trigIter).second->layout(dc);
259 portY = location_.y + size_.GetHeight();
260 portX += (*trigIter).second->bounds().GetWidth() +
262 }
263
264 // Layout bidirectional ports.
265 map<std::string, Figure*>::iterator bdIter = bidirPorts.begin();
266 for (; bdIter != bidirPorts.end(); bdIter++) {
267 portY -= (*bdIter).second->bounds().GetHeight()/2;
268 (*bdIter).second->setLocation(wxPoint(portX, portY));
269 (*bdIter).second->layout(dc);
270 portY = location_.y + size_.GetHeight();
271 portX += (*bdIter).second->bounds().GetWidth() +
273 }
274
275 // Layout output ports.
276 map<std::string, Figure*>::iterator outIter = outputPorts.begin();
277 for (; outIter != outputPorts.end(); outIter++) {
278 portY -= (*outIter).second->bounds().GetHeight()/2;
279 (*outIter).second->setLocation(wxPoint(portX, portY));
280 (*outIter).second->layout(dc);
281 portY = location_.y + size_.GetHeight();
282 portX += (*outIter).second->bounds().GetWidth() +
284 }
285
286 // Layout ports w/ no direction.
287 map<std::string, Figure*>::iterator ndIter = nodirPorts.begin();
288 for (; ndIter != nodirPorts.end(); ndIter++) {
289 portY -= (*ndIter).second->bounds().GetHeight()/2;
290 (*ndIter).second->setLocation(wxPoint(portX, portY));
291 (*ndIter).second->layout(dc);
292 portY = location_.y + size_.GetHeight();
293 portX += (*ndIter).second->bounds().GetWidth() +
295 }
296}
#define assert(condition)
int childCount() const
Figure * child(int index) const
std::vector< Figure * > children_
Figure's children.
Definition Figure.hh:90
virtual wxRect bounds() const
static const int PORT_SPACE
Space between ports.
std::string name() const

References assert, Figure::bounds(), Figure::child(), Figure::childCount(), Figure::children_, Figure::location_, UnitPortFigure::name(), MachineCanvasLayoutConstraints::PORT_SPACE, and Figure::size_.

Referenced by layout().

Here is the call graph for this function:

◆ layoutSelf()

void UnitFigure::layoutSelf ( wxDC *  dc)
protectedvirtual

Calculates and sets the size of the unit.

Depends on its name and the amount of ports.

Parameters
dcDevice context.

Reimplemented from Figure.

Definition at line 350 of file UnitFigure.cc.

350 {
351
352 bool showInfo = (options() != NULL) && options()->optionValue(
354
355 int portsWidth = 0;
356
357 vector<Figure*>::const_iterator i = children_.begin();
358 for (; i != children_.end(); i++) {
359 portsWidth += (*i)->bounds().GetWidth();
360 }
361
362 portsWidth +=
364
365 int nameWidth = 0;
366 int nameHeight = 0;
367 int infoWidth = 0;
368 int infoHeight = 0;
369 int typeWidth = 0;
370 int typeHeight = 0;
371
372 dc->GetTextExtent(name_, &nameWidth, &nameHeight);
373 dc->GetTextExtent(type_, &typeWidth, &typeHeight);
374 if (showInfo) {
375 dc->GetTextExtent(info_, &infoWidth, &infoHeight);
376 }
377 nameWidth += MARGIN * 4;
378 typeWidth += MARGIN * 4;
379 infoWidth += MARGIN * 4;
380
382
383 if (portsWidth > maxWidth) {
384 maxWidth = portsWidth;
385 }
386
387 if ((nameWidth + 2 * MARGIN) > maxWidth) {
388
389 unsigned int chars = 0;
390 int charsExtent = 0;
391
392 while ((charsExtent + 2 * MARGIN) < maxWidth) {
393 int charWidth = 0;
394 int charHeight = 0;
395 dc->GetTextExtent(name_.GetChar(chars), &charWidth, &charHeight);
396 charsExtent += charWidth;
397 chars++;
398 if (chars > name_.Len()) {
399 break;
400 }
401 }
402
403 name_.Truncate(chars - 5);
404 name_.Append(_T("..."));
405 dc->GetTextExtent(name_, &nameWidth, &nameHeight);
406 nameWidth += 4 * MARGIN;
407 }
408
409 if (showInfo && (infoWidth + 2 * MARGIN) > maxWidth) {
410
411 unsigned int chars = 0;
412 int charsExtent = 0;
413
414 while ((charsExtent + 2 * MARGIN) < maxWidth) {
415 int charWidth = 0;
416 int charHeight = 0;
417 dc->GetTextExtent(info_.GetChar(chars), &charWidth, &charHeight);
418 charsExtent += charWidth;
419 chars++;
420 if (chars > info_.Len()) {
421 break;
422 }
423 }
424
425 info_.Truncate(chars - 5);
426 info_.Append(_T("..."));
427 dc->GetTextExtent(info_, &infoWidth, &infoHeight);
428 infoWidth += 4 * MARGIN;
429 }
430
431 if (infoWidth > size_.GetWidth() &&
432 infoWidth >= nameWidth && infoWidth > portsWidth) {
433
434 size_.SetWidth(infoWidth);
435
436 } else if (nameWidth > size_.GetWidth() &&
437 nameWidth > infoWidth && nameWidth > portsWidth) {
438
439 size_.SetWidth(nameWidth);
440
441 } else if (portsWidth > size_.GetWidth()) {
442 size_.SetWidth(portsWidth);
443 }
444
445 // Set figure height.
446 int height = 2 * MARGIN + SPACING + nameHeight +
448
449 if (showInfo) {
450 height += typeHeight + SPACING + infoHeight;
451 }
452 if (height > minSize_.GetHeight()) {
453 size_.SetHeight(height);
454 }
455}
static const int PORT_WIDTH
Default Width of a port.
static const int MAX_UNIT_NAME_WIDTH
Maximun unit name width in pixels.

References Figure::children_, info_, OptionValue::isFlagOn(), MARGIN, MachineCanvasLayoutConstraints::MAX_UNIT_NAME_WIDTH, Figure::minSize_, name_, Figure::options(), Options::optionValue(), MachineCanvasLayoutConstraints::PORT_SPACE, MachineCanvasLayoutConstraints::PORT_WIDTH, MachineCanvasOptions::SHOW_UNIT_INFO_STRING, Figure::size_, SPACING, and type_.

Referenced by layout().

Here is the call graph for this function:

◆ operator=()

UnitFigure & UnitFigure::operator= ( UnitFigure old)
private

Assignment not allowed.

◆ setInfo()

void UnitFigure::setInfo ( const wxString &  info)

Sets the information string of the unit.

Parameters
infoNew info string..

Definition at line 323 of file UnitFigure.cc.

323 {
324 info_ = info;
325}

References info_.

Referenced by FUFactory::createEditPart(), GCUFactory::createEditPart(), IUFactory::createEditPart(), and RFFactory::createEditPart().

◆ setName()

void UnitFigure::setName ( const wxString &  name)

Sets the name of the unit.

Parameters
nameNew name.

Definition at line 304 of file UnitFigure.cc.

304 {
305 int index = name.Find(':');
306 if (index == -1) {
307 type_ = _T("Unit:");
308 name_ = name;
309 } else {
310 type_ = name.Mid(0, index + 1);
311 type_.Trim();
312 name_ = name.Mid(index + 2);
313 name_.Trim();
314 }
315}

References name_, and type_.

Referenced by FUFactory::createEditPart(), GCUFactory::createEditPart(), IUFactory::createEditPart(), and RFFactory::createEditPart().

Member Data Documentation

◆ DEFAULT_BG_COLOUR

const wxColour UnitFigure::DEFAULT_BG_COLOUR = wxColour(255, 255, 255)
staticprivate

Default background colour for the figure.

Definition at line 76 of file UnitFigure.hh.

Referenced by drawSelf().

◆ DEFAULT_COLOUR

const wxColour UnitFigure::DEFAULT_COLOUR = wxColour(0, 0, 0)
staticprivate

Default colour for the figure.

Definition at line 74 of file UnitFigure.hh.

Referenced by drawSelf().

◆ DEFAULT_INFO_TEXT_COLOUR

const wxColour UnitFigure::DEFAULT_INFO_TEXT_COLOUR = wxColour(150, 150, 150)
staticprivate

Default info string colour for the figure.

Definition at line 78 of file UnitFigure.hh.

Referenced by drawSelf().

◆ info_

wxString UnitFigure::info_
private

Extra information string describing the unit.

Definition at line 71 of file UnitFigure.hh.

Referenced by drawSelf(), layoutSelf(), and setInfo().

◆ MARGIN

const int UnitFigure::MARGIN = 5
staticprivate

Top and bottom margin in pixels.

Definition at line 80 of file UnitFigure.hh.

Referenced by drawSelf(), and layoutSelf().

◆ name_

wxString UnitFigure::name_
private

Name of the unit.

Definition at line 69 of file UnitFigure.hh.

Referenced by drawSelf(), layoutSelf(), and setName().

◆ SPACING

const int UnitFigure::SPACING = 5
staticprivate

Space between text rows in pixels.

Definition at line 82 of file UnitFigure.hh.

Referenced by drawSelf(), and layoutSelf().

◆ type_

wxString UnitFigure::type_
private

Type identifier of the unit.

Definition at line 67 of file UnitFigure.hh.

Referenced by drawSelf(), layoutSelf(), and setName().


The documentation for this class was generated from the following files: