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