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