API Help
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, etc in graphic editor. For example when inserting a window macro on a page, EPLAN framework calls action: 

     

     XGedStartInteractionAction /Name:XMIaInsertMacro
    

     

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

    There are 2 general types of API Interactions usage : creating custom ones and overriding default (system). 

     

    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 Eplan::EplApi::EServices::Ged::InsertInteraction for interactions which insert objects on a page. It contains additional property showing placed object. 

     

    Interaction attributes 

    Programmer can decorate interaction class with Eplan::EplApi::EServices::Ged::InteractionAttribute to customize name of interaction, set name of interaction to override (see paragraph bellow), ordinal number and priority: 

     

    C#
    Copy Code
    //example of interaction attributes
        [InteractionAttribute(Name = "DerivedSymbolInsertInteraction", NameOfBaseInteraction = "XEGedIaInsertSymRef", Ordinal = 50, Prio = 20)]
        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";
                    }
                }
            }
        }
    

     

    For more details see Eplan::EplApi::EServices::Ged::InteractionAttribute

     

    Overriding default interactions 

    API interactions can also override default EPLAN interactions. This way execution will be passed to a user code instead of EPLAN core. 

    Such interactions has to derive from Interaction class also. Example how to do it is shown above (DerivedSymbolInsertInteraction) 

    The only change which has to be done is in InteractionAttribute : 

     

    [InteractionAttribute(Name = "XEGedIaInsertSymRef", NameOfBaseInteraction = "XEGedIaInsertSymRef", Ordinal = 50, Prio = 20)]
    

    How does this mechanism work ? 

    By default all events connected with inserting symbol operation are routed to the core interaction XEGedIaInsertSymRef. 

    But DerivedSymbolInsertInteraction can override default interaction by using 'NameOfBaseInteraction' and 'Name' property of the InteractionAttribute. 

     

    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

    API Interactions

    Reference