|
int seekIntersect()
{
int iErrSta = 0;
Acad::ErrorStatus es = Acad::eOk;
ads_name en;
ads_point ptRes;
iErrSta = acedEntSel( "/n请选择一条曲线:", en, ptRes );
switch( iErrSta )
{
case RTERROR:
acedAlert(_T("选择实体不成功!"));
return 1;
case RTCAN:
return 0;
}
AcDbObjectId enId1;
acdbGetObjectId( enId1, en );
AcDbEntity *pObject1;
CString strLayerName1 = _T("");
es = acdbOpenObject(pObject1, enId1, AcDb::kForWrite);
if (Acad::eOk != es) return 2;
if ( AcDbLine::desc() == pObject1->isA() )
{
strLayerName1 = pObject1 ->layer();
pObject1 ->highlight();
pObject1 ->close();
}
else
{
CString strClassName = pObject1 ->isA() ->name();
pObject1 ->close();
acedAlert(_T("选择的实体不是曲线,不能进行处理!"));
return 3;
}
iErrSta = acedEntSel("/n请选择另外一条曲线:", en, ptRes);
switch(iErrSta)
{
case RTERROR:
highlightAEntity(enId1, false);
acedAlert(_T("选择实体不成功!"));
return 4;
case RTCAN:
highlightAEntity(enId1, false);
return 0;
}
AcDbObjectId enId2;
acdbGetObjectId(enId2, en);
AcDbEntity *pObject2;
CString strLayerName2 = _T("");
es = acdbOpenObject(pObject2, enId2, AcDb::kForWrite);
if (AcDbLine::desc() == pObject2 ->isA())
{
strLayerName2 = pObject2 ->layer();
pObject2 ->highlight();
pObject2 ->close();
}
else
{
pObject2 ->close();
highlightAEntity(enId1, false);
acedAlert(_T("选择的实体不是曲线,不能进行处理!"));
return 5;
}
highlightAEntity(enId1, false);
highlightAEntity(enId2, false);
if (strLayerName1 != strLayerName2)
{
acedAlert(_T("两条曲线不在同一层上,不能进行处理!"));
return 6;
}
AcGePoint3d startPt1, startPt2, endPt1, endPt2;
AcDbLine* pLine1, *pLine2;
es = acdbOpenObject(pObject1, enId1, AcDb::kForWrite);
if (Acad::eOk != es) return 6;
if (AcDbLine::desc() == pObject1->isA())
{
pLine1 = AcDbLine::cast(pObject1);
startPt1 = pLine1 ->startPoint();
endPt1 = pLine1 ->endPoint();
if (fabs(startPt1.z) > MINIMUM || fabs(endPt1.z) > MINIMUM);
{
startPt1.z = 0;
endPt1.z = 0;
pLine1 ->setStartPoint(startPt1);
pLine1 ->setEndPoint(endPt1);
}
}
else
{
pObject1 ->close();
}
es = acdbOpenObject(pObject2, enId2, AcDb::kForWrite);
if (Acad::eOk != es)
{
pLine1 ->close();
return 7;
}
if (AcDbLine::desc() == pObject2 ->isA())
{
pLine2 = AcDbLine::cast(pObject2);
startPt2 = pLine2 ->startPoint();
endPt2 = pLine2 ->endPoint();
if (fabs(startPt2.z) > MINIMUM || fabs(endPt2.z) > MINIMUM);
{
startPt2.z = 0;
endPt2.z = 0;
pLine2 ->setStartPoint(startPt2);
pLine2 ->setEndPoint(endPt2);
}
}
else
{
pObject2 ->close();
}
AcGePoint3dArray ptArray;
pObject1 ->intersectWith( pObject2, AcDb::kExtendBoth, ptArray );
if ( 0 == ptArray.length())
{
bool bIsOnCurve = false;
pointIsOnCurve(bIsOnCurve, (AcDbCurve*)pObject2, startPt1, Adesk::kTrue);
if (bIsOnCurve)
{
AcGePoint3d tempPt;
tempPt = getClosestPt(startPt1, startPt2, endPt2);
if (isSame(startPt2, tempPt))
{
tempPt = getClosestPt(startPt2, startPt1, endPt1);
}
else
{
tempPt = getClosestPt(endPt2, startPt1, endPt1);
}
if (isSame(startPt1, tempPt))
{
pLine1 ->setStartPoint(startPt2);
}
else
{
pLine1 ->setEndPoint(startPt2);
}
}
pObject2 ->close();
pObject1 ->close();
}
else if ( 1 == ptArray.length())
{
AcGePoint3d intersectPt = ptArray[0];
AcGePoint3d tempPt = AcGePoint3d::kOrigin;
tempPt = getClosestPt(intersectPt, startPt1, endPt1);
if (isSame(startPt1, tempPt))
{
pLine1 ->setStartPoint(intersectPt);
}
else
{
pLine1 ->setEndPoint(intersectPt);
}
pLine1 ->close();
tempPt = AcGePoint3d::kOrigin;
tempPt = getClosestPt(intersectPt, startPt2, endPt2);
if (isSame(startPt2, tempPt))
{
pLine2 ->setStartPoint(intersectPt);
}
else
{
pLine2 ->setEndPoint(intersectPt);
}
pLine2 ->close();
}
return 0;
} |
|