Skip to content

Commit b7dc846

Browse files
imp schematic: use part browser for assiging parts
changelog: Enhancements/Schematic Editor: use part browser for assigning parts
1 parent 12db4ca commit b7dc846

15 files changed

+440
-134
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ SRC_IMP = \
306306
src/core/tools/tool_place_pad.cpp\
307307
src/core/tools/tool_paste.cpp\
308308
src/core/tools/tool_assign_part.cpp\
309+
src/core/tools/tool_clear_part.cpp\
309310
src/core/tools/tool_map_package.cpp\
310311
src/core/tools/tool_draw_track.cpp\
311312
src/core/tools/tool_place_via.cpp\

src/core/create_tool.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "tools/tool_add_part.hpp"
44
#include "tools/tool_add_vertex.hpp"
55
#include "tools/tool_assign_part.hpp"
6+
#include "tools/tool_clear_part.hpp"
67
#include "tools/tool_bend_line_net.hpp"
78
#include "tools/tool_delete.hpp"
89
#include "tools/tool_disconnect.hpp"
@@ -214,6 +215,9 @@ std::unique_ptr<ToolBase> Core::create_tool(ToolID tool_id)
214215
case ToolID::ASSIGN_PART:
215216
return std::make_unique<ToolAssignPart>(this, tool_id);
216217

218+
case ToolID::CLEAR_PART:
219+
return std::make_unique<ToolClearPart>(this, tool_id);
220+
217221
case ToolID::MAP_PACKAGE:
218222
return std::make_unique<ToolMapPackage>(this, tool_id);
219223

src/core/tool_id.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,6 @@ enum class ToolID {
169169
DRAW_NET_TIE,
170170
MOVE_TRACK_CONNECTION,
171171
MOVE_TRACK_CENTER,
172+
CLEAR_PART,
172173
};
173174
} // namespace horizon

src/core/tools/tool_clear_part.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "tool_clear_part.hpp"
2+
#include "document/idocument_schematic.hpp"
3+
#include "schematic/schematic.hpp"
4+
#include "imp/imp_interface.hpp"
5+
6+
namespace horizon {
7+
8+
bool ToolClearPart::can_begin()
9+
{
10+
for (const auto &it : selection) {
11+
if (it.type == ObjectType::SCHEMATIC_SYMBOL) {
12+
auto &sym = doc.c->get_sheet()->symbols.at(it.uuid);
13+
if (sym.component->part)
14+
return true;
15+
}
16+
}
17+
return false;
18+
}
19+
20+
ToolResponse ToolClearPart::begin(const ToolArgs &args)
21+
{
22+
for (const auto &it : args.selection) {
23+
if (it.type == ObjectType::SCHEMATIC_SYMBOL) {
24+
auto &sym = doc.c->get_sheet()->symbols.at(it.uuid);
25+
sym.component->part = nullptr;
26+
}
27+
}
28+
return ToolResponse::commit();
29+
}
30+
31+
ToolResponse ToolClearPart::update(const ToolArgs &args)
32+
{
33+
return ToolResponse();
34+
}
35+
36+
} // namespace horizon

src/core/tools/tool_clear_part.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
#include "core/tool.hpp"
3+
4+
namespace horizon {
5+
6+
class ToolClearPart : public ToolBase {
7+
public:
8+
using ToolBase::ToolBase;
9+
ToolResponse begin(const ToolArgs &args) override;
10+
ToolResponse update(const ToolArgs &args) override;
11+
bool can_begin() override;
12+
bool is_specific() override
13+
{
14+
return true;
15+
}
16+
17+
private:
18+
};
19+
} // namespace horizon

src/imp/action_catalog.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,11 @@ const std::map<ActionToolID, ActionCatalogItem> action_catalog = {
444444

445445
{{ActionID::TOOL, ToolID::ASSIGN_PART},
446446
{"Assign part", ActionGroup::SCHEMATIC, ActionCatalogItem::AVAILABLE_IN_SCHEMATIC,
447+
ActionCatalogItem::FLAGS_NO_POPOVER | ActionCatalogItem::FLAGS_NO_MENU
448+
| ActionCatalogItem::FLAGS_NO_PREFERENCES}},
449+
450+
{{ActionID::TOOL, ToolID::CLEAR_PART},
451+
{"Clear part", ActionGroup::SCHEMATIC, ActionCatalogItem::AVAILABLE_IN_SCHEMATIC,
447452
ActionCatalogItem::FLAGS_DEFAULT}},
448453

449454
{{ActionID::TOOL, ToolID::EDIT_SCHEMATIC_PROPERTIES},
@@ -1092,6 +1097,10 @@ const std::map<ActionToolID, ActionCatalogItem> action_catalog = {
10921097
{{ActionID::CONVERT_TO_PAD, ToolID::NONE},
10931098
{"Convert to pad", ActionGroup::PACKAGE, ActionCatalogItem::AVAILABLE_IN_PACKAGE,
10941099
ActionCatalogItem::FLAGS_SPECIFIC}},
1100+
1101+
{{ActionID::ASSIGN_PART, ToolID::NONE},
1102+
{"Assign part", ActionGroup::SCHEMATIC, ActionCatalogItem::AVAILABLE_IN_SCHEMATIC,
1103+
ActionCatalogItem::FLAGS_SPECIFIC}},
10951104
};
10961105

10971106
const std::vector<std::pair<ActionGroup, std::string>> action_group_catalog = {
@@ -1247,6 +1256,7 @@ const LutEnumStr<ActionID> action_lut = {
12471256
ACTION_LUT_ITEM(CYCLE_LAYER_DISPLAY_MODE),
12481257
ACTION_LUT_ITEM(OPEN_PROJECT),
12491258
ACTION_LUT_ITEM(CONVERT_TO_PAD),
1259+
ACTION_LUT_ITEM(ASSIGN_PART),
12501260
};
12511261

12521262
#define TOOL_LUT_ITEM(x) \
@@ -1291,6 +1301,7 @@ const LutEnumStr<ToolID> tool_lut = {
12911301
TOOL_LUT_ITEM(PLACE_PAD),
12921302
TOOL_LUT_ITEM(PASTE),
12931303
TOOL_LUT_ITEM(ASSIGN_PART),
1304+
TOOL_LUT_ITEM(CLEAR_PART),
12941305
TOOL_LUT_ITEM(MAP_PACKAGE),
12951306
TOOL_LUT_ITEM(DRAW_TRACK),
12961307
TOOL_LUT_ITEM(PLACE_VIA),

src/imp/actions.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,6 @@ enum class ActionID {
126126
CYCLE_LAYER_DISPLAY_MODE,
127127
OPEN_PROJECT,
128128
CONVERT_TO_PAD,
129+
ASSIGN_PART,
129130
};
130131
}

src/imp/imp_schematic.cpp

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,41 @@ void ImpSchematic::construct()
611611
this->send_json(j);
612612
}
613613
});
614+
connect_action(ActionID::ASSIGN_PART, [this](const auto &a) {
615+
const auto sel = canvas->get_selection();
616+
617+
if (!sockets_connected) {
618+
this->tool_begin(ToolID::ASSIGN_PART);
619+
}
620+
else if (auto entity = entity_from_selection(sel)) {
621+
canvas->set_selection_mode(CanvasGL::SelectionMode::NORMAL);
622+
handle_selection_cross_probe();
623+
std::set<const Component *> components;
624+
const auto &sheet = *core_schematic.get_sheet();
625+
for (const auto &it : sel) {
626+
if (it.type == ObjectType::SCHEMATIC_SYMBOL) {
627+
if (sheet.symbols.count(it.uuid))
628+
components.insert(sheet.symbols.at(it.uuid).component);
629+
}
630+
}
631+
std::string hint;
632+
for (const auto comp : components) {
633+
if (hint.size())
634+
hint += ", ";
635+
hint += core_schematic.get_top_block()
636+
->get_component_info(*comp, core_schematic.get_instance_path())
637+
.refdes;
638+
}
639+
hint = "Assigning to " + hint;
640+
json j;
641+
j["op"] = "show-browser-assign";
642+
j["time"] = gtk_get_current_event_time();
643+
j["entity"] = (std::string)entity->uuid;
644+
j["hint"] = hint;
645+
allow_set_foreground_window(mgr_pid);
646+
this->send_json(j);
647+
}
648+
});
614649

615650
connect_action(ActionID::PREV_SHEET, sigc::mem_fun(*this, &ImpSchematic::handle_next_prev_sheet));
616651
connect_action(ActionID::NEXT_SHEET, sigc::mem_fun(*this, &ImpSchematic::handle_next_prev_sheet));
@@ -900,9 +935,33 @@ ActionButton &ImpSchematic::add_action_button_schematic(ActionToolID id)
900935
return b;
901936
}
902937

938+
const Entity *ImpSchematic::entity_from_selection(const std::set<SelectableRef> &sel)
939+
{
940+
if (core_schematic.get_block_symbol_mode())
941+
return nullptr;
942+
const Entity *entity = nullptr;
943+
const auto &sheet = *core_schematic.get_sheet();
944+
for (const auto &it : sel) {
945+
if (it.type == ObjectType::SCHEMATIC_SYMBOL) {
946+
if (!sheet.symbols.count(it.uuid))
947+
continue;
948+
const auto &sym = sheet.symbols.at(it.uuid);
949+
if (entity) {
950+
if (entity != sym.component->entity) {
951+
return nullptr;
952+
}
953+
}
954+
else {
955+
entity = sym.component->entity;
956+
}
957+
}
958+
}
959+
return entity;
960+
}
961+
903962
void ImpSchematic::update_action_sensitivity()
904963
{
905-
auto sel = canvas->get_selection();
964+
const auto sel = canvas->get_selection();
906965
const auto n_block_sym = sel_count_type(sel, ObjectType::SCHEMATIC_BLOCK_SYMBOL);
907966
if (sockets_connected) {
908967
json req;
@@ -977,6 +1036,9 @@ void ImpSchematic::update_action_sensitivity()
9771036
set_action_sensitive(ActionID::EDIT_BLOCK_SYMBOL, have_block_sym);
9781037
set_action_sensitive(ActionID::POP_OUT_OF_BLOCK, core_schematic.get_instance_path().size());
9791038
set_action_sensitive(ActionID::GO_TO_BLOCK_SYMBOL, !core_schematic.current_block_is_top());
1039+
1040+
set_action_sensitive(ActionID::ASSIGN_PART, entity_from_selection(sel));
1041+
9801042
ImpBase::update_action_sensitivity();
9811043
}
9821044

src/imp/imp_schematic.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ImpSchematic : public ImpBase {
5353
void handle_move_to_other_sheet(const ActionConnection &conn);
5454
void handle_highlight_group_tag(const ActionConnection &conn);
5555
void handle_next_prev_sheet(const ActionConnection &conn);
56+
const Entity *entity_from_selection(const std::set<SelectableRef> &sel);
5657

5758
struct ViewInfo {
5859
float scale;

src/pool-prj-mgr/pool-prj-mgr-app_win.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,13 @@ json PoolProjectManagerAppWindow::handle_req(const json &j)
463463
part_browser_window->placed_part(part);
464464
}
465465
else if (op == "show-browser") {
466+
part_browser_window->set_entity({}, "");
467+
part_browser_window->present(timestamp);
468+
part_browser_window->focus_search();
469+
}
470+
else if (op == "show-browser-assign") {
471+
const UUID entity_uuid = j.at("entity").get<std::string>();
472+
part_browser_window->set_entity(entity_uuid, j.at("hint").get<std::string>());
466473
part_browser_window->present(timestamp);
467474
part_browser_window->focus_search();
468475
}

0 commit comments

Comments
 (0)