Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1998-09-01 |
2 | // Created by: Robert COUBLANC | |
3 | // Copyright (c) 1998-1999 Matra Datavision | |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
5 | // | |
6 | // The content of this file is subject to the Open CASCADE Technology Public | |
7 | // License Version 6.5 (the "License"). You may not use the content of this file | |
8 | // except in compliance with the License. Please obtain a copy of the License | |
9 | // at http://www.opencascade.org and read it completely before using this file. | |
10 | // | |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
13 | // | |
14 | // The Original Code and all software distributed under the License is | |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
16 | // Initial Developer hereby disclaims all such warranties, including without | |
17 | // limitation, any warranties of merchantability, fitness for a particular | |
18 | // purpose or non-infringement. Please see the License for the specific terms | |
19 | // and conditions governing the rights and limitations under the License. | |
20 | ||
7fd59977 | 21 | |
22 | // Robert Boehne 30 May 2000 : Dec Osf | |
23 | ||
24 | #ifdef HAVE_CONFIG_H | |
25 | # include <config.h> | |
26 | #endif | |
27 | ||
28 | #ifdef WNT | |
29 | #include <windows.h> | |
30 | #endif | |
31 | ||
32 | #include <Graphic3d_ExportFormat.hxx> | |
33 | #include <ViewerTest.hxx> | |
34 | #include <ViewerTest_EventManager.hxx> | |
35 | #include <Visual3d_View.hxx> | |
25289ec1 | 36 | #include <Visual3d_ViewManager.hxx> |
37 | #include <V3d_LayerMgr.hxx> | |
7fd59977 | 38 | #include <NIS_View.hxx> |
39 | #include <NIS_Triangulated.hxx> | |
40 | #include <NIS_InteractiveContext.hxx> | |
41 | #include <AIS_InteractiveContext.hxx> | |
42 | #include <Draw_Interpretor.hxx> | |
43 | #include <Draw.hxx> | |
44 | #include <Draw_Appli.hxx> | |
7edf74fd A |
45 | #include <Aspect_PrintAlgo.hxx> |
46 | #include <Image_PixMap.hxx> | |
59f45b7c | 47 | #include <TColStd_SequenceOfInteger.hxx> |
20637bd2 | 48 | #include <Visual3d_LayerItem.hxx> |
49 | #include <V3d_LayerMgr.hxx> | |
50 | #include <V3d_LayerMgrPointer.hxx> | |
51 | #include <Aspect_TypeOfLine.hxx> | |
7fd59977 | 52 | |
25289ec1 | 53 | #ifdef WNT |
54 | #undef DrawText | |
55 | #endif | |
56 | ||
57 | #include <Visual3d_Layer.hxx> | |
58 | ||
7fd59977 | 59 | #ifndef WNT |
60 | #include <Graphic3d_GraphicDevice.hxx> | |
61 | #include <Xw_GraphicDevice.hxx> | |
62 | #include <Xw_WindowQuality.hxx> | |
63 | #include <Xw_Window.hxx> | |
64 | #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */ | |
65 | #include <X11/Xutil.h> | |
66 | #include <tk.h> | |
67 | ||
68 | #else | |
69 | ||
70 | #include <Graphic3d_WNTGraphicDevice.hxx> | |
71 | #include <WNT_WClass.hxx> | |
72 | #include <WNT_Window.hxx> | |
73 | ||
74 | #define _CRT_SECURE_NO_DEPRECATE | |
75 | #pragma warning (disable:4996) | |
76 | ||
77 | #endif | |
78 | ||
79 | #define OCC120 | |
80 | ||
81 | //============================================================================== | |
82 | ||
83 | //============================================================================== | |
84 | // VIEWER GLOBAL VARIABLES | |
85 | //============================================================================== | |
86 | ||
87 | Standard_IMPORT Standard_Boolean Draw_VirtualWindows; | |
88 | ||
89 | Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv); | |
90 | extern const Handle(NIS_InteractiveContext)& TheNISContext(); | |
91 | ||
92 | #ifdef WNT | |
93 | static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){ | |
94 | static Handle(Graphic3d_WNTGraphicDevice) GD; | |
95 | return GD; | |
96 | } | |
97 | ||
98 | static Handle(WNT_Window)& VT_GetWindow() { | |
99 | static Handle(WNT_Window) WNTWin; | |
100 | return WNTWin; | |
101 | } | |
102 | ||
103 | #else | |
104 | static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){ | |
105 | static Handle(Graphic3d_GraphicDevice) GD; | |
106 | return GD; | |
107 | } | |
108 | static Handle(Xw_Window)& VT_GetWindow(){ | |
109 | static Handle(Xw_Window) XWWin; | |
110 | return XWWin; | |
111 | } | |
112 | static Display *display; | |
113 | ||
114 | static void VProcessEvents(ClientData,int); | |
115 | #endif | |
116 | ||
117 | #ifdef OCC120 | |
118 | static Standard_Boolean DegenerateMode = Standard_True; | |
119 | #endif | |
120 | ||
121 | #define ZCLIPWIDTH 1. | |
122 | ||
123 | static void OSWindowSetup(); | |
124 | ||
125 | //============================================================================== | |
126 | // EVENT GLOBAL VARIABLES | |
127 | //============================================================================== | |
128 | ||
129 | static int Start_Rot = 0; | |
130 | static int ZClipIsOn = 0; | |
131 | static int X_Motion= 0,Y_Motion=0; // Current cursor position | |
132 | static int X_ButtonPress = 0, Y_ButtonPress = 0; // Last ButtonPress position | |
133 | ||
134 | ||
135 | //============================================================================== | |
136 | ||
137 | #ifdef WNT | |
138 | static LRESULT WINAPI ViewerWindowProc( | |
139 | HWND hwnd, | |
140 | UINT uMsg, | |
141 | WPARAM wParam, | |
142 | LPARAM lParam ); | |
143 | static LRESULT WINAPI AdvViewerWindowProc( | |
144 | HWND hwnd, | |
145 | UINT uMsg, | |
146 | WPARAM wParam, | |
147 | LPARAM lParam ); | |
148 | #endif | |
149 | ||
150 | ||
151 | //============================================================================== | |
152 | //function : WClass | |
153 | //purpose : | |
154 | //============================================================================== | |
155 | ||
156 | const Handle(MMgt_TShared)& ViewerTest::WClass() | |
157 | { | |
158 | static Handle(MMgt_TShared) theWClass; | |
159 | #ifdef WNT | |
160 | if (theWClass.IsNull()) { | |
161 | theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc, | |
162 | CS_VREDRAW | CS_HREDRAW, 0, 0, | |
163 | ::LoadCursor (NULL, IDC_ARROW)); | |
164 | } | |
165 | #endif | |
166 | return theWClass; | |
167 | } | |
168 | ||
169 | //============================================================================== | |
170 | //function : ViewerInit | |
171 | //purpose : Create the window viewer and initialize all the global variable | |
172 | //============================================================================== | |
173 | ||
174 | void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop, | |
175 | const Standard_Integer thePxWidth, const Standard_Integer thePxHeight) | |
176 | { | |
177 | static Standard_Boolean isFirst = Standard_True; | |
178 | ||
179 | Standard_Integer aPxLeft = 0; | |
180 | Standard_Integer aPxTop = 460; | |
181 | Standard_Integer aPxWidth = 409; | |
182 | Standard_Integer aPxHeight = 409; | |
183 | if (thePxWidth != 0 && thePxHeight != 0) | |
184 | { | |
185 | aPxLeft = thePxLeft; | |
186 | aPxTop = thePxTop; | |
187 | aPxWidth = thePxWidth; | |
188 | aPxHeight = thePxHeight; | |
189 | } | |
190 | ||
191 | if (isFirst) | |
192 | { | |
193 | // Create the Graphic device | |
194 | #ifdef WNT | |
195 | if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice(); | |
196 | if (VT_GetWindow().IsNull()) | |
197 | { | |
198 | // Create the Graphic device and the window | |
199 | Handle(WNT_GraphicDevice) g_Device = new WNT_GraphicDevice(); | |
200 | ||
201 | VT_GetWindow() = new WNT_Window (g_Device, "Test3d", | |
202 | Handle(WNT_WClass)::DownCast (WClass()), | |
203 | WS_OVERLAPPEDWINDOW, | |
204 | aPxLeft, aPxTop, | |
205 | aPxWidth, aPxHeight, | |
206 | Quantity_NOC_BLACK); | |
207 | VT_GetWindow()->SetVirtual (Draw_VirtualWindows); | |
208 | } | |
209 | #else | |
210 | if (GetG3dDevice().IsNull()) GetG3dDevice() = | |
211 | new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY); | |
212 | if (VT_GetWindow().IsNull()) | |
213 | { | |
214 | VT_GetWindow() = new Xw_Window (GetG3dDevice(), | |
215 | "Test3d", | |
216 | aPxLeft, aPxTop, | |
217 | aPxWidth, aPxHeight, | |
218 | Xw_WQ_3DQUALITY, | |
219 | Quantity_NOC_BLACK); | |
220 | VT_GetWindow()->SetVirtual (Draw_VirtualWindows); | |
221 | } | |
222 | #endif | |
223 | ||
224 | Handle(V3d_Viewer) a3DViewer, a3DCollector; | |
225 | // Viewer and View creation | |
226 | ||
227 | TCollection_ExtendedString NameOfWindow("Visu3D"); | |
228 | ||
229 | a3DViewer = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString()); | |
230 | NameOfWindow = TCollection_ExtendedString("Collector"); | |
231 | a3DCollector = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString()); | |
232 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); | |
233 | a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE); | |
234 | Handle(NIS_View) aView = | |
235 | Handle(NIS_View)::DownCast(ViewerTest::CurrentView()); | |
236 | if ( aView.IsNull() ) { | |
237 | // Handle (V3d_View) V = a3DViewer->CreateView(); | |
238 | aView = new NIS_View (a3DViewer, VT_GetWindow()); | |
239 | ViewerTest::CurrentView(aView); | |
240 | TheNISContext()->AttachView (aView); | |
241 | } | |
242 | Handle(V3d_View) a3DViewCol; | |
243 | if ( a3DViewCol.IsNull() ) a3DViewCol = a3DViewer->CreateView(); | |
244 | ||
245 | // AIS setup | |
246 | if ( ViewerTest::GetAISContext().IsNull() ) { | |
247 | Handle(AIS_InteractiveContext) C = | |
248 | new AIS_InteractiveContext(a3DViewer,a3DCollector); | |
249 | ViewerTest::SetAISContext(C); | |
250 | } | |
251 | ||
252 | // Setup for X11 or NT | |
253 | OSWindowSetup(); | |
254 | // Viewer and View creation | |
255 | ||
256 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); | |
257 | ||
258 | Handle (V3d_View) V = ViewerTest::CurrentView(); | |
259 | ||
260 | V->SetDegenerateModeOn(); | |
261 | #ifdef OCC120 | |
262 | DegenerateMode = V->DegenerateModeIsOn(); | |
263 | #endif | |
264 | // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL); | |
265 | ||
266 | V->SetZClippingDepth(0.5); | |
267 | V->SetZClippingWidth(ZCLIPWIDTH/2.); | |
268 | a3DViewer->SetDefaultLights(); | |
269 | a3DViewer->SetLightOn(); | |
270 | ||
271 | #ifndef WNT | |
272 | #if TCL_MAJOR_VERSION < 8 | |
273 | Tk_CreateFileHandler((void*)ConnectionNumber(display), | |
274 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); | |
275 | #else | |
276 | Tk_CreateFileHandler(ConnectionNumber(display), | |
277 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); | |
278 | #endif | |
279 | #endif | |
280 | ||
281 | isFirst = Standard_False; | |
282 | } | |
283 | VT_GetWindow()->Map(); | |
284 | } | |
285 | ||
286 | //============================================================================== | |
287 | //function : Vinit | |
288 | //purpose : Create the window viewer and initialize all the global variable | |
289 | // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event | |
290 | //============================================================================== | |
291 | ||
292 | static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
293 | { | |
294 | Standard_Integer aPxLeft = (argc > 1) ? atoi (argv[1]) : 0; | |
295 | Standard_Integer aPxTop = (argc > 2) ? atoi (argv[2]) : 0; | |
296 | Standard_Integer aPxWidth = (argc > 3) ? atoi (argv[3]) : 0; | |
297 | Standard_Integer aPxHeight = (argc > 4) ? atoi (argv[4]) : 0; | |
298 | ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight); | |
299 | return 0; | |
300 | } | |
301 | ||
302 | //============================================================================== | |
303 | //function : ProcessKeyPress | |
304 | //purpose : Handle KeyPress event from a CString | |
305 | //============================================================================== | |
306 | ||
307 | static void ProcessKeyPress( char *buf_ret ) | |
308 | { | |
309 | //cout << "KeyPress" << endl; | |
310 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
311 | const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView); | |
312 | // Letter in alphabetic order | |
313 | ||
314 | if ( !strcasecmp(buf_ret, "A") ) { | |
315 | // AXO | |
316 | aView->SetProj(V3d_XposYnegZpos); | |
317 | } | |
318 | else if ( !strcasecmp(buf_ret, "D") ) { | |
319 | // Reset | |
320 | aView->Reset(); | |
321 | } | |
322 | else if ( !strcasecmp(buf_ret, "F") ) { | |
323 | // FitAll | |
324 | if (aNisView.IsNull()) | |
325 | aView->FitAll(); | |
326 | else | |
327 | aNisView->FitAll3d(); | |
328 | } | |
329 | else if ( !strcasecmp(buf_ret, "H") ) { | |
330 | // HLR | |
331 | cout << "HLR" << endl; | |
332 | #ifdef OCC120 | |
333 | if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff(); | |
334 | else aView->SetDegenerateModeOn(); | |
335 | DegenerateMode = aView->DegenerateModeIsOn(); | |
336 | #else | |
337 | ViewerTest::CurrentView()->SetDegenerateModeOff(); | |
338 | #endif | |
339 | } | |
340 | else if ( !strcasecmp(buf_ret, "D") ) { | |
341 | // Reset | |
342 | aView->Reset(); | |
343 | } | |
344 | else if ( !strcasecmp(buf_ret, "S") ) { | |
345 | // SHADING | |
346 | cout << "passage en mode 1 (shading pour les shapes)" << endl; | |
347 | #ifndef OCC120 | |
348 | ViewerTest::CurrentView()->SetDegenerateModeOn(); | |
349 | #endif | |
350 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); | |
351 | if(Ctx->NbCurrents()==0 || | |
352 | Ctx->NbSelected()==0) | |
353 | Ctx->SetDisplayMode(AIS_Shaded); | |
354 | else{ | |
355 | if(Ctx->HasOpenedContext()){ | |
356 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
357 | Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False); | |
358 | } | |
359 | else{ | |
360 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
361 | Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False); | |
362 | } | |
363 | Ctx->UpdateCurrentViewer(); | |
364 | } | |
365 | } | |
366 | else if ( !strcasecmp(buf_ret, "U") ) { | |
367 | // SHADING | |
368 | cout<<"passage au mode par defaut"<<endl; | |
369 | #ifndef OCC120 | |
370 | ViewerTest::CurrentView()->SetDegenerateModeOn(); | |
371 | #endif | |
372 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); | |
373 | if(Ctx->NbCurrents()==0 || | |
374 | Ctx->NbSelected()==0) | |
375 | Ctx->SetDisplayMode(AIS_WireFrame); | |
376 | else{ | |
377 | if(Ctx->HasOpenedContext()){ | |
378 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
379 | Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False); | |
380 | } | |
381 | else{ | |
382 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
383 | Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False); | |
384 | } | |
385 | Ctx->UpdateCurrentViewer(); | |
386 | } | |
387 | ||
388 | } | |
389 | else if ( !strcasecmp(buf_ret, "T") ) { | |
390 | // Top | |
391 | aView->SetProj(V3d_Zpos); | |
392 | } | |
393 | else if ( !strcasecmp(buf_ret, "B") ) { | |
394 | // Top | |
395 | aView->SetProj(V3d_Zneg); | |
396 | } | |
397 | else if ( !strcasecmp(buf_ret, "L") ) { | |
398 | // Top | |
399 | aView->SetProj(V3d_Xneg); | |
400 | } | |
401 | else if ( !strcasecmp(buf_ret, "R") ) { | |
402 | // Top | |
403 | aView->SetProj(V3d_Xpos); | |
404 | } | |
405 | ||
406 | else if ( !strcasecmp(buf_ret, "W") ) { | |
407 | // WIREFRAME | |
408 | #ifndef OCC120 | |
409 | ViewerTest::CurrentView()->SetDegenerateModeOn(); | |
410 | #endif | |
411 | cout << "passage en mode 0 (filaire pour les shapes)" << endl; | |
412 | #ifndef OCC120 | |
413 | ViewerTest::CurrentView()->SetDegenerateModeOn(); | |
414 | #endif | |
415 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); | |
416 | if(Ctx->NbCurrents()==0 || | |
417 | Ctx->NbSelected()==0) | |
418 | Ctx->SetDisplayMode(AIS_WireFrame); | |
419 | else{ | |
420 | if(Ctx->HasOpenedContext()){ | |
421 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
422 | Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False); | |
423 | } | |
424 | else{ | |
425 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
426 | Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False); | |
427 | } | |
428 | Ctx->UpdateCurrentViewer(); | |
429 | } | |
430 | } | |
431 | else if ( !strcasecmp(buf_ret, "Z") ) { | |
432 | // ZCLIP | |
433 | ||
434 | if ( ZClipIsOn ) { | |
435 | cout << "ZClipping OFF" << endl; | |
436 | ZClipIsOn = 0; | |
437 | ||
438 | aView->SetZClippingType(V3d_OFF); | |
439 | aView->Redraw(); | |
440 | } | |
441 | else { | |
442 | cout << "ZClipping ON" << endl; | |
443 | ZClipIsOn = 1; | |
444 | ||
445 | aView->SetZClippingType(V3d_FRONT); | |
446 | aView->Redraw(); | |
447 | } | |
448 | } | |
449 | else if ( !strcasecmp(buf_ret, ",") ) { | |
450 | ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView()); | |
451 | ||
452 | ||
453 | } | |
454 | else if ( !strcasecmp(buf_ret, ".") ) { | |
455 | ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView()); | |
456 | } | |
457 | // Number | |
458 | else{ | |
459 | Standard_Integer Num = atoi(buf_ret); | |
460 | if(Num>=0 && Num<=7) | |
461 | ViewerTest::StandardModeActivation(Num); | |
462 | } | |
463 | } | |
464 | ||
465 | //============================================================================== | |
466 | //function : ProcessExpose | |
467 | //purpose : Redraw the View on an Expose Event | |
468 | //============================================================================== | |
469 | ||
470 | static void ProcessExpose( ) | |
471 | { //cout << "Expose" << endl; | |
472 | ViewerTest::CurrentView()->Redraw(); | |
473 | } | |
474 | ||
475 | //============================================================================== | |
476 | //function : ProcessConfigure | |
477 | //purpose : Resize the View on an Configure Event | |
478 | //============================================================================== | |
479 | ||
480 | static void ProcessConfigure() | |
481 | { | |
482 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
483 | V->MustBeResized(); | |
484 | V->Update(); | |
485 | V->Redraw(); | |
486 | } | |
487 | ||
488 | //============================================================================== | |
489 | //function : ProcessButton1Press | |
490 | //purpose : Picking | |
491 | //============================================================================== | |
492 | ||
493 | static Standard_Boolean ProcessButton1Press( | |
494 | Standard_Integer , | |
495 | const char** argv, | |
496 | Standard_Boolean pick, | |
497 | Standard_Boolean shift ) | |
498 | { | |
499 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
500 | if ( pick ) { | |
501 | Standard_Real X, Y, Z; | |
502 | ||
503 | ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z); | |
504 | ||
505 | Draw::Set(argv[1], X); | |
506 | Draw::Set(argv[2], Y); | |
507 | Draw::Set(argv[3], Z);} | |
508 | ||
509 | if(shift) | |
510 | EM->ShiftSelect(); | |
511 | else | |
512 | EM->Select(); | |
513 | ||
514 | pick = 0; | |
515 | return pick; | |
516 | } | |
517 | ||
518 | //============================================================================== | |
519 | //function : ProcessButton3Press | |
520 | //purpose : Start Rotation | |
521 | //============================================================================== | |
522 | ||
523 | static void ProcessButton3Press() | |
524 | ||
525 | { // Start rotation | |
526 | Start_Rot = 1; | |
527 | ViewerTest::CurrentView()->SetDegenerateModeOn(); | |
528 | ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress ); | |
529 | ||
530 | } | |
531 | //============================================================================== | |
532 | //function : ProcessButtonRelease | |
533 | //purpose : Start Rotation | |
534 | //============================================================================== | |
535 | ||
536 | static void ProcessButtonRelease() | |
537 | ||
538 | { // End rotation | |
539 | #ifdef OCC120 | |
540 | if (Start_Rot) { | |
541 | Start_Rot = 0; | |
542 | if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff(); | |
543 | } | |
544 | #else | |
545 | Start_Rot = 0; | |
546 | ViewerTest::CurrentView()->SetDegenerateModeOff(); | |
547 | #endif | |
548 | } | |
549 | ||
550 | //============================================================================== | |
551 | //function : ProcessZClipMotion | |
552 | //purpose : Zoom | |
553 | //============================================================================== | |
554 | ||
555 | void ProcessZClipMotion() | |
556 | { | |
557 | Handle(V3d_View) a3DView = ViewerTest::CurrentView(); | |
558 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { | |
559 | static Standard_Real CurZPos = 0.; | |
560 | ||
561 | //Quantity_Length VDX, VDY; | |
562 | //a3DView->Size(VDX,VDY); | |
563 | //Standard_Real VDZ = a3DView->ZSize(); | |
564 | //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ); | |
565 | ||
566 | Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress); | |
567 | ||
568 | // Front = Depth + width/2. | |
569 | Standard_Real D = 0.5; | |
570 | Standard_Real W = 0.1; | |
571 | ||
572 | CurZPos += (dx); | |
573 | ||
574 | D += CurZPos; | |
575 | ||
576 | //printf("dx %lf Depth %lf Width %lf\n", dx, D, W); | |
577 | ||
578 | a3DView->SetZClippingType(V3d_OFF); | |
579 | a3DView->SetZClippingDepth(D); | |
580 | a3DView->SetZClippingWidth(W); | |
581 | a3DView->SetZClippingType(V3d_FRONT); | |
582 | ||
583 | a3DView->Redraw(); | |
584 | ||
585 | X_ButtonPress = X_Motion; | |
586 | Y_ButtonPress = Y_Motion; | |
587 | } | |
588 | } | |
589 | ||
590 | //============================================================================== | |
591 | //function : ProcessControlButton1Motion | |
592 | //purpose : Zoom | |
593 | //============================================================================== | |
594 | ||
595 | static void ProcessControlButton1Motion() | |
596 | { | |
597 | ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion); | |
598 | ||
599 | X_ButtonPress = X_Motion; | |
600 | Y_ButtonPress = Y_Motion; | |
601 | } | |
602 | ||
603 | //============================================================================== | |
604 | //function : ProcessControlButton2Motion | |
605 | //purpose : Pann | |
606 | //============================================================================== | |
607 | ||
608 | static void ProcessControlButton2Motion() | |
609 | { | |
610 | Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress); | |
611 | Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress); | |
612 | ||
613 | dy = -dy; // Xwindow Y axis is from top to Bottom | |
614 | ||
615 | ViewerTest::CurrentView()->Panning( dx, dy ); | |
616 | ||
617 | X_ButtonPress = X_Motion; | |
618 | Y_ButtonPress = Y_Motion; | |
619 | } | |
620 | ||
621 | //============================================================================== | |
622 | //function : ProcessControlButton3Motion | |
623 | //purpose : Rotation | |
624 | //============================================================================== | |
625 | ||
626 | static void ProcessControlButton3Motion() | |
627 | { | |
628 | if ( Start_Rot ) ViewerTest::CurrentView()->Rotation( X_Motion, Y_Motion); | |
629 | } | |
630 | ||
631 | //============================================================================== | |
632 | //function : ProcessPointerMotion | |
633 | //purpose : Rotation | |
634 | //============================================================================== | |
635 | ||
636 | static void ProcessMotion() | |
637 | { | |
638 | //pre-hilights detected objects at mouse position | |
639 | ||
640 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
641 | EM->MoveTo(X_Motion, Y_Motion); | |
642 | } | |
643 | ||
644 | ||
645 | void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix) | |
646 | { | |
647 | Xpix = X_Motion;Ypix=Y_Motion; | |
648 | } | |
649 | ||
650 | //============================================================================== | |
651 | //function : VAxo | |
652 | //purpose : Switch to an Axonometric view | |
653 | //Draw arg : No args | |
654 | //============================================================================== | |
655 | ||
656 | static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** ) | |
657 | { if ( ViewerTest::CurrentView().IsNull() ) { | |
658 | di<<"La commande vinit n'a pas ete appele avant"<<"\n"; | |
659 | // VInit(di, argc, argv); | |
660 | } | |
661 | ||
662 | ViewerTest::CurrentView()->SetProj(V3d_XposYnegZpos); | |
663 | ||
664 | return 0; | |
665 | } | |
666 | ||
667 | //============================================================================== | |
668 | //function : VTop | |
669 | //purpose : Switch to a Top View | |
670 | //Draw arg : No args | |
671 | //============================================================================== | |
672 | ||
673 | static int VTop(Draw_Interpretor& di, Standard_Integer , const char** ) | |
674 | { | |
675 | ||
676 | if ( ViewerTest::CurrentView().IsNull() ) { | |
677 | di<<"La commande vinit n'a pas ete appele avant"<<"\n"; | |
678 | ||
679 | // VInit(di, , argv); | |
680 | } | |
681 | ||
682 | ViewerTest::CurrentView()->SetProj(V3d_Zpos); | |
683 | return 0; | |
684 | ||
685 | } | |
686 | ||
687 | //============================================================================== | |
688 | //function : VHelp | |
689 | //purpose : Dsiplay help on viewer Keyboead and mouse commands | |
690 | //Draw arg : No args | |
691 | //============================================================================== | |
692 | ||
693 | static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** ) | |
694 | { | |
695 | ||
696 | di << "Q : Quit the application" << "\n"; | |
697 | ||
698 | di << "========================="<<"\n"; | |
699 | di << "F : FitAll" << "\n"; | |
700 | di << "T : TopView" << "\n"; | |
701 | di << "A : AxonometricView" << "\n"; | |
702 | di << "R : ResetView" << "\n"; | |
703 | ||
704 | di << "========================="<<"\n"; | |
705 | di << "S : Shading" << "\n"; | |
706 | di << "W : Wireframe" << "\n"; | |
707 | di << "H : HidelLineRemoval" << "\n"; | |
708 | ||
709 | di << "========================="<<"\n"; | |
710 | di << "Selection mode "<<"\n"; | |
711 | di << "0 : Shape" <<"\n"; | |
712 | di << "1 : Vertex" <<"\n"; | |
713 | di << "2 : Edge" <<"\n"; | |
714 | di << "3 : Wire" <<"\n"; | |
715 | di << "4 : Face" <<"\n"; | |
716 | di << "5 : Shell" <<"\n"; | |
717 | di << "6 : Solid" <<"\n"; | |
718 | di << "7 : Compound" <<"\n"; | |
719 | ||
720 | di << "=========================="<<"\n"; | |
721 | di << "D : Remove Selected Object"<<"\n"; | |
722 | di << "=========================="<<"\n"; | |
723 | ||
724 | return 0; | |
725 | } | |
726 | ||
727 | Standard_Boolean IsDragged = Standard_False; | |
728 | ||
729 | Standard_Integer xx1, yy1, xx2, yy2; | |
730 | //the first and last point in viewer co-ordinates | |
731 | ||
732 | Standard_Boolean DragFirst; | |
733 | ||
734 | ||
735 | #ifdef WNT | |
736 | ||
737 | static Standard_Boolean Ppick = 0; | |
738 | static Standard_Integer Pargc = 0; | |
739 | static const char** Pargv = NULL; | |
740 | ||
741 | ||
742 | static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd, | |
743 | UINT Msg, | |
744 | WPARAM wParam, | |
745 | LPARAM lParam ) | |
746 | { | |
747 | if ( !ViewerTest::CurrentView().IsNull() ) { | |
748 | ||
749 | WPARAM fwKeys = wParam; | |
750 | ||
751 | switch( Msg ) { | |
752 | ||
753 | case WM_LBUTTONUP: | |
754 | IsDragged = Standard_False; | |
755 | if( !DragFirst ) | |
756 | { | |
757 | HDC hdc = GetDC( hwnd ); | |
758 | HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) ); | |
759 | SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) ); | |
760 | SetROP2( hdc, R2_NOT ); | |
761 | Rectangle( hdc, xx1, yy1, xx2, yy2 ); | |
762 | ReleaseDC( hwnd, hdc ); | |
763 | ||
764 | const Handle(ViewerTest_EventManager) EM = | |
765 | ViewerTest::CurrentEventManager(); | |
766 | if ( fwKeys & MK_SHIFT ) | |
767 | EM->ShiftSelect( min( xx1, xx2 ), max( yy1, yy2 ), | |
768 | max( xx1, xx2 ), min( yy1, yy2 )); | |
769 | else | |
770 | EM->Select( min( xx1, xx2 ), max( yy1, yy2 ), | |
771 | max( xx1, xx2 ), min( yy1, yy2 )); | |
772 | } | |
773 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
774 | ||
775 | case WM_LBUTTONDOWN: | |
776 | if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) ) | |
777 | { | |
778 | IsDragged = Standard_True; | |
779 | DragFirst = Standard_True; | |
780 | xx1 = LOWORD(lParam); | |
781 | yy1 = HIWORD(lParam); | |
782 | } | |
783 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
784 | ||
785 | break; | |
786 | ||
787 | case WM_MOUSEMOVE: | |
788 | if( IsDragged ) | |
789 | { | |
790 | HDC hdc = GetDC( hwnd ); | |
791 | ||
792 | HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) ); | |
793 | SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) ); | |
794 | SetROP2( hdc, R2_NOT ); | |
795 | ||
796 | if( !DragFirst ) | |
797 | Rectangle( hdc, xx1, yy1, xx2, yy2 ); | |
798 | ||
799 | DragFirst = Standard_False; | |
800 | xx2 = LOWORD(lParam); | |
801 | yy2 = HIWORD(lParam); | |
802 | ||
803 | Rectangle( hdc, xx1, yy1, xx2, yy2 ); | |
804 | ||
805 | SelectObject( hdc, anObj ); | |
806 | ||
807 | ReleaseDC( hwnd, hdc ); | |
808 | } | |
809 | else | |
810 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
811 | break; | |
812 | ||
813 | default: | |
814 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
815 | } | |
816 | return 0; | |
817 | } | |
818 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
819 | } | |
820 | ||
821 | ||
822 | static LRESULT WINAPI ViewerWindowProc( HWND hwnd, | |
823 | UINT Msg, | |
824 | WPARAM wParam, | |
825 | LPARAM lParam ) | |
826 | { | |
827 | /*static Standard_Boolean Ppick = 0; | |
828 | static Standard_Integer Pargc = 0; | |
829 | static char** Pargv = NULL;*/ | |
830 | ||
831 | static int Up = 1; | |
832 | ||
833 | if ( !ViewerTest::CurrentView().IsNull() ) { | |
834 | PAINTSTRUCT ps; | |
835 | ||
836 | switch( Msg ) { | |
837 | case WM_CLOSE: | |
838 | // do not destroy the window - just hide it! | |
839 | VT_GetWindow()->Unmap(); | |
840 | return 0; | |
841 | case WM_PAINT: | |
842 | //cout << "\t WM_PAINT" << endl; | |
843 | BeginPaint(hwnd, &ps); | |
844 | EndPaint(hwnd, &ps); | |
845 | ProcessExpose(); | |
846 | break; | |
847 | ||
848 | case WM_SIZE: | |
849 | //cout << "\t WM_SIZE" << endl; | |
850 | ProcessConfigure(); | |
851 | break; | |
852 | ||
853 | case WM_KEYDOWN: | |
854 | //cout << "\t WM_KEYDOWN " << (int) wParam << endl; | |
855 | ||
856 | if ( (wParam != VK_SHIFT) && (wParam != VK_CONTROL) ) { | |
857 | char c[2]; | |
858 | c[0] = (char) wParam; | |
859 | c[1] = '\0'; | |
860 | ProcessKeyPress( c); | |
861 | } | |
862 | break; | |
863 | ||
864 | case WM_LBUTTONUP: | |
865 | case WM_MBUTTONUP: | |
866 | case WM_RBUTTONUP: | |
867 | //cout << "\t WM_xBUTTONUP" << endl; | |
868 | Up = 1; | |
869 | ProcessButtonRelease(); | |
870 | break; | |
871 | ||
872 | case WM_LBUTTONDOWN: | |
873 | case WM_MBUTTONDOWN: | |
874 | case WM_RBUTTONDOWN: | |
875 | { | |
876 | //cout << "\t WM_xBUTTONDOWN" << endl; | |
877 | WPARAM fwKeys = wParam; | |
878 | ||
879 | Up = 0; | |
880 | ||
881 | X_ButtonPress = LOWORD(lParam); | |
882 | Y_ButtonPress = HIWORD(lParam); | |
883 | ||
884 | if ( Msg == WM_LBUTTONDOWN) { | |
885 | if(fwKeys & MK_CONTROL) { | |
886 | Ppick = ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) ); | |
887 | } else | |
888 | ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) ); | |
889 | } | |
890 | else if ( Msg == WM_RBUTTONDOWN ) { | |
891 | // Start rotation | |
892 | ProcessButton3Press( ); | |
893 | } | |
894 | } | |
895 | break; | |
896 | ||
897 | case WM_MOUSEMOVE: | |
898 | { | |
899 | //cout << "\t WM_MOUSEMOVE" << endl; | |
900 | WPARAM fwKeys = wParam; | |
901 | X_Motion = LOWORD(lParam); | |
902 | Y_Motion = HIWORD(lParam); | |
903 | ||
904 | if ( Up && | |
905 | fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) { | |
906 | Up = 0; | |
907 | X_ButtonPress = LOWORD(lParam); | |
908 | Y_ButtonPress = HIWORD(lParam); | |
909 | ||
910 | if ( fwKeys & MK_RBUTTON ) { | |
911 | // Start rotation | |
912 | ProcessButton3Press(); | |
913 | } | |
914 | } | |
915 | ||
916 | if ( fwKeys & MK_CONTROL ) { | |
917 | if ( fwKeys & MK_LBUTTON ) { | |
918 | ProcessControlButton1Motion(); | |
919 | } | |
920 | else if ( fwKeys & MK_MBUTTON || | |
921 | ((fwKeys&MK_LBUTTON) && | |
922 | (fwKeys&MK_RBUTTON) ) ){ | |
923 | ProcessControlButton2Motion(); | |
924 | } | |
925 | else if ( fwKeys & MK_RBUTTON ) { | |
926 | ProcessControlButton3Motion(); | |
927 | } | |
928 | } | |
929 | #ifdef BUG | |
930 | else if ( fwKeys & MK_SHIFT ) { | |
931 | if ( fwKeys & MK_MBUTTON || | |
932 | ((fwKeys&MK_LBUTTON) && | |
933 | (fwKeys&MK_RBUTTON) ) ) { | |
934 | cout << "ProcessZClipMotion()" << endl; | |
935 | ProcessZClipMotion(); | |
936 | } | |
937 | } | |
938 | #endif | |
939 | else | |
940 | if (( fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON) ) )){ | |
941 | ProcessZClipMotion(); | |
942 | } | |
943 | else { | |
944 | ProcessMotion(); | |
945 | } | |
946 | } | |
947 | break; | |
948 | ||
949 | default: | |
950 | return( DefWindowProc( hwnd, Msg, wParam, lParam )); | |
951 | } | |
952 | return 0L; | |
953 | } | |
954 | ||
955 | return DefWindowProc( hwnd, Msg, wParam, lParam ); | |
956 | } | |
957 | ||
958 | ||
959 | ||
960 | ||
961 | //============================================================================== | |
962 | //function : ViewerMainLoop | |
963 | //purpose : Get a Event on the view and dispatch it | |
964 | //============================================================================== | |
965 | ||
966 | ||
967 | static int ViewerMainLoop(Standard_Integer argc, const char** argv) | |
968 | { | |
969 | ||
970 | //cout << "No yet implemented on WNT" << endl; | |
971 | /*static Standard_Boolean Ppick = 0; | |
972 | static Standard_Integer Pargc = 0; | |
973 | static char** Pargv = NULL;*/ | |
974 | ||
975 | //Ppick = (argc > 0)? -1 : 0; | |
976 | Ppick = (argc > 0)? 1 : 0; | |
977 | Pargc = argc; | |
978 | Pargv = argv; | |
979 | ||
980 | if ( Ppick ) { | |
981 | MSG msg; | |
982 | msg.wParam = 1; | |
983 | ||
984 | cout << "Start picking" << endl; | |
985 | ||
986 | //while ( Ppick == -1 ) { | |
987 | while ( Ppick == 1 ) { | |
988 | // Wait for a ProcessButton1Press() to toggle pick to 1 or 0 | |
989 | if (GetMessage(&msg, NULL, 0, 0) ) { | |
990 | TranslateMessage(&msg); | |
991 | DispatchMessage(&msg); | |
992 | } | |
993 | } | |
994 | ||
995 | cout << "Picking done" << endl; | |
996 | } | |
997 | ||
998 | return Ppick; | |
999 | } | |
1000 | ||
1001 | ||
1002 | #else | |
1003 | ||
1004 | int min( int a, int b ) | |
1005 | { | |
1006 | if( a<b ) | |
1007 | return a; | |
1008 | else | |
1009 | return b; | |
1010 | } | |
1011 | ||
1012 | int max( int a, int b ) | |
1013 | { | |
1014 | if( a>b ) | |
1015 | return a; | |
1016 | else | |
1017 | return b; | |
1018 | } | |
1019 | ||
1020 | int ViewerMainLoop(Standard_Integer argc, const char** argv) | |
1021 | ||
1022 | { Standard_Boolean pick = argc > 0; | |
1023 | ||
1024 | // X11 Event loop | |
1025 | ||
1026 | static XEvent report; | |
1027 | ||
1028 | XNextEvent( display, &report ); | |
1029 | // cout << "rep type = " << report.type << endl; | |
1030 | // cout << "rep button = " << report.xbutton.button << endl; | |
1031 | ||
1032 | switch ( report.type ) { | |
1033 | case Expose: | |
1034 | { | |
1035 | ProcessExpose(); | |
1036 | } | |
1037 | break; | |
1038 | case ConfigureNotify: | |
1039 | { | |
1040 | ProcessConfigure(); | |
1041 | } | |
1042 | break; | |
1043 | case KeyPress: | |
1044 | { | |
1045 | ||
1046 | KeySym ks_ret ; | |
1047 | char buf_ret[11] ; | |
1048 | int ret_len ; | |
1049 | XComposeStatus status_in_out; | |
1050 | ||
1051 | ret_len = XLookupString( ( XKeyEvent *)&report , | |
1052 | (char *) buf_ret , 10 , | |
1053 | &ks_ret , &status_in_out ) ; | |
1054 | ||
1055 | ||
1056 | buf_ret[ret_len] = '\0' ; | |
1057 | ||
1058 | if ( ret_len ) { | |
1059 | ProcessKeyPress( buf_ret); | |
1060 | } | |
1061 | } | |
1062 | break; | |
1063 | case ButtonPress: | |
1064 | // cout << "ButtonPress" << endl; | |
1065 | { | |
1066 | X_ButtonPress = report.xbutton.x; | |
1067 | Y_ButtonPress = report.xbutton.y; | |
1068 | ||
1069 | if ( report.xbutton.button == Button1 ) | |
1070 | if( report.xbutton.state & ControlMask ) | |
1071 | pick = ProcessButton1Press( argc, argv, pick, | |
1072 | ( report.xbutton.state & ShiftMask) ); | |
1073 | else | |
1074 | { | |
1075 | IsDragged = Standard_True; | |
1076 | xx1 = X_ButtonPress; | |
1077 | yy1 = Y_ButtonPress; | |
1078 | DragFirst = Standard_True; | |
1079 | } | |
1080 | else if ( report.xbutton.button == Button3 ) | |
1081 | // Start rotation | |
1082 | ProcessButton3Press(); | |
1083 | } | |
1084 | break; | |
1085 | case ButtonRelease: | |
1086 | { | |
1087 | // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl; | |
1088 | // cout << IsDragged << endl; | |
1089 | // cout << DragFirst << endl; | |
1090 | ||
1091 | if( IsDragged ) | |
1092 | { | |
1093 | if( !DragFirst ) | |
1094 | { | |
1095 | Aspect_Handle aWindow = VT_GetWindow()->XWindow(); | |
1096 | GC gc = XCreateGC( display, aWindow, 0, 0 ); | |
1097 | // XSetFunction( display, gc, GXinvert ); | |
1098 | XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) ); | |
1099 | } | |
1100 | ||
1101 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
1102 | if( aContext.IsNull() ) | |
1103 | { | |
1104 | cout << "The context is null. Please use vinit before createmesh" << endl; | |
1105 | return 0; | |
1106 | } | |
1107 | ||
1108 | Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask ); | |
1109 | if( report.xbutton.button==1 ) | |
1110 | if( DragFirst ) | |
1111 | if( ShiftPressed ) | |
1112 | { | |
1113 | aContext->ShiftSelect(); | |
1114 | // cout << "shift select" << endl; | |
1115 | } | |
1116 | else | |
1117 | { | |
1118 | aContext->Select(); | |
1119 | // cout << "select" << endl; | |
1120 | } | |
1121 | else | |
1122 | if( ShiftPressed ) | |
1123 | { | |
1124 | aContext->ShiftSelect( min( xx1, xx2 ), min( yy1, yy2 ), | |
1125 | max( xx1, xx2 ), max( yy1, yy2 ), | |
1126 | ViewerTest::CurrentView()); | |
1127 | // cout << "shift select" << endl; | |
1128 | } | |
1129 | else | |
1130 | { | |
1131 | aContext->Select( min( xx1, xx2 ), min( yy1, yy2 ), | |
1132 | max( xx1, xx2 ), max( yy1, yy2 ), | |
1133 | ViewerTest::CurrentView() ); | |
1134 | // cout << "select" << endl; | |
1135 | } | |
1136 | else | |
1137 | ProcessButtonRelease(); | |
1138 | ||
1139 | IsDragged = Standard_False; | |
1140 | } | |
1141 | else | |
1142 | ProcessButtonRelease(); | |
1143 | } | |
1144 | break; | |
1145 | case MotionNotify: | |
1146 | { | |
1147 | // XEvent dummy; | |
1148 | ||
1149 | X_Motion = report.xmotion.x; | |
1150 | Y_Motion = report.xmotion.y; | |
1151 | ||
1152 | if( IsDragged ) | |
1153 | { | |
1154 | Aspect_Handle aWindow = VT_GetWindow()->XWindow(); | |
1155 | GC gc = XCreateGC( display, aWindow, 0, 0 ); | |
1156 | XSetFunction( display, gc, GXinvert ); | |
1157 | ||
1158 | if( !DragFirst ) | |
1159 | XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) ); | |
1160 | ||
1161 | xx2 = X_Motion; | |
1162 | yy2 = Y_Motion; | |
1163 | DragFirst = Standard_False; | |
1164 | ||
1165 | //cout << "draw rect : " << xx2 << ", " << yy2 << endl; | |
1166 | XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) ); | |
1167 | } | |
1168 | else | |
1169 | { | |
1170 | ||
1171 | //cout << "MotionNotify " << X_Motion << "," << Y_Motion << endl; | |
1172 | ||
1173 | // remove all the ButtonMotionMask | |
1174 | while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ; | |
1175 | ||
1176 | if ( ZClipIsOn && report.xmotion.state & ShiftMask ) { | |
1177 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { | |
1178 | ||
1179 | Quantity_Length VDX, VDY; | |
1180 | ||
1181 | ViewerTest::CurrentView()->Size(VDX,VDY); | |
1182 | Standard_Real VDZ =0 ; | |
1183 | VDZ = ViewerTest::CurrentView()->ZSize(); | |
1184 | ||
1185 | // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ); | |
1186 | printf("%f,%f,%f\n", VDX, VDY, VDZ); | |
1187 | ||
1188 | Quantity_Length dx = 0 ; | |
1189 | dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress); | |
1190 | ||
1191 | cout << dx << endl; | |
1192 | ||
1193 | dx = dx / VDX * VDZ; | |
1194 | ||
1195 | cout << dx << endl; | |
1196 | ||
1197 | // Front = Depth + width/2. | |
1198 | //ViewerTest::CurrentView()->SetZClippingDepth(dx); | |
1199 | //ViewerTest::CurrentView()->SetZClippingWidth(0.); | |
1200 | ||
1201 | ViewerTest::CurrentView()->Redraw(); | |
1202 | } | |
1203 | } | |
1204 | ||
1205 | if ( report.xmotion.state & ControlMask ) { | |
1206 | if ( report.xmotion.state & Button1Mask ) { | |
1207 | ProcessControlButton1Motion(); | |
1208 | } | |
1209 | else if ( report.xmotion.state & Button2Mask ) { | |
1210 | ProcessControlButton2Motion(); | |
1211 | } | |
1212 | else if ( report.xmotion.state & Button3Mask ) { | |
1213 | ProcessControlButton3Motion(); | |
1214 | } | |
1215 | } | |
1216 | else { | |
1217 | ProcessMotion(); | |
1218 | } | |
1219 | } | |
1220 | } | |
1221 | break; | |
1222 | } | |
1223 | ||
1224 | ||
1225 | return pick; | |
1226 | } | |
1227 | ||
1228 | //============================================================================== | |
1229 | //function : VProcessEvents | |
1230 | //purpose : call by Tk_CreateFileHandler() to be able to manage the | |
1231 | // event in the Viewer window | |
1232 | //============================================================================== | |
1233 | ||
1234 | static void VProcessEvents(ClientData,int) | |
1235 | { | |
1236 | //cout << "VProcessEvents" << endl; | |
1237 | ||
1238 | // test for X Event | |
1239 | while (XPending(display)) { | |
1240 | ViewerMainLoop( 0, NULL); | |
1241 | } | |
1242 | } | |
1243 | #endif | |
1244 | ||
1245 | //============================================================================== | |
1246 | //function : OSWindowSetup | |
1247 | //purpose : Setup for the X11 window to be able to cath the event | |
1248 | //============================================================================== | |
1249 | ||
1250 | ||
1251 | static void OSWindowSetup() | |
1252 | { | |
1253 | #ifndef WNT | |
1254 | // X11 | |
1255 | ||
1256 | Window window = VT_GetWindow()->XWindow(); | |
1257 | ||
1258 | Standard_Address theDisplay = GetG3dDevice()->XDisplay(); | |
1259 | display = (Display * ) theDisplay; | |
1260 | // display = (Display *)GetG3dDevice()->XDisplay(); | |
1261 | ||
1262 | XSynchronize(display, 1); | |
1263 | ||
1264 | VT_GetWindow()->Map(); | |
1265 | ||
1266 | // X11 : For keyboard on SUN | |
1267 | XWMHints wmhints; | |
1268 | wmhints.flags = InputHint; | |
1269 | wmhints.input = 1; | |
1270 | ||
1271 | XSetWMHints( display, window, &wmhints); | |
1272 | ||
1273 | XSelectInput( display, window, ExposureMask | KeyPressMask | | |
1274 | ButtonPressMask | ButtonReleaseMask | | |
1275 | StructureNotifyMask | | |
1276 | PointerMotionMask | | |
1277 | Button1MotionMask | Button2MotionMask | | |
1278 | Button3MotionMask | |
1279 | ); | |
1280 | ||
1281 | XSynchronize(display, 0); | |
1282 | ||
1283 | #else | |
1284 | // WNT | |
1285 | #endif | |
1286 | ||
1287 | } | |
1288 | ||
1289 | ||
1290 | //============================================================================== | |
1291 | //function : VFit | |
1292 | ||
1293 | //purpose : Fitall, no DRAW arguments | |
1294 | //Draw arg : No args | |
1295 | //============================================================================== | |
1296 | ||
1297 | static int VFit(Draw_Interpretor& , Standard_Integer , const char** ) | |
1298 | { | |
1299 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
1300 | Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView); | |
1301 | if (V.IsNull() == Standard_False) { | |
1302 | V->FitAll3d(); | |
1303 | } else if (aView.IsNull() == Standard_False) { | |
1304 | aView->FitAll(); | |
1305 | } | |
1306 | return 0; | |
1307 | } | |
1308 | ||
1309 | //============================================================================== | |
1310 | //function : VZFit | |
1311 | //purpose : ZFitall, no DRAW arguments | |
1312 | //Draw arg : No args | |
1313 | //============================================================================== | |
1314 | ||
1315 | static int VZFit(Draw_Interpretor& , Standard_Integer , const char** ) | |
1316 | { | |
1317 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
1318 | if ( !V.IsNull() ) V->ZFitAll(); return 0; } | |
1319 | ||
1320 | ||
1321 | static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** ) | |
1322 | { | |
1323 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
1324 | if ( !V.IsNull() ) V->Redraw(); return 0; | |
1325 | } | |
1326 | ||
1327 | ||
1328 | //============================================================================== | |
1329 | //function : VClear | |
1330 | //purpose : Remove all the object from the viewer | |
1331 | //Draw arg : No args | |
1332 | //============================================================================== | |
1333 | ||
1334 | static int VClear(Draw_Interpretor& , Standard_Integer , const char** ) | |
1335 | { | |
1336 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
1337 | if(!V.IsNull()) | |
1338 | ViewerTest::Clear(); | |
1339 | return 0; | |
1340 | } | |
1341 | ||
1342 | //============================================================================== | |
1343 | //function : VPick | |
1344 | //purpose : | |
1345 | //============================================================================== | |
1346 | ||
1347 | static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1348 | { if (ViewerTest::CurrentView().IsNull() ) return 1; | |
1349 | ||
1350 | if ( argc < 4 ) { | |
1351 | di << argv[0] << "Invalid number of arguments" << "\n"; | |
1352 | return 1; | |
1353 | } | |
1354 | ||
1355 | while (ViewerMainLoop( argc, argv)) { | |
1356 | } | |
1357 | ||
1358 | return 0; | |
1359 | } | |
1360 | ||
1361 | ||
1362 | ||
1363 | //============================================================================== | |
1364 | //function : InitViewerTest | |
1365 | //purpose : initialisation de toutes les variables static de ViewerTest (dp) | |
1366 | //============================================================================== | |
1367 | ||
1368 | void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context) | |
1369 | { | |
1370 | Handle(V3d_Viewer) viewer = context->CurrentViewer(); | |
1371 | ViewerTest::SetAISContext(context); | |
1372 | viewer->InitActiveViews(); | |
1373 | Handle(V3d_View) view = viewer->ActiveView(); | |
1374 | if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view); | |
1375 | ViewerTest::ResetEventManager(); | |
1376 | Handle(Aspect_GraphicDevice) device = viewer->Device(); | |
1377 | Handle(Aspect_Window) window = view->Window(); | |
1378 | #ifndef WNT | |
1379 | // X11 | |
1380 | VT_GetWindow() = Handle(Xw_Window)::DownCast(window); | |
1381 | GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device); | |
1382 | OSWindowSetup(); | |
1383 | static int first = 1; | |
1384 | if ( first ) { | |
1385 | #if TCL_MAJOR_VERSION < 8 | |
1386 | Tk_CreateFileHandler((void*)ConnectionNumber(display), | |
1387 | TK_READABLE, VProcessEvents, (ClientData) 0); | |
1388 | #else | |
1389 | Tk_CreateFileHandler(ConnectionNumber(display), | |
1390 | TK_READABLE, VProcessEvents, (ClientData) 0); | |
1391 | #endif | |
1392 | first = 0; | |
1393 | } | |
1394 | #endif | |
1395 | } | |
1396 | ||
1397 | ||
1398 | //============================================================================== | |
1399 | //function : VSetBg | |
1400 | //purpose : Load image as background | |
1401 | //============================================================================== | |
1402 | ||
1403 | static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1404 | { | |
1405 | if (argc < 2 || argc > 3) | |
1406 | { | |
1407 | di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n"; | |
f8b2ed36 | 1408 | di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n"; |
7fd59977 | 1409 | return 1; |
1410 | } | |
1411 | ||
1412 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
1413 | if(AISContext.IsNull()) | |
1414 | { | |
1415 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
1416 | return 1; | |
1417 | } | |
1418 | ||
1419 | Aspect_FillMethod aFillType = Aspect_FM_CENTERED; | |
1420 | if (argc == 3) | |
1421 | { | |
1422 | const char* szType = argv[2]; | |
1423 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
1424 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
1425 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
1426 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
1427 | else | |
1428 | { | |
1429 | di << "Wrong fill type : " << szType << "\n"; | |
1430 | di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
1431 | return 1; | |
1432 | } | |
1433 | } | |
1434 | ||
1435 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
1436 | V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True); | |
1437 | ||
1438 | return 0; | |
1439 | } | |
1440 | ||
f8b2ed36 | 1441 | //============================================================================== |
1442 | //function : VSetBgMode | |
1443 | //purpose : Change background image fill type | |
1444 | //============================================================================== | |
1445 | ||
1446 | static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1447 | { | |
1448 | if (argc != 2) | |
1449 | { | |
1450 | di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n"; | |
1451 | di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
1452 | return 1; | |
1453 | } | |
1454 | ||
1455 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
1456 | if(AISContext.IsNull()) | |
1457 | { | |
1458 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
1459 | return 1; | |
1460 | } | |
1461 | ||
1462 | Aspect_FillMethod aFillType; | |
1463 | if (argc == 2) | |
1464 | { | |
1465 | const char* szType = argv[1]; | |
1466 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
1467 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
1468 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
1469 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
1470 | else | |
1471 | { | |
1472 | di << "Wrong fill type : " << szType << "\n"; | |
1473 | di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
1474 | return 1; | |
1475 | } | |
1476 | } | |
1477 | ||
1478 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
1479 | V3dView->SetBgImageStyle(aFillType, Standard_True); | |
1480 | ||
1481 | return 0; | |
1482 | } | |
1483 | ||
7fd59977 | 1484 | //============================================================================== |
1485 | //function : VSetGradientBg | |
1486 | //purpose : Mount gradient background | |
1487 | //============================================================================== | |
1488 | static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1489 | { | |
1490 | if (argc != 8 ) | |
1491 | { | |
1492 | di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n"; | |
1493 | di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n"; | |
1494 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
1495 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
1496 | return 1; | |
1497 | } | |
1498 | ||
1499 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
1500 | if(AISContext.IsNull()) | |
1501 | { | |
1502 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
1503 | return 1; | |
1504 | } | |
1505 | if (argc == 8) | |
1506 | { | |
1507 | ||
1508 | Standard_Real R1 = atof(argv[1])/255.; | |
1509 | Standard_Real G1 = atof(argv[2])/255.; | |
1510 | Standard_Real B1 = atof(argv[3])/255.; | |
1511 | Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB); | |
1512 | ||
1513 | Standard_Real R2 = atof(argv[4])/255.; | |
1514 | Standard_Real G2 = atof(argv[5])/255.; | |
1515 | Standard_Real B2 = atof(argv[6])/255.; | |
1516 | ||
1517 | Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB); | |
1518 | int aType = atoi(argv[7]); | |
1519 | if( aType < 0 || aType > 8 ) | |
1520 | { | |
1521 | di << "Wrong fill type " << "\n"; | |
1522 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
1523 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
1524 | return 1; | |
1525 | } | |
1526 | ||
1527 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
1528 | ||
1529 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
1530 | V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1); | |
1531 | } | |
1532 | ||
1533 | return 0; | |
1534 | } | |
1535 | ||
f8b2ed36 | 1536 | //============================================================================== |
1537 | //function : VSetGradientBgMode | |
1538 | //purpose : Change gradient background fill style | |
1539 | //============================================================================== | |
1540 | static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1541 | { | |
1542 | if (argc != 2 ) | |
1543 | { | |
1544 | di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n"; | |
1545 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
1546 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
1547 | return 1; | |
1548 | } | |
1549 | ||
1550 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
1551 | if(AISContext.IsNull()) | |
1552 | { | |
1553 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
1554 | return 1; | |
1555 | } | |
1556 | if (argc == 2) | |
1557 | { | |
1558 | int aType = atoi(argv[1]); | |
1559 | if( aType < 0 || aType > 8 ) | |
1560 | { | |
1561 | di << "Wrong fill type " << "\n"; | |
1562 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
1563 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
1564 | return 1; | |
1565 | } | |
1566 | ||
1567 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
1568 | ||
1569 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
1570 | V3dView->SetBgGradientStyle( aMethod, 1 ); | |
1571 | } | |
1572 | ||
1573 | return 0; | |
1574 | } | |
1575 | ||
1576 | //============================================================================== | |
1577 | //function : VSetColorBg | |
1578 | //purpose : Set color background | |
1579 | //============================================================================== | |
1580 | static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1581 | { | |
1582 | if (argc != 4 ) | |
1583 | { | |
1584 | di << "Usage : " << argv[0] << " R G B : Set color background" << "\n"; | |
1585 | di << "R,G,B = [0..255]" << "\n"; | |
1586 | return 1; | |
1587 | } | |
1588 | ||
1589 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
1590 | if(AISContext.IsNull()) | |
1591 | { | |
1592 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
1593 | return 1; | |
1594 | } | |
1595 | if (argc == 4) | |
1596 | { | |
1597 | ||
1598 | Standard_Real R = atof(argv[1])/255.; | |
1599 | Standard_Real G = atof(argv[2])/255.; | |
1600 | Standard_Real B = atof(argv[3])/255.; | |
1601 | Quantity_Color aColor(R,G,B,Quantity_TOC_RGB); | |
1602 | ||
1603 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
1604 | V3dView->SetBackgroundColor( aColor ); | |
1605 | V3dView->Update(); | |
1606 | } | |
1607 | ||
1608 | return 0; | |
1609 | } | |
1610 | ||
7fd59977 | 1611 | //============================================================================== |
1612 | //function : VScale | |
1613 | //purpose : View Scaling | |
1614 | //============================================================================== | |
1615 | ||
1616 | static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1617 | { | |
1618 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
1619 | if ( V3dView.IsNull() ) return 1; | |
1620 | ||
1621 | if ( argc != 4 ) { | |
1622 | di << argv[0] << "Invalid number of arguments" << "\n"; | |
1623 | return 1; | |
1624 | } | |
1625 | V3dView->SetAxialScale( atof(argv[1]), atof(argv[2]), atof(argv[3]) ); | |
1626 | return 0; | |
1627 | } | |
1628 | //============================================================================== | |
1629 | //function : VTestZBuffTrihedron | |
7c8a8fcc | 1630 | //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron |
7fd59977 | 1631 | //============================================================================== |
1632 | ||
1633 | static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1634 | { | |
1635 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
1636 | if ( V3dView.IsNull() ) return 1; | |
1637 | ||
7fd59977 | 1638 | V3dView->ZBufferTriedronSetup(); |
7c8a8fcc | 1639 | |
1640 | if ( argc == 1 ) { | |
1641 | // Set up default trihedron parameters | |
1642 | V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER ); | |
1643 | } else | |
1644 | if ( argc == 7 ) | |
1645 | { | |
1646 | Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER; | |
1647 | const char* aPosType = argv[1]; | |
1648 | ||
1649 | if ( strcmp(aPosType, "center") == 0 ) | |
1650 | { | |
1651 | aPosition = Aspect_TOTP_CENTER; | |
1652 | } else | |
1653 | if (strcmp(aPosType, "left_lower") == 0) | |
1654 | { | |
1655 | aPosition = Aspect_TOTP_LEFT_LOWER; | |
1656 | } else | |
1657 | if (strcmp(aPosType, "left_upper") == 0) | |
1658 | { | |
1659 | aPosition = Aspect_TOTP_LEFT_UPPER; | |
1660 | } else | |
1661 | if (strcmp(aPosType, "right_lower") == 0) | |
1662 | { | |
1663 | aPosition = Aspect_TOTP_RIGHT_LOWER; | |
1664 | } else | |
1665 | if (strcmp(aPosType, "right_upper") == 0) | |
1666 | { | |
1667 | aPosition = Aspect_TOTP_RIGHT_UPPER; | |
1668 | } else | |
1669 | { | |
1670 | di << argv[1] << " Invalid type of alignment" << "\n"; | |
1671 | di << "Must be one of [ center, left_lower," << "\n"; | |
1672 | di << "left_upper, right_lower, right_upper ]" << "\n"; | |
1673 | return 1; | |
1674 | } | |
1675 | ||
1676 | Standard_Real R = atof(argv[2])/255.; | |
1677 | Standard_Real G = atof(argv[3])/255.; | |
1678 | Standard_Real B = atof(argv[4])/255.; | |
1679 | Quantity_Color aColor(R, G, B, Quantity_TOC_RGB); | |
1680 | ||
1681 | Standard_Real aScale = atof(argv[5]); | |
1682 | ||
1683 | if( aScale <= 0.0 ) | |
1684 | { | |
1685 | di << argv[5] << " Invalid value. Must be > 0" << "\n"; | |
1686 | return 1; | |
1687 | } | |
1688 | ||
1689 | V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER; | |
1690 | const char* aPresType = argv[6]; | |
1691 | ||
1692 | if ( strcmp(aPresType, "wireframe") == 0 ) | |
1693 | { | |
1694 | aPresentation = V3d_WIREFRAME; | |
1695 | } else | |
1696 | if (strcmp(aPresType, "zbuffer") == 0) | |
1697 | { | |
1698 | aPresentation = V3d_ZBUFFER; | |
1699 | } else | |
1700 | { | |
1701 | di << argv[6] << " Invalid type of visualization" << "\n"; | |
1702 | di << "Must be one of [ wireframe, zbuffer ]" << "\n"; | |
1703 | return 1; | |
1704 | } | |
1705 | ||
1706 | V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation ); | |
1707 | ||
1708 | } else | |
1709 | { | |
1710 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
1711 | return 1; | |
1712 | } | |
1713 | ||
7fd59977 | 1714 | V3dView->ZFitAll(); |
7c8a8fcc | 1715 | |
7fd59977 | 1716 | return 0; |
1717 | } | |
1718 | ||
1719 | //============================================================================== | |
1720 | //function : VRotate | |
1721 | //purpose : Camera Rotating | |
1722 | //============================================================================== | |
1723 | ||
1724 | static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
1725 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
1726 | if ( V3dView.IsNull() ) { | |
1727 | return 1; | |
1728 | } | |
1729 | ||
1730 | if ( argc == 4 ) { | |
1731 | V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]) ); | |
1732 | return 0; | |
1733 | } else if ( argc == 7 ) { | |
1734 | V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]), atof(argv[6]) ); | |
1735 | return 0; | |
1736 | } else { | |
1737 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
1738 | return 1; | |
1739 | } | |
1740 | } | |
1741 | ||
1742 | //============================================================================== | |
1743 | //function : VZoom | |
1744 | //purpose : View zoom in / out (relative to current zoom) | |
1745 | //============================================================================== | |
1746 | ||
1747 | static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
1748 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
1749 | if ( V3dView.IsNull() ) { | |
1750 | return 1; | |
1751 | } | |
1752 | ||
1753 | if ( argc == 2 ) { | |
1754 | Standard_Real coef = atof(argv[1]); | |
1755 | if ( coef <= 0.0 ) { | |
1756 | di << argv[1] << "Invalid value" << "\n"; | |
1757 | return 1; | |
1758 | } | |
1759 | V3dView->SetZoom( atof(argv[1]) ); | |
1760 | return 0; | |
1761 | } else { | |
1762 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
1763 | return 1; | |
1764 | } | |
1765 | } | |
1766 | ||
1767 | //============================================================================== | |
1768 | //function : VPan | |
1769 | //purpose : View panning (in pixels) | |
1770 | //============================================================================== | |
1771 | ||
1772 | static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
1773 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
1774 | if ( V3dView.IsNull() ) return 1; | |
1775 | ||
1776 | if ( argc == 3 ) { | |
1777 | V3dView->Pan( atoi(argv[1]), atoi(argv[2]) ); | |
1778 | return 0; | |
1779 | } else { | |
1780 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
1781 | return 1; | |
1782 | } | |
1783 | } | |
1784 | ||
1785 | ||
1786 | //============================================================================== | |
1787 | //function : VExport | |
5cedc27f | 1788 | //purpose : Export the view to a vector graphic format (PS, EMF, PDF) |
7fd59977 | 1789 | //============================================================================== |
1790 | ||
1791 | static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1792 | { | |
1793 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
5cedc27f K |
1794 | if (V3dView.IsNull()) |
1795 | return 1; | |
7fd59977 | 1796 | |
5cedc27f K |
1797 | if (argc == 1) |
1798 | { | |
1799 | std::cout << "Usage: " << argv[0] << " Filename [Format]\n"; | |
7fd59977 | 1800 | return 1; |
1801 | } | |
1802 | ||
5cedc27f K |
1803 | Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF; |
1804 | TCollection_AsciiString aFormatStr; | |
1805 | ||
1806 | TCollection_AsciiString aFileName (argv[1]); | |
1807 | Standard_Integer aLen = aFileName.Length(); | |
1808 | ||
1809 | if (argc > 2) | |
1810 | { | |
1811 | aFormatStr = TCollection_AsciiString (argv[2]); | |
1812 | } | |
1813 | else if (aLen >= 4) | |
1814 | { | |
1815 | if (aFileName.Value (aLen - 2) == '.') | |
1816 | { | |
1817 | aFormatStr = aFileName.SubString (aLen - 1, aLen); | |
1818 | } | |
1819 | else if (aFileName.Value (aLen - 3) == '.') | |
1820 | { | |
1821 | aFormatStr = aFileName.SubString (aLen - 2, aLen); | |
1822 | } | |
1823 | else | |
1824 | { | |
1825 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
1826 | return 1; | |
1827 | } | |
1828 | } | |
1829 | else | |
1830 | { | |
1831 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
1832 | return 1; | |
1833 | } | |
1834 | ||
1835 | aFormatStr.UpperCase(); | |
1836 | if (aFormatStr == "PS") | |
1837 | anExpFormat = Graphic3d_EF_PostScript; | |
1838 | else if (aFormatStr == "EPS") | |
1839 | anExpFormat = Graphic3d_EF_EnhPostScript; | |
1840 | else if (aFormatStr == "TEX") | |
1841 | anExpFormat = Graphic3d_EF_TEX; | |
1842 | else if (aFormatStr == "PDF") | |
1843 | anExpFormat = Graphic3d_EF_PDF; | |
1844 | else if (aFormatStr == "SVG") | |
1845 | anExpFormat = Graphic3d_EF_SVG; | |
1846 | else if (aFormatStr == "PGF") | |
1847 | anExpFormat = Graphic3d_EF_PGF; | |
1848 | else if (aFormatStr == "EMF") | |
1849 | anExpFormat = Graphic3d_EF_EMF; | |
1850 | else | |
1851 | { | |
1852 | std::cout << "Invalid export format '" << aFormatStr << "'\n"; | |
1853 | return 1; | |
1854 | } | |
1855 | ||
1856 | if (!V3dView->View()->Export (argv[1], anExpFormat)) | |
1857 | { | |
1858 | std::cout << "Export failed!\n"; | |
1859 | return 1; | |
1860 | } | |
7fd59977 | 1861 | return 0; |
1862 | } | |
1863 | ||
1864 | //============================================================================== | |
1865 | //function : VColorScale | |
1866 | //purpose : representation color scale | |
1867 | //============================================================================== | |
1868 | #include <V3d_ColorScale.hxx> | |
1869 | ||
1870 | static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) | |
1871 | { | |
1872 | if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 ) | |
1873 | { | |
1874 | di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n"; | |
1875 | return 1; | |
1876 | } | |
1877 | ||
1878 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
1879 | if(aContext.IsNull()) { | |
1880 | di << argv[0] << " ERROR : use 'vinit' command before " << "\n"; | |
1881 | return -1; | |
1882 | } | |
1883 | ||
1884 | Standard_Real minRange = 0. , maxRange = 100. ; | |
1885 | ||
1886 | Standard_Integer numIntervals = 10 ; | |
1887 | Standard_Real textHeight = 16. ; | |
1888 | Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT; | |
1889 | Standard_Real X = 0., Y = 0. ; | |
1890 | ||
1891 | if ( argc < 9 ) | |
1892 | { | |
1893 | if( argc > 3 ) | |
1894 | { | |
1895 | minRange = atof( argv[1] ); | |
1896 | maxRange = atof( argv[2] ); | |
1897 | numIntervals = atoi( argv[3] ); | |
1898 | } | |
1899 | if ( argc > 4 ) | |
1900 | textHeight = atof( argv[4] ); | |
1901 | if ( argc > 5 ) | |
1902 | position = (Aspect_TypeOfColorScalePosition)atoi( argv[5] ); | |
1903 | if ( argc > 7 ) | |
1904 | { | |
1905 | X = atof( argv[6] ); | |
1906 | Y = atof( argv[7] ); | |
1907 | } | |
1908 | } | |
1909 | Handle(V3d_View) curView = ViewerTest::CurrentView( ); | |
1910 | if ( curView.IsNull( ) ) | |
1911 | return 1; | |
1912 | Handle(Aspect_ColorScale) aCSV = curView->ColorScale( ); | |
1913 | Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) ); | |
1914 | if( ! aCS.IsNull( ) ) | |
1915 | { | |
1916 | aCS->SetPosition( X , Y ); | |
1917 | aCS->SetHeight( 0.95) ; | |
1918 | aCS->SetTextHeight( textHeight ); | |
1919 | aCS->SetRange( minRange , maxRange ); | |
1920 | aCS->SetNumberOfIntervals( numIntervals ); | |
1921 | aCS->SetLabelPosition( position ); | |
1922 | if( !curView->ColorScaleIsDisplayed() ) | |
1923 | curView->ColorScaleDisplay( ); | |
1924 | } | |
1925 | return 0; | |
1926 | } | |
1927 | ||
1928 | //============================================================================== | |
1929 | //function : VGraduatedTrihedron | |
1930 | //purpose : Displays a graduated trihedron | |
1931 | //============================================================================== | |
13a22457 S |
1932 | |
1933 | static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg) | |
1934 | { | |
1935 | const char *str = arg; | |
1936 | while (*str) | |
1937 | { | |
1938 | unsigned short c1 = *str++; | |
1939 | unsigned short c2 = *str++; | |
1940 | if (!c1 || !c2) break; | |
1941 | name += (Standard_ExtCharacter)((c1 << 8) | c2); | |
1942 | } | |
1943 | } | |
1944 | ||
7fd59977 | 1945 | static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
1946 | { | |
13a22457 S |
1947 | // Check arguments |
1948 | if (argc != 2 && argc < 5) | |
1949 | { | |
1950 | di<<"Error: "<<argv[0]<<" - invalid number of arguments\n"; | |
1951 | di<<"Usage: type help "<<argv[0]<<"\n"; | |
1952 | return 1; //TCL_ERROR | |
1953 | } | |
7fd59977 | 1954 | |
13a22457 S |
1955 | Handle(V3d_View) aV3dView = ViewerTest::CurrentView(); |
1956 | ||
1957 | // Create 3D view if it doesn't exist | |
1958 | if ( aV3dView.IsNull() ) | |
7fd59977 | 1959 | { |
13a22457 S |
1960 | ViewerTest::ViewerInit(); |
1961 | aV3dView = ViewerTest::CurrentView(); | |
1962 | if( aV3dView.IsNull() ) | |
1963 | { | |
1964 | di << "Error: Cannot create a 3D view\n"; | |
1965 | return 1; //TCL_ERROR | |
1966 | } | |
7fd59977 | 1967 | } |
1968 | ||
13a22457 S |
1969 | // Erase (==0) or display (!=0) |
1970 | const int display = atoi(argv[1]); | |
7fd59977 | 1971 | |
13a22457 | 1972 | if (display) |
7fd59977 | 1973 | { |
13a22457 S |
1974 | // Text font |
1975 | TCollection_AsciiString font; | |
1976 | if (argc < 6) | |
1977 | font.AssignCat("Courier"); | |
1978 | else | |
1979 | font.AssignCat(argv[5]); | |
1980 | ||
1981 | // Text is multibyte | |
1982 | const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (atoi(argv[6]) != 0); | |
1983 | ||
1984 | // Set axis names | |
1985 | TCollection_ExtendedString xname, yname, zname; | |
1986 | if (argc >= 5) | |
1987 | { | |
1988 | if (isMultibyte) | |
7fd59977 | 1989 | { |
13a22457 S |
1990 | AddMultibyteString(xname, argv[2]); |
1991 | AddMultibyteString(yname, argv[3]); | |
1992 | AddMultibyteString(zname, argv[4]); | |
7fd59977 | 1993 | } |
13a22457 S |
1994 | else |
1995 | { | |
1996 | xname += argv[2]; | |
1997 | yname += argv[3]; | |
1998 | zname += argv[4]; | |
1999 | } | |
2000 | } | |
2001 | else | |
2002 | { | |
2003 | xname += "X (mm)"; | |
2004 | yname += "Y (mm)"; | |
2005 | zname += "Z (mm)"; | |
2006 | } | |
7fd59977 | 2007 | |
13a22457 S |
2008 | aV3dView->GraduatedTrihedronDisplay(xname, yname, zname, |
2009 | Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/, | |
2010 | Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/, | |
2011 | Standard_True/*drawgrid*/, | |
2012 | Standard_True/*drawaxes*/, | |
2013 | 5/*nbx*/, 5/*nby*/, 5/*nbz*/, | |
2014 | 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/, | |
2015 | 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/, | |
2016 | Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/, | |
2017 | 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/, | |
2018 | Quantity_NOC_WHITE/*gridcolor*/, | |
2019 | Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/, | |
2020 | Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font); | |
2021 | } | |
7fd59977 | 2022 | else |
13a22457 | 2023 | aV3dView->GraduatedTrihedronErase(); |
7fd59977 | 2024 | |
2025 | ViewerTest::GetAISContext()->UpdateCurrentViewer(); | |
13a22457 S |
2026 | aV3dView->Redraw(); |
2027 | ||
7fd59977 | 2028 | return 0; |
2029 | } | |
2030 | ||
7edf74fd A |
2031 | //============================================================================== |
2032 | //function : VPrintView | |
2033 | //purpose : Test printing algorithm, print the view to image file with given | |
2034 | // width and height. Printing implemented only for WNT. | |
2035 | //============================================================================== | |
2036 | static int VPrintView (Draw_Interpretor& di, Standard_Integer argc, | |
2037 | const char** argv) | |
2038 | { | |
2039 | #ifndef WNT | |
2040 | di << "Printing implemented only for wnt!\n"; | |
2041 | return 1; | |
2042 | #else | |
2043 | ||
2044 | Handle(AIS_InteractiveContext) aContextAIS = NULL; | |
2045 | Handle(V3d_View) aView = NULL; | |
2046 | aContextAIS = ViewerTest::GetAISContext(); | |
2047 | if (!aContextAIS.IsNull()) | |
2048 | { | |
2049 | const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer(); | |
2050 | Vwr->InitActiveViews(); | |
2051 | if(Vwr->MoreActiveViews()) | |
2052 | aView = Vwr->ActiveView(); | |
2053 | } | |
2054 | ||
2055 | // check for errors | |
2056 | if (aView.IsNull()) | |
2057 | { | |
2058 | di << "Call vinit before!\n"; | |
2059 | return 1; | |
2060 | } | |
2061 | else if (argc < 4) | |
2062 | { | |
2063 | di << "Use: " << argv[0]; | |
2064 | di << " width height filename [print algo=0]\n"; | |
2065 | di << "width, height of the intermediate buffer for operation\n"; | |
2066 | di << "algo : {0|1}\n"; | |
2067 | di << " 0 - stretch algorithm\n"; | |
2068 | di << " 1 - tile algorithm\n"; | |
2069 | di << "test printing algorithms into an intermediate buffer\n"; | |
2070 | di << "with saving output to an image file\n"; | |
2071 | return 1; | |
2072 | } | |
2073 | ||
2074 | // get the input params | |
2075 | Standard_Integer aWidth = atoi (argv[1]); | |
2076 | Standard_Integer aHeight = atoi (argv[2]); | |
2077 | Standard_Integer aMode = 0; | |
2078 | TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]); | |
2079 | if (argc==5) | |
2080 | aMode = atoi (argv[4]); | |
2081 | ||
2082 | // check the input parameters | |
2083 | if (aWidth <= 0 || aHeight <= 0) | |
2084 | { | |
2085 | di << "Width and height must be positive values!\n"; | |
2086 | return 1; | |
2087 | } | |
2088 | if (aMode != 0 && aMode != 1) | |
2089 | aMode = 0; | |
2090 | ||
2091 | Image_CRawBufferData aRawBuffer; | |
2092 | HDC anDC = CreateCompatibleDC(0); | |
2093 | ||
2094 | // define compatible bitmap | |
2095 | BITMAPINFO aBitmapData; | |
2096 | memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER)); | |
2097 | aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); | |
2098 | aBitmapData.bmiHeader.biWidth = aWidth ; | |
2099 | aBitmapData.bmiHeader.biHeight = aHeight; | |
2100 | aBitmapData.bmiHeader.biPlanes = 1; | |
2101 | aBitmapData.bmiHeader.biBitCount = 24; | |
2102 | aBitmapData.bmiHeader.biXPelsPerMeter = 0; | |
2103 | aBitmapData.bmiHeader.biYPelsPerMeter = 0; | |
2104 | aBitmapData.bmiHeader.biClrUsed = 0; | |
2105 | aBitmapData.bmiHeader.biClrImportant = 0; | |
2106 | aBitmapData.bmiHeader.biCompression = BI_RGB; | |
2107 | aBitmapData.bmiHeader.biSizeImage = 0; | |
2108 | ||
2109 | // Create Device Independent Bitmap | |
2110 | HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS, | |
2111 | &aRawBuffer.dataPtr, NULL, 0); | |
2112 | HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap); | |
2113 | ||
2114 | Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False; | |
2115 | if (aRawBuffer.dataPtr != 0) | |
2116 | { | |
2117 | if (aMode == 0) | |
2118 | isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH); | |
2119 | else | |
2120 | isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE); | |
2121 | ||
2122 | // succesfully printed into an intermediate buffer | |
2123 | if (isPrinted) | |
2124 | { | |
2125 | Handle(Image_PixMap) anImageBitmap = | |
2126 | new Image_PixMap ((Standard_PByte)aRawBuffer.dataPtr, | |
2127 | aWidth, aHeight, | |
2128 | aWidth*3 + aWidth%4, 24, 0); | |
2129 | isSaved = anImageBitmap->Dump(aFileName.ToCString()); | |
2130 | } | |
2131 | else | |
2132 | { | |
2133 | di << "Print operation failed due to printing errors or\n"; | |
2134 | di << "insufficient memory available\n"; | |
2135 | di << "Please, try to use smaller dimensions for this test\n"; | |
2136 | di << "command, as it allocates intermediate buffer for storing\n"; | |
2137 | di << "the result\n"; | |
2138 | } | |
2139 | } | |
2140 | else | |
2141 | { | |
2142 | di << "Can't allocate memory for intermediate buffer\n"; | |
2143 | di << "Please use smaller dimensions\n"; | |
2144 | } | |
2145 | ||
2146 | if (aMemoryBitmap) | |
2147 | { | |
2148 | SelectObject (anDC, anOldBitmap); | |
2149 | DeleteObject (aMemoryBitmap); | |
2150 | DeleteDC(anDC); | |
2151 | } | |
2152 | ||
2153 | if (!isSaved) | |
2154 | { | |
2155 | di << "Save to file operation failed. This operation may fail\n"; | |
2156 | di << "if you don't have enough available memory, then you can\n"; | |
2157 | di << "use smaller dimensions for the output file\n"; | |
2158 | return 1; | |
2159 | } | |
2160 | ||
2161 | return 0; | |
2162 | ||
2163 | #endif | |
2164 | } | |
2165 | ||
59f45b7c | 2166 | //============================================================================== |
2167 | //function : VZLayer | |
2168 | //purpose : Test z layer operations for v3d viewer | |
2169 | //============================================================================== | |
2170 | static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2171 | { | |
2172 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext (); | |
2173 | if (aContextAIS.IsNull()) | |
2174 | { | |
2175 | di << "Call vinit before!\n"; | |
2176 | return 1; | |
2177 | } | |
2178 | else if (argc < 2) | |
2179 | { | |
2180 | di << "Use: vzlayer " << argv[0]; | |
2181 | di << " add/del/get [id]\n"; | |
2182 | di << " add - add new z layer to viewer and print its id\n"; | |
2183 | di << " del - del z layer by its id\n"; | |
2184 | di << " get - print sequence of z layers in increasing order of their overlay level\n"; | |
2185 | di << "id - the layer identificator value defined when removing z layer\n"; | |
2186 | return 1; | |
2187 | } | |
2188 | ||
2189 | const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); | |
2190 | if (aViewer.IsNull()) | |
2191 | { | |
2192 | di << "No active viewer!\n"; | |
2193 | return 1; | |
2194 | } | |
2195 | ||
2196 | // perform operation | |
2197 | TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]); | |
2198 | if (anOp == "add") | |
2199 | { | |
2200 | Standard_Integer aNewId; | |
2201 | if (!aViewer->AddZLayer (aNewId)) | |
2202 | { | |
2203 | di << "Impossible to add new z layer!\n"; | |
2204 | return 1; | |
2205 | } | |
2206 | ||
2207 | di << "New z layer added with index: " << aNewId << "\n"; | |
2208 | } | |
2209 | else if (anOp == "del") | |
2210 | { | |
2211 | if (argc < 3) | |
2212 | { | |
2213 | di << "Please also provide as argument id of z layer to remove\n"; | |
2214 | return 1; | |
2215 | } | |
2216 | ||
2217 | Standard_Integer aDelId = atoi (argv[2]); | |
2218 | if (!aViewer->RemoveZLayer (aDelId)) | |
2219 | { | |
2220 | di << "Impossible to remove the z layer or invalid id!\n"; | |
2221 | return 1; | |
2222 | } | |
2223 | ||
2224 | di << "Z layer " << aDelId << " has been removed\n"; | |
2225 | } | |
2226 | else if (anOp == "get") | |
2227 | { | |
2228 | TColStd_SequenceOfInteger anIds; | |
2229 | aViewer->GetAllZLayers (anIds); | |
2230 | for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++) | |
2231 | { | |
2232 | di << anIds.Value (aSeqIdx) << " "; | |
2233 | } | |
2234 | ||
2235 | di << "\n"; | |
2236 | } | |
2237 | else | |
2238 | { | |
2239 | di << "Invalid operation, please use { add / del / get }\n"; | |
2240 | return 1; | |
2241 | } | |
2242 | ||
2243 | return 0; | |
2244 | } | |
2245 | ||
25289ec1 | 2246 | DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem) |
2247 | ||
2248 | // this class provides a presentation of text item in v3d view under-/overlayer | |
2249 | class V3d_TextItem : public Visual3d_LayerItem | |
2250 | { | |
2251 | public: | |
2252 | ||
2253 | // CASCADE RTTI | |
2254 | DEFINE_STANDARD_RTTI(V3d_TextItem) | |
2255 | ||
2256 | // constructor | |
2257 | Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText, | |
2258 | const Standard_Real theX1, | |
2259 | const Standard_Real theY1, | |
2260 | const Standard_Real theHeight, | |
2261 | const TCollection_AsciiString& theFontName, | |
2262 | const Quantity_Color& theColor, | |
2263 | const Quantity_Color& theSubtitleColor, | |
2264 | const Aspect_TypeOfDisplayText& theTypeOfDisplay, | |
2265 | const Handle(Visual3d_Layer)& theLayer); | |
2266 | ||
2267 | // redraw method | |
2268 | Standard_EXPORT void RedrawLayerPrs(); | |
2269 | ||
2270 | private: | |
2271 | ||
2272 | Standard_Real myX1; | |
2273 | Standard_Real myY1; | |
2274 | Standard_Real myHeight; | |
2275 | TCollection_AsciiString myText; | |
2276 | TCollection_AsciiString myFontName; | |
2277 | Quantity_Color myColor; | |
2278 | Quantity_Color mySubtitleColor; | |
2279 | Aspect_TypeOfDisplayText myType; | |
2280 | Handle(Visual3d_Layer) myLayer; | |
2281 | ||
2282 | }; | |
2283 | ||
2284 | IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem) | |
2285 | IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem) | |
2286 | ||
2287 | // create and add to display the text item | |
2288 | V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText, | |
2289 | const Standard_Real theX1, | |
2290 | const Standard_Real theY1, | |
2291 | const Standard_Real theHeight, | |
2292 | const TCollection_AsciiString& theFontName, | |
2293 | const Quantity_Color& theColor, | |
2294 | const Quantity_Color& theSubtitleColor, | |
2295 | const Aspect_TypeOfDisplayText& theTypeOfDisplay, | |
2296 | const Handle(Visual3d_Layer)& theLayer) | |
2297 | : myX1 (theX1), myY1 (theY1), | |
2298 | myText (theText), | |
2299 | myHeight (theHeight), | |
2300 | myLayer (theLayer), | |
2301 | myColor (theColor), | |
2302 | mySubtitleColor (theSubtitleColor), | |
2303 | myType (theTypeOfDisplay), | |
2304 | myFontName (theFontName) | |
2305 | { | |
2306 | if (!myLayer.IsNull ()) | |
2307 | myLayer->AddLayerItem (this); | |
2308 | } | |
2309 | ||
2310 | // render item | |
2311 | void V3d_TextItem::RedrawLayerPrs () | |
2312 | { | |
2313 | if (myLayer.IsNull ()) | |
2314 | return; | |
2315 | ||
2316 | myLayer->SetColor (myColor); | |
2317 | myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor); | |
2318 | myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight); | |
2319 | } | |
2320 | ||
20637bd2 | 2321 | DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem) |
2322 | ||
2323 | // The Visual3d_LayerItem line item for "vlayerline" command | |
2324 | // it provides a presentation of line with user-defined | |
2325 | // linewidth, linetype and transparency. | |
2326 | class V3d_LineItem : public Visual3d_LayerItem | |
2327 | { | |
2328 | public: | |
2329 | // CASCADE RTTI | |
2330 | DEFINE_STANDARD_RTTI(V3d_LineItem) | |
2331 | ||
2332 | // constructor | |
2333 | Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1, | |
2334 | Standard_Real X2, Standard_Real Y2, | |
2335 | V3d_LayerMgrPointer theLayerMgr, | |
2336 | Aspect_TypeOfLine theType = Aspect_TOL_SOLID, | |
2337 | Standard_Real theWidth = 0.5, | |
2338 | Standard_Real theTransp = 1.0); | |
2339 | ||
2340 | // redraw method | |
2341 | Standard_EXPORT void RedrawLayerPrs(); | |
2342 | ||
2343 | private: | |
2344 | ||
2345 | Standard_Real myX1, myY1, myX2, myY2; | |
2346 | Standard_Real myWidth; | |
2347 | Standard_Real myTransparency; | |
2348 | Aspect_TypeOfLine myType; | |
2349 | V3d_LayerMgrPointer myLayerMgr; | |
2350 | }; | |
2351 | ||
2352 | IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem) | |
2353 | IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem) | |
2354 | ||
2355 | // default constructor for line item | |
2356 | V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1, | |
2357 | Standard_Real X2, Standard_Real Y2, | |
2358 | V3d_LayerMgrPointer theLayerMgr, | |
2359 | Aspect_TypeOfLine theType, | |
2360 | Standard_Real theWidth, | |
2361 | Standard_Real theTransp) : | |
2362 | myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr), | |
2363 | myType(theType), myWidth(theWidth), myTransparency(theTransp) | |
2364 | { | |
2365 | if (myLayerMgr && myLayerMgr->Overlay()) | |
2366 | myLayerMgr->Overlay()->AddLayerItem (this); | |
2367 | } | |
2368 | ||
2369 | // render line | |
2370 | void V3d_LineItem::RedrawLayerPrs () | |
2371 | { | |
2372 | Handle (Visual3d_Layer) aOverlay; | |
2373 | ||
2374 | if (myLayerMgr) | |
2375 | aOverlay = myLayerMgr->Overlay(); | |
2376 | ||
2377 | if (!aOverlay.IsNull()) | |
2378 | { | |
2379 | Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB); | |
2380 | aOverlay->SetColor(aColor); | |
2381 | aOverlay->SetTransparency((Standard_ShortReal)myTransparency); | |
2382 | aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth); | |
2383 | aOverlay->BeginPolyline(); | |
2384 | aOverlay->AddVertex(myX1, myY1); | |
2385 | aOverlay->AddVertex(myX2, myY2); | |
2386 | aOverlay->ClosePrimitive(); | |
2387 | } | |
2388 | } | |
2389 | ||
2390 | //============================================================================= | |
2391 | //function : VLayerLine | |
2392 | //purpose : Draws line in the v3d view layer with given attributes: linetype, | |
2393 | // : linewidth, transparency coefficient | |
2394 | //============================================================================ | |
2395 | static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2396 | { | |
2397 | // get the active view | |
2398 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
2399 | if (aView.IsNull()) | |
2400 | { | |
2401 | di << "Call vinit before!\n"; | |
2402 | return 1; | |
2403 | } | |
2404 | else if (argc < 5) | |
2405 | { | |
2406 | di << "Use: " << argv[0]; | |
2407 | di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n"; | |
2408 | di << " linetype : { 0 | 1 | 2 | 3 } \n"; | |
2409 | di << " 0 - solid \n"; | |
2410 | di << " 1 - dashed \n"; | |
2411 | di << " 2 - dot \n"; | |
2412 | di << " 3 - dashdot\n"; | |
2413 | di << " transparency : { 0.0 - 1.0 } \n"; | |
2414 | di << " 0.0 - transparent\n"; | |
2415 | di << " 1.0 - visible \n"; | |
2416 | return 1; | |
2417 | } | |
2418 | ||
2419 | // get the input params | |
2420 | Standard_Real X1 = atof(argv[1]); | |
2421 | Standard_Real Y1 = atof(argv[2]); | |
2422 | Standard_Real X2 = atof(argv[3]); | |
2423 | Standard_Real Y2 = atof(argv[4]); | |
2424 | ||
2425 | Standard_Real aWidth = 0.5; | |
2426 | Standard_Integer aType = 0; | |
2427 | Standard_Real aTransparency = 1.0; | |
2428 | ||
2429 | // has width | |
2430 | if (argc > 5) | |
2431 | aWidth = atof(argv[5]); | |
2432 | ||
2433 | // has type | |
2434 | if (argc > 6) | |
2435 | aType = (Standard_Integer) atoi(argv[6]); | |
2436 | ||
2437 | // has transparency | |
2438 | if (argc > 7) | |
2439 | { | |
2440 | aTransparency = atof(argv[7]); | |
2441 | if (aTransparency < 0 || aTransparency > 1.0) | |
2442 | aTransparency = 1.0; | |
2443 | } | |
2444 | ||
2445 | // select appropriate line type | |
2446 | Aspect_TypeOfLine aLineType; | |
2447 | switch (aType) | |
2448 | { | |
2449 | case 1: | |
2450 | aLineType = Aspect_TOL_DASH; | |
2451 | break; | |
2452 | ||
2453 | case 2: | |
2454 | aLineType = Aspect_TOL_DOT; | |
2455 | break; | |
2456 | ||
2457 | case 3: | |
2458 | aLineType = Aspect_TOL_DOTDASH; | |
2459 | break; | |
2460 | ||
2461 | default: | |
2462 | aLineType = Aspect_TOL_SOLID; | |
2463 | } | |
2464 | ||
2465 | // replace layer manager | |
2466 | Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView); | |
2467 | aView->SetLayerMgr(aMgr); | |
2468 | ||
2469 | // add line item | |
2470 | Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2, | |
2471 | aMgr.operator->(), | |
2472 | aLineType, aWidth, | |
2473 | aTransparency); | |
2474 | ||
2475 | // update view | |
2476 | aView->MustBeResized(); | |
2477 | aView->Redraw(); | |
2478 | ||
2479 | return 0; | |
2480 | } | |
2481 | ||
25289ec1 | 2482 | //======================================================================= |
2483 | //function : VOverlayText | |
2484 | //purpose : Test text displaying in view overlay | |
2485 | //======================================================================= | |
2486 | static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv) | |
2487 | { | |
2488 | // get the active view | |
2489 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
2490 | if (aView.IsNull()) | |
2491 | { | |
2492 | di << "No active view. Please call vinit.\n"; | |
2493 | return 1; | |
2494 | } | |
2495 | else if (argc < 4 || argc > 13) | |
2496 | { | |
2497 | di << "Use: " << argv[0]; | |
2498 | di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n"; | |
2499 | di << "[background_color: R G B]\n"; | |
2500 | di << " height - pixel height of the text (default=10.0)\n"; | |
2501 | di << " font_name - name of font (default=courier)\n"; | |
2502 | di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n"; | |
2503 | di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n"; | |
2504 | di << " background_color- R G B values used for subtitle and decal text\n"; | |
2505 | di << "(default=255.0 255.0 255.0)\n"; | |
2506 | return 1; | |
2507 | } | |
2508 | ||
2509 | TCollection_AsciiString aText (argv[1]); | |
2510 | Standard_Real aPosX = atof(argv[2]); | |
2511 | Standard_Real aPosY = atof(argv[3]); | |
2512 | Standard_Real aHeight = (argc >= 5) ? atof (argv[4]) : 10.0; | |
2513 | ||
2514 | // font name | |
2515 | TCollection_AsciiString aFontName = "Courier"; | |
2516 | if (argc >= 6) | |
2517 | aFontName = TCollection_AsciiString (argv[5]); | |
2518 | ||
2519 | // text colors | |
2520 | Quantity_Parameter aColorRed = 1.0; | |
2521 | Quantity_Parameter aColorGreen = 1.0; | |
2522 | Quantity_Parameter aColorBlue = 1.0; | |
2523 | if (argc >= 9) | |
2524 | { | |
2525 | aColorRed = atof (argv[6])/255.; | |
2526 | aColorGreen = atof (argv[7])/255.; | |
2527 | aColorBlue = atof (argv[8])/255.; | |
2528 | } | |
2529 | ||
2530 | // display type | |
2531 | TCollection_AsciiString aDispStr; | |
2532 | if (argc >= 10) | |
2533 | aDispStr = TCollection_AsciiString (argv[9]); | |
2534 | ||
2535 | Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL; | |
2536 | if (aDispStr.IsEqual ("subtitle")) | |
2537 | aTextType = Aspect_TODT_SUBTITLE; | |
2538 | else if (aDispStr.IsEqual ("decal")) | |
2539 | aTextType = Aspect_TODT_DEKALE; | |
2540 | else if (aDispStr.IsEqual ("blend")) | |
2541 | aTextType = Aspect_TODT_BLEND; | |
2542 | ||
2543 | // subtitle color | |
2544 | Quantity_Parameter aSubRed = 1.0; | |
2545 | Quantity_Parameter aSubGreen = 1.0; | |
2546 | Quantity_Parameter aSubBlue = 1.0; | |
2547 | if (argc == 13) | |
2548 | { | |
2549 | aSubRed = atof (argv[10])/255.; | |
2550 | aSubGreen = atof (argv[11])/255.; | |
2551 | aSubBlue = atof (argv[12])/255.; | |
2552 | } | |
2553 | ||
2554 | // check fo current overlay | |
2555 | Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer (); | |
2556 | if (anOverlay.IsNull ()) | |
2557 | { | |
2558 | Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView); | |
2559 | anOverlay = aMgr->Overlay (); | |
2560 | aView->SetLayerMgr (aMgr); | |
2561 | } | |
2562 | ||
2563 | Quantity_Color aTextColor (aColorRed, aColorGreen, | |
2564 | aColorBlue, Quantity_TOC_RGB); | |
2565 | Quantity_Color aSubtColor (aSubRed, aSubGreen, | |
2566 | aSubBlue, Quantity_TOC_RGB); | |
2567 | ||
2568 | // add text item | |
2569 | Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY, | |
2570 | aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay); | |
2571 | ||
2572 | // update view | |
2573 | aView->MustBeResized(); | |
2574 | aView->Redraw(); | |
2575 | ||
2576 | return 0; | |
2577 | } | |
2578 | ||
7fd59977 | 2579 | //======================================================================= |
2580 | //function : ViewerCommands | |
2581 | //purpose : | |
2582 | //======================================================================= | |
2583 | ||
2584 | void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) | |
2585 | { | |
2586 | ||
2587 | const char *group = "ZeViewer"; | |
2588 | theCommands.Add("vinit" , | |
2589 | "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window", | |
2590 | __FILE__,VInit,group); | |
2591 | theCommands.Add("vhelp" , | |
2592 | "vhelp : display help on the viewer commands", | |
2593 | __FILE__,VHelp,group); | |
2594 | theCommands.Add("vtop" , | |
2595 | "vtop or <T> : Top view" , | |
2596 | __FILE__,VTop,group); | |
2597 | theCommands.Add("vaxo" , | |
2598 | " vaxo or <A> : Axonometric view ", | |
2599 | __FILE__,VAxo,group); | |
2600 | theCommands.Add("vpick" , | |
2601 | "vpick : vpick X Y Z [shape subshape] ( all variables as string )", | |
2602 | VPick,group); | |
2603 | theCommands.Add("vfit" , | |
2604 | "vfit or <F> : vfit", | |
2605 | __FILE__,VFit,group); | |
2606 | theCommands.Add("vzfit" , | |
2607 | "vzfit", | |
2608 | __FILE__,VZFit,group); | |
2609 | theCommands.Add("vrepaint", | |
2610 | "vrepaint : vrepaint, force redraw", | |
2611 | __FILE__,VRepaint,group); | |
2612 | theCommands.Add("vclear", | |
2613 | "vclear : vclear", | |
2614 | __FILE__,VClear,group); | |
2615 | theCommands.Add("vsetbg", | |
2616 | "vsetbg : vsetbg imagefile [filltype] : Load image as background", | |
2617 | __FILE__,VSetBg,group); | |
f8b2ed36 | 2618 | theCommands.Add("vsetbgmode", |
2619 | "vsetbgmode : vsetbgmode filltype : Change background image fill type", | |
2620 | __FILE__,VSetBgMode,group); | |
7fd59977 | 2621 | theCommands.Add("vsetgradientbg", |
f8b2ed36 | 2622 | "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background", |
7fd59977 | 2623 | __FILE__,VSetGradientBg,group); |
f8b2ed36 | 2624 | theCommands.Add("vsetgrbgmode", |
2625 | "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type", | |
2626 | __FILE__,VSetGradientBgMode,group); | |
2627 | theCommands.Add("vsetcolorbg", | |
2628 | "vsetcolorbg : vsetcolorbg r g b : Set background color", | |
2629 | __FILE__,VSetColorBg,group); | |
7fd59977 | 2630 | theCommands.Add("vscale", |
2631 | "vscale : vscale X Y Z", | |
2632 | __FILE__,VScale,group); | |
2633 | theCommands.Add("vzbufftrihedron", | |
7c8a8fcc | 2634 | "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper" |
2635 | " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]" | |
2636 | " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron", | |
7fd59977 | 2637 | __FILE__,VTestZBuffTrihedron,group); |
2638 | theCommands.Add("vrotate", | |
2639 | "vrotate : vrotate AX AY AZ [X Y Z]", | |
2640 | __FILE__,VRotate,group); | |
2641 | theCommands.Add("vzoom", | |
2642 | "vzoom : vzoom coef", | |
2643 | __FILE__,VZoom,group); | |
2644 | theCommands.Add("vpan", | |
2645 | "vpan : vpan dx dy", | |
2646 | __FILE__,VPan,group); | |
2647 | theCommands.Add("vexport", | |
5cedc27f K |
2648 | "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }" |
2649 | " : exports the view to a vector file of a given format" | |
2650 | " : notice that EMF format requires patched gl2ps", | |
7fd59977 | 2651 | __FILE__,VExport,group); |
2652 | theCommands.Add("vcolorscale", | |
2653 | "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale", | |
2654 | __FILE__,VColorScale,group); | |
2655 | theCommands.Add("vgraduatedtrihedron", | |
13a22457 | 2656 | "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]", |
7fd59977 | 2657 | __FILE__,VGraduatedTrihedron,group); |
7edf74fd A |
2658 | theCommands.Add("vprintview" , |
2659 | "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile", | |
2660 | __FILE__,VPrintView,group); | |
59f45b7c | 2661 | theCommands.Add("vzlayer", |
2662 | "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids", | |
2663 | __FILE__,VZLayer,group); | |
25289ec1 | 2664 | theCommands.Add("voverlaytext", |
2665 | "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]" | |
2666 | " : height - pixel height of the text (default=10.0)" | |
2667 | " : font_name - name of font (default=courier)" | |
2668 | " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) " | |
2669 | " : display_type = {normal/subtitle/decal/blend}, (default=normal) " | |
2670 | " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ", | |
2671 | __FILE__,VOverlayText,group); | |
20637bd2 | 2672 | theCommands.Add("vlayerline", |
2673 | "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]", | |
2674 | __FILE__,VLayerLine,group); | |
7fd59977 | 2675 | } |