score-plugin-scenario/Scenario/Document/Graph.hpp
1 #pragma once
2 #include <score/tools/std/HashMap.hpp>
3 
4 #include <boost/graph/adjacency_list.hpp>
5 #include <boost/graph/directed_graph.hpp>
6 
7 #include <QObject>
8 
9 #include <nano_observer.hpp>
10 #include <score_plugin_scenario_export.h>
11 
12 namespace Scenario
13 {
14 class TimeSyncModel;
15 class IntervalModel;
16 class EventModel;
17 class StateModel;
18 class ScenarioInterface;
19 class ProcessModel;
20 
21 using GraphVertex = Scenario::TimeSyncModel*;
22 using GraphEdge = Scenario::IntervalModel*;
23 
24 using Graph = boost::directed_graph<GraphVertex, GraphEdge>;
25 /*
26 using Graph = boost::adjacency_list<
27  boost::vecS,
28  boost::vecS,
29  boost::directedS,
30  GraphVertex,
31  GraphEdge>;
32 */
41 struct SCORE_PLUGIN_SCENARIO_EXPORT TimenodeGraphConnectedComponent
42 {
43  std::vector<const Scenario::TimeSyncModel*> syncs;
44  std::vector<const Scenario::IntervalModel*> intervals;
45 
46  bool isMain(const Scenario::ProcessModel&) const;
47 };
48 struct SCORE_PLUGIN_SCENARIO_EXPORT TimenodeGraphComponents
49 {
50  const Scenario::ProcessModel& scenario;
51  std::vector<TimenodeGraphConnectedComponent> comps;
52 
54  component(const Scenario::TimeSyncModel& c) const;
55  bool isInMain(const Scenario::TimeSyncModel& c) const;
56  bool isInMain(const Scenario::IntervalModel& c) const;
57  bool isInMain(const Scenario::EventModel& c) const;
58  bool isInMain(const Scenario::StateModel& c) const;
59 };
60 struct SCORE_PLUGIN_SCENARIO_EXPORT TimenodeGraph
61  : public QObject
62  , public Nano::Observer
63 {
65 
66  const Graph& graph() const { return m_graph; }
67  const auto& edges() const { return m_edges; }
68  const auto& vertices() const { return m_vertices; }
69 
71  bool hasPath(const TimeSyncModel& t1, const TimeSyncModel& t2) const noexcept;
72 
73  bool hasCycles() const noexcept;
75  void writeGraphviz();
76 
77  TimenodeGraphComponents components();
78 
79 private:
80  void intervalsChanged(const IntervalModel&);
81  void timeSyncsChanged(const TimeSyncModel&);
82  void recompute();
83 
84  const Scenario::ProcessModel& m_scenario;
85  Graph m_graph;
86  bool m_cycles{};
87 
88  score::hash_map<const Scenario::TimeSyncModel*, Graph::vertex_descriptor> m_vertices;
89  score::hash_map<const Scenario::IntervalModel*, Graph::edge_descriptor> m_edges;
90 };
91 }
Definition: EventModel.hpp:36
Definition: IntervalModel.hpp:50
The core hierarchical and temporal process of score.
Definition: ScenarioModel.hpp:37
Definition: StateModel.hpp:63
Definition: TimeSyncModel.hpp:34
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Definition: score-plugin-scenario/Scenario/Document/Graph.hpp:49
A directed graph of all the TimeSyncs in a ScenarioInterface.
Definition: score-plugin-scenario/Scenario/Document/Graph.hpp:42
Definition: score-plugin-scenario/Scenario/Document/Graph.hpp:63