Antares Simulator
Power System Simulator
action.h
1 /*
2  * Copyright 2007-2025, RTE (https://www.rte-france.com)
3  * See AUTHORS.txt
4  * SPDX-License-Identifier: MPL-2.0
5  * This file is part of Antares-Simulator,
6  * Adequacy and Performance assessment for interconnected energy networks.
7  *
8  * Antares_Simulator is free software: you can redistribute it and/or modify
9  * it under the terms of the Mozilla Public Licence 2.0 as published by
10  * the Mozilla Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Antares_Simulator is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * Mozilla Public Licence 2.0 for more details.
17  *
18  * You should have received a copy of the Mozilla Public Licence 2.0
19  * along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20  */
21 #ifndef __ANTARES_LIBS_STUDY_ACTION_ACTION_H__
22 #define __ANTARES_LIBS_STUDY_ACTION_ACTION_H__
23 
24 #include <yuni/yuni.h>
25 #include <yuni/core/tree/treeN.h>
26 #include <yuni/core/string.h>
27 #include "fwd.h"
28 #include <antares/study/study.h>
29 #include <vector>
30 
31 namespace Antares::Action
32 {
33 class Context;
34 
35 class IAction: public Yuni::Core::TreeN<IAction>
36 {
37 public:
39  using AncestorType = Yuni::Core::TreeN<IAction>;
41  using Ptr = AncestorType::Ptr;
43  using ThreadingPolicy = AncestorType::ThreadingPolicy;
44 
46  using Vector = std::vector<Ptr>;
47 
49  using iterator = AncestorType::iterator;
50 
51 public:
53 
54 
57  IAction();
59  virtual ~IAction();
61 
65  Yuni::String caption() const;
66 
70  Yuni::String message() const;
71 
75  bool prepare(Context& ctx);
76 
80  void registerViews(Context& ctx);
81 
82  void datagridCaption(Yuni::String& title);
83 
87  bool prepareRootNode(Context& ctx);
88 
92  bool perform(Context& ctx, bool recursive = true);
93 
97  void dump() const;
98 
102  virtual bool bold() const;
103 
107  virtual bool autoExpand() const;
108 
112  virtual bool canDoSomething() const;
113 
114  virtual bool allowUpdate() const;
115  virtual bool allowSkip() const;
116  virtual bool allowOverwrite() const;
117  virtual bool shouldPrepareRootNode() const;
118 
120  virtual bool visible() const;
121 
123 
124  Behavior behavior() const;
127  void behavior(Behavior newBehavior);
129 
131  bool prepareStack(Vector& vector);
132 
134 
135  State state() const;
137 
139 
140  virtual void behaviorToText(Behavior behavior, Yuni::String& out);
142 
146  void createPostActions(const IAction::Ptr& node);
147 
148 protected:
150  virtual bool prepareWL(Context& ctx) = 0;
151 
153  virtual void prepareSkipWL(Context&)
154  {
155  }
156 
158  virtual bool performWL(Context& ctx) = 0;
159 
161  virtual void registerViewsWL(Context&)
162  {
163  }
164 
166  virtual void createPostActionsWL(const IAction::Ptr& node);
167 
168 protected:
171 
172 private:
173  void internalDump(Yuni::String& tmp, uint level) const;
174 
175 }; // class IAction
176 
177 } // namespace Antares::Action
178 
179 #include "action.hxx"
180 #include "context.h"
181 
182 #endif // __ANTARES_LIBS_STUDY_ACTION_ACTION_H__
Definition: context.h:36
Definition: action.h:36
virtual void createPostActionsWL(const IAction::Ptr &node)
Create post actions (if any)
Definition: action.hxx:82
std::vector< Ptr > Vector
Vector.
Definition: action.h:46
bool perform(Context &ctx, bool recursive=true)
Perform the action.
Definition: action.cpp:144
virtual bool bold() const
Get if the action should be represented with a bold font.
Definition: action.hxx:26
IAction()
Default constructor.
Definition: action.cpp:29
AncestorType::Ptr Ptr
The most suitable smart ptr for the class.
Definition: action.h:41
bool prepare(Context &ctx)
Make preparations for the execution.
Definition: action.cpp:101
Behavior behavior() const
Get the behavior.
Definition: action.hxx:36
AncestorType::iterator iterator
iterator
Definition: action.h:49
virtual void prepareSkipWL(Context &)
Prepare the execution (when the behavior says that the action should be skipped)
Definition: action.h:153
virtual void registerViewsWL(Context &)
Register all views.
Definition: action.h:161
virtual ~IAction()
Destructor.
Definition: action.cpp:34
bool prepareRootNode(Context &ctx)
Look for the root node and make preparations for the execution.
Definition: action.cpp:134
void dump() const
Dump the tree from this node to the stdcout.
Definition: action.cpp:56
Yuni::Core::TreeN< IAction > AncestorType
The ancestor.
Definition: action.h:39
ActionInformations pInfos
All data related to the action.
Definition: action.h:170
virtual bool autoExpand() const
Auto-expand.
Definition: action.hxx:31
void registerViews(Context &ctx)
Register if possible the action into the appropriate view.
Definition: action.cpp:124
bool prepareStack(Vector &vector)
Prepare the whole list of actions to execute in the given order.
Definition: action.cpp:179
virtual bool prepareWL(Context &ctx)=0
Prepare the execution.
virtual bool visible() const
Get if the action should be visible to the user.
Definition: action.hxx:77
Yuni::String message() const
Get the message of the action.
Definition: action.cpp:44
virtual bool performWL(Context &ctx)=0
Perform the action.
AncestorType::ThreadingPolicy ThreadingPolicy
The threading policy.
Definition: action.h:43
Yuni::String caption() const
Get the caption of the action.
Definition: action.cpp:38
void createPostActions(const IAction::Ptr &node)
Create post actions if required.
Definition: action.cpp:207