3
* $Id: herramientaregla.cpp 3526 2011-03-16 19:56:19Z carlos $
6
* Copyright 2008-10 MetaEmotion S.L. All rights reserved.
7
* http://ginkgo-cadx.com
9
* This file is licensed under LGPL v3 license.
10
* See License.txt for details
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>
25
#include <vtk/vtkginkgoimageviewer.h>
26
#include <wx/xml/xml.h>
28
GNC::HerramientaRegla::HerramientaRegla() {
30
m_pReglaBuilder = NULL;
32
m_Descripcion = _Std("Rule");
33
m_Icono = GinkgoResourcesManager::IconosHerramientas::GetIcoLongitud();
36
GNC::HerramientaRegla::~HerramientaRegla() {
40
wxXmlNode* GNC::HerramientaRegla::Serializar(GNC::GCS::IVista* pVista, long vid, const std::string nombreMedicoSerializa)
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);
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));
66
resultado->AddChild(pRegla->Serializar(nombreMedicoSerializa));
73
void GNC::HerramientaRegla::Deserializar(GNC::GCS::IVista* pVista, long vid, wxXmlNode* nodo)
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;
79
typedef GNC::GCS::IContratable<GNC::GCS::IContratoWidgets> ICConcreto;
81
for (ICConcreto::IteradorMapaContratos it = ICConcreto::m_Contratos.begin(); it != ICConcreto::m_Contratos.end(); it++) {
82
if((*it).first == pVista){
84
for (ICConcreto::IteradorListaContratos it2 = (*it).second->begin(); it2 != (*it).second->end(); it2++) {
85
GNC::GCS::IContratoWidgets* pC = (*it2);
87
GNC::GCS::ListaWidgets listaWidgets;
89
wxXmlNode *child = nodo->GetChildren();
91
GNC::GCS::Widgets::WRegla* pWidget = new GNC::GCS::Widgets::WRegla(pC->GetManager(), vid, child);
92
listaWidgets.push_back(pWidget);
93
child = child->GetNext();
96
for (GNC::GCS::IWidgetsManager::IteradorListaWidgets itWidgets = listaWidgets.begin(); itWidgets!= listaWidgets.end(); itWidgets++){
97
pC->GetManager()->InsertarWidget((*itWidgets),false);
104
//region "Realizaci�n de la interfaz IHerramienta"
106
void GNC::HerramientaRegla::CrearPaneles( wxPanel* /*panel*/ ) {
107
m_pAbstractPanelHerramientaOpciones = NULL;
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;
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()) {
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);
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);
133
void GNC::HerramientaRegla::SetVistaActiva(GNC::GCS::IVista* pVista) {
134
GNC::GCS::IContratable<GNC::GCS::IContratoWidgets>::EstablecerVistaActiva(pVista);
135
GTRACE("GNC::HerramientaRegla::SetVistaActiva(" << pVista << ")");
138
void GNC::HerramientaRegla::ConectarContratos(bool activar) {
139
typedef GNC::GCS::IContratable<GNC::GCS::IContratoWidgets> ICConcreto;
140
if (ICConcreto::m_pListaActiva == NULL) {
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;
144
if (m_pReglaBuilder != NULL) {
145
delete m_pReglaBuilder;
146
m_pReglaBuilder = NULL;
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()) {
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());
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;
177
//region "Eventos refinados desde los paneles"