| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2015 Thomas Anderson <blobfish[at]gmx.com> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
#ifndef GUI_TRANSFORM_DRAGGER_H |
| 24 |
#define GUI_TRANSFORM_DRAGGER_H |
| 25 |
|
| 26 |
#include <Inventor/draggers/SoDragger.h> |
| 27 |
#include <Inventor/fields/SoSFColor.h> |
| 28 |
#include <Inventor/fields/SoSFDouble.h> |
| 29 |
#include <Inventor/fields/SoSFFloat.h> |
| 30 |
#include <Inventor/fields/SoSFInt32.h> |
| 31 |
#include <Inventor/fields/SoSFRotation.h> |
| 32 |
#include <Inventor/fields/SoSFString.h> |
| 33 |
#include <Inventor/sensors/SoIdleSensor.h> |
| 34 |
#include <Inventor/nodes/SoBaseColor.h> |
| 35 |
#include <FCGlobal.h> |
| 36 |
|
| 37 |
#include <string> |
| 38 |
|
| 39 |
class SoCamera; |
| 40 |
|
| 41 |
namespace Gui |
| 42 |
{ |
| 43 |
|
| 44 |
class SoLinearDraggerContainer; |
| 45 |
|
| 46 |
/*! @brief Coordinate System Dragger |
| 47 |
* |
| 48 |
* used to transform objects in 3d space. Set initial: |
| 49 |
* translation, rotation, translationIncrement and |
| 50 |
* rotationIncrement. Use *IncrementCount* multiplied |
| 51 |
* with *Increment for full double precision output. |
| 52 |
* |
| 53 |
* Dragger can be displayed in 2 modes: static scale and auto scale. |
| 54 |
* For static you can set the field scale and you are done. |
| 55 |
* For autoscale you set the field scale & call setupAutoScale with |
| 56 |
* the viewer camera. @see setUpAutoScale @see scale. |
| 57 |
*/ |
| 58 |
class GuiExport SoTransformDragger: public SoDragger |
| 59 |
{ |
| 60 |
SO_KIT_HEADER(SoTransformDragger); |
| 61 |
SO_KIT_CATALOG_ENTRY_HEADER(annotation); |
| 62 |
SO_KIT_CATALOG_ENTRY_HEADER(scaleNode); |
| 63 |
SO_KIT_CATALOG_ENTRY_HEADER(pickStyle); |
| 64 |
// Translator |
| 65 |
SO_KIT_CATALOG_ENTRY_HEADER(xTranslatorDragger); |
| 66 |
SO_KIT_CATALOG_ENTRY_HEADER(yTranslatorDragger); |
| 67 |
SO_KIT_CATALOG_ENTRY_HEADER(zTranslatorDragger); |
| 68 |
// Planar Translator |
| 69 |
SO_KIT_CATALOG_ENTRY_HEADER(xyPlanarTranslatorSwitch); |
| 70 |
SO_KIT_CATALOG_ENTRY_HEADER(yzPlanarTranslatorSwitch); |
| 71 |
SO_KIT_CATALOG_ENTRY_HEADER(zxPlanarTranslatorSwitch); |
| 72 |
SO_KIT_CATALOG_ENTRY_HEADER(xyPlanarTranslatorSeparator); |
| 73 |
SO_KIT_CATALOG_ENTRY_HEADER(yzPlanarTranslatorSeparator); |
| 74 |
SO_KIT_CATALOG_ENTRY_HEADER(zxPlanarTranslatorSeparator); |
| 75 |
SO_KIT_CATALOG_ENTRY_HEADER(xyPlanarTranslatorColor); |
| 76 |
SO_KIT_CATALOG_ENTRY_HEADER(yzPlanarTranslatorColor); |
| 77 |
SO_KIT_CATALOG_ENTRY_HEADER(zxPlanarTranslatorColor); |
| 78 |
SO_KIT_CATALOG_ENTRY_HEADER(xyPlanarTranslatorRotation); |
| 79 |
SO_KIT_CATALOG_ENTRY_HEADER(yzPlanarTranslatorRotation); |
| 80 |
SO_KIT_CATALOG_ENTRY_HEADER(zxPlanarTranslatorRotation); |
| 81 |
SO_KIT_CATALOG_ENTRY_HEADER(xyPlanarTranslatorDragger); |
| 82 |
SO_KIT_CATALOG_ENTRY_HEADER(yzPlanarTranslatorDragger); |
| 83 |
SO_KIT_CATALOG_ENTRY_HEADER(zxPlanarTranslatorDragger); |
| 84 |
// Rotator |
| 85 |
SO_KIT_CATALOG_ENTRY_HEADER(xRotatorDragger); |
| 86 |
SO_KIT_CATALOG_ENTRY_HEADER(yRotatorDragger); |
| 87 |
SO_KIT_CATALOG_ENTRY_HEADER(zRotatorDragger); |
| 88 |
|
| 89 |
public: |
| 90 |
static void initClass(); |
| 91 |
SoTransformDragger(); |
| 92 |
~SoTransformDragger() override; |
| 93 |
|
| 94 |
SoSFVec3f translation; //!< initial translation and reflects single precision movement. |
| 95 |
SoSFDouble translationIncrement; //!< set from outside used for rounding. |
| 96 |
SoSFInt32 translationIncrementCountX; //!< used from outside for translation x steps. |
| 97 |
SoSFInt32 translationIncrementCountY; //!< used from outside for translation y steps. |
| 98 |
SoSFInt32 translationIncrementCountZ; //!< used from outside for translation z steps. |
| 99 |
|
| 100 |
SoSFRotation rotation; //!< initial rotation and reflects single precision movement. |
| 101 |
SoSFDouble rotationIncrement; //!< radians set from outside and used for rounding. |
| 102 |
SoSFInt32 rotationIncrementCountX; //!< used from outside for rotation x steps. |
| 103 |
SoSFInt32 rotationIncrementCountY; //!< used from outside for rotation y steps. |
| 104 |
SoSFInt32 rotationIncrementCountZ; //!< used from outside for rotation z steps. |
| 105 |
|
| 106 |
SoSFString xAxisLabel; //!< label for X axis |
| 107 |
SoSFString yAxisLabel; //!< label for Y axis |
| 108 |
SoSFString zAxisLabel; //!< label for Z axis |
| 109 |
|
| 110 |
void clearIncrementCounts(); //!< used to reset after drag update. |
| 111 |
|
| 112 |
/*! @brief Overall scale of dragger node. |
| 113 |
* |
| 114 |
* When using autoscale mode, this represents normalized device coordinates (0.0 to 1.0). A value |
| 115 |
* of 0.05 is a good place to start. When NOT using autoscale mode, scale represents |
| 116 |
* a traditional scale and a value of 1.0 is a good place to start. |
| 117 |
*/ |
| 118 |
SoSFFloat draggerSize; |
| 119 |
SoSFFloat autoScaleResult; //!< result of autoscale calculation and used by childdraggers. |
| 120 |
//!< Don't use. |
| 121 |
|
| 122 |
SoIdleSensor idleSensor; //!< might be overkill, but want to make sure of performance. |
| 123 |
void setUpAutoScale(SoCamera* cameraIn); //!< used to setup the auto scaling of dragger. |
| 124 |
|
| 125 |
void setAxisColors(unsigned long x, unsigned long y, unsigned long z); //!< set the axis colors. |
| 126 |
|
| 127 |
//! @name Visibility Functions |
| 128 |
//@{ |
| 129 |
void showTranslationX(); //!< show the x translation dragger. |
| 130 |
void showTranslationY(); //!< show the y translation dragger. |
| 131 |
void showTranslationZ(); //!< show the z translation dragger. |
| 132 |
void hideTranslationX(); //!< hide the x translation dragger. |
| 133 |
void hideTranslationY(); //!< hide the y translation dragger. |
| 134 |
void hideTranslationZ(); //!< hide the z translation dragger. |
| 135 |
bool isShownTranslationX(); //!< is x translation dragger shown. |
| 136 |
bool isShownTranslationY(); //!< is y translation dragger shown. |
| 137 |
bool isShownTranslationZ(); //!< is z translation dragger shown. |
| 138 |
|
| 139 |
void showPlanarTranslationXY(); //!< show the xy planar translation dragger. |
| 140 |
void showPlanarTranslationYZ(); //!< show the yz planar translation dragger. |
| 141 |
void showPlanarTranslationZX(); //!< show the zx planar translation dragger. |
| 142 |
void hidePlanarTranslationXY(); //!< hide the xy planar translation dragger. |
| 143 |
void hidePlanarTranslationYZ(); //!< hide the yz planar translation dragger. |
| 144 |
void hidePlanarTranslationZX(); //!< hide the zx planar translation dragger. |
| 145 |
bool isShownPlanarTranslationXY(); //!< is xy planar translation dragger shown. |
| 146 |
bool isShownPlanarTranslationYZ(); //!< is yz planar translation dragger shown. |
| 147 |
bool isShownPlanarTranslationZX(); //!< is zx planar translation dragger shown. |
| 148 |
bool isHiddenPlanarTranslationXY(); //!< is xy planar translation dragger hidden. |
| 149 |
bool isHiddenPlanarTranslationYZ(); //!< is yz planar translation dragger hidden. |
| 150 |
bool isHiddenPlanarTranslationZX(); //!< is zx planar translation dragger hidden. |
| 151 |
|
| 152 |
void showRotationX(); //!< show the x rotation dragger. |
| 153 |
void showRotationY(); //!< show the y rotation dragger. |
| 154 |
void showRotationZ(); //!< show the z rotation dragger. |
| 155 |
void hideRotationX(); //!< hide the x rotation dragger. |
| 156 |
void hideRotationY(); //!< hide the y rotation dragger. |
| 157 |
void hideRotationZ(); //!< hide the z rotation dragger. |
| 158 |
bool isShownRotationX(); //!< is x rotation dragger shown. |
| 159 |
bool isShownRotationY(); //!< is x rotation dragger shown. |
| 160 |
bool isShownRotationZ(); //!< is x rotation dragger shown. |
| 161 |
//@} |
| 162 |
|
| 163 |
void GLRender(SoGLRenderAction* action) override; |
| 164 |
|
| 165 |
protected: |
| 166 |
SbBool setUpConnections(SbBool onoff, SbBool doitalways = FALSE) override; |
| 167 |
void handleEvent(SoHandleEventAction* action) override; |
| 168 |
|
| 169 |
static void translationSensorCB(void* f, SoSensor*); |
| 170 |
static void rotationSensorCB(void* f, SoSensor*); |
| 171 |
static void valueChangedCB(void*, SoDragger* d); |
| 172 |
static void cameraCB(void* data, SoSensor*); |
| 173 |
static void idleCB(void* data, SoSensor*); //!< scheduled from cameraCB to auto scale dragger. |
| 174 |
static void finishDragCB(void* data, SoDragger*); |
| 175 |
|
| 176 |
|
| 177 |
SoFieldSensor translationSensor; |
| 178 |
SoFieldSensor rotationSensor; |
| 179 |
SoFieldSensor cameraSensor; |
| 180 |
|
| 181 |
private: |
| 182 |
// Used to compensate for axis scale in world transformation when doing |
| 183 |
// auto scale. |
| 184 |
SbVec3f axisScale; |
| 185 |
|
| 186 |
bool scaleInited {false}; |
| 187 |
|
| 188 |
void updateAxisScale(); |
| 189 |
|
| 190 |
void setupTranslationDraggers(); |
| 191 |
void setupTranslationDragger( |
| 192 |
const std::string& name, |
| 193 |
SoSFString* label, |
| 194 |
SoSFInt32& incrementCount, |
| 195 |
const SbVec3f& rotDir |
| 196 |
); |
| 197 |
void setupRotationDraggers(); |
| 198 |
void setupRotationDragger(const std::string& name, SoSFInt32& incrementCount); |
| 199 |
|
| 200 |
using inherited = SoDragger; |
| 201 |
}; |
| 202 |
|
| 203 |
} // namespace Gui |
| 204 |
|
| 205 |
#endif /* GUI_TRANSFORM_DRAGGER_H */ |