]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxBlackBoxEditionDialog.cxx
d4663da4fe07641a1b45214de44f740253a48794
[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(520, 640),wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) 
44         {
45                 _model=model;
46                 _parent = parent;
47                 std::string title("BlackBox Editing - ");
48                 title+=_model->getBBTKPackage();
49                 title+=":";
50                 title+=_model->getBBTKType();
51                 title+=":";
52                 title+=_model->getBBTKName();
53                 SetTitle(std2wx(title));
54
55                 constructBlackBoxEditionDialog();
56         }
57
58         //=========================================================================
59
60
61         wxBlackBoxEditionDialog::~wxBlackBoxEditionDialog()
62         {
63
64         }
65
66         //=========================================================================
67
68         void wxBlackBoxEditionDialog::constructBlackBoxEditionDialog()
69         {
70                 wxBoxSizer *sizerDialog = new wxBoxSizer(wxVERTICAL);
71
72         wxScrolledWindow *scrollWin = new wxScrolledWindow( this, -1, wxDefaultPosition,  wxSize(200,200), wxVSCROLL);
73
74                 wxStaticText *text = new wxStaticText(scrollWin, -1, wxT("Input Ports"));
75                 wxFont font(11, wxDEFAULT, wxNORMAL, wxBOLD);
76                 text->SetFont(font);
77
78
79
80                 std::vector<GPortModel*> lstInputs = _model->getInputPorts();
81                 wxFlexGridSizer *sizer = new wxFlexGridSizer(lstInputs.size(),3,5,5);
82                 sizer->AddGrowableCol(0);
83                 sizer->AddGrowableCol(1);
84                 sizer->AddGrowableCol(2);
85                 
86                 for(int i = 0;i<(int)lstInputs.size();i++)
87                 {
88                         sizer->AddGrowableRow(i);
89                         GPortModel* port        = lstInputs[i];
90                         std::string type        = port->getBBTKType();
91                         wxStaticText *lblName   = new wxStaticText(scrollWin, -1, std2wx(port->getBBTKName()),wxDefaultPosition,wxSize(100,25));
92                         wxStaticText *lblType   = new wxStaticText(scrollWin, -1, std2wx(type),wxDefaultPosition,wxSize(250,25));
93                         wxTextCtrl *txtValue    = new wxTextCtrl(scrollWin, -1, _T(""),wxDefaultPosition,wxSize(300,25));
94
95                         if(port->getValue()!="")
96                         {
97                                 txtValue->SetValue(crea::std2wx(port->getValue()));
98                         }
99
100                         if(port->isConnected())
101                         {
102                                 std::string connected("--Port Connected--");
103                                 txtValue->SetValue(crea::std2wx(connected));
104                                 txtValue->SetEditable(false);
105                         }
106
107                         char et = '*';
108                         if(type.find(et)!=-1)
109                         {
110                                 std::string noEditable("--No editable--");
111                                 txtValue->SetValue(crea::std2wx(noEditable));
112                                 txtValue->SetEditable(false);
113                         }
114
115                         _lstNames.push_back(lblName);
116                         _lstValues.push_back(txtValue);
117                         _lstTypes.push_back(lblType);
118
119                         sizer->Add(lblName,1,wxEXPAND,5);
120                         sizer->Add(txtValue,1,wxEXPAND,5);
121                         sizer->Add(lblType,1,wxCENTRE|wxEXPAND,5);
122                 }
123
124
125                 wxBoxSizer *buts        = new wxBoxSizer(wxHORIZONTAL);
126                 wxButton *okButton      = new wxButton(scrollWin, -1, _T("Ok"),wxDefaultPosition, wxSize(70, 30));
127                 wxButton *closeButton   = new wxButton(scrollWin, -1, _T("Close"), wxDefaultPosition, wxSize(70, 30));
128
129                 // connect command event handlers
130                 Connect(okButton->GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxBlackBoxEditionDialog::onClickOk));
131                 Connect(closeButton->GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxBlackBoxEditionDialog::onClickClose));
132
133                 buts->Add(okButton,0,wxCENTRE|wxEXPAND,5);
134                 buts->Add(closeButton,0,wxCENTRE|wxEXPAND,5);
135
136                 sizerDialog->AddSpacer(10);
137                 sizerDialog->Add(text,0,wxALIGN_TOP|wxALIGN_CENTER);
138                 sizerDialog->AddSpacer(15);
139                 sizerDialog->Add(sizer,0,wxALIGN_CENTER| wxEXPAND);
140                 sizerDialog->AddSpacer(15);
141                 sizerDialog->Add(buts,0,wxALIGN_CENTER | wxTOP | wxBOTTOM);
142
143                 scrollWin->SetSizer(sizerDialog);
144                 scrollWin->Centre();
145
146
147         scrollWin->SetVirtualSize(400,400);
148         scrollWin->SetSize(300,300);
149         scrollWin->SetScrollbars(10, 10, 50, 50);
150 //        scrollWin->SetSizer(sizer);
151
152
153                 ShowModal();
154                 Destroy();
155         }
156
157         //=========================================================================
158
159         void wxBlackBoxEditionDialog::onClickOk(wxCommandEvent& event)
160         {
161                 for(int i=0;i<(int)_lstValues.size();i++)
162                 {
163                         std::string text = wx2std(_lstValues[i]->GetValue());
164                         //TOFIX Search a better alternative
165                         if(text!="--No editable--" && text!="--Port Connected--")
166                         {
167                                 _model->setValueToInputPort(i,text);
168                         }
169                 }
170                 _parent->SaveTempActualDiagram();
171                 Close(true);
172         }
173
174         //=========================================================================
175
176         void wxBlackBoxEditionDialog::onClickClose(wxCommandEvent& event)
177         {
178 printf("EED wxBlackBoxEditionDialog::onClickClose\n");
179                 Close(true);
180         }
181
182         //=========================================================================
183
184 }  // EO namespace bbtk
185
186 // EOF
187 /*      // remove * from the name
188                 std::string name = _tabsMgr->GetNameTabPanel();
189                 if(name[name.length() - 1] != '*')
190                         name = name.substr(0, name.length()-2);
191                 _tabsMgr->SetNameTabPanel(name);*/