This example demonstrates displaying and modifying the helix constrain type. The constrain type defines the behavior of the spiral curve when the Total Height, Turn Height, or Turns properties are changed.
The AboutHelixConstrain() function requires a value of the OdDbHelix::ConstrainType enumerator and returns a string containing the comment about the passed helix constrain type as an OdString value. The functions declare a variable of the OdString type and use the format() method to convert the type number. Then this function checks the passed type using the switch statement to select the comment which must be attached to the resulting string.
The AboutHelixConstrain() function has the following implementation:
OdString AboutHelixConstrain(OdDbHelix::ConstrainType type)
{
OdString sAbout;
sAbout.format(L"[%d-", type);
switch(type)
{
case OdDbHelix::kTurnHeight: sAbout += L"TurnHeight"; break;
case OdDbHelix::kTurns: sAbout += L"Revolutions"; break;
case OdDbHelix::kHeight: sAbout += L"TotalHeight"; break;
default: sAbout += L"?";
}
return (sAbout += L"]");
}
The EntryHelixConstrain() function requires a reference to a variable of a 16-bit Integer type in which the selected helix constrain type must be saved as an argument; the function returns True if the user selects a type or False if the user cancels entry. The function organizes a loop that displays the list of available constrain types, and then, inquires about the number as an Integer value. The constrain type can take the following values: 0-kTurnHeight (Turn Height), 1-kTurns (Revolutions), 2-kHeight (Total Height). After entry, the function checks whether the value is in the range [0 to 2]. If the entry is incorrect or out of range, the function displays an error message and repeats the loop. If the entry is correct, the function returns True and returns the selected type number through the argument in the calling function. If the user selects [3] or [6], the function cancels entry and returns False as a resulting value.
The EntryHelixConstrain() function has the following implementation:
bool EntryHelixConstrain(OdInt16& refType)
{
OdInt16 type;
do {
wcout << L"\n0. Turn Height"
<< L"\n1. Revolutions"
<< L"\n2. Total Height"
<< L"\n3. Quit"
<< L"\nEntry the constrain:>";
wcin >> type;
if(!wcin.fail() && wcin.peek() == 10)
if(type >= 0 && type <= 2)
{
refType = type;
return true;
}
else if(type == 3) return false;
else wcout << L"Error: Undefined constrain type\n";
else { wcin.clear(); wcout << L"Error: Invalid entered value\n"; wcin.sync(); }
}
while(1);
}
The testing function has the following implementation:
void DemoBase(OdDbDatabase* pDb)
{
OdInt16 type;
EntryHelixConstrain(type);
wcout << L"Constrain type = " << AboutHelixConstrain((OdDbHelix::ConstrainType) type);
}
Testing gives the following results:
0. Turn Height
1. Revolutions
2. Total Height
3. Quit
Entry the constrain:>1
Constrain type is set to: [1-Revolutions]
Example of Working with the Helix Object
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|