JeVois  1.21
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
GUIeditor.H
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2022 by Laurent Itti, the University of Southern
4// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5//
6// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10// License for more details. You should have received a copy of the GNU General Public License along with this program;
11// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12//
13// Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14// Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16/*! \file */
17
18#pragma once
19
20// This is only available on JeVoisPro
21#ifdef JEVOIS_PRO
22
23#include <ImGuiColorTextEdit/TextEditor.h>
24#include <filesystem>
25#include <set>
26
27namespace ImGui { class FileBrowser; }
28
29namespace jevois
30{
31 class GUIhelper;
32
33 //! Helper enum for actions to execute after saving a config file \relates GUIeditor
34 enum class EditorSaveAction { None, Reload, Reboot, RefreshMappings, Compile };
35
36 //! Helper class to represent a GUIeditor file in a pull-down menu \relates GUIeditor
37 struct EditorItem {
38 std::filesystem::path filename; //!< Full absolute path to the item
39 std::string displayname; //!< Description of item in pull-down menu
40 EditorSaveAction action; //!< What to do after file is edited and saved
41 };
42
43 //! Editor panel for JeVois-Pro GUI
44 /*! This panel allows one to select one of several files, and to edit it.
45 \ingroup gui */
46 class GUIeditor : public TextEditor
47 {
48 public:
49 //! Constructor
50 GUIeditor(GUIhelper * helper, std::string const & imguiid, std::vector<EditorItem> && fixeditems,
51 std::string const & scanpath, std::string const & prefix, std::set<std::string> && extensions);
52
53 //! Destructor
54 virtual ~GUIeditor();
55
56 //! Draw the editor into ImGui
57 void draw();
58
59 //! Load a file and set it as the current file
60 void loadFile(std::filesystem::path const & fn);
61
62 //! Get path of file last loaded with loadFile(), may be empty
63 std::filesystem::path const & getLoadedFilePath() const;
64
65 //! Refresh list of files
66 void refresh();
67
68 protected:
69 //! Save a file
70 void saveFile();
71
72 private:
73 //! Load a file and set it as the current file
74 /*! If the load fails, we can either display failtxt in the editor and make it read-only, or, if failtxt is empty,
75 assume that we want to create a new file (e.g., module's params.cfg) and hence set the editor read-write. */
76 void loadFileInternal(std::filesystem::path const & fn, std::string const & failtxt);
77 GUIhelper * const itsHelper;
78 std::string const itsId;
79
80 std::vector<EditorItem> itsItems;
81 size_t itsNumFixedItems;
82 std::string itsScanPath;
83 std::string const itsPrefix;
84 std::set<std::string> const itsExtensions;
85
86 int itsCurrentItem = 0;
87 bool itsWantLoad = true;
88 bool itsWantAction = false;
89 bool itsOkToLoad = false;
90 bool itsOverrideReloadModule = false;
91 int itsNewItem = 0;
92 std::filesystem::path itsFilename;
93 std::unique_ptr<ImGui::FileBrowser> itsBrowser;
94 };
95
96
97
98} // namespace jevois
99
100#endif // JEVOIS_PRO
Editor panel for JeVois-Pro GUI.
Definition GUIeditor.H:47
EditorSaveAction
Helper enum for actions to execute after saving a config file.
Definition GUIeditor.H:34
virtual ~GUIeditor()
Destructor.
Definition GUIeditor.C:46
void saveFile()
Save a file.
Definition GUIeditor.C:500
std::filesystem::path const & getLoadedFilePath() const
Get path of file last loaded with loadFile(), may be empty.
Definition GUIeditor.C:496
void refresh()
Refresh list of files.
Definition GUIeditor.C:50
void loadFile(std::filesystem::path const &fn)
Load a file and set it as the current file.
Definition GUIeditor.C:362
void draw()
Draw the editor into ImGui.
Definition GUIeditor.C:113
Helper class to assist modules in creating graphical and GUI elements.
Definition GUIhelper.H:133
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2
Helper class to represent a GUIeditor file in a pull-down menu.
Definition GUIeditor.H:37
EditorSaveAction action
What to do after file is edited and saved.
Definition GUIeditor.H:40
std::filesystem::path filename
Full absolute path to the item.
Definition GUIeditor.H:38
std::string displayname
Description of item in pull-down menu.
Definition GUIeditor.H:39