1 /*
2     This file is a part of the RepSnapper project.
3     Copyright (C) 2010 Michael Meeks
4     Copyright (C) 2013  martin.dieringer@gmx.de
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU Lesser General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU Lesser General Public License for more details.
15 
16     You should have received a copy of the GNU Lesser General Public License along
17     with this program; if not, write to the Free Software Foundation, Inc.,
18     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20 
21 #pragma once
22 
23 #include <string>
24 #include <giomm/file.h>
25 #include <glibmm/keyfile.h>
26 
27 #include "stdafx.h"
28 
29 
30 // Allow passing as a pointer to something to
31 // avoid including glibmm in every header.
32 typedef Glib::RefPtr<Gtk::Builder> Builder;
33 
34 
35 class Settings : public Glib::KeyFile {
36 
37   Glib::ustring filename; // where it's loaded from
38 
39   bool m_user_changed;
40   bool inhibit_callback; // don't update settings from gui while setting to gui
41 
42  public:
43 
44   void copyGroup(const string &from, const string &to);
45 
46   // overwrite to get the chance to make multiple extruder manipulations
47 
48   /* int      get_integer (const string &group, const string &name) const; */
49   /* double   get_double  (const string &group, const string &name) const; */
50   /* bool     get_boolean (const string &group, const string &name) const; */
51   /* string   get_string  (const string &group, const string &name) const; */
52   Vector4f get_colour  (const string &group, const string &name) const;
53 
54   /* void set_integer (const string &group, const string &name, const int value); */
55   /* void set_double  (const string &group, const string &name, const double value); */
56   /* void set_boolean (const string &group, const string &name, const bool value); */
57   /* void set_string  (const string &group, const string &name, const string &value); */
58   void set_colour  (const string &group, const string &name, const Vector4f &value);
59 
60   string numberedExtruder(const string &group, int num=-1) const;
61 
62 
63   vmml::vec3d getPrintVolume() const;
64   vmml::vec3d getPrintMargin() const;
65 
66 
67   static double RoundedLinewidthCorrection(double extr_width,
68 					   double layerheight);
69   double GetExtrudedMaterialWidth(const double layerheight) const;
70   double GetExtrusionPerMM(double layerheight) const;
71   std::vector<char> get_extruder_letters() const;
72   Vector3d get_extruder_offset(uint num) const;
73   uint GetSupportExtruder() const;
74   void CopyExtruder(uint num);
75   void RemoveExtruder(uint num);
76   void SelectExtruder(uint num, Builder *builder=NULL);
77   uint selectedExtruder;
78   uint getNumExtruders() const;
79 
80 
81   /* class GCodeImpl; */
82   /* enum GCodeTextType { */
83   /*   GCODE_TEXT_START, */
84   /*   GCODE_TEXT_LAYER, */
85   /*   GCODE_TEXT_END, */
86   /*   GCODE_TEXT_TYPE_COUNT */
87   /* }; */
88   /* struct GCodeType { */
89   /*   GCodeImpl *m_impl; */
90   /*   std::string getText(GCodeTextType t) const ; */
91   /*   std::string getStartText() const { return getText (GCODE_TEXT_START); } */
92   /*   std::string getLayerText() const { return getText (GCODE_TEXT_LAYER); } */
93   /*   std::string getEndText()   const { return getText (GCODE_TEXT_END);   } */
94   /* }; */
95   /* GCodeType GCode; */
96 
97 
98   // Paths we loaded / saved things to last time
99   std::string STLPath;
100   std::string RFOPath;
101   std::string GCodePath;
102   std::string SettingsPath;
103 
104 
105  private:
106   void set_to_gui              (Builder &builder, int i);
107   void set_to_gui              (Builder &builder,
108 				const string &group, const string &key);
109   void get_from_gui_old        (Builder &builder, int i);
110   void get_from_gui            (Builder &builder, const string &glade_name);
111   bool get_group_and_key       (int i, Glib::ustring &group, Glib::ustring &key);
112   void get_colour_from_gui     (Builder &builder, const string &glade_name);
113   void convert_old_colour      (const string &group, const string &key);
114   void set_defaults ();
115 
116  public:
117 
118   Settings();
119   ~Settings();
120 
has_user_changed()121   bool has_user_changed() const { return m_user_changed; }
122   void assign_from(Settings *pSettings);
123 
124   bool set_user_button(const string &name, const string &gcode);
125   bool del_user_button(const string &name);
126   string get_user_gcode(const string &name);
127 
128   Matrix4d getBasicTransformation(Matrix4d T) const;
129 
130   // return real mm depending on hardware extrusion width setting
131   double GetInfillDistance(double layerthickness, float percent) const;
132 
133   // sync changed settings with the GUI eg. used post load
134   void set_to_gui (Builder &builder, const string filter="");
135 
136   // connect settings to relevant GUI widgets
137   void connect_to_ui (Builder &builder);
138 
139 
140   void merge (const Glib::KeyFile &keyfile);
141   bool load_from_file (string file);
142   bool load_from_data (string data);
143 
144   void load_settings (Glib::RefPtr<Gio::File> file);
145   void load_settings_as (const Glib::ustring onlygroup = "",
146 			 const Glib::ustring as_group = "");
147   void save_settings (Glib::RefPtr<Gio::File> file);
148   void save_settings_as (const Glib::ustring onlygroup = "",
149 			 const Glib::ustring as_group = "");
150 
151   std::string get_image_path();
152 
153   sigc::signal< void > m_signal_visual_settings_changed;
154   sigc::signal< void > m_signal_update_settings_gui;
155   sigc::signal< void > m_signal_core_settings_changed;
156 };
157 
158