Close

Relief for ODA Team in Ukraine

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

This example demonstrates working with the UCS record object to display and modify its properties. The example uses the console menu which represents the following operations: getting and setting the X-axis direction [X], Y-axis direction [Y], UCS origin [O], and orthographic view origins [V].

The PrintUCSProperties() function requires the pointer to an existing UCS record object and prints the properties of the UCS. The function uses the AboutPoint3d() function for converting the UCS origin and orthographic view origins to a string value and the AboutVector3d() function for converting the X-axis and Y-axis vectors to a string value. The AboutPoint3d() and AboutVector3d() functions require an instance of the three-dimensional point or three-dimensional vector to be converted as an argument and return a string containing the X,Y,Z coordinates.

The PrintUCSProperties() function has the following implementation:


void PrintUCSProperties(OdDbUCSTableRecord* pUCS)
{
  wcout << L"\nH=" << pUCS->handle().ascii() 
        << L"\n  Name = \"" << pUCS->getName() << L"\""
        << L"\n  Status: " << ((pUCS->isErased()) ? L"erased" : L"unerased")
                           << ((pUCS->isDBRO()) ? L",resident" : L"")
                           << ((pUCS->isModified()) ? L",modified" : L"")
                           << ((pUCS->isDependent()) ? L",XRef-dependent" : L"") 
        << L"\n  Origin = " << AboutPoint3d(pUCS->origin())
        << L"\n  X-axis = " << AboutVector3d(pUCS->xAxis())
        << L", Y-axis = " << AboutVector3d(pUCS->yAxis())
        << L"\n  Top = " << AboutPoint3d( pUCS->ucsBaseOrigin(OdDb::kTopView) )
        << L", Bottom = " << AboutPoint3d( pUCS->ucsBaseOrigin(OdDb::kBottomView) )
        << L"\n  Front = " << AboutPoint3d( pUCS->ucsBaseOrigin(OdDb::kFrontView) )
        << L", Back = " << AboutPoint3d( pUCS->ucsBaseOrigin(OdDb::kBackView) )
        << L"\n  Left = " << AboutPoint3d( pUCS->ucsBaseOrigin(OdDb::kLeftView) )
        << L", Right = " << AboutPoint3d( pUCS->ucsBaseOrigin(OdDb::kRightView) );
}

The ModifyUCSProperties() function requires a pointer to an existing UCS record 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 ModifyUCSProperties() function processes user actions in the loop until the user does not select the [Q] operation. The function uses the AboutPoint3d() function for converting the UCS origin and orthographic view origins to a string value, AboutVector3d() function for converting the X-axis and Y-axis vectors to string values, EntryPoint3d() function for entering coordinates for a three-dimensional point, and EntryVector3d() function for entering coordinates of a three-dimensional vector. The EntryPoint3d() and EntryVector3d() functions require a reference to an instance of the three-dimensional point or three-dimensional vector to be modified as an argument and return a True when the passed instance is modified successfully, or a False when an user cancels the entry.

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

When the user selects [X], the function gets the X-axis vector using the xAxis() method, calls the EntryVector3d() function for entry of coordinates, and sets the returned vector as a new X-axis direction using the setXAxis() method if entering is successfully.

When the user selects [Y], the function gets the Y-axis vector using the yAxis() method, calls the EntryVector3d() function for entry of coordinates, and sets the returned vector as a new Y-axis direction using the setYAxis() method if entering is successfully.

When an user selects [O], the function gets the UCS origin using the origin() method, calls the EntryPoint3d() function for entry of coordinates, and sets the returned point as the new origin using the setOrigin() method if entering is successfully.

When the user selects [V], the function inquires on the orthographic view identifier as an Integer value which takes the following values: 1-Top, 2-Bottom, 3-Front, 4-Back, 5-Left, and 6-Right. Then, the function gets the origin for the specified orthographic view using the ucsBaseOrigin() method, calls the EntryPoint3d() function for entry of coordinates, and sets the returned point as a new orthographic view origin using the setUcsBaseOrigin() method. The function passes the entered point and orthographic view identifier as arguments of the setUcsBaseOrigin() method. After each operation, the ModifyUCSProperties() function displays the modified property of the UCS record object.

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

The ModifyUCSProperties() function has the following implementation:


#include "..\Common\DemoMain.h"
#include "DbUCSTable.h"
#include "DbUCSTableRecord.h"
#include "Ge\GePoint3d.h"
#include "Ge\GeVector3d.h"
#include <iostream>
using namespace std;

OdString AboutPoint3d(const OdGePoint3d& point);
bool EntryPoint3d(OdGePoint3d& point);

OdString AboutVector3d(const OdGeVector3d& vector);
bool EntryVector3d(OdGeVector3d& vector);

OdString AboutOrthographicView(const OdDb::OrthographicView nview)
{ 
  OdString sAbout;

  switch(nview)
  {
    case OdDb::kNonOrthoView :   sAbout = L"NonView";   break;
    case OdDb::kTopView      :   sAbout = L"Top";       break;
    case OdDb::kBottomView   :   sAbout = L"Bottom";    break;
    case OdDb::kFrontView    :   sAbout = L"Front";     break;
    case OdDb::kBackView     :   sAbout = L"Back";      break;
    case OdDb::kLeftView     :   sAbout = L"Left";      break;
    case OdDb::kRightView    :   sAbout = L"Right";     break;
    default:
      sAbout = L"???";
  }
  return sAbout;
}

void ModifyUCSProperties(OdDbUCSTableRecord* pUCS)
{
  wchar_t ch = L'\0';
  OdGeVector3d vector;
  OdGePoint3d point;
  int nview;

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


      case L'X':          // Set the X-axis
      case L'x':
        wcout << L"Entry the X-axis vector";
        vector = pUCS->xAxis();
        
        if(EntryVector3d(vector))
        {
          pUCS->setXAxis(vector);
          wcout << L"UCS X-axis vector is set to " << AboutVector3d(pUCS->xAxis()) << L"\n";
        }
        break;


      case L'Y':          // Set the Y-axis
      case L'y':
        wcout << L"Entry the Y-axis vector";
        vector = pUCS->yAxis();

        if(EntryVector3d(vector))
        {
          pUCS->setYAxis(vector);
          wcout << L"UCS Y-axis vector is set to " << AboutVector3d(pUCS->yAxis()) << L"\n";
        }
        break;


      case L'O':          // Set the UCS origin
      case L'o':
        wcout << L"Entry the origin point";
        point = pUCS->origin();

        if(EntryPoint3d(point))
        {
          pUCS->setOrigin(point);
          wcout << L"UCS Origin is set to " << AboutPoint3d(pUCS->origin()) << L"\n";
        }
        break;


      case L'V':          // Set the orthographic view origin
      case L'v':
        wcout << L"\nOrthographic views:\n1-Top, 2-Bottom, 3-Front, 4-Back, 5-Left, 6-Right"
              << L"\nEntry the view identifier [1...6]:>";
        wcin >> nview;
        
        if(nview >= 1 && nview <= 6)
        {
          point = pUCS->ucsBaseOrigin((OdDb::OrthographicView) nview);

          if(EntryPoint3d(point))
          {
            pUCS->setUcsBaseOrigin(point, (OdDb::OrthographicView) nview);

            wcout << L"The " << AboutOrthographicView((OdDb::OrthographicView) nview) 
                  << L" origin is set to "
                  << AboutPoint3d(pUCS->ucsBaseOrigin((OdDb::OrthographicView) nview)) << L"\n";
          }
        }
        else wcout << L"Error: Incorrect view identifier\n";
        break;


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

      default:
        wcout << L"Incorrect operation\n";
    }
    wcout << L"\nSelected UCS: \"" << pUCS->getName() << L"\"";
    wcout << L"\nP. Print specific properties";
    wcout << L"\nX. Set the X-axis";
    wcout << L"\nY. Set the Y-axis";
    wcout << L"\nO. Set the UCS origin";
    wcout << L"\nV. Set the orthographic view origin";
    wcout << L"\nQ. Quit";
    wcout << L"\nSelect operation:>";
    wcin >> ch;
  }
  while(ch != L'Q' && ch != L'q');

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

Testing gives the following results:


Start modifying of the UCS properties

Selected UCS: "UCS0"
P. Print specific properties
X. Set the X-axis
Y. Set the Y-axis
O. Set the UCS origin
V. Set the orthographic view origin
Q. Quit
Select operation:>

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


H=3F
  Name = "UCS0"
  Status: unerased,resident,modified
  Origin = (0,0,0)
  X-axis = (1,0,0), Y-axis = (0,1,0)
  Top = (0,0,0), Bottom = (0,0,0)
  Front = (0,0,0), Back = (0,0,0)
  Left = (0,0,0), Right = (0,0,0)

When the operation is X-"Set the X-axis":


Entry the X-axis vector
Current vector directions: (1,0,0)
Entry X-direction:>0.707
Entry Y-direction:>0.303
Entry Z-direction:>0.1
UCS X-axis vector is set to (0.707,0.303,0.1)

When the operation is Y-"Set the Y-axis":


Entry the Y-axis vector
Current vector directions: (0,1,0)
Entry X-direction:>0.303
Entry Y-direction:>0.707
Entry Z-direction:>0.021
UCS Y-axis vector is set to (0.303,0.707,0.021)

When the operation is O-"Set the UCS origin":


Entry the origin point
Current coordinates: (0,0,0)
Entry X-coordinate:>1
Entry Y-coordinate:>3
Entry Z-coordinate:>2
UCS Origin is set to (1,3,2)

The setOrigin() method sets all orthographic view origins to the specified point. After setting the origin, select the operation P-"Print the specific properties":


H=3F
  Name = "UCS0"
  Status:unerased,DBRO,modified
  Origin = (1,3,2)
  X-axis = (0.707,0.303,0.1), Y-axis = (0.303,0.707,0.021)
  Top = (1,3,2), Bottom = (1,3,2)
  Front = (1,3,2), Back = (1,3,2)
  Left = (1,3,2), Right = (1,3,2)

When the operation is V-"Set the orthographic view origin":


Orthographic views:
1-Top, 2-Bottom, 3-Front, 4-Back, 5-Left, 6-Right
Entry the view identifier [1...6]:>3

Current coordinates: (1,3,2)
Entry X-coordinate:>4
Entry Y-coordinate:>1
Entry Z-coordinate:>3
The Front origin is set to (4,1,3)

Repeat the operation V-"Set the orthographic view origin":


Orthographic views:
1-Top, 2-Bottom, 3-Front, 4-Back, 5-Left, 6-Right
Entry the view identifier [1...6]:>5

Current coordinates: (1,3,2)
Entry X-coordinate:>2
Entry Y-coordinate:>2
Entry Z-coordinate:>1
The Left origin is set to (2,2,1)

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


H=3F
  Name = "UCS0"
  Status:unerased,DBRO,modified
  Origin = (1,3,2)
  X-axis = (0.707,0.303,0.1), Y-axis = (0.303,0.707,0.021)
  Top = (1,3,2), Bottom = (1,3,2)
  Front = (4,1,3), Back = (1,3,2)
  Left = (2,2,1), Right = (1,3,2)

Use the Q-"Quit" operation to exit:


Stop modifying of the UCS properties

See Also

Working with UCSs

Specific Properties of UCSs

Example of Working with the UCS Table Object

Example of Entering and Displaying 3D Point Objects

Example of Entering and Displaying 3D Vector Objects

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