1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/**
*
* This file is part of Tulip (www.tulip-software.org)
*
* Authors: David Auber and the Tulip development Team
* from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
*
* Tulip is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Tulip is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
*/
#include <iostream>
#include <tulip/BooleanProperty.h>
#include <tulip/ColorProperty.h>
#include <tulip/DoubleProperty.h>
/**
* Tutorial 005
*
* Create a graph hierarchy and sevral properties
* Display the inherited and local properties in each graph
*/
using namespace std;
using namespace tlp;
void buildGraph(Graph *graph) {
//add three nodes
node n1=graph->addNode();
node n2=graph->addNode();
node n3=graph->addNode();
//add three edges
graph->addEdge(n2,n3);
graph->addEdge(n1,n2);
graph->addEdge(n3,n1);
}
int main() {
//create an empty graph
Graph *graph=tlp::newGraph();
//build the graph
buildGraph(graph);
//Get and create several properties
BooleanProperty *select=graph->getLocalProperty<BooleanProperty>("firstSelection");
graph->getLocalProperty<ColorProperty>("firstColors");
graph->getLocalProperty<DoubleProperty>("firstMetric");
//init the selection in order to use it for building clone subgraph
select->setAllNodeValue(true);
select->setAllEdgeValue(true);
//Create a hierarchy of subgraph (there are all the same)
Graph *subgraph1=graph->addSubGraph(select);
Graph *subgraph2=subgraph1->addSubGraph(select);
//create a property in subgraph1 (redefinition of the one defined in graph)
subgraph1->getLocalProperty<DoubleProperty>("firstMetric");
//create a new property in subgraph1
subgraph1->getLocalProperty<DoubleProperty>("secondMetric");
//create a new property in subgraph3
subgraph2->getLocalProperty<DoubleProperty>("thirdMetric");
cout << "List of the local properties present in the subgraph1:" << endl;
Iterator<string> *it=subgraph1->getLocalProperties();
while (it->hasNext()) {
cout << it->next() << endl;
}
delete it;
cout << "List of inherited properties present in the subgraph1:" << endl;
it=subgraph1->getInheritedProperties();
while (it->hasNext()) {
cout << it->next() << endl;
}
delete it;
cout << "List of the local properties present in the subgraph2:" << endl;
it=subgraph2->getLocalProperties();
while (it->hasNext()) {
cout << it->next() << endl;
}
delete it;
cout << "List of inherited properties present in the subgraph2:" << endl;
it=subgraph2->getInheritedProperties();
while (it->hasNext()) {
cout << it->next() << endl;
}
delete it;
delete graph;
return EXIT_SUCCESS;
}
|