HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
STY_StyleSheet.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: STY_StyleSheet.h ( STY Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __STY_StyleSheet__
12 #define __STY_StyleSheet__
13 
14 #include "STY_API.h"
15 #include "STY_Types.h"
16 #include <UT/UT_Array.h>
17 #include <UT/UT_NonCopyable.h>
18 #include <UT/UT_WorkBuffer.h>
19 #include <UT/UT_StringArray.h>
20 #include <UT/UT_StringMap.h>
21 #include <UT/UT_StringSet.h>
22 #include <UT/UT_IntrusivePtr.h>
23 #include <UT/UT_Lock.h>
24 
25 class STY_Material;
26 class STY_OverrideScript;
27 class UT_JSONWriter;
28 class UT_JSONValue;
29 class UT_IStream;
30 
31 /// Style sheet definition that contains style entries (an entry specifies the
32 /// target styling subject and overrides that need to be applied to the
33 /// properties of that subject. It also contains extra data needed for
34 /// successful overrides, such as material definitions.
36  public UT_NonCopyable,
37  public UT_IntrusiveRefCounter<STY_StyleSheet>
38 {
39 public:
40  /// Constructor and destructor.
41  explicit STY_StyleSheet(const UT_StringHolder &source_location,
42  STY_StyleSheetLoadMode load_mode);
43  explicit STY_StyleSheet(const char *json_str,
44  const UT_StringHolder &source_location,
45  STY_StyleSheetLoadMode load_mode);
46  explicit STY_StyleSheet(const UT_JSONValue &json_value,
47  const UT_StringHolder &source_location,
48  STY_StyleSheetLoadMode load_mode);
49  explicit STY_StyleSheet(
50  const UT_StringArray &import_files,
51  const UT_Array<STY_StyleHandle> &styles,
52  const STY_MaterialMap &materials,
53  const STY_OverrideScriptMap &scripts,
54  const STY_OverrideBlockMap &override_sets,
56  ~STY_StyleSheet();
57 
58  /// Utility function to track internally defined style sheets, to allow
59  /// one internal style sheet to reference another, and to treat internally
60  /// defined style sheet on par with external files.
61  static void setRegisteredStyleSheetMap(
63  stylesheet_map);
64 
65  /// Primitive/detail string attribute name that can define a style sheet.
66  static const UT_StringHolder &
67  getDefAttributeName();
68  /// Object parameter name that can define a style sheet.
69  static const UT_StringHolder &
70  getDefParmName();
71 
72  /// Object parameter label in the data tree
73  static const UT_StringHolder &
74  getDefParmLabel();
75 
76  /// Get any errors encounterd during the parsing of the stylesheet.
77  const UT_WorkBuffer &getErrors() const
78  { return myErrors; }
79 
80  /// Get the style entries defined by this style sheet.
82  getStyles() const
83  { return myStyles; }
84 
85  /// Gets all material definitions provided by the style sheet.
86  const STY_MaterialMap &
88  { return myMaterials; }
89 
90  /// Gets all shared script definitions provided by the style sheet.
91  const STY_OverrideScriptMap &
92  getScripts() const
93  { return myScripts; }
94 
95  /// Gets all material definitions provided by the style sheet.
96  const STY_OverrideBlockMap &
98  { return myOverrideSets; }
99 
100  /// Gets a list of imported style sheet files.
101  const UT_StringArray &
103  { return myImportFiles; }
104 
105  /// Gets the flags for this style sheet.
107  { return myFlags; }
108 
109  /// Saves the style sheet as text in JSON format.
110  void saveStyleSheet(UT_WorkBuffer &stylesheet) const;
111 
112 private:
113  /// Parses the JSON definition of the style sheet and builds internal data.
114  void loadStyleSheetString(const char *json_str,
115  const UT_StringHolder &source_location,
116  STY_StyleSheetLoadMode load_mode);
117  void loadStyleSheetFile(const UT_StringHolder &file_name,
118  STY_StyleSheetLoadMode load_mode);
119  void loadStyleSheet(UT_IStream &is,
120  const UT_StringHolder &file_name,
121  STY_StyleSheetLoadMode load_mode);
122  void loadStyleSheet(const UT_JSONValue &json_value,
123  const UT_StringHolder &file_name,
124  STY_StyleSheetLoadMode load_mode);
125 
126  /// A list of imported files (assuming we dont parse them on load).
127  UT_StringArray myImportFiles;
128  STY_StyleSheetLoadMode myLoadMode;
129 
130  /// A style contains the target specification and value overrides.
131  UT_Array<STY_StyleHandle> myStyles;
132 
133  /// Style sheet can define materials used in value overrides.
134  STY_MaterialMap myMaterials;
135 
136  /// Style sheet can define scripts referenced in override scripts.
137  STY_OverrideScriptMap myScripts;
138 
139  /// Style sheet can define override sets referenced in styles.
140  STY_OverrideBlockMap myOverrideSets;
141 
142  /// Holds errors generated during constuction/parsing.
143  UT_WorkBuffer myErrors;
144 
145  /// A set of all file names imported while loading this style sheet.
146  UT_StringSet myStyleSheetFiles;
147 
148  /// Flags that determine styler behavior.
149  STY_StyleSheetFlags myFlags;
150  bool myFlagsSet;
151 };
152 
153 #endif
154 
const UT_StringArray & getImportFiles() const
Gets a list of imported style sheet files.
GLbitfield flags
Definition: glcorearb.h:1596
Represents a material defined within a style sheet.
Definition: STY_Material.h:24
STY_StyleSheetLoadMode
Definition: STY_Types.h:63
const UT_WorkBuffer & getErrors() const
Get any errors encounterd during the parsing of the stylesheet.
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
#define STY_API
Definition: STY_API.h:10
A reference counter base class for use with UT_IntrusivePtr.
STY_StyleSheetFlags
Flags that may be set on stylesheets.
Definition: STY_Types.h:70
STY_StyleSheetFlags getFlags() const
Gets the flags for this style sheet.
Defines a script that computes an override value.
const STY_OverrideScriptMap & getScripts() const
Gets all shared script definitions provided by the style sheet.
const STY_OverrideBlockMap & getOverrideSets() const
Gets all material definitions provided by the style sheet.
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
const UT_Array< STY_StyleHandle > & getStyles() const
Get the style entries defined by this style sheet.
const STY_MaterialMap & getMaterialDefinitions() const
Gets all material definitions provided by the style sheet.