Eplan Platform API
EPLAN API / User Guide / API Electrotechnical services / Interactions
In This Topic
    Interactions
    In This Topic

    In EPLAN API, "interactions" term refers to classes used to handle events related to interactive work in GED. 

    Mechanism of interactions bases mostly on XGedStartInteractionAction action, which is invoked by EPLAN framework in case of moving, adding or selecting object in the graphical editor. For example when inserting a window macro on a page, EPLAN framework calls the action: 

     XGedStartInteractionAction /Name:XMIaInsertMacro
    

    Its parameter Name is used to pass a name of an interaction. 

    Usually interactions are used for 2 purposes: creating custom ones or overriding default (system). 

    Please be aware that interactions work only in a context of currently open page or layout space (InstallationSpace in API). Because of it, this is not possible to handle events from another windows, like navigators. Also when leaving current page, interaction is aborted by default (i.e. OnCancel method is called)

    Creating custom interactions 

    EPLAN API enables programmers to create their own custom interactions. 

     

    C#
    Copy Code
    public class DeleteTerminalsInteraction : Interaction
    {
       public override RequestCode OnStart(InteractionContext pContext)
       {
          // interaction has been stated.
          // set initial state
          m_state = State.Start;
          //
          // activate placement filter
          //
          IsPlacementFilterActive = true;
          //
          // request point and set prompt for user
          //
          this.PromptForStatusLine = "select Terminals";
          return  RequestCode.Select;
      }
    //can be used to filter for selection or for highlight
      public override bool OnFilterElement(StorableObject placement)
      {
         if (placement is Terminal)
         {
            return true;
         }
         return false;
       }
       public override RequestCode OnSelect(StorableObject[] placements, SelectionContext context)
       {
          m_Terminals = placements.Cast<Terminal>().ToArray();
          m_state = State.Select;
          return RequestCode.Success;
       }
       public override void OnSuccess(InteractionContext result)
       {
          if (m_state == State.Select)
          {
             for (int i = 0; i < m_Terminals.Length; i++)
             {
                m_Terminals[i].Remove();
             }
          }
       }
       enum State
       {
          Start = 0,
          Select,
       };
    
       State m_state;
       Terminal[] m_Terminals;
    }
    
        
    

     

    To add interaction to EPLAN , it must be included in an API add-in or addon. Interaction is registered under name of its class while loading an API add-in containing it. 

    There is also special class InsertInteraction for interactions which insert objects on a page. It contains additional property showing placed object. 

     

    Deriving interactions

    Programmer can derive a new interaction from existing one in order to inherit its functionality. In this case, there should be Interaction attribute set , with Name

    as a name of new interaction, NameOfBaseInteraction as a name of existing interaction. Also Ordinal number must be set to value higher than 30 .

    Following example shows how to create a new interaction derived from standard one for symbol insertion:

    C#
    Copy Code
        [Interaction(Name = "DerivedSymbolInsertInteraction", NameOfBaseInteraction = "XEGedIaInsertSymRef", Ordinal = 50)]
        class DerivedSymbolInsertInteraction : InsertInteraction
        {
            public override RequestCode OnStart(InteractionContext pContext)
            {
                return base.OnStart(pContext);
            }
            public override void OnSuccess(InteractionContext result)
            {
                // execute standard operation of symbol insert interaction
                //
                base.OnSuccess(result);
                //
                // set property of inserted function
                Placement[] placements = InsertedPlacements;
                for (int i = 0; i < placements.Length; i++)
                {
                    Function f = (Function)placements[i];
                    if (f != null)
                    {
                        f.Properties[Properties.Function.FUNC_TEXT] = "API_Demos : DerivedSymbolInsertInteraction";
                    }
                }
            }
        }
    

     

    Overriding default interactions 

    API interactions can also override default EPLAN interactions. This way the execution will be passed to a user code instead of EPLAN core. Such interactions has to derive from Interaction class also, as in case of derived interactions.  The only change which has to be made is in Interaction attribute, i.e both Name and NameOfBaseInteraction must be set to the same base interaction : 

     

    [Interaction(Name = "XEGedIaInsertSymRef", NameOfBaseInteraction = "XEGedIaInsertSymRef", Ordinal = 50)]
    

     

    This way all events connected with standard interaction (i.e inserting symbol  in this case) are routed to the core interaction XEGeIaInsertSymRef. 

    Getting feedback from GED 

    Most of interaction's methods return Eplan::EplApi::EServices::Ged::RequestCode which is used to control workflow of interaction. Default implementation of method Interaction::OnStart returns RequestCode::Success which causes end of interaction. If it's overridden and returns RequestCode::Point then interaction stays active, and when user clicks mouse button, method Interaction::OnPoint is called by EPLAN.

    See Also