This example demonstrates displaying and modifying properties of a face object. This example uses a console menu that represents the following operations: getting and setting the zero, first, second, or third vertex [V]; switching the visibility of the zero, first, second, or third edge [E]; displaying the object properties, general properties, and specific properties [P]; and modifying the general entity properties [M].
The PrintFaceProperties() function requires a pointer to an existing face object and displays its properties. The function gets the specific properties using the getVertexAt() and isEdgeVisibleAt() methods. The function organizes a loop using an index from 0 to 3 in which it gets the coordinates of each vertex using the getVertexAt() method and checks the edge visibility using the isEdgeVisibilityAt() method. The function uses the AboutPoint3d() function for converting the coordinates of the zero, first, second, or third vertex to a string value. The AboutPoint3d() function requires an instance of the three-dimensional point to be converted as an argument and returns a string containing the X,Y,Z coordinates.
The PrintFaceProperties() function has the following implementation:
void PrintFaceProperties(OdDbFace* pFace)
{
OdInt16 index;
OdGePoint3d point;
for(index=0 ; index <= 3 ; index++)
{
pFace->getVertexAt(index, point);
wcout << L"\n Vertex(" << index << L") = " << AboutPoint3d(point)
<< L", Edge(" << index << ") is "
<< ((pFace->isEdgeVisibleAt(index)) ? L"visible" : L"invisible");
}
}
The ModifyFaceProperties() function requires a pointer to an existing face 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 that requires a reference to an instance of the three-dimensional point to be modified as an argument and returns 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 face properties using the PrintFaceProperties() function. When the user selects the [p] operation, the function displays only specific face properties.
When the user selects [V], the function requests the vertex index as a character '0', '1', '2', or '3' and checks the entered letter. Then, the function calculates the vertex index as the difference between the obtained letter code and the code of the '0' letter, gets the coordinates of the vertex corresponding to the calculated index using the getVertexAt() method, calls the EntryPoint3d() function for entry of the coordinates, and sets the returned point as the new face vertex using the setVertexAt() method if entry is successful.
When the user selects [E], the function inquires the edge index as a character '0', '1', '2', or '3' and checks the entered letter. Then, the function calculates the edge index as the difference between the obtained letter code and code of the '0' letter and requests the new visibility status: S-show or H-hide. When the user enters the 'S' letter, the function calls the makeEdgeVisibleAt() method and passes to it the calculated edge index as an argument. When the user enters the 'H' letter, the function calls the makeEdgeInvisibleAt() method and passes to it the calculated edge index as an argument. After that, the function displays the edge visibility using the isEdgeVisibilityAt() method for the calculated edge index.
When the user selects [M], the function calls the ModifyEntityProperties() function and passes to it the pointer to the face object for modifying its general entity properties. After modifying, the function displays all face properties using the [P] operation.
When the user selects [Q], the function ends the loop and returns in the calling function.
The ModifyFaceProperties() function has the following implementation:
#include "..\Common\DemoMain.h"
#include "DbFace.h"
#include <iostream>
using namespace std;
OdString AboutPoint3d(const OdGePoint3d& point);
bool EntryPoint3d(OdGePoint3d& point);
void PrintEntityProperties(OdDbEntity *pEntity);
void ModifyEntityProperties(OdDbEntity *pEntity);
void ModifyFaceProperties(OdDbFace* pFace)
{
wchar_t ch = L'\0';
OdInt16 index;
OdGePoint3d point;
wcout << L"\n\nStart modifying of the face properties";
do {
switch(ch)
{
case L'M': // Modify the general properties
case L'm':
ModifyEntityProperties(pFace);
case L'P': // Print the whole properties
wcout << L"\nH=" << pFace->handle().ascii();
wcout << L"\n ------ Common Object Properties";
PrintObjectProperties(pFace);
wcout << L"\n ------ General Entity Properties";
PrintEntityProperties(pFace);
case L'p': // Print the specific properties
wcout << L"\n ------ Specific Face Properties";
PrintFaceProperties(pFace);
wcout << L"\n";
break;
case L'V': // Set the vertex coordinates
case L'v':
wcout << L"\nSelect the vertex [0,1,2,3]:>";
wcin >> ch;
if(ch == L'0' || ch == L'1' || ch == L'2' || ch == L'3')
{
index = (OdInt16)(ch - L'0');
pFace->getVertexAt(index, point);
wcout << L"Vertex(" << index << L")";
if(EntryPoint3d(point))
pFace->setVertexAt(index, point);
}
else wcout << L"Error: Incorrect vertex index\n";
break;
case L'E': // Set the edge visibility
case L'e':
wcout << L"\nSelect the edge [0,1,2,3]:>";
wcin >> ch;
if(ch == L'0' || ch == L'1' || ch == L'2' || ch == L'3')
{
index = (OdInt16)(ch - L'0');
wcout << "Switch the edge visibility [S-show|H-hide]:>";
wcin >> ch;
if(ch == L'S' || ch == L's') pFace->makeEdgeVisibleAt(index);
else if(ch == L'H' || ch == L'h') pFace->makeEdgeInvisibleAt(index);
wcout << L"Edge(" << index << L") is "
<< ((pFace->isEdgeVisibleAt(index)) ? L"visible\n" : L"invisible\n");
}
else wcout << L"Error: Incorrect edge index\n";
break;
case L'\0': // Skip an action
break;
default:
wcout << L"Error: Incorrect operation\n";
}
wcout << L"\nE. Set the edge visibility";
wcout << L"\nV. Set the vertex coordinates";
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 face properties\n";
}
Testing gives the following results:
Start modifying of the face properties
E. Set the edge visibility
V. Set the vertex coordinates
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 Face Properties
Vertex(0) = (0,0,0), Edge(0) is visible
Vertex(1) = (0,0,0), Edge(1) is visible
Vertex(2) = (0,0,0), Edge(2) is visible
Vertex(3) = (0,0,0), Edge(3) is visible
When the operation is V-"Set the vertex coordinates":
Select the vertex [0,1,2,3]:>0
Vertex(0)
Current coordinates: (0,0,0)
Entry X-coordinate:>1.4
Entry Y-coordinate:>0.8
Entry Z-coordinate:>0.2
Select the vertex [0,1,2,3]:>1
Vertex(1)
Current coordinates: (0,0,0)
Entry X-coordinate:>5.4
Entry Y-coordinate:>2.5
Entry Z-coordinate:>1.3
Select the vertex [0,1,2,3]:>2
Vertex(2)
Current coordinates: (0,0,0)
Entry X-coordinate:>9.4
Entry Y-coordinate:>9.1
Entry Z-coordinate:>-2.2
Select the vertex [0,1,2,3]:>3
Vertex(3)
Current coordinates: (0,0,0)
Entry X-coordinate:>2.1
Entry Y-coordinate:>5.8
Entry Z-coordinate:>1.3
Select the vertex [0,1,2,3]:>4
Error: Incorrect vertex index
When the operation is E-"Set the edge visibility":
Select the edge [0,1,2,3]:>0
Switch the edge visibility [S-show|H-hide]:>s
Edge(0) is visible
Select the edge [0,1,2,3]:>1
Switch the edge visibility [S-show|H-hide]:>h
Edge(1) is invisible
Select the edge [0,1,2,3]:>2
Switch the edge visibility [S-show|H-hide]:>s
Edge(2) is visible
Select the edge [0,1,2,3]:>3
Switch the edge visibility [S-show|H-hide]:>h
Edge(3) is invisible
Select the edge [0,1,2,3]:>4
Error: Incorrect edge index
When the operation is P-"Print all properties":
H=40
------ Common Object Properties
Type: AcDbFace
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: Nonplanar, Visible, Cast Shadows, Receive Shadows
------ Specific Face Properties
Vertex(0) = (1.4,0.8,0.2), Edge(0) is visible
Vertex(1) = (5.4,2.5,1.3), Edge(1) is invisible
Vertex(2) = (9.4,9.1,-2.2), Edge(2) is visible
Vertex(3) = (2.1,5.8,1.3), Edge(3) is invisible
Use the Q-"Quit" operation to exit:
Stop modifying of the face properties
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|