OpenASIP  2.0
MDFView.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 MDFView.cc
26  *
27  * Definition of MFDView class.
28  *
29  * @author Veli-Pekka J��skel�inen 2003 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  * @note reviewed Jun 23 2004 by ml, jn, jm, vpj
32  */
33 
34 #include <wx/dcps.h>
35 #include <string>
36 #include "MDFView.hh"
37 #include "tce_config.h"
38 #include "MDFDocument.hh"
39 #include "Machine.hh"
40 #include "SelectTool.hh"
41 #include "EditPart.hh"
42 #include "ProDeConstants.hh"
43 #include "WxConversion.hh"
44 #include "FileSystem.hh"
45 #include "MachineCanvas.hh"
47 #include "MainFrame.hh"
48 #include "ADFPrintout.hh"
49 
50 IMPLEMENT_DYNAMIC_CLASS(MDFView, wxView)
51 
52 using std::vector;
53 using std::string;
54 using namespace TTAMachine;
55 
56 
57 /**
58  * The Constructor.
59  */
61  wxView(),
62  canvas_(NULL),
63  frame_(NULL) {
64 }
65 
66 
67 /**
68  * The Destructor.
69  */
71 }
72 
73 
74 /**
75  * Implements closing behaviour.
76  *
77  * Closes the associated document.
78  *
79  * @param deleteWindow If true, deletes the frame associated with the view.
80  * @return true if the associated document was succesfully closed.
81  */
82 bool
83 MDFView::OnClose(bool deleteWindow) {
84 
85  if (!GetDocument()->Close()) {
86  return false;
87  }
88 
89  Activate(false);
90 
91  if (deleteWindow) {
92  delete canvas_;
93  canvas_ = NULL;
94  delete frame_;
95  frame_ = NULL;
96  }
97  return true;
98 }
99 
100 
101 /**
102  * Creates a ChildFrame and a Canvas for the document when a new view
103  * is created.
104  *
105  * @param doc Pointer to the document which this view visualizes.
106  * @return True if the ChildFrame and the Canvas was succesfully
107  * created.
108  */
109 bool
110 MDFView::OnCreate(wxDocument* doc, long) {
111 
112  if (doc == NULL) {
113  return false;
114  }
115 
116  // create a childframe for the view
117  wxDocMDIParentFrame* mainFrame = wxGetApp().mainFrame();
118  frame_ = new ChildFrame(doc, this, mainFrame);
119  SetFrame(frame_);
120  frame_->Show(true);
121 
122  // create a canvas for the child frame
124  // create select tool and set it as active tool for the canvas
125  SelectTool* selectTool = new SelectTool(frame_, this);
126  canvas_->setTool(selectTool);
127 
128  Activate(true);
129  return true;
130 }
131 
132 
133 /**
134  * Updates the model visualization.
135  *
136  * @param sender View that sent the update request, or NULL if no
137  * single view requested the update (for instance, when
138  * the document is opened).
139  * @param hint Unused at the moment but may in future contain
140  * application-specific information for making updating
141  * more efficient.
142  */
143 void
144 MDFView::OnUpdate(wxView* /* sender */, wxObject* /* hint */) {
145 
146  wxDocument* doc = GetDocument();
147  assert(doc != NULL);
148  MDFDocument* mdfdoc = dynamic_cast<MDFDocument*>(doc);
149  assert(mdfdoc != NULL);
150 
151  Model* model = mdfdoc->getModel();
152  if (model == NULL) {
153  // The model is NULL if document opening fails.
154  // View is updated even if the document opening fails.
155  return;
156  }
157 
158  Machine* machine = model->getMachine();
159  assert(machine != NULL);
161 }
162 
163 /**
164  * Returns selected component of the view.
165  *
166  * @return Pointer to the selected EditPart.
167  */
168 EditPart*
170  if (canvas_ != NULL) {
171  return canvas_->selection();
172  } else {
173  return NULL;
174  }
175 }
176 
177 
178 /**
179  * Clears the component selection.
180  */
181 void
184 }
185 
186 
187 /**
188  * Sets the main frame title when the view is activated.
189  */
190 void
192  bool activate, wxView* /* unused */, wxView* /* unused */) {
193 
194  if (!activate) {
195  wxString title = ProDeConstants::EDITOR_NAME;
196  wxGetApp().mainFrame()->SetTitle(title);
197  return;
198  }
199 
200  OnUpdate(NULL, NULL);
201 
202  // Update main frame title.
204  wxGetApp().mainFrame()->updateUI();
205 }
206 
207 
208 /**
209  * Updates the main and child frame titles when the filename changes.
210  */
211 void
213  string path = WxConversion::toString(GetDocument()->GetFilename());
214  string filename = FileSystem::fileOfPath(path);
215  wxString title = ProDeConstants::EDITOR_NAME;
216  title.Append(_T(" - "));
217  title.Append(WxConversion::toWxString(filename));
218  wxGetApp().mainFrame()->SetTitle(title);
219  frame_->SetTitle(WxConversion::toWxString(filename));
220 }
221 
222 
223 /**
224  * Returns pointer to the MachineCanvas of the view.
225  *
226  * @return MachineCanvas of the view.
227  */
230  return canvas_;
231 }
232 
233 
234 /**
235  * Handles paint events of the view.
236  *
237  * @param dc Device context to draw the machine on.
238  */
239 void
240 MDFView::OnDraw(wxDC* dc) {
241  canvas_->OnDraw(*dc);
242 }
243 
244 
245 /**
246  * Creates printout of the machine figure.
247  *
248  * @return Printout object of the machine figure for printing.
249  */
250 wxPrintout*
252  return new ADFPrintout(*canvas_, GetDocument()->GetFilename());
253 }
MDFDocument::getModel
Model * getModel()
Definition: MDFDocument.cc:229
MachineCanvas
Definition: MachineCanvas.hh:64
FileSystem.hh
WxConversion::toWxString
static wxString toWxString(const std::string &source)
SelectTool
Definition: SelectTool.hh:47
MDFDocument.hh
MachineCanvas::clearSelection
void clearSelection()
Definition: MachineCanvas.cc:395
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
MDFView::canvas
MachineCanvas * canvas() const
Definition: MDFView.cc:229
MDFView::OnCreatePrintout
virtual wxPrintout * OnCreatePrintout()
Definition: MDFView.cc:251
FileSystem::fileOfPath
static std::string fileOfPath(const std::string pathName)
Definition: FileSystem.cc:101
ChildFrame
Definition: ChildFrame.hh:42
MachineCanvas::setTool
void setTool(MachineCanvasTool *tool)
Definition: MachineCanvas.cc:305
assert
#define assert(condition)
Definition: Application.hh:86
MachineCanvas::selection
EditPart * selection()
Definition: MachineCanvas.cc:409
EditPart.hh
MDFView::OnChangeFilename
virtual void OnChangeFilename()
Definition: MDFView.cc:212
MDFView::clearSelection
void clearSelection()
Definition: MDFView.cc:182
MDFView::OnCreate
virtual bool OnCreate(wxDocument *doc, long)
Definition: MDFView.cc:110
MachineCanvas.hh
EditPart
Definition: EditPart.hh:60
Machine.hh
ADFPrintout.hh
ProDeEditPolicyFactory
Definition: ProDeEditPolicyFactory.hh:42
ProDeConstants::EDITOR_NAME
static const wxString EDITOR_NAME
Full name of the Editor.
Definition: ProDeConstants.hh:386
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants.hh
MDFView::selection
EditPart * selection()
Definition: MDFView.cc:169
SelectTool.hh
MainFrame.hh
MDFView::frame_
ChildFrame * frame_
ChildFrame for displaying the view.
Definition: MDFView.hh:87
MDFView::canvas_
MachineCanvas * canvas_
The window where the figures are drawn.
Definition: MDFView.hh:85
MDFView.hh
MachineCanvas::setMachine
void setMachine(TTAMachine::Machine *machine)
Definition: MachineCanvas.cc:386
MDFView::OnDraw
virtual void OnDraw(wxDC *dc)
Definition: MDFView.cc:240
MDFView::OnActivateView
virtual void OnActivateView(bool activate, wxView *activateView, wxView *deactivateView)
Definition: MDFView.cc:191
Model
Definition: Model.hh:50
MDFView::OnUpdate
virtual void OnUpdate(wxView *sender, wxObject *hint)
Definition: MDFView.cc:144
WxConversion.hh
MDFView::~MDFView
virtual ~MDFView()
Definition: MDFView.cc:70
MachineCanvas::OnDraw
virtual void OnDraw(wxDC &dc)
Definition: MachineCanvas.cc:101
TTAMachine
Definition: Assembler.hh:48
MDFView::OnClose
virtual bool OnClose(bool deleteWindow)
Definition: MDFView.cc:83
WxConversion::toString
static std::string toString(const wxString &source)
ProDeEditPolicyFactory.hh
ADFPrintout
Definition: ADFPrintout.hh:45
Model::getMachine
TTAMachine::Machine * getMachine()
Definition: Model.cc:88
TTAMachine::Machine
Definition: Machine.hh:73
MDFView::MDFView
MDFView()
Definition: MDFView.cc:60
MDFView
Definition: MDFView.hh:59