1 /*=========================================================================
3 Module: $RCSfile: bbwxCommandButton.cxx,v $
5 Date: $Date: 2009/05/15 14:58:03 $
6 Version: $Revision: 1.15 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
37 #ifdef _USE_WXWIDGETS_
40 #include "bbwxCommandButton.h"
41 #include "bbwxPackage.h"
42 #include "bbtkInterpreter.h"
43 #include "bbtkExecuter.h"
51 //--------------------------------------------------------------------------
52 class CommandButtonWidget : public wxPanel
55 CommandButtonWidget(CommandButton* box, wxWindow *parent,
57 ~CommandButtonWidget();
58 void OnCommandButton( wxEvent& );
59 void SetLabel(wxString title);
60 void SetColour(wxColour color);
64 wxButton *mwxCommandButton;
67 //--------------------------------------------------------------------------
68 //--------------------------------------------------------------------------
70 CommandButtonWidget::CommandButtonWidget(CommandButton* box,
73 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
77 wxPanel *panel = this;
79 mwxCommandButton = new wxButton( panel, -1, title);
80 Connect( mwxCommandButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED ,
81 (wxObjectEventFunction)
82 (void (wxPanel::*)(wxEvent&))
83 &CommandButtonWidget::OnCommandButton );
85 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
86 sizer -> Add( mwxCommandButton,1,wxGROW | wxALL,10 );
87 sizer -> AddGrowableCol(0);
89 panel -> SetSizer(sizer);
90 panel -> SetAutoLayout(true);
95 CommandButtonWidget::~CommandButtonWidget()
100 void CommandButtonWidget::OnCommandButton( wxEvent& )
102 // Look for the interpreter or the executer if no interpreter
103 bbtk::Interpreter::Pointer I;
104 bbtk::VirtualExec::Pointer E;
105 if (mBox->bbGetParent() != 0)
107 bbtk::Factory::Pointer f = boost::dynamic_pointer_cast<bbtk::ComplexBlackBoxDescriptor>(mBox->bbGetParent()->bbGetDescriptor())->GetFactory();
111 E = f->GetExecuter();
112 I = E->GetInterpreter();
117 // bbtkError("CommandButton::DoProcess() : could not find interpreter");
120 // If no executer : create a totally independant interpreter
121 I = bbtk::Interpreter::New();
125 // If executer : create an interpreter using E
126 I = bbtk::Interpreter::New(E);
130 std::string commandstr(mBox->bbGetInputIn());
132 // bbtk::Interpreter::mGlobalInterpreter->InterpretLine( commandstr );
136 pos2 = commandstr.find(";",pos1);
137 std::string ccommand;
143 ccommand=commandstr.substr(pos1,commandstr.length()-pos1 );
147 ccommand=commandstr.substr(pos1,pos2-pos1);
149 for ( i=0 ; i < ccommand.length() ; i++)
151 if (ccommand[i]==39) // '
156 I->InterpretLine( ccommand );
158 pos2 = commandstr.find(";",pos2+1);
163 mBox->UpdateColour();
164 mBox->bbSignalOutputModification();
168 //--------------------------------------------------------------------------
170 void CommandButtonWidget::SetLabel(wxString title)
172 mwxCommandButton->SetLabel(title);
174 //--------------------------------------------------------------------------
176 void CommandButtonWidget::SetColour(wxColour color)
178 mwxCommandButton->SetBackgroundColour(color);
183 //--------------------------------------------------------------------------
184 //-------------------------------------------------------------------------
185 //--------------------------------------------------------------------------
186 //--------------------------------------------------------------------------
188 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,CommandButton);
189 BBTK_BLACK_BOX_IMPLEMENTATION(CommandButton,bbtk::WxBlackBox);
191 //-----------------------------------------------------------------
192 void CommandButton::bbUserSetDefaultValues()
196 std::vector<double> lstColour;
197 lstColour.push_back(0.75);
198 lstColour.push_back(0.75);
199 lstColour.push_back(0.75);
200 bbSetInputColour(lstColour);
201 bbSetOutputWidget(0);
204 //-----------------------------------------------------------------
205 void CommandButton::bbUserInitializeProcessing()
209 //-----------------------------------------------------------------
210 void CommandButton::bbUserFinalizeProcessing()
215 void CommandButton::Process()
217 CommandButtonWidget* w = (CommandButtonWidget*)bbGetOutputWidget();
225 void CommandButton::UpdateColour()
227 CommandButtonWidget* wxwidget = (CommandButtonWidget*)bbGetOutputWidget();
228 if ( (bbGetInputColour()[0]==-1) &&
229 (bbGetInputColour()[1]==-1) &&
230 (bbGetInputColour()[2]==-1) )
232 wxwidget->SetColour( wxwidget->GetParent()->GetBackgroundColour() );
236 int r=(int) (255*bbGetInputColour()[0]);
237 int g=(int) (255*bbGetInputColour()[1]);
238 int b=(int) (255*bbGetInputColour()[2]);
239 wxwidget->SetColour( wxColour(r,g,b) );
244 void CommandButton::UpdateLabel()
246 CommandButtonWidget* wxwidget = (CommandButtonWidget*)bbGetOutputWidget();
247 wxwidget->SetLabel( bbtk::std2wx( bbGetInputLabel() ) );
251 * \brief Create wxWidget .
255 void CommandButton::CreateWidget(wxWindow* parent)
258 ( new CommandButtonWidget ( this, //bbGetWxParent(),
260 bbtk::std2wx(bbGetInputLabel()) ) );
267 #endif // _USE_WXWIDGETS_