Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: imp board: exclude packages from STEP export #722

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/board/step_export_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ namespace horizon {

STEPExportSettings::STEPExportSettings(const json &j)
: filename(j.at("filename").get<std::string>()), prefix(j.at("prefix").get<std::string>()),
include_3d_models(j.at("include_3d_models"))
include_3d_models(j.at("include_3d_models")), min_diameter(j.value("min_diameter", 0_mm))
{
auto excllist = j.value("pkgs_excluded", json::array());

for (const auto &excluuid : excllist) {
if (!excluuid.is_string())
continue;

pkgs_excluded.emplace(excluuid.get<std::string>());
}
}

json STEPExportSettings::serialize() const
Expand All @@ -16,6 +24,17 @@ json STEPExportSettings::serialize() const
j["filename"] = filename;
j["prefix"] = prefix;
j["include_3d_models"] = include_3d_models;
if (min_diameter)
j["min_diameter"] = min_diameter;
if (pkgs_excluded.size()) {
auto excllist = json::array();

for (const auto &uuid : pkgs_excluded) {
excllist.push_back(uuid);
}

j["pkgs_excluded"] = excllist;
}
return j;
}

Expand Down
3 changes: 3 additions & 0 deletions src/board/step_export_settings.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <set>
#include "common/common.hpp"
#include "common/lut.hpp"
#include "nlohmann/json_fwd.hpp"
Expand All @@ -18,5 +19,7 @@ class STEPExportSettings {
std::string filename;
std::string prefix;
bool include_3d_models = true;
uint64_t min_diameter;
std::set<UUID> pkgs_excluded;
};
} // namespace horizon
14 changes: 11 additions & 3 deletions src/export_step/export_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ static TopoDS_Shape face_from_polyon(const Polygon &poly)

class CanvasHole : public Canvas {
public:
CanvasHole(TopTools_ListOfShape &cs) : cutouts(cs)
CanvasHole(TopTools_ListOfShape &cs, uint64_t mdia = 0) : cutouts(cs), min_diameter(mdia)
{
img_mode = true;
}

private:
TopTools_ListOfShape &cutouts;
uint64_t min_diameter;

void img_hole(const class Hole &hole) override
{
if (hole.diameter == 0)
Expand All @@ -115,6 +117,9 @@ class CanvasHole : public Canvas {
Placement tr = transform;
tr.accumulate(hole.placement);
if (hole.shape == Hole::Shape::ROUND) {
if (hole.diameter < min_diameter)
return;

auto ax = gp_Ax2(gp_Pnt(tr.shift.x / 1e6, tr.shift.y / 1e6, 0), gp_Dir(0, 0, 1));
auto circ = gp_Circ(ax, hole.diameter / 2e6);
auto edge = BRepBuilderAPI_MakeEdge(circ);
Expand Down Expand Up @@ -402,7 +407,7 @@ static bool getModelLabel(const std::string &aFileName, TDF_Label &aLabel, Handl

void export_step(const std::string &filename, const Board &brd, class IPool &pool, bool include_models,
std::function<void(const std::string &)> progress_cb, const BoardColors *colors,
const std::string &prefix)
const std::string &prefix, uint64_t min_diameter, std::set<UUID> *pkgs_excluded)
{
try {
auto app = XCAFApp_Application::GetApplication();
Expand Down Expand Up @@ -430,7 +435,7 @@ void export_step(const std::string &filename, const Board &brd, class IPool &poo

progress_cb("Holes…");
{
CanvasHole canvas_hole(cutouts);
CanvasHole canvas_hole(cutouts, min_diameter);
canvas_hole.update(brd);
}
for (const auto &hole : outline.holes) {
Expand Down Expand Up @@ -498,6 +503,9 @@ void export_step(const std::string &filename, const Board &brd, class IPool &poo
if (package.component && package.component->nopopulate) {
continue;
}
if (pkgs_excluded && (pkgs_excluded->find(package.package.uuid) != pkgs_excluded->end())) {
continue;
}
pkgs.push_back(&package);
}
auto n_pkg = std::to_string(pkgs.size());
Expand Down
5 changes: 4 additions & 1 deletion src/export_step/export_step.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#pragma once
#include <string>
#include <functional>
#include <set>
#include "util/uuid.hpp"
#include "common/common.hpp"

namespace horizon {
void export_step(const std::string &filename, const class Board &brd, class IPool &pool, bool include_models,
std::function<void(const std::string &)> progress_cb, const class BoardColors *colors = nullptr,
const std::string &prefix = "");
const std::string &prefix = "", uint64_t min_diameter = 0_mm, std::set<UUID> *pkgs_excluded = nullptr);
}
195 changes: 192 additions & 3 deletions src/imp/step_export.ui
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-next-symbolic</property>
</object>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-previous-symbolic</property>
</object>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<property name="default_height">400</property>
Expand Down Expand Up @@ -45,6 +55,7 @@
<property name="orientation">vertical</property>
<property name="spacing">20</property>
<child>
<!-- n-columns=3 n-rows=4 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
Expand Down Expand Up @@ -80,7 +91,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
Expand All @@ -93,7 +104,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
Expand Down Expand Up @@ -160,13 +171,191 @@
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Minimum hole/via ø</property>
<property name="xalign">1</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkBox" id="min_dia_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Exclude circular holes or vias from STEP export if they are smaller than the given diameter. Holes/vias of this size or larger are included (i.e. greater-or-equal comparison.) Has no effect on non-circular structures like slots or manually drawn outline polygons.

Setting this to zero (the default) includes all holes.</property>
<property name="halign">start</property>
<property name="orientation">vertical</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<!-- n-columns=3 n-rows=2 -->
<object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="column_spacing">10</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_bottom">5</property>
<property name="vexpand">False</property>
<property name="label" translatable="yes">Included packages</property>
<property name="xalign">0</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">Excluded packages</property>
<property name="xalign">0</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin_top">20</property>
<property name="margin_bottom">20</property>
<property name="orientation">vertical</property>
<property name="spacing">10</property>
<child>
<object class="GtkButton" id="pkg_excl_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">image1</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="pkg_incl_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_bottom">5</property>
<property name="image">image2</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="pkgs_included_tv">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="search-column">0</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">multiple</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="pkgs_excluded_tv">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">False</property>
<property name="search-column">0</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">multiple</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="visible">True</property>
Expand Down
Loading