(WIP) Addition of .h files

This commit is contained in:
Maxime Gimeno 2015-09-29 14:06:11 +02:00
parent 06e885da4c
commit fee42307f7
11 changed files with 422 additions and 13 deletions

View File

@ -8,7 +8,6 @@
#include <cmath>
class Scene_item;
// OpenGL rendering mode
enum RenderingMode { Points = 0,
PointsPlusNormals,
@ -71,7 +70,7 @@ public:
typedef int Item_id;
virtual ~Scene_interface() {};
virtual ~Scene_interface() {}
virtual Item_id addItem(Scene_item* item) = 0;
virtual Scene_item* replaceItem(Item_id, Scene_item*, bool emit_item_about_to_be_destroyed = false) = 0;

View File

@ -135,6 +135,7 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
Viewer.cpp #Viewer_moc.cpp
Viewer_interface_moc.cpp
Scene_item.cpp #Scene_item.moc
Scene_group_item.cpp
Polyhedron_demo_plugin_helper.cpp)
qt5_use_modules(demo_framework OpenGL Gui Widgets Script Xml)
@ -213,7 +214,7 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
scene_basic_objects
scene_polyhedron_item
scene_polygon_soup_item
scene_nef_polyhedron_item )
scene_nef_polyhedron_item)
add_to_cached_list( CGAL_EXECUTABLE_TARGETS ${lib} )
endforeach()
@ -493,6 +494,13 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
polyhedron_demo_plugin(shortest_path_plugin Polyhedron_demo_shortest_path_plugin ${shortestPathUI_FILES})
target_link_libraries(shortest_path_plugin scene_polyhedron_item scene_polylines_item scene_polyhedron_selection_item scene_polyhedron_shortest_path_item scene_basic_objects)
add_item(scene_group_item Scene_group_item.cpp)
qt5_wrap_ui( groupUI_FILES Polyhedron_demo_group_plugin.ui)
polyhedron_demo_plugin(group_plugin Polyhedron_demo_group_plugin ${groupUI_FILES})
target_link_libraries(group_plugin scene_group_item)
#
# Exporting
#

View File

@ -159,9 +159,9 @@ MainWindow::MainWindow(QWidget* parent)
// setup the sceneview: delegation and columns sizing...
sceneView->setItemDelegate(delegate);
/* sceneView->header()->setStretchLastSection(false);
sceneView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch);
sceneView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch);
//sceneView->header()->setStretchLastSection(false);
/* sceneView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch);
sceneView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch);
sceneView->header()->setSectionResizeMode(Scene::ColorColumn, QHeaderView::ResizeToContents);
sceneView->header()->setSectionResizeMode(Scene::RenderingModeColumn, QHeaderView::Fixed);
sceneView->header()->setSectionResizeMode(Scene::ABColumn, QHeaderView::Fixed);
@ -1290,7 +1290,6 @@ bool MainWindow::on_actionErase_triggered()
{
int next_index = scene->erase(scene->selectionIndices());
selectSceneItem(next_index);
qDebug()<<"Remaining values : "<<scene->index_map.values();
return next_index >= 0;
}

View File

@ -0,0 +1,85 @@
#include "Polyhedron_demo_group_plugin.h"
#include "Polyhedron_demo_group_plugin.moc"
#include "Scene.h"
/**********
* Models *
**********/
QVariant GroupModel::data(const QModelIndex &index, int role) const
{
if(index.row()<0 || index.row()>groups().size())
return QVariant();
if(role != Qt::DisplayRole)
return QVariant();
return groups()[index.row()]->name();
}
QVariant ItemsModel::data(const QModelIndex &index, int role) const
{
if(index.row()<0 || index.row() > items().size())
return QVariant();
if(role != Qt::DisplayRole)
return QVariant();
return items()[index.row()]->name();
}
/****************
* Group Plugin *
****************/
void Polyhedron_demo_group_plugin::init(QMainWindow* mainWindow,
Scene_interface* scene_interface) {
//get the references
Scene* trueScene = dynamic_cast<Scene*>(scene_interface);
this->scene = scene_interface;
this->mw = mainWindow;
group_model = new GroupModel(trueScene);
items_model = new ItemsModel(trueScene);
//creates and link the actions
actionAddToGroup= new QAction("Add to group", mw);
if(actionAddToGroup) {
connect(actionAddToGroup, SIGNAL(triggered()),
this, SLOT(draw_triangle()));
}
}
void Polyhedron_demo_group_plugin::GroupChoice()
{
Polyhedron_demo_group_plugin_dialog *dialog = new Polyhedron_demo_group_plugin_dialog(this);
dialog->show();
}
/****************
* Dialog Class *
****************/
Polyhedron_demo_group_plugin_dialog::Polyhedron_demo_group_plugin_dialog( Polyhedron_demo_group_plugin *p_plugin)
{
m_plugin= p_plugin;
setupUi(this);
itemsView->setModel(m_plugin->items_model);
groupsView->setModel(m_plugin->group_model);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(selected_scene_items()));
}
void Polyhedron_demo_group_plugin_dialog::selected_scene_items()
{
QModelIndexList selectedRows = itemsView->selectionModel()->selectedIndexes();
QModelIndex selectedGroup= groupsView->selectionModel()->selectedIndexes().first();
Q_FOREACH(QModelIndex index, selectedRows)
{
m_plugin->selected_items << m_plugin->items_model->items()[index.row()];
}
m_plugin->selected_group = m_plugin->group_model->groups()[selectedGroup.row()];
m_plugin->add_to_group();
}

View File

@ -0,0 +1,117 @@
#ifndef POLYHEDRON_DEMO_GROUP_H
#define POLYHEDRON_DEMO_GROUP_H
#include <QApplication>
#include <QMainWindow>
#include <QAction>
#include <QList>
#include <QAbstractListModel>
#include "Scene_group_item.h"
#include "CGAL_demo/Scene_interface.h"
#include "ui_Polyhedron_demo_group_plugin.h"
#include "Scene.h"
class Scene_interface;
class GroupModel : public QAbstractListModel
{
public:
GroupModel(Scene* scene)
{
data_pool = scene;
}
QVariant data(const QModelIndex &index, int role) const;
int rowCount(const QModelIndex &parent) const
{
return data_pool->group_entries().size();
}
QList<Scene_group_item*> groups() const
{
return data_pool->group_entries();
}
private:
Scene* data_pool;
};
class ItemsModel : public QAbstractListModel
{
public:
ItemsModel(Scene* scene)
{
data_pool = scene;
}
QVariant data(const QModelIndex &index, int role) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const
{
Q_UNUSED(parent);
return data_pool->item_entries().size();
}
QList<Scene_item*> items() const
{
return data_pool->item_entries();
}
private:
Scene* data_pool;
};
#include "Polyhedron_demo_plugin_helper.h"
class Polyhedron_demo_group_plugin :
public QObject,
public Polyhedron_demo_plugin_helper
{
//Configures CMake to use MOC correctly
Q_OBJECT
Q_INTERFACES(Polyhedron_demo_plugin_interface)
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0")
public :
// To silent a warning -Woverloaded-virtual
// See http://stackoverflow.com/questions/9995421/gcc-woverloaded-virtual-warnings
using Polyhedron_demo_plugin_helper::init;
void init(QMainWindow* mainWindow,
Scene_interface* scene_interface);
bool applicable(QAction*) const
{
return true;
}
QList<QAction*> actions() const {
return QList<QAction*>() << actionAddToGroup;
}
GroupModel *group_model;
ItemsModel *items_model;
void add_to_group() {
Q_FOREACH(Scene_item* item, selected_items)
selected_group->addChild(item);
}
QList<Scene_item*> selected_items;
Scene_group_item* selected_group;
public Q_SLOTS:
void GroupChoice();
private:
QAction* actionAddToGroup;
}; //end of class Polyhedron_demo_group_plugin
class Polyhedron_demo_group_plugin_dialog : public QDialog, private Ui::GroupDialog
{
Q_OBJECT
public:
Polyhedron_demo_group_plugin_dialog(Polyhedron_demo_group_plugin *p_plugin);
public Q_SLOTS:
void selected_scene_items();
private :
Polyhedron_demo_group_plugin * m_plugin;
};
#endif

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GroupDialog</class>
<widget class="QDialog" name="GroupDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>30</x>
<y>240</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
<x>9</x>
<y>9</y>
<width>371</width>
<height>211</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListView" name="itemsView"/>
</item>
<item>
<widget class="QListView" name="groupsView"/>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>GroupDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>GroupDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -13,7 +13,7 @@ class QMainWindow;
class QDockWidget;
#include "Polyhedron_demo_plugin_interface.h"
#include "Scene_interface.h"
#include "CGAL_demo/Scene_interface.h"
class SCENE_ITEM_EXPORT Polyhedron_demo_plugin_helper
: public Polyhedron_demo_plugin_interface

View File

@ -4,7 +4,6 @@
#include "config.h"
#include "Scene.h"
#include "Scene_item.h"
#include <QObject>
#include <QMetaObject>
@ -888,7 +887,15 @@ Scene::Bbox Scene::bbox() const
}
return bbox;
}
QList<Scene_group_item*> Scene::group_entries() const
{
return m_group_entries;
}
QList<Scene_item*> Scene::item_entries() const
{
return m_entries;
}
#include "Scene_find_items.h"
namespace scene { namespace details {

View File

@ -2,10 +2,8 @@
#define SCENE_H
#include "config.h"
#include "Scene_config.h"
#include "Scene_interface.h"
#include "Scene_draw_interface.h"
#include <QtOpenGL/qgl.h>
#include <QStandardItemModel>
#include <QString>
@ -21,6 +19,7 @@
#include <cmath>
#include <boost/variant.hpp>
#include "Scene_item.h"
#include "Scene_group_item.h"
class QEvent;
class QMouseEvent;
namespace GlSplat { class SplatRenderer; }
@ -108,8 +107,8 @@ public:
QVariant headerData ( int section, ::Qt::Orientation orientation, int role = ::Qt::DisplayRole ) const;
::Qt::ItemFlags flags ( const QModelIndex & index ) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
QList<Scene_group_item*> group_entries() const ;
QList<Scene_item*> item_entries() const ;
// auxiliary public function for QMainWindow
QItemSelection createSelection(int i);
QItemSelection createSelectionAll();
@ -176,6 +175,7 @@ private:
QStandardItem* viewItem;
typedef QList<Scene_item*> Entries;
Entries m_entries;
QList<Scene_group_item*> m_group_entries;
int selected_item;
QList<int> selected_items_list;
int item_A;

View File

@ -0,0 +1,72 @@
#include "Scene_group_item.h"
Scene_group_item::Scene_group_item()
: Scene_item(0,0)
{}
bool Scene_group_item::isFinite() const
{
Q_FOREACH(Scene_item *item, children)
if(!item->isFinite()){
return false;
}
return true;
}
bool Scene_group_item::isEmpty() const {
Q_FOREACH(Scene_item *item, children)
if(!item->isEmpty()){
return false;
}
return true;
}
Scene_group_item::Bbox Scene_group_item::bbox() const
{
double xmax=0, ymax=0, zmax=0;
double xmin=0, ymin=0, zmin=0;
if(!children.isEmpty())
{
xmax = children.first()->bbox().xmax; ymax = children.first()->bbox().ymax; zmax = children.first()->bbox().zmax;
xmin = children.first()->bbox().xmin; ymin = children.first()->bbox().ymin; zmin = children.first()->bbox().zmin;
}
Q_FOREACH(Scene_item* item, children)
{
xmax = std::max(xmax,item->bbox().xmax); ymax = std::max(ymax, item->bbox().ymax); zmax = std::max(zmax, item->bbox().zmax);
xmin = std::min(xmin, item->bbox().xmin); ymin = std::min(ymin,item->bbox().ymin); zmin = std::min(zmin,item->bbox().zmin);
}
return Bbox(xmin, ymin, zmin, xmax, ymax, zmax);
}
bool Scene_group_item::supportsRenderingMode(RenderingMode m) const {
Q_FOREACH(Scene_item* item, children)
if(!item->supportsRenderingMode(m))
return false;
return !children.isEmpty();
}
QString Scene_group_item::toolTip() const {
QString str =
QObject::tr( "<p>Number of children: %1<br />").arg(children.size());
str+="</p>";
str += QString("Bounding box: min (%1,%2,%3), max(%4,%5,%6)")
.arg(bbox().xmin)
.arg(bbox().ymin)
.arg(bbox().zmin)
.arg(bbox().xmax)
.arg(bbox().ymax)
.arg(bbox().zmax);
return str;
}
void Scene_group_item::addChild(Scene_item* new_item)
{
if(!children.contains(new_item))
children.append(new_item);
else
print_message("Item is already in group.");
}

View File

@ -0,0 +1,36 @@
#ifndef SCENE_GROUP_ITEM_H
#define SCENE_GROUP_ITEM_H
#include "Scene_item.h"
#include "Messages_interface.h"
class Q_DECL_EXPORT Scene_group_item : public Scene_item
{
Q_OBJECT
public :
Scene_group_item();
~Scene_group_item() {}
bool isFinite() const;
bool isEmpty() const ;
Bbox bbox() const;
Scene_group_item* clone() const {return 0;}
//! Indicate if rendering mode is supported.
bool supportsRenderingMode(RenderingMode m) const;
QString toolTip() const;
void addChild(Scene_item* new_item);
private:
QList<Scene_item*> children;
void print_message(QString message) { messages->information(message); }
Messages_interface* messages;
}; //end of class Scene_group_item
#endif // SCENE_GROUP_ITEM_H