Warning, file /graphics/glaxnimate/src/core/model/comp_graph.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include <vector>
0010 #include <unordered_map>
0011 
0012 namespace glaxnimate::model {
0013 
0014 class Composition;
0015 class PreCompLayer;
0016 class Document;
0017 
0018 /**
0019  * \brief Dependency graph between compositions.
0020  *
0021  * The graph is a directed acyclic graph, rooted in the main composition of a document.
0022  * I might not be connected as you could have comps not used anywhere.
0023  *
0024  * This graph is used to avoid cyclical dependencies.
0025  */
0026 class CompGraph
0027 {
0028 public:
0029     /**
0030      * \brief Adds a composition and scans it for existing layers
0031      */
0032     void add_composition(model::Composition* comp);
0033 
0034     /**
0035      * \brief Remove a composition from the graph
0036      */
0037     void remove_composition(model::Composition* comp);
0038 
0039     /**
0040      * \brief Registers \p layer to be a layer in \p comp.
0041      */
0042     void add_connection(model::Composition* comp, model::PreCompLayer* layer);
0043 
0044     /**
0045      * \brief Registers \p layer to no longer be a layer in \p comp.
0046      */
0047     void remove_connection(model::Composition* comp, model::PreCompLayer* layer);
0048 
0049     /**
0050      * \brief Returns a list of composition used by \p comp,
0051      */
0052     std::vector<model::Composition*> children(model::Composition* comp) const;
0053 
0054     /**
0055      * \brief Returns whether starting from \p ancestor you can find a path to \p descendant using precomp layers.
0056      *
0057      * A comp is considered being ancestor of itself.
0058      */
0059     bool is_ancestor_of(model::Composition* ancestor, model::Composition* descendant) const;
0060 
0061     /**
0062      * \brief Returns a list of compositions that can be added as a child of \p ancestor.
0063      *
0064      * Basically all the precomps in \p document that are not ancestors of \p ancestor.
0065      */
0066     std::vector<model::Composition*> possible_descendants(model::Composition* ancestor, model::Document* document) const;
0067 
0068 private:
0069     std::unordered_map<model::Composition*, std::vector<model::PreCompLayer*>> layers;
0070 };
0071 
0072 } // namespace glaxnimate::model