// Copyright (c) 2008 GeometryFactory Sarl (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under // the terms of the Q Public License version 1.0. // See the file LICENSE.QPL distributed with CGAL. // // Licensees holding a valid commercial license may use this file in // accordance with the commercial license agreement provided with the software. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // // $URL$ // $Id$ // // // Author(s) : Andreas Fabri // Laurent Rineau #ifndef CGAL_QT_CONVERTER_H #define CGAL_QT_CONVERTER_H #include #include #include #include #include #include #include namespace CGAL { template class Circular_arc_point_2; namespace Qt { template class Converter { bool clippingRectIsInitialized; CGAL::Iso_rectangle_2 clippingRect; public: Converter() : clippingRectIsInitialized(false) { } Converter(QRectF rect) { if(rect.isValid()) { clippingRect = this->operator()(rect); clippingRectIsInitialized = true; } else clippingRectIsInitialized = false; } CGAL::Point_2 operator()(const QPointF& qp) const { return CGAL::Point_2(qp.x(), qp.y()); } QPointF operator()(const CGAL::Point_2& p) const { return QPointF(to_double(p.x()), to_double(p.y())); } QPointF operator()(const CGAL::Circular_arc_point_2& p) const { return QPointF(to_double(p.x()), to_double(p.y())); } CGAL::Segment_2 operator()(const QLineF& qs) const { return CGAL::Segment_2(operator()(qs.p1()), operator()(qs.p2)); } QLineF operator()(const CGAL::Segment_2 &s) const { return QLineF(operator()(s.source()), operator()(s.target())); } CGAL::Iso_rectangle_2 operator()(const QRectF& qr) const { return CGAL::Iso_rectangle_2(operator()(qr.bottomLeft()), operator()(qr.topRight())); } QRectF operator()(const CGAL::Iso_rectangle_2& r) const { return QRectF(operator()(r[3]), operator()(r[1])); // top left, bottom right } QRectF operator()(const CGAL::Bbox_2& bb) { return QRectF(bb.xmin(), bb.ymin(), bb.xmax()-bb.xmin(), bb.ymax()-bb.ymin()); } QLineF operator()(const CGAL::Ray_2 &r) const { CGAL_assertion(clippingRectIsInitialized); Object o = CGAL::intersection(r, clippingRect); typedef CGAL::Segment_2 Segment_2; typedef CGAL::Point_2 Point_2; if(const Segment_2 *s = CGAL::object_cast(&o)){ return this->operator()(*s); } else if(const Point_2 *p = CGAL::object_cast(&o)){ return QLineF(operator()(*p), operator()(*p)); } return QLineF(); } QLineF operator()(const CGAL::Line_2 &l) const { CGAL_assertion(clippingRectIsInitialized); Object o = CGAL::intersection(l, clippingRect); typedef CGAL::Segment_2 Segment_2; typedef CGAL::Point_2 Point_2; if(const Segment_2 *s = CGAL::object_cast(&o)){ return this->operator()(*s); } else if(const Point_2 *p = CGAL::object_cast(&o)){ return QLineF(operator()(*p), operator()(*p)); } return QLineF(); } QPolygonF operator()(const CGAL::Triangle_2 &t) { QPolygonF qp; qp << operator()(t.vertex(0)) << operator()(t.vertex(1)) << operator()(t.vertex(2)); return qp; } void operator()(std::list< CGAL::Point_2 >& p, const QPolygonF& qp) const { for(int i = 0; i < qp.size(); i++){ p.push_back(operator()(qp[i])); } } }; } // namesapce Qt } // namespace CGAL #endif // CGAL_QT_CONVERTER_H