20 #ifndef Tulip_SUPERGRAPH_H 21 #define Tulip_SUPERGRAPH_H 29 #include <tulip/tulipconf.h> 30 #include <tulip/DataSet.h> 31 #include <tulip/Node.h> 32 #include <tulip/Edge.h> 33 #include <tulip/Observable.h> 37 class PropertyInterface;
38 class BooleanProperty;
99 TLP_SCOPE
bool saveGraph(
Graph *graph,
const std::string &filename,
119 TLP_SCOPE
bool exportGraph(
Graph *graph, std::ostream &outputStream,
const std::string &format,
234 friend class GraphAbstract;
235 friend class GraphUpdatesRecorder;
236 friend class GraphDecorator;
237 friend class PropertyManager;
268 bool applyAlgorithm(
const std::string &algorithm, std::string &errorMessage,
282 virtual void clear() = 0;
296 const std::string &name =
"unnamed") = 0;
304 Graph *addSubGraph(
const std::string &name);
318 virtual Graph *addCloneSubGraph(
const std::string &name =
"unnamed",
bool addSibling =
false,
319 bool addSiblingProperties =
false);
332 Graph *inducedSubGraph(
const std::vector<node> &nodes,
Graph *parentSubGraph =
nullptr,
333 const std::string &name =
"unnamed");
340 _DEPRECATED
Graph *inducedSubGraph(
const std::set<node> &nodeSet,
Graph *parentSubGraph =
nullptr,
341 const std::string &name =
"unnamed");
357 const std::string &name =
"unnamed");
379 virtual void delSubGraph(
Graph *graph) = 0;
399 virtual void delAllSubGraphs(
Graph *graph =
nullptr) = 0;
406 virtual Graph *getSuperGraph()
const = 0;
412 virtual Graph *getRoot()
const = 0;
420 virtual void setSuperGraph(
Graph *) = 0;
442 virtual const std::vector<Graph *> &subGraphs()
const = 0;
464 virtual Graph *getNthSubGraph(
unsigned int n)
const;
480 virtual unsigned int numberOfSubGraphs()
const = 0;
496 virtual unsigned int numberOfDescendantGraphs()
const = 0;
504 virtual bool isSubGraph(
const Graph *subGraph)
const = 0;
512 virtual bool isDescendantGraph(
const Graph *subGraph)
const = 0;
521 virtual Graph *getSubGraph(
unsigned int id)
const = 0;
530 virtual Graph *getSubGraph(
const std::string &name)
const = 0;
540 virtual Graph *getDescendantGraph(
unsigned int id)
const = 0;
549 virtual Graph *getDescendantGraph(
const std::string &name)
const = 0;
575 virtual node addNode() = 0;
584 virtual void addNodes(
unsigned int nbNodes) = 0;
594 virtual void addNodes(
unsigned int nbNodes, std::vector<node> &addedNodes) = 0;
606 virtual void addNode(
const node n) = 0;
632 void addNodes(
const std::vector<node> &nodes);
642 virtual void delNode(
const node n,
bool deleteInAllGraphs =
false) = 0;
653 virtual void delNodes(
Iterator<node> *it,
bool deleteInAllGraphs =
false) = 0;
664 void delNodes(
const std::vector<node> &nodes,
bool deleteInAllGraphs =
false);
674 virtual edge addEdge(
const node source,
const node target) = 0;
686 virtual void addEdges(
const std::vector<std::pair<node, node>> &edges) = 0;
699 virtual void addEdges(
const std::vector<std::pair<node, node>> &edges,
700 std::vector<edge> &addedEdges) = 0;
712 virtual void addEdge(
const edge e) = 0;
733 void addEdges(
const std::vector<edge> &edges);
743 virtual void delEdge(
const edge e,
bool deleteInAllGraphs =
false) = 0;
753 virtual void delEdges(
Iterator<edge> *itE,
bool deleteInAllGraphs =
false) = 0;
763 void delEdges(
const std::vector<edge> &edges,
bool deleteInAllGraphs =
false);
775 virtual void setEdgeOrder(
const node n,
const std::vector<edge> &edges) = 0;
783 virtual void swapEdgeOrder(
const node n,
const edge e1,
const edge e2) = 0;
790 virtual void setSource(
const edge e,
const node source) = 0;
797 virtual void setTarget(
const edge e,
const node target) = 0;
805 virtual void setEnds(
const edge e,
const node source,
const node target) = 0;
814 virtual void reverse(
const edge e) = 0;
817 virtual void reserveNodes(
unsigned int nbNodes) = 0;
820 virtual void reserveEdges(
unsigned int nbEdges) = 0;
844 virtual node getOneNode()
const = 0;
852 virtual node getRandomNode()
const = 0;
859 virtual const std::vector<node> &nodes()
const = 0;
865 virtual unsigned int nodePos(
const node n)
const = 0;
898 virtual node getInNode(
const node n,
unsigned int i)
const = 0;
931 virtual node getOutNode(
const node n,
unsigned int i)
const = 0;
974 virtual Graph *getNodeMetaInfo(
const node metaNode)
const = 0;
981 virtual const std::vector<edge> &edges()
const = 0;
987 virtual unsigned int edgePos(
const edge e)
const = 0;
1002 virtual edge getOneEdge()
const = 0;
1010 virtual edge getRandomEdge()
const = 0;
1049 virtual const std::vector<edge> &allEdges(
const node n)
const = 0;
1064 virtual void sortElts() = 0;
1082 return nodes().empty();
1090 virtual unsigned int numberOfNodes()
const = 0;
1097 virtual unsigned int numberOfEdges()
const = 0;
1103 virtual unsigned int deg(
const node n)
const = 0;
1110 virtual unsigned int indeg(
const node n)
const = 0;
1117 virtual unsigned int outdeg(
const node n)
const = 0;
1124 virtual node source(
const edge e)
const = 0;
1131 virtual node target(
const edge e)
const = 0;
1138 virtual const std::pair<node, node> &ends(
const edge e)
const = 0;
1146 virtual node opposite(
const edge e,
const node n)
const = 0;
1153 virtual bool isElement(
const node n)
const = 0;
1160 virtual bool isMetaNode(
const node n)
const = 0;
1167 virtual bool isElement(
const edge e)
const = 0;
1174 virtual bool isMetaEdge(
const edge e)
const = 0;
1184 return existEdge(source, target, directed).isValid();
1194 virtual std::vector<edge> getEdges(
const node source,
const node target,
1195 bool directed =
true)
const = 0;
1207 virtual edge existEdge(
const node source,
const node target,
bool directed =
true)
const = 0;
1217 virtual void setName(
const std::string &name) = 0;
1223 virtual std::string getName()
const = 0;
1232 return const_cast<Graph *
>(
this)->getNonConstAttributes();
1241 template <
typename ATTRIBUTETYPE>
1242 bool getAttribute(
const std::string &name, ATTRIBUTETYPE &value)
const;
1249 DataType *getAttribute(
const std::string &name)
const;
1256 template <
typename ATTRIBUTETYPE>
1257 void setAttribute(
const std::string &name,
const ATTRIBUTETYPE &value);
1264 void setAttribute(
const std::string &name,
const DataType *value);
1271 notifyRemoveAttribute(name);
1272 getNonConstAttributes().remove(name);
1281 return getAttributes().exists(name);
1288 return existAttribute(name);
1298 virtual void addLocalProperty(
const std::string &name,
PropertyInterface *prop) = 0;
1324 template <
typename PropertyType>
1325 PropertyType *getLocalProperty(
const std::string &name);
1340 template <
typename PropertyType>
1341 PropertyType *getProperty(
const std::string &name);
1359 const std::string &propertyType);
1376 PropertyInterface *getProperty(
const std::string &propertyName,
const std::string &propertyType);
1383 virtual bool existProperty(
const std::string &name)
const = 0;
1390 virtual bool existLocalProperty(
const std::string &name)
const = 0;
1399 virtual void delLocalProperty(
const std::string &name) = 0;
1457 bool applyPropertyAlgorithm(
const std::string &algorithm,
PropertyInterface *result,
1458 std::string &errorMessage,
DataSet *parameters =
nullptr,
1468 DataSet *parameters =
nullptr) {
1469 return applyPropertyAlgorithm(algorithm, result, errorMessage, parameters, progress);
1539 virtual void push(
bool unpopAllowed =
true,
1540 std::vector<PropertyInterface *> *propertiesToPreserveOnPop =
nullptr) = 0;
1547 virtual void pop(
bool unpopAllowed =
true) = 0;
1552 virtual void popIfNoUpdates() = 0;
1588 virtual void unpop() = 0;
1594 virtual bool canPop() = 0;
1600 virtual bool canUnpop() = 0;
1607 virtual bool canPopThenUnpop() = 0;
1622 virtual node createMetaNode(
const std::vector<node> &nodes,
bool multiEdges =
true,
1623 bool delAllEdge =
true);
1629 _DEPRECATED
node createMetaNode(
const std::set<node> &nodeSet,
bool multiEdges =
true,
1630 bool delAllEdge =
true);
1642 std::vector<node> &metaNodes);
1653 virtual node createMetaNode(
Graph *subGraph,
bool multiEdges =
true,
bool delAllEdge =
true);
1665 void openMetaNode(
node n,
bool updateProperties =
true);
1669 virtual DataSet &getNonConstAttributes() = 0;
1672 virtual void restoreNode(
node) = 0;
1673 virtual void restoreEdge(
edge,
node source,
node target) = 0;
1676 virtual void removeNode(
const node) = 0;
1677 virtual void removeEdge(
const edge) = 0;
1682 return getRoot()->canDeleteProperty(g, prop);
1687 virtual bool renameLocalProperty(
PropertyInterface *prop,
const std::string &newName) = 0;
1690 virtual void removeSubGraph(
Graph *) = 0;
1691 virtual void clearSubGraphs() = 0;
1692 virtual void restoreSubGraph(
Graph *) = 0;
1693 virtual void setSubGraphToKeep(
Graph *) = 0;
1696 void notifyAddNode(
const node n);
1697 void notifyAddNode(
Graph *,
const node n) {
1700 void notifyAddEdge(
const edge e);
1701 void notifyAddEdge(
Graph *,
const edge e) {
1704 void notifyBeforeSetEnds(
const edge e);
1705 void notifyBeforeSetEnds(
Graph *,
const edge e) {
1706 notifyBeforeSetEnds(e);
1708 void notifyAfterSetEnds(
const edge e);
1709 void notifyAfterSetEnds(
Graph *,
const edge e) {
1710 notifyAfterSetEnds(e);
1712 void notifyDelNode(
const node n);
1713 void notifyDelNode(
Graph *,
const node n) {
1716 void notifyDelEdge(
const edge e);
1717 void notifyDelEdge(
Graph *,
const edge e) {
1720 void notifyReverseEdge(
const edge e);
1721 void notifyReverseEdge(
Graph *,
const edge e) {
1722 notifyReverseEdge(e);
1724 void notifyBeforeAddSubGraph(
const Graph *);
1725 void notifyAfterAddSubGraph(
const Graph *);
1726 void notifyBeforeAddSubGraph(
Graph *,
const Graph *sg) {
1727 notifyBeforeAddSubGraph(sg);
1729 void notifyAfterAddSubGraph(
Graph *,
const Graph *sg) {
1730 notifyAfterAddSubGraph(sg);
1732 void notifyBeforeDelSubGraph(
const Graph *);
1733 void notifyAfterDelSubGraph(
const Graph *);
1734 void notifyBeforeDelSubGraph(
Graph *,
const Graph *sg) {
1735 notifyBeforeDelSubGraph(sg);
1737 void notifyAfterDelSubGraph(
Graph *,
const Graph *sg) {
1738 notifyAfterDelSubGraph(sg);
1741 void notifyBeforeAddDescendantGraph(
const Graph *);
1742 void notifyAfterAddDescendantGraph(
const Graph *);
1743 void notifyBeforeDelDescendantGraph(
const Graph *);
1744 void notifyAfterDelDescendantGraph(
const Graph *);
1746 void notifyBeforeAddLocalProperty(
const std::string &);
1747 void notifyAddLocalProperty(
const std::string &);
1748 void notifyAddLocalProperty(
Graph *,
const std::string &name) {
1749 notifyAddLocalProperty(name);
1751 void notifyBeforeDelLocalProperty(
const std::string &);
1752 void notifyAfterDelLocalProperty(
const std::string &);
1753 void notifyDelLocalProperty(
Graph *,
const std::string &name) {
1754 notifyBeforeDelLocalProperty(name);
1756 void notifyBeforeSetAttribute(
const std::string &);
1757 void notifyBeforeSetAttribute(
Graph *,
const std::string &name) {
1758 notifyBeforeSetAttribute(name);
1760 void notifyAfterSetAttribute(
const std::string &);
1761 void notifyAfterSetAttribute(
Graph *,
const std::string &name) {
1762 notifyAfterSetAttribute(name);
1764 void notifyRemoveAttribute(
const std::string &);
1765 void notifyRemoveAttribute(
Graph *,
const std::string &name) {
1766 notifyRemoveAttribute(name);
1768 void notifyDestroy();
1769 void notifyDestroy(
Graph *) {
1774 TLP_HASH_MAP<std::string, tlp::PropertyInterface *> circularCalls;
1786 enum GraphEventType {
1791 TLP_REVERSE_EDGE = 4,
1792 TLP_BEFORE_SET_ENDS = 5,
1793 TLP_AFTER_SET_ENDS = 6,
1796 TLP_BEFORE_ADD_DESCENDANTGRAPH = 9,
1797 TLP_AFTER_ADD_DESCENDANTGRAPH = 10,
1798 TLP_BEFORE_DEL_DESCENDANTGRAPH = 11,
1799 TLP_AFTER_DEL_DESCENDANTGRAPH = 12,
1800 TLP_BEFORE_ADD_SUBGRAPH = 13,
1801 TLP_AFTER_ADD_SUBGRAPH = 14,
1802 TLP_BEFORE_DEL_SUBGRAPH = 15,
1803 TLP_AFTER_DEL_SUBGRAPH = 16,
1804 TLP_ADD_LOCAL_PROPERTY = 17,
1805 TLP_BEFORE_DEL_LOCAL_PROPERTY = 18,
1806 TLP_AFTER_DEL_LOCAL_PROPERTY = 19,
1807 TLP_ADD_INHERITED_PROPERTY = 20,
1808 TLP_BEFORE_DEL_INHERITED_PROPERTY = 21,
1809 TLP_AFTER_DEL_INHERITED_PROPERTY = 22,
1810 TLP_BEFORE_RENAME_LOCAL_PROPERTY = 23,
1811 TLP_AFTER_RENAME_LOCAL_PROPERTY = 24,
1812 TLP_BEFORE_SET_ATTRIBUTE = 25,
1813 TLP_AFTER_SET_ATTRIBUTE = 26,
1814 TLP_REMOVE_ATTRIBUTE = 27,
1815 TLP_BEFORE_ADD_LOCAL_PROPERTY = 28,
1816 TLP_BEFORE_ADD_INHERITED_PROPERTY = 29
1820 GraphEvent(
const Graph &g, GraphEventType graphEvtType,
unsigned int id,
1821 Event::EventType evtType = Event::TLP_MODIFICATION)
1822 :
Event(g, evtType), evtType(graphEvtType) {
1823 if (graphEvtType == TLP_ADD_NODES || graphEvtType == TLP_ADD_EDGES)
1828 vectInfos.addedNodes =
nullptr;
1832 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1834 vectInfos.addedNodes =
nullptr;
1838 GraphEvent(
const Graph &g, GraphEventType graphEvtType,
const std::string &str,
1839 Event::EventType evtType = Event::TLP_MODIFICATION)
1840 :
Event(g, evtType), evtType(graphEvtType) {
1841 info.name =
new std::string(str);
1842 vectInfos.addedNodes =
nullptr;
1847 const std::string &newName)
1848 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1849 info.renamedProp =
new std::pair<PropertyInterface *, std::string>(prop, newName);
1850 vectInfos.addedNodes =
nullptr;
1855 Graph *getGraph()
const {
1856 return static_cast<Graph *
>(sender());
1859 node getNode()
const {
1860 assert(evtType < TLP_ADD_EDGE);
1861 return node(info.eltId);
1864 edge getEdge()
const {
1865 assert(evtType > TLP_DEL_NODE && evtType < TLP_ADD_NODES);
1866 return edge(info.eltId);
1869 const std::vector<node> &getNodes()
const;
1871 unsigned int getNumberOfNodes()
const {
1872 assert(evtType == TLP_ADD_NODES);
1876 const std::vector<edge> &getEdges()
const;
1878 unsigned int getNumberOfEdges()
const {
1879 assert(evtType == TLP_ADD_EDGES);
1883 const Graph *getSubGraph()
const {
1884 assert(evtType > TLP_ADD_EDGES && evtType < TLP_ADD_LOCAL_PROPERTY);
1885 return info.subGraph;
1888 const std::string &getAttributeName()
const {
1889 assert(evtType > TLP_AFTER_DEL_INHERITED_PROPERTY);
1890 return *(info.name);
1893 const std::string &getPropertyName()
const;
1896 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
1897 evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1898 return info.renamedProp->first;
1901 const std::string &getPropertyNewName()
const {
1902 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY);
1903 return info.renamedProp->second;
1906 const std::string &getPropertyOldName()
const {
1907 assert(evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1908 return info.renamedProp->second;
1911 GraphEventType getType()
const {
1916 GraphEventType evtType;
1919 const Graph *subGraph;
1921 unsigned int nbElts;
1922 std::pair<PropertyInterface *, std::string> *renamedProp;
1925 std::vector<node> *addedNodes;
1926 std::vector<edge> *addedEdges;
1938 TLP_BEGIN_HASH_NAMESPACE {
1940 struct TLP_SCOPE hash<const tlp::
Graph *> {
1941 size_t operator()(
const tlp::Graph *s)
const {
1942 return size_t(s->
getId());
1946 struct TLP_SCOPE hash<tlp::
Graph *> {
1948 return size_t(s->
getId());
1952 TLP_END_HASH_NAMESPACE
1955 #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.