Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2861


Ignore:
Timestamp:
02/24/10 17:58:03 (15 years ago)
Author:
mkommend
Message:

intermediate version of graph visualization (ticket #867)

Location:
trunk/sources
Files:
20 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Core/Scene graph/Model.cs

    r2768 r2861  
    490490            get
    491491            {
    492                 throw new System.NotImplementedException();
     492              return CurrentPage.Connections;
    493493            }
    494494
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Diagram elements/Connectors/Connector.cs

    r2768 r2861  
    33using System.Drawing.Drawing2D;
    44
    5 namespace Netron.Diagramming.Core
    6 {
    7     // ----------------------------------------------------------------------
    8   /// <summary>
    9   /// The default connector.  Represents an endpoint of a connection or a
    10     /// location of a bundle to which a connection can be attached.
    11     /// </summary>
    12     // ----------------------------------------------------------------------
    13   public partial class Connector : ConnectorBase
    14     {
    15         #region Fields
    16 
    17         // ------------------------------------------------------------------
    18         /// <summary>
    19         /// Implementation of IVersion - the current version of
    20         /// Connector.
    21         /// </summary>
    22         // ------------------------------------------------------------------
    23         protected const double connectorVersion = 1.0;
    24 
    25         // ------------------------------------------------------------------
    26         /// <summary>
    27         /// Specifies how the connector is drawn on the canvas when 'IsVisible'
    28         /// is true.  The default style is 'Simple', which is a transparent
    29         /// background with a blue 'x' (similar to Visio).
    30         /// </summary>
    31         // ------------------------------------------------------------------
    32         protected ConnectorStyle myStyle = ConnectorStyle.Simple;
    33 
    34         #endregion
    35 
    36         #region Properties
    37 
    38         // ------------------------------------------------------------------
    39         /// <summary>
    40         /// Gets the current version.
    41         /// </summary>
    42         // ------------------------------------------------------------------
    43         public override double Version
    44         {
    45             get
    46             {
    47                 return connectorVersion;
    48             }
     5namespace Netron.Diagramming.Core {
     6  // ----------------------------------------------------------------------
     7  /// <summary>
     8  /// The default connector.  Represents an endpoint of a connection or a
     9  /// location of a bundle to which a connection can be attached.
     10  /// </summary>
     11  // ----------------------------------------------------------------------
     12  public partial class Connector : ConnectorBase {
     13    #region Fields
     14
     15    // ------------------------------------------------------------------
     16    /// <summary>
     17    /// Implementation of IVersion - the current version of
     18    /// Connector.
     19    /// </summary>
     20    // ------------------------------------------------------------------
     21    protected const double connectorVersion = 1.0;
     22
     23    // ------------------------------------------------------------------
     24    /// <summary>
     25    /// Specifies how the connector is drawn on the canvas when 'IsVisible'
     26    /// is true.  The default style is 'Simple', which is a transparent
     27    /// background with a blue 'x' (similar to Visio).
     28    /// </summary>
     29    // ------------------------------------------------------------------
     30    protected ConnectorStyle myStyle = ConnectorStyle.Simple;
     31
     32    #endregion
     33
     34    #region Properties
     35
     36    // ------------------------------------------------------------------
     37    /// <summary>
     38    /// Gets the current version.
     39    /// </summary>
     40    // ------------------------------------------------------------------
     41    public override double Version {
     42      get {
     43        return connectorVersion;
     44      }
     45    }
     46
     47    // ------------------------------------------------------------------
     48    /// <summary>
     49    /// Gets or sets how the connector is drawn on the canvas when
     50    /// 'IsVisible' is true.
     51    /// </summary>
     52    // ------------------------------------------------------------------
     53    public ConnectorStyle ConnectorStyle {
     54      get {
     55        return this.myStyle;
     56      }
     57      set {
     58        this.myStyle = value;
     59      }
     60    }
     61
     62    // ------------------------------------------------------------------
     63    /// <summary>
     64    /// Gets the friendly name of the entity to be displayed in the UI
     65    /// </summary>
     66    /// <value></value>
     67    // ------------------------------------------------------------------
     68    public override string EntityName {
     69      get { return "Connector"; }
     70    }
     71
     72    // ------------------------------------------------------------------
     73    /// <summary>
     74    /// The bounds of the paintable entity.
     75    /// </summary>
     76    /// <value></value>
     77    // ------------------------------------------------------------------
     78    public override Rectangle Rectangle {
     79      get {
     80        return new Rectangle(Point.X - 2, Point.Y - 2, 4, 4);
     81      }
     82      //set {               Point = value.Location;               
     83      //TODO: think about what to do when setting the size            }
     84    }
     85
     86    #endregion
     87
     88    #region Constructor
     89
     90    // ------------------------------------------------------------------
     91    /// <summary>
     92    /// Initializes a new instance of the <see cref="T:Connector"/> class.
     93    /// </summary>
     94    /// <param name="site">The site.</param>
     95    // ------------------------------------------------------------------
     96    public Connector(IModel site)
     97      : base(site) {
     98    }
     99
     100    // ------------------------------------------------------------------
     101    /// <summary>
     102    /// Initializes a new instance of the <see cref="T:Connector"/> class.
     103    /// </summary>
     104    /// <param name="p">The p.</param>
     105    /// <param name="site">The site.</param>
     106    // ------------------------------------------------------------------
     107    public Connector(Point p, IModel site)
     108      : base(p, site) {
     109    }
     110
     111    // ------------------------------------------------------------------
     112    /// <summary>
     113    /// Initializes a new instance of the <see cref="T:Connector"/> class.
     114    /// </summary>
     115    /// <param name="p">The p.</param>
     116    // ------------------------------------------------------------------
     117    public Connector(Point p)
     118      : base(p) {
     119    }
     120
     121    #endregion
     122
     123    #region Methods
     124
     125    // ------------------------------------------------------------------
     126    /// <summary>
     127    /// Paints the connector on the canvas.
     128    /// </summary>
     129    /// <param name="g"></param>
     130    // ------------------------------------------------------------------
     131    public override void Paint(Graphics g) {
     132      if (g == null) {
     133        throw new ArgumentNullException(
     134            "The Graphics object is 'null'");
     135      }
     136
     137      if (Hovered || IsSelected) {
     138        Rectangle area = Rectangle;
     139        area.Inflate(3, 3);
     140        g.DrawRectangle(
     141            ArtPalette.ConnectionHighlightPen,
     142            area);
     143        //g.FillRectangle(
     144        //    Brushes.Green,
     145        //    Point.X - 4,
     146        //    Point.Y - 4,
     147        //    8,
     148        //    8);
     149      } else {
     150        if (Visible) {
     151          switch (this.myStyle) {
     152            case ConnectorStyle.Simple:
     153              DrawSimpleConnector(g);
     154              break;
     155
     156            case ConnectorStyle.Round:
     157              break;
     158
     159            case ConnectorStyle.Square:
     160              DrawSquareConnector(g);
     161              break;
     162          }
     163
     164          if (this.mShowName) {
     165            DrawName(g);
     166          }
    49167        }
    50 
    51         // ------------------------------------------------------------------
    52         /// <summary>
    53         /// Gets or sets how the connector is drawn on the canvas when
    54         /// 'IsVisible' is true.
    55         /// </summary>
    56         // ------------------------------------------------------------------
    57         public ConnectorStyle ConnectorStyle
    58         {
    59             get
    60             {
    61                 return this.myStyle;
    62             }
    63             set
    64             {
    65                 this.myStyle = value;
    66             }
     168      }
     169    }
     170
     171    // ------------------------------------------------------------------
     172    /// <summary>
     173    /// Draws the name of this connector.
     174    /// </summary>
     175    /// <param name="g">Graphics</param>
     176    // ------------------------------------------------------------------
     177    void DrawName(Graphics g) {
     178      Size size = Size.Round(
     179          g.MeasureString(mName, mFont));
     180
     181      int xOffset = (size.Width - Rectangle.Width) / 2;
     182      int yOffset = (size.Height - Rectangle.Height) / 2;
     183
     184      System.Drawing.Point location = Rectangle.Location;
     185
     186      switch (this.mNameLocation) {
     187        case ConnectorNameLocation.Top:
     188          location = new Point(
     189              Rectangle.X - xOffset,
     190              Rectangle.Y - size.Height);
     191          break;
     192
     193        case ConnectorNameLocation.Bottom:
     194          location = new Point(
     195              Rectangle.X - xOffset,
     196              Rectangle.Bottom + size.Height);
     197          break;
     198
     199        case ConnectorNameLocation.Left:
     200          location = new Point(
     201              Rectangle.X - size.Width,
     202              Rectangle.Y - yOffset);
     203          break;
     204
     205        case ConnectorNameLocation.Right:
     206          location = new Point(
     207              Rectangle.Right,
     208              Rectangle.Y - yOffset);
     209          break;
     210      }
     211
     212      Rectangle textArea = new Rectangle(location, size);
     213      StringFormat format = new StringFormat();
     214      format.FormatFlags = StringFormatFlags.FitBlackBox;
     215      g.DrawString(
     216          mName,
     217          mFont,
     218          new SolidBrush(mForeColor),
     219          location);
     220    }
     221
     222    // ------------------------------------------------------------------
     223    /// <summary>
     224    /// Draws a blue 'x' using 'Dot' as the line style, with a transparent
     225    /// color.
     226    /// </summary>
     227    /// <param name="g">Graphics</param>
     228    // ------------------------------------------------------------------
     229    protected virtual void DrawSimpleConnector(Graphics g) {
     230      Pen pen = ArtPalette.GetSimpleConnectorPenStyle().DrawingPen();
     231      Brush brush =
     232          ArtPalette.GetSimpleConnectorPaintStyle().GetBrush(
     233          this.Rectangle);
     234
     235      GraphicsPath path = new GraphicsPath();
     236      // Diagonal line from top left to bottom right.
     237      g.DrawLine(pen, this.TopLeftCorner, this.BottomRightCorner);
     238
     239
     240      // Diagonal line from top right to bottom lrft.
     241      g.DrawLine(pen, this.TopRightCorner, this.BottomLeftCorner);
     242    }
     243
     244    protected virtual void DrawSquareConnector(Graphics g) {
     245      Pen pen = ArtPalette.GetSimpleConnectorPenStyle().DrawingPen();
     246      Brush brush = ArtPalette.GetSimpleConnectorPaintStyle().GetBrush(this.Rectangle);
     247      g.DrawRectangle(pen, this.Rectangle);
     248    }
     249
     250
     251    // ------------------------------------------------------------------
     252    /// <summary>
     253    /// Tests if the mouse hits this connector.
     254    /// </summary>
     255    /// <param name="p">Point</param>
     256    /// <returns>bool</returns>
     257    // ------------------------------------------------------------------
     258    public override bool Hit(Point p) {
     259      Point a = p;
     260      Point b = Point;
     261      b.Offset(-7, -7);
     262      //a.Offset(-1,-1);
     263      Rectangle r = new Rectangle(a, new Size(0, 0));
     264      Rectangle d = new Rectangle(b, new Size(15, 15));
     265      return d.Contains(r);
     266    }
     267
     268    // ------------------------------------------------------------------
     269    /// <summary>
     270    /// Invalidates the connector
     271    /// </summary>
     272    // ------------------------------------------------------------------
     273    public override void Invalidate() {
     274      Point p = Point;
     275      p.Offset(-5, -5);
     276      if (Model != null)
     277        Model.RaiseOnInvalidateRectangle(
     278                  new Rectangle(p, new Size(10, 10)));
     279    }
     280
     281    // ------------------------------------------------------------------
     282    /// <summary>
     283    /// Moves the connector with the given shift-vector.
     284    /// </summary>
     285    /// <param name="p">Point</param>
     286    // ------------------------------------------------------------------
     287    public override void MoveBy(Point p) {
     288      Point pt = new Point(this.Point.X + p.X, this.Point.Y + p.Y);
     289      IConnection con = null;
     290      Point p1 = Point.Empty, p2 = Point.Empty;
     291
     292      Rectangle rec = new Rectangle(
     293          Point.X - 10,
     294          Point.Y - 10,
     295          20,
     296          20);
     297
     298      this.Point = pt;
     299
     300      #region Case of connection
     301      if (typeof(IConnection).IsInstanceOfType(this.Parent)) {
     302        (Parent as IConnection).Invalidate();
     303      }
     304      #endregion
     305
     306      #region Case of attached connectors
     307      for (int k = 0; k < AttachedConnectors.Count; k++) {
     308        if (typeof(IConnection).IsInstanceOfType(AttachedConnectors[k].Parent)) {
     309          //keep a reference to the two points so we can invalidate the region afterwards
     310          con = AttachedConnectors[k].Parent as IConnection;
     311          p1 = con.From.Point;
     312          p2 = con.To.Point;
    67313        }
    68 
    69         // ------------------------------------------------------------------
    70         /// <summary>
    71         /// Gets the friendly name of the entity to be displayed in the UI
    72         /// </summary>
    73         /// <value></value>
    74         // ------------------------------------------------------------------
    75         public override string EntityName
    76         {
    77             get { return "Connector"; }
     314        AttachedConnectors[k].MoveBy(p);
     315        if (con != null) {
     316          //invalidate the 'before the move'-region                     
     317          Rectangle f = new Rectangle(p1, new Size(10, 10));
     318          Rectangle t = new Rectangle(p2, new Size(10, 10));
     319          Model.RaiseOnInvalidateRectangle(Rectangle.Union(f, t));
     320          //finally, invalidate the region where the connection is now
     321          (AttachedConnectors[k].Parent as IConnection).Invalidate();
    78322        }
    79 
    80         // ------------------------------------------------------------------
    81         /// <summary>
    82         /// The bounds of the paintable entity.
    83         /// </summary>
    84         /// <value></value>
    85         // ------------------------------------------------------------------
    86         public override Rectangle Rectangle
    87         {
    88             get
    89             {
    90                 return new Rectangle(Point.X - 2, Point.Y - 2, 4, 4);
    91             }
    92             //set {               Point = value.Location;               
    93             //TODO: think about what to do when setting the size            }
    94         }
    95 
    96         #endregion
    97 
    98         #region Constructor
    99 
    100         // ------------------------------------------------------------------
    101         /// <summary>
    102         /// Initializes a new instance of the <see cref="T:Connector"/> class.
    103         /// </summary>
    104         /// <param name="site">The site.</param>
    105         // ------------------------------------------------------------------
    106         public Connector(IModel site):base(site)
    107         {
    108         }
    109 
    110         // ------------------------------------------------------------------
    111         /// <summary>
    112         /// Initializes a new instance of the <see cref="T:Connector"/> class.
    113         /// </summary>
    114         /// <param name="p">The p.</param>
    115         /// <param name="site">The site.</param>
    116         // ------------------------------------------------------------------
    117     public Connector(Point p, IModel site):base(p, site)
    118         {
    119         }
    120 
    121         // ------------------------------------------------------------------
    122         /// <summary>
    123         /// Initializes a new instance of the <see cref="T:Connector"/> class.
    124         /// </summary>
    125         /// <param name="p">The p.</param>
    126         // ------------------------------------------------------------------
    127         public Connector(Point p) : base(p)
    128         {
    129         }
    130 
    131     #endregion
    132 
    133     #region Methods
    134 
    135         // ------------------------------------------------------------------
    136     /// <summary>
    137     /// Paints the connector on the canvas.
    138     /// </summary>
    139         /// <param name="g"></param>
    140         // ------------------------------------------------------------------
    141     public override void Paint(Graphics g)
    142     {
    143             if (g == null)
    144             {
    145                 throw new ArgumentNullException(
    146                     "The Graphics object is 'null'");
    147             }
    148 
    149             if (Hovered || IsSelected)
    150             {
    151                 Rectangle area = Rectangle;
    152                 area.Inflate(3, 3);
    153                 g.DrawRectangle(
    154                     ArtPalette.ConnectionHighlightPen,
    155                     area);
    156                 //g.FillRectangle(
    157                 //    Brushes.Green,
    158                 //    Point.X - 4,
    159                 //    Point.Y - 4,
    160                 //    8,
    161                 //    8);
    162             }
    163             else
    164             {
    165                 if (Visible)
    166                 {
    167                     switch (this.myStyle)
    168                     {
    169                         case ConnectorStyle.Simple :
    170                             DrawSimpleConnector(g);
    171                             break;
    172 
    173                         case ConnectorStyle.Round :
    174                             break;
    175 
    176                         case ConnectorStyle.Square :
    177                             break;
    178                     }
    179 
    180                     if (this.mShowName)
    181                     {
    182                         DrawName(g);
    183                     }
    184                 }
    185             }
    186     }
    187 
    188         // ------------------------------------------------------------------
    189         /// <summary>
    190         /// Draws the name of this connector.
    191         /// </summary>
    192         /// <param name="g">Graphics</param>
    193         // ------------------------------------------------------------------
    194         void DrawName(Graphics g)
    195         {
    196             Size size = Size.Round(
    197                 g.MeasureString(mName, mFont));
    198 
    199             int xOffset = (size.Width - Rectangle.Width) / 2;
    200             int yOffset = (size.Height - Rectangle.Height) / 2;
    201 
    202             System.Drawing.Point location = Rectangle.Location;
    203 
    204             switch (this.mNameLocation)
    205             {
    206                 case ConnectorNameLocation.Top:
    207                     location = new Point(
    208                         Rectangle.X - xOffset,
    209                         Rectangle.Y - size.Height);
    210                     break;
    211 
    212                 case ConnectorNameLocation.Bottom:
    213                     location = new Point(
    214                         Rectangle.X - xOffset,
    215                         Rectangle.Bottom + size.Height);
    216                     break;
    217 
    218                 case ConnectorNameLocation.Left:
    219                     location = new Point(
    220                         Rectangle.X - size.Width,
    221                         Rectangle.Y - yOffset);
    222                     break;
    223 
    224                 case ConnectorNameLocation.Right:
    225                     location = new Point(
    226                         Rectangle.Right,
    227                         Rectangle.Y - yOffset);
    228                     break;
    229             }
    230 
    231             Rectangle textArea = new Rectangle(location, size);
    232             StringFormat format = new StringFormat();
    233             format.FormatFlags = StringFormatFlags.FitBlackBox;
    234             g.DrawString(
    235                 mName,
    236                 mFont,
    237                 new SolidBrush(mForeColor),
    238                 location);
    239         }
    240 
    241         // ------------------------------------------------------------------
    242         /// <summary>
    243         /// Draws a blue 'x' using 'Dot' as the line style, with a transparent
    244         /// color.
    245         /// </summary>
    246         /// <param name="g">Graphics</param>
    247         // ------------------------------------------------------------------
    248         protected virtual void DrawSimpleConnector(Graphics g)
    249         {
    250             Pen pen = ArtPalette.GetSimpleConnectorPenStyle().DrawingPen();
    251             Brush brush =
    252                 ArtPalette.GetSimpleConnectorPaintStyle().GetBrush(
    253                 this.Rectangle);
    254 
    255             GraphicsPath path = new GraphicsPath();
    256             // Diagonal line from top left to bottom right.
    257             g.DrawLine(pen, this.TopLeftCorner, this.BottomRightCorner);
    258 
    259            
    260             // Diagonal line from top right to bottom lrft.
    261             g.DrawLine(pen, this.TopRightCorner, this.BottomLeftCorner);
    262         }
    263 
    264         // ------------------------------------------------------------------
    265     /// <summary>
    266     /// Tests if the mouse hits this connector.
    267     /// </summary>
    268         /// <param name="p">Point</param>
    269         /// <returns>bool</returns>
    270         // ------------------------------------------------------------------
    271     public override bool Hit(Point p)
    272     {
    273       Point a = p;
    274       Point b  = Point;
    275       b.Offset(-7,-7);
    276       //a.Offset(-1,-1);
    277       Rectangle r = new Rectangle(a,new Size(0,0));
    278       Rectangle d = new Rectangle(b, new Size(15,15));
    279       return d.Contains(r);
    280     }
    281 
    282         // ------------------------------------------------------------------
    283     /// <summary>
    284     /// Invalidates the connector
    285         /// </summary>
    286         // ------------------------------------------------------------------
    287     public override void Invalidate()
    288     {
    289       Point p = Point;
    290       p.Offset(-5,-5);
    291             if(Model!=null)
    292           Model.RaiseOnInvalidateRectangle(
    293                     new Rectangle(p,new Size(10,10)));
    294     }
    295 
    296         // ------------------------------------------------------------------
    297     /// <summary>
    298     /// Moves the connector with the given shift-vector.
    299     /// </summary>
    300         /// <param name="p">Point</param>
    301         // ------------------------------------------------------------------
    302     public override void MoveBy(Point p)
    303     {
    304             Point pt = new Point(this.Point.X + p.X, this.Point.Y + p.Y);           
    305             IConnection con = null;
    306             Point p1 = Point.Empty, p2 = Point.Empty;
    307 
    308             Rectangle rec = new Rectangle(
    309                 Point.X - 10,
    310                 Point.Y - 10,
    311                 20,
    312                 20);
    313 
    314             this.Point = pt;
    315            
    316             #region Case of connection
    317             if (typeof(IConnection).IsInstanceOfType(this.Parent))
    318             {
    319                 (Parent as IConnection).Invalidate();
    320             }
    321             #endregion
    322 
    323             #region Case of attached connectors
    324             for (int k = 0; k < AttachedConnectors.Count; k++)
    325             {
    326                 if (typeof(IConnection).IsInstanceOfType(AttachedConnectors[k].Parent))
    327                 {
    328                     //keep a reference to the two points so we can invalidate the region afterwards
    329                     con = AttachedConnectors[k].Parent as IConnection;
    330                     p1 = con.From.Point;
    331                     p2 = con.To.Point;
    332                 }
    333                 AttachedConnectors[k].MoveBy(p);
    334                 if (con != null)
    335                 {
    336                     //invalidate the 'before the move'-region                     
    337                     Rectangle f = new Rectangle(p1, new Size(10, 10));
    338                     Rectangle t = new Rectangle(p2, new Size(10, 10));
    339                     Model.RaiseOnInvalidateRectangle(Rectangle.Union(f, t));
    340                     //finally, invalidate the region where the connection is now
    341                     (AttachedConnectors[k].Parent as IConnection).Invalidate();
    342                 }
    343             }
    344             #endregion
    345             //invalidate this connector, since it's been moved
    346             Invalidate(rec);//before the move
    347             this.Invalidate();//after the move
    348            
    349     }
    350 
    351         // ------------------------------------------------------------------
    352         /// <summary>
    353         /// Moves the connector with the given shift-vector
    354         /// </summary>
    355         /// <param name="x">The x.</param>
    356         /// <param name="y">The y.</param>
    357         // ------------------------------------------------------------------
    358     public void MoveBy(int x, int y)
    359     {
    360       Point pt = new Point( x, y);
    361             MoveBy(pt);
    362     }
    363 
    364     #endregion
    365   }
     323      }
     324      #endregion
     325      //invalidate this connector, since it's been moved
     326      Invalidate(rec);//before the move
     327      this.Invalidate();//after the move
     328
     329    }
     330
     331    // ------------------------------------------------------------------
     332    /// <summary>
     333    /// Moves the connector with the given shift-vector
     334    /// </summary>
     335    /// <param name="x">The x.</param>
     336    /// <param name="y">The y.</param>
     337    // ------------------------------------------------------------------
     338    public void MoveBy(int x, int y) {
     339      Point pt = new Point(x, y);
     340      MoveBy(pt);
     341    }
     342
     343    #endregion
     344  }
    366345}
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Layout/BalloonTreeLayout.cs

    r2768 r2861  
    4949            : base("Balloon TreeLayout", controller)
    5050        {
    51 
    5251        }
    5352        #endregion
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Layout/FruchtermanReingoldLayout.cs

    r2768 r2861  
    4343            : base("FruchtermanReingold Layout", controller)
    4444        {
    45 
    4645        }
    4746        #endregion
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Layout/RadialTreeLayout.cs

    r2768 r2861  
    6969            : base("Radial TreeLayout", controller)
    7070        {
    71 
    7271        }
    7372        private bool Init()
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Layout/RandomLayout.cs

    r2768 r2861  
    3939            : base("Random layout", controller)
    4040        {
    41 
    4241        }
    4342        #endregion
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Layout/StandardTreeLayout.cs

    r2819 r2861  
    103103        {
    104104
    105 
     105          Orientation = TreeOrientation.LeftRight;
    106106
    107107        }
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/ConnectionTool.cs

    r2768 r2861  
    55using System.Windows.Forms;
    66
    7 namespace Netron.Diagramming.Core
    8 {
    9    
    10     class ConnectionTool : AbstractTool, IMouseListener
    11     {
     7namespace Netron.Diagramming.Core {
    128
    13         #region Fields
    14         /// <summary>
    15         /// the location of the mouse when the motion starts
    16         /// </summary>
    17         private Point initialPoint;
    18         private bool doDraw;
     9  class ConnectionTool : AbstractTool, IMouseListener {
     10
     11    #region Fields
     12    /// <summary>
     13    /// the location of the mouse when the motion starts
     14    /// </summary>
     15    private Point initialPoint;
     16    private bool doDraw;
     17    #endregion
     18
     19    #region Constructor
     20    /// <summary>
     21    /// Initializes a new instance of the <see cref="T:ConnectionTool"/> class.
     22    /// </summary>
     23    /// <param name="name">The name of the tool.</param>
     24    public ConnectionTool(string name)
     25      : base(name) {
     26    }
     27    #endregion
     28
     29    #region Methods
     30
     31    /// <summary>
     32    /// Called when the tool is activated.
     33    /// </summary>
     34    protected override void OnActivateTool() {
     35      Controller.View.CurrentCursor = CursorPalette.Grip;
     36      this.SuspendOtherTools();
     37      doDraw = false;
     38    }
     39
     40    /// <summary>
     41    /// Handles the mouse down event
     42    /// </summary>
     43    /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
     44    /// <returns>Returns 'true' if the event was handled, otherwise 'false'.</returns>
     45    public bool MouseDown(MouseEventArgs e) {
     46      if (e == null)
     47        throw new ArgumentNullException("The argument object is 'null'");
     48      if (e.Button == MouseButtons.Left && Enabled && !IsSuspended) {
     49
     50        initialPoint = e.Location;
     51        doDraw = true;
     52        return true;
     53      }
     54      return false;
     55    }
     56
     57    /// <summary>
     58    /// Handles the mouse move event
     59    /// </summary>
     60    /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
     61    public void MouseMove(MouseEventArgs e) {
     62      if (e == null)
     63        throw new ArgumentNullException("The argument object is 'null'");
     64      Point point = e.Location;
     65      if (IsActive) {
     66        if (foundConnector != null)
     67          foundConnector.Hovered = false;
     68        foundConnector = Selection.FindConnectorAt(e.Location);
     69        if (foundConnector != null)
     70          foundConnector.Hovered = true;
     71      }
     72      if (IsActive && doDraw) {
     73        Controller.View.PaintGhostLine(initialPoint, point);
     74        Controller.View.Invalidate(System.Drawing.Rectangle.Inflate(Controller.View.Ghost.Rectangle, 20, 20));
     75
     76
     77      }
     78    }
     79    private IConnector foundConnector;
     80    /// <summary>
     81    ///
     82    /// </summary>
     83    /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
     84    public void MouseUp(MouseEventArgs e) {
     85      if (IsActive) {
     86        DeactivateTool();
     87
     88        // First, make sure the initial point is far enough away from
     89        // the final point to make a connection.
     90        int maxX = Math.Abs(Math.Max(initialPoint.X, e.Location.X));
     91        int maxY = Math.Abs(Math.Max(initialPoint.Y, e.Location.Y));
     92
     93        if (!(maxX > ConnectionBase.MinLength) ||
     94            !(maxY > ConnectionBase.MinLength)) {
     95          return;
     96        }
     97
     98        //whatever comes hereafter, a compund command is the most economic approach
     99        CompoundCommand package = new CompoundCommand(this.Controller);
     100
     101        //let's see if the connection endpoints hit other connectors
     102        //note that the following can be done because the actual connection has not been created yet
     103        //otherwise the search would find the endpoints of the newly created connection, which
     104        //would create a loop and a stack overflow!
     105        IConnector startConnector = Selection.FindConnectorAt(initialPoint);
     106        IConnector endConnector = Selection.FindConnectorAt(e.Location);
     107
     108        #region Create the new connection
     109        Connection cn = new Connection(this.initialPoint, e.Location, this.Controller.Model);
     110        AddConnectionCommand newcon = new AddConnectionCommand(this.Controller, cn);
     111
    19112        #endregion
    20113
    21         #region Constructor
    22         /// <summary>
    23         /// Initializes a new instance of the <see cref="T:ConnectionTool"/> class.
    24         /// </summary>
    25         /// <param name="name">The name of the tool.</param>
    26         public ConnectionTool(string name) : base(name)
    27         {
     114        #region Initial attachment?
     115        if (startConnector != null) {
     116          BindConnectorsCommand bindStart = new BindConnectorsCommand(this.Controller, startConnector, cn.From);
     117          package.Commands.Add(bindStart);
    28118        }
    29119        #endregion
    30120
    31         #region Methods
    32 
    33         /// <summary>
    34         /// Called when the tool is activated.
    35         /// </summary>
    36         protected override void OnActivateTool()
    37         {
    38             Controller.View.CurrentCursor =CursorPalette.Grip;
    39             this.SuspendOtherTools();
    40             doDraw = false;
    41         }
    42 
    43         /// <summary>
    44         /// Handles the mouse down event
    45         /// </summary>
    46         /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
    47         /// <returns>Returns 'true' if the event was handled, otherwise 'false'.</returns>
    48         public bool MouseDown(MouseEventArgs e)
    49         {
    50             if (e == null)
    51                 throw new ArgumentNullException("The argument object is 'null'");
    52             if (e.Button == MouseButtons.Left && Enabled && !IsSuspended)
    53             {
    54                
    55                     initialPoint = e.Location;
    56                     doDraw = true;
    57                     return true;           
    58             }
    59             return false;
    60         }
    61 
    62         /// <summary>
    63         /// Handles the mouse move event
    64         /// </summary>
    65         /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
    66         public void MouseMove(MouseEventArgs e)
    67         {
    68             if (e == null)
    69                 throw new ArgumentNullException("The argument object is 'null'");
    70             Point point = e.Location;
    71             if (IsActive)
    72             {
    73                 if (foundConnector != null)
    74                     foundConnector.Hovered = false;
    75                 foundConnector = Selection.FindConnectorAt(e.Location);
    76                 if (foundConnector != null)
    77                     foundConnector.Hovered = true;
    78             }
    79             if(IsActive && doDraw)
    80             {
    81                 Controller.View.PaintGhostLine(initialPoint, point);
    82                 Controller.View.Invalidate(System.Drawing.Rectangle.Inflate(Controller.View.Ghost.Rectangle, 20, 20));
    83                
    84                
    85             }           
    86         }
    87         private IConnector foundConnector;
    88         /// <summary>
    89         ///
    90         /// </summary>
    91         /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
    92         public void MouseUp(MouseEventArgs e)
    93         {
    94             if (IsActive)
    95             {
    96                 DeactivateTool();
    97 
    98                 // First, make sure the initial point is far enough away from
    99                 // the final point to make a connection.
    100                 int maxX = Math.Abs(Math.Max(initialPoint.X, e.Location.X));
    101                 int maxY = Math.Abs(Math.Max(initialPoint.Y, e.Location.Y));
    102 
    103                 if (!(maxX > ConnectionBase.MinLength) ||
    104                     !(maxY > ConnectionBase.MinLength))
    105                 {
    106                     return;
    107                 }
    108 
    109                 //whatever comes hereafter, a compund command is the most economic approach
    110                 CompoundCommand package = new CompoundCommand(this.Controller);
    111 
    112                 //let's see if the connection endpoints hit other connectors
    113                 //note that the following can be done because the actual connection has not been created yet
    114                 //otherwise the search would find the endpoints of the newly created connection, which
    115                 //would create a loop and a stack overflow!
    116                 IConnector startConnector = Selection.FindConnectorAt(initialPoint);
    117                 IConnector endConnector = Selection.FindConnectorAt(e.Location);
    118 
    119                 #region Create the new connection
    120                 Connection cn = new Connection(this.initialPoint, e.Location, this.Controller.Model);
    121                 AddConnectionCommand newcon = new AddConnectionCommand(this.Controller, cn);
    122                 package.Commands.Add(newcon);
    123                 #endregion
    124      
    125                 #region Initial attachment?
    126                 if(startConnector != null)
    127                 {
    128                     BindConnectorsCommand bindStart = new BindConnectorsCommand(this.Controller, startConnector, cn.From);
    129                     package.Commands.Add(bindStart);
    130                 }
    131                 #endregion
    132 
    133                 #region Final attachment?
    134                 if(endConnector != null)
    135                 {
    136                     BindConnectorsCommand bindEnd = new BindConnectorsCommand(this.Controller, endConnector, cn.To);
    137                     package.Commands.Add(bindEnd);
    138                 }
    139                 #endregion
    140            package.Text = "New connection";
    141                 this.Controller.UndoManager.AddUndoCommand(package);
    142                
    143                 //do it all
    144                 package.Redo();
    145 
    146                 //reset highlight of the found connector
    147                 if (foundConnector != null)
    148                     foundConnector.Hovered = false;
    149                 //drop the painted ghost
    150                 Controller.View.ResetGhost();
    151                 //release other tools
    152                 this.UnsuspendTools();
    153             }
     121        #region Final attachment?
     122        if (endConnector != null) {
     123          BindConnectorsCommand bindEnd = new BindConnectorsCommand(this.Controller, endConnector, cn.To);
     124          package.Commands.Add(bindEnd);
    154125        }
    155126        #endregion
     127        package.Text = "New connection";
     128        package.Commands.Add(newcon);
     129        this.Controller.UndoManager.AddUndoCommand(package);
     130
     131        //do it all
     132        package.Redo();
     133
     134        //reset highlight of the found connector
     135        if (foundConnector != null)
     136          foundConnector.Hovered = false;
     137        //drop the painted ghost
     138        Controller.View.ResetGhost();
     139        //release other tools
     140        this.UnsuspendTools();
     141      }
    156142    }
     143    #endregion
     144  }
    157145
    158146}
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/HeuristicLab.Operators.Views.GraphVisualization-3.3.csproj

    r2853 r2861  
    9595    <None Include="HeuristicLabOperatorsViewsGraphVisualizationPlugin.cs.frame" />
    9696    <None Include="Properties\AssemblyInfo.frame" />
    97     <Compile Include="Model\ConnectionInfo.cs" />
    98     <Compile Include="Model\IConnectionInfo.cs" />
    9997    <Compile Include="Model\OperatorShapeInfo.cs" />
    10098    <Compile Include="Model\OperatorGraphVisualizationInfo.cs" />
     
    106104    </Compile>
    107105    <Compile Include="Model\ShapeInfoFactory.cs" />
     106    <Compile Include="ToolBarItems\ConnectionToolBarItem.cs" />
    108107    <Compile Include="ToolBarItems\SelectToolBarItem.cs" />
    109108    <Compile Include="ToolBarItems\PanToolBarItem.cs" />
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/IShapeInfo.cs

    r2853 r2861  
    2727using System.Drawing;
    2828using Netron.Diagramming.Core;
     29using HeuristicLab.Collections;
    2930
    3031namespace HeuristicLab.Operators.Views.GraphVisualization {
     
    3435    Size Size { get; set; }
    3536
     37    void AddConnector(string connectorName);
     38    void RemoveConnector(string connectorName);
     39
     40    IEnumerable<KeyValuePair<string,IShapeInfo>> Connections {get;}
     41    INotifyObservableDictionaryItemsChanged<string, IShapeInfo> ObservableConnections { get; }
     42
     43    void AddConnection(string fromConnectorName, IShapeInfo toShapeInfo);
     44    void RemoveConnection(string fromConnectorName);
     45    void ChangeConnection(string fromConnector, IShapeInfo toShapeInfo);
     46
    3647    IShape CreateShape();
     48    void UpdateShape(IShape shape);
    3749  }
    3850}
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorGraphVisualizationInfo.cs

    r2853 r2861  
    3030
    3131namespace HeuristicLab.Operators.Views.GraphVisualization {
    32   public sealed class OperatorGraphVisualizationInfo : Item {
     32  public sealed class OperatorGraphVisualizationInfo : DeepCloneable {
    3333    private BidirectionalLookup<IOperator, IShapeInfo> shapeInfoMapping;
    34 
    35     public OperatorGraphVisualizationInfo(OperatorGraph operatorGraph) {
     34    private BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>> operatorParameterCollectionMapping;
     35    private Dictionary<IValueParameter<IOperator>, IOperator> parameterOperatorMapping;
     36
     37    private OperatorGraphVisualizationInfo() {
     38      this.shapeInfoMapping = new BidirectionalLookup<IOperator, IShapeInfo>();
     39      this.operatorParameterCollectionMapping = new BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>>();
     40      this.parameterOperatorMapping = new Dictionary<IValueParameter<IOperator>, IOperator>();
     41
     42      this.shapeInfos = new ObservableSet<IShapeInfo>();
     43    }
     44
     45    public OperatorGraphVisualizationInfo(OperatorGraph operatorGraph)
     46      : this() {
    3647      this.operatorGraph = operatorGraph;
    37       this.shapeInfoMapping = new BidirectionalLookup<IOperator, IShapeInfo>();
    38       this.shapeInfos = new ObservableSet<IShapeInfo>();
    39 
     48      this.operatorGraph.InitialOperatorChanged += new EventHandler(operatorGraph_InitialOperatorChanged);
    4049      foreach (IOperator op in operatorGraph.Operators)
    4150        this.AddOperator(op);
    42       this.initialOperator = operatorGraph.InitialOperator;
    4351
    4452      operatorGraph.Operators.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsAdded);
     
    4755    }
    4856
     57    public event EventHandler InitialShapeChanged;
     58    private void operatorGraph_InitialOperatorChanged(object sender, EventArgs e) {
     59      if (this.InitialShapeChanged != null)
     60        this.InitialShapeChanged(this, new EventArgs());
     61    }
     62
     63    public IShapeInfo InitialShape {
     64      get {
     65        IOperator op = this.operatorGraph.InitialOperator;
     66        if (op == null)
     67          return null;
     68        return this.shapeInfoMapping.GetByFirst(op);
     69      }
     70    }
     71
    4972    private OperatorGraph operatorGraph;
    5073    public OperatorGraph OperatorGraph {
     
    5679      get { return this.shapeInfos; }
    5780    }
    58 
    5981    public IEnumerable<IShapeInfo> ShapeInfos {
    6082      get { return this.shapeInfos; }
    6183    }
    6284
    63     private IOperator initialOperator;
    64     public IOperator InitialOperator {
    65       get { return this.initialOperator; }
    66       set {
    67         if (this.initialOperator != value) {
    68           if (!this.shapeInfoMapping.ContainsFirst(value))
    69             throw new ArgumentException("Could not set initial operator in graph visualization information, because the operator " +
    70               value.ToString() + " is not contained in the operator set.");
    71           this.initialOperator = value;
    72           this.OnChanged();
    73         }
    74       }
    75     }
    76 
    7785    internal void AddShapeInfo(IOperator op, IShapeInfo shapeInfo) {
    7886      this.RegisterOperatorEvents(op);
     87      this.operatorParameterCollectionMapping.Add(op, op.Parameters);
    7988      this.shapeInfoMapping.Add(op, shapeInfo);
    8089      this.shapeInfos.Add(shapeInfo);
     
    9099    #region operator events
    91100    private void AddOperator(IOperator op) {
    92       if (!shapeInfoMapping.ContainsFirst(op)) {
    93         this.RegisterOperatorEvents(op);
    94 
    95         IShapeInfo shapeInfo = ShapeInfoFactory.CreateShapeInfo(op);
    96         this.shapeInfoMapping.Add(op, shapeInfo);
    97         this.shapeInfos.Add(shapeInfo);
    98       }
     101      if (shapeInfoMapping.ContainsFirst(op))
     102        return;
     103
     104      this.RegisterOperatorEvents(op);
     105      IShapeInfo shapeInfo = Factory.CreateShapeInfo(op);
     106      this.operatorParameterCollectionMapping.Add(op, op.Parameters);
     107      this.shapeInfoMapping.Add(op, shapeInfo);
     108      foreach (IParameter param in op.Parameters)
     109        this.AddParameter(op, param);
     110
     111      this.shapeInfos.Add(shapeInfo);
    99112    }
    100113
    101114    private void RemoveOperator(IOperator op) {
    102115      this.DeregisterOperatorEvents(op);
     116      foreach (IParameter param in op.Parameters)
     117        this.RemoveParameter(op, param);
    103118
    104119      IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op);
     120      this.operatorParameterCollectionMapping.RemoveByFirst(op);
    105121      this.shapeInfoMapping.RemoveByFirst(op);
    106122      this.shapeInfos.Remove(shapeInfo);
     
    139155
    140156    #region parameter events
    141     private void AddParameter(IParameter param) {
     157    private void AddParameter(IOperator op, IParameter param) {
    142158      IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>;
    143159      if (opParam != null) {
    144         RegisterOperatorParameterEvents(opParam);
    145         //TODO add connector
    146       }
    147     }
    148     private void RemoveParameter(IParameter param) {
     160        this.RegisterOperatorParameterEvents(opParam);
     161        this.parameterOperatorMapping.Add(opParam, op);
     162        IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op);
     163        shapeInfo.AddConnector(param.Name);
     164
     165        if (opParam.Value != null) {
     166          if (!this.shapeInfoMapping.ContainsFirst(opParam.Value))
     167            this.AddOperator(opParam.Value);
     168          shapeInfo.AddConnection(param.Name, this.shapeInfoMapping.GetByFirst(opParam.Value));
     169        }
     170      }
     171    }
     172    private void RemoveParameter(IOperator op, IParameter param) {
    149173      IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>;
    150174      if (opParam != null) {
    151         DeregisterOperatorParameterEvents(opParam);
    152         //TODO remove connector
     175        this.DeregisterOperatorParameterEvents(opParam);
     176        this.parameterOperatorMapping.Remove(opParam);
     177        IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op);
     178        shapeInfo.RemoveConnector(param.Name);
    153179      }
    154180    }
     
    156182    private void opParam_ValueChanged(object sender, EventArgs e) {
    157183      IValueParameter<IOperator> opParam = (IValueParameter<IOperator>)sender;
    158       //TODO update connections
     184      if (opParam != null) {
     185        IOperator op = this.parameterOperatorMapping[opParam];
     186        IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op);
     187
     188        if (opParam.Value == null)
     189          shapeInfo.RemoveConnection(opParam.Name);
     190        else
     191          shapeInfo.ChangeConnection(opParam.Name, this.shapeInfoMapping.GetByFirst(opParam.Value));
     192      }
    159193    }
    160194
    161195    private void Parameters_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
    162       foreach (IParameter param in e.Items)
    163         AddParameter(param);
     196      IObservableKeyedCollection<string, IParameter> parameterCollection = sender as IObservableKeyedCollection<string, IParameter>;
     197      IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection);
     198      foreach (IParameter param in e.Items)
     199        AddParameter(op, param);
    164200    }
    165201    private void Parameters_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
    166       foreach (IParameter param in e.Items)
    167         RemoveParameter(param);
     202      IObservableKeyedCollection<string, IParameter> parameterCollection = sender as IObservableKeyedCollection<string, IParameter>;
     203      IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection);
     204      foreach (IParameter param in e.Items)
     205        RemoveParameter(op, param);
    168206    }
    169207    private void Parameters_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
     208      IObservableKeyedCollection<string, IParameter> parameterCollection = sender as IObservableKeyedCollection<string, IParameter>;
     209      IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection);
    170210      foreach (IParameter param in e.OldItems)
    171         RemoveParameter(param);
    172       foreach (IParameter param in e.Items)
    173         AddParameter(param);
     211        RemoveParameter(op, param);
     212      foreach (IParameter param in e.Items)
     213        AddParameter(op, param);
    174214    }
    175215    private void Parameters_CollectionReset(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
     216      IObservableKeyedCollection<string, IParameter> parameterCollection = sender as IObservableKeyedCollection<string, IParameter>;
     217      IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection);
    176218      foreach (IParameter param in e.OldItems)
    177         RemoveParameter(param);
    178       foreach (IParameter param in e.Items)
    179         AddParameter(param);
    180     }
     219        RemoveParameter(op, param);
     220      foreach (IParameter param in e.Items)
     221        AddParameter(op, param);
     222    }
     223
    181224
    182225    private void RegisterOperatorParameterEvents(IValueParameter<IOperator> opParam) {
     
    187230    }
    188231    #endregion
    189 
    190 
    191 
    192 
    193 
    194 
    195 
    196 
    197     private static IConnection CreateConnection(IShape from, IShape to) {
    198       IConnector parentConnector = from.Connectors.Where(c => c.Name == "Bottom connector").First();
    199       IConnector operatorConnector = to.Connectors.Where(c => c.Name == "Top connector").First();
    200 
    201       IConnection connection = new Connection(parentConnector.Point, operatorConnector.Point);
    202 
    203       parentConnector.AttachConnector(connection.From);
    204       operatorConnector.AttachConnector(connection.To);
    205 
    206       return connection;
    207     }
    208232  }
    209233}
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorShape.cs

    r2853 r2861  
    3030  public class OperatorShape : ClassShape {
    3131
    32     private BidirectionalLookup<string, IConnector> additionalConnectors;
    3332    public OperatorShape()
    3433      : base() {
    35       this.additionalConnectors = new BidirectionalLookup<string,IConnector>();
     34      this.additionalConnectors = new List<IConnector>();
    3635    }
    3736
    38     private Connector predecessor;
    39     public Connector Predecessor {
     37    private List<IConnector> additionalConnectors;
     38    public IEnumerable<string> AdditionalConnectorNames {
     39      get { return this.additionalConnectors.Select(c => c.Name); }
     40    }
     41
     42    private IConnector predecessor;
     43    public IConnector Predecessor {
    4044      get { return this.predecessor; }
    4145    }
    4246
    43     private Connector successor;
    44     public Connector Successor {
     47    private IConnector successor;
     48    public IConnector Successor {
    4549      get { return this.successor; }
    4650    }
    4751
     52    private IConnector CreateConnector(string connectorName, Point location) {
     53      Connector connector = new Connector(location);
     54      connector.ConnectorStyle = ConnectorStyle.Square;
     55      connector.Parent = this;
     56      connector.Name = connectorName;
     57      return connector;
     58    }
     59
     60
    4861
    4962    public void AddConnector(string connectorName) {
    50       Connector connector = new Connector(new Point(Rectangle.Right, Rectangle.Bottom));
    51       connector.ConnectorStyle = ConnectorStyle.Square;
    52       connector.Parent = this;
    53       this.additionalConnectors.Add(connectorName, connector);
    54       Connectors.Add(connector);
     63      IConnector connector = this.CreateConnector(connectorName, this.BottomRightCorner);
     64
     65      this.additionalConnectors.Add(connector);
     66      this.Connectors.Add(connector);
     67      this.UpdateConnectorLocation();
    5568    }
    5669
    5770    public void RemoveConnector(string connectorName) {
    58       this.additionalConnectors.RemoveByFirst(connectorName);
    59       this.UpdateConnectorLocation();
     71      IConnector connector = this.additionalConnectors.Where(c => c.Name ==connectorName).FirstOrDefault();
     72      if (connector != null) {
     73        this.additionalConnectors.Remove(connector);
     74        this.Connectors.Remove(connector);
     75        this.UpdateConnectorLocation();
     76      }
    6077    }
    6178
    62     private void UpdateConnectorLocation() {
    63       //TODO set x position of connectors
     79    private void UpdateConnectorLocation() {
     80      int spacing = this.Rectangle.Width / this.additionalConnectors.Count + 1;
     81      int margin = spacing / 2;
     82      int posX = margin + this.Rectangle.X;
     83      int posY = this.additionalConnectors[0].Point.Y;
     84      for (int i = 0; i < this.additionalConnectors.Count; i++) {
     85        this.additionalConnectors[i].Point = new Point(posX, posY);
     86        posX += spacing;
     87      }
    6488    }
    6589
     
    7195      this.Connectors.Clear();
    7296
    73       predecessor = new Connector(new Point(Rectangle.Right, (int)(Rectangle.Top + Rectangle.Height / 2)));
    74       predecessor.ConnectorStyle = ConnectorStyle.Square;
    75       predecessor.Name = "Predecessor";
    76       predecessor.Parent = this;
     97      predecessor = this.CreateConnector("Predecessor", new Point(Rectangle.Left, Center.Y));
    7798      Connectors.Add(predecessor);
    7899
    79       successor = new Connector(new Point(Rectangle.Left, (int)(Rectangle.Top + Rectangle.Height / 2)));
    80       predecessor.ConnectorStyle = ConnectorStyle.Square;
    81       successor.Name = "Successor";
    82       successor.Parent = this;
     100      successor = this.CreateConnector("Successor",(new Point(Rectangle.Right, Center.Y)));
    83101      Connectors.Add(successor);
    84102      #endregion
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorShapeInfo.cs

    r2853 r2861  
    2727using System.Drawing;
    2828using Netron.Diagramming.Core;
     29using System.Windows.Forms;
    2930
    3031namespace HeuristicLab.Operators.Views.GraphVisualization {
    3132  internal class OperatorShapeInfo : ShapeInfo {
    3233
    33     private HashSet<string> connectorNames;
     34    private List<string> connectorNames;
    3435    public OperatorShapeInfo()
    3536      : base(typeof(OperatorShape)) {
    36       this.connectorNames = new HashSet<string>();
     37      this.connectorNames = new List<string>();
    3738    }
    3839
     
    4344    }
    4445
    45     public void AddConnector(string connectorName) {
    46       if (this.connectorNames.Add(connectorName))
     46    public override void AddConnector(string connectorName) {
     47      if (!this.connectorNames.Contains(connectorName) && connectorName != "Successor") {
     48        this.connectorNames.Add(connectorName);
    4749        this.OnChanged();
     50      }
    4851    }
    4952
    50     public void RemoveConnector(string connectorName) {
    51       if (this.connectorNames.Remove(connectorName))
     53    public override void RemoveConnector(string connectorName) {
     54      if (this.connectorNames.Contains(connectorName)) {
     55        this.connectorNames.Remove(connectorName);
     56        if (this.connections.ContainsKey(connectorName))
     57          this.connections.Remove(connectorName);
    5258        this.OnChanged();
     59      }
    5360    }
    5461
     62    public override void AddConnection(string fromConnectorName, IShapeInfo toShapeInfo) {
     63      this.connections.Add(fromConnectorName, toShapeInfo);
     64    }
     65
     66    public override void RemoveConnection(string fromConnectorName) {
     67      if (this.connections.ContainsKey(fromConnectorName))
     68        this.connections.Remove(fromConnectorName);
     69    }
     70
     71    public override void ChangeConnection(string fromConnectorName, IShapeInfo toShapeInfo) {
     72      this.connections[fromConnectorName] = toShapeInfo;
     73    }
    5574
    5675    private string title;
     
    96115      return shape;
    97116    }
     117
     118    public override void UpdateShape(IShape shape) {
     119      base.UpdateShape(shape);
     120      OperatorShape operatorShape = shape as OperatorShape;
     121
     122      if (operatorShape != null) {
     123        operatorShape.Title = this.Title;
     124        operatorShape.SubTitle = this.Text;
     125        operatorShape.HeadColor = this.HeadColor;
     126
     127        int i = 0;
     128        int j = 0;
     129        //remove old connectors and skip correct connectors
     130        List<string> oldConnectorNames = operatorShape.AdditionalConnectorNames.ToList();
     131        while (i < this.connectorNames.Count && j < oldConnectorNames.Count) {
     132          if (this.connectorNames[i] != oldConnectorNames[j]) {
     133            operatorShape.RemoveConnector(oldConnectorNames[j]);
     134          } else
     135            i++;
     136          j++;
     137        }
     138        //remove old connectors
     139        for (; j < oldConnectorNames.Count; i++)
     140          operatorShape.RemoveConnector(oldConnectorNames[j]);
     141
     142        //add new connectors
     143        for (; i < this.connectorNames.Count; i++)
     144          operatorShape.AddConnector(this.connectorNames[i]);
     145      }
     146    }
    98147  }
    99148}
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/ShapeInfo.cs

    r2853 r2861  
    2727using System.Drawing;
    2828using Netron.Diagramming.Core;
     29using HeuristicLab.Collections;
    2930
    3031namespace HeuristicLab.Operators.Views.GraphVisualization {
    3132  internal abstract class ShapeInfo : Item, IShapeInfo {
    32 
    33 
    3433    protected ShapeInfo(Type shapeType) {
    3534      if (!typeof(IShape).IsAssignableFrom(shapeType))
    3635        throw new ArgumentException("The passed shape type " + shapeType + " must be derived from IShape.");
    3736      this.shapeType = shapeType;
     37      this.connections = new ObservableDictionary<string, IShapeInfo>();
    3838    }
    3939
     
    6565    }
    6666
     67    protected ObservableDictionary<string, IShapeInfo> connections;
     68    public IEnumerable<KeyValuePair<string, IShapeInfo>> Connections {
     69      get { return this.connections; }
     70    }
     71    public INotifyObservableDictionaryItemsChanged<string, IShapeInfo> ObservableConnections {
     72      get { return this.connections; }
     73    }
     74
     75    public abstract void AddConnector(string connectorName);
     76    public abstract void RemoveConnector(string connectorName);
     77    public abstract void AddConnection(string fromConnectorName, IShapeInfo toShapeInfo);
     78    public abstract void RemoveConnection(string fromConnectorName);
     79    public abstract void ChangeConnection(string fromConnectorName, IShapeInfo toShapeInfo);
     80
     81
    6782    public virtual IShape CreateShape() {
    6883      IShape shape = (IShape)Activator.CreateInstance(this.shapeType);
     
    7287      return shape;
    7388    }
     89
     90    public virtual void UpdateShape(IShape shape) {
     91      shape.Location = this.Location;
     92      shape.Height = this.Size.Height;
     93      shape.Width = this.Size.Width;
     94    }
    7495  }
    7596}
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/ShapeInfoFactory.cs

    r2853 r2861  
    2525using System.Text;
    2626using HeuristicLab.Core;
     27using Netron.Diagramming.Core;
     28using System.Drawing;
     29using System.Drawing.Drawing2D;
    2730
    2831namespace HeuristicLab.Operators.Views.GraphVisualization {
    29   public static class ShapeInfoFactory {
     32  public static class Factory {
     33    private static LinePenStyle connectionPenStyle;
     34
     35    static Factory() {
     36      connectionPenStyle = new LinePenStyle();
     37      connectionPenStyle.EndCap = LineCap.ArrowAnchor;
     38    }
     39
    3040    public static IShapeInfo CreateShapeInfo(IOperator op) {
    31       OperatorShapeInfo operatorShapeInfo = new OperatorShapeInfo();
     41      IEnumerable<string> paramterNames = op.Parameters.Where(p => p is IValueParameter<IOperator> && p.Name != "Successor").Select(p => p.Name);
     42      OperatorShapeInfo operatorShapeInfo = new OperatorShapeInfo(paramterNames);
    3243      operatorShapeInfo.Title = op.Name;
    3344      operatorShapeInfo.Text = op.GetType().ToString();
     
    3546      return operatorShapeInfo;
    3647    }
     48
     49    public static IConnection CreateConnection(IConnector from, IConnector to) {
     50      Connection connection = new Connection(from.Point, to.Point);
     51      connection.AllowMove = false;
     52      from.AttachConnector(connection.From);
     53      to.AttachConnector(connection.To);
     54      connection.PenStyle = connectionPenStyle;
     55      return connection;
     56    }
    3757  }
    3858}
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphView.Designer.cs

    r2853 r2861  
    4949      this.graphVisualization.TabIndex = 0;
    5050      this.graphVisualization.OnEntityRemoved += new System.EventHandler<global::Netron.Diagramming.Core.EntityEventArgs>(this.graphVisualization_OnEntityRemoved);
     51      this.graphVisualization.OnEntityAdded += new System.EventHandler<global::Netron.Diagramming.Core.EntityEventArgs>(this.graphVisualization_OnEntityAdded);
    5152      //
    5253      // OperatorGraphView
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphView.cs

    r2853 r2861  
    3434using HeuristicLab.Parameters;
    3535using HeuristicLab.MainForm.WindowsForms;
     36using HeuristicLab.Collections;
    3637
    3738namespace HeuristicLab.Operators.Views.GraphVisualization {
     39
    3840  [Content(typeof(OperatorGraph), false)]
    3941  public partial class OperatorGraphView : ContentView {
    40     private BidirectionalLookup<IShapeInfo, IShape> shapeMapping;
    41     private BidirectionalLookup<IConnectionInfo, IConnection> connectionMapping;
     42    private BidirectionalLookup<IShapeInfo, IShape> shapeInfoShapeMapping;
     43    private BidirectionalLookup<IShapeInfo, INotifyObservableDictionaryItemsChanged<string, IShapeInfo>> shapeInfoConnectionsMapping;
     44    private Dictionary<IConnector, IShape> connectorShapeMapping;
     45    private BidirectionalLookup<IConnection, KeyValuePair<IConnector, IConnector>> connectionConnectorsMapping;
    4246
    4347    private bool causedUpdateOfShapeInfo;
     
    4650      this.causedUpdateOfShapeInfo = false;
    4751      Caption = "Operator Graph";
    48       this.shapeMapping = new BidirectionalLookup<IShapeInfo, IShape>();
    49       this.connectionMapping = new BidirectionalLookup<IConnectionInfo, IConnection>();
     52      this.shapeInfoShapeMapping = new BidirectionalLookup<IShapeInfo, IShape>();
     53      this.shapeInfoConnectionsMapping = new BidirectionalLookup<IShapeInfo, INotifyObservableDictionaryItemsChanged<string, IShapeInfo>>();
     54      this.connectionConnectorsMapping = new BidirectionalLookup<IConnection, KeyValuePair<IConnector, IConnector>>();
     55      this.connectorShapeMapping = new Dictionary<IConnector, IShape>();
    5056    }
    5157
     
    7278
    7379    private void UpdateVisualizationInfo() {
    74       foreach (IShapeInfo shapeInfo in this.shapeMapping.FirstValues)
     80      foreach (IShapeInfo shapeInfo in this.shapeInfoShapeMapping.FirstValues)
    7581        this.RemoveShapeInfo(shapeInfo);
    76       this.shapeMapping.Clear();
     82
     83      this.shapeInfoShapeMapping.Clear();
     84      this.shapeInfoConnectionsMapping.Clear();
     85      this.connectorShapeMapping.Clear();
     86      this.connectionConnectorsMapping.Clear();
    7787
    7888      foreach (IShapeInfo shapeInfo in this.VisualizationInfo.ShapeInfos)
    7989        this.AddShapeInfo(shapeInfo);
     90
     91      this.UpdateLayoutRoot();
     92    }
     93
     94    private void UpdateLayoutRoot() {
     95      IShapeInfo shapeInfo = this.VisualizationInfo.InitialShape;
     96      if (shapeInfo != null)
     97        this.graphVisualization.Controller.Model.LayoutRoot = this.shapeInfoShapeMapping.GetByFirst(shapeInfo);
     98      else
     99        this.graphVisualization.Controller.Model.LayoutRoot = null;
     100    }
     101
     102    private void VisualizationInfo_InitialShapeChanged(object sender, EventArgs e) {
     103      this.UpdateLayoutRoot();
    80104    }
    81105
    82106    protected override void RegisterContentEvents() {
    83107      base.RegisterContentEvents();
     108      this.VisualizationInfo.InitialShapeChanged += new EventHandler(VisualizationInfo_InitialShapeChanged);
    84109      this.VisualizationInfo.ObserveableShapeInfos.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_ItemsAdded);
    85110      this.VisualizationInfo.ObserveableShapeInfos.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_ItemsRemoved);
     
    89114    protected override void DeregisterContentEvents() {
    90115      base.DeregisterContentEvents();
     116      this.VisualizationInfo.InitialShapeChanged -= new EventHandler(VisualizationInfo_InitialShapeChanged);
    91117      this.VisualizationInfo.ObserveableShapeInfos.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_ItemsAdded);
    92118      this.VisualizationInfo.ObserveableShapeInfos.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_ItemsRemoved);
    93119      this.VisualizationInfo.ObserveableShapeInfos.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_CollectionReset);
    94120    }
    95 
    96121
    97122    private void ShapeInfos_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IShapeInfo> e) {
     
    100125      foreach (IShapeInfo shapeInfo in e.Items)
    101126        this.AddShapeInfo(shapeInfo);
    102       this.graphVisualization.Invalidate();
    103127    }
    104128
     
    106130      foreach (IShapeInfo shapeInfo in e.Items)
    107131        this.AddShapeInfo(shapeInfo);
    108       this.graphVisualization.Invalidate();
    109132    }
    110133
     
    112135      foreach (IShapeInfo shapeInfo in e.Items)
    113136        this.RemoveShapeInfo(shapeInfo);
    114       this.graphVisualization.Invalidate();
    115137    }
    116138
    117139    private void AddShapeInfo(IShapeInfo shapeInfo) {
     140      this.RegisterShapeInfoEvents(shapeInfo);
     141
    118142      IShape shape = shapeInfo.CreateShape();
     143      shape.OnEntityChange += new EventHandler<EntityEventArgs>(shape_OnEntityChange);
     144      this.shapeInfoShapeMapping.Add(shapeInfo, shape);
     145
     146      foreach (IConnector connector in shape.Connectors)
     147        this.connectorShapeMapping.Add(connector, shape);
     148
    119149      this.graphVisualization.Controller.Model.AddShape(shape);
    120       this.shapeMapping.Add(shapeInfo, shape);
    121 
    122       shape.OnEntityChange += new EventHandler<EntityEventArgs>(shape_OnEntityChange);
    123       shapeInfo.Changed += new ChangedEventHandler(shapeInfo_Changed);
     150
     151      foreach (KeyValuePair<string, IShapeInfo> pair in shapeInfo.Connections) {
     152        if (!this.shapeInfoShapeMapping.ContainsFirst(pair.Value))
     153          this.AddShapeInfo(pair.Value);
     154        this.AddConnection(shapeInfo, pair.Key, pair.Value);
     155      }
    124156    }
    125157
    126158    private void RemoveShapeInfo(IShapeInfo shapeInfo) {
    127       IShape shape = this.shapeMapping.GetByFirst(shapeInfo);
     159      this.DeregisterShapeInfoEvents(shapeInfo);
     160      IShape shape = this.shapeInfoShapeMapping.GetByFirst(shapeInfo);
    128161      shape.OnEntityChange -= new EventHandler<EntityEventArgs>(shape_OnEntityChange);
    129162      shapeInfo.Changed -= new ChangedEventHandler(shapeInfo_Changed);
    130163
    131       this.shapeMapping.RemoveByFirst(shapeInfo);
    132       if (this.graphVisualization.Controller.Model.Shapes.Contains(shape))
     164      IConnection connection;
     165      foreach (IConnector connector in shape.Connectors) {
     166        connection = this.GetConnection(shapeInfo, connector.Name);
     167        this.RemoveConnection(connection);
     168      }
     169
     170      this.shapeInfoShapeMapping.RemoveByFirst(shapeInfo);
     171
     172      if (this.graphVisualization.Controller.Model.Shapes.Contains(shape)) {
    133173        this.graphVisualization.Controller.Model.RemoveShape(shape);
    134     }
     174      }
     175    }
     176
     177    private void RegisterShapeInfoEvents(IShapeInfo shapeInfo) {
     178      shapeInfo.Changed += new ChangedEventHandler(shapeInfo_Changed);
     179
     180      this.shapeInfoConnectionsMapping.Add(shapeInfo, shapeInfo.ObservableConnections);
     181      shapeInfo.ObservableConnections.ItemsAdded += new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_ItemsAdded);
     182      shapeInfo.ObservableConnections.ItemsRemoved += new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_ItemsRemoved);
     183      shapeInfo.ObservableConnections.ItemsReplaced += new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_ItemsReplaced);
     184      shapeInfo.ObservableConnections.CollectionReset += new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_CollectionReset);
     185    }
     186
     187    private void DeregisterShapeInfoEvents(IShapeInfo shapeInfo) {
     188      shapeInfo.Changed -= new ChangedEventHandler(shapeInfo_Changed);
     189
     190      this.shapeInfoConnectionsMapping.RemoveByFirst(shapeInfo);
     191      shapeInfo.ObservableConnections.ItemsAdded -= new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_ItemsAdded);
     192      shapeInfo.ObservableConnections.ItemsRemoved -= new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_ItemsRemoved);
     193      shapeInfo.ObservableConnections.ItemsReplaced -= new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_ItemsReplaced);
     194      shapeInfo.ObservableConnections.CollectionReset -= new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_CollectionReset);
     195    }
     196
     197    private void Connections_CollectionReset(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IShapeInfo>> e) {
     198      IShapeInfo shapeInfo = this.shapeInfoConnectionsMapping.GetBySecond((INotifyObservableDictionaryItemsChanged<string, IShapeInfo>)sender);
     199      IConnection connection;
     200      foreach (KeyValuePair<string, IShapeInfo> pair in e.Items) {
     201        connection = this.GetConnection(shapeInfo, pair.Key);
     202        this.RemoveConnection(connection);
     203      }
     204      foreach (KeyValuePair<string, IShapeInfo> pair in e.Items)
     205        this.AddConnection(shapeInfo, pair.Key, pair.Value);
     206    }
     207
     208    private void Connections_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IShapeInfo>> e) {
     209      IShapeInfo shapeInfo = this.shapeInfoConnectionsMapping.GetBySecond((INotifyObservableDictionaryItemsChanged<string, IShapeInfo>)sender);
     210      IConnection connection;
     211      foreach (KeyValuePair<string, IShapeInfo> pair in e.Items) {
     212        connection = this.GetConnection(shapeInfo, pair.Key);
     213        this.RemoveConnection(connection);
     214      }
     215      foreach (KeyValuePair<string, IShapeInfo> pair in e.Items)
     216        this.AddConnection(shapeInfo, pair.Key, pair.Value);
     217    }
     218
     219    private void Connections_ItemsAdded(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IShapeInfo>> e) {
     220      IShapeInfo shapeInfo = this.shapeInfoConnectionsMapping.GetBySecond((INotifyObservableDictionaryItemsChanged<string, IShapeInfo>)sender);
     221      foreach (KeyValuePair<string, IShapeInfo> pair in e.Items)
     222        this.AddConnection(shapeInfo, pair.Key, pair.Value);
     223    }
     224
     225    private void Connections_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IShapeInfo>> e) {
     226      IShapeInfo shapeInfo = this.shapeInfoConnectionsMapping.GetBySecond((INotifyObservableDictionaryItemsChanged<string, IShapeInfo>)sender);
     227      IConnection connection;
     228      foreach (KeyValuePair<string, IShapeInfo> pair in e.Items) {
     229        connection = this.GetConnection(shapeInfo, pair.Key);
     230        this.RemoveConnection(connection);
     231      }
     232    }
     233
     234    private void AddConnection(IShapeInfo shapeInfoFrom, string connectorName, IShapeInfo shapeInfoTo) {
     235      IShape shapeFrom = this.shapeInfoShapeMapping.GetByFirst(shapeInfoFrom);
     236      IShape shapeTo = this.shapeInfoShapeMapping.GetByFirst(shapeInfoTo);
     237
     238      IConnector connectorFrom = shapeFrom.Connectors.Where(c => c.Name == connectorName).First();
     239      IConnector connectorTo = shapeTo.Connectors.Where(c => c.Name == "Predecessor").FirstOrDefault();
     240
     241      IConnection connection = Factory.CreateConnection(connectorFrom, connectorTo);
     242      this.connectionConnectorsMapping.Add(connection, new KeyValuePair<IConnector, IConnector>(connectorFrom, connectorTo));
     243      this.graphVisualization.Controller.Model.AddConnection(connection);
     244      this.graphVisualization.Invalidate();
     245    }
     246
     247    private IConnection GetConnection(IShapeInfo shapeInfoFrom, string connectorName) {
     248      IShape shape = this.shapeInfoShapeMapping.GetByFirst(shapeInfoFrom);
     249      IConnector connector = shape.Connectors.Where(c => c.Name == connectorName).First();
     250
     251      if (!this.connectionConnectorsMapping.SecondValues.Any(p => p.Key == connector))
     252        return null;
     253
     254      KeyValuePair<IConnector, IConnector> connectorPair = this.connectionConnectorsMapping.SecondValues.Where(p => p.Key == connector).FirstOrDefault();
     255      return this.connectionConnectorsMapping.GetBySecond(connectorPair);
     256    }
     257
     258    private void ChangeConnection(IShapeInfo shapeInfoFrom, string connectorName, IShapeInfo shapeInfoTo) {
     259      IConnection connection = this.GetConnection(shapeInfoFrom, connectorName);
     260      IShape shapeTo = this.shapeInfoShapeMapping.GetByFirst(shapeInfoFrom);
     261      IConnector connectorTo = shapeTo.Connectors.Where(c => c.Name == "Predecessor").FirstOrDefault();
     262
     263      connection.To.DetachFromParent();
     264      connection.To.AttachTo(connectorTo);
     265      this.graphVisualization.Invalidate();
     266    }
     267
     268    private void RemoveConnection(IConnection connection) {
     269      if (connection == null)
     270        return;
     271
     272      if (connection.From.AttachedTo != null)
     273        connection.From.DetachFromParent();
     274      if (connection.To.AttachedTo != null)
     275        connection.To.DetachFromParent();
     276
     277      if (this.connectionConnectorsMapping.ContainsFirst(connection))
     278        this.connectionConnectorsMapping.RemoveByFirst(connection);
     279      if (this.graphVisualization.Controller.Model.Connections.Contains(connection))
     280        this.graphVisualization.Controller.Model.Remove(connection);
     281      this.graphVisualization.Invalidate();
     282    }
     283
    135284
    136285    private void shapeInfo_Changed(object sender, ChangedEventArgs e) {
     286      if (this.causedUpdateOfShapeInfo)
     287        return;
     288
    137289      IShapeInfo shapeInfo = (IShapeInfo)sender;
    138       this.UpdateShape(shapeInfo);
    139     }
     290      IShape shape = this.shapeInfoShapeMapping.GetByFirst(shapeInfo);
     291      shapeInfo.UpdateShape(shape);
     292    }
     293
    140294
    141295    private void shape_OnEntityChange(object sender, EntityEventArgs e) {
    142296      this.causedUpdateOfShapeInfo = true;
    143297      IShape shape = e.Entity as IShape;
    144       IShapeInfo shapeInfo = this.shapeMapping.GetBySecond(shape);
     298      IShapeInfo shapeInfo = this.shapeInfoShapeMapping.GetBySecond(shape);
    145299
    146300      shapeInfo.Location = shape.Location;
     301      shapeInfo.Size = new Size(shape.Width, shape.Height);
     302
    147303      this.graphVisualization.Invalidate();
    148304      this.causedUpdateOfShapeInfo = false;
    149305    }
    150306
    151     private void UpdateShape(IShapeInfo shapeInfo) {
    152       if (!this.causedUpdateOfShapeInfo) {
    153         IShape shape = this.shapeMapping.GetByFirst(shapeInfo);
    154         shape.Location = shapeInfo.Location;
     307    private void graphVisualization_OnEntityAdded(object sender, EntityEventArgs e) {
     308      IConnection connection = e.Entity as IConnection;
     309      if (connection != null && !this.connectionConnectorsMapping.ContainsFirst(connection)) {
     310        if (connection.From.AttachedTo == null || connection.To.AttachedTo == null)
     311          this.RemoveConnection(connection);
    155312      }
    156313    }
    157314
    158315    private void graphVisualization_OnEntityRemoved(object sender, EntityEventArgs e) {
    159       IShape shape = (IShape)e.Entity;
    160       if (this.shapeMapping.ContainsSecond(shape)) {
    161         IShapeInfo shapeInfo = this.shapeMapping.GetBySecond(shape);
     316      IShape shape = e.Entity as IShape;
     317      if (shape != null && this.shapeInfoShapeMapping.ContainsSecond(shape)) {
     318        IShapeInfo shapeInfo = this.shapeInfoShapeMapping.GetBySecond(shape);
    162319        this.VisualizationInfo.RemoveShapeInfo(shapeInfo);
    163320      }
    164     }
    165 
    166 
    167 
    168 
    169     //protected override void OnContentChanged() {
    170     //  base.OnContentChanged();
    171     //  this.ClearGraph();
    172 
    173     //  this.CreateGraph(null, new OperatorParameter(string.Empty, this.Content));
    174     //  foreach (IShape shape in this.operatorShapeMapping.Values)
    175     //    this.GraphModel.AddShape(shape);
    176 
    177     //  foreach (IConnection connection in this.connectionMapping.Values)
    178     //    this.GraphModel.AddConnection(connection);
    179 
    180     //  if (this.Content == null)
    181     //    this.graphVisualization.Controller.Model.LayoutRoot = null;
    182     //  else
    183     //    this.graphVisualization.Controller.Model.LayoutRoot = this.operatorShapeMapping[this.Content];
    184     //  this.RelayoutOperatorGraph();
    185     //}
    186 
    187     //private void opParam_ValueChanged(object sender, EventArgs e) {
    188     //  if (InvokeRequired)
    189     //    Invoke(new EventHandler(opParam_ValueChanged), sender, e);
    190     //  else {
    191     //    this.OnContentChanged();
    192     //  }
    193     //}
    194 
    195     //private void ClearGraph() {
    196     //  this.GraphModel.Clear();
    197     //  foreach (IValueParameter<IOperator> opParam in this.parameters)
    198     //    opParam.ValueChanged -= opParam_ValueChanged;
    199 
    200     //  this.operatorShapeMapping.Clear();
    201     //  this.parameters.Clear();
    202     //  this.connectionMapping.Clear();
    203     //}
    204 
    205 
    206 
    207     //private void CreateGraph(IOperator parent, IValueParameter<IOperator> op) {
    208     //  if (op == null || op.Value == null)
    209     //    return;
    210 
    211     //  IShape shape;
    212     //  if (!this.operatorShapeMapping.ContainsKey(op.Value)) {
    213     //    //shape = GraphVisualizationInfo.CreateShape(op.Value);
    214     //    //this.operatorShapeMapping[op.Value] = shape;
    215 
    216     //    foreach (IParameter param in op.Value.Parameters) {
    217     //      IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>;
    218     //      if (opParam != null) {
    219     //        HandleOperatorParameter(opParam);
    220     //        this.CreateGraph(op.Value, opParam);
    221     //      }
    222     //    }
    223     //  }
    224 
    225     //  if (parent != null) {
    226     //    IShape from = this.operatorShapeMapping[parent];
    227     //    IShape to = this.operatorShapeMapping[op.Value];
    228     //    //IConnection connection = GraphVisualizationInfo.CreateConnection(from,to);
    229     //    //this.connectionMapping[new KeyValuePair<IOperator, IValueParameter<IOperator>>(parent, op)] = connection;
    230     //  }
    231     //}
    232 
    233     //private void DeleteGraph(IOperator parent, IValueParameter<IOperator> op) {
    234 
    235     //}
    236 
    237     //private void HandleOperatorParameter(IValueParameter<IOperator> opParam) {
    238     //  if (opParam == null)
    239     //    return;
    240     //  opParam.ValueChanged += new EventHandler(opParam_ValueChanged);
    241     //  parameters.Add(opParam);
    242     //}
    243 
    244     //private void Model_OnEntityRemoved(object sender, EntityEventArgs e) {
    245     //  IShape shape = e.Entity as IShape;
    246     //  if (shape != null) {
    247     //    IOperator op = operatorShapeMapping.Where(os => os.Value == shape).First().Key;
    248     //    if (op == this.Content)
    249     //      this.Content = null;
    250     //    else {
    251     //      //clear all connections to the removed operator
    252     //      IEnumerable<IValueParameter<IOperator>> parentOperator = this.connectionMapping.Where(cs => cs.Key.Value.Value == op).Select(x => x.Key.Value);
    253     //      foreach (IValueParameter<IOperator> opParam in parentOperator.ToArray())
    254     //        opParam.Value = null;
    255 
    256     //      //remove connections from graph view
    257     //      IEnumerable<IConnection> connections = this.connectionMapping.Where(cs => cs.Key.Value.Value == op).Select(x => x.Value);
    258     //      foreach (IConnection connection in connections)
    259     //        this.GraphModel.Remove(connection);
    260 
    261     //      this.graphVisualization.Invalidate();
    262     //    }
    263 
    264 
    265     //  }
    266     //}
     321
     322      IConnection connection = e.Entity as IConnection;
     323      if (connection != null && this.connectionConnectorsMapping.ContainsFirst(connection)) {
     324        IShape parentShape = this.connectorShapeMapping[connection.From.AttachedTo];
     325        IShapeInfo shapeInfo = this.shapeInfoShapeMapping.GetBySecond(parentShape);
     326        string parameterName = connection.From.AttachedTo.Name;
     327
     328        shapeInfo.RemoveConnection(parameterName);
     329      }
     330    }
    267331
    268332    #region methods for toolbar items
    269333
     334    private int layoutCount = 0;
    270335    internal void RelayoutOperatorGraph() {
    271       //if (this.operatorShapeMapping.Count > 0 && this.connectionMapping.Count > 0) { //otherwise the layout does not work
    272       this.graphVisualization.Controller.RunActivity("Standard TreeLayout");
    273       this.graphVisualization.Invalidate();
    274       //}
     336      if (this.shapeInfoShapeMapping.Count > 0 && this.connectionConnectorsMapping.Count > 0) { //otherwise the layout does not work
     337
     338        string layoutName = string.Empty;
     339        switch (this.layoutCount % 6) {
     340          case 0: { layoutName = "Random Layout"; break; }
     341          case 1: { layoutName = "FruchtermanReingold Layout"; break; }
     342          case 2: { layoutName = "Standard TreeLayout"; break; }
     343          case 3: { layoutName = "Radial TreeLayout"; break; }
     344          case 4: { layoutName = "Balloon TreeLayout"; break; }
     345          case 5: { layoutName = "ForceDirected Layout"; break; }
     346        }
     347        this.graphVisualization.Controller.RunActivity(layoutName);
     348        MessageBox.Show(layoutName);
     349        this.layoutCount++;
     350        this.graphVisualization.Invalidate();
     351      }
     352    }
     353
     354    internal void ActivateConnectionTool() {
     355      this.graphVisualization.Controller.ActivateTool(ControllerBase.ConnectionToolName);
    275356    }
    276357
     
    309390      if (e.Effect != DragDropEffects.None) {
    310391        IOperator op = e.Data.GetData("Value") as IOperator;
    311         IShapeInfo shapeInfo = ShapeInfoFactory.CreateShapeInfo(op);
     392        IShapeInfo shapeInfo = Factory.CreateShapeInfo(op);
    312393        Point controlCoordinates = this.PointToClient(new Point(e.X, e.Y));
    313394        PointF viewCoordinates = this.graphVisualization.Controller.View.DeviceToView(controlCoordinates);
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/ToolBarItems/ConnectionToolBarItem.cs

    r2853 r2861  
    2525
    2626namespace HeuristicLab.Operators.Views.GraphVisualization {
    27   internal class PanToolBarItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem, HeuristicLab.Optimizer.IOptimizerUserInterfaceItemProvider {
     27  internal class ConnectionToolBarItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem, HeuristicLab.Optimizer.IOptimizerUserInterfaceItemProvider {
    2828    public override string Name {
    29       get { return "Pan"; }
     29      get { return "Connection"; }
    3030    }
    3131
    3232    public override string ToolTipText {
    33       get { return "Pan"; }
     33      get { return "Connection"; }
    3434    }
    3535    public override int Position {
    36       get { return 130; }
     36      get { return 140; }
    3737    }
    3838    public override Image Image {
    39       get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Macro; }
     39      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Add; }
    4040    }
    4141
     
    4848      OperatorGraphView view = MainFormManager.MainForm.ActiveView as OperatorGraphView;
    4949      if (view != null)
    50         view.ActivatePanTool();
     50        view.ActivateConnectionTool();
    5151    }
    5252  }
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/ToolBarItems/ZoomInToolBarItem.cs

    r2853 r2861  
    3434    }
    3535    public override int Position {
    36       get { return 141; }
     36      get { return 151; }
    3737    }
    3838    public override Image Image {
    39       get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Sort; }
     39      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.ArrowUp; }
    4040    }
    4141
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/ToolBarItems/ZoomOutToolBarItem.cs

    r2853 r2861  
    3434    }
    3535    public override int Position {
    36       get { return 142; }
     36      get { return 152; }
    3737    }
    3838    public override Image Image {
    39       get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.SortUp; }
     39      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.ArrowDown; }
    4040    }
    4141
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/ToolBarItems/ZoomToolBarItem.cs

    r2853 r2861  
    3434    }
    3535    public override int Position {
    36       get { return 140; }
     36      get { return 150; }
    3737    }
    3838    public override Image Image {
Note: See TracChangeset for help on using the changeset viewer.