Skip to content

Commit 6a7696e

Browse files
committed
Add default 3d view preferences for #742
1 parent 1b733ee commit 6a7696e

8 files changed

Lines changed: 131 additions & 0 deletions

File tree

src/imp/3d/3d_view.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,24 @@ void View3DWindow::apply_preferences(const Preferences &prefs)
616616
canvas->set_appearance(prefs.canvas_layer.appearance);
617617
canvas->spacenav_prefs = prefs.spacenav.prefs;
618618
canvas->input_devices_prefs = prefs.input_devices.prefs;
619+
620+
if (prefs.view_3d.use_ortho_projection)
621+
proj_ortho_rb->set_active(true);
622+
else
623+
proj_persp_rb->set_active(true);
624+
canvas->set_projection(prefs.view_3d.use_ortho_projection ? Canvas3D::Projection::ORTHO
625+
: Canvas3D::Projection::PERSP);
626+
set_color_button_color(solder_mask_color_button, prefs.view_3d.solder_mask_color);
627+
canvas->set_solder_mask_color(prefs.view_3d.solder_mask_color);
628+
set_color_button_color(silkscreen_color_button, prefs.view_3d.silkscreen_color);
629+
canvas->set_silkscreen_color(prefs.view_3d.silkscreen_color);
630+
set_color_button_color(substrate_color_button, prefs.view_3d.substrate_color);
631+
canvas->set_substrate_color(prefs.view_3d.substrate_color);
632+
set_color_button_color(background_top_color_button, prefs.view_3d.bg_top_color);
633+
canvas->set_background_top_color(prefs.view_3d.bg_top_color);
634+
set_color_button_color(background_bottom_color_button, prefs.view_3d.bg_bottom_color);
635+
canvas->set_background_bottom_color(prefs.view_3d.bg_bottom_color);
636+
619637
spnav_buttons = prefs.spacenav.buttons;
620638
const auto av = ActionCatalogItem::AVAILABLE_IN_3D;
621639
for (auto &it : action_connections) {

src/pool-prj-mgr/preferences/preferences_row.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ PreferencesRowBoolButton::PreferencesRowBoolButton(const std::string &title, con
6969
pack_start(*box, false, false, 0);
7070
}
7171

72+
PreferencesRowColorButton::PreferencesRowColorButton(const std::string &title, const std::string &subtitle,
73+
Preferences &prefs, Color &v)
74+
: PreferencesRow(title, subtitle, prefs)
75+
{
76+
btn = Gtk::manage(new Gtk::ColorButton);
77+
btn->set_valign(Gtk::ALIGN_CENTER);
78+
btn->show();
79+
pack_start(*btn, false, false, 0);
80+
bind_widget(btn, v, [this](const Color &) { preferences.signal_changed().emit(); });
81+
}
7282

7383
PreferencesGroup::PreferencesGroup(const std::string &title) : Gtk::Box(Gtk::ORIENTATION_VERTICAL, 8)
7484
{

src/pool-prj-mgr/preferences/preferences_row.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ template <typename T> class PreferencesRowEnum : public PreferencesRow {
9696
Gtk::ComboBoxText *combo = nullptr;
9797
};
9898

99+
class PreferencesRowColorButton : public PreferencesRow {
100+
public:
101+
PreferencesRowColorButton(const std::string &title, const std::string &subtitle, Preferences &prefs, Color &v);
102+
103+
private:
104+
Gtk::ColorButton *btn = nullptr;
105+
};
106+
99107
class PreferencesGroup : public Gtk::Box {
100108
public:
101109
PreferencesGroup(const std::string &title);

src/pool-prj-mgr/preferences/preferences_window_misc.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,48 @@ MiscPreferencesEditor::MiscPreferencesEditor(Preferences &prefs) : preferences(p
8484
gr->add_row(*r);
8585
}
8686
}
87+
88+
{
89+
auto gr = Gtk::manage(new PreferencesGroup("3D View"));
90+
box->pack_start(*gr, false, false, 0);
91+
gr->show();
92+
{
93+
94+
auto r = Gtk::manage(new PreferencesRowBoolButton("View projection", "Default view projection",
95+
"Orthographic", "Perspective", preferences,
96+
preferences.view_3d.use_ortho_projection));
97+
gr->add_row(*r);
98+
}
99+
{
100+
auto r = Gtk::manage(new PreferencesRowColorButton("Solder mask color", "Default solder mask color",
101+
preferences, preferences.view_3d.solder_mask_color));
102+
gr->add_row(*r);
103+
}
104+
{
105+
auto r = Gtk::manage(new PreferencesRowColorButton("Silkscreen color", "Default silkscreen color",
106+
preferences, preferences.view_3d.silkscreen_color));
107+
gr->add_row(*r);
108+
}
109+
{
110+
auto r = Gtk::manage(new PreferencesRowColorButton("Substrate color", "Default substrate color",
111+
preferences, preferences.view_3d.substrate_color));
112+
gr->add_row(*r);
113+
}
114+
115+
{
116+
auto r =
117+
Gtk::manage(new PreferencesRowColorButton("Top background color", "Background gradient start color",
118+
preferences, preferences.view_3d.bg_top_color));
119+
gr->add_row(*r);
120+
}
121+
{
122+
auto r = Gtk::manage(new PreferencesRowColorButton("Bottom background color",
123+
"Background gradient end color", preferences,
124+
preferences.view_3d.bg_bottom_color));
125+
gr->add_row(*r);
126+
}
127+
}
128+
87129
{
88130
auto gr = Gtk::manage(new PreferencesGroup("Zoom & Pan"));
89131
box->pack_start(*gr, false, false, 0);

src/preferences/preferences.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,33 @@ void BoardPreferences::load_from_json(const json &j)
215215
move_using_router = j.value("move_using_router", true);
216216
}
217217

218+
json View3DPreferences::serialize() const
219+
{
220+
json j;
221+
j["use_ortho_projection"] = use_ortho_projection;
222+
j["solder_mask_color"] = color_to_json(solder_mask_color);
223+
j["silkscreen_color"] = color_to_json(silkscreen_color);
224+
j["substrate_color"] = color_to_json(substrate_color);
225+
j["bg_top_color"] = color_to_json(bg_top_color);
226+
j["bg_bottom_color"] = color_to_json(bg_bottom_color);
227+
return j;
228+
}
229+
230+
void View3DPreferences::load_from_json(const json &j)
231+
{
232+
use_ortho_projection = j.value("use_ortho_projection", false);
233+
if (j.count("solder_mask_color"))
234+
solder_mask_color = color_from_json(j.at("solder_mask_color"));
235+
if (j.count("silkscreen_color"))
236+
silkscreen_color = color_from_json(j.at("silkscreen_color"));
237+
if (j.count("substrate_color"))
238+
substrate_color = color_from_json(j.at("substrate_color"));
239+
if (j.count("bg_top_color"))
240+
bg_top_color = color_from_json(j.at("bg_top_color"));
241+
if (j.count("bg_bottom_color"))
242+
bg_bottom_color = color_from_json(j.at("bg_bottom_color"));
243+
}
244+
218245
json ZoomPreferences::serialize() const
219246
{
220247
json j;
@@ -601,6 +628,7 @@ json Preferences::serialize() const
601628
j["key_sequences"] = key_sequences.serialize();
602629
j["in_tool_key_sequences"] = in_tool_key_sequences.serialize();
603630
j["board"] = board.serialize();
631+
j["view_3d"] = view_3d.serialize();
604632
j["zoom"] = zoom.serialize();
605633
j["capture_output"] = capture_output;
606634
j["stock_info_provider"] = stock_info_provider_lut.lookup_reverse(stock_info_provider);
@@ -636,6 +664,8 @@ void Preferences::load_from_json(const json &j)
636664
schematic.load_from_json(j.at("schematic"));
637665
if (j.count("board"))
638666
board.load_from_json(j.at("board"));
667+
if (j.count("view_3d"))
668+
view_3d.load_from_json(j.at("view_3d"));
639669
if (j.count("zoom"))
640670
zoom.load_from_json(j.at("zoom"));
641671
if (j.count("key_sequences"))

src/preferences/preferences.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ class BoardPreferences {
4545
json serialize() const;
4646
};
4747

48+
class View3DPreferences {
49+
public:
50+
bool use_ortho_projection = false;
51+
Color solder_mask_color = Color(0, .5, 0);
52+
Color silkscreen_color = Color(1, 1, 1);
53+
Color substrate_color = Color(.2, .15, 0);
54+
Color bg_top_color = Color(.2, .2, .4);
55+
Color bg_bottom_color = Color(.59, .59, .66);
56+
57+
void load_from_json(const json &j);
58+
json serialize() const;
59+
};
60+
4861
class KeySequencesPreferences {
4962
public:
5063
std::map<ActionToolID, std::map<ActionCatalogItem::Availability, std::vector<KeySequence>>> keys;
@@ -187,6 +200,7 @@ class Preferences {
187200
CanvasPreferences canvas_layer;
188201
SchematicPreferences schematic;
189202
BoardPreferences board;
203+
View3DPreferences view_3d;
190204
KeySequencesPreferences key_sequences;
191205
ZoomPreferences zoom;
192206
bool capture_output = false;

src/util/gtk_util.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
#endif
1515

1616
namespace horizon {
17+
void set_color_button_color(Gtk::ColorButton *color_button, const class Color &v)
18+
{
19+
Gdk::Color c;
20+
c.set_rgb_p(v.r, v.g, v.b);
21+
color_button->set_color(c);
22+
}
23+
1724
void bind_widget(Gtk::Switch *sw, bool &v)
1825
{
1926
sw->set_active(v);

src/util/gtk_util.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <gtkmm.h>
33
#include <stdint.h>
44
namespace horizon {
5+
void set_color_button_color(Gtk::ColorButton *color_button, const class Color &v);
6+
57
void bind_widget(class SpinButtonDim *sp, int64_t &v);
68
void bind_widget(class SpinButtonDim *sp, uint64_t &v);
79

0 commit comments

Comments
 (0)