]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.h
#3057 bbGEditor Feature New Normal - optimizing of vtk actors management (input...
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxVtkSceneManager.h
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 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------  
24 */
25
26 /*=========================================================================
27 Program:   bbtk
28 Module:    $RCSfile$
29 Language:  C++
30 Date:      $Date$
31 Version:   $Revision$
32 =========================================================================*/
33
34 /* ---------------------------------------------------------------------
35
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
38 *
39 *  This software is governed by the CeCILL-B license under French law and
40 *  abiding by the rules of distribution of free software. You can  use,
41 *  modify and/ or redistribute the software under the terms of the CeCILL-B
42 *  license as circulated by CEA, CNRS and INRIA at the following URL
43 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44 *  or in the file LICENSE.txt.
45 *
46 *  As a counterpart to the access to the source code and  rights to copy,
47 *  modify and redistribute granted by the license, users are provided only
48 *  with a limited warranty  and the software's author,  the holder of the
49 *  economic rights,  and the successive licensors  have only  limited
50 *  liability.
51 *
52 *  The fact that you are presently reading this means that you have had
53 *  knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */
55
56
57
58 /**
59 *  \file
60 *  \brief Class bbtk::BlackBox : abstract black-box interface.
61 */
62
63 /****
64 * Design and Developpement of BBTK GEditor
65 * Ricardo A Corredor J <ra.corredor67@uniandes.edu.co>
66 * RaC - 2010
67 ****/
68
69 #ifndef __wxVtkSceneManager_h__
70 #define __wxVtkSceneManager_h__
71
72 //Includes same project
73 #include "GObjectsMVCFactory.h"
74 #include "Observer.h"
75 #include "GBoxModel.h"
76 #include "GComplexBoxPortModel.h"
77 #include "GPortModel.h"
78 #include "vtkGConnectorView.h"
79 #include "GConnectorModel.h"
80 #include "GConnectorController.h"
81 #include "vtkGPortView.h"
82 #include "manualConnectorContourView.h"
83 #include "manualConnectorContourController.h"
84 #include "wxGEditorTabPanel.h"
85
86 //Includes bbtk
87 #include <bbtkBlackBoxInputDescriptor.h>
88 #include <bbtkBlackBoxDescriptor.h>
89
90 //Includes creaMaracasVisu
91 #include <wxVtk3DBaseView.h>
92 #include <InteractorStyleMaracas.h>
93 #include <vtkInteractorStyleBaseView2D.h>
94 #include <manualContourControler.h>
95 #include <manualContourModel.h>
96
97 //Includes vtk
98 #include <vtkRenderWindow.h>
99 #include <vtkRenderWindowInteractor.h>
100 #include <vtkRenderer.h>
101 #include <vtkInteractorStyleImage.h>
102 #include <vtkActor.h>
103 #include <vtkPoints.h>
104 #include <vtkTextActor3D.h>
105  #include <vtkDataSetMapper.h>
106
107
108 //Includes std
109 #include <iostream>
110 #include <string>
111 #include <sstream>
112 #include <map>
113
114 namespace bbtk
115 {
116         class wxGEditorTabPanel;
117
118         class wxVtkSceneManager : public InteractorStyleMaracas , public Observer
119         {
120         public:
121                 
122 //EED 15 oct 2012               wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager);
123                 wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory);
124                 
125                 ~wxVtkSceneManager();
126                 void disconnectDrop();
127
128                 //-------
129                 void configureBaseView();
130                 void registerController(InteractorStyleMaracas *param);
131                 void unregisterController(InteractorStyleMaracas *param);
132
133                 virtual bool OnChar();
134                 virtual bool OnMouseMove();
135                 virtual bool OnLeftButtonDown();
136                 virtual bool OnLeftButtonUp();
137                 virtual bool OnRightButtonUp();
138                 virtual bool OnLeftDClick();
139         virtual bool OnMiddleButtonDown(); ///JLGR 21-05-2012
140         virtual bool OnMiddleButtonUp(); ///JLGR 21-05-2012
141
142                 //-------
143                 int createGBlackBox(int x, int y, std::string packageName, std::string boxType );
144                 int createGComplexBoxInputPort(std::string inputName);
145                 int createGComplexBoxOutputPort(std::string outputName);
146                 GPortController* createGPort(int portType, std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posinBox,GBoxModel *blackBox);
147                 int createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc);
148                 int createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc);
149                 int createGConnector(GPortModel* startPort);
150
151                 void configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn);
152                 int configGConnetion( std::string nameStartBox, std::string  nameStartPort, std::string nameEndBox, std::string  nameEndPort);
153                 void configGComBoxInputOutputPort(bool inputoutput, std::string inputPortName, double xIn, double yIn,double zIn);
154                 GBoxModel* findGBox(std::string boxname);
155
156
157
158                 vtkRenderWindow* getRenderWindow();
159                 vtkRenderer*     getRenderer();
160
161                 virtual void update(int idController,int command);
162
163                 void refresh();
164                 void refreshScene();
165                 void displayBlackBoxInfo(std::string packageName, std::string boxName);
166                 void updateStatusBar(std::string textStatus);
167
168                 //-------
169                 //Get a collection of object ids
170                 std::vector<int> getBlackBoxes();
171                 std::vector<int> getConnections();
172                 std::vector<int> getComplexInputPorts();
173                 std::vector<int> getComplexOutputPorts();
174
175                 //Get the map of selected objects (id, controller)
176                 std::map<int,GObjectController*> getSelectedObjects();
177
178                 //Get size of selected objects map
179                 int getNumSelectedObjects();
180
181                 //Complex box edition mode
182                 bool isComplexBox();
183                 void setComplexBox(bool val);
184
185                 //-------
186                 //Add an object to the list of controllers
187                 int addObjectController(GObjectController* objController);
188
189                 //Add a map of object controllers
190                 void addObjects(std::map<int,GObjectController*> objectsMap);
191
192                 /// Duplicates Objects to current a diagram
193         void DuplicateObjects(std::map<int,GObjectController*> objectsMap);///JLGR 21-05-2012
194
195                 //-------
196                 // Makes a BlackBox Executable
197                 bool MakeBoxExecutable();//DFCH
198                 //-------
199                 //Returns a string with the BBS script of the current diagram.
200                 std::string getDiagramBBS(bool wln=false);
201
202                 //Returns a string with the BBS script of the complex box.
203                 std::string saveComplexBoxBBS();
204
205                 //Delete the object in the list of controllers with the id given by parameter.
206                 bool deleteObject(int id);
207
208                 void AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id);
209
210                 //Clear list of controllers and refresh
211                 void deleteAllBoxes();
212
213                 //Save the diagram in the BBG format, in the string given by param.
214                 void saveDiagram(std::string &content);
215
216                 //Load the diagram
217                 void loadDiagram(std::stringstream &inputStream);
218
219                 //Center the view of the camera in the initial position
220                 void centerView();
221
222                 bool boxExist(std::string boxname);
223                 std::string generateANewNameForABox();
224                 std::string findANewNameForABox();
225                 //-------
226
227         void SetCbName(std::string cbNane);
228         void SetCbPackageName(std::string packagename);
229         void SetAuthor(std::string author);
230         void SetCategory(std::string category);
231         void SetDescription(std::string description);
232                                 void SetMessageKind(std::string kind);
233                                 void SetMessageLevel(std::string Level);
234
235         std::string GetCbName();
236         std::string GetCbPackageName();
237         std::string GetAuthor();
238         std::string GetCategory();
239         std::string GetDescription();
240                                 std::string GetMessageKind();
241         std::string GetMessageLevel();
242   
243         // RaC2012 2nd HackFest
244         // External Inputs was the complex inputs in previous versions
245         // Get names of all external inputs
246         std::vector< std::string> GetExternalInputsNames();
247                 void getCleanLine(std::stringstream &inputStream, std::string &line);
248                 
249         // JGRR & CM
250         void printAll( int com, int sta );
251
252                 
253                 std::vector<std::string> boxesDiagram;//CFT
254
255         private:
256
257         std::string                         _cbName;
258         std::string                         _cbPackageName;
259         std::string                         _Author;
260         std::string                         _Category;
261         std::string                         _Description;
262                 std::string                                     _MessageKind;
263                 std::string                                     _MessageLevel;
264
265                 //wxPanel that uses the manager
266                 wxGEditorTabPanel                                       *_parent;
267
268                 // Id of the manager, the same of the panel
269                 int                                                                     _idManager;
270
271                 // Boxes number in the scene
272                 int                                                                     _numBoxes;
273
274                 // StartDragging
275                 bool                                                            _startDragging;
276
277                 // creaMaracasVisu viewer
278                 wxVtk3DBaseView                                         *_baseView;
279
280                 // State of the 3D Scene or the virtual world
281                 int _worldState;
282
283                 //Map of id - objectController
284                 std::map<int,GObjectController*>        _controllers;
285
286                 //Saves the id's of the selected objects in the controllers map
287                 std::vector<int>                                        _selectedObjects;
288
289                 //Is the diagram in state complex box
290                 bool                                                            _isComplexBox;
291
292                 int                                                                     _idConnectionInCreation;
293
294                 int _contLastId;
295
296                 vtkTextActor3D                                          *_textActor;
297                 std::string                                                     _bugTextActor_text;
298                 int                                                                     _bugTextActor_status;
299
300                 vtkPoints                                                       *_pts;
301                 vtkActor                                                        *_fillObjectActor;
302                 vtkDataSetMapper                                        *_aPolygonMapper;
303
304                 Factory::Pointer                                        _bbtkfactory;
305                 
306                 
307         std::string LineNumber(bool withLineNumber, int &value);
308         int GetIndexInSelected(int idControler);
309         void UnSelectBlackBoxes();
310         GObjectController *GetGBlackBoxControlerPointedByMouse();
311                 void CancelConnection();
312                 
313
314         protected:
315
316         };
317
318
319 }
320 // namespace bbtk
321 #endif
322