void asdktest5 () {
    //----- Select the entities
    ads_name ss, en ;
    if ( acedSSGet (NULL, NULL, NULL, NULL, ss) != RTNORM )
        return ;

    //----- Append entity IDs to the collector
    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) ;

    //----- Display a dialog box to select HLR controls, the user wants to apply to the HLR engine
    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")) ;
    
    //----- Ask for virtual viewport settings
    AcDbViewport *pVp =NULL ;
    if ( !pickViewport (pVp) )
        return ;

    //----- Process hidden line removal
    AsdkHlrEngine hlr (pVp, control) ;
    hlr.run (collector) ;
    delete pVp ;

    //----- The following code will collect the color of the originator entity of an edge
    //----- and will assign it to the resulting entity.
    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 asdktest6 () {
    int nPoints =8 ;
    int nTriangles =12 ;
    int nIndices =3 * nTriangles ;

    double p [] ={
        0, 0, 0,
        1, 0, 0,
        1, 1, 0,
        0, 1, 0,
        0, 0, 1,
        1, 0, 1,
        1, 1, 1,
        0, 1, 1
    } ;

    int i [] ={
        0, 1, 5,    0, 5, 4,
        1, 6, 5,    1, 2, 6,
        4, 5, 6,    4, 6, 7,
        7, 0, 4,    7, 3, 0,
        2, 0, 3,    2, 1, 0,
        7, 6, 3,    6, 2, 3
    } ;

    AcGeIntArray indices (nIndices) ;
    indices.setLogicalLength (nIndices) ;
    indices.setPhysicalLength (nIndices) ;
    memcpy (indices.asArrayPtr (), i, nIndices * sizeof (int)) ;

    AcGePoint3dArray gePts (nPoints) ;
    gePts.setLogicalLength (nPoints) ;
    gePts.setPhysicalLength (nPoints) ;
    memcpy (gePts.asArrayPtr (), p, nPoints * sizeof (AcGePoint3d)) ;

    void *acisBody =createBodyFromTriangles (gePts, indices) ;
    AcDb3dSolid *b =new AcDb3dSolid ;
    b->setASMBody(acisBody);
        
    AcDbObjectId id ;
    postToDatabase (NULL, b, id) ;
}
Beispiel #3
0
Acad::ErrorStatus newLine()
{
//Mark the leftmost cubicle as unusable by putting a red diagonal
//line from the lower left to upper right corners
//Use the first parameter of acedGetPoint to rubberband to the second point
//Prompt the user to select the line's endpoints
	ads_point pt1, pt2;
	int retval;
//{{BEGIN_LEVEL_ADVANCED
	
	try 
	{
		//get the first point from the user.  Do not specify a base point.
		//...
//{{BEGIN_LEVEL_INTERMEDIATE
		if ((retval = acedGetPoint(NULL, "\nSelect lower left:  ", pt1)) != RTNORM) 
			throw retval;
//{{END_LEVEL_INTERMEDIATE
		//get the second point from the user, using the first point as a base point.
		//...
//{{BEGIN_LEVEL_INTERMEDIATE
		if ((retval = acedGetPoint(pt1, "\nSelect upper right:  ", pt2)) != RTNORM)
			throw retval;
//{{END_LEVEL_INTERMEDIATE
	}
	catch (int e)
	{
		if (e == RTCAN)
			return Acad::eUserBreak;
		if (e == RTERROR)
			return Acad::eInvalidInput;
	}
//{{END_LEVEL_ADVANCED
	
//Instantiate an AcDbLine pointer.  Use the two user-chosen 
//points as endpoints.
//Since AcDbLine's constructor uses AcGePoint2d, but acedGetPoint returns ads_point,
//you must find a way to translate old style to new style.  This can be done either by
//assigning each array member individually, or by calling asPnt3d() from geassign.h
//{{BEGIN_LEVEL_ADVANCED
//...
//{{BEGIN_LEVEL_INTERMEDIATE

	AcDbLine* pLine = new AcDbLine(asPnt3d(pt1), asPnt3d(pt2));
//{{END_LEVEL_INTERMEDIATE
//Make sure you created the line...
	if (!pLine)
	{
		acedAlert("Not enough memory to create a Line!");
		return Acad::eOutOfMemory;
	}
//{{END_LEVEL_ADVANCED
//Prompt the user to enter a new color
//Then change the color property of the new line to this value.
//{{BEGIN_LEVEL_ADVANCED
//...
//{{BEGIN_LEVEL_INTERMEDIATE
	int color;
	acedGetInt("\nEnter AutoCAD color number:  ", &color);
	if (pLine->setColorIndex(color) != Acad::eOk)
	{
		acutPrintf("\nInvalid color chosen.\n");
	}
//{{END_LEVEL_INTERMEDIATE
//{{END_LEVEL_ADVANCED

//Post the new entity to the database
//{{BEGIN_LEVEL_ADVANCED
	AcDbObjectId id;
	return postToDatabase(pLine, id);
//{{END_LEVEL_ADVANCED
}
OarxEmployee *OarxEmployeeService::createEmployee (int id, AcGePoint3d location, int cubeNumber, char *strFirstName, char *strLastName) {
	OarxEmployee *p =NULL ;
	AcDbXrecord *pRec =NULL ;
	AcDbDictionary *pAppDict =NULL ;

	try {
		//----- Create the object
		p =new OarxEmployee ;
		if ( p == NULL )
			throw Acad::eOutOfMemory ;

		ARXOK ( p->setID (id) ) ;
		ARXOK ( p->setCubeNumber (cubeNumber) ) ;
		ARXOK ( p->setFirstName (strFirstName) ) ;
		ARXOK ( p->setLastName (strLastName) ) ;
		ARXOK ( p->setCenter (location) ) ;

		AcDbObjectId id0 ;
		ARXOK ( postToDatabase (p, id0) ) ;

		pRec =new AcDbXrecord ;
		if ( pRec == NULL )
			throw Acad::eOutOfMemory ;

		struct resbuf rb ;
		rb.restype =330 ; //----- SoftPointerId to the OarxEmployee entity
		rb.rbnext =NULL ;
		ARXOK ( acdbGetAdsName (rb.resval.rlname, id0) ) ;

		ARXOK ( pRec->setFromRbChain (rb) ) ;
		pRec->setXlateReferences (Adesk::kTrue) ;

		AcDbObjectId idDict =getAppDictionary () ;
		if ( idDict == AcDbObjectId::kNull )
			throw Acad::eNullObjectId ;
		ARXOK ( acdbOpenAcDbObject ((AcDbObject *&)pAppDict, idDict, AcDb::kForWrite) ) ;

		char buffer [33] ;
		sprintf (buffer, "%d", id) ;
		ARXOK ( pAppDict->setAt (buffer, pRec, id0) ) ;

		pRec->close () ;
		pAppDict->close () ;

		return (p) ;

	} catch (const Acad::ErrorStatus es) {
		if ( p != NULL && p->objectId () == AcDbObjectId::kNull )
			delete p ;
		else
			p->cancel () ;

		if ( pRec != NULL && pRec->objectId () == AcDbObjectId::kNull )
			delete pRec ;
		else
			pRec->cancel () ;

		if ( pAppDict != NULL )
			pAppDict->cancel () ;

		return (NULL) ;
	}
}
void asdktest1 () {
    //----- Select the entities
    ads_name ss, en ;
    if ( acedSSGet (NULL, NULL, NULL, NULL, ss) != RTNORM )
        return ;

    //----- Append entity IDs to the collector
    long n ;
    AcDbObjectId id ;
    AsdkHlrCollector collector ;
    collector.setDeleteState (true) ;
    acedSSLength (ss, &n) ;
    for ( int i =0 ; i < n ; i++ ) {
        acedSSName (ss, i, en) ;
        acdbGetObjectId (id, en) ;
        collector.addEntity (id) ;
    }
    acedSSFree (ss) ;

    //----- Get current viewport settings
    struct resbuf rb;
    acedGetVar(ACRX_T(/*NOXLATE*/"viewdir"), &rb);
    ads_point dirPt;
    acdbUcs2Wcs (rb.resval.rpoint, dirPt, Adesk::kTrue) ;
    acedGetVar(ACRX_T(/*NOXLATE*/"target"), &rb);
    ads_point tarPt;
    acdbUcs2Wcs (rb.resval.rpoint, tarPt, Adesk::kFalse) ;

    //----- Ask if non-visible edges should be created
    int hidLines =AfxMessageBox (ACRX_T("Would you like to see hidden lines?"), MB_YESNO) ;
    int honorInt =AfxMessageBox (ACRX_T("Would you like to honor internal visibility of polyface meshes or ACIS objects?"), MB_YESNO) ;
    int meshSils =AfxMessageBox (ACRX_T("Would you like to calculate silhouettes of polyface meshes?"), MB_YESNO) ;
    int unit =AfxMessageBox (ACRX_T("Would you like to unit solid before processing?"), MB_YESNO) ;

    //----- Process hidden line removal
    AsdkHlrEngine hlr (
        asPnt3d (tarPt), asVec3d (dirPt),
        kEntity | kBlock | kSubentity | kProgress
        | (honorInt == IDYES ? kHonorInternals : 0)
        | (hidLines == IDYES ? kShowAll : 0)
        | (meshSils == IDYES ? kMeshSilhouettes : 0)
        | (unit == IDYES ? kUnite : 0)
    ) ;
    hlr.setAcisConversionProgressCallBack (progress1) ;
    hlr.setAhlProgressCallBack (progress2) ;
    hlr.setAcadConversionProgressCallBack (progress3) ;

    acedSetStatusBarProgressMeter (ACRX_T("HLR running: "), 0, 300) ;
    hlr.run (collector) ;
    acedRestoreStatusBar () ;

    //----- Assign color to the resulting entities
    //----- red for visible edges
    //----- blue for non-visible edges
    //----- yellow for internal edges
    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 ( postToDatabase (NULL, pEnt, id) != Acad::eOk ) {
            acutPrintf (_T("Failed to add entity to current space.\n")) ;
            break ;
        }
        if ( acdbOpenAcDbEntity (pEnt, id, AcDb::kForRead) != Acad::eOk ) {
            acutPrintf (_T("Failed to open last added outputed curve.\n")) ;
            break ;
        }

        //----- Entity originator path for block reference entities
        AcDbObjectIdArray ids =p->getObjectIds () ;
        if ( ids.logicalLength () > 0 ) {
            acutPrintf (ACRX_T("\n%lx, "), pEnt->objectId ().asOldId ()) ;
            if ( p->getSubentId ().type () != AcDb::kNullSubentType )
                acutPrintf (ACRX_T("[%ld, %ld], "), p->getSubentId ().type (), p->getSubentId ().index ()) ;
            for ( int j =0 ; j < ids.logicalLength () ; j++ )
                acutPrintf (ACRX_T("%lx, "), ids.at (j).asOldId ()) ;
            AcDbObjectId id =ids.last () ;
            if ( !id.isNull () ) {
                AcDbEntity *ent =NULL ;
                acdbOpenAcDbEntity (ent, id, AcDb::kForRead) ;
                id =ent->linetypeId () ;
                ent->close () ;
                if ( pEnt->upgradeOpen () == Acad::eOk )
                pEnt->setLinetype (id) ;
            }
        }

        pEnt->close () ;
    }
}
// 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 () ;
    }
}
void asdktest3 () {
    //----- Create a line and a circle (memory only)
    AcDbLine *pLine =new AcDbLine (AcGePoint3d (), AcGePoint3d (100, 100, -100)) ;
    AcDbCircle *pCircle =new AcDbCircle (AcGePoint3d (50, 50, 0), AcGeVector3d (0, 0, 1) , 25.0) ;

    //----- Create a region from the circle
    AcDbVoidPtrArray arr1, arr2 ;
    arr1.append (pCircle) ;
    AcDbRegion::createFromCurves (arr1, arr2) ;
    AcDbRegion *pRegion =(AcDbRegion *)arr2.at (0) ;
    delete pCircle ;

    //----- Add the line and the region objects to the collector
    //----- NB: Remember those object are memory objects only
    AsdkHlrCollector collector ;
    collector.setDeleteState (true) ;
    collector.addEntity (pLine) ;
    collector.addEntity (pRegion) ;

    //----- Process hidden line removal
    AsdkHlrEngine hlr (AcGePoint3d (50, 50,0), AcGeVector3d (0, 0, 1), kEntity | kBlock | kShowAll | kProject | kHonorInternals) ;
    hlr.run (collector) ;

    //----- To easily see the result, we do append resulting entities to the current database
    //----- and use the color convention used in command 'TEST1'
    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) ;
        else
            pEnt->setColorIndex (5) ;
        AcDbObjectId id ;
        if ( postToDatabase (NULL, pEnt, id) != Acad::eOk ) {
            acutPrintf (_T("Failed to add entity to current space.\n")) ;
            break ;
        }

        //----- Entity originator path
        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 () ;
    }
}