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

« back to all changes in this revision

Viewing changes to src/cadxcore/main/tools/herramientaangulo.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: herramientaangulo.cpp 3526 2011-03-16 19:56:19Z 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
//#define _GINKGO_TRACE
 
15
#include <wx/wx.h>
 
16
#include <wx/aui/aui.h>
 
17
#include <wx/stattext.h>
 
18
#include <wx/xml/xml.h>
 
19
 
 
20
#include <api/globals.h>
 
21
#include <api/iwidgetsmanager.h>
 
22
#include <api/internacionalizacion.h>
 
23
#include "herramientaangulo.h"
 
24
#include <widgets/wangulo.h>
 
25
#include <resources/ginkgoresourcemanager.h>
 
26
 
 
27
#include <iostream>
 
28
 
 
29
#ifdef __DEPRECATED
 
30
#undef __DEPRECATED
 
31
#endif
 
32
#include <vtk/vtkginkgoimageviewer.h>
 
33
 
 
34
#define TIPO_NORMAL 1211
 
35
#define TIPO_COBB   1212
 
36
 
 
37
//----------------------------------------------------------------------
 
38
namespace GNC {
 
39
        namespace GUI {
 
40
                class HerramientaOpcionesAnguloGUI : public AUI_NAMESPACE wxAuiToolBar {
 
41
                public:
 
42
                        HerramientaOpcionesAnguloGUI(wxWindow* pParent, HerramientaAngulo* pHerramienta) : AUI_NAMESPACE wxAuiToolBar(pParent,wxID_ANY, wxDefaultPosition, wxDefaultSize,AUI_NAMESPACE wxAUI_TB_DEFAULT_STYLE )
 
43
                        {
 
44
                                m_pHerramienta=pHerramienta;
 
45
 
 
46
                                SetToolBitmapSize( wxSize( 16,16 ) );
 
47
 
 
48
                                AddLabel(wxID_ANY, _("Type"), 25);
 
49
 
 
50
                                AddTool( TIPO_NORMAL, _("Normal"), GinkgoResourcesManager::BarraAngulo::GetIcoAnguloNormal(), _("Normal Angle (3 points)"),wxITEM_CHECK );
 
51
                                ToggleTool(TIPO_NORMAL,true);
 
52
                                AddTool( TIPO_COBB, _("Cobb"), GinkgoResourcesManager::BarraAngulo::GetIcoAnguloCobb(), _("Cobb Angle (2 straight lines)"), wxITEM_CHECK );
 
53
 
 
54
                                Realize();
 
55
 
 
56
                                Layout();
 
57
 
 
58
                                // Connect Events
 
59
                                this->Connect( TIPO_NORMAL, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( HerramientaOpcionesAnguloGUI::OnTipoAnguloNormalClick ) );
 
60
                                this->Connect( TIPO_COBB, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( HerramientaOpcionesAnguloGUI::OnTipoAnguloCobbClick ) );
 
61
 
 
62
                        };
 
63
 
 
64
                        ~HerramientaOpcionesAnguloGUI() {
 
65
                                this->Disconnect( TIPO_COBB, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( HerramientaOpcionesAnguloGUI::OnTipoAnguloCobbClick ) );
 
66
                                this->Disconnect( TIPO_NORMAL, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( HerramientaOpcionesAnguloGUI::OnTipoAnguloNormalClick ) );
 
67
 
 
68
                        };
 
69
 
 
70
                        virtual void OnTipoAnguloNormalClick(wxCommandEvent& event){
 
71
                                m_pHerramienta->SetTipo(GNC::HerramientaAngulo::TA_Normal);
 
72
                                ToggleTool(TIPO_NORMAL,true);
 
73
                                ToggleTool(TIPO_COBB,false);
 
74
                                event.Skip(false);
 
75
                        }
 
76
 
 
77
                        virtual void OnTipoAnguloCobbClick(wxCommandEvent& event){
 
78
                                m_pHerramienta->SetTipo(GNC::HerramientaAngulo::TA_Cobb);
 
79
                                ToggleTool(TIPO_NORMAL,false);
 
80
                                ToggleTool(TIPO_COBB,true);
 
81
                                event.Skip(false);
 
82
                        }
 
83
                protected:
 
84
                        GNC::HerramientaAngulo* m_pHerramienta;
 
85
                };
 
86
        };
 
87
};
 
88
 
 
89
GNC::HerramientaAngulo::HerramientaAngulo()
 
90
{
 
91
        m_Activa = false;
 
92
        m_TipoAngulo = TA_Normal;
 
93
        m_Descripcion = _Std("Angle");
 
94
        m_Icono = GinkgoResourcesManager::IconosHerramientas::GetIcoAngulo();
 
95
        m_pAnguloBuilder = NULL;
 
96
}
 
97
 
 
98
GNC::HerramientaAngulo::~HerramientaAngulo()
 
99
{
 
100
}
 
101
 
 
102
wxXmlNode* GNC::HerramientaAngulo::Serializar(GNC::GCS::IVista* pVista, long vid, const std::string nombreMedicoSerializa)
 
103
{
 
104
 
 
105
        typedef  GNC::GCS::IContratable<GNC::GCS::IContratoWidgets> ICConcreto;
 
106
        //se cogen todas los widgets regla de los contratos con ese vid
 
107
        GNC::GCS::ListaWidgets listaWidgets;
 
108
        for (ICConcreto::IteradorMapaContratos it = ICConcreto::m_Contratos.begin(); it != ICConcreto::m_Contratos.end(); it++) {
 
109
                if((*it).first == pVista){
 
110
                        for (ICConcreto::IteradorListaContratos it2 = (*it).second->begin(); it2 != (*it).second->end(); it2++) {
 
111
                                GNC::GCS::IContratoWidgets* pC = (*it2);
 
112
                                GNC::GCS::ListaWidgets listaWidgetsTmp;
 
113
                                if(pC->GetManager() != NULL){
 
114
                                        pC->GetManager()->GetListaWidgetsSubVista(vid,listaWidgetsTmp);
 
115
                                        listaWidgets.splice(listaWidgets.begin(),listaWidgetsTmp);
 
116
                                }
 
117
                        }
 
118
                }
 
119
        }
 
120
 
 
121
        wxXmlNode* resultado = NULL;
 
122
        if(listaWidgets.size()>0){
 
123
                resultado = new wxXmlNode(NULL,wxXML_ELEMENT_NODE,wxT("angle"));
 
124
                resultado->AddProperty(wxT("id"),wxString::Format(wxT("%d"),this->ID));
 
125
                for (GNC::GCS::IWidgetsManager::IteradorListaWidgets it = listaWidgets.begin();  it!= listaWidgets.end(); it++){
 
126
                        GNC::GCS::Widgets::WAngulo* pAngulo = dynamic_cast<GNC::GCS::Widgets::WAngulo*>((*it));
 
127
                        if( pAngulo != NULL){
 
128
                                resultado->AddChild(pAngulo->Serializar(nombreMedicoSerializa));
 
129
                        }
 
130
                }
 
131
        }
 
132
        return resultado;
 
133
}
 
134
 
 
135
void GNC::HerramientaAngulo::Deserializar(GNC::GCS::IVista* pVista, long vid, wxXmlNode* nodo)
 
136
{
 
137
        if(nodo->GetPropVal(wxT("id"),wxT("")) != wxString::Format(wxT("%d"),this->ID)){
 
138
                std::cerr<< "Ha ocurrido un error al desserializar la herramienta angulo"<<std::endl;
 
139
        }
 
140
 
 
141
        typedef  GNC::GCS::IContratable<GNC::GCS::IContratoWidgets> ICConcreto;
 
142
 
 
143
        for (ICConcreto::IteradorMapaContratos it = ICConcreto::m_Contratos.begin(); it != ICConcreto::m_Contratos.end(); it++) {
 
144
                if((*it).first == pVista){
 
145
 
 
146
                        for (ICConcreto::IteradorListaContratos it2 = (*it).second->begin(); it2 != (*it).second->end(); it2++) {
 
147
                                GNC::GCS::IContratoWidgets* pC = (*it2);
 
148
 
 
149
                                GNC::GCS::ListaWidgets listaWidgets;
 
150
 
 
151
                                wxXmlNode *child = nodo->GetChildren();
 
152
                                while (child) {
 
153
                                        GNC::GCS::Widgets::WAngulo* pAngulo = new GNC::GCS::Widgets::WAngulo(pC->GetManager(), vid, child);
 
154
                                        listaWidgets.push_back(pAngulo);
 
155
                                        child = child->GetNext();
 
156
                                }
 
157
 
 
158
                                for (GNC::GCS::IWidgetsManager::IteradorListaWidgets itWidgets = listaWidgets.begin();  itWidgets!= listaWidgets.end(); itWidgets++){
 
159
                                        pC->GetManager()->InsertarWidget((*itWidgets),false);
 
160
                                }
 
161
                        }
 
162
                }
 
163
        }
 
164
}
 
165
 
 
166
wxCursor GNC::HerramientaAngulo::GetCursor(){
 
167
        return wxCursor(wxCURSOR_CROSS);
 
168
}
 
169
 
 
170
void GNC::HerramientaAngulo::SetTipo(TipoAngulo tipo)
 
171
{
 
172
        if (m_TipoAngulo != tipo) {
 
173
                m_TipoAngulo = tipo;
 
174
                if (m_pAnguloBuilder != NULL) {
 
175
                        if (m_TipoAngulo == TA_Normal) {
 
176
                                m_pAnguloBuilder->SetModo(GNC::GCS::Widgets::MA_Normal);
 
177
                        }
 
178
                        else {
 
179
                                m_pAnguloBuilder->SetModo(GNC::GCS::Widgets::MA_Cobb);
 
180
                        }
 
181
                }
 
182
        }
 
183
 
 
184
}
 
185
 
 
186
//region "Realizaci�n de la interfaz IHerramienta"
 
187
 
 
188
void GNC::HerramientaAngulo::CrearPaneles(wxPanel* panel)
 
189
{
 
190
        m_pAbstractPanelHerramientaOpciones = new GNC::GUI::HerramientaOpcionesAnguloGUI(panel, this);
 
191
}
 
192
 
 
193
void GNC::HerramientaAngulo::ConectarContratoFalso(bool activar)
 
194
{
 
195
        typedef GNC::GCS::IContratable<GNC::GCS::IContratoWidgets> ICConcreto;
 
196
        if (ICConcreto::m_pListaActiva == NULL) {
 
197
                //std::cerr << "Error: Se trato de activar el modo deshabilitado de una vista sin haber asignado la vista activa. Error en la logica de activacion. Accion ignorada" << std::endl;
 
198
                return;
 
199
        }
 
200
 
 
201
        for (ICConcreto::IteradorListaContratos it = ICConcreto::m_pListaActiva->begin(); it != ICConcreto::m_pListaActiva->end(); it++) {
 
202
                GNC::GCS::IContratoWidgets* pC = (*it);
 
203
                if (pC->Inicializado()) {
 
204
                        if (activar) {
 
205
                                GTRACE("HerramientaAngulo: Conectando contrato falso de vista " << ICConcreto::m_pVistaActiva);
 
206
                                pC->GetViewer()->SetInteractionStyle(vtkGinkgoImageViewer::ZOOM_INTERACTION);
 
207
                                pC->GetManager()->SetCursor(GNC::GCS::Widgets::CUR_FLECHA);
 
208
                        } else {
 
209
                                GTRACE("HerramientaAngulo: Desconectando contrato falso de vista " << ICConcreto::m_pVistaActiva);
 
210
                                pC->GetViewer()->SetInteractionStyle(vtkGinkgoImageViewer::ZOOM_INTERACTION);
 
211
                                pC->GetManager()->SetCursor(GNC::GCS::Widgets::CUR_FLECHA);
 
212
                        }
 
213
                }
 
214
        }
 
215
}
 
216
 
 
217
void GNC::HerramientaAngulo::SetVistaActiva(GNC::GCS::IVista* pVista)
 
218
{
 
219
        GNC::GCS::IContratable<GNC::GCS::IContratoWidgets>::EstablecerVistaActiva(pVista);
 
220
        GTRACE("GNC::HerramientaAngulo::SetVistaActiva(" << pVista << ")");
 
221
}
 
222
 
 
223
void GNC::HerramientaAngulo::ConectarContratos(bool activar)
 
224
{
 
225
        typedef GNC::GCS::IContratable<GNC::GCS::IContratoWidgets> ICConcreto;
 
226
        if (ICConcreto::m_pListaActiva == NULL) {
 
227
                if (activar) {
 
228
                        std::cerr << "Error: Se trataron de conectar contratos sin haber asignado la vista activa. Error en la logica de activacion. Accion ignorada" << std::endl;
 
229
                } else {
 
230
                        if (m_pAnguloBuilder != NULL)
 
231
                        {
 
232
                                delete m_pAnguloBuilder;
 
233
                                m_pAnguloBuilder = NULL;
 
234
                        }
 
235
                }
 
236
                return;
 
237
        }
 
238
 
 
239
 
 
240
        for (ICConcreto::IteradorListaContratos it = ICConcreto::m_pListaActiva->begin(); it != ICConcreto::m_pListaActiva->end(); it++) {
 
241
                GNC::GCS::IContratoWidgets* pC = (*it);
 
242
                if (pC->Inicializado()) {
 
243
                        if (activar) {
 
244
                                GTRACE("HerramientaAngulo: Conectando contratos de vista " << ICConcreto::m_pVistaActiva);
 
245
                                m_pAnguloBuilder = new GNC::GCS::Widgets::WAnguloBuilder(pC->GetManager());
 
246
                                if (m_TipoAngulo == TA_Normal) {
 
247
                                        m_pAnguloBuilder->SetModo(GNC::GCS::Widgets::MA_Normal);
 
248
                                }
 
249
                                else {
 
250
                                        m_pAnguloBuilder->SetModo(GNC::GCS::Widgets::MA_Cobb);
 
251
                                }
 
252
                                pC->GetViewer()->SetInteractionStyle(vtkGinkgoImageViewer::ZOOM_INTERACTION);
 
253
                                pC->GetManager()->SetCursor(m_pAnguloBuilder->GetCursor());
 
254
                        } else {
 
255
                                GTRACE("HerramientaAngulo: Desconectando contratos de vista " << ICConcreto::m_pVistaActiva);
 
256
                                pC->GetViewer()->SetInteractionStyle(vtkGinkgoImageViewer::ZOOM_INTERACTION);
 
257
                                pC->GetManager()->SetCursor(GNC::GCS::Widgets::CUR_FLECHA);
 
258
                                if (m_pAnguloBuilder != NULL)
 
259
                                {
 
260
                                        delete m_pAnguloBuilder;
 
261
                                        m_pAnguloBuilder = NULL;
 
262
                                }
 
263
                        }
 
264
                }
 
265
        }
 
266
}
 
267
 
 
268
//endregion
 
269
 
 
270
 
 
271
//region "Eventos refinados desde los paneles"
 
272
 
 
273
//endregion