You can create your own patterns for hatch entities. To create a pattern, use an object of the OdHatchPattern class.
Note: This section describes creating a pattern of the kCustomDefined type. These user defined patterns are not of the kUserDefined pattern type.
A pattern of a classic hatch object consists of dashes (which are represented by the OdHatchPatternLine class) that replicate according to an offset relative to a base point inside the hatch boundary. A dash is an infinite line that is limited by the contour that bounds the hatch area. Each of the following dashes shifts according to an offset from the previous dash in the direction of replication.
A dash can be rotated at an angle counterclockwise relative to a horizontal line and can be a solid line or broken line. The shape of a dash is defined by a sequence of lengths. If a length value is positive, the dash is drawn. If a length value is negative, the dash is not drawn. A combination of positive and negative length values in a sequence defines the number of broken lines and dots within the dash, when it is drawn in the pattern. If the sequence of lengths is empty, the dash is a solid line.
Parts of a dash placed outside of a hatch boundary are invisible. Parameters of a dash are the base point, offset, angles, and dash lengths.
The base point defines the two-dimensional coordinates (X0,Y0) relative to the origin of the coordinate system for the point from which the dash is drawn. The base point begins the sequence of broken lines. The X0-coordinate defines the shift to the base point of a dash in the direction of the x-axis. The Y0-coordinate defines the shift to the base point of a dash in the direction of the y-axis. If the base point is (0,0), the dash begins in the origin of the coordinate system.
The offset defines the two-dimensional displacement from the base point of the next dash relative to the base point of the previous dash. The x- and y-displacement define the offset to the next base points in the direction of the replication of dashes; x- and y-displacement cannot be equal to zero simultaneously.
The angle defines the rotation of a dash counterclockwise relative to the x-axis in the range 0 to 2PI radians.
A pattern definition can contain more than one dash definition, each with different parameters that generates its own sequence of dash replications inside the hatch boundary. Angles, directions, offsets, and lengths of dashes can be different with each replication. This allows you to develop different shapes from dashes using a user-defined pattern. For example, the following pattern requires three dash definitions.
Continuing the example above, the following code creates the pattern and applies it to the hatch entity:
// Define a custom hatch pattern OD_T("MY_TRIANGLE")
OdHatchPattern triangles;
OdHatchPatternLine line;
// Define first line
line.m_dLineAngle = 0.0;
line.m_patternOffset = OdGeVector2d(0, 0.2);
line.m_dashes.push_back(-0.1);
line.m_dashes.push_back(0.1);
// Add line to pattern
triangles.push_back(line);
// Define second line
line.m_dLineAngle = 1.57;
line.m_patternOffset = OdGeVector2d(0, 0.2);
line.m_dashes.clear();
line.m_dashes.push_back(0.1);
line.m_dashes.push_back(-0.1);
// Add line to pattern
triangles.push_back(line);
// Define third line
line.m_dLineAngle = 0.785;
line.m_basePoint = OdGePoint2d(-0.1, 0);
line.m_dashes.clear();
line.m_dashes.push_back(0.1414);
line.m_dashes.push_back(-0.1414);
line.m_patternOffset = OdGeVector2d(-0.1414, 0.1414);
// Add line to pattern
triangles.push_back(line);
// Register the pattern
pDb->appServices()->patternManager()->appendPattern(OdDbHatch::kCustomDefined,
OD_T("MY_TRIANGLE"), triangles); //pDb variable stores a pointer to the database object
// Create an associative custom defined hatch
OdDbHatchPtr pHatch = OdDbHatch::createObject();
pHatch->setDatabaseDefaults(pDb);
OdDbObjectId hatchId = bBTR->appendOdDbEntity(pHatch); // bPTR stores a pointer to the block table record
// Set some properties
pHatch->setAssociative(true);
pHatch->setDatabaseDefaults(pDb); // make hatch aware of DB for the next call
pHatch->setPattern(OdDbHatch::kCustomDefined, OD_T("MY_TRIANGLE"));
pHatch->setHatchStyle(OdDbHatch::kNormal);
// Define the loop
OdDbObjectIdArray loopIds;
OdDbCirclePtr pCircle = OdDbCircle::createObject();
pCircle->setDatabaseDefaults(pDb);
loopIds.push_back(bBTR->appendOdDbEntity(pCircle));
centerPt.x = 0 ;
centerPt.y = 0;
OdGePoint3d centerPt ;
pCircle->setCenter(centerPt);
pCircle->setRadius(20);
// Append the loop to the hatch
pHatch->appendLoop(OdDbHatch::kDefault, loopIds);
After this you will have a hatch that is bounded by a circle and filled with triangles.
Working with General Properties of Hatches
Working with Pattern Properties of Hatches
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|