The OdDbHatch object implements the hatch entity and is derived from the OdDbEntity object, inheriting all properties and methods of the standard entities interface on which it expands the properties and methods for working with hatches.
The OdDbHatch object has the hatchObjectType(), setHatchObjectType(), hatchStyle(), setHatchStyle(), associative(), setAssociative(), originPoint(), setOriginPoint(), normal(), setNormal() and getArea() methods to work with general hatch parameters. In the examples below, pDb variable stores a pointer to the database object, bPTR stores a pointer to the block table record, and the pHatch variable stores the reference to a hatch entity.
There are two types of hatches. Classic hatches can be a pattern of lines or a solid. Another type of hatch is a gradient hatch. To get the hatch object type, use the hatchObjectType() method, which requires no parameters and returns the hatch object type as a value from the OdDbHatch::HatchObjectType enumeration:
enum HatchObjectType {
kHatchObject = 0, // Defines a classic hatch object that is filled with a pattern formed by dashes.
kGradientObject = 1 // Defines a gradient hatch object that is filled by a gradient.
};
For example:
if (pHatch->hatchObjectType() == 0)
odPrintConsoleString(L"\npHatch is hatch object");
else odPrintConsoleString(L"\npHatch is gradient object");
To set the hatch object type, use the setHatchObjectType() method, which requires one parameter — hatch object type. The hatch object type is represented by the OdDbHatch::HatchObjectType enumeration (see above). For example:
pHatch->setHatchObjectType(OdDbHatch::HatchObjectType::kGradientObject);
To get the hatch style, use the hatchStyle() method, which requires no parameters and returns the hatch style as a value from the OdDbHatch::HatchStyle enumeration:
enum HatchStyle {
kNormal = 0, // Fills the area within the boundary from the outer loop to the inner loop, then switches the hatching on and off between even and uneven inner loops.
kOuter = 1, // Fills the area within the boundary only from the outer loop to the first inner loop and skips other inner loops.
kIgnore = 2 // Fills the area within the boundary through all inner loops and ignores the internal structure of loops.
};
For example:
odPrintConsoleString(L"\nHatch style is %i", pHatch->hatchStyle());
To set the hatch style, use the setHatchStyle() method, which requires one parameter — hatch style. The hatch style is represented by the OdDbHatch::HatchStyle enumeration (see above). For example:
pHatch->setHatchStyle(OdDbHatch::HatchStyle::kNormal);
The result of applying different hatch styles depends on flags of the hatch loops (see Working with Loops of Hatches).
Text islands are never hatched.
Hatch associativity determines whether the hatch is associative with entities that form the hatch boundary. To get the associativity property, use the associative() method, which requires no parameters and returns the associativity property as a boolean value. The method returns True if the hatch is associative or false if the hatch is not associative.
For example:
if (pHatch->associative())
odPrintConsoleString(L"\npHatch is associative");
else odPrintConsoleString(L"\npHatch is not associative");
To set or unset the associative property, use the setAssociative() method, which requires one boolean parameter as the associative flag. For example:
pHatch->setAssociative(true);
To find out the area of a hatch, use the getArea() method, which requires one double parameter to specify the output value of the hatch area. The method returns eOk if the method performed the operations correctly or OdResult error code if an error occurs. The hatch entity must have a loop.
For example:
double area;
pHatch->getArea(area);
odPrintConsoleString(L"\nArea of pHatch %f", area);
To get the normal of a hatch, use the normal() method, which requires no parameters and returns the hatch normal as an OdGeVector3d object.
For example:
OdGeVector3d normal = pHatch->normal();
odPrintConsoleString(L"\nNormal x= %f y= %f z= %f", normal.x, normal.y, normal.z);
To set a new normal, use the setNormal() method, which requires one OdGeVector3d parameter as a new normal vector. For example:
OdGeVector3d newNormal;
newNormal.x = 1.0;
newNormal.y = 2.0;
newNormal.z = 3.0;
pHatch->setNormal(newNormal);
Hatch elevation shows the distance from the origin of coordinates to the hatch plane along the normal. To get the hatch elevation, use the elevation() method, which requires no parameters and returns the distance as a double value. A positive value defines the elevation in the direction to the normal. A negative value defines the elevation in the opposite direction to the normal.
For example:
odPrintConsoleString(L"\nElevation of pHatch %f", pHatch->elevation());
To set a new elevation to a hatch, use the setElevation method, which requires one double parameter as a new elevation value. For example:
pHatch3->setElevation(13.5);
Working with Pattern Properties of Hatches
Working with Gradient Properties of Hatches
Working with User-Defined Patterns of Hatches
Example of Working with Hatches
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|