1 // Gmsh - Copyright (C) 1997-2021 C. Geuzaine, J.-F. Remacle 2 // 3 // See the LICENSE.txt file in the Gmsh root directory for license information. 4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues. 5 6 #ifndef FL_GUI_H 7 #define FL_GUI_H 8 9 #include <string> 10 #include <vector> 11 #include <atomic> 12 #include "SPoint2.h" 13 14 #define GMSH_WINDOW_BOX FL_FLAT_BOX 15 #define GMSH_SIMPLE_RIGHT_BOX (Fl_Boxtype)(FL_FREE_BOXTYPE + 1) 16 #define GMSH_SIMPLE_TOP_BOX (Fl_Boxtype)(FL_FREE_BOXTYPE + 2) 17 18 #define IW (10 * FL_NORMAL_SIZE) // input field width 19 #define BB (7 * FL_NORMAL_SIZE) // width of a button with internal label 20 #define BH (2 * FL_NORMAL_SIZE + 1) // button height 21 #define WB (5) // window border 22 23 class graphicWindow; 24 class openglWindow; 25 class optionWindow; 26 class onelabWindow; 27 class fieldWindow; 28 class pluginWindow; 29 class statisticsWindow; 30 class visibilityWindow; 31 class highOrderToolsWindow; 32 class clippingWindow; 33 class manipWindow; 34 class elementaryContextWindow; 35 class transformContextWindow; 36 class meshContextWindow; 37 class physicalContextWindow; 38 class onelabContextWindow; 39 class onelabGroup; 40 class helpWindow; 41 class Fl_Widget; 42 class drawContext; 43 44 class GVertex; 45 class GEdge; 46 class GFace; 47 class GRegion; 48 class MElement; 49 class PView; 50 51 class FlGui { 52 private: 53 static FlGui *_instance; 54 static std::string _openedThroughMacFinder; 55 static bool _finishedProcessingCommandLine; 56 static std::atomic<int> _locked; 57 std::string _lastStatus; 58 bool _quitShouldExit; 59 60 public: 61 std::vector<GVertex *> selectedVertices; 62 std::vector<GEdge *> selectedEdges; 63 std::vector<GFace *> selectedFaces; 64 std::vector<GRegion *> selectedRegions; 65 std::vector<MElement *> selectedElements; 66 std::vector<SPoint2> selectedPoints; 67 std::vector<PView *> selectedViews; 68 69 public: 70 std::vector<graphicWindow *> graph; 71 optionWindow *options; 72 fieldWindow *fields; 73 pluginWindow *plugins; 74 statisticsWindow *stats; 75 visibilityWindow *visibility; 76 highOrderToolsWindow *highordertools; 77 clippingWindow *clipping; 78 manipWindow *manip; 79 elementaryContextWindow *elementaryContext; 80 transformContextWindow *transformContext; 81 meshContextWindow *meshContext; 82 physicalContextWindow *physicalContext; 83 onelabContextWindow *onelabContext; 84 int lastContextWindow; 85 helpWindow *help; 86 onelabGroup *onelab; 87 openglWindow *fullscreen; 88 89 public: 90 FlGui(int argc, char **argv, bool quitShouldExit, 91 void (*error_handler)(const char *fmt, ...) = nullptr); 92 ~FlGui(); 93 // return the single static instance of the GUI 94 static FlGui *instance(int argc = 0, char **argv = nullptr, 95 bool quitShouldExit = true, 96 void (*error_handler)(const char *fmt, ...) = nullptr); 97 // destroy instance 98 static void destroy(); 99 // check if the GUI is available 100 static bool available(); 101 // run the GUI until there's no window left 102 static int run(); 103 // check if there are any pending events, and process them (if rateLimited is 104 // set, only perform the check if one has not been made in the last 1 / 105 // General.FltkRefreshRate seconds) 106 static void check(bool rateLimited = false); 107 // wait (possibly indefinitely) for any events, then process them 108 static void wait(bool force = false); 109 // wait (at most time seconds) for any events, then process them 110 static void wait(double time, bool force = false); 111 // lock/unlock child threads 112 static void lock(); 113 static void unlock(); 114 // trigger event loop in main thread 115 static void awake(const std::string &action); 116 // is locked 117 static int locked(); 118 // is a file opened through the Mac Finder? 119 static void setOpenedThroughMacFinder(const std::string &name); 120 static std::string getOpenedThroughMacFinder(); 121 static void setFinishedProcessingCommandLine(); 122 static bool getFinishedProcessingCommandLine(); 123 // test application-level keyboard shortcuts 124 int testGlobalShortcuts(int event); 125 // test the arrow shortcuts (not in the application-level shortcuts) 126 // since it is used elsewhere (where we want to override widget 127 // navigation). This is necessary since FLTK 1.1. 128 int testArrowShortcuts(); 129 // set the title of the graphic windows 130 void setGraphicTitle(const std::string &title); 131 // update the GUI when views get modified, added or deleted 132 void updateViews(bool numberOfViewsHasChanged, bool deleteWidgets); 133 // update the GUI when fields change 134 void updateFields(); 135 // reset the visibility window 136 void resetVisibility(); 137 // store current window positions and sizes in CTX 138 void storeCurrentWindowsInfo(); 139 // get the last opengl window that received an event 140 openglWindow *getCurrentOpenglWindow(); 141 // get the draw context from the last opengl window that received an event 142 drawContext *getCurrentDrawContext(); 143 // override which opengl window should be considered as current, by given an 144 // absolute index amongst all the existing opengl windows 145 void setCurrentOpenglWindow(int which); 146 // split the current opengl window 147 void splitCurrentOpenglWindow(char how, double ratio = 0.5); 148 // copy the current opengl window to the clipboard 149 void copyCurrentOpenglWindowToClipboard(); 150 // select an entity in the most recent graphic window 151 char selectEntity(int type); 152 // display status message 153 void setStatus(const std::string &msg, bool opengl = false); 154 // redisplay last status message 155 void setLastStatus(int col = -1); 156 // display status message and update progress bar 157 void setProgress(const std::string &msg, double val, double min, double max); 158 // add line in message console 159 void addMessage(const char *msg); 160 // save messages to file 161 void saveMessages(const char *fileName); 162 // rebuild the tree 163 void rebuildTree(bool deleteWidgets); 164 // open module in tree 165 void openModule(const std::string &name); 166 // open tree item 167 void openTreeItem(const std::string &name); 168 // close tree item 169 void closeTreeItem(const std::string &name); 170 // apply color scheme to widgets 171 void applyColorScheme(bool redraw = false); 172 // should the quit callback exit the app, or just close all windows? quitShouldExit()173 bool quitShouldExit() { return _quitShouldExit; } 174 // show onelab context window for the given entity 175 void showOnelabContext(int dim, int tag); 176 }; 177 178 void redraw_cb(Fl_Widget *w, void *data); 179 void window_cb(Fl_Widget *w, void *data); 180 181 #endif 182