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;
208 friend class GraphAbstract;
209 friend class GraphUpdatesRecorder;
210 friend class GraphDecorator;
211 friend class PropertyManager;
239 bool applyAlgorithm(
const std::string &algorithm, std::string &errorMessage,
DataSet *dataSet=NULL,
PluginProgress *progress=NULL);
252 virtual void clear()=0;
265 const std::string& name =
"unnamed")=0;
273 Graph *addSubGraph(
const std::string& name);
283 virtual Graph* addCloneSubGraph(
const std::string& name =
"unnamed",
bool addSibling =
false,
bool addSiblingProperties =
false);
295 Graph *inducedSubGraph(
const std::vector<node>& nodes,
296 Graph* parentSubGraph = NULL,
297 const std::string& name =
"unnamed");
302 _DEPRECATED
Graph *inducedSubGraph(
const std::set<node>& nodeSet,
303 Graph* parentSubGraph = NULL,
304 const std::string& name =
"unnamed");
318 Graph* parentSubGraph = NULL,
const std::string& name =
"unnamed");
340 virtual void delSubGraph(
Graph *graph)=0;
360 virtual void delAllSubGraphs(
Graph *graph)=0;
367 virtual Graph* getSuperGraph()
const =0;
373 virtual Graph* getRoot()
const =0;
381 virtual void setSuperGraph(
Graph *)=0;
396 virtual Iterator<Graph *> * getSubGraphs()
const=0;
417 virtual Graph *getNthSubGraph(
unsigned int n)
const;
433 virtual unsigned int numberOfSubGraphs()
const=0;
449 virtual unsigned int numberOfDescendantGraphs()
const=0;
457 virtual bool isSubGraph(
const Graph* subGraph)
const=0;
465 virtual bool isDescendantGraph(
const Graph* subGraph)
const=0;
474 virtual Graph* getSubGraph(
unsigned int id)
const=0;
483 virtual Graph* getSubGraph(
const std::string &name)
const=0;
492 virtual Graph* getDescendantGraph(
unsigned int id)
const=0;
501 virtual Graph* getDescendantGraph(
const std::string &name)
const=0;
516 Iterator<Graph *> * getDescendantGraphs()
const;
527 virtual node addNode()=0;
536 virtual void addNodes(
unsigned int nbNodes)=0;
546 virtual void addNodes(
unsigned int nbNodes, std::vector<node>& addedNodes)=0;
557 virtual void addNode(
const node n)=0;
569 virtual void addNodes(Iterator<node>* nodes)=0;
580 void addNodes(
const std::vector<node>& nodes);
589 virtual void delNode(
const node n,
bool deleteInAllGraphs =
false)=0;
599 virtual void delNodes(Iterator<node>* it,
bool deleteInAllGraphs =
false)=0;
609 void delNodes(
const std::vector<node>& nodes,
bool deleteInAllGraphs =
false);
619 virtual edge addEdge(
const node source,
const node target)=0;
631 virtual void addEdges(
const std::vector<std::pair<node, node> >& edges)=0;
644 virtual void addEdges(
const std::vector<std::pair<node, node> >& edges,
645 std::vector<edge>& addedEdges)=0;
657 virtual void addEdge(
const edge e)=0;
668 virtual void addEdges(Iterator<edge>* edges)=0;
678 void addEdges(
const std::vector<edge>& edges);
687 virtual void delEdge(
const edge e,
bool deleteInAllGraphs =
false)=0;
696 virtual void delEdges(Iterator<edge>* itE,
bool deleteInAllGraphs =
false)=0;
705 void delEdges(
const std::vector<edge>& edges,
bool deleteInAllGraphs =
false);
716 virtual void setEdgeOrder(
const node n,
const std::vector<edge> &edges)=0;
724 virtual void swapEdgeOrder(
const node n,
const edge e1,
const edge e2)=0;
731 virtual void setSource(
const edge e,
const node source) = 0;
738 virtual void setTarget(
const edge e,
const node target) = 0;
746 virtual void setEnds(
const edge e,
const node source,
const node target) = 0;
755 virtual void reverse(
const edge e)=0;
758 virtual void reserveNodes(
unsigned int nbNodes) = 0;
761 virtual void reserveEdges(
unsigned int nbEdges) = 0;
783 virtual node getOneNode()
const =0;
791 virtual node getRandomNode()
const =0;
798 virtual const std::vector<node>& nodes()
const =0;
804 virtual unsigned int nodePos(
const node n)
const =0;
814 virtual Iterator<node>* getNodes()
const =0;
837 virtual node getInNode(
const node n,
unsigned int i)
const =0;
847 virtual Iterator<node>* getInNodes(
const node n)
const =0;
870 virtual node getOutNode(
const node n,
unsigned int i)
const =0;
880 virtual Iterator<node>* getOutNodes(
const node n)
const =0;
887 virtual Iterator<node>* getInOutNodes(
const node n)
const =0;
896 virtual Iterator<node>* bfs(
const node root =
node())
const = 0;
905 virtual Iterator<node>* dfs(
const node root =
node())
const = 0;
913 virtual Graph* getNodeMetaInfo(
const node metaNode)
const = 0;
920 virtual const std::vector<edge>& edges()
const =0;
926 virtual unsigned int edgePos(
const edge e)
const =0;
935 virtual Iterator<edge>* getEdges()
const =0;
941 virtual edge getOneEdge()
const =0;
949 virtual edge getRandomEdge()
const =0;
959 virtual Iterator<edge>* getOutEdges(
const node n)
const =0;
969 virtual Iterator<edge>* getInOutEdges(
const node n)
const =0;
979 virtual Iterator<edge>* getInEdges(
const node n)
const =0;
988 virtual const std::vector<edge>& allEdges(
const node n)
const =0;
996 virtual Iterator<edge>* getEdgeMetaInfo(
const edge metaEdge)
const =0;
1003 virtual void sortElts()=0;
1021 virtual unsigned int numberOfNodes()
const =0;
1028 virtual unsigned int numberOfEdges()
const =0;
1034 virtual unsigned int deg(
const node n)
const =0;
1041 virtual unsigned int indeg(
const node n)
const =0;
1048 virtual unsigned int outdeg(
const node n)
const =0;
1055 virtual node source(
const edge e)
const =0;
1062 virtual node target(
const edge e)
const =0;
1069 virtual const std::pair<node, node>& ends(
const edge e)
const=0;
1077 virtual node opposite(
const edge e,
const node n)
const =0;
1084 virtual bool isElement(
const node n)
const =0;
1091 virtual bool isMetaNode(
const node n)
const =0;
1098 virtual bool isElement(
const edge e)
const =0;
1105 virtual bool isMetaEdge(
const edge e)
const =0;
1115 bool directed =
true)
const {
1116 return existEdge(source, target, directed).isValid();
1127 virtual std::vector<edge> getEdges(
const node source,
const node target,
1128 bool directed =
true)
const=0;
1140 virtual edge existEdge(
const node source,
const node target,
1141 bool directed =
true)
const=0;
1151 virtual void setName(
const std::string &name) = 0;
1157 virtual std::string getName()
const = 0;
1166 return (const_cast<Graph *>(
this))->getNonConstAttributes();
1175 template<
typename ATTRIBUTETYPE>
1176 bool getAttribute(
const std::string &name, ATTRIBUTETYPE& value)
const;
1183 DataType* getAttribute(
const std::string& name)
const;
1190 template<
typename ATTRIBUTETYPE>
1191 void setAttribute(
const std::string &name,
const ATTRIBUTETYPE &value);
1198 void setAttribute(
const std::string &name,
const DataType* value);
1205 notifyRemoveAttribute(name);
1206 getNonConstAttributes().remove(name);
1215 return getAttributes().exist(name);
1222 return existAttribute(name);
1232 virtual void addLocalProperty(
const std::string &name,
PropertyInterface *prop)=0;
1258 template<
typename PropertyType>
1259 PropertyType* getLocalProperty(
const std::string &name);
1273 template<
typename PropertyType>
1274 PropertyType* getProperty(
const std::string &name);
1289 PropertyInterface *getLocalProperty(
const std::string& propertyName,
const std::string& propertyType);
1304 PropertyInterface *getProperty(
const std::string& propertyName,
const std::string& propertyType);
1311 virtual bool existProperty(
const std::string& name)
const = 0;
1318 virtual bool existLocalProperty(
const std::string& name)
const = 0;
1326 virtual void delLocalProperty(
const std::string& name)=0;
1332 virtual Iterator<std::string>* getLocalProperties()
const=0;
1338 virtual Iterator<PropertyInterface*>* getLocalObjectProperties()
const=0;
1345 virtual Iterator<std::string>* getInheritedProperties()
const=0;
1352 virtual Iterator<PropertyInterface*>* getInheritedObjectProperties()
const=0;
1359 virtual Iterator<std::string>* getProperties()
const=0;
1366 virtual Iterator<PropertyInterface*>* getObjectProperties()
const=0;
1380 bool applyPropertyAlgorithm(
const std::string &algorithm,
1382 std::string &errorMessage,
1447 virtual void push(
bool unpopAllowed =
true,
1448 std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL)=0;
1455 virtual void pop(
bool unpopAllowed =
true)=0;
1460 virtual void popIfNoUpdates()=0;
1497 virtual void unpop()=0;
1503 virtual bool canPop()=0;
1509 virtual bool canUnpop()=0;
1515 virtual bool canPopThenUnpop()=0;
1529 node createMetaNode(
const std::vector<node> &nodes,
bool multiEdges =
true,
1530 bool delAllEdge =
true);
1535 _DEPRECATED
node createMetaNode(
const std::set<node> &nodeSet,
1536 bool multiEdges =
true,
1537 bool delAllEdge =
true);
1548 void createMetaNodes(Iterator<Graph *> *itS,
Graph *quotientGraph,
1549 std::vector<node>& metaNodes);
1560 node createMetaNode(
Graph* subGraph,
bool multiEdges =
true,
bool delAllEdge =
true);
1571 void openMetaNode(
node n,
bool updateProperties=
true);
1575 virtual DataSet &getNonConstAttributes() = 0;
1578 virtual void restoreNode(
node)=0;
1579 virtual void restoreEdge(
edge,
node source,
node target)=0;
1582 virtual void removeNode(
const node)=0;
1583 virtual void removeEdge(
const edge)=0;
1588 return getRoot()->canDeleteProperty(g, prop);
1594 const std::string& newName)=0;
1597 virtual void removeSubGraph(
Graph*)=0;
1598 virtual void clearSubGraphs()=0;
1599 virtual void restoreSubGraph(
Graph*)=0;
1600 virtual void setSubGraphToKeep(
Graph*)=0;
1603 void notifyAddNode(
const node n);
1604 void notifyAddNode(
Graph*,
const node n) {
1607 void notifyAddEdge(
const edge e);
1608 void notifyAddEdge(
Graph*,
const edge e) {
1611 void notifyBeforeSetEnds(
const edge e);
1612 void notifyBeforeSetEnds(
Graph*,
const edge e) {
1613 notifyBeforeSetEnds(e);
1615 void notifyAfterSetEnds(
const edge e);
1616 void notifyAfterSetEnds(
Graph*,
const edge e) {
1617 notifyAfterSetEnds(e);
1619 void notifyDelNode(
const node n);
1620 void notifyDelNode(
Graph*,
const node n) {
1623 void notifyDelEdge(
const edge e);
1624 void notifyDelEdge(
Graph*,
const edge e) {
1627 void notifyReverseEdge(
const edge e);
1628 void notifyReverseEdge(
Graph*,
const edge e) {
1629 notifyReverseEdge(e);
1631 void notifyBeforeAddSubGraph(
const Graph*);
1632 void notifyAfterAddSubGraph(
const Graph*);
1633 void notifyBeforeAddSubGraph(
Graph*,
const Graph* sg) {
1634 notifyBeforeAddSubGraph(sg);
1636 void notifyAfterAddSubGraph(
Graph*,
const Graph* sg) {
1637 notifyAfterAddSubGraph(sg);
1639 void notifyBeforeDelSubGraph(
const Graph*);
1640 void notifyAfterDelSubGraph(
const Graph*);
1641 void notifyBeforeDelSubGraph(
Graph*,
const Graph* sg) {
1642 notifyBeforeDelSubGraph(sg);
1644 void notifyAfterDelSubGraph(
Graph*,
const Graph* sg) {
1645 notifyAfterDelSubGraph(sg);
1648 void notifyBeforeAddDescendantGraph(
const Graph*);
1649 void notifyAfterAddDescendantGraph(
const Graph*);
1650 void notifyBeforeDelDescendantGraph(
const Graph*);
1651 void notifyAfterDelDescendantGraph(
const Graph*);
1653 void notifyBeforeAddLocalProperty(
const std::string&);
1654 void notifyAddLocalProperty(
const std::string&);
1655 void notifyAddLocalProperty(
Graph*,
const std::string& name) {
1656 notifyAddLocalProperty(name);
1658 void notifyBeforeDelLocalProperty(
const std::string&);
1659 void notifyAfterDelLocalProperty(
const std::string&);
1660 void notifyDelLocalProperty(
Graph*,
const std::string& name) {
1661 notifyBeforeDelLocalProperty(name);
1663 void notifyBeforeSetAttribute(
const std::string&);
1664 void notifyBeforeSetAttribute(
Graph*,
const std::string& name) {
1665 notifyBeforeSetAttribute(name);
1667 void notifyAfterSetAttribute(
const std::string&);
1668 void notifyAfterSetAttribute(
Graph*,
const std::string& name) {
1669 notifyAfterSetAttribute(name);
1671 void notifyRemoveAttribute(
const std::string&);
1672 void notifyRemoveAttribute(
Graph*,
const std::string& name) {
1673 notifyRemoveAttribute(name);
1675 void notifyDestroy();
1676 void notifyDestroy(
Graph*) {
1681 TLP_HASH_MAP<std::string, tlp::PropertyInterface*> circularCalls;
1693 enum GraphEventType {
1698 TLP_REVERSE_EDGE = 4,
1699 TLP_BEFORE_SET_ENDS = 5,
1700 TLP_AFTER_SET_ENDS = 6,
1703 TLP_BEFORE_ADD_DESCENDANTGRAPH = 9,
1704 TLP_AFTER_ADD_DESCENDANTGRAPH = 10,
1705 TLP_BEFORE_DEL_DESCENDANTGRAPH = 11,
1706 TLP_AFTER_DEL_DESCENDANTGRAPH = 12,
1707 TLP_BEFORE_ADD_SUBGRAPH = 13,
1708 TLP_AFTER_ADD_SUBGRAPH = 14,
1709 TLP_BEFORE_DEL_SUBGRAPH = 15,
1710 TLP_AFTER_DEL_SUBGRAPH = 16,
1711 TLP_ADD_LOCAL_PROPERTY = 17,
1712 TLP_BEFORE_DEL_LOCAL_PROPERTY = 18,
1713 TLP_AFTER_DEL_LOCAL_PROPERTY = 19,
1714 TLP_ADD_INHERITED_PROPERTY = 20,
1715 TLP_BEFORE_DEL_INHERITED_PROPERTY = 21,
1716 TLP_AFTER_DEL_INHERITED_PROPERTY = 22,
1717 TLP_BEFORE_RENAME_LOCAL_PROPERTY = 23,
1718 TLP_AFTER_RENAME_LOCAL_PROPERTY = 24,
1719 TLP_BEFORE_SET_ATTRIBUTE = 25,
1720 TLP_AFTER_SET_ATTRIBUTE = 26,
1721 TLP_REMOVE_ATTRIBUTE = 27,
1722 TLP_BEFORE_ADD_LOCAL_PROPERTY = 28,
1723 TLP_BEFORE_ADD_INHERITED_PROPERTY = 29
1727 GraphEvent(
const Graph& g, GraphEventType graphEvtType,
unsigned int id,
1728 Event::EventType evtType = Event::TLP_MODIFICATION)
1729 :
Event(g, evtType), evtType(graphEvtType) {
1730 if (graphEvtType == TLP_ADD_NODES || graphEvtType == TLP_ADD_EDGES)
1735 vectInfos.addedNodes = NULL;
1740 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1742 vectInfos.addedNodes = NULL;
1747 const std::string& str,
1748 Event::EventType evtType = Event::TLP_MODIFICATION)
1749 :
Event(g, evtType), evtType(graphEvtType) {
1750 info.name =
new std::string(str);
1751 vectInfos.addedNodes = NULL;
1757 const std::string& newName)
1758 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1760 new std::pair<PropertyInterface*,std::string>(prop, newName);
1761 vectInfos.addedNodes = NULL;
1766 Graph* getGraph()
const {
1767 return static_cast<Graph *
>(sender());
1770 node getNode()
const {
1771 assert(evtType < TLP_ADD_EDGE);
1772 return node(info.eltId);
1775 edge getEdge()
const {
1776 assert(evtType > TLP_DEL_NODE && evtType < TLP_ADD_NODES);
1777 return edge(info.eltId);
1780 const std::vector<node>& getNodes()
const;
1782 unsigned int getNumberOfNodes()
const {
1783 assert(evtType == TLP_ADD_NODES);
1787 const std::vector<edge>& getEdges()
const;
1789 unsigned int getNumberOfEdges()
const {
1790 assert(evtType == TLP_ADD_EDGES);
1794 const Graph* getSubGraph()
const {
1795 assert(evtType > TLP_ADD_EDGES && evtType < TLP_ADD_LOCAL_PROPERTY);
1796 return info.subGraph;
1799 const std::string& getAttributeName()
const {
1800 assert(evtType > TLP_AFTER_DEL_INHERITED_PROPERTY);
1801 return *(info.name);
1804 const std::string& getPropertyName()
const;
1807 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
1808 evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1809 return info.renamedProp->first;
1812 const std::string& getPropertyNewName()
const {
1813 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY);
1814 return info.renamedProp->second;
1817 const std::string& getPropertyOldName()
const {
1818 assert(evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1819 return info.renamedProp->second;
1822 GraphEventType getType()
const {
1827 GraphEventType evtType;
1830 const Graph* subGraph;
1832 unsigned int nbElts;
1833 std::pair<PropertyInterface*, std::string>* renamedProp;
1836 std::vector<node>* addedNodes;
1837 std::vector<edge>* addedEdges;
1850 TLP_BEGIN_HASH_NAMESPACE {
1852 struct TLP_SCOPE hash<const tlp::
Graph *> {
1853 size_t operator()(
const tlp::Graph *s)
const {
return size_t(s->
getId());}
1856 struct TLP_SCOPE hash<tlp::
Graph *> {
1859 } TLP_END_HASH_NAMESPACE
1862 #include "cxx/Graph.cxx"
bool attributeExist(const std::string &name) const
deprecated, use existAttribute instead.
A graph property that maps a boolean value to graph elements.
Graph * newGraph()
Creates a new, empty graph.
std::ostream & operator<<(std::ostream &os, const Array< Obj, SIZE > &array)
operator << stream operator to easily print an array, or save it to a file.
PropertyInterface describes the interface of a graph property.
void copyToGraph(Graph *outG, const Graph *inG, BooleanProperty *inSelection=NULL, BooleanProperty *outSelection=NULL)
Interface for Tulip iterators. Allows basic iteration operations only.
virtual bool hasEdge(const node source, const node target, bool directed=true) const
Checks if an edge exists between two given nodes.
Describes a value of any type.
bool saveGraph(Graph *graph, const std::string &filename, tlp::PluginProgress *progress=NULL, tlp::DataSet *data=NULL)
Saves the corresponding graph to a file (extension can be any of the Tulip supported ouput graph file...
A container that can store data from any type.
bool existAttribute(const std::string &name) const
Checks if an attribute exists.
const DataSet & getAttributes() const
Gets the attributes of the graph.
Graph * importGraph(const std::string &format, DataSet &dataSet, PluginProgress *progress=NULL, Graph *newGraph=NULL)
Imports a graph using the specified import plugin with the parameters stored in the DataSet...
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.
Iterator< Graph * > * getRootGraphs()
Event is the base class for all events used in the Observation mechanism.
PluginProcess subclasses are meant to notify about the progress state of some process (typically a pl...
void removeAttribute(const std::string &name)
Removes an attribute on the graph.
unsigned int getId() const
Gets the unique identifier of the graph.
bool exportGraph(Graph *graph, std::ostream &outputStream, const std::string &format, DataSet &dataSet, PluginProgress *progress=NULL)
Exports a graph using the specified export plugin with parameters stored in the DataSet.
The Observable class is the base of Tulip's observation system.
void removeFromGraph(Graph *ioG, BooleanProperty *inSelection=NULL)
Graph * loadGraph(const std::string &filename, tlp::PluginProgress *progress=NULL)
Loads a graph from a file (extension can be any of the Tulip supported input graph file format)...