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); } }
AcDbObjectId CArxHelper::InsertBlock(const AcDbObjectId& blockId, const AcGePoint3d& ptInsert, double dAngle) { AcDbBlockReference* pBlockReference = new AcDbBlockReference(); pBlockReference->setBlockTableRecord(blockId); pBlockReference->setNormal(AcGeVector3d::kZAxis); pBlockReference->setPosition(ptInsert); pBlockReference->setRotation(dAngle); return AddToCAD(pBlockReference); }
AcDbBlockReference* TWBlockRefenceTool::CreateBlockRefence( IN const CString& strBlockName, IN const AcGePoint3d& PtIns, IN double dScale, IN double dRat, AcDbDatabase* pDb /*= NULL */ ) { AcDbObjectId IdBd; if( !TWArxBlokTableFun::HasBlockTableRecord(strBlockName, IdBd, pDb) ) return NULL; AcDbBlockReference* pBrf = new AcDbBlockReference( PtIns, IdBd ); pBrf->setScaleFactors( AcGeScale3d(dScale, dScale, dScale) ); pBrf->setRotation( dRat ); return pBrf; }
void CGraphListCtrl::ResetDefaultIcon() { AcDbObjectId blkId; if (!GetDefaultIconId(blkId)) { return; } AcDbBlockReference* pRef = new AcDbBlockReference(AcGePoint3d::kOrigin, blkId); m_DefDb->addAcDbObject(pRef); SetDefaultIcon(AcDbEntity::cast(pRef->clone())); }
void hilitInsert() { Adesk::Boolean interrupted = Adesk::kFalse; ads_printf("\nSelect an insert"); Acad::ErrorStatus es = Acad::eOk; AcDbEntity *ent = NULL; AcDbEntity *ent2 = NULL; AcDbBlockReference *blRef = NULL; AcDbObjectId objectId, blRefId; ads_name ename, sset; for (;;) { switch (ads_ssget(NULL, NULL, NULL, NULL, sset)) { case RTNORM: { struct resbuf *rb; if (ads_ssnamex(&rb, sset, 0) != RTNORM) { ads_printf("\nads_ssnamex failed"); ads_ssfree(sset); return; } int sel_method; ads_name subname; short marker; AcGePoint3d pickpnt; AcGeVector3d pickvec; if (!extractEntityInfo(rb, sel_method, ename, subname, marker, pickpnt, pickvec)) { ads_printf("\nextractEntityInfo failed"); ads_ssfree(sset); return; } ads_ssfree(sset); assert(marker != 0); if (marker == 0) { ads_printf("\nmarker == 0"); return; } // Get the insert first. // AOK(acdbGetObjectId(blRefId, ename)); AOK(acdbOpenAcDbEntity(ent, blRefId, AcDb::kForRead)); assert(ent != NULL); blRef = AcDbBlockReference::cast(ent); if (blRef == NULL) { ads_printf("\nNot an insert."); AOK(ent->close()); continue; } struct resbuf *insStack; ads_point pickpoint; ads_matrix adsmat; pickpoint[0] = pickpnt[0]; pickpoint[1] = pickpnt[1]; pickpoint[2] = pickpnt[2]; // Now get details on the entity that was // selected. // if (ads_nentselp(NULL, ename, pickpoint, TRUE, adsmat, &insStack) != RTNORM) { ads_printf("\nFailure in ads_nentselp"); return; } assert(insStack != NULL); AOK(acdbGetObjectId(objectId, ename)); AOK(acdbOpenAcDbEntity(ent2, objectId, AcDb::kForRead)); assert(ent2 != NULL); // Make an array of AcDbObjectIds from the // insertStack. Don't use the "smart array" // AcDbObjectIdArray class, because the // getSubentPathsAtGsMarker() function expects argument // eight to be of type AcDbObjectId*. Just // make room for approximately 100 IDs in the array. // AcDbObjectId *idArray = new AcDbObjectId[100]; int count = 0; struct resbuf *rbIter = insStack; AcDbObjectId objId; acdbGetObjectId(objId, ename); idArray[count++] = objId; while (rbIter != NULL) { ename[0] = rbIter->resval.rlname[0]; ename[1] = rbIter->resval.rlname[1]; acdbGetObjectId(objId, ename); idArray[count++] = objId; rbIter = rbIter->rbnext; } count--; ads_relrb(insStack); // First, we'll highlight an edge. // int numPaths; AcDbFullSubentPath *subentPaths; AcGeMatrix3d xform; es = blRef->getSubentPathsAtGsMarker( AcDb::kEdgeSubentType, marker, pickpnt, xform, numPaths, subentPaths, count, idArray); assert(numPaths == 1); // Highlight and unhighlight the selected edge. // ads_printf("\nHighlighting the first edge."); es = blRef->highlight(subentPaths[0]); pressEnterToContinue(); es = blRef->unhighlight(subentPaths[0]); // If this is a solid, it will have faces. // In this case, let's highlight them. // if(ent2->isKindOf(AcDb3dSolid::desc())) { es = blRef->getSubentPathsAtGsMarker( AcDb::kFaceSubentType, marker, pickpnt, xform, numPaths, subentPaths, count, idArray); assert(numPaths == 2); // Highlight and unhighlight the selected // faces. // ads_printf("\nHighlighting the first" " face."); es = blRef->highlight(subentPaths[0]); pressEnterToContinue(); es = blRef->unhighlight(subentPaths[0]); ads_printf("\nHighlighting the next face."); es = blRef->highlight(subentPaths[1]); pressEnterToContinue(); es = blRef->unhighlight(subentPaths[1]); } delete []subentPaths; // Now, let's highlight the whole entity. // ads_printf("\nHighlighting the entire entity"); AcDbFullSubentPath subPath; for (int i = count; i >= 0; i--) { subPath.objectIds().append(idArray[i]); } es = blRef->highlight(subPath); pressEnterToContinue(); es = blRef->unhighlight(subPath); // Finally, let's highlight each enclosing // insert. // for (i = count -1; i >= 0; i --) { subPath.objectIds().removeAt( subPath.objectIds().length() - 1); ads_printf("\nHighlighting insert layer %d", i + 1); blRef->highlight(subPath); pressEnterToContinue(); es = blRef->unhighlight(subPath); } } // case RTNORM break; case RTNONE: case RTCAN: return; default: continue; } // switch break; } //for (;;) AOK(ent->close()); AOK(ent2->close()); return; }
void addBlockWithAttributes() { // Get an insertion point for the block reference, // definition, and attribute definition. // AcGePoint3d basePoint; if (acedGetPoint(NULL, "\nEnter insertion point: ", asDblArray(basePoint)) != RTNORM) return; // Get the rotation angle for the attribute definition. // double textAngle; if (acedGetAngle(asDblArray(basePoint), "\nEnter rotation angle: ", &textAngle) != RTNORM) return; // Define the height used for the attribute definition text. // double textHeight; if (acedGetDist(asDblArray(basePoint), "\nEnter text height: ", &textHeight) != RTNORM) return; // Build the block definition to be inserted. // AcDbObjectId blockId; defineBlockWithAttributes(blockId, basePoint, textHeight, textAngle); // Step 1: Allocate a block reference object. // AcDbBlockReference *pBlkRef = new AcDbBlockReference; // Step 2: Set up the block reference to the newly // created block definition. // pBlkRef->setBlockTableRecord(blockId); // Give it the current UCS normal. // struct resbuf to, from; from.restype = RTSHORT; from.resval.rint = 1; // UCS to.restype = RTSHORT; to.resval.rint = 0; // WCS AcGeVector3d normal(0.0, 0.0, 1.0); acedTrans(&(normal.x), &from, &to, Adesk::kTrue, &(normal.x)); // Set the insertion point for the block reference. // pBlkRef->setPosition(basePoint); // Indicate the LCS 0.0 angle, not necessarily the UCS 0.0 angle. // pBlkRef->setRotation(0.0); pBlkRef->setNormal(normal); // Step 3: Open the current database's model space // block Table Record. // AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); pBlockTable->close(); // Append the block reference to the model space // block Table Record. // AcDbObjectId newEntId; pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef); pBlockTableRecord->close(); // Step 4: Open the block definition for read. // AcDbBlockTableRecord *pBlockDef; acdbOpenObject(pBlockDef, blockId, AcDb::kForRead); // Set up a block table record iterator to iterate // over the attribute definitions. // AcDbBlockTableRecordIterator *pIterator; pBlockDef->newIterator(pIterator); AcDbEntity *pEnt; AcDbAttributeDefinition *pAttdef; for (pIterator->start(); !pIterator->done(); pIterator->step()) { // Get the next entity. // pIterator->getEntity(pEnt, AcDb::kForRead); // Make sure the entity is an attribute definition // and not a constant. // pAttdef = AcDbAttributeDefinition::cast(pEnt); if (pAttdef != NULL && !pAttdef->isConstant()) { // We have a non-constant attribute definition, // so build an attribute entity. // AcDbAttribute *pAtt = new AcDbAttribute(); pAtt->setPropertiesFrom(pAttdef); pAtt->setInvisible(pAttdef->isInvisible()); // Translate the attribute by block reference. // To be really correct, the entire block // reference transform should be applied here. // basePoint = pAttdef->position(); basePoint += pBlkRef->position().asVector(); pAtt->setPosition(basePoint); pAtt->setHeight(pAttdef->height()); pAtt->setRotation(pAttdef->rotation()); pAtt->setTag("Tag"); pAtt->setFieldLength(25); char *pStr = pAttdef->tag(); pAtt->setTag(pStr); free(pStr); pAtt->setFieldLength(pAttdef->fieldLength()); // The database column value should be displayed. // INSERT prompts for this. // pAtt->setTextString("Assigned Attribute Value"); AcDbObjectId attId; pBlkRef->appendAttribute(attId, pAtt); pAtt->close(); } pEnt->close(); // use pEnt... pAttdef might be NULL } delete pIterator; pBlockDef->close(); pBlkRef->close(); }
BOOL CGuiDaoNode::GetBlockToward( long nHandleXHJ ,int &iToward) { if(nHandleXHJ==0) { return FALSE; } long t1=GetTickCount(); BOOL bRet = FALSE ; AcDbEntity* pEnt = NULL ; iToward =-1; if (m_sys.OpenAcDbEntity(nHandleXHJ, pEnt, AcDb::kForRead)) { if (pEnt->isKindOf(AcDbBlockReference::desc())) { AcDbBlockReference* pRef = AcDbBlockReference::cast(pEnt) ; //bRet= GetBlockName(pRef, strBlockName) ; double rota=pRef->rotation(); //acutPrintf(_T("\n %6f"),rota); int cnt=0; while((rota-PI)>1.0E-6) { rota-=PI; cnt++; } while((rota+PI)<1.0E-6) { rota+=PI; cnt++; } float res=rota-PI/2; //acutPrintf("rota=%6f",rota); if(fabs(res)<=1.0E-6&&cnt%2==0) { //向上 iToward=0; } else if(fabs(res)<=1.0E-6&&cnt%2==1) { //向下; iToward=3; } else if(res<1.0E-6&&cnt%2==0) { //朝右 iToward=1; } else if(res<1.0E-6&&cnt%2==1) { iToward=2; } else if(res>1.0E-6&&cnt%2==0) { //朝左 iToward=2; } else if(res>1.0E-6&&cnt%2==1) { iToward=1; } else { iToward=-1; } } pEnt->close() ; bRet =TRUE; } long t2=GetTickCount(); CString str; str.Format(_T("GetBlockToward:%d ms"),t2-t1); //acutPrintf(_T("\n%s"),str); return bRet ; }