コード例 #1
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            if (CurrentFloor == null)
            {
                return;
            }

            e.Handled = true;
            var position = GetAbsolutePosition(e.GetPosition(this));

            try
            {
                switch (SelectedActionMode)
                {
                case ActionMode.AddStart:
                {
                    var start = new StartNode(CurrentFloor.Model, position);
                    AddVisualEntity(new VisualStartNode(start, CurrentFloor)); break;
                }

                case ActionMode.AddExit:
                {
                    var exit = new ExitNode(CurrentFloor.Model, position);
                    AddVisualEntity(new VisualExitNode(exit, CurrentFloor)); break;
                }

                case ActionMode.AddEntry:
                {
                    var entry = new EntryNode(CurrentFloor.Model, position);
                    AddVisualEntity(new VisualEntryNode(entry, CurrentFloor)); break;
                }

                case ActionMode.AddStairs:
                case ActionMode.AddRoad:
                {
                    CreatingSection(position);
                    break;
                }

                case ActionMode.Move:
                {
                    var entity = CurrentFloor.GetVisualEntity(position);
                    if (entity != null)
                    {
                        moveInformation         = new MoveInformation(entity.GetUnit(position), position);
                        entity.Model.IsSelected = true;
                    }
                    else if (Shell != null)
                    {
                        moveInformation = new MoveInformation(Shell, e.GetPosition(this), true);
                        e.Handled       = false;
                    }
                    e.Handled = true;
                    break;
                }

                case ActionMode.Remove:
                {
                    var entity = CurrentFloor.GetVisualEntity(position);
                    CurrentFloor.RemoveVisualEntity(entity);
                    break;
                }

                case ActionMode.SetScale:
                {
                    if (IsCreatingLine)
                    {
                        CreatingLineInf.LastPosition = position;
                        SetScale();
                    }
                    else
                    {
                        CreatingLineInf = new CreatingLineInformation(new VisualThumb(position));
                    }
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #2
0
        private void CreatingSection(Point position)
        {
            var        entity = CurrentFloor.GetVisualEntity(position);
            VisualNode node   = null;

            if (entity is VisualNode)
            {
                node = entity as VisualNode;
            }
            else
            {
                switch (SelectedActionMode)
                {
                case ActionMode.AddStairs:
                    node = new VisualStairsNode(new StairsNode(CurrentFloor.Model, position), CurrentFloor); break;

                case ActionMode.AddRoad:
                    node = new VisualNode(new RoadNode(CurrentFloor.Model, position), CurrentFloor); break;
                }
                AddVisualEntity(node);
            }

            if (IsCreatingLine)
            {
                if (!node.NodeModel.IncomingSectionsAllowed)
                {
                    return;
                }
                if (CreatingLineInf.FirstUnit == node || !(CreatingLineInf.FirstUnit is VisualNode))
                {
                    return;
                }

                VisualRoadSection section = null;
                Section           model   = null;
                switch (SelectedActionMode)
                {
                case ActionMode.AddStairs:
                    model = new StairsSection(CreatingLineInf.FirstNode.NodeModel, node.NodeModel, CurrentFloor.Model); break;

                case ActionMode.AddRoad:
                    model = new RoadSection(CreatingLineInf.FirstNode.NodeModel, node.NodeModel, CurrentFloor.Model); break;
                }

                // по каким-то причинам (образовывается петля) нет возможности добавить данный участок
                if (!CurrentFloor.Model.CanAddSection(model))
                {
                    return;
                }

                switch (SelectedActionMode)
                {
                case ActionMode.AddStairs:
                    section = new VisualStairsSection(CreatingLineInf.FirstNode, node, model as StairsSection, CurrentFloor); break;

                case ActionMode.AddRoad:
                    section = new VisualRoadSection(CreatingLineInf.FirstNode, node, model as RoadSection, CurrentFloor); break;
                }

                AddVisualEntity(section);
            }

            CreatingLineInf = new CreatingLineInformation(node);

            if (!CreatingLineInf.FirstNode.NodeModel.OutgoingSectionsAllowed)
            {
                IsCreatingLine = false;
            }
        }