1 /*=========================================================================
4 Module: $RCSfile: bbwxCommandButton.cxx,v $
6 Date: $Date: 2008/03/10 06:24:13 $
7 Version: $Revision: 1.3 $
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"
35 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,CommandButton);
37 CommandButtonWidget::CommandButtonWidget(CommandButton* box,
40 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
44 wxPanel *panel = this;
46 mwxCommandButton = new wxButton( panel, -1, title);
47 Connect( mwxCommandButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED ,
48 (wxObjectEventFunction)
49 (void (wxPanel::*)(wxEvent&))
50 &CommandButtonWidget::OnCommandButton );
52 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
53 sizer -> Add( mwxCommandButton,1,wxGROW );
54 sizer -> AddGrowableCol(0);
56 panel -> SetSizer(sizer);
57 panel -> SetAutoLayout(true);
62 CommandButtonWidget::~CommandButtonWidget()
67 void CommandButtonWidget::OnCommandButton( wxEvent& )
69 // Look for the interpreter
70 bbtk::Interpreter* I = 0;
71 if (mBox->bbGetParent() != 0)
74 ((bbtk::ComplexBlackBoxDescriptor*)mBox->bbGetParent()
75 ->bbGetDescriptor())->GetFactory();
79 I = f->GetExecuter()->GetInterpreter();
84 // bbtkError("ExecBbiCommand::DoProcess() : could not find interpreter");
85 I = new bbtk::Interpreter();
88 std::string commandstr(mBox->bbGetInputIn());
90 // bbtk::Interpreter::mGlobalInterpreter->InterpretLine( commandstr );
94 pos2 = commandstr.find(";",pos1);
101 ccommand=commandstr.substr(pos1,commandstr.length()-pos1 );
105 ccommand=commandstr.substr(pos1,pos2-pos1);
107 for ( i=0 ; i < ccommand.length() ; i++)
114 bool insideComment = false; // for multiline comment
115 I->InterpretLine( ccommand, insideComment );
117 pos2 = commandstr.find(";",pos2+1);
122 mBox->UpdateColour();
123 mBox->bbSignalOutputModification();
127 //--------------------------------------------------------------------------
129 void CommandButtonWidget::SetLabel(wxString title)
131 mwxCommandButton->SetLabel(title);
133 //--------------------------------------------------------------------------
135 void CommandButtonWidget::SetColour(wxColour color)
137 mwxCommandButton->SetBackgroundColour(color);
142 //--------------------------------------------------------------------------
143 //-------------------------------------------------------------------------
144 //--------------------------------------------------------------------------
145 //--------------------------------------------------------------------------
148 BBTK_USER_BLACK_BOX_IMPLEMENTATION(CommandButton,bbtk::WxBlackBox);
150 void CommandButton::bbUserConstructor()
154 std::vector<double> lstColour;
155 lstColour.push_back(-1);
156 lstColour.push_back(-1);
157 lstColour.push_back(-1);
158 bbSetInputColour(lstColour);
162 void CommandButton::Process()
168 void CommandButton::UpdateColour()
170 CommandButtonWidget* wxwidget = (CommandButtonWidget*)bbGetOutputWidget();
171 if ( (bbGetInputColour()[0]==-1) &&
172 (bbGetInputColour()[1]==-1) &&
173 (bbGetInputColour()[2]==-1) )
175 wxwidget->SetColour( wxwidget->GetParent()->GetBackgroundColour() );
179 int r=(int) (255*bbGetInputColour()[0]);
180 int g=(int) (255*bbGetInputColour()[1]);
181 int b=(int) (255*bbGetInputColour()[2]);
182 wxwidget->SetColour( wxColour(r,g,b) );
186 void CommandButton::UpdateLabel()
188 CommandButtonWidget* wxwidget = (CommandButtonWidget*)bbGetOutputWidget();
189 wxwidget->SetLabel( bbtk::std2wx( bbGetInputLabel() ) );
193 * \brief Create wxWidget .
197 void CommandButton::CreateWidget()
200 ( new CommandButtonWidget ( this, bbGetWxParent(),
201 bbtk::std2wx(bbGetInputLabel()) ) );
208 #endif // _USE_WXWIDGETS_