Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Example of Working with the Linetype Dash

This example demonstrates working with linetype dashes and displaying and modifying their properties. This example uses a console menu with operations for getting and setting the following: dash length [L], offset [O], scale factor [F], rotation angle [A], UCS orientation [U], upright orientation [R], text inclusion [T], shape inclusion [I], and inclusion style [S].

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


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

// Example of Entering and Displaying 2D Vector Objects
bool EntryVector2d(OdGeVector2d& vector);
OdString AboutVector2d(const OdGeVector2d& vector);

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

// Example of Using the Record–Table and Dictionary Interfaces for Getting Information about Objects
OdString AboutDbObject(OdDbObjectId idObject);

// Example of Using the Record–Table Interface for Selecting Objects
OdDbObjectId EntryTableRecordObject(OdDbObjectId idTable, OdDbObjectId idRecord = OdDbObjectId::kNull);

The PrintLTDash() function displays the listed properties of the specified dash and requires a pointer to an existing linetype record object and index of the dash. This function uses the dashLengthAt() method for displaying a dash length, shapeOffsetAt() method and AboutVector2d() function for displaying an offset, shapeScaleAt() method for displaying a scale factor, shapeRotationAt() method for displaying a rotation angle, textAt() method for displaying a text inclusion, shapeNumberAt() method for displaying a shape inclusion, shapeStyleAt() method and AboutDbObject() function for displaying a text style of the inclusion, and shapeIsUcsOrientedAt() method for displaying a UCS orientation. The listed methods require the dash index as an argument.

The PrintLTDash() function has the following implementation:


void PrintLTDash(OdDbLinetypeTableRecord* pLinetype, OdInt16 index)
{
  wcout << L"\n  Dash (" << index << L") " 
        << ((pLinetype->shapeIsUcsOrientedAt(index)) ? L"absolute" : L"relative")
        << ((pLinetype->shapeIsUprightAt(index)) ? L",upright" : L",inline")
        << L", Style=" << AboutDbObject(pLinetype->shapeStyleAt(index))
        << L", Shape=" << pLinetype->shapeNumberAt(index)
        << L", Text=\"" << pLinetype->textAt(index) << L"\""
        << L"\n  Length=" << pLinetype->dashLengthAt(index)
        << L", Scale=" << pLinetype->shapeScaleAt(index)
        << L", Angle=" << pLinetype->shapeRotationAt(index)
        << L", Offset=" << AboutVector2d(pLinetype->shapeOffsetAt(index));
}

The ModifyLTDash() function requires a pointer to an existing linetype record object, requires the index of the dash to be modified as arguments, and implements the 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 PrintLTDash() function for displaying the specific properties of the specified dash, AboutVector2d() function for displaying coordinates of a two-dimensional vector, and AboutTableRecordObject() function for displaying information about the text style record object associated with the dash. The ModifyLTDash() 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 dash using the PrintLTDash() function.

When the user selects [L], the function displays the current dash length using the dashLengthAt() method and inquires about a new length as a double value. If an entered value is incorrect, the function displays an error message and breaks to the console menu. If an entered value is correct, the function calls the setDashLengthAt() method and passes to it the dash index and entered value as arguments to set the new length for the dash. If a length value is positive, the dash is drawn. If a length value is negative, the dash is not drawn. If the length value is zero, the dash is a point.

When the user selects [T], the function displays the current text inclusion using the textAt() method and inquires about a new text as a string value. If the entered value is correct, the function calls the setTextAt() method and passes to it the dash index and entered value to set the text as an inclusion of the dash.

When the user selects [I], the function displays the current code of the shape inclusion using the shapeNumberAt() method and inquires about a new code as an integer value. If an entered value is correct, the function calls the setShapeNumberAt() method and passes to it the dash index and entered code to set the shape as an inclusion of the dash.

When the user selects [O], the function gets the current dash offset using the shapeOffsetAt() method and calls the EntryVector2d() function for entering coordinates. The EntryVector2d() function requires a reference to the two-dimensional vector instance of the OdDbVector2d type to be modified. This function returns True and passes the two-dimensional vector with new coordinates specified by the user through argument, or returns False if the user cancels entry. After entry, the ModifyLTDash() function calls the setShapeOffsetAt() method and passes to it the dash index and returned vector to set the new offset for the dash inclusion.

When the user selects [F], the function displays the current scale factor using the shapeScaleAt() method and inquires about a new scale factor 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 setShapeScaleAt() method and passes to it the dash index and entered value to set the new scale factor for the dash inclusion.

When the user selects [A], the function displays the current rotation angle using the shapeRotationAt() method and inquires about a new angle as a double value in the range 0 to 360 degrees. If an entered value is incorrect, the function displays an error message and breaks to the console menu. If an entered value is correct, the function calls the setShapeRotationAt() method and passes to it the dash index and entered value to set the rotation angle for the dash inclusion.

When the user selects [U] or [R], the function inquires about a new UCS or Upright orientation flag and prompts: S-set flag or C-clear flag. The function calls the setShapeIsUcsOrientedAt() or setShapeIsUprightAt() method and passes to it the dash index and either 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 UCS or Upright orientation using the shapeIsUcsOrientedAt() or shapeIsUprightAt() method.

When the user selects [S], the function gets the Object ID of the current text style assigned to the dash inclusion using the shapeStyleAt() method and calls the EntryTableRecordObject() function for selecting a text style. The EntryTableRecordObject() function requires the Object ID of the text style table object and text style record object as arguments and returns the Object ID of the text style specified by the user or the same Object ID when the user cancels entry. To get the text style table, the ModifyLTDash() function uses the getTextStyleTableId() method of the database object which the database() method returns. The EntryTableRecordObject() function organizes its own console menu for selecting the text style. After selection, the ModifyLTDash() function calls the setShapeStyleAt() method and passes to it the dash index and returned Object ID to set the new text style for the dash inclusion.

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

The ModifyLTDash() function has the following implementation:


void ModifyLTDash(OdDbLinetypeTableRecord* pLinetype, OdInt16 index)
{
  wchar_t ch = L'\0';
  double value;
  OdInt16 number;
  OdString txtstr;
  OdGeVector2d offset;

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


      case L'L':          // Set the length
      case L'l':
        wcout << L"\nCurrent dash length = " << pLinetype->dashLengthAt(index)
              << L"\nEntry a new length:>";
        wcin >> value;

        if(!wcin.fail() && wcin.peek() == 10)
        {
          pLinetype->setDashLengthAt(index, value);

          wcout << L"Dash (" << index << L") Length is set to: " 
                << pLinetype->dashLengthAt(index) << L"\n";
        }
        else { wcin.clear();  wcin.sync();  wcout << L"Error: Invalid entered value\n"; }
        break;


      case L'O':          // Set the offset
      case L'o':
        wcout << L"Entry the offset";
        offset = pLinetype->shapeOffsetAt(index);
        
        if(EntryVector2d(offset))
        {
          pLinetype->setShapeOffsetAt(index, offset);
          wcout << L"Dash (" << index << L") Offset is set to: " 
                << AboutVector2d(pLinetype->shapeOffsetAt(index)) << L"\n";
        }
        break;


      case L'F':          // Set the scale factor
      case L'f':
        wcout << L"\nCurrent scale factor = " << pLinetype->shapeScaleAt(index)
              << L"\nEntry a new scale factor [f>0]:>";
        wcin >> value;

        if(!wcin.fail() && wcin.peek() == 10)
        {
          if(value >= 0)
          {
            pLinetype->setShapeScaleAt(index, value);

            wcout << L"Dash (" << index << L") Scale Factor is set to: " 
                  << pLinetype->shapeScaleAt(index) << L"\n";
          }
          else wcout << L"Error: Scale Factor must be a positive double value\n";
        }
        else { wcin.clear();  wcin.sync();  wcout << L"Error: Invalid entered value\n"; }
        break;


      case L'A':          // Set the rotation angle
      case L'a':
        wcout << L"\nCurrent rotation angle = " << pLinetype->shapeRotationAt(index) << L" radians"
              << L"\nEntry a new angle [0...2Pi]:>";
        wcin >> value;

        if(!wcin.fail() && wcin.peek() == 10)
        {
          pLinetype->setShapeRotationAt(index, value);

          wcout << L"Dash (" << index << L") Rotation Angle is set to: " 
                << pLinetype->shapeRotationAt(index) << L" radians\n";
        }
        else { wcin.clear();  wcin.sync();  wcout << L"Error: Invalid entered value\n"; }
        break;


      case L'U':          // Set the UCS orientation
      case L'u':
        wcout << L"\nEntry UCS flag [S-Set flag|C-Clear flag]:>";
        wcin >> ch;

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

        wcout << L"Dash (" << index << L") is " 
              << ((pLinetype->shapeIsUcsOrientedAt(index)) ? L"absolute" : L"relative") << L"-oriented\n";
        break;


      case L'R':          // Set the Upright orientation
      case L'r':
        wcout << L"\nEntry Upright flag [S-Set flag|C-Clear flag]:>";
        wcin >> ch;

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

        wcout << L"Dash (" << index << L") is " 
              << ((pLinetype->shapeIsUprightAt(index)) ? L"upright" : L"inline") << L"-oriented\n";
        break;


      case L'T':          // Set the text inclusion
      case L't':
        wcout << L"\nCurrent text = " << pLinetype->textAt(index)
              << L"\nEntry a new string:>";

        if((txtstr = EntryTextAs(kArbitrary)).isEmpty()) break;
        
        pLinetype->setTextAt(index, txtstr);

        wcout << L"Dash (" << index << L") Text is set to: \"" << pLinetype->textAt(index)
              << L"\" (Shape = " << pLinetype->shapeNumberAt(index) << L")\n";
        break;


      case L'I':          // Set the shape inclusion
      case L'i':
        wcout << L"\nCurrent shape number = " << pLinetype->shapeNumberAt(index)
              << L"\nEntry a new number:>";
        wcin >> number;

        if(!wcin.fail() && wcin.peek() == 10)
        {
          pLinetype->setShapeNumberAt(index, number);

          wcout << L"Dash (" << index << L") Shape Number is set to: " 
                << pLinetype->shapeNumberAt(index) 
                << L" (Text = \"" << pLinetype->textAt(index) << "\")\n";
        }
        else { wcin.clear();  wcin.sync();  wcout << L"Error: Invalid entered value\n"; }
        break;


      case L'S':          // Set the inclusion style
      case L's':
        pLinetype->setShapeStyleAt(index, EntryTableRecordObject(
                   pLinetype->database()->getTextStyleTableId(), pLinetype->shapeStyleAt(index)));
                   
        wcout << L"Dash (" << index << L") Style is set to: " 
              << AboutDbObject(pLinetype->shapeStyleAt(index)) << L"\n";
        break;


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

      default:
        wcout << L"Incorrect operation\n";
    }
    wcout << L"\nSelected dash (" << index << L") Linetype \"" << pLinetype->getName() << L"\"";
    wcout << L"\nL. Set the length";
    wcout << L"\nO. Set the offset";
    wcout << L"\nF. Set the scale factor";
    wcout << L"\nA. Set the rotation angle";
    wcout << L"\nT. Set the text inclusion";
    wcout << L"\nI. Set the shape inclusion";
    wcout << L"\nS. Set the inclusion style";
    wcout << L"\nU. Set the UCS orientation";
    wcout << L"\nR. Set the Upright orientation";
    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 dash properties\n";
}

Testing gives the following results:


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:>

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


Dash (1) absolute,inline, Style=[Db:kNull], Shape=0, Text=""
Length=0, Scale=0, Angle=0, Offset=(0,0)

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


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

When the operation is I-"Set the shape inclusion":


Current shape number = 0
Entry a new number:>133
Dash (1) Shape Number is set to: 133 (Text = "")

When the operation is T-"Set the text inclusion":


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

When the operation is S-"Set the inclusion style":


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

When the operation is U-"Set the UCS orientation":


Entry UCS flag [S-Set flag|C-Clear flag]:>C
Dash (1) is relative-oriented

When the operation is R-"Set the Upright orientation":


Entry Upright flag [S-Set flag|C-Clear flag]:>S
Dash (1) is upright-oriented

When the operation is F-"Set the scale factor":


Current scale factor = 0
Entry a new scale factor [f>0]:>0.85
Dash (1) Scale Factor is set to: 0.85

When the operation is F-"Set the scale factor" and a value is incorrect:


Current scale factor = 0.85
Entry a new scale factor [f>0]:>-2.5
Error: Scale Factor must be a positive double value

When the operation is A-"Set the rotation angle":


Current rotation angle = 0 radians
Entry a new angle [0...2Pi]:>0.375
Dash (1) Rotation Angle is set to: 0.375 radians

When the operation is O-"Set the offset":


Entry the offset
Current vector directions: (0,0)
Entry X-direction:>0.5
Entry Y-direction:>0.2
Dash (1) Offset is set to: (0.5,0.2)

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


Dash (1) relative,upright, Style=[11-"Standard"-TextStyle], Shape=0, Text="GAS"
Length=-1.2, Scale=0.85, Angle=0.375, Offset=(0.5,0.2)

Use the Q-"Quit" operation to exit:


Stop modifying of the dash properties

See Also

Working with Linetypes

Working with the Linetype Pattern

Example of Working with the Linetype Table Object

Example of Working with the Linetype Record Object

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