2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkWxBlackBox.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.45 $
34 =========================================================================*/
45 #include "bbtkWtBlackBox.h"
46 #include "bbtkBlackBoxOutputConnector.h"
49 //#include "bbtkWxContainerBlackBox.h"
50 //#include <wx/dialog.h>
52 //#include "bbtkData.h"
53 //#include "bbtkFactory.h"
57 //=========================================================================
59 //=========================================================================
62 Wt::WContainerWidget *parent;
63 WtBlackBox::Pointer b;
67 static wtData myWtData;
68 //=========================================================================
70 //=========================================================================
71 // Application WT deployed
72 //==================================================================
76 class WtWFrame : public Wt::WApplication
80 const Wt::WEnvironment& env
86 WtBlackBox::WeakPointer mBox;
93 const Wt::WEnvironment& env
102 std::cout<<" SIN PADRE "<<std::endl;
103 if(myWtData.parent == 0){std::cout<<" PARENT 0 "<<std::endl;}
104 if(myWtData.parent == NULL){std::cout<<" PARENT NULL "<<std::endl;}
105 myWtData.parent = new Wt::WContainerWidget();
106 std::cout<<"Parent created -- DELETE ME -- bbtkWtBlackBox.cxx"<<std::endl;
109 Wt::WContainerWidget *myCont = new Wt::WContainerWidget(myWtData.parent);
110 myCont->setMinimumSize(800,500);
111 std::cout<<"Creando WebWIDGET DELETE ME ---- bbtkWtBlackBox.cxx.................50%"<<std::endl;
112 myWtData.b->bbUserCreateWidget(myCont);
113 root()->addWidget(myWtData.parent);
114 //bbmWindow = myCont;
115 std::cout<<"Creando WebWIDGET DELETE ME ---- bbtkWtBlackBox.cxx.................80%"<<std::endl;
119 //==================================================================
120 //==================================================================
121 WtWFrame::~WtWFrame()
124 bbtkDebugMessage("widget",9,"["<<mBox.lock()->bbGetName()
125 <<"] $$$$$$$$$$$$$$$$$$$ ~W()"
128 bbtkDebugMessage("widget",9,"[DEAD] $$$$$$$$$$$$$$$$$$$$$ ~WtContainer()"<<std::endl);
129 bbtkDebugMessage("widget",9,"WtWFrame::~WtWFrame()"<<std::endl);
130 if (mBox.lock()) mBox.lock()->bbSetWindow(0);
131 WWt::DecNbWindowsAlive();
137 Wt::WApplication *createApplication(const Wt::WEnvironment& env)
139 return new WtWFrame(env);
143 //=========================================================================
144 // WxDialogWxBlackBox::Pointer box
145 //=========================================================================
147 //==================================================================
148 // Dialog window which is modal
149 /* class BBTK_EXPORT WxDialog : public wxDialog
152 WxDialog(WxBlackBox::Pointer box,
156 ~WxDialog();Wt::GetTopWindow()
157 void OnCloseWindow(wxCloseEvent& event);
160 WxBlackBox::WeakPointer mBox;
161 DECLARE_EVENT_TABLE();
165 BEGIN_EVENT_TABLE(WxDialog, wxDialog)
166 EVT_CLOSE(WxDialog::OnCloseWindow)
168 //=========================================================================
170 //=========================================================================
171 WxDialog::WxDialog(WxBlackBox::Pointer b,
190 bbtkDebugMessage("widget",9,"WxDialog::WxDialog ["<<b->bbGetName()<<"]"
191 <<std::endl);WxBlackBox::Pointer box
192 Wx::IncNbWindowsAlive();
193 b->bbSetWindow(this);
194 // Insert the widget into the window
195 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
196 b->bbUserCreateWidget(this);
197 wxWindow* widget = b->bbGetOutputWidget();
198 sizer->Add( widget, 1, wxALL|wxGROW, 2);
202 //==================================================================
203 //==================================================================
204 WxDialog::~WxDialog()
206 bbtkDebugMessage("widget",9,"WxDialog::~WxDialog()"<<std::endl);
207 //bbtkDebugMessage("widget",9,"WxFrame::~WxFrame()"<<std::endl);
208 // if (mBox.lock()) mBox.lock()->bbSetWindow(0);
209 // Wx::DecNbWindowsAlive();
211 //==================================================================
212 //==================================================================
213 void WxDialog::OnCloseWindow(wxCloseEvent& event)
215 bbtkDebugMessage("widget",9,"WxDialog::OnCloseWindow()"<<std::endl);
216 if (mBox.lock()) mBox.lock()->bbSetWindow(0);
217 Wx::DecNbWindowsAlive();
220 //==================================================================
223 //=========================================================================
225 //=========================================================================
227 //=========================================================================
228 //=========================================================================
229 //=========================================================================
230 //=========================================================================
231 BBTK_BLACK_BOX_IMPLEMENTATION(WtBlackBox,WidgetBlackBox<Wt::WContainerWidget>);
233 //=========================================================================
234 //=========================================================================
235 void WtBlackBox::bbUserSetDefaultValues()
237 bbtkBlackBoxDebugMessage("widget",5,"WtBlackBox::bbUserSetDefaultValues()"<<std::endl);
240 //=========================================================================
242 //=========================================================================
243 void WtBlackBox::bbUserInitializeProcessing()
247 //================================================================http://intranet-if.insa-lyon.fr/temps/5IF39.html==
249 //=========================================================================
250 void WtBlackBox::bbUserFinalizeProcessing()
252 bbtkBlackBoxDebugMessage("widget",5,"==> WtBlackBox::bbUserFinalizeProcessing()"<<std::endl);
254 bbtkBlackBoxDebugMessage("widget",5,"<== WtBlackBox::bbUserFinalizeProcessing()"<<std::endl);
256 //==================================================================
258 //==================================================================
259 /// Callback for creating a Dialog window (modal)
260 void WtBlackBox::bbCreateDialogWindow()
262 bbtkBlackBoxDebugMessage("widget",3,
263 "==> WtBlackBox::bbCreateDialogWindow() - No Dialog must be created, it is a web app"
267 //=========================================================================
269 //==================================================================
271 //==================================================================
272 /// Callback for creating a Frame window
273 void WtBlackBox::bbCreateFrameWindow()
276 bbtkBlackBoxDebugMessage("widget",3,
277 "==> WtBlackBox::bbCreateFrameWindow() - parent = "
278 <<WWt::GetTopWindow()
281 //Setting necessary data for Wt server deployment
282 myWtData.parent = WWt::GetTopWindow();
283 myWtData.b = GetThisPointer<WtBlackBox>();
284 myWtData.title = std2wt( bbGetInputWinTitle()
285 + " - bbtk (c) CREATIS");
287 std::cout<<"Creating Container WT -- Definition of server parameters by default -DELETE THIS MESSAGE bbtkWTBlackBox.cxx"<<std::endl;
288 char *argv[7] = {"./WtTest","--docroot","/home/gonzalez/Documents/pruebaResources","--http-address","0.0.0.0","--http-port","8080"};
290 /* if(Wt::WServer::instance()->isRunning())
292 std::cout<<"Checking the existence of a Server deployed -DELETE THIS MESSAGE bbtkWTBlackBox.cxx"<<std::endl;
293 Wt::WServer::instance()->stop();
296 std::cout<<"Deploying Server -- Definition of server parameters by default -DELETE THIS MESSAGE bbtkWTBlackBox.cxx"<<std::endl;
297 Wt::WRun(argc,argv,&createApplication);
300 //==================================================================
302 //==================================================================
303 void WtBlackBox::bbSetWindow(Wt::WContainerWidget* w)
305 bbtkBlackBoxDebugMessage("widget",9,"==> WtBlackBox::bbSetWindow("<<w<<")"<<std::endl);
306 if ((bbmWindow != 0)&&(w!=0))
308 std::cout << "ERRRRRRRROOOOR"<<std::endl;
315 //==================================================================
317 //==================================================================
318 void WtBlackBox::bbShowWindow()
320 if ((bbmWindow) && (!bbIsShown()))
322 bbtkBlackBoxDebugMessage("widget",3,"==> WtBlackBox::bbShowWindow()"
324 if (bbGetInputWinDialog())
326 // ((WxDialog*)bbmWindow)->ShowModal();
330 // There is not such a thing like show becouse it is a webapp
331 // bbGetWindow()->Show();
332 // WWt::CreateWtAppIfNeeded();
337 //==================================================================
339 //==================================================================
340 void WtBlackBox::bbDestroyWindow()
342 bbtkBlackBoxDebugMessage("widget",3,"==> WtBlackBox::bbDestroyWindow("<<bbmWindow<<")"<<std::endl);
343 if (bbGetWindow()!=NULL)
345 // wxWindow* w = bbGetWindow();
347 // WE SHOULD DESTROY THE WINDOW WITH THE Close METHOD
351 delete bbGetWindow();
354 bbtkBlackBoxDebugMessage("widget",3,"<== WtBlackBox::bbDestroyWindow("<<bbmWindow<<")"<<std::endl);
357 //==================================================================