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

« back to all changes in this revision

Viewing changes to src/cadxcore/widgets/wchroma.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: wchroma.cpp 3535 2011-03-18 17:57:05Z 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
 
 
16
#include <cmath>
 
17
 
 
18
#include <wx/xml/xml.h>
 
19
 
 
20
#include <api/globals.h>
 
21
 
 
22
#include <api/ievento.h>
 
23
#include <api/iwidgetsrenderer.h>
 
24
#include <api/iwidgetsmanager.h>
 
25
#include <api/icontexto.h>
 
26
#include <api/westilo.h>
 
27
 
 
28
#include <eventos/eventosginkgo.h>
 
29
 
 
30
#include <main/managers/widgetsmanager.h>
 
31
 
 
32
#include "wchroma.h"
 
33
 
 
34
#include <vtkgl.h>
 
35
 
 
36
#define WRADIO_CRUZ 12.0f
 
37
#define WLONGITUD_LINEA 15.0f
 
38
 
 
39
//region "Implementacion de WSemillasBuilder"
 
40
 
 
41
GNC::GCS::Widgets::WChromaBuilder::WChromaBuilder(GNC::GCS::IWidgetsManager* pManager, long gid, GNC::GCS::Widgets::Observadores::IObservadorChroma* pObservador) : GNC::GCS::Widgets::IWidgetBuilder(pManager, gid), GNC::GCS::Widgets::Notificadores::INotificadorChroma(pObservador)
 
42
{
 
43
        m_MouseDown = false;
 
44
        m_NumMaxSemillas = 1;
 
45
        m_Estado = WBS_Ninguno;
 
46
}
 
47
 
 
48
GNC::GCS::Widgets::WChromaBuilder::~WChromaBuilder()
 
49
{
 
50
 
 
51
}
 
52
 
 
53
void GNC::GCS::Widgets::WChromaBuilder::OnMouseEvents(GNC::GCS::Eventos::EventoRaton& evento)
 
54
{
 
55
        if (!m_pManager) {
 
56
                return;
 
57
        }
 
58
        GTRACE("GNC::GCS::Widgets::WSemillasBuilder::OnMouseEvents(wxMouseEvent&)");
 
59
        if (m_MouseDown && evento.ButtonUp(GNC::GCS::Eventos::EventoRaton::EB_IZQUIERDO)) {
 
60
 
 
61
                m_MouseDown = false;
 
62
                switch(m_Estado) {
 
63
                        case WBS_Ninguno:
 
64
                                // ĀæError?
 
65
                                break;
 
66
                        case WBS_Creando:
 
67
                                {
 
68
                                        m_Nodo = evento.iP;
 
69
 
 
70
                                        GNC::GCS::Widgets::WChroma* semilla = new GNC::GCS::Widgets::WChroma(m_pManager, evento.c->GetRenderer()->GetVID(), m_Nodo, "chroma", m_GID);
 
71
                                        int numSemillas = 0;
 
72
                                        if (m_NumMaxSemillas > 0) {
 
73
                                                for (GNC::GCS::ListaWidgets::iterator it = m_pManager->GetListaWidgets().begin(); it !=  m_pManager->GetListaWidgets().end(); it++) {
 
74
                                                        if ( (*it)->GetGID() == m_GID) {
 
75
                                                                numSemillas++;
 
76
                                                                if (numSemillas >= m_NumMaxSemillas) {
 
77
                                                                        m_pManager->EliminarWidget(it);
 
78
                                                                        break;
 
79
                                                                }
 
80
                                                        }
 
81
                                                }
 
82
                                        }
 
83
                                        m_pManager->InsertarWidget(semilla);
 
84
                                        m_pManager->LanzarEventoCreacion(semilla);
 
85
                                        m_pManager->Modificado();
 
86
                                        ConsumirEvento();
 
87
                                }
 
88
                                break;
 
89
                        case WBS_Seleccionando:
 
90
                                break;
 
91
                        case WBS_Moviendo:
 
92
                                break;
 
93
                }
 
94
                m_Estado = WBS_Ninguno;
 
95
 
 
96
        } else if (evento.ButtonDown(GNC::GCS::Eventos::EventoRaton::EB_IZQUIERDO)) {
 
97
                if (m_Estado != WBS_Ninguno) {
 
98
                        return;
 
99
                }
 
100
 
 
101
                int numSemillas = 0;
 
102
                if (m_NumMaxSemillas > 0) {
 
103
                        for (GNC::GCS::ListaWidgets::iterator it = m_pManager->GetListaWidgets().begin(); it !=  m_pManager->GetListaWidgets().end(); it++) {
 
104
                                if ( (*it)->GetGID() == m_GID) {
 
105
                                        numSemillas++;
 
106
                                        if (numSemillas >= m_NumMaxSemillas) {
 
107
                                                m_pManager->EliminarWidget(it);
 
108
                                                break;
 
109
                                        }
 
110
                                }
 
111
                        }
 
112
                }
 
113
                
 
114
                m_Nodo = evento.iP;
 
115
                m_MouseDown = true;
 
116
                m_Estado = WBS_Creando;
 
117
                m_pManager->Modificado();
 
118
                ConsumirEvento();
 
119
 
 
120
        } else if (evento.Dragging() && m_MouseDown) {
 
121
                if (m_Estado == WBS_Creando) {
 
122
                        m_Nodo = evento.iP;
 
123
                        m_pManager->Modificado();
 
124
                        ConsumirEvento();
 
125
                }
 
126
        }
 
127
}
 
128
 
 
129
void GNC::GCS::Widgets::WChromaBuilder::OnKeyEvents(GNC::GCS::Eventos::EventoTeclado& evt)
 
130
{
 
131
        NotificarKeyEvent(evt);
 
132
}
 
133
 
 
134
void GNC::GCS::Widgets::WChromaBuilder::Render(GNC::GCS::Contexto3D* c)
 
135
{
 
136
        if (m_Estado != WBS_Creando) {
 
137
                return;
 
138
        }
 
139
 
 
140
        GNC::GCS::Vector escala = c->RelacionImagenPantalla();
 
141
 
 
142
        float radioCruz = WRADIO_CRUZ * escala.x;
 
143
        float longitudLinea = WLONGITUD_LINEA * escala.x;
 
144
 
 
145
        // Sombra
 
146
        float fsombrax, fsombray;
 
147
        if (m_MouseDown)
 
148
        {
 
149
                fsombrax = WIDGET_OFFSET_X_SOMBRA_SELECCIONADO * escala.x;
 
150
                fsombray = WIDGET_OFFSET_Y_SOMBRA_SELECCIONADO * escala.y;
 
151
        }
 
152
        else
 
153
        {
 
154
                fsombrax = WIDGET_OFFSET_X_SOMBRA * escala.x;
 
155
                fsombray = WIDGET_OFFSET_Y_SOMBRA * escala.y;
 
156
        }
 
157
 
 
158
 
 
159
        wColorSombra.Aplicar();
 
160
 
 
161
        glLineWidth(WIDGET_GROSOR_LINEA);
 
162
        // cruz
 
163
        glEnable(GL_LINE_STIPPLE);
 
164
        glLineStipple(3, 0xAAAA);
 
165
        glBegin(GL_LINE_STRIP);
 
166
        glVertex3f(m_Nodo.x - radioCruz + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
167
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
168
        glEnd();
 
169
        glBegin(GL_LINE_STRIP);
 
170
        glVertex3f(m_Nodo.x + radioCruz + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
171
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
172
        glEnd();
 
173
 
 
174
        glBegin(GL_LINE_STRIP);
 
175
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - radioCruz - fsombray, 0.0f);
 
176
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
177
        glEnd();
 
178
        glBegin(GL_LINE_STRIP);
 
179
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y + radioCruz - fsombray, 0.0f);
 
180
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
181
        glEnd();
 
182
        glDisable(GL_LINE_STIPPLE);
 
183
 
 
184
        //linea de la cruz 45 grados xa abajo
 
185
        glBegin(GL_LINES);
 
186
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
187
        glVertex3f(m_Nodo.x + longitudLinea + fsombrax, m_Nodo.y - longitudLinea - fsombray, 0.0f);
 
188
        glEnd();
 
189
 
 
190
 
 
191
        // Cuerpo
 
192
        glLineWidth(WIDGET_GROSOR_LINEA_ARRASTRE);
 
193
        wAplicarColor(m_Nodo.m_Iluminado, m_MouseDown, m_Nodo.m_Seleccionado);
 
194
 
 
195
        // Cruz
 
196
        glEnable(GL_LINE_STIPPLE);
 
197
        glLineStipple(3, 0xAAAA);
 
198
        glBegin(GL_LINE_STRIP);
 
199
        glVertex3f(m_Nodo.x - radioCruz, m_Nodo.y, 0.0f);
 
200
        glVertex3f(m_Nodo.x , m_Nodo.y, 0.0f);
 
201
        glEnd();
 
202
        glBegin(GL_LINE_STRIP);
 
203
        glVertex3f(m_Nodo.x + radioCruz, m_Nodo.y, 0.0f);
 
204
        glVertex3f(m_Nodo.x , m_Nodo.y, 0.0f);
 
205
        glEnd();
 
206
 
 
207
        glBegin(GL_LINE_STRIP);
 
208
        glVertex3f(m_Nodo.x, m_Nodo.y - radioCruz, 0.0f);
 
209
        glVertex3f(m_Nodo.x, m_Nodo.y, 0.0f);
 
210
        glEnd();
 
211
        glBegin(GL_LINE_STRIP);
 
212
        glVertex3f(m_Nodo.x, m_Nodo.y + radioCruz, 0.0f);
 
213
        glVertex3f(m_Nodo.x, m_Nodo.y, 0.0f);
 
214
        glEnd();
 
215
        glDisable(GL_LINE_STIPPLE);
 
216
 
 
217
        //linea de la cruz 45 grados xa abajo
 
218
        
 
219
 
 
220
        glBegin(GL_LINES);
 
221
        glVertex3f(m_Nodo.x, m_Nodo.y, 0.0f);
 
222
        glVertex3f(m_Nodo.x + longitudLinea, m_Nodo.y - longitudLinea, 0.0f);
 
223
        glEnd();
 
224
}
 
225
 
 
226
GNC::GCS::Widgets::TipoCursor GNC::GCS::Widgets::WChromaBuilder::GetCursor()
 
227
{
 
228
        return GNC::GCS::Widgets::CUR_CREAR_PUNTO;
 
229
}
 
230
 
 
231
//endregion
 
232
 
 
233
 
 
234
//region "Constructor y destructor"
 
235
 
 
236
GNC::GCS::Widgets::WChroma::WChroma(IWidgetsManager* pManager, long vid, GNC::GCS::Nodo nodo, const char* nombre, long gid, bool oculto) : GNC::GCS::Widgets::IWidget(pManager, vid, nombre, gid)
 
237
{
 
238
        m_Nodo = nodo;
 
239
        m_Nodo.m_Size = WRADIO_CRUZ;
 
240
        m_MouseDown = false;
 
241
        m_UID = (long)this;
 
242
        m_Oculto = oculto;
 
243
 
 
244
        /*GNC::GCS::Eventos::EventoModificacionImagen evt1(m_pManager->GetVista());
 
245
        m_pManager->GetControladorEventos()->Registrar(this, evt1);*/
 
246
}
 
247
 
 
248
GNC::GCS::Widgets::WChroma::~WChroma()
 
249
{
 
250
        LanzarEventoDestruccion();
 
251
}
 
252
 
 
253
//endregion
 
254
 
 
255
void GNC::GCS::Widgets::WChroma::OnMouseEvents(GNC::GCS::Eventos::EventoRaton& evento)
 
256
{
 
257
        if(EstaOculto()){
 
258
                return;
 
259
        }
 
260
        //------------------------------------------------------
 
261
        // Leaving
 
262
        else if (evento.Leaving() ) {
 
263
                Iluminar(false);
 
264
        }
 
265
        //------------------------------------------------------
 
266
        // Entering
 
267
        else if (evento.Entering() ) {
 
268
                if (m_MouseDown) {
 
269
                        Iluminar(true);
 
270
                }
 
271
        }
 
272
        //------------------------------------------------------
 
273
        // Dragging
 
274
        if (evento.Dragging() && m_MouseDown) {
 
275
                if (m_Nodo.m_Seleccionado) {
 
276
                        Vector delta = evento.iP - m_PosCursor;
 
277
                        m_PosCursor = evento.iP;
 
278
                        m_Nodo += delta;
 
279
                        Modificar(true);
 
280
 
 
281
                        NotificarCambios(true);
 
282
                        ConsumirEvento();
 
283
                        LanzarEventoModificacion();
 
284
                }
 
285
                return;
 
286
        }
 
287
        //------------------------------------------------------
 
288
        // LeftDown
 
289
        else if (evento.LeftDown()) {
 
290
 
 
291
                if (EventoConsumido() && !evento.m_controlDown) {
 
292
                        if (EstaSeleccionado()) {
 
293
                                NotificarCambios(true);
 
294
                        }
 
295
                        Seleccionar(false);
 
296
                        return;
 
297
                }
 
298
 
 
299
                const GNC::GCS::Vector::TComponente& factor = evento.c->RelacionImagenPantalla().NormaInfinito();
 
300
 
 
301
                bool dentro = false;
 
302
 
 
303
                m_PosCursor = evento.iP;
 
304
 
 
305
                if (m_Nodo.Hits(evento.iP, factor)) { // click sobre el nodo
 
306
                        dentro = true;
 
307
                        if (evento.m_controlDown) { // Inversion de seleccion
 
308
                                InvertirSeleccion();
 
309
                        }
 
310
                        else{
 
311
                                Seleccionar(true);
 
312
                        }
 
313
                }
 
314
                else { // Click fuera del nodo
 
315
                        if (!evento.m_controlDown) {
 
316
                                Seleccionar(false);
 
317
                        }
 
318
                        else {
 
319
                                ConsumirEvento();
 
320
                                if (EstaSeleccionado()) {
 
321
                                        m_MouseDown = true;
 
322
                                }
 
323
                        }
 
324
                }
 
325
                if (dentro) {
 
326
                        m_MouseDown = true;
 
327
                        m_PosAntigua = m_Nodo;
 
328
                        ConsumirEvento();
 
329
                }
 
330
                return;
 
331
        }
 
332
        //------------------------------------------------------
 
333
        // LeftUP
 
334
        else if (evento.LeftUp()) {
 
335
                if (m_MouseDown) {
 
336
                        m_MouseDown = false;
 
337
                        ConsumirEvento();
 
338
                }
 
339
        }
 
340
        //------------------------------------------------------
 
341
        // Moving
 
342
        else if (evento.Moving()) {
 
343
                if (EventoConsumido()) {
 
344
                        return;
 
345
                }
 
346
                const GNC::GCS::Vector::TComponente& factor = evento.c->RelacionImagenPantalla().NormaInfinito();
 
347
 
 
348
                bool dentro = false;
 
349
 
 
350
                m_PosCursor = evento.iP;
 
351
 
 
352
                if (m_Nodo.Hits(evento.iP, factor)) {
 
353
                        Iluminar(true);
 
354
                        dentro = true;
 
355
                }
 
356
                else {
 
357
                        Iluminar(false);
 
358
                }
 
359
                if (dentro) {
 
360
                        ConsumirEvento();
 
361
                }
 
362
                return;
 
363
        }
 
364
}
 
365
 
 
366
void GNC::GCS::Widgets::WChroma::OnKeyEvents(GNC::GCS::Eventos::EventoTeclado& evento)
 
367
{
 
368
        if (evento.GetKeyCode() == WXK_ESCAPE) {
 
369
                Seleccionar(false);
 
370
        }
 
371
}
 
372
 
 
373
bool GNC::GCS::Widgets::WChroma::HitTest(float /*x*/, float /*y*/, float /*umbralCuadrado*/)
 
374
{
 
375
        return false;
 
376
}
 
377
 
 
378
bool GNC::GCS::Widgets::WChroma::HitTest(GNC::GCS::Vector* vertices, int numVertices)
 
379
{
 
380
        return m_Nodo.DentroDePoligono2(vertices,numVertices);
 
381
}
 
382
 
 
383
void GNC::GCS::Widgets::WChroma::Render(GNC::GCS::Contexto3D* c)
 
384
{
 
385
        if(m_Oculto){
 
386
                return;
 
387
        }
 
388
 
 
389
        GNC::GCS::Vector escala = c->RelacionImagenPantalla();
 
390
 
 
391
        float radioCruz = WRADIO_CRUZ * escala.x;
 
392
        float longitudLinea = WLONGITUD_LINEA * escala.x;
 
393
 
 
394
        // Sombra
 
395
        float fsombrax, fsombray;
 
396
        if (m_MouseDown)
 
397
        {
 
398
                fsombrax = WIDGET_OFFSET_X_SOMBRA_SELECCIONADO * escala.x;
 
399
                fsombray = WIDGET_OFFSET_Y_SOMBRA_SELECCIONADO * escala.y;
 
400
        }
 
401
        else
 
402
        {
 
403
                fsombrax = WIDGET_OFFSET_X_SOMBRA * escala.x;
 
404
                fsombray = WIDGET_OFFSET_Y_SOMBRA * escala.y;
 
405
        }
 
406
 
 
407
 
 
408
        wColorSombra.Aplicar();
 
409
 
 
410
        // cruz
 
411
        glEnable(GL_LINE_STIPPLE);
 
412
        glLineStipple(3, 0xAAAA);
 
413
        glBegin(GL_LINE_STRIP);
 
414
        glVertex3f(m_Nodo.x - radioCruz + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
415
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
416
        glEnd();
 
417
        glBegin(GL_LINE_STRIP);
 
418
        glVertex3f(m_Nodo.x + radioCruz + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
419
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
420
        glEnd();
 
421
 
 
422
        glBegin(GL_LINE_STRIP);
 
423
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - radioCruz - fsombray, 0.0f);
 
424
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
425
        glEnd();
 
426
        glBegin(GL_LINE_STRIP);
 
427
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y + radioCruz - fsombray, 0.0f);
 
428
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
429
        glEnd();
 
430
        glDisable(GL_LINE_STIPPLE);
 
431
 
 
432
        //linea de la cruz 45 grados xa abajo
 
433
        glBegin(GL_LINES);
 
434
        glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
 
435
        glVertex3f(m_Nodo.x + longitudLinea + fsombrax, m_Nodo.y - longitudLinea - fsombray, 0.0f);
 
436
        glEnd();
 
437
 
 
438
        // arrastre
 
439
        if (m_MouseDown) {
 
440
                glEnable(GL_LINE_STIPPLE);
 
441
                wColorLineaArrastre.Aplicar();
 
442
                glLineWidth(WIDGET_GROSOR_LINEA_ARRASTRE);
 
443
                glLineStipple(3, 0xAAAA);
 
444
 
 
445
                glBegin(GL_LINE_STRIP);
 
446
                glVertex2d(m_PosAntigua.x, m_PosAntigua.y);
 
447
                glVertex2d(m_Nodo.x, m_Nodo.y);
 
448
                glEnd();
 
449
 
 
450
                glDisable(GL_LINE_STIPPLE);
 
451
        }
 
452
 
 
453
        // Cuerpo
 
454
        glLineWidth(WIDGET_GROSOR_LINEA_ARRASTRE);
 
455
        wAplicarColor(m_Nodo.m_Iluminado, m_MouseDown, m_Nodo.m_Seleccionado);
 
456
 
 
457
        // Cruz
 
458
        glEnable(GL_LINE_STIPPLE);
 
459
        glLineStipple(3, 0xAAAA);
 
460
        glBegin(GL_LINE_STRIP);
 
461
        glVertex3f(m_Nodo.x - radioCruz, m_Nodo.y, 0.0f);
 
462
        glVertex3f(m_Nodo.x , m_Nodo.y, 0.0f);
 
463
        glEnd();
 
464
        glBegin(GL_LINE_STRIP);
 
465
        glVertex3f(m_Nodo.x + radioCruz, m_Nodo.y, 0.0f);
 
466
        glVertex3f(m_Nodo.x , m_Nodo.y, 0.0f);
 
467
        glEnd();
 
468
 
 
469
        glBegin(GL_LINE_STRIP);
 
470
        glVertex3f(m_Nodo.x, m_Nodo.y - radioCruz, 0.0f);
 
471
        glVertex3f(m_Nodo.x, m_Nodo.y, 0.0f);
 
472
        glEnd();
 
473
        glBegin(GL_LINE_STRIP);
 
474
        glVertex3f(m_Nodo.x, m_Nodo.y + radioCruz, 0.0f);
 
475
        glVertex3f(m_Nodo.x, m_Nodo.y, 0.0f);
 
476
        glEnd();
 
477
        glDisable(GL_LINE_STIPPLE);
 
478
 
 
479
        //linea de la cruz 45 grados xa abajo
 
480
        
 
481
        glLineWidth(WIDGET_GROSOR_LINEA);
 
482
        glBegin(GL_LINES);
 
483
        glVertex3f(m_Nodo.x, m_Nodo.y, 0.0f);
 
484
        glVertex3f(m_Nodo.x + longitudLinea, m_Nodo.y - longitudLinea, 0.0f);
 
485
        glEnd();
 
486
}
 
487