HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UNI_Category.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: UNI_Category.h ( UN Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UNI_Category_h__
13 #define __UNI_Category_h__
14 
15 #include "UNI_API.h"
16 #include "UNI_Include.h"
17 #include <UT/UT_NonCopyable.h>
18 #include <UT/UT_Notifier.h>
19 #include <UT/UT_StringArray.h>
20 #include <UT/UT_UniquePtr.h>
21 
22 class UNI_NodeTypeEvent;
23 
24 
25 // ============================================================================
26 /// The category of node types, nodes, and port types that work together
27 /// in a domain-specific specialization context of the UNI graph.
28 ///
29 /// It groups these concepts into one umbrella, isolating them from other
30 /// incompatible nodes and types. It allows presenting available node types
31 /// and determine connectability of node ports, avoiding type collisions, etc.
32 ///
34 {
35 public:
36  /// @{ Constructor and destructor
38  const UT_StringRef &label = UT_StringRef() );
39  virtual ~UNI_Category();
41  /// @}
42 
43  /// Returns the name of this category.
44  /// It is used for finding node types in the category, filtering
45  /// shelved tools in the Tab menu, filtering RMB node menu items, etc.
46  const UT_StringHolder & name() const { return myName; }
47 
48  /// Returns the label of this category.
49  /// It is used for user-facing label of the category, such as the name
50  /// that appears in the upper-right corner of network editor, etc.
51  const UT_StringHolder & label() const
52  {
53  return myLabel ? myLabel : myName;
54  }
55 
56  /// Returns the list of known node type names in this category.
57  virtual UT_StringArray nodeTypeNames() const = 0;
58 
59  /// Returns true if the given node type name is valid in this category.
60  virtual bool isValidNodeType(
61  const UT_StringRef &type_name ) const = 0;
62 
63  /// Returns true if the given node type is hidden from the Tab menu.
64  virtual bool isHiddenNodeType(
65  const UT_StringRef &type_name ) const = 0;
66 
67  /// Returns the label of the given node type for the display in UI.
68  virtual UT_StringHolder nodeTypeLabel(
69  const UT_StringRef &type_name ) const = 0;
70 
71  /// Returns the name of the icon for the given node type.
72  virtual UT_StringHolder nodeTypeIcon(
73  const UT_StringRef &type_name ) const = 0;
74 
75  /// Returns the list of function signature names node type offers.
76  virtual UT_Array<UNI_Signature> nodeTypeSignatures(
77  const UT_StringRef &type_name ) const = 0;
78 
79  /// Returns node types names in the preferred order for the given node type.
80  /// Some node types may have several versions as well as namespaces,
81  /// and Houdini may be configured to prefer one namespace or version over
82  /// the other. This method returns the node types in that preferred ordered.
83  virtual UT_StringArray nodeTypeNamesInPrecedenceOrder(
84  const UT_StringRef &type_name ) const = 0;
85 
86  /// Returns the node type name used for a generic subnet in this context,
87  /// if there is any. Otherwise, returns an empty string.
88  virtual UT_StringHolder subnetNodeTypeName() const = 0;
89 
90  /// Returns the node type category names that can be children of the
91  /// specified node type.
92  virtual UT_StringArray childCategoryNames(
93  const UT_StringRef &type_name) const = 0;
94 
95  /// Returns true if Houdini should create a default shelf tool for
96  /// the given node type, if there is no such tool already.
97  virtual bool shouldGenerateToolForNodeType(
98  const UT_StringRef &type_name) const = 0;
99 
100  /// Information about the default shelf tool for a UNI node type.
101  class ToolInfo
102  {
103  public:
104  /// Shelf tool label.
105  void setLabel( const UT_StringRef &label )
106  { myLabel = label; }
107  const UT_StringHolder & label() const
108  { return myLabel; }
109 
110  /// Shelf tool sub-menu in the Tab menu.
111  void setSubmenus( const UT_StringArray &submenus )
112  { mySubmenus = submenus; }
113  const UT_StringArray & submenus() const
114  { return mySubmenus; }
115 
116  /// Shelf tool icon.
117  void setIcon( const UT_StringRef &icon )
118  { myIcon = icon; }
119  const UT_StringHolder & icon() const
120  { return myIcon; }
121 
122  /// Default name for the nodes created by the tool.
124  { myDefaultNodeName = name; }
126  { return myDefaultNodeName; }
127 
128  /// Shelf tool script.
129  void setScript( const UT_StringRef &script )
130  { myScript = script; }
131  const UT_StringHolder & script() const
132  { return myScript; }
133 
134  private:
135  UT_StringHolder myLabel; // Tool label
136  UT_StringArray mySubmenus; // Tab menu submenus for the tool
137  UT_StringHolder myIcon; // Tool icon
138  UT_StringHolder myDefaultNodeName; // Name of the created node
139  UT_StringHolder myScript; // Tool script
140  };
141 
142  /// Returns information about a default shelf tool for the given node type.
143  virtual ToolInfo nodeTypeToolInfo(
144  const UT_StringRef &type_name ) const = 0;
145 
146 
147  /// Returns an object for notifying interested parties about
148  /// changes to the known node types (adding a new or removing old one).
150  getNodeTypeEventNotifier() = 0;
151 
152 private:
153  /// The unique name of the category.
154  UT_StringHolder myName;
155 
156  /// The label of the category.
157  UT_StringHolder myLabel;
158 };
159 
160 /// A handle to the category object, for expressing the ownership.
162 
163 
164 // ============================================================================
165 /// Class containing info about node type registry change event.
167 {
168 public:
169  /// Enumeration of event types.
170  enum class Type
171  {
172  NodeTypeAdded, // Node type added
173  NodeTypeRemoved // Node type removed
174  };
175 
176  /// Constructor.
178  const UNI_Category &category, Type type, const UT_StringRef name )
179  : myCategory(category)
180  , myType(type)
181  , myName(name)
182  {}
183 
184  /// Category issuing the event.
185  const UNI_Category & category() const
186  { return myCategory; }
187 
188  /// Event type.
189  Type type() const
190  { return myType; }
191 
192  /// Name of added/removed node type.
193  const UT_StringHolder & name() const
194  { return myName; }
195 
196 private:
197  const UNI_Category & myCategory; // The category issuing event
198  Type myType; // Type of the event
199  const UT_StringHolder myName; // Name of affected node type
200 };
201 
202 #endif
203 
void setIcon(const UT_StringRef &icon)
Shelf tool icon.
Definition: UNI_Category.h:117
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
const UT_StringHolder & icon() const
Definition: UNI_Category.h:119
const UT_StringHolder & script() const
Definition: UNI_Category.h:131
void setSubmenus(const UT_StringArray &submenus)
Shelf tool sub-menu in the Tab menu.
Definition: UNI_Category.h:111
const UNI_Category & category() const
Category issuing the event.
Definition: UNI_Category.h:185
UNI_NodeTypeEvent(const UNI_Category &category, Type type, const UT_StringRef name)
Constructor.
Definition: UNI_Category.h:177
#define UNI_API
Definition: UNI_API.h:11
Class containing info about node type registry change event.
Definition: UNI_Category.h:166
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
Information about the default shelf tool for a UNI node type.
Definition: UNI_Category.h:101
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
const UT_StringHolder & label() const
Definition: UNI_Category.h:107
constexpr std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size(){return subtype_count< typename std::tuple_element< I, T >::type >::value+tuple_type_size< T, I+1 >);}template< typename T > struct type_count< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size< T, 0 >)};};template< typename T > struct subtype_count{static constexpr int value{is_mutable_container< T >::value?expected_max_vector_size:type_count< T >::value};};template< typename T, typename Enable=void > struct type_count_min{static const int value{0};};template< typename T >struct type_count_min< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_tuple_like< T >::value &&!is_wrapper< T >::value &&!is_complex< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{type_count< T >::value};};template< typename T > struct type_count_min< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr int value{1};};template< typename T >struct type_count_min< T, typename std::enable_if< is_wrapper< T >::value &&!is_complex< T >::value &&!is_tuple_like< T >::value >::type >{static constexpr int value{subtype_count_min< typename T::value_type >::value};};template< typename T, std::size_t I >constexpr typename std::enable_if< I==type_count_base< T >::value, int >::type tuple_type_size_min(){return 0;}template< typename T, std::size_t I > constexpr typename std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size_min(){return subtype_count_min< typename std::tuple_element< I, T >::type >::value+tuple_type_size_min< T, I+1 >);}template< typename T > struct type_count_min< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size_min< T, 0 >)};};template< typename T > struct subtype_count_min{static constexpr int value{is_mutable_container< T >::value?((type_count< T >::value< expected_max_vector_size)?type_count< T >::value:0):type_count_min< T >::value};};template< typename T, typename Enable=void > struct expected_count{static const int value{0};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_wrapper< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{1};};template< typename T > struct expected_count< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr int value{expected_max_vector_size};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&is_wrapper< T >::value >::type >{static constexpr int value{expected_count< typename T::value_type >::value};};enum class object_category:int{char_value=1, integral_value=2, unsigned_integral=4, enumeration=6, boolean_value=8, floating_point=10, number_constructible=12, double_constructible=14, integer_constructible=16, string_assignable=23, string_constructible=24, other=45, wrapper_value=50, complex_number=60, tuple_value=70, container_value=80,};template< typename T, typename Enable=void > struct classify_object{static constexpr object_category value{object_category::other};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&!std::is_same< T, char >::value &&std::is_signed< T >::value &&!is_bool< T >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::integral_value};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&std::is_unsigned< T >::value &&!std::is_same< T, char >::value &&!is_bool< T >::value >::type >{static constexpr object_category value{object_category::unsigned_integral};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_same< T, char >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::char_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_bool< T >::value >::type >{static constexpr object_category value{object_category::boolean_value};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_floating_point< T >::value >::type >{static constexpr object_category value{object_category::floating_point};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&std::is_assignable< T &, std::string >::value >::type >{static constexpr object_category value{object_category::string_assignable};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&(type_count< T >::value==1)&&std::is_constructible< T, std::string >::value >::type >{static constexpr object_category value{object_category::string_constructible};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::enumeration};};template< typename T > struct classify_object< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr object_category value{object_category::complex_number};};template< typename T > struct uncommon_type{using type=typename std::conditional<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&!std::is_constructible< T, std::string >::value &&!is_complex< T >::value &&!is_mutable_container< T >::value &&!std::is_enum< T >::value, std::true_type, std::false_type >::type;static constexpr bool value=type::value;};template< typename T >struct classify_object< T, typename std::enable_if<(!is_mutable_container< T >::value &&is_wrapper< T >::value &&!is_tuple_like< T >::value &&uncommon_type< T >::value)>::type >{static constexpr object_category value{object_category::wrapper_value};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::number_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&!is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::integer_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::double_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< is_tuple_like< T >::value &&((type_count< T >::value >=2 &&!is_wrapper< T >::value)||(uncommon_type< T >::value &&!is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value)||(uncommon_type< T >::value &&type_count< T >::value >=2))>::type >{static constexpr object_category value{object_category::tuple_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr object_category value{object_category::container_value};};template< typename T, enable_if_t< classify_object< T >::value==object_category::char_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"CHAR";}template< typename T, enable_if_t< classify_object< T >::value==object_category::integral_value||classify_object< T >::value==object_category::integer_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"INT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::unsigned_integral, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"UINT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::floating_point||classify_object< T >::value==object_category::number_constructible||classify_object< T >::value==object_category::double_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"FLOAT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::enumeration, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"ENUM";}template< typename T, enable_if_t< classify_object< T >::value==object_category::boolean_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"BOOLEAN";}template< typename T, enable_if_t< classify_object< T >::value==object_category::complex_number, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"COMPLEX";}template< typename T, enable_if_t< classify_object< T >::value >=object_category::string_assignable &&classify_object< T >::value<=object_category::other, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"TEXT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::container_value||classify_object< T >::value==object_category::wrapper_value, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value==1, detail::enabler >=detail::dummy >inline std::string type_name(){return type_name< typename std::decay< typename std::tuple_element< 0, T >::type >::type >);}template< typename T, std::size_t I >inline typename std::enable_if< I==type_count_base< T >::value, std::string >::type tuple_name(){return std::string{};}template< typename T, std::size_t I >inline typename std::enable_if<(I< type_count_base< T >::value), std::string >::type tuple_name(){auto str=std::string{type_name< typename std::decay< typename std::tuple_element< I, T >::type >::type >)}+ ','+tuple_name< T, I+1 >);if(str.back()== ',') str.pop_back();return str;}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler > > std::string type_name()
Recursively generate the tuple type name.
Definition: CLI11.h:1729
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
GLuint const GLchar * name
Definition: glcorearb.h:786
const UT_StringArray & submenus() const
Definition: UNI_Category.h:113
const UT_StringHolder & label() const
Definition: UNI_Category.h:51
void setDefaultNodeName(const UT_StringRef &name)
Default name for the nodes created by the tool.
Definition: UNI_Category.h:123
Type type() const
Event type.
Definition: UNI_Category.h:189
UT_UniquePtr< UNI_Category > UNI_CategoryHandle
A handle to the category object, for expressing the ownership.
Definition: UNI_Category.h:161
const UT_StringHolder & defaultNodeName() const
Definition: UNI_Category.h:125
const UT_StringHolder & name() const
Name of added/removed node type.
Definition: UNI_Category.h:193
Type
Enumeration of event types.
Definition: UNI_Category.h:170
void setScript(const UT_StringRef &script)
Shelf tool script.
Definition: UNI_Category.h:129
void setLabel(const UT_StringRef &label)
Shelf tool label.
Definition: UNI_Category.h:105