Modlr plugin

A Plugin interface is an easy way to allow for you to add your own extensions.

We have now extended the Plugin with yet another interface to facilitate the adding of custom ocl operations. This way the design time functions like CheckModel, ViewModels and OclEditor can be made to recognize your custom operations.

  1. namespace Modlr.Plugins
  2. {
  3.     public interface IModlrPlugin
  4.     {
  5.         string GetName();
  6.         List<IModlrPluginMenuOperation> ProvideOperations();
  7.     }
  8.  
  9.     public interface IModlrPluginMenuOperation
  10.     {
  11.         string GetName();
  12.         void CheckEnableOrExecute(IEcoServiceProvider esp, bool execute, IEcoObject maincontext, IEcoObject subcontext,out bool enabled );
  13.     }
  14.  
  15.  
  16.     public enum CallbackEventKind {CodeGen,ForcedCodeGen };
  17.     public interface IModlrPluginImportantEventCallbackHandler
  18.     {
  19.         void ImportantEventAboutToHappen(IEcoServiceProvider esp, CallbackEventKind eventkind, ref bool stop, ref string message);
  20.         void ImportantEventHasHappend(IEcoServiceProvider esp, CallbackEventKind eventkind);
  21.     }
  22.  
  23.     public interface IModlrPluginModelAccessOclType
  24.     {
  25.       /// <summary>
  26.       /// Possible usage – add custom ocl operations that can then be correctly executed by WECPOF and correctly evaluated in OCL design time
  27.       /// </summary>
  28.       void RuntimeModelAccess(IOclTypeService ocl);
  29.     }
  30.  
  31.  
  32. }

 

I added an example in the demos folder called ModlrPluginCodeGenEventsAndCustomOCLOperations

Not going to repeat everything here but a few goodies.

  1. namespace ModlrPluginCodeGenEventsAndCustomOCLOperations
  2. {
  3.   public class Plugindemo : IModlrPlugin, IModlrPluginMenuOperation, IModlrPluginModelAccessOclType, IModlrPluginImportantEventCallbackHandler
  4.   {
  5.     public string GetName()
  6.     {
  7.       return "AnotherPlugin";
  8.     }

The IModlrPluginImportantEventCallback can do things on codegen>

  1. public void ImportantEventAboutToHappen(Eco.ObjectRepresentation.IEcoServiceProvider esp, CallbackEventKind eventkind, ref bool stop, ref string message)
  2. {
  3.   // Here you can perform checks before codegen, and optionally stop the codegen
  4.   System.Windows.Forms.MessageBox.Show("You are updating the code, this annoying message came from plugin ModlrPluginCodeGenEventsAndCustomOCLOperations");
  5. }

But the brand new interface is the IModlrPluginModelAccessOclType>

  1. public void RuntimeModelAccess(IOclTypeService ocl)
  2. {
  3.   ocl.InstallOperation(new CustomOCL_SplitAtSemi());
  4. }

And the operation (really a different subject) looks like this:

  1. public class CustomOCL_SplitAtSemi : OclOperationBase
  2. {
  3.   public CustomOCL_SplitAtSemi()
  4.   {
  5.   
  6.   }
  7.  
  8.   protected override void Init()
  9.   {
  10.     InternalInit("SplitAtSemi", new IOclType[] { Support.StringType }, Support.StringType);
  11.  
  12.   }
  13.  
  14.   public override void Evaluate(IOclOperationParameters __Params)
  15.   {
  16.     string s = Support.GetAsString(__Params.Values[0]);
  17.     string[] ss=s.Split(';');
  18.     string first = "";
  19.     if (ss.Length > 0)
  20.       first = ss[0];
  21.     Support.MakeNewString(__Params.Result, first);
  22.   }
  23. }

So this is really super because my model validates in design time even if I use the custom operation:

image

Viewmodel columns that use the custom expression are evaluated correctly:

image

CheckModel stays empty since everything is validated:

image

And of course the prototyping actually executes your operations:

image

This entry was posted in CO-Unique, Modlr, OCL, Plugin. Bookmark the permalink.

7 Responses to Modlr plugin

  1. Pingback: GB Bilder » Modlr plugin | CapableObjects

  2. Rick W says:

    Can I download the samples somewhere or do I just have to wait for the next daily build? I have 5580 from 5/20, but do not have this sample – I assume you just added it.

  3. Rick W says:

    Hmmm, just tried the latest daily build listed and still no IModlrPluginModelAccessOclType defined or sample listed.

  4. Rick W says:

    Did you ever check to see if this worked with the PM Validate Model and at runtime?

    • Rick W says:

      I had a problem, but I see how I caused it. The important thing for people to know is that you must add the custom ocl operation class to your EcoSpace in addition to providing it to this new plug-in feature.

  5. guest00 says:

    Hi Hans,
    Could you please explain how to register custom EAL operation using this really useful plugin functionality?
    Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *

*