]> Creatis software - creaWT.git/blob - wt/bbtk_wt_PKG/src/bbwtCommandButton.cxx~
2536 BBTK Feature New Normal wt-version Package
[creaWT.git] / wt / bbtk_wt_PKG / src / bbwtCommandButton.cxx~
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbwtCommandButton.h"
5 #include "bbwtPackage.h"
6 #include "bbtkInterpreter.h"
7 #include "bbtkExecuter.h"
8 namespace bbwt
9 {
10
11   //---------------------------------------------------------------------------------
12   class CommandButtonWidget : public Wt::WContainerWidget
13   {
14     public:
15       CommandButtonWidget(CommandButton* box,
16                           Wt::WContainerWidget *parent,
17                           Wt::WString label);
18       ~CommandButtonWidget();
19       void OnCommandButton();
20       void SetLabel(Wt::WString nLabel);
21     
22
23     private:
24       CommandButton* mBox;
25       Wt::WPushButton *mwtPushButton;
26   };
27   //--------------------------------------------------------------------------
28   //--------------------------------------------------------------------------
29   CommandButtonWidget::CommandButtonWidget(CommandButton* box,
30                           Wt::WContainerWidget *parent,
31                           Wt::WString label)
32                           :
33                           Wt::WContainerWidget(parent),
34                           mBox(box)
35   {
36     Wt::WContainerWidget *container = this;
37     mwtPushButton = new Wt::WPushButton(label,parent);
38     mwtPushButton->setMinimumSize(200,40);
39     mwtPushButton->clicked().connect(this, &CommandButtonWidget::OnCommandButton);
40     container->addWidget(mwtPushButton);
41   }
42   //--------------------------------------------------------------------------
43   //--------------------------------------------------------------------------
44   CommandButtonWidget::~CommandButtonWidget()
45   {
46   }
47   //--------------------------------------------------------------------------
48   //--------------------------------------------------------------------------
49   void CommandButtonWidget::OnCommandButton()
50   {
51     bbtk::Interpreter::Pointer I;
52     bbtk::VirtualExec::Pointer E;
53     if (mBox->bbGetParent() != 0) 
54           {
55             bbtk::Factory::Pointer f = boost::dynamic_pointer_cast<bbtk::ComplexBlackBoxDescriptor>(mBox->bbGetParent()->bbGetDescriptor())->GetFactory();
56             if ((f != 0)&&
57                 (f->GetExecuter()))
58       {
59         E = f->GetExecuter();
60               I = E->GetInterpreter();
61             }
62           }
63     if (I==0) 
64           {
65             //    bbtkError("CommandButton::DoProcess() : could not find interpreter");
66             if (E==0) 
67             {
68               // If no executer : create a totally independant interpreter
69               I = bbtk::Interpreter::New();
70             }
71             else 
72             {
73               // If executer : create an interpreter using E
74               I = bbtk::Interpreter::New(E);
75             }
76           }
77       
78     std::string commandstr(mBox->bbGetInputIn());
79     
80     //  bbtk::Interpreter::mGlobalInterpreter->InterpretLine( commandstr );
81     unsigned int i;
82     bool ok=true;
83     int pos1=0,pos2;
84     pos2 = commandstr.find(";",pos1);
85     std::string ccommand;
86     while (ok==true)
87     {
88             if (pos2==-1) 
89             {
90               ok=false;
91               ccommand=commandstr.substr(pos1,commandstr.length()-pos1 );
92             } 
93             else 
94             {
95               ccommand=commandstr.substr(pos1,pos2-pos1);
96             }
97             for ( i=0 ; i < ccommand.length() ; i++)
98             {
99               if (ccommand[i]==39) // '
100               {
101                       ccommand[i]=34;  // "
102               }
103             }           
104             I->InterpretLine( ccommand );
105             pos1=pos2+1;
106             pos2 = commandstr.find(";",pos2+1);
107         
108     }
109     mBox->UpdateLabel();
110     mBox->bbSignalOutputModification();
111     
112   }
113   //--------------------------------------------------------------------------
114   //--------------------------------------------------------------------------
115   void CommandButtonWidget::SetLabel(Wt::WString nLabel)
116   {
117     mwtPushButton->setText(nLabel);   
118   }
119
120 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wt,CommandButton)
121 BBTK_BLACK_BOX_IMPLEMENTATION(CommandButton,bbtk::WtBlackBox);
122 //===== 
123 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
124 //===== 
125 void CommandButton::Process()
126 {
127
128   CommandButtonWidget* w = (CommandButtonWidget*)bbGetOutputWidget();
129   if (w) 
130   {
131     UpdateLabel();
132   }
133   
134 }
135 //===== 
136 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
137 //===== 
138 void CommandButton::CreateWidget(Wt::WContainerWidget* parent)
139 {
140
141    bbSetOutputWidget( new CommandButtonWidget(this,
142                                               parent,
143                                               bbtk::std2wt(bbGetInputLabel())
144                                               )
145                      );
146   
147 }
148 //--------------------------------------------------------------------------------------
149   void CommandButton::UpdateLabel()
150   {
151     CommandButtonWidget* wtWidget = (CommandButtonWidget*)bbGetOutputWidget();
152     wtWidget->SetLabel( bbtk::std2wt( bbGetInputLabel() ) );
153   } 
154
155 //===== 
156 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
157 //===== 
158 void CommandButton::bbUserSetDefaultValues()
159 {
160   bbSetInputIn("");
161   bbSetInputLabel("");
162   bbSetOutputWidget(0);
163     
164 }
165 //===== 
166 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
167 //===== 
168 void CommandButton::bbUserInitializeProcessing()
169 {
170
171 }
172 //===== 
173 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
174 //===== 
175 void CommandButton::bbUserFinalizeProcessing()
176 {
177
178 }
179 }
180 // EO namespace bbwt
181
182