- UID
- 33023
- 积分
- 157
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-3-3
- 最后登录
- 1970-1-1
|
发表于 2004-7-24 09:36:15
|
显示全部楼层
#include "StdAfx.h"
#include "StdArx.h"
//#include ".\pmtDBX\PFGpmtinit.h"
#include <dbsymtb.h>
#include <math.h>
#include "CommonUtils.h"
//ÃüÃû¶ÔÏó´ÊµäÖÐÎÞËùÐèÉú³ÉµÄ´Êµä£¨dictName£©Ê±Éú³É´Êµä£¬µ±DdictName´æÔÚʱֱ½Ó·µ»Ø
void createDictionary(char *dictName)
{
AcDbDictionary *pNameDict;
acdbHostApplicationServices()->workingDatabase()->
getNamedObjectsDictionary(pNameDict, AcDb::kForWrite);
AcDbDictionary *pDict;
if (pNameDict->getAt(dictName, (AcDbObject*&) pDict,
AcDb::kForWrite) == Acad::eKeyNotFound)
{
pDict = new AcDbDictionary;
AcDbObjectId DictId;
pNameDict->setAt(dictName, pDict, DictId);
}
pNameDict->close();
pDict->close();
}
//½«×Ô¶¨Òå¶ÔÏópObj¼ÓÈë´ÊµädictName£¬¶ÔÏóÃûΪobjectName¡£´ÊµädictName²»´æÔÚʱ£¬µ÷ÓÃcreatDictionary()Éú³É¡£
void addObjectToDict(AcDbObject *pObj,char *objectName,char *dictName)
{
createDictionary(dictName);
AcDbDictionary *pNamedobj;
acdbHostApplicationServices()->workingDatabase()
->getNamedObjectsDictionary(pNamedobj, AcDb::kForRead);
Acad::ErrorStatus es;
AcDbDictionary *pDict;
es=pNamedobj->getAt(dictName, (AcDbObject*&)pDict,
AcDb::kForWrite);
pNamedobj->close();
if (es==Acad::eOk) //ʹÓÃif(pDict)²»ÄÜÆðµ½ÅжϵÄ×÷Óá£
{
// add new objects to the dictionary,
// then close them.
AcDbObjectId rId1;
pDict->setAt(objectName, pObj, rId1);
pDict->close(); //²»ÄÜ·ÅÔڸô¦{}Ö®Í⣬¼´Î´ÄÜÕý³£»ñÈ¡£¬¾ÍÎÞËùν¹Ø±Õ£¬·ñÔò³ö´í¡£
}
// pDict->close();
}
//¸ù¾ÝCADÁ½µã×ø±ê¼°¶ÔÓ¦µÄ´óµØ×ø±ê£¨¾­Î³¾à£©¼ÆËãÁ½×ø±êϵµÄ¼Ð½Çangle¼°±ÈÀýת»»ÏµÊýK
//¼ÆËã´óµØ×ø±êϵԭµãÔÚCADÊÀ½ç×ø±êϵÖеÄÔ­µã×ø±êearthorg
//º¯Êýreturn¼Ð½Ç£¬Æ䵥λΪ»¡¶È
float EonAndXoyAngle(ads_point cadPt1,ads_point cadPt2,ads_point earthPt1,ads_point earthPt2,double &k,ads_point &earthOrg)
{
float angle;
double n,e,x,y;
float ax,ae;
n=(earthPt2[Y]-earthPt1[Y]);
e=(earthPt2[X]-earthPt1[X]);
x=(cadPt2[X]-cadPt1[X]);
y=(cadPt2[Y]-cadPt1[Y]);
k=sqrt((n*n+e*e)/(x*x+y*y));
ax=atan2(y,x); //Ï߶ÎÓëXÖáµÄ¼Ð½Ç
ae=atan2(n,e); //Ï߶ÎÓëEÖáµÄ¼Ð½Ç
angle=(ax-ae);
earthOrg[X]=cadPt1[X]-(cos(angle)*earthPt1[X]-sin(angle)*earthPt1[Y])/k;
earthOrg[Y]=cadPt1[Y]-(cos(angle)*earthPt1[Y]+sin(angle)*earthPt1[X])/k;
return angle;
}
//½«CAD×ø±êת»»Îª´óµØ×ø±ê
void xyToEn(ads_point cadPt,ads_point& earthPt,ads_point earthOrg,float angle, double k)
{
earthPt[X]=k*(cos(angle)*(cadPt[X]-earthOrg[X])+sin(angle)*(cadPt[Y]-earthOrg[Y]));
earthPt[Y]=k*(-sin(angle)*(cadPt[X]-earthOrg[X])+cos(angle)*(cadPt[Y]-earthOrg[Y]));
}
//½«´óµØ×ø±êת»»ÎªCAD×ø±ê
void enToXY(ads_point earthPt,ads_point& cadPt,ads_point earthOrg,float angle, double k)
{
cadPt[X]=earthOrg[X]+(cos(angle)*earthPt[X]-sin(angle)*earthPt[Y])/k;
cadPt[Y]=earthOrg[Y]+(cos(angle)*earthPt[Y]+sin(angle)*earthPt[X])/k;
}
// Åж¨µ±Ç°Í¼ÐÎÖÐÓÐÎÞ¸ø¶¨¿éÃûµÄ¿é±í¼Ç¼£¬Óзµ»Øtrue¡¢Í¬Ê±·µ»ØÆäid£¬
//·ñÔò·µ»Øflase
bool existBlock(char* pBlockName,AcDbObjectId &blockId)
{
AcDbBlockTable* pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable,AcDb::kForRead);
if(pBlockTable->has(pBlockName))
{
pBlockTable->getAt(pBlockName,blockId);
pBlockTable->close();
return true;
}
else
{
pBlockTable->close();
return false;
}
}
// °ÑһͼÐÎÎļþdwg²åÈ뵱ǰͼÐÎ×÷Ϊһ¿é£¬²¢¸øÓè¿éÃû¡£ÈôÓÐͬÃû¿é¾Í²»ÔÙ²åÈë¡£
bool insertDwgToCurDwg(char* pFullPathFile,char* pBlockName,AcDbObjectId &blockId)
{
AcDbDatabase *pNewDb,*pCurDb;
Acad::ErrorStatus es;
if(existBlock(pBlockName,blockId))
{
return true;
}
pNewDb=new AcDbDatabase(Adesk::kFalse);
es=pNewDb->readDwgFile(pFullPathFile, _SH_DENYNO,false);
if (es!=Acad::eOk)
{
acutPrintf("¶ÁÎļþ´í");
delete pNewDb;
return false;
}
pCurDb =acdbHostApplicationServices()->workingDatabase();
if((es=pCurDb->insert(blockId, pBlockName,pNewDb, true))==Acad::eOk)
{
delete pNewDb;
return true;
}
else
{
delete pNewDb;
return false;
}
}
奇怪!!从vc 6.0中拷贝粘贴过来,中文不能正常显示 |
|