OpenASIP  2.0
FitWidthCmd.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 FitWidthCmd.cc
26  *
27  * Definition of FitWidthCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30  */
31 
32 #include <wx/gdicmn.h>
33 #include <wx/docview.h>
34 
35 #include "FitWidthCmd.hh"
36 #include "MDFView.hh"
37 #include "MachineCanvas.hh"
38 #include "ProDeConstants.hh"
39 #include "ProDe.hh"
40 #include "CanvasConstants.hh"
41 
42 using std::string;
43 
44 /**
45  * The Constructor.
46  */
48  EditorCommand(ProDeConstants::CMD_NAME_ZOOM_FIT_WID) {
49 
50 }
51 
52 
53 /**
54  * The Destructor.
55  */
57 }
58 
59 
60 
61 /**
62  * Executes the command.
63  *
64  * @return true, if the command was succesfully executed, false otherwise.
65  */
66 bool
68 
69  MDFView* mView = dynamic_cast<MDFView*>(view());
70  MachineCanvas* canvas = mView->canvas();
71 
72  wxSize figureSize = canvas->getFigureSize();
73  wxSize cSize = canvas->GetSize();
74 
75  // Decrease zoom factor from maximum until the figure width is smaller
76  // than the window width.
77  double factor = CanvasConstants::MAX_ZOOM_FACTOR;
78 
79  while (cSize.GetWidth() < factor*figureSize.GetWidth()) {
80  factor = factor - CanvasConstants::AUTOZOOM_STEP;
81  }
82 
83  canvas->setZoomFactor(factor);
84  return true;
85 }
86 
87 
88 /**
89  * Returns id of this command.
90  *
91  * @return ID for this command to be used in menus and toolbars.
92  */
93 int
94 FitWidthCmd::id() const {
96 }
97 
98 
99 /**
100  * Creates and returns a new instance of this command.
101  *
102  * @return Newly created instance of this command.
103  */
106  return new FitWidthCmd();
107 }
108 
109 
110 /**
111  * Returns path to the command's icon file.
112  *
113  * @return Full path to the command's icon file.
114  */
115 string
118 }
119 
120 
121 /**
122  * Returns short version of the command name.
123  *
124  * @return Short name of the command to be used in the toolbar.
125  */
126 string
129 }
130 
131 
132 /**
133  * Returns true when the command is executable, false when not.
134  *
135  * This command is executable when a document is open.
136  *
137  * @return True, if a document is open.
138  */
139 bool
141  wxDocManager* manager = wxGetApp().docManager();
142  if (manager->GetCurrentView() != NULL) {
143  return true;
144  }
145  return false;
146 }
MachineCanvas::getFigureSize
wxSize getFigureSize() const
Definition: MachineCanvas.cc:294
MachineCanvas
Definition: MachineCanvas.hh:64
ProDe.hh
CanvasConstants.hh
MachineCanvas::setZoomFactor
void setZoomFactor(double factor)
Definition: MachineCanvas.cc:188
MDFView::canvas
MachineCanvas * canvas() const
Definition: MDFView.cc:229
FitWidthCmd::create
virtual FitWidthCmd * create() const
Definition: FitWidthCmd.cc:105
CanvasConstants::MAX_ZOOM_FACTOR
static const double MAX_ZOOM_FACTOR
Maximum zoom factor.
Definition: CanvasConstants.hh:47
ProDeConstants::CMD_SNAME_ZOOM_FIT_WID
static const std::string CMD_SNAME_ZOOM_FIT_WID
Command name for the "Fit Width" command.
Definition: ProDeConstants.hh:278
ProDeConstants::COMMAND_ZOOM_FIT_WID
@ COMMAND_ZOOM_FIT_WID
Definition: ProDeConstants.hh:451
FitWidthCmd.hh
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
MachineCanvas.hh
FitWidthCmd::id
virtual int id() const
Definition: FitWidthCmd.cc:94
ProDeConstants::CMD_ICON_ZOOM_FIT_WID
static const std::string CMD_ICON_ZOOM_FIT_WID
Icon location for the "Fit Width" command.
Definition: ProDeConstants.hh:336
ProDeConstants.hh
MDFView.hh
FitWidthCmd
Definition: FitWidthCmd.hh:40
CanvasConstants::AUTOZOOM_STEP
static const double AUTOZOOM_STEP
More precise step for automatic canvas resizing.
Definition: CanvasConstants.hh:51
FitWidthCmd::icon
virtual std::string icon() const
Definition: FitWidthCmd.cc:116
EditorCommand
Definition: EditorCommand.hh:46
FitWidthCmd::isEnabled
virtual bool isEnabled()
Definition: FitWidthCmd.cc:140
FitWidthCmd::~FitWidthCmd
virtual ~FitWidthCmd()
Definition: FitWidthCmd.cc:56
ProDeConstants
Definition: ProDeConstants.hh:43
FitWidthCmd::shortName
virtual std::string shortName() const
Definition: FitWidthCmd.cc:127
FitWidthCmd::Do
virtual bool Do()
Definition: FitWidthCmd.cc:67
FitWidthCmd::FitWidthCmd
FitWidthCmd()
Definition: FitWidthCmd.cc:47
MDFView
Definition: MDFView.hh:59