Пример #1
0
String GetSelectedExtent() {
  ads_name selection;
  int returnValue = acedSSGet(_T("I"), NULL, NULL, NULL, selection);
  if (returnValue == RTCAN) return 0;
  if (returnValue != RTNORM) {
    return L"";
  }

  if (acedSSSetFirst(selection, NULL) != RTNORM) {
    acedSSFree(selection);
    return L"";
  }
  ads_name element;
  acedSSName(selection, 0, element);
  acedSSFree(selection);
  
  AcDbObjectId idEntity;
  if (acdbGetObjectId(idEntity, element) != Acad::eOk) {
    acedSSFree(element);
    return L"";
  }
  
  AcDbEntity * entity;
  if ((acdbGetObjectId(idEntity, element) != Acad::eOk) || 
      (acdbOpenObject(entity, idEntity, AcDb::kForRead) != Acad::eOk)) {
    
    acedSSFree(element);
    return L"";
  }
  
  acedSSFree(element);
  
  if (!entity->isKindOf(AcDbPolyline::desc())) return L"";
  
  AcDbPolyline * poly = static_cast<AcDbPolyline*>(entity);
  if (!poly->isClosed()) return 0;
  
  String extent = L"POLYGON((";
  AcGePoint2d start;
  AcGePoint2d current;
  for (int i = 0; i < poly->numVerts(); i++) {
    poly->getPointAt(i, current);
    
    if (i > 0) {
      extent += L", ";
    } else {
      start = current;
    }
    extent += Round(current.x, 0) + L" " + Round(current.y, 0);
  }
  if (!start.isEqualTo(current)) {
    extent += L", " + Round(start.x, 0) + L" " + Round(start.y, 0);
  }
  
  extent += L"))";
  
  poly->close();
  
  return extent;
}
void AcDbDoubleClickEditPline::startEdit(AcDbEntity *pEnt, AcGePoint3d clickpt)
{
	// Implement the startEdit notification handler to catch when
	// a user double-clicks a 'POLYLINE' entity
	
	// Get the Current Document
	AcApDocument *pDoc=acDocManager->curDocument(); 
	AcDbPolyline *pLine;
		
	// Cast the AcDbEntity pointer to AcDbPolyline
	if(pEnt->isKindOf(AcDbPolyline::desc()) == Adesk::kTrue)
		pLine=AcDbPolyline::cast(pEnt);
	else
	{
		acutPrintf("Error: Invalid AcDbPolyline Object");
		return;
	}
	
	acDocManager->lockDocument(pDoc,AcAp::kWrite);
	
	// Upgrade to write
	if(pLine->upgradeOpen()!=Acad::eOk)
	{
		acutPrintf("Error: Could Not open AcDbPolyline Object");
		return;
	}
	
	// iterate through all the vertices to find which
	// segment was clicked on, and place a vertex there.
	for(unsigned int c=0;c<pLine->numVerts()-1;c++)
	{
		AcGePoint3d pt1,pt2;
		pLine->getPointAt(c,pt1);
		pLine->getPointAt(c+1,pt2);
		AcGeVector3d lineVec(pt2-pt1),clickVec(clickpt-pt1),
			clickVec2(pt2-clickpt);
		double ang=lineVec.angleTo(clickVec);
		
		// This is the filter...
		// .05 (5% of lineVec length) is an arbitrary length...
		if((sin(ang)*clickVec.length()<.05*lineVec.length()) && 
			clickVec.length()<lineVec.length() && 
			clickVec2.length()<lineVec.length()) 
		{
			// Add the point Here!
			ads_point outPt;
			acdbWcs2Ecs(asDblArray(clickpt),outPt,asDblArray(pLine->normal()),Adesk::kFalse);	
			pLine->addVertexAt(c+1,asPnt2d(outPt));
			break;
		}
	}
	
	pLine->close();

	acDocManager->unlockDocument(pDoc);
	
	// invoking acedSSSetFirst(NULL,NULL) here will clear the
	// pickfirst selection, if desired (not With pline though).
	//acedSSSetFirst(NULL,NULL);
	
	// Update the graphics...
	pLine->draw();
	actrTransactionManager->flushGraphics();
	acedUpdateDisplay();
}
Пример #3
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"));
	}

}