// Copyright (C), 1998-2007, Beijing Tangent Engineering Software Co. Ltd. // = FileName: commonRoad.h // = Version: 8.5 // = Author: lgh // = Date: 2010-10-26 11:07:20 // = Description: 道路公用函数 // = Maintainers: #ifndef __TCH_SITEPLAN_COMMONROAD_H__ #define __TCH_SITEPLAN_COMMONROAD_H__ class CLineInterStruct; class CArcInterStruct; class CInterStruct; typedef AcArray AcAryLineInterStruct; typedef AcArray AcAryArcInterStruct; typedef AcArray AcAryInterStructPointer; #define POINT_2D_TO_3D(point) (AcGePoint3d((point).x, (point).y, 0.0)) #define POINT_3D_TO_2D(point) (AcGePoint2d((point).x, (point).y)) namespace TRoadCommon { // 显示的指定内存分配器,以使平台之间兼容。 typedef AcArray > AcAryLineSeg2d; typedef AcArray > AcAryCircArc2d; // 描述两个向量的方向的关系。相同,相反,垂直 enum EVecDirection {eSameDir, eOppDir, ePerpDir}; enum ERoadInterRet {eIntersect = 0, eNotIntersect, eOverlay, eOverlayed}; enum EFilletStyle{eSameCenter = 0, eSameRadius}; // 在垂直方向上,一个点相对于一个道路的位置,从左到右依次为:左部,左边线上,道路内,右边线上,右部 enum EPointAtRoadPerp {eRoadLeftSide = 0, eRoadLeftEdge, eInRoad, eRoadRightEdge, eRoadRightSide}; inline bool InRoadPerp(EPointAtRoadPerp ep){ return (ep == eRoadLeftEdge) || (ep == eRoadRightEdge) || (ep == eInRoad);} inline bool InRoadEdgePerp(EPointAtRoadPerp ep) {return (ep == eRoadLeftEdge) || (ep == eRoadRightEdge);} // 水平方向上,交点跟当前道路的关系,起点外,路内,终点外 // 从起点到终点依次为:起点外,路上,终点外。 enum EPointAtRoadInDir {eRoadStartOut, eInEdge, eRoadEndOut}; // 点跟线(包括弧线)的关系(有长度的线)依次为: enum EPointToLine{ eLeft, // 线左侧 eOnLine, // 线上 eRight, // 线右侧 eStartOut, // 起点外 eStartPoint, // 起点处 eEndOut, // 终点外 eEndPoint // 终点处 }; template void ClearAcaryAll(TAcAryPtrs &arry) { while (!arry.isEmpty()) arry.removeFirst(); } template void ClearAndDeleteAry(TAcAryPtrs &arry) { for (int i = 0; i < (int)arry.length(); i++) { delete arry[i]; } ClearAcaryAll(arry); } template inline void SWAP(T &a, T&b) { T c = a; a = b; b = c; } template inline T MAX(const T &a, const T&b) { return a > b ? a : b; } template inline T MIN(const T &a, const T&b) { return a < b ? a : b; } // 判断是否是偶数。 inline bool EvenNum(int num) {return (num & 0x1) == 0;} inline bool DoubleEqual(double d1, double d2, double dTol = 1e-6) { return (fabs(d1 - d2) < dTol); } inline AcGeLine2d ToLine(const AcGeLineSeg2d &lineSeg) {return AcGeLine2d(lineSeg.startPoint(), lineSeg.endPoint());} inline AcGeCircArc2d ToCircle(const AcGeCircArc2d &arc) {return AcGeCircArc2d(arc.center(), arc.radius());} // 点相对于线段的关系,左侧,右侧,线段(所在的直线)上, EPointToLine PointToLineSegPerp(const AcGeLineSeg2d &lineseg, const AcGePoint2d &point, double dTol = 1.0); EPointToLine PointToArcPerp(const AcGeCircArc2d &arc, const AcGePoint2d &point, double dTol = 1.0); EPointToLine PointToLineSegDir(const AcGeLineSeg2d &lineseg, const AcGePoint2d &point, double dTol = 1.0); EPointToLine PointToArcDir(const AcGeCircArc2d &arc, const AcGePoint2d &point, double dTol = 1.0); // GeArc是MM单位,DbArc是系统单位 AcDbArc& GeArcToDbSys(const AcGeCircArc2d &arc, AcDbArc &dbArc); AcDbArc* GeArcToDbSys(const AcGeCircArc2d &arc); AcGeCircArc2d DbArcToGeMM(const AcDbArc &dbArc); AcDbLine* GeLineToDbLineSys(const AcGeLineSeg2d &lineSeg); AcGeLineSeg2d DbLineToGeLineMM(const AcDbLine &dbLine); enum EEntType {eRoadEdgeType = 0, eRoadMidType}; void SetLayer(AcDbEntity *pEnt, EEntType entType); //AcGeCircArc2d ConArc(const AcGePoint2d ¢er, const AcGePoint2d &ptStart, const AcGePoint2d &ptEnd); AcGeCircArc2d OutSideArc(const AcGeCircArc2d &arcTem, double dHalfWid); AcGeCircArc2d InSideArc(const AcGeCircArc2d &arcTem, double dHalfWid); AcGeLineSeg2d LeftLine(const AcGeLineSeg2d &lineseg, double dDis); AcGeLineSeg2d RightLine(const AcGeLineSeg2d &lineseg, double dDis); AcGeCircArc2d LeftArc(const AcGeCircArc2d &arc, double dDis); AcGeCircArc2d RightArc(const AcGeCircArc2d &arc, double dDis); // ptStart, ptEnd仅仅用来控制生成圆弧的角度,不改变圆弧的半径和圆形。所以他们可以不再该弧上 AcGeCircArc2d ConNewArc(const AcGeCircArc2d &arcTemplate, const AcGePoint2d &ptStart, const AcGePoint2d &ptEnd); AcGeCircArc2d ConNewArc(const AcGeCircArc2d &arcTemplate, double dRadius); AcGeVector2d TanVecOfArcStartPoint(const AcGeCircArc2d &arc); AcGeVector2d TanVecOfArcEndPoint(const AcGeCircArc2d &arc); double NormalAngle(double dAngle); double AngleInClock(bool bClockwise, double angle1, double angle2); // 从Vec1 到 Vec2的角度,按照bClock的方向 double AngleOfVec(const AcGeVector2d &vec1, const AcGeVector2d &vec2, bool bClock); // 取得圆弧的中点 AcGePoint2d MidPointOfArc(const AcGeCircArc2d &arc); AcGePoint2d AntiMidPointOfArc(const AcGeCircArc2d &arc); // clock的方向上添加角度 inline double AddAngleInClock(bool bClockWise, double dAngle, double dAdd) { return NormalAngle(dAngle + (bClockWise ? -dAdd : dAdd)); } // 反方向的角度 inline double AntiAngle(double dAngle) { return NormalAngle(dAngle + PI); } // 向量vec的方向上,对pt1和pt2排序 // ret:-1:pt1 < pt2; 0: pt == pt2;1: pt1 > pt2。 int PointSequence(const AcGeVector2d &vec, const AcGePoint2d &pt1, const AcGePoint2d &pt2, double dTol = 1e-6); // 圆弧arc的方向上(顺时针,逆时针)对pt1和pt2进行排序. // 备注:排序的起点是arc另一侧圆弧的中点,方向是按照圆弧的时针方向 // ret:-1:pt1 < pt2; 0: pt == pt2;1: pt1 > pt2。 int PointSequence(const AcGeCircArc2d &arc, const AcGePoint2d &pt1, const AcGePoint2d &pt2, double dTol = 1e-6); // 向一端延长直线,延伸长度 == dExtend AcGeLineSeg2d ExtendLine(const AcGeLineSeg2d &lineseg, bool bStart, double dExtend); // 向一端延长弧线,延伸部分不会超过本半圆。延伸长度 = dExtendLen AcGeCircArc2d ExtendArc(const AcGeCircArc2d &arc, bool bStart, double dExtendLen); // 两端延伸线段,延伸长度分别为:dExtendStart, dExtendEnd; AcGeLineSeg2d ExtendLine(const AcGeLineSeg2d &lineseg, double dExtendStart, double dExtendEnd); // 两端延伸圆弧,延伸长度分别为:dExtendStart, dExntedEnd;两端的延伸长度皆不超过半圆弧 AcGeCircArc2d ExtendArc(const AcGeCircArc2d &arc, double dExtendStart, double dExtendEnd); void ResetLine(AcGeLineSeg2d &line, bool bStart, const AcGePoint2d &ptAccurate); void ResetArc(AcGeCircArc2d &arc, bool bStart, const AcGePoint2d &ptAccurate); double LenOfArc(const AcGeCircArc2d &arc); BOOL SameAngle(double dAngle1, double dAngle2, double dAngleTol); template inline AcGePoint2d ChosePoint(const TGeCurve &curve, BOOL bStart) { return bStart ? curve.startPoint() : curve.endPoint(); } inline AcGePoint2d AsSysUnitPoint2d(const AcGePoint2d &pt) { return AcGePoint2d(_AS_SYS_UNIT(pt.x), _AS_SYS_UNIT(pt.y)); } inline AcGePoint2d AsMMUnitPoint2d(const AcGePoint2d &pt) { return AcGePoint2d(_AS_MM(pt.x), _AS_MM(pt.y)); } inline AcGePoint3d AsSysUnitPoint3d(const AcGePoint3d &pt) { return AcGePoint3d(_AS_SYS_UNIT(pt.x), _AS_SYS_UNIT(pt.y), _AS_SYS_UNIT(pt.z)); } inline AcGePoint3d AsMMUnitPoint3d(const AcGePoint3d &pt) { return AcGePoint3d(_AS_MM(pt.x), _AS_MM(pt.y), _AS_MM(pt.z)); } // 多选,每选择一次,函数退出。 // csPrompt:提示信息 // ssResult:结果选择集 // rbBaseMask:过滤列表 // szKeyword:关键字列表(单个关键字,不区分大小写,无须空格) // chRet:所选择的关键字 // ret:空格,回车,右键:RTNONE; // ret:关键字:RTKWORD; // ret:正常选择:RTNORMAL; // ret:ESC:RTCAN; // ret:所选实体无亮显,用户可在每次选择之后自己控制亮显。 int SelectEntitiesOnce(CString csPrompt,PickSet &ssResult, TRBList &rbBaseMask,const TCHAR* szKeyword, TCHAR &chRet); // 测试类 class MyArc { public: MyArc (const AcGeCircArc2d &arc) { Set(arc); } void Set(const AcGeCircArc2d &arc) { ptStart = arc.startPoint(); ptEnd = arc.endPoint(); ptCenter = arc.center(); dRaidus = arc.radius(); bColck = arc.isClockWise(); } AcGePoint2d ptStart; AcGePoint2d ptEnd; AcGePoint2d ptCenter; double dRaidus; Adesk::Boolean bColck; }; class MyLineSeg { public: MyLineSeg(const AcGeLineSeg2d &line) { ptStart = line.startPoint(); ptEnd = line.endPoint(); dLen = line.length(); } AcGePoint2d ptStart; AcGePoint2d ptEnd; double dLen; }; } using namespace TRoadCommon; #endif