4In VTK, certain classes can have what are called
"implementations". When the
5base
class is requested, it instead looks into a list of available
6implementations. One of the implementations is then constructed and returned
10constructed, it instead actually returns a window for the X window system,
11Cocoa, or Win32 depending
on what is available.
13VTK's implementation utilizes the
16module system. A module which contains an object factory must declare itself as
17`IMPLEMENTABLE` and modules which contain an implementation of an object
18factory must claim that they `IMPLEMENTS` modules containing those base object
19factories (a module may contain the object factory and an implementation; it
20then says that it `IMPLEMENTS` itself).
23set(_vtkObjectFactory_source_dir "${CMAKE_CURRENT_LIST_DIR}")
26@brief Declare a factory
override
28Declare that a
class in this module (the implementation) is an `OVERRIDE` for a
34 OVERRIDE <implementation>)
38 cmake_parse_arguments(PARSE_ARGV 0 _vtk_object_factory_declare
43 if (_vtk_object_factory_declare_UNPARSED_ARGUMENTS)
45 "Unparsed arguments for vtk_object_factory_declare: "
46 "${_vtk_object_factory_declare_UNPARSED_ARGUMENTS}")
49 if (NOT DEFINED _vtk_object_factory_declare_BASE)
51 "The `BASE` argument is required.")
54 if (NOT DEFINED _vtk_object_factory_declare_OVERRIDE)
56 "The `OVERRIDE` argument is required.")
59 set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}
" APPEND
61 _vtk_object_factory_overrides "${_vtk_object_factory_declare_OVERRIDE}
")
62 set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}
" APPEND
64 "_vtk_object_factory_override_${_vtk_object_factory_declare_OVERRIDE}
" "${_vtk_object_factory_declare_BASE}
")
68@brief Generate source for overrides in a module
70A module may only have a single declaration of all its object factory
71implementations. This function generates the source for all of the overrides
72declared using @ref vtk_object_factory_declare.
75vtk_object_factory_configure(
76 SOURCE_FILE <variable>
77 [HEADER_FILE <variable>]
78 [EXPORT_MACRO <macro>]
80 [EXTRA_INCLUDES <include>...])
83 - `SOURCE_FILE`: (Required) A variable to set to the path to generated source
85 - `HEADER_FILE`: (Recommended) A variable to set to the path to generated
86 header file. This should not be treated as a public header.
87 - `EXPORT_MACRO`: (Recommended) The export macro to add to the generated
89 - `INITIAL_CODE`: C++ code to run when the object factory is initialized.
90 - `EXTRA_INCLUDES`: A list of headers to include. The header names need to
91 include the `<>` or `""` quoting.
93function (vtk_object_factory_configure)
94 if (NOT DEFINED _vtk_build_module)
99 cmake_parse_arguments(PARSE_ARGV 0 _vtk_object_factory_configure
101 "SOURCE_FILE;HEADER_FILE;INITIAL_CODE;EXPORT_MACRO
"
104 if (_vtk_object_factory_configure_UNPARSED_ARGUMENTS)
107 "${_vtk_object_factory_configure_UNPARSED_ARGUMENTS}
")
110 get_property(_vtk_object_factory_done
112 PROPERTY "_vtk_object_factory_${_vtk_build_module}
"
114 if (_vtk_object_factory_done)
116 "An
object factory has already been created
for ${_vtk_build_module}.
")
120 "_vtk_object_factory_${_vtk_build_module}
" 1)
123 get_property(_vtk_object_factory_overrides
125 PROPERTY _vtk_object_factory_overrides)
127 if (NOT _vtk_object_factory_overrides)
129 "The ${_vtk_build_module} is generating an
object factory, but does not have any declared overrides.
")
132 set(_vtk_object_factory_doc
133 "Override
for ${_vtk_build_module}
module")
135 set(_vtk_object_factory_includes "")
136 set(_vtk_object_factory_functions "")
137 set(_vtk_object_factory_calls "")
139 foreach (_vtk_object_factory_extra_include IN LISTS _vtk_object_factory_configure_EXTRA_INCLUDES)
140 string(APPEND _vtk_object_factory_includes
141 "#include ${_vtk_object_factory_extra_include}\n")
144 foreach (_vtk_object_factory_override IN LISTS _vtk_object_factory_overrides)
145 get_property(_vtk_object_factory_base
147 PROPERTY "_vtk_object_factory_override_${_vtk_object_factory_override}")
148 string(APPEND _vtk_object_factory_includes
149 "#include \"${_vtk_object_factory_override}.h\"\n")
150 string(APPEND _vtk_object_factory_functions
151 "VTK_CREATE_CREATE_FUNCTION(${_vtk_object_factory_override})\n")
152 string(APPEND _vtk_object_factory_calls
153 "this->RegisterOverride(\"${_vtk_object_factory_base}\", \"${_vtk_object_factory_override}\", \"${_vtk_object_factory_doc}\", 1, vtkObjectFactoryCreate${_vtk_object_factory_override});\n
")
156 get_property(_vtk_object_factory_library_name GLOBAL
157 PROPERTY "_vtk_module_${_vtk_build_module}_library_name
")
159 set(_vtk_object_factory_overrides_header
160 "${CMAKE_CURRENT_BINARY_DIR}/${_vtk_object_factory_library_name}ObjectFactory.h
")
161 set(_vtk_object_factory_overrides_source
162 "${CMAKE_CURRENT_BINARY_DIR}/${_vtk_object_factory_library_name}ObjectFactory.cxx
")
166 "${_vtk_object_factory_overrides_header}
"
170 "${_vtk_object_factory_overrides_source}
"
173 if (_vtk_object_factory_configure_HEADER_FILE)
174 set("${_vtk_object_factory_configure_HEADER_FILE}
"
175 "${_vtk_object_factory_overrides_header}
"
179 set("${_vtk_object_factory_configure_SOURCE_FILE}
"
180 "${_vtk_object_factory_overrides_source}
"
abstract base class for vtkObjectFactories
create a window for renderers to draw into
function vtk_object_factory_configure()
Generate source for overrides in a module.
function vtk_object_factory_declare()
Declare a factory override.