Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/25/16 16:48:19 (8 years ago)
Author:
jlodewyc
Message:

#2582 RC2 migration fixed. OKB query implemented. Preparing for OKB manager

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/WebJobManager/HeuristicLab.Operators.Views.GraphVisualization.Views/3.3/ShapeInfoExtensions.cs

    r12012 r13860  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using Netron.Diagramming.Core;
    2625
    27 namespace HeuristicLab.Operators.Views.GraphVisualization.Views {
    28   internal static class ShapeInfoExtensions {
    29     public static IShape CreateShape(this IShapeInfo shapeInfo) {
    30       if (shapeInfo is IOperatorShapeInfo) return CreateShape((IOperatorShapeInfo)shapeInfo);
    31       throw new ArgumentException("Could not determine which shape object should be created.");
     26namespace HeuristicLab.Operators.Views.GraphVisualization.Views
     27{
     28    internal static class ShapeInfoExtensions
     29    {
     30        public static IShape CreateShape(this IShapeInfo shapeInfo)
     31        {
     32            if (shapeInfo is IOperatorShapeInfo) return CreateShape((IOperatorShapeInfo)shapeInfo);
     33            throw new ArgumentException("Could not determine which shape object should be created.");
     34        }
     35
     36        public static void UpdateShape(this IShapeInfo shapeInfo, IShape shape)
     37        {
     38            shape.Location = shapeInfo.Location;
     39            if (shapeInfo is IOperatorShapeInfo && shape is OperatorShape)
     40                UpdateShape((IOperatorShapeInfo)shapeInfo, (OperatorShape)shape);
     41        }
     42
     43        public static void UpdateShapeInfo(this IShapeInfo shapeInfo, IShape shape)
     44        {
     45            shapeInfo.Location = shape.Location;
     46            if (shapeInfo is IOperatorShapeInfo && shape is OperatorShape)
     47                UpdateShapeInfo((IOperatorShapeInfo)shapeInfo, (OperatorShape)shape);
     48        }
     49
     50        #region OperatorShapeInfo specific methos
     51        public static OperatorShape CreateShape(IOperatorShapeInfo shapeInfo)
     52        {
     53            OperatorShape shape = new OperatorShape();
     54            shape.Tag = shapeInfo;
     55            shape.Location = shapeInfo.Location;
     56            shape.Title = shapeInfo.Title;
     57            shape.Subtitle = shapeInfo.TypeName;
     58            shape.Color = shapeInfo.Color;
     59            shape.LineColor = shapeInfo.LineColor;
     60            shape.LineWidth = shapeInfo.LineWidth;
     61            shape.Icon = shapeInfo.Icon;
     62            shape.Collapsed = shapeInfo.Collapsed;
     63            foreach (string connectorName in shapeInfo.Connectors)
     64                if (connectorName != OperatorShapeInfoFactory.SuccessorConnector && connectorName != OperatorShapeInfoFactory.PredecessorConnector)
     65                    shape.AddConnector(connectorName);
     66
     67            shape.UpdateLabels(shapeInfo.Labels);
     68            return shape;
     69        }
     70
     71        public static void UpdateShape(IOperatorShapeInfo operatorShapeInfo, OperatorShape operatorShape)
     72        {
     73            operatorShape.Title = operatorShapeInfo.Title;
     74            operatorShape.Subtitle = operatorShapeInfo.TypeName;
     75            operatorShape.Color = operatorShapeInfo.Color;
     76            operatorShape.LineColor = operatorShapeInfo.LineColor;
     77            operatorShape.LineWidth = operatorShapeInfo.LineWidth;
     78            operatorShape.Icon = operatorShapeInfo.Icon;
     79            operatorShape.Collapsed = operatorShapeInfo.Collapsed;
     80
     81            int i = 0;
     82            int j = 0;
     83            //remove old connectors and skip correct connectors
     84            List<string> oldConnectorNames = operatorShape.AdditionalConnectorNames.ToList();
     85            while (i < operatorShapeInfo.Connectors.Count() && j < oldConnectorNames.Count)
     86            {
     87                if (operatorShapeInfo.Connectors.ElementAt(i) == OperatorShapeInfoFactory.SuccessorConnector ||
     88                  operatorShapeInfo.Connectors.ElementAt(i) == OperatorShapeInfoFactory.PredecessorConnector)
     89                    i++;
     90                else if (oldConnectorNames[j] == OperatorShapeInfoFactory.SuccessorConnector ||
     91                  oldConnectorNames[j] == OperatorShapeInfoFactory.PredecessorConnector)
     92                    j++;
     93                else if (operatorShapeInfo.Connectors.ElementAt(i) != oldConnectorNames[j])
     94                {
     95                    operatorShape.RemoveConnector(oldConnectorNames[j]);
     96                    j++;
     97                }
     98                else
     99                {
     100                    i++;
     101                    j++;
     102                }
     103            }
     104            //remove remaining old connectors
     105            for (; j < oldConnectorNames.Count; j++)
     106                operatorShape.RemoveConnector(oldConnectorNames[j]);
     107
     108            //add new connectors except successor and connector
     109            for (; i < operatorShapeInfo.Connectors.Count(); i++)
     110                if (operatorShapeInfo.Connectors.ElementAt(i) != OperatorShapeInfoFactory.SuccessorConnector &&
     111                  operatorShapeInfo.Connectors.ElementAt(i) != OperatorShapeInfoFactory.PredecessorConnector)
     112                    operatorShape.AddConnector(operatorShapeInfo.Connectors.ElementAt(i));
     113
     114            operatorShape.UpdateLabels(operatorShapeInfo.Labels);
     115        }
     116
     117        public static void UpdateShapeInfo(IOperatorShapeInfo operatorShapeInfo, OperatorShape operatorShape)
     118        {
     119            operatorShapeInfo.Title = operatorShape.Title;
     120            operatorShapeInfo.TypeName = operatorShape.Subtitle;
     121            operatorShapeInfo.Color = operatorShape.Color;
     122            operatorShapeInfo.LineColor = operatorShape.LineColor;
     123            operatorShapeInfo.LineWidth = operatorShape.LineWidth;
     124            operatorShapeInfo.Icon = operatorShape.Icon;
     125            operatorShapeInfo.Collapsed = operatorShape.Collapsed;
     126        }
     127        #endregion
    32128    }
    33 
    34     public static void UpdateShape(this IShapeInfo shapeInfo, IShape shape) {
    35       shape.Location = shapeInfo.Location;
    36       if (shapeInfo is IOperatorShapeInfo && shape is OperatorShape)
    37         UpdateShape((IOperatorShapeInfo)shapeInfo, (OperatorShape)shape);
    38     }
    39 
    40     public static void UpdateShapeInfo(this IShapeInfo shapeInfo, IShape shape) {
    41       shapeInfo.Location = shape.Location;
    42       if (shapeInfo is IOperatorShapeInfo && shape is OperatorShape)
    43         UpdateShapeInfo((IOperatorShapeInfo)shapeInfo, (OperatorShape)shape);
    44     }
    45 
    46     #region OperatorShapeInfo specific methos
    47     public static OperatorShape CreateShape(IOperatorShapeInfo shapeInfo) {
    48       OperatorShape shape = new OperatorShape();
    49       shape.Tag = shapeInfo;
    50       shape.Location = shapeInfo.Location;
    51       shape.Title = shapeInfo.Title;
    52       shape.Subtitle = shapeInfo.TypeName;
    53       shape.Color = shapeInfo.Color;
    54       shape.LineColor = shapeInfo.LineColor;
    55       shape.LineWidth = shapeInfo.LineWidth;
    56       shape.Icon = shapeInfo.Icon;
    57       shape.Collapsed = shapeInfo.Collapsed;
    58       foreach (string connectorName in shapeInfo.Connectors)
    59         if (connectorName != OperatorShapeInfoFactory.SuccessorConnector && connectorName != OperatorShapeInfoFactory.PredecessorConnector)
    60           shape.AddConnector(connectorName);
    61 
    62       shape.UpdateLabels(shapeInfo.Labels);
    63       return shape;
    64     }
    65 
    66     public static void UpdateShape(IOperatorShapeInfo operatorShapeInfo, OperatorShape operatorShape) {
    67       operatorShape.Title = operatorShapeInfo.Title;
    68       operatorShape.Subtitle = operatorShapeInfo.TypeName;
    69       operatorShape.Color = operatorShapeInfo.Color;
    70       operatorShape.LineColor = operatorShapeInfo.LineColor;
    71       operatorShape.LineWidth = operatorShapeInfo.LineWidth;
    72       operatorShape.Icon = operatorShapeInfo.Icon;
    73       operatorShape.Collapsed = operatorShapeInfo.Collapsed;
    74 
    75       int i = 0;
    76       int j = 0;
    77       //remove old connectors and skip correct connectors
    78       List<string> oldConnectorNames = operatorShape.AdditionalConnectorNames.ToList();
    79       while (i < operatorShapeInfo.Connectors.Count() && j < oldConnectorNames.Count) {
    80         if (operatorShapeInfo.Connectors.ElementAt(i) == OperatorShapeInfoFactory.SuccessorConnector ||
    81           operatorShapeInfo.Connectors.ElementAt(i) == OperatorShapeInfoFactory.PredecessorConnector)
    82           i++;
    83         else if (oldConnectorNames[j] == OperatorShapeInfoFactory.SuccessorConnector ||
    84           oldConnectorNames[j] == OperatorShapeInfoFactory.PredecessorConnector)
    85           j++;
    86         else if (operatorShapeInfo.Connectors.ElementAt(i) != oldConnectorNames[j]) {
    87           operatorShape.RemoveConnector(oldConnectorNames[j]);
    88           j++;
    89         } else {
    90           i++;
    91           j++;
    92         }
    93       }
    94       //remove remaining old connectors
    95       for (; j < oldConnectorNames.Count; j++)
    96         operatorShape.RemoveConnector(oldConnectorNames[j]);
    97 
    98       //add new connectors except successor and connector
    99       for (; i < operatorShapeInfo.Connectors.Count(); i++)
    100         if (operatorShapeInfo.Connectors.ElementAt(i) != OperatorShapeInfoFactory.SuccessorConnector &&
    101           operatorShapeInfo.Connectors.ElementAt(i) != OperatorShapeInfoFactory.PredecessorConnector)
    102           operatorShape.AddConnector(operatorShapeInfo.Connectors.ElementAt(i));
    103 
    104       operatorShape.UpdateLabels(operatorShapeInfo.Labels);
    105     }
    106 
    107     public static void UpdateShapeInfo(IOperatorShapeInfo operatorShapeInfo, OperatorShape operatorShape) {
    108       operatorShapeInfo.Title = operatorShape.Title;
    109       operatorShapeInfo.TypeName = operatorShape.Subtitle;
    110       operatorShapeInfo.Color = operatorShape.Color;
    111       operatorShapeInfo.LineColor = operatorShape.LineColor;
    112       operatorShapeInfo.LineWidth = operatorShape.LineWidth;
    113       operatorShapeInfo.Icon = operatorShape.Icon;
    114       operatorShapeInfo.Collapsed = operatorShape.Collapsed;
    115     }
    116     #endregion
    117   }
    118129}
Note: See TracChangeset for help on using the changeset viewer.