TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

Register
 
When replying to a specific statement be sure to quote the previous post.

Tool behavior handling in TurboCAD .NET SDK environment
Read 3388 times
* September 28, 2010, 06:25:12 AM
How to control the tool's behavior:
1) When the user clicks on the tool to tell the tool to stay active - its icon to remain clicked.
2) Show status messages to give directions to the user what to do next i.e. click to enter a point
3) Add additinal options in the context menu when the tool is active.

I am using the .NET TurboCAD SDK throgh C#. I am not using COM, VB, AutoIT or whatever other language.

Observations and experiments to gain access to the tool's behavior:
=======================

I tried using the events interface:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

namespace IMSIGX
{
   public interface Application : IApplication, IAppEvents_Event
     
   ...

}

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

namespace IMSIGX
{
   public interface IAppEvents_Event
   {
      event IAppEvents_BeforeDoubleClickEventHandler BeforeDoubleClick;

      ...
   }
}

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

namespace IMSIGX
{
   public enum ImsiEventMask
   {
      imsiEventBeforeExit = 1,

      ...
   }
}

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

... in the .NET SDK but registering events within the active application:

public void RunToolEventHandler(Tool WhichTool)
{
}

public bool Initialize(object Tool)
{
   IMSIGX.Tool t = (IMSIGX.Tool) Tool;
   IMSIGX.Application app = (IMSIGX.Application) t.Application;

   app.RunTool += RunToolEventHandler; // exception
}

Either I am not filling the delegate in the proper place (probably it should not be done in Initialize) or the t.Application is of IMSIGX.IApplication type not of IMSIGX.Appplication (without the 'I' in front of Application). If the latter is the case the line:

   IMSIGX.Application app = (IMSIGX.Application) t.Application;

... should rise exception. It doesn't rise an exception.

The C++ COM SDK allows the user to access tool's behavior through the IToolEvents interface declared in xdbtool.h

The second question is whether there is IToolEvents equivalent in the .NET SDK?

There is IMSIGX.Application.ToolEvents gettable property which has System.Object return type. But what is the actual type of the variable returned by ToolEvents? GetType tells the type is "System.__ComObject".

Logged


* October 01, 2010, 05:01:59 AM
#1
Finally, I managed to detect application events using the TurboCAD's .NET SDK.
The example provided below is a C# equivalent to the sample SDK C++ COM project given along with the TurboCAD's SDK.

Visual Studio 2010 is used.

Now what's left is to figure out how to detect tool events - such as:
1) when the user clicks on the icon of a given tool engrave the tool's icon to show that it has been activated
2) change tool status message when a point is clicked after the tool has already been activated
3) make the user draw not only points but rectangles, circles, or any other kind of geometry when the tool has already been activated

Probably this sample code should be added to the contributions section as well.

Logged