3
* $Id: wanotacionesquina.cpp $
6
* Copyright 2008-12 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
18
#include <cairo/cairo.h>
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>
30
#include <eventos/modificacionimagen.h>
32
#include <main/entorno.h>
33
#include <main/controllers/controladoreventos.h>
34
#include <main/controllers/configurationcontroller.h>
36
#include "wstaticrule.h"
39
#include <vtkImageData.h>
40
#include <vtkImageActor.h>
41
#include <vtkPointData.h>
42
#include <vtk/vtkginkgoimageviewer.h>
45
//region "Constructor y destructor"
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)
53
GNC::GCS::ConfigurationController::Instance()->readBoolUser("/GinkgoCore/Tools/CornerAnotations", "IsShown", m_Oculto, true);
55
m_ReservaRecursos = false;
56
m_color = GNC::GCS::GLHelper::TColor(ANNOTATOR_STATIC_RULE_COLOR);
58
GNC::GCS::Events::EventoModificacionImagen evt2(m_pManager->GetVista());
59
GNC::GCS::IEventsController::Instance()->Registrar(this, evt2);
62
GNC::GCS::Widgets::WStaticRule::~WStaticRule()
68
//region "Interfaz generica"
70
void GNC::GCS::Widgets::WStaticRule::OnMouseEvents(GNC::GCS::Events::EventoRaton& /*evento*/)
75
void GNC::GCS::Widgets::WStaticRule::OnKeyEvents(GNC::GCS::Events::EventoTeclado& /*evento*/)
79
bool GNC::GCS::Widgets::WStaticRule::HitTest(float , float , const GNC::GCS::Vector&)
84
bool GNC::GCS::Widgets::WStaticRule::HitTest(GNC::GCS::Vector* , int )
89
void GetRuleMeasureAndFragments(double maxMeasure, double& ruleMeasure, double& ruleFragments)
91
if (maxMeasure > 1000) {
94
} else if (maxMeasure > 100) {
97
} else if (maxMeasure > 50) {
100
} else if (maxMeasure > 10) {
103
} else if (maxMeasure > 5) {
106
} else if (maxMeasure > 1) {
109
} else if (maxMeasure > 0.5) {
112
} else if(maxMeasure > 0.1) {
115
} else if (maxMeasure > 0.05) {
118
} else if(maxMeasure > 0.01) {
124
void GNC::GCS::Widgets::WStaticRule::Render(GNC::GCS::Contexto3D* c)
126
if(m_Oculto && c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL){
130
vtkGinkgoImageViewer* pImageViewer = c->GetRenderer()->m_pImageViewer;
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);
135
glPushAttrib(GL_ALL_ATTRIB_BITS);
137
glMatrixMode(GL_TEXTURE);
141
glMatrixMode(GL_PROJECTION);
144
glOrtho( 0, viewport[2] , viewport[3] , 0, -1, 1 );
146
glMatrixMode(GL_MODELVIEW);
152
GNC::GCS::Vector3D screenToImage(c->RelacionImagenPantalla().x,c->RelacionImagenPantalla().y,1);
154
pImageViewer->GetSpacing(spacing);
155
GNC::GCS::Vector3D spacingVector(spacing[0], spacing[1], spacing[2]);
156
GNC::GCS::Vector3D screenToWorld = spacingVector * screenToImage;
158
GNC::GCS::Vector ruleMeasure;
159
GNC::GCS::Vector ruleFragments;
161
GetRuleMeasureAndFragments(0.95f * viewport[2] * screenToWorld.x, ruleMeasure.x, ruleFragments.x);
162
GetRuleMeasureAndFragments(0.95f * viewport[3] * screenToWorld.y, ruleMeasure.y, ruleFragments.y);
164
// Dibujado de la regla
165
glLineWidth(WIDGET_GROSOR_LINEA);
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])};
171
glColor4f(m_color.RF(), m_color.GF(), m_color.BF(), m_color.AF());
173
glVertex2d(xLimitsRule[0], viewport[3] - RULE_MARGIN);
174
glVertex2d(xLimitsRule[1], viewport[3] - RULE_MARGIN);
178
for (int i = 0; i <= ruleFragments.x; ++i) {
180
glVertex2d(xLimitsRule[0] + (i*ruleMeasureScreen[0]/ruleFragments.x), viewport[3] - RULE_MARGIN);
182
glVertex2d(xLimitsRule[0] + (i*ruleMeasureScreen[0]/ruleFragments.x), viewport[3] - RULE_MARGIN - SIZE_BIG_MARKS);
184
glVertex2d(xLimitsRule[0] + (i*ruleMeasureScreen[0]/ruleFragments.x), viewport[3] - RULE_MARGIN - SIZE_SMALL_MARKS);
191
glVertex2d(RULE_MARGIN,yLimitsRule[0]);
192
glVertex2d(RULE_MARGIN,yLimitsRule[1]);
196
for (int i = 0; i <= ruleFragments.y; ++i) {
198
glVertex2d(RULE_MARGIN, yLimitsRule[0] + (i*ruleMeasureScreen[1]/ruleFragments.y));
200
glVertex2d(RULE_MARGIN + SIZE_BIG_MARKS, yLimitsRule[0] + (i*ruleMeasureScreen[1]/ruleFragments.y) );
202
glVertex2d(RULE_MARGIN + SIZE_SMALL_MARKS, yLimitsRule[0] + (i*ruleMeasureScreen[1]/ruleFragments.y) );
210
glMatrixMode(GL_PROJECTION);
213
glMatrixMode(GL_TEXTURE);
216
glMatrixMode(GL_MODELVIEW);
221
void GNC::GCS::Widgets::WStaticRule::Modificar (bool /*modificada*/)
226
void GNC::GCS::Widgets::WStaticRule::Seleccionar(bool )
230
void GNC::GCS::Widgets::WStaticRule::Iluminar(bool )
234
void GNC::GCS::Widgets::WStaticRule::Ocultar(bool oculto)
236
if(oculto != m_Oculto){
244
//region "Interfaz especifica"
249
//region "Estado interno"
251
//region Interfaz de eventos ginkgo
253
void GNC::GCS::Widgets::WStaticRule::ProcesarEvento(GNC::GCS::Events::IEvent *evt)
256
std::cerr << "Error: Evento nulo" << std::endl;
259
switch (evt->GetCodigoEvento()) {
261
case ginkgoEVT_Core_ModificacionImagen:
263
/* GNC::GCS::Events::EventoModificacionImagen* pEvt = dynamic_cast<GNC::GCS::Events::EventoModificacionImagen*>(evt);
264
if (pEvt != NULL && pEvt->GetTipo() == GNC::GCS::Events::EventoModificacionImagen::AnotacionesEstaticasModificadas) {
266
m_Estado->InvalidarTodas();
276
void GNC::GCS::Widgets::WStaticRule::OffscreenRender(GNC::GCS::Contexto3D* /*c*/)