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