OpenASIP  2.0
MachineCanvas.hh
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 MachineCanvas.hh
26  *
27  * Declaration of MachineCanvas class.
28  *
29  * @author Veli-Pekka Jääskeläinen (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TTA_MACHINE_CANVAS_HH
34 #define TTA_MACHINE_CANVAS_HH
35 
36 #include <vector>
37 #include <wx/scrolwin.h>
38 #include <wx/docmdi.h>
39 #include "Exception.hh"
40 #include "MachineCanvasOptions.hh"
41 #include "ChildFrame.hh"
42 
43 namespace TTAMachine {
44  class Machine;
45  class MachinePart;
46  class Bus;
47  class Port;
48 }
49 
50 class MachineCanvasTool;
51 class RootEditPart;
52 class EditPolicyFactory;
53 class EditPart;
54 class Figure;
55 
56 /**
57  * Machine Object Model visualization canvas.
58  *
59  * MachineCanvas is a window which can be utilized to display visualization
60  * of a machine object model. The visualization is interactive, and behaviour
61  * of machine components can be defined using custom EditPolicies and custom
62  * MachineCanvasTools.
63  */
64 class MachineCanvas : public wxScrolledWindow {
65 public:
66  MachineCanvas(wxWindow* parent, EditPolicyFactory* policyFactory,
67  ChildFrame* parentFrame = nullptr);
68  virtual ~MachineCanvas();
69  virtual void OnDraw(wxDC& dc);
70 
71  double zoomFactor();
72  void setZoomFactor(double factor);
73  void zoomIn();
74  void zoomOut();
75  wxSize getFigureSize() const;
76 
77 
80 
82  void updateMachine();
84  EditPart* findEditPart(int x, int y);
86  bool hasEditPart(const EditPart* part) const;
87  int findEditPartsInRange(int x, int y, int range,
88  std::vector<EditPart*>& found);
89  void highlight(TTAMachine::MachinePart* model, const wxColour& colour);
90  void clearHighlights();
91  void clearSelection();
92  void select(EditPart* part);
93  void refreshToolFigure();
94 
95  void addMove(
96  const TTAMachine::Bus* bus, const TTAMachine::Port* source,
97  const TTAMachine::Port* target);
98  void clearMoves();
99 
100 #if wxCHECK_VERSION(3, 0, 0)
101  bool saveSVG(const std::string& filename);
102 #else
103  bool saveEPS(
104  const std::string& filename,
105  const std::string& title,
106  const std::string& creator = "");
107 #endif
108 
109  bool savePNG(const std::string& filename);
110 
112 
113 protected:
114  void onMouseEvent(wxMouseEvent& event);
115  void refreshLogicalRect(const wxRect& rectangle);
116 
117 private:
118  /// Tool which handles mouse events on the MachineCanvas.
120  /// Machine to draw on the canvas.
122  /// EditPolicyFactory which creates edit policies for machine components.
124  /// Parent frame which holds the MachineCanvas
126 
127  /// Zoom factor of the canvas.
128  double zoomFactor_;
129  /// Tells if the figures need to be laid out before next draw.
130  bool dirty_;
131  /// Root of the machine EditPart hierarchy.
133 
134  /// Pointer to the the selected component.
136  /// Bounding box of the last tool figure drawn.
137  wxRect toolBounds_;
138 
139  /// Move figures to be drawn on the canvas.
140  std::vector<Figure*> moveFigures_;
141 
143 
144  /// Event table of the canvas.
145  DECLARE_EVENT_TABLE()
146 };
147 #endif
MachineCanvas::getFigureSize
wxSize getFigureSize() const
Definition: MachineCanvas.cc:294
MachineCanvas::findEditPart
EditPart * findEditPart(int x, int y)
Definition: MachineCanvas.cc:421
MachineCanvas
Definition: MachineCanvas.hh:64
MachineCanvas::onMouseEvent
void onMouseEvent(wxMouseEvent &event)
Definition: MachineCanvas.cc:265
EditPolicyFactory
Definition: EditPolicyFactory.hh:46
MachineCanvas::options_
MachineCanvasOptions options_
Definition: MachineCanvas.hh:142
ChildFrame.hh
MachineCanvas::setZoomFactor
void setZoomFactor(double factor)
Definition: MachineCanvas.cc:188
MachineCanvas::clearSelection
void clearSelection()
Definition: MachineCanvas.cc:395
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
Exception.hh
MachineCanvas::refreshLogicalRect
void refreshLogicalRect(const wxRect &rectangle)
Definition: MachineCanvas.cc:329
TTAMachine::Bus
Definition: Bus.hh:53
MachineCanvasOptions.hh
MachineCanvas::toolBounds_
wxRect toolBounds_
Bounding box of the last tool figure drawn.
Definition: MachineCanvas.hh:137
MachineCanvas::selection_
EditPart * selection_
Pointer to the the selected component.
Definition: MachineCanvas.hh:135
MachineCanvas::editPolicyFactory_
EditPolicyFactory * editPolicyFactory_
EditPolicyFactory which creates edit policies for machine components.
Definition: MachineCanvas.hh:123
MachineCanvas::parent_
ChildFrame * parent_
Parent frame which holds the MachineCanvas.
Definition: MachineCanvas.hh:125
MachineCanvas::saveEPS
bool saveEPS(const std::string &filename, const std::string &title, const std::string &creator="")
Definition: MachineCanvas.cc:617
ChildFrame
Definition: ChildFrame.hh:42
MachineCanvas::zoomFactor_
double zoomFactor_
Zoom factor of the canvas.
Definition: MachineCanvas.hh:128
MachineCanvas::setTool
void setTool(MachineCanvasTool *tool)
Definition: MachineCanvas.cc:305
MachineCanvas::~MachineCanvas
virtual ~MachineCanvas()
Definition: MachineCanvas.cc:88
MachineCanvasOptions
Definition: MachineCanvasOptions.hh:42
MachineCanvas::machine_
TTAMachine::Machine * machine_
Machine to draw on the canvas.
Definition: MachineCanvas.hh:121
MachineCanvas::refreshToolFigure
void refreshToolFigure()
Definition: MachineCanvas.cc:164
MachineCanvas::selection
EditPart * selection()
Definition: MachineCanvas.cc:409
MachineCanvas::tool_
MachineCanvasTool * tool_
Tool which handles mouse events on the MachineCanvas.
Definition: MachineCanvas.hh:119
MachineCanvas::MachineCanvas
MachineCanvas(wxWindow *parent, EditPolicyFactory *policyFactory, ChildFrame *parentFrame=nullptr)
Definition: MachineCanvas.cc:70
TTAMachine::Port
Definition: Port.hh:54
Figure
Definition: Figure.hh:50
TTAMachine::MachinePart
Definition: MachinePart.hh:57
MachineCanvas::updateMachine
void updateMachine()
Definition: MachineCanvas.cc:345
MachineCanvasTool
Definition: MachineCanvasTool.hh:49
MachineCanvas::tool
MachineCanvasTool * tool()
Definition: MachineCanvas.cc:318
EditPart
Definition: EditPart.hh:60
MachineCanvas::clearHighlights
void clearHighlights()
Definition: MachineCanvas.cc:527
MachineCanvas::moveFigures_
std::vector< Figure * > moveFigures_
Move figures to be drawn on the canvas.
Definition: MachineCanvas.hh:140
MachineCanvas::select
void select(EditPart *part)
Definition: MachineCanvas.cc:485
MachineCanvas::options
MachineCanvasOptions & options()
Definition: MachineCanvas.cc:681
MachineCanvas::clearMoves
void clearMoves()
Definition: MachineCanvas.cc:577
MachineCanvas::root_
RootEditPart * root_
Root of the machine EditPart hierarchy.
Definition: MachineCanvas.hh:132
MachineCanvas::setMachine
void setMachine(TTAMachine::Machine *machine)
Definition: MachineCanvas.cc:386
MachineCanvas::findEditPartsInRange
int findEditPartsInRange(int x, int y, int range, std::vector< EditPart * > &found)
Definition: MachineCanvas.cc:454
MachineCanvas::addMove
void addMove(const TTAMachine::Bus *bus, const TTAMachine::Port *source, const TTAMachine::Port *target)
Definition: MachineCanvas.cc:541
MachineCanvas::highlight
void highlight(TTAMachine::MachinePart *model, const wxColour &colour)
Definition: MachineCanvas.cc:510
MachineCanvas::savePNG
bool savePNG(const std::string &filename)
Definition: MachineCanvas.cc:648
RootEditPart
Definition: RootEditPart.hh:44
MachineCanvas::dirty_
bool dirty_
Tells if the figures need to be laid out before next draw.
Definition: MachineCanvas.hh:130
MachineCanvas::zoomFactor
double zoomFactor()
Definition: MachineCanvas.cc:230
MachineCanvas::zoomIn
void zoomIn()
Definition: MachineCanvas.cc:240
MachineCanvas::OnDraw
virtual void OnDraw(wxDC &dc)
Definition: MachineCanvas.cc:101
TTAMachine
Definition: Assembler.hh:48
MachineCanvas::zoomOut
void zoomOut()
Definition: MachineCanvas.cc:251
MachineCanvas::hasEditPart
bool hasEditPart(const EditPart *part) const
Definition: MachineCanvas.cc:470
TTAMachine::Machine
Definition: Machine.hh:73