JeVois  1.18
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
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 
27 namespace ImGui { class FileBrowser; }
28 
29 namespace 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 };
35 
36  //! Helper class to represent a GUIeditor file in a pull-down menu \relates GUIeditor
37  struct EditorItem {
38  std::filesystem::path filename;
39  std::string displayname;
40  EditorSaveAction action;
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
60  /*! If the load fails, we can either display failtxt in the editor and make it read-only, or, if failtxt is empty,
61  assume that we want to create a new file (e.g., module's params.cfg) and hence set the editor read-write. */
62  void loadFile(std::filesystem::path const & fn, std::string const & failtxt);
63 
64  //! Save a file
65  void saveFile();
66 
67  //! Refresh list of files
68  void refresh();
69 
70  private:
71  GUIhelper * const itsHelper;
72  std::string const itsId;
73 
74  std::vector<EditorItem> itsItems;
75  size_t itsNumFixedItems;
76  std::string itsScanPath;
77  std::string const itsPrefix;
78  std::set<std::string> const itsExtensions;
79 
80  int itsCurrentItem = 0;
81  EditorSaveAction itsCurrentAction = EditorSaveAction::None;
82  bool itsWantLoad = true;
83  bool itsWantAction = false;
84  bool itsOkToLoad = false;
85  bool itsOverrideReloadModule = false;
86  int itsNewItem = 0;
87  std::filesystem::path itsFilename;
88  std::unique_ptr<ImGui::FileBrowser> itsBrowser;
89  };
90 
91 
92 
93 } // namespace jevois
94 
95 #endif // JEVOIS_PRO
jevois::GUIeditor::saveFile
void saveFile()
Save a file.
Definition: GUIeditor.C:375
jevois::GUIeditor::EditorSaveAction
EditorSaveAction
Helper enum for actions to execute after saving a config file.
Definition: GUIeditor.H:34
jevois::EditorItem::action
EditorSaveAction action
Definition: GUIeditor.H:40
jevois::GUIhelper
Helper class to assist modules in creating graphical and GUI elements.
Definition: GUIhelper.H:122
jevois::GUIeditor::loadFile
void loadFile(std::filesystem::path const &fn, std::string const &failtxt)
Load a file.
Definition: GUIeditor.C:339
jevois::GUIeditor
Editor panel for JeVois-Pro GUI.
Definition: GUIeditor.H:46
jevois
Definition: Concepts.dox:1
jevois::GUIeditor::draw
void draw()
Draw the editor into ImGui.
Definition: GUIeditor.C:102
jevois::EditorItem::displayname
std::string displayname
Definition: GUIeditor.H:39
jevois::GUIeditor::refresh
void refresh()
Refresh list of files.
Definition: GUIeditor.C:50
jevois::EditorItem::filename
std::filesystem::path filename
Definition: GUIeditor.H:38
jevois::EditorItem
Helper class to represent a GUIeditor file in a pull-down menu.
Definition: GUIeditor.H:37
jevois::GUIeditor::GUIeditor
GUIeditor(GUIhelper *helper, std::string const &imguiid, std::vector< EditorItem > &&fixeditems, std::string const &scanpath, std::string const &prefix, std::set< std::string > &&extensions)
Constructor.
Definition: GUIeditor.C:31
jevois::GUIeditor::~GUIeditor
virtual ~GUIeditor()
Destructor.
Definition: GUIeditor.C:46
ImGui
Definition: GUIeditor.H:27