예제 #1
0
String GetSelectedExtent() {
  ads_name selection;
  int returnValue = acedSSGet(_T("I"), NULL, NULL, NULL, selection);
  if (returnValue == RTCAN) return 0;
  if (returnValue != RTNORM) {
    return L"";
  }

  if (acedSSSetFirst(selection, NULL) != RTNORM) {
    acedSSFree(selection);
    return L"";
  }
  ads_name element;
  acedSSName(selection, 0, element);
  acedSSFree(selection);
  
  AcDbObjectId idEntity;
  if (acdbGetObjectId(idEntity, element) != Acad::eOk) {
    acedSSFree(element);
    return L"";
  }
  
  AcDbEntity * entity;
  if ((acdbGetObjectId(idEntity, element) != Acad::eOk) || 
      (acdbOpenObject(entity, idEntity, AcDb::kForRead) != Acad::eOk)) {
    
    acedSSFree(element);
    return L"";
  }
  
  acedSSFree(element);
  
  if (!entity->isKindOf(AcDbPolyline::desc())) return L"";
  
  AcDbPolyline * poly = static_cast<AcDbPolyline*>(entity);
  if (!poly->isClosed()) return 0;
  
  String extent = L"POLYGON((";
  AcGePoint2d start;
  AcGePoint2d current;
  for (int i = 0; i < poly->numVerts(); i++) {
    poly->getPointAt(i, current);
    
    if (i > 0) {
      extent += L", ";
    } else {
      start = current;
    }
    extent += Round(current.x, 0) + L" " + Round(current.y, 0);
  }
  if (!start.isEqualTo(current)) {
    extent += L", " + Round(start.x, 0) + L" " + Round(start.y, 0);
  }
  
  extent += L"))";
  
  poly->close();
  
  return extent;
}
예제 #2
0
    //-------------------------------------------------------------------------------------------
    //
    //  功能: 将从AcDbObject派生数据库对象保存到实体的扩展词典中
    //
    //  作者:Qin H.X.
    //
    // 日期:200709
    //
    //  历史:
    //          2007.10.08 修改 by Qin H.X.
    //
    //----------------------------------------------------------------------------------------------
    // - CSCH081.AddAttribute command (do not rename)
    static void CSCH081AddAttribute(void)
    {
        AcDbObjectId dictObjId,eId, attId;
        AcDbDictionary* pDict;
        //选择管道(多义线)
        ads_name en;
        ads_point pt;
        if (  acedEntSel(_T("\n选择管道(多义线): "), en, pt)!= RTNORM)
        {
            acutPrintf(_T("\n选择失败,退出: "));
            return ;
        }
        // 打开对象
        acdbGetObjectId(eId, en);
        AcDbEntity * pEnt;
        acdbOpenObject(pEnt, eId,  AcDb::kForWrite);
        if(!pEnt->isKindOf (AcDbPolyline::desc ()))
        {
            acutPrintf(_T("\n选择的不是管道(多义线),退出: " ));
            return ;
        }

        // 判断实体的扩展词典是否创建,如果没有则创建
        dictObjId = pEnt->extensionDictionary();
        if(	dictObjId ==  AcDbObjectId::kNull )
        {
            pEnt->createExtensionDictionary();
        }

        // 获取实体的扩展词典
        dictObjId = pEnt->extensionDictionary();
        pEnt->close();

        // 	判断词典中的属性是否创建
        CPipeAttribute* pAttribute;
        acdbOpenObject(pDict, dictObjId, AcDb::kForWrite);
        pDict->getAt (_T("属性"),attId);
        if(attId!= AcDbObjectId::kNull )//如果已经创建则输出数据
        {
            acdbOpenObject(pAttribute, attId, AcDb::kForRead);
            acutPrintf(_T("\n管径:%4.2f " ),pAttribute->m_dRadius);
            acutPrintf(_T("\n壁厚:%4.2f " ),pAttribute->m_dThickness );
            acutPrintf(_T("\n埋深:%4.2f " ),pAttribute->m_dDeep );
            acutPrintf(_T("\n材质:%s " ),pAttribute->m_cMaterial  );
        }
        else
        {
            //没有则创建属性
            pAttribute = new CPipeAttribute();
            pDict->setAt(_T("属性"), pAttribute, attId);
        }
        //关闭对象
        pDict->close();
        pAttribute->close();

    }
예제 #3
0
//0,不显示属性,1,显示属性,2,显示属性默认值
void CZhfPalette::FilterDb(AcDbDatabase* pDb, int iFilterMode)
{
	if (iFilterMode==1)
	{
		return ;
	}
	Acad::ErrorStatus es ;
	AcDbBlockTable* pBT = NULL ;
	pDb->getBlockTable(pBT, AcDb::kForRead);
	AcDbBlockTableRecord* pBTR = NULL;
	es = pBT->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForWrite);
	pBT->close();

	AcDbBlockTableRecordIterator* pIT;
	es = pBTR->newIterator(pIT) ;
	for (; !pIT->done(); pIT->step()) 
	{
		AcDbEntity* pEnt = NULL ;
		if (Acad::eOk==pIT->getEntity(pEnt, AcDb::kForWrite))
		{
			if (pEnt->isKindOf(AcDbAttributeDefinition::desc()))
			{
				AcDbAttributeDefinition *pAttDef = AcDbAttributeDefinition::cast(pEnt);

				if (iFilterMode==0)
				{
					pEnt->erase() ;
				}
				else if (iFilterMode>1)
				{
					if (pAttDef != NULL && !pAttDef->isConstant())
					{
						// We have a non-constant attribute definition,
						// so build an attribute entity.
						CString strShowVal ;

						if (iFilterMode==2)
						{
							strShowVal = pAttDef->textString() ;
						}
						else if (iFilterMode==3)
						{
							strShowVal = pAttDef->prompt() ; //显示中文为乱码
						}
						pAttDef->setTag(strShowVal) ;
					}
				}
			}
			pEnt->close() ;
		}
	}

	delete pIT;
	pBTR->close();
}
예제 #4
0
bool Additional_Class::Get_LayerLW( CString LayerName, double &Length, double &Width )
{
	AcDbLayerTable *pLayerTbl = NULL;
	acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTbl,AcDb::kForRead);
	if (!pLayerTbl->has(LayerName))
	{
		//acutPrintf("\n木有%s层!", LayerName);
		//SetError("THERE ISN`T"+LayerName+"LATYER!",  "Get_LayerLW");
		pLayerTbl->close();
		return false;
	}
	AcDbObjectId layerId;
	pLayerTbl->getAt(LayerName, layerId);
	pLayerTbl->close();
	AcDbBlockTable *pBlkTbl = NULL;
	////获得当前数据库块表
	acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite);
	////获得模型空间块表记录
	AcDbBlockTableRecord *pBlkTblRcd = NULL;
	pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForRead);
	pBlkTbl->close();

	////创建块表记录遍历器

	AcDbBlockTableRecordIterator *pltr;
	pBlkTblRcd->newIterator(pltr);

	AcDbEntity *pEnt;
	//AcDbEntityPointer pEnt_Ptr;
	////AcDbObjectPointer<AcDbPolyline> pPolyLine_Ptr;
	AcDbPolyline *pPolyLine = NULL;
	AcDbObjectIdArray PolyLineID_List;
	for (pltr->start(); !pltr->done(); pltr->step())
	{
		pltr->getEntity(pEnt, AcDb::kForRead);
	//	//pEnt_Ptr.acquire(pEnt);
		if (pEnt->layerId()==layerId)
		{
			if (pEnt->isKindOf(AcDbPolyline::desc()))
			{
				pPolyLine = AcDbPolyline::cast(pEnt);
				if (pPolyLine != NULL)
				{
					if (PolyLineIfRectangle(pPolyLine)==true)
					{
						PolyLineID_List.append(pPolyLine->objectId());
					}
				}
			}
		}
	}

	if (PolyLineID_List.length() >1)
	{
		acutPrintf(_T("Bom Error 1002\n"));// 有很多矩形
		delete pltr;
		pEnt->close();
		pPolyLine->close();
		pBlkTblRcd->close();
		return false;
	}
	////pPolyLine.open(PolyLineID_List[0], AcDb::kForRead);
	acdbOpenAcDbEntity(pEnt,PolyLineID_List[0], AcDb::kForRead);	//error!
	pPolyLine =  AcDbPolyline::cast(pEnt);
	Get_RectangleLW(pPolyLine, Length, Width);
	pBlkTblRcd->close();
	pPolyLine->close();
	pEnt->close();
	delete pltr;
	return true;
}
void
refEditApiExample()
{

    AcDbObjectId transId;
    AcDbDatabase* pDb;
    char *fname;
    struct resbuf *rb;

    // Get a dwg file from the user.
    //
    rb = acutNewRb(RTSTR);
    int stat = acedGetFileD("Pick a drawing", NULL, "dwg", 0, rb);
    
    if ((stat != RTNORM) || (rb == NULL)) {
        acutPrintf("\nYou must pick a drawing file.");
        return;
    }

    fname = (char*)acad_malloc(strlen(rb->resval.rstring) + 1);
    strcpy(fname, rb->resval.rstring);
    acutRelRb(rb);
    
    // Open the dwg file.
    //
    pDb = new AcDbDatabase(Adesk::kFalse);
    if (pDb->readDwgFile(fname) != Acad::eOk) {
        acutPrintf("\nSorry, that draing is probably already open.");
        return;
    }

    // Get the Block Table and then the model space record.
    //
    AcDbBlockTable *pBlockTable;
    pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
    AcDbBlockTableRecord *pOtherMsBtr;
    pBlockTable->getAt(ACDB_MODEL_SPACE, pOtherMsBtr, AcDb::kForRead);
    pBlockTable->close();

    // Create an iterator.
    //
    AcDbBlockTableRecordIterator *pIter;
    pOtherMsBtr->newIterator(pIter);

    // Set up an object ID array.
    //
    AcDbObjectIdArray objIdArray;

    // Iterate over the model space BTR. Look specifically 
    // for lines and append their object ID to the array.
    //
    for (pIter->start(); !pIter->done(); pIter->step()) {
        AcDbEntity *pEntity;
        pIter->getEntity(pEntity, AcDb::kForRead);

        // Look for only AcDbLine objects and add them to the 
        // object ID array.
        //
        if (pEntity->isKindOf(AcDbLine::desc())) {
            objIdArray.append(pEntity->objectId());
        }
        pEntity->close();
    }
    delete pIter;
    pOtherMsBtr->close();

    if (objIdArray.isEmpty()) {
        acad_free(fname);
        acutPrintf("\nYou must pick a drawing file that contains lines.");
        return;
    }

    // Now get the current database and the object ID for the
    // current database's model space BTR.
    //
    AcDbBlockTable *pThisBlockTable;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pThisBlockTable, AcDb::kForRead);

    AcDbBlockTableRecord *pThisMsBtr;
    pThisBlockTable->getAt(ACDB_MODEL_SPACE, pThisMsBtr, AcDb::kForWrite);
    pThisBlockTable->close();
    
    AcDbObjectId id = pThisMsBtr->objectId();
    pThisMsBtr->close();


    // Create the long transaction. This will check all the entities 
    // out of the external database.
    //
    AcDbIdMapping errorMap;
    acapLongTransactionManagerPtr()->checkOut(transId, objIdArray, id, errorMap);

    // Now modify the color of these entities.
    //
    int colorIndex;
    acedGetInt("\nEnter color number to change entities to: ", &colorIndex);
    AcDbObject* pObj;
    if (acdbOpenObject(pObj, transId, AcDb::kForRead) == Acad::eOk) {

        // Get a pointer to the transaction.
        //
        AcDbLongTransaction* pLongTrans = AcDbLongTransaction::cast(pObj);
        if (pLongTrans != NULL) {

            // Get a work set iterator.
            //
            AcDbLongTransWorkSetIterator* pWorkSetIter;
            pLongTrans->newWorkSetIterator(pWorkSetIter);

            // Iterate over the entities in the work set and change the color.
            //
            for (pWorkSetIter->start(); !pWorkSetIter->done(); pWorkSetIter->step()) {
                AcDbEntity *pEntity;
                acdbOpenAcDbEntity(pEntity, pWorkSetIter->objectId(), AcDb::kForWrite);
                pEntity->setColorIndex(colorIndex);
                pEntity->close();
            }
            delete pWorkSetIter;
        }
        pObj->close();
    }

    // Pause to see the change.
    //
    char str[132];
    acedGetString(0, "\nSee the new colors. Press return to check the object into the original database", str);

    // Check the entities back in to the original database.
    //
    acapLongTransactionManagerPtr()->checkIn(transId, errorMap);

    // Save the original database, since we have made changes.
    //
    pDb->saveAs(fname);

    // Close/Delete the database
    //
    delete pDb;
    pDb = NULL;

    acad_free(fname);
}
예제 #6
0
파일: BlockDraw.cpp 프로젝트: kanbang/TIDS
static void BlockToEntity( const AcDbObjectId& blkId, const AcGeMatrix3d& blkXform,
                           const AcStringArray& names, const AcStringArray& attValues,
                           AcGeVoidPointerArray& ents )
{
    // 将块定义分解成独立的图元
    // 将属性替换成多行文字
    AcTransaction* pTrans = actrTransactionManager->startTransaction();
    AcDbObject* pObj;
    if( Acad::eOk != pTrans->getObject( pObj, blkId, AcDb::kForRead ) )
    {
        actrTransactionManager->abortTransaction();
        return;
    }

    AcDbBlockTableRecord* pBTR = AcDbBlockTableRecord::cast( pObj );
    // BUG:不能调用hasAttributeDefinitions()方法
    // 调用之后,如果没有在块编辑器中对块进行修改,
    // 那么进行移动、夹点编辑等操作,没有动态显示效果
    //if(!pBTR->hasAttributeDefinitions())
    //{
    //	// 没有属性定义
    //	acutPrintf(_T("\n没有属性定义"));
    //	actrTransactionManager->abortTransaction();
    //	return;
    //}

    AcDbBlockTableRecordIterator* pIterator;
    if( Acad::eOk != pBTR->newIterator( pIterator ) )
    {
        actrTransactionManager->abortTransaction();
        return;
    }

    // 遍历块中的图元,查找AcDbAttributeDefinition
    for( pIterator->start( true ); !pIterator->done(); pIterator->step( true ) )
    {
        AcDbObjectId objId;
        if( Acad::eOk != pIterator->getEntityId( objId ) ) continue;
        if( Acad::eOk != pTrans->getObject( pObj, objId, AcDb::kForWrite ) ) continue;

        AcDbEntity* pEnt = AcDbEntity::cast( pObj );
        if( !pEnt->isKindOf( AcDbAttributeDefinition::desc() ) )
        {
            AcDbEntity* pClone = AcDbEntity::cast( pEnt->clone() );
            pClone->transformBy( blkXform );
            // 添加到实体集合
            ents.append( pClone );
        }
        else
        {
            AcDbAttributeDefinition* pAttDef = AcDbAttributeDefinition::cast( pEnt );
            pAttDef->convertIntoMTextAttributeDefinition( Adesk::kTrue );

            // 获取标签名称
            ACHAR* pTag = pAttDef->tag();
            int pos = names.find( pTag );
            if( pos != -1 )
            {
                // 获取多行文本对象
                AcDbMText* pMText = pAttDef->getMTextAttributeDefinition();
                pMText->transformBy( blkXform );
                pMText->setContents( attValues[pos].kACharPtr() );
                // 添加到实体集合
                ents.append( pMText );
            }
            acutDelString( pTag );
        }
    }
    delete pIterator;
    actrTransactionManager->endTransaction();
}
예제 #7
0
void 
polyeditCommand()
{
	Adesk::Boolean interrupted = Adesk::kFalse;
	Adesk::Boolean	    done;
    Acad::ErrorStatus es = Acad::eOk;
    AcDbFullSubentPath nullSub;
	AcGePoint2d   savedCenter;
	AcGePoint2d   savedStartPoint;
	int	     savedNumSides;
	AcGeVector3d  savedNormal;
	char	     savedName[133];
    double savedElevation;
    
    // Select an AsdkPoly entity.
    
    AsdkPoly	 *poly = NULL;
    AcDb3dSolid  *solid = NULL;
    AcDbObjectId  objId;
    
    ads_name	  ename;
    ads_point     ptres;

    AcDbEntity* ent;

	ads_name ss ;
	if ( acedSSGet ("_I", NULL, NULL, NULL, ss) == RTNORM ) {
		long n ;
		acedSSLength (ss, &n) ;
		switch ( n ) {
			case 0:
				//----- Not possible, but ?
				break ;
			case 1:
				acedSSName (ss, 0, ename) ;

				AOK(acdbGetObjectId(objId, ename));
        
				AOK(acdbOpenAcDbEntity(ent, objId, AcDb::kForRead));
				assert(ent != NULL);
        
				poly = AsdkPoly::cast(ent);
				if (poly == NULL) {
					acutPrintf("\nNot a polygon.");
					AOK(ent->close());
				}
				break ;
			default:
				//----- If more than one entity selected, fallback in standard selection mode
				break ;
		}
		acedSSFree (ss) ;
	}

	while ( poly == NULL ) {

		switch (acedEntSel("\nSelect a poly: ", ename, ptres)) {
        
		case RTNORM:
        
			AOK(acdbGetObjectId(objId, ename));
        
			AOK(acdbOpenAcDbEntity(ent, objId, AcDb::kForRead));
			assert(ent != NULL);
        
			poly = AsdkPoly::cast(ent);
			if (poly == NULL) {
				acutPrintf("\nNot a polygon.");
				AOK(ent->close());
				continue;
			}
        
			break;
        
		case RTNONE:
		case RTCAN:
			return;
		default:
			continue;
		}
		break;
	}

    // Now we have a polygon. Start editing it.
    
    char option[256];
    
    done = Adesk::kFalse;
    interrupted = Adesk::kFalse;
    
    while (!done && !interrupted) {
        
        AOK(getEditOption(option,interrupted));
        
        if (strcmp(option, "Grow") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(growPoly(poly));
            
        } else if (strcmp(option, "Shrink") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(shrinkPoly(poly));
            
        } else if (strcmp(option, "More") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(morePoly(poly));
            
        } else if (strcmp(option, "Less") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(lessPoly(poly));
            
        } else if (strcmp(option, "Thicken") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(thickenPoly(poly, ent, savedCenter,savedStartPoint, savedNumSides,savedNormal,savedName,savedElevation));
            
            solid = AcDb3dSolid::cast(ent);
            assert(solid != NULL);
            poly = NULL;
            
            
            solid->draw();
            
        } else if (strcmp(option, "Flatten") == 0) {
            
            if (!ent->isKindOf(AcDb3dSolid::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(flattenPoly(solid,ent,savedCenter,savedStartPoint, savedNumSides,savedNormal,savedName,savedElevation));
            
            poly = AsdkPoly::cast(ent);
            assert(poly != NULL);
            solid = NULL;
            
            
        } else if (strcmp(option, "Name") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            Acad::ErrorStatus es;
            if ((es = namePoly(poly)) != Acad::eOk) {
                acutPrintf("\nError setting Poly's name. Error: %s",
                    acadErrorStatusText(es));
                done = Adesk::kTrue;
                continue;
            }
            if ((es = stylePoly(poly)) != Acad::eOk) {
                acutPrintf("\nError setting Poly's text style. Error: %s",
                    acadErrorStatusText(es));
                done = Adesk::kTrue;
                continue;
            }
        } else if (strcmp(option, "EXit") == 0) {
            done = Adesk::kTrue;
        } else {
            done = Adesk::kTrue;
        }
        
    }
    
    // Close the entity corresponding to the open for read right
    // after selection.
    
    AOK(ent->close());
}
예제 #8
0
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 ;


}