Radu Ursu 14-01-2002

This commit is contained in:
Radu Ursu 2002-01-15 17:24:52 +00:00
parent 8c4730544a
commit 01007d2528
19 changed files with 148 additions and 82 deletions

View File

@ -24,12 +24,14 @@
#include "Qt_widget_toolbar.h"
// icons
#include <CGAL/IO/pixmaps/movepoint.xpm>
#include <CGAL/IO/pixmaps/point.xpm>
#include <CGAL/IO/pixmaps/arrow.xpm>
namespace CGAL {
Tools_toolbar::Tools_toolbar(Qt_widget *w, QMainWindow *mw)
Tools_toolbar::Tools_toolbar(Qt_widget *w, QMainWindow *mw, std::list<Point> &l1) :
my_toolbar_list(l1)
{
//when it is created, the toolbar has 0 buttons
nr_of_buttons = 0;
@ -63,10 +65,19 @@ namespace CGAL {
maintoolbar,
"Point Tool");
but[2] = new QToolButton(QPixmap( (const char**)movepoint_xpm ),
"Move selected point",
0,
this,
SLOT(movepoint()),
maintoolbar,
"Move point");
but[1]->setToggleButton(TRUE);
nr_of_buttons = 2;
but[2]->setToggleButton(TRUE);
nr_of_buttons = 3;
connect(w, SIGNAL(detached_tool()), this, SLOT(toggle_button()));
};
@ -96,6 +107,22 @@ namespace CGAL {
widget->detach_current_tool();
}
}
void Tools_toolbar::movepoint()
{
if (but[2]->isOn())
{
widget->attach(movepointbut);
movepointbut.set_list(my_toolbar_list);
activebutton = 2;
is_active = true;
}
else
{
is_active = false;
widget->detach_current_tool();
}
}
void Tools_toolbar::notool()
{
if(is_active) {

View File

@ -24,20 +24,20 @@
#include <CGAL/basic.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Delaunay_triangulation_2.h>
// TODO: check if some of those includes shouldn't be in the .C file
#include <CGAL/IO/Qt_Widget.h>
#include <CGAL/IO/Qt_Widget_Get_point.h>
#include "Qt_Widget_MovePoint.h"
#include <qobject.h>
#include <qtoolbutton.h>
#include <qtoolbar.h>
#include <qmainwindow.h>
typedef double Coord_type;
typedef CGAL::Cartesian<Coord_type> Rp;
typedef CGAL::Cartesian<double> Rp;
typedef Rp::Point_2 Point;
namespace CGAL {
@ -45,7 +45,7 @@ class Tools_toolbar : public QObject
{
Q_OBJECT
public:
Tools_toolbar(Qt_widget *w, QMainWindow *mw);
Tools_toolbar(Qt_widget *w, QMainWindow *mw, std::list<Point> &l1);
~Tools_toolbar()
{
delete maintoolbar;
@ -59,6 +59,7 @@ signals:
private slots:
void get_new_object(CGAL::Object obj) { emit(new_object(obj)); }
void movepoint();
void pointtool();
void notool();
@ -71,10 +72,12 @@ private:
int activebutton;
bool is_active;
void setActiveButton(int i);
void addToolButton(QToolButton *b);
int nr_of_buttons;
std::list<Point> my_toolbar_list;
CGAL::Qt_widget_get_point<Rp> pointbut;
CGAL::Qt_widget_movepoint<Rp> movepointbut;
};//end class
};//end namespace

View File

@ -29,6 +29,7 @@ int main(int, char*)
#include <CGAL/IO/Qt_Widget.h>
#include "Qt_widget_toolbar.h"
#include <CGAL/IO/Qt_Widget_standard_toolbar.h>
#include <CGAL/IO/Qt_widget_view.h>
#include <qplatinumstyle.h>
#include <qapplication.h>
@ -56,6 +57,56 @@ const QString my_title_string("Convex_Hull_2 Demo with"
int current_state;
std::list<Point> list_of_points;
class Qt_view_show_ch : public CGAL::Qt_widget_view
{
public:
Qt_view_show_ch(){};
void draw_view(CGAL::Qt_widget &win)
{
win.lock();
win << CGAL::PointSize(7) << CGAL::PointStyle(CGAL::CROSS);
win << CGAL::GREEN;
std::list<Point>::iterator itp = list_of_points.begin();
while(itp!=list_of_points.end())
{
win << (*itp++);
}
std::list<Point> out;
std::list<Segment> Sl;
CGAL::convex_hull_points_2(list_of_points.begin(), list_of_points.end(), std::back_inserter(out));
if( out.size() > 1 ) {
Point pakt,prev,pstart;
std::list<Point>::const_iterator it;
it=out.begin();
prev= *it; pstart=prev;
it++;
for(; it != out.end(); ++it) {
pakt= *it;
Sl.push_back(Segment(prev,pakt));
prev=pakt;
}
Sl.push_back(Segment(pakt,pstart));
win << CGAL::RED;
std::list<Segment>::iterator its = Sl.begin();
while(its!=Sl.end())
{
win << (*its++);
}
}
win.unlock();
};
};//end class
class MyWindow : public QMainWindow
{
Q_OBJECT
@ -98,7 +149,7 @@ public:
//the new tools toolbar
setUsesBigPixmaps(TRUE);
newtoolbar = new CGAL::Tools_toolbar(&win, this);
newtoolbar = new CGAL::Tools_toolbar(&win, this, list_of_points);
//the standard toolbar
stoolbar = new CGAL::Standard_toolbar (&win, this);
this->addToolBar(stoolbar->toolbar(), Top, FALSE);
@ -119,6 +170,9 @@ public:
//application flag stuff
old_state = 0;
//views
win << &testview;
};
~MyWindow()
@ -146,44 +200,8 @@ public slots:
void redrawWin()
{
win.lock();
win << CGAL::PointSize(7) << CGAL::PointStyle(CGAL::CROSS);
win << CGAL::GREEN;
std::list<Point>::iterator itp = list_of_points.begin();
while(itp!=list_of_points.end())
{
win << (*itp++);
}
std::list<Point> out;
std::list<Segment> Sl;
CGAL::convex_hull_points_2(list_of_points.begin(), list_of_points.end(), std::back_inserter(out));
if( out.size() > 1 ) {
Point pakt,prev,pstart;
std::list<Point>::const_iterator it;
it=out.begin();
prev= *it; pstart=prev;
it++;
for(; it != out.end(); ++it) {
pakt= *it;
Sl.push_back(Segment(prev,pakt));
prev=pakt;
}
Sl.push_back(Segment(pakt,pstart));
win << CGAL::RED;
std::list<Segment>::iterator its = Sl.begin();
while(its!=Sl.end())
{
win << (*its++);
}
}
win.unlock();
}
private slots:
void get_new_object(CGAL::Object obj)
@ -267,6 +285,7 @@ private:
CGAL::Tools_toolbar *newtoolbar;
CGAL::Standard_toolbar *stoolbar;
int old_state;
Qt_view_show_ch testview;
};
#include "convex_hull_2.moc"

View File

@ -1,7 +1,7 @@
/****************************************************************************
** MyWindow meta object code from reading C++ file 'convex_hull_2.C'
**
** Created: Thu Jan 10 10:41:37 2002
** Created: Tue Jan 15 18:01:29 2002
** by: The Qt MOC ($Id$)
**
** WARNING! All changes made in this file will be lost!

View File

@ -113,6 +113,10 @@ SOURCE=..\..\..\src\Qt_Widget_tool.C
SOURCE=.\Qt_widget_toolbar.C
# End Source File
# Begin Source File
SOURCE=..\..\..\src\Qt_widget_view.C
# End Source File
# End Group
# Begin Group "Header Files"
@ -147,6 +151,21 @@ SOURCE=..\..\..\include\CGAL\IO\Qt_Widget_Handtool.h
# Begin Source File
SOURCE=.\Qt_Widget_MovePoint.h
!IF "$(CFG)" == "demo - Win32 Release"
!ELSEIF "$(CFG)" == "demo - Win32 Debug"
# Begin Custom Build
InputPath=.\Qt_Widget_MovePoint.h
"Qt_Widget_MovePoint.moc" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
$(QTDIR)\bin\moc.exe -o "Qt_Widget_MovePoint.moc" "Qt_Widget_MovePoint.h"
# End Custom Build
!ENDIF
# End Source File
# Begin Source File
@ -207,6 +226,10 @@ InputPath=.\Qt_widget_toolbar.h
# End Source File
# Begin Source File
SOURCE=..\..\..\include\CGAL\IO\Qt_widget_view.h
# End Source File
# Begin Source File
SOURCE=..\..\..\include\CGAL\IO\Qt_Widget_Zoom.h
# End Source File
# Begin Source File

View File

@ -32,14 +32,20 @@ public:
My_Window(int x, int y){ resize(x,y); };
private:
void redraw()
{
Qt_widget::redraw();
*this << dt;
}
//this event is called only when the user press mouse
void mousePressEvent(QMouseEvent *e)
{
clear();
Qt_widget::mousePressEvent(e);
dt.insert(Point(x_real(e->x()), y_real(e->y())));
*this << dt;
redraw();
//clear();
//*this << dt;
}
};
int main( int argc, char **argv )

View File

@ -77,13 +77,10 @@ public:
void unlock() { if (Locked>0) --Locked; do_paint(); };
void do_paint() { if (Locked==0) repaint( FALSE ); };
void show_scene(Qt_widget_view* s);
inline
Qt_widget& operator<<(Qt_widget_view* s)
{
add_scene(s);
show_scene(s);
add_view(s);
return *this;
};
@ -161,6 +158,7 @@ public:
Qt_widget& operator>>(Qt_widget_tool &tool);
*/
void new_object(CGAL::Object obj) { emit(new_cgal_object(obj)); };
virtual void redraw();
signals:
void mousePressed(QMouseEvent *e);
@ -190,13 +188,13 @@ public slots:
// ***** Should be call when:
// - an editable scene is changed (should be call by tools)
// - ranges are changed
void redraw();
//virtual void redraw();
// add a scene in the list of displayable scenes
void add_scene(Qt_widget_view* s);
void add_view(Qt_widget_view* s);
// remove a scene from the list of displayable scenes
void remove_scene(Qt_widget_view* s);
void remove_view(Qt_widget_view* s);
private:
void set_scales(); // set xscal and yscal

View File

@ -41,7 +41,7 @@ public:
Qt_view_show_greene_approx(T &p) : polygon(p)
{};
void draw_scene(Qt_widget &widget)
void draw_view(Qt_widget &widget)
{
greene_approx_polys.clear();
Traits partition_traits;

View File

@ -35,7 +35,7 @@ class Qt_view_mouse_coordinates : public Qt_widget_view
public:
Qt_view_mouse_coordinates(QMainWindow &mw) : qmw(mw){};
void draw_scene(Qt_widget &widget){};
void draw_view(Qt_widget &widget){};
void mouseMoveEvent(QMouseEvent *e, Qt_widget &widget)
{
char xsir[40], ysir[40], final[80];

View File

@ -40,7 +40,7 @@ public:
Qt_view_nearest_vertex(T &t) : first_time(TRUE), tr(t){};
void draw_scene(Qt_widget &widget){first_time = TRUE;};
void draw_view(Qt_widget &widget){first_time = TRUE;};
void mouseMoveEvent(QMouseEvent *e, Qt_widget &widget)
{
if (tr.dimension()<1) return;

View File

@ -41,7 +41,7 @@ public:
Qt_view_show_optimal_convex(T &p) : polygon(p)
{};
void draw_scene(Qt_widget &widget)
void draw_view(Qt_widget &widget)
{
optimal_convex.clear();
Traits partition_traits;

View File

@ -38,7 +38,7 @@ public:
Qt_view_show_points(T &t) : tr(t){};
void draw_scene(Qt_widget &widget)
void draw_view(Qt_widget &widget)
{
Vertex v;
Vertex_iterator it = tr.vertices_begin(),

View File

@ -36,7 +36,7 @@ class Qt_view_show_polygon : public Qt_widget_view
public:
Qt_view_show_polygon(T &p) : polygon(p){};
void draw_scene(Qt_widget &widget)
void draw_view(Qt_widget &widget)
{
widget << LineWidth(3);
widget << CGAL::BLUE;

View File

@ -36,7 +36,7 @@ public:
Qt_view_show_polygon_points(T &p) : polygon(p){};
void draw_scene(Qt_widget &widget)
void draw_view(Qt_widget &widget)
{
typename T::const_iterator vert_it;

View File

@ -33,7 +33,7 @@ public:
Qt_view_show_triangulation(T &t) : tr(t){};
void draw_scene(Qt_widget &widget)
void draw_view(Qt_widget &widget)
{
widget << CGAL::BLUE;
widget << tr;

View File

@ -34,7 +34,7 @@ class Qt_view_show_voronoi : public Qt_widget_view
public:
Qt_view_show_voronoi(T &t1) : tr(t1){};
void draw_scene(Qt_widget &widget)
void draw_view(Qt_widget &widget)
{
widget << CGAL::RED ;
tr.draw_dual(widget);

View File

@ -41,7 +41,7 @@ public:
Qt_view_show_ymonotone(T &p) : polygon(p)
{};
void draw_scene(Qt_widget &widget)
void draw_view(Qt_widget &widget)
{
ymonotone.clear();

View File

@ -45,7 +45,7 @@ public:
virtual void leaveEvent(QEvent *, Qt_widget&) {};
public slots:
virtual void draw_scene(Qt_widget&)=0;
virtual void draw_view(Qt_widget&)=0;
signals:
void dying(Qt_widget_view*);
public:

View File

@ -360,16 +360,6 @@ void Qt_widget::detach_current_tool()
};
void Qt_widget::show_scene(Qt_widget_view* s)
{/*
if(scenes_to_display.find(s)!=scenes_to_display.end())
{
scenes_to_display[s]=true;
redraw();
}*/
};
// redraw shown scenes
// ***** Should be call when:
// - an editable scene is changed (should be call by tools)
@ -382,7 +372,7 @@ void Qt_widget::redraw()
lock();
std::list<Qt_widget_view*>::iterator it;
for(it = qt_scenes.begin(); it!= qt_scenes.end(); it++)
(*it)->draw_scene(*this);
(*it)->draw_view(*this);
unlock();
if (has_tool())
@ -392,14 +382,14 @@ void Qt_widget::redraw()
};
// add a scene in the list of displayable scenes
void Qt_widget::add_scene(Qt_widget_view* s)
void Qt_widget::add_view(Qt_widget_view* s)
{
qt_scenes.push_back(s);
connect(s,SIGNAL(dying(Qt_widget_view*)),this,SLOT(remove_scene(Qt_widget_view*)));
}
// remove a scene from the list of displayable scenes
void Qt_widget::remove_scene(Qt_widget_view* s)
void Qt_widget::remove_view(Qt_widget_view* s)
{
qt_scenes.erase(std::find(qt_scenes.begin(),qt_scenes.end(),s));
}