This example demonstrates displaying and modifying the properties of a circle object. This example uses a console menu that represents the following operations: getting and setting the center [C], radius [R], normal [N], thickness [T], computing the features at parameter [Z], displaying the object properties, general properties, computed properties, specific properties [P], and modifying the general entity properties [M].
The PrintCircleProperties() function requires a pointer to an existing circle object and displays its specific properties. The function gets the specific properties using the center(), normal(), radius(), and thickness() methods. The function uses the AboutPoint3d() function for converting the coordinates of the center 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 PrintCircleProperties() function has the following implementation:
void PrintCircleProperties(OdDbCircle* pCircle)
{
wcout << L"\n Normal = " << AboutVector3d(pCircle->normal())
<< L"\n Center = " << AboutPoint3d(pCircle->center())
<< L"\n Radius = " << pCircle->radius()
<< L"\n Thickness = " << pCircle->thickness();
}
The PrintCircleFeatures() function requires a pointer to an existing circle object and displays properties computed at a parameter (features). The function uses the getStartPoint(), getEndPoint(), getStartParam(), getEndParam(), getArea(), getDistAtParam(), getParamAtDist(), getPointAtParam(), getFirstDeriv(),getSecondDeriv(), and getPlane() methods, and also uses the AboutPoint3d() and AboutVector3d() functions. The start point coincides with the end point for the circle. The parameter is the angle measured from the X-axis and is changed to the range 0 to 2PI. The circumference is calculated as the distance from the start point to the end point computed at a parameter. The circle has four quadrants which are computed through parameters for angles: 0, PI/2, PI, 3PI/2. The first and second derivatives are vectors which are also computed through parameters for angles: PI/4 and 3PI/4. The circle is a planar entity, and the function gets and displays the coefficients of the plane using the AboutPlane() function.
The PrintCircleFeatures() function has the following implementation:
void PrintCircleFeatures(OdDbCircle* pCircle)
{
OdGePlane plane;
OdGePoint3d point;
OdGeVector3d vector;
OdDb::Planarity planarity;
double value;
pCircle->getStartPoint(point);
wcout << L"\n Start point = " << AboutPoint3d(point);
pCircle->getEndPoint(point);
wcout << L"\n End point = " << AboutPoint3d(point);
pCircle->getStartParam(value);
wcout << L"\n Start parameter = " << value;
pCircle->getEndParam(value);
wcout << L"\n End parameter = " << value;
pCircle->getArea(value);
wcout << L"\n Area = " << value;
pCircle->getDistAtParam(Oda2PI, value);
wcout << L"\n Circumference = " << value;
pCircle->getParamAtDist(value/2, value);
wcout << L"\n Parameter at half-length = " << value;
wcout << L"\n Quadrants:";
pCircle->getPointAtParam(0, point);
wcout << L"\n Q(0) = " << AboutPoint3d(point);
pCircle->getPointAtParam((OdaPI * 0.5), point);
wcout << L"\n Q(PI/2) = " << AboutPoint3d(point);
pCircle->getPointAtParam(OdaPI, point);
wcout << L"\n Q(PI) = " << AboutPoint3d(point);
pCircle->getPointAtParam((OdaPI * 1.5), point);
wcout << L"\n Q(3PI/2) = " << AboutPoint3d(point);
wcout << L"\n Derivatives:";
pCircle->getFirstDeriv((OdaPI * 0.25), vector);
wcout << L"\n First(PI/4) = " << AboutVector3d(vector);
pCircle->getFirstDeriv((OdaPI * 0.75), vector);
wcout << L"\n First(3PI/4) = " << AboutVector3d(vector);
pCircle->getSecondDeriv((OdaPI * 0.25), vector);
wcout << L"\n Second(PI/4) = " << AboutVector3d(vector);
pCircle->getSecondDeriv((OdaPI * 0.75), vector);
wcout << L"\n Second(3PI/4) = " << AboutVector3d(vector);
if(pCircle->getPlane(plane, planarity) == eOk)
wcout << L"\n " << ((planarity == OdDb::kPlanar) ? L"Entity" :
(planarity == OdDb::kLinear) ? L"Arbitrary" : L"Non")
<< L" Plane = " << AboutPlane(plane);
}
The ModifyCircleProperties() function requires a pointer to an existing circle 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 they return True when the passed instance is modified successfully or False when a 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 circle properties using the PrintCircleFeatures() function, and specific circle properties using the PrintCircleProperties() function. When the user selects the [p] operation, the function displays only specific properties for circles.
When the user selects [C], the function gets the center of the circle using the center() method, calls the EntryPoint3d() function for entering its coordinates, and sets the returned point as the new center using the setCenter() method if entry is successful.
When the user selects [N], the function gets the normal to the plane of the circle using the normal() method, calls the EntryVector3d() function for entering its coordinates, and sets the returned vector as a new normal using the setNormal() method if entry is successful.
When the user selects [R], the function gets the current radius using the radius() method and requests a positive double value. If an entered value is incorrect or negative, the function displays an error message and breaks to the console menu. If an entered value is correct, the function sets the new radius using the setRadius() method.
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 [Z], the function requests a parameter as a double value in the range 0 to 2PI. If an entered value is correct, the function computes the coordinates of the point on the circle 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 computes 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 a pointer to the circle object for modifying its general entity properties. After modifying, the function displays all circle properties using the [P] operation.
When the user selects [Q], the function ends the loop and returns in the calling function.
The ModifyCircleProperties() function has the following implementation:
#include "..\Common\DemoMain.h"
#include "DbCircle.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 ModifyCircleProperties(OdDbCircle* pCircle)
{
wchar_t ch = L'\0';
double value, param;
OdGePoint3d point;
OdGeVector3d vector;
wcout << L"\n\nStart modifying of the circle properties";
do {
switch(ch)
{
case L'M': // Modify the general properties
case L'm':
ModifyEntityProperties(pCircle);
case L'P': // Print the whole properties
wcout << L"\nH=" << pCircle->handle().ascii();
wcout << L"\n ------ Common Object Properties";
PrintObjectProperties(pCircle);
wcout << L"\n ------ General Entity Properties";
PrintEntityProperties(pCircle);
wcout << L"\n ------ Computed Circle Properties";
PrintCircleFeatures(pCircle);
case L'p': // Print the specific properties
wcout << L"\n ------ Specific Circle Properties";
PrintCircleProperties(pCircle);
wcout << L"\n";
break;
case L'N': // Set the normal
case L'n':
wcout << L"Entry the normal";
vector = pCircle->normal();
if(EntryVector3d(vector))
{
pCircle->setNormal(vector);
wcout << L"Normal is set to " << AboutVector3d(pCircle->normal()) << L"\n";
}
break;
case L'C': // Set the center
case L'c':
wcout << L"Entry the center";
point = pCircle->center();
if(EntryPoint3d(point))
{
pCircle->setCenter(point);
wcout << L"Center is set to " << AboutPoint3d(pCircle->center()) << L"\n";
}
break;
case L'R': // Set the radius
case L'r':
wcout << L"\nCurrent radius = " << pCircle->radius()
<< L"\nEntry a new radius [r>0]:>";
wcin >> value;
if(!wcin.fail() && wcin.peek() == 10)
{
if(value >= 0)
{
pCircle->setRadius(value);
wcout << L"Radius is set to: " << pCircle->radius() << L"\n";
}
else wcout << L"Error: Radius must be a positive double value\n";
}
else { wcin.clear(); wcin.sync(); wcout << L"Error: Invalid entered value\n"; }
break;
case L'T': // Set the thickness
case L't':
wcout << L"\nCurrent thickness = " << pCircle->thickness()
<< L"\nEntry a new thickness [t>0-along normal|t<0-opposite normal]:>";
wcin >> value;
if(!wcin.fail() && wcin.peek() == 10)
{
pCircle->setThickness(value);
wcout << L"Thickness is set to: " << pCircle->thickness() << L"\n";
}
else { wcin.clear(); wcin.sync(); wcout << L"Error: Invalid entered value\n"; }
break;
case L'Z': // Compute the features at parameter
case L'z':
wcout << L"\nEntry a parameter [0 to 2PI]:>";
wcin >> param;
if(!wcin.fail() && wcin.peek() == 10)
{
wcout << L"Compute at (" << param << L"):";
if(pCircle->getDistAtParam(param, value) == eOk)
wcout << L"\nDistance = " << value;
if(pCircle->getPointAtParam(param, point) == eOk)
wcout << L"\nPoint on = " << AboutPoint3d(point);
if(pCircle->getFirstDeriv(param, vector) == eOk)
wcout << L"\n1-Derivative = " << AboutVector3d(vector);
if(pCircle->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"\nN. Set the normal";
wcout << L"\nC. Set the center";
wcout << L"\nR. Set the radius";
wcout << L"\nT. Set the thickness";
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 circle properties\n";
}
Testing gives the following results:
Start modifying of the circle properties
N. Set the normal
C. Set the center
R. Set the radius
T. Set the thickness
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 Circle Properties
Normal = (0,0,1)
Center = (0,0,0)
Radius = 0
Thickness = 0
When the operation is C-"Set the center":
Entry the center
Current coordinates: (0,0,0)
Entry X-coordinate:>2
Entry Y-coordinate:>1
Entry Z-coordinate:>3
Center is set to (2,1,3)
When the operation is R-"Set the radius":
Current radius = 0
Entry a new radius [r>0]:>-3
Error: Radius must be a positive double value
Current radius = 0
Entry a new radius [r>0]:>3
Radius is set to: 3
When the operation is T-"Set the thickness":
Current thickness = 0
Entry a new thickness [t>0-along normal|t<0-opposite normal]:>1.5
Thickness is set to: 1.5
When the operation is N-"Set the normal":
Entry the normal
Current vector directions: (0,0,1)
Entry X-direction:>2.3
Entry Y-direction:>1.5
Entry Z-direction:>0.7
Normal is set to (0.811652,0.529339,0.247025)
When the operation is Z-"Compute the features at parameter":
Entry a parameter [0 to 2PI]:>2.34
Compute at (2.34):
Distance = 7.02
Point on = (2.69392,-1.03869,5.0886)
1-Derivative = (1.60918,-1.5238,-2.02202)
2-Derivative = (-0.693918,2.03869,-2.0886)
--at--
When the operation is P-"Print all properties":
H=40
------ Common Object Properties
Type: AcDbCircle
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 Circle Properties
Start point = (0.361197,3.51283,3)
End point = (0.361197,3.51283,3)
Start parameter = 0
End parameter = 6.28319
Area = 28.2743
Circumference = 18.8496
Parameter at half-length = 3.14159
Quadrants:
Q(0) = (0.361197,3.51283,3)
Q(PI/2) = (1.37927,0.595175,5.90703)
Q(PI) = (3.6388,-1.51283,3)
Q(3PI/2) = (2.62073,1.40482,0.0929724)
Derivatives:
First(PI/4) = (0.719886,-2.06309,2.05558)
First(3PI/4) = (1.59773,-1.49059,-2.05558)
Second(PI/4) = (1.59773,-1.49059,-2.05558)
Second(3PI/4) = (-0.719886,2.06309,-2.05558)
Entity Plane = (0.811652 * X + 0.529339 * Y + 0.247025 * Z + -2.89372)
------ Specific Circle Properties
Normal = (0.811652,0.529339,0.247025)
Center = (2,1,3)
Radius = 3.0
Thickness = 1.5
Use the Q-"Quit" operation to exit:
Stop modifying of the circle properties
Example of Working with the Circular Arc
Example of Working with the Ellipse Object
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|