1 /*=========================================================================
4 Module: $RCSfile: bbwxCommandButton.cxx,v $
6 Date: $Date: 2008/07/25 07:44:12 $
7 Version: $Revision: 1.10 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
24 #ifdef _USE_WXWIDGETS_
27 #include "bbwxCommandButton.h"
28 #include "bbwxPackage.h"
29 #include "bbtkInterpreter.h"
30 #include "bbtkExecuter.h"
36 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,CommandButton);
38 CommandButtonWidget::CommandButtonWidget(CommandButton* box,
41 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
45 wxPanel *panel = this;
47 mwxCommandButton = new wxButton( panel, -1, title);
48 Connect( mwxCommandButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED ,
49 (wxObjectEventFunction)
50 (void (wxPanel::*)(wxEvent&))
51 &CommandButtonWidget::OnCommandButton );
53 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
54 sizer -> Add( mwxCommandButton,1,wxGROW | wxALL,10 );
55 sizer -> AddGrowableCol(0);
57 panel -> SetSizer(sizer);
58 panel -> SetAutoLayout(true);
63 CommandButtonWidget::~CommandButtonWidget()
68 void CommandButtonWidget::OnCommandButton( wxEvent& )
70 // Look for the interpreter or the executer if no interpreter
71 bbtk::Interpreter::Pointer I;
72 bbtk::VirtualExec::Pointer E;
73 if (mBox->bbGetParent() != 0)
75 bbtk::Factory::Pointer f = boost::dynamic_pointer_cast<bbtk::ComplexBlackBoxDescriptor>(mBox->bbGetParent()->bbGetDescriptor())->GetFactory();
80 I = E->GetInterpreter();
85 // bbtkError("CommandButton::DoProcess() : could not find interpreter");
88 // If no executer : create a totally independant interpreter
89 I = bbtk::Interpreter::New();
93 // If executer : create an interpreter using E
94 I = bbtk::Interpreter::New(E);
98 std::string commandstr(mBox->bbGetInputIn());
100 // bbtk::Interpreter::mGlobalInterpreter->InterpretLine( commandstr );
104 pos2 = commandstr.find(";",pos1);
105 std::string ccommand;
111 ccommand=commandstr.substr(pos1,commandstr.length()-pos1 );
115 ccommand=commandstr.substr(pos1,pos2-pos1);
117 for ( i=0 ; i < ccommand.length() ; i++)
119 if (ccommand[i]==39) // '
124 I->InterpretLine( ccommand );
126 pos2 = commandstr.find(";",pos2+1);
131 mBox->UpdateColour();
132 mBox->bbSignalOutputModification();
136 //--------------------------------------------------------------------------
138 void CommandButtonWidget::SetLabel(wxString title)
140 mwxCommandButton->SetLabel(title);
142 //--------------------------------------------------------------------------
144 void CommandButtonWidget::SetColour(wxColour color)
146 mwxCommandButton->SetBackgroundColour(color);
151 //--------------------------------------------------------------------------
152 //-------------------------------------------------------------------------
153 //--------------------------------------------------------------------------
154 //--------------------------------------------------------------------------
157 BBTK_BLACK_BOX_IMPLEMENTATION(CommandButton,bbtk::WxBlackBox);
159 void CommandButton::bbUserConstructor()
163 std::vector<double> lstColour;
164 lstColour.push_back(0.75);
165 lstColour.push_back(0.75);
166 lstColour.push_back(0.75);
167 bbSetInputColour(lstColour);
171 void CommandButton::Process()
177 void CommandButton::UpdateColour()
179 CommandButtonWidget* wxwidget = (CommandButtonWidget*)bbGetOutputWidget();
180 if ( (bbGetInputColour()[0]==-1) &&
181 (bbGetInputColour()[1]==-1) &&
182 (bbGetInputColour()[2]==-1) )
184 wxwidget->SetColour( wxwidget->GetParent()->GetBackgroundColour() );
188 int r=(int) (255*bbGetInputColour()[0]);
189 int g=(int) (255*bbGetInputColour()[1]);
190 int b=(int) (255*bbGetInputColour()[2]);
191 wxwidget->SetColour( wxColour(r,g,b) );
195 void CommandButton::UpdateLabel()
197 CommandButtonWidget* wxwidget = (CommandButtonWidget*)bbGetOutputWidget();
198 wxwidget->SetLabel( bbtk::std2wx( bbGetInputLabel() ) );
202 * \brief Create wxWidget .
206 void CommandButton::CreateWidget()
209 ( new CommandButtonWidget ( this, bbGetWxParent(),
210 bbtk::std2wx(bbGetInputLabel()) ) );
217 #endif // _USE_WXWIDGETS_