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

« back to all changes in this revision

Viewing changes to src/cadxcore/widgets/wmarcadoarea.h

  • 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: wmarcadoarea.h 3558 2011-03-20 20:02:22Z 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
#pragma once
 
15
#include <api/iwidgets.h>
 
16
#include <api/widgetserializable.h>
 
17
#include <vector>
 
18
#include <widgets/observers/iobservadormarcadoarea.h>
 
19
 
 
20
 
 
21
//----------------------------------------------------------------------------------------------------
 
22
//region "Forward Declarations"
 
23
class vtkImageData;
 
24
namespace GNC {
 
25
        namespace GCS {
 
26
                namespace Widgets {
 
27
                        
 
28
                        typedef std::list<GNC::GCS::Nodo> VerticesPoligono;
 
29
                        
 
30
                        class WMarcadoArea;
 
31
                }
 
32
        }
 
33
}
 
34
//endregion
 
35
 
 
36
 
 
37
namespace GNC {
 
38
        namespace GCS {
 
39
                namespace Widgets {
 
40
 
 
41
                        //====================================================================================================
 
42
                        //= Builder de marcado
 
43
                        //====================================================================================================
 
44
 
 
45
                        class EXTAPI WMarcadoAreaBuilder : public GNC::GCS::Widgets::IWidgetBuilder, public GNC::GCS::Widgets::Notificadores::INotificadorMarcadoArea {
 
46
                        
 
47
                        public:
 
48
                                typedef enum ModoMarcado {
 
49
                                        MP_Lazo,      // Poligono volatil. Existencia maxima: 1.
 
50
                                        MP_Normal   // Poligono persistente. Existencia maxima: Inf.
 
51
                                } ModoMarcado;
 
52
 
 
53
                                WMarcadoAreaBuilder(ModoMarcado modo, vtkImageData* pImageData, GNC::GCS::IWidgetsManager* pManager, long gid, GNC::GCS::Widgets::Observadores::IObservadorMarcadoArea* pObservador = NULL);
 
54
 
 
55
                                ~WMarcadoAreaBuilder();
 
56
 
 
57
                                void EliminarWidget(bool notificar = false);
 
58
 
 
59
                                void SetRadioNodo(float radio)
 
60
                                {
 
61
                                        m_RadioNodo = radio;
 
62
                                        m_DistanciaMinimaCuadrado = radio * 2;
 
63
                                        m_DistanciaMinimaCuadrado *= m_DistanciaMinimaCuadrado;
 
64
 
 
65
                                }
 
66
 
 
67
                                virtual void OnMouseEvents(GNC::GCS::Eventos::EventoRaton&);
 
68
 
 
69
                                virtual void OnKeyEvents(GNC::GCS::Eventos::EventoTeclado&);
 
70
 
 
71
                                virtual void Render(GNC::GCS::Contexto3D* c);
 
72
 
 
73
                                virtual GNC::GCS::Widgets::TipoCursor GetCursor();
 
74
 
 
75
                        protected:
 
76
 
 
77
                                GNC::GCS::Vector                          m_PosCursor;
 
78
                                VerticesPoligono                          m_Vertices;
 
79
                                GNC::GCS::Widgets::IWidgetBuilder::Estado m_Estado;
 
80
 
 
81
                                int                                       m_NumNodos;
 
82
                                bool                                      m_MouseDown;
 
83
                                float                                     m_RadioNodo;
 
84
                                float                                     m_DistanciaMinimaCuadrado;
 
85
                                GNC::GCS::Widgets::WMarcadoArea*          m_pPoligonoCreado;
 
86
                                vtkImageData*                             m_pImageData;
 
87
                                ModoMarcado                               m_Modo;
 
88
 
 
89
                        };
 
90
                        
 
91
                        //====================================================================================================
 
92
                        //= Widget de marcado
 
93
                        //====================================================================================================
 
94
                        class EXTAPI WMarcadoArea : public GNC::GCS::Widgets::IWidget, public GNC::GCS::Widgets::Notificadores::INotificadorMarcadoArea {
 
95
 
 
96
                        //----------------------------------------------------------------------------------------------------
 
97
                        //region "Constructor y destructor"
 
98
                        public:
 
99
                                WMarcadoArea(WMarcadoAreaBuilder::ModoMarcado modo, IWidgetsManager* pManager, unsigned int vid, VerticesPoligono& vertices, long gid, GNC::GCS::Widgets::Observadores::IObservadorMarcadoArea* pObservador = NULL, const char* nombre = "");
 
100
 
 
101
                                ~WMarcadoArea();
 
102
 
 
103
                        //endregion
 
104
 
 
105
                                virtual bool EsMarcador() const
 
106
                                {
 
107
                                        return m_Modo == WMarcadoAreaBuilder::MP_Normal;
 
108
                                }
 
109
 
 
110
                                virtual bool DelimitaArea() const
 
111
                                {
 
112
                                        return true;
 
113
                                }
 
114
 
 
115
                                virtual bool ContieneFast(const GNC::GCS::Vector& punto) const
 
116
                                {
 
117
                                        return punto.DentroDePoligono2(m_Vertices);
 
118
                                }
 
119
 
 
120
                                virtual void GetBoundingBox(GNC::GCS::Vector& bb0, GNC::GCS::Vector& bb1) const
 
121
                                {
 
122
                                        if (m_Vertices.size() > 0) {
 
123
 
 
124
                                                VerticesPoligono::const_iterator it = m_Vertices.begin();
 
125
                                                (*it).IniciarBoundingBox(bb0, bb1);
 
126
                                                for (; it != m_Vertices.end(); it++) {
 
127
                                                        (*it).ExtenderBoundingBox(bb0, bb1);
 
128
                                                }
 
129
                                        }
 
130
                                }
 
131
 
 
132
                                virtual void GetPosicion(GNC::GCS::Vector& posicion) const
 
133
                                {
 
134
                                        posicion = m_Centro;
 
135
                                }
 
136
 
 
137
                                virtual void GetPuntoAnclaje(GNC::GCS::Vector& punto, const GNC::GCS::Vector& escala) const
 
138
                                {
 
139
                                        punto = m_PosCursor + (GNC::GCS::Vector(10.0f, -10.0f) * escala);
 
140
                                }
 
141
 
 
142
                                virtual void GetCentro(GNC::GCS::Vector& centro) const
 
143
                                {
 
144
                                        centro = m_Centro;
 
145
                                }
 
146
 
 
147
                                virtual float GetAreaMetrica() const
 
148
                                {
 
149
                                        return m_AreaMetrica;
 
150
                                }
 
151
 
 
152
                                virtual float GetPerimetro() const
 
153
                                {
 
154
                                        return m_Perimetro;
 
155
                                }
 
156
 
 
157
                                virtual bool SoportaAutoBorrado() const {
 
158
                                        if (m_Modo == WMarcadoAreaBuilder::MP_Normal) {
 
159
                                                return true;
 
160
                                        }
 
161
                                        else {
 
162
                                                return false;
 
163
                                        }
 
164
                                }
 
165
 
 
166
                        //----------------------------------------------------------------------------------------------------
 
167
                        //region "Interfaz especifica"
 
168
 
 
169
                                virtual void OnMouseEvents(GNC::GCS::Eventos::EventoRaton&);
 
170
 
 
171
                                virtual void OnKeyEvents(GNC::GCS::Eventos::EventoTeclado&);
 
172
 
 
173
                                virtual bool HitTest(float x, float y, float umbralCuadrado);
 
174
 
 
175
                                virtual bool HitTest(GNC::GCS::Vector* vertices, int numVertices);
 
176
 
 
177
                                virtual void Render(GNC::GCS::Contexto3D* c);
 
178
 
 
179
                                virtual void Seleccionar(bool seleccionado);
 
180
 
 
181
                                virtual void Iluminar(bool iluminado);
 
182
 
 
183
                                virtual void Ocultar(bool oculto);
 
184
        
 
185
                        //endregion
 
186
        
 
187
                        //----------------------------------------------------------------------------------------------------
 
188
                        //region "Estado interno"
 
189
                        private:
 
190
                                bool              m_MouseDown;
 
191
                                GNC::GCS::Vector  m_PosCursor;
 
192
                        //endregion
 
193
 
 
194
                        //----------------------------------------------------------------------------------------------------
 
195
                        //region "Propiedades geometricas"
 
196
                        private:
 
197
 
 
198
                                VerticesPoligono  m_Vertices;
 
199
                                float                    m_RadioNodo;
 
200
 
 
201
                                GNC::GCS::Vector m_Centro;
 
202
                                float                    m_AreaMetrica;
 
203
                                float                    m_Perimetro;
 
204
 
 
205
 
 
206
                                friend std::ostream & operator<<(std::ostream& out, const WMarcadoArea& /*w*/)
 
207
                                {
 
208
                                        return out;
 
209
                                }
 
210
 
 
211
                        public:
 
212
                                virtual void GetVertices(std::list<GNC::GCS::Vector>& vertices) const {
 
213
                                        for (VerticesPoligono::const_iterator it = m_Vertices.begin(); it != m_Vertices.end(); ++it) {
 
214
                                                vertices.push_back(*it);
 
215
                                        }
 
216
                                }
 
217
 
 
218
                                void GetNodos(std::list<GNC::GCS::Nodo>& vertices) {
 
219
                                        for (VerticesPoligono::const_iterator it = m_Vertices.begin(); it != m_Vertices.end(); ++it) {
 
220
                                                vertices.push_back(*it);
 
221
                                        }
 
222
                                }
 
223
                                
 
224
                                const VerticesPoligono& Vertices() const
 
225
                                {
 
226
                                        return m_Vertices;
 
227
                                }
 
228
 
 
229
                        //endregion
 
230
 
 
231
                        private:
 
232
                                WMarcadoAreaBuilder::ModoMarcado m_Modo;
 
233
                        
 
234
                        
 
235
                                
 
236
                                
 
237
                        //----------------------------------------------------------------------------------------------------
 
238
                        //region "Helpers"
 
239
                        public:
 
240
                                
 
241
                                virtual void Recalcular();
 
242
                                
 
243
                        //endregion
 
244
                        };
 
245
                }
 
246
        }
 
247
}