312 lines
8.2 KiB
C++
312 lines
8.2 KiB
C++
#include "stdafx.h"
|
|
#include "HandRailDlg.h"
|
|
#include "RailDlg.h"
|
|
#include "CurveMeshDlg.h"
|
|
|
|
void MakeStairHand(Entity ent, XPoint pickPt, double nRailWidth, double nRailHeight, double nOffset)
|
|
{
|
|
AcDbObjectId id;
|
|
acdbGetObjectId(id, ent);
|
|
AcDbEntity *pEnt=NULL;
|
|
acdbOpenObject(pEnt, id, AcDb::kForRead);
|
|
// pEnt->highlight(kNullSubent);
|
|
TDbStair *pStair;
|
|
pStair=TDbStair::cast(pEnt);
|
|
if (!pStair) {
|
|
pEnt->close();
|
|
return;
|
|
}
|
|
|
|
XDirectionCurve mySide1,mySide2;
|
|
XCurveSegment myCurve1,myCurve2;
|
|
mySide1=pStair->GetSideCurve2d(0);
|
|
myCurve1=mySide1.GetCurve();
|
|
mySide2=pStair->GetSideCurve2d(1);
|
|
myCurve2=mySide2.GetCurve();
|
|
XPoint myPt1,myPt2;
|
|
myCurve1.ProjectToMe(pickPt,myPt1);
|
|
myCurve2.ProjectToMe(pickPt,myPt2);
|
|
|
|
XPoly2D myPolyPath;
|
|
Adesk::UInt8 myAlignment;
|
|
XDirectionCurve cv;
|
|
if (myPt1.Distance2d(pickPt) < myPt2.Distance2d(pickPt)) {
|
|
//mySide1.AsPoly2D(myPolyPath);
|
|
myAlignment=1;
|
|
cv=mySide1.Offset(nOffset+nRailWidth/2, LS_FINITE);
|
|
}
|
|
else {
|
|
//mySide2.AsPoly2D(myPolyPath);
|
|
myAlignment=2;
|
|
cv=mySide2.Offset(-nOffset-nRailWidth/2, LS_FINITE);
|
|
}
|
|
|
|
XPoint ptStart=cv.StartPoint();
|
|
ptStart.z=pStair->GetElevation();
|
|
XPoint ptEnd=cv.EndPoint();
|
|
ptEnd.z=pStair->GetElevation()+pStair->GetStairHeight();
|
|
|
|
TDbHandRail *pHandRail = new TDbHandRail;
|
|
//pHandRail->SetAlignment(myAlignment);
|
|
int nFlag2d=pStair->Get2DFlag();
|
|
if (nFlag2d==SF_NO2D)
|
|
pHandRail->SetHas2D(FALSE);
|
|
else
|
|
pHandRail->SetHas2D(TRUE);
|
|
int nFlag3d=pStair->Get3DFlag();
|
|
if (nFlag3d&SF_HAS3D)
|
|
pHandRail->SetHas3D(TRUE);
|
|
else
|
|
pHandRail->SetHas3D(FALSE);
|
|
double nStepWidth=cv.GetLength()/(pStair->GetStepNum()-1);
|
|
if (nFlag2d==SF_1SECT) {
|
|
XPointDir2d ptDir;
|
|
cv.Polar(nStepWidth/2, ptDir);
|
|
ptStart=XPoint(ptDir.x, ptDir.y, ptStart.z+pStair->GetStepHeight());
|
|
} else {
|
|
XPointDir2d ptDir;
|
|
cv.Polar(-nStepWidth/2, ptDir);
|
|
ptStart=XPoint(ptDir.x, ptDir.y, ptStart.z);
|
|
}
|
|
{
|
|
XPointDir2d ptDir;
|
|
cv.Polar(-nStepWidth/2, ptDir, FALSE);
|
|
ptEnd=XPoint(ptDir.x, ptDir.y, ptEnd.z);
|
|
}
|
|
pStair->close();
|
|
//*myPolyPath.Head()=ptStart;
|
|
//*myPolyPath.Tail()=ptEnd;
|
|
cv.SetPoints(ptStart, ptEnd);
|
|
cv.AsPoly2D(myPolyPath);
|
|
myPolyPath.Head()->z=ptStart.z;
|
|
myPolyPath.Tail()->z=ptEnd.z;
|
|
pHandRail->SetPathPoly(myPolyPath,pHandRail->GetNormal().AsAcGeVector3d());
|
|
pHandRail->SetWidth(nRailWidth);
|
|
pHandRail->SetHeight(nRailHeight);
|
|
pHandRail->AddToMSpace(Adesk::kTrue);
|
|
|
|
|
|
PickSet ss(SS_FREE);
|
|
ss += ent;
|
|
UpdateGraphic(ss);
|
|
}
|
|
|
|
// Command: 扶手
|
|
void Poly2Rail()
|
|
{
|
|
Entity ent;
|
|
RBList rbMask(RTDXF0, _T("LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,TCH_LINESTAIR,TCH_ARCSTAIR,TCH_CURVESTAIR"), NULL);
|
|
XPoint ptPick;
|
|
if (SelectEntity1(_T("\n请选择梯段或作为路径的曲线(线/弧/圆/多段线):"), ent, ptPick, rbMask)==RTNORM) {
|
|
XVector3D vtNormal=XVector3D(0,0,1);
|
|
AcDbObjectId idBind;
|
|
ptPick=Ucs2Wcs(ptPick);
|
|
BOOL bStair=FALSE;
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbStair, pPathEnt);
|
|
if (pPathEnt) {
|
|
bStair=TRUE;
|
|
/*
|
|
if (vtNormal.AsAcGeVector3d()!=pPathEnt->GetNormal().AsAcGeVector3d()) {
|
|
adsout << _T("\n当前构造平面不在WCS的XY平行的平面上!");
|
|
return;
|
|
}
|
|
idBind=pPathEnt->objectId();
|
|
*/
|
|
} else {
|
|
XVector3D vtPoly(0,0,1);
|
|
if (ent.GetData(210, &vtPoly)!=RTNORM)
|
|
vtPoly=XVector3D(0,0,1);
|
|
if (vtPoly.AsAcGeVector3d()!=vtNormal.AsAcGeVector3d()) {
|
|
adsout << _T("\n所选对象的构造平面与当前构造平面不平行!");
|
|
return;
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
ent.Redraw(3);
|
|
static double nRailWidth=60;
|
|
static double nRailHeight=900;
|
|
if (GetDist(_T("\n扶手宽度"), nRailWidth, RSG_NOZERO|RSG_NONEG)==RTCAN ||
|
|
GetDist(_T("\n扶手顶面高度"), nRailHeight, RSG_NOZERO|RSG_NONEG)==RTCAN) {
|
|
ent.Redraw(4);
|
|
return;
|
|
}
|
|
|
|
if (bStair) {
|
|
static double nOffset=0.0;
|
|
if (GetReal(_T("\n扶手距边"), nOffset, 0)!=RTCAN) {
|
|
MakeStairHand(ent, ptPick, nRailWidth, nRailHeight, nOffset);
|
|
}
|
|
} else {
|
|
XPoly2D polyRail(ent);
|
|
if (!polyRail) {
|
|
if (polyRail.GetFlag()>1)
|
|
return;
|
|
else if (ent.Is(_T("LINE")) || ent.Is(_T("ARC")) || ent.Is(_T("CIRCLE"))) {
|
|
XCurveSegment seg(ent);
|
|
polyRail.Reset();
|
|
seg.AsPoly2D(polyRail);
|
|
} else
|
|
return;
|
|
}
|
|
if (polyRail.IsClosed()) {
|
|
AS_OPENPOLY(polyRail);
|
|
}
|
|
|
|
|
|
Adesk::UInt8 nAlign=AL_CENTER;
|
|
XString sKeyword;
|
|
int nRetCode;
|
|
INITGET_BEG(0, _T("M L R"));
|
|
nRetCode=ads_getkword(_T("\n输入对齐方式[中间对齐(M)/左边对齐(L)/右边对齐(R)]<M>:"), sKeyword);
|
|
INITGET_END();
|
|
ent.Redraw(4);
|
|
if (nRetCode==RTCAN)
|
|
return;
|
|
if (nRetCode==RTNORM) {
|
|
if (sKeyword[0]==_T('M'))
|
|
nAlign=0;
|
|
else if (sKeyword[0]==_T('L'))
|
|
nAlign=1;
|
|
else
|
|
nAlign=2;
|
|
//nAlign=_ttoi(sKeyword);
|
|
}
|
|
|
|
int bDelObj;
|
|
VERIFY(xg_getvar(_T("DELOBJ"), &bDelObj)==RTNORM);
|
|
if (bDelObj)
|
|
ent.Delete();
|
|
|
|
TDbHandRail *pStep = new TDbHandRail;
|
|
pStep->SetWidth(nRailWidth);
|
|
pStep->SetHeight(nRailHeight);
|
|
pStep->SetAlignment(nAlign);
|
|
pStep->AddToMSpace(Adesk::kFalse);
|
|
if (!idBind) {
|
|
pStep->SetOutline(polyRail);
|
|
} else {
|
|
if (pStep->SetBindObject(idBind)!=Acad::eOk)
|
|
pStep->erase(Adesk::kTrue);
|
|
pStep->close();
|
|
}
|
|
|
|
pStep->UpdateHitObjects();
|
|
pStep->close();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Command: 栏杆
|
|
// 必须在WCS
|
|
void Rail()
|
|
{
|
|
CAcModuleResourceOverride vTemp;
|
|
|
|
CRailDlg dlg;
|
|
|
|
AsureWCS();
|
|
RBList rbMask1(RTDXF0, _T("LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,TCH_*"), NULL);
|
|
Entity ent1;
|
|
if (SelectEntity(_T("\n请选择作为路径的曲线(线/弧/圆/多段线)或可绑定对象(路径曲面/扶手/坡屋顶):"), ent1, rbMask1)==RTNORM) {
|
|
XVector3D vtNormal=XVector3D(0,0,1);
|
|
AcDbObjectId idBind;
|
|
|
|
//modified by whl on 060224
|
|
OPENOBJ_BEGIN(ent1, AcDb::kForRead, AcDbEntity, pEnt);
|
|
if (pEnt==NULL)
|
|
return;
|
|
|
|
if (pEnt->isKindOf(TDbPolyCurveEnt::desc())||pEnt->isKindOf(TDbPolyPathEnt::desc()))
|
|
{
|
|
TEntityBase *pPathEnt=TEntityBase::Cast(pEnt);
|
|
XPoly2D poly;
|
|
AcGeVector3d vt;
|
|
pPathEnt->GetPathPoly(poly,vt);
|
|
if (vtNormal.AsAcGeVector3d()!=vt)
|
|
{
|
|
adsout << _T("\n当前构造平面不在WCS的XY平行的平面上!");
|
|
return;
|
|
}
|
|
idBind=pEnt->objectId();
|
|
}
|
|
else
|
|
{
|
|
XVector3D vtPoly(0,0,1);
|
|
if (ent1.GetData(210, &vtPoly)!=RTNORM)
|
|
vtPoly=XVector3D(0,0,1);
|
|
if (vtPoly.AsAcGeVector3d()!=vtNormal.AsAcGeVector3d())
|
|
{
|
|
adsout << _T("\n所选对象的构造平面与当前构造平面不平行!");
|
|
return;
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
//OPENOBJ_BEGIN(ent1, AcDb::kForRead, TDbPolyPathEnt, pPathEnt);
|
|
//if (pPathEnt) {
|
|
// if (vtNormal.AsAcGeVector3d()!=pPathEnt->GetNormal().AsAcGeVector3d()) {
|
|
// adsout << _T("\n当前构造平面不在WCS的XY平行的平面上!");
|
|
// return;
|
|
// }
|
|
// idBind=pPathEnt->objectId();
|
|
//} else {
|
|
// XVector3D vtPoly(0,0,1);
|
|
// if (ent1.GetData(210, &vtPoly)!=RTNORM)
|
|
// vtPoly=XVector3D(0,0,1);
|
|
// if (vtPoly.AsAcGeVector3d()!=vtNormal.AsAcGeVector3d()) {
|
|
// adsout << _T("\n所选对象的构造平面与当前构造平面不平行!");
|
|
// return;
|
|
// }
|
|
//}
|
|
//OPENOBJ_END();
|
|
|
|
static BOOL bDelPoly = TRUE;
|
|
|
|
ent1.Redraw(3);
|
|
|
|
dlg.SelectPickcell();
|
|
|
|
dlg.m_nAlignment = 0;
|
|
dlg.m_bDelPoly = bDelPoly;
|
|
dlg.m_bAutoExpand = FALSE;
|
|
double nInitDist=0.0;
|
|
dlg.m_csInitDist = (const TCHAR *)Dist2Str(nInitDist);
|
|
dlg.m_idBind = idBind;
|
|
dlg.m_ent = ent1;
|
|
ent1.Redraw(4);
|
|
if (dlg.DoModal() != IDOK){
|
|
return;
|
|
}
|
|
bDelPoly = dlg.m_bDelPoly;
|
|
|
|
}
|
|
}
|
|
/////////////////////////////////////////////
|
|
// Command: 构造路径曲面
|
|
void CurveMesh()
|
|
{
|
|
CAcModuleResourceOverride vTemp;
|
|
static BOOL bDelCell = TRUE, bDelCurve = TRUE;
|
|
CCurveMeshDlg dlg;
|
|
dlg.m_bDelCell = bDelCell;
|
|
dlg.m_bDelCurve = bDelCurve;
|
|
if (dlg.DoModal() != IDOK)
|
|
return;
|
|
bDelCell = dlg.m_bDelCell;
|
|
bDelCurve = dlg.m_bDelCurve;
|
|
}
|
|
// 编辑扶手
|
|
int EditHandRail(AcDbObjectId id)
|
|
{
|
|
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbHandRail, pStep);
|
|
if (!pStep)
|
|
return RTERROR;
|
|
CHandRailDlg dlg(pStep);
|
|
{
|
|
CAcModuleResourceOverride vTemp;
|
|
if (dlg.DoModal() != IDOK)
|
|
return RTERROR;
|
|
}
|
|
OPENOBJ_END();
|
|
return RTNORM;
|
|
}
|