Changeset 2067 for trunk/CrypPlugins/WorkspaceManager/View/VisualComponents/CryptoLineView/CryptoLineView.cs
 Timestamp:
 Nov 9, 2010, 2:21:21 AM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/CrypPlugins/WorkspaceManager/View/VisualComponents/CryptoLineView/CryptoLineView.cs
r2007 r2067 103 103 { 104 104 this.Model = connectionModel; 105 Color color = ColorHelper.Get Color(connectionModel.ConnectionType);105 Color color = ColorHelper.GetLineColor(connectionModel.ConnectionType); 106 106 Stroke = new SolidColorBrush(color); 107 107 StrokeThickness = 2; … … 341 341 // continue; 342 342 // Point pos = new Point((plug1.RenderTransform as TranslateTransform).X, (plug1.RenderTransform as TranslateTransform).Y); 343 344 343 // if (!isBetween(pos.Y, pos.Y + plug1.ActualHeight, left.Y)) 345 344 // continue; 346 347 345 // // case 1: one point is inside the plugin 348 346 // if (isBetween(pos.X, pos.X + plug1.ActualWidth, left.X)  … … 351 349 // return false; 352 350 // } 353 354 351 // // case 2: goes through 355 352 // if (pos.X > left.X && pos.X + plug1.ActualWidth < right.X) … … 359 356 // } 360 357 // } 361 362 358 // return true; 363 359 //} … … 383 379 queryRect = new System.Drawing.RectangleF((float)left.X, (float)left.Y, (float)(right.X  left.X), 1); 384 380 } 385 386 381 return !quadTree.QueryAny(queryRect); 387 382 } 388 383 389 private bool performOrthogonalPointConnection(Node n1, Point p2, Node n3, List<Node> nodeList, QuadTreeLib.QuadTree<FakeNode> quadTree) 390 { 391 if (isConnectionPossible(n1.Point, p2, quadTree) && isConnectionPossible(p2, n3.Point, quadTree)) 384 private bool performOrthogonalPointConnection(Node n1, Point p2, Node n3, List<Node> nodeList, QuadTreeLib.QuadTree<FakeNode> quadTreePlugins, QuadTreeLib.QuadTree<FakeNode> quadTreeLines) 385 { 386 //bool isHorizontal; 387 //Point help1, help2; 388 //foreach (FakeNode FKNode in getQueriesFromLine(n1.Point, p2, quadTreeLines, out isHorizontal)) 389 //{ 390 // if (isHorizontal) 391 // { 392 // if (FKNode.Source != this.source) 393 // continue; 394 395 // help1 = new Point(n1.Point.X, 2); 396 // help2 = new Point(p 397 // } 398 // else 399 // { 400 // if (FKNode.Source != this.source) 401 // continue; 402 // } 403 //} 404 405 //foreach (FakeNode FKNode in getQueriesFromLine(p2, n3.Point, quadTreeLines, out isHorizontal)) 406 //{ 407 // if (isHorizontal) 408 // { 409 410 // } 411 // else 412 // { 413 414 // } 415 //} 416 417 if (isConnectionPossible(n1.Point, p2, quadTreePlugins) && isConnectionPossible(p2, n3.Point, quadTreePlugins)) 392 418 { 393 419 Node n2 = new Node() { Point = p2 }; … … 402 428 return true; 403 429 } 430 404 431 return false; 405 432 } 433 434 private List<FakeNode> getQueriesFromLine(Point p1,Point p2,QuadTreeLib.QuadTree<FakeNode> quadTreeLines, out bool isHorizontal) 435 { 436 if (p1.X != p2.X && p1.Y != p2.Y) 437 throw new ArgumentException("only 90° allowed"); 438 439 System.Drawing.RectangleF queryRect; 440 441 if (p1.Y != p2.Y) 442 { 443 Point up = p2.Y < p1.Y ? p2 : p1; 444 Point down = p2.Y < p1.Y ? p1 : p2; 445 isHorizontal = false; 446 447 queryRect = new System.Drawing.RectangleF((float)up.X, (float)up.Y, 1, (float)(down.Y  up.Y)); 448 } 449 else 450 { 451 Point left = p2.X < p1.X ? p2 : p1; 452 Point right = p2.X < p1.X ? p1 : p2; 453 isHorizontal = true; 454 455 queryRect = new System.Drawing.RectangleF((float)left.X, (float)left.Y, (float)(right.X  left.X), 1); 456 } 457 458 return quadTreeLines.Query(queryRect); 459 } 460 461 //private bool isSimpleOrthogonalConnectionPossible(Point p1, Point p2, QuadTreeLib.QuadTree<FakeNode> quadTree) 462 //{ 463 // if (p1.X != p2.X && p1.Y != p2.Y) 464 // throw new ArgumentException("only 90° allowed"); 465 466 // List<FakeNode> list; 467 // System.Drawing.RectangleF queryRect; 468 // if (p1.Y != p2.Y) 469 // { 470 // Point up = p2.Y < p1.Y ? p2 : p1; 471 // Point down = p2.Y < p1.Y ? p1 : p2; 472 473 // queryRect = new System.Drawing.RectangleF((float)up.X, (float)up.Y, (float)5, (float)(down.Y  up.Y)); 474 // } 475 // else 476 // { 477 // Point left = p2.X < p1.X ? p2 : p1; 478 // Point right = p2.X < p1.X ? p1 : p2; 479 480 // queryRect = new System.Drawing.RectangleF((float)left.X, (float)left.Y, (float)(right.X  left.X), (float)5); 481 // } 482 483 // list = quadTree.Query(queryRect); 484 485 // return !quadTree.Query(queryRect); 486 //} 406 487 407 488 private void performOrthogonalPointConnection(Node p1, Node p2, QuadTreeLib.QuadTree<FakeNode> quadTree) … … 413 494 } 414 495 } 496 415 497 internal class FakeNode : QuadTreeLib.IHasRect 416 498 { 417 499 public System.Drawing.RectangleF Rectangle { get; set; } 418 } 500 public ConnectorView Source { get; set; } 501 public ConnectorView Target { get; set; } 502 } 503 419 504 private void makeOrthogonalPoints() 420 505 { … … 432 517 float actualWidth = (float)parent.ActualWidth, actualHeight = (float)parent.ActualWidth; 433 518 //Consider zoom factor 434 QuadTreeLib.QuadTree<FakeNode> quadTree = new QuadTreeLib.QuadTree<FakeNode>519 QuadTreeLib.QuadTree<FakeNode> quadTreePlugins = new QuadTreeLib.QuadTree<FakeNode> 435 520 (new System.Drawing.RectangleF(actualWidth, actualHeight, actualWidth * 5, actualHeight * 5)); 521 522 QuadTreeLib.QuadTree<FakeNode> quadTreeLines = new QuadTreeLib.QuadTree<FakeNode> 523 (new System.Drawing.RectangleF(actualWidth, actualHeight, actualWidth * 5, actualHeight * 5)); 524 525 436 526 437 527 //foreach (var element in parent.Children) … … 460 550 if (routPoint == 0) 461 551 { 462 quadTree .Insert(new FakeNode()552 quadTreePlugins.Insert(new FakeNode() 463 553 { 464 554 Rectangle = new System.Drawing.RectangleF((float)p1.GetPosition().X, … … 468 558 }); 469 559 } 560 } 561 562 if (routPoint != 0) 563 continue; 564 565 if (element is CryptoLineView) 566 { 567 CryptoLineView l1 = element as CryptoLineView; 568 foreach (FromTo fromto in l1.pointList) 569 { 570 Point p1 = fromto.From, p2 = fromto.To; 571 if (p1.Y != p2.Y) 572 { 573 Point up = p2.Y < p1.Y ? p2 : p1; 574 Point down = p2.Y < p1.Y ? p1 : p2; 575 576 quadTreeLines.Insert(new FakeNode() 577 { 578 Source = l1.source, 579 Target = l1.target, 580 Rectangle = new System.Drawing.RectangleF((float)up.X, (float)up.Y, 1, (float)(down.Y  up.Y)) 581 }); 582 } 583 else 584 { 585 Point left = p2.X < p1.X ? p2 : p1; 586 Point right = p2.X < p1.X ? p1 : p2; 587 588 quadTreeLines.Insert(new FakeNode() 589 { 590 Source = l1.source, 591 Target = l1.target, 592 Rectangle = new System.Drawing.RectangleF((float)left.X, (float)left.Y, (float)(right.X  left.X), 1) 593 }); 594 } 595 } 596 470 597 } 471 598 } … … 508 635 p1.Point.Y == p2.Point.Y) 509 636 { 510 performOrthogonalPointConnection(p1, p2, quadTree );637 performOrthogonalPointConnection(p1, p2, quadTreePlugins); 511 638 } 512 639 else … … 514 641 Point help = new Point(p1.Point.X, p2.Point.Y); 515 642 516 if (!performOrthogonalPointConnection(p1, help, p2, nodeList, quadTree ))643 if (!performOrthogonalPointConnection(p1, help, p2, nodeList, quadTreePlugins, quadTreeLines)) 517 644 { 518 645 help = new Point(p2.Point.X, p1.Point.Y); 519 if (!performOrthogonalPointConnection(p1, help, p2, nodeList, quadTree ))646 if (!performOrthogonalPointConnection(p1, help, p2, nodeList, quadTreePlugins, quadTreeLines)) 520 647 { 521 648 // optional todo: double edge helping routes
Note: See TracChangeset
for help on using the changeset viewer.