#ifndef __PIPETOOLS_H #define __PIPETOOLS_H #include "DbPsConfig.h" /*============================================================================* * Copyright(c), 1994-2007, Beijing Tangent Engineering Software Co.Ltd. * 文 件 名: PipeTools.h * 归属项目: 给排水,暖通 =============================================================================*/ #define PS_SNAP (20.0*_distSnap) #define MIRROR_XAXIS 0x01 // x轴镜像 #define MIRROR_YAXIS 0x02 // y轴镜像 // 当前数据库中的全局变量 #define g_bPipeWeight IsPsLineWeight() // 是否管线加粗 #define g_bRadiatorWeight IsPsRadiatorWeight() // 是否散热器加粗 #define g_bFloorPipeWeight IsPsFloorPipeWeight() // 是否地热盘管加粗 mcl add 2010.11.23 #define g_bBreakPipe IsPsBreakPipe() // 是否加粗 #define g_bSPipeFDir IsPsShowPipeFlowDir() // 显示管线流向 #define g_nPipeOsnap GetPSPipeOsnap() // 管段捕捉 #define g_dPipeTextDis GetPsPipeTextDis() // 管线文字边距 #define g_dBreakWidth GetPsBreakWidth() // 单线管线遮挡打断宽度 #define g_bEqByScale IsPsEqByScale() // 上华设备及阀门绘图比例是否随出图比例 #define g_nElbowType GetElbowType() // 双线弯头样式 extern AcGeVector3d GetUcsZvt(); // mcl add 2010.11.18. 获取UcsZ坐标 // sg add #define g_nSplitNum 40 // 圆离散成多边型的边数,要求为4的整数倍 // cet 2017.9.27 del 废弃代码 // PS_IMPEXP BOOL IsPsSystemShow(TPipeSys::SysType sysType, AcDbDatabase *pDb);//查询管线系统的显示属性 // PS_IMPEXP void PsShowSystem(TPipeSys::SysType sysType,BOOL bFlag, AcDbDatabase *pDb);//设置管线系统的显示属性 // 实体是否可见(决定因素:实体本身是否可见,所在图层是否锁定或关闭) PS_IMPEXP bool IsVisibleEntity(const AcDbEntity *pEnt); PS_IMPEXP bool IsVisibleEntity(const AcDbObjectId &idEnt); // cet 2017.12.27 add 判断点相同时的误差值 PS_IMPEXP double EqualPointTol(); #define CMD_UNKNOWN 0 #define CMD_UPDATE 1 #define CMD_ATTACHCHANGE 2 extern int g_nCmdReactor;//命令状态 extern TARCH_IMPEXP int g_nProductId; PS_IMPEXP BOOL GetInsertExtend(const AcDbObjectId &id,double &dWid,double &dHei); PS_IMPEXP BOOL GetInsertExtend(const AcDbObjectId &id,double &x,double &y,double &z); PS_IMPEXP BOOL GetBlkNameById(AcDbObjectId id,CString &sBlkName,CString &sDesName); PS_IMPEXP BOOL GetPipeMaterial(XStringList &lstMaterial); // 获取水管材料 PS_IMPEXP double GetPipeOutDByDn(int nMaterial, double dDn); // 得到外径 // double GetPipeDjByDn(const TCHAR* szMat, int iDnIn); // CString GetPipeMaterialByIdx(int idx); // sg add PS_IMPEXP BOOL GetDuctMaterial(XStringList &lstMaterial); // 获取风管材料 /*============================================================================* * 类 名: XExtent * 功能描述: 外包矩形 ==============================================================================*/ class PS_IMPEXP XExtent { public: double dLen,dWid;//长(x)、宽(y) public: XExtent(Entity &); XExtent(const AcDbEntity *); XExtent(const AcDbObjectId &); XExtent():dLen(0),dWid(0) {} XExtent(double l,double w) { dLen = l; dWid = w; } XExtent(const XExtent &ex) { dLen = ex.dLen; dWid = ex.dWid; } BOOL operator == (const XExtent& ex) const { return (fabs(dLen-ex.dLen)<_distSnap && fabs(dWid-ex.dWid)<_distSnap); } BOOL operator != (const XExtent& ex) const { return !((*this)==ex); } void operator += (const XExtent& ex) { dLen+=ex.dLen; dWid+=ex.dWid;} void operator -= (const XExtent& ex) { dLen-=ex.dLen; dWid-=ex.dWid;} void operator *= (double dScale) { dLen *= dScale; dWid *= dScale;} void operator /= (double dScale) { dLen /= dScale; dWid /= dScale;} operator XPoint () const { return XPoint(dLen,dWid,0);} #ifdef ACRXAPP operator const AcGeVector2d& () const { return *(const AcGeVector2d *)this; } operator AcGeVector2d& () const { return *(AcGeVector2d *)this; } operator AcGeVector2d () const { return AcGeVector2d(dLen,dWid); } #endif friend PS_IMPEXP XExtent operator + (const XExtent &, const XExtent &); friend PS_IMPEXP XExtent operator - (const XExtent &, const XExtent &); }; inline XExtent operator + (const XExtent& ex1,const XExtent& ex2) { return XExtent(ex1.dLen+ex2.dLen, ex1.dWid+ex2.dWid); } inline XExtent operator - (const XExtent& ex1,const XExtent& ex2) { return XExtent(ex1.dLen-ex2.dLen, ex1.dWid-ex2.dWid); } // 比较两个id是否相等 //inline int CompareObjectId_New(const AcDbObjectId *id1,const void *id2) //{ // if(*id1 == *(const AcDbObjectId *)id2) // return 0; // return 1; //} // 比较两个id是否相等 //inline int CompareObjectId_New(const AcDbSoftPointerId *id1, const void *id2) //{ // if(*id1 == *(const AcDbSoftPointerId *)id2) // return 0; // return 1; //} inline BOOL GreatEqual2d(const XPoint &pt1,const XPoint &pt2,double nSnap=_distSnap) { return (GreatEqual(pt1.x, pt2.x, nSnap) && GreatEqual(pt1.y, pt2.y, nSnap)); } inline BOOL LessEqual2d(const XPoint &pt1,const XPoint &pt2,double nSnap=_distSnap) { return (LessEqual(pt1.x, pt2.x, nSnap) && LessEqual(pt1.y, pt2.y, nSnap)); } inline BOOL GreatEqual3d(const XPoint &pt1,const XPoint &pt2,double nSnap=_distSnap) { return (GreatEqual(pt1.x, pt2.x, nSnap) && GreatEqual(pt1.y, pt2.y, nSnap) && GreatEqual(pt1.z, pt2.z, nSnap)); } inline BOOL LessEqual3d(const XPoint &pt1,const XPoint &pt2,double nSnap=_distSnap) { return (LessEqual(pt1.x, pt2.x, nSnap) && LessEqual(pt1.y, pt2.y, nSnap) && LessEqual(pt1.z, pt2.z, nSnap)); } inline BOOL ExtendInBox2d(const XPoint &ptMin,const XPoint &ptMax,const XRectAngle &box) { return (ptMin.x>box.lowLeft.x && ptMin.y>box.lowLeft.y && ptMax.xptMax.x || box.lowLeft.y>ptMax.y); } inline BOOL PointInBox02d(const XPoint &pt,const XRectAngle &box) { return(pt.x>=box.lowLeft.x && pt.x<=box.upRight.x && pt.y>=box.lowLeft.y && pt.y<=box.upRight.y); } inline void ScaleTransform(const AcGeMatrix3d& xform,double &dVar) { double dScale=xform.scale(); if(fabs(dScale-1)>1.0E-3 && fabs(dScale)>1.0E-3) dVar *= dScale; } inline void AngleTransform(const AcGeMatrix3d& xform,double &dAngle) { XVector3D vt(cos(dAngle),sin(dAngle),0); ((AcGeVector3d &)vt).transformBy(xform); dAngle=ads_angle(XPoint(),vt); //dAngle=CT_std_angle(dAngle); } inline Acad::ErrorStatus ReadAcDbSoftPointerIds( AcDbDwgFiler* pFiler,DList &lstId) { Adesk::UInt8 nCount=0; pFiler->readItem(&nCount); for(Adesk::UInt8 i=0; ireadItem(&id); lstId.Append(new AcDbSoftPointerId(id)); } return pFiler->filerStatus(); } inline Acad::ErrorStatus ReadPoints(AcDbDwgFiler* pFiler,DList &lstPoint) { Adesk::UInt8 nCount=0; pFiler->readItem(&nCount); for(Adesk::UInt8 i=0; ireadItem(&pt); lstPoint.Append(new XPoint(pt)); } return pFiler->filerStatus(); } inline Acad::ErrorStatus WriteAcDbSoftPointerIds( AcDbDwgFiler* pFiler,const DList &lstId) { Adesk::UInt8 nCount=(Adesk::UInt8)lstId.Length(); pFiler->writeItem(nCount); for(Adesk::UInt8 i=0; iwriteItem(lstId[i]); return pFiler->filerStatus(); } inline Acad::ErrorStatus WritePoints(AcDbDwgFiler* pFiler,const DList &lstPoint) { Adesk::UInt8 nCount=(Adesk::UInt8)lstPoint.Length(); pFiler->writeItem(nCount); for(Adesk::UInt8 i=0; iwriteItem((const AcGePoint3d &)lstPoint[i]); return pFiler->filerStatus(); } inline BOOL IsTransformCmd() { if(!GetCurDocData()) return FALSE; XString &sCmd=GetCurDocData()->m_sCurCommand; return(_tcsicmp(sCmd,_T("MOVE"))==0 || _tcsicmp(sCmd,_T("COPY"))==0 || _tcsicmp(sCmd,_T("ROTATE"))==0 || _tcsicmp(sCmd,_T("MIRROR"))==0 ); } inline BOOL IsKeyDown(int nVirtKey) // VK_CONTROL、... { SHORT sState=GetKeyState(nVirtKey); return (sState&256)!=0; } inline CString DoubleToString(double dValue, int nPreci, bool bTrim = false) { CString csRet; CString csFormat; csFormat.Format(_T("%%.%df"), nPreci); csRet.Format(csFormat, dValue); // 带小数点,删除末尾的0以及小数点(如2.10=》2.1或2.00=》2) cet 2018.1.12 add if (bTrim && csRet.Find(_T('.')) > -1) { csRet.TrimRight(_T("0")); csRet.TrimRight(_T(".")); } return csRet; } #endif