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);
287 virtual Graph* addCloneSubGraph(
const std::string& name =
"unnamed",
bool addSibling =
false);
297 Graph *inducedSubGraph(
const std::set<node>& nodeSet,
298 Graph* parentSubGraph = NULL);
320 virtual void delSubGraph(
Graph *graph)=0;
340 virtual void delAllSubGraphs(
Graph *graph)=0;
347 virtual Graph* getSuperGraph()
const =0;
353 virtual Graph* getRoot()
const =0;
361 virtual void setSuperGraph(
Graph *)=0;
376 virtual Iterator<Graph *> * getSubGraphs()
const=0;
397 virtual Graph *getNthSubGraph(
unsigned int n)
const;
413 virtual unsigned int numberOfSubGraphs()
const=0;
429 virtual unsigned int numberOfDescendantGraphs()
const=0;
437 virtual bool isSubGraph(
const Graph* subGraph)
const=0;
445 virtual bool isDescendantGraph(
const Graph* subGraph)
const=0;
454 virtual Graph* getSubGraph(
unsigned int id)
const=0;
463 virtual Graph* getSubGraph(
const std::string &name)
const=0;
472 virtual Graph* getDescendantGraph(
unsigned int id)
const=0;
481 virtual Graph* getDescendantGraph(
const std::string &name)
const=0;
496 Iterator<Graph *> * getDescendantGraphs()
const;
507 virtual node addNode()=0;
517 virtual void addNodes(
unsigned int nbNodes, std::vector<node>& addedNodes)=0;
528 virtual void addNode(
const node n)=0;
540 virtual void addNodes(Iterator<node>* nodes)=0;
551 void addNodes(
const std::vector<node>& nodes);
560 virtual void delNode(
const node n,
bool deleteInAllGraphs =
false)=0;
570 virtual void delNodes(Iterator<node>* it,
bool deleteInAllGraphs =
false)=0;
580 void delNodes(
const std::vector<node>& nodes,
bool deleteInAllGraphs =
false);
590 virtual edge addEdge(
const node source,
const node target)=0;
603 virtual void addEdges(
const std::vector<std::pair<node, node> >& edges,
604 std::vector<edge>& addedEdges)=0;
616 virtual void addEdge(
const edge e)=0;
627 virtual void addEdges(Iterator<edge>* edges)=0;
637 void addEdges(
const std::vector<edge>& edges);
646 virtual void delEdge(
const edge e,
bool deleteInAllGraphs =
false)=0;
655 virtual void delEdges(Iterator<edge>* itE,
bool deleteInAllGraphs =
false)=0;
664 void delEdges(
const std::vector<edge>& edges,
bool deleteInAllGraphs =
false);
675 virtual void setEdgeOrder(
const node n,
const std::vector<edge> &edges)=0;
683 virtual void swapEdgeOrder(
const node n,
const edge e1,
const edge e2)=0;
690 virtual void setSource(
const edge e,
const node source) = 0;
697 virtual void setTarget(
const edge e,
const node target) = 0;
705 virtual void setEnds(
const edge e,
const node source,
const node target) = 0;
714 virtual void reverse(
const edge e)=0;
717 virtual void reserveNodes(
unsigned int nbNodes) = 0;
720 virtual void reserveEdges(
unsigned int nbEdges) = 0;
735 virtual node getOneNode()
const =0;
743 virtual node getRandomNode()
const =0;
753 virtual Iterator<node>* getNodes()
const =0;
776 virtual node getInNode(
const node n,
unsigned int i)
const =0;
786 virtual Iterator<node>* getInNodes(
const node n)
const =0;
809 virtual node getOutNode(
const node n,
unsigned int i)
const =0;
819 virtual Iterator<node>* getOutNodes(
const node n)
const =0;
826 virtual Iterator<node>* getInOutNodes(
const node n)
const =0;
835 virtual Iterator<node>* bfs(
const node root =
node())
const = 0;
844 virtual Iterator<node>* dfs(
const node root =
node())
const = 0;
852 virtual Graph* getNodeMetaInfo(
const node metaNode)
const = 0;
861 virtual Iterator<edge>* getEdges()
const =0;
867 virtual edge getOneEdge()
const =0;
875 virtual edge getRandomEdge()
const =0;
885 virtual Iterator<edge>* getOutEdges(
const node n)
const =0;
895 virtual Iterator<edge>* getInOutEdges(
const node n)
const =0;
905 virtual Iterator<edge>* getInEdges(
const node n)
const =0;
913 virtual Iterator<edge>* getEdgeMetaInfo(
const edge metaEdge)
const =0;
931 virtual unsigned int numberOfNodes()
const =0;
938 virtual unsigned int numberOfEdges()
const =0;
944 virtual unsigned int deg(
const node n)
const =0;
951 virtual unsigned int indeg(
const node n)
const =0;
958 virtual unsigned int outdeg(
const node n)
const =0;
965 virtual node source(
const edge e)
const =0;
972 virtual node target(
const edge e)
const =0;
979 virtual const std::pair<node, node>& ends(
const edge e)
const=0;
987 virtual node opposite(
const edge e,
const node n)
const =0;
994 virtual bool isElement(
const node n)
const =0;
1001 virtual bool isMetaNode(
const node n)
const =0;
1008 virtual bool isElement(
const edge e)
const =0;
1015 virtual bool isMetaEdge(
const edge e)
const =0;
1025 bool directed =
true)
const {
1026 return existEdge(source, target, directed).isValid();
1037 virtual std::vector<edge> getEdges(
const node source,
const node target,
1038 bool directed =
true)
const=0;
1050 virtual edge existEdge(
const node source,
const node target,
1051 bool directed =
true)
const=0;
1061 virtual void setName(
const std::string &name) = 0;
1067 virtual std::string getName()
const = 0;
1076 return (const_cast<Graph *>(
this))->getNonConstAttributes();
1085 template<
typename ATTRIBUTETYPE>
1086 bool getAttribute(
const std::string &name, ATTRIBUTETYPE& value)
const;
1093 DataType* getAttribute(
const std::string& name)
const;
1100 template<
typename ATTRIBUTETYPE>
1101 void setAttribute(
const std::string &name,
const ATTRIBUTETYPE &value);
1108 void setAttribute(
const std::string &name,
const DataType* value);
1115 notifyRemoveAttribute(name);
1116 getNonConstAttributes().remove(name);
1125 return getAttributes().exist(name);
1135 virtual void addLocalProperty(
const std::string &name,
PropertyInterface *prop)=0;
1161 template<
typename PropertyType>
1162 PropertyType* getLocalProperty(
const std::string &name);
1176 template<
typename PropertyType>
1177 PropertyType* getProperty(
const std::string &name);
1192 PropertyInterface *getLocalProperty(
const std::string& propertyName,
const std::string& propertyType);
1207 PropertyInterface *getProperty(
const std::string& propertyName,
const std::string& propertyType);
1214 virtual bool existProperty(
const std::string& name)
const = 0;
1221 virtual bool existLocalProperty(
const std::string& name)
const = 0;
1229 virtual void delLocalProperty(
const std::string& name)=0;
1235 virtual Iterator<std::string>* getLocalProperties()
const=0;
1241 virtual Iterator<PropertyInterface*>* getLocalObjectProperties()
const=0;
1248 virtual Iterator<std::string>* getInheritedProperties()
const=0;
1255 virtual Iterator<PropertyInterface*>* getInheritedObjectProperties()
const=0;
1262 virtual Iterator<std::string>* getProperties()
const=0;
1269 virtual Iterator<PropertyInterface*>* getObjectProperties()
const=0;
1283 bool applyPropertyAlgorithm(
const std::string &algorithm,
1285 std::string &errorMessage,
1349 virtual void push(
bool unpopAllowed =
true,
1350 std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL)=0;
1357 virtual void pop(
bool unpopAllowed =
true)=0;
1393 virtual void unpop()=0;
1399 virtual bool canPop()=0;
1405 virtual bool canUnpop()=0;
1411 virtual bool canPopThenUnpop()=0;
1425 node createMetaNode(
const std::set<node> &nodeSet,
bool multiEdges =
true,
bool delAllEdge =
true);
1436 void createMetaNodes(Iterator<Graph *> *itS,
Graph *quotientGraph,
1437 std::vector<node>& metaNodes);
1448 node createMetaNode(
Graph* subGraph,
bool multiEdges =
true,
bool delAllEdge =
true);
1459 void openMetaNode(
node n,
bool updateProperties=
true);
1462 virtual DataSet &getNonConstAttributes() = 0;
1466 virtual void restoreNodes(
const std::vector<node>& nodes)=0;
1468 virtual void restoreEdges(
const std::vector<edge>& edges,
1469 const std::vector<std::pair<node, node> >& ends)=0;
1472 virtual void removeNode(
const node)=0;
1473 virtual void removeEdge(
const edge)=0;
1478 return getRoot()->canDeleteProperty(g, prop);
1483 virtual bool renameLocalProperty(PropertyInterface* prop,
1484 const std::string& newName)=0;
1487 virtual void removeSubGraph(Graph*)=0;
1488 virtual void clearSubGraphs()=0;
1489 virtual void restoreSubGraph(Graph*)=0;
1490 virtual void setSubGraphToKeep(Graph*)=0;
1493 void notifyAddNode(
const node n);
1494 void notifyAddNode(Graph*,
const node n) {
1497 void notifyAddEdge(
const edge e);
1498 void notifyAddEdge(Graph*,
const edge e) {
1501 void notifyBeforeSetEnds(
const edge e);
1502 void notifyBeforeSetEnds(Graph*,
const edge e) {
1503 notifyBeforeSetEnds(e);
1505 void notifyAfterSetEnds(
const edge e);
1506 void notifyAfterSetEnds(Graph*,
const edge e) {
1507 notifyAfterSetEnds(e);
1509 void notifyDelNode(
const node n);
1510 void notifyDelNode(Graph*,
const node n) {
1513 void notifyDelEdge(
const edge e);
1514 void notifyDelEdge(Graph*,
const edge e) {
1517 void notifyReverseEdge(
const edge e);
1518 void notifyReverseEdge(Graph*,
const edge e) {
1519 notifyReverseEdge(e);
1521 void notifyBeforeAddSubGraph(
const Graph*);
1522 void notifyAfterAddSubGraph(
const Graph*);
1523 void notifyBeforeAddSubGraph(Graph*,
const Graph* sg) {
1524 notifyBeforeAddSubGraph(sg);
1526 void notifyAfterAddSubGraph(Graph*,
const Graph* sg) {
1527 notifyAfterAddSubGraph(sg);
1529 void notifyBeforeDelSubGraph(
const Graph*);
1530 void notifyAfterDelSubGraph(
const Graph*);
1531 void notifyBeforeDelSubGraph(Graph*,
const Graph* sg) {
1532 notifyBeforeDelSubGraph(sg);
1534 void notifyAfterDelSubGraph(Graph*,
const Graph* sg) {
1535 notifyAfterDelSubGraph(sg);
1538 void notifyBeforeAddDescendantGraph(
const Graph*);
1539 void notifyAfterAddDescendantGraph(
const Graph*);
1540 void notifyBeforeDelDescendantGraph(
const Graph*);
1541 void notifyAfterDelDescendantGraph(
const Graph*);
1543 void notifyBeforeAddLocalProperty(
const std::string&);
1544 void notifyAddLocalProperty(
const std::string&);
1545 void notifyAddLocalProperty(Graph*,
const std::string& name) {
1546 notifyAddLocalProperty(name);
1548 void notifyBeforeDelLocalProperty(
const std::string&);
1549 void notifyAfterDelLocalProperty(
const std::string&);
1550 void notifyDelLocalProperty(Graph*,
const std::string& name) {
1551 notifyBeforeDelLocalProperty(name);
1553 void notifyBeforeSetAttribute(
const std::string&);
1554 void notifyBeforeSetAttribute(Graph*,
const std::string& name) {
1555 notifyBeforeSetAttribute(name);
1557 void notifyAfterSetAttribute(
const std::string&);
1558 void notifyAfterSetAttribute(Graph*,
const std::string& name) {
1559 notifyAfterSetAttribute(name);
1561 void notifyRemoveAttribute(
const std::string&);
1562 void notifyRemoveAttribute(Graph*,
const std::string& name) {
1563 notifyRemoveAttribute(name);
1565 void notifyDestroy();
1566 void notifyDestroy(Graph*) {
1571 TLP_HASH_MAP<std::string, tlp::PropertyInterface*> circularCalls;
1582 enum GraphEventType {
1587 TLP_REVERSE_EDGE = 4,
1588 TLP_BEFORE_SET_ENDS = 5,
1589 TLP_AFTER_SET_ENDS = 6,
1592 TLP_BEFORE_ADD_DESCENDANTGRAPH = 9,
1593 TLP_AFTER_ADD_DESCENDANTGRAPH = 10,
1594 TLP_BEFORE_DEL_DESCENDANTGRAPH = 11,
1595 TLP_AFTER_DEL_DESCENDANTGRAPH = 12,
1596 TLP_BEFORE_ADD_SUBGRAPH = 13,
1597 TLP_AFTER_ADD_SUBGRAPH = 14,
1598 TLP_BEFORE_DEL_SUBGRAPH = 15,
1599 TLP_AFTER_DEL_SUBGRAPH = 16,
1600 TLP_ADD_LOCAL_PROPERTY = 17,
1601 TLP_BEFORE_DEL_LOCAL_PROPERTY = 18,
1602 TLP_AFTER_DEL_LOCAL_PROPERTY = 19,
1603 TLP_ADD_INHERITED_PROPERTY = 20,
1604 TLP_BEFORE_DEL_INHERITED_PROPERTY = 21,
1605 TLP_AFTER_DEL_INHERITED_PROPERTY = 22,
1606 TLP_BEFORE_RENAME_LOCAL_PROPERTY = 23,
1607 TLP_AFTER_RENAME_LOCAL_PROPERTY = 24,
1608 TLP_BEFORE_SET_ATTRIBUTE = 25,
1609 TLP_AFTER_SET_ATTRIBUTE = 26,
1610 TLP_REMOVE_ATTRIBUTE = 27,
1611 TLP_BEFORE_ADD_LOCAL_PROPERTY = 28,
1612 TLP_BEFORE_ADD_INHERITED_PROPERTY = 29
1616 GraphEvent(
const Graph& g, GraphEventType graphEvtType,
unsigned int id,
1617 Event::EventType evtType = Event::TLP_MODIFICATION)
1618 :
Event(g, evtType), evtType(graphEvtType) {
1623 const std::vector<node>& nodes,
1624 Event::EventType evtType = Event::TLP_MODIFICATION)
1625 :
Event(g, evtType), evtType(graphEvtType) {
1626 info.nodes = &nodes;
1630 const std::vector<edge>& edges,
1631 Event::EventType evtType = Event::TLP_MODIFICATION)
1632 :
Event(g, evtType), evtType(graphEvtType) {
1633 info.edges = &edges;
1638 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1644 const std::string& str,
1645 Event::EventType evtType = Event::TLP_MODIFICATION)
1646 :
Event(g, evtType), evtType(graphEvtType) {
1647 info.name =
new std::string(str);
1653 const std::string& newName)
1654 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1656 new std::pair<PropertyInterface*,std::string>(prop, newName);
1661 if (evtType > TLP_AFTER_DEL_SUBGRAPH) {
1662 if (evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
1663 evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY)
1664 delete info.renamedProp;
1670 Graph* getGraph()
const {
1671 return static_cast<Graph *
>(sender());
1674 node getNode()
const {
1675 assert(evtType < TLP_ADD_EDGE);
1676 return node(info.eltId);
1679 edge getEdge()
const {
1680 assert(evtType > TLP_DEL_NODE && evtType < TLP_ADD_NODES);
1681 return edge(info.eltId);
1684 const std::vector<node>& getNodes()
const {
1685 assert(evtType == TLP_ADD_NODES);
1686 return *(info.nodes);
1689 const std::vector<edge>& getEdges()
const {
1690 assert(evtType == TLP_ADD_EDGES);
1691 return *(info.edges);
1694 const Graph* getSubGraph()
const {
1695 assert(evtType > TLP_ADD_EDGES && evtType < TLP_ADD_LOCAL_PROPERTY);
1696 return info.subGraph;
1699 const std::string& getAttributeName()
const {
1700 assert(evtType > TLP_AFTER_DEL_INHERITED_PROPERTY);
1701 return *(info.name);
1704 const std::string& getPropertyName()
const;
1707 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
1708 evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1709 return info.renamedProp->first;
1712 const std::string& getPropertyNewName()
const {
1713 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY);
1714 return info.renamedProp->second;
1717 const std::string& getPropertyOldName()
const {
1718 assert(evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1719 return info.renamedProp->second;
1722 GraphEventType getType()
const {
1727 GraphEventType evtType;
1730 const Graph* subGraph;
1732 const std::vector<node>* nodes;
1733 const std::vector<edge>* edges;
1734 std::pair<PropertyInterface*, std::string>* renamedProp;
1741 TLP_SCOPE std::ostream& operator<< (std::ostream &,
const tlp::Graph *);
1746 #ifndef DOXYGEN_NOTFOR_DEVEL
1748 TLP_BEGIN_HASH_NAMESPACE {
1750 struct TLP_SCOPE hash<const tlp::Graph *> {
1751 size_t operator()(
const tlp::Graph *s)
const {
return size_t(s->
getId());}
1754 struct TLP_SCOPE hash<tlp::Graph *> {
1757 } TLP_END_HASH_NAMESPACE
1759 #endif // DOXYGEN_NOTFOR_DEVEL
1760 #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)...