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;
92 TLP_SCOPE
bool exportGraph(Graph *graph, std::ostream &outputStream,
const std::string &format, DataSet &dataSet, PluginProgress *progress=NULL);
107 TLP_SCOPE Graph*
importGraph(
const std::string &format, DataSet &dataSet, PluginProgress *progress=NULL,Graph *
newGraph=NULL);
131 TLP_SCOPE _DEPRECATED Graph*
newSubGraph(Graph *graph, std::string name =
"unnamed");
143 TLP_SCOPE _DEPRECATED Graph*
newCloneSubGraph(Graph *graph, std::string name =
"unnamed");
152 TLP_SCOPE
void copyToGraph(Graph *outG,
const Graph *inG, BooleanProperty* inSelection=NULL, BooleanProperty* outSelection=NULL );
160 TLP_SCOPE
void removeFromGraph(Graph * ioG, BooleanProperty* inSelection=NULL);
209 friend class GraphAbstract;
210 friend class GraphUpdatesRecorder;
211 friend class GraphDecorator;
212 friend class PropertyManager;
239 bool applyAlgorithm(
const std::string &algorithm, std::string &errorMessage,
DataSet *dataSet=NULL,
PluginProgress *progress=NULL);
252 virtual void clear()=0;
268 std::string name =
"unnamed")=0;
276 Graph *addSubGraph(std::string name);
284 virtual Graph* addCloneSubGraph(std::string name =
"unnamed");
294 Graph *inducedSubGraph(
const std::set<node>& nodeSet,
295 Graph* parentSubGraph = NULL);
317 virtual void delSubGraph(
Graph *graph)=0;
337 virtual void delAllSubGraphs(
Graph *graph)=0;
344 virtual Graph* getSuperGraph()
const =0;
350 virtual Graph* getRoot()
const =0;
358 virtual void setSuperGraph(
Graph *)=0;
373 virtual Iterator<Graph *> * getSubGraphs()
const=0;
394 virtual Graph *getNthSubGraph(
unsigned int n)
const;
410 virtual unsigned int numberOfSubGraphs()
const=0;
426 virtual unsigned int numberOfDescendantGraphs()
const=0;
434 virtual bool isSubGraph(
const Graph* subGraph)
const=0;
442 virtual bool isDescendantGraph(
const Graph* subGraph)
const=0;
451 virtual Graph* getSubGraph(
unsigned int id)
const=0;
460 virtual Graph* getSubGraph(
const std::string &name)
const=0;
469 virtual Graph* getDescendantGraph(
unsigned int id)
const=0;
478 virtual Graph* getDescendantGraph(
const std::string &name)
const=0;
488 virtual node addNode()=0;
498 virtual void addNodes(
unsigned int nbNodes, std::vector<node>& addedNodes)=0;
509 virtual void addNode(
const node n)=0;
521 virtual void addNodes(Iterator<node>* nodes)=0;
530 virtual void delNode(
const node n,
bool deleteInAllGraphs =
false)=0;
540 virtual void delNodes(Iterator<node>* it,
bool deleteInAllGraphs =
false)=0;
550 virtual edge addEdge(
const node source,
const node target)=0;
563 virtual void addEdges(
const std::vector<std::pair<node, node> >& edges,
564 std::vector<edge>& addedEdges)=0;
576 virtual void addEdge(
const edge e)=0;
587 virtual void addEdges(Iterator<edge>* edges)=0;
596 virtual void delEdge(
const edge e,
bool deleteInAllGraphs =
false)=0;
605 virtual void delEdges(Iterator<edge>* itE,
bool deleteInAllGraphs =
false)=0;
616 virtual void setEdgeOrder(
const node n,
const std::vector<edge> &edges)=0;
624 virtual void swapEdgeOrder(
const node n,
const edge e1,
const edge e2)=0;
631 virtual void setSource(
const edge e,
const node source) = 0;
638 virtual void setTarget(
const edge e,
const node target) = 0;
646 virtual void setEnds(
const edge e,
const node source,
const node target) = 0;
655 virtual void reverse(
const edge e)=0;
658 virtual void reserveNodes(
unsigned int nbNodes) = 0;
661 virtual void reserveEdges(
unsigned int nbEdges) = 0;
676 virtual node getOneNode()
const =0;
686 virtual Iterator<node>* getNodes()
const =0;
709 virtual node getInNode(
const node n,
unsigned int i)
const =0;
719 virtual Iterator<node>* getInNodes(
const node n)
const =0;
742 virtual node getOutNode(
const node n,
unsigned int i)
const =0;
752 virtual Iterator<node>* getOutNodes(
const node n)
const =0;
759 virtual Iterator<node>* getInOutNodes(
const node n)
const =0;
768 virtual Iterator<node>* bfs(
const node root =
node())
const = 0;
777 virtual Iterator<node>* dfs(
const node root =
node())
const = 0;
785 virtual Graph* getNodeMetaInfo(
const node metaNode)
const = 0;
794 virtual Iterator<edge>* getEdges()
const =0;
800 virtual edge getOneEdge()
const =0;
810 virtual Iterator<edge>* getOutEdges(
const node n)
const =0;
820 virtual Iterator<edge>* getInOutEdges(
const node n)
const =0;
830 virtual Iterator<edge>* getInEdges(
const node n)
const =0;
838 virtual Iterator<edge>* getEdgeMetaInfo(
const edge metaEdge)
const =0;
856 virtual unsigned int numberOfNodes()
const =0;
863 virtual unsigned int numberOfEdges()
const =0;
869 virtual unsigned int deg(
const node n)
const =0;
876 virtual unsigned int indeg(
const node n)
const =0;
883 virtual unsigned int outdeg(
const node n)
const =0;
890 virtual node source(
const edge e)
const =0;
897 virtual node target(
const edge e)
const =0;
904 virtual const std::pair<node, node>& ends(
const edge e)
const=0;
912 virtual node opposite(
const edge e,
const node n)
const =0;
919 virtual bool isElement(
const node n)
const =0;
926 virtual bool isMetaNode(
const node n)
const =0;
933 virtual bool isElement(
const edge e)
const =0;
940 virtual bool isMetaEdge(
const edge e)
const =0;
949 virtual bool hasEdge(
const node source,
const node target,
950 bool directed =
true)
const {
951 return existEdge(source, target, directed).
isValid();
962 virtual std::vector<edge> getEdges(
const node source,
const node target,
963 bool directed =
true)
const=0;
975 virtual edge existEdge(
const node source,
const node target,
976 bool directed =
true)
const=0;
986 virtual void setName(
const std::string &name) = 0;
992 virtual std::string getName()
const = 0;
1001 return (const_cast<Graph *>(
this))->getNonConstAttributes();
1010 template<
typename ATTRIBUTETYPE>
1011 bool getAttribute(
const std::string &name, ATTRIBUTETYPE& value)
const;
1018 DataType* getAttribute(
const std::string& name)
const;
1025 template<
typename ATTRIBUTETYPE>
1026 void setAttribute(
const std::string &name,
const ATTRIBUTETYPE &value);
1033 void setAttribute(
const std::string &name,
const DataType* value);
1040 notifyRemoveAttribute(name);
1041 getNonConstAttributes().remove(name);
1050 return getAttributes().exist(name);
1060 virtual void addLocalProperty(
const std::string &name,
PropertyInterface *prop)=0;
1086 template<
typename PropertyType>
1087 PropertyType* getLocalProperty(
const std::string &name);
1101 template<
typename PropertyType>
1102 PropertyType* getProperty(
const std::string &name);
1117 PropertyInterface *getLocalProperty(
const std::string& propertyName,
const std::string& propertyType);
1132 PropertyInterface *getProperty(
const std::string& propertyName,
const std::string& propertyType);
1139 virtual bool existProperty(
const std::string& name)
const = 0;
1146 virtual bool existLocalProperty(
const std::string& name)
const = 0;
1154 virtual void delLocalProperty(
const std::string& name)=0;
1160 virtual Iterator<std::string>* getLocalProperties()
const=0;
1166 virtual Iterator<PropertyInterface*>* getLocalObjectProperties()
const=0;
1173 virtual Iterator<std::string>* getInheritedProperties()
const=0;
1180 virtual Iterator<PropertyInterface*>* getInheritedObjectProperties()
const=0;
1187 virtual Iterator<std::string>* getProperties()
const=0;
1194 virtual Iterator<PropertyInterface*>* getObjectProperties()
const=0;
1208 bool applyPropertyAlgorithm(
const std::string &algorithm,
1210 std::string &errorMessage,
1220 template<
typename PropertyType>
1221 _DEPRECATED
bool computeProperty(
const std::string &algorithm,
1222 PropertyType* result, std::string &msg,
1226 void _DEPRECATED addGraphObserver(
Observable *)
const;
1227 void _DEPRECATED removeGraphObserver(
Observable *)
const;
1289 virtual void push(
bool unpopAllowed =
true,
1290 std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL)=0;
1297 virtual void pop(
bool unpopAllowed =
true)=0;
1333 virtual void unpop()=0;
1339 virtual bool canPop()=0;
1345 virtual bool canUnpop()=0;
1351 virtual bool canPopThenUnpop()=0;
1365 node createMetaNode(
const std::set<node> &nodeSet,
bool multiEdges =
true,
bool delAllEdge =
true);
1376 void createMetaNodes(Iterator<Graph *> *itS,
Graph *quotientGraph,
1377 std::vector<node>& metaNodes);
1388 node createMetaNode(
Graph* subGraph,
bool multiEdges =
true,
bool delAllEdge =
true);
1399 void openMetaNode(
node n,
bool updateProperties=
true);
1402 virtual DataSet &getNonConstAttributes() = 0;
1406 virtual void restoreNodes(
const std::vector<node>& nodes)=0;
1408 virtual void restoreEdges(
const std::vector<edge>& edges,
1409 const std::vector<std::pair<node, node> >& ends)=0;
1412 virtual void removeNode(
const node)=0;
1413 virtual void removeEdge(
const edge)=0;
1418 return getRoot()->canDeleteProperty(g, prop);
1422 virtual void removeSubGraph(Graph*)=0;
1423 virtual void clearSubGraphs()=0;
1424 virtual void restoreSubGraph(Graph*)=0;
1425 virtual void setSubGraphToKeep(Graph*)=0;
1428 void notifyAddNode(
const node n);
1429 void notifyAddNode(Graph*,
const node n) {
1432 void notifyAddEdge(
const edge e);
1433 void notifyAddEdge(Graph*,
const edge e) {
1436 void notifyBeforeSetEnds(
const edge e);
1437 void notifyBeforeSetEnds(Graph*,
const edge e) {
1438 notifyBeforeSetEnds(e);
1440 void notifyAfterSetEnds(
const edge e);
1441 void notifyAfterSetEnds(Graph*,
const edge e) {
1442 notifyAfterSetEnds(e);
1444 void notifyDelNode(
const node n);
1445 void notifyDelNode(Graph*,
const node n) {
1448 void notifyDelEdge(
const edge e);
1449 void notifyDelEdge(Graph*,
const edge e) {
1452 void notifyReverseEdge(
const edge e);
1453 void notifyReverseEdge(Graph*,
const edge e) {
1454 notifyReverseEdge(e);
1456 void notifyBeforeAddSubGraph(
const Graph*);
1457 void notifyAfterAddSubGraph(
const Graph*);
1458 void notifyBeforeAddSubGraph(Graph*,
const Graph* sg) {
1459 notifyBeforeAddSubGraph(sg);
1461 void notifyAfterAddSubGraph(Graph*,
const Graph* sg) {
1462 notifyAfterAddSubGraph(sg);
1464 void notifyBeforeDelSubGraph(
const Graph*);
1465 void notifyAfterDelSubGraph(
const Graph*);
1466 void notifyBeforeDelSubGraph(Graph*,
const Graph* sg) {
1467 notifyBeforeDelSubGraph(sg);
1469 void notifyAfterDelSubGraph(Graph*,
const Graph* sg) {
1470 notifyAfterDelSubGraph(sg);
1473 void notifyBeforeAddDescendantGraph(
const Graph*);
1474 void notifyAfterAddDescendantGraph(
const Graph*);
1475 void notifyBeforeDelDescendantGraph(
const Graph*);
1476 void notifyAfterDelDescendantGraph(
const Graph*);
1478 void notifyBeforeAddLocalProperty(
const std::string&);
1479 void notifyAddLocalProperty(
const std::string&);
1480 void notifyAddLocalProperty(Graph*,
const std::string& name) {
1481 notifyAddLocalProperty(name);
1483 void notifyBeforeDelLocalProperty(
const std::string&);
1484 void notifyAfterDelLocalProperty(
const std::string&);
1485 void notifyDelLocalProperty(Graph*,
const std::string& name) {
1486 notifyBeforeDelLocalProperty(name);
1488 void notifyBeforeSetAttribute(
const std::string&);
1489 void notifyBeforeSetAttribute(Graph*,
const std::string& name) {
1490 notifyBeforeSetAttribute(name);
1492 void notifyAfterSetAttribute(
const std::string&);
1493 void notifyAfterSetAttribute(Graph*,
const std::string& name) {
1494 notifyAfterSetAttribute(name);
1496 void notifyRemoveAttribute(
const std::string&);
1497 void notifyRemoveAttribute(Graph*,
const std::string& name) {
1498 notifyRemoveAttribute(name);
1500 void notifyDestroy();
1501 void notifyDestroy(Graph*) {
1506 TLP_HASH_MAP<std::string, tlp::PropertyInterface*> circularCalls;
1517 enum GraphEventType {
1522 TLP_REVERSE_EDGE = 4,
1523 TLP_BEFORE_SET_ENDS = 5,
1524 TLP_AFTER_SET_ENDS = 6,
1527 TLP_BEFORE_ADD_DESCENDANTGRAPH = 9,
1528 TLP_AFTER_ADD_DESCENDANTGRAPH = 10,
1529 TLP_BEFORE_DEL_DESCENDANTGRAPH = 11,
1530 TLP_AFTER_DEL_DESCENDANTGRAPH = 12,
1531 TLP_BEFORE_ADD_SUBGRAPH = 13,
1532 TLP_AFTER_ADD_SUBGRAPH = 14,
1533 TLP_BEFORE_DEL_SUBGRAPH = 15,
1534 TLP_AFTER_DEL_SUBGRAPH = 16,
1535 TLP_ADD_LOCAL_PROPERTY = 17,
1536 TLP_BEFORE_DEL_LOCAL_PROPERTY = 18,
1537 TLP_AFTER_DEL_LOCAL_PROPERTY = 19,
1538 TLP_ADD_INHERITED_PROPERTY = 20,
1539 TLP_BEFORE_DEL_INHERITED_PROPERTY = 21,
1540 TLP_AFTER_DEL_INHERITED_PROPERTY = 22,
1541 TLP_BEFORE_SET_ATTRIBUTE = 23,
1542 TLP_AFTER_SET_ATTRIBUTE = 24,
1543 TLP_REMOVE_ATTRIBUTE = 25,
1544 TLP_BEFORE_ADD_LOCAL_PROPERTY = 26,
1545 TLP_BEFORE_ADD_INHERITED_PROPERTY = 27
1549 GraphEvent(
const Graph& g, GraphEventType graphEvtType,
unsigned int id,
1550 Event::EventType evtType = Event::TLP_MODIFICATION)
1551 :
Event(g, evtType), evtType(graphEvtType) {
1556 const std::vector<node>& nodes,
1557 Event::EventType evtType = Event::TLP_MODIFICATION)
1558 :
Event(g, evtType), evtType(graphEvtType) {
1559 info.nodes = &nodes;
1563 const std::vector<edge>& edges,
1564 Event::EventType evtType = Event::TLP_MODIFICATION)
1565 :
Event(g, evtType), evtType(graphEvtType) {
1566 info.edges = &edges;
1571 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1577 const std::string& str,
1578 Event::EventType evtType = Event::TLP_MODIFICATION)
1579 :
Event(g, evtType), evtType(graphEvtType) {
1580 info.name =
new std::string(str);
1585 if (evtType > TLP_AFTER_DEL_SUBGRAPH)
1589 Graph* getGraph()
const {
1590 return static_cast<Graph *
>(sender());
1593 node getNode()
const {
1594 assert(evtType < TLP_ADD_EDGE);
1595 return node(info.eltId);
1598 edge getEdge()
const {
1599 assert(evtType > TLP_DEL_NODE && evtType < TLP_ADD_NODES);
1600 return edge(info.eltId);
1603 const std::vector<node>& getNodes()
const {
1604 assert(evtType == TLP_ADD_NODES);
1605 return *(info.nodes);
1608 const std::vector<edge>& getEdges()
const {
1609 assert(evtType == TLP_ADD_EDGES);
1610 return *(info.edges);
1613 const Graph* getSubGraph()
const {
1614 assert(evtType > TLP_ADD_EDGES && evtType < TLP_ADD_LOCAL_PROPERTY);
1615 return info.subGraph;
1618 const std::string& getAttributeName()
const {
1619 assert(evtType > TLP_AFTER_DEL_INHERITED_PROPERTY);
1620 return *(info.name);
1623 const std::string& getPropertyName()
const {
1624 assert(evtType > TLP_AFTER_DEL_SUBGRAPH && evtType < TLP_BEFORE_SET_ATTRIBUTE);
1625 return *(info.name);
1628 GraphEventType getType()
const {
1633 GraphEventType evtType;
1636 const Graph* subGraph;
1638 const std::vector<node>* nodes;
1639 const std::vector<edge>* edges;
1646 TLP_SCOPE std::ostream& operator<< (std::ostream &,
const tlp::Graph *);
1651 #ifndef DOXYGEN_NOTFOR_DEVEL
1653 TLP_BEGIN_HASH_NAMESPACE {
1655 struct TLP_SCOPE hash<const tlp::Graph *> {
1656 size_t operator()(
const tlp::Graph *s)
const {
return size_t(s->
getId());}
1659 struct TLP_SCOPE hash<tlp::Graph *> {
1662 } TLP_END_HASH_NAMESPACE
1664 #endif // DOXYGEN_NOTFOR_DEVEL
1665 #include "cxx/Graph.cxx"