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