-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSketcher_SnapIntersection.cxx
188 lines (176 loc) · 5.19 KB
/
Sketcher_SnapIntersection.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/**
* \file Sketcher_SnapIntersection.cxx
* \brief Implementation file for the class Sketcher_SnapIntersection
* \author <a href="mailto:[email protected]?subject=Sketcher_SnapIntersection.cxx">Sergei Maslov</a>
*/
#include "Sketcher_SnapIntersection.hxx"
IMPLEMENT_STANDARD_RTTIEXT(Sketcher_SnapIntersection, Sketcher_Snap)
/**
* \fn Sketcher_SnapIntersection()
* \brief Constructs a Sketcher_SnapIntersection
*/
Sketcher_SnapIntersection::Sketcher_SnapIntersection()
{
cur1Geom2d_Line = new Geom2d_Line(gp::Origin2d(),gp::DX2d());
cur2Geom2d_Line = new Geom2d_Line(gp::Origin2d(),gp::DX2d());
bpu = 0;
}
/**
* \fn ~Sketcher_SnapIntersection()
* \brief Destructor
*/
Sketcher_SnapIntersection::~Sketcher_SnapIntersection()
{
}
/**
* \fn SelectEvent()
* \brief find nearest intersection point
* \return void
*/
void Sketcher_SnapIntersection::SelectEvent()
{
findbestPnt2d = Standard_False;
minDistance = minimumSnapDistance;
for( Standard_Integer i=1; i<=data->Length(); i++)
{
mySObject = Handle(Sketcher_Object)::DownCast(data->Value(i));
myGeometryType = mySObject->GetGeometryType();
switch (myGeometryType)
{
case PointSketcherObject:
curGeom2d_Point = Handle(Geom2d_CartesianPoint)::DownCast(mySObject->GetGeometry());
objectPnt2d = curGeom2d_Point->Pnt2d();
if(count())
{
bestPnt2d = objectPnt2d;
curHilightedObj = mySObject->GetAIS_Object();
curHilightedObj2 = curHilightedObj;
}
break;
case LineSketcherObject:
cur1Geom2d_Edge = Handle(Geom2d_Edge)::DownCast(mySObject->GetGeometry());
cur1Geom2d_Line->SetLin2d(cur1Geom2d_Edge->Lin2d());
cur1Geom2d_Curve = cur1Geom2d_Line;
findSecondObject(i);
break;
case CircleSketcherObject:
case ArcSketcherObject:
cur1Geom2d_Curve = Handle(Geom2d_Curve)::DownCast(mySObject->GetGeometry());
findSecondObject(i);
break;
default:break;
}
}
if(minDistance == minimumSnapDistance)
bestPnt2d = curPnt2d;
else findbestPnt2d = Standard_True;
}
/**
* \fn findSecondObject(Standard_Integer start)
* \brief find intersection points for object with start index
* \return void
* \param start Standard_Integer
*/
void Sketcher_SnapIntersection::findSecondObject(Standard_Integer start)
{
for( Standard_Integer j=start+1; j<=data->Length(); j++)
{
secondSObject = Handle(Sketcher_Object)::DownCast(data->Value(j));
myGeometryType = secondSObject->GetGeometryType();
switch (myGeometryType)
{
case PointSketcherObject:
break;
case LineSketcherObject:
{
cur2Geom2d_Edge = Handle(Geom2d_Edge)::DownCast(secondSObject->GetGeometry());
cur2Geom2d_Line->SetLin2d(cur2Geom2d_Edge->Lin2d());
my2dAPI_InterCurveCurve.Init(cur1Geom2d_Curve,cur2Geom2d_Line,1.0e-12);
for( Standard_Integer k=1; k<=my2dAPI_InterCurveCurve.NbPoints(); k++)
{
objectPnt2d = my2dAPI_InterCurveCurve.Point(k);
curDistance = objectPnt2d.Distance(curPnt2d);
if(minDistance > curDistance)
{
bpu = ElCLib::Parameter(cur2Geom2d_Edge->Lin2d(),objectPnt2d);
if( bpu > cur2Geom2d_Edge->StartParameter() && bpu < cur2Geom2d_Edge->EndParameter())
{
if (cur1Geom2d_Curve->IsKind(STANDARD_TYPE(Geom2d_Line)))
{
bpu = ElCLib::Parameter(cur1Geom2d_Edge->Lin2d(),objectPnt2d);
if( bpu > cur1Geom2d_Edge->StartParameter() && bpu < cur1Geom2d_Edge->EndParameter())
{
bestPnt2d = objectPnt2d;
minDistance = curDistance;
curHilightedObj = mySObject->GetAIS_Object();
curHilightedObj2 = secondSObject->GetAIS_Object();
}
}
else
{
bestPnt2d = objectPnt2d;
minDistance = curDistance;
curHilightedObj = mySObject->GetAIS_Object();
curHilightedObj2 = secondSObject->GetAIS_Object();
}
}
}
}
}
break;
case CircleSketcherObject:
case ArcSketcherObject:
{
cur2Geom2d_Curve = Handle(Geom2d_Curve)::DownCast(secondSObject->GetGeometry());
my2dAPI_InterCurveCurve.Init(cur1Geom2d_Curve,cur2Geom2d_Curve,1.0e-12);
for( Standard_Integer k=1; k<=my2dAPI_InterCurveCurve.NbPoints(); k++)
{
objectPnt2d = my2dAPI_InterCurveCurve.Point(k);
curDistance = objectPnt2d.Distance(curPnt2d);
if(minDistance > curDistance)
{
if (cur1Geom2d_Curve->IsKind(STANDARD_TYPE(Geom2d_Line)))
{
bpu = ElCLib::Parameter(cur1Geom2d_Edge->Lin2d(),objectPnt2d);
if( bpu > cur1Geom2d_Edge->StartParameter() && bpu < cur1Geom2d_Edge->EndParameter())
{
bestPnt2d = objectPnt2d;
minDistance = curDistance;
curHilightedObj = mySObject->GetAIS_Object();
curHilightedObj2 = secondSObject->GetAIS_Object();
}
}
else
{
bestPnt2d = objectPnt2d;
minDistance = curDistance;
curHilightedObj = mySObject->GetAIS_Object();
curHilightedObj2 = secondSObject->GetAIS_Object();
}
}
}
}
break;
default:break;
}
}
}
/**
* \fn GetSnapType()
* \brief get Snap type
* \return Sketcher_SnapType
*/
Sketcher_SnapType Sketcher_SnapIntersection::GetSnapType()
{
return SnapIntersection;
}
/**
* \fn DrawRelation()
* \brief draw relation
* \return void
*/
void Sketcher_SnapIntersection::DrawRelation()
{
myContext->SetSelected(curHilightedObj, false);
myContext->SetSelected(curHilightedObj2, true);
}