b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | #if defined(WOKC40) |
7fd59977 |
19 | |
20 | #define OCC198 // jfa 06/03/2002 // to prevent exception on bad font index |
21 | #define OCC199 // jfa 06/03/2002 // to prevent exception on bad color index |
22 | |
23 | #include <QAViewer2dTest.hxx> |
24 | |
25 | #include <QAViewer2dTest_EventManager.hxx> |
26 | #include <QAViewer2dTest_DataMapOfText.hxx> |
27 | |
28 | #include <AIS2D_InteractiveContext.hxx> |
29 | |
30 | #include <Draw_Interpretor.hxx> |
31 | #include <Draw.hxx> |
32 | |
33 | #ifndef WNT |
34 | |
35 | #include <tk.h> |
36 | #include <X11/Xlib.h> |
37 | #include <X11/Xutil.h> |
38 | #include <Graphic3d_GraphicDevice.hxx> |
39 | #include <Xw_Window.hxx> |
40 | #include <Xw_Driver.hxx> |
41 | |
42 | #else |
43 | |
44 | #include <Graphic3d_WNTGraphicDevice.hxx> |
45 | #include <WNT_WClass.hxx> |
46 | #include <WNT_Window.hxx> |
47 | #include <WNT_WDriver.hxx> |
48 | |
49 | #include <stdio.h> |
50 | |
51 | #endif |
52 | |
53 | #include <V2d_Viewer.hxx> |
54 | #include <V2d_View.hxx> |
55 | |
56 | #include <Graphic2d_Text.hxx> |
57 | |
58 | #include <PS_Driver.hxx> |
59 | |
60 | //============================================================================== |
61 | // VIEWER GLOBALs |
62 | //============================================================================== |
63 | Standard_EXPORT int ViewerMainLoop2d (Standard_Integer , char** argv); |
64 | |
65 | #ifdef WNT |
66 | static Handle(Graphic3d_WNTGraphicDevice)& GetG2dDevice() |
67 | { |
68 | static Handle(Graphic3d_WNTGraphicDevice) GD; |
69 | return GD; |
70 | } |
71 | |
72 | static Handle(WNT_Window)& VT_GetWindow2d() |
73 | { |
74 | static Handle(WNT_Window) WNTWin; |
75 | return WNTWin; |
76 | } |
77 | |
78 | #else |
79 | static Handle(Graphic3d_GraphicDevice)& GetG2dDevice() |
80 | { |
81 | static Handle(Graphic3d_GraphicDevice) GD; |
82 | return GD; |
83 | } |
84 | |
85 | static Handle(Xw_Window)& VT_GetWindow2d() |
86 | { |
87 | static Handle(Xw_Window) XWWin; |
88 | return XWWin; |
89 | } |
90 | |
91 | static Display* display2d; |
92 | |
93 | static void VProcessEvents2d (ClientData, int); |
94 | #endif |
95 | |
96 | #define ZCLIPWIDTH 1. |
97 | |
98 | static QAViewer2dTest_DataMapOfText myMapOfText; |
99 | |
100 | static void OSWindowSetup2d(); |
101 | |
102 | //============================================================================== |
103 | // EVENT GLOBAL VARIABLES |
104 | //============================================================================== |
105 | static int Start_Rot = 0; |
106 | static int ZClipIsOn = 0; |
107 | static int X_Motion = 0, Y_Motion = 0; // Current cursor position |
108 | static int X_ButtonPress = 0, Y_ButtonPress = 0; // Last ButtonPress position |
109 | //============================================================================== |
110 | |
111 | #ifdef WNT |
112 | static LRESULT WINAPI Viewer2dWindowProc (HWND hwnd, UINT uMsg, |
113 | WPARAM wParam, LPARAM lParam); |
114 | #endif |
115 | |
116 | //============================================================================== |
117 | //function : ViewerInit |
118 | //purpose : Create the window viewer and initialize all the global variable |
119 | //============================================================================== |
120 | void QAViewer2dTest::ViewerInit() |
121 | { |
122 | static int first = 1; |
123 | |
124 | if (first) |
125 | { |
126 | Handle(Aspect_WindowDriver) aWindowDriver; |
127 | |
128 | #ifdef WNT |
129 | // Create the Graphic device |
130 | if (GetG2dDevice().IsNull()) |
131 | GetG2dDevice() = new Graphic3d_WNTGraphicDevice(); |
132 | |
133 | // Create window |
134 | if (VT_GetWindow2d().IsNull()) |
135 | { |
136 | Handle(WNT_GraphicDevice) g_Device = new WNT_GraphicDevice(); |
137 | |
138 | Handle(WNT_WClass) WC = new WNT_WClass |
139 | ("GW3D_Class", Viewer2dWindowProc, CS_VREDRAW | CS_HREDRAW, |
140 | 0, 0, LoadCursor(NULL, IDC_ARROW)); |
141 | VT_GetWindow2d() = new WNT_Window |
142 | (g_Device,"Test2d", WC, WS_OVERLAPPEDWINDOW,0.,0.20,0.40,0.40,Quantity_NOC_BLACK); |
143 | VT_GetWindow2d()->Map(); |
144 | } |
145 | |
146 | // Create window driver |
147 | aWindowDriver = new WNT_WDriver(VT_GetWindow2d()); |
148 | #else |
149 | // Create the Graphic device |
150 | if (GetG2dDevice().IsNull()) |
151 | GetG2dDevice() = new Graphic3d_GraphicDevice(getenv("DISPLAY"),Xw_TOM_READONLY); |
152 | |
153 | // Create window |
154 | if (VT_GetWindow2d().IsNull()) |
155 | { |
156 | VT_GetWindow2d() = new Xw_Window(GetG2dDevice(), "Test2d", |
157 | 0.,0.60,0.40,0.40, |
158 | Xw_WQ_3DQUALITY, Quantity_NOC_BLACK); |
159 | } |
160 | |
161 | // Create window driver |
162 | aWindowDriver = new Xw_Driver(VT_GetWindow2d()); |
163 | #endif |
164 | |
165 | Handle(V2d_Viewer) a3DViewer,a3DCollector; |
166 | // Create Viewer and View |
167 | a3DViewer = new V2d_Viewer(GetG2dDevice(),Standard_ExtString("Visu3D")); |
168 | a3DCollector = new V2d_Viewer(GetG2dDevice(),Standard_ExtString("Collector")); |
169 | // a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); |
170 | // a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE); |
171 | |
172 | if (QAViewer2dTest::CurrentView().IsNull()) |
173 | { |
174 | // VT_GetWindow2d()->SetBackground(Quantity_NOC_MATRAGRAY); |
175 | Handle(V2d_View) V = new V2d_View(aWindowDriver, a3DViewer); |
176 | QAViewer2dTest::CurrentView(V); |
177 | } |
178 | Handle(V2d_View) a3DViewCol = new V2d_View(aWindowDriver, a3DCollector); |
179 | |
180 | // AIS2D setup |
181 | if (QAViewer2dTest::GetAIS2DContext().IsNull()) |
182 | { |
183 | Handle(AIS2D_InteractiveContext) C = new AIS2D_InteractiveContext(a3DViewer,a3DCollector); |
184 | QAViewer2dTest::SetAIS2DContext(C); |
185 | } |
186 | |
187 | // Setup for X11 or NT |
188 | OSWindowSetup2d(); |
189 | |
190 | // Viewer and View creation |
191 | |
192 | // a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); |
193 | |
194 | Handle(V2d_View) V = QAViewer2dTest::CurrentView(); |
195 | |
196 | // V->SetDegenerateModeOn(); |
197 | // V->SetWindow(VT_GetWindow2d()); |
198 | |
199 | // V->SetZClippingDepth(0.5); |
200 | // V->SetZClippingWidth(ZCLIPWIDTH/2.); |
201 | |
202 | // a3DViewer->SetDefaultLights(); |
203 | // a3DViewer->SetLightOn(); |
204 | |
205 | #ifndef WNT |
206 | #if TCL_MAJOR_VERSION < 8 && !defined(DECOSF1) |
207 | Tk_CreateFileHandler((void*)ConnectionNumber(display2d), |
208 | TK_READABLE, VProcessEvents2d, (ClientData) VT_GetWindow2d()->XWindow()); |
209 | #else |
210 | Tk_CreateFileHandler(ConnectionNumber(display2d), |
211 | TK_READABLE, VProcessEvents2d, (ClientData) VT_GetWindow2d()->XWindow()); |
212 | #endif |
213 | #endif |
214 | |
215 | first = 0; |
216 | } |
217 | } |
218 | |
219 | //============================================================================== |
220 | //function : V2dinit |
221 | //purpose : Create the window viewer and initialize all the global variable |
222 | // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event |
223 | //============================================================================== |
224 | static int V2dInit (Draw_Interpretor& , Standard_Integer , char** ) |
225 | { |
226 | QAViewer2dTest::ViewerInit(); |
227 | return 0; |
228 | } |
229 | |
230 | //============================================================================== |
231 | //function : ProcessKeyPress2d |
232 | //purpose : Handle KeyPress event from a CString |
233 | //============================================================================== |
234 | static void ProcessKeyPress2d (char *buf_ret) |
235 | { |
236 | // Letters |
237 | if (!strcasecmp(buf_ret, "R")) |
238 | { |
239 | // Reset |
240 | QAViewer2dTest::CurrentView()->Reset(); |
241 | } |
242 | else if (!strcasecmp(buf_ret, "F")) |
243 | { |
244 | // FitAll |
245 | QAViewer2dTest::CurrentView()->Fitall(); |
246 | } |
247 | else if (!strcasecmp(buf_ret, "H")) |
248 | { |
249 | // HLR |
250 | cout << "HLR" << endl; |
251 | // QAViewer2dTest::CurrentView()->SetDegenerateModeOff(); |
252 | } |
253 | else if (!strcasecmp(buf_ret, "S")) |
254 | { |
255 | // SHADING |
256 | cout << "passage en mode 1 (shading pour les shapes)" << endl; |
257 | // QAViewer2dTest::CurrentView()->SetDegenerateModeOn(); |
258 | Handle(AIS2D_InteractiveContext) Ctx = QAViewer2dTest::GetAIS2DContext(); |
259 | // if (Ctx->NbCurrents() == 0 || Ctx->NbSelected() == 0) |
260 | // Ctx->SetDisplayMode(AIS2D_Shaded); |
261 | // else |
262 | { |
263 | if (Ctx->HasOpenedContext()) |
264 | { |
265 | // for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) |
266 | // Ctx->SetDisplayMode(Ctx->Interactive(), 1, Standard_False); |
267 | } |
268 | else |
269 | { |
270 | // for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) |
271 | // Ctx->SetDisplayMode(Ctx->Current(), 1, Standard_False); |
272 | } |
273 | Ctx->UpdateCurrentViewer(); |
274 | } |
275 | } |
276 | else if (!strcasecmp(buf_ret, "U")) |
277 | { |
278 | // Unset display mode |
279 | cout << "passage au mode par defaut" << endl; |
280 | // QAViewer2dTest::CurrentView()->SetDegenerateModeOn(); |
281 | Handle(AIS2D_InteractiveContext) Ctx = QAViewer2dTest::GetAIS2DContext(); |
282 | // if (Ctx->NbCurrents() == 0 || Ctx->NbSelected() == 0) |
283 | // Ctx->SetDisplayMode(AIS2D_WireFrame); |
284 | // else |
285 | { |
286 | if(Ctx->HasOpenedContext()) |
287 | { |
288 | // for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected()) |
289 | // Ctx->UnsetDisplayMode(Ctx->Interactive(), Standard_False); |
290 | } |
291 | else |
292 | { |
293 | // for (Ctx->InitCurrent(); Ctx->MoreCurrent(); Ctx->NextCurrent()) |
294 | // Ctx->UnsetDisplayMode(Ctx->Current(), Standard_False); |
295 | } |
296 | Ctx->UpdateCurrentViewer(); |
297 | } |
298 | } |
299 | else if (!strcasecmp(buf_ret, "W")) |
300 | { |
301 | // WIREFRAME |
302 | cout << "passage en mode 0 (filaire pour les shapes)" << endl; |
303 | // QAViewer2dTest::CurrentView()->SetDegenerateModeOn(); |
304 | Handle(AIS2D_InteractiveContext) Ctx = QAViewer2dTest::GetAIS2DContext(); |
305 | // if (Ctx->NbCurrents() == 0 || Ctx->NbSelected() == 0) |
306 | // Ctx->SetDisplayMode(AIS2D_WireFrame); |
307 | // else |
308 | { |
309 | if (Ctx->HasOpenedContext()) |
310 | { |
311 | // for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected()) |
312 | // Ctx->SetDisplayMode(Ctx->Interactive(), 0, Standard_False); |
313 | } |
314 | else |
315 | { |
316 | // for (Ctx->InitCurrent(); Ctx->MoreCurrent(); Ctx->NextCurrent()) |
317 | // Ctx->SetDisplayMode(Ctx->Current(), 0, Standard_False); |
318 | } |
319 | Ctx->UpdateCurrentViewer(); |
320 | } |
321 | } |
322 | else if (!strcasecmp(buf_ret, "D")) |
323 | { |
324 | // Delete selected |
325 | cout << "Delete selected object - not yet implemented" << endl; |
326 | QAViewer2dTest::CurrentView()->Reset(); |
327 | } |
328 | else if (!strcasecmp(buf_ret, "Z")) |
329 | { |
330 | // ZCLIP |
331 | if (ZClipIsOn) |
332 | { |
333 | cout << "ZClipping OFF" << endl; |
334 | ZClipIsOn = 0; |
335 | |
336 | // QAViewer2dTest::CurrentView()->SetZClippingType(V2d_OFF); |
337 | // QAViewer2dTest::CurrentView()->Redraw(); |
338 | } |
339 | else |
340 | { |
341 | cout << "ZClipping ON" << endl; |
342 | ZClipIsOn = 1; |
343 | |
344 | // QAViewer2dTest::CurrentView()->SetZClippingType(V2d_FRONT); |
345 | // QAViewer2dTest::CurrentView()->Redraw(); |
346 | } |
347 | } |
348 | else if (!strcasecmp(buf_ret, ",")) |
349 | { |
350 | // QAViewer2dTest::GetAIS2DContext()->HilightNextDetected(QAViewer2dTest::CurrentView()); |
351 | } |
352 | else if (!strcasecmp(buf_ret, ".")) |
353 | { |
354 | // QAViewer2dTest::GetAIS2DContext()->HilightPreviousDetected(QAViewer2dTest::CurrentView()); |
355 | } |
356 | else // Number |
357 | { |
358 | Standard_Integer Num = atoi(buf_ret); |
359 | if (Num >= 0 && Num <= 7) |
360 | QAViewer2dTest::StandardModeActivation(Num); |
361 | } |
362 | } |
363 | |
364 | //============================================================================== |
365 | //function : ProcessExpose2d |
366 | //purpose : Redraw the View on an Expose Event |
367 | //============================================================================== |
368 | static void ProcessExpose2d() |
369 | { |
370 | QAViewer2dTest::CurrentView()->Viewer()->Update(); |
371 | // QAViewer2dTest::CurrentView()->Redraw(); |
372 | } |
373 | |
374 | //============================================================================== |
375 | //function : ProcessConfigure2d |
376 | //purpose : Resize the View on an Configure Event |
377 | //============================================================================== |
378 | static void ProcessConfigure2d() |
379 | { |
380 | Handle(V2d_View) V = QAViewer2dTest::CurrentView(); |
381 | V->MustBeResized(V2d_TOWRE_ENLARGE_OBJECTS); |
382 | V->Update(); |
383 | // V->Redraw(); |
384 | V->Viewer()->Update(); |
385 | } |
386 | |
387 | //============================================================================== |
388 | //function : V2dPickGrid |
389 | //purpose : v2dpickgrid : get coordinates of a grid point near to MB1 click |
390 | //============================================================================== |
391 | static int V2dHitGrid (int argc, Standard_Integer anX, Standard_Integer anY, |
392 | char* xxname = 0, char* yyname = 0) |
393 | { |
394 | if (argc != 1 && argc != 3 && argc != 5) |
395 | { |
396 | cout << "Usage : V2dHitGrid [mouse_X mouse_Y [grid_X grid_Y]]" << endl; |
397 | return 1; |
398 | } |
399 | |
400 | Handle(V2d_View) V = QAViewer2dTest::CurrentView(); |
401 | if (V.IsNull()) return 1; |
402 | |
403 | if (V->Viewer()->IsActive()) // about the grid |
404 | { |
405 | // if (argc == 1) |
406 | // { |
407 | // cout << "Mouse cursor position: X = " << anX << " Y = " << anY << endl; |
408 | // } |
409 | |
410 | Quantity_Length xx, yy; |
411 | V->Hit(anX, anY, xx, yy); |
412 | |
413 | Standard_Integer xw, yw; |
414 | V->Convert(xx, yy, xw, yw); |
415 | printf("Window coords of Grid Point: X = %d Y = %d\n", xw, yw); |
416 | |
417 | if (argc < 5) |
418 | { |
419 | printf("Grid Point: X = %.6g Y = %.6g\n", xx, yy); |
420 | } |
421 | else |
422 | { |
423 | char szbuf[32]; |
424 | sprintf(szbuf, "%.6g", xx); |
425 | Draw::Set(xxname, szbuf); |
426 | sprintf(szbuf, "%.6g", yy); |
427 | Draw::Set(yyname, szbuf); |
428 | } |
429 | } |
430 | return 0; |
431 | } |
432 | |
433 | int V2dPickGrid (Draw_Interpretor& , Standard_Integer argc, char** argv) |
434 | { |
435 | if (argc != 1 && argc != 3 && argc != 5) |
436 | { |
437 | cout << "Usage : v2dpickgrid (MB1 in the viewer)" << endl; |
438 | cout << "Usage : v2dgetgrid mouse_X mouse_Y [grid_X grid_Y]" << endl; |
439 | return 1; |
440 | } |
441 | |
442 | if (argc > 1) |
443 | { |
444 | if (argc > 3) |
445 | { |
446 | char *xxname, *yyname; |
447 | xxname = argv[3]; |
448 | yyname = argv[4]; |
449 | V2dHitGrid(argc, atoi(argv[1]), atoi(argv[2]), xxname, yyname); |
450 | } |
451 | else |
452 | { |
453 | V2dHitGrid(argc, atoi(argv[1]), atoi(argv[2])); |
454 | } |
455 | } |
456 | else |
457 | { |
458 | while (ViewerMainLoop2d (argc, argv)) {} |
459 | } |
460 | |
461 | return 0; |
462 | } |
463 | |
464 | //============================================================================== |
465 | //function : ProcessButton1Press2d |
466 | //purpose : Picking |
467 | //============================================================================== |
468 | static Standard_Boolean ProcessButton1Press2d |
469 | (Standard_Integer , char** argv, Standard_Boolean pick, Standard_Boolean shift) |
470 | { |
471 | if (pick) |
472 | { |
473 | cout << "Window X = " << X_ButtonPress << " Window Y = " << Y_ButtonPress << endl; |
474 | if (strlen(argv[0]) > 7) // v2dpickgrid |
475 | { |
476 | V2dHitGrid(1, X_ButtonPress, Y_ButtonPress); |
477 | } |
478 | else |
479 | { |
480 | Handle(V2d_View) V = QAViewer2dTest::CurrentView(); |
481 | if (V.IsNull()) return 1; |
482 | Quantity_Length xx, yy; |
483 | V->Convert(X_ButtonPress, Y_ButtonPress, xx, yy); |
484 | printf("Coord system X = %.6g Y = %.6g\n", xx, yy); |
485 | } |
486 | } |
487 | |
488 | Handle(QAViewer2dTest_EventManager) EM = QAViewer2dTest::CurrentEventManager(); |
489 | if (shift) EM->ShiftSelect(); |
490 | else EM->Select(); |
491 | |
492 | pick = 0; |
493 | return pick; |
494 | } |
495 | |
496 | //============================================================================== |
497 | //function : ProcessButton3Press2d |
498 | //purpose : Start Rotation |
499 | //============================================================================== |
500 | static void ProcessButton3Press2d() |
501 | { |
502 | // Start rotation |
503 | Start_Rot = 1; |
504 | // QAViewer2dTest::CurrentView()->SetDegenerateModeOn(); |
505 | // QAViewer2dTest::CurrentView()->StartRotation(X_ButtonPress, Y_ButtonPress); |
506 | } |
507 | |
508 | //============================================================================== |
509 | //function : ProcessButtonRelease2d |
510 | //purpose : End Rotation |
511 | //============================================================================== |
512 | static void ProcessButtonRelease2d() |
513 | { |
514 | // End rotation |
515 | Start_Rot = 0; |
516 | // QAViewer2dTest::CurrentView()->SetDegenerateModeOff(); |
517 | } |
518 | |
519 | //============================================================================== |
520 | //function : ProcessZClipMotion2d |
521 | //purpose : Zoom |
522 | //============================================================================== |
523 | void ProcessZClipMotion2d() |
524 | { |
525 | Handle(V2d_View) a3DView = QAViewer2dTest::CurrentView(); |
526 | if (Abs(X_Motion - X_ButtonPress) > 2) |
527 | { |
528 | static Standard_Real CurZPos = 0.; |
529 | // Quantity_Length VDX, VDY; |
530 | |
531 | // a3DView->Size(VDX,VDY); |
532 | |
533 | #ifdef DEB |
534 | // Standard_Real VDZ = |
535 | #endif |
536 | // a3DView->ZSize(); |
537 | |
538 | Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress); |
539 | |
540 | // Front = Depth + width/2. |
541 | Standard_Real D = 0.5; |
542 | // Standard_Real W = 0.1; |
543 | |
544 | CurZPos += (dx); |
545 | |
546 | D += CurZPos; |
547 | |
548 | // a3DView->SetZClippingType(V2d_OFF); |
549 | // a3DView->SetZClippingDepth(D); |
550 | // a3DView->SetZClippingWidth(W); |
551 | // a3DView->SetZClippingType(V2d_FRONT); |
552 | |
553 | // a3DView->Redraw(); |
554 | |
555 | X_ButtonPress = X_Motion; |
556 | Y_ButtonPress = Y_Motion; |
557 | } |
558 | } |
559 | |
560 | //============================================================================== |
561 | //function : ProcessControlButton1Motion2d |
562 | //purpose : Zoom on Ctrl+MB1 |
563 | //============================================================================== |
564 | static void ProcessControlButton1Motion2d() |
565 | { |
566 | QAViewer2dTest::CurrentView()->Zoom(X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion); |
567 | |
568 | X_ButtonPress = X_Motion; |
569 | Y_ButtonPress = Y_Motion; |
570 | } |
571 | |
572 | //============================================================================== |
573 | //function : ProcessControlButton2Motion2d |
574 | //purpose : Pan on Ctrl+MB2 |
575 | //============================================================================== |
576 | static void ProcessControlButton2Motion2d() |
577 | { |
578 | QAViewer2dTest::CurrentView()->Pan(X_Motion - X_ButtonPress, Y_ButtonPress - Y_Motion); |
579 | |
580 | X_ButtonPress = X_Motion; |
581 | Y_ButtonPress = Y_Motion; |
582 | } |
583 | |
584 | //============================================================================== |
585 | //function : ProcessControlButton3Motion2d |
586 | //purpose : Rotation on Ctrl+MB3 |
587 | //============================================================================== |
588 | static void ProcessControlButton3Motion2d() |
589 | { |
590 | // if (Start_Rot) QAViewer2dTest::CurrentView()->Rotation(X_Motion, Y_Motion); |
591 | } |
592 | |
593 | //============================================================================== |
594 | //function : ProcessMotion2d |
595 | //purpose : pre-hilights detected objects at mouse position |
596 | //============================================================================== |
597 | static void ProcessMotion2d() |
598 | { |
599 | Handle(QAViewer2dTest_EventManager) EM = QAViewer2dTest::CurrentEventManager(); |
600 | Handle(V2d_View) V = QAViewer2dTest::CurrentView(); |
601 | EM->MoveTo(X_Motion, Y_Motion, V); |
602 | } |
603 | |
604 | //============================================================================== |
605 | //function : ProcessGridMotion2d |
606 | //purpose : pre-hilights grid point near mouse position |
607 | //============================================================================== |
608 | static void ProcessGridMotion2d() |
609 | { |
610 | Handle(V2d_View) V = QAViewer2dTest::CurrentView(); |
611 | |
612 | static Standard_Boolean LastIsGridActiveStatus = Standard_True; |
613 | if (V->Viewer()->IsActive()) // about the grid |
614 | { |
615 | V->ShowHit(X_Motion, Y_Motion); |
616 | LastIsGridActiveStatus = Standard_True; |
617 | } |
618 | if (!V->Viewer()->IsActive() && LastIsGridActiveStatus) // about the grid |
619 | { |
620 | V->EraseHit(); |
621 | LastIsGridActiveStatus = Standard_False; |
622 | } |
623 | } |
624 | |
625 | //============================================================================== |
626 | //function : GetMousePosition |
627 | //purpose : |
628 | //============================================================================== |
629 | void QAViewer2dTest::GetMousePosition (Standard_Integer& Xpix, Standard_Integer& Ypix) |
630 | { |
631 | Xpix = X_Motion; |
632 | Ypix = Y_Motion; |
633 | } |
634 | |
635 | //============================================================================== |
636 | //function : V2dHelp |
637 | //purpose : Dsiplay help on viewer Keyboead and mouse commands |
638 | //Draw arg : No args |
639 | //============================================================================== |
640 | /*static int V2dHelp (Draw_Interpretor& , Standard_Integer , char** ) |
641 | { |
642 | cout << "Q : Quit the application" << endl; |
643 | cout << "=========================" << endl; |
644 | cout << "F : FitAll" << endl; |
645 | cout << "R : ResetView" << endl; |
646 | cout << "=========================" << endl; |
647 | cout << "Selection mode " << endl; |
648 | cout << "0 : OBJECT" << endl; |
649 | cout << "1 : PRIMITIVE" << endl; |
650 | cout << "2 : ELEMENT" << endl; |
651 | cout << "3 : VERTEX" << endl; |
652 | cout << "4 : NONE" << endl; |
653 | cout << "==========================" << endl; |
654 | cout << "D : Remove Selected Object" << endl; |
655 | cout << "==========================" << endl; |
656 | |
657 | return 0; |
658 | }*/ |
659 | |
660 | #ifdef WNT |
661 | |
662 | static LRESULT WINAPI Viewer2dWindowProc (HWND hwnd, UINT Msg, |
663 | WPARAM wParam, LPARAM lParam ) |
664 | { |
665 | static Standard_Boolean Ppick = 0; |
666 | static Standard_Integer Pargc = 0; |
667 | static char** Pargv = NULL; |
668 | |
669 | static int Up = 1; |
670 | |
671 | if (!QAViewer2dTest::CurrentView().IsNull()) |
672 | { |
673 | PAINTSTRUCT ps; |
674 | |
675 | switch (Msg) |
676 | { |
677 | case WM_PAINT: |
678 | BeginPaint(hwnd, &ps); |
679 | EndPaint(hwnd, &ps); |
680 | ProcessExpose2d(); |
681 | break; |
682 | |
683 | case WM_SIZE: |
684 | ProcessConfigure2d(); |
685 | break; |
686 | |
687 | case WM_KEYDOWN: |
688 | char c[2]; |
689 | c[0] = (char) wParam; |
690 | c[1] = '\0'; |
691 | ProcessKeyPress2d(c); |
692 | break; |
693 | |
694 | case WM_LBUTTONUP: |
695 | case WM_MBUTTONUP: |
696 | case WM_RBUTTONUP: |
697 | Up = 1; |
698 | ProcessButtonRelease2d(); |
699 | break; |
700 | |
701 | case WM_LBUTTONDOWN: |
702 | case WM_MBUTTONDOWN: |
703 | case WM_RBUTTONDOWN: |
704 | { |
705 | WPARAM fwKeys = wParam; |
706 | |
707 | Up = 0; |
708 | |
709 | X_ButtonPress = LOWORD(lParam); |
710 | Y_ButtonPress = HIWORD(lParam); |
711 | |
712 | if (Msg == WM_LBUTTONDOWN && !(fwKeys & MK_CONTROL)) |
713 | { |
714 | Ppick = ProcessButton1Press2d(Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT)); |
715 | } |
716 | else if (Msg == WM_RBUTTONDOWN) |
717 | { |
718 | // Start rotation |
719 | ProcessButton3Press2d(); |
720 | } |
721 | } |
722 | break; |
723 | |
724 | case WM_MOUSEMOVE: |
725 | { |
726 | WPARAM fwKeys = wParam; |
727 | X_Motion = LOWORD(lParam); |
728 | Y_Motion = HIWORD(lParam); |
729 | |
730 | if (Up && fwKeys & (MK_LBUTTON|MK_MBUTTON|MK_RBUTTON)) |
731 | { |
732 | Up = 0; |
733 | X_ButtonPress = LOWORD(lParam); |
734 | Y_ButtonPress = HIWORD(lParam); |
735 | |
736 | if (fwKeys & MK_RBUTTON) |
737 | { |
738 | // Start rotation |
739 | ProcessButton3Press2d(); |
740 | } |
741 | } |
742 | |
743 | if (fwKeys & MK_CONTROL) |
744 | { |
745 | if (fwKeys & MK_LBUTTON) |
746 | { |
747 | ProcessControlButton1Motion2d(); |
748 | } |
749 | else if (fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON))) |
750 | { |
751 | ProcessControlButton2Motion2d(); |
752 | } |
753 | else if (fwKeys & MK_RBUTTON) |
754 | { |
755 | ProcessControlButton3Motion2d(); |
756 | } |
757 | } |
758 | else if (fwKeys & MK_SHIFT) |
759 | { |
760 | if (fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON))) |
761 | { |
762 | ProcessZClipMotion2d(); |
763 | } |
764 | } |
765 | else |
766 | { |
767 | ProcessMotion2d(); |
768 | } |
769 | } |
770 | break; |
771 | |
772 | default: |
773 | return(DefWindowProc(hwnd, Msg, wParam, lParam)); |
774 | } |
775 | return 0L; |
776 | } |
777 | |
778 | return DefWindowProc(hwnd, Msg, wParam, lParam); |
779 | } |
780 | |
781 | //============================================================================== |
782 | //function : ViewerMainLoop2d |
783 | //purpose : Get a Event on the view and dispatch it |
784 | //============================================================================== |
785 | static int ViewerMainLoop2d (Standard_Integer argc, char** argv) |
786 | { |
787 | cout << "No yet implemented on WNT" << endl; |
788 | static Standard_Boolean Ppick = 0; |
789 | static Standard_Integer Pargc = 0; |
790 | static char** Pargv = NULL; |
791 | |
792 | Ppick = (argc > 0)? -1 : 0; |
793 | Pargc = argc; |
794 | Pargv = argv; |
795 | |
796 | if (Ppick) |
797 | { |
798 | MSG msg; |
799 | msg.wParam = 1; |
800 | |
801 | cout << "Start picking" << endl; |
802 | |
803 | while (Ppick == -1) |
804 | { |
805 | // Wait for a ProcessButton1Press2d() to toggle pick to 1 or 0 |
806 | if (GetMessage(&msg, NULL, 0, 0)) |
807 | { |
808 | TranslateMessage(&msg); |
809 | DispatchMessage(&msg); |
810 | } |
811 | } |
812 | |
813 | cout << "Picking done" << endl; |
814 | } |
815 | |
816 | return Ppick; |
817 | } |
818 | |
819 | #else |
820 | |
821 | //============================================================================== |
822 | //function : ViewerMainLoop2d |
823 | //purpose : Get a Event on the view and dispatch it |
824 | //============================================================================== |
825 | int ViewerMainLoop2d (Standard_Integer argc, char** argv) |
826 | { |
827 | Standard_Boolean pick = argc > 0; |
828 | |
829 | // X11 Event loop |
830 | static XEvent report; |
831 | |
832 | XNextEvent(display2d, &report); |
833 | |
834 | switch (report.type) |
835 | { |
836 | case Expose: |
837 | ProcessExpose2d(); |
838 | break; |
839 | case ConfigureNotify: |
840 | ProcessConfigure2d(); |
841 | break; |
842 | case KeyPress: |
843 | { |
844 | KeySym ks_ret; |
845 | char buf_ret[11]; |
846 | int ret_len; |
847 | XComposeStatus status_in_out; |
848 | |
849 | ret_len = XLookupString((XKeyEvent *)&report, (char *) buf_ret, |
850 | 10, &ks_ret, &status_in_out); |
851 | |
852 | buf_ret[ret_len] = '\0'; |
853 | if (ret_len) ProcessKeyPress2d(buf_ret); |
854 | } |
855 | break; |
856 | case ButtonPress: |
857 | { |
858 | X_ButtonPress = report.xbutton.x; |
859 | Y_ButtonPress = report.xbutton.y; |
860 | |
861 | if (report.xbutton.button == Button1 && |
862 | !(report.xbutton.state & ControlMask)) |
863 | { |
864 | pick = ProcessButton1Press2d(argc, argv, pick, |
865 | (report.xbutton.state & ShiftMask)); |
866 | } |
867 | else if (report.xbutton.button == Button3) |
868 | { |
869 | // Start rotation |
870 | ProcessButton3Press2d(); |
871 | } |
872 | } |
873 | break; |
874 | case ButtonRelease: |
875 | ProcessButtonRelease2d(); |
876 | break; |
877 | case MotionNotify: |
878 | { |
879 | X_Motion = report.xmotion.x; |
880 | Y_Motion = report.xmotion.y; |
881 | |
882 | // remove all the ButtonMotionMask |
883 | while (XCheckMaskEvent(display2d, ButtonMotionMask, &report)) {} |
884 | |
885 | if (ZClipIsOn && report.xmotion.state & ShiftMask) |
886 | { |
887 | if (Abs(X_Motion - X_ButtonPress) > 2) |
888 | { |
889 | Quantity_Length VDX = 0.0, VDY = 0.0; |
890 | |
891 | // QAViewer2dTest::CurrentView()->Size(VDX,VDY); |
892 | Standard_Real VDZ =0 ; |
893 | // VDZ = QAViewer2dTest::CurrentView()->ZSize(); |
894 | |
895 | printf("%f,%f,%f\n", VDX, VDY, VDZ); |
896 | |
897 | Quantity_Length dx = 0 ; |
898 | dx = QAViewer2dTest::CurrentView()->Convert(X_Motion - X_ButtonPress); |
899 | |
900 | cout << dx << endl; |
901 | |
902 | dx = dx / VDX * VDZ; |
903 | |
904 | cout << dx << endl; |
905 | |
906 | // Front = Depth + width/2. |
907 | //QAViewer2dTest::CurrentView()->SetZClippingDepth(dx); |
908 | //QAViewer2dTest::CurrentView()->SetZClippingWidth(0.); |
909 | |
910 | // QAViewer2dTest::CurrentView()->Redraw(); |
911 | } |
912 | } |
913 | |
914 | if (report.xmotion.state & ControlMask) |
915 | { |
916 | if (report.xmotion.state & Button1Mask) |
917 | { |
918 | ProcessControlButton1Motion2d(); |
919 | } |
920 | else if (report.xmotion.state & Button2Mask) |
921 | { |
922 | ProcessControlButton2Motion2d(); |
923 | } |
924 | else if (report.xmotion.state & Button3Mask) |
925 | { |
926 | ProcessControlButton3Motion2d(); |
927 | } |
928 | } |
929 | else |
930 | { |
931 | if (pick && strlen(argv[0]) > 7) // v2dpickgrid |
932 | ProcessGridMotion2d(); |
933 | else |
934 | ProcessMotion2d(); |
935 | } |
936 | } |
937 | break; |
938 | } |
939 | |
940 | return pick; |
941 | } |
942 | |
943 | //============================================================================== |
944 | //function : VProcessEvents2d |
945 | //purpose : call by Tk_CreateFileHandler() to be able to manage the |
946 | // event in the Viewer window |
947 | //============================================================================== |
948 | static void VProcessEvents2d (ClientData, int) |
949 | { |
950 | // test for X Event |
951 | while (XPending(display2d)) |
952 | { |
953 | ViewerMainLoop2d(0, NULL); |
954 | } |
955 | } |
956 | #endif |
957 | |
958 | //============================================================================== |
959 | //function : OSWindowSetup2d |
960 | //purpose : Setup for the X11 window to be able to cath the event |
961 | //============================================================================== |
962 | static void OSWindowSetup2d() |
963 | { |
964 | #ifndef WNT |
965 | // X11 |
966 | Window window = VT_GetWindow2d()->XWindow(); |
967 | |
968 | Standard_Address theDisplay = GetG2dDevice()->XDisplay(); |
969 | display2d = (Display * ) theDisplay; |
970 | |
971 | XSynchronize(display2d, 1); |
972 | |
973 | VT_GetWindow2d()->Map(); |
974 | |
975 | // X11 : For keyboard on SUN |
976 | XWMHints wmhints; |
977 | wmhints.flags = InputHint; |
978 | wmhints.input = 1; |
979 | |
980 | XSetWMHints( display2d, window, &wmhints); |
981 | |
982 | XSelectInput(display2d, window, |
983 | ExposureMask | StructureNotifyMask | KeyPressMask | ButtonPressMask | |
984 | PointerMotionMask | |
985 | Button1MotionMask | Button2MotionMask | Button3MotionMask); |
986 | |
987 | XSynchronize(display2d, 0); |
988 | |
989 | #else |
990 | // WNT |
991 | #endif |
992 | |
993 | } |
994 | |
995 | //============================================================================== |
996 | //function : InitQAViewer2dTest |
997 | //purpose : initialisation de toutes les variables static de QAViewer2dTest (dp) |
998 | //============================================================================== |
999 | void QAViewer2dTest_InitQAViewer2dTest (const Handle(AIS2D_InteractiveContext)& context) |
1000 | { |
1001 | Handle(V2d_Viewer) viewer = context->CurrentViewer(); |
1002 | QAViewer2dTest::SetAIS2DContext(context); |
1003 | viewer->InitActiveViews(); |
1004 | Handle(V2d_View) view = viewer->ActiveView(); |
1005 | if (viewer->MoreActiveViews()) QAViewer2dTest::CurrentView(view); |
1006 | QAViewer2dTest::ResetEventManager(); |
1007 | Handle(Aspect_GraphicDevice) device = viewer->Device(); |
1008 | Handle(Aspect_WindowDriver) aWDr = view->Driver(); |
1009 | Handle(Aspect_Window) window = aWDr->Window(); |
1010 | #ifndef WNT |
1011 | // X11 |
1012 | VT_GetWindow2d() = Handle(Xw_Window)::DownCast(window); |
1013 | GetG2dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device); |
1014 | OSWindowSetup2d(); |
1015 | static int first = 1; |
1016 | if (first) |
1017 | { |
1018 | #if TCL_MAJOR_VERSION < 8 && !defined(DECOSF1) |
1019 | Tk_CreateFileHandler((void*)ConnectionNumber(display2d), |
1020 | TK_READABLE, VProcessEvents2d, (ClientData) 0); |
1021 | #else |
1022 | Tk_CreateFileHandler(ConnectionNumber(display2d), |
1023 | TK_READABLE, VProcessEvents2d, (ClientData) 0); |
1024 | #endif |
1025 | first = 0; |
1026 | } |
1027 | #endif |
1028 | } |
1029 | |
1030 | //============================================================================== |
1031 | //function : V2dFit |
1032 | //purpose : Fitall, no DRAW arguments |
1033 | //Draw arg : No args |
1034 | //============================================================================== |
1035 | static int V2dFit (Draw_Interpretor& , Standard_Integer , char** ) |
1036 | { |
1037 | Handle(V2d_View) V = QAViewer2dTest::CurrentView(); |
1038 | if (!V.IsNull()) V->Fitall(); |
1039 | return 0; |
1040 | } |
1041 | |
1042 | //============================================================================== |
1043 | //function : V2dRepaint |
1044 | //purpose : refresh viewer |
1045 | //Draw arg : No args |
1046 | //============================================================================== |
1047 | static int V2dRepaint (Draw_Interpretor& , Standard_Integer , char** ) |
1048 | { |
1049 | Handle(V2d_View) V = QAViewer2dTest::CurrentView(); |
1050 | if (!V.IsNull()) |
1051 | // V->Redraw(); |
1052 | V->Viewer()->Update(); |
1053 | return 0; |
1054 | } |
1055 | |
1056 | //============================================================================== |
1057 | //function : V2dClear |
1058 | //purpose : Remove all the object from the viewer |
1059 | //Draw arg : No args |
1060 | //============================================================================== |
1061 | static int V2dClear (Draw_Interpretor& , Standard_Integer , char** ) |
1062 | { |
1063 | Handle(V2d_View) V = QAViewer2dTest::CurrentView(); |
1064 | if (V.IsNull()) return 1; |
1065 | |
1066 | QAViewer2dTest::Clear(); |
1067 | V->Viewer()->Update(); |
1068 | return 0; |
1069 | } |
1070 | |
1071 | //============================================================================== |
1072 | //function : V2dPick |
1073 | //purpose : v2dpick - print mouse coords and color |
1074 | //============================================================================== |
1075 | static int V2dPick (Draw_Interpretor& , Standard_Integer argc, char** argv) |
1076 | { |
1077 | if (argc != 1) |
1078 | { |
1079 | cout << "Usage: v2dpick (MB1 in the viewer)" << endl; |
1080 | return 1; |
1081 | } |
1082 | if (QAViewer2dTest::CurrentView().IsNull()) return 1; |
1083 | |
1084 | while (ViewerMainLoop2d (argc, argv)) {} |
1085 | |
1086 | return 0; |
1087 | } |
1088 | |
1089 | //============================================================================== |
1090 | //function : V2dSetBG |
1091 | //purpose : v2dsetbg imagefile [filltype] : load image as background |
1092 | //============================================================================== |
1093 | static int V2dSetBG (Draw_Interpretor& , Standard_Integer argc, char** argv) |
1094 | { |
1095 | if (argc < 2 || argc > 3) |
1096 | { |
1097 | cout << "Usage : v2dsetbg imagefile [filltype]" << endl; |
1098 | return 1; |
1099 | } |
1100 | if (QAViewer2dTest::CurrentView().IsNull()) return 1; |
1101 | |
1102 | Aspect_FillMethod aFillType = Aspect_FM_CENTERED; |
1103 | if (argc == 3) |
1104 | { |
1105 | char* szType = argv[2]; |
1106 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; |
1107 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; |
1108 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; |
1109 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; |
1110 | else |
1111 | { |
1112 | cout << "Wrong fill type : " << szType << endl; |
1113 | cout << "Must be one of CENTERED, TILED, STRETCH, NONE" << endl; |
1114 | return -1; |
1115 | } |
1116 | } |
1117 | |
1118 | QAViewer2dTest::CurrentView()->SetBackground(argv[1], aFillType); |
1119 | QAViewer2dTest::CurrentView()->Viewer()->Update(); |
1120 | |
1121 | return 0; |
1122 | } |
1123 | |
1124 | //============================================================================== |
1125 | //function : V2dGrid |
1126 | //purpose : v2dgrid [type [Origin(X Y) XStep/RadiusStep YStep/DivisionNb RotationAngle] [drawmode]] : load grid |
1127 | // : v2drmgrid : unload grid |
1128 | //============================================================================== |
1129 | static int V2dGrid (Draw_Interpretor& , Standard_Integer argc, char** argv) |
1130 | { |
1131 | if (QAViewer2dTest::CurrentView().IsNull()) return 1; |
1132 | Handle(V2d_Viewer) aViewer = QAViewer2dTest::CurrentView()->Viewer(); |
1133 | |
1134 | char* szName = argv[0]; |
1135 | if (strcmp(szName, "v2drmgrid") == 0) |
1136 | { |
1137 | if (argc > 1) |
1138 | { |
1139 | cout << "Usage : v2drmgrid" << endl; |
1140 | return 1; |
1141 | } |
1142 | |
1143 | aViewer->DeactivateGrid(); |
1144 | return 0; |
1145 | } |
1146 | |
1147 | // v2dgrid. Args nb may be 1,2,3,7,8 |
1148 | if (argc < 1 || argc > 8 || (argc < 7 && argc > 3)) |
1149 | { |
1150 | cout << "Usage : v2dgrid [type [Origin(X Y) XStep/RadiusStep YStep/DivisionNb RotationAngle] [drawmode]]" << endl; |
1151 | return 1; |
1152 | } |
1153 | |
1154 | Aspect_GridType aGridT = Aspect_GT_Rectangular; |
1155 | Aspect_GridDrawMode aDrawM = Aspect_GDM_Lines; |
1156 | |
1157 | if (argc > 1) |
1158 | { |
1159 | char* szType = argv[1]; |
1160 | if (strcmp(szType, "Rect") == 0) aGridT = Aspect_GT_Rectangular; |
1161 | else if (strcmp(szType, "Circ") == 0) aGridT = Aspect_GT_Circular; |
1162 | else |
1163 | { |
1164 | cout << "Wrong grid type : " << szType << endl; |
1165 | cout << "Must be Rect or Circ" << endl; |
1166 | return -1; |
1167 | } |
1168 | |
1169 | if (argc == 3 || argc == 8) |
1170 | { |
1171 | char* szMode = (argc == 3) ? argv[2] : argv[7]; |
1172 | if (strcmp(szMode, "Lines" ) == 0) aDrawM = Aspect_GDM_Lines; |
1173 | else if (strcmp(szMode, "Points") == 0) aDrawM = Aspect_GDM_Points; |
1174 | else if (strcmp(szMode, "None" ) == 0) aDrawM = Aspect_GDM_None; |
1175 | else |
1176 | { |
1177 | cout << "Wrong grid draw mode : " << szMode << endl; |
1178 | cout << "Must be Lines or Points, or None" << endl; |
1179 | return -1; |
1180 | } |
1181 | } |
1182 | } |
1183 | |
1184 | aViewer->ActivateGrid(aGridT, aDrawM); |
1185 | |
1186 | if (argc > 3) |
1187 | { |
1188 | Quantity_Length aXOrigin = atof(argv[2]); |
1189 | Quantity_Length aYOrigin = atof(argv[3]); |
1190 | Quantity_PlaneAngle aRotationAngle = atof(argv[6]); |
1191 | |
1192 | if (aGridT == Aspect_GT_Rectangular) |
1193 | { |
1194 | Quantity_Length aXStep = atof(argv[4]); |
1195 | Quantity_Length aYStep = atof(argv[5]); |
1196 | aViewer->SetRectangularGridValues |
1197 | (aXOrigin, aYOrigin, aXStep, aYStep, aRotationAngle); |
1198 | } |
1199 | else |
1200 | { |
1201 | Quantity_Length aRadiusStep = atof(argv[4]); |
1202 | Standard_Integer aDivisionNumber = atoi(argv[5]); |
1203 | aViewer->SetCircularGridValues |
1204 | (aXOrigin, aYOrigin, aRadiusStep, aDivisionNumber, aRotationAngle); |
1205 | } |
1206 | } |
1207 | |
1208 | return 0; |
1209 | } |
1210 | |
1211 | //============================================================================== |
1212 | //function : V2dPSOut |
1213 | //purpose : v2dpsout imagefile [Scale TypeOfColorSpace] [Width Height XCenter YCenter] : PostScript Output |
1214 | //============================================================================== |
1215 | static int V2dPSOut (Draw_Interpretor& , Standard_Integer argc, char** argv) |
1216 | { |
1217 | if (argc < 2 || argc > 8) |
1218 | { |
1219 | cout << "Usage : v2dpsout imagefile [Scale TypeOfColorSpace] [Width Height XCenter YCenter]" << endl; |
1220 | return 1; |
1221 | } |
1222 | |
1223 | Handle(V2d_View) V = QAViewer2dTest::CurrentView(); |
1224 | if (V.IsNull()) return 1; |
1225 | |
1226 | Quantity_Factor aScale = 1.0; |
1227 | Aspect_TypeOfColorSpace aColorType = Aspect_TOCS_RGB; |
1228 | |
1229 | Quantity_Length aWidth = 100.0, aHeight = 100.0; |
1230 | |
1231 | Quantity_Length aXCenter, aYCenter; |
1232 | V->Center(aXCenter, aYCenter); |
1233 | |
1234 | if (argc > 2) |
1235 | { |
1236 | aScale = atof(argv[2]); |
1237 | |
1238 | if (argc > 3) |
1239 | { |
1240 | char* szType = argv[3]; |
1241 | if (strcmp(szType, "RGB") == 0) aColorType = Aspect_TOCS_RGB; |
1242 | else if (strcmp(szType, "BlackAndWhite") == 0) aColorType = Aspect_TOCS_BlackAndWhite; |
1243 | else if (strcmp(szType, "GreyScale") == 0) aColorType = Aspect_TOCS_GreyScale; |
1244 | else |
1245 | { |
1246 | cout << "Wrong color space type : " << szType << endl; |
1247 | cout << "Must be one of RGB, BlackAndWhite, GreyScale" << endl; |
1248 | return -1; |
1249 | } |
1250 | |
1251 | if (argc == 8) |
1252 | { |
1253 | aWidth = atof(argv[4]); |
1254 | aHeight = atof(argv[5]); |
1255 | aXCenter = atof(argv[6]); |
1256 | aYCenter = atof(argv[7]); |
1257 | } |
1258 | else // take current window size |
1259 | { |
1260 | #ifndef WNT |
1261 | Handle(Aspect_Window) anAspWindow = V->Driver()->Window(); |
1262 | Handle(Xw_Window) anXWindow = Handle(Xw_Window)::DownCast(anAspWindow); |
1263 | anXWindow->Size(aWidth, aHeight); |
1264 | #endif |
1265 | } |
1266 | } |
1267 | } |
1268 | |
1269 | QAViewer2dTest::CurrentView()->PostScriptOutput |
1270 | (argv[1], aWidth, aHeight, aXCenter, aYCenter, aScale, aColorType); |
1271 | |
1272 | return 0; |
1273 | } |
1274 | |
1275 | //============================================================================== |
1276 | //function : V2dPlot |
1277 | //purpose : v2dplot format imagefile [Scale TypeOfColorSpace] [Width Height XCenter YCenter] |
1278 | //============================================================================== |
1279 | /*static int V2dPlot (Draw_Interpretor& , Standard_Integer argc, char** argv) |
1280 | { |
1281 | if (argc < 3 || argc > 9) |
1282 | { |
1283 | cout << "Args: format imagefile [Scale TypeOfColorSpace] [Width Height XCenter YCenter]" << endl; |
1284 | return 1; |
1285 | } |
1286 | if (QAViewer2dTest::CurrentView().IsNull()) return 1; |
1287 | |
1288 | Quantity_Factor aScale = 1.0; |
1289 | Aspect_TypeOfColorSpace aColorType = Aspect_TOCS_RGB; |
1290 | |
1291 | Quantity_Length aWidth = 100.0, aHeight = 100.0; |
1292 | |
1293 | Quantity_Length aXCenter, aYCenter; |
1294 | QAViewer2dTest::CurrentView()->Center(aXCenter, aYCenter); |
1295 | |
1296 | if (argc > 3) |
1297 | { |
1298 | aScale = atof(argv[3]); |
1299 | |
1300 | if (argc > 4) |
1301 | { |
1302 | char* szType = argv[4]; |
1303 | if (strcmp(szType, "RGB") == 0) aColorType = Aspect_TOCS_RGB; |
1304 | else if (strcmp(szType, "BlackAndWhite") == 0) aColorType = Aspect_TOCS_BlackAndWhite; |
1305 | else if (strcmp(szType, "GreyScale") == 0) aColorType = Aspect_TOCS_GreyScale; |
1306 | else |
1307 | { |
1308 | cout << "Wrong color space type : " << szType << endl; |
1309 | cout << "Must be one of RGB, BlackAndWhite, GreyScale" << endl; |
1310 | return -1; |
1311 | } |
1312 | |
1313 | if (argc == 9) |
1314 | { |
1315 | aWidth = atof(argv[5]); |
1316 | aHeight = atof(argv[6]); |
1317 | aXCenter = atof(argv[7]); |
1318 | aYCenter = atof(argv[8]); |
1319 | } |
1320 | } |
1321 | } |
1322 | |
1323 | char* szFormat = argv[1]; |
1324 | if (strcmp(szFormat, "PS") == 0) |
1325 | { |
1326 | Handle(PS_Driver) aPSDriver = new PS_Driver(argv[2], aWidth, aHeight, aColorType); |
1327 | QAViewer2dTest::CurrentView()->Plot(aPSDriver, aXCenter, aYCenter, aScale); |
1328 | } |
1329 | else if (strcmp(szFormat, "") == 0) |
1330 | { |
1331 | Handle(PS_Driver) aPSDriver = new PS_Driver(argv[2], aWidth, aHeight, aColorType); |
1332 | QAViewer2dTest::CurrentView()->Plot(aPSDriver, aXCenter, aYCenter, aScale); |
1333 | } |
1334 | else if (strcmp(szFormat, "") == 0) |
1335 | { |
1336 | } |
1337 | else |
1338 | { |
1339 | } |
1340 | |
1341 | return 0; |
1342 | }*/ |
1343 | |
1344 | //======================================================================= |
1345 | //function : V2dTextColor |
1346 | //purpose : v2dsettextcolor text_name color_index |
1347 | //======================================================================= |
1348 | static int V2dTextColor (Draw_Interpretor& , int argc, char** argv) |
1349 | { |
1350 | if (argc != 3) |
1351 | { |
1352 | cerr << "Usage : v2dsettextcolor text_name color_index" << endl; |
1353 | return -1; |
1354 | } |
1355 | |
1356 | //////////////////TCollection_AsciiString aName (argv[1]); |
1357 | TCollection_ExtendedString ExtendedString (argv[1]); |
1358 | Standard_ExtString aName = ExtendedString.ToExtString(); |
1359 | |
1360 | if (!myMapOfText.IsBound(aName)) |
1361 | { |
1362 | cout << "No such text object: " << aName << endl; |
1363 | return -1; |
1364 | } |
1365 | |
1366 | int aColInd = atoi(argv[2]); |
1367 | |
1368 | #ifdef OCC199 |
1369 | // check color index |
1370 | Standard_Integer aColMin, aColMax; |
1371 | QAViewer2dTest::CurrentView()->Driver()->ColorBoundIndexs(aColMin, aColMax); |
1372 | if (aColInd < aColMin || aColMax < aColInd) |
1373 | { |
1374 | cout << "Color index must be between " << aColMin << " and " << aColMax << endl; |
1375 | return -1; |
1376 | } |
1377 | #endif |
1378 | |
1379 | myMapOfText(aName)->SetColorIndex(aColInd); |
1380 | QAViewer2dTest::CurrentView()->Viewer()->Update(); |
1381 | return 0; |
1382 | } |
1383 | |
1384 | //======================================================================= |
1385 | //function : V2dText |
1386 | //purpose : v2dtext text_str position(x y) [angle scale font] |
1387 | //======================================================================= |
1388 | static int V2dText (Draw_Interpretor& , int argc, char** argv) |
1389 | { |
1390 | if (argc != 4 && argc != 7) |
1391 | { |
1392 | cerr << "Usage : v2dtext text_str position(x y) [angle scale font]" << endl; |
1393 | return -1; |
1394 | } |
1395 | |
1396 | Handle(AIS2D_InteractiveContext) myAIScontext = QAViewer2dTest::GetAIS2DContext(); |
1397 | if (myAIScontext.IsNull()) |
1398 | { |
1399 | cerr << "use 'v2dinit' command before " << argv[0] << endl; |
1400 | return -1; |
1401 | } |
1402 | myAIScontext->SetPickMode(Graphic2d_PM_INTERSECT); |
1403 | Handle(V2d_View) V = QAViewer2dTest::CurrentView(); |
1404 | |
1405 | Handle(Graphic2d_GraphicObject) obj = |
1406 | new Graphic2d_GraphicObject(V->View()); |
1407 | |
1408 | Quantity_PlaneAngle anAngle = 0.0; |
1409 | Quantity_Factor aScale = 1.0; |
1410 | Standard_Integer aFontIn = 0; |
1411 | |
1412 | if (argc > 4) |
1413 | { |
1414 | anAngle = atof(argv[4]); |
1415 | aScale = atof(argv[5]); |
1416 | aFontIn = atoi(argv[6]); |
1417 | |
1418 | #ifdef OCC198 |
1419 | // check font index |
1420 | Standard_Integer aFontMin, aFontMax; |
1421 | QAViewer2dTest::CurrentView()->Driver()->FontBoundIndexs(aFontMin, aFontMax); |
1422 | if (aFontIn < aFontMin || aFontMax < aFontIn) |
1423 | { |
1424 | cout << "Font index must be between " << aFontMin << " and " << aFontMax << endl; |
1425 | return -1; |
1426 | } |
1427 | #endif |
1428 | } |
1429 | |
1430 | Handle(Graphic2d_Text) text = |
1431 | new Graphic2d_Text(obj, TCollection_ExtendedString(argv[1]), |
1432 | atof(argv[2]), atof(argv[3]), anAngle, |
1433 | Aspect_TOT_SOLID, aScale); |
1434 | text->SetFontIndex(aFontIn); |
1435 | |
1436 | obj->Display(); |
1437 | V->Fitall(); |
1438 | |
1439 | int i = myMapOfText.Extent(); |
1440 | |
1441 | TCollection_AsciiString aTxtName ("text_"); |
1442 | aTxtName += TCollection_AsciiString(i); |
1443 | |
1444 | //////////////////myMapOfText.Bind(aTxtName, text); |
1445 | TCollection_ExtendedString ExtendedString (aTxtName); |
1446 | Standard_ExtString ExtString_aTxtName = ExtendedString.ToExtString(); |
1447 | myMapOfText.Bind(ExtString_aTxtName, text); |
1448 | |
1449 | cout << "Text " << aTxtName << " created" << endl; |
1450 | return 0; |
1451 | } |
1452 | |
1453 | //======================================================================= |
1454 | //function : ViewerCommands |
1455 | //purpose : |
1456 | //======================================================================= |
1457 | void QAViewer2dTest::ViewerCommands(Draw_Interpretor& theCommands) |
1458 | { |
1459 | char *group = "2D AIS Viewer - Viewer Commands"; |
1460 | |
1461 | theCommands.Add("v2dinit", |
1462 | "v2dinit : Create the Viewer window", |
1463 | __FILE__, V2dInit, group); |
1464 | |
1465 | theCommands.Add("v2dsetbg", |
1466 | "v2dsetbg imagefile [filltype] : Load image as background", |
1467 | __FILE__, V2dSetBG, group); |
1468 | |
1469 | theCommands.Add("v2dgrid", |
1470 | "v2dgrid [type [Origin(X Y) XStep/RadiusStep YStep/DivisionNb RotationAngle(in radians)] [drawmode]] : Load grid", |
1471 | __FILE__, V2dGrid, group); |
1472 | |
1473 | theCommands.Add("v2drmgrid", |
1474 | "v2drmgrid : Unload grid", |
1475 | __FILE__, V2dGrid, group); |
1476 | |
1477 | // theCommands.Add("v2dplot", |
1478 | // "v2dplot format filename : Dump in file in certain format", |
1479 | // __FILE__, V2dPlot, group); |
1480 | |
1481 | theCommands.Add("v2dpsout", |
1482 | "v2dpsout imagefile [Scale TypeOfColorSpace] [Width Height XCenter YCenter] : PostScript Output", |
1483 | __FILE__, V2dPSOut, group); |
1484 | |
1485 | theCommands.Add("v2dpick", |
1486 | "v2dpick (MB1 in the viewer) : Print pixel coords and color", |
1487 | __FILE__, V2dPick, group); |
1488 | |
1489 | theCommands.Add("v2dpickgrid", |
1490 | "v2dpickgrid (MB1 in the viewer) : Print coordinates of a grid point near to MB1 click", |
1491 | __FILE__, V2dPickGrid, group); |
1492 | |
1493 | theCommands.Add("v2dfit", |
1494 | "v2dfit or <F> : Fit all shapes", |
1495 | __FILE__, V2dFit, group); |
1496 | |
1497 | theCommands.Add("v2drepaint", |
1498 | "v2drepaint : Force redraw", |
1499 | __FILE__, V2dRepaint, group); |
1500 | |
1501 | theCommands.Add("v2dclear", |
1502 | "v2dclear : Clear the viewer", |
1503 | __FILE__, V2dClear, group); |
1504 | |
1505 | theCommands.Add("v2dtext", "v2dtext text_str position(x y) [angle scale font]", V2dText, group); |
1506 | theCommands.Add("v2dsettextcolor", "v2dsettextcolor text_name color_index", V2dTextColor, group); |
1507 | |
1508 | // theCommands.Add("v2dhelp", |
1509 | // "v2dhelp : Display help on the viewer commands", |
1510 | // __FILE__, V2dHelp, group); |
1511 | } |
1512 | #endif |