Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Operators.Views.GraphVisualization.Views/3.3/ShapeInfoExtensions.cs @ 15617

Last change on this file since 15617 was 13860, checked in by jlodewyc, 8 years ago

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

File size: 5.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25
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
128    }
129}
Note: See TracBrowser for help on using the repository browser.