00001
00002
00003 #include "Iguana/Inventor/interface/IgSoClipPlane.h"
00004 #include <Inventor/nodes/SoClipPlane.h>
00005 #include <Inventor/nodes/SoShapeHints.h>
00006 #include <Inventor/manips/SoClipPlaneManip.h>
00007 #include <Inventor/sensors/SoFieldSensor.h>
00008 #include <Inventor/SbBox.h>
00009
00010 #ifdef __APPLE__
00011 # include <OpenGL/gl.h>
00012 #else
00013 # include <GL/gl.h>
00014 #endif
00015
00016
00017
00018
00019
00020
00021
00022 SO_NODE_SOURCE (IgSoClipPlane);
00023
00024
00025
00026
00027
00028 void
00029 IgSoClipPlane::initClass (void)
00030 {
00031 SO_NODE_INIT_CLASS (IgSoClipPlane, SoNode, "Node");
00032 }
00033
00034 IgSoClipPlane::IgSoClipPlane (void)
00035 : m_plane (new SoClipPlane),
00036 m_shapeHints (new SoShapeHints),
00037 m_onSensor (0),
00038 m_manipSensor (0),
00039 m_planeSensor (0),
00040 m_mplaneSensor (0)
00041 {
00042 SO_NODE_CONSTRUCTOR (IgSoClipPlane);
00043 SO_NODE_ADD_FIELD (on, (TRUE));
00044 SO_NODE_ADD_FIELD (manip, (FALSE));
00045 SO_NODE_ADD_FIELD (plane, (SbPlane (SbVec3f (1, 0, 0), 0)));
00046
00047 m_shapeHints->setOverride (TRUE);
00048 m_shapeHints->ref();
00049
00050 addChild (m_plane);
00051 addChild (m_shapeHints);
00052
00053 m_onSensor = new SoFieldSensor (&onSensorCB, this);
00054 m_onSensor->attach (&on);
00055
00056 m_manipSensor = new SoFieldSensor (&manipSensorCB, this);
00057 m_manipSensor->attach (&manip);
00058
00059 m_planeSensor = new SoFieldSensor (&planeSensorCB, this);
00060 m_planeSensor->attach (&plane);
00061
00062 m_mplaneSensor = new SoFieldSensor (&mplaneSensorCB, this);
00063
00064
00065 reconnect ();
00066 }
00067
00068 IgSoClipPlane::~IgSoClipPlane (void)
00069 {
00070 removeChild (m_plane);
00071 if (on.getValue ())
00072 removeChild (m_shapeHints);
00073 m_shapeHints->unref();
00074 delete m_onSensor;
00075 delete m_manipSensor;
00076 delete m_planeSensor;
00077 delete m_mplaneSensor;
00078 }
00079
00080 void
00081 IgSoClipPlane::reconnect (void)
00082 {
00083 m_plane->on = on;
00084 syncPlane ();
00085 m_mplaneSensor->attach (&m_plane->plane);
00086 }
00087
00090 void
00091 IgSoClipPlane::onSensorCB (void *me, SoSensor *)
00092 {
00093
00094
00095 IgSoClipPlane *self = static_cast<IgSoClipPlane *> (me);
00096 if (self->on.getValue ())
00097 self->addChild (self->m_shapeHints);
00098 else
00099 self->removeChild (self->m_shapeHints);
00100
00101 self->m_plane->on = self->on;
00102 }
00103
00107 void
00108 IgSoClipPlane::manipSensorCB (void *me, SoSensor *)
00109 {
00110
00111
00112
00113
00114 IgSoClipPlane *self = static_cast<IgSoClipPlane *> (me);
00115
00116 if (self->manip.getValue ())
00117 {
00118
00119 self->replaceChild (0, self->m_plane = new SoClipPlaneManip);
00120 self->reconnect ();
00121 }
00122 else
00123 {
00124
00125 self->replaceChild (0, self->m_plane = new SoClipPlane);
00126 self->reconnect ();
00127 }
00128 }
00129
00132 void
00133 IgSoClipPlane::planeSensorCB (void *me, SoSensor *)
00134 {
00135 IgSoClipPlane *self = static_cast<IgSoClipPlane *> (me);
00136 self->m_mplaneSensor->detach ();
00137 self->syncPlane ();
00138 self->m_mplaneSensor->attach (&self->m_plane->plane);
00139 }
00140
00143 void
00144 IgSoClipPlane::mplaneSensorCB (void *me, SoSensor *)
00145 {
00146 IgSoClipPlane *self = static_cast<IgSoClipPlane *> (me);
00147 self->m_planeSensor->detach ();
00148 self->plane = self->m_plane->plane;
00149 self->m_planeSensor->attach (&self->plane);
00150 }
00151
00152 void
00153 IgSoClipPlane::write (SoWriteAction *action)
00154 { SoNode::write (action); }
00155
00156 void
00157 IgSoClipPlane::syncPlane (void)
00158 {
00159 #ifdef __COIN__
00160 if (dynamic_cast<SoClipPlaneManip *>(m_plane))
00161 {
00162 SbBox3f box (-1,-1,-1, 1, 1, 1);
00163 SbVec3f p (plane.getValue ().getNormal ());
00164 float d = -1 * plane.getValue ().getDistanceFromOrigin();
00165 static_cast<SoClipPlaneManip *>(m_plane)->setValue (box, p, 1.02f);
00166 m_plane->plane.setValue (SbPlane(p, d));
00167 }
00168 else
00169 #endif
00170 m_plane->plane = plane;
00171 }