Skip to content

Commit

Permalink
remove IDocument::get_hole
Browse files Browse the repository at this point in the history
was only used in padstacks after all
  • Loading branch information
carrotIndustries committed Jul 24, 2024
1 parent 512bba8 commit eabff88
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 147 deletions.
4 changes: 0 additions & 4 deletions src/core/core_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ std::map<UUID, Picture> *CorePackage::get_picture_map()
{
return &package.pictures;
}
std::map<UUID, Hole> *CorePackage::get_hole_map()
{
return nullptr;
}

std::pair<Coordi, Coordi> CorePackage::get_bbox()
{
Expand Down
1 change: 0 additions & 1 deletion src/core/core_package.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class CorePackage : public Core, public virtual IDocumentPackage {
std::map<UUID, Arc> *get_arc_map() override;
std::map<UUID, Text> *get_text_map() override;
std::map<UUID, Polygon> *get_polygon_map() override;
std::map<UUID, Hole> *get_hole_map() override;
std::map<UUID, Keepout> *get_keepout_map() override;
std::map<UUID, Dimension> *get_dimension_map() override;
std::map<UUID, Picture> *get_picture_map() override;
Expand Down
98 changes: 94 additions & 4 deletions src/core/core_padstack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PropertyValueBool &>(value).value = hole->plated;
return true;

case ObjectProperty::ID::DIAMETER:
dynamic_cast<PropertyValueInt &>(value).value = hole->diameter;
return true;

case ObjectProperty::ID::LENGTH:
dynamic_cast<PropertyValueInt &>(value).value = hole->length;
return true;

case ObjectProperty::ID::SHAPE:
dynamic_cast<PropertyValueInt &>(value).value = static_cast<int>(hole->shape);
return true;

case ObjectProperty::ID::PARAMETER_CLASS:
dynamic_cast<PropertyValueString &>(value).value = hole->parameter_class;
return true;

case ObjectProperty::ID::SPAN:
dynamic_cast<PropertyValueLayerRange &>(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) {
Expand Down Expand Up @@ -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<const PropertyValueBool &>(value).value;
break;

case ObjectProperty::ID::DIAMETER:
hole->diameter = dynamic_cast<const PropertyValueInt &>(value).value;
break;

case ObjectProperty::ID::LENGTH:
if (hole->shape != Hole::Shape::SLOT)
return false;
hole->length = dynamic_cast<const PropertyValueInt &>(value).value;
break;

case ObjectProperty::ID::SHAPE:
hole->shape = static_cast<Hole::Shape>(dynamic_cast<const PropertyValueInt &>(value).value);
break;

case ObjectProperty::ID::PARAMETER_CLASS:
hole->parameter_class = dynamic_cast<const PropertyValueString &>(value).value;
break;

case ObjectProperty::ID::SPAN:
hole->span = dynamic_cast<const PropertyValueLayerRange &>(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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -207,10 +301,6 @@ std::map<UUID, Polygon> *CorePadstack::get_polygon_map()
{
return &padstack.polygons;
}
std::map<UUID, Hole> *CorePadstack::get_hole_map()
{
return &padstack.holes;
}

void CorePadstack::rebuild_internal(bool from_undo, const std::string &comment)
{
Expand Down
1 change: 0 additions & 1 deletion src/core/core_padstack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class CorePadstack : public Core, public virtual IDocumentPadstack {

private:
std::map<UUID, Polygon> *get_polygon_map() override;
std::map<UUID, Hole> *get_hole_map() override;

Padstack padstack;
std::string m_filename;
Expand Down
88 changes: 0 additions & 88 deletions src/core/core_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PropertyValueBool &>(value).value = hole->plated;
return true;

case ObjectProperty::ID::DIAMETER:
dynamic_cast<PropertyValueInt &>(value).value = hole->diameter;
return true;

case ObjectProperty::ID::LENGTH:
dynamic_cast<PropertyValueInt &>(value).value = hole->length;
return true;

case ObjectProperty::ID::SHAPE:
dynamic_cast<PropertyValueInt &>(value).value = static_cast<int>(hole->shape);
return true;

case ObjectProperty::ID::PARAMETER_CLASS:
dynamic_cast<PropertyValueString &>(value).value = hole->parameter_class;
return true;

case ObjectProperty::ID::SPAN:
dynamic_cast<PropertyValueLayerRange &>(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);
Expand Down Expand Up @@ -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<const PropertyValueBool &>(value).value;
break;

case ObjectProperty::ID::DIAMETER:
hole->diameter = dynamic_cast<const PropertyValueInt &>(value).value;
break;

case ObjectProperty::ID::LENGTH:
if (hole->shape != Hole::Shape::SLOT)
return false;
hole->length = dynamic_cast<const PropertyValueInt &>(value).value;
break;

case ObjectProperty::ID::SHAPE:
hole->shape = static_cast<Hole::Shape>(dynamic_cast<const PropertyValueInt &>(value).value);
break;

case ObjectProperty::ID::PARAMETER_CLASS:
hole->parameter_class = dynamic_cast<const PropertyValueString &>(value).value;
break;

case ObjectProperty::ID::SPAN:
hole->span = dynamic_cast<const PropertyValueLayerRange &>(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) {
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/core/tools/tool_delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/core/tools/tool_helper_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -342,7 +342,7 @@ void ToolHelperMove::move_mirror_or_rotate(const Coordi &center, 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);
Expand Down
2 changes: 1 addition & 1 deletion src/core/tools/tool_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/core/tools/tool_paste.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/core/tools/tool_place_hole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
22 changes: 0 additions & 22 deletions src/document/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
Loading

0 comments on commit eabff88

Please sign in to comment.