private void newToolStripMenuItem_Click(object sender, EventArgs e) { if (!CheckUnsavedChanges()) { return; } if (openImageDialog.ShowDialog() == DialogResult.OK) { var projectDir = Path.GetDirectoryName(openImageDialog.FileName); saveProjectDialog.InitialDirectory = projectDir; project = new OrthoProject(); project.Radiograph = openImageDialog.FileName; UpdateSetScale(true); InitializeProject(projectDir); } }
void OpenProject(string fileName) { saveProjectDialog.FileName = fileName; using (var reader = XmlReader.Create(fileName)) { var serializer = new XmlSerializer(typeof(OrthoProject)); try { project = (OrthoProject)serializer.Deserialize(reader); } catch (InvalidOperationException) { project = null; MessageBox.Show("Unrecognized file format. Please check if project file is compatible with this version of OpenOrtho.", "Invalid file format", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } UpdateSetScale(false); InitializeProject(Path.GetDirectoryName(fileName)); } }
void InitializeProject(string projectDir) { if (background != null) { background.Dispose(); } var radiographPath = Path.IsPathRooted(project.Radiograph) ? project.Radiograph : Path.Combine(projectDir, project.Radiograph); if (!File.Exists(radiographPath)) { radiographPath = project.Radiograph; project = null; MessageBox.Show(string.Format("Radiograph image file {0} is missing. Unable to load project data.", radiographPath), "Missing radiograph image file", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } using (var bitmap = new Bitmap(radiographPath)) { var query = new int[1]; GL.GetInteger(GetPName.MaxTextureSize, query); var maxSize = query[0]; textureWidth = backgroundWidth = bitmap.Width; textureHeight = backgroundHeight = bitmap.Height; if (!nonPowerOfTwo || backgroundWidth > maxSize || backgroundHeight > maxSize) { textureWidth = Math.Min(maxSize, Utilities.NearestPowerOfTwo(backgroundWidth)); textureHeight = Math.Min(maxSize, Utilities.NearestPowerOfTwo(backgroundHeight)); using (var potsBitmap = new Bitmap(bitmap, textureWidth, textureHeight)) { background = Texture2D.FromBitmap(potsBitmap); } } else { background = Texture2D.FromBitmap(bitmap); } } analysisPropertyGrid.SelectedObject = project; analysisPropertyGrid.Enabled = true; ResetProjectStatus(); }