]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.h
#3084 bbGEditor Bug New Normal - Color refresh for inputs and outputs
[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
148 //EED2017-04-07
149 //              int createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc);
150 //              int createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc);
151                 int createGInputPort(int portType, int posinBox,GObjectController *gBoxControler, BlackBoxInputDescriptor *desc);
152                 int createGOutputPort(int portType, int posinBox,GObjectController *gBoxControler, BlackBoxOutputDescriptor *desc);
153
154                 int createGConnector(GPortModel* startPort);
155
156                 void configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn);
157                 int configGConnetion( std::string nameStartBox, std::string  nameStartPort, std::string nameEndBox, std::string  nameEndPort);
158                 void configGComBoxInputOutputPort(bool inputoutput, std::string inputPortName, double xIn, double yIn,double zIn);
159                 GBoxModel* findGBox(std::string boxname);
160
161
162
163                 vtkRenderWindow* getRenderWindow();
164                 vtkRenderer*     getRenderer();
165
166                 virtual void update(int idController,int command);
167
168                 void refresh();
169                 void refreshScene();
170                 void displayBlackBoxInfo(std::string packageName, std::string boxName);
171                 void updateStatusBar(std::string textStatus);
172
173                 //-------
174                 //Get a collection of object ids
175                 std::vector<int> getBlackBoxes();
176                 std::vector<int> getConnections();
177                 std::vector<int> getComplexInputPorts();
178                 std::vector<int> getComplexOutputPorts();
179
180                 //Get the map of selected objects (id, controller)
181                 std::map<int,GObjectController*> getSelectedObjects();
182
183                 //Get size of selected objects map
184                 int getNumSelectedObjects();
185
186                 //Complex box edition mode
187                 bool isComplexBox();
188                 void setComplexBox(bool val);
189
190                 //-------
191                 //Add an object to the list of controllers
192                 int addObjectController(GObjectController* objController);
193
194                 //Add a map of object controllers
195                 void addObjects(std::map<int,GObjectController*> objectsMap);
196
197                 /// Duplicates Objects to current a diagram
198         void DuplicateObjects(std::map<int,GObjectController*> objectsMap);///JLGR 21-05-2012
199
200                 //-------
201                 // Makes a BlackBox Executable
202                 bool MakeBoxExecutable();//DFCH
203                 //-------
204                 //Returns a string with the BBS script of the current diagram.
205                 std::string getDiagramBBS(bool wln=false);
206
207                 //Returns a string with the BBS script of the complex box.
208                 std::string saveComplexBoxBBS();
209
210                 //Delete the object in the list of controllers with the id given by parameter.
211                 bool deleteObject(int id);
212
213                 void AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id);
214
215                 //Clear list of controllers and refresh
216                 void deleteAllBoxes();
217
218                 //Save the diagram in the BBG format, in the string given by param.
219                 void saveDiagram(std::string &content);
220
221                 //Load the diagram
222                 void loadDiagram(std::stringstream &inputStream);
223
224                 //Center the view of the camera in the initial position
225                 void centerView();
226
227                 bool boxExist(std::string boxname);
228                 std::string generateANewNameForABox();
229                 std::string findANewNameForABox();
230                 //-------
231
232         void SetCbName(std::string cbNane);
233         void SetCbPackageName(std::string packagename);
234         void SetAuthor(std::string author);
235         void SetCategory(std::string category);
236         void SetDescription(std::string description);
237                 void SetMessageKind(std::string kind);
238                 void SetMessageLevel(std::string Level);
239         std::string GetCbName();
240         std::string GetCbPackageName();
241         std::string GetAuthor();
242         std::string GetCategory();
243         std::string GetDescription();
244                 std::string GetMessageKind();
245         std::string GetMessageLevel();
246   
247         // RaC2012 2nd HackFest
248         // External Inputs was the complex inputs in previous versions
249         // Get names of all external inputs
250         std::vector< std::string> GetExternalInputsNames();
251                 void getCleanLine(std::stringstream &inputStream, std::string &line);
252         // JGRR & CM
253         void printAll( int com, int sta );
254                 std::vector<std::string> boxesDiagram;//CFT
255         private:
256         std::string                         _cbName;
257         std::string                         _cbPackageName;
258         std::string                         _Author;
259         std::string                         _Category;
260         std::string                         _Description;
261                 std::string                                     _MessageKind;
262                 std::string                                     _MessageLevel;
263                 //wxPanel that uses the manager
264                 wxGEditorTabPanel                                       *_parent;
265                 // Id of the manager, the same of the panel
266                 int                                                                     _idManager;
267                 // Boxes number in the scene
268                 int                                                                     _numBoxes;
269                 // StartDragging
270                 bool                                                            _startDragging;
271                 // creaMaracasVisu viewer
272                 wxVtk3DBaseView                                         *_baseView;
273                 // State of the 3D Scene or the virtual world
274                 int _worldState;
275                 //Map of id - objectController
276                 std::map<int,GObjectController*>        _controllers;
277                 //Saves the id's of the selected objects in the controllers map
278                 std::vector<int>                                        _selectedObjects;
279                 //Is the diagram in state complex box
280                 bool                                                            _isComplexBox;
281                 int                                                                     _idConnectionInCreation;
282                 int _contLastId;
283                 vtkTextActor3D                                          *_textActor;
284                 std::string                                                     _bugTextActor_text;
285                 int                                                                     _bugTextActor_status;
286                 vtkPoints                                                       *_pts;
287                 vtkActor                                                        *_fillObjectActor;
288                 vtkDataSetMapper                                        *_aPolygonMapper;
289                 Factory::Pointer                                        _bbtkfactory;
290         std::string LineNumber(bool withLineNumber, int &value);
291         int GetIndexInSelected(int idControler);
292         void UnSelectBlackBoxes();
293         GObjectController *GetGBlackBoxControlerPointedByMouse();
294                 void CancelConnection();
295         protected:
296         };
297
298
299 }
300 // namespace bbtk
301 #endif
302