#ifndef CGAL_QT_ARCS_GRAPHICS_ITEM_H #define CGAL_QT_ARCS_GRAPHICS_ITEM_H #include #include #include #include #include #include #include namespace CGAL { namespace Qt { template class ArcsGraphicsItem : public GraphicsItem { std::vector& arcs, &intersections; typedef typename CK::Circle_2 Circle_2; typedef typename CK::Circular_arc_2 Circular_arc_2; typedef typename CK::Circular_arc_point_2 Circular_arc_point_2; typedef typename CK::Line_arc_2 Line_arc_2; public: ArcsGraphicsItem(std::vector& arcs_, std::vector& intersections_); void modelChanged(); public: QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); const QPen& intersectionsPen() const { return intersections_pen; } const QPen& inputPen() const { return input_pen; } void setIntersectionsPen(const QPen& pen) { intersections_pen = pen; } void setInputPen(const QPen& pen) { input_pen = pen; } protected: void updateBoundingBox(); QPainter* m_painter; PainterOstream painterostream; QRectF bounding_rect; QPen intersections_pen; QPen input_pen; Converter convert; }; template ArcsGraphicsItem::ArcsGraphicsItem(std::vector& arcs_, std::vector& intersections_) : arcs(arcs_), intersections(intersections_), painterostream(nullptr) { setIntersectionsPen(QPen(::Qt::red, 3.)); if(arcs.empty()){ this->hide(); } updateBoundingBox(); setZValue(3); } template QRectF ArcsGraphicsItem::boundingRect() const { return bounding_rect; } template void ArcsGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * ) { painter->setPen(this->inputPen()); painterostream = PainterOstream(painter); for(std::vector::iterator it = arcs.begin(); it != arcs.end(); ++it){ Circular_arc_2 ca; Line_arc_2 la; if(assign(ca, *it)){ painterostream << ca; } else if(assign(la, *it)){ painterostream << la; } } painter->setPen(this->intersectionsPen()); painterostream = PainterOstream(painter); for(std::vector::iterator it = intersections.begin(); it != intersections.end(); ++it){ std::pair cap_ui; Circular_arc_2 ca; Line_arc_2 la; if(assign(cap_ui, *it)){ QTransform matrix = painter->worldTransform(); painter->resetTransform(); painter->drawPoint(matrix.map(convert(cap_ui.first))); painter->setWorldTransform(matrix); }if(assign(ca, *it)){ painterostream << ca; } else if(assign(la, *it)){ painterostream << la; } } } template void ArcsGraphicsItem::updateBoundingBox() { bounding_rect = QRectF(0,0,100, 100); Bbox_2 bb; bool initialized = false; for(std::vector::iterator it = arcs.begin(); it != arcs.end(); ++it){ Circular_arc_2 ca; Line_arc_2 la; if(assign(ca, *it)){ if(initialized){ bb = bb + ca.supporting_circle().bbox(); } else { initialized = true; bb = ca.supporting_circle().bbox(); } } else if(assign(la, *it)){ if(initialized){ bb = bb + la.bbox(); } else { initialized = true; bb = la.bbox(); } } } prepareGeometryChange(); bounding_rect = convert(bb); } template void ArcsGraphicsItem::modelChanged() { if((arcs.empty()) ){ this->hide(); } else if((! arcs.empty()) && (! this->isVisible())){ this->show(); } updateBoundingBox(); update(); } } // namespace Qt } // namespace CGAL #endif // CGAL_QT_ARCS_GRAPHICS_ITEM_H