OpenASIP  2.0
UnitPortFigure.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 UnitPortFigure.cc
26  *
27  * Definition of UnitPortFigure 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 "UnitPortFigure.hh"
38 #include "MathTools.hh"
39 
40 #include "InputSocketFigure.hh"
41 #include "OutputSocketFigure.hh"
42 
43 using std::vector;
44 
45 const wxColour UnitPortFigure::DEFAULT_COLOUR = wxColour(0, 0, 0);
46 const wxColour UnitPortFigure::DEFAULT_BG_COLOUR = wxColour(255, 255, 255);
47 
48 /**
49  * The Constructor.
50  */
51 UnitPortFigure::UnitPortFigure(std::string name, int bitWidth): Figure(), name_(name) {
52  size_ = wxSize(std::max(
53  ((MathTools::requiredBits(bitWidth)+(bitWidth/31))<<1)+
57 }
58 
59 /**
60  * The Destructor.
61  */
63 }
64 
65 /**
66  * Sets the x-coordinate for its child sockets.
67  */
68 void
70  int socketX = location_.x;
71  bool oneSet = false;
72 
73  for (unsigned int i = 0; i < children_.size(); i++) {
74 
75  children_[i]->setWidth(size_.GetWidth());
76 
77  if (!oneSet && !children_[i]->xSet()) {
78  children_[i]->setX(location_.x);
79  oneSet = true;
82  } else if (children_[i]->location().x == 0) {
83  children_[i]->setPreferredX(socketX);
84  }
85  }
86 }
87 
88 /**
89  * Draws the port's Figure on the given device context.
90  *
91  * @param dc The device context.
92  */
93 void
95  wxPen pen = wxPen(DEFAULT_COLOUR, 1, wxSOLID);
96  dc->SetPen(pen);
97  wxBrush brush = wxBrush(DEFAULT_BG_COLOUR, wxSOLID);
98  if (highlighted_) {
99  brush = wxBrush(highlight_, wxSOLID);
100  }
101  dc->SetBrush(brush);
102  dc->DrawRectangle(location_.x, location_.y, size_.GetWidth(),
103  size_.GetHeight());
104 }
105 
106 /**
107  * Returns name of the port.
108  *
109  * @return Name of the port.
110  */
111 std::string
113  return name_;
114 }
UnitPortFigure::UnitPortFigure
UnitPortFigure(std::string name, int bitWidth)
Definition: UnitPortFigure.cc:51
UnitPortFigure::drawSelf
virtual void drawSelf(wxDC *dc)
Definition: UnitPortFigure.cc:94
InputSocketFigure.hh
UnitPortFigure::name
std::string name() const
Definition: UnitPortFigure.cc:112
MachineCanvasLayoutConstraints::PORT_BASE_WIDTH
static const int PORT_BASE_WIDTH
Constant used for port width calculation.
Definition: MachineCanvasLayoutConstraints.hh:55
MachineCanvasLayoutConstraints::PORT_MIN_WIDTH
static const int PORT_MIN_WIDTH
Minimum Width of a port.
Definition: MachineCanvasLayoutConstraints.hh:53
Figure::children_
std::vector< Figure * > children_
Figure's children.
Definition: Figure.hh:90
MachineCanvasLayoutConstraints::SOCKET_WIDTH
static const int SOCKET_WIDTH
Width of a socket.
Definition: MachineCanvasLayoutConstraints.hh:59
Figure::highlight_
wxColour highlight_
Highlight colour.
Definition: Figure.hh:99
MachineCanvasLayoutConstraints::SOCKET_MIN_SPACE
static const int SOCKET_MIN_SPACE
Space dividing connected sockets.
Definition: MachineCanvasLayoutConstraints.hh:65
Figure::location
wxPoint location() const
Figure::size_
wxSize size_
wxSize of the Figure's bounding rectangle.
Definition: Figure.hh:86
UnitPortFigure::DEFAULT_COLOUR
static const wxColour DEFAULT_COLOUR
Default colour for the figure.
Definition: UnitPortFigure.hh:63
OutputSocketFigure.hh
UnitPortFigure::name_
std::string name_
Name of the port.
Definition: UnitPortFigure.hh:68
Figure
Definition: Figure.hh:50
Figure::location_
wxPoint location_
Top-left location of the Figure's bounding rectangle.
Definition: Figure.hh:84
Figure::xSet
bool xSet() const
UnitPortFigure.hh
MachineCanvasLayoutConstraints::PORT_WIDTH
static const int PORT_WIDTH
Default Width of a port.
Definition: MachineCanvasLayoutConstraints.hh:51
MathTools::requiredBits
static int requiredBits(unsigned long int number)
UnitPortFigure::DEFAULT_BG_COLOUR
static const wxColour DEFAULT_BG_COLOUR
Default background colour for the figure.
Definition: UnitPortFigure.hh:65
UnitPortFigure::layoutChildren
virtual void layoutChildren(wxDC *)
Definition: UnitPortFigure.cc:69
Figure::highlighted_
bool highlighted_
Tells if the figure is highlighted.
Definition: Figure.hh:101
MachineCanvasLayoutConstraints.hh
UnitPortFigure::~UnitPortFigure
virtual ~UnitPortFigure()
Definition: UnitPortFigure.cc:62
MathTools.hh