#include "stdafx.h" #include "AecDbX3dPart.h" #include "AcDbX3dSolid.h" #include "CoreTools.h" #include "KTSetting.h" #include "geometry2json.h" extern CString IDCreate(); extern double PixelToWcs(int nPixel); Adesk::UInt32 AecDbX3dPart::kCurrentVersionNumber = 1; static const Adesk::UInt16 kColorByBlock = 0; static const Adesk::UInt16 kRed = 1; static const Adesk::UInt16 kYellow = 2; static const Adesk::UInt16 kGreen = 3; static const Adesk::UInt16 kCyan = 4; static const Adesk::UInt16 kBlue = 5; static const Adesk::UInt16 kMagenta = 6; static const Adesk::UInt16 kWhite = 7; static const Adesk::UInt16 kColorByLayer = 256; static void FreeBuffer(int n,AcDbVoidPtrArray& arEntPtrs) { AcDbEntity* pEnt = NULL; while(arEntPtrs.length() > n ) { pEnt = (AcDbEntity*)arEntPtrs.last(); if (pEnt != NULL) { pEnt->erase(); pEnt->close(); arEntPtrs.removeLast(); DELETE_PTR(pEnt); } } } AecDbX3dPart::AecDbX3dPart(void) { m_vtMove.set(0,0,0); memset(m_dAxisRotats,0,sizeof(double) * MAX_AXISROTATS); for (int i = 0;i < MAX_AXISROTATS;i++) { m_arVtAxis.append(AcGeVector3d::kIdentity); } m_nBoolOper = 0; m_pSolidDraw = NULL; m_pSolid = NULL; m_sName = _T(""); m_sGUID = IDCreate(); m_bActive = false; m_nPeelOff = -1; m_ptActiveInf.x = -1; m_ptActiveInf.y = -1; } AecDbX3dPart::AecDbX3dPart(const AecDbX3dPart& pPart) { m_pSolidDraw = NULL; m_pSolid = NULL; m_sName = pPart.m_sName; m_sGUID = pPart.m_sGUID; m_nBoolOper = pPart.m_nBoolOper; // AcDbX3dSolid* pXSolid = NULL; AcDbX3dSolid* pXSolidNew = NULL; for (int i = 0;i < pPart.m_arX3DSolidPtrsUnite.length();i++) { pXSolid = (AcDbX3dSolid*)pPart.m_arX3DSolidPtrsUnite.at(i); pXSolidNew = new AcDbX3dSolid(*pXSolid); pXSolidNew->ReCreate(); m_arX3DSolidPtrsUnite.append(pXSolidNew); } for (int i = 0;i < pPart.m_arX3DSolidPtrsSubtr.length();i++) { pXSolid = (AcDbX3dSolid*)pPart.m_arX3DSolidPtrsSubtr.at(i); pXSolidNew = new AcDbX3dSolid(*pXSolid); pXSolidNew->ReCreate(); m_arX3DSolidPtrsSubtr.append(pXSolidNew); } for (int i = 0;i < pPart.m_arX3DSolidPtrsSubtrForHouse.length();i++) { pXSolid = (AcDbX3dSolid*)pPart.m_arX3DSolidPtrsSubtrForHouse.at(i); pXSolidNew = new AcDbX3dSolid(*pXSolid); pXSolidNew->ReCreate(); m_arX3DSolidPtrsSubtrForHouse.append(pXSolidNew); } //先旋转,后移动 m_vtMove = pPart.m_vtMove; //总移动 m_ptOrg = pPart.m_ptOrg; //原点 m_arVtAxis.append(pPart.m_arVtAxis); //轴向 memcpy(m_dAxisRotats,pPart.m_dAxisRotats,MAX_AXISROTATS * sizeof(double)); m_mapXData.CopyFrom(&pPart.m_mapXData); //显示,临时 m_ptActiveInf = pPart.m_ptActiveInf; m_bActive = pPart.m_bActive; m_nPeelOff = pPart.m_nPeelOff; } AecDbX3dPart::~AecDbX3dPart(void) { AcDbX3dSolid* pXSolid = NULL; for (int i = 0;i < m_arX3DSolidPtrsUnite.length();i++) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsUnite.at(i); DELETE_PTR(pXSolid); } for (int i = 0;i < m_arX3DSolidPtrsSubtr.length();i++) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsSubtr.at(i); DELETE_PTR(pXSolid); } if (m_pSolid != NULL) DELETE_PTR(m_pSolid); if (m_pSolidDraw != NULL) DELETE_PTR(m_pSolidDraw); } void AecDbX3dPart::SetName(LPCTSTR pszName) { m_sName = pszName; } void AecDbX3dPart::GetName(CString& sName) const { sName = m_sName; } LPCTSTR AecDbX3dPart::GetGUID() const { return (LPCTSTR)m_sGUID; } void AecDbX3dPart::ReCreateGUID() { m_sGUID = IDCreate(); } void AecDbX3dPart::AddX3dSolid(AcDbX3dSolid* pXSolid,AcDb::BoolOperType bType /*AcDb::kBoolUnite*/,bool bForHouseSub /*= false*/) { if (bType == AcDb::kBoolUnite) { m_arX3DSolidPtrsUnite.append(pXSolid); } else { if (bForHouseSub) { m_arX3DSolidPtrsSubtrForHouse.append(pXSolid); } else { m_arX3DSolidPtrsSubtr.append(pXSolid); } } } void AecDbX3dPart::SetOrgPoint(const AcGePoint3d& ptOrg) { m_ptOrg = ptOrg; } AcGePoint3d AecDbX3dPart::GetOrgPoint(bool bByTransform/* = false*/) const { if (bByTransform) { //然后整体变换 //先旋转 //再移动 AcGePoint3d ptOrg = m_ptOrg; //if (m_arVtAxis.length() <= MAX_AXISROTATS) { //先旋转 AcGeMatrix3d xRote; for (int i = 0;i < m_arVtAxis.length();i++) { if (fabs(m_dAxisRotats[i]) > 1.e-10) { xRote.setToRotation(m_dAxisRotats[i],m_arVtAxis.at(i),ptOrg); ptOrg.transformBy(xRote); } } } ptOrg += m_vtMove; return ptOrg; } return m_ptOrg; } int AecDbX3dPart::GetActiveInf() const { CPoint ptPos,ptRW; if ( GetActiveInf(ptPos)) { GetInterfaceCount(ptRW); int nPos = ptPos.x * ptRW.y + ptPos.y; return nPos; } return -1; } void AecDbX3dPart::SetActiveInf(int nIndex) { CString sName; GetName(sName); if (sName.CompareNoCase(_T("剖切")) == 0) { int nDir = 0; GetSpecialtyData()->GetAt(_T("Dir"),nDir); if (nDir == 0) nDir = 1; else if (nDir == 1) nDir = 0; GetSpecialtyData()->SetAt(_T("Dir"),nDir); return; } CPoint ptRW,ptPos; if ( GetInterfaceCount(ptRW) ) { ptPos.x = nIndex / ptRW.y; ptPos.y = nIndex - ptPos.x * ptRW.y; m_ptActiveInf = ptPos; } } bool AecDbX3dPart::GetInterface(int nIndex,AecInterface& inf) const { CPoint ptRW,ptPos; if ( GetInterfaceCount(ptRW) ) { ptPos.x = nIndex / ptRW.y; ptPos.y = nIndex - ptPos.x * ptRW.y; return GetInterface(ptPos.x,ptPos.y,inf); } return false; } bool AecDbX3dPart::GetInterface(int nRow,int nCol,AecInterface& inf) const { CString sName; GetName(sName); if (sName.CompareNoCase(_T("开洞")) != 0) { return false; } //来自CFUKKDlg 和 CFUKKDlg::GetX3dPart 函数 double dlg_m_dL; double dlg_m_dW; double dlg_m_dX; double dlg_m_dY; double dlg_m_dZ; int dlg_m_nShape; int dlg_m_nDir; double dlg_m_dT; int dlg_m_nH; int dlg_m_nV; double dlg_m_dHSpace; double dlg_m_dVSpace; BOOL dlg_m_bAddHoleCase; GetSpecialtyData()->GetAt(_T("m_dL"),dlg_m_dL); GetSpecialtyData()->GetAt(_T("m_dW"),dlg_m_dW); GetSpecialtyData()->GetAt(_T("m_dT"),dlg_m_dT); GetSpecialtyData()->GetAt(_T("m_dX"),dlg_m_dX); GetSpecialtyData()->GetAt(_T("m_dY"),dlg_m_dY); GetSpecialtyData()->GetAt(_T("m_dZ"),dlg_m_dZ); GetSpecialtyData()->GetAt(_T("m_nDir"),dlg_m_nDir); GetSpecialtyData()->GetAt(_T("m_nH"),dlg_m_nH); GetSpecialtyData()->GetAt(_T("m_nV"),dlg_m_nV); GetSpecialtyData()->GetAt(_T("m_dHSpace"),dlg_m_dHSpace); GetSpecialtyData()->GetAt(_T("m_dVSpace"),dlg_m_dVSpace); GetSpecialtyData()->GetAt(_T("m_bAddHoleCase"),dlg_m_bAddHoleCase); GetSpecialtyData()->GetAt(_T("m_nShape"),dlg_m_nShape); AcGePoint3d ptOrg,ptNewOrg; ptOrg.set(dlg_m_dX,dlg_m_dY,dlg_m_dZ); //ptOrg = GetOrgPoint(); AcGeVector3d vtZ = AcGeVector3d::kZAxis; AcGeVector3d vtStep = AcGeVector3d::kZAxis; if (dlg_m_nDir > 0)//板开 { vtStep = AcGeVector3d::kYAxis; } AcDbX3dSolid* pXSolid = NULL; for (int i = 0;i < dlg_m_nH;i++) { ptNewOrg = ptOrg + i * AcGeVector3d::kXAxis * dlg_m_dHSpace; for (int j = 0;j < dlg_m_nV;j++) { if (dlg_m_nShape == 0)//方 { //L,W,t,H 长宽,厚度 if (dlg_m_nDir == 0)//墙开 { vtZ = AcGeVector3d::kYAxis; } //套管 //if (dlg_m_bAddHoleCase) { if ( nCol == i && nRow == j) { inf.dSize1 = dlg_m_dL; inf.dSize2 = dlg_m_dW; inf.ptPos = ptNewOrg - vtZ * 0.5 * dlg_m_dT; inf.vtDir = vtZ; Transformby(inf.ptPos); Transformby(inf.vtDir); return true; } } } else//园 { if (dlg_m_nDir == 0)//墙开 { vtZ = AcGeVector3d::kYAxis; } //rxtxH //if (dlg_m_bAddHoleCase) { if ( nCol == i && nRow == j) { inf.dSize1 = dlg_m_dL; inf.dSize2 = dlg_m_dL; inf.ptPos = ptNewOrg - vtZ * 0.5 * dlg_m_dT; inf.vtDir = vtZ; Transformby(inf.ptPos); Transformby(inf.vtDir); return true; } } } ptNewOrg += vtStep * dlg_m_dVSpace; } } return false; } bool AecDbX3dPart::GetInterfaceCount(CPoint& ptRC) const { CString sName; GetName(sName); if (sName.CompareNoCase(_T("开洞")) != 0) { return false; } int dlg_m_nH; int dlg_m_nV; GetSpecialtyData()->GetAt(_T("m_nH"),dlg_m_nH); GetSpecialtyData()->GetAt(_T("m_nV"),dlg_m_nV); ptRC.x = dlg_m_nV; ptRC.y = dlg_m_nH; return true; } bool AecDbX3dPart::GetSlicePlan(AcGePlane& plan) const { CString sName; GetName(sName); if (sName.CompareNoCase(_T("剖切")) == 0) { int nPlan = 0; GetSpecialtyData()->GetAt(_T("m_nPlan"),nPlan); int nDir = 0; GetSpecialtyData()->GetAt(_T("Dir"),nDir); AcGePoint3d ptOrg = GetOrgPoint(); Transformby(ptOrg); switch(nPlan) { case 0://xz { if (nDir == 0) plan.set(ptOrg,AcGeVector3d::kYAxis); else plan.set(ptOrg,-AcGeVector3d::kYAxis); break; } case 1://yz { if (nDir == 0) plan.set(ptOrg,AcGeVector3d::kXAxis); else plan.set(ptOrg,-AcGeVector3d::kXAxis); break; } case 2://xy { if (nDir == 0) plan.set(ptOrg,AcGeVector3d::kZAxis); else plan.set(ptOrg,-AcGeVector3d::kZAxis); break; } default: break; } return true; } return false; } bool AecDbX3dPart::SetActiveInf(const CPoint& ptRC) { CString sName; GetName(sName); if (sName.CompareNoCase(_T("开洞")) != 0) { return false; } if (ptRC.x >= -1 && ptRC.y >= -1) { m_ptActiveInf = ptRC; } return false; } bool AecDbX3dPart::GetActiveInf(CPoint& ptRC) const { CString sName; GetName(sName); if (sName.CompareNoCase(_T("开洞")) != 0) { return false; } ptRC = m_ptActiveInf; return true; } void AecDbX3dPart::RemoveAll3dSolidRec() { AcDbX3dSolid* pXSolid = NULL; for (int i = 0;i < m_arX3DSolidPtrsUnite.length();i++) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsUnite.at(i); DELETE_PTR(pXSolid); } m_arX3DSolidPtrsUnite.removeAll(); for (int i = 0;i < m_arX3DSolidPtrsSubtr.length();i++) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsSubtr.at(i); DELETE_PTR(pXSolid); } m_arX3DSolidPtrsSubtr.removeAll(); for (int i = 0;i < m_arX3DSolidPtrsSubtrForHouse.length();i++) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsSubtrForHouse.at(i); DELETE_PTR(pXSolid); } m_arX3DSolidPtrsSubtrForHouse.removeAll(); //recreate if (m_pSolid != NULL) DELETE_PTR(m_pSolid); if (m_pSolidDraw != NULL) DELETE_PTR(m_pSolidDraw); //保持用户的位置 //ResetMove(); //ResetRotate(-1); } void AecDbX3dPart::RemoveAt(int nIndex,AcDb::BoolOperType bType/* = AcDb::kBoolUnite*/,bool bForHouseSub/* = false*/) { AcDbX3dSolid* pXSolid = NULL; if (bForHouseSub) { if (nIndex > -1 && nIndex < m_arX3DSolidPtrsSubtrForHouse.length()) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsSubtrForHouse.at(nIndex); m_arX3DSolidPtrsSubtrForHouse.removeAt(nIndex); delete pXSolid; } return; } if (bType == AcDb::kBoolUnite) { if (nIndex > -1 && nIndex < m_arX3DSolidPtrsUnite.length()) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsUnite.at(nIndex); m_arX3DSolidPtrsUnite.removeAt(nIndex); delete pXSolid; } } else { if (nIndex > -1 && nIndex < m_arX3DSolidPtrsSubtr.length()) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsSubtr.at(nIndex); m_arX3DSolidPtrsSubtr.removeAt(nIndex); delete pXSolid; } } //recreate if (m_pSolid != NULL) DELETE_PTR(m_pSolid); if (m_pSolidDraw != NULL) DELETE_PTR(m_pSolidDraw); } int AecDbX3dPart::GetX3dSolidCount(AcDb::BoolOperType bType/* = AcDb::kBoolUnite*/,bool bForHouseSub/* = false*/) const { if (bForHouseSub) { return m_arX3DSolidPtrsSubtrForHouse.length(); } else { if (bType == AcDb::kBoolUnite) { return m_arX3DSolidPtrsUnite.length(); } else { return m_arX3DSolidPtrsSubtr.length(); } } return 0; } AcDbX3dSolid* AecDbX3dPart::GetX3dSolid(int nIndex,AcDb::BoolOperType bType/* = AcDb::kBoolUnite*/) const { AcDbX3dSolid* pX3dSolid = NULL; if (bType == AcDb::kBoolUnite) { if (nIndex > -1 && nIndex < m_arX3DSolidPtrsUnite.length()) { pX3dSolid = (AcDbX3dSolid* )m_arX3DSolidPtrsUnite.at(nIndex); } } else { pX3dSolid = (AcDbX3dSolid* )m_arX3DSolidPtrsSubtr.at(nIndex); } return pX3dSolid; } bool AecDbX3dPart::SetAxis(int nIndex,const AcGeVector3d& vtAxis) { if (nIndex >= 0 && nIndex < MAX_AXISROTATS) { m_arVtAxis.setAt(nIndex,vtAxis); return true; } return false; } bool AecDbX3dPart::GetAxis(int nIndex,AcGeVector3d& vtAxis) const { if (nIndex >= 0 && nIndex < m_arVtAxis.length()) { vtAxis = m_arVtAxis.at(nIndex); return true; } return false; } void AecDbX3dPart::SetHideShow( ) { bool bHide = IsHide(); SetHide(!bHide); } void AecDbX3dPart::SetHide(bool bHide) { m_mapXData.SetAt(_T("Hide"),bHide ? 1 : 0); } bool AecDbX3dPart::IsHide() const { int nVal = 0; if ( m_mapXData.GetAt(_T("Hide"),nVal) ) { return nVal > 0 ? true : false; } return false; } void AecDbX3dPart::PeelOffTheSkin(int nPos) { m_nPeelOff = nPos; if (m_pSolidDraw != NULL) DELETE_PTR(m_pSolidDraw); if (m_pSolid != NULL) DELETE_PTR(m_pSolid); } bool AecDbX3dPart::IsPeelOffTheSkin() const { return m_nPeelOff > -1 ? true : false; } void AecDbX3dPart::SetActive(bool bActive) { m_bActive = bActive; } void AecDbX3dPart::AddMove(const AcGeVector3d& vtMove) { m_vtMove += vtMove; if (m_pSolidDraw != NULL) DELETE_PTR(m_pSolidDraw); if (m_pSolid != NULL) DELETE_PTR(m_pSolid); } void AecDbX3dPart::AddMove(const AcGeMatrix3d& xMirror) { m_vtMove += xMirror.translation(); if (m_pSolidDraw != NULL) DELETE_PTR(m_pSolidDraw); if (m_pSolid != NULL) DELETE_PTR(m_pSolid); } AcGeVector3d AecDbX3dPart::GetMove() const { return m_vtMove; } void AecDbX3dPart::ResetMove() { m_vtMove = AcGeVector3d::kIdentity; if (m_pSolidDraw != NULL) DELETE_PTR(m_pSolidDraw); if (m_pSolid != NULL) DELETE_PTR(m_pSolid); } void AecDbX3dPart::AddRotate(int nAxisIndex,double dRot) { if (nAxisIndex >= 0 && nAxisIndex <= MAX_AXISROTATS ) { m_dAxisRotats[nAxisIndex] += dRot; if (m_pSolidDraw != NULL) DELETE_PTR(m_pSolidDraw); if (m_pSolid != NULL) DELETE_PTR(m_pSolid); } } double AecDbX3dPart::GetRotate(int nAxisIndex) const { if (nAxisIndex >= 0 && nAxisIndex <= MAX_AXISROTATS ) { return m_dAxisRotats[nAxisIndex]; } return 0.0; } void AecDbX3dPart::ResetRotate(int nAxisIndex) { if (nAxisIndex >= 0 && nAxisIndex < MAX_AXISROTATS) { m_dAxisRotats[nAxisIndex] = 0.0; if (m_pSolidDraw != NULL) DELETE_PTR(m_pSolidDraw); if (m_pSolid != NULL) DELETE_PTR(m_pSolid); } if (nAxisIndex == -1) { memset(m_dAxisRotats,0,sizeof(double) * MAX_AXISROTATS); if (m_pSolidDraw != NULL) DELETE_PTR(m_pSolidDraw); if (m_pSolid != NULL) DELETE_PTR(m_pSolid); } } void AecDbX3dPart::Transformby(AcGePoint3d& pt) const { pt += m_vtMove; AcGePoint3d ptOrg = m_ptOrg; ptOrg += m_vtMove; if (m_arVtAxis.length() <= MAX_AXISROTATS) { //先旋转 AcGeMatrix3d xRote; for (int i = 0;i < m_arVtAxis.length();i++) { if (fabs(m_dAxisRotats[i]) > 1.e-10) { xRote.setToRotation(m_dAxisRotats[i],m_arVtAxis.at(i),ptOrg); pt.transformBy(xRote); } } } } void AecDbX3dPart::Transformby(AcGeVector3d& vt) const { AcGeMatrix3d xform; AcGeVector3d vtAxis; for (int i = 0;i < m_arVtAxis.length();i++) { vtAxis = m_arVtAxis.at(i); if ( !vtAxis.isZeroLength() && fabs(m_dAxisRotats[i]) > 1.e-10) { xform.setToIdentity(); xform.setToRotation(m_dAxisRotats[i],vtAxis,m_ptOrg); vt.transformBy(xform); } } } void AecDbX3dPart::SetBoolOperFor(int nOper) { m_nBoolOper = nOper; } int AecDbX3dPart::GetBoolOperFor() const { return m_nBoolOper; } AecDbObjXDataMap* AecDbX3dPart::GetSpecialtyData() { return &m_mapXData; } const AecDbObjXDataMap* AecDbX3dPart::GetSpecialtyData() const { return &m_mapXData; } bool AecDbX3dPart::Create() { if (m_pSolid != NULL) DELETE_PTR(m_pSolid); int nVt; if (GetSpecialtyData()->HasKey(_T("DTYG_TYPE"), nVt)) { // 说明是单体异构 BOOL bHide(FALSE); if (GetSpecialtyData()->GetAt(_T("Hide"), bHide)) { if (bHide) return true; } } Acad::ErrorStatus es; AcDbX3dSolid* pXSolid = NULL; //先unite for (int i = 0;i < m_arX3DSolidPtrsUnite.length();i++) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsUnite.at(i); AcDb3dSolid* pSolid = pXSolid->GetDraw3dSolid(); if (pSolid == NULL) continue; if (m_pSolid == NULL) { m_pSolid = pSolid; } else { if ( Acad::eOk == (es = m_pSolid->booleanOper(AcDb::kBoolUnite,pSolid) ) ) { } else { DELETE_PTR(pSolid); } } } if (m_pSolid == NULL) return false; //然后 subtract for (int i = 0;i < m_arX3DSolidPtrsSubtr.length();i++) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsSubtr.at(i); AcDb3dSolid* pSolid = pXSolid->GetDraw3dSolid(); if (pSolid != NULL) { if ( Acad::eOk == (es = m_pSolid->booleanOper(AcDb::kBoolSubtract,pSolid) ) ) { } else { DELETE_PTR(pSolid); } } } //然后整体变换 //先旋转 //再移动 AcGePoint3d ptOrg = m_ptOrg; //if (m_arVtAxis.length() <= MAX_AXISROTATS) { //先旋转 AcGeMatrix3d xRote; for (int i = 0;i < m_arVtAxis.length();i++) { if (fabs(m_dAxisRotats[i]) > 1.e-10) { xRote.setToIdentity(); xRote.setToRotation(m_dAxisRotats[i],m_arVtAxis.at(i),ptOrg); m_pSolid->transformBy(xRote); } } } ptOrg += m_vtMove; AcGeMatrix3d xMove; xMove.setToTranslation(m_vtMove); m_pSolid->transformBy(xMove); if (m_bActive) { m_pSolid->setColorIndex(ColorIndex::kMagenta); } else { int nVt; if (GetSpecialtyData()->HasKey(_T("DTYG_TYPE"), nVt)) { // 说明是单体异构 CString s; if (GetSpecialtyData()->GetAt(_T("user1"), s)) { std::vector vec; CoreTools::SplitString(s, _T(':'), vec); if (vec.size() == 2) { int clr = TypeConvert::s2i(vec[1]); m_pSolid->setColorIndex(clr); } } } } m_mapXData.Write(m_pSolid,_T("BIMDATA")); return true; } int AecDbX3dPart::GetForHouseSubtract(AcDbVoidPtrArray& arSolidPtrs) const { AcDbX3dSolid* pXSolid = NULL; AcGePoint3d ptOrg = m_ptOrg; ptOrg += m_vtMove; AcGeMatrix3d xMove; xMove.setToTranslation(m_vtMove); for (int i = 0;i < m_arX3DSolidPtrsSubtrForHouse.length();i++) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsSubtrForHouse.at(i); AcDb3dSolid* pSolid = pXSolid->GetDraw3dSolid(); if (pSolid != NULL) { if (m_arVtAxis.length() <= MAX_AXISROTATS) { //先旋转 AcGeMatrix3d xRote; for (int i = 0;i < m_arVtAxis.length();i++) { if (fabs(m_dAxisRotats[i]) > 1.e-10) { xRote.setToRotation(m_dAxisRotats[i],m_arVtAxis.at(i),m_ptOrg); pSolid->transformBy(xRote); } } } pSolid->transformBy(xMove); arSolidPtrs.append(pSolid); } } return arSolidPtrs.length(); } AcDb3dSolid* AecDbX3dPart::CreateDraw3dSolid() const { AcDb3dSolid* pDraw = NULL; if (m_pSolid != NULL) { int nVt; pDraw = (AcDb3dSolid*)m_pSolid->clone(); AcDbObjectId ltid(KTSetting::InitLineStyle(_T("CENTER"))); if (GetSpecialtyData()->HasKey(_T("DTYG_TYPE"), nVt)) { AecDbObjXDataMap map; map.SetAt(_T("IS_DTYG"), _T("1")); map.Write(pDraw, _T("DTYG")); if (GetBoolOperFor() == AcDb::kBoolSubtract && ltid.isValid()) pDraw->setLinetype(ltid); } } return pDraw; } Acad::ErrorStatus AecDbX3dPart::Draw2d(AcGiDraw &dc) const { //投影 if (m_pSolidDraw != NULL) { } return Acad::eOk; } Acad::ErrorStatus AecDbX3dPart::Draw3d(AcGiDraw &dc) const { if (m_pSolidDraw == NULL) { m_pSolidDraw = CreateDraw3dSolid(); } if (m_pSolidDraw != NULL) { if (m_bActive ) m_pSolidDraw->setColorIndex(kMagenta); if (!IsHide()) { AcGiCommonDraw *pCommDraw = dc.GetCommonDraw(); if (pCommDraw != NULL) { AcCmTransparency tr = pCommDraw->subEntityTraits().transparency(); m_pSolidDraw->setTransparency(tr); } dc.DrawEntity(*m_pSolidDraw); } } return Acad::eOk; } Acad::ErrorStatus AecDbX3dPart::DrawAxis(AcGiDraw &dc) const { Draw3d(dc); AcGePoint3d ptOrg = m_ptOrg; ptOrg += m_vtMove; AcGeVector3d vtDir; for (int i = 0;i < m_arVtAxis.length();i++) { vtDir = m_arVtAxis.at(i); if (vtDir.isZeroLength()) continue; vtDir.normalize(); Adesk::Int16 nCr = dc.GetColor(); if (i == 0) dc.SetColor(1);//red else if (i == 1) dc.SetColor(3);//gree else if (i == 2) dc.SetColor(5);//blue else dc.SetColor(i+1); vtDir.normalize(); vtDir *= PixelToWcs(20); //clinder AcGePoint3d ptGeFr = ptOrg; AcGePoint3d ptGeTo = ptGeFr + vtDir; AcDbEntity* p3d = dc.DrawCone(ptGeFr,PixelToWcs(1),ptGeTo,PixelToWcs(1)); if (p3d != NULL) { } //arrow ptGeFr = ptGeTo; vtDir.normalize(); ptGeTo += vtDir * PixelToWcs(15); p3d = dc.DrawCone(ptGeFr,PixelToWcs(5),ptGeTo,1.e-3); if (p3d != NULL) { } dc.SetColor(nCr); } DrawInf(dc); return Acad::eOk; } Acad::ErrorStatus AecDbX3dPart::DrawInf(AcGiDraw &dc) const { if (m_ptActiveInf.x > -1 && m_ptActiveInf.y > -1) { AecInterface inf; if ( GetInterface(m_ptActiveInf.x,m_ptActiveInf.y,inf) ) { AcGeVector3d vtDir = inf.vtDir; vtDir.normalize(); Adesk::Int16 nCr = dc.GetColor(); dc.SetColor(kYellow);//red vtDir.normalize(); vtDir *= PixelToWcs(30); double dlg_m_dT = 0.0; GetSpecialtyData()->GetAt(_T("m_dT"),dlg_m_dT); //clinder inf.ptPos += inf.vtDir * dlg_m_dT; AcGePoint3d ptGeFr = inf.ptPos; AcGePoint3d ptGeTo = ptGeFr + vtDir; AcDbEntity* p3d = dc.DrawCone(ptGeFr,PixelToWcs(1),ptGeTo,PixelToWcs(1)); if (p3d != NULL) { } //arrow ptGeFr = ptGeTo; vtDir.normalize(); ptGeTo += vtDir * PixelToWcs(15); p3d = dc.DrawCone(ptGeFr,PixelToWcs(5),ptGeTo,1.e-3); if (p3d != NULL) { } dc.SetColor(nCr); } } return Acad::eOk; } Acad::ErrorStatus AecDbX3dPart::getOsnapPoints( AcDb::OsnapMode osnapMode, INT_PTR gsSelectionMark, const AcGePoint3d& pickPoint, const AcGePoint3d& lastPoint, const AcGeMatrix3d& viewXform, AcGePoint3dArray& snapPoints, AcDbIntArray& geomIds) const { if (m_pSolidDraw != NULL) { m_pSolidDraw->getOsnapPoints(osnapMode,gsSelectionMark,pickPoint,lastPoint,viewXform,snapPoints,geomIds); } return Acad::eOk; } Acad::ErrorStatus AecDbX3dPart::dwgInFields (AcDbDwgFiler* pFiler) { Acad::ErrorStatus es; Adesk::UInt32 version =0 ; if ( (es =pFiler->readUInt32 (&version)) != Acad::eOk ) return (es) ; if ( version > AecDbX3dPart::kCurrentVersionNumber ) return (Acad::eMakeMeProxy) ; TCHAR* pszTemp = NULL; pFiler->readString(&pszTemp); if (pszTemp != NULL) { m_sName = pszTemp; acutDelString(pszTemp); } pszTemp = NULL; pFiler->readString(&pszTemp); if (pszTemp != NULL) { m_sGUID = pszTemp; acutDelString(pszTemp); } Adesk::Int32 nVal = 0; pFiler->readInt32(&nVal); m_nBoolOper = nVal; //1 Adesk::Int32 nLen = 0; pFiler->readInt32(&nLen); RemoveAll3dSolidRec(); AcDbX3dSolid* pXSolid = NULL; for (int i = 0;i < nLen;i++) { pXSolid = new AcDbX3dSolid; pXSolid->dwgInFields(pFiler); m_arX3DSolidPtrsUnite.append(pXSolid); } //2 nLen = 0; pFiler->readInt32(&nLen); for (int i = 0;i < nLen;i++) { pXSolid = new AcDbX3dSolid; pXSolid->dwgInFields(pFiler); m_arX3DSolidPtrsSubtr.append(pXSolid); } //3 pFiler->readInt32(&nLen); for (int i = 0;i < nLen;i++) { pXSolid = new AcDbX3dSolid; pXSolid->dwgInFields(pFiler); m_arX3DSolidPtrsSubtrForHouse.append(pXSolid); } pFiler->readVector3d(&m_vtMove); pFiler->readPoint3d(&m_ptOrg); pFiler->readInt32(&nLen); m_arVtAxis.removeAll(); AcGeVector3d vt; for (int i = 0;i < nLen;i++) { pFiler->readVector3d(&vt); m_arVtAxis.append(vt); } pFiler->readBytes(m_dAxisRotats,sizeof(double) * MAX_AXISROTATS); m_mapXData.dwgInFields(pFiler); return Acad::eOk; } Acad::ErrorStatus AecDbX3dPart::dwgOutFields(AcDbDwgFiler* pFiler) const { Acad::ErrorStatus es; //----- Object version number needs to be saved first if ( (es = pFiler->writeUInt32 (AecDbX3dPart::kCurrentVersionNumber)) != Acad::eOk ) return (es); pFiler->writeString((LPCTSTR)m_sName); pFiler->writeString((LPCTSTR)m_sGUID); pFiler->writeInt32(m_nBoolOper); //1 Adesk::Int32 nLen = m_arX3DSolidPtrsUnite.length(); pFiler->writeInt32(nLen); AcDbX3dSolid* pXSolid = NULL; for (int i = 0;i < nLen;i++) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsUnite.at(i); pXSolid->dwgOutFields(pFiler); } //2 nLen = m_arX3DSolidPtrsSubtr.length(); pFiler->writeInt32(nLen); for (int i = 0;i < nLen;i++) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsSubtr.at(i); pXSolid->dwgOutFields(pFiler); } //3 nLen = m_arX3DSolidPtrsSubtrForHouse.length(); pFiler->writeInt32(nLen); for (int i = 0;i < nLen;i++) { pXSolid = (AcDbX3dSolid*)m_arX3DSolidPtrsSubtrForHouse.at(i); pXSolid->dwgOutFields(pFiler); } pFiler->writeVector3d(m_vtMove); pFiler->writePoint3d(m_ptOrg); nLen = m_arVtAxis.length(); pFiler->writeInt32(nLen); for (int i = 0;i < nLen;i++) { pFiler->writeVector3d(m_arVtAxis.at(i)); } pFiler->writeBytes(m_dAxisRotats,sizeof(double) * MAX_AXISROTATS); m_mapXData.dwgOutFields(pFiler); return Acad::eOk; } Acad::ErrorStatus AecDbX3dPart::CopyFrom(AecDbX3dPart* pSrcPart) { if (pSrcPart == NULL) return Acad::eInvalidInput; AecDbX3dPart& pPart = *pSrcPart; m_pSolidDraw = NULL; m_pSolid = NULL; m_sName = pPart.m_sName; m_sGUID = pPart.m_sGUID; m_nBoolOper = pPart.m_nBoolOper; // RemoveAll3dSolidRec(); AcDbX3dSolid* pXSolid = NULL; AcDbX3dSolid* pXSolidNew = NULL; for (int i = 0;i < pPart.m_arX3DSolidPtrsUnite.length();i++) { pXSolid = (AcDbX3dSolid*)pPart.m_arX3DSolidPtrsUnite.at(i); pXSolidNew = new AcDbX3dSolid(*pXSolid); pXSolidNew->ReCreate(); m_arX3DSolidPtrsUnite.append(pXSolidNew); } for (int i = 0;i < pPart.m_arX3DSolidPtrsSubtr.length();i++) { pXSolid = (AcDbX3dSolid*)pPart.m_arX3DSolidPtrsSubtr.at(i); pXSolidNew = new AcDbX3dSolid(*pXSolid); pXSolidNew->ReCreate(); m_arX3DSolidPtrsSubtr.append(pXSolidNew); } for (int i = 0;i < pPart.m_arX3DSolidPtrsSubtrForHouse.length();i++) { pXSolid = (AcDbX3dSolid*)pPart.m_arX3DSolidPtrsSubtrForHouse.at(i); pXSolidNew = new AcDbX3dSolid(*pXSolid); pXSolidNew->ReCreate(); m_arX3DSolidPtrsSubtrForHouse.append(pXSolidNew); } //先旋转,后移动 m_vtMove = pPart.m_vtMove; //总移动 m_ptOrg = pPart.m_ptOrg; //原点 m_arVtAxis.append(pPart.m_arVtAxis); //轴向 memcpy(m_dAxisRotats,pPart.m_dAxisRotats,MAX_AXISROTATS * sizeof(double)); m_mapXData.CopyFrom(&pPart.m_mapXData); //显示,临时 m_ptActiveInf = pPart.m_ptActiveInf; m_bActive = pPart.m_bActive; m_nPeelOff = pPart.m_nPeelOff; return Acad::eOk; } void AecDbX3dPart::List() const { acutPrintf(_T("\n名称: %s"),m_sName); acutPrintf(_T("\n唯一标识: %s"),m_sGUID); acutPrintf(_T("\n装配类型: %d"),m_nBoolOper); acutPrintf(_T("\n并元素个数: %d"),m_arX3DSolidPtrsUnite.length()); acutPrintf(_T("\n减元素个数: %d"),m_arX3DSolidPtrsSubtr.length()); acutPrintf(_T("\nBIM信息:")); acutPrintf(_T("\nOrg:%g,%g,%g"),m_ptOrg.x,m_ptOrg.y,m_ptOrg.z); acutPrintf(_T("\nMove:%g,%g,%g"),m_vtMove.x,m_vtMove.y,m_vtMove.z); for (int i = 0;i < MAX_AXISROTATS;i++) { if (i < m_arVtAxis.length()) { if (m_arVtAxis.at(i).isZeroLength()) { break; } acutPrintf(_T("\nRotat:%g"),m_dAxisRotats[i]); acutPrintf(_T("\nAxis:%g,%g,%g"),m_arVtAxis.at(i).x,m_arVtAxis.at(i).y,m_arVtAxis.at(i).z); } } m_mapXData.List(); } SHJson::WValue& AecDbX3dPart::ToJson() const { using namespace SHJson; /* //序列化 CString m_sName; CString m_sGUID; Adesk::Int32 m_nBoolOper; // AcDbVoidPtrArray m_arX3DSolidPtrsUnite; AcDbVoidPtrArray m_arX3DSolidPtrsSubtr; AcDbVoidPtrArray m_arX3DSolidPtrsSubtrForHouse; //先旋转,后移动 AcGeVector3d m_vtMove; //总移动 AcGePoint3d m_ptOrg; //原点 AcGeVector3dArray m_arVtAxis; //轴向 double m_dAxisRotats[MAX_AXISROTATS];//最多10个轴向旋转 AecDbObjXDataMap m_mapXData; //BIM数据 */ WValue &v(m_json), tmp; v.SetObject(); addMember(v, _T("__class__"), _T("AecDbX3dPart")); addMember(v, _T("__sName__"), m_sName); addMember(v, _T("__sGUID__"), m_sGUID); addMember(v, _T("__nBoolOper__"), m_nBoolOper); addMember(v, _T("__vtMove__"), GEO2JSON::vector(m_vtMove).ToJson()); addMember(v, _T("__ptOrg__"), GEO2JSON::point(m_ptOrg).ToJson()); // 轴向 WValue jAr; jAr.SetArray(); for (int i = 0; i < m_arVtAxis.length(); ++i) { pushBack(jAr, GEO2JSON::vector(m_arVtAxis[i]).ToJson()); } addMember(v, _T("__arVtAxis__"), jAr); // 旋转量 jAr.SetNull(); jAr.SetArray(); for (int i = 0; i < MAX_AXISROTATS; ++i) { pushBack(jAr, m_dAxisRotats[i]); } addMember(v, _T("__dAxisRotats__"), jAr); // UnitePart jAr.SetNull(); jAr.SetArray(); for (int i = 0; i < m_arX3DSolidPtrsUnite.length(); ++i) { AcDbX3dSolid *pSolid((AcDbX3dSolid*)m_arX3DSolidPtrsUnite[i]); pushBack(jAr, pSolid->ToJson()); } addMember(v, _T("__arX3DSolidPtrsUnite__"), jAr); // SubtrPart jAr.SetNull(); jAr.SetArray(); for (int i = 0; i < m_arX3DSolidPtrsSubtr.length(); ++i) { AcDbX3dSolid *pSolid((AcDbX3dSolid*)m_arX3DSolidPtrsSubtr[i]); pushBack(jAr, pSolid->ToJson()); } addMember(v, _T("__arX3DSolidPtrsSubtr__"), jAr); // SubtrForHouse jAr.SetNull(); jAr.SetArray(); for (int i = 0; i < m_arX3DSolidPtrsSubtrForHouse.length(); ++i) { AcDbX3dSolid *pSolid((AcDbX3dSolid*)m_arX3DSolidPtrsSubtrForHouse[i]); pushBack(jAr, pSolid->ToJson()); } addMember(v, _T("__arX3DSolidPtrsSubtrForHouse__"), jAr); // xdata addMember(v, _T("__xdata__"), m_mapXData.ToJson()); return v; } bool AecDbX3dPart::ByJson(const SHJson::WValue &v) { MCIt it = v.FindMember(_T("__sName__")); if (it == v.MemberEnd()) return false; m_sName = it->value.GetString(); it = v.FindMember(_T("__sGUID__")); if (it == v.MemberEnd()) return false; m_sGUID = it->value.GetString(); it = v.FindMember(_T("__nBooloper__")); if (it == v.MemberEnd()) return false; m_nBoolOper = it->value.GetInt(); it = v.FindMember(_T("__vtMove__")); if (it == v.MemberEnd()) return false; m_vtMove = GEO2JSON::vector(it->value).asVec3d(); it = v.FindMember(_T("__ptOrg")); if (it == v.MemberEnd()) return false; m_ptOrg = GEO2JSON::point(it->value).asPnt3d(); it = v.FindMember(_T("__arVtAxis__")); if (it == v.MemberEnd()) return false; if (!it->value.IsArray()) return false; for (VCIt i = it->value.Begin(); i != it->value.End(); ++i) { m_arVtAxis.append(GEO2JSON::vector(it->value).asVec3d()); } it = v.FindMember(_T("__dAxisRotats__")); if (it == v.MemberEnd()) return false; if (!it->value.IsArray()) return false; int j(0); for (VCIt i = it->value.Begin(); i != it->value.End(); ++i, ++j) { m_dAxisRotats[j] = i->GetDouble(); } it = v.FindMember(_T("__arX3DSolidPtrsUnite__")); if (it == v.MemberEnd()) return false; if (!it->value.IsArray()) return false; for (VCIt i = it->value.Begin(); i != it->value.End(); ++i) { AcDbX3dSolid *pSolid = new AcDbX3dSolid(); if (pSolid->ByJson(it->value)) { m_arX3DSolidPtrsUnite.append(pSolid); } else { DELETE_PTR(pSolid); } } it = v.FindMember(_T("__arX3DSolidPtrsSubtr__")); if (it == v.MemberEnd()) return false; if (!it->value.IsArray()) return false; for (VCIt i = it->value.Begin(); i != it->value.End(); ++i) { AcDbX3dSolid *pSolid = new AcDbX3dSolid(); if (pSolid->ByJson(it->value)) { m_arX3DSolidPtrsSubtr.append(pSolid); } else { DELETE_PTR(pSolid); } } it = v.FindMember(_T("__arX3DSolidPtrsSubtrForHouse__")); if (it == v.MemberEnd()) return false; if (!it->value.IsArray()) return false; for (VCIt i = it->value.Begin(); i != it->value.End(); ++i) { AcDbX3dSolid *pSolid = new AcDbX3dSolid(); if (pSolid->ByJson(it->value)) { m_arX3DSolidPtrsSubtrForHouse.append(pSolid); } else { DELETE_PTR(pSolid); } } it = v.FindMember(_T("__xdata__")); if (it == v.MemberEnd()) return false; if (!m_mapXData.ByJson(v)) return false; return true; } void AecDbX3dPart::getBimDatas(SH_BIM_BLOCK &data) { const AecDbObjXDataMap *pDataMap = GetSpecialtyData(); if (!pDataMap) return; CoreTools::getBimDatas(*pDataMap, data); } void AecDbX3dPart::setBimDatas(const SH_BIM_BLOCK &data) { AecDbObjXDataMap *pDataMap = GetSpecialtyData(); if (!pDataMap) return; CoreTools::setBimDatas(*pDataMap, data); }