|
Katana Plug-in APIs 0.1
|
00001 // Copyright (c) 2016 The Foundry Visionmongers Ltd. All Rights Reserved. 00002 00003 #ifndef FNVIEWER_VIEWERDELEGATE_H 00004 #define FNVIEWER_VIEWERDELEGATE_H 00005 00006 #include <FnViewer/suite/FnViewerDelegateSuite.h> 00007 #include <FnViewer/plugin/FnOptionIdGenerator.h> 00008 #include <FnViewer/plugin/FnMathTypes.h> 00009 #include <FnViewer/plugin/FnViewerLocationEvent.h> 00010 00011 #include <FnPluginSystem/FnPluginSystem.h> 00012 #include <FnPluginSystem/FnPlugin.h> 00013 #include <FnAttribute/FnAttribute.h> 00014 00015 #include <string> 00016 #include <vector> 00017 #include <memory> 00018 00019 namespace Foundry 00020 { 00021 namespace Katana 00022 { 00023 namespace ViewerAPI 00024 { 00025 00026 // Forward declaration. 00027 class ViewerDelegateComponentWrapper; 00028 typedef std::shared_ptr<ViewerDelegateComponentWrapper> 00029 ViewerDelegateComponentWrapperPtr; 00030 class ViewportWrapper; 00031 typedef std::shared_ptr<ViewportWrapper> ViewportWrapperPtr; 00032 00101 class ViewerDelegatePluginBase 00102 { 00103 public: 00104 00106 ViewerDelegatePluginBase(); 00107 00109 virtual ~ViewerDelegatePluginBase(); 00110 00111 public: /* Methods to be called by the plugin. */ 00112 00113 /* Geolib3 Methods */ 00114 00134 FnAttribute::GroupAttribute getAttributes( 00135 const std::string& locationPath, 00136 FnViewerDelegateSceneView sceneView = kFnViewerDelegatePrimary); 00137 00150 Matrix44d getLocalXform( 00151 const std::string& locationPath, bool& isAbsolute, 00152 FnViewerDelegateSceneView sceneView = kFnViewerDelegatePrimary); 00153 00162 Matrix44d getWorldXform( 00163 const std::string& locationPath, 00164 FnViewerDelegateSceneView sceneView = kFnViewerDelegatePrimary); 00165 00174 Matrix44d getParentXform( 00175 const std::string& locationPath, 00176 FnViewerDelegateSceneView sceneView = kFnViewerDelegatePrimary); 00177 00237 Matrix44d getPartialXform( 00238 const std::string& locationPath, const std::string& groupName, 00239 const std::string& componentName, bool includeComponent, 00240 FnViewerDelegateSceneView sceneView = kFnViewerDelegatePrimary, 00241 bool includeParentXform = true, bool includeBeforeGroup = true, 00242 bool includeAfterGroup = false); 00243 00244 /* Location open/close Methods */ 00245 00254 void openLocation(const std::string& locationPath); 00255 00266 void openLocations(const std::vector<std::string>& locationPaths); 00267 00277 void closeLocation(const std::string& locationPath); 00278 00290 void closeLocations(const std::vector<std::string>& locationPaths); 00291 00292 /* Source activation methods */ 00293 00302 void activateSourceLocation(const std::string& locationPath); 00303 00312 void activateSourceLocations( 00313 const std::vector<std::string>& locationPaths); 00314 00320 void deactivateSourceLocation(const std::string& locationPath); 00321 00327 void deactivateSourceLocations( 00328 const std::vector<std::string>& locationPaths); 00329 00330 /* Location selection functions */ 00331 00337 void selectLocation(const std::string& locationPath); 00338 00344 void selectLocations(const std::vector<std::string>& locationPaths); 00345 00351 void getSelectedLocations(std::vector<std::string>& locationPaths); 00352 00353 /* ViewerDelegateComponent Management Methods */ 00354 00366 ViewerDelegateComponentWrapperPtr addComponent( 00367 const std::string& pluginName, const std::string& name); 00368 00382 ViewerDelegateComponentWrapperPtr insertComponent( 00383 const std::string& pluginName, const std::string& name, 00384 unsigned int index); 00385 00396 ViewerDelegateComponentWrapperPtr getComponent( 00397 const std::string& name) const; 00398 00411 ViewerDelegateComponentWrapperPtr getComponent(unsigned int index) const; 00412 00420 void removeComponent(const std::string& name); 00421 00431 void removeComponent(unsigned int index); 00432 00441 unsigned int getNumberOfComponents() const; 00442 00452 std::string getComponentName(unsigned int index); 00453 00462 int getComponentIndex(const std::string& name); 00463 00464 /* Viewport access methods */ 00465 00477 ViewportWrapperPtr getViewport(const std::string& name); 00478 00494 ViewportWrapperPtr getViewport(unsigned int index); 00495 00507 unsigned int getNumberOfViewports(); 00508 00519 std::string getViewportName(unsigned int index); 00520 00521 00522 /* Other Methods */ 00523 00557 FnAttribute::GroupAttribute getCompatibleManipulatorsInfo( 00558 const std::vector<std::string>& locationPaths); 00559 00576 FnAttribute::Attribute callPythonCallback(const std::string& name, 00577 FnAttribute::Attribute message); 00578 00593 FnAttribute::GroupAttribute getLiveAttributes( 00594 const std::string& locationPath, 00595 FnViewerDelegateSceneView sceneView = kFnViewerDelegatePrimary); 00596 00610 FnAttribute::GroupAttribute getCookedAttributes( 00611 const std::string& locationPath, 00612 FnViewerDelegateSceneView sceneView = kFnViewerDelegatePrimary); 00613 00654 bool setManipulatedAttribute(const std::string& locationPath, 00655 const std::string& attrName, 00656 FnAttribute::Attribute valueAttr, 00657 bool isFinal); 00658 00672 void openManipulationGroup(const std::string& locationPath); 00673 00681 void closeManipulationGroup(const std::string& locationPath); 00682 00689 void setBoundingBoxesEnabled(bool enabled); 00690 00697 void setProxyGeometryEnabled(bool enabled); 00698 00709 FnAttribute::StringAttribute getDescendantLocations( 00710 const std::string& location); 00711 00726 FnAttribute::DoubleAttribute computeMergedExtent( 00727 const std::vector<std::string>& locations, 00728 const std::string& excludeLocation); 00729 00731 public: 00732 static FnPlugStatus setHost(FnPluginHost* host); 00733 static FnPluginHost* getHost(); 00734 00735 protected: 00736 static FnPluginHost* m_host; 00737 00738 FnViewerDelegateHostSuite_v4* m_hostSuite; 00739 FnViewerDelegateHostHandle m_hostHandle; 00740 00742 }; 00743 00744 00746 class ViewerDelegate : public ViewerDelegatePluginBase 00747 { 00748 public: 00749 00751 ViewerDelegate(); 00752 00754 virtual ~ViewerDelegate(); 00755 00757 virtual void setup() = 0; 00758 00760 virtual void cleanup() = 0; 00761 00774 virtual FnAttribute::DoubleAttribute getBounds( 00775 const std::string& locationPath); 00776 00789 virtual FnAttribute::DoubleAttribute computeExtent( 00790 const std::string& locationPath); 00791 00792 public: /* Virtual functions to be extended by the plugin. */ 00793 00821 virtual void* getPrivateData(void* inputData) { return 0x0; } 00822 00823 /* Scene Graph Events */ 00824 00835 virtual void locationEvent(const ViewerLocationEvent& event, 00836 bool locationHandled) = 0; 00837 00844 virtual void sourceLocationEvent(const ViewerLocationEvent& event) = 0; 00845 00851 virtual void locationsSelected( 00852 const std::vector<std::string>& locationPaths) = 0; 00853 00860 virtual bool isProcessing() const { return false; } 00861 00862 /* Options setting and getting. */ 00863 00877 virtual void setOption(OptionIdGenerator::value_type optionId, 00878 FnAttribute::Attribute attr) {} 00879 00891 virtual FnAttribute::Attribute getOption( 00892 OptionIdGenerator::value_type optionId); 00893 00907 void setOption(const std::string& name, FnAttribute::Attribute attr); 00908 00921 FnAttribute::Attribute getOption(const std::string& name); 00922 00923 /* General Methods */ 00924 00935 virtual void freeze() = 0; 00936 00945 virtual void thaw() = 0; 00946 00953 static void flush() {} 00954 00956 public: 00957 static FnViewerDelegatePluginSuite_v3 createSuite( 00958 FnViewerDelegatePluginHandle (*create)( 00959 FnViewerDelegateHostHandle hostHandle)); 00960 00961 static FnViewerDelegatePluginHandle newViewerDelegateHandle( 00962 ViewerDelegate* viewerDelegate); 00963 00964 static unsigned int _apiVersion; 00965 static const char* _apiName; 00966 00967 void setHostHandle(FnViewerDelegateHostHandle hostHandle); 00968 00970 }; 00971 00973 class ViewerDelegateWrapper : public ViewerDelegatePluginBase 00974 { 00975 public: 00976 ViewerDelegateWrapper( 00977 FnPluginHost* host, 00978 FnViewerDelegateHostHandle hostHandle, 00979 FnViewerDelegatePluginHandle pluginHandle, 00980 FnViewerDelegatePluginSuite_v3* pluginSuite); 00981 00982 ~ViewerDelegateWrapper(); 00983 01001 template<class T> T* getPluginInstance() 01002 { 01003 return dynamic_cast<T*>(getPluginPointer()); 01004 } 01005 01007 void setOption(OptionIdGenerator::value_type optionId, FnAttribute::Attribute attr); 01008 01010 FnAttribute::Attribute getOption(OptionIdGenerator::value_type optionId); 01011 01013 void setOption(const std::string& name, FnAttribute::Attribute attr); 01014 01016 FnAttribute::Attribute getOption(const std::string& name); 01017 01019 private: 01020 ViewerDelegate* getPluginPointer(); 01021 01023 FnViewerDelegatePluginSuite_v3* m_pluginSuite; 01024 FnViewerDelegatePluginHandle m_pluginHandle; 01025 01027 }; 01028 01029 typedef std::shared_ptr<ViewerDelegateWrapper> ViewerDelegateWrapperPtr; 01030 01033 } // ViewerAPI 01034 } // Katana 01035 } // Foundry 01036 01037 01038 01040 01041 // Plugin-side structure to be pointed by the plugin handles. 01042 struct FnViewerDelegatePluginStruct 01043 { 01044 public: 01045 FnViewerDelegatePluginStruct( 01046 Foundry::Katana::ViewerAPI::ViewerDelegate* viewerDelegate) 01047 : m_viewerDelegate(viewerDelegate) 01048 { } 01049 01050 ~FnViewerDelegatePluginStruct() 01051 { }; 01052 01053 Foundry::Katana::ViewerAPI::ViewerDelegate* getViewerDelegate() 01054 { 01055 return m_viewerDelegate.get(); 01056 } 01057 01058 private: 01059 std::shared_ptr< 01060 Foundry::Katana::ViewerAPI::ViewerDelegate> m_viewerDelegate; 01061 }; 01062 01063 // Plugin Registering Macro. 01064 #define DEFINE_VIEWER_DELEGATE_PLUGIN(VIEWER_DELEGATE_CLASS) \ 01065 \ 01066 FnPlugin VIEWER_DELEGATE_CLASS##_plugin; \ 01067 \ 01068 FnViewerDelegatePluginHandle VIEWER_DELEGATE_CLASS##_create( \ 01069 FnViewerDelegateHostHandle hostHandle) \ 01070 { \ 01071 Foundry::Katana::ViewerAPI::ViewerDelegate* viewerDelegate = \ 01072 VIEWER_DELEGATE_CLASS::create(); \ 01073 \ 01074 viewerDelegate->setHostHandle(hostHandle); \ 01075 return Foundry::Katana::ViewerAPI::ViewerDelegate::newViewerDelegateHandle( \ 01076 viewerDelegate); \ 01077 } \ 01078 \ 01079 FnViewerDelegatePluginSuite_v3 VIEWER_DELEGATE_CLASS##_suite = \ 01080 Foundry::Katana::ViewerAPI::ViewerDelegate::createSuite( \ 01081 VIEWER_DELEGATE_CLASS##_create); \ 01082 \ 01083 const void* VIEWER_DELEGATE_CLASS##_getSuite() \ 01084 { \ 01085 return &VIEWER_DELEGATE_CLASS##_suite; \ 01086 } 01087 01089 01090 #endif
1.7.3