OpenASIP  2.0
BusFigure.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 BusFigure.cc
26  *
27  * Definition of BusFigure class.
28  *
29  * @author Ari Metsähalme 2003 (ari.metsahalme-no.spam-tut.fi)
30  * @note rating: yellow
31  * @note reviewed Jul 27 2004 by ml, pj, am
32  */
33 
34 #include <vector>
35 
36 #include "BusFigure.hh"
37 #include "SegmentFigure.hh"
39 #include "WxConversion.hh"
40 
41 using std::vector;
42 
43 const wxColour BusFigure::DEFAULT_COLOUR = wxColour(150, 150, 150);
44 
45 /**
46  * The Constructor.
47  */
48 BusFigure::BusFigure(unsigned int slot): Figure(), slot_(slot) {
49  minSize_ = wxSize(
52  size_ = minSize_;
53 }
54 
55 /**
56  * The Destructor.
57  */
59 
60 /**
61  * Returns the virtual bounds of a bus, which are a bit higher than
62  * the visible bounds to make selection easier.
63  *
64  * @return The virtual bounds of a bus.
65  */
66 wxRect
68  if (childCount() <= 1) {
69  wxRect virtualLocation = wxRect(
70  wxPoint(location_.x, location_.y - size_.GetHeight()),
71  wxSize(size_.GetWidth(), size_.GetHeight() * 3));
72  return virtualLocation;
73  } else {
74  return wxRect(location_, size_);
75  }
76 }
77 
78 /**
79  * Lays ouf the segments in a column, spaced evenly.
80  *
81  * @param dc Device context.
82  */
83 void
85 
86  int segY = location_.y;
87  int segX = location_.x;
88 
89  for(unsigned int i = 0; i < children_.size(); i++) {
90  children_[i]->setLocation(wxPoint(segX, segY));
91  children_[i]->setWidth(size_.GetWidth());
92  children_[i]->layout(dc);
93  segY += children_[i]->bounds().GetHeight() +
95  }
96 }
97 
98 /**
99  * Calculates and sets bus size according to the size of segments.
100  */
101 void
103 
104  if (children_.size() > 0) {
105  int segsHeight = 0;
106 
107  vector<Figure*>::const_iterator i = children_.begin();
108  for (; i != children_.end(); i++) {
109  segsHeight += (*i)->bounds().GetHeight();
110  }
111 
112  dynamic_cast<SegmentFigure*>(children_.back())->setLast(true);
113 
114  segsHeight += (children_.size() - 1)
116 
117  size_.SetHeight(segsHeight);
118  }
119 }
120 
121 /**
122  * Draws the Figure of the bus on the given device context if it has
123  * no segments, otherwise only the segments are drawn.
124  *
125  * @param dc The device context.
126  */
127 void
129 
130  if (children_.empty()) {
131  wxPen pen = wxPen(DEFAULT_COLOUR, 1, wxSOLID);
132  wxBrush brush = wxBrush(DEFAULT_COLOUR, wxSOLID);
133  dc->SetPen(pen);
134  dc->SetBrush(brush);
135 
136  dc->DrawRectangle(location_.x, location_.y,
137  size_.GetWidth(), size_.GetHeight());
138  }
139 
140  // Draw slot label.
141  int slotLabelWidth;
142  int slotLabelHeight;
143  wxString slotLabel = WxConversion::toWxString(slot_);
144  dc->GetTextExtent(slotLabel, &slotLabelWidth, &slotLabelHeight);
145 
146  int slotLabelX = location_.x - slotLabelWidth - 10;
147  int slotLabelY =
148  ((size_.GetHeight() / 2) + location_.y) - (slotLabelHeight / 2);
149 
150  dc->SetBackgroundMode(wxTRANSPARENT);
151  dc->SetTextForeground(*wxBLACK);
152  dc->DrawText(slotLabel, slotLabelX, slotLabelY);
153 }
WxConversion::toWxString
static wxString toWxString(const std::string &source)
BusFigure::slot_
unsigned int slot_
Slot of the bus.
Definition: BusFigure.hh:67
BusFigure::virtualBounds
virtual wxRect virtualBounds() const
Definition: BusFigure.cc:67
MachineCanvasLayoutConstraints::BUS_MIN_WIDTH
static const int BUS_MIN_WIDTH
Minimum width of a bus.
Definition: MachineCanvasLayoutConstraints.hh:71
BusFigure::layoutSelf
virtual void layoutSelf(wxDC *)
Definition: BusFigure.cc:102
BusFigure::layoutChildren
virtual void layoutChildren(wxDC *)
Definition: BusFigure.cc:84
BusFigure::DEFAULT_COLOUR
static const wxColour DEFAULT_COLOUR
Default colour for the figure.
Definition: BusFigure.hh:69
Figure::children_
std::vector< Figure * > children_
Figure's children.
Definition: Figure.hh:90
SegmentFigure
Definition: SegmentFigure.hh:46
Figure::size_
wxSize size_
wxSize of the Figure's bounding rectangle.
Definition: Figure.hh:86
BusFigure::~BusFigure
virtual ~BusFigure()
Definition: BusFigure.cc:58
BusFigure::drawSelf
virtual void drawSelf(wxDC *)
Definition: BusFigure.cc:128
Figure
Definition: Figure.hh:50
Figure::location_
wxPoint location_
Top-left location of the Figure's bounding rectangle.
Definition: Figure.hh:84
SegmentFigure.hh
MachineCanvasLayoutConstraints::SEGMENT_SPACE
static const int SEGMENT_SPACE
Space dividing segments.
Definition: MachineCanvasLayoutConstraints.hh:67
Figure::minSize_
wxSize minSize_
Figure's minimum size.
Definition: Figure.hh:88
Figure::childCount
int childCount() const
MachineCanvasLayoutConstraints.hh
BusFigure::BusFigure
BusFigure(unsigned int slot)
Definition: BusFigure.cc:48
MachineCanvasLayoutConstraints::BUS_MIN_HEIGHT
static const int BUS_MIN_HEIGHT
Minimum height of a bus.
Definition: MachineCanvasLayoutConstraints.hh:73
WxConversion.hh
BusFigure.hh