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,
91  const UT_StringRef &layersavepath,
93  { return false; }
94 
95  virtual HUSD_ShouldSave shouldSave(const UT_StringRef &save_path,
96  const UT_StringRef &identifier,
98  { return SHOULD_SAVE_NO_OPINION; }
99 
100  virtual UT_StringHolder displayName() const = 0;
101  virtual const PI_EditScriptedParms *parameters() const = 0;
102 
103  virtual bool hidden() const
104  { return false; }
105 };
109 
110 // ============================================================================
111 /// Keeps a list of known processors that can translate a USD output path
112 /// during a save operation.
113 ///
115 {
116 public:
117  /// Returns a singelton instance.
118  static HUSD_OutputProcessorRegistry &get();
119 
120  /// Returns a list of the names of all available processors.
121  UT_StringArray processorNames() const;
122 
123  /// Returns the processor that matches the supplied name.
124  HUSD_OutputProcessorPtr createProcessor(const UT_StringRef &name) const;
125 
126  /// Adds the processor to the list of known processors.
127  void registerOutputProcessor(
128  const UT_StringHolder &name,
129  const HUSD_OutputProcessorFactory &factory);
130 
131  /// Removes the processor from the list of known processors.
132  void unregisterOutputProcessor(
133  const UT_StringRef &name);
134 
135  /// Removes all processors from the registry. Should only be called on
136  /// shutdown of the process.
137  void clear();
138 
139 private:
140  /// Map of known output processors, keyed by their internal names.
141  UT_StringMap<HUSD_OutputProcessorFactory> myProcessorFactories;
142 };
143 
148 
149 #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 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:87
fpreal64 fpreal
Definition: SYS_Types.h:283
virtual bool processLayer(const UT_StringRef &identifier, const UT_StringRef &layersavepath, UT_String &error)
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