2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbwxCommandButton.cxx,v $
32 Date: $Date: 2012/11/16 08:52:14 $
33 Version: $Revision: 1.16 $
34 =========================================================================*/
42 #ifdef _USE_WXWIDGETS_
45 #include "bbwxCommandButton.h"
46 #include "bbwxPackage.h"
47 #include "bbtkInterpreter.h"
48 #include "bbtkExecuter.h"
56 //--------------------------------------------------------------------------
57 class CommandButtonWidget : public wxPanel
60 CommandButtonWidget(CommandButton* box, wxWindow *parent,
62 ~CommandButtonWidget();
63 void OnCommandButton( wxEvent& );
64 void SetLabel(wxString title);
65 void SetColour(wxColour color);
69 wxButton *mwxCommandButton;
72 //--------------------------------------------------------------------------
73 //--------------------------------------------------------------------------
75 CommandButtonWidget::CommandButtonWidget(CommandButton* box,
78 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
81 wxPanel *panel = this;
82 mwxCommandButton = new wxButton( panel, -1, title);
83 Connect( mwxCommandButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED ,
84 (wxObjectEventFunction)
85 (void (wxPanel::*)(wxEvent&))
86 &CommandButtonWidget::OnCommandButton );
87 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
88 sizer -> Add( mwxCommandButton,1,wxGROW | wxALL,10 );
89 sizer -> AddGrowableCol(0);
90 panel -> SetSizer(sizer);
91 panel -> SetAutoLayout(true);
95 CommandButtonWidget::~CommandButtonWidget()
99 void CommandButtonWidget::OnCommandButton( wxEvent& )
101 // Look for the interpreter or the executer if no interpreter
102 bbtk::Interpreter::Pointer I;
103 bbtk::VirtualExec::Pointer E;
104 if (mBox->bbGetParent() != 0)
106 bbtk::Factory::Pointer f = boost::dynamic_pointer_cast<bbtk::ComplexBlackBoxDescriptor>(mBox->bbGetParent()->bbGetDescriptor())->GetFactory();
110 E = f->GetExecuter();
111 I = E->GetInterpreter();
116 // bbtkError("CommandButton::DoProcess() : could not find interpreter");
119 // If no executer : create a totally independant interpreter
120 I = bbtk::Interpreter::New();
124 // If executer : create an interpreter using E
125 I = bbtk::Interpreter::New(E);
129 std::string commandstr(mBox->bbGetInputIn());
131 // bbtk::Interpreter::mGlobalInterpreter->InterpretLine( commandstr );
135 pos2 = commandstr.find(";",pos1);
136 std::string ccommand;
142 ccommand=commandstr.substr(pos1,commandstr.length()-pos1 );
146 ccommand=commandstr.substr(pos1,pos2-pos1);
148 for ( i=0 ; i < ccommand.length() ; i++)
150 if (ccommand[i]==39) // '
155 I->InterpretLine( ccommand );
157 pos2 = commandstr.find(";",pos2+1);
160 mBox->UpdateColour();
161 mBox->bbSignalOutputModification();
164 //--------------------------------------------------------------------------
165 void CommandButtonWidget::SetLabel(wxString title)
167 mwxCommandButton->SetLabel(title);
170 //--------------------------------------------------------------------------
171 void CommandButtonWidget::SetColour(wxColour color)
173 mwxCommandButton->SetBackgroundColour(color);
174 mwxCommandButton->Refresh();
175 mwxCommandButton->ClearBackground();
180 //--------------------------------------------------------------------------
181 //-------------------------------------------------------------------------
182 //--------------------------------------------------------------------------
183 //--------------------------------------------------------------------------
185 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,CommandButton);
186 BBTK_BLACK_BOX_IMPLEMENTATION(CommandButton,bbtk::WxBlackBox);
188 //-----------------------------------------------------------------
189 void CommandButton::bbUserSetDefaultValues()
193 std::vector<double> lstColour;
194 lstColour.push_back(0.75);
195 lstColour.push_back(0.75);
196 lstColour.push_back(0.75);
197 bbSetInputColour(lstColour);
198 bbSetOutputWidget(0);
201 //-----------------------------------------------------------------
202 void CommandButton::bbUserInitializeProcessing()
206 //-----------------------------------------------------------------
207 void CommandButton::bbUserFinalizeProcessing()
212 void CommandButton::Process()
214 CommandButtonWidget* w = (CommandButtonWidget*)bbGetOutputWidget();
222 void CommandButton::UpdateColour()
224 CommandButtonWidget* wxwidget = (CommandButtonWidget*)bbGetOutputWidget();
225 if ( (bbGetInputColour()[0]==-1) &&
226 (bbGetInputColour()[1]==-1) &&
227 (bbGetInputColour()[2]==-1) )
229 wxwidget->SetColour( wxwidget->GetParent()->GetBackgroundColour() );
231 int r=(int) (255*bbGetInputColour()[0]);
232 int g=(int) (255*bbGetInputColour()[1]);
233 int b=(int) (255*bbGetInputColour()[2]);
234 wxwidget->SetColour( wxColour(r,g,b) );
238 void CommandButton::UpdateLabel()
240 CommandButtonWidget* wxwidget = (CommandButtonWidget*)bbGetOutputWidget();
241 wxwidget->SetLabel( bbtk::std2wx( bbGetInputLabel() ) );
245 * \brief Create wxWidget .
249 void CommandButton::CreateWidget(wxWindow* parent)
252 ( new CommandButtonWidget ( this, //bbGetWxParent(),
254 bbtk::std2wx(bbGetInputLabel()) ) );
261 #endif // _USE_WXWIDGETS_