Exemplo n.º 1
1
Acad::ErrorStatus createCircle(AcDbObjectId & idCircle)
{
	CLogger::Print(L"*Call: createCircle()");
	Acad::ErrorStatus es, esTmp;

	AcDbBlockTable* pBlockTable = NULL;
	es = acdbHostApplicationServices()->workingDatabase()
				->getSymbolTable(pBlockTable, AcDb::kForRead);
	if (Acad::eOk != es) {
		CLogger::Print(L"*Exit: createCircle() - Fail to get the BlockTable.");
		return es;
	}

	AcDbBlockTableRecord* pModelSpace = NULL;
	es = pBlockTable->getAt(ACDB_MODEL_SPACE, pModelSpace, AcDb::kForWrite);
	if (Acad::eOk != (esTmp =  pBlockTable->close())) {
		CLogger::Print(L"Warn: Fail to close the BlockTable!");
		acrx_abort(ACRX_T("\nThere is an error occured when close the BlockTable. Message: %s")
									, acadErrorStatusText(esTmp));
	}
	if (Acad::eOk != es) {
		CLogger::Print(L"*Exit: createCircle() - Fail to get the Model Space! Error: %s", acadErrorStatusText(es));
		return es;
	}

	idCircle = AcDbObjectId::kNull;
	AcGePoint3d pt3Center(9.0, 3.0, 0.0);
	AcGeVector3d vt3Normal(0.0, 0.0, 1.0);
	AcDbCircle* pCircle = new AcDbCircle(pt3Center, vt3Normal, 10.0);

	if (!pCircle) {
		if (Acad::eOk != (esTmp = pModelSpace->close())) {
			CLogger::Print(L"Warn: Fail to create new circle object!");
			acrx_abort(ACRX_T("\nThere is an error occured. Error: %s")
											, acadErrorStatusText(esTmp));
		}
		return Acad::eOutOfMemory;
	}

	es = pModelSpace->appendAcDbEntity(idCircle, pCircle);
	if (Acad::eOk != (esTmp = pModelSpace->close())) {
		CLogger::Print(L"Warn: Fail to close the Model Space!");
		acrx_abort(ACRX_T("\nThere is an error occured when close the Model Space! Error: %s")
										, acadErrorStatusText(esTmp));
	}
	if (Acad::eOk != es) {
		CLogger::Print(L"*Exit: createCircle() - Fail to append new circle in to Model Space!");
		delete pCircle;
		return es;
	}

	if (Acad::eOk != (esTmp = pCircle->close())) {
		CLogger::Print(L"Warn: Fail to close the circle object.");
		acrx_abort(ACRX_T("\nFail to close the circle entity!, Error: %s")
										, acadErrorStatusText(esTmp));
	}

	CLogger::Print(L"*Exit: createCircle()");
	return Acad::eOk;
}
void
ArxDbgDbAdeskLogo::getReferenceAttachmentPoint(AcDbEntity* ent, AcGePoint3d& toPt)
{
	AcDbCircle* circ;
	AcDbArc* arc;
	AcDbLine* line;
	AcDbPoint* point;
	AcDbBlockReference* blkRef;
	
	if ((circ = AcDbCircle::cast(ent)) != NULL)
		toPt = circ->center();
	else if ((arc = AcDbArc::cast(ent)) != NULL)
		toPt = arc->center();
	else if ((line = AcDbLine::cast(ent)) != NULL)
		toPt = line->startPoint();
	else if ((point = AcDbPoint::cast(ent)) != NULL)
		toPt = point->position();
	else if ((blkRef = AcDbBlockReference::cast(ent)) != NULL)
		toPt = blkRef->position();
	else {
			// can't get anything better so just rely on the ECS.  If the
			// raw AutoCAD entities would do this, we wouldn't need the above
			// switch statement.
		AcGeMatrix3d mat;
		ent->getEcs(mat);

		AcGeVector3d v1, v2, v3;
		mat.getCoordSystem(toPt, v1, v2, v3);
	}
}
Exemplo n.º 3
0
double
AsdkCircleTemperature::reflectedEnergy(
    AcDbEntity* pEnt) const
{
    AcDbCircle *pCircle = AcDbCircle::cast(pEnt);

    // Compute reflected energy in manner distinctly
    // different than for AcDbRegion.
    // 
    return pCircle->radius() * 6.21 * 42.0;
}
Exemplo n.º 4
0
AcDbObjectId Additional_Class::Draw_Circle( AcGePoint3d ptCircle, double Radius )
{
	AcGeVector3d norm(0,0,1);
	AcDbCircle *pCircle = new AcDbCircle(ptCircle, norm, Radius);
	AcDbBlockTable *pBlockTable;
	AcDbBlockTableRecord *pBlockTableRecord;
	acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead);
	//Open_BlockTable(pBlockTable, NREADMODE);
	//Open_ModelTableRecord(pBlockTableRecord, pBlockTable, NWRITEMODE);
	pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
	AcDbObjectId CircleId;
	pBlockTableRecord->appendAcDbEntity(CircleId, pCircle);
	pCircle->close();
	pBlockTable->close();
	pBlockTableRecord->close();
	return CircleId;
}
Exemplo n.º 5
0
Acad::ErrorStatus createBlockRecord(/*[in]*/const char* name)
{
	AcDbCircle* pFace = NULL;
	AcDbCircle* pLeftEye = NULL;
	AcDbCircle* pRightEye = NULL;
	AcDbArc* pMouth = NULL;
	AcDbBlockTable* pBlockTable = NULL;
	AcDbBlockTableRecord* pBlockTableRecord = NULL;

	try
	{
		// First, check if a block of the same name already exists
		// by verifying in the current database block table.
		//
		// Open the block table for read
		//
		ARXOK(acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead));

		if (pBlockTable->has(name) == Adesk::kTrue)
		{
			pBlockTable->close();
			return Acad::eDuplicateKey;
		}

		// Now we know the block does not exist, so we create it
		// using the name passed in.
		//
		pBlockTableRecord = new AcDbBlockTableRecord();
		if (!pBlockTableRecord)
			throw Acad::eOutOfMemory;

		pBlockTableRecord->setName(name);

		// To keep it simple, we use the origin for the insertion point
		//
		pBlockTableRecord->setOrigin(AcGePoint3d::kOrigin);

		// Open the block table for write
		// since we are adding a new block definition
		//
		ARXOK(pBlockTable->upgradeOpen());

		// Add the new block table record to the block table.
		// For now, the block table record is empty.
		//
		ARXOK(pBlockTable->add(pBlockTableRecord));
		pBlockTable->close();
		pBlockTable = NULL;

		// Now the block table record is in the database, but is empty
		// (has no sub-entity).
		// Note that after having been added to the database, an object or an entity
		// is implicitely opened for write.
		//
		// So we create the sub entities to append to the block
		// which will represent a "happy face":
		// the block should consist of a round yellow face (circle)
		// two blue eyes (circles) and a red mouth (arc)
		//
		pFace = new AcDbCircle(AcGePoint3d::kOrigin, AcGeVector3d::kZAxis, 1.0);
		pLeftEye = new AcDbCircle(AcGePoint3d(0.33, 0.25, 0.0), AcGeVector3d::kZAxis, 0.1);
		pRightEye = new AcDbCircle(AcGePoint3d(-0.33, 0.25, 0.0), AcGeVector3d::kZAxis, 0.1);
		pMouth = new AcDbArc(AcGePoint3d(0, 0.5, 0), 1.0, PI + (PI * 0.3), PI + (PI * 0.7));
		if (!pFace || !pLeftEye || !pRightEye || !pMouth)
		{
			delete pFace;
			delete pLeftEye;
			delete pRightEye;
			delete pMouth;
			throw Acad::eOutOfMemory;
		}

		// Set the color property.
		//
		pFace->setColorIndex(2);
		pLeftEye->setColorIndex(5);
		pRightEye->setColorIndex(5);
		pMouth->setColorIndex(1);

		ARXOK(pBlockTableRecord->appendAcDbEntity(pFace));
		ARXOK(pBlockTableRecord->appendAcDbEntity(pLeftEye));
		ARXOK(pBlockTableRecord->appendAcDbEntity(pRightEye));
		ARXOK(pBlockTableRecord->appendAcDbEntity(pMouth));

		pFace->close();
		pLeftEye->close();
		pRightEye->close();
		pMouth->close();

		pBlockTableRecord->close();
		return Acad::eOk;
	}

	catch(const Acad::ErrorStatus es)
	{

		if(pBlockTable)
			pBlockTable->close();

		if(pBlockTableRecord)
			// if the id is NULL, it means that the object
			// is not in the database and that we can sefely delete it
			if(pBlockTableRecord->objectId() == AcDbObjectId::kNull)
				delete pBlockTableRecord;
			else
			{
				pBlockTableRecord->erase();
				pBlockTableRecord->close();
			}
		
		if(pFace)
			if(pFace->objectId() == AcDbObjectId::kNull)
				delete pFace;
			else
				pFace->close();
		if(pLeftEye)
			if(pLeftEye->objectId() == AcDbObjectId::kNull)
				delete pLeftEye;
			else
				pLeftEye->close();
		if(pRightEye)
			if(pRightEye->objectId() == AcDbObjectId::kNull)
				delete pRightEye;
			else
				pRightEye->close();
		if(pMouth)
			if(pMouth->objectId() == AcDbObjectId::kNull)
				delete pMouth;
			else
				pMouth->close();

		return es;
	}

}
Exemplo n.º 6
0
//---------------------------------------------------------------------------------------
//
//  功能: 路线绘制回调函数
//
//  输入参数:
//             AeccDisplayOrientation &viewMode
//             IAeccAlignment *pAlign
//             IAcadBlock *pAnonymousBlock 
//
//  返回值:bool
//
// 作  者:  
//
//  日期: 2007/08
//
//  修改记录:无
//
//---------------------------------------------------------------------------------------
bool customAlignmentDraw(const AeccDisplayOrientation &viewMode, IAeccAlignment *pAlign,
						 IAcadBlock *pAnonymousBlock )
{
	AcDbBlockTableRecord* blkRec;
	CString strName;
	CComBSTR bstrName;
	pAnonymousBlock->get_Name( &bstrName);
	strName = bstrName;
	AcDbBlockTable* blkTbl;

	AcDbDatabase* pDb = acdbCurDwg();
	Acad::ErrorStatus es = pDb->getSymbolTable(blkTbl, AcDb::kForRead);
	if (es != Acad::eOk){
		return false;
	}
	//// open named block
	es = blkTbl->getAt(strName, blkRec, AcDb::kForWrite);
	acutPrintf(_T("\nget block"));
	if (es != Acad::eOk) {
		blkTbl->close();    // doesn't need to be open anymore
		return false;
	}

	blkTbl->close();    // doesn't need to be open anymore

	CComQIPtr <IAeccAlignmentEntities> pAlignEntities;
	CComQIPtr <IAeccAlignmentEntity> pAlignEnt;
	CComQIPtr<IAeccAlignmentArc> pAlignArc;
	long iCount;
	pAlign->get_Entities(&pAlignEntities);

	if (pAlignEntities != NULL) {
		pAlignEntities->get_Count(&iCount);

		for (long i = 0; i < iCount; i++) {
			pAlignEnt.Release();
			pAlignEntities->Item(_variant_t(i), &pAlignEnt);
			pAlignArc.Release();
			pAlignArc = pAlignEnt;
			if (pAlignArc != NULL) {
				double radius;
				pAlignArc->get_Radius(&radius);
				//acutPrintf(_T("\nRadius: %f", radius));

				if (radius < 200) {
					double x;
					double y;
					double dStart;
					double dEnd;
					pAlignArc->get_StartingStation(&dStart);
					pAlignArc->get_EndingStation(&dEnd);
					for (double delta = dStart; delta < dEnd; delta += 3.0) {
						pAlign->PointLocation(delta, 0.0, &x, &y);
						AcGePoint3d pt(x,y,0);
						AcDbCircle* cir = new AcDbCircle(pt, AcGeVector3d::kZAxis, 5.0);
						cir->setColorIndex (1, Adesk::kTrue);
						blkRec->appendAcDbEntity(cir);
						cir->close();
					}
				}
			}
		}
	}
	blkRec->close();
	return (true) ;
}
Exemplo n.º 7
0
void
defineBlockWithAttributes(
    AcDbObjectId& blockId, // This is a returned value.
    const AcGePoint3d& basePoint,
    double textHeight,
    double textAngle)
{
    int retCode = 0;
    AcDbBlockTable *pBlockTable = NULL;
    AcDbBlockTableRecord* pBlockRecord
       = new AcDbBlockTableRecord;
    AcDbObjectId entityId;

    // Step 1: Set the block name and base point of the block definition
    //
    pBlockRecord->setName("ASDK-BLOCK-WITH-ATTR");
    pBlockRecord->setOrigin(basePoint);

    // Open the block table for write.
    //
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForWrite);

    // Step 2: Add the block table record to block table.
    //
    pBlockTable->add(blockId, pBlockRecord);

    // Step 3: Create a circle entity.
    //
    AcDbCircle *pCircle = new AcDbCircle;
    pCircle->setCenter(basePoint);
    pCircle->setRadius(textHeight * 4.0);
    pCircle->setColorIndex(3);

    // Append the circle entity to the block record.
    //
    pBlockRecord->appendAcDbEntity(entityId, pCircle);
    pCircle->close();

    // Step 4: Create an attribute definition entity.
    //
    AcDbAttributeDefinition *pAttdef
        = new AcDbAttributeDefinition;

    // Set the attribute definition values.
    //
    pAttdef->setPosition(basePoint);
    pAttdef->setHeight(textHeight);
    pAttdef->setRotation(textAngle);
    pAttdef->setHorizontalMode(AcDb::kTextLeft);
    pAttdef->setVerticalMode(AcDb::kTextBase);
    pAttdef->setPrompt("Prompt");
    pAttdef->setTextString("DEFAULT");
    pAttdef->setTag("Tag");
    pAttdef->setInvisible(Adesk::kFalse);
    pAttdef->setVerifiable(Adesk::kFalse);
    pAttdef->setPreset(Adesk::kFalse);
    pAttdef->setConstant(Adesk::kFalse);
    pAttdef->setFieldLength(25);

    // Append the attribute definition to the block.
    //
    pBlockRecord->appendAcDbEntity(entityId, pAttdef);

    // The second attribute definition is a little easier
    // because we are cloning the first one.
    //
    AcDbAttributeDefinition *pAttdef2
        = AcDbAttributeDefinition::cast(pAttdef->clone());

    // Set the values which are specific to the
    // second attribute definition.
    //
    AcGePoint3d tempPt(basePoint);
    tempPt.y -= pAttdef2->height();
    pAttdef2->setPosition(tempPt);
    pAttdef2->setColorIndex(1); // Red
    pAttdef2->setConstant(Adesk::kTrue);

    // Append the second attribute definition to the block.
    //
    pBlockRecord->appendAcDbEntity(entityId, pAttdef2);

    pAttdef->close();
    pAttdef2->close();
    pBlockRecord->close();
    pBlockTable->close();
    return;
}