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; } }
public Building Load(string filename) { var formatter = new BinaryFormatter(); var files = new List <SavedFile>(); using (var fs = new FileStream(filename, FileMode.OpenOrCreate)) { files = (List <SavedFile>)formatter.Deserialize(fs); } Type t = typeof(Building); var sBuilding = (BuildingSavedFile)files.FirstOrDefault(x => x.FileType == typeof(Building)); if (sBuilding == null) { return(null); } Building building = new Building(sBuilding.Title); var dictionary = new Dictionary <int, dynamic>(); foreach (var file in files.Where(x => x.FileType == typeof(ZoomTool))) { var sScale = file as ZoomToolSavedFile; dictionary.Add(sScale.HashCode, new ZoomTool(sScale.ActualLength, sScale.GraphicLength)); } foreach (var file in files.Where(x => x.FileType == typeof(Floor))) { var sFloor = file as FloorSavedFile; var floor = new Floor(sFloor.Title, building) { Scale = dictionary[sFloor.Scale], FloorPlanImage = SettingsManager.GetBitmapImage(sFloor.FloorPlanImage) }; dictionary.Add(sFloor.HashCode, floor); building.AddFloor(floor); } foreach (var file in files) { if (file is StartNodeSavedFile) { var sNode = file as StartNodeSavedFile; Floor floor = dictionary[sNode.ParentHashCode]; var node = new StartNode(floor, sNode.Position, sNode.Title) { PeopleCount = sNode.PeopleCount, ProjectionArea = sNode.ProjectionArea, AutoSize = sNode.AutoSize }; dictionary.Add(sNode.HashCode, node); floor.AddObject(node); continue; } if (file is EntryNodeSavedFile) { var sNode = file as EntryNodeSavedFile; Floor floor = dictionary[sNode.ParentHashCode]; var node = new EntryNode(floor, sNode.Position, sNode.Title) { AutoSize = sNode.AutoSize, Width = sNode.Width }; dictionary.Add(sNode.HashCode, node); floor.AddObject(node); continue; } if (file is StairsNodeSavedFile) { var sNode = file as StairsNodeSavedFile; Floor floor = dictionary[sNode.ParentHashCode]; var node = new StairsNode(floor, sNode.Position, sNode.Title) { AutoSize = sNode.AutoSize, IsFloorsConnected = sNode.IsFloorsConnected }; dictionary.Add(sNode.HashCode, node); floor.AddObject(node); continue; } if (file is NodeSavedFile) { var sNode = file as NodeSavedFile; Floor floor = dictionary[sNode.ParentHashCode]; Node node = null; if (sNode.FileType == typeof(ExitNode)) { node = new ExitNode(floor, sNode.Position, sNode.Title) { AutoSize = sNode.AutoSize } } ; if (sNode.FileType == typeof(RoadNode)) { node = new RoadNode(floor, sNode.Position, sNode.Title) { AutoSize = sNode.AutoSize } } ; dictionary.Add(sNode.HashCode, node); floor.AddObject(node); continue; } if (file is SectionSavedFile) { var sSection = file as SectionSavedFile; Floor floor = dictionary[sSection.ParentHashCode]; Section section = null; if (sSection.FileType == typeof(RoadSection)) { section = new RoadSection((Node)dictionary[sSection.FirstNodeHashCode], (Node)dictionary[sSection.LastNodeHashCode], floor, sSection.Title) { AutoSize = sSection.AutoSize, Length = sSection.Length, Width = sSection.Width } } ; else if (sSection.FileType == typeof(StairsSection)) { section = new StairsSection((Node)dictionary[sSection.FirstNodeHashCode], (Node)dictionary[sSection.LastNodeHashCode], floor, sSection.Title) { AutoSize = sSection.AutoSize, Length = sSection.Length, Width = sSection.Width } } ; else if (sSection.FileType == typeof(FloorsConnectionSection)) { continue; // следует произвести добавление в самом конце } dictionary.Add(sSection.HashCode, section); floor.AddObject(section); continue; } } foreach (var file in files.Where(x => x.FileType == typeof(FloorsConnectionSection))) { var sSection = file as SectionSavedFile; Floor floor = dictionary[sSection.ParentHashCode]; var section = new FloorsConnectionSection((Node)dictionary[sSection.FirstNodeHashCode], (Node)dictionary[sSection.LastNodeHashCode], floor); dictionary.Add(sSection.HashCode, section); floor.AddObject(section); } return(building); } } }