wxArt2D
pathsettings.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: a2dPathSettings.cpp
3 // Purpose:
4 // Author: Klaas Holwerda
5 // Modified by:
6 // Created: 10/04/2008 17:02:58
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 ////@begin includes
24 ////@end includes
25 
26 #include "wx/canvas/pathsettings.h"
27 #include "wx/canvas/edit.h"
28 #include "wx/canvas/canmod.h"
29 
30 #define ID_WIDTH 10002
31 #define ID_UNITS 10005
32 #define ID_Rounded 10001
33 #define ID_Rectangle 10003
34 #define ID_RectangleExt 10004
35 #define ID_HIDE 10006
36 #define ID_APPLY 10007
37 
38 ////@begin XPM images
39 ////@end XPM images
40 
41 
42 /*!
43  * a2dPathSettings type definition
44  */
45 
46 IMPLEMENT_DYNAMIC_CLASS( a2dPathSettings, wxDialog )
47 
48 
49 /*!
50  * a2dPathSettings event table definition
51  */
52 
53 BEGIN_EVENT_TABLE( a2dPathSettings, wxDialog )
54  EVT_COM_EVENT( a2dPathSettings::OnComEvent )
55  EVT_TEXT_ENTER( ID_WIDTH, a2dPathSettings::OnWidthEnter )
56  EVT_CHOICE( ID_UNITS, a2dPathSettings::OnUnitsSelected )
57  EVT_RADIOBUTTON( ID_Rounded, a2dPathSettings::OnRoundedSelected )
58  EVT_RADIOBUTTON( ID_Rectangle, a2dPathSettings::OnRectangleSelected )
59  EVT_RADIOBUTTON( ID_RectangleExt, a2dPathSettings::OnRectangleExtSelected )
60  EVT_BUTTON( ID_HIDE, a2dPathSettings::OnHideClick )
61  EVT_BUTTON( ID_APPLY, a2dPathSettings::OnApplyClick )
62 END_EVENT_TABLE()
63 
64 
65 /*!
66  * a2dPathSettings constructors
67  */
68 
69 a2dPathSettings::a2dPathSettings()
70 {
71  Init();
72 }
73 
74 a2dPathSettings::a2dPathSettings( a2dHabitat* habitat, wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
75 {
76  m_habitat = habitat;
77  Init();
78  Create( parent, id, caption, pos, size, style );
79 }
80 
81 
82 /*!
83  * a2dPathSettings creator
84  */
85 
86 bool a2dPathSettings::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
87 {
88 ////@begin a2dPathSettings creation
89  SetExtraStyle( wxWS_EX_BLOCK_EVENTS );
90  wxDialog::Create( parent, id, caption, pos, size, style );
91 
93  if ( GetSizer() )
94  {
95  GetSizer()->SetSizeHints( this );
96  }
97  Centre();
98 ////@end a2dPathSettings creation
99  return true;
100 }
101 
102 
103 /*!
104  * a2dPathSettings destructor
105  */
106 
108 {
109 }
110 
111 
112 /*!
113  * Member initialisation
114  */
115 
117 {
118  m_width = NULL;
119  m_units = NULL;
120  m_rounded = NULL;
121  m_rectangular = NULL;
122  m_extRectangular = NULL;
123  m_hide = NULL;
124  m_apply = NULL;
125  m_pathtype = m_habitat->GetPathType();
126  m_contourWidth = m_habitat->GetContourWidth();
127 }
128 
129 
130 /*!
131  * Control creation for a2dPathSettings
132  */
133 
135 {
136  a2dPathSettings* itemDialog1 = this;
137 
138  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer( wxVERTICAL );
139  itemDialog1->SetSizer( itemBoxSizer2 );
140 
141  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer( wxHORIZONTAL );
142  itemBoxSizer2->Add( itemBoxSizer3, 1, wxGROW | wxALL, 2 );
143 
144  wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, wxID_STATIC, _( "Width" ), wxDefaultPosition, wxDefaultSize, 0 );
145  itemStaticText4->SetHelpText( _( "width of polylines and lines" ) );
147  itemStaticText4->SetToolTip( _( "width of polylines and lines" ) );
148  itemBoxSizer3->Add( itemStaticText4, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
149 
150  m_width = new wxTextCtrl( itemDialog1, ID_WIDTH, _( "0" ), wxDefaultPosition, wxSize( 100, -1 ), wxTE_PROCESS_ENTER );
151  m_width->SetHelpText( _( "Width of polyline" ) );
153  m_width->SetToolTip( _( "Width of polyline" ) );
154  m_width->SetName( _T( "width" ) );
155  itemBoxSizer3->Add( m_width, 2, wxALIGN_CENTER_VERTICAL | wxALL, 1 );
156 
157  m_unitsStrings.Add( wxT( "pm" ) );
158  m_unitsStrings.Add( wxT( "nm" ) );
159  m_unitsStrings.Add( wxT( "um" ) );
160  m_unitsStrings.Add( wxT( "mm" ) );
161  m_unitsStrings.Add( wxT( "cm" ) );
162  m_unitsStrings.Add( wxT( "dm" ) );
163  m_unitsStrings.Add( wxT( "m" ) );
164  m_unitsStrings.Add( wxT( "mil" ) );
165  m_unitsStrings.Add( wxT( "inch" ) );
166  m_unitsStrings.Add( wxT( "foot" ) );
167 
168  m_units = new wxChoice( itemDialog1, ID_UNITS, wxDefaultPosition, wxSize( 40, -1 ), m_unitsStrings, 0 );
169  m_units->SetStringSelection( _( "um" ) );
170  m_units->SetHelpText( _( "Units in which width is given" ) );
172  m_units->SetToolTip( _( "Units in which width is given" ) );
173  m_units->SetName( _T( "Units" ) );
174  itemBoxSizer3->Add( m_units, 1, wxALIGN_CENTER_VERTICAL | wxALL, 1 );
175 
176  m_rounded = new wxRadioButton( itemDialog1, ID_Rounded, _( "Rounded" ), wxDefaultPosition, wxDefaultSize, 0 );
177  m_rounded->SetValue( true );
178  m_rounded->SetHelpText( _( "end of lines will be rounded" ) );
180  m_rounded->SetToolTip( _( "end of lines will be rounded" ) );
181  m_rounded->SetName( _T( "rounded" ) );
182  itemBoxSizer2->Add( m_rounded, 0, wxALIGN_LEFT | wxALL, 2 );
183 
184  m_rectangular = new wxRadioButton( itemDialog1, ID_Rectangle, _( "Rectangular" ), wxDefaultPosition, wxDefaultSize, 0 );
185  m_rectangular->SetValue( false );
186  m_rectangular->SetHelpText( _( "end of lines will be rectangular" ) );
188  m_rectangular->SetToolTip( _( "end of lines will be rectangular" ) );
189  m_rectangular->SetName( _T( "rectangular" ) );
190  itemBoxSizer2->Add( m_rectangular, 0, wxALIGN_LEFT | wxALL, 2 );
191 
192  m_extRectangular = new wxRadioButton( itemDialog1, ID_RectangleExt, _( "Extended Rectangular" ), wxDefaultPosition, wxDefaultSize, 0 );
193  m_extRectangular->SetValue( false );
194  m_extRectangular->SetHelpText( _( "end of lines will be extended rectangular" ) );
196  m_extRectangular->SetToolTip( _( "end of lines will be extended rectangular" ) );
197  m_extRectangular->SetName( _T( "extended" ) );
198  itemBoxSizer2->Add( m_extRectangular, 0, wxALIGN_LEFT | wxALL, 2 );
199 
200  wxBoxSizer* itemBoxSizer10 = new wxBoxSizer( wxHORIZONTAL );
201  itemBoxSizer2->Add( itemBoxSizer10, 1, wxGROW | wxALL, 2 );
202 
203  m_hide = new wxButton( itemDialog1, ID_HIDE, _( "Hide" ), wxDefaultPosition, wxDefaultSize, 0 );
204  m_hide->SetHelpText( _( "hide and NOT execute commands" ) );
206  m_hide->SetToolTip( _( "hide and NOT execute commands" ) );
207  m_hide->SetName( _T( "hide" ) );
208  itemBoxSizer10->Add( m_hide, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1 );
209 
210  m_apply = new wxButton( itemDialog1, ID_APPLY, _( "Apply" ), wxDefaultPosition, wxDefaultSize, 0 );
211  m_apply->SetHelpText( _( "execute commands" ) );
213  m_apply->SetToolTip( _( "execute commands" ) );
214  m_apply->SetName( _T( "apply" ) );
215  itemBoxSizer10->Add( m_apply, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1 );
216 
217 }
218 
219 
220 /*!
221  * Should we show tooltips?
222  */
223 
225 {
226  return true;
227 }
228 
229 /*!
230  * wxEVT_COMMAND_TEXT_ENTER event handler for ID_WIDTH
231  */
232 
233 void a2dPathSettings::OnWidthEnter( wxCommandEvent& event )
234 {
235  double value;
236  m_width->GetValue().ToDouble( &value );
237  m_contourWidth = a2dDoMu( value, m_unitsStrings[m_units->GetSelection()] );
238 }
239 
240 
241 /*!
242  * wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_UNITS
243  */
244 void a2dPathSettings::OnUnitsSelected( wxCommandEvent& event )
245 {
246  event.Skip();
247 }
248 
249 /*!
250  * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for ID_Rounded
251  */
252 
253 void a2dPathSettings::OnRoundedSelected( wxCommandEvent& event )
254 {
255  m_pathtype = a2dPATH_END_ROUND;
256 }
257 
258 
259 /*!
260  * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for ID_Rectangle
261  */
262 
263 void a2dPathSettings::OnRectangleSelected( wxCommandEvent& event )
264 {
265  m_pathtype = a2dPATH_END_SQAURE;
266 }
267 
268 
269 /*!
270  * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for ID_RectangleExt
271  */
272 
273 void a2dPathSettings::OnRectangleExtSelected( wxCommandEvent& event )
274 {
275  m_pathtype = a2dPATH_END_SQAURE_EXT;
276 }
277 
278 
279 /*!
280  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_HIDE
281  */
282 
283 void a2dPathSettings::OnHideClick( wxCommandEvent& event )
284 {
285  Show( false );
286 }
287 
288 
289 /*!
290  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_APPLY
291  */
292 
293 void a2dPathSettings::OnApplyClick( wxCommandEvent& event )
294 {
295  double value;
296  m_width->GetValue().ToDouble( &value );
297  m_contourWidth = a2dDoMu( value, m_unitsStrings[m_units->GetSelection()] );
298 
299  m_habitat->SetContourWidth( m_contourWidth );
300  m_habitat->SetPathType( m_pathtype );
301 }
302 
303 void a2dPathSettings::OnComEvent( a2dComEvent& event )
304 {
305  bool baseContinue = true;
306  if ( event.GetId() == a2dRecursiveEditTool::sig_toolStartEditObject )
307  {
308  a2dObjectEditTool* editTool = wxDynamicCast( event.GetEventObject(), a2dObjectEditTool );
309  if ( editTool )
310  {
311  m_contourWidth = editTool->GetContourWidth();
312  m_width->SetValue( m_contourWidth.GetNumberString() ); // / a2dGetCmdh()->GetCanvasDocument()->GetUnitsScale() );
313  m_units->SetStringSelection( m_contourWidth.GetMultiplierString() );
314 
315  a2dPolylineL* poly = wxDynamicCast( editTool->GetOriginal(), a2dPolylineL );
316  if ( poly )
317  m_pathtype = poly->GetPathType();
318  a2dSLine* line = wxDynamicCast( editTool->GetOriginal(), a2dSLine );
319  if ( line )
320  m_pathtype = line->GetPathType();
321 
322  switch ( m_pathtype )
323  {
324  case a2dPATH_END_ROUND : m_rounded->SetValue( true ); break;
325  case a2dPATH_END_SQAURE : m_rectangular->SetValue( true ); break;
326  case a2dPATH_END_SQAURE_EXT : m_extRectangular->SetValue( true ); break;
327  }
328  }
329  }
330 }
void SetContourWidth(const a2dDoMu &currentContourWidth)
set the Contour width of shapes
Definition: canglob.cpp:1064
#define wxDynamicCast(obj, className)
Define wxDynamicCast so that it will give a compiler error for unrelated types.
Definition: gen.h:75
const a2dDoMu & GetContourWidth() const
get the Contour width of shapes in meters
Definition: canglob.h:872
a2dPATH_END_TYPE GetPathType()
get when m_contourwidth != 0 what is the end of the line looks like.
Definition: canglob.h:878
bool Create(wxWindow *parent, wxWindowID id=SYMBOL_a2dPathSettings_IDNAME, const wxString &caption=SYMBOL_a2dPathSettings_TITLE, const wxPoint &pos=SYMBOL_a2dPathSettings_POSITION, const wxSize &size=SYMBOL_a2dPathSettings_SIZE, long style=SYMBOL_a2dPathSettings_STYLE)
Creation.
store and convert number to number with unit and visa versa. e.g. 1.23e-6 => 1.23 * 1e-6 ...
Definition: artglob.h:208
a2dPATH_END_TYPE GetPathType()
get when m_contourwidth != 0 what is the end of the line looks like.
Definition: polygon.h:404
a2dPathSettings()
Constructors.
polyline defined with list of points.
Definition: polygon.h:332
a2dCanvasObject * GetOriginal()
object to draw or edit
Definition: sttool.h:220
#define EVT_COM_EVENT(func)
static wxEvtHandler for communication event
Definition: gen.h:564
void Init()
Initialises member variables.
static const a2dSignal sig_toolStartEditObject
when starting editing an object, this event is sent to tool
Definition: edit.h:83
a2dSLine
Definition: canprim.h:987
This tool is for editing a single object.
Definition: edit.h:73
defines common settinsg for a habitat for a set of a2dCameleons.
Definition: canglob.h:439
void SetPathType(a2dPATH_END_TYPE pathtype)
Set when m_contourwidth != 0 what is the end of the line should be.
Definition: canglob.cpp:1057
~a2dPathSettings()
Destructor.
void CreateControls()
Creates the controls and sizers.
editing tool for a2dCanvasObject's
wxString GetMultiplierString() const
get the number 1.1 um -> "um"
Definition: artglob.cpp:353
double GetContourWidth() const
get the Contour width of the shape
Definition: tools.h:723
see a2dComEvent
Definition: gen.h:371
all headers of the canvas module
wxString GetNumberString() const
get the number 1.1 um -> "1.1"
Definition: artglob.cpp:358
static bool ShowToolTips()
Should we show tooltips?
a2dPATH_END_TYPE GetPathType()
get when m_contourwidth != 0 what is the end of the line looks like.
Definition: canprim.h:1114
pathsettings.cpp Source File -- Sun Oct 12 2014 17:04:23 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation