JeVois  1.20
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, 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  //! Refresh list of files
63  void refresh();
64 
65  protected:
66  //! Save a file
67  void saveFile();
68 
69  private:
70  //! Load a file and set it as the current file
71  /*! If the load fails, we can either display failtxt in the editor and make it read-only, or, if failtxt is empty,
72  assume that we want to create a new file (e.g., module's params.cfg) and hence set the editor read-write. */
73  void loadFileInternal(std::filesystem::path const & fn, std::string const & failtxt);
74  GUIhelper * const itsHelper;
75  std::string const itsId;
76 
77  std::vector<EditorItem> itsItems;
78  size_t itsNumFixedItems;
79  std::string itsScanPath;
80  std::string const itsPrefix;
81  std::set<std::string> const itsExtensions;
82 
83  int itsCurrentItem = 0;
84  bool itsWantLoad = true;
85  bool itsWantAction = false;
86  bool itsOkToLoad = false;
87  bool itsOverrideReloadModule = false;
88  int itsNewItem = 0;
89  std::filesystem::path itsFilename;
90  std::unique_ptr<ImGui::FileBrowser> itsBrowser;
91  };
92 
93 
94 
95 } // namespace jevois
96 
97 #endif // JEVOIS_PRO
jevois::GUIeditor::saveFile
void saveFile()
Save a file.
Definition: GUIeditor.C:496
jevois::GUIeditor::EditorSaveAction
EditorSaveAction
Helper enum for actions to execute after saving a config file.
Definition: GUIeditor.H:34
jevois::EditorItem::action
EditorSaveAction action
What to do after file is edited and saved.
Definition: GUIeditor.H:40
jevois::GUIhelper
Helper class to assist modules in creating graphical and GUI elements.
Definition: GUIhelper.H:128
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:113
jevois::EditorItem::displayname
std::string displayname
Description of item in pull-down menu.
Definition: GUIeditor.H:39
jevois::GUIeditor::refresh
void refresh()
Refresh list of files.
Definition: GUIeditor.C:50
jevois::EditorItem::filename
std::filesystem::path filename
Full absolute path to the item.
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
jevois::GUIeditor::loadFile
void loadFile(std::filesystem::path const &fn)
Load a file and set it as the current file.
Definition: GUIeditor.C:362