2008/utils-Win32/HlrApi/samples/HlrArxSample/HlrArxSampleCommands.cpp
// Command TEST5 ask you to select entities on the AutoCAD DWG file, for a virtual viewport,
// and for HLR controls you want to apply to the HLR engine. Then the color of each resulting
// entities will depend of the originator entity. The function is going throw block definition
// to find the original entity which produced the edges, and assign its color to the edges.
// Its like test2, but works with clipping

Command TEST5 ask you to select entities on the AutoCAD DWG file, for a virtual viewport,
and for HLR controls you want to apply to the HLR engine. Then the color of each resulting
entities will depend of the originator entity. The function is going throw block definition
to find the original entity which produced the edges, and assign its color to the edges.
Its like test2, but works with clipping
Command TEST5 ask you to select entities on the AutoCAD DWG file for a virtual viewport and for HLR controls you want to apply to the HLR engine . Then the color of each resulting entities will depend of the originator entity . The function is going throw block definition to find the original entity which produced the edges and assign its color to the edges . Its like test2 but works with clipping
void asdktest5 () {
	ads_name ss, en ;
	if ( acedSSGet (NULL, NULL, NULL, NULL, ss) != RTNORM )
		return ;
	long n ;
	AcDbObjectId id ;
	AsdkHlrCollector collector ;
	acedSSLength (ss, &n) ;
	for ( int i =0 ; i < n ; i++ ) {
		acedSSName (ss, i, en) ;
		acdbGetObjectId (id, en) ;
		collector.addEntity (id) ;
	}
	acedSSFree (ss) ;
	AfxSetResourceHandle (_hdllInstance) ;
	CControlsDlg dlg ;
	dlg.mnControls =kProject | kEntity | kBlock | kHonorInternals ;
	if ( dlg.DoModal () != IDOK ) {
		AfxSetResourceHandle (acedGetAcadResourceInstance ()) ;
		return ;
	}
	AfxSetResourceHandle (acedGetAcadResourceInstance ()) ;
	int control =dlg.mnControls ;
	acutPrintf (ACRX_T("\nAbout to call hidden Line calculation")) ;
	acutPrintf (ACRX_T("\nCalling with %d Entities"), collector.getInputEntityIds ().logicalLength ()) ;
	acutPrintf (ACRX_T("\nkProject %s "), control & kProject ? ACRX_T("On") : ACRX_T("Off")) ;
	acutPrintf (ACRX_T("\nkShowAll %s "), control & kShowAll ? ACRX_T("On") : ACRX_T("Off")) ;
	acutPrintf (ACRX_T("\nkEntity %s "), control & kEntity  ? ACRX_T("On") : ACRX_T("Off")) ;
	acutPrintf (ACRX_T("\nkBlock %s "), control & kBlock  ? ACRX_T("On") : ACRX_T("Off")) ;
	acutPrintf (ACRX_T("\nkSubentity %s "), control & kSubentity  ? ACRX_T("On") : ACRX_T("Off")) ;
	acutPrintf (ACRX_T("\nkHideTangents %s "), control & kHideTangents  ? ACRX_T("On") : ACRX_T("Off")) ;
	acutPrintf (ACRX_T("\nkCleanup %s "), control & kCleanup  ? ACRX_T("On") : ACRX_T("Off")) ;
	acutPrintf (ACRX_T("\nkIsolines %s "), control & kIsolines  ? ACRX_T("On") : ACRX_T("Off")) ;
	acutPrintf (ACRX_T("\nkUnite %s "), control & kUnite  ? ACRX_T("On") : ACRX_T("Off")) ;
	acutPrintf (ACRX_T("\nkReuse %s "), control & kReuse  ? ACRX_T("On") : ACRX_T("Off")) ;
	acutPrintf (ACRX_T("\nkProgress %s "), control & kProgress  ? ACRX_T("On") : ACRX_T("Off")) ;
	acutPrintf (ACRX_T("\nkHandlePoints %s "), control & kHandlePoints  ? ACRX_T("On") : ACRX_T("Off")) ;
	acutPrintf (ACRX_T("\nkHonorInternals %s "), control & kHonorInternals ? ACRX_T("On") : ACRX_T("Off")) ;
	acutPrintf (ACRX_T("\nkMeshSilhouettes %s "), control & kMeshSilhouettes ? ACRX_T("On") : ACRX_T("Off")) ;
	AcDbViewport *pVp =NULL ;
	if ( !pickViewport (pVp) )
		return ;
	AsdkHlrEngine hlr (pVp, control) ;
	hlr.run (collector) ;
	delete pVp ;
	actrTransactionManager->startTransaction () ;
	int nOutput =collector.mOutputData.logicalLength () ;
	acutPrintf (ACRX_T("\nHlr returned %d curves"), nOutput) ;
	for ( int j =0 ; j < nOutput ; j++ ) {
		AsdkHlrData *pResult =collector.mOutputData [j] ;
		AcDbEntity *pResultEntity =pResult->getResultEntity () ;
		AcDbObjectId id ;
		if ( postToDatabase (NULL, pResultEntity, id) != Acad::eOk ) {
			acutPrintf (_T("Failed to add entity to current space.\n")) ;
			break ;
		}
		actrTransactionManager->getObject ((AcDbObject *&)pResultEntity, id, AcDb::kForWrite) ;
		AcDbObjectIdArray ids =pResult->getObjectIds () ;
		int last =ids.logicalLength () - 1 ;
		AcCmColor color ;
		AcDbObjectId layerId ;
		color.setColorIndex (0) ;
		while ( last >= 0 && color.colorIndex () == 0 ) {
			AcDbObjectId innerId =ids.at (last) ;
			AcDbObject *pObj ;
			actrTransactionManager->getObject (pObj, innerId, AcDb::kForRead) ;
			AcDbEntity *pEnt =AcDbEntity::cast (pObj) ;
			color =pEnt->color () ;
			layerId =pEnt->layerId () ;
			last-- ;
		}
		if ( layerId != AcDbObjectId::kNull ) {
			pResultEntity->setColor (color) ;
			pResultEntity->setLayer (layerId) ;
		} else {
			AcDbEntity *pEnt =pResult->getEntity () ;
			if ( pEnt != NULL ) {
				pResultEntity->setColor (pEnt->color ()) ;
				pResultEntity->setLayer (pEnt->layer ()) ;
			}
		}
		pResultEntity->close () ;
	}
	actrTransactionManager->endTransaction();
}
void asdktest5 ( ) { ads_name ss , en ; if ( acedSSGet ( NULL , NULL , NULL , NULL , ss ) != RTNORM ) return ; long n ; AcDbObjectId id ; AsdkHlrCollector collector ; acedSSLength ( ss , & n ) ; for ( int i = 0 ; i < n ; i ++ ) { acedSSName ( ss , i , en ) ; acdbGetObjectId ( id , en ) ; collector . addEntity ( id ) ; } acedSSFree ( ss ) ; AfxSetResourceHandle ( _hdllInstance ) ; CControlsDlg dlg ; dlg . mnControls = kProject | kEntity | kBlock | kHonorInternals ; if ( dlg . DoModal ( ) != IDOK ) { AfxSetResourceHandle ( acedGetAcadResourceInstance ( ) ) ; return ; } AfxSetResourceHandle ( acedGetAcadResourceInstance ( ) ) ; int control = dlg . mnControls ; acutPrintf ( ACRX_T ( " \n " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , collector . getInputEntityIds ( ) . logicalLength ( ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kProject ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kShowAll ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kEntity ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kBlock ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kSubentity ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kHideTangents ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kCleanup ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kIsolines ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kUnite ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kReuse ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kProgress ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kHandlePoints ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kHonorInternals ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; acutPrintf ( ACRX_T ( " \n " ) , control & kMeshSilhouettes ? ACRX_T ( " " ) : ACRX_T ( " " ) ) ; AcDbViewport * pVp = NULL ; if ( ! pickViewport ( pVp ) ) return ; AsdkHlrEngine hlr ( pVp , control ) ; hlr . run ( collector ) ; delete pVp ; actrTransactionManager -> startTransaction ( ) ; int nOutput = collector . mOutputData . logicalLength ( ) ; acutPrintf ( ACRX_T ( " \n " ) , nOutput ) ; for ( int j = 0 ; j < nOutput ; j ++ ) { AsdkHlrData * pResult = collector . mOutputData [ j ] ; AcDbEntity * pResultEntity = pResult -> getResultEntity ( ) ; AcDbObjectId id ; if ( postToDatabase ( NULL , pResultEntity , id ) != Acad :: eOk ) { acutPrintf ( _T ( " \n " ) ) ; break ; } actrTransactionManager -> getObject ( ( AcDbObject * & ) pResultEntity , id , AcDb :: kForWrite ) ; AcDbObjectIdArray ids = pResult -> getObjectIds ( ) ; int last = ids . logicalLength ( ) - 1 ; AcCmColor color ; AcDbObjectId layerId ; color . setColorIndex ( 0 ) ; while ( last >= 0 && color . colorIndex ( ) == 0 ) { AcDbObjectId innerId = ids . at ( last ) ; AcDbObject * pObj ; actrTransactionManager -> getObject ( pObj , innerId , AcDb :: kForRead ) ; AcDbEntity * pEnt = AcDbEntity :: cast ( pObj ) ; color = pEnt -> color ( ) ; layerId = pEnt -> layerId ( ) ; last -- ; } if ( layerId != AcDbObjectId :: kNull ) { pResultEntity -> setColor ( color ) ; pResultEntity -> setLayer ( layerId ) ; } else { AcDbEntity * pEnt = pResult -> getEntity ( ) ; if ( pEnt != NULL ) { pResultEntity -> setColor ( pEnt -> color ( ) ) ; pResultEntity -> setLayer ( pEnt -> layer ( ) ) ; } } pResultEntity -> close ( ) ; } actrTransactionManager -> endTransaction ( ) ; }
Command TEST5 ask you to select entities on the AutoCAD DWG file, for a virtual viewport,
and for HLR controls you want to apply to the HLR engine.
Command TEST5 ask you to select entities on the AutoCAD DWG file for a virtual viewport and for HLR controls you want to apply to the HLR engine .
//----- Select the entities
 //----- Append entity IDs to the collector
 //----- Display a dialog box to select HLR controls, the user wants to apply to the HLR engine
 //----- Ask for virtual viewport settings
 //----- Process hidden line removal
 //----- The following code will collect the color of the originator entity of an edge
 //----- and will assign it to the resulting entity.
