]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.h
Feature #1366 Increased the line width of bbEditor connections.
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxVtkSceneManager.h
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
33 /**
34  *  \file
35  *  \brief Class bbtk::BlackBox : abstract black-box interface.
36  */
37
38 /****
39  * Design and Developpement of BBTK GEditor
40  * Ricardo A Corredor J <ra.corredor67@uniandes.edu.co>
41  * RaC - 2010
42  ****/
43
44 #ifndef __wxVtkSceneManager_h__
45 #define __wxVtkSceneManager_h__
46
47 //Includes same project
48 #include "GObjectsMVCFactory.h"
49 #include "Observer.h"
50 #include "GBoxModel.h"
51 #include "GComplexBoxPortModel.h"
52 #include "GPortModel.h"
53 #include "vtkGConnectorView.h"
54 #include "GConnectorModel.h"
55 #include "GConnectorController.h"
56 #include "vtkGPortView.h"
57 #include "manualConnectorContourView.h"
58 #include "manualConnectorContourController.h"
59 #include "wxGEditorTabPanel.h"
60
61 //Includes bbtk
62 #include <bbtkBlackBoxInputDescriptor.h>
63 #include <bbtkBlackBoxDescriptor.h>
64
65 //Includes creaMaracasVisu
66 #include <wxVtk3DBaseView.h>
67 #include <InteractorStyleMaracas.h>
68 #include <vtkInteractorStyleBaseView2D.h>
69 #include <manualContourControler.h>
70 #include <manualContourModel.h>
71
72 //Includes vtk
73 #include <vtkRenderWindow.h>
74 #include <vtkRenderWindowInteractor.h>
75 #include <vtkRenderer.h>
76 #include <vtkInteractorStyleImage.h>
77 #include <vtkActor.h>
78 #include <vtkPoints.h>
79 #include <vtkTextActor3D.h>
80 #include <vtkDataSetMapper.h>
81
82
83 //Includes std
84 #include <iostream>
85 #include <string>
86 #include <sstream>
87 #include <map>
88
89
90 namespace bbtk
91 {
92         class wxGEditorTabPanel;
93
94         class wxVtkSceneManager : public InteractorStyleMaracas , public Observer
95         {
96         public:
97
98                 wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager);
99                 ~wxVtkSceneManager();
100                 void disconnectDrop();
101
102                 //-------
103                 void configureBaseView();
104                 void registerController(InteractorStyleMaracas *param);
105                 void unregisterController(InteractorStyleMaracas *param);
106
107                 virtual bool OnChar();
108                 virtual bool OnMouseMove();
109                 virtual bool OnLeftButtonDown();
110                 virtual bool OnLeftButtonUp();
111                 virtual bool OnRightButtonUp();
112                 virtual bool OnLeftDClick();
113                 virtual bool OnMiddleButtonDown(); ///JLGR 21-05-2012
114                 virtual bool OnMiddleButtonUp(); ///JLGR 21-05-2012
115
116                 //-------
117                 int createGBlackBox(int x, int y, std::string packageName, std::string boxType );
118                 int createGComplexBoxInputPort(std::string inputName);
119                 int createGComplexBoxOutputPort(std::string outputName);
120                 GPortController* createGPort(int portType, std::string bbtkName, std::string bbtkType, int posinBox,GBoxModel *blackBox);
121                 int createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc);
122                 int createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc);
123                 int createGConnector(GPortModel* startPort);
124
125                 void configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn);
126                 int configGConnetion( std::string nameStartBox, std::string  nameStartPort, std::string
127                                                           nameEndBox, std::string  nameEndPort);
128                 void configGComBoxInputOutputPort(bool inputoutput, std::string inputPortName, double xIn, double yIn,double zIn);
129                 GBoxModel* findGBox(std::string boxname);
130
131     class wxVtkSceneManager : public InteractorStyleMaracas, public Observer {
132     public:
133
134         wxVtkSceneManager( wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager );
135         ~ wxVtkSceneManager( );
136         void disconnectDrop( );
137
138         //-------
139         void configureBaseView( );
140         void registerController( InteractorStyleMaracas *param );
141         void unregisterController( InteractorStyleMaracas *param );
142
143         virtual bool OnChar( );
144         virtual bool OnMouseMove( );
145         virtual bool OnLeftButtonDown( );
146         virtual bool OnLeftButtonUp( );
147         virtual bool OnRightButtonUp( );
148         virtual bool OnLeftDClick( );
149
150         //-------
151         int createGBlackBox( int x, int y, std::string packageName, std::string boxType );
152         int createGComplexBoxInputPort( std::string inputName );
153         int createGComplexBoxOutputPort( std::string outputName );
154         GPortController* createGPort( int portType, std::string bbtkName, std::string bbtkType, int posinBox, GBoxModel *blackBox );
155         int createGInputPort( int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc );
156         int createGOutputPort( int portType, int posinBox, GBoxModel *blackBox, BlackBoxOutputDescriptor *desc );
157         int createGConnector( GPortModel* startPort );
158
159         void configGBlackBox( int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable, double xEn, double yEn, double zEn );
160         int configGConnetion( std::string nameStartBox, std::string nameStartPort, std::string
161         nameEndBox, std::string nameEndPort );
162         void configGComBoxInputOutputPort( bool inputoutput, std::string inputPortName, double xIn, double yIn, double zIn );
163         GBoxModel* findGBox( std::string boxname );
164
165         vtkRenderWindow* getRenderWindow( );
166         vtkRenderer* getRenderer( );
167
168         virtual void update( int idController, int command );
169
170         void refresh( );
171         void refreshScene( );
172         void displayBlackBoxInfo( std::string packageName, std::string boxName );
173         void updateStatusBar( std::string textStatus );
174
175         //-------
176         //Get a collection of object ids
177         std::vector<int> getBlackBoxes( );
178         std::vector<int> getConnections( );
179         std::vector<int> getComplexInputPorts( );
180         std::vector<int> getComplexOutputPorts( );
181
182         //Get the map of selected objects (id, controller)
183         std::map<int, GObjectController*> getSelectedObjects( );
184
185         //Get size of selected objects map
186         int getNumSelectedObjects( );
187
188         //Complex box edition mode
189         bool isComplexBox( );
190         void setComplexBox( bool val );
191
192         //-------
193         //Add an object to the list of controllers
194         int addObjectController( GObjectController* objController );
195
196         //Add a map of object controllers
197         void addObjects( std::map<int, GObjectController*> objectsMap );
198
199
200         //-------
201         //Returns a string with the BBS script of the current diagram.
202         std::string getDiagramBBS( bool wln = false );
203
204
205                 vtkRenderWindow* getRenderWindow();
206                 vtkRenderer* getRenderer();
207
208                 virtual void update(int idController,int command);
209
210                 void refresh();
211                 void refreshScene();
212                 void displayBlackBoxInfo(std::string packageName, std::string boxName);
213                 void updateStatusBar(std::string textStatus);
214
215                 //-------
216                 //Get a collection of object ids
217                 std::vector<int> getBlackBoxes();
218                 std::vector<int> getConnections();
219                 std::vector<int> getComplexInputPorts();
220                 std::vector<int> getComplexOutputPorts();
221
222                 //Get the map of selected objects (id, controller)
223                 std::map<int,GObjectController*> getSelectedObjects();
224
225                 //Get size of selected objects map
226                 int getNumSelectedObjects();
227
228                 //Complex box edition mode
229                 bool isComplexBox();
230                 void setComplexBox(bool val);
231
232                 //-------
233                 //Add an object to the list of controllers
234                 int addObjectController(GObjectController* objController);
235
236                 //Add a map of object controllers
237                 void addObjects(std::map<int,GObjectController*> objectsMap);
238
239                 /// Duplicates Objects to current a diagram
240                 void DuplicateObjects(std::map<int,GObjectController*> objectsMap);///JLGR 21-05-2012
241
242                 //-------
243                 // Makes a BlackBox Executable
244                 bool MakeBoxExecutable();//DFCH
245                 //-------
246                 //Returns a string with the BBS script of the current diagram.
247                 std::string getDiagramBBS(bool wln=false);
248
249
250         void AddControlerToBeRemove( std::vector<int> *controllersToRemove, int id );
251
252         //Clear list of controllers and refresh
253         void deleteAllBoxes( );
254
255         //Save the diagram in the BBG format, in the string given by param.
256         void saveDiagram( std::string &content );
257
258         //Load the diagram
259         void loadDiagram( ifstream &inputStream );
260
261         //Center the view of the camera in the initial position
262         void centerView( );
263
264                 //Load the diagram
265                 void loadDiagram(std::stringstream &inputStream);
266
267
268         void SetCbName( std::string cbNane );
269         void SetCbPackageName( std::string packagename );
270         void SetAuthor( std::string author );
271         void SetCategory( std::string category );
272         void SetDescription( std::string description );
273
274         std::string GetCbName( );
275         std::string GetCbPackageName( );
276         std::string GetAuthor( );
277         std::string GetCategory( );
278         std::string GetDescription( );
279         
280         
281
282         // JGRR & CM
283         void printAll( int com, int sta );
284
285         
286
287     private:
288
289         std::string _cbName;
290         std::string _cbPackageName;
291         std::string _Author;
292         std::string _Category;
293         std::string _Description;
294
295         //wxPanel that uses the manager
296         wxGEditorTabPanel *_parent;
297
298         // Id of the manager, the same of the panel
299         int _idManager;
300
301         // Boxes number in the scene
302         int _numBoxes;
303
304         // StartDragging
305         bool _startDragging;
306
307         // creaMaracasVisu viewer
308         wxVtk3DBaseView *_baseView;
309
310         // State of the 3D Scene or the virtual world
311         int _worldState;
312
313         //Map of id - objectController
314         std::map<int, GObjectController*> _controllers;
315
316         //Saves the id's of the selected objects in the controllers map
317         std::vector<int> _selectedObjects;
318
319         //Is the diagram in state complex box
320         bool _isComplexBox;
321
322         int _idConnectionInCreation;
323
324         int _contLastId;
325
326         vtkTextActor3D *_textActor;
327         vtkPoints *_pts;
328         vtkActor *_fillObjectActor;
329         vtkDataSetMapper *_aPolygonMapper;
330
331         std::string LineNumber( bool withLineNumber, int &value );
332         int GetIndexInSelected( int idControler );
333         void UnSelectBlackBoxes( );
334         GObjectController *GetGBlackBoxControlerPointedByMouse( );
335         void CancelConnection( );
336
337     protected:
338
339     };
340
341
342 }
343 // namespace bbtk
344 #endif
345