Skip to content

Commit

Permalink
improved compilation performance according to PIMPL idiom
Browse files Browse the repository at this point in the history
  • Loading branch information
gorbatschow committed Apr 26, 2023
1 parent 95ddd5d commit 39674f7
Show file tree
Hide file tree
Showing 40 changed files with 733 additions and 535 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ set(IMOSM_SRC
src/ImOsmRichMarkStorage.cpp
src/ImOsmRichMarkEditorWidget.cpp
src/ImOsmRichMarkItemWidget.cpp
src/ImOsmRichDestinationCalcWidget.cpp
src/ImOsmRichDistanceCalcWidget.cpp
src/ImOsmRichMapPlot.cpp
src/ImOsmTileGrabberWidget.cpp
src/ImOsmTileSourceWidget.cpp
src/ImOsmTileSourceUrlImpl.cpp
src/ImOsmTileSourceFs.cpp
src/ImOsmTileSaver.cpp
)

add_library(${PROJECT_NAME} ${IMOSM_SRC})
Expand Down
14 changes: 7 additions & 7 deletions include/ImOsmCoords.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ struct OsmCoords {
};

struct GeoCoords {
GeoCoords() = default;
GeoCoords(double lat_, double lon_) : lat{lat_}, lon{lon_} {}
GeoCoords(const std::array<double, 2> &arr)
: lat{arr.front()}, lon{arr.back()} {}
GeoCoords(const std::array<float, 2> &arr)
: lat{arr.front()}, lon{arr.back()} {}

double lat{};
double lon{};

Expand All @@ -123,13 +130,6 @@ struct GeoCoords {
return c;
}

GeoCoords() = default;
GeoCoords(double lat_, double lon_) : lat{lat_}, lon{lon_} {}
GeoCoords(const std::array<double, 2> &arr)
: lat{arr.front()}, lon{arr.back()} {}
GeoCoords(const std::array<float, 2> &arr)
: lat{arr.front()}, lon{arr.back()} {}

inline double distance(const GeoCoords &other) const {
return LatLon::distance(lat, lon, other.lat, other.lon);
}
Expand Down
12 changes: 5 additions & 7 deletions include/ImOsmIRichItem.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#pragma once

namespace ImOsm {
class IRichItem
{
namespace Rich {
class IRichItem {
public:
virtual ~IRichItem() = default;

virtual bool inBounds(float minLat,
float maxLat,
float minLon,
float maxLon) const
= 0;
virtual bool inBounds(float minLat, float maxLat, float minLon,
float maxLon) const = 0;
virtual void setEnabled(bool enabled) = 0;
virtual bool enabled() const = 0;
virtual void paint() = 0;
};
} // namespace Rich
} // namespace ImOsm
9 changes: 5 additions & 4 deletions include/ImOsmITile.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once
#include <imgui.h>
#include <vector>

namespace ImOsm {
using ImTextureID = void *;
using size_t = unsigned long;

class ITile {
public:
virtual ~ITile() = default;
Expand All @@ -18,11 +19,11 @@ class ITile {
virtual bool isDummy() const = 0;

virtual const char *rawBlob() const = 0;
virtual std::size_t rawBlobSize() const = 0;
virtual size_t rawBlobSize() const = 0;

virtual void rgbaLoad() const = 0;
virtual const char *rgbaBlob() const = 0;
virtual std::size_t rgbaBlobSize() const = 0;
virtual size_t rgbaBlobSize() const = 0;

virtual ImTextureID texture() const = 0;
};
Expand Down
3 changes: 2 additions & 1 deletion include/ImOsmITileLoader.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
#include <imgui.h>

namespace ImOsm {
using ImTextureID = void *;

class ITileLoader {
public:
virtual ~ITileLoader() = default;
Expand Down
5 changes: 3 additions & 2 deletions include/ImOsmITileSource.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#pragma once
#include "ImOsmITile.h"
#include "ImOsmITileSaver.h"
#include <memory>
#include <vector>

namespace ImOsm {
class ITile;
class ITileSaver;

class ITileSource {
public:
virtual ~ITileSource() = default;
Expand Down
4 changes: 2 additions & 2 deletions include/ImOsmMapPlot.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once
#include "ImOsmCoords.h"
#include "ImOsmITileLoader.h"
#include <implot.h>
#include <memory>

namespace ImOsm {
class ITileLoader;

class MapPlot {
public:
MapPlot();
Expand Down
42 changes: 8 additions & 34 deletions include/ImOsmRichDestinationCalcWidget.h
Original file line number Diff line number Diff line change
@@ -1,47 +1,21 @@
#pragma once
#include "ImOsmRichMarkStorage.h"
#include <memory>
#include <misc/cpp/imgui_stdlib.h>

namespace ImOsm {
namespace Rich {
class DestinationCalcWidget
{
class MarkStorage;

class DestinationCalcWidget {
public:
DestinationCalcWidget(std::shared_ptr<MarkStorage> storage)
: _storage{storage} {}
DestinationCalcWidget(std::shared_ptr<MarkStorage> storage);
~DestinationCalcWidget();

void paint() {
ImGui::PushID(this);
ImGui::TextUnformatted("Destination Calculator");
ImGui::SetNextItemWidth(100.f);
ImGui::InputText("Mark A", &_markNameA);
ImGui::SetNextItemWidth(100.f);
ImGui::InputFloat("Distance [m]##", &_distance, {}, {}, "%.2f");
ImGui::SameLine();
ImGui::SetNextItemWidth(100.f);
ImGui::InputFloat("Bearing [deg]##", &_bearing, {}, {}, "%.2f");
ImGui::SameLine();
if (ImGui::Button("Calculate##")) {
bool foundA{false};
_markA = _storage->findMark(_markNameA, foundA);
if (foundA) {
_markB = _markA.destination(_distance, _bearing);
}
}
ImGui::Text("Destination [deg] Lat: %.6f Lon: %.6f", _markB.lat, _markB.lon);
ImGui::SameLine();
if (ImGui::Button("Pick##")) {
_storage->setPickCoords(_markB);
}
ImGui::PopID();
}
void paint();

private:
struct Ui;
std::unique_ptr<Ui> _ui;
std::shared_ptr<MarkStorage> _storage;
std::string _markNameA;
GeoCoords _markA, _markB;
float _distance{}, _bearing{};
};
} // namespace Rich
} // namespace ImOsm
52 changes: 9 additions & 43 deletions include/ImOsmRichDistanceCalcWidget.h
Original file line number Diff line number Diff line change
@@ -1,56 +1,22 @@
#pragma once
#include "ImOsmRichMarkStorage.h"
#include <imgui.h>
#include <memory>
#include <misc/cpp/imgui_stdlib.h>
#include <string>

namespace ImOsm {
namespace Rich {
class DistanceCalcWidget
{
class MarkStorage;

class DistanceCalcWidget {
public:
DistanceCalcWidget(std::shared_ptr<MarkStorage> storage)
: _storage{storage} {}
DistanceCalcWidget(std::shared_ptr<MarkStorage> storage);
~DistanceCalcWidget();

void paint() {
ImGui::PushID(this);
ImGui::TextUnformatted("D/B/M Calculator");
ImGui::SetNextItemWidth(100.f);
ImGui::InputText("Mark A##", &_markNameA);
ImGui::SameLine();
ImGui::SetNextItemWidth(100.f);
ImGui::InputText("Mark B##", &_markNameB);
ImGui::SameLine();
if (ImGui::Button("Calculate##")) {
bool foundA{false}, foundB{false};
_markA = _storage->findMark(_markNameA, foundA);
_markB = _storage->findMark(_markNameB, foundB);
if (foundA && foundB) {
_distance = _markA.distance(_markB);
_bearing = _markA.bearing(_markB);
_markC = _markA.midpoint(_markB);
}
}
if (_distance < 1e3) {
ImGui::Text("Distance [m] %.2f", _distance);
} else {
ImGui::Text("Distance [km] %.2f", _distance * 1e-3);
}
ImGui::Text("Bearing [deg] %.2f", _bearing);
ImGui::Text("Midpoint [deg] Lat: %.6f Lon: %.6f", _markC.lat, _markC.lon);
ImGui::SameLine();
if (ImGui::Button("Pick##")) {
_storage->setPickCoords(_markC);
}
ImGui::PopID();
}
void paint();

private:
std::string _markNameA, _markNameB;
GeoCoords _markA, _markB, _markC;
std::shared_ptr<MarkStorage> _storage;
double _distance{}, _bearing{};

struct Ui;
std::unique_ptr<Ui> _ui;
};
} // namespace Rich
} // namespace ImOsm
55 changes: 8 additions & 47 deletions include/ImOsmRichMapPlot.h
Original file line number Diff line number Diff line change
@@ -1,61 +1,22 @@
#pragma once
#include "ImOsmIRichItem.h"
#include "ImOsmMapPlot.h"
#include <algorithm>
#include <imgui.h>
#include <ini.h>
#include <iostream>
#include <memory>
#include <vector>

namespace ImOsm {

namespace Rich {
enum class GeoMarkType { Text };
class IRichItem;

class RichMapPlot : public MapPlot {
public:
RichMapPlot() {}
virtual ~RichMapPlot() = default;

void loadState(const mINI::INIStructure &ini) {
if (ini.has("map_plot")) {
if (ini.get("map_plot").has("min_lat") &&
ini.get("map_plot").has("max_lat") &&
ini.get("map_plot").has("min_lon") &&
ini.get("map_plot").has("max_lon")) {
setBoundsGeo(std::stof(ini.get("map_plot").get("min_lat")),
std::stof(ini.get("map_plot").get("max_lat")),
std::stof(ini.get("map_plot").get("min_lon")),
std::stof(ini.get("map_plot").get("max_lon")));
}
}
}

void saveState(mINI::INIStructure &ini) const {
float minLat{}, maxLat{}, minLon{}, maxLon{};
getBoundsGeo(minLat, maxLat, minLon, maxLon);
ini["map_plot"].set("min_lat", std::to_string(minLat));
ini["map_plot"].set("max_lat", std::to_string(maxLat));
ini["map_plot"].set("min_lon", std::to_string(minLon));
ini["map_plot"].set("max_lon", std::to_string(maxLon));
}

virtual void paintOverMap() override {
ImOsm::MapPlot::paintOverMap();

_items.erase(std::remove_if(_items.begin(), _items.end(),
[](auto item) { return item.expired(); }),
_items.end());

std::for_each(_items.begin(), _items.end(), [this](auto ptr) {
auto item{ptr.lock()};
if (item->enabled() &&
item->inBounds(minLat(), maxLat(), minLon(), maxLon()))
item->paint();
});
}
RichMapPlot();
virtual ~RichMapPlot() override;

inline void addItem(std::weak_ptr<IRichItem> item) { _items.push_back(item); }
virtual void paintOverMap() override;
void loadState(const mINI::INIStructure &ini);
void saveState(mINI::INIStructure &ini) const;
void addItem(std::weak_ptr<IRichItem> item);

private:
std::vector<std::weak_ptr<IRichItem>> _items;
Expand Down
23 changes: 8 additions & 15 deletions include/ImOsmRichMarkEditorWidget.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
#pragma once
#include "ImOsmRichMapPlot.h"
#include "ImOsmRichMarkItemWidget.h"
#include "ImOsmRichMarkStorage.h"
#include <array>
#include <imgui.h>
#include <ini.h>

namespace ImOsm {
namespace Rich {
class MarkEditorWidget
{
class RichMapPlot;
class MarkStorage;
class MarkItemWidget;

class MarkEditorWidget {
public:
MarkEditorWidget(std::shared_ptr<RichMapPlot> plot,
std::shared_ptr<MarkStorage> storage);
virtual ~MarkEditorWidget() = default;
~MarkEditorWidget();

void loadState(const mINI::INIStructure &ini);
void saveState(mINI::INIStructure &ini) const;
void paint();

private:
Expand All @@ -27,16 +24,12 @@ class MarkEditorWidget
void paint_markTable();
void paint_markTableRow(const MarkStorage::ItemNode &item);

std::array<float, 2> _latLonInput{0.f, 0.f};
std::shared_ptr<RichMapPlot> _plot;
std::shared_ptr<MarkStorage> _storage;
std::unique_ptr<MarkItemWidget> _itemWidget;

bool _isMousePick{false};
std::string _markNameInputText{};
bool _isMarkAdd{false};

inline static const char _latlonFormat[]{"%.6f"};
struct Ui;
std::unique_ptr<Ui> _ui;
};
} // namespace Rich
} // namespace ImOsm
Loading

0 comments on commit 39674f7

Please sign in to comment.