manipulators/manipcamera/ormanipcamera_layout.cxx

manipulators/manipcamera/ormanipcamera_layout.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
MATERIALS DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
//--- Class declarations
#include "ormanipcamera_layout.h"
//--- Registration defines
#define ORMANIPCAMERA__LAYOUT ORManipulatorCameraLayout
//--- FiLMBOX implementation and registration
FBManipulatorLayoutImplementation ( ORMANIPCAMERA__LAYOUT );
FBRegisterManipulatorLayout ( ORMANIPCAMERA__LAYOUT,
ORMANIPCAMERA__CLASSSTR,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* FiLMBOX Constructor.
************************************************/
bool ORManipulatorCameraLayout::FBCreate()
{
if( FBManipulatorLayout::FBCreate() )
{
// Get a handle on the manipulator
mManipulator = ((ORManipulatorCamera *)(FBManipulator *)Manipulator);
// Create & configure the UI
UICreate ();
UIConfigure ();
UIReset ();
// Add idle callback
mSystem.OnUIIdle.Add( this, (FBCallback) &ORManipulatorCameraLayout::EventUIIdle );
return true;
}
return false;
}
/************************************************
* FiLMBOX Destructor.
************************************************/
void ORManipulatorCameraLayout::FBDestroy()
{
// Remove idle callback
mSystem.OnUIIdle.Remove( this, (FBCallback) &ORManipulatorCameraLayout::EventUIIdle );
FBManipulatorLayout::FBDestroy();
}
/************************************************
* Create the UI.
************************************************/
void ORManipulatorCameraLayout::UICreate()
{
int lS = 4;
int lH = 18;
// Add regions
AddRegion("LabelAOV", "LabelAOV",
lS, kFBAttachLeft, "", 1.0,
lS, kFBAttachTop, "", 1.0,
-lS, kFBAttachRight, "", 1.0,
lH, kFBAttachNone, NULL, 1.0 );
AddRegion("ButtonAnimatingAOV", "ButtonAnimatingAOV",
0, kFBAttachLeft, "LabelAOV", 1.0,
lS, kFBAttachBottom, "LabelAOV", 1.0,
0, kFBAttachWidth, "LabelAOV", 1.0,
0, kFBAttachHeight, "LabelAOV", 1.0 );
AddRegion("ButtonAOVUpOrDown", "ButtonAOVUpOrDown",
0, kFBAttachLeft, "ButtonAnimatingAOV", 1.0,
lS, kFBAttachBottom, "ButtonAnimatingAOV", 1.0,
0, kFBAttachWidth, "ButtonAnimatingAOV", 1.0,
0, kFBAttachHeight, "ButtonAnimatingAOV", 1.0 );
AddRegion("EditNumberAOVStep", "EditNumberAOVStep",
0, kFBAttachLeft, "ButtonAOVUpOrDown", 1.0,
lS, kFBAttachBottom, "ButtonAOVUpOrDown", 1.0,
0, kFBAttachWidth, "ButtonAOVUpOrDown", 1.0,
0, kFBAttachHeight, "ButtonAOVUpOrDown", 1.0 );
AddRegion("LabelRotate", "LabelRotate",
0, kFBAttachLeft, "EditNumberAOVStep", 1.0,
2*lS, kFBAttachBottom, "EditNumberAOVStep", 1.0,
0, kFBAttachRight, "EditNumberAOVStep", 1.0,
0, kFBAttachHeight, "EditNumberAOVStep", 1.0 );
AddRegion("ButtonRotating", "ButtonRotating",
0, kFBAttachLeft, "LabelRotate", 1.0,
lS, kFBAttachBottom, "LabelRotate", 1.0,
0, kFBAttachWidth, "LabelRotate", 1.0,
0, kFBAttachHeight, "LabelRotate", 1.0 );
AddRegion("ButtonDirectionLR", "ButtonDirectionLR",
0, kFBAttachLeft, "ButtonRotating", 1.0,
lS, kFBAttachBottom, "ButtonRotating", 1.0,
0, kFBAttachWidth, "ButtonRotating", 1.0,
0, kFBAttachHeight, "ButtonRotating", 1.0 );
AddRegion("EditNumberRotateStep","EditNumberRotateStep",
0, kFBAttachLeft, "ButtonDirectionLR", 1.0,
lS, kFBAttachBottom, "ButtonDirectionLR", 1.0,
0, kFBAttachWidth, "ButtonDirectionLR", 1.0,
0, kFBAttachHeight, "ButtonDirectionLR", 1.0 );
AddRegion("LabelList", "LabelList",
0, kFBAttachLeft, "EditNumberRotateStep", 1.0,
2*lS, kFBAttachBottom, "EditNumberRotateStep", 1.0,
0, kFBAttachRight, "EditNumberRotateStep", 1.0,
0, kFBAttachHeight, "EditNumberRotateStep", 1.0 );
AddRegion("ListModel", "ListModel",
0, kFBAttachLeft, "LabelList", 1.0,
lS, kFBAttachBottom, "LabelList", 1.0,
0, kFBAttachWidth, "LabelList", 1.0,
0, kFBAttachHeight, "LabelList", 1.0 );
AddRegion("ButtonClearList", "ButtonClearList",
0, kFBAttachLeft, "ListModel", 1.0,
lS, kFBAttachBottom, "ListModel", 1.0,
0, kFBAttachWidth, "ListModel", 1.0,
0, kFBAttachHeight, "ListModel", 1.0 );
AddRegion("EditVectorPosition", "EditVectorPosition",
0, kFBAttachLeft, "ButtonClearList", 1.0,
lS, kFBAttachBottom, "ButtonClearList", 1.0,
0, kFBAttachWidth, "ButtonClearList", 1.0,
0, kFBAttachHeight, "ButtonClearList", 1.0 );
// Assign regions
SetControl( "LabelAOV", mLabelAOV );
SetControl( "ButtonAnimatingAOV", mButtonAnimatingAOV );
SetControl( "ButtonAOVUpOrDown", mButtonAOVUpOrDown );
SetControl( "EditNumberAOVStep", mEditNumberAOVStep );
SetControl( "LabelRotate", mLabelRotate );
SetControl( "ButtonRotating", mButtonRotating );
SetControl( "ButtonDirectionLR", mButtonDirectionLR );
SetControl( "EditNumberRotateStep", mEditNumberRotateStep );
SetControl( "LabelList", mLabelList );
SetControl( "ListModel", mListModel );
SetControl( "ButtonClearList", mButtonClearList );
SetControl( "EditVectorPosition", mEditVectorPosition );
}
/************************************************
* Configure the UI.
************************************************/
void ORManipulatorCameraLayout::UIConfigure()
{
// Configure the UI elements.
mLabelAOV.Caption = "Angle Of View";
mButtonAOVUpOrDown.Style = kFB2States;
mButtonAOVUpOrDown.Caption = "Zoom Out";
mEditNumberAOVStep.Min = 0.01;
mEditNumberAOVStep.Max = 0.1;
mEditNumberAOVStep.Precision = 3.3;
mEditNumberAOVStep.SmallStep = 0.01;
mEditNumberAOVStep.LargeStep = 0.01;
mLabelRotate.Caption = "Rotation/Observation";
mButtonDirectionLR.Style = kFB2States;
mButtonDirectionLR.Caption = "Turning Left";
mEditNumberRotateStep.Min = 0.01;
mEditNumberRotateStep.SmallStep = 0.01;
mEditNumberRotateStep.LargeStep = 0.01;
mEditNumberRotateStep.Max = 3;
mEditNumberRotateStep.Precision = 3.3;
mLabelList.Caption = "Turning Objects";
mListModel.Items.SetString ("---Current Camera---");
mListModel.Style = kFBVerticalList;
mButtonClearList.Caption = "Clear Object";
// Get the values from the manipulator (this is called as well in UIReset() )
mButtonAnimatingAOV.Caption = mManipulator->mAnimatingAOV ? "Zooming":"Stopped";
mButtonAOVUpOrDown.State = mManipulator->mZoomingOut ? 1:0;
mEditNumberAOVStep.Value = mManipulator->mStepAOV;
mButtonRotating.Caption = mManipulator->mRotating ? "Turning":"Stopped";
mButtonDirectionLR.State = mManipulator->mTurningLeft ? 1:0;
mEditNumberRotateStep.Value = mManipulator->mStepRotate;
// Assign the callbacks
mButtonAnimatingAOV.OnClick.Add ( this, (FBCallback) &ORManipulatorCameraLayout::EventButtonAnimatingAOVClick );
mButtonAOVUpOrDown.OnClick.Add ( this, (FBCallback) &ORManipulatorCameraLayout::EventButtonAOVUpOrDownClick );
mEditNumberAOVStep.OnChange.Add ( this, (FBCallback) &ORManipulatorCameraLayout::EventEditNumberAOVStepChange );
mButtonRotating.OnClick.Add ( this, (FBCallback) &ORManipulatorCameraLayout::EventButtonRotatingClick );
mButtonDirectionLR.OnClick.Add ( this, (FBCallback) &ORManipulatorCameraLayout::EventButtonDirectionLRClick );
mEditNumberRotateStep.OnChange.Add ( this, (FBCallback) &ORManipulatorCameraLayout::EventEditNumberRotateStepChange );
mListModel.OnDragAndDrop.Add ( this, (FBCallback) &ORManipulatorCameraLayout::EventListModelDragAndDrop );
mButtonClearList.OnClick.Add ( this, (FBCallback) &ORManipulatorCameraLayout::EventButtonClearListClick );
}
/************************************************
* Reset the UI from the manipulator.
************************************************/
void ORManipulatorCameraLayout::UIReset()
{
// Fill the UI elements with values from the manipulator
mListModel.Items.Clear();
if( mManipulator->mModelRotate )
{
mListModel.Items.Add( mManipulator->mModelRotate->Name, (unsigned long) mManipulator->mModelRotate );
}
else
{
mListModel.Items.SetString ("---Current Camera---");
}
mButtonAOVUpOrDown.State = mManipulator->mZoomingOut ? 1:0;
mButtonAnimatingAOV.Caption = mManipulator->mAnimatingAOV ? "Zooming":"Stopped";
mEditNumberAOVStep.Value = mManipulator->mStepAOV;
mButtonRotating.Caption = mManipulator->mRotating ? "Turning":"Stopped";
mEditNumberRotateStep.Value = mManipulator->mStepRotate;
mButtonDirectionLR.State = mManipulator->mTurningLeft ? 1:0;
}
/************************************************
* Refresh the UI on idle.
************************************************/
void ORManipulatorCameraLayout::UIRefresh()
{
FBVector3d lPos;
if( mManipulator->mModelRotate )
{
mManipulator->mModelRotate->GetVector( lPos, kModelTranslation, true );
}
mEditVectorPosition.Value = lPos;
}
/************************************************
* UI Idle event.
************************************************/
void ORManipulatorCameraLayout::EventUIIdle( HISender pSender, HKEvent pEvent )
{
UIRefresh();
}
/************************************************
* Activate/Deactivate AOV animation.
************************************************/
void ORManipulatorCameraLayout::EventButtonAnimatingAOVClick( HISender pSender, HKEvent pEvent )
{
mManipulator->mAnimatingAOV = mManipulator->mAnimatingAOV ? false : true;
UIReset();
}
/************************************************
* Select which direction the AOV is going.
************************************************/
void ORManipulatorCameraLayout::EventButtonAOVUpOrDownClick( HISender pSender, HKEvent pEvent )
{
mManipulator->mZoomingOut = mButtonAOVUpOrDown.State == 1 ? true : false;
UIReset();
}
/************************************************
* Clear models from list.
************************************************/
void ORManipulatorCameraLayout::EventButtonClearListClick( HISender pSender, HKEvent pEvent )
{
mManipulator->mModelRotate = NULL;
UIReset();
}
/************************************************
* Activate/Deactivate rotating element with manipulator.
************************************************/
void ORManipulatorCameraLayout::EventButtonRotatingClick( HISender pSender, HKEvent pEvent )
{
mManipulator->mRotating = mManipulator->mRotating ? false : true;
UIReset();
}
/************************************************
* Affect the direction of the rotating element.
************************************************/
void ORManipulatorCameraLayout::EventButtonDirectionLRClick( HISender pSender, HKEvent pEvent )
{
mManipulator->mTurningLeft = mButtonDirectionLR.State == 1 ? true : false;
UIReset();
}
/************************************************
* Edit the step size for the animated AOV.
************************************************/
void ORManipulatorCameraLayout::EventEditNumberAOVStepChange( HISender pSender, HKEvent pEvent )
{
mManipulator->mStepAOV = mEditNumberAOVStep.Value;
UIReset();
}
/************************************************
* Edit the rotation step angle for the rotating element.
************************************************/
void ORManipulatorCameraLayout::EventEditNumberRotateStepChange( HISender pSender, HKEvent pEvent )
{
mManipulator->mStepRotate = mEditNumberRotateStep.Value;
UIReset();
}
/************************************************
* List drag and drop event.
************************************************/
void ORManipulatorCameraLayout::EventListModelDragAndDrop( HISender pSender, HKEvent pEvent )
{
FBEventDragAndDrop lDrag(pEvent);
switch( lDrag.State )
{
{
lDrag.Accept();
}
break;
{
mManipulator->mModelRotate = (FBModel*) lDrag.Get(0);
UIReset();
}
break;
}
}