Files
envi-code/SourceCode/Code2026/tg_shs/shs_kerncmd/EditSlab.cpp
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

166 lines
5.2 KiB
C++

#include "stdafx.h"
static int CompareInt(const int *p1, const void *p2)
{
if (*p1==*(const int *)p2)
return 0;
return 1;
}
// extern GEOAPI int FindNearestEdge(const XPoly2D &poly, const XPoint &ptEdge);
extern int SearchBalcony(XPoly2D &polyBalc, XPoly2D &polyWall, XPoly2D &polyOutline);
// Command: 平板
// 需要加前线搜索
void Poly2Slab()
{
Entity ent;
RBList rbMask(RTDXF0, _T("POLYLINE,LWPOLYLINE,CIRCLE"), NULL);
if (SelectEntity(_T("\n选择一封闭的多段线或圆<退出>:"), ent, rbMask)==RTNORM) {
XVector3D vtNormal=Ucs2Wcs(XVector3D(0,0,1), TRUE);
((AcGeVector3d &)vtNormal).normalize();
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;
}
XPoly2D polyRail(ent), poly(1);
if (!polyRail || polyRail.GetFlag()>1) {
if (ent.Is(_T("CIRCLE"))) {
XCurveSegment seg;
seg=XCircle(ent);
seg.AsPoly2D(polyRail);
} else {
adsout << _T("\n非法选择!");
return;
}
} else {
polyRail.Compress();
}
DList<int> lstEdgeIndex;
if (vtNormal.AsAcGeVector3d()==AcGeVector3d(0,0,1)) {
if (!polyRail.IsClosed()) {
XPoly2D polyWall(0);
if (SearchBalcony(polyRail, polyWall, poly)!=RTNORM)
return;
for(int n=0; n<polyWall.TotalSegments(); n++) {
XCurveSegment cvSeg;
polyWall.Nth(n, cvSeg);
XPoint ptEdge = cvSeg.MidPoint();
int nEdge=FindNearestEdge(poly, ptEdge);
if (nEdge>=0 && !lstEdgeIndex.FindNode(&nEdge, CompareInt)) {
lstEdgeIndex.Append(new int(nEdge));
}
}
} else {
poly=polyRail;
if (poly.PathArea()>0) //确保逆时针
poly.Reverse();
XScreenDc dc(1,1);
while(1) {
XPushVar<int> tVar(_T("OSMODE"), OS_NEA);
XPoint ptEdge;
int nRet=ads_getpoint(NULL, _T("\n请点取不可见的边<结束>"), ptEdge);
if (nRet==RTNONE)
break;
else if (nRet==RTCAN)
return;
ptEdge=Ucs2Wcs(ptEdge);
int nEdge=FindNearestEdge(poly, ptEdge);
if (nEdge>=0 && !lstEdgeIndex.FindNode(&nEdge, CompareInt)) {
lstEdgeIndex.Append(new int(nEdge));
XCurveSegment seg;
poly.Nth(nEdge, seg);
seg.StartPoint()=Wcs2Ucs(seg.StartPoint());
seg.EndPoint()=Wcs2Ucs(seg.EndPoint());
dc << seg;
}
}
}
} else {
poly=polyRail;
poly.SetFlag(1);
if (poly.PathArea()>0) //确保逆时针
poly.Reverse();
}
PickSet ssHoles(SS_FREE);
RBList rbHoleMask=GetClosedCurveMask();
const TCHAR *szPrompt[2]={_T("选择作为板内洞口的封闭的多段线或圆:"), _T("移除已选的多段线或圆")};
int nRet=ssHoles.Get(_T(":$"), szPrompt, NULL, rbHoleMask);
if (nRet==RTCAN)
return;
ssHoles -= ent; //排除外边界线
static double nThickness=200;
if (GetDist(_T("\n板厚(负值表示向下生成)"), nThickness)==RTCAN)
return;
TDbSlab *pStep = new TDbSlab;
pStep->SetOutline(poly);
pStep->SetThickness(nThickness);
for(int i=0; i<lstEdgeIndex.Length(); i++)
pStep->SetVisibilityAt(*lstEdgeIndex[i], FALSE);
if (nRet==RTNORM) {
long len=ssHoles.Length();
for(long idx=0L; idx<len; idx++) {
Entity entHole=ssHoles[idx];
XPoly2D polyHole(entHole);
if (!polyHole) {
if (entHole.Is(_T("CIRCLE"))) {
XCurveSegment segTemp(entHole);
segTemp.AsPoly2D(polyHole);
} else
continue;
}
pStep->AddHole(polyHole);
}
}
int bDelObj;
VERIFY(xg_getvar(_T("DELOBJ"), &bDelObj)==RTNORM);
if (bDelObj) {
ent.Delete();
ssHoles.Delete();
}
pStep->SetNormal(vtNormal);
pStep->AddToMSpace(Adesk::kTrue);
}
}
// Command: 竖板
void VertSlab()
{
XPoint ptStart, ptEnd;
if (XGetPoint(NULL, _T("\n起点"), ptStart)==RTNORM &&
XGetPoint(ptStart, _T("\n终点"), ptEnd)==RTNORM &&
GetReal(_T("\n起点标高"), ptStart.z)!=RTCAN &&
GetReal(_T("\n终点标高"), ptEnd.z)!=RTCAN) {
double hs=1000;
if (GetReal(_T("\n起边高度"), hs)==RTCAN)
return;
double he=hs;
if (GetReal(_T("\n终边高度"), he)==RTCAN)
return;
static double nThick=200;
if (GetReal(_T("\n板厚"), nThick, RSG_NONEG|RSG_NOZERO)==RTCAN)
return;
int bShow2d=YesNoQuestion(_T("\n是否显示二维竖板"), Q_YES);
if (bShow2d==RTCAN)
return;
TDbVertSlab *pStep = new TDbVertSlab;
pStep->SetStartPoint(Ucs2Wcs(ptStart));
pStep->SetEndPoint(Ucs2Wcs(ptEnd));
pStep->SetHeightS(hs);
pStep->SetHeightE(he);
pStep->SetThickness(nThick);
pStep->Set2DVisible(bShow2d==Q_YES);
pStep->AddToMSpace(Adesk::kTrue);
}
}