Пример #1
0
////////////////////////////////////////////////////////////////////////
//
// Description:
//    Set up the highlighting, projector, and the initial hit on
//    the dragger
//
// Use: private
//
void
SoTranslate2Dragger::dragStart()
//
////////////////////////////////////////////////////////////////////////
{
    // Set the switches to 1...
    setSwitchValue( translatorSwitch.getValue(), 1 );
    setSwitchValue( feedbackSwitch.getValue(), 1 );

    // Set the axis feedback switch to display both.
    // They're displayed while dragging
    setSwitchValue( axisFeedbackSwitch.getValue(), SO_SWITCH_ALL );

    // There is no constrained direction...
    translateDir = -1;

    // Make a note of which modifier keys are down.
    shftDown = getEvent()->wasShiftDown();

    // This is the point we'll use if a metaKey callback makes us re-start.
	worldRestartPt = getWorldStartingPoint();

    // Establish the projector plane in working space.
    // Working space is space at end of motion matrix.
    // Plane normal is defined relative to the translatorPart, so 
    // use z-axis to construct the projector plane.
	SbVec3f startLocalHitPt = getLocalStartingPoint();
	planeProj->setPlane( SbPlane(SbVec3f(0,0,1), startLocalHitPt ) );
}
Пример #2
0
////////////////////////////////////////////////////////////////////////
//
// Description:
//    Rotate the rotateDiscDragger based on mouse motion.
//
// Use: private
//
void
SoRotateDiscDragger::dragFinish()
//
////////////////////////////////////////////////////////////////////////
{
    // Set the switches to 0...
    setSwitchValue( rotatorSwitch.getValue(), 0 );
    setSwitchValue( feedbackSwitch.getValue(), 0 );
}    
Пример #3
0
////////////////////////////////////////////////////////////////////////
//
// Description:
//
// Use: private
//
void
SoTranslate2Dragger::dragFinish()
//
////////////////////////////////////////////////////////////////////////
{
    // Set the switches to 0...
    setSwitchValue( translatorSwitch.getValue(), 0 );
    setSwitchValue( feedbackSwitch.getValue(), 0 );

    // Set the axis feedback switch to SO_SWITCH_NONE
    // They're only displayed while dragging
    setSwitchValue( axisFeedbackSwitch.getValue(), SO_SWITCH_NONE );
}
Пример #4
0
void TranslateRadialDragger::
dragFinish()
{
  // Display inactive versions of parts...
  SoSwitch *sw;
  sw = SO_GET_ANY_PART(this, "translatorSwitch", SoSwitch);
  setSwitchValue(sw, 0);
  sw = SO_GET_ANY_PART(this, "feedbackSwitch", SoSwitch);
  setSwitchValue(sw, 0);

  // Get rid of the "feedbackRotate" part.  We don't need
  // it since we aren't showing the feedback any more.
  setAnyPart("feedbackRotate", NULL);
}
Пример #5
0
////////////////////////////////////////////////////////////////////////
//
// Description:
//    Rotate the rotateDiscDragger based on mouse motion.
//
// Use: private
//
void
SoRotateDiscDragger::dragStart()
//
////////////////////////////////////////////////////////////////////////
{
    // Set the switches to 1...
    setSwitchValue( rotatorSwitch.getValue(), 1 );
    setSwitchValue( feedbackSwitch.getValue(), 1 );

    // Establish the projector plane in working space.
    // Working space is space at end of motion matrix.
    // The plane used should be the x-y plane.
	SbVec3f startLocalHitPt = getLocalStartingPoint();
	SbLine  workSpaceAxis( SbVec3f(0,0,0), SbVec3f(0,0,1) );
	SbVec3f planeOrigin = workSpaceAxis.getClosestPoint(startLocalHitPt);
	planeProj->setPlane(SbPlane(SbVec3f(0,0,1), planeOrigin));
}
Пример #6
0
void TranslateRadialDragger::
dragStart()
{
  // Display the 'active' parts...
  SoSwitch *sw;
  sw = SO_GET_ANY_PART(this, "translatorSwitch", SoSwitch);
  setSwitchValue(sw, 1);
  sw = SO_GET_ANY_PART(this, "feedbackSwitch", SoSwitch);
  setSwitchValue(sw, 1);

  // Establish the projector line.
  // The direction of translation goes from the center of the
  // dragger toward the point that was hit, in local space.
  // For the center, use (0,0,0).
  SbVec3f startLocalHitPt = getLocalStartingPoint();
  lineProj->setLine(SbLine(SbVec3f(0, 0, 0), startLocalHitPt));

  // orient the feedback geometry.
  orientFeedbackGeometry(startLocalHitPt);
}
Пример #7
0
////////////////////////////////////////////////////////////////////////
//
// Description:
//    Stretch the dragger according to the motion along the plane
//    projector
//
// Use: private
//
void
SoTranslate2Dragger::drag()
//
////////////////////////////////////////////////////////////////////////
{
    // Set up the projector space and view.
    // Working space is space at end of motion matrix.
	planeProj->setViewVolume( getViewVolume() );    
	planeProj->setWorkingSpace( getLocalToWorldMatrix() );

    // Get newHitPt and startHitPt in workspace.
	SbVec3f newHitPt = planeProj->project( getNormalizedLocaterPosition()); 
	SbVec3f startHitPt = getLocalStartingPoint();

    // Convert newHitPt to world space and save this as our new worldRestartPt
	getLocalToWorldMatrix().multVecMatrix( newHitPt, worldRestartPt );

    // Figure out the translation relative to start position.
        SbVec3f motion = newHitPt - startHitPt;

    // Maybe we need to constrain the motion...
    if ( !shftDown )
	translateDir = -1;
    else {
	// The shift key is pressed. This means 1-D translation.
	if ( translateDir == -1 ) {
	    // The 1-D direction is not defined. Calculate it based on which
	    // direction got the maximum locater motion.
            if ( isAdequateConstraintMotion() ) {
		if ( fabs( motion[0]) > fabs( motion[1]))
		    translateDir = 0;
		else 
		    translateDir = 1;

		// Set the axis feedback switch to the given direction.
		setSwitchValue( axisFeedbackSwitch.getValue(), translateDir );
	    }
	    else {
		// Not ready to pick a direction yet. Don't move.
		return;
	    }
	}
	// get the projection of 'motion' onto the preferred axis.
	SbVec3f constrainedMotion(0,0,0);
	constrainedMotion[translateDir] = motion[translateDir];
	motion = constrainedMotion;
    }

    // Append this to the startMotionMatrix, which we saved at the beginning
    // of the drag, to find the current motion matrix.
	setMotionMatrix( appendTranslation( getStartMotionMatrix(), motion ) );
}
Пример #8
0
void ArduinoEngine::pi_returnSwitchValue(int vl)
{
    std::cout<<__FUNCTION__<<":"<<vl<<std::endl;
    if (vl != _switchValue) {
        setSwitchValue(vl);
        //write activity log
        if (_switchValue == LOW) {
            _db.writeLog("Door opened!");
        } else {
            _db.writeLog("Door closed!");
        }

        //decide to push
        if (_getOptionsValue<bool>(HSS_DT_DOOR_ENABLE_SETTING)) {
            //push
            if (_switchValue == LOW) {
                pushMessage("Door opened!");
            } else {
                pushMessage("Door closed!");
            }
        }
    }
}
Пример #9
0
////////////////////////////////////////////////////////////////////////
//
// Description:
//    Constructor
//
SoTranslate2Dragger::SoTranslate2Dragger()
//
////////////////////////////////////////////////////////////////////////
{
    SO_KIT_CONSTRUCTOR(SoTranslate2Dragger);

    isBuiltIn = TRUE;

    // Put this stuff under the geomSeparator so it will draw more
    // efficiently.
    SO_KIT_ADD_CATALOG_ENTRY(translatorSwitch, SoSwitch, TRUE,
				geomSeparator,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(translator, SoSeparator, TRUE,
				translatorSwitch,\x0,TRUE);
    SO_KIT_ADD_CATALOG_ENTRY(translatorActive, SoSeparator, TRUE,
				translatorSwitch,\x0,TRUE);
    SO_KIT_ADD_CATALOG_ENTRY(feedbackSwitch, SoSwitch, TRUE,
				geomSeparator,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(feedback, SoSeparator, TRUE,
				feedbackSwitch,\x0,TRUE);
    SO_KIT_ADD_CATALOG_ENTRY(feedbackActive, SoSeparator, TRUE,
				feedbackSwitch,\x0,TRUE);
    SO_KIT_ADD_CATALOG_ENTRY(axisFeedbackSwitch, SoSwitch, TRUE,
				geomSeparator,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(xAxisFeedback, SoSeparator, TRUE,
				axisFeedbackSwitch,\x0,TRUE);
    SO_KIT_ADD_CATALOG_ENTRY(yAxisFeedback, SoSeparator, TRUE,
				axisFeedbackSwitch,\x0,TRUE);

    // read geometry for shared parts
    if (SO_KIT_IS_FIRST_INSTANCE())
	readDefaultParts("translate2Dragger.iv", geomBuffer, sizeof(geomBuffer) );

    SO_KIT_ADD_FIELD(translation, (0.0, 0.0, 0.0));

    SO_KIT_INIT_INSTANCE();

    // create the parts...
   setPartAsDefault("translator",      "translate2Translator");
   setPartAsDefault("translatorActive","translate2TranslatorActive");
   setPartAsDefault("feedback",        "translate2Feedback");
   setPartAsDefault("feedbackActive",  "translate2FeedbackActive");
   setPartAsDefault("xAxisFeedback",  "translate2XAxisFeedback");
   setPartAsDefault("yAxisFeedback",  "translate2YAxisFeedback");

    // Set the switches to 0...
    setSwitchValue( translatorSwitch.getValue(), 0 );
    setSwitchValue( feedbackSwitch.getValue(), 0 );

    // Set the axis feedback switch to SO_SWITCH_NONE
    // They're only displayed while dragging
    setSwitchValue( axisFeedbackSwitch.getValue(), SO_SWITCH_NONE );

    // Create the line projector
    planeProj = new SbPlaneProjector();

    // add the callbacks to perform the dragging
    addStartCallback(  &SoTranslate2Dragger::startCB );
    addMotionCallback( &SoTranslate2Dragger::motionCB );
    addFinishCallback(   &SoTranslate2Dragger::finishCB );

    // add callback to respond to the shift key, for constraining motion
    // to a line within the plane.
    addOtherEventCallback( &SoTranslate2Dragger::metaKeyChangeCB );

    // Updates the translation field when the motionMatrix is set.
    addValueChangedCallback( &SoTranslate2Dragger::valueChangedCB );

    // Updates the motionMatrix when the translation field is set.
    fieldSensor = new SoFieldSensor( &SoTranslate2Dragger::fieldSensorCB, this);
    fieldSensor->setPriority( 0 );

    setUpConnections( TRUE, TRUE );
}
Пример #10
0
////////////////////////////////////////////////////////////////////////
//
// Description:
//    Constructor
//
SoRotateDiscDragger::SoRotateDiscDragger()
//
////////////////////////////////////////////////////////////////////////
{
    SO_KIT_CONSTRUCTOR(SoRotateDiscDragger);

    isBuiltIn = TRUE;

    // Put this stuff under the geomSeparator so it will draw more
    // efficiently.
    SO_KIT_ADD_CATALOG_ENTRY(rotatorSwitch, SoSwitch, TRUE,
				geomSeparator,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(rotator, SoSeparator, TRUE,
				rotatorSwitch,\x0,TRUE);
    SO_KIT_ADD_CATALOG_ENTRY(rotatorActive, SoSeparator, TRUE,
				rotatorSwitch,\x0,TRUE);
    SO_KIT_ADD_CATALOG_ENTRY(feedbackSwitch, SoSwitch, TRUE,
				geomSeparator,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(feedback, SoSeparator, TRUE,
				feedbackSwitch,\x0,TRUE);
    SO_KIT_ADD_CATALOG_ENTRY(feedbackActive, SoSeparator, TRUE,
				feedbackSwitch,\x0,TRUE);

    // read geometry for shared parts
    if (SO_KIT_IS_FIRST_INSTANCE())
	readDefaultParts("rotateDiscDragger.iv", geomBuffer, sizeof(geomBuffer) );

    SO_KIT_ADD_FIELD(rotation, (0.0, 0.0, 0.0, 1.0));

    SO_KIT_INIT_INSTANCE();

    // create the parts...
   setPartAsDefault("rotator",       "rotateDiscRotator");
   setPartAsDefault("rotatorActive", 
			 "rotateDiscRotatorActive"); 
   setPartAsDefault("feedback",      "rotateDiscFeedback");
   setPartAsDefault("feedbackActive",
			 "rotateDiscFeedbackActive");

    // Set the switches to 0...
    setSwitchValue( rotatorSwitch.getValue(), 0 );
    setSwitchValue( feedbackSwitch.getValue(), 0 );

    // our humble projector
    planeProj = new SbPlaneProjector();

    // add the callbacks to perform the dragging
    addStartCallback(  &SoRotateDiscDragger::startCB );
    addMotionCallback( &SoRotateDiscDragger::motionCB );
    addFinishCallback( &SoRotateDiscDragger::doneCB );

    // Updates the scaleFactor field when the motionMatrix is set.
    addValueChangedCallback( &SoRotateDiscDragger::valueChangedCB );

    // Updates the motionMatrix when the scaleFactor field is set.
    fieldSensor 
	= new SoFieldSensor(&SoRotateDiscDragger::fieldSensorCB, this);
    fieldSensor->setPriority( 0 );

    setUpConnections( TRUE, TRUE );
}
Пример #11
0
////////////////////////////////////////////////////////////////////////
//
// Description:
//    Constructor
//
SoDragPointDragger::SoDragPointDragger()
//
////////////////////////////////////////////////////////////////////////
{
    SO_KIT_CONSTRUCTOR(SoDragPointDragger);

    isBuiltIn = TRUE;

    SO_KIT_ADD_CATALOG_ENTRY(noRotSep, SoSeparator, FALSE,
				topSeparator, geomSeparator,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(xTranslatorSwitch, SoSwitch, FALSE, 
				noRotSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(xTranslator, SoTranslate1Dragger, TRUE, 
				xTranslatorSwitch,\x0,TRUE);
    SO_KIT_ADD_CATALOG_ENTRY(xyTranslatorSwitch, SoSwitch, FALSE, 
				noRotSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(xyTranslator, SoTranslate2Dragger, TRUE, 
				xyTranslatorSwitch,\x0,TRUE);

    SO_KIT_ADD_CATALOG_ENTRY(rotXSep, SoSeparator, FALSE,
				topSeparator, geomSeparator,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(rotX, SoRotation, TRUE, 
				rotXSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(xzTranslatorSwitch, SoSwitch, FALSE, 
				rotXSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(xzTranslator, SoTranslate2Dragger, TRUE, 
				xzTranslatorSwitch,\x0,TRUE);

    SO_KIT_ADD_CATALOG_ENTRY(rotYSep, SoSeparator, FALSE,
				topSeparator, geomSeparator,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(rotY, SoRotation, TRUE, 
				rotYSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(zTranslatorSwitch, SoSwitch, FALSE, 
				rotYSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(zTranslator, SoTranslate1Dragger, TRUE, 
				zTranslatorSwitch,\x0,TRUE);
    SO_KIT_ADD_CATALOG_ENTRY(yzTranslatorSwitch, SoSwitch, FALSE, 
				rotYSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(yzTranslator, SoTranslate2Dragger, TRUE, 
				yzTranslatorSwitch,\x0,TRUE);

    SO_KIT_ADD_CATALOG_ENTRY(rotZSep, SoSeparator, FALSE,
				topSeparator, geomSeparator,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(rotZ, SoRotation, TRUE, 
				rotZSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(yTranslatorSwitch, SoSwitch, FALSE, 
				rotZSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(yTranslator, SoTranslate1Dragger, TRUE, 
				yTranslatorSwitch,\x0,TRUE);

    SO_KIT_ADD_CATALOG_ENTRY(xFeedbackSwitch, SoSwitch, FALSE, 
				topSeparator, geomSeparator,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(xFeedbackSep, SoSeparator, FALSE,
				xFeedbackSwitch,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(xFeedbackTranslation, SoTranslation, FALSE,
				xFeedbackSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(xFeedback, SoSeparator, TRUE,
				xFeedbackSep,\x0,TRUE);

    SO_KIT_ADD_CATALOG_ENTRY(yFeedbackSwitch, SoSwitch, FALSE, 
				topSeparator, geomSeparator,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(yFeedbackSep, SoSeparator, FALSE,
				yFeedbackSwitch,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(yFeedbackTranslation, SoTranslation, FALSE,
				yFeedbackSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(yFeedback, SoSeparator, TRUE,
				yFeedbackSep,\x0,TRUE);

    SO_KIT_ADD_CATALOG_ENTRY(zFeedbackSwitch, SoSwitch, FALSE, 
				topSeparator, geomSeparator,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(zFeedbackSep, SoSeparator, FALSE,
				zFeedbackSwitch,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(zFeedbackTranslation, SoTranslation, FALSE,
				zFeedbackSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(zFeedback, SoSeparator, TRUE,
				zFeedbackSep,\x0,TRUE);

    SO_KIT_ADD_CATALOG_ENTRY(planeFeedbackSep, SoSeparator, FALSE,
				topSeparator, geomSeparator,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(planeFeedbackTranslation, SoTranslation, FALSE,
				planeFeedbackSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(planeFeedbackSwitch, SoSwitch, FALSE, 
				planeFeedbackSep,\x0,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(yzFeedback, SoSeparator, TRUE,
				planeFeedbackSwitch,\x0,TRUE);
    SO_KIT_ADD_CATALOG_ENTRY(xzFeedback, SoSeparator, TRUE,
				planeFeedbackSwitch,\x0,TRUE);
    SO_KIT_ADD_CATALOG_ENTRY(xyFeedback, SoSeparator, TRUE,
				planeFeedbackSwitch,\x0,TRUE);

    // read geometry for shared parts
    if (SO_KIT_IS_FIRST_INSTANCE())
	readDefaultParts("dragPointDragger.iv",geomBuffer,sizeof(geomBuffer) );

    // The field that reflects where the dragger has been translated to
    SO_KIT_ADD_FIELD(translation, (0.0, 0.0, 0.0));

    SO_KIT_INIT_INSTANCE();

    // Cached values to make updating the feedback geometry more efficient
    oldXAxisNode = NULL;
    oldYAxisNode = NULL;
    oldZAxisNode = NULL;

    //******************
    // Set up the parts.
    //******************

    // Set up the rotations to orient the draggers correctly.
    SoRotation *myRotX = new SoRotation;
    SoRotation *myRotY = new SoRotation;
    SoRotation *myRotZ = new SoRotation;
    myRotX->rotation = SbRotation( SbVec3f(1,0,0), 1.57079 );
    myRotY->rotation = SbRotation( SbVec3f(0,1,0), 1.57079 );
    myRotZ->rotation = SbRotation( SbVec3f(0,0,1), 1.57079 );
    setAnyPartAsDefault("rotX", myRotX );
    setAnyPartAsDefault("rotY", myRotY );
    setAnyPartAsDefault("rotZ", myRotZ );

    // CREATE THE CHILD DRAGGERS.
    // Create the translate1Draggers...
    SoTranslate1Dragger *myXTrans, *myYTrans, *myZTrans;
    myXTrans = SO_GET_ANY_PART(this,"xTranslator",SoTranslate1Dragger);
    myYTrans = SO_GET_ANY_PART(this,"yTranslator",SoTranslate1Dragger);
    myZTrans = SO_GET_ANY_PART(this,"zTranslator",SoTranslate1Dragger);

    // Create the translate2Draggers...
    SoTranslate2Dragger *myYZTrans, *myXZTrans, *myXYTrans;
    myYZTrans = SO_GET_ANY_PART(this,"yzTranslator",SoTranslate2Dragger);
    myXZTrans = SO_GET_ANY_PART(this,"xzTranslator",SoTranslate2Dragger);
    myXYTrans = SO_GET_ANY_PART(this,"xyTranslator",SoTranslate2Dragger);

    //******************
    // The feedback parts jump around as the limit box changes. That is, they
    // stay fixed in space while the dragger moves around.
    // However, they jump to a new location when the dragger nears the edge.
    // These parts a separate translation node, since they move differently
    // than the dragger itself.
    //******************

    //******************
    // The feedback parts jump around as the limit box changes. That is, they
    // stay fixed in space while the dragger moves around.
    // However, they jump to a new location when the dragger nears the edge.
    // These parts a separate translation node, since they move differently
    // than the dragger itself.
    //
    // Only one plane or one axis is shown at a time, depending on which
    // translator has initiated the dragging.
    //******************

   setPartAsDefault("xFeedback",      "dragPointXFeedback");
   setPartAsDefault("yFeedback",      "dragPointYFeedback");
   setPartAsDefault("zFeedback",      "dragPointZFeedback");

   setPartAsDefault("yzFeedback", "dragPointYZFeedback");
   setPartAsDefault("xzFeedback", "dragPointXZFeedback");
   setPartAsDefault("xyFeedback", "dragPointXYFeedback");

    //********************
    // initialize state, limitbox, gesture variables
    //********************

    // To begin with, only the yTranslator and xzTranslators are turned on.
    // You can switch between pairs of line/plane draggers by hitting the 
    // CONTROL key
    setSwitchValue(xTranslatorSwitch.getValue(),   SO_SWITCH_NONE );
    setSwitchValue(yTranslatorSwitch.getValue(),   0 );
    setSwitchValue(zTranslatorSwitch.getValue(),   SO_SWITCH_NONE );
    setSwitchValue(yzTranslatorSwitch.getValue(),   SO_SWITCH_NONE );
    setSwitchValue(xzTranslatorSwitch.getValue(),   0 );
    setSwitchValue(xyTranslatorSwitch.getValue(),  SO_SWITCH_NONE );

    // ??? Would be cool to be able to choose a free
    // axis, rotate it around to whatever direction, maybe even
    // have it snap to things in the scene, then constrain
    // dragging to that line.

    // Start off inactive
    currentDragger = NULL;

    // The state of the modifier keys
    shftDown = FALSE;

    // Need to initialize since checkBoxLimits will look at it...
    startLocalHitPt.setValue(0,0,0);

    // The jump axes will jump when the edit point gets within
    // 10% of their ends
    jumpLimit = .1;

    // makes the offsetWorkLimit box
    limitBox.makeEmpty();

    updateLimitBoxAndFeedback();

    // These will be called by the child draggers after they call
    // their own callbacks...
    addStartCallback( &SoDragPointDragger::startCB );
    addMotionCallback( &SoDragPointDragger::motionCB );
    addFinishCallback( &SoDragPointDragger::finishCB );

    // When modify keys are released, we need to turn off any constraints.
    addOtherEventCallback( &SoDragPointDragger::metaKeyChangeCB );

    // Updates the translation field when the motionMatrix is set.
    addValueChangedCallback( &SoDragPointDragger::valueChangedCB );

    // Updates the motionMatrix when the translation field is set.
    fieldSensor = new SoFieldSensor( &SoDragPointDragger::fieldSensorCB, this);
    fieldSensor->setPriority( 0 );

    setUpConnections( TRUE, TRUE );
}
Пример #12
0
////////////////////////////////////////////////////////////////////////
//
// Description:
//
// Sets switches to show one line dragger and one plane dragger.
// It cycles through 3 different configurations:
// xline/yzPlane, yline/xzplane, zline/xyplane
//
////////////////////////////////////////////////////////////////////////
void
SoDragPointDragger::showNextDraggerSet()
{
    SoSwitch *sw;

    // Case 1. Currently, xline is displayed. Switch to y.
    sw = (SoSwitch *) xTranslatorSwitch.getValue();
    if ( sw && sw->whichChild.getValue() != SO_SWITCH_NONE ) {
	setSwitchValue(xTranslatorSwitch.getValue(),   SO_SWITCH_NONE );
	setSwitchValue(yTranslatorSwitch.getValue(),   0 );
	setSwitchValue(zTranslatorSwitch.getValue(),   SO_SWITCH_NONE );
	setSwitchValue(yzTranslatorSwitch.getValue(),   SO_SWITCH_NONE );
	setSwitchValue(xzTranslatorSwitch.getValue(),   0 );
	setSwitchValue(xyTranslatorSwitch.getValue(),  SO_SWITCH_NONE );
	return;
    }

    // Case 2. Currently, yline is displayed. Switch to z.
    sw = (SoSwitch *) yTranslatorSwitch.getValue();
    if ( sw && sw->whichChild.getValue() != SO_SWITCH_NONE ) {
	setSwitchValue(xTranslatorSwitch.getValue(),   SO_SWITCH_NONE );
	setSwitchValue(yTranslatorSwitch.getValue(),   SO_SWITCH_NONE );
	setSwitchValue(zTranslatorSwitch.getValue(),   0 );
	setSwitchValue(yzTranslatorSwitch.getValue(),   SO_SWITCH_NONE );
	setSwitchValue(xzTranslatorSwitch.getValue(),   SO_SWITCH_NONE );
	setSwitchValue(xyTranslatorSwitch.getValue(),  0 );
	return;
    }

    // Case 3. Currently, zline is displayed. Switch to x.
    sw = (SoSwitch *) zTranslatorSwitch.getValue();
    if ( sw && sw->whichChild.getValue() != SO_SWITCH_NONE ) {
	setSwitchValue(xTranslatorSwitch.getValue(),   0 );
	setSwitchValue(yTranslatorSwitch.getValue(),   SO_SWITCH_NONE );
	setSwitchValue(zTranslatorSwitch.getValue(),   SO_SWITCH_NONE );
	setSwitchValue(yzTranslatorSwitch.getValue(),   0 );
	setSwitchValue(xzTranslatorSwitch.getValue(),   SO_SWITCH_NONE );
	setSwitchValue(xyTranslatorSwitch.getValue(),  SO_SWITCH_NONE );
	return;
    }
}
Пример #13
0
////////////////////////////////////////////////////////////////////////
//
// Description:
//    Sets the feedback geometry depending on which dragger is active.
//    A 1-D translator results in that line's feedback turning on.
//    A 2-D translator results in that plane's feedback turning on.
//
// Use: private
//
void
SoDragPointDragger::setFeedbackGeometry()
//
////////////////////////////////////////////////////////////////////////
{
    // First, figure out if we need to know a constrained translation
    // direction. This happens if a plane dragger is in use, but is
    // being constrained.
    int translateDir = -1;
#define TINY .0001
    if ( shftDown ) {
	SbVec3f current = getMotionMatrix()[3];
	SbVec3f start   = getStartMotionMatrix()[3];
	SbVec3f motion  = current - start;
	if (    fabs( motion[0]) > fabs( motion[1])
	     && fabs( motion[0]) > fabs( motion[2]))
	     translateDir = 0;
	else if ( fabs( motion[1]) > fabs( motion[2]))
	    translateDir = 1;
	else if ( fabs( motion[2] ) > TINY )
	    translateDir = 2;
    }
#undef TINY

    // Turn on appropriate parts, based on state.
    if (currentDragger == NULL) {
	setSwitchValue(xFeedbackSwitch.getValue(),      SO_SWITCH_NONE );
	setSwitchValue(yFeedbackSwitch.getValue(),      SO_SWITCH_NONE );
	setSwitchValue(zFeedbackSwitch.getValue(),      SO_SWITCH_NONE );
	setSwitchValue(planeFeedbackSwitch.getValue(),  SO_SWITCH_NONE );
    }
    else if (currentDragger == xTranslator.getValue() ) {
	setSwitchValue(xFeedbackSwitch.getValue(),      0 );
	setSwitchValue(yFeedbackSwitch.getValue(),      SO_SWITCH_NONE );
	setSwitchValue(zFeedbackSwitch.getValue(),      SO_SWITCH_NONE );
	setSwitchValue(planeFeedbackSwitch.getValue(),  SO_SWITCH_NONE );
    }
    else if (currentDragger == yTranslator.getValue() ) {
	setSwitchValue(xFeedbackSwitch.getValue(),      SO_SWITCH_NONE );
	setSwitchValue(yFeedbackSwitch.getValue(),      0 );
	setSwitchValue(zFeedbackSwitch.getValue(),      SO_SWITCH_NONE );
	setSwitchValue(planeFeedbackSwitch.getValue(),  SO_SWITCH_NONE );
    }
    else if (currentDragger == zTranslator.getValue() ) {
	setSwitchValue(xFeedbackSwitch.getValue(),      SO_SWITCH_NONE );
	setSwitchValue(yFeedbackSwitch.getValue(),      SO_SWITCH_NONE );
	setSwitchValue(zFeedbackSwitch.getValue(),      0 );
	setSwitchValue(planeFeedbackSwitch.getValue(),  SO_SWITCH_NONE );
    }
    else if (currentDragger == yzTranslator.getValue() ) {
	setSwitchValue(xFeedbackSwitch.getValue(),      SO_SWITCH_NONE );
	if ( translateDir == -1 || translateDir == 1 )
	    setSwitchValue(yFeedbackSwitch.getValue(),  0 );
	else
	    setSwitchValue(yFeedbackSwitch.getValue(),  SO_SWITCH_NONE );
	if ( translateDir == -1 || translateDir == 2 )
	    setSwitchValue(zFeedbackSwitch.getValue(),  0 );
	else
	    setSwitchValue(zFeedbackSwitch.getValue(),  SO_SWITCH_NONE );
	setSwitchValue(planeFeedbackSwitch.getValue(),  0 );
    }
    else if (currentDragger == xzTranslator.getValue() ) {
	if ( translateDir == -1 || translateDir == 0 )
	    setSwitchValue(xFeedbackSwitch.getValue(),  0 );
	else
	    setSwitchValue(xFeedbackSwitch.getValue(),  SO_SWITCH_NONE );
	setSwitchValue(yFeedbackSwitch.getValue(),      SO_SWITCH_NONE );
	if ( translateDir == -1 || translateDir == 2 )
	    setSwitchValue(zFeedbackSwitch.getValue(),  0 );
	else
	    setSwitchValue(zFeedbackSwitch.getValue(),  SO_SWITCH_NONE );
	setSwitchValue(planeFeedbackSwitch.getValue(),  1 );
    }
    else if (currentDragger == xyTranslator.getValue() ) {
	if ( translateDir == -1 || translateDir == 0 )
	    setSwitchValue(xFeedbackSwitch.getValue(),  0 );
	else
	    setSwitchValue(xFeedbackSwitch.getValue(),  SO_SWITCH_NONE );
	if ( translateDir == -1 || translateDir == 1 )
	    setSwitchValue(yFeedbackSwitch.getValue(),  0 );
	else
	    setSwitchValue(yFeedbackSwitch.getValue(),  SO_SWITCH_NONE );
	setSwitchValue(zFeedbackSwitch.getValue(),      SO_SWITCH_NONE );
	setSwitchValue(planeFeedbackSwitch.getValue(),  2 );
    }

    checkBoxLimits();

    //**************************************
    // Set the transforms for the feedback axes and/or planes.
    //**************************************

    // First, find the center and scale for each part, in LOCAL space.

	// The limit box is defined in a space aligned and scaled as 
	// LOCAL space, but with it's center remaining fixed in WORLD 
	// space.

	// We need to transform the center of the limitBox
	// from WORLD space to LOCAL space to 
	// find the location of the center of the limit box feedback.
	SbMatrix worldToLocal = getWorldToLocalMatrix();

	SbVec3f limitBoxCenterInLocal = limitBox.getCenter();
	worldToLocal.multVecMatrix( limitBoxCenterInLocal, 
				     limitBoxCenterInLocal );

	SbVec3f xAxisSpot = limitBoxCenterInLocal;
	SbVec3f yAxisSpot = limitBoxCenterInLocal;
	SbVec3f zAxisSpot = limitBoxCenterInLocal;
	SbVec3f planeSpot = limitBoxCenterInLocal;

        //With center matching mouse location...
	// The point under the mouse is stored as 'startLocalHitPt', which is
	// expressed in LOCAL space. 

	xAxisSpot[1] = startLocalHitPt[1];
	xAxisSpot[2] = startLocalHitPt[2];

	yAxisSpot[0] = startLocalHitPt[0];
	yAxisSpot[2] = startLocalHitPt[2];

	zAxisSpot[0] = startLocalHitPt[0];
	zAxisSpot[1] = startLocalHitPt[1];

	if (   currentDragger == yzTranslator.getValue()) {
	    planeSpot[0] = startLocalHitPt[0];
	}
	else if (   currentDragger == xzTranslator.getValue()) {
	    planeSpot[1] = startLocalHitPt[1];
	}
	else if (   currentDragger == xyTranslator.getValue()) {
	    planeSpot[2] = startLocalHitPt[2];
	}

    SoTranslation *transNode;
    // Set position of each axis feedback
	if ( xFeedbackTranslation.getValue() == NULL )
	    setAnyPart( "xFeedbackTranslation", new SoTranslation );
	transNode = (SoTranslation *) xFeedbackTranslation.getValue();
	transNode->translation = xAxisSpot;

	if ( yFeedbackTranslation.getValue() == NULL )
	    setAnyPart( "yFeedbackTranslation", new SoTranslation );
	transNode = (SoTranslation *) yFeedbackTranslation.getValue();
	transNode->translation = yAxisSpot;

	if ( zFeedbackTranslation.getValue() == NULL )
	    setAnyPart( "zFeedbackTranslation", new SoTranslation );
	transNode = (SoTranslation *) zFeedbackTranslation.getValue();
	transNode->translation = zAxisSpot;

    // Set position of plane feedback
	if ( planeFeedbackTranslation.getValue() == NULL )
	    setAnyPart( "planeFeedbackTranslation", new SoTranslation );
	transNode = (SoTranslation *) planeFeedbackTranslation.getValue();
	transNode->translation = planeSpot;
}
Пример #14
0
TranslateRadialDragger::
TranslateRadialDragger()
{
  SO_KIT_CONSTRUCTOR(TranslateRadialDragger);

  SO_KIT_ADD_CATALOG_ENTRY(validitySwitch, SoBlinker, TRUE,
                           geomSeparator, , FALSE);

  SO_KIT_ADD_CATALOG_ENTRY(materialSwitch, SoSwitch, TRUE,
                           validitySwitch, , FALSE);

  // Put this under geomSeparator so it draws efficiently.
  SO_KIT_ADD_CATALOG_ENTRY(translatorSwitch, SoSwitch, TRUE,
                           geomSeparator, , FALSE);
  SO_KIT_ADD_CATALOG_ENTRY(translator, SoSeparator, TRUE,
                           translatorSwitch, , TRUE);
  SO_KIT_ADD_CATALOG_ENTRY(translatorActive, SoSeparator, TRUE,
                           translatorSwitch, , TRUE);
  SO_KIT_ADD_CATALOG_ENTRY(feedbackRotate, SoRotation, TRUE,
                           geomSeparator, , TRUE);
  SO_KIT_ADD_CATALOG_ENTRY(feedbackSwitch, SoSwitch, TRUE,
                           geomSeparator, , FALSE);
  SO_KIT_ADD_CATALOG_ENTRY(feedback, SoSeparator, TRUE,
                           feedbackSwitch, , TRUE);
  SO_KIT_ADD_CATALOG_ENTRY(feedbackActive, SoSeparator, TRUE,
                           feedbackSwitch, , TRUE);


  SO_KIT_ADD_CATALOG_ENTRY(materialPlaced, SoMaterial, TRUE,
                           materialSwitch, , TRUE);
  SO_KIT_ADD_CATALOG_ENTRY(materialNormal, SoMaterial, TRUE,
                           materialSwitch, , TRUE);
  SO_KIT_ADD_CATALOG_ENTRY(materialActive, SoMaterial, TRUE,
                           materialSwitch, , TRUE);
  SO_KIT_ADD_CATALOG_ENTRY(materialInvalid, SoMaterial, TRUE,
                           validitySwitch, , TRUE);

  // Read geometry resources. Only do this the first time we
  // construct one.  'geomBuffer' contains our compiled in
  // defaults. The user can override these by specifying new
  // scene graphs in the file:
  // $(SO_DRAGGER_DIR)/translateRadialDragger.iv
  if(SO_KIT_IS_FIRST_INSTANCE())
    readDefaultParts("translateRadialDragger.iv", geomBuffer,
                     sizeof(geomBuffer) - 1);

  // Field that always shows current position of the dragger.
  SO_KIT_ADD_FIELD(translation, (0.0, 0.0, 0.0));

  // Creates the parts list for this nodekit
  SO_KIT_INIT_INSTANCE();

  // Create the parts of the dragger. This dragger has five
  // parts that we need to create: "translator",
  // "translatorActive", "feedback," and "feedbackActive" will
  // be created using the resource mechanism. They are looked
  // up in the global dictionary.
  // "rotator," used to position the feedback so it points in
  // the direction selected by the user, will just be a plain
  // old SoRotation node.
  // We call 'setPartAsDefault' because we are installing
  // default geometries from the resource files. By calling
  // 'setPartAsDefault' instead of 'setPart', we insure that
  // these parts will not write to file unless they are
  // changed later.
  setPartAsDefault("translator",
                   "translateRadialTranslator");
  setPartAsDefault("translatorActive",
                   "translateRadialTranslatorActive");
  setPartAsDefault("feedback",
                   "translateRadialFeedback");
  setPartAsDefault("feedbackActive",
                   "translateRadialFeedbackActive");
  setPartAsDefault("materialNormal",
                   "translateNormalMaterial");
  setPartAsDefault("materialActive",
                   "translateActiveMaterial");
  setPartAsDefault("materialPlaced",
                   "translatePlacedMaterial");
  setPartAsDefault("materialInvalid",
                   "translateInvalidMaterial");

  // Set the switch parts to 0 to display the inactive parts.
  // The parts "translatorSwitch" and "feedbackSwitch"
  // are not public parts. (i.e., when making the catalog, the
  // isPublic flag was set FALSE, so users cannot access them)
  // To retrieve the parts we must use the SO_GET_ANY_PART
  // macro which calls the protected method getAnyPart().
  SoSwitch *sw;
  sw = SO_GET_ANY_PART(this, "translatorSwitch", SoSwitch);
  setSwitchValue(sw, 0);
  sw = SO_GET_ANY_PART(this, "feedbackSwitch", SoSwitch);
  setSwitchValue(sw, 0);
  sw = SO_GET_ANY_PART(this, "materialSwitch", SoSwitch);
  setSwitchValue(sw, 0);
  sw = SO_GET_ANY_PART(this, "validitySwitch", SoBlinker);
  setSwitchValue(sw, 0);

  // This dragger does motion along a line,
  // so we create a line projector.
  lineProj = new SbLineProjector();

  // Add the callback functions that will be called when
  // the user clicks, drags, and releases.
  addStartCallback(&TranslateRadialDragger::startCB);
  addMotionCallback(&TranslateRadialDragger::motionCB);
  addFinishCallback(&TranslateRadialDragger::finishCB);

  // Updates the translation field when the dragger moves.
  addValueChangedCallback(&TranslateRadialDragger::valueChangedCB);

  // Updates the motionMatrix (and thus moves the dragger
  // through space) to a new location whenever the translation
  // field is changed from the outside.
  fieldSensor = new SoFieldSensor(
      &TranslateRadialDragger::fieldSensorCB, this);
  fieldSensor->setPriority(0);
  setUpConnections(TRUE, TRUE);
}