Move packages to trunk root
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
First tutorial
|
||||
-----------------
|
||||
|
||||
In this tutorial you can see how can you use Qt_widget like a stream,
|
||||
for outputing Cgal objects. Of course I recomend to read the tutorial
|
||||
from Trolltech, that is the original Qt tutorial, but I think that you
|
||||
can pass this tutorials without having strong skills of Qt
|
||||
programming. Anyway, the code that belongs to Qt it is explained in
|
||||
this tutorials.
|
||||
|
||||
The following is a typical template of how to create a window using Qt
|
||||
and Qt_widget.
|
||||
|
||||
#include <CGAL/IO/Qt_widget.h>
|
||||
#include <qapplication.h>
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
QApplication app( argc, argv );
|
||||
CGAL::Qt_widget * W = new CGAL::Qt_widget();
|
||||
app.setMainWidget( W );
|
||||
W.resize(600, 600);
|
||||
W.set_window(0, 600, 0, 600);
|
||||
W.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
You'll allways need to include the header:
|
||||
|
||||
#include <qapplication.h>
|
||||
|
||||
The entry point for a typical Qt application is the function main. In
|
||||
this function you should define an application object of Qt:
|
||||
|
||||
QApplication app( argc, argv );
|
||||
|
||||
You will run the Qt application with the line:
|
||||
|
||||
return app.exec();
|
||||
|
||||
To use Qt_widget you need an instance and tell the application to use
|
||||
that instance:
|
||||
|
||||
CGAL::Qt_widget *W = new CGAL::Qt_widget();
|
||||
app.setMainWidget( W );
|
||||
|
||||
To resize and set the scales of the window you'll use:
|
||||
|
||||
W->resize(600, 600);
|
||||
W->set_window(0, 600, 0, 600);
|
||||
|
||||
At the end you need to show the window when the initialization have been done:
|
||||
|
||||
W->show();
|
||||
|
||||
All the drawing code should be put betwen Qt_Widget's lock() and
|
||||
unlock() functions. See the manual reference pages of Qt_widget. Doing
|
||||
like this, the window will be updated only once, when Qt_widget find
|
||||
the last unlock(). This way you can avoid the window flickering.
|
||||
|
||||
As you'll notice, this tutorial has some limitations. If you try to
|
||||
resize the window you'll see that what you have been painted will
|
||||
disappear. This is not a very pleasant thing but you'll see in the
|
||||
next tutorial how you can solve this problem.
|
||||
|
||||
Applications following this approach are only usefull when you quickly
|
||||
want to see how the output of a computation looks like.
|
||||
@@ -0,0 +1,48 @@
|
||||
# Created by the script create_makefile
|
||||
# This is the makefile for compiling a CGAL application.
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# include platform specific settings
|
||||
#---------------------------------------------------------------------#
|
||||
# Choose the right include file from the <cgalroot>/make directory.
|
||||
|
||||
# CGAL_MAKEFILE = ENTER_YOUR_INCLUDE_MAKEFILE_HERE
|
||||
include $(CGAL_MAKEFILE)
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# compiler flags
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
CXXFLAGS = -I../../../../include/ \
|
||||
$(CGAL_CXXFLAGS) \
|
||||
$(LONG_NAME_PROBLEM_CXXFLAGS) \
|
||||
$(DEBUG_OPT)
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# linker flags
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
LIBPATH = \
|
||||
$(CGAL_LIB_DIR)
|
||||
|
||||
LDFLAGS = \
|
||||
$(LONG_NAME_PROBLEM_LDFLAGS) \
|
||||
$(CGAL_QT_LDFLAGS)
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# target entries
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
all: tutorial1$(EXE_EXT)
|
||||
|
||||
tutorial1$(EXE_EXT): tutorial1$(OBJ_EXT)
|
||||
$(CGAL_CXX) $(EXE_OPT)tutorial1 tutorial1$(OBJ_EXT) $(LDFLAGS)
|
||||
|
||||
clean: tutorial1.clean
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# suffix rules
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
.C$(OBJ_EXT):
|
||||
$(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) $<
|
||||
@@ -0,0 +1,71 @@
|
||||
//demo/Qt_widget/basic/tutorial1/tutorial1.C
|
||||
#ifndef CGAL_USE_QT
|
||||
#include <iostream>
|
||||
int main(int, char*){
|
||||
std::cout << "Sorry, this demo needs QT..." << std::endl; return 0;}
|
||||
#else
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/Bbox_2.h>
|
||||
#include <list>
|
||||
#include <CGAL/Polygon_2.h>
|
||||
#include <CGAL/IO/Qt_widget_Polygon_2.h>
|
||||
#include <qapplication.h>
|
||||
#include <CGAL/IO/Qt_widget.h>
|
||||
|
||||
typedef CGAL::Cartesian<int> Rep;
|
||||
typedef CGAL::Point_2<Rep> Point;
|
||||
typedef CGAL::Circle_2<Rep> Circle;
|
||||
typedef CGAL::Segment_2<Rep> Segment;
|
||||
typedef CGAL::Line_2<Rep> Line;
|
||||
typedef CGAL::Ray_2<Rep> Ray;
|
||||
typedef CGAL::Triangle_2<Rep> Triangle;
|
||||
typedef CGAL::Iso_rectangle_2<Rep>
|
||||
Cgal_Rectangle;
|
||||
typedef CGAL::Bbox_2 BBox;
|
||||
typedef std::list<Point> Container;
|
||||
typedef CGAL::Polygon_2<Rep,Container>
|
||||
Cgal_Polygon;
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
QApplication app( argc, argv );
|
||||
using namespace CGAL;
|
||||
CGAL::Qt_widget * W = new CGAL::Qt_widget();
|
||||
app.setMainWidget( W );
|
||||
W->resize(600, 600);
|
||||
W->set_window(0, 600, 0, 600);
|
||||
W->show();
|
||||
//painting something on the screen
|
||||
W->lock();
|
||||
|
||||
*W << BackgroundColor(ORANGE) << RED <<
|
||||
LineWidth(3) << PointSize(3) << PointStyle(DISC);
|
||||
*W << Segment(Point(10,20),Point(300,400));
|
||||
*W << LineWidth(5) << GREEN << FillColor(BLACK) <<
|
||||
Circle(Point(400,400),50*50);
|
||||
*W << LineWidth(1) << noFill << Circle(Point(300,300),300*300);
|
||||
*W << BLUE << LineWidth(2);
|
||||
*W << Segment(Point(200,200),Point(400,400));
|
||||
*W << Segment(Point(200,400),Point(400,200));
|
||||
W->setFilled(TRUE);
|
||||
*W << RED << Triangle(Point(150,300),
|
||||
Point(150,350),
|
||||
Point(100,325));
|
||||
*W << FillColor(RED) << Cgal_Rectangle(Point(320,220),
|
||||
Point(350,240));
|
||||
*W << DEEPBLUE << BBox(100,80,260,140);
|
||||
Cgal_Polygon p;
|
||||
p.push_back(Point(300,30));
|
||||
p.push_back(Point(400,30));
|
||||
p.push_back(Point(500,130));
|
||||
p.push_back(Point(400,180));
|
||||
p.push_back(Point(300,130));
|
||||
*W << p;
|
||||
*W << Ray(Point(200,400), Point(180,430))
|
||||
<< Ray(Point(200,400), Point(180,370));
|
||||
W->unlock();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user