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 unsigned int id = 0)=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;
767 virtual Graph* getNodeMetaInfo(
const node metaNode)
const = 0;
776 virtual Iterator<edge>* getEdges()
const =0;
782 virtual edge getOneEdge()
const =0;
792 virtual Iterator<edge>* getOutEdges(
const node n)
const =0;
802 virtual Iterator<edge>* getInOutEdges(
const node n)
const =0;
812 virtual Iterator<edge>* getInEdges(
const node n)
const =0;
820 virtual Iterator<edge>* getEdgeMetaInfo(
const edge metaEdge)
const =0;
837 virtual unsigned int numberOfNodes()
const =0;
844 virtual unsigned int numberOfEdges()
const =0;
850 virtual unsigned int deg(
const node n)
const =0;
857 virtual unsigned int indeg(
const node n)
const =0;
864 virtual unsigned int outdeg(
const node n)
const =0;
871 virtual node source(
const edge e)
const =0;
878 virtual node target(
const edge e)
const =0;
885 virtual const std::pair<node, node>& ends(
const edge e)
const=0;
893 virtual node opposite(
const edge e,
const node n)
const =0;
900 virtual bool isElement(
const node n)
const =0;
907 virtual bool isMetaNode(
const node n)
const =0;
914 virtual bool isElement(
const edge e)
const =0;
921 virtual bool isMetaEdge(
const edge e)
const =0;
938 virtual edge existEdge(
const node source,
const node target,
939 bool directed =
true)
const =0;
948 virtual void setName(
const std::string &name) = 0;
954 virtual std::string getName()
const = 0;
963 return (const_cast<Graph *>(
this))->getNonConstAttributes();
972 template<
typename ATTRIBUTETYPE>
973 bool getAttribute(
const std::string &name, ATTRIBUTETYPE& value)
const;
980 DataType* getAttribute(
const std::string& name)
const;
987 template<
typename ATTRIBUTETYPE>
988 void setAttribute(
const std::string &name,
const ATTRIBUTETYPE &value);
995 void setAttribute(
const std::string &name,
const DataType* value);
1002 notifyRemoveAttribute(name);
1003 getNonConstAttributes().remove(name);
1012 return getAttributes().exist(name);
1022 virtual void addLocalProperty(
const std::string &name,
PropertyInterface *prop)=0;
1048 template<
typename PropertyType>
1049 PropertyType* getLocalProperty(
const std::string &name);
1063 template<
typename PropertyType>
1064 PropertyType* getProperty(
const std::string &name);
1079 PropertyInterface *getLocalProperty(
const std::string& propertyName,
const std::string& propertyType);
1094 PropertyInterface *getProperty(
const std::string& propertyName,
const std::string& propertyType);
1101 virtual bool existProperty(
const std::string& name)
const = 0;
1108 virtual bool existLocalProperty(
const std::string& name)
const = 0;
1116 virtual void delLocalProperty(
const std::string& name)=0;
1122 virtual Iterator<std::string>* getLocalProperties()
const=0;
1128 virtual Iterator<PropertyInterface*>* getLocalObjectProperties()
const=0;
1135 virtual Iterator<std::string>* getInheritedProperties()
const=0;
1142 virtual Iterator<PropertyInterface*>* getInheritedObjectProperties()
const=0;
1149 virtual Iterator<std::string>* getProperties()
const=0;
1156 virtual Iterator<PropertyInterface*>* getObjectProperties()
const=0;
1170 bool applyPropertyAlgorithm(
const std::string &algorithm,
1172 std::string &errorMessage,
1182 template<
typename PropertyType>
1183 _DEPRECATED
bool computeProperty(
const std::string &algorithm,
1184 PropertyType* result, std::string &msg,
1188 void _DEPRECATED addGraphObserver(
Observable *)
const;
1189 void _DEPRECATED removeGraphObserver(
Observable *)
const;
1251 virtual void push(
bool unpopAllowed =
true,
1252 std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL)=0;
1259 virtual void pop(
bool unpopAllowed =
true)=0;
1295 virtual void unpop()=0;
1301 virtual bool canPop()=0;
1307 virtual bool canUnpop()=0;
1313 virtual bool canPopThenUnpop()=0;
1327 node createMetaNode(
const std::set<node> &nodeSet,
bool multiEdges =
true,
bool delAllEdge =
true);
1338 void createMetaNodes(Iterator<Graph *> *itS,
Graph *quotientGraph,
1339 std::vector<node>& metaNodes);
1350 node createMetaNode(
Graph* subGraph,
bool multiEdges =
true,
bool delAllEdge =
true);
1361 void openMetaNode(
node n,
bool updateProperties=
true);
1364 virtual DataSet &getNonConstAttributes() = 0;
1368 virtual void restoreNodes(
const std::vector<node>& nodes)=0;
1370 virtual void restoreEdges(
const std::vector<edge>& edges,
1371 const std::vector<std::pair<node, node> >& ends)=0;
1374 virtual void removeNode(
const node)=0;
1375 virtual void removeEdge(
const edge)=0;
1380 return getRoot()->canDeleteProperty(g, prop);
1384 virtual void removeSubGraph(Graph*)=0;
1385 virtual void clearSubGraphs()=0;
1386 virtual void restoreSubGraph(Graph*)=0;
1387 virtual void setSubGraphToKeep(Graph*)=0;
1390 void notifyAddNode(
const node n);
1391 void notifyAddNode(Graph*,
const node n) {
1394 void notifyAddEdge(
const edge e);
1395 void notifyAddEdge(Graph*,
const edge e) {
1398 void notifyBeforeSetEnds(
const edge e);
1399 void notifyBeforeSetEnds(Graph*,
const edge e) {
1400 notifyBeforeSetEnds(e);
1402 void notifyAfterSetEnds(
const edge e);
1403 void notifyAfterSetEnds(Graph*,
const edge e) {
1404 notifyAfterSetEnds(e);
1406 void notifyDelNode(
const node n);
1407 void notifyDelNode(Graph*,
const node n) {
1410 void notifyDelEdge(
const edge e);
1411 void notifyDelEdge(Graph*,
const edge e) {
1414 void notifyReverseEdge(
const edge e);
1415 void notifyReverseEdge(Graph*,
const edge e) {
1416 notifyReverseEdge(e);
1418 void notifyBeforeAddSubGraph(
const Graph*);
1419 void notifyAfterAddSubGraph(
const Graph*);
1420 void notifyBeforeAddSubGraph(Graph*,
const Graph* sg) {
1421 notifyBeforeAddSubGraph(sg);
1423 void notifyAfterAddSubGraph(Graph*,
const Graph* sg) {
1424 notifyAfterAddSubGraph(sg);
1426 void notifyBeforeDelSubGraph(
const Graph*);
1427 void notifyAfterDelSubGraph(
const Graph*);
1428 void notifyBeforeDelSubGraph(Graph*,
const Graph* sg) {
1429 notifyBeforeDelSubGraph(sg);
1431 void notifyAfterDelSubGraph(Graph*,
const Graph* sg) {
1432 notifyAfterDelSubGraph(sg);
1435 void notifyBeforeAddDescendantGraph(
const Graph*);
1436 void notifyAfterAddDescendantGraph(
const Graph*);
1437 void notifyBeforeDelDescendantGraph(
const Graph*);
1438 void notifyAfterDelDescendantGraph(
const Graph*);
1440 void notifyBeforeAddLocalProperty(
const std::string&);
1441 void notifyAddLocalProperty(
const std::string&);
1442 void notifyAddLocalProperty(Graph*,
const std::string& name) {
1443 notifyAddLocalProperty(name);
1445 void notifyBeforeDelLocalProperty(
const std::string&);
1446 void notifyAfterDelLocalProperty(
const std::string&);
1447 void notifyDelLocalProperty(Graph*,
const std::string& name) {
1448 notifyBeforeDelLocalProperty(name);
1450 void notifyBeforeSetAttribute(
const std::string&);
1451 void notifyBeforeSetAttribute(Graph*,
const std::string& name) {
1452 notifyBeforeSetAttribute(name);
1454 void notifyAfterSetAttribute(
const std::string&);
1455 void notifyAfterSetAttribute(Graph*,
const std::string& name) {
1456 notifyAfterSetAttribute(name);
1458 void notifyRemoveAttribute(
const std::string&);
1459 void notifyRemoveAttribute(Graph*,
const std::string& name) {
1460 notifyRemoveAttribute(name);
1462 void notifyDestroy();
1463 void notifyDestroy(Graph*) {
1470 TLP_HASH_MAP<std::string, tlp::PropertyInterface*> circularCalls;
1481 enum GraphEventType {
1486 TLP_REVERSE_EDGE = 4,
1487 TLP_BEFORE_SET_ENDS = 5,
1488 TLP_AFTER_SET_ENDS = 6,
1491 TLP_BEFORE_ADD_DESCENDANTGRAPH = 9,
1492 TLP_AFTER_ADD_DESCENDANTGRAPH = 10,
1493 TLP_BEFORE_DEL_DESCENDANTGRAPH = 11,
1494 TLP_AFTER_DEL_DESCENDANTGRAPH = 12,
1495 TLP_BEFORE_ADD_SUBGRAPH = 13,
1496 TLP_AFTER_ADD_SUBGRAPH = 14,
1497 TLP_BEFORE_DEL_SUBGRAPH = 15,
1498 TLP_AFTER_DEL_SUBGRAPH = 16,
1499 TLP_ADD_LOCAL_PROPERTY = 17,
1500 TLP_BEFORE_DEL_LOCAL_PROPERTY = 18,
1501 TLP_AFTER_DEL_LOCAL_PROPERTY = 19,
1502 TLP_ADD_INHERITED_PROPERTY = 20,
1503 TLP_BEFORE_DEL_INHERITED_PROPERTY = 21,
1504 TLP_AFTER_DEL_INHERITED_PROPERTY = 22,
1505 TLP_BEFORE_SET_ATTRIBUTE = 23,
1506 TLP_AFTER_SET_ATTRIBUTE = 24,
1507 TLP_REMOVE_ATTRIBUTE = 25,
1508 TLP_BEFORE_ADD_LOCAL_PROPERTY = 26,
1509 TLP_BEFORE_ADD_INHERITED_PROPERTY = 27
1513 GraphEvent(
const Graph& g, GraphEventType graphEvtType,
unsigned int id,
1514 Event::EventType evtType = Event::TLP_MODIFICATION)
1515 :
Event(g, evtType), evtType(graphEvtType) {
1520 const std::vector<node>& nodes,
1521 Event::EventType evtType = Event::TLP_MODIFICATION)
1522 :
Event(g, evtType), evtType(graphEvtType) {
1523 info.nodes = &nodes;
1527 const std::vector<edge>& edges,
1528 Event::EventType evtType = Event::TLP_MODIFICATION)
1529 :
Event(g, evtType), evtType(graphEvtType) {
1530 info.edges = &edges;
1535 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1541 const std::string& str,
1542 Event::EventType evtType = Event::TLP_MODIFICATION)
1543 :
Event(g, evtType), evtType(graphEvtType) {
1544 info.name =
new std::string(str);
1549 if (evtType > TLP_AFTER_DEL_SUBGRAPH)
1553 Graph* getGraph()
const {
1554 return dynamic_cast<Graph *
>(sender());
1557 node getNode()
const {
1558 assert(evtType < TLP_ADD_EDGE);
1559 return node(info.eltId);
1562 edge getEdge()
const {
1563 assert(evtType > TLP_DEL_NODE && evtType < TLP_ADD_NODES);
1564 return edge(info.eltId);
1567 const std::vector<node>& getNodes()
const {
1568 assert(evtType == TLP_ADD_NODES);
1569 return *(info.nodes);
1572 const std::vector<edge>& getEdges()
const {
1573 assert(evtType == TLP_ADD_EDGES);
1574 return *(info.edges);
1577 const Graph* getSubGraph()
const {
1578 assert(evtType > TLP_ADD_EDGES && evtType < TLP_ADD_LOCAL_PROPERTY);
1579 return info.subGraph;
1582 const std::string& getAttributeName()
const {
1583 assert(evtType > TLP_AFTER_DEL_INHERITED_PROPERTY);
1584 return *(info.name);
1587 const std::string& getPropertyName()
const {
1588 assert(evtType > TLP_AFTER_DEL_SUBGRAPH && evtType < TLP_BEFORE_SET_ATTRIBUTE);
1589 return *(info.name);
1592 GraphEventType getType()
const {
1597 GraphEventType evtType;
1600 const Graph* subGraph;
1602 const std::vector<node>* nodes;
1603 const std::vector<edge>* edges;
1610 TLP_SCOPE std::ostream& operator<< (std::ostream &,
const tlp::Graph *);
1615 #ifndef DOXYGEN_NOTFOR_DEVEL
1617 TLP_BEGIN_HASH_NAMESPACE {
1619 struct TLP_SCOPE hash<const tlp::Graph *> {
1620 size_t operator()(
const tlp::Graph *s)
const {
return size_t(s->
getId());}
1623 struct TLP_SCOPE hash<tlp::Graph *> {
1626 } TLP_END_HASH_NAMESPACE
1628 #endif // DOXYGEN_NOTFOR_DEVEL
1630 #include <tulip/PropertyInterface.h>
1631 #include "cxx/Graph.cxx"