A multi-polygon can have multiple loops that form the multi-polygon boundary. Each loop is a planar contour created from planar entities of the following types:
The OdDbMPolygon
class has the
following methods to work with loops:
numMPolygonLoops()
appendLoopFromBoundary()
appendMPolygonLoop()
createLoopsFromBoundaries()
createLoops()
getMPolygonLoopAt()
To find out the number of loops, use the
numMPolygonLoops()
method, which requires no parameters and returns the number of loops in the multi-polygon
boundary as a positive integer value. If the number of loops is zero, the
multi-polygon does not have loops. For example:
odPrintConsoleString(L"\nNumber of loops %i", pMPolygon->numMPolygonLoops());
odPrintConsoleString(L"\nNumber of invalid loops %i", pMPolygon->numMPolygonLoops() - pMPolygon->hatch()->numLoops());
To append loops to a multi-polygon, use the
appendLoopFromBoundary()
method, which returns an OdResult
value and has three variants for using
either an OdDbCircle
, OdDbPolyline
or OdDb2dPolyline
. Input entities must have a closed boundary. A loop
is not appended if it intersects with the existing loops. To append such
a loop, specify the parameter: excludeCrossing = false
.
To append a loop to a multi-polygon, you can also use the
appendMPolygonLoop()
method, which returns an OdResult
value and has an array of points as an
input parameter.
To create a multi-polygon with many loops at once, use one of the following two methods:
createLoopsFromBoundaries()
— Creates loops from an array of object IDs, where one object is one
loop.
createLoops()
— Creates loops from an array that contains arrays of points.
Note: These methods can be used only if an
OdDbMPolygon
object does not have loops.
To append loops to a multi-polygon using object IDs, use the
appendLoopFromBoundary()
method, which requires three parameters:
OdDbCircle
, OdDbPolyline
or
OdDb2dPolyline
) from which a loop is createdFor example:
OdDbBlockTableRecordPtr modelSpace = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
OdDbMPolygonPtr mpolygon = OdDbMPolygon::createObject();
mpolygon->setDatabaseDefaults(pDb);
mpolygon->setPattern(OdDbHatch::kPreDefined, L"SOLID");
modelSpace->appendOdDbEntity(mpolygon);
OdDbCirclePtr circle = OdDbCircle::createObject();
circle->setCenter(OdGePoint3d(10, 10, 0));
circle->setRadius(5.0);
OdResult result = mpolygon->appendLoopFromBoundary(circle);
To append loops to a multi-polygon using an array of points, use the
appendMPolygonLoop()
method, which requires four parameters:
OdGePoint2dArray
class to specify an array of
points (vertices)OdGeDoubledArray
class to specify bulges
corresponding to the vertices arrayFor example:
OdDbBlockTableRecordPtr modelSpace = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
OdDbMPolygonPtr mpolygon = OdDbMPolygon::createObject();
mpolygon->setDatabaseDefaults(pDb);
mpolygon->setPattern(OdDbHatch::kPreDefined, L"SOLID");
modelSpace->appendOdDbEntity(mpolygon);
OdGePoint2dArray vertices;
vertices.append(OdGePoint2d(-200, 200));
vertices.append(OdGePoint2d(-200, -200));
vertices.append(OdGePoint2d(200, -200));
vertices.append(OdGePoint2d(200, 200));
vertices.append(OdGePoint2d(-200, 200));
OdGeDoubleArray bulges;
bulges.resize(5, 0.0);
OdResult result = mpolygon->appendMPolygonLoop(vertices, bulges);
To insert a loop at a specific index in the loop array of a multi-polygon, use the
insertMPolygonLoopAt()
method, which returns an
OdResult
value and requires five parameters:
OdGePoint2dArray
class to specify an array of
points
OdGeDoubledArray
class to specify bulges
corresponding to the vertices array
For example:
OdDbBlockTableRecordPtr modelSpace = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
OdDbMPolygonPtr mpolygon = OdDbMPolygon::createObject();
mpolygon->setDatabaseDefaults(pDb);
mpolygon->setPattern(OdDbHatch::kPreDefined, L"SOLID");
modelSpace->appendOdDbEntity(mpolygon);
OdGePoint2dArray vertices;
vertices.append(OdGePoint2d(-200, 200));
vertices.append(OdGePoint2d(-200, -200));
vertices.append(OdGePoint2d(200, -200));
vertices.append(OdGePoint2d(200, 200));
vertices.append(OdGePoint2d(-200, 200));
OdGeDoubleArray bulges;
bulges.resize(5, 0.0);
OdResult result = mpolygon->insertMPolygonLoopAt(1, vertices, bulges);
To append loops to a multi-polygon using an array of points, use the
createLoops()
method, which requires five parameters:
OdGePoint2dArrayArray
class to specify an array
of arrays of points (vertices)
OdArray<OdGeDoubleArray>
class to specify
an array of bulges corresponding to the vertices array
OdIntArray
class to specify an array of indices
that indicates the elements from the array of arrays of points that led to errors
while creating loops
For example:
OdDbBlockTableRecordPtr modelSpace = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
OdDbMPolygonPtr mpolygon = OdDbMPolygon::createObject();
mpolygon->setDatabaseDefaults(pDb);
mpolygon->setPattern(OdDbHatch::kPreDefined, L"SOLID");
modelSpace->appendOdDbEntity(mpolygon);
OdGePoint2dArrayArray verticesArr;
OdGePoint2dArray vertices1, vertices2;
vertices1.append(OdGePoint2d(0, 0));
vertices1.append(OdGePoint2d(10, 0));
vertices1.append(OdGePoint2d(5, 10));
vertices2.append(OdGePoint2d(20, 0));
vertices2.append(OdGePoint2d(30, 0));
vertices2.append(OdGePoint2d(25, 10));
verticesArr.append(vertices1);
verticesArr.append(vertices2);
OdArray<OdGeDoubleArray> bulgesArr;
OdGeDoubleArray bulges1, bulges2;
bulges1.resize(3, 0.0);
bulges2.resize(3, 0.0);
bulgesArr.append(bulges1);
bulgesArr.append(bulges2);
OdIntArray rejectedObjs;
OdResult result = mpolygon->createLoops(verticesArr, bulgesArr, rejectedObjs);
To append loops to a multi-polygon using an array of object IDs, use the
createLoopsFromBoundaries()
method, which requires four parameters:
OdDbObjectIdArray
class to specify the object IDs
of the objects that comprise the loops
OdIntArray
class to specify indices from the
array of arrays of points that led to errors while creating loops
For example:
OdDbBlockTableRecordPtr modelSpace = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
OdDbMPolygonPtr mpolygon = OdDbMPolygon::createObject();
mpolygon->setDatabaseDefaults(pDb);
mpolygon->setPattern(OdDbHatch::kPreDefined, L"SOLID");
modelSpace->appendOdDbEntity(mpolygon);
OdDbCirclePtr circle1 = OdDbCircle::createObject();
circle1->setCenter(OdGePoint3d(10, 10, 0));
circle1->setRadius(5.0);
OdDbCirclePtr circle2 = OdDbCircle::createObject();
circle2->setCenter(OdGePoint3d(200, 200, 0));
circle2->setRadius(5.0);
OdDbObjectIdArray arrId;
OdIntArray rejectedObjs;
arrid.append(circle1->objectId());
arrid.append(circle2->objectId());
OdResult result = mpolygon-> createLoopsFromBoundaries (arrId, rejectedObjs);
To get a multi-polygon loop by using a specific index in the loop array, use the
getMPolygonLoopAt()
method.
This method gets the loop as an array of vertices that the loop consists of
and the array of bulges corresponding to the vertices array.
The getMPolygonLoopAt()
method requires three parameters:
OdGePoint2dArray
object to receive the
placement of the output loop
OdGeDoubleArray
object to receive the
placement of the output bulges
For example:
OdGePoint2dArray vertexPts;
OdGeDoubleArray vertexBulges;
OdResult result = pMPolygon->getMPolygonLoopAt (0, vertexPts, vertexBulges);
Working with the Loop Direction
Examples of Working with Multi-Polygons
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|