20 #ifndef Tulip_SUPERGRAPH_H 21 #define Tulip_SUPERGRAPH_H 28 #include <tulip/tulipconf.h> 29 #include <tulip/DataSet.h> 30 #include <tulip/Node.h> 31 #include <tulip/Edge.h> 32 #include <tulip/Observable.h> 36 class PropertyInterface;
37 class BooleanProperty;
210 friend class GraphAbstract;
211 friend class GraphUpdatesRecorder;
212 friend class GraphDecorator;
213 friend class PropertyManager;
241 bool applyAlgorithm(
const std::string &algorithm, std::string &errorMessage,
DataSet *dataSet=NULL,
PluginProgress *progress=NULL);
254 virtual void clear()=0;
270 const std::string& name =
"unnamed")=0;
278 Graph *addSubGraph(
const std::string& name);
288 virtual Graph* addCloneSubGraph(
const std::string& name =
"unnamed",
bool addSibling =
false,
bool addSiblingProperties =
false);
298 Graph *inducedSubGraph(
const std::set<node>& nodeSet,
299 Graph* parentSubGraph = NULL);
312 Graph* parentSubGraph = NULL);
334 virtual void delSubGraph(
Graph *graph)=0;
354 virtual void delAllSubGraphs(
Graph *graph)=0;
361 virtual Graph* getSuperGraph()
const =0;
367 virtual Graph* getRoot()
const =0;
375 virtual void setSuperGraph(
Graph *)=0;
390 virtual Iterator<Graph *> * getSubGraphs()
const=0;
411 virtual Graph *getNthSubGraph(
unsigned int n)
const;
427 virtual unsigned int numberOfSubGraphs()
const=0;
443 virtual unsigned int numberOfDescendantGraphs()
const=0;
451 virtual bool isSubGraph(
const Graph* subGraph)
const=0;
459 virtual bool isDescendantGraph(
const Graph* subGraph)
const=0;
468 virtual Graph* getSubGraph(
unsigned int id)
const=0;
477 virtual Graph* getSubGraph(
const std::string &name)
const=0;
486 virtual Graph* getDescendantGraph(
unsigned int id)
const=0;
495 virtual Graph* getDescendantGraph(
const std::string &name)
const=0;
510 Iterator<Graph *> * getDescendantGraphs()
const;
521 virtual node addNode()=0;
531 virtual void addNodes(
unsigned int nbNodes, std::vector<node>& addedNodes)=0;
542 virtual void addNode(
const node n)=0;
554 virtual void addNodes(Iterator<node>* nodes)=0;
565 void addNodes(
const std::vector<node>& nodes);
574 virtual void delNode(
const node n,
bool deleteInAllGraphs =
false)=0;
584 virtual void delNodes(Iterator<node>* it,
bool deleteInAllGraphs =
false)=0;
594 void delNodes(
const std::vector<node>& nodes,
bool deleteInAllGraphs =
false);
604 virtual edge addEdge(
const node source,
const node target)=0;
617 virtual void addEdges(
const std::vector<std::pair<node, node> >& edges,
618 std::vector<edge>& addedEdges)=0;
630 virtual void addEdge(
const edge e)=0;
641 virtual void addEdges(Iterator<edge>* edges)=0;
651 void addEdges(
const std::vector<edge>& edges);
660 virtual void delEdge(
const edge e,
bool deleteInAllGraphs =
false)=0;
669 virtual void delEdges(Iterator<edge>* itE,
bool deleteInAllGraphs =
false)=0;
678 void delEdges(
const std::vector<edge>& edges,
bool deleteInAllGraphs =
false);
689 virtual void setEdgeOrder(
const node n,
const std::vector<edge> &edges)=0;
697 virtual void swapEdgeOrder(
const node n,
const edge e1,
const edge e2)=0;
704 virtual void setSource(
const edge e,
const node source) = 0;
711 virtual void setTarget(
const edge e,
const node target) = 0;
719 virtual void setEnds(
const edge e,
const node source,
const node target) = 0;
728 virtual void reverse(
const edge e)=0;
731 virtual void reserveNodes(
unsigned int nbNodes) = 0;
734 virtual void reserveEdges(
unsigned int nbEdges) = 0;
749 virtual node getOneNode()
const =0;
757 virtual node getRandomNode()
const =0;
767 virtual Iterator<node>* getNodes()
const =0;
790 virtual node getInNode(
const node n,
unsigned int i)
const =0;
800 virtual Iterator<node>* getInNodes(
const node n)
const =0;
823 virtual node getOutNode(
const node n,
unsigned int i)
const =0;
833 virtual Iterator<node>* getOutNodes(
const node n)
const =0;
840 virtual Iterator<node>* getInOutNodes(
const node n)
const =0;
849 virtual Iterator<node>* bfs(
const node root =
node())
const = 0;
858 virtual Iterator<node>* dfs(
const node root =
node())
const = 0;
866 virtual Graph* getNodeMetaInfo(
const node metaNode)
const = 0;
875 virtual Iterator<edge>* getEdges()
const =0;
881 virtual edge getOneEdge()
const =0;
889 virtual edge getRandomEdge()
const =0;
899 virtual Iterator<edge>* getOutEdges(
const node n)
const =0;
909 virtual Iterator<edge>* getInOutEdges(
const node n)
const =0;
919 virtual Iterator<edge>* getInEdges(
const node n)
const =0;
927 virtual Iterator<edge>* getEdgeMetaInfo(
const edge metaEdge)
const =0;
945 virtual unsigned int numberOfNodes()
const =0;
952 virtual unsigned int numberOfEdges()
const =0;
958 virtual unsigned int deg(
const node n)
const =0;
965 virtual unsigned int indeg(
const node n)
const =0;
972 virtual unsigned int outdeg(
const node n)
const =0;
979 virtual node source(
const edge e)
const =0;
986 virtual node target(
const edge e)
const =0;
993 virtual const std::pair<node, node>& ends(
const edge e)
const=0;
1001 virtual node opposite(
const edge e,
const node n)
const =0;
1008 virtual bool isElement(
const node n)
const =0;
1015 virtual bool isMetaNode(
const node n)
const =0;
1022 virtual bool isElement(
const edge e)
const =0;
1029 virtual bool isMetaEdge(
const edge e)
const =0;
1039 bool directed =
true)
const {
1040 return existEdge(source, target, directed).isValid();
1051 virtual std::vector<edge> getEdges(
const node source,
const node target,
1052 bool directed =
true)
const=0;
1064 virtual edge existEdge(
const node source,
const node target,
1065 bool directed =
true)
const=0;
1075 virtual void setName(
const std::string &name) = 0;
1081 virtual std::string getName()
const = 0;
1090 return (const_cast<Graph *>(
this))->getNonConstAttributes();
1099 template<
typename ATTRIBUTETYPE>
1100 bool getAttribute(
const std::string &name, ATTRIBUTETYPE& value)
const;
1107 DataType* getAttribute(
const std::string& name)
const;
1114 template<
typename ATTRIBUTETYPE>
1115 void setAttribute(
const std::string &name,
const ATTRIBUTETYPE &value);
1122 void setAttribute(
const std::string &name,
const DataType* value);
1129 notifyRemoveAttribute(name);
1130 getNonConstAttributes().remove(name);
1139 return getAttributes().exist(name);
1146 return existAttribute(name);
1156 virtual void addLocalProperty(
const std::string &name,
PropertyInterface *prop)=0;
1182 template<
typename PropertyType>
1183 PropertyType* getLocalProperty(
const std::string &name);
1197 template<
typename PropertyType>
1198 PropertyType* getProperty(
const std::string &name);
1213 PropertyInterface *getLocalProperty(
const std::string& propertyName,
const std::string& propertyType);
1228 PropertyInterface *getProperty(
const std::string& propertyName,
const std::string& propertyType);
1235 virtual bool existProperty(
const std::string& name)
const = 0;
1242 virtual bool existLocalProperty(
const std::string& name)
const = 0;
1250 virtual void delLocalProperty(
const std::string& name)=0;
1256 virtual Iterator<std::string>* getLocalProperties()
const=0;
1262 virtual Iterator<PropertyInterface*>* getLocalObjectProperties()
const=0;
1269 virtual Iterator<std::string>* getInheritedProperties()
const=0;
1276 virtual Iterator<PropertyInterface*>* getInheritedObjectProperties()
const=0;
1283 virtual Iterator<std::string>* getProperties()
const=0;
1290 virtual Iterator<PropertyInterface*>* getObjectProperties()
const=0;
1304 bool applyPropertyAlgorithm(
const std::string &algorithm,
1306 std::string &errorMessage,
1370 virtual void push(
bool unpopAllowed =
true,
1371 std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL)=0;
1378 virtual void pop(
bool unpopAllowed =
true)=0;
1414 virtual void unpop()=0;
1420 virtual bool canPop()=0;
1426 virtual bool canUnpop()=0;
1432 virtual bool canPopThenUnpop()=0;
1446 node createMetaNode(
const std::set<node> &nodeSet,
bool multiEdges =
true,
bool delAllEdge =
true);
1457 void createMetaNodes(Iterator<Graph *> *itS,
Graph *quotientGraph,
1458 std::vector<node>& metaNodes);
1469 node createMetaNode(
Graph* subGraph,
bool multiEdges =
true,
bool delAllEdge =
true);
1480 void openMetaNode(
node n,
bool updateProperties=
true);
1484 virtual DataSet &getNonConstAttributes() = 0;
1488 virtual void restoreNodes(
const std::vector<node>& nodes)=0;
1490 virtual void restoreEdges(
const std::vector<edge>& edges,
1491 const std::vector<std::pair<node, node> >& ends)=0;
1494 virtual void removeNode(
const node)=0;
1495 virtual void removeEdge(
const edge)=0;
1500 return getRoot()->canDeleteProperty(g, prop);
1506 const std::string& newName)=0;
1509 virtual void removeSubGraph(
Graph*)=0;
1510 virtual void clearSubGraphs()=0;
1511 virtual void restoreSubGraph(
Graph*)=0;
1512 virtual void setSubGraphToKeep(
Graph*)=0;
1515 void notifyAddNode(
const node n);
1516 void notifyAddNode(
Graph*,
const node n) {
1519 void notifyAddEdge(
const edge e);
1520 void notifyAddEdge(
Graph*,
const edge e) {
1523 void notifyBeforeSetEnds(
const edge e);
1524 void notifyBeforeSetEnds(
Graph*,
const edge e) {
1525 notifyBeforeSetEnds(e);
1527 void notifyAfterSetEnds(
const edge e);
1528 void notifyAfterSetEnds(
Graph*,
const edge e) {
1529 notifyAfterSetEnds(e);
1531 void notifyDelNode(
const node n);
1532 void notifyDelNode(
Graph*,
const node n) {
1535 void notifyDelEdge(
const edge e);
1536 void notifyDelEdge(
Graph*,
const edge e) {
1539 void notifyReverseEdge(
const edge e);
1540 void notifyReverseEdge(
Graph*,
const edge e) {
1541 notifyReverseEdge(e);
1543 void notifyBeforeAddSubGraph(
const Graph*);
1544 void notifyAfterAddSubGraph(
const Graph*);
1545 void notifyBeforeAddSubGraph(
Graph*,
const Graph* sg) {
1546 notifyBeforeAddSubGraph(sg);
1548 void notifyAfterAddSubGraph(
Graph*,
const Graph* sg) {
1549 notifyAfterAddSubGraph(sg);
1551 void notifyBeforeDelSubGraph(
const Graph*);
1552 void notifyAfterDelSubGraph(
const Graph*);
1553 void notifyBeforeDelSubGraph(
Graph*,
const Graph* sg) {
1554 notifyBeforeDelSubGraph(sg);
1556 void notifyAfterDelSubGraph(
Graph*,
const Graph* sg) {
1557 notifyAfterDelSubGraph(sg);
1560 void notifyBeforeAddDescendantGraph(
const Graph*);
1561 void notifyAfterAddDescendantGraph(
const Graph*);
1562 void notifyBeforeDelDescendantGraph(
const Graph*);
1563 void notifyAfterDelDescendantGraph(
const Graph*);
1565 void notifyBeforeAddLocalProperty(
const std::string&);
1566 void notifyAddLocalProperty(
const std::string&);
1567 void notifyAddLocalProperty(
Graph*,
const std::string& name) {
1568 notifyAddLocalProperty(name);
1570 void notifyBeforeDelLocalProperty(
const std::string&);
1571 void notifyAfterDelLocalProperty(
const std::string&);
1572 void notifyDelLocalProperty(
Graph*,
const std::string& name) {
1573 notifyBeforeDelLocalProperty(name);
1575 void notifyBeforeSetAttribute(
const std::string&);
1576 void notifyBeforeSetAttribute(
Graph*,
const std::string& name) {
1577 notifyBeforeSetAttribute(name);
1579 void notifyAfterSetAttribute(
const std::string&);
1580 void notifyAfterSetAttribute(
Graph*,
const std::string& name) {
1581 notifyAfterSetAttribute(name);
1583 void notifyRemoveAttribute(
const std::string&);
1584 void notifyRemoveAttribute(
Graph*,
const std::string& name) {
1585 notifyRemoveAttribute(name);
1587 void notifyDestroy();
1588 void notifyDestroy(
Graph*) {
1593 TLP_HASH_MAP<std::string, tlp::PropertyInterface*> circularCalls;
1605 enum GraphEventType {
1610 TLP_REVERSE_EDGE = 4,
1611 TLP_BEFORE_SET_ENDS = 5,
1612 TLP_AFTER_SET_ENDS = 6,
1615 TLP_BEFORE_ADD_DESCENDANTGRAPH = 9,
1616 TLP_AFTER_ADD_DESCENDANTGRAPH = 10,
1617 TLP_BEFORE_DEL_DESCENDANTGRAPH = 11,
1618 TLP_AFTER_DEL_DESCENDANTGRAPH = 12,
1619 TLP_BEFORE_ADD_SUBGRAPH = 13,
1620 TLP_AFTER_ADD_SUBGRAPH = 14,
1621 TLP_BEFORE_DEL_SUBGRAPH = 15,
1622 TLP_AFTER_DEL_SUBGRAPH = 16,
1623 TLP_ADD_LOCAL_PROPERTY = 17,
1624 TLP_BEFORE_DEL_LOCAL_PROPERTY = 18,
1625 TLP_AFTER_DEL_LOCAL_PROPERTY = 19,
1626 TLP_ADD_INHERITED_PROPERTY = 20,
1627 TLP_BEFORE_DEL_INHERITED_PROPERTY = 21,
1628 TLP_AFTER_DEL_INHERITED_PROPERTY = 22,
1629 TLP_BEFORE_RENAME_LOCAL_PROPERTY = 23,
1630 TLP_AFTER_RENAME_LOCAL_PROPERTY = 24,
1631 TLP_BEFORE_SET_ATTRIBUTE = 25,
1632 TLP_AFTER_SET_ATTRIBUTE = 26,
1633 TLP_REMOVE_ATTRIBUTE = 27,
1634 TLP_BEFORE_ADD_LOCAL_PROPERTY = 28,
1635 TLP_BEFORE_ADD_INHERITED_PROPERTY = 29
1639 GraphEvent(
const Graph& g, GraphEventType graphEvtType,
unsigned int id,
1640 Event::EventType evtType = Event::TLP_MODIFICATION)
1641 :
Event(g, evtType), evtType(graphEvtType) {
1646 const std::vector<node>& nodes,
1647 Event::EventType evtType = Event::TLP_MODIFICATION)
1648 :
Event(g, evtType), evtType(graphEvtType) {
1649 info.nodes = &nodes;
1653 const std::vector<edge>& edges,
1654 Event::EventType evtType = Event::TLP_MODIFICATION)
1655 :
Event(g, evtType), evtType(graphEvtType) {
1656 info.edges = &edges;
1661 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1667 const std::string& str,
1668 Event::EventType evtType = Event::TLP_MODIFICATION)
1669 :
Event(g, evtType), evtType(graphEvtType) {
1670 info.name =
new std::string(str);
1676 const std::string& newName)
1677 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1679 new std::pair<PropertyInterface*,std::string>(prop, newName);
1684 if (evtType > TLP_AFTER_DEL_SUBGRAPH) {
1685 if (evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
1686 evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY)
1687 delete info.renamedProp;
1693 Graph* getGraph()
const {
1694 return static_cast<Graph *
>(sender());
1697 node getNode()
const {
1698 assert(evtType < TLP_ADD_EDGE);
1699 return node(info.eltId);
1702 edge getEdge()
const {
1703 assert(evtType > TLP_DEL_NODE && evtType < TLP_ADD_NODES);
1704 return edge(info.eltId);
1707 const std::vector<node>& getNodes()
const {
1708 assert(evtType == TLP_ADD_NODES);
1709 return *(info.nodes);
1712 const std::vector<edge>& getEdges()
const {
1713 assert(evtType == TLP_ADD_EDGES);
1714 return *(info.edges);
1717 const Graph* getSubGraph()
const {
1718 assert(evtType > TLP_ADD_EDGES && evtType < TLP_ADD_LOCAL_PROPERTY);
1719 return info.subGraph;
1722 const std::string& getAttributeName()
const {
1723 assert(evtType > TLP_AFTER_DEL_INHERITED_PROPERTY);
1724 return *(info.name);
1727 const std::string& getPropertyName()
const;
1730 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
1731 evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1732 return info.renamedProp->first;
1735 const std::string& getPropertyNewName()
const {
1736 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY);
1737 return info.renamedProp->second;
1740 const std::string& getPropertyOldName()
const {
1741 assert(evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1742 return info.renamedProp->second;
1745 GraphEventType getType()
const {
1750 GraphEventType evtType;
1753 const Graph* subGraph;
1755 const std::vector<node>* nodes;
1756 const std::vector<edge>* edges;
1757 std::pair<PropertyInterface*, std::string>* renamedProp;
1770 TLP_BEGIN_HASH_NAMESPACE {
1772 struct TLP_SCOPE hash<const tlp::
Graph *> {
1773 size_t operator()(
const tlp::Graph *s)
const {
return size_t(s->
getId());}
1776 struct TLP_SCOPE hash<tlp::
Graph *> {
1779 } TLP_END_HASH_NAMESPACE
1782 #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.
A container that can store data from any type.
bool existAttribute(const std::string &name) const
Checks if an attribute exists.
bool saveGraph(Graph *graph, const std::string &filename, tlp::PluginProgress *progress=NULL)
Saves the corresponding graph to a file (extension can be any of the Tulip supported ouput graph file...
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)...