/*=============================================================================
Project: SharpImage
Module: siFormRendererEditor.cs
Language: C#
Author: Dan Mueller
Date: $Date: 2007-07-27 03:48:36 +1000 (Fri, 27 Jul 2007) $
Revision: $Revision: 9 $
Copyright (c) Queensland University of Technology (QUT) 2007.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=============================================================================*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using SharpImage.Main;
using SharpImage.Rendering;
using SharpImage.Properties;
namespace SharpImage.Forms
{
public partial class siFormRendererEditor : siFormTool
{
#region Instance Variables
//=====================================================================
//=====================================================================
#endregion
#region Construction and Disposal
//=====================================================================
///
/// Default constructor.
///
/// The transfer function to edit.
public siFormRendererEditor(siVolumeRenderer renderer) : base(renderer)
{
// Init components
InitializeComponent();
// Setup the renderer
renderer.Modified += new siRenderer.siRendererHandler(renderer_Modified);
this.gridRenderer.SelectedObject = renderer.Properties;
}
//=====================================================================
#endregion
#region Methods
//=====================================================================
void renderer_Modified(siRenderer renderer, EventArgs e)
{
this.gridRenderer.ResetSelectedProperty();
}
private void cmdOpen_Click(object sender, EventArgs e)
{
// Show the open file dialog
OpenFileDialog ofd = new OpenFileDialog();
ofd.CheckFileExists = true;
ofd.CheckPathExists = true;
ofd.DefaultExt = "xml";
ofd.Filter = "Volume Properties XML files (*.xml)|*.xml";
ofd.Multiselect = false;
ofd.RestoreDirectory = true;
ofd.ShowHelp = false;
ofd.Title = "Please select the Volume Properties XML file to open...";
if (ofd.ShowDialog(this) == DialogResult.OK)
{
try
{
siVolumeProperties propsFromXmlFile = siVolumeProperties.FromXmlFile(this.Renderer as siVolumeRenderer, ofd.FileName);
if (propsFromXmlFile != null)
{
// Update the renderer
(this.Renderer as siVolumeRenderer).Properties = propsFromXmlFile;
this.Renderer.RaiseModified();
this.Renderer.Repaint();
// Update the form
this.gridRenderer.SelectedObject = propsFromXmlFile;
this.gridRenderer.Refresh();
}
}
catch (Exception ex)
{
string message = "An error occured while writing the Volume Properties XML file.\r\n\r\n" + ex.ToString();
string caption = "Unable to save Volume Properties to XML file";
MessageBox.Show(this, message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void cmdSave_Click(object sender, EventArgs e)
{
// Show the save file dialog
SaveFileDialog sfd = new SaveFileDialog();
sfd.CheckFileExists = false;
sfd.CheckPathExists = true;
sfd.DefaultExt = "xml";
sfd.Filter = "Volume Properties XML files (*.xml)|*.xml";
sfd.RestoreDirectory = true;
sfd.ShowHelp = false;
sfd.Title = "Please select the Volume Properties XML file to open...";
if (sfd.ShowDialog(this) == DialogResult.OK)
{
try
{
if (this.Renderer is siVolumeRenderer)
(this.Renderer as siVolumeRenderer).Properties.ToXmlFile(sfd.FileName);
}
catch (Exception ex)
{
string message = "An error occured while writing the Volume Properties XML file.\r\n\r\n" + ex.ToString();
string caption = "Unable to save Volume Properties to XML file";
MessageBox.Show(this, message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
//=====================================================================
#endregion
}
}