Kernel SDK Developer's Guide > Working with the Ge Library > Example of Entering and Displaying 3D Point Objects
Example of Entering and Displaying 3D Point Objects

The example demonstrates working with the three-dimensional point object, including the display and modification of its properties. The AboutPoint3d() function requires a reference to an existing three-dimensional point as an OdGePoint3d instance and returns a string containing the values of the X, Y, Z coordinates of the passed point as an OdString value. The function declares the variable of the OdString type and uses the format() method to convert the coordinates to a string. The AboutPoint3d() function has the following implementation:

OdString AboutPoint3d(const OdGePoint3d& point)
{ 
  OdString s;
  s.format(L"(%g,%g,%g)", point.x, point.y, point.z);
  return s;
}

The EntryPoint3d() function requires a reference to an existing three-dimensional point as an OdGePoint3d instance which is used as a default value and returns True if the user modifies the passed instance, or False if the user cancels entry. The function organizes a loop for entry of coordinates and displays the current values of coordinates before the loop. If an entered value of a coordinate is incorrect, the function displays an error message and repeats the entry. If the entered X, Y, Z coordinates are correct, the function passes the modified instance in the calling function through own argument and returns True as a result. If the user selects [Q], the function cancels the entry, remains the current coordinates, and returns False as a result. The EntryPoint3d() function has the following implementation:

bool EntryPoint3d(const OdGePoint3d& point)
{
  wchar_t ch;
  OdGePoint3d value = point;

  wcout << L"\nCurrent coordinates: " << AboutPoint3d(point) << L"\n";
  do {
    wcout << L"Entry X-coordinate:>";
    wcin >> value.x;

    if(!wcin.fail() && wcin.peek() == 10)
    {
      wcout << L"Entry Y-coordinate:>";
      wcin >> value.y;

      if(!wcin.fail() && wcin.peek() == 10)
      {
        wcout << L"Entry Z-coordinate:>";
        wcin >> value.z;

        if(!wcin.fail() && wcin.peek() == 10)
        {
          point = value;
          return true;
        }
      }
    }
    wcin.clear();  
    wcin.sync();
    wcout << L"Error: Invalid entered value\nPress any key to repeat [or Q-quit]:>";
    wcin >> ch;
  } 
  while(ch != L'Q' && ch != L'q');

  return false;
}

Note: The «toString» sample code contains an additional example for converting an OdGePoint3d value to an OdString value.

The AboutPoint3d() and EntryPoint3d() functions are used in the documented examples that require display and entry of a three-dimensional point.

See Also

Working with Basic Geometry Types

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