~ubuntu-branches/ubuntu/trusty/ginkgocadx/trusty

« back to all changes in this revision

Viewing changes to src/cadxcore/widgets/wstaticrule.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2013-07-21 11:58:53 UTC
  • mfrom: (7.2.1 sid)
  • Revision ID: package-import@ubuntu.com-20130721115853-44e7n1xujqglu78e
Tags: 3.4.0.928.29+dfsg-1
* New upstream release [July 2013]
  + new B-D: "libjsoncpp-dev".
  + new patch "unbundle-libjsoncpp.patch" to avoid building bundled
    "libjsoncpp-dev".
  + new patch "fix-wx.patch" to avoid FTBFS due to missing
    "-lwx_gtk2u_html-2.8".
* Removed unnecessary versioned Build-Depends.
* Removed obsolete lintian override.
* Reference get-orig-source implementation for orig.tar clean-up and
  DFSG-repackaging.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
*  
 
3
*  $Id: wanotacionesquina.cpp $
 
4
*  Ginkgo CADx Project
 
5
*
 
6
*  Copyright 2008-12 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
 
 
15
#include <sstream>
 
16
#include <cmath>
 
17
#include <cstring>
 
18
#include <cairo/cairo.h>
 
19
 
 
20
//#define _GINKGO_TRACE
 
21
#include <api/globals.h>
 
22
#include <api/helpers/helpertexto.h>
 
23
#include <api/iwidgetsmanager.h>
 
24
#include <api/controllers/icontroladorlog.h>
 
25
#include <api/ievento.h>
 
26
#include <api/icontexto.h>
 
27
#include <api/math/geometry3d.h>
 
28
#include <api/westilo.h>
 
29
 
 
30
#include <eventos/modificacionimagen.h>
 
31
 
 
32
#include <main/entorno.h>
 
33
#include <main/controllers/controladoreventos.h>
 
34
#include <main/controllers/configurationcontroller.h>
 
35
 
 
36
#include "wstaticrule.h"
 
37
 
 
38
#include <vtkgl.h>
 
39
#include <vtkImageData.h>
 
40
#include <vtkImageActor.h>
 
41
#include <vtkPointData.h>
 
42
#include <vtk/vtkginkgoimageviewer.h>
 
43
 
 
44
 
 
45
//region "Constructor y destructor"
 
46
 
 
47
#define ANNOTATOR_STATIC_RULE_COLOR 0.0f, 1.0f, 0.0f, 0.5f
 
48
#define RULE_MARGIN 20
 
49
#define SIZE_BIG_MARKS 10
 
50
#define SIZE_SMALL_MARKS 5
 
51
GNC::GCS::Widgets::WStaticRule::WStaticRule(IWidgetsManager* pManager, long vid, const char* nombre, long gid) : GNC::GCS::Widgets::IWidget(pManager, vid, nombre, gid)
 
52
{
 
53
        GNC::GCS::ConfigurationController::Instance()->readBoolUser("/GinkgoCore/Tools/CornerAnotations", "IsShown", m_Oculto, true);
 
54
        m_TopLevel = true;
 
55
        m_ReservaRecursos = false;
 
56
        m_color = GNC::GCS::GLHelper::TColor(ANNOTATOR_STATIC_RULE_COLOR);
 
57
 
 
58
        GNC::GCS::Events::EventoModificacionImagen evt2(m_pManager->GetVista());
 
59
        GNC::GCS::IEventsController::Instance()->Registrar(this, evt2);
 
60
}
 
61
 
 
62
GNC::GCS::Widgets::WStaticRule::~WStaticRule()
 
63
{}
 
64
 
 
65
//endregion
 
66
 
 
67
 
 
68
//region "Interfaz generica"
 
69
 
 
70
void GNC::GCS::Widgets::WStaticRule::OnMouseEvents(GNC::GCS::Events::EventoRaton& /*evento*/)
 
71
{
 
72
 
 
73
}
 
74
 
 
75
void GNC::GCS::Widgets::WStaticRule::OnKeyEvents(GNC::GCS::Events::EventoTeclado& /*evento*/)
 
76
{
 
77
}
 
78
 
 
79
bool GNC::GCS::Widgets::WStaticRule::HitTest(float , float , const GNC::GCS::Vector&)
 
80
{
 
81
        return false;
 
82
}
 
83
 
 
84
bool GNC::GCS::Widgets::WStaticRule::HitTest(GNC::GCS::Vector* , int )
 
85
{
 
86
        return false;
 
87
}
 
88
 
 
89
void GetRuleMeasureAndFragments(double maxMeasure, double& ruleMeasure, double& ruleFragments)
 
90
{
 
91
        if (maxMeasure > 1000) {
 
92
                ruleMeasure = 1000;
 
93
                ruleFragments = 10;
 
94
        } else if (maxMeasure > 100) {
 
95
                ruleMeasure = 100;
 
96
                ruleFragments = 10;
 
97
        } else if (maxMeasure > 50) {
 
98
                ruleMeasure = 50;
 
99
                ruleFragments = 5;
 
100
        } else if (maxMeasure > 10) {
 
101
                ruleMeasure = 10;
 
102
                ruleFragments = 10;
 
103
        } else if (maxMeasure > 5) {
 
104
                ruleMeasure = 5;
 
105
                ruleFragments = 5;
 
106
        } else if (maxMeasure > 1) {
 
107
                ruleMeasure = 1;
 
108
                ruleFragments = 10;
 
109
        }  else if (maxMeasure > 0.5) {
 
110
                ruleMeasure = 0.5;
 
111
                ruleFragments = 5;
 
112
        } else if(maxMeasure > 0.1) {
 
113
                ruleMeasure = 0.1;
 
114
                ruleFragments = 10;
 
115
        } else if (maxMeasure > 0.05) {
 
116
                ruleMeasure = 0.05;
 
117
                ruleFragments = 5;
 
118
        } else if(maxMeasure > 0.01) {
 
119
                ruleMeasure = 0.01;
 
120
                ruleFragments = 10;
 
121
        }
 
122
}
 
123
 
 
124
void GNC::GCS::Widgets::WStaticRule::Render(GNC::GCS::Contexto3D* c)
 
125
{
 
126
        if(m_Oculto && c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL){
 
127
                return;
 
128
        }
 
129
 
 
130
        vtkGinkgoImageViewer* pImageViewer = c->GetRenderer()->m_pImageViewer;
 
131
 
 
132
        double viewport[4] = {0.0f, 0.0f, 0.0f, 0.0f}; // { x, y, ancho, alto }. Convenio de coordenadas: {x, y} == {bottom, left}, {ancho, alto} == {top, right}
 
133
        glGetDoublev(GL_VIEWPORT, viewport);
 
134
 
 
135
        glPushAttrib(GL_ALL_ATTRIB_BITS);
 
136
 
 
137
        glMatrixMode(GL_TEXTURE);
 
138
        glPushMatrix();
 
139
        glLoadIdentity();
 
140
 
 
141
        glMatrixMode(GL_PROJECTION);
 
142
        glPushMatrix();
 
143
        glLoadIdentity();
 
144
        glOrtho( 0, viewport[2] , viewport[3] , 0, -1, 1 );
 
145
 
 
146
        glMatrixMode(GL_MODELVIEW);
 
147
        glPushMatrix();
 
148
        glLoadIdentity();
 
149
 
 
150
 
 
151
        {
 
152
                GNC::GCS::Vector3D screenToImage(c->RelacionImagenPantalla().x,c->RelacionImagenPantalla().y,1);
 
153
                double spacing[3];
 
154
                pImageViewer->GetSpacing(spacing);
 
155
                GNC::GCS::Vector3D spacingVector(spacing[0], spacing[1], spacing[2]);
 
156
                GNC::GCS::Vector3D screenToWorld = spacingVector * screenToImage;
 
157
                                
 
158
                GNC::GCS::Vector ruleMeasure;
 
159
                GNC::GCS::Vector ruleFragments;
 
160
                
 
161
                GetRuleMeasureAndFragments(0.95f * viewport[2] * screenToWorld.x, ruleMeasure.x, ruleFragments.x);
 
162
                GetRuleMeasureAndFragments(0.95f * viewport[3] * screenToWorld.y, ruleMeasure.y, ruleFragments.y);
 
163
                        
 
164
                // Dibujado de la regla         
 
165
                glLineWidth(WIDGET_GROSOR_LINEA);
 
166
 
 
167
                const double ruleMeasureScreen[2] = {ruleMeasure.x/screenToWorld.x,ruleMeasure.y/screenToWorld.y};
 
168
                const double xLimitsRule[2] = {(viewport[2]/2)-(0.5*ruleMeasureScreen[0]), (viewport[2]/2)+(0.5*ruleMeasureScreen[0])};
 
169
                const double yLimitsRule[2] = {(viewport[3]/2)-(0.5*ruleMeasureScreen[1]), (viewport[3]/2)+(0.5*ruleMeasureScreen[1])};
 
170
 
 
171
                glColor4f(m_color.RF(), m_color.GF(), m_color.BF(), m_color.AF());
 
172
                glBegin(GL_LINES);
 
173
                        glVertex2d(xLimitsRule[0], viewport[3] - RULE_MARGIN);
 
174
                        glVertex2d(xLimitsRule[1], viewport[3] - RULE_MARGIN);
 
175
                glEnd();
 
176
 
 
177
                //marks
 
178
                for (int i = 0; i <= ruleFragments.x; ++i) {
 
179
                        glBegin(GL_LINES);
 
180
                                glVertex2d(xLimitsRule[0] + (i*ruleMeasureScreen[0]/ruleFragments.x), viewport[3] - RULE_MARGIN);
 
181
                                if (i%5==0) {
 
182
                                        glVertex2d(xLimitsRule[0] + (i*ruleMeasureScreen[0]/ruleFragments.x), viewport[3] - RULE_MARGIN - SIZE_BIG_MARKS);
 
183
                                } else {
 
184
                                        glVertex2d(xLimitsRule[0] + (i*ruleMeasureScreen[0]/ruleFragments.x), viewport[3] - RULE_MARGIN - SIZE_SMALL_MARKS);
 
185
                                }
 
186
                        glEnd();
 
187
                }
 
188
 
 
189
                //yRule
 
190
                glBegin(GL_LINES);
 
191
                        glVertex2d(RULE_MARGIN,yLimitsRule[0]);
 
192
                        glVertex2d(RULE_MARGIN,yLimitsRule[1]);
 
193
                glEnd();
 
194
 
 
195
                //marks
 
196
                for (int i = 0; i <=  ruleFragments.y; ++i) {
 
197
                        glBegin(GL_LINES);
 
198
                                glVertex2d(RULE_MARGIN, yLimitsRule[0] + (i*ruleMeasureScreen[1]/ruleFragments.y));
 
199
                                if (i%5==0) {
 
200
                                        glVertex2d(RULE_MARGIN + SIZE_BIG_MARKS, yLimitsRule[0] + (i*ruleMeasureScreen[1]/ruleFragments.y) );
 
201
                                } else {
 
202
                                        glVertex2d(RULE_MARGIN + SIZE_SMALL_MARKS, yLimitsRule[0] + (i*ruleMeasureScreen[1]/ruleFragments.y) );
 
203
                                }
 
204
                        glEnd();
 
205
                }
 
206
        }
 
207
 
 
208
        glPopMatrix();
 
209
 
 
210
        glMatrixMode(GL_PROJECTION);
 
211
        glPopMatrix();
 
212
 
 
213
        glMatrixMode(GL_TEXTURE);
 
214
        glPopMatrix();
 
215
 
 
216
        glMatrixMode(GL_MODELVIEW);
 
217
 
 
218
        glPopAttrib();
 
219
}
 
220
 
 
221
void GNC::GCS::Widgets::WStaticRule::Modificar (bool /*modificada*/)
 
222
{
 
223
 
 
224
}
 
225
 
 
226
void GNC::GCS::Widgets::WStaticRule::Seleccionar(bool )
 
227
{
 
228
}
 
229
 
 
230
void GNC::GCS::Widgets::WStaticRule::Iluminar(bool )
 
231
{
 
232
}
 
233
 
 
234
void GNC::GCS::Widgets::WStaticRule::Ocultar(bool oculto)
 
235
{
 
236
        if(oculto != m_Oculto){
 
237
                m_Oculto = oculto;
 
238
        }
 
239
}
 
240
 
 
241
//endregion
 
242
 
 
243
 
 
244
//region "Interfaz especifica"
 
245
 
 
246
//endregion
 
247
 
 
248
 
 
249
//region "Estado interno"
 
250
 
 
251
//region Interfaz de eventos ginkgo
 
252
 
 
253
void GNC::GCS::Widgets::WStaticRule::ProcesarEvento(GNC::GCS::Events::IEvent *evt)
 
254
{
 
255
        if (evt == NULL) {
 
256
                std::cerr << "Error: Evento nulo" << std::endl;
 
257
                return;
 
258
        }
 
259
        switch (evt->GetCodigoEvento()) {
 
260
 
 
261
        case ginkgoEVT_Core_ModificacionImagen:
 
262
                {
 
263
        /*              GNC::GCS::Events::EventoModificacionImagen* pEvt = dynamic_cast<GNC::GCS::Events::EventoModificacionImagen*>(evt);
 
264
                        if (pEvt != NULL && pEvt->GetTipo() == GNC::GCS::Events::EventoModificacionImagen::AnotacionesEstaticasModificadas) {
 
265
                                Modificar(true);
 
266
                                m_Estado->InvalidarTodas();
 
267
                        }*/
 
268
                }
 
269
                break;
 
270
 
 
271
        }
 
272
}
 
273
 
 
274
//endregion
 
275
 
 
276
void GNC::GCS::Widgets::WStaticRule::OffscreenRender(GNC::GCS::Contexto3D* /*c*/)
 
277
{
 
278
        
 
279
}
 
280