]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxBlackBoxEditionDialog.cxx
Changes in information presented in status bar, inside the box, and the editing dialo...
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxBlackBoxEditionDialog.cxx
1 /*=========================================================================                                                                               
2 Program:   bbtk
3 Module:    $RCSfile$
4 Language:  C++
5 Date:      $Date$
6 Version:   $Revision$
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32 *  \file 
33 *  \brief Class bbtk::wxBlackBoxEditionDialog . 
34 */
35
36 #include "wxBlackBoxEditionDialog.h"
37 #include "creaWx.h"
38
39 namespace bbtk
40 {
41         //=========================================================================
42
43         wxBlackBoxEditionDialog::wxBlackBoxEditionDialog(wxGUIEditorGraphicBBS *parent,GBlackBoxModel *model):wxDialog(parent,wxID_ANY,_T(""), wxDefaultPosition, wxSize(480, 640),wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
44         {
45                 _model=model;
46                 std::string title("BlackBox Editing - ");
47                 title+=_model->getBBTKPackage();
48                 title+=":";
49                 title+=_model->getBBTKType();
50                 title+=":";
51                 title+=_model->getBBTKName();
52                 SetTitle(std2wx(title));
53
54                 constructBlackBoxEditionDialog();
55         }
56
57         //=========================================================================
58
59         wxBlackBoxEditionDialog::wxBlackBoxEditionDialog(wxGUIEditorGraphicBBS *parent,wxVtkSceneManager* scene):wxDialog(parent, wxID_ANY, _T(""), wxDefaultPosition, wxSize(300, 300))
60         {
61                 
62         }
63
64         //=========================================================================
65
66         wxBlackBoxEditionDialog::~wxBlackBoxEditionDialog()
67         {
68
69         }
70
71         //=========================================================================
72
73         void wxBlackBoxEditionDialog::constructBlackBoxEditionDialog()
74         {
75                 wxBoxSizer *sizerDialog = new wxBoxSizer(wxVERTICAL);
76
77                 wxStaticText *text = new wxStaticText(this, -1, wxT("Input Ports"));
78                 wxFont font(11, wxDEFAULT, wxNORMAL, wxBOLD);
79                 text->SetFont(font);
80                                 
81                 std::vector<GPortModel*> lstInputs = _model->getInputPorts();
82                 wxFlexGridSizer *sizer = new wxFlexGridSizer(lstInputs.size(),3,5,5);             
83                 for(int i = 0;i<lstInputs.size();i++)
84                 {
85                         GPortModel* port = lstInputs[i];
86                         std::string type = port->getBBTKType();
87                         wxStaticText *lblName = new wxStaticText(this, -1, std2wx(port->getBBTKName()),wxDefaultPosition,wxSize(100,25));
88                         wxStaticText *lblType = new wxStaticText(this, -1, std2wx(type),wxDefaultPosition,wxSize(250,25));
89                         wxTextCtrl *txtValue = new wxTextCtrl(this, -1, _T(""),wxDefaultPosition,wxSize(90,25));
90                         
91                         if(port->getValue()!="")
92                         {
93                                 txtValue->SetLabel(crea::std2wx(port->getValue()));
94                         }
95
96                         if(port->isConnected())
97                         {
98                                 std::string connected("--Port Connected--");
99                                 txtValue->SetLabel(crea::std2wx(connected));
100                                 txtValue->SetEditable(false);
101                         }
102
103                         char et = '*';
104                         if(type.find(et)!=-1)
105                         {
106                                 std::string noEditable("--No editable--");
107                                 txtValue->SetLabel(crea::std2wx(noEditable));
108                                 txtValue->SetEditable(false);
109                         }
110
111                         _lstNames.push_back(lblName);                   
112                         _lstValues.push_back(txtValue);
113                         _lstTypes.push_back(lblType);
114                         
115                         sizer->Add(lblName,1,wxEXPAND,5);                       
116                         sizer->Add(txtValue,1,wxEXPAND,5);
117                         sizer->Add(lblType,1,wxCENTRE|wxEXPAND,5);
118                         
119                 }
120                 
121                 wxBoxSizer *buts = new wxBoxSizer(wxHORIZONTAL);
122                 wxButton *okButton = new wxButton(this, 1003, _T("Ok"),wxDefaultPosition, wxSize(70, 30));
123                 wxButton *closeButton = new wxButton(this, 1004, _T("Close"), wxDefaultPosition, wxSize(70, 30));
124
125                 // connect command event handlers
126                 Connect(1003,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxBlackBoxEditionDialog::onClickOk));
127                 Connect(1004,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxBlackBoxEditionDialog::onClickClose));
128                 
129                 buts->Add(okButton,0,wxCENTRE|wxEXPAND,5);
130                 buts->Add(closeButton,0,wxCENTRE|wxEXPAND,5);
131
132                 sizerDialog->AddSpacer(10);
133                 sizerDialog->Add(text,0,wxALIGN_TOP|wxALIGN_CENTER);
134                 sizerDialog->AddSpacer(15);
135                 sizerDialog->Add(sizer,0,wxALIGN_CENTER);
136                 sizerDialog->AddSpacer(15);
137                 sizerDialog->Add(buts,0,wxALIGN_CENTER | wxTOP | wxBOTTOM);
138
139                 SetSizer(sizerDialog);
140
141                 Centre();
142                 ShowModal();
143                 Destroy();
144         }
145
146         //=========================================================================
147
148         void wxBlackBoxEditionDialog::onClickOk(wxCommandEvent& event)
149         {
150
151                 for(int i=0;i<_lstValues.size();i++)
152                 {
153                         std::string text = wx2std(_lstValues[i]->GetLabelText());               
154                         _model->setValueToInputPort(i,text);
155                 }
156
157                 Close(true);
158         }
159
160         //=========================================================================
161
162         void wxBlackBoxEditionDialog::onClickClose(wxCommandEvent& event)
163         {
164                 Close(true);            
165         }
166
167         //=========================================================================
168
169 }  // EO namespace bbtk
170
171 // EOF