001package jmri.jmrit.logixng;
002
003import jmri.NamedBean;
004
005/**
006 * LogixNG.
007 *
008 * @author Daniel Bergqvist Copyright 2018
009 * @author Dave Sand        Copyright 2021
010 */
011public interface LogixNG extends Base, NamedBean {
012
013    String PROPERTY_ENABLED = "Enabled";
014    String PROPERTY_INLINE = "IsInline";
015
016    /**
017     * Clear the startup flag.
018     */
019    void clearStartup();
020
021    /**
022     * Determines whether this LogixNG is currently during startup.
023     *
024     * @return true if the LogixNG is currently during startup, false otherwise
025     */
026    public boolean isStartup();
027
028    /**
029     * Sets whether this LogixNG is inline or not.
030     *
031     * @param inline true if the LogixNG is inline, false otherwise
032     */
033    void setInline(boolean inline);
034
035    /**
036     * Determines whether this LogixNG is inline or not.
037     *
038     * @return true if the LogixNG is inline, false otherwise
039     */
040    boolean isInline();
041
042    /**
043     * Set the InlineLogixNG that owns this LogixNG, if the LogixNG is inline.
044     *
045     * @param inlineLogixNG the InlineLogixNG that owns this LogixNG, if the LogixNG is inline.
046     */
047    void setInlineLogixNG(InlineLogixNG inlineLogixNG);
048
049    /**
050     * Get the InlineLogixNG that owns this LogixNG, if the LogixNG is inline.
051     *
052     * @return the InlineLogixNG
053     */
054    InlineLogixNG getInlineLogixNG();
055
056    /**
057     * Set whenether this LogixNG is enabled or disabled.
058     * <P>
059     * This method must call registerListeners() / unregisterListeners() and
060     * also call execute() if enable is true.
061     *
062     * @param enable true if this LogixNG should be enabled, false otherwise
063     */
064    void setEnabled(boolean enable);
065
066    /**
067     * Determines whether this LogixNG is enabled.
068     *
069     * @return true if the LogixNG is enabled, false otherwise
070     */
071    @Override
072    boolean isEnabled();
073
074    /**
075     * Activates this LogixNG.
076     * <P>
077     * This method is called by the LogixNG manager during
078     * initialization of the LogixNGs.
079     */
080    void activate();
081
082    /**
083     * Activates/deactivates this LogixNG.
084     * <P>
085     * This method is used by the LogixNG action EnableLogixNG to temporary
086     * activate or deactivate a LogixNG.
087     * @param active true if activate, false if deactivate
088     */
089    public void setActive(boolean active);
090
091    /**
092     * Set the system name for the conditionalNG at the specified position in this list
093     * @param index index of the element to set the system name
094     * @return the system name
095     */
096    String getConditionalNG_SystemName(int index);
097
098    /**
099     * Set the system name for the conditionalNG at the specified position in this list
100     * @param index index of the element to set the system name
101     * @param systemName the new system name
102     */
103    void setConditionalNG_SystemName(int index, String systemName);
104
105    /**
106     * Get number of ConditionalNGs for this LogixNG.
107     *
108     * @return the number of conditionals
109     */
110    int getNumConditionalNGs();
111
112    /**
113     * Move 'row' to 'nextInOrder' and shift all between 'nextInOrder' and 'row'
114     * up one position. Requires {@code row > nextInOrder}.
115     *
116     * @param nextInOrder target order for ConditionalNG at row
117     * @param row         position of ConditionalNG to move
118     */
119    void swapConditionalNG(int nextInOrder, int row);
120
121    /**
122     * Returns the conditionalNG that will calculate in the specified order.
123     * This is also the order the ConditionalNG is listed in the
124     * Add/Edit LogixNG dialog. If 'order' is greater than the number of
125     * ConditionalNGs for this LogixNG, null is returned.
126     *
127     * @param order order in which the ConditionalNG calculates
128     * @return the conditionalNG or null
129     */
130    ConditionalNG getConditionalNG(int order);
131
132    /**
133     * Add a child ConditionalNG to the parent LogixNG.
134     * <p>
135     * The first part handles adding conditionalNGs to the LogixNG list
136     * during file loading.
137     * <p>
138     * The second part handles normal additions using the GUI, Logix imports or tests.
139     *
140     * @param conditionalNG The ConditionalNG object.
141     * @return true if the ConditionalNG was added, false otherwise.
142     */
143    boolean addConditionalNG(ConditionalNG conditionalNG);
144
145    /**
146     * Get a ConditionalNG belonging to this LogixNG.
147     *
148     * @param systemName The name of the ConditionalNG object.
149     * @return the ConditionalNG object or null if not found.
150     */
151    ConditionalNG getConditionalNG(String systemName);
152
153    /**
154     * Get a ConditionalNG belonging to this LogixNG.
155     *
156     * @param userName The name of the ConditionalNG object.
157     * @return the ConditionalNG object or null if not found.
158     */
159    ConditionalNG getConditionalNGByUserName(String userName);
160
161    /**
162     * Delete a ConditionalNG from this LogixNG.
163     * <p>
164     * Note: Since each LogixNG must have at least one ConditionalNG, the last
165     * ConditionalNG will not be deleted.
166     * <p>
167     * Returns An array of names used in an error message explaining why
168     * ConditionalNG should not be deleted.
169     *
170     * @param conditionalNG The ConditionalNG to delete
171     */
172    void deleteConditionalNG(ConditionalNG conditionalNG);
173
174    /**
175     * Is this item active?
176     * This method returns true if the the LogixNG is active but not enabled,
177     * while the method {@link #isActive() } only returns true if the LogixNG
178     * is both active and enabled.
179     * @return true if active, false otherwise.
180     */
181    boolean isActivated();
182
183    /**
184     * Execute all ConditionalNGs if the LogixNG is enabled and activated.
185     */
186    void execute();
187
188    /**
189     * Execute all ConditionalNGs if the LogixNG is enabled and activated.
190     * @param allowRunDelayed true if it's ok to run delayed, false otherwise
191     */
192    void execute(boolean allowRunDelayed);
193
194    /**
195     * Execute all ConditionalNGs if the LogixNG is enabled and activated.
196     * @param allowRunDelayed true if it's ok to run delayed, false otherwise
197     * @param isStartup true if startup, false otherwise
198     */
199    void execute(boolean allowRunDelayed, boolean isStartup);
200
201}