This example demonstrates displaying and modifying properties of a planar solid object. This example uses a console menu that represents the following operations: getting and setting the zero vertex [0], first vertex [1], second vertex [2], third vertex [3], normal [N], thickness [T]; displaying the object properties, general properties, and specific properties [P]; and modifying the general entity properties [M].
The PrintSolid2dProperties() function requires a pointer to an existing planar solid object and displays its properties. The function gets the specific properties using the getPointAt(), normal(), and thickness() methods. The function uses the AboutPoint3d() function for converting the coordinates of the zero, first, second, or third vertex 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 PrintSolid2dProperties() function has the following implementation:
void PrintSolid2dProperties(OdDbSolid* pSolid)
{
OdGePoint3d vertex;
pSolid->getPointAt(0, vertex);
wcout << L"\n Vertex(0) = " << AboutPoint3d(vertex);
pSolid->getPointAt(1, vertex);
wcout << L"\n Vertex(1) = " << AboutPoint3d(vertex);
pSolid->getPointAt(2, vertex);
wcout << L"\n Vertex(2) = " << AboutPoint3d(vertex);
pSolid->getPointAt(3, vertex);
wcout << L"\n Vertex(3) = " << AboutPoint3d(vertex);
wcout << L"\n Normal = " << AboutVector3d(pSolid->normal());
wcout << L"\n Thickness = " << pSolid->thickness();
}
The ModifySolid2dProperties() function requires a pointer to an existing planar solid 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 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 specific planar solid properties using the PrintSolid2dProperties() function. When the user selects the [p] operation, the function displays only specific planar solid properties.
When the user selects [0], [1], [2], or [3], the function calculates the vertex index as the difference between the obtained letter code and code of the '0' letter, gets the coordinates of the vertex corresponding to the calculated index using the getPointAt() method, calls the EntryPoint3d() function for entry of its coordinates, and sets the returned point as the new solid vertex using the setPointAt() method if entry is successful.
When the user selects the [N] operation, the function gets the normal to the plane of the solid 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 [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 [M], the function calls the ModifyEntityProperties() function and passes to it the pointer to the planar solid object for modifying its general entity properties. After modifying, the function displays all solid properties using the [P] operation.
When the user selects [Q], the function ends the loop and returns in the calling function.
The ModifySolid2dProperties() function has the following implementation:
#include "..\Common\DemoMain.h"
#include "DbSolid.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 ModifySolid2dProperties(OdDbSolid* pSolid)
{
wchar_t ch = L'\0';
OdInt16 index;
double value;
OdGePoint3d vertex;
OdGeVector3d normal;
wcout << L"\n\nStart modifying of the planar solid properties";
do {
switch(ch)
{
case L'M': // Modify the general properties
case L'm':
ModifyEntityProperties(pSolid);
case L'P': // Print the whole properties
wcout << L"\nH=" << pSolid->handle().ascii();
wcout << L"\n ------ Common Object Properties";
PrintObjectProperties(pSolid);
wcout << L"\n ------ General Entity Properties";
PrintEntityProperties(pSolid);
case L'p': // Print the specific properties
wcout << L"\n ------ Specific Planar Solid Properties";
PrintSolid2dProperties(pSolid);
wcout << L"\n";
break;
case L'N': // Set the normal
case L'n':
normal = pSolid->normal();
if(EntryVector3d(normal))
{
pSolid->setNormal(normal);
wcout << L"Normal is set to " << AboutVector3d(pSolid->normal()) << L"\n";
}
break;
case L'T': // Set the thickness
case L't':
wcout << L"\nCurrent thickness = " << pSolid->thickness()
<< L"\nEntry a new thickness [t>0-along normal|t<0-opposite normal]:>";
wcin >> value;
if(!wcin.fail() && wcin.peek() == 10)
{
pSolid->setThickness(value);
wcout << L"Thickness is set to: " << pSolid->thickness() << L"\n";
}
else { wcin.clear(); wcin.sync(); wcout << L"Error: Invalid entered value\n"; }
break;
case L'0': // Set the vertex point
case L'1':
case L'2':
case L'3':
index = (OdInt16)(ch - L'0');
pSolid->getPointAt(index, vertex);
wcout << L"Vertex(" << index << L")";
if(EntryPoint3d(vertex))
pSolid->setPointAt(index, vertex);
break;
case L'\0': // Skip an action
break;
default:
wcout << L"Error: Incorrect operation\n";
}
wcout << L"\nN. Set the normal";
wcout << L"\nT. Set the thickness";
wcout << L"\n0,1,2,3. Set the solid vertex";
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 planar solid properties\n";
}
Testing gives the following results:
Start modifying of the planar solid properties
N. Set the normal
T. Set the thickness
0,1,2,3. Set the solid vertex
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 Planar Solid Properties
Vertex(0) = (0,0,0)
Vertex(1) = (0,0,0)
Vertex(2) = (0,0,0)
Vertex(3) = (0,0,0)
Normal = (0,0,1)
Thickness = 0
When the operation is 0-"Set the vertex 0":
Vertex(0)
Current coordinates: (0,0,0)
Entry X-coordinate:>3.1
Entry Y-coordinate:>1.3
Entry Z-coordinate:>1.0
When the operation is 1-"Set the vertex 1":
Vertex(1)
Current coordinates: (0,0,0)
Entry X-coordinate:>1.4
Entry Y-coordinate:>6.2
Entry Z-coordinate:>1.0
When the operation is 2-"Set the vertex 2":
Vertex(2)
Current coordinates: (0,0,0)
Entry X-coordinate:>8.4
Entry Y-coordinate:>4.2
Entry Z-coordinate:>1.0
When the operation is 3-"Set the vertex 3":
Vertex(3)
Current coordinates: (0,0,0)
Entry X-coordinate:>7.6
Entry Y-coordinate:>8.9
Entry Z-coordinate:>1.0
When the operation is N-"Set the normal":
Current vector directions: (0,0,1)
Entry X-direction:>0.9
Entry Y-direction:>1.2
Entry Z-direction:>0.8
Normal is set to (0.529412,0.705882,0.470588)
When the operation is T-"Set the thickness":
Current thickness = 0
Entry a new thickness [t>0-along normal|t<0-opposite normal]:>2.1
Thickness is set to: 2.1
When the operation is P-"Print all properties":
H=40
------ Common Object Properties
Type: AcDbSolid
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
------ Specific Planar Solid Properties
Vertex(0) = (3.1,1.3,1)
Vertex(1) = (1.4,6.2,1)
Vertex(2) = (8.4,4.2,1)
Vertex(3) = (7.6,8.9,1)
Normal = (0.529412,0.705882,0.470588)
Thickness = 2.1
Use the Q-"Quit" operation to exit:
Stop modifying of the planar solid properties
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.
|