Use Case
| • | You want the tool to perform an operation on the currently selected image when you click a toolbar button, or select a menu item. |
| • | You want the tool to be associated with an ImageViewerComponent. |
Relevant Architecture
Relevant Types
| • | ImageViewerToolExtensionPoint |
| • | ImageViewerTool |
| • | IImageViewerToolContext |
Sample Code
using ClearCanvas.Common;
using ClearCanvas.Desktop;
using ClearCanvas.Desktop.Actions;
using ClearCanvas.ImageViewer;
using ClearCanvas.ImageViewer.BaseTools;
// ... (other using namespace statements here)
namespace MyPlugin.Basics
{
[MenuAction("apply", "global-menus/MenuTools/MenuStandard/MenuMyImageViewerTool", "Apply")]
[ButtonAction("apply", "global-toolbars/ToolbarStandard/ToolbarMyImageViewerTool", "Apply")]
[Tooltip("apply", "TooltipMyImageViewerTool")]
[IconSet("apply", IconScheme.Colour, "Icons.MyToolSmall.png", "Icons.MyToolMedium.png", "Icons.MyToolLarge.png")]
[EnabledStateObserver("apply", "Enabled", "EnabledChanged")]
// ... (other action attributes here)
[ExtensionOf(typeof (ImageViewerToolExtensionPoint))]
public class MyImageViewerTool : ImageViewerTool
{
/// <summary>
/// Default constructor. A no-args constructor is required by the
/// framework. Do not remove.
/// </summary>
public MyImageViewerTool() {}
/// <summary>
/// Called by the framework to initialize this tool.
/// </summary>
public override void Initialize()
{
base.Initialize();
// TODO: add any significant initialization code here rather than in the constructor
}
/// <summary>
/// Called by the framework when the user clicks the "apply" menu item or toolbar button.
/// </summary>
public void Apply()
{
// Add code here to implement the functionality of the tool
if (this.SelectedPresentationImage == null)
return;
}
}
}
Remarks
The ImageViewerTool class provides a number of convenience properties such as SelectedPresentationImage, SelectedSpatialTransformProvider, etc. that help you manipulate the selected PresentationImage. ImageViewerTool derived tools also disable themselves automatically when no image is currently selected.
Using the Wizard
The ClearCanvas SDK provides some useful wizards to make common tasks a little easier. One such task is creating an image viewer tool. To use the wizard to create an image viewer tool:
| 1. | Follow the instructions for creating a desktop tool, except: |
| 2. | On the ClearCanvas Tool Wizard that appears, select Image Viewer Tool under Template and click OK. This will generate the appropriate boilerplate code. |

Examples in Code Base
| • | ClearCanvas.ImageViewer.Tools.Standard.FlipHorizontalTool |
| • | ClearCanvas.ImageViewer.Tools.Standard.LocateOnDiskTool |