Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1998-09-01 |
2 | // Created by: Robert COUBLANC | |
3 | // Copyright (c) 1998-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
b311480e | 16 | |
58655684 | 17 | #include <OpenGl_GlCore20.hxx> |
0a768f56 | 18 | #include <AIS_Shape.hxx> |
19 | #include <AIS_Drawer.hxx> | |
20 | #include <AIS_InteractiveObject.hxx> | |
21 | #include <AIS_ListOfInteractive.hxx> | |
22 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
23 | #include <DBRep.hxx> | |
2bd4c032 | 24 | #include <Graphic3d_AspectMarker3d.hxx> |
7fd59977 | 25 | #include <Graphic3d_ExportFormat.hxx> |
269294d6 | 26 | #include <Graphic3d_NameOfTextureEnv.hxx> |
27 | #include <Graphic3d_TextureEnv.hxx> | |
28 | #include <Graphic3d_TextureParams.hxx> | |
29 | #include <Graphic3d_TypeOfTextureFilter.hxx> | |
4269bd1b | 30 | #include <Graphic3d_AspectFillArea3d.hxx> |
7fd59977 | 31 | #include <ViewerTest.hxx> |
8625ef7e | 32 | #include <ViewerTest_AutoUpdater.hxx> |
7fd59977 | 33 | #include <ViewerTest_EventManager.hxx> |
4754e164 | 34 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
4269bd1b | 35 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> |
7fd59977 | 36 | #include <Visual3d_View.hxx> |
25289ec1 | 37 | #include <Visual3d_ViewManager.hxx> |
12381341 | 38 | #include <V3d_AmbientLight.hxx> |
39 | #include <V3d_DirectionalLight.hxx> | |
25289ec1 | 40 | #include <V3d_LayerMgr.hxx> |
12381341 | 41 | #include <V3d_LayerMgrPointer.hxx> |
42 | #include <V3d_PositionalLight.hxx> | |
43 | #include <V3d_SpotLight.hxx> | |
18d715bd | 44 | #include <NCollection_DoubleMap.hxx> |
45 | #include <NCollection_List.hxx> | |
46 | #include <NCollection_Vector.hxx> | |
7fd59977 | 47 | #include <NIS_View.hxx> |
48 | #include <NIS_Triangulated.hxx> | |
49 | #include <NIS_InteractiveContext.hxx> | |
50 | #include <AIS_InteractiveContext.hxx> | |
51 | #include <Draw_Interpretor.hxx> | |
52 | #include <Draw.hxx> | |
53 | #include <Draw_Appli.hxx> | |
7edf74fd | 54 | #include <Aspect_PrintAlgo.hxx> |
692613e5 | 55 | #include <Image_AlienPixMap.hxx> |
58655684 | 56 | #include <OpenGl_GraphicDriver.hxx> |
208e6839 | 57 | #include <OSD_Timer.hxx> |
900f7229 | 58 | #include <TColStd_HSequenceOfAsciiString.hxx> |
59f45b7c | 59 | #include <TColStd_SequenceOfInteger.hxx> |
4754e164 | 60 | #include <TColStd_HSequenceOfReal.hxx> |
61 | #include <TColgp_Array1OfPnt2d.hxx> | |
197ac94e | 62 | #include <TColStd_MapOfAsciiString.hxx> |
20637bd2 | 63 | #include <Visual3d_LayerItem.hxx> |
20637bd2 | 64 | #include <Aspect_TypeOfLine.hxx> |
692613e5 | 65 | #include <Image_Diff.hxx> |
dc3fe572 | 66 | #include <Aspect_DisplayConnection.hxx> |
4269bd1b | 67 | #include <gp_Pnt.hxx> |
68 | #include <gp_Dir.hxx> | |
69 | #include <gp_Pln.hxx> | |
70 | #include <PrsMgr_PresentableObject.hxx> | |
71 | #include <Graphic3d_ClipPlane.hxx> | |
72 | #include <NCollection_DataMap.hxx> | |
73 | #include <Graphic3d_Texture2Dmanual.hxx> | |
74 | #include <Prs3d_ShadingAspect.hxx> | |
7fd59977 | 75 | |
25289ec1 | 76 | #ifdef WNT |
77 | #undef DrawText | |
78 | #endif | |
79 | ||
80 | #include <Visual3d_Layer.hxx> | |
692613e5 | 81 | #include <cstdlib> |
25289ec1 | 82 | |
58655684 | 83 | #if defined(_WIN32) |
4fe56619 | 84 | #include <WNT_WClass.hxx> |
85 | #include <WNT_Window.hxx> | |
86 | ||
87 | #if defined(_MSC_VER) | |
88 | #define _CRT_SECURE_NO_DEPRECATE | |
89 | #pragma warning (disable:4996) | |
90 | #endif | |
91 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
4fe56619 | 92 | #include <Cocoa_Window.hxx> |
7fd59977 | 93 | #else |
4fe56619 | 94 | #include <Xw_Window.hxx> |
95 | #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */ | |
96 | #include <X11/Xutil.h> | |
97 | #include <tk.h> | |
7fd59977 | 98 | #endif |
99 | ||
8625ef7e | 100 | inline Standard_Boolean parseOnOff (Standard_CString theArg, |
101 | Standard_Boolean& theIsOn) | |
102 | { | |
103 | TCollection_AsciiString aFlag (theArg); | |
104 | aFlag.LowerCase(); | |
105 | if (aFlag == "on" | |
106 | || aFlag == "1") | |
107 | { | |
108 | theIsOn = Standard_True; | |
109 | return Standard_True; | |
110 | } | |
111 | else if (aFlag == "off" | |
112 | || aFlag == "0") | |
113 | { | |
114 | theIsOn = Standard_False; | |
115 | return Standard_True; | |
116 | } | |
117 | return Standard_False; | |
118 | } | |
119 | ||
b514beda | 120 | // Auxiliary definitions |
121 | static const char THE_KEY_DELETE = 127; | |
7fd59977 | 122 | |
123 | //============================================================================== | |
124 | // VIEWER GLOBAL VARIABLES | |
125 | //============================================================================== | |
126 | ||
127 | Standard_IMPORT Standard_Boolean Draw_VirtualWindows; | |
b514beda | 128 | Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand); |
7fd59977 | 129 | |
130 | Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv); | |
131 | extern const Handle(NIS_InteractiveContext)& TheNISContext(); | |
4754e164 | 132 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
7fd59977 | 133 | |
b514beda | 134 | extern int VErase (Draw_Interpretor& theDI, |
135 | Standard_Integer theArgNb, | |
136 | const char** theArgVec); | |
137 | ||
58655684 | 138 | #if defined(_WIN32) |
7fd59977 | 139 | static Handle(WNT_Window)& VT_GetWindow() { |
140 | static Handle(WNT_Window) WNTWin; | |
141 | return WNTWin; | |
142 | } | |
4fe56619 | 143 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
4fe56619 | 144 | static Handle(Cocoa_Window)& VT_GetWindow() |
145 | { | |
146 | static Handle(Cocoa_Window) aWindow; | |
147 | return aWindow; | |
148 | } | |
149 | extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow); | |
18d715bd | 150 | extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle); |
151 | extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight); | |
152 | ||
7fd59977 | 153 | #else |
7fd59977 | 154 | static Handle(Xw_Window)& VT_GetWindow(){ |
155 | static Handle(Xw_Window) XWWin; | |
156 | return XWWin; | |
157 | } | |
7fd59977 | 158 | |
159 | static void VProcessEvents(ClientData,int); | |
160 | #endif | |
161 | ||
18d715bd | 162 | static Handle(Aspect_DisplayConnection)& GetDisplayConnection() |
163 | { | |
164 | static Handle(Aspect_DisplayConnection) aDisplayConnection; | |
165 | return aDisplayConnection; | |
166 | } | |
167 | ||
168 | static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection) | |
169 | { | |
170 | GetDisplayConnection() = theDisplayConnection; | |
171 | } | |
172 | ||
58655684 | 173 | #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
18d715bd | 174 | Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow) |
dc3fe572 | 175 | { |
0ebaa4db | 176 | Aspect_Handle aWindowHandle = (Aspect_Handle)NULL; |
58655684 | 177 | #if defined(_WIN32) |
18d715bd | 178 | const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow); |
179 | if (!aWindow.IsNull()) | |
180 | return aWindow->HWindow(); | |
181 | #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
182 | const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow); | |
183 | if (!aWindow.IsNull()) | |
184 | return aWindow->XWindow(); | |
185 | #endif | |
186 | return aWindowHandle; | |
dc3fe572 | 187 | } |
18d715bd | 188 | #endif |
dc3fe572 | 189 | |
de75ed09 | 190 | static Standard_Boolean MyHLRIsOn = Standard_False; |
7fd59977 | 191 | |
18d715bd | 192 | NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews; |
58655684 | 193 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts; |
18d715bd | 194 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers; |
58655684 | 195 | static OpenGl_Caps ViewerTest_myDefaultCaps; |
18d715bd | 196 | |
7fd59977 | 197 | #define ZCLIPWIDTH 1. |
198 | ||
199 | static void OSWindowSetup(); | |
200 | ||
201 | //============================================================================== | |
202 | // EVENT GLOBAL VARIABLES | |
203 | //============================================================================== | |
204 | ||
205 | static int Start_Rot = 0; | |
206 | static int ZClipIsOn = 0; | |
4fe56619 | 207 | int X_Motion = 0; // Current cursor position |
208 | int Y_Motion = 0; | |
209 | int X_ButtonPress = 0; // Last ButtonPress position | |
210 | int Y_ButtonPress = 0; | |
211 | Standard_Boolean IsDragged = Standard_False; | |
8abada55 | 212 | Standard_Boolean DragFirst = Standard_False; |
7fd59977 | 213 | |
214 | //============================================================================== | |
215 | ||
216 | #ifdef WNT | |
217 | static LRESULT WINAPI ViewerWindowProc( | |
218 | HWND hwnd, | |
219 | UINT uMsg, | |
220 | WPARAM wParam, | |
221 | LPARAM lParam ); | |
222 | static LRESULT WINAPI AdvViewerWindowProc( | |
223 | HWND hwnd, | |
224 | UINT uMsg, | |
225 | WPARAM wParam, | |
226 | LPARAM lParam ); | |
227 | #endif | |
228 | ||
229 | ||
230 | //============================================================================== | |
231 | //function : WClass | |
232 | //purpose : | |
233 | //============================================================================== | |
234 | ||
235 | const Handle(MMgt_TShared)& ViewerTest::WClass() | |
236 | { | |
237 | static Handle(MMgt_TShared) theWClass; | |
58655684 | 238 | #if defined(_WIN32) |
4fe56619 | 239 | if (theWClass.IsNull()) |
240 | { | |
7fd59977 | 241 | theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc, |
242 | CS_VREDRAW | CS_HREDRAW, 0, 0, | |
243 | ::LoadCursor (NULL, IDC_ARROW)); | |
244 | } | |
245 | #endif | |
246 | return theWClass; | |
247 | } | |
248 | ||
18d715bd | 249 | //============================================================================== |
250 | //function : CreateName | |
251 | //purpose : Create numerical name for new object in theMap | |
252 | //============================================================================== | |
253 | template <typename ObjectType> | |
254 | TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap, | |
255 | const TCollection_AsciiString& theDefaultString) | |
256 | { | |
257 | if (theObjectMap.IsEmpty()) | |
258 | return theDefaultString + TCollection_AsciiString(1); | |
259 | ||
260 | Standard_Integer aNextKey = 1; | |
261 | Standard_Boolean isFound = Standard_False; | |
262 | while (!isFound) | |
263 | { | |
264 | TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey); | |
265 | // Look for objects with default names | |
266 | if (theObjectMap.IsBound1(aStringKey)) | |
267 | { | |
268 | aNextKey++; | |
269 | } | |
270 | else | |
271 | isFound = Standard_True; | |
272 | } | |
273 | ||
274 | return theDefaultString + TCollection_AsciiString(aNextKey); | |
275 | } | |
276 | ||
277 | //============================================================================== | |
278 | //structure : ViewerTest_Names | |
279 | //purpose : Allow to operate with full view name: driverName/viewerName/viewName | |
280 | //============================================================================== | |
281 | struct ViewerTest_Names | |
282 | { | |
283 | private: | |
284 | TCollection_AsciiString myDriverName; | |
285 | TCollection_AsciiString myViewerName; | |
286 | TCollection_AsciiString myViewName; | |
287 | ||
288 | public: | |
289 | ||
290 | const TCollection_AsciiString& GetDriverName () const | |
291 | { | |
292 | return myDriverName; | |
293 | } | |
294 | void SetDriverName (const TCollection_AsciiString& theDriverName) | |
295 | { | |
296 | myDriverName = theDriverName; | |
297 | } | |
298 | const TCollection_AsciiString& GetViewerName () const | |
299 | { | |
300 | return myViewerName; | |
301 | } | |
302 | void SetViewerName (const TCollection_AsciiString& theViewerName) | |
303 | { | |
304 | myViewerName = theViewerName; | |
305 | } | |
306 | const TCollection_AsciiString& GetViewName () const | |
307 | { | |
308 | return myViewName; | |
309 | } | |
310 | void SetViewName (const TCollection_AsciiString& theViewName) | |
311 | { | |
312 | myViewName = theViewName; | |
313 | } | |
314 | ||
315 | //=========================================================================== | |
316 | //function : Constructor for ViewerTest_Names | |
317 | //purpose : Get view, viewer, driver names from custom string | |
318 | //=========================================================================== | |
319 | ||
320 | ViewerTest_Names (const TCollection_AsciiString& theInputString) | |
321 | { | |
322 | TCollection_AsciiString aName(theInputString); | |
323 | if (theInputString.IsEmpty()) | |
324 | { | |
325 | // Get current configuration | |
326 | if (ViewerTest_myDrivers.IsEmpty()) | |
327 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
328 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
329 | else | |
330 | myDriverName = ViewerTest_myDrivers.Find2 | |
331 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
332 | ||
333 | if(ViewerTest_myContexts.IsEmpty()) | |
334 | { | |
335 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
336 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
337 | } | |
338 | else | |
339 | myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext()); | |
340 | ||
341 | myViewName = CreateName <Handle(V3d_View)> | |
342 | (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View")); | |
343 | } | |
344 | else | |
345 | { | |
346 | // There is at least view name | |
347 | Standard_Integer aParserNumber = 0; | |
348 | for (Standard_Integer i = 0; i < 3; ++i) | |
349 | { | |
350 | Standard_Integer aParserPos = aName.SearchFromEnd("/"); | |
351 | if(aParserPos != -1) | |
352 | { | |
353 | aParserNumber++; | |
354 | aName.Split(aParserPos-1); | |
355 | } | |
356 | else | |
357 | break; | |
358 | } | |
359 | if (aParserNumber == 0) | |
360 | { | |
361 | // Only view name | |
362 | if (!ViewerTest::GetAISContext().IsNull()) | |
363 | { | |
364 | myDriverName = ViewerTest_myDrivers.Find2 | |
365 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
366 | myViewerName = ViewerTest_myContexts.Find2 | |
367 | (ViewerTest::GetAISContext()); | |
368 | } | |
369 | else | |
370 | { | |
371 | // There is no opened contexts here, need to create names for viewer and driver | |
372 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
373 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
374 | ||
375 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
376 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
377 | } | |
378 | myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString); | |
379 | } | |
380 | else if (aParserNumber == 1) | |
381 | { | |
382 | // Here is viewerName/viewName | |
383 | if (!ViewerTest::GetAISContext().IsNull()) | |
384 | myDriverName = ViewerTest_myDrivers.Find2 | |
385 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
386 | else | |
387 | { | |
388 | // There is no opened contexts here, need to create name for driver | |
389 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
390 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
391 | } | |
392 | myViewerName = TCollection_AsciiString(myDriverName + "/" + aName); | |
393 | ||
394 | myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString); | |
395 | } | |
396 | else | |
397 | { | |
398 | //Here is driverName/viewerName/viewName | |
399 | myDriverName = TCollection_AsciiString(aName); | |
400 | ||
401 | TCollection_AsciiString aViewerName(theInputString); | |
402 | aViewerName.Split(aViewerName.SearchFromEnd("/") - 1); | |
403 | myViewerName = TCollection_AsciiString(aViewerName); | |
404 | ||
405 | myViewName = TCollection_AsciiString(theInputString); | |
406 | } | |
407 | } | |
408 | } | |
409 | }; | |
410 | ||
411 | //============================================================================== | |
412 | //function : FindContextByView | |
413 | //purpose : Find AIS_InteractiveContext by View | |
414 | //============================================================================== | |
415 | ||
416 | Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView) | |
417 | { | |
418 | Handle(AIS_InteractiveContext) anAISContext; | |
419 | ||
420 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
421 | anIter (ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
422 | { | |
423 | if (anIter.Value()->CurrentViewer() == theView->Viewer()) | |
424 | return anIter.Key2(); | |
425 | } | |
426 | return anAISContext; | |
427 | } | |
428 | ||
429 | ||
430 | //============================================================================== | |
431 | //function : SetWindowTitle | |
432 | //purpose : Set window title | |
433 | //============================================================================== | |
434 | ||
435 | void SetWindowTitle (const Handle(Aspect_Window)& theWindow, | |
436 | Standard_CString theTitle) | |
437 | { | |
58655684 | 438 | #if defined(_WIN32) |
18d715bd | 439 | SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(), |
440 | theTitle); | |
441 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
442 | SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle); | |
443 | #else | |
444 | if(GetDisplayConnection()->GetDisplay()) | |
445 | { | |
446 | Window aWindow = | |
447 | Handle(Xw_Window)::DownCast(theWindow)->XWindow(); | |
448 | XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle); | |
449 | } | |
450 | #endif | |
451 | } | |
452 | ||
453 | //============================================================================== | |
454 | //function : IsWindowOverlapped | |
455 | //purpose : Check if theWindow overlapp another view | |
456 | //============================================================================== | |
457 | ||
458 | Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft, | |
459 | const Standard_Integer thePxTop, | |
460 | const Standard_Integer thePxRight, | |
461 | const Standard_Integer thePxBottom, | |
462 | TCollection_AsciiString& theViewId) | |
463 | { | |
464 | for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
465 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
466 | { | |
467 | Standard_Integer aTop = 0, | |
468 | aLeft = 0, | |
469 | aRight = 0, | |
470 | aBottom = 0; | |
471 | anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom); | |
472 | if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
473 | (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) || | |
474 | (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
475 | (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom)) | |
476 | { | |
477 | theViewId = anIter.Key1(); | |
478 | return Standard_True; | |
479 | } | |
480 | } | |
481 | return Standard_False; | |
482 | } | |
483 | ||
484 | // Workaround: to create and delete non-orthographic views outside ViewerTest | |
485 | void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName) | |
486 | { | |
487 | ViewerTest_myViews.UnBind1 (theName); | |
488 | } | |
489 | ||
490 | void ViewerTest::InitViewName (const TCollection_AsciiString& theName, | |
491 | const Handle(V3d_View)& theView) | |
492 | { | |
493 | ViewerTest_myViews.Bind (theName, theView); | |
494 | } | |
495 | ||
496 | TCollection_AsciiString ViewerTest::GetCurrentViewName () | |
497 | { | |
498 | return ViewerTest_myViews.Find2( ViewerTest::CurrentView()); | |
499 | } | |
7fd59977 | 500 | //============================================================================== |
501 | //function : ViewerInit | |
502 | //purpose : Create the window viewer and initialize all the global variable | |
503 | //============================================================================== | |
504 | ||
18d715bd | 505 | TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft, |
506 | const Standard_Integer thePxTop, | |
507 | const Standard_Integer thePxWidth, | |
508 | const Standard_Integer thePxHeight, | |
509 | Standard_CString theViewName, | |
510 | Standard_CString theDisplayName) | |
7fd59977 | 511 | { |
8c3c9904 | 512 | // Default position and dimension of the viewer window. |
4fe56619 | 513 | // Note that left top corner is set to be sufficiently small to have |
8c3c9904 | 514 | // window fit in the small screens (actual for remote desktops, see #23003). |
4fe56619 | 515 | // The position corresponds to the window's client area, thus some |
8c3c9904 | 516 | // gap is added for window frame to be visible. |
517 | Standard_Integer aPxLeft = 20; | |
518 | Standard_Integer aPxTop = 40; | |
7fd59977 | 519 | Standard_Integer aPxWidth = 409; |
520 | Standard_Integer aPxHeight = 409; | |
18d715bd | 521 | Standard_Boolean toCreateViewer = Standard_False; |
522 | ||
58655684 | 523 | Handle(OpenGl_GraphicDriver) aGraphicDriver; |
18d715bd | 524 | ViewerTest_Names aViewNames(theViewName); |
525 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ())) | |
526 | aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View")); | |
527 | ||
528 | if (thePxLeft != 0) | |
529 | aPxLeft = thePxLeft; | |
530 | if (thePxTop != 0) | |
531 | aPxTop = thePxTop; | |
532 | if (thePxWidth != 0) | |
533 | aPxWidth = thePxWidth; | |
534 | if (thePxHeight != 0) | |
7fd59977 | 535 | aPxHeight = thePxHeight; |
4269bd1b | 536 | |
18d715bd | 537 | // Get graphic driver (create it or get from another view) |
538 | if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName())) | |
539 | { | |
540 | // Get connection string | |
58655684 | 541 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
18d715bd | 542 | TCollection_AsciiString aDisplayName(theDisplayName); |
498ce76b | 543 | if (!aDisplayName.IsEmpty()) |
18d715bd | 544 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
545 | else | |
546 | SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName)); | |
18d715bd | 547 | #else |
498ce76b | 548 | (void)theDisplayName; // avoid warning on unused argument |
18d715bd | 549 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
550 | #endif | |
65993a95 | 551 | aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection()); |
58655684 | 552 | aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps; |
18d715bd | 553 | ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver); |
554 | toCreateViewer = Standard_True; | |
555 | } | |
556 | else | |
557 | { | |
58655684 | 558 | aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName())); |
7fd59977 | 559 | } |
560 | ||
18d715bd | 561 | //Dispose the window if input parameters are default |
562 | if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0) | |
7fd59977 | 563 | { |
18d715bd | 564 | Standard_Integer aTop = 0, |
565 | aLeft = 0, | |
566 | aRight = 0, | |
567 | aBottom = 0, | |
568 | aScreenWidth = 0, | |
569 | aScreenHeight = 0; | |
570 | ||
571 | // Get screen resolution | |
572 | #if defined(_WIN32) || defined(__WIN32__) | |
573 | RECT aWindowSize; | |
574 | GetClientRect(GetDesktopWindow(), &aWindowSize); | |
575 | aScreenHeight = aWindowSize.bottom; | |
576 | aScreenWidth = aWindowSize.right; | |
577 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
578 | GetCocoaScreenResolution (aScreenWidth, aScreenHeight); | |
579 | #else | |
580 | Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay()); | |
581 | aScreenWidth = WidthOfScreen(aScreen); | |
582 | aScreenHeight = HeightOfScreen(aScreen); | |
583 | #endif | |
584 | ||
585 | TCollection_AsciiString anOverlappedViewId(""); | |
773f53f1 | 586 | |
587 | while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)) | |
dc3fe572 | 588 | { |
18d715bd | 589 | ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom); |
590 | ||
591 | if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId) | |
592 | && aRight + 2*aPxWidth + 40 > aScreenWidth) | |
593 | { | |
594 | if (aBottom + aPxHeight + 40 > aScreenHeight) | |
595 | { | |
596 | aPxLeft = 20; | |
597 | aPxTop = 40; | |
598 | break; | |
599 | } | |
600 | aPxLeft = 20; | |
601 | aPxTop = aBottom + 40; | |
602 | } | |
603 | else | |
604 | aPxLeft = aRight + 20; | |
dc3fe572 | 605 | } |
18d715bd | 606 | } |
607 | ||
608 | // Get viewer name | |
609 | TCollection_AsciiString aTitle("3D View - "); | |
610 | aTitle = aTitle + aViewNames.GetViewName() + "(*)"; | |
611 | ||
612 | // Change name of current active window | |
613 | if (!ViewerTest::CurrentView().IsNull()) | |
614 | { | |
615 | TCollection_AsciiString aTitle("3D View - "); | |
616 | aTitle = aTitle | |
617 | + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); | |
618 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
619 | } | |
620 | ||
621 | // Create viewer | |
eb4320f2 | 622 | Handle(V3d_Viewer) a3DViewer; |
18d715bd | 623 | // If it's the single view, we first look for empty context |
624 | if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty()) | |
625 | { | |
626 | NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
627 | anIter(ViewerTest_myContexts); | |
628 | if (anIter.More()) | |
629 | ViewerTest::SetAISContext (anIter.Value()); | |
630 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 631 | } |
632 | else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())) | |
633 | { | |
634 | ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName())); | |
635 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 636 | } |
eb4320f2 | 637 | else if (a3DViewer.IsNull()) |
18d715bd | 638 | { |
639 | toCreateViewer = Standard_True; | |
640 | TCollection_ExtendedString NameOfWindow("Viewer3D"); | |
641 | a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString()); | |
642 | ||
643 | NameOfWindow = TCollection_ExtendedString("Collector"); | |
18d715bd | 644 | |
645 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); | |
18d715bd | 646 | } |
647 | ||
648 | // AIS context setup | |
649 | if (ViewerTest::GetAISContext().IsNull() || | |
650 | !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))) | |
651 | { | |
e79a94b9 | 652 | Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer); |
18d715bd | 653 | ViewerTest::SetAISContext (aContext); |
654 | ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext()); | |
655 | } | |
656 | else | |
e79a94b9 | 657 | { |
18d715bd | 658 | ViewerTest::ResetEventManager(); |
e79a94b9 | 659 | } |
18d715bd | 660 | |
661 | // Create window | |
e79a94b9 | 662 | #if defined(_WIN32) |
663 | VT_GetWindow() = new WNT_Window (aTitle.ToCString(), | |
664 | Handle(WNT_WClass)::DownCast (WClass()), | |
665 | Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW, | |
666 | aPxLeft, aPxTop, | |
667 | aPxWidth, aPxHeight, | |
668 | Quantity_NOC_BLACK); | |
4fe56619 | 669 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
e79a94b9 | 670 | VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(), |
671 | aPxLeft, aPxTop, | |
672 | aPxWidth, aPxHeight); | |
673 | ViewerTest_SetCocoaEventManagerView (VT_GetWindow()); | |
7fd59977 | 674 | #else |
e79a94b9 | 675 | VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(), |
676 | aTitle.ToCString(), | |
677 | aPxLeft, aPxTop, | |
678 | aPxWidth, aPxHeight); | |
7fd59977 | 679 | #endif |
18d715bd | 680 | VT_GetWindow()->SetVirtual (Draw_VirtualWindows); |
7fd59977 | 681 | |
18d715bd | 682 | // NIS setup |
683 | Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow()); | |
4269bd1b | 684 | |
18d715bd | 685 | ViewerTest::CurrentView(aView); |
686 | ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView); | |
687 | TheNISContext()->AttachView (aView); | |
7fd59977 | 688 | |
18d715bd | 689 | // Setup for X11 or NT |
690 | OSWindowSetup(); | |
7fd59977 | 691 | |
18d715bd | 692 | // Set parameters for V3d_View and V3d_Viewer |
693 | const Handle (V3d_View) aV3dView = ViewerTest::CurrentView(); | |
694 | aV3dView->SetComputedMode(Standard_False); | |
695 | MyHLRIsOn = aV3dView->ComputedMode(); | |
696 | aV3dView->SetZClippingDepth(0.5); | |
697 | aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.); | |
7fd59977 | 698 | |
18d715bd | 699 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); |
700 | if (toCreateViewer) | |
701 | { | |
7fd59977 | 702 | a3DViewer->SetDefaultLights(); |
703 | a3DViewer->SetLightOn(); | |
18d715bd | 704 | } |
7fd59977 | 705 | |
e79a94b9 | 706 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
4fe56619 | 707 | #if TCL_MAJOR_VERSION < 8 |
18d715bd | 708 | Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 709 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
4fe56619 | 710 | #else |
18d715bd | 711 | Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 712 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
4fe56619 | 713 | #endif |
714 | #endif | |
7fd59977 | 715 | |
7fd59977 | 716 | VT_GetWindow()->Map(); |
4269bd1b | 717 | |
18d715bd | 718 | // Set the handle of created view in the event manager |
719 | ViewerTest::ResetEventManager(); | |
720 | ||
4fe56619 | 721 | ViewerTest::CurrentView()->Redraw(); |
18d715bd | 722 | |
723 | aView.Nullify(); | |
724 | a3DViewer.Nullify(); | |
18d715bd | 725 | |
726 | return aViewNames.GetViewName(); | |
727 | } | |
728 | ||
4269bd1b | 729 | //============================================================================== |
730 | //function : RedrawAllViews | |
731 | //purpose : Redraw all created views | |
732 | //============================================================================== | |
733 | void ViewerTest::RedrawAllViews() | |
734 | { | |
735 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
736 | for (; aViewIt.More(); aViewIt.Next()) | |
737 | { | |
738 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
739 | aView->Redraw(); | |
740 | } | |
741 | } | |
742 | ||
7fd59977 | 743 | //============================================================================== |
744 | //function : Vinit | |
745 | //purpose : Create the window viewer and initialize all the global variable | |
e79a94b9 | 746 | // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event |
7fd59977 | 747 | //============================================================================== |
748 | ||
18d715bd | 749 | static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 750 | { |
e79a94b9 | 751 | if (theArgsNb > 9) |
18d715bd | 752 | { |
e79a94b9 | 753 | std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n" |
754 | << "Type help for more information.\n"; | |
18d715bd | 755 | return 1; |
756 | } | |
18d715bd | 757 | |
e79a94b9 | 758 | TCollection_AsciiString aViewName, aDisplayName; |
759 | Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0; | |
760 | TCollection_AsciiString aName, aValue; | |
761 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
18d715bd | 762 | { |
e79a94b9 | 763 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; |
764 | TCollection_AsciiString anArgCase = anArg; | |
765 | anArgCase.UpperCase(); | |
1d7ca641 | 766 | if (ViewerTest::SplitParameter (anArg, aName, aValue)) |
18d715bd | 767 | { |
e79a94b9 | 768 | aName.UpperCase(); |
769 | if (aName.IsEqual ("NAME")) | |
18d715bd | 770 | { |
771 | aViewName = aValue; | |
772 | } | |
e79a94b9 | 773 | else if (aName.IsEqual ("L") |
774 | || aName.IsEqual ("LEFT")) | |
775 | { | |
18d715bd | 776 | aPxLeft = aValue.IntegerValue(); |
e79a94b9 | 777 | } |
778 | else if (aName.IsEqual ("T") | |
779 | || aName.IsEqual ("TOP")) | |
780 | { | |
18d715bd | 781 | aPxTop = aValue.IntegerValue(); |
e79a94b9 | 782 | } |
783 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
784 | else if (aName.IsEqual ("DISP") | |
785 | || aName.IsEqual ("DISPLAY")) | |
786 | { | |
18d715bd | 787 | aDisplayName = aValue; |
e79a94b9 | 788 | } |
789 | #endif | |
790 | else if (aName.IsEqual ("W") | |
791 | || aName.IsEqual ("WIDTH")) | |
792 | { | |
18d715bd | 793 | aPxWidth = aValue.IntegerValue(); |
e79a94b9 | 794 | } |
795 | else if (aName.IsEqual ("H") | |
796 | || aName.IsEqual ("HEIGHT")) | |
797 | { | |
18d715bd | 798 | aPxHeight = aValue.IntegerValue(); |
e79a94b9 | 799 | } |
18d715bd | 800 | else |
801 | { | |
e79a94b9 | 802 | std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n"; |
18d715bd | 803 | } |
804 | } | |
e79a94b9 | 805 | else if (aViewName.IsEmpty()) |
806 | { | |
807 | aViewName = anArg; | |
808 | } | |
809 | else | |
810 | { | |
811 | std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n"; | |
812 | } | |
18d715bd | 813 | } |
814 | ||
815 | ViewerTest_Names aViewNames (aViewName); | |
e79a94b9 | 816 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName())) |
18d715bd | 817 | { |
e79a94b9 | 818 | TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName(); |
819 | theDi.Eval (aCommand.ToCString()); | |
18d715bd | 820 | return 0; |
821 | } | |
822 | ||
823 | TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight, | |
824 | aViewName.ToCString(), | |
825 | aDisplayName.ToCString()); | |
e79a94b9 | 826 | theDi << aViewId; |
7fd59977 | 827 | return 0; |
828 | } | |
829 | ||
0a768f56 | 830 | //============================================================================== |
831 | //function : VHLR | |
832 | //purpose : hidden lines removal algorithm | |
e9224045 | 833 | //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}] |
0a768f56 | 834 | //============================================================================== |
835 | ||
836 | static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
837 | { | |
838 | if (ViewerTest::CurrentView().IsNull()) | |
839 | { | |
840 | di << argv[0] << ": Call vinit before this command, please.\n"; | |
841 | return 1; | |
842 | } | |
843 | ||
e9224045 | 844 | if (argc < 2) |
0a768f56 | 845 | { |
846 | di << argv[0] << ": Wrong number of command arguments.\n" | |
847 | << "Type help " << argv[0] << " for more information.\n"; | |
848 | return 1; | |
849 | } | |
850 | ||
e9224045 | 851 | // Enable or disable HLR mode. |
0a768f56 | 852 | Standard_Boolean isHLROn = |
853 | (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False; | |
854 | ||
e9224045 | 855 | if (isHLROn != MyHLRIsOn) |
0a768f56 | 856 | { |
e9224045 | 857 | MyHLRIsOn = isHLROn; |
858 | ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn); | |
0a768f56 | 859 | } |
860 | ||
e9224045 | 861 | // Show or hide hidden lines in HLR mode. |
862 | Standard_Boolean isCurrentShowHidden | |
863 | = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine(); | |
864 | ||
865 | Standard_Boolean isShowHidden = | |
866 | (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False) | |
867 | : isCurrentShowHidden; | |
868 | ||
869 | ||
870 | if (isShowHidden != isCurrentShowHidden) | |
871 | { | |
872 | if (isShowHidden) | |
873 | { | |
874 | ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine(); | |
875 | } | |
876 | else | |
877 | { | |
878 | ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine(); | |
879 | } | |
880 | ||
881 | // Redisplay shapes. | |
882 | if (MyHLRIsOn) | |
883 | { | |
884 | AIS_ListOfInteractive aListOfShapes; | |
885 | ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes); | |
886 | ||
887 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next()) | |
888 | { | |
889 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value()); | |
890 | if (aShape.IsNull()) | |
891 | { | |
892 | continue; | |
893 | } | |
894 | aShape->Redisplay(); | |
895 | } | |
896 | } | |
897 | } | |
0a768f56 | 898 | |
e9224045 | 899 | ViewerTest::CurrentView()->Update(); |
0a768f56 | 900 | return 0; |
901 | } | |
902 | ||
903 | //============================================================================== | |
904 | //function : VHLRType | |
905 | //purpose : change type of using HLR algorithm | |
906 | //============================================================================== | |
907 | ||
908 | static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
909 | { | |
910 | if (ViewerTest::CurrentView().IsNull()) | |
911 | { | |
912 | di << argv[0] << ": Call vinit before this command, please.\n"; | |
913 | return 1; | |
914 | } | |
915 | ||
916 | if (argc < 2) | |
917 | { | |
918 | di << argv[0] << ": Wrong number of command arguments.\n" | |
919 | << "Type help " << argv[0] << " for more information.\n"; | |
920 | return 1; | |
921 | } | |
922 | ||
923 | Prs3d_TypeOfHLR aTypeOfHLR = | |
924 | (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo; | |
925 | ||
926 | if (argc == 2) | |
927 | { | |
928 | AIS_ListOfInteractive aListOfShapes; | |
929 | ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes); | |
930 | ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR); | |
931 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); | |
932 | anIter.More(); anIter.Next()) | |
933 | { | |
934 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
935 | if (aShape.IsNull()) | |
936 | continue; | |
937 | if (aShape->TypeOfHLR() != aTypeOfHLR) | |
938 | aShape->SetTypeOfHLR (aTypeOfHLR); | |
939 | if (MyHLRIsOn) | |
940 | aShape->Redisplay(); | |
941 | } | |
942 | ViewerTest::CurrentView()->Update(); | |
943 | return 0; | |
944 | } | |
945 | else | |
946 | { | |
947 | for (Standard_Integer i = 2; i < argc; ++i) | |
948 | { | |
949 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
950 | TCollection_AsciiString aName (argv[i]); | |
951 | ||
952 | if (!aMap.IsBound2 (aName)) | |
953 | { | |
954 | di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n"; | |
955 | continue; | |
956 | } | |
957 | Handle(AIS_Shape) anAISObject = | |
958 | Handle(AIS_Shape)::DownCast (aMap.Find2(aName)); | |
959 | if (anAISObject.IsNull()) | |
960 | continue; | |
961 | anAISObject->SetTypeOfHLR (aTypeOfHLR); | |
962 | if (MyHLRIsOn) | |
963 | anAISObject->Redisplay(); | |
964 | } | |
965 | ViewerTest::CurrentView()->Update(); | |
966 | } | |
967 | ||
968 | return 0; | |
969 | } | |
970 | ||
18d715bd | 971 | //============================================================================== |
972 | //function : FindViewIdByWindowHandle | |
973 | //purpose : Find theView Id in the map of views by window handle | |
974 | //============================================================================== | |
975 | #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
976 | TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle) | |
977 | { | |
978 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
979 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
980 | { | |
981 | Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window()); | |
982 | if (aWindowHandle == theWindowHandle) | |
983 | return anIter.Key1(); | |
984 | } | |
985 | return TCollection_AsciiString(""); | |
986 | } | |
987 | #endif | |
988 | ||
989 | //============================================================================== | |
990 | //function : ActivateView | |
991 | //purpose : Make the view active | |
992 | //============================================================================== | |
993 | ||
994 | void ActivateView (const TCollection_AsciiString& theViewName) | |
995 | { | |
996 | const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
997 | if (!aView.IsNull()) | |
998 | { | |
999 | Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView); | |
1000 | if (!anAISContext.IsNull()) | |
1001 | { | |
1002 | if (!ViewerTest::CurrentView().IsNull()) | |
1003 | { | |
1004 | TCollection_AsciiString aTitle("3D View - "); | |
1005 | aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); | |
1006 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1007 | } | |
1008 | ||
1009 | ViewerTest::CurrentView (aView); | |
1010 | // Update degenerate mode | |
1011 | MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode(); | |
1012 | ViewerTest::SetAISContext (anAISContext); | |
1013 | TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - "); | |
1014 | aTitle = aTitle + theViewName + "(*)"; | |
1015 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1016 | #if defined(_WIN32) || defined(__WIN32__) | |
1017 | VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
1018 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1019 | VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
1020 | #else | |
1021 | VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
1022 | #endif | |
1023 | SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); | |
1024 | ViewerTest::CurrentView()->Redraw(); | |
1025 | } | |
1026 | } | |
1027 | } | |
1028 | ||
0e93d9e5 | 1029 | //============================================================================== |
1030 | //function : RemoveView | |
1031 | //purpose : | |
1032 | //============================================================================== | |
1033 | void ViewerTest::RemoveView (const Handle(V3d_View)& theView, | |
1034 | const Standard_Boolean theToRemoveContext) | |
1035 | { | |
1036 | if (!ViewerTest_myViews.IsBound2 (theView)) | |
1037 | { | |
1038 | return; | |
1039 | } | |
1040 | ||
1041 | const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView); | |
1042 | RemoveView (aViewName, theToRemoveContext); | |
1043 | } | |
1044 | ||
18d715bd | 1045 | //============================================================================== |
1046 | //function : RemoveView | |
1047 | //purpose : Close and remove view from display, clear maps if neccessary | |
1048 | //============================================================================== | |
1049 | void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved) | |
1050 | { | |
1051 | if (!ViewerTest_myViews.IsBound1(theViewName)) | |
1052 | { | |
1053 | cout << "Wrong view name\n"; | |
1054 | return; | |
1055 | } | |
1056 | ||
1057 | // Activate another view if it's active now | |
1058 | if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView()) | |
1059 | { | |
1060 | if (ViewerTest_myViews.Extent() > 1) | |
1061 | { | |
1062 | TCollection_AsciiString aNewViewName; | |
1063 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator | |
1064 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
1065 | if (anIter.Key1() != theViewName) | |
1066 | { | |
1067 | aNewViewName = anIter.Key1(); | |
1068 | break; | |
1069 | } | |
1070 | ActivateView (aNewViewName); | |
1071 | } | |
1072 | else | |
1073 | { | |
1074 | Handle(V3d_View) anEmptyView; | |
1075 | #if defined(_WIN32) || defined(__WIN32__) | |
1076 | Handle(WNT_Window) anEmptyWindow; | |
1077 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1078 | Handle(Cocoa_Window) anEmptyWindow; | |
1079 | #else | |
1080 | Handle(Xw_Window) anEmptyWindow; | |
1081 | #endif | |
1082 | VT_GetWindow() = anEmptyWindow; | |
1083 | ViewerTest::CurrentView (anEmptyView); | |
1084 | if (isContextRemoved) | |
1085 | { | |
1086 | Handle(AIS_InteractiveContext) anEmptyContext; | |
1087 | ViewerTest::SetAISContext(anEmptyContext); | |
1088 | } | |
1089 | } | |
1090 | } | |
1091 | ||
1092 | // Delete view | |
1093 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
1094 | Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView); | |
1095 | ||
1096 | // Remove view resources | |
1097 | TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView)); | |
1098 | ViewerTest_myViews.UnBind1(theViewName); | |
1099 | aView->Remove(); | |
1100 | ||
1101 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
1102 | XFlush (GetDisplayConnection()->GetDisplay()); | |
1103 | #endif | |
1104 | ||
1105 | // Keep context opened only if the closed view is last to avoid | |
1106 | // unused empty contexts | |
1107 | if (!aCurrentContext.IsNull()) | |
1108 | { | |
1109 | // Check if there are more difined views in the viewer | |
1110 | aCurrentContext->CurrentViewer()->InitDefinedViews(); | |
1111 | if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews()) | |
1112 | { | |
1113 | // Remove driver if there is no viewers that use it | |
1114 | Standard_Boolean isRemoveDriver = Standard_True; | |
1115 | for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1116 | anIter(ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
1117 | { | |
1118 | if (aCurrentContext != anIter.Key2() && | |
1119 | aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver()) | |
1120 | { | |
1121 | isRemoveDriver = Standard_False; | |
1122 | break; | |
1123 | } | |
1124 | } | |
1125 | if(isRemoveDriver) | |
1126 | { | |
1127 | ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver()); | |
1128 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
1129 | #if TCL_MAJOR_VERSION < 8 | |
1130 | Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); | |
1131 | #else | |
1132 | Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); | |
1133 | #endif | |
1134 | #endif | |
1135 | } | |
1136 | ||
1137 | ViewerTest_myContexts.UnBind2(aCurrentContext); | |
1138 | } | |
1139 | } | |
1140 | cout << "3D View - " << theViewName << " was deleted.\n"; | |
1141 | ||
1142 | } | |
1143 | ||
1144 | //============================================================================== | |
1145 | //function : VClose | |
1146 | //purpose : Remove the view defined by its name | |
1147 | //============================================================================== | |
1148 | ||
d0cc1cb7 | 1149 | static int VClose (Draw_Interpretor& /*theDi*/, |
1150 | Standard_Integer theArgsNb, | |
1151 | const char** theArgVec) | |
18d715bd | 1152 | { |
18d715bd | 1153 | NCollection_List<TCollection_AsciiString> aViewList; |
d0cc1cb7 | 1154 | if (theArgsNb > 1) |
18d715bd | 1155 | { |
d0cc1cb7 | 1156 | TCollection_AsciiString anArg (theArgVec[1]); |
1157 | anArg.UpperCase(); | |
1158 | if (anArg.IsEqual ("ALL") | |
1159 | || anArg.IsEqual ("*")) | |
1160 | { | |
1161 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews); | |
1162 | anIter.More(); anIter.Next()) | |
1163 | { | |
1164 | aViewList.Append (anIter.Key1()); | |
1165 | } | |
1166 | if (aViewList.IsEmpty()) | |
1167 | { | |
1168 | std::cout << "No view to close\n"; | |
1169 | return 0; | |
1170 | } | |
1171 | } | |
1172 | else | |
18d715bd | 1173 | { |
d0cc1cb7 | 1174 | ViewerTest_Names aViewName (theArgVec[1]); |
1175 | if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName())) | |
1176 | { | |
1177 | std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n"; | |
1178 | return 1; | |
1179 | } | |
1180 | aViewList.Append (aViewName.GetViewName()); | |
18d715bd | 1181 | } |
1182 | } | |
1183 | else | |
1184 | { | |
d0cc1cb7 | 1185 | // close active view |
1186 | if (ViewerTest::CurrentView().IsNull()) | |
1187 | { | |
1188 | std::cerr << "No active view!\n"; | |
1189 | return 1; | |
1190 | } | |
1191 | aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView())); | |
18d715bd | 1192 | } |
1193 | ||
d0cc1cb7 | 1194 | Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1); |
18d715bd | 1195 | for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList); |
1196 | anIter.More(); anIter.Next()) | |
1197 | { | |
d0cc1cb7 | 1198 | ViewerTest::RemoveView (anIter.Value(), toRemoveContext); |
18d715bd | 1199 | } |
1200 | ||
1201 | return 0; | |
1202 | } | |
1203 | ||
1204 | //============================================================================== | |
1205 | //function : VActivate | |
1206 | //purpose : Activate the view defined by its ID | |
1207 | //============================================================================== | |
1208 | ||
1209 | static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
1210 | { | |
1211 | if (theArgsNb > 2) | |
1212 | { | |
1213 | theDi << theArgVec[0] << ": wrong number of command arguments.\n" | |
1214 | << "Usage: " << theArgVec[0] << " ViewID\n"; | |
1215 | return 1; | |
1216 | } | |
1217 | if(theArgsNb == 1) | |
1218 | { | |
1219 | theDi.Eval("vviewlist"); | |
1220 | return 0; | |
1221 | } | |
1222 | ||
1223 | TCollection_AsciiString aNameString(theArgVec[1]); | |
29cb310a | 1224 | if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 ) |
18d715bd | 1225 | { |
1226 | TCollection_AsciiString aTitle("3D View - "); | |
1227 | aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView()); | |
1228 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1229 | Handle(V3d_View) anEmptyView; | |
1230 | #if defined(_WIN32) || defined(__WIN32__) | |
1231 | Handle(WNT_Window) anEmptyWindow; | |
1232 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1233 | Handle(Cocoa_Window) anEmptyWindow; | |
1234 | #else | |
1235 | Handle(Xw_Window) anEmptyWindow; | |
1236 | #endif | |
1237 | VT_GetWindow() = anEmptyWindow; | |
1238 | ViewerTest::CurrentView (anEmptyView); | |
1239 | ViewerTest::ResetEventManager(); | |
1240 | theDi << theArgVec[0] << ": all views are inactive\n"; | |
1241 | return 0; | |
1242 | } | |
1243 | ||
1244 | ViewerTest_Names aViewNames(aNameString); | |
1245 | ||
1246 | // Check if this view exists in the viewer with the driver | |
1247 | if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName())) | |
1248 | { | |
1249 | theDi << "Wrong view name\n"; | |
1250 | return 1; | |
1251 | } | |
1252 | ||
1253 | // Check if it is active already | |
1254 | if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName())) | |
1255 | { | |
1256 | theDi << theArgVec[0] << ": the view is active already\n"; | |
1257 | return 0; | |
1258 | } | |
1259 | ||
1260 | ActivateView (aViewNames.GetViewName()); | |
1261 | return 0; | |
1262 | } | |
1263 | ||
1264 | //============================================================================== | |
1265 | //function : VViewList | |
1266 | //purpose : Print current list of views per viewer and graphic driver ID | |
1267 | // shared between viewers | |
1268 | //============================================================================== | |
1269 | ||
1270 | static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
1271 | { | |
1272 | if (theArgsNb > 2) | |
1273 | { | |
1274 | theDi << theArgVec[0] << ": Wrong number of command arguments\n" | |
29cb310a | 1275 | << "Usage: " << theArgVec[0] << " name"; |
18d715bd | 1276 | return 1; |
1277 | } | |
1278 | if (ViewerTest_myContexts.Size() < 1) | |
1279 | return 0; | |
1280 | ||
18d715bd | 1281 | Standard_Boolean isTreeView = |
29cb310a | 1282 | (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 )); |
18d715bd | 1283 | |
1284 | if (isTreeView) | |
1285 | theDi << theArgVec[0] <<":\n"; | |
1286 | ||
1287 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
1288 | aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next()) | |
1289 | { | |
1290 | if (isTreeView) | |
1291 | theDi << aDriverIter.Key1() << ":\n"; | |
1292 | ||
1293 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1294 | aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next()) | |
1295 | { | |
1296 | if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1) | |
1297 | { | |
1298 | if (isTreeView) | |
1299 | { | |
1300 | TCollection_AsciiString aContextName(aContextIter.Key1()); | |
1301 | theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n"; | |
1302 | } | |
1303 | ||
1304 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
1305 | aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next()) | |
1306 | { | |
1307 | if (aViewIter.Key1().Search(aContextIter.Key1()) != -1) | |
1308 | { | |
1309 | TCollection_AsciiString aViewName(aViewIter.Key1()); | |
1310 | if (isTreeView) | |
1311 | { | |
1312 | if (aViewIter.Value() == ViewerTest::CurrentView()) | |
1313 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n"; | |
1314 | else | |
1315 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n"; | |
1316 | } | |
1317 | else | |
1318 | { | |
1319 | theDi << aViewName << " "; | |
1320 | } | |
1321 | } | |
1322 | } | |
1323 | } | |
1324 | } | |
1325 | } | |
1326 | return 0; | |
1327 | } | |
1328 | ||
7fd59977 | 1329 | //============================================================================== |
4fe56619 | 1330 | //function : VT_ProcessKeyPress |
7fd59977 | 1331 | //purpose : Handle KeyPress event from a CString |
1332 | //============================================================================== | |
4fe56619 | 1333 | void VT_ProcessKeyPress (const char* buf_ret) |
7fd59977 | 1334 | { |
1335 | //cout << "KeyPress" << endl; | |
1336 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
1337 | const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView); | |
1338 | // Letter in alphabetic order | |
1339 | ||
b514beda | 1340 | if (!strcasecmp (buf_ret, "A")) |
1341 | { | |
7fd59977 | 1342 | // AXO |
1343 | aView->SetProj(V3d_XposYnegZpos); | |
1344 | } | |
b514beda | 1345 | else if (!strcasecmp (buf_ret, "D")) |
1346 | { | |
7fd59977 | 1347 | // Reset |
1348 | aView->Reset(); | |
1349 | } | |
b514beda | 1350 | else if (!strcasecmp (buf_ret, "F")) |
1351 | { | |
7fd59977 | 1352 | // FitAll |
1353 | if (aNisView.IsNull()) | |
1354 | aView->FitAll(); | |
1355 | else | |
1356 | aNisView->FitAll3d(); | |
1357 | } | |
b514beda | 1358 | else if (!strcasecmp (buf_ret, "H")) |
1359 | { | |
7fd59977 | 1360 | // HLR |
1361 | cout << "HLR" << endl; | |
de75ed09 | 1362 | aView->SetComputedMode (!aView->ComputedMode()); |
1363 | MyHLRIsOn = aView->ComputedMode(); | |
7fd59977 | 1364 | } |
b514beda | 1365 | else if (!strcasecmp (buf_ret, "P")) |
1366 | { | |
0a768f56 | 1367 | // Type of HLR |
1368 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
1369 | if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo) | |
1370 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo); | |
1371 | else | |
1372 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo); | |
1373 | if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0) | |
1374 | { | |
1375 | AIS_ListOfInteractive aListOfShapes; | |
1376 | aContext->DisplayedObjects(aListOfShapes); | |
1377 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); | |
1378 | anIter.More(); anIter.Next()) | |
1379 | { | |
1380 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
1381 | if (aShape.IsNull()) | |
1382 | continue; | |
1383 | if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1384 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1385 | else | |
1386 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
1387 | aShape->Redisplay(); | |
1388 | } | |
1389 | } | |
1390 | else | |
1391 | { | |
1392 | for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()) | |
1393 | { | |
1394 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current()); | |
1395 | if (aShape.IsNull()) | |
1396 | continue; | |
1397 | if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1398 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1399 | else | |
1400 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
1401 | aShape->Redisplay(); | |
1402 | } | |
1403 | } | |
1404 | ||
1405 | aContext->UpdateCurrentViewer(); | |
4269bd1b | 1406 | |
0a768f56 | 1407 | } |
b514beda | 1408 | else if (!strcasecmp (buf_ret, "S")) |
1409 | { | |
1410 | std::cout << "setup Shaded display mode" << std::endl; | |
4fe56619 | 1411 | |
7fd59977 | 1412 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
1413 | if(Ctx->NbCurrents()==0 || | |
1414 | Ctx->NbSelected()==0) | |
1415 | Ctx->SetDisplayMode(AIS_Shaded); | |
1416 | else{ | |
1417 | if(Ctx->HasOpenedContext()){ | |
1418 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1419 | Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False); | |
1420 | } | |
1421 | else{ | |
1422 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
1423 | Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False); | |
1424 | } | |
1425 | Ctx->UpdateCurrentViewer(); | |
1426 | } | |
1427 | } | |
b514beda | 1428 | else if (!strcasecmp (buf_ret, "U")) |
1429 | { | |
41811896 | 1430 | // Unset display mode |
b514beda | 1431 | std::cout << "reset display mode to defaults" << std::endl; |
4fe56619 | 1432 | |
7fd59977 | 1433 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
1434 | if(Ctx->NbCurrents()==0 || | |
1435 | Ctx->NbSelected()==0) | |
1436 | Ctx->SetDisplayMode(AIS_WireFrame); | |
1437 | else{ | |
1438 | if(Ctx->HasOpenedContext()){ | |
1439 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1440 | Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False); | |
1441 | } | |
1442 | else{ | |
1443 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
1444 | Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False); | |
1445 | } | |
1446 | Ctx->UpdateCurrentViewer(); | |
1447 | } | |
1448 | ||
1449 | } | |
b514beda | 1450 | else if (!strcasecmp (buf_ret, "T")) |
1451 | { | |
7fd59977 | 1452 | // Top |
1453 | aView->SetProj(V3d_Zpos); | |
1454 | } | |
b514beda | 1455 | else if (!strcasecmp (buf_ret, "B")) |
1456 | { | |
41811896 | 1457 | // Bottom |
7fd59977 | 1458 | aView->SetProj(V3d_Zneg); |
1459 | } | |
b514beda | 1460 | else if (!strcasecmp (buf_ret, "L")) |
1461 | { | |
41811896 | 1462 | // Left |
7fd59977 | 1463 | aView->SetProj(V3d_Xneg); |
1464 | } | |
b514beda | 1465 | else if (!strcasecmp (buf_ret, "R")) |
1466 | { | |
41811896 | 1467 | // Right |
7fd59977 | 1468 | aView->SetProj(V3d_Xpos); |
1469 | } | |
b514beda | 1470 | else if (!strcasecmp (buf_ret, "W")) |
1471 | { | |
1472 | std::cout << "setup WireFrame display mode" << std::endl; | |
7fd59977 | 1473 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
1474 | if(Ctx->NbCurrents()==0 || | |
1475 | Ctx->NbSelected()==0) | |
1476 | Ctx->SetDisplayMode(AIS_WireFrame); | |
1477 | else{ | |
1478 | if(Ctx->HasOpenedContext()){ | |
1479 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1480 | Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False); | |
1481 | } | |
1482 | else{ | |
1483 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
1484 | Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False); | |
1485 | } | |
1486 | Ctx->UpdateCurrentViewer(); | |
1487 | } | |
1488 | } | |
b514beda | 1489 | else if (!strcasecmp (buf_ret, "Z")) |
1490 | { | |
7fd59977 | 1491 | // ZCLIP |
7fd59977 | 1492 | if ( ZClipIsOn ) { |
1493 | cout << "ZClipping OFF" << endl; | |
1494 | ZClipIsOn = 0; | |
1495 | ||
1496 | aView->SetZClippingType(V3d_OFF); | |
1497 | aView->Redraw(); | |
1498 | } | |
1499 | else { | |
1500 | cout << "ZClipping ON" << endl; | |
1501 | ZClipIsOn = 1; | |
1502 | ||
1503 | aView->SetZClippingType(V3d_FRONT); | |
1504 | aView->Redraw(); | |
1505 | } | |
1506 | } | |
b514beda | 1507 | else if (!strcasecmp (buf_ret, ",")) |
1508 | { | |
7fd59977 | 1509 | ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView()); |
7fd59977 | 1510 | } |
b514beda | 1511 | else if (!strcasecmp (buf_ret, ".")) |
1512 | { | |
7fd59977 | 1513 | ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView()); |
1514 | } | |
b514beda | 1515 | else if (*buf_ret == THE_KEY_DELETE) |
1516 | { | |
1517 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
1518 | if (!aCtx.IsNull() | |
1519 | && aCtx->NbCurrents() > 0 | |
1520 | && aCtx->NbSelected() > 0) | |
1521 | { | |
1522 | Draw_Interprete ("verase"); | |
1523 | } | |
1524 | } | |
1525 | else | |
1526 | { | |
1527 | // Number | |
91322f44 | 1528 | Standard_Integer Num = Draw::Atoi(buf_ret); |
7fd59977 | 1529 | if(Num>=0 && Num<=7) |
1530 | ViewerTest::StandardModeActivation(Num); | |
1531 | } | |
1532 | } | |
1533 | ||
1534 | //============================================================================== | |
4fe56619 | 1535 | //function : VT_ProcessExpose |
7fd59977 | 1536 | //purpose : Redraw the View on an Expose Event |
1537 | //============================================================================== | |
4fe56619 | 1538 | void VT_ProcessExpose() |
1539 | { | |
1540 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); | |
1541 | if (!aView3d.IsNull()) | |
1542 | { | |
1543 | aView3d->Redraw(); | |
1544 | } | |
7fd59977 | 1545 | } |
1546 | ||
1547 | //============================================================================== | |
4fe56619 | 1548 | //function : VT_ProcessConfigure |
7fd59977 | 1549 | //purpose : Resize the View on an Configure Event |
1550 | //============================================================================== | |
4fe56619 | 1551 | void VT_ProcessConfigure() |
7fd59977 | 1552 | { |
4fe56619 | 1553 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); |
1554 | if (aView3d.IsNull()) | |
1555 | { | |
1556 | return; | |
1557 | } | |
1558 | ||
1559 | aView3d->MustBeResized(); | |
1560 | aView3d->Update(); | |
1561 | aView3d->Redraw(); | |
7fd59977 | 1562 | } |
1563 | ||
1564 | //============================================================================== | |
4fe56619 | 1565 | //function : VT_ProcessButton1Press |
7fd59977 | 1566 | //purpose : Picking |
1567 | //============================================================================== | |
e79a94b9 | 1568 | Standard_Boolean VT_ProcessButton1Press (Standard_Integer , |
1569 | const char** theArgVec, | |
1570 | Standard_Boolean theToPick, | |
1571 | Standard_Boolean theIsShift) | |
7fd59977 | 1572 | { |
e79a94b9 | 1573 | if (theToPick) |
1574 | { | |
7fd59977 | 1575 | Standard_Real X, Y, Z; |
e79a94b9 | 1576 | ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z); |
7fd59977 | 1577 | |
e79a94b9 | 1578 | Draw::Set (theArgVec[1], X); |
1579 | Draw::Set (theArgVec[2], Y); | |
1580 | Draw::Set (theArgVec[3], Z); | |
1581 | } | |
7fd59977 | 1582 | |
e79a94b9 | 1583 | if (theIsShift) |
1584 | { | |
1585 | ViewerTest::CurrentEventManager()->ShiftSelect(); | |
1586 | } | |
7fd59977 | 1587 | else |
e79a94b9 | 1588 | { |
1589 | ViewerTest::CurrentEventManager()->Select(); | |
1590 | } | |
7fd59977 | 1591 | |
e79a94b9 | 1592 | return Standard_False; |
7fd59977 | 1593 | } |
1594 | ||
1595 | //============================================================================== | |
4fe56619 | 1596 | //function : VT_ProcessButton1Release |
1597 | //purpose : End selecting | |
7fd59977 | 1598 | //============================================================================== |
4fe56619 | 1599 | void VT_ProcessButton1Release (Standard_Boolean theIsShift) |
1600 | { | |
1601 | if (IsDragged) | |
1602 | { | |
1603 | IsDragged = Standard_False; | |
1604 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1605 | if (theIsShift) | |
1606 | { | |
1607 | EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion), | |
1608 | Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion)); | |
1609 | } | |
1610 | else | |
1611 | { | |
1612 | EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion), | |
1613 | Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion)); | |
1614 | } | |
1615 | } | |
1616 | } | |
7fd59977 | 1617 | |
4fe56619 | 1618 | //============================================================================== |
1619 | //function : VT_ProcessButton3Press | |
1620 | //purpose : Start Rotation | |
1621 | //============================================================================== | |
1622 | void VT_ProcessButton3Press() | |
1623 | { | |
7fd59977 | 1624 | Start_Rot = 1; |
de75ed09 | 1625 | if (MyHLRIsOn) |
1626 | { | |
1627 | ViewerTest::CurrentView()->SetComputedMode (Standard_False); | |
1628 | } | |
7fd59977 | 1629 | ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress ); |
7fd59977 | 1630 | } |
4fe56619 | 1631 | |
7fd59977 | 1632 | //============================================================================== |
4fe56619 | 1633 | //function : VT_ProcessButton3Release |
1634 | //purpose : End rotation | |
7fd59977 | 1635 | //============================================================================== |
4fe56619 | 1636 | void VT_ProcessButton3Release() |
1637 | { | |
1638 | if (Start_Rot) | |
1639 | { | |
7fd59977 | 1640 | Start_Rot = 0; |
de75ed09 | 1641 | if (MyHLRIsOn) |
1642 | { | |
1643 | ViewerTest::CurrentView()->SetComputedMode (Standard_True); | |
1644 | } | |
7fd59977 | 1645 | } |
7fd59977 | 1646 | } |
1647 | ||
1648 | //============================================================================== | |
1649 | //function : ProcessZClipMotion | |
1650 | //purpose : Zoom | |
1651 | //============================================================================== | |
1652 | ||
1653 | void ProcessZClipMotion() | |
1654 | { | |
1655 | Handle(V3d_View) a3DView = ViewerTest::CurrentView(); | |
1656 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { | |
1657 | static Standard_Real CurZPos = 0.; | |
1658 | ||
1659 | //Quantity_Length VDX, VDY; | |
1660 | //a3DView->Size(VDX,VDY); | |
1661 | //Standard_Real VDZ = a3DView->ZSize(); | |
1662 | //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ); | |
1663 | ||
1664 | Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress); | |
1665 | ||
1666 | // Front = Depth + width/2. | |
1667 | Standard_Real D = 0.5; | |
1668 | Standard_Real W = 0.1; | |
1669 | ||
1670 | CurZPos += (dx); | |
1671 | ||
1672 | D += CurZPos; | |
1673 | ||
1674 | //printf("dx %lf Depth %lf Width %lf\n", dx, D, W); | |
1675 | ||
1676 | a3DView->SetZClippingType(V3d_OFF); | |
1677 | a3DView->SetZClippingDepth(D); | |
1678 | a3DView->SetZClippingWidth(W); | |
1679 | a3DView->SetZClippingType(V3d_FRONT); | |
1680 | ||
1681 | a3DView->Redraw(); | |
1682 | ||
1683 | X_ButtonPress = X_Motion; | |
1684 | Y_ButtonPress = Y_Motion; | |
1685 | } | |
1686 | } | |
1687 | ||
1688 | //============================================================================== | |
1689 | //function : ProcessControlButton1Motion | |
1690 | //purpose : Zoom | |
1691 | //============================================================================== | |
1692 | ||
900f7229 | 1693 | #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 1694 | static void ProcessControlButton1Motion() |
1695 | { | |
1696 | ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion); | |
1697 | ||
1698 | X_ButtonPress = X_Motion; | |
1699 | Y_ButtonPress = Y_Motion; | |
1700 | } | |
900f7229 | 1701 | #endif |
7fd59977 | 1702 | |
1703 | //============================================================================== | |
4fe56619 | 1704 | //function : VT_ProcessControlButton2Motion |
1705 | //purpose : Panning | |
7fd59977 | 1706 | //============================================================================== |
4fe56619 | 1707 | void VT_ProcessControlButton2Motion() |
7fd59977 | 1708 | { |
197ac94e | 1709 | Standard_Integer aDx = X_Motion - X_ButtonPress; |
1710 | Standard_Integer aDy = Y_Motion - Y_ButtonPress; | |
7fd59977 | 1711 | |
197ac94e | 1712 | aDy = -aDy; // Xwindow Y axis is from top to Bottom |
7fd59977 | 1713 | |
197ac94e | 1714 | ViewerTest::CurrentView()->Pan (aDx, aDy); |
7fd59977 | 1715 | |
1716 | X_ButtonPress = X_Motion; | |
1717 | Y_ButtonPress = Y_Motion; | |
1718 | } | |
1719 | ||
1720 | //============================================================================== | |
4fe56619 | 1721 | //function : VT_ProcessControlButton3Motion |
7fd59977 | 1722 | //purpose : Rotation |
1723 | //============================================================================== | |
4fe56619 | 1724 | void VT_ProcessControlButton3Motion() |
7fd59977 | 1725 | { |
4fe56619 | 1726 | if (Start_Rot) |
1727 | { | |
1728 | ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion); | |
1729 | } | |
7fd59977 | 1730 | } |
1731 | ||
1732 | //============================================================================== | |
4fe56619 | 1733 | //function : VT_ProcessMotion |
1734 | //purpose : | |
7fd59977 | 1735 | //============================================================================== |
4fe56619 | 1736 | void VT_ProcessMotion() |
7fd59977 | 1737 | { |
1738 | //pre-hilights detected objects at mouse position | |
1739 | ||
1740 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1741 | EM->MoveTo(X_Motion, Y_Motion); | |
1742 | } | |
1743 | ||
1744 | ||
1745 | void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix) | |
1746 | { | |
1747 | Xpix = X_Motion;Ypix=Y_Motion; | |
1748 | } | |
1749 | ||
44b8f2d6 | 1750 | //============================================================================== |
1751 | //function : ViewProject: implements VAxo, VTop, VLeft, ... | |
1752 | //purpose : Switches to an axonometric, top, left and other views | |
1753 | //============================================================================== | |
1754 | ||
1755 | static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori) | |
1756 | { | |
4fe56619 | 1757 | if ( ViewerTest::CurrentView().IsNull() ) |
44b8f2d6 | 1758 | { |
1759 | di<<"Call vinit before this command, please"<<"\n"; | |
1760 | return 1; | |
1761 | } | |
1762 | ||
1763 | ViewerTest::CurrentView()->SetProj(ori); | |
1764 | return 0; | |
1765 | } | |
1766 | ||
7fd59977 | 1767 | //============================================================================== |
1768 | //function : VAxo | |
1769 | //purpose : Switch to an Axonometric view | |
1770 | //Draw arg : No args | |
1771 | //============================================================================== | |
1772 | ||
1773 | static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** ) | |
44b8f2d6 | 1774 | { |
1775 | return ViewProject(di, V3d_XposYnegZpos); | |
7fd59977 | 1776 | } |
1777 | ||
1778 | //============================================================================== | |
1779 | //function : VTop | |
1780 | //purpose : Switch to a Top View | |
1781 | //Draw arg : No args | |
1782 | //============================================================================== | |
1783 | ||
1784 | static int VTop(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1785 | { | |
44b8f2d6 | 1786 | return ViewProject(di, V3d_Zpos); |
1787 | } | |
7fd59977 | 1788 | |
44b8f2d6 | 1789 | //============================================================================== |
1790 | //function : VBottom | |
1791 | //purpose : Switch to a Bottom View | |
1792 | //Draw arg : No args | |
1793 | //============================================================================== | |
7fd59977 | 1794 | |
44b8f2d6 | 1795 | static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** ) |
1796 | { | |
1797 | return ViewProject(di, V3d_Zneg); | |
1798 | } | |
7fd59977 | 1799 | |
44b8f2d6 | 1800 | //============================================================================== |
1801 | //function : VLeft | |
1802 | //purpose : Switch to a Left View | |
1803 | //Draw arg : No args | |
1804 | //============================================================================== | |
1805 | ||
1806 | static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1807 | { | |
1808 | return ViewProject(di, V3d_Ypos); | |
1809 | } | |
1810 | ||
1811 | //============================================================================== | |
1812 | //function : VRight | |
1813 | //purpose : Switch to a Right View | |
1814 | //Draw arg : No args | |
1815 | //============================================================================== | |
1816 | ||
1817 | static int VRight(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1818 | { | |
1819 | return ViewProject(di, V3d_Yneg); | |
1820 | } | |
7fd59977 | 1821 | |
44b8f2d6 | 1822 | //============================================================================== |
1823 | //function : VFront | |
1824 | //purpose : Switch to a Front View | |
1825 | //Draw arg : No args | |
1826 | //============================================================================== | |
1827 | ||
1828 | static int VFront(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1829 | { | |
1830 | return ViewProject(di, V3d_Xpos); | |
1831 | } | |
1832 | ||
1833 | //============================================================================== | |
1834 | //function : VBack | |
1835 | //purpose : Switch to a Back View | |
1836 | //Draw arg : No args | |
1837 | //============================================================================== | |
1838 | ||
1839 | static int VBack(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1840 | { | |
1841 | return ViewProject(di, V3d_Xneg); | |
7fd59977 | 1842 | } |
1843 | ||
1844 | //============================================================================== | |
1845 | //function : VHelp | |
1846 | //purpose : Dsiplay help on viewer Keyboead and mouse commands | |
1847 | //Draw arg : No args | |
1848 | //============================================================================== | |
1849 | ||
1850 | static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1851 | { | |
1852 | ||
1853 | di << "Q : Quit the application" << "\n"; | |
1854 | ||
1855 | di << "========================="<<"\n"; | |
1856 | di << "F : FitAll" << "\n"; | |
1857 | di << "T : TopView" << "\n"; | |
41811896 | 1858 | di << "B : BottomView" << "\n"; |
1859 | di << "R : RightView" << "\n"; | |
1860 | di << "L : LeftView" << "\n"; | |
7fd59977 | 1861 | di << "A : AxonometricView" << "\n"; |
41811896 | 1862 | di << "D : ResetView" << "\n"; |
7fd59977 | 1863 | |
1864 | di << "========================="<<"\n"; | |
1865 | di << "S : Shading" << "\n"; | |
1866 | di << "W : Wireframe" << "\n"; | |
1867 | di << "H : HidelLineRemoval" << "\n"; | |
41811896 | 1868 | di << "U : Unset display mode" << "\n"; |
b514beda | 1869 | di << "Delete : Remove selection from viewer" << "\n"; |
7fd59977 | 1870 | |
1871 | di << "========================="<<"\n"; | |
1872 | di << "Selection mode "<<"\n"; | |
1873 | di << "0 : Shape" <<"\n"; | |
1874 | di << "1 : Vertex" <<"\n"; | |
1875 | di << "2 : Edge" <<"\n"; | |
1876 | di << "3 : Wire" <<"\n"; | |
1877 | di << "4 : Face" <<"\n"; | |
1878 | di << "5 : Shell" <<"\n"; | |
1879 | di << "6 : Solid" <<"\n"; | |
1880 | di << "7 : Compound" <<"\n"; | |
1881 | ||
41811896 | 1882 | di << "========================="<<"\n"; |
1883 | di << "Z : Switch Z clipping On/Off" << "\n"; | |
1884 | di << ", : Hilight next detected" << "\n"; | |
1885 | di << ". : Hilight previous detected" << "\n"; | |
7fd59977 | 1886 | |
1887 | return 0; | |
1888 | } | |
1889 | ||
7fd59977 | 1890 | #ifdef WNT |
1891 | ||
1892 | static Standard_Boolean Ppick = 0; | |
1893 | static Standard_Integer Pargc = 0; | |
1894 | static const char** Pargv = NULL; | |
1895 | ||
1896 | ||
1897 | static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd, | |
1898 | UINT Msg, | |
1899 | WPARAM wParam, | |
1900 | LPARAM lParam ) | |
1901 | { | |
18d715bd | 1902 | if (!ViewerTest_myViews.IsEmpty()) { |
7fd59977 | 1903 | |
1904 | WPARAM fwKeys = wParam; | |
1905 | ||
1906 | switch( Msg ) { | |
18d715bd | 1907 | case WM_CLOSE: |
1908 | { | |
1909 | // Delete view from map of views | |
1910 | ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd)); | |
1911 | return 0; | |
1912 | } | |
1913 | break; | |
1914 | case WM_ACTIVATE: | |
1915 | if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE | |
1916 | || ViewerTest::CurrentView().IsNull()) | |
1917 | { | |
1918 | // Activate inactive window | |
1919 | if(GetWindowHandle(VT_GetWindow()) != hwnd) | |
1920 | { | |
1921 | ActivateView (FindViewIdByWindowHandle(hwnd)); | |
1922 | } | |
1923 | } | |
1924 | break; | |
7fd59977 | 1925 | case WM_LBUTTONUP: |
8abada55 | 1926 | if (!DragFirst) |
7fd59977 | 1927 | { |
1928 | HDC hdc = GetDC( hwnd ); | |
7fd59977 | 1929 | SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) ); |
1930 | SetROP2( hdc, R2_NOT ); | |
4fe56619 | 1931 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
7fd59977 | 1932 | ReleaseDC( hwnd, hdc ); |
8abada55 | 1933 | VT_ProcessButton1Release (fwKeys & MK_SHIFT); |
7fd59977 | 1934 | } |
8abada55 | 1935 | IsDragged = Standard_False; |
7fd59977 | 1936 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); |
1937 | ||
1938 | case WM_LBUTTONDOWN: | |
1939 | if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) ) | |
1940 | { | |
1941 | IsDragged = Standard_True; | |
1942 | DragFirst = Standard_True; | |
4fe56619 | 1943 | X_ButtonPress = LOWORD(lParam); |
1944 | Y_ButtonPress = HIWORD(lParam); | |
7fd59977 | 1945 | } |
1946 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1947 | ||
1948 | break; | |
1949 | ||
1950 | case WM_MOUSEMOVE: | |
1951 | if( IsDragged ) | |
1952 | { | |
1953 | HDC hdc = GetDC( hwnd ); | |
1954 | ||
1955 | HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) ); | |
1956 | SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) ); | |
1957 | SetROP2( hdc, R2_NOT ); | |
1958 | ||
1959 | if( !DragFirst ) | |
4fe56619 | 1960 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
7fd59977 | 1961 | |
1962 | DragFirst = Standard_False; | |
4fe56619 | 1963 | X_Motion = LOWORD(lParam); |
1964 | Y_Motion = HIWORD(lParam); | |
7fd59977 | 1965 | |
4fe56619 | 1966 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
7fd59977 | 1967 | |
1968 | SelectObject( hdc, anObj ); | |
1969 | ||
1970 | ReleaseDC( hwnd, hdc ); | |
1971 | } | |
1972 | else | |
1973 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1974 | break; | |
1975 | ||
1976 | default: | |
1977 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1978 | } | |
1979 | return 0; | |
1980 | } | |
1981 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1982 | } | |
1983 | ||
1984 | ||
1985 | static LRESULT WINAPI ViewerWindowProc( HWND hwnd, | |
1986 | UINT Msg, | |
1987 | WPARAM wParam, | |
1988 | LPARAM lParam ) | |
1989 | { | |
7fd59977 | 1990 | static int Up = 1; |
1991 | ||
1992 | if ( !ViewerTest::CurrentView().IsNull() ) { | |
1993 | PAINTSTRUCT ps; | |
1994 | ||
1995 | switch( Msg ) { | |
7fd59977 | 1996 | case WM_PAINT: |
7fd59977 | 1997 | BeginPaint(hwnd, &ps); |
1998 | EndPaint(hwnd, &ps); | |
4fe56619 | 1999 | VT_ProcessExpose(); |
7fd59977 | 2000 | break; |
2001 | ||
2002 | case WM_SIZE: | |
4fe56619 | 2003 | VT_ProcessConfigure(); |
7fd59977 | 2004 | break; |
2005 | ||
2006 | case WM_KEYDOWN: | |
4fe56619 | 2007 | if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL)) |
2008 | { | |
7fd59977 | 2009 | char c[2]; |
2010 | c[0] = (char) wParam; | |
2011 | c[1] = '\0'; | |
b514beda | 2012 | if (wParam == VK_DELETE) |
2013 | { | |
2014 | c[0] = THE_KEY_DELETE; | |
2015 | } | |
4ca4bbe8 | 2016 | // comma |
2017 | else if (wParam == VK_OEM_COMMA) | |
2018 | { | |
2019 | c[0] = ','; | |
2020 | } | |
2021 | // dot | |
2022 | else if (wParam == VK_OEM_PERIOD) | |
2023 | { | |
2024 | c[0] = '.'; | |
2025 | } | |
4fe56619 | 2026 | VT_ProcessKeyPress (c); |
7fd59977 | 2027 | } |
2028 | break; | |
2029 | ||
2030 | case WM_LBUTTONUP: | |
2031 | case WM_MBUTTONUP: | |
2032 | case WM_RBUTTONUP: | |
7fd59977 | 2033 | Up = 1; |
4fe56619 | 2034 | VT_ProcessButton3Release(); |
7fd59977 | 2035 | break; |
2036 | ||
2037 | case WM_LBUTTONDOWN: | |
2038 | case WM_MBUTTONDOWN: | |
2039 | case WM_RBUTTONDOWN: | |
2040 | { | |
7fd59977 | 2041 | WPARAM fwKeys = wParam; |
2042 | ||
2043 | Up = 0; | |
2044 | ||
2045 | X_ButtonPress = LOWORD(lParam); | |
2046 | Y_ButtonPress = HIWORD(lParam); | |
2047 | ||
4fe56619 | 2048 | if (Msg == WM_LBUTTONDOWN) |
2049 | { | |
2050 | if (fwKeys & MK_CONTROL) | |
2051 | { | |
2052 | Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT)); | |
2053 | } | |
2054 | else | |
2055 | { | |
2056 | VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT)); | |
2057 | } | |
7fd59977 | 2058 | } |
4fe56619 | 2059 | else if (Msg == WM_RBUTTONDOWN) |
2060 | { | |
7fd59977 | 2061 | // Start rotation |
4fe56619 | 2062 | VT_ProcessButton3Press(); |
7fd59977 | 2063 | } |
2064 | } | |
2065 | break; | |
2066 | ||
2067 | case WM_MOUSEMOVE: | |
2068 | { | |
2069 | //cout << "\t WM_MOUSEMOVE" << endl; | |
2070 | WPARAM fwKeys = wParam; | |
2071 | X_Motion = LOWORD(lParam); | |
2072 | Y_Motion = HIWORD(lParam); | |
2073 | ||
2074 | if ( Up && | |
2075 | fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) { | |
2076 | Up = 0; | |
2077 | X_ButtonPress = LOWORD(lParam); | |
2078 | Y_ButtonPress = HIWORD(lParam); | |
2079 | ||
2080 | if ( fwKeys & MK_RBUTTON ) { | |
2081 | // Start rotation | |
4fe56619 | 2082 | VT_ProcessButton3Press(); |
7fd59977 | 2083 | } |
2084 | } | |
2085 | ||
2086 | if ( fwKeys & MK_CONTROL ) { | |
2087 | if ( fwKeys & MK_LBUTTON ) { | |
2088 | ProcessControlButton1Motion(); | |
2089 | } | |
2090 | else if ( fwKeys & MK_MBUTTON || | |
2091 | ((fwKeys&MK_LBUTTON) && | |
2092 | (fwKeys&MK_RBUTTON) ) ){ | |
4fe56619 | 2093 | VT_ProcessControlButton2Motion(); |
7fd59977 | 2094 | } |
2095 | else if ( fwKeys & MK_RBUTTON ) { | |
4fe56619 | 2096 | VT_ProcessControlButton3Motion(); |
7fd59977 | 2097 | } |
2098 | } | |
2099 | #ifdef BUG | |
2100 | else if ( fwKeys & MK_SHIFT ) { | |
2101 | if ( fwKeys & MK_MBUTTON || | |
2102 | ((fwKeys&MK_LBUTTON) && | |
2103 | (fwKeys&MK_RBUTTON) ) ) { | |
2104 | cout << "ProcessZClipMotion()" << endl; | |
2105 | ProcessZClipMotion(); | |
2106 | } | |
2107 | } | |
2108 | #endif | |
08398024 | 2109 | else if (GetWindowHandle (VT_GetWindow()) == hwnd) |
2110 | { | |
4fe56619 | 2111 | if ((fwKeys & MK_MBUTTON |
2112 | || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON)))) | |
2113 | { | |
7fd59977 | 2114 | ProcessZClipMotion(); |
2115 | } | |
4fe56619 | 2116 | else |
2117 | { | |
2118 | VT_ProcessMotion(); | |
7fd59977 | 2119 | } |
08398024 | 2120 | } |
7fd59977 | 2121 | } |
2122 | break; | |
2123 | ||
2124 | default: | |
2125 | return( DefWindowProc( hwnd, Msg, wParam, lParam )); | |
2126 | } | |
2127 | return 0L; | |
2128 | } | |
2129 | ||
2130 | return DefWindowProc( hwnd, Msg, wParam, lParam ); | |
2131 | } | |
2132 | ||
2133 | ||
2134 | ||
2135 | ||
2136 | //============================================================================== | |
2137 | //function : ViewerMainLoop | |
2138 | //purpose : Get a Event on the view and dispatch it | |
2139 | //============================================================================== | |
2140 | ||
2141 | ||
8263fcd3 | 2142 | int ViewerMainLoop(Standard_Integer argc, const char** argv) |
7fd59977 | 2143 | { |
7fd59977 | 2144 | Ppick = (argc > 0)? 1 : 0; |
2145 | Pargc = argc; | |
2146 | Pargv = argv; | |
2147 | ||
2148 | if ( Ppick ) { | |
2149 | MSG msg; | |
2150 | msg.wParam = 1; | |
2151 | ||
2152 | cout << "Start picking" << endl; | |
2153 | ||
7fd59977 | 2154 | while ( Ppick == 1 ) { |
4fe56619 | 2155 | // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0 |
7fd59977 | 2156 | if (GetMessage(&msg, NULL, 0, 0) ) { |
2157 | TranslateMessage(&msg); | |
2158 | DispatchMessage(&msg); | |
2159 | } | |
2160 | } | |
2161 | ||
2162 | cout << "Picking done" << endl; | |
2163 | } | |
2164 | ||
2165 | return Ppick; | |
2166 | } | |
2167 | ||
4fe56619 | 2168 | #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 2169 | |
2170 | int min( int a, int b ) | |
2171 | { | |
2172 | if( a<b ) | |
2173 | return a; | |
2174 | else | |
2175 | return b; | |
2176 | } | |
2177 | ||
2178 | int max( int a, int b ) | |
2179 | { | |
2180 | if( a>b ) | |
2181 | return a; | |
2182 | else | |
2183 | return b; | |
2184 | } | |
2185 | ||
2186 | int ViewerMainLoop(Standard_Integer argc, const char** argv) | |
2187 | ||
4269bd1b | 2188 | { |
18d715bd | 2189 | static XEvent aReport; |
2190 | Standard_Boolean pick = argc > 0; | |
2191 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2192 | XNextEvent (aDisplay, &aReport); | |
7fd59977 | 2193 | |
18d715bd | 2194 | // Handle event for the chosen display connection |
2195 | switch (aReport.type) { | |
2196 | case ClientMessage: | |
2197 | { | |
eb1ebea4 | 2198 | if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW)) |
18d715bd | 2199 | { |
2200 | // Close the window | |
2201 | ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window)); | |
2202 | } | |
2203 | } | |
2204 | return 0; | |
2205 | case FocusIn: | |
2206 | { | |
2207 | // Activate inactive view | |
2208 | Window aWindow = GetWindowHandle(VT_GetWindow()); | |
2209 | if(aWindow != aReport.xfocus.window) | |
2210 | { | |
2211 | ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window)); | |
2212 | } | |
2213 | } | |
2214 | break; | |
7fd59977 | 2215 | case Expose: |
2216 | { | |
4fe56619 | 2217 | VT_ProcessExpose(); |
7fd59977 | 2218 | } |
2219 | break; | |
2220 | case ConfigureNotify: | |
2221 | { | |
4fe56619 | 2222 | VT_ProcessConfigure(); |
7fd59977 | 2223 | } |
2224 | break; | |
2225 | case KeyPress: | |
2226 | { | |
2227 | ||
2228 | KeySym ks_ret ; | |
2229 | char buf_ret[11] ; | |
2230 | int ret_len ; | |
2231 | XComposeStatus status_in_out; | |
2232 | ||
18d715bd | 2233 | ret_len = XLookupString( ( XKeyEvent *)&aReport , |
7fd59977 | 2234 | (char *) buf_ret , 10 , |
2235 | &ks_ret , &status_in_out ) ; | |
2236 | ||
2237 | ||
2238 | buf_ret[ret_len] = '\0' ; | |
2239 | ||
4fe56619 | 2240 | if (ret_len) |
2241 | { | |
2242 | VT_ProcessKeyPress (buf_ret); | |
7fd59977 | 2243 | } |
2244 | } | |
2245 | break; | |
2246 | case ButtonPress: | |
7fd59977 | 2247 | { |
18d715bd | 2248 | X_ButtonPress = aReport.xbutton.x; |
2249 | Y_ButtonPress = aReport.xbutton.y; | |
7fd59977 | 2250 | |
18d715bd | 2251 | if (aReport.xbutton.button == Button1) |
4fe56619 | 2252 | { |
18d715bd | 2253 | if (aReport.xbutton.state & ControlMask) |
4fe56619 | 2254 | { |
18d715bd | 2255 | pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask)); |
4fe56619 | 2256 | } |
7fd59977 | 2257 | else |
2258 | { | |
2259 | IsDragged = Standard_True; | |
7fd59977 | 2260 | DragFirst = Standard_True; |
2261 | } | |
4fe56619 | 2262 | } |
18d715bd | 2263 | else if (aReport.xbutton.button == Button3) |
4fe56619 | 2264 | { |
7fd59977 | 2265 | // Start rotation |
4fe56619 | 2266 | VT_ProcessButton3Press(); |
2267 | } | |
7fd59977 | 2268 | } |
2269 | break; | |
2270 | case ButtonRelease: | |
2271 | { | |
7fd59977 | 2272 | if( IsDragged ) |
2273 | { | |
2274 | if( !DragFirst ) | |
2275 | { | |
2276 | Aspect_Handle aWindow = VT_GetWindow()->XWindow(); | |
18d715bd | 2277 | GC gc = XCreateGC( aDisplay, aWindow, 0, 0 ); |
2278 | XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) ); | |
7fd59977 | 2279 | } |
2280 | ||
2281 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
2282 | if( aContext.IsNull() ) | |
2283 | { | |
2284 | cout << "The context is null. Please use vinit before createmesh" << endl; | |
2285 | return 0; | |
2286 | } | |
2287 | ||
18d715bd | 2288 | Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask ); |
2289 | if( aReport.xbutton.button==1 ) | |
7fd59977 | 2290 | if( DragFirst ) |
2291 | if( ShiftPressed ) | |
2292 | { | |
2293 | aContext->ShiftSelect(); | |
7fd59977 | 2294 | } |
2295 | else | |
2296 | { | |
2297 | aContext->Select(); | |
7fd59977 | 2298 | } |
2299 | else | |
2300 | if( ShiftPressed ) | |
2301 | { | |
4fe56619 | 2302 | aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), |
2303 | max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), | |
7fd59977 | 2304 | ViewerTest::CurrentView()); |
7fd59977 | 2305 | } |
2306 | else | |
2307 | { | |
4fe56619 | 2308 | aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), |
2309 | max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), | |
7fd59977 | 2310 | ViewerTest::CurrentView() ); |
7fd59977 | 2311 | } |
2312 | else | |
4fe56619 | 2313 | VT_ProcessButton3Release(); |
7fd59977 | 2314 | |
2315 | IsDragged = Standard_False; | |
2316 | } | |
2317 | else | |
4fe56619 | 2318 | VT_ProcessButton3Release(); |
7fd59977 | 2319 | } |
2320 | break; | |
2321 | case MotionNotify: | |
2322 | { | |
08398024 | 2323 | if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window) |
2324 | { | |
2325 | break; | |
2326 | } | |
7fd59977 | 2327 | if( IsDragged ) |
2328 | { | |
2329 | Aspect_Handle aWindow = VT_GetWindow()->XWindow(); | |
18d715bd | 2330 | GC gc = XCreateGC( aDisplay, aWindow, 0, 0 ); |
2331 | XSetFunction( aDisplay, gc, GXinvert ); | |
7fd59977 | 2332 | |
2333 | if( !DragFirst ) | |
18d715bd | 2334 | XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) ); |
7fd59977 | 2335 | |
18d715bd | 2336 | X_Motion = aReport.xmotion.x; |
2337 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2338 | DragFirst = Standard_False; |
2339 | ||
18d715bd | 2340 | XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) ); |
7fd59977 | 2341 | } |
2342 | else | |
2343 | { | |
18d715bd | 2344 | X_Motion = aReport.xmotion.x; |
2345 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2346 | |
18d715bd | 2347 | // remove all the ButtonMotionMaskr |
2348 | while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ; | |
7fd59977 | 2349 | |
18d715bd | 2350 | if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) { |
7fd59977 | 2351 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { |
2352 | ||
2353 | Quantity_Length VDX, VDY; | |
2354 | ||
2355 | ViewerTest::CurrentView()->Size(VDX,VDY); | |
2356 | Standard_Real VDZ =0 ; | |
2357 | VDZ = ViewerTest::CurrentView()->ZSize(); | |
2358 | ||
7fd59977 | 2359 | printf("%f,%f,%f\n", VDX, VDY, VDZ); |
2360 | ||
2361 | Quantity_Length dx = 0 ; | |
2362 | dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress); | |
2363 | ||
2364 | cout << dx << endl; | |
2365 | ||
2366 | dx = dx / VDX * VDZ; | |
2367 | ||
2368 | cout << dx << endl; | |
2369 | ||
7fd59977 | 2370 | ViewerTest::CurrentView()->Redraw(); |
2371 | } | |
2372 | } | |
2373 | ||
18d715bd | 2374 | if ( aReport.xmotion.state & ControlMask ) { |
2375 | if ( aReport.xmotion.state & Button1Mask ) { | |
7fd59977 | 2376 | ProcessControlButton1Motion(); |
2377 | } | |
18d715bd | 2378 | else if ( aReport.xmotion.state & Button2Mask ) { |
4fe56619 | 2379 | VT_ProcessControlButton2Motion(); |
7fd59977 | 2380 | } |
18d715bd | 2381 | else if ( aReport.xmotion.state & Button3Mask ) { |
4fe56619 | 2382 | VT_ProcessControlButton3Motion(); |
7fd59977 | 2383 | } |
2384 | } | |
4fe56619 | 2385 | else |
2386 | { | |
2387 | VT_ProcessMotion(); | |
7fd59977 | 2388 | } |
2389 | } | |
2390 | } | |
2391 | break; | |
2392 | } | |
7fd59977 | 2393 | return pick; |
2394 | } | |
2395 | ||
2396 | //============================================================================== | |
2397 | //function : VProcessEvents | |
2398 | //purpose : call by Tk_CreateFileHandler() to be able to manage the | |
2399 | // event in the Viewer window | |
2400 | //============================================================================== | |
2401 | ||
2402 | static void VProcessEvents(ClientData,int) | |
2403 | { | |
18d715bd | 2404 | NCollection_Vector<int> anEventNumbers; |
2405 | // Get number of messages from every display | |
2406 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2407 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next()) | |
2408 | { | |
2409 | anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay())); | |
4269bd1b | 2410 | } |
18d715bd | 2411 | // Handle events for every display |
2412 | int anEventIter = 0; | |
2413 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2414 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++) | |
2415 | { | |
4269bd1b | 2416 | for (int i = 0; i < anEventNumbers.Value(anEventIter) && |
18d715bd | 2417 | XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i) |
2418 | { | |
2419 | SetDisplayConnection (anIter.Key2()->GetDisplayConnection()); | |
2420 | int anEventResult = ViewerMainLoop( 0, NULL); | |
2421 | // If window is closed or context was not found finish current event processing loop | |
2422 | if (!anEventResult) | |
2423 | return; | |
2424 | } | |
7fd59977 | 2425 | } |
4269bd1b | 2426 | |
18d715bd | 2427 | SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection()); |
4269bd1b | 2428 | |
7fd59977 | 2429 | } |
2430 | #endif | |
2431 | ||
2432 | //============================================================================== | |
2433 | //function : OSWindowSetup | |
2434 | //purpose : Setup for the X11 window to be able to cath the event | |
2435 | //============================================================================== | |
2436 | ||
2437 | ||
2438 | static void OSWindowSetup() | |
2439 | { | |
4fe56619 | 2440 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
7fd59977 | 2441 | // X11 |
2442 | ||
2443 | Window window = VT_GetWindow()->XWindow(); | |
18d715bd | 2444 | SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
2445 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2446 | XSynchronize(aDisplay, 1); | |
7fd59977 | 2447 | |
2448 | // X11 : For keyboard on SUN | |
2449 | XWMHints wmhints; | |
2450 | wmhints.flags = InputHint; | |
2451 | wmhints.input = 1; | |
2452 | ||
18d715bd | 2453 | XSetWMHints( aDisplay, window, &wmhints); |
7fd59977 | 2454 | |
18d715bd | 2455 | XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | |
7fd59977 | 2456 | ButtonPressMask | ButtonReleaseMask | |
2457 | StructureNotifyMask | | |
2458 | PointerMotionMask | | |
2459 | Button1MotionMask | Button2MotionMask | | |
18d715bd | 2460 | Button3MotionMask | FocusChangeMask |
7fd59977 | 2461 | ); |
18d715bd | 2462 | Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW); |
2463 | XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1); | |
7fd59977 | 2464 | |
18d715bd | 2465 | XSynchronize(aDisplay, 0); |
7fd59977 | 2466 | |
2467 | #else | |
2468 | // WNT | |
2469 | #endif | |
2470 | ||
2471 | } | |
2472 | ||
2473 | ||
2474 | //============================================================================== | |
2475 | //function : VFit | |
2476 | ||
2477 | //purpose : Fitall, no DRAW arguments | |
2478 | //Draw arg : No args | |
2479 | //============================================================================== | |
2480 | ||
2481 | static int VFit(Draw_Interpretor& , Standard_Integer , const char** ) | |
2482 | { | |
2483 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
2484 | Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView); | |
2485 | if (V.IsNull() == Standard_False) { | |
2486 | V->FitAll3d(); | |
2487 | } else if (aView.IsNull() == Standard_False) { | |
2488 | aView->FitAll(); | |
2489 | } | |
2490 | return 0; | |
2491 | } | |
2492 | ||
6262a303 | 2493 | //======================================================================= |
2494 | //function : VFitArea | |
2495 | //purpose : Fit view to show area located between two points | |
2496 | // : given in world 2D or 3D coordinates. | |
2497 | //======================================================================= | |
2498 | static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
2499 | { | |
2500 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
2501 | if (aView.IsNull()) | |
2502 | { | |
2503 | std::cerr << theArgVec[0] << "Error: No active view.\n"; | |
2504 | return 1; | |
2505 | } | |
2506 | ||
2507 | // Parse arguments. | |
2508 | gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0); | |
2509 | gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0); | |
2510 | ||
2511 | if (theArgNb == 5) | |
2512 | { | |
2513 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
2514 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
2515 | aWorldPnt2.SetX (Draw::Atof (theArgVec[3])); | |
2516 | aWorldPnt2.SetY (Draw::Atof (theArgVec[4])); | |
2517 | } | |
2518 | else if (theArgNb == 7) | |
2519 | { | |
2520 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
2521 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
2522 | aWorldPnt1.SetZ (Draw::Atof (theArgVec[3])); | |
2523 | aWorldPnt2.SetX (Draw::Atof (theArgVec[4])); | |
2524 | aWorldPnt2.SetY (Draw::Atof (theArgVec[5])); | |
2525 | aWorldPnt2.SetZ (Draw::Atof (theArgVec[6])); | |
2526 | } | |
2527 | else | |
2528 | { | |
2529 | std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n"; | |
2530 | theDI.PrintHelp(theArgVec[0]); | |
2531 | return 1; | |
2532 | } | |
2533 | ||
2534 | // Convert model coordinates to view space | |
2535 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); | |
2536 | gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1); | |
2537 | gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2); | |
2538 | ||
2539 | // Determine fit area | |
2540 | gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y())); | |
2541 | gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y())); | |
2542 | ||
2543 | Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner); | |
2544 | ||
2545 | if (aDiagonal < Precision::Confusion()) | |
2546 | { | |
2547 | std::cerr << theArgVec[0] << "Error: view area is too small.\n"; | |
2548 | return 1; | |
2549 | } | |
2550 | ||
2551 | aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y()); | |
2552 | return 0; | |
2553 | } | |
2554 | ||
7fd59977 | 2555 | //============================================================================== |
2556 | //function : VZFit | |
2557 | //purpose : ZFitall, no DRAW arguments | |
2558 | //Draw arg : No args | |
2559 | //============================================================================== | |
197ac94e | 2560 | static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 2561 | { |
197ac94e | 2562 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
2563 | ||
2564 | if (aCurrentView.IsNull()) | |
2565 | { | |
2566 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; | |
2567 | return 1; | |
2568 | } | |
2569 | ||
2570 | if (theArgsNb == 1) | |
2571 | { | |
6bc6a6fc | 2572 | aCurrentView->View()->ZFitAll(); |
197ac94e | 2573 | aCurrentView->Redraw(); |
2574 | return 0; | |
2575 | } | |
2576 | ||
2577 | Standard_Real aScale = 1.0; | |
2578 | ||
2579 | if (theArgsNb >= 2) | |
2580 | { | |
2581 | aScale = Draw::Atoi (theArgVec[1]); | |
2582 | } | |
2583 | ||
6bc6a6fc | 2584 | aCurrentView->View()->ZFitAll (aScale); |
197ac94e | 2585 | aCurrentView->Redraw(); |
7fd59977 | 2586 | |
197ac94e | 2587 | return 0; |
2588 | } | |
7fd59977 | 2589 | |
197ac94e | 2590 | //============================================================================== |
2591 | //function : VRepaint | |
2592 | //purpose : | |
2593 | //============================================================================== | |
2594 | static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** ) | |
7fd59977 | 2595 | { |
2596 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
2597 | if ( !V.IsNull() ) V->Redraw(); return 0; | |
2598 | } | |
2599 | ||
7fd59977 | 2600 | //============================================================================== |
2601 | //function : VClear | |
2602 | //purpose : Remove all the object from the viewer | |
2603 | //Draw arg : No args | |
2604 | //============================================================================== | |
2605 | ||
2606 | static int VClear(Draw_Interpretor& , Standard_Integer , const char** ) | |
2607 | { | |
2608 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
2609 | if(!V.IsNull()) | |
2610 | ViewerTest::Clear(); | |
2611 | return 0; | |
2612 | } | |
2613 | ||
2614 | //============================================================================== | |
2615 | //function : VPick | |
2616 | //purpose : | |
2617 | //============================================================================== | |
2618 | ||
2619 | static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2620 | { if (ViewerTest::CurrentView().IsNull() ) return 1; | |
2621 | ||
2622 | if ( argc < 4 ) { | |
2623 | di << argv[0] << "Invalid number of arguments" << "\n"; | |
2624 | return 1; | |
2625 | } | |
2626 | ||
2627 | while (ViewerMainLoop( argc, argv)) { | |
2628 | } | |
2629 | ||
2630 | return 0; | |
2631 | } | |
2632 | ||
7fd59977 | 2633 | //============================================================================== |
2634 | //function : VSetBg | |
2635 | //purpose : Load image as background | |
2636 | //============================================================================== | |
2637 | ||
2638 | static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2639 | { | |
2640 | if (argc < 2 || argc > 3) | |
2641 | { | |
2642 | di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n"; | |
f8b2ed36 | 2643 | di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n"; |
7fd59977 | 2644 | return 1; |
2645 | } | |
2646 | ||
2647 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2648 | if(AISContext.IsNull()) | |
2649 | { | |
2650 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2651 | return 1; | |
2652 | } | |
2653 | ||
2654 | Aspect_FillMethod aFillType = Aspect_FM_CENTERED; | |
2655 | if (argc == 3) | |
2656 | { | |
2657 | const char* szType = argv[2]; | |
2658 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
2659 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
2660 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
2661 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
2662 | else | |
2663 | { | |
2664 | di << "Wrong fill type : " << szType << "\n"; | |
2665 | di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
2666 | return 1; | |
2667 | } | |
2668 | } | |
2669 | ||
2670 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2671 | V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True); | |
2672 | ||
2673 | return 0; | |
2674 | } | |
2675 | ||
f8b2ed36 | 2676 | //============================================================================== |
2677 | //function : VSetBgMode | |
2678 | //purpose : Change background image fill type | |
2679 | //============================================================================== | |
2680 | ||
2681 | static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2682 | { | |
2683 | if (argc != 2) | |
2684 | { | |
2685 | di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n"; | |
2686 | di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
2687 | return 1; | |
2688 | } | |
2689 | ||
2690 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2691 | if(AISContext.IsNull()) | |
2692 | { | |
2693 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2694 | return 1; | |
2695 | } | |
1d47d8d0 | 2696 | Aspect_FillMethod aFillType = Aspect_FM_NONE; |
2697 | const char* szType = argv[1]; | |
2698 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
2699 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
2700 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
2701 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
2702 | else | |
f8b2ed36 | 2703 | { |
1d47d8d0 | 2704 | di << "Wrong fill type : " << szType << "\n"; |
2705 | di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
2706 | return 1; | |
f8b2ed36 | 2707 | } |
f8b2ed36 | 2708 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
2709 | V3dView->SetBgImageStyle(aFillType, Standard_True); | |
f8b2ed36 | 2710 | return 0; |
2711 | } | |
2712 | ||
7fd59977 | 2713 | //============================================================================== |
2714 | //function : VSetGradientBg | |
2715 | //purpose : Mount gradient background | |
2716 | //============================================================================== | |
2717 | static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2718 | { | |
2719 | if (argc != 8 ) | |
2720 | { | |
2721 | di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n"; | |
2722 | di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n"; | |
2723 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2724 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2725 | return 1; | |
2726 | } | |
2727 | ||
2728 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2729 | if(AISContext.IsNull()) | |
2730 | { | |
2731 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2732 | return 1; | |
2733 | } | |
2734 | if (argc == 8) | |
2735 | { | |
2736 | ||
91322f44 | 2737 | Standard_Real R1 = Draw::Atof(argv[1])/255.; |
2738 | Standard_Real G1 = Draw::Atof(argv[2])/255.; | |
2739 | Standard_Real B1 = Draw::Atof(argv[3])/255.; | |
7fd59977 | 2740 | Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB); |
2741 | ||
91322f44 | 2742 | Standard_Real R2 = Draw::Atof(argv[4])/255.; |
2743 | Standard_Real G2 = Draw::Atof(argv[5])/255.; | |
2744 | Standard_Real B2 = Draw::Atof(argv[6])/255.; | |
7fd59977 | 2745 | |
2746 | Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB); | |
91322f44 | 2747 | int aType = Draw::Atoi(argv[7]); |
7fd59977 | 2748 | if( aType < 0 || aType > 8 ) |
2749 | { | |
2750 | di << "Wrong fill type " << "\n"; | |
2751 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2752 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2753 | return 1; | |
2754 | } | |
2755 | ||
2756 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
2757 | ||
2758 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2759 | V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1); | |
2760 | } | |
2761 | ||
2762 | return 0; | |
2763 | } | |
2764 | ||
f8b2ed36 | 2765 | //============================================================================== |
2766 | //function : VSetGradientBgMode | |
2767 | //purpose : Change gradient background fill style | |
2768 | //============================================================================== | |
2769 | static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2770 | { | |
2771 | if (argc != 2 ) | |
2772 | { | |
2773 | di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n"; | |
2774 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2775 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2776 | return 1; | |
2777 | } | |
2778 | ||
2779 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2780 | if(AISContext.IsNull()) | |
2781 | { | |
2782 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2783 | return 1; | |
2784 | } | |
2785 | if (argc == 2) | |
2786 | { | |
91322f44 | 2787 | int aType = Draw::Atoi(argv[1]); |
f8b2ed36 | 2788 | if( aType < 0 || aType > 8 ) |
2789 | { | |
2790 | di << "Wrong fill type " << "\n"; | |
2791 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2792 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2793 | return 1; | |
2794 | } | |
2795 | ||
2796 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
2797 | ||
2798 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2799 | V3dView->SetBgGradientStyle( aMethod, 1 ); | |
2800 | } | |
2801 | ||
2802 | return 0; | |
2803 | } | |
2804 | ||
2805 | //============================================================================== | |
2806 | //function : VSetColorBg | |
2807 | //purpose : Set color background | |
2808 | //============================================================================== | |
2809 | static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2810 | { | |
2811 | if (argc != 4 ) | |
2812 | { | |
2813 | di << "Usage : " << argv[0] << " R G B : Set color background" << "\n"; | |
2814 | di << "R,G,B = [0..255]" << "\n"; | |
2815 | return 1; | |
2816 | } | |
2817 | ||
2818 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2819 | if(AISContext.IsNull()) | |
2820 | { | |
2821 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2822 | return 1; | |
2823 | } | |
2824 | if (argc == 4) | |
2825 | { | |
2826 | ||
91322f44 | 2827 | Standard_Real R = Draw::Atof(argv[1])/255.; |
2828 | Standard_Real G = Draw::Atof(argv[2])/255.; | |
2829 | Standard_Real B = Draw::Atof(argv[3])/255.; | |
f8b2ed36 | 2830 | Quantity_Color aColor(R,G,B,Quantity_TOC_RGB); |
2831 | ||
2832 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2833 | V3dView->SetBackgroundColor( aColor ); | |
2834 | V3dView->Update(); | |
2835 | } | |
2836 | ||
2837 | return 0; | |
2838 | } | |
2839 | ||
7fd59977 | 2840 | //============================================================================== |
2841 | //function : VScale | |
2842 | //purpose : View Scaling | |
2843 | //============================================================================== | |
2844 | ||
2845 | static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2846 | { | |
2847 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2848 | if ( V3dView.IsNull() ) return 1; | |
2849 | ||
2850 | if ( argc != 4 ) { | |
2851 | di << argv[0] << "Invalid number of arguments" << "\n"; | |
2852 | return 1; | |
2853 | } | |
91322f44 | 2854 | V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) ); |
7fd59977 | 2855 | return 0; |
2856 | } | |
2857 | //============================================================================== | |
2858 | //function : VTestZBuffTrihedron | |
7c8a8fcc | 2859 | //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron |
7fd59977 | 2860 | //============================================================================== |
2861 | ||
2862 | static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2863 | { | |
2864 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2865 | if ( V3dView.IsNull() ) return 1; | |
2866 | ||
7fd59977 | 2867 | V3dView->ZBufferTriedronSetup(); |
7c8a8fcc | 2868 | |
2869 | if ( argc == 1 ) { | |
2870 | // Set up default trihedron parameters | |
2871 | V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER ); | |
2872 | } else | |
2873 | if ( argc == 7 ) | |
2874 | { | |
2875 | Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER; | |
2876 | const char* aPosType = argv[1]; | |
2877 | ||
2878 | if ( strcmp(aPosType, "center") == 0 ) | |
2879 | { | |
2880 | aPosition = Aspect_TOTP_CENTER; | |
2881 | } else | |
2882 | if (strcmp(aPosType, "left_lower") == 0) | |
2883 | { | |
2884 | aPosition = Aspect_TOTP_LEFT_LOWER; | |
2885 | } else | |
2886 | if (strcmp(aPosType, "left_upper") == 0) | |
2887 | { | |
2888 | aPosition = Aspect_TOTP_LEFT_UPPER; | |
2889 | } else | |
2890 | if (strcmp(aPosType, "right_lower") == 0) | |
2891 | { | |
2892 | aPosition = Aspect_TOTP_RIGHT_LOWER; | |
2893 | } else | |
2894 | if (strcmp(aPosType, "right_upper") == 0) | |
2895 | { | |
2896 | aPosition = Aspect_TOTP_RIGHT_UPPER; | |
2897 | } else | |
2898 | { | |
2899 | di << argv[1] << " Invalid type of alignment" << "\n"; | |
2900 | di << "Must be one of [ center, left_lower," << "\n"; | |
2901 | di << "left_upper, right_lower, right_upper ]" << "\n"; | |
2902 | return 1; | |
2903 | } | |
2904 | ||
91322f44 | 2905 | Standard_Real R = Draw::Atof(argv[2])/255.; |
2906 | Standard_Real G = Draw::Atof(argv[3])/255.; | |
2907 | Standard_Real B = Draw::Atof(argv[4])/255.; | |
7c8a8fcc | 2908 | Quantity_Color aColor(R, G, B, Quantity_TOC_RGB); |
2909 | ||
91322f44 | 2910 | Standard_Real aScale = Draw::Atof(argv[5]); |
7c8a8fcc | 2911 | |
2912 | if( aScale <= 0.0 ) | |
2913 | { | |
2914 | di << argv[5] << " Invalid value. Must be > 0" << "\n"; | |
2915 | return 1; | |
2916 | } | |
2917 | ||
2918 | V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER; | |
2919 | const char* aPresType = argv[6]; | |
2920 | ||
2921 | if ( strcmp(aPresType, "wireframe") == 0 ) | |
2922 | { | |
2923 | aPresentation = V3d_WIREFRAME; | |
2924 | } else | |
2925 | if (strcmp(aPresType, "zbuffer") == 0) | |
2926 | { | |
2927 | aPresentation = V3d_ZBUFFER; | |
2928 | } else | |
2929 | { | |
2930 | di << argv[6] << " Invalid type of visualization" << "\n"; | |
2931 | di << "Must be one of [ wireframe, zbuffer ]" << "\n"; | |
2932 | return 1; | |
2933 | } | |
2934 | ||
2935 | V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation ); | |
2936 | ||
2937 | } else | |
2938 | { | |
2939 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
2940 | return 1; | |
2941 | } | |
2942 | ||
6bc6a6fc | 2943 | V3dView->View()->ZFitAll(); |
7c8a8fcc | 2944 | |
7fd59977 | 2945 | return 0; |
2946 | } | |
2947 | ||
2948 | //============================================================================== | |
2949 | //function : VRotate | |
2950 | //purpose : Camera Rotating | |
2951 | //============================================================================== | |
2952 | ||
2953 | static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
2954 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2955 | if ( V3dView.IsNull() ) { | |
2956 | return 1; | |
2957 | } | |
2958 | ||
2959 | if ( argc == 4 ) { | |
91322f44 | 2960 | V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) ); |
7fd59977 | 2961 | return 0; |
2962 | } else if ( argc == 7 ) { | |
91322f44 | 2963 | V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Draw::Atof(argv[6]) ); |
7fd59977 | 2964 | return 0; |
2965 | } else { | |
2966 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
2967 | return 1; | |
2968 | } | |
2969 | } | |
2970 | ||
2971 | //============================================================================== | |
2972 | //function : VZoom | |
2973 | //purpose : View zoom in / out (relative to current zoom) | |
2974 | //============================================================================== | |
2975 | ||
2976 | static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
2977 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2978 | if ( V3dView.IsNull() ) { | |
2979 | return 1; | |
2980 | } | |
2981 | ||
2982 | if ( argc == 2 ) { | |
91322f44 | 2983 | Standard_Real coef = Draw::Atof(argv[1]); |
7fd59977 | 2984 | if ( coef <= 0.0 ) { |
2985 | di << argv[1] << "Invalid value" << "\n"; | |
2986 | return 1; | |
2987 | } | |
91322f44 | 2988 | V3dView->SetZoom( Draw::Atof(argv[1]) ); |
7fd59977 | 2989 | return 0; |
2990 | } else { | |
2991 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
2992 | return 1; | |
2993 | } | |
2994 | } | |
2995 | ||
2996 | //============================================================================== | |
2997 | //function : VPan | |
2998 | //purpose : View panning (in pixels) | |
2999 | //============================================================================== | |
3000 | ||
3001 | static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
3002 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3003 | if ( V3dView.IsNull() ) return 1; | |
3004 | ||
3005 | if ( argc == 3 ) { | |
91322f44 | 3006 | V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) ); |
7fd59977 | 3007 | return 0; |
3008 | } else { | |
3009 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
3010 | return 1; | |
3011 | } | |
3012 | } | |
3013 | ||
3014 | ||
3015 | //============================================================================== | |
3016 | //function : VExport | |
5cedc27f | 3017 | //purpose : Export the view to a vector graphic format (PS, EMF, PDF) |
7fd59977 | 3018 | //============================================================================== |
3019 | ||
3020 | static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3021 | { | |
3022 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
5cedc27f K |
3023 | if (V3dView.IsNull()) |
3024 | return 1; | |
7fd59977 | 3025 | |
5cedc27f K |
3026 | if (argc == 1) |
3027 | { | |
3028 | std::cout << "Usage: " << argv[0] << " Filename [Format]\n"; | |
7fd59977 | 3029 | return 1; |
3030 | } | |
3031 | ||
5cedc27f K |
3032 | Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF; |
3033 | TCollection_AsciiString aFormatStr; | |
3034 | ||
3035 | TCollection_AsciiString aFileName (argv[1]); | |
3036 | Standard_Integer aLen = aFileName.Length(); | |
3037 | ||
3038 | if (argc > 2) | |
3039 | { | |
3040 | aFormatStr = TCollection_AsciiString (argv[2]); | |
3041 | } | |
3042 | else if (aLen >= 4) | |
3043 | { | |
3044 | if (aFileName.Value (aLen - 2) == '.') | |
3045 | { | |
3046 | aFormatStr = aFileName.SubString (aLen - 1, aLen); | |
3047 | } | |
3048 | else if (aFileName.Value (aLen - 3) == '.') | |
3049 | { | |
3050 | aFormatStr = aFileName.SubString (aLen - 2, aLen); | |
3051 | } | |
3052 | else | |
3053 | { | |
3054 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
3055 | return 1; | |
3056 | } | |
3057 | } | |
3058 | else | |
3059 | { | |
3060 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
3061 | return 1; | |
3062 | } | |
3063 | ||
3064 | aFormatStr.UpperCase(); | |
3065 | if (aFormatStr == "PS") | |
3066 | anExpFormat = Graphic3d_EF_PostScript; | |
3067 | else if (aFormatStr == "EPS") | |
3068 | anExpFormat = Graphic3d_EF_EnhPostScript; | |
3069 | else if (aFormatStr == "TEX") | |
3070 | anExpFormat = Graphic3d_EF_TEX; | |
3071 | else if (aFormatStr == "PDF") | |
3072 | anExpFormat = Graphic3d_EF_PDF; | |
3073 | else if (aFormatStr == "SVG") | |
3074 | anExpFormat = Graphic3d_EF_SVG; | |
3075 | else if (aFormatStr == "PGF") | |
3076 | anExpFormat = Graphic3d_EF_PGF; | |
3077 | else if (aFormatStr == "EMF") | |
3078 | anExpFormat = Graphic3d_EF_EMF; | |
3079 | else | |
3080 | { | |
3081 | std::cout << "Invalid export format '" << aFormatStr << "'\n"; | |
3082 | return 1; | |
3083 | } | |
3084 | ||
9753e6de | 3085 | try { |
3086 | if (!V3dView->View()->Export (argv[1], anExpFormat)) | |
3087 | { | |
3088 | di << "Error: export of image to " << aFormatStr << " failed!\n"; | |
3089 | } | |
3090 | } | |
3091 | catch (Standard_Failure) | |
5cedc27f | 3092 | { |
9753e6de | 3093 | di << "Error: export of image to " << aFormatStr << " failed"; |
3094 | di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")"; | |
5cedc27f | 3095 | } |
7fd59977 | 3096 | return 0; |
3097 | } | |
3098 | ||
3099 | //============================================================================== | |
3100 | //function : VColorScale | |
3101 | //purpose : representation color scale | |
3102 | //============================================================================== | |
3103 | #include <V3d_ColorScale.hxx> | |
3104 | ||
3105 | static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) | |
3106 | { | |
3107 | if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 ) | |
3108 | { | |
3109 | di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n"; | |
3110 | return 1; | |
3111 | } | |
3112 | ||
3113 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
3114 | if(aContext.IsNull()) { | |
3115 | di << argv[0] << " ERROR : use 'vinit' command before " << "\n"; | |
3116 | return -1; | |
3117 | } | |
3118 | ||
3119 | Standard_Real minRange = 0. , maxRange = 100. ; | |
3120 | ||
3121 | Standard_Integer numIntervals = 10 ; | |
208e6839 | 3122 | Standard_Integer textHeight = 16; |
7fd59977 | 3123 | Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT; |
3124 | Standard_Real X = 0., Y = 0. ; | |
3125 | ||
3126 | if ( argc < 9 ) | |
3127 | { | |
3128 | if( argc > 3 ) | |
3129 | { | |
91322f44 | 3130 | minRange = Draw::Atof( argv[1] ); |
3131 | maxRange = Draw::Atof( argv[2] ); | |
3132 | numIntervals = Draw::Atoi( argv[3] ); | |
7fd59977 | 3133 | } |
3134 | if ( argc > 4 ) | |
91322f44 | 3135 | textHeight = Draw::Atoi( argv[4] ); |
7fd59977 | 3136 | if ( argc > 5 ) |
91322f44 | 3137 | position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] ); |
7fd59977 | 3138 | if ( argc > 7 ) |
3139 | { | |
91322f44 | 3140 | X = Draw::Atof( argv[6] ); |
3141 | Y = Draw::Atof( argv[7] ); | |
7fd59977 | 3142 | } |
3143 | } | |
3144 | Handle(V3d_View) curView = ViewerTest::CurrentView( ); | |
3145 | if ( curView.IsNull( ) ) | |
3146 | return 1; | |
3147 | Handle(Aspect_ColorScale) aCSV = curView->ColorScale( ); | |
3148 | Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) ); | |
3149 | if( ! aCS.IsNull( ) ) | |
3150 | { | |
3151 | aCS->SetPosition( X , Y ); | |
3152 | aCS->SetHeight( 0.95) ; | |
3153 | aCS->SetTextHeight( textHeight ); | |
3154 | aCS->SetRange( minRange , maxRange ); | |
3155 | aCS->SetNumberOfIntervals( numIntervals ); | |
3156 | aCS->SetLabelPosition( position ); | |
3157 | if( !curView->ColorScaleIsDisplayed() ) | |
3158 | curView->ColorScaleDisplay( ); | |
3159 | } | |
3160 | return 0; | |
3161 | } | |
3162 | ||
3163 | //============================================================================== | |
3164 | //function : VGraduatedTrihedron | |
3165 | //purpose : Displays a graduated trihedron | |
3166 | //============================================================================== | |
13a22457 S |
3167 | |
3168 | static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg) | |
3169 | { | |
3170 | const char *str = arg; | |
3171 | while (*str) | |
3172 | { | |
3173 | unsigned short c1 = *str++; | |
3174 | unsigned short c2 = *str++; | |
3175 | if (!c1 || !c2) break; | |
3176 | name += (Standard_ExtCharacter)((c1 << 8) | c2); | |
3177 | } | |
3178 | } | |
3179 | ||
7fd59977 | 3180 | static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
3181 | { | |
13a22457 S |
3182 | // Check arguments |
3183 | if (argc != 2 && argc < 5) | |
3184 | { | |
3185 | di<<"Error: "<<argv[0]<<" - invalid number of arguments\n"; | |
3186 | di<<"Usage: type help "<<argv[0]<<"\n"; | |
3187 | return 1; //TCL_ERROR | |
3188 | } | |
7fd59977 | 3189 | |
13a22457 S |
3190 | Handle(V3d_View) aV3dView = ViewerTest::CurrentView(); |
3191 | ||
3192 | // Create 3D view if it doesn't exist | |
3193 | if ( aV3dView.IsNull() ) | |
7fd59977 | 3194 | { |
4fe56619 | 3195 | ViewerTest::ViewerInit(); |
13a22457 S |
3196 | aV3dView = ViewerTest::CurrentView(); |
3197 | if( aV3dView.IsNull() ) | |
3198 | { | |
3199 | di << "Error: Cannot create a 3D view\n"; | |
3200 | return 1; //TCL_ERROR | |
3201 | } | |
7fd59977 | 3202 | } |
3203 | ||
13a22457 | 3204 | // Erase (==0) or display (!=0) |
91322f44 | 3205 | const int display = Draw::Atoi(argv[1]); |
7fd59977 | 3206 | |
13a22457 | 3207 | if (display) |
7fd59977 | 3208 | { |
13a22457 S |
3209 | // Text font |
3210 | TCollection_AsciiString font; | |
3211 | if (argc < 6) | |
3212 | font.AssignCat("Courier"); | |
3213 | else | |
3214 | font.AssignCat(argv[5]); | |
3215 | ||
3216 | // Text is multibyte | |
91322f44 | 3217 | const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0); |
13a22457 S |
3218 | |
3219 | // Set axis names | |
3220 | TCollection_ExtendedString xname, yname, zname; | |
3221 | if (argc >= 5) | |
3222 | { | |
3223 | if (isMultibyte) | |
7fd59977 | 3224 | { |
13a22457 S |
3225 | AddMultibyteString(xname, argv[2]); |
3226 | AddMultibyteString(yname, argv[3]); | |
3227 | AddMultibyteString(zname, argv[4]); | |
7fd59977 | 3228 | } |
13a22457 S |
3229 | else |
3230 | { | |
3231 | xname += argv[2]; | |
3232 | yname += argv[3]; | |
3233 | zname += argv[4]; | |
3234 | } | |
3235 | } | |
3236 | else | |
3237 | { | |
3238 | xname += "X (mm)"; | |
3239 | yname += "Y (mm)"; | |
3240 | zname += "Z (mm)"; | |
3241 | } | |
7fd59977 | 3242 | |
13a22457 S |
3243 | aV3dView->GraduatedTrihedronDisplay(xname, yname, zname, |
3244 | Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/, | |
3245 | Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/, | |
3246 | Standard_True/*drawgrid*/, | |
3247 | Standard_True/*drawaxes*/, | |
3248 | 5/*nbx*/, 5/*nby*/, 5/*nbz*/, | |
3249 | 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/, | |
3250 | 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/, | |
3251 | Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/, | |
3252 | 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/, | |
3253 | Quantity_NOC_WHITE/*gridcolor*/, | |
3254 | Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/, | |
3255 | Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font); | |
3256 | } | |
7fd59977 | 3257 | else |
13a22457 | 3258 | aV3dView->GraduatedTrihedronErase(); |
7fd59977 | 3259 | |
3260 | ViewerTest::GetAISContext()->UpdateCurrentViewer(); | |
13a22457 S |
3261 | aV3dView->Redraw(); |
3262 | ||
7fd59977 | 3263 | return 0; |
3264 | } | |
3265 | ||
7edf74fd A |
3266 | //============================================================================== |
3267 | //function : VPrintView | |
3268 | //purpose : Test printing algorithm, print the view to image file with given | |
3269 | // width and height. Printing implemented only for WNT. | |
3270 | //============================================================================== | |
4fe56619 | 3271 | static int VPrintView (Draw_Interpretor& di, Standard_Integer argc, |
7edf74fd A |
3272 | const char** argv) |
3273 | { | |
3274 | #ifndef WNT | |
3275 | di << "Printing implemented only for wnt!\n"; | |
b5ac8292 | 3276 | return 0; |
7edf74fd A |
3277 | #else |
3278 | ||
3279 | Handle(AIS_InteractiveContext) aContextAIS = NULL; | |
3280 | Handle(V3d_View) aView = NULL; | |
3281 | aContextAIS = ViewerTest::GetAISContext(); | |
3282 | if (!aContextAIS.IsNull()) | |
3283 | { | |
3284 | const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer(); | |
3285 | Vwr->InitActiveViews(); | |
3286 | if(Vwr->MoreActiveViews()) | |
3287 | aView = Vwr->ActiveView(); | |
3288 | } | |
3289 | ||
3290 | // check for errors | |
3291 | if (aView.IsNull()) | |
3292 | { | |
3293 | di << "Call vinit before!\n"; | |
3294 | return 1; | |
3295 | } | |
3296 | else if (argc < 4) | |
3297 | { | |
3298 | di << "Use: " << argv[0]; | |
b5ac8292 | 3299 | di << " width height filename [print algo=0] [tile_width tile_height]\n"; |
7edf74fd A |
3300 | di << "width, height of the intermediate buffer for operation\n"; |
3301 | di << "algo : {0|1}\n"; | |
3302 | di << " 0 - stretch algorithm\n"; | |
3303 | di << " 1 - tile algorithm\n"; | |
3304 | di << "test printing algorithms into an intermediate buffer\n"; | |
b5ac8292 | 3305 | di << "using specific tile size if provided\n"; |
7edf74fd A |
3306 | di << "with saving output to an image file\n"; |
3307 | return 1; | |
3308 | } | |
3309 | ||
3310 | // get the input params | |
91322f44 | 3311 | Standard_Integer aWidth = Draw::Atoi (argv[1]); |
3312 | Standard_Integer aHeight = Draw::Atoi (argv[2]); | |
7edf74fd A |
3313 | Standard_Integer aMode = 0; |
3314 | TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]); | |
b5ac8292 | 3315 | if (argc >= 5) |
91322f44 | 3316 | aMode = Draw::Atoi (argv[4]); |
7edf74fd | 3317 | |
b5ac8292 | 3318 | Standard_Integer aTileWidth = 0; |
3319 | Standard_Integer aTileHeight = 0; | |
3320 | Standard_Boolean isTileSizeProvided = Standard_False; | |
3321 | if (argc == 7) | |
3322 | { | |
3323 | isTileSizeProvided = Standard_True; | |
3324 | aTileWidth = Draw::Atoi (argv[5]); | |
3325 | aTileHeight = Draw::Atoi (argv[6]); | |
3326 | } | |
3327 | ||
7edf74fd A |
3328 | // check the input parameters |
3329 | if (aWidth <= 0 || aHeight <= 0) | |
3330 | { | |
3331 | di << "Width and height must be positive values!\n"; | |
3332 | return 1; | |
3333 | } | |
3334 | if (aMode != 0 && aMode != 1) | |
3335 | aMode = 0; | |
3336 | ||
7edf74fd | 3337 | // define compatible bitmap |
692613e5 | 3338 | HDC anDC = CreateCompatibleDC(0); |
7edf74fd A |
3339 | BITMAPINFO aBitmapData; |
3340 | memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER)); | |
3341 | aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); | |
3342 | aBitmapData.bmiHeader.biWidth = aWidth ; | |
3343 | aBitmapData.bmiHeader.biHeight = aHeight; | |
3344 | aBitmapData.bmiHeader.biPlanes = 1; | |
3345 | aBitmapData.bmiHeader.biBitCount = 24; | |
3346 | aBitmapData.bmiHeader.biXPelsPerMeter = 0; | |
3347 | aBitmapData.bmiHeader.biYPelsPerMeter = 0; | |
3348 | aBitmapData.bmiHeader.biClrUsed = 0; | |
3349 | aBitmapData.bmiHeader.biClrImportant = 0; | |
3350 | aBitmapData.bmiHeader.biCompression = BI_RGB; | |
3351 | aBitmapData.bmiHeader.biSizeImage = 0; | |
3352 | ||
3353 | // Create Device Independent Bitmap | |
692613e5 | 3354 | void* aBitsOut = NULL; |
7edf74fd | 3355 | HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS, |
692613e5 | 3356 | &aBitsOut, NULL, 0); |
7edf74fd A |
3357 | HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap); |
3358 | ||
3359 | Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False; | |
692613e5 | 3360 | if (aBitsOut != NULL) |
4fe56619 | 3361 | { |
7edf74fd A |
3362 | if (aMode == 0) |
3363 | isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH); | |
3364 | else | |
b5ac8292 | 3365 | { |
3366 | if (isTileSizeProvided) | |
3367 | { | |
3368 | Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView()); | |
3369 | Graphic3d_PtrFrameBuffer anOldBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO); | |
3370 | aCView->ptrFBO = aView->View()->FBOCreate (aTileWidth, aTileHeight); | |
3371 | ||
3372 | isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE); | |
3373 | ||
3374 | Graphic3d_PtrFrameBuffer aNewBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO); | |
3375 | aView->View()->FBORelease (aNewBuffer); | |
3376 | aCView->ptrFBO = anOldBuffer; | |
3377 | } | |
3378 | else | |
3379 | { | |
3380 | isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE); | |
3381 | } | |
3382 | } | |
7edf74fd A |
3383 | |
3384 | // succesfully printed into an intermediate buffer | |
3385 | if (isPrinted) | |
3386 | { | |
692613e5 | 3387 | Image_PixMap aWrapper; |
3388 | aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4); | |
3389 | aWrapper.SetTopDown (false); | |
3390 | ||
3391 | Image_AlienPixMap anImageBitmap; | |
3392 | anImageBitmap.InitCopy (aWrapper); | |
3393 | isSaved = anImageBitmap.Save (aFileName); | |
7edf74fd A |
3394 | } |
3395 | else | |
3396 | { | |
3397 | di << "Print operation failed due to printing errors or\n"; | |
3398 | di << "insufficient memory available\n"; | |
3399 | di << "Please, try to use smaller dimensions for this test\n"; | |
3400 | di << "command, as it allocates intermediate buffer for storing\n"; | |
3401 | di << "the result\n"; | |
3402 | } | |
3403 | } | |
3404 | else | |
3405 | { | |
3406 | di << "Can't allocate memory for intermediate buffer\n"; | |
3407 | di << "Please use smaller dimensions\n"; | |
3408 | } | |
3409 | ||
3410 | if (aMemoryBitmap) | |
3411 | { | |
3412 | SelectObject (anDC, anOldBitmap); | |
3413 | DeleteObject (aMemoryBitmap); | |
3414 | DeleteDC(anDC); | |
3415 | } | |
3416 | ||
3417 | if (!isSaved) | |
3418 | { | |
3419 | di << "Save to file operation failed. This operation may fail\n"; | |
3420 | di << "if you don't have enough available memory, then you can\n"; | |
3421 | di << "use smaller dimensions for the output file\n"; | |
3422 | return 1; | |
3423 | } | |
3424 | ||
3425 | return 0; | |
3426 | ||
3427 | #endif | |
3428 | } | |
3429 | ||
59f45b7c | 3430 | //============================================================================== |
3431 | //function : VZLayer | |
3432 | //purpose : Test z layer operations for v3d viewer | |
3433 | //============================================================================== | |
3434 | static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3435 | { | |
3436 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext (); | |
3437 | if (aContextAIS.IsNull()) | |
3438 | { | |
3439 | di << "Call vinit before!\n"; | |
3440 | return 1; | |
3441 | } | |
3442 | else if (argc < 2) | |
3443 | { | |
c5751993 | 3444 | di << "Use: vzlayer "; |
3445 | di << " add/del/get/settings/enable/disable [id]\n"; | |
59f45b7c | 3446 | di << " add - add new z layer to viewer and print its id\n"; |
3447 | di << " del - del z layer by its id\n"; | |
3448 | di << " get - print sequence of z layers in increasing order of their overlay level\n"; | |
c5751993 | 3449 | di << " settings - print status of z layer settings\n"; |
3450 | di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"; | |
3451 | di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"; | |
3452 | di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"; | |
3453 | di << "\nWhere id is the layer identificator\n"; | |
3454 | di << "\nExamples:\n"; | |
3455 | di << " vzlayer add\n"; | |
3456 | di << " vzlayer enable poffset 1\n"; | |
3457 | di << " vzlayer disable depthtest 1\n"; | |
3458 | di << " vzlayer del 1\n"; | |
59f45b7c | 3459 | return 1; |
3460 | } | |
3461 | ||
3462 | const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); | |
3463 | if (aViewer.IsNull()) | |
3464 | { | |
3465 | di << "No active viewer!\n"; | |
3466 | return 1; | |
3467 | } | |
3468 | ||
3469 | // perform operation | |
3470 | TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]); | |
3471 | if (anOp == "add") | |
3472 | { | |
3473 | Standard_Integer aNewId; | |
3474 | if (!aViewer->AddZLayer (aNewId)) | |
3475 | { | |
3476 | di << "Impossible to add new z layer!\n"; | |
3477 | return 1; | |
3478 | } | |
3479 | ||
3480 | di << "New z layer added with index: " << aNewId << "\n"; | |
3481 | } | |
3482 | else if (anOp == "del") | |
3483 | { | |
3484 | if (argc < 3) | |
3485 | { | |
3486 | di << "Please also provide as argument id of z layer to remove\n"; | |
3487 | return 1; | |
3488 | } | |
3489 | ||
91322f44 | 3490 | Standard_Integer aDelId = Draw::Atoi (argv[2]); |
59f45b7c | 3491 | if (!aViewer->RemoveZLayer (aDelId)) |
3492 | { | |
3493 | di << "Impossible to remove the z layer or invalid id!\n"; | |
3494 | return 1; | |
3495 | } | |
3496 | ||
3497 | di << "Z layer " << aDelId << " has been removed\n"; | |
3498 | } | |
3499 | else if (anOp == "get") | |
3500 | { | |
3501 | TColStd_SequenceOfInteger anIds; | |
3502 | aViewer->GetAllZLayers (anIds); | |
3503 | for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++) | |
3504 | { | |
3505 | di << anIds.Value (aSeqIdx) << " "; | |
3506 | } | |
3507 | ||
3508 | di << "\n"; | |
3509 | } | |
c5751993 | 3510 | else if (anOp == "settings") |
3511 | { | |
3512 | if (argc < 3) | |
3513 | { | |
3514 | di << "Please also provide an id\n"; | |
3515 | return 1; | |
3516 | } | |
3517 | ||
3518 | Standard_Integer anId = Draw::Atoi (argv[2]); | |
3519 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId); | |
3520 | ||
3521 | di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n"; | |
3522 | di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n"; | |
3523 | di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n"; | |
3524 | di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n"; | |
3525 | ||
3526 | } | |
3527 | else if (anOp == "enable") | |
3528 | { | |
3529 | if (argc < 3) | |
3530 | { | |
3531 | di << "Please also provide an option to enable\n"; | |
3532 | return 1; | |
3533 | } | |
3534 | ||
3535 | if (argc < 4) | |
3536 | { | |
3537 | di << "Please also provide a layer id\n"; | |
3538 | return 1; | |
3539 | } | |
3540 | ||
3541 | TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]); | |
3542 | Standard_Integer anId = Draw::Atoi (argv[3]); | |
3543 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId); | |
3544 | ||
3545 | if (aSubOp == "depthtest" || aSubOp == "test") | |
3546 | { | |
3547 | aSettings.EnableSetting (Graphic3d_ZLayerDepthTest); | |
3548 | } | |
3549 | else if (aSubOp == "depthwrite" || aSubOp == "write") | |
3550 | { | |
3551 | aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite); | |
3552 | } | |
3553 | else if (aSubOp == "depthclear" || aSubOp == "clear") | |
3554 | { | |
3555 | aSettings.EnableSetting (Graphic3d_ZLayerDepthClear); | |
3556 | } | |
3557 | else if (aSubOp == "depthoffset" || aSubOp == "offset") | |
3558 | { | |
3559 | if (argc < 6) | |
3560 | { | |
3561 | di << "Please also provide a factor and units values for depth offset\n"; | |
3562 | di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n"; | |
3563 | return 1; | |
3564 | } | |
3565 | ||
3566 | Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3])); | |
3567 | Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4])); | |
3568 | anId = Draw::Atoi (argv[5]); | |
3569 | aSettings = aViewer->ZLayerSettings (anId); | |
3570 | ||
3571 | aSettings.DepthOffsetFactor = aFactor; | |
3572 | aSettings.DepthOffsetUnits = aUnits; | |
3573 | ||
3574 | aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset); | |
3575 | } | |
3576 | else if (aSubOp == "positiveoffset" || aSubOp == "poffset") | |
3577 | { | |
3578 | aSettings.SetDepthOffsetPositive(); | |
3579 | } | |
3580 | else if (aSubOp == "negativeoffset" || aSubOp == "noffset") | |
3581 | { | |
3582 | aSettings.SetDepthOffsetNegative(); | |
3583 | } | |
3584 | ||
3585 | aViewer->SetZLayerSettings (anId, aSettings); | |
3586 | } | |
3587 | else if (anOp == "disable") | |
3588 | { | |
3589 | if (argc < 3) | |
3590 | { | |
3591 | di << "Please also provide an option to disable\n"; | |
3592 | return 1; | |
3593 | } | |
3594 | ||
3595 | if (argc < 4) | |
3596 | { | |
3597 | di << "Please also provide a layer id\n"; | |
3598 | return 1; | |
3599 | } | |
3600 | ||
3601 | TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]); | |
3602 | Standard_Integer anId = Draw::Atoi (argv[3]); | |
3603 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId); | |
3604 | ||
3605 | if (aSubOp == "depthtest" || aSubOp == "test") | |
3606 | { | |
3607 | aSettings.DisableSetting (Graphic3d_ZLayerDepthTest); | |
3608 | } | |
3609 | else if (aSubOp == "depthwrite" || aSubOp == "write") | |
3610 | { | |
3611 | aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite); | |
3612 | } | |
3613 | else if (aSubOp == "depthclear" || aSubOp == "clear") | |
3614 | { | |
3615 | aSettings.DisableSetting (Graphic3d_ZLayerDepthClear); | |
3616 | } | |
3617 | else if (aSubOp == "depthoffset" || aSubOp == "offset") | |
3618 | { | |
3619 | aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset); | |
3620 | } | |
3621 | ||
3622 | aViewer->SetZLayerSettings (anId, aSettings); | |
3623 | } | |
59f45b7c | 3624 | else |
3625 | { | |
c5751993 | 3626 | di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n"; |
59f45b7c | 3627 | return 1; |
3628 | } | |
3629 | ||
3630 | return 0; | |
3631 | } | |
3632 | ||
25289ec1 | 3633 | DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem) |
3634 | ||
3635 | // this class provides a presentation of text item in v3d view under-/overlayer | |
3636 | class V3d_TextItem : public Visual3d_LayerItem | |
3637 | { | |
3638 | public: | |
3639 | ||
3640 | // CASCADE RTTI | |
3641 | DEFINE_STANDARD_RTTI(V3d_TextItem) | |
3642 | ||
3643 | // constructor | |
3644 | Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText, | |
3645 | const Standard_Real theX1, | |
3646 | const Standard_Real theY1, | |
3647 | const Standard_Real theHeight, | |
3648 | const TCollection_AsciiString& theFontName, | |
3649 | const Quantity_Color& theColor, | |
3650 | const Quantity_Color& theSubtitleColor, | |
3651 | const Aspect_TypeOfDisplayText& theTypeOfDisplay, | |
3652 | const Handle(Visual3d_Layer)& theLayer); | |
3653 | ||
3654 | // redraw method | |
3655 | Standard_EXPORT void RedrawLayerPrs(); | |
3656 | ||
3657 | private: | |
3658 | ||
3659 | Standard_Real myX1; | |
3660 | Standard_Real myY1; | |
25289ec1 | 3661 | TCollection_AsciiString myText; |
eafb234b | 3662 | Standard_Real myHeight; |
3663 | Handle(Visual3d_Layer) myLayer; | |
25289ec1 | 3664 | Quantity_Color myColor; |
3665 | Quantity_Color mySubtitleColor; | |
3666 | Aspect_TypeOfDisplayText myType; | |
eafb234b | 3667 | TCollection_AsciiString myFontName; |
25289ec1 | 3668 | }; |
3669 | ||
3670 | IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem) | |
3671 | IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem) | |
3672 | ||
3673 | // create and add to display the text item | |
3674 | V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText, | |
3675 | const Standard_Real theX1, | |
3676 | const Standard_Real theY1, | |
3677 | const Standard_Real theHeight, | |
3678 | const TCollection_AsciiString& theFontName, | |
3679 | const Quantity_Color& theColor, | |
3680 | const Quantity_Color& theSubtitleColor, | |
3681 | const Aspect_TypeOfDisplayText& theTypeOfDisplay, | |
3682 | const Handle(Visual3d_Layer)& theLayer) | |
3683 | : myX1 (theX1), myY1 (theY1), | |
3684 | myText (theText), | |
3685 | myHeight (theHeight), | |
3686 | myLayer (theLayer), | |
3687 | myColor (theColor), | |
3688 | mySubtitleColor (theSubtitleColor), | |
3689 | myType (theTypeOfDisplay), | |
3690 | myFontName (theFontName) | |
3691 | { | |
3692 | if (!myLayer.IsNull ()) | |
3693 | myLayer->AddLayerItem (this); | |
3694 | } | |
3695 | ||
3696 | // render item | |
3697 | void V3d_TextItem::RedrawLayerPrs () | |
4fe56619 | 3698 | { |
25289ec1 | 3699 | if (myLayer.IsNull ()) |
3700 | return; | |
3701 | ||
3702 | myLayer->SetColor (myColor); | |
3703 | myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor); | |
3704 | myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight); | |
3705 | } | |
3706 | ||
20637bd2 | 3707 | DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem) |
3708 | ||
3709 | // The Visual3d_LayerItem line item for "vlayerline" command | |
4fe56619 | 3710 | // it provides a presentation of line with user-defined |
20637bd2 | 3711 | // linewidth, linetype and transparency. |
4fe56619 | 3712 | class V3d_LineItem : public Visual3d_LayerItem |
20637bd2 | 3713 | { |
3714 | public: | |
3715 | // CASCADE RTTI | |
4fe56619 | 3716 | DEFINE_STANDARD_RTTI(V3d_LineItem) |
3717 | ||
20637bd2 | 3718 | // constructor |
3719 | Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1, | |
3720 | Standard_Real X2, Standard_Real Y2, | |
3721 | V3d_LayerMgrPointer theLayerMgr, | |
3722 | Aspect_TypeOfLine theType = Aspect_TOL_SOLID, | |
3723 | Standard_Real theWidth = 0.5, | |
3724 | Standard_Real theTransp = 1.0); | |
3725 | ||
3726 | // redraw method | |
3727 | Standard_EXPORT void RedrawLayerPrs(); | |
3728 | ||
3729 | private: | |
3730 | ||
3731 | Standard_Real myX1, myY1, myX2, myY2; | |
eafb234b | 3732 | V3d_LayerMgrPointer myLayerMgr; |
3733 | Aspect_TypeOfLine myType; | |
20637bd2 | 3734 | Standard_Real myWidth; |
3735 | Standard_Real myTransparency; | |
20637bd2 | 3736 | }; |
3737 | ||
3738 | IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem) | |
3739 | IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem) | |
3740 | ||
3741 | // default constructor for line item | |
4fe56619 | 3742 | V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1, |
20637bd2 | 3743 | Standard_Real X2, Standard_Real Y2, |
3744 | V3d_LayerMgrPointer theLayerMgr, | |
3745 | Aspect_TypeOfLine theType, | |
3746 | Standard_Real theWidth, | |
3747 | Standard_Real theTransp) : | |
3748 | myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr), | |
3749 | myType(theType), myWidth(theWidth), myTransparency(theTransp) | |
3750 | { | |
9e4c2fbb | 3751 | if (myLayerMgr && !myLayerMgr->Overlay().IsNull()) |
20637bd2 | 3752 | myLayerMgr->Overlay()->AddLayerItem (this); |
3753 | } | |
3754 | ||
3755 | // render line | |
3756 | void V3d_LineItem::RedrawLayerPrs () | |
3757 | { | |
3758 | Handle (Visual3d_Layer) aOverlay; | |
4fe56619 | 3759 | |
20637bd2 | 3760 | if (myLayerMgr) |
3761 | aOverlay = myLayerMgr->Overlay(); | |
3762 | ||
3763 | if (!aOverlay.IsNull()) | |
3764 | { | |
3765 | Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB); | |
3766 | aOverlay->SetColor(aColor); | |
3767 | aOverlay->SetTransparency((Standard_ShortReal)myTransparency); | |
3768 | aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth); | |
3769 | aOverlay->BeginPolyline(); | |
3770 | aOverlay->AddVertex(myX1, myY1); | |
3771 | aOverlay->AddVertex(myX2, myY2); | |
3772 | aOverlay->ClosePrimitive(); | |
3773 | } | |
3774 | } | |
3775 | ||
3776 | //============================================================================= | |
3777 | //function : VLayerLine | |
3778 | //purpose : Draws line in the v3d view layer with given attributes: linetype, | |
3779 | // : linewidth, transparency coefficient | |
3780 | //============================================================================ | |
3781 | static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3782 | { | |
3783 | // get the active view | |
3784 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3785 | if (aView.IsNull()) | |
3786 | { | |
3787 | di << "Call vinit before!\n"; | |
3788 | return 1; | |
3789 | } | |
3790 | else if (argc < 5) | |
3791 | { | |
3792 | di << "Use: " << argv[0]; | |
3793 | di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n"; | |
3794 | di << " linetype : { 0 | 1 | 2 | 3 } \n"; | |
3795 | di << " 0 - solid \n"; | |
3796 | di << " 1 - dashed \n"; | |
3797 | di << " 2 - dot \n"; | |
3798 | di << " 3 - dashdot\n"; | |
3799 | di << " transparency : { 0.0 - 1.0 } \n"; | |
3800 | di << " 0.0 - transparent\n"; | |
3801 | di << " 1.0 - visible \n"; | |
3802 | return 1; | |
3803 | } | |
3804 | ||
3805 | // get the input params | |
91322f44 | 3806 | Standard_Real X1 = Draw::Atof(argv[1]); |
3807 | Standard_Real Y1 = Draw::Atof(argv[2]); | |
3808 | Standard_Real X2 = Draw::Atof(argv[3]); | |
3809 | Standard_Real Y2 = Draw::Atof(argv[4]); | |
20637bd2 | 3810 | |
3811 | Standard_Real aWidth = 0.5; | |
3812 | Standard_Integer aType = 0; | |
3813 | Standard_Real aTransparency = 1.0; | |
3814 | ||
3815 | // has width | |
3816 | if (argc > 5) | |
91322f44 | 3817 | aWidth = Draw::Atof(argv[5]); |
20637bd2 | 3818 | |
3819 | // has type | |
3820 | if (argc > 6) | |
91322f44 | 3821 | aType = (Standard_Integer) Draw::Atoi(argv[6]); |
20637bd2 | 3822 | |
3823 | // has transparency | |
3824 | if (argc > 7) | |
3825 | { | |
91322f44 | 3826 | aTransparency = Draw::Atof(argv[7]); |
4fe56619 | 3827 | if (aTransparency < 0 || aTransparency > 1.0) |
20637bd2 | 3828 | aTransparency = 1.0; |
3829 | } | |
3830 | ||
3831 | // select appropriate line type | |
3832 | Aspect_TypeOfLine aLineType; | |
3833 | switch (aType) | |
3834 | { | |
3835 | case 1: | |
3836 | aLineType = Aspect_TOL_DASH; | |
3837 | break; | |
3838 | ||
3839 | case 2: | |
3840 | aLineType = Aspect_TOL_DOT; | |
3841 | break; | |
3842 | ||
3843 | case 3: | |
3844 | aLineType = Aspect_TOL_DOTDASH; | |
3845 | break; | |
3846 | ||
3847 | default: | |
3848 | aLineType = Aspect_TOL_SOLID; | |
3849 | } | |
3850 | ||
3851 | // replace layer manager | |
3852 | Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView); | |
3853 | aView->SetLayerMgr(aMgr); | |
3854 | ||
3855 | // add line item | |
4fe56619 | 3856 | Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2, |
20637bd2 | 3857 | aMgr.operator->(), |
4fe56619 | 3858 | aLineType, aWidth, |
20637bd2 | 3859 | aTransparency); |
3860 | ||
3861 | // update view | |
3862 | aView->MustBeResized(); | |
3863 | aView->Redraw(); | |
3864 | ||
3865 | return 0; | |
3866 | } | |
3867 | ||
25289ec1 | 3868 | //======================================================================= |
3869 | //function : VOverlayText | |
3870 | //purpose : Test text displaying in view overlay | |
3871 | //======================================================================= | |
3872 | static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv) | |
3873 | { | |
3874 | // get the active view | |
3875 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3876 | if (aView.IsNull()) | |
3877 | { | |
3878 | di << "No active view. Please call vinit.\n"; | |
3879 | return 1; | |
3880 | } | |
3881 | else if (argc < 4 || argc > 13) | |
3882 | { | |
3883 | di << "Use: " << argv[0]; | |
3884 | di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n"; | |
3885 | di << "[background_color: R G B]\n"; | |
3886 | di << " height - pixel height of the text (default=10.0)\n"; | |
3887 | di << " font_name - name of font (default=courier)\n"; | |
3888 | di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n"; | |
a6eb515f | 3889 | di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n"; |
25289ec1 | 3890 | di << " background_color- R G B values used for subtitle and decal text\n"; |
3891 | di << "(default=255.0 255.0 255.0)\n"; | |
3892 | return 1; | |
3893 | } | |
4fe56619 | 3894 | |
25289ec1 | 3895 | TCollection_AsciiString aText (argv[1]); |
91322f44 | 3896 | Standard_Real aPosX = Draw::Atof(argv[2]); |
3897 | Standard_Real aPosY = Draw::Atof(argv[3]); | |
3898 | Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0; | |
25289ec1 | 3899 | |
3900 | // font name | |
3901 | TCollection_AsciiString aFontName = "Courier"; | |
3902 | if (argc >= 6) | |
3903 | aFontName = TCollection_AsciiString (argv[5]); | |
3904 | ||
3905 | // text colors | |
3906 | Quantity_Parameter aColorRed = 1.0; | |
3907 | Quantity_Parameter aColorGreen = 1.0; | |
3908 | Quantity_Parameter aColorBlue = 1.0; | |
3909 | if (argc >= 9) | |
3910 | { | |
91322f44 | 3911 | aColorRed = Draw::Atof (argv[6])/255.; |
3912 | aColorGreen = Draw::Atof (argv[7])/255.; | |
3913 | aColorBlue = Draw::Atof (argv[8])/255.; | |
25289ec1 | 3914 | } |
3915 | ||
3916 | // display type | |
3917 | TCollection_AsciiString aDispStr; | |
3918 | if (argc >= 10) | |
3919 | aDispStr = TCollection_AsciiString (argv[9]); | |
3920 | ||
3921 | Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL; | |
3922 | if (aDispStr.IsEqual ("subtitle")) | |
3923 | aTextType = Aspect_TODT_SUBTITLE; | |
3924 | else if (aDispStr.IsEqual ("decal")) | |
3925 | aTextType = Aspect_TODT_DEKALE; | |
3926 | else if (aDispStr.IsEqual ("blend")) | |
3927 | aTextType = Aspect_TODT_BLEND; | |
a6eb515f | 3928 | else if (aDispStr.IsEqual ("dimension")) |
3929 | aTextType = Aspect_TODT_DIMENSION; | |
25289ec1 | 3930 | |
3931 | // subtitle color | |
3932 | Quantity_Parameter aSubRed = 1.0; | |
3933 | Quantity_Parameter aSubGreen = 1.0; | |
3934 | Quantity_Parameter aSubBlue = 1.0; | |
3935 | if (argc == 13) | |
3936 | { | |
91322f44 | 3937 | aSubRed = Draw::Atof (argv[10])/255.; |
3938 | aSubGreen = Draw::Atof (argv[11])/255.; | |
3939 | aSubBlue = Draw::Atof (argv[12])/255.; | |
25289ec1 | 3940 | } |
3941 | ||
3942 | // check fo current overlay | |
3943 | Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer (); | |
3944 | if (anOverlay.IsNull ()) | |
3945 | { | |
3946 | Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView); | |
3947 | anOverlay = aMgr->Overlay (); | |
3948 | aView->SetLayerMgr (aMgr); | |
3949 | } | |
3950 | ||
4fe56619 | 3951 | Quantity_Color aTextColor (aColorRed, aColorGreen, |
25289ec1 | 3952 | aColorBlue, Quantity_TOC_RGB); |
4fe56619 | 3953 | Quantity_Color aSubtColor (aSubRed, aSubGreen, |
25289ec1 | 3954 | aSubBlue, Quantity_TOC_RGB); |
3955 | ||
3956 | // add text item | |
3957 | Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY, | |
3958 | aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay); | |
3959 | ||
3960 | // update view | |
3961 | aView->MustBeResized(); | |
3962 | aView->Redraw(); | |
3963 | ||
3964 | return 0; | |
3965 | } | |
3966 | ||
2bd4c032 | 3967 | //============================================================================== |
3968 | //function : VGrid | |
3969 | //purpose : | |
3970 | //============================================================================== | |
3971 | ||
35e08fe8 | 3972 | static int VGrid (Draw_Interpretor& /*theDI*/, |
2bd4c032 | 3973 | Standard_Integer theArgNb, |
3974 | const char** theArgVec) | |
3975 | { | |
3976 | // get the active view | |
3977 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3978 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
3979 | if (aView.IsNull() || aViewer.IsNull()) | |
3980 | { | |
3981 | std::cerr << "No active view. Please call vinit.\n"; | |
3982 | return 1; | |
3983 | } | |
3984 | ||
3985 | Aspect_GridType aType = aViewer->GridType(); | |
3986 | Aspect_GridDrawMode aMode = aViewer->GridDrawMode(); | |
3987 | ||
3988 | Standard_Integer anIter = 1; | |
3989 | for (; anIter < theArgNb; ++anIter) | |
3990 | { | |
3991 | const char* aValue = theArgVec[anIter]; | |
3992 | if (*aValue == 'r') | |
3993 | { | |
3994 | aType = Aspect_GT_Rectangular; | |
3995 | } | |
3996 | else if (*aValue == 'c') | |
3997 | { | |
3998 | aType = Aspect_GT_Circular; | |
3999 | } | |
4000 | else if (*aValue == 'l') | |
4001 | { | |
4002 | aMode = Aspect_GDM_Lines; | |
4003 | } | |
4004 | else if (*aValue == 'p') | |
4005 | { | |
4006 | aMode = Aspect_GDM_Points; | |
4007 | } | |
4008 | else if (strcmp (aValue, "off" ) == 0) | |
4009 | { | |
4010 | aViewer->DeactivateGrid(); | |
4011 | return 0; | |
4012 | } | |
4013 | else | |
4014 | { | |
4015 | break; | |
4016 | } | |
4017 | } | |
4018 | ||
4019 | Standard_Integer aTail = (theArgNb - anIter); | |
4020 | if (aTail == 0) | |
4021 | { | |
4022 | aViewer->ActivateGrid (aType, aMode); | |
4023 | return 0; | |
4024 | } | |
4025 | else if (aTail != 2 && aTail != 5) | |
4026 | { | |
4027 | std::cerr << "Incorrect arguments number! Usage:\n" | |
4028 | << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n"; | |
4029 | return 1; | |
4030 | } | |
4031 | ||
4032 | Quantity_Length anOriginX, anOriginY; | |
4033 | Quantity_PlaneAngle aRotAngle; | |
4034 | if (aType == Aspect_GT_Rectangular) | |
4035 | { | |
4036 | Quantity_Length aRStepX, aRStepY; | |
4037 | aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); | |
4038 | ||
91322f44 | 4039 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
4040 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 4041 | if (aTail == 5) |
4042 | { | |
91322f44 | 4043 | aRStepX = Draw::Atof (theArgVec[anIter++]); |
4044 | aRStepY = Draw::Atof (theArgVec[anIter++]); | |
4045 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 4046 | } |
4047 | aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); | |
4048 | aViewer->ActivateGrid (aType, aMode); | |
4049 | } | |
4050 | else if (aType == Aspect_GT_Circular) | |
4051 | { | |
4052 | Quantity_Length aRadiusStep; | |
4053 | Standard_Integer aDivisionNumber; | |
4054 | aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
4055 | ||
91322f44 | 4056 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
4057 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 4058 | if (aTail == 5) |
4059 | { | |
91322f44 | 4060 | aRadiusStep = Draw::Atof (theArgVec[anIter++]); |
4061 | aDivisionNumber = Draw::Atoi (theArgVec[anIter++]); | |
4062 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 4063 | } |
4064 | ||
4065 | aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
4066 | aViewer->ActivateGrid (aType, aMode); | |
4067 | } | |
4068 | ||
4069 | return 0; | |
4070 | } | |
4071 | ||
208e6839 | 4072 | //============================================================================== |
4073 | //function : VFps | |
4074 | //purpose : | |
4075 | //============================================================================== | |
4076 | ||
4077 | static int VFps (Draw_Interpretor& theDI, | |
4078 | Standard_Integer theArgNb, | |
4079 | const char** theArgVec) | |
4080 | { | |
4081 | // get the active view | |
4082 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4083 | if (aView.IsNull()) | |
4084 | { | |
4085 | std::cerr << "No active view. Please call vinit.\n"; | |
4086 | return 1; | |
4087 | } | |
4088 | ||
91322f44 | 4089 | Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100; |
208e6839 | 4090 | if (aFramesNb <= 0) |
4091 | { | |
4092 | std::cerr << "Incorrect arguments!\n"; | |
4093 | return 1; | |
4094 | } | |
4095 | ||
4096 | // the time is meaningless for first call | |
4097 | // due to async OpenGl rendering | |
4098 | aView->Redraw(); | |
4099 | ||
4100 | // redraw view in loop to estimate average values | |
4101 | OSD_Timer aTimer; | |
4102 | aTimer.Start(); | |
4103 | for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter) | |
4104 | { | |
4105 | aView->Redraw(); | |
4106 | } | |
4107 | aTimer.Stop(); | |
4108 | Standard_Real aCpu; | |
4109 | const Standard_Real aTime = aTimer.ElapsedTime(); | |
4110 | aTimer.OSD_Chronometer::Show (aCpu); | |
4111 | ||
4112 | const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime; | |
4113 | const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb); | |
4114 | ||
4115 | // return statistics | |
4116 | theDI << "FPS: " << aFpsAver << "\n" | |
4117 | << "CPU: " << (1000.0 * aCpuAver) << " msec\n"; | |
4118 | ||
4119 | return 0; | |
4120 | } | |
4121 | ||
58655684 | 4122 | //============================================================================== |
4123 | //function : VGlDebug | |
4124 | //purpose : | |
4125 | //============================================================================== | |
4126 | ||
4127 | static int VGlDebug (Draw_Interpretor& theDI, | |
4128 | Standard_Integer theArgNb, | |
4129 | const char** theArgVec) | |
4130 | { | |
aaf512f1 | 4131 | Handle(OpenGl_GraphicDriver) aDriver; |
4132 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4133 | if (!aView.IsNull()) | |
4134 | { | |
4135 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver()); | |
4136 | } | |
58655684 | 4137 | if (theArgNb < 2) |
4138 | { | |
aaf512f1 | 4139 | if (aDriver.IsNull()) |
58655684 | 4140 | { |
4141 | std::cerr << "No active view. Please call vinit.\n"; | |
4142 | return 0; | |
4143 | } | |
4144 | ||
4145 | Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS), | |
4146 | "GL_ARB_debug_output"); | |
4147 | std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n"; | |
4148 | theDI << (isActive ? "1" : "0"); | |
4149 | return 0; | |
4150 | } | |
4151 | ||
aaf512f1 | 4152 | const Standard_Boolean toEnableDebug = Draw::Atoi (theArgVec[1]) != 0; |
4153 | ViewerTest_myDefaultCaps.contextDebug = toEnableDebug; | |
4154 | ViewerTest_myDefaultCaps.glslWarnings = toEnableDebug; | |
4155 | if (aDriver.IsNull()) | |
4156 | { | |
4157 | return 0; | |
4158 | } | |
4159 | ||
4160 | aDriver->ChangeOptions().glslWarnings = toEnableDebug; | |
58655684 | 4161 | return 0; |
4162 | } | |
208e6839 | 4163 | |
4164 | //============================================================================== | |
4165 | //function : VVbo | |
4166 | //purpose : | |
4167 | //============================================================================== | |
4168 | ||
58655684 | 4169 | static int VVbo (Draw_Interpretor& theDI, |
208e6839 | 4170 | Standard_Integer theArgNb, |
4171 | const char** theArgVec) | |
4172 | { | |
58655684 | 4173 | const Standard_Boolean toSet = (theArgNb > 1); |
4174 | const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1; | |
4175 | if (toSet) | |
208e6839 | 4176 | { |
58655684 | 4177 | ViewerTest_myDefaultCaps.vboDisable = toUseVbo; |
208e6839 | 4178 | } |
4179 | ||
58655684 | 4180 | // get the context |
4181 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
4182 | if (aContextAIS.IsNull()) | |
208e6839 | 4183 | { |
58655684 | 4184 | if (!toSet) |
4185 | { | |
4186 | std::cerr << "No active view!\n"; | |
4187 | } | |
208e6839 | 4188 | return 1; |
4189 | } | |
58655684 | 4190 | Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver()); |
4191 | if (!aDriver.IsNull()) | |
208e6839 | 4192 | { |
58655684 | 4193 | if (!toSet) |
4194 | { | |
4195 | theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n"; | |
4196 | } | |
4197 | else | |
4198 | { | |
4199 | aDriver->ChangeOptions().vboDisable = toUseVbo; | |
4200 | } | |
208e6839 | 4201 | } |
4202 | ||
208e6839 | 4203 | return 0; |
4204 | } | |
4205 | ||
a577aaab | 4206 | //============================================================================== |
4207 | //function : VCaps | |
4208 | //purpose : | |
4209 | //============================================================================== | |
4210 | ||
4211 | static int VCaps (Draw_Interpretor& theDI, | |
4212 | Standard_Integer theArgNb, | |
4213 | const char** theArgVec) | |
4214 | { | |
4215 | OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps; | |
4216 | Handle(OpenGl_GraphicDriver) aDriver; | |
8625ef7e | 4217 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
4218 | if (!aContext.IsNull()) | |
a577aaab | 4219 | { |
8625ef7e | 4220 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver()); |
a577aaab | 4221 | aCaps = &aDriver->ChangeOptions(); |
4222 | } | |
4223 | ||
4224 | if (theArgNb < 2) | |
4225 | { | |
4226 | theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n"; | |
4227 | theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n"; | |
abe46077 | 4228 | theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n"; |
8625ef7e | 4229 | theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n"; |
a577aaab | 4230 | return 0; |
4231 | } | |
4232 | ||
8625ef7e | 4233 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
a577aaab | 4234 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
4235 | { | |
8625ef7e | 4236 | Standard_CString anArg = theArgVec[anArgIter]; |
4237 | TCollection_AsciiString anArgCase (anArg); | |
4238 | anArgCase.LowerCase(); | |
4239 | if (anUpdateTool.parseRedrawMode (anArg)) | |
4240 | { | |
4241 | continue; | |
4242 | } | |
4243 | else if (anArgCase == "-ffp") | |
4244 | { | |
4245 | Standard_Boolean toEnable = Standard_True; | |
4246 | if (++anArgIter < theArgNb | |
4247 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
4248 | { | |
4249 | --anArgIter; | |
4250 | } | |
4251 | aCaps->ffpEnable = toEnable; | |
4252 | } | |
4253 | else if (anArgCase == "-vbo") | |
a577aaab | 4254 | { |
8625ef7e | 4255 | Standard_Boolean toEnable = Standard_True; |
4256 | if (++anArgIter < theArgNb | |
4257 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
4258 | { | |
4259 | --anArgIter; | |
4260 | } | |
4261 | aCaps->vboDisable = !toEnable; | |
a577aaab | 4262 | } |
8625ef7e | 4263 | else if (anArgCase == "-sprite" |
4264 | || anArgCase == "-sprites") | |
a577aaab | 4265 | { |
8625ef7e | 4266 | Standard_Boolean toEnable = Standard_True; |
4267 | if (++anArgIter < theArgNb | |
4268 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
4269 | { | |
4270 | --anArgIter; | |
4271 | } | |
4272 | aCaps->pntSpritesDisable = !toEnable; | |
a577aaab | 4273 | } |
8625ef7e | 4274 | else if (anArgCase == "-softmode") |
abe46077 | 4275 | { |
8625ef7e | 4276 | Standard_Boolean toEnable = Standard_True; |
4277 | if (++anArgIter < theArgNb | |
4278 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
4279 | { | |
4280 | --anArgIter; | |
4281 | } | |
4282 | aCaps->contextNoAccel = toEnable; | |
4283 | } | |
4284 | else if (anArgCase == "-accel" | |
4285 | || anArgCase == "-acceleration") | |
4286 | { | |
4287 | Standard_Boolean toEnable = Standard_True; | |
4288 | if (++anArgIter < theArgNb | |
4289 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
4290 | { | |
4291 | --anArgIter; | |
4292 | } | |
4293 | aCaps->contextNoAccel = !toEnable; | |
abe46077 | 4294 | } |
a577aaab | 4295 | else |
4296 | { | |
8625ef7e | 4297 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
4298 | return 1; | |
a577aaab | 4299 | } |
4300 | } | |
4301 | if (aCaps != &ViewerTest_myDefaultCaps) | |
4302 | { | |
4303 | ViewerTest_myDefaultCaps = *aCaps; | |
4304 | } | |
4305 | return 0; | |
4306 | } | |
4307 | ||
f0430952 | 4308 | //============================================================================== |
4309 | //function : VMemGpu | |
4310 | //purpose : | |
4311 | //============================================================================== | |
4312 | ||
4313 | static int VMemGpu (Draw_Interpretor& theDI, | |
4314 | Standard_Integer theArgNb, | |
4315 | const char** theArgVec) | |
4316 | { | |
4317 | // get the context | |
4318 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
4319 | if (aContextAIS.IsNull()) | |
4320 | { | |
4321 | std::cerr << "No active view. Please call vinit.\n"; | |
4322 | return 1; | |
4323 | } | |
4324 | ||
dc3fe572 | 4325 | Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver(); |
f0430952 | 4326 | if (aDriver.IsNull()) |
4327 | { | |
4328 | std::cerr << "Graphic driver not available.\n"; | |
4329 | return 1; | |
4330 | } | |
4331 | ||
4332 | Standard_Size aFreeBytes = 0; | |
4333 | TCollection_AsciiString anInfo; | |
4334 | if (!aDriver->MemoryInfo (aFreeBytes, anInfo)) | |
4335 | { | |
4336 | std::cerr << "Information not available.\n"; | |
4337 | return 1; | |
4338 | } | |
4339 | ||
4340 | if (theArgNb > 1 && *theArgVec[1] == 'f') | |
4341 | { | |
4342 | theDI << Standard_Real (aFreeBytes); | |
4343 | } | |
4344 | else | |
4345 | { | |
4346 | theDI << anInfo; | |
4347 | } | |
4348 | ||
4349 | return 0; | |
4350 | } | |
4351 | ||
85e096c3 | 4352 | // ============================================================================== |
4353 | // function : VReadPixel | |
4354 | // purpose : | |
4355 | // ============================================================================== | |
4356 | static int VReadPixel (Draw_Interpretor& theDI, | |
4357 | Standard_Integer theArgNb, | |
4358 | const char** theArgVec) | |
4359 | { | |
4360 | // get the active view | |
4361 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4362 | if (aView.IsNull()) | |
4363 | { | |
4364 | std::cerr << "No active view. Please call vinit.\n"; | |
4365 | return 1; | |
4366 | } | |
4367 | else if (theArgNb < 3) | |
4368 | { | |
4369 | std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n"; | |
4370 | return 1; | |
4371 | } | |
4372 | ||
692613e5 | 4373 | Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; |
4374 | Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA; | |
4375 | ||
85e096c3 | 4376 | Standard_Integer aWidth, aHeight; |
4377 | aView->Window()->Size (aWidth, aHeight); | |
91322f44 | 4378 | const Standard_Integer anX = Draw::Atoi (theArgVec[1]); |
4379 | const Standard_Integer anY = Draw::Atoi (theArgVec[2]); | |
85e096c3 | 4380 | if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight) |
4381 | { | |
4382 | std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n"; | |
4383 | return 1; | |
4384 | } | |
4385 | ||
4386 | Standard_Boolean toShowName = Standard_False; | |
4387 | Standard_Boolean toShowHls = Standard_False; | |
4388 | for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter) | |
4389 | { | |
29cb310a | 4390 | const char* aParam = theArgVec[anIter]; |
4391 | if ( strcasecmp( aParam, "rgb" ) == 0 ) | |
85e096c3 | 4392 | { |
692613e5 | 4393 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; |
4394 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 4395 | } |
29cb310a | 4396 | else if ( strcasecmp( aParam, "hls" ) == 0 ) |
85e096c3 | 4397 | { |
692613e5 | 4398 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; |
4399 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 4400 | toShowHls = Standard_True; |
4401 | } | |
29cb310a | 4402 | else if ( strcasecmp( aParam, "rgbf" ) == 0 ) |
85e096c3 | 4403 | { |
692613e5 | 4404 | aFormat = Image_PixMap::ImgRGBF; |
4405 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 4406 | } |
29cb310a | 4407 | else if ( strcasecmp( aParam, "rgba" ) == 0 ) |
85e096c3 | 4408 | { |
692613e5 | 4409 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; |
4410 | aBufferType = Graphic3d_BT_RGBA; | |
85e096c3 | 4411 | } |
29cb310a | 4412 | else if ( strcasecmp( aParam, "rgbaf" ) == 0 ) |
85e096c3 | 4413 | { |
692613e5 | 4414 | aFormat = Image_PixMap::ImgRGBAF; |
4415 | aBufferType = Graphic3d_BT_RGBA; | |
85e096c3 | 4416 | } |
29cb310a | 4417 | else if ( strcasecmp( aParam, "depth" ) == 0 ) |
85e096c3 | 4418 | { |
692613e5 | 4419 | aFormat = Image_PixMap::ImgGrayF; |
4420 | aBufferType = Graphic3d_BT_Depth; | |
85e096c3 | 4421 | } |
29cb310a | 4422 | else if ( strcasecmp( aParam, "name" ) == 0 ) |
85e096c3 | 4423 | { |
4424 | toShowName = Standard_True; | |
4425 | } | |
4426 | } | |
4427 | ||
692613e5 | 4428 | Image_PixMap anImage; |
4429 | if (!anImage.InitTrash (aFormat, aWidth, aHeight)) | |
4430 | { | |
4431 | std::cerr << "Image allocation failed\n"; | |
4432 | return 1; | |
4433 | } | |
4434 | else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType)) | |
85e096c3 | 4435 | { |
4436 | std::cerr << "Image dump failed\n"; | |
4437 | return 1; | |
4438 | } | |
4439 | ||
4440 | Quantity_Parameter anAlpha; | |
692613e5 | 4441 | Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha); |
85e096c3 | 4442 | if (toShowName) |
4443 | { | |
692613e5 | 4444 | if (aBufferType == Graphic3d_BT_RGBA) |
85e096c3 | 4445 | { |
64c759f8 | 4446 | theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha; |
85e096c3 | 4447 | } |
4448 | else | |
4449 | { | |
64c759f8 | 4450 | theDI << Quantity_Color::StringName (aColor.Name()); |
85e096c3 | 4451 | } |
4452 | } | |
4453 | else | |
4454 | { | |
4455 | switch (aBufferType) | |
4456 | { | |
4457 | default: | |
692613e5 | 4458 | case Graphic3d_BT_RGB: |
85e096c3 | 4459 | { |
4460 | if (toShowHls) | |
4461 | { | |
64c759f8 | 4462 | theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation(); |
85e096c3 | 4463 | } |
4464 | else | |
4465 | { | |
64c759f8 | 4466 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue(); |
85e096c3 | 4467 | } |
4468 | break; | |
4469 | } | |
692613e5 | 4470 | case Graphic3d_BT_RGBA: |
85e096c3 | 4471 | { |
64c759f8 | 4472 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha; |
85e096c3 | 4473 | break; |
4474 | } | |
692613e5 | 4475 | case Graphic3d_BT_Depth: |
85e096c3 | 4476 | { |
64c759f8 | 4477 | theDI << aColor.Red(); |
85e096c3 | 4478 | break; |
4479 | } | |
4480 | } | |
4481 | } | |
4482 | ||
4483 | return 0; | |
4484 | } | |
4485 | ||
692613e5 | 4486 | //============================================================================== |
4487 | //function : VDiffImage | |
4488 | //purpose : The draw-command compares two images. | |
4489 | //============================================================================== | |
4490 | ||
4491 | static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
4492 | { | |
4493 | if (theArgNb < 6) | |
4494 | { | |
4495 | theDI << "Not enough arguments.\n"; | |
4496 | return 1; | |
4497 | } | |
4498 | ||
4499 | // image file names | |
4500 | const char* anImgPathRef = theArgVec[1]; | |
4501 | const char* anImgPathNew = theArgVec[2]; | |
4502 | ||
4503 | // get string tolerance and check its validity | |
91322f44 | 4504 | Standard_Real aTolColor = Draw::Atof (theArgVec[3]); |
692613e5 | 4505 | if (aTolColor < 0.0) |
4506 | aTolColor = 0.0; | |
4507 | if (aTolColor > 1.0) | |
4508 | aTolColor = 1.0; | |
4509 | ||
91322f44 | 4510 | Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1); |
4511 | Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1); | |
692613e5 | 4512 | |
4513 | // image file of difference | |
4514 | const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL; | |
4515 | ||
4516 | // compare the images | |
4517 | Image_Diff aComparer; | |
4518 | if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite)) | |
4519 | { | |
4520 | return 1; | |
4521 | } | |
4522 | ||
4523 | aComparer.SetColorTolerance (aTolColor); | |
4524 | aComparer.SetBorderFilterOn (isBorderFilterOn); | |
4525 | Standard_Integer aDiffColorsNb = aComparer.Compare(); | |
4526 | theDI << aDiffColorsNb << "\n"; | |
4527 | ||
4528 | // save image of difference | |
4529 | if (aDiffImagePath != NULL) | |
4530 | { | |
4531 | aComparer.SaveDiffImage (aDiffImagePath); | |
4532 | } | |
4533 | ||
4534 | return 0; | |
4535 | } | |
4536 | ||
4754e164 | 4537 | //======================================================================= |
4538 | //function : VSelect | |
4539 | //purpose : Emulates different types of selection by mouse: | |
4540 | // 1) single click selection | |
4541 | // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2) | |
4542 | // 3) selection with polygon having corners at | |
dc3fe572 | 4543 | // pixel positions (x1,y1),...,(xn,yn) |
4754e164 | 4544 | // 4) any of these selections with shift button pressed |
4545 | //======================================================================= | |
4546 | static Standard_Integer VSelect (Draw_Interpretor& di, | |
4547 | Standard_Integer argc, | |
4548 | const char ** argv) | |
4549 | { | |
dc3fe572 | 4550 | if(argc < 3) |
4754e164 | 4551 | { |
4552 | di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n"; | |
4553 | return 1; | |
4554 | } | |
4555 | ||
4556 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); | |
dc3fe572 | 4557 | if(myAIScontext.IsNull()) |
4754e164 | 4558 | { |
4559 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4560 | return 1; | |
4561 | } | |
4562 | const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1)); | |
4563 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); | |
4564 | aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2])); | |
4565 | if(argc <= 4) | |
4566 | { | |
4567 | if(isShiftSelection) | |
4568 | aCurrentEventManager->ShiftSelect(); | |
4569 | else | |
4570 | aCurrentEventManager->Select(); | |
4571 | } | |
4572 | else if(argc <= 6) | |
4573 | { | |
4574 | if(isShiftSelection) | |
4575 | aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4])); | |
4576 | else | |
4577 | aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4])); | |
4578 | } | |
4579 | else | |
4580 | { | |
4581 | Standard_Integer anUpper = 0; | |
4582 | ||
4583 | if(isShiftSelection) | |
4584 | anUpper = (argc-1)/2; | |
4585 | else | |
4586 | anUpper = argc/2; | |
4587 | TColgp_Array1OfPnt2d aPolyline(1,anUpper); | |
4588 | ||
4589 | for(Standard_Integer i=1;i<=anUpper;++i) | |
4590 | aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i]))); | |
4591 | ||
4592 | if(isShiftSelection) | |
4593 | aCurrentEventManager->ShiftSelect(aPolyline); | |
4594 | else | |
4595 | aCurrentEventManager->Select(aPolyline); | |
4596 | } | |
4597 | return 0; | |
4598 | } | |
4599 | ||
4600 | //======================================================================= | |
4601 | //function : VMoveTo | |
dc3fe572 | 4602 | //purpose : Emulates cursor movement to defined pixel position |
4754e164 | 4603 | //======================================================================= |
4604 | static Standard_Integer VMoveTo (Draw_Interpretor& di, | |
4605 | Standard_Integer argc, | |
4606 | const char ** argv) | |
4607 | { | |
dc3fe572 | 4608 | if(argc != 3) |
4754e164 | 4609 | { |
4610 | di << "Usage : " << argv[0] << " x y" << "\n"; | |
4611 | return 1; | |
4612 | } | |
4613 | ||
4614 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
dc3fe572 | 4615 | if(aContext.IsNull()) |
4754e164 | 4616 | { |
4617 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4618 | return 1; | |
4619 | } | |
4620 | ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2])); | |
4621 | return 0; | |
4622 | } | |
4623 | ||
197ac94e | 4624 | //================================================================================================= |
4754e164 | 4625 | //function : VViewParams |
dc3fe572 | 4626 | //purpose : Gets or sets AIS View characteristics |
197ac94e | 4627 | //================================================================================================= |
4628 | static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
4754e164 | 4629 | { |
197ac94e | 4630 | Handle(V3d_View) anAISView = ViewerTest::CurrentView(); |
4631 | if (anAISView.IsNull()) | |
4754e164 | 4632 | { |
197ac94e | 4633 | std::cout << theArgVec[0] << ": please initialize or activate view.\n"; |
4754e164 | 4634 | return 1; |
4635 | } | |
197ac94e | 4636 | |
4637 | if (theArgsNb == 1) | |
4754e164 | 4638 | { |
197ac94e | 4639 | // print all of the available view parameters |
4640 | Quantity_Factor anAISViewScale = anAISView->Scale(); | |
4641 | ||
4754e164 | 4642 | Standard_Real anAISViewProjX = 0.0; |
4643 | Standard_Real anAISViewProjY = 0.0; | |
4644 | Standard_Real anAISViewProjZ = 0.0; | |
197ac94e | 4645 | anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ); |
4646 | ||
4754e164 | 4647 | Standard_Real anAISViewUpX = 0.0; |
4648 | Standard_Real anAISViewUpY = 0.0; | |
4649 | Standard_Real anAISViewUpZ = 0.0; | |
197ac94e | 4650 | anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ); |
4651 | ||
4754e164 | 4652 | Standard_Real anAISViewAtX = 0.0; |
4653 | Standard_Real anAISViewAtY = 0.0; | |
4654 | Standard_Real anAISViewAtZ = 0.0; | |
197ac94e | 4655 | anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ); |
4656 | ||
4657 | Standard_Real anAISViewEyeX = 0.0; | |
4658 | Standard_Real anAISViewEyeY = 0.0; | |
4659 | Standard_Real anAISViewEyeZ = 0.0; | |
4660 | anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ); | |
4661 | ||
4662 | theDi << "Scale of current view: " << anAISViewScale << "\n"; | |
4663 | theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n"; | |
4664 | theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n"; | |
4665 | theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n"; | |
4666 | theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n"; | |
4667 | return 0; | |
4754e164 | 4668 | } |
197ac94e | 4669 | |
4670 | // ------------------------- | |
4671 | // Parse options and values | |
4672 | // ------------------------- | |
4673 | ||
900f7229 | 4674 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues; |
197ac94e | 4675 | TCollection_AsciiString aParseKey; |
4676 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
4677 | { | |
4678 | TCollection_AsciiString anArg (theArgVec [anArgIt]); | |
4679 | ||
4680 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) | |
4681 | { | |
4682 | aParseKey = anArg; | |
4683 | aParseKey.Remove (1); | |
4684 | aParseKey.UpperCase(); | |
900f7229 | 4685 | aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); |
197ac94e | 4686 | continue; |
4687 | } | |
4688 | ||
3dfe95cd | 4689 | if (aParseKey.IsEmpty()) |
4690 | { | |
4691 | std::cout << theArgVec[0] << ": values should be passed with key.\n"; | |
4692 | std::cout << "Type help for more information.\n"; | |
4693 | return 1; | |
4694 | } | |
4695 | ||
900f7229 | 4696 | aMapOfKeysByValues(aParseKey)->Append (anArg); |
197ac94e | 4697 | } |
4698 | ||
4699 | // --------------------------------------------- | |
4700 | // Change or print parameters, order plays role | |
4701 | // --------------------------------------------- | |
4702 | ||
4703 | // Check arguments for validity | |
900f7229 | 4704 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues); |
197ac94e | 4705 | for (; aMapIt.More(); aMapIt.Next()) |
4754e164 | 4706 | { |
197ac94e | 4707 | const TCollection_AsciiString& aKey = aMapIt.Key(); |
900f7229 | 4708 | const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value(); |
4709 | ||
4710 | if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty())) | |
4711 | && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty())) | |
4712 | && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty())) | |
4713 | && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty())) | |
4714 | && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty())) | |
4715 | && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty())) | |
4716 | && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2)) | |
197ac94e | 4717 | { |
4718 | TCollection_AsciiString aLowerKey; | |
4719 | aLowerKey = "-"; | |
4720 | aLowerKey += aKey; | |
4721 | aLowerKey.LowerCase(); | |
4722 | std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n"; | |
4723 | std::cout << "Type help for more information.\n"; | |
4724 | return 1; | |
4725 | } | |
4754e164 | 4726 | } |
197ac94e | 4727 | |
900f7229 | 4728 | Handle(TColStd_HSequenceOfAsciiString) aValues; |
197ac94e | 4729 | |
4730 | // Change view parameters in proper order | |
4731 | if (aMapOfKeysByValues.Find ("SCALE", aValues)) | |
4732 | { | |
900f7229 | 4733 | if (aValues->IsEmpty()) |
197ac94e | 4734 | { |
4735 | theDi << "Scale: " << anAISView->Scale() << "\n"; | |
4736 | } | |
4737 | else | |
4738 | { | |
900f7229 | 4739 | anAISView->SetScale (aValues->Value(1).RealValue()); |
197ac94e | 4740 | } |
4741 | } | |
3dfe95cd | 4742 | if (aMapOfKeysByValues.Find ("SIZE", aValues)) |
4743 | { | |
900f7229 | 4744 | if (aValues->IsEmpty()) |
3dfe95cd | 4745 | { |
4746 | Standard_Real aSizeX = 0.0; | |
4747 | Standard_Real aSizeY = 0.0; | |
4748 | anAISView->Size (aSizeX, aSizeY); | |
4749 | theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n"; | |
4750 | } | |
4751 | else | |
4752 | { | |
900f7229 | 4753 | anAISView->SetSize (aValues->Value(1).RealValue()); |
3dfe95cd | 4754 | } |
4755 | } | |
197ac94e | 4756 | if (aMapOfKeysByValues.Find ("EYE", aValues)) |
4757 | { | |
900f7229 | 4758 | if (aValues->IsEmpty()) |
197ac94e | 4759 | { |
4760 | Standard_Real anEyeX = 0.0; | |
4761 | Standard_Real anEyeY = 0.0; | |
4762 | Standard_Real anEyeZ = 0.0; | |
4763 | anAISView->Eye (anEyeX, anEyeY, anEyeZ); | |
4764 | theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n"; | |
4765 | } | |
4766 | else | |
4767 | { | |
900f7229 | 4768 | anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
197ac94e | 4769 | } |
4770 | } | |
4771 | if (aMapOfKeysByValues.Find ("AT", aValues)) | |
4772 | { | |
900f7229 | 4773 | if (aValues->IsEmpty()) |
197ac94e | 4774 | { |
4775 | Standard_Real anAtX = 0.0; | |
4776 | Standard_Real anAtY = 0.0; | |
4777 | Standard_Real anAtZ = 0.0; | |
4778 | anAISView->At (anAtX, anAtY, anAtZ); | |
4779 | theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n"; | |
4780 | } | |
4781 | else | |
4782 | { | |
900f7229 | 4783 | anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
197ac94e | 4784 | } |
4785 | } | |
4786 | if (aMapOfKeysByValues.Find ("PROJ", aValues)) | |
4787 | { | |
900f7229 | 4788 | if (aValues->IsEmpty()) |
197ac94e | 4789 | { |
4790 | Standard_Real aProjX = 0.0; | |
4791 | Standard_Real aProjY = 0.0; | |
4792 | Standard_Real aProjZ = 0.0; | |
4793 | anAISView->Proj (aProjX, aProjY, aProjZ); | |
4794 | theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n"; | |
4795 | } | |
4796 | else | |
4797 | { | |
900f7229 | 4798 | anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
197ac94e | 4799 | } |
4800 | } | |
4801 | if (aMapOfKeysByValues.Find ("UP", aValues)) | |
4802 | { | |
900f7229 | 4803 | if (aValues->IsEmpty()) |
197ac94e | 4804 | { |
4805 | Standard_Real anUpX = 0.0; | |
4806 | Standard_Real anUpY = 0.0; | |
4807 | Standard_Real anUpZ = 0.0; | |
4808 | anAISView->Up (anUpX, anUpY, anUpZ); | |
4809 | theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n"; | |
4810 | } | |
4811 | else | |
4812 | { | |
900f7229 | 4813 | anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
197ac94e | 4814 | } |
4815 | } | |
4816 | if (aMapOfKeysByValues.Find ("CENTER", aValues)) | |
4817 | { | |
900f7229 | 4818 | anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue()); |
197ac94e | 4819 | } |
4820 | ||
4754e164 | 4821 | return 0; |
4822 | } | |
4823 | ||
4824 | //======================================================================= | |
4825 | //function : VChangeSelected | |
dc3fe572 | 4826 | //purpose : Adds the shape to selection or remove one from it |
4754e164 | 4827 | //======================================================================= |
4828 | static Standard_Integer VChangeSelected (Draw_Interpretor& di, | |
4829 | Standard_Integer argc, | |
4830 | const char ** argv) | |
4831 | { | |
4832 | if(argc != 2) | |
4833 | { | |
4834 | di<<"Usage : " << argv[0] << " shape \n"; | |
4835 | return 1; | |
4836 | } | |
4837 | //get AIS_Shape: | |
4838 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4839 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4840 | TCollection_AsciiString aName(argv[1]); | |
4841 | Handle(AIS_InteractiveObject) anAISObject; | |
4842 | ||
4843 | if(!aMap.IsBound2(aName)) | |
4844 | { | |
4845 | di<<"Use 'vdisplay' before"; | |
4846 | return 1; | |
4847 | } | |
4848 | else | |
4849 | { | |
4850 | anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName)); | |
4851 | if(anAISObject.IsNull()){ | |
4852 | di<<"No interactive object \n"; | |
4853 | return 1; | |
4854 | } | |
4855 | ||
4856 | if(aContext->HasOpenedContext()) | |
4857 | { | |
4858 | aContext->AddOrRemoveSelected(anAISObject); | |
4859 | } | |
dc3fe572 | 4860 | else |
4754e164 | 4861 | { |
4862 | aContext->AddOrRemoveCurrentObject(anAISObject); | |
4863 | } | |
4864 | } | |
4865 | return 0; | |
4866 | } | |
4867 | ||
4868 | //======================================================================= | |
4869 | //function : VZClipping | |
dc3fe572 | 4870 | //purpose : Gets or sets ZClipping mode, width and depth |
4754e164 | 4871 | //======================================================================= |
4872 | static Standard_Integer VZClipping (Draw_Interpretor& di, | |
4873 | Standard_Integer argc, | |
4874 | const char ** argv) | |
4875 | { | |
dc3fe572 | 4876 | if(argc>4) |
4754e164 | 4877 | { |
4878 | di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
4879 | <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
4880 | return -1; | |
4881 | } | |
4882 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
dc3fe572 | 4883 | if(aContext.IsNull()) |
4754e164 | 4884 | { |
4885 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4886 | return 1; | |
4887 | } | |
4888 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
1d47d8d0 | 4889 | V3d_TypeOfZclipping aZClippingMode = V3d_OFF; |
4754e164 | 4890 | if(argc==1) |
4891 | { | |
4892 | TCollection_AsciiString aZClippingModeString; | |
4893 | Quantity_Length aDepth, aWidth; | |
4894 | aZClippingMode = aView->ZClipping(aDepth, aWidth); | |
4895 | switch (aZClippingMode) | |
4896 | { | |
4897 | case V3d_OFF: | |
4898 | aZClippingModeString.Copy("OFF"); | |
4899 | break; | |
4900 | case V3d_BACK: | |
4901 | aZClippingModeString.Copy("BACK"); | |
4902 | break; | |
4903 | case V3d_FRONT: | |
4904 | aZClippingModeString.Copy("FRONT"); | |
4905 | break; | |
4906 | case V3d_SLICE: | |
4907 | aZClippingModeString.Copy("SLICE"); | |
4908 | break; | |
4909 | default: | |
4910 | aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode)); | |
4911 | break; | |
4912 | } | |
4913 | di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n" | |
4914 | << "ZClipping depth = " << aDepth << "\n" | |
4915 | << "ZClipping width = " << aWidth << "\n"; | |
4916 | } | |
4917 | else | |
4918 | { | |
4919 | if(argc !=3) | |
4920 | { | |
4921 | Standard_Integer aStatus = 0; | |
4922 | if ( strcmp (argv [1], "OFF") == 0 ) { | |
4923 | aStatus = 1; | |
4924 | aZClippingMode = V3d_OFF; | |
4925 | } | |
4926 | if ( strcmp (argv [1], "BACK") == 0 ) { | |
4927 | aStatus = 1; | |
4928 | aZClippingMode = V3d_BACK; | |
4929 | } | |
4930 | if ( strcmp (argv [1], "FRONT") == 0 ) { | |
4931 | aStatus = 1; | |
4932 | aZClippingMode = V3d_FRONT; | |
4933 | } | |
4934 | if ( strcmp (argv [1], "SLICE") == 0 ) { | |
4935 | aStatus = 1; | |
4936 | aZClippingMode = V3d_SLICE; | |
4937 | } | |
4938 | if (aStatus != 1) | |
4939 | { | |
4940 | di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
4941 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
4942 | return 1; | |
dc3fe572 | 4943 | } |
4754e164 | 4944 | aView->SetZClippingType(aZClippingMode); |
4945 | } | |
4946 | if(argc >2) | |
4947 | { | |
4948 | Quantity_Length aDepth = 0., aWidth = 1.; | |
4949 | if(argc == 3) | |
4950 | { | |
6b62b2da | 4951 | aDepth = Draw::Atof (argv[1]); |
4952 | aWidth = Draw::Atof (argv[2]); | |
4754e164 | 4953 | } |
4954 | else if(argc == 4) | |
4955 | { | |
6b62b2da | 4956 | aDepth = Draw::Atof (argv[2]); |
4957 | aWidth = Draw::Atof (argv[3]); | |
4754e164 | 4958 | } |
dc3fe572 | 4959 | |
4754e164 | 4960 | if(aDepth<0. || aDepth>1.) |
4961 | { | |
4962 | di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
4963 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
4964 | return 1; | |
4965 | } | |
4966 | if(aWidth<0. || aWidth>1.) | |
4967 | { | |
4968 | di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
4969 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
4970 | return 1; | |
4971 | } | |
4972 | ||
4973 | aView->SetZClippingDepth(aDepth); | |
4974 | aView->SetZClippingWidth(aWidth); | |
4975 | } | |
4976 | aView->Redraw(); | |
4977 | } | |
4978 | return 0; | |
4979 | } | |
4980 | ||
4981 | //======================================================================= | |
4982 | //function : VNbSelected | |
dc3fe572 | 4983 | //purpose : Returns number of selected objects |
4754e164 | 4984 | //======================================================================= |
4985 | static Standard_Integer VNbSelected (Draw_Interpretor& di, | |
4986 | Standard_Integer argc, | |
4987 | const char ** argv) | |
4988 | { | |
4989 | if(argc != 1) | |
4990 | { | |
4991 | di << "Usage : " << argv[0] << "\n"; | |
4992 | return 1; | |
4993 | } | |
4994 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4995 | if(aContext.IsNull()) | |
4996 | { | |
4997 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4998 | return 1; | |
4999 | } | |
5000 | di << aContext->NbSelected() << "\n"; | |
5001 | return 0; | |
5002 | } | |
5003 | ||
5004 | //======================================================================= | |
5005 | //function : VAntialiasing | |
dc3fe572 | 5006 | //purpose : Switches altialiasing on or off |
4754e164 | 5007 | //======================================================================= |
5008 | static Standard_Integer VAntialiasing (Draw_Interpretor& di, | |
5009 | Standard_Integer argc, | |
5010 | const char ** argv) | |
5011 | { | |
5012 | if(argc > 2) | |
5013 | { | |
5014 | di << "Usage : " << argv[0] << " [1|0]" << "\n"; | |
5015 | return 1; | |
5016 | } | |
5017 | ||
5018 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5019 | if(aContext.IsNull()) | |
5020 | { | |
5021 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
5022 | return 1; | |
5023 | } | |
5024 | ||
5025 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5026 | ||
5027 | if((argc == 2) && (atof(argv[1]) == 0)) | |
5028 | aView->SetAntialiasingOff(); | |
5029 | else | |
5030 | aView->SetAntialiasingOn(); | |
5031 | aView->Update(); | |
5032 | return 0; | |
5033 | } | |
5034 | ||
5035 | //======================================================================= | |
5036 | //function : VPurgeDisplay | |
dc3fe572 | 5037 | //purpose : Switches altialiasing on or off |
4754e164 | 5038 | //======================================================================= |
5039 | static Standard_Integer VPurgeDisplay (Draw_Interpretor& di, | |
5040 | Standard_Integer argc, | |
5041 | const char ** argv) | |
5042 | { | |
eb4320f2 | 5043 | if (argc > 1) |
4754e164 | 5044 | { |
eb4320f2 | 5045 | di << "Usage : " << argv[0] << "\n"; |
4754e164 | 5046 | return 1; |
5047 | } | |
4754e164 | 5048 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
5049 | if (aContext.IsNull()) | |
5050 | { | |
5051 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
5052 | return 1; | |
5053 | } | |
5054 | aContext->CloseAllContexts(Standard_False); | |
eb4320f2 | 5055 | di << aContext->PurgeDisplay() << "\n"; |
4754e164 | 5056 | return 0; |
5057 | } | |
5058 | ||
5059 | //======================================================================= | |
5060 | //function : VSetViewSize | |
5061 | //purpose : | |
5062 | //======================================================================= | |
5063 | static Standard_Integer VSetViewSize (Draw_Interpretor& di, | |
5064 | Standard_Integer argc, | |
5065 | const char ** argv) | |
5066 | { | |
5067 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5068 | if(aContext.IsNull()) | |
5069 | { | |
5070 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
5071 | return 1; | |
5072 | } | |
5073 | if(argc != 2) | |
5074 | { | |
5075 | di<<"Usage : " << argv[0] << " Size\n"; | |
5076 | return 1; | |
5077 | } | |
6b62b2da | 5078 | Standard_Real aSize = Draw::Atof (argv[1]); |
4754e164 | 5079 | if (aSize <= 0.) |
5080 | { | |
5081 | di<<"Bad Size value : " << aSize << "\n"; | |
5082 | return 1; | |
5083 | } | |
5084 | ||
5085 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5086 | aView->SetSize(aSize); | |
5087 | return 0; | |
5088 | } | |
5089 | ||
5090 | //======================================================================= | |
5091 | //function : VMoveView | |
5092 | //purpose : | |
5093 | //======================================================================= | |
5094 | static Standard_Integer VMoveView (Draw_Interpretor& di, | |
5095 | Standard_Integer argc, | |
5096 | const char ** argv) | |
5097 | { | |
5098 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5099 | if(aContext.IsNull()) | |
5100 | { | |
5101 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
5102 | return 1; | |
5103 | } | |
5104 | if(argc < 4 || argc > 5) | |
5105 | { | |
5106 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
5107 | return 1; | |
5108 | } | |
6b62b2da | 5109 | Standard_Real Dx = Draw::Atof (argv[1]); |
5110 | Standard_Real Dy = Draw::Atof (argv[2]); | |
5111 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 5112 | Standard_Boolean aStart = Standard_True; |
5113 | if (argc == 5) | |
5114 | { | |
6b62b2da | 5115 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 5116 | } |
5117 | ||
5118 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5119 | aView->Move(Dx,Dy,Dz,aStart); | |
5120 | return 0; | |
5121 | } | |
5122 | ||
5123 | //======================================================================= | |
5124 | //function : VTranslateView | |
5125 | //purpose : | |
5126 | //======================================================================= | |
5127 | static Standard_Integer VTranslateView (Draw_Interpretor& di, | |
5128 | Standard_Integer argc, | |
5129 | const char ** argv) | |
5130 | { | |
5131 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5132 | if(aContext.IsNull()) | |
5133 | { | |
5134 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
5135 | return 1; | |
5136 | } | |
5137 | if(argc < 4 || argc > 5) | |
5138 | { | |
5139 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
5140 | return 1; | |
5141 | } | |
6b62b2da | 5142 | Standard_Real Dx = Draw::Atof (argv[1]); |
5143 | Standard_Real Dy = Draw::Atof (argv[2]); | |
5144 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 5145 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 5146 | if (argc == 5) |
4754e164 | 5147 | { |
6b62b2da | 5148 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 5149 | } |
5150 | ||
5151 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5152 | aView->Translate(Dx,Dy,Dz,aStart); | |
5153 | return 0; | |
5154 | } | |
5155 | ||
5156 | //======================================================================= | |
5157 | //function : VTurnView | |
5158 | //purpose : | |
5159 | //======================================================================= | |
5160 | static Standard_Integer VTurnView (Draw_Interpretor& di, | |
5161 | Standard_Integer argc, | |
5162 | const char ** argv) | |
5163 | { | |
5164 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5165 | if(aContext.IsNull()) { | |
5166 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
5167 | return 1; | |
5168 | } | |
5169 | if(argc < 4 || argc > 5){ | |
5170 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n"; | |
5171 | return 1; | |
5172 | } | |
6b62b2da | 5173 | Standard_Real Ax = Draw::Atof (argv[1]); |
5174 | Standard_Real Ay = Draw::Atof (argv[2]); | |
5175 | Standard_Real Az = Draw::Atof (argv[3]); | |
4754e164 | 5176 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 5177 | if (argc == 5) |
4754e164 | 5178 | { |
6b62b2da | 5179 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 5180 | } |
5181 | ||
5182 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5183 | aView->Turn(Ax,Ay,Az,aStart); | |
5184 | return 0; | |
5185 | } | |
5186 | ||
269294d6 | 5187 | //============================================================================== |
5188 | //function : VTextureEnv | |
5189 | //purpose : ENables or disables environment mapping | |
5190 | //============================================================================== | |
5191 | class OCC_TextureEnv : public Graphic3d_TextureEnv | |
5192 | { | |
5193 | public: | |
5194 | OCC_TextureEnv(const Standard_CString FileName); | |
5195 | OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName); | |
5196 | void SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
5197 | const Standard_Boolean theModulateFlag, | |
5198 | const Graphic3d_TypeOfTextureFilter theFilter, | |
5199 | const Standard_ShortReal theXScale, | |
5200 | const Standard_ShortReal theYScale, | |
5201 | const Standard_ShortReal theXShift, | |
5202 | const Standard_ShortReal theYShift, | |
5203 | const Standard_ShortReal theAngle); | |
5204 | DEFINE_STANDARD_RTTI(OCC_TextureEnv); | |
5205 | }; | |
5206 | DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv); | |
5207 | IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv); | |
5208 | IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv); | |
5209 | ||
5210 | OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName) | |
5211 | : Graphic3d_TextureEnv(theFileName) | |
5212 | { | |
5213 | } | |
5214 | ||
5215 | OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId) | |
5216 | : Graphic3d_TextureEnv(theTexId) | |
5217 | { | |
5218 | } | |
5219 | ||
5220 | void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
5221 | const Standard_Boolean theModulateFlag, | |
5222 | const Graphic3d_TypeOfTextureFilter theFilter, | |
5223 | const Standard_ShortReal theXScale, | |
5224 | const Standard_ShortReal theYScale, | |
5225 | const Standard_ShortReal theXShift, | |
5226 | const Standard_ShortReal theYShift, | |
5227 | const Standard_ShortReal theAngle) | |
5228 | { | |
5229 | myParams->SetRepeat (theRepeatFlag); | |
5230 | myParams->SetModulate (theModulateFlag); | |
5231 | myParams->SetFilter (theFilter); | |
5232 | myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale)); | |
5233 | myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift)); | |
5234 | myParams->SetRotation (theAngle); | |
5235 | } | |
5236 | ||
35e08fe8 | 5237 | static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec) |
269294d6 | 5238 | { |
5239 | // get the active view | |
5240 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5241 | if (aView.IsNull()) | |
5242 | { | |
5243 | std::cerr << "No active view. Please call vinit.\n"; | |
5244 | return 1; | |
5245 | } | |
5246 | ||
5247 | // Checking the input arguments | |
5248 | Standard_Boolean anEnableFlag = Standard_False; | |
5249 | Standard_Boolean isOk = theArgNb >= 2; | |
5250 | if (isOk) | |
5251 | { | |
5252 | TCollection_AsciiString anEnableOpt(theArgVec[1]); | |
5253 | anEnableFlag = anEnableOpt.IsEqual("on"); | |
5254 | isOk = anEnableFlag || anEnableOpt.IsEqual("off"); | |
5255 | } | |
5256 | if (anEnableFlag) | |
5257 | { | |
5258 | isOk = (theArgNb == 3 || theArgNb == 11); | |
5259 | if (isOk) | |
5260 | { | |
5261 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
5262 | isOk = (!aTextureOpt.IsIntegerValue() || | |
5263 | (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN)); | |
5264 | ||
5265 | if (isOk && theArgNb == 11) | |
5266 | { | |
5267 | TCollection_AsciiString aRepeatOpt (theArgVec[3]), | |
5268 | aModulateOpt(theArgVec[4]), | |
5269 | aFilterOpt (theArgVec[5]), | |
5270 | aSScaleOpt (theArgVec[6]), | |
5271 | aTScaleOpt (theArgVec[7]), | |
5272 | aSTransOpt (theArgVec[8]), | |
5273 | aTTransOpt (theArgVec[9]), | |
5274 | anAngleOpt (theArgVec[10]); | |
5275 | isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) && | |
5276 | (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) && | |
5277 | (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) && | |
5278 | aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() && | |
5279 | aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() && | |
5280 | anAngleOpt.IsRealValue()); | |
5281 | } | |
5282 | } | |
5283 | } | |
5284 | ||
5285 | if (!isOk) | |
5286 | { | |
5287 | std::cerr << "Usage :" << std::endl; | |
5288 | std::cerr << theArgVec[0] << " off" << std::endl; | |
5289 | std::cerr << theArgVec[0] << " on {index_of_std_texture(0..7)|texture_file_name} [{clamp|repeat} {decal|modulate} {nearest|bilinear|trilinear} scale_s scale_t translation_s translation_t rotation_degrees]" << std::endl; | |
5290 | return 1; | |
5291 | } | |
5292 | ||
5293 | if (anEnableFlag) | |
5294 | { | |
5295 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
5296 | Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ? | |
5297 | new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) : | |
5298 | new OCC_TextureEnv(theArgVec[2]); | |
5299 | ||
5300 | if (theArgNb == 11) | |
5301 | { | |
5302 | TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]); | |
5303 | aTexEnv->SetTextureParameters( | |
5304 | aRepeatOpt. IsEqual("repeat"), | |
5305 | aModulateOpt.IsEqual("modulate"), | |
5306 | aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST : | |
5307 | aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR : | |
5308 | Graphic3d_TOTF_TRILINEAR, | |
5309 | (Standard_ShortReal)Draw::Atof(theArgVec[6]), | |
5310 | (Standard_ShortReal)Draw::Atof(theArgVec[7]), | |
5311 | (Standard_ShortReal)Draw::Atof(theArgVec[8]), | |
5312 | (Standard_ShortReal)Draw::Atof(theArgVec[9]), | |
5313 | (Standard_ShortReal)Draw::Atof(theArgVec[10]) | |
5314 | ); | |
5315 | } | |
5316 | aView->SetTextureEnv(aTexEnv); | |
5317 | aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT); | |
5318 | } | |
5319 | else // Disabling environment mapping | |
5320 | { | |
5321 | aView->SetSurfaceDetail(V3d_TEX_NONE); | |
5322 | Handle(Graphic3d_TextureEnv) aTexture; | |
5323 | aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data | |
5324 | } | |
5325 | ||
5326 | aView->Redraw(); | |
5327 | return 0; | |
5328 | } | |
5329 | ||
4269bd1b | 5330 | //=============================================================================================== |
5331 | //function : VClipPlane | |
5332 | //purpose : | |
5333 | //=============================================================================================== | |
5334 | static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
5335 | { | |
5336 | // use short-cut for created clip planes map of created (or "registered by name") clip planes | |
5337 | typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes; | |
5338 | static MapOfPlanes aRegPlanes; | |
5339 | ||
5340 | if (theArgsNb < 2) | |
5341 | { | |
5342 | theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n"; | |
5343 | return 1; | |
5344 | } | |
5345 | ||
5346 | TCollection_AsciiString aCommand (theArgVec[1]); | |
5347 | ||
5348 | // print maximum number of planes for current viewer | |
5349 | if (aCommand == "maxplanes") | |
5350 | { | |
5351 | if (theArgsNb < 3) | |
5352 | { | |
5353 | theDi << theArgVec[0] << ": view name is required. Type help for more information.\n"; | |
5354 | return 1; | |
5355 | } | |
5356 | ||
5357 | TCollection_AsciiString aViewName (theArgVec[2]); | |
5358 | ||
5359 | if (!ViewerTest_myViews.IsBound1 (aViewName)) | |
5360 | { | |
5361 | theDi << theArgVec[0] << ": view is not found.\n"; | |
5362 | return 1; | |
5363 | } | |
5364 | ||
5365 | const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName); | |
5366 | ||
5367 | theDi << theArgVec[0] << ": " | |
5368 | << aView->Viewer()->Driver()->InquirePlaneLimit() | |
5369 | << " plane slots provided by driver." | |
5370 | << " Note that 2 more planes might be used (reserved for z-clipping).\n"; | |
5371 | ||
5372 | return 0; | |
5373 | } | |
5374 | ||
5375 | // create / delete plane instance | |
5376 | if (aCommand == "create" || aCommand == "delete" || aCommand == "clone") | |
5377 | { | |
5378 | if (theArgsNb < 3) | |
5379 | { | |
5380 | theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n"; | |
5381 | return 1; | |
5382 | } | |
5383 | ||
5384 | Standard_Boolean toCreate = (aCommand == "create"); | |
5385 | Standard_Boolean toClone = (aCommand == "clone"); | |
5386 | TCollection_AsciiString aPlane (theArgVec[2]); | |
5387 | ||
5388 | if (toCreate) | |
5389 | { | |
5390 | if (aRegPlanes.IsBound (aPlane)) | |
5391 | { | |
5392 | theDi << theArgVec[0] << ": plane name is in use.\n"; | |
5393 | return 1; | |
5394 | } | |
5395 | ||
5396 | aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane()); | |
5397 | } | |
5398 | else if (toClone) // toClone | |
5399 | { | |
5400 | if (!aRegPlanes.IsBound (aPlane)) | |
5401 | { | |
5402 | theDi << theArgVec[0] << ": no such plane.\n"; | |
5403 | return 1; | |
5404 | } | |
5405 | ||
5406 | if (theArgsNb < 4) | |
5407 | { | |
5408 | theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n"; | |
5409 | return 1; | |
5410 | } | |
5411 | ||
5412 | TCollection_AsciiString aClone (theArgVec[3]); | |
5413 | if (aRegPlanes.IsBound (aClone)) | |
5414 | { | |
5415 | theDi << theArgVec[0] << ": plane name is in use.\n"; | |
5416 | return 1; | |
5417 | } | |
5418 | ||
5419 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
5420 | ||
5421 | aRegPlanes.Bind (aClone, aClipPlane->Clone()); | |
5422 | } | |
5423 | else// toDelete | |
5424 | { | |
5425 | if (!aRegPlanes.IsBound (aPlane)) | |
5426 | { | |
5427 | theDi << theArgVec[0] << ": no such plane.\n"; | |
5428 | return 1; | |
5429 | } | |
5430 | ||
5431 | Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane); | |
5432 | aRegPlanes.UnBind (aPlane); | |
5433 | ||
5434 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS()); | |
5435 | for (; anIObjIt.More(); anIObjIt.Next()) | |
5436 | { | |
5437 | Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1()); | |
5438 | aPrs->RemoveClipPlane(aClipPlane); | |
5439 | } | |
5440 | ||
5441 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
5442 | for (; aViewIt.More(); aViewIt.Next()) | |
5443 | { | |
5444 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
5445 | aView->RemoveClipPlane(aClipPlane); | |
5446 | } | |
5447 | ||
5448 | ViewerTest::RedrawAllViews(); | |
5449 | } | |
5450 | ||
5451 | return 0; | |
5452 | } | |
5453 | ||
5454 | // set / unset plane command | |
5455 | if (aCommand == "set" || aCommand == "unset") | |
5456 | { | |
5457 | if (theArgsNb < 4) | |
5458 | { | |
5459 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5460 | return 1; | |
5461 | } | |
5462 | ||
5463 | Standard_Boolean toSet = (aCommand == "set"); | |
5464 | TCollection_AsciiString aPlane (theArgVec [2]); | |
5465 | if (!aRegPlanes.IsBound (aPlane)) | |
5466 | { | |
5467 | theDi << theArgVec[0] << ": no such plane.\n"; | |
5468 | return 1; | |
5469 | } | |
5470 | ||
5471 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
5472 | ||
5473 | TCollection_AsciiString aTarget (theArgVec [3]); | |
5474 | if (aTarget != "object" && aTarget != "view") | |
5475 | { | |
5476 | theDi << theArgVec[0] << ": invalid target.\n"; | |
5477 | return 1; | |
5478 | } | |
5479 | ||
5480 | if (aTarget == "object" || aTarget == "view") | |
5481 | { | |
5482 | if (theArgsNb < 5) | |
5483 | { | |
5484 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5485 | return 1; | |
5486 | } | |
5487 | ||
5488 | Standard_Boolean isObject = (aTarget == "object"); | |
5489 | ||
5490 | for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt) | |
5491 | { | |
5492 | TCollection_AsciiString anEntityName (theArgVec[anIt]); | |
5493 | if (isObject) // to object | |
5494 | { | |
5495 | if (!GetMapOfAIS().IsBound2 (anEntityName)) | |
5496 | { | |
5497 | theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n"; | |
5498 | continue; | |
5499 | } | |
5500 | ||
5501 | Handle(AIS_InteractiveObject) aIObj = | |
5502 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName)); | |
5503 | ||
5504 | if (toSet) | |
5505 | aIObj->AddClipPlane (aClipPlane); | |
5506 | else | |
5507 | aIObj->RemoveClipPlane (aClipPlane); | |
5508 | } | |
5509 | else // to view | |
5510 | { | |
5511 | if (!ViewerTest_myViews.IsBound1 (anEntityName)) | |
5512 | { | |
5513 | theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n"; | |
5514 | continue; | |
5515 | } | |
5516 | ||
5517 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName); | |
5518 | if (toSet) | |
5519 | aView->AddClipPlane (aClipPlane); | |
5520 | else | |
5521 | aView->RemoveClipPlane (aClipPlane); | |
5522 | } | |
5523 | } | |
5524 | ||
5525 | ViewerTest::RedrawAllViews(); | |
5526 | } | |
5527 | ||
5528 | return 0; | |
5529 | } | |
5530 | ||
5531 | // change plane command | |
5532 | if (aCommand == "change") | |
5533 | { | |
5534 | if (theArgsNb < 4) | |
5535 | { | |
5536 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5537 | return 1; | |
5538 | } | |
5539 | ||
5540 | TCollection_AsciiString aPlane (theArgVec [2]); | |
5541 | if (!aRegPlanes.IsBound (aPlane)) | |
5542 | { | |
5543 | theDi << theArgVec[0] << ": no such plane.\n"; | |
5544 | return 1; | |
5545 | } | |
5546 | ||
5547 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
5548 | ||
5549 | TCollection_AsciiString aChangeArg (theArgVec [3]); | |
5550 | if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation") | |
5551 | { | |
5552 | theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n"; | |
5553 | return 1; | |
5554 | } | |
5555 | ||
5556 | if (aChangeArg == "on" || aChangeArg == "off") // on / off | |
5557 | { | |
5558 | aClipPlane->SetOn (aChangeArg == "on"); | |
5559 | } | |
5560 | else if (aChangeArg == "equation") // change equation | |
5561 | { | |
5562 | if (theArgsNb < 8) | |
5563 | { | |
5564 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5565 | return 1; | |
5566 | } | |
5567 | ||
6b62b2da | 5568 | Standard_Real aCoeffA = Draw::Atof (theArgVec [4]); |
5569 | Standard_Real aCoeffB = Draw::Atof (theArgVec [5]); | |
5570 | Standard_Real aCoeffC = Draw::Atof (theArgVec [6]); | |
5571 | Standard_Real aCoeffD = Draw::Atof (theArgVec [7]); | |
4269bd1b | 5572 | aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD)); |
5573 | } | |
5574 | else if (aChangeArg == "capping") // change capping aspects | |
5575 | { | |
5576 | if (theArgsNb < 5) | |
5577 | { | |
5578 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5579 | return 1; | |
5580 | } | |
5581 | ||
5582 | TCollection_AsciiString aCappingArg (theArgVec [4]); | |
5583 | if (aCappingArg != "on" && aCappingArg != "off" && | |
5584 | aCappingArg != "color" && aCappingArg != "texname" && | |
5585 | aCappingArg != "texscale" && aCappingArg != "texorigin" && | |
5586 | aCappingArg != "texrotate" && aCappingArg != "hatch") | |
5587 | { | |
5588 | theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n"; | |
5589 | return 1; | |
5590 | } | |
5591 | ||
5592 | if (aCappingArg == "on" || aCappingArg == "off") // on / off capping | |
5593 | { | |
5594 | aClipPlane->SetCapping (aCappingArg == "on"); | |
5595 | } | |
5596 | else if (aCappingArg == "color") // color aspect for capping | |
5597 | { | |
5598 | if (theArgsNb < 8) | |
5599 | { | |
5600 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5601 | return 1; | |
5602 | } | |
5603 | ||
6b62b2da | 5604 | Standard_Real aRed = Draw::Atof (theArgVec [5]); |
5605 | Standard_Real aGrn = Draw::Atof (theArgVec [6]); | |
5606 | Standard_Real aBlu = Draw::Atof (theArgVec [7]); | |
4269bd1b | 5607 | |
5608 | Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); | |
8aeeca44 | 5609 | Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB); |
5610 | aMat.SetAmbientColor (aColor); | |
5611 | aMat.SetDiffuseColor (aColor); | |
4269bd1b | 5612 | aClipPlane->SetCappingMaterial (aMat); |
5613 | } | |
5614 | else if (aCappingArg == "texname") // texture name | |
5615 | { | |
5616 | if (theArgsNb < 6) | |
5617 | { | |
5618 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5619 | return 1; | |
5620 | } | |
5621 | ||
5622 | TCollection_AsciiString aTextureName (theArgVec [5]); | |
5623 | ||
5624 | Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); | |
5625 | if (!aTexture->IsDone ()) | |
5626 | { | |
5627 | aClipPlane->SetCappingTexture (NULL); | |
5628 | } | |
5629 | else | |
5630 | { | |
5631 | aTexture->EnableModulate(); | |
5632 | aTexture->EnableRepeat(); | |
5633 | aClipPlane->SetCappingTexture (aTexture); | |
5634 | } | |
5635 | } | |
5636 | else if (aCappingArg == "texscale") // texture scale | |
5637 | { | |
5638 | if (aClipPlane->CappingTexture().IsNull()) | |
5639 | { | |
5640 | theDi << theArgVec[0] << ": no texture is set.\n"; | |
5641 | return 1; | |
5642 | } | |
5643 | ||
5644 | if (theArgsNb < 7) | |
5645 | { | |
5646 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5647 | return 1; | |
5648 | } | |
5649 | ||
5650 | Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]); | |
5651 | Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]); | |
5652 | ||
5653 | aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); | |
5654 | } | |
5655 | else if (aCappingArg == "texorigin") // texture origin | |
5656 | { | |
5657 | if (aClipPlane->CappingTexture().IsNull()) | |
5658 | { | |
5659 | theDi << theArgVec[0] << ": no texture is set.\n"; | |
5660 | return 1; | |
5661 | } | |
5662 | ||
5663 | if (theArgsNb < 7) | |
5664 | { | |
5665 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5666 | return 1; | |
5667 | } | |
5668 | ||
5669 | Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]); | |
5670 | Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]); | |
5671 | ||
5672 | aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); | |
5673 | } | |
5674 | else if (aCappingArg == "texrotate") // texture rotation | |
5675 | { | |
5676 | if (aClipPlane->CappingTexture().IsNull()) | |
5677 | { | |
5678 | theDi << theArgVec[0] << ": no texture is set.\n"; | |
5679 | return 1; | |
5680 | } | |
5681 | ||
5682 | if (theArgsNb < 6) | |
5683 | { | |
5684 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5685 | return 1; | |
5686 | } | |
5687 | ||
5688 | Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]); | |
5689 | ||
5690 | aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot); | |
5691 | } | |
5692 | else if (aCappingArg == "hatch") // hatch style | |
5693 | { | |
5694 | if (theArgsNb < 6) | |
5695 | { | |
5696 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5697 | return 1; | |
5698 | } | |
5699 | ||
5700 | TCollection_AsciiString aHatchStr (theArgVec [5]); | |
5701 | if (aHatchStr == "on") | |
5702 | { | |
5703 | aClipPlane->SetCappingHatchOn(); | |
5704 | } | |
5705 | else if (aHatchStr == "off") | |
5706 | { | |
5707 | aClipPlane->SetCappingHatchOff(); | |
5708 | } | |
5709 | else | |
5710 | { | |
5711 | aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5])); | |
5712 | } | |
5713 | } | |
5714 | } | |
5715 | ||
5716 | ViewerTest::RedrawAllViews(); | |
5717 | ||
5718 | return 0; | |
5719 | } | |
5720 | ||
5721 | theDi << theArgVec[0] << ": invalid command. Type help for more information.\n"; | |
5722 | return 1; | |
5723 | } | |
5724 | ||
5725 | //=============================================================================================== | |
5726 | //function : VSetTextureMode | |
5727 | //purpose : | |
5728 | //=============================================================================================== | |
5729 | static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
5730 | { | |
5731 | if (theArgsNb < 3) | |
5732 | { | |
5733 | theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n"; | |
5734 | return 1; | |
5735 | } | |
5736 | ||
5737 | TCollection_AsciiString aViewName (theArgVec[1]); | |
5738 | if (!ViewerTest_myViews.IsBound1 (aViewName)) | |
5739 | { | |
5740 | theDi << theArgVec[0] << ": view is not found.\n"; | |
5741 | return 1; | |
5742 | } | |
5743 | ||
5744 | const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName); | |
5745 | switch (atoi (theArgVec[2])) | |
5746 | { | |
5747 | case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break; | |
5748 | case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break; | |
5749 | case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break; | |
5750 | default: | |
5751 | theDi << theArgVec[0] << ": invalid mode.\n"; | |
5752 | return 1; | |
5753 | } | |
5754 | ||
5755 | aView->Redraw(); | |
5756 | return 0; | |
5757 | } | |
5758 | ||
b5ac8292 | 5759 | //=============================================================================================== |
5760 | //function : VZRange | |
5761 | //purpose : | |
5762 | //=============================================================================================== | |
5763 | static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
5764 | { | |
197ac94e | 5765 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
5766 | ||
5767 | if (aCurrentView.IsNull()) | |
b5ac8292 | 5768 | { |
197ac94e | 5769 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
b5ac8292 | 5770 | return 1; |
5771 | } | |
5772 | ||
197ac94e | 5773 | Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera(); |
b5ac8292 | 5774 | |
5775 | if (theArgsNb < 2) | |
5776 | { | |
5777 | theDi << "ZNear: " << aCamera->ZNear() << "\n"; | |
5778 | theDi << "ZFar: " << aCamera->ZFar() << "\n"; | |
5779 | return 0; | |
5780 | } | |
5781 | ||
5782 | if (theArgsNb == 3) | |
5783 | { | |
6b62b2da | 5784 | Standard_Real aNewZNear = Draw::Atof (theArgVec[1]); |
5785 | Standard_Real aNewZFar = Draw::Atof (theArgVec[2]); | |
197ac94e | 5786 | |
5787 | if (aNewZNear >= aNewZFar) | |
5788 | { | |
5789 | std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n"; | |
5790 | return 1; | |
5791 | } | |
5792 | ||
5793 | if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0)) | |
5794 | { | |
5795 | std::cout << theArgVec[0] << ": invalid arguments: "; | |
5796 | std::cout << "znear, zfar should be positive for perspective camera.\n"; | |
5797 | return 1; | |
5798 | } | |
5799 | ||
5800 | aCamera->SetZRange (aNewZNear, aNewZFar); | |
b5ac8292 | 5801 | } |
5802 | else | |
5803 | { | |
197ac94e | 5804 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
b5ac8292 | 5805 | return 1; |
5806 | } | |
5807 | ||
197ac94e | 5808 | aCurrentView->Redraw(); |
5809 | ||
b5ac8292 | 5810 | return 0; |
5811 | } | |
5812 | ||
5813 | //=============================================================================================== | |
5814 | //function : VAutoZFit | |
5815 | //purpose : | |
5816 | //=============================================================================================== | |
5817 | static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
5818 | { | |
197ac94e | 5819 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
5820 | ||
5821 | if (aCurrentView.IsNull()) | |
b5ac8292 | 5822 | { |
197ac94e | 5823 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
b5ac8292 | 5824 | return 1; |
5825 | } | |
5826 | ||
6bc6a6fc | 5827 | Standard_Real aScale = aCurrentView->View()->AutoZFitScaleFactor(); |
197ac94e | 5828 | |
5829 | if (theArgsNb > 3) | |
b5ac8292 | 5830 | { |
197ac94e | 5831 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
5832 | return 1; | |
b5ac8292 | 5833 | } |
5834 | ||
197ac94e | 5835 | if (theArgsNb < 2) |
b5ac8292 | 5836 | { |
197ac94e | 5837 | theDi << "Auto z-fit mode: " << "\n" |
6bc6a6fc | 5838 | << "On: " << (aCurrentView->View()->AutoZFitMode() ? "enabled" : "disabled") << "\n" |
197ac94e | 5839 | << "Scale: " << aScale << "\n"; |
5840 | return 0; | |
b5ac8292 | 5841 | } |
197ac94e | 5842 | |
5843 | Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1; | |
5844 | ||
5845 | if (theArgsNb >= 3) | |
b5ac8292 | 5846 | { |
197ac94e | 5847 | aScale = Draw::Atoi (theArgVec[2]); |
b5ac8292 | 5848 | } |
5849 | ||
6bc6a6fc | 5850 | aCurrentView->View()->SetAutoZFitMode (isOn, aScale); |
5851 | aCurrentView->View()->AutoZFit(); | |
197ac94e | 5852 | aCurrentView->Redraw(); |
5853 | ||
b5ac8292 | 5854 | return 0; |
5855 | } | |
5856 | ||
6b62b2da | 5857 | //! Auxiliary function to print projection type |
5858 | inline const char* projTypeName (Graphic3d_Camera::Projection theProjType) | |
5859 | { | |
5860 | switch (theProjType) | |
5861 | { | |
5862 | case Graphic3d_Camera::Projection_Orthographic: return "orthographic"; | |
5863 | case Graphic3d_Camera::Projection_Perspective: return "perspective"; | |
5864 | case Graphic3d_Camera::Projection_Stereo: return "stereoscopic"; | |
5865 | case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye"; | |
5866 | case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye"; | |
5867 | } | |
5868 | return "UNKNOWN"; | |
5869 | } | |
5870 | ||
b5ac8292 | 5871 | //=============================================================================================== |
6b62b2da | 5872 | //function : VCamera |
b5ac8292 | 5873 | //purpose : |
5874 | //=============================================================================================== | |
6b62b2da | 5875 | static int VCamera (Draw_Interpretor& theDI, |
5876 | Standard_Integer theArgsNb, | |
5877 | const char** theArgVec) | |
b5ac8292 | 5878 | { |
6b62b2da | 5879 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
5880 | if (aView.IsNull()) | |
b5ac8292 | 5881 | { |
6b62b2da | 5882 | std::cout << "Error: no active view.\n"; |
b5ac8292 | 5883 | return 1; |
5884 | } | |
5885 | ||
6b62b2da | 5886 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); |
5887 | if (theArgsNb < 2) | |
b5ac8292 | 5888 | { |
6b62b2da | 5889 | theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n"; |
5890 | theDI << "FOVy: " << aCamera->FOVy() << "\n"; | |
5891 | theDI << "Distance: " << aCamera->Distance() << "\n"; | |
5892 | theDI << "IOD: " << aCamera->IOD() << "\n"; | |
5893 | theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n"; | |
5894 | theDI << "ZFocus: " << aCamera->ZFocus() << "\n"; | |
5895 | theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n"; | |
5896 | return 0; | |
b5ac8292 | 5897 | } |
5898 | ||
6b62b2da | 5899 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) |
b5ac8292 | 5900 | { |
6b62b2da | 5901 | Standard_CString anArg = theArgVec[anArgIter]; |
5902 | TCollection_AsciiString anArgCase (anArg); | |
5903 | anArgCase.LowerCase(); | |
5904 | if (anArgCase == "-proj" | |
5905 | || anArgCase == "-projection" | |
5906 | || anArgCase == "-projtype" | |
5907 | || anArgCase == "-projectiontype") | |
5908 | { | |
5909 | theDI << projTypeName (aCamera->ProjectionType()) << " "; | |
5910 | } | |
5911 | else if (anArgCase == "-ortho" | |
5912 | || anArgCase == "-orthographic") | |
b5ac8292 | 5913 | { |
5914 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic); | |
6b62b2da | 5915 | } |
5916 | else if (anArgCase == "-persp" | |
5917 | || anArgCase == "-perspective" | |
5918 | || anArgCase == "-perspmono" | |
5919 | || anArgCase == "-perspectivemono" | |
5920 | || anArgCase == "-mono") | |
b5ac8292 | 5921 | { |
5922 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); | |
5923 | } | |
6b62b2da | 5924 | else if (anArgCase == "-stereo" |
5925 | || anArgCase == "-stereoscopic" | |
5926 | || anArgCase == "-perspstereo" | |
5927 | || anArgCase == "-perspectivestereo") | |
5928 | { | |
5929 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
5930 | } | |
5931 | else if (anArgCase == "-left" | |
5932 | || anArgCase == "-lefteye" | |
5933 | || anArgCase == "-monoleft" | |
5934 | || anArgCase == "-monolefteye" | |
5935 | || anArgCase == "-perpsleft" | |
5936 | || anArgCase == "-perpslefteye") | |
b5ac8292 | 5937 | { |
5938 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye); | |
5939 | } | |
6b62b2da | 5940 | else if (anArgCase == "-right" |
5941 | || anArgCase == "-righteye" | |
5942 | || anArgCase == "-monoright" | |
5943 | || anArgCase == "-monorighteye" | |
5944 | || anArgCase == "-perpsright") | |
b5ac8292 | 5945 | { |
5946 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye); | |
5947 | } | |
6b62b2da | 5948 | else if (anArgCase == "-dist" |
5949 | || anArgCase == "-distance") | |
b5ac8292 | 5950 | { |
6b62b2da | 5951 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
5952 | if (anArgValue != NULL | |
5953 | && *anArgValue != '-') | |
5954 | { | |
5955 | ++anArgIter; | |
5956 | aCamera->SetDistance (Draw::Atof (anArgValue)); | |
5957 | continue; | |
5958 | } | |
5959 | theDI << aCamera->Distance() << " "; | |
b5ac8292 | 5960 | } |
6b62b2da | 5961 | else if (anArgCase == "-iod") |
b5ac8292 | 5962 | { |
6b62b2da | 5963 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
5964 | if (anArgValue != NULL | |
5965 | && *anArgValue != '-') | |
5966 | { | |
5967 | ++anArgIter; | |
5968 | aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue)); | |
5969 | continue; | |
5970 | } | |
5971 | theDI << aCamera->IOD() << " "; | |
b5ac8292 | 5972 | } |
6b62b2da | 5973 | else if (anArgCase == "-iodtype") |
b5ac8292 | 5974 | { |
6b62b2da | 5975 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
5976 | TCollection_AsciiString anValueCase (anArgValue); | |
5977 | anValueCase.LowerCase(); | |
5978 | if (anValueCase == "abs" | |
5979 | || anValueCase == "absolute") | |
5980 | { | |
5981 | ++anArgIter; | |
5982 | aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD()); | |
5983 | continue; | |
5984 | } | |
5985 | else if (anValueCase == "rel" | |
5986 | || anValueCase == "relative") | |
5987 | { | |
5988 | ++anArgIter; | |
5989 | aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD()); | |
5990 | continue; | |
5991 | } | |
5992 | else if (*anArgValue != '-') | |
5993 | { | |
5994 | std::cout << "Error: unknown IOD type '" << anArgValue << "'\n"; | |
5995 | return 1; | |
5996 | } | |
5997 | switch (aCamera->GetIODType()) | |
5998 | { | |
5999 | case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break; | |
6000 | case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break; | |
6001 | } | |
b5ac8292 | 6002 | } |
6b62b2da | 6003 | else if (anArgCase == "-zfocus") |
b5ac8292 | 6004 | { |
6b62b2da | 6005 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
6006 | if (anArgValue != NULL | |
6007 | && *anArgValue != '-') | |
6008 | { | |
6009 | ++anArgIter; | |
6010 | aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue)); | |
6011 | continue; | |
6012 | } | |
6013 | theDI << aCamera->ZFocus() << " "; | |
b5ac8292 | 6014 | } |
6b62b2da | 6015 | else if (anArgCase == "-zfocustype") |
b5ac8292 | 6016 | { |
6b62b2da | 6017 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
6018 | TCollection_AsciiString anValueCase (anArgValue); | |
6019 | anValueCase.LowerCase(); | |
6020 | if (anValueCase == "abs" | |
6021 | || anValueCase == "absolute") | |
6022 | { | |
6023 | ++anArgIter; | |
6024 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus()); | |
6025 | continue; | |
6026 | } | |
6027 | else if (anValueCase == "rel" | |
6028 | || anValueCase == "relative") | |
6029 | { | |
6030 | ++anArgIter; | |
6031 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus()); | |
6032 | continue; | |
6033 | } | |
6034 | else if (*anArgValue != '-') | |
6035 | { | |
6036 | std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n"; | |
6037 | return 1; | |
6038 | } | |
6039 | switch (aCamera->ZFocusType()) | |
6040 | { | |
6041 | case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break; | |
6042 | case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break; | |
6043 | } | |
6044 | } | |
6045 | else if (anArgCase == "-fov" | |
6046 | || anArgCase == "-fovy") | |
b5ac8292 | 6047 | { |
6b62b2da | 6048 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
6049 | if (anArgValue != NULL | |
6050 | && *anArgValue != '-') | |
6051 | { | |
6052 | ++anArgIter; | |
6053 | aCamera->SetFOVy (Draw::Atof (anArgValue)); | |
6054 | continue; | |
6055 | } | |
6056 | theDI << aCamera->FOVy() << " "; | |
b5ac8292 | 6057 | } |
6058 | else | |
6059 | { | |
6b62b2da | 6060 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
b5ac8292 | 6061 | return 1; |
6062 | } | |
6063 | } | |
b5ac8292 | 6064 | |
6b62b2da | 6065 | aView->View()->AutoZFit(); |
6066 | aView->Redraw(); | |
b5ac8292 | 6067 | |
6068 | return 0; | |
6069 | } | |
6070 | ||
6071 | //============================================================================== | |
6072 | //function : VStereo | |
6073 | //purpose : | |
6074 | //============================================================================== | |
6075 | ||
6076 | static int VStereo (Draw_Interpretor& theDI, | |
6077 | Standard_Integer theArgNb, | |
6078 | const char** theArgVec) | |
6079 | { | |
6080 | if (theArgNb < 2) | |
6081 | { | |
6082 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6083 | if (aView.IsNull()) | |
6084 | { | |
6085 | std::cerr << "No active view. Please call vinit.\n"; | |
6086 | return 0; | |
6087 | } | |
6088 | ||
6089 | Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo; | |
6090 | theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n"; | |
6091 | return 0; | |
6092 | } | |
6093 | ||
6094 | ViewerTest_myDefaultCaps.contextStereo = Draw::Atoi (theArgVec[1]) != 0; | |
6095 | return 0; | |
6096 | } | |
6097 | ||
392ac980 | 6098 | //=============================================================================================== |
6099 | //function : VDefaults | |
6100 | //purpose : | |
6101 | //=============================================================================================== | |
6102 | static int VDefaults (Draw_Interpretor& theDi, | |
6103 | Standard_Integer theArgsNb, | |
6104 | const char** theArgVec) | |
6105 | { | |
6106 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
6107 | if (aCtx.IsNull()) | |
6108 | { | |
6109 | std::cerr << "No active viewer!\n"; | |
6110 | return 1; | |
6111 | } | |
6112 | ||
6113 | Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer(); | |
6114 | if (theArgsNb < 2) | |
6115 | { | |
6116 | if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE) | |
6117 | { | |
6118 | theDi << "DeflType: relative\n" | |
6119 | << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n"; | |
6120 | } | |
6121 | else | |
6122 | { | |
6123 | theDi << "DeflType: absolute\n" | |
6124 | << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n"; | |
6125 | } | |
6126 | theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n"; | |
6127 | return 0; | |
6128 | } | |
6129 | ||
6130 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
6131 | { | |
6132 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
6133 | TCollection_AsciiString aKey, aValue; | |
1d7ca641 | 6134 | if (!ViewerTest::SplitParameter (anArg, aKey, aValue) |
392ac980 | 6135 | || aValue.IsEmpty()) |
6136 | { | |
6137 | std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n"; | |
6138 | return 1; | |
6139 | } | |
6140 | ||
6141 | aKey.UpperCase(); | |
6142 | if (aKey == "ABSDEFL" | |
6143 | || aKey == "ABSOLUTEDEFLECTION" | |
6144 | || aKey == "DEFL" | |
6145 | || aKey == "DEFLECTION") | |
6146 | { | |
6147 | aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE); | |
6148 | aDefParams->SetMaximalChordialDeviation (aValue.RealValue()); | |
6149 | } | |
6150 | else if (aKey == "RELDEFL" | |
6151 | || aKey == "RELATIVEDEFLECTION" | |
6152 | || aKey == "DEVCOEFF" | |
6153 | || aKey == "DEVIATIONCOEFF" | |
6154 | || aKey == "DEVIATIONCOEFFICIENT") | |
6155 | { | |
6156 | aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE); | |
6157 | aDefParams->SetDeviationCoefficient (aValue.RealValue()); | |
6158 | } | |
6159 | else if (aKey == "ANGDEFL" | |
6160 | || aKey == "ANGULARDEFL" | |
6161 | || aKey == "ANGULARDEFLECTION") | |
6162 | { | |
6163 | // currently HLRDeviationAngle is used instead of DeviationAngle in most places | |
6164 | aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0); | |
6165 | } | |
6166 | else | |
6167 | { | |
6168 | std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n"; | |
6169 | } | |
6170 | } | |
6171 | ||
6172 | return 0; | |
6173 | } | |
6174 | ||
12381341 | 6175 | //! Auxiliary method |
6176 | inline void addLight (const Handle(V3d_Light)& theLightNew, | |
6177 | const Standard_Boolean theIsGlobal) | |
6178 | { | |
6179 | if (theLightNew.IsNull()) | |
6180 | { | |
6181 | return; | |
6182 | } | |
6183 | ||
6184 | if (theIsGlobal) | |
6185 | { | |
6186 | ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew); | |
6187 | } | |
6188 | else | |
6189 | { | |
6190 | ViewerTest::CurrentView()->SetLightOn (theLightNew); | |
6191 | } | |
6192 | } | |
6193 | ||
6194 | //! Auxiliary method | |
6195 | inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext) | |
6196 | { | |
6197 | TCollection_AsciiString anArgNextCase (theArgNext); | |
6198 | anArgNextCase.UpperCase(); | |
6199 | if (anArgNextCase.Length() > 5 | |
6200 | && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT")) | |
6201 | { | |
6202 | return theArgNext.SubString (6, theArgNext.Length()).IntegerValue(); | |
6203 | } | |
6204 | else | |
6205 | { | |
6206 | return theArgNext.IntegerValue(); | |
6207 | } | |
6208 | } | |
6209 | ||
6210 | //=============================================================================================== | |
6211 | //function : VLight | |
6212 | //purpose : | |
6213 | //=============================================================================================== | |
6214 | static int VLight (Draw_Interpretor& theDi, | |
6215 | Standard_Integer theArgsNb, | |
6216 | const char** theArgVec) | |
6217 | { | |
6218 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6219 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
6220 | if (aView.IsNull() | |
6221 | || aViewer.IsNull()) | |
6222 | { | |
6223 | std::cerr << "No active viewer!\n"; | |
6224 | return 1; | |
6225 | } | |
6226 | ||
6227 | Standard_Real anXYZ[3]; | |
6228 | Quantity_Coefficient anAtten[2]; | |
6229 | if (theArgsNb < 2) | |
6230 | { | |
6231 | // print lights info | |
6232 | Standard_Integer aLightId = 0; | |
6233 | for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId) | |
6234 | { | |
6235 | Handle(V3d_Light) aLight = aView->ActiveLight(); | |
6236 | const Quantity_Color aColor = aLight->Color(); | |
6237 | theDi << "Light" << aLightId << "\n"; | |
6238 | switch (aLight->Type()) | |
6239 | { | |
6240 | case V3d_AMBIENT: | |
6241 | { | |
6242 | theDi << " Type: Ambient\n"; | |
6243 | break; | |
6244 | } | |
6245 | case V3d_DIRECTIONAL: | |
6246 | { | |
6247 | Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight); | |
6248 | theDi << " Type: Directional\n"; | |
6249 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
6250 | if (!aLightDir.IsNull()) | |
6251 | { | |
6252 | aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]); | |
6253 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
6254 | aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); | |
6255 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
6256 | } | |
6257 | break; | |
6258 | } | |
6259 | case V3d_POSITIONAL: | |
6260 | { | |
6261 | Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight); | |
6262 | theDi << " Type: Positional\n"; | |
6263 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
6264 | if (!aLightPos.IsNull()) | |
6265 | { | |
6266 | aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]); | |
6267 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
6268 | aLightPos->Attenuation (anAtten[0], anAtten[1]); | |
6269 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; | |
6270 | } | |
6271 | break; | |
6272 | } | |
6273 | case V3d_SPOT: | |
6274 | { | |
6275 | Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight); | |
6276 | theDi << " Type: Spot\n"; | |
6277 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
6278 | if (!aLightSpot.IsNull()) | |
6279 | { | |
6280 | aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]); | |
6281 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
6282 | aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); | |
6283 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
6284 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); | |
6285 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; | |
6286 | theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n"; | |
6287 | theDi << " Exponent: " << aLightSpot->Concentration() << "\n"; | |
6288 | } | |
6289 | break; | |
6290 | } | |
6291 | default: | |
6292 | { | |
6293 | theDi << " Type: UNKNOWN\n"; | |
6294 | break; | |
6295 | } | |
6296 | } | |
6297 | theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n"; | |
6298 | } | |
6299 | } | |
6300 | ||
6301 | Handle(V3d_Light) aLightNew; | |
6302 | Handle(V3d_Light) aLightOld; | |
6303 | Standard_Boolean isGlobal = Standard_True; | |
6304 | Standard_Boolean toCreate = Standard_False; | |
6305 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
6306 | { | |
6307 | Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew; | |
6308 | Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr); | |
6309 | Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr); | |
6310 | Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr); | |
6311 | Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr); | |
6312 | ||
6313 | TCollection_AsciiString aName, aValue; | |
6314 | const TCollection_AsciiString anArg (theArgVec[anArgIt]); | |
6315 | TCollection_AsciiString anArgCase (anArg); | |
6316 | anArgCase.UpperCase(); | |
6317 | if (anArgCase.IsEqual ("NEW") | |
6318 | || anArgCase.IsEqual ("ADD") | |
6319 | || anArgCase.IsEqual ("CREATE")) | |
6320 | { | |
6321 | toCreate = Standard_True; | |
6322 | } | |
6323 | else if (anArgCase.IsEqual ("GLOB") | |
6324 | || anArgCase.IsEqual ("GLOBAL")) | |
6325 | { | |
6326 | isGlobal = Standard_True; | |
6327 | } | |
6328 | else if (anArgCase.IsEqual ("LOC") | |
6329 | || anArgCase.IsEqual ("LOCAL")) | |
6330 | { | |
6331 | isGlobal = Standard_False; | |
6332 | } | |
4fe9ad57 | 6333 | else if (anArgCase.IsEqual ("DEF") |
6334 | || anArgCase.IsEqual ("DEFAULTS")) | |
6335 | { | |
6336 | toCreate = Standard_False; | |
6337 | aViewer->SetDefaultLights(); | |
6338 | } | |
6339 | else if (anArgCase.IsEqual ("CLR") | |
6340 | || anArgCase.IsEqual ("CLEAR")) | |
6341 | { | |
6342 | toCreate = Standard_False; | |
6343 | aView->InitActiveLights(); | |
6344 | while (aView->MoreActiveLights()) | |
6345 | { | |
6346 | aViewer->DelLight (aView->ActiveLight()); | |
6347 | aView->InitActiveLights(); | |
6348 | } | |
6349 | } | |
12381341 | 6350 | else if (anArgCase.IsEqual ("AMB") |
6351 | || anArgCase.IsEqual ("AMBIENT") | |
6352 | || anArgCase.IsEqual ("AMBLIGHT")) | |
6353 | { | |
6354 | addLight (aLightNew, isGlobal); | |
6355 | if (!toCreate) | |
6356 | { | |
6357 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6358 | return 1; | |
6359 | } | |
6360 | toCreate = Standard_False; | |
6361 | aLightNew = new V3d_AmbientLight (aViewer); | |
6362 | } | |
6363 | else if (anArgCase.IsEqual ("DIRECTIONAL") | |
6364 | || anArgCase.IsEqual ("DIRLIGHT")) | |
6365 | { | |
6366 | addLight (aLightNew, isGlobal); | |
6367 | if (!toCreate) | |
6368 | { | |
6369 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6370 | return 1; | |
6371 | } | |
6372 | toCreate = Standard_False; | |
6373 | aLightNew = new V3d_DirectionalLight (aViewer); | |
6374 | } | |
6375 | else if (anArgCase.IsEqual ("SPOT") | |
6376 | || anArgCase.IsEqual ("SPOTLIGHT")) | |
6377 | { | |
6378 | addLight (aLightNew, isGlobal); | |
6379 | if (!toCreate) | |
6380 | { | |
6381 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6382 | return 1; | |
6383 | } | |
6384 | toCreate = Standard_False; | |
6385 | aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0); | |
6386 | } | |
6387 | else if (anArgCase.IsEqual ("POSLIGHT") | |
6388 | || anArgCase.IsEqual ("POSITIONAL")) | |
6389 | { | |
6390 | addLight (aLightNew, isGlobal); | |
6391 | if (!toCreate) | |
6392 | { | |
6393 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6394 | return 1; | |
6395 | } | |
6396 | toCreate = Standard_False; | |
6397 | aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0); | |
6398 | } | |
6399 | else if (anArgCase.IsEqual ("CHANGE")) | |
6400 | { | |
6401 | addLight (aLightNew, isGlobal); | |
6402 | aLightNew.Nullify(); | |
6403 | if (++anArgIt >= theArgsNb) | |
6404 | { | |
6405 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6406 | return 1; | |
6407 | } | |
6408 | ||
6409 | const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]); | |
6410 | Standard_Integer aLightIt = 0; | |
6411 | for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt) | |
6412 | { | |
6413 | if (aLightIt == aLightId) | |
6414 | { | |
6415 | aLightOld = aView->ActiveLight(); | |
6416 | break; | |
6417 | } | |
6418 | } | |
6419 | ||
6420 | if (aLightOld.IsNull()) | |
6421 | { | |
6422 | std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n"; | |
6423 | return 1; | |
6424 | } | |
6425 | } | |
6426 | else if (anArgCase.IsEqual ("DEL") | |
6427 | || anArgCase.IsEqual ("DELETE")) | |
6428 | { | |
6429 | Handle(V3d_Light) aLightDel; | |
6430 | if (++anArgIt >= theArgsNb) | |
6431 | { | |
6432 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6433 | return 1; | |
6434 | } | |
6435 | ||
6436 | const TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
6437 | const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]); | |
6438 | Standard_Integer aLightIt = 0; | |
6439 | for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt) | |
6440 | { | |
6441 | aLightDel = aView->ActiveLight(); | |
6442 | if (aLightIt == aLightDelId) | |
6443 | { | |
6444 | break; | |
6445 | } | |
6446 | } | |
6447 | if (!aLightDel.IsNull()) | |
6448 | { | |
6449 | aViewer->DelLight (aLightDel); | |
6450 | } | |
6451 | } | |
6452 | else if (anArgCase.IsEqual ("COLOR") | |
6453 | || anArgCase.IsEqual ("COLOUR")) | |
6454 | { | |
6455 | if (++anArgIt >= theArgsNb) | |
6456 | { | |
6457 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6458 | return 1; | |
6459 | } | |
6460 | ||
6461 | TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
6462 | anArgNext.UpperCase(); | |
6463 | const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString()); | |
6464 | if (!aLightCurr.IsNull()) | |
6465 | { | |
6466 | aLightCurr->SetColor (aColor); | |
6467 | } | |
6468 | } | |
6469 | else if (anArgCase.IsEqual ("POS") | |
6470 | || anArgCase.IsEqual ("POSITION")) | |
6471 | { | |
6472 | if ((anArgIt + 3) >= theArgsNb) | |
6473 | { | |
6474 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6475 | return 1; | |
6476 | } | |
6477 | ||
6478 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
6479 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
6480 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
6481 | if (!aLightDir.IsNull()) | |
6482 | { | |
6483 | aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); | |
6484 | } | |
6485 | else if (!aLightPos.IsNull()) | |
6486 | { | |
6487 | aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); | |
6488 | } | |
6489 | else if (!aLightSpot.IsNull()) | |
6490 | { | |
6491 | aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); | |
6492 | } | |
6493 | else | |
6494 | { | |
6495 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6496 | return 1; | |
6497 | } | |
6498 | } | |
6499 | else if (anArgCase.IsEqual ("DIR") | |
6500 | || anArgCase.IsEqual ("DIRECTION")) | |
6501 | { | |
6502 | if ((anArgIt + 3) >= theArgsNb) | |
6503 | { | |
6504 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6505 | return 1; | |
6506 | } | |
6507 | ||
6508 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
6509 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
6510 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
6511 | if (!aLightDir.IsNull()) | |
6512 | { | |
6513 | aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]); | |
6514 | } | |
6515 | else if (!aLightSpot.IsNull()) | |
6516 | { | |
6517 | aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]); | |
6518 | } | |
6519 | else | |
6520 | { | |
6521 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6522 | return 1; | |
6523 | } | |
6524 | } | |
4fe9ad57 | 6525 | else if (anArgCase.IsEqual ("ANG") |
6526 | || anArgCase.IsEqual ("ANGLE")) | |
6527 | { | |
6528 | if (++anArgIt >= theArgsNb) | |
6529 | { | |
6530 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6531 | return 1; | |
6532 | } | |
6533 | ||
6534 | Standard_Real anAngle = Atof (theArgVec[anArgIt]); | |
6535 | ||
6536 | if (!aLightSpot.IsNull()) | |
6537 | { | |
6538 | aLightSpot->SetAngle (anAngle / 180.0 * M_PI); | |
6539 | } | |
6540 | } | |
12381341 | 6541 | else if (anArgCase.IsEqual ("CONSTATTEN") |
6542 | || anArgCase.IsEqual ("CONSTATTENUATION")) | |
6543 | { | |
6544 | if (++anArgIt >= theArgsNb) | |
6545 | { | |
6546 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6547 | return 1; | |
6548 | } | |
6549 | ||
6550 | if (!aLightPos.IsNull()) | |
6551 | { | |
6552 | aLightPos->Attenuation (anAtten[0], anAtten[1]); | |
6553 | anAtten[0] = Atof (theArgVec[anArgIt]); | |
6554 | aLightPos->SetAttenuation (anAtten[0], anAtten[1]); | |
6555 | } | |
6556 | else if (!aLightSpot.IsNull()) | |
6557 | { | |
6558 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); | |
6559 | anAtten[0] = Atof (theArgVec[anArgIt]); | |
6560 | aLightSpot->SetAttenuation (anAtten[0], anAtten[1]); | |
6561 | } | |
6562 | else | |
6563 | { | |
6564 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6565 | return 1; | |
6566 | } | |
6567 | } | |
6568 | else if (anArgCase.IsEqual ("LINATTEN") | |
6569 | || anArgCase.IsEqual ("LINEARATTEN") | |
6570 | || anArgCase.IsEqual ("LINEARATTENUATION")) | |
6571 | { | |
6572 | if (++anArgIt >= theArgsNb) | |
6573 | { | |
6574 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6575 | return 1; | |
6576 | } | |
6577 | ||
6578 | if (!aLightPos.IsNull()) | |
6579 | { | |
6580 | aLightPos->Attenuation (anAtten[0], anAtten[1]); | |
6581 | anAtten[1] = Atof (theArgVec[anArgIt]); | |
6582 | aLightPos->SetAttenuation (anAtten[0], anAtten[1]); | |
6583 | } | |
6584 | else if (!aLightSpot.IsNull()) | |
6585 | { | |
6586 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); | |
6587 | anAtten[1] = Atof (theArgVec[anArgIt]); | |
6588 | aLightSpot->SetAttenuation (anAtten[0], anAtten[1]); | |
6589 | } | |
6590 | else | |
6591 | { | |
6592 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6593 | return 1; | |
6594 | } | |
6595 | } | |
6596 | else if (anArgCase.IsEqual ("EXP") | |
6597 | || anArgCase.IsEqual ("EXPONENT") | |
6598 | || anArgCase.IsEqual ("SPOTEXP") | |
6599 | || anArgCase.IsEqual ("SPOTEXPONENT")) | |
6600 | { | |
6601 | if (++anArgIt >= theArgsNb) | |
6602 | { | |
6603 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6604 | return 1; | |
6605 | } | |
6606 | ||
6607 | if (!aLightSpot.IsNull()) | |
6608 | { | |
6609 | aLightSpot->SetConcentration (Atof (theArgVec[anArgIt])); | |
6610 | } | |
6611 | else | |
6612 | { | |
6613 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6614 | return 1; | |
6615 | } | |
6616 | } | |
6617 | else if (anArgCase.IsEqual ("HEAD") | |
6618 | || anArgCase.IsEqual ("HEADLIGHT")) | |
6619 | { | |
6620 | if (++anArgIt >= theArgsNb) | |
6621 | { | |
6622 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6623 | return 1; | |
6624 | } | |
6625 | ||
6626 | if (aLightAmb.IsNull() | |
6627 | && !aLightCurr.IsNull()) | |
6628 | { | |
6629 | aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0); | |
6630 | } | |
6631 | else | |
6632 | { | |
6633 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
6634 | return 1; | |
6635 | } | |
6636 | } | |
6637 | else | |
6638 | { | |
6639 | std::cerr << "Warning: unknown argument '" << anArg << "'\n"; | |
6640 | } | |
6641 | } | |
6642 | ||
6643 | addLight (aLightNew, isGlobal); | |
6644 | aViewer->UpdateLights(); | |
6645 | ||
6646 | return 0; | |
6647 | } | |
6648 | ||
e276548b | 6649 | //======================================================================= |
bc8c79bb | 6650 | //function : VRenderParams |
6651 | //purpose : Enables/disables rendering features | |
e276548b | 6652 | //======================================================================= |
6653 | ||
bc8c79bb | 6654 | static Standard_Integer VRenderParams (Draw_Interpretor& theDI, |
6655 | Standard_Integer theArgNb, | |
6656 | const char** theArgVec) | |
e276548b | 6657 | { |
7ae4a307 | 6658 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
6659 | if (aView.IsNull()) | |
e276548b | 6660 | { |
bc8c79bb | 6661 | std::cerr << "Error: no active viewer!\n"; |
e276548b | 6662 | return 1; |
6663 | } | |
bc8c79bb | 6664 | |
6665 | Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); | |
6b62b2da | 6666 | TCollection_AsciiString aCmdName (theArgVec[0]); |
6667 | aCmdName.LowerCase(); | |
6668 | if (aCmdName == "vraytrace") | |
6669 | { | |
6670 | if (theArgNb == 1) | |
6671 | { | |
6672 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " "; | |
6673 | return 0; | |
6674 | } | |
6675 | else if (theArgNb == 2) | |
6676 | { | |
6677 | TCollection_AsciiString aValue (theArgVec[1]); | |
6678 | aValue.LowerCase(); | |
6679 | if (aValue == "on" | |
6680 | || aValue == "1") | |
6681 | { | |
6682 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
6683 | aView->Redraw(); | |
6684 | return 0; | |
6685 | } | |
6686 | else if (aValue == "off" | |
6687 | || aValue == "0") | |
6688 | { | |
6689 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
6690 | aView->Redraw(); | |
6691 | return 0; | |
6692 | } | |
6693 | else | |
6694 | { | |
6695 | std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n"; | |
6696 | return 1; | |
6697 | } | |
6698 | } | |
6699 | else | |
6700 | { | |
6701 | std::cout << "Error: wrong number of arguments\n"; | |
6702 | return 1; | |
6703 | } | |
6704 | } | |
bc8c79bb | 6705 | |
6706 | if (theArgNb < 2) | |
e276548b | 6707 | { |
bc8c79bb | 6708 | theDI << "renderMode: "; |
6709 | switch (aParams.Method) | |
6710 | { | |
6711 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
6712 | case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break; | |
6713 | } | |
6714 | theDI << "\n"; | |
8625ef7e | 6715 | theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n"; |
6716 | theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n"; | |
6717 | theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n"; | |
6718 | theDI << "rayDepth: " << aParams.RaytracingDepth << "\n"; | |
6719 | theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n"; | |
6720 | theDI << "shadingModel: "; | |
6721 | switch (aView->ShadingModel()) | |
6722 | { | |
6723 | case V3d_COLOR: theDI << "color"; break; | |
6724 | case V3d_FLAT: theDI << "flat"; break; | |
6725 | case V3d_GOURAUD: theDI << "gouraud"; break; | |
6726 | case V3d_PHONG: theDI << "phong"; break; | |
6727 | } | |
6728 | theDI << "\n"; | |
bc8c79bb | 6729 | return 0; |
e276548b | 6730 | } |
6731 | ||
bc8c79bb | 6732 | Standard_Boolean toPrint = Standard_False; |
8625ef7e | 6733 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
e276548b | 6734 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
6735 | { | |
bc8c79bb | 6736 | Standard_CString anArg (theArgVec[anArgIter]); |
6737 | TCollection_AsciiString aFlag (anArg); | |
6738 | aFlag.LowerCase(); | |
8625ef7e | 6739 | if (anUpdateTool.parseRedrawMode (aFlag)) |
6740 | { | |
6741 | continue; | |
6742 | } | |
6743 | else if (aFlag == "-echo" | |
6744 | || aFlag == "-print") | |
e276548b | 6745 | { |
bc8c79bb | 6746 | toPrint = Standard_True; |
8625ef7e | 6747 | anUpdateTool.Invalidate(); |
e276548b | 6748 | } |
bc8c79bb | 6749 | else if (aFlag == "-mode" |
6750 | || aFlag == "-rendermode" | |
6751 | || aFlag == "-render_mode") | |
e276548b | 6752 | { |
bc8c79bb | 6753 | if (toPrint) |
6754 | { | |
6755 | switch (aParams.Method) | |
6756 | { | |
6757 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
6758 | case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break; | |
6759 | } | |
6760 | continue; | |
6761 | } | |
e276548b | 6762 | else |
bc8c79bb | 6763 | { |
6764 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
6765 | return 1; | |
6766 | } | |
6767 | } | |
6768 | else if (aFlag == "-ray" | |
6769 | || aFlag == "-raytrace") | |
6770 | { | |
6771 | if (toPrint) | |
6772 | { | |
6773 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " "; | |
6774 | continue; | |
6775 | } | |
6776 | ||
6777 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
e276548b | 6778 | } |
bc8c79bb | 6779 | else if (aFlag == "-rast" |
6780 | || aFlag == "-raster" | |
6781 | || aFlag == "-rasterization") | |
e276548b | 6782 | { |
bc8c79bb | 6783 | if (toPrint) |
6784 | { | |
6785 | theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " "; | |
6786 | continue; | |
6787 | } | |
6788 | ||
6789 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
6790 | } | |
6791 | else if (aFlag == "-raydepth" | |
6792 | || aFlag == "-ray_depth") | |
6793 | { | |
6794 | if (toPrint) | |
6795 | { | |
6796 | theDI << aParams.RaytracingDepth << " "; | |
6797 | continue; | |
6798 | } | |
6799 | else if (++anArgIter >= theArgNb) | |
6800 | { | |
6801 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
6802 | return 1; | |
6803 | } | |
6804 | ||
6805 | const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]); | |
6806 | if (aDepth < 1 || aDepth > 10) | |
6807 | { | |
6808 | std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n"; | |
6809 | return 1; | |
6810 | } | |
e276548b | 6811 | else |
bc8c79bb | 6812 | { |
6813 | aParams.RaytracingDepth = aDepth; | |
6814 | } | |
6815 | } | |
6816 | else if (aFlag == "-shad" | |
6817 | || aFlag == "-shadows") | |
6818 | { | |
6819 | if (toPrint) | |
6820 | { | |
6821 | theDI << (aParams.IsShadowEnabled ? "on" : "off") << " "; | |
6822 | continue; | |
6823 | } | |
6824 | ||
6825 | Standard_Boolean toEnable = Standard_True; | |
6826 | if (++anArgIter < theArgNb | |
6827 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
6828 | { | |
6829 | --anArgIter; | |
6830 | } | |
6831 | aParams.IsShadowEnabled = toEnable; | |
6832 | } | |
6833 | else if (aFlag == "-refl" | |
6834 | || aFlag == "-reflections") | |
6835 | { | |
6836 | if (toPrint) | |
6837 | { | |
6838 | theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " "; | |
6839 | continue; | |
6840 | } | |
6841 | ||
6842 | Standard_Boolean toEnable = Standard_True; | |
6843 | if (++anArgIter < theArgNb | |
6844 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
6845 | { | |
6846 | --anArgIter; | |
6847 | } | |
6848 | aParams.IsReflectionEnabled = toEnable; | |
6849 | } | |
6850 | else if (aFlag == "-fsaa") | |
6851 | { | |
6852 | if (toPrint) | |
6853 | { | |
6854 | theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " "; | |
6855 | continue; | |
6856 | } | |
6857 | ||
6858 | Standard_Boolean toEnable = Standard_True; | |
6859 | if (++anArgIter < theArgNb | |
6860 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
6861 | { | |
6862 | --anArgIter; | |
6863 | } | |
6864 | aParams.IsAntialiasingEnabled = toEnable; | |
6865 | } | |
6866 | else if (aFlag == "-gleam") | |
6867 | { | |
6868 | if (toPrint) | |
6869 | { | |
6870 | theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " "; | |
6871 | continue; | |
6872 | } | |
6873 | ||
6874 | Standard_Boolean toEnable = Standard_True; | |
6875 | if (++anArgIter < theArgNb | |
6876 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
6877 | { | |
6878 | --anArgIter; | |
6879 | } | |
6880 | aParams.IsTransparentShadowEnabled = toEnable; | |
e276548b | 6881 | } |
8625ef7e | 6882 | else if (aFlag == "-shademodel" |
6883 | || aFlag == "-shadingmodel" | |
6884 | || aFlag == "-shading") | |
6885 | { | |
6886 | if (toPrint) | |
6887 | { | |
6888 | switch (aView->ShadingModel()) | |
6889 | { | |
6890 | case V3d_COLOR: theDI << "color "; break; | |
6891 | case V3d_FLAT: theDI << "flat "; break; | |
6892 | case V3d_GOURAUD: theDI << "gouraud "; break; | |
6893 | case V3d_PHONG: theDI << "phong "; break; | |
6894 | } | |
6895 | continue; | |
6896 | } | |
6897 | ||
6898 | if (++anArgIter >= theArgNb) | |
6899 | { | |
6900 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
6901 | } | |
6902 | ||
6903 | TCollection_AsciiString aMode (theArgVec[anArgIter]); | |
6904 | aMode.LowerCase(); | |
6905 | if (aMode == "color" | |
6906 | || aMode == "none") | |
6907 | { | |
6908 | aView->SetShadingModel (V3d_COLOR); | |
6909 | } | |
6910 | else if (aMode == "flat" | |
6911 | || aMode == "facet") | |
6912 | { | |
6913 | aView->SetShadingModel (V3d_FLAT); | |
6914 | } | |
6915 | else if (aMode == "gouraud" | |
6916 | || aMode == "vertex" | |
6917 | || aMode == "vert") | |
6918 | { | |
6919 | aView->SetShadingModel (V3d_GOURAUD); | |
6920 | } | |
6921 | else if (aMode == "phong" | |
6922 | || aMode == "fragment" | |
6923 | || aMode == "frag" | |
6924 | || aMode == "pixel") | |
6925 | { | |
6926 | aView->SetShadingModel (V3d_PHONG); | |
6927 | } | |
6928 | else | |
6929 | { | |
6930 | std::cout << "Error: unknown shading model '" << aMode << "'\n"; | |
6931 | return 1; | |
6932 | } | |
6933 | } | |
e276548b | 6934 | else |
6935 | { | |
bc8c79bb | 6936 | std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n"; |
6937 | return 1; | |
e276548b | 6938 | } |
6939 | } | |
e276548b | 6940 | return 0; |
6941 | } | |
6942 | ||
b7cd4ba7 | 6943 | //======================================================================= |
6944 | //function : VFrustumCulling | |
6945 | //purpose : enables/disables view volume's culling. | |
6946 | //======================================================================= | |
6947 | static int VFrustumCulling (Draw_Interpretor& theDI, | |
6948 | Standard_Integer theArgNb, | |
6949 | const char** theArgVec) | |
6950 | { | |
6951 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6952 | if (aView.IsNull()) | |
6953 | { | |
6954 | std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n"; | |
6955 | return 1; | |
6956 | } | |
6957 | ||
6958 | if (theArgNb < 2) | |
6959 | { | |
6960 | theDI << (aView->IsCullingEnabled() ? "on" : "off"); | |
6961 | return 0; | |
6962 | } | |
6963 | else if (theArgNb != 2) | |
6964 | { | |
6965 | std::cout << theArgVec[0] << " Syntax error: Specify the mode\n"; | |
6966 | return 1; | |
6967 | } | |
6968 | ||
6969 | TCollection_AsciiString aModeStr (theArgVec[1]); | |
6970 | aModeStr.LowerCase(); | |
6971 | Standard_Boolean toEnable = 0; | |
6972 | if (aModeStr == "on") | |
6973 | { | |
6974 | toEnable = 1; | |
6975 | } | |
6976 | else if (aModeStr == "off") | |
6977 | { | |
6978 | toEnable = 0; | |
6979 | } | |
6980 | else | |
6981 | { | |
6982 | toEnable = Draw::Atoi (theArgVec[1]) != 0; | |
6983 | } | |
6984 | ||
6985 | aView->SetFrustumCulling (toEnable); | |
6986 | aView->Redraw(); | |
6987 | return 0; | |
6988 | } | |
6989 | ||
c398b00e | 6990 | //======================================================================= |
6991 | //function : VHighlightSelected | |
6992 | //purpose : | |
6993 | //======================================================================= | |
6994 | static int VHighlightSelected (Draw_Interpretor& theDI, | |
6995 | Standard_Integer theArgNb, | |
6996 | const char** theArgVec) | |
6997 | { | |
6998 | if (ViewerTest::GetAISContext().IsNull()) | |
6999 | { | |
7000 | std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n"; | |
7001 | return 1; | |
7002 | } | |
7003 | ||
7004 | const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
7005 | ||
7006 | if (theArgNb < 2) | |
7007 | { | |
7008 | theDI << (aContext->ToHilightSelected() ? "on" : "off"); | |
7009 | return 0; | |
7010 | } | |
7011 | ||
7012 | if (theArgNb != 2) | |
7013 | { | |
7014 | std::cout << theArgVec[0] << " error : wrong number of parameters." | |
7015 | << "Type 'help" << theArgVec[0] << "' for more information."; | |
7016 | return 1; | |
7017 | } | |
7018 | ||
7019 | // Parse parameter | |
7020 | TCollection_AsciiString aMode (theArgVec[1]); | |
7021 | aMode.LowerCase(); | |
7022 | Standard_Boolean toEnable = Standard_False; | |
7023 | if (aMode.IsEqual ("on")) | |
7024 | { | |
7025 | toEnable = Standard_True; | |
7026 | } | |
7027 | else if (aMode.IsEqual ("off")) | |
7028 | { | |
7029 | toEnable = Standard_False; | |
7030 | } | |
7031 | else | |
7032 | { | |
7033 | toEnable = Draw::Atoi (theArgVec[1]) != 0; | |
7034 | } | |
7035 | ||
7036 | if (toEnable != aContext->ToHilightSelected()) | |
7037 | { | |
7038 | aContext->SetToHilightSelected (toEnable); | |
7039 | ||
7040 | // Move cursor to null position and back to process updating of detection | |
7041 | // and highlighting of selected object immediatly. | |
7042 | Standard_Integer aPixX = 0; | |
7043 | Standard_Integer aPixY = 0; | |
7044 | const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager(); | |
7045 | ||
7046 | anEventManager->GetCurrentPosition (aPixX, aPixY); | |
7047 | anEventManager->MoveTo (0, 0); | |
7048 | anEventManager->MoveTo (aPixX, aPixY); | |
7049 | } | |
7050 | ||
7051 | return 0; | |
7052 | } | |
7053 | ||
0717ddc1 | 7054 | //======================================================================= |
7055 | //function : VXRotate | |
7056 | //purpose : | |
7057 | //======================================================================= | |
7058 | static Standard_Integer VXRotate (Draw_Interpretor& di, | |
7059 | Standard_Integer argc, | |
7060 | const char ** argv) | |
7061 | { | |
7062 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
7063 | if (aContext.IsNull()) | |
7064 | { | |
7065 | di << argv[0] << "ERROR : use 'vinit' command before " << "\n"; | |
7066 | return 1; | |
7067 | } | |
7068 | ||
7069 | if (argc != 3) | |
7070 | { | |
7071 | di << "ERROR : Usage : " << argv[0] << " name angle" << "\n"; | |
7072 | return 1; | |
7073 | } | |
7074 | ||
7075 | TCollection_AsciiString aName (argv[1]); | |
7076 | Standard_Real anAngle = Draw::Atof (argv[2]); | |
7077 | ||
7078 | // find object | |
7079 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
7080 | Handle(AIS_InteractiveObject) anIObj; | |
7081 | if (!aMap.IsBound2 (aName) ) | |
7082 | { | |
7083 | di << "Use 'vdisplay' before" << "\n"; | |
7084 | return 1; | |
7085 | } | |
7086 | else | |
7087 | { | |
7088 | anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName)); | |
7089 | ||
7090 | gp_Trsf aTransform; | |
7091 | aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle); | |
7092 | aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart()); | |
7093 | ||
7094 | aContext->SetLocation (anIObj, aTransform); | |
7095 | aContext->UpdateCurrentViewer(); | |
7096 | } | |
7097 | ||
7098 | return 0; | |
7099 | } | |
7100 | ||
7fd59977 | 7101 | //======================================================================= |
7102 | //function : ViewerCommands | |
7103 | //purpose : | |
7104 | //======================================================================= | |
7105 | ||
7106 | void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) | |
7107 | { | |
7108 | ||
7109 | const char *group = "ZeViewer"; | |
18d715bd | 7110 | theCommands.Add("vinit", |
7111 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
7112 | "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" | |
7113 | #else | |
7114 | "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" | |
7115 | #endif | |
7116 | " - Creates new View window with specified name view_name.\n" | |
7117 | "By default the new view is created in the viewer and in" | |
7118 | " graphic driver shared with active view.\n" | |
7119 | " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n" | |
7120 | "If driverName isn't specified the driver will be shared with active view.\n" | |
7121 | "If viewerName isn't specified the viewer will be shared with active view.\n" | |
7122 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
7123 | " - display = HostName.DisplayNumber[:ScreenNumber] : if specified" | |
7124 | "is used in creation of graphic driver\n" | |
7125 | #endif | |
7126 | " - l, t: pixel position of left top corner of the window\n" | |
7127 | " - w,h: width and heigth of window respectively.\n" | |
7128 | "Additional commands for operations with views: vclose, vactivate, vviewlist.\n", | |
7fd59977 | 7129 | __FILE__,VInit,group); |
18d715bd | 7130 | theCommands.Add("vclose" , |
d0cc1cb7 | 7131 | "[view_id [keep_context=0|1]]\n" |
18d715bd | 7132 | "or vclose ALL - to remove all created views\n" |
7133 | " - removes view(viewer window) defined by its view_id.\n" | |
7134 | " - keep_context: by default 0; if 1 and the last view is deleted" | |
7135 | " the current context is not removed.", | |
7136 | __FILE__,VClose,group); | |
7137 | theCommands.Add("vactivate" , | |
7138 | "view_id" | |
7139 | " - activates view(viewer window) defined by its view_id", | |
7140 | __FILE__,VActivate,group); | |
7141 | theCommands.Add("vviewlist", | |
7142 | "vviewlist [format={tree, long}]" | |
7143 | " - prints current list of views per viewer and graphic_driver ID shared between viewers" | |
7144 | " - format: format of result output, if tree the output is a tree view;" | |
7145 | "otherwise it's a list of full view names. By default format = tree", | |
7146 | __FILE__,VViewList,group); | |
7fd59977 | 7147 | theCommands.Add("vhelp" , |
7148 | "vhelp : display help on the viewer commands", | |
7149 | __FILE__,VHelp,group); | |
7150 | theCommands.Add("vtop" , | |
44b8f2d6 | 7151 | "vtop or <T> : Top view" , |
7fd59977 | 7152 | __FILE__,VTop,group); |
44b8f2d6 | 7153 | theCommands.Add("vbottom" , |
7154 | "vbottom : Bottom view" , | |
7155 | __FILE__,VBottom,group); | |
7156 | theCommands.Add("vleft" , | |
7157 | "vleft : Left view" , | |
7158 | __FILE__,VLeft,group); | |
7159 | theCommands.Add("vright" , | |
7160 | "vright : Right view" , | |
7161 | __FILE__,VRight,group); | |
7fd59977 | 7162 | theCommands.Add("vaxo" , |
7163 | " vaxo or <A> : Axonometric view ", | |
7164 | __FILE__,VAxo,group); | |
44b8f2d6 | 7165 | theCommands.Add("vfront" , |
7166 | "vfront : Front view" , | |
7167 | __FILE__,VFront,group); | |
7168 | theCommands.Add("vback" , | |
7169 | "vback : Back view" , | |
7170 | __FILE__,VBack,group); | |
7fd59977 | 7171 | theCommands.Add("vpick" , |
7172 | "vpick : vpick X Y Z [shape subshape] ( all variables as string )", | |
7173 | VPick,group); | |
7174 | theCommands.Add("vfit" , | |
7175 | "vfit or <F> : vfit", | |
7176 | __FILE__,VFit,group); | |
6262a303 | 7177 | theCommands.Add ("vfitarea", |
7178 | "vfitarea x1 y1 x2 y2" | |
7179 | "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2" | |
7180 | "\n\t\t: Fit view to show area located between two points" | |
7181 | "\n\t\t: given in world 2D or 3D corrdinates.", | |
7182 | __FILE__, VFitArea, group); | |
197ac94e | 7183 | theCommands.Add ("vzfit", "vzfit [scale]\n" |
7184 | " Matches Z near, Z far view volume planes to the displayed objects.\n" | |
7185 | " \"scale\" - specifies factor to scale computed z range.\n", | |
7186 | __FILE__, VZFit, group); | |
7fd59977 | 7187 | theCommands.Add("vrepaint", |
7188 | "vrepaint : vrepaint, force redraw", | |
7189 | __FILE__,VRepaint,group); | |
7190 | theCommands.Add("vclear", | |
7191 | "vclear : vclear", | |
7192 | __FILE__,VClear,group); | |
7193 | theCommands.Add("vsetbg", | |
7194 | "vsetbg : vsetbg imagefile [filltype] : Load image as background", | |
7195 | __FILE__,VSetBg,group); | |
f8b2ed36 | 7196 | theCommands.Add("vsetbgmode", |
7197 | "vsetbgmode : vsetbgmode filltype : Change background image fill type", | |
7198 | __FILE__,VSetBgMode,group); | |
7fd59977 | 7199 | theCommands.Add("vsetgradientbg", |
f8b2ed36 | 7200 | "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background", |
7fd59977 | 7201 | __FILE__,VSetGradientBg,group); |
f8b2ed36 | 7202 | theCommands.Add("vsetgrbgmode", |
7203 | "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type", | |
7204 | __FILE__,VSetGradientBgMode,group); | |
7205 | theCommands.Add("vsetcolorbg", | |
7206 | "vsetcolorbg : vsetcolorbg r g b : Set background color", | |
7207 | __FILE__,VSetColorBg,group); | |
7fd59977 | 7208 | theCommands.Add("vscale", |
7209 | "vscale : vscale X Y Z", | |
7210 | __FILE__,VScale,group); | |
7211 | theCommands.Add("vzbufftrihedron", | |
7c8a8fcc | 7212 | "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper" |
7213 | " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]" | |
7214 | " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron", | |
7fd59977 | 7215 | __FILE__,VTestZBuffTrihedron,group); |
7216 | theCommands.Add("vrotate", | |
7217 | "vrotate : vrotate AX AY AZ [X Y Z]", | |
7218 | __FILE__,VRotate,group); | |
7219 | theCommands.Add("vzoom", | |
7220 | "vzoom : vzoom coef", | |
7221 | __FILE__,VZoom,group); | |
7222 | theCommands.Add("vpan", | |
7223 | "vpan : vpan dx dy", | |
7224 | __FILE__,VPan,group); | |
7225 | theCommands.Add("vexport", | |
5cedc27f K |
7226 | "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }" |
7227 | " : exports the view to a vector file of a given format" | |
7228 | " : notice that EMF format requires patched gl2ps", | |
7fd59977 | 7229 | __FILE__,VExport,group); |
7230 | theCommands.Add("vcolorscale", | |
7231 | "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale", | |
7232 | __FILE__,VColorScale,group); | |
7233 | theCommands.Add("vgraduatedtrihedron", | |
13a22457 | 7234 | "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]", |
7fd59977 | 7235 | __FILE__,VGraduatedTrihedron,group); |
7edf74fd | 7236 | theCommands.Add("vprintview" , |
b5ac8292 | 7237 | "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile", |
7edf74fd | 7238 | __FILE__,VPrintView,group); |
59f45b7c | 7239 | theCommands.Add("vzlayer", |
c5751993 | 7240 | "vzlayer add/del/get/settings/enable/disable [id]\n" |
7241 | " add - add new z layer to viewer and print its id\n" | |
7242 | " del - del z layer by its id\n" | |
7243 | " get - print sequence of z layers in increasing order of their overlay level\n" | |
7244 | " settings - print status of z layer settings\n" | |
7245 | " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n" | |
7246 | " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n" | |
7247 | " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n" | |
7248 | "\nWhere id is the layer identificator\n" | |
7249 | "\nExamples:\n" | |
7250 | " vzlayer add\n" | |
7251 | " vzlayer enable poffset 1\n" | |
7252 | " vzlayer disable depthtest 1\n" | |
7253 | " vzlayer del 1\n", | |
59f45b7c | 7254 | __FILE__,VZLayer,group); |
25289ec1 | 7255 | theCommands.Add("voverlaytext", |
7256 | "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]" | |
7257 | " : height - pixel height of the text (default=10.0)" | |
7258 | " : font_name - name of font (default=courier)" | |
7259 | " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) " | |
7260 | " : display_type = {normal/subtitle/decal/blend}, (default=normal) " | |
7261 | " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ", | |
7262 | __FILE__,VOverlayText,group); | |
20637bd2 | 7263 | theCommands.Add("vlayerline", |
7264 | "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]", | |
7265 | __FILE__,VLayerLine,group); | |
2bd4c032 | 7266 | theCommands.Add ("vgrid", |
7267 | "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]" | |
7268 | " : Mode - rectangular or circular" | |
7269 | " : Type - lines or points", | |
7270 | __FILE__, VGrid, group); | |
208e6839 | 7271 | theCommands.Add ("vfps", |
7272 | "vfps [framesNb=100] : estimate average frame rate for active view", | |
7273 | __FILE__, VFps, group); | |
58655684 | 7274 | theCommands.Add ("vgldebug", |
7275 | "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n" | |
7276 | " : this function is implemented only for Windows\n" | |
7277 | " : GL_ARB_debug_output extension should be exported by OpenGL driver!", | |
7278 | __FILE__, VGlDebug, group); | |
208e6839 | 7279 | theCommands.Add ("vvbo", |
58655684 | 7280 | "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects", |
208e6839 | 7281 | __FILE__, VVbo, group); |
b5ac8292 | 7282 | theCommands.Add ("vstereo", |
7283 | "\nvstereo [{0|1}] : turn stereo usage On/Off; affects only newly displayed objects", | |
7284 | __FILE__, VStereo, group); | |
a577aaab | 7285 | theCommands.Add ("vcaps", |
8625ef7e | 7286 | "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]" |
7287 | "\n\t\t: [-softMode {0|1}] [-noupdate|-update]" | |
7288 | "\n\t\t: Modify particular graphic driver options:" | |
7289 | "\n\t\t: FFP - use fixed-function pipeline instead of" | |
7290 | "\n\t\t: built-in GLSL programs" | |
7291 | "\n\t\t: VBO - use Vertex Buffer Object (copy vertex" | |
7292 | "\n\t\t: arrays to GPU memory)" | |
7293 | "\n\t\t: sprite - use textured sprites instead of bitmaps" | |
7294 | "\n\t\t: softMode - use software OpenGL implementation," | |
7295 | "\n\t\t: should be set BEFORE viewer creation" | |
7296 | "\n\t\t: Unlike vrenderparams, these parameters control alternative" | |
7297 | "\n\t\t: rendering paths producing the same visual result when" | |
7298 | "\n\t\t: possible." | |
7299 | "\n\t\t: Command is intended for testing old hardware compatibility.", | |
a577aaab | 7300 | __FILE__, VCaps, group); |
f0430952 | 7301 | theCommands.Add ("vmemgpu", |
7302 | "vmemgpu [f]: print system-dependent GPU memory information if available;" | |
7303 | " with f option returns free memory in bytes", | |
7304 | __FILE__, VMemGpu, group); | |
85e096c3 | 7305 | theCommands.Add ("vreadpixel", |
7306 | "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]" | |
7307 | " : Read pixel value for active view", | |
7308 | __FILE__, VReadPixel, group); | |
692613e5 | 7309 | theCommands.Add("diffimage", |
7310 | "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]", | |
7311 | __FILE__, VDiffImage, group); | |
4754e164 | 7312 | theCommands.Add ("vselect", |
7313 | "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n" | |
7314 | "- emulates different types of selection:\n" | |
7315 | "- 1) single click selection\n" | |
7316 | "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n" | |
7317 | "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n" | |
7318 | "- 4) any of these selections with shift button pressed", | |
7319 | __FILE__, VSelect, group); | |
7320 | theCommands.Add ("vmoveto", | |
7321 | "vmoveto x y" | |
7322 | "- emulates cursor movement to pixel postion (x,y)", | |
7323 | __FILE__, VMoveTo, group); | |
197ac94e | 7324 | theCommands.Add ("vviewparams", "vviewparams usage:\n" |
7325 | "- vviewparams\n" | |
7326 | "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n" | |
3dfe95cd | 7327 | " [-proj [x y z]] [-center x y] [-size sx]\n" |
197ac94e | 7328 | "- Gets or sets current view parameters.\n" |
7329 | "- If called without arguments, all view parameters are printed.\n" | |
7330 | "- The options are:\n" | |
3dfe95cd | 7331 | " -scale [s] : prints or sets viewport relative scale.\n" |
197ac94e | 7332 | " -eye [x y z] : prints or sets eye location.\n" |
7333 | " -at [x y z] : prints or sets center of look.\n" | |
7334 | " -up [x y z] : prints or sets direction of up vector.\n" | |
7335 | " -proj [x y z] : prints or sets direction of look.\n" | |
3dfe95cd | 7336 | " -center x y : sets location of center of the screen in pixels.\n" |
7337 | " -size [sx] : prints viewport projection width and height sizes\n" | |
7338 | " : or changes the size of its maximum dimension.\n", | |
197ac94e | 7339 | __FILE__, VViewParams, group); |
4754e164 | 7340 | theCommands.Add("vchangeselected", |
dc3fe572 | 7341 | "vchangeselected shape" |
4754e164 | 7342 | "- adds to shape to selection or remove one from it", |
7343 | __FILE__, VChangeSelected, group); | |
7344 | theCommands.Add("vzclipping", | |
7345 | "vzclipping [mode] [depth width]\n" | |
7346 | "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n" | |
7347 | "- gets or sets ZClipping mode, width and depth", | |
7348 | __FILE__,VZClipping,group); | |
7349 | theCommands.Add ("vnbselected", | |
7350 | "vnbselected", __FILE__, VNbSelected, group); | |
6b62b2da | 7351 | theCommands.Add ("vcamera", |
7352 | "vcamera [-ortho] [-projtype]" | |
7353 | "\n\t\t: [-persp]" | |
7354 | "\n\t\t: [-fovy [Angle]] [-distance [Distance]]" | |
7355 | "\n\t\t: [-stereo] [-leftEye] [-rightEye]" | |
7356 | "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]" | |
7357 | "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]" | |
7358 | "\n\t\t: Manage camera parameters." | |
7359 | "\n\t\t: Prints current value when option called without argument." | |
7360 | "\n\t\t: Orthographic camera:" | |
7361 | "\n\t\t: -ortho activate orthographic projection" | |
7362 | "\n\t\t: Perspective camera:" | |
7363 | "\n\t\t: -persp activate perspective projection (mono)" | |
7364 | "\n\t\t: -fovy field of view in y axis, in degrees" | |
7365 | "\n\t\t: -distance distance of eye from camera center" | |
7366 | "\n\t\t: Stereoscopic camera:" | |
7367 | "\n\t\t: -stereo perspective projection (stereo)" | |
7368 | "\n\t\t: -leftEye perspective projection (left eye)" | |
7369 | "\n\t\t: -rightEye perspective projection (right eye)" | |
7370 | "\n\t\t: -iod intraocular distance value" | |
7371 | "\n\t\t: -iodType distance type, absolute or relative" | |
7372 | "\n\t\t: -zfocus stereographic focus value" | |
7373 | "\n\t\t: -zfocusType focus type, absolute or relative", | |
7374 | __FILE__, VCamera, group); | |
b5ac8292 | 7375 | theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n" |
197ac94e | 7376 | "- vautozfit [on={1|0}] [scale]\n" |
7377 | " Prints or changes parameters of automatic z-fit mode:\n" | |
7378 | " \"on\" - turns automatic z-fit on or off\n" | |
7379 | " \"scale\" - specifies factor to scale computed z range.\n", | |
7380 | __FILE__, VAutoZFit, group); | |
b5ac8292 | 7381 | theCommands.Add ("vzrange", "command to manually access znear and zfar values\n" |
7382 | " vzrange - without parameters shows current values\n" | |
7383 | " vzrange [znear] [zfar] - applies provided values to view", | |
7384 | __FILE__,VZRange, group); | |
4754e164 | 7385 | theCommands.Add("vantialiasing", |
7386 | "vantialiasing 1|0", | |
7387 | __FILE__,VAntialiasing,group); | |
7388 | theCommands.Add ("vpurgedisplay", | |
eb4320f2 | 7389 | "vpurgedisplay" |
4754e164 | 7390 | "- removes structures which don't belong to objects displayed in neutral point", |
7391 | __FILE__, VPurgeDisplay, group); | |
7392 | theCommands.Add("vsetviewsize", | |
7393 | "vsetviewsize size", | |
7394 | __FILE__,VSetViewSize,group); | |
7395 | theCommands.Add("vmoveview", | |
7396 | "vmoveview Dx Dy Dz [Start = 1|0]", | |
7397 | __FILE__,VMoveView,group); | |
7398 | theCommands.Add("vtranslateview", | |
7399 | "vtranslateview Dx Dy Dz [Start = 1|0)]", | |
7400 | __FILE__,VTranslateView,group); | |
7401 | theCommands.Add("vturnview", | |
7402 | "vturnview Ax Ay Az [Start = 1|0]", | |
7403 | __FILE__,VTurnView,group); | |
269294d6 | 7404 | theCommands.Add("vtextureenv", |
7405 | "Enables or disables environment mapping in the 3D view, loading the texture from the given standard " | |
7406 | "or user-defined file and optionally applying texture mapping parameters\n" | |
7407 | " Usage:\n" | |
7408 | " vtextureenv off - disables environment mapping\n" | |
7409 | " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n" | |
7410 | " std_texture = (0..7)\n" | |
7411 | " rep = {clamp|repeat}\n" | |
7412 | " mod = {decal|modulate}\n" | |
7413 | " flt = {nearest|bilinear|trilinear}\n" | |
7414 | " ss, st - scale factors for s and t texture coordinates\n" | |
7415 | " ts, tt - translation for s and t texture coordinates\n" | |
7416 | " rot - texture rotation angle in degrees", | |
7417 | __FILE__, VTextureEnv, group); | |
0a768f56 | 7418 | theCommands.Add("vhlr" , |
e9224045 | 7419 | "is_enabled={on|off} [show_hidden={1|0}]" |
0a768f56 | 7420 | " - Hidden line removal algorithm:" |
e9224045 | 7421 | " - is_enabled: if is on HLR algorithm is applied\n" |
7422 | " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n", | |
0a768f56 | 7423 | __FILE__,VHLR,group); |
7424 | theCommands.Add("vhlrtype" , | |
7425 | "algo_type={algo|polyalgo} [shape_1 ... shape_n]" | |
7426 | " - Changes the type of HLR algorithm using for shapes." | |
7427 | " - algo_type: if equals to algo, exact HLR algorithm is applied;\n" | |
7428 | " if equals to polyalgo, polygonal HLR algorithm is applied." | |
7429 | "If shapes are not given HLR algoithm of given type is applied" | |
7430 | " to all shapes in the view\n", | |
7431 | __FILE__,VHLRType,group); | |
4269bd1b | 7432 | theCommands.Add("vclipplane", "vclipplane usage: \n" |
7433 | " maxplanes <view_name> - get plane limit for view.\n" | |
7434 | " create <plane_name> - create new plane.\n" | |
7435 | " delete <plane_name> - delete plane.\n" | |
7436 | " clone <source_plane> <plane_name> - clone the plane definition.\n" | |
7437 | " set/unset <plane_name> object <object list> - set/unset plane for IO.\n" | |
7438 | " set/unset <plane_name> view <view list> - set/unset plane for view.\n" | |
7439 | " change <plane_name> on/off - turn clipping on/off.\n" | |
7440 | " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n" | |
7441 | " change <plane_name> capping on/off - turn capping on/off.\n" | |
7442 | " change <plane_name> capping color <r> <g> <b> - set color.\n" | |
7443 | " change <plane name> capping texname <texture> - set texture.\n" | |
7444 | " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n" | |
7445 | " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n" | |
7446 | " change <plane_name> capping texrotate <angle> - set tex rotation.\n" | |
7447 | " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n" | |
7448 | " please use VSetTextureMode command to enable texture rendering in view.\n" | |
7449 | , __FILE__, VClipPlane, group); | |
7450 | theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n" | |
7451 | " mode can be:\n" | |
7452 | " 0 - no textures enabled in view.\n" | |
7453 | " 1 - only environment textures enabled.\n" | |
7454 | " 2 - all textures enabled.\n" | |
7455 | " this command sets texture details mode for the specified view.\n" | |
7456 | , __FILE__, VSetTextureMode, group); | |
392ac980 | 7457 | theCommands.Add("vdefaults", |
7458 | "vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]", | |
7459 | __FILE__, VDefaults, group); | |
12381341 | 7460 | theCommands.Add("vlight", |
816d03ee | 7461 | "tool to manage light sources, without arguments shows list of lights." |
7462 | "\n Main commands: " | |
7463 | "\n 'clear' to clear lights" | |
7464 | "\n '{def}aults' to load deafault lights" | |
7465 | "\n 'add' (or 'new') <type> to add any light source" | |
7466 | "\n where <type> is one of {amb}ient|directional|{spot}light|positional" | |
7467 | "\n 'change' <lightId> to edit light source with specified lightId" | |
7468 | "\n\n In addition to 'add' and 'change' commands you can use light parameters:" | |
7469 | "\n {pos}ition X Y Z" | |
7470 | "\n {dir}ection X Y Z (for directional light or for spotlight)" | |
7471 | "\n color colorName" | |
7472 | "\n {head}light 0|1" | |
7473 | "\n {constAtten}uation value" | |
7474 | "\n {linearAtten}uation value" | |
7475 | "\n angle angleDeg" | |
7476 | "\n {spotexp}onent value" | |
7477 | "\n local|global" | |
7478 | "\n\n example: vlight add positional head 1 pos 0 1 1 color red" | |
7479 | "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2", | |
12381341 | 7480 | __FILE__, VLight, group); |
6b62b2da | 7481 | theCommands.Add("vraytrace", |
7482 | "vraytrace [0|1]" | |
7483 | "\n\t\t: Turn on/off raytracing renderer." | |
7484 | "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'." | |
7485 | "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.", | |
7486 | __FILE__, VRenderParams, group); | |
bc8c79bb | 7487 | theCommands.Add("vrenderparams", |
7488 | "\n Manages rendering parameters: " | |
8625ef7e | 7489 | "\n '-rayTrace' Enables GPU ray-tracing" |
7490 | "\n '-raster' Disables GPU ray-tracing" | |
7491 | "\n '-rayDepth 0..10' Defines maximum ray-tracing depth" | |
7492 | "\n '-shadows on|off' Enables/disables shadows rendering" | |
7493 | "\n '-reflections on|off' Enables/disables specular reflections" | |
7494 | "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing" | |
7495 | "\n '-gleam on|off' Enables/disables transparency shadow effects" | |
7496 | "\n '-shadingModel model' Controls shading model from enumeration" | |
7497 | "\n color, flat, gouraud, phong" | |
7498 | "\n Unlike vcaps, these parameters dramatically change visual properties." | |
7499 | "\n Command is intended to control presentation quality depending on" | |
7500 | "\n hardware capabilities and performance.", | |
bc8c79bb | 7501 | __FILE__, VRenderParams, group); |
b7cd4ba7 | 7502 | theCommands.Add("vfrustumculling", |
7503 | "vfrustumculling [toEnable]: enables/disables objects clipping", | |
7504 | __FILE__,VFrustumCulling,group); | |
c398b00e | 7505 | theCommands.Add("vhighlightselected", |
7506 | "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n" | |
7507 | "Without arguments it shows if highlighting of selected objects is enabled now.", | |
7508 | __FILE__,VHighlightSelected,group); | |
7509 | ||
0717ddc1 | 7510 | |
7511 | theCommands.Add("vxrotate", | |
7512 | "vxrotate", | |
7513 | __FILE__,VXRotate,group); | |
7514 | ||
7fd59977 | 7515 | } |