wxArt2D
transdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: transform.cpp
3 // Purpose:
4 // Author: Klaas Holwerda
5 // Modified by:
6 // Created: 15/04/2008 10:44:52
7 // RCS-ID:
8 // Copyright: Klaas Holwerda
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11 
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "a2dprec.h"
14 
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18 
19 #ifndef WX_PRECOMP
20 #include "wx/wx.h"
21 #endif
22 
23 #include "wx/canvas/transdlg.h"
24 #include "wx/canvas/canmod.h"
25 
26 #define ID_x 10002
27 #define ID_y 10003
28 #define ID_scalex 10006
29 #define ID_scaley 10004
30 #define ID_TEXTCTRL3 10013
31 #define ID_vertical 10010
32 #define ID_horizontal 10009
33 #define ID_rotateangle 10014
34 #define ID_clockwise 10011
35 #define ID_counterclockwise 10012
36 #define ID_hide 10015
37 #define ID_apply 10016
38 
39 /*!
40  * transform type definition
41  */
42 
43 IMPLEMENT_DYNAMIC_CLASS( a2dTransDlg, wxDialog )
44 
45 /*!
46  * transform event table definition
47  */
48 BEGIN_EVENT_TABLE( a2dTransDlg, wxDialog )
49  EVT_BUTTON( ID_hide, a2dTransDlg::OnHideClick )
50  EVT_BUTTON( ID_apply, a2dTransDlg::OnApplyClick )
51 END_EVENT_TABLE()
52 
53 
54 /*!
55  * transform constructors
56  */
57 a2dTransDlg::a2dTransDlg()
58 {
59  Init();
60 }
61 
62 a2dTransDlg::a2dTransDlg( wxWindow* parent, bool modal, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
63 {
64  m_modal = modal;
65  Init();
66  Create( parent, id, caption, pos, size, style );
67 }
68 
69 
70 /*!
71  * transform creator
72  */
73 bool a2dTransDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
74 {
75  SetExtraStyle( wxWS_EX_BLOCK_EVENTS );
76  wxDialog::Create( parent, id, caption, pos, size, style );
77 
79  if ( GetSizer() )
80  {
81  GetSizer()->SetSizeHints( this );
82  }
83  Centre();
84  return true;
85 }
86 
87 
88 /*!
89  * transform destructor
90  */
92 {
93 }
94 
95 
96 /*!
97  * Member initialisation
98  */
100 {
101  m_x = NULL;
102  m_y = NULL;
103  m_scalex = NULL;
104  m_scaley = NULL;
105  m_vertical = NULL;
106  m_horizontal = NULL;
107  m_rotateangle = NULL;
108  m_clockwise = NULL;
109  m_counterclockwise = NULL;
110  m_hide = NULL;
111  m_apply = NULL;
112 }
113 
115 {
116  a2dTransDlg* itemDialog1 = this;
117 
118  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer( wxVERTICAL );
119  itemDialog1->SetSizer( itemBoxSizer2 );
120 
121  wxStaticBox* itemStaticBoxSizer3Static = new wxStaticBox( itemDialog1, wxID_ANY, _( "Move (x,y)" ) );
122  wxStaticBoxSizer* itemStaticBoxSizer3 = new wxStaticBoxSizer( itemStaticBoxSizer3Static, wxVERTICAL );
123  itemBoxSizer2->Add( itemStaticBoxSizer3, 0, wxALIGN_LEFT | wxALL, 2 );
124 
125  m_x = new wxTextCtrl( itemDialog1, ID_x, _( "0" ), wxDefaultPosition, wxDefaultSize, 0 );
126  m_x->SetHelpText( _( "Move by x" ) );
128  m_x->SetToolTip( _( "Move by x" ) );
129  m_x->SetName( _T( "x" ) );
130  itemStaticBoxSizer3->Add( m_x, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2 );
131 
132  m_y = new wxTextCtrl( itemDialog1, ID_y, _( "0" ), wxDefaultPosition, wxDefaultSize, 0 );
133  m_y->SetHelpText( _( "Move by y" ) );
135  m_y->SetToolTip( _( "Move by y" ) );
136  m_y->SetName( _T( "y" ) );
137  itemStaticBoxSizer3->Add( m_y, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2 );
138 
139  wxStaticBox* itemStaticBoxSizer6Static = new wxStaticBox( itemDialog1, wxID_ANY, _( "Scale (x,y)" ) );
140  wxStaticBoxSizer* itemStaticBoxSizer6 = new wxStaticBoxSizer( itemStaticBoxSizer6Static, wxVERTICAL );
141  itemBoxSizer2->Add( itemStaticBoxSizer6, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5 );
142 
143  m_scalex = new wxTextCtrl( itemDialog1, ID_scalex, _( "1" ), wxDefaultPosition, wxDefaultSize, 0 );
144  m_scalex->SetHelpText( _( "Scale in x with this value" ) );
146  m_scalex->SetToolTip( _( "Scale in x with this value" ) );
147  m_scalex->SetName( _T( "scalex" ) );
148  itemStaticBoxSizer6->Add( m_scalex, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2 );
149 
150  m_scaley = new wxTextCtrl( itemDialog1, ID_scaley, _( "1" ), wxDefaultPosition, wxDefaultSize, 0 );
151  m_scaley->SetHelpText( _( "Scale in y with this value" ) );
153  m_scaley->SetToolTip( _( "Scale in y with this value" ) );
154  m_scaley->SetName( _T( "scaley" ) );
155  itemStaticBoxSizer6->Add( m_scaley, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2 );
156 
157  wxStaticBox* itemStaticBoxSizer9Static = new wxStaticBox( itemDialog1, wxID_ANY, _( "Mirror" ) );
158  wxStaticBoxSizer* itemStaticBoxSizer9 = new wxStaticBoxSizer( itemStaticBoxSizer9Static, wxVERTICAL );
159  itemBoxSizer2->Add( itemStaticBoxSizer9, 0, wxALIGN_LEFT | wxALL, 2 );
160 
161  m_vertical = new wxCheckBox( itemDialog1, ID_vertical, _( "Vertical" ), wxDefaultPosition, wxDefaultSize, 0 );
162  m_vertical->SetValue( false );
163  m_vertical->SetHelpText( _( "Mirror on vertical axis" ) );
165  m_vertical->SetToolTip( _( "Mirror on vertical axis" ) );
166  m_vertical->SetName( _T( "vertical" ) );
167  itemStaticBoxSizer9->Add( m_vertical, 0, wxALIGN_LEFT | wxALL, 2 );
168 
169  m_horizontal = new wxCheckBox( itemDialog1, ID_horizontal, _( "Horizontal" ), wxDefaultPosition, wxDefaultSize, 0 );
170  m_horizontal->SetValue( false );
171  m_horizontal->SetHelpText( _( "Mirror the object on horizontal" ) );
173  m_horizontal->SetToolTip( _( "Mirror the object on horizontal" ) );
174  m_horizontal->SetName( _T( "horizontal" ) );
175  itemStaticBoxSizer9->Add( m_horizontal, 0, wxALIGN_LEFT | wxALL, 2 );
176 
177  wxStaticBox* itemStaticBoxSizer12Static = new wxStaticBox( itemDialog1, wxID_ANY, _( "Rotate" ) );
178  wxStaticBoxSizer* itemStaticBoxSizer12 = new wxStaticBoxSizer( itemStaticBoxSizer12Static, wxVERTICAL );
179  itemBoxSizer2->Add( itemStaticBoxSizer12, 0, wxALIGN_LEFT | wxALL, 2 );
180 
181  m_rotateangle = new wxTextCtrl( itemDialog1, ID_rotateangle, _( "0" ), wxDefaultPosition, wxDefaultSize, 0 );
182  m_rotateangle->SetHelpText( _( "Rotate object by this angle" ) );
184  m_rotateangle->SetToolTip( _( "Rotate object by this angle" ) );
185  m_rotateangle->SetName( _T( "rotateangle" ) );
186  itemStaticBoxSizer12->Add( m_rotateangle, 0, wxALIGN_LEFT | wxALL, 2 );
187 
188  m_clockwise = new wxRadioButton( itemDialog1, ID_clockwise, _( "Clockwise" ), wxDefaultPosition, wxDefaultSize, 0 );
189  m_clockwise->SetValue( true );
190  m_clockwise->SetHelpText( _( "Rotate clockwise" ) );
192  m_clockwise->SetToolTip( _( "Rotate clockwise" ) );
193  m_clockwise->SetName( _T( "clockwise" ) );
194  itemStaticBoxSizer12->Add( m_clockwise, 0, wxALIGN_LEFT | wxALL, 2 );
195 
196  m_counterclockwise = new wxRadioButton( itemDialog1, ID_counterclockwise, _( "Counter clockwise" ), wxDefaultPosition, wxDefaultSize, 0 );
197  m_counterclockwise->SetValue( false );
198  m_counterclockwise->SetHelpText( _( "Rotate clockwise" ) );
200  m_counterclockwise->SetToolTip( _( "Rotate clockwise" ) );
201  m_counterclockwise->SetName( _T( "counterclockwise" ) );
202  itemStaticBoxSizer12->Add( m_counterclockwise, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2 );
203 
204  wxBoxSizer* itemBoxSizer16 = new wxBoxSizer( wxHORIZONTAL );
205  itemBoxSizer2->Add( itemBoxSizer16, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5 );
206 
207  if ( !m_modal )
208  {
209  m_hide = new wxButton( itemDialog1, ID_hide, _( "Hide" ), wxDefaultPosition, wxSize( 50, -1 ), 0 );
210  m_hide->SetHelpText( _( "Hide this dialog" ) );
212  m_hide->SetToolTip( _( "Hide this dialog" ) );
213  m_hide->SetName( _T( "hide" ) );
214  itemBoxSizer16->Add( m_hide, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2 );
215 
216  m_apply = new wxButton( itemDialog1, ID_apply, _( "Apply" ), wxDefaultPosition, wxSize( 50, -1 ), 0 );
217  m_apply->SetHelpText( _( "Apply transform" ) );
219  m_apply->SetToolTip( _( "Apply transform" ) );
220  m_apply->SetName( _T( "apply" ) );
221  itemBoxSizer16->Add( m_apply, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2 );
222  }
223  else
224  {
225  m_hide = new wxButton( itemDialog1, ID_hide, _( "Cancel" ), wxDefaultPosition, wxSize( 50, -1 ), 0 );
226  m_hide->SetHelpText( _( "Cancel this action" ) );
228  m_hide->SetToolTip( _( "Cancel this dialog" ) );
229  m_hide->SetName( _T( "hide" ) );
230 
231  itemBoxSizer16->Add( m_hide, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2 );
232  m_apply = new wxButton( itemDialog1, ID_apply, _( "Oke" ), wxDefaultPosition, wxSize( 50, -1 ), 0 );
233  m_apply->SetHelpText( _( "Apply transform" ) );
235  m_apply->SetToolTip( _( "Apply transform" ) );
236  m_apply->SetName( _T( "apply" ) );
237  itemBoxSizer16->Add( m_apply, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2 );
238  }
239 }
240 
241 /*!
242  * Should we show tooltips?
243  */
245 {
246  return true;
247 }
248 
249 /*!
250  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_hide
251  */
252 void a2dTransDlg::OnHideClick( wxCommandEvent& event )
253 {
254  if ( m_modal )
255  {
256  EndModal( wxID_CANCEL );
257  }
258  else
259  Show( false );
260 }
261 
262 /*!
263  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_apply
264  */
265 void a2dTransDlg::OnApplyClick( wxCommandEvent& event )
266 {
267  m_lworld = a2dIDENTITY_MATRIX;
268  m_lworld.Mirror( m_vertical->GetValue(), m_horizontal->GetValue() );
269 
270  double x = 0;
271  m_x->GetValue().ToDouble( &x );
272  double y = 0;
273  m_y->GetValue().ToDouble( &y );
274  m_lworld.Translate( x, y );
275 
276  double rotate = 0;
277  m_rotateangle->GetValue().ToDouble( &rotate );
278  if ( m_clockwise->GetValue() )
279  rotate = -rotate;
280  m_lworld = m_lworld.Rotate( rotate, 0, 0 );
281 
282  double scalex = 1;
283  m_scalex->GetValue().ToDouble( &scalex );
284  double scaley = 1;
285  m_scaley->GetValue().ToDouble( &scaley );
286  m_lworld.Scale( scalex, scaley, x, y );
287 
288  if ( m_modal )
289  {
290  EndModal( wxID_OK );
291  }
292  else
293  {
295  if ( !drawingPart )
296  return;
297 
298  a2dCanvasObject* top = drawingPart->GetShowObject();
299 
300  a2dCommand_TransformMask* com = new a2dCommand_TransformMask( top, m_lworld );
301  drawingPart->GetDrawing()->GetCommandProcessor()->Submit( com );
302  }
303 }
304 
Display Part of a a2dDrawing, in which a2dCanvasObjects are shown.
Definition: drawer.h:470
a2dAffineMatrix & Mirror(bool y=true, bool x=false)
mirror a matrix in x, y
Definition: afmatrix.cpp:396
bool Rotate(double angle)
Rotate clockwise by the given number of degrees:
Definition: afmatrix.cpp:432
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
a2dAffineMatrix a2dIDENTITY_MATRIX
global a2dAffineMatrix to set/pass the identity matrix.
Definition: afmatrix.cpp:51
void OnApplyClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_apply
Definition: transdlg.cpp:265
a2dDrawingPart * GetActiveDrawingPart()
return the currently/last active drawing part.
Definition: canglob.h:1262
~a2dTransDlg()
Destructor.
Definition: transdlg.cpp:91
void Init()
Initialises member variables.
Definition: transdlg.cpp:99
for changing only the matrix of objects for which a certain mask was set
Definition: drawing.h:1822
bool Create(wxWindow *parent, wxWindowID id=SYMBOL_TRANSFORM_IDNAME, const wxString &caption=SYMBOL_TRANSFORM_TITLE, const wxPoint &pos=SYMBOL_TRANSFORM_POSITION, const wxSize &size=SYMBOL_TRANSFORM_SIZE, long style=SYMBOL_TRANSFORM_STYLE)
Creation.
Definition: transdlg.cpp:73
a2dCanvasObject * GetShowObject() const
return pointer of then currently shown object on the drawer.
Definition: drawer.h:680
virtual bool Submit(a2dCommand *command, bool storeIt=true)
next to the base class submit, it sets a2DocumentCommandProcessor for a2dCommand
Definition: comevt.cpp:842
void OnHideClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_hide
Definition: transdlg.cpp:252
static bool ShowToolTips()
Should we show tooltips?
Definition: transdlg.cpp:244
a2dCommandProcessor * GetCommandProcessor() const
Returns a pointer to the command processor associated with this document.
Definition: drawing.h:549
void CreateControls()
Creates the controls and sizers.
Definition: transdlg.cpp:114
a2dTransDlg()
Constructors.
Definition: transdlg.cpp:57
bool Scale(double scale)
Scale by scale (isotropic scaling i.e. the same in x and y):
Definition: afmatrix.cpp:270
bool Translate(double x, double y)
Translate by dx, dy:
Definition: afmatrix.cpp:420
a2dDrawing * GetDrawing() const
get drawing via top object
Definition: drawer.cpp:726
a2dCanvasGlobal * a2dCanvasGlobals
global a2dCanvasGlobal to have easy access to global settings
Definition: canglob.cpp:1234
all headers of the canvas module
transdlg.cpp Source File -- Sun Oct 12 2014 17:04:26 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation