Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Example of Working with the Xline Object

This example demonstrates displaying and modifying the properties of the Xline object. This example uses a console menu that represents the following operations: getting and setting the base point [B]; getting and setting the direction vector [D]; computing the features at a parameter [Z]; displaying the object properties, general properties, computed properties, and specific properties [P]; and modifying the general entity properties [M].

The PrintXlineProperties() function requires a pointer to an existing Xline object and displays its specific properties. The function gets the specific properties using the basePoint() and unitDir() methods. The function uses the AboutPoint3d() function for converting the coordinates of the base point to a string value and the AboutVector3d() function for converting the coordinates of the direction vector 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 PrintXlineProperties() function has the following implementation:


void PrintXlineProperties(OdDbXline* pXLine)
{
  wcout << L"\n  Direction = " << AboutVector3d(pXLine->unitDir())
        << L"\n  Base point = " << AboutPoint3d(pXLine->basePoint());
}

The PrintXlineFeatures() function requires a pointer to an existing Xline object and displays the properties computed at a parameter (features). The function uses the getPointAtParam(), getFirstDeriv(), getSecondDeriv(), and getPlane() methods, and also uses the AboutPoint3d() and AboutVector3d() functions. The parameter is the distance measured from the base point. The infinite line does not have a length and area. The first and second derivatives are vectors which are computed at the parameter and are constant for any point on the infinite line. The infinite line is an entity that has an arbitrary plane passed through it. The function gets and displays the coefficients of the arbitrary plane using the AboutPlane() function.

The PrintXlineFeatures() function has the following implementation:


void PrintXlineFeatures(OdDbXline* pXLine)
{
  OdGePlane plane;
  OdGeVector3d vector;
  OdDb::Planarity planarity;

  pXLine->getFirstDeriv(0, vector);
  wcout << L"\n  First derivative = " << AboutVector3d(vector);
  pXLine->getSecondDeriv(0, vector);
  wcout << L"\n  Second derivative = " << AboutVector3d(vector);

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

The ModifyXlineProperties() function requires a pointer to an existing Xline 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 for 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, computed infinite line properties using the PrintXlineFeatures() function, and specific infinite line properties using the PrintXlineProperties() function. When the user selects the [p] operation, the function displays only specific infinite line properties.

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

When the user selects [D], the function gets the direction vector using the unitDir() method, calls the EntryVector3d() function for entry of its coordinates, and sets the returned vector as a new direction using the setUnitDir() method if entry is successful.

When the user selects [Z], the function requests a parameter as a double value. If the entered value is correct, the function computes the coordinates of the point on the infinite line corresponding to the specified parameter using the getPointAtParam() method, computes the distance from the start point to the computed point using the getDistAtParam() method, and computers the first and second derivatives in the computed point using the getFirstDeriv() and getSecondDeriv() methods.

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

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

The ModifyXlineProperties() function has the following implementation:


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

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 ModifyXlineProperties(OdDbXline* pXLine)
{
  wchar_t ch = L'\0';
  double value, param;
  OdGePoint3d point;
  OdGeVector3d vector;

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

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


      case L'P':          // Print the whole properties
        wcout << L"\nH=" << pXLine->handle().ascii();
        wcout << L"\n  ------ Common Object Properties";
        PrintObjectProperties(pXLine);
        wcout << L"\n  ------ General Entity Properties";
        PrintEntityProperties(pXLine);
        wcout << L"\n  ------ Computed Xline Properties";
        PrintXlineFeatures(pXLine);


      case L'p':          // Print the specific properties
        wcout << L"\n  ------ Specific Xline Properties";
        PrintXlineProperties(pXLine);
        wcout << L"\n";        
        break;


      case L'D':          // Set the direction
      case L'd':
        wcout << L"Entry the direction";
        vector = pXLine->unitDir();

        if(EntryVector3d(vector))
        {
          pXLine->setUnitDir(vector);
          wcout << L"Direction is set to " << AboutVector3d(pXLine->unitDir()) << L"\n";
        }
        break;


      case L'B':          // Set the base point
      case L'b':
        wcout << L"Entry the base point";
        point = pXLine->basePoint();

        if(EntryPoint3d(point))
        {
          pXLine->setBasePoint(point);
          wcout << L"Base point is set to " << AboutPoint3d(pXLine->basePoint()) << L"\n";
        }
        break;


      case L'Z':          // Compute the features at parameter
      case L'z':
        wcout << L"\nEntry a parameter:>";
        wcin >> param;

        if(!wcin.fail() && wcin.peek() == 10)
        {
          wcout << L"Compute at (" << param << L"):";
          if(pXLine->getDistAtParam(param, value) == eOk)
            wcout << L"\nDistance = " << value;
          if(pXLine->getPointAtParam(param, point) == eOk)
            wcout << L"\nPoint on = " << AboutPoint3d(point);
          if(pXLine->getFirstDeriv(param, vector) == eOk)
            wcout << L"\n1-Derivative = " << AboutVector3d(vector);
          if(pXLine->getSecondDeriv(param, vector) == eOk)
            wcout << L"\n2-Derivative = " << AboutVector3d(vector);
          wcout << L"\n--at--";
        }
        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"\nD. Set the direction";
    wcout << L"\nB. Set the base point";
    wcout << L"\nP. Print the whole properties";
    wcout << L"\np. Print the specific properties";
    wcout << L"\nM. Modify the general properties";
    wcout << L"\nZ. Compute the features at parameter";
    wcout << L"\nQ. Quit";
    wcout << L"\nSelect operation:>";
    wcin >> ch;
  }
  while(ch != L'Q' && ch != L'q');

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

Testing gives the following results:


Start modifying of the infinity line properties

D. Set the direction
B. Set the base point
P. Print the whole properties
p. Print the specific properties
M. Modify the general properties
Z. Compute the features at parameter
Q. Quit
Select operation:>

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


------ Specific Xline Properties
Direction = (0,0,1)
Base point = (0,0,0)

When the operation is B-"Set the base point":


Entry the base point
Current coordinates: (0,0,0)
Entry X-coordinate:>3.6
Entry Y-coordinate:>2.5
Entry Z-coordinate:>1.4
Base point is set to (3.6,2.5,1.4)

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


Entry the direction
Current vector directions: (0,0,1)
Entry X-direction:>2.3
Entry Y-direction:>0.8
Entry Z-direction:>0.1
Direction is set to (0.943701,0.328244,0.0410305)

When the operation is Z-"Compute the features at parameter":


Entry a parameter:>3.5
Compute at (3.5):
Distance = 3.5
Point on = (6.90296,3.64885,1.54361)
1-Derivative = (0.943701,0.328244,0.0410305)
2-Derivative = (0,0,0)
--at--

Entry a parameter:>-3.5
Compute at (-3.5):
Distance = 3.5
Point on = (0.297045,1.35115,1.25639)
1-Derivative = (0.943701,0.328244,0.0410305)
2-Derivative = (0,0,0)
--at--

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


H=40
  ------ Common Object Properties
  Type: AcDbXline
  Status: unerased,resident,modified,forRead,forWrite
  Database: c:\test.dwg
  ------ 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
  ------ Computed Xline Properties
  First derivative = (0.943701,0.328244,0.0410305)
  Second derivative = (0,0,0)
  Arbitrary Plane = (-0.328521 * X + 0.944497 * Y + 0 * Z + -1.17857)  
  ------ Specific Xline Properties
  Direction = (0.943701,0.328244,0.0410305)
  Base point = (3.6,2.5,1.4)

Use the Q-"Quit" operation to exit:


Stop modifying of the infinity line properties

See Also

Working with Infinite Lines

Example of Working with the Ray 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.