This example demonstrates working with the scale object for displaying and modifying its properties. This example uses a console menu that represents the following operations: getting and setting the temporary status [T], default status [S], paper units [U], drawing units [D], and scale name [N].
The example uses the following header files and functions implemented in examples:
#include "..\Common\DemoMain.h"
#include "DbScale.h"
#include <iostream>
using namespace std;
// Example of Using the Record–Table and Dictionary Interfaces for Getting Information about Objects
OdString AboutObjectKey(OdDbObject* pObject);
// Example of Entering Characters for String Objects
OdString EntryTextAs(enum enumCheckText = kArbitrary);
The PrintScaleProperties() function requires a pointer to an existing scale object and prints the listed properties of the passed scale. This function uses the scaleName() method for displaying the internal (display) name of the scale, paperUnits() method for displaying the value of paper units, drawingUnits() method for displaying the value of drawing units, scale() method for displaying the ratio of the paper units to the drawing units, and the isTempraryScale(), isUnitScale() methods for displaying the scale status.
The PrintScaleProperties() function has the following implementation:
void PrintScaleProperties(OdDbScale* pScale)
{
wcout << L"\nH=" << pScale->handle().ascii()
<< L"\n Scale Key = \"" << AboutObjectKey(pScale) << "\""
<< L"\n Scale Name = <" << pScale->scaleName() << L">"
<< L"\n Status: " << ((pScale->isErased()) ? L"erased" : L"unerased")
<< ((pScale->isDBRO()) ? L",resident" : L"")
<< ((pScale->isModified()) ? L",modified" : L"")
<< ((pScale->isTemporaryScale()) ? L",temporary" : L",fixed")
<< ((pScale->isUnitScale()) ? L",selected(1:1)" : L"")
<< L"\n Scale = " << pScale->scale()
<< L"\n Paper Units = " << pScale->paperUnits()
<< L"\n Drawing Units = " << pScale->drawingUnits();
}
The internal scale name differs from the external scale name being used in the scale dictionary for manipulating this scale. Therefore this example uses the AboutObjectKey() function that returns the key in the dictionary which is the external scale name for the specified scale object.
The ModifyScaleProperties() function requires a pointer to an existing scale object and implements the console menu for the listed operations. The function creates a loop that inquires about the operation code and uses the switch statement to select whether the case must be performed. The function uses the PrintScaleProperties() function for displaying the specific properties. The function processes user actions in the loop until the user selects [Q] operation.
When the user selects [P], the function displays the specific properties of the specified scale object using the PrintScaleProperties() function.
When the user selects [U], the function inquires about new paper units as a positive non-zero double value. If the entered value is incorrect or is negative, the function displays an error message and breaks to the console menu. If the entered value is correct, the function calls the setPaperUnits() method and passes to it the entered value to set the paper units. After setting, the function gets and displays the current value using the paperUnits() method.
When the user selects [D], the function inquires about new drawing units as a positive non-zero double value. If the entered value is incorrect or is negative, the function displays an error message and breaks to the console menu. If the entered value is correct, the function calls the setDrawingUnits() method and passes to it the entered value to set the drawing units. After setting, the function gets and displays the current value using the drawingUnits() method.
When the user selects [T], the function inquires about the new temporary status and prompts for the letter T-scale is temporary or F-scale is fixed. The function calls the setIsTemporaryScale() method and passes to it a True value if the user enters 'T' (temporary status) or a False value if the user enters 'F' (fixed status). After setting, the function checks and displays the current temporary status using the isTemporaryScale() method.
When the user selects [S], the function inquires about the new default status and prompts for the letter T-scale is selected (1:1) or F-scale is ordinary. The function calls the setIsUnitScale() method and passes to it a True value if the user enters 'T' (selected (1:1)) or a False value if the user enters 'F' (ordinary). After setting, the function checks and displays the current default status using the isUnitScale() method.
When the user selects [N], the function inquires about the new internal scale name as a wide-character string using the EntryTextAs() function and saves it in the declared variable as a OdString value. Then the function calls the setScaleName() method and passes to it the entered value to set the new scale name. To display the scale name, the function uses the scaleName() method. To display the current scale factor, the function uses the scale() method.
When the user selects [Q], the function ends the loop and returns to the calling function.
The ModifyScaleProperties() function has the following implementation:
void ModifyScaleProperties(OdDbScale* pScale)
{
wchar_t ch = L'\0';
double value;
OdString comment;
wcout << L"\nStart modifying of the scale properties";
do {
switch(ch)
{
case L'P': // Print the specific properties
case L'p':
PrintScaleProperties(pScale);
wcout << L"\n";
break;
case L'N': // Set the internal scale name
case L'n':
wcout << L"\nInternal name:>";
if((comment = EntryTextAs(kArbitrary)).isEmpty()) break;
pScale->setScaleName(comment);
break;
case L'T': // Set the Temporary status
case L't':
wcout << "\nEntry the Temporary status [T-scale is temporary|F-scale is fixed]:>";
wcin >> ch;
if(ch == L'T' || ch == L't') pScale->setIsTemporaryScale(true);
else if(ch == L'F' || ch == L'f') pScale->setIsTemporaryScale(false);
wcout << L"Status is set to: " << ((pScale->isTemporaryScale()) ? L"Temporary" : L"Fixed") << L"\n";
break;
case L'S': // Set the Default status
case L's':
wcout << "\nEntry the Default status [T-scale is selected(1:1)|F-scale is ordinary]:>";
wcin >> ch;
if(ch == L'T' || ch == L't') pScale->setIsUnitScale(true);
else if(ch == L'F' || ch == L'f') pScale->setIsUnitScale(false);
wcout << L"Status is set to: " << ((pScale->isUnitScale()) ? L"Selected(1:1)" : L"Ordinary") << L"\n";
break;
case L'D': // Set the drawing units
case L'd':
wcout << L"\nEntry a new drawing units factor [f > 0]:>";
wcin >> value;
if(!wcin.fail() && wcin.peek() == 10)
{
if(value > 0.0001)
{
pScale->setDrawingUnits(value);
wcout << L"Drawing units is set to: " << pScale->drawingUnits() << L"\n";
}
else wcout << L"Error: Drawing units must be a positive non-zero double value\n";
}
else { wcin.clear(); wcin.sync(); wcout << L"Error: Invalid entered value\n"; }
break;
case L'U': // Set the paper units
case L'u':
wcout << L"\nEntry a new paper units factor [f > 0]:>";
wcin >> value;
if(!wcin.fail() && wcin.peek() == 10)
{
if(value > 0.0001)
{
pScale->setPaperUnits(value);
wcout << L"Paper units is set to: " << pScale->paperUnits() << L"\n";
}
else wcout << L"Error: Paper units must be a positive non-zero double value\n";
}
else { wcin.clear(); wcin.sync(); wcout << L"Error: Invalid entered value\n"; }
break;
case L'\0': // Skip an action
break;
default:
wcout << L"Error: Incorrect operation\n";
}
wcout << L"\nSelected scale: \"" << GetScaleKey(pScale)
<< L"\"-<" << pScale->scaleName() << L"> = " << pScale->scale();
wcout << L"\nN. Set the Scale Name";
wcout << L"\nU. Set the Paper Units";
wcout << L"\nD. Set the Drawing Units";
wcout << L"\nS. Set the Default status";
wcout << L"\nT. Set the Temporary status";
wcout << L"\nP. Print the specific properties";
wcout << L"\nQ. Quit";
wcout << L"\nSelect operation:>";
wcin >> ch;
}
while(ch != L'Q' && ch != L'q');
wcout << L"Stop modifying of the scale properties\n";
}
Testing gives the following results:
Start modifying of the scale properties
Selected scale: "Z0"-<> = 1
N. Set the Scale Name
U. Set the Paper Units
D. Set the Drawing Units
S. Set the Default status
T. Set the Temporary status
P. Print the specific properties
Q. Quit
Select operation:>
When the operation is P-"Print the specific properties":
H=62
Scale Key = "Z0"
Scale Name = <>
Status: unerased,resident,temporary
Scale = 1
Paper Units = 1
Drawing Units = 1
When the operation is N-"Set the Scale Name":
Entry a new scale name:>3:8
Selected scale: "Z0"-<3:8> = 1
When the operation is U-"Set the Paper Units":
Entry a new paper units factor [f > 0]:>3.0
Paper units is set to: 3
Selected scale: "Z0"-<3:8> = 3
When the operation is U-"Set the Paper Units" and a value is incorrect:
Entry a new paper units factor [f > 0]:>-3
Error: Paper units must be a positive non-zero double value
Selected scale: "Z0"-<3:8> = 3
When the operation is D-"Set the Drawing Units":
Entry a new drawing units factor [f > 0]:>8.0
Drawing units is set to: 8
Selected scale: "Z0"-<3:8> = 0.375
When the operation is D-"Set the Drawing Units" and a value is incorrect:
Entry a new drawing units factor [f > 0]:>-8
Error: Drawing units must be a positive non-zero double value
Selected scale: "Z0"-<3:8> = 0.375
When the operation is T-"Set the Temporary status":
Entry the Temporary status [T-scale is temporary|F-scale is fixed]:>F
Status is set to: Fixed
When the operation is S-"Set the Default status":
Entry the Default status [T-scale is selected(1:1)|F-scale is ordinary]:>F
Status is set to: Ordinary
After entry, the operation P-"Print the specific properties" displays:
H=62
Scale Key = "Z0"
Scale Name = <3:8>
Status: unerased,resident,modified,fixed
Scale = 0.375
Paper Units = 3
Drawing Units = 8
Use the Q-"Quit" operation to exit:
Stop modifying of the scale properties
Example of Working with the Scale Dictionary Object
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|