wxArt2D
camcreate.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: camcreate.cpp
3 // Purpose:
4 // Author: K
5 // Modified by:
6 // Created: 27/10/2013 15:43:45
7 // RCS-ID:
8 // Copyright: H
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11 
12 #include "a2dprec.h"
13 
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17 
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21 
22 #include "wx/canvas/cameleon.h"
23 #include "wx/canvas/camcreate.h"
24 
25 ////@begin XPM images
26 ////@end XPM images
27 
28 
29 /*!
30  * a2dCamCreate type definition
31  */
32 
33 IMPLEMENT_DYNAMIC_CLASS( a2dCamCreate, wxDialog )
34 
35 
36 /*!
37  * a2dCamCreate event table definition
38  */
39 
40 BEGIN_EVENT_TABLE( a2dCamCreate, wxDialog )
41 
42 ////@begin a2dCamCreate event table entries
43  EVT_BUTTON( ID_CamCreateOke, a2dCamCreate::OnCamCreateOkeClick )
44 
45  EVT_BUTTON( ID_CamCreateCancel, a2dCamCreate::OnCancel )
46 
47 ////@end a2dCamCreate event table entries
48 
49 END_EVENT_TABLE()
50 
51 
52 /*!
53  * a2dCamCreate constructors
54  */
55 
56 a2dCamCreate::a2dCamCreate()
57 {
58  Init();
59 }
60 
61 a2dCamCreate::a2dCamCreate( wxWindow* parent, a2dHabitat* habitat, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
62 {
63  Init();
64  Create(parent, habitat, id, caption, pos, size, style);
65 }
66 
67 
68 /*!
69  * a2dCamCreate creator
70  */
71 
72 bool a2dCamCreate::Create( wxWindow* parent, a2dHabitat* habitat, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
73 {
74  m_habitat = habitat;
75 ////@begin a2dCamCreate creation
76  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
77  wxDialog::Create( parent, id, caption, pos, size, style );
78 
80  if (GetSizer())
81  {
82  GetSizer()->SetSizeHints(this);
83  }
84  Centre();
85 ////@end a2dCamCreate creation
86  return true;
87 }
88 
89 
90 /*!
91  * a2dCamCreate destructor
92  */
93 
95 {
96 ////@begin a2dCamCreate destruction
97 ////@end a2dCamCreate destruction
98 }
99 
100 
101 /*!
102  * Member initialisation
103  */
104 
106 {
107 ////@begin a2dCamCreate member initialisation
108  m_habitat = NULL;
109  m_camName = NULL;
110  m_NrPorts = NULL;
111  m_symbol = NULL;
112  m_diagram = NULL;
113  m_gui = NULL;
114  m_instanceSymbol = NULL;
115  m_instanceDiagram = NULL;
116  m_noInst = NULL;
117  m_oke = NULL;
118  m_cancel = NULL;
119 ////@end a2dCamCreate member initialisation
120 }
121 
122 
123 /*!
124  * Control creation for a2dCamCreate
125  */
126 
128 {
129 ////@begin a2dCamCreate content construction
130  // Generated by DialogBlocks, 27/10/2013 16:00:44 (unregistered)
131 
132  a2dCamCreate* itemDialog1 = this;
133 
134  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
135  itemDialog1->SetSizer(itemBoxSizer2);
136 
137  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
138  itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
139 
140  wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, ID__CamNameText, _("Cameleon Name:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );
141  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxFIXED_MINSIZE, 5);
142 
143  m_camName = new wxTextCtrl( itemDialog1, ID_CamName, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
144  m_camName->SetHelpText(_("Name of the a2dCameleon to create"));
146  m_camName->SetToolTip(_("Name of the a2dCameleon to create"));
147  m_camName->SetName(_T("a2dCameleon"));
148  itemBoxSizer3->Add(m_camName, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
149 
150  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
151  itemBoxSizer2->Add(itemBoxSizer6, 0, wxALIGN_LEFT|wxALL, 5);
152 
153  wxStaticText* itemStaticText7 = new wxStaticText( itemDialog1, ID_NrPortsText, _("Number of ports:"), wxDefaultPosition, wxDefaultSize, 0 );
154  itemStaticText7->SetHelpText(_("Number of port to create on symbol (can be modified later on)\nWhen not 0, a symbol will be automatically created. This the user can modify.\n"));
156  itemStaticText7->SetToolTip(_("Number of port to create on symbol (can be modified laterb on)"));
157  itemBoxSizer6->Add(itemStaticText7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
158 
159  m_NrPorts = new wxSpinCtrl( itemDialog1, ID_NrPorts, _T("0"), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 100, 0 );
160  m_NrPorts->SetHelpText(_("The number of ports to generate on symbol, can be modified later on"));
162  m_NrPorts->SetToolTip(_("The number of ports to generate on symbol, can be modified later on"));
163  itemBoxSizer6->Add(m_NrPorts, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
164 
165  m_symbol = new wxCheckBox( itemDialog1, ID_InstSymbol, _("Symbol"), wxDefaultPosition, wxDefaultSize, 0 );
166  m_symbol->SetValue(true);
167  m_symbol->SetHelpText(_("Create a symbol appearance"));
169  m_symbol->SetToolTip(_("Create a symbol"));
170  m_symbol->SetName(_T("symbol"));
171  itemBoxSizer2->Add(m_symbol, 0, wxALIGN_LEFT|wxALL, 5);
172 
173  m_diagram = new wxCheckBox( itemDialog1, ID__InstDiagram, _("Diagram"), wxDefaultPosition, wxDefaultSize, 0 );
174  m_diagram->SetValue(true);
175  m_diagram->SetHelpText(_("Create a diagram appearance"));
177  m_diagram->SetToolTip(_("Create a diagram"));
178  m_diagram->SetName(_T("diagram"));
179  itemBoxSizer2->Add(m_diagram, 0, wxALIGN_LEFT|wxALL, 5);
180 
181  m_gui = new wxCheckBox( itemDialog1, ID_InstGui, _("Graphical Interface"), wxDefaultPosition, wxDefaultSize, 0 );
182  m_gui->SetValue(false);
183  m_gui->SetHelpText(_("Create a GUI Apperance"));
185  m_gui->SetToolTip(_("Create a GUI"));
186  m_gui->SetName(_T("gui"));
187  itemBoxSizer2->Add(m_gui, 0, wxALIGN_LEFT|wxALL, 5);
188 
189  wxStaticBox* itemStaticBoxSizer12Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Instanciation"));
190  wxStaticBoxSizer* itemStaticBoxSizer12 = new wxStaticBoxSizer(itemStaticBoxSizer12Static, wxHORIZONTAL);
191  itemBoxSizer2->Add(itemStaticBoxSizer12, 0, wxALIGN_LEFT|wxALL, 5);
192 
193  m_instanceSymbol = new wxRadioButton( itemDialog1, ID_RADIOBUTTON, _("Instanciate Symbol"), wxDefaultPosition, wxDefaultSize, 0 );
194  m_instanceSymbol->SetValue(true);
195  m_instanceSymbol->SetHelpText(_("Create an instance of the new a2dCameleon in current view, using the symbol"));
197  m_instanceSymbol->SetToolTip(_("Create an instance of the new a2dCameleon in current view, using the symbol"));
198  itemStaticBoxSizer12->Add(m_instanceSymbol, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
199 
200  m_instanceDiagram = new wxRadioButton( itemDialog1, ID_RADIOBUTTON1, _("Instanciate Diagram"), wxDefaultPosition, wxDefaultSize, 0 );
201  m_instanceDiagram->SetValue(false);
202  m_instanceDiagram->SetHelpText(_("Create an instance of the new a2dCameleon in current view, using the Diagram"));
204  m_instanceDiagram->SetToolTip(_("Create an instance of the new a2dCameleon in current view, using the Diagram"));
205  itemStaticBoxSizer12->Add(m_instanceDiagram, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
206 
207  m_noInst = new wxRadioButton( itemDialog1, ID_RADIOBUTTON2, _("No instance"), wxDefaultPosition, wxDefaultSize, 0 );
208  m_noInst->SetValue(false);
209  m_noInst->SetHelpText(_("No instance will be added"));
211  m_noInst->SetToolTip(_("No instance will be added"));
212  itemStaticBoxSizer12->Add(m_noInst, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
213 
214  wxBoxSizer* itemBoxSizer16 = new wxBoxSizer(wxHORIZONTAL);
215  itemBoxSizer2->Add(itemBoxSizer16, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
216 
217  m_oke = new wxButton( itemDialog1, ID_CamCreateOke, _("Oke"), wxDefaultPosition, wxDefaultSize, 0 );
218  m_oke->SetDefault();
219  m_oke->SetName(_T("Oke"));
220  itemBoxSizer16->Add(m_oke, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
221 
222  m_cancel = new wxButton( itemDialog1, ID_CamCreateCancel, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
223  m_cancel->SetName(_T("Cancel"));
224  itemBoxSizer16->Add(m_cancel, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
225 
226 ////@end a2dCamCreate content construction
227 }
228 
229 
230 /*!
231  * Should we show tooltips?
232  */
233 
235 {
236  return true;
237 }
238 
239 /*!
240  * Get bitmap resources
241  */
242 
243 wxBitmap a2dCamCreate::GetBitmapResource( const wxString& name )
244 {
245  // Bitmap retrieval
246 ////@begin a2dCamCreate bitmap retrieval
247  wxUnusedVar(name);
248  return wxNullBitmap;
249 ////@end a2dCamCreate bitmap retrieval
250 }
251 
252 /*!
253  * Get icon resources
254  */
255 
256 wxIcon a2dCamCreate::GetIconResource( const wxString& name )
257 {
258  // Icon retrieval
259 ////@begin a2dCamCreate icon retrieval
260  wxUnusedVar(name);
261  return wxNullIcon;
262 ////@end a2dCamCreate icon retrieval
263 }
264 
265 
266 /*!
267  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CamCreateOke
268  */
269 
270 void a2dCamCreate::OnCamCreateOkeClick( wxCommandEvent& event )
271 {
272  wxString name = m_camName->GetValue();
273  if ( ! name.IsEmpty() )
274  {
275  double grid = m_habitat->GetObjectGridSize();
276  a2dCameleon* cam = new a2dCameleon( name, 0,0, m_habitat );
277  cam->AddToRoot();
278 
279  a2dDiagram* diagram = NULL;
280  if ( m_symbol->GetValue() )
281  {
282  diagram = new a2dSymbol( cam, 0,0 );
283  cam->AddAppearance( diagram );
284  int nrports = m_NrPorts->GetValue();
285  if ( nrports )
286  {
287  a2dRect* r = new a2dRect( 0, 0, 30*grid, ( nrports + 2 ) * grid*3 );
288  r->SetGeneratePins( false );
289  diagram->AppendToDrawing( r );
290  double y = 3*grid;
291  for ( int i = 0 ; i < nrports; i ++ )
292  {
293  wxString strNr = wxString::Format("%s_%d", name, i);
294  a2dPort* p = new a2dPort( 0, 0, strNr, a2dPinClass::Standard );
295  p->Rotate( 180 );
296  p->Translate( 0, y );
297  diagram->AppendToDrawing( p );
298  y += 3*grid;
299  }
300  }
301  else
302  {
303  a2dText* text = new a2dText( "No contents yet, draw a symbol wih port here", 0, 0, a2dCanvasModule::GetFontMedBold() );
304  text->SetStrokeColour( wxColour( 124, 124,1) );
305  diagram->AppendToDrawing( text );
306  }
307  }
308  if ( m_diagram->GetValue() )
309  {
310  diagram = new a2dDiagram( cam, 0,0 );
311  diagram->Translate( 0, - grid * 6 );
312  a2dText* text = new a2dText( "No contents yet, draw a diagram with port", 0, 0, a2dCanvasModule::GetFontMedBold() );
313  text->SetStrokeColour( wxColour( 124, 124,1) );
314  cam->AddAppearance( diagram );
315  }
316  m_cameleon = cam;
317  EndModal(wxID_OK);
318  }
319 }
320 
321 
322 /*!
323  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CamCreateCancel
324  */
325 
326 void a2dCamCreate::OnCancel( wxCommandEvent& event )
327 {
328  EndModal( wxID_CANCEL );
329 }
330 
double GetObjectGridSize()
used for objects which depend in size on this grid
Definition: canglob.h:939
void SetGeneratePins(bool value)
set the GeneratePins flag
Definition: canobj.h:2295
~a2dCamCreate()
Destructor.
Definition: camcreate.cpp:94
diagram is an appearance for a2dCameleon
Definition: cameleon.h:382
void OnCamCreateOkeClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CamCreateOke
Definition: camcreate.cpp:270
Port to be used in a diagram for connecting to symbol.
Definition: cameleon.h:54
static bool ShowToolTips()
Should we show tooltips?
Definition: camcreate.cpp:234
object to show several appearance views on what it contains
Definition: cameleon.h:630
void AddToRoot(bool autoPlace=true)
add this to ms_centralCameleonRoot at a suitable position
Definition: cameleon.cpp:1260
void Init()
Initialises member variables.
Definition: camcreate.cpp:105
a2dText is an abstract base class.
Definition: cantext.h:93
void SetStrokeColour(const wxColour &colour)
set first colour of stroke
Definition: canobj.cpp:2963
void Translate(double x, double y)
relative translate the object to position x,y in world coordinates
Definition: canobj.h:569
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
Definition: camcreate.cpp:256
Symbolic appearance for a2dCameleon.
Definition: cameleon.h:470
defines common settinsg for a habitat for a set of a2dCameleons.
Definition: canglob.h:439
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
Definition: camcreate.cpp:243
special a2dCanvasObject to make a multi view hierachy.
bool Create(wxWindow *parent, a2dHabitat *habitat=NULL, wxWindowID id=SYMBOL_A2DCAMCREATE_IDNAME, const wxString &caption=SYMBOL_A2DCAMCREATE_TITLE, const wxPoint &pos=SYMBOL_A2DCAMCREATE_POSITION, const wxSize &size=SYMBOL_A2DCAMCREATE_SIZE, long style=SYMBOL_A2DCAMCREATE_STYLE)
Creation.
Definition: camcreate.cpp:72
static a2dPinClass * Standard
Pins of this class can only connect to pins of the same class.
Definition: canpin.h:766
void OnCancel(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CamCreateCancel
Definition: camcreate.cpp:326
void CreateControls()
Creates the controls and sizers.
Definition: camcreate.cpp:127
a2dRect
Definition: canprim.h:440
void Rotate(double rotation)
Rotates this object clockwise.
Definition: canobj.cpp:2615
a2dCamCreate()
Constructors.
Definition: camcreate.cpp:56
camcreate.cpp Source File -- Sun Oct 12 2014 17:04:12 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation