Skip to content

Commit

Permalink
disable unimplemented elements
Browse files Browse the repository at this point in the history
  • Loading branch information
p3p committed Jul 14, 2024
1 parent a2e6fb2 commit afe7c1c
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 83 deletions.
87 changes: 41 additions & 46 deletions src/MarlinSimulator/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Application::Application() {

sim.vis.create();

user_interface.addElement<UiWindow>("MainMenu", [this](UiWindow* window){
user_interface.m_main_menu = [this](){
if (ImGui::BeginMainMenuBar()) {
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("Preferences")) {
user_interface.ui_elements["Preferences"]->enable();
}
// if (ImGui::MenuItem("Preferences")) {
// user_interface.ui_elements["Preferences"]->enable();
// }
if (ImGui::MenuItem("Quit")) {
Kernel::quit_requested = true;
active = false;
Expand Down Expand Up @@ -55,7 +55,7 @@ Application::Application() {
}
ImGui::EndMainMenuBar();
}
});
};

user_interface.addElement<SerialMonitor>("Serial Monitor(0)", serial_stream_0);
user_interface.addElement<SerialMonitor>("Serial Monitor(1)", serial_stream_1);
Expand Down Expand Up @@ -221,57 +221,52 @@ Application::Application() {
ImGui::InputText("Pin regex", export_regex, sizeof(export_regex));

if (ImGuiFileDialog::Instance()->Display("PulseExportDlgKey", ImGuiWindowFlags_NoDocking)) {
try{
if (ImGuiFileDialog::Instance()->IsOk()) {
std::string image_filename = ImGuiFileDialog::Instance()->GetFilePathName();
try {
if (ImGuiFileDialog::Instance()->IsOk()) {
std::string image_filename = ImGuiFileDialog::Instance()->GetFilePathName();

using namespace vcd;
using namespace vcd;

HeadPtr head = makeVCDHeader(static_cast<TimeScale>(50), TimeScaleUnit::ns, utils::now());
VCDWriter writer{image_filename, head};
HeadPtr head = makeVCDHeader(static_cast<TimeScale>(50), TimeScaleUnit::ns, utils::now());
VCDWriter writer {image_filename, head};

if (export_single_pin) {
std::string pin_name(active_label);
auto scope = pin_name.substr(0, pin_name.find_first_of('_'));
auto var = writer.register_var(scope, pin_name, VariableType::wire, 1);
if (export_single_pin) {
std::string pin_name(active_label);
auto scope = pin_name.substr(0, pin_name.find_first_of('_'));
auto var = writer.register_var(scope, pin_name, VariableType::wire, 1);

if (Gpio::pin_map[monitor_pin].event_log.size() && pin_array[monitor_pin].is_digital) {
for (const auto &value : Gpio::pin_map[monitor_pin].event_log) {
writer.change(var, value.timestamp / 50, utils::format("%u", value.value));
if (Gpio::pin_map[monitor_pin].event_log.size() && pin_array[monitor_pin].is_digital) {
for (const auto& value : Gpio::pin_map[monitor_pin].event_log) {
writer.change(var, value.timestamp / 50, utils::format("%u", value.value));
}
}
} else {
std::map<size_t, VarPtr> pin_to_var_map;
std::regex expression(export_regex);

for (auto pin : pin_array) {
std::string pin_name(pin.name);
bool regex_match = strlen(export_regex) == 0 || std::regex_search(pin_name, expression);
auto scope = pin_name.substr(0, pin_name.find_first_of('_'));
if (pin.is_digital && regex_match) pin_to_var_map[pin.pin] = writer.register_var(scope, pin_name, VariableType::wire, 1);
}
}
}
else {
std::map<size_t, VarPtr> pin_to_var_map;
std::regex expression(export_regex);

for (auto pin : pin_array) {
std::string pin_name(pin.name);
bool regex_match = strlen(export_regex) == 0 || std::regex_search(pin_name, expression);
auto scope = pin_name.substr(0, pin_name.find_first_of('_'));
if (pin.is_digital && regex_match)
pin_to_var_map[pin.pin] = writer.register_var(scope, pin_name, VariableType::wire, 1);
}

std::multimap<uint64_t, std::pair<pin_t, uint16_t> > timestamp_pin_change_map;
std::multimap<uint64_t, std::pair<pin_t, uint16_t>> timestamp_pin_change_map;

for (auto pin : pin_array) {
if (pin.is_digital && pin_to_var_map.find(pin.pin) != pin_to_var_map.end())
for (const auto &data : Gpio::pin_map[pin.pin].event_log)
{
timestamp_pin_change_map.emplace(std::make_pair(data.timestamp, std::make_pair(pin.pin, data.value)));
}
}
for (auto pin : pin_array) {
if (pin.is_digital && pin_to_var_map.find(pin.pin) != pin_to_var_map.end())
for (const auto& data : Gpio::pin_map[pin.pin].event_log) {
timestamp_pin_change_map.emplace(std::make_pair(data.timestamp, std::make_pair(pin.pin, data.value)));
}
}

auto timestamp_offset = timestamp_pin_change_map.begin()->first;
for (const auto &timestamp : timestamp_pin_change_map) {
writer.change(pin_to_var_map[timestamp.second.first], (timestamp.first - timestamp_offset) / 50, utils::format("%u", timestamp.second.second));
auto timestamp_offset = timestamp_pin_change_map.begin()->first;
for (const auto& timestamp : timestamp_pin_change_map) {
writer.change(pin_to_var_map[timestamp.second.first], (timestamp.first - timestamp_offset) / 50, utils::format("%u", timestamp.second.second));
}
}
}
}
}
catch (const std::exception& e)
{
} catch (const std::exception& e) {
auto test = e.what();
}
ImGuiFileDialog::Instance()->Close();
Expand Down
76 changes: 45 additions & 31 deletions src/MarlinSimulator/resources/resource_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,10 @@ static const char * data_shader_default_fs = R"SHADERSTR(

}

/**
* |-----|-----|------|
* |Stat | LCD | |
* | | |
* | | 3D |
* |-----------| |
* |Ser | |
* |-----------|------|
*/

static constexpr char const* imgui_ini = R"(
[Window][DockSpaceWindwow]
Pos=0,0
Size=1280,720
Pos=0,19
Size=1280,701
Collapsed=0
[Window][Debug##Default]
Expand All @@ -223,20 +213,20 @@ Size=400,400
Collapsed=0
[Window][Components]
Pos=1003,0
Size=277,720
Pos=1003,19
Size=277,701
Collapsed=0
DockId=0x00000006,0
[Window][Simulation]
Pos=0,0
Size=313,107
Pos=0,19
Size=313,351
Collapsed=0
DockId=0x00000003,0
DockId=0x0000000B,0
[Window][Viewport]
Pos=315,0
Size=686,482
Pos=315,19
Size=686,463
Collapsed=0
DockId=0x00000009,0
Expand All @@ -247,14 +237,14 @@ Collapsed=0
DockId=0x00000004,0
[Window][Signal Analyser]
Pos=315,0
Size=686,482
Pos=315,19
Size=686,463
Collapsed=0
DockId=0x00000009,1
[Window][Pin List]
Pos=1003,0
Size=277,720
Pos=1003,19
Size=277,701
Collapsed=0
DockId=0x00000006,1
Expand Down Expand Up @@ -293,24 +283,48 @@ Pos=271,95
Size=678,431
Collapsed=0
[Window][Debug]
Pos=0,372
Size=313,348
Collapsed=0
DockId=0x0000000C,0
[Window][Log]
Pos=315,484
Size=686,236
Collapsed=0
DockId=0x0000000A,4
[Window][Choose File##ChooseSDFileDlgKey]
Pos=271,95
Size=678,431
Collapsed=0
[Table][0x5E7B4F09,4]
RefScale=13
Column 0 Sort=0v
Column 1
Column 2
Column 3
[Table][0xD049C3E8,4]
RefScale=13
Column 0 Sort=0v
[Table][0xC6018A16,4]
RefScale=13
Column 0 Sort=0v
[Docking][Data]
DockSpace ID=0x6F13380E Window=0x49B6D357 Pos=0,0 Size=1280,720 Split=X
DockSpace ID=0x6F13380E Window=0x49B6D357 Pos=0,19 Size=1280,701 Split=X
DockNode ID=0x00000005 Parent=0x6F13380E SizeRef=1001,720 Split=X
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=313,720 Split=Y Selected=0x7CAC602A
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=637,107 Selected=0x848745AB
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=637,107 Split=Y Selected=0xFBEA9FC2
DockNode ID=0x0000000B Parent=0x00000003 SizeRef=313,351 Selected=0xFBEA9FC2
DockNode ID=0x0000000C Parent=0x00000003 SizeRef=313,348 Selected=0x392A5ADD
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=637,611 Selected=0x7CAC602A
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=686,720 Split=Y Selected=0x995B0CF8
DockNode ID=0x00000007 Parent=0x00000002 SizeRef=448,451 Split=Y Selected=0x995B0CF8
DockNode ID=0x00000009 Parent=0x00000007 SizeRef=623,482 CentralNode=1 Selected=0x995B0CF8
DockNode ID=0x0000000A Parent=0x00000007 SizeRef=623,236 Selected=0xB516B7B1
DockNode ID=0x00000009 Parent=0x00000007 SizeRef=623,482 CentralNode=1 Selected=0x13926F0B
DockNode ID=0x0000000A Parent=0x00000007 SizeRef=623,236 Selected=0x4B8A34E6
DockNode ID=0x00000008 Parent=0x00000002 SizeRef=448,267 Selected=0xB42549D5
DockNode ID=0x00000006 Parent=0x6F13380E SizeRef=277,720 Selected=0xA115F62D
DockNode ID=0x00000006 Parent=0x6F13380E SizeRef=277,720 Selected=0xFCB30AB3
)";
4 changes: 3 additions & 1 deletion src/MarlinSimulator/user_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ void UserInterface::show() {
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
renderer::gl_log_error();

DockSpace();
if (m_main_menu) {
m_main_menu();
}
for (auto element : ui_elements) {
element.second->show();
}
Expand Down
1 change: 1 addition & 0 deletions src/MarlinSimulator/user_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class UserInterface {

bool post_init_complete = false;
std::function<void(void)> post_init;
std::function<void(void)> m_main_menu;

static std::map<std::string, std::shared_ptr<UiWindow>> ui_elements;
};
Expand Down
10 changes: 5 additions & 5 deletions src/MarlinSimulator/visualisation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,11 @@ void Visualisation::ui_viewport_menu_callback(UiWindow*) {
camera.rotation = {-192.0f, -25.0, 0.0f};
camera.up = {0.0f, 1.0f, 0.0f};
}
if (ImGui::BeginMenu("Mode")) {
if (ImGui::MenuItem("Fly", nullptr, true, true)) { }
if (ImGui::MenuItem("Orbit", nullptr, false, true)) { }
ImGui::EndMenu();
}
// if (ImGui::BeginMenu("Mode")) {
// if (ImGui::MenuItem("Fly", nullptr, true, true)) { }
// if (ImGui::MenuItem("Orbit", nullptr, false, true)) { }
// ImGui::EndMenu();
// }
if (ImGui::BeginMenu("Focus View")) {
if (ImGui::MenuItem("Centre X (Right)")) {
camera.position = {build_plate_dimension.x, 10.0f, -(build_plate_dimension.y / 2.0f)};
Expand Down

0 comments on commit afe7c1c

Please sign in to comment.