Graphite  Version 3
An experimental 3D geometry processing program
application_base.h
1 /*
2  * GXML/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000 Bruno Levy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * If you modify this software, you should include a notice giving the
20  * name of the person performing the modification, the date of modification,
21  * and the reason for such modification.
22  *
23  * Contact: Bruno Levy
24  *
25  * levy@loria.fr
26  *
27  * ISA Project
28  * LORIA, INRIA Lorraine,
29  * Campus Scientifique, BP 239
30  * 54506 VANDOEUVRE LES NANCY CEDEX
31  * FRANCE
32  *
33  * Note that the GNU General Public License does not permit incorporating
34  * the Software into proprietary programs.
35  */
36 
37 
38 #ifndef H_SCENE_GRAPH_SKIN_APPLICATION_BASE_H
39 #define H_SCENE_GRAPH_SKIN_APPLICATION_BASE_H
40 
42 #include <OGF/gom/types/node.h>
43 #include <geogram/basic/progress.h>
44 #include <iostream>
45 
51 namespace OGF {
52 
58  gom_class SCENE_GRAPH_API ApplicationBase : public Object {
59 
60  public:
65  ApplicationBase(Interpreter* interpreter = nullptr);
66 
70  ~ApplicationBase() override;
71 
77  return interpreter_;
78  }
79 
80  static ApplicationBase* instance() {
81  return instance_;
82  }
83 
84  gom_properties:
85 
90  void set_tooltip(const std::string& x) {
91  tooltip_ = x;
92  // Interpret "\\n" in string.
93  for(
94  size_t index = tooltip_.find("\\n");
95  index != std::string::npos;
96  index = tooltip_.find("\\n", index+2)
97  ) {
98  tooltip_.replace(index, 2, " \n");
99  }
100  }
101 
107  const std::string& get_tooltip() const {
108  return tooltip_;
109  }
110 
111  gom_slots:
117  virtual void start();
118 
124  virtual void stop();
125 
134  virtual void set_style(const std::string& value);
135 
143  virtual void set_font_size(index_t value);
144 
154  const std::string& name,
155  const std::string& value,
156  const std::string& help=""
157  );
158 
162  virtual void save_preferences();
163 
164 
169  virtual void load_preferences(const std::string& filename);
170 
178  virtual bool preferences_loaded();
179 
186  virtual void cancel_current_job();
187 
194  virtual void draw();
195 
199  virtual void update();
200 
205  virtual void begin();
206 
213  virtual void progress(index_t step, index_t percent);
214 
221  virtual void end(bool canceled);
222 
228  std::string find_file(const std::string& filename) const;
229 
233  virtual void save_state();
234 
238  virtual void undo();
239 
243  virtual void redo();
244 
245 
249  virtual void progress_cancel();
250 
251 
255  virtual void post_draw();
256 
257  gom_properties:
258 
264  bool get_can_undo() const;
265 
266 
272  bool get_can_redo() const;
273 
274  gom_signals:
279  void started();
280 
287  void div(const std::string& value);
288 
295  void out(const std::string& value);
296 
303  void warn(const std::string& value);
304 
311  void err(const std::string& value);
312 
318  void status(const std::string& value);
319 
324  void notify_progress_begin(const std::string& value);
325 
331 
336 
346  static bool is_stopping() {
347  return stopping_;
348  }
349 
350 
351  protected:
352 
356  virtual void save_state_to_file(const std::string& filename);
357 
361  virtual void load_state_from_file(const std::string& filename);
362 
363 
373  std::string state_buffer_filename(index_t i) const;
374 
375 
383  static void set_stopping_flag() {
384  stopping_ = true;
385  }
386 
391  class ApplicationBaseLoggerClient : public LoggerClient {
392  public:
394 
398  void div(const std::string& value) override;
399 
403  void out(const std::string& value) override;
404 
408  void warn(const std::string& value) override;
409 
413  void err(const std::string& value) override;
414 
418  void status(const std::string& value) override;
419 
420  private:
421  ApplicationBase* application_base_;
422  };
423 
429  public:
431 
435  void begin() override;
436 
440  void progress(index_t step, index_t percent) override;
441 
445  void end(bool canceled) override;
446 
447  private:
448  ApplicationBase* application_base_;
449  };
450 
451  Interpreter* interpreter_;
452  LoggerClient_var logger_client_;
453  ProgressClient_var progress_client_;
454  std::string tooltip_;
455 
456  index_t state_buffer_begin_;
457  index_t state_buffer_end_;
458  index_t state_buffer_size_;
459  index_t state_buffer_current_;
460  bool undo_redo_called_;
461 
462  static ApplicationBase* instance_;
463  static bool stopping_;
464  bool started_callback_called_;
465  };
466 
467 }
468 
469 #endif
Task progress listener.
Definition: progress.h:76
A LoggerClient that redirects all messages to an ApplicationBase.
void out(const std::string &value) override
void div(const std::string &value) override
void status(const std::string &value) override
void warn(const std::string &value) override
void err(const std::string &value) override
A ProgressClient that redirects all messages to an ApplicationBase.
void begin() override
Starts listening progress.
void end(bool canceled) override
Stops listening progress.
void progress(index_t step, index_t percent) override
Tracks progress.
Base class for Application.
virtual void end(bool canceled)
ProgressClient overload, callback called by ProgressTask.
virtual void post_draw()
Called after each frame.
std::string state_buffer_filename(index_t i) const
Gets the file name to be used to store a state buffer.
void err(const std::string &value)
A signal that is triggered when the logger displays an error message.
virtual void save_state_to_file(const std::string &filename)
Saves Graphite state to a file.
virtual void save_state()
Saves state before applying command or tool, for undo()/redo().
void div(const std::string &value)
A signal that is triggered when a 'separation div' should be displayed in the logger.
virtual void progress_cancel()
Cancels current progress tastk.
virtual void begin()
ProgressClient overload, callback called by ProgressTask.
virtual void progress(index_t step, index_t percent)
ProgressClient overload, callback called by ProgressTask.
std::string find_file(const std::string &filename) const
Finds a file in the OGF_PATH.
Interpreter * interpreter()
Gets the main Interpreter.
virtual void save_preferences()
Saves the preferences to home directory / graphite.ini.
const std::string & get_tooltip() const
Gets the tooltip to be displayed near the cursor in the rendering area, or an empty string if there i...
virtual void draw()
Redraws the main window.
virtual void stop()
Stops the application.
void declare_preference_variable(const std::string &name, const std::string &value, const std::string &help="")
Declares a preference variable.
virtual void set_style(const std::string &value)
Sets the style to be used for widgets.
bool get_can_redo() const
Tests whether redo() can be called.
void notify_progress(index_t value)
A signal that is triggered when a ProgressTask is updated.
virtual void undo()
Restores last saved state if available.
void notify_progress_begin(const std::string &value)
A signal that is triggered when a ProgressTask starts.
ApplicationBase(Interpreter *interpreter=nullptr)
ApplicationBase constructor.
~ApplicationBase() override
ApplicationBase destructor.
static bool is_stopping()
Tests whether the application is stopping.
virtual void load_state_from_file(const std::string &filename)
Saves Graphite state to a file.
virtual void cancel_current_job()
Cancels the current job.
void out(const std::string &value)
A signal that is triggered when the logger displays a message.
virtual bool preferences_loaded()
Tests whether preferences were loaded.
void notify_progress_end()
A signal that is triggered when a ProgressTask finishes.
void status(const std::string &value)
A signal that is triggered when the message in the status bar should be updated.
virtual void redo()
Restores next saved state if available.
static void set_stopping_flag()
Indicates that the application is stopping, i.e. processes the last events from the event queue.
virtual void set_font_size(index_t value)
Sets the size of fonts in the application.
virtual void load_preferences(const std::string &filename)
Loads preference variables from a file.
void warn(const std::string &value)
A signal that is triggered when the logger displays a warning message.
virtual void update()
Indicates that the main window should be redrawn.
Abstract base class for the GOM interpreter.
Definition: interpreter.h:222
Base class for all objects in the GOM system.
Definition: object.h:65
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Global Graphite namespace.
Definition: common.h:76
The base class for all composite objects in the GOM system.
Functions and classes for displaying progress bars.
Definitions common to all include files in the scene_graph library.