Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Working with Loops of Hatches

A hatch can have multiple loops that form outer and inner contours, and the loops can form the hatch boundary. Each loop is a planar contour created from planar entities of the following types: line, circle, ellipse, circular arc, elliptical arc, polyline, spline, region. The OdDbHatch object has the numberOfLoops() appendLoop(), insertLoopAt(), and getLoopAt() methods to work with loops.

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.

Number of loops

To find out the number of loops, use the numLoops() method, which requires no parameters and returns the number of loops in the hatch boundary as a positive integer value. If the number of loops is zero, the hatch does not have a boundary and the area is absent. For example:


odPrintConsoleString(L"\nNumber of loops %i", pHatch->numLoops());

Loop types

Each loop of a hatch has its type. It is set while the loop appending. Loop types are represented by the OdDbHatch::HatchLoopType enumeration and consist of the following values:


enum HatchLoopType {
  kDefault = 0                  // Not yet specified. 
  kExternal = 1                 // Defined by external entities. 
  kPolyline = 2                 // Defined by OdGe polyline. 
  kDerived = 4                  // Derived from a picked point. 
  kTextbox = 8                  // Defined by text. 
  kOutermost = 0x10             // Outermost loop. 
  kNotClosed = 0x20             // Open loop. 
  kSelfIntersecting = 0x40      // Self-intersecting loop. 
  kTextIsland = 0x80            // Text loop surrounded by an even number of loops. 
  kDuplicate = 0x100            // Duplicate loop. 
  kIsAnnotative = 0x200         // The bounding area is an annotative block. 
  kDoesNotSupportScale = 0x400  // The bounding type does not support scaling 
  kForceAnnoAllVisible = 0x800  // Forces all annotatives to be visible 
  kOrientToPaper = 0x1000       // Orients hatch loop to paper 
  kIsAnnotativeBlock = 0x2000   // Describes if the hatch is an annotative block. 
};

To find out the type of a separate loop use the loopTypeAt() method, which requires one integer value to specify the loop number and returns the loop type as an OdInt32 value. For example:


OdInt32 iLoopType = pHatch->loopTypeAt(2);
odPrintConsoleString(L"\nLoop type is %x", iLoopType);

Appending loops

To append loops to a hatch, use the appendLoop() method, which doesn't return a value and has three variants for defining: using the object IDs, an array of edges, or an array of points. The array can consist of one or more entities of the following type: line, circle, ellipse, circular arc, elliptical arc, polyline, spline, region. If the entity contours are open, their end points must coincide in the same contour.

Appending loops using object IDs

To append loops to a hatch using object IDs, use the appendLoop() method, which requires two parameters: an OdDbHatch::HatchLoopType parameter to indicate the type of bounding area and an object of the OdDbObjectIdArray class to indicate the object IDs that comprise the loop.

For example:


OdDbObjectIdArray loopIds;
OdDbEllipsePtr pEllipse = OdDbEllipse::createObject();
pEllipse->setDatabaseDefaults(pDb);
loopIds.push_back(bBTR->appendOdDbEntity(pEllipse));
OdGePoint3d centerPt = OdGePoint3d(5.0, 3.0, 0.0);
pEllipse->set(centerPt, OdGeVector3d::kZAxis, OdGeVector3d(3, 0., 0.), 0.5);
pHatch->appendLoop(OdDbHatch::kDefault, loopIds);

Appending loops using an array of edges

To append loops to a hatch using an array of edges, use the appendLoop() method, which requires two parameters: an OdDbHatch::HatchLoopType parameter to indicate loop type of the hatch and an object of the EdgeArray class to indicate an array of edges that will create a loop. Loop types are represented by the OdDbHatch::HatchLoopType enumeration (see above). For example:


OdGeCircArc2d *cirArc = new OdGeCircArc2d();
OdGePoint3d point;
point.x = 10;
point.y = 15;
OdGePoint2d cenPt(point.x, point.y);
cirArc->setCenter(cenPt);
cirArc->setRadius(5);
cirArc->setAngles(0.0, Oda2PI);
EdgeArray edgePtrs;
edgePtrs.append(cirArc);
pHatch->appendLoop(OdDbHatch::kDefault, edgePtrs);

Appending loops using an array of points

To append loops to a hatch using an array of points, use the appendLoop() method, which requires three parameters: an OdDbHatch::HatchLoopType parameter to indicate the loop type of the hatch, object of the OdGePoint2dArray class to indicate an array of points, and an object of the OdGeDoubledArray class to indicate bulges corresponding to the vertices array. Loop types are represented by the OdDbHatch::HatchLoopType enumeration (see above). For example:


OdGePoint2dArray  vertexPts;
OdGeDoubleArray   vertexBulges;
vertexPts.resize(4);
OdGePoint3d point;
double delta = 2;
point.x = 10;
point.y = 10;
vertexPts[0].set(point.x + delta,   point.y - delta);
vertexPts[1].set(point.x + delta*5, point.y - delta);
vertexPts[2].set(point.x + delta*5, point.y - delta*5);
vertexPts[3].set(point.x + delta,   point.y - delta*5);
pHatch->appendLoop(OdDbHatch::kExternal | OdDbHatch::kPolyline, vertexPts, vertexBulges);

Inserting a loop to a specific index

To insert a loop into a specific index in the loop array of a hatch, use the insertLoopAt() method, which returns nothing and has three variants for defining just like the appendLoop() method: using an array of object IDs, an array of edges, or an array of points. The array can consist of one or more entities of the following type: line, circle, ellipse, circular arc, elliptical arc, polyline, spline, region. The next example demonstrates inserting a loop using an array of edges. This method requires three parameters: an integer value to indicate the index of the loop in the loop array, an OdDbHatch::HatchLoopType parameter to indicate the loop type of the hatch (see above), and an object of the EdgeArray class to indicate the array of edges that will create a loop:


OdGePoint3d point;
double delta = 2;
point.x = 10;
point.y = 10;
OdGePoint2d cenPt(point.x + delta*3, point.y - delta*3);
OdGeCircArc2d *cirArc = new OdGeCircArc2d();
cirArc->setCenter(cenPt);
cirArc->setRadius(delta);
cirArc->setAngles(0.0, Oda2PI);
EdgeArray edgePtrs;
edgePtrs.append(cirArc);
pHatch->insertLoopAt(1, OdDbHatch::kDefault, edgePtrs);

Getting a loop by a specific index

To get a hatch loop by a specific index of a loop in a loop array, use the getLoopAt() method, which has two variants for defining: getting the loop as an array of OdGeCurve2d pointers to the edges that comprise the loop, or getting the loop as an array of vertices that comprise the loop and the array of bulges corresponding to the vertices array.

Getting a loop by a specific index as an array of edges

To get a loop by a specific index as an array of edges, use the getLoopAt() method, which requires two parameters: an input integer value to indicate the loop index and an output pointer to the EdgeArray object to indicate the placement of the output loop. For example:


EdgeArray edgePtrs;
pHatch->getLoopAt(1, edgePtrs);
OdGeCurve2d *curv = edgePtrs.getAt(0);
if (curv->isClosed())
  odPrintConsoleString(L"\nCurve is closed");
else odPrintConsoleString(L"\nCurve is open");

Getting a loop by a specific index as an array of points

To get a loop by a specific index as an array of edges, use the getLoopAt() method, which requires three parameters: an input integer value to indicate the loop index, an output pointer to an OdGePoint2dArray object to indicate the placement for the output loop, and an output pointer to an OdGeDoubleArray object to indicate the placement for output bulges. For example:


OdGePoint2dArray  vertexPts;
OdGeDoubleArray   vertexBulges;
vertexPts.resize(4);
pHatch->getLoopAt(0, vertexPts, vertexBulges);
odPrintConsoleString(L"\nFirst point x= %f y= %f", vertexPts[0].x, vertexPts[0].y);

See Also

Overview of Hatches

Working with General Properties of Hatches

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 – 2022. Open Design Alliance. All rights reserved.