Example #1
0
 public static ConnectorInfo Create(ConnectorOrientation orientation, Point hotspotPosition)
 {
     return new ConnectorInfo
     {
         Orientation = orientation,
         HotspotPosition = hotspotPosition
     };
 }
        public List<Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation)
        {
            var lineStart = GetOffsetPoint(source.HotspotPosition, source.Orientation, SmallMargin);
            var lineStartOffset = GetOffsetPoint(lineStart, source.Orientation, Margin);

            var lineEnd = sinkPoint;

            return new List<Point>{lineStart, lineStartOffset, lineEnd};
        }
Example #3
0
 public ConnectorInfo ConnectorInfo(ConnectorOrientation orientation, double left, double top, Point position)
 {
     return(new ConnectorInfo()
     {
         Orientation = orientation,
         DesignerItemSize = new Size(DesignerItemViewModelBase.ItemWidth, DesignerItemViewModelBase.ItemHeight),
         DesignerItemLeft = left,
         DesignerItemTop = top,
         Position = position
     });
 }
Example #4
0
 public ConnectorInfo ConnectorInfo(ConnectorOrientation orientation, double left, double top, Point position)
 {
     return(new ConnectorInfo()
     {
         Orientation = orientation,
         DesignerItemSize = new Size(sourceConnectorInfo.DataItem.ItemWidth, sourceConnectorInfo.DataItem.ItemHeight),
         DesignerItemLeft = left,
         DesignerItemTop = top,
         Position = position
     });
 }
        public List<Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation)
        {
            List<Point> linePoints = new List<Point>();
            //Rect rectSource = PathFinderHelper.GetRectWithMargin(source, 0);
            //Point startPoint = PathFinderHelper.GetOffsetPoint(source, rectSource);
            //Point endPoint = sinkPoint;

            linePoints.Add(source.Position);
            linePoints.Add(sinkPoint);

            return linePoints;
        }
        public List <Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation)
        {
            List <Point> linePoints = new List <Point>();

            //Rect rectSource = PathFinderHelper.GetRectWithMargin(source, 0);
            //Point startPoint = PathFinderHelper.GetOffsetPoint(source, rectSource);
            //Point endPoint = sinkPoint;

            linePoints.Add(source.Position);
            linePoints.Add(sinkPoint);

            return(linePoints);
        }
        protected void CreateOutput(int outputNumber,
                                    ConnectorOrientation orientation, Vector2 position)
        {
            if (outputNumber >= OutCount)
            {
                throw new IndexOutOfRangeException();
            }
            var connector = new Connector(SimpleShader, orientation, ConnectorType.Output);

            connector.Translate            = position;
            OutputConnectors[outputNumber] = connector;
            Childrens.Add(connector);
        }
 private static Point GetOffsetPoint(Point point, ConnectorOrientation orientation, int offset)
 {
     switch (orientation)
     {
         case ConnectorOrientation.Left:
             point.Offset(-offset, 0);
             return point;
         case ConnectorOrientation.Right:
             point.Offset(offset, 0);
             return point;
         default:
             throw new ArgumentOutOfRangeException("orientation");
     }
 }
Example #9
0
        public Connector(SimpleShader simpleShader, ConnectorOrientation orientation, ConnectorType type)
            : base(simpleShader)
        {
            Orientation = orientation;
            Type        = type;
            InstasingList.Add(new VisualUniforms(Color4.Black));
            var vertices = new List <Vector2>();

            vertices.AddRange(Circle(new Vector2(0, 0), 3, 12));
            vertices.AddRange(Line(new Vector2(0, 0), new Vector2(Delta, 0), 2));
            switch (Type)
            {
            case ConnectorType.Input:
                vertices.AddRange(Polyline(new[]
                {
                    new Vector2(Delta / 2, Delta * 0.3f),
                    new Vector2(Delta * 0.9f, 0),
                    new Vector2(Delta / 2, -Delta * 0.3f),
                }, 2));
                break;

            case ConnectorType.Output:
                vertices.AddRange(Polyline(new[]
                {
                    new Vector2(Delta / 2, Delta * 0.3f),
                    new Vector2(Delta * 0.1f, 0),
                    new Vector2(Delta / 2, -Delta * 0.3f),
                }, 2));
                break;
            }
            Shape = vertices.ToArray();
            switch (Orientation)
            {
            case ConnectorOrientation.Left:
                Rotate = (float)0;
                break;

            case ConnectorOrientation.Top:
                Rotate = (float)Math.PI * 3 / 2;
                break;

            case ConnectorOrientation.Right:
                Rotate = (float)Math.PI;
                break;

            case ConnectorOrientation.Bottom:
                Rotate = (float)Math.PI / 2;
                break;
            }
        }
Example #10
0
        private void LoadPerstistDesignerItems(IDiagramItem wholeDiagramToLoad, IDiagramViewModel diagramViewModel)
        {
            //load diagram items
            foreach (DiagramItemData diagramItemData in wholeDiagramToLoad.DesignerItems)
            {
                if (diagramItemData.ItemType == typeof(PersistDesignerItem))
                {
                    PersistDesignerItem          persistedDesignerItem        = databaseAccessService.FetchPersistDesignerItem(diagramItemData.ItemId);
                    PersistDesignerItemViewModel persistDesignerItemViewModel =
                        new PersistDesignerItemViewModel(persistedDesignerItem.Id, diagramViewModel, persistedDesignerItem.Left, persistedDesignerItem.Top, persistedDesignerItem.ItemWidth, persistedDesignerItem.ItemHeight, persistedDesignerItem.HostUrl);
                    diagramViewModel.Items.Add(persistDesignerItemViewModel);
                }
                if (diagramItemData.ItemType == typeof(SettingsDesignerItem))
                {
                    SettingsDesignerItem          settingsDesignerItem          = databaseAccessService.FetchSettingsDesignerItem(diagramItemData.ItemId);
                    SettingsDesignerItemViewModel settingsDesignerItemViewModel =
                        new SettingsDesignerItemViewModel(settingsDesignerItem.Id, diagramViewModel, settingsDesignerItem.Left, settingsDesignerItem.Top, settingsDesignerItem.ItemWidth, settingsDesignerItem.ItemHeight, settingsDesignerItem.Setting1);
                    diagramViewModel.Items.Add(settingsDesignerItemViewModel);
                }
                if (diagramItemData.ItemType == typeof(GroupDesignerItem))
                {
                    GroupDesignerItem             groupDesignerItem             = databaseAccessService.FetchGroupingDesignerItem(diagramItemData.ItemId);
                    GroupingDesignerItemViewModel groupingDesignerItemViewModel =
                        new GroupingDesignerItemViewModel(groupDesignerItem.Id, diagramViewModel, groupDesignerItem.Left, groupDesignerItem.Top, groupDesignerItem.ItemWidth, groupDesignerItem.ItemHeight);
                    if (groupDesignerItem.DesignerItems != null && groupDesignerItem.DesignerItems.Count > 0)
                    {
                        LoadPerstistDesignerItems(groupDesignerItem, groupingDesignerItemViewModel);
                    }
                    diagramViewModel.Items.Add(groupingDesignerItemViewModel);
                }
            }
            //load connection items
            foreach (int connectionId in wholeDiagramToLoad.ConnectionIds)
            {
                Connection connection = databaseAccessService.FetchConnection(connectionId);

                DesignerItemViewModelBase sourceItem = GetConnectorDataItem(diagramViewModel, connection.SourceId, connection.SourceType);
                ConnectorOrientation      sourceConnectorOrientation = GetOrientationForConnector(connection.SourceOrientation);
                FullyCreatedConnectorInfo sourceConnectorInfo        = GetFullConnectorInfo(connection.Id, sourceItem, sourceConnectorOrientation);

                DesignerItemViewModelBase sinkItem = GetConnectorDataItem(diagramViewModel, connection.SinkId, connection.SinkType);
                ConnectorOrientation      sinkConnectorOrientation = GetOrientationForConnector(connection.SinkOrientation);
                FullyCreatedConnectorInfo sinkConnectorInfo        = GetFullConnectorInfo(connection.Id, sinkItem, sinkConnectorOrientation);

                ConnectorViewModel connectionVM = new ConnectorViewModel(connection.Id, diagramViewModel, sourceConnectorInfo, sinkConnectorInfo);
                diagramViewModel.Items.Add(connectionVM);
            }
        }
Example #11
0
        private Orientation GetOrientationFromConnector(ConnectorOrientation connectorOrientation)
        {
            Orientation result = Orientation.None;

            switch (connectorOrientation)
            {
            case ConnectorOrientation.Left:
                result = Orientation.Left;
                break;

            case ConnectorOrientation.Right:
                result = Orientation.Right;
                break;
            }
            return(result);
        }
Example #12
0
 public static ConnectorOrientation GetOpositeOrientation(ConnectorOrientation connectorOrientation)
 {
     switch (connectorOrientation)
     {
         case ConnectorOrientation.Left:
             return ConnectorOrientation.Right;
         case ConnectorOrientation.Top:
             return ConnectorOrientation.Bottom;
         case ConnectorOrientation.Right:
             return ConnectorOrientation.Left;
         case ConnectorOrientation.Bottom:
             return ConnectorOrientation.Top;
         default:
             return ConnectorOrientation.Top;
     }
 }
Example #13
0
        private ConnectorOrientation GetOrientationForConnector(Orientation persistedOrientation)
        {
            ConnectorOrientation result = ConnectorOrientation.None;

            switch (persistedOrientation)
            {
            case Orientation.Left:
                result = ConnectorOrientation.Left;
                break;

            case Orientation.Right:
                result = ConnectorOrientation.Right;
                break;
            }
            return(result);
        }
Example #14
0
        /// <summary>
        /// Получить точки углов охватывающей элемент рамки
        /// </summary>
        /// <param name="orientation">Левосторонный или правосторонний вывод</param>
        /// <param name="rect">Рамка, охватывающая элемент</param>
        /// <param name="n1">Точка угла 1</param>
        /// <param name="n2">Точка угла 2</param>
        private static void GetNeighborCorners(ConnectorOrientation orientation, Rect rect, out Point n1, out Point n2)
        {
            switch (orientation)
            {
            case ConnectorOrientation.LEFT:
                n1 = rect.TopLeft; n2 = rect.BottomLeft;
                break;

            case ConnectorOrientation.RIGHT:
                n1 = rect.TopRight; n2 = rect.BottomRight;
                break;

            default:
                n1 = rect.TopRight; n2 = rect.BottomRight;
                break;
            }
        }
Example #15
0
        private static Orientation GetOrientation(ConnectorOrientation sourceOrientation)
        {
            switch (sourceOrientation)
            {
            case ConnectorOrientation.Left:
                return(Orientation.Horizontal);

            case ConnectorOrientation.Top:
                return(Orientation.Vertical);

            case ConnectorOrientation.Right:
                return(Orientation.Horizontal);

            case ConnectorOrientation.Bottom:
                return(Orientation.Vertical);

            default:
                throw new Exception("Unknown ConnectorOrientation");
            }
        }
Example #16
0
        private static ConnectorOrientation GetOpositeOrientation(ConnectorOrientation connectorOrientation)
        {
            switch (connectorOrientation)
            {
            case ConnectorOrientation.Left:
                return(ConnectorOrientation.Right);

            case ConnectorOrientation.Top:
                return(ConnectorOrientation.Bottom);

            case ConnectorOrientation.Right:
                return(ConnectorOrientation.Left);

            case ConnectorOrientation.Bottom:
                return(ConnectorOrientation.Top);

            default:
                return(ConnectorOrientation.Top);
            }
        }
Example #17
0
        private Node CalculateOrientationNode(ConnectorOrientation orientation, IInput item)
        {
            switch (orientation)
            {
            case ConnectorOrientation.Left:
                return(new Node(item.X, item.Y + item.Height / 2));

            case ConnectorOrientation.Right:
                return(new Node(item.Right, item.Y + item.Height / 2));

            case ConnectorOrientation.Top:
                return(new Node(item.X + item.Width / 2, item.Y));

            case ConnectorOrientation.Bottom:
                return(new Node(item.X + item.Width / 2, item.Bottom));

            default:
                return(null);
            }
        }
Example #18
0
        /// <summary>
        /// Gets the hit test information for provided orientation
        /// </summary>
        /// <param name="orientation">The orientation.</param>
        /// <returns></returns>
        private HitTestInfo GetHitTestInfo(ConnectorOrientation orientation)
        {
            switch (orientation)
            {
            case ConnectorOrientation.Left:
                return(HitTestInfo.AnchorLeft);

            case ConnectorOrientation.Top:
                return(HitTestInfo.AnchorTop);

            case ConnectorOrientation.Right:
                return(HitTestInfo.AnchorRight);

            case ConnectorOrientation.Bottom:
                return(HitTestInfo.AnchorBottom);

            default:
                throw new ArgumentOutOfRangeException(nameof(orientation), orientation, null);
            }
        }
Example #19
0
        protected static void GetOppositeCorners(ConnectorOrientation orientation, Rect rect, out Point n1, out Point n2)
        {
            switch (orientation)
            {
            case ConnectorOrientation.Left:
                n1 = rect.TopRight; n2 = rect.BottomRight;
                break;

            case ConnectorOrientation.Top:
                n1 = rect.BottomLeft; n2 = rect.BottomRight;
                break;

            case ConnectorOrientation.Right:
                n1 = rect.TopLeft; n2 = rect.BottomLeft;
                break;

            case ConnectorOrientation.Bottom:
                n1 = rect.TopLeft; n2 = rect.TopRight;
                break;

            default:
                throw new Exception("No opposite corners found!");
            }
        }
Example #20
0
        internal static PathGeometry GetPathGeometry(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation)
        {
            var rectSource = GetRectWithMargin(source, 0);
            var startPoint = GetOffsetPoint(source, rectSource);
            var endPoint = sinkPoint;

            var midpoint = CalculateMidpoint(startPoint, new Point(endPoint.X, startPoint.Y));
            var distance = CalculateDistance(startPoint, midpoint);

            var p1 = CalculateEndpoint(startPoint, distance, GetAngel(source.Orientation));
            var p2 = CalculateEndpoint(endPoint, distance, GetAngel(preferredOrientation));
            var p3 = endPoint;

            var geometry = new PathGeometry();

            var pathFigure = new PathFigure();
            pathFigure.StartPoint = startPoint;
            geometry.Figures.Add(pathFigure);

            var bs = new BezierSegment(p1, p2, p3, true);
            pathFigure.Segments.Add(bs);

            return geometry;
        }
Example #21
0
        private static void GetNeighborCorners(ConnectorOrientation orientation, Rect rect, out Point n1, out Point n2)
        {
            switch (orientation)
            {
            case ConnectorOrientation.Left:
                n1 = rect.TopLeft; n2 = rect.BottomLeft;
                break;

            case ConnectorOrientation.Top:
                n1 = rect.TopLeft; n2 = rect.TopRight;
                break;

            case ConnectorOrientation.Right:
                n1 = rect.TopRight; n2 = rect.BottomRight;
                break;

            case ConnectorOrientation.Bottom:
                n1 = rect.BottomLeft; n2 = rect.BottomRight;
                break;

            default:
                throw new Exception("No neighour corners found!");
            }
        }
Example #22
0
        private static List <Point> OptimizeLinePoints(List <Point> linePoints, Rect[] rectangles, ConnectorOrientation sourceOrientation, ConnectorOrientation sinkOrientation)
        {
            List <Point> points = new List <Point>();
            int          cut    = 0;

            for (int i = 0; i < linePoints.Count; i++)
            {
                if (i >= cut)
                {
                    for (int k = linePoints.Count - 1; k > i; k--)
                    {
                        if (IsPointVisible(linePoints[i], linePoints[k], rectangles))
                        {
                            cut = k;
                            break;
                        }
                    }
                    points.Add(linePoints[i]);
                }
            }

            #region Line
            for (int j = 0; j < points.Count - 1; j++)
            {
                if (points[j].X != points[j + 1].X && points[j].Y != points[j + 1].Y)
                {
                    ConnectorOrientation orientationFrom;
                    ConnectorOrientation orientationTo;

                    // orientation from point
                    if (j == 0)
                    {
                        orientationFrom = sourceOrientation;
                    }
                    else
                    {
                        orientationFrom = GetOrientation(points[j], points[j - 1]);
                    }

                    // orientation to pint
                    if (j == points.Count - 2)
                    {
                        orientationTo = sinkOrientation;
                    }
                    else
                    {
                        orientationTo = GetOrientation(points[j + 1], points[j + 2]);
                    }


                    if ((orientationFrom == ConnectorOrientation.Left || orientationFrom == ConnectorOrientation.Right) &&
                        (orientationTo == ConnectorOrientation.Left || orientationTo == ConnectorOrientation.Right))
                    {
                        double centerX = Math.Min(points[j].X, points[j + 1].X) + Math.Abs(points[j].X - points[j + 1].X) / 2;
                        points.Insert(j + 1, new Point(centerX, points[j].Y));
                        points.Insert(j + 2, new Point(centerX, points[j + 2].Y));
                        if (points.Count - 1 > j + 3)
                        {
                            points.RemoveAt(j + 3);
                        }
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Top || orientationFrom == ConnectorOrientation.Bottom) &&
                        (orientationTo == ConnectorOrientation.Top || orientationTo == ConnectorOrientation.Bottom))
                    {
                        double centerY = Math.Min(points[j].Y, points[j + 1].Y) + Math.Abs(points[j].Y - points[j + 1].Y) / 2;
                        points.Insert(j + 1, new Point(points[j].X, centerY));
                        points.Insert(j + 2, new Point(points[j + 2].X, centerY));
                        if (points.Count - 1 > j + 3)
                        {
                            points.RemoveAt(j + 3);
                        }
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Left || orientationFrom == ConnectorOrientation.Right) &&
                        (orientationTo == ConnectorOrientation.Top || orientationTo == ConnectorOrientation.Bottom))
                    {
                        points.Insert(j + 1, new Point(points[j + 1].X, points[j].Y));
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Top || orientationFrom == ConnectorOrientation.Bottom) &&
                        (orientationTo == ConnectorOrientation.Left || orientationTo == ConnectorOrientation.Right))
                    {
                        points.Insert(j + 1, new Point(points[j].X, points[j + 1].Y));
                        return(points);
                    }
                }
            }
            #endregion

            return(points);
        }
Example #23
0
 public FullyCreatedConnectorInfo(DesignerElement dataItem, ConnectorOrientation orientation)
     : base(orientation)
 {
     this.DataItem = dataItem;
 }
Example #24
0
 public Connector(ConnectorOrientation orientation, ConnectorType type)
 {
     this.Orientation      = orientation;
     this.Type             = type;
     this.ConnectionNumber = -1;
 }
Example #25
0
 protected ConnectorInfoBase(ConnectorKind kind, ConnectorOrientation orientation, Type connectorDataType)
 {
     Kind = kind;
     Orientation = orientation;
     ConnectorDataType = connectorDataType;
 }
 public FullyCreatedConnectorInfo(DesignerItemViewModel designerItem, ConnectorKind kind, ConnectorOrientation orientation, Type dataType)
     : base(kind, orientation, dataType)
 {
     DesignerItem = designerItem;
     Visible = true;
 }
Example #27
0
 public List<Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation)
 {
     throw new System.NotImplementedException();
 }
        public ConnectorInfo ConnectorInfo(ConnectorOrientation orientation, double left, double top, Point position)
        {
            return new ConnectorInfo()
            {
                Orientation = orientation,
                DesignerItemSize = new Size(DesignerItemViewModelBase.ItemWidth, DesignerItemViewModelBase.ItemHeight),
                DesignerItemLeft = left,
                DesignerItemTop = top,
                Position = position

            };
        }
 private FullyCreatedConnectorInfo GetFullConnectorInfo(int connectorId, DesignerItemViewModelBase dataItem, ConnectorOrientation connectorOrientation)
 {
     switch(connectorOrientation)
     {
         case ConnectorOrientation.Top:
             return dataItem.TopConnector;
         case ConnectorOrientation.Left:
             return dataItem.LeftConnector;
         case ConnectorOrientation.Right:
             return dataItem.RightConnector;
         case ConnectorOrientation.Bottom:
             return dataItem.BottomConnector;
         default:
             throw new InvalidOperationException($"Found invalid persisted Connector Orientation for Connector Id: {connectorId}");
     }
 }
Example #30
0
        internal static List <Point> GetConnectionLine1(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation)
        {
            List <Point> linePoints = new List <Point>();
            Rect         rectSource = GetRectWithMargin(source, 10);
            Point        startPoint = GetOffsetPoint(source, rectSource);
            Point        endPoint   = sinkPoint;

            linePoints.Add(startPoint);
            Point currentPoint = startPoint;

            if (startPoint.X < sinkPoint.X)
            {
                linePoints.Clear();
                Point p1 = new Point();
                p1.X = startPoint.X + (sinkPoint.X - startPoint.X) / 2;
                p1.Y = startPoint.Y;
                Point p2 = new Point();
                p2.X = sinkPoint.X - (sinkPoint.X - startPoint.X) / 2;
                p2.Y = sinkPoint.Y;
                linePoints.Add(startPoint);
                linePoints.Add(p1);
                linePoints.Add(p2);
                linePoints.Add(sinkPoint);
            }

            if (startPoint.X >= sinkPoint.X)
            {
                linePoints.Clear();
                Point p1 = new Point();
                p1.X = startPoint.X + distance;
                p1.Y = startPoint.Y;
                Point p4 = new Point();
                p4.X = sinkPoint.X - distance;
                p4.Y = sinkPoint.Y;
                Point p2 = new Point();
                p2.X = p1.X;
                p2.Y = sinkPoint.Y - (sinkPoint.Y - startPoint.Y) / 2;
                Point p3 = new Point();
                p3.X = sinkPoint.X - distance;
                p3.Y = p2.Y;
                if (sinkPoint.Y > (source.DesignerItemTop + source.DesignerItemSize.Height))
                {
                    p2.Y = (sinkPoint.Y - (source.DesignerItemTop + source.DesignerItemSize.Height)) / 2 + (source.DesignerItemTop + source.DesignerItemSize.Height);
                    p3.Y = sinkPoint.Y - (sinkPoint.Y - (source.DesignerItemTop + source.DesignerItemSize.Height)) / 2;
                }
                if (sinkPoint.Y < source.DesignerItemTop)
                {
                    p2.Y = source.DesignerItemTop - (source.DesignerItemTop - sinkPoint.Y) / 2;
                    p3.Y = p2.Y;
                }
                linePoints.Add(startPoint);
                linePoints.Add(p1);
                linePoints.Add(p2);
                linePoints.Add(p3);
                linePoints.Add(p4);
                linePoints.Add(sinkPoint);
            }
            return(linePoints);
        }
        private Orientation GetOrientationFromConnector(ConnectorOrientation connectorOrientation)
        {
            Orientation result = Orientation.None;
            switch (connectorOrientation)
            {
                case ConnectorOrientation.Bottom:
                    result = Orientation.Bottom;
                    break;
                case ConnectorOrientation.Left:
                    result = Orientation.Left;
                    break;
                case ConnectorOrientation.Top:
                    result = Orientation.Top;
                    break;
                case ConnectorOrientation.Right:
                    result = Orientation.Right;
                    break;
            }

            return result;
        }
 public FullyCreatedConnectorInfo(DesignerItemViewModelBase dataItem, ConnectorOrientation orientation)
     : base(orientation)
 {
     this.DataItem = dataItem;
 }
 protected ConnectorInfoBase(ConnectorOrientation orientation)
 {
     Orientation = orientation;
 }
Example #34
0
        internal static List<Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation)
        {
            List<Point> linePoints = new List<Point>();
            Rect rectSource = GetRectWithMargin(source, 10);
            Point startPoint = GetOffsetPoint(source, rectSource);
            Point endPoint = sinkPoint;

            linePoints.Add(startPoint);
            Point currentPoint = startPoint;

            if (!rectSource.Contains(endPoint))
            {
                while (true)
                {
                    if (IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource }))
                    {
                        linePoints.Add(endPoint);
                        break;
                    }

                    bool sideFlag;
                    Point n = GetNearestNeighborSource(source, endPoint, rectSource, out sideFlag);
                    linePoints.Add(n);
                    currentPoint = n;

                    if (IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource }))
                    {
                        linePoints.Add(endPoint);
                        break;
                    }
                    else
                    {
                        Point n1, n2;
                        GetOppositeCorners(source.Orientation, rectSource, out n1, out n2);
                        if (sideFlag)
                            linePoints.Add(n1);
                        else
                            linePoints.Add(n2);

                        linePoints.Add(endPoint);
                        break;
                    }
                }
            }
            else
            {
                linePoints.Add(endPoint);
            }

            if (preferredOrientation != ConnectorOrientation.None)
                linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Orientation, preferredOrientation);
            else
                linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Orientation, GetOpositeOrientation(source.Orientation));

            return linePoints;
        }
Example #35
0
 public FullyCreatedConnectorInfo(DesignerItemViewModelBase dataItem, ConnectorOrientation orientation)
     : base(orientation)
 {
     DataItem = dataItem;
 }
Example #36
0
 private static Orientation GetOrientation(ConnectorOrientation sourceOrientation)
 {
     switch (sourceOrientation)
     {
         case ConnectorOrientation.Left:
             return Orientation.Horizontal;
         case ConnectorOrientation.Top:
             return Orientation.Vertical;
         case ConnectorOrientation.Right:
             return Orientation.Horizontal;
         case ConnectorOrientation.Bottom:
             return Orientation.Vertical;
         default:
             throw new Exception("Unknown ConnectorOrientation");
     }
 }
Example #37
0
        private void ExecuteLoadDiagramCommand(object parameter)
        {
            IsBusy = true;
            DiagramItem wholeDiagramToLoad = null;

            if (SavedDiagramId == null)
            {
                messageBoxService.ShowError("You need to select a diagram to load");
                return;
            }

            Task <DiagramViewModel> task = Task.Factory.StartNew <DiagramViewModel>(() =>
            {
                //ensure that itemsToRemove is cleared ready for any new changes within a session
                itemsToRemove = new List <SelectableDesignerItemViewModelBase>();
                DiagramViewModel diagramViewModel = new DiagramViewModel();

                wholeDiagramToLoad = databaseAccessService.FetchDiagram((int)SavedDiagramId.Value);

                //load diagram items
                foreach (DiagramItemData diagramItemData in wholeDiagramToLoad.DesignerItems)
                {
                    if (diagramItemData.ItemType == typeof(PersistDesignerItem))
                    {
                        PersistDesignerItem persistedDesignerItem = databaseAccessService.FetchPersistDesignerItem(diagramItemData.ItemId);
                        PersistDesignerItemViewModel persistDesignerItemViewModel =
                            new PersistDesignerItemViewModel(persistedDesignerItem.Id, diagramViewModel, persistedDesignerItem.Left, persistedDesignerItem.Top, persistedDesignerItem.HostUrl);
                        diagramViewModel.Items.Add(persistDesignerItemViewModel);
                    }
                    if (diagramItemData.ItemType == typeof(SettingsDesignerItem))
                    {
                        SettingsDesignerItem settingsDesignerItem = databaseAccessService.FetchSettingsDesignerItem(diagramItemData.ItemId);
                        SettingsDesignerItemViewModel settingsDesignerItemViewModel =
                            new SettingsDesignerItemViewModel(settingsDesignerItem.Id, diagramViewModel, settingsDesignerItem.Left, settingsDesignerItem.Top, settingsDesignerItem.Setting1);
                        diagramViewModel.Items.Add(settingsDesignerItemViewModel);
                    }
                }
                //load connection items
                foreach (int connectionId in wholeDiagramToLoad.ConnectionIds)
                {
                    Connection connection = databaseAccessService.FetchConnection(connectionId);

                    DesignerItemViewModelBase sourceItem            = GetConnectorDataItem(diagramViewModel, connection.SourceId, connection.SourceType);
                    ConnectorOrientation sourceConnectorOrientation = GetOrientationForConnector(connection.SourceOrientation);
                    FullyCreatedConnectorInfo sourceConnectorInfo   = GetFullConnectorInfo(connection.Id, sourceItem, sourceConnectorOrientation);

                    DesignerItemViewModelBase sinkItem            = GetConnectorDataItem(diagramViewModel, connection.SinkId, connection.SinkType);
                    ConnectorOrientation sinkConnectorOrientation = GetOrientationForConnector(connection.SinkOrientation);
                    FullyCreatedConnectorInfo sinkConnectorInfo   = GetFullConnectorInfo(connection.Id, sinkItem, sinkConnectorOrientation);

                    ConnectorViewModel connectionVM = new ConnectorViewModel(connection.Id, diagramViewModel, sourceConnectorInfo, sinkConnectorInfo);
                    diagramViewModel.Items.Add(connectionVM);
                }

                return(diagramViewModel);
            });

            task.ContinueWith((ant) =>
            {
                this.DiagramViewModel = ant.Result;
                IsBusy = false;
                messageBoxService.ShowInformation(string.Format("Finished loading Diagram Id : {0}", wholeDiagramToLoad.Id));
            }, TaskContinuationOptions.OnlyOnRanToCompletion);
        }
 protected static void GetNeighborCorners(ConnectorOrientation orientation, Rect rect, out Point n1, out Point n2)
 {
     switch (orientation)
     {
         case ConnectorOrientation.Left:
             n1 = rect.TopLeft; n2 = rect.BottomLeft;
             break;
         case ConnectorOrientation.Top:
             n1 = rect.TopLeft; n2 = rect.TopRight;
             break;
         case ConnectorOrientation.Right:
             n1 = rect.TopRight; n2 = rect.BottomRight;
             break;
         case ConnectorOrientation.Bottom:
             n1 = rect.BottomLeft; n2 = rect.BottomRight;
             break;
         default:
             throw new Exception("No neighour corners found!");
     }
 }
Example #39
0
 public SizeToMarginConverter(Point relativePosition, ConnectorOrientation orientation)
 {
     relativePosition_ = relativePosition;
     orientation_      = orientation;
 }
Example #40
0
        private static List <Point> OptimizeLinePoints(IList <Point> linePoints, Rect[] rectangles, ConnectorOrientation sourceOrientation,
                                                       ConnectorOrientation targetOrientation)
        {
            var points = new List <Point>();
            var cut    = 0;

            for (var i = 0; i < linePoints.Count; i++)
            {
                if (i >= cut)
                {
                    for (var k = linePoints.Count - 1; k > i; k--)
                    {
                        if (IsPointVisible(linePoints[i], linePoints[k], rectangles))
                        {
                            cut = k;
                            break;
                        }
                    }

                    points.Add(linePoints[i]);
                }
            }

            #region Line

            for (var j = 0; j < points.Count - 1; j++)
            {
                if (Math.Abs(points[j].X - points[j + 1].X) > Epsilon && Math.Abs(points[j].Y - points[j + 1].Y) > Epsilon)
                {
                    // orientation from point
                    var orientationFrom = j == 0 ? sourceOrientation : GetOrientation(points[j], points[j - 1]);

                    // orientation to pint
                    var orientationTo = j == points.Count - 2 ? targetOrientation : GetOrientation(points[j + 1], points[j + 2]);

                    if ((orientationFrom == ConnectorOrientation.Left || orientationFrom == ConnectorOrientation.Right) &&
                        (orientationTo == ConnectorOrientation.Left || orientationTo == ConnectorOrientation.Right))
                    {
                        var centerX = Math.Min(points[j].X, points[j + 1].X) + Math.Abs(points[j].X - points[j + 1].X) / 2;
                        points.Insert(j + 1, new Point(centerX, points[j].Y));
                        points.Insert(j + 2, new Point(centerX, points[j + 2].Y));

                        if (points.Count - 1 > j + 3)
                        {
                            points.RemoveAt(j + 3);
                        }

                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Top || orientationFrom == ConnectorOrientation.Bottom) &&
                        (orientationTo == ConnectorOrientation.Top || orientationTo == ConnectorOrientation.Bottom))
                    {
                        var centerY = Math.Min(points[j].Y, points[j + 1].Y) + Math.Abs(points[j].Y - points[j + 1].Y) / 2;
                        points.Insert(j + 1, new Point(points[j].X, centerY));
                        points.Insert(j + 2, new Point(points[j + 2].X, centerY));

                        if (points.Count - 1 > j + 3)
                        {
                            points.RemoveAt(j + 3);
                        }

                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Left || orientationFrom == ConnectorOrientation.Right) &&
                        (orientationTo == ConnectorOrientation.Top || orientationTo == ConnectorOrientation.Bottom))
                    {
                        points.Insert(j + 1, new Point(points[j + 1].X, points[j].Y));
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Top || orientationFrom == ConnectorOrientation.Bottom) &&
                        (orientationTo == ConnectorOrientation.Left || orientationTo == ConnectorOrientation.Right))
                    {
                        points.Insert(j + 1, new Point(points[j].X, points[j + 1].Y));
                        return(points);
                    }
                }
            }

            #endregion Line

            return(points);
        }
Example #41
0
        private static double GetAngel(ConnectorOrientation orientation)
        {
            switch (orientation)
            {
                case ConnectorOrientation.Left:
                    return 180;
                case ConnectorOrientation.Top:
                    return 270;
                case ConnectorOrientation.Right:
                    return 0;
                case ConnectorOrientation.Bottom:
                    return 90;
                default:
                    throw new Exception("Unknown ConnectorOrientation");

            }
        }
Example #42
0
        internal static List <Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation)
        {
            _linePoints.Clear();

            Rect  sourceRect = GetElementRect(source);
            Point startPoint = source.ConnectorPoint;

            _linePoints.Add(startPoint);
            if (!sourceRect.Contains(sinkPoint))
            {
                AddOtherPoints(_linePoints, source, sinkPoint, sourceRect);
            }
            else
            {
                _linePoints.Add(sinkPoint);
            }
            // задание изломов линии на сегменты под 90 градусов
            OptimizeLine(_linePoints, sourceRect);
            return(_linePoints);
        }
Example #43
0
        private FullyCreatedConnectorInfo GetFullConnectorInfo(int connectorId, DesignerItemViewModelBase dataItem, ConnectorOrientation connectorOrientation)
        {
            switch (connectorOrientation)
            {
            case ConnectorOrientation.Top:
                return(dataItem.TopConnector);

            case ConnectorOrientation.Left:
                return(dataItem.LeftConnector);

            case ConnectorOrientation.Right:
                return(dataItem.RightConnector);

            case ConnectorOrientation.Bottom:
                return(dataItem.BottomConnector);

            default:
                throw new InvalidOperationException(
                          string.Format("Found invalid persisted Connector Orientation for Connector Id: {0}", connectorId));
            }
        }
Example #44
0
 public ConnectorInfoBase(ConnectorOrientation orientation)
 {
     this.Orientation = orientation;
 }
Example #45
0
        internal static List <Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation)
        {
            List <Point> linePoints = new List <Point>();
            Rect         rectSource = GetRectWithMargin(source, 10);
            Point        startPoint = GetOffsetPoint(source, rectSource);
            Point        endPoint   = sinkPoint;

            linePoints.Add(startPoint);
            Point currentPoint = startPoint;

            if (!rectSource.Contains(endPoint))
            {
                while (true)
                {
                    if (IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource }))
                    {
                        linePoints.Add(endPoint);
                        break;
                    }

                    bool  sideFlag;
                    Point n = GetNearestNeighborSource(source, endPoint, rectSource, out sideFlag);
                    linePoints.Add(n);
                    currentPoint = n;

                    if (IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource }))
                    {
                        linePoints.Add(endPoint);
                        break;
                    }
                    else
                    {
                        Point n1, n2;
                        GetOppositeCorners(source.Orientation, rectSource, out n1, out n2);
                        if (sideFlag)
                        {
                            linePoints.Add(n1);
                        }
                        else
                        {
                            linePoints.Add(n2);
                        }

                        linePoints.Add(endPoint);
                        break;
                    }
                }
            }
            else
            {
                linePoints.Add(endPoint);
            }

            if (preferredOrientation != ConnectorOrientation.None)
            {
                linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Orientation, preferredOrientation);
            }
            else
            {
                linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Orientation, GetOpositeOrientation(source.Orientation));
            }

            return(linePoints);
        }
Example #46
0
        private static List <Point> OptimizeLinePoints(List <Point> linePoints, Rect[] rectangles, ConnectorOrientation sourceOrientation, ConnectorOrientation sinkOrientation) //makes connection orthogonal
        {
            List <Point> points = new List <Point>();
            int          cut    = 0;

            //making path shorter if it is possible. It is not orthogonal yet
            for (int i = 0; i < linePoints.Count; i++)
            {
                if (i >= cut)
                {
                    for (int k = linePoints.Count - 1; k > i; k--)
                    {
                        if (IsPointVisible(linePoints[i], linePoints[k], rectangles))
                        {
                            cut = k;
                            break;
                        }
                    }
                    points.Add(linePoints[i]);
                }
            }

            //orthogonalization
            #region Line
            for (int j = 0; j < points.Count - 1; j++)
            {
                if (Math.Abs(points[j].X - points[j + 1].X) > comparisonTolerance && Math.Abs(points[j].Y - points[j + 1].Y) > comparisonTolerance) // if the points[j] differs from the points[j+1] in X and Y (it is the only one not orthogonal fragment of path)
                {
                    ConnectorOrientation orientationFrom;
                    ConnectorOrientation orientationTo;

                    // orientation from point
                    if (j == 0) //start point
                    {
                        orientationFrom = sourceOrientation;
                    }
                    else
                    {
                        orientationFrom = GetOrientation(points[j], points[j - 1]);
                    }

                    if (orientationFrom == ConnectorOrientation.None)
                    {
                        return(points);
                    }

                    // orientation to point
                    if (j == points.Count - 2) //end point
                    {
                        orientationTo = sinkOrientation;
                    }
                    else
                    {
                        orientationTo = GetOrientation(points[j + 1], points[j + 2]);
                    }

                    if (orientationTo == ConnectorOrientation.None)
                    {
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Left || orientationFrom == ConnectorOrientation.Right) &&
                        (orientationTo == ConnectorOrientation.Left || orientationTo == ConnectorOrientation.Right))
                    {
                        double centerX = Math.Min(points[j].X, points[j + 1].X) + Math.Abs(points[j].X - points[j + 1].X) / 2;
                        points.Insert(j + 1, new Point(centerX, points[j].Y));
                        points.Insert(j + 2, new Point(centerX, points[j + 2].Y));
                        if (points.Count - 1 > j + 3)
                        {
                            points.RemoveAt(j + 3);
                        }
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Top || orientationFrom == ConnectorOrientation.Bottom) &&
                        (orientationTo == ConnectorOrientation.Top || orientationTo == ConnectorOrientation.Bottom))
                    {
                        double centerY = Math.Min(points[j].Y, points[j + 1].Y) + Math.Abs(points[j].Y - points[j + 1].Y) / 2;
                        points.Insert(j + 1, new Point(points[j].X, centerY));
                        points.Insert(j + 2, new Point(points[j + 2].X, centerY));
                        if (points.Count - 1 > j + 3)
                        {
                            points.RemoveAt(j + 3);
                        }
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Left || orientationFrom == ConnectorOrientation.Right) &&
                        (orientationTo == ConnectorOrientation.Top || orientationTo == ConnectorOrientation.Bottom))
                    {
                        points.Insert(j + 1, new Point(points[j + 1].X, points[j].Y));
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Top || orientationFrom == ConnectorOrientation.Bottom) &&
                        (orientationTo == ConnectorOrientation.Left || orientationTo == ConnectorOrientation.Right))
                    {
                        points.Insert(j + 1, new Point(points[j].X, points[j + 1].Y));
                        return(points);
                    }
                }
            }
            #endregion

            return(points);
        }
Example #47
0
 public Connector(Node child)
 {
     this.m_child = child;
     this.m_orientation = ConnectorOrientation.Agnostic;
 }
 public ConnectorInfoBase(ConnectorOrientation orientation)
 {
     this.Orientation = orientation;
 }
Example #49
0
 public Connector(Node child, ConnectorOrientation orientation)
 {
     this.m_child = child;
     this.m_orientation = orientation;
 }
Example #50
0
        public Connector GetConnector(Guid itemID, String connectorName, IList <DesignerItem> designerItems, ConnectorOrientation orientation)
        {
            //logger.Info("Inicio Obtener Conector");
            DesignerItem designerItem = (from item in designerItems
                                         where item.ID == itemID
                                         select item).FirstOrDefault();
            Connector result = new Connector();

            result.Name = connectorName;
            result.ParentDesignerItem = designerItem;
            result.Orientation        = orientation;
            //logger.Info("Fin Obtener Conector");
            return(result);
        }
Example #51
0
 private static void GetOppositeCorners(ConnectorOrientation orientation, Rect rect, out Point n1, out Point n2)
 {
     switch (orientation)
     {
         case ConnectorOrientation.Left:
             n1 = rect.TopRight; n2 = rect.BottomRight;
             break;
         case ConnectorOrientation.Top:
             n1 = rect.BottomLeft; n2 = rect.BottomRight;
             break;
         case ConnectorOrientation.Right:
             n1 = rect.TopLeft; n2 = rect.BottomLeft;
             break;
         case ConnectorOrientation.Bottom:
             n1 = rect.TopLeft; n2 = rect.TopRight;
             break;
         default:
             throw new Exception("No opposite corners found!");
     }
 }
Example #52
0
        public static List <Point> GetConnectionLine(ConnectorInfo source, Point targetPoint, ConnectorOrientation preferredOrientation)
        {
            var linePoints = new List <Point>();
            var rectSource = GetRectWithMargin(source, 10);
            var startPoint = GetOffsetPoint(source, rectSource);
            var endPoint   = targetPoint;

            linePoints.Add(startPoint);
            var currentPoint = startPoint;

            if (!rectSource.Contains(endPoint))
            {
                while (true)
                {
                    if (IsPointVisible(currentPoint, endPoint, new[] { rectSource }))
                    {
                        linePoints.Add(endPoint);
                        break;
                    }

                    var n = GetNearestNeighborSource(source, endPoint, rectSource, out var sideFlag);
                    linePoints.Add(n);
                    currentPoint = n;

                    if (IsPointVisible(currentPoint, endPoint, new[] { rectSource }))
                    {
                        linePoints.Add(endPoint);
                        break;
                    }

                    GetOppositeCorners(source.Orientation, rectSource, out var n1, out var n2);
                    linePoints.Add(sideFlag ? n1 : n2);
                    linePoints.Add(endPoint);
                    break;
                }
            }
            else
            {
                linePoints.Add(endPoint);
            }

            linePoints = OptimizeLinePoints(linePoints, new[] { rectSource }, source.Orientation,
                                            preferredOrientation != ConnectorOrientation.None
                                                ? preferredOrientation
                                                : GetOpositeOrientation(source.Orientation));

            return(linePoints);
        }
Example #53
0
        private static List<Point> OptimizeLinePoints(List<Point> linePoints, Rect[] rectangles, ConnectorOrientation sourceOrientation, ConnectorOrientation sinkOrientation)
        {
            List<Point> points = new List<Point>();
            int cut = 0;

            for (int i = 0; i < linePoints.Count; i++)
            {
                if (i >= cut)
                {
                    for (int k = linePoints.Count - 1; k > i; k--)
                    {
                        if (IsPointVisible(linePoints[i], linePoints[k], rectangles))
                        {
                            cut = k;
                            break;
                        }
                    }
                    points.Add(linePoints[i]);
                }
            }

            #region Line
            for (int j = 0; j < points.Count - 1; j++)
            {
                if (points[j].X != points[j + 1].X && points[j].Y != points[j + 1].Y)
                {
                    ConnectorOrientation orientationFrom;
                    ConnectorOrientation orientationTo;

                    // orientation from point
                    if (j == 0)
                        orientationFrom = sourceOrientation;
                    else
                        orientationFrom = GetOrientation(points[j], points[j - 1]);

                    // orientation to pint
                    if (j == points.Count - 2)
                        orientationTo = sinkOrientation;
                    else
                        orientationTo = GetOrientation(points[j + 1], points[j + 2]);

                    if ((orientationFrom == ConnectorOrientation.Left || orientationFrom == ConnectorOrientation.Right) &&
                        (orientationTo == ConnectorOrientation.Left || orientationTo == ConnectorOrientation.Right))
                    {
                        double centerX = Math.Min(points[j].X, points[j + 1].X) + Math.Abs(points[j].X - points[j + 1].X) / 2;
                        points.Insert(j + 1, new Point(centerX, points[j].Y));
                        points.Insert(j + 2, new Point(centerX, points[j + 2].Y));
                        if (points.Count - 1 > j + 3)
                            points.RemoveAt(j + 3);
                        return points;
                    }

                    if ((orientationFrom == ConnectorOrientation.Top || orientationFrom == ConnectorOrientation.Bottom) &&
                        (orientationTo == ConnectorOrientation.Top || orientationTo == ConnectorOrientation.Bottom))
                    {
                        double centerY = Math.Min(points[j].Y, points[j + 1].Y) + Math.Abs(points[j].Y - points[j + 1].Y) / 2;
                        points.Insert(j + 1, new Point(points[j].X, centerY));
                        points.Insert(j + 2, new Point(points[j + 2].X, centerY));
                        if (points.Count - 1 > j + 3)
                            points.RemoveAt(j + 3);
                        return points;
                    }

                    if ((orientationFrom == ConnectorOrientation.Left || orientationFrom == ConnectorOrientation.Right) &&
                        (orientationTo == ConnectorOrientation.Top || orientationTo == ConnectorOrientation.Bottom))
                    {
                        points.Insert(j + 1, new Point(points[j + 1].X, points[j].Y));
                        return points;
                    }

                    if ((orientationFrom == ConnectorOrientation.Top || orientationFrom == ConnectorOrientation.Bottom) &&
                        (orientationTo == ConnectorOrientation.Left || orientationTo == ConnectorOrientation.Right))
                    {
                        points.Insert(j + 1, new Point(points[j].X, points[j + 1].Y));
                        return points;
                    }
                }
            }
            #endregion

            return points;
        }
        private static IConnector getConnector(DDTRelation rel, ConnectorOrientation orientation, Netron.NetronLight.IDDTObject obj)
        {
            IConnector connector = null;
            Conn_Position temp;
            if (orientation == ConnectorOrientation.FROM)
                temp = rel.from.pos;
            else if (orientation == ConnectorOrientation.TO)
                temp = rel.to.pos;
            else return null;

            switch (temp)
            {
                case Conn_Position.LEFT:
                    connector = obj.connectorA;
                    break;
                case Conn_Position.TOP:
                    connector = obj.connectorB;
                    break;
                case Conn_Position.RIGHT:
                    connector = obj.connectorC;
                    break;
                case Conn_Position.BOTTOM:
                    connector = obj.connectorD;
                    break;
                default:
                    connector = obj.connectorC;
                    break;
            }

            return connector;
        }