~ubuntu-branches/ubuntu/oneiric/ginkgocadx/oneiric

« back to all changes in this revision

Viewing changes to src/cadxcore/main/tools/herramientaregla.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: herramientaregla.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 <api/globals.h>
 
16
#include "herramientaregla.h"
 
17
#include <widgets/wregla.h>
 
18
#include <resources/ginkgoresourcemanager.h>
 
19
#include <api/internacionalizacion.h>
 
20
 
 
21
#include <iostream>
 
22
#ifdef __DEPRECATED
 
23
#undef __DEPRECATED
 
24
#endif
 
25
#include <vtk/vtkginkgoimageviewer.h>
 
26
#include <wx/xml/xml.h>
 
27
 
 
28
GNC::HerramientaRegla::HerramientaRegla() {
 
29
        m_Activa = false;
 
30
        m_pReglaBuilder = NULL;
 
31
 
 
32
        m_Descripcion = _Std("Rule");
 
33
        m_Icono = GinkgoResourcesManager::IconosHerramientas::GetIcoLongitud();
 
34
}
 
35
 
 
36
GNC::HerramientaRegla::~HerramientaRegla() {
 
37
 
 
38
}
 
39
 
 
40
wxXmlNode* GNC::HerramientaRegla::Serializar(GNC::GCS::IVista* pVista, long vid, const std::string nombreMedicoSerializa)
 
41
{
 
42
        //se cogen todas los widgets regla de los contratos con ese vid
 
43
        typedef  GNC::GCS::IContratable<GNC::GCS::IContratoWidgets> ICConcreto;
 
44
        //se cogen todas los widgets regla de los contratos con ese vid
 
45
        GNC::GCS::ListaWidgets listaWidgets;
 
46
        for (ICConcreto::IteradorMapaContratos it = ICConcreto::m_Contratos.begin(); it != ICConcreto::m_Contratos.end(); it++) {
 
47
                if((*it).first == pVista){
 
48
                        for (ICConcreto::IteradorListaContratos it2 = (*it).second->begin(); it2 != (*it).second->end(); it2++) {
 
49
                                GNC::GCS::IContratoWidgets* pC = (*it2);
 
50
                                GNC::GCS::ListaWidgets listaWidgetsTmp;
 
51
                                if(pC->GetManager() != NULL){
 
52
                                        pC->GetManager()->GetListaWidgetsSubVista(vid,listaWidgetsTmp);
 
53
                                        listaWidgets.splice(listaWidgets.begin(),listaWidgetsTmp);
 
54
                                }
 
55
                        }
 
56
                }
 
57
        }
 
58
 
 
59
        wxXmlNode* resultado = NULL;
 
60
        if(listaWidgets.size()>0){
 
61
                resultado = new wxXmlNode(NULL,wxXML_ELEMENT_NODE,wxT("rule"));
 
62
                resultado->AddProperty(wxT("id"),wxString::Format(wxT("%d"),this->ID));
 
63
                for (GNC::GCS::IWidgetsManager::IteradorListaWidgets it = listaWidgets.begin();  it!= listaWidgets.end(); it++){
 
64
                        GNC::GCS::Widgets::WRegla* pRegla = dynamic_cast<GNC::GCS::Widgets::WRegla*>((*it));
 
65
                        if( pRegla != NULL){
 
66
                                resultado->AddChild(pRegla->Serializar(nombreMedicoSerializa));
 
67
                        }
 
68
                }
 
69
        }
 
70
        return resultado;
 
71
}
 
72
 
 
73
void GNC::HerramientaRegla::Deserializar(GNC::GCS::IVista* pVista, long vid, wxXmlNode* nodo)
 
74
{
 
75
        if(nodo->GetPropVal(wxT("id"),wxT("")) != wxString::Format(wxT("%d"),this->ID)){
 
76
                std::cerr<< "Ha ocurrido un error al desserializar la herramienta regla"<<std::endl;
 
77
        }
 
78
 
 
79
        typedef  GNC::GCS::IContratable<GNC::GCS::IContratoWidgets> ICConcreto;
 
80
 
 
81
        for (ICConcreto::IteradorMapaContratos it = ICConcreto::m_Contratos.begin(); it != ICConcreto::m_Contratos.end(); it++) {
 
82
                if((*it).first == pVista){
 
83
 
 
84
                        for (ICConcreto::IteradorListaContratos it2 = (*it).second->begin(); it2 != (*it).second->end(); it2++) {
 
85
                                GNC::GCS::IContratoWidgets* pC = (*it2);
 
86
 
 
87
                                GNC::GCS::ListaWidgets listaWidgets;
 
88
 
 
89
                                wxXmlNode *child = nodo->GetChildren();
 
90
                                while (child) {
 
91
                                        GNC::GCS::Widgets::WRegla* pWidget = new GNC::GCS::Widgets::WRegla(pC->GetManager(), vid, child);
 
92
                                        listaWidgets.push_back(pWidget);
 
93
                                        child = child->GetNext();
 
94
                                }
 
95
 
 
96
                                for (GNC::GCS::IWidgetsManager::IteradorListaWidgets itWidgets = listaWidgets.begin();  itWidgets!= listaWidgets.end(); itWidgets++){
 
97
                                        pC->GetManager()->InsertarWidget((*itWidgets),false);
 
98
                                }
 
99
                        }
 
100
                }
 
101
        }
 
102
}
 
103
 
 
104
//region "Realizaci�n de la interfaz IHerramienta"
 
105
 
 
106
void GNC::HerramientaRegla::CrearPaneles( wxPanel* /*panel*/ ) {
 
107
        m_pAbstractPanelHerramientaOpciones = NULL;
 
108
}
 
109
 
 
110
void GNC::HerramientaRegla::ConectarContratoFalso(bool activar) {
 
111
        typedef  GNC::GCS::IContratable<GNC::GCS::IContratoWidgets> ICConcreto;
 
112
        if (ICConcreto::m_pListaActiva == NULL) {
 
113
                //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;
 
114
                return;
 
115
        }
 
116
 
 
117
        for (ICConcreto::IteradorListaContratos it = ICConcreto::m_pListaActiva->begin(); it != ICConcreto::m_pListaActiva->end(); it++) {
 
118
                GNC::GCS::IContratoWidgets* pC = (*it);
 
119
                if (pC->Inicializado()) {
 
120
                        if (activar) {
 
121
                                pC->GetViewer()->SetInteractionStyle(vtkGinkgoImageViewer::ZOOM_INTERACTION);
 
122
                                pC->GetManager()->SetCursor(GNC::GCS::Widgets::CUR_FLECHA);
 
123
                                GTRACE("HerramientaRegla: Conectando contrato falso de vista " << ICConcreto::m_pVistaActiva);
 
124
                        } else {
 
125
                                GTRACE("HerramientaRegla: Desconectando contrato falso de vista " << ICConcreto::m_pVistaActiva);
 
126
                                pC->GetViewer()->SetInteractionStyle(vtkGinkgoImageViewer::ZOOM_INTERACTION);
 
127
                                pC->GetManager()->SetCursor(GNC::GCS::Widgets::CUR_FLECHA);
 
128
                        }
 
129
                }
 
130
        }
 
131
}
 
132
 
 
133
void GNC::HerramientaRegla::SetVistaActiva(GNC::GCS::IVista* pVista) {
 
134
        GNC::GCS::IContratable<GNC::GCS::IContratoWidgets>::EstablecerVistaActiva(pVista);
 
135
        GTRACE("GNC::HerramientaRegla::SetVistaActiva(" <<  pVista << ")");
 
136
}
 
137
 
 
138
void GNC::HerramientaRegla::ConectarContratos(bool activar) {
 
139
        typedef  GNC::GCS::IContratable<GNC::GCS::IContratoWidgets> ICConcreto;
 
140
        if (ICConcreto::m_pListaActiva == NULL) {
 
141
                if (activar) {
 
142
                        std::cerr << "Error: Se trataron de conectar contratos sin haber asignado la vista activa. Error en la logica de activacion. Accion ignorada" << std::endl;
 
143
                } else {
 
144
                        if (m_pReglaBuilder != NULL) {
 
145
                                delete m_pReglaBuilder;
 
146
                                m_pReglaBuilder = NULL;
 
147
                        }
 
148
                }
 
149
                return;
 
150
        }
 
151
 
 
152
        for (ICConcreto::IteradorListaContratos it = ICConcreto::m_pListaActiva->begin(); it != ICConcreto::m_pListaActiva->end(); it++) {
 
153
                GNC::GCS::IContratoWidgets* pC = (*it);
 
154
                if (pC->Inicializado()) {
 
155
                        if (activar) {
 
156
                                GTRACE("HerramientaRegla: Conectando contratos de vista " << ICConcreto::m_pVistaActiva);
 
157
                                // Subscribimos los eventos de la ventana a un metodo especifico del panel de esta herramienta
 
158
                                m_pReglaBuilder = new GNC::GCS::Widgets::WReglaBuilder(pC->GetManager());
 
159
                                pC->GetViewer()->SetInteractionStyle(vtkGinkgoImageViewer::ZOOM_INTERACTION);
 
160
                                pC->GetManager()->SetCursor(m_pReglaBuilder->GetCursor());
 
161
                        } else {
 
162
                                GTRACE( "HerramientaRegla: Desconectando contratos de vista " << ICConcreto::m_pVistaActiva );
 
163
                                // DesSubscribimos los eventos de la ventana a un metodo especifico del panel de esta herramienta
 
164
                                pC->GetViewer()->SetInteractionStyle(vtkGinkgoImageViewer::ZOOM_INTERACTION);
 
165
                                pC->GetManager()->SetCursor(GNC::GCS::Widgets::CUR_FLECHA);
 
166
                                if (m_pReglaBuilder != NULL) {
 
167
                                        delete m_pReglaBuilder;
 
168
                                        m_pReglaBuilder = NULL;
 
169
                                }
 
170
                        }
 
171
                }
 
172
        }
 
173
}
 
174
 
 
175
//endregion
 
176
 
 
177
//region "Eventos refinados desde los paneles"
 
178
 
 
179
//endregion