Katana Plug-in APIs 0.1

FnViewerDelegateComponent.h

00001 // Copyright (c) 2016 The Foundry Visionmongers Ltd. All Rights Reserved.
00002 
00003 #ifndef FNVIEWER_VIEWERDELEGATECOMPONENT_H
00004 #define FNVIEWER_VIEWERDELEGATECOMPONENT_H
00005 
00006 #include <FnViewer/plugin/FnViewerDelegate.h>
00007 #include <FnViewer/plugin/FnViewerLocationEvent.h>
00008 #include <FnViewer/suite/FnViewerDelegateComponentSuite.h>
00009 
00010 #include <FnPluginSystem/FnPluginSystem.h>
00011 #include <FnPluginSystem/FnPlugin.h>
00012 #include <FnAttribute/FnAttribute.h>
00013 
00014 #include <string>
00015 #include <vector>
00016 #include <memory>
00017 
00018 namespace Foundry
00019 {
00020 namespace Katana
00021 {
00022 namespace ViewerAPI
00023 {
00024 
00064 class ViewerDelegateComponentPluginBase
00065 {
00066 public:
00067 
00069     ViewerDelegateComponentPluginBase();
00070 
00072     virtual ~ViewerDelegateComponentPluginBase();
00073 
00074 public: /* Methods to be called by the plugin. */
00075 
00082     ViewerDelegateWrapperPtr getViewerDelegate();
00083 
00100     FnAttribute::GroupAttribute getAttributes(const std::string& locationPath);
00101 
00103 public:
00104     static FnPlugStatus setHost(FnPluginHost* host);
00105     static FnPluginHost* getHost();
00106 
00107 protected:
00108     FnViewerDelegateComponentHostSuite_v2* m_hostSuite;
00109     FnViewerDelegateComponentHostHandle m_hostHandle;
00110 
00111     static FnPluginHost* m_host;
00112 
00113 private:
00114     ViewerDelegateWrapperPtr m_viewerDelegateWrapper;
00115 
00117 };
00118 
00119 
00121 class ViewerDelegateComponent : public ViewerDelegateComponentPluginBase
00122 {
00123 public:
00124     ViewerDelegateComponent();
00125     virtual ~ViewerDelegateComponent();
00126 
00127 public: /* Virtual functions to be extended by the plugin. */
00128 
00130     virtual void setup() = 0;
00131 
00133     virtual void cleanup() = 0;
00134 
00135     /* Scene Graph Events */
00136 
00150     virtual bool locationEvent(const ViewerLocationEvent& event,
00151             bool locationHandled) = 0;
00152 
00158     virtual void locationsSelected(
00159         const std::vector<std::string>& locationPaths) = 0;
00160 
00167     virtual bool isProcessing() const { return false; }
00168 
00175     static void flush() {}
00176 
00198     virtual void* getPrivateData(void* inputData) { return 0x0; }
00199 
00200     /* Options setting and getting. */
00201 
00214     virtual void setOption(OptionIdGenerator::value_type optionId,
00215                            FnAttribute::Attribute attr) {}
00216 
00228     virtual FnAttribute::Attribute getOption(
00229         OptionIdGenerator::value_type optionId);
00230 
00244     void setOption(const std::string& name, FnAttribute::Attribute attr);
00245 
00258     FnAttribute::Attribute getOption(const std::string& name);
00259 
00268     virtual FnAttribute::DoubleAttribute getBounds(
00269         const std::string& locationPath);
00270 
00281     virtual FnAttribute::DoubleAttribute computeExtent(
00282         const std::string& locationPath);
00283 
00285 public:
00286     static FnViewerDelegateComponentPluginSuite_v2 createSuite(
00287         FnViewerDelegateComponentPluginHandle (*create)(
00288             FnViewerDelegateComponentHostHandle hostHandle));
00289     static FnViewerDelegateComponentPluginHandle newViewerDelegateComponentHandle(
00290         ViewerDelegateComponent* viewerDelegateComponent);
00291 
00292     static unsigned int _apiVersion;
00293     static const char*  _apiName;
00294 
00295     void setHostHandle(FnViewerDelegateComponentHostHandle m_hostHandle);
00296     FnViewerDelegateComponentHostHandle getHostHandle();
00297 
00299 };
00300 
00301 
00303 class ViewerDelegateComponentWrapper : public ViewerDelegateComponentPluginBase
00304 {
00305 public:
00306     ViewerDelegateComponentWrapper(
00307         FnPluginHost* host,
00308         FnViewerDelegateComponentHostHandle hostHandle,
00309         FnViewerDelegateComponentPluginHandle pluginHandle,
00310         FnViewerDelegateComponentPluginSuite_v2* pluginSuite);
00311 
00312     ~ViewerDelegateComponentWrapper();
00313 
00332     template<class T> T* getPluginInstance()
00333     {
00334         return dynamic_cast<T*>(getPluginPointer());
00335     }
00336 
00338     void setOption(OptionIdGenerator::value_type optionId,
00339         FnAttribute::Attribute attr);
00341     FnAttribute::Attribute getOption(OptionIdGenerator::value_type optionId);
00343     void setOption(const std::string& name, FnAttribute::Attribute attr);
00345     FnAttribute::Attribute getOption(const std::string& name);
00346 
00348     FnAttribute::DoubleAttribute getBounds(const std::string& location);
00350     FnAttribute::DoubleAttribute computeExtent(const std::string& location);
00351 
00353 private:
00354     ViewerDelegateComponent* getPluginPointer();
00355 
00357     FnViewerDelegateComponentPluginSuite_v2* m_pluginSuite;
00358     FnViewerDelegateComponentPluginHandle m_pluginHandle;
00359 
00361 };
00362 
00363 typedef std::shared_ptr<ViewerDelegateComponentWrapper>
00364     ViewerDelegateComponentWrapperPtr;
00365 
00368 } // ViewerAPI
00369 } // Katana
00370 } // Foundry
00371 
00372 
00373 
00375 
00376 // Plugin-side structure to be pointed by the plugin handles.
00377 struct FnViewerDelegateComponentPluginStruct
00378 {
00379 public:
00380     FnViewerDelegateComponentPluginStruct(
00381         Foundry::Katana::ViewerAPI::ViewerDelegateComponent* viewerDelegateComponent)
00382     : m_ViewerDelegateComponent(viewerDelegateComponent)
00383     { }
00384 
00385     ~FnViewerDelegateComponentPluginStruct()
00386     { }
00387 
00388     Foundry::Katana::ViewerAPI::ViewerDelegateComponent* getViewerDelegateComponent()
00389     {
00390         return m_ViewerDelegateComponent.get();
00391     }
00392 
00393 private:
00394     std::shared_ptr<Foundry::Katana::ViewerAPI::ViewerDelegateComponent>
00395         m_ViewerDelegateComponent;
00396 };
00397 
00398 // Plugin Registering Macro.
00399 #define DEFINE_VIEWER_DELEGATE_COMPONENT_PLUGIN(VIEWER_DELEGATE_COMPONENT_CLASS)        \
00400                                                                               \
00401     FnPlugin VIEWER_DELEGATE_COMPONENT_CLASS##_plugin;                        \
00402                                                                               \
00403     FnViewerDelegateComponentPluginHandle VIEWER_DELEGATE_COMPONENT_CLASS##_create(     \
00404         FnViewerDelegateComponentHostHandle hostHandle)                       \
00405     {                                                                         \
00406         Foundry::Katana::ViewerAPI::ViewerDelegateComponent* viewerDelegateComponent =  \
00407             VIEWER_DELEGATE_COMPONENT_CLASS::create();                        \
00408                                                                               \
00409         viewerDelegateComponent->setHostHandle(hostHandle);                   \
00410         return Foundry::Katana::ViewerAPI::ViewerDelegateComponent::newViewerDelegateComponentHandle( \
00411             viewerDelegateComponent);                                         \
00412     }                                                                         \
00413                                                                               \
00414     FnViewerDelegateComponentPluginSuite_v2                                   \
00415         VIEWER_DELEGATE_COMPONENT_CLASS##_suite =                             \
00416             Foundry::Katana::ViewerAPI::ViewerDelegateComponent::createSuite( \
00417                     VIEWER_DELEGATE_COMPONENT_CLASS##_create);                \
00418                                                                               \
00419     const void* VIEWER_DELEGATE_COMPONENT_CLASS##_getSuite()                  \
00420     {                                                                         \
00421         return &VIEWER_DELEGATE_COMPONENT_CLASS##_suite;                      \
00422     }
00423 
00425 
00426 #endif
 All Classes Functions Variables Typedefs Enumerations Enumerator