Exemple #1
0
        /// <summary>
        /// Actually load the scene
        /// </summary>
        /// <param name="relFileName"></param>
        /// <returns></returns>
        public bool Load(string relFileName)
        {
            _bSceneLoadingInProgress = true;
              EditorManager.Progress.StatusString = "Load manifest file";
              FileName = relFileName;
              string absFileName = AbsoluteFileName;

              // Check for old scene file format, and refuse to load it.
              try
              {
            using (FileStream fs = new FileStream(absFileName, FileMode.Open, FileAccess.Read))
            {
              long iLen = fs.Length;

              if (iLen > 0) // this is an old file
              {
            String error = String.Format("Loading aborted.\nThe file format of this scene is not supported by recent versions of vForge.\nTo migrate it, please open and then re-save this file in vForge prior to version 2012.3.");
            EditorManager.ShowMessageBox(error, "Scene loading error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return false;
              }
            }
              }
              catch (Exception ex)
              {
            EditorManager.DumpException(ex);
            EditorManager.ShowMessageBox("An exception occurred while loading scene file '" + relFileName + "'.\nPlease check whether the file is there and it is not write protected.\n\nDetailed Message:\n" + ex.Message,
              "Scene loading error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            _bSceneLoadingInProgress = false;
            return false; // the file isn't there at all or write protected?
              }
              EditorManager.Progress.Percentage = 15.0f; // loaded manifest
              EditorManager.Progress.StatusString = "Load layer and zone files";

              // Load export profile. If the return value is null, CurrentExportProfile creates a new instance
              _currentProfile = SceneExportProfile.LoadProfile(this, null, false);
              if (_currentProfile == null)
            EditorSceneSettings.PATCH_PROFILE = CurrentExportProfile; // patch into profile if no dedicated file has been loaded

              // Load user specific data
              string directoryName = LayerDirectoryName;
              string userFilename = Path.Combine(directoryName, EditorManager.UserSettingsFilename);

              // first try user specific file:
              if (!LoadUserSettingsFile(userFilename))
              {
            // alternatively try default.user file
            userFilename = Path.Combine(directoryName, "default.user");
            LoadUserSettingsFile(userFilename);
              }
              EditorSceneSettings.PATCH_PROFILE = null;

              if (!string.IsNullOrEmpty(Settings.ExportProfileName))
              {
            SceneExportProfile profile = SceneExportProfile.LoadProfile(this, Settings.ExportProfileName, false);
            if (profile != null)
              _currentProfile = profile;
              }

              EditorManager.Progress.SetRange(15.0f, 20.0f); // remap GatherLayers to range 15..20
              Zones.Clear();
              if (!GatherZones(Zones))
              {
            _bSceneLoadingInProgress = false;
            return false;
              }

              Layers.Clear();

              // load the layer files...
              LayerCollection newLayers = new LayerCollection();
              if (!GatherLayers(newLayers, EditorManager.Progress))
              {
            _bSceneLoadingInProgress = false;
            Layers.Clear();
            return false;
              }

              // Take the SortingOrder value
              newLayers.Sort();

              // create a dictionary for fast name lookup
              Dictionary<string, Layer> layerNameDict = new Dictionary<string, Layer>(newLayers.Count);
              foreach (Layer layer in newLayers)
            layerNameDict.Add(layer.LayerFilename, layer);

              if (!Zones.MatchupLayerNames(newLayers, layerNameDict))
              {
            _bSceneLoadingInProgress = false;
            return false;
              }

              // Add layers to the scene (do not lock them)
              foreach (Layer layer in newLayers)
            AddLayer(layer, false, false, false);

              // If project setting is to lock all layers on scene load open the layer lock dialog.
              // Otherwise all layers will be locked automatically (when not locked already by any other user).
              if (!TestManager.IsRunning && !EditorManager.SilentMode && Project.LayerLocking == EditorProject.LayerLocking_e.AskOnSceneOpen)
              {
            // user lock selection is not obeyed if a layer backup was detected, then the layer restore selection was responsible for locking the layers
            if (_useLayersBackupRestore)
            {
              foreach (Layer layer in _layersBackupRestoreSelection)
              {
            layer.TryLock(this, false);
              }
            }
            else
            {
              // Open layer lock dialog where user can select the layers to lock
              LayerLockDlg dlg = new LayerLockDlg();
              dlg.Scene = this;

              // Dialog has only an OK button as canceling the operation doesn't make much sense
              dlg.ShowDialog();
            }
              }
              else
              {
            foreach (Layer layer in Layers)
              layer.TryLock(this, false);
              }

              if (!newLayers.CheckLayerUniqueIDs())
              {
            EditorManager.ShowMessageBox("Layer IDs in this scene are not unique. Please contact support", "Layer ID conflict", MessageBoxButtons.OK, MessageBoxIcon.Warning);
              }

              // fixup exported layer names and put the Export flag into the layers own flag
              SceneExportProfile exportprofile = CurrentExportProfile;
              exportprofile.FixupLayerNames();
              if (exportprofile.LoadedFromFile) // preserve the flags loaded from Layer files otherwise
            exportprofile.ExportedLayersToScene();

              _iSceneversion = SCENE_VERSION_CURRENT; // however, scene version does not make much sense anymore

              // Mark all layers that have been restored from a backup as dirty
              foreach (Layer layer in _layersBackupRestoreSelection)
              {
            layer.Dirty = true;
              }

              // The scene is dirty if any layer was restored from a backup
              m_bDirty = (_useLayersBackupRestore && _layersBackupRestoreSelection.Count > 0);

              // Layers with backup have been dealt with, clean list for potential next selection
              _layersBackupRestoreSelection.Clear();

              EditorManager.Progress.SetRange(0.0f, 100.0f); // set back sub-range
              EditorManager.Progress.Percentage = 20.0f; // loaded layer files
              _bSceneLoadingInProgress = false;

              return true;
        }