OpenASIP  2.0
SelectionFigure.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 SelectToolFigure.cc
26  *
27  * Definition of SelectionFigure class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include "SelectionFigure.hh"
34 
35 #if wxCHECK_VERSION(3, 0, 0)
36 #include <wx/dcsvg.h> // wxSVGFileDC only available in wxwidgets 3.*
37 #endif
38 
40 
41 
42 /**
43  * The Constructor.
44  *
45  * @param selection Figure of the selected EditPart.
46  */
48  Figure(), selection_(selection) {
49 }
50 
51 /**
52  * The Destructor.
53  */
55 }
56 
57 /**
58  * Draws the selection's figure on the given device context.
59  */
60 void
62  // wxWidgets implementation of SVGFileDC doesnt support dashed lines, so
63  // we draw solid blue line when some item is selected when saving to *.svg
64  bool isSVGcontext = false;
65 
66 #if wxCHECK_VERSION(3, 0, 0)
67  if (dynamic_cast<wxSVGFileDC*> (dc)) {
68  isSVGcontext = true;
69  }
70 #endif
71 
72  // Draw blue rectangles around selected EditParts figures.
73  if (selection_ != NULL) {
74 
75  wxPen pen = wxPen(wxColour(0,0,255), 2, wxSHORT_DASH);
76  if (isSVGcontext) {
77  pen.SetStyle(wxSOLID);
78  }
79  wxBrush brush = wxBrush(wxColor(0,0,0), wxTRANSPARENT);
80  dc->SetBrush(brush);
81  dc->SetPen(pen);
82  wxRect bounds = selection_->bounds();
83  dc->DrawRectangle(
86  bounds.GetWidth() + 2*SELECT_BOX_MARGIN,
87  bounds.GetHeight() + 2*SELECT_BOX_MARGIN);
88  }
89 }
90 
91 
92 /**
93  * Set the selected figure.
94  *
95  * Selection figure will be drawn around the selected figure.
96  *
97  * @param selection Figure of the selected part.
98  */
99 void
101  selection_ = selection;
102 }
103 
104 
105 /**
106  * Returns the Figure's bounding rectangle.
107  *
108  * @return Figure's bounding rectangle.
109  */
110 wxRect
112  if (selection_ == NULL) {
113  return wxRect(0, 0, 0, 0);
114  }
115  wxRect bounds = selection_->bounds();
117  bounds.Inflate(SELECT_BOX_MARGIN * 4);
118  return bounds;
119 }
SelectionFigure::SelectionFigure
SelectionFigure(Figure *selection)
Definition: SelectionFigure.cc:47
Figure::bounds
virtual wxRect bounds() const
SelectionFigure::bounds
virtual wxRect bounds() const
Definition: SelectionFigure.cc:111
Figure
Definition: Figure.hh:50
SelectionFigure::~SelectionFigure
virtual ~SelectionFigure()
Definition: SelectionFigure.cc:54
SelectionFigure::selection_
Figure * selection_
Selected part figure.
Definition: SelectionFigure.hh:62
SelectionFigure::drawSelf
virtual void drawSelf(wxDC *dc)
Definition: SelectionFigure.cc:61
SelectionFigure::SELECT_BOX_MARGIN
static const int SELECT_BOX_MARGIN
Width of the margin between the part figure and selection box.
Definition: SelectionFigure.hh:65
SelectionFigure::setSelection
void setSelection(Figure *selection)
Definition: SelectionFigure.cc:100
SelectionFigure.hh