Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Netpane: use `std::unique_ptr` for data. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
9356d6cdbc6f646781d8f83a949283cb |
| User & Date: | fifr 2017-05-06 16:29:01.042 |
Context
|
2017-05-06
| ||
| 18:01 | KraView: copy url in `writeTikz`. check-in: b0120ac24a user: fifr tags: trunk | |
| 16:29 | Netpane: use `std::unique_ptr` for data. check-in: 9356d6cdbc user: fifr tags: trunk | |
| 16:17 | Update translations. check-in: d8d97897bd user: fifr tags: trunk | |
Changes
Changes to src/Netpane.cxx.
| ︙ | ︙ | |||
61 62 63 64 65 66 67 |
const Net* net;
bool initialized;
};
Netpane::Netpane() :
| | | | | | | | | | | | | | < | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
const Net* net;
bool initialized;
};
Netpane::Netpane() :
d(new Data)
{
d->x = 0;
d->y = 0;
d->width = 0;
d->height = 0;
d->scale = MAX_SCALE;
d->xscale = MAX_SCALE;
d->yscale = MAX_SCALE;
d->itemlist = 0;
d->hitlist = 0;
d->scalelist = 0;
d->net = nullptr;
d->initialized = false;
}
Netpane::~Netpane()
{
}
static void draw_disc(int name, double x, double y, double r)
{
static GLUquadric* quadric = nullptr;
if (quadric == nullptr) quadric = gluNewQuadric();
|
| ︙ | ︙ | |||
222 223 224 225 226 227 228 |
draw_arc(net, i, with_names);
}
}
void Netpane::redraw_net()
{
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
draw_arc(net, i, with_names);
}
}
void Netpane::redraw_net()
{
if (!d->net || !d->initialized) return;
glNewList(d->itemlist, GL_COMPILE);
draw_graph(*d->net, false);
glEndList();
glNewList(d->hitlist, GL_COMPILE);
draw_graph(*d->net, true);
glEndList();
}
void Netpane::rescale()
{
if (!d->initialized) return;
if (log10(d->scale) < MIN_SCALE)
d->scale = pow(10.0, MIN_SCALE);
else if (log10(d->scale) > MAX_SCALE)
d->scale = pow(10.0, MAX_SCALE);
glNewList(d->scalelist, GL_COMPILE);
glScalef(d->scale, d->scale, 1);
glEndList();
if (d->width < d->height) {
d->xscale = d->scale;
d->yscale = d->scale * d->height / d->width;
} else {
d->xscale = d->scale * d->width / d->height;
d->yscale = d->scale;
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-d->xscale / 2, d->xscale / 2, -d->yscale / 2, d->yscale / 2);
glMatrixMode(GL_MODELVIEW);
}
void Netpane::init()
{
glShadeModel(GL_FLAT);
glClearColor(1.0, 1.0, 1.0, 1.0);
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LINE_SMOOTH);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLuint n = glGenLists(3);
d->itemlist = (int)n++;
d->hitlist = (int)n++;
d->scalelist = (int)n++;
d->initialized = true;
d->scale = 1.0;
d->height = 1;
d->width = 1;
rescale();
redraw_net();
}
void Netpane::resize(double width, double height)
{
d->width = width;
d->height = height;
glViewport(0, 0, width, height);
rescale();
}
void Netpane::fit()
{
if (!d->net) return;
double min_x = std::numeric_limits<double>::infinity();
double max_x = -std::numeric_limits<double>::infinity();
double min_y = std::numeric_limits<double>::infinity();
double max_y = -std::numeric_limits<double>::infinity();
for (size_type i = 0, n = d->net->num_nodes(); i < n; i++) {
auto& node = d->net->node(i);
min_x = std::min(node.x, min_x);
max_x = std::max(node.x, max_x);
min_y = std::min(node.y, min_y);
max_y = std::max(node.y, max_y);
}
double dx, dy;
if (d->width > d->height) {
dx = (max_x - min_x) * d->height / d->width;
dy = max_y - min_y;
} else {
dx = max_x - min_x;
dy = (max_y - min_y) * d->width / d->height;
}
d->scale = 1.1 * (dx > dy ? dx : dy);
d->x = -(min_x + max_x) / 2;
d->y = (min_y + max_y) / 2;
rescale();
}
void Netpane::paint()
{
glMatrixMode(GL_MODELVIEW);
glLineWidth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(d->x, d->y, 0);
glScalef(1, -1, 1);
glCallList(d->itemlist);
if (!d->hl_nodes.empty()) {
glLineWidth(3.0);
for (auto nodeid : d->hl_nodes)
draw_node(*d->net, nodeid, false, NODE_RADIUS * 1.3);
}
if (!d->hl_arcs.empty()) {
glLineWidth(5.0);
for (auto arcid : d->hl_arcs)
draw_arc(*d->net, arcid, false);
}
}
double Netpane::zoom() const
{
return d->scale;
}
void Netpane::set_zoom(double newscale)
{
d->scale = newscale;
rescale();
}
void Netpane::start_scale(int scale)
{
d->startscale = scale;
d->scalebase = d->scale;
}
void Netpane::do_scale(int scale)
{
double h = d->height < d->width ? d->width : d->height;
d->scale = d->scalebase * exp(10 * (scale - d->startscale) / h);
rescale();
}
void Netpane::start_move(int x, int y)
{
d->startmovex = x;
d->startmovey = y;
d->movebasex = d->x;
d->movebasey = d->y;
}
void Netpane::do_move(int x, int y)
{
d->x = d->movebasex
+ (x - d->startmovex) / d->width * d->xscale;
d->y = d->movebasey
+ (y - d->startmovey) / d->height * d->yscale;
}
void Netpane::get_items(int x, int y,
std::vector<size_type>& nodes,
std::vector<size_type>& arcs) const
{
nodes.clear();
arcs.clear();
if (!d->net) return;
GLint vp[4];
glGetIntegerv(GL_VIEWPORT, vp);
GLuint select_buf[512];
glSelectBuffer(512, select_buf);
glRenderMode(GL_SELECT);
glInitNames();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(x, vp[3] - y, 5, 5, vp);
gluOrtho2D(-d->xscale / 2, +d->xscale / 2, -d->yscale / 2, +d->yscale / 2);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(d->x , d->y, 0);
glScalef(1, -1, 1);
glCallList(d->hitlist);
glFlush();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
GLint nhits = glRenderMode(GL_RENDER);
GLint idx = 0;
size_type n = d->net->num_nodes();
for (GLint i = 0; i < nhits; i++) {
GLuint nnames = select_buf[idx];
idx += 3;
for (size_type j = 0; j < nnames; j++) {
if (select_buf[idx] < n)
nodes.push_back(select_buf[idx]);
else
arcs.push_back(select_buf[idx] - n);
idx += 1;
}
}
}
void Netpane::highlight_node(size_type nodeid, bool highlight)
{
if (highlight)
d->hl_nodes.insert(nodeid);
else
d->hl_nodes.erase(nodeid);
}
void Netpane::highlight_arc(size_type arcid, bool highlight)
{
if (highlight)
d->hl_arcs.insert(arcid);
else
d->hl_arcs.erase(arcid);
}
void Netpane::unhighlight_all()
{
d->hl_nodes.clear();
d->hl_arcs.clear();
}
void Netpane::set_net(const Net& net)
{
d->net = &net;
unhighlight_all();
redraw_net();
}
void Netpane::clear_net()
{
d->net = nullptr;
unhighlight_all();
redraw_net();
}
const Net* Netpane::net() const
{
return d->net;
}
|
Changes to src/Netpane.hxx.
| ︙ | ︙ | |||
16 17 18 19 20 21 22 | * You should have received a copy of the GNU General Public License * along with KraView. If not, see <http://www.gnu.org/licenses/>. */ #ifndef __GRAV_NETPANE_HXX__ #define __GRAV_NETPANE_HXX__ | | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
* You should have received a copy of the GNU General Public License
* along with KraView. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GRAV_NETPANE_HXX__
#define __GRAV_NETPANE_HXX__
#include <vector>
#include <memory>
namespace fifr {
namespace graph {
namespace grav {
class Net;
|
| ︙ | ︙ | |||
96 97 98 99 100 101 102 |
* do_scale. If d' - d = 0 then the zoom is unchanged, otherwise
* it is increased or decreased.
*
* The typical use of these functions is by calling start_scale
* with some mouse-coordinate on a click and do_scale with the new
* mouse coordinate on subsequent drags.
*
| | | | | | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
* do_scale. If d' - d = 0 then the zoom is unchanged, otherwise
* it is increased or decreased.
*
* The typical use of these functions is by calling start_scale
* with some mouse-coordinate on a click and do_scale with the new
* mouse coordinate on subsequent drags.
*
* @param scale start value for interactive zoom
*/
void start_scale(int scale);
/**
* Updates an interactive zoom.
*
* @param scale update value for interactive zoom
*
* @see start_scale.
*/
void do_scale(int scale);
/**
* Starts an interactive move.
*
* This function should be called with the x and y coordinates of
* a mouse click. Subsequent mouse drags should call do_move with
* the new coordinates.
|
| ︙ | ︙ | |||
161 162 163 164 165 166 167 |
void redraw_net();
/// Updates the viewpane w.r.t. the current scale.
void rescale();
private:
struct Data;
| | | 161 162 163 164 165 166 167 168 169 170 171 |
void redraw_net();
/// Updates the viewpane w.r.t. the current scale.
void rescale();
private:
struct Data;
std::unique_ptr<Data> d;
};
#endif
|