Skip to content

Commit

Permalink
Added remaining render items, fix compiling on Ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
ad3154 committed Aug 18, 2023
1 parent 6fe5ff6 commit 0802f09
Show file tree
Hide file tree
Showing 7 changed files with 1,039 additions and 216 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include(CMakePackageConfigHelpers)
set(CPACK_DEBIAN_FILENAME DEB-DEFAULT)
set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE)
set(CPACK_PACKAGE_VENDOR "Open-Agriculture")
set(CPACK_PACKAGE_CONTACT ${contact})
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/Open-Agriculture")
set(CPACK_PACKAGE_VERSION ${CMAKE_PROJECT_VERSION})
if(CPack_CMake_INCLUDED EQUAL 1)
Expand All @@ -26,6 +26,7 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(OpenGL REQUIRED)

set(BUILD_TESTING OFF)
add_subdirectory(submodules/agisostack)
add_subdirectory(submodules/sdl)

Expand Down
Binary file added EXAMPLE.iop
Binary file not shown.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
# AgIsoStack DDOP Generator

## Wip
## Overview

This program allows you to create, save, load, and edit ISO11783 device descriptor object pools (DDOP) for use with communicating with an ISOBUS task controller.

It is written in C++ and is based on the DDOP objects from [AgIsoStack++](https://github.com/Open-Agriculture/AgIsoStack-plus-plus), with a simple GUI created with [Dear ImGui](https://github.com/ocornut/imgui) running on OpenGL3.

When used in combination with AgIsoStack (or any other TC client), it provides an easy way to visualize your DDOP, build a binary version of it, and easily deserialize it back into C++ objects if you want to interact with a DDOP in your own application.

![Main Screen Image](docs/images/example1.png)

### Features

* Supports dynamically editing any DDOP or creating one from scratch
* Compatible with both TC version 3 and 4
* Basic object pool error checking to help you find errors before loading onto a TC
* Completely free and open source alternative to many paid products!

### Compilation

This project is built with CMake.

Make sure you have all the dependencies installed.

```
sudo apt install cmake build-essential
```

Then compile with CMake:

```
cmake -S . -B build
cmake --build build
```
36 changes: 23 additions & 13 deletions include/L2DFileDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@

#include <imgui.h>
#include <imgui_internal.h>
#include <time.h>
#include <algorithm>
#include <chrono>
#include <ctime>
#include <filesystem>
#include <sstream>
#include <string>
Expand Down Expand Up @@ -287,7 +288,11 @@ namespace FileDialog
std::time_t tt = std::chrono::system_clock::to_time_t(st);

std::tm mt;
#ifndef _MSC_VER
localtime_r(&tt, &mt);
#else
localtime_s(&mt, &tt);
#endif
std::stringstream ss;
ss << std::put_time(&mt, "%F %R");

Expand All @@ -296,6 +301,11 @@ namespace FileDialog
}
ImGui::EndChild();

if (file_dialog_current_path.empty())
{
file_dialog_current_path = std::filesystem::current_path().string();
}

std::string selected_file_path = file_dialog_current_path + (file_dialog_current_path.back() == '\\' ? "" : "\\") + (file_dialog_current_folder.size() > 0 ? file_dialog_current_folder : file_dialog_current_file);
char *buf = &selected_file_path[0];
ImGui::PushItemWidth(724);
Expand All @@ -321,7 +331,7 @@ namespace FileDialog
{
if (strlen(new_folder_name) <= 0)
{
strcpy_s(new_folder_error, "Folder name can't be empty");
strncpy(new_folder_error, "Folder name can't be empty", sizeof(new_folder_error));
}
else
{
Expand All @@ -333,11 +343,11 @@ namespace FileDialog
ImGui::SameLine();
if (ImGui::Button("Cancel##1"))
{
strcpy_s(new_folder_name, "");
strcpy_s(new_folder_error, "");
strncpy(new_folder_name, "", sizeof(new_folder_name));
strncpy(new_folder_error, "", sizeof(new_folder_error));
ImGui::CloseCurrentPopup();
}
ImGui::TextColored(ImColor(1.0f, 0.0f, 0.2f, 1.0f), new_folder_error);
ImGui::TextColored(ImColor(1.0f, 0.0f, 0.2f, 1.0f), "%s", new_folder_error);
ImGui::EndPopup();
}

Expand Down Expand Up @@ -367,7 +377,7 @@ namespace FileDialog
file_dialog_file_select_index = 0;
file_dialog_folder_select_index = 0;
file_dialog_current_file = "";
strcpy_s(file_dialog_error, "");
strncpy(file_dialog_error, "", sizeof(file_dialog_error));
initial_path_set = false;
file_dialog_open = false;
};
Expand Down Expand Up @@ -400,35 +410,35 @@ namespace FileDialog
{
if (file_dialog_current_folder == "")
{
strcpy_s(file_dialog_error, "Error: You must select a folder!");
strncpy(file_dialog_error, "Error: You must select a folder!", sizeof(file_dialog_error));
}
else
{
auto path = file_dialog_current_path + (file_dialog_current_path.back() == '\\' ? "" : "\\") + file_dialog_current_file;
strcpy_s(buffer, path.length() + 1, path.c_str());
strcpy_s(file_dialog_error, "");
strncpy(buffer, path.c_str(), sizeof(buffer));
strncpy(file_dialog_error, "", sizeof(file_dialog_error));
reset_everything();
}
}
else if (type == FileDialogType::OpenFile)
{
if (file_dialog_current_file == "")
{
strcpy_s(file_dialog_error, "Error: You must select a file!");
strncpy(file_dialog_error, "Error: You must select a file!", sizeof(file_dialog_error));
}
else
{
auto path = file_dialog_current_path + (file_dialog_current_path.back() == '\\' ? "" : "\\") + file_dialog_current_file;
strcpy_s(buffer, path.length() + 1, path.c_str());
strcpy_s(file_dialog_error, "");
strncpy(buffer, path.c_str(), buffer_size);
strncpy(file_dialog_error, "", sizeof(file_dialog_error));
reset_everything();
}
}
}

if (strlen(file_dialog_error) > 0)
{
ImGui::TextColored(ImColor(1.0f, 0.0f, 0.2f, 1.0f), file_dialog_error);
ImGui::TextColored(ImColor(1.0f, 0.0f, 0.2f, 1.0f), "%s", file_dialog_error);
}

ImGui::End();
Expand Down
29 changes: 24 additions & 5 deletions include/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class DDOPGeneratorGUI

void start();

private:
static constexpr std::size_t FILE_PATH_BUFFER_MAX_LENGTH = 1024;

bool render_menu_bar();
void render_open_file_menu();
void parseElementChildrenOfElement(std::uint16_t objectID);
Expand All @@ -33,18 +36,21 @@ class DDOPGeneratorGUI
void render_device_process_data_settings(std::shared_ptr<isobus::task_controller_object::DeviceProcessDataObject> object);
void render_device_property_settings(std::shared_ptr<isobus::task_controller_object::DevicePropertyObject> object);
void render_device_presentation_settings(std::shared_ptr<isobus::task_controller_object::DeviceValuePresentationObject> object);
void render_object_components(std::shared_ptr<isobus::task_controller_object::Object> object);
void render_current_selected_object_settings(std::shared_ptr<isobus::task_controller_object::Object> object);
void render_device_element_components(std::shared_ptr<isobus::task_controller_object::DeviceElementObject> object);
void render_device_process_data_components(std::shared_ptr<isobus::task_controller_object::DeviceProcessDataObject> object);
void render_device_property_components(std::shared_ptr<isobus::task_controller_object::DevicePropertyObject> object);
void render_device_presentation_components(std::shared_ptr<isobus::task_controller_object::DeviceValuePresentationObject> object);
void render_save();
void render_all_objects();
void on_selected_object_changed(std::shared_ptr<isobus::task_controller_object::Object> newObject);

private:
static constexpr std::size_t FILE_PATH_BUFFER_MAX_LENGTH = 1024;

static std::string get_element_type_string(isobus::task_controller_object::DeviceElementObject::Type type);
static std::string get_object_type_string(isobus::task_controller_object::ObjectTypes type);
const std::array<std::uint8_t, 7> generate_localization_label();
std::uint16_t get_first_unused_id() const;

std::string languageCode; ///< The last received language code, such as "en", "es", "de", etc.
std::string languageCode;
isobus::LanguageCommandInterface::DecimalSymbols decimalSymbol = isobus::LanguageCommandInterface::DecimalSymbols::Point;
isobus::LanguageCommandInterface::TimeFormats timeFormat = isobus::LanguageCommandInterface::TimeFormats::TwelveHourAmPm;
isobus::LanguageCommandInterface::DateFormats dateFormat = isobus::LanguageCommandInterface::DateFormats::mmddyyyy;
Expand All @@ -66,11 +72,24 @@ class DDOPGeneratorGUI
char structureLabelBuffer[8] = { 0 };
char extendedStructureLabelBuffer[129] = { 0 };
char hexIsoNameBuffer[17] = { 0 };
char languageCodeBuffer[3] = { 0 };
std::string lastFileName;
int elementNumberBuffer = 0;
int parentObjectBuffer = 0;
int ddiBuffer = 0;
int objectIDBuffer = 0;
int presentationObjectBuffer = 0;
int valueBuffer = 0;
int numberDecimalsBuffer = 0;
int offsetBuffer = 0;
int versionIndex = 0;
int addChildComboIndex = 0;
float scaleBuffer = 0.0f;
std::uint16_t selectedObjectID = 0xFFFF;
std::array<bool, 8> propertiesBitfieldBuffer = { false };
std::array<bool, 8> triggerBitfieldBuffer = { false };
bool openFileDialogue = false;
bool saveModal = false;
bool saveAsModal = false;
bool currentPoolValid = false;
};
Expand Down
Loading

0 comments on commit 0802f09

Please sign in to comment.