QModelIndex SceneLayersModel::index(int row, int column,const QModelIndex &parent) const {
  if(!hasIndex(row,column,parent))
    return QModelIndex();

  if (!parent.isValid()) { // Top level: layers
    GlLayer* layer = _scene->getLayersList()[row].second;
    assert(layer != NULL);
    return createIndex(row,column,layer);
  }

  GlComposite* composite = NULL;

  if (!parent.parent().isValid())  {// 1st sublevel, parent is a layer
    GlLayer *layer = reinterpret_cast<GlLayer*>(parent.internalPointer());
    composite = layer->getComposite();
  }
  else {  // Deeper sublevel, the parent is a composite
    composite = reinterpret_cast<GlComposite*>(parent.internalPointer());
  }

  if (_scene->getGlGraphComposite() == composite)
    return createIndex(row,column,GRAPH_COMPOSITE_IDS[row]);

  int i=0;
  std::map<std::string, GlSimpleEntity*> entities = composite->getGlEntities();

  for (std::map<std::string,GlSimpleEntity*>::iterator it = entities.begin(); it != entities.end(); ++it) {
    if (i++ == row)
      return createIndex(row,column,it->second);
  }

  return QModelIndex();
}
Esempio n. 2
0
GlLayer *GlScene::createLayerAfter(const string &layerName, const string &afterLayerWithName, bool is3d) {
  GlLayer *newLayer = NULL;
  GlLayer *oldLayer = getLayer(layerName);

  for(vector<pair<string, GlLayer *> >::iterator it = _layersList.begin() ; it != _layersList.end(); ++it) {
    if(it->first == afterLayerWithName) {
      ++it;
      if (!is3d) {
        newLayer = new GlLayer(layerName, is3d);
      } else {
        newLayer = new GlLayer(layerName, getMainLayer()->getCamera(), getMainLayer()->getLight());
      }
      _layersList.insert(it, pair<string,GlLayer*>(layerName, newLayer));
      newLayer->setScene(this);

      if(oldLayer != NULL) {
        warning() << "Warning : You have a layer in the scene with same name, previous layer will be removed" << endl;
        removeLayer(oldLayer);
      }

      break;
    }
  }

  if (newLayer) {
    sendEvent(GlSceneEvent(GlSceneEvent::LAYER_ADDED_IN_SCENE, this, newLayer));
  }

  return newLayer;
}
Esempio n. 3
0
GlScene *GlMetaNodeRenderer::createScene(Graph *metaGraph) const {
  GlScene *scene = new GlScene(new GlCPULODCalculator());
  GlLayer *layer = new GlLayer("Main");
  scene->addExistingLayer(layer);
  GlGraphComposite *graphComposite = new GlGraphComposite(metaGraph, scene);
  layer->addGlEntity(graphComposite, "graph");
  return scene;
}
Esempio n. 4
0
int main(int argc, char **argv) {

  // A QApplication must always be declared at the beginning of the main function if you intend to
  // use the tulip-gui library
  // This must be done before calling tlp::initTulipSoftware()
  QApplication app(argc, argv);

  // Initialize the library and load all plugins
  tlp::initTulipSoftware();

  Graph *g = nullptr;
  if (QApplication::arguments().size() == 2) {
    // Load the file passed as first argument into a graph.
    // This method will select the default Tulip algorithm plugin (TLP)
    QString filename = QApplication::arguments()[1];
    if (!((filename.endsWith(".tlp")) || (filename.endsWith(".tlp.gz")))) {
      cout << "File " << QStringToTlpString(filename)
           << " not compatible. Use a tlp file or a tlp.gz file" << endl;
      exit(EXIT_FAILURE);
    }
    g = tlp::loadGraph(QStringToTlpString(filename));
  } else {
    // If no arguments were given to the command, create a complete tree of depth 5
    // and degree 2 for demo purpose
    g = createCompleteTree(5, 2);
    // Set some visual properties in order to visualize the tree
    setTreeVisualProperties(g);
  }

  // Creates the main widget that will display our graph
  GlMainWidget *mainWidget = new GlMainWidget(nullptr);

  // Adds a layer to the scene
  GlLayer *mainLayer = mainWidget->getScene()->createLayer("Main");

  // Adds the graph to this layer
  mainLayer->addGraph(g, "graph");

  // Sets some rendering parameters on the graph to visualize
  setGraphRenderingParameters(mainWidget->getScene()->getGlGraphComposite());

  // Display the widget
  mainWidget->show();

  // Flush event loop in order to let paint events pass through in order for the scene to be
  // initialized.
  QApplication::processEvents();

  // Center the camera and draw the graph
  mainWidget->centerScene();
  mainWidget->draw();

  // Adds Zoom and pan navigation to the widget
  mainWidget->installEventFilter(new MouseNKeysNavigator);
  return app.exec();
}
Esempio n. 5
0
set<GlEntity*> GlScene::getEntities() {
  set<GlEntity*> ret;
  for(vector<pair<string,GlLayer*> >::iterator it=_layersList.begin() ; it!=_layersList.end() ; ++it) {
    GlLayer *layer = it->second;
    const map<string, GlEntity*> &layerEntities = layer->getGlEntities();
    for (map<string, GlEntity*>::const_iterator it2 = layerEntities.begin() ; it2 != layerEntities.end() ; ++it2) {
      GlEntity *entity = it2->second;
      ret.insert(entity);
    }
  }
  return ret;
}
Esempio n. 6
0
int main(int argc, char **argv) {
  /*
  A QApplication must always be declared at the beginning of the main function in order for Tulip to work.
  This must be done before calling tlp::initTulipSoftware()
  */
  QApplication app(argc, argv);
  /*
  Initialize the library, load plugins and set application runtime pathes accordingly to the host
  operating system
  This method should always be called if you intend to use plugins in your application.
  */
  tlp::initTulipSoftware();
  /*
  Load the file passed as first argument into a graph.
  This method will select the default Tulip algorithm plugin (TLP)
  */
  // Graph* g = tlp::loadGraph(argv[1]);
  Graph *g = newGraph();

  TulipProject *_project = TulipProject::openProject(QString::fromLatin1(argv[1]));

  // std::cout << QString::fromLatin1(argv[1]) << std::endl;

  if (_project->exists("/data/graphs/0/graph.tlp")) {
    std::cout << "pouet pouet" << std::endl;
    DataSet data;

    data.set<std::string>("file::filename",
                          QStringToTlpString(_project->toAbsolutePath("/data/graphs/0/graph.tlp")));

    g = tlp::importGraph("TLP Import", data);
    std::cout << g << std::endl;
  }

  // Creates the main widget that will display our graph
  GlMainWidget *mainWidget = new GlMainWidget();
  // Adds a layer to the scene
  GlLayer *mainLayer = mainWidget->getScene()->createLayer("Main");
  // Adds the graph to this layer
  mainLayer->addGraph(g, "graph");

  // Display the widget
  mainWidget->show();
  // Flush event loop in order to let paint events pass through in order for the scene to be
  // initialized.
  QApplication::processEvents();
  // Center the camera and draw the graph
  mainWidget->centerScene();
  mainWidget->draw();
  // Adds Zoom and pan navigation to the widget
  mainWidget->installEventFilter(new MouseNKeysNavigator);
  return app.exec();
}
Esempio n. 7
0
int main(int argc, char **argv) {
  /*
  A QApplication must always be declared at the beginning of the main function in order for Tulip to work.
  This must be done before calling tlp::initTulipSoftware()
  */
  QApplication app(argc, argv);
  /*
  Initialize the library, load plugins and set application runtime pathes accordingly to the host
  operating system
  This method should always be called if you intend to use plugins in your application.
  */
  tlp::initTulipSoftware();

  // Creates the main widget that will display our graph
  GlMainWidget *mainWidget = new GlMainWidget();
  // Adds a layer to the scene
  GlLayer *mainLayer = mainWidget->getScene()->createLayer("Main");

  Coord center1(-1, -1, -1);
  Coord center2(1, 1, 1);
  Size size(1, 1, 1);
  Color whiteOpaque(255, 255, 255, 255);
  Color blackOpaque(0, 0, 0, 255);

  GlBox *node1 = new GlBox(center1, size, whiteOpaque, blackOpaque);
  GlBox *node2 = new GlBox(center2, size, whiteOpaque, blackOpaque);

  mainLayer->addGlEntity(node1, "Gl Tutorial 1: Node 1");
  mainLayer->addGlEntity(node2, "Gl Tutorial 1: Node 2");

  Coord centerBox(0, 0, 0);
  Size sizeBox(3.001, 3.001, 3.001);
  Color purpleTrans(155, 0, 155, 50);
  GlBox *box = new GlBox(centerBox, sizeBox, purpleTrans, blackOpaque);
  mainLayer->addGlEntity(box, "Gl Tutorial 2: Box");

  // Display the widget
  mainWidget->show();
  // Flush event loop in order to let paint events pass through in order for the scene to be
  // initialized.
  QApplication::processEvents();
  // Center the camera and draw the graph
  mainWidget->centerScene();
  mainWidget->draw();
  // Adds Zoom and pan navigation to the widget
  mainWidget->installEventFilter(new MouseNKeysNavigator);
  return app.exec();
}
Esempio n. 8
0
void PathHighlighter::addGlEntity(GlScene *scene, GlSimpleEntity *entity, bool deleteOnExit, const string &name) {
  string realName = name;

  if (realName.compare("") == 0) {
    stringstream ss;
    ss << getName() << entityId++;
    realName = ss.str();
  }

  if (backupScene)
    backupScene->removeListener(this);

  backupScene = scene;
  backupScene->addListener(this);

  GlLayer *layer = getWorkingLayer(backupScene);
  entities[realName] = deleteOnExit;
  layer->addGlEntity(entity, realName);
}
Esempio n. 9
0
void PathHighlighter::clear() {
  if (backupScene) {
    GlLayer *layer = getWorkingLayer(backupScene);

    for (map<string, bool>::iterator it = entities.begin(); it != entities.end(); ++it) {
      string entityName(it->first);
      GlSimpleEntity *entity(layer->findGlEntity(entityName));

      if (entity) {
        layer->deleteGlEntity(entity);

        if (it->second)
          delete entity;
      }
    }

    entities.clear();
  }
}
Esempio n. 10
0
GlLayer *GlScene::createLayer(const string &name, bool is3d) {
  GlLayer *oldLayer = getLayer(name);

  if(oldLayer != NULL) {
    warning() << "Warning : You have a layer in the scene with same name, previous layer will be removed" << endl;
    removeLayer(oldLayer);
  }

  GlLayer *newLayer = NULL;
  if (!is3d) {
    newLayer = new GlLayer(name, is3d);
  } else {
    newLayer = new GlLayer(name, getMainLayer()->getCamera(), getMainLayer()->getLight());
  }
  _layersList.push_back(pair<string,GlLayer*>(name, newLayer));
  newLayer->setScene(this);

  sendEvent(GlSceneEvent(GlSceneEvent::LAYER_ADDED_IN_SCENE, this, newLayer));

  return newLayer;
}
int SceneLayersModel::rowCount(const QModelIndex &parent) const {
  if (!parent.isValid()) { // Top level, layers count
    return _scene->getLayersList().size();
  }

  if (!parent.parent().isValid()) {// First sublevel: parent is a GlLayer
    GlLayer* layer = reinterpret_cast<GlLayer*>(parent.internalPointer());
    return layer->getComposite()->getGlEntities().size();
  }

  if (GRAPH_COMPOSITE_IDS.contains(parent.internalId()))
    return 0;

  GlSimpleEntity* entity = reinterpret_cast<GlSimpleEntity*>(parent.internalPointer());

  if (_scene->getGlGraphComposite() == entity)
    return GRAPH_COMPOSITE_IDS.size();

  if (dynamic_cast<GlComposite*>(entity) != NULL)
    return static_cast<GlComposite*>(entity)->getGlEntities().size();

  return 0;
}
bool SceneLayersModel::setData(const QModelIndex &index, const QVariant &value, int role) {
  if (index.column() == 0 || role != Qt::CheckStateRole)
    return false;

  if (GRAPH_COMPOSITE_IDS.contains(index.internalId())) {
    quint32 id = index.internalId();
    GlGraphRenderingParameters* p = _scene->getGlGraphComposite()->getRenderingParametersPointer();

    if (index.column() == 1) {
      bool visible = value.value<int>() == (int)(Qt::Checked);

      if (id == NODES_ID)
        p->setDisplayNodes(visible);
      else if (id == EDGES_ID)
        p->setDisplayEdges(visible);
      else if (id == META_NODES_ID)
        p->setDisplayMetaNodes(visible);
      else if (id == NODES_LABELS_ID)
        p->setViewNodeLabel(visible);
      else if (id == EDGES_LABELS_ID)
        p->setViewEdgeLabel(visible);
      else if (id == META_NODES_LABELS_ID)
        p->setViewMetaLabel(visible);
    }
    else if (index.column() == 2) {
      int stencil = (value.value<int>() == (int)(Qt::Checked) ? FULL_STENCIL : NO_STENCIL);

      if (id == NODES_ID)
        p->setNodesStencil(stencil);
      else if (id == EDGES_ID)
        p->setEdgesStencil(stencil);
      else if (id == SELECTED_NODES_ID)
        p->setSelectedNodesStencil(stencil);
      else if (id == SELECTED_EDGES_ID)
        p->setSelectedEdgesStencil(stencil);
      else if (id == META_NODES_ID)
        p->setMetaNodesStencil(stencil);
      else if (id == SELECTED_META_NODES_ID)
        p->setSelectedMetaNodesStencil(stencil);
      else if (id == META_NODES_LABELS_ID)
        p->setMetaNodesLabelStencil(stencil);
      else if (id == NODES_LABELS_ID)
        p->setNodesLabelStencil(stencil);
      else if (id == EDGES_LABELS_ID)
        p->setEdgesLabelStencil(stencil);
    }

    emit drawNeeded(_scene);
    return true;
  }

  GlSimpleEntity* entity = NULL;
  GlLayer* layer = NULL;

  if (!index.parent().isValid()) {
    layer = reinterpret_cast<GlLayer*>(index.internalPointer());
    entity = layer->getComposite();
  }
  else
    entity = reinterpret_cast<GlSimpleEntity*>(index.internalPointer());

  bool val = value.value<int>() == (int)Qt::Checked;

  if (index.column() == 1) {
    if (layer)
      layer->setVisible(val);

    entity->setVisible(val);
  }
  else if (index.column() == 2)
    entity->setStencil(val ? FULL_STENCIL : 0xFFFF);

  emit drawNeeded(_scene);
  return true;
}
QVariant SceneLayersModel::data(const QModelIndex &index, int role) const {
  GlComposite* parent = NULL;
  GlSimpleEntity* entity = NULL;
  GlLayer* layer = NULL;

  if (GRAPH_COMPOSITE_IDS.contains(index.internalId())) {
    quint32 id = index.internalId();
    GlGraphRenderingParameters* parameters = _scene->getGlGraphComposite()->getRenderingParametersPointer();
    QString display;
    int stencil = NO_STENCIL;
    bool visible = false;

    if (id == NODES_ID) {
      display = trUtf8("Nodes");
      stencil = parameters->getNodesStencil();
      visible = parameters->isDisplayNodes();
    }
    else if (id == EDGES_ID) {
      display = trUtf8("Edges");
      stencil = parameters->getEdgesStencil();
      visible = parameters->isDisplayEdges();
    }
    else if (id == SELECTED_NODES_ID) {
      display = trUtf8("Selected nodes");
      stencil = parameters->getSelectedNodesStencil();
      visible = parameters->isDisplayNodes();
    }
    else if (id == SELECTED_EDGES_ID) {
      display = trUtf8("Selected edges");
      stencil = parameters->getSelectedEdgesStencil();
      visible = parameters->isDisplayEdges();
    }
    else if (id == META_NODES_ID) {
      display = trUtf8("Meta nodes content");
      stencil = parameters->getMetaNodesStencil();
      visible = parameters->isDisplayMetaNodes();
    }
    else if (id == SELECTED_META_NODES_ID) {
      display = trUtf8("Selected meta nodes");
      stencil = parameters->getSelectedMetaNodesStencil();
      visible = parameters->isDisplayMetaNodes();
    }
    else if (id == META_NODES_LABELS_ID) {
      display = trUtf8("Meta nodes content labels");
      stencil = parameters->getMetaNodesLabelStencil();
      visible = parameters->isViewMetaLabel();
    }
    else if (id == NODES_LABELS_ID) {
      display = trUtf8("Nodes labels");
      stencil = parameters->getNodesLabelStencil();
      visible = parameters->isViewNodeLabel();
    }
    else if (id == EDGES_LABELS_ID) {
      display = trUtf8("Edges labels");
      stencil = parameters->getEdgesLabelStencil();
      visible = parameters->isViewEdgeLabel();
    }

    if (role == Qt::DisplayRole && index.column() == 0)
      return display;

    if (role == Qt::CheckStateRole) {
      if (index.column() == 1)
        return (visible ? Qt::Checked : Qt::Unchecked);

      if (index.column() == 2)
        return (stencil == NO_STENCIL ? Qt::Unchecked : Qt::Checked);
    }

    return QVariant();
  }

  if (!index.parent().isValid()) {
    layer = reinterpret_cast<GlLayer*>(index.internalPointer());
    entity = layer->getComposite();
  }
  else {
    entity = reinterpret_cast<GlSimpleEntity*>(index.internalPointer());
    parent = entity->getParent();
  }

  if (role == Qt::DisplayRole && index.column() == 0) {
    if (layer != NULL)
      return layer->getName().c_str();

    std::map<std::string, GlSimpleEntity*> siblings = parent->getGlEntities();

    for(std::map<std::string, GlSimpleEntity*>::iterator it = siblings.begin(); it != siblings.end(); ++it) {
      if (it->second == entity)
        return it->first.c_str();
    }
  }

  if (role == Qt::FontRole && layer != NULL) {
    QFont f;
    f.setBold(true);
    return f;
  }

  if (role == Qt::CheckStateRole) {
    if (index.column() == 1)
      return (entity->isVisible() ? Qt::Checked : Qt::Unchecked);

    if (index.column() == 2)
      return (entity->getStencil() == NO_STENCIL ? Qt::Unchecked : Qt::Checked);
  }

  if (role == Qt::TextAlignmentRole && index.column() != 0)
    return Qt::AlignCenter;

  return QVariant();
}