HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_OutputProcessor.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef __HUSD_OutputProcessor_h__
19 #define __HUSD_OutputProcessor_h__
20 
21 #include "HUSD_API.h"
22 #include <UT/UT_Function.h>
23 #include <UT/UT_SharedPtr.h>
24 #include <UT/UT_StringArray.h>
25 #include <UT/UT_StringMap.h>
26 
27 class UT_Options;
28 class UT_String;
29 class OP_Node;
31 
32 // ============================================================================
33 /// Performs processing on a USD output path during a save operation.
34 ///
36 {
37 public:
38  /// This enum describes the return value from the shouldSave method.
39  /// This enum must be kept in sync with the values in outputprocessors.py,
40  /// in the OutputProcessor class.
42  SHOULD_SAVE_FALSE = 0,
43  SHOULD_SAVE_TRUE = 1,
44  SHOULD_SAVE_NO_OPINION = 2
45  };
46 
47  /// Standard virtual destructor for this abstract base class.
48  virtual ~HUSD_OutputProcessor() = default;
49 
50  virtual void beginSave(OP_Node *config_node,
51  const UT_Options &config_overrides,
52  OP_Node *lop_node,
53  fpreal t,
54  const UT_Options &stage_variables,
56  { }
57 
58  virtual void endSave(OP_Node *config_node,
59  const UT_Options &config_overrides,
60  OP_Node *lop_node,
61  fpreal t,
62  const UT_Options &stage_variables,
63  const UT_StringArray &saved_paths,
64  const UT_String &error_messages,
66  { }
67 
68  virtual bool processSavePath(const UT_StringRef &asset_path,
69  const UT_StringRef &referencing_layer_path,
70  bool asset_is_layer,
71  UT_String &newpath,
73  { return false; }
74 
75  virtual bool processReferencePath(const UT_StringRef &asset_path,
76  const UT_StringRef &referencing_layer_path,
77  bool asset_is_layer,
78  UT_String &newpath,
80  { return false; }
81 
83  const UT_StringRef &asset_expression,
84  const UT_StringRef &referencing_layer_path,
85  bool asset_is_layer,
86  UT_String &newpath,
88  { return false; }
89 
90  virtual bool processLayer(const UT_StringRef &identifier,
92  { return false; }
93 
94  virtual HUSD_ShouldSave shouldSave(const UT_StringRef &save_path,
95  const UT_StringRef &identifier,
97  { return SHOULD_SAVE_NO_OPINION; }
98 
99  virtual UT_StringHolder displayName() const = 0;
100  virtual const PI_EditScriptedParms *parameters() const = 0;
101 
102  virtual bool hidden() const
103  { return false; }
104 };
108 
109 // ============================================================================
110 /// Keeps a list of known processors that can translate a USD output path
111 /// during a save operation.
112 ///
114 {
115 public:
116  /// Returns a singelton instance.
117  static HUSD_OutputProcessorRegistry &get();
118 
119  /// Returns a list of the names of all available processors.
120  UT_StringArray processorNames() const;
121 
122  /// Returns the processor that matches the supplied name.
123  HUSD_OutputProcessorPtr createProcessor(const UT_StringRef &name) const;
124 
125  /// Adds the processor to the list of known processors.
126  void registerOutputProcessor(
127  const UT_StringHolder &name,
128  const HUSD_OutputProcessorFactory &factory);
129 
130  /// Removes the processor from the list of known processors.
131  void unregisterOutputProcessor(
132  const UT_StringRef &name);
133 
134  /// Removes all processors from the registry. Should only be called on
135  /// shutdown of the process.
136  void clear();
137 
138 private:
139  /// Map of known output processors, keyed by their internal names.
140  UT_StringMap<HUSD_OutputProcessorFactory> myProcessorFactories;
141 };
142 
147 
148 #endif
HUSD_API UT_StringHolder HUSDremoveHfsOutputProcessorName()
virtual bool hidden() const
virtual bool processSavePath(const UT_StringRef &asset_path, const UT_StringRef &referencing_layer_path, bool asset_is_layer, UT_String &newpath, UT_String &error)
#define HUSD_API
Definition: HUSD_API.h:31
< returns > If no error
Definition: snippets.dox:2
virtual bool processLayer(const UT_StringRef &identifier, UT_String &error)
virtual void beginSave(OP_Node *config_node, const UT_Options &config_overrides, OP_Node *lop_node, fpreal t, const UT_Options &stage_variables, UT_String &error)
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
HUSD_API HUSD_OutputProcessorPtr HUSDcreateOutputProcessor(const UT_StringRef &name)
UT_Array< HUSD_OutputProcessorPtr > HUSD_OutputProcessorArray
virtual void endSave(OP_Node *config_node, const UT_Options &config_overrides, OP_Node *lop_node, fpreal t, const UT_Options &stage_variables, const UT_StringArray &saved_paths, const UT_String &error_messages, UT_String &error)
GLuint const GLchar * name
Definition: glcorearb.h:786
std::function< T > UT_Function
Definition: UT_Function.h:37
GLdouble t
Definition: glad.h:2397
A map of string to various well defined value types.
Definition: UT_Options.h:84
fpreal64 fpreal
Definition: SYS_Types.h:278
virtual HUSD_ShouldSave shouldSave(const UT_StringRef &save_path, const UT_StringRef &identifier, UT_String &error)
virtual bool processReferenceExpression(const UT_StringRef &asset_expression, const UT_StringRef &referencing_layer_path, bool asset_is_layer, UT_String &newpath, UT_String &error)
virtual bool processReferencePath(const UT_StringRef &asset_path, const UT_StringRef &referencing_layer_path, bool asset_is_layer, UT_String &newpath, UT_String &error)
UT_Function< HUSD_OutputProcessorPtr()> HUSD_OutputProcessorFactory
UT_SharedPtr< HUSD_OutputProcessor > HUSD_OutputProcessorPtr