// =========================================================================== // 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. // =========================================================================== ///////////////////////////////////////////////////////////////////////// // // Creation Date: May 1996 // // Description: // Create and show a dialog for creating flexors. // ///////////////////////////////////////////////////////////////////////// // // Procedure Name: // handleExecError // // Description: // called to clean up when execFlexorCommand is called but the // flexor that the user requested was not able to be created // (The most likely source of error would be that the user // had an invalid selection. For example, you can't make a joint // flexor if you do not have a joint in your selection list.) // // Input Arguments: // none // // Return Value: // none // proc handleExecError(string $oldSelection[]) { // disable position flexor check box // checkBoxGrp -e -v1 0 positionBox; // restore the old selection list // if (size($oldSelection) > 0) { select -r $oldSelection; } return; } proc string flexorType_melToUI( string $mel ) { string $ui = $mel; if( $mel == "lattice" ) { $ui = (uiRes("m_createFlexorWin.kLattice")); } else if( $mel == "sculpt" ) { $ui = (uiRes("m_createFlexorWin.kSculpt")); } else if( $mel == "jointCluster" ) { $ui = (uiRes("m_createFlexorWin.kJointCluster")); } else { uiToMelMsg( "flexorType_melToUI", $mel, 1 ); } return $ui; } proc string flexorType_uiToMel( string $ui ) { string $mel = $ui; if( $ui == (`uiRes("m_createFlexorWin.kLattice")`) ) { $mel = "lattice"; } else if ( $ui == (`uiRes("m_createFlexorWin.kSculpt")`) ) { $mel = "sculpt"; } else if ( $ui == (`uiRes("m_createFlexorWin.kJointCluster")`) ) { $mel = "jointCluster"; } else { uiToMelMsg( "flexorType_uiToMel", $ui, 1 ); } return $mel; } // // Procedure Name: // execFlexorCommand // // Description: // create a string corresponding to the flexor command based // on the UI and execute it // // Input Arguments: // none // // Return Value: // none // global proc execFlexorCommand () { int $doTwoCommands = 0; int $flexorIsLattice = 0; int $flexorIsCluster = 0; int $atJoints = `checkBox -q -v allJoints` || `checkBox -q -v selJoints`; int $atBones = `checkBox -q -v allBones` || `checkBox -q -v selBones`; // all segments but only selected joints or vice versa require // different sets of flags so we need two commands // if ($atJoints && $atBones) { $doTwoCommands = 1; } string $flexorType = flexorType_uiToMel(`optionMenuGrp -q -v typeMenu`); string $flexorType2; string $whereString; string $whereString2; int $atBindPoseWarning = 0; $flexorIsLattice = ($flexorType == "lattice"); $flexorIsCluster = ($flexorType == "jointCluster"); // If the flexor is a lattice, make it a joint or bone lattice // according to whether the user asked to have it at bones // or at joints. // // Two commands will be necessary if the user asked to have it // at both joints and bones. // if ($flexorIsLattice) { string $bpNode[] = `dagPose -q -bp -sl`; string $atBindPose[]; if (! catch ($atBindPose = `eval ("dagPose -q -ap "+$bpNode[0])`)) { if (0 != size($atBindPose[0])) { $atBindPoseWarning = 1; } } if ($atJoints && $atBones) { $flexorType = "jointLattice"; $flexorType2 = "boneLattice"; } else if ($atJoints) { $flexorType = "jointLattice"; } else if ($atBones) { $flexorType = "boneLattice"; } else { $flexorType = "lattice"; } } else if ($flexorIsCluster) { $flexorType = "jointCluster"; } else if ($atJoints && $atBones) { $flexorType2 = $flexorType; } // the whereString's are constructed according to the states of // "At Selected Bones", "At All Bones", "At Selected Joints", "At All Joints" // if ($atJoints && $atBones) { $whereString = " -aj "; if (`checkBox -q -v allJoints`) $whereString += "-ts "; $whereString2 = " -ab "; if (`checkBox -q -v allBones`) $whereString2 += "-ts "; } else if ($atJoints) { if (`checkBox -q -v allJoints`) $whereString = " -aj -ts "; else $whereString = " -aj "; } else if ($atBones) { if (`checkBox -q -v allBones`) $whereString = "-ab -ts "; else $whereString = " -ab "; } // start constructing the command string(s) that we will execute // string $deformCmd; string $cmdString = "flexor -typ " + $flexorType + $whereString; string $cmdString2 = "flexor -typ " + $flexorType2 + $whereString2; // If it is a sculpt flexor, get the sculpt-specific data // from the UI and add it to the flexor's -dc flag argument // if ($flexorType == "sculpt") { $deformCmd = "sculpt"; float $maxDisp = `floatSliderGrp -q -v maxFS`; float $dropoff = `floatSliderGrp -q -v dropoffFS`; // Get the sculpt object dropoff type from the // option menu // string $dropoffType = `optionMenuGrp -q -v sculptDropoffMenu`; if($dropoffType == (uiRes("m_createFlexorWin.kNone"))) { $dropoffType = "none"; } else if($dropoffType == (uiRes("m_createFlexorWin.kLinear"))) { $dropoffType = "linear"; } else { $dropoffType = "none"; } // Get the sculpt object mode setting from // the option menu // string $mode = `optionMenuGrp -q -v sculptModeMenu`; if($mode == (uiRes("m_createFlexorWin.kFlip"))) { $mode = "flip"; } else if ($mode == (uiRes("m_createFlexorWin.kProject"))) { $mode = "project"; } else if ($mode == (uiRes("m_createFlexorWin.kStretch"))) { $mode = "stretch"; } else { $mode = "stretch"; } // Get the sculpt object inside mode setting from // the option menu // string $insideMode = `optionMenuGrp -q -v sculptInsideMenu`; if($insideMode == (uiRes("m_createFlexorWin.kRing"))) { $insideMode = "ring"; } else if($insideMode == (uiRes("m_createFlexorWin.kEven"))) { $insideMode = "even"; } else { $insideMode = "ring"; } $deformCmd += (" -mxd " + $maxDisp); $deformCmd += (" -m " + $mode + " -im " + $insideMode); $deformCmd += (" -drt " + $dropoffType + " -dds " + $dropoff); } // if it is a lattice flexor, get the lattice-specific data // from the UI and add them to the flexor's -dc flag argument // else if ($flexorIsLattice) { $deformCmd = "lattice"; int $sd, $td, $ud; $sd = `intSliderGrp -q -v sDiv`; $td = `intSliderGrp -q -v tDiv`; $ud = `intSliderGrp -q -v uDiv`; $deformCmd += (" -dv "+$sd+" "+$td+" "+$ud); $deformCmd += (" -cp "); } // save the current selection so we can restore it later // string $selected[]; $selected = `ls -sl`; // actually execute the first command // string $results[]; if (! $flexorIsCluster) { if ($flexorType == "jointLattice") { $cmdString += " -dc " + ("\""+$deformCmd+" -dualBase true \""); } else { $cmdString += " -dc " + ("\""+$deformCmd+"\""); } } if (catch ($results = `evalEcho $cmdString`) || 0 == size($results)) { // Return here and give the user another chance rather // than removing the window. // if (0 == size($results)) { // cleanup and return // handleExecError($selected); return; } } // we do two commands when there are conflicting flags: // * lattice at segments and at joints // * all segments but only selected joints or vice versa // if ($doTwoCommands) { if (size($selected) > 0) { select -r $selected; } else { select -d; } if (! $flexorIsCluster) $cmdString2 += " -dc " + ("\""+$deformCmd+"\""); catch ($results = `evalEcho $cmdString2`); } // a 0-sized result signals failure. Return here and give the // user another chance rather than removing the window. // if (0 == size($results)) { // cleanup and return // handleExecError($selected); return; } if ($atBindPoseWarning) { warning (uiRes("m_createFlexorWin.kSkeletonWarn")); } // if the user clicked the positionBox, set the state on the // invisible checkBox as a global variable // if (`checkBoxGrp -q -v1 positionBox`) { // select the transform above the lattice so that we can position it // string $currentSelection[]; $currentSelection = `ls -sl`; if ($flexorIsLattice && (1 == size($currentSelection))) { $positionedFlexorLattice=$currentSelection[0]; string $parents[]; $parents = `listRelatives -p`; if (size($parents) > 0) select -r $parents[0]; } checkBoxGrp -e -v1 false positionBox; } else { select -r $selected; } return; } // =============== updateFlexorTypeCB ======== // // update callback for when the flexor type option is changed // // global proc updateFlexorTypeCB() { string $flexorType = flexorType_uiToMel(`optionMenuGrp -q -v typeMenu`); frameLayout -e -enable true flexorBoneFrame; if ($flexorType == "sculpt") { frameLayout -e -visible true sculptFrame; frameLayout -e -visible false latticeFrame; frameLayout -e -visible false clusterFrame; } else if ($flexorType == "jointCluster") { // bone flexors are not valid for joint clusters // frameLayout -e -enable false flexorBoneFrame; checkBox -e -v 0 allBones; checkBox -e -v 0 selBones; frameLayout -e -visible true clusterFrame; frameLayout -e -visible false latticeFrame; frameLayout -e -visible false sculptFrame; } else if ($flexorType == "lattice" || $flexorType == "jointLattice" || $flexorType == "boneLattice") { frameLayout -e -visible true latticeFrame; frameLayout -e -visible false sculptFrame; frameLayout -e -visible false clusterFrame; } } global proc jtsOrBonesCB () // // Description: // callback for when selected joints/bones checkbox is clicked // { int $atSelJoints = `checkBox -q -v selJoints`; int $atSelBones = `checkBox -q -v selBones`; int $atAllJoints = `checkBox -q -v allJoints`; int $atAllBones = `checkBox -q -v allBones`; // enable the positionBox if only one of either selJoints or // selBones is true and neither allJoints nor allBones is on // if (($atSelJoints && $atSelBones) || $atAllJoints || $atAllBones) { checkBoxGrp -e -enable false positionBox; } else if ($atSelJoints || $atSelBones) { checkBoxGrp -e -enable true positionBox; } else { checkBoxGrp -e -enable false positionBox; } } // // Procedure Name: // createFlexorWin // // Description: // create and show a flexor-creation dialog // // Input Arguments: // none // // Return Value: // none // global proc createFlexorWin() { string $winName = "createFlexorDialog"; // if the window already exists, just pop it up to the top // if (`window -exists $winName`) { checkBoxGrp -e -v1 0 positionBox; showWindow $winName; return; } // create a new dialog and base container layout. // string $wndTitle = (uiRes("m_createFlexorWin.kCreateFlexor")); if (`about -mac`) { window -rtf true -mnb false -mxb false -retain -s false -wh 430 325 -tlc 120 740 -title $wndTitle -iconName $wndTitle $winName; } else { window -rtf true -mnb false -mxb false -retain -s false -wh 430 310 -tlc 120 740 -title $wndTitle -iconName $wndTitle $winName; } setUITemplate -pushTemplate DefaultTemplate; // ==================== FLEXOR TYPE OPTIONS =================/ formLayout -nd 100 flexorMainForm; formLayout flexorTypeForm; optionMenuGrp -label (uiRes("m_createFlexorWin.kFlexorType")) -cw 1 80 -cc updateFlexorTypeCB typeMenu; // Get the available types and add them to an // option menu // int $i; string $flexList[]; $flexList = `flexor -q -l`; $flexListCount = size($flexList); menuItem -label (flexorType_melToUI("lattice")) latticeItem; for ($i = 0; $i < $flexListCount; $i++) { if ($flexList[$i] != "lattice" && $flexList[$i] != "jointLattice" && $flexList[$i] != "boneLattice") { menuItem -label (flexorType_melToUI($flexList [$i])) ($flexList[$i] + "Item"); } } setParent -m ..; button -label (uiRes("m_createFlexorWin.kHelp")) -w 80 -c "showHelp CreateFlexor" helpButton; formLayout -e -af typeMenu top 0 -af typeMenu bottom 0 -an typeMenu right -af typeMenu left 0 -af helpButton top 0 -af helpButton bottom 0 -af helpButton right 0 -an helpButton left flexorTypeForm; setParent flexorMainForm; // ==================== JOINT OPTIONS =================/ frameLayout -label (uiRes("m_createFlexorWin.kJoints")) -cll false -cl false -li 0 flexorJointFrame; columnLayout -adj true -cal "left"; checkBox -v 1 -label (uiRes("m_createFlexorWin.kSelectedJoints")) -onc "checkBox -e -v 0 allJoints; jtsOrBonesCB" -ofc "jtsOrBonesCB" selJoints; checkBox -v 0 -label (uiRes("m_createFlexorWin.kAllJoints")) -onc "checkBox -e -v 0 selJoints; jtsOrBonesCB" -ofc "jtsOrBonesCB" allJoints; setParent flexorMainForm; // ==================== BONE OPTIONS =================/ frameLayout -label (uiRes("m_createFlexorWin.kBones")) -cll false -cl false -li 0 flexorBoneFrame; columnLayout -adj true -cal "left"; checkBox -v 0 -label (uiRes("m_createFlexorWin.kSelectedBones")) -onc "checkBox -e -v 0 allBones; jtsOrBonesCB" -ofc "jtsOrBonesCB" selBones; checkBox -v 0 -label (uiRes("m_createFlexorWin.kAllBones")) -onc "checkBox -e -v 0 selBones; jtsOrBonesCB" -ofc "jtsOrBonesCB" allBones; formLayout -e -af flexorTypeForm top 5 -af flexorTypeForm right 5 -af flexorTypeForm left 5 -an flexorTypeForm bottom -ac flexorJointFrame top 5 flexorTypeForm -ap flexorJointFrame right 5 50 -af flexorJointFrame left 5 -ac flexorBoneFrame left 5 flexorJointFrame -ac flexorBoneFrame top 5 flexorTypeForm -af flexorBoneFrame right 5 flexorMainForm; setParent flexorMainForm; // ==================== SPECIAL OPTIONS =================/ // // These forms will hold special flexor options that vary depending // on the flexor type. We leave them invisible and only show // them as needed. // // ==================== SCULPT OPTIONS =================/ setParent flexorMainForm; frameLayout -label (uiRes("m_createFlexorWin.kSculptOptions")) -lv true -li 0 -cll false -cl false -visible false sculptFrame; columnLayout -p sculptFrame -adj true -cw 100 cLayout; floatSliderGrp -field true -label (uiRes("m_createFlexorWin.kMaxDisplacement")) -min 0 -max 2 -pre 3 -step 0.1 maxFS; floatSliderGrp -field true -label (uiRes("m_createFlexorWin.kDropoffDistance")) -min 0 -max 20 -pre 3 -step 0.1 dropoffFS; columnLayout -co "left" 20; optionMenuGrp -label (uiRes("m_createFlexorWin.kDropoffType")) -cc updateFlexorTypeCB sculptDropoffMenu; menuItem -label (uiRes("m_createFlexorWin.kNone")) ; menuItem -label (uiRes("m_createFlexorWin.kLinear")) ; setParent -m ..; optionMenuGrp -label (uiRes("m_createFlexorWin.kMode")) -cc updateFlexorTypeCB sculptModeMenu; menuItem -label (uiRes("m_createFlexorWin.kStretch")) ; menuItem -label (uiRes("m_createFlexorWin.kFlip")) ; menuItem -label (uiRes("m_createFlexorWin.kProject")) ; setParent -m ..; optionMenuGrp -label (uiRes("m_createFlexorWin.kInsideMode")) -cc updateFlexorTypeCB sculptInsideMenu; menuItem -label (uiRes("m_createFlexorWin.kRing")) ; menuItem -label (uiRes("m_createFlexorWin.kEven")) ; setParent -m ..; // ==================== LATTICE OPTIONS =================/ setParent flexorMainForm; frameLayout -label (uiRes("m_createFlexorWin.kLatticeOptions")) -lv true -li 0 -cll false -cl false -visible true latticeFrame; columnLayout -adj true -cw 100 cLayout2; intSliderGrp -field true -label (uiRes("m_createFlexorWin.kSDivisions")) -min 2 -max 20 -v 2 -step 1 sDiv; intSliderGrp -field true -label (uiRes("m_createFlexorWin.kTDivisions")) -min 2 -max 20 -v 5 tDiv; intSliderGrp -field true -label (uiRes("m_createFlexorWin.kUDivisions")) -min 2 -max 20 -v 2 uDiv; checkBoxGrp -v1 0 -label1 (uiRes("m_createFlexorWin.kPositionFlexor")) positionBox; // ==================== CLUSTER OPTIONS =================/ // // No options - just inform the user setParent flexorMainForm; frameLayout -label (uiRes("m_createFlexorWin.kClusterOptions")) -lv true -li 0 -cll false -cl false -visible false clusterFrame; formLayout textForm; text -label (uiRes("m_createFlexorWin.kNoOptions")) noOptionText; setParent ..; formLayout -e -af noOptionText left 80 -af noOptionText top 60 textForm; // ==================== CREATE and CLOSE Buttons =================/ setParent flexorMainForm; button -label (uiRes("m_createFlexorWin.kCreate")) -w 100 -c execFlexorCommand okayButton; button -label (uiRes("m_createFlexorWin.kClose")) -w 100 -c "deleteUI createFlexorDialog" closeButton; formLayout -e -af okayButton left 5 -an okayButton top -ap okayButton right 5 50 -af okayButton bottom 5 -ac closeButton left 5 okayButton -af closeButton right 5 -an closeButton top -af closeButton bottom 5 -ac latticeFrame top 5 flexorBoneFrame -af latticeFrame left 5 -af latticeFrame right 5 -ac latticeFrame bottom 5 okayButton -ac sculptFrame top 5 flexorBoneFrame -af sculptFrame left 5 -af sculptFrame right 5 -ac sculptFrame bottom 5 okayButton -ac clusterFrame top 5 flexorBoneFrame -af clusterFrame left 5 -af clusterFrame right 5 -ac clusterFrame bottom 5 okayButton flexorMainForm; updateFlexorTypeCB; setUITemplate -popTemplate; showWindow $winName; } // createFlexorWin //