Katana Plug-in APIs 0.1

FnManipulator.h

00001 // Copyright (c) 2016 The Foundry Visionmongers Ltd. All Rights Reserved.
00002 
00003 #ifndef FNMANIPULATOR_H_
00004 #define FNMANIPULATOR_H_
00005 
00006 #include <FnViewer/suite/FnManipulatorSuite.h>
00007 #include <FnViewer/plugin/FnViewport.h>
00008 #include <FnViewer/plugin/FnEventWrapper.h>
00009 #include <FnViewer/plugin/FnMathTypes.h>
00010 
00011 #include <FnPluginSystem/FnPluginSystem.h>
00012 #include <FnPluginSystem/FnPlugin.h>
00013 #include <FnAttribute/FnAttribute.h>
00014 
00015 #include <vector>
00016 #include <stdint.h>
00017 #include <string>
00018 #include <memory>
00019 
00020 
00021 namespace Foundry
00022 {
00023 namespace Katana
00024 {
00025 namespace ViewerAPI
00026 {
00027 
00028 // Forward declarations
00029 class ViewportWrapper;
00030 class ManipulatorHandleWrapper;
00031 typedef std::shared_ptr<ViewportWrapper> ViewportWrapperPtr;
00032 typedef std::shared_ptr<ManipulatorHandleWrapper> ManipulatorHandleWrapperPtr;
00033 
00087 class ManipulatorPluginBase
00088 {
00089 public:
00090 
00092     ManipulatorPluginBase();
00093 
00095     virtual ~ManipulatorPluginBase();
00096 
00097 public: /* Constants */
00098 
00099     // Some standard tag keys
00101     static const char kTagName[];
00103     static const char kTagShortcut[];
00105     static const char kTagGroup[];
00108     static const char kTagTechnology[];
00112     static const char kTagAlwaysAvailable[];
00115     static const char kTagExclusiveInGroup[];
00118     static const char kTagPriorityInGroup[];
00119 
00120     // Some standard group tag values
00121     static const char kTagGroup_TRANSFORM[];  // Translate, Rotate, etc.
00122     static const char kTagGroup_LIGHT[];  // Light related manipulators.
00123 
00124 
00125 public: /* Methods to be called by the plugin. */
00126 
00132     std::string getPluginName();
00133 
00145     ViewportWrapperPtr getViewport();
00146 
00158     void getLocationPaths(std::vector<std::string>& paths);
00159 
00165     Matrix44d getXform();
00166 
00172     void setXform(const Matrix44d& xformMatrix);
00173 
00183     Matrix44d calculateAveragePositionXform();
00184 
00224     bool setValue(const std::string& locationPath, const std::string& attrName,
00225                   FnAttribute::Attribute valueAttr, bool isFinal);
00226 
00239     void openManipulationGroup(const std::string& locationPath);
00240 
00248     void closeManipulationGroup(const std::string& locationPath);
00249 
00259     FnAttribute::Attribute getValue(const std::string& locationPath,
00260                                     const std::string& attrName);
00261 
00273     ManipulatorHandleWrapperPtr addManipulatorHandle(
00274         const std::string& pluginName, const std::string& name);
00275 
00287     ManipulatorHandleWrapperPtr getManipulatorHandle(const std::string& name);
00288 
00300     ManipulatorHandleWrapperPtr getManipulatorHandle(unsigned int index);
00301 
00307     void removeManipulatorHandle(const std::string& name);
00308 
00314     void removeManipulatorHandle(unsigned int index);
00315 
00321     unsigned int getNumberOfManipulatorHandles() const;
00322 
00332     std::string getManipulatorHandleName(unsigned int index);
00333 
00341     static FnAttribute::GroupAttribute GetRegisteredManipulatorsInfo();
00342 
00352     bool isInteractive() const;
00353 
00355 public:
00356     static FnPlugStatus setHost(FnPluginHost* host);
00357     static FnPluginHost* getHost();
00358 
00359 protected:
00360     static FnPluginHost* m_host;
00361 
00362     FnManipulatorHostSuite_v2* m_hostSuite;
00363     FnManipulatorHostHandle m_hostHandle;
00364 
00365     static const FnManipulatorHostSuite_v2* _manipulatorSuite;
00366 
00368 };
00369 
00373 class Manipulator : public ManipulatorPluginBase
00374 {
00375 public:
00377     Manipulator();
00378 
00380     virtual ~Manipulator();
00381 
00382 public: /* Virtual functions to be extended by the plugin. */
00383 
00390     static bool matches(const FnAttribute::GroupAttribute& locationAttrs);
00391 
00408     static FnAttribute::GroupAttribute getTags();
00409 
00416     virtual void setup() = 0;
00417 
00428     virtual bool event(const FnEventWrapper& eventData);
00429 
00437     virtual void draw();
00438 
00447     virtual void pickerDraw(int64_t pickerId);
00448 
00470     virtual void* getPrivateData(void* inputData) { return 0x0; }
00471 
00472     /* Options setting and getting. */
00473 
00485     virtual void setOption(OptionIdGenerator::value_type optionId,
00486                            FnAttribute::Attribute attr) {}
00487 
00499     virtual FnAttribute::Attribute getOption(
00500         OptionIdGenerator::value_type optionId);
00501 
00515     void setOption(const std::string& name, FnAttribute::Attribute attr);
00516 
00529     FnAttribute::Attribute getOption(const std::string& name);
00530 
00532 public:
00533     static FnManipulatorPluginSuite_v1 createSuite(
00534         FnManipulatorPluginHandle (*create)(FnManipulatorHostHandle hostHandle),
00535         int (*matches)(FnAttributeHandle locationAttributes),
00536         FnAttributeHandle (*getTags)());
00537 
00538     static FnManipulatorPluginHandle newManipulatorPluginHandle(
00539         Manipulator* viewport);
00540 
00541     static unsigned int _apiVersion;
00542     static const char*  _apiName;
00543 
00544     void setHostHandle(FnManipulatorHostHandle m_hostHandle);
00545 
00547 };
00548 
00552 class ManipulatorWrapper : public ManipulatorPluginBase
00553 {
00554 public:
00555     ManipulatorWrapper(FnPluginHost* host, FnManipulatorHostHandle hostHandle,
00556                        FnManipulatorPluginHandle pluginHandle,
00557                        FnManipulatorPluginSuite_v1* pluginSuite);
00558 
00559     ~ManipulatorWrapper();
00560 
00578     template<class T> T* getPluginInstance()
00579     {
00580         return dynamic_cast<T*>(getPluginPointer());
00581     }
00582 
00583     bool matches(const FnAttribute::GroupAttribute& locationAttrs);
00584 
00585     FnAttribute::GroupAttribute getTags();
00586 
00593     void draw();
00594 
00602     bool event(FnEventWrapper eventData);
00603 
00612     void pickerDraw(int64_t pickerId);
00613 
00615     void setOption(OptionIdGenerator::value_type optionId,
00616         FnAttribute::Attribute attr);
00618     FnAttribute::Attribute getOption(OptionIdGenerator::value_type optionId);
00620     void setOption(const std::string& name, FnAttribute::Attribute attr);
00622     FnAttribute::Attribute getOption(const std::string& name);
00623 
00625 private:
00626     Manipulator* getPluginPointer();
00627 
00629     FnManipulatorPluginSuite_v1* m_pluginSuite;
00630     FnManipulatorPluginHandle m_pluginHandle;
00631 
00633 };
00634 
00635 typedef std::shared_ptr<ManipulatorWrapper>
00636     ManipulatorWrapperPtr;
00637 
00640 } // ViewerAPI
00641 } // Katana
00642 } // Foundry
00643 
00645 
00646 // Plugin-side structure to be pointed by the plugin handles.
00647 struct FnManipulatorPluginStruct
00648 {
00649 public:
00650     FnManipulatorPluginStruct(
00651         Foundry::Katana::ViewerAPI::Manipulator* manipulator)
00652     : m_manipulator(manipulator)
00653     {}
00654 
00655     ~FnManipulatorPluginStruct()
00656     {};
00657 
00658     Foundry::Katana::ViewerAPI::Manipulator* getManipulator()
00659     {
00660         return m_manipulator.get();
00661     }
00662 
00663 private:
00664     std::shared_ptr<
00665         Foundry::Katana::ViewerAPI::Manipulator> m_manipulator;
00666 };
00667 
00668 
00669 // Plugin Registering Macro.
00670 #define DEFINE_MANIPULATOR_PLUGIN(MANIPULATOR_CLASS)                          \
00671                                                                               \
00672 FnPlugin MANIPULATOR_CLASS##_plugin;                                          \
00673                                                                               \
00674 FnManipulatorPluginHandle MANIPULATOR_CLASS##_create(                         \
00675     FnManipulatorHostHandle hostHandle)                                       \
00676 {                                                                             \
00677     Foundry::Katana::ViewerAPI::Manipulator* manipulator =                    \
00678         MANIPULATOR_CLASS::create();                                          \
00679                                                                               \
00680     manipulator->setHostHandle(hostHandle);                                   \
00681     return Foundry::Katana::ViewerAPI::Manipulator::newManipulatorPluginHandle( \
00682         manipulator);                                                         \
00683 }                                                                             \
00684                                                                               \
00685 int MANIPULATOR_CLASS##_matches(FnAttributeHandle locationAttributesHandle)   \
00686 {                                                                             \
00687     return MANIPULATOR_CLASS::matches(                                        \
00688         FnAttribute::Attribute::CreateAndRetain(locationAttributesHandle));   \
00689 }                                                                             \
00690                                                                               \
00691 FnAttributeHandle MANIPULATOR_CLASS##_getTags()                               \
00692 {                                                                             \
00693     return MANIPULATOR_CLASS::getTags().getRetainedHandle();                  \
00694 }                                                                             \
00695                                                                               \
00696 FnManipulatorPluginSuite_v1 MANIPULATOR_CLASS##_suite =                       \
00697         Foundry::Katana::ViewerAPI::Manipulator::createSuite(                 \
00698                 MANIPULATOR_CLASS##_create,                                   \
00699                 MANIPULATOR_CLASS##_matches,                                  \
00700                 MANIPULATOR_CLASS##_getTags);                                 \
00701                                                                               \
00702 const void* MANIPULATOR_CLASS##_getSuite()                                    \
00703 {                                                                             \
00704     return &MANIPULATOR_CLASS##_suite;                                        \
00705 }
00706 
00708 #endif /* FNMANIPULATOR_H_ */
 All Classes Functions Variables Typedefs Enumerations Enumerator