20 #ifndef Tulip_SUPERGRAPH_H 21 #define Tulip_SUPERGRAPH_H 28 #include <unordered_map> 31 #include <tulip/tulipconf.h> 32 #include <tulip/DataSet.h> 33 #include <tulip/Node.h> 34 #include <tulip/Edge.h> 35 #include <tulip/Observable.h> 39 class PropertyInterface;
40 class BooleanProperty;
101 TLP_SCOPE
bool saveGraph(
Graph *graph,
const std::string &filename,
121 TLP_SCOPE
bool exportGraph(
Graph *graph, std::ostream &outputStream,
const std::string &format,
236 friend class GraphAbstract;
237 friend class GraphUpdatesRecorder;
238 friend class GraphDecorator;
239 friend class PropertyManager;
270 bool applyAlgorithm(
const std::string &algorithm, std::string &errorMessage,
284 virtual void clear() = 0;
298 const std::string &name =
"unnamed") = 0;
306 Graph *addSubGraph(
const std::string &name);
320 virtual Graph *addCloneSubGraph(
const std::string &name =
"unnamed",
bool addSibling =
false,
321 bool addSiblingProperties =
false);
334 Graph *inducedSubGraph(
const std::vector<node> &nodes,
Graph *parentSubGraph =
nullptr,
335 const std::string &name =
"unnamed");
342 _DEPRECATED
Graph *inducedSubGraph(
const std::set<node> &nodeSet,
Graph *parentSubGraph =
nullptr,
343 const std::string &name =
"unnamed");
359 const std::string &name =
"unnamed");
381 virtual void delSubGraph(
Graph *graph) = 0;
401 virtual void delAllSubGraphs(
Graph *graph =
nullptr) = 0;
408 virtual Graph *getSuperGraph()
const = 0;
414 virtual Graph *getRoot()
const = 0;
422 virtual void setSuperGraph(
Graph *) = 0;
444 virtual const std::vector<Graph *> &subGraphs()
const = 0;
466 virtual Graph *getNthSubGraph(
unsigned int n)
const;
482 virtual unsigned int numberOfSubGraphs()
const = 0;
498 virtual unsigned int numberOfDescendantGraphs()
const = 0;
506 virtual bool isSubGraph(
const Graph *subGraph)
const = 0;
514 virtual bool isDescendantGraph(
const Graph *subGraph)
const = 0;
523 virtual Graph *getSubGraph(
unsigned int id)
const = 0;
532 virtual Graph *getSubGraph(
const std::string &name)
const = 0;
542 virtual Graph *getDescendantGraph(
unsigned int id)
const = 0;
551 virtual Graph *getDescendantGraph(
const std::string &name)
const = 0;
577 virtual node addNode() = 0;
586 virtual void addNodes(
unsigned int nbNodes) = 0;
596 virtual void addNodes(
unsigned int nbNodes, std::vector<node> &addedNodes) = 0;
608 virtual void addNode(
const node n) = 0;
634 void addNodes(
const std::vector<node> &nodes);
644 virtual void delNode(
const node n,
bool deleteInAllGraphs =
false) = 0;
655 virtual void delNodes(
Iterator<node> *it,
bool deleteInAllGraphs =
false) = 0;
666 void delNodes(
const std::vector<node> &nodes,
bool deleteInAllGraphs =
false);
676 virtual edge addEdge(
const node source,
const node target) = 0;
688 virtual void addEdges(
const std::vector<std::pair<node, node>> &edges) = 0;
701 virtual void addEdges(
const std::vector<std::pair<node, node>> &edges,
702 std::vector<edge> &addedEdges) = 0;
714 virtual void addEdge(
const edge e) = 0;
735 void addEdges(
const std::vector<edge> &edges);
745 virtual void delEdge(
const edge e,
bool deleteInAllGraphs =
false) = 0;
755 virtual void delEdges(
Iterator<edge> *itE,
bool deleteInAllGraphs =
false) = 0;
765 void delEdges(
const std::vector<edge> &edges,
bool deleteInAllGraphs =
false);
777 virtual void setEdgeOrder(
const node n,
const std::vector<edge> &edges) = 0;
785 virtual void swapEdgeOrder(
const node n,
const edge e1,
const edge e2) = 0;
792 virtual void setSource(
const edge e,
const node source) = 0;
799 virtual void setTarget(
const edge e,
const node target) = 0;
807 virtual void setEnds(
const edge e,
const node source,
const node target) = 0;
816 virtual void reverse(
const edge e) = 0;
819 virtual void reserveNodes(
unsigned int nbNodes) = 0;
822 virtual void reserveEdges(
unsigned int nbEdges) = 0;
846 virtual node getOneNode()
const = 0;
854 virtual node getRandomNode()
const = 0;
861 virtual const std::vector<node> &nodes()
const = 0;
867 virtual unsigned int nodePos(
const node n)
const = 0;
900 virtual node getInNode(
const node n,
unsigned int i)
const = 0;
933 virtual node getOutNode(
const node n,
unsigned int i)
const = 0;
976 virtual Graph *getNodeMetaInfo(
const node metaNode)
const = 0;
983 virtual const std::vector<edge> &edges()
const = 0;
989 virtual unsigned int edgePos(
const edge e)
const = 0;
1004 virtual edge getOneEdge()
const = 0;
1012 virtual edge getRandomEdge()
const = 0;
1051 virtual const std::vector<edge> &allEdges(
const node n)
const = 0;
1066 virtual void sortElts() = 0;
1084 return nodes().empty();
1092 virtual unsigned int numberOfNodes()
const = 0;
1099 virtual unsigned int numberOfEdges()
const = 0;
1105 virtual unsigned int deg(
const node n)
const = 0;
1112 virtual unsigned int indeg(
const node n)
const = 0;
1119 virtual unsigned int outdeg(
const node n)
const = 0;
1126 virtual node source(
const edge e)
const = 0;
1133 virtual node target(
const edge e)
const = 0;
1140 virtual const std::pair<node, node> &ends(
const edge e)
const = 0;
1148 virtual node opposite(
const edge e,
const node n)
const = 0;
1155 virtual bool isElement(
const node n)
const = 0;
1162 virtual bool isMetaNode(
const node n)
const = 0;
1169 virtual bool isElement(
const edge e)
const = 0;
1176 virtual bool isMetaEdge(
const edge e)
const = 0;
1186 return existEdge(source, target, directed).isValid();
1196 virtual std::vector<edge> getEdges(
const node source,
const node target,
1197 bool directed =
true)
const = 0;
1209 virtual edge existEdge(
const node source,
const node target,
bool directed =
true)
const = 0;
1219 virtual void setName(
const std::string &name) = 0;
1225 virtual std::string getName()
const = 0;
1234 return const_cast<Graph *
>(
this)->getNonConstAttributes();
1243 template <
typename ATTRIBUTETYPE>
1244 bool getAttribute(
const std::string &name, ATTRIBUTETYPE &value)
const;
1251 DataType *getAttribute(
const std::string &name)
const;
1258 template <
typename ATTRIBUTETYPE>
1259 void setAttribute(
const std::string &name,
const ATTRIBUTETYPE &value);
1266 void setAttribute(
const std::string &name,
const DataType *value);
1273 notifyRemoveAttribute(name);
1274 getNonConstAttributes().remove(name);
1283 return getAttributes().exists(name);
1290 return existAttribute(name);
1300 virtual void addLocalProperty(
const std::string &name,
PropertyInterface *prop) = 0;
1326 template <
typename PropertyType>
1327 PropertyType *getLocalProperty(
const std::string &name);
1342 template <
typename PropertyType>
1343 PropertyType *getProperty(
const std::string &name);
1361 const std::string &propertyType);
1378 PropertyInterface *getProperty(
const std::string &propertyName,
const std::string &propertyType);
1385 virtual bool existProperty(
const std::string &name)
const = 0;
1392 virtual bool existLocalProperty(
const std::string &name)
const = 0;
1401 virtual void delLocalProperty(
const std::string &name) = 0;
1459 bool applyPropertyAlgorithm(
const std::string &algorithm,
PropertyInterface *result,
1460 std::string &errorMessage,
DataSet *parameters =
nullptr,
1470 DataSet *parameters =
nullptr) {
1471 return applyPropertyAlgorithm(algorithm, result, errorMessage, parameters, progress);
1541 virtual void push(
bool unpopAllowed =
true,
1542 std::vector<PropertyInterface *> *propertiesToPreserveOnPop =
nullptr) = 0;
1549 virtual void pop(
bool unpopAllowed =
true) = 0;
1554 virtual void popIfNoUpdates() = 0;
1590 virtual void unpop() = 0;
1596 virtual bool canPop() = 0;
1602 virtual bool canUnpop() = 0;
1609 virtual bool canPopThenUnpop() = 0;
1624 virtual node createMetaNode(
const std::vector<node> &nodes,
bool multiEdges =
true,
1625 bool delAllEdge =
true);
1631 _DEPRECATED
node createMetaNode(
const std::set<node> &nodeSet,
bool multiEdges =
true,
1632 bool delAllEdge =
true);
1644 std::vector<node> &metaNodes);
1655 virtual node createMetaNode(
Graph *subGraph,
bool multiEdges =
true,
bool delAllEdge =
true);
1667 void openMetaNode(
node n,
bool updateProperties =
true);
1671 virtual DataSet &getNonConstAttributes() = 0;
1674 virtual void restoreNode(
node) = 0;
1675 virtual void restoreEdge(
edge,
node source,
node target) = 0;
1678 virtual void removeNode(
const node) = 0;
1679 virtual void removeEdge(
const edge) = 0;
1684 return getRoot()->canDeleteProperty(g, prop);
1689 virtual bool renameLocalProperty(
PropertyInterface *prop,
const std::string &newName) = 0;
1692 virtual void removeSubGraph(
Graph *) = 0;
1693 virtual void clearSubGraphs() = 0;
1694 virtual void restoreSubGraph(
Graph *) = 0;
1695 virtual void setSubGraphToKeep(
Graph *) = 0;
1698 void notifyAddNode(
const node n);
1699 void notifyAddNode(
Graph *,
const node n) {
1702 void notifyAddEdge(
const edge e);
1703 void notifyAddEdge(
Graph *,
const edge e) {
1706 void notifyBeforeSetEnds(
const edge e);
1707 void notifyBeforeSetEnds(
Graph *,
const edge e) {
1708 notifyBeforeSetEnds(e);
1710 void notifyAfterSetEnds(
const edge e);
1711 void notifyAfterSetEnds(
Graph *,
const edge e) {
1712 notifyAfterSetEnds(e);
1714 void notifyDelNode(
const node n);
1715 void notifyDelNode(
Graph *,
const node n) {
1718 void notifyDelEdge(
const edge e);
1719 void notifyDelEdge(
Graph *,
const edge e) {
1722 void notifyReverseEdge(
const edge e);
1723 void notifyReverseEdge(
Graph *,
const edge e) {
1724 notifyReverseEdge(e);
1726 void notifyBeforeAddSubGraph(
const Graph *);
1727 void notifyAfterAddSubGraph(
const Graph *);
1728 void notifyBeforeAddSubGraph(
Graph *,
const Graph *sg) {
1729 notifyBeforeAddSubGraph(sg);
1731 void notifyAfterAddSubGraph(
Graph *,
const Graph *sg) {
1732 notifyAfterAddSubGraph(sg);
1734 void notifyBeforeDelSubGraph(
const Graph *);
1735 void notifyAfterDelSubGraph(
const Graph *);
1736 void notifyBeforeDelSubGraph(
Graph *,
const Graph *sg) {
1737 notifyBeforeDelSubGraph(sg);
1739 void notifyAfterDelSubGraph(
Graph *,
const Graph *sg) {
1740 notifyAfterDelSubGraph(sg);
1743 void notifyBeforeAddDescendantGraph(
const Graph *);
1744 void notifyAfterAddDescendantGraph(
const Graph *);
1745 void notifyBeforeDelDescendantGraph(
const Graph *);
1746 void notifyAfterDelDescendantGraph(
const Graph *);
1748 void notifyBeforeAddLocalProperty(
const std::string &);
1749 void notifyAddLocalProperty(
const std::string &);
1750 void notifyAddLocalProperty(
Graph *,
const std::string &name) {
1751 notifyAddLocalProperty(name);
1753 void notifyBeforeDelLocalProperty(
const std::string &);
1754 void notifyAfterDelLocalProperty(
const std::string &);
1755 void notifyDelLocalProperty(
Graph *,
const std::string &name) {
1756 notifyBeforeDelLocalProperty(name);
1758 void notifyBeforeSetAttribute(
const std::string &);
1759 void notifyBeforeSetAttribute(
Graph *,
const std::string &name) {
1760 notifyBeforeSetAttribute(name);
1762 void notifyAfterSetAttribute(
const std::string &);
1763 void notifyAfterSetAttribute(
Graph *,
const std::string &name) {
1764 notifyAfterSetAttribute(name);
1766 void notifyRemoveAttribute(
const std::string &);
1767 void notifyRemoveAttribute(
Graph *,
const std::string &name) {
1768 notifyRemoveAttribute(name);
1770 void notifyDestroy();
1771 void notifyDestroy(
Graph *) {
1776 std::unordered_map<std::string, tlp::PropertyInterface *> circularCalls;
1788 enum GraphEventType {
1793 TLP_REVERSE_EDGE = 4,
1794 TLP_BEFORE_SET_ENDS = 5,
1795 TLP_AFTER_SET_ENDS = 6,
1798 TLP_BEFORE_ADD_DESCENDANTGRAPH = 9,
1799 TLP_AFTER_ADD_DESCENDANTGRAPH = 10,
1800 TLP_BEFORE_DEL_DESCENDANTGRAPH = 11,
1801 TLP_AFTER_DEL_DESCENDANTGRAPH = 12,
1802 TLP_BEFORE_ADD_SUBGRAPH = 13,
1803 TLP_AFTER_ADD_SUBGRAPH = 14,
1804 TLP_BEFORE_DEL_SUBGRAPH = 15,
1805 TLP_AFTER_DEL_SUBGRAPH = 16,
1806 TLP_ADD_LOCAL_PROPERTY = 17,
1807 TLP_BEFORE_DEL_LOCAL_PROPERTY = 18,
1808 TLP_AFTER_DEL_LOCAL_PROPERTY = 19,
1809 TLP_ADD_INHERITED_PROPERTY = 20,
1810 TLP_BEFORE_DEL_INHERITED_PROPERTY = 21,
1811 TLP_AFTER_DEL_INHERITED_PROPERTY = 22,
1812 TLP_BEFORE_RENAME_LOCAL_PROPERTY = 23,
1813 TLP_AFTER_RENAME_LOCAL_PROPERTY = 24,
1814 TLP_BEFORE_SET_ATTRIBUTE = 25,
1815 TLP_AFTER_SET_ATTRIBUTE = 26,
1816 TLP_REMOVE_ATTRIBUTE = 27,
1817 TLP_BEFORE_ADD_LOCAL_PROPERTY = 28,
1818 TLP_BEFORE_ADD_INHERITED_PROPERTY = 29
1822 GraphEvent(
const Graph &g, GraphEventType graphEvtType,
unsigned int id,
1823 Event::EventType evtType = Event::TLP_MODIFICATION)
1824 :
Event(g, evtType), evtType(graphEvtType) {
1825 if (graphEvtType == TLP_ADD_NODES || graphEvtType == TLP_ADD_EDGES)
1830 vectInfos.addedNodes =
nullptr;
1834 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1836 vectInfos.addedNodes =
nullptr;
1840 GraphEvent(
const Graph &g, GraphEventType graphEvtType,
const std::string &str,
1841 Event::EventType evtType = Event::TLP_MODIFICATION)
1842 :
Event(g, evtType), evtType(graphEvtType) {
1843 info.name =
new std::string(str);
1844 vectInfos.addedNodes =
nullptr;
1849 const std::string &newName)
1850 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1851 info.renamedProp =
new std::pair<PropertyInterface *, std::string>(prop, newName);
1852 vectInfos.addedNodes =
nullptr;
1857 Graph *getGraph()
const {
1858 return static_cast<Graph *
>(sender());
1861 node getNode()
const {
1862 assert(evtType < TLP_ADD_EDGE);
1863 return node(info.eltId);
1866 edge getEdge()
const {
1867 assert(evtType > TLP_DEL_NODE && evtType < TLP_ADD_NODES);
1868 return edge(info.eltId);
1871 const std::vector<node> &getNodes()
const;
1873 unsigned int getNumberOfNodes()
const {
1874 assert(evtType == TLP_ADD_NODES);
1878 const std::vector<edge> &getEdges()
const;
1880 unsigned int getNumberOfEdges()
const {
1881 assert(evtType == TLP_ADD_EDGES);
1885 const Graph *getSubGraph()
const {
1886 assert(evtType > TLP_ADD_EDGES && evtType < TLP_ADD_LOCAL_PROPERTY);
1887 return info.subGraph;
1890 const std::string &getAttributeName()
const {
1891 assert(evtType > TLP_AFTER_DEL_INHERITED_PROPERTY);
1892 return *(info.name);
1895 const std::string &getPropertyName()
const;
1898 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
1899 evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1900 return info.renamedProp->first;
1903 const std::string &getPropertyNewName()
const {
1904 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY);
1905 return info.renamedProp->second;
1908 const std::string &getPropertyOldName()
const {
1909 assert(evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1910 return info.renamedProp->second;
1913 GraphEventType getType()
const {
1918 GraphEventType evtType;
1921 const Graph *subGraph;
1923 unsigned int nbElts;
1924 std::pair<PropertyInterface *, std::string> *renamedProp;
1927 std::vector<node> *addedNodes;
1928 std::vector<edge> *addedEdges;
1936 #include "cxx/Graph.cxx" virtual bool hasEdge(const node source, const node target, bool directed=true) const
Checks if an edge exists between two given nodes.
void removeFromGraph(Graph *ioG, BooleanProperty *inSelection=nullptr)
A graph property that maps a boolean value to graph elements.
Interface for Tulip iterators. Allows basic iteration operations only.
Graph * newGraph()
Creates a new, empty graph.
PropertyInterface describes the interface of a graph property.
Describes a value of any type.
A container that can store data from any type.
const DataSet & getAttributes() const
Gets the attributes of the graph.
Graph * loadGraph(const std::string &filename, tlp::PluginProgress *progress=nullptr)
Loads a graph from a file (extension can be any of the Tulip supported input graph file format)...
Graph * importGraph(const std::string &format, DataSet &dataSet, PluginProgress *progress=nullptr, Graph *newGraph=nullptr)
Imports a graph using the specified import plugin with the parameters stored in the DataSet...
Iterator< Graph * > * getRootGraphs()
virtual bool isEmpty() const
return whether the graph is empty or not.
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.
Event is the base class for all events used in the Observation mechanism.
unsigned int getId() const
Gets the unique identifier of the graph.
PluginProcess subclasses are meant to notify about the progress state of some process (typically a pl...
bool applyPropertyAlgorithm(const std::string &algorithm, PropertyInterface *result, std::string &errorMessage, PluginProgress *progress, DataSet *parameters=nullptr)
Deprecated, use applyPropertyAlgorithm(const std::string &algorithm, PropertyInterface *result...
void removeAttribute(const std::string &name)
Removes an attribute on the graph.
void copyToGraph(Graph *outG, const Graph *inG, BooleanProperty *inSelection=nullptr, BooleanProperty *outSelection=nullptr)
The Observable class is the base of Tulip's observation system.
bool attributeExist(const std::string &name) const
deprecated, use existAttribute instead.
bool saveGraph(Graph *graph, const std::string &filename, tlp::PluginProgress *progress=nullptr, tlp::DataSet *data=nullptr)
Saves the corresponding graph to a file (extension can be any of the Tulip supported ouput graph file...
bool existAttribute(const std::string &name) const
Checks if an attribute exists.
bool exportGraph(Graph *graph, std::ostream &outputStream, const std::string &format, DataSet &dataSet, PluginProgress *progress=nullptr)
Exports a graph using the specified export plugin with parameters stored in the DataSet.
std::ostream & operator<<(std::ostream &os, const Array< T, N > &array)
operator << stream operator to easily print an array, or save it to a file.