private void button_CreateProfile_Click(object sender, EventArgs e)
    {
      if (!PromptProfileModified())
        return;

      CreateFileDlg dlg = new CreateFileDlg();
      dlg.InitialDirectory = EditorManager.Scene.LayerDirectoryName;
      dlg.Caption = "Creating a new Export Profile";
      dlg.Description = "Enter the name of the new profile file.";
      dlg.Ext = "." + SceneExportProfile.FILE_EXTENSION_EXPORTPROFILE;
      dlg.Filter = new string[] { dlg.Ext.ToLower() };
      dlg.AllowOverwrite = false;
      dlg.SupportCustomDirectories = false;
      dlg.AllowFolderCreation = false;

      if (dlg.ShowDialog(this) != DialogResult.OK)
        return;
      SceneExportProfile settings = Settings;
      string oldName = settings.ProfileName;
      settings.ProfileName = Path.GetFileNameWithoutExtension(dlg.FileName);
      if (!SaveProfile(settings))
      {
        settings.ProfileName = oldName;
        return;
      }
      Settings = settings; // create unmodified copy
    }
    bool SaveProfile(SceneExportProfile settings)
    {
      if (!settings.SaveToFile())
      {
        EditorManager.ShowMessageBox("Failed to save export profile '" + settings.ProfileName + "'", "Export Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return false;
      }
      Settings = settings; // clone and update UI
      _settingsUnmodified = (SceneExportProfile)settings.Clone();

      return true;
    }
 private void comboBox_Profile_SelectionChangeCommitted(object sender, EventArgs e)
 {
   if (comboBox_Profile.SelectedItem == null)
     return;
   string newName = comboBox_Profile.SelectedItem.ToString();
   if (_settings != null && string.Compare(_settings.ProfileName, newName, true) == 0)
     return;
   if (!PromptProfileModified())
   {
     // switch back to old profile
     UpdateButtonStates();
     return;
   }
   SceneExportProfile newProfile = SceneExportProfile.LoadProfile(EditorManager.Scene, newName, true);
   if (newProfile == null)
   {
     EditorManager.ShowMessageBox("Failed to load '" + newName + "'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     UpdateButtonStates();
     return;
   }
   Settings = newProfile; // clone and apply to UI
   _settingsUnmodified = (SceneExportProfile)newProfile.Clone();
 }
Exemple #4
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;
        }
Exemple #5
0
        /// <summary>
        /// Overridden scene close function
        /// </summary>
        /// <returns></returns> 
        public override bool Close()
        {
            // Close a possibly open description dialog when closing the scene
              if (_descriptionDialog != null)
              {
            _descriptionDialog.FormClosed -= new FormClosedEventHandler(_OnDescriptionDialogClosed);
            if (!_descriptionDialog.IsDisposed)
              _descriptionDialog.Close();
              }

              EditorManager.OnSceneEvent(new SceneEventArgs(SceneEventArgs.Action.BeforeClosing, true));

              // unlock the file (layers)
              foreach (Layer layer in Layers)
            layer.ReleaseLock(false, false);

              // Delete the scene file watcher that listens for lock/layer file changes.
              RemoveFileWatcher();

              // Stop playback
              EditorManager.EditorMode = EditorManager.Mode.EM_NONE;
              OnRemoveAllEngineInstances();

              // Remove interim layer backup files (has to be done before setting Project.Scene to null)
              foreach (Layer layer in Layers)
              {
            if(!layer.IsReference)
              layer.DeleteInterimBackup();
              }

              Project.Scene = null;

              EditorManager.EngineManager.DeInitScene();

              _currentProfile = null;

              bool bResult = base.Close();

              EditorManager.OnSceneEvent(new SceneEventArgs(SceneEventArgs.Action.AfterClosing, bResult));

              return bResult;
        }
        bool DeleteProfile(SceneExportProfile settings)
        {
            if (comboBox_Profile.Items.Count <= 1)
              {
            EditorManager.ShowMessageBox("Can't delete the last export preset '" + settings.ProfileName + "'", "Delete Export Preset Failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return false;
              }

              if (EditorManager.ShowMessageBox("Do you want to delete the export preset '" + settings.ProfileName + "'?", "Delete Export Preset?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
              {
            return false;
              }

              if (!settings.DeleteFile())
              {
            EditorManager.ShowMessageBox("Failed to delete preset '" + settings.ProfileName + "'.\nMake sure the file '" + settings.FileName + "' is writable.", "Delete Export Preset Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return false;
              }

              // We do not want that popup that the export preset we just deleted is modified.
              _bForceReturnNotModified = true;
              // Rebuild the export preset combobox and select its new first index.
              FillProfileCombobox();
              comboBox_Profile.SelectedIndex = 0;
              // Changing SelectedIndex does not invoke selection changed, so we do so manually.
              comboBox_Profile_SelectionChangeCommitted(null, null);
              _bForceReturnNotModified = false;
              // The Settings property has now been modified and we need to push it back to the global settings as it may still be the just deleted one.
              EditorManager.Scene.CurrentExportProfile = Settings;
              return true;
        }
 private void comboBox_Profile_SelectionChangeCommitted(object sender, EventArgs e)
 {
     if (comboBox_Profile.SelectedItem == null)
     return;
       string newName = comboBox_Profile.SelectedItem.ToString();
       if (_settings != null && string.Compare(_settings.ProfileName, newName, true) == 0)
     return;
       if (!PromptProfileModified())
       {
     // switch back to old profile
     UpdateButtonStates();
     return;
       }
       SceneExportProfile newProfile = SceneExportProfile.LoadProfile(EditorManager.Scene, newName, true);
       if (newProfile == null)
       {
     EditorManager.ShowMessageBox("Failed to load '" + newName + "'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     UpdateButtonStates();
     return;
       }
       Settings = newProfile; // clone and apply to UI
       _settingsUnmodified = (SceneExportProfile)newProfile.Clone();
 }
        bool SaveProfile(SceneExportProfile settings)
        {
            if (!settings.SaveToFile())
              {
            EditorManager.ShowMessageBox("Failed to save export preset '" + settings.ProfileName + "'", "Export Preset Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return false;
              }
              Settings = settings; // clone and update UI
              _settingsUnmodified = (SceneExportProfile)settings.Clone();

              return true;
        }
        public override bool ExportScene(string absPath, bool bShowDialog)
        {
            string assetProfileOverride = null;

              // if we do not show the dialog, we must use the active profile
              if (!bShowDialog)
              {
            assetProfileOverride = EditorManager.ProfileManager.GetActiveProfile()._name;
              }

              if (bShowDialog)
              {
            // Open export dialog
            ExportDialog dlg = new ExportDialog();
            using (dlg)
            {
              CurrentExportProfile.ExportedLayersFromScene(); // retrieve current status
              dlg.Settings = CurrentExportProfile; // clones the settings
              dlg.AutoSaveExportProfile = Settings.AutoSaveExportProfile;

              // Show dialog
              if (dlg.ShowDialog() != DialogResult.OK)
            return true;

              // Get back settings
              SceneExportProfile newProfile = dlg.Settings;
              if (!CurrentExportProfile.Equals(newProfile))
            Dirty = true;
              _currentProfile = newProfile;
              Settings.ExportProfileName = CurrentExportProfile.ProfileName;
              Settings.AutoSaveExportProfile = dlg.AutoSaveExportProfile;

              if (dlg.ExportActiveProfileOnly)
              {
            assetProfileOverride = EditorManager.ProfileManager.GetActiveProfile()._name;
              }

              EditorManager.EngineManager.CheckLightGridDataExists();
            }
              }

              // Deactivate isolate selection mode temporarily
              EditorManager.ActiveView.IsolateSelection(false, true);

              // Ensure that scene script file is set in script manager
              // This is e.g. required if the script was broken when the scene was loaded but it was corrected in the meantime
              // then the exporter scene will have the proper script
              string sceneScriptFile = ((V3DLayer)EditorManager.Scene.MainLayer).SceneScriptFile;
              if (sceneScriptFile != null && sceneScriptFile.Length > 0)
              {
            ScriptManager.SetSceneScriptFile(sceneScriptFile);
              }

              // Export
              bool bSuccess = ExportScene(absPath, assetProfileOverride);
              string absExportPath = absPath;
              if (absExportPath == null)
            absExportPath = AbsoluteExportPath;

              // Reactivate isolate selection mode
              EditorManager.ActiveView.IsolateSelection(true, true);

              // now launch the viewer
              if (bSuccess && CurrentExportProfile.RunAfterExport)
              {
            // Try to find the optimal profile to run:
            string profileToRun = null;
            if (assetProfileOverride != null)
            {
              // If exporting for one specific profile, use that one
              profileToRun = assetProfileOverride;
            }
            else if (CurrentExportProfile.SelectedAssetProfiles.IsActiveProfileSet)
            {
              // If the current profile is among the selected profiles, use that one
              profileToRun = EditorManager.ProfileManager.GetActiveProfile()._name;
            }
            else
            {
              // Otherwise, use the first profile we can find.
              foreach (IProfileManager.Profile profile in EditorManager.ProfileManager.GetProfiles())
              {
            if (CurrentExportProfile.SelectedAssetProfiles.IsProfileSet(profile._name))
            {
              profileToRun = profile._name;
              break;
            }
              }
            }

            // If there is a profile we can run, start the scene viewer.
            if (profileToRun != null)
            {
              string sceneToRun = absExportPath;
              string oldExtension = Path.GetExtension(sceneToRun);
              sceneToRun = Path.ChangeExtension(sceneToRun, profileToRun) + oldExtension;

              string path = Path.GetDirectoryName(Application.ExecutablePath);
              string absSceneViewerPath = Path.Combine(path, "vSceneViewer.exe");
              FileHelper.RunExternalTool("Scene Viewer", absSceneViewerPath, "\"" + sceneToRun + "\"", false);
            }
              }
              return bSuccess;
        }