]> Creatis software - bbtk.git/blob - kernel/src/bbtkWtBlackBox.cxx
#2696 BBTK Bug New Normal - BoxChange BoxExecute not responding at the second actio...
[bbtk.git] / kernel / src / bbtkWtBlackBox.cxx
1
2 /*
3  # ---------------------------------------------------------------------
4  #
5  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6  #                        pour la SantÈ)
7  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
9  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10  #
11  #  This software is governed by the CeCILL-B license under French law and
12  #  abiding by the rules of distribution of free software. You can  use,
13  #  modify and/ or redistribute the software under the terms of the CeCILL-B
14  #  license as circulated by CEA, CNRS and INRIA at the following URL
15  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
16  #  or in the file LICENSE.txt.
17  #
18  #  As a counterpart to the access to the source code and  rights to copy,
19  #  modify and redistribute granted by the license, users are provided only
20  #  with a limited warranty  and the software's author,  the holder of the
21  #  economic rights,  and the successive licensors  have only  limited
22  #  liability.
23  #
24  #  The fact that you are presently reading this means that you have had
25  #  knowledge of the CeCILL-B license and that you accept its terms.
26  # ------------------------------------------------------------------------ */
27
28
29 /*=========================================================================
30   Program:   bbtk
31   Module:    $RCSfile: bbtkWxBlackBox.cxx,v $
32   Language:  C++
33   Date:      $Date: 2012/11/16 08:49:01 $
34   Version:   $Revision: 1.45 $
35 =========================================================================*/
36
37
38
39 #ifdef _USE_WT_
40
41 /**
42  *  \file 
43  *  \brief 
44  */
45  
46 #include "bbtkWtBlackBox.h"
47 #include "bbtkBlackBoxOutputConnector.h"
48
49
50 //#include "bbtkWxContainerBlackBox.h"
51 //#include <wx/dialog.h>
52
53 //#include "bbtkData.h"
54 //#include "bbtkFactory.h"
55
56
57
58
59 namespace bbtk
60 {
61
62  
63 /*      
64         class jScript
65         {
66                 public:
67                         jScript();
68                         std::string jScriptLine;
69         };
70 */
71   //=========================================================================
72   // wtData structure
73   //=========================================================================
74
75         // For the very first contruction of the application
76 /*      struct wtServerData
77         {
78           std::string docRoot;
79           std::string port;
80           std::string address;
81         
82         };
83         */
84         struct wtData
85         {
86                 Wt::WContainerWidget *parent;
87                 WtBlackBox::Pointer b;
88                 WtBlackBox *pbox;       
89                 Wt::WString title;      
90         };
91
92 /*      jScript::jScript()
93         {
94                 jScriptLine = "";
95         }
96 */
97 //      static bbtk::jScript* js  = new bbtk::jScript();
98         static wtData myWtData;
99 //      static wtServerData loadedJS;
100         //static std::string* jss;
101         
102         
103
104   //=========================================================================
105   // javaScript Line
106   //=========================================================================
107         //Contains all the JS statements needed for the bbwt.
108                 
109   //=========================================================================
110   // WxFrame
111   //=========================================================================
112         // Application WT deployed
113   //==================================================================
114  
115  class WtWFrame : public Wt::WApplication
116   {
117   public:
118     WtWFrame( const Wt::WEnvironment& env );
119     ~WtWFrame();        
120     WtBlackBox::WeakPointer mBox; 
121   };    
122         
123
124         WtWFrame::WtWFrame( const Wt::WEnvironment& env ):Wt::WApplication(env)
125         {  
126                 //std::cout<<"Adding JavaScript --  DELETE ME -- bbtkWtBlackBox.cxx"<<std::endl;
127                 //this->require("/home/gonzalez/Documents/CREATOOLS/wt_library/wt/bbtk_wt_PKG/src/js/xtk.js");
128
129                 //this->require("http://get.goXTK.com/xtk.js");
130                 //this->useStyleSheet("css/demo.css");
131
132         //this->require("http://get.goXTK.com/xtk.js");
133         this->require( "resourcesXTK/xtk.js" );
134                 
135         //      this->require("http://get.goXTK.com/xtk_edge.js");
136 //      this->require("http://get.goXTK.com/xtk_xdat.gui.js");
137         this->require( "resourcesXTK/xtk_xdat.gui.js" );
138
139   this->useStyleSheet("resourcesXTK/styleWT.css"); 
140         //      std::cout<<"Cargado------------           "<<loadedJS<<std::endl;
141                 mBox = myWtData.b;
142
143 //EED -->
144                 if(!myWtData.parent)
145                 {
146                         std::cout<<"        SIN PADRE "<<std::endl;
147                         if(myWtData.parent == 0){std::cout<<"        PARENT 0 "<<std::endl;}
148                         if(myWtData.parent == NULL){std::cout<<"        PARENT NULL "<<std::endl;}
149                         myWtData.parent = new Wt::WContainerWidget();
150                         std::cout<<"Parent created --  DELETE ME -- bbtkWtBlackBox.cxx"<<std::endl;
151                 }
152
153                 Wt::WContainerWidget *myContainer = new Wt::WContainerWidget(myWtData.parent);
154                 myContainer->setMinimumSize(800,500);
155                 std::cout<<"Creando WebWIDGET DELETE ME ---- bbtkWtBlackBox.cxx.......50%"<<std::endl;
156                 myWtData.b->bbUserCreateWidget(myContainer);
157
158                 root()->addWidget(myWtData.parent);
159                 //bbmWindow = myCont;
160                 this->refresh();
161                 //jss = WtBlackBox::jScript;
162                 std::cout<<"Creando WebWIDGET DELETE ME ---- bbtkWtBlackBox.cxx........80%"<<std::endl;
163                 std::cout<<"Creando WebWIDGET DELETE ME SCRIPT : ---"<<bbtk::jScript<<"......80%"<<std::endl;
164                 //this->doJavaScript(bbtk::jScript); 
165
166 //EED
167        myWtData.pbox->bbwtUpdateInputs();
168 //       myWtData.pbox->bbwtProcess();
169
170
171   }
172   //==================================================================
173   //==================================================================
174   WtWFrame::~WtWFrame() 
175     { 
176       if (mBox.lock())
177         bbtkDebugMessage("widget",9,"["<<mBox.lock()->bbGetName()
178                          <<"] $$$$$$$$$$$$$$$$$$$ ~W()"
179                          <<std::endl);
180       else 
181         bbtkDebugMessage("widget",9,"[DEAD] $$$$$$$$$$$$$$$$$$$$$ ~WtContainer()"<<std::endl);
182       bbtkDebugMessage("widget",9,"WtWFrame::~WtWFrame()"<<std::endl);
183       if (mBox.lock()) mBox.lock()->bbSetWindow(0); 
184       WWt::DecNbWindowsAlive();
185     }
186
187
188  
189    
190         Wt::WApplication *createApplication(const Wt::WEnvironment& env)
191         {
192                         return new WtWFrame(env);                       
193         }
194
195
196   //=========================================================================
197   // WxDialogWxBlackBox::Pointer box
198   //=========================================================================
199
200    //==================================================================
201   // Dialog window which is modal
202  /* class BBTK_EXPORT  WxDialog : public wxDialog
203   {
204   public:
205     WxDialog(WxBlackBox::Pointer box, 
206                      wxWindow *parent, 
207                      wxString title, 
208                      wxSize size);
209     ~WxDialog();Wt::GetTopWindow()
210     void OnCloseWindow(wxCloseEvent& event);
211
212
213     WxBlackBox::WeakPointer mBox;      
214     DECLARE_EVENT_TABLE();
215     
216   };
217   
218   BEGIN_EVENT_TABLE(WxDialog, wxDialog)
219     EVT_CLOSE(WxDialog::OnCloseWindow)
220     END_EVENT_TABLE();
221   //=========================================================================
222
223   //=========================================================================
224   WxDialog::WxDialog(WxBlackBox::Pointer b,
225                      wxWindow *parent,
226                      wxString title,
227                      wxSize size)
228     :
229     wxDialog( parent, 
230                 -1, 
231                 title,
232                 wxDefaultPosition,
233                 size,
234                 wxRESIZE_BORDER | 
235                 wxSYSTEM_MENU  |
236                 wxCLOSE_BOX |
237                 wxMAXIMIZE_BOX | 
238                 wxMINIMIZE_BOX | 
239                 wxCAPTION  
240               ),
241     mBox(b)
242   {
243     bbtkDebugMessage("widget",9,"WxDialog::WxDialog ["<<b->bbGetName()<<"]"
244                      <<std::endl);WxBlackBox::Pointer box
245     Wx::IncNbWindowsAlive();
246     b->bbSetWindow(this);
247     // Insert the widget into the window
248     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
249     b->bbUserCreateWidget(this);
250     wxWindow* widget = b->bbGetOutputWidget();
251     sizer->Add( widget, 1, wxALL|wxGROW, 2);
252     SetSizer(sizer);
253     Layout();
254   }
255   //==================================================================
256   //===========================organise=======================================
257   WxDialog::~WxDialog() 
258     { 
259       bbtkDebugMessage("widget",9,"WxDialog::~WxDialog()"<<std::endl);
260       //bbtkDebugMessage("widget",9,"WxFrame::~WxFrame()"<<std::endl);
261       //      if (mBox.lock()) mBox.lock()->bbSetWindow(0); 
262       //      Wx::DecNbWindowsAlive();
263     }
264    //==================================================================
265    //==================================================================
266   void WxDialog::OnCloseWindow(wxCloseEvent& event)
267     {
268       bbtkDebugMessage("widget",9,"WxDialog::OnCloseWindow()"<<wxGUIEditorGraphicBBS:std::endl);
269       if (mBox.lock()) mBox.lock()->bbSetWindow(0); http://doodle.com/qx65tfxismf7d6ku5vxykghs/admin#table
270       Wx::DecNbWindowsAlive();
271       this->Destroy();
272     }
273    //==================================================================
274
275 */
276  //=========================================================================
277   // WxBlackBox
278   //=========================================================================
279
280   //=========================================================================
281   //=========================================================================
282   //=========================================================================
283   //=========================================================================
284   BBTK_BLACK_BOX_IMPLEMENTATION(WtBlackBox,WidgetBlackBox<Wt::WContainerWidget>);
285         
286         //std::string WtBlackBox::wtServerData::docRoot = "/home/gonzalez/Documents/pruebaResources";
287         //std::string WtBlackBox::wtServerData::docRoot = "/usr/local/share/wtResources";
288   //std::string WtBlackBox::wtServerData::port    = "8081";
289
290         std::string WtBlackBox::wtServerData::docRoot   = "<void>";
291         std::string WtBlackBox::wtServerData::port      = "<void>";
292         std::string WtBlackBox::wtServerData::address   = "0.0.0.0";
293         int WtBlackBox::wtServerData::argc                              = 0;
294         char **WtBlackBox::wtServerData::argv                   = NULL;
295
296   //=========================================================================
297   //=========================================================================
298   void WtBlackBox::bbUserSetDefaultValues()
299   {
300     bbtkBlackBoxDebugMessage("widget",5,"WtBlackBox::bbUserSetDefaultValues()"<<std::endl);
301     bbmWindow = 0;
302   }
303   //=========================================================================
304
305   //=========================================================================
306   void WtBlackBox::bbUserInitializeProcessing()
307   {
308
309   }
310   //================================================================http://intranet-if.insa-lyon.fr/temps/5IF39.html==    
311
312   //=========================================================================
313   void WtBlackBox::bbUserFinalizeProcessing()
314   {
315     bbtkBlackBoxDebugMessage("widget",5,"==> WtBlackBox::bbUserFinalizeProcessing()"<<std::endl);
316     bbDestroyWindow();
317     bbtkBlackBoxDebugMessage("widget",5,"<== WtBlackBox::bbUserFinalizeProcessing()"<<std::endl);
318   }
319   //==================================================================    
320
321   //==================================================================    
322   /// Callback for creating a Dialog window (modal)
323   void WtBlackBox::bbCreateDialogWindow()
324   {
325           bbtkBlackBoxDebugMessage("widget",3,
326                      "==> WtBlackBox::bbCreateDialogWindow() - No Dialog must be created, it is a web app"
327                      <<std::endl);
328
329   } 
330   //=========================================================================
331
332   //==================================================================    
333
334   //==================================================================    
335   /// Callback for creating a Frame window 
336         void WtBlackBox::bbCreateFrameWindow()
337         {
338
339                 bbtkBlackBoxDebugMessage("widget",3,
340                         "==> WtBlackBox::bbCreateFrameWindow() - parent = "
341                         <<WWt::GetTopWindow()
342                         <<std::endl);
343
344                 //Setting necessary data for Wt server deployment
345                 myWtData.parent = WWt::GetTopWindow();
346                 myWtData.b      = GetThisPointer<WtBlackBox>();
347                 myWtData.title  = std2wt( bbGetInputWinTitle() + " - bbtk (c) CREATIS");
348                 myWtData.pbox   = this;
349                 
350                 //char  *argv[7] =  {"./WtTest","--docroot","/home/gonzalez/Documents/pruebaResources","--http-address","0.0.0.0","--http-port","8080"};
351                 //int argc = 7;
352                 
353 /*              
354                         char  *argv[7] =  {"./WtTest"
355 ,"--docroot",(char*)WtBlackBox::wtServerData::docRoot.c_str()
356 ,"--http-address",(char*)WtBlackBox::wtServerData::address.c_str()
357 ,"--http-port",(char*)WtBlackBox::wtServerData::port.c_str()
358 };
359                 int argc = 3;
360                 std::cout<<" ---  PUERTO  :"<<WtBlackBox::wtServerData::port<<std::endl;
361 */
362
363 /*              
364 char  *argv[2] =  {"./bbiWeb.wt","client"};
365 int argc=2;
366 */
367
368
369         /*      if(Wt::WServer::instance()->isRunning())
370                 {
371                         std::cout<<"Checking the existence of a Server deployed  -DELETE THIS MESSAGE bbtkWTBlackBox.cxx"<<std::endl;
372                         Wt::WServer::instance()->stop();
373                 }
374         */
375
376
377                 std::cout<<"EED WtBlackBox::bbCreateFrameWindow  Deploying Server -- Definition of server parameters by default  -DELETE THIS MESSAGE bbtkWTBlackBox.cxx"<<std::endl;
378
379
380 //              Wt::WRun(argc,argv,&createApplication); 
381
382                 Wt::WRun(WtBlackBox::wtServerData::argc,
383                          WtBlackBox::wtServerData::argv,
384                          &createApplication);   
385
386
387    }
388
389   //==================================================================    
390
391   //==================================================================    
392   void WtBlackBox::bbSetWindow(Wt::WContainerWidget* w) 
393   {
394     bbtkBlackBoxDebugMessage("widget",9,"==> WtBlackBox::bbSetWindow("<<w<<")"<<std::endl);
395     if ((bbmWindow != 0)&&(w!=0)) 
396       { 
397         std::cout << "ERRRRRRRROOOOR"<<std::endl; 
398       }
399     bbmWindow = w;
400   }
401
402         
403
404     //==================================================================    
405
406   //==================================================================
407   void WtBlackBox::bbShowWindow()
408   {
409     if ((bbmWindow) && (!bbIsShown()))
410       {
411         bbtkBlackBoxDebugMessage("widget",3,"==> WtBlackBox::bbShowWindow()"
412                          <<std::endl);
413         if (bbGetInputWinDialog()) 
414           {
415           //  ((WxDialog*)bbmWindow)->ShowModal();
416           }
417         else
418           {
419                 // There is not such a thing like show becouse it is a webapp
420            // bbGetWindow()->Show();
421           //  WWt::CreateWtAppIfNeeded();
422
423
424                 Wt::WRun(WtBlackBox::wtServerData::argc,
425                          WtBlackBox::wtServerData::argv,
426                          &createApplication);   
427
428
429             bbSetShown(true);
430           } 
431       }
432   }
433   //==================================================================    
434
435   //==================================================================    
436   void WtBlackBox::bbDestroyWindow()
437   {
438     bbtkBlackBoxDebugMessage("widget",3,"==> WtBlackBox::bbDestroyWindow("<<bbmWindow<<")"<<std::endl);
439     if (bbGetWindow()!=NULL) 
440       {
441         //       wxWindow* w = bbGetWindow();
442         //bbSetWindow(0);
443         // WE SHOULD DESTROY THE WINDOW WITH THE Close METHOD
444         // HOWEVER I
445         //w->Close(true);
446         //
447         delete bbGetWindow();
448         bbSetShown(false);
449       }
450     bbtkBlackBoxDebugMessage("widget",3,"<== WtBlackBox::bbDestroyWindow("<<bbmWindow<<")"<<std::endl);
451
452   }
453
454
455 //==================================================================    
456         void WtBlackBox::bbwtUpdateInputs()
457         {
458                 BlackBox::bbUpdateInputs();
459         }
460
461 //==================================================================    
462         void WtBlackBox::bbwtProcess()
463         {
464                 BlackBox::bbProcess();
465         }
466
467
468
469 }//namespace bbtk
470
471 #endif
472
473