예제 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void NodeEditControl_ConnectionDragCompleted(object sender, ConnectionDragCompletedEventArgs e)
 {
     NodeEditViewModel.ConnectionDragCompleted(e);
 }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        public void ConnectionDragCompleted(ConnectionDragCompletedEventArgs arg)
        {
            LinkViewModel m = arg.Connection as LinkViewModel;

            if (m == null)
            {
                return;
            }

            bool isConnect = false;

            if (arg.ConnectorDraggedOver != null)
            {
                NodeConnectorViewModel connector = arg.ConnectorDraggedOver as NodeConnectorViewModel;
                if (connector != null)
                {
                    var linkSource = m.SourceConnector != null ? m.SourceConnector : m.TargetConnector;

                    // リンク元と同じタイプ、同じ親ならdiscard
                    if (linkSource.Type != connector.Type &&
                        linkSource.Parent != connector.Parent
                        )
                    {
                        if (connector.Type == NodeConnectorViewModel.ConnectorType.Input)
                        {
                            m.TargetConnector = connector;
                        }
                        else
                        {
                            m.SourceConnector = connector;
                        }
                        isConnect = true;
                    }
                }
            }

            // 接続されない場合リンクを削除する
            if (!isConnect)
            {
                m.SourceConnector = null;
                m.TargetConnector = null;
                Links.Remove(m);
            }
            else
            {
                // 接続された場合Undo登録する
                UndoableContext.CurrentContext.CommandStacking(new UndoableDelegate("ConnectAttribute", false,
                                                                                    // Undo
                                                                                    (o) => {
                    // 内部でコールバック登録等を行っているのでちゃんといったんクリアする
                    var d = o as ConnectorHistoryData;
                    d.linkObject.SourceConnector = null;
                    d.linkObject.TargetConnector = null;
                    Links.Remove(d.linkObject);
                    return(o);
                },
                                                                                    // Redo
                                                                                    (o) => {
                    var d = o as ConnectorHistoryData;
                    d.linkObject.SourceConnector = d.source;
                    d.linkObject.TargetConnector = d.target;
                    Links.Add(d.linkObject);
                    return(o);
                }),
                                                               // History data
                                                               new ConnectorHistoryData()
                {
                    linkObject = m,
                    source     = m.SourceConnector,
                    target     = m.TargetConnector
                }
                                                               );
            }
        }