]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.h
e44720c24f13a4049402bddbdb1a41bb7adc4339
[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 <map>
86
87
88 namespace bbtk
89 {
90         class wxGEditorTabPanel;
91
92         class wxVtkSceneManager : public InteractorStyleMaracas , public Observer
93         {
94         public:
95
96                 wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager);
97                 ~wxVtkSceneManager();
98                 void disconnectDrop();
99
100                 //-------
101                 void configureBaseView();
102                 void registerController(InteractorStyleMaracas *param);
103                 void unregisterController(InteractorStyleMaracas *param);
104
105                 virtual bool OnChar();
106                 virtual bool OnMouseMove();
107                 virtual bool OnLeftButtonDown();
108                 virtual bool OnLeftButtonUp();
109                 virtual bool OnRightButtonUp();
110                 virtual bool OnLeftDClick();
111
112                 //-------
113                 int createGBlackBox(int x, int y, std::string packageName, std::string boxType );
114                 int createGComplexBoxInputPort(std::string inputName);
115                 int createGComplexBoxOutputPort(std::string outputName);
116                 GPortController* createGPort(int portType, std::string bbtkName, std::string bbtkType, int posinBox,GBoxModel *blackBox);
117                 int createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc);
118                 int createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc);
119                 int createGConnector(GPortModel* startPort);
120
121                 void configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn);
122                 int configGConnetion( std::string nameStartBox, std::string  nameStartPort, std::string
123                                                           nameEndBox, std::string  nameEndPort);
124                 void configGComBoxInputOutputPort(bool inputoutput, std::string inputPortName, double xIn, double yIn,double zIn);
125                 GBoxModel* findGBox(std::string boxname);
126
127
128
129                 vtkRenderWindow* getRenderWindow();
130                 vtkRenderer* getRenderer();
131
132                 virtual void update(int idController,int command);
133
134                 void refresh();
135                 void refreshScene();
136                 void displayBlackBoxInfo(std::string packageName, std::string boxName);
137                 void updateStatusBar(std::string textStatus);
138
139                 //-------
140                 //Get a collection of object ids
141                 std::vector<int> getBlackBoxes();
142                 std::vector<int> getConnections();
143                 std::vector<int> getComplexInputPorts();
144                 std::vector<int> getComplexOutputPorts();
145
146                 //Get the map of selected objects (id, controller)
147                 std::map<int,GObjectController*> getSelectedObjects();
148
149                 //Get size of selected objects map
150                 int getNumSelectedObjects();
151
152                 //Complex box edition mode
153                 bool isComplexBox();
154                 void setComplexBox(bool val);
155
156                 //-------
157                 //Add an object to the list of controllers
158                 int addObjectController(GObjectController* objController);
159
160                 //Add a map of object controllers
161                 void addObjects(std::map<int,GObjectController*> objectsMap);
162
163
164                 //-------
165                 //Returns a string with the BBS script of the current diagram.
166                 std::string getDiagramBBS(bool wln=false);
167
168                 //Returns a string with the BBS script of the complex box.
169                 std::string saveComplexBoxBBS();
170
171                 //Delete the object in the list of controllers with the id given by parameter.
172                 void deleteObject(int id);
173
174                 void AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id);
175
176                 //Clear list of controllers and refresh
177                 void deleteAllBoxes();
178
179                 //Save the diagram in the BBG format, in the string given by param.
180                 void saveDiagram(std::string &content);
181
182                 //Load the diagram
183                 void loadDiagram(ifstream &inputStream);
184
185                 //Center the view of the camera in the initial position
186                 void centerView();
187
188                 bool boxExist(std::string boxname);
189                 std::string generateANewNameForABox();
190                 std::string findANewNameForABox();
191                 //-------
192
193         void SetCbName(std::string cbNane);
194         void SetCbPackageName(std::string packagename);
195         void SetAuthor(std::string author);
196         void SetCategory(std::string category);
197         void SetDescription(std::string description);
198
199         std::string GetCbName();
200         std::string GetCbPackageName();
201         std::string GetAuthor();
202         std::string GetCategory();
203         std::string GetDescription();
204
205         private:
206
207         std::string                         _cbName;
208         std::string                         _cbPackageName;
209         std::string                         _Author;
210         std::string                         _Category;
211         std::string                         _Description;
212
213                 //wxPanel that uses the manager
214                 wxGEditorTabPanel                                       *_parent;
215
216                 // Id of the manager, the same of the panel
217                 int                                                                     _idManager;
218
219                 // Boxes number in the scene
220                 int                                                                     _numBoxes;
221
222                 // StartDragging
223                 bool                                                            _startDragging;
224
225                 // creaMaracasVisu viewer
226                 wxVtk3DBaseView                                         *_baseView;
227
228                 // State of the 3D Scene or the virtual world
229                 int _worldState;
230
231                 //Map of id - objectController
232                 std::map<int,GObjectController*>        _controllers;
233
234                 //Saves the id's of the selected objects in the controllers map
235                 std::vector<int>                                        _selectedObjects;
236
237                 //Is the diagram in state complex box
238                 bool                                                            _isComplexBox;
239
240                 int                                                                     _idConnectionInCreation;
241
242                 int _contLastId;
243
244                 vtkTextActor3D                                          *_textActor;
245                 vtkPoints                                                       *_pts;
246                 vtkActor                                                        *_fillObjectActor;
247                 vtkDataSetMapper                                        *_aPolygonMapper;
248
249         std::string LineNumber(bool withLineNumber, int &value);
250         int GetIndexInSelected(int idControler);
251         void UnSelectBlackBoxes();
252         GObjectController *GetGBlackBoxControlerPointedByMouse();
253                 void CancelConnection();
254
255         protected:
256
257         };
258
259
260 }
261 // namespace bbtk
262 #endif
263