HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GABC_LayerOptions.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) COPYRIGHTYEAR
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  */
27 
28 #ifndef __GABC_LayerOptions__
29 #define __GABC_LayerOptions__
30 
31 #include "GABC_API.h"
32 
33 #include <Alembic/Abc/Foundation.h>
36 #include <UT/UT_Array.h>
37 #include <UT/UT_String.h>
38 #include <UT/UT_StringHolder.h>
39 
40 namespace GABC_NAMESPACE
41 {
42 
44 {
45 public:
46 
47  // IMPORTANT: The order of the following two enums are significative.
48  // Make sure you understand how they work before you change them.
49 
50  // The LayerType is being widely used for exporting layering archive
51  // and it has different meaning for the nodes and the props.
52  // In the case of the nodes:
53  // NONE : The node won't exist in the archive.
54  // PRUNE : The empty sparse node with the prune metadata.
55  // SPARSE : The sparse node with several props.
56  // FULL : The common full node.
57  // REPLACE : The full node with the replace metadata.
58  // And for the props:
59  // NONE : The property won't exist in the archive.
60  // PRUNE : The empty property with the prune metadata.
61  // FULL : The common property.
62  // NOTE: Presently, the REPLACE and the SPARSE are illegal on the props.
63  enum class LayerType
64  {
65  NONE,
66  PRUNE,
67  SPARSE,
68  FULL,
69  REPLACE
70  };
71 
72  // Flag the visibility of the Alembic node. It contains all of the
73  // ObjectVisibilities and a DEFAULT. Which means setting the visibility
74  // by populating it from the houdini session.
75  enum class VizType
76  {
77  NONE,
78  DEFAULT,
79  DEFER,
80  HIDDEN,
81  VISIBLE
82  };
83 
86 
87  static void getMetadata(Alembic::Abc::MetaData &md,
88  LayerType type);
90  getSparseFlag(LayerType type);
92  getOVisibility(VizType type);
93 
94  void appendNodeRule(const UT_StringRef &nodePat,
95  LayerType type);
96  void appendVizRule(const UT_StringRef &nodePat,
97  VizType type);
98  void appendAttrRule(const UT_StringRef &nodePat,
99  const UT_StringRef &attrPat,
100  LayerType type);
101  void appendFaceSetRule(const UT_StringRef &nodePat,
102  const UT_StringRef &attrPat,
103  LayerType type);
104  void appendUserPropRule(const UT_StringRef &nodePat,
105  const UT_StringRef &userPropPat,
106  LayerType type);
107 
108  // The method should never be called in the saving process. The ROP_AbcNode
109  // should always hold the actual node type.
110  LayerType getNodeType(const UT_StringRef &nodePath) const;
111 
112  // These methods accept an extra node type then map it as proper property
113  // type before matching the pattern.
114  VizType getVizType(const UT_StringRef &nodePath,
115  LayerType nodeType) const;
116  LayerType getAttrType(const UT_StringRef &nodePath,
117  const UT_StringRef &attrName,
118  LayerType nodeType) const;
119  LayerType getFaceSetType(const UT_StringRef &nodePath,
120  const UT_StringRef &faceSetName,
121  LayerType nodeType) const;
122  LayerType getUserPropType(const UT_StringRef &nodePath,
123  const UT_StringRef &userPropName,
124  LayerType nodeType) const;
125 
126 private:
127  template <typename RULETYPE>
128  class Rules
129  {
130  struct Rule
131  {
132  Rule(const UT_StringHolder &pat, RULETYPE type) :
133  myNodePat(pat), myType(type) {}
134 
135  UT_StringHolder myNodePat;
136  RULETYPE myType;
137  };
138 
139  public:
140  Rules() {}
141  ~Rules() {}
142 
143  void append(const UT_StringRef &pattern, RULETYPE type)
144  { myData.append(Rule(pattern, type)); }
145 
146  RULETYPE getRule(const UT_StringRef &str) const
147  {
148  for(auto it = myData.begin();
149  it != myData.end(); ++it)
150  {
151  if(str.multiMatch(it->myNodePat))
152  return it->myType;
153  }
154  return (RULETYPE) 0;
155  }
156 
157  bool matchesNodePattern(const UT_StringRef &str) const
158  {
159  for(auto it = myData.begin();
160  it != myData.end(); ++it)
161  {
162  if(str.multiMatch(it->myNodePat))
163  return true;
164  }
165  return false;
166  }
167 
168  private:
169  UT_Array<Rule> myData;
170  };
171 
172  template <typename RULETYPE>
173  class MultiRules
174  {
175  struct Rule
176  {
177  Rule(const UT_StringHolder &pat, const UT_StringHolder &subPat,
178  RULETYPE type) :
179  myNodePat(pat), mySubPat(subPat), myType(type) {}
180 
181  UT_StringHolder myNodePat;
182  UT_StringHolder mySubPat;
183  RULETYPE myType;
184  };
185 
186  public:
187  MultiRules() {}
188  ~MultiRules() {}
189 
190  void append(const UT_StringRef &pat,
191  const UT_StringRef &subPat,
192  RULETYPE type)
193  { myData.append(Rule(pat, subPat, type)); }
194 
195  RULETYPE getRule(const UT_StringRef &str,
196  const UT_StringRef &subStr) const
197  {
198  for(auto it = myData.begin();
199  it != myData.end(); ++it)
200  {
201  if(str.multiMatch(it->myNodePat) &&
202  subStr.multiMatch(it->mySubPat))
203  return it->myType;
204  }
205  return (RULETYPE) 0;
206  }
207 
208  bool matchesNodePattern(const UT_StringRef &str) const
209  {
210  for(auto it = myData.begin();
211  it != myData.end(); ++it)
212  {
213  if(str.multiMatch(it->myNodePat))
214  return true;
215  }
216  return false;
217  }
218 
219  private:
220  UT_Array<Rule> myData;
221  };
222 
223  Rules<LayerType> myNodeData;
224  Rules<VizType> myVizData;
225  MultiRules<LayerType> myAttrData;
226  MultiRules<LayerType> myFaceSetData;
227  MultiRules<LayerType> myUserPropData;
228 };
229 
230 } // GABC_NAMESPACE
231 
232 #endif
unsigned multiMatch(const char *pattern, bool case_sensitive, char separator) const
#define GABC_NAMESPACE
Definition: GABC_API.h:42
simple inheritance: W = L * pW
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
ObjectVisibility
Values for the visibility property The top-compound object of AbcGeom Schema objects can include an o...
Definition: Visibility.h:60
#define GABC_API
Definition: GABC_API.h:37
GLubyte * pattern
Definition: glew.h:5711