// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== proc int jointOrientAxesStringToInt( string $ax ) { switch( tolower( $ax ) ) { default : case "x": return 1; case "y": return 2; case "z": return 3; } } proc string jointOrientAxesIntToString( int $ax ) { switch( $ax ) { default: case 1: return "x"; case 2: return "y"; case 3: return "z"; } } proc int jointOrientSignStringToInt( string $s ) { switch( tolower( $s ) ) { default : case "up" : return 1; case "down": return 2; } } proc string jointOrientSignIntToString( int $s ) { switch( $s ) { default: case 1: return "up"; case 2: return "down"; } } proc jointOrientCompleteTriple( string $ax[] ) { switch ( $ax[1] ) { case "x": { switch( $ax[0] ) { case "y": $ax[2] = "z"; break; case "z": $ax[2] = "y"; break; } } break; case "z": { switch( $ax[0] ) { case "x": $ax[2] = "y"; break; case "y": $ax[2] = "x"; break; } } break; case "y": { switch( $ax[0] ) { case "x": $ax[2] = "z"; break; case "z": $ax[2] = "x"; break; } } break; } } global proc jointOrientEnablePrimaryOptions( string $parent, int $state ) { setParent $parent; control -e -enable $state ojPrimaryAxisGrp; control -e -enable $state ojSecondaryAxisGrp; } global proc jointOrientEnableSecondaryOptions( string $parent, int $state ) { setParent $parent; control -e -enable $state ojSecondaryOrientGrp; control -e -enable $state ojSecondaryOrientSignGrp; } global proc jointOrientSetOrientAxes( string $parent, string $axes[] ) { setParent $parent; string $oj = $axes[0]; string $sao = $axes[1]; // Check if the user wants to orient the joint to the world frame. if ( strcmp( $oj, "none" ) == 0 ) { // If so, enable the world axis checkbox and exit. checkBoxGrp -e -value1 true ojWorldAxisGrp; jointOrientWorldSelected $parent; return; } jointOrientEnablePrimaryOptions $parent true; checkBoxGrp -e -value1 false ojWorldAxisGrp; // If the user doesn't want to align to the world, a xyz triple MUST // be specified. if ( size( $oj ) != 3 ) return; // Split the input string into primary, secondary, and tertiary parts int $primary[]; $primary[0] = jointOrientAxesStringToInt( substring( $oj, 1, 1 ) ); $primary[1] = jointOrientAxesStringToInt( substring( $oj, 2, 2 ) ); $primary[2] = jointOrientAxesStringToInt( substring( $oj, 3, 3 ) ); radioButtonGrp -e -select $primary[0] ojPrimaryAxisGrp; radioButtonGrp -e -select $primary[1] ojSecondaryAxisGrp; if ( strcmp( $sao, "none" ) == 0 ) { radioButtonGrp -e -select 4 ojSecondaryAxisGrp; jointOrientEnableSecondaryOptions $parent false; } else { jointOrientEnableSecondaryOptions $parent true; int $saoDir = jointOrientAxesStringToInt( substring( $sao, 1, 1 ) ); int $saoSgn = jointOrientSignStringToInt( substring( $sao, 2, size($sao) ) ); radioButtonGrp -e -select $saoDir ojSecondaryOrientGrp; optionMenu -e -select $saoSgn ojSecondaryOrientSignGrp; } } global proc jointOrientGetOrientAxes( string $parent, string $axes[] ) { setParent $parent; string $oj = "none"; string $sao = "none"; // If the user has selected to orient the joint to world to something other than world int $isWorld = `checkBoxGrp -q -value1 ojWorldAxisGrp`; if ( $isWorld == false ) { // Query the UI to determine the primary and secondary axes ... int $pri = `radioButtonGrp -q -select ojPrimaryAxisGrp`; int $sec = `radioButtonGrp -q -select ojSecondaryAxisGrp`; // If something other than none has been selected for the secondary ... if ( $sec != 4 ) { // ... build the sao from the secondary orient direction and sign int $dir = `radioButtonGrp -q -select ojSecondaryOrientGrp`; int $sgn = `optionMenu -q -select ojSecondaryOrientSignGrp`; $sao = jointOrientAxesIntToString( $dir ) + jointOrientSignIntToString( $sgn ); } // ... handle the case when the secondary axis is "none" if ( $sec == 4 ) $sec = fmod( $pri, 3 ) + 1; // ... and complete the xyz triple for the oj command argument string $ojs[] = { jointOrientAxesIntToString( $pri ), jointOrientAxesIntToString( $sec ) }; jointOrientCompleteTriple( $ojs ); $oj = stringArrayToString( $ojs, "" ); } // Assign values to the string array parameter $axes = {}; $axes[0] = $oj; $axes[1] = $sao; } global proc jointOrientWorldSelected( string $parent ) { setParent $parent; int $selected = ( `checkBoxGrp -q -v1 ojWorldAxisGrp` ) ? false : true ; jointOrientEnablePrimaryOptions $parent $selected ; $selected = ( `radioButtonGrp -q -select ojSecondaryAxisGrp` == 4 ) ? false : $selected; jointOrientEnableSecondaryOptions $parent $selected ; jointOrientPrimarySelected $parent; } global proc jointOrientPrimarySelected( string $parent ) { setParent $parent; int $i = `radioButtonGrp -q -select ojPrimaryAxisGrp`; int $j = `radioButtonGrp -q -select ojSecondaryAxisGrp`; if ( $i == $j ) radioButtonGrp -e -select ( fmod( $i, 3 ) + 1 ) ojSecondaryAxisGrp; } global proc jointOrientSecondarySelected( string $parent ) { setParent $parent; int $i = `radioButtonGrp -q -select ojPrimaryAxisGrp`; int $j = `radioButtonGrp -q -select ojSecondaryAxisGrp`; jointOrientEnableSecondaryOptions $parent ( ( $j == 4 ) ? false : true ); if ( $i == $j && $j != 4 ) radioButtonGrp -e -select ( fmod( $j, 3 ) + 1 ) ojPrimaryAxisGrp; } global proc jointOrientOptionsSetup( string $parent ) { setParent $parent; frameLayout -collapsable true -collapse false -label (uiRes("m_jointOrientUtils.kOrientationSettings")) orientationSettingsFrame; $parent = `columnLayout -adjustableColumn 1`; // Define widths of various columns. Note that we make the first column a little wider on // non-windows platforms to avoid clipping issues. int $w1 = ( `about -win` )? 190 : 200; int $w2 = 50; int $w3 = $w1 + 3.2*$w2 ; string $x = (uiRes("m_jointOrientUtils.kX")); string $y = (uiRes("m_jointOrientUtils.kY")); string $z = (uiRes("m_jointOrientUtils.kZ")); string $w = (uiRes("m_jointOrientUtils.kW")); string $plus = (uiRes("m_jointOrientUtils.kPlus")); string $mnus = (uiRes("m_jointOrientUtils.kMinus")); string $world = (uiRes("m_jointOrientUtils.kWorldOrientationLabel")); string $paxis = (uiRes("m_jointOrientUtils.kPriAxisLabel")); string $saxis = (uiRes("m_jointOrientUtils.kSecAxisLabel")); string $sorient = (uiRes("m_jointOrientUtils.kSecondaryOrientLabel")); string $worlda = (uiRes("m_jointOrientUtils.kWorldOrientationAnnot")); string $paxisa = (uiRes("m_jointOrientUtils.kPriAxisAnnot")); string $saxisa = (uiRes("m_jointOrientUtils.kSecAxisAnnot")); string $sorienta = (uiRes("m_jointOrientUtils.kSecondaryOrientAnnot")); checkBoxGrp -label $world -annotation $worlda -numberOfCheckBoxes 1 -columnWidth 1 $w1 -cc ( "jointOrientWorldSelected " + $parent + ";" ) ojWorldAxisGrp; radioButtonGrp -label $paxis -annotation $paxisa -numberOfRadioButtons 3 -labelArray3 $x $y $z -columnWidth 1 $w1 -columnWidth 2 $w2 -columnWidth 3 $w2 -columnWidth 4 $w2 -select 1 -cc ( "jointOrientPrimarySelected " + $parent + ";" ) ojPrimaryAxisGrp; radioButtonGrp -label $saxis -annotation $saxisa -numberOfRadioButtons 4 -labelArray4 $x $y $z $w -columnWidth 1 $w1 -columnWidth 2 $w2 -columnWidth 3 $w2 -columnWidth 4 $w2 -columnWidth 5 $w2 -select 2 -cc ( "jointOrientSecondarySelected " + $parent + ";" ) ojSecondaryAxisGrp; rowLayout -numberOfColumns 3 -width ( $w3 + $w2 + 1 ) -columnWidth 1 $w3 -columnWidth 2 $w2 -columnWidth 3 1 -columnOffset3 0 0 0 -columnAlign3 left left left rowLayout1; radioButtonGrp -numberOfRadioButtons 3 -label $sorient -annotation $sorienta -labelArray3 $x $y $z -width $w3 -columnWidth 1 $w1 -columnWidth 2 $w2 -columnWidth 3 $w2 -columnWidth 4 $w2 -select 1 ojSecondaryOrientGrp; optionMenu -width $w2 ojSecondaryOrientSignGrp; menuItem -label $plus; menuItem -label $mnus; setParent ..; } global proc jointOrientUtils() {}