public MovingState(ConnectorModel connectorModel,
                               RoutingConnectorWithWaypointsStrategy parent, Point p)
            {
                _parent = parent;
                _model  = connectorModel;
                int        i            = 0;
                int        nrOfSegments = 0;
                PathFigure pf           = _parent._myPath.First();

                var   start = pf.StartPoint;
                Point end   = start;

                nrOfSegments = pf.Segments.Count;
                foreach (var ps in pf.Segments)
                {
                    var ls = ps as LineSegment;
                    if (ls != null)
                    {
                        end = ls.Point;
                        var l = new LineGeometry(start, end);
                        if (l.StrokeContains(_connectorPen, p))
                        {
                            break;
                        }
                        start = end;
                        ++i;
                    }
                }
                _distance = _parent._model.MiddlePointRelativePosition;
                if (i == 0)
                {
                    _moveType   = Types.MoveType.MoveStartPoint;
                    _startPoint = _parent._start;
                }
                else if (i == 1 && nrOfSegments == 3)
                {
                    _moveType   = Types.MoveType.MoveMiddlePoint;
                    _startPoint = new Point((start.X + end.X) / 2.0, (start.Y + end.Y) / 2);
                }
                else if (i == 2 || (i == 1 && nrOfSegments == 2))
                {
                    _moveType   = Types.MoveType.MoveEndPoint;
                    _startPoint = _parent._end;
                }
                else
                {
                    _moveType = Types.MoveType.MoveTypeNone;
                    //throw new NotSupportedException("don't know how to move connector");
                }
            }
Example #2
0
 public ConnectorLabelModel(ConnectorModel connector, ISketchItemContainer container, bool isStartPointLabel, bool showLabelConnection, Point labelPosition)
     : base(labelPosition, container,
            ComputeSizeOfBounds(connector.GetLabel(isStartPointLabel)),
            connector.GetLabel(isStartPointLabel), Colors.Snow)
 {
     _connector = connector;
     _connector.PropertyChanged += Connector_PropertyChanged;
     _isStartpointLabel          = isStartPointLabel;
     _showLabelConnection        = showLabelConnection;
     CanChangeSize   = false;
     StrokeThickness = 0.2;
     FillColor       = Color.FromArgb(0x31, 0xFF, 0xFA, 0xFA);
     UpdateGeometry();
 }
Example #3
0
        public static IConnectorStrategy GetConnectionType(ConnectorModel parent, ConnectionType type, Point s, Point e)
        {
            if (parent.From == parent.To)
            {
                return(CreateSelfConnector(parent));
            }
            switch (type)
            {
            case ConnectionType.AutoRouting:
                return(CreateAutoRoutingConnector(parent, s, e));

            //case ConnectionType.RoutingWithWaypoint:
            //    return CreateRoutingWithWaypointsConnector(parent, s, e);
            case ConnectionType.StrightLine:
                return(CreateStrightLineConnector(parent, s, e));

            default:
                throw new NotSupportedException(string.Format("connection type {0} not supported", type));
            }
        }
Example #4
0
 public AutoRoutingConnectorStrategy(ConnectorModel model, Point startPointHint, Point endPointHint)
 {
     _model          = model;
     _startPointHint = startPointHint;
     _endPointHint   = endPointHint;
 }
 public StraightLineConnectorStrategy(ConnectorModel connectorModel, Point start, Point end)
 {
     _model = connectorModel;
     _start = start;
     _end   = end;
 }
 public RoutingConnectorWithWaypointsStrategy(ConnectorModel model, Point startHint,
                                              Point endHint)
 {
     _model = model;
 }
Example #7
0
 static IConnectorStrategy CreateStrightLineConnector(ConnectorModel connectorModel, Point start, Point end)
 {
     return(new StraightLineConnectorStrategy(connectorModel, start, end));
 }
Example #8
0
 static IConnectorStrategy CreateAutoRoutingConnector(ConnectorModel connectorModel, Point startPointHint, Point endPointHint)
 {
     return(new AutoRoutingConnectorStrategy(connectorModel, startPointHint, endPointHint));
 }
Example #9
0
 static IConnectorStrategy CreateSelfConnector(ConnectorModel connectorModel)
 {
     return(new SelfConnectorStrategy(connectorModel));
 }
Example #10
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++;
            }
        }
 public SelfConnectorStrategy(ConnectorModel connectorModel)
 {
     _model = connectorModel;
 }
Example #12
0
 public ToWaypointAdapter(ConnectorModel model, IConnectable connectable)
 {
     _connector   = model;
     _connectable = connectable;
     _connectable.ShapeChanged += NotifyShapedChanged;
 }