]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxDiagramPropertiesEditionDialog.cxx
2396 bbGEditor Feature New Normal Feature Show Tree 2014-06-18 15:29
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxDiagramPropertiesEditionDialog.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------  
24 */
25
26 /*=========================================================================
27 Program:   bbtkGEditor
28 Module:    $RCSfile$
29 Language:  C++
30 Date:      $Date$
31 Version:   $Revision$
32 =========================================================================*/
33
34 /* ---------------------------------------------------------------------
35
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux, Ricardo A Corredor
38 *
39 *  This software is governed by the CeCILL-B license under French law and
40 *  abiding by the rules of distribution of free software. You can  use,
41 *  modify and/ or redistribute the software under the terms of the CeCILL-B
42 *  license as circulated by CEA, CNRS and INRIA at the following URL
43 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44 *  or in the file LICENSE.txt.
45 *
46 *  As a counterpart to the access to the source code and  rights to copy,
47 *  modify and redistribute granted by the license, users are provided only
48 *  with a limited warranty  and the software's author,  the holder of the
49 *  economic rights,  and the successive licensors  have only  limited
50 *  liability.
51 *
52 *  The fact that you are presently reading this means that you have had
53 *  knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */
55
56 /**
57 *  \file
58 *  \brief Class bbtk::wxDiagramPropertiesEditionDialog .
59 */
60
61 #include "wxDiagramPropertiesEditionDialog.h"
62 #include "creaWx.h"
63
64
65 namespace bbtk
66 {
67         //=========================================================================
68
69         wxDiagramPropertiesEditionDialog::wxDiagramPropertiesEditionDialog(wxGUIEditorGraphicBBS *parent, NodeTreeC tree):wxDialog(parent,wxID_ANY,_T("Diagram Properties"), wxDefaultPosition, wxSize(500, 650),wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
70         {
71                 _parent = parent;
72                 _tree = tree;
73                 constructDiagramPropertiesEditionDialog();
74         }
75
76         //=========================================================================
77
78
79         wxDiagramPropertiesEditionDialog::~wxDiagramPropertiesEditionDialog()
80         {
81
82         }
83
84         //=========================================================================
85         
86         void wxDiagramPropertiesEditionDialog::constructBoxTree(NodeTreeC nodeTree, wxTreeItemId itemId)
87         {
88                 
89                 for(int i = 0 ; i < nodeTree.childs.size() ; i++)
90                 {
91                         string spc = nodeTree.childs[i].data;
92                         const char* ccc = spc.c_str();
93                         wxString pc = wxString::FromUTF8 (ccc);
94                         wxTreeItemId iId = _treeBox->AppendItem(itemId, pc, -1, -1, NULL);
95                         constructBoxTree(nodeTree.childs[i], iId );
96                 }
97         }
98
99   //==================================================================================
100
101         void wxDiagramPropertiesEditionDialog::constructDiagramPropertiesEditionDialog()
102         {
103                 const int ID_COMBO = 1;
104                 wxPanel *panel = new wxPanel(this, -1);
105                 wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
106                 wxFlexGridSizer *fgsizer = new wxFlexGridSizer(5, 2, 9, 25);
107
108
109                 //CFT           
110
111                 wxStaticText *tree = new wxStaticText(panel, -1, wxT("Tree of Box"));
112                 
113                 string sp = _tree.data;
114                 const char* cc = sp.c_str();
115                 wxString p = wxString::FromUTF8 (cc);
116
117                 _treeBox = new wxTreeCtrl (this, wxID_ANY, wxPoint(0,0), wxSize(320,300), wxTR_HAS_BUTTONS | wxTR_SINGLE );
118                 wxTreeItemId itemId = _treeBox->AddRoot(p, -1,-1,NULL);
119                 
120                 constructBoxTree(_tree, itemId);
121                 _treeBox->ExpandAll();  
122                 //_tree.treeTour(0);
123                 //CFT END
124
125 //CFT
126 //COMBOBOX OF MESSAGE
127 /*
128 Kind         Level  Nature
129 Interpreter  0  Messages of the interpreter
130 all          0  Minimum level for all kind of messages
131 change       0  Box i/o changes related messages
132 code         0  If positive then codes of the messages are displayed
133 config       0  Configuration related messages
134 connection   0  Connections related messages
135 data         0  Data related messages
136 debug        0  Debug messages
137 echo         1  Level>0 : Prints the output of the 'print' commands of the user.
138         Level>1 : Prints the command being interpreted
139 error        0  Error messages
140 gui          0  Graphical user interface related messages
141 help         1  Help messages
142 kernel       0  Messages generated by the core classes of the lib
143 max          9  Maximum level for all kind of messages
144 object       0  object memory related messages
145 output       1  Output messages
146 package      0  Packages related messages
147 process      0  Messages related to box processing
148 qt           0  Qt related messages
149 warning      1  Warning messages
150 widget       0  Widgets related messages
151 wx   
152 */
153                 _diagramMessageKind = new wxComboBox(panel, -1, wxEmptyString, wxDefaultPosition, wxSize(100,-1) );
154                 _diagramMessageKind->Append (wxT("Interpreter"));
155                 _diagramMessageKind->Append (wxT("all"));
156                 _diagramMessageKind->Append (wxT("change"));
157                 _diagramMessageKind->Append (wxT("code"));
158                 _diagramMessageKind->Append (wxT("config"));
159                 _diagramMessageKind->Append (wxT("connection"));
160                 _diagramMessageKind->Append (wxT("data"));
161                 _diagramMessageKind->Append (wxT("debug"));
162                 _diagramMessageKind->Append (wxT("echo"));
163                 _diagramMessageKind->Append (wxT("error"));
164                 _diagramMessageKind->Append (wxT("help"));
165                 _diagramMessageKind->Append (wxT("kernel"));
166                 _diagramMessageKind->Append (wxT("max"));
167                 _diagramMessageKind->Append (wxT("object"));
168                 _diagramMessageKind->Append (wxT("output"));
169                 _diagramMessageKind->Append (wxT("package"));
170                 _diagramMessageKind->Append (wxT("process"));
171                 _diagramMessageKind->Append (wxT("qt"));
172                 _diagramMessageKind->Append (wxT("warning"));
173                 _diagramMessageKind->Append (wxT("widget"));
174                 _diagramMessageKind->Append (wxT("wx"));
175                 _diagramMessageKind->SetEditable(false);
176
177                 _diagramMessageLevel = new wxComboBox(panel, -1, wxEmptyString, wxDefaultPosition, wxSize(100,-1) );
178                 _diagramMessageLevel->Append (wxT("0"));
179                 _diagramMessageLevel->Append (wxT("1"));
180                 _diagramMessageLevel->Append (wxT("2"));
181                 _diagramMessageLevel->Append (wxT("3"));
182                 _diagramMessageLevel->Append (wxT("4"));
183                 _diagramMessageLevel->Append (wxT("5"));
184                 _diagramMessageLevel->Append (wxT("6"));
185                 _diagramMessageLevel->Append (wxT("7"));
186                 _diagramMessageLevel->Append (wxT("8"));
187                 _diagramMessageLevel->Append (wxT("9"));
188                 _diagramMessageLevel->SetEditable(false);
189
190 //CFT END
191
192                 // SELECTION CONSTANTS
193                 // 0 - Application
194                 // 1 - Complex box
195                 _diagramType = new wxComboBox(panel, -1, wxEmptyString, wxDefaultPosition, wxSize(100,-1) );
196                 _diagramType->Append (wxT("Application"));
197                 _diagramType->Append (wxT("Complex box"));
198                 _diagramType->SetEditable(false);
199                 //_diagramType->Enable(false);
200
201                 Connect(ID_COMBO, wxEVT_COMMAND_COMBOBOX_SELECTED,
202                                         wxCommandEventHandler(wxDiagramPropertiesEditionDialog::OnComboBoxSelected));
203
204                 int currentType = (_parent->isCurrentDiagramComplexBox()==false)? 0 : 1;
205                 _diagramType->Select(currentType);
206                 _diagramMessageKind->Select(currentType);
207                 _diagramMessageLevel->Select(currentType);
208
209                 wxStaticText *type = new wxStaticText(panel, -1, wxT("Type"));
210                 wxStaticText *author = new wxStaticText(panel, -1, wxT("Author"));
211                 wxStaticText *category = new wxStaticText(panel, -1, wxT("Categories"));
212                 wxStaticText *description = new wxStaticText(panel, -1, wxT("Description"));
213                 wxStaticText *messageKind = new wxStaticText(panel, -1, wxT("Message kind"));
214                 wxStaticText *messageLevel = new wxStaticText(panel, -1, wxT("Message level"));
215
216                 _txtAuthor = new wxTextCtrl(panel, -1);
217                 _txtCategory = new wxTextCtrl(panel, -1);
218                 _txtDescription = new wxTextCtrl(panel, -1, wxT(""), wxPoint(-1, -1), wxSize(-1, -1), wxTE_MULTILINE);
219                 wxButton *okButton      = new wxButton(panel, -1, _T("Ok"),wxDefaultPosition, wxSize(-1, -1));
220                 wxButton *closeButton   = new wxButton(panel, -1, _T("Close"), wxDefaultPosition, wxSize(-1, -1));
221
222                 // connect command event handlers
223                 Connect(okButton->GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxDiagramPropertiesEditionDialog::onClickOk));
224                 Connect(closeButton->GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxDiagramPropertiesEditionDialog::onClickClose));
225
226                 // Assign loaded values
227                 _txtAuthor->SetValue(crea::std2wx(_parent->getCurrentDiagramAuthor()));
228                 _txtCategory->SetValue(crea::std2wx(_parent->getCurrentDiagramCategory()));
229                 _txtDescription->SetValue(crea::std2wx(_parent->getCurrentDiagramDescription()));
230
231
232                 fgsizer->Add(type);
233                 fgsizer->Add(_diagramType, 1, wxEXPAND);
234                 fgsizer->Add(author);
235                 fgsizer->Add(_txtAuthor, 1, wxEXPAND);
236                 fgsizer->Add(category);
237                 fgsizer->Add(_txtCategory, 1, wxEXPAND);
238                 fgsizer->Add(description, 1, wxEXPAND);
239                 fgsizer->Add(_txtDescription, 1, wxEXPAND);
240 //cft
241                 fgsizer->Add(messageKind);
242                 fgsizer->Add(_diagramMessageKind, 1, wxEXPAND);
243                 fgsizer->Add(messageLevel);
244                 fgsizer->Add(_diagramMessageLevel, 1, wxEXPAND);
245                 fgsizer->Add(tree);
246                 fgsizer->Add(_treeBox, 1, wxEXPAND);
247 //cft end               
248                 fgsizer->Add(okButton, 1, wxEXPAND);
249                 fgsizer->Add(closeButton, 1, wxEXPAND);
250
251                 fgsizer->AddGrowableRow(3, 1);
252                 fgsizer->AddGrowableCol(1, 1);
253
254                 hbox->Add(fgsizer, 1, wxALL | wxEXPAND, 15);
255                 panel->SetSizerAndFit(hbox);
256                 Centre();
257
258                 ShowModal();
259                 Destroy();
260
261                 // Assign loaded values
262                 _txtAuthor->SetValue(crea::std2wx(_parent->getCurrentDiagramAuthor()));
263                 _txtCategory->SetValue(crea::std2wx(_parent->getCurrentDiagramCategory()));
264                 _txtDescription->SetValue(crea::std2wx(_parent->getCurrentDiagramDescription()));
265         }
266
267         //=========================================================================
268
269         void wxDiagramPropertiesEditionDialog::onClickOk(wxCommandEvent& event)
270         {
271                 printf("RaC wxDiagramPropertiesEditionDialog::onClickOk\n");
272                 std::string txtAuthor = wx2std(_txtAuthor->GetValue());
273                 std::string txtCategory = wx2std(_txtCategory->GetValue());
274                 std::string txtDescription = wx2std(_txtDescription->GetValue());
275                 _parent->setCurrentDiagramAuthor(txtAuthor);
276                 _parent->setCurrentDiagramCategory(txtCategory);
277                 _parent->setCurrentDiagramDescription(txtDescription);
278
279                 // SELECTION CONSTANTS
280                 // 0 - Application
281                 // 1 - Complex box
282                 int selection = _diagramType->GetSelection();
283                 if(selection == 0)
284                         _parent->disableComplexBox();
285                 else if (selection == 1)
286                         _parent->enableComplexBox();
287
288
289                 //Message
290                 std::string kindSelected = wx2std(_diagramMessageKind->GetStringSelection());
291                 std::string levelSelected = wx2std(_diagramMessageLevel->GetStringSelection());
292                 _parent->setCurrentDiagramMessageKind(kindSelected);
293                 _parent->setCurrentDiagramMessageLevel(levelSelected);
294                 Close(true);
295         }
296
297         //=========================================================================
298
299         void wxDiagramPropertiesEditionDialog::onClickClose(wxCommandEvent& event)
300         {
301                 printf("RaC wxDiagramPropertiesEditionDialog::onClickClose\n");
302                 Close(true);
303         }
304
305         //=========================================================================
306
307         void wxDiagramPropertiesEditionDialog::OnComboBoxSelected(wxCommandEvent& event)
308         {
309                 // TODO Show info to edit complex boxes
310         }
311
312         //=========================================================================
313         
314
315         
316         
317 }  // EO namespace bbtk
318
319