- UID
- 30105
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-2-18
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
// RegionGraph.h: interface for the CRegionGraph class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_REGIONGRAPH_H__F0B13024_7238_44D7_9966_1F79DEC8EEED__INCLUDED_)
#define AFX_REGIONGRAPH_H__F0B13024_7238_44D7_9966_1F79DEC8EEED__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CRegionGraph
{
public:
AcGeVector3d getUcsZAxis(AcDbDatabase* db);
AcGeVector3d getUcsYAxis(AcDbDatabase* db);
AcGeVector3d getUcsXAxis(AcDbDatabase* db);
AcGePlane getUcsPlane(AcDbDatabase* db);
// AcDbObjectIdArray regionsArrayId;
// AcGePoint2d centroid;
// double area;
int GetRegionsAreaProp(ads_point internalpt , double& area ,AcGePoint2d& centroid ,AcDbObjectIdArray& regions ,int& num );
int GetBoundaryCommandObjects(ads_point internalpt ,AcDbObjectIdArray& regions);
AcGePoint2d CentriodSub(double mass, AcGePoint2d& pt, double masssub, AcGePoint2d &ptsub);
AcGePoint2d CentroidUnite(double mass1,AcGePoint2d &pt1,double mass2,AcGePoint2d &pt2 );
Acad::ErrorStatus GetAreaProp( AcDbRegion *pregion,double& area ,AcGePoint2d& centroid );
int BoundaryCMD(ads_point internalpt);
CRegionGraph();
virtual ~CRegionGraph();
};
#endif // !defined(AFX_REGIONGRAPH_H__F0B13024_7238_44D7_9966_1F79DEC8EEED__INCLUDED_)
// RegionGraph.cpp: implementation of the CRegionGraph class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "RegionGraph.h"
#include "dbregion.h"
#include "Select.h"
#include "geplane.h"
#include "gemat3d.h"
#include "dbxutil.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CRegionGraph::CRegionGraph()
{
}
CRegionGraph::~CRegionGraph()
{
}
int CRegionGraph::BoundaryCMD(ads_point internalpt)
{
int err ;
err = acedCommand(RTSTR, "boundary",RTSTR, "A", RTSTR, "O",RTSTR, "R",RTSTR, "B",RTSTR, "E",RTSTR, "",0);
if( err != RTNORM)
{
acutPrintf("\nBOUNDARYÉèÖø߼¶ÊôÐÔʧ°Ü");
return err ;
}
err = acedCommand(RTPOINT,internalpt,RTSTR, "", 0) ;
if( err != RTNORM )
{
acutPrintf("\nÑ¡ÔñÄÚ²¿µãʧ°Ü");
return err ;
}
return RTNORM;
}
Acad::ErrorStatus CRegionGraph::GetAreaProp(AcDbRegion *pregion ,
double& area ,//·µ»Ø×ÜÃæ»ý
AcGePoint2d& centroid //·µ»ØÖÊÁ¿ÖÐÐÄ
)
{
AcDbDatabase* db = acdbHostApplicationServices()->workingDatabase();
Acad::ErrorStatus err ;
AcGePoint3d origin ;
origin.set(0,0,0);
AcGeVector3d xAxis;
xAxis = getUcsXAxis(db) ;
//xAxis.set(1,0,0) ;
AcGeVector3d yAxis;
yAxis = getUcsYAxis(db) ;
//yAxis.set(0,1,0);
double perimeter;
//double area;
//AcGePoint2d centroid;
double momInertia[2];
double prodInertia;
double prinMoments[2];
AcGeVector2d prinAxes[2];
double radiiGyration[2];
AcGePoint2d extentsLow ;
AcGePoint2d extentsHigh ;
err = pregion ->getAreaProp(origin, xAxis, yAxis,
perimeter,
area,
centroid,
momInertia,
prodInertia,
prinMoments,
prinAxes,
radiiGyration,
extentsLow ,
extentsHigh
) ;
return err ;
}
AcGePoint2d CRegionGraph::CentroidUnite(double mass1, AcGePoint2d &pt1, double mass2, AcGePoint2d &pt2)
{
AcGePoint2d centerpt ;
centerpt.x = (mass1 * pt1.x + mass2 * pt2.x)/(mass1+mass2) ;
centerpt.y = (mass1 * pt1.y + mass2 * pt2.y)/(mass1+mass2) ;
return centerpt ;
}
AcGePoint2d CRegionGraph::CentriodSub(double mass, AcGePoint2d &pt, double masssub, AcGePoint2d &ptsub)
{
AcGePoint2d centerpt ;
centerpt.x = (mass * pt.x - masssub * ptsub.x)/(mass-masssub) ;
centerpt.y = (mass * pt.y - masssub * ptsub.y)/(mass-masssub) ;
return centerpt ;
}
int CRegionGraph::GetBoundaryCommandObjects(ads_point internalpt ,
AcDbObjectIdArray& regions)//·µ»ØÄ¿±ê¼¯ºÏ
{
ads_name lname0 ,lname1 ,lastname;
//************************************************
int err = acdbEntLast(lastname);
if (err != RTNORM)
{
acutPrintf("\n³õʼ»¯Ê§°Ü");
return err;
}
//--------------------------------------------------
err = BoundaryCMD(internalpt) ;
if (err != RTNORM)
{
acutPrintf("\nBoundary µ÷ÓÃʧ°Ü");
return err;
}
//********************************************
err = acdbEntNext(lastname, lname0) ;
if (err != RTNORM )
{
acutPrintf("\nûÓÐÉú³ÉÃæÓò");
return err ;
}
//**************************************************
do {
AcDbObjectId objId;
if (Acad::eOk != acdbGetObjectId(objId, lname0))
{
acutPrintf("\n»ñÈ¡ObjectIdʧ°Ü");
return RTERROR ;
}
AcDbEntity *pEntity;
if (Acad::eOk !=acdbOpenAcDbEntity(pEntity, objId, AcDb::kForRead)) //ͨ¹ý¶ÔÏóID»ñÈ¡¶ÔÏó¾ä±úÖ¸Õë
{
acutPrintf("\n»ñÈ¡¶ÔÏó½øÐжÁ²Ù×÷ʧ°Ü");
return RTERROR ;
}
const char *pCname = pEntity->isA()->name();//»ñÈ¡¶ÔÏóÀàÃû
if(strcmp(pCname,"AcDbRegion") !=0)
{
if (Acad::eOk != pEntity ->close())
{
acutPrintf("\n¶ÔÏó¹Ø±Õʧ°Ü");
return RTERROR ;
}
continue ;
}
AcDbRegion *pregion;
pregion=AcDbRegion::cast(pEntity);
if(pregion !=NULL)
{
regions.append(objId);
}
if (Acad::eOk != pregion->close())
{
acutPrintf("\nÃæÓò¶ÔÏó¹Ø±Õʧ°Ü");
return RTERROR ;
}
if (Acad::eOk != pEntity ->close())
{
acutPrintf("\n¶ÔÏó¹Ø±Õʧ°Ü");
return RTERROR ;
}
ads_name_set(lname0, lname1);
} while (acdbEntNext(lname1, lname0) == RTNORM );
//*****************************************************
return RTNORM ;
}
int CRegionGraph::GetRegionsAreaProp(ads_point internalpt , //ÊäÈëÄÚ²¿Ò»µã
double &area, //·µ»ØÃæ»ý
AcGePoint2d ¢roid ,//·µ»ØÖÊÁ¿ÖÐÐÄ
AcDbObjectIdArray& regions , //·µ»Øregions¼¯ºÏ
int& num //·µ»ØÊýÁ¿
)
{
double areak = 0 ;
area = 0 ;
AcGePoint2d centroidk ;
centroidk.set(0,0);
centroid.set(0,0) ;
//*****************************************************
int err = GetBoundaryCommandObjects(internalpt ,regions);
if (err != RTNORM )
{
// acutPrintf("\nûÓÐÃæÓòÉú³É");
return err ;
}
///****************************************************
int length ;
length = regions.length() ;
num = length ;
for (int i = 0 ; i < length ; i++)
{
AcDbEntity *pEntity;
acdbOpenAcDbEntity(pEntity, regions, AcDb::kForRead); //ͨ¹ý¶ÔÏóID»ñÈ¡¶ÔÏó¾ä±úÖ¸Õë
const char *pCname = pEntity->isA()->name();//»ñÈ¡¶ÔÏóÀàÃû
if(strcmp(pCname,"AcDbRegion") !=0)
{
pEntity ->close();
continue ;
}
AcDbRegion *pregion;
pregion=AcDbRegion::cast(pEntity);
if (Acad::eOk != GetAreaProp(pregion,areak ,centroidk ))
{
acutPrintf("\n»ñÈ¡µÚ%d¸öÃæ»ýÊôÐÔʧ°Ü",i+1);
return RTERROR ;
}
if(i != 0)
{
areak = -areak ;
}
// acutPrintf("\nÃæ»ý%.3f",areak);
//-----------------------------------------------------------------------
pregion->close();
pEntity->close();
centroid = CentroidUnite(area ,centroid ,areak ,centroidk);
area = area + areak ;
}
// acutPrintf("\nÃæ»ý%.3f",area);
return RTNORM ;
}
//DEL int CRegionGraph::AreaAndCentroid(double& tolarea , AcGePoint2d& tolcentroid)
//DEL {
//DEL ads_name sset;
//DEL acedSSAdd(NULL, NULL, sset);//´´½¨Ò»¸ö¿ÕµÄÑ¡Ôñ¼¯
//DEL CSelect sel ;
//DEL tolarea = 0 ;
//DEL tolcentroid.set(0,0) ;
//DEL
//DEL for (int i = 0 ; i < 100 ; i++){
//DEL //************************************************
//DEL ads_point internalpt ;
//DEL
//DEL int err = acedGetPoint( NULL,
//DEL "\nÇëÑ¡ÔñÄÚ²¿Ò»µã,°´ENTER½áÊø!",internalpt) ;
//DEL if ( err == RTNONE )
//DEL {
//DEL sel.EarseS(sset);
//DEL acedSSFree(sset);
//DEL acutPrintf("\nËùÑ¡ÔñÇøÓòµÄ×ÜÃæ»ýΪ:%.3f mm^2",tolarea);
//DEL acutPrintf("\n×ÜÐÎÐÄ×ø±êΪ:[%.3f,%.3f] ",tolcentroid.x , tolcentroid.y);
//DEL return err;
//DEL }
//DEL if ( err == RTCAN )
//DEL {
//DEL sel.EarseS(sset);
//DEL acedSSFree(sset);
//DEL return err ;
//DEL }
//DEL if(err != RTNORM)
//DEL {
//DEL continue ;
//DEL }
//DEL if ( i==99 )
//DEL {
//DEL sel.EarseS(sset);
//DEL acedSSFree(sset);
//DEL
//DEL }
//DEL //***********************************************
//DEL
//DEL double area; //·µ»ØÃæ»ý
//DEL AcGePoint2d centroid ;//·µ»ØÖÊÁ¿ÖÐÐÄ
//DEL AcDbObjectIdArray regions ; //·µ»Øregions¼¯ºÏ
//DEL int num ; //·µ»ØÊýÁ¿
//DEL
//DEL err= GetRegionsAreaProp(internalpt , area ,centroid ,regions ,num );
//DEL if(err != RTNORM)
//DEL {
//DEL continue ;
//DEL }
//DEL
//DEL if (! regions.isEmpty()){
//DEL
//DEL int length ;
//DEL
//DEL length = regions.length();
//DEL
//DEL for (int k = 0 ; k < length ; k++)
//DEL {
//DEL ads_name objName ;
//DEL acdbGetAdsName( objName, regions[k]) ;
//DEL acedSSAdd(objName , sset, sset);
//DEL }
//DEL sel.highlight(sset);
//DEL //---------------------------------------------
//DEL tolcentroid = CentroidUnite(tolarea ,tolcentroid ,area ,centroid) ;
//DEL tolarea += area ;
//DEL
//DEL }
//DEL }
//DEL
//DEL return RTNORM ;
//DEL
//DEL }
AcGePlane
CRegionGraph::getUcsPlane(AcDbDatabase* db)
{
ASSERT(db != NULL);
AcGeMatrix3d m;
if (acdbUcsMatrix(m, db)) {
AcGePoint3d origin;
AcGeVector3d xDir, yDir, zDir;
m.getCoordSystem(origin, xDir, yDir, zDir);
AcGePlane ucsPlane(origin, xDir, yDir);
return ucsPlane;
}
else {
ASSERT(0);
AcGePlane ucsPlane(AcGePoint3d::kOrigin, AcGeVector3d::kIdentity);
return ucsPlane;
}
}
//*****************************
AcGeVector3d
CRegionGraph::getUcsXAxis(AcDbDatabase* db)
{
ASSERT(db != NULL);
AcGeMatrix3d m;
if (acdbUcsMatrix(m, db)) {
AcGePoint3d origin;
AcGeVector3d xDir, yDir, zDir;
m.getCoordSystem(origin, xDir, yDir, zDir);
return xDir;
}
else {
ASSERT(0);
return AcGeVector3d::kXAxis;
}
}
/****************************************************************************
**
** CRegionGraph::getUcsYAxis
** returns current UCS Y Axis, even if currently the paperSpace viewport
**
** **jma
*/
//*************************************/
AcGeVector3d
CRegionGraph::getUcsYAxis(AcDbDatabase* db)
{
ASSERT(db != NULL);
AcGeMatrix3d m;
if (acdbUcsMatrix(m, db)) {
AcGePoint3d origin;
AcGeVector3d xDir, yDir, zDir;
m.getCoordSystem(origin, xDir, yDir, zDir);
return yDir;
}
else {
ASSERT(0);
return AcGeVector3d::kYAxis;
}
}
/****************************************************************************
**
** CRegionGraph::getUcsZAxis
**
** **jma
**
*************************************/
AcGeVector3d
CRegionGraph::getUcsZAxis(AcDbDatabase* db)
{
ASSERT(db != NULL);
AcGeMatrix3d m;
if (acdbUcsMatrix(m, db)) {
AcGePoint3d origin;
AcGeVector3d xDir, yDir, zDir;
m.getCoordSystem(origin, xDir, yDir, zDir);
return zDir;
}
else {
ASSERT(0);
return AcGeVector3d::kZAxis;
}
} |
|