Skip to content

Commit

Permalink
add panelisation
Browse files Browse the repository at this point in the history
also adds outline notes layer
  • Loading branch information
carrotIndustries committed Mar 8, 2020
1 parent 611304e commit 188802f
Show file tree
Hide file tree
Showing 47 changed files with 1,014 additions and 96 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ SRC_COMMON = \
src/common/keepout.cpp\
src/board/board_layers.cpp\
src/pool/pool_parametric.cpp \
src/board/included_board.cpp \
src/board/board_panel.cpp \
src/pool/pool_cached.cpp\

ifeq ($(OS),Windows_NT)
SRC_COMMON += src/util/uuid_win32.cpp
Expand Down Expand Up @@ -238,6 +241,8 @@ SRC_IMP = \
src/core/tools/tool_fix.cpp\
src/core/tools/tool_nopopulate.cpp\
src/core/tools/tool_polygon_to_line_loop.cpp\
src/core/tools/tool_place_board_panel.cpp\
src/core/tools/tool_smash_panel_outline.cpp\
src/document/documents.cpp\
src/core/clipboard.cpp\
src/core/buffer.cpp\
Expand Down Expand Up @@ -271,6 +276,8 @@ SRC_IMP = \
src/dialogs/ask_datum_angle.cpp\
src/dialogs/tool_window.cpp\
src/dialogs/renumber_pads_window.cpp\
src/dialogs/select_included_board.cpp\
src/dialogs/manage_included_boards.cpp\
src/util/sort_controller.cpp\
src/core/core_symbol.cpp\
src/core/core_schematic.cpp\
Expand Down Expand Up @@ -405,6 +412,7 @@ SRC_IMP = \
src/imp/search/searcher_schematic.cpp\
src/imp/search/searcher_package.cpp\
src/imp/search/searcher_board.cpp\
src/util/clipper_util.cpp\

SRC_IMPC = \
3rd_party/footag/wiz.c\
Expand Down
61 changes: 57 additions & 4 deletions src/board/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,22 @@ Board::Board(const UUID &uu, const json &j, Block &iblock, Pool &pool, ViaPadsta
Logger::Domain::BOARD);
}
}
if (j.count("included_boards")) {
const json &o = j["included_boards"];
for (auto it = o.cbegin(); it != o.cend(); ++it) {
auto u = UUID(it.key());
load_and_log(included_boards, ObjectType::BOARD, std::forward_as_tuple(u, it.value()),
Logger::Domain::BOARD);
}
}
if (j.count("board_panels")) {
const json &o = j["board_panels"];
for (auto it = o.cbegin(); it != o.cend(); ++it) {
auto u = UUID(it.key());
load_and_log(board_panels, ObjectType::BOARD, std::forward_as_tuple(u, it.value(), *this),
Logger::Domain::BOARD);
}
}
if (j.count("rules")) {
try {
rules.load_from_json(j.at("rules"));
Expand Down Expand Up @@ -259,10 +275,10 @@ const std::map<int, Layer> &Board::get_layers() const

Board::Board(const Board &brd, CopyMode copy_mode)
: layers(brd.layers), uuid(brd.uuid), block(brd.block), name(brd.name), polygons(brd.polygons), holes(brd.holes),
junctions(brd.junctions), tracks(brd.tracks), airwires(brd.airwires), texts(brd.texts), lines(brd.lines),
arcs(brd.arcs), planes(brd.planes), keepouts(brd.keepouts), dimensions(brd.dimensions),
connection_lines(brd.connection_lines), warnings(brd.warnings), rules(brd.rules),
fab_output_settings(brd.fab_output_settings), stackup(brd.stackup), colors(brd.colors),
junctions(brd.junctions), tracks(brd.tracks), texts(brd.texts), lines(brd.lines), arcs(brd.arcs),
planes(brd.planes), keepouts(brd.keepouts), dimensions(brd.dimensions), connection_lines(brd.connection_lines),
included_boards(brd.included_boards), board_panels(brd.board_panels), warnings(brd.warnings), rules(brd.rules),
fab_output_settings(brd.fab_output_settings), airwires(brd.airwires), stackup(brd.stackup), colors(brd.colors),
pdf_export_settings(brd.pdf_export_settings), step_export_settings(brd.step_export_settings),
pnp_export_settings(brd.pnp_export_settings), n_inner_layers(brd.n_inner_layers)
{
Expand Down Expand Up @@ -342,6 +358,9 @@ void Board::update_refs()
for (auto &it : connection_lines) {
it.second.update_refs(*this);
}
for (auto &it : board_panels) {
it.second.included_board.update(included_boards);
}
}

unsigned int Board::get_n_inner_layers() const
Expand All @@ -354,6 +373,7 @@ void Board::set_n_inner_layers(unsigned int n)
n_inner_layers = n;
layers.clear();
layers = {{200, {200, "Top Notes"}},
{BoardLayers::OUTLINE_NOTES, {BoardLayers::OUTLINE_NOTES, "Outline Notes"}},
{100, {100, "Outline"}},
{60, {60, "Top Courtyard"}},
{50, {50, "Top Assembly"}},
Expand Down Expand Up @@ -399,6 +419,7 @@ void Board::update_pdf_export_settings(PDFExportSettings &settings)
std::forward_as_tuple(l, Color(0, 0, 0), PDFExportSettings::Layer::Mode::OUTLINE, enable));
};

add_layer(BoardLayers::OUTLINE_NOTES);
add_layer(BoardLayers::L_OUTLINE);
add_layer(BoardLayers::TOP_PASTE, false);
add_layer(BoardLayers::TOP_SILKSCREEN, false);
Expand Down Expand Up @@ -931,6 +952,26 @@ void Board::smash_package_silkscreen_graphics(BoardPackage *pkg)
pkg->omit_silkscreen = true;
}

void Board::smash_panel_outline(BoardPanel &panel)
{
for (const auto &it : panel.included_board->board->polygons) {
if (it.second.layer == BoardLayers::L_OUTLINE) {
auto uu = UUID::random();
auto &new_poly = polygons.emplace(uu, uu).first->second;
new_poly.layer = BoardLayers::L_OUTLINE;
for (const auto &it_v : it.second.vertices) {
new_poly.vertices.emplace_back();
auto &v = new_poly.vertices.back();
v.arc_center = panel.placement.transform(it_v.arc_center);
v.arc_reverse = it_v.arc_reverse;
v.type = it_v.type;
v.position = panel.placement.transform(it_v.position);
}
}
}
panel.omit_outline = true;
}

void Board::unsmash_package(BoardPackage *pkg)
{
if (!pkg->smashed)
Expand Down Expand Up @@ -1106,6 +1147,18 @@ json Board::serialize() const
for (const auto &it : connection_lines) {
j["connection_lines"][(std::string)it.first] = it.second.serialize();
}
if (included_boards.size()) {
j["included_boards"] = json::object();
for (const auto &it : included_boards) {
j["included_boards"][(std::string)it.first] = it.second.serialize();
}
}
if (board_panels.size()) {
j["board_panels"] = json::object();
for (const auto &it : board_panels) {
j["board_panels"][(std::string)it.first] = it.second.serialize();
}
}
return j;
}
} // namespace horizon
5 changes: 5 additions & 0 deletions src/board/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "step_export_settings.hpp"
#include "pnp_export_settings.hpp"
#include "airwire.hpp"
#include "included_board.hpp"
#include "board_panel.hpp"
#include <fstream>
#include <map>
#include <vector>
Expand Down Expand Up @@ -66,6 +68,7 @@ class Board : public ObjectProvider, public LayerProvider {
void copy_package_silkscreen_texts(BoardPackage *dest, const BoardPackage *src);
void unsmash_package(BoardPackage *pkg);
void smash_package_silkscreen_graphics(BoardPackage *pkg);
void smash_panel_outline(BoardPanel &panel);

Junction *get_junction(const UUID &uu) override;
Polygon *get_polygon(const UUID &uu) override;
Expand Down Expand Up @@ -97,6 +100,8 @@ class Board : public ObjectProvider, public LayerProvider {
std::map<UUID, Keepout> keepouts;
std::map<UUID, Dimension> dimensions;
std::map<UUID, ConnectionLine> connection_lines;
std::map<UUID, IncludedBoard> included_boards;
std::map<UUID, BoardPanel> board_panels;

std::vector<Warning> warnings;

Expand Down
18 changes: 11 additions & 7 deletions src/board/board_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ std::string BoardLayers::get_layer_name(int l)
case TOP_NOTES:
return "Top Notes";

case OUTLINE_NOTES:
return "Outline Notes";

case L_OUTLINE:
return "Outline";

Expand Down Expand Up @@ -65,13 +68,14 @@ std::string BoardLayers::get_layer_name(int l)
}

static const std::vector<int> layers = {
BoardLayers::TOP_NOTES, BoardLayers::L_OUTLINE, BoardLayers::TOP_COURTYARD,
BoardLayers::TOP_ASSEMBLY, BoardLayers::TOP_PACKAGE, BoardLayers::TOP_PASTE,
BoardLayers::TOP_SILKSCREEN, BoardLayers::TOP_MASK, BoardLayers::TOP_COPPER,
BoardLayers::IN1_COPPER, BoardLayers::IN2_COPPER, BoardLayers::IN3_COPPER,
BoardLayers::IN4_COPPER, BoardLayers::BOTTOM_COPPER, BoardLayers::BOTTOM_MASK,
BoardLayers::BOTTOM_SILKSCREEN, BoardLayers::BOTTOM_PASTE, BoardLayers::BOTTOM_PACKAGE,
BoardLayers::BOTTOM_ASSEMBLY, BoardLayers::BOTTOM_COURTYARD, BoardLayers::BOTTOM_NOTES};
BoardLayers::TOP_NOTES, BoardLayers::OUTLINE_NOTES, BoardLayers::L_OUTLINE,
BoardLayers::TOP_COURTYARD, BoardLayers::TOP_ASSEMBLY, BoardLayers::TOP_PACKAGE,
BoardLayers::TOP_PASTE, BoardLayers::TOP_SILKSCREEN, BoardLayers::TOP_MASK,
BoardLayers::TOP_COPPER, BoardLayers::IN1_COPPER, BoardLayers::IN2_COPPER,
BoardLayers::IN3_COPPER, BoardLayers::IN4_COPPER, BoardLayers::BOTTOM_COPPER,
BoardLayers::BOTTOM_MASK, BoardLayers::BOTTOM_SILKSCREEN, BoardLayers::BOTTOM_PASTE,
BoardLayers::BOTTOM_PACKAGE, BoardLayers::BOTTOM_ASSEMBLY, BoardLayers::BOTTOM_COURTYARD,
BoardLayers::BOTTOM_NOTES};

const std::vector<int> &BoardLayers::get_layers()
{
Expand Down
1 change: 1 addition & 0 deletions src/board/board_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class BoardLayers {
public:
enum Layer {
TOP_NOTES = 200,
OUTLINE_NOTES = 110,
L_OUTLINE = 100,
TOP_COURTYARD = 60,
TOP_ASSEMBLY = 50,
Expand Down
25 changes: 25 additions & 0 deletions src/board/board_panel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "board_panel.hpp"
#include "nlohmann/json.hpp"
#include "board.hpp"

namespace horizon {
BoardPanel::BoardPanel(const UUID &uu, const json &j, const Board &brd)
: uuid(uu), included_board(&brd.included_boards.at(UUID(j.at("included_board").get<std::string>()))),
placement(j.at("placement")), omit_outline(j.value("omit_outline", false))
{
}
BoardPanel::BoardPanel(const UUID &uu, const IncludedBoard &inc) : uuid(uu), included_board(&inc)
{
}


json BoardPanel::serialize() const
{
json j;
j["included_board"] = (std::string)included_board->uuid;
j["placement"] = placement.serialize();
j["omit_outline"] = omit_outline;
return j;
}

} // namespace horizon
17 changes: 17 additions & 0 deletions src/board/board_panel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include "included_board.hpp"

namespace horizon {
class BoardPanel {
public:
BoardPanel(const UUID &uu, const json &j, const Board &brd);
BoardPanel(const UUID &uu, const IncludedBoard &inc);

json serialize() const;

UUID uuid;
uuid_ptr<const IncludedBoard> included_board;
Placement placement;
bool omit_outline = false;
};
} // namespace horizon
92 changes: 92 additions & 0 deletions src/board/included_board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include "included_board.hpp"
#include "nlohmann/json.hpp"
#include "project/project.hpp"
#include "pool/pool_manager.hpp"
#include "board/board.hpp"
#include "pool/entity.hpp"
#include "pool/part.hpp"
#include "pool/symbol.hpp"
#include "block/block.hpp"
#include "board/via_padstack_provider.hpp"
#include "pool/pool_cached.hpp"

namespace horizon {
IncludedBoard::IncludedBoard(const UUID &uu, const Project &prj, const std::string &p) : uuid(uu), project_filename(p)
{
reload();
}

IncludedBoard::IncludedBoard(const UUID &uu, const json &j)
: IncludedBoard(uu, j.at("project_filename").get<std::string>())
{
}

IncludedBoard::IncludedBoard(const UUID &uu, const std::string &prj_filename)
: IncludedBoard(uu, Project::new_from_file(prj_filename), prj_filename)
{
}

IncludedBoard::IncludedBoard(const IncludedBoard &other)
: uuid(other.uuid), project_filename(other.project_filename),
pool(std::make_unique<PoolCached>(other.pool->get_base_path(), other.pool->get_cache_path())),
block(std::make_unique<Block>(*other.block)), vpp(std::make_unique<ViaPadstackProvider>(*other.vpp)),
board(std::make_unique<Board>(*other.board))
{
board->block = block.get();
board->update_refs();
}

void IncludedBoard::reload()
{
auto prj = Project::new_from_file(project_filename);
reset();

try {
pool = std::make_unique<PoolCached>(horizon::PoolManager::get().get_by_uuid(prj.pool_uuid)->base_path,
prj.pool_cache_directory);
block = std::make_unique<Block>(horizon::Block::new_from_file(prj.get_top_block().block_filename, *pool));
vpp = std::make_unique<ViaPadstackProvider>(prj.vias_directory, *pool);
board = std::make_unique<Board>(horizon::Board::new_from_file(prj.board_filename, *block, *pool, *vpp));
board->expand();
}
catch (...) {
reset();
throw;
}
}

void IncludedBoard::reset()
{
pool.reset();
block.reset();
board.reset();
vpp.reset();
}

bool IncludedBoard::is_valid() const
{
return board != nullptr;
}

json IncludedBoard::serialize() const
{
json j;
j["project_filename"] = project_filename;
return j;
}

std::string IncludedBoard::get_name() const
{
if (!is_valid())
return "invalid";
else if (block->project_meta.count("project_title"))
return block->project_meta.at("project_title");
else
return "unknown";
}

UUID IncludedBoard::get_uuid() const
{
return uuid;
}
} // namespace horizon
33 changes: 33 additions & 0 deletions src/board/included_board.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once
#include "util/uuid.hpp"
#include "nlohmann/json_fwd.hpp"
#include "pool/pool_cached.hpp"
#include <memory>

namespace horizon {
using json = nlohmann::json;

class IncludedBoard {
public:
IncludedBoard(const UUID &uu, const json &j);
IncludedBoard(const UUID &uu, const std::string &p);
IncludedBoard(const IncludedBoard &other);
json serialize() const;
UUID get_uuid() const;
std::string get_name() const;
void reload();
bool is_valid() const;

UUID uuid;
std::string project_filename;

std::unique_ptr<class PoolCached> pool;
std::unique_ptr<class Block> block;
std::unique_ptr<class ViaPadstackProvider> vpp;
std::unique_ptr<class Board> board;

private:
IncludedBoard(const UUID &uu, const class Project &prj, const std::string &p);
void reset();
};
} // namespace horizon

0 comments on commit 188802f

Please sign in to comment.