Developer documentation | Axl-2.5.1

axlParameterSpace.cpp
Go to the documentation of this file.
1 /* axlParameterSpace.cpp ---
2  *
3  * Author: Julien Wintz
4  * Copyright (C) 2008 - Julien Wintz, Inria.
5  * Created: Mon Mar 28 13:54:50 2011 (+0200)
6  * Version: $Id$
7  * Last-Updated: Wed Nov 9 15:04:28 2011 (+0100)
8  * By: Julien Wintz
9  * Update #: 80
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlParameterSpace.h"
21 
22 // /////////////////////////////////////////////////////////////////
23 // axlParameterSpaceView
24 // /////////////////////////////////////////////////////////////////
25 
26 class axlParameterSpaceViewPrivate
27 {
28 public:
29 
30 };
31 
32 axlParameterSpaceView::axlParameterSpaceView(QWidget *parent) : QGraphicsView(parent), d(new axlParameterSpaceViewPrivate)
33 {
34  this->setFrameShape(QFrame::NoFrame);
35 }
36 
38 {
39  delete d;
40 
41  d = NULL;
42 }
43 
44 // /////////////////////////////////////////////////////////////////
45 // axlParameterSpaceScene
46 // /////////////////////////////////////////////////////////////////
47 
48 class axlParameterSpaceScenePrivate
49 {
50 public:
51  double min_range_u;
52  double max_range_u;
53 
54  double min_range_v;
55  double max_range_v;
56 
57  double min_range_w;
58  double max_range_w;
59 };
60 
61 axlParameterSpaceScene::axlParameterSpaceScene(QObject *parent) : QGraphicsScene(parent), d(new axlParameterSpaceScenePrivate)
62 {
63  d->min_range_u = 0.0;
64  d->max_range_u = 0.0;
65  d->min_range_v = 0.0;
66  d->max_range_v = 0.0;
67  d->min_range_w = 0.0;
68  d->max_range_w = 0.0;
69 
70  this->setBackgroundBrush(QColor(230, 230, 230));
71 }
72 
74 {
75  delete d;
76 
77  d = NULL;
78 }
79 
81 {
82  this->setSceneRect(0, 0, size.width(), size.height());
83 }
84 
85 void axlParameterSpaceScene::setRangeU(double min, double max)
86 {
87  d->min_range_u = min;
88  d->max_range_u = max;
89 }
90 
91 void axlParameterSpaceScene::setRangeV(double min, double max)
92 {
93  d->min_range_v = min;
94  d->max_range_v = max;
95 }
96 
97 void axlParameterSpaceScene::setRangeW(double min, double max)
98 {
99  d->min_range_w = min;
100  d->max_range_w = max;
101 }
102 
103 void axlParameterSpaceScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
104 {
105  double x = event->scenePos().x();
106  double y = event->scenePos().y();
107 
108  double u = d->min_range_u + x/this->width() * (d->max_range_u - d->min_range_u);
109  double v = d->min_range_v + y/this->height() * (d->max_range_v - d->min_range_v);
110 
111  if(u > d->max_range_u)
112  u = d->max_range_u;
113 
114  if(u < d->min_range_u)
115  u = d->min_range_u;
116 
117  if(v > d->max_range_v)
118  v = d->max_range_v;
119 
120  if(v < d->min_range_v)
121  v = d->min_range_v;
122 
123 
124  emit moveCurrentPoint(u, v);
125  emit update();
126 }
127 
128 void axlParameterSpaceScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
129 {
130  double x = event->scenePos().x();
131  double y = event->scenePos().y();
132 
133  double u = d->min_range_u + x/this->width() * (d->max_range_u - d->min_range_u);
134  double v = d->min_range_v + y/this->height() * (d->max_range_v - d->min_range_v);
135 
136  emit showCurrentPoint(u, v);
137  emit update();
138 }
139 
140 void axlParameterSpaceScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
141 {
142  double x = event->scenePos().x();
143  double y = event->scenePos().y();
144 
145  double u = d->min_range_u + x/this->width() * (d->max_range_u - d->min_range_u);
146  double v = d->min_range_v + y/this->height() * (d->max_range_v - d->min_range_v);
147 
148  emit hideCurrentPoint(u, v);
149  emit update();
150 }
151 
152 // /////////////////////////////////////////////////////////////////
153 // axlParameterSpaceView
154 // /////////////////////////////////////////////////////////////////
155 
156 class axlParameterSpacePrivate
157 {
158 public:
159  axlParameterSpaceScene *scene;
160  axlParameterSpaceView *view;
161 };
162 
163 axlParameterSpace::axlParameterSpace(QWidget *parent) : QFrame(parent), d(new axlParameterSpacePrivate)
164 {
165  d->scene = new axlParameterSpaceScene(this);
166 
167  d->view = new axlParameterSpaceView(this);
168  d->view->setScene(d->scene);
169 
170  QVBoxLayout *layout = new QVBoxLayout(this);
171  layout->setContentsMargins(0, 0, 0, 0);
172  layout->setSpacing(0);
173  layout->addWidget(d->view);
174 
175  connect(d->scene, SIGNAL(showCurrentPoint(double, double)), this, SIGNAL(showCurrentPoint(double, double)));
176  connect(d->scene, SIGNAL(hideCurrentPoint(double, double)), this, SIGNAL(hideCurrentPoint(double, double)));
177  connect(d->scene, SIGNAL(moveCurrentPoint(double, double)), this, SIGNAL(moveCurrentPoint(double, double)));
178  connect(d->scene, SIGNAL(update()), this, SIGNAL(update()));
179 }
180 
181 
183 {
184  delete d;
185 
186  d = NULL;
187 }
188 
189 void axlParameterSpace::setRangeU(double min, double max)
190 {
191  d->scene->setRangeU(min, max);
192 }
193 
194 void axlParameterSpace::setRangeV(double min, double max)
195 {
196  d->scene->setRangeV(min, max);
197 }
198 
199 void axlParameterSpace::setRangeW(double min, double max)
200 {
201  d->scene->setRangeW(min, max);
202 }
203 
204 void axlParameterSpace::resizeEvent(QResizeEvent *event)
205 {
206  d->scene->resize(event->size());
207 }
axlParameterSpaceScene(QObject *parent=0)
void showCurrentPoint(double u, double v)
void setRangeW(double min, double max)
axlParameterSpace(QWidget *parent=0)
void setRangeU(double min, double max)
void hideCurrentPoint(double u, double v)
void hideCurrentPoint(double u, double v)
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
void setRangeV(double min, double max)
void setRangeW(double min, double max)
void setRangeV(double min, double max)
axlParameterSpaceView(QWidget *parent=0)
void moveCurrentPoint(double u, double v)
void showCurrentPoint(double u, double v)
void setRangeU(double min, double max)
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
void moveCurrentPoint(double u, double v)
void resizeEvent(QResizeEvent *event)