-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSketcher_CommandLine2P.cxx
206 lines (177 loc) · 4.97 KB
/
Sketcher_CommandLine2P.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
/**
* \file Sketcher_CommandLine2P.cxx
* \brief Implementation file for the class Sketcher_CommandLine2P
* \author <a href="mailto:[email protected]?subject=Sketcher_CommandLine2P.cxx">Sergei Maslov</a>
*/
#include "Sketcher_CommandLine2P.hxx"
IMPLEMENT_STANDARD_RTTIEXT(Sketcher_CommandLine2P, Sketcher_Command)
/**
* \fn Sketcher_CommandLine2P()
* \brief Constructs a Sketcher_CommandLine2P
*/
Sketcher_CommandLine2P::Sketcher_CommandLine2P()
: Sketcher_Command("Line2P.")
{
myLine2PAction = Nothing;
}
/**
* \fn ~Sketcher_CommandLine2P()
* \brief destructor
*/
Sketcher_CommandLine2P::~Sketcher_CommandLine2P()
{
}
/**
* \fn Action()
* \brief turn command to active state
*/
void Sketcher_CommandLine2P::Action()
{
myLine2PAction = Input_FirstPointLine;
}
/**
* \fn MouseInputEvent(const gp_Pnt2d& thePnt2d )
* \brief input event handler
* \return Standard_Boolean
* \param thePnt2d const gp_Pnt2d&
*/
Standard_Boolean Sketcher_CommandLine2P::MouseInputEvent(const gp_Pnt2d& thePnt2d)
{
switch (myLine2PAction)
{
case Nothing: break;
case Input_FirstPointLine:
curPnt2d = myAnalyserSnap->MouseInputException(thePnt2d,thePnt2d,Line_FirstPnt,Standard_True);
myFirstgp_Pnt2d = curPnt2d;
myFirstPoint->SetPnt(ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d));
// myRubberLine->SetPoints(myFirstPoint,myFirstPoint);
// myContext->Display(myRubberLine,0,-1);
myLine2PAction = Input_SecondPointLine;
firstPoint = true;
break;
case Input_SecondPointLine:
{
curPnt2d = myAnalyserSnap->MouseInputException(myFirstgp_Pnt2d,thePnt2d,Line_SecondPnt,Standard_False);
Handle(Geom2d_Edge) newGeom2d_Edge = new Geom2d_Edge();
if(newGeom2d_Edge->SetPoints(myFirstgp_Pnt2d,curPnt2d))
{
Handle (Geom_CartesianPoint) Geom_Point1 = new Geom_CartesianPoint(ElCLib::To3d(curCoordinateSystem.Ax2(),myFirstgp_Pnt2d));
Handle (Geom_CartesianPoint) Geom_Point2 = new Geom_CartesianPoint(ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d));
Handle(AIS_Line) myAIS_Line = new AIS_Line(Geom_Point1,Geom_Point2);
AddObject(newGeom2d_Edge,myAIS_Line,LineSketcherObject);
myContext->Display(myAIS_Line, true);
if (myPolylineMode)
{
myFirstgp_Pnt2d = curPnt2d;
myFirstPoint->SetPnt(mySecondPoint->Pnt());
myRubberLine->SetPoints(myFirstPoint,myFirstPoint);
myContext->Redisplay(myRubberLine, true);
}
else
{
myContext->Remove(myRubberLine, true);
myLine2PAction = Input_FirstPointLine;
}
}
}
break;
default:break;
}
return Standard_False;
}
/**
* \fn MouseMoveEvent(const gp_Pnt2d& thePnt2d )
* \brief mouse move handler
* \return void
* \param thePnt2d const gp_Pnt2d&
*/
void Sketcher_CommandLine2P::MouseMoveEvent(const gp_Pnt2d& thePnt2d)
{
switch (myLine2PAction)
{
case Nothing:break;
case Input_FirstPointLine:
curPnt2d = myAnalyserSnap->MouseMoveException(thePnt2d,thePnt2d,Line_FirstPnt,Standard_True);
break;
case Input_SecondPointLine:
curPnt2d = myAnalyserSnap->MouseMoveException(myFirstgp_Pnt2d,thePnt2d,Line_SecondPnt,Standard_False);
mySecondPoint->SetPnt(ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d));
myRubberLine->SetPoints(myFirstPoint,mySecondPoint);
if(firstPoint)
{
myContext->Display(myRubberLine,0,-1, true);
firstPoint = false;
}else
{
myContext->Redisplay(myRubberLine, true);
}
break;
default:break;
}
}
/**
* \fn CancelEvent()
* \brief cancel event handler, stop entering object
* \return void
*/
void Sketcher_CommandLine2P::CancelEvent()
{
switch (myLine2PAction)
{
case Nothing: break;
case Input_FirstPointLine: break;
case Input_SecondPointLine: myContext->Remove(myRubberLine, true);
break;
default: break;
}
myLine2PAction = Nothing;
}
/**
* \fn GetTypeOfMethod()
* \brief get command Method
* \return Sketcher_ObjectTypeOfMethod
*/
Sketcher_ObjectTypeOfMethod Sketcher_CommandLine2P::GetTypeOfMethod()
{
return Line2P_Method;
}
/**
* \fn SetPolylineFirstPnt(const gp_Pnt2d& p1)
* \brief set last entering gp_Pnt2d for polyline
* \return void
* \param p1 const gp_Pnt2d&
*/
void Sketcher_CommandLine2P::SetPolylineFirstPnt(const gp_Pnt2d& p1)
{
myFirstgp_Pnt2d = p1;
myFirstPoint->SetPnt(ElCLib::To3d(curCoordinateSystem.Ax2(),p1));
myRubberLine->SetPoints(myFirstPoint,myFirstPoint);
myContext->Display(myRubberLine,0,-1, true);
myLine2PAction = Input_SecondPointLine;
}
/**
* \fn GetPolylineFirstPnt(gp_Pnt2d& p1)
* \brief get last entering gp_Pnt2d for polyline
* \return Standard_Boolean
* \param p1 gp_Pnt2d&
*/
Standard_Boolean Sketcher_CommandLine2P::GetPolylineFirstPnt(gp_Pnt2d& p1)
{
if (myLine2PAction == Input_SecondPointLine && myPolylineMode == Standard_True)
{
p1 = myFirstgp_Pnt2d;
return Standard_True;
}
else
return Standard_False;
}
/**
* \fn SetPolylineMode(Standard_Boolean mode)
* \brief set polyline mode
* \return void
* \param mode Standard_Boolean
*/
void Sketcher_CommandLine2P::SetPolylineMode (Standard_Boolean mode)
{
myPolylineMode = mode;
}