|
Katana Plug-in APIs 0.1
|
00001 // Copyright (c) 2016 The Foundry Visionmongers Ltd. All Rights Reserved. 00002 00003 #ifndef FNVIEWER_VIEWPORT_H 00004 #define FNVIEWER_VIEWPORT_H 00005 00006 #include <FnViewer/suite/FnViewportSuite.h> 00007 #include <FnViewer/plugin/FnEventWrapper.h> 00008 #include <FnViewer/plugin/FnViewerDelegate.h> 00009 #include <FnViewer/plugin/FnViewportCamera.h> 00010 #include <FnViewer/plugin/FnManipulator.h> 00011 #include <FnViewer/plugin/FnOptionIdGenerator.h> 00012 #include <FnViewer/plugin/FnMathTypes.h> 00013 #include <FnViewer/plugin/FnPickingTypes.h> 00014 00015 #include <FnPluginSystem/FnPluginSystem.h> 00016 #include <FnPluginSystem/FnPlugin.h> 00017 #include <FnAttribute/FnAttribute.h> 00018 00019 #include <string> 00020 #include <map> 00021 #include <vector> 00022 #include <memory> 00023 00024 namespace Foundry 00025 { 00026 namespace Katana 00027 { 00028 namespace ViewerAPI 00029 { 00030 00031 // Forward declarations 00032 class ViewportLayerWrapper; 00033 class ManipulatorWrapper; 00034 class ViewportCameraWrapper; 00035 typedef std::shared_ptr<ViewportLayerWrapper> ViewportLayerWrapperPtr; 00036 typedef std::shared_ptr<ManipulatorWrapper> ManipulatorWrapperPtr; 00037 typedef std::shared_ptr<ViewportCameraWrapper> ViewportCameraWrapperPtr; 00038 00128 class ViewportPluginBase 00129 { 00130 public: 00131 00133 ViewportPluginBase(); 00134 00136 virtual ~ViewportPluginBase(); 00137 00138 public: /* Methods to be called by the plugin. */ 00139 00147 std::string getName(); 00148 00154 ViewerDelegateWrapperPtr getViewerDelegate(); 00155 00162 unsigned int getWidth(); 00163 00170 unsigned int getHeight(); 00171 00177 ViewportCameraWrapperPtr getActiveCamera(); 00178 00191 ViewportCameraWrapperPtr addCamera(const std::string& pluginName, 00192 const std::string& name); 00193 00204 ViewportCameraWrapperPtr getCamera(const std::string& name) const; 00205 00218 ViewportCameraWrapperPtr getCamera(unsigned int index) const; 00219 00227 void removeCamera(const std::string& name); 00228 00238 void removeCamera(unsigned int index); 00239 00247 unsigned int getNumberOfCameras() const; 00248 00258 std::string getCameraName(unsigned int index); 00259 00260 00269 std::string getCameraName(ViewportCameraWrapperPtr camera); 00270 00279 int getCameraIndex(const std::string& name); 00280 00282 void removeCamera(ViewportCameraWrapperPtr camera); 00283 00285 void setActiveCamera(ViewportCameraWrapperPtr camera); 00286 00298 void setViewFrozen(bool isViewFrozen); 00299 00307 bool isViewFrozen() const; 00308 00314 const double* getViewMatrix(); 00315 00321 Matrix44d getViewMatrix44d(); 00322 00328 const double* getProjectionMatrix(); 00329 00335 Matrix44d getProjectionMatrix44d(); 00336 00344 bool isDirty(); 00345 00354 void setDirty(bool dirty); 00355 00356 /* ViewportLayer management Methods */ 00357 00369 ViewportLayerWrapperPtr addLayer(const std::string& pluginName, 00370 const std::string& name); 00371 00386 ViewportLayerWrapperPtr insertLayer(const std::string& pluginName, 00387 const std::string& name, 00388 unsigned int index); 00389 00400 ViewportLayerWrapperPtr getLayer(const std::string& name) const; 00401 00414 ViewportLayerWrapperPtr getLayer(unsigned int index) const; 00415 00423 void removeLayer(const std::string& name); 00424 00434 void removeLayer(unsigned int index); 00435 00443 unsigned int getNumberOfLayers() const; 00444 00454 std::string getLayerName(unsigned int index); 00455 00464 int getLayerIndex(const std::string& name); 00465 00466 00467 /* Active Manipulators Methods */ 00468 00485 void activateManipulator(const std::string& pluginName, 00486 const std::vector<std::string>& locationPaths); 00487 00498 void deactivateManipulator(const std::string& pluginName); 00499 00508 void deactivateAllManipulators(); 00509 00518 unsigned int getNumberOfActiveManipulators(); 00519 00536 ManipulatorWrapperPtr getActiveManipulator(unsigned int index); 00537 00546 ManipulatorWrapperPtr getActiveManipulator(const std::string& pluginName); 00547 00553 bool makeGLContextCurrent(); 00554 00560 bool doneGLContextCurrent(); 00561 00569 bool isGLContextCurrent(); 00570 00584 unsigned int getDefaultFramebufferObject(); 00585 00594 void enableCap(uint32_t cap); 00595 00604 void disableCap(uint32_t cap); 00605 00657 void pick(unsigned int x, unsigned int y, 00658 unsigned int w, unsigned int h, 00659 bool deepPicking, 00660 PickedAttrsMap& pickedAttrs, 00661 float* singlePointDepth=NULL); 00662 00664 void setPanAndZoomActive(bool active); 00665 00667 bool isPanAndZoomActive(); 00668 00670 float getHorizontalOffset(); 00671 00673 float getVerticalOffset(); 00674 00676 float getZoom(); 00677 00679 public: 00680 static FnPlugStatus setHost(FnPluginHost* host); 00681 static FnPluginHost* getHost(); 00682 00683 protected: 00684 static FnPluginHost* m_host; 00685 00686 FnViewportHostSuite_v3* m_hostSuite; 00687 FnViewportHostHandle m_hostHandle; 00688 00689 private: 00690 ViewerDelegateWrapperPtr m_viewerDelegateWrapper; 00691 00693 }; 00694 00695 00697 class Viewport : public ViewportPluginBase 00698 { 00699 public: 00700 // API methods (to be implemented / used by sub-classes) 00701 00703 Viewport(); 00704 00706 virtual ~Viewport(); 00707 00708 public: /* Virtual functions to be extended by the plugin. */ 00709 00720 virtual void setup() = 0; 00721 00727 virtual void cleanup() = 0; 00728 00741 virtual bool event(const FnEventWrapper& eventData); 00742 00753 virtual void draw(); 00754 00766 virtual void resize(unsigned int width, unsigned int height); 00767 00788 virtual void hover(bool isHovering, int x, int y); 00789 00803 virtual void setOption(OptionIdGenerator::value_type optionId, 00804 FnAttribute::Attribute attr) {} 00805 00819 virtual FnAttribute::Attribute getOption( 00820 OptionIdGenerator::value_type optionId); 00821 00835 void setOption(const std::string& name, FnAttribute::Attribute attr); 00836 00849 FnAttribute::Attribute getOption(const std::string& name); 00850 00851 /* General Methods */ 00852 00862 virtual void freeze() = 0; 00863 00872 virtual void thaw() = 0; 00873 00880 static void flush() {} 00881 00903 virtual void* getPrivateData(void* inputData) { return 0x0; } 00904 00937 virtual void pickerDraw(unsigned int x, unsigned int y, 00938 unsigned int w, unsigned int h, 00939 const PickedAttrsMap& ignoreAttrs) {} 00940 00985 virtual bool customPick(unsigned int x, unsigned int y, 00986 unsigned int w, unsigned int h, 00987 bool deepPicking, 00988 PickedAttrsMap& pickedAttrs, 00989 float* singlePointDepth=NULL); 00990 01028 FnPickId addPickableObject(FnAttribute::Attribute attr); 01029 01031 public: 01032 static FnViewportPluginSuite_v2 createSuite( 01033 FnViewportPluginHandle (*create)(FnViewportHostHandle hostHandle)); 01034 01035 static FnViewportPluginHandle newViewportHandle(Viewport* viewport); 01036 01037 static unsigned int _apiVersion; 01038 static const char* _apiName; 01039 01040 void setHostHandle(FnViewportHostHandle m_hostHandle); 01041 01043 }; 01044 01045 01047 class ViewportWrapper : public ViewportPluginBase 01048 { 01049 public: 01050 ViewportWrapper(FnPluginHost* host, FnViewportHostHandle hostHandle, 01051 FnViewportPluginHandle pluginHandle, 01052 FnViewportPluginSuite_v2* pluginSuite); 01053 01054 ~ViewportWrapper(); 01055 01073 template<class T> T* getPluginInstance() 01074 { 01075 return dynamic_cast<T*>(getPluginPointer()); 01076 } 01077 01083 bool event(const FnEventWrapper& eventData); 01084 01086 void setOption(OptionIdGenerator::value_type optionId, FnAttribute::Attribute attr); 01087 01089 FnAttribute::Attribute getOption(OptionIdGenerator::value_type optionId); 01090 01092 void setOption(const std::string& name, FnAttribute::Attribute attr); 01093 01095 FnAttribute::Attribute getOption(const std::string& name); 01096 01098 private: 01099 Viewport* getPluginPointer(); 01100 01102 FnViewportPluginSuite_v2* m_pluginSuite; 01103 FnViewportPluginHandle m_pluginHandle; 01104 01106 }; 01107 01109 typedef std::shared_ptr<ViewportWrapper> ViewportWrapperPtr; 01110 01113 } // namespace ViewerAPI 01114 } // namespace Katana 01115 } // namespace Foundry 01116 01117 01119 01120 // Plugin-side structure to be pointed by the plugin handles. 01121 struct FnViewportPluginStruct 01122 { 01123 public: 01124 FnViewportPluginStruct( 01125 Foundry::Katana::ViewerAPI::Viewport* viewport) 01126 : m_viewport(viewport) 01127 {} 01128 01129 ~FnViewportPluginStruct() 01130 {}; 01131 01132 Foundry::Katana::ViewerAPI::Viewport* getViewport() 01133 { 01134 return m_viewport.get(); 01135 } 01136 01137 private: 01138 std::shared_ptr<Foundry::Katana::ViewerAPI::Viewport> m_viewport; 01139 }; 01140 01141 // Plugin Registering Macro. 01142 #define DEFINE_VIEWPORT_PLUGIN(VIEWPORT_CLASS) \ 01143 \ 01144 FnPlugin VIEWPORT_CLASS##_plugin; \ 01145 FnViewportPluginHandle VIEWPORT_CLASS##_create( \ 01146 FnViewportHostHandle hostHandle) \ 01147 { \ 01148 Foundry::Katana::ViewerAPI::Viewport* viewport = \ 01149 VIEWPORT_CLASS::create(); \ 01150 \ 01151 viewport->setHostHandle(hostHandle); \ 01152 return Foundry::Katana::ViewerAPI::Viewport::newViewportHandle( \ 01153 viewport); \ 01154 } \ 01155 \ 01156 FnViewportPluginSuite_v2 VIEWPORT_CLASS##_suite = \ 01157 Foundry::Katana::ViewerAPI::Viewport::createSuite( \ 01158 VIEWPORT_CLASS##_create); \ 01159 \ 01160 const void* VIEWPORT_CLASS##_getSuite() \ 01161 { \ 01162 return &VIEWPORT_CLASS##_suite; \ 01163 } 01164 01166 01167 #endif
1.7.3