#include "stdafx.h" #include "LandScapeDataCenterNew.h" #include #include #include "RoolBackNew.h" #include "GlwGlobalVariable.h" CLandScapeDataCenterNew::CLandScapeDataCenterNew(void) { } CLandScapeDataCenterNew::~CLandScapeDataCenterNew(void) { } void CLandScapeDataCenterNew::AddLineRoad(const CLineRoad &lineRoad) { CDataRoolBack::AddNewStep(); // 从CAD中大致选择实体 ROAD_EDGE_STRUCT res; ROAD_MID_STRUCT rms; AcGePoint2d ptLeftDown, ptRightUp; lineRoad.ToRegionSys(ptLeftDown, ptRightUp); SelectEntInCAD(ptLeftDown, ptRightUp, res.lineEdges, res.arcEdges, rms.lineMids, rms.arcMids); // CAD中的实体被处理为这些携带相关信息的结构。 // 处理成道路结构体 DealLeftAndRightEnt(lineRoad, rms, res); // 对左边的,和右边的arInterStruct分别执行合并 SortInterStructs(lineRoad.LeftLine(), true, res.leftIntersAll); SortInterStructs(lineRoad.RightLine(), true, res.rightIntersAll); // 将细小的线段删除。防止引起错误。(刚刚处理完毕之后就进行该项操作。) RemoveShortInterStruct(res, lineRoad.TolLen()); ReTestInterStruct(res, &(lineRoad), lineRoad.TolLen()); InterStuctRealIn(res.leftIntersAll, res.leftIntersIn); InterStuctRealIn(res.rightIntersAll, res.rightIntersIn); // 过滤模式,--在计算所有的interStruct之后,道路边线的裁剪规则(哪一段应该删除,哪一段应该显示) CFilterMode leftFilter, rightFilter; leftFilter = FindFilterMode(lineRoad.LeftLine(), true, res.leftIntersIn); rightFilter = FindFilterMode(lineRoad.RightLine(), true, res.rightIntersIn); CLineLandScapeEdgeCreater lineEdgeCreater(&lineRoad, res.leftIntersAll, res.rightIntersAll, res.leftIntersIn, res.rightIntersIn, rms.leftInterMid, rms.rightInterMid, leftFilter, rightFilter); lineEdgeCreater.MakeCorner(); lineEdgeCreater.MakeRoad(); CLandScapeStyle* pLandScape = GET_GLOBAL_VARIABLE(CLandScapeStyle); pLandScape->ssAll.IncludeEnd(); m_arrGroupId.append(pLandScape->MakeUnnamedGroup()); pLandScape->ssAll.Free(); CreateRoadEdgeStruct(res); Clear(res, rms); } void CLandScapeDataCenterNew::AddArcRoad(const CArcRoad &arcRoad) { CDataRoolBack::AddNewStep(); // 从CAD中大致选择实体 ROAD_MID_STRUCT rms; ROAD_EDGE_STRUCT res; AcGePoint2d ptLeftDown, ptRightUp; arcRoad.ToRegionSys(ptLeftDown, ptRightUp); SelectEntInCAD(ptLeftDown, ptRightUp, res.lineEdges, res.arcEdges, rms.lineMids, rms.arcMids); // CAD中的实体被处理为这些携带相关信息的结构。 // 处理成道路结构体 DealLeftAndRightEnt(arcRoad, rms, res); // 对左边的,和右边的arInterStruct分别执行合并 SortInterStructs(arcRoad.LeftArc(), true, res.leftIntersAll); SortInterStructs(arcRoad.RightArc(), true, res.rightIntersAll); // 将细小的线段删除。防止引起错误。(刚刚处理完毕之后就进行该项操作。) RemoveShortInterStruct(res, arcRoad.TolLen()); ReTestInterStruct(res, &(arcRoad), arcRoad.TolLen(), arcRoad.MidArc().isClockWise() == Adesk::kTrue ? true : false); InterStuctRealIn(res.leftIntersAll, res.leftIntersIn); InterStuctRealIn(res.rightIntersAll, res.rightIntersIn); // 过滤模式,--在计算所有的interStruct之后,道路边线的裁剪规则(哪一段应该删除,哪一段应该显示) CFilterMode leftFilter, rightFilter; leftFilter = FindFilterMode(arcRoad.LeftArc(), true, res.leftIntersIn); rightFilter = FindFilterMode(arcRoad.RightArc(), true, res.rightIntersIn); CArcLandScapeEdgeCreater arcEdgeCreater(&arcRoad, res.leftIntersAll, res.rightIntersAll, res.leftIntersIn, res.rightIntersIn, rms.leftInterMid, rms.rightInterMid,leftFilter, rightFilter); arcEdgeCreater.MakeCorner(); arcEdgeCreater.MakeRoad(); CLandScapeStyle* pLandScape = GET_GLOBAL_VARIABLE(CLandScapeStyle); pLandScape->ssAll.IncludeEnd(); m_arrGroupId.append(pLandScape->MakeUnnamedGroup()); pLandScape->ssAll.Free(); CreateRoadEdgeStruct(res); Clear(res, rms); } //选择实体 void CLandScapeDataCenterNew::SelectEntInCAD(const AcGePoint2d &ptLeftDown, const AcGePoint2d &ptRightUp, AcAryLineEntEdgeAdapterPtr &lineEdges, AcAryArcEntEdgeAdapterPtr &arcEdges, AcAryLineEntEdgeAdapterPtr &lineMids, AcAryArcEntEdgeAdapterPtr &arcMids) { //add tyj 20161021:解决在UCS坐标系下,绘制景观路无法正常倒角 /*-----------------begin-------------------*/ TADSGePoint3d ptSave1(ptLeftDown.x, ptLeftDown.y, 0.0); TADSGePoint3d ptSave2(ptRightUp.x, ptRightUp.y, 0.0); ptSave1 = Wcs2Ucs(ptSave1); ptSave2 = Wcs2Ucs(ptSave2); ads_point pt1 = {ptSave1.x, ptSave1.y, 0.0}; ads_point pt2 = {ptSave2.x, ptSave2.y, 0.0}; //ads_point pt1 = {ptLeftDown.x, ptLeftDown.y, 0.0}; //ads_point pt2 = {ptRightUp.x, ptRightUp.y, 0.0}; /*------------------end--------------------*/ CString strRoadLay(LAY_LSCP_ROAD); CString strMidRoadLay = LAY_ROADDOTE; ads_name ssName; // 差选! acedSSGet(_T("C"), pt1, pt2, NULL, ssName); Adesk::Int32 len = 0; acedSSLength(ssName, &len); ads_name ent; AcDbObjectId id; CStringList arrgrpNames; AcDbVoidPtrArray arrLinePtrs; AcDbVoidPtrArray arrArcPtrs; for (long i = 0; i < len; i++) { if (acedSSName(ssName, i, ent) == RTNORM) { if (acdbGetObjectId(id, ent) == Acad::eOk) { AcDbObjectPointer pEnt; if (pEnt.open(id, AcDb::kForRead) == Acad::eOk) { TCHAR* lay = pEnt->layer(); if (strRoadLay.CompareNoCase(pEnt->layer()) == 0) { if (pEnt->isKindOf(AcDbBlockReference::desc())) { AcDbObjectIdArray arrGroupId; const AcDbVoidPtrArray *pReactors; pReactors = pEnt->reactors(); if (pReactors == NULL) { pEnt->close(); continue; } pEnt->close(); void *pSomething; int length = pReactors->length(); for (int nReact = 0; nReact < length; ++nReact) { pSomething = (AcDbObject*) pReactors->at(nReact); if (acdbIsPersistentReactor(pSomething)) { AcDbObjectId persObjId = acdbPersistentReactorObjectId(pSomething); AcDbObject *pReactor; if (Acad::eOk != acdbOpenObject(pReactor, persObjId, AcDb::kForRead)) { continue; } pReactor->close(); if (pReactor->isKindOf(AcDbGroup::desc())) { ACHAR *pName(NULL); OPENOBJ_BEGIN(persObjId, AcDb::kForRead, AcDbGroup, pGroup) if (pGroup) { pGroup->getName(pName); } OPENOBJ_END() if (!arrgrpNames.Find(pName)) { arrgrpNames.AddHead(pName); arrGroupId.append(persObjId); } } } } for (int nNum = 0; nNum < arrGroupId.length(); ++nNum) { AcDbObjectIdArray idEnts; OPENOBJ_BEGIN(arrGroupId.at(nNum), AcDb::kForRead, AcDbGroup, pGroup) if (pGroup) { pGroup->allEntityIds(idEnts); } OPENOBJ_END() for(int nEnt=0; nEntvisibility(); if (pBorderEnt->isKindOf(AcDbArc::desc())) { for (int nPt = 0; nPt < arrArcPtrs.length(); ++nPt) { AcDbEntity* pTempEnt = (AcDbEntity*)arrArcPtrs.at(nPt); if (pTempEnt->isEqualTo(pBorderEnt)) { break; } } if (nPt >= arrArcPtrs.length()) { CArcCADEntEdgeAdapter* pEdge = new CArcCADEntEdgeAdapter(idEnts.at(nEnt)); pEdge->SetGroupId(arrGroupId.at(nNum)); pEdge->SetIsVisible(bIsvisible); arcEdges.append(pEdge); arrArcPtrs.append(pBorderEnt); } } else if(pBorderEnt->isKindOf(AcDbLine::desc())) { for (int nPt = 0; nPt < arrLinePtrs.length(); ++nPt) { AcDbEntity* pTempEnt = (AcDbEntity*)arrLinePtrs.at(nPt); if (pTempEnt->isEqualTo(pBorderEnt)) { break; } } if (nPt >= arrLinePtrs.length()) { CLineCADEntEdgeAdapter* pEdge = new CLineCADEntEdgeAdapter(idEnts.at(nEnt)); pEdge->SetGroupId(arrGroupId.at(nNum)); pEdge->SetIsVisible(bIsvisible); lineEdges.append(pEdge); arrLinePtrs.append(pBorderEnt); } } pBorderEnt->close(); } } idEnts.removeAll(); } arrGroupId.removeAll(); } else { pEnt->close(); continue; } } else { pEnt->close(); continue; } } } } } ads_ssfree(ssName); arrgrpNames.RemoveAll(); arrArcPtrs.removeAll(); arrLinePtrs.removeAll(); } void CLandScapeDataCenterNew::CreateRoadEdgeStruct(ROAD_EDGE_STRUCT &res) { int index = 0, ilen = (int)res.lineEdges.length(); for (index = 0; index < ilen; index++) res.lineEdges[index]->ReCreateForLandScape(); ilen = (int)res.arcEdges.length(); for (index = 0; index < ilen; index++) res.arcEdges[index]->ReCreateForLandScape(); } void CLandScapeDataCenterNew::RoolBack() { CDataRoolBack::RoolAStep(); AcDbObjectId groupId = m_arrGroupId.last(); AcDbObjectPointer pObj; AcDbObjectIdArray idEnts; OPENOBJ_BEGIN(groupId, AcDb::kForWrite, AcDbGroup, pGroup) if (pGroup) { pGroup->allEntityIds(idEnts); for(int nEnt=0; nEnterase(true); pBorderEnt->close(); } } idEnts.removeAll(); m_arrGroupId.removeLast(); pGroup->erase(true); // 删除 } OPENOBJ_END() } ////////////////////////////////////////////////////////////////////////// // TDbArcLandScapeEntity ACRX_DXF_DEFINE_MEMBERS(TDbArcLandScapeEntity, TDbArcRoadEntity, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 1, ATS_ARCLANDSCAPEENTITY, "ATS_ARCLANDSCAPEENTITY, 请下载上华软件|网址: www.shanghuasoft.com"); IMPLEMENT_TENTBASE(TDbArcLandScapeEntity); CArcRoad* TDbArcLandScapeEntity::CreateArcRoad(CLandScapeStyle *pLandStyle) { CArcRoad *pArcRoad = new CArcRoad(0.5 * _AS_MM(pLandStyle->GetRoadWidth()), 0.5 * _AS_MM(pLandStyle->GetRoadWidth()), 0, 0, 0,eSameCenter, AcGeCircArc2d(AsMMUnitPoint2d(GetFirstPt()), AsMMUnitPoint2d(GetThirdPt()), AsMMUnitPoint2d(GetEndPt()))); return pArcRoad; } void TDbArcLandScapeEntity::SetArcRoad(const AcGePoint2d &ptFir, const AcGePoint2d &ptThir, const AcGePoint2d &ptEnd, CLandScapeStyle *pLandStyle) { double dHalfWid = 0.5 * pLandStyle->GetRoadWidth(); double dOffSet = 0.0; //AcGeCircArc2d arc(ptFir, ptThir, ptEnd); //// 一个圆弧拆成两个圆弧,然后分别作偏移。 //AcGeCircArc2d arc1 = ConNewArc(arc, ptFir, ptThir); //AcGeCircArc2d arc2 = ConNewArc(arc, ptThir, ptEnd); //arc1 = LeftArc(arc1, dOffSet); //arc2 = LeftArc(arc2, dOffSet); SetMidArc(ptFir, ptThir, ptEnd); SetHalfWid(dHalfWid); } ////////////////////////////////////////////////////////////////////////// // TDbLineLandScapeEntity ACRX_DXF_DEFINE_MEMBERS(TDbLineLandScapeEntity, TDbLineRoadEntity, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 1, ATS_LINELANDSCAPEENTITY, "ATS_ARCROAD缺乏解释器图形看不见, 请下载上华软件|网址: www.shanghuasoft.com"); IMPLEMENT_TENTBASE(TDbLineLandScapeEntity); CLineRoad* TDbLineLandScapeEntity::CreateLineRoad(CLandScapeStyle *pLandStyle) { CLineRoad *pLineRoad = new CLineRoad(0.5 * _AS_MM(pLandStyle->GetRoadWidth()), 0.5 * _AS_MM(pLandStyle->GetRoadWidth()), 0, 0, 0,eSameCenter, AcGeLineSeg2d(AsMMUnitPoint2d(GetStartPt()), AsMMUnitPoint2d(GetEndPt()))); return pLineRoad; } void TDbLineLandScapeEntity::SetLineRoad(const AcGePoint2d &ptStart, const AcGePoint2d &ptEnd, CLandScapeStyle *pLandStyle) { double dHalfWid = 0.5 * pLandStyle->GetRoadWidth(); double dOffSet = 0.0; AcGeLineSeg2d lineseg(ptStart, ptEnd); lineseg = LeftLine(lineseg, dOffSet); SetMidLine(lineseg); SetHalfWid(dHalfWid); } CLineLandScapeEdgeCreater::CLineLandScapeEdgeCreater(const CRoad *pRoad, AcAryInterStructPointer &leftInterStruct, AcAryInterStructPointer &rightInterStruct, AcAryInterStructPointer &leftInterStructin, AcAryInterStructPointer &rightInterStructin, AcAryInterStructPointer &leftInterStructMid, AcAryInterStructPointer &rightInterStructMid, CFilterMode &leftFilterMode, CFilterMode &rightFiltMode) :CLineRoadEdgeCreater(pRoad, leftInterStruct, rightInterStruct, leftInterStructin, rightInterStructin, leftInterStructMid, rightInterStructMid, leftFilterMode, rightFiltMode) { } CArcLandScapeEdgeCreater::CArcLandScapeEdgeCreater(const CRoad *pRoad, AcAryInterStructPointer &leftInterStruct, AcAryInterStructPointer &rightInterStruct, AcAryInterStructPointer &leftInterStructin, AcAryInterStructPointer &rightInterStructin, AcAryInterStructPointer &leftInterStructMid, AcAryInterStructPointer &rightInterStructMid, CFilterMode &leftFilterMode, CFilterMode &rightFiltMode) : CArcRoadEdgeCreater(pRoad, leftInterStruct, rightInterStruct, leftInterStructin, rightInterStructin, leftInterStructMid, rightInterStructMid,leftFilterMode, rightFiltMode) { } void CArcLandScapeEdgeCreater::DrawRoadEdge() { CLandScapeStyle* pLandScape = GET_GLOBAL_VARIABLE(CLandScapeStyle); m_edgeAry.append(m_leftedge); m_edgeAry.append(m_rightEdge); AcDbArc *pArc = new AcDbArc(); GeArcToDbSys(m_midEdge, *pArc); TADSGePoint3d ptCen; TGGeCurveSegment xCurve; (AcGePoint3d &)ptCen = pArc->center(); XArc* pxArc = new XArc(ptCen, pArc->radius(), pArc->startAngle(), pArc->endAngle()); xCurve = *pxArc; for (int i = 0; i < (int)m_edgeAry.length(); i++) { std::vector vecPtAndAngle;//点和角度 const AcGeCircArc2d &arc = m_edgeAry[i]; double dangle(0.0); AcGePoint3d ptArcSt; AcDbArc *pArcedge = new AcDbArc(); GeArcToDbSys(arc, *pArcedge); pArcedge->getStartPoint(ptArcSt); if(xCurve.OnWhichSide(ptArcSt)) { TADSGePoint3d ptCen; TGGeCurveSegment xCurve; (AcGePoint3d &)ptCen = pArcedge->center(); XArc pedgeXArc(ptCen, pArcedge->radius(), pArcedge->startAngle(), pArcedge->endAngle()); pedgeXArc = pedgeXArc.Offset(-0.5 * pLandScape->GetRoadWidth()); // 调用圆弧类型,获得所有圆弧上的插入点,存放在Vector中 AcDbArc* pArcTemp = new AcDbArc(pedgeXArc.GetCenterPt().AsAcGePoint3d(), pedgeXArc.GetRadius(), pedgeXArc.GetStarAngle(), pedgeXArc.GetEndAngle()); pLandScape->ArcStyle(pArcTemp, pLandScape->GetGap(),dangle , pLandScape->GetIsAutoAdjust(), vecPtAndAngle); int iLen = vecPtAndAngle.size(); for (int n = 0; n < iLen; n++) { if (!pLandScape->MakeBlockReference(vecPtAndAngle[n].ptPoint, -vecPtAndAngle[n].dAngle)) // 造块 { return ; } } //delete pArcTemp; } AcDbObjectId idLayer = InitLayer(LAY_LSCP_ROAD); pArcedge->setLayer(idLayer); if (!pLandScape->GetIsDrawRoadLine()) { pArcedge->setVisibility(AcDb::kInvisible); } RoolBackAddNewData(pArcedge); } delete pxArc; } void CLineLandScapeEdgeCreater::DrawRoadEdge() { CLandScapeStyle* pLandScape = GET_GLOBAL_VARIABLE(CLandScapeStyle); m_edgeAry.append(m_leftedge); m_edgeAry.append(m_rightEdge); AcDbLine* pLineMid = GeLineToDbLineSys(m_midEdge); XLine* pXline = new XLine; pXline->SetStartPoint(pLineMid->startPoint()); pXline->SetEndPoint(pLineMid->endPoint()); for (int i = 0; i < (int)m_edgeAry.length(); i++) { const AcGeLineSeg2d &lineseg = m_edgeAry[i]; AcDbLine *pLine = GeLineToDbLineSys(lineseg); if(pXline->OnWhichSide(pLine->startPoint())) { XLine* pXlineTemp = new XLine; pXline->SetStartPoint(pLine->startPoint()); pXline->SetEndPoint(pLine->endPoint()); *pXline = pXline->Offset(-0.5 * pLandScape->GetRoadWidth()); AcDbLine* pLineTemp = new AcDbLine(pXline->GetStartPoint(), pXline->GetEndPoint()); std::vector vecPtAndAngle;//点和角度 // 调用直线类型,获得所有直线上的插入点,存放在vector中 pLandScape->LineStyle(pLineTemp, pLandScape->GetGap(), pLandScape->GetIsAutoAdjust(),vecPtAndAngle); // 将块插入到图纸中 int iLen = vecPtAndAngle.size(); for (int n = 0; n < iLen; n++) { if (!pLandScape->MakeBlockReference(vecPtAndAngle[n].ptPoint, -vecPtAndAngle[n].dAngle)) // 造块 { return ; } } delete pLineTemp; } AcDbObjectId idLayer = InitLayer(LAY_LSCP_ROAD); pLine->setLayer(idLayer); if (!pLandScape->GetIsDrawRoadLine()) { pLine->setVisibility(AcDb::kInvisible); } RoolBackAddNewData(pLine); } delete pXline; } void TDbLineLandScapeEntity::SetHalfWid(double dHalfWid) { assertWriteEnabled(); m_dHalfWid = dHalfWid; } void TDbArcLandScapeEntity::SetHalfWid(double dHalfWid) { assertWriteEnabled(); m_dHalfWid = dHalfWid; }