Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Example of Working with the Linetype Record Object

This example demonstrates working with the linetype record object for displaying and modifying its properties. This example uses a console menu for getting and setting the following: scaling status [F], pattern length [L], description [D], number of dashes [N], and modification of each dash of the linetype pattern [M].

The example uses the following header files, examples, and implemented functions:


#include "..\Common\DemoMain.h"
#include "DbLinetypeTable.h"
#include "DbLinetypeTableRecord.h"
#include <iostream>
using namespace std;

// Example of Working with the Linetype Dash
void PrintLTDash(OdDbLinetypeTableRecord* pLinetype, OdInt16 index);
void ModifyLTDash(OdDbLinetypeTableRecord* pLinetype, OdInt16 index);

// Example of Entering for String Objects
OdString EntryTextAs(enum enumCheckText = kArbitrary);

The PrintLinetypeProperties() function displays the listed properties of the specified linetype and requires a pointer to an existing linetype record object. This function uses the comments() method for displaying a description, patternLength() method for displaying a pattern length, numDashes() method for displaying the number of dashes, and the PrintLTDash() function for displaying the specific properties of each dash of the pattern.

The PrintLinetypeProperties() function has the following implementation:


void PrintLinetypeProperties(OdDbLinetypeTableRecord* pLinetype)
{
  wcout << L"\nH=" << pLinetype->handle().ascii() 
        << L"\n  Name = \"" << pLinetype->getName() << L"\"" 
        << L"\n  Status: " << ((pLinetype->isErased()) ? L"erased" : L"unerased")
                           << ((pLinetype->isDBRO()) ? L",resident" : L"")
                           << ((pLinetype->isModified()) ? L",modified" : L"")
                           << ((pLinetype->isDependent()) ? L",XRef-dependent" : L"")
                           << ((pLinetype->isScaledToFit()) ? L",scaled" : L"")
        << L"\n  Description: \"" << pLinetype->comments() << L"\""
        << L"\n  Pattern length = " << pLinetype->patternLength()
        << L"\n  Number of dashes = " << pLinetype->numDashes();

  for(int index = 0 ; index < pLinetype->numDashes() ; index++)
    PrintLTDash(pLinetype, index);
}

The ModifyLinetypeProperties() function requires a pointer to an existing linetype record object and implements a console menu for the listed operations. The function creates a loop that inquires about the operation and uses the switch statement to select whether the case must be performed. The function uses the PrintLinetypeProperties() function for displaying the specific properties and ModifyLTDash() function for modifying the properties of the selected dash of the pattern. The ModifyLTDash() function requires a pointer to an existing linetype record object, requires the index of a dash as an Integer value, and does not return a value. The ModifyLinetypeProperties() function processes user actions in the loop until the user selects the [Q] operation.

When the user selects [P], the function displays the specific properties of the specified linetype record object using the PrintLinetypeProperties() function.

When the user selects [D], the function inquires about the new description string using the getline() method and the comment variable declared as a wide-char buffer. Then the function calls the setComments() method and passes to it the entered value to set the new comments for the linetype.

When the user selects [F], the function inquires about the new scaling status and prompts: S-Set scale to fit status or C-Clear status. The function calls the setIsScaledToFit() method and passes to it a True value if the user enters the 'S' letter (status is set) or a False value if the user enters the 'C' letter (status is cleared). After setting, the function checks and displays the current scaling status using the isScaledToFit() method.

When the user selects [L], the function displays the current pattern length using the patternLength() method and inquires about the new length as a positive double value. If an entered value is incorrect or is negative, the function displays an error message and breaks to the console menu. If an entered value is correct, the function calls the setPatternLength() method and passes to it the entered value to set the new length for the linetype.

When the user selects [N], the function displays the current number of dashes using the numDashes() method and inquires about the new number as a positive integer value. If an entered value is incorrect or is negative, the function displays an error message and breaks to the console menu. If an entered value is correct, the function calls the setNumDashes() method and passes to it the entered value to set the new number of dashes for the linetype. If the new value is greater than than old value, the setNumDashes() method adds the new dashes to the end of the pattern and fills their properties using default values. If the new value is less than the old value, the setNumDashes() method deletes existing dashes from the end of the pattern. If the new value is zero, the setNumDashes() method clears the pattern and makes it a solid line. The number of dashes cannot be one.

When the user selects [M], the function inquires about the index of an existing dash to be modified. If the entered index is incorrect or is out of the scope, the function displays an error message and breaks to the console menu. If the entered index is correct, the function calls the ModifyLTDash() function which organizes its own console menu for modifying the specific properties of the specified dash for the linetype record object.

When the user selects [Q], the function ends the loop and returns in the calling function.

The ModifyLinetypeProperties() function has the following implementation:


void ModifyLinetypeProperties(OdDbLinetypeTableRecord* pLinetype)
{
  wchar_t ch = L'\0';
  OdInt16 number, index;
  OdString comment;
  double value;

  wcout << L"\nStart modifying of the linetype properties";    
  do {
    switch(ch)
    {
      case L'P':          // Print the specific properties
      case L'p':
        PrintLinetypeProperties(pLinetype);
        wcout << L"\n";
        break;


      case L'D':          // Set the description
      case L'd':
        wcout << L"\nDescription:>";

        if((comment = EntryTextAs(kArbitrary)).isEmpty()) break;

        pLinetype->setComments(comment);
        wcout << L"Description is set to: \"" << pLinetype->comments() << L"\"\n";
        break;


      case L'F':          // Set the scaling status
      case L'f':
        wcout << L"\nEntry the scaling status [S-Set scale to fit status|C-Clear status]:>";
        wcin >> ch;

        if(ch == L'S' || ch == L's') pLinetype->setIsScaledToFit(true);
        else if(ch == L'C' || ch == L'c') pLinetype->setIsScaledToFit(false);

        wcout << L"Status is set to: " << ((pLinetype->isScaledToFit()) ? L"Scaled" : L"NonScaled") << L"\n";
        break;


      case L'L':          // Set the pattern length
      case L'l':
        wcout << L"\nPattern length = " << pLinetype->patternLength()
              << L"\nEntry a new length:>";
        wcin >> value;
        
        if(!wcin.fail() && wcin.peek() == 10)
        {
          if(value >= 0)
          {
            pLinetype->setPatternLength(value);
            wcout << L"Pattern length is set to: " << pLinetype->patternLength() << L"\n";
          }
          else wcout << L"Error: Pattern length must be a positive double value\n";
        }
        else { wcin.clear();  wcin.sync();  wcout << L"Error: Invalid entered value\n"; }
        break;


      case L'N':          // Set the number of dashes
      case L'n':
        wcout << L"\nNumber of dashes = " << pLinetype->numDashes() 
              << L"\nEntry a new number:>";
        wcin >> number;
        
        if(!wcin.fail() && wcin.peek() == 10)
        {
          if(number >= 0)
          {
            pLinetype->setNumDashes(number);
            wcout << L"Number of dashes is set to: " << pLinetype->numDashes() << L"\n";
          }
          else wcout << L"Error: Number of dashes must be a positive integer value\n";
        }
        else { wcin.clear();  wcin.sync();  wcout << L"Error: Invalid entered value\n"; }
        break;


      case L'M':          // Modify the selected dash
      case L'm':
        number = pLinetype->numDashes()-1;
        wcout << L"\nEntry the dash index [0..." << number << "] to be modified:>";
        wcin >> index;
        
        if(index >= 0 && index <= number) ModifyLTDash(pLinetype, index);
        
        else wcout << L"Error: Incorrect dash index\n";
        break;


      case L'\0':         // Skip an action
        break;

      default:
        wcout << L"Incorrect operation\n";
    }
    wcout << L"\nSelected linetype: \"" << pLinetype->getName() << L"\"";
    wcout << L"\nP. Print the specific properties";
    wcout << L"\nD. Set the description";
    wcout << L"\nF. Set the scaling status";
    wcout << L"\nL. Set the pattern length";
    wcout << L"\nN. Set the number of dashes";
    wcout << L"\nM. Modify the selected dash";
    wcout << L"\nQ. Quit";
    wcout << L"\nSelect operation:>";
    wcin >> ch;
  }
  while(ch != L'Q' && ch != L'q');

  wcout << L"Stop modifying of the linetype properties\n";
}

Testing gives the following results:


Start modifying of the linetype properties

Selected linetype: "GAS-Line"
P. Print the specific properties
D. Set the description
F. Set the scaling status
L. Set the pattern length
N. Set the number of dashes
M. Modify the selected dash
Q. Quit
Select operation:>

When the operation is P-"Print the specific properties":


H=3F
  Name = "GAS-Line"
  Status: unerased,resident
  Description: ""
  Pattern length = 0
  Number of dashes = 0

When the operation is D-"Set the description":


Description:>--- GAS --- GAS ---
Description is set to: "--- GAS --- GAS ---"

When the operation is F-"Set the scaling status":


Entry the scaling status [S-Set scale to fit status|C-Clear status]:>S
Status is set to: Scaled

When the operation is L-"Set the pattern length":


Pattern length = 0
Entry a new length:>2.5
Pattern length is set to: 2.5

When the operation is L-"Set the pattern length" and a value is incorrect:


Pattern length = 2.5
Entry a new length:>-0.5
Error: Pattern length must be a positive double value

When the operation is N-"Set the number of dashes":


Number of dashes = 0
Entry a new number:>2
Number of dashes is set to: 2

When the operation is N-"Set the number of dashes" and a value is incorrect:


Number of dashes = 2
Entry a new number:>-2
Error: Number of dashes must be a positive integer value

When the operation is M-"Modify the selected linetype":


Entry the dash index [0...1] to be modified:>1

Start modifying of the dash properties
Selected dash (1) Linetype "GAS-Line"
L. Set the length
O. Set the offset
F. Set the scale factor
A. Set the rotation angle
T. Set the text inclusion
I. Set the shape inclusion
S. Set the inclusion style
U. Set the UCS orientation
R. Set the Upright orientation
P. Print the specific properties
Q. Quit
Select operation:>L

Current dash length = 0
Entry a new length:>-0.5
Dash (1) Length is set to: -0.5

Select operation:>T

Current text =
Entry a new string:>GAS
Dash (1) Text is set to: "GAS" (Shape = 0)

Select operation:>S

Select the TextStyle object:
11-"Standard"
Current: [Db:kNull]
Entry the name to be selected (or [?]-null/[:]-quit):>standard
Dash (1) Style is set to: [11-"Standard"-TextStyle]

Select operation:>Q
Stop modifying of the dash properties

After entry, the operation P-"Print the specific properties" displays:


H=3F
  Name = "GAS-Line"
  Status: unerased,resident,modified,scaled
  Description: "--- GAS --- GAS ---"
  Pattern length = 2.5
  Number of dashes = 2
  Dash (0) relative,inline, Style=[Db:kNull], Shape=0, Text=""
  Length=0, Scale=0, Angle=0, Offset=(0,0)
  Dash (1) relative,inline, Style=[11-"Standard"-TextStyle], Shape=0, Text="GAS"
  Length=-0.5, Scale=0, Angle=0, Offset=(0,0)

Use the Q-"Quit" operation to exit:


Stop modifying of the linetype properties

See Also

Working with Linetypes

Specific Properties of Linetypes

Example of Working with the Linetype Dash

Example of Working with the Linetype Table Object

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.