// =========================================================================== // 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. // =========================================================================== // Procedure Name: // precisionPrompt // // Description Name; // Displays a modal dialog to get a decimal precision value // from the user. // // Input Value: // $parent - the window to parent the dialog to (empty if none) // $oldPrecision - the current value // $max - highest allowable value // // Output Value: // 0 = if user cancelled // > 0 - the new precision // global proc int precisionPrompt (string $parent, int $oldPrecision, int $max) { string $returnValue; string $precisionStr; int $newPrecision = 0; // Loop until an acceptable integer is entered into the // modal prompt dialog (won't accept text garbage) string $title = (uiRes("m_precisionPrompt.kChangePrecision")); string $message = (uiRes("m_precisionPrompt.kDecimalPlaces")); string $ok = (uiRes("m_precisionPrompt.kOK")); string $cancel = (uiRes("m_precisionPrompt.kCancel")); for (;;) { if ($parent == "") { $returnValue = `promptDialog -title $title -message $message -text $oldPrecision -button $ok -button $cancel -defaultButton $ok`; } else { $returnValue = `promptDialog -title $title -message $message -text $oldPrecision -button $ok -button $cancel -defaultButton $ok -parent $parent`; } if ($returnValue != $ok) break; $precisionStr = `promptDialog -q`; $newPrecision = (int) $precisionStr; // Determine if the number entered is within a reasonable bound int $isWithinBounds = $newPrecision >= 1 && $newPrecision <= $max; // Convert the string to an integer and back, and if the string // is still the same then the string entered must have been a // proper integer. Also, this way float values aren't accepted! if ($precisionStr == (string) $newPrecision && $isWithinBounds) { break; } else { string $errorMsg = (uiRes("m_precisionPrompt.kNotValidEntry")); string $errorDisp = `format -s $precisionStr -s $max $errorMsg`; catch( error( $errorDisp ) ); } } return $newPrecision; }