1 #include <tulip/PluginLoaderTxt.h> 2 #include <tulip/PluginLibraryLoader.h> 3 #include <tulip/GlMainWidget.h> 4 #include <tulip/MouseInteractors.h> 5 #include <tulip/TlpQtTools.h> 6 #include <tulip/LayoutProperty.h> 7 #include <tulip/SizeProperty.h> 8 #include <tulip/StringProperty.h> 9 #include <tulip/DoubleProperty.h> 10 #include <tulip/IntegerProperty.h> 11 #include <tulip/TulipViewSettings.h> 12 #include <tulip/GlGraphComposite.h> 13 #include <tulip/GlGraphRenderingParameters.h> 14 #include <tulip/ForEach.h> 15 #include <QApplication> 27 GlMainWidget *mainWidget;
34 InteractorPlugin(Graph *_g, GlMainWidget *_widget) : graph(_g), mainWidget(_widget), MousePanNZoomNavigator()
44 bool eventFilter(QObject *obj, QEvent* e) {
45 bool apply_plugin =
false;
48 float cluster_spacing = 0;
49 graph->getAttribute(
"cluster_spacing", cluster_spacing);
51 if (e->type() == QEvent::KeyPress) {
52 QKeyEvent *ke =
static_cast<QKeyEvent*
>(e);
53 int delta = (ke->isAutoRepeat() ? 3 : 1);
57 cluster_spacing -= 0.01f;
58 if (cluster_spacing < 0)
64 cluster_spacing += 0.01f;
73 graph->setAttribute(
"cluster_spacing", cluster_spacing);
74 LayoutProperty *viewLayout = graph->getProperty<LayoutProperty>(
"viewLayout");
76 graph->applyPropertyAlgorithm(
"SFCLayout", viewLayout, errMsg);
77 cout <<
"SFCLayout errMsg: " << errMsg << endl;
85 return MousePanNZoomNavigator::eventFilter(obj, e);
89 void addChildren(Graph *graph, node root,
int depth,
int degree) {
91 for (
int i = 0; i < degree; ++i) {
92 node child = graph->addNode();
93 graph->addEdge(root, child);
94 addChildren(graph, child, depth - 1, degree);
99 Graph *createCompleteTree(
int depth,
int degree) {
100 Graph *graph = newGraph();
101 node root = graph->addNode();
102 addChildren(graph, root, depth, degree);
106 void setVisualProperties(Graph *tree) {
108 StringProperty *viewLabel = tree->getProperty<StringProperty>(
"viewLabel");
110 forEach(n, tree->getNodes()) {
111 viewLabel->setNodeValue(n, QString::number(n.id).toStdString());
114 DoubleProperty *viewBorderWidth = tree->getProperty<DoubleProperty>(
"viewBorderWidth");
115 viewBorderWidth->setAllNodeValue(1);
118 void setGraphRenderingParameters(GlGraphComposite *glGraphComposite) {
119 GlGraphRenderingParameters *renderingParameters = glGraphComposite->getRenderingParametersPointer();
121 renderingParameters->setAntialiasing(
true);
123 renderingParameters->setDisplayNodes(
true);
125 renderingParameters->setLabelsDensity(100);
127 renderingParameters->setViewArrow(
false);
129 renderingParameters->setEdgeColorInterpolate(
false);
131 renderingParameters->setEdgeSizeInterpolate(
false);
133 renderingParameters->setLabelScaled(
true);
136 int main(
int argc,
char** argv) {
139 QApplication app(argc, argv);
142 tlp:PluginLoader * plugin_loader =
new tlp::PluginLoaderTxt();
143 tlp::initTulipSoftware(plugin_loader);
146 if (QApplication::arguments().size() == 2) {
149 QString filename = QApplication::arguments()[1];
150 if (!((filename.endsWith(
".tlp")) || (filename.endsWith(
".tlp.gz")))) {
151 cout <<
"File " << filename.toStdString() <<
" not compatible. Use a tlp file or a tlp.gz file" << endl;
154 g = tlp::loadGraph(filename.toStdString());
159 g = createCompleteTree(5, 6);
164 float cluster_spacing = 2;
165 g->setAttribute(
"cluster_spacing", cluster_spacing);
167 LayoutProperty *viewLayout = g->getProperty<LayoutProperty>(
"viewLayout");
169 g->applyPropertyAlgorithm(
"SFCLayout", viewLayout, errMsg);
170 cout <<
"SFCLayout errMsg: " << errMsg << endl;
173 GlMainWidget* mainWidget =
new GlMainWidget(NULL);
175 GlLayer* mainLayer = mainWidget->getScene()->createLayer(
"Main");
179 Graph * sg = g->getSubGraph(
"original");
181 setVisualProperties(sg);
182 mainLayer->addGraph(sg,
"graph");
185 setGraphRenderingParameters(mainWidget->getScene()->getGlGraphComposite());
189 QApplication::processEvents();
191 mainWidget->centerScene();
194 mainWidget->installEventFilter(
new MouseNKeysNavigator);
199 mainWidget->installEventFilter(&interactorPlugin);