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;
 
  240   bool applyAlgorithm(
const std::string &algorithm, std::string &errorMessage, 
DataSet *dataSet=NULL, 
PluginProgress *progress=NULL);
 
  253   virtual  void clear()=0;
 
  269                              std::string name = 
"unnamed")=0;
 
  277   Graph *addSubGraph(std::string name);
 
  285   virtual Graph* addCloneSubGraph(std::string name = 
"unnamed");
 
  295   Graph *inducedSubGraph(
const std::set<node>& nodeSet,
 
  296                          Graph* parentSubGraph = NULL);
 
  318   virtual void delSubGraph(
Graph *graph)=0;
 
  338   virtual void delAllSubGraphs(
Graph *graph)=0;
 
  345   virtual Graph* getSuperGraph()
const =0;
 
  351   virtual Graph* getRoot() 
const =0;
 
  359   virtual void setSuperGraph(
Graph *)=0;
 
  374   virtual Iterator<Graph *> * getSubGraphs() 
const=0;
 
  395   virtual Graph *getNthSubGraph(
unsigned int n) 
const;
 
  411   virtual unsigned int numberOfSubGraphs() 
const=0;
 
  427   virtual unsigned int numberOfDescendantGraphs() 
const=0;
 
  435   virtual bool isSubGraph(
const Graph* subGraph) 
const=0;
 
  443   virtual bool isDescendantGraph(
const Graph* subGraph) 
const=0;
 
  452   virtual Graph* getSubGraph(
unsigned int id) 
const=0;
 
  461   virtual Graph* getSubGraph(
const std::string &name) 
const=0;
 
  470   virtual Graph* getDescendantGraph(
unsigned int id) 
const=0;
 
  479   virtual Graph* getDescendantGraph(
const std::string &name) 
const=0;
 
  489   virtual node addNode()=0;
 
  499   virtual void addNodes(
unsigned int nbNodes, std::vector<node>& addedNodes)=0;
 
  510   virtual void addNode(
const node n)=0;
 
  522   virtual void addNodes(Iterator<node>* nodes)=0;
 
  531   virtual void delNode(
const node n, 
bool deleteInAllGraphs = 
false)=0;
 
  541   virtual void delNodes(Iterator<node>* it, 
bool deleteInAllGraphs = 
false)=0;
 
  551   virtual edge addEdge(
const node source, 
const node target)=0;
 
  564   virtual void addEdges(
const std::vector<std::pair<node, node> >& edges,
 
  565                         std::vector<edge>& addedEdges)=0;
 
  577   virtual void addEdge(
const edge e)=0;
 
  588   virtual void addEdges(Iterator<edge>* edges)=0;
 
  597   virtual void delEdge(
const edge e, 
bool deleteInAllGraphs = 
false)=0;
 
  606   virtual void delEdges(Iterator<edge>* itE, 
bool deleteInAllGraphs = 
false)=0;
 
  617   virtual void setEdgeOrder(
const node n,
const std::vector<edge> &edges)=0;
 
  625   virtual void swapEdgeOrder(
const node n,
const edge e1, 
const edge e2)=0;
 
  632   virtual void setSource(
const edge e, 
const node source) = 0;
 
  639   virtual void setTarget(
const edge e, 
const node target) = 0;
 
  647   virtual void setEnds(
const edge e, 
const node source, 
const node target) = 0;
 
  656   virtual void reverse(
const edge e)=0;
 
  659   virtual void reserveNodes(
unsigned int nbNodes) = 0;
 
  662   virtual void reserveEdges(
unsigned int nbEdges) = 0;
 
  677   virtual node getOneNode() 
const =0;
 
  687   virtual Iterator<node>* getNodes() 
const =0;
 
  710   virtual node getInNode(
const node n,
unsigned int i)
const =0;
 
  720   virtual Iterator<node>* getInNodes(
const node n) 
const =0;
 
  743   virtual node getOutNode(
const node n,
unsigned int i) 
const =0;
 
  753   virtual Iterator<node>* getOutNodes(
const node n) 
const =0;
 
  760   virtual Iterator<node>* getInOutNodes(
const node n) 
const =0;
 
  769   virtual Iterator<node>* bfs(
const node root = 
node()) 
const = 0;
 
  778   virtual Iterator<node>* dfs(
const node root = 
node()) 
const = 0;
 
  786   virtual Graph* getNodeMetaInfo(
const node metaNode) 
const = 0;
 
  795   virtual Iterator<edge>* getEdges() 
const =0;
 
  801   virtual edge getOneEdge() 
const =0;
 
  811   virtual Iterator<edge>* getOutEdges(
const node n) 
const =0;
 
  821   virtual Iterator<edge>* getInOutEdges(
const node n) 
const =0;
 
  831   virtual Iterator<edge>* getInEdges(
const node n) 
const =0;
 
  839   virtual Iterator<edge>* getEdgeMetaInfo(
const edge metaEdge) 
const =0;
 
  857   virtual unsigned int numberOfNodes()
const =0;
 
  864   virtual unsigned int numberOfEdges()
const =0;
 
  870   virtual unsigned int deg(
const node n)
const =0;
 
  877   virtual unsigned int indeg(
const node n)
const =0;
 
  884   virtual unsigned int outdeg(
const node n)
const =0;
 
  891   virtual node source(
const edge e)
const =0;
 
  898   virtual node target(
const edge e)
const =0;
 
  905   virtual const std::pair<node, node>& ends(
const edge e)
const=0;
 
  913   virtual node opposite(
const edge e, 
const node n)
const =0;
 
  920   virtual bool isElement(
const node n) 
const =0;
 
  927   virtual bool isMetaNode(
const node n) 
const =0;
 
  934   virtual bool isElement(
const edge e) 
const =0;
 
  941   virtual bool isMetaEdge(
const edge e) 
const =0;
 
  950   virtual bool hasEdge(
const node source, 
const node target,
 
  951                        bool directed = 
true)
 const {
 
  952     return existEdge(source, target, directed).
isValid();
 
  963   virtual std::vector<edge> getEdges(
const node source, 
const node target,
 
  964                                      bool directed = 
true) 
const=0;
 
  976   virtual edge existEdge(
const node source, 
const node target,
 
  977                          bool directed = 
true) 
const=0;
 
  987   virtual void setName(
const std::string &name) = 0;
 
  993   virtual std::string getName() 
const = 0;
 
 1002     return (const_cast<Graph *>(
this))->getNonConstAttributes();
 
 1011   template<
typename ATTRIBUTETYPE>
 
 1012   bool getAttribute(
const std::string &name, ATTRIBUTETYPE& value) 
const;
 
 1019   DataType* getAttribute(
const std::string& name) 
const;
 
 1026   template<
typename ATTRIBUTETYPE>
 
 1027   void setAttribute(
const std::string &name,
const ATTRIBUTETYPE &value);
 
 1034   void setAttribute(
const std::string &name, 
const DataType* value);
 
 1041     notifyRemoveAttribute(name);
 
 1042     getNonConstAttributes().remove(name);
 
 1051     return getAttributes().exist(name);
 
 1061   virtual  void addLocalProperty(
const std::string &name, 
PropertyInterface *prop)=0;
 
 1087   template<
typename PropertyType>
 
 1088   PropertyType* getLocalProperty(
const std::string &name);
 
 1102   template<
typename PropertyType>
 
 1103   PropertyType* getProperty(
const std::string &name);
 
 1118   PropertyInterface *getLocalProperty(
const std::string& propertyName, 
const std::string& propertyType);
 
 1133   PropertyInterface *getProperty(
const std::string& propertyName, 
const std::string& propertyType);
 
 1140   virtual  bool existProperty(
const std::string& name) 
const = 0;
 
 1147   virtual  bool existLocalProperty(
const std::string& name) 
const = 0;
 
 1155   virtual  void delLocalProperty(
const std::string& name)=0;
 
 1161   virtual Iterator<std::string>* getLocalProperties() 
const=0;
 
 1167   virtual Iterator<PropertyInterface*>* getLocalObjectProperties() 
const=0;
 
 1174   virtual Iterator<std::string>* getInheritedProperties() 
const=0;
 
 1181   virtual Iterator<PropertyInterface*>* getInheritedObjectProperties() 
const=0;
 
 1188   virtual Iterator<std::string>* getProperties() 
const=0;
 
 1195   virtual Iterator<PropertyInterface*>* getObjectProperties() 
const=0;
 
 1209   bool applyPropertyAlgorithm(
const std::string &algorithm,
 
 1211                               std::string &errorMessage,
 
 1221   template<
typename PropertyType>
 
 1222   _DEPRECATED 
bool computeProperty(
const std::string &algorithm,
 
 1223                                    PropertyType* result, std::string &msg,
 
 1286   virtual void push(
bool unpopAllowed = 
true,
 
 1287                     std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL)=0;
 
 1294   virtual void pop(
bool unpopAllowed = 
true)=0;
 
 1330   virtual void unpop()=0;
 
 1336   virtual bool canPop()=0;
 
 1342   virtual bool canUnpop()=0;
 
 1348   virtual bool canPopThenUnpop()=0;
 
 1362   node createMetaNode(
const std::set<node> &nodeSet, 
bool multiEdges = 
true, 
bool delAllEdge = 
true);
 
 1373   void createMetaNodes(Iterator<Graph *> *itS, 
Graph *quotientGraph,
 
 1374                        std::vector<node>& metaNodes);
 
 1385   node createMetaNode(
Graph* subGraph, 
bool multiEdges = 
true, 
bool delAllEdge = 
true);
 
 1396   void openMetaNode(
node n, 
bool updateProperties=
true);
 
 1399   virtual DataSet &getNonConstAttributes() = 0;
 
 1403   virtual void restoreNodes(
const std::vector<node>& nodes)=0;
 
 1405   virtual void restoreEdges(
const std::vector<edge>& edges,
 
 1406                             const std::vector<std::pair<node, node> >& ends)=0;
 
 1409   virtual void removeNode(
const node)=0;
 
 1410   virtual void removeEdge(
const edge)=0;
 
 1415     return getRoot()->canDeleteProperty(g, prop);
 
 1420   virtual bool renameLocalProperty(PropertyInterface* prop,
 
 1421                                    const std::string& newName)=0;
 
 1424   virtual void removeSubGraph(Graph*)=0;
 
 1425   virtual void clearSubGraphs()=0;
 
 1426   virtual void restoreSubGraph(Graph*)=0;
 
 1427   virtual void setSubGraphToKeep(Graph*)=0;
 
 1430   void notifyAddNode(
const node n);
 
 1431   void notifyAddNode(Graph*, 
const node n) {
 
 1434   void notifyAddEdge(
const edge e);
 
 1435   void notifyAddEdge(Graph*, 
const edge e) {
 
 1438   void notifyBeforeSetEnds(
const edge e);
 
 1439   void notifyBeforeSetEnds(Graph*, 
const edge e) {
 
 1440     notifyBeforeSetEnds(e);
 
 1442   void notifyAfterSetEnds(
const edge e);
 
 1443   void notifyAfterSetEnds(Graph*, 
const edge e) {
 
 1444     notifyAfterSetEnds(e);
 
 1446   void notifyDelNode(
const node n);
 
 1447   void notifyDelNode(Graph*, 
const node n) {
 
 1450   void notifyDelEdge(
const edge e);
 
 1451   void notifyDelEdge(Graph*, 
const edge e) {
 
 1454   void notifyReverseEdge(
const edge e);
 
 1455   void notifyReverseEdge(Graph*, 
const edge e) {
 
 1456     notifyReverseEdge(e);
 
 1458   void notifyBeforeAddSubGraph(
const Graph*);
 
 1459   void notifyAfterAddSubGraph(
const Graph*);
 
 1460   void notifyBeforeAddSubGraph(Graph*, 
const Graph* sg) {
 
 1461     notifyBeforeAddSubGraph(sg);
 
 1463   void notifyAfterAddSubGraph(Graph*, 
const Graph* sg) {
 
 1464     notifyAfterAddSubGraph(sg);
 
 1466   void notifyBeforeDelSubGraph(
const Graph*);
 
 1467   void notifyAfterDelSubGraph(
const Graph*);
 
 1468   void notifyBeforeDelSubGraph(Graph*, 
const Graph* sg) {
 
 1469     notifyBeforeDelSubGraph(sg);
 
 1471   void notifyAfterDelSubGraph(Graph*, 
const Graph* sg) {
 
 1472     notifyAfterDelSubGraph(sg);
 
 1475   void notifyBeforeAddDescendantGraph(
const Graph*);
 
 1476   void notifyAfterAddDescendantGraph(
const Graph*);
 
 1477   void notifyBeforeDelDescendantGraph(
const Graph*);
 
 1478   void notifyAfterDelDescendantGraph(
const Graph*);
 
 1480   void notifyBeforeAddLocalProperty(
const std::string&);
 
 1481   void notifyAddLocalProperty(
const std::string&);
 
 1482   void notifyAddLocalProperty(Graph*, 
const std::string& name) {
 
 1483     notifyAddLocalProperty(name);
 
 1485   void notifyBeforeDelLocalProperty(
const std::string&);
 
 1486   void notifyAfterDelLocalProperty(
const std::string&);
 
 1487   void notifyDelLocalProperty(Graph*, 
const std::string& name) {
 
 1488     notifyBeforeDelLocalProperty(name);
 
 1490   void notifyBeforeSetAttribute(
const std::string&);
 
 1491   void notifyBeforeSetAttribute(Graph*, 
const std::string& name) {
 
 1492     notifyBeforeSetAttribute(name);
 
 1494   void notifyAfterSetAttribute(
const std::string&);
 
 1495   void notifyAfterSetAttribute(Graph*, 
const std::string& name) {
 
 1496     notifyAfterSetAttribute(name);
 
 1498   void notifyRemoveAttribute(
const std::string&);
 
 1499   void notifyRemoveAttribute(Graph*, 
const std::string& name) {
 
 1500     notifyRemoveAttribute(name);
 
 1502   void notifyDestroy();
 
 1503   void notifyDestroy(Graph*) {
 
 1508   TLP_HASH_MAP<std::string, tlp::PropertyInterface*> circularCalls;
 
 1519   enum GraphEventType {
 
 1524     TLP_REVERSE_EDGE = 4,
 
 1525     TLP_BEFORE_SET_ENDS = 5,
 
 1526     TLP_AFTER_SET_ENDS = 6,
 
 1529     TLP_BEFORE_ADD_DESCENDANTGRAPH = 9,
 
 1530     TLP_AFTER_ADD_DESCENDANTGRAPH = 10,
 
 1531     TLP_BEFORE_DEL_DESCENDANTGRAPH = 11,
 
 1532     TLP_AFTER_DEL_DESCENDANTGRAPH = 12,
 
 1533     TLP_BEFORE_ADD_SUBGRAPH = 13,
 
 1534     TLP_AFTER_ADD_SUBGRAPH = 14,
 
 1535     TLP_BEFORE_DEL_SUBGRAPH = 15,
 
 1536     TLP_AFTER_DEL_SUBGRAPH = 16,
 
 1537     TLP_ADD_LOCAL_PROPERTY = 17,
 
 1538     TLP_BEFORE_DEL_LOCAL_PROPERTY = 18,
 
 1539     TLP_AFTER_DEL_LOCAL_PROPERTY = 19,
 
 1540     TLP_ADD_INHERITED_PROPERTY = 20,
 
 1541     TLP_BEFORE_DEL_INHERITED_PROPERTY = 21,
 
 1542     TLP_AFTER_DEL_INHERITED_PROPERTY = 22,
 
 1543     TLP_BEFORE_RENAME_LOCAL_PROPERTY = 23,
 
 1544     TLP_AFTER_RENAME_LOCAL_PROPERTY = 24,
 
 1545     TLP_BEFORE_SET_ATTRIBUTE = 25,
 
 1546     TLP_AFTER_SET_ATTRIBUTE = 26,
 
 1547     TLP_REMOVE_ATTRIBUTE = 27,
 
 1548     TLP_BEFORE_ADD_LOCAL_PROPERTY = 28,
 
 1549     TLP_BEFORE_ADD_INHERITED_PROPERTY = 29
 
 1553   GraphEvent(
const Graph& g, GraphEventType graphEvtType, 
unsigned int id,
 
 1554              Event::EventType evtType = Event::TLP_MODIFICATION)
 
 1555     : 
Event(g, evtType), evtType(graphEvtType) {
 
 1560              const std::vector<node>& nodes,
 
 1561              Event::EventType evtType = Event::TLP_MODIFICATION)
 
 1562     : 
Event(g, evtType), evtType(graphEvtType) {
 
 1563     info.nodes = &nodes;
 
 1567              const std::vector<edge>& edges,
 
 1568              Event::EventType evtType = Event::TLP_MODIFICATION)
 
 1569     : 
Event(g, evtType), evtType(graphEvtType) {
 
 1570     info.edges = &edges;
 
 1575     : 
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
 
 1581              const std::string& str,
 
 1582              Event::EventType evtType = Event::TLP_MODIFICATION)
 
 1583     : 
Event(g, evtType), evtType(graphEvtType) {
 
 1584     info.name = 
new std::string(str);
 
 1590              const std::string& newName)
 
 1591     : 
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
 
 1593       new std::pair<PropertyInterface*,std::string>(prop, newName);
 
 1598     if (evtType > TLP_AFTER_DEL_SUBGRAPH) {
 
 1599       if (evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
 
 1600           evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY)
 
 1601         delete info.renamedProp;
 
 1607   Graph* getGraph()
 const {
 
 1608     return static_cast<Graph *
>(sender());
 
 1611   node getNode()
 const {
 
 1612     assert(evtType < TLP_ADD_EDGE);
 
 1613     return node(info.eltId);
 
 1616   edge getEdge()
 const {
 
 1617     assert(evtType > TLP_DEL_NODE && evtType < TLP_ADD_NODES);
 
 1618     return edge(info.eltId);
 
 1621   const std::vector<node>& getNodes()
 const {
 
 1622     assert(evtType == TLP_ADD_NODES);
 
 1623     return *(info.nodes);
 
 1626   const std::vector<edge>& getEdges()
 const {
 
 1627     assert(evtType == TLP_ADD_EDGES);
 
 1628     return *(info.edges);
 
 1631   const Graph* getSubGraph()
 const {
 
 1632     assert(evtType > TLP_ADD_EDGES && evtType < TLP_ADD_LOCAL_PROPERTY);
 
 1633     return info.subGraph;
 
 1636   const std::string& getAttributeName()
 const {
 
 1637     assert(evtType > TLP_AFTER_DEL_INHERITED_PROPERTY);
 
 1638     return *(info.name);
 
 1641   const std::string& getPropertyName() 
const;
 
 1644     assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
 
 1645            evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
 
 1646     return info.renamedProp->first;
 
 1649   const std::string& getPropertyNewName()
 const {
 
 1650     assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY);
 
 1651     return info.renamedProp->second;
 
 1654   const std::string& getPropertyOldName()
 const {
 
 1655     assert(evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
 
 1656     return info.renamedProp->second;
 
 1659   GraphEventType getType()
 const {
 
 1664   GraphEventType evtType;
 
 1667     const Graph* subGraph;
 
 1669     const std::vector<node>* nodes;
 
 1670     const std::vector<edge>* edges;
 
 1671     std::pair<PropertyInterface*, std::string>* renamedProp;
 
 1678 TLP_SCOPE std::ostream& operator<< (std::ostream &,
const tlp::Graph *);
 
 1683 #ifndef DOXYGEN_NOTFOR_DEVEL 
 1685 TLP_BEGIN_HASH_NAMESPACE {
 
 1687   struct TLP_SCOPE hash<const tlp::Graph *> {
 
 1688     size_t operator()(
const tlp::Graph *s)
 const {
return size_t(s->
getId());}
 
 1691   struct TLP_SCOPE hash<tlp::Graph *> {
 
 1694 } TLP_END_HASH_NAMESPACE
 
 1696 #endif // DOXYGEN_NOTFOR_DEVEL 
 1697 #include "cxx/Graph.cxx"