00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00037 #ifdef _USE_WXWIDGETS_
00038
00039
00040 #include "bbwxCommandButton.h"
00041 #include "bbwxPackage.h"
00042 #include "bbtkInterpreter.h"
00043 #include "bbtkExecuter.h"
00044
00045
00046
00047 namespace bbwx
00048 {
00049
00050
00051
00052 class CommandButtonWidget : public wxPanel
00053 {
00054 public:
00055 CommandButtonWidget(CommandButton* box, wxWindow *parent,
00056 wxString title);
00057 ~CommandButtonWidget();
00058 void OnCommandButton( wxEvent& );
00059 void SetLabel(wxString title);
00060 void SetColour(wxColour color);
00061
00062 private:
00063 CommandButton* mBox;
00064 wxButton *mwxCommandButton;
00065 };
00066
00067
00068
00069
00070 CommandButtonWidget::CommandButtonWidget(CommandButton* box,
00071 wxWindow *parent,
00072 wxString title )
00073 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
00074 mBox(box)
00075 {
00076
00077 wxPanel *panel = this;
00078
00079 mwxCommandButton = new wxButton( panel, -1, title);
00080 Connect( mwxCommandButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED ,
00081 (wxObjectEventFunction)
00082 (void (wxPanel::*)(wxEvent&))
00083 &CommandButtonWidget::OnCommandButton );
00084
00085 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
00086 sizer -> Add( mwxCommandButton,1,wxGROW | wxALL,10 );
00087 sizer -> AddGrowableCol(0);
00088
00089 panel -> SetSizer(sizer);
00090 panel -> SetAutoLayout(true);
00091 panel -> Layout();
00092
00093 }
00094
00095 CommandButtonWidget::~CommandButtonWidget()
00096 {
00097 }
00098
00099
00100 void CommandButtonWidget::OnCommandButton( wxEvent& )
00101 {
00102
00103 bbtk::Interpreter::Pointer I;
00104 bbtk::VirtualExec::Pointer E;
00105 if (mBox->bbGetParent() != 0)
00106 {
00107 bbtk::Factory::Pointer f = boost::dynamic_pointer_cast<bbtk::ComplexBlackBoxDescriptor>(mBox->bbGetParent()->bbGetDescriptor())->GetFactory();
00108 if ((f != 0)&&
00109 (f->GetExecuter()))
00110 {
00111 E = f->GetExecuter();
00112 I = E->GetInterpreter();
00113 }
00114 }
00115 if (I==0)
00116 {
00117
00118 if (E==0)
00119 {
00120
00121 I = bbtk::Interpreter::New();
00122 }
00123 else
00124 {
00125
00126 I = bbtk::Interpreter::New(E);
00127 }
00128 }
00129
00130 std::string commandstr(mBox->bbGetInputIn());
00131
00132
00133 unsigned int i;
00134 bool ok=true;
00135 int pos1=0,pos2;
00136 pos2 = commandstr.find(";",pos1);
00137 std::string ccommand;
00138 while (ok==true)
00139 {
00140 if (pos2==-1)
00141 {
00142 ok=false;
00143 ccommand=commandstr.substr(pos1,commandstr.length()-pos1 );
00144 }
00145 else
00146 {
00147 ccommand=commandstr.substr(pos1,pos2-pos1);
00148 }
00149 for ( i=0 ; i < ccommand.length() ; i++)
00150 {
00151 if (ccommand[i]==39)
00152 {
00153 ccommand[i]=34;
00154 }
00155 }
00156 I->InterpretLine( ccommand );
00157 pos1=pos2+1;
00158 pos2 = commandstr.find(";",pos2+1);
00159
00160 }
00161
00162 mBox->UpdateLabel();
00163 mBox->UpdateColour();
00164 mBox->bbSignalOutputModification();
00165 }
00166
00167
00168
00169
00170 void CommandButtonWidget::SetLabel(wxString title)
00171 {
00172 mwxCommandButton->SetLabel(title);
00173 }
00174
00175
00176 void CommandButtonWidget::SetColour(wxColour color)
00177 {
00178 mwxCommandButton->SetBackgroundColour(color);
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,CommandButton);
00189 BBTK_BLACK_BOX_IMPLEMENTATION(CommandButton,bbtk::WxBlackBox);
00190
00191 void CommandButton::bbUserConstructor()
00192 {
00193 bbSetInputIn("");
00194 bbSetInputLabel("");
00195 std::vector<double> lstColour;
00196 lstColour.push_back(0.75);
00197 lstColour.push_back(0.75);
00198 lstColour.push_back(0.75);
00199 bbSetInputColour(lstColour);
00200 bbSetOutputWidget(0);
00201 }
00202
00203
00204 void CommandButton::Process()
00205 {
00206 CommandButtonWidget* w = (CommandButtonWidget*)bbGetOutputWidget();
00207 if (w)
00208 {
00209 UpdateColour();
00210 UpdateLabel();
00211 }
00212 }
00213
00214 void CommandButton::UpdateColour()
00215 {
00216 CommandButtonWidget* wxwidget = (CommandButtonWidget*)bbGetOutputWidget();
00217 if ( (bbGetInputColour()[0]==-1) &&
00218 (bbGetInputColour()[1]==-1) &&
00219 (bbGetInputColour()[2]==-1) )
00220 {
00221 wxwidget->SetColour( wxwidget->GetParent()->GetBackgroundColour() );
00222 }
00223 else
00224 {
00225 int r=(int) (255*bbGetInputColour()[0]);
00226 int g=(int) (255*bbGetInputColour()[1]);
00227 int b=(int) (255*bbGetInputColour()[2]);
00228 wxwidget->SetColour( wxColour(r,g,b) );
00229 }
00230
00231 }
00232 void CommandButton::UpdateLabel()
00233 {
00234 CommandButtonWidget* wxwidget = (CommandButtonWidget*)bbGetOutputWidget();
00235 wxwidget->SetLabel( bbtk::std2wx( bbGetInputLabel() ) );
00236 }
00237
00243 void CommandButton::CreateWidget(wxWindow* parent)
00244 {
00245 bbSetOutputWidget
00246 ( new CommandButtonWidget ( this,
00247 parent,
00248 bbtk::std2wx(bbGetInputLabel()) ) );
00249 UpdateColour();
00250 }
00251
00252
00253 }
00254
00255 #endif // _USE_WXWIDGETS_
00256