Exemple #1
0
        private void menuItem_MergeLayersIntoZones_Click(object sender, EventArgs e)
        {
            if (EditorManager.Scene == null || EditorManager.Scene.Zones.Count == 0)
            return;
              ZoneCollection zones = new ZoneCollection();
              foreach (Zone zone in EditorManager.Scene.Zones)
            if (zone.ConsiderForSortIntoZones)
              zones.Add(zone);
              if (zones.Count==0)
            return;

              OpenFileDialog dlg = new OpenFileDialog();
              dlg.InitialDirectory = EditorManager.Project.ProjectDir;
              dlg.Filter = "Layer files (*.Layer)|*.Layer";
              dlg.Multiselect = true;
              dlg.Title = "Select one or more layer files from external folders that should be merged into the zones of the currect scenes";
              if (dlg.ShowDialog() != DialogResult.OK)
            return;
              string[] names = dlg.FileNames;
              if (names == null || names.Length==0)
            return;

              float fProgressStep = 50.0f / (float)names.Length;
              EditorManager.Progress.ShowProgressDialog("Merging shapes...");

              EditorManager.ActiveView.Gizmo.LockCtr++; // do not update
              ShapeTreeView.UIUpdateLock++;

              foreach (string name in names)
              {
            EditorManager.Progress.StatusString = "Loading Layer" + Path.GetFileName(name);
            Application.DoEvents();
            Layer layer = null;
            BinaryFormatter fmt = SerializationHelper.BINARY_FORMATTER;
            try
            {
              // open the layer in read-only mode
              FileStream fs = new FileStream(name, FileMode.Open, FileAccess.Read);
              layer = (Layer)fmt.Deserialize(fs);
              fs.Close();
            }
            catch (Exception ex)
            {
              EditorManager.DumpException(ex, true);
            }
            if (layer == null || layer.Root == null)
              continue;
            layer.OnCreateAllEngineInstances(null); // we need the engine instances, because otherwise the bounding boxs are not correct
            EditorManager.Progress.Percentage += fProgressStep;
            EditorManager.Progress.StatusString = "Merging Layer" + Path.GetFileName(name);
            Application.DoEvents();
            SortShapesIntoZonesAction action = new SortShapesIntoZonesAction(layer.Root.ChildCollection, zones);

            // layer cleanup
            layer.OnRemoveAllEngineInstances();
            EditorManager.EngineManager.Resources_PurgeUnusedResources();

            EditorManager.Actions.Add(action);
            EditorManager.Progress.Percentage += fProgressStep;
            Application.DoEvents();
              }
              EditorManager.Progress.HideProgressDialog();
              EditorManager.ActiveView.Gizmo.LockCtr--; // do not update
              ShapeTreeView.UIUpdateLock--;
        }
        private void sortShapesIntoZonesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ZoneCollection zones = new ZoneCollection();
              foreach (Zone zone in EditorManager.Scene.Zones)
            if (zone.ConsiderForSortIntoZones)
              zones.Add(zone);
              if (zones.Count==0)
            return;

              ShapeCollection shapes = new ShapeCollection();
              foreach (Layer layer in treeView_Layers.Selection_Layers)
              {
            if (layer.ParentZone != null || !layer.Modifiable)
              continue;
            foreach (ShapeBase shape in layer.Root.ChildCollection)
              shapes.Add(shape);

              }

              if (shapes.Count > 0)
              {
            SortShapesIntoZonesAction action = new SortShapesIntoZonesAction(shapes, zones);
            EditorManager.Actions.Add(action);
              }
        }