Navigation:  I Want To... > Basics >

Create a mouse image viewer tool

Previous pageReturn to chapter overviewNext page

Use Case

You want the tool to map an operation to a mouse button so that on a mouse-drag, some property of the selected image changes (e.g., like how the zoom and pan operations work).
You want the tool to be associated with an ImageViewerComponent.

Relevant Architecture

Tools
Extending functionality with Tools

Relevant Types

ImageViewerToolExtensionPoint
MouseImageViewerTool
IImageViewerToolContext

Sample Code

using ClearCanvas.Common;

using ClearCanvas.Desktop;

using ClearCanvas.Desktop.Actions;

using ClearCanvas.ImageViewer;

using ClearCanvas.ImageViewer.BaseTools;

using ClearCanvas.ImageViewer.InputManagement;

 

// ... (other using namespace statements here)

 

namespace MyPlugin.Basics

{

   [MenuAction("activate""global-menus/MenuTools/MenuStandard/MenuMyMouseImageViewerTool""Select", Flags = ClickActionFlags.CheckAction)]

   [ButtonAction("activate""global-toolbars/ToolbarStandard/ToolbarMyMouseImageViewerTool""Select", Flags = ClickActionFlags.CheckAction)]

   [CheckedStateObserver("activate""Active""ActivationChanged")]

   [TooltipValueObserver("activate""Tooltip""TooltipChanged")]

   [IconSet("activate", IconScheme.Colour, "Icons.MyToolSmall.png""Icons.MyToolMedium.png""Icons.MyToolLarge.png")]

   [MouseToolButton(XMouseButtons.Right, false)]

   // ... (other action attributes here)

   [ExtensionOf(typeof (ImageViewerToolExtensionPoint))]

   public class MyMouseImageViewerTool : MouseImageViewerTool

   {

      public MyMouseImageViewerTool()

      {

         base.TooltipPrefix = "MyMouseImageViewerTool";

      }

 

      public override bool Start(IMouseInformation mouseInformation)

      {

         base.Start(mouseInformation);

 

         // TODO: Mouse down functionality

 

         return true;

      }

 

      public override bool Track(IMouseInformation mouseInformation)

      {

         base.Track(mouseInformation);

 

         // TODO: Mouse move functionality

 

         return true;

      }

 

      public override bool Stop(IMouseInformation mouseInformation)

      {

         base.Stop(mouseInformation);

 

         // TODO: Mouse up functionality

 

         return false;

      }

   }

}

Remarks

When the input device is a mouse, the Start, Track and Stop methods correspond to MouseDown, MouseMove and MouseUp events.  As a tool writer, your responsibility is to implement these methods.  Note that the behaviour where only one mouse tool is active at a time per mouse button is automatically handled for you; there is no need for you to code that functionality.  The only thing you need to do is to specify the MenuAction and ButtonAction with Select (a method in MouseImageViewerTool itself) as the click handler. Since a MouseImageViewerTool is an ImageViewerTool, it inherits all of the base class' functionality, including automatic disablement of the tool 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 a mouse image viewer tool.  To use the wizard to create a mouse image viewer tool:

1.Follow the instructions for creating a desktop tool, except:
2.On the ClearCanvas Tool Wizard that appears, select Mouse Image Viewer Tool under Template and click OK.  This will generate the appropriate boilerplate code.

3.Also, instead of filling out the Apply() method, fill out the Start(), Track() and Stop() methods.

Examples in Code Base

ClearCanvas.ImageViewer.Tools.Standard.ZoomTool
ClearCanvas.ImageViewer.Tools.Standard.ProbeTool