Skip to content

Commit

Permalink
add in-tool actions and convert all tools to them
Browse files Browse the repository at this point in the history
  • Loading branch information
carrotIndustries committed Jul 16, 2020
1 parent 09161dc commit 07283ce
Show file tree
Hide file tree
Showing 125 changed files with 3,321 additions and 1,165 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ SRC_IMP = \
src/imp/selection_filter_dialog.cpp\
src/imp/action.cpp\
src/imp/action_catalog.cpp\
src/imp/in_tool_action_catalog.cpp\
$(SRC_CANVAS) \
src/document/document.cpp \
src/document/document_board.cpp \
Expand Down Expand Up @@ -591,12 +592,15 @@ SRC_POOL_PRJ_MGR = \
src/preferences/preferences_util.cpp\
src/pool-prj-mgr/preferences/preferences_window.cpp\
src/pool-prj-mgr/preferences/preferences_window_keys.cpp\
src/pool-prj-mgr/preferences/preferences_window_in_tool_keys.cpp\
src/pool-prj-mgr/preferences/preferences_window_canvas.cpp\
src/pool-prj-mgr/preferences/preferences_window_pool.cpp\
src/pool-prj-mgr/preferences/preferences_window_partinfo.cpp\
src/pool-prj-mgr/preferences/preferences_window_misc.cpp\
src/pool-prj-mgr/preferences/action_editor.cpp\
src/imp/action.cpp\
src/imp/action_catalog.cpp\
src/imp/in_tool_action_catalog.cpp\
src/widgets/unit_info_box.cpp\
src/widgets/entity_info_box.cpp\
src/widgets/padstack_preview.cpp\
Expand Down
3 changes: 3 additions & 0 deletions imp.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<file>util/window_state_schema.sql</file>
<file>imp/layer_display_default.json</file>
<file>imp/keys_default.json</file>
<file>imp/in_tool_keys_default.json</file>
<file>imp/app_menu.ui</file>
<file>pool-prj-mgr/preferences/preferences.ui</file>
<file>property_panels/property_panel.ui</file>
Expand Down Expand Up @@ -68,6 +69,8 @@
<file preprocess="xml-stripblanks">icons/scalable/actions/action-place-via-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/action-route-track-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/action-route-diffpair-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/action-lmb-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/action-rmb-symbolic.svg</file>
<file>icons/scalable/apps/horizon-eda.svg</file>
<file>icons/16x16/apps/horizon-eda.png</file>
<file>icons/32x32/apps/horizon-eda.png</file>
Expand Down
8 changes: 8 additions & 0 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ std::set<SelectableRef> &Core::get_tool_selection()
return tool_selection;
}

std::set<InToolActionID> Core::get_tool_actions() const
{
if (tool)
return tool->get_actions();
else
return {};
}

std::pair<bool, bool> Core::tool_can_begin(ToolID tool_id, const std::set<SelectableRef> &sel)
{
auto t = create_tool(tool_id);
Expand Down
2 changes: 2 additions & 0 deletions src/core/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class Core : public virtual Document {
std::set<SelectableRef> &get_tool_selection();
Pool *m_pool;

std::set<InToolActionID> get_tool_actions() const;

bool get_needs_save() const;
void set_needs_save();

Expand Down
8 changes: 7 additions & 1 deletion src/core/tool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include "tool_data.hpp"
#include "nlohmann/json_fwd.hpp"
#include "document/documents.hpp"
#include "imp/in_tool_action.hpp"
#include <set>
#include <memory>

namespace horizon {
using json = nlohmann::json;

enum class ToolEventType { NONE, MOVE, CLICK, CLICK_RELEASE, KEY, LAYER_CHANGE, DATA };
enum class ToolEventType { NONE, MOVE, CLICK, CLICK_RELEASE, KEY, ACTION, LAYER_CHANGE, DATA };

enum class ToolID;

Expand All @@ -27,6 +28,7 @@ class ToolArgs {
bool keep_selection = false;
unsigned int button = 0;
unsigned int key = 0;
InToolActionID action = InToolActionID::NONE;
enum Modifieres {
MOD_FINE = (1 << 0),
MOD_ALT = (1 << 1),
Expand Down Expand Up @@ -145,6 +147,10 @@ class ToolBase {
{
}

virtual std::set<InToolActionID> get_actions() const
{
return {};
}

/**
* Gets called right after the constructor has finished.
Expand Down
41 changes: 25 additions & 16 deletions src/core/tools/tool_add_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,23 @@ ToolResponse ToolAddPart::begin(const ToolArgs &args)
selection.emplace(sym_current->uuid, ObjectType::SCHEMATIC_SYMBOL);
move_init(args.coords);
current_gate = 0;
update_tip();

return ToolResponse();
}

void ToolAddPart::update_tip()
{
imp->tool_bar_set_actions({
{InToolActionID::LMB, "place"},
{InToolActionID::RMB, "cancel"},
{InToolActionID::ROTATE},
{InToolActionID::MIRROR},
});

std::stringstream ss;
ss << "<b>LMB:</b>place <b>RMB:</b>cancel <b>r:</b>rotate <b>e:</b>mirror "
"<i>placing gate ";
ss << current_gate + 1 << "/" << gates.size() << "</i>";
ss << "placing gate ";
ss << current_gate + 1 << "/" << gates.size();
imp->tool_bar_set_tip(ss.str());
}

Expand All @@ -99,8 +106,9 @@ ToolResponse ToolAddPart::update(const ToolArgs &args)
if (args.type == ToolEventType::MOVE) {
move_do_cursor(args.coords);
}
else if (args.type == ToolEventType::CLICK) {
if (args.button == 1) {
else if (args.type == ToolEventType::ACTION) {
switch (args.action) {
case InToolActionID::LMB:
doc.c->get_schematic()->autoconnect_symbol(doc.c->get_sheet(), sym_current);
if (sym_current->component->connections.size() == 0) {
doc.c->get_schematic()->place_bipole_on_line(doc.c->get_sheet(), sym_current);
Expand Down Expand Up @@ -143,23 +151,24 @@ ToolResponse ToolAddPart::update(const ToolArgs &args)
return ToolResponse();
}
}
}
else {
break;

case InToolActionID::RMB:
case InToolActionID::CANCEL:
if (current_gate == 0) { // also delete the component
doc.c->get_block()->components.erase(comp->uuid);
}
doc.c->delete_schematic_symbol(sym_current->uuid);
sym_current = nullptr;
return ToolResponse::commit();
}
}
else if (args.type == ToolEventType::KEY) {
if (args.key == GDK_KEY_Escape) {
return ToolResponse::revert();
}
else if (args.key == GDK_KEY_r || args.key == GDK_KEY_e) {
bool rotate = args.key == GDK_KEY_r;
move_mirror_or_rotate(sym_current->placement.shift, rotate);
break;

case InToolActionID::MIRROR:
case InToolActionID::ROTATE:
move_mirror_or_rotate(sym_current->placement.shift, args.action == InToolActionID::ROTATE);
break;

default:;
}
}
update_tip();
Expand Down
8 changes: 8 additions & 0 deletions src/core/tools/tool_add_part.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ class ToolAddPart : public ToolHelperMapSymbol, public ToolHelperMove {
ToolResponse begin(const ToolArgs &args) override;
ToolResponse update(const ToolArgs &args) override;
bool can_begin() override;
std::set<InToolActionID> get_actions() const override
{
using I = InToolActionID;
return {
I::LMB, I::CANCEL, I::RMB, I::ROTATE, I::MIRROR,
};
}


class ToolDataAddPart : public ToolData {
public:
Expand Down
23 changes: 12 additions & 11 deletions src/core/tools/tool_add_vertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,28 @@ ToolResponse ToolAddVertex::begin(const ToolArgs &args)
vertex = &*poly->vertices.insert(poly->vertices.begin() + v_next, args.coords);
selection.clear();
selection.emplace(poly->uuid, ObjectType::POLYGON_VERTEX, v_next);
imp->tool_bar_set_tip("<b>LMB:</b>place vertex <b>RMB:</b>cancel");
imp->tool_bar_set_actions({
{InToolActionID::LMB, "place vertex"},
{InToolActionID::RMB, "cancel"},
});
return ToolResponse();
}
ToolResponse ToolAddVertex::update(const ToolArgs &args)
{
if (args.type == ToolEventType::MOVE) {
vertex->position = args.coords;
}
else if (args.type == ToolEventType::CLICK) {
if (args.button == 1) {
else if (args.type == ToolEventType::ACTION) {
switch (args.action) {
case InToolActionID::LMB:
return ToolResponse::commit();
}
else if (args.button == 3) {
selection.clear();
return ToolResponse::revert();
}
}
else if (args.type == ToolEventType::KEY) {
if (args.key == GDK_KEY_Escape) {

case InToolActionID::RMB:
case InToolActionID::CANCEL:
selection.clear();
return ToolResponse::revert();

default:;
}
}
return ToolResponse();
Expand Down
9 changes: 9 additions & 0 deletions src/core/tools/tool_add_vertex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ class ToolAddVertex : public ToolBase {
{
return true;
}
std::set<InToolActionID> get_actions() const override
{
using I = InToolActionID;
return {
I::LMB,
I::CANCEL,
I::RMB,
};
}

private:
class Polygon *poly = nullptr;
Expand Down
22 changes: 12 additions & 10 deletions src/core/tools/tool_bend_line_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,27 @@ ToolResponse ToolBendLineNet::begin(const ToolArgs &args)

LineNet *li = &doc.c->get_sheet()->net_lines.at(it->uuid);
doc.c->get_sheet()->split_line_net(li, temp);
imp->tool_bar_set_tip("<b>LMB:</b>place junction <b>RMB:</b>cancel");
imp->tool_bar_set_actions({
{InToolActionID::LMB},
{InToolActionID::RMB},
});
return ToolResponse();
}
ToolResponse ToolBendLineNet::update(const ToolArgs &args)
{
if (args.type == ToolEventType::MOVE) {
temp->position = args.coords;
}
else if (args.type == ToolEventType::CLICK) {
if (args.button == 1) {
else if (args.type == ToolEventType::ACTION) {
switch (args.action) {
case InToolActionID::LMB:
return ToolResponse::commit();
}
else if (args.button == 3) {
return ToolResponse::revert();
}
}
else if (args.type == ToolEventType::KEY) {
if (args.key == GDK_KEY_Escape) {

case InToolActionID::RMB:
case InToolActionID::CANCEL:
return ToolResponse::revert();

default:;
}
}
return ToolResponse();
Expand Down
9 changes: 9 additions & 0 deletions src/core/tools/tool_bend_line_net.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ class ToolBendLineNet : public ToolBase {
{
return true;
}
std::set<InToolActionID> get_actions() const override
{
using I = InToolActionID;
return {
I::LMB,
I::CANCEL,
I::RMB,
};
}

private:
class Junction *temp = 0;
Expand Down
18 changes: 10 additions & 8 deletions src/core/tools/tool_copy_placement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#include "document/idocument_board.hpp"
#include "board/board.hpp"
#include "imp/imp_interface.hpp"
#include <iostream>
#include "util/util.hpp"
#include "util/selection_util.hpp"

namespace horizon {

Expand All @@ -15,20 +16,21 @@ bool ToolCopyPlacement::can_begin()
if (!doc.b)
return false;

return std::count_if(selection.begin(), selection.end(),
[](const auto &x) { return x.type == ObjectType::BOARD_PACKAGE; })
> 0;
return sel_count_type(selection, ObjectType::BOARD_PACKAGE) > 0;
}

ToolResponse ToolCopyPlacement::begin(const ToolArgs &args)
{
imp->tool_bar_set_tip("LMB: pick reference RMB: cancel");
imp->tool_bar_set_actions({
{InToolActionID::LMB, "pick reference"},
{InToolActionID::RMB, "cancel"},
});
return ToolResponse();
}
ToolResponse ToolCopyPlacement::update(const ToolArgs &args)
{
if (args.type == ToolEventType::CLICK) {
if (args.button == 1) {
if (args.type == ToolEventType::ACTION) {
if (args.action == InToolActionID::LMB) {
if (args.target.type == ObjectType::BOARD_PACKAGE || args.target.type == ObjectType::PAD) {
auto pkg_uuid = args.target.path.at(0);
auto brd = doc.b->get_board();
Expand Down Expand Up @@ -121,7 +123,7 @@ ToolResponse ToolCopyPlacement::update(const ToolArgs &args)
imp->tool_bar_flash("please click on a package");
}
}
else if (args.button == 3) {
else if (any_of(args.action, {InToolActionID::RMB, InToolActionID::CANCEL})) {
return ToolResponse::revert();
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/core/tools/tool_copy_placement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ class ToolCopyPlacement : public ToolBase {
{
return true;
}
std::set<InToolActionID> get_actions() const override
{
using I = InToolActionID;
return {
I::LMB,
I::CANCEL,
I::RMB,
};
}

private:
};
Expand Down
Loading

0 comments on commit 07283ce

Please sign in to comment.