Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) WktToSvg

 

WktToSvg is a tool to convert WKT to SVG.

 

 

 

 

 

Downloads

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./ToolWktToSvg/ToolWktToSvgConsole.pro

 

include(../../ConsoleApplication.pri)
include(../../Libraries/Apfloat.pri)
include(../../Libraries/Boost.pri)
include(../../Libraries/GeneralConsole.pri)

#Console
include(../../Classes/CppContainer/CppContainer.pri)
include(../../Classes/CppGeometry/CppGeometry.pri)
include(../../Classes/CppPlane/CppPlane.pri)
include(../../Classes/CppRibiRegex/CppRibiRegex.pri)

#Specific
include(ToolWktToSvgConsole.pri)

SOURCES += main.cpp

 

 

 

 

 

Qt project file: ./ToolWktToSvg/ToolWktToSvgDesktop.pro

 

include(../../DesktopApplication.pri)
include(../../Libraries/Apfloat.pri)
include(../../Libraries/Boost.pri)
include(../../Libraries/GeneralConsole.pri)
include(../../Libraries/GeneralDesktop.pri)

#Console
include(../../Classes/CppContainer/CppContainer.pri)
include(../../Classes/CppGeometry/CppGeometry.pri)
include(../../Classes/CppPlane/CppPlane.pri)
include(../../Classes/CppRibiRegex/CppRibiRegex.pri)

#Desktop
include(../../Classes/CppQtNavigationableGraphicsView/CppQtNavigationableGraphicsView.pri)
include(../../Tools/ToolWktToSvg/ToolWktToSvgDesktop.pri)

SOURCES += qtmain.cpp

 

 

 

 

 

Qt project file: ./ToolWktToSvg/ToolWktToSvgWebsite.pro

 

include(../../Tools/Tool/ToolConsole.pri)

 

 

 

 

 

./ToolWktToSvg/ToolWktToSvgConsole.pri

 

INCLUDEPATH += ../../Tools/ToolWktToSvg

HEADERS += \
    ../../Tools/ToolWktToSvg/wkttosvgmaindialog.h \
    ../../Tools/ToolWktToSvg/wkttosvgmenudialog.h

SOURCES += \
    ../../Tools/ToolWktToSvg/wkttosvgmaindialog.cpp \
    ../../Tools/ToolWktToSvg/wkttosvgmenudialog.cpp

RESOURCES += \
    ../../Tools/ToolWktToSvg/ToolWktToSvg.qrc

OTHER_FILES += \
    ../../Tools/ToolWktToSvg/Licence.txt

 

 

 

 

 

./ToolWktToSvg/ToolWktToSvgDesktop.pri

 

include(../../Tools/ToolWktToSvg/ToolWktToSvgConsole.pri)

SOURCES += \
    ../../Tools/ToolWktToSvg/qtwkttosvgmenudialog.cpp \
    ../../Tools/ToolWktToSvg/qtwkttosvgmaindialog.cpp

FORMS += \
    ../../Tools/ToolWktToSvg/qtwkttosvgmenudialog.ui \
    ../../Tools/ToolWktToSvg/qtwkttosvgmaindialog.ui

HEADERS += \
    ../../Tools/ToolWktToSvg/qtwkttosvgmenudialog.h \
    ../../Tools/ToolWktToSvg/qtwkttosvgmaindialog.h

 

 

 

 

 

./ToolWktToSvg/ToolWktToSvgWebsite.pri

 

include(../../Tools/ToolWktToSvg/ToolWktToSvgConsole.pri)

HEADERS +=

SOURCES +=

 

 

 

 

 

./ToolWktToSvg/main.cpp

 

//---------------------------------------------------------------------------
/*
WktToSvg, tool to convert WKT to SVG
Copyright (C) 2014-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolWktToSvg.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include "wkttosvgmenudialog.h"
#pragma GCC diagnostic pop

int main(int argc, char* argv[])
{
  const std::vector<std::string> args { ribi::MenuDialog::ConvertArguments(argc,argv) };
  ribi::WktToSvgMenuDialog d;
  return d.Execute(args);

}

 

 

 

 

 

./ToolWktToSvg/qtmain.cpp

 

//---------------------------------------------------------------------------
/*
WktToSvg, tool to convert WKT to SVG
Copyright (C) 2014-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolWktToSvg.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <QApplication>

#include "qtwkttosvgmenudialog.h"
#include "trace.h"
#pragma GCC diagnostic pop

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  ribi::QtWktToSvgMenuDialog w;
  w.show();
  return a.exec();
}

 

 

 

 

 

./ToolWktToSvg/qtwkttosvgmaindialog.h

 

//---------------------------------------------------------------------------
/*
WktToSvg, tool to convert WKT to SVG
Copyright (C) 2014-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolWktToSvg.htm
//---------------------------------------------------------------------------
#ifndef QTWKTTOSVGMAINDIALOG_H
#define QTWKTTOSVGMAINDIALOG_H

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si/area.hpp>
#include <boost/units/systems/si/length.hpp>
#include <boost/units/systems/si/plane_angle.hpp>
#include "qthideandshowdialog.h"
//#include "trianglemeshcreateverticalfacesstrategy.h"
#pragma GCC diagnostic pop

struct QPlainTextEdit;

namespace Ui {
  class QtWktToSvgMainDialog;
}

namespace ribi {

class QtWktToSvgMainDialog : public QtHideAndShowDialog
{
  Q_OBJECT

public:
  explicit QtWktToSvgMainDialog(QWidget *parent = 0) noexcept;
  QtWktToSvgMainDialog(const QtWktToSvgMainDialog&) = delete;
  QtWktToSvgMainDialog& operator=(const QtWktToSvgMainDialog&) = delete;
  ~QtWktToSvgMainDialog() noexcept;

protected:
  void keyPressEvent(QKeyEvent *) noexcept;

private:
  Ui::QtWktToSvgMainDialog *ui;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif

private slots:
  void on_text_svg_textChanged();
  void OnInputChanged();
};

} //~namespace ribi

#endif // QTWKTTOSVGMAINDIALOG_H

 

 

 

 

 

./ToolWktToSvg/qtwkttosvgmaindialog.cpp

 

//---------------------------------------------------------------------------
/*
WktToSvg, tool to convert WKT to SVG
Copyright (C) 2014-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolWktToSvg.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include "qtwkttosvgmaindialog.h"

#include <fstream>
#include <stdexcept>

#include <QGraphicsSvgItem>
#include <QKeyEvent>

#include "fileio.h"
#include "qtnavigationablegraphicsview.h"
#include "testtimer.h"
#include "trace.h"
#include "wkttosvgmaindialog.h"
#include "ui_qtwkttosvgmaindialog.h"

#pragma GCC diagnostic pop

ribi::QtWktToSvgMainDialog::QtWktToSvgMainDialog(QWidget *parent) noexcept
  : QtHideAndShowDialog(parent),
    ui(new Ui::QtWktToSvgMainDialog)
{
  #ifndef NDEBUG
  Test();
  #endif
  ui->setupUi(this);

  QObject::connect(
    ui->edit,
    static_cast<void (QLineEdit::*)(const QString&)>(&QLineEdit::textChanged),
    this,
    &ribi::QtWktToSvgMainDialog::OnInputChanged
  );
  QObject::connect(
    ui->box_stroke_width,
    static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
    this,
    &ribi::QtWktToSvgMainDialog::OnInputChanged
  );

  OnInputChanged();
}

ribi::QtWktToSvgMainDialog::~QtWktToSvgMainDialog() noexcept
{
  delete ui;
}

void ribi::QtWktToSvgMainDialog::keyPressEvent(QKeyEvent * event) noexcept
{
  if (event->key() == Qt::Key_Escape) { close(); return; }
}

#ifndef NDEBUG
void ribi::QtWktToSvgMainDialog::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
  WktToSvgMainDialog("POLYGON((0 0,0 1,1 1))",1.0);
  QtWktToSvgMainDialog();
}
#endif

void ribi::QtWktToSvgMainDialog::OnInputChanged()
{
  const std::string wkt_text = ui->edit->text().toStdString();
  const double stroke_width = ui->box_stroke_width->value();
  const WktToSvgMainDialog d(
    wkt_text,
    stroke_width
  );

  const std::string svg_text = d.GetSvg();

  ui->text_svg->setPlainText(svg_text.c_str()); //Calls on_text_svg_textChanged
}

void ribi::QtWktToSvgMainDialog::on_text_svg_textChanged()
{
  assert(ui->view->scene());
  ui->view->scene()->clear();


  const std::string svg_text = ui->text_svg->toPlainText().toStdString();


  const std::string filename = fileio::FileIo().GetTempFileName(".svg");
  //if (verbose) { std::clog << "Write SVG to file '" << filename << "'" << std::endl; }
  {
    std::ofstream f(filename.c_str());
    f << svg_text;
  }
  {
    QGraphicsSvgItem * const item = new QGraphicsSvgItem(filename.c_str());
    assert(item);
    item->setScale(10.0);
    ui->view->scene()->addItem(item);
    assert(!ui->view->scene()->items().empty());
  }
  fileio::FileIo().DeleteFile(filename);
}

 

 

 

 

 

./ToolWktToSvg/qtwkttosvgmenudialog.h

 

//---------------------------------------------------------------------------
/*
WktToSvg, tool to convert WKT to SVG
Copyright (C) 2014-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolWktToSvg.htm
//---------------------------------------------------------------------------
#ifndef QTWKTTOSVGMENUDIALOG_H
#define QTWKTTOSVGMENUDIALOG_H

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include "qthideandshowdialog.h"
#pragma GCC diagnostic pop

namespace Ui {
  class QtWktToSvgMenuDialog;
}

namespace ribi {

class QtWktToSvgMenuDialog : public QtHideAndShowDialog
{
  Q_OBJECT

public:
  explicit QtWktToSvgMenuDialog(QWidget *parent = 0) noexcept;
  QtWktToSvgMenuDialog(const QtWktToSvgMenuDialog&) = delete;
  QtWktToSvgMenuDialog& operator=(const QtWktToSvgMenuDialog&) = delete;
  ~QtWktToSvgMenuDialog() noexcept;

protected:
  void keyPressEvent(QKeyEvent * event) noexcept;

private:
  Ui::QtWktToSvgMenuDialog *ui;

private slots:
  void on_button_about_clicked() noexcept;
  void on_button_quit_clicked() noexcept;
  void on_button_start_clicked() noexcept;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
};

} //~namespace ribi

#endif // QTWKTTOSVGMENUDIALOG_H

 

 

 

 

 

./ToolWktToSvg/qtwkttosvgmenudialog.cpp

 

//---------------------------------------------------------------------------
/*
WktToSvg, tool to convert WKT to SVG
Copyright (C) 2014-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolWktToSvg.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include "qtwkttosvgmenudialog.h"

#include <QDesktopWidget>
#include <QKeyEvent>

#include "wkttosvgmenudialog.h"
#include "testtimer.h"
#include "qtaboutdialog.h"
#include "qtwkttosvgmaindialog.h"
#include "qthideandshowdialog.h"
#include "trace.h"
#include "ui_qtwkttosvgmenudialog.h"
#pragma GCC diagnostic pop

ribi::QtWktToSvgMenuDialog::QtWktToSvgMenuDialog(QWidget *parent) noexcept :
    QtHideAndShowDialog(parent),
    ui(new Ui::QtWktToSvgMenuDialog)
{
  #ifndef NDEBUG
  Test();
  #endif
  ui->setupUi(this);
}

ribi::QtWktToSvgMenuDialog::~QtWktToSvgMenuDialog() noexcept
{
  delete ui;
}

void ribi::QtWktToSvgMenuDialog::keyPressEvent(QKeyEvent * event) noexcept
{
  if (event->key() == Qt::Key_Escape) { close(); return; }
}

void ribi::QtWktToSvgMenuDialog::on_button_about_clicked() noexcept
{
  ribi::About a = WktToSvgMenuDialog().GetAbout();
  a.AddLibrary("QtHideAndShowDialog version: " + QtHideAndShowDialog::GetVersion());
  ribi::QtAboutDialog d(a);
  d.setWindowIcon(this->windowIcon());
  d.setStyleSheet(this->styleSheet());
  this->ShowChild(&d);
}

void ribi::QtWktToSvgMenuDialog::on_button_quit_clicked() noexcept
{
  close();
}

void ribi::QtWktToSvgMenuDialog::on_button_start_clicked() noexcept
{
  QtWktToSvgMainDialog d;
  ShowChild(&d);
}

#ifndef NDEBUG
void ribi::QtWktToSvgMenuDialog::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  WktToSvgMenuDialog();
  QtWktToSvgMainDialog();
  const TestTimer test_timer(__func__,__FILE__,1.0);
}
#endif

 

 

 

 

 

./ToolWktToSvg/wkttosvgmaindialog.h

 

//---------------------------------------------------------------------------
/*
WktToSvg, tool to convert WKT to SVG
Copyright (C) 2014-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolWktToSvg.htm
//---------------------------------------------------------------------------
#ifndef RIBI_WKTTOSVGMAINDIALOG_H
#define RIBI_WKTTOSVGMAINDIALOG_H

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <iosfwd>
#include <string>
#include <vector>
#pragma GCC diagnostic pop

namespace ribi {

struct WktToSvgMainDialog
{
  explicit WktToSvgMainDialog(
    const std::string& wkt,
    const double stroke_width
  );

  const std::string& GetSvg() const noexcept { return m_svg; }
  const std::string& GetWkt() const noexcept { return m_wkt; }


  private:
  const std::string m_svg;
  const std::string m_wkt;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif

  static std::string ToSvg(
    const std::string& wkt,
    const double stroke_width
  );
};

} //~namespace ribi

#endif // RIBI_WKTTOSVGMAINDIALOG_H

 

 

 

 

 

./ToolWktToSvg/wkttosvgmaindialog.cpp

 

//---------------------------------------------------------------------------
/*
WktToSvg, tool to convert WKT to SVG
Copyright (C) 2014-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolWktToSvg.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include "wkttosvgmaindialog.h"

#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/geometry/io/svg/svg_mapper.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/xpressive/xpressive.hpp>

#include "geometry.h"
#include "trace.h"
#include "testtimer.h"

#pragma GCC diagnostic pop

ribi::WktToSvgMainDialog::WktToSvgMainDialog(
  const std::string& wkt,
  const double stroke_width
) : m_svg(ToSvg(wkt,stroke_width)),
    m_wkt(wkt)
{
  #ifndef NDEBUG
  Test();
  #endif
}

#ifndef NDEBUG
void ribi::WktToSvgMainDialog::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
}
#endif

std::string ribi::WktToSvgMainDialog::ToSvg(
  const std::string& wkt,
  const double stroke_width
)
{
  return Geometry().WktToSvg(wkt,stroke_width);
}

 

 

 

 

 

./ToolWktToSvg/wkttosvgmenudialog.h

 

//---------------------------------------------------------------------------
/*
WktToSvg, tool to convert WKT to SVG
Copyright (C) 2014-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolWktToSvg.htm
//---------------------------------------------------------------------------
#ifndef RIBI_WKTTOSVGMENUDIALOG_H
#define RIBI_WKTTOSVGMENUDIALOG_H

#include <string>
#include <vector>

#include "menudialog.h"

struct QRegExp;

namespace ribi {

///GUI independent WktToSvg menu dialog
struct WktToSvgMenuDialog final : public MenuDialog
{
  WktToSvgMenuDialog();
  About GetAbout() const noexcept override;
  Help GetHelp() const noexcept override;
  boost::shared_ptr<const Program> GetProgram() const noexcept override;
  std::string GetVersion() const noexcept override;
  std::vector<std::string> GetVersionHistory() const noexcept override;

  private:
  int ExecuteSpecific(const std::vector<std::string>& argv) noexcept override;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
};

} //namespace ribi

#endif // RIBI_WKTTOSVGMENUDIALOG_H

 

 

 

 

 

./ToolWktToSvg/wkttosvgmenudialog.cpp

 

//---------------------------------------------------------------------------
/*
WktToSvg, tool to convert WKT to SVG
Copyright (C) 2014-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolWktToSvg.htm
//---------------------------------------------------------------------------
#include "wkttosvgmenudialog.h"

#include <cassert>
#include <iostream>
#include <memory>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <boost/lexical_cast.hpp>

#include <QRegExp>

#include "fileio.h"
#include "richelbilderbeekprogram.h"
#include "testtimer.h"
#include "trace.h"
#include "wkttosvgmaindialog.h"
#pragma GCC diagnostic pop

ribi::WktToSvgMenuDialog::WktToSvgMenuDialog()
{
  #ifndef NDEBUG
  Test();
  #endif
}

int ribi::WktToSvgMenuDialog::ExecuteSpecific(const std::vector<std::string>& args) noexcept
{
  const int argc = static_cast<int>(args.size());

  //Verbosity
  bool verbose = false;
  if (std::count(args.begin(),args.end(),"-b") || std::count(args.begin(),args.end(),"--verbose"))
  {
    verbose = true;
    std::cout << "Verbose mode" << std::endl;
  }

  //WKT
  std::string wkt = "";
  for (int i=0; i!=argc-1; ++i)
  {
    if (args[i] == "-w" || args[i] == "--wkt" || args[i] == "--WKT")
    {
      wkt = args[i+1];
      break;
    }
  }
  if (wkt.empty())
  {
    std::cerr << "Please supply a WKT, e.g. 'POLYGON((1 1,1 -1,1 -1))" << std::endl;
    return 1;

  }
  if (verbose)
  {
    std::cout << "WKT: " << wkt << '\n';
  }

  //Stroke width
  double stroke_width = 1.0;
  for (int i=0; i!=argc-1; ++i)
  {
    if (args[i] == "-x" || args[i] == "--stroke_width")
    {
      try
      {
        stroke_width = boost::lexical_cast<double>(args[i+1]);
      }
      catch (boost::bad_lexical_cast&)
      {
        std::cerr
          << "You supplied a stroke width of '" << args[i+1] << "'\n"
          << "Please supply a value of stroke width, for example '1.0'" << std::endl
        ;
        return 1;
      }
      break;
    }
  }
  if (stroke_width <= 0.0)
  {
    std::cerr
      << "You supplied a stroke width of " << stroke_width << '\n'
      << "Please supply a positive value of stroke width" << std::endl;
    return 1;

  }
  if (verbose)
  {
    std::cout << "stroke_width: " << stroke_width << '\n';
  }

  //Silent
  bool silent = false;
  if (std::count(args.begin(),args.end(),"-s") || std::count(args.begin(),args.end(),"--silent"))
  {
    silent = true;
  }

  try
  {
    const WktToSvgMainDialog d(wkt,stroke_width);
    if (!silent)
    {
      std::cout << d.GetSvg() << std::endl;
    }
    return 0;
  }
  catch (std::exception& e)
  {
    std::cerr << "ERROR: Exception caught: " << e.what() << std::endl;
    return 1;
  }
  catch (...)
  {
    std::cerr << "ERROR: Unknown exception caught!" << std::endl;
    return 1;
  }
}

ribi::About ribi::WktToSvgMenuDialog::GetAbout() const noexcept
{
  
  About a(
    "Richel Bilderbeek",
    "WktToSvg",
    "tool to convert WKT to SVG",
    "the 12th of June 2014",
    "2014-2015",
    "http://www.richelbilderbeek.nl/ToolWktToSvg.htm",
    GetVersion(),
    GetVersionHistory()
  );
  a.AddLibrary("FileIo version: " + fileio::FileIo().GetVersion());
  return a;
}

ribi::Help ribi::WktToSvgMenuDialog::GetHelp() const noexcept
{
  return Help(
    this->GetAbout().GetFileTitle(),
    this->GetAbout().GetFileDescription(),
    {
      Help::Option('b',"verbose","generate more output"),
      Help::Option('s',"silent","no final output"),
      Help::Option('w',"wkt","the WTK string"),
      Help::Option('x',"stroke_width","the stroke width (1.0 by default)")
    },
    {
      GetAbout().GetFileTitle() + " --wtk POLYGON((1 1,-1 1,-1 -1,1 -1)) --verbose",
      GetAbout().GetFileTitle() + " -w POLYGON((0 1,-1 -1,1 -1)),LINESTRING((0 -1,-1 1,1 1)) -b",
      GetAbout().GetFileTitle() + " -w LINESTRING((0 -1,-1 1,1 1)) --stroke_width 0.1",
    }
  );
}

boost::shared_ptr<const ribi::Program> ribi::WktToSvgMenuDialog::GetProgram() const noexcept
{
  boost::shared_ptr<const ribi::Program> p {
    new ribi::ProgramWktToSvg
  };
  assert(p);
  return p;
}

std::string ribi::WktToSvgMenuDialog::GetVersion() const noexcept
{
  return "1.3";
}

std::vector<std::string> ribi::WktToSvgMenuDialog::GetVersionHistory() const noexcept
{
  return {
    "2014-06-10: version 1.0: initial version, supports polygon only",
    "2014-06-10: version 1.1: added support for linestring",
    "2014-06-12: version 1.2: added stroke_width parameter",
    "2014-06-12: version 1.3: removed verbose option in desktop version"
  };
}

#ifndef NDEBUG
void ribi::WktToSvgMenuDialog::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  WktToSvgMenuDialog().GetAbout();
  WktToSvgMenuDialog().GetHelp();
  WktToSvgMainDialog("",1.0);
  const TestTimer test_timer(__func__,__FILE__,1.0);
  const bool verbose{false};
  if (verbose) { TRACE("Construction"); }
  {
    WktToSvgMenuDialog d;
  }
  if (verbose) { TRACE("Run with simple polygon"); }
  {
    WktToSvgMenuDialog().Execute(
      {
        "WktToSvgMenuDialog",
        "--wkt", "POLYGON((1 1,-1 1,-1 -1,1 -1))",
        "--silent"
        //"--verbose"
      }
    );
  }
  if (verbose) { TRACE("Run with simple linestring"); }
  {
    WktToSvgMenuDialog().Execute(
      {
        "WktToSvgMenuDialog",
        "--wkt", "LINESTRING(1 1,-1 1,-1 -1,1 -1)",
        "-s"
        //"--verbose"
      }
    );
  }
  if (verbose) { TRACE("Run with simple polygons"); }
  {
    WktToSvgMenuDialog().Execute(
      {
        "WktToSvgMenuDialog",
        "-w", "POLYGON((0 1,-1 -1,1 -1)),POLYGON((0 -1,-1 1,1 1))",
        "-s"
        //"-b"
      }
    );
  }
  if (verbose) { TRACE("Run with simple polygon and linestring"); }
  {
    WktToSvgMenuDialog().Execute(
      {
        "WktToSvgMenuDialog",
        "-w", "POLYGON((0 1,-1 -1,1 -1)),LINESTRING(0 -1,-1 1,1 1,0 -1)",
        "-s",
        //"-b",
        "-x", "3.1415926"
      }
    );
  }
}
#endif

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml