diff --git a/src/core/core_package.cpp b/src/core/core_package.cpp index 46aeb8c5b..373641421 100644 --- a/src/core/core_package.cpp +++ b/src/core/core_package.cpp @@ -89,10 +89,6 @@ std::map *CorePackage::get_picture_map() { return &package.pictures; } -std::map *CorePackage::get_hole_map() -{ - return nullptr; -} std::pair CorePackage::get_bbox() { diff --git a/src/core/core_package.hpp b/src/core/core_package.hpp index ee2dd8a7d..68266d296 100644 --- a/src/core/core_package.hpp +++ b/src/core/core_package.hpp @@ -61,7 +61,6 @@ class CorePackage : public Core, public virtual IDocumentPackage { std::map *get_arc_map() override; std::map *get_text_map() override; std::map *get_polygon_map() override; - std::map *get_hole_map() override; std::map *get_keepout_map() override; std::map *get_dimension_map() override; std::map *get_picture_map() override; diff --git a/src/core/core_padstack.cpp b/src/core/core_padstack.cpp index a93ed5c4b..bf9e7cc89 100644 --- a/src/core/core_padstack.cpp +++ b/src/core/core_padstack.cpp @@ -36,6 +36,43 @@ bool CorePadstack::get_property(ObjectType type, const UUID &uu, ObjectProperty: if (Core::get_property(type, uu, property, value)) return true; switch (type) { + case ObjectType::HOLE: { + auto hole = &padstack.holes.at(uu); + switch (property) { + case ObjectProperty::ID::PLATED: + dynamic_cast(value).value = hole->plated; + return true; + + case ObjectProperty::ID::DIAMETER: + dynamic_cast(value).value = hole->diameter; + return true; + + case ObjectProperty::ID::LENGTH: + dynamic_cast(value).value = hole->length; + return true; + + case ObjectProperty::ID::SHAPE: + dynamic_cast(value).value = static_cast(hole->shape); + return true; + + case ObjectProperty::ID::PARAMETER_CLASS: + dynamic_cast(value).value = hole->parameter_class; + return true; + + case ObjectProperty::ID::SPAN: + dynamic_cast(value).value = hole->span; + return true; + + case ObjectProperty::ID::POSITION_X: + case ObjectProperty::ID::POSITION_Y: + case ObjectProperty::ID::ANGLE: + get_placement(hole->placement, value, property); + return true; + + default: + return false; + } + } break; case ObjectType::SHAPE: { auto shape = &padstack.shapes.at(uu); switch (property) { @@ -88,6 +125,46 @@ bool CorePadstack::set_property(ObjectType type, const UUID &uu, ObjectProperty: if (Core::set_property(type, uu, property, value)) return true; switch (type) { + case ObjectType::HOLE: { + auto hole = &padstack.holes.at(uu); + switch (property) { + case ObjectProperty::ID::PLATED: + hole->plated = dynamic_cast(value).value; + break; + + case ObjectProperty::ID::DIAMETER: + hole->diameter = dynamic_cast(value).value; + break; + + case ObjectProperty::ID::LENGTH: + if (hole->shape != Hole::Shape::SLOT) + return false; + hole->length = dynamic_cast(value).value; + break; + + case ObjectProperty::ID::SHAPE: + hole->shape = static_cast(dynamic_cast(value).value); + break; + + case ObjectProperty::ID::PARAMETER_CLASS: + hole->parameter_class = dynamic_cast(value).value; + break; + + case ObjectProperty::ID::SPAN: + hole->span = dynamic_cast(value).value; + break; + + case ObjectProperty::ID::POSITION_X: + case ObjectProperty::ID::POSITION_Y: + case ObjectProperty::ID::ANGLE: + set_placement(hole->placement, value, property); + break; + + default: + return false; + } + } break; + case ObjectType::SHAPE: { auto shape = &padstack.shapes.at(uu); switch (property) { @@ -146,6 +223,20 @@ bool CorePadstack::get_property_meta(ObjectType type, const UUID &uu, ObjectProp if (Core::get_property_meta(type, uu, property, meta)) return true; switch (type) { + case ObjectType::HOLE: { + auto hole = &padstack.holes.at(uu); + switch (property) { + case ObjectProperty::ID::LENGTH: + meta.is_settable = hole->shape == Hole::Shape::SLOT; + return true; + case ObjectProperty::ID::SPAN: + layers_to_meta(meta); + return true; + default: + return false; + } + } break; + case ObjectType::SHAPE: { auto shape = &padstack.shapes.at(uu); switch (property) { @@ -176,6 +267,9 @@ bool CorePadstack::get_property_meta(ObjectType type, const UUID &uu, ObjectProp std::string CorePadstack::get_display_name(ObjectType type, const UUID &uu) { switch (type) { + case ObjectType::HOLE: + return padstack.holes.at(uu).shape == Hole::Shape::ROUND ? "Round" : "Slot"; + case ObjectType::SHAPE: { auto form = padstack.shapes.at(uu).form; switch (form) { @@ -207,10 +301,6 @@ std::map *CorePadstack::get_polygon_map() { return &padstack.polygons; } -std::map *CorePadstack::get_hole_map() -{ - return &padstack.holes; -} void CorePadstack::rebuild_internal(bool from_undo, const std::string &comment) { diff --git a/src/core/core_padstack.hpp b/src/core/core_padstack.hpp index 3d2b09cfb..e35840a9f 100644 --- a/src/core/core_padstack.hpp +++ b/src/core/core_padstack.hpp @@ -42,7 +42,6 @@ class CorePadstack : public Core, public virtual IDocumentPadstack { private: std::map *get_polygon_map() override; - std::map *get_hole_map() override; Padstack padstack; std::string m_filename; diff --git a/src/core/core_properties.cpp b/src/core/core_properties.cpp index b3009d115..58e33ef48 100644 --- a/src/core/core_properties.cpp +++ b/src/core/core_properties.cpp @@ -25,43 +25,7 @@ namespace horizon { bool Core::get_property(ObjectType type, const UUID &uu, ObjectProperty::ID property, PropertyValue &value) { switch (type) { - case ObjectType::HOLE: { - auto hole = get_hole(uu); - switch (property) { - case ObjectProperty::ID::PLATED: - dynamic_cast(value).value = hole->plated; - return true; - - case ObjectProperty::ID::DIAMETER: - dynamic_cast(value).value = hole->diameter; - return true; - - case ObjectProperty::ID::LENGTH: - dynamic_cast(value).value = hole->length; - return true; - - case ObjectProperty::ID::SHAPE: - dynamic_cast(value).value = static_cast(hole->shape); - return true; - case ObjectProperty::ID::PARAMETER_CLASS: - dynamic_cast(value).value = hole->parameter_class; - return true; - - case ObjectProperty::ID::SPAN: - dynamic_cast(value).value = hole->span; - return true; - - case ObjectProperty::ID::POSITION_X: - case ObjectProperty::ID::POSITION_Y: - case ObjectProperty::ID::ANGLE: - get_placement(hole->placement, value, property); - return true; - - default: - return false; - } - } break; case ObjectType::LINE: { auto line = get_line(uu); @@ -236,46 +200,6 @@ bool Core::get_property(ObjectType type, const UUID &uu, ObjectProperty::ID prop bool Core::set_property(ObjectType type, const UUID &uu, ObjectProperty::ID property, const PropertyValue &value) { switch (type) { - case ObjectType::HOLE: { - auto hole = get_hole(uu); - switch (property) { - case ObjectProperty::ID::PLATED: - hole->plated = dynamic_cast(value).value; - break; - - case ObjectProperty::ID::DIAMETER: - hole->diameter = dynamic_cast(value).value; - break; - - case ObjectProperty::ID::LENGTH: - if (hole->shape != Hole::Shape::SLOT) - return false; - hole->length = dynamic_cast(value).value; - break; - - case ObjectProperty::ID::SHAPE: - hole->shape = static_cast(dynamic_cast(value).value); - break; - - case ObjectProperty::ID::PARAMETER_CLASS: - hole->parameter_class = dynamic_cast(value).value; - break; - - case ObjectProperty::ID::SPAN: - hole->span = dynamic_cast(value).value; - break; - - case ObjectProperty::ID::POSITION_X: - case ObjectProperty::ID::POSITION_Y: - case ObjectProperty::ID::ANGLE: - set_placement(hole->placement, value, property); - break; - - default: - return false; - } - } break; - case ObjectType::LINE: { auto line = get_line(uu); switch (property) { @@ -438,18 +362,6 @@ bool Core::get_property_meta(ObjectType type, const UUID &uu, ObjectProperty::ID { meta.is_settable = true; switch (type) { - case ObjectType::HOLE: - switch (property) { - case ObjectProperty::ID::LENGTH: - meta.is_settable = get_hole(uu)->shape == Hole::Shape::SLOT; - return true; - case ObjectProperty::ID::SPAN: - layers_to_meta(meta); - return true; - default: - return false; - } - break; case ObjectType::TEXT: switch (property) { case ObjectProperty::ID::LAYER: diff --git a/src/core/tools/tool_delete.cpp b/src/core/tools/tool_delete.cpp index 91e902519..199e4c119 100644 --- a/src/core/tools/tool_delete.cpp +++ b/src/core/tools/tool_delete.cpp @@ -252,7 +252,7 @@ ToolResponse ToolDelete::begin(const ToolArgs &args) doc.r->delete_junction(it.uuid); break; case ObjectType::HOLE: - doc.r->delete_hole(it.uuid); + doc.a->get_padstack().holes.erase(it.uuid); break; case ObjectType::PAD: doc.k->get_package().pads.erase(it.uuid); diff --git a/src/core/tools/tool_helper_move.cpp b/src/core/tools/tool_helper_move.cpp index a60ba16c5..3e6ab05c1 100644 --- a/src/core/tools/tool_helper_move.cpp +++ b/src/core/tools/tool_helper_move.cpp @@ -46,7 +46,7 @@ void ToolHelperMove::move_do(const Coordi &delta) doc.r->get_junction(it.uuid)->position += delta; break; case ObjectType::HOLE: - doc.r->get_hole(it.uuid)->placement.shift += delta; + doc.a->get_padstack().holes.at(it.uuid).placement.shift += delta; break; case ObjectType::SYMBOL_PIN: doc.y->get_symbol_pin(it.uuid).position += delta; @@ -342,7 +342,7 @@ void ToolHelperMove::move_mirror_or_rotate(const Coordi ¢er, bool rotate) } break; case ObjectType::HOLE: { - Hole *hole = doc.r->get_hole(it.uuid); + Hole *hole = &doc.a->get_padstack().holes.at(it.uuid); transform(hole->placement.shift, center, rotate); if (rotate) { hole->placement.inc_angle_deg(-90); diff --git a/src/core/tools/tool_move.cpp b/src/core/tools/tool_move.cpp index b2f039d37..3190df55e 100644 --- a/src/core/tools/tool_move.cpp +++ b/src/core/tools/tool_move.cpp @@ -260,7 +260,7 @@ Coordi ToolMove::get_selection_center() accu.accumulate(doc.r->get_junction(it.uuid)->position); break; case ObjectType::HOLE: - accu.accumulate(doc.r->get_hole(it.uuid)->placement.shift); + accu.accumulate(doc.a->get_padstack().holes.at(it.uuid).placement.shift); break; case ObjectType::BOARD_HOLE: accu.accumulate(doc.b->get_board()->holes.at(it.uuid).placement.shift); diff --git a/src/core/tools/tool_paste.cpp b/src/core/tools/tool_paste.cpp index 5a69f4155..488eac999 100644 --- a/src/core/tools/tool_paste.cpp +++ b/src/core/tools/tool_paste.cpp @@ -317,9 +317,12 @@ ToolResponse ToolPaste::really_begin_paste(const json &j, const Coordi &cursor_p const json &o = j["holes"]; for (auto it = o.cbegin(); it != o.cend(); ++it) { auto u = UUID::random(); - auto x = doc.r->insert_hole(u); - *x = Hole(u, it.value()); - transform(x->placement, ObjectType::HOLE); + auto &x = doc.a->get_padstack() + .holes + .emplace(std::piecewise_construct, std::forward_as_tuple(u), + std::forward_as_tuple(u, it.value())) + .first->second; + transform(x.placement, ObjectType::HOLE); selection.emplace(u, ObjectType::HOLE); } } diff --git a/src/core/tools/tool_place_hole.cpp b/src/core/tools/tool_place_hole.cpp index a8f2816a8..a4ba62e18 100644 --- a/src/core/tools/tool_place_hole.cpp +++ b/src/core/tools/tool_place_hole.cpp @@ -9,7 +9,7 @@ namespace horizon { bool ToolPlaceHole::can_begin() { - return doc.r->has_object_type(ObjectType::HOLE); + return doc.a; } ToolResponse ToolPlaceHole::begin(const ToolArgs &args) @@ -27,7 +27,8 @@ ToolResponse ToolPlaceHole::begin(const ToolArgs &args) void ToolPlaceHole::create_hole(const Coordi &c) { - temp = doc.r->insert_hole(UUID::random()); + const auto uu = UUID::random(); + temp = &doc.a->get_padstack().holes.emplace(uu, uu).first->second; temp->placement.shift = c; if (tool_id == ToolID::PLACE_HOLE_SLOT) { temp->shape = Hole::Shape::SLOT; @@ -49,7 +50,7 @@ ToolResponse ToolPlaceHole::update(const ToolArgs &args) case InToolActionID::RMB: case InToolActionID::CANCEL: - doc.r->delete_hole(temp->uuid); + doc.a->get_padstack().holes.erase(temp->uuid); temp = 0; selection.clear(); for (auto it : holes_placed) { diff --git a/src/document/document.cpp b/src/document/document.cpp index 465611a7d..221aa28b7 100644 --- a/src/document/document.cpp +++ b/src/document/document.cpp @@ -130,25 +130,6 @@ void Document::delete_polygon(const UUID &uu) map->erase(uu); } -Hole *Document::insert_hole(const UUID &uu) -{ - auto map = get_hole_map(); - auto x = map->emplace(std::make_pair(uu, uu)); - return &(x.first->second); -} - -Hole *Document::get_hole(const UUID &uu) -{ - auto map = get_hole_map(); - return &map->at(uu); -} - -void Document::delete_hole(const UUID &uu) -{ - auto map = get_hole_map(); - map->erase(uu); -} - Dimension *Document::insert_dimension(const UUID &uu) { auto map = get_dimension_map(); @@ -226,9 +207,6 @@ std::string Document::get_display_name(ObjectType type, const UUID &uu, const UU std::string Document::get_display_name(ObjectType type, const UUID &uu) { switch (type) { - case ObjectType::HOLE: - return get_hole(uu)->shape == Hole::Shape::ROUND ? "Round" : "Slot"; - case ObjectType::TEXT: return get_text(uu)->text; diff --git a/src/document/document.hpp b/src/document/document.hpp index 273611976..f2443eb8b 100644 --- a/src/document/document.hpp +++ b/src/document/document.hpp @@ -24,10 +24,6 @@ class Document : public virtual IDocument { class Polygon *get_polygon(const UUID &uu) override; void delete_polygon(const UUID &uu) override; - class Hole *insert_hole(const UUID &uu) override; - class Hole *get_hole(const UUID &uu) override; - void delete_hole(const UUID &uu) override; - class Dimension *insert_dimension(const UUID &uu) override; class Dimension *get_dimension(const UUID &uu) override; void delete_dimension(const UUID &uu) override; @@ -68,10 +64,6 @@ class Document : public virtual IDocument { { return nullptr; } - virtual std::map *get_hole_map() - { - return nullptr; - } virtual std::map *get_dimension_map() { return nullptr; diff --git a/src/document/idocument.hpp b/src/document/idocument.hpp index fa183d158..f133d4c67 100644 --- a/src/document/idocument.hpp +++ b/src/document/idocument.hpp @@ -26,10 +26,6 @@ class IDocument { virtual class Polygon *get_polygon(const UUID &uu) = 0; virtual void delete_polygon(const UUID &uu) = 0; - virtual class Hole *insert_hole(const UUID &uu) = 0; - virtual class Hole *get_hole(const UUID &uu) = 0; - virtual void delete_hole(const UUID &uu) = 0; - virtual class Dimension *insert_dimension(const UUID &uu) = 0; virtual class Dimension *get_dimension(const UUID &uu) = 0; virtual void delete_dimension(const UUID &uu) = 0; diff --git a/src/imp/imp_hud.cpp b/src/imp/imp_hud.cpp index 4b8a7823c..7d01334b9 100644 --- a/src/imp/imp_hud.cpp +++ b/src/imp/imp_hud.cpp @@ -146,7 +146,7 @@ std::string ImpBase::get_hud_text(std::set &sel) } // Display the delta if two items of these types are selected - for (const ObjectType type : {ObjectType::HOLE, ObjectType::POLYGON_VERTEX, ObjectType::JUNCTION}) { + for (const ObjectType type : {ObjectType::POLYGON_VERTEX, ObjectType::JUNCTION}) { if (sel_count_type(sel, type) == 2) { s += "\n\n2 " + object_descriptions.at(type).name_pl + ""; std::vector positions; @@ -157,10 +157,6 @@ std::string ImpBase::get_hud_text(std::set &sel) const auto vertex = &poly->vertices.at(iter.vertex); positions.push_back(vertex->position); } - else if (type == ObjectType::HOLE) { - const auto hole = core->get_hole(iter.uuid); - positions.push_back(hole->placement.shift); - } else if (type == ObjectType::JUNCTION) { const auto junction = core->get_junction(iter.uuid); positions.push_back(junction->position);