7fd59977 |
1 | // OCCDemo_Presentation.cpp: implementation of the OCCDemo_Presentation class. |
2 | // This is a base class for all presentations |
3 | ////////////////////////////////////////////////////////////////////// |
4 | |
5 | #include "stdafx.h" |
6 | #include "OCCDemo_Presentation.h" |
7 | #include "OCCDemoView.h" |
8 | #include "ISession_Curve.h" |
9 | |
10 | #include <AIS_InteractiveObject.hxx> |
11 | #include <Geom_Surface.hxx> |
12 | #include <Geom_Curve.hxx> |
13 | #include <Geom2d_Curve.hxx> |
14 | #include <Quantity_Color.hxx> |
15 | #include <AIS_Shape.hxx> |
16 | #include <BRepBuilderAPI_MakeFace.hxx> |
17 | #include <Precision.hxx> |
18 | #include <Geom_Line.hxx> |
19 | #include <Geom_TrimmedCurve.hxx> |
6262338c |
20 | #include <Prs3d_Drawer.hxx> |
7fd59977 |
21 | #include <Prs3d_ArrowAspect.hxx> |
22 | #include <AIS_Point.hxx> |
23 | #include <Geom_CartesianPoint.hxx> |
24 | #include <Geom2d_OffsetCurve.hxx> |
25 | #include <GeomAPI.hxx> |
26 | #include <gp_Pln.hxx> |
27 | #include <Geom_OffsetCurve.hxx> |
28 | |
a110c4a3 |
29 | #define MAX_PARAM 1000 // if a surface parameter is infinite, it is assigned |
7fd59977 |
30 | // this value in order to display the "infinit" object in the viewer. |
31 | |
32 | |
33 | Standard_Boolean OCCDemo_Presentation::WaitForInput (unsigned long aMilliSeconds) |
34 | { |
35 | //::WaitForSingleObject(::CreateEvent (NULL, FALSE, FALSE, NULL), aMilliSeconds); |
36 | if (::MsgWaitForMultipleObjects(0, NULL, FALSE, aMilliSeconds, |
37 | QS_KEY | QS_MOUSEBUTTON) != WAIT_TIMEOUT) |
38 | { |
39 | MSG msg; |
40 | if (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) |
41 | { |
168077a6 |
42 | if ( msg.message == WM_KEYUP || |
43 | msg.message == WM_MOUSEFIRST || |
44 | msg.message == WM_PAINT ) |
7fd59977 |
45 | { |
46 | ::PeekMessage (&msg, NULL, 0, 0, PM_REMOVE); |
47 | return WaitForInput (aMilliSeconds); |
48 | } |
49 | else |
50 | return Standard_True; |
51 | } |
52 | } |
53 | return Standard_False; |
54 | } |
55 | |
56 | //================================================================ |
57 | // Function : fixParam |
a110c4a3 |
58 | // Purpose : assigns a finite value to theParam if it's infinite |
7fd59977 |
59 | // (equal to +- Precision::Infinite()) |
60 | //================================================================ |
61 | static Standard_Boolean fixParam(Standard_Real& theParam) |
62 | { |
63 | Standard_Boolean aResult = Standard_False; |
64 | if (Precision::IsNegativeInfinite(theParam)) |
65 | { |
66 | theParam = -MAX_PARAM; |
67 | aResult = Standard_True; |
68 | } |
69 | if (Precision::IsPositiveInfinite(theParam)) |
70 | { |
71 | theParam = MAX_PARAM; |
72 | aResult = Standard_True; |
73 | } |
74 | return aResult; |
75 | } |
76 | |
77 | //================================================================ |
78 | // Function : DrawSurface |
79 | // Purpose : displays a given geometric surface in 3d viewer |
80 | // (creates a finite face and displays it) |
81 | //================================================================ |
92efcf78 |
82 | Handle(AIS_InteractiveObject) OCCDemo_Presentation::drawSurface |
83 | (const Handle(Geom_Surface)& theSurface, |
7fd59977 |
84 | const Quantity_Color& theColor, |
85 | const Standard_Boolean toDisplay) |
86 | { |
87 | Standard_Real u1, u2, v1, v2; |
88 | theSurface->Bounds(u1,u2,v1,v2); |
89 | fixParam(u1); |
90 | fixParam(u2); |
91 | fixParam(v1); |
92 | fixParam(v2); |
93 | |
92efcf78 |
94 | Handle(AIS_Shape) aGraphicSurface = |
9181b66d |
95 | new AIS_Shape(BRepBuilderAPI_MakeFace (theSurface, u1, u2, v1, v2, Precision::Confusion())); |
7fd59977 |
96 | |
97 | getAISContext()->SetMaterial(aGraphicSurface, Graphic3d_NOM_PLASTIC, toDisplay); |
98 | getAISContext()->SetColor(aGraphicSurface, theColor, toDisplay); |
99 | if (toDisplay) { |
100 | if (FitMode){ |
101 | getAISContext()->Display (aGraphicSurface, Standard_False); |
102 | COCCDemoDoc::Fit(); |
103 | } |
104 | else |
0577ae8c |
105 | getAISContext()->Display (aGraphicSurface, Standard_True); |
7fd59977 |
106 | } |
107 | |
108 | return aGraphicSurface; |
109 | } |
110 | |
111 | //================================================================ |
112 | // Function : DrawCurve |
113 | // Purpose : displays a given curve 3d |
114 | //================================================================ |
92efcf78 |
115 | Handle(AIS_InteractiveObject) OCCDemo_Presentation::drawCurve |
116 | (const Handle(Geom_Curve)& theCurve, |
7fd59977 |
117 | const Quantity_Color& theColor, |
118 | const Standard_Boolean toDisplay) |
119 | { |
120 | Handle(ISession_Curve) aGraphicCurve = new ISession_Curve (theCurve); |
121 | |
122 | getAISContext()->SetColor (aGraphicCurve, theColor, toDisplay); |
123 | aGraphicCurve->Attributes()->Link()->SetLineArrowDraw(Standard_False); |
124 | if (toDisplay){ |
125 | if (FitMode){ |
126 | getAISContext()->Display (aGraphicCurve, Standard_False); |
127 | COCCDemoDoc::Fit(); |
128 | } |
129 | else |
0577ae8c |
130 | getAISContext()->Display (aGraphicCurve, Standard_True); |
7fd59977 |
131 | } |
132 | |
133 | return aGraphicCurve; |
134 | } |
135 | |
136 | //================================================================ |
137 | // Function : DrawCurve |
138 | // Purpose : displays a given curve 2d |
139 | //================================================================ |
92efcf78 |
140 | Handle(AIS_InteractiveObject) OCCDemo_Presentation::drawCurve |
141 | (const Handle(Geom2d_Curve)& theCurve, |
7fd59977 |
142 | const Quantity_Color& theColor, |
143 | const Standard_Boolean toDisplay, |
144 | const gp_Ax2& aPosition) |
145 | { |
146 | // create 3D curve in plane |
147 | Handle(Geom_Curve) aCurve3d; |
148 | if (theCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve))) |
149 | { |
150 | Handle(Geom2d_OffsetCurve) aOffCurve = |
151 | Handle(Geom2d_OffsetCurve)::DownCast(theCurve); |
152 | Handle(Geom_Curve) aBasCurve3d = |
153 | GeomAPI::To3d (aOffCurve->BasisCurve(), gp_Pln(aPosition)); |
154 | Standard_Real aDist = aOffCurve->Offset(); |
155 | aCurve3d = new Geom_OffsetCurve (aBasCurve3d, aDist, aPosition.Direction()); |
156 | } |
157 | else |
158 | { |
159 | aCurve3d = GeomAPI::To3d (theCurve, gp_Pln(aPosition)); |
160 | } |
161 | return drawCurve (aCurve3d, theColor, toDisplay); |
162 | } |
163 | |
164 | //================================================================ |
165 | // Function : drawPoint |
166 | // Purpose : displays a given point |
167 | //================================================================ |
92efcf78 |
168 | Handle(AIS_Point) OCCDemo_Presentation::drawPoint |
7fd59977 |
169 | (const gp_Pnt& aPnt, |
170 | const Quantity_Color& theColor, |
171 | const Standard_Boolean toDisplay) |
172 | { |
173 | Handle(AIS_Point) aGraphicPoint = new AIS_Point (new Geom_CartesianPoint(aPnt)); |
174 | |
175 | getAISContext()->SetColor (aGraphicPoint, theColor, toDisplay); |
176 | if (toDisplay) { |
0577ae8c |
177 | getAISContext()->Display (aGraphicPoint, Standard_True); |
7fd59977 |
178 | //COCCDemoDoc::Fit(); |
179 | } |
180 | |
181 | return aGraphicPoint; |
182 | } |
183 | |
184 | //================================================================ |
185 | // Function : drawVector |
186 | // Purpose : displays a given vector in 3d viewer |
187 | // (segment of line starting at thePnt with the arrow at the end, |
188 | // the length of segment is the length of the vector) |
189 | //================================================================ |
92efcf78 |
190 | Handle(AIS_InteractiveObject) OCCDemo_Presentation::drawVector |
7fd59977 |
191 | (const gp_Pnt& thePnt, |
192 | const gp_Vec& theVec, |
193 | const Quantity_Color& theColor, |
194 | const Standard_Boolean toDisplay) |
195 | { |
196 | Standard_Real aLength = theVec.Magnitude(); |
197 | if (aLength < Precision::Confusion()) |
198 | return Handle(AIS_InteractiveObject)(); |
199 | |
200 | Handle(Geom_Curve) aCurve = new Geom_Line (thePnt, theVec); |
201 | aCurve = new Geom_TrimmedCurve (aCurve, 0, aLength); |
202 | |
203 | Handle(ISession_Curve) aGraphicCurve = new ISession_Curve (aCurve); |
204 | |
205 | getAISContext()->SetColor (aGraphicCurve, theColor, toDisplay); |
206 | Handle(Prs3d_Drawer) aDrawer = aGraphicCurve->Attributes()->Link(); |
207 | aDrawer->SetLineArrowDraw(Standard_True); |
208 | aDrawer->ArrowAspect()->SetLength(aLength/10); |
209 | if (toDisplay) { |
210 | if (FitMode){ |
211 | getAISContext()->Display (aGraphicCurve, Standard_False); |
212 | COCCDemoDoc::Fit(); |
213 | } |
214 | else |
0577ae8c |
215 | getAISContext()->Display (aGraphicCurve, Standard_True); |
7fd59977 |
216 | } |
217 | |
218 | return aGraphicCurve; |
219 | } |
220 | |
221 | |
92efcf78 |
222 | Handle(AIS_Shape) OCCDemo_Presentation::drawShape |
7fd59977 |
223 | (const TopoDS_Shape& theShape,const Quantity_Color& theColor, |
224 | const Standard_Boolean toDisplay) |
225 | { |
92efcf78 |
226 | Handle(AIS_Shape) aGraphicShape = new AIS_Shape(theShape); |
7fd59977 |
227 | |
228 | getAISContext()->SetMaterial(aGraphicShape, Graphic3d_NOM_PLASTIC, toDisplay); |
229 | getAISContext()->SetColor (aGraphicShape, theColor, toDisplay); |
230 | if (toDisplay){ |
231 | if (FitMode){ |
232 | getAISContext()->Display (aGraphicShape, Standard_False); |
233 | COCCDemoDoc::Fit(); |
234 | } |
235 | else |
0577ae8c |
236 | getAISContext()->Display (aGraphicShape, Standard_True); |
7fd59977 |
237 | } |
238 | |
239 | return aGraphicShape; |
240 | } |
241 | |
92efcf78 |
242 | Handle(AIS_Shape) OCCDemo_Presentation::drawShape |
7fd59977 |
243 | (const TopoDS_Shape& theShape, |
244 | const Graphic3d_NameOfMaterial theMaterial, |
245 | const Standard_Boolean toDisplay) |
246 | { |
92efcf78 |
247 | Handle(AIS_Shape) aGraphicShape = new AIS_Shape(theShape); |
7fd59977 |
248 | |
249 | getAISContext()->SetMaterial(aGraphicShape, theMaterial, toDisplay); |
250 | if (toDisplay) { |
251 | if (FitMode){ |
252 | getAISContext()->Display (aGraphicShape, Standard_False); |
253 | COCCDemoDoc::Fit(); |
254 | } |
255 | else |
0577ae8c |
256 | getAISContext()->Display (aGraphicShape, Standard_True); |
7fd59977 |
257 | } |
258 | |
259 | return aGraphicShape; |
260 | } |
261 | |
ee2be2a8 |
262 | void OCCDemo_Presentation::GetViewAt (Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) |
7fd59977 |
263 | { |
9764ccbb |
264 | CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
265 | CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
266 | COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView(); |
267 | pView->GetViewAt (theX, theY, theZ); |
7fd59977 |
268 | } |
269 | |
ee2be2a8 |
270 | void OCCDemo_Presentation::SetViewAt (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ) |
7fd59977 |
271 | { |
9764ccbb |
272 | CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
273 | CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
274 | COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView(); |
275 | pView->SetViewAt (theX, theY, theZ); |
7fd59977 |
276 | } |
277 | |
ee2be2a8 |
278 | void OCCDemo_Presentation::GetViewEye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) |
7fd59977 |
279 | { |
280 | CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
281 | CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
282 | COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView(); |
283 | pView->GetViewEye(X,Y,Z); |
284 | } |
285 | |
ee2be2a8 |
286 | void OCCDemo_Presentation::SetViewEye(Standard_Real X, Standard_Real Y, Standard_Real Z) |
7fd59977 |
287 | { |
288 | CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
289 | CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
290 | COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView(); |
291 | pView->SetViewEye(X,Y,Z); |
292 | } |
293 | |
ee2be2a8 |
294 | Standard_Real OCCDemo_Presentation::GetViewScale() |
7fd59977 |
295 | { |
296 | CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
297 | CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
298 | COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView(); |
299 | return pView->GetViewScale(); |
300 | } |
301 | |
ee2be2a8 |
302 | void OCCDemo_Presentation::SetViewScale(Standard_Real Coef) |
7fd59977 |
303 | { |
304 | CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
305 | CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
306 | COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView(); |
307 | pView->SetViewScale(Coef); |
308 | } |
309 | |
310 | void OCCDemo_Presentation::ResetView() |
311 | { |
312 | CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
313 | CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
314 | COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView(); |
315 | pView->Reset(); |
9764ccbb |
316 | } |
317 | |
ee2be2a8 |
318 | void OCCDemo_Presentation::TranslateView (const Standard_Real theX, const Standard_Real theY) |
9764ccbb |
319 | { |
320 | CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
321 | CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
322 | COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView(); |
323 | pView->Translate (theX, theY); |
324 | } |