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);
128 TLP_SCOPE
void copyToGraph(Graph *outG,
const Graph *inG, BooleanProperty* inSelection=NULL, BooleanProperty* outSelection=NULL );
136 TLP_SCOPE
void removeFromGraph(Graph * ioG, BooleanProperty* inSelection=NULL);
194 friend class GraphAbstract;
195 friend class GraphUpdatesRecorder;
196 friend class GraphDecorator;
197 friend class PropertyManager;
225 bool applyAlgorithm(
const std::string &algorithm, std::string &errorMessage,
DataSet *dataSet=NULL,
PluginProgress *progress=NULL);
238 virtual void clear()=0;
254 const std::string& name =
"unnamed")=0;
262 Graph *addSubGraph(
const std::string& name);
271 virtual Graph* addCloneSubGraph(
const std::string& name =
"unnamed",
bool addSibling =
false);
281 Graph *inducedSubGraph(
const std::set<node>& nodeSet,
282 Graph* parentSubGraph = NULL);
304 virtual void delSubGraph(
Graph *graph)=0;
324 virtual void delAllSubGraphs(
Graph *graph)=0;
331 virtual Graph* getSuperGraph()
const =0;
337 virtual Graph* getRoot()
const =0;
345 virtual void setSuperGraph(
Graph *)=0;
360 virtual Iterator<Graph *> * getSubGraphs()
const=0;
381 virtual Graph *getNthSubGraph(
unsigned int n)
const;
397 virtual unsigned int numberOfSubGraphs()
const=0;
413 virtual unsigned int numberOfDescendantGraphs()
const=0;
421 virtual bool isSubGraph(
const Graph* subGraph)
const=0;
429 virtual bool isDescendantGraph(
const Graph* subGraph)
const=0;
438 virtual Graph* getSubGraph(
unsigned int id)
const=0;
447 virtual Graph* getSubGraph(
const std::string &name)
const=0;
456 virtual Graph* getDescendantGraph(
unsigned int id)
const=0;
465 virtual Graph* getDescendantGraph(
const std::string &name)
const=0;
480 Iterator<Graph *> * getDescendantGraphs()
const;
491 virtual node addNode()=0;
501 virtual void addNodes(
unsigned int nbNodes, std::vector<node>& addedNodes)=0;
512 virtual void addNode(
const node n)=0;
524 virtual void addNodes(Iterator<node>* nodes)=0;
535 void addNodes(
const std::vector<node>& nodes);
544 virtual void delNode(
const node n,
bool deleteInAllGraphs =
false)=0;
554 virtual void delNodes(Iterator<node>* it,
bool deleteInAllGraphs =
false)=0;
564 void delNodes(
const std::vector<node>& nodes,
bool deleteInAllGraphs =
false);
574 virtual edge addEdge(
const node source,
const node target)=0;
587 virtual void addEdges(
const std::vector<std::pair<node, node> >& edges,
588 std::vector<edge>& addedEdges)=0;
600 virtual void addEdge(
const edge e)=0;
611 virtual void addEdges(Iterator<edge>* edges)=0;
621 void addEdges(
const std::vector<edge>& edges);
630 virtual void delEdge(
const edge e,
bool deleteInAllGraphs =
false)=0;
639 virtual void delEdges(Iterator<edge>* itE,
bool deleteInAllGraphs =
false)=0;
648 void delEdges(
const std::vector<edge>& edges,
bool deleteInAllGraphs =
false);
659 virtual void setEdgeOrder(
const node n,
const std::vector<edge> &edges)=0;
667 virtual void swapEdgeOrder(
const node n,
const edge e1,
const edge e2)=0;
674 virtual void setSource(
const edge e,
const node source) = 0;
681 virtual void setTarget(
const edge e,
const node target) = 0;
689 virtual void setEnds(
const edge e,
const node source,
const node target) = 0;
698 virtual void reverse(
const edge e)=0;
701 virtual void reserveNodes(
unsigned int nbNodes) = 0;
704 virtual void reserveEdges(
unsigned int nbEdges) = 0;
719 virtual node getOneNode()
const =0;
729 virtual Iterator<node>* getNodes()
const =0;
752 virtual node getInNode(
const node n,
unsigned int i)
const =0;
762 virtual Iterator<node>* getInNodes(
const node n)
const =0;
785 virtual node getOutNode(
const node n,
unsigned int i)
const =0;
795 virtual Iterator<node>* getOutNodes(
const node n)
const =0;
802 virtual Iterator<node>* getInOutNodes(
const node n)
const =0;
811 virtual Iterator<node>* bfs(
const node root =
node())
const = 0;
820 virtual Iterator<node>* dfs(
const node root =
node())
const = 0;
828 virtual Graph* getNodeMetaInfo(
const node metaNode)
const = 0;
837 virtual Iterator<edge>* getEdges()
const =0;
843 virtual edge getOneEdge()
const =0;
853 virtual Iterator<edge>* getOutEdges(
const node n)
const =0;
863 virtual Iterator<edge>* getInOutEdges(
const node n)
const =0;
873 virtual Iterator<edge>* getInEdges(
const node n)
const =0;
881 virtual Iterator<edge>* getEdgeMetaInfo(
const edge metaEdge)
const =0;
899 virtual unsigned int numberOfNodes()
const =0;
906 virtual unsigned int numberOfEdges()
const =0;
912 virtual unsigned int deg(
const node n)
const =0;
919 virtual unsigned int indeg(
const node n)
const =0;
926 virtual unsigned int outdeg(
const node n)
const =0;
933 virtual node source(
const edge e)
const =0;
940 virtual node target(
const edge e)
const =0;
947 virtual const std::pair<node, node>& ends(
const edge e)
const=0;
955 virtual node opposite(
const edge e,
const node n)
const =0;
962 virtual bool isElement(
const node n)
const =0;
969 virtual bool isMetaNode(
const node n)
const =0;
976 virtual bool isElement(
const edge e)
const =0;
983 virtual bool isMetaEdge(
const edge e)
const =0;
993 bool directed =
true)
const {
994 return existEdge(source, target, directed).isValid();
1005 virtual std::vector<edge> getEdges(
const node source,
const node target,
1006 bool directed =
true)
const=0;
1018 virtual edge existEdge(
const node source,
const node target,
1019 bool directed =
true)
const=0;
1029 virtual void setName(
const std::string &name) = 0;
1035 virtual std::string getName()
const = 0;
1044 return (const_cast<Graph *>(
this))->getNonConstAttributes();
1053 template<
typename ATTRIBUTETYPE>
1054 bool getAttribute(
const std::string &name, ATTRIBUTETYPE& value)
const;
1061 DataType* getAttribute(
const std::string& name)
const;
1068 template<
typename ATTRIBUTETYPE>
1069 void setAttribute(
const std::string &name,
const ATTRIBUTETYPE &value);
1076 void setAttribute(
const std::string &name,
const DataType* value);
1083 notifyRemoveAttribute(name);
1084 getNonConstAttributes().remove(name);
1093 return getAttributes().exist(name);
1103 virtual void addLocalProperty(
const std::string &name,
PropertyInterface *prop)=0;
1129 template<
typename PropertyType>
1130 PropertyType* getLocalProperty(
const std::string &name);
1144 template<
typename PropertyType>
1145 PropertyType* getProperty(
const std::string &name);
1160 PropertyInterface *getLocalProperty(
const std::string& propertyName,
const std::string& propertyType);
1175 PropertyInterface *getProperty(
const std::string& propertyName,
const std::string& propertyType);
1182 virtual bool existProperty(
const std::string& name)
const = 0;
1189 virtual bool existLocalProperty(
const std::string& name)
const = 0;
1197 virtual void delLocalProperty(
const std::string& name)=0;
1203 virtual Iterator<std::string>* getLocalProperties()
const=0;
1209 virtual Iterator<PropertyInterface*>* getLocalObjectProperties()
const=0;
1216 virtual Iterator<std::string>* getInheritedProperties()
const=0;
1223 virtual Iterator<PropertyInterface*>* getInheritedObjectProperties()
const=0;
1230 virtual Iterator<std::string>* getProperties()
const=0;
1237 virtual Iterator<PropertyInterface*>* getObjectProperties()
const=0;
1251 bool applyPropertyAlgorithm(
const std::string &algorithm,
1253 std::string &errorMessage,
1317 virtual void push(
bool unpopAllowed =
true,
1318 std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL)=0;
1325 virtual void pop(
bool unpopAllowed =
true)=0;
1361 virtual void unpop()=0;
1367 virtual bool canPop()=0;
1373 virtual bool canUnpop()=0;
1379 virtual bool canPopThenUnpop()=0;
1393 node createMetaNode(
const std::set<node> &nodeSet,
bool multiEdges =
true,
bool delAllEdge =
true);
1404 void createMetaNodes(Iterator<Graph *> *itS,
Graph *quotientGraph,
1405 std::vector<node>& metaNodes);
1416 node createMetaNode(
Graph* subGraph,
bool multiEdges =
true,
bool delAllEdge =
true);
1427 void openMetaNode(
node n,
bool updateProperties=
true);
1430 virtual DataSet &getNonConstAttributes() = 0;
1434 virtual void restoreNodes(
const std::vector<node>& nodes)=0;
1436 virtual void restoreEdges(
const std::vector<edge>& edges,
1437 const std::vector<std::pair<node, node> >& ends)=0;
1440 virtual void removeNode(
const node)=0;
1441 virtual void removeEdge(
const edge)=0;
1446 return getRoot()->canDeleteProperty(g, prop);
1451 virtual bool renameLocalProperty(PropertyInterface* prop,
1452 const std::string& newName)=0;
1455 virtual void removeSubGraph(Graph*)=0;
1456 virtual void clearSubGraphs()=0;
1457 virtual void restoreSubGraph(Graph*)=0;
1458 virtual void setSubGraphToKeep(Graph*)=0;
1461 void notifyAddNode(
const node n);
1462 void notifyAddNode(Graph*,
const node n) {
1465 void notifyAddEdge(
const edge e);
1466 void notifyAddEdge(Graph*,
const edge e) {
1469 void notifyBeforeSetEnds(
const edge e);
1470 void notifyBeforeSetEnds(Graph*,
const edge e) {
1471 notifyBeforeSetEnds(e);
1473 void notifyAfterSetEnds(
const edge e);
1474 void notifyAfterSetEnds(Graph*,
const edge e) {
1475 notifyAfterSetEnds(e);
1477 void notifyDelNode(
const node n);
1478 void notifyDelNode(Graph*,
const node n) {
1481 void notifyDelEdge(
const edge e);
1482 void notifyDelEdge(Graph*,
const edge e) {
1485 void notifyReverseEdge(
const edge e);
1486 void notifyReverseEdge(Graph*,
const edge e) {
1487 notifyReverseEdge(e);
1489 void notifyBeforeAddSubGraph(
const Graph*);
1490 void notifyAfterAddSubGraph(
const Graph*);
1491 void notifyBeforeAddSubGraph(Graph*,
const Graph* sg) {
1492 notifyBeforeAddSubGraph(sg);
1494 void notifyAfterAddSubGraph(Graph*,
const Graph* sg) {
1495 notifyAfterAddSubGraph(sg);
1497 void notifyBeforeDelSubGraph(
const Graph*);
1498 void notifyAfterDelSubGraph(
const Graph*);
1499 void notifyBeforeDelSubGraph(Graph*,
const Graph* sg) {
1500 notifyBeforeDelSubGraph(sg);
1502 void notifyAfterDelSubGraph(Graph*,
const Graph* sg) {
1503 notifyAfterDelSubGraph(sg);
1506 void notifyBeforeAddDescendantGraph(
const Graph*);
1507 void notifyAfterAddDescendantGraph(
const Graph*);
1508 void notifyBeforeDelDescendantGraph(
const Graph*);
1509 void notifyAfterDelDescendantGraph(
const Graph*);
1511 void notifyBeforeAddLocalProperty(
const std::string&);
1512 void notifyAddLocalProperty(
const std::string&);
1513 void notifyAddLocalProperty(Graph*,
const std::string& name) {
1514 notifyAddLocalProperty(name);
1516 void notifyBeforeDelLocalProperty(
const std::string&);
1517 void notifyAfterDelLocalProperty(
const std::string&);
1518 void notifyDelLocalProperty(Graph*,
const std::string& name) {
1519 notifyBeforeDelLocalProperty(name);
1521 void notifyBeforeSetAttribute(
const std::string&);
1522 void notifyBeforeSetAttribute(Graph*,
const std::string& name) {
1523 notifyBeforeSetAttribute(name);
1525 void notifyAfterSetAttribute(
const std::string&);
1526 void notifyAfterSetAttribute(Graph*,
const std::string& name) {
1527 notifyAfterSetAttribute(name);
1529 void notifyRemoveAttribute(
const std::string&);
1530 void notifyRemoveAttribute(Graph*,
const std::string& name) {
1531 notifyRemoveAttribute(name);
1533 void notifyDestroy();
1534 void notifyDestroy(Graph*) {
1539 TLP_HASH_MAP<std::string, tlp::PropertyInterface*> circularCalls;
1550 enum GraphEventType {
1555 TLP_REVERSE_EDGE = 4,
1556 TLP_BEFORE_SET_ENDS = 5,
1557 TLP_AFTER_SET_ENDS = 6,
1560 TLP_BEFORE_ADD_DESCENDANTGRAPH = 9,
1561 TLP_AFTER_ADD_DESCENDANTGRAPH = 10,
1562 TLP_BEFORE_DEL_DESCENDANTGRAPH = 11,
1563 TLP_AFTER_DEL_DESCENDANTGRAPH = 12,
1564 TLP_BEFORE_ADD_SUBGRAPH = 13,
1565 TLP_AFTER_ADD_SUBGRAPH = 14,
1566 TLP_BEFORE_DEL_SUBGRAPH = 15,
1567 TLP_AFTER_DEL_SUBGRAPH = 16,
1568 TLP_ADD_LOCAL_PROPERTY = 17,
1569 TLP_BEFORE_DEL_LOCAL_PROPERTY = 18,
1570 TLP_AFTER_DEL_LOCAL_PROPERTY = 19,
1571 TLP_ADD_INHERITED_PROPERTY = 20,
1572 TLP_BEFORE_DEL_INHERITED_PROPERTY = 21,
1573 TLP_AFTER_DEL_INHERITED_PROPERTY = 22,
1574 TLP_BEFORE_RENAME_LOCAL_PROPERTY = 23,
1575 TLP_AFTER_RENAME_LOCAL_PROPERTY = 24,
1576 TLP_BEFORE_SET_ATTRIBUTE = 25,
1577 TLP_AFTER_SET_ATTRIBUTE = 26,
1578 TLP_REMOVE_ATTRIBUTE = 27,
1579 TLP_BEFORE_ADD_LOCAL_PROPERTY = 28,
1580 TLP_BEFORE_ADD_INHERITED_PROPERTY = 29
1584 GraphEvent(
const Graph& g, GraphEventType graphEvtType,
unsigned int id,
1585 Event::EventType evtType = Event::TLP_MODIFICATION)
1586 :
Event(g, evtType), evtType(graphEvtType) {
1591 const std::vector<node>& nodes,
1592 Event::EventType evtType = Event::TLP_MODIFICATION)
1593 :
Event(g, evtType), evtType(graphEvtType) {
1594 info.nodes = &nodes;
1598 const std::vector<edge>& edges,
1599 Event::EventType evtType = Event::TLP_MODIFICATION)
1600 :
Event(g, evtType), evtType(graphEvtType) {
1601 info.edges = &edges;
1606 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1612 const std::string& str,
1613 Event::EventType evtType = Event::TLP_MODIFICATION)
1614 :
Event(g, evtType), evtType(graphEvtType) {
1615 info.name =
new std::string(str);
1621 const std::string& newName)
1622 :
Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1624 new std::pair<PropertyInterface*,std::string>(prop, newName);
1629 if (evtType > TLP_AFTER_DEL_SUBGRAPH) {
1630 if (evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
1631 evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY)
1632 delete info.renamedProp;
1638 Graph* getGraph()
const {
1639 return static_cast<Graph *
>(sender());
1642 node getNode()
const {
1643 assert(evtType < TLP_ADD_EDGE);
1644 return node(info.eltId);
1647 edge getEdge()
const {
1648 assert(evtType > TLP_DEL_NODE && evtType < TLP_ADD_NODES);
1649 return edge(info.eltId);
1652 const std::vector<node>& getNodes()
const {
1653 assert(evtType == TLP_ADD_NODES);
1654 return *(info.nodes);
1657 const std::vector<edge>& getEdges()
const {
1658 assert(evtType == TLP_ADD_EDGES);
1659 return *(info.edges);
1662 const Graph* getSubGraph()
const {
1663 assert(evtType > TLP_ADD_EDGES && evtType < TLP_ADD_LOCAL_PROPERTY);
1664 return info.subGraph;
1667 const std::string& getAttributeName()
const {
1668 assert(evtType > TLP_AFTER_DEL_INHERITED_PROPERTY);
1669 return *(info.name);
1672 const std::string& getPropertyName()
const;
1675 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
1676 evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1677 return info.renamedProp->first;
1680 const std::string& getPropertyNewName()
const {
1681 assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY);
1682 return info.renamedProp->second;
1685 const std::string& getPropertyOldName()
const {
1686 assert(evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1687 return info.renamedProp->second;
1690 GraphEventType getType()
const {
1695 GraphEventType evtType;
1698 const Graph* subGraph;
1700 const std::vector<node>* nodes;
1701 const std::vector<edge>* edges;
1702 std::pair<PropertyInterface*, std::string>* renamedProp;
1709 TLP_SCOPE std::ostream& operator<< (std::ostream &,
const tlp::Graph *);
1714 #ifndef DOXYGEN_NOTFOR_DEVEL
1716 TLP_BEGIN_HASH_NAMESPACE {
1718 struct TLP_SCOPE hash<const tlp::Graph *> {
1719 size_t operator()(
const tlp::Graph *s)
const {
return size_t(s->
getId());}
1722 struct TLP_SCOPE hash<tlp::Graph *> {
1725 } TLP_END_HASH_NAMESPACE
1727 #endif // DOXYGEN_NOTFOR_DEVEL
1728 #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 and all its subgraphs to a file using the tlp format. Extension of the file can be either .tlp (human-readable text file) or .tlp.gz (gzipped text 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 in the tlp format from a file (extension can be .tlp or .tlp.gz). This function uses th...