MeVisLabToolboxReference
|
00001 // **InsertLicense** code 00002 //---------------------------------------------------------------------------------- 00004 00009 //---------------------------------------------------------------------------------- 00010 00011 00012 #ifndef __SoCSOLabelRenderer_H 00013 #define __SoCSOLabelRenderer_H 00014 00015 #include <SoView2DCSOEditor/SoView2DCSOExtensibleEditor/SoCSOEditorExtension.h> 00016 00017 00018 ML_START_NAMESPACE 00019 class CSOLabelRenderer; 00020 ML_END_NAMESPACE 00021 00023 00025 struct CSOLabelBoundingBox 00026 { 00027 CSOLabelBoundingBox() 00028 { 00029 cso = NULL; 00030 } 00031 00032 ml::CSO* cso; 00033 ml::Vector2 v1, v2; 00034 }; 00035 00037 00039 class SOCSO_EXPORT SoCSOLabelRenderer : public SoCSOEditorExtension 00040 { 00041 SO_NODE_HEADER(SoCSOLabelRenderer); 00042 00043 public: 00044 00046 SoCSOLabelRenderer(); 00048 ~SoCSOLabelRenderer(); 00049 00051 virtual void draw(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, const CSODrawSliceInformation& drawSliceInfo, SoView2DCSOExtensibleEditor* editor); 00052 00054 static void initClass(); 00055 00056 void labelStartPressAt(ml::CSO* cso, const SoPointerPosition& pos); 00057 void labelDragMoveTo(ml::CSO* cso, const SoPointerPosition& pos); 00058 SoPointingAction* labelEndPress(ml::CSO* cso, int clickCount); 00059 00060 // just overload the methods below since we do not work 00061 // with the standard actions 00062 virtual void createStartPressAt(const SoPointerPosition& ) {} 00063 virtual void createDragMoveTo(const SoPointerPosition& ) {} 00064 virtual bool createEndPress(int ) { return false; } 00065 00066 virtual void selectAndMoveStartPressAt(const SoPointerPosition& ) {} 00067 virtual void selectAndMoveDragMoveTo(const SoPointerPosition& ) {} 00068 virtual SoPointingAction* selectAndMoveEndPress(int ) {return NULL; } 00069 00070 virtual int cursorShape() const { return SoViewerProxy::DEFAULT_CURSOR; } 00071 00072 virtual bool shouldRenderGeneral(ml::CSO*) const { return true; } 00073 00074 virtual void startDrawing(View2DSliceList* slicelist); 00075 00077 ml::CSO* getLabelCSO(const std::string& currentViewerId, const SoPointerPosition& pos); 00078 00080 void setOuterModule(ml::CSOLabelRenderer* labelRendererModule) { _labelRendererModule = labelRendererModule; } 00081 00083 void updateStringsInCache(); 00084 00086 virtual void resetCache(); 00087 00089 SoSFInt32 labelBorderMarginX; 00091 SoSFInt32 labelBorderMarginY; 00093 SoSFBool drawLabelBorderForSelectedCSO; 00095 SoSFTrigger repaintTrigger; 00096 00097 private: 00098 00100 ml::CSOLabelRenderer* _labelRendererModule; 00101 00103 struct DeviceOffset 00104 { 00105 DeviceOffset() { xOffset = yOffset = 0; } 00106 int xOffset; 00107 int yOffset; 00108 }; 00109 00111 std::map < int, std::string > _csoLabelStrings; 00113 std::map < int, std::string > _csoLabelNames; 00115 std::map < int, DeviceOffset > _csoDeviceOffsets; 00116 00119 void clearInternalStructures(); 00121 void setupInternalStructures(ml::CSOList* csoList); 00122 00124 void getLabelBoundingBox(ml::CSO* cso, const std::string& viewerId, CSOLabelBoundingBox& labelBoundingBox); 00127 void removeLabelBoundingBox(const std::string& viewerId, ml::CSO* cso); 00129 void removeAllLabelBoundingBoxesForCSOId(int id, bool removeAll=false); 00131 void insertLabelBoundingBox(const std::string& viewerId, ml::CSO* cso, int deviceX, int deviceY, int labelWidth, int labelHeight); 00133 bool isHit(const CSOLabelBoundingBox& labelBoundingBox, const SoPointerPosition& pos) const; 00135 std::multimap < std::string, CSOLabelBoundingBox > _viewerLabelBoundingBoxes; 00136 00142 void buildLabelString(ml::CSO* cso); 00144 void drawLabelBorder(const CSODrawView2DInfos& view2DInfos, int deviceX, int deviceY, int labelWidth, int labelHeight, bool useShadow); 00146 void renderLabelName(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, float fontColor[4], const std::string& labelName); 00147 00149 void getRightmostSeedPointPosition(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, float& deviceX, float& deviceY); 00151 void getRightMostPathPointPositionOnCurrentSlice(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, float& deviceX, float& deviceY); 00152 00154 float fontSize() { return 12.f; } 00155 00157 SbVec2f _startDragDevicePosition; 00158 00161 SbVec2f computeRelativeVector(const SoPointerPosition& pos, const SbVec2f& deviceVector); 00162 00164 static void baseEventCB(void* userData, ml::BaseEvent* event); 00167 bool needsUpdate(ml::CSO* cso); 00170 void attachAsListenerTo(ml::CSOList* csoList); 00172 ml::CSOList* _listenToCSOList; 00174 std::set<int> _needsUpdateCSOIds; 00175 }; 00176 00178 00179 #endif // __SoCSOLabelRenderer_H