VIPRA Documentation
Loading...
Searching...
No Matches
dxf.hpp
1#pragma once
2#include "vipra/macros/parameters.hpp"
3#define _USE_MATH_DEFINES
4
5#include <cmath>
6#include <filesystem>
7#include <optional>
8#include <string>
9
10#include "vipra/geometry/polygon.hpp"
11#include "vipra/macros/module.hpp"
12#include "vipra/modules/map_input.hpp"
13#include "vipra/modules/serializable.hpp"
14
15#include "drw_reader.hpp"
16
17/* ERRORS:
180 BAD_NONE
191 BAD_UNKNOWN
202 BAD_OPEN
213 BAD_VERSION
224 BAD_READ_METADATA
235 BAD_READ_FILE_HEADER
246 BAD_READ_HEADER
257 BAD_READ_HANDLES
268 BAD_READ_CLASSES
279 BAD_READ_TABLES
2810 BAD_READ_BLOCKS
2911 BAD_READ_ENTITIES
3012 BAD_READ_OBJECTS
3113 BAD_READ_SECTION
3214 BAD_CODE_PARSED
33*/
34
40class DXF : public VIPRA::Modules::Module<DXF>,
43 public:
44 VIPRA_MODULE_NAME("DXF");
45 VIPRA_MODULE_TYPE(MapInput);
46
47 VIPRA_REGISTER_PARAMS()
48
49 void load(std::string const& filepath) override;
50
51 // TODO(rolland): implement
52 [[nodiscard]] auto serialize() -> std::string override { return ""; }
53 void parse(std::string const& /*data*/) override {}
54
55 [[nodiscard]] auto get_obstacles() const
56 -> std::optional<std::vector<VIPRA::Geometry::Polygon>> override;
57 [[nodiscard]] auto get_spawns() const
58 -> std::optional<std::vector<VIPRA::Geometry::Polygon>> override;
59 [[nodiscard]] auto get_objectives() const
60 -> std::optional<
61 std::map<std::string, std::vector<VIPRA::Geometry::Polygon>>> override;
62 [[nodiscard]] auto get_areas() const
63 -> std::optional<std::map<std::string, VIPRA::Geometry::Polygon>> override;
64
65 [[nodiscard]] auto get_objective_types(std::vector<std::string> const& keys) const
66 -> std::optional<std::vector<std::string>>
67 {
68 if ( keys.size() != 1 ) return std::nullopt;
69 if ( keys[0] != "obj_types" ) return std::nullopt;
70
71 std::vector<std::string> types;
72 types.reserve(_objectives.size());
73
74 for ( auto const& [type, coords] : _objectives ) {
75 types.push_back(type);
76 }
77
78 return {types};
79 }
80
81 [[nodiscard]] static auto get_polygons(
82 std::vector<std::shared_ptr<DRW_Vertex>>& vertexList)
83 -> std::optional<std::vector<VIPRA::Geometry::Polygon>>;
84
85 private:
86 std::filesystem::path _filepath;
87
88 std::map<std::string, std::vector<VIPRA::Geometry::Polygon>> _objectives;
89 std::vector<VIPRA::Geometry::Polygon> _obstacles;
90 std::vector<VIPRA::Geometry::Polygon> _spawns;
91
92 std::map<std::string, VIPRA::Geometry::Polygon> _areas;
93
94 VIPRA::DrwReader _drwReader;
95};
Parameter and Polygon qualified dxf input module.
Definition dxf.hpp:42
void load(std::string const &filepath) override
Loads the DXF file from the given path.
Definition dxf.cpp:62
auto get_obstacles() const -> std::optional< std::vector< VIPRA::Geometry::Polygon > > override
Returns obstacles geometry from the .dxf file.
Definition dxf.cpp:16
auto get_objectives() const -> std::optional< std::map< std::string, std::vector< VIPRA::Geometry::Polygon > > > override
Returns Objectives map from the .dxf file.
Definition dxf.cpp:36
auto get_areas() const -> std::optional< std::map< std::string, VIPRA::Geometry::Polygon > > override
Returns spawn area geometry from the .dxf file.
Definition dxf.cpp:47
auto get_spawns() const -> std::optional< std::vector< VIPRA::Geometry::Polygon > > override
Returns spawn area geometry from the .dxf file.
Definition dxf.cpp:26
Base MapInput Module.
Definition map_input.hpp:15
VIPRA Module Base CRTP Class.
Definition module.hpp:36
Definition serializable.hpp:7
Definition drw_reader.hpp:13