0029807: [Regression to 7.0.0] Impossible to cut cone from prism
[occt.git] / tools / TInspector / TInspector_Preferences.hxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #ifndef TInspector_Preferences_H
17 #define TInspector_Preferences_H
18
19 #include <TCollection_AsciiString.hxx>
20 #include <inspector/TInspectorAPI_PreferencesDataMap.hxx>
21
22 #include <Standard_WarningsDisable.hxx>
23 #include <QDomElement>
24 #include <Standard_WarningsRestore.hxx>
25
26 //! The class to read/write custom plugin preferences in XML format.
27 //! The preferences file is intended to know about:
28 //! - dock window placement
29 //! - tree view columns: visibility, width
30 class TInspector_Preferences
31 {
32 public:
33   //! Constructs the communicator.
34   TInspector_Preferences() {}
35
36   //! Destructor
37   virtual ~TInspector_Preferences() {}
38
39   static Standard_CString PreferencesFileName() { return ".tinspector.xml"; }
40
41   //! Sets path to a preferences file
42   //! \param thePath a path
43   void SetDirectory (const TCollection_AsciiString& thePath) { reset(); myDirectory = thePath; }
44
45   //! Returns path to a preferences file
46   //! \return path
47   TCollection_AsciiString GetDirectory() const { return myDirectory; }
48
49   //! Returns plugin preferences
50   //! \param thePluginName a plugin name
51   Standard_EXPORT void GetPreferences (const TCollection_AsciiString& thePluginName,
52                                        TInspectorAPI_PreferencesDataMap& theItem);
53
54   //! Stores plugin preferences
55   //! \param thePluginName a plugin name
56   //! \theItem container of plugin preferences values in form: <name, value>
57   void SetPreferences (const TCollection_AsciiString& thePluginName, const TInspectorAPI_PreferencesDataMap& theItem)
58   { myLoadedPreferences.Bind(thePluginName, theItem); }
59
60   //! Store plugin preferences into a preferences file
61   Standard_EXPORT void StorePreferences();
62
63   //! Remove plugin preferences file
64   Standard_EXPORT void RemovePreferences();
65
66 private:
67   //! Loads the directory preference file with filling internal container
68   void loadPreferences();
69
70   //! clears all internal containers with information of already loaded file
71   void reset() { myLoadedPreferences.Clear(); myIsLoadedPreferences = Standard_False; }
72
73   //! Reads plugin preferences and fill container
74   void readPluginItem(const QDomElement thePluginElement, TInspectorAPI_PreferencesDataMap& theItem);
75
76   //! Returns text of attribute document
77   static Standard_CString documentKey() { return "document"; }
78
79   //! Returns text of attribute plugin
80   static Standard_CString pluginKey() { return "plugin"; }
81
82   //! Returns text of attribute parameter
83   static Standard_CString parameterKey() { return "parameter"; }
84
85   //! Returns text of attribute name
86   static Standard_CString nameKey() { return "name"; }
87
88   //! Returns text of attribute value
89   static Standard_CString valueKey() { return "value"; }
90
91 private:
92   //! directory of preferences file
93   TCollection_AsciiString myDirectory;
94   //! container of already loaded preferences : cache
95   NCollection_DataMap<TCollection_AsciiString, TInspectorAPI_PreferencesDataMap> myLoadedPreferences;
96   //! state whether the preferences of the current directory is loaded
97   Standard_Boolean myIsLoadedPreferences;
98 };
99
100 #endif