MeVisLabToolboxReference
MeVisLab/Standard/Sources/Inventor/SoCSO/CSOProcessor/CSOTransformationProcessor/CSOTransformationProcessor.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //----------------------------------------------------------------------------------
00004 
00009 //----------------------------------------------------------------------------------
00010 
00011 #ifndef __CSOTransformationProcessor_H
00012 #define __CSOTransformationProcessor_H
00013 
00014 
00015 #include "SoCSOSystem.h"
00016 #include "CSOProcessor/CSOProcessor.h"
00017 #include "SoView2DCSOEditor/SoView2DCSOEditor.h"
00018 
00019 
00020 ML_START_NAMESPACE
00021 
00023 
00024 struct CSOInventorVoxelBoundingBox 
00025 {
00026   SbVec3f v1, v2;
00027   CSO* cso;
00028   CSOBoundingBox voxelBB;
00029   SbVec3f middle() const { return SbVec3f((v1[0]+v2[0])*.5f, (v1[1]+v2[1])*.5f, (v1[2]+v2[2])*.5f); }
00030 };
00031 
00033 
00034 enum TransformationModes {
00035   TRANSFORMATION_MODE_SCALE     = 0,
00036   TRANSFORMATION_MODE_ROTATE    = 1,
00037   TRANSFORMATION_MODE_TRANSLATE = 2
00038 };
00039 
00041 
00042 enum ScaleDirection {  
00043   SCALE_DIRECTION_NORTH = 0,
00044   SCALE_DIRECTION_SOUTH = 1,
00045   SCALE_DIRECTION_WEST  = 2,
00046   SCALE_DIRECTION_EAST  = 3
00047 };
00048 
00050 
00051 enum TransformationIcon {
00052   ICON_SCALE_ISO = 0,
00053   ICON_SCALE     = 1,  
00054   ICON_ROTATE    = 2,
00055   ICON_TRANSLATE = 3  
00056 };
00057 
00059 
00061 class SOCSO_EXPORT CSOTransformationProcessor : public CSOProcessor
00062 {
00063 
00064 public:
00065 
00067   CSOTransformationProcessor();
00068 
00071   virtual bool process(CSOEvalEventView2DInfos view2DInfos, CSOEvalEventCSOInfos csoInfos);
00072 
00074   virtual void draw(CSODrawView2DInfos view2DInfos, CSODrawCSOInfos csoInfos);
00075   
00077   virtual bool isCurrentlyEditing();
00079   virtual bool isCurrentlyGenerating() { return false; }
00081   virtual void resetInteractionState();
00083   virtual void triggerSetMouseCursor(SoView2D* view2d, bool shouldSetMouseCursor);
00084 
00085   virtual void handleNotification(Field* field);  
00086 
00087 
00088 protected:
00089 
00091   virtual ~CSOTransformationProcessor();
00092 
00093 private:
00094 
00095   // FIELDS
00096   BoolField* _enableScaleFld;
00097   BoolField* _enableRotateFld;
00098   BoolField* _enableTranslateFld;
00099 
00100   FloatField* _handleScaleFld;
00101   FloatField* _influenceMarginFld;
00102 
00103   BoolField* _useAutoLevelingFld;
00104 
00105   BoolField* _useCSOColorFld;
00106 
00107   ColorField* _scaleHandleColorFld;
00108   ColorField* _rotateHandleColorFld;
00109   ColorField* _translateHandleColorFld;
00110 
00111   FloatField* _scaleHandleAlphaFld;
00112   FloatField* _rotateHandleAlphaFld;
00113   FloatField* _translateHandleAlphaFld;
00114 
00115   BoolField* _showHandlesOnlyForSelectedCSOFld;
00116   BoolField* _useUndoRedoManagerFld;
00117   BoolField* _scaleIsotropicFld;
00118 
00119   BoolField*   _useIconFileFld;
00120   StringField* _iconFileFld;
00121   StringField* _internalIconFileFld;
00122 
00123   // METHODS
00124 
00125   CSO* _checkScaleHandles();
00126   CSO* _checkRotateHandles();
00127   CSO* _checkTranslateHandles();
00128 
00129   void _drawScaleHandles(const CSOInventorVoxelBoundingBox& dBB) const;
00130   void _drawRotateHandles(const CSOInventorVoxelBoundingBox& dBB) const;
00131   void _drawTranslateHandles(const CSOInventorVoxelBoundingBox& dBB) const;
00132 
00133   void _scaleCurrentCSO();    
00134   void _rotateCurrentCSO();   
00135   void _translateCurrentCSO();
00136 
00137   void _initializeRotation();
00138   void _finishRotation();
00139 
00140   void _initializeHandleIcons();
00141 
00142   float handleMargin() const { return _handleSize * 2.0f; }
00143   float handleSize() const { return _handleSize * _handleScaleFld->getFloatValue(); }
00144   float influenceMargin() const { return _influenceMarginFld->getFloatValue(); }
00145 
00146   CSOInventorVoxelBoundingBox _convertVoxelBoundingBoxToInventor(CSO* cso, Matrix4 worldToVoxelMatrix) const;
00147   Matrix4 _convertInventorToMLMatrix(const SbMatrix& inventorMatrix) const;
00148 
00149   void _compileActiveCSOs(CSOList* csoList, View2DSliceList* slicelist, CSOBoundingBox slabBB, std::vector<CSOInventorVoxelBoundingBox>& voxelBBList);
00150 
00151   // STATE VARIABLES
00152   bool _isEditing;
00153 
00154   bool _shouldStoreInUndoManager;
00155 
00156   bool _isScaling;
00157   bool _isRotating;
00158   bool _isTranslating;
00159 
00160   bool _mouseOverScaleHandle;
00161   bool _mouseOverRotateHandle;
00162   bool _mouseOverTranslateHandle;
00163 
00164   CSO* _hitCSO;
00165   CSO* _mouseOverCSO;
00166   CSO  _rotationCSO;  
00167   bool _hasRotationSingularity; 
00168 
00169   ScaleDirection _scaleDirection;  
00170   CSOInventorVoxelBoundingBox _rotateBoundingBox;
00171   float _rotationAngle;
00172 
00173   float _deviceX;
00174   float _deviceY;
00175 
00176   float _startPosX;
00177   float _startPosY;
00178 
00179   float _currentPosX;
00180   float _currentPosY;
00181 
00182   float _interactionStartX;
00183   float _interactionStartY;
00184 
00185   // member constant for global icon scaling.
00186   float _handleSize;
00187 
00188   View2DIcons* _handleIcons;
00189 
00190   View2DSliceList* _slicelistDraw;
00191   View2DSliceList* _slicelistEdit;
00192 
00193   std::vector<CSOInventorVoxelBoundingBox> _visibleCSOBoundingBoxes;
00194   std::vector<CSOInventorVoxelBoundingBox> _editableCSOBoundingBoxes;
00195 
00196   ML_MODULE_CLASS_HEADER(CSOTransformationProcessor);
00197 };
00198 
00200 
00201 
00202 ML_END_NAMESPACE
00203 
00204 #endif // __CSOTransformationProcessor_H