Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) TestPolyFileFromPolygons

 

TestPolyFileFromPolygons is a tool to test the PolyFileFromPolygons class.

 

 

 

 

 

Downloads

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./ToolTestPolyFileFromPolygons/ToolTestPolyFileFromPolygonsConsole.pro

 

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

include(../../Classes/CppContainer/CppContainer.pri)
include(../../Classes/CppCoordinat/CppCoordinat.pri)
include(../../Classes/CppFuzzy_equal_to/CppFuzzy_equal_to.pri)
include(../../Classes/CppGeometry/CppGeometry.pri)
include(../../Classes/CppPlane/CppPlane.pri)
include(../../Classes/CppPolyFile/CppPolyFile.pri)
include(../../Classes/CppPolyFileFromPolygons/CppPolyFileFromPolygons.pri)
include(../../Classes/CppRibiRegex/CppRibiRegex.pri)
include(../../Classes/CppXml/CppXml.pri)

include(../../Tools/ToolTestPolyFileFromPolygons/ToolTestPolyFileFromPolygonsConsole.pri)

SOURCES += main.cpp

 

 

 

 

 

Qt project file: ./ToolTestPolyFileFromPolygons/ToolTestPolyFileFromPolygonsDesktop.pro

 

include(../../DesktopApplication.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/CppPolyFile/CppPolyFile.pri)
include(../../Classes/CppPolyFileFromPolygons/CppPolyFileFromPolygons.pri)

#Desktop
include(../../Classes/CppQtNavigationableGraphicsView/CppQtNavigationableGraphicsView.pri)
include(../../Tools/ToolTestPolyFileFromPolygons/ToolTestPolyFileFromPolygonsDesktop.pri)
include(../../Tools/ToolWktToSvg/ToolWktToSvgConsole.pri)

SOURCES += qtmain.cpp

 

 

 

 

 

Qt project file: ./ToolTestPolyFileFromPolygons/ToolTestPolyFileFromPolygonsWebsite.pro

 

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

 

 

 

 

 

./ToolTestPolyFileFromPolygons/ToolTestPolyFileFromPolygonsConsole.pri

 

INCLUDEPATH += ../../Tools/ToolTestPolyFileFromPolygons

HEADERS += \
    ../../Tools/ToolTestPolyFileFromPolygons/testpolyfilefrompolygonsmaindialog.h \
    ../../Tools/ToolTestPolyFileFromPolygons/testpolyfilefrompolygonsmenudialog.h

SOURCES += \
    ../../Tools/ToolTestPolyFileFromPolygons/testpolyfilefrompolygonsmaindialog.cpp \
    ../../Tools/ToolTestPolyFileFromPolygons/testpolyfilefrompolygonsmenudialog.cpp

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

 

 

 

 

 

./ToolTestPolyFileFromPolygons/ToolTestPolyFileFromPolygonsDesktop.pri

 

include(../../Tools/ToolTestPolyFileFromPolygons/ToolTestPolyFileFromPolygonsConsole.pri)

SOURCES += \
    ../../Tools/ToolTestPolyFileFromPolygons/qttestpolyfilefrompolygonsmenudialog.cpp \
    ../../Tools/ToolTestPolyFileFromPolygons/qttestpolyfilefrompolygonsmaindialog.cpp

FORMS += \
    ../../Tools/ToolTestPolyFileFromPolygons/qttestpolyfilefrompolygonsmenudialog.ui \
    ../../Tools/ToolTestPolyFileFromPolygons/qttestpolyfilefrompolygonsmaindialog.ui

HEADERS += \
    ../../Tools/ToolTestPolyFileFromPolygons/qttestpolyfilefrompolygonsmenudialog.h \
    ../../Tools/ToolTestPolyFileFromPolygons/qttestpolyfilefrompolygonsmaindialog.h

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

 

 

 

 

 

./ToolTestPolyFileFromPolygons/ToolTestPolyFileFromPolygonsWebsite.pri

 

include(../../Tools/ToolTestPolyFileFromPolygons/ToolTestPolyFileFromPolygonsConsole.pri)

HEADERS +=

SOURCES +=

 

 

 

 

 

./ToolTestPolyFileFromPolygons/main.cpp

 

#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 "testpolyfilefrompolygonsmenudialog.h"
#pragma GCC diagnostic pop

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

}

 

 

 

 

 

./ToolTestPolyFileFromPolygons/qtmain.cpp

 

//---------------------------------------------------------------------------
/*
TestPolyFileFromPolygons, tests the PolyFileFromPolygons class
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/ToolTestPolyFileFromPolygons.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 "qttestpolyfilefrompolygonsmenudialog.h"
#include "trace.h"
#pragma GCC diagnostic pop

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

 

 

 

 

 

./ToolTestPolyFileFromPolygons/qttestpolyfilefrompolygonsmaindialog.h

 

//---------------------------------------------------------------------------
/*
TestPolyFileFromPolygons, tests the PolyFileFromPolygons class
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/ToolTestPolyFileFromPolygons.htm
//---------------------------------------------------------------------------
#ifndef QTTRIANGLEMESHCREATORMAINDIALOG_H
#define QTTRIANGLEMESHCREATORMAINDIALOG_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/linestring.hpp>
#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"
#pragma GCC diagnostic pop

struct QPlainTextEdit;

namespace Ui {
  class QtTestPolyFileFromPolygonsMainDialog;
}

namespace ribi {

class QtTestPolyFileFromPolygonsMainDialog : public QtHideAndShowDialog
{
  Q_OBJECT

public:

  explicit QtTestPolyFileFromPolygonsMainDialog(QWidget *parent = 0) noexcept;
  QtTestPolyFileFromPolygonsMainDialog(const QtTestPolyFileFromPolygonsMainDialog&) = delete;
  QtTestPolyFileFromPolygonsMainDialog& operator=(const QtTestPolyFileFromPolygonsMainDialog&) = delete;
  ~QtTestPolyFileFromPolygonsMainDialog() noexcept;

  typedef boost::geometry::model::d2::point_xy<double> Coordinat2D;
  typedef boost::geometry::model::polygon<Coordinat2D> Polygon;
  typedef boost::geometry::model::linestring<Coordinat2D> Linestring;
  typedef std::vector<Polygon> Polygons;
  typedef std::vector<Linestring> Linestrings;
  typedef std::pair<Polygons,Linestrings> Shapes;
  Shapes GetShapes() const noexcept;

protected:
  void keyPressEvent(QKeyEvent *) noexcept;

private:
  Ui::QtTestPolyFileFromPolygonsMainDialog *ui;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
  //static std::vector<std::string> SeperateString(
  //  const std::string& input,
  //  const char seperator = '\n'
  //) noexcept;

private slots:

  void DisplayPolyFile() noexcept;
  void DisplayPolygons() noexcept;

  void on_edit_shapes_textChanged();
};

} //~namespace ribi

#endif // QTTRIANGLEMESHCREATORMAINDIALOG_H

 

 

 

 

 

./ToolTestPolyFileFromPolygons/qttestpolyfilefrompolygonsmaindialog.cpp

 

//---------------------------------------------------------------------------
/*
TestPolyFileFromPolygons, tests the PolyFileFromPolygons class
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/ToolTestPolyFileFromPolygons.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 "qttestpolyfilefrompolygonsmaindialog.h"

#include <fstream>
#include <stdexcept>

#include <QGraphicsSvgItem>
#include <QKeyEvent>

#include "container.h"
#include "fileio.h"
#include "geometry.h"
#include "polyfilefrompolygons.h"
#include "qtnavigationablegraphicsview.h"
#include "testtimer.h"
#include "testpolyfilefrompolygonsmaindialog.h"
#include "trace.h"
#include "ui_qttestpolyfilefrompolygonsmaindialog.h"
#include "wkttosvgmaindialog.h"

#pragma GCC diagnostic pop

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

  on_edit_shapes_textChanged();
}

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

void ribi::QtTestPolyFileFromPolygonsMainDialog::DisplayPolyFile() noexcept
{
  const auto shapes = GetShapes();

  const std::string filename = fileio::FileIo().GetTempFileName(".poly");
  {
    PolyFileFromPolygons polyfile(shapes.first,shapes.second);
    std::ofstream f(filename.c_str());
    f << polyfile.ToStr();
  }
  const auto text = fileio::FileIo().FileToVector(filename);
  std::string s;
  for (const auto line: text) { s += line + '\n'; }
  s.pop_back();
  ui->text_file->setPlainText(s.c_str());

  fileio::FileIo().DeleteFile(filename);
}

void ribi::QtTestPolyFileFromPolygonsMainDialog::DisplayPolygons() noexcept
{
  assert(ui->view->scene());
  ui->view->scene()->clear();
  const std::string svg_filename = fileio::FileIo().GetTempFileName(".svg");
  {
    const std::string text_with_comments = ui->edit_shapes->toPlainText().toStdString();
    const auto v = Container().SeperateString(text_with_comments,'\n');
    std::string text;
    for (const auto s: v)
    {
      std::string t = boost::algorithm::trim_copy(s);
      if (!t.empty() && t[0] != '#') text += t + '\n';
    }
    const double stroke_width = 1.0;
    const WktToSvgMainDialog d(text,stroke_width);
    std::ofstream f(svg_filename.c_str());
    f << d.GetSvg();
  }
  {
    QGraphicsSvgItem * const item = new QGraphicsSvgItem(svg_filename.c_str());
    item->setScale(1.0);
    ui->view->scene()->addItem(item);
  }
  fileio::FileIo().DeleteFile(svg_filename);
}



ribi::QtTestPolyFileFromPolygonsMainDialog::Shapes
  ribi::QtTestPolyFileFromPolygonsMainDialog::GetShapes() const noexcept
{
  Shapes shapes;
  const std::string text = ui->edit_shapes->toPlainText().toStdString();
  const std::vector<std::string> lines = Container().SeperateString(text,'\n');
  for (const std::string line: lines)
  {
    try
    {
      Polygon polygon;
      boost::geometry::read_wkt(line,polygon);
      shapes.first.push_back(polygon);
    }
    catch (boost::geometry::read_wkt_exception&)
    {
      //No problem
    }
    try
    {
      Linestring linestring;
      boost::geometry::read_wkt(line,linestring);
      shapes.second.push_back(linestring);
    }
    catch (boost::geometry::read_wkt_exception&)
    {
      //No problem
    }
  }
  return shapes;
}

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

void ribi::QtTestPolyFileFromPolygonsMainDialog::on_edit_shapes_textChanged()
{
  DisplayPolyFile();
  DisplayPolygons();
}

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

 

 

 

 

 

./ToolTestPolyFileFromPolygons/qttestpolyfilefrompolygonsmenudialog.h

 

//---------------------------------------------------------------------------
/*
TestPolyFileFromPolygons, tests the PolyFileFromPolygons class
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/ToolTestPolyFileFromPolygons.htm
//---------------------------------------------------------------------------
#ifndef QTTESTPOLYFILEFROMPOLYGONSMENUDIALOG_H
#define QTTESTPOLYFILEFROMPOLYGONSMENUDIALOG_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 QtTestPolyFileFromPolygonsMenuDialog;
}

namespace ribi {

class QtTestPolyFileFromPolygonsMenuDialog : public QtHideAndShowDialog
{
  Q_OBJECT

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

protected:
  void keyPressEvent(QKeyEvent * event) noexcept;

private:
  Ui::QtTestPolyFileFromPolygonsMenuDialog *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 // QTTESTPOLYFILEFROMPOLYGONSMENUDIALOG_H

 

 

 

 

 

./ToolTestPolyFileFromPolygons/qttestpolyfilefrompolygonsmenudialog.cpp

 

//---------------------------------------------------------------------------
/*
TestPolyFileFromPolygons, tests the PolyFileFromPolygons class
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/ToolTestPolyFileFromPolygons.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 "qttestpolyfilefrompolygonsmenudialog.h"

#include <QDesktopWidget>
#include <QKeyEvent>

#include "testpolyfilefrompolygonsmenudialog.h"
#include "qtaboutdialog.h"
#include "testtimer.h"
#include "qttestpolyfilefrompolygonsmaindialog.h"
#include "qthideandshowdialog.h"
#include "trace.h"
#include "ui_qttestpolyfilefrompolygonsmenudialog.h"
#pragma GCC diagnostic pop

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

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

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

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

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

void ribi::QtTestPolyFileFromPolygonsMenuDialog::on_button_start_clicked() noexcept
{
  QtTestPolyFileFromPolygonsMainDialog d;
  ShowChild(&d);
}

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

 

 

 

 

 

./ToolTestPolyFileFromPolygons/testpolyfilefrompolygonsmaindialog.h

 

//---------------------------------------------------------------------------
/*
TestPolyFileFromPolygons, tests the PolyFileFromPolygons class
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/ToolTestPolyFileFromPolygons.htm
//---------------------------------------------------------------------------
#ifndef RIBI_TESTPOLYFILEFROMPOLYGONSMAINDIALOG_H
#define RIBI_TESTPOLYFILEFROMPOLYGONSMAINDIALOG_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.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/shared_ptr.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>
#pragma GCC diagnostic pop

namespace ribi {

///Converts shapes to a .poly file its content (using operator<<
struct TestPolyFileFromPolygonsMainDialog
{
  typedef boost::geometry::model::d2::point_xy<double> Point;
  typedef boost::geometry::model::polygon<Point> Polygon;
  typedef std::vector<Polygon> Polygons;


  TestPolyFileFromPolygonsMainDialog(const Polygons& polygons);
  const Polygons& GetPolygons() const noexcept { return m_polygons; }

  private:
  const Polygons m_polygons;

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

std::ostream& operator<<(std::ostream& os, const TestPolyFileFromPolygonsMainDialog& dialog) noexcept;

} //~namespace ribi

#endif // RIBI_TESTPOLYFILEFROMPOLYGONSMAINDIALOG_H

 

 

 

 

 

./ToolTestPolyFileFromPolygons/testpolyfilefrompolygonsmaindialog.cpp

 

//---------------------------------------------------------------------------
/*
TestPolyFileFromPolygons, tests the PolyFileFromPolygons class
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/ToolTestPolyFileFromPolygons.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 "testpolyfilefrompolygonsmaindialog.h"

#include <fstream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>

#include "fileio.h"
#include "geometry.h"
#include "polyfilefrompolygons.h"
#include "trace.h"
#include "testtimer.h"
#pragma GCC diagnostic pop

ribi::TestPolyFileFromPolygonsMainDialog::TestPolyFileFromPolygonsMainDialog(
  const Polygons& polygons
) : m_polygons(polygons)
{
  #ifndef NDEBUG
  Test();
  #endif
}

#ifndef NDEBUG
void ribi::TestPolyFileFromPolygonsMainDialog::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  {
    PolyFile( {}, {} );
    PolyFileFromPolygons( {}, {} );
    Geometry();
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
  const auto polygon = Geometry().CreateShapeTriangle();
  const Polygons polygons = { polygon };
  TestPolyFileFromPolygonsMainDialog d(polygons);
  std::stringstream s;
  s << d;
  assert(!s.str().empty());
}
#endif

std::ostream& ribi::operator<<(std::ostream& os, const TestPolyFileFromPolygonsMainDialog& dialog) noexcept
{
  PolyFileFromPolygons file(dialog.GetPolygons());
  os << file.ToStr();
  return os;

}

 

 

 

 

 

./ToolTestPolyFileFromPolygons/testpolyfilefrompolygonsmenudialog.h

 

//---------------------------------------------------------------------------
/*
TestPolyFileFromPolygons, tests the PolyFileFromPolygons class
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/ToolTestPolyFileFromPolygons.htm
//---------------------------------------------------------------------------
#ifndef RIBI_TESTPOLYFILEFROMPOLYGONSMENUDIALOG_H
#define RIBI_TESTPOLYFILEFROMPOLYGONSMENUDIALOG_H

#include <string>
#include <vector>

#include "menudialog.h"

struct QRegExp;

namespace ribi {

///GUI independent TestPolyFileFromPolygons menu dialog
struct TestPolyFileFromPolygonsMenuDialog final : public MenuDialog
{
  TestPolyFileFromPolygonsMenuDialog();
  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_TESTPOLYFILEFROMPOLYGONSMENUDIALOG_H

 

 

 

 

 

./ToolTestPolyFileFromPolygons/testpolyfilefrompolygonsmenudialog.cpp

 

//---------------------------------------------------------------------------
/*
TestPolyFileFromPolygons, tests the PolyFileFromPolygons class
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/ToolTestPolyFileFromPolygons.htm
//---------------------------------------------------------------------------
#include "testpolyfilefrompolygonsmenudialog.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 <boost/units/io.hpp>

#include "ribi_regex.h"
#include "container.h"
#include "fileio.h"
#include "geometry.h"
#include "richelbilderbeekprogram.h"
#include "trace.h"
#include "testtimer.h"
#include "plane.h"
#include "polyfile.h"
#include "polyfilefrompolygons.h"
#include "testpolyfilefrompolygonsmaindialog.h"
#pragma GCC diagnostic pop

ribi::TestPolyFileFromPolygonsMenuDialog::TestPolyFileFromPolygonsMenuDialog()
{
  #ifndef NDEBUG
  Test();
  #endif
}
int ribi::TestPolyFileFromPolygonsMenuDialog::ExecuteSpecific(const std::vector<std::string>& args) noexcept
{
  bool silent{false};
  if (std::count(args.begin(),args.end(),"-s") || std::count(args.begin(),args.end(),"--silent"))
  {
    silent = true;
  }

  typedef boost::geometry::model::d2::point_xy<double> Coordinat;
  typedef boost::geometry::model::polygon<Coordinat> Polygon;

  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;
    if (!silent) { std::cout << "Verbose mode" << std::endl; }
  }

  //Polygons
  if (!std::count(args.begin(),args.end(),"-p")
    && !std::count(args.begin(),args.end(),"--polygon")
    && !std::count(args.begin(),args.end(),"--polygons")
  )
  {
    if (!silent) { std::cerr << "Parameter for polygons missing" << '\n'; }
    return 1;
  }

  std::vector<Polygon> polygons;
  for (int i=0; i!=argc-1; ++i)
  {
    if (args[i] == "-p" || args[i] == "--polygon" || args[i] == "--polygons")
    {
      const std::string text = args[i+1];
      if (verbose) { std::cout << "Parsing polygons '" << text << "'" << std::endl; }
      const auto regex = Regex().GetRegexPolygon();
      const auto lines = Regex().GetRegexMatches(text,regex);
      for (const std::string& line: lines)
      {
        if (verbose) { std::cout << "Parsing polygon '" << line << "'" << std::endl; }
        Polygon polygon;
        try
        {
          boost::geometry::read_wkt(line,polygon);
          polygons.push_back(polygon);
        }
        catch (boost::geometry::read_wkt_exception& e)
        {
          //No problem
        }
      }
    }
  }
  if (polygons.empty())
  {
    if (!silent) { std::cerr << "Please supply a value for polygon, e.g. 'POLYGON((1 1,1 -1,1 -1))" << std::endl; }
    return 1;

  }
  if (verbose)
  {
    if (!silent) {
      std::cout << "Number of polygons: " << polygons.size() << std::endl
        << "Polygons (as SVG text): " << Geometry().ToSvg(polygons) << std::endl;
    }
  }

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

ribi::About ribi::TestPolyFileFromPolygonsMenuDialog::GetAbout() const noexcept
{
  
  About a(
    "Richel Bilderbeek",
    "TestPolyFileFromPolygons",
    "tests the PolyFileFromPolygons class",
    "the 12th of June 2014",
    "2014-2015",
    "http://www.richelbilderbeek.nl/ToolTestPolyFileFromPolygons.htm",
    GetVersion(),
    GetVersionHistory()
  );
  a.AddLibrary("Container version: " + Container().GetVersion());
  a.AddLibrary("FileIo version: " + fileio::FileIo().GetVersion());
  a.AddLibrary("Geometry version: " + Geometry().GetVersion());
  a.AddLibrary("Plane version: " + Plane::GetVersion());
  a.AddLibrary("PolyFile version: " + PolyFile::GetVersion());
  a.AddLibrary("PolyFileFromPolygons version: " + PolyFileFromPolygons::GetVersion());
  return a;
}

ribi::Help ribi::TestPolyFileFromPolygonsMenuDialog::GetHelp() const noexcept
{
  return Help(
    this->GetAbout().GetFileTitle(),
    this->GetAbout().GetFileDescription(),
    {
      Help::Option('b',"verbose","generate more output"),
      Help::Option('p',"polygons","the shapes used as a base"),
      Help::Option('s',"silent","produce no output")
    },
    {
      GetAbout().GetFileTitle() + " --polygons POLYGON((1 1,-1 1,-1 -1,1 -1)) --verbose",
      GetAbout().GetFileTitle() + " -p POLYGON((0 1,-1 -1,1 -1)),POLYGON((0 -1,-1 1,1 1)) -b",
    }
  );
}

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


std::string ribi::TestPolyFileFromPolygonsMenuDialog::GetVersion() const noexcept
{
  return "1.2";
}

std::vector<std::string> ribi::TestPolyFileFromPolygonsMenuDialog::GetVersionHistory() const noexcept
{
  return {
    "2014-06-02: version 1.0: initial version, supported polygons only",
    "2014-06-12: version 1.1: added support for linestring",
    "2014-08-08: version 1.2: added silent flag to console version"
  };
}

#ifndef NDEBUG
void ribi::TestPolyFileFromPolygonsMenuDialog::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  {
    Container();
    fileio::FileIo();
    boost::shared_ptr<Plane> plane{
      new Plane(
        Plane::Coordinat3D(1.0,0.0,0.0),
        Plane::Coordinat3D(0.0,1.0,0.0),
        Plane::Coordinat3D(0.0,0.0,1.0)
      )
    };
    TestPolyFileFromPolygonsMainDialog( {} );
  }
  const bool verbose{false};
  const TestTimer test_timer(__func__,__FILE__,1.0);
  {
    TestPolyFileFromPolygonsMenuDialog d;
    if (verbose) { TRACE("Create triangle with long notation"); }
    d.Execute(
      {
        "TestPolyFileFromPolygonsMenuDialog",
        "--polygons",
        "POLYGON((0 0,0 1,1 0))",
        "--silent"
      }
    );
    if (verbose) { TRACE("Create two triangles with short notation"); }
    d.Execute(
      {
        "TestPolyFileFromPolygonsMenuDialog",
        "-p",
        "POLYGON((0 0,0 1,1 0)),POLYGON((1 1,1 2,2 1))",
        "--silent"
      }
    );
  }
}
#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