wxArt2D
identifydlg.cpp
1 /*! \file editor/src/identifydlg.cpp
2  \author Klaas Holwerda
3 
4  Copyright: 2000-2004 (c) Klaas Holwerda
5 
6  Licence: wxWidgets Licence
7 
8  RCS-ID: $Id: identifydlg.cpp,v 1.7 2009/09/03 20:09:53 titato Exp $
9 */
10 
11 #include "a2dprec.h"
12 
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16 
17 #include "wx/canvas/canmod.h"
18 #include "wx/canvas/layerinf.h"
19 
20 #include "wx/canvas/identifydlg.h"
21 
22 
23 IMPLEMENT_DYNAMIC_CLASS( IdentifyDialog, wxDialog )
24 
25 BEGIN_EVENT_TABLE( IdentifyDialog, wxDialog )
26  EVT_BUTTON ( ID_IDENT_HIDE, IdentifyDialog::hide )
27  EVT_BUTTON ( ID_IDENT_UPDATE, IdentifyDialog::Update )
28  EVT_ACTIVATE ( IdentifyDialog::OnActivate )
29  //EVT_ACTIVATE_VIEW( IdentifyDialog::OnActivateView )
30  EVT_CLOSE ( IdentifyDialog::OnCloseWindow )
31  EVT_SIZE ( IdentifyDialog::OnSize )
32  EVT_DO ( IdentifyDialog::OnDoEvent )
33  EVT_COM_EVENT ( IdentifyDialog::OnComEvent )
34  //EVT_CHANGED_DOCUMENT( IdentifyDialog::OnChangedDocument )
35 END_EVENT_TABLE()
36 
37 /*!
38  * IdentifyDialog constructors
39  */
40 IdentifyDialog::IdentifyDialog( )
41 {
42  a2dCanvasGlobals->ConnectEvent( a2dEVT_COM_EVENT, this );
43 
44 /*
45  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_CHANGED_DOCUMENT, this );
46  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_ACTIVATE_VIEW, this );
47  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_DO, this );
48  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_UNDO, this );
49  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_REDO, this );
50  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( a2dEVT_COM_EVENT, this );
51 */
52  m_showObject = NULL;
53 }
54 
55 IdentifyDialog::IdentifyDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
56 {
57  a2dCanvasGlobals->ConnectEvent( a2dEVT_COM_EVENT, this );
58  Create( parent, id, caption, pos, size, style );
59 /*
60  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_CHANGED_DOCUMENT, this );
61  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_ACTIVATE_VIEW, this );
62  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_DO, this );
63  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_UNDO, this );
64  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_REDO, this );
65  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( a2dEVT_COM_EVENT, this );
66 */
67 }
68 
69 IdentifyDialog::~IdentifyDialog( )
70 {
71  a2dCanvasGlobals->DisconnectEvent( a2dEVT_COM_EVENT, this );
72 
73 /*
74  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( wxEVT_CHANGED_DOCUMENT, this );
75  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( wxEVT_ACTIVATE_VIEW, this );
76  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( wxEVT_DO, this );
77  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( wxEVT_UNDO, this );
78  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( wxEVT_REDO, this );
79  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( a2dEVT_COM_EVENT, this );
80 */
81 }
82 
83 
84 /*!
85  * IdentifyDialog creator
86  */
87 bool IdentifyDialog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
88 {
89  m_showObject = NULL;
90  m_objectsList = NULL;
91  m_update = NULL;
92 
93  SetExtraStyle( GetExtraStyle() | wxWS_EX_BLOCK_EVENTS );
94  wxDialog::Create( parent, id, caption, pos, size, style );
95 
97  //GetSizer()->SetSizeHints(this);
98  //GetSizer()->Fit(this);
99  Centre();
100  return TRUE;
101 }
102 
103 /*!
104  * Control creation for IdentifyDialog
105  */
107 {
108  IdentifyDialog* itemDialog1 = this;
109 
110  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer( wxVERTICAL );
111  itemDialog1->SetSizer( itemBoxSizer2 );
112 
113  wxString* m_objectsListStrings = NULL;
114  m_objectsList = new wxListBox( itemDialog1, ID_IDENT_LISTBOX, wxDefaultPosition, wxDefaultSize, 0, m_objectsListStrings, wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_SORT );
115  m_objectsList->SetHelpText( _( "Object selected for identify" ) );
116  if ( ShowToolTips() )
117  m_objectsList->SetToolTip( _( "Object selected for identify" ) );
118  itemBoxSizer2->Add( m_objectsList, 1, wxGROW | wxALL, 0 );
119 
120  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer( wxHORIZONTAL );
121  itemBoxSizer2->Add( itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5 );
122 
123  wxButton* itemButton5 = new wxButton( itemDialog1, ID_IDENT_HIDE, _( "Hide" ), wxDefaultPosition, wxDefaultSize, 0 );
124  itemButton5->SetHelpText( _( "Hide dialog" ) );
125  if ( ShowToolTips() )
126  itemButton5->SetToolTip( _( "Hide dialog" ) );
127  itemBoxSizer4->Add( itemButton5, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0 );
128 
129  m_update = new wxButton( itemDialog1, ID_IDENT_UPDATE, _( "Update" ), wxDefaultPosition, wxDefaultSize, 0 );
130  m_update->SetHelpText( _( "Update dialog for selected objects in view" ) );
131  if ( ShowToolTips() )
132  m_update->SetToolTip( _( "Update dialog for selected objects in view" ) );
133  itemBoxSizer4->Add( m_update, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0 );
134 }
135 
136 /*!
137  * Should we show tooltips?
138  */
140 {
141  return TRUE;
142 }
143 
144 void IdentifyDialog::hide( wxCommandEvent& )
145 {
146  m_objectsList->Clear();
147  Show( FALSE );
148 }
149 
150 void IdentifyDialog::OnCloseWindow( wxCloseEvent& event )
151 {
152  m_objectsList->Clear();
153  Show( FALSE );
154 }
155 
156 void IdentifyDialog::Update( wxCommandEvent& )
157 {
158  Init( m_showObject );
159 }
160 
162 {
163  if ( !m_objectsList )
164  return;
165  m_objectsList->Clear();
166  if ( !showObject )
167  return;
168 
169  m_showObject = showObject;
170 
172  for( a2dCanvasObjectList::iterator iter = childList->begin(); iter != childList->end(); ++iter )
173  {
174  a2dCanvasObject* obj = ( *iter );
175  if ( obj->GetSelected() )
176  {
177  wxString layerName;
178  a2dDrawing* root = obj->GetRoot();
179  a2dLayerInfo* layerobj = wxNullLayerInfo;
180  if ( root->GetLayerSetup() )
181  layerobj = root->GetLayerSetup()->GetLayerIndex()[obj->GetLayer()];
182  if ( layerobj != wxNullLayerInfo )
183  layerName = layerobj->GetName();
184 
185  wxString listline;
186  listline = wxString::Format( wxT( "layerId=%d layer=%s " ), obj->GetLayer(), layerName.c_str() );
187  listline += wxString::Format( wxT( "x=%lg, y=%lg " ), obj->GetPosX(), obj->GetPosY() );
188  listline << wxT( "name=" ) << obj->GetName() << wxT( " class=" ) << obj->GetClassInfo()->GetClassName();
189  m_objectsList->Append( listline );
190  }
191  }
192 }
193 
194 void IdentifyDialog::OnActivate( wxActivateEvent& windowevent )
195 {
196  windowevent.Skip(); //skip to base OnActivate Handler which sets proper focus to child window(s)
197 }
198 
199 /*
200 void IdentifyDialog::OnActivateView( a2dViewEvent& viewevent )
201 {
202  a2dView* view = wxStaticCast( viewevent.GetEventObject(), a2dView );
203  a2dCanvasView* canview = wxDynamicCast( view, a2dCanvasView );
204  viewevent.Skip();
205 
206  if ( ! canview )
207  return;
208 
209  if ( m_showObject != canview->GetDrawingPart()->GetShowObject() )
210  Init( canview->GetDrawingPart()->GetShowObject() );
211 }
212 
213 
214 void IdentifyDialog::OnChangedDocument( a2dCommandEvent& event )
215 {
216  Init( NULL );
217 }
218 */
219 
220 // Size the subwindows when the frame is resized
221 void IdentifyDialog::OnSize( wxSizeEvent& WXUNUSED( event ) )
222 {
223  Layout();
224 }
225 
226 void IdentifyDialog::OnDoEvent( a2dCommandProcessorEvent& event )
227 {
228  wxString cmdName = event.GetCommand()->GetName();
229 
230  if ( event.GetCommand()->GetCommandId() == &a2dCommand_SetShowObject::Id )
231  {
233  if ( !drawingPart )
234  return;
235 
236  m_showObject = drawingPart->GetShowObject();
237  Init( m_showObject );
238  }
239 }
240 
241 void IdentifyDialog::OnComEvent( a2dComEvent& event )
242 {
243  if ( event.GetId() == a2dDrawingPart::sig_changedShowObject )
244  {
245  // an existing corridor on a view will become invalid when the ShowObject changes.
246  // Most tools can handle a change in corridor, for those there is no need to remove them after a change
247  // in ShowObject.
248  a2dCanvasObject* newtop = wxStaticCast( event.GetProperty()->GetRefObject(), a2dCanvasObject );
249  if ( newtop )
250  {
251  m_showObject = newtop;
252  Init( m_showObject );
253  }
254  }
255  else if ( event.GetId() == a2dCanvasGlobal::sig_changedActiveDrawing )
256  {
258  if ( part && part->GetShowObject() && part->GetShowObject()->GetRoot() )
259  {
260  m_showObject = part->GetShowObject();
261  Init( m_showObject );
262  }
263  }
264  else
265  event.Skip();
266 }
267 
Display Part of a a2dDrawing, in which a2dCanvasObjects are shown.
Definition: drawer.h:470
virtual wxString GetName() const
Returns the name of this object, if no name is given the internal id will be returned.
Definition: gen.cpp:1310
IdentifyDialog()
Constructors.
Definition: identifydlg.cpp:40
a2dCommand * GetCommand()
the command ( if there was one ) that did it.
Definition: comevt.h:759
bool Create(wxWindow *parent, wxWindowID id=SYMBOL_IDENTIFYDIALOG_IDNAME, const wxString &caption=SYMBOL_IDENTIFYDIALOG_TITLE, const wxPoint &pos=SYMBOL_IDENTIFYDIALOG_POSITION, const wxSize &size=SYMBOL_IDENTIFYDIALOG_SIZE, long style=SYMBOL_IDENTIFYDIALOG_STYLE)
Creation.
Definition: identifydlg.cpp:87
void Init(a2dCanvasObject *showObject)
selected child objects with this as parent will be shown
a2dDrawing * GetRoot() const
get a2dCanvasDocument of the object.
Definition: canobj.h:952
#define EVT_DO(func)
event sent from a2DocumentCommandProcessor when a command is initially done
Definition: comevt.h:795
static bool ShowToolTips()
Should we show tooltips?
void ConnectEvent(wxEventType type, wxEvtHandler *eventSink)
Definition: gen.cpp:876
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
std::vector< a2dLayerInfoPtr > & GetLayerIndex()
return array index on Layer
Definition: layerinf.cpp:555
virtual a2dObject * GetRefObject() const
when a2dProperty, return its value else assert
Definition: gen.cpp:1976
a2dLayers * GetLayerSetup()
Get the layersettings for the canvas.
Definition: drawing.h:506
a2dCanvasObjectList * GetChildObjectList()
get the list where the child objects are stored in.
Definition: canobj.cpp:2551
bool GetSelected() const
is the object selected flag set
Definition: canobj.h:1603
a2dDrawingPart * GetActiveDrawingPart()
return the currently/last active drawing part.
Definition: canglob.h:1262
Identification Dialog.
virtual wxString GetName() const
Get name for layer.
Definition: layerinf.cpp:248
static const a2dSignal sig_changedShowObject
Definition: drawer.h:1513
static const a2dSignal sig_changedActiveDrawing
when active drawing is set, this signal is send to the drawing.
Definition: canglob.h:1292
double GetPosX() const
get x position from affine matrix
Definition: canobj.h:527
#define EVT_COM_EVENT(func)
static wxEvtHandler for communication event
Definition: gen.h:564
layer settings for a a2dCanvasDocument Holds layers settings classes
const a2dCommandId * GetCommandId()
a specific id for this command.
Definition: comevt.h:179
#define wxStaticCast(obj, className)
The wxWindows 2.4.2 wxStaticCast is buggy. It evaluates its argument twice.
Definition: gen.h:123
void CreateControls()
Creates the controls and sizers.
a2dCanvasObject * GetShowObject() const
return pointer of then currently shown object on the drawer.
Definition: drawer.h:680
wxUint16 GetLayer() const
Returns the layer index where this object is drawn upon.
Definition: canobj.h:2368
contains the layer properties for one layer,
Definition: layerinf.h:41
a2dCanvasObject * m_showObject
selected child objects with this as parent will be shown
Definition: identifydlg.h:95
double GetPosY() const
get y position from affine matrix
Definition: canobj.h:530
Event sent to a2dCommandProcessor.
Definition: comevt.h:701
see a2dComEvent
Definition: gen.h:371
a2dCanvasGlobal * a2dCanvasGlobals
global a2dCanvasGlobal to have easy access to global settings
Definition: canglob.cpp:1234
all headers of the canvas module
bool DisconnectEvent(wxEventType type, wxEvtHandler *eventSink)
Definition: gen.cpp:902
Contain one drawing as hierarchical tree of a2dCanvasObject&#39;s.
Definition: drawing.h:434
identifydlg.cpp Source File -- Sun Oct 12 2014 17:04:21 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation