HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_UserOption.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: GR_UserOption.h ( GR Library, C++)
7  *
8  * COMMENTS:
9  * A GR_UserOption is a custom display option which can be toggled on/off
10  * and contain any arbitrary settings.
11  */
12 
13 #ifndef __GR_UserOption__
14 #define __GR_UserOption__
15 
16 #include "GR_API.h"
17 #include <UT/UT_String.h>
18 #include <UT/UT_Vector3.h>
19 #include <UT/UT_VectorTypes.h>
20 #include "GR_Defines.h"
21 
22 // Option tokens for all GR_UserOption subclasses.
23 #define GR_LABEL_TOKEN "label"
24 #define GR_ICON_TOKEN "icon"
25 #define GR_VISIBILITY_TOKEN "visibility"
26 #define GR_ATTRIB_TOKEN "attrib"
27 #define GR_GROUP_TOKEN "group"
28 #define GR_CLASS_TOKEN "class"
29 #define GR_OVERRIDECOLOR_TOKEN "overridecolor"
30 #define GR_COLOR_TOKEN "color"
31 #define GR_SELCOLOR_TOKEN "selcolor"
32 #define GR_STYLE_TOKEN "style"
33 #define GR_FLAGS_TOKEN "flags"
34 
35 // Option tokens for GR_VectorOption.
36 #define GR_SCALE_TOKEN "scale"
37 #define GR_ARROW_TOKEN "arrow"
38 // obsolete tokens
39 #define GR_FADE_TOKEN "fade"
40 
41 // Option tokens for GR_GenericOption
42 #define GR_STRING_TOKEN "string"
43 
44 class GR_OptionTemplate;
45 class GR_UserDecoration;
46 class GU_Detail;
47 class UT_Options;
48 
50 {
56 };
57 
59 {
60 public:
61  const char *myName;
62  int myType;
63 };
64 
66 {
67 public:
68  GR_UserOption(const char *name, const char *label,
69  GR_OptionTemplate *entry);
70 
71  virtual ~GR_UserOption();
72 
73  const char *getName() const { return (const char *) myName; }
74  void setName(const char *name) { myName.harden(name); }
75  const char *getLabel() const { return (const char *) myLabel; }
76  void setLabel(const char *label) { myLabel.harden(label); }
77  const char *getIconName() const { return (const char *) myIconName; }
78  void setIconName(const char *name);
79  GR_DecorVisibility getVisibility() const { return myVisibility; }
80  void setVisibility(GR_DecorVisibility v) { myVisibility = v; }
81 
82  // Changing the state of this option will trigger a geometry refinement
83  // if 'ref_req' is true. This is primarily used by filter-style render
84  // hooks. This can only be called during setup of the option.
85  void setRefineRequired(bool ref_req) { myRefineRequired=ref_req; }
86  bool isRefineRequired() const { return myRefineRequired; }
87 
88  // Hide the option from the Display Options dialog. Should only be called
89  // during option setup.
90  void setHidden(bool hide) { myHidden = hide; }
91  bool isHidden() const { return myHidden; }
92 
93  GR_OptionTemplate *getTemplate() const { return myTemplate; }
94 
95  // The version count is incremented whenever the settings of the
96  // option are changed.
97  int getVersion() const { return myVersion; }
98  void bumpVersion() { myVersion++; }
99 
100  virtual GR_UserOption *duplicate() const = 0;
101 
102  // Class I/O methods. They return 0 if successful, -1 if not.
103  virtual int saveCommand(std::ostream &os) const;
104  virtual bool loadCommand(UT_IStream &is);
105 
106  virtual bool save(std::ostream &os, int indent) const;
107  virtual bool load(UT_IStream &is);
108 
109  // Methods to manipulate the internal settings of the option. The apply
110  // method returns a boolean to indicate whether the settings have changed.
111  virtual void querySettings(UT_Options &options) const = 0;
112  virtual bool applySettings(const UT_Options &options) = 0;
113 
114  virtual const char *getAttribute() const { return NULL; }
115  virtual int getAttributeType() const { return 0; }
116  virtual fpreal getScale() const { return 1.0; }
117  virtual bool getArrowTip() const { return false; }
118  virtual bool getOverrideColor() const { return false; }
119  virtual UT_Vector3 getColor() const { return UT_Vector3(); }
120  virtual UT_Vector3 getSelectColor() const{return UT_Vector3();}
122  { return GR_USER_OPTION_GENERIC; }
123 
124  // A utility method to output settings as a single line where each
125  // setting is saved in the form:
126  // <token> ( <value1>, [<value2>...] ).
127  // Return 0 if successful, -1 if not.
128  // TODO: Take templates to specify order as UT_Options is sorted!
129  static int saveSettings(std::ostream &os,
130  const UT_Options &options, bool for_cmd);
131 
132  // A utility method to extract settings from an input stream where each
133  // settings is stored in the form:
134  // <token> ( <value1>, [<value2>...] )
135  //
136  // A terminal token can be specified to stop the processing of the stream
137  // when it is encountered.
138  static bool loadSettings(UT_IStream &is,
139  const GR_UserOptionParm *parm_templates,
140  UT_Options &options, bool for_cmd,
141  const char *terminal_token = 0);
142 
143 protected:
145 
146  virtual const GR_UserOptionParm *getSettingTemplates() const = 0;
147 
148  static void getDefaultColor(UT_Vector3 &clr);
149  static void getDefaultSelColor(UT_Vector3 &clr);
150 
151  // Utility methods to query a specified setting. The return value is used
152  // to indicate the setting differs from the passed in value.
153  static bool querySetting(const UT_Options &options,
154  const char *name, bool &v);
155  static bool querySetting(const UT_Options &options,
156  const char *name, float &v);
157  static bool querySetting(const UT_Options &options,
158  const char *name, UT_String &v);
159  static bool querySetting(const UT_Options &options,
160  const char *name, UT_Vector3 &v);
161  static bool querySetting(const UT_Options &options,
162  const char *name, exint &i);
163 
164 private:
165  UT_String myName;
166  UT_String myLabel;
167  UT_String myIconName;
168  GR_OptionTemplate *myTemplate;
169  GR_DecorVisibility myVisibility;
170  bool myRefineRequired;
171  bool myHidden;
172 
173  int myVersion;
174 };
175 
176 #endif
const char * myName
Definition: GR_UserOption.h:61
virtual fpreal getScale() const
virtual UT_Vector3 getSelectColor() const
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
const GLdouble * v
Definition: glcorearb.h:837
UT_Vector3T< float > UT_Vector3
int64 exint
Definition: SYS_Types.h:125
const char * getIconName() const
Definition: GR_UserOption.h:77
const char * getLabel() const
Definition: GR_UserOption.h:75
virtual GR_UserOptionType getOptionType() const
GR_DecorVisibility
Definition: GR_Defines.h:192
const char * getName() const
Definition: GR_UserOption.h:73
void setHidden(bool hide)
Definition: GR_UserOption.h:90
GR_OptionTemplate * getTemplate() const
Definition: GR_UserOption.h:93
#define GR_API
Definition: GR_API.h:10
bool isHidden() const
Definition: GR_UserOption.h:91
void setLabel(const char *label)
Definition: GR_UserOption.h:76
GLuint const GLchar * name
Definition: glcorearb.h:786
void setName(const char *name)
Definition: GR_UserOption.h:74
void setRefineRequired(bool ref_req)
Definition: GR_UserOption.h:85
virtual UT_Vector3 getColor() const
A map of string to various well defined value types.
Definition: UT_Options.h:84
GR_UserOptionType
Definition: GR_UserOption.h:49
GR_DecorVisibility getVisibility() const
Definition: GR_UserOption.h:79
fpreal64 fpreal
Definition: SYS_Types.h:277
virtual int getAttributeType() const
bool isRefineRequired() const
Definition: GR_UserOption.h:86
virtual const char * getAttribute() const
void setVisibility(GR_DecorVisibility v)
Definition: GR_UserOption.h:80
virtual bool getOverrideColor() const
virtual bool getArrowTip() const
int getVersion() const
Definition: GR_UserOption.h:97
void bumpVersion()
Definition: GR_UserOption.h:98
GLenum src
Definition: glcorearb.h:1793