wxArt2D
groupdlg.cpp
1 /*! \file editor/src/groupdlg.cpp
2  \brief Document/view classes
3  \author Klaas Holwerda
4  \date Created 05/07/2003
5 
6  Copyright: 2001-2004 (C) Klaas Holwerda
7 
8  Licence: wxWidgets licence
9 
10  RCS-ID: $Id: groupdlg.cpp,v 1.7 2008/10/21 21:48:30 titato Exp $
11 */
12 
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/platform.h>
24 #include <wx/clipbrd.h>
25 #include <algorithm>
26 
27 #include "wx/canvas/groupdlg.h"
28 #include "wx/canvas/canglob.h"
29 
30 #define GROUPDLG_HSIZE 400
31 #define GROUPDLG_VSIZE 400
32 
33 const int GROUP_BUTTON_OK = wxNewId();
34 const int GROUP_BUTTON_CANCEL = wxNewId();
35 const int GROUP_BUTTON_ADD_A = wxNewId();
36 const int GROUP_BUTTON_REMOVE_A = wxNewId();
37 const int GROUP_BUTTON_CLR_A = wxNewId();
38 const int GROUP_BUTTON_ADD_B = wxNewId();
39 const int GROUP_BUTTON_REMOVE_B = wxNewId();
40 const int GROUP_BUTTON_CLR_B = wxNewId();
41 const int GROUP_BUTTON_ADD_D = wxNewId();
42 const int GROUP_BUTTON_REMOVE_D = wxNewId();
43 
44 const int ID_LISTBOX = wxNewId();
45 const int ID_CHECKBOX1 = wxNewId();
46 const int ID_CHECKBOX2 = wxNewId();
47 const int ID_CHECKBOX3 = wxNewId();
48 const int ID_TEXTCTRL = wxNewId();
49 
50 BEGIN_EVENT_TABLE( a2dGroupDlg, wxDialog )
51  EVT_BUTTON ( GROUP_BUTTON_OK, a2dGroupDlg::CmOk )
52  EVT_BUTTON ( GROUP_BUTTON_CANCEL, a2dGroupDlg::CmCancel )
53  EVT_BUTTON ( GROUP_BUTTON_ADD_A, a2dGroupDlg::CmAdd_A )
54  EVT_BUTTON ( GROUP_BUTTON_REMOVE_A, a2dGroupDlg::CmRemove_A )
55  EVT_BUTTON ( GROUP_BUTTON_CLR_A, a2dGroupDlg::CmClear_A )
56  EVT_BUTTON ( GROUP_BUTTON_ADD_B, a2dGroupDlg::CmAdd_B )
57  EVT_BUTTON ( GROUP_BUTTON_REMOVE_B, a2dGroupDlg::CmRemove_B )
58  EVT_BUTTON ( GROUP_BUTTON_CLR_B, a2dGroupDlg::CmClear_B )
59  EVT_BUTTON ( GROUP_BUTTON_ADD_D, a2dGroupDlg::CmAdd_D )
60  EVT_BUTTON ( GROUP_BUTTON_REMOVE_D, a2dGroupDlg::CmRemove_D )
61  EVT_CLOSE( a2dGroupDlg::OnCloseWindow )
62 END_EVENT_TABLE()
63 
64 a2dGroupDlg::a2dGroupDlg( a2dHabitat* habitat, wxFrame* parent, const wxString& title, long style, const wxString& name ):
65  wxDialog( parent, -1, title, wxDefaultPosition, wxSize( GROUPDLG_HSIZE, GROUPDLG_VSIZE ), style, name )
66 {
67  m_habitat = m_habitat;
68 /*
69  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_CHANGED_DOCUMENT, this );
70  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_ACTIVATE_VIEW, this );
71  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_DO, this );
72  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_UNDO, this );
73  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_REDO, this );
74  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( a2dEVT_COM_EVENT, this );
75 */
76  wxSizer* item0 = new wxBoxSizer( wxVERTICAL );
77 
78  wxSizer* item1 = new wxBoxSizer( wxHORIZONTAL );
79 
80  wxStaticBox* item3 = new wxStaticBox( this, -1, _( "layers" ) );
81  wxSizer* item2 = new wxStaticBoxSizer( item3, wxVERTICAL );
82 
83  m_listbox_main = new wxListCtrl( this, ID_LISTBOX, wxDefaultPosition, wxSize( 40, -1 ), wxLC_REPORT | wxLC_NO_HEADER );
84  item2->Add( m_listbox_main, 1, wxEXPAND | wxALL );
85  m_listbox_main->InsertColumn( 0, _T( "Layers" ) );
86 
87  item1->Add( item2, 1, wxGROW | wxALL, 0 );
88 
89  wxSizer* item5 = new wxBoxSizer( wxVERTICAL );
90 
91  wxStaticBox* item7 = new wxStaticBox( this, -1, _( "group A" ) );
92  wxSizer* item6 = new wxStaticBoxSizer( item7, wxHORIZONTAL );
93 
94  wxSizer* item8 = new wxBoxSizer( wxVERTICAL );
95 
96  wxButton* item9 = new wxButton( this, GROUP_BUTTON_ADD_A, _( "add >>" ), wxDefaultPosition, wxDefaultSize, 0 );
97  item8->Add( item9, 0, wxALIGN_CENTRE | wxALL, 2 );
98 
99  wxButton* item10 = new wxButton( this, GROUP_BUTTON_REMOVE_A, _( "<< remove" ), wxDefaultPosition, wxDefaultSize, 0 );
100  item8->Add( item10, 0, wxALIGN_CENTRE | wxALL, 2 );
101 
102  wxButton* item11 = new wxButton( this, GROUP_BUTTON_CLR_A, _( "clear" ), wxDefaultPosition, wxDefaultSize, 0 );
103  item8->Add( item11, 0, wxALIGN_CENTRE | wxALL, 2 );
104 
105  m_onlyselect_A = new wxCheckBox( this, ID_CHECKBOX1, _( "selected" ), wxDefaultPosition, wxDefaultSize, 0 );
106  item8->Add( m_onlyselect_A, 0, wxALIGN_CENTRE | wxALL, 2 );
107 
108  item6->Add( item8, 0, wxALIGN_CENTRE | wxALL, 0 );
109 
110  m_listbox_a = new wxListCtrl( this, ID_LISTBOX, wxDefaultPosition, wxSize( 40, 100 ), wxLC_REPORT | wxLC_NO_HEADER );
111  item6->Add( m_listbox_a, 1, wxEXPAND | wxALL );
112  m_listbox_a->InsertColumn( 0, _T( "Group A" ) );
113 
114  item5->Add( item6, 1, wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 0 );
115 
116  wxStaticBox* item15 = new wxStaticBox( this, -1, _( "group B" ) );
117  wxSizer* item14 = new wxStaticBoxSizer( item15, wxHORIZONTAL );
118 
119  wxSizer* item16 = new wxBoxSizer( wxVERTICAL );
120 
121  wxButton* item17 = new wxButton( this, GROUP_BUTTON_ADD_B, _( "add >>" ), wxDefaultPosition, wxDefaultSize, 0 );
122  item16->Add( item17, 0, wxALIGN_CENTRE | wxALL, 2 );
123 
124  wxButton* item18 = new wxButton( this, GROUP_BUTTON_REMOVE_B, _( "<< remove" ), wxDefaultPosition, wxDefaultSize, 0 );
125  item16->Add( item18, 0, wxALIGN_CENTRE | wxALL, 2 );
126 
127  wxButton* item19 = new wxButton( this, GROUP_BUTTON_CLR_B, _( "clear" ), wxDefaultPosition, wxDefaultSize, 0 );
128  item16->Add( item19, 0, wxALIGN_CENTRE | wxALL, 2 );
129 
130  m_onlyselect_B = new wxCheckBox( this, ID_CHECKBOX1, _( "selected" ), wxDefaultPosition, wxDefaultSize, 0 );
131  item16->Add( m_onlyselect_B, 0, wxALIGN_CENTRE | wxALL, 2 );
132 
133  item14->Add( item16, 0, wxALIGN_CENTRE | wxALL, 0 );
134 
135  m_listbox_b = new wxListCtrl( this, ID_LISTBOX, wxDefaultPosition, wxSize( 40, 100 ), wxLC_REPORT | wxLC_NO_HEADER );
136  item14->Add( m_listbox_b, 1, wxGROW | wxALIGN_CENTER_HORIZONTAL | wxALL );
137  m_listbox_b->InsertColumn( 0, _T( "Group B" ) );
138 
139  item5->Add( item14, 1, wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 0 );
140 
141  wxStaticBox* item23 = new wxStaticBox( this, -1, _( "Destination" ) );
142  wxSizer* item22 = new wxStaticBoxSizer( item23, wxHORIZONTAL );
143 
144  wxSizer* item24 = new wxBoxSizer( wxVERTICAL );
145 
146  wxButton* item25 = new wxButton( this, GROUP_BUTTON_ADD_D, _( "Set Target >>" ), wxDefaultPosition, wxDefaultSize, 0 );
147  item24->Add( item25, 0, wxALIGN_CENTRE | wxALL, 2 );
148 
149  m_clearTarget = new wxCheckBox( this, ID_CHECKBOX3, _( "Clear" ), wxDefaultPosition, wxDefaultSize, 0 );
150  item24->Add( m_clearTarget, 0, wxALIGN_CENTRE | wxALL, 2 );
151 
152  item22->Add( item24, 0, wxALIGN_CENTRE | wxALL, 0 );
153 
154  m_destination = new wxTextCtrl( this, ID_TEXTCTRL, wxEmptyString, wxDefaultPosition, wxSize( 40, -1 ), 0 );
155  item22->Add( m_destination, 1, wxALIGN_CENTRE | wxALL, 0 );
156 
157  item5->Add( item22, 0, wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 0 );
158 
159  item1->Add( item5, 1, wxGROW | wxALIGN_CENTER_HORIZONTAL | wxALL, 0 );
160 
161  item0->Add( item1, 1, wxGROW | wxALIGN_CENTER_VERTICAL, 0 );
162 
163  wxSizer* item28 = new wxBoxSizer( wxHORIZONTAL );
164 
165  wxButton* item29 = new wxButton( this, GROUP_BUTTON_OK, _( "OK" ), wxDefaultPosition, wxDefaultSize, 0 );
166  item28->Add( item29, 0, wxALIGN_CENTRE, 0 );
167 
168  wxButton* item30 = new wxButton( this, GROUP_BUTTON_CANCEL, _( "Cancel" ), wxDefaultPosition, wxDefaultSize, 0 );
169  item28->Add( item30, 0, wxALIGN_CENTRE, 0 );
170 
171  item0->Add( item28, 0, wxALIGN_CENTRE, 0 );
172 
173  Init();
174 
175  m_listbox_main->SetColumnWidth( 0, wxLIST_AUTOSIZE );
176  m_listbox_a->SetColumnWidth( 0, wxLIST_AUTOSIZE );
177  m_listbox_b->SetColumnWidth( 0, wxLIST_AUTOSIZE );
178  m_listbox_main->SetColumnWidth( 0, 200 );
179  m_listbox_a->SetColumnWidth( 0, 200 );
180  m_listbox_b->SetColumnWidth( 0, 200 );
181 
182  SetAutoLayout( true );
183  SetSizer( item0 );
184  item0->SetSizeHints( this );
185  item0->Fit( this );
186 }
187 
188 a2dGroupDlg::~a2dGroupDlg()
189 {
190 /*
191  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( wxEVT_CHANGED_DOCUMENT, this );
192  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( wxEVT_ACTIVATE_VIEW, this );
193  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( wxEVT_DO, this );
194  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( wxEVT_UNDO, this );
195  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( wxEVT_REDO, this );
196  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( a2dEVT_COM_EVENT, this );
197 */
198 }
199 
200 void a2dGroupDlg::Init()
201 {
203  if ( !drawingPart )
204  return;
205 
206  m_layersetup = drawingPart->GetDrawing()->GetLayerSetup();
207 
208  a2dLayerGroup& groupa = m_habitat->GetGroupA();
209  a2dLayerGroup& groupb = m_habitat->GetGroupB();
210  int target = m_habitat->GetTarget();
211 
212  // fill the listboxes
213  wxString layerLine;
214  wxString available;
215 
216  for ( int i = 0; i < wxMAXLAYER; i++ )
217  {
218  a2dLayerInfo* lobj = m_layersetup->GetLayerIndex()[i];
219 
220  layerLine.Printf( _T( "%04d %s" ), i, lobj->GetName().c_str() );
221  m_listbox_main->InsertItem( i, layerLine );
222  if ( lobj->GetAvailable() )
223  m_listbox_main->SetItemTextColour( i, *wxRED );
224 
225  wxListItem itemCol;
226  itemCol.SetText( layerLine );
227  itemCol.SetImage( -1 );
228  itemCol.SetData( i ); //store index of layer
229 
230  // are there selected?
231  a2dLayerGroup::iterator iter = wxSTD find( groupa.begin(), groupa.end(), i );
232  if ( iter != groupa.end() )
233  m_listbox_a->InsertItem( itemCol );
234  iter = wxSTD find( groupb.begin(), groupb.end(), i );
235  if ( iter != groupb.end() )
236  m_listbox_b->InsertItem( itemCol );
237 
238  if ( target == i )
239  {
240  m_destination->SetValue( layerLine );
241  m_target = i;
242  }
243  }
244  m_onlyselect_A->SetValue( m_habitat->GetSelectedOnlyA() );
245  m_onlyselect_B->SetValue( m_habitat->GetSelectedOnlyB() );
246  m_clearTarget->SetValue( m_habitat->GetClearTarget() );
247 }
248 
249 void a2dGroupDlg::OnCloseWindow( wxCloseEvent& WXUNUSED( event ) )
250 {
251  EndModal( 0 );
252 }
253 
254 
255 void a2dGroupDlg::CmAdd_A( wxCommandEvent& )
256 {
257  wxString buf;
258  int selcount;
259 
260  selcount = m_listbox_main->GetSelectedItemCount();
261 
262  if ( selcount == 0 ) return;
263 
264  long item = -1;
265  for ( ;; )
266  {
267  item = m_listbox_main->GetNextItem( item,
268  wxLIST_NEXT_ALL,
269  wxLIST_STATE_SELECTED );
270  if ( item == -1 )
271  break;
272 
273  buf = m_listbox_main->GetItemText( item );
274  if ( m_listbox_a->FindItem( -1, buf ) == -1 )
275  {
276  wxListItem itemCol;
277  itemCol.SetText( buf );
278  itemCol.SetImage( -1 );
279  itemCol.SetData( item ); //store index of layer
280  m_listbox_a->InsertItem( itemCol );
281  }
282  }
283  m_listbox_a->SetColumnWidth( 0, wxLIST_AUTOSIZE );
284  m_listbox_a->SetColumnWidth( 0, 200 );
285 }
286 
287 // the user presses add to b
288 void a2dGroupDlg::CmAdd_B( wxCommandEvent& )
289 {
290  wxString buf;
291  int selcount;
292 
293  selcount = m_listbox_main->GetSelectedItemCount();
294 
295  if ( selcount == 0 ) return;
296 
297  long item = -1;
298  for ( ;; )
299  {
300  item = m_listbox_main->GetNextItem( item,
301  wxLIST_NEXT_ALL,
302  wxLIST_STATE_SELECTED );
303  if ( item == -1 )
304  break;
305 
306  buf = m_listbox_main->GetItemText( item );
307  if ( m_listbox_b->FindItem( -1, buf ) == -1 )
308  {
309  wxListItem itemCol;
310  itemCol.SetText( buf );
311  itemCol.SetImage( -1 );
312  itemCol.SetData( item ); //store index of layer
313  m_listbox_b->InsertItem( itemCol );
314  }
315  }
316  m_listbox_b->SetColumnWidth( 0, wxLIST_AUTOSIZE );
317  m_listbox_b->SetColumnWidth( 0, 200 );
318 }
319 
320 // the user selected add to destination
321 void a2dGroupDlg::CmAdd_D( wxCommandEvent& )
322 {
323  wxString buf;
324 
325  long item = m_listbox_main->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
326  if ( item == -1 )
327  return;
328 
329  buf = m_listbox_main->GetItemText( item );
330 
332  if ( !drawingPart )
333  return;
334 
335  m_layersetup = drawingPart->GetDrawing()->GetLayerSetup();
336 
337  m_destination->SetValue( buf );
338  m_target = item;
339  m_listbox_main->SetItemState( item, 0, wxLIST_STATE_SELECTED );
340 }
341 
342 void a2dGroupDlg::CmRemove_A( wxCommandEvent& )
343 {
344  long item = -1;
345  for ( ;; )
346  {
347  item = m_listbox_a->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
348  if ( item == -1 )
349  break;
350 
351  m_listbox_a->DeleteItem( item );
352  }
353 }
354 
355 void a2dGroupDlg::CmRemove_B( wxCommandEvent& )
356 {
357  long item = -1;
358  for ( ;; )
359  {
360  item = m_listbox_b->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
361  if ( item == -1 )
362  break;
363 
364  m_listbox_b->DeleteItem( item );
365  }
366 }
367 
368 void a2dGroupDlg::CmRemove_D( wxCommandEvent& )
369 {
370  m_destination->SetValue( wxEmptyString );
371 }
372 
373 void a2dGroupDlg::CmClear_A( wxCommandEvent& )
374 {
375  m_listbox_a->DeleteAllItems();
376 }
377 
378 void a2dGroupDlg::CmClear_B( wxCommandEvent& )
379 {
380  m_listbox_b->DeleteAllItems();
381 }
382 
383 // the user pressed OK. This function is called then
384 void a2dGroupDlg::CmOk( wxCommandEvent& )
385 {
387  if ( !drawingPart )
388  return;
389 
390  m_layersetup = drawingPart->GetDrawing()->GetLayerSetup();
391 
392  a2dLayerGroup groupa;
393  long item = -1;
394  for ( ;; )
395  {
396  item = m_listbox_a->GetNextItem( item );
397  if ( item == -1 )
398  break;
399  groupa.push_back( m_listbox_a->GetItemData( item ) );
400  }
401 
402  a2dLayerGroup groupb;
403  item = -1;
404  for ( ;; )
405  {
406  item = m_listbox_b->GetNextItem( item );
407  if ( item == -1 )
408  break;
409  groupb.push_back( m_listbox_b->GetItemData( item ) );
410  }
411 
412  m_habitat->SetGroupA( groupa );
413  m_habitat->SetGroupB( groupb );
414  m_habitat->SetSelectedOnlyA( m_onlyselect_A->GetValue() );
415  m_habitat->SetSelectedOnlyB( m_onlyselect_B->GetValue() );
416  m_habitat->SetClearTarget( m_clearTarget->GetValue() );
417  m_habitat->SetTarget( m_target );
418 
419  EndModal( 0 );
420 }
421 
422 void a2dGroupDlg::CmCancel( wxCommandEvent& )
423 {
424  EndModal( 1 );
425 }
Display Part of a a2dDrawing, in which a2dCanvasObjects are shown.
Definition: drawer.h:470
a2dLayerGroup & GetGroupA()
return group A layers
Definition: canglob.h:658
bool GetAvailable()
are there objects on this layer
Definition: layerinf.h:108
bool GetSelectedOnlyB() const
get selectedOnlyB in group operations
Definition: canglob.h:685
void SetSelectedOnlyB(bool selectedOnlyB)
set selectedOnlyB in group operations
Definition: canglob.h:682
std::vector< a2dLayerInfoPtr > & GetLayerIndex()
return array index on Layer
Definition: layerinf.cpp:555
wxUint16 GetTarget()
get target layer in operation
Definition: canglob.h:673
a2dLayers * GetLayerSetup()
Get the layersettings for the canvas.
Definition: drawing.h:506
a2dDrawingPart * GetActiveDrawingPart()
return the currently/last active drawing part.
Definition: canglob.h:1262
bool GetClearTarget() const
get clear of target in group operations
Definition: canglob.h:766
virtual wxString GetName() const
Get name for layer.
Definition: layerinf.cpp:248
void SetClearTarget(bool clearTarget)
set clear of target in group operations
Definition: canglob.h:763
void SetGroupA(const a2dLayerGroup &groupA)
sets operand A in layer operation
Definition: canglob.h:652
Definition of class for dialog to set groups for boolean operations.
void SetTarget(wxUint16 target)
set target layer in operation
Definition: canglob.cpp:1088
contains the layer properties for one layer,
Definition: layerinf.h:41
defines common settinsg for a habitat for a set of a2dCameleons.
Definition: canglob.h:439
holds a list of layers numbers
Definition: canglob.h:60
void SetGroupB(const a2dLayerGroup &groupB)
sets operand B in layer operation
Definition: canglob.h:655
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
a2dLayerGroup & GetGroupB()
return group B layers
Definition: canglob.h:661
void SetSelectedOnlyA(bool selectedOnlyA)
set selectedOnlyA in group operations
Definition: canglob.h:676
bool GetSelectedOnlyA() const
get selectedOnlyA in group operations
Definition: canglob.h:679
general canvas module declarations and classes
groupdlg.cpp Source File -- Sun Oct 12 2014 17:04:21 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation