Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Working with Specific Entitites > Working with Points > Example of Working with the Point Object
Example of Working with the Point Object

This example demonstrates displaying and modifying properties of a point object. This example uses a console menu that represents the following operations: getting and setting the position [C], normal [N], thickness [T], ECS rotation [R], point mode [D], and point size [S]; displaying the object properties, general properties, and specific properties [P]; and modifying the general entity properties [M].

The PrintPointProperties() function requires a pointer to an existing point object and displays its properties. The function gets the specific properties using the position(), normal(), thickness(), and escRotation() methods. The function uses the AboutPoint3d() function for converting the position coordinates to a string value and the AboutVector3d() function for converting the coordinates of the normal 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 point is a planar entity, and the function gets and displays the coefficients of the plane using the AboutPlane() function.

The PrintPointProperties() function has the following implementation:


void PrintPointProperties(OdDbPoint* pPoint)
{
  OdGePlane plane;
  OdDb::Planarity planarity;

  wcout << L"\n  Normal = " << AboutVector3d(pPoint->normal())
        << L"\n  Position = " << AboutPoint3d(pPoint->position())
        << L"\n  Thickness = " << pPoint->thickness()
        << L"\n  ECSRotation = " << pPoint->ecsRotation();

  if(pPoint->getPlane(plane, planarity) == eOk)
    wcout << L"\n  " << ((planarity == OdDb::kPlanar) ? L"Entity" : 
                         (planarity == OdDb::kLinear) ? L"Arbitrary" : L"Non")
          << L" Plane = " << AboutPlane(plane);
}

The ModifyPointProperties() function requires a pointer to an existing point object and implements the console menu for the listed operations. The function organizes a loop that inquires about the operation code and uses the switch statement to select whether the case must be performed. The function processes user actions in the loop until the user selects the [Q] operation. The function uses the EntryPoint3d() function for entering coordinates of a three-dimensional point and the 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 True when the passed instance is modified successfully or False when the user cancels entry.

When the user selects [P], the function displays the common object properties using the PrintObjectProperties() function, general entity properties using the PrintEntityProperties() function, and PDMODE and PDSIZE system variables and specific point properties using the PrintPointProperties() function. When the user selects the [p] operation, the function displays only specific point properties.

When the user selects [C], the function gets the position of the point using the position() method, calls the EntryPoint3d() function for entry of its coordinates, and sets the returned point as the new position using the setPosition() method if entry is successful.

When the user selects [N], the function gets the normal to the plane of the point using the normal() method, calls the EntryVector3d() function for entry of its coordinates, and sets the returned vector as a new normal using the setNormal() method if entry is successful.

When the user selects [T], the function gets the current thickness using the thickness() method and requests 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 sets the new thickness using the setThickness() method.

When the user selects [R], the function gets the current ECS angle using the ecsRotation() method and requests a double value in the range 0 to 2PI. 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 sets the new angle using the setEcsRotation() method.

When the user selects [S], the function gets the current point size from the system variable PDSIZE using the getPDSIZE() method of the database object and requests a double value for the new size. 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 sets the new point size using the setPDSIZE() method of the database object.

When the user selects [D], the function gets the current point mode from the system variable PDMODE using the getPDMODE() method of the database object and displays it using the AboutPDMODE() function. Then the function calls the EntryPDMODE() function for selecting a new point mode. The EntryPDMODE() function requires a reference to a variable in which the selected mode must be saved and returns True when the point mode is selected or False when the user cancels entry. If entry is successful, the function sets the selected point mode using the setPDMODE() method of the database object.

When the user selects [M], the function calls the ModifyEntityProperties() function and passes to it the pointer to the point object for modifying its general entity properties. After modification, the function displays all point properties using the [P] operation.

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

The ModifyPointProperties() function has the following implementation:


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

OdString AboutPDMODE(OdInt16 mode);
bool EntryPDMODE(OdInt16& mode);

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

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

void PrintEntityProperties(OdDbEntity *pEntity);
void ModifyEntityProperties(OdDbEntity *pEntity);

void ModifyPointProperties(OdDbPoint* pPoint)
{
  wchar_t ch = L'\0';
  double value;
  OdInt16 mode;
  OdGePoint3d point;
  OdGeVector3d vector;

  wcout << L"\n\nStart modifying of the point properties";

  do {
    switch(ch)
    {
      case L'M':          // Modify the general properties
      case L'm':
        ModifyEntityProperties(pPoint);


      case L'P':          // Print the whole properties
        wcout << L"\nH=" << pPoint->handle().ascii();
        wcout << L"\n  ------ Common Object Properties";
        PrintObjectProperties(pPoint);
        wcout << L"\n  ------ General Entity Properties";
        PrintEntityProperties(pPoint);
        wcout << L"\n  ------ System Variables";
        wcout << L"\n  Point mode = " << pPoint->database()->getPDMODE();
        wcout << L"\n  Point size = " << pPoint->database()->getPDSIZE();


      case L'p':          // Print the specific properties
        wcout << L"\n  ------ Specific Point Properties";
        PrintPointProperties(pPoint);
        wcout << L"\n";        
        break;


      case L'N':          // Set the normal
      case L'n':
        wcout << L"Entry the normal";
        vector = pPoint->normal();
        if(EntryVector3d(vector))
        {
          pPoint->setNormal(vector);
          wcout << L"Normal is set to " << AboutVector3d(pPoint->normal()) << L"\n";
        }
        break;


      case L'C':          // Set the position
      case L'c':
        wcout << L"Entry the position";
        point = pPoint->position();
        if(EntryPoint3d(point))
        {
          pPoint->setPosition(point);
          wcout << L"Position is set to " << AboutPoint3d(pPoint->position()) << L"\n";
        }
        break;


      case L'T':          // Set the thickness
      case L't':
        wcout << L"\nCurrent thickness = " << pPoint->thickness()
              << L"\nEntry a new thickness [t>0-along normal|t<0-opposite normal]:>";
        wcin >> value;

        if(!wcin.fail() && wcin.peek() == 10)
        {
          pPoint->setThickness(value);
          wcout << L"Thickness is set to: " << pPoint->thickness() << L"\n";
        }
        else { wcin.clear();  wcin.sync();  wcout << L"Error: Invalid entered value\n"; }
        break;


      case L'R':          // Set the ECS rotation
      case L'r':
        wcout << L"\nCurrent ecs rotation angle = " << pPoint->ecsRotation()
              << L"\nEntry a new angle [0...2PI]:>";
        wcin >> value;

        if(!wcin.fail() && wcin.peek() == 10)
        {
          pPoint->setEcsRotation(value);
          wcout << L"ECS Rotation is set to: " << pPoint->ecsRotation() << L"\n";
        }
        else { wcin.clear();  wcin.sync();  wcout << L"Error: Invalid entered value\n"; }
        break;


      case L'D':          // Set the PDMODE
      case L'd':
        mode = pPoint->database()->getPDMODE();
        wcout << L"\nCurrent point mode = " << AboutPDMODE(mode);

        if(EntryPDMODE(mode))
        {
          pPoint->database()->setPDMODE(mode);
          wcout << L"Point mode is set to: " << AboutPDMODE(pPoint->database()->getPDMODE()) << L"\n";
        }
        break;


      case L'S':          // Set the PDSIZE
      case L's':
        wcout << L"\nCurrent point size = " << pPoint->database()->getPDSIZE()
              << L"\nEntry a new point size:>";
        wcin >> value;

        if(!wcin.fail() && wcin.peek() == 10)
        {
          pPoint->database()->setPDSIZE(value);
          wcout << L"Point size is set to: " << pPoint->database()->getPDSIZE() << L"\n";
        }
        else { wcin.clear();  wcin.sync();  wcout << L"Error: Invalid entered value\n"; }
        break;


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

      default:
        wcout << L"Error: Incorrect operation\n";
    }
    wcout << L"\nN. Set the normal";
    wcout << L"\nC. Set the position";
    wcout << L"\nT. Set the thickness";
    wcout << L"\nD. Set the point mode";
    wcout << L"\nS. Set the point size";
    wcout << L"\nR. Set the ECS rotation";
    wcout << L"\nP. Print the whole properties";
    wcout << L"\np. Print the specific properties";
    wcout << L"\nM. Modify the general properties";
    wcout << L"\nQ. Quit";
    wcout << L"\nSelect operation:>";
    wcin >> ch;
  }
  while(ch != L'Q' && ch != L'q');

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

Testing gives the following results:


Start modifying of the point properties

N. Set the normal
C. Set the position
T. Set the thickness
D. Set the point mode
S. Set the point size
R. Set the ECS rotation
P. Print the whole properties
p. Print the specific properties
M. Modify the general properties
Q. Quit
Select operation:>

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


------ Specific Point Properties
Normal = (0,0,1)
Position = (0,0,0)
Thickness = 0
ECSRotation = 0
Arbitrary Plane = (0 * X + 0 * Y + 1 * Z + -0)

When the operation is C-"Set the center":


Entry the position
Current coordinates: (0,0,0)
Entry X-coordinate:>4.6
Entry Y-coordinate:>2.5
Entry Z-coordinate:>1.3
Position is set to (4.6,2.5,1.3)

When the operation is N-"Set the normal":


Entry the normal
Current vector directions: (0,0,1)
Entry X-direction:>0.8
Entry Y-direction:>1.2
Entry Z-direction:>0.3
Normal is set to (0.543075,0.814613,0.203653)

When the operation is T-"Set the thickness":


Current thickness = 0
Entry a new thickness [t>0-along normal|t<0-opposite normal]:>1.8
Thickness is set to: 1.8

When the operation is D-"Set the point mode":


Current point mode = 0 - dot
0  - dot
1  - empty
2  - plus
3  - cross
4  - pin
32 - dot & circle
33 - circle
34 - plus & circle
35 - cross & circle
36 - pin & circle
64 - dot & square
65 - square
66 - plus & square
67 - cross & square
68 - pin & square
96 - dot & circle & square
97 - circle & square
98 - plus & circle & square
99 - cross & circle & square
100- pin & circle & square
Entry the point mode number:>98
Point mode is set to: 98 - plus & circle & square

When the operation is S-"Set the point size":


Current point size = 0
Entry a new point size:>0.5
Point size is set to: 0.5

When the operation is R-"Set the ECS rotation":


Current ecs rotation angle = 0
Entry a new angle [0...2PI]:>0.102
ECS Rotation is set to: 0.102

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


H=40
  ------ Common Object Properties
  Type: AcDbPoint
  Status: unerased,resident,modified,forRead,forWrite
  Database:
  ------ General Entity Properties
  Block: [1F-"*Model_Space"-Block]
  Layer: [10-"0"-Layer]
  Material: [3C-"ByLayer"-Material]
  Linetype: [15-"ByLayer"-Linetype]
  Lineweight: [kLnWtByLayer]
  Transparency: [byLayer]
  Visual style: [Db:kNull]
  PlotStyleName: ByLayer
  Linetype scale: 1
  Color: [byLayer], Index = 256
  State: Planar, Visible, Cast Shadows, Receive Shadows
  ------ System Variables
  Point mode = 98
  Point size = 0.5
  ------ Specific Point Properties
  Normal = (0.543075,0.814613,0.203653)
  Position = (4.6,2.5,1.3)
  Thickness = 1.8
  ECSRotation = 0.102
  Arbitrary Plane = (0.543075 * X + 0.814613 * Y + 0.203653 * Z + -4.79943)

Use the Q-"Quit" operation to exit:


Stop modifying of the point properties

See Also

Working with Points

Appearance and Size of Points

Example of Entering and Displaying for 3D Point Objects

Example of Entering and Displaying for 3D Vector Objects

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