Acad::ErrorStatus
ArxDbgUtils::addNewLayer(LPCTSTR layerName, AcDbDatabase* db)
{
	ASSERT(db != NULL);

        // if layer already exists, then just return
    AcDbLayerTable* layTbl;
	Acad::ErrorStatus es = db->getSymbolTable(layTbl, AcDb::kForRead);
	if (es != Acad::eOk)
		return es;

    if (layTbl->has(layerName)) {
        layTbl->close();
        return Acad::eOk;
    }
        // upgrade to write
    es = layTbl->upgradeOpen();
    if (es != Acad::eOk) {
        ASSERT(0);
        layTbl->close();
        return es;
    }
        // make sure the name gets set ok
    AcDbLayerTableRecord* newRec = new AcDbLayerTableRecord;
    es = newRec->setName(layerName);
    if (es != Acad::eOk) {
        delete newRec;
        layTbl->close();
        return Acad::eInvalidInput;
    }
        // look up value for default linetype CONTINUOUS,
        // AcDbLayerTableRecord doesn't set this automatically (at least it didn't in Sedona)
    newRec->setLinetypeObjectId(db->continuousLinetype());

    es = layTbl->add(newRec);
    if (es != Acad::eOk)
        delete newRec;
    else
        newRec->close();

    layTbl->close();
    return es;
}
Example #2
0
Acad::ErrorStatus TWArxLayer::Create( OUT AcDbObjectId& IdLayer ) const
{
	if( m_strName.IsEmpty() ) return Acad::eInvalidInput;

	AcDbDatabase* pDb = GetWorkingDB();

	Acad::ErrorStatus es = Acad::eKeyNotFound;

	AcDbLayerTable* pLayerTb = NULL;
	es = pDb->getLayerTable( pLayerTb,AcDb::kForRead );
	if( pLayerTb == NULL ) return es;
	
	es = pLayerTb->getAt( m_strName, IdLayer );
	if( es == Acad::eOk )
	{
		pLayerTb->close();
		return es;
	}

	es = pLayerTb->upgradeOpen();

	AcDbLayerTableRecord* pLtr = new AcDbLayerTableRecord;
	pLtr->setName( m_strName );
	pLtr->setIsFrozen( m_bIsFrozen );
	pLtr->setIsLocked( m_bIsLocked );
	pLtr->setIsOff( m_bIsOff );

	es = pLayerTb->add( IdLayer, pLtr );
	pLayerTb->close();

	if( es == Acad::eOk )
	{
		pLtr->close();
		return es;
	}

	TWFreePtr( pLtr );
	return es;
}
// This command demonstrates the use of kCleanup / kReuse flags
void AddEntityToLayer (AsdkHlrCollector &collector, ACHAR *layerName) {
    //----- Check layer
    if ( layerName != NULL && *layerName != ACRX_T('\0') ) {
        AcDbDatabase *pDb =acdbHostApplicationServices ()->workingDatabase () ;
        AcDbLayerTable *pLayerTable ;
        pDb->getLayerTable (pLayerTable, AcDb::kForRead) ;
        if ( !pLayerTable->has (layerName) ) {
            AcDbLayerTableRecord *pLayerRecord =new AcDbLayerTableRecord ;
            pLayerRecord->setName (layerName) ;
            pLayerTable->upgradeOpen () ;
            pLayerTable->add (pLayerRecord) ;
            pLayerTable->downgradeOpen () ;
            pLayerRecord->close () ;
            pLayerTable->close () ;
            applyCurDwgLayerTableChanges () ;
        } else {
            pLayerTable->close () ;
        }
    } else {
        layerName =NULL ;
    }
    //----- Assign color to the resulting entities
    //----- red for visible edges
    //----- blue for non-visible edges
    //----- yellow for internal edges
    int n =collector.mOutputData.logicalLength () ;
    for ( int i =0 ; i < n ; i++ ) {
        AsdkHlrData *p =collector.mOutputData [i] ;

        AcDbEntity *pEnt =p->getResultEntity () ;
        AsdkHlrData::Visibility vis =p->getVisibility () ;
        if ( vis == AsdkHlrData::kVisible ) {
            pEnt->setColorIndex (1) ; //----- Read
        } else if ( vis == AsdkHlrData::kInternallyHidden ) {
            if ( p->getHlrVisibility () == AsdkHlrData::kVisible )
                pEnt->setColorIndex (2) ; //----- Yellow
            else
                pEnt->setColorIndex (3) ; //----- Green
        } else {
            pEnt->setColorIndex (5) ; //----- Blue
        }
        if ( layerName != NULL )
            pEnt->setLayer (layerName) ;
        AcDbObjectId id ;
        if ( postToDatabase (NULL, pEnt, id) != Acad::eOk ) {
            acutPrintf (_T("Failed to add entity to current space.\n")) ;
            break ;
        }

        //----- Entity originator path for block reference entities
        AcDbObjectIdArray ids =p->getObjectIds () ;
        if ( ids.logicalLength () > 0 ) {
            acutPrintf (ACRX_T("\n%ld, "), pEnt->objectId ().asOldId ()) ;
            for ( int j =0 ; j < ids.logicalLength () ; j++ ) {
                acutPrintf (ACRX_T("%ld, "), ids.at (j).asOldId ()) ;
            }
        }

        pEnt->close () ;
    }
}