예제 #1
0
 public ConnectorModel(ConnectionType type,
                       IBoundedSketchItemModel from, IBoundedSketchItemModel to,
                       System.Windows.Point connectorStartHint, System.Windows.Point connectorEndHint,
                       ISketchItemContainer container)
 //:base(new Guid())
 {
     ParentNode                  = container;
     _connectionType             = type;
     MiddlePointRelativePosition = 0.5;
     From = from;
     To   = to;
     _myConnectorStrategy = ConnectorUtilities.GetConnectionType(this, _connectionType, connectorStartHint, connectorEndHint);
     Label     = string.Format("{0}->{1}", from.Label, to.Label);
     LineWidth = 1;
     _geometry.Children.Add(_path);
     Initialize();
 }
예제 #2
0
        //readonly GeometryGroup _geometry = new GeometryGroup();

        public ConnectorMoveHelper(ConnectorModel connectorModel, IConnectorStrategy parent, Point p)
        {
            _routingStrategy = parent;
            _model           = connectorModel;
            _moveType        = MoveType.MoveTypeNone;
            _startingFrom    = new ToWaypointAdapter(_model, connectorModel.From);
            _endingAt        = new ToWaypointAdapter(_model, connectorModel.To);
            List <double> middlePointInfo = new List <double>()
            {
                _model.MiddlePointRelativePosition
            };
            List <IWaypoint> connectionPoints = new List <IWaypoint> {
                _startingFrom
            };

            connectionPoints.AddRange(_model.Waypoints);
            connectionPoints.Add(_endingAt);

            double[] relativePositions = new double[connectionPoints.Count];
            for (int i = 0; i < relativePositions.Length; i++)
            {
                relativePositions[i] = 0.5;
            }
            relativePositions[0] = _model.StartPointRelativePosition;
            relativePositions[relativePositions.Length - 1] = _model.EndPointRelativePosition;

            middlePointInfo.AddRange(_model.Waypoints.Select <IWaypoint, double>((x) => x.MiddlePosition));

            foreach (var pf in _routingStrategy.ConnectorPath)
            {
                var nrOfSegments = pf.Segments.Count();
                if (ConnectorUtilities.HitLineSegment(p, pf, out int index, out _startPoint, out _endPoint))
                {
                    _distance = middlePointInfo[_pathIndex];
                    _startPointRelativePosition = relativePositions[_pathIndex];
                    _endPointRelativePosition   = relativePositions[_pathIndex + 1];
                    if (index == 0 && nrOfSegments == 1)
                    {
                        var d1 = Point.Subtract(p, _startPoint).Length;
                        var d2 = Point.Subtract(p, _endPoint).Length;
                        _moveType = MoveType.MoveStartPoint;
                        if (d1 > d2)
                        {
                            _moveType = MoveType.MoveEndPoint;
                            //_moveStart = _startPoint;
                        }
                    }
                    else if (index == 0 && nrOfSegments > 1)
                    {
                        _moveType = MoveType.MoveStartPoint;
                        //_moveStart = StartPoint;
                    }
                    else if ((index == 1 && nrOfSegments == 3) || (index == 2 && nrOfSegments == 7) || (index == 3))
                    {
                        _moveType = MoveType.MoveMiddlePoint;
                    }

                    else if (index == 2 || (index == 1 && nrOfSegments == 2) || (index == 6))
                    {
                        _moveType   = MoveType.MoveEndPoint;
                        _startPoint = _endPoint;
                    }

                    _startingFrom = connectionPoints[_pathIndex];
                    _endingAt     = connectionPoints[_pathIndex + 1];
                    break;
                }
                _pathIndex++;
            }
        }