Skip to content

Commit

Permalink
imp schematic: add next/prev sheet action
Browse files Browse the repository at this point in the history
  • Loading branch information
carrotIndustries committed Apr 13, 2021
1 parent a8301ff commit c2f0bce
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/imp/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ enum class ActionID {
ROTATE_VIEW_RIGHT,
ROTATE_VIEW_RESET,
ROTATE_VIEW,
NEXT_SHEET,
PREV_SHEET,
};

using ActionToolID = std::pair<ActionID, ToolID>;
Expand Down
10 changes: 10 additions & 0 deletions src/imp/action_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,14 @@ const std::map<ActionToolID, ActionCatalogItem> action_catalog = {
{{ActionID::TOOL, ToolID::EDIT_CUSTOM_VALUE},
{"Edit custom value", ActionGroup::SCHEMATIC, ActionCatalogItem::AVAILABLE_IN_SCHEMATIC,
ActionCatalogItem::FLAGS_DEFAULT}},

{{ActionID::NEXT_SHEET, ToolID::NONE},
{"Next sheet", ActionGroup::VIEW, ActionCatalogItem::AVAILABLE_IN_SCHEMATIC,
ActionCatalogItem::FLAGS_DEFAULT}},

{{ActionID::PREV_SHEET, ToolID::NONE},
{"Previous sheet", ActionGroup::VIEW, ActionCatalogItem::AVAILABLE_IN_SCHEMATIC,
ActionCatalogItem::FLAGS_DEFAULT}},
};

const std::vector<std::pair<ActionGroup, std::string>> action_group_catalog = {
Expand Down Expand Up @@ -1042,6 +1050,8 @@ const LutEnumStr<ActionID> action_lut = {
ACTION_LUT_ITEM(ROTATE_VIEW_RIGHT),
ACTION_LUT_ITEM(ROTATE_VIEW_RESET),
ACTION_LUT_ITEM(ROTATE_VIEW),
ACTION_LUT_ITEM(NEXT_SHEET),
ACTION_LUT_ITEM(PREV_SHEET),
};

#define TOOL_LUT_ITEM(x) \
Expand Down
16 changes: 16 additions & 0 deletions src/imp/imp_schematic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ void ImpSchematic::handle_remove_sheet(Sheet *sh)
canvas_update();
}

void ImpSchematic::handle_next_prev_sheet(const ActionConnection &conn)
{
const auto &sch = *core_schematic.get_schematic();
const int sheet_idx_current = core_schematic.get_sheet()->index;
const int inc = conn.action_id == ActionID::PREV_SHEET ? -1 : 1;
const int sheet_idx_next = sheet_idx_current + inc;
auto next_sheet = std::find_if(sch.sheets.begin(), sch.sheets.end(),
[sheet_idx_next](const auto &x) { return (int)x.second.index == sheet_idx_next; });
if (next_sheet != sch.sheets.end()) {
sheet_box->select_sheet(next_sheet->second.uuid);
}
}

void ImpSchematic::update_highlights()
{
std::map<UUID, std::set<ObjectRef>> highlights_for_sheet;
Expand Down Expand Up @@ -320,6 +333,9 @@ void ImpSchematic::construct()
}
});

connect_action(ActionID::PREV_SHEET, sigc::mem_fun(*this, &ImpSchematic::handle_next_prev_sheet));
connect_action(ActionID::NEXT_SHEET, sigc::mem_fun(*this, &ImpSchematic::handle_next_prev_sheet));

if (sockets_connected) {
connect_action(ActionID::TO_BOARD, [this](const auto &conn) {
json j;
Expand Down
1 change: 1 addition & 0 deletions src/imp/imp_schematic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ImpSchematic : public ImpBase {
void handle_tool_change(ToolID id) override;
void handle_move_to_other_sheet(const ActionConnection &conn);
void handle_highlight_group_tag(const ActionConnection &conn);
void handle_next_prev_sheet(const ActionConnection &conn);
std::string last_pdf_filename;

std::map<UUID, std::pair<float, Coordf>> sheet_views;
Expand Down
28 changes: 28 additions & 0 deletions src/imp/keys_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2177,5 +2177,33 @@
]
},
"tool": "NONE"
},
{
"action": "NEXT_SHEET",
"keys": {
"2": [
[
{
"key": "Page_Down",
"mod": 0
}
]
]
},
"tool": "NONE"
},
{
"action": "PREV_SHEET",
"keys": {
"2": [
[
{
"key": "Page_Up",
"mod": 0
}
]
]
},
"tool": "NONE"
}
]

0 comments on commit c2f0bce

Please sign in to comment.