Files
envi-code/SourceCode/Code2026/tg_shs/shs_kerncmd/zhouComponent1.cpp
T

486 lines
14 KiB
C++
Raw Normal View History

2026-10-04 00:04:20 +08:00
#include "stdafx.h"
2026-09-28 15:28:50 +08:00
void myHandrail() {
// XPushVar<int> vOsMode(_T("OSMODE"), 0);
PickSet ss(SS_FREE);
g_ssPickFirst.Free();
RBList mask(RTDXF0, _T("TCH_HANDRAIL"), NULL);
2026-10-04 00:04:20 +08:00
if (SelectEntities(_T("\n选择待连接的扶手(注意与顶点顺序一致): "), ss, mask)!=RTNORM) return;
2026-09-28 15:28:50 +08:00
AcDbObjectId idHandRail;
Entity ent;
XPoint myPoint;
XPointList myPointList;
Adesk::UInt8 myAlignment=1;
XPoly2D myPolyPath;
long lCount=ss.Length();
for(long i=0L; i<lCount; i++) {
XPoly2D polyPath;
AcGeVector3d normal;
ent=ss[i];
VERIFY(acdbGetObjectId(idHandRail, ent.name)==Acad::eOk);
OPENOBJ_BEGIN(idHandRail, AcDb::kForRead, TDbHandRail, pHandRail);
ASSERT(pHandRail);
pHandRail->GetPathPoly(polyPath,normal);
myAlignment=pHandRail->GetAlignment();
OPENOBJ_END();
/*
long l=polyPath.Length();
XPoint firstPt=*polyPath[0L], lastPt=*polyPath[l-1];
if (firstPt[2] < lastPt[2])
for (long j=0L; j<l; j++) {
myPoint=*polyPath[j];
myPointList.NewAppend(myPoint);
}
else
for (long j=l-1; j>=0L; j--) {
myPoint=*polyPath[j];
myPointList.NewAppend(myPoint);
}*/
if (!myPolyPath)
myPolyPath=polyPath;
else {
if (myPolyPath.Tail()->Distance(*polyPath.Head())>myPolyPath.Tail()->Distance(*polyPath.Tail()))
polyPath.Reverse();
for(int kk=0; kk<polyPath.Length(); kk++) {
myPolyPath.AppendNode(*polyPath[kk], polyPath.GetBulge(kk));
}
}
}
//myPointList.AsPoly2D(myPolyPath);
//TDbHandRail *pHandRail = new TDbHandRail;
//pHandRail->SetPathPoly(myPolyPath);
//pHandRail->SetAlignment(myAlignment);
//pHandRail->AddToMSpace(Adesk::kTrue);
Entity eFirst=ss[0L];
OPENOBJ_BEGIN(eFirst, AcDb::kForWrite, TDbHandRail, pHand);
if (pHand) {
pHand->SetPathPoly(myPolyPath,pHand->GetNormal().AsAcGeVector3d());
}
OPENOBJ_END();
ss -= eFirst;
ss.Erase();
}
void myStair() {
// XPushVar<int> vOsMode(_T("OSMODE"), 512);
Entity ent;
XPoint pickPt;
RBList mask(RTDXF0, _T("TCH_LINESTAIR,TCH_ARCSTAIR,TCH_CURVESTAIR"), NULL);
2026-10-04 00:04:20 +08:00
if (SelectEntity(_T("\n选择梯段: "), ent, pickPt, mask)!=RTNORM) return;
2026-09-28 15:28:50 +08:00
pickPt=Ucs2Wcs(pickPt);
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;
}
else {
//mySide2.AsPoly2D(myPolyPath);
myAlignment=2;
cv=mySide2;
}
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->AddToMSpace(Adesk::kTrue);
PickSet ss(SS_FREE);
ss += ent;
UpdateGraphic(ss);
}
enum myFlag {
kRectangle=1, // Rectangle
kCircle=2, // Circle
};
static myFlag g_typ;
static XPoint g_pt;
static double g_nRot;
static XPoly2D g_poly;
static void GetPoly(myFlag typ, const XPoint &pt1, const XPoint &pt2, XPoly2D &poly)
{
poly.Reset();
poly.SetFlag(1);
switch (typ) {
case kRectangle: {
XPoint p1, p2;
XLine lnSide1(pt1, g_nRot);
XLine lnSide2(pt2, g_nRot+PI/2.0);
lnSide1.Intersection(&lnSide2, p1);
XLine lnSide3(pt1, g_nRot+PI/2.0);
XLine lnSide4(pt2, g_nRot);
lnSide3.Intersection(&lnSide4, p2);
poly.AppendNode(pt1);
poly.AppendNode(p1);
poly.AppendNode(pt2);
poly.AppendNode(p2);
}
break;
case kCircle: {
XCurveSegment seg;
seg=XCircle(pt1, pt1.Distance(pt2));
seg.AsPoly2D(poly);
}
break;
}
}
static BOOL myMouseMoveMonitor(MSG* msg)
{
if (!acdbCurDwg())
return FALSE;
BOOL bRet=FALSE;
switch(msg->message) {
case WM_MOUSEMOVE: {
CPoint ptClient=msg->pt;
acedGetAcadDwgView()->ScreenToClient(&ptClient);
int nVpNum=acedGetWinNum(ptClient.x, ptClient.y);
int nCurVp=0;
VERIFY(xg_getvar(_T("CVPORT"), &nCurVp)==RTNORM);
if (nVpNum==nCurVp) {
XPoint ptDwgWcs, ptDwgDcs;
BOOL nRetCode=TRUE;
if (acedCoordFromPixelToWorld(nVpNum, ptClient, ptDwgWcs)) {
XScreenDc dc(-1);
if (g_poly.Length())
dc << g_poly;
XPoint ptDwgUcs=Wcs2Ucs(ptDwgWcs);
ptDwgUcs.z=g_pt.z;
GetPoly(g_typ, g_pt, ptDwgUcs, g_poly);
dc << g_poly;
}
}
}
break;
default: break;
}
return bRet;
}
int XGetPoints(const XPoint &pt1, const TCHAR *pszMsg, myFlag typ, XPoint &pt2)
{
if (pszMsg)
adsout << pszMsg;
g_poly.Reset();
g_poly.SetFlag(1);
g_typ=typ;
g_nRot=0.0;
g_pt=pt1;
acedRegisterFilterWinMsg(myMouseMoveMonitor);
int nRet=ads_getpoint(NULL, _T(""), pt2);
acedRemoveFilterWinMsg(myMouseMoveMonitor);
g_poly.Reset();
ads_redraw(NULL,0);
return nRet;
}
int myGetClipBoundary1(XPoly2D &poly2d)
{
XPoint ptStart;
2026-10-04 00:04:20 +08:00
adsout << _T("\n矩形的第一个角点或 [圆形裁剪(C)/多边形裁剪(P)/多段线定边界(L)/图块定边界(B)]<退出>:");
2026-09-28 15:28:50 +08:00
int nCode;
INITGET_BEG(0, _T("C P L B"));
nCode=ads_getpoint(NULL, _T(""), ptStart);
INITGET_END();
if (nCode!=RTKWORD && nCode!=RTNORM)
return nCode;
XScreenDc dc;
dc.m_nDrawMode=1;
if (nCode==RTNORM) {
XPoint ptOther;
2026-10-04 00:04:20 +08:00
int nCode=XGetPoints(ptStart, _T("\n另一个角点<退出>:"), kRectangle, ptOther);
2026-09-28 15:28:50 +08:00
if (nCode!=RTNORM)
return nCode;
XRectAngle rect(ptStart, ptOther);
rect.AsPoly2D(poly2d);
dc << poly2d;
} else {
nCode=RTNORM;
XString sKey;
ads_getinput(sKey);
if (sKey[0]==_T('C')) {
2026-10-04 00:04:20 +08:00
int nCode=ads_getpoint(NULL, _T("\n圆心点<退出>:"), ptStart);
2026-09-28 15:28:50 +08:00
if (nCode!=RTNORM)
return nCode;
XPoint ptOther;
2026-10-04 00:04:20 +08:00
nCode=XGetPoints(ptStart, _T("\n半径点<退出>:"), kCircle, ptOther);
2026-09-28 15:28:50 +08:00
if (nCode!=RTNORM)
return nCode;
XCurveSegment seg;
seg=XCircle(ptStart, ptStart.Distance(ptOther));
seg.AsPoly2D(poly2d);
dc << poly2d;
} else if (sKey[0]==_T('P')) {
2026-10-04 00:04:20 +08:00
if (ads_getpoint(NULL, _T("\n多边形起点<退出>:"), ptStart)!=RTNORM)
2026-09-28 15:28:50 +08:00
return RTERROR;
XPoint pt2;
DStack<XPoint> aStack;
aStack.Push(new XPoint(ptStart));
while(1) {
XPoint &ptFrom=*aStack.Top();
if (aStack.Length()>=3)
2026-10-04 00:04:20 +08:00
adsout << _T("\n下一点或 [回退(U)]<封闭>: ");
2026-09-28 15:28:50 +08:00
else
2026-10-04 00:04:20 +08:00
adsout << _T("\n下一点或 [回退(U)]<退出>: ");
2026-09-28 15:28:50 +08:00
int rc;
INITGET_BEG(0, _T("U"));
rc=ads_getpoint(ptFrom, _T(""), pt2);
INITGET_END();
if (rc==RTCAN) {
aStack.Reset();
return rc;
} else if (rc==RTKWORD) {
if (*aStack.Top() != ptStart) {// Not on first state
XPoint *pPt2 = aStack.Pop();
XPoint *pPt1 = aStack.Top();
dc.SetColor(-1);
dc << XLine(*pPt1, *pPt2);
delete pPt2;
}
} else {
if (rc==RTNONE) {
if (aStack.Length()<3)
return RTERROR;
else
pt2=ptStart;
}
XLine ln(*aStack.Top(), pt2);
if (ln.GetLength()>_DIST_SNAP) {
dc.SetColor(7);
dc << ln;
if (!(rc==RTNONE))
aStack.Push(new XPoint(pt2));
else break;
}
}
}
poly2d.Reset();
XPoint *ptCur=NULL;
while((ptCur=aStack.Pop())!=NULL) {
poly2d.AppendNode(*ptCur);
delete ptCur;
}
} else if (sKey[0]==_T('L')) {
Entity entFront;
2026-10-04 00:04:20 +08:00
if (SelectEntity(_T("\n请选择封闭的多段线作为裁剪边界<退出>: "), entFront, RBList(RTDXF0, _T("POLYLINE,LWPOLYLINE"), 70, 1, NULL)) != RTNORM)
2026-09-28 15:28:50 +08:00
return RTERROR;
poly2d=XPoly2D(entFront);
poly2d.TransUCS(Groups(0), Groups(1));
dc << poly2d;
} else if (sKey[0]==_T('B')) {
Entity entFront;
2026-10-04 00:04:20 +08:00
if (SelectEntity(_T("\n请选择图块作为裁剪边界<退出>: "), entFront, RBList(RTDXF0, _T("INSERT,TCH_BLOCK_INSERT,TCH_MVINSERT"), NULL)) != RTNORM)
2026-09-28 15:28:50 +08:00
return RTERROR;
if (GetBoundaryFromInsert2D(entFront, poly2d)!=RTNORM) {
2026-10-04 00:04:20 +08:00
adsout << _T("\n无法搜到图块的边界!");
2026-09-28 15:28:50 +08:00
return RTERROR;
}
poly2d.TransUCS(Groups(0), Groups(1));
dc << poly2d;
2026-10-04 00:04:20 +08:00
int nAnser=YesNoQuestion(_T("\n系统确定的图块轮廓线是否正确"));
2026-09-28 15:28:50 +08:00
if (nAnser!=Q_YES) {
2026-10-04 00:04:20 +08:00
adsout << _T("\n请用其他方法确定裁剪边界!");
2026-09-28 15:28:50 +08:00
return RTERROR;
}
}
}
poly2d.Compress();
if (!poly2d || poly2d.Length()<2)
return RTERROR;
return RTNORM;
}
static BOOL myDelete=FALSE;
void addHatch(AcDbObjectId hatchId) {
XPoly2D poly2d;
if (myGetClipBoundary1(poly2d)!=RTNORM) return;
if (myDelete)
poly2d.Make();
OPENOBJ_BEGIN(hatchId, AcDb::kForWrite, AcDbHatch, pHatch);
pHatch->setAssociative(Adesk::kFalse);
AcGePoint2dArray vertices;
AcGeDoubleArray bulges;
int len=poly2d.Length();
vertices.setLogicalLength(len+1);
bulges.setLogicalLength(len+1);
AcDbPolyline pline(len);
PolyConvert(poly2d,pline);
AcGePoint3d p;
pline.getPointAt(0,p);
vertices[0].set(p.x,p.y);
vertices[len].set(p.x,p.y);
double b;
pline.getBulgeAt(0,b);
bulges[0]=b;
bulges[len]=b;
for (int i=1;i<len;i++) {
pline.getPointAt(i,p);
vertices[i].set(p.x,p.y);
pline.getBulgeAt(i,b);
bulges[i]=b;
}
pHatch->appendLoop(AcDbHatch::kOutermost,vertices,bulges);
pHatch->evaluateHatch();
OPENOBJ_END();
}
void removeHatch(AcDbObjectId hatchId) {
XPoint pt;
XPushVar<int> vOsMode(_T("OSMODE"), 0);
2026-10-04 00:04:20 +08:00
if (acedGetPoint(NULL,_T("\n选取边界区域内的点<退出>: "),pt)!=RTNORM) return;
2026-09-28 15:28:50 +08:00
OPENOBJ_BEGIN(hatchId, AcDb::kForWrite, AcDbHatch, pHatch);
pHatch->setAssociative(Adesk::kFalse);
int num=pHatch->numLoops();
for (int i=0;i<num;i++) {
Adesk::Int32 typ;
AcGePoint2dArray vertices;
AcGeDoubleArray bulges;
pHatch->getLoopAt(i,typ,vertices,bulges);
if (!(typ & AcDbHatch::kExternal)) {
int len=vertices.length();
BOOL flag2=bulges.length()>0;
XPoly2D boundary;
for (int j=0;j<len;j++) {
XPoint p(vertices[j].x,vertices[j].y,0.0);
double b=0.0;;
if (flag2) b=4*atan(bulges[j]);
boundary.AppendNode(p,b);
}
boundary.Compress();
boundary.SetFlag(1);
// boundary.Make();
if ((pt & boundary)==PR_INSIDE) {
pHatch->removeLoopAt(i);
break; // ZJQ add here
}
}
}
pHatch->evaluateHatch();
OPENOBJ_END();
}
void myHatch() {
Entity ent;
RBList mask(RTDXF0, _T("HATCH"), NULL);
2026-10-04 00:04:20 +08:00
if (SelectEntity(_T("\n请选择图案填充<退出>: "),ent,mask)!=RTNORM) return;
2026-09-28 15:28:50 +08:00
AcDbObjectId hatchId;
acdbGetObjectId(hatchId, ent);
2026-10-04 00:04:20 +08:00
adsout << _T("\nAdd[A]/Remove[R]<退出>:");
2026-09-28 15:28:50 +08:00
int nCode;
XString sKey;
INITGET_BEG(0, _T("A R C"));
nCode=acedGetKword(NULL, sKey);
INITGET_END();
if (nCode!=RTKWORD && nCode!=RTNORM) return;
if (sKey[0]==_T('A'))
addHatch(hatchId);
else if (sKey[0]==_T('R'))
removeHatch(hatchId);
}
void addHatch()
{
Entity ent;
RBList mask(RTDXF0, _T("HATCH"), NULL);
2026-10-04 00:04:20 +08:00
if (SelectEntity(_T("\n请选择图案填充<退出>: "),ent,mask)!=RTNORM) return;
2026-09-28 15:28:50 +08:00
AcDbObjectId hatchId;
acdbGetObjectId(hatchId, ent);
addHatch(hatchId);
}
void removeHatch()
{
Entity ent;
RBList mask(RTDXF0, _T("HATCH"), NULL);
2026-10-04 00:04:20 +08:00
if (SelectEntity(_T("\n请选择图案填充<退出>: "),ent,mask)!=RTNORM) return;
2026-09-28 15:28:50 +08:00
AcDbObjectId hatchId;
acdbGetObjectId(hatchId, ent);
removeHatch(hatchId);
}