Exemplo n.º 1
0
void extractVertexCoords(const AcDbObjectId& objID, std::map<std::wstring, AcGePoint3d>& m_3dPoints)
{
	AcDbEntity* pEnt = nullptr;
	acdbOpenObject(pEnt, objID, AcDb::kForRead);

	             /*****Pline****/
	if (pEnt->isA() == AcDbPolyline::desc())
	{
		AcDbPolyline* pLine = static_cast<AcDbPolyline*>(pEnt);
		pEnt->close();
		acdbOpenObject(pLine, objID, AcDb::kForRead);
		AcGePoint3d vertex;
		for (LONGLONG i = 0; i < pLine->numVerts(); i++)
		{
			pLine->getPointAt(i, vertex);
			std::wstring w_nrPunct = std::to_wstring(i + 1);
			m_3dPoints.insert(std::pair<std::wstring, AcGePoint3d>(w_nrPunct, vertex));
		}

		pLine->close();	
	}

	            /******P2dLine****/
	else if (pEnt->isA() == AcDb2dPolyline::desc())
	{
		AcGePoint3d point;
		AcDbObjectId vertexID;
		AcDb3dPolylineVertex* pVertex = nullptr;

		AcDb2dPolyline* p2dline = static_cast<AcDb2dPolyline*>(pEnt);
		pEnt->close();

		acdbOpenObject(p2dline, objID, AcDb::kForRead);
		AcDbObjectIterator* pIterator = p2dline->vertexIterator();
		for (pIterator->start(); !pIterator->done(); pIterator->step())
		{
			LONGLONG contor = 1;
			vertexID = pIterator->objectId();
			acdbOpenObject(pVertex, vertexID, AcDb::kForRead);
			point = pVertex->position();

			std::wstring w_nrPunct = std::to_wstring(contor);
			contor++;
			m_3dPoints.insert(std::pair<std::wstring, AcGePoint3d>(w_nrPunct, point));

			pVertex->close();
		}
		delete pIterator;
		p2dline->close();
	}

	         /***********P3dLine**************/
	else if (pEnt->isA() == AcDb3dPolyline::desc())
	{
		AcGePoint3d point;
		AcDbObjectId vertexID;
		AcDb3dPolylineVertex* pVertex = nullptr;

		AcDb3dPolyline* p3dline = static_cast<AcDb3dPolyline*>(pEnt);
		pEnt->close();

		acdbOpenObject(p3dline, objID, AcDb::kForRead);
		AcDbObjectIterator* pIterator = p3dline->vertexIterator();

		for (pIterator->start(); !pIterator->done(); pIterator->step())
		{
			LONGLONG contor = 1;
			vertexID = pIterator->objectId();
			acdbOpenObject(pVertex, vertexID, AcDb::kForRead);
			point = pVertex->position();

			std::wstring w_nrPunct = std::to_wstring(contor);

			m_3dPoints.insert(std::pair<std::wstring, AcGePoint3d>(w_nrPunct, point));
			pVertex->close();
		}
		delete pIterator;
		p3dline->close();
	}
	else
	{
		pEnt->close();
		acutPrintf(_T("\nObiectul selectat nu este o polilinie"));
	}

}