|
Katana Plug-in APIs 0.1
|
00001 // Copyright (c) 2016 The Foundry Visionmongers Ltd. All Rights Reserved. 00002 00003 #ifndef FNVIEWER_VIEWPORTLAYER_H 00004 #define FNVIEWER_VIEWPORTLAYER_H 00005 00006 #include <FnViewer/plugin/FnEventWrapper.h> 00007 #include <FnViewer/plugin/FnViewport.h> 00008 #include <FnViewer/suite/FnViewportLayerSuite.h> 00009 #include <FnViewer/plugin/FnMathTypes.h> 00010 #include <FnViewer/plugin/FnPickingTypes.h> 00011 00012 #include <FnPluginSystem/FnPluginSystem.h> 00013 #include <FnPluginSystem/FnPlugin.h> 00014 #include <FnAttribute/FnAttribute.h> 00015 00016 #include <map> 00017 #include <string> 00018 #include <iostream> 00019 #include <memory> 00020 00021 00022 namespace Foundry 00023 { 00024 namespace Katana 00025 { 00026 namespace ViewerAPI 00027 { 00028 00087 class ViewportLayerPluginBase 00088 { 00089 public: 00090 // API methods (to be implemented / used by sub-classes) 00091 00092 ViewportLayerPluginBase(); 00093 virtual ~ViewportLayerPluginBase(); 00094 public: /* Methods to be called by the plugin. */ 00095 00101 ViewportWrapperPtr getViewport(); 00102 00120 void hover(bool isHovering, int x, int y); 00121 00172 void pick(unsigned int x, unsigned int y, 00173 unsigned int w, unsigned int h, 00174 bool deepPicking, 00175 PickedAttrsMap& pickedAttrs, 00176 float* singlePointDepth=NULL); 00177 00179 public: 00180 static FnPlugStatus setHost(FnPluginHost* host); 00181 static FnPluginHost* getHost(); 00182 00183 protected: 00184 FnViewportLayerHostSuite_v2* m_hostSuite; 00185 FnViewportLayerHostHandle m_hostHandle; 00186 00187 static FnPluginHost* m_host; 00188 00189 private: 00190 ViewportWrapperPtr m_viewportWrapper; 00191 00193 }; 00194 00196 class ViewportLayer : public ViewportLayerPluginBase 00197 { 00198 public: 00199 00211 ViewportLayer(bool usePickingOnHover=false); 00212 00214 virtual ~ViewportLayer(); 00215 00216 public: /* Virtual functions to be extended by the plugin. */ 00217 00228 virtual void setup() = 0; 00229 00235 virtual void cleanup() = 0; 00236 00249 virtual bool event(const FnEventWrapper& eventData) { return false; } 00250 00261 virtual void draw() = 0; 00262 00269 virtual void resize(unsigned int width, unsigned int height) = 0; 00270 00287 virtual void hover(bool isHovering, int x, int y) {} 00288 00297 virtual void freeze() = 0; 00298 00307 virtual void thaw() = 0; 00308 00317 static void flush() {} 00318 00340 virtual void* getPrivateData(void* inputData) { return 0x0; } 00341 00342 /* Options setting and getting. */ 00343 00355 virtual void setOption(OptionIdGenerator::value_type optionId, 00356 FnAttribute::Attribute attr) {} 00357 00369 virtual FnAttribute::Attribute getOption( 00370 OptionIdGenerator::value_type optionId); 00371 00385 void setOption(const std::string& name, FnAttribute::Attribute attr); 00386 00399 FnAttribute::Attribute getOption(const std::string& name); 00400 00410 bool usesPickingOnHover() { return m_usesPickingOnHover; } 00411 00444 virtual void pickerDraw(unsigned int x, unsigned int y, 00445 unsigned int w, unsigned int h, 00446 const PickedAttrsMap& ignoreAttrs) {} 00447 00492 virtual bool customPick(unsigned int x, unsigned int y, 00493 unsigned int w, unsigned int h, 00494 bool deepPicking, 00495 PickedAttrsMap& pickedAttrs, 00496 float* singlePointDepth=NULL); 00497 00498 00536 FnPickId addPickableObject(FnAttribute::Attribute attr); 00537 00539 public: 00540 static FnViewportLayerPluginSuite_v2 createSuite( 00541 FnViewportLayerPluginHandle (*create)( 00542 FnViewportLayerHostHandle hostHandle)); 00543 static FnViewportLayerPluginHandle newViewportLayerHandle( 00544 ViewportLayer* viewportLayer); 00545 00546 static unsigned int _apiVersion; 00547 static const char* _apiName; 00548 00549 void setHostHandle(FnViewportLayerHostHandle m_hostHandle); 00550 FnViewportLayerHostHandle getHostHandle(); 00551 00552 private: 00553 bool m_usesPickingOnHover; 00554 00556 }; 00557 00559 class ViewportLayerWrapper : public ViewportLayerPluginBase 00560 { 00561 public: 00562 ViewportLayerWrapper( 00563 FnPluginHost* host, 00564 FnViewportLayerHostHandle hostHandle, 00565 FnViewportLayerPluginHandle pluginHandle, 00566 FnViewportLayerPluginSuite_v2* pluginSuite); 00567 00568 ~ViewportLayerWrapper(); 00569 00587 template<class T> T* getPluginInstance() 00588 { 00589 return dynamic_cast<T*>(getPluginPointer()); 00590 } 00591 00597 void draw(); 00598 00610 bool event(FnEventWrapper eventData); 00611 00613 void setOption(OptionIdGenerator::value_type optionId, 00614 FnAttribute::Attribute attr); 00616 FnAttribute::Attribute getOption(OptionIdGenerator::value_type optionId); 00618 void setOption(const std::string& name, FnAttribute::Attribute attr); 00620 FnAttribute::Attribute getOption(const std::string& name); 00621 00623 private: 00624 ViewportLayer* getPluginPointer(); 00625 00627 FnViewportLayerPluginSuite_v2* m_pluginSuite; 00628 FnViewportLayerPluginHandle m_pluginHandle; 00629 00631 }; 00632 00633 typedef std::shared_ptr<ViewportLayerWrapper> ViewportLayerWrapperPtr; 00634 00637 } // ViewerAPI 00638 } // Katana 00639 } // Foundry 00640 00641 00643 00644 // Plugin-side structure to be pointed by the plugin handles. 00645 struct FnViewportLayerPluginStruct 00646 { 00647 public: 00648 FnViewportLayerPluginStruct( 00649 Foundry::Katana::ViewerAPI::ViewportLayer* viewportLayer) 00650 : m_viewportLayer(viewportLayer) 00651 {} 00652 00653 ~FnViewportLayerPluginStruct() 00654 {}; 00655 00656 Foundry::Katana::ViewerAPI::ViewportLayer* getViewportLayer() 00657 { 00658 return m_viewportLayer.get(); 00659 } 00660 00661 FnAttribute::GroupAttribute getAttributes(const std::string& locationPath); 00662 00663 private: 00664 std::shared_ptr<Foundry::Katana::ViewerAPI::ViewportLayer> m_viewportLayer; 00665 }; 00666 00667 00668 // Plugin Registering Macro. 00669 #define DEFINE_VIEWPORT_LAYER_PLUGIN(VIEWPORT_LAYER_CLASS) \ 00670 \ 00671 FnPlugin VIEWPORT_LAYER_CLASS##_plugin; \ 00672 \ 00673 FnViewportLayerPluginHandle VIEWPORT_LAYER_CLASS##_create( \ 00674 FnViewportLayerHostHandle hostHandle) \ 00675 { \ 00676 Foundry::Katana::ViewerAPI::ViewportLayer* viewportLayer = \ 00677 VIEWPORT_LAYER_CLASS::create(); \ 00678 \ 00679 viewportLayer->setHostHandle(hostHandle); \ 00680 return Foundry::Katana::ViewerAPI::ViewportLayer::newViewportLayerHandle(viewportLayer); \ 00681 } \ 00682 \ 00683 FnViewportLayerPluginSuite_v2 VIEWPORT_LAYER_CLASS##_suite = \ 00684 Foundry::Katana::ViewerAPI::ViewportLayer::createSuite( \ 00685 VIEWPORT_LAYER_CLASS##_create); \ 00686 \ 00687 const void* VIEWPORT_LAYER_CLASS##_getSuite() \ 00688 { \ 00689 return &VIEWPORT_LAYER_CLASS##_suite; \ 00690 } 00691 00693 00694 #endif
1.7.3