mirror of https://github.com/CGAL/cgal
intial version of Qt4 based Snaprounding demo
This commit is contained in:
parent
ba741338c6
commit
7e26a61cf4
|
|
@ -1445,6 +1445,9 @@ GraphicsView/demo/Segment_Delaunay_graph_2/icons/moving_point.pdf -text
|
|||
GraphicsView/demo/Segment_Delaunay_graph_2/icons/moving_point.png -text
|
||||
GraphicsView/demo/Segment_Delaunay_graph_2/icons/triangulation.pdf -text
|
||||
GraphicsView/demo/Segment_Delaunay_graph_2/icons/triangulation.png -text
|
||||
GraphicsView/demo/Snap_rounding_2/Snap_rounding_2.qrc -text
|
||||
GraphicsView/demo/Snap_rounding_2/Snap_rounding_2.ui -text
|
||||
GraphicsView/demo/Snap_rounding_2/about_Snap_rounding_2.html svneol=native#text/html
|
||||
GraphicsView/demo/Stream_lines_2/Stream_lines_2.qrc -text
|
||||
GraphicsView/demo/Stream_lines_2/Stream_lines_2.ui -text
|
||||
GraphicsView/demo/Stream_lines_2/about_Stream_lines_2.html svneol=native#text/html
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
# Created by the script cgal_create_cmake_script
|
||||
# This is the CMake script for compiling a CGAL application.
|
||||
|
||||
project (Snap_rounding_2_demo)
|
||||
|
||||
cmake_minimum_required(VERSION 2.4.5)
|
||||
|
||||
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
|
||||
|
||||
if ( COMMAND cmake_policy )
|
||||
cmake_policy( SET CMP0003 NEW )
|
||||
endif()
|
||||
|
||||
find_package(CGAL COMPONENTS Qt4)
|
||||
|
||||
include(${CGAL_USE_FILE})
|
||||
|
||||
set( QT_USE_QTXML TRUE )
|
||||
set( QT_USE_QTMAIN TRUE )
|
||||
set( QT_USE_QTSCRIPT TRUE )
|
||||
set( QT_USE_QTOPENGL TRUE )
|
||||
|
||||
|
||||
find_package(Qt4)
|
||||
include_directories (BEFORE ../../include)
|
||||
include_directories (BEFORE ../../../Snap_rounding_2/include)
|
||||
|
||||
|
||||
if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND )
|
||||
|
||||
include(${QT_USE_FILE})
|
||||
|
||||
#--------------------------------
|
||||
# UI files (Qt Designer files)
|
||||
qt4_wrap_ui( DT_UI_FILES Snap_rounding_2.ui )
|
||||
|
||||
# qrc files (resources files, that contain icons, at least)
|
||||
qt4_add_resources ( DT_RESOURCE_FILES ./Snap_rounding_2.qrc )
|
||||
|
||||
# use the Qt MOC preprocessor on classes that derives from QObject
|
||||
qt4_generate_moc( Snap_rounding_2.cpp Snap_rounding_2.moc )
|
||||
|
||||
# The executable itself.
|
||||
add_executable ( Snap_rounding_2 Snap_rounding_2.cpp Snap_rounding_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} )
|
||||
|
||||
add_to_cached_list( CGAL_EXECUTABLE_TARGETS Snap_rounding_2 )
|
||||
|
||||
# Link with Qt libraries
|
||||
target_link_libraries( Snap_rounding_2 ${QT_LIBRARIES} )
|
||||
# Link with CGAL
|
||||
target_link_libraries( Snap_rounding_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES})
|
||||
|
||||
else()
|
||||
|
||||
message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.")
|
||||
|
||||
endif()
|
||||
|
|
@ -0,0 +1,291 @@
|
|||
#include <fstream>
|
||||
|
||||
// CGAL headers
|
||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
#include <CGAL/Snap_rounding_traits_2.h>
|
||||
#include <CGAL/Snap_rounding_2.h>
|
||||
#include <CGAL/Snap_rounding_traits_2.h>
|
||||
|
||||
// Qt headers
|
||||
#include <QtGui>
|
||||
#include <QString>
|
||||
#include <QActionGroup>
|
||||
#include <QFileDialog>
|
||||
#include <QInputDialog>
|
||||
|
||||
// GraphicsView items and event filters (input classes)
|
||||
#include <CGAL/Qt/RegularGridGraphicsItem.h>
|
||||
#include <CGAL/Qt/SegmentsGraphicsItem.h>
|
||||
#include <CGAL/Qt/PolylinesGraphicsItem.h>
|
||||
#include <CGAL/Qt/GraphicsViewPolylineInput.h>
|
||||
|
||||
// for viewportsBbox
|
||||
#include <CGAL/Qt/utility.h>
|
||||
|
||||
// the two base classes
|
||||
#include "ui_Snap_rounding_2.h"
|
||||
#include <CGAL/Qt/DemosMainWindow.h>
|
||||
|
||||
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
|
||||
typedef CGAL::Snap_rounding_traits_2<K> Traits;
|
||||
|
||||
typedef K::Point_2 Point_2;
|
||||
typedef K::Segment_2 Segment_2;
|
||||
typedef K::Iso_rectangle_2 Iso_rectangle_2;
|
||||
|
||||
|
||||
|
||||
class MainWindow :
|
||||
public CGAL::Qt::DemosMainWindow,
|
||||
public Ui::Snap_rounding_2
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
||||
QGraphicsScene scene;
|
||||
|
||||
CGAL::Qt::RegularGridGraphicsItem<K> * rgi;
|
||||
|
||||
CGAL::Qt::GraphicsViewPolylineInput<K> * pi;
|
||||
|
||||
std::list<Segment_2> input;
|
||||
std::list<std::list<Point_2> > output;
|
||||
|
||||
typedef CGAL::Qt::SegmentsGraphicsItem<std::list<Segment_2> > InputSegmentsGraphicsItem;
|
||||
typedef CGAL::Qt::PolylinesGraphicsItem<std::list<std::list<Point_2> > > OutputPolylinesGraphicsItem;
|
||||
InputSegmentsGraphicsItem * isgi;
|
||||
OutputPolylinesGraphicsItem *plgi;
|
||||
double delta;
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
|
||||
public slots:
|
||||
|
||||
void processInput(CGAL::Object o);
|
||||
|
||||
void on_actionLoadPoints_triggered();
|
||||
|
||||
void on_actionClear_triggered();
|
||||
|
||||
void on_actionSavePoints_triggered();
|
||||
|
||||
void on_actionGenerate_triggered();
|
||||
|
||||
void on_actionRecenter_triggered();
|
||||
|
||||
virtual void open(QString fileName);
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
};
|
||||
|
||||
|
||||
MainWindow::MainWindow()
|
||||
: DemosMainWindow(), delta(1.0)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
this->graphicsView->setAcceptDrops(false);
|
||||
|
||||
isgi = new InputSegmentsGraphicsItem(&input);
|
||||
scene.addItem(isgi);
|
||||
|
||||
plgi = new OutputPolylinesGraphicsItem(&output);
|
||||
scene.addItem(plgi);
|
||||
|
||||
// inputs polylines with 2 points
|
||||
pi = new CGAL::Qt::GraphicsViewPolylineInput<K>(this, &scene, 2, false);
|
||||
QObject::connect(pi, SIGNAL(generate(CGAL::Object)),
|
||||
this, SLOT(processInput(CGAL::Object)));
|
||||
|
||||
scene.installEventFilter(pi);
|
||||
|
||||
// Manual handling of actions
|
||||
//
|
||||
|
||||
QObject::connect(this->actionQuit, SIGNAL(triggered()),
|
||||
this, SLOT(close()));
|
||||
|
||||
//
|
||||
// Setup the scene and the view
|
||||
//
|
||||
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||
scene.setSceneRect(-50, -50, 50, 50);
|
||||
this->graphicsView->setScene(&scene);
|
||||
|
||||
// Turn the vertical axis upside down
|
||||
this->graphicsView->matrix().scale(1, -1);
|
||||
this->graphicsView->setMouseTracking(true);
|
||||
|
||||
rgi = new CGAL::Qt::RegularGridGraphicsItem<K>(delta, delta);
|
||||
|
||||
QObject::connect(this, SIGNAL(changed()),
|
||||
rgi, SLOT(modelChanged()));
|
||||
|
||||
QObject::connect(this, SIGNAL(changed()),
|
||||
isgi, SLOT(modelChanged()));
|
||||
|
||||
QObject::connect(this, SIGNAL(changed()),
|
||||
plgi, SLOT(modelChanged()));
|
||||
|
||||
|
||||
rgi->setVerticesPen(QPen(Qt::red, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
rgi->setEdgesPen(QPen(Qt::gray, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
scene.addItem(rgi);
|
||||
|
||||
plgi->setEdgesPen(QPen(Qt::blue, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
scene.addItem(plgi);
|
||||
|
||||
|
||||
// The navigation adds zooming and translation functionality to the
|
||||
// QGraphicsView
|
||||
this->addNavigation(this->graphicsView);
|
||||
|
||||
this->setupStatusBar();
|
||||
this->setupOptionsMenu();
|
||||
this->addAboutDemo(":/cgal/help/about_Snap_rounding_2.html");
|
||||
this->addAboutCGAL();
|
||||
|
||||
this->addRecentFiles(this->menuFile, this->actionQuit);
|
||||
connect(this, SIGNAL(openRecentFile(QString)),
|
||||
this, SLOT(open(QString)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
MainWindow::processInput(CGAL::Object o)
|
||||
{
|
||||
|
||||
std::list<Point_2> points;
|
||||
if(CGAL::assign(points, o)){
|
||||
if(points.size() == 2) {
|
||||
input.push_back(Segment_2(points.front(), points.back()));
|
||||
output.clear();
|
||||
CGAL::snap_rounding_2<Traits,std::list<Segment_2>::const_iterator,std::list<std::list<Point_2> > >(input.begin(), input.end(), output, delta, true, false);
|
||||
}
|
||||
else {
|
||||
std::cerr << points.size() << std::endl;
|
||||
}
|
||||
}
|
||||
emit(changed());
|
||||
}
|
||||
|
||||
/*
|
||||
* Qt Automatic Connections
|
||||
* http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections
|
||||
*
|
||||
* setupUi(this) generates connections to the slots named
|
||||
* "on_<action_name>_<signal_name>"
|
||||
*/
|
||||
|
||||
|
||||
void
|
||||
MainWindow::on_actionClear_triggered()
|
||||
{
|
||||
emit(changed());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWindow::on_actionGenerate_triggered()
|
||||
{
|
||||
on_actionRecenter_triggered();
|
||||
emit(changed());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
MainWindow::on_actionLoadPoints_triggered()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this,
|
||||
tr("Open grid file"),
|
||||
".");
|
||||
if(! fileName.isEmpty()){
|
||||
open(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWindow::open(QString fileName)
|
||||
{
|
||||
#if 0
|
||||
// wait cursor
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
std::ifstream ifs(qPrintable(fileName));
|
||||
|
||||
runge_kutta_integrator = new Runge_kutta_integrator(integrating);
|
||||
double iXSize, iYSize;
|
||||
iXSize = iYSize = 512;
|
||||
unsigned int x_samples, y_samples;
|
||||
ifs >> x_samples;
|
||||
ifs >> y_samples;
|
||||
regular_grid = new Regular_grid(x_samples, y_samples, iXSize, iYSize);
|
||||
/*fill the grid with the appropreate values*/
|
||||
for (unsigned int i=0;i<x_samples;i++)
|
||||
for (unsigned int j=0;j<y_samples;j++)
|
||||
{
|
||||
double xval, yval;
|
||||
ifs >> xval;
|
||||
ifs >> yval;
|
||||
regular_grid->set_field(i, j, Vector(xval, yval));
|
||||
}
|
||||
ifs.close();
|
||||
// default cursor
|
||||
QApplication::restoreOverrideCursor();
|
||||
this->addToRecentFiles(fileName);
|
||||
// actionRecenter->trigger();
|
||||
on_actionGenerate_triggered();
|
||||
emit(changed());
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::on_actionSavePoints_triggered()
|
||||
{
|
||||
/*
|
||||
QString fileName = QFileDialog::getSaveFileName(this,
|
||||
tr("Save points"),
|
||||
".");
|
||||
if(! fileName.isEmpty()){
|
||||
std::ofstream ofs(qPrintable(fileName));
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWindow::on_actionRecenter_triggered()
|
||||
{
|
||||
this->graphicsView->setSceneRect(isgi->boundingRect());
|
||||
this->graphicsView->fitInView(isgi->boundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
|
||||
#include "Snap_rounding_2.moc"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
app.setOrganizationDomain("geometryfactory.com");
|
||||
app.setOrganizationName("GeometryFactory");
|
||||
app.setApplicationName("Snap_rounding_2 demo");
|
||||
|
||||
// Import resources from libCGALQt4.
|
||||
// See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE
|
||||
Q_INIT_RESOURCE(File);
|
||||
Q_INIT_RESOURCE(Snap_rounding_2);
|
||||
Q_INIT_RESOURCE(Input);
|
||||
Q_INIT_RESOURCE(CGAL);
|
||||
|
||||
MainWindow mainWindow;
|
||||
mainWindow.show();
|
||||
return app.exec();
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<RCC>
|
||||
<qresource prefix="/cgal/Actions" >
|
||||
</qresource>
|
||||
<qresource prefix="/cgal/help" >
|
||||
<file alias="about_CGAL.html" >../resources/about_CGAL.html</file>
|
||||
<file>about_Snap_rounding_2.html</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<author>GeometryFactory</author>
|
||||
<class>Snap_rounding_2</class>
|
||||
<widget class="QMainWindow" name="Snap_rounding_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>CGAL Snaprounding</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../resources/CGAL.qrc">
|
||||
<normaloff>:/cgal/logos/cgal_icon</normaloff>:/cgal/logos/cgal_icon</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGraphicsView" name="graphicsView">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
<property name="transformationAnchor">
|
||||
<enum>QGraphicsView::NoAnchor</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<widget class="QToolBar" name="fileToolBar">
|
||||
<property name="windowTitle">
|
||||
<string>File Tools</string>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="actionClear"/>
|
||||
<addaction name="actionLoadPoints"/>
|
||||
<addaction name="actionSavePoints"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="toolBar">
|
||||
<property name="windowTitle">
|
||||
<string>Visualization Tools</string>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="actionRecenter"/>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>&File</string>
|
||||
</property>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionClear"/>
|
||||
<addaction name="actionLoadPoints"/>
|
||||
<addaction name="actionSavePoints"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionQuit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuEdit">
|
||||
<property name="title">
|
||||
<string>&Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuTools">
|
||||
<property name="title">
|
||||
<string>&Tools</string>
|
||||
</property>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionRecenter"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuEdit"/>
|
||||
<addaction name="menuTools"/>
|
||||
</widget>
|
||||
<action name="actionAbout">
|
||||
<property name="text">
|
||||
<string>&About</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAboutCGAL">
|
||||
<property name="text">
|
||||
<string>About &CGAL</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionQuit">
|
||||
<property name="text">
|
||||
<string>&Quit</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Q</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionClear">
|
||||
<property name="icon">
|
||||
<iconset resource="../icons/File.qrc">
|
||||
<normaloff>:/cgal/fileToolbar/fileNew.png</normaloff>:/cgal/fileToolbar/fileNew.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Clear</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+C</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLoadPoints">
|
||||
<property name="icon">
|
||||
<iconset resource="../icons/File.qrc">
|
||||
<normaloff>:/cgal/fileToolbar/fileOpen.png</normaloff>:/cgal/fileToolbar/fileOpen.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Load Points...</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+L</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSavePoints">
|
||||
<property name="icon">
|
||||
<iconset resource="../icons/File.qrc">
|
||||
<normaloff>:/cgal/fileToolbar/fileSave.png</normaloff>:/cgal/fileToolbar/fileSave.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Save Points...</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+S</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRecenter">
|
||||
<property name="icon">
|
||||
<iconset resource="../icons/Input.qrc">
|
||||
<normaloff>:/cgal/Input/zoom-best-fit</normaloff>:/cgal/Input/zoom-best-fit</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Re&center the viewport</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+R</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="Snap_rounding_2.qrc"/>
|
||||
<include location="../icons/File.qrc"/>
|
||||
<include location="../resources/CGAL.qrc"/>
|
||||
<include location="../icons/Input.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<html>
|
||||
<body>
|
||||
<h2>Snap Rounding</h2>
|
||||
<p>Copyright © 2010 GeometryFactory</p>
|
||||
<p>This application illustrates the 2D Snap Rounding.</p>
|
||||
<p>See also <a href="http://www.cgal.org/Pkg/SnapRounding2">the online
|
||||
manual</a>.</p>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue