]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.cxx
Feature #1347
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxGEditorTabPanel.cxx
1 /*=========================================================================
2 Program:   bbtk
3 Module:    $RCSfile$
4 Language:  C++
5 Date:      $Date$
6 Version:   $Revision$
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and
15 *  abiding by the rules of distribution of free software. You can  use,
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B
17 *  license as circulated by CEA, CNRS and INRIA at the following URL
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability.
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
30
31 /**
32 *  \file
33 *  \brief Class bbtk::wxGEditorTabPanel .
34 */
35
36
37 #include "wxGEditorTabPanel.h"
38 #include "creaWx.h"
39
40 namespace bbtk
41 {
42
43         //=========================================================================
44         wxGEditorTabPanel::wxGEditorTabPanel()
45         {
46                 printf ("EED %p wxGEditorTabPanel 1 ()\n" , this );
47         }
48
49         //=========================================================================
50         wxGEditorTabPanel::wxGEditorTabPanel(wxWindow *parent,int id):wxPanel(parent),wxTextDropTarget()
51         {
52 printf("EED wxGEditorTabPanel::wxGEditorTabPanel 0\n");
53                 printf ("EED %p wxGEditorTabPanel 2 ()\n" , this );
54                 _id=id;
55                 _panelAUIMgr = new wxAuiManager(this);
56                 _sceneManager = NULL;
57                 _actualdo = states.begin();
58                 initWxVtkCanvas();
59 printf("EED wxGEditorTabPanel::wxGEditorTabPanel 1\n");
60         }
61
62         //=========================================================================
63         wxGEditorTabPanel::~wxGEditorTabPanel()
64         {
65 printf ("EED %p ~wxGEditorTabPanel()\n" , this );
66 //ED02JUIN2010          _sceneManager->disconnectDrop();
67
68         _panelsManager->VerifyLastTabPanel();
69                 //FCY memory leaks
70                 delete _panelAUIMgr;
71                 delete _sceneManager;
72
73         }
74
75         //=========================================================================
76         void wxGEditorTabPanel::initWxVtkCanvas()
77         {
78 printf("EED wxGEditorTabPanel::initWxVtkCanvas 0\n");
79                 wxVtk3DBaseView *baseview = new wxVtk3DBaseView(this);
80                 baseview->Configure();
81                 _sceneManager=new wxVtkSceneManager(this,baseview,_id);
82
83
84 //EED02JUIN2010
85                 printf("RaC-EED 21-06-2010 wxGEditorTabPanel::initWxVtkCanvas Remove the panelAUIMgr, and change to a normal sizer inside the wxGEditorTabPanel\n");
86                 _panelAUIMgr->AddPane((wxWindow*)baseview->GetWxVTKRenderWindowInteractor(),wxAuiPaneInfo().Fixed().CenterPane());
87
88                 _panelAUIMgr->Update();
89 printf("EED wxGEditorTabPanel::initWxVtkCanvas 1\n");
90         }
91
92         //=========================================================================
93
94         bool wxGEditorTabPanel::OnDropText(wxCoord x, wxCoord y, const wxString& data)
95         {
96                 std::string packageName="";
97                 std::string boxType="";
98
99                 wxString foo( (data) );
100                 char str[150];
101                 strcpy( str, (const char*)foo.mb_str(wxConvUTF8) );
102
103                 char delims[] = ":";
104                  char *result = NULL;
105                  result = strtok( str, delims );
106                  packageName += result;
107
108                  result = strtok( NULL, delims );
109                  boxType += result;
110
111                 _sceneManager->createGBlackBox(x,y,packageName, boxType);
112
113           return true;
114         }
115
116         //=========================================================================
117
118         void wxGEditorTabPanel::setPanelsManager(wxTabPanelsManager* panelsManager)
119         {
120                 _panelsManager = panelsManager;
121         }
122
123         //=========================================================================
124
125         void wxGEditorTabPanel::displayBlackBoxInfo(std::string packageName, std::string boxName)
126         {
127                 _panelsManager->displayBlackBoxInfo(packageName,boxName);
128         }
129
130         //=========================================================================
131
132         void wxGEditorTabPanel::updateStatusBar(std::string textStatus)
133         {
134                 _panelsManager->updateStatusBar(textStatus);
135         }
136
137         //=========================================================================
138
139         std::string wxGEditorTabPanel::getDiagramBBS(bool wln)
140         {
141                 return _sceneManager->getDiagramBBS(wln);
142         }
143
144         //=========================================================================
145
146         std::string wxGEditorTabPanel::saveComplexBoxBBS()
147         {
148                 return _sceneManager->saveComplexBoxBBS();
149         }
150
151         //=========================================================================
152
153         void wxGEditorTabPanel::editBlackBox(GBlackBoxModel *bbmodel)
154         {
155                 _panelsManager->editBlackBox(bbmodel);
156         }
157
158         //=========================================================================
159
160         void wxGEditorTabPanel::deleteAllBoxes()
161         {
162                 _sceneManager->deleteAllBoxes();
163         }
164
165         //=========================================================================
166
167         void wxGEditorTabPanel::centerView()
168         {
169                 if(_sceneManager)
170                 {
171                         _sceneManager->centerView();
172                 }
173         }
174
175         //=========================================================================
176
177         void wxGEditorTabPanel::saveDiagram(std::string &content, const std::string &path) //DFCH
178         {
179                 this->SetFullPath(path);
180                 _sceneManager->saveDiagram(content);
181         }
182
183         //=========================================================================
184
185         void wxGEditorTabPanel::saveTempDiagram() //FCY
186         {
187                 std::string content = "";
188                 // writing file header
189                 content += "# ----------------------------------\n";
190                 content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
191                 content += "# - ";
192                 content += "temp";
193                 content += "\n";
194                 content += "# ----------------------------------\n";
195                 content += "\n";
196                 content += "APP_START\n";
197                 _sceneManager->saveDiagram(content);
198                 content += "APP_END\n"; //put here to avoid mistakes
199                 if(_actualdo == states.end() ) // same size, write to the end
200                 {
201                         states.push_back (content);
202                 }
203                 else
204                 {
205                         std::vector<std::string>::iterator it = _actualdo+1;
206                         states.erase(it, states.end());
207                         states.push_back(content);
208                 }
209                 _actualdo = states.end();
210                         
211         }
212
213         //=========================================================================
214
215         void wxGEditorTabPanel::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
216         {
217                 this->SetFullPath(path);
218                 stringstream ss;
219                 ss << inputStream ;
220                 _sceneManager->loadDiagram(ss);
221         }
222
223         //=========================================================================
224         unsigned short wxGEditorTabPanel::loadTempDiagram(unsigned short un) //FCY
225         {
226                 unsigned short res = 1;
227                 deleteAllBoxes();
228                 std::stringstream ss;
229                 if (un == 0) //undo
230                 {
231                         if(_actualdo == states.end() ) // same size, write to the end
232                         {
233                                 (_actualdo--);
234                         }
235                         if(_actualdo != states.begin() )
236                         {
237                                 ss << *(--_actualdo);
238                         }
239                         else
240                         {
241                                 ss << *_actualdo;
242                                 res = 0;
243                         }
244                 }
245                 else //redo
246                 {
247                         _actualdo++;
248                         if(_actualdo != states.end())
249                         {
250                                 ss << *_actualdo;
251                         }
252                         else
253                         {
254                                 res = 0;
255                         }
256                 }
257                 _sceneManager->loadDiagram(ss);
258                 return res;
259         }
260         
261         //=========================================================================
262
263         int wxGEditorTabPanel::getPanelId()
264         {
265                 return _id;
266         }
267
268         //=========================================================================
269
270         bool wxGEditorTabPanel::isComplexBox()
271         {
272                 return _sceneManager->isComplexBox();
273         }
274
275         //=========================================================================
276
277         void wxGEditorTabPanel::setComplexBox(bool val)
278         {
279                 _sceneManager->setComplexBox(val);
280         }
281
282         //=========================================================================
283
284         void wxGEditorTabPanel::addComplexInputPort(std::string portName)
285         {
286                 _sceneManager->createGComplexBoxInputPort(portName);
287         }
288
289         //=========================================================================
290
291         void wxGEditorTabPanel::addComplexOutputPort(std::string portName)
292         {
293                 _sceneManager->createGComplexBoxOutputPort(portName);
294         }
295
296         //=========================================================================
297
298         std::map<int,GObjectController*> wxGEditorTabPanel::getSelectedObjects()
299         {
300                 return _sceneManager->getSelectedObjects();
301         }
302
303         //=========================================================================
304
305         void wxGEditorTabPanel::addObjects(std::map<int,GObjectController*> objectsMap)
306         {
307                 _sceneManager->addObjects(objectsMap);
308         }
309
310         //=========================================================================
311
312         int wxGEditorTabPanel::getNumSelectedObjects()
313         {
314                 return _sceneManager->getNumSelectedObjects();
315         }
316
317         //=========================================================================
318
319
320         wxVtkSceneManager* wxGEditorTabPanel::getSceneManager()
321         {
322                 return _sceneManager;
323         }
324
325         //=========================================================================
326     std::string wxGEditorTabPanel::GetCbName()
327         {
328             return _sceneManager->GetCbName();
329         }
330
331
332         //=========================================================================
333     std::string wxGEditorTabPanel::GetCbPackageName()
334         {
335             return _sceneManager->GetCbPackageName();
336         }
337
338         //=========================================================================
339     std::string wxGEditorTabPanel::GetAuthor()
340         {
341             return _sceneManager->GetAuthor();
342         }
343
344         //=========================================================================
345     std::string wxGEditorTabPanel::GetDescription()
346         {
347             return _sceneManager->GetDescription();
348         }
349
350         //=========================================================================
351     std::string wxGEditorTabPanel::GetCategory()
352         {
353             return _sceneManager->GetCategory();
354         }
355
356         //=========================================================================
357     void wxGEditorTabPanel::SetCbName(std::string cbName)
358     {
359         _sceneManager->SetCbName( cbName );
360     }
361
362         //=========================================================================
363     void wxGEditorTabPanel::SetCbPackageName(std::string packagename)
364     {
365         _sceneManager->SetCbPackageName( packagename );
366     }
367
368
369         //=========================================================================
370     void wxGEditorTabPanel::SetAuthor(std::string author)
371     {
372         _sceneManager->SetAuthor( author );
373     }
374
375
376         //=========================================================================
377     void wxGEditorTabPanel::SetCategory(std::string category)
378     {
379         _sceneManager->SetCategory( category );
380     }
381
382
383         //=========================================================================
384     void wxGEditorTabPanel::SetDescription(std::string description)
385     {
386         _sceneManager->SetDescription( description );
387     }
388     //=========================================================================
389         //DFCH
390         void wxGEditorTabPanel::SetFullPath( const std::string& fullpath )
391         {
392                 this->_fullPath = fullpath;
393         }
394         //=========================================================================
395         //DFCH
396         void wxGEditorTabPanel::SetFileName( const std::string& filename )
397         {
398                 this->_fileName = filename;
399         }
400         //=========================================================================
401         //DFCH
402         std::string wxGEditorTabPanel::GetFullPath( )
403         {
404                 return( this->_fullPath );
405         }
406         //=========================================================================
407         //DFCH
408     std::string wxGEditorTabPanel::GetFileName( )
409     {
410                 return( this->_fileName );
411         }
412
413
414
415
416 }  // EO namespace bbtk
417
418 // EOF