~ubuntu-branches/ubuntu/wily/ginkgocadx/wily-proposed

« back to all changes in this revision

Viewing changes to src/visualizator/visualizator/wxvtk/gvistacompleja.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille
  • Date: 2011-05-02 08:09:26 UTC
  • Revision ID: james.westby@ubuntu.com-20110502080926-bql5wep49c7hg91t
Tags: upstream-2.4.1.1
Import upstream version 2.4.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  
 
3
 *  $Id: gvistacompleja.cpp 3748 2011-04-20 10:38:38Z carlos $
 
4
 *  Ginkgo CADx Project
 
5
 *
 
6
 *  Copyright 2008-10 MetaEmotion S.L. All rights reserved.
 
7
 *  http://ginkgo-cadx.com
 
8
 *
 
9
 *  This file is licensed under LGPL v3 license.
 
10
 *  See License.txt for details
 
11
 *
 
12
 *
 
13
 */
 
14
#include <wx/wx.h>
 
15
#include "gvistacompleja.h"
 
16
#include "gvistasimple.h"
 
17
#include "imprimevistasimple.h"
 
18
#include "../vistas/vista2d.h"
 
19
#include "../../recursos/aprimresourcemanager.h"
 
20
 
 
21
#include <wx/msgdlg.h>
 
22
#include <wx/menu.h>
 
23
#include <wx/config.h>
 
24
 
 
25
#include "../eventos/visualizatorevents.h"
 
26
#include <api/icontroladorherramientas.h>
 
27
#include <api/icontroladorlog.h>
 
28
#include <api/icontroladorvistas.h>
 
29
#include <eventos/eventosginkgo.h>
 
30
#include <api/iwidgetsmanager.h>
 
31
#include "../estudios/visualizatorstudy.h"
 
32
 
 
33
#ifdef __DEPRECATED
 
34
#undef __DEPRECATED
 
35
#endif
 
36
 
 
37
#include <vtkVISUManagement/vtkLookupTableManager.h>
 
38
#include <vtk/widgets/widgetsactor.h>
 
39
#include <vtkCamera.h>
 
40
#include <vtkPointData.h>
 
41
#include <vtkImageBlend.h>
 
42
#include <vtkImageMathematics.h>
 
43
#include <api/westilo.h>
 
44
 
 
45
 
 
46
#include <export/iherramientapuntero.h>
 
47
#include <export/iherramientaregla.h>
 
48
#include <export/iherramientaangulo.h>
 
49
#include <export/iherramientanota.h>
 
50
#include <export/iherramientawindowlevel.h>
 
51
#include <export/iherramientalupa.h>
 
52
#include <export/iherramientamarcado.h>
 
53
#include <export/iherramientarejillametrica.h>
 
54
#include <export/iherramientaanotacionesesquina.h>
 
55
#include <api/imodelointegracion.h>
 
56
#include <api/icontroladormodulo.h>
 
57
#include <api/icontroladorpermisos.h>
 
58
#include <api/icontroladorcomandos.h>
 
59
#include <export/iherramientareset.h>
 
60
#include <export/iherramientalayoutventana.h>
 
61
#include "../exportacion/iherramientamapacolor.h"
 
62
#include "../exportacion/iherramientaoverlays.h"
 
63
#include "../exportacion/ireconstructiontool.h"
 
64
#include <export/iherramientadesencajar.h>
 
65
 
 
66
#include <commands/comandodestruirvista.h>
 
67
 
 
68
#include <cairo/cairo.h>
 
69
#include <widgets/openglhelper.h>
 
70
//#include <widgets/wprogreso.h>
 
71
#include <widgets/wanotacionesquina.h>
 
72
 
 
73
#include <hackimageactor.h>
 
74
#include <api/internacionalizacion.h>
 
75
 
 
76
#include "reconstruction/endoscopy.h"
 
77
#include "reconstruction/mpr3d.h"
 
78
#include "reconstruction/surface.h"
 
79
#include "reconstruction/volume.h"
 
80
 
 
81
#define ID_BOTON_PLAY_STOP 0
 
82
#define ID_BOTON_VER 1
 
83
#define ID_BOTON_LAYOUT 2
 
84
#define ID_BOTON_SINCRONIZAR 3
 
85
#define ID_BOTON_DESENCAJAR 4
 
86
 
 
87
#define ID_ROTATE_LEFT 4151
 
88
#define ID_ROTATE_RIGHT 4152
 
89
#define ID_FLIP_V 4153
 
90
#define ID_FLIP_H 4154
 
91
//esta clase sirve para las barras de herramientas de abajo
 
92
class BarraHerramientasBotones:public wxAuiToolBar{
 
93
public:
 
94
        BarraHerramientasBotones(wxWindow* pParent, const wxColor& color = wxColor(0x40, 0x40, 0x40)): wxAuiToolBar(pParent,wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_TB_DEFAULT_STYLE)
 
95
        {
 
96
                SetToolBitmapSize(wxSize(16,16));
 
97
                AUI_NAMESPACE wxAuiDefaultToolBarArt* pToolArt= new AUI_NAMESPACE wxAuiDefaultToolBarArt();
 
98
#if defined(USE_PATCHED_LIBS) && !defined(__WXOSX__)
 
99
                pToolArt->SetBaseColor(color);
 
100
#endif
 
101
                SetArtProvider(pToolArt);
 
102
        }
 
103
 
 
104
        ~BarraHerramientasBotones()
 
105
        {
 
106
        }
 
107
};
 
108
 
 
109
//esta clase sirve para no tener que definir identificadores en las opciones de periodo en el cine
 
110
class ItemFrameRate: protected wxEvtHandler, public wxMenuItem {
 
111
public:
 
112
        ItemFrameRate(wxMenu *parentMenu,const wxString& text,GVistaCompleja* pVista,int periodo):wxMenuItem(parentMenu,wxID_ANY,text,wxEmptyString,wxITEM_CHECK)
 
113
        {
 
114
                m_pVista = pVista;
 
115
                m_periodo = periodo;
 
116
                int id = wxMenuItem::GetId();
 
117
                #ifdef __WXMSW__
 
118
                parentMenu->GetParent()->Connect(id,wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( ItemFrameRate::OnMenuClick),NULL,this);
 
119
                #else
 
120
                parentMenu->Connect(id,wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( ItemFrameRate::OnMenuClick),NULL,this);
 
121
                #endif
 
122
        }
 
123
        ~ItemFrameRate(){
 
124
                m_pVista =NULL;
 
125
                int id = wxMenuItem::GetId();
 
126
                #ifdef __WXMSW__
 
127
                GetMenu()->GetParent()->Disconnect(id,wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( ItemFrameRate::OnMenuClick ),NULL,this);
 
128
                #else
 
129
                GetMenu()->Disconnect(id,wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( ItemFrameRate::OnMenuClick ),NULL,this);
 
130
                #endif
 
131
        }
 
132
 
 
133
        void OnMenuClick(wxCommandEvent &event) {
 
134
                m_pVista->SetPeriodo(m_periodo);
 
135
                event.Skip(false);
 
136
        }
 
137
 
 
138
 
 
139
        GVistaCompleja* m_pVista;
 
140
        int m_periodo;
 
141
};
 
142
 
 
143
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
144
class TimerPlay:public wxTimer
 
145
{
 
146
public:
 
147
        TimerPlay(GVistaCompleja *pVista){
 
148
                m_pVista=pVista;
 
149
        }
 
150
 
 
151
        ~TimerPlay() {}
 
152
 
 
153
        virtual void Notify(){
 
154
                m_pVista->OnTimer();
 
155
        }
 
156
 
 
157
        GVistaCompleja *m_pVista;
 
158
};
 
159
 
 
160
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
161
 
 
162
 
 
163
GVistaCompleja::GVistaCompleja(GNKVisualizator::Vista2D* pIVista) : VistaComplejaBase(pIVista->GetVisualizatorStudy()->VentanaPadre ) {
 
164
        IVista = pIVista;
 
165
        IVista->GetVisualizatorStudy()->Ventana = this;
 
166
        m_hasBeenRendered = false;
 
167
        m_ReproducirBucle = false;
 
168
        m_PeriodoMs = 500;
 
169
        m_posicion = m_pSliderSlice->GetValue();
 
170
 
 
171
        // Setup del manejador de widgets */
 
172
        GNC::GCS::IContratoWidgets::m_pManager = IVista->GetEstudio()->Entorno->NewWidgetsManager(IVista);
 
173
        GNC::GCS::IContratoWidgets::Setup(GNC::GCS::IContratoWidgets::m_pManager);
 
174
 
 
175
        m_playTimer = new TimerPlay(this);
 
176
 
 
177
        //se añaden los botones de ver/cine
 
178
        m_pBarraIzquierda = new BarraHerramientasBotones(m_pPanelManipulacion);
 
179
        m_pBarraIzquierda->AddTool(ID_BOTON_VER,_("Display Options"),APrimResourcesManager::Herramientas::GetIcoMenuImagen(),_("Display Options"));
 
180
        m_pBarraIzquierda->Connect(ID_BOTON_VER,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( GVistaCompleja::OnMenuVerClick),NULL,this);
 
181
 
 
182
        m_pBarraIzquierda->AddTool(ID_BOTON_LAYOUT,_("Layout Setup"),APrimResourcesManager::Herramientas::GetIcoLayout(),_("Layout Setup"));
 
183
        m_pBarraIzquierda->Connect(ID_BOTON_LAYOUT,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( GVistaCompleja::OnMenuLayout),NULL,this);
 
184
 
 
185
        GNC::GCS::IControladorHerramientas* cH = IVista->GetEstudio()->Entorno->GetControladorHerramientas();
 
186
        try {
 
187
                GNC::GCS::IHerramientaDesencajar*  hDesencajar = NULL;
 
188
                hDesencajar = cH->ObtenerHerramientaConcreta<GNC::GCS::IHerramientaDesencajar>(GNC::GCS::IHerramientaDesencajar::ID);
 
189
                if (hDesencajar != NULL) {
 
190
                        m_pBarraIzquierda->AddTool(ID_BOTON_DESENCAJAR,_("Disencage view"),hDesencajar->GetIcono(),_("Disencage view"));
 
191
                        m_pBarraIzquierda->Connect(ID_BOTON_DESENCAJAR,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( GVistaCompleja::OnDesencajar),NULL,this);
 
192
                }
 
193
        }catch(...){}
 
194
 
 
195
        m_pBarraIzquierda->Realize();
 
196
        m_pSizerIzquierda->Add(m_pBarraIzquierda,0, wxALIGN_CENTER_VERTICAL|wxEXPAND,0);
 
197
 
 
198
        m_pBarraCine = new BarraHerramientasBotones(m_pPanelManipulacion);
 
199
        m_pBarraCine->AddTool(ID_BOTON_PLAY_STOP,_("Play"),APrimResourcesManager::BarraCine::GetIcoPlay(),_("Play"));
 
200
        m_pBarraCine->Connect(ID_BOTON_PLAY_STOP,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( GVistaCompleja::OnPlayStopClick),NULL,this);
 
201
        m_pBarraCine->SetToolDropDown(ID_BOTON_PLAY_STOP, true);
 
202
        m_pBarraCine->Connect(ID_BOTON_PLAY_STOP,wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, wxAuiToolBarEventHandler( GVistaCompleja::OnMenuCineClick),NULL,this);
 
203
 
 
204
        m_pBarraCine->Realize();
 
205
        m_pSizerIzquierda->Add(m_pBarraCine,0, wxALIGN_CENTER_VERTICAL|wxEXPAND,0);
 
206
 
 
207
        //se añaden los de sincronizar/dessincronizar
 
208
        m_pBarraDerecha = new BarraHerramientasBotones(m_pPanelManipulacion);
 
209
        m_pBarraDerecha->AddTool(ID_BOTON_SINCRONIZAR,_("Synchronize/Des synchronize"),APrimResourcesManager::BarraSincronizar::GetIcoDessincronizar(),_("Synchronize/Des synchronize"),wxITEM_CHECK);
 
210
        m_pBarraDerecha->Connect(ID_BOTON_SINCRONIZAR,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( GVistaCompleja::OnSincronizarClick),NULL,this);
 
211
        m_pBarraDerecha->ToggleTool(ID_BOTON_SINCRONIZAR,false);
 
212
 
 
213
        m_pBarraDerecha->Realize();
 
214
        m_pSizerDerecho->Add(m_pBarraDerecha,0, wxALIGN_CENTER_VERTICAL|wxEXPAND,0);
 
215
 
 
216
 
 
217
 
 
218
 
 
219
        //Connect(wxEVT_CHILD_FOCUS, wxChildFocusEventHandler(GVistaCompleja::OnFocus),NULL,this);
 
220
        Connect(wxEVT_KEY_DOWN,wxKeyEventHandler(GVistaCompleja::OnKeyDown),NULL,this);
 
221
        Connect(wxEVT_CHAR,wxKeyEventHandler(GVistaCompleja::OnKeyDown),NULL,this);
 
222
        Connect(wxEVT_MOUSEWHEEL,wxMouseEventHandler(GVistaCompleja::OnMouseWheel),NULL,this);
 
223
 
 
224
        GNC::GCS::Eventos::EventoModificacionImagen ev2(IVista);
 
225
        GNC::GCS::Eventos::EventoModificacionWidget ev3(IVista);
 
226
        GNC::GCS::Eventos::EventoRender ev4(IVista);
 
227
        GNKVisualizator::Eventos::EventoMostrarOverlay evt5(IVista);
 
228
 
 
229
        pIVista->GetEstudio()->Entorno->GetControladorEventos()->Registrar(this, ev2);
 
230
        pIVista->GetEstudio()->Entorno->GetControladorEventos()->Registrar(this, ev3);
 
231
        pIVista->GetEstudio()->Entorno->GetControladorEventos()->Registrar(this, ev4);
 
232
        pIVista->GetEstudio()->Entorno->GetControladorEventos()->Registrar(this, evt5);
 
233
 
 
234
        GNC::GCS::IContratoWidgets::m_pManager->CrearWidgetAnotador(this);
 
235
        AddVistaSimple();
 
236
 
 
237
        //FUNDAMENTAL PARA QUE FUNCIONE LA HERRAMIENTA DE MAPAS DE COLOR
 
238
        IVista->VisualizatorStudy->Viewer = m_VistasSimples[0]->ViewImage2D;
 
239
 
 
240
        //GNC::GCS::IContratoWidgets::m_pManager->InsertarWidget(new GNC::GCS::Widgets::WProgreso(m_VistasSimples.front()->ViewInteractor2D, GNC::GCS::IContratoWidgets::m_pManager, -1, "progreso", 666));
 
241
        GNC::GCS::IContratoWidgets::m_pManager->EnableAnimation();
 
242
 
 
243
        Layout();
 
244
}
 
245
 
 
246
GVistaCompleja::~GVistaCompleja()
 
247
{
 
248
        IVista->ComienzaDestruccion();
 
249
        //FUNDAMENTAL PARA QUE los viewers se destruyan correctamente y sin leaks ya que Viewer es smart pointer
 
250
        for(TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
251
                (*it)->UnRefIVista();
 
252
        }
 
253
 
 
254
        IVista->VisualizatorStudy->Viewer = NULL;
 
255
 
 
256
        if (IVista != NULL) {
 
257
                IVista->VisualizatorStudy->Entorno->GetControladorComandos()->AbortarComandosDeOwner(IVista);
 
258
        }
 
259
 
 
260
        //Disconnect(wxEVT_CHILD_FOCUS, wxChildFocusEventHandler(GVistaCompleja::OnFocus),NULL,this);
 
261
        this->Disconnect(wxEVT_KEY_DOWN,wxKeyEventHandler(GVistaCompleja::OnKeyDown),NULL,this);
 
262
        this->Disconnect(wxEVT_MOUSEWHEEL,wxMouseEventHandler(GVistaCompleja::OnMouseWheel),NULL,this);
 
263
 
 
264
        if(m_ListaSincronizacion.size() >0){
 
265
                //si esta reproduciendose se para
 
266
                Stop();
 
267
                //
 
268
                DesSincronizar();
 
269
        }
 
270
 
 
271
        if(m_playTimer!= NULL) {
 
272
                delete m_playTimer;
 
273
                m_playTimer = NULL;
 
274
        }
 
275
 
 
276
        GNC::GCS::IContratoWidgets::m_pManager->EliminarTodosLosWidgets(false);
 
277
 
 
278
        m_VistasSimples.clear();
 
279
 
 
280
        IVista->GetEstudio()->Entorno->FreeWidgetsManager(GNC::GCS::IContratoWidgets::m_pManager);
 
281
        GNC::GCS::IContratoWidgets::m_pManager = NULL;
 
282
        
 
283
        GNKVisualizator::IReconstructionTool* hReconstruction = IVista->VisualizatorStudy->Entorno->GetControladorHerramientas()->ObtenerHerramientaConcreta<GNKVisualizator::IReconstructionTool>(GNKVisualizator::IReconstructionTool::ID);
 
284
        if (hReconstruction != NULL) {
 
285
                ((GNC::GCS::IContratable<GNKVisualizator::IReconstructionContract>*)hReconstruction)->DesSubscribirsLosDeLaVista(IVista);
 
286
        }
 
287
 
 
288
        IVista->Lock(GLOC());
 
289
        delete IVista;
 
290
}
 
291
 
 
292
void GVistaCompleja::AddVistaSimple()
 
293
{
 
294
        GVistaSimple* pVistaSimple = new GVistaSimple(IVista,this);
 
295
        m_VistasSimples.push_back(pVistaSimple);
 
296
        m_pSizerSeries->Add(pVistaSimple,1,wxEXPAND);
 
297
 
 
298
 
 
299
        GNC::GCS::IWidgetsRenderer* pR = pVistaSimple->ViewInteractor2D;
 
300
        pR->SetManager(GNC::GCS::IContratoWidgets::m_pManager);
 
301
        pR->SetIOverlay(pVistaSimple);
 
302
        //GNC::GCS::IContratoWidgets::m_pManager->SetRendererActivo(pR);
 
303
        std::ostringstream os;
 
304
        os << "Renderer " << pVistaSimple << std::endl;
 
305
        pR->sid = os.str();
 
306
        ////
 
307
 
 
308
        WidgetRepresentation* pWidgetsRepresentation = WidgetRepresentation::New();
 
309
        pWidgetsRepresentation->SetRenderer(pVistaSimple->ViewInteractor2D->FindPokedRenderer(0,0));
 
310
        pVistaSimple->ViewInteractor2D->FindPokedRenderer(0,0)->AddViewProp(pWidgetsRepresentation);
 
311
        pR->SetRepresentation(pWidgetsRepresentation);
 
312
        pWidgetsRepresentation->SetWidgetsManager(GNC::GCS::IContratoWidgets::m_pManager);
 
313
        pWidgetsRepresentation->SetWidgetsRenderer(pR);
 
314
        pWidgetsRepresentation->Delete();
 
315
 
 
316
        pVistaSimple->ViewImage2D->SetWindowLevelFrom(m_VistasSimples[0]->ViewImage2D);
 
317
        pVistaSimple->ViewImage2D->SetLookupTable(m_VistasSimples[0]->ViewImage2D->GetLookupTable(), m_VistasSimples[0]->ViewImage2D->GetIdLookupTable());
 
318
        pVistaSimple->ViewImage2D->SetZoom(m_VistasSimples[0]->ViewImage2D->GetZoom());
 
319
        pVistaSimple->ViewImage2D->CopyCameraStatus(m_VistasSimples[0]->ViewImage2D);
 
320
 
 
321
        for (unsigned int i = 0; i < m_VistasSimples.size(); i++) {
 
322
                GNC::GCS::IWidgetsRenderer* pR = m_VistasSimples[i]->ViewInteractor2D;
 
323
                pR->SetVID(i, false);
 
324
                std::ostringstream os;
 
325
                os << "Renderer " << i << std::endl;
 
326
                pR->sid = os.str();
 
327
        }
 
328
}
 
329
 
 
330
void GVistaCompleja::IniciarPipeline()
 
331
{
 
332
        m_pPanelManipulacion->Enable(true);
 
333
 
 
334
        m_pListaOverlays = IVista->VisualizatorStudy->GetOverlaysImagenActiva();
 
335
        IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(new GNKVisualizator::Eventos::EventoRefrescarListaOverlays(IVista,m_pListaOverlays));
 
336
 
 
337
        //contratos que son 1:1 con gvistacompleja
 
338
        GNKVisualizator::IContratoMapaColor::Setup(IVista->GetEstudio());
 
339
        GNKVisualizator::IReconstructionContract::Setup(IVista->GetEstudio());
 
340
        GNKVisualizator::IContratoOverlays::Setup(m_pListaOverlays,IVista->GetEstudio()->Entorno);
 
341
        //esto es correcto porque en la creacion se mete siempre una vista simple
 
342
 
 
343
 
 
344
        GNC::GCS::IContratoWindowLevel::Setup(*IVista->GetEstudio()->GetTagsImagenDeImagenActiva());
 
345
 
 
346
 
 
347
        ///////////recorrer las vistas simples y pasarles las imagenes
 
348
        int i = 0;
 
349
        if(m_VistasSimples.size() > 0) {
 
350
                for(TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
351
                        GVistaSimple* pvs = *it;
 
352
                        pvs->EstudioReferido->SetIndiceActivo(i);
 
353
                        pvs->SetOverlays(m_pListaOverlays, m_EstadoOverlays);
 
354
 
 
355
                        //despues se establece el WL
 
356
                        if (HasDefaultWindowLevel()) {
 
357
                                GNC::GCS::IContratoWindowLevel::WindowLevel wl = GetAndSetDefaultWindowLevel();
 
358
                                pvs->ViewImage2D->SetDefaultWindowLevel(wl.m_window, wl.m_level);
 
359
                        }
 
360
                        else {
 
361
                                pvs->ViewImage2D->SetAutoDefaultWindowLevel();
 
362
                        }
 
363
                        i++;
 
364
                }
 
365
                GNC::GCS::IContratoWidgets::m_pManager->SetRendererActivo( (* (m_VistasSimples.begin()) )->ViewInteractor2D );
 
366
 
 
367
                GNC::GCS::IContratoLayoutVentana::Setup(0, IVista->GetEstudio()->GetNumeroCortes() - 1);
 
368
 
 
369
                ActualizarMaxMinSlider();
 
370
        }
 
371
 
 
372
        //contrato window level, hay que preguntarle al viewer de la primera vista porque el estudioatencionprimaria no tiene viewer
 
373
        GNC::GCS::IControladorHerramientas* cH = IVista->GetEstudio()->Entorno->GetControladorHerramientas();
 
374
        GNC::GCS::IHerramientaWindowLevel* hWindowLevel = NULL;
 
375
        try {
 
376
                if(m_VistasSimples[0]->ViewImage2D->GetNumberOfComponents() == 1){
 
377
                        // Subscribimos la vista al contrato de hWindowLevel
 
378
                        hWindowLevel = cH->ObtenerHerramientaConcreta<GNC::GCS::IHerramientaWindowLevel>(GNC::GCS::IHerramientaWindowLevel::ID);
 
379
                        if (hWindowLevel != NULL) {
 
380
                                ((GNC::GCS::IContratable<GNC::GCS::IContratoWidgets>*)hWindowLevel)->Subscribir(IVista, this);
 
381
                                ((GNC::GCS::IContratable<GNC::GCS::IContratoWindowLevel>*)hWindowLevel)->Subscribir(IVista, this);
 
382
                        }
 
383
                }
 
384
        }
 
385
        catch (GNC::GCS::ControladorHerramientasException& ex) {
 
386
                std::cerr << "Error al obtener la herramienta puntero: No se pudo subscribir la herramienta: " << ex.getCause() << std::endl;
 
387
        }
 
388
 
 
389
        GNKVisualizator::IReconstructionTool* hReconstruction = cH->ObtenerHerramientaConcreta<GNKVisualizator::IReconstructionTool>(GNKVisualizator::IReconstructionTool::ID);
 
390
        if (hReconstruction != NULL) {
 
391
                ((GNC::GCS::IContratable<GNKVisualizator::IReconstructionContract>*)hReconstruction)->Subscribir(IVista, this);
 
392
        }
 
393
}
 
394
 
 
395
 
 
396
 
 
397
void GVistaCompleja::DetenerPipeline()
 
398
{
 
399
        m_pManager->OcultarTodosLosWidgets(true, 666);
 
400
        m_pManager->DisableAnimation();
 
401
        m_pPanelManipulacion->Enable(true);
 
402
        m_pManager->Render();
 
403
}
 
404
 
 
405
void GVistaCompleja::OnCargaFinalizada()
 
406
{
 
407
        m_pManager->OcultarTodosLosWidgets(true, 666);
 
408
        m_pManager->DisableAnimation();
 
409
        m_pManager->Render();
 
410
}
 
411
 
 
412
 
 
413
void GVistaCompleja::OnPaint(wxPaintEvent& event)
 
414
{
 
415
        //std::cout << "GVistaCompleja::OnPaint()" << std::endl;
 
416
        VistaComplejaBase::OnPaint(event);
 
417
        if(IVista->GetEstudio()->Entorno->GetControladorVistas()->GetVistaActiva() == IVista)
 
418
        {
 
419
                wxPaintDC dc(this);
 
420
                wxColour colorLineaSeleccion(219, 219, 0, 255);
 
421
                dc.SetBrush(wxBrush(colorLineaSeleccion,wxTRANSPARENT));
 
422
                dc.SetPen(wxPen(colorLineaSeleccion, 3, wxSOLID));
 
423
                dc.DrawRectangle(wxRect(wxPoint(1, 1), wxPoint(dc.GetSize().x-1, dc.GetSize().y-1)));
 
424
        }
 
425
        //la comprobacion de la textura, se hace la primera vez que se pinta
 
426
        if(!m_hasBeenRendered ) {
 
427
                if(IVista->EstaCargada()) {
 
428
                        for(GVistaCompleja::TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
429
                                GVistaSimple* vs = *it;
 
430
                                try {
 
431
                                        vs->ViewInteractor2D->Render();
 
432
                                        long idTextura = vs->ViewImage2D->GetImageTexture();
 
433
                                        if (idTextura != 0) {
 
434
                                                if ( !glIsTexture(idTextura) ) {
 
435
                                                        IVista->GetEstudio()->Entorno->GetControladorLog()->Log("GVistaCompleja: Textura no cargada en memoria de video",GNC::GCS::IControladorLog::ErrorLog);
 
436
                                                        IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(new GNC::GCS::Eventos::EventoMensajes(NULL,_Std("Error: You have exhausted the system's video memory and has not been able to load the image. Close some studies to free memory."),GNC::GCS::Eventos::EventoMensajes::PopUpMessage,false));
 
437
                                                        GADAPI::ComandoDestruirVistaParams* pParams = new GADAPI::ComandoDestruirVistaParams(IVista);
 
438
                                                        IVista->GetEstudio()->Entorno->GetControladorComandos()->ProcessAsync(_Std("Destroy View"),new GADAPI::ComandoDestruirVista(pParams),NULL);
 
439
                                                }
 
440
                                        } else {
 
441
                                                //se comprobara mas tarde porque la textura todavia no tiene id
 
442
                                                return;
 
443
                                        }
 
444
                                }catch(const std::bad_alloc&)
 
445
                                {
 
446
                                        IVista->GetEstudio()->Entorno->GetControladorLog()->Log("GVistaCompleja: bad_alloc, error al reservar memoria física",GNC::GCS::IControladorLog::ErrorLog);
 
447
                                        IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(new GNC::GCS::Eventos::EventoMensajes(NULL,_Std("Error: System out of memory. Close some studies to free memory."),GNC::GCS::Eventos::EventoMensajes::PopUpMessage,false));
 
448
                                        GADAPI::ComandoDestruirVistaParams* pParams = new GADAPI::ComandoDestruirVistaParams(IVista);
 
449
                                        IVista->GetEstudio()->Entorno->GetControladorComandos()->ProcessAsync(_Std("Destroy View"),new GADAPI::ComandoDestruirVista(pParams),NULL);
 
450
                                }
 
451
                                catch(...)
 
452
                                {
 
453
                                        IVista->GetEstudio()->Entorno->GetControladorLog()->Log("GVistaCompleja: excepción general al comprobar errores de memoria",GNC::GCS::IControladorLog::ErrorLog);
 
454
                                        IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(new GNC::GCS::Eventos::EventoMensajes(NULL,_Std("Error: Internal error."),GNC::GCS::Eventos::EventoMensajes::PopUpMessage,false));
 
455
                                        GADAPI::ComandoDestruirVistaParams* pParams = new GADAPI::ComandoDestruirVistaParams(IVista);
 
456
                                        IVista->GetEstudio()->Entorno->GetControladorComandos()->ProcessAsync(_Std("Destroy View"),new GADAPI::ComandoDestruirVista(pParams),NULL);
 
457
                                }
 
458
                        }
 
459
                        m_hasBeenRendered = true;
 
460
                }
 
461
        }
 
462
}
 
463
 
 
464
void GVistaCompleja::OnMenuVerClick(wxCommandEvent& )
 
465
{
 
466
        IVista->OnFocus();
 
467
        wxMenu* pMenuVer = new wxMenu();
 
468
        GNC::GCS::IControladorHerramientas* cH = IVista->GetEstudio()->Entorno->GetControladorHerramientas();
 
469
        try {
 
470
                //////HERRAMIENTA ANOTACIONES ESQUINA, UN MENU////
 
471
                GNC::GCS::IHerramientaAnotacionesEsquina*  hAnotacionesEsquina = NULL;
 
472
                // Subscribimos la vista al contrato de Anotaciones ventana
 
473
                // Subscribimos la vista al contrato de rejilla
 
474
                hAnotacionesEsquina = cH->ObtenerHerramientaConcreta<GNC::GCS::IHerramientaAnotacionesEsquina>(GNC::GCS::IHerramientaAnotacionesEsquina::ID);
 
475
                if (hAnotacionesEsquina != NULL) {
 
476
                        hAnotacionesEsquina->AppendInMenu(this,pMenuVer);
 
477
                }
 
478
 
 
479
                GNC::GCS::IHerramientaRejillaMetrica*  hRejilla = NULL;
 
480
                // Subscribimos la vista al contrato de rejilla
 
481
                hRejilla = cH->ObtenerHerramientaConcreta<GNC::GCS::IHerramientaRejillaMetrica>(GNC::GCS::IHerramientaRejillaMetrica::ID);
 
482
                if (hRejilla != NULL) {
 
483
                        hRejilla->AppendInMenu(this,pMenuVer);
 
484
                }
 
485
 
 
486
                pMenuVer->AppendSeparator();
 
487
                
 
488
                /////MAPA DE COLOR/////
 
489
                GNKVisualizator::IHerramientaMapaColor*  hMapa = NULL;
 
490
                // Subscribimos la vista al contrato de rejilla
 
491
                hMapa = cH->ObtenerHerramientaConcreta<GNKVisualizator::IHerramientaMapaColor>(GNKVisualizator::IHerramientaMapaColor::ID);
 
492
                if (hMapa != NULL) {
 
493
                        hMapa->AppendInMenu(this,pMenuVer);
 
494
                }
 
495
                /////OVERLAYS//////
 
496
                GNKVisualizator::IHerramientaOverlays*  hOverlays = NULL;
 
497
                // Subscribimos la vista al contrato de rejilla
 
498
                hOverlays = cH->ObtenerHerramientaConcreta<GNKVisualizator::IHerramientaOverlays>(GNKVisualizator::IHerramientaOverlays::ID);
 
499
                if (hOverlays != NULL) {
 
500
                        hOverlays->AppendInMenu(this,pMenuVer);
 
501
                }
 
502
 
 
503
                if (m_pEntorno->GetControladorPermisos()->Get("atencionprimaria", "reconstruction")) {
 
504
                        GNKVisualizator::IReconstructionTool* hReconstruction = NULL;
 
505
                        // Reconstruction Tool subscription
 
506
                        hReconstruction = cH->ObtenerHerramientaConcreta<GNKVisualizator::IReconstructionTool>(GNKVisualizator::IReconstructionTool::ID);
 
507
                        if (hReconstruction != NULL) {
 
508
                                pMenuVer->AppendSeparator();
 
509
                                hReconstruction->AppendInMenu(this, pMenuVer);
 
510
                        }
 
511
                }
 
512
 
 
513
                pMenuVer->AppendSeparator();
 
514
 
 
515
                //////RESETEAR////
 
516
                GNC::GCS::IHerramientaReset*  hReset = NULL;
 
517
                // Subscribimos la vista al contrato de reset
 
518
                hReset = cH->ObtenerHerramientaConcreta<GNC::GCS::IHerramientaReset>(GNC::GCS::IHerramientaReset::ID);
 
519
                if (hReset != NULL) {
 
520
                        hReset->AppendInMenu(this,pMenuVer);
 
521
                }
 
522
 
 
523
                //rotate left y right y flip
 
524
                pMenuVer->AppendSeparator();
 
525
                wxMenuItem* pRotateLeft = new wxMenuItem(pMenuVer, ID_ROTATE_LEFT, _("Rotate 90") + wxString::FromUTF8("º")+ _(" Counter-ClockWise"));
 
526
                wxMenuItem* pRotateRight = new wxMenuItem(pMenuVer, ID_ROTATE_RIGHT, _("Rotate 90") + wxString::FromUTF8("º")+ _(" ClockWise"));
 
527
                wxMenuItem* pFlipVertical = new wxMenuItem(pMenuVer, ID_FLIP_V, _("Flip Vertical"));
 
528
                wxMenuItem* pFlipHorizontal = new wxMenuItem(pMenuVer, ID_FLIP_H, _("Flip Horizontal"));
 
529
                
 
530
                #ifdef __WXMSW__
 
531
                        pRotateLeft->SetBitmaps(APrimResourcesManager::Herramientas::GetIcoRotateLeft());
 
532
                        pRotateRight->SetBitmaps(APrimResourcesManager::Herramientas::GetIcoRotateRight());
 
533
                        pFlipVertical->SetBitmaps(APrimResourcesManager::Herramientas::GetIcoFlipVertical());
 
534
                        pFlipHorizontal->SetBitmaps(APrimResourcesManager::Herramientas::GetIcoFlipHorizontal());
 
535
                #else
 
536
                        pRotateLeft->SetBitmap(APrimResourcesManager::Herramientas::GetIcoRotateLeft());
 
537
                        pRotateRight->SetBitmap(APrimResourcesManager::Herramientas::GetIcoRotateRight());
 
538
                        pFlipVertical->SetBitmap(APrimResourcesManager::Herramientas::GetIcoFlipVertical());
 
539
                        pFlipHorizontal->SetBitmap(APrimResourcesManager::Herramientas::GetIcoFlipHorizontal());
 
540
                #endif
 
541
                pMenuVer->Append(pRotateLeft);
 
542
                pMenuVer->Append(pRotateRight);
 
543
                pMenuVer->AppendSeparator();
 
544
                pMenuVer->Append(pFlipVertical);
 
545
                pMenuVer->Append(pFlipHorizontal);
 
546
 
 
547
                pMenuVer->Connect(ID_ROTATE_LEFT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GVistaCompleja::OnRotateLeft),NULL,this);
 
548
                pMenuVer->Connect(ID_ROTATE_RIGHT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GVistaCompleja::OnRotateRight),NULL,this);
 
549
                pMenuVer->Connect(ID_FLIP_V, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GVistaCompleja::OnFlipVertical),NULL,this);
 
550
                pMenuVer->Connect(ID_FLIP_H, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GVistaCompleja::OnFlipHorizontal),NULL,this);
 
551
        }
 
552
        catch (GNC::GCS::ControladorHerramientasException& ex) {
 
553
                std::cerr << "Error al obtener la herramienta puntero: No se pudo subscribir la herramienta: " << ex.getCause() << std::endl;
 
554
        }
 
555
        m_pBarraIzquierda->PopupMenu(pMenuVer);
 
556
        delete pMenuVer;
 
557
}
 
558
 
 
559
 
 
560
void GVistaCompleja::OnMenuCineClick(wxAuiToolBarEvent& evt)
 
561
{
 
562
        if (evt.IsDropDownClicked())
 
563
        {
 
564
                wxAuiToolBar* tb = static_cast<wxAuiToolBar*>(evt.GetEventObject());
 
565
                tb->SetToolSticky(evt.GetId(), true);
 
566
 
 
567
                IVista->OnFocus();
 
568
                //se crea el menu
 
569
                wxMenu menuVer;
 
570
                wxMenu* pMenuFrameRate = new wxMenu();
 
571
                menuVer.AppendSubMenu(pMenuFrameRate,_("Speed"));
 
572
                //importante si se añade un titulo añadir un periodo!!
 
573
                wxString titulos[8] = {wxT("20 fps"), wxT("8 fps"),wxT("4 fps"),wxT("2 fps"),wxT("1 fps"),wxT("0.5 fps"),wxT("0.2 fps"),wxT("0.1 fps")};
 
574
                int periodos[8] = {50,125,250,500,1000,2000,5000,10000};
 
575
                for(int i=0; i < 8; i++)
 
576
                {
 
577
                        wxMenuItem* pItem = new ItemFrameRate(pMenuFrameRate,titulos[i],this,periodos[i]);
 
578
                        pMenuFrameRate->Append(pItem);
 
579
                        if(periodos[i] == m_PeriodoMs) {
 
580
                                pItem->Check(true);
 
581
                        }
 
582
                }
 
583
 
 
584
                wxMenuItem* pItem = new wxMenuItem(&menuVer,wxID_ANY,_("Loop"),_("Repeat on end"),wxITEM_CHECK);
 
585
                #ifdef __WXMSW__
 
586
                pItem->SetBitmaps(APrimResourcesManager::BarraCine::GetIcoBucle(),APrimResourcesManager::BarraCine::GetIcoNoBucle());
 
587
                //#else
 
588
                //pItem->SetBitmap(APrimResourcesManager::BarraCine::GetIcoBucle());
 
589
                #endif
 
590
                //este apend suelta por consola: 'InsertMenuItem()' failed with error 0x00000057, es un buf arreglado pero no afecta negativamente,
 
591
                // es xq solo tiene un bitmap mas info:
 
592
                //http://trac.wxwidgets.org/ticket/9878
 
593
                menuVer.Append(pItem);
 
594
                //
 
595
                menuVer.Check(pItem->GetId(),m_ReproducirBucle);
 
596
                menuVer.Connect(pItem->GetId(),wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GVistaCompleja::OnBucleClick ),NULL,this);
 
597
 
 
598
                if(!m_playTimer->IsRunning()){
 
599
                        pItem = new wxMenuItem(&menuVer,wxID_ANY,_("Play"),_("Start playback"));
 
600
                        #ifdef __WXMSW__
 
601
                        pItem->SetBitmaps(APrimResourcesManager::BarraCine::GetIcoPlay());
 
602
                        #else
 
603
                        pItem->SetBitmap(APrimResourcesManager::BarraCine::GetIcoPlay());
 
604
                        #endif
 
605
                        menuVer.Append(pItem);
 
606
                        menuVer.Connect(pItem->GetId(),wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GVistaCompleja::OnPlayStopClick ),NULL,this);
 
607
                } else {
 
608
                        pItem = new wxMenuItem(&menuVer,wxID_ANY,_("Stop"),_("End playback"));
 
609
                        #ifdef __WXMSW__
 
610
                        pItem->SetBitmaps(APrimResourcesManager::BarraCine::GetIcoPause());
 
611
                        #else
 
612
                        pItem->SetBitmap(APrimResourcesManager::BarraCine::GetIcoPause());
 
613
                        #endif
 
614
                        menuVer.Append(pItem);
 
615
                        menuVer.Connect(pItem->GetId(),wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GVistaCompleja::OnPlayStopClick ),NULL,this);
 
616
                }
 
617
 
 
618
                wxRect rect = tb->GetToolRect(evt.GetId());
 
619
                wxPoint pt = tb->ClientToScreen(rect.GetBottomLeft());
 
620
                pt = ScreenToClient(pt);
 
621
 
 
622
 
 
623
                PopupMenu(&menuVer, pt);
 
624
 
 
625
                // make sure the button is "un-stuck"
 
626
                tb->SetToolSticky(evt.GetId(), false);
 
627
        }
 
628
}
 
629
 
 
630
void GVistaCompleja::OnMenuLayout(wxCommandEvent &event)
 
631
{
 
632
        IVista->OnFocus();
 
633
        GNC::GCS::IControladorHerramientas* cH = IVista->GetEstudio()->Entorno->GetControladorHerramientas();
 
634
        try {
 
635
                //////HERRAMIENTA layout ventana////
 
636
                GNC::GCS::IHerramientaLayoutVentana*  hLayout = NULL;
 
637
                hLayout = cH->ObtenerHerramientaConcreta<GNC::GCS::IHerramientaLayoutVentana>(GNC::GCS::IHerramientaLayoutVentana::ID);
 
638
                if (hLayout != NULL) {
 
639
                        wxMenu* pMenuLayout = hLayout->GetMenu(this);
 
640
                        m_pBarraIzquierda->PopupMenu(pMenuLayout);
 
641
                        delete pMenuLayout;
 
642
                }
 
643
        }
 
644
        catch (GNC::GCS::ControladorHerramientasException& ex) {
 
645
                std::cerr << "Error al obtener la herramienta puntero: No se pudo subscribir la herramienta: " << ex.getCause() << std::endl;
 
646
        }
 
647
}
 
648
 
 
649
void GVistaCompleja::OnDesencajar(wxCommandEvent &event)
 
650
{
 
651
        IVista->OnFocus();
 
652
        GNC::GCS::IControladorHerramientas* cH = IVista->GetEstudio()->Entorno->GetControladorHerramientas();
 
653
        try {
 
654
                GNC::GCS::IHerramientaDesencajar*  hDesencajar = NULL;
 
655
                hDesencajar = cH->ObtenerHerramientaConcreta<GNC::GCS::IHerramientaDesencajar>(GNC::GCS::IHerramientaDesencajar::ID);
 
656
                if (hDesencajar != NULL) {
 
657
                        if(hDesencajar->IsDesencajada()) {
 
658
                                m_pBarraIzquierda->SetToolShortHelp(ID_BOTON_DESENCAJAR,_("Disengage Vista"));
 
659
                        } else {
 
660
                                m_pBarraIzquierda->SetToolShortHelp(ID_BOTON_DESENCAJAR,_("Fit View"));
 
661
                        }
 
662
                        hDesencajar->Desencajar(IVista);
 
663
                }
 
664
        }
 
665
        catch (GNC::GCS::ControladorHerramientasException& ex) {
 
666
                std::cerr << "Error al obtener la herramienta puntero: No se pudo subscribir la herramienta: " << ex.getCause() << std::endl;
 
667
        }
 
668
}
 
669
void GVistaCompleja::OnRotateLeft(wxCommandEvent &event)
 
670
{
 
671
        for (TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
672
                (*it)->Rotar(false);
 
673
        }
 
674
}
 
675
 
 
676
void GVistaCompleja::OnRotateRight(wxCommandEvent &event)
 
677
{
 
678
        for (TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
679
                (*it)->Rotar(true);
 
680
        }       
 
681
}
 
682
 
 
683
void GVistaCompleja::OnFlipVertical(wxCommandEvent &event)
 
684
{
 
685
        for (TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
686
                (*it)->Flip(true);
 
687
        }
 
688
}
 
689
 
 
690
void GVistaCompleja::OnFlipHorizontal(wxCommandEvent &event)
 
691
{
 
692
        for (TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
693
                (*it)->Flip(false);
 
694
        }
 
695
}
 
696
 
 
697
void GVistaCompleja::ActualizarMaxMinSlider()
 
698
{
 
699
        //depende de m_MinSlice y m_MaxSlice;
 
700
        //tb depende del numero de vistasimples
 
701
        int minSlider = m_MinSlice;
 
702
        int maxSlider = ((m_MaxSlice - m_MinSlice) +1)  - (m_pSizerSeries->GetRows() * m_pSizerSeries->GetCols());
 
703
        if (minSlider < maxSlider) {
 
704
                m_pSliderSlice->SetRange(minSlider, maxSlider);
 
705
                m_pSliderSlice->Enable(true);
 
706
                if( !m_pBarraCine->IsShown() ) {
 
707
                        m_pBarraCine->SetToolBitmap(ID_BOTON_PLAY_STOP, APrimResourcesManager::BarraCine::GetIcoPlay());
 
708
                        m_pBarraCine->SetToolShortHelp(ID_BOTON_PLAY_STOP, _("Play"));
 
709
                        m_pBarraCine->Enable(true);
 
710
                        m_pBarraCine->Show(true);
 
711
                }
 
712
                m_pSliderSlice->Show(true);
 
713
                m_pBarraDerecha->Show(true);
 
714
                m_pBarraDerecha->Refresh();
 
715
        } else {
 
716
                m_pSliderSlice->SetRange(0, 1);
 
717
                if(m_ListaSincronizacion.size()>0)
 
718
                {
 
719
                        Sincronizar(false);
 
720
                }
 
721
                if(m_playTimer->IsRunning()) {
 
722
                        Stop();
 
723
                }
 
724
                m_pBarraCine->Hide();
 
725
                m_pSliderSlice->Show(false);
 
726
                m_pBarraDerecha->Show(false);
 
727
        }
 
728
}
 
729
 
 
730
void GVistaCompleja::SetPeriodo(int milisegundos)
 
731
{
 
732
        if(milisegundos>0) {
 
733
                m_PeriodoMs = milisegundos;
 
734
                if(m_playTimer->IsRunning()){
 
735
                        m_playTimer->Stop();
 
736
                        m_playTimer->Start(m_PeriodoMs);
 
737
                }
 
738
        }
 
739
}
 
740
 
 
741
void GVistaCompleja::OnFocus(wxChildFocusEvent &)
 
742
{
 
743
        IVista->OnFocus();
 
744
}
 
745
 
 
746
void GVistaCompleja::OnSize(wxSizeEvent &)
 
747
{
 
748
        Layout();
 
749
}
 
750
 
 
751
void GVistaCompleja::OnZSliderScroll (wxScrollEvent& event) {
 
752
        int pos = event.GetPosition() - m_posicion;
 
753
 
 
754
        if(pos!=0){
 
755
                GoToSlice(event.GetPosition(), false);
 
756
        }
 
757
        event.Skip(false);
 
758
}
 
759
 
 
760
void GVistaCompleja::OnKeyDown( wxKeyEvent& event )
 
761
{
 
762
        switch(event.GetKeyCode()){
 
763
                case WXK_RIGHT:
 
764
                        {
 
765
                                GoToSlice(1);
 
766
                        }
 
767
                        break;
 
768
                case WXK_LEFT:
 
769
                        {
 
770
                                GoToSlice(-1);
 
771
                        }
 
772
                        break;
 
773
                case WXK_ESCAPE:
 
774
                        {
 
775
                                GNC::GCS::ISolicitadorCambioHerramienta* solicitador = dynamic_cast<GNC::GCS::ISolicitadorCambioHerramienta*>(IVista->GetEstudio()->Entorno->GetControladorHerramientas());
 
776
                                if(solicitador!=NULL){
 
777
                                        solicitador->SolicitarActivacion(IVista->GetEstudio()->Entorno->GetControladorHerramientas()->ObtenerHerramienta(GNC::GCS::IHerramientaPuntero::ID));
 
778
                                }
 
779
                        }
 
780
                        break;
 
781
                default:
 
782
                        event.Skip(true);
 
783
        }
 
784
}
 
785
 
 
786
void GVistaCompleja::OnMouseWheel(wxMouseEvent& event)
 
787
{
 
788
        if (event.ControlDown())
 
789
        {
 
790
                if (event.ShiftDown()) {
 
791
                        for (TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
792
                                if(event.GetWheelRotation() > 0)
 
793
                                {
 
794
                                        (*it)->GoToTSlice(-1);
 
795
                                }
 
796
                                else
 
797
                                {
 
798
                                        (*it)->GoToTSlice(1);
 
799
                                }
 
800
                        }
 
801
                } else {
 
802
                        if(event.GetWheelRotation() > 0)
 
803
                        {
 
804
                                GoToSlice(1);
 
805
                        }
 
806
                        else
 
807
                        {
 
808
                                GoToSlice(-1);
 
809
                        }
 
810
                }
 
811
        } 
 
812
}
 
813
 
 
814
void GVistaCompleja::OnPlayStopClick(wxCommandEvent &){
 
815
        if(!m_playTimer->IsRunning()) {
 
816
                Play();
 
817
        } else {
 
818
                Stop();
 
819
        }
 
820
}
 
821
 
 
822
void GVistaCompleja::Play()
 
823
{
 
824
        if(!m_ReproducirBucle && m_pSliderSlice->GetValue() == m_pSliderSlice->GetMax()){
 
825
                GoToSlice(0,false);
 
826
        }
 
827
        m_playTimer->Start(m_PeriodoMs);
 
828
        m_pBarraCine->SetToolBitmap(ID_BOTON_PLAY_STOP, APrimResourcesManager::BarraCine::GetIcoStop());
 
829
        m_pBarraCine->SetToolShortHelp(ID_BOTON_PLAY_STOP, _("Stop"));
 
830
        m_pBarraCine->Refresh();
 
831
 
 
832
        AtencionPrimaria::Eventos::EventoSincronizacion* evt = new AtencionPrimaria::Eventos::EventoSincronizacion(IVista,AtencionPrimaria::Eventos::EventoSincronizacion::Play);
 
833
        IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(evt);
 
834
}
 
835
 
 
836
void GVistaCompleja::Stop()
 
837
{
 
838
        //stop
 
839
        m_playTimer->Stop();
 
840
        m_pBarraCine->SetToolBitmap(ID_BOTON_PLAY_STOP, APrimResourcesManager::BarraCine::GetIcoPlay());
 
841
        m_pBarraCine->SetToolShortHelp(ID_BOTON_PLAY_STOP, _("Play"));
 
842
        m_pBarraCine->Refresh();
 
843
 
 
844
        AtencionPrimaria::Eventos::EventoSincronizacion* evt = new AtencionPrimaria::Eventos::EventoSincronizacion(IVista,AtencionPrimaria::Eventos::EventoSincronizacion::Stop);
 
845
        IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(evt);
 
846
}
 
847
 
 
848
void GVistaCompleja::OnBucleClick(wxCommandEvent &){
 
849
        m_ReproducirBucle = !m_ReproducirBucle;
 
850
}
 
851
 
 
852
void GVistaCompleja::OnTimer()
 
853
{
 
854
        if((m_pSliderSlice->GetValue() +1 ) >m_pSliderSlice->GetMax() && m_ReproducirBucle){
 
855
                GoToSlice(0,false);
 
856
        } else {
 
857
                GoToSlice(1);
 
858
 
 
859
                if(m_pSliderSlice->GetValue()  == m_pSliderSlice->GetMax() && !m_ReproducirBucle){
 
860
                        Stop();
 
861
                }
 
862
        }
 
863
}
 
864
 
 
865
//contrato widgets
 
866
vtkGinkgoImageViewer* GVistaCompleja::GetViewer()
 
867
{
 
868
        // TODO Excepciones
 
869
        vtkGinkgoImageViewer* viewer = m_VistasSimples[0]->ViewImage2D;
 
870
        for (TListaGVistasSimples::iterator it = m_VistasSimples.begin(); viewer == NULL && it != m_VistasSimples.end(); it++)
 
871
        {
 
872
                if (m_pManager->GetRendererActivo() == (*it)->ViewInteractor2D)
 
873
                {
 
874
                        viewer = (*it)->ViewImage2D;
 
875
                }
 
876
        }
 
877
        return viewer;
 
878
}
 
879
 
 
880
 
 
881
//region "Realizacion de la interfaz IAnnotator"
 
882
std::string GVistaCompleja::GetTopLeftAnnotation(GNC::GCS::Contexto3D* c)
 
883
{
 
884
        GNC::GCS::IWidgetsRenderer* r = ( c == NULL? NULL : c->GetRenderer());
 
885
        if (r == NULL) {
 
886
                return m_VistasSimples[0]->GetTopLeftAnnotation(c);
 
887
        } else {
 
888
                for (TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
889
                        if ( (*it)->ViewInteractor2D == r) {
 
890
                                return (*it)->GetTopLeftAnnotation(c);
 
891
                        }
 
892
                }
 
893
        }
 
894
        return "";
 
895
}
 
896
 
 
897
std::string GVistaCompleja::GetTopRightAnnotation(GNC::GCS::Contexto3D* c)
 
898
{
 
899
        GNC::GCS::IWidgetsRenderer* r = ( c == NULL? NULL : c->GetRenderer());
 
900
        if (r == NULL) {
 
901
                return m_VistasSimples[0]->GetTopRightAnnotation(c);
 
902
        } else {
 
903
                for (TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
904
                        if ( (*it)->ViewInteractor2D == r) {
 
905
                                return (*it)->GetTopRightAnnotation(c);
 
906
                        }
 
907
                }
 
908
        }
 
909
        return "";
 
910
}
 
911
 
 
912
std::string GVistaCompleja::GetBottomLeftAnnotation(GNC::GCS::Contexto3D* c)
 
913
{
 
914
        GNC::GCS::IWidgetsRenderer* r = ( c == NULL? NULL : c->GetRenderer());
 
915
        if (r == NULL) {
 
916
                return m_VistasSimples[0]->GetBottomLeftAnnotation(c);
 
917
        } else {
 
918
                for (TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
919
                        if ( (*it)->ViewInteractor2D == r) {
 
920
                                return (*it)->GetBottomLeftAnnotation(c);
 
921
                        }
 
922
                }
 
923
        }
 
924
        return "";
 
925
}
 
926
 
 
927
std::string GVistaCompleja::GetBottomRightAnnotation(GNC::GCS::Contexto3D* c)
 
928
{
 
929
        GNC::GCS::IWidgetsRenderer* r = ( c == NULL? NULL : c->GetRenderer());
 
930
        if (r == NULL) {
 
931
                return m_VistasSimples[0]->GetBottomRightAnnotation(c);
 
932
        } else {
 
933
                for (TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
934
                        if ( (*it)->ViewInteractor2D == r) {
 
935
                                return (*it)->GetBottomRightAnnotation(c);
 
936
                        }
 
937
                }
 
938
        }
 
939
        return "";
 
940
}
 
941
 
 
942
std::string GVistaCompleja::GetAnotacionPosicion(GNC::GCS::Vector* pPosicion)
 
943
{
 
944
        GNC::GCS::IWidgetsRenderer* r = GNC::GCS::IContratoWidgets::m_pManager->GetRendererActivo();
 
945
        for (TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
946
                if ( (*it)->ViewInteractor2D == r) {
 
947
                        return (*it)->GetAnotacionPosicion(pPosicion);
 
948
                }
 
949
        }
 
950
        return "";
 
951
}
 
952
//endregion
 
953
 
 
954
// Asigna los valores de los apuntadores a la la imagen y el slice actual
 
955
void GVistaCompleja::AsignarConexionesDeFiltrado(vtkImageData** pImagen, int* slice, vtkImageData** pChroma)
 
956
{
 
957
        /*
 
958
        *pImagen = m_pImagenOriginal;
 
959
        if(m_VistasSimples.size() > 0) {
 
960
                *slice = m_VistasSimples[0]->ViewImage2D->GetZSlice();
 
961
        }
 
962
        */
 
963
}
 
964
 
 
965
void GVistaCompleja::ActualizarImagen()
 
966
{
 
967
        //m_pImagenOriginal->Modified();
 
968
        IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(new GNC::GCS::Eventos::EventoModificacionImagen(IVista,GNC::GCS::Eventos::EventoModificacionImagen::ImagenModificada, -1));
 
969
}
 
970
 
 
971
//----------DIALOGO SINCRONIZACION...-------------
 
972
class DialogoSincronizacion: public DialogoSincronizacionBase {
 
973
public:
 
974
        typedef std::vector<GNKVisualizator::Vista2D*>  TipoListaVistas;
 
975
        DialogoSincronizacion(wxWindow* parent, TipoListaVistas listaVistas):DialogoSincronizacionBase(parent){
 
976
                m_lista = listaVistas;
 
977
                for(TipoListaVistas::iterator it = listaVistas.begin(); it!=listaVistas.end(); it++){
 
978
                        m_pCheckListVistas->AppendString(wxString::FromUTF8((*it)->GetTitulo().c_str()));
 
979
                }
 
980
                Layout();
 
981
        }
 
982
 
 
983
        ~DialogoSincronizacion(){
 
984
 
 
985
        }
 
986
 
 
987
        void OnAceptarClick(wxCommandEvent &event){
 
988
                EndModal(wxID_OK);
 
989
        }
 
990
 
 
991
        TipoListaVistas GetVistasSeleccionadas(){
 
992
                TipoListaVistas resultado;
 
993
                wxArrayInt selecciones;
 
994
                for(unsigned int i=0; i<m_pCheckListVistas->GetCount();i++){
 
995
                        //se busca la vista
 
996
                        for(TipoListaVistas::iterator itVistas = m_lista.begin(); itVistas!= m_lista.end(); ++itVistas){
 
997
                                if(m_pCheckListVistas->IsChecked(i)){
 
998
                                        resultado.push_back(m_lista[i]);
 
999
                                        break;
 
1000
                                }
 
1001
                        }
 
1002
                }
 
1003
                return resultado;
 
1004
        }
 
1005
 
 
1006
protected:
 
1007
        TipoListaVistas m_lista;
 
1008
};
 
1009
 
 
1010
//---------- end DIALOGO SINCRONIZACION...-------------
 
1011
 
 
1012
void GVistaCompleja::OnSincronizarClick(wxCommandEvent &event)
 
1013
{
 
1014
        bool enabled = m_pBarraDerecha->GetToolToggled(ID_BOTON_SINCRONIZAR);
 
1015
        Sincronizar(enabled);
 
1016
}
 
1017
 
 
1018
void GVistaCompleja::Sincronizar(bool sincronizar)
 
1019
{
 
1020
        //si esta toogled...
 
1021
        if(!sincronizar) {
 
1022
                //dessincronizar
 
1023
                //si esta reproduciendose se para
 
1024
                Stop();
 
1025
                //
 
1026
                DesSincronizar();
 
1027
        } else {
 
1028
                //sincronizar
 
1029
                typedef GNC::GCS::IControladorVistas::TipoListaVistas TipoListaIVistas;
 
1030
 
 
1031
                TipoListaVista2D lista;
 
1032
                {
 
1033
                        TipoListaIVistas listaTmp = IVista->GetEstudio()->Entorno->GetControladorVistas()->GetVistas();
 
1034
 
 
1035
                        //pillamos las vistas simples
 
1036
                        for(TipoListaIVistas::iterator it = listaTmp.begin(); it!= listaTmp.end(); it++){
 
1037
                                GNKVisualizator::Vista2D* v = dynamic_cast<GNKVisualizator::Vista2D*> ((*it));
 
1038
                                if(v!=NULL && v!=IVista && v->GVista->EsSincronizable()){
 
1039
                                        lista.push_back(v);
 
1040
                                }
 
1041
                        }
 
1042
                }
 
1043
 
 
1044
                DialogoSincronizacion* dialogoSincronizacion = new DialogoSincronizacion(this, lista);
 
1045
                int answer = dialogoSincronizacion->ShowModal();
 
1046
                if (answer == wxID_OK) {
 
1047
                        //se pillan las vistas seleccionadas
 
1048
                        lista = dialogoSincronizacion->GetVistasSeleccionadas();
 
1049
                        if(lista.size()>0){
 
1050
                                //nos metemos en la lista
 
1051
                                lista.push_back(IVista);
 
1052
                                //y ahora sincronizamos a tol mundo
 
1053
                                for(DialogoSincronizacion::TipoListaVistas::iterator it = lista.begin(); it!= lista.end(); it++){
 
1054
                                        (*it)->GVista->Sincronizar(lista);
 
1055
                                }
 
1056
                                m_pBarraDerecha->ToggleTool(ID_BOTON_SINCRONIZAR,true);
 
1057
                                m_pBarraDerecha->Refresh();
 
1058
                        } else {
 
1059
                                m_pBarraDerecha->ToggleTool(ID_BOTON_SINCRONIZAR,false);
 
1060
                                m_pBarraDerecha->Refresh();
 
1061
                        }
 
1062
                }
 
1063
        }
 
1064
}
 
1065
 
 
1066
void GVistaCompleja::Sincronizar(const TipoListaVista2D& lista)
 
1067
{
 
1068
        //si esta reproduciendose se para
 
1069
        Stop();
 
1070
        //se suscribe a los eventos de los brothers
 
1071
        for(TipoListaVista2D::const_iterator it = lista.begin(); it!= lista.end(); it++){
 
1072
                if((*it) != IVista){
 
1073
                        AtencionPrimaria::Eventos::EventoSincronizacion evento((*it));
 
1074
                        IVista->GetEstudio()->Entorno->GetControladorEventos()->Registrar(this,evento);
 
1075
                        m_ListaSincronizacion.push_back((*it));
 
1076
                }
 
1077
        }
 
1078
        m_pBarraDerecha->ToggleTool(ID_BOTON_SINCRONIZAR,true);
 
1079
        m_pBarraDerecha->Refresh();
 
1080
}
 
1081
 
 
1082
bool GVistaCompleja::EsSincronizable(){
 
1083
        return (m_ListaSincronizacion.size() == 0) && m_pSliderSlice->IsShown();
 
1084
}
 
1085
 
 
1086
void GVistaCompleja::DesSincronizar(){
 
1087
        for(TipoListaVista2D::iterator it = m_ListaSincronizacion.begin(); it!= m_ListaSincronizacion.end(); it++){
 
1088
                AtencionPrimaria::Eventos::EventoSincronizacion eventoOtro((*it));
 
1089
                IVista->GetEstudio()->Entorno->GetControladorEventos()->DesRegistrar(this,eventoOtro);
 
1090
        }
 
1091
        m_ListaSincronizacion.clear();
 
1092
 
 
1093
        m_pBarraCine->Enable(true);
 
1094
        m_pBarraCine->Refresh();
 
1095
 
 
1096
        //dessincronizamos
 
1097
        AtencionPrimaria::Eventos::EventoSincronizacion* evento = new AtencionPrimaria::Eventos::EventoSincronizacion(IVista,AtencionPrimaria::Eventos::EventoSincronizacion::Dessincronizar);
 
1098
        IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(evento);
 
1099
 
 
1100
        m_pBarraDerecha->ToggleTool(ID_BOTON_SINCRONIZAR,false);
 
1101
        m_pBarraDerecha->Refresh();
 
1102
}
 
1103
 
 
1104
void GVistaCompleja::GoToSlice(int pos, bool relativa, bool propagar, bool render){
 
1105
        if (m_MaxSlice == m_MinSlice) {
 
1106
                return;
 
1107
        }
 
1108
        int posicion;
 
1109
 
 
1110
        if(relativa){
 
1111
                posicion = m_pSliderSlice->GetValue() + pos;
 
1112
        }else{
 
1113
                posicion = pos;
 
1114
        }
 
1115
 
 
1116
        posicion = std::max(m_pSliderSlice->GetMin(), std::min(m_pSliderSlice->GetMax(), posicion));
 
1117
 
 
1118
        //si la posicion + las que se muestran en el layout actual es mayor al número de slices de la serie, no se avanza
 
1119
 
 
1120
        if(posicion + ( (int) m_VistasSimples.size() ) > IVista->GetEstudio()->GetNumeroCortes()) {
 
1121
                return;
 
1122
        }
 
1123
 
 
1124
        m_pSliderSlice->SetValue(posicion);
 
1125
        m_posicion = posicion;
 
1126
 
 
1127
        //se reestablece el window/level antes del evento de modificación porque ese evento lo escucha la herramienta
 
1128
        GNC::GCS::IContratoWindowLevel::Setup(*IVista->GetEstudio()->GetTagsImagenDeImagenActiva());
 
1129
 
 
1130
        //se le indica al manager el vid
 
1131
        IVista->GetEstudio()->IndiceFicheroActivo = posicion;
 
1132
        for(TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
1133
                (*it)->GoToSlice(posicion,false,false);
 
1134
 
 
1135
                //despues se establece el WL
 
1136
                if (HasCurrentWindowLevel()) {
 
1137
                        GNC::GCS::IContratoWindowLevel::WindowLevel wl = GetCurrentWindowLevel();
 
1138
                        (*it)->ViewImage2D->SetDefaultWindowLevel(wl.m_window, wl.m_level);
 
1139
                } else if (HasDefaultWindowLevel()) {
 
1140
                        GNC::GCS::IContratoWindowLevel::WindowLevel wl = GetAndSetDefaultWindowLevel();
 
1141
                        (*it)->ViewImage2D->SetDefaultWindowLevel(wl.m_window, wl.m_level);                     
 
1142
                } else {
 
1143
                        (*it)->ViewImage2D->SetAutoDefaultWindowLevel();
 
1144
                }
 
1145
 
 
1146
                if(IVista->VisualizatorStudy->TieneOverlaysImagen(posicion)) {
 
1147
                        GNKVisualizator::TListaOverlays* pLista = IVista->VisualizatorStudy->GetOverlaysImagen(posicion);
 
1148
                        (*it)->SetOverlays(pLista,m_EstadoOverlays);
 
1149
                } else {
 
1150
                        (*it)->SetOverlays(NULL, m_EstadoOverlays);
 
1151
                }
 
1152
                posicion++;
 
1153
        }
 
1154
                
 
1155
        
 
1156
        GNC::GCS::Eventos::EventoModificacionImagen* pEvt = new GNC::GCS::Eventos::EventoModificacionImagen(IVista,GNC::GCS::Eventos::EventoModificacionImagen::SliceCambiado, -1, render);
 
1157
        IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(pEvt);
 
1158
 
 
1159
        if(propagar){
 
1160
                IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(new AtencionPrimaria::Eventos::EventoSincronizacion(IVista, AtencionPrimaria::Eventos::EventoSincronizacion::Scroll,pos,relativa));
 
1161
        }
 
1162
}
 
1163
 
 
1164
void GVistaCompleja::PreProcesarEvento(GNC::GCS::Eventos::IEvento* evt, GNC::GCS::IControladorEventos::TipoListaPunterosEventos& lista)
 
1165
{
 
1166
        if (evt == NULL) {
 
1167
                std::cerr << "Error: Evento nulo" << std::endl;
 
1168
                return;
 
1169
        }
 
1170
        switch (evt->GetCodigoEvento()) {
 
1171
                case ginkgoEVT_GNKVisualizator_EventoSincronizacion:
 
1172
                        {
 
1173
                                AtencionPrimaria::Eventos::EventoSincronizacion* pEvt = dynamic_cast<AtencionPrimaria::Eventos::EventoSincronizacion*>(evt);
 
1174
                                if (pEvt == NULL) {
 
1175
                                        std::cerr << "Error al interpretar evento como evento de sincronización: Evento = " << evt << std::endl;
 
1176
                                        return;
 
1177
                                }
 
1178
                                if (pEvt->GetTipoEvento() != AtencionPrimaria::Eventos::EventoSincronizacion::Scroll) {
 
1179
                                        return;
 
1180
                                }
 
1181
                                int posicion = pEvt->GetPosicion();
 
1182
                                if(pEvt->EsRelativa()){
 
1183
                                        posicion += m_pSliderSlice->GetValue();
 
1184
                                }
 
1185
                                posicion = std::max(m_pSliderSlice->GetMin(), std::min(m_pSliderSlice->GetMax(), posicion));
 
1186
                        }
 
1187
                        break;
 
1188
                case ginkgoEVT_Core_ModificacionImagen:
 
1189
                        {
 
1190
                                GNC::GCS::Eventos::EventoModificacionImagen* pEvt = dynamic_cast<GNC::GCS::Eventos::EventoModificacionImagen*>(evt);
 
1191
                                if (pEvt == NULL) {
 
1192
                                        std::cerr << "Error al interpretar evento como evento de modificación de imagen: Evento = " << evt << std::endl;
 
1193
                                        return;
 
1194
                                }
 
1195
                                switch (pEvt->GetTipo()) {
 
1196
                                        case GNC::GCS::Eventos::EventoModificacionImagen::ImagenRecalibrada:
 
1197
                                                {
 
1198
                                                        lista.push_back(new GNC::GCS::Eventos::EventoModificacionImagen(IVista,GNC::GCS::Eventos::EventoModificacionImagen::ImagenCargada, -1));
 
1199
                                                        lista.push_back(new GNC::GCS::Eventos::EventoModificacionFichero(IVista,GNC::GCS::Eventos::EventoModificacionFichero::FicheroModificado));
 
1200
                                                }
 
1201
                                                break;
 
1202
                                        default:
 
1203
                                                break;
 
1204
                                }
 
1205
                                if (pEvt->GetApilarRender()) {
 
1206
                                        lista.push_back(new GNC::GCS::Eventos::EventoRender(IVista,pEvt->GetSliceAfectado()));
 
1207
                                }
 
1208
                        }
 
1209
                        break;
 
1210
                case ginkgoEVT_Core_ModificacionWidget:
 
1211
                        {
 
1212
                                GNC::GCS::Eventos::EventoModificacionWidget* pEvt = dynamic_cast<GNC::GCS::Eventos::EventoModificacionWidget*>(evt);
 
1213
                                if (pEvt == NULL) {
 
1214
                                        std::cerr << "Error al interpretar evento como evento de modificación de widget: Evento = " << evt << std::endl;
 
1215
                                        return;
 
1216
                                }
 
1217
                                // TODO: Este flujo es muy mejorable
 
1218
                                lista.push_back(new GNC::GCS::Eventos::EventoModificacionFichero(IVista,GNC::GCS::Eventos::EventoModificacionFichero::FicheroModificado,IVista));
 
1219
                        }
 
1220
                        break;
 
1221
                case ginkgoEVT_GNKVisualizator_EventoMostrarOverlay:
 
1222
                        {
 
1223
                                lista.push_back(new GNC::GCS::Eventos::EventoRender(IVista));
 
1224
                        }
 
1225
                        break;
 
1226
                default:
 
1227
                        break;
 
1228
        }
 
1229
}
 
1230
 
 
1231
void GVistaCompleja::ProcesarEvento(GNC::GCS::Eventos::IEvento *evt)
 
1232
{
 
1233
        switch (evt->GetCodigoEvento()) {
 
1234
                case ginkgoEVT_GNKVisualizator_EventoSincronizacion:
 
1235
                        {
 
1236
                                AtencionPrimaria::Eventos::EventoSincronizacion* pEvt = dynamic_cast<AtencionPrimaria::Eventos::EventoSincronizacion*>(evt);
 
1237
                                if(pEvt!=NULL){
 
1238
                                        if(pEvt->GetTipoEvento() == AtencionPrimaria::Eventos::EventoSincronizacion::Scroll){
 
1239
                                                GoToSlice(pEvt->GetPosicion(),pEvt->EsRelativa(),false);
 
1240
                                        } else if (pEvt->GetTipoEvento() == AtencionPrimaria::Eventos::EventoSincronizacion::Play) {
 
1241
                                                m_pBarraCine->Enable(false);
 
1242
                                                m_pBarraCine->Refresh();
 
1243
                                        } else if (pEvt->GetTipoEvento() == AtencionPrimaria::Eventos::EventoSincronizacion::Stop) {
 
1244
                                                m_pBarraCine->Enable(true);
 
1245
                                                m_pBarraCine->Refresh();
 
1246
                                        } else if (pEvt->GetTipoEvento() == AtencionPrimaria::Eventos::EventoSincronizacion::Dessincronizar) {
 
1247
                                                for(TipoListaVista2D::iterator it = m_ListaSincronizacion.begin(); it!= m_ListaSincronizacion.end(); it++){
 
1248
                                                        if((*it) == pEvt->GetVista()){
 
1249
                                                                IVista->GetEstudio()->Entorno->GetControladorEventos()->DesRegistrar(this,*pEvt);
 
1250
                                                                m_ListaSincronizacion.erase(it);
 
1251
                                                                if(m_ListaSincronizacion.size() == 0){
 
1252
                                                                        m_pBarraDerecha->ToggleTool(ID_BOTON_SINCRONIZAR,false);
 
1253
                                                                        m_pBarraDerecha->Refresh();
 
1254
                                                                }
 
1255
                                                                return;
 
1256
                                                        }
 
1257
                                                }
 
1258
                                        }
 
1259
                                }
 
1260
                        }
 
1261
                        break;
 
1262
 
 
1263
                        case ginkgoEVT_Core_ModificacionImagen:
 
1264
                        {
 
1265
                                GNC::GCS::Eventos::EventoModificacionImagen* pEvt = dynamic_cast<GNC::GCS::Eventos::EventoModificacionImagen*>(evt);
 
1266
                                if (pEvt == NULL) {
 
1267
                                        std::cerr << "Error al interpretar evento como evento de modificación de imagen: Evento = " << evt << std::endl;
 
1268
                                        return;
 
1269
                                }
 
1270
                                switch (pEvt->GetTipo()) {
 
1271
                                        case GNC::GCS::Eventos::EventoModificacionImagen::ImagenModificada:
 
1272
                                        case GNC::GCS::Eventos::EventoModificacionImagen::ImagenCargada:
 
1273
                                        case GNC::GCS::Eventos::EventoModificacionImagen::MapaModificado:
 
1274
                                        case GNC::GCS::Eventos::EventoModificacionImagen::SliceCambiado:
 
1275
                                                        {
 
1276
                                                                for(TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
1277
                                                                        (*it)->ViewImage2D->Modified();
 
1278
                                                                }
 
1279
                                                                IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(new GNC::GCS::Eventos::EventoModificacionImagen(IVista,GNC::GCS::Eventos::EventoModificacionImagen::AnotacionesEstaticasModificadas));
 
1280
                                                        }
 
1281
                                                        break;
 
1282
                                        case GNC::GCS::Eventos::EventoModificacionImagen::ImagenRecalibrada:
 
1283
                                                {
 
1284
                                                        
 
1285
                                                                int i = 0;
 
1286
                                                                for(TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++, i++) {
 
1287
                                                                        m_VistasSimples[i]->GetEstudio()->RecalibrarImagenActiva(pEvt->GetNewSpacing(), pEvt->GetNewOrigin());
 
1288
 
 
1289
                                                                        //esto es necesario para establecer bien las coordenadas cuando se cambia el origen
 
1290
                                                                        (*it)->GoToSlice(m_posicion + i,false,false);
 
1291
                                                                        pEvt->SetSlice(-1);
 
1292
                                                                        (*it)->RefrescarOverlays(m_EstadoOverlays);
 
1293
                                                                }
 
1294
                                                                //se vuelve hacer setup del contrato mapa de color
 
1295
                                                        //      GNKVisualizator::IContratoMapaColor::Setup(m_pImagenOriginal);
 
1296
                                                                
 
1297
                                                        
 
1298
                                                }
 
1299
                                        break;
 
1300
                                        case GNC::GCS::Eventos::EventoModificacionImagen::VisualizacionImagenModificada:
 
1301
                                                //para que pille bien el window/level
 
1302
                                                for(TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
1303
                                                        if(pEvt->ResetWindowLevel()) {
 
1304
                                                                if (HasDefaultWindowLevel()) {
 
1305
                                                                        GNC::GCS::IContratoWindowLevel::WindowLevel wl = GetAndSetDefaultWindowLevel();
 
1306
                                                                        (*it)->ViewImage2D->SetDefaultWindowLevel(wl.m_window, wl.m_level);                     
 
1307
                                                                } else {
 
1308
                                                                        (*it)->ViewImage2D->SetAutoDefaultWindowLevel();
 
1309
                                                                }
 
1310
                                                                (*it)->ViewImage2D->ResetToDefaultWindowLevel();
 
1311
                                                        } else {
 
1312
                                                                (*it)->ViewImage2D->SetWindow(pEvt->GetWindow());
 
1313
                                                                (*it)->ViewImage2D->SetLevel(pEvt->GetLevel());
 
1314
                                                                //(*it)->ViewImage2D->UpdateImage();
 
1315
                                                                for(TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
1316
                                                                    //(*it)->ViewInteractor2D->Refresh(false);
 
1317
                                                                    //(*it)->ViewInteractor2D->Render();
 
1318
                                                                }
 
1319
                                                        }
 
1320
                                                        if(pEvt->ResetCurrentPoint())
 
1321
                                                        {
 
1322
                                                                /*
 
1323
                                                                double* bounds  = (*it)->ViewImage2D->GetInput()->GetBounds();
 
1324
                                                                const double* currentPoint = (*it)->ViewImage2D->GetCurrentPoint();
 
1325
                                                                double  pos[3] =
 
1326
                                                                {
 
1327
                                                                        (bounds[0]+bounds[1])/2.0,
 
1328
                                                                        (bounds[2]+bounds[3])/2.0,
 
1329
                                                                        currentPoint[2]
 
1330
                                                                };
 
1331
 
 
1332
                                                                (*it)->ViewImage2D->SetCurrentPoint(pos);
 
1333
                                                                */
 
1334
                                                        }
 
1335
                                                        if(pEvt->ResetZoom())
 
1336
                                                        {
 
1337
                                                                (*it)->ViewImage2D->ResetZoom();
 
1338
                                                        }
 
1339
                                                        //(*it)->ViewImage2D->Modified();
 
1340
                                                }
 
1341
                                                IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(new GNC::GCS::Eventos::EventoModificacionImagen(IVista,GNC::GCS::Eventos::EventoModificacionImagen::AnotacionesEstaticasModificadas));
 
1342
                                        break;
 
1343
                                        case GNC::GCS::Eventos::EventoModificacionImagen::ImagenDescargada:
 
1344
                                        break;
 
1345
                                        case GNC::GCS::Eventos::EventoModificacionImagen::AnotacionesEstaticasModificadas:
 
1346
 
 
1347
                                        break;
 
1348
                                }
 
1349
                        }//fin modificacion
 
1350
                        break;
 
1351
 
 
1352
                case ginkgoEVT_Core_Render:
 
1353
                        {
 
1354
                                for(TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
1355
                                        (*it)->ViewInteractor2D->Refresh(false);
 
1356
                                }
 
1357
                        }
 
1358
                        break;
 
1359
                case ginkgoEVT_Core_ModificacionFichero:
 
1360
                        {
 
1361
                                GNC::GCS::Eventos::EventoModificacionFichero* pEvt = new GNC::GCS::Eventos::EventoModificacionFichero();
 
1362
                                pEvt->SetVista(IVista);
 
1363
                                IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(pEvt);
 
1364
                        }
 
1365
                        break;
 
1366
                case ginkgoEVT_GNKVisualizator_EventoMostrarOverlay:
 
1367
                        {
 
1368
                                for(TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
1369
                                        (*it)->RefrescarOverlays(m_EstadoOverlays);
 
1370
                                        (*it)->ViewImage2D->Modified();
 
1371
                                }
 
1372
                        }
 
1373
                        break;
 
1374
        }
 
1375
}
 
1376
 
 
1377
void GVistaCompleja::SetMapaColor(vtkLookupTable* pTabla, int idLookupTable)
 
1378
{
 
1379
        Freeze();
 
1380
        for(TListaGVistasSimples::iterator it = m_VistasSimples.begin(); it != m_VistasSimples.end(); it++) {
 
1381
                (*it)->ViewImage2D->SetLookupTable(pTabla, idLookupTable);
 
1382
        }
 
1383
        IVista->GetEstudio()->Entorno->GetControladorEventos()->ProcesarEvento(new GNC::GCS::Eventos::EventoRender(IVista));
 
1384
        Thaw();
 
1385
}
 
1386
 
 
1387
 
 
1388
void GVistaCompleja::SetLayoutVentana(int filas, int columnas)
 
1389
{
 
1390
        if(filas <1 || columnas < 1)
 
1391
        {
 
1392
                //layout invalido
 
1393
                return;
 
1394
        }
 
1395
        bool incrementado = false;
 
1396
 
 
1397
        const int maxSlices = m_MaxSlice - m_MinSlice +1;
 
1398
        if(filas*columnas > maxSlices) {
 
1399
                //layout invalido aunque podría ser valido...
 
1400
                filas = (int)std::ceil((double)maxSlices/columnas);
 
1401
        }
 
1402
        Freeze();
 
1403
 
 
1404
        int filasActuales = m_pSizerSeries->GetRows();
 
1405
        int columnasActuales = m_pSizerSeries->GetCols();
 
1406
        int tamAnterior = m_VistasSimples.size();
 
1407
        int nuevoTam = filas*columnas;
 
1408
 
 
1409
        m_pSizerSeries->SetCols(columnas);
 
1410
        m_pSizerSeries->SetRows(filas);
 
1411
 
 
1412
 
 
1413
        //FUNDAMENTAL PARA QUE los viewers se destruyan correctamente y sin leaks ya que Viewer es smart pointer
 
1414
        IVista->VisualizatorStudy->Viewer = NULL;
 
1415
        if(tamAnterior > nuevoTam) {
 
1416
                //hay que borrar
 
1417
                for(int i = 0; i< tamAnterior-nuevoTam; i++) {
 
1418
                        TListaGVistasSimples::iterator pVista = m_VistasSimples.begin();
 
1419
                        m_pManager->LiberarRecursos((*pVista)->ViewInteractor2D);
 
1420
                        m_pSizerSeries->Detach((*pVista));
 
1421
                        (*pVista)->Destroy();
 
1422
 
 
1423
                        m_VistasSimples.erase(pVista);
 
1424
                }
 
1425
        } else {
 
1426
 
 
1427
                //hay que crear
 
1428
                for(unsigned int i = 0; i< (unsigned int) (nuevoTam - tamAnterior) && m_VistasSimples.size() < (unsigned int) maxSlices; i++) {
 
1429
                        incrementado = true;
 
1430
                        AddVistaSimple();
 
1431
                }
 
1432
                //por si la posicion actual es invalida
 
1433
                m_posicion = 0;
 
1434
        }
 
1435
        //FUNDAMENTAL PARA QUE FUNCIONE LA HERRAMIENTA DE MAPAS DE COLOR
 
1436
        IVista->VisualizatorStudy->Viewer = m_VistasSimples[0]->ViewImage2D;
 
1437
        ActualizarMaxMinSlider();
 
1438
        Layout();
 
1439
        //nos quedamos en la posicion
 
1440
        GoToSlice(m_posicion,false,false,false);
 
1441
        Thaw();
 
1442
        if ( (filas > 1 || columnas > 1) && incrementado) { // condición para evitar doble render. Ya se comprueba por otro lado en la creación (con 1 vista).
 
1443
                bool noerror = true;
 
1444
                for(TListaGVistasSimples::iterator it = m_VistasSimples.begin(); noerror && it != m_VistasSimples.end(); it++) {
 
1445
                        GVistaSimple* vs = *it;
 
1446
                        vs->ViewInteractor2D->Render();
 
1447
                        long idTextura = vs->ViewImage2D->GetImageTexture();
 
1448
                        if (idTextura == 0 || !glIsTexture(idTextura)) {
 
1449
                                noerror = false;
 
1450
                        }
 
1451
                }
 
1452
                if (!noerror) {
 
1453
                        SetLayoutVentana(filasActuales, columnasActuales);
 
1454
                        wxMessageBox(_("It has exhausted the system's video memory and has not been able to assign the grid configuration. Close some studies to free memory."), _("Error configuring the grid"), wxOK, NULL);
 
1455
                        return;
 
1456
                }
 
1457
        }
 
1458
}
 
1459
 
 
1460
int GVistaCompleja::GetFilas()
 
1461
{
 
1462
        return m_pSizerSeries->GetRows();
 
1463
}
 
1464
 
 
1465
int GVistaCompleja::GetColumnas()
 
1466
{
 
1467
        return m_pSizerSeries->GetCols();
 
1468
}
 
1469
 
 
1470
vtkScalarsToColors* GVistaCompleja::GetLookupTable()
 
1471
{
 
1472
        if(m_VistasSimples.size()>0) {
 
1473
                return m_VistasSimples[0]->ViewImage2D->GetLookupTable();
 
1474
        } else {
 
1475
                return NULL;
 
1476
        }
 
1477
}
 
1478
 
 
1479
void GVistaCompleja::GetImage(GNC::GCS::IContratoExportacionImages::ImageType::Pointer& img, int index, bool conWidgets, const GNC::GCS::Vector& size)
 
1480
{
 
1481
        if (!IVista->VisualizatorStudy->Viewer->IsInstalledAndInitialized())
 
1482
                return ;
 
1483
 
 
1484
        GNKVisualizator::ImprimeVistaSimple imprimeVistaSimple(GNC::GCS::IContratoWidgets::m_pManager, IVista->VisualizatorStudy, index);
 
1485
 
 
1486
        if(IVista->VisualizatorStudy->Viewer->GetNumberOfComponents() == 3) {
 
1487
                imprimeVistaSimple.PrintImageRGB(img,conWidgets, size);
 
1488
        } else {
 
1489
                vtkScalarsToColors* pTabla = GetLookupTable();
 
1490
                if(pTabla != NULL) {
 
1491
                        imprimeVistaSimple.PrintImage(img, conWidgets, pTabla, size);
 
1492
                }
 
1493
        }
 
1494
}
 
1495
 
 
1496
void GVistaCompleja::SetReconstructionMode(GNKVisualizator::Reconstruction::ReconstructionMode mode)
 
1497
{
 
1498
 
 
1499
        switch (mode) {
 
1500
                case GNKVisualizator::Reconstruction::RM_SurfaceRendering:
 
1501
                        {
 
1502
                                typedef MedicalViewer::Reconstruction::GUI::wxSurfaceRendering TReconstructionWin;
 
1503
                                TReconstructionWin* win = new TReconstructionWin(this, GNKVisualizator::IReconstructionContract::Estudio);
 
1504
                                win->Show(true);                                
 
1505
                        }
 
1506
                        break;
 
1507
                case GNKVisualizator::Reconstruction::RM_VolumeRendering:
 
1508
                        {
 
1509
                                typedef MedicalViewer::Reconstruction::GUI::wxVolumeRendering TReconstructionWin;
 
1510
                                TReconstructionWin* win = new TReconstructionWin(this, GNKVisualizator::IReconstructionContract::Estudio, GetViewer()->GetWindow(), GetViewer()->GetLevel());
 
1511
                                win->Show(true);
 
1512
                        }
 
1513
                        break;
 
1514
                case GNKVisualizator::Reconstruction::RM_OrthogonalMPR:
 
1515
                case GNKVisualizator::Reconstruction::RM_MIP3D:
 
1516
                case GNKVisualizator::Reconstruction::RM_3D_Endoscopy:
 
1517
                case GNKVisualizator::Reconstruction::RM_MaxMode:
 
1518
                        wxMessageBox(_("Reconstruction mode not implemented:\n"), _("Error"), wxICON_ERROR);
 
1519
                        break;
 
1520
                default:
 
1521
                        wxMessageBox(_("Reconstruction mode not supported:\n"), _("Error"), wxICON_ERROR);
 
1522
                        break;
 
1523
                        
 
1524
        }       
 
1525
}