// Copyright (c) 2003 INRIA Sophia-Antipolis (France) and // Max-Planck-Institute Saarbruecken (Germany). // All rights reserved. // // Authors : Monique Teillaud // Sylvain Pion // Radu Ursu // // Partially supported by the IST Programme of the EU as a Shared-cost // RTD (FET Open) Project under Contract No IST-2000-26473 // (CGAL - Effective Computational Geometry for Curves and Surfaces) // TODO : // - Add the possibility to input full circles. // - locate the cell containing a point. // - Move more basic IO routines in include/CGAL/IO/ // - File menu #include // if QT is not installed, a message will be issued at runtime. #ifndef CGAL_USE_QT #include int main() { std::cout << "Sorry, this demo needs QT..." << std::endl; return 0; } #else #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Qt_widget_get_segment.h" #include "Qt_widget_get_arc.h" #include "trash.xpm" #include "get_arc.xpm" //#include #include #include #include #include typedef CGAL::Quotient NT; typedef CGAL::Cartesian Linear_k; typedef CGAL::Algebraic_kernel_for_circles_2_2 Algebraic_k; typedef CGAL::Circular_kernel_2 Circular_k; typedef Circular_k::Line_arc_2 Line_arc_2; typedef Circular_k::Segment_2 Segment; typedef Circular_k::Circular_arc_2 Circular_arc_2; typedef boost::variant< Circular_arc_2, Segment > Arc; typedef std::vector ArcContainer; #ifndef CGAL_CURVED_KERNEL_DEBUG typedef CGAL::Arr_circular_line_arc_traits Traits; #else typedef CGAL::Arr_circular_line_arc_traits Traits0; typedef CGAL::Circular_arc_traits_tracer Traits; #endif typedef Traits::Point_2 Point_2; typedef Traits::Curve_2 Conic_arc_2; typedef Traits::X_monotone_curve_2 X_monotone_curve_2; const QString my_title_string("CGAL :: " "Planar Map of Intersecting Circular Arcs"); // This layer controls the drawing of the arc_container. struct Qt_layer_show_ch : public CGAL::Qt_widget_layer { ArcContainer _arc_container; bool show_arcs; public: Qt_layer_show_ch() : show_arcs(true) {} const ArcContainer & arc_container() const { return _arc_container; } ArcContainer & arc_container() { return _arc_container; } void swap_show() { show_arcs = ! show_arcs; } void draw() { if (!show_arcs) return; *widget << CGAL::BLUE; for (ArcContainer::const_iterator cit = arc_container().begin(); cit != arc_container().end(); ++cit){ if(const Segment* line = boost::get( &(*cit))){ *widget << *line; } else if (const Circular_arc_2* arc = boost::get( &(*cit))){ *widget << *arc; } } } }; class MyWindow : public QMainWindow { Q_OBJECT public: MyWindow(int w, int h) : something_changed(true) { widget = new CGAL::Qt_widget(this); setCentralWidget(widget); // create a timer for checking if something changed QTimer *timer = new QTimer( this ); connect( timer, SIGNAL(timeout()), this, SLOT(timer_done()) ); timer->start( 200, FALSE ); // file menu QPopupMenu * file = new QPopupMenu( this ); menuBar()->insertItem( "&File", file ); file->insertItem("&New", this, SLOT(new_instance()), CTRL+Key_N); file->insertItem("New &Window", this, SLOT(new_window()), CTRL+Key_W); file->insertSeparator(); file->insertItem("&Load Arcs", this, SLOT(load_arcs()), CTRL+Key_L); file->insertItem("&Save Arcs", this, SLOT(save_arcs()), CTRL+Key_S); file->insertSeparator(); file->insertItem("Print", widget, SLOT(print_to_ps()), CTRL+Key_P); file->insertSeparator(); file->insertItem( "&Close", this, SLOT(close()), CTRL+Key_X ); file->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q ); // help menu QPopupMenu * help = new QPopupMenu( this ); menuBar()->insertItem( "&Help", help ); help->insertItem("How To", this, SLOT(howto()), Key_F1); help->insertSeparator(); help->insertItem("&About", this, SLOT(about()), CTRL+Key_A ); help->insertItem("About &Qt", this, SLOT(aboutQt()) ); // the standard toolbar stoolbar = new CGAL::Qt_widget_standard_toolbar (widget, this, "ST"); // my tool bar QToolBar * layers_toolbar = new QToolBar("Tools", this, QMainWindow::Top, TRUE, "Tools"); // the button controlling if we show the input arcs QToolButton * show_container_button = new QToolButton(QPixmap((const char**)::get_arc), "Show Original arcs", 0, this, SLOT(show_original_arcs()), layers_toolbar, "Show Original arcs"); show_container_button->setToggleButton(true); show_container_button->toggle(); connect(show_container_button, SIGNAL(stateChanged(int)), &testlayer, SLOT(stateChanged(int))); // this button clears the content of the arc container and the PMWX. QToolButton * clear_button = new QToolButton(QPixmap((const char**)trash), "Clear", 0, this, SLOT(clear_container()), layers_toolbar, "Clear"); connect(clear_button, SIGNAL(stateChanged(int)), &testlayer, SLOT(stateChanged(int))); *widget << CGAL::LineWidth(2) << CGAL::BackgroundColor(CGAL::WHITE); resize(w,h); widget->set_window(-1, 1, -1, 1); widget->setMouseTracking(TRUE); // layers widget->attach(&testlayer); get_arc_layer = new CGAL::Qt_widget_get_arc; get_segment_layer = new CGAL::Qt_widget_get_segment; // connect(get_arc_layer, SIGNAL(new_object_time()), this, SLOT(get_arc())); // connect(get_segment_layer, SIGNAL(new_object_time()), this, SLOT(get_arc())); } public slots: void new_instance() { widget->lock(); widget->clear_history(); widget->set_window(-1.1, 1.1, -1.1, 1.1); // set the Visible Area to the Interval widget->unlock(); something_changed = true; } void show_original_arcs() { testlayer.swap_show(); something_changed = true; widget->redraw(); } void clear_container() { arc_container().clear(); something_changed = true; widget->redraw(); } private slots: void about() { QMessageBox::about(this, my_title_string, "This is a demo of CGAL's Planar Map of intersecting Circle Arcs\n" "Using the Circular_kernel by Sylvain Pion and Monique Teillaud"); } void aboutQt() { QMessageBox::aboutQt(this, my_title_string); } void howto() { CGAL::Qt_help_window *help = new CGAL::Qt_help_window("help/index.html", ".", 0, "help viewer"); help->resize(400, 400); help->setCaption("Demo HowTo"); help->show(); } void new_window() { MyWindow *ed = new MyWindow(500, 500); ed->setCaption("Layer"); ed->widget->clear_history(); ed->widget->set_window(-1.1, 1.1, -1.1, 1.1); ed->show(); something_changed = true; } void timer_done() { if (something_changed) widget->redraw(); something_changed = false; } void load_arcs() { QString s( QFileDialog::getOpenFileName( QString::null, "DXF files (*.dxf)", this ) ); if ( s.isEmpty() ) return; //std::ifstream in(s); //CGAL::set_ascii_mode(in); //std::istream_iterator begin(in), end; //ArcContainer arcs(begin, end); //arc_container().swap(arcs); //to read dxf files std::ifstream in(s); CGAL::set_ascii_mode(in); ArcContainer arcs; CGAL::variant_load(in, std::back_inserter(arcs)); arc_container().swap(arcs); //update_pmwx(); stoolbar->clear_history(); something_changed = true; } void save_arcs() { QString fileName = QFileDialog::getSaveFileName( "arcs.cgal", "CGAL files (*.cgal)", this ); if ( !fileName.isNull() ) { // got a file name std::ofstream out(fileName); CGAL::set_ascii_mode(out); // std::copy(arc_container().begin(), arc_container().end(), // std::ostream_iterator(out, "\n")); } } private: const ArcContainer & arc_container() const { return testlayer.arc_container(); } ArcContainer & arc_container() { return testlayer.arc_container(); } CGAL::Qt_widget *widget; CGAL::Qt_widget_standard_toolbar *stoolbar; bool something_changed; Qt_layer_show_ch testlayer; CGAL::Qt_widget_get_segment *get_segment_layer; CGAL::Qt_widget_get_arc *get_arc_layer; }; #include "demo_viewer.moc" int main(int argc, char **argv) { QApplication app(argc, argv); MyWindow widget(800, 700); // physical window size app.setMainWidget(&widget); widget.setCaption(my_title_string); widget.setMouseTracking(TRUE); widget.show(); return app.exec(); } #endif // CGAL_USE_QT