1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 93 94 95 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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 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 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442
|
/*
* Copyright (C) 1997 by the University of Southern California
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
*
* The copyright of this module includes the following
* linking-with-specific-other-licenses addition:
*
* In addition, as a special exception, the copyright holders of
* this module give you permission to combine (via static or
* dynamic linking) this module with free software programs or
* libraries that are released under the GNU LGPL and with code
* included in the standard release of ns-2 under the Apache 2.0
* license or under otherwise-compatible licenses with advertising
* requirements (or modified versions of such code, with unchanged
* license). You may copy and distribute such a system following the
* terms of the GNU GPL for this module and the licenses of the
* other code concerned, provided that you include the source code of
* that other code when and as the GNU GPL requires distribution of
* source code.
*
* Note that people who make modified versions of this module
* are not obligated to grant this special exception for their
* modified versions; it is their choice whether to do so. The GNU
* General Public License gives permission to release a modified
* version without this exception; this exception also makes it
* possible to release a modified version which carries forward this
* exception.
*
* $Header: /cvsroot/nsnam/nam-1/editview.cc,v 1.37 2011/10/31 05:46:16 tom_henderson Exp $
*/
#include <stdlib.h>
#ifdef WIN32
#include <windows.h>
#endif
#include <ctype.h>
#include <math.h>
#include "view.h"
#include "bbox.h"
#include "netmodel.h"
#include "editview.h"
#include "tclcl.h"
#include "paint.h"
#include "tag.h"
#include "node.h"
#include "edge.h"
#include "agent.h"
void EditView::DeleteCmdProc(ClientData cd)
{
EditView *ev = (EditView *)cd;
if (ev->tk_ != NULL) {
Tk_DestroyWindow(ev->tk_);
}
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
EditView::EditView(const char *name, NetModel* m)
: NetView(name), defTag_(NULL)
{
if (tk_!=0) {
Tcl& tcl = Tcl::instance();
cmd_ = Tcl_CreateCommand(tcl.interp(), Tk_PathName(tk_),
command,
(ClientData)this, DeleteCmdProc);
}
char str[256];
model_ = m;
sprintf(str, "def%-li", (long)this);
defTag_ = new Tag(str);
model_->add_tag(defTag_);
editing_stage_ = NONE;
}
//----------------------------------------------------------------------
// EditView::EditView(const char *name, NetModel* m,
// int width, int height)
//----------------------------------------------------------------------
EditView::EditView(const char *name, NetModel* m, int width, int height)
: NetView(name, SQUARE, width, height), defTag_(NULL) {
char str[256];
if (tk_!=0) {
Tcl& tcl = Tcl::instance();
cmd_ = Tcl_CreateCommand(tcl.interp(), Tk_PathName(tk_),
command, (ClientData) this,
DeleteCmdProc);
}
model_ = m;
sprintf(str, "def%-li", (long)this);
defTag_ = new Tag(name);
model_->add_tag(defTag_);
editing_stage_ = NONE;
}
EditView::~EditView()
{
model_->remove_view(this);
if (defTag_ != NULL) {
model_->delete_tag(defTag_->name());
delete defTag_;
defTag_ = NULL;
}
// Delete Tcl command created
// Tcl& tcl = Tcl::instance();
// Tcl_DeleteCommandFromToken(tcl.interp(), cmd_);
}
//----------------------------------------------------------------------
// int
// EditView::command(ClientData cd, Tcl_Interp* tcl,
// int argc, char **argv)
// Parse Tcl command interface
// - setPoint, addNode, addLink addAgent, deleteObject, etc...
//----------------------------------------------------------------------
int EditView::command(ClientData cd, Tcl_Interp* tcl,
int argc, CONST84 char **argv) {
EditorNetModel * editor_net_model;
Node * node, * source, * destination;
Edge * edge;
Agent * source_agent, * destination_agent;
TrafficSource * traffic_source;
LossModel * loss_model;
//double world_x, world_y;
if (argc < 2) {
Tcl_AppendResult(tcl, "\"", argv[0], "\": arg mismatch", 0);
return (TCL_ERROR);
}
char c = argv[1][0];
int length = strlen(argv[1]);
EditView * ev = (EditView *) cd;
editor_net_model = (EditorNetModel *) ev->model_;
float cx, cy;
int flag;
// Following implements several useful interactive commands of
// Tk's canvas. Their syntax and semantics are kept as close to
// those of Tk canvas as possible.
if ((c == 'd') && (strncmp(argv[1], "draw", length) == 0)) {
// Redraw seen at time = argv[2]
ev->draw(strtod(argv[2],NULL));
return TCL_OK;
} else if ((c == 'c') && (strncmp(argv[1], "close", length) == 0)) {
ev->destroy();
return TCL_OK;
} else if ((c == 'd') &&
(strncmp(argv[1], "dctag", length) == 0)) {
/*
* <view> dctag
*
* Delete the current selection, start all over.
*/
if (ev->defTag_ != NULL)
ev->defTag_->remove();
ev->draw();
return (TCL_OK);
} else if ((c == 's') &&
(strncmp(argv[1], "setPoint", length) == 0)) {
/*
* <view> setPoint x y addFlag
*
* Select the object (if any) under point (x, y). If no such
* object, set current point to (x, y)
*/
if (argc != 5) {
Tcl_AppendResult(tcl, "wrong # args: should be \"",
argv[0], " setPoint x y addFlag\"",
(char *)NULL);
return (TCL_ERROR);
}
cx = strtod(argv[2], NULL);
cy = strtod(argv[3], NULL);
flag = strtol(argv[4], NULL, 10);
return ev->cmdSetPoint(cx, cy, flag);
} else if ((c == 'd') && (strncmp(argv[1], "deleteObject", length) == 0)) {
cx = strtod(argv[2], NULL);
cy = strtod(argv[3], NULL);
return ev->cmdDeleteObj(cx, cy);
} else if ((c == 'm') && (strncmp(argv[1], "moveTo", length) == 0)) {
/*
* <view> moveto x y
*
* Move the current selected object (if any) or the
* rubber band to point (x, y)
*/
if (argc != 4) {
Tcl_AppendResult(tcl, "wrong # args: should be \"",
argv[0],
" moveTo x y\"", (char *)NULL);
return (TCL_ERROR);
}
cx = strtod(argv[2], NULL);
cy = strtod(argv[3], NULL);
return ev->cmdMoveTo(cx, cy);
} else if ((c == 'r') && (strncmp(argv[1], "releasePoint", length) == 0)) {
/*
* <view> releasePoint x y
*
* If any object is selected, set the object's
* position to point (x,y); otherwise set the rubber
* band rectangle and select all the objects in that
* rectangle Note: we need a default tag for the
* selection in rubber band.
*/
if (argc != 4) {
Tcl_AppendResult(tcl, "wrong # args: should be \"",
argv[0],
" releasePoint x y\"", (char *)NULL);
return (TCL_ERROR);
}
cx = strtod(argv[2], NULL);
cy = strtod(argv[3], NULL);
return ev->cmdReleasePoint(cx, cy);
} else if ((c == 's') && (strncmp(argv[1], "setNodeProperty", length) == 0)) {
// <view> setNodeProperty nodeid nodepropertyvalue properyname
int nodeid = atoi(argv[2]);
return ev->cmdsetNodeProperty(nodeid, argv[3], argv[4]);
} else if ((c == 's') && (strncmp(argv[1], "setAgentProperty", length) == 0)) {
// <view> setAgentProperty nodeid nodepropertyvalue properyname
int agentid = atoi(argv[2]);
return ev->cmdsetAgentProperty(agentid, argv[3], argv[4]);
} else if ((c == 's') && (strncmp(argv[1], "setLinkProperty", length) == 0)) {
// <view> setLinkProperty sid did propertyvalue properyname
int source_id = atoi(argv[2]);
int destination_id = atoi(argv[3]);
return ev->cmdsetLinkProperty(source_id, destination_id,
argv[4], argv[5]);
} else if ((c == 's') &&
(strncmp(argv[1], "setQueueHandleProperty", length) == 0)) {
// Called by the following code in Editor.tcl
// ------------------------------------------------------------
// $editor_view_ setQueueHandleProperty $source $destination
// $property_value
// $property_variable
//
// - argv[2] = source
// - argv[3] = destination
// - argv[4] = value
// - argv[5] = variable name
editor_net_model->setQueueHandleProperty(atoi(argv[2]), atoi(argv[3]),
argv[4], argv[5]);
ev->draw();
return TCL_OK;
} else if ((c == 's') &&
(strncmp(argv[1], "setTrafficSourceProperty", length) == 0)) {
// <view> setTrafficSourceProperty id propertyvalue propertyname
int id = atoi(argv[2]);
const char * value = argv[3];
const char * variable_name = argv[4];
return ev->cmdsetTrafficSourceProperty(id, value, variable_name);
} else if ((c == 's') &&
(strncmp(argv[1], "setLossModelProperty", length) == 0)) {
// <view> setLossModelProperty id propertyvalue propertyname
int id = atoi(argv[2]);
const char * value = argv[3];
const char * variable_name = argv[4];
return ev->cmdsetLossModelProperty(id, value, variable_name);
} else if ((c == 'a') && (strncmp(argv[1], "addNode", length) == 0)) {
// <view> addNode x y
// - add a new Node under current (x,y) with default size
cx = strtod(argv[2], NULL);
cy = strtod(argv[3], NULL);
return ev->cmdaddNode(cx, cy);
} else if ((c == 'i') && (strncmp(argv[1], "importNode", length) == 0)) {
// Used when reading a nam editor file to add a node created in tcl
// to this editview and its editornetmodel
node = (Node *) TclObject::lookup(argv[2]);
//world_x = atof(argv[3]);
//world_y = atof(argv[4]);
if (node) {
if (editor_net_model->addNode(node)) {
// node->place(world_x, world_y);
// ev->draw();
return TCL_OK;
}
}
fprintf(stderr, "Error creating node.\n");
return TCL_ERROR;
} else if ((c == 'a') && (strncmp(argv[1], "attachNodes", length) == 0)) {
// <view> linkNodes source_id destination_id
// - link 2 existing nodes to each other
edge = (Edge *) TclObject::lookup(argv[2]);
source = (Node *) TclObject::lookup(argv[3]);
destination = (Node *) TclObject::lookup(argv[4]);
edge->attachNodes(source, destination);
editor_net_model->addEdge(edge);
ev->draw();
return TCL_OK;
} else if ((c == 'a') && (strncmp(argv[1], "addLink", length) == 0)) {
// <view> addLink x y
// - add a new Link if its start AND end point is inside of
cx = strtod(argv[2], NULL);
cy = strtod(argv[3], NULL);
return ev->cmdaddLink(cx, cy);
} else if ((c == 'a') && (strncmp(argv[1], "addQueueHandle", length) == 0)) {
// <view> addQueueHandle edge queue_type
edge = (Edge *) TclObject::lookup(argv[2]);
if (edge) {
editor_net_model->addQueueHandle(edge, argv[3]);
}
return TCL_OK;
// --------------- Agent -----------------
} else if ((c == 'a') && (strncmp(argv[1], "addAgent", length) == 0)) {
// <view> addAgent x y agent
// - add a new agent
cx = strtod(argv[2], NULL);
cy = strtod(argv[3], NULL);
const char * agent_name = argv[4];
return ev->cmdaddAgent(cx, cy, agent_name);
} else if ((c == 'i') && (strncmp(argv[1], "importAgent", length) == 0)) {
source_agent = (Agent *) TclObject::lookup(argv[2]);
node = (Node *) TclObject::lookup(argv[3]);
return editor_net_model->addAgent(source_agent, node);
} else if ((c == 'l') && (strncmp(argv[1], "linkAgents", length) == 0)) {
// <view> linkAgents source_id destination_id
// - link 2 existing agents to each other
source_agent = (Agent *) TclObject::lookup(argv[2]);
destination_agent = (Agent *) TclObject::lookup(argv[3]);
return editor_net_model->addAgentLink(source_agent, destination_agent);
} else if ((c == 's') && (strncmp(argv[1], "showAgentLink", length) == 0)) {
cx = strtod(argv[2], NULL);
cy = strtod(argv[3], NULL);
return ev->showAgentLink(cx, cy);
} else if ((c == 'h') && (strncmp(argv[1], "hideAgentLinks", length) == 0)) {
editor_net_model->hideAgentLinks();
ev->draw();
return TCL_OK;
// --------------- Traffic Source -----------------
} else if ((c == 'a') &&
(strncmp(argv[1], "addTrafficSource", length) == 0)) {
// <view> addTrafficSource x y trafficsource_type
// - add a new TrafficSource
cx = strtod(argv[2], NULL);
cy = strtod(argv[3], NULL);
// argv[4] is the name of the traffic source
return ev->cmdaddTrafficSource(cx, cy, argv[4]);
} else if ((c == 'a') &&
(strncmp(argv[1], "attachTrafficSource", length) == 0)) {
traffic_source = (TrafficSource *) TclObject::lookup(argv[2]);
source_agent = (Agent *) TclObject::lookup(argv[3]);
return editor_net_model->addTrafficSource(traffic_source, source_agent);
// ----------- Loss Models ----------------
} else if ((c == 'a') &&
(strncmp(argv[1], "addLossModel", length) == 0)) {
// <view> addLossModel x y lossmodel
cx = strtod(argv[2], NULL);
cy = strtod(argv[3], NULL);
// argv[4] is the type of the loss model to add
return ev->cmdaddLossModel(cx, cy, argv[4]);
} else if ((c == 'a') &&
(strncmp(argv[1], "attachLossModel", length) == 0)) {
loss_model = (LossModel *) TclObject::lookup(argv[2]);
source = (Node *) TclObject::lookup(argv[3]);
destination = (Node *) TclObject::lookup(argv[4]);
edge = source->find_edge(destination->number());
return editor_net_model->addLossModel(loss_model, edge);
// ----------- Object and Object Properties ----------------
} else if ((c == 'g') &&
(strncmp(argv[1], "getObjectInformation", length) == 0)) {
// <view> getObject x y
// - return object under current point
cx = strtod(argv[2], NULL);
cy = strtod(argv[3], NULL);
return ev->cmdgetObjectInformation(cx, cy);
} else if ((c == 'g') &&
(strncmp(argv[1], "getObjectProperty", length) == 0)) {
// <view> getObjectPropert x y [type]
// - return properties for object under current point
// - if type is passed in then pass that to object
cx = strtod(argv[2], NULL);
cy = strtod(argv[3], NULL);
if (argc == 5) {
return ev->cmdgetObjectProperties(cx, cy, argv[4]);
} else {
return ev->cmdgetObjProperty(cx, cy);
}
} else if ((c == 'v') && (strncmp(argv[1], "view_mode", length)==0)) {
/*
* <view> view_mode
*
* clear defTag_ and change to view mode
*/
ev->view_mode();
return TCL_OK;
}
return (NetView::command(cd, tcl, argc, argv));
}
int EditView::cmdsetNodeProperty(int id, const char * value, const char * variable)
{
EditorNetModel* emodel_ = (EditorNetModel *) model_;
// goto enetmodel.cc
emodel_->setNodeProperty(id, value, variable);
// EditType oldt_;
// oldt_ = editing_stage_;
// editing_stage_ = END_OBJECT;
draw();
// editing_stage_ = NONE;
// model_->update(model_->now());
// editing_stage_ = oldt_;
return(TCL_OK);
}
int EditView::cmdsetAgentProperty(int id, const char * value, const char * variable) {
EditorNetModel* emodel_ = (EditorNetModel *) model_;
emodel_->setAgentProperty(id, value ,variable);
draw();
return(TCL_OK);
}
int EditView::cmdsetLinkProperty(int sid, int did,
const char * value, const char * variable) {
EditorNetModel * emodel_ = (EditorNetModel *) model_;
emodel_->setLinkProperty(sid, did, value, variable);
draw();
return(TCL_OK);
}
//----------------------------------------------------------------------
// int
// EditView::cmdsetTrafficSourceProperty(int sid, int did, const char *pv, int pn)
//----------------------------------------------------------------------
int
EditView::cmdsetTrafficSourceProperty(int id, const char * value, const char * variable) {
EditorNetModel* emodel_ = (EditorNetModel *) model_;
emodel_->setTrafficSourceProperty(id, value, variable);
draw();
return(TCL_OK);
}
//----------------------------------------------------------------------
// int
// EditView::cmdsetLossModelProperty(int id, char * value, char * variable)
//----------------------------------------------------------------------
int
EditView::cmdsetLossModelProperty(int id, const char * value, const char * variable) {
EditorNetModel* emodel_ = (EditorNetModel *) model_;
emodel_->setLossModelProperty(id, value, variable);
draw();
return(TCL_OK);
}
//----------------------------------------------------------------------
// int
// EditView::cmdgetObjProperty(float cx, float cy)
// - get properties for a selected object
//----------------------------------------------------------------------
int
EditView::cmdgetObjProperty(float cx, float cy) {
Animation *p;
Tcl& tcl = Tcl::instance();
// matrix_ comes from class View (view.h)
// - imap is the inverse mapping
// (i.e from screen to world coordinate systems)
matrix_.imap(cx, cy);
// Finds the object which contains the coordinate (cx, cy)
p = model_->inside(cx, cy);
if (p == NULL) {
tcl.resultf("NONE");
} else {
tcl.resultf("%s",p->property());
}
return(TCL_OK);
}
//----------------------------------------------------------------------
// int
// EditView::cmdgetObjectProperties(float cx, float cy, char * type)
// - get properties for a selected object and the specific
// type within that object
//----------------------------------------------------------------------
int
EditView::cmdgetObjectProperties(float cx, float cy, const char * type) {
Animation * animation_object;
Tcl& tcl = Tcl::instance();
// matrix_ comes from class View (view)
// - imap is the inverse mapping
// (i.e from screen to world coordinate systems)
matrix_.imap(cx, cy);
// Finds the object which contains the coordinate (cx, cy)
animation_object = model_->inside(cx, cy);
if (animation_object == NULL) {
tcl.resultf("NONE");
} else {
tcl.resultf("%s",animation_object->getProperties(type));
}
return(TCL_OK);
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
int EditView::cmdgetObjectInformation(float cx, float cy) {
Tcl& tcl = Tcl::instance();
matrix_.imap(cx, cy);
Animation *p = model_->inside(cx, cy);
if (p == NULL) {
tcl.resultf("NONE");
} else {
tcl.resultf("%s",p->info());
}
return(TCL_OK);
}
//----------------------------------------------------------------------
// int
// EditView::cmdaddLink(float cx, float cy)
// - Note: all cx_ and cy_ below are in *window* coordinates
//----------------------------------------------------------------------
int
EditView::cmdaddLink(float cx, float cy) {
Animation * p;
static Animation * old_p;
EditorNetModel* emodel_ = (EditorNetModel *) model_;
cx_ = cx;
cy_ = cy;
matrix_.imap(cx, cy);
// Do we have a node on current point ?
p = model_->inside(cx, cy);
if (p == NULL) {
defTag_->remove();
if (editing_stage_ == START_LINK) {
editing_stage_ = NONE;
draw();
}
return (TCL_OK);
}
if (p->classid() == ClassNodeID) {
if (editing_stage_ != START_LINK) {
old_p = p; /* remember the orig node */
startSetObject(p, cx_, cy_);
editing_stage_ = START_LINK;
} else if ((old_p == p)||(old_p->classid()!=ClassNodeID)) {
editing_stage_ = NONE;
draw();
// to support making link by click-&-click
editing_stage_ = START_LINK;
} else {
// add a new link b/w the two nodes
startSetObject(p, cx_, cy_);
Node *src, *dst;
src = (Node *)old_p;
dst = (Node *)p;
emodel_->addLink(src, dst);
editing_stage_ = END_OBJECT;
// Erase old positions
defTag_->draw(this, model_->now());
// At least we should redo scale estimation and
// place everything
defTag_->move(this, rb_.xmax - oldx_, rb_.ymax - oldy_);
model_->recalc();
model_->render(this);
defTag_->remove();
editing_stage_ = NONE;
draw();
editing_stage_ = NONE;
}
} else if (p->classid() == ClassAgentID) {
if (editing_stage_ != START_LINK) {
old_p = p;
startSetObject(p, cx_, cy_);
editing_stage_ = START_LINK;
} else if ((old_p == p)||(old_p->classid()!= ClassAgentID)) {
editing_stage_ = NONE;
draw();
// to support making agent-link by click-&-click
editing_stage_ = START_LINK;
} else {
startSetObject(p, cx_, cy_);
Agent *src_agent, *dst_agent;
src_agent = (Agent *)old_p;
dst_agent = (Agent *)p;
emodel_->addAgentLink(src_agent, dst_agent);
editing_stage_ = END_OBJECT;
defTag_->draw(this, model_->now());
defTag_->move(this, rb_.xmax - oldx_, rb_.ymax - oldy_);
model_->recalc();
model_->render(this);
defTag_->remove();
editing_stage_ = NONE;
draw();
}
} else {
editing_stage_ = NONE;
}
return(TCL_OK);
}
//----------------------------------------------------------------------
// int
// EditView::cmdaddAgent(float cx, float cy, char* agent)
//----------------------------------------------------------------------
int EditView::cmdaddAgent(float cx, float cy, const char* agent) {
Animation * p;
Node * src;
EditorNetModel* emodel_ = (EditorNetModel *)model_;
// Switch from screen coordinates to world coordinates
matrix_.imap(cx, cy);
// Do we have a node on the clicked point ?
p = model_->inside(cx, cy);
if (p == NULL) {
defTag_->remove();
return (TCL_OK);
}
if (p->classid() == ClassNodeID) {
// Yes, we have a node to which we can add the agent
src = (Node *) p;
// goto EditorNetModel::addAgent(...) in enetmodel.cc
emodel_->addAgent(src, agent, cx, cy);
draw();
} else {
return (TCL_OK);
}
return(TCL_OK);
}
//----------------------------------------------------------------------
// int EditView::showAgentLink(float cx, float cy)
//----------------------------------------------------------------------
int EditView::showAgentLink(float cx, float cy) {
Animation * animation;
Agent * agent;
// Change from screen coordinates to worl coordinates
matrix_.imap(cx, cy);
// Get the clicked on animation object.
animation = model_->inside(cx, cy);
if (animation != NULL && animation->classid() == ClassAgentID) {
agent = (Agent *) animation;
agent->showLink();
draw();
}
return(TCL_OK);
}
//----------------------------------------------------------------------
// int
// EditView::cmdaddNode(float cx, float cy)
// Note: all cx_ and cy_ below are in *window* coordinates
//----------------------------------------------------------------------
int EditView::cmdaddNode(float cx, float cy) {
Animation * animation_object;
EditorNetModel* emodel_ = (EditorNetModel *)model_;
// Convert screen coordinates to world coordinates
matrix_.imap(cx, cy);
// Check to see if an object already exists on the click point
animation_object = model_->inside(cx,cy);
if (animation_object == NULL) {
defTag_->remove();
emodel_->addNode(cx, cy);
draw();
}
return(TCL_OK);
}
//----------------------------------------------------------------------
// int
// EditView::cmdDeleteObj(float cx, float cy)
//----------------------------------------------------------------------
int
EditView::cmdDeleteObj(float cx, float cy) {
Animation * p; // I don't know why p was chosen for the varible name
// Just to confuse other programmers, I guess
// First of all, clear the old point
cx_ = cx;
cy_ = cy;
// Do we have an animation object on the clicked point?
matrix_.imap(cx, cy);
p = model_->inside(cx, cy);
if (p == NULL) {
defTag_->remove();
return (TCL_OK);
}
// If object is already selected unselect it
if (p->isTagged()) {
if (p->numTag() > 1) {
fprintf(stderr, "Error: More than one tag for an object %d!\n",
p->id());
p = NULL;
} else {
p = p->getLastTag();
}
}
// Only nodes, links, agents, traffic sources and
// loss models can be deleted
if ((p->classid() != ClassNodeID) &&
(p->classid() != ClassEdgeID) &&
(p->classid() != ClassAgentID) &&
(p->classid() != ClassTrafficSourceID) &&
(p->classid() != ClassLossModelID)) {
p = NULL;
}
if (p == NULL) {
defTag_->remove();
} else {
if (p->classid() == ClassNodeID) {
Node * n = (Node *) p;
EditorNetModel * emodel_ = (EditorNetModel *) model_;
emodel_->removeNode(n);
draw();
}
if (p->classid() == ClassEdgeID) {
Edge * e = (Edge *) p;
EditorNetModel * emodel_ = (EditorNetModel *) model_;
emodel_->removeLink(e);
draw();
}
if (p->classid() == ClassAgentID) {
Agent * a = (Agent *) p;
EditorNetModel* emodel_ = (EditorNetModel *) model_;
emodel_->removeAgent(a);
draw();
}
if (p->classid() == ClassTrafficSourceID) {
TrafficSource * ts = (TrafficSource *) p;
EditorNetModel* emodel_ = (EditorNetModel *) model_;
emodel_->removeTrafficSource(ts);
draw();
}
if (p->classid() == ClassLossModelID) {
LossModel * lossmodel = (LossModel *) p;
EditorNetModel* emodel_ = (EditorNetModel *) model_;
emodel_->removeLossModel(lossmodel);
draw();
}
}
return (TCL_OK);
}
//----------------------------------------------------------------------
// int
// EditView::cmdaddTrafficSource(float cx, float cy, char * type)
//----------------------------------------------------------------------
int
EditView::cmdaddTrafficSource(float cx, float cy, const char * type) {
Animation * object;
Agent * agent;
EditorNetModel* emodel_ = (EditorNetModel *)model_;
// Switch from screen coordinates to world coordinates
matrix_.imap(cx, cy);
// Do we have an agent on the clicked point ?
object = model_->inside(cx, cy);
if (object == NULL) {
defTag_->remove();
return (TCL_OK);
}
if (object->classid() == ClassAgentID) {
// Yes, we have a node to which we can add the agent
agent = (Agent *) object;
// goto EditorNetModel::addTrafficSource(...) in enetmodel.cc
emodel_->addTrafficSource(agent, type, cx, cy);
draw();
} else {
return (TCL_OK);
}
return(TCL_OK);
}
//----------------------------------------------------------------------
// int
// EditView::cmdaddLossModel(float cx, float cy, char * type)
//----------------------------------------------------------------------
int
EditView::cmdaddLossModel(float cx, float cy, const char * type) {
Animation * object;
Node * source, * destination;
Edge * edge, * reverse_edge;
EditorNetModel* emodel_ = (EditorNetModel *) model_;
// Switch from screen coordinates to world coordinates
matrix_.imap(cx, cy);
// Do we have a link on the clicked point ?
object = model_->inside(cx, cy);
if (object == NULL) {
defTag_->remove();
return (TCL_OK);
}
if (object->classid() == ClassEdgeID ||
object->classid() == ClassQueueHandleID ) {
//
// Yes, we have a possible edge to which we can add the loss model
if (object->classid() == ClassQueueHandleID ) {
edge = ((QueueHandle *) object)->getEdge();
} else {
edge = (Edge *) object;
}
if (edge) {
// Check distance to source to determine if we should attach
// to the forward or reverse edge
source = edge->getSourceNode();
destination = edge->getDestinationNode();
if (source->distance(cx, cy) > destination->distance(cx,cy)) {
// if source is farther away than destination then place
// this loss model on the reverse edge
reverse_edge = emodel_->lookupEdge(destination->number(), source->number());
if (reverse_edge) { // Make sure there is a reverse edge
edge = reverse_edge;
}
}
// goto EditorNetModel::addTrafficSource(...) in enetmodel.cc
emodel_->addLossModel(edge, type, cx, cy);
draw();
}
}
return(TCL_OK);
}
// ---------------------------------------------------------------------
// int
// EditView::cmdSetPoint(float cx, float cy, int bAdd)
// - Note: all cx_ and cy_ below are in *window* coordinates
// ---------------------------------------------------------------------
int
EditView::cmdSetPoint(float cx, float cy, int add_object) {
Animation * animation_object;
// First of all, clean the old group
cx_ = cx;
cy_ = cy;
// Inverse Map cx, cy to world coordinates
matrix_.imap(cx, cy);
// Do we have anything on current point?
animation_object = model_->inside(cx, cy);
// If nothing at this point start selection rubberband
if (animation_object == NULL) {
defTag_->remove();
startRubberBand(cx_, cy_);
return (TCL_OK);
}
// Otherwise look to move object if it is a node or a Tag
// - A tag is a grouping marker, if an object is tagged then
// that tag group can be moved together
if (animation_object->isTagged()) {
if (animation_object->numTag() > 1) {
fprintf(stderr, "Error: More than one tag for object %d!\n",
animation_object->id());
animation_object = NULL;
} else {
animation_object = animation_object->getLastTag();
}
}
// Only nodes and tags can be moved
if ((animation_object->classid() == ClassNodeID) ||
(animation_object->classid() == ClassTagID)) {
// If a single non-tag object is selected, or explicitly
// instructed, remove the previous selection. Otherwise,
// the object under the current point will be added to the
// entire tagged selection
if (!add_object && (animation_object != defTag_)) {
defTag_->remove();
}
// Just tags the object as being selected.
// Draws a box around the tagged object
startSetObject(animation_object, cx_, cy_);
} else {
defTag_->remove();
startRubberBand(cx_, cy_);
}
return (TCL_OK);
}
//----------------------------------------------------------------------
// int
// EditView::cmdMoveTo(float cx, float cy)
// - Moves object to end location
// - Ends the rubber band selection
//----------------------------------------------------------------------
int EditView::cmdMoveTo(float cx, float cy) {
// cx and cy should be in screen (canvas) coordinates
cx_ = cx;
cy_ = cy;
switch (editing_stage_) {
case START_RUBBERBAND:
case MOVE_RUBBERBAND:
oldx_ = rb_.xmax;
oldy_ = rb_.ymax;
rb_.xmax = cx_;
rb_.ymax = cy_;
editing_stage_ = MOVE_RUBBERBAND;
clip_ = rb_;
clip_.adjust();
if (clip_.xmin > oldx_)
clip_.xmin = oldx_;
if (clip_.xmax < oldx_)
clip_.xmax = oldx_;
if (clip_.ymin > oldy_)
clip_.ymin = oldy_;
if (clip_.ymax < oldy_)
clip_.ymax = oldy_;
break;
case START_OBJECT:
case MOVE_OBJECT: {
oldx_ = rb_.xmax;
oldy_ = rb_.ymax;
rb_.xmax = cx_;
rb_.ymax = cy_;
editing_stage_ = MOVE_OBJECT;
clip_.clear();
defTag_->merge(clip_);
matrix_.map(clip_.xmin, clip_.ymin);
matrix_.map(clip_.xmax, clip_.ymax);
clip_.adjust();
// Actual move and final bbox computation is done in render
break;
case START_LINK:
case MOVE_LINK:
// I believe this is never reached and should be removed
// maybe it is changed in the future
oldx_ = rb_.xmax;
oldy_ = rb_.ymax;
rb_.xmax = cx_;
rb_.ymax = cy_;
editing_stage_ = MOVE_LINK;
clip_ = rb_;
clip_.adjust();
if (clip_.xmin > oldx_)
clip_.xmin = oldx_;
if (clip_.xmax < oldx_)
clip_.xmax = oldx_;
if (clip_.ymin > oldy_)
clip_.ymin = oldy_;
if (clip_.ymax < oldy_)
clip_.ymax = oldy_;
break;
}
default:
// to avoid segmentation fault from click-n-dragging
return (TCL_OK);
}
draw();
return (TCL_OK);
}
int EditView::cmdReleasePoint(float cx, float cy) {
static char buffer[512];
int chars_written;
cx_ = cx;
cy_ = cy;
Tcl & tcl = Tcl::instance();
switch (editing_stage_) {
case START_RUBBERBAND:
case MOVE_RUBBERBAND: {
oldx_ = rb_.xmax; oldy_ = rb_.ymax;
rb_.xmax = cx_, rb_.ymax = cy_;
// Need to add the region to defTag_
clip_ = rb_;
clip_.adjust();
BBox bb = clip_;
matrix_.imap(bb.xmin, bb.ymin);
matrix_.imap(bb.xmax, bb.ymax);
bb.adjust();
model_->tagArea(bb, defTag_, 1);
// We can do a total redraw
editing_stage_ = NONE;
draw();
// Get time movement info for node markers on time slider
// defTag_->addNodeMovementDestination(this, cx - oldx_, cy - oldy_, model_->now());
// chars_written = defTag_->getNodeMovementTimes(buffer, 512);
// if (chars_written == -1) {
tcl.resultf("NONE");
// } else {
// tcl.resultf("%s", buffer);
// }
break;
}
case START_OBJECT:
case MOVE_OBJECT: {
oldx_ = rb_.xmax;
oldy_ = rb_.ymax;
rb_.xmax = cx_;
rb_.ymax = cy_;
clip_.clear();
defTag_->merge(clip_);
matrix_.map(clip_.xmin, clip_.ymin);
matrix_.map(clip_.xmax, clip_.ymax);
clip_.adjust();
// Later in render() we'll compute the real bbox
editing_stage_ = END_OBJECT;
draw();
editing_stage_ = NONE;
model_->update(model_->now());
// defTag_->move(this, rb_.xmax - oldx_, rb_.ymax - oldy_);
// Get time movement info for node markers on time slider
defTag_->addNodeMovementDestination(this, cx - oldx_, cy - oldy_, model_->now());
chars_written = defTag_->getNodeMovementTimes(buffer, 512);
if (chars_written == -1) {
tcl.resultf("NONE");
} else {
tcl.resultf("%s", buffer);
}
break;
}
case START_LINK:
case MOVE_LINK: {
editing_stage_ = START_LINK;
draw();
model_->update(model_->now());
cmdaddLink(cx_, cy_);
tcl.resultf("NONE");
break;
}
default:
// This cannot happen!
editing_stage_ = NONE;
draw();
tcl.resultf("NONE");
}
return (TCL_OK);
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
inline void
EditView::startRubberBand(float cx, float cy) {
// Nothing's here. Set rubber band.
editing_stage_ = START_RUBBERBAND;
rb_.xmin = rb_.xmax = cx;
rb_.ymin = rb_.ymax = cy;
clip_ = rb_;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
inline void
EditView::startSetObject(Animation * animation_object, float cx, float cy) {
// Find an object, add it to group
editing_stage_ = START_OBJECT;
// Add it into defTag_
if (animation_object != defTag_) {
model_->tagObject(defTag_, animation_object);
}
rb_.xmin = rb_.xmax = cx;
rb_.ymin = rb_.ymax = cy;
clip_.clear();
defTag_->merge(clip_);
// for the bounding box (bbox)
oldx_ = rb_.xmax;
oldy_ = rb_.ymax;
rb_.xmax = cx_;
rb_.ymax = cy_;
clip_.clear();
defTag_->merge(clip_);
matrix_.map(clip_.xmin, clip_.ymin);
matrix_.map(clip_.xmax, clip_.ymax);
clip_.adjust();
// Later in render() we'll compute the real bbox
// We have selected the object and now we are at the end of
// the object selection process
editing_stage_ = END_OBJECT;
draw();
editing_stage_ = NONE;
model_->update(model_->now());
editing_stage_ = START_OBJECT;
}
//----------------------------------------------------------------------
// void EditView::draw()
//----------------------------------------------------------------------
void EditView::draw() {
if (editing_stage_ == NONE) {
View::draw();
} else {
// Ignore the cleaning part
render();
// XXX Don't understand why clip's height and width need to
// increase 3 to draw tagged objects correctly.
XCopyArea(Tk_Display(tk_), offscreen_, Tk_WindowId(tk_),
background_,(int)clip_.xmin, (int)clip_.ymin,
(int)clip_.width()+3, (int)clip_.height()+3,
(int)clip_.xmin, (int)clip_.ymin);
}
}
//----------------------------------------------------------------------
// void EditView::draw(double current_time)
//----------------------------------------------------------------------
void EditView::draw(double current_time) {
model_->update(current_time);
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void EditView::xline(float x0, float y0, float x1, float y1, GC gc) {
XDrawLine(Tk_Display(tk_), offscreen_, gc, (int) x0, (int) y0,
(int) x1, (int) y1);
}
// Without transform.
void EditView::xrect(float x0, float y0, float x1, float y1, GC gc)
{
int x = (int) floor(x0);
int y = (int) floor(y0);
int w = (int)(x1 - x0);
if (w < 0) {
x = (int) ceil(x1);
w = -w;
}
int h = (int)(y1 - y0);
if (h < 0) {
h = -h;
y = (int)ceil(y1);
}
XDrawRectangle(Tk_Display(tk_), offscreen_, gc, x, y, w, h);
}
void EditView::line(float x0, float y0, float x1, float y1, int color)
{
if (editing_stage_ != NONE)
View::line(x0, y0, x1, y1, Paint::instance()->Xor());
else
View::line(x0, y0, x1, y1, color);
}
void EditView::rect(float x0, float y0, float x1, float y1, int color)
{
if (editing_stage_ != NONE)
View::rect(x0, y0, x1, y1, Paint::instance()->Xor());
else
View::rect(x0, y0, x1, y1, color);
}
void EditView::polygon(const float* x, const float* y, int n, int color)
{
if (editing_stage_ != NONE)
View::polygon(x, y, n, Paint::instance()->Xor());
else
View::polygon(x, y, n, color);
}
void EditView::fill(const float* x, const float* y, int n, int color)
{
if (editing_stage_ != NONE)
View::fill(x, y, n, Paint::instance()->Xor());
else
View::fill(x, y, n, color);
}
void EditView::circle(float x, float y, float r, int color)
{
if (editing_stage_ != NONE)
View::circle(x, y, r, Paint::instance()->Xor());
else
View::circle(x, y, r, color);
}
// Do not display any string, because no xor font gc
void EditView::string(float fx, float fy, float dim, const char* s, int anchor)
{
if (editing_stage_ == NONE)
View::string(fx, fy, dim, s, anchor);
}
//----------------------------------------------------------------------
// void
// EditView::BoundingBox(BBox &bb)
// - This copies the area in which an animation drawn may be drawn
// into (clipping area) the destination bb.
//----------------------------------------------------------------------
void
EditView::BoundingBox(BBox &bb) {
double temp;
// Calculate the world coordinates for the view's canvas
matrix_.imap(0.0, 0.0, bb.xmin, bb.ymin);
matrix_.imap(width_, height_, bb.xmax, bb.ymax);
// Check to make sure xmin, ymin is the lower left corner
// and xmax, ymax is the upper right
if (bb.xmin > bb.xmax) {
temp = bb.xmax;
bb.xmax = bb.xmin;
bb.xmin = temp;
}
if (bb.ymin > bb.ymax) {
temp = bb.ymax;
bb.ymax = bb.ymin;
bb.ymin = temp;
}
}
void
EditView::getWorldBox(BBox &bb) {
model_->BoundingBox(bb);
}
//----------------------------------------------------------------------
// void
// EditView::render()
// - not sure why this is called render but it seems to take care of
// rubberband selections and moving a selection on the screen
// - I believe the real "rendering" is done in model_->render()
// which is of type NetModel. -- mehringe@isi.edu
//
//----------------------------------------------------------------------
void
EditView::render() {
// Here we can compute the clipping box for render
Paint *paint = Paint::instance();
GC gc = paint->paint_to_gc(paint->Xor());
switch (editing_stage_) {
case START_RUBBERBAND:
// draw rubber band
xrect(rb_.xmin, rb_.ymin, rb_.xmax, rb_.ymax, gc);
break;
case MOVE_RUBBERBAND:
// erase previous rubberband
xrect(rb_.xmin, rb_.ymin, oldx_, oldy_, gc);
// draw new rubberband
xrect(rb_.xmin, rb_.ymin, rb_.xmax, rb_.ymax, gc);
break;
case END_RUBBERBAND:
// erase previous rubber band
xrect(rb_.xmin, rb_.ymin, oldx_, oldy_, gc);
// XXX Should draw the tag?
model_->render(this);
editing_stage_ = NONE;
break;
case START_OBJECT:
xrect(rb_.xmin, rb_.ymin, rb_.xmax, rb_.ymax, gc);
// xor-draw all relevant objects
defTag_->draw(this, model_->now());
break;
case MOVE_OBJECT:
// erase old positions first.
if ((oldx_ == rb_.xmax) && (oldy_ == rb_.ymax))
return;
defTag_->draw(this, model_->now());
// move these objects
defTag_->move(this, rb_.xmax - oldx_, rb_.ymax - oldy_);
BBox bb;
bb.clear();
defTag_->merge(bb);
matrix_.imap(bb.xmin, bb.ymin);
matrix_.imap(bb.xmax, bb.ymax);
bb.adjust();
clip_.merge(bb);
defTag_->draw(this, model_->now());
break;
case END_OBJECT:
// Erase old positions
defTag_->draw(this, model_->now());
// At least we should redo scale estimation and
// place everything
defTag_->move(this, rb_.xmax - oldx_, rb_.ymax - oldy_);
model_->recalc();
model_->render(this);
editing_stage_ = NONE;
break;
case START_LINK:
line(link_start_x_, link_start_y_, link_end_x_, link_end_y_, 3);
defTag_->draw(this, model_->now());
break;
case MOVE_LINK:
// erase previous link
xline(rb_.xmin, rb_.ymin, oldx_, oldy_, gc);
// draw new rubberband
xline(rb_.xmin, rb_.ymin, rb_.xmax, rb_.ymax, gc);
break;
case END_LINK:
// erase previous link
xline(rb_.xmin, rb_.ymin, oldx_, oldy_, gc);
// XXX Should draw the tag?
model_->render(this);
editing_stage_ = NONE;
break;
default:
// redraw model
model_->render(this);
break;
}
return;
}
|