// =========================================================================== // 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: August, 1998 // // Description: // // // global proc int isValidAttribute(string $nodeName, string $attrName) { // If the attribute doesn't exist, warn the user and return. // I can only do this if there is an object name. // if (size($nodeName) > 0) { if (!`attributeQuery -exists -node $nodeName $attrName`) { string $fmt = (uiRes("m_AEspringEditComponent.kAttrInexistant")); warning( `format -s $attrName -s $nodeName $fmt` ); return 0; } } // If the attribute is not one the component editor can edit, warn // the user. if (($attrName == "restLengthPS") || ($attrName == "stiffnessPS") || ($attrName == "dampingPS")) { return 1; } else { string $fmt = (uiRes("m_AEspringEditComponent.kCannotEditAttr")); warning( `format -s $attrName -s $nodeName $fmt` ); return 0; } } // ========== sEditCompSetAttrCB ========== // // Description: // User has selected the "Set Attribute" in the Edit Component // dialog; so set the selected attribute with the correct values. // global proc sEditCompSetAttrCB(string $nodeName, string $attrName) { string $cmd, $useCmd; if (size($attrName) == 0) { warning( (uiRes("m_AEspringEditComponent.kNoValidSelection")) ); return; } if (isValidAttribute($nodeName, $attrName)) { float $value = `floatSliderGrp -q -v springsComponentVal`; int $editMode = `radioButtonGrp -q -sl sEditCompRB`; if ($attrName == "restLengthPS") $useCmd = "spring -e -useRestLengthPS true "; else if ($attrName == "stiffnessPS") $useCmd = "spring -e -useStiffnessPS true "; else if ($attrName == "dampingPS") $useCmd = "spring -e -useDampingPS true "; // If the user is in "edit components" mode, don't send the // nodeName so the selected components will be edited, rather // than the user having to both select the components and select // the correct node name in the editor. // if ($editMode == 2) $useCmd = $useCmd + $nodeName; $cmd = "spring -e -" + $attrName + " " + $value; if ($editMode == 2) $cmd = $cmd + " " + $nodeName; evalEcho $useCmd; evalEcho $cmd; // Update the average values. // sEditCompGetAttrCB($nodeName, $attrName); } } // sEditCompSetAttrCB // ========== sEditCompGetAttrCB ========== // // Description: // User has selected the "Get Attribute" in the Edit Component // dialog; so get the value of the selected attribute, if only // one spring is selected. // global proc sEditCompGetAttrCB(string $nodeName, string $attrName) { global string $dynSpringSaveParent; int $editMode = `radioButtonGrp -q -sl sEditCompRB`; if ($editMode == 2) $cmd = "spring -q -" + $attrName + " " + $nodeName; else { // If in component edit mode, query only if a component is // selected. // string $selected[] = `ls -sl`; if (size($selected)) $cmd = "spring -q -" + $attrName; } float $averageValue = eval($cmd); floatField -e -v $averageValue springsAverageComponentVal; } // sEditCompGetAttrCB // ========== sEditCompSelectTypeCB ========== // // Description: // User has changed the selection method (object, selected comps). // If editing whole object, enable the object name textfield. // If editing selected components, disable and empty it. // global proc sEditCompSelectTypeCB(string $nodeName, string $attrName, int $editType) { global string $dynSpringSaveParent; textFieldGrp -e -text $nodeName sEditCompObjTF; if ($editType == 2) { textFieldGrp -e -enable true sEditCompObjTF; } else { textFieldGrp -e -enable false sEditCompObjTF; textFieldGrp -e -text "" sEditCompObjTF; } } // sEditCompSelectTypeCB // ========== sEditCompAttrNameCB ========== // // Description: // User has changed the attribute name. // Get the values for the new attribute, and reset appropriate // callbacks. // global proc sEditCompAttrNameCB( string $attrName ) { global string $dynSpringSaveParent; string $nodeName; int $editMode = `radioButtonGrp -q -sl sEditCompRB`; // editMode == 2 means in object mode, so use the object name in the // textfield. editMode != 2 means in component mode, so use the // selection list and get the object name. Only one object can be // edited at a time. // if ($editMode == 2) { $nodeName = `textFieldGrp -q -text sEditCompObjTF`; } else { string $selected[] = `ls -sl -o`; if (size($selected) == 1) $nodeName = $selected[0]; else if (size($selected) == 0) warning( (uiRes("m_AEspringEditComponent.kSelectOneObject")) ); else warning( (uiRes("m_AEspringEditComponent.kSelectOnlyOneObject")) ); } if (!isValidAttribute($nodeName, $attrName)) { radioButtonGrp -e -en 0 sEditCompRB; return; } radioButtonGrp -e -en 1 sEditCompRB; button -e -c ("sEditCompSetAttrCB " +$nodeName+" " +$attrName) sEditCompSetAttrBtn; button -e -c ("sEditCompGetAttrCB " +$nodeName+" " +$attrName) sEditCompGetAttrBtn; if (size($nodeName) == 0) $nodeName = " "; sEditCompGetAttrCB($nodeName, $attrName); } // sEditCompAttrNameCB // ========== sEditCompObjNameCB ========== // // Description: // User has changed the object name. // Get the values for the new object, and reset appropriate // callbacks. // global proc sEditCompObjNameCB( string $nodeName ) { global string $dynSpringSaveParent; // Get the name of the current attribute in the textfield. // string $attrName = `textFieldGrp -q -text sEditCompAttrTF`; // Make sure the node exists // if (`objExists $nodeName`) { // enable all the devices in case a wrong nodeName was entered // textFieldGrp -e -en 1 sEditCompAttrTF; radioButtonGrp -e -en 1 sEditCompRB; button -e -c ("sEditCompSetAttrCB " +$nodeName+" " +$attrName) sEditCompSetAttrBtn; button -e -c ("sEditCompGetAttrCB " +$nodeName+" " +$attrName) sEditCompGetAttrBtn; sEditCompGetAttrCB($nodeName, $attrName); } else { // Disable all the widgets because an invalid node was // entered. // textFieldGrp -e -en 0 sEditCompAttrTF; radioButtonGrp -e -en 0 sEditCompRB; string $fmt = (uiRes("m_AEspringEditComponent.kNodeInexistant")); warning( `format -s $nodeName $fmt` ); return; } } // sEditCompObjNameCB // ========== AEspringEditComponent ========== // // Description: // Bring up the Edit Component dialog. // global proc AEspringEditComponent ( string $nodeName, string $attrName) { setUITemplate -pst attributeEditorTemplate; global float $gDynMaxFloatField; global float $gDynMinFloatField; string $buffer[]; tokenize($nodeName, "|", $buffer); $nodeName = $buffer[size($buffer) - 1]; if (!`window -exists "sEditCompWin"`) { window -title (uiRes("m_AEspringEditComponent.kSpringComponents")) -rtf false -wh 460 220 sEditCompWin; setUITemplate -pst attributeEditorTemplate; // Setup the main look of the window // // Create the base form. // formLayout -nd 100 sEditCompBaseForm; // Create the column layout that will hold the value sliders. // columnLayout -adj false sEditCompCL; setParent ..; // Create the form for the buttons at the bottom of the window. // formLayout -nd 100 sEditCompBtnsForm; button -label (uiRes("m_AEspringEditComponent.kSetAttribute")) -c ("sEditCompSetAttrCB " +$nodeName+" " +$attrName) sEditCompSetAttrBtn; button -label (uiRes("m_AEspringEditComponent.kGetAttribute")) -c ("sEditCompGetAttrCB " +$nodeName+" " +$attrName) sEditCompGetAttrBtn; button -label (uiRes("m_AEspringEditComponent.kClose")) -c ("window -e -vis 0 sEditCompWin") sEditCompWinCloseButton; formLayout -e -af sEditCompSetAttrBtn top 2 -ap sEditCompSetAttrBtn left 0 2 -ap sEditCompSetAttrBtn right 0 32 -af sEditCompSetAttrBtn bottom 5 -af sEditCompGetAttrBtn top 2 -ap sEditCompGetAttrBtn left 0 34 -ap sEditCompGetAttrBtn right 0 66 -af sEditCompGetAttrBtn bottom 5 -af sEditCompWinCloseButton top 2 -ap sEditCompWinCloseButton left 0 68 -ap sEditCompWinCloseButton right 0 98 -af sEditCompWinCloseButton bottom 5 sEditCompBtnsForm; setParent ..; separator -hr true -h 20 sEditCompWinSeparator; // Set the parent back up the the base form. // setParent sEditCompBaseForm; formLayout -e -af sEditCompCL top 4 -af sEditCompCL right 0 -af sEditCompCL left 0 -an sEditCompCL bottom -ac sEditCompWinSeparator top 4 sEditCompCL -af sEditCompWinSeparator left 0 -af sEditCompWinSeparator right 0 -an sEditCompWinSeparator bottom -ac sEditCompBtnsForm top 4 sEditCompWinSeparator -af sEditCompBtnsForm left 0 -af sEditCompBtnsForm right 0 -an sEditCompBtnsForm bottom sEditCompBaseForm; // start building the widgets // setParent sEditCompCL; textFieldGrp -label (uiRes("m_AEspringEditComponent.kObjectName")) -text $nodeName -cc ("sEditCompObjNameCB #1") sEditCompObjTF; textFieldGrp -label (uiRes("m_AEspringEditComponent.kAttributeName")) -text $attrName -cc ("sEditCompAttrNameCB #1") sEditCompAttrTF; radioButtonGrp -label (uiRes("m_AEspringEditComponent.kEdit")) -nrb 2 -label2 (uiRes("m_AEspringEditComponent.kEntireObject")) -label1 (uiRes("m_AEspringEditComponent.kSelectedComponents")) -cc2 ("sEditCompSelectTypeCB " +$nodeName+" " +$attrName+" 2") -cc1 ("sEditCompSelectTypeCB " +$nodeName+" " +$attrName+" 1") sEditCompRB; // Select the "Selected Components" radio button. // radioButtonGrp -e -select 1 sEditCompRB; // create the widgets for the componentvalues // floatSliderGrp -label (uiRes("m_AEspringEditComponent.kNewAttributeValue")) -field true -min -10 -max 10 -fmn $gDynMinFloatField -fmx $gDynMaxFloatField -pre 3 -step 0.1 springsComponentVal; rowLayout -nc 2 -cat 1 right 5 -cat 2 both 0 -cw 2 80 springsAvCompRow; text -label (uiRes("m_AEspringEditComponent.kComponentAverageValue")) ; floatField -ed false -pre 3 springsAverageComponentVal; setParent sEditCompBaseForm; setUITemplate -ppt; } else { setParent sEditCompBaseForm; // setParent sEditCompCL; textFieldGrp -e -text $nodeName sEditCompObjTF; textFieldGrp -e -text $attrName sEditCompAttrTF; button -e -c ("sEditCompSetAttrCB " +$nodeName+" " +$attrName) sEditCompSetAttrBtn; button -e -c ("sEditCompGetAttrCB " +$nodeName+" " +$attrName) sEditCompGetAttrBtn; // make sure everything is enabled when a new attribute // is selected from the attribute editor // // textFieldGrp -e -en 1 sEditCompObjTF; textFieldGrp -e -en 1 sEditCompAttrTF; radioButtonGrp -e -en 1 sEditCompRB; int $RBselected = `radioButtonGrp -q -sl sEditCompRB`; sEditCompSelectTypeCB $nodeName $attrName $RBselected; } floatSliderGrp -e -v 0.0 springsComponentVal; floatField -e -v 0.0 springsAverageComponentVal; radioButtonGrp -e -cc2 ("sEditCompSelectTypeCB " +$nodeName+" " +$attrName+" " +" 2") -cc1 ("sEditCompSelectTypeCB " +$nodeName+" " +$attrName+" " +" 1") sEditCompRB; sEditCompGetAttrCB($nodeName, $attrName); int $RBselected = `radioButtonGrp -q -sl sEditCompRB`; sEditCompSelectTypeCB $nodeName $attrName $RBselected; setUITemplate -ppt; showWindow sEditCompWin; } // AEspringEditComponent