-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSketcher_Snap.cxx
240 lines (218 loc) · 5.03 KB
/
Sketcher_Snap.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/**
* \file Sketcher_Snap.cxx
* \brief Implementation file for the class Sketcher_Snap
* \author <a href="mailto:[email protected]?subject=Sketcher_Snap.cxx">Sergei Maslov</a>
*/
#include "Sketcher_Snap.hxx"
IMPLEMENT_STANDARD_RTTIEXT(Sketcher_Snap, Standard_Transient)
/**
* \fn Sketcher_Snap()
* \brief Constructs a Sketcher_Snap
*/
Sketcher_Snap::Sketcher_Snap()
: curCoordinateSystem(gp::XOY()),
FirstEdge(),SecondEdge()
{
curPnt2d = gp::Origin2d();
objectPnt2d = gp::Origin2d();
bestPnt2d = gp::Origin2d();
findbestPnt2d = Standard_False;
firstDisplay = Standard_True;
myGeom_Point = new Geom_CartesianPoint(gp::Origin());
myAIS_Point = new AIS_Point(myGeom_Point);
myAIS_Point->SetColor(Quantity_NOC_CYAN1);
minimumSnapDistance = MINIMUMSNAP;
minDistance = 0;
curDistance = 0;
curGeom2d_Point = new Geom2d_CartesianPoint(curPnt2d);
myPlane = new Geom_Plane(curCoordinateSystem);
}
/**
* \fn ~Sketcher_Snap()
* \brief Destructor
*/
Sketcher_Snap::~Sketcher_Snap()
{
}
/**
* \fn SetContext(Handle(AIS_InteractiveContext)& theContext)
* \brief set context
* \return void
* \param theContext Handle(AIS_InteractiveContext)&
*/
void Sketcher_Snap::SetContext (Handle(AIS_InteractiveContext)& theContext)
{
myContext = theContext;
}
/**
* \fn SetData(Handle(TColStd_HSequenceOfTransient)& thedata)
* \brief set list of objects
* \return void
* \param thedata TColStd_HSequenceOfTransient)&
*/
void Sketcher_Snap::SetData (Handle(TColStd_HSequenceOfTransient)& thedata)
{
data = thedata;
}
/**
* \fn SetAx3(const gp_Ax3& theAx3)
* \brief set coordinate system
* \return void
* \param theAx3 const gp_Ax3&
*/
void Sketcher_Snap::SetAx3(const gp_Ax3 &theAx3)
{
curCoordinateSystem = theAx3;
}
/**
* \fn SetMinDistance(const Standard_Real& aPrecise)
* \brief set precise
* \return void
* \param aPrecise const Standard_Real&
*/
void Sketcher_Snap::SetMinDistance(const Standard_Real& aPrecise)
{
minimumSnapDistance = aPrecise;
}
/**
* \fn MouseInputEvent(const gp_Pnt2d& thePnt2d)
* \brief input event handler
* \return gp_Pnt2d
* \param thePnt2d const gp_Pnt2d&
*/
gp_Pnt2d Sketcher_Snap::MouseInputEvent(const gp_Pnt2d& tempPnt2d)
{
curPnt2d = tempPnt2d;
SelectEvent();
EraseSnap();
return bestPnt2d;
}
/**
* \fn MouseMoveEvent(const gp_Pnt2d& thePnt2d)
* \brief mouse move handler
* \return gp_Pnt2d
* \param thePnt2d const gp_Pnt2d&
*/
gp_Pnt2d Sketcher_Snap::MouseMoveEvent(const gp_Pnt2d& tempPnt2d)
{
curPnt2d = tempPnt2d;
SelectEvent();
if(findbestPnt2d)
{
myGeom_Point->SetPnt(ElCLib::To3d(curCoordinateSystem.Ax2(),bestPnt2d));
myAIS_Point->SetComponent(myGeom_Point);
if (firstDisplay)
{
myContext->Display(myAIS_Point,0,-1, true);
DrawRelation();
firstDisplay = Standard_False;
}
else
{
myContext->Redisplay(myAIS_Point, true);
DrawRelation();
}
}
else
{
myContext->Remove(myAIS_Point, true);
EraseRelation();
firstDisplay = Standard_True;
}
return bestPnt2d;
}
/**
* \fn EraseSnap()
* \brief cancel event handler
* \return void
*/
void Sketcher_Snap::EraseSnap()
{
firstDisplay = Standard_True;
myContext->Remove(myAIS_Point, true);
EraseRelation();
}
/**
* \fn AnalyserEvent(const gp_Pnt2d& tempPnt2d, gp_Pnt2d& newPnt2d,Standard_Real& dist,Standard_Integer& type)
* \brief get new point, minimum distance, snap type
* \return Standard_Boolean
* \param tempPnt2d const gp_Pnt2d&
* \param newPnt2d const gp_Pnt2d&
* \param dist Standard_Real&
* \param type Standard_Integer&
*/
Standard_Boolean Sketcher_Snap::AnalyserEvent(const gp_Pnt2d& tempPnt2d, gp_Pnt2d& newPnt2d,Standard_Real& dist,Standard_Integer& type)
{
curPnt2d = tempPnt2d;
SelectEvent();
newPnt2d = bestPnt2d;
dist = minDistance;
type = (Standard_Integer)GetSnapType();
return findbestPnt2d;
}
/**
* \fn DrawRelation()
* \brief draw relation
* \return void
*/
void Sketcher_Snap::DrawRelation()
{
myContext->SetSelected(curHilightedObj, true);
}
/**
* \fn EraseRelation()
* \brief erase relation
* \return void
*/
void Sketcher_Snap::EraseRelation()
{
myContext->ClearSelected(true);
}
/**
* \fn setFirstPnt(const gp_Pnt2d& p)
* \brief set point for exceptions
* \return void
* \param p const gp_Pnt2d&
*/
void Sketcher_Snap::setFirstPnt(const gp_Pnt2d& p)
{
}
/**
* \fn setFirstPnt(const gp_Pnt2d& p)
* \brief set point and tangent type for exceptions
* \return void
* \param p const gp_Pnt2d&
* \param ttype TangentType
*/
void Sketcher_Snap::setFirstPnt(const gp_Pnt2d& p,TangentType ttype)
{
}
/**
* \fn countProject()
* \brief find point projected on curve
* \return Standard_Boolean
*/
Standard_Boolean Sketcher_Snap::countProject()
{
if(ProjectOnCurve.NbPoints() > 0)
{
objectPnt2d = ProjectOnCurve.NearestPoint();
return count();
}
else return Standard_False;
}
/**
* \fn count()
* \brief check distance to point
* \return Standard_Boolean
*/
Standard_Boolean Sketcher_Snap::count()
{
curDistance = objectPnt2d.Distance(curPnt2d);
if(minDistance > curDistance)
{
minDistance = curDistance;
return Standard_True;
}
else return Standard_False;
}