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;
39 template<
class C>
struct Iterator;
108 TLP_SCOPE
bool exportGraph(Graph *graph, std::ostream &outputStream,
const std::string &format, DataSet &dataSet, PluginProgress *progress=NULL);
123 TLP_SCOPE Graph*
importGraph(
const std::string &format, DataSet &dataSet, PluginProgress *progress=NULL,Graph *
newGraph=NULL);
144 TLP_SCOPE
void copyToGraph(Graph *outG,
const Graph *inG, BooleanProperty* inSelection=NULL, BooleanProperty* outSelection=NULL );
152 TLP_SCOPE
void removeFromGraph(Graph * ioG, BooleanProperty* inSelection=NULL);
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);
321 virtual void delSubGraph(
Graph *graph)=0;
341 virtual void delAllSubGraphs(
Graph *graph)=0;
348 virtual Graph* getSuperGraph()
const =0;
354 virtual Graph* getRoot()
const =0;
362 virtual void setSuperGraph(
Graph *)=0;
377 virtual Iterator<Graph *> * getSubGraphs()
const=0;
398 virtual Graph *getNthSubGraph(
unsigned int n)
const;
414 virtual unsigned int numberOfSubGraphs()
const=0;
430 virtual unsigned int numberOfDescendantGraphs()
const=0;
438 virtual bool isSubGraph(
const Graph* subGraph)
const=0;
446 virtual bool isDescendantGraph(
const Graph* subGraph)
const=0;
455 virtual Graph* getSubGraph(
unsigned int id)
const=0;
464 virtual Graph* getSubGraph(
const std::string &name)
const=0;
473 virtual Graph* getDescendantGraph(
unsigned int id)
const=0;
482 virtual Graph* getDescendantGraph(
const std::string &name)
const=0;
497 Iterator<Graph *> * getDescendantGraphs()
const;
508 virtual node addNode()=0;
518 virtual void addNodes(
unsigned int nbNodes, std::vector<node>& addedNodes)=0;
529 virtual void addNode(
const node n)=0;
541 virtual void addNodes(Iterator<node>* nodes)=0;
552 void addNodes(
const std::vector<node>& nodes);
561 virtual void delNode(
const node n,
bool deleteInAllGraphs =
false)=0;
571 virtual void delNodes(Iterator<node>* it,
bool deleteInAllGraphs =
false)=0;
581 void delNodes(
const std::vector<node>& nodes,
bool deleteInAllGraphs =
false);
591 virtual edge addEdge(
const node source,
const node target)=0;
604 virtual void addEdges(
const std::vector<std::pair<node, node> >& edges,
605 std::vector<edge>& addedEdges)=0;
617 virtual void addEdge(
const edge e)=0;
628 virtual void addEdges(Iterator<edge>* edges)=0;
638 void addEdges(
const std::vector<edge>& edges);
647 virtual void delEdge(
const edge e,
bool deleteInAllGraphs =
false)=0;
656 virtual void delEdges(Iterator<edge>* itE,
bool deleteInAllGraphs =
false)=0;
665 void delEdges(
const std::vector<edge>& edges,
bool deleteInAllGraphs =
false);
676 virtual void setEdgeOrder(
const node n,
const std::vector<edge> &edges)=0;
684 virtual void swapEdgeOrder(
const node n,
const edge e1,
const edge e2)=0;
691 virtual void setSource(
const edge e,
const node source) = 0;
698 virtual void setTarget(
const edge e,
const node target) = 0;
706 virtual void setEnds(
const edge e,
const node source,
const node target) = 0;
715 virtual void reverse(
const edge e)=0;
718 virtual void reserveNodes(
unsigned int nbNodes) = 0;
721 virtual void reserveEdges(
unsigned int nbEdges) = 0;
736 virtual node getOneNode()
const =0;
744 virtual node getRandomNode()
const =0;
754 virtual Iterator<node>* getNodes()
const =0;
777 virtual node getInNode(
const node n,
unsigned int i)
const =0;
787 virtual Iterator<node>* getInNodes(
const node n)
const =0;
810 virtual node getOutNode(
const node n,
unsigned int i)
const =0;
820 virtual Iterator<node>* getOutNodes(
const node n)
const =0;
827 virtual Iterator<node>* getInOutNodes(
const node n)
const =0;
836 virtual Iterator<node>* bfs(
const node root =
node())
const = 0;
845 virtual Iterator<node>* dfs(
const node root =
node())
const = 0;
853 virtual Graph* getNodeMetaInfo(
const node metaNode)
const = 0;
862 virtual Iterator<edge>* getEdges()
const =0;
868 virtual edge getOneEdge()
const =0;
876 virtual edge getRandomEdge()
const =0;
886 virtual Iterator<edge>* getOutEdges(
const node n)
const =0;
896 virtual Iterator<edge>* getInOutEdges(
const node n)
const =0;
906 virtual Iterator<edge>* getInEdges(
const node n)
const =0;
914 virtual Iterator<edge>* getEdgeMetaInfo(
const edge metaEdge)
const =0;
932 virtual unsigned int numberOfNodes()
const =0;
939 virtual unsigned int numberOfEdges()
const =0;
945 virtual unsigned int deg(
const node n)
const =0;
952 virtual unsigned int indeg(
const node n)
const =0;
959 virtual unsigned int outdeg(
const node n)
const =0;
966 virtual node source(
const edge e)
const =0;
973 virtual node target(
const edge e)
const =0;
980 virtual const std::pair<node, node>& ends(
const edge e)
const=0;
988 virtual node opposite(
const edge e,
const node n)
const =0;
995 virtual bool isElement(
const node n)
const =0;
1002 virtual bool isMetaNode(
const node n)
const =0;
1009 virtual bool isElement(
const edge e)
const =0;
1016 virtual bool isMetaEdge(
const edge e)
const =0;
1026 bool directed =
true)
const {
1027 return existEdge(source, target, directed).isValid();
1038 virtual std::vector<edge> getEdges(
const node source,
const node target,
1039 bool directed =
true)
const=0;
1051 virtual edge existEdge(
const node source,
const node target,
1052 bool directed =
true)
const=0;
1062 virtual void setName(
const std::string &name) = 0;
1068 virtual std::string getName()
const = 0;
1077 return (const_cast<Graph *>(
this))->getNonConstAttributes();
1086 template<
typename ATTRIBUTETYPE>
1087 bool getAttribute(
const std::string &name, ATTRIBUTETYPE& value)
const;
1094 DataType* getAttribute(
const std::string& name)
const;
1101 template<
typename ATTRIBUTETYPE>
1102 void setAttribute(
const std::string &name,
const ATTRIBUTETYPE &value);
1109 void setAttribute(
const std::string &name,
const DataType* value);
1116 notifyRemoveAttribute(name);
1117 getNonConstAttributes().remove(name);
1126 return getAttributes().exist(name);
1136 virtual void addLocalProperty(
const std::string &name,
PropertyInterface *prop)=0;
1162 template<
typename PropertyType>
1163 PropertyType* getLocalProperty(
const std::string &name);
1177 template<
typename PropertyType>
1178 PropertyType* getProperty(
const std::string &name);
1193 PropertyInterface *getLocalProperty(
const std::string& propertyName,
const std::string& propertyType);
1208 PropertyInterface *getProperty(
const std::string& propertyName,
const std::string& propertyType);
1215 virtual bool existProperty(
const std::string& name)
const = 0;
1222 virtual bool existLocalProperty(
const std::string& name)
const = 0;
1230 virtual void delLocalProperty(
const std::string& name)=0;
1236 virtual Iterator<std::string>* getLocalProperties()
const=0;
1242 virtual Iterator<PropertyInterface*>* getLocalObjectProperties()
const=0;
1249 virtual Iterator<std::string>* getInheritedProperties()
const=0;
1256 virtual Iterator<PropertyInterface*>* getInheritedObjectProperties()
const=0;
1263 virtual Iterator<std::string>* getProperties()
const=0;
1270 virtual Iterator<PropertyInterface*>* getObjectProperties()
const=0;
1284 bool applyPropertyAlgorithm(
const std::string &algorithm,
1286 std::string &errorMessage,
1350 virtual void push(
bool unpopAllowed =
true,
1351 std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL)=0;
1358 virtual void pop(
bool unpopAllowed =
true)=0;
1394 virtual void unpop()=0;
1400 virtual bool canPop()=0;
1406 virtual bool canUnpop()=0;
1412 virtual bool canPopThenUnpop()=0;
1426 node createMetaNode(
const std::set<node> &nodeSet,
bool multiEdges =
true,
bool delAllEdge =
true);
1437 void createMetaNodes(Iterator<Graph *> *itS,
Graph *quotientGraph,
1438 std::vector<node>& metaNodes);
1449 node createMetaNode(
Graph* subGraph,
bool multiEdges =
true,
bool delAllEdge =
true);
1460 void openMetaNode(
node n,
bool updateProperties=
true);
1463 virtual DataSet &getNonConstAttributes() = 0;
1467 virtual void restoreNodes(
const std::vector<node>& nodes)=0;
1469 virtual void restoreEdges(
const std::vector<edge>& edges,
1470 const std::vector<std::pair<node, node> >& ends)=0;
1473 virtual void removeNode(
const node)=0;
1474 virtual void removeEdge(
const edge)=0;
1479 return getRoot()->canDeleteProperty(g, prop);
1484 virtual bool renameLocalProperty(PropertyInterface* prop,
1485 const std::string& newName)=0;
1488 virtual void removeSubGraph(Graph*)=0;
1489 virtual void clearSubGraphs()=0;
1490 virtual void restoreSubGraph(Graph*)=0;
1491 virtual void setSubGraphToKeep(Graph*)=0;
1494 void notifyAddNode(
const node n);
1495 void notifyAddNode(Graph*,
const node n) {
1498 void notifyAddEdge(
const edge e);
1499 void notifyAddEdge(Graph*,
const edge e) {
1502 void notifyBeforeSetEnds(
const edge e);
1503 void notifyBeforeSetEnds(Graph*,
const edge e) {
1504 notifyBeforeSetEnds(e);
1506 void notifyAfterSetEnds(
const edge e);
1507 void notifyAfterSetEnds(Graph*,
const edge e) {
1508 notifyAfterSetEnds(e);
1510 void notifyDelNode(
const node n);
1511 void notifyDelNode(Graph*,
const node n) {
1514 void notifyDelEdge(
const edge e);
1515 void notifyDelEdge(Graph*,
const edge e) {
1518 void notifyReverseEdge(
const edge e);
1519 void notifyReverseEdge(Graph*,
const edge e) {
1520 notifyReverseEdge(e);
1522 void notifyBeforeAddSubGraph(
const Graph*);
1523 void notifyAfterAddSubGraph(
const Graph*);
1524 void notifyBeforeAddSubGraph(Graph*,
const Graph* sg) {
1525 notifyBeforeAddSubGraph(sg);
1527 void notifyAfterAddSubGraph(Graph*,
const Graph* sg) {
1528 notifyAfterAddSubGraph(sg);
1530 void notifyBeforeDelSubGraph(
const Graph*);
1531 void notifyAfterDelSubGraph(
const Graph*);
1532 void notifyBeforeDelSubGraph(Graph*,
const Graph* sg) {
1533 notifyBeforeDelSubGraph(sg);
1535 void notifyAfterDelSubGraph(Graph*,
const Graph* sg) {
1536 notifyAfterDelSubGraph(sg);
1539 void notifyBeforeAddDescendantGraph(
const Graph*);
1540 void notifyAfterAddDescendantGraph(
const Graph*);
1541 void notifyBeforeDelDescendantGraph(
const Graph*);
1542 void notifyAfterDelDescendantGraph(
const Graph*);
1544 void notifyBeforeAddLocalProperty(
const std::string&);
1545 void notifyAddLocalProperty(
const std::string&);
1546 void notifyAddLocalProperty(Graph*,
const std::string& name) {
1547 notifyAddLocalProperty(name);
1549 void notifyBeforeDelLocalProperty(
const std::string&);
1550 void notifyAfterDelLocalProperty(
const std::string&);
1551 void notifyDelLocalProperty(Graph*,
const std::string& name) {
1552 notifyBeforeDelLocalProperty(name);
1554 void notifyBeforeSetAttribute(
const std::string&);
1555 void notifyBeforeSetAttribute(Graph*,
const std::string& name) {
1556 notifyBeforeSetAttribute(name);
1558 void notifyAfterSetAttribute(
const std::string&);
1559 void notifyAfterSetAttribute(Graph*,
const std::string& name) {
1560 notifyAfterSetAttribute(name);
1562 void notifyRemoveAttribute(
const std::string&);
1563 void notifyRemoveAttribute(Graph*,
const std::string& name) {
1564 notifyRemoveAttribute(name);
1566 void notifyDestroy();
1567 void notifyDestroy(Graph*) {
1572 TLP_HASH_MAP<std::string, tlp::PropertyInterface*> circularCalls;
1583 enum GraphEventType {
1588 TLP_REVERSE_EDGE = 4,
1589 TLP_BEFORE_SET_ENDS = 5,
1590 TLP_AFTER_SET_ENDS = 6,
1593 TLP_BEFORE_ADD_DESCENDANTGRAPH = 9,
1594 TLP_AFTER_ADD_DESCENDANTGRAPH = 10,
1595 TLP_BEFORE_DEL_DESCENDANTGRAPH = 11,
1596 TLP_AFTER_DEL_DESCENDANTGRAPH = 12,
1597 TLP_BEFORE_ADD_SUBGRAPH = 13,
1598 TLP_AFTER_ADD_SUBGRAPH = 14,
1599 TLP_BEFORE_DEL_SUBGRAPH = 15,
1600 TLP_AFTER_DEL_SUBGRAPH = 16,
1601 TLP_ADD_LOCAL_PROPERTY = 17,
1602 TLP_BEFORE_DEL_LOCAL_PROPERTY = 18,
1603 TLP_AFTER_DEL_LOCAL_PROPERTY = 19,
1604 TLP_ADD_INHERITED_PROPERTY = 20,
1605 TLP_BEFORE_DEL_INHERITED_PROPERTY = 21,
1606 TLP_AFTER_DEL_INHERITED_PROPERTY = 22,
1607 TLP_BEFORE_RENAME_LOCAL_PROPERTY = 23,
1608 TLP_AFTER_RENAME_LOCAL_PROPERTY = 24,
1609 TLP_BEFORE_SET_ATTRIBUTE = 25,
1610 TLP_AFTER_SET_ATTRIBUTE = 26,
1611 TLP_REMOVE_ATTRIBUTE = 27,
1612 TLP_BEFORE_ADD_LOCAL_PROPERTY = 28,
1613 TLP_BEFORE_ADD_INHERITED_PROPERTY = 29
1617 GraphEvent(
const Graph& g, GraphEventType graphEvtType,
unsigned int id,
1618 Event::EventType evtType = Event::TLP_MODIFICATION)
1619 :
Event(g, evtType), evtType(graphEvtType) {
1624 const std::vector<node>& nodes,
1625 Event::EventType evtType = Event::TLP_MODIFICATION)
1626 :
Event(g, evtType), evtType(graphEvtType) {
1627 info.nodes = &nodes;
1631 const std::vector<edge>& edges,
1632 Event::EventType evtType = Event::TLP_MODIFICATION)
1633 :
Event(g, evtType), evtType(graphEvtType) {
1634 info.edges = &edges;
1639 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1645 const std::string& str,
1646 Event::EventType evtType = Event::TLP_MODIFICATION)
1647 :
Event(g, evtType), evtType(graphEvtType) {
1648 info.name =
new std::string(str);
1654 const std::string& newName)
1655 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1657 new std::pair<PropertyInterface*,std::string>(prop, newName);
1662 if (evtType > TLP_AFTER_DEL_SUBGRAPH) {
1663 if (evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
1664 evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY)
1665 delete info.renamedProp;
1671 Graph* getGraph()
const {
1672 return static_cast<Graph *
>(sender());
1675 node getNode()
const {
1676 assert(evtType < TLP_ADD_EDGE);
1677 return node(info.eltId);
1680 edge getEdge()
const {
1681 assert(evtType > TLP_DEL_NODE && evtType < TLP_ADD_NODES);
1682 return edge(info.eltId);
1685 const std::vector<node>& getNodes()
const {
1686 assert(evtType == TLP_ADD_NODES);
1687 return *(info.nodes);
1690 const std::vector<edge>& getEdges()
const {
1691 assert(evtType == TLP_ADD_EDGES);
1692 return *(info.edges);
1695 const Graph* getSubGraph()
const {
1696 assert(evtType > TLP_ADD_EDGES && evtType < TLP_ADD_LOCAL_PROPERTY);
1697 return info.subGraph;
1700 const std::string& getAttributeName()
const {
1701 assert(evtType > TLP_AFTER_DEL_INHERITED_PROPERTY);
1702 return *(info.name);
1705 const std::string& getPropertyName()
const;
1708 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
1709 evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1710 return info.renamedProp->first;
1713 const std::string& getPropertyNewName()
const {
1714 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY);
1715 return info.renamedProp->second;
1718 const std::string& getPropertyOldName()
const {
1719 assert(evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1720 return info.renamedProp->second;
1723 GraphEventType getType()
const {
1728 GraphEventType evtType;
1731 const Graph* subGraph;
1733 const std::vector<node>* nodes;
1734 const std::vector<edge>* edges;
1735 std::pair<PropertyInterface*, std::string>* renamedProp;
1742 TLP_SCOPE std::ostream& operator<< (std::ostream &,
const tlp::Graph *);
1747 #ifndef DOXYGEN_NOTFOR_DEVEL
1749 TLP_BEGIN_HASH_NAMESPACE {
1751 struct TLP_SCOPE hash<const tlp::Graph *> {
1752 size_t operator()(
const tlp::Graph *s)
const {
return size_t(s->
getId());}
1755 struct TLP_SCOPE hash<tlp::Graph *> {
1758 } TLP_END_HASH_NAMESPACE
1760 #endif // DOXYGEN_NOTFOR_DEVEL
1761 #include "cxx/Graph.cxx"
A graph property that maps a boolean value to graph elements.
Graph * newGraph()
Creates a new, empty graph.
PropertyInterface describes the interface of a graph property.
void copyToGraph(Graph *outG, const Graph *inG, BooleanProperty *inSelection=NULL, BooleanProperty *outSelection=NULL)
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 attributeExist(const std::string &name)
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)...