119 lines
3.2 KiB
C++
119 lines
3.2 KiB
C++
#include "stdafx.h"
|
|
|
|
int XOsEnd(XPoint &ptPick, DList<XCurveSegment> &lstCurves)
|
|
{
|
|
for(int i=0; i<lstCurves.Length(); i++) {
|
|
XCurveSegment &curve=*lstCurves[i];
|
|
if(curve.OSnap(OS_END, ptPick))
|
|
return OS_END;
|
|
}
|
|
return OS_NON;
|
|
}
|
|
|
|
int XOsMid(XPoint &ptPick, DList<XCurveSegment> &lstCurves)
|
|
{
|
|
for(int i=0; i<lstCurves.Length(); i++) {
|
|
XCurveSegment &curve=*lstCurves[i];
|
|
if(curve.OSnap(OS_MID, ptPick))
|
|
return OS_MID;
|
|
}
|
|
return OS_NON;
|
|
}
|
|
|
|
|
|
int XOsInt(XPoint &ptPick, DList<XCurveSegment> &lstCurves)
|
|
{
|
|
int len=lstCurves.Length();
|
|
for(int i=0; i<len; i++) {
|
|
XCurveSegment &curve1=*lstCurves[i];
|
|
for(int j=i+1; j<len; j++) {
|
|
XCurveSegment &curve2=*lstCurves[j];
|
|
XPoint pt1, pt2;
|
|
int nInt=curve1.Intersection(curve2, pt1, pt2);
|
|
if(nInt==1) {
|
|
ptPick=pt1;
|
|
return OS_INT;
|
|
} else if(nInt==2) {
|
|
ptPick = XLine(pt1,pt2).NearPoint(ptPick);
|
|
return OS_INT;
|
|
}
|
|
}
|
|
}
|
|
return OS_NON;
|
|
}
|
|
|
|
|
|
int XOsNea(XPoint &ptPick, DList<XCurveSegment> &lstCurves)
|
|
{
|
|
for(int i=0; i<lstCurves.Length(); i++) {
|
|
XCurveSegment &curve=*lstCurves[i];
|
|
if(curve.OSnap(OS_NEA, ptPick))
|
|
return OS_NEA;
|
|
}
|
|
return OS_NON;
|
|
}
|
|
|
|
|
|
int XOsnap(XPoint &ptPick, int nMode, DList<XCurveSegment> &ss)
|
|
{
|
|
switch(nMode) {
|
|
case OS_END: return XOsEnd(ptPick, ss);
|
|
case OS_MID: return XOsMid(ptPick, ss);
|
|
case OS_INT: return XOsInt(ptPick, ss);
|
|
case OS_NEA: return XOsNea(ptPick, ss);
|
|
}
|
|
return OS_NON;
|
|
}
|
|
|
|
|
|
|
|
// return: the mode has been use
|
|
// Now:
|
|
// ptPick1(WCS) -- both IN/OUT
|
|
// mask--support LINE,ARC,CIRCLE
|
|
// mode--support END, MID, INT, NEA
|
|
// nHalfSize--The aperture half size, when <=0, use last size
|
|
// bInsideAperture -- Make sure the Osnap point must inside the aperture
|
|
// bPrio -- 0 Descendent mode, 1 Ascendent
|
|
TUTIL_IMPEXP int XOsnap(XPoint &ptPick1, int nMode, const RBList &rbMask, ads_real nHalfSize, int bInsideAperture, int bPrior)
|
|
{
|
|
static ads_real nHalfAperture=10.0;
|
|
if(nHalfSize>0.0) nHalfAperture=nHalfSize;
|
|
XPoint ptPick=ptPick1;
|
|
XPoint ptLow=Wcs2Ucs(ptPick)-XPoint(nHalfAperture, nHalfAperture),
|
|
ptUp=Wcs2Ucs(ptPick)+XPoint(nHalfAperture, nHalfAperture);
|
|
PickSet ss(SS_FREE);
|
|
if(ss.Get(_T("C"), ptLow, ptUp, rbMask)!=RTNORM)
|
|
return OS_NON;
|
|
|
|
DList<XCurveSegment> lstCurves;
|
|
long ssLen=ss.Length();
|
|
for(long n=0; n<ssLen; n++) {
|
|
Entity ent=ss[n];
|
|
XCurveSegment *seg=new XCurveSegment(ent, LS_FINITE);
|
|
if(!(*seg)) {
|
|
delete seg;
|
|
} else {
|
|
lstCurves.Append(seg);
|
|
}
|
|
}
|
|
|
|
XRectAngle boxTarget(ptLow, ptUp);
|
|
int nModeArray[]={OS_END, OS_MID, OS_INT, OS_NEA};
|
|
int nIndex=bPrior? 0:(ELEMENTS(nModeArray)-1);
|
|
for(int i=0; i<ELEMENTS(nModeArray); i++) {
|
|
if(nMode&nModeArray[nIndex]) {
|
|
if(XOsnap(ptPick, nModeArray[nIndex], lstCurves)) {
|
|
if(!bInsideAperture || (Wcs2Ucs(ptPick)&boxTarget)==PR_INSIDE) {
|
|
ptPick1=ptPick;
|
|
return nModeArray[nIndex];
|
|
}
|
|
}
|
|
}
|
|
if(bPrior) nIndex++;
|
|
else nIndex--;
|
|
}
|
|
return OS_NON;
|
|
}
|
|
|