308 lines
7.2 KiB
C++
308 lines
7.2 KiB
C++
#include "stdafx.h"
|
|
#include "AcGiViewDraw.h"
|
|
#include "AecDbPingfadim.h"
|
|
#include "dbgrip.h"
|
|
#include "MFCDbDwgFiler.h"
|
|
#include "CoreTools.h"
|
|
|
|
IMP_XDATA_KEY(AecDbPingFaDim, _AllText_);
|
|
IMP_XDATA_KEY(AecDbPingFaDim, _TextHeight_);
|
|
IMP_XDATA_KEY(AecDbPingFaDim, _TextStyle_);
|
|
IMP_XDATA_KEY(AecDbPingFaDim, _StartPoint_);
|
|
IMP_XDATA_KEY(AecDbPingFaDim, _LineDir_);
|
|
|
|
|
|
ACRX_DXF_DEFINE_MEMBERS(AecDbPingFaDim, AecDbEntityBase,
|
|
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
|
AcDbProxyEntity::kNoOperation | AcDbProxyEntity::kDisableProxyWarning,
|
|
AEC_PFDIM,
|
|
"AecDbPingFaDim"
|
|
"|Product Desc: shanghua earthworm app obj"
|
|
"|Company: shanghua inc"
|
|
"|WEB Address: www.shanghuasoft.com")
|
|
|
|
Adesk::UInt32 AecDbPingFaDim::kCurrentVersionNumber = 1;
|
|
|
|
AecDbPingFaDim::AecDbPingFaDim(void) { }
|
|
|
|
AecDbPingFaDim::~AecDbPingFaDim(void) { }
|
|
|
|
Acad::ErrorStatus AecDbPingFaDim::subErase(Adesk::Boolean erasing)
|
|
{
|
|
return AecDbEntityBase::subErase(erasing);
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbPingFaDim::copyFrom(const AcRxObject *pSrc)
|
|
{
|
|
AssertWriteEnabled();
|
|
AecDbPingFaDim *pCamera = AecDbPingFaDim::cast(pSrc);
|
|
if (pCamera != NULL)
|
|
{
|
|
m_mapSpecXData.CopyFrom(pCamera->GetSpecialtyData(AcDb::kForRead));
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
void AecDbPingFaDim::subList() const
|
|
{
|
|
assertReadEnabled();
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbPingFaDim::subTransformBy(const AcGeMatrix3d &xform)
|
|
{
|
|
AssertWriteEnabled();
|
|
|
|
SetStartPoint(GetStartPoint().transformBy(xform));
|
|
SetLineDir(GetLineDir().transformBy(xform));
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbPingFaDim::subGetGripPoints(AcDbGripDataPtrArray &grips,
|
|
const double curViewUnitSize,
|
|
const int gripSize,
|
|
const AcGeVector3d &curViewDir,
|
|
const int bitflags) const
|
|
{
|
|
return Acad::eNotImplementedYet;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbPingFaDim::subGetGripPoints(AcGePoint3dArray &gripPoints, AcDbIntArray &osnapModes, AcDbIntArray &geomIds) const
|
|
{
|
|
assertReadEnabled();
|
|
gripPoints.append(GetStartPoint());
|
|
gripPoints.append(GetStartPoint() + GetLineDir());
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbPingFaDim::subGetOsnapPoints(AcDb::OsnapMode osnapMode
|
|
, INT_PTR gsSelectionMark
|
|
, const AcGePoint3d &pickPoint
|
|
, const AcGePoint3d &lastPoint
|
|
, const AcGeMatrix3d &viewXform
|
|
, AcGePoint3dArray &snapPoints
|
|
, AcDbIntArray &geomIds) const
|
|
{
|
|
return AecDbEntityBase::subGetOsnapPoints(osnapMode, gsSelectionMark, pickPoint
|
|
, lastPoint, viewXform, snapPoints, geomIds);
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbPingFaDim::subMoveGripPointsAt(const AcDbVoidPtrArray &appData
|
|
, const AcGeVector3d &offset
|
|
, const int bitflags)
|
|
{
|
|
return Acad::eNotImplementedYet;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbPingFaDim::subMoveGripPointsAt(const AcDbIntArray &indices, const AcGeVector3d &offset)
|
|
{
|
|
assertWriteEnabled();
|
|
if (indices.isEmpty()) return Acad::eOk;
|
|
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(offset);
|
|
|
|
// 改变位置
|
|
if (indices.first() == 0)
|
|
{
|
|
SetStartPoint(GetStartPoint().transformBy(mat));
|
|
}
|
|
else if (indices.first() == 1)
|
|
{
|
|
AcGePoint3d ptS(GetStartPoint());
|
|
AcGePoint3d ptOld(ptS + GetLineDir());
|
|
|
|
AcGeVector3d vt(GetLineDir().normalize());
|
|
vt.rotateBy(-PI*.5, AcGeVector3d::kZAxis);
|
|
AcGeLine3d line(ptS, vt);
|
|
|
|
AcGePoint3d ptNew(ptS + GetLineDir());
|
|
ptNew.transformBy(mat);
|
|
|
|
vt = GetLineDir().normalize();
|
|
if (!(line.closestPointTo(ptOld) - ptOld).isCodirectionalTo(line.closestPointTo(ptNew) - ptNew))
|
|
vt.negate();
|
|
|
|
double dist = line.distanceTo(ptNew);
|
|
SetLineDir(vt * dist);
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
void AecDbPingFaDim::GetGripText(int nPos, CString &sText)
|
|
{
|
|
if (nPos == 0)
|
|
{
|
|
sText = _T("移动标注位置");
|
|
}
|
|
else if (nPos == 1)
|
|
{
|
|
sText = _T("改变标注长度");
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbPingFaDim::dwgInFields(AcDbDwgFiler *pFiler)
|
|
{
|
|
AssertWriteEnabled();
|
|
|
|
//----- Read parent class information first.
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
if (!pFiler->isKindOf(CMFCDbDwgFiler::desc()))
|
|
{
|
|
es = AecDbEntityBase::dwgInFields(pFiler);
|
|
if (es != Acad::eOk)
|
|
return (es);
|
|
}
|
|
|
|
//----- Object version number needs to be read first
|
|
Adesk::UInt32 version = 0;
|
|
if ((es = pFiler->readUInt32(&version)) != Acad::eOk)
|
|
return (es);
|
|
|
|
if (version > AecDbPingFaDim::kCurrentVersionNumber)
|
|
return (Acad::eMakeMeProxy);
|
|
|
|
m_mapSpecXData.dwgInFields(pFiler);
|
|
|
|
return (pFiler->filerStatus());
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbPingFaDim::dwgOutFields(AcDbDwgFiler *pFiler) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
//----- Save parent class information first.
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
if (!pFiler->isKindOf(CMFCDbDwgFiler::desc()))
|
|
{
|
|
es = AecDbEntityBase::dwgOutFields(pFiler);
|
|
if (es != Acad::eOk)
|
|
return (es);
|
|
}
|
|
|
|
//----- Object version number needs to be saved first
|
|
if ((es = pFiler->writeUInt32(AecDbPingFaDim::kCurrentVersionNumber)) != Acad::eOk)
|
|
return (es);
|
|
|
|
m_mapSpecXData.dwgOutFields(pFiler);
|
|
|
|
|
|
return (pFiler->filerStatus());
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbPingFaDim::Draw2d(AcGiDraw &dc) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
Adesk::UInt16 iOldClr = dc.GetColor();
|
|
|
|
// 画线
|
|
dc.SetColor(3);
|
|
AcGePoint3d ptS(GetStartPoint()), ptE(ptS + GetLineDir());
|
|
dc.DrawLine(AcGeLineSeg3d(ptS, ptE));
|
|
dc.SetColor(iOldClr);
|
|
|
|
CString sAllString(GetAllText());
|
|
if (sAllString.IsEmpty()) return Acad::eOk;
|
|
std::vector<CString> texts;
|
|
CoreTools::SplitString(sAllString, _T("\r\n"), texts);
|
|
if (texts.empty()) return Acad::eOk;
|
|
|
|
// 写字
|
|
|
|
double dTextH(GetTextHeight());
|
|
dTextH *= CoreTools::getPScale();
|
|
if (CoreTools::IsMetersUnit())
|
|
dTextH *= 1000;
|
|
|
|
double dSpace(dTextH / 3);
|
|
AcGeVector3d vtTxt(GetLineDir().normalize().rotateBy(-PI * .5, AcGeVector3d::kZAxis));
|
|
vtTxt.z = .0;
|
|
AcGeVector3d vtLine(GetLineDir().normalize());
|
|
AcGePoint3d ptPos(ptE + vtTxt * dSpace);
|
|
AcDbText txt;
|
|
txt.setTextStyle(GetTextStyle());
|
|
txt.setHeight(dTextH);
|
|
double dAngle(AcGeVector3d::kXAxis.angleTo(vtTxt, AcGeVector3d::kZAxis));
|
|
txt.setRotation(dAngle);
|
|
txt.setWidthFactor(.7);
|
|
dc.SetColor(255);
|
|
ptPos -= vtLine * dTextH;
|
|
for (int i(0); i < texts.size(); ++i)
|
|
{
|
|
txt.setPosition(ptPos);
|
|
txt.setTextString(texts[i]);
|
|
dc.DrawEntity(txt);
|
|
ptPos -= vtLine * (dSpace + dTextH);
|
|
}
|
|
|
|
dc.SetColor(iOldClr);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbPingFaDim::Draw3d(AcGiDraw &dc) const
|
|
{
|
|
return Draw2d(dc);
|
|
}
|
|
|
|
AecDbObjXDataMap *AecDbPingFaDim::GetSpecialtyData(AcDb::OpenMode bMode)
|
|
{
|
|
if (bMode == AcDb::kForWrite)
|
|
AssertWriteEnabled();
|
|
else
|
|
assertReadEnabled();
|
|
|
|
return &m_mapSpecXData;
|
|
}
|
|
|
|
const AecDbObjXDataMap *AecDbPingFaDim::GetSpecialtyData() const
|
|
{
|
|
assertReadEnabled();
|
|
return &m_mapSpecXData;
|
|
}
|
|
|
|
|
|
#pragma region
|
|
CPingFaDimJig::CPingFaDimJig(void):m_pEnt(NULL), m_nStep(0), m_pBeamCurve(NULL) { }
|
|
|
|
CPingFaDimJig::~CPingFaDimJig(void) { }
|
|
|
|
AcEdJig::DragStatus CPingFaDimJig::DoIt()
|
|
{
|
|
setDispPrompt(_T("\n指定第二点:"));
|
|
return drag();
|
|
}
|
|
|
|
AcEdJig::DragStatus CPingFaDimJig::sampler()
|
|
{
|
|
setUserInputControls((UserInputControls)(AcEdJig::kAccept3dCoordinates | AcEdJig::kNullResponseAccepted));
|
|
AcEdJig::DragStatus eStat = acquirePoint(m_pt2, m_pt1);
|
|
if (m_pt1.distanceTo(m_pt2) < 1.)
|
|
return AcEdJig::kNoChange;
|
|
|
|
if (m_pBeamCurve)
|
|
{
|
|
AcGePoint3d pt(m_pt2);
|
|
m_pBeamCurve->getClosestPointTo(m_pt2, pt);
|
|
m_pt2 += m_pt1 - pt;
|
|
}
|
|
|
|
return eStat;
|
|
}
|
|
|
|
AcDbEntity *CPingFaDimJig::entity() const
|
|
{
|
|
return m_pEnt;
|
|
}
|
|
|
|
Adesk::Boolean CPingFaDimJig::update()
|
|
{
|
|
|
|
m_pEnt->SetLineDir(m_pt2 - m_pt1);
|
|
return Adesk::kTrue;
|
|
}
|
|
#pragma endregion
|