diff --git a/src/exportvector.cpp b/src/exportvector.cpp index 9ed8817..3e274c0 100644 --- a/src/exportvector.cpp +++ b/src/exportvector.cpp @@ -6,13 +6,6 @@ #include #include "solvespace.h" -VectorFileWriter::~VectorFileWriter() { - // This out-of-line virtual method definition quells the following warning - // from Clang++: "'VectorFileWriter' has no out-of-line virtual method - // definitions; its vtable will be emitted in every translation unit - // [-Wweak-vtables]" -} - class PolylineBuilder { public: struct Edge; @@ -160,14 +153,14 @@ public: DxfWriteInterface(DxfFileWriter *w, dxfRW *dxfrw) : writer(w), dxf(dxfrw) {} - virtual void writeTextstyles() { + void writeTextstyles() override { DRW_Textstyle ts; ts.name = "unicode"; ts.font = "unicode"; dxf->writeTextstyle(&ts); } - virtual void writeLayers() { + void writeLayers() override { DRW_Layer layer; layer.name = "dimensions"; @@ -195,7 +188,7 @@ public: } } - virtual void writeLTypes() { + void writeLTypes() override { for(int i = 0; i <= Style::LAST_STIPPLE; i++) { DRW_LType type; // LibreCAD requires the line type to have one of these exact names, @@ -286,7 +279,7 @@ public: } } - virtual void writeEntities() { + void writeEntities() override { writePolylines(); for(DxfFileWriter::BezierPath &path : writer->paths) { @@ -389,7 +382,7 @@ public: Vector dna = norm.Cross(da).WithMagnitude(1.0); double thetaf = acos(da.DirectionCosineWith(db)); - + // Calculate median Vector m = da.WithMagnitude(1.0).ScaledBy(cos(thetaf/2)).Plus( dna.ScaledBy(sin(thetaf/2))); diff --git a/src/importdxf.cpp b/src/importdxf.cpp index e534bda..a8b721d 100644 --- a/src/importdxf.cpp +++ b/src/importdxf.cpp @@ -528,20 +528,20 @@ public: return hr.entity(0); } - virtual void addLayer(const DRW_Layer &data) { + void addLayer(const DRW_Layer &data) override { layers.emplace(data.name, data); } - virtual void addBlock(const DRW_Block &data) { + void addBlock(const DRW_Block &data) override { readBlock = &blocks[data.name]; readBlock->data = data; } - virtual void endBlock() { + void endBlock() override { readBlock = NULL; } - virtual void addPoint(const DRW_Point &data) { + void addPoint(const DRW_Point &data) override { if(data.space != DRW::ModelSpace) return; if(addPendingBlockEntity(data)) return; @@ -550,14 +550,14 @@ public: processPoint(hr.entity(0)); } - virtual void addLine(const DRW_Line &data) { + void addLine(const DRW_Line &data) override { if(data.space != DRW::ModelSpace) return; if(addPendingBlockEntity(data)) return; createLine(toVector(data.basePoint), toVector(data.secPoint), styleFor(&data).v, true); } - virtual void addArc(const DRW_Arc &data) { + void addArc(const DRW_Arc &data) override { if(data.space != DRW::ModelSpace) return; if(addPendingBlockEntity(data)) return; @@ -587,14 +587,14 @@ public: setStyle(hr, styleFor(&data)); } - virtual void addCircle(const DRW_Circle &data) { + void addCircle(const DRW_Circle &data) override { if(data.space != DRW::ModelSpace) return; if(addPendingBlockEntity(data)) return; createCircle(toVector(data.basePoint), data.radious, styleFor(&data).v); } - virtual void addLWPolyline(const DRW_LWPolyline &data) { + void addLWPolyline(const DRW_LWPolyline &data) override { if(data.space != DRW::ModelSpace) return; if(addPendingBlockEntity(data)) return; @@ -630,7 +630,7 @@ public: } } - virtual void addPolyline(const DRW_Polyline &data) { + void addPolyline(const DRW_Polyline &data) override { if(data.space != DRW::ModelSpace) return; if(addPendingBlockEntity(data)) return; @@ -667,7 +667,7 @@ public: } } - virtual void addSpline(const DRW_Spline *data) { + void addSpline(const DRW_Spline *data) override { if(data->space != DRW::ModelSpace) return; if(data->degree != 3) return; if(addPendingBlockEntity(*data)) return; @@ -680,7 +680,7 @@ public: setStyle(hr, styleFor(data)); } - virtual void addInsert(const DRW_Insert &data) { + void addInsert(const DRW_Insert &data) override { if(data.space != DRW::ModelSpace) return; if(addPendingBlockEntity(data)) return; @@ -710,7 +710,7 @@ public: blockT = t; } - virtual void addMText(const DRW_MText &data) { + void addMText(const DRW_MText &data) override { if(data.space != DRW::ModelSpace) return; if(addPendingBlockEntity(data)) return; @@ -719,7 +719,7 @@ public: addText(text); } - virtual void addText(const DRW_Text &data) { + void addText(const DRW_Text &data) override { if(data.space != DRW::ModelSpace) return; if(addPendingBlockEntity(data)) return; @@ -737,7 +737,7 @@ public: Constraint::AddConstraint(&c, false); } - virtual void addDimAlign(const DRW_DimAligned *data) { + void addDimAlign(const DRW_DimAligned *data) override { if(data->space != DRW::ModelSpace) return; if(addPendingBlockEntity(*data)) return; @@ -760,7 +760,7 @@ public: c->disp.offset = p2.Minus(p0.Plus(p1).ScaledBy(0.5)); } - virtual void addDimLinear(const DRW_DimLinear *data) { + void addDimLinear(const DRW_DimLinear *data) override { if(data->space != DRW::ModelSpace) return; if(addPendingBlockEntity(*data)) return; @@ -799,7 +799,7 @@ public: c->disp.offset = p2.Minus(p4); } - virtual void addDimAngular(const DRW_DimAngular *data) { + void addDimAngular(const DRW_DimAngular *data) override { if(data->space != DRW::ModelSpace) return; if(addPendingBlockEntity(*data)) return; @@ -856,7 +856,7 @@ public: return hc; } - virtual void addDimRadial(const DRW_DimRadial *data) { + void addDimRadial(const DRW_DimRadial *data) override { if(data->space != DRW::ModelSpace) return; if(addPendingBlockEntity(*data)) return; @@ -871,7 +871,7 @@ public: createDiametric(cp, cp.Minus(dp).Magnitude(), tp, actual, /*asRadius=*/true); } - virtual void addDimDiametric(const DRW_DimDiametric *data) { + void addDimDiametric(const DRW_DimDiametric *data) override { if(data->space != DRW::ModelSpace) return; if(addPendingBlockEntity(*data)) return; @@ -888,7 +888,7 @@ public: createDiametric(cp, cp.Minus(dp1).Magnitude(), tp, actual, /*asRadius=*/false); } - virtual void addDimAngular3P(const DRW_DimAngular3p *data) { + void addDimAngular3P(const DRW_DimAngular3p *data) override { if(data->space != DRW::ModelSpace) return; if(addPendingBlockEntity(*data)) return; diff --git a/src/platform/gtkmain.cpp b/src/platform/gtkmain.cpp index 315ef42..077ee7f 100644 --- a/src/platform/gtkmain.cpp +++ b/src/platform/gtkmain.cpp @@ -323,7 +323,12 @@ public: protected: /* Draw on a GLX framebuffer object, then read pixels out and draw them on the Cairo context. Slower, but you get to overlay nice widgets. */ - virtual bool on_draw(const Cairo::RefPtr &cr) { +#ifdef HAVE_GTK3 + bool on_draw(const Cairo::RefPtr &cr) override { +#else + bool on_expose_event(GdkEventExpose *) override { + const Cairo::RefPtr &cr = get_window()->create_cairo_context(); +#endif if(!glXMakeCurrent(_xdisplay, _xwindow, _glcontext)) oops(); @@ -348,12 +353,6 @@ protected: return true; } -#ifdef HAVE_GTK2 - virtual bool on_expose_event(GdkEventExpose *) { - return on_draw(get_window()->create_cairo_context()); - } -#endif - virtual void on_gl_draw() = 0; private: @@ -451,7 +450,7 @@ public: } protected: - virtual bool on_key_press_event(GdkEventKey *event) { + bool on_key_press_event(GdkEventKey *event) override { if(event->keyval == GDK_KEY_Escape) { stop_editing(); return true; @@ -460,13 +459,13 @@ protected: return false; } - virtual void on_size_allocate(Gtk::Allocation& allocation) { + void on_size_allocate(Gtk::Allocation& allocation) override { Gtk::Fixed::on_size_allocate(allocation); _underlay.size_allocate(allocation); } - virtual void on_activate() { + void on_activate() { _signal_editing_done(_entry.get_text()); } @@ -514,18 +513,18 @@ public: } protected: - virtual bool on_configure_event(GdkEventConfigure *event) { + bool on_configure_event(GdkEventConfigure *event) override { _w = event->width; _h = event->height; return GlWidget::on_configure_event(event);; } - virtual void on_gl_draw() { + void on_gl_draw() override { SS.GW.Paint(); } - virtual bool on_motion_notify_event(GdkEventMotion *event) { + bool on_motion_notify_event(GdkEventMotion *event) override { int x, y; ij_to_xy(event->x, event->y, x, y); @@ -539,7 +538,7 @@ protected: return true; } - virtual bool on_button_press_event(GdkEventButton *event) { + bool on_button_press_event(GdkEventButton *event) override { int x, y; ij_to_xy(event->x, event->y, x, y); @@ -560,7 +559,7 @@ protected: return true; } - virtual bool on_button_release_event(GdkEventButton *event) { + bool on_button_release_event(GdkEventButton *event) override { int x, y; ij_to_xy(event->x, event->y, x, y); @@ -577,7 +576,7 @@ protected: return true; } - virtual bool on_scroll_event(GdkEventScroll *event) { + bool on_scroll_event(GdkEventScroll *event) override { int x, y; ij_to_xy(event->x, event->y, x, y); @@ -586,7 +585,7 @@ protected: return true; } - virtual bool on_leave_notify_event (GdkEventCrossing *) { + bool on_leave_notify_event (GdkEventCrossing *) override { SS.GW.MouseLeave(); return true; @@ -637,25 +636,25 @@ public: } protected: - virtual void on_show() { + void on_show() override { Gtk::Window::on_show(); CnfThawWindowPos(this, "GraphicsWindow"); } - virtual void on_hide() { + void on_hide() override { CnfFreezeWindowPos(this, "GraphicsWindow"); Gtk::Window::on_hide(); } - virtual bool on_delete_event(GdkEventAny *) { + bool on_delete_event(GdkEventAny *) override { SS.Exit(); return true; } - virtual bool on_window_state_event(GdkEventWindowState *event) { + bool on_window_state_event(GdkEventWindowState *event) override { _is_fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN; /* The event arrives too late for the caller of ToggleFullScreen @@ -666,7 +665,7 @@ protected: return Gtk::Window::on_window_state_event(event); } - virtual bool on_key_press_event(GdkEventKey *event) { + bool on_key_press_event(GdkEventKey *event) override { int chr; switch(event->keyval) { @@ -715,7 +714,7 @@ protected: return Gtk::Window::on_key_press_event(event); } - virtual void on_editing_done(Glib::ustring value) { + void on_editing_done(Glib::ustring value) { SS.GW.EditControlDone(value.c_str()); } @@ -806,7 +805,7 @@ public: } protected: - virtual void on_activate() { + void on_activate() override { Gtk::MenuItem::on_activate(); if(has_submenu()) @@ -821,7 +820,7 @@ protected: via keyboard. This selects the item twice in some cases, but we are idempotent. */ - virtual bool on_button_press_event(GdkEventButton *event) { + bool on_button_press_event(GdkEventButton *event) override { if(event->button == 1 && event->type == GDK_BUTTON_PRESS) { on_activate(); return true; @@ -943,7 +942,7 @@ public: } protected: - virtual void on_activate() { + void on_activate() override { MenuItem::on_activate(); if(_synthetic) @@ -1026,7 +1025,7 @@ public: } protected: - virtual void on_activate() { + void on_activate() override { if(_id >= RECENT_OPEN && _id < (RECENT_OPEN + MAX_RECENT)) SolveSpaceUI::MenuFile(_id); else if(_id >= RECENT_LINK && _id < (RECENT_LINK + MAX_RECENT)) @@ -1290,11 +1289,11 @@ public: } protected: - virtual void on_gl_draw() { + void on_gl_draw() override { SS.TW.Paint(); } - virtual bool on_motion_notify_event(GdkEventMotion *event) { + bool on_motion_notify_event(GdkEventMotion *event) override { SS.TW.MouseEvent(/*leftClick*/ false, /*leftDown*/ event->state & GDK_BUTTON1_MASK, event->x, event->y); @@ -1302,7 +1301,7 @@ protected: return true; } - virtual bool on_button_press_event(GdkEventButton *event) { + bool on_button_press_event(GdkEventButton *event) override { SS.TW.MouseEvent(/*leftClick*/ event->type == GDK_BUTTON_PRESS, /*leftDown*/ event->state & GDK_BUTTON1_MASK, event->x, event->y); @@ -1310,14 +1309,14 @@ protected: return true; } - virtual bool on_scroll_event(GdkEventScroll *event) { + bool on_scroll_event(GdkEventScroll *event) override { _adjustment->set_value(_adjustment->get_value() + DeltaYOfScrollEvent(event) * _adjustment->get_page_increment()); return true; } - virtual bool on_leave_notify_event (GdkEventCrossing *) { + bool on_leave_notify_event (GdkEventCrossing *) override { SS.TW.MouseLeave(); return true; @@ -1370,49 +1369,49 @@ public: } protected: - virtual void on_show() { + void on_show() override { Gtk::Window::on_show(); CnfThawWindowPos(this, "TextWindow"); } - virtual void on_hide() { + void on_hide() override { CnfFreezeWindowPos(this, "TextWindow"); Gtk::Window::on_hide(); } - virtual bool on_delete_event(GdkEventAny *) { + bool on_key_press_event(GdkEventKey *event) override { + if(GW->emulate_key_press(event)) { + return true; + } + + return Gtk::Window::on_key_press_event(event); + } + + bool on_delete_event(GdkEventAny *) override { /* trigger the action and ignore the request */ GraphicsWindow::MenuView(GraphicsWindow::MNU_SHOW_TEXT_WND); return false; } - virtual void on_scrollbar_value_changed() { + void on_scrollbar_value_changed() { SS.TW.ScrollbarEvent((int)_scrollbar.get_adjustment()->get_value()); } - virtual void on_editing_done(Glib::ustring value) { + void on_editing_done(Glib::ustring value) { SS.TW.EditControlDone(value.c_str()); } - virtual bool on_editor_motion_notify_event(GdkEventMotion *event) { + bool on_editor_motion_notify_event(GdkEventMotion *event) { return _widget.event((GdkEvent*) event); } - virtual bool on_editor_button_press_event(GdkEventButton *event) { + bool on_editor_button_press_event(GdkEventButton *event) { return _widget.event((GdkEvent*) event); } - virtual bool on_key_press_event(GdkEventKey *event) { - if(GW->emulate_key_press(event)) { - return true; - } - - return Gtk::Window::on_key_press_event(event); - } - private: Gtk::VScrollbar _scrollbar; TextWidget _widget; diff --git a/src/solvespace.h b/src/solvespace.h index 41479a5..bbd4ac7 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -497,8 +497,6 @@ public: static VectorFileWriter *ForFile(const std::string &filename); - ~VectorFileWriter(); - void SetModelviewProjection(const Vector &u, const Vector &v, const Vector &n, const Vector &origin, double cameraTan, double scale); Vector Transform(Vector &pos) const; @@ -508,18 +506,17 @@ public: void BezierAsPwl(SBezier *sb); void BezierAsNonrationalCubic(SBezier *sb, int depth=0); - virtual bool OutputConstraints(IdList *) { return false; } - virtual bool CanOutputMesh() const { return false; } - virtual void StartPath( RgbaColor strokeRgb, double lineWidth, bool filled, RgbaColor fillRgb, hStyle hs) = 0; virtual void FinishPath(RgbaColor strokeRgb, double lineWidth, bool filled, RgbaColor fillRgb, hStyle hs) = 0; virtual void Bezier(SBezier *sb) = 0; virtual void Triangle(STriangle *tr) = 0; - virtual void StartFile(void) = 0; - virtual void FinishAndCloseFile(void) = 0; - virtual bool HasCanvasSize(void) = 0; + virtual bool OutputConstraints(IdList *) { return false; } + virtual void StartFile() = 0; + virtual void FinishAndCloseFile() = 0; + virtual bool HasCanvasSize() const = 0; + virtual bool CanOutputMesh() const = 0; }; class DxfFileWriter : public VectorFileWriter { public: @@ -530,21 +527,21 @@ public: std::vector paths; IdList *constraint; - bool OutputConstraints(IdList *constraint); - - void StartPath( RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); - void FinishPath(RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); - void Triangle(STriangle *tr); - void Bezier(SBezier *sb); - void StartFile(void); - void FinishAndCloseFile(void); - bool HasCanvasSize(void) { return false; } - bool NeedToOutput(Constraint *c); - static const char *lineTypeName(int stippleType); + bool OutputConstraints(IdList *constraint) override; + + void StartPath( RgbaColor strokeRgb, double lineWidth, + bool filled, RgbaColor fillRgb, hStyle hs) override; + void FinishPath(RgbaColor strokeRgb, double lineWidth, + bool filled, RgbaColor fillRgb, hStyle hs) override; + void Triangle(STriangle *tr) override; + void Bezier(SBezier *sb) override; + void StartFile() override; + void FinishAndCloseFile() override; + bool HasCanvasSize() const override { return false; } + bool CanOutputMesh() const override { return false; } + bool NeedToOutput(Constraint *c); }; class EpsFileWriter : public VectorFileWriter { public: @@ -552,15 +549,15 @@ public: void MaybeMoveTo(Vector s, Vector f); void StartPath( RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); + bool filled, RgbaColor fillRgb, hStyle hs) override; void FinishPath(RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); - void Triangle(STriangle *tr); - void Bezier(SBezier *sb); - void StartFile(void); - void FinishAndCloseFile(void); - bool HasCanvasSize(void) { return true; } - bool CanOutputMesh() const { return true; } + bool filled, RgbaColor fillRgb, hStyle hs) override; + void Triangle(STriangle *tr) override; + void Bezier(SBezier *sb) override; + void StartFile() override; + void FinishAndCloseFile() override; + bool HasCanvasSize() const override { return true; } + bool CanOutputMesh() const override { return true; } }; class PdfFileWriter : public VectorFileWriter { public: @@ -570,15 +567,15 @@ public: void MaybeMoveTo(Vector s, Vector f); void StartPath( RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); + bool filled, RgbaColor fillRgb, hStyle hs) override; void FinishPath(RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); - void Triangle(STriangle *tr); - void Bezier(SBezier *sb); - void StartFile(void); - void FinishAndCloseFile(void); - bool HasCanvasSize(void) { return true; } - bool CanOutputMesh() const { return true; } + bool filled, RgbaColor fillRgb, hStyle hs) override; + void Triangle(STriangle *tr) override; + void Bezier(SBezier *sb) override; + void StartFile() override; + void FinishAndCloseFile() override; + bool HasCanvasSize() const override { return true; } + bool CanOutputMesh() const override { return true; } }; class SvgFileWriter : public VectorFileWriter { public: @@ -586,53 +583,56 @@ public: void MaybeMoveTo(Vector s, Vector f); void StartPath( RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); + bool filled, RgbaColor fillRgb, hStyle hs) override; void FinishPath(RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); - void Triangle(STriangle *tr); - void Bezier(SBezier *sb); - void StartFile(void); - void FinishAndCloseFile(void); - bool HasCanvasSize(void) { return true; } - bool CanOutputMesh() const { return true; } + bool filled, RgbaColor fillRgb, hStyle hs) override; + void Triangle(STriangle *tr) override; + void Bezier(SBezier *sb) override; + void StartFile() override; + void FinishAndCloseFile() override; + bool HasCanvasSize() const override { return true; } + bool CanOutputMesh() const override { return true; } }; class HpglFileWriter : public VectorFileWriter { public: static double MmToHpglUnits(double mm); void StartPath( RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); + bool filled, RgbaColor fillRgb, hStyle hs) override; void FinishPath(RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); - void Triangle(STriangle *tr); - void Bezier(SBezier *sb); - void StartFile(void); - void FinishAndCloseFile(void); - bool HasCanvasSize(void) { return false; } + bool filled, RgbaColor fillRgb, hStyle hs) override; + void Triangle(STriangle *tr) override; + void Bezier(SBezier *sb) override; + void StartFile() override; + void FinishAndCloseFile() override; + bool HasCanvasSize() const override { return false; } + bool CanOutputMesh() const override { return false; } }; class Step2dFileWriter : public VectorFileWriter { StepFileWriter sfw; void StartPath( RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); + bool filled, RgbaColor fillRgb, hStyle hs) override; void FinishPath(RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); - void Triangle(STriangle *tr); - void Bezier(SBezier *sb); - void StartFile(void); - void FinishAndCloseFile(void); - bool HasCanvasSize(void) { return false; } + bool filled, RgbaColor fillRgb, hStyle hs) override; + void Triangle(STriangle *tr) override; + void Bezier(SBezier *sb) override; + void StartFile() override; + void FinishAndCloseFile() override; + bool HasCanvasSize() const override { return false; } + bool CanOutputMesh() const override { return false; } }; class GCodeFileWriter : public VectorFileWriter { public: SEdgeList sel; void StartPath( RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); + bool filled, RgbaColor fillRgb, hStyle hs) override; void FinishPath(RgbaColor strokeRgb, double lineWidth, - bool filled, RgbaColor fillRgb, hStyle hs); - void Triangle(STriangle *tr); - void Bezier(SBezier *sb); - void StartFile(void); - void FinishAndCloseFile(void); - bool HasCanvasSize(void) { return false; } + bool filled, RgbaColor fillRgb, hStyle hs) override; + void Triangle(STriangle *tr) override; + void Bezier(SBezier *sb) override; + void StartFile() override; + void FinishAndCloseFile() override; + bool HasCanvasSize() const override { return false; } + bool CanOutputMesh() const override { return false; } }; #ifdef LIBRARY