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> |
7a324550 | 18 | #include <AIS_ColorScale.hxx> |
b12e1c7b | 19 | #include <AIS_RubberBand.hxx> |
0a768f56 | 20 | #include <AIS_Shape.hxx> |
0a768f56 | 21 | #include <AIS_InteractiveObject.hxx> |
22 | #include <AIS_ListOfInteractive.hxx> | |
23 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
24 | #include <DBRep.hxx> | |
61b0191c | 25 | #include <Graphic3d_ArrayOfPolylines.hxx> |
2bd4c032 | 26 | #include <Graphic3d_AspectMarker3d.hxx> |
7fd59977 | 27 | #include <Graphic3d_ExportFormat.hxx> |
269294d6 | 28 | #include <Graphic3d_NameOfTextureEnv.hxx> |
a79f67f8 | 29 | #include <Graphic3d_GraduatedTrihedron.hxx> |
269294d6 | 30 | #include <Graphic3d_TextureEnv.hxx> |
31 | #include <Graphic3d_TextureParams.hxx> | |
32 | #include <Graphic3d_TypeOfTextureFilter.hxx> | |
4269bd1b | 33 | #include <Graphic3d_AspectFillArea3d.hxx> |
7fd59977 | 34 | #include <ViewerTest.hxx> |
8625ef7e | 35 | #include <ViewerTest_AutoUpdater.hxx> |
7fd59977 | 36 | #include <ViewerTest_EventManager.hxx> |
4754e164 | 37 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
4269bd1b | 38 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> |
12381341 | 39 | #include <V3d_AmbientLight.hxx> |
40 | #include <V3d_DirectionalLight.hxx> | |
12381341 | 41 | #include <V3d_PositionalLight.hxx> |
42 | #include <V3d_SpotLight.hxx> | |
18d715bd | 43 | #include <NCollection_DoubleMap.hxx> |
44 | #include <NCollection_List.hxx> | |
45 | #include <NCollection_Vector.hxx> | |
7fd59977 | 46 | #include <AIS_InteractiveContext.hxx> |
47 | #include <Draw_Interpretor.hxx> | |
48 | #include <Draw.hxx> | |
49 | #include <Draw_Appli.hxx> | |
7edf74fd | 50 | #include <Aspect_PrintAlgo.hxx> |
692613e5 | 51 | #include <Image_AlienPixMap.hxx> |
58655684 | 52 | #include <OpenGl_GraphicDriver.hxx> |
208e6839 | 53 | #include <OSD_Timer.hxx> |
900f7229 | 54 | #include <TColStd_HSequenceOfAsciiString.hxx> |
59f45b7c | 55 | #include <TColStd_SequenceOfInteger.hxx> |
4754e164 | 56 | #include <TColStd_HSequenceOfReal.hxx> |
57 | #include <TColgp_Array1OfPnt2d.hxx> | |
197ac94e | 58 | #include <TColStd_MapOfAsciiString.hxx> |
20637bd2 | 59 | #include <Aspect_TypeOfLine.hxx> |
692613e5 | 60 | #include <Image_Diff.hxx> |
dc3fe572 | 61 | #include <Aspect_DisplayConnection.hxx> |
4269bd1b | 62 | #include <gp_Pnt.hxx> |
63 | #include <gp_Dir.hxx> | |
64 | #include <gp_Pln.hxx> | |
65 | #include <PrsMgr_PresentableObject.hxx> | |
66 | #include <Graphic3d_ClipPlane.hxx> | |
67 | #include <NCollection_DataMap.hxx> | |
68 | #include <Graphic3d_Texture2Dmanual.hxx> | |
69 | #include <Prs3d_ShadingAspect.hxx> | |
6262338c | 70 | #include <Prs3d_Drawer.hxx> |
61b0191c | 71 | #include <Prs3d_LineAspect.hxx> |
72 | #include <Prs3d_Root.hxx> | |
7fd59977 | 73 | |
57c28b61 | 74 | #ifdef _WIN32 |
25289ec1 | 75 | #undef DrawText |
76 | #endif | |
77 | ||
692613e5 | 78 | #include <cstdlib> |
25289ec1 | 79 | |
58655684 | 80 | #if defined(_WIN32) |
4fe56619 | 81 | #include <WNT_WClass.hxx> |
82 | #include <WNT_Window.hxx> | |
83 | ||
84 | #if defined(_MSC_VER) | |
85 | #define _CRT_SECURE_NO_DEPRECATE | |
86 | #pragma warning (disable:4996) | |
87 | #endif | |
88 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
4fe56619 | 89 | #include <Cocoa_Window.hxx> |
7fd59977 | 90 | #else |
4fe56619 | 91 | #include <Xw_Window.hxx> |
92 | #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */ | |
93 | #include <X11/Xutil.h> | |
94 | #include <tk.h> | |
7fd59977 | 95 | #endif |
96 | ||
b514beda | 97 | // Auxiliary definitions |
98 | static const char THE_KEY_DELETE = 127; | |
7fd59977 | 99 | |
100 | //============================================================================== | |
101 | // VIEWER GLOBAL VARIABLES | |
102 | //============================================================================== | |
103 | ||
104 | Standard_IMPORT Standard_Boolean Draw_VirtualWindows; | |
b514beda | 105 | Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand); |
7fd59977 | 106 | |
107 | Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv); | |
4754e164 | 108 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
7fd59977 | 109 | |
b514beda | 110 | extern int VErase (Draw_Interpretor& theDI, |
111 | Standard_Integer theArgNb, | |
112 | const char** theArgVec); | |
113 | ||
58655684 | 114 | #if defined(_WIN32) |
7fd59977 | 115 | static Handle(WNT_Window)& VT_GetWindow() { |
116 | static Handle(WNT_Window) WNTWin; | |
117 | return WNTWin; | |
118 | } | |
4fe56619 | 119 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
4fe56619 | 120 | static Handle(Cocoa_Window)& VT_GetWindow() |
121 | { | |
122 | static Handle(Cocoa_Window) aWindow; | |
123 | return aWindow; | |
124 | } | |
125 | extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow); | |
18d715bd | 126 | extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle); |
127 | extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight); | |
128 | ||
7fd59977 | 129 | #else |
7fd59977 | 130 | static Handle(Xw_Window)& VT_GetWindow(){ |
131 | static Handle(Xw_Window) XWWin; | |
132 | return XWWin; | |
133 | } | |
7fd59977 | 134 | |
135 | static void VProcessEvents(ClientData,int); | |
136 | #endif | |
137 | ||
18d715bd | 138 | static Handle(Aspect_DisplayConnection)& GetDisplayConnection() |
139 | { | |
140 | static Handle(Aspect_DisplayConnection) aDisplayConnection; | |
141 | return aDisplayConnection; | |
142 | } | |
143 | ||
144 | static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection) | |
145 | { | |
146 | GetDisplayConnection() = theDisplayConnection; | |
147 | } | |
148 | ||
58655684 | 149 | #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
18d715bd | 150 | Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow) |
dc3fe572 | 151 | { |
0ebaa4db | 152 | Aspect_Handle aWindowHandle = (Aspect_Handle)NULL; |
58655684 | 153 | #if defined(_WIN32) |
18d715bd | 154 | const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow); |
155 | if (!aWindow.IsNull()) | |
156 | return aWindow->HWindow(); | |
157 | #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
158 | const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow); | |
159 | if (!aWindow.IsNull()) | |
160 | return aWindow->XWindow(); | |
161 | #endif | |
162 | return aWindowHandle; | |
dc3fe572 | 163 | } |
18d715bd | 164 | #endif |
dc3fe572 | 165 | |
de75ed09 | 166 | static Standard_Boolean MyHLRIsOn = Standard_False; |
7fd59977 | 167 | |
18d715bd | 168 | NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews; |
58655684 | 169 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts; |
18d715bd | 170 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers; |
58655684 | 171 | static OpenGl_Caps ViewerTest_myDefaultCaps; |
18d715bd | 172 | |
7fd59977 | 173 | #define ZCLIPWIDTH 1. |
174 | ||
175 | static void OSWindowSetup(); | |
176 | ||
f42753ed | 177 | static struct |
178 | { | |
179 | Quantity_Color FlatColor; | |
180 | Quantity_Color GradientColor1; | |
181 | Quantity_Color GradientColor2; | |
182 | Aspect_GradientFillMethod FillMethod; | |
183 | } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE }; | |
184 | ||
7fd59977 | 185 | //============================================================================== |
186 | // EVENT GLOBAL VARIABLES | |
187 | //============================================================================== | |
188 | ||
189 | static int Start_Rot = 0; | |
190 | static int ZClipIsOn = 0; | |
4fe56619 | 191 | int X_Motion = 0; // Current cursor position |
192 | int Y_Motion = 0; | |
193 | int X_ButtonPress = 0; // Last ButtonPress position | |
194 | int Y_ButtonPress = 0; | |
195 | Standard_Boolean IsDragged = Standard_False; | |
8abada55 | 196 | Standard_Boolean DragFirst = Standard_False; |
7fd59977 | 197 | |
b12e1c7b | 198 | |
199 | Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand() | |
200 | { | |
201 | static Handle(AIS_RubberBand) aBand; | |
202 | if (aBand.IsNull()) | |
203 | { | |
69adb9ce | 204 | aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0); |
205 | aBand->SetDisplayMode (0); | |
b12e1c7b | 206 | } |
207 | return aBand; | |
208 | } | |
209 | ||
7fd59977 | 210 | //============================================================================== |
211 | ||
57c28b61 | 212 | #ifdef _WIN32 |
7fd59977 | 213 | static LRESULT WINAPI ViewerWindowProc( |
214 | HWND hwnd, | |
215 | UINT uMsg, | |
216 | WPARAM wParam, | |
217 | LPARAM lParam ); | |
218 | static LRESULT WINAPI AdvViewerWindowProc( | |
219 | HWND hwnd, | |
220 | UINT uMsg, | |
221 | WPARAM wParam, | |
222 | LPARAM lParam ); | |
223 | #endif | |
224 | ||
225 | ||
226 | //============================================================================== | |
227 | //function : WClass | |
228 | //purpose : | |
229 | //============================================================================== | |
230 | ||
231 | const Handle(MMgt_TShared)& ViewerTest::WClass() | |
232 | { | |
233 | static Handle(MMgt_TShared) theWClass; | |
58655684 | 234 | #if defined(_WIN32) |
4fe56619 | 235 | if (theWClass.IsNull()) |
236 | { | |
7c65581d | 237 | theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc, |
7fd59977 | 238 | CS_VREDRAW | CS_HREDRAW, 0, 0, |
239 | ::LoadCursor (NULL, IDC_ARROW)); | |
240 | } | |
241 | #endif | |
242 | return theWClass; | |
243 | } | |
244 | ||
18d715bd | 245 | //============================================================================== |
246 | //function : CreateName | |
247 | //purpose : Create numerical name for new object in theMap | |
248 | //============================================================================== | |
249 | template <typename ObjectType> | |
250 | TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap, | |
251 | const TCollection_AsciiString& theDefaultString) | |
252 | { | |
253 | if (theObjectMap.IsEmpty()) | |
254 | return theDefaultString + TCollection_AsciiString(1); | |
255 | ||
256 | Standard_Integer aNextKey = 1; | |
257 | Standard_Boolean isFound = Standard_False; | |
258 | while (!isFound) | |
259 | { | |
260 | TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey); | |
261 | // Look for objects with default names | |
262 | if (theObjectMap.IsBound1(aStringKey)) | |
263 | { | |
264 | aNextKey++; | |
265 | } | |
266 | else | |
267 | isFound = Standard_True; | |
268 | } | |
269 | ||
270 | return theDefaultString + TCollection_AsciiString(aNextKey); | |
271 | } | |
272 | ||
273 | //============================================================================== | |
274 | //structure : ViewerTest_Names | |
275 | //purpose : Allow to operate with full view name: driverName/viewerName/viewName | |
276 | //============================================================================== | |
277 | struct ViewerTest_Names | |
278 | { | |
279 | private: | |
280 | TCollection_AsciiString myDriverName; | |
281 | TCollection_AsciiString myViewerName; | |
282 | TCollection_AsciiString myViewName; | |
283 | ||
284 | public: | |
285 | ||
286 | const TCollection_AsciiString& GetDriverName () const | |
287 | { | |
288 | return myDriverName; | |
289 | } | |
290 | void SetDriverName (const TCollection_AsciiString& theDriverName) | |
291 | { | |
292 | myDriverName = theDriverName; | |
293 | } | |
294 | const TCollection_AsciiString& GetViewerName () const | |
295 | { | |
296 | return myViewerName; | |
297 | } | |
298 | void SetViewerName (const TCollection_AsciiString& theViewerName) | |
299 | { | |
300 | myViewerName = theViewerName; | |
301 | } | |
302 | const TCollection_AsciiString& GetViewName () const | |
303 | { | |
304 | return myViewName; | |
305 | } | |
306 | void SetViewName (const TCollection_AsciiString& theViewName) | |
307 | { | |
308 | myViewName = theViewName; | |
309 | } | |
310 | ||
311 | //=========================================================================== | |
312 | //function : Constructor for ViewerTest_Names | |
313 | //purpose : Get view, viewer, driver names from custom string | |
314 | //=========================================================================== | |
315 | ||
316 | ViewerTest_Names (const TCollection_AsciiString& theInputString) | |
317 | { | |
318 | TCollection_AsciiString aName(theInputString); | |
319 | if (theInputString.IsEmpty()) | |
320 | { | |
321 | // Get current configuration | |
322 | if (ViewerTest_myDrivers.IsEmpty()) | |
323 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
324 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
325 | else | |
326 | myDriverName = ViewerTest_myDrivers.Find2 | |
327 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
328 | ||
329 | if(ViewerTest_myContexts.IsEmpty()) | |
330 | { | |
331 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
332 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
333 | } | |
334 | else | |
335 | myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext()); | |
336 | ||
337 | myViewName = CreateName <Handle(V3d_View)> | |
338 | (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View")); | |
339 | } | |
340 | else | |
341 | { | |
342 | // There is at least view name | |
343 | Standard_Integer aParserNumber = 0; | |
344 | for (Standard_Integer i = 0; i < 3; ++i) | |
345 | { | |
346 | Standard_Integer aParserPos = aName.SearchFromEnd("/"); | |
347 | if(aParserPos != -1) | |
348 | { | |
349 | aParserNumber++; | |
350 | aName.Split(aParserPos-1); | |
351 | } | |
352 | else | |
353 | break; | |
354 | } | |
355 | if (aParserNumber == 0) | |
356 | { | |
357 | // Only view name | |
358 | if (!ViewerTest::GetAISContext().IsNull()) | |
359 | { | |
360 | myDriverName = ViewerTest_myDrivers.Find2 | |
361 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
362 | myViewerName = ViewerTest_myContexts.Find2 | |
363 | (ViewerTest::GetAISContext()); | |
364 | } | |
365 | else | |
366 | { | |
367 | // There is no opened contexts here, need to create names for viewer and driver | |
368 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
369 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
370 | ||
371 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
372 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
373 | } | |
374 | myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString); | |
375 | } | |
376 | else if (aParserNumber == 1) | |
377 | { | |
378 | // Here is viewerName/viewName | |
379 | if (!ViewerTest::GetAISContext().IsNull()) | |
380 | myDriverName = ViewerTest_myDrivers.Find2 | |
381 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
382 | else | |
383 | { | |
384 | // There is no opened contexts here, need to create name for driver | |
385 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
386 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
387 | } | |
388 | myViewerName = TCollection_AsciiString(myDriverName + "/" + aName); | |
389 | ||
390 | myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString); | |
391 | } | |
392 | else | |
393 | { | |
394 | //Here is driverName/viewerName/viewName | |
395 | myDriverName = TCollection_AsciiString(aName); | |
396 | ||
397 | TCollection_AsciiString aViewerName(theInputString); | |
398 | aViewerName.Split(aViewerName.SearchFromEnd("/") - 1); | |
399 | myViewerName = TCollection_AsciiString(aViewerName); | |
400 | ||
401 | myViewName = TCollection_AsciiString(theInputString); | |
402 | } | |
403 | } | |
404 | } | |
405 | }; | |
406 | ||
407 | //============================================================================== | |
408 | //function : FindContextByView | |
409 | //purpose : Find AIS_InteractiveContext by View | |
410 | //============================================================================== | |
411 | ||
412 | Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView) | |
413 | { | |
414 | Handle(AIS_InteractiveContext) anAISContext; | |
415 | ||
416 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
417 | anIter (ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
418 | { | |
419 | if (anIter.Value()->CurrentViewer() == theView->Viewer()) | |
420 | return anIter.Key2(); | |
421 | } | |
422 | return anAISContext; | |
423 | } | |
424 | ||
425 | ||
426 | //============================================================================== | |
427 | //function : SetWindowTitle | |
428 | //purpose : Set window title | |
429 | //============================================================================== | |
430 | ||
431 | void SetWindowTitle (const Handle(Aspect_Window)& theWindow, | |
432 | Standard_CString theTitle) | |
433 | { | |
58655684 | 434 | #if defined(_WIN32) |
18d715bd | 435 | SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(), |
436 | theTitle); | |
437 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
438 | SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle); | |
439 | #else | |
440 | if(GetDisplayConnection()->GetDisplay()) | |
441 | { | |
442 | Window aWindow = | |
443 | Handle(Xw_Window)::DownCast(theWindow)->XWindow(); | |
444 | XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle); | |
445 | } | |
446 | #endif | |
447 | } | |
448 | ||
449 | //============================================================================== | |
450 | //function : IsWindowOverlapped | |
451 | //purpose : Check if theWindow overlapp another view | |
452 | //============================================================================== | |
453 | ||
454 | Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft, | |
455 | const Standard_Integer thePxTop, | |
456 | const Standard_Integer thePxRight, | |
457 | const Standard_Integer thePxBottom, | |
458 | TCollection_AsciiString& theViewId) | |
459 | { | |
460 | for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
461 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
462 | { | |
463 | Standard_Integer aTop = 0, | |
464 | aLeft = 0, | |
465 | aRight = 0, | |
466 | aBottom = 0; | |
467 | anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom); | |
468 | if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
469 | (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) || | |
470 | (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
471 | (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom)) | |
472 | { | |
473 | theViewId = anIter.Key1(); | |
474 | return Standard_True; | |
475 | } | |
476 | } | |
477 | return Standard_False; | |
478 | } | |
479 | ||
480 | // Workaround: to create and delete non-orthographic views outside ViewerTest | |
481 | void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName) | |
482 | { | |
483 | ViewerTest_myViews.UnBind1 (theName); | |
484 | } | |
485 | ||
486 | void ViewerTest::InitViewName (const TCollection_AsciiString& theName, | |
487 | const Handle(V3d_View)& theView) | |
488 | { | |
489 | ViewerTest_myViews.Bind (theName, theView); | |
490 | } | |
491 | ||
492 | TCollection_AsciiString ViewerTest::GetCurrentViewName () | |
493 | { | |
494 | return ViewerTest_myViews.Find2( ViewerTest::CurrentView()); | |
495 | } | |
7fd59977 | 496 | //============================================================================== |
497 | //function : ViewerInit | |
498 | //purpose : Create the window viewer and initialize all the global variable | |
499 | //============================================================================== | |
500 | ||
18d715bd | 501 | TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft, |
502 | const Standard_Integer thePxTop, | |
503 | const Standard_Integer thePxWidth, | |
504 | const Standard_Integer thePxHeight, | |
505 | Standard_CString theViewName, | |
506 | Standard_CString theDisplayName) | |
7fd59977 | 507 | { |
8c3c9904 | 508 | // Default position and dimension of the viewer window. |
4fe56619 | 509 | // Note that left top corner is set to be sufficiently small to have |
8c3c9904 | 510 | // window fit in the small screens (actual for remote desktops, see #23003). |
4fe56619 | 511 | // The position corresponds to the window's client area, thus some |
8c3c9904 | 512 | // gap is added for window frame to be visible. |
513 | Standard_Integer aPxLeft = 20; | |
514 | Standard_Integer aPxTop = 40; | |
7fd59977 | 515 | Standard_Integer aPxWidth = 409; |
516 | Standard_Integer aPxHeight = 409; | |
18d715bd | 517 | Standard_Boolean toCreateViewer = Standard_False; |
518 | ||
58655684 | 519 | Handle(OpenGl_GraphicDriver) aGraphicDriver; |
18d715bd | 520 | ViewerTest_Names aViewNames(theViewName); |
521 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ())) | |
522 | aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View")); | |
523 | ||
524 | if (thePxLeft != 0) | |
525 | aPxLeft = thePxLeft; | |
526 | if (thePxTop != 0) | |
527 | aPxTop = thePxTop; | |
528 | if (thePxWidth != 0) | |
529 | aPxWidth = thePxWidth; | |
530 | if (thePxHeight != 0) | |
7fd59977 | 531 | aPxHeight = thePxHeight; |
4269bd1b | 532 | |
18d715bd | 533 | // Get graphic driver (create it or get from another view) |
534 | if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName())) | |
535 | { | |
536 | // Get connection string | |
58655684 | 537 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
18d715bd | 538 | TCollection_AsciiString aDisplayName(theDisplayName); |
498ce76b | 539 | if (!aDisplayName.IsEmpty()) |
18d715bd | 540 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
541 | else | |
542 | SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName)); | |
18d715bd | 543 | #else |
498ce76b | 544 | (void)theDisplayName; // avoid warning on unused argument |
18d715bd | 545 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
546 | #endif | |
65993a95 | 547 | aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection()); |
58655684 | 548 | aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps; |
18d715bd | 549 | ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver); |
550 | toCreateViewer = Standard_True; | |
551 | } | |
552 | else | |
553 | { | |
58655684 | 554 | aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName())); |
7fd59977 | 555 | } |
556 | ||
18d715bd | 557 | //Dispose the window if input parameters are default |
558 | if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0) | |
7fd59977 | 559 | { |
18d715bd | 560 | Standard_Integer aTop = 0, |
561 | aLeft = 0, | |
562 | aRight = 0, | |
563 | aBottom = 0, | |
564 | aScreenWidth = 0, | |
565 | aScreenHeight = 0; | |
566 | ||
567 | // Get screen resolution | |
568 | #if defined(_WIN32) || defined(__WIN32__) | |
569 | RECT aWindowSize; | |
570 | GetClientRect(GetDesktopWindow(), &aWindowSize); | |
571 | aScreenHeight = aWindowSize.bottom; | |
572 | aScreenWidth = aWindowSize.right; | |
573 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
574 | GetCocoaScreenResolution (aScreenWidth, aScreenHeight); | |
575 | #else | |
576 | Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay()); | |
577 | aScreenWidth = WidthOfScreen(aScreen); | |
578 | aScreenHeight = HeightOfScreen(aScreen); | |
579 | #endif | |
580 | ||
581 | TCollection_AsciiString anOverlappedViewId(""); | |
773f53f1 | 582 | |
583 | while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)) | |
dc3fe572 | 584 | { |
18d715bd | 585 | ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom); |
586 | ||
587 | if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId) | |
588 | && aRight + 2*aPxWidth + 40 > aScreenWidth) | |
589 | { | |
590 | if (aBottom + aPxHeight + 40 > aScreenHeight) | |
591 | { | |
592 | aPxLeft = 20; | |
593 | aPxTop = 40; | |
594 | break; | |
595 | } | |
596 | aPxLeft = 20; | |
597 | aPxTop = aBottom + 40; | |
598 | } | |
599 | else | |
600 | aPxLeft = aRight + 20; | |
dc3fe572 | 601 | } |
18d715bd | 602 | } |
603 | ||
604 | // Get viewer name | |
605 | TCollection_AsciiString aTitle("3D View - "); | |
606 | aTitle = aTitle + aViewNames.GetViewName() + "(*)"; | |
607 | ||
608 | // Change name of current active window | |
609 | if (!ViewerTest::CurrentView().IsNull()) | |
610 | { | |
51740958 | 611 | TCollection_AsciiString anActiveWindowTitle("3D View - "); |
612 | anActiveWindowTitle = anActiveWindowTitle | |
18d715bd | 613 | + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); |
51740958 | 614 | SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString()); |
18d715bd | 615 | } |
616 | ||
617 | // Create viewer | |
eb4320f2 | 618 | Handle(V3d_Viewer) a3DViewer; |
18d715bd | 619 | // If it's the single view, we first look for empty context |
620 | if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty()) | |
621 | { | |
622 | NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
623 | anIter(ViewerTest_myContexts); | |
624 | if (anIter.More()) | |
625 | ViewerTest::SetAISContext (anIter.Value()); | |
626 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 627 | } |
628 | else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())) | |
629 | { | |
630 | ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName())); | |
631 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 632 | } |
eb4320f2 | 633 | else if (a3DViewer.IsNull()) |
18d715bd | 634 | { |
635 | toCreateViewer = Standard_True; | |
636 | TCollection_ExtendedString NameOfWindow("Viewer3D"); | |
637 | a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString()); | |
f42753ed | 638 | a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor); |
639 | a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1, | |
640 | ViewerTest_DefaultBackground.GradientColor2, | |
641 | ViewerTest_DefaultBackground.FillMethod); | |
18d715bd | 642 | } |
643 | ||
644 | // AIS context setup | |
645 | if (ViewerTest::GetAISContext().IsNull() || | |
646 | !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))) | |
647 | { | |
e79a94b9 | 648 | Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer); |
18d715bd | 649 | ViewerTest::SetAISContext (aContext); |
650 | ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext()); | |
651 | } | |
652 | else | |
e79a94b9 | 653 | { |
18d715bd | 654 | ViewerTest::ResetEventManager(); |
e79a94b9 | 655 | } |
18d715bd | 656 | |
657 | // Create window | |
e79a94b9 | 658 | #if defined(_WIN32) |
659 | VT_GetWindow() = new WNT_Window (aTitle.ToCString(), | |
660 | Handle(WNT_WClass)::DownCast (WClass()), | |
62e1beed | 661 | Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW, |
e79a94b9 | 662 | aPxLeft, aPxTop, |
663 | aPxWidth, aPxHeight, | |
664 | Quantity_NOC_BLACK); | |
4fe56619 | 665 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
e79a94b9 | 666 | VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(), |
667 | aPxLeft, aPxTop, | |
668 | aPxWidth, aPxHeight); | |
669 | ViewerTest_SetCocoaEventManagerView (VT_GetWindow()); | |
7fd59977 | 670 | #else |
e79a94b9 | 671 | VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(), |
672 | aTitle.ToCString(), | |
673 | aPxLeft, aPxTop, | |
674 | aPxWidth, aPxHeight); | |
7fd59977 | 675 | #endif |
18d715bd | 676 | VT_GetWindow()->SetVirtual (Draw_VirtualWindows); |
7fd59977 | 677 | |
d09dda09 | 678 | // View setup |
679 | Handle(V3d_View) aView = a3DViewer->CreateView(); | |
680 | aView->SetWindow (VT_GetWindow()); | |
c3282ec1 | 681 | ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer); |
4269bd1b | 682 | |
18d715bd | 683 | ViewerTest::CurrentView(aView); |
684 | ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView); | |
7fd59977 | 685 | |
18d715bd | 686 | // Setup for X11 or NT |
687 | OSWindowSetup(); | |
7fd59977 | 688 | |
18d715bd | 689 | // Set parameters for V3d_View and V3d_Viewer |
690 | const Handle (V3d_View) aV3dView = ViewerTest::CurrentView(); | |
691 | aV3dView->SetComputedMode(Standard_False); | |
692 | MyHLRIsOn = aV3dView->ComputedMode(); | |
693 | aV3dView->SetZClippingDepth(0.5); | |
694 | aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.); | |
7fd59977 | 695 | |
18d715bd | 696 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); |
697 | if (toCreateViewer) | |
698 | { | |
7fd59977 | 699 | a3DViewer->SetDefaultLights(); |
700 | a3DViewer->SetLightOn(); | |
18d715bd | 701 | } |
7fd59977 | 702 | |
e79a94b9 | 703 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
4fe56619 | 704 | #if TCL_MAJOR_VERSION < 8 |
18d715bd | 705 | Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 706 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
4fe56619 | 707 | #else |
18d715bd | 708 | Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 709 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
4fe56619 | 710 | #endif |
711 | #endif | |
7fd59977 | 712 | |
7fd59977 | 713 | VT_GetWindow()->Map(); |
4269bd1b | 714 | |
18d715bd | 715 | // Set the handle of created view in the event manager |
716 | ViewerTest::ResetEventManager(); | |
717 | ||
4fe56619 | 718 | ViewerTest::CurrentView()->Redraw(); |
18d715bd | 719 | |
720 | aView.Nullify(); | |
721 | a3DViewer.Nullify(); | |
18d715bd | 722 | |
723 | return aViewNames.GetViewName(); | |
724 | } | |
725 | ||
4269bd1b | 726 | //============================================================================== |
727 | //function : RedrawAllViews | |
728 | //purpose : Redraw all created views | |
729 | //============================================================================== | |
730 | void ViewerTest::RedrawAllViews() | |
731 | { | |
732 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
733 | for (; aViewIt.More(); aViewIt.Next()) | |
734 | { | |
735 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
736 | aView->Redraw(); | |
737 | } | |
738 | } | |
739 | ||
7fd59977 | 740 | //============================================================================== |
741 | //function : Vinit | |
742 | //purpose : Create the window viewer and initialize all the global variable | |
e79a94b9 | 743 | // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event |
7fd59977 | 744 | //============================================================================== |
745 | ||
18d715bd | 746 | static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 747 | { |
e79a94b9 | 748 | if (theArgsNb > 9) |
18d715bd | 749 | { |
e79a94b9 | 750 | std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n" |
751 | << "Type help for more information.\n"; | |
18d715bd | 752 | return 1; |
753 | } | |
18d715bd | 754 | |
e79a94b9 | 755 | TCollection_AsciiString aViewName, aDisplayName; |
756 | Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0; | |
757 | TCollection_AsciiString aName, aValue; | |
758 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
18d715bd | 759 | { |
e79a94b9 | 760 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; |
761 | TCollection_AsciiString anArgCase = anArg; | |
762 | anArgCase.UpperCase(); | |
1d7ca641 | 763 | if (ViewerTest::SplitParameter (anArg, aName, aValue)) |
18d715bd | 764 | { |
e79a94b9 | 765 | aName.UpperCase(); |
766 | if (aName.IsEqual ("NAME")) | |
18d715bd | 767 | { |
768 | aViewName = aValue; | |
769 | } | |
e79a94b9 | 770 | else if (aName.IsEqual ("L") |
771 | || aName.IsEqual ("LEFT")) | |
772 | { | |
18d715bd | 773 | aPxLeft = aValue.IntegerValue(); |
e79a94b9 | 774 | } |
775 | else if (aName.IsEqual ("T") | |
776 | || aName.IsEqual ("TOP")) | |
777 | { | |
18d715bd | 778 | aPxTop = aValue.IntegerValue(); |
e79a94b9 | 779 | } |
780 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
781 | else if (aName.IsEqual ("DISP") | |
782 | || aName.IsEqual ("DISPLAY")) | |
783 | { | |
18d715bd | 784 | aDisplayName = aValue; |
e79a94b9 | 785 | } |
786 | #endif | |
787 | else if (aName.IsEqual ("W") | |
788 | || aName.IsEqual ("WIDTH")) | |
789 | { | |
18d715bd | 790 | aPxWidth = aValue.IntegerValue(); |
e79a94b9 | 791 | } |
792 | else if (aName.IsEqual ("H") | |
793 | || aName.IsEqual ("HEIGHT")) | |
794 | { | |
18d715bd | 795 | aPxHeight = aValue.IntegerValue(); |
e79a94b9 | 796 | } |
18d715bd | 797 | else |
798 | { | |
e79a94b9 | 799 | std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n"; |
18d715bd | 800 | } |
801 | } | |
e79a94b9 | 802 | else if (aViewName.IsEmpty()) |
803 | { | |
804 | aViewName = anArg; | |
805 | } | |
806 | else | |
807 | { | |
808 | std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n"; | |
809 | } | |
18d715bd | 810 | } |
811 | ||
812 | ViewerTest_Names aViewNames (aViewName); | |
e79a94b9 | 813 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName())) |
18d715bd | 814 | { |
e79a94b9 | 815 | TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName(); |
816 | theDi.Eval (aCommand.ToCString()); | |
18d715bd | 817 | return 0; |
818 | } | |
819 | ||
820 | TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight, | |
821 | aViewName.ToCString(), | |
822 | aDisplayName.ToCString()); | |
e79a94b9 | 823 | theDi << aViewId; |
7fd59977 | 824 | return 0; |
825 | } | |
826 | ||
0a768f56 | 827 | //============================================================================== |
828 | //function : VHLR | |
829 | //purpose : hidden lines removal algorithm | |
e9224045 | 830 | //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}] |
0a768f56 | 831 | //============================================================================== |
832 | ||
833 | static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
834 | { | |
835 | if (ViewerTest::CurrentView().IsNull()) | |
836 | { | |
837 | di << argv[0] << ": Call vinit before this command, please.\n"; | |
838 | return 1; | |
839 | } | |
840 | ||
e9224045 | 841 | if (argc < 2) |
0a768f56 | 842 | { |
843 | di << argv[0] << ": Wrong number of command arguments.\n" | |
844 | << "Type help " << argv[0] << " for more information.\n"; | |
845 | return 1; | |
846 | } | |
847 | ||
e9224045 | 848 | // Enable or disable HLR mode. |
0a768f56 | 849 | Standard_Boolean isHLROn = |
850 | (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False; | |
851 | ||
e9224045 | 852 | if (isHLROn != MyHLRIsOn) |
0a768f56 | 853 | { |
e9224045 | 854 | MyHLRIsOn = isHLROn; |
855 | ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn); | |
0a768f56 | 856 | } |
857 | ||
e9224045 | 858 | // Show or hide hidden lines in HLR mode. |
859 | Standard_Boolean isCurrentShowHidden | |
860 | = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine(); | |
861 | ||
862 | Standard_Boolean isShowHidden = | |
863 | (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False) | |
864 | : isCurrentShowHidden; | |
865 | ||
866 | ||
867 | if (isShowHidden != isCurrentShowHidden) | |
868 | { | |
869 | if (isShowHidden) | |
870 | { | |
871 | ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine(); | |
872 | } | |
873 | else | |
874 | { | |
875 | ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine(); | |
876 | } | |
877 | ||
878 | // Redisplay shapes. | |
879 | if (MyHLRIsOn) | |
880 | { | |
881 | AIS_ListOfInteractive aListOfShapes; | |
882 | ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes); | |
883 | ||
884 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next()) | |
885 | { | |
886 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value()); | |
887 | if (aShape.IsNull()) | |
888 | { | |
889 | continue; | |
890 | } | |
36132a2e | 891 | ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False); |
e9224045 | 892 | } |
893 | } | |
894 | } | |
0a768f56 | 895 | |
e9224045 | 896 | ViewerTest::CurrentView()->Update(); |
0a768f56 | 897 | return 0; |
898 | } | |
899 | ||
900 | //============================================================================== | |
901 | //function : VHLRType | |
902 | //purpose : change type of using HLR algorithm | |
903 | //============================================================================== | |
904 | ||
905 | static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
906 | { | |
907 | if (ViewerTest::CurrentView().IsNull()) | |
908 | { | |
909 | di << argv[0] << ": Call vinit before this command, please.\n"; | |
910 | return 1; | |
911 | } | |
912 | ||
913 | if (argc < 2) | |
914 | { | |
915 | di << argv[0] << ": Wrong number of command arguments.\n" | |
916 | << "Type help " << argv[0] << " for more information.\n"; | |
917 | return 1; | |
918 | } | |
919 | ||
920 | Prs3d_TypeOfHLR aTypeOfHLR = | |
921 | (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo; | |
922 | ||
923 | if (argc == 2) | |
924 | { | |
925 | AIS_ListOfInteractive aListOfShapes; | |
926 | ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes); | |
927 | ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR); | |
928 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); | |
929 | anIter.More(); anIter.Next()) | |
930 | { | |
931 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
932 | if (aShape.IsNull()) | |
933 | continue; | |
934 | if (aShape->TypeOfHLR() != aTypeOfHLR) | |
935 | aShape->SetTypeOfHLR (aTypeOfHLR); | |
936 | if (MyHLRIsOn) | |
36132a2e | 937 | ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False); |
0a768f56 | 938 | } |
939 | ViewerTest::CurrentView()->Update(); | |
940 | return 0; | |
941 | } | |
942 | else | |
943 | { | |
944 | for (Standard_Integer i = 2; i < argc; ++i) | |
945 | { | |
946 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
947 | TCollection_AsciiString aName (argv[i]); | |
948 | ||
949 | if (!aMap.IsBound2 (aName)) | |
950 | { | |
586db386 | 951 | di << argv[0] << ": Wrong shape name:" << aName.ToCString() << ".\n"; |
0a768f56 | 952 | continue; |
953 | } | |
954 | Handle(AIS_Shape) anAISObject = | |
955 | Handle(AIS_Shape)::DownCast (aMap.Find2(aName)); | |
956 | if (anAISObject.IsNull()) | |
957 | continue; | |
958 | anAISObject->SetTypeOfHLR (aTypeOfHLR); | |
959 | if (MyHLRIsOn) | |
36132a2e | 960 | ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False); |
0a768f56 | 961 | } |
962 | ViewerTest::CurrentView()->Update(); | |
963 | } | |
964 | ||
965 | return 0; | |
966 | } | |
967 | ||
18d715bd | 968 | //============================================================================== |
969 | //function : FindViewIdByWindowHandle | |
970 | //purpose : Find theView Id in the map of views by window handle | |
971 | //============================================================================== | |
972 | #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
973 | TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle) | |
974 | { | |
975 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
976 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
977 | { | |
978 | Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window()); | |
979 | if (aWindowHandle == theWindowHandle) | |
980 | return anIter.Key1(); | |
981 | } | |
982 | return TCollection_AsciiString(""); | |
983 | } | |
984 | #endif | |
985 | ||
986 | //============================================================================== | |
987 | //function : ActivateView | |
988 | //purpose : Make the view active | |
989 | //============================================================================== | |
990 | ||
991 | void ActivateView (const TCollection_AsciiString& theViewName) | |
992 | { | |
993 | const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
994 | if (!aView.IsNull()) | |
995 | { | |
996 | Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView); | |
997 | if (!anAISContext.IsNull()) | |
998 | { | |
999 | if (!ViewerTest::CurrentView().IsNull()) | |
1000 | { | |
1001 | TCollection_AsciiString aTitle("3D View - "); | |
1002 | aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); | |
1003 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1004 | } | |
1005 | ||
1006 | ViewerTest::CurrentView (aView); | |
1007 | // Update degenerate mode | |
1008 | MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode(); | |
1009 | ViewerTest::SetAISContext (anAISContext); | |
1010 | TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - "); | |
1011 | aTitle = aTitle + theViewName + "(*)"; | |
1012 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1013 | #if defined(_WIN32) || defined(__WIN32__) | |
1014 | VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
1015 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1016 | VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
1017 | #else | |
1018 | VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
1019 | #endif | |
1020 | SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); | |
1021 | ViewerTest::CurrentView()->Redraw(); | |
1022 | } | |
1023 | } | |
1024 | } | |
1025 | ||
0e93d9e5 | 1026 | //============================================================================== |
1027 | //function : RemoveView | |
1028 | //purpose : | |
1029 | //============================================================================== | |
1030 | void ViewerTest::RemoveView (const Handle(V3d_View)& theView, | |
1031 | const Standard_Boolean theToRemoveContext) | |
1032 | { | |
1033 | if (!ViewerTest_myViews.IsBound2 (theView)) | |
1034 | { | |
1035 | return; | |
1036 | } | |
1037 | ||
1038 | const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView); | |
1039 | RemoveView (aViewName, theToRemoveContext); | |
1040 | } | |
1041 | ||
18d715bd | 1042 | //============================================================================== |
1043 | //function : RemoveView | |
1044 | //purpose : Close and remove view from display, clear maps if neccessary | |
1045 | //============================================================================== | |
1046 | void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved) | |
1047 | { | |
1048 | if (!ViewerTest_myViews.IsBound1(theViewName)) | |
1049 | { | |
1050 | cout << "Wrong view name\n"; | |
1051 | return; | |
1052 | } | |
1053 | ||
1054 | // Activate another view if it's active now | |
1055 | if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView()) | |
1056 | { | |
1057 | if (ViewerTest_myViews.Extent() > 1) | |
1058 | { | |
1059 | TCollection_AsciiString aNewViewName; | |
1060 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator | |
1061 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
1062 | if (anIter.Key1() != theViewName) | |
1063 | { | |
1064 | aNewViewName = anIter.Key1(); | |
1065 | break; | |
1066 | } | |
1067 | ActivateView (aNewViewName); | |
1068 | } | |
1069 | else | |
1070 | { | |
1071 | Handle(V3d_View) anEmptyView; | |
1072 | #if defined(_WIN32) || defined(__WIN32__) | |
1073 | Handle(WNT_Window) anEmptyWindow; | |
1074 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1075 | Handle(Cocoa_Window) anEmptyWindow; | |
1076 | #else | |
1077 | Handle(Xw_Window) anEmptyWindow; | |
1078 | #endif | |
1079 | VT_GetWindow() = anEmptyWindow; | |
1080 | ViewerTest::CurrentView (anEmptyView); | |
1081 | if (isContextRemoved) | |
1082 | { | |
1083 | Handle(AIS_InteractiveContext) anEmptyContext; | |
1084 | ViewerTest::SetAISContext(anEmptyContext); | |
1085 | } | |
1086 | } | |
1087 | } | |
1088 | ||
1089 | // Delete view | |
1090 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
1091 | Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView); | |
1092 | ||
1093 | // Remove view resources | |
18d715bd | 1094 | ViewerTest_myViews.UnBind1(theViewName); |
1095 | aView->Remove(); | |
1096 | ||
1097 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
1098 | XFlush (GetDisplayConnection()->GetDisplay()); | |
1099 | #endif | |
1100 | ||
1101 | // Keep context opened only if the closed view is last to avoid | |
1102 | // unused empty contexts | |
1103 | if (!aCurrentContext.IsNull()) | |
1104 | { | |
1105 | // Check if there are more difined views in the viewer | |
1106 | aCurrentContext->CurrentViewer()->InitDefinedViews(); | |
1107 | if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews()) | |
1108 | { | |
1109 | // Remove driver if there is no viewers that use it | |
1110 | Standard_Boolean isRemoveDriver = Standard_True; | |
1111 | for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1112 | anIter(ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
1113 | { | |
1114 | if (aCurrentContext != anIter.Key2() && | |
1115 | aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver()) | |
1116 | { | |
1117 | isRemoveDriver = Standard_False; | |
1118 | break; | |
1119 | } | |
1120 | } | |
1121 | if(isRemoveDriver) | |
1122 | { | |
1123 | ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver()); | |
1124 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
1125 | #if TCL_MAJOR_VERSION < 8 | |
1126 | Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); | |
1127 | #else | |
1128 | Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); | |
1129 | #endif | |
1130 | #endif | |
1131 | } | |
1132 | ||
1133 | ViewerTest_myContexts.UnBind2(aCurrentContext); | |
1134 | } | |
1135 | } | |
1136 | cout << "3D View - " << theViewName << " was deleted.\n"; | |
1137 | ||
1138 | } | |
1139 | ||
1140 | //============================================================================== | |
1141 | //function : VClose | |
1142 | //purpose : Remove the view defined by its name | |
1143 | //============================================================================== | |
1144 | ||
d0cc1cb7 | 1145 | static int VClose (Draw_Interpretor& /*theDi*/, |
1146 | Standard_Integer theArgsNb, | |
1147 | const char** theArgVec) | |
18d715bd | 1148 | { |
18d715bd | 1149 | NCollection_List<TCollection_AsciiString> aViewList; |
d0cc1cb7 | 1150 | if (theArgsNb > 1) |
18d715bd | 1151 | { |
d0cc1cb7 | 1152 | TCollection_AsciiString anArg (theArgVec[1]); |
1153 | anArg.UpperCase(); | |
1154 | if (anArg.IsEqual ("ALL") | |
1155 | || anArg.IsEqual ("*")) | |
1156 | { | |
1157 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews); | |
1158 | anIter.More(); anIter.Next()) | |
1159 | { | |
1160 | aViewList.Append (anIter.Key1()); | |
1161 | } | |
1162 | if (aViewList.IsEmpty()) | |
1163 | { | |
1164 | std::cout << "No view to close\n"; | |
1165 | return 0; | |
1166 | } | |
1167 | } | |
1168 | else | |
18d715bd | 1169 | { |
d0cc1cb7 | 1170 | ViewerTest_Names aViewName (theArgVec[1]); |
1171 | if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName())) | |
1172 | { | |
1173 | std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n"; | |
1174 | return 1; | |
1175 | } | |
1176 | aViewList.Append (aViewName.GetViewName()); | |
18d715bd | 1177 | } |
1178 | } | |
1179 | else | |
1180 | { | |
d0cc1cb7 | 1181 | // close active view |
1182 | if (ViewerTest::CurrentView().IsNull()) | |
1183 | { | |
1184 | std::cerr << "No active view!\n"; | |
1185 | return 1; | |
1186 | } | |
1187 | aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView())); | |
18d715bd | 1188 | } |
1189 | ||
d0cc1cb7 | 1190 | Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1); |
18d715bd | 1191 | for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList); |
1192 | anIter.More(); anIter.Next()) | |
1193 | { | |
d0cc1cb7 | 1194 | ViewerTest::RemoveView (anIter.Value(), toRemoveContext); |
18d715bd | 1195 | } |
1196 | ||
1197 | return 0; | |
1198 | } | |
1199 | ||
1200 | //============================================================================== | |
1201 | //function : VActivate | |
1202 | //purpose : Activate the view defined by its ID | |
1203 | //============================================================================== | |
1204 | ||
1205 | static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
1206 | { | |
1207 | if (theArgsNb > 2) | |
1208 | { | |
1209 | theDi << theArgVec[0] << ": wrong number of command arguments.\n" | |
1210 | << "Usage: " << theArgVec[0] << " ViewID\n"; | |
1211 | return 1; | |
1212 | } | |
1213 | if(theArgsNb == 1) | |
1214 | { | |
1215 | theDi.Eval("vviewlist"); | |
1216 | return 0; | |
1217 | } | |
1218 | ||
1219 | TCollection_AsciiString aNameString(theArgVec[1]); | |
29cb310a | 1220 | if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 ) |
18d715bd | 1221 | { |
1222 | TCollection_AsciiString aTitle("3D View - "); | |
1223 | aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView()); | |
1224 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1225 | Handle(V3d_View) anEmptyView; | |
1226 | #if defined(_WIN32) || defined(__WIN32__) | |
1227 | Handle(WNT_Window) anEmptyWindow; | |
1228 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1229 | Handle(Cocoa_Window) anEmptyWindow; | |
1230 | #else | |
1231 | Handle(Xw_Window) anEmptyWindow; | |
1232 | #endif | |
1233 | VT_GetWindow() = anEmptyWindow; | |
1234 | ViewerTest::CurrentView (anEmptyView); | |
1235 | ViewerTest::ResetEventManager(); | |
1236 | theDi << theArgVec[0] << ": all views are inactive\n"; | |
1237 | return 0; | |
1238 | } | |
1239 | ||
1240 | ViewerTest_Names aViewNames(aNameString); | |
1241 | ||
1242 | // Check if this view exists in the viewer with the driver | |
1243 | if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName())) | |
1244 | { | |
1245 | theDi << "Wrong view name\n"; | |
1246 | return 1; | |
1247 | } | |
1248 | ||
1249 | // Check if it is active already | |
1250 | if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName())) | |
1251 | { | |
1252 | theDi << theArgVec[0] << ": the view is active already\n"; | |
1253 | return 0; | |
1254 | } | |
1255 | ||
1256 | ActivateView (aViewNames.GetViewName()); | |
1257 | return 0; | |
1258 | } | |
1259 | ||
1260 | //============================================================================== | |
1261 | //function : VViewList | |
1262 | //purpose : Print current list of views per viewer and graphic driver ID | |
1263 | // shared between viewers | |
1264 | //============================================================================== | |
1265 | ||
1266 | static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
1267 | { | |
1268 | if (theArgsNb > 2) | |
1269 | { | |
1270 | theDi << theArgVec[0] << ": Wrong number of command arguments\n" | |
29cb310a | 1271 | << "Usage: " << theArgVec[0] << " name"; |
18d715bd | 1272 | return 1; |
1273 | } | |
1274 | if (ViewerTest_myContexts.Size() < 1) | |
1275 | return 0; | |
1276 | ||
18d715bd | 1277 | Standard_Boolean isTreeView = |
29cb310a | 1278 | (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 )); |
18d715bd | 1279 | |
1280 | if (isTreeView) | |
1281 | theDi << theArgVec[0] <<":\n"; | |
1282 | ||
1283 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
1284 | aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next()) | |
1285 | { | |
1286 | if (isTreeView) | |
1287 | theDi << aDriverIter.Key1() << ":\n"; | |
1288 | ||
1289 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1290 | aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next()) | |
1291 | { | |
1292 | if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1) | |
1293 | { | |
1294 | if (isTreeView) | |
1295 | { | |
1296 | TCollection_AsciiString aContextName(aContextIter.Key1()); | |
586db386 | 1297 | theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n"; |
18d715bd | 1298 | } |
1299 | ||
1300 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
1301 | aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next()) | |
1302 | { | |
1303 | if (aViewIter.Key1().Search(aContextIter.Key1()) != -1) | |
1304 | { | |
1305 | TCollection_AsciiString aViewName(aViewIter.Key1()); | |
1306 | if (isTreeView) | |
1307 | { | |
1308 | if (aViewIter.Value() == ViewerTest::CurrentView()) | |
586db386 | 1309 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n"; |
18d715bd | 1310 | else |
1311 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n"; | |
1312 | } | |
1313 | else | |
1314 | { | |
1315 | theDi << aViewName << " "; | |
1316 | } | |
1317 | } | |
1318 | } | |
1319 | } | |
1320 | } | |
1321 | } | |
1322 | return 0; | |
1323 | } | |
1324 | ||
7fd59977 | 1325 | //============================================================================== |
4fe56619 | 1326 | //function : VT_ProcessKeyPress |
7fd59977 | 1327 | //purpose : Handle KeyPress event from a CString |
1328 | //============================================================================== | |
4fe56619 | 1329 | void VT_ProcessKeyPress (const char* buf_ret) |
7fd59977 | 1330 | { |
1331 | //cout << "KeyPress" << endl; | |
1332 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
7fd59977 | 1333 | // Letter in alphabetic order |
1334 | ||
b514beda | 1335 | if (!strcasecmp (buf_ret, "A")) |
1336 | { | |
7fd59977 | 1337 | // AXO |
1338 | aView->SetProj(V3d_XposYnegZpos); | |
1339 | } | |
b514beda | 1340 | else if (!strcasecmp (buf_ret, "D")) |
1341 | { | |
7fd59977 | 1342 | // Reset |
1343 | aView->Reset(); | |
1344 | } | |
b514beda | 1345 | else if (!strcasecmp (buf_ret, "F")) |
1346 | { | |
b586500b | 1347 | if (ViewerTest::GetAISContext()->NbSelected() > 0) |
1348 | { | |
1349 | ViewerTest::GetAISContext()->FitSelected (aView); | |
1350 | } | |
1351 | else | |
1352 | { | |
1353 | // FitAll | |
1354 | aView->FitAll(); | |
1355 | } | |
7fd59977 | 1356 | } |
b514beda | 1357 | else if (!strcasecmp (buf_ret, "H")) |
1358 | { | |
7fd59977 | 1359 | // HLR |
1360 | cout << "HLR" << endl; | |
de75ed09 | 1361 | aView->SetComputedMode (!aView->ComputedMode()); |
1362 | MyHLRIsOn = aView->ComputedMode(); | |
7fd59977 | 1363 | } |
b514beda | 1364 | else if (!strcasecmp (buf_ret, "P")) |
1365 | { | |
0a768f56 | 1366 | // Type of HLR |
1367 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
1368 | if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo) | |
1369 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo); | |
1370 | else | |
1371 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo); | |
c3282ec1 | 1372 | if (aContext->NbSelected()==0) |
0a768f56 | 1373 | { |
1374 | AIS_ListOfInteractive aListOfShapes; | |
1375 | aContext->DisplayedObjects(aListOfShapes); | |
1376 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); | |
1377 | anIter.More(); anIter.Next()) | |
1378 | { | |
1379 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
1380 | if (aShape.IsNull()) | |
1381 | continue; | |
1382 | if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1383 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1384 | else | |
1385 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
36132a2e | 1386 | aContext->Redisplay (aShape, Standard_False); |
0a768f56 | 1387 | } |
1388 | } | |
1389 | else | |
1390 | { | |
c3282ec1 | 1391 | for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()) |
0a768f56 | 1392 | { |
c3282ec1 | 1393 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive()); |
0a768f56 | 1394 | if (aShape.IsNull()) |
1395 | continue; | |
1396 | if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1397 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1398 | else | |
1399 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
36132a2e | 1400 | aContext->Redisplay (aShape, Standard_False); |
0a768f56 | 1401 | } |
1402 | } | |
1403 | ||
1404 | aContext->UpdateCurrentViewer(); | |
4269bd1b | 1405 | |
0a768f56 | 1406 | } |
b514beda | 1407 | else if (!strcasecmp (buf_ret, "S")) |
1408 | { | |
1409 | std::cout << "setup Shaded display mode" << std::endl; | |
4fe56619 | 1410 | |
7fd59977 | 1411 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
c3282ec1 | 1412 | if(Ctx->NbSelected()==0) |
7fd59977 | 1413 | Ctx->SetDisplayMode(AIS_Shaded); |
1414 | else{ | |
c3282ec1 | 1415 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) |
1416 | Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False); | |
7fd59977 | 1417 | Ctx->UpdateCurrentViewer(); |
1418 | } | |
1419 | } | |
b514beda | 1420 | else if (!strcasecmp (buf_ret, "U")) |
1421 | { | |
41811896 | 1422 | // Unset display mode |
b514beda | 1423 | std::cout << "reset display mode to defaults" << std::endl; |
4fe56619 | 1424 | |
7fd59977 | 1425 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
c3282ec1 | 1426 | if(Ctx->NbSelected()==0) |
7fd59977 | 1427 | Ctx->SetDisplayMode(AIS_WireFrame); |
1428 | else{ | |
c3282ec1 | 1429 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) |
1430 | Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False); | |
7fd59977 | 1431 | Ctx->UpdateCurrentViewer(); |
1432 | } | |
1433 | ||
1434 | } | |
b514beda | 1435 | else if (!strcasecmp (buf_ret, "T")) |
1436 | { | |
7fd59977 | 1437 | // Top |
1438 | aView->SetProj(V3d_Zpos); | |
1439 | } | |
b514beda | 1440 | else if (!strcasecmp (buf_ret, "B")) |
1441 | { | |
41811896 | 1442 | // Bottom |
7fd59977 | 1443 | aView->SetProj(V3d_Zneg); |
1444 | } | |
b514beda | 1445 | else if (!strcasecmp (buf_ret, "L")) |
1446 | { | |
41811896 | 1447 | // Left |
7fd59977 | 1448 | aView->SetProj(V3d_Xneg); |
1449 | } | |
b514beda | 1450 | else if (!strcasecmp (buf_ret, "R")) |
1451 | { | |
41811896 | 1452 | // Right |
7fd59977 | 1453 | aView->SetProj(V3d_Xpos); |
1454 | } | |
b514beda | 1455 | else if (!strcasecmp (buf_ret, "W")) |
1456 | { | |
1457 | std::cout << "setup WireFrame display mode" << std::endl; | |
7fd59977 | 1458 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
c3282ec1 | 1459 | if(Ctx->NbSelected()==0) |
7fd59977 | 1460 | Ctx->SetDisplayMode(AIS_WireFrame); |
1461 | else{ | |
c3282ec1 | 1462 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) |
1463 | Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False); | |
7fd59977 | 1464 | Ctx->UpdateCurrentViewer(); |
1465 | } | |
1466 | } | |
b514beda | 1467 | else if (!strcasecmp (buf_ret, "Z")) |
1468 | { | |
7fd59977 | 1469 | // ZCLIP |
7fd59977 | 1470 | if ( ZClipIsOn ) { |
1471 | cout << "ZClipping OFF" << endl; | |
1472 | ZClipIsOn = 0; | |
1473 | ||
1474 | aView->SetZClippingType(V3d_OFF); | |
1475 | aView->Redraw(); | |
1476 | } | |
1477 | else { | |
1478 | cout << "ZClipping ON" << endl; | |
1479 | ZClipIsOn = 1; | |
1480 | ||
1481 | aView->SetZClippingType(V3d_FRONT); | |
1482 | aView->Redraw(); | |
1483 | } | |
1484 | } | |
b514beda | 1485 | else if (!strcasecmp (buf_ret, ",")) |
1486 | { | |
7fd59977 | 1487 | ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView()); |
7fd59977 | 1488 | } |
b514beda | 1489 | else if (!strcasecmp (buf_ret, ".")) |
1490 | { | |
7fd59977 | 1491 | ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView()); |
1492 | } | |
f978241f | 1493 | else if (!strcasecmp (buf_ret, "/")) |
1494 | { | |
1495 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); | |
1496 | if (aCamera->IsStereo()) | |
1497 | { | |
1498 | aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01); | |
1499 | aView->Redraw(); | |
1500 | } | |
1501 | } | |
1502 | else if (!strcasecmp (buf_ret, "*")) | |
1503 | { | |
1504 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); | |
1505 | if (aCamera->IsStereo()) | |
1506 | { | |
1507 | aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01); | |
1508 | aView->Redraw(); | |
1509 | } | |
1510 | } | |
b514beda | 1511 | else if (*buf_ret == THE_KEY_DELETE) |
1512 | { | |
1513 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
1514 | if (!aCtx.IsNull() | |
b514beda | 1515 | && aCtx->NbSelected() > 0) |
1516 | { | |
1517 | Draw_Interprete ("verase"); | |
1518 | } | |
1519 | } | |
1520 | else | |
1521 | { | |
1522 | // Number | |
91322f44 | 1523 | Standard_Integer Num = Draw::Atoi(buf_ret); |
7fd59977 | 1524 | if(Num>=0 && Num<=7) |
1525 | ViewerTest::StandardModeActivation(Num); | |
1526 | } | |
1527 | } | |
1528 | ||
1529 | //============================================================================== | |
4fe56619 | 1530 | //function : VT_ProcessExpose |
7fd59977 | 1531 | //purpose : Redraw the View on an Expose Event |
1532 | //============================================================================== | |
4fe56619 | 1533 | void VT_ProcessExpose() |
1534 | { | |
1535 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); | |
1536 | if (!aView3d.IsNull()) | |
1537 | { | |
1538 | aView3d->Redraw(); | |
1539 | } | |
7fd59977 | 1540 | } |
1541 | ||
1542 | //============================================================================== | |
4fe56619 | 1543 | //function : VT_ProcessConfigure |
7fd59977 | 1544 | //purpose : Resize the View on an Configure Event |
1545 | //============================================================================== | |
4fe56619 | 1546 | void VT_ProcessConfigure() |
7fd59977 | 1547 | { |
4fe56619 | 1548 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); |
1549 | if (aView3d.IsNull()) | |
1550 | { | |
1551 | return; | |
1552 | } | |
1553 | ||
1554 | aView3d->MustBeResized(); | |
1555 | aView3d->Update(); | |
1556 | aView3d->Redraw(); | |
7fd59977 | 1557 | } |
1558 | ||
1559 | //============================================================================== | |
4fe56619 | 1560 | //function : VT_ProcessButton1Press |
7fd59977 | 1561 | //purpose : Picking |
1562 | //============================================================================== | |
e79a94b9 | 1563 | Standard_Boolean VT_ProcessButton1Press (Standard_Integer , |
1564 | const char** theArgVec, | |
1565 | Standard_Boolean theToPick, | |
1566 | Standard_Boolean theIsShift) | |
7fd59977 | 1567 | { |
e79a94b9 | 1568 | if (theToPick) |
1569 | { | |
7fd59977 | 1570 | Standard_Real X, Y, Z; |
e79a94b9 | 1571 | ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z); |
7fd59977 | 1572 | |
e79a94b9 | 1573 | Draw::Set (theArgVec[1], X); |
1574 | Draw::Set (theArgVec[2], Y); | |
1575 | Draw::Set (theArgVec[3], Z); | |
1576 | } | |
7fd59977 | 1577 | |
e79a94b9 | 1578 | if (theIsShift) |
1579 | { | |
1580 | ViewerTest::CurrentEventManager()->ShiftSelect(); | |
1581 | } | |
7fd59977 | 1582 | else |
e79a94b9 | 1583 | { |
1584 | ViewerTest::CurrentEventManager()->Select(); | |
1585 | } | |
7fd59977 | 1586 | |
e79a94b9 | 1587 | return Standard_False; |
7fd59977 | 1588 | } |
1589 | ||
1590 | //============================================================================== | |
4fe56619 | 1591 | //function : VT_ProcessButton1Release |
1592 | //purpose : End selecting | |
7fd59977 | 1593 | //============================================================================== |
4fe56619 | 1594 | void VT_ProcessButton1Release (Standard_Boolean theIsShift) |
1595 | { | |
1596 | if (IsDragged) | |
1597 | { | |
1598 | IsDragged = Standard_False; | |
1599 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1600 | if (theIsShift) | |
1601 | { | |
2157d6ac | 1602 | EM->ShiftSelect (X_ButtonPress, Y_ButtonPress, |
1603 | X_Motion, Y_Motion); | |
4fe56619 | 1604 | } |
1605 | else | |
1606 | { | |
2157d6ac | 1607 | EM->Select (X_ButtonPress, Y_ButtonPress, |
1608 | X_Motion, Y_Motion); | |
4fe56619 | 1609 | } |
1610 | } | |
1611 | } | |
7fd59977 | 1612 | |
4fe56619 | 1613 | //============================================================================== |
1614 | //function : VT_ProcessButton3Press | |
1615 | //purpose : Start Rotation | |
1616 | //============================================================================== | |
1617 | void VT_ProcessButton3Press() | |
1618 | { | |
7fd59977 | 1619 | Start_Rot = 1; |
de75ed09 | 1620 | if (MyHLRIsOn) |
1621 | { | |
1622 | ViewerTest::CurrentView()->SetComputedMode (Standard_False); | |
1623 | } | |
7fd59977 | 1624 | ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress ); |
7fd59977 | 1625 | } |
4fe56619 | 1626 | |
7fd59977 | 1627 | //============================================================================== |
4fe56619 | 1628 | //function : VT_ProcessButton3Release |
1629 | //purpose : End rotation | |
7fd59977 | 1630 | //============================================================================== |
4fe56619 | 1631 | void VT_ProcessButton3Release() |
1632 | { | |
1633 | if (Start_Rot) | |
1634 | { | |
7fd59977 | 1635 | Start_Rot = 0; |
de75ed09 | 1636 | if (MyHLRIsOn) |
1637 | { | |
1638 | ViewerTest::CurrentView()->SetComputedMode (Standard_True); | |
1639 | } | |
7fd59977 | 1640 | } |
7fd59977 | 1641 | } |
1642 | ||
1643 | //============================================================================== | |
1644 | //function : ProcessZClipMotion | |
1645 | //purpose : Zoom | |
1646 | //============================================================================== | |
1647 | ||
1648 | void ProcessZClipMotion() | |
1649 | { | |
1650 | Handle(V3d_View) a3DView = ViewerTest::CurrentView(); | |
1651 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { | |
7fd59977 | 1652 | |
1653 | //Quantity_Length VDX, VDY; | |
1654 | //a3DView->Size(VDX,VDY); | |
1655 | //Standard_Real VDZ = a3DView->ZSize(); | |
1656 | //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ); | |
1657 | ||
58978f9b | 1658 | Quantity_Length aDx = a3DView->Convert(X_Motion - X_ButtonPress); |
7fd59977 | 1659 | |
1660 | // Front = Depth + width/2. | |
58978f9b | 1661 | Standard_Real aDepth = 0.5; |
1662 | Standard_Real aWidth = 0.1; | |
1663 | a3DView->ZClipping(aDepth,aWidth); | |
7fd59977 | 1664 | |
58978f9b | 1665 | aDepth += aDx; |
7fd59977 | 1666 | |
1667 | //printf("dx %lf Depth %lf Width %lf\n", dx, D, W); | |
1668 | ||
58978f9b | 1669 | a3DView->SetZClippingDepth(aDepth); |
7fd59977 | 1670 | |
1671 | a3DView->Redraw(); | |
1672 | ||
1673 | X_ButtonPress = X_Motion; | |
1674 | Y_ButtonPress = Y_Motion; | |
1675 | } | |
1676 | } | |
1677 | ||
1678 | //============================================================================== | |
1679 | //function : ProcessControlButton1Motion | |
1680 | //purpose : Zoom | |
1681 | //============================================================================== | |
1682 | ||
900f7229 | 1683 | #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 1684 | static void ProcessControlButton1Motion() |
1685 | { | |
1686 | ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion); | |
1687 | ||
1688 | X_ButtonPress = X_Motion; | |
1689 | Y_ButtonPress = Y_Motion; | |
1690 | } | |
900f7229 | 1691 | #endif |
7fd59977 | 1692 | |
1693 | //============================================================================== | |
4fe56619 | 1694 | //function : VT_ProcessControlButton2Motion |
1695 | //purpose : Panning | |
7fd59977 | 1696 | //============================================================================== |
4fe56619 | 1697 | void VT_ProcessControlButton2Motion() |
7fd59977 | 1698 | { |
197ac94e | 1699 | Standard_Integer aDx = X_Motion - X_ButtonPress; |
1700 | Standard_Integer aDy = Y_Motion - Y_ButtonPress; | |
7fd59977 | 1701 | |
197ac94e | 1702 | aDy = -aDy; // Xwindow Y axis is from top to Bottom |
7fd59977 | 1703 | |
197ac94e | 1704 | ViewerTest::CurrentView()->Pan (aDx, aDy); |
7fd59977 | 1705 | |
1706 | X_ButtonPress = X_Motion; | |
1707 | Y_ButtonPress = Y_Motion; | |
1708 | } | |
1709 | ||
1710 | //============================================================================== | |
4fe56619 | 1711 | //function : VT_ProcessControlButton3Motion |
7fd59977 | 1712 | //purpose : Rotation |
1713 | //============================================================================== | |
4fe56619 | 1714 | void VT_ProcessControlButton3Motion() |
7fd59977 | 1715 | { |
4fe56619 | 1716 | if (Start_Rot) |
1717 | { | |
1718 | ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion); | |
1719 | } | |
7fd59977 | 1720 | } |
1721 | ||
1722 | //============================================================================== | |
4fe56619 | 1723 | //function : VT_ProcessMotion |
1724 | //purpose : | |
7fd59977 | 1725 | //============================================================================== |
4fe56619 | 1726 | void VT_ProcessMotion() |
7fd59977 | 1727 | { |
1728 | //pre-hilights detected objects at mouse position | |
1729 | ||
1730 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1731 | EM->MoveTo(X_Motion, Y_Motion); | |
1732 | } | |
1733 | ||
1734 | ||
1735 | void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix) | |
1736 | { | |
1737 | Xpix = X_Motion;Ypix=Y_Motion; | |
1738 | } | |
1739 | ||
44b8f2d6 | 1740 | //============================================================================== |
1741 | //function : ViewProject: implements VAxo, VTop, VLeft, ... | |
1742 | //purpose : Switches to an axonometric, top, left and other views | |
1743 | //============================================================================== | |
1744 | ||
1745 | static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori) | |
1746 | { | |
4fe56619 | 1747 | if ( ViewerTest::CurrentView().IsNull() ) |
44b8f2d6 | 1748 | { |
586db386 | 1749 | di<<"Call vinit before this command, please\n"; |
44b8f2d6 | 1750 | return 1; |
1751 | } | |
1752 | ||
1753 | ViewerTest::CurrentView()->SetProj(ori); | |
1754 | return 0; | |
1755 | } | |
1756 | ||
7fd59977 | 1757 | //============================================================================== |
1758 | //function : VAxo | |
1759 | //purpose : Switch to an Axonometric view | |
1760 | //Draw arg : No args | |
1761 | //============================================================================== | |
1762 | ||
1763 | static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** ) | |
44b8f2d6 | 1764 | { |
1765 | return ViewProject(di, V3d_XposYnegZpos); | |
7fd59977 | 1766 | } |
1767 | ||
1768 | //============================================================================== | |
1769 | //function : VTop | |
1770 | //purpose : Switch to a Top View | |
1771 | //Draw arg : No args | |
1772 | //============================================================================== | |
1773 | ||
1774 | static int VTop(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1775 | { | |
44b8f2d6 | 1776 | return ViewProject(di, V3d_Zpos); |
1777 | } | |
7fd59977 | 1778 | |
44b8f2d6 | 1779 | //============================================================================== |
1780 | //function : VBottom | |
1781 | //purpose : Switch to a Bottom View | |
1782 | //Draw arg : No args | |
1783 | //============================================================================== | |
7fd59977 | 1784 | |
44b8f2d6 | 1785 | static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** ) |
1786 | { | |
1787 | return ViewProject(di, V3d_Zneg); | |
1788 | } | |
7fd59977 | 1789 | |
44b8f2d6 | 1790 | //============================================================================== |
1791 | //function : VLeft | |
1792 | //purpose : Switch to a Left View | |
1793 | //Draw arg : No args | |
1794 | //============================================================================== | |
1795 | ||
1796 | static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1797 | { | |
27af3052 | 1798 | return ViewProject(di, V3d_Xneg); |
44b8f2d6 | 1799 | } |
1800 | ||
1801 | //============================================================================== | |
1802 | //function : VRight | |
1803 | //purpose : Switch to a Right View | |
1804 | //Draw arg : No args | |
1805 | //============================================================================== | |
1806 | ||
1807 | static int VRight(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1808 | { | |
27af3052 | 1809 | return ViewProject(di, V3d_Xpos); |
44b8f2d6 | 1810 | } |
7fd59977 | 1811 | |
44b8f2d6 | 1812 | //============================================================================== |
1813 | //function : VFront | |
1814 | //purpose : Switch to a Front View | |
1815 | //Draw arg : No args | |
1816 | //============================================================================== | |
1817 | ||
1818 | static int VFront(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1819 | { | |
27af3052 | 1820 | return ViewProject(di, V3d_Yneg); |
44b8f2d6 | 1821 | } |
1822 | ||
1823 | //============================================================================== | |
1824 | //function : VBack | |
1825 | //purpose : Switch to a Back View | |
1826 | //Draw arg : No args | |
1827 | //============================================================================== | |
1828 | ||
1829 | static int VBack(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1830 | { | |
27af3052 | 1831 | return ViewProject(di, V3d_Ypos); |
7fd59977 | 1832 | } |
1833 | ||
1834 | //============================================================================== | |
1835 | //function : VHelp | |
1836 | //purpose : Dsiplay help on viewer Keyboead and mouse commands | |
1837 | //Draw arg : No args | |
1838 | //============================================================================== | |
1839 | ||
1840 | static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1841 | { | |
1842 | ||
586db386 | 1843 | di << "Q : Quit the application\n"; |
1844 | ||
1845 | di << "=========================\n"; | |
1846 | di << "F : FitAll\n"; | |
1847 | di << "T : TopView\n"; | |
1848 | di << "B : BottomView\n"; | |
1849 | di << "R : RightView\n"; | |
1850 | di << "L : LeftView\n"; | |
1851 | di << "A : AxonometricView\n"; | |
1852 | di << "D : ResetView\n"; | |
1853 | ||
1854 | di << "=========================\n"; | |
1855 | di << "S : Shading\n"; | |
1856 | di << "W : Wireframe\n"; | |
1857 | di << "H : HidelLineRemoval\n"; | |
1858 | di << "U : Unset display mode\n"; | |
1859 | di << "Delete : Remove selection from viewer\n"; | |
1860 | ||
1861 | di << "=========================\n"; | |
1862 | di << "Selection mode \n"; | |
1863 | di << "0 : Shape\n"; | |
1864 | di << "1 : Vertex\n"; | |
1865 | di << "2 : Edge\n"; | |
1866 | di << "3 : Wire\n"; | |
1867 | di << "4 : Face\n"; | |
1868 | di << "5 : Shell\n"; | |
1869 | di << "6 : Solid\n"; | |
1870 | di << "7 : Compound\n"; | |
1871 | ||
1872 | di << "=========================\n"; | |
1873 | di << "Z : Switch Z clipping On/Off\n"; | |
1874 | di << ", : Hilight next detected\n"; | |
1875 | di << ". : Hilight previous detected\n"; | |
7fd59977 | 1876 | |
1877 | return 0; | |
1878 | } | |
1879 | ||
57c28b61 | 1880 | #ifdef _WIN32 |
7fd59977 | 1881 | |
1882 | static Standard_Boolean Ppick = 0; | |
1883 | static Standard_Integer Pargc = 0; | |
1884 | static const char** Pargv = NULL; | |
1885 | ||
1886 | ||
1887 | static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd, | |
1888 | UINT Msg, | |
1889 | WPARAM wParam, | |
1890 | LPARAM lParam ) | |
1891 | { | |
18d715bd | 1892 | if (!ViewerTest_myViews.IsEmpty()) { |
7fd59977 | 1893 | |
1894 | WPARAM fwKeys = wParam; | |
1895 | ||
1896 | switch( Msg ) { | |
18d715bd | 1897 | case WM_CLOSE: |
1898 | { | |
1899 | // Delete view from map of views | |
1900 | ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd)); | |
1901 | return 0; | |
1902 | } | |
1903 | break; | |
1904 | case WM_ACTIVATE: | |
1905 | if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE | |
1906 | || ViewerTest::CurrentView().IsNull()) | |
1907 | { | |
1908 | // Activate inactive window | |
1909 | if(GetWindowHandle(VT_GetWindow()) != hwnd) | |
1910 | { | |
1911 | ActivateView (FindViewIdByWindowHandle(hwnd)); | |
1912 | } | |
1913 | } | |
1914 | break; | |
7fd59977 | 1915 | case WM_LBUTTONUP: |
8abada55 | 1916 | if (!DragFirst) |
7fd59977 | 1917 | { |
b12e1c7b | 1918 | if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand())) |
1919 | { | |
1920 | ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False); | |
1921 | ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate(); | |
1922 | } | |
1923 | ||
8abada55 | 1924 | VT_ProcessButton1Release (fwKeys & MK_SHIFT); |
7fd59977 | 1925 | } |
8abada55 | 1926 | IsDragged = Standard_False; |
7fd59977 | 1927 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); |
1928 | ||
1929 | case WM_LBUTTONDOWN: | |
1930 | if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) ) | |
1931 | { | |
1932 | IsDragged = Standard_True; | |
1933 | DragFirst = Standard_True; | |
4fe56619 | 1934 | X_ButtonPress = LOWORD(lParam); |
1935 | Y_ButtonPress = HIWORD(lParam); | |
7fd59977 | 1936 | } |
1937 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1938 | ||
1939 | break; | |
1940 | ||
1941 | case WM_MOUSEMOVE: | |
b12e1c7b | 1942 | if (IsDragged) |
7fd59977 | 1943 | { |
69adb9ce | 1944 | bool toRedraw = false; |
b12e1c7b | 1945 | if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand())) |
1946 | { | |
1947 | ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False); | |
69adb9ce | 1948 | toRedraw = true; |
b12e1c7b | 1949 | } |
7fd59977 | 1950 | |
1951 | DragFirst = Standard_False; | |
b12e1c7b | 1952 | X_Motion = LOWORD (lParam); |
1953 | Y_Motion = HIWORD (lParam); | |
7fd59977 | 1954 | |
b12e1c7b | 1955 | RECT aRect; |
1956 | if (GetClientRect (hwnd, &aRect)) | |
1957 | { | |
1958 | int aHeight = aRect.bottom - aRect.top; | |
1959 | GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion); | |
69adb9ce | 1960 | ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed); |
1961 | toRedraw = true; | |
1962 | } | |
1963 | if (toRedraw) | |
1964 | { | |
b12e1c7b | 1965 | ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate(); |
1966 | } | |
7fd59977 | 1967 | } |
1968 | else | |
1969 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1970 | break; | |
1971 | ||
1972 | default: | |
1973 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1974 | } | |
1975 | return 0; | |
1976 | } | |
1977 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1978 | } | |
1979 | ||
1980 | ||
1981 | static LRESULT WINAPI ViewerWindowProc( HWND hwnd, | |
1982 | UINT Msg, | |
1983 | WPARAM wParam, | |
1984 | LPARAM lParam ) | |
1985 | { | |
7fd59977 | 1986 | static int Up = 1; |
f978241f | 1987 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); |
1988 | if (aView.IsNull()) | |
1989 | { | |
1990 | return DefWindowProc( hwnd, Msg, wParam, lParam ); | |
1991 | } | |
7fd59977 | 1992 | |
7fd59977 | 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; |
f978241f | 2005 | case WM_MOVE: |
2006 | case WM_MOVING: | |
2007 | case WM_SIZING: | |
2008 | switch (aView->RenderingParams().StereoMode) | |
2009 | { | |
2010 | case Graphic3d_StereoMode_RowInterlaced: | |
2011 | case Graphic3d_StereoMode_ColumnInterlaced: | |
2012 | case Graphic3d_StereoMode_ChessBoard: | |
2013 | VT_ProcessConfigure(); // track window moves to reverse stereo pair | |
2014 | break; | |
2015 | default: | |
2016 | break; | |
2017 | } | |
2018 | break; | |
7fd59977 | 2019 | |
2020 | case WM_KEYDOWN: | |
4fe56619 | 2021 | if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL)) |
2022 | { | |
7fd59977 | 2023 | char c[2]; |
2024 | c[0] = (char) wParam; | |
2025 | c[1] = '\0'; | |
b514beda | 2026 | if (wParam == VK_DELETE) |
2027 | { | |
2028 | c[0] = THE_KEY_DELETE; | |
2029 | } | |
4ca4bbe8 | 2030 | // comma |
2031 | else if (wParam == VK_OEM_COMMA) | |
2032 | { | |
2033 | c[0] = ','; | |
2034 | } | |
2035 | // dot | |
2036 | else if (wParam == VK_OEM_PERIOD) | |
2037 | { | |
2038 | c[0] = '.'; | |
2039 | } | |
f978241f | 2040 | else if (wParam == VK_DIVIDE) |
2041 | { | |
2042 | c[0] = '/'; | |
2043 | } | |
2044 | // dot | |
2045 | else if (wParam == VK_MULTIPLY) | |
2046 | { | |
2047 | c[0] = '*'; | |
2048 | } | |
4fe56619 | 2049 | VT_ProcessKeyPress (c); |
7fd59977 | 2050 | } |
2051 | break; | |
2052 | ||
2053 | case WM_LBUTTONUP: | |
2054 | case WM_MBUTTONUP: | |
2055 | case WM_RBUTTONUP: | |
7fd59977 | 2056 | Up = 1; |
4fe56619 | 2057 | VT_ProcessButton3Release(); |
7fd59977 | 2058 | break; |
2059 | ||
2060 | case WM_LBUTTONDOWN: | |
2061 | case WM_MBUTTONDOWN: | |
2062 | case WM_RBUTTONDOWN: | |
2063 | { | |
7fd59977 | 2064 | WPARAM fwKeys = wParam; |
2065 | ||
2066 | Up = 0; | |
2067 | ||
2068 | X_ButtonPress = LOWORD(lParam); | |
2069 | Y_ButtonPress = HIWORD(lParam); | |
2070 | ||
4fe56619 | 2071 | if (Msg == WM_LBUTTONDOWN) |
2072 | { | |
2073 | if (fwKeys & MK_CONTROL) | |
2074 | { | |
2075 | Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT)); | |
2076 | } | |
2077 | else | |
2078 | { | |
2079 | VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT)); | |
2080 | } | |
7fd59977 | 2081 | } |
4fe56619 | 2082 | else if (Msg == WM_RBUTTONDOWN) |
2083 | { | |
7fd59977 | 2084 | // Start rotation |
4fe56619 | 2085 | VT_ProcessButton3Press(); |
7fd59977 | 2086 | } |
2087 | } | |
2088 | break; | |
2089 | ||
f978241f | 2090 | case WM_MOUSEWHEEL: |
2091 | { | |
2092 | int aDelta = GET_WHEEL_DELTA_WPARAM (wParam); | |
2093 | if (wParam & MK_CONTROL) | |
2094 | { | |
2095 | if (aView->Camera()->IsStereo()) | |
2096 | { | |
2097 | Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05); | |
2098 | if (aFocus > 0.2 | |
2099 | && aFocus < 2.0) | |
2100 | { | |
2101 | aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus); | |
2102 | aView->Redraw(); | |
2103 | } | |
2104 | } | |
2105 | } | |
2106 | else | |
2107 | { | |
2108 | aView->Zoom (0, 0, aDelta / 40, aDelta / 40); | |
2109 | } | |
2110 | break; | |
2111 | } | |
2112 | ||
7fd59977 | 2113 | case WM_MOUSEMOVE: |
2114 | { | |
2115 | //cout << "\t WM_MOUSEMOVE" << endl; | |
2116 | WPARAM fwKeys = wParam; | |
2117 | X_Motion = LOWORD(lParam); | |
2118 | Y_Motion = HIWORD(lParam); | |
2119 | ||
2120 | if ( Up && | |
2121 | fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) { | |
2122 | Up = 0; | |
2123 | X_ButtonPress = LOWORD(lParam); | |
2124 | Y_ButtonPress = HIWORD(lParam); | |
2125 | ||
2126 | if ( fwKeys & MK_RBUTTON ) { | |
2127 | // Start rotation | |
4fe56619 | 2128 | VT_ProcessButton3Press(); |
7fd59977 | 2129 | } |
2130 | } | |
2131 | ||
2132 | if ( fwKeys & MK_CONTROL ) { | |
2133 | if ( fwKeys & MK_LBUTTON ) { | |
2134 | ProcessControlButton1Motion(); | |
2135 | } | |
2136 | else if ( fwKeys & MK_MBUTTON || | |
2137 | ((fwKeys&MK_LBUTTON) && | |
2138 | (fwKeys&MK_RBUTTON) ) ){ | |
4fe56619 | 2139 | VT_ProcessControlButton2Motion(); |
7fd59977 | 2140 | } |
2141 | else if ( fwKeys & MK_RBUTTON ) { | |
4fe56619 | 2142 | VT_ProcessControlButton3Motion(); |
7fd59977 | 2143 | } |
2144 | } | |
2145 | #ifdef BUG | |
2146 | else if ( fwKeys & MK_SHIFT ) { | |
2147 | if ( fwKeys & MK_MBUTTON || | |
2148 | ((fwKeys&MK_LBUTTON) && | |
2149 | (fwKeys&MK_RBUTTON) ) ) { | |
2150 | cout << "ProcessZClipMotion()" << endl; | |
2151 | ProcessZClipMotion(); | |
2152 | } | |
2153 | } | |
2154 | #endif | |
08398024 | 2155 | else if (GetWindowHandle (VT_GetWindow()) == hwnd) |
2156 | { | |
4fe56619 | 2157 | if ((fwKeys & MK_MBUTTON |
2158 | || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON)))) | |
2159 | { | |
7fd59977 | 2160 | ProcessZClipMotion(); |
2161 | } | |
4fe56619 | 2162 | else |
2163 | { | |
2164 | VT_ProcessMotion(); | |
7fd59977 | 2165 | } |
08398024 | 2166 | } |
7fd59977 | 2167 | } |
2168 | break; | |
2169 | ||
2170 | default: | |
2171 | return( DefWindowProc( hwnd, Msg, wParam, lParam )); | |
2172 | } | |
2173 | return 0L; | |
7fd59977 | 2174 | } |
2175 | ||
2176 | ||
2177 | ||
2178 | ||
2179 | //============================================================================== | |
2180 | //function : ViewerMainLoop | |
2181 | //purpose : Get a Event on the view and dispatch it | |
2182 | //============================================================================== | |
2183 | ||
2184 | ||
8263fcd3 | 2185 | int ViewerMainLoop(Standard_Integer argc, const char** argv) |
7fd59977 | 2186 | { |
7fd59977 | 2187 | Ppick = (argc > 0)? 1 : 0; |
2188 | Pargc = argc; | |
2189 | Pargv = argv; | |
2190 | ||
2191 | if ( Ppick ) { | |
2192 | MSG msg; | |
2193 | msg.wParam = 1; | |
2194 | ||
2195 | cout << "Start picking" << endl; | |
2196 | ||
7fd59977 | 2197 | while ( Ppick == 1 ) { |
4fe56619 | 2198 | // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0 |
7fd59977 | 2199 | if (GetMessage(&msg, NULL, 0, 0) ) { |
2200 | TranslateMessage(&msg); | |
2201 | DispatchMessage(&msg); | |
2202 | } | |
2203 | } | |
2204 | ||
2205 | cout << "Picking done" << endl; | |
2206 | } | |
2207 | ||
2208 | return Ppick; | |
2209 | } | |
2210 | ||
4fe56619 | 2211 | #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 2212 | |
2213 | int min( int a, int b ) | |
2214 | { | |
2215 | if( a<b ) | |
2216 | return a; | |
2217 | else | |
2218 | return b; | |
2219 | } | |
2220 | ||
2221 | int max( int a, int b ) | |
2222 | { | |
2223 | if( a>b ) | |
2224 | return a; | |
2225 | else | |
2226 | return b; | |
2227 | } | |
2228 | ||
2229 | int ViewerMainLoop(Standard_Integer argc, const char** argv) | |
2230 | ||
4269bd1b | 2231 | { |
18d715bd | 2232 | static XEvent aReport; |
2233 | Standard_Boolean pick = argc > 0; | |
2234 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2235 | XNextEvent (aDisplay, &aReport); | |
7fd59977 | 2236 | |
18d715bd | 2237 | // Handle event for the chosen display connection |
2238 | switch (aReport.type) { | |
2239 | case ClientMessage: | |
2240 | { | |
eb1ebea4 | 2241 | if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW)) |
18d715bd | 2242 | { |
2243 | // Close the window | |
2244 | ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window)); | |
2245 | } | |
2246 | } | |
2247 | return 0; | |
2248 | case FocusIn: | |
2249 | { | |
2250 | // Activate inactive view | |
2251 | Window aWindow = GetWindowHandle(VT_GetWindow()); | |
2252 | if(aWindow != aReport.xfocus.window) | |
2253 | { | |
2254 | ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window)); | |
2255 | } | |
2256 | } | |
2257 | break; | |
7fd59977 | 2258 | case Expose: |
2259 | { | |
4fe56619 | 2260 | VT_ProcessExpose(); |
7fd59977 | 2261 | } |
2262 | break; | |
2263 | case ConfigureNotify: | |
2264 | { | |
4fe56619 | 2265 | VT_ProcessConfigure(); |
7fd59977 | 2266 | } |
2267 | break; | |
2268 | case KeyPress: | |
2269 | { | |
2270 | ||
2271 | KeySym ks_ret ; | |
2272 | char buf_ret[11] ; | |
2273 | int ret_len ; | |
2274 | XComposeStatus status_in_out; | |
2275 | ||
18d715bd | 2276 | ret_len = XLookupString( ( XKeyEvent *)&aReport , |
7fd59977 | 2277 | (char *) buf_ret , 10 , |
2278 | &ks_ret , &status_in_out ) ; | |
2279 | ||
2280 | ||
2281 | buf_ret[ret_len] = '\0' ; | |
2282 | ||
4fe56619 | 2283 | if (ret_len) |
2284 | { | |
2285 | VT_ProcessKeyPress (buf_ret); | |
7fd59977 | 2286 | } |
2287 | } | |
2288 | break; | |
2289 | case ButtonPress: | |
7fd59977 | 2290 | { |
18d715bd | 2291 | X_ButtonPress = aReport.xbutton.x; |
2292 | Y_ButtonPress = aReport.xbutton.y; | |
7fd59977 | 2293 | |
18d715bd | 2294 | if (aReport.xbutton.button == Button1) |
4fe56619 | 2295 | { |
18d715bd | 2296 | if (aReport.xbutton.state & ControlMask) |
4fe56619 | 2297 | { |
18d715bd | 2298 | pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask)); |
4fe56619 | 2299 | } |
7fd59977 | 2300 | else |
2301 | { | |
2302 | IsDragged = Standard_True; | |
7fd59977 | 2303 | DragFirst = Standard_True; |
2304 | } | |
4fe56619 | 2305 | } |
18d715bd | 2306 | else if (aReport.xbutton.button == Button3) |
4fe56619 | 2307 | { |
7fd59977 | 2308 | // Start rotation |
4fe56619 | 2309 | VT_ProcessButton3Press(); |
2310 | } | |
7fd59977 | 2311 | } |
2312 | break; | |
2313 | case ButtonRelease: | |
2314 | { | |
7fd59977 | 2315 | if( IsDragged ) |
2316 | { | |
2317 | if( !DragFirst ) | |
2318 | { | |
b12e1c7b | 2319 | if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand())) |
2320 | { | |
2321 | ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False); | |
2322 | ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate(); | |
2323 | } | |
7fd59977 | 2324 | } |
2325 | ||
2326 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
2327 | if( aContext.IsNull() ) | |
2328 | { | |
2329 | cout << "The context is null. Please use vinit before createmesh" << endl; | |
2330 | return 0; | |
2331 | } | |
2332 | ||
18d715bd | 2333 | Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask ); |
2334 | if( aReport.xbutton.button==1 ) | |
7fd59977 | 2335 | if( DragFirst ) |
2336 | if( ShiftPressed ) | |
2337 | { | |
2338 | aContext->ShiftSelect(); | |
7fd59977 | 2339 | } |
2340 | else | |
2341 | { | |
2342 | aContext->Select(); | |
7fd59977 | 2343 | } |
2344 | else | |
2345 | if( ShiftPressed ) | |
2346 | { | |
4fe56619 | 2347 | aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), |
2348 | max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), | |
7fd59977 | 2349 | ViewerTest::CurrentView()); |
7fd59977 | 2350 | } |
2351 | else | |
2352 | { | |
4fe56619 | 2353 | aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), |
2354 | max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), | |
7fd59977 | 2355 | ViewerTest::CurrentView() ); |
7fd59977 | 2356 | } |
2357 | else | |
4fe56619 | 2358 | VT_ProcessButton3Release(); |
7fd59977 | 2359 | |
2360 | IsDragged = Standard_False; | |
2361 | } | |
2362 | else | |
4fe56619 | 2363 | VT_ProcessButton3Release(); |
7fd59977 | 2364 | } |
2365 | break; | |
2366 | case MotionNotify: | |
2367 | { | |
08398024 | 2368 | if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window) |
2369 | { | |
2370 | break; | |
2371 | } | |
7fd59977 | 2372 | if( IsDragged ) |
2373 | { | |
7fd59977 | 2374 | if( !DragFirst ) |
b12e1c7b | 2375 | { |
2376 | if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand())) | |
2377 | { | |
2378 | ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False); | |
b12e1c7b | 2379 | } |
2380 | } | |
7fd59977 | 2381 | |
18d715bd | 2382 | X_Motion = aReport.xmotion.x; |
2383 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2384 | DragFirst = Standard_False; |
2385 | ||
b12e1c7b | 2386 | Window aWindow = GetWindowHandle(VT_GetWindow()); |
2387 | Window aRoot; | |
2388 | int anX, anY; | |
2389 | unsigned int aWidth, aHeight, aBorderWidth, aDepth; | |
2390 | XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth); | |
2391 | GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion); | |
69adb9ce | 2392 | ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed); |
b12e1c7b | 2393 | ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate(); |
7fd59977 | 2394 | } |
2395 | else | |
2396 | { | |
18d715bd | 2397 | X_Motion = aReport.xmotion.x; |
2398 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2399 | |
18d715bd | 2400 | // remove all the ButtonMotionMaskr |
2401 | while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ; | |
7fd59977 | 2402 | |
18d715bd | 2403 | if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) { |
7fd59977 | 2404 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { |
2405 | ||
2406 | Quantity_Length VDX, VDY; | |
2407 | ||
2408 | ViewerTest::CurrentView()->Size(VDX,VDY); | |
2409 | Standard_Real VDZ =0 ; | |
2410 | VDZ = ViewerTest::CurrentView()->ZSize(); | |
2411 | ||
7fd59977 | 2412 | printf("%f,%f,%f\n", VDX, VDY, VDZ); |
2413 | ||
2414 | Quantity_Length dx = 0 ; | |
2415 | dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress); | |
2416 | ||
2417 | cout << dx << endl; | |
2418 | ||
2419 | dx = dx / VDX * VDZ; | |
2420 | ||
2421 | cout << dx << endl; | |
2422 | ||
7fd59977 | 2423 | ViewerTest::CurrentView()->Redraw(); |
2424 | } | |
2425 | } | |
2426 | ||
18d715bd | 2427 | if ( aReport.xmotion.state & ControlMask ) { |
2428 | if ( aReport.xmotion.state & Button1Mask ) { | |
7fd59977 | 2429 | ProcessControlButton1Motion(); |
2430 | } | |
18d715bd | 2431 | else if ( aReport.xmotion.state & Button2Mask ) { |
4fe56619 | 2432 | VT_ProcessControlButton2Motion(); |
7fd59977 | 2433 | } |
18d715bd | 2434 | else if ( aReport.xmotion.state & Button3Mask ) { |
4fe56619 | 2435 | VT_ProcessControlButton3Motion(); |
7fd59977 | 2436 | } |
2437 | } | |
4fe56619 | 2438 | else |
2439 | { | |
2440 | VT_ProcessMotion(); | |
7fd59977 | 2441 | } |
2442 | } | |
2443 | } | |
2444 | break; | |
2445 | } | |
7fd59977 | 2446 | return pick; |
2447 | } | |
2448 | ||
2449 | //============================================================================== | |
2450 | //function : VProcessEvents | |
2451 | //purpose : call by Tk_CreateFileHandler() to be able to manage the | |
2452 | // event in the Viewer window | |
2453 | //============================================================================== | |
2454 | ||
2455 | static void VProcessEvents(ClientData,int) | |
2456 | { | |
18d715bd | 2457 | NCollection_Vector<int> anEventNumbers; |
2458 | // Get number of messages from every display | |
2459 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2460 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next()) | |
2461 | { | |
2462 | anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay())); | |
4269bd1b | 2463 | } |
18d715bd | 2464 | // Handle events for every display |
2465 | int anEventIter = 0; | |
2466 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2467 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++) | |
2468 | { | |
4269bd1b | 2469 | for (int i = 0; i < anEventNumbers.Value(anEventIter) && |
18d715bd | 2470 | XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i) |
2471 | { | |
2472 | SetDisplayConnection (anIter.Key2()->GetDisplayConnection()); | |
2473 | int anEventResult = ViewerMainLoop( 0, NULL); | |
2474 | // If window is closed or context was not found finish current event processing loop | |
2475 | if (!anEventResult) | |
2476 | return; | |
2477 | } | |
7fd59977 | 2478 | } |
4269bd1b | 2479 | |
18d715bd | 2480 | SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection()); |
4269bd1b | 2481 | |
7fd59977 | 2482 | } |
2483 | #endif | |
2484 | ||
2485 | //============================================================================== | |
2486 | //function : OSWindowSetup | |
2487 | //purpose : Setup for the X11 window to be able to cath the event | |
2488 | //============================================================================== | |
2489 | ||
2490 | ||
2491 | static void OSWindowSetup() | |
2492 | { | |
4fe56619 | 2493 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
7fd59977 | 2494 | // X11 |
2495 | ||
2496 | Window window = VT_GetWindow()->XWindow(); | |
18d715bd | 2497 | SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
2498 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2499 | XSynchronize(aDisplay, 1); | |
7fd59977 | 2500 | |
2501 | // X11 : For keyboard on SUN | |
2502 | XWMHints wmhints; | |
2503 | wmhints.flags = InputHint; | |
2504 | wmhints.input = 1; | |
2505 | ||
18d715bd | 2506 | XSetWMHints( aDisplay, window, &wmhints); |
7fd59977 | 2507 | |
18d715bd | 2508 | XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | |
7fd59977 | 2509 | ButtonPressMask | ButtonReleaseMask | |
2510 | StructureNotifyMask | | |
2511 | PointerMotionMask | | |
2512 | Button1MotionMask | Button2MotionMask | | |
18d715bd | 2513 | Button3MotionMask | FocusChangeMask |
7fd59977 | 2514 | ); |
18d715bd | 2515 | Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW); |
2516 | XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1); | |
7fd59977 | 2517 | |
18d715bd | 2518 | XSynchronize(aDisplay, 0); |
7fd59977 | 2519 | |
2520 | #else | |
57c28b61 | 2521 | // _WIN32 |
7fd59977 | 2522 | #endif |
2523 | ||
2524 | } | |
2525 | ||
7fd59977 | 2526 | //============================================================================== |
2527 | //function : VFit | |
2528 | ||
2529 | //purpose : Fitall, no DRAW arguments | |
2530 | //Draw arg : No args | |
2531 | //============================================================================== | |
2532 | ||
b586500b | 2533 | static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgc, const char** theArgv) |
7fd59977 | 2534 | { |
b586500b | 2535 | if (theArgc > 2) |
2536 | { | |
2537 | std::cout << "Wrong number of arguments! Use: vfit [-selected]" << std::endl; | |
2538 | } | |
2539 | ||
7fd59977 | 2540 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); |
b586500b | 2541 | |
2542 | if (theArgc == 2) | |
2543 | { | |
2544 | TCollection_AsciiString anArg (theArgv[1]); | |
2545 | anArg.LowerCase(); | |
2546 | if (anArg == "-selected") | |
2547 | { | |
fb64064b | 2548 | ViewerTest::GetAISContext()->FitSelected (aView); |
b586500b | 2549 | return 0; |
2550 | } | |
2551 | } | |
fb64064b | 2552 | if (aView.IsNull() == Standard_False) { |
b586500b | 2553 | |
7fd59977 | 2554 | aView->FitAll(); |
2555 | } | |
2556 | return 0; | |
2557 | } | |
2558 | ||
6262a303 | 2559 | //======================================================================= |
2560 | //function : VFitArea | |
2561 | //purpose : Fit view to show area located between two points | |
2562 | // : given in world 2D or 3D coordinates. | |
2563 | //======================================================================= | |
2564 | static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
2565 | { | |
2566 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
2567 | if (aView.IsNull()) | |
2568 | { | |
2569 | std::cerr << theArgVec[0] << "Error: No active view.\n"; | |
2570 | return 1; | |
2571 | } | |
2572 | ||
2573 | // Parse arguments. | |
2574 | gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0); | |
2575 | gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0); | |
2576 | ||
2577 | if (theArgNb == 5) | |
2578 | { | |
2579 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
2580 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
2581 | aWorldPnt2.SetX (Draw::Atof (theArgVec[3])); | |
2582 | aWorldPnt2.SetY (Draw::Atof (theArgVec[4])); | |
2583 | } | |
2584 | else if (theArgNb == 7) | |
2585 | { | |
2586 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
2587 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
2588 | aWorldPnt1.SetZ (Draw::Atof (theArgVec[3])); | |
2589 | aWorldPnt2.SetX (Draw::Atof (theArgVec[4])); | |
2590 | aWorldPnt2.SetY (Draw::Atof (theArgVec[5])); | |
2591 | aWorldPnt2.SetZ (Draw::Atof (theArgVec[6])); | |
2592 | } | |
2593 | else | |
2594 | { | |
2595 | std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n"; | |
2596 | theDI.PrintHelp(theArgVec[0]); | |
2597 | return 1; | |
2598 | } | |
2599 | ||
2600 | // Convert model coordinates to view space | |
2601 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); | |
2602 | gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1); | |
2603 | gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2); | |
2604 | ||
2605 | // Determine fit area | |
2606 | gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y())); | |
2607 | gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y())); | |
2608 | ||
2609 | Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner); | |
2610 | ||
2611 | if (aDiagonal < Precision::Confusion()) | |
2612 | { | |
2613 | std::cerr << theArgVec[0] << "Error: view area is too small.\n"; | |
2614 | return 1; | |
2615 | } | |
2616 | ||
2617 | aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y()); | |
2618 | return 0; | |
2619 | } | |
2620 | ||
7fd59977 | 2621 | //============================================================================== |
2622 | //function : VZFit | |
2623 | //purpose : ZFitall, no DRAW arguments | |
2624 | //Draw arg : No args | |
2625 | //============================================================================== | |
197ac94e | 2626 | static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 2627 | { |
197ac94e | 2628 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
2629 | ||
2630 | if (aCurrentView.IsNull()) | |
2631 | { | |
2632 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; | |
2633 | return 1; | |
2634 | } | |
2635 | ||
2636 | if (theArgsNb == 1) | |
2637 | { | |
c357e426 | 2638 | aCurrentView->ZFitAll(); |
197ac94e | 2639 | aCurrentView->Redraw(); |
2640 | return 0; | |
2641 | } | |
2642 | ||
2643 | Standard_Real aScale = 1.0; | |
2644 | ||
2645 | if (theArgsNb >= 2) | |
2646 | { | |
2647 | aScale = Draw::Atoi (theArgVec[1]); | |
2648 | } | |
2649 | ||
c357e426 | 2650 | aCurrentView->ZFitAll (aScale); |
197ac94e | 2651 | aCurrentView->Redraw(); |
7fd59977 | 2652 | |
197ac94e | 2653 | return 0; |
2654 | } | |
7fd59977 | 2655 | |
197ac94e | 2656 | //============================================================================== |
2657 | //function : VRepaint | |
2658 | //purpose : | |
2659 | //============================================================================== | |
2660 | static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** ) | |
7fd59977 | 2661 | { |
2662 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
2663 | if ( !V.IsNull() ) V->Redraw(); return 0; | |
2664 | } | |
2665 | ||
7fd59977 | 2666 | //============================================================================== |
2667 | //function : VClear | |
2668 | //purpose : Remove all the object from the viewer | |
2669 | //Draw arg : No args | |
2670 | //============================================================================== | |
2671 | ||
2672 | static int VClear(Draw_Interpretor& , Standard_Integer , const char** ) | |
2673 | { | |
2674 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
2675 | if(!V.IsNull()) | |
2676 | ViewerTest::Clear(); | |
2677 | return 0; | |
2678 | } | |
2679 | ||
2680 | //============================================================================== | |
2681 | //function : VPick | |
2682 | //purpose : | |
2683 | //============================================================================== | |
2684 | ||
2685 | static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2686 | { if (ViewerTest::CurrentView().IsNull() ) return 1; | |
2687 | ||
2688 | if ( argc < 4 ) { | |
586db386 | 2689 | di << argv[0] << "Invalid number of arguments\n"; |
7fd59977 | 2690 | return 1; |
2691 | } | |
2692 | ||
2693 | while (ViewerMainLoop( argc, argv)) { | |
2694 | } | |
2695 | ||
2696 | return 0; | |
2697 | } | |
2698 | ||
7fd59977 | 2699 | //============================================================================== |
2700 | //function : VSetBg | |
2701 | //purpose : Load image as background | |
2702 | //============================================================================== | |
2703 | ||
2704 | static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2705 | { | |
2706 | if (argc < 2 || argc > 3) | |
2707 | { | |
586db386 | 2708 | di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n"; |
2709 | di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n"; | |
7fd59977 | 2710 | return 1; |
2711 | } | |
2712 | ||
2713 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2714 | if(AISContext.IsNull()) | |
2715 | { | |
2716 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2717 | return 1; | |
2718 | } | |
2719 | ||
2720 | Aspect_FillMethod aFillType = Aspect_FM_CENTERED; | |
2721 | if (argc == 3) | |
2722 | { | |
2723 | const char* szType = argv[2]; | |
2724 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
2725 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
2726 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
2727 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
2728 | else | |
2729 | { | |
2730 | di << "Wrong fill type : " << szType << "\n"; | |
586db386 | 2731 | di << "Must be one of CENTERED, TILED, STRETCH, NONE\n"; |
7fd59977 | 2732 | return 1; |
2733 | } | |
2734 | } | |
2735 | ||
2736 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2737 | V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True); | |
2738 | ||
2739 | return 0; | |
2740 | } | |
2741 | ||
f8b2ed36 | 2742 | //============================================================================== |
2743 | //function : VSetBgMode | |
2744 | //purpose : Change background image fill type | |
2745 | //============================================================================== | |
2746 | ||
2747 | static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2748 | { | |
2749 | if (argc != 2) | |
2750 | { | |
586db386 | 2751 | di << "Usage : " << argv[0] << " filltype : Change background image mode\n"; |
2752 | di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n"; | |
f8b2ed36 | 2753 | return 1; |
2754 | } | |
2755 | ||
2756 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2757 | if(AISContext.IsNull()) | |
2758 | { | |
2759 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2760 | return 1; | |
2761 | } | |
1d47d8d0 | 2762 | Aspect_FillMethod aFillType = Aspect_FM_NONE; |
2763 | const char* szType = argv[1]; | |
2764 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
2765 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
2766 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
2767 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
2768 | else | |
f8b2ed36 | 2769 | { |
1d47d8d0 | 2770 | di << "Wrong fill type : " << szType << "\n"; |
586db386 | 2771 | di << "Must be one of CENTERED, TILED, STRETCH, NONE\n"; |
1d47d8d0 | 2772 | return 1; |
f8b2ed36 | 2773 | } |
f8b2ed36 | 2774 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
2775 | V3dView->SetBgImageStyle(aFillType, Standard_True); | |
f8b2ed36 | 2776 | return 0; |
2777 | } | |
2778 | ||
7fd59977 | 2779 | //============================================================================== |
2780 | //function : VSetGradientBg | |
2781 | //purpose : Mount gradient background | |
2782 | //============================================================================== | |
2783 | static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2784 | { | |
2785 | if (argc != 8 ) | |
2786 | { | |
586db386 | 2787 | di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n"; |
2788 | di << "R1,G1,B1,R2,G2,B2 = [0..255]\n"; | |
2789 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n"; | |
2790 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n"; | |
7fd59977 | 2791 | return 1; |
2792 | } | |
2793 | ||
2794 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2795 | if(AISContext.IsNull()) | |
2796 | { | |
2797 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2798 | return 1; | |
2799 | } | |
2800 | if (argc == 8) | |
2801 | { | |
2802 | ||
91322f44 | 2803 | Standard_Real R1 = Draw::Atof(argv[1])/255.; |
2804 | Standard_Real G1 = Draw::Atof(argv[2])/255.; | |
2805 | Standard_Real B1 = Draw::Atof(argv[3])/255.; | |
7fd59977 | 2806 | Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB); |
2807 | ||
91322f44 | 2808 | Standard_Real R2 = Draw::Atof(argv[4])/255.; |
2809 | Standard_Real G2 = Draw::Atof(argv[5])/255.; | |
2810 | Standard_Real B2 = Draw::Atof(argv[6])/255.; | |
7fd59977 | 2811 | |
2812 | Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB); | |
91322f44 | 2813 | int aType = Draw::Atoi(argv[7]); |
7fd59977 | 2814 | if( aType < 0 || aType > 8 ) |
2815 | { | |
586db386 | 2816 | di << "Wrong fill type \n"; |
2817 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n"; | |
2818 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n"; | |
7fd59977 | 2819 | return 1; |
2820 | } | |
2821 | ||
2822 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
2823 | ||
2824 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2825 | V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1); | |
2826 | } | |
2827 | ||
2828 | return 0; | |
2829 | } | |
2830 | ||
f8b2ed36 | 2831 | //============================================================================== |
2832 | //function : VSetGradientBgMode | |
2833 | //purpose : Change gradient background fill style | |
2834 | //============================================================================== | |
2835 | static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2836 | { | |
2837 | if (argc != 2 ) | |
2838 | { | |
586db386 | 2839 | di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n"; |
2840 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n"; | |
2841 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n"; | |
f8b2ed36 | 2842 | return 1; |
2843 | } | |
2844 | ||
2845 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2846 | if(AISContext.IsNull()) | |
2847 | { | |
2848 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2849 | return 1; | |
2850 | } | |
2851 | if (argc == 2) | |
2852 | { | |
91322f44 | 2853 | int aType = Draw::Atoi(argv[1]); |
f8b2ed36 | 2854 | if( aType < 0 || aType > 8 ) |
2855 | { | |
586db386 | 2856 | di << "Wrong fill type \n"; |
2857 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n"; | |
2858 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n"; | |
f8b2ed36 | 2859 | return 1; |
2860 | } | |
2861 | ||
2862 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
2863 | ||
2864 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2865 | V3dView->SetBgGradientStyle( aMethod, 1 ); | |
2866 | } | |
2867 | ||
2868 | return 0; | |
2869 | } | |
2870 | ||
2871 | //============================================================================== | |
2872 | //function : VSetColorBg | |
2873 | //purpose : Set color background | |
2874 | //============================================================================== | |
2875 | static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2876 | { | |
2877 | if (argc != 4 ) | |
2878 | { | |
586db386 | 2879 | di << "Usage : " << argv[0] << " R G B : Set color background\n"; |
2880 | di << "R,G,B = [0..255]\n"; | |
f8b2ed36 | 2881 | return 1; |
2882 | } | |
2883 | ||
2884 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2885 | if(AISContext.IsNull()) | |
2886 | { | |
2887 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2888 | return 1; | |
2889 | } | |
2890 | if (argc == 4) | |
2891 | { | |
2892 | ||
91322f44 | 2893 | Standard_Real R = Draw::Atof(argv[1])/255.; |
2894 | Standard_Real G = Draw::Atof(argv[2])/255.; | |
2895 | Standard_Real B = Draw::Atof(argv[3])/255.; | |
f8b2ed36 | 2896 | Quantity_Color aColor(R,G,B,Quantity_TOC_RGB); |
2897 | ||
2898 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2899 | V3dView->SetBackgroundColor( aColor ); | |
2900 | V3dView->Update(); | |
2901 | } | |
2902 | ||
2903 | return 0; | |
2904 | } | |
2905 | ||
f42753ed | 2906 | //============================================================================== |
2907 | //function : VSetDefaultBg | |
2908 | //purpose : Set default viewer background fill color | |
2909 | //============================================================================== | |
2910 | static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
2911 | { | |
2912 | if (theArgNb != 4 | |
2913 | && theArgNb != 8) | |
2914 | { | |
2915 | std::cout << "Error: wrong syntax! See usage:\n"; | |
2916 | theDI.PrintHelp (theArgVec[0]); | |
2917 | return 1; | |
2918 | } | |
2919 | ||
2920 | ViewerTest_DefaultBackground.FillMethod = | |
2921 | theArgNb == 4 ? Aspect_GFM_NONE | |
2922 | : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]); | |
2923 | ||
2924 | if (theArgNb == 4) | |
2925 | { | |
2926 | Standard_Real R = Draw::Atof (theArgVec[1]) / 255.; | |
2927 | Standard_Real G = Draw::Atof (theArgVec[2]) / 255.; | |
2928 | Standard_Real B = Draw::Atof (theArgVec[3]) / 255.; | |
2929 | ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
2930 | } | |
2931 | else | |
2932 | { | |
2933 | Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.; | |
2934 | Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.; | |
2935 | Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.; | |
2936 | ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB); | |
2937 | ||
2938 | Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.; | |
2939 | Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.; | |
2940 | Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.; | |
2941 | ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB); | |
2942 | } | |
2943 | ||
2944 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
2945 | anIter (ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
2946 | { | |
2947 | const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer(); | |
2948 | aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor); | |
2949 | aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1, | |
2950 | ViewerTest_DefaultBackground.GradientColor2, | |
2951 | ViewerTest_DefaultBackground.FillMethod); | |
2952 | } | |
2953 | ||
2954 | return 0; | |
2955 | } | |
2956 | ||
7fd59977 | 2957 | //============================================================================== |
2958 | //function : VScale | |
2959 | //purpose : View Scaling | |
2960 | //============================================================================== | |
2961 | ||
2962 | static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2963 | { | |
2964 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2965 | if ( V3dView.IsNull() ) return 1; | |
2966 | ||
2967 | if ( argc != 4 ) { | |
586db386 | 2968 | di << argv[0] << "Invalid number of arguments\n"; |
7fd59977 | 2969 | return 1; |
2970 | } | |
91322f44 | 2971 | V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) ); |
7fd59977 | 2972 | return 0; |
2973 | } | |
2974 | //============================================================================== | |
536d98e2 | 2975 | //function : VZBuffTrihedron |
2976 | //purpose : | |
7fd59977 | 2977 | //============================================================================== |
2978 | ||
536d98e2 | 2979 | static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/, |
2980 | Standard_Integer theArgNb, | |
2981 | const char** theArgVec) | |
7fd59977 | 2982 | { |
536d98e2 | 2983 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2984 | if (aView.IsNull()) | |
2985 | { | |
2986 | std::cout << "Error: no active viewer!\n"; | |
2987 | return 1; | |
2988 | } | |
7fd59977 | 2989 | |
536d98e2 | 2990 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
7c8a8fcc | 2991 | |
536d98e2 | 2992 | Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER; |
2993 | V3d_TypeOfVisualization aVisType = V3d_ZBUFFER; | |
2994 | Quantity_Color aLabelsColor = Quantity_NOC_WHITE; | |
2995 | Quantity_Color anArrowColorX = Quantity_NOC_RED; | |
2996 | Quantity_Color anArrowColorY = Quantity_NOC_GREEN; | |
2997 | Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1; | |
2998 | Standard_Real aScale = 0.1; | |
2999 | Standard_Real aSizeRatio = 0.8; | |
3000 | Standard_Real anArrowDiam = 0.05; | |
3001 | Standard_Integer aNbFacets = 12; | |
3002 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
7c8a8fcc | 3003 | { |
536d98e2 | 3004 | Standard_CString anArg = theArgVec[anArgIter]; |
3005 | TCollection_AsciiString aFlag (anArg); | |
3006 | aFlag.LowerCase(); | |
3007 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
7c8a8fcc | 3008 | { |
536d98e2 | 3009 | continue; |
3010 | } | |
3011 | else if (aFlag == "-on") | |
7c8a8fcc | 3012 | { |
536d98e2 | 3013 | continue; |
3014 | } | |
3015 | else if (aFlag == "-off") | |
7c8a8fcc | 3016 | { |
536d98e2 | 3017 | aView->TriedronErase(); |
3018 | return 0; | |
3019 | } | |
3020 | else if (aFlag == "-pos" | |
3021 | || aFlag == "-position" | |
3022 | || aFlag == "-corner") | |
7c8a8fcc | 3023 | { |
536d98e2 | 3024 | if (++anArgIter >= theArgNb) |
3025 | { | |
3026 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3027 | return 1; | |
3028 | } | |
3029 | ||
3030 | TCollection_AsciiString aPosName (theArgVec[anArgIter]); | |
3031 | aPosName.LowerCase(); | |
3032 | if (aPosName == "center") | |
3033 | { | |
3034 | aPosition = Aspect_TOTP_CENTER; | |
3035 | } | |
3036 | else if (aPosName == "left_lower" | |
3037 | || aPosName == "lower_left" | |
3038 | || aPosName == "leftlower" | |
3039 | || aPosName == "lowerleft") | |
3040 | { | |
3041 | aPosition = Aspect_TOTP_LEFT_LOWER; | |
3042 | } | |
3043 | else if (aPosName == "left_upper" | |
3044 | || aPosName == "upper_left" | |
3045 | || aPosName == "leftupper" | |
3046 | || aPosName == "upperleft") | |
3047 | { | |
3048 | aPosition = Aspect_TOTP_LEFT_UPPER; | |
3049 | } | |
3050 | else if (aPosName == "right_lower" | |
3051 | || aPosName == "lower_right" | |
3052 | || aPosName == "rightlower" | |
3053 | || aPosName == "lowerright") | |
3054 | { | |
3055 | aPosition = Aspect_TOTP_RIGHT_LOWER; | |
3056 | } | |
3057 | else if (aPosName == "right_upper" | |
3058 | || aPosName == "upper_right" | |
3059 | || aPosName == "rightupper" | |
3060 | || aPosName == "upperright") | |
3061 | { | |
3062 | aPosition = Aspect_TOTP_RIGHT_UPPER; | |
3063 | } | |
3064 | else | |
3065 | { | |
3066 | std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n"; | |
3067 | return 1; | |
3068 | } | |
3069 | } | |
3070 | else if (aFlag == "-type") | |
7c8a8fcc | 3071 | { |
536d98e2 | 3072 | if (++anArgIter >= theArgNb) |
3073 | { | |
3074 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3075 | return 1; | |
3076 | } | |
3077 | ||
3078 | TCollection_AsciiString aTypeName (theArgVec[anArgIter]); | |
3079 | aTypeName.LowerCase(); | |
3080 | if (aTypeName == "wireframe" | |
3081 | || aTypeName == "wire") | |
3082 | { | |
3083 | aVisType = V3d_WIREFRAME; | |
3084 | } | |
3085 | else if (aTypeName == "zbuffer" | |
3086 | || aTypeName == "shaded") | |
3087 | { | |
3088 | aVisType = V3d_ZBUFFER; | |
3089 | } | |
3090 | else | |
3091 | { | |
3092 | std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n"; | |
3093 | } | |
3094 | } | |
3095 | else if (aFlag == "-scale") | |
7c8a8fcc | 3096 | { |
536d98e2 | 3097 | if (++anArgIter >= theArgNb) |
3098 | { | |
3099 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3100 | return 1; | |
3101 | } | |
3102 | ||
3103 | aScale = Draw::Atof (theArgVec[anArgIter]); | |
7c8a8fcc | 3104 | } |
536d98e2 | 3105 | else if (aFlag == "-size" |
3106 | || aFlag == "-sizeratio") | |
3107 | { | |
3108 | if (++anArgIter >= theArgNb) | |
3109 | { | |
3110 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3111 | return 1; | |
3112 | } | |
7c8a8fcc | 3113 | |
536d98e2 | 3114 | aSizeRatio = Draw::Atof (theArgVec[anArgIter]); |
3115 | } | |
3116 | else if (aFlag == "-arrowdiam" | |
3117 | || aFlag == "-arrowdiameter") | |
3118 | { | |
3119 | if (++anArgIter >= theArgNb) | |
3120 | { | |
3121 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3122 | return 1; | |
3123 | } | |
7c8a8fcc | 3124 | |
536d98e2 | 3125 | anArrowDiam = Draw::Atof (theArgVec[anArgIter]); |
3126 | } | |
3127 | else if (aFlag == "-nbfacets") | |
3128 | { | |
3129 | if (++anArgIter >= theArgNb) | |
3130 | { | |
3131 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3132 | return 1; | |
3133 | } | |
7c8a8fcc | 3134 | |
536d98e2 | 3135 | aNbFacets = Draw::Atoi (theArgVec[anArgIter]); |
3136 | } | |
3137 | else if (aFlag == "-colorlabel" | |
3138 | || aFlag == "-colorlabels") | |
7c8a8fcc | 3139 | { |
536d98e2 | 3140 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3141 | theArgVec + anArgIter + 1, | |
3142 | aLabelsColor); | |
3143 | if (aNbParsed == 0) | |
3144 | { | |
3145 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3146 | return 1; | |
3147 | } | |
3148 | anArgIter += aNbParsed; | |
7c8a8fcc | 3149 | } |
536d98e2 | 3150 | else if (aFlag == "-colorarrowx") |
7c8a8fcc | 3151 | { |
536d98e2 | 3152 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3153 | theArgVec + anArgIter + 1, | |
3154 | anArrowColorX); | |
3155 | if (aNbParsed == 0) | |
3156 | { | |
3157 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3158 | return 1; | |
3159 | } | |
3160 | anArgIter += aNbParsed; | |
3161 | } | |
3162 | else if (aFlag == "-colorarrowy") | |
7c8a8fcc | 3163 | { |
536d98e2 | 3164 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3165 | theArgVec + anArgIter + 1, | |
3166 | anArrowColorY); | |
3167 | if (aNbParsed == 0) | |
3168 | { | |
3169 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3170 | return 1; | |
3171 | } | |
3172 | anArgIter += aNbParsed; | |
3173 | } | |
3174 | else if (aFlag == "-colorarrowz") | |
7c8a8fcc | 3175 | { |
536d98e2 | 3176 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3177 | theArgVec + anArgIter + 1, | |
3178 | anArrowColorZ); | |
3179 | if (aNbParsed == 0) | |
3180 | { | |
3181 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3182 | return 1; | |
3183 | } | |
3184 | anArgIter += aNbParsed; | |
3185 | } | |
3186 | else | |
3187 | { | |
3188 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
7c8a8fcc | 3189 | return 1; |
3190 | } | |
7c8a8fcc | 3191 | } |
3192 | ||
536d98e2 | 3193 | aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(), |
3194 | aSizeRatio, anArrowDiam, aNbFacets); | |
3195 | aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType); | |
c357e426 | 3196 | aView->ZFitAll(); |
7fd59977 | 3197 | return 0; |
3198 | } | |
3199 | ||
3200 | //============================================================================== | |
3201 | //function : VRotate | |
3202 | //purpose : Camera Rotating | |
3203 | //============================================================================== | |
3204 | ||
4af098ba | 3205 | static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec) |
3206 | { | |
3207 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3208 | if (aView.IsNull()) | |
3209 | { | |
3210 | std::cout << "No active view!\n"; | |
7fd59977 | 3211 | return 1; |
3212 | } | |
3213 | ||
4af098ba | 3214 | Standard_Boolean hasFlags = Standard_False; |
3215 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
3216 | { | |
3217 | Standard_CString anArg (theArgVec[anArgIter]); | |
3218 | TCollection_AsciiString aFlag (anArg); | |
3219 | aFlag.LowerCase(); | |
3220 | if (aFlag == "-mousestart" | |
3221 | || aFlag == "-mousefrom") | |
3222 | { | |
3223 | hasFlags = Standard_True; | |
3224 | if (anArgIter + 2 >= theArgNb) | |
3225 | { | |
3226 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
3227 | return 1; | |
3228 | } | |
3229 | ||
3230 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); | |
3231 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); | |
3232 | aView->StartRotation (anX, anY); | |
3233 | } | |
3234 | else if (aFlag == "-mousemove") | |
3235 | { | |
3236 | hasFlags = Standard_True; | |
3237 | if (anArgIter + 2 >= theArgNb) | |
3238 | { | |
3239 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
3240 | return 1; | |
3241 | } | |
3242 | ||
3243 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); | |
3244 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); | |
3245 | aView->Rotation (anX, anY); | |
3246 | } | |
3247 | else if (theArgNb != 4 | |
3248 | && theArgNb != 7) | |
3249 | { | |
3250 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
3251 | return 1; | |
3252 | } | |
3253 | } | |
3254 | ||
3255 | if (hasFlags) | |
3256 | { | |
7fd59977 | 3257 | return 0; |
4af098ba | 3258 | } |
3259 | else if (theArgNb == 4) | |
3260 | { | |
3261 | Standard_Real anAX = Draw::Atof (theArgVec[1]); | |
3262 | Standard_Real anAY = Draw::Atof (theArgVec[2]); | |
3263 | Standard_Real anAZ = Draw::Atof (theArgVec[3]); | |
3264 | aView->Rotate (anAX, anAY, anAZ); | |
3265 | return 0; | |
3266 | } | |
3267 | else if (theArgNb == 7) | |
3268 | { | |
3269 | Standard_Real anAX = Draw::Atof (theArgVec[1]); | |
3270 | Standard_Real anAY = Draw::Atof (theArgVec[2]); | |
3271 | Standard_Real anAZ = Draw::Atof (theArgVec[3]); | |
3272 | ||
3273 | Standard_Real anX = Draw::Atof (theArgVec[4]); | |
3274 | Standard_Real anY = Draw::Atof (theArgVec[5]); | |
3275 | Standard_Real anZ = Draw::Atof (theArgVec[6]); | |
3276 | ||
3277 | aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ); | |
7fd59977 | 3278 | return 0; |
7fd59977 | 3279 | } |
4af098ba | 3280 | |
3281 | std::cout << "Error: Invalid number of arguments\n"; | |
3282 | return 1; | |
7fd59977 | 3283 | } |
3284 | ||
3285 | //============================================================================== | |
3286 | //function : VZoom | |
3287 | //purpose : View zoom in / out (relative to current zoom) | |
3288 | //============================================================================== | |
3289 | ||
3290 | static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
3291 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3292 | if ( V3dView.IsNull() ) { | |
3293 | return 1; | |
3294 | } | |
3295 | ||
3296 | if ( argc == 2 ) { | |
91322f44 | 3297 | Standard_Real coef = Draw::Atof(argv[1]); |
7fd59977 | 3298 | if ( coef <= 0.0 ) { |
586db386 | 3299 | di << argv[1] << "Invalid value\n"; |
7fd59977 | 3300 | return 1; |
3301 | } | |
91322f44 | 3302 | V3dView->SetZoom( Draw::Atof(argv[1]) ); |
7fd59977 | 3303 | return 0; |
3304 | } else { | |
586db386 | 3305 | di << argv[0] << " Invalid number of arguments\n"; |
7fd59977 | 3306 | return 1; |
3307 | } | |
3308 | } | |
3309 | ||
3310 | //============================================================================== | |
3311 | //function : VPan | |
3312 | //purpose : View panning (in pixels) | |
3313 | //============================================================================== | |
3314 | ||
3315 | static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
3316 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3317 | if ( V3dView.IsNull() ) return 1; | |
3318 | ||
3319 | if ( argc == 3 ) { | |
91322f44 | 3320 | V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) ); |
7fd59977 | 3321 | return 0; |
3322 | } else { | |
586db386 | 3323 | di << argv[0] << " Invalid number of arguments\n"; |
7fd59977 | 3324 | return 1; |
3325 | } | |
3326 | } | |
3327 | ||
49e1a5c7 | 3328 | //============================================================================== |
3329 | //function : VPlace | |
3330 | //purpose : Place the point (in pixels) at the center of the window | |
3331 | //============================================================================== | |
3332 | static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs) | |
3333 | { | |
3334 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3335 | if (aView.IsNull()) | |
3336 | { | |
3337 | std::cerr << theArgs[0] << "Error: no active view." << std::endl; | |
3338 | return 1; | |
3339 | } | |
3340 | ||
3341 | if (theArgNb != 3) | |
3342 | { | |
3343 | std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl; | |
3344 | return 1; | |
3345 | } | |
3346 | ||
3347 | aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale()); | |
3348 | ||
3349 | return 0; | |
3350 | } | |
7fd59977 | 3351 | |
3352 | //============================================================================== | |
3353 | //function : VExport | |
5cedc27f | 3354 | //purpose : Export the view to a vector graphic format (PS, EMF, PDF) |
7fd59977 | 3355 | //============================================================================== |
3356 | ||
3357 | static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3358 | { | |
3359 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
5cedc27f K |
3360 | if (V3dView.IsNull()) |
3361 | return 1; | |
7fd59977 | 3362 | |
5cedc27f K |
3363 | if (argc == 1) |
3364 | { | |
3365 | std::cout << "Usage: " << argv[0] << " Filename [Format]\n"; | |
7fd59977 | 3366 | return 1; |
3367 | } | |
3368 | ||
5cedc27f K |
3369 | Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF; |
3370 | TCollection_AsciiString aFormatStr; | |
3371 | ||
3372 | TCollection_AsciiString aFileName (argv[1]); | |
3373 | Standard_Integer aLen = aFileName.Length(); | |
3374 | ||
3375 | if (argc > 2) | |
3376 | { | |
3377 | aFormatStr = TCollection_AsciiString (argv[2]); | |
3378 | } | |
3379 | else if (aLen >= 4) | |
3380 | { | |
3381 | if (aFileName.Value (aLen - 2) == '.') | |
3382 | { | |
c3282ec1 | 3383 | aFormatStr = aFileName.ToCString() + aLen - 2; |
5cedc27f K |
3384 | } |
3385 | else if (aFileName.Value (aLen - 3) == '.') | |
3386 | { | |
c3282ec1 | 3387 | aFormatStr = aFileName.ToCString() + aLen - 3; |
5cedc27f K |
3388 | } |
3389 | else | |
3390 | { | |
3391 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
3392 | return 1; | |
3393 | } | |
3394 | } | |
3395 | else | |
3396 | { | |
3397 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
3398 | return 1; | |
3399 | } | |
3400 | ||
3401 | aFormatStr.UpperCase(); | |
3402 | if (aFormatStr == "PS") | |
3403 | anExpFormat = Graphic3d_EF_PostScript; | |
3404 | else if (aFormatStr == "EPS") | |
3405 | anExpFormat = Graphic3d_EF_EnhPostScript; | |
3406 | else if (aFormatStr == "TEX") | |
3407 | anExpFormat = Graphic3d_EF_TEX; | |
3408 | else if (aFormatStr == "PDF") | |
3409 | anExpFormat = Graphic3d_EF_PDF; | |
3410 | else if (aFormatStr == "SVG") | |
3411 | anExpFormat = Graphic3d_EF_SVG; | |
3412 | else if (aFormatStr == "PGF") | |
3413 | anExpFormat = Graphic3d_EF_PGF; | |
3414 | else if (aFormatStr == "EMF") | |
3415 | anExpFormat = Graphic3d_EF_EMF; | |
3416 | else | |
3417 | { | |
3418 | std::cout << "Invalid export format '" << aFormatStr << "'\n"; | |
3419 | return 1; | |
3420 | } | |
3421 | ||
c357e426 | 3422 | try |
3423 | { | |
3424 | if (!V3dView->Export (argv[1], anExpFormat)) | |
9753e6de | 3425 | { |
3426 | di << "Error: export of image to " << aFormatStr << " failed!\n"; | |
3427 | } | |
3428 | } | |
3429 | catch (Standard_Failure) | |
5cedc27f | 3430 | { |
9753e6de | 3431 | di << "Error: export of image to " << aFormatStr << " failed"; |
3432 | di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")"; | |
5cedc27f | 3433 | } |
7fd59977 | 3434 | return 0; |
3435 | } | |
3436 | ||
3437 | //============================================================================== | |
3438 | //function : VColorScale | |
3439 | //purpose : representation color scale | |
3440 | //============================================================================== | |
7fd59977 | 3441 | |
71215351 | 3442 | static Standard_Boolean checkColor (const TCollection_AsciiString& theRed, |
3443 | const TCollection_AsciiString& theGreen, | |
3444 | const TCollection_AsciiString& theBlue, | |
3445 | Standard_Real& theRedValue, | |
3446 | Standard_Real& theGreenValue, | |
3447 | Standard_Real& theBlueValue) | |
7fd59977 | 3448 | { |
71215351 | 3449 | if (!theRed.IsRealValue() |
3450 | || !theGreen.IsRealValue() | |
3451 | || !theBlue.IsRealValue()) | |
7fd59977 | 3452 | { |
71215351 | 3453 | std::cout << "Error: RGB color values should be real!\n"; |
3454 | return Standard_True; | |
3455 | } | |
3456 | theRedValue = theRed .RealValue(); | |
3457 | theGreenValue = theGreen.RealValue(); | |
3458 | theBlueValue = theBlue .RealValue(); | |
3459 | if (theRedValue < 0.0 || theRedValue > 1.0 | |
3460 | || theGreenValue < 0.0 || theGreenValue > 1.0 | |
3461 | || theBlueValue < 0.0 || theBlueValue > 1.0) | |
3462 | { | |
3463 | std::cout << "Error: RGB color values should be within range 0..1!\n"; | |
3464 | return Standard_True; | |
7fd59977 | 3465 | } |
71215351 | 3466 | return Standard_False; |
3467 | } | |
7fd59977 | 3468 | |
71215351 | 3469 | static int VColorScale (Draw_Interpretor& theDI, |
3470 | Standard_Integer theArgNb, | |
3471 | const char** theArgVec) | |
3472 | { | |
7fd59977 | 3473 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
71215351 | 3474 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
3475 | if (aContext.IsNull()) | |
3476 | { | |
3477 | std::cout << "Error: no active view!\n"; | |
3478 | return 1; | |
7fd59977 | 3479 | } |
24a88697 | 3480 | if (theArgNb <= 1) |
3481 | { | |
3482 | std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n"; | |
3483 | return 1; | |
3484 | } | |
7fd59977 | 3485 | |
7a324550 | 3486 | Handle(AIS_ColorScale) aCS; |
3487 | // find object | |
3488 | Handle(AIS_InteractiveObject) anIObj; | |
3489 | if (GetMapOfAIS().IsBound2 (theArgVec[1])) | |
71215351 | 3490 | { |
7a324550 | 3491 | aCS = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1])); |
3492 | if (aCS.IsNull()) | |
3493 | { | |
3494 | std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n"; | |
3495 | return 1; | |
3496 | } | |
3497 | } | |
3498 | else | |
3499 | { | |
3500 | aCS = new AIS_ColorScale(); | |
3501 | GetMapOfAIS().Bind (aCS,theArgVec[1]); | |
3502 | } | |
3503 | ||
3504 | if (aCS->ZLayer() != Graphic3d_ZLayerId_TopOSD) | |
3505 | { | |
3506 | aCS->SetZLayer (Graphic3d_ZLayerId_TopOSD); | |
3507 | } | |
3508 | if (aCS->GetTransformPersistenceMode() != Graphic3d_TMF_2d) | |
3509 | { | |
3510 | aCS->SetTransformPersistence (Graphic3d_TMF_2d, gp_Pnt (-1,-1,0)); | |
7fd59977 | 3511 | } |
71215351 | 3512 | |
3513 | Standard_Real aMinRange = aCS->GetMin(); | |
3514 | Standard_Real aMaxRange = aCS->GetMax(); | |
180f89a2 | 3515 | Standard_Integer aBreadth = aCS->GetBreadth(); |
b4b2ecca | 3516 | Standard_Integer aHeight = aCS->GetHeight(); |
71215351 | 3517 | Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals(); |
3518 | Standard_Integer aTextHeight = aCS->GetTextHeight(); | |
3519 | Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition(); | |
b4b2ecca | 3520 | Standard_Integer aPosX = aCS->GetXPosition(); |
3521 | Standard_Integer aPosY = aCS->GetYPosition(); | |
71215351 | 3522 | |
3523 | ViewerTest_AutoUpdater anUpdateTool (aContext, aView); | |
3524 | ||
7a324550 | 3525 | if (theArgNb <= 2) |
3526 | { | |
3527 | theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n" | |
71215351 | 3528 | << "Min range: " << aMinRange << "\n" |
3529 | << "Max range: " << aMaxRange << "\n" | |
3530 | << "Number of intervals: " << aNbIntervals << "\n" | |
3531 | << "Text height: " << aTextHeight << "\n" | |
b4b2ecca | 3532 | << "Color scale position: " << aPosX <<" "<< aPosY<< "\n" |
71215351 | 3533 | << "Color scale title: " << aCS->GetTitle() << "\n" |
3534 | << "Label position: "; | |
3535 | switch (aLabPosition) | |
3536 | { | |
3537 | case Aspect_TOCSP_NONE: | |
3538 | theDI << "None\n"; | |
3539 | break; | |
3540 | case Aspect_TOCSP_LEFT: | |
3541 | theDI << "Left\n"; | |
3542 | break; | |
3543 | case Aspect_TOCSP_RIGHT: | |
3544 | theDI << "Right\n"; | |
3545 | break; | |
3546 | case Aspect_TOCSP_CENTER: | |
3547 | theDI << "Center\n"; | |
3548 | break; | |
3549 | } | |
3550 | return 0; | |
3551 | } | |
71215351 | 3552 | |
7a324550 | 3553 | for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter) |
71215351 | 3554 | { |
3555 | Standard_CString anArg = theArgVec[anArgIter]; | |
3556 | TCollection_AsciiString aFlag (anArg); | |
3557 | aFlag.LowerCase(); | |
3558 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
3559 | { | |
3560 | continue; | |
3561 | } | |
3562 | else if (aFlag == "-range") | |
3563 | { | |
3564 | if (anArgIter + 3 >= theArgNb) | |
3565 | { | |
3566 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3567 | return 1; | |
3568 | } | |
3569 | ||
3570 | TCollection_AsciiString anArg1 (theArgVec[++anArgIter]); | |
3571 | TCollection_AsciiString anArg2 (theArgVec[++anArgIter]); | |
3572 | TCollection_AsciiString anArg3 (theArgVec[++anArgIter]); | |
3573 | if (!anArg1.IsRealValue()) | |
3574 | { | |
3575 | std::cout << "Error: the minRange value should be real!\n"; | |
3576 | return 1; | |
3577 | } | |
3578 | else if (!anArg2.IsRealValue()) | |
3579 | { | |
3580 | std::cout << "Error: the maxRange value should be real!\n"; | |
3581 | return 1; | |
3582 | } | |
3583 | else if (!anArg3.IsIntegerValue()) | |
3584 | { | |
3585 | std::cout << "Error: the number of intervals should be integer!\n"; | |
3586 | return 1; | |
3587 | } | |
3588 | ||
3589 | aMinRange = anArg1.RealValue(); | |
3590 | aMaxRange = anArg2.RealValue(); | |
3591 | aNbIntervals = anArg3.IntegerValue(); | |
3592 | } | |
3593 | else if (aFlag == "-font") | |
3594 | { | |
3595 | if (anArgIter + 1 >= theArgNb) | |
3596 | { | |
3597 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3598 | return 1; | |
3599 | } | |
51740958 | 3600 | TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]); |
3601 | if (!aFontArg.IsIntegerValue()) | |
71215351 | 3602 | { |
3603 | std::cout << "Error: HeightFont value should be integer!\n"; | |
3604 | return 1; | |
3605 | } | |
3606 | ||
51740958 | 3607 | aTextHeight = aFontArg.IntegerValue(); |
71215351 | 3608 | anArgIter += 1; |
3609 | } | |
3610 | else if (aFlag == "-textpos") | |
3611 | { | |
3612 | if (anArgIter + 1 >= theArgNb) | |
3613 | { | |
3614 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3615 | return 1; | |
3616 | } | |
51740958 | 3617 | TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]); |
3618 | aTextPosArg.LowerCase(); | |
3619 | if (aTextPosArg == "none") | |
71215351 | 3620 | { |
3621 | aLabPosition = Aspect_TOCSP_NONE; | |
3622 | } | |
51740958 | 3623 | else if (aTextPosArg == "left") |
71215351 | 3624 | { |
3625 | aLabPosition = Aspect_TOCSP_LEFT; | |
3626 | } | |
51740958 | 3627 | else if (aTextPosArg == "right") |
71215351 | 3628 | { |
3629 | aLabPosition = Aspect_TOCSP_RIGHT; | |
3630 | } | |
51740958 | 3631 | else if (aTextPosArg == "center") |
71215351 | 3632 | { |
3633 | aLabPosition = Aspect_TOCSP_CENTER; | |
3634 | } | |
3635 | else | |
3636 | { | |
51740958 | 3637 | std::cout << "Error: unknown position '" << aTextPosArg << "'!\n"; |
71215351 | 3638 | return 1; |
3639 | } | |
3640 | } | |
24a88697 | 3641 | else if (aFlag == "-logarithmic" |
3642 | || aFlag == "-log") | |
3643 | { | |
3644 | if (anArgIter + 1 >= theArgNb) | |
3645 | { | |
3646 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3647 | return 1; | |
3648 | } | |
3649 | Standard_Boolean IsLog; | |
3650 | if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog)) | |
3651 | { | |
3652 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3653 | return 1; | |
3654 | } | |
3655 | aCS->SetLogarithmic (IsLog); | |
3656 | } | |
71215351 | 3657 | else if (aFlag == "-xy") |
3658 | { | |
3659 | if (anArgIter + 2 >= theArgNb) | |
3660 | { | |
3661 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3662 | return 1; | |
3663 | } | |
3664 | ||
3665 | TCollection_AsciiString aX (theArgVec[++anArgIter]); | |
3666 | TCollection_AsciiString aY (theArgVec[++anArgIter]); | |
b4b2ecca | 3667 | if (!aX.IsIntegerValue() |
3668 | || !aY.IsIntegerValue()) | |
71215351 | 3669 | { |
b4b2ecca | 3670 | std::cout << "Error: coordinates should be integer values!\n"; |
71215351 | 3671 | return 1; |
3672 | } | |
3673 | ||
b4b2ecca | 3674 | aPosX = aX.IntegerValue(); |
3675 | aPosY = aY.IntegerValue(); | |
3676 | } | |
3677 | else if (aFlag == "-width" | |
3678 | || aFlag == "-w") | |
3679 | { | |
3680 | if (anArgIter + 1 >= theArgNb) | |
3681 | { | |
3682 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3683 | return 1; | |
3684 | } | |
3685 | ||
3686 | TCollection_AsciiString aW (theArgVec[++anArgIter]); | |
3687 | if (!aW.IsIntegerValue()) | |
3688 | { | |
3689 | std::cout << "Error: a width should be an integer value!\n"; | |
3690 | return 1; | |
3691 | } | |
3692 | ||
180f89a2 | 3693 | aBreadth = aW.IntegerValue(); |
b4b2ecca | 3694 | } |
3695 | else if (aFlag == "-height" | |
3696 | || aFlag == "-h") | |
3697 | { | |
3698 | if (anArgIter + 1 >= theArgNb) | |
3699 | { | |
3700 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3701 | return 1; | |
3702 | } | |
3703 | ||
3704 | TCollection_AsciiString aH (theArgVec[++anArgIter]); | |
3705 | if (!aH.IsIntegerValue()) | |
3706 | { | |
3707 | std::cout << "Error: a width should be an integer value!\n"; | |
3708 | return 1; | |
3709 | } | |
3710 | ||
3711 | aHeight = aH.IntegerValue(); | |
71215351 | 3712 | } |
3713 | else if (aFlag == "-color") | |
3714 | { | |
3715 | if (aCS->GetColorType() != Aspect_TOCSD_USER) | |
3716 | { | |
3717 | std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n"; | |
3718 | return 1; | |
3719 | } | |
3720 | ||
3721 | Quantity_NameOfColor aColorName; | |
3722 | if (anArgIter + 4 >= theArgNb) | |
3723 | { | |
3724 | if (anArgIter + 2 >= theArgNb) | |
3725 | { | |
3726 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3727 | return 1; | |
3728 | } | |
3729 | else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName)) | |
3730 | { | |
3731 | std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n"; | |
3732 | return 1; | |
3733 | } | |
3734 | } | |
3735 | ||
3736 | TCollection_AsciiString anInd (theArgVec[anArgIter + 1]); | |
3737 | if (!anInd.IsIntegerValue()) | |
3738 | { | |
3739 | std::cout << "Error: Index value should be integer!\n"; | |
3740 | return 1; | |
3741 | } | |
3742 | ||
3743 | Standard_Integer anIndex = anInd.IntegerValue(); | |
180f89a2 | 3744 | if (anIndex <= 0 || anIndex > aNbIntervals) |
71215351 | 3745 | { |
180f89a2 | 3746 | std::cout << "Error: Index value should be within range 1.." << aNbIntervals <<"!\n"; |
71215351 | 3747 | return 1; |
3748 | } | |
3749 | ||
3750 | if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName)) | |
3751 | { | |
180f89a2 | 3752 | aCS->SetIntervalColor (Quantity_Color (aColorName), anIndex); |
7a324550 | 3753 | aCS->SetColorType (Aspect_TOCSD_USER); |
71215351 | 3754 | anArgIter += 2; |
3755 | continue; | |
3756 | } | |
3757 | ||
3758 | TCollection_AsciiString aRed (theArgVec[anArgIter + 2]); | |
3759 | TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]); | |
3760 | TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]); | |
3761 | Standard_Real aRedValue,aGreenValue, aBlueValue; | |
3762 | if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue)) | |
3763 | { | |
3764 | return 1; | |
3765 | } | |
180f89a2 | 3766 | aCS->SetIntervalColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex); |
71215351 | 3767 | aCS->SetColorType (Aspect_TOCSD_USER); |
3768 | anArgIter += 4; | |
3769 | } | |
3770 | else if (aFlag == "-label") | |
3771 | { | |
3772 | if (aCS->GetColorType() != Aspect_TOCSD_USER) | |
3773 | { | |
3774 | std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n"; | |
3775 | return 1; | |
3776 | } | |
3777 | else if (anArgIter + 2 >= theArgNb) | |
3778 | { | |
3779 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3780 | return 1; | |
3781 | } | |
3782 | ||
3783 | Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]); | |
180f89a2 | 3784 | if (anIndex <= 0 || anIndex > aNbIntervals+1) |
71215351 | 3785 | { |
180f89a2 | 3786 | std::cout << "Error: Index value should be within range 1.." << aNbIntervals+1 <<"!\n"; |
71215351 | 3787 | return 1; |
3788 | } | |
3789 | ||
3790 | TCollection_ExtendedString aText (theArgVec[anArgIter + 2]); | |
3791 | aCS->SetLabel (aText, anIndex); | |
3792 | aCS->SetLabelType (Aspect_TOCSD_USER); | |
3793 | anArgIter += 2; | |
3794 | } | |
3795 | else if (aFlag == "-colors") | |
3796 | { | |
3797 | Aspect_SequenceOfColor aSeq; | |
3798 | if (anArgIter + aNbIntervals + 1 > theArgNb) | |
3799 | { | |
3800 | std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the " | |
3801 | << aNbIntervals << " intervals\n"; | |
3802 | return 1; | |
3803 | } | |
3804 | ||
3805 | Standard_Integer aColorIter = anArgIter + 1; | |
3806 | while (aColorIter < theArgNb) | |
3807 | { | |
3808 | if (theArgVec[aColorIter][0] == '-') | |
3809 | { | |
3810 | break; | |
3811 | } | |
3812 | ||
3813 | else if (theArgVec[aColorIter][0] >= 97 | |
3814 | && theArgVec[aColorIter][0] <= 122) | |
3815 | { | |
3816 | Quantity_NameOfColor aColorName; | |
3817 | if (!Quantity_Color::ColorFromName (theArgVec[aColorIter], aColorName)) | |
3818 | { | |
3819 | std::cout << "Error: wrong color name: " << theArgVec[aColorIter] << " !\n"; | |
3820 | return 1; | |
3821 | } | |
3822 | aSeq.Append (Quantity_Color (aColorName)); | |
3823 | aColorIter++; | |
3824 | anArgIter++; | |
3825 | } | |
3826 | else | |
3827 | { | |
3828 | TCollection_AsciiString aRed (theArgVec[aColorIter]); | |
3829 | TCollection_AsciiString aGreen (theArgVec[aColorIter + 1]); | |
3830 | TCollection_AsciiString aBlue (theArgVec[aColorIter + 2]); | |
3831 | Standard_Real aRedValue,aGreenValue, aBlueValue; | |
3832 | if (checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue)) | |
3833 | { | |
3834 | return 1; | |
3835 | } | |
3836 | aSeq.Append (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB)); | |
3837 | aColorIter += 3; | |
3838 | anArgIter += 3; | |
3839 | } | |
3840 | } | |
3841 | if (aSeq.Length() < aNbIntervals) | |
3842 | { | |
3843 | std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the " | |
3844 | << aNbIntervals << " intervals\n"; | |
3845 | return 1; | |
3846 | } | |
3847 | ||
3848 | aCS->SetColors (aSeq); | |
3849 | aCS->SetColorType (Aspect_TOCSD_USER); | |
3850 | } | |
3851 | else if (aFlag == "-labels") | |
3852 | { | |
3853 | if (anArgIter + aNbIntervals + 1 >= theArgNb) | |
3854 | { | |
3855 | std::cout << "Error: not enough arguments! You should provide " << (aNbIntervals + 1) | |
3856 | << " text labels for " << aNbIntervals << " intervals.\n"; | |
3857 | return 1; | |
3858 | } | |
3859 | ||
3860 | TColStd_SequenceOfExtendedString aSeq; | |
3861 | for (int aLabelIter = anArgIter + 1; aLabelIter <= anArgIter + aNbIntervals + 1; aLabelIter += 1) | |
3862 | { | |
3863 | aSeq.Append (TCollection_ExtendedString (theArgVec[aLabelIter])); | |
3864 | } | |
3865 | aCS->SetLabels (aSeq); | |
3866 | aCS->SetLabelType (Aspect_TOCSD_USER); | |
3867 | anArgIter += aSeq.Length(); | |
3868 | } | |
3869 | else if (aFlag == "-title") | |
3870 | { | |
3871 | if (anArgIter + 1 >= theArgNb) | |
3872 | { | |
3873 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3874 | return 1; | |
3875 | } | |
3876 | ||
3877 | Standard_Boolean isTwoArgs = Standard_False; | |
3878 | if (anArgIter + 2 < theArgNb) | |
3879 | { | |
3880 | TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]); | |
3881 | aSecondArg.LowerCase(); | |
3882 | if (aSecondArg == "none") | |
3883 | { | |
3884 | aCS->SetTitlePosition (Aspect_TOCSP_NONE); | |
3885 | isTwoArgs = Standard_True; | |
3886 | } | |
3887 | else if (aSecondArg == "left") | |
3888 | { | |
3889 | aCS->SetTitlePosition (Aspect_TOCSP_LEFT); | |
3890 | isTwoArgs = Standard_True; | |
3891 | } | |
3892 | else if (aSecondArg == "right") | |
3893 | { | |
3894 | aCS->SetTitlePosition (Aspect_TOCSP_RIGHT); | |
3895 | isTwoArgs = Standard_True; | |
3896 | } | |
3897 | else if (aSecondArg == "center") | |
3898 | { | |
3899 | aCS->SetTitlePosition (Aspect_TOCSP_CENTER); | |
3900 | isTwoArgs = Standard_True; | |
3901 | } | |
3902 | } | |
3903 | ||
3904 | aCS->SetTitle (theArgVec[anArgIter + 1]); | |
3905 | if (isTwoArgs) | |
3906 | { | |
3907 | anArgIter += 1; | |
3908 | } | |
3909 | anArgIter += 1; | |
3910 | } | |
3911 | else if (aFlag == "-demoversion" | |
3912 | || aFlag == "-demo") | |
3913 | { | |
b4b2ecca | 3914 | aPosX = 0; |
3915 | aPosY = 0; | |
71215351 | 3916 | aTextHeight = 16; |
3917 | aMinRange = 0.0; | |
3918 | aMaxRange = 100; | |
3919 | aNbIntervals = 10; | |
180f89a2 | 3920 | aBreadth = 0; |
b4b2ecca | 3921 | aHeight = 0; |
71215351 | 3922 | aLabPosition = Aspect_TOCSP_RIGHT; |
7a324550 | 3923 | aCS->SetColorType (Aspect_TOCSD_AUTO); |
3924 | aCS->SetLabelType (Aspect_TOCSD_AUTO); | |
71215351 | 3925 | } |
3926 | else | |
3927 | { | |
3928 | std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n"; | |
3929 | return 1; | |
3930 | } | |
3931 | } | |
180f89a2 | 3932 | if (!aBreadth || !aHeight) |
b4b2ecca | 3933 | { |
3934 | Standard_Integer aWinWidth, aWinHeight; | |
3935 | aView->Window()->Size (aWinWidth, aWinHeight); | |
180f89a2 | 3936 | if (!aBreadth) |
b4b2ecca | 3937 | { |
180f89a2 | 3938 | aBreadth = aWinWidth; |
b4b2ecca | 3939 | } |
3940 | if (!aHeight) | |
3941 | { | |
3942 | aHeight = aWinHeight; | |
3943 | } | |
3944 | } | |
180f89a2 | 3945 | aCS->SetSize (aBreadth, aHeight); |
b4b2ecca | 3946 | aCS->SetPosition (aPosX, aPosY); |
71215351 | 3947 | aCS->SetTextHeight (aTextHeight); |
3948 | aCS->SetRange (aMinRange, aMaxRange); | |
3949 | aCS->SetNumberOfIntervals (aNbIntervals); | |
3950 | aCS->SetLabelPosition (aLabPosition); | |
180f89a2 | 3951 | // aCS->SetColor (aView->BackgroundColor().Invert()); |
7a324550 | 3952 | aCS->SetToUpdate(); |
3953 | aContext->Display (aCS); | |
71215351 | 3954 | |
7fd59977 | 3955 | return 0; |
3956 | } | |
3957 | ||
3958 | //============================================================================== | |
3959 | //function : VGraduatedTrihedron | |
a79f67f8 | 3960 | //purpose : Displays or hides a graduated trihedron |
7fd59977 | 3961 | //============================================================================== |
a79f67f8 | 3962 | static Standard_Boolean GetColor (const TCollection_AsciiString& theValue, |
3963 | Quantity_Color& theColor) | |
13a22457 | 3964 | { |
a79f67f8 | 3965 | Quantity_NameOfColor aColorName; |
3966 | TCollection_AsciiString aVal = theValue; | |
3967 | aVal.UpperCase(); | |
3968 | if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName)) | |
13a22457 | 3969 | { |
a79f67f8 | 3970 | return Standard_False; |
13a22457 | 3971 | } |
a79f67f8 | 3972 | theColor = Quantity_Color (aColorName); |
3973 | return Standard_True; | |
13a22457 S |
3974 | } |
3975 | ||
a79f67f8 | 3976 | static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs) |
7fd59977 | 3977 | { |
a79f67f8 | 3978 | if (theArgNum < 2) |
13a22457 | 3979 | { |
a79f67f8 | 3980 | std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help" |
3981 | << theArgs[0] <<"' for more information.\n"; | |
3982 | return 1; //TCL_ERROR | |
13a22457 | 3983 | } |
7fd59977 | 3984 | |
a79f67f8 | 3985 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs; |
3986 | TCollection_AsciiString aParseKey; | |
3987 | for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt) | |
3988 | { | |
3989 | TCollection_AsciiString anArg (theArgs [anArgIt]); | |
3990 | ||
3991 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) | |
3992 | { | |
3993 | aParseKey = anArg; | |
3994 | aParseKey.Remove (1); | |
3995 | aParseKey.LowerCase(); | |
3996 | aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); | |
3997 | continue; | |
3998 | } | |
13a22457 | 3999 | |
a79f67f8 | 4000 | if (aParseKey.IsEmpty()) |
4001 | { | |
4002 | continue; | |
4003 | } | |
4004 | ||
4005 | aMapOfArgs(aParseKey)->Append (anArg); | |
4006 | } | |
4007 | ||
4008 | // Check parameters | |
4009 | for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs); | |
4010 | aMapIt.More(); aMapIt.Next()) | |
7fd59977 | 4011 | { |
a79f67f8 | 4012 | const TCollection_AsciiString& aKey = aMapIt.Key(); |
4013 | const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value(); | |
4014 | ||
4015 | // Bool key, without arguments | |
4016 | if ((aKey.IsEqual ("on") || aKey.IsEqual ("off")) | |
4017 | && anArgs->IsEmpty()) | |
4018 | { | |
4019 | continue; | |
4020 | } | |
4021 | ||
4022 | // One argument | |
4023 | if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname")) | |
4024 | && anArgs->Length() == 1) | |
4025 | { | |
4026 | continue; | |
4027 | } | |
4028 | ||
4029 | // On/off arguments | |
4030 | if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname") | |
4031 | || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks") | |
536d98e2 | 4032 | || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues") |
4033 | || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes")) | |
a79f67f8 | 4034 | && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off"))) |
4035 | { | |
4036 | continue; | |
4037 | } | |
4038 | ||
4039 | // One string argument | |
4040 | if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor") | |
4041 | || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor")) | |
4042 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) | |
4043 | { | |
4044 | continue; | |
4045 | } | |
4046 | ||
4047 | // One integer argument | |
4048 | if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks") | |
4049 | || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength") | |
4050 | || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset") | |
4051 | || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset")) | |
4052 | && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue()) | |
4053 | { | |
4054 | continue; | |
4055 | } | |
4056 | ||
4057 | // One real argument | |
4058 | if ( aKey.IsEqual ("arrowlength") | |
4059 | && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue())) | |
4060 | { | |
4061 | continue; | |
4062 | } | |
4063 | ||
4064 | // Two string arguments | |
4065 | if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont")) | |
4066 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) | |
13a22457 | 4067 | { |
a79f67f8 | 4068 | continue; |
13a22457 | 4069 | } |
a79f67f8 | 4070 | |
4071 | TCollection_AsciiString aLowerKey; | |
4072 | aLowerKey = "-"; | |
4073 | aLowerKey += aKey; | |
4074 | aLowerKey.LowerCase(); | |
4075 | std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n"; | |
4076 | std::cout << "Type help for more information.\n"; | |
4077 | return 1; | |
7fd59977 | 4078 | } |
4079 | ||
a79f67f8 | 4080 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); |
4081 | if (anAISContext.IsNull()) | |
4082 | { | |
586db386 | 4083 | std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n"; |
a79f67f8 | 4084 | return 1; |
4085 | } | |
7fd59977 | 4086 | |
a79f67f8 | 4087 | Standard_Boolean toDisplay = Standard_True; |
4088 | Quantity_Color aColor; | |
4089 | Graphic3d_GraduatedTrihedron aTrihedronData; | |
4090 | // Process parameters | |
4091 | Handle(TColStd_HSequenceOfAsciiString) aValues; | |
4092 | if (aMapOfArgs.Find ("off", aValues)) | |
7fd59977 | 4093 | { |
a79f67f8 | 4094 | toDisplay = Standard_False; |
4095 | } | |
13a22457 | 4096 | |
a79f67f8 | 4097 | // AXES NAMES |
4098 | if (aMapOfArgs.Find ("xname", aValues)) | |
4099 | { | |
4100 | aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1)); | |
4101 | } | |
4102 | if (aMapOfArgs.Find ("yname", aValues)) | |
4103 | { | |
4104 | aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1)); | |
4105 | } | |
4106 | if (aMapOfArgs.Find ("zname", aValues)) | |
4107 | { | |
4108 | aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1)); | |
4109 | } | |
4110 | if (aMapOfArgs.Find ("xdrawname", aValues)) | |
4111 | { | |
536d98e2 | 4112 | aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4113 | } |
4114 | if (aMapOfArgs.Find ("ydrawname", aValues)) | |
4115 | { | |
536d98e2 | 4116 | aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4117 | } |
4118 | if (aMapOfArgs.Find ("zdrawname", aValues)) | |
4119 | { | |
536d98e2 | 4120 | aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4121 | } |
4122 | if (aMapOfArgs.Find ("xnameoffset", aValues)) | |
4123 | { | |
4124 | aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
4125 | } | |
4126 | if (aMapOfArgs.Find ("ynameoffset", aValues)) | |
4127 | { | |
4128 | aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
4129 | } | |
4130 | if (aMapOfArgs.Find ("znameoffset", aValues)) | |
4131 | { | |
4132 | aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
4133 | } | |
13a22457 | 4134 | |
a79f67f8 | 4135 | // COLORS |
4136 | if (aMapOfArgs.Find ("xnamecolor", aValues)) | |
4137 | { | |
4138 | if (!GetColor (aValues->Value(1), aColor)) | |
13a22457 | 4139 | { |
a79f67f8 | 4140 | std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n"; |
4141 | return 1; | |
13a22457 | 4142 | } |
a79f67f8 | 4143 | aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor); |
4144 | } | |
4145 | if (aMapOfArgs.Find ("ynamecolor", aValues)) | |
4146 | { | |
4147 | if (!GetColor (aValues->Value(1), aColor)) | |
13a22457 | 4148 | { |
a79f67f8 | 4149 | std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n"; |
4150 | return 1; | |
4151 | } | |
4152 | aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor); | |
4153 | } | |
4154 | if (aMapOfArgs.Find ("znamecolor", aValues)) | |
4155 | { | |
4156 | if (!GetColor (aValues->Value(1), aColor)) | |
4157 | { | |
4158 | std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n"; | |
4159 | return 1; | |
4160 | } | |
4161 | aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor); | |
4162 | } | |
4163 | if (aMapOfArgs.Find ("xcolor", aValues)) | |
4164 | { | |
4165 | if (!GetColor (aValues->Value(1), aColor)) | |
4166 | { | |
4167 | std::cout << theArgs[0] << "error: -xcolor wrong color name.\n"; | |
4168 | return 1; | |
4169 | } | |
4170 | aTrihedronData.ChangeXAxisAspect().SetColor (aColor); | |
4171 | } | |
4172 | if (aMapOfArgs.Find ("ycolor", aValues)) | |
4173 | { | |
4174 | if (!GetColor (aValues->Value(1), aColor)) | |
4175 | { | |
4176 | std::cout << theArgs[0] << "error: -ycolor wrong color name.\n"; | |
4177 | return 1; | |
4178 | } | |
4179 | aTrihedronData.ChangeYAxisAspect().SetColor (aColor); | |
4180 | } | |
4181 | if (aMapOfArgs.Find ("zcolor", aValues)) | |
4182 | { | |
4183 | if (!GetColor (aValues->Value(1), aColor)) | |
4184 | { | |
4185 | std::cout << theArgs[0] << "error: -zcolor wrong color name.\n"; | |
4186 | return 1; | |
4187 | } | |
4188 | aTrihedronData.ChangeZAxisAspect().SetColor (aColor); | |
4189 | } | |
4190 | ||
4191 | // TICKMARKS | |
4192 | if (aMapOfArgs.Find ("xticks", aValues)) | |
4193 | { | |
536d98e2 | 4194 | aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4195 | } |
4196 | if (aMapOfArgs.Find ("yticks", aValues)) | |
4197 | { | |
536d98e2 | 4198 | aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4199 | } |
4200 | if (aMapOfArgs.Find ("zticks", aValues)) | |
4201 | { | |
536d98e2 | 4202 | aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4203 | } |
4204 | if (aMapOfArgs.Find ("xticklength", aValues)) | |
4205 | { | |
536d98e2 | 4206 | aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4207 | } |
4208 | if (aMapOfArgs.Find ("yticklength", aValues)) | |
4209 | { | |
536d98e2 | 4210 | aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4211 | } |
4212 | if (aMapOfArgs.Find ("zticklength", aValues)) | |
4213 | { | |
536d98e2 | 4214 | aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4215 | } |
4216 | if (aMapOfArgs.Find ("xdrawticks", aValues)) | |
4217 | { | |
536d98e2 | 4218 | aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4219 | } |
4220 | if (aMapOfArgs.Find ("ydrawticks", aValues)) | |
4221 | { | |
536d98e2 | 4222 | aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4223 | } |
4224 | if (aMapOfArgs.Find ("zdrawticks", aValues)) | |
4225 | { | |
536d98e2 | 4226 | aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4227 | } |
4228 | ||
4229 | // VALUES | |
4230 | if (aMapOfArgs.Find ("xdrawvalues", aValues)) | |
4231 | { | |
536d98e2 | 4232 | aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4233 | } |
4234 | if (aMapOfArgs.Find ("ydrawvalues", aValues)) | |
4235 | { | |
536d98e2 | 4236 | aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4237 | } |
4238 | if (aMapOfArgs.Find ("zdrawvalues", aValues)) | |
4239 | { | |
536d98e2 | 4240 | aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4241 | } |
4242 | if (aMapOfArgs.Find ("xvaluesoffset", aValues)) | |
4243 | { | |
4244 | aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
4245 | } | |
4246 | if (aMapOfArgs.Find ("yvaluesoffset", aValues)) | |
4247 | { | |
4248 | aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
4249 | } | |
4250 | if (aMapOfArgs.Find ("zvaluesoffset", aValues)) | |
4251 | { | |
4252 | aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
4253 | } | |
4254 | ||
4255 | // ARROWS | |
4256 | if (aMapOfArgs.Find ("arrowlength", aValues)) | |
4257 | { | |
536d98e2 | 4258 | aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue()); |
a79f67f8 | 4259 | } |
4260 | ||
4261 | // FONTS | |
4262 | if (aMapOfArgs.Find ("namefont", aValues)) | |
4263 | { | |
4264 | aTrihedronData.SetNamesFont (aValues->Value(1)); | |
4265 | } | |
4266 | if (aMapOfArgs.Find ("valuesfont", aValues)) | |
4267 | { | |
4268 | aTrihedronData.SetValuesFont (aValues->Value(1)); | |
4269 | } | |
4270 | ||
536d98e2 | 4271 | if (aMapOfArgs.Find ("drawgrid", aValues)) |
4272 | { | |
4273 | aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on")); | |
4274 | } | |
4275 | if (aMapOfArgs.Find ("drawaxes", aValues)) | |
4276 | { | |
4277 | aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on")); | |
4278 | } | |
4279 | ||
a79f67f8 | 4280 | // The final step: display of erase trihedron |
4281 | if (toDisplay) | |
4282 | { | |
4283 | ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData); | |
13a22457 | 4284 | } |
7fd59977 | 4285 | else |
a79f67f8 | 4286 | { |
4287 | ViewerTest::CurrentView()->GraduatedTrihedronErase(); | |
4288 | } | |
7fd59977 | 4289 | |
4290 | ViewerTest::GetAISContext()->UpdateCurrentViewer(); | |
a79f67f8 | 4291 | ViewerTest::CurrentView()->Redraw(); |
13a22457 | 4292 | |
7fd59977 | 4293 | return 0; |
4294 | } | |
4295 | ||
7edf74fd A |
4296 | //============================================================================== |
4297 | //function : VPrintView | |
4298 | //purpose : Test printing algorithm, print the view to image file with given | |
4299 | // width and height. Printing implemented only for WNT. | |
4300 | //============================================================================== | |
4fe56619 | 4301 | static int VPrintView (Draw_Interpretor& di, Standard_Integer argc, |
7edf74fd A |
4302 | const char** argv) |
4303 | { | |
57c28b61 | 4304 | #ifndef _WIN32 |
c85385c0 | 4305 | (void )argc; |
4306 | (void )argv; | |
57c28b61 | 4307 | di << "Printing implemented only for WNT!\n"; |
b5ac8292 | 4308 | return 0; |
7edf74fd A |
4309 | #else |
4310 | ||
4311 | Handle(AIS_InteractiveContext) aContextAIS = NULL; | |
4312 | Handle(V3d_View) aView = NULL; | |
4313 | aContextAIS = ViewerTest::GetAISContext(); | |
4314 | if (!aContextAIS.IsNull()) | |
4315 | { | |
4316 | const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer(); | |
4317 | Vwr->InitActiveViews(); | |
4318 | if(Vwr->MoreActiveViews()) | |
4319 | aView = Vwr->ActiveView(); | |
4320 | } | |
4321 | ||
4322 | // check for errors | |
4323 | if (aView.IsNull()) | |
4324 | { | |
4325 | di << "Call vinit before!\n"; | |
4326 | return 1; | |
4327 | } | |
4328 | else if (argc < 4) | |
4329 | { | |
4330 | di << "Use: " << argv[0]; | |
b5ac8292 | 4331 | di << " width height filename [print algo=0] [tile_width tile_height]\n"; |
7edf74fd A |
4332 | di << "width, height of the intermediate buffer for operation\n"; |
4333 | di << "algo : {0|1}\n"; | |
4334 | di << " 0 - stretch algorithm\n"; | |
4335 | di << " 1 - tile algorithm\n"; | |
4336 | di << "test printing algorithms into an intermediate buffer\n"; | |
b5ac8292 | 4337 | di << "using specific tile size if provided\n"; |
7edf74fd A |
4338 | di << "with saving output to an image file\n"; |
4339 | return 1; | |
4340 | } | |
4341 | ||
4342 | // get the input params | |
91322f44 | 4343 | Standard_Integer aWidth = Draw::Atoi (argv[1]); |
4344 | Standard_Integer aHeight = Draw::Atoi (argv[2]); | |
7edf74fd A |
4345 | Standard_Integer aMode = 0; |
4346 | TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]); | |
b5ac8292 | 4347 | if (argc >= 5) |
91322f44 | 4348 | aMode = Draw::Atoi (argv[4]); |
7edf74fd | 4349 | |
b5ac8292 | 4350 | Standard_Integer aTileWidth = 0; |
4351 | Standard_Integer aTileHeight = 0; | |
4352 | Standard_Boolean isTileSizeProvided = Standard_False; | |
4353 | if (argc == 7) | |
4354 | { | |
4355 | isTileSizeProvided = Standard_True; | |
4356 | aTileWidth = Draw::Atoi (argv[5]); | |
4357 | aTileHeight = Draw::Atoi (argv[6]); | |
4358 | } | |
4359 | ||
7edf74fd A |
4360 | // check the input parameters |
4361 | if (aWidth <= 0 || aHeight <= 0) | |
4362 | { | |
4363 | di << "Width and height must be positive values!\n"; | |
4364 | return 1; | |
4365 | } | |
4366 | if (aMode != 0 && aMode != 1) | |
4367 | aMode = 0; | |
4368 | ||
7edf74fd | 4369 | // define compatible bitmap |
692613e5 | 4370 | HDC anDC = CreateCompatibleDC(0); |
7edf74fd A |
4371 | BITMAPINFO aBitmapData; |
4372 | memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER)); | |
4373 | aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); | |
4374 | aBitmapData.bmiHeader.biWidth = aWidth ; | |
4375 | aBitmapData.bmiHeader.biHeight = aHeight; | |
4376 | aBitmapData.bmiHeader.biPlanes = 1; | |
4377 | aBitmapData.bmiHeader.biBitCount = 24; | |
4378 | aBitmapData.bmiHeader.biXPelsPerMeter = 0; | |
4379 | aBitmapData.bmiHeader.biYPelsPerMeter = 0; | |
4380 | aBitmapData.bmiHeader.biClrUsed = 0; | |
4381 | aBitmapData.bmiHeader.biClrImportant = 0; | |
4382 | aBitmapData.bmiHeader.biCompression = BI_RGB; | |
4383 | aBitmapData.bmiHeader.biSizeImage = 0; | |
4384 | ||
4385 | // Create Device Independent Bitmap | |
692613e5 | 4386 | void* aBitsOut = NULL; |
7edf74fd | 4387 | HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS, |
692613e5 | 4388 | &aBitsOut, NULL, 0); |
7edf74fd A |
4389 | HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap); |
4390 | ||
4391 | Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False; | |
692613e5 | 4392 | if (aBitsOut != NULL) |
4fe56619 | 4393 | { |
7edf74fd A |
4394 | if (aMode == 0) |
4395 | isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH); | |
4396 | else | |
b5ac8292 | 4397 | { |
4398 | if (isTileSizeProvided) | |
4399 | { | |
b128c892 | 4400 | Handle(Graphic3d_CView) aGraphicView = ViewerTest::CurrentView()->View(); |
4401 | Handle(Standard_Transient) anOldBuffer = aGraphicView->FBO(); | |
4402 | Handle(Standard_Transient) aNewBuffer = aGraphicView->FBOCreate (aTileWidth, aTileHeight); | |
c357e426 | 4403 | aGraphicView->SetFBO (aNewBuffer); |
b5ac8292 | 4404 | |
4405 | isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE); | |
4406 | ||
c357e426 | 4407 | aGraphicView->FBORelease (aNewBuffer); |
4408 | aGraphicView->SetFBO (anOldBuffer); | |
b5ac8292 | 4409 | } |
4410 | else | |
4411 | { | |
4412 | isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE); | |
4413 | } | |
4414 | } | |
7edf74fd | 4415 | |
c357e426 | 4416 | // successfully printed into an intermediate buffer |
7edf74fd A |
4417 | if (isPrinted) |
4418 | { | |
692613e5 | 4419 | Image_PixMap aWrapper; |
4420 | aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4); | |
4421 | aWrapper.SetTopDown (false); | |
4422 | ||
4423 | Image_AlienPixMap anImageBitmap; | |
4424 | anImageBitmap.InitCopy (aWrapper); | |
4425 | isSaved = anImageBitmap.Save (aFileName); | |
7edf74fd A |
4426 | } |
4427 | else | |
4428 | { | |
4429 | di << "Print operation failed due to printing errors or\n"; | |
4430 | di << "insufficient memory available\n"; | |
4431 | di << "Please, try to use smaller dimensions for this test\n"; | |
4432 | di << "command, as it allocates intermediate buffer for storing\n"; | |
4433 | di << "the result\n"; | |
4434 | } | |
4435 | } | |
4436 | else | |
4437 | { | |
4438 | di << "Can't allocate memory for intermediate buffer\n"; | |
4439 | di << "Please use smaller dimensions\n"; | |
4440 | } | |
4441 | ||
4442 | if (aMemoryBitmap) | |
4443 | { | |
4444 | SelectObject (anDC, anOldBitmap); | |
4445 | DeleteObject (aMemoryBitmap); | |
4446 | DeleteDC(anDC); | |
4447 | } | |
4448 | ||
4449 | if (!isSaved) | |
4450 | { | |
4451 | di << "Save to file operation failed. This operation may fail\n"; | |
4452 | di << "if you don't have enough available memory, then you can\n"; | |
4453 | di << "use smaller dimensions for the output file\n"; | |
4454 | return 1; | |
4455 | } | |
4456 | ||
4457 | return 0; | |
4458 | ||
4459 | #endif | |
4460 | } | |
4461 | ||
59f45b7c | 4462 | //============================================================================== |
4463 | //function : VZLayer | |
4464 | //purpose : Test z layer operations for v3d viewer | |
4465 | //============================================================================== | |
4466 | static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
4467 | { | |
4468 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext (); | |
4469 | if (aContextAIS.IsNull()) | |
4470 | { | |
4471 | di << "Call vinit before!\n"; | |
4472 | return 1; | |
4473 | } | |
4474 | else if (argc < 2) | |
4475 | { | |
c5751993 | 4476 | di << "Use: vzlayer "; |
4477 | di << " add/del/get/settings/enable/disable [id]\n"; | |
59f45b7c | 4478 | di << " add - add new z layer to viewer and print its id\n"; |
4479 | di << " del - del z layer by its id\n"; | |
4480 | di << " get - print sequence of z layers in increasing order of their overlay level\n"; | |
c5751993 | 4481 | di << " settings - print status of z layer settings\n"; |
4482 | di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"; | |
4483 | di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"; | |
4484 | di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"; | |
4485 | di << "\nWhere id is the layer identificator\n"; | |
4486 | di << "\nExamples:\n"; | |
4487 | di << " vzlayer add\n"; | |
4488 | di << " vzlayer enable poffset 1\n"; | |
4489 | di << " vzlayer disable depthtest 1\n"; | |
4490 | di << " vzlayer del 1\n"; | |
59f45b7c | 4491 | return 1; |
4492 | } | |
4493 | ||
4494 | const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); | |
4495 | if (aViewer.IsNull()) | |
4496 | { | |
4497 | di << "No active viewer!\n"; | |
4498 | return 1; | |
4499 | } | |
4500 | ||
4501 | // perform operation | |
4502 | TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]); | |
4503 | if (anOp == "add") | |
4504 | { | |
4505 | Standard_Integer aNewId; | |
4506 | if (!aViewer->AddZLayer (aNewId)) | |
4507 | { | |
4508 | di << "Impossible to add new z layer!\n"; | |
4509 | return 1; | |
4510 | } | |
4511 | ||
4512 | di << "New z layer added with index: " << aNewId << "\n"; | |
4513 | } | |
4514 | else if (anOp == "del") | |
4515 | { | |
4516 | if (argc < 3) | |
4517 | { | |
4518 | di << "Please also provide as argument id of z layer to remove\n"; | |
4519 | return 1; | |
4520 | } | |
4521 | ||
91322f44 | 4522 | Standard_Integer aDelId = Draw::Atoi (argv[2]); |
59f45b7c | 4523 | if (!aViewer->RemoveZLayer (aDelId)) |
4524 | { | |
4525 | di << "Impossible to remove the z layer or invalid id!\n"; | |
4526 | return 1; | |
4527 | } | |
4528 | ||
a1954302 | 4529 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); |
4530 | anObjIter.More(); anObjIter.Next()) | |
4531 | { | |
4532 | Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1()); | |
4533 | if (aPrs.IsNull() | |
4534 | || aPrs->ZLayer() != aDelId) | |
4535 | { | |
4536 | continue; | |
4537 | } | |
4538 | aPrs->SetZLayer (Graphic3d_ZLayerId_Default); | |
4539 | } | |
4540 | ||
59f45b7c | 4541 | di << "Z layer " << aDelId << " has been removed\n"; |
4542 | } | |
4543 | else if (anOp == "get") | |
4544 | { | |
4545 | TColStd_SequenceOfInteger anIds; | |
4546 | aViewer->GetAllZLayers (anIds); | |
4547 | for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++) | |
4548 | { | |
4549 | di << anIds.Value (aSeqIdx) << " "; | |
4550 | } | |
4551 | ||
4552 | di << "\n"; | |
4553 | } | |
c5751993 | 4554 | else if (anOp == "settings") |
4555 | { | |
4556 | if (argc < 3) | |
4557 | { | |
4558 | di << "Please also provide an id\n"; | |
4559 | return 1; | |
4560 | } | |
4561 | ||
4562 | Standard_Integer anId = Draw::Atoi (argv[2]); | |
4563 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId); | |
4564 | ||
4565 | di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n"; | |
4566 | di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n"; | |
4567 | di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n"; | |
4568 | di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n"; | |
4569 | ||
4570 | } | |
4571 | else if (anOp == "enable") | |
4572 | { | |
4573 | if (argc < 3) | |
4574 | { | |
4575 | di << "Please also provide an option to enable\n"; | |
4576 | return 1; | |
4577 | } | |
4578 | ||
4579 | if (argc < 4) | |
4580 | { | |
4581 | di << "Please also provide a layer id\n"; | |
4582 | return 1; | |
4583 | } | |
4584 | ||
4585 | TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]); | |
4586 | Standard_Integer anId = Draw::Atoi (argv[3]); | |
4587 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId); | |
4588 | ||
4589 | if (aSubOp == "depthtest" || aSubOp == "test") | |
4590 | { | |
4591 | aSettings.EnableSetting (Graphic3d_ZLayerDepthTest); | |
4592 | } | |
4593 | else if (aSubOp == "depthwrite" || aSubOp == "write") | |
4594 | { | |
4595 | aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite); | |
4596 | } | |
4597 | else if (aSubOp == "depthclear" || aSubOp == "clear") | |
4598 | { | |
4599 | aSettings.EnableSetting (Graphic3d_ZLayerDepthClear); | |
4600 | } | |
4601 | else if (aSubOp == "depthoffset" || aSubOp == "offset") | |
4602 | { | |
4603 | if (argc < 6) | |
4604 | { | |
4605 | di << "Please also provide a factor and units values for depth offset\n"; | |
4606 | di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n"; | |
4607 | return 1; | |
4608 | } | |
4609 | ||
4610 | Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3])); | |
4611 | Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4])); | |
4612 | anId = Draw::Atoi (argv[5]); | |
4613 | aSettings = aViewer->ZLayerSettings (anId); | |
4614 | ||
4615 | aSettings.DepthOffsetFactor = aFactor; | |
4616 | aSettings.DepthOffsetUnits = aUnits; | |
4617 | ||
4618 | aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset); | |
4619 | } | |
4620 | else if (aSubOp == "positiveoffset" || aSubOp == "poffset") | |
4621 | { | |
4622 | aSettings.SetDepthOffsetPositive(); | |
4623 | } | |
4624 | else if (aSubOp == "negativeoffset" || aSubOp == "noffset") | |
4625 | { | |
4626 | aSettings.SetDepthOffsetNegative(); | |
4627 | } | |
4628 | ||
4629 | aViewer->SetZLayerSettings (anId, aSettings); | |
4630 | } | |
4631 | else if (anOp == "disable") | |
4632 | { | |
4633 | if (argc < 3) | |
4634 | { | |
4635 | di << "Please also provide an option to disable\n"; | |
4636 | return 1; | |
4637 | } | |
4638 | ||
4639 | if (argc < 4) | |
4640 | { | |
4641 | di << "Please also provide a layer id\n"; | |
4642 | return 1; | |
4643 | } | |
4644 | ||
4645 | TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]); | |
4646 | Standard_Integer anId = Draw::Atoi (argv[3]); | |
4647 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId); | |
4648 | ||
4649 | if (aSubOp == "depthtest" || aSubOp == "test") | |
4650 | { | |
4651 | aSettings.DisableSetting (Graphic3d_ZLayerDepthTest); | |
4652 | } | |
4653 | else if (aSubOp == "depthwrite" || aSubOp == "write") | |
4654 | { | |
4655 | aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite); | |
4656 | } | |
4657 | else if (aSubOp == "depthclear" || aSubOp == "clear") | |
4658 | { | |
4659 | aSettings.DisableSetting (Graphic3d_ZLayerDepthClear); | |
4660 | } | |
4661 | else if (aSubOp == "depthoffset" || aSubOp == "offset") | |
4662 | { | |
4663 | aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset); | |
4664 | } | |
4665 | ||
4666 | aViewer->SetZLayerSettings (anId, aSettings); | |
4667 | } | |
59f45b7c | 4668 | else |
4669 | { | |
c5751993 | 4670 | di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n"; |
59f45b7c | 4671 | return 1; |
4672 | } | |
4673 | ||
4674 | return 0; | |
4675 | } | |
4676 | ||
c357e426 | 4677 | // The interactive presentation of 2d layer item |
4678 | // for "vlayerline" command it provides a presentation of | |
4679 | // line with user-defined linewidth, linetype and transparency. | |
61b0191c | 4680 | class V3d_LineItem : public AIS_InteractiveObject |
20637bd2 | 4681 | { |
4682 | public: | |
4683 | // CASCADE RTTI | |
92efcf78 | 4684 | DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject) |
4fe56619 | 4685 | |
20637bd2 | 4686 | // constructor |
4687 | Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1, | |
4688 | Standard_Real X2, Standard_Real Y2, | |
20637bd2 | 4689 | Aspect_TypeOfLine theType = Aspect_TOL_SOLID, |
4690 | Standard_Real theWidth = 0.5, | |
4691 | Standard_Real theTransp = 1.0); | |
4692 | ||
61b0191c | 4693 | private: |
4694 | ||
4695 | void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
4696 | const Handle(Prs3d_Presentation)& thePresentation, | |
79104795 | 4697 | const Standard_Integer theMode) Standard_OVERRIDE; |
61b0191c | 4698 | |
4699 | void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/, | |
79104795 | 4700 | const Standard_Integer /*aMode*/) Standard_OVERRIDE |
4701 | {} | |
20637bd2 | 4702 | |
4703 | private: | |
4704 | ||
4705 | Standard_Real myX1, myY1, myX2, myY2; | |
eafb234b | 4706 | Aspect_TypeOfLine myType; |
20637bd2 | 4707 | Standard_Real myWidth; |
20637bd2 | 4708 | }; |
4709 | ||
20637bd2 | 4710 | // default constructor for line item |
4fe56619 | 4711 | V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1, |
20637bd2 | 4712 | Standard_Real X2, Standard_Real Y2, |
20637bd2 | 4713 | Aspect_TypeOfLine theType, |
4714 | Standard_Real theWidth, | |
4715 | Standard_Real theTransp) : | |
61b0191c | 4716 | myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), |
4717 | myType(theType), myWidth(theWidth) | |
20637bd2 | 4718 | { |
61b0191c | 4719 | SetTransparency (1-theTransp); |
20637bd2 | 4720 | } |
4721 | ||
4722 | // render line | |
61b0191c | 4723 | void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/, |
4724 | const Handle(Prs3d_Presentation)& thePresentation, | |
4725 | const Standard_Integer /*theMode*/) | |
20637bd2 | 4726 | { |
61b0191c | 4727 | thePresentation->Clear(); |
4728 | Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB); | |
4729 | Standard_Integer aWidth, aHeight; | |
4730 | ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight); | |
4731 | Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation); | |
4732 | Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5); | |
4733 | aPrim->AddVertex(myX1, aHeight-myY1, 0.); | |
4734 | aPrim->AddVertex(myX2, aHeight-myY2, 0.); | |
4735 | Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth); | |
4736 | aGroup->SetPrimitivesAspect (anAspect->Aspect()); | |
4737 | aGroup->AddPrimitiveArray (aPrim); | |
20637bd2 | 4738 | } |
4739 | ||
4740 | //============================================================================= | |
4741 | //function : VLayerLine | |
4742 | //purpose : Draws line in the v3d view layer with given attributes: linetype, | |
4743 | // : linewidth, transparency coefficient | |
4744 | //============================================================================ | |
4745 | static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
4746 | { | |
4747 | // get the active view | |
4748 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4749 | if (aView.IsNull()) | |
4750 | { | |
4751 | di << "Call vinit before!\n"; | |
4752 | return 1; | |
4753 | } | |
4754 | else if (argc < 5) | |
4755 | { | |
4756 | di << "Use: " << argv[0]; | |
4757 | di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n"; | |
4758 | di << " linetype : { 0 | 1 | 2 | 3 } \n"; | |
4759 | di << " 0 - solid \n"; | |
4760 | di << " 1 - dashed \n"; | |
4761 | di << " 2 - dot \n"; | |
4762 | di << " 3 - dashdot\n"; | |
4763 | di << " transparency : { 0.0 - 1.0 } \n"; | |
4764 | di << " 0.0 - transparent\n"; | |
4765 | di << " 1.0 - visible \n"; | |
4766 | return 1; | |
4767 | } | |
4768 | ||
61b0191c | 4769 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
20637bd2 | 4770 | // get the input params |
91322f44 | 4771 | Standard_Real X1 = Draw::Atof(argv[1]); |
4772 | Standard_Real Y1 = Draw::Atof(argv[2]); | |
4773 | Standard_Real X2 = Draw::Atof(argv[3]); | |
4774 | Standard_Real Y2 = Draw::Atof(argv[4]); | |
20637bd2 | 4775 | |
4776 | Standard_Real aWidth = 0.5; | |
4777 | Standard_Integer aType = 0; | |
4778 | Standard_Real aTransparency = 1.0; | |
4779 | ||
4780 | // has width | |
4781 | if (argc > 5) | |
91322f44 | 4782 | aWidth = Draw::Atof(argv[5]); |
20637bd2 | 4783 | |
4784 | // has type | |
4785 | if (argc > 6) | |
91322f44 | 4786 | aType = (Standard_Integer) Draw::Atoi(argv[6]); |
20637bd2 | 4787 | |
4788 | // has transparency | |
4789 | if (argc > 7) | |
4790 | { | |
91322f44 | 4791 | aTransparency = Draw::Atof(argv[7]); |
4fe56619 | 4792 | if (aTransparency < 0 || aTransparency > 1.0) |
20637bd2 | 4793 | aTransparency = 1.0; |
4794 | } | |
4795 | ||
4796 | // select appropriate line type | |
4797 | Aspect_TypeOfLine aLineType; | |
4798 | switch (aType) | |
4799 | { | |
4800 | case 1: | |
4801 | aLineType = Aspect_TOL_DASH; | |
4802 | break; | |
4803 | ||
4804 | case 2: | |
4805 | aLineType = Aspect_TOL_DOT; | |
4806 | break; | |
4807 | ||
4808 | case 3: | |
4809 | aLineType = Aspect_TOL_DOTDASH; | |
4810 | break; | |
4811 | ||
4812 | default: | |
4813 | aLineType = Aspect_TOL_SOLID; | |
4814 | } | |
4815 | ||
61b0191c | 4816 | static Handle (V3d_LineItem) aLine; |
4817 | if (!aLine.IsNull()) | |
25289ec1 | 4818 | { |
61b0191c | 4819 | aContext->Erase (aLine); |
25289ec1 | 4820 | } |
61b0191c | 4821 | aLine = new V3d_LineItem (X1, Y1, X2, Y2, |
4822 | aLineType, aWidth, | |
4823 | aTransparency); | |
25289ec1 | 4824 | |
61b0191c | 4825 | aLine->SetTransformPersistence (Graphic3d_TMF_2d,gp_Pnt(-1,-1,0)); |
4826 | aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD); | |
4827 | aLine->SetToUpdate(); | |
4828 | aContext->Display (aLine, Standard_True); | |
25289ec1 | 4829 | |
4830 | return 0; | |
4831 | } | |
4832 | ||
61b0191c | 4833 | |
2bd4c032 | 4834 | //============================================================================== |
4835 | //function : VGrid | |
4836 | //purpose : | |
4837 | //============================================================================== | |
4838 | ||
35e08fe8 | 4839 | static int VGrid (Draw_Interpretor& /*theDI*/, |
2bd4c032 | 4840 | Standard_Integer theArgNb, |
4841 | const char** theArgVec) | |
4842 | { | |
4843 | // get the active view | |
4844 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4845 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
4846 | if (aView.IsNull() || aViewer.IsNull()) | |
4847 | { | |
4848 | std::cerr << "No active view. Please call vinit.\n"; | |
4849 | return 1; | |
4850 | } | |
4851 | ||
4852 | Aspect_GridType aType = aViewer->GridType(); | |
4853 | Aspect_GridDrawMode aMode = aViewer->GridDrawMode(); | |
4854 | ||
4855 | Standard_Integer anIter = 1; | |
4856 | for (; anIter < theArgNb; ++anIter) | |
4857 | { | |
4858 | const char* aValue = theArgVec[anIter]; | |
4859 | if (*aValue == 'r') | |
4860 | { | |
4861 | aType = Aspect_GT_Rectangular; | |
4862 | } | |
4863 | else if (*aValue == 'c') | |
4864 | { | |
4865 | aType = Aspect_GT_Circular; | |
4866 | } | |
4867 | else if (*aValue == 'l') | |
4868 | { | |
4869 | aMode = Aspect_GDM_Lines; | |
4870 | } | |
4871 | else if (*aValue == 'p') | |
4872 | { | |
4873 | aMode = Aspect_GDM_Points; | |
4874 | } | |
4875 | else if (strcmp (aValue, "off" ) == 0) | |
4876 | { | |
4877 | aViewer->DeactivateGrid(); | |
4878 | return 0; | |
4879 | } | |
4880 | else | |
4881 | { | |
4882 | break; | |
4883 | } | |
4884 | } | |
4885 | ||
4886 | Standard_Integer aTail = (theArgNb - anIter); | |
4887 | if (aTail == 0) | |
4888 | { | |
4889 | aViewer->ActivateGrid (aType, aMode); | |
4890 | return 0; | |
4891 | } | |
4892 | else if (aTail != 2 && aTail != 5) | |
4893 | { | |
4894 | std::cerr << "Incorrect arguments number! Usage:\n" | |
4895 | << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n"; | |
4896 | return 1; | |
4897 | } | |
4898 | ||
4899 | Quantity_Length anOriginX, anOriginY; | |
4900 | Quantity_PlaneAngle aRotAngle; | |
4901 | if (aType == Aspect_GT_Rectangular) | |
4902 | { | |
4903 | Quantity_Length aRStepX, aRStepY; | |
4904 | aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); | |
4905 | ||
91322f44 | 4906 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
4907 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 4908 | if (aTail == 5) |
4909 | { | |
91322f44 | 4910 | aRStepX = Draw::Atof (theArgVec[anIter++]); |
4911 | aRStepY = Draw::Atof (theArgVec[anIter++]); | |
4912 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 4913 | } |
4914 | aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); | |
4915 | aViewer->ActivateGrid (aType, aMode); | |
4916 | } | |
4917 | else if (aType == Aspect_GT_Circular) | |
4918 | { | |
4919 | Quantity_Length aRadiusStep; | |
4920 | Standard_Integer aDivisionNumber; | |
4921 | aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
4922 | ||
91322f44 | 4923 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
4924 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 4925 | if (aTail == 5) |
4926 | { | |
91322f44 | 4927 | aRadiusStep = Draw::Atof (theArgVec[anIter++]); |
4928 | aDivisionNumber = Draw::Atoi (theArgVec[anIter++]); | |
4929 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 4930 | } |
4931 | ||
4932 | aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
4933 | aViewer->ActivateGrid (aType, aMode); | |
4934 | } | |
4935 | ||
4936 | return 0; | |
4937 | } | |
4938 | ||
c40b7d58 | 4939 | //============================================================================== |
4940 | //function : VPriviledgedPlane | |
4941 | //purpose : | |
4942 | //============================================================================== | |
4943 | ||
4944 | static int VPriviledgedPlane (Draw_Interpretor& theDI, | |
4945 | Standard_Integer theArgNb, | |
4946 | const char** theArgVec) | |
4947 | { | |
4948 | if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10) | |
4949 | { | |
4950 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
4951 | theDI.PrintHelp (theArgVec[0]); | |
4952 | return 1; | |
4953 | } | |
4954 | ||
4955 | // get the active viewer | |
4956 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
4957 | if (aViewer.IsNull()) | |
4958 | { | |
4959 | std::cerr << "Error: no active viewer. Please call vinit.\n"; | |
4960 | return 1; | |
4961 | } | |
4962 | ||
4963 | if (theArgNb == 1) | |
4964 | { | |
4965 | gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane(); | |
4966 | const gp_Pnt& anOrig = aPriviledgedPlane.Location(); | |
4967 | const gp_Dir& aNorm = aPriviledgedPlane.Direction(); | |
4968 | const gp_Dir& aXDir = aPriviledgedPlane.XDirection(); | |
4969 | theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " " | |
4970 | << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " " | |
4971 | << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n"; | |
4972 | return 0; | |
4973 | } | |
4974 | ||
4975 | Standard_Integer anArgIdx = 1; | |
4976 | Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]); | |
4977 | Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]); | |
4978 | Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]); | |
4979 | Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]); | |
4980 | Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]); | |
4981 | Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]); | |
4982 | ||
4983 | gp_Ax3 aPriviledgedPlane; | |
4984 | gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ); | |
4985 | gp_Dir aNorm (aNormX, aNormY, aNormZ); | |
4986 | if (theArgNb > 7) | |
4987 | { | |
4988 | Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]); | |
4989 | Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]); | |
4990 | Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]); | |
4991 | gp_Dir aXDir (aXDirX, aXDirY, aXDirZ); | |
4992 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir); | |
4993 | } | |
4994 | else | |
4995 | { | |
4996 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm); | |
4997 | } | |
4998 | ||
4999 | aViewer->SetPrivilegedPlane (aPriviledgedPlane); | |
5000 | ||
5001 | return 0; | |
5002 | } | |
5003 | ||
f25b82d6 | 5004 | //============================================================================== |
5005 | //function : VConvert | |
5006 | //purpose : | |
5007 | //============================================================================== | |
5008 | ||
5009 | static int VConvert (Draw_Interpretor& theDI, | |
5010 | Standard_Integer theArgNb, | |
5011 | const char** theArgVec) | |
5012 | { | |
5013 | // get the active view | |
5014 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5015 | if (aView.IsNull()) | |
5016 | { | |
c40b7d58 | 5017 | std::cerr << "Error: no active view. Please call vinit.\n"; |
f25b82d6 | 5018 | return 1; |
5019 | } | |
5020 | ||
5021 | enum { Model, Ray, View, Window, Grid } aMode = Model; | |
5022 | ||
5023 | // access coordinate arguments | |
5024 | TColStd_SequenceOfReal aCoord; | |
5025 | Standard_Integer anArgIdx = 1; | |
5026 | for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx) | |
5027 | { | |
5028 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); | |
5029 | if (!anArg.IsRealValue()) | |
5030 | { | |
5031 | break; | |
5032 | } | |
5033 | aCoord.Append (anArg.RealValue()); | |
5034 | } | |
5035 | ||
5036 | // non-numeric argument too early | |
5037 | if (aCoord.IsEmpty()) | |
5038 | { | |
5039 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
5040 | theDI.PrintHelp (theArgVec[0]); | |
5041 | return 1; | |
5042 | } | |
5043 | ||
5044 | // collect all other arguments and options | |
5045 | for (; anArgIdx < theArgNb; ++anArgIdx) | |
5046 | { | |
5047 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); | |
5048 | anArg.LowerCase(); | |
5049 | if (anArg == "window") aMode = Window; | |
5050 | else if (anArg == "view") aMode = View; | |
5051 | else if (anArg == "grid") aMode = Grid; | |
5052 | else if (anArg == "ray") aMode = Ray; | |
5053 | else | |
5054 | { | |
5055 | std::cerr << "Error: wrong argument " << anArg << "! See usage:\n"; | |
5056 | theDI.PrintHelp (theArgVec[0]); | |
5057 | return 1; | |
5058 | } | |
5059 | } | |
5060 | ||
5061 | // complete input checks | |
5062 | if ((aCoord.Length() == 1 && theArgNb > 3) || | |
5063 | (aCoord.Length() == 2 && theArgNb > 4) || | |
5064 | (aCoord.Length() == 3 && theArgNb > 5)) | |
5065 | { | |
5066 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
5067 | theDI.PrintHelp (theArgVec[0]); | |
5068 | return 1; | |
5069 | } | |
5070 | ||
5071 | Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; | |
5072 | Standard_Integer aXYp[2] = {0, 0}; | |
5073 | ||
5074 | // convert one-dimensional coordinate | |
5075 | if (aCoord.Length() == 1) | |
5076 | { | |
5077 | switch (aMode) | |
5078 | { | |
5079 | case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0; | |
5080 | case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0; | |
5081 | default: | |
5082 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
5083 | theDI.PrintHelp (theArgVec[0]); | |
5084 | return 1; | |
5085 | } | |
5086 | } | |
5087 | ||
5088 | // convert 2D coordinates from projection or view reference space | |
5089 | if (aCoord.Length() == 2) | |
5090 | { | |
5091 | switch (aMode) | |
5092 | { | |
5093 | case Model : | |
5094 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); | |
5095 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; | |
5096 | return 0; | |
5097 | ||
5098 | case View : | |
5099 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]); | |
5100 | theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n"; | |
5101 | return 0; | |
5102 | ||
5103 | case Window : | |
5104 | aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]); | |
5105 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; | |
5106 | return 0; | |
5107 | ||
5108 | case Grid : | |
5109 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); | |
5110 | aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]); | |
5111 | theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; | |
5112 | return 0; | |
5113 | ||
5114 | case Ray : | |
5115 | aView->ConvertWithProj ((Standard_Integer) aCoord (1), | |
5116 | (Standard_Integer) aCoord (2), | |
5117 | aXYZ[0], aXYZ[1], aXYZ[2], | |
5118 | aXYZ[3], aXYZ[4], aXYZ[5]); | |
5119 | theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; | |
5120 | return 0; | |
5121 | ||
5122 | default: | |
5123 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
5124 | theDI.PrintHelp (theArgVec[0]); | |
5125 | return 1; | |
5126 | } | |
5127 | } | |
5128 | ||
5129 | // convert 3D coordinates from view reference space | |
5130 | else if (aCoord.Length() == 3) | |
5131 | { | |
5132 | switch (aMode) | |
5133 | { | |
5134 | case Window : | |
5135 | aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]); | |
5136 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; | |
5137 | return 0; | |
5138 | ||
5139 | case Grid : | |
5140 | aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]); | |
5141 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; | |
5142 | return 0; | |
5143 | ||
5144 | default: | |
5145 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
5146 | theDI.PrintHelp (theArgVec[0]); | |
5147 | return 1; | |
5148 | } | |
5149 | } | |
5150 | ||
5151 | return 0; | |
5152 | } | |
5153 | ||
208e6839 | 5154 | //============================================================================== |
5155 | //function : VFps | |
5156 | //purpose : | |
5157 | //============================================================================== | |
5158 | ||
5159 | static int VFps (Draw_Interpretor& theDI, | |
5160 | Standard_Integer theArgNb, | |
5161 | const char** theArgVec) | |
5162 | { | |
5163 | // get the active view | |
5164 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5165 | if (aView.IsNull()) | |
5166 | { | |
5167 | std::cerr << "No active view. Please call vinit.\n"; | |
5168 | return 1; | |
5169 | } | |
5170 | ||
91322f44 | 5171 | Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100; |
208e6839 | 5172 | if (aFramesNb <= 0) |
5173 | { | |
5174 | std::cerr << "Incorrect arguments!\n"; | |
5175 | return 1; | |
5176 | } | |
5177 | ||
5178 | // the time is meaningless for first call | |
5179 | // due to async OpenGl rendering | |
5180 | aView->Redraw(); | |
5181 | ||
5182 | // redraw view in loop to estimate average values | |
5183 | OSD_Timer aTimer; | |
5184 | aTimer.Start(); | |
5185 | for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter) | |
5186 | { | |
5187 | aView->Redraw(); | |
5188 | } | |
5189 | aTimer.Stop(); | |
5190 | Standard_Real aCpu; | |
5191 | const Standard_Real aTime = aTimer.ElapsedTime(); | |
5192 | aTimer.OSD_Chronometer::Show (aCpu); | |
5193 | ||
5194 | const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime; | |
5195 | const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb); | |
5196 | ||
5197 | // return statistics | |
5198 | theDI << "FPS: " << aFpsAver << "\n" | |
5199 | << "CPU: " << (1000.0 * aCpuAver) << " msec\n"; | |
5200 | ||
8c820969 | 5201 | // compute additional statistics in ray-tracing mode |
5202 | Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); | |
5203 | ||
5204 | if (aParams.Method == Graphic3d_RM_RAYTRACING) | |
5205 | { | |
5206 | Standard_Integer aSizeX; | |
5207 | Standard_Integer aSizeY; | |
5208 | ||
5209 | aView->Window()->Size (aSizeX, aSizeY); | |
5210 | ||
5211 | // 1 shadow ray and 1 secondary ray pew each bounce | |
5212 | const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f; | |
5213 | ||
5214 | theDI << "MRays/sec (upper bound): " << aMRays << "\n"; | |
5215 | } | |
5216 | ||
208e6839 | 5217 | return 0; |
5218 | } | |
5219 | ||
58655684 | 5220 | //============================================================================== |
5221 | //function : VGlDebug | |
5222 | //purpose : | |
5223 | //============================================================================== | |
5224 | ||
5225 | static int VGlDebug (Draw_Interpretor& theDI, | |
5226 | Standard_Integer theArgNb, | |
5227 | const char** theArgVec) | |
5228 | { | |
aaf512f1 | 5229 | Handle(OpenGl_GraphicDriver) aDriver; |
5230 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5231 | if (!aView.IsNull()) | |
5232 | { | |
5233 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver()); | |
5234 | } | |
c87535af | 5235 | OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps; |
5236 | OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL; | |
5237 | ||
58655684 | 5238 | if (theArgNb < 2) |
5239 | { | |
c87535af | 5240 | TCollection_AsciiString aDebActive, aSyncActive; |
5241 | if (aCaps == NULL) | |
58655684 | 5242 | { |
c87535af | 5243 | aCaps = aDefCaps; |
5244 | } | |
5245 | else | |
5246 | { | |
5247 | Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS), | |
5248 | "GL_ARB_debug_output"); | |
5249 | aDebActive = isActive ? " (active)" : " (inactive)"; | |
5250 | if (isActive) | |
5251 | { | |
5252 | // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB | |
5253 | aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)"; | |
5254 | } | |
58655684 | 5255 | } |
5256 | ||
c87535af | 5257 | theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n" |
5258 | << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n" | |
5259 | << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n" | |
5260 | << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n"; | |
58655684 | 5261 | return 0; |
5262 | } | |
5263 | ||
c87535af | 5264 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
aaf512f1 | 5265 | { |
c87535af | 5266 | Standard_CString anArg = theArgVec[anArgIter]; |
5267 | TCollection_AsciiString anArgCase (anArg); | |
5268 | anArgCase.LowerCase(); | |
5269 | Standard_Boolean toEnableDebug = Standard_True; | |
5270 | if (anArgCase == "-glsl" | |
5271 | || anArgCase == "-glslwarn" | |
5272 | || anArgCase == "-glslwarns" | |
5273 | || anArgCase == "-glslwarnings") | |
5274 | { | |
5275 | Standard_Boolean toShowWarns = Standard_True; | |
5276 | if (++anArgIter < theArgNb | |
a5565a3c | 5277 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns)) |
c87535af | 5278 | { |
5279 | --anArgIter; | |
5280 | } | |
5281 | aDefCaps->glslWarnings = toShowWarns; | |
5282 | if (aCaps != NULL) | |
5283 | { | |
5284 | aCaps->glslWarnings = toShowWarns; | |
5285 | } | |
5286 | } | |
5287 | else if (anArgCase == "-extra" | |
5288 | || anArgCase == "-extramsg" | |
5289 | || anArgCase == "-extramessages") | |
5290 | { | |
5291 | Standard_Boolean toShow = Standard_True; | |
5292 | if (++anArgIter < theArgNb | |
a5565a3c | 5293 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow)) |
c87535af | 5294 | { |
5295 | --anArgIter; | |
5296 | } | |
5297 | aDefCaps->suppressExtraMsg = !toShow; | |
5298 | if (aCaps != NULL) | |
5299 | { | |
5300 | aCaps->suppressExtraMsg = !toShow; | |
5301 | } | |
5302 | } | |
5303 | else if (anArgCase == "-noextra" | |
5304 | || anArgCase == "-noextramsg" | |
5305 | || anArgCase == "-noextramessages") | |
5306 | { | |
5307 | Standard_Boolean toSuppress = Standard_True; | |
5308 | if (++anArgIter < theArgNb | |
a5565a3c | 5309 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress)) |
c87535af | 5310 | { |
5311 | --anArgIter; | |
5312 | } | |
5313 | aDefCaps->suppressExtraMsg = toSuppress; | |
5314 | if (aCaps != NULL) | |
5315 | { | |
5316 | aCaps->suppressExtraMsg = toSuppress; | |
5317 | } | |
5318 | } | |
5319 | else if (anArgCase == "-sync") | |
5320 | { | |
5321 | Standard_Boolean toSync = Standard_True; | |
5322 | if (++anArgIter < theArgNb | |
a5565a3c | 5323 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync)) |
c87535af | 5324 | { |
5325 | --anArgIter; | |
5326 | } | |
5327 | aDefCaps->contextSyncDebug = toSync; | |
5328 | if (toSync) | |
5329 | { | |
5330 | aDefCaps->contextDebug = Standard_True; | |
5331 | } | |
5332 | } | |
5333 | else if (anArgCase == "-debug") | |
5334 | { | |
5335 | if (++anArgIter < theArgNb | |
a5565a3c | 5336 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug)) |
c87535af | 5337 | { |
5338 | --anArgIter; | |
5339 | } | |
5340 | aDefCaps->contextDebug = toEnableDebug; | |
5341 | } | |
a5565a3c | 5342 | else if (ViewerTest::ParseOnOff (anArg, toEnableDebug) |
c87535af | 5343 | && (anArgIter + 1 == theArgNb)) |
5344 | { | |
5345 | // simple alias to turn on almost everything | |
5346 | aDefCaps->contextDebug = toEnableDebug; | |
5347 | aDefCaps->contextSyncDebug = toEnableDebug; | |
5348 | aDefCaps->glslWarnings = toEnableDebug; | |
5349 | } | |
5350 | else | |
5351 | { | |
5352 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
5353 | return 1; | |
5354 | } | |
aaf512f1 | 5355 | } |
5356 | ||
58655684 | 5357 | return 0; |
5358 | } | |
208e6839 | 5359 | |
5360 | //============================================================================== | |
5361 | //function : VVbo | |
5362 | //purpose : | |
5363 | //============================================================================== | |
5364 | ||
58655684 | 5365 | static int VVbo (Draw_Interpretor& theDI, |
208e6839 | 5366 | Standard_Integer theArgNb, |
5367 | const char** theArgVec) | |
5368 | { | |
58655684 | 5369 | const Standard_Boolean toSet = (theArgNb > 1); |
5370 | const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1; | |
5371 | if (toSet) | |
208e6839 | 5372 | { |
58655684 | 5373 | ViewerTest_myDefaultCaps.vboDisable = toUseVbo; |
208e6839 | 5374 | } |
5375 | ||
58655684 | 5376 | // get the context |
5377 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
5378 | if (aContextAIS.IsNull()) | |
208e6839 | 5379 | { |
58655684 | 5380 | if (!toSet) |
5381 | { | |
5382 | std::cerr << "No active view!\n"; | |
5383 | } | |
208e6839 | 5384 | return 1; |
5385 | } | |
58655684 | 5386 | Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver()); |
5387 | if (!aDriver.IsNull()) | |
208e6839 | 5388 | { |
58655684 | 5389 | if (!toSet) |
5390 | { | |
5391 | theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n"; | |
5392 | } | |
5393 | else | |
5394 | { | |
5395 | aDriver->ChangeOptions().vboDisable = toUseVbo; | |
5396 | } | |
208e6839 | 5397 | } |
5398 | ||
208e6839 | 5399 | return 0; |
5400 | } | |
5401 | ||
a577aaab | 5402 | //============================================================================== |
5403 | //function : VCaps | |
5404 | //purpose : | |
5405 | //============================================================================== | |
5406 | ||
5407 | static int VCaps (Draw_Interpretor& theDI, | |
5408 | Standard_Integer theArgNb, | |
5409 | const char** theArgVec) | |
5410 | { | |
5411 | OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps; | |
5412 | Handle(OpenGl_GraphicDriver) aDriver; | |
8625ef7e | 5413 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
5414 | if (!aContext.IsNull()) | |
a577aaab | 5415 | { |
8625ef7e | 5416 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver()); |
a577aaab | 5417 | aCaps = &aDriver->ChangeOptions(); |
5418 | } | |
5419 | ||
5420 | if (theArgNb < 2) | |
5421 | { | |
5422 | theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n"; | |
5423 | theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n"; | |
abe46077 | 5424 | theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n"; |
8625ef7e | 5425 | theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n"; |
f978241f | 5426 | theDI << "VSync: " << aCaps->swapInterval << "\n"; |
4e1523ef | 5427 | theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n"; |
f978241f | 5428 | theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n"; |
a577aaab | 5429 | return 0; |
5430 | } | |
5431 | ||
8625ef7e | 5432 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
a577aaab | 5433 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
5434 | { | |
8625ef7e | 5435 | Standard_CString anArg = theArgVec[anArgIter]; |
5436 | TCollection_AsciiString anArgCase (anArg); | |
5437 | anArgCase.LowerCase(); | |
5438 | if (anUpdateTool.parseRedrawMode (anArg)) | |
5439 | { | |
5440 | continue; | |
5441 | } | |
f978241f | 5442 | else if (anArgCase == "-vsync" |
5443 | || anArgCase == "-swapinterval") | |
5444 | { | |
5445 | Standard_Boolean toEnable = Standard_True; | |
5446 | if (++anArgIter < theArgNb | |
a5565a3c | 5447 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 5448 | { |
5449 | --anArgIter; | |
5450 | } | |
5451 | aCaps->swapInterval = toEnable; | |
5452 | } | |
8625ef7e | 5453 | else if (anArgCase == "-ffp") |
5454 | { | |
5455 | Standard_Boolean toEnable = Standard_True; | |
5456 | if (++anArgIter < theArgNb | |
a5565a3c | 5457 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 5458 | { |
5459 | --anArgIter; | |
5460 | } | |
5461 | aCaps->ffpEnable = toEnable; | |
5462 | } | |
5463 | else if (anArgCase == "-vbo") | |
a577aaab | 5464 | { |
8625ef7e | 5465 | Standard_Boolean toEnable = Standard_True; |
5466 | if (++anArgIter < theArgNb | |
a5565a3c | 5467 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 5468 | { |
5469 | --anArgIter; | |
5470 | } | |
5471 | aCaps->vboDisable = !toEnable; | |
a577aaab | 5472 | } |
8625ef7e | 5473 | else if (anArgCase == "-sprite" |
5474 | || anArgCase == "-sprites") | |
a577aaab | 5475 | { |
8625ef7e | 5476 | Standard_Boolean toEnable = Standard_True; |
5477 | if (++anArgIter < theArgNb | |
a5565a3c | 5478 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 5479 | { |
5480 | --anArgIter; | |
5481 | } | |
5482 | aCaps->pntSpritesDisable = !toEnable; | |
a577aaab | 5483 | } |
8625ef7e | 5484 | else if (anArgCase == "-softmode") |
abe46077 | 5485 | { |
8625ef7e | 5486 | Standard_Boolean toEnable = Standard_True; |
5487 | if (++anArgIter < theArgNb | |
a5565a3c | 5488 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 5489 | { |
5490 | --anArgIter; | |
5491 | } | |
5492 | aCaps->contextNoAccel = toEnable; | |
5493 | } | |
5494 | else if (anArgCase == "-accel" | |
5495 | || anArgCase == "-acceleration") | |
5496 | { | |
5497 | Standard_Boolean toEnable = Standard_True; | |
5498 | if (++anArgIter < theArgNb | |
a5565a3c | 5499 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 5500 | { |
5501 | --anArgIter; | |
5502 | } | |
5503 | aCaps->contextNoAccel = !toEnable; | |
abe46077 | 5504 | } |
4e1523ef | 5505 | else if (anArgCase == "-compat" |
5506 | || anArgCase == "-compatprofile" | |
5507 | || anArgCase == "-compatible" | |
5508 | || anArgCase == "-compatibleprofile") | |
5509 | { | |
5510 | Standard_Boolean toEnable = Standard_True; | |
5511 | if (++anArgIter < theArgNb | |
a5565a3c | 5512 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
4e1523ef | 5513 | { |
5514 | --anArgIter; | |
5515 | } | |
5516 | aCaps->contextCompatible = toEnable; | |
5517 | if (!aCaps->contextCompatible) | |
5518 | { | |
5519 | aCaps->ffpEnable = Standard_False; | |
5520 | } | |
5521 | } | |
5522 | else if (anArgCase == "-core" | |
5523 | || anArgCase == "-coreprofile") | |
5524 | { | |
5525 | Standard_Boolean toEnable = Standard_True; | |
5526 | if (++anArgIter < theArgNb | |
a5565a3c | 5527 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
4e1523ef | 5528 | { |
5529 | --anArgIter; | |
5530 | } | |
5531 | aCaps->contextCompatible = !toEnable; | |
5532 | if (!aCaps->contextCompatible) | |
5533 | { | |
5534 | aCaps->ffpEnable = Standard_False; | |
5535 | } | |
5536 | } | |
f978241f | 5537 | else if (anArgCase == "-stereo" |
5538 | || anArgCase == "-quadbuffer") | |
5539 | { | |
5540 | Standard_Boolean toEnable = Standard_True; | |
5541 | if (++anArgIter < theArgNb | |
a5565a3c | 5542 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 5543 | { |
5544 | --anArgIter; | |
5545 | } | |
5546 | aCaps->contextStereo = toEnable; | |
5547 | } | |
a577aaab | 5548 | else |
5549 | { | |
8625ef7e | 5550 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
5551 | return 1; | |
a577aaab | 5552 | } |
5553 | } | |
5554 | if (aCaps != &ViewerTest_myDefaultCaps) | |
5555 | { | |
5556 | ViewerTest_myDefaultCaps = *aCaps; | |
5557 | } | |
5558 | return 0; | |
5559 | } | |
5560 | ||
f0430952 | 5561 | //============================================================================== |
5562 | //function : VMemGpu | |
5563 | //purpose : | |
5564 | //============================================================================== | |
5565 | ||
5566 | static int VMemGpu (Draw_Interpretor& theDI, | |
5567 | Standard_Integer theArgNb, | |
5568 | const char** theArgVec) | |
5569 | { | |
5570 | // get the context | |
5571 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
5572 | if (aContextAIS.IsNull()) | |
5573 | { | |
5574 | std::cerr << "No active view. Please call vinit.\n"; | |
5575 | return 1; | |
5576 | } | |
5577 | ||
dc3fe572 | 5578 | Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver(); |
f0430952 | 5579 | if (aDriver.IsNull()) |
5580 | { | |
5581 | std::cerr << "Graphic driver not available.\n"; | |
5582 | return 1; | |
5583 | } | |
5584 | ||
5585 | Standard_Size aFreeBytes = 0; | |
5586 | TCollection_AsciiString anInfo; | |
5587 | if (!aDriver->MemoryInfo (aFreeBytes, anInfo)) | |
5588 | { | |
5589 | std::cerr << "Information not available.\n"; | |
5590 | return 1; | |
5591 | } | |
5592 | ||
5593 | if (theArgNb > 1 && *theArgVec[1] == 'f') | |
5594 | { | |
5595 | theDI << Standard_Real (aFreeBytes); | |
5596 | } | |
5597 | else | |
5598 | { | |
5599 | theDI << anInfo; | |
5600 | } | |
5601 | ||
5602 | return 0; | |
5603 | } | |
5604 | ||
85e096c3 | 5605 | // ============================================================================== |
5606 | // function : VReadPixel | |
5607 | // purpose : | |
5608 | // ============================================================================== | |
5609 | static int VReadPixel (Draw_Interpretor& theDI, | |
5610 | Standard_Integer theArgNb, | |
5611 | const char** theArgVec) | |
5612 | { | |
5613 | // get the active view | |
5614 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5615 | if (aView.IsNull()) | |
5616 | { | |
5617 | std::cerr << "No active view. Please call vinit.\n"; | |
5618 | return 1; | |
5619 | } | |
5620 | else if (theArgNb < 3) | |
5621 | { | |
5622 | std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n"; | |
5623 | return 1; | |
5624 | } | |
5625 | ||
692613e5 | 5626 | Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; |
5627 | Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA; | |
5628 | ||
85e096c3 | 5629 | Standard_Integer aWidth, aHeight; |
5630 | aView->Window()->Size (aWidth, aHeight); | |
91322f44 | 5631 | const Standard_Integer anX = Draw::Atoi (theArgVec[1]); |
5632 | const Standard_Integer anY = Draw::Atoi (theArgVec[2]); | |
85e096c3 | 5633 | if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight) |
5634 | { | |
5635 | std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n"; | |
5636 | return 1; | |
5637 | } | |
5638 | ||
5639 | Standard_Boolean toShowName = Standard_False; | |
5640 | Standard_Boolean toShowHls = Standard_False; | |
5641 | for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter) | |
5642 | { | |
29cb310a | 5643 | const char* aParam = theArgVec[anIter]; |
5644 | if ( strcasecmp( aParam, "rgb" ) == 0 ) | |
85e096c3 | 5645 | { |
692613e5 | 5646 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; |
5647 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 5648 | } |
29cb310a | 5649 | else if ( strcasecmp( aParam, "hls" ) == 0 ) |
85e096c3 | 5650 | { |
692613e5 | 5651 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; |
5652 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 5653 | toShowHls = Standard_True; |
5654 | } | |
29cb310a | 5655 | else if ( strcasecmp( aParam, "rgbf" ) == 0 ) |
85e096c3 | 5656 | { |
692613e5 | 5657 | aFormat = Image_PixMap::ImgRGBF; |
5658 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 5659 | } |
29cb310a | 5660 | else if ( strcasecmp( aParam, "rgba" ) == 0 ) |
85e096c3 | 5661 | { |
692613e5 | 5662 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; |
5663 | aBufferType = Graphic3d_BT_RGBA; | |
85e096c3 | 5664 | } |
29cb310a | 5665 | else if ( strcasecmp( aParam, "rgbaf" ) == 0 ) |
85e096c3 | 5666 | { |
692613e5 | 5667 | aFormat = Image_PixMap::ImgRGBAF; |
5668 | aBufferType = Graphic3d_BT_RGBA; | |
85e096c3 | 5669 | } |
29cb310a | 5670 | else if ( strcasecmp( aParam, "depth" ) == 0 ) |
85e096c3 | 5671 | { |
692613e5 | 5672 | aFormat = Image_PixMap::ImgGrayF; |
5673 | aBufferType = Graphic3d_BT_Depth; | |
85e096c3 | 5674 | } |
29cb310a | 5675 | else if ( strcasecmp( aParam, "name" ) == 0 ) |
85e096c3 | 5676 | { |
5677 | toShowName = Standard_True; | |
5678 | } | |
5679 | } | |
5680 | ||
692613e5 | 5681 | Image_PixMap anImage; |
5682 | if (!anImage.InitTrash (aFormat, aWidth, aHeight)) | |
5683 | { | |
5684 | std::cerr << "Image allocation failed\n"; | |
5685 | return 1; | |
5686 | } | |
5687 | else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType)) | |
85e096c3 | 5688 | { |
5689 | std::cerr << "Image dump failed\n"; | |
5690 | return 1; | |
5691 | } | |
5692 | ||
5693 | Quantity_Parameter anAlpha; | |
692613e5 | 5694 | Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha); |
85e096c3 | 5695 | if (toShowName) |
5696 | { | |
692613e5 | 5697 | if (aBufferType == Graphic3d_BT_RGBA) |
85e096c3 | 5698 | { |
64c759f8 | 5699 | theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha; |
85e096c3 | 5700 | } |
5701 | else | |
5702 | { | |
64c759f8 | 5703 | theDI << Quantity_Color::StringName (aColor.Name()); |
85e096c3 | 5704 | } |
5705 | } | |
5706 | else | |
5707 | { | |
5708 | switch (aBufferType) | |
5709 | { | |
5710 | default: | |
692613e5 | 5711 | case Graphic3d_BT_RGB: |
85e096c3 | 5712 | { |
5713 | if (toShowHls) | |
5714 | { | |
64c759f8 | 5715 | theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation(); |
85e096c3 | 5716 | } |
5717 | else | |
5718 | { | |
64c759f8 | 5719 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue(); |
85e096c3 | 5720 | } |
5721 | break; | |
5722 | } | |
692613e5 | 5723 | case Graphic3d_BT_RGBA: |
85e096c3 | 5724 | { |
64c759f8 | 5725 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha; |
85e096c3 | 5726 | break; |
5727 | } | |
692613e5 | 5728 | case Graphic3d_BT_Depth: |
85e096c3 | 5729 | { |
64c759f8 | 5730 | theDI << aColor.Red(); |
85e096c3 | 5731 | break; |
5732 | } | |
5733 | } | |
5734 | } | |
5735 | ||
5736 | return 0; | |
5737 | } | |
5738 | ||
692613e5 | 5739 | //============================================================================== |
5740 | //function : VDiffImage | |
5741 | //purpose : The draw-command compares two images. | |
5742 | //============================================================================== | |
5743 | ||
5744 | static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
5745 | { | |
5746 | if (theArgNb < 6) | |
5747 | { | |
5748 | theDI << "Not enough arguments.\n"; | |
5749 | return 1; | |
5750 | } | |
5751 | ||
5752 | // image file names | |
5753 | const char* anImgPathRef = theArgVec[1]; | |
5754 | const char* anImgPathNew = theArgVec[2]; | |
5755 | ||
5756 | // get string tolerance and check its validity | |
91322f44 | 5757 | Standard_Real aTolColor = Draw::Atof (theArgVec[3]); |
692613e5 | 5758 | if (aTolColor < 0.0) |
5759 | aTolColor = 0.0; | |
5760 | if (aTolColor > 1.0) | |
5761 | aTolColor = 1.0; | |
5762 | ||
91322f44 | 5763 | Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1); |
5764 | Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1); | |
692613e5 | 5765 | |
5766 | // image file of difference | |
5767 | const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL; | |
5768 | ||
5769 | // compare the images | |
5770 | Image_Diff aComparer; | |
5771 | if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite)) | |
5772 | { | |
5773 | return 1; | |
5774 | } | |
5775 | ||
5776 | aComparer.SetColorTolerance (aTolColor); | |
5777 | aComparer.SetBorderFilterOn (isBorderFilterOn); | |
5778 | Standard_Integer aDiffColorsNb = aComparer.Compare(); | |
5779 | theDI << aDiffColorsNb << "\n"; | |
5780 | ||
5781 | // save image of difference | |
936f43da | 5782 | if (aDiffColorsNb >0 && aDiffImagePath != NULL) |
692613e5 | 5783 | { |
5784 | aComparer.SaveDiffImage (aDiffImagePath); | |
5785 | } | |
5786 | ||
5787 | return 0; | |
5788 | } | |
5789 | ||
4754e164 | 5790 | //======================================================================= |
5791 | //function : VSelect | |
5792 | //purpose : Emulates different types of selection by mouse: | |
5793 | // 1) single click selection | |
5794 | // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2) | |
5795 | // 3) selection with polygon having corners at | |
dc3fe572 | 5796 | // pixel positions (x1,y1),...,(xn,yn) |
4754e164 | 5797 | // 4) any of these selections with shift button pressed |
5798 | //======================================================================= | |
5799 | static Standard_Integer VSelect (Draw_Interpretor& di, | |
5800 | Standard_Integer argc, | |
5801 | const char ** argv) | |
5802 | { | |
dc3fe572 | 5803 | if(argc < 3) |
4754e164 | 5804 | { |
586db386 | 5805 | di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n"; |
4754e164 | 5806 | return 1; |
5807 | } | |
5808 | ||
5809 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); | |
dc3fe572 | 5810 | if(myAIScontext.IsNull()) |
4754e164 | 5811 | { |
5812 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
5813 | return 1; | |
5814 | } | |
2157d6ac | 5815 | |
5816 | const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1)); | |
5817 | Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1; | |
5818 | TCollection_AsciiString anArg; | |
5819 | anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2]; | |
5820 | anArg.LowerCase(); | |
5821 | if (anArg == "-allowoverlap") | |
5822 | { | |
5823 | Standard_Boolean isValidated = isShiftSelection ? argc == 8 | |
5824 | : argc == 7; | |
5825 | if (!isValidated) | |
5826 | { | |
5827 | di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection"; | |
5828 | return 1; | |
5829 | } | |
5830 | ||
5831 | Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]); | |
5832 | myAIScontext->MainSelector()->AllowOverlapDetection((Standard_Boolean)isToAllow); | |
5833 | aCoordsNb -= 2; | |
5834 | } | |
5835 | ||
4754e164 | 5836 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); |
5837 | aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2])); | |
2157d6ac | 5838 | if(aCoordsNb == 2) |
4754e164 | 5839 | { |
5840 | if(isShiftSelection) | |
5841 | aCurrentEventManager->ShiftSelect(); | |
5842 | else | |
5843 | aCurrentEventManager->Select(); | |
5844 | } | |
2157d6ac | 5845 | else if(aCoordsNb == 4) |
4754e164 | 5846 | { |
5847 | if(isShiftSelection) | |
2157d6ac | 5848 | aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False); |
4754e164 | 5849 | else |
2157d6ac | 5850 | aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False); |
4754e164 | 5851 | } |
5852 | else | |
5853 | { | |
2157d6ac | 5854 | TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2); |
4754e164 | 5855 | |
2157d6ac | 5856 | for(Standard_Integer i=1;i<=aCoordsNb / 2;++i) |
4754e164 | 5857 | aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i]))); |
5858 | ||
5859 | if(isShiftSelection) | |
5860 | aCurrentEventManager->ShiftSelect(aPolyline); | |
5861 | else | |
5862 | aCurrentEventManager->Select(aPolyline); | |
5863 | } | |
5864 | return 0; | |
5865 | } | |
5866 | ||
5867 | //======================================================================= | |
5868 | //function : VMoveTo | |
dc3fe572 | 5869 | //purpose : Emulates cursor movement to defined pixel position |
4754e164 | 5870 | //======================================================================= |
5871 | static Standard_Integer VMoveTo (Draw_Interpretor& di, | |
5872 | Standard_Integer argc, | |
5873 | const char ** argv) | |
5874 | { | |
dc3fe572 | 5875 | if(argc != 3) |
4754e164 | 5876 | { |
586db386 | 5877 | di << "Usage : " << argv[0] << " x y\n"; |
4754e164 | 5878 | return 1; |
5879 | } | |
5880 | ||
5881 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
dc3fe572 | 5882 | if(aContext.IsNull()) |
4754e164 | 5883 | { |
5884 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
5885 | return 1; | |
5886 | } | |
5887 | ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2])); | |
5888 | return 0; | |
5889 | } | |
5890 | ||
197ac94e | 5891 | //================================================================================================= |
4754e164 | 5892 | //function : VViewParams |
dc3fe572 | 5893 | //purpose : Gets or sets AIS View characteristics |
197ac94e | 5894 | //================================================================================================= |
5895 | static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
4754e164 | 5896 | { |
197ac94e | 5897 | Handle(V3d_View) anAISView = ViewerTest::CurrentView(); |
5898 | if (anAISView.IsNull()) | |
4754e164 | 5899 | { |
197ac94e | 5900 | std::cout << theArgVec[0] << ": please initialize or activate view.\n"; |
4754e164 | 5901 | return 1; |
5902 | } | |
197ac94e | 5903 | |
5904 | if (theArgsNb == 1) | |
4754e164 | 5905 | { |
197ac94e | 5906 | // print all of the available view parameters |
5907 | Quantity_Factor anAISViewScale = anAISView->Scale(); | |
5908 | ||
4754e164 | 5909 | Standard_Real anAISViewProjX = 0.0; |
5910 | Standard_Real anAISViewProjY = 0.0; | |
5911 | Standard_Real anAISViewProjZ = 0.0; | |
197ac94e | 5912 | anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ); |
5913 | ||
4754e164 | 5914 | Standard_Real anAISViewUpX = 0.0; |
5915 | Standard_Real anAISViewUpY = 0.0; | |
5916 | Standard_Real anAISViewUpZ = 0.0; | |
197ac94e | 5917 | anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ); |
5918 | ||
4754e164 | 5919 | Standard_Real anAISViewAtX = 0.0; |
5920 | Standard_Real anAISViewAtY = 0.0; | |
5921 | Standard_Real anAISViewAtZ = 0.0; | |
197ac94e | 5922 | anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ); |
5923 | ||
5924 | Standard_Real anAISViewEyeX = 0.0; | |
5925 | Standard_Real anAISViewEyeY = 0.0; | |
5926 | Standard_Real anAISViewEyeZ = 0.0; | |
5927 | anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ); | |
5928 | ||
5929 | theDi << "Scale of current view: " << anAISViewScale << "\n"; | |
5930 | theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n"; | |
5931 | theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n"; | |
5932 | theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n"; | |
5933 | theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n"; | |
5934 | return 0; | |
4754e164 | 5935 | } |
197ac94e | 5936 | |
5937 | // ------------------------- | |
5938 | // Parse options and values | |
5939 | // ------------------------- | |
5940 | ||
900f7229 | 5941 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues; |
197ac94e | 5942 | TCollection_AsciiString aParseKey; |
5943 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
5944 | { | |
5945 | TCollection_AsciiString anArg (theArgVec [anArgIt]); | |
5946 | ||
5947 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) | |
5948 | { | |
5949 | aParseKey = anArg; | |
5950 | aParseKey.Remove (1); | |
5951 | aParseKey.UpperCase(); | |
900f7229 | 5952 | aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); |
197ac94e | 5953 | continue; |
5954 | } | |
5955 | ||
3dfe95cd | 5956 | if (aParseKey.IsEmpty()) |
5957 | { | |
5958 | std::cout << theArgVec[0] << ": values should be passed with key.\n"; | |
5959 | std::cout << "Type help for more information.\n"; | |
5960 | return 1; | |
5961 | } | |
5962 | ||
900f7229 | 5963 | aMapOfKeysByValues(aParseKey)->Append (anArg); |
197ac94e | 5964 | } |
5965 | ||
5966 | // --------------------------------------------- | |
5967 | // Change or print parameters, order plays role | |
5968 | // --------------------------------------------- | |
5969 | ||
5970 | // Check arguments for validity | |
900f7229 | 5971 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues); |
197ac94e | 5972 | for (; aMapIt.More(); aMapIt.Next()) |
4754e164 | 5973 | { |
197ac94e | 5974 | const TCollection_AsciiString& aKey = aMapIt.Key(); |
900f7229 | 5975 | const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value(); |
5976 | ||
5977 | if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty())) | |
5978 | && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty())) | |
5979 | && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty())) | |
5980 | && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty())) | |
5981 | && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty())) | |
5982 | && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty())) | |
5983 | && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2)) | |
197ac94e | 5984 | { |
5985 | TCollection_AsciiString aLowerKey; | |
5986 | aLowerKey = "-"; | |
5987 | aLowerKey += aKey; | |
5988 | aLowerKey.LowerCase(); | |
5989 | std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n"; | |
5990 | std::cout << "Type help for more information.\n"; | |
5991 | return 1; | |
5992 | } | |
4754e164 | 5993 | } |
197ac94e | 5994 | |
900f7229 | 5995 | Handle(TColStd_HSequenceOfAsciiString) aValues; |
197ac94e | 5996 | |
5997 | // Change view parameters in proper order | |
5998 | if (aMapOfKeysByValues.Find ("SCALE", aValues)) | |
5999 | { | |
900f7229 | 6000 | if (aValues->IsEmpty()) |
197ac94e | 6001 | { |
6002 | theDi << "Scale: " << anAISView->Scale() << "\n"; | |
6003 | } | |
6004 | else | |
6005 | { | |
900f7229 | 6006 | anAISView->SetScale (aValues->Value(1).RealValue()); |
197ac94e | 6007 | } |
6008 | } | |
3dfe95cd | 6009 | if (aMapOfKeysByValues.Find ("SIZE", aValues)) |
6010 | { | |
900f7229 | 6011 | if (aValues->IsEmpty()) |
3dfe95cd | 6012 | { |
6013 | Standard_Real aSizeX = 0.0; | |
6014 | Standard_Real aSizeY = 0.0; | |
6015 | anAISView->Size (aSizeX, aSizeY); | |
6016 | theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n"; | |
6017 | } | |
6018 | else | |
6019 | { | |
900f7229 | 6020 | anAISView->SetSize (aValues->Value(1).RealValue()); |
3dfe95cd | 6021 | } |
6022 | } | |
197ac94e | 6023 | if (aMapOfKeysByValues.Find ("EYE", aValues)) |
6024 | { | |
900f7229 | 6025 | if (aValues->IsEmpty()) |
197ac94e | 6026 | { |
6027 | Standard_Real anEyeX = 0.0; | |
6028 | Standard_Real anEyeY = 0.0; | |
6029 | Standard_Real anEyeZ = 0.0; | |
6030 | anAISView->Eye (anEyeX, anEyeY, anEyeZ); | |
6031 | theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n"; | |
6032 | } | |
6033 | else | |
6034 | { | |
900f7229 | 6035 | anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
197ac94e | 6036 | } |
6037 | } | |
6038 | if (aMapOfKeysByValues.Find ("AT", aValues)) | |
6039 | { | |
900f7229 | 6040 | if (aValues->IsEmpty()) |
197ac94e | 6041 | { |
6042 | Standard_Real anAtX = 0.0; | |
6043 | Standard_Real anAtY = 0.0; | |
6044 | Standard_Real anAtZ = 0.0; | |
6045 | anAISView->At (anAtX, anAtY, anAtZ); | |
6046 | theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n"; | |
6047 | } | |
6048 | else | |
6049 | { | |
900f7229 | 6050 | anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
197ac94e | 6051 | } |
6052 | } | |
6053 | if (aMapOfKeysByValues.Find ("PROJ", aValues)) | |
6054 | { | |
900f7229 | 6055 | if (aValues->IsEmpty()) |
197ac94e | 6056 | { |
6057 | Standard_Real aProjX = 0.0; | |
6058 | Standard_Real aProjY = 0.0; | |
6059 | Standard_Real aProjZ = 0.0; | |
6060 | anAISView->Proj (aProjX, aProjY, aProjZ); | |
6061 | theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n"; | |
6062 | } | |
6063 | else | |
6064 | { | |
900f7229 | 6065 | anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
197ac94e | 6066 | } |
6067 | } | |
6068 | if (aMapOfKeysByValues.Find ("UP", aValues)) | |
6069 | { | |
900f7229 | 6070 | if (aValues->IsEmpty()) |
197ac94e | 6071 | { |
6072 | Standard_Real anUpX = 0.0; | |
6073 | Standard_Real anUpY = 0.0; | |
6074 | Standard_Real anUpZ = 0.0; | |
6075 | anAISView->Up (anUpX, anUpY, anUpZ); | |
6076 | theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n"; | |
6077 | } | |
6078 | else | |
6079 | { | |
900f7229 | 6080 | anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
197ac94e | 6081 | } |
6082 | } | |
6083 | if (aMapOfKeysByValues.Find ("CENTER", aValues)) | |
6084 | { | |
900f7229 | 6085 | anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue()); |
197ac94e | 6086 | } |
6087 | ||
4754e164 | 6088 | return 0; |
6089 | } | |
6090 | ||
6091 | //======================================================================= | |
6092 | //function : VChangeSelected | |
dc3fe572 | 6093 | //purpose : Adds the shape to selection or remove one from it |
4754e164 | 6094 | //======================================================================= |
6095 | static Standard_Integer VChangeSelected (Draw_Interpretor& di, | |
6096 | Standard_Integer argc, | |
6097 | const char ** argv) | |
6098 | { | |
6099 | if(argc != 2) | |
6100 | { | |
6101 | di<<"Usage : " << argv[0] << " shape \n"; | |
6102 | return 1; | |
6103 | } | |
6104 | //get AIS_Shape: | |
6105 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6106 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
6107 | TCollection_AsciiString aName(argv[1]); | |
6108 | Handle(AIS_InteractiveObject) anAISObject; | |
6109 | ||
6110 | if(!aMap.IsBound2(aName)) | |
6111 | { | |
6112 | di<<"Use 'vdisplay' before"; | |
6113 | return 1; | |
6114 | } | |
6115 | else | |
6116 | { | |
6117 | anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName)); | |
6118 | if(anAISObject.IsNull()){ | |
6119 | di<<"No interactive object \n"; | |
6120 | return 1; | |
6121 | } | |
6122 | ||
c3282ec1 | 6123 | aContext->AddOrRemoveSelected(anAISObject); |
4754e164 | 6124 | } |
6125 | return 0; | |
6126 | } | |
6127 | ||
6128 | //======================================================================= | |
6129 | //function : VZClipping | |
dc3fe572 | 6130 | //purpose : Gets or sets ZClipping mode, width and depth |
4754e164 | 6131 | //======================================================================= |
6132 | static Standard_Integer VZClipping (Draw_Interpretor& di, | |
6133 | Standard_Integer argc, | |
6134 | const char ** argv) | |
6135 | { | |
dc3fe572 | 6136 | if(argc>4) |
4754e164 | 6137 | { |
586db386 | 6138 | di << "Usage : " << argv[0] << " [mode] [depth width]\n" |
6139 | <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"; | |
4754e164 | 6140 | return -1; |
6141 | } | |
6142 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
dc3fe572 | 6143 | if(aContext.IsNull()) |
4754e164 | 6144 | { |
6145 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6146 | return 1; | |
6147 | } | |
6148 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
1d47d8d0 | 6149 | V3d_TypeOfZclipping aZClippingMode = V3d_OFF; |
4754e164 | 6150 | if(argc==1) |
6151 | { | |
6152 | TCollection_AsciiString aZClippingModeString; | |
6153 | Quantity_Length aDepth, aWidth; | |
6154 | aZClippingMode = aView->ZClipping(aDepth, aWidth); | |
6155 | switch (aZClippingMode) | |
6156 | { | |
6157 | case V3d_OFF: | |
6158 | aZClippingModeString.Copy("OFF"); | |
6159 | break; | |
6160 | case V3d_BACK: | |
6161 | aZClippingModeString.Copy("BACK"); | |
6162 | break; | |
6163 | case V3d_FRONT: | |
6164 | aZClippingModeString.Copy("FRONT"); | |
6165 | break; | |
6166 | case V3d_SLICE: | |
6167 | aZClippingModeString.Copy("SLICE"); | |
6168 | break; | |
6169 | default: | |
6170 | aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode)); | |
6171 | break; | |
6172 | } | |
6173 | di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n" | |
6174 | << "ZClipping depth = " << aDepth << "\n" | |
6175 | << "ZClipping width = " << aWidth << "\n"; | |
6176 | } | |
6177 | else | |
6178 | { | |
6179 | if(argc !=3) | |
6180 | { | |
6181 | Standard_Integer aStatus = 0; | |
6182 | if ( strcmp (argv [1], "OFF") == 0 ) { | |
6183 | aStatus = 1; | |
6184 | aZClippingMode = V3d_OFF; | |
6185 | } | |
6186 | if ( strcmp (argv [1], "BACK") == 0 ) { | |
6187 | aStatus = 1; | |
6188 | aZClippingMode = V3d_BACK; | |
6189 | } | |
6190 | if ( strcmp (argv [1], "FRONT") == 0 ) { | |
6191 | aStatus = 1; | |
6192 | aZClippingMode = V3d_FRONT; | |
6193 | } | |
6194 | if ( strcmp (argv [1], "SLICE") == 0 ) { | |
6195 | aStatus = 1; | |
6196 | aZClippingMode = V3d_SLICE; | |
6197 | } | |
6198 | if (aStatus != 1) | |
6199 | { | |
586db386 | 6200 | di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]\n" |
6201 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"; | |
4754e164 | 6202 | return 1; |
dc3fe572 | 6203 | } |
4754e164 | 6204 | aView->SetZClippingType(aZClippingMode); |
6205 | } | |
6206 | if(argc >2) | |
6207 | { | |
6208 | Quantity_Length aDepth = 0., aWidth = 1.; | |
6209 | if(argc == 3) | |
6210 | { | |
6b62b2da | 6211 | aDepth = Draw::Atof (argv[1]); |
6212 | aWidth = Draw::Atof (argv[2]); | |
4754e164 | 6213 | } |
6214 | else if(argc == 4) | |
6215 | { | |
6b62b2da | 6216 | aDepth = Draw::Atof (argv[2]); |
6217 | aWidth = Draw::Atof (argv[3]); | |
4754e164 | 6218 | } |
dc3fe572 | 6219 | |
4754e164 | 6220 | if(aDepth<0. || aDepth>1.) |
6221 | { | |
586db386 | 6222 | di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]\n" |
6223 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"; | |
4754e164 | 6224 | return 1; |
6225 | } | |
6226 | if(aWidth<0. || aWidth>1.) | |
6227 | { | |
586db386 | 6228 | di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]\n" |
6229 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"; | |
4754e164 | 6230 | return 1; |
6231 | } | |
6232 | ||
6233 | aView->SetZClippingDepth(aDepth); | |
6234 | aView->SetZClippingWidth(aWidth); | |
6235 | } | |
6236 | aView->Redraw(); | |
6237 | } | |
6238 | return 0; | |
6239 | } | |
6240 | ||
6241 | //======================================================================= | |
6242 | //function : VNbSelected | |
dc3fe572 | 6243 | //purpose : Returns number of selected objects |
4754e164 | 6244 | //======================================================================= |
6245 | static Standard_Integer VNbSelected (Draw_Interpretor& di, | |
6246 | Standard_Integer argc, | |
6247 | const char ** argv) | |
6248 | { | |
6249 | if(argc != 1) | |
6250 | { | |
6251 | di << "Usage : " << argv[0] << "\n"; | |
6252 | return 1; | |
6253 | } | |
6254 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6255 | if(aContext.IsNull()) | |
6256 | { | |
6257 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6258 | return 1; | |
6259 | } | |
6260 | di << aContext->NbSelected() << "\n"; | |
6261 | return 0; | |
6262 | } | |
6263 | ||
6264 | //======================================================================= | |
6265 | //function : VAntialiasing | |
dc3fe572 | 6266 | //purpose : Switches altialiasing on or off |
4754e164 | 6267 | //======================================================================= |
6268 | static Standard_Integer VAntialiasing (Draw_Interpretor& di, | |
6269 | Standard_Integer argc, | |
6270 | const char ** argv) | |
6271 | { | |
6272 | if(argc > 2) | |
6273 | { | |
586db386 | 6274 | di << "Usage : " << argv[0] << " [1|0]\n"; |
4754e164 | 6275 | return 1; |
6276 | } | |
6277 | ||
6278 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6279 | if(aContext.IsNull()) | |
6280 | { | |
6281 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6282 | return 1; | |
6283 | } | |
6284 | ||
6285 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6286 | ||
6287 | if((argc == 2) && (atof(argv[1]) == 0)) | |
6288 | aView->SetAntialiasingOff(); | |
6289 | else | |
6290 | aView->SetAntialiasingOn(); | |
6291 | aView->Update(); | |
6292 | return 0; | |
6293 | } | |
6294 | ||
6295 | //======================================================================= | |
6296 | //function : VPurgeDisplay | |
dc3fe572 | 6297 | //purpose : Switches altialiasing on or off |
4754e164 | 6298 | //======================================================================= |
6299 | static Standard_Integer VPurgeDisplay (Draw_Interpretor& di, | |
6300 | Standard_Integer argc, | |
6301 | const char ** argv) | |
6302 | { | |
eb4320f2 | 6303 | if (argc > 1) |
4754e164 | 6304 | { |
eb4320f2 | 6305 | di << "Usage : " << argv[0] << "\n"; |
4754e164 | 6306 | return 1; |
6307 | } | |
4754e164 | 6308 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
6309 | if (aContext.IsNull()) | |
6310 | { | |
6311 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6312 | return 1; | |
6313 | } | |
6314 | aContext->CloseAllContexts(Standard_False); | |
eb4320f2 | 6315 | di << aContext->PurgeDisplay() << "\n"; |
4754e164 | 6316 | return 0; |
6317 | } | |
6318 | ||
6319 | //======================================================================= | |
6320 | //function : VSetViewSize | |
6321 | //purpose : | |
6322 | //======================================================================= | |
6323 | static Standard_Integer VSetViewSize (Draw_Interpretor& di, | |
6324 | Standard_Integer argc, | |
6325 | const char ** argv) | |
6326 | { | |
6327 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6328 | if(aContext.IsNull()) | |
6329 | { | |
6330 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6331 | return 1; | |
6332 | } | |
6333 | if(argc != 2) | |
6334 | { | |
6335 | di<<"Usage : " << argv[0] << " Size\n"; | |
6336 | return 1; | |
6337 | } | |
6b62b2da | 6338 | Standard_Real aSize = Draw::Atof (argv[1]); |
4754e164 | 6339 | if (aSize <= 0.) |
6340 | { | |
6341 | di<<"Bad Size value : " << aSize << "\n"; | |
6342 | return 1; | |
6343 | } | |
6344 | ||
6345 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6346 | aView->SetSize(aSize); | |
6347 | return 0; | |
6348 | } | |
6349 | ||
6350 | //======================================================================= | |
6351 | //function : VMoveView | |
6352 | //purpose : | |
6353 | //======================================================================= | |
6354 | static Standard_Integer VMoveView (Draw_Interpretor& di, | |
6355 | Standard_Integer argc, | |
6356 | const char ** argv) | |
6357 | { | |
6358 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6359 | if(aContext.IsNull()) | |
6360 | { | |
6361 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6362 | return 1; | |
6363 | } | |
6364 | if(argc < 4 || argc > 5) | |
6365 | { | |
6366 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
6367 | return 1; | |
6368 | } | |
6b62b2da | 6369 | Standard_Real Dx = Draw::Atof (argv[1]); |
6370 | Standard_Real Dy = Draw::Atof (argv[2]); | |
6371 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 6372 | Standard_Boolean aStart = Standard_True; |
6373 | if (argc == 5) | |
6374 | { | |
6b62b2da | 6375 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 6376 | } |
6377 | ||
6378 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6379 | aView->Move(Dx,Dy,Dz,aStart); | |
6380 | return 0; | |
6381 | } | |
6382 | ||
6383 | //======================================================================= | |
6384 | //function : VTranslateView | |
6385 | //purpose : | |
6386 | //======================================================================= | |
6387 | static Standard_Integer VTranslateView (Draw_Interpretor& di, | |
6388 | Standard_Integer argc, | |
6389 | const char ** argv) | |
6390 | { | |
6391 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6392 | if(aContext.IsNull()) | |
6393 | { | |
6394 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6395 | return 1; | |
6396 | } | |
6397 | if(argc < 4 || argc > 5) | |
6398 | { | |
6399 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
6400 | return 1; | |
6401 | } | |
6b62b2da | 6402 | Standard_Real Dx = Draw::Atof (argv[1]); |
6403 | Standard_Real Dy = Draw::Atof (argv[2]); | |
6404 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 6405 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 6406 | if (argc == 5) |
4754e164 | 6407 | { |
6b62b2da | 6408 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 6409 | } |
6410 | ||
6411 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6412 | aView->Translate(Dx,Dy,Dz,aStart); | |
6413 | return 0; | |
6414 | } | |
6415 | ||
6416 | //======================================================================= | |
6417 | //function : VTurnView | |
6418 | //purpose : | |
6419 | //======================================================================= | |
6420 | static Standard_Integer VTurnView (Draw_Interpretor& di, | |
6421 | Standard_Integer argc, | |
6422 | const char ** argv) | |
6423 | { | |
6424 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6425 | if(aContext.IsNull()) { | |
6426 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6427 | return 1; | |
6428 | } | |
6429 | if(argc < 4 || argc > 5){ | |
6430 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n"; | |
6431 | return 1; | |
6432 | } | |
6b62b2da | 6433 | Standard_Real Ax = Draw::Atof (argv[1]); |
6434 | Standard_Real Ay = Draw::Atof (argv[2]); | |
6435 | Standard_Real Az = Draw::Atof (argv[3]); | |
4754e164 | 6436 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 6437 | if (argc == 5) |
4754e164 | 6438 | { |
6b62b2da | 6439 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 6440 | } |
6441 | ||
6442 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6443 | aView->Turn(Ax,Ay,Az,aStart); | |
6444 | return 0; | |
6445 | } | |
6446 | ||
269294d6 | 6447 | //============================================================================== |
6448 | //function : VTextureEnv | |
6449 | //purpose : ENables or disables environment mapping | |
6450 | //============================================================================== | |
6451 | class OCC_TextureEnv : public Graphic3d_TextureEnv | |
6452 | { | |
6453 | public: | |
6454 | OCC_TextureEnv(const Standard_CString FileName); | |
6455 | OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName); | |
6456 | void SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
6457 | const Standard_Boolean theModulateFlag, | |
6458 | const Graphic3d_TypeOfTextureFilter theFilter, | |
6459 | const Standard_ShortReal theXScale, | |
6460 | const Standard_ShortReal theYScale, | |
6461 | const Standard_ShortReal theXShift, | |
6462 | const Standard_ShortReal theYShift, | |
6463 | const Standard_ShortReal theAngle); | |
68858c7d | 6464 | DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv) |
269294d6 | 6465 | }; |
a3f6f591 | 6466 | DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv) |
ec357c5c | 6467 | |
269294d6 | 6468 | OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName) |
6469 | : Graphic3d_TextureEnv(theFileName) | |
6470 | { | |
6471 | } | |
6472 | ||
6473 | OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId) | |
6474 | : Graphic3d_TextureEnv(theTexId) | |
6475 | { | |
6476 | } | |
6477 | ||
6478 | void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
6479 | const Standard_Boolean theModulateFlag, | |
6480 | const Graphic3d_TypeOfTextureFilter theFilter, | |
6481 | const Standard_ShortReal theXScale, | |
6482 | const Standard_ShortReal theYScale, | |
6483 | const Standard_ShortReal theXShift, | |
6484 | const Standard_ShortReal theYShift, | |
6485 | const Standard_ShortReal theAngle) | |
6486 | { | |
6487 | myParams->SetRepeat (theRepeatFlag); | |
6488 | myParams->SetModulate (theModulateFlag); | |
6489 | myParams->SetFilter (theFilter); | |
6490 | myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale)); | |
6491 | myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift)); | |
6492 | myParams->SetRotation (theAngle); | |
6493 | } | |
6494 | ||
35e08fe8 | 6495 | static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec) |
269294d6 | 6496 | { |
6497 | // get the active view | |
6498 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6499 | if (aView.IsNull()) | |
6500 | { | |
6501 | std::cerr << "No active view. Please call vinit.\n"; | |
6502 | return 1; | |
6503 | } | |
6504 | ||
6505 | // Checking the input arguments | |
6506 | Standard_Boolean anEnableFlag = Standard_False; | |
6507 | Standard_Boolean isOk = theArgNb >= 2; | |
6508 | if (isOk) | |
6509 | { | |
6510 | TCollection_AsciiString anEnableOpt(theArgVec[1]); | |
6511 | anEnableFlag = anEnableOpt.IsEqual("on"); | |
6512 | isOk = anEnableFlag || anEnableOpt.IsEqual("off"); | |
6513 | } | |
6514 | if (anEnableFlag) | |
6515 | { | |
6516 | isOk = (theArgNb == 3 || theArgNb == 11); | |
6517 | if (isOk) | |
6518 | { | |
6519 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
6520 | isOk = (!aTextureOpt.IsIntegerValue() || | |
6521 | (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN)); | |
6522 | ||
6523 | if (isOk && theArgNb == 11) | |
6524 | { | |
6525 | TCollection_AsciiString aRepeatOpt (theArgVec[3]), | |
6526 | aModulateOpt(theArgVec[4]), | |
6527 | aFilterOpt (theArgVec[5]), | |
6528 | aSScaleOpt (theArgVec[6]), | |
6529 | aTScaleOpt (theArgVec[7]), | |
6530 | aSTransOpt (theArgVec[8]), | |
6531 | aTTransOpt (theArgVec[9]), | |
6532 | anAngleOpt (theArgVec[10]); | |
6533 | isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) && | |
6534 | (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) && | |
6535 | (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) && | |
6536 | aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() && | |
6537 | aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() && | |
6538 | anAngleOpt.IsRealValue()); | |
6539 | } | |
6540 | } | |
6541 | } | |
6542 | ||
6543 | if (!isOk) | |
6544 | { | |
6545 | std::cerr << "Usage :" << std::endl; | |
6546 | std::cerr << theArgVec[0] << " off" << std::endl; | |
6547 | 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; | |
6548 | return 1; | |
6549 | } | |
6550 | ||
6551 | if (anEnableFlag) | |
6552 | { | |
6553 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
6554 | Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ? | |
6555 | new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) : | |
6556 | new OCC_TextureEnv(theArgVec[2]); | |
6557 | ||
6558 | if (theArgNb == 11) | |
6559 | { | |
6560 | TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]); | |
6561 | aTexEnv->SetTextureParameters( | |
6562 | aRepeatOpt. IsEqual("repeat"), | |
6563 | aModulateOpt.IsEqual("modulate"), | |
6564 | aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST : | |
6565 | aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR : | |
6566 | Graphic3d_TOTF_TRILINEAR, | |
6567 | (Standard_ShortReal)Draw::Atof(theArgVec[6]), | |
6568 | (Standard_ShortReal)Draw::Atof(theArgVec[7]), | |
6569 | (Standard_ShortReal)Draw::Atof(theArgVec[8]), | |
6570 | (Standard_ShortReal)Draw::Atof(theArgVec[9]), | |
6571 | (Standard_ShortReal)Draw::Atof(theArgVec[10]) | |
6572 | ); | |
6573 | } | |
6574 | aView->SetTextureEnv(aTexEnv); | |
6575 | aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT); | |
6576 | } | |
6577 | else // Disabling environment mapping | |
6578 | { | |
6579 | aView->SetSurfaceDetail(V3d_TEX_NONE); | |
6580 | Handle(Graphic3d_TextureEnv) aTexture; | |
6581 | aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data | |
6582 | } | |
6583 | ||
6584 | aView->Redraw(); | |
6585 | return 0; | |
6586 | } | |
6587 | ||
4269bd1b | 6588 | //=============================================================================================== |
6589 | //function : VClipPlane | |
6590 | //purpose : | |
6591 | //=============================================================================================== | |
6592 | static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
6593 | { | |
6594 | // use short-cut for created clip planes map of created (or "registered by name") clip planes | |
6595 | typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes; | |
6596 | static MapOfPlanes aRegPlanes; | |
6597 | ||
6598 | if (theArgsNb < 2) | |
6599 | { | |
6600 | theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n"; | |
6601 | return 1; | |
6602 | } | |
6603 | ||
6604 | TCollection_AsciiString aCommand (theArgVec[1]); | |
6605 | ||
6606 | // print maximum number of planes for current viewer | |
6607 | if (aCommand == "maxplanes") | |
6608 | { | |
6609 | if (theArgsNb < 3) | |
6610 | { | |
6611 | theDi << theArgVec[0] << ": view name is required. Type help for more information.\n"; | |
6612 | return 1; | |
6613 | } | |
6614 | ||
6615 | TCollection_AsciiString aViewName (theArgVec[2]); | |
6616 | ||
6617 | if (!ViewerTest_myViews.IsBound1 (aViewName)) | |
6618 | { | |
6619 | theDi << theArgVec[0] << ": view is not found.\n"; | |
6620 | return 1; | |
6621 | } | |
6622 | ||
6623 | const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName); | |
6624 | ||
6625 | theDi << theArgVec[0] << ": " | |
6626 | << aView->Viewer()->Driver()->InquirePlaneLimit() | |
6627 | << " plane slots provided by driver." | |
6628 | << " Note that 2 more planes might be used (reserved for z-clipping).\n"; | |
6629 | ||
6630 | return 0; | |
6631 | } | |
6632 | ||
6633 | // create / delete plane instance | |
6634 | if (aCommand == "create" || aCommand == "delete" || aCommand == "clone") | |
6635 | { | |
6636 | if (theArgsNb < 3) | |
6637 | { | |
6638 | theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n"; | |
6639 | return 1; | |
6640 | } | |
6641 | ||
6642 | Standard_Boolean toCreate = (aCommand == "create"); | |
6643 | Standard_Boolean toClone = (aCommand == "clone"); | |
6644 | TCollection_AsciiString aPlane (theArgVec[2]); | |
6645 | ||
6646 | if (toCreate) | |
6647 | { | |
6648 | if (aRegPlanes.IsBound (aPlane)) | |
6649 | { | |
6650 | theDi << theArgVec[0] << ": plane name is in use.\n"; | |
6651 | return 1; | |
6652 | } | |
6653 | ||
6654 | aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane()); | |
6655 | } | |
6656 | else if (toClone) // toClone | |
6657 | { | |
6658 | if (!aRegPlanes.IsBound (aPlane)) | |
6659 | { | |
6660 | theDi << theArgVec[0] << ": no such plane.\n"; | |
6661 | return 1; | |
6662 | } | |
6663 | ||
6664 | if (theArgsNb < 4) | |
6665 | { | |
6666 | theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n"; | |
6667 | return 1; | |
6668 | } | |
6669 | ||
6670 | TCollection_AsciiString aClone (theArgVec[3]); | |
6671 | if (aRegPlanes.IsBound (aClone)) | |
6672 | { | |
6673 | theDi << theArgVec[0] << ": plane name is in use.\n"; | |
6674 | return 1; | |
6675 | } | |
6676 | ||
6677 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
6678 | ||
6679 | aRegPlanes.Bind (aClone, aClipPlane->Clone()); | |
6680 | } | |
6681 | else// toDelete | |
6682 | { | |
6683 | if (!aRegPlanes.IsBound (aPlane)) | |
6684 | { | |
6685 | theDi << theArgVec[0] << ": no such plane.\n"; | |
6686 | return 1; | |
6687 | } | |
6688 | ||
6689 | Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane); | |
6690 | aRegPlanes.UnBind (aPlane); | |
6691 | ||
6692 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS()); | |
6693 | for (; anIObjIt.More(); anIObjIt.Next()) | |
6694 | { | |
6695 | Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1()); | |
6696 | aPrs->RemoveClipPlane(aClipPlane); | |
6697 | } | |
6698 | ||
6699 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
6700 | for (; aViewIt.More(); aViewIt.Next()) | |
6701 | { | |
6702 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
6703 | aView->RemoveClipPlane(aClipPlane); | |
6704 | } | |
6705 | ||
6706 | ViewerTest::RedrawAllViews(); | |
6707 | } | |
6708 | ||
6709 | return 0; | |
6710 | } | |
6711 | ||
6712 | // set / unset plane command | |
6713 | if (aCommand == "set" || aCommand == "unset") | |
6714 | { | |
6715 | if (theArgsNb < 4) | |
6716 | { | |
6717 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6718 | return 1; | |
6719 | } | |
6720 | ||
6721 | Standard_Boolean toSet = (aCommand == "set"); | |
6722 | TCollection_AsciiString aPlane (theArgVec [2]); | |
6723 | if (!aRegPlanes.IsBound (aPlane)) | |
6724 | { | |
6725 | theDi << theArgVec[0] << ": no such plane.\n"; | |
6726 | return 1; | |
6727 | } | |
6728 | ||
6729 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
6730 | ||
6731 | TCollection_AsciiString aTarget (theArgVec [3]); | |
6732 | if (aTarget != "object" && aTarget != "view") | |
6733 | { | |
6734 | theDi << theArgVec[0] << ": invalid target.\n"; | |
6735 | return 1; | |
6736 | } | |
6737 | ||
6738 | if (aTarget == "object" || aTarget == "view") | |
6739 | { | |
6740 | if (theArgsNb < 5) | |
6741 | { | |
6742 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6743 | return 1; | |
6744 | } | |
6745 | ||
6746 | Standard_Boolean isObject = (aTarget == "object"); | |
6747 | ||
6748 | for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt) | |
6749 | { | |
6750 | TCollection_AsciiString anEntityName (theArgVec[anIt]); | |
6751 | if (isObject) // to object | |
6752 | { | |
6753 | if (!GetMapOfAIS().IsBound2 (anEntityName)) | |
6754 | { | |
6755 | theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n"; | |
6756 | continue; | |
6757 | } | |
6758 | ||
6759 | Handle(AIS_InteractiveObject) aIObj = | |
6760 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName)); | |
6761 | ||
6762 | if (toSet) | |
6763 | aIObj->AddClipPlane (aClipPlane); | |
6764 | else | |
6765 | aIObj->RemoveClipPlane (aClipPlane); | |
6766 | } | |
6767 | else // to view | |
6768 | { | |
6769 | if (!ViewerTest_myViews.IsBound1 (anEntityName)) | |
6770 | { | |
6771 | theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n"; | |
6772 | continue; | |
6773 | } | |
6774 | ||
6775 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName); | |
6776 | if (toSet) | |
6777 | aView->AddClipPlane (aClipPlane); | |
6778 | else | |
6779 | aView->RemoveClipPlane (aClipPlane); | |
6780 | } | |
6781 | } | |
6782 | ||
6783 | ViewerTest::RedrawAllViews(); | |
6784 | } | |
6785 | ||
6786 | return 0; | |
6787 | } | |
6788 | ||
6789 | // change plane command | |
6790 | if (aCommand == "change") | |
6791 | { | |
6792 | if (theArgsNb < 4) | |
6793 | { | |
6794 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6795 | return 1; | |
6796 | } | |
6797 | ||
6798 | TCollection_AsciiString aPlane (theArgVec [2]); | |
6799 | if (!aRegPlanes.IsBound (aPlane)) | |
6800 | { | |
6801 | theDi << theArgVec[0] << ": no such plane.\n"; | |
6802 | return 1; | |
6803 | } | |
6804 | ||
6805 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
6806 | ||
6807 | TCollection_AsciiString aChangeArg (theArgVec [3]); | |
6808 | if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation") | |
6809 | { | |
6810 | theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n"; | |
6811 | return 1; | |
6812 | } | |
6813 | ||
6814 | if (aChangeArg == "on" || aChangeArg == "off") // on / off | |
6815 | { | |
6816 | aClipPlane->SetOn (aChangeArg == "on"); | |
6817 | } | |
6818 | else if (aChangeArg == "equation") // change equation | |
6819 | { | |
6820 | if (theArgsNb < 8) | |
6821 | { | |
6822 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6823 | return 1; | |
6824 | } | |
6825 | ||
6b62b2da | 6826 | Standard_Real aCoeffA = Draw::Atof (theArgVec [4]); |
6827 | Standard_Real aCoeffB = Draw::Atof (theArgVec [5]); | |
6828 | Standard_Real aCoeffC = Draw::Atof (theArgVec [6]); | |
6829 | Standard_Real aCoeffD = Draw::Atof (theArgVec [7]); | |
4269bd1b | 6830 | aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD)); |
6831 | } | |
6832 | else if (aChangeArg == "capping") // change capping aspects | |
6833 | { | |
6834 | if (theArgsNb < 5) | |
6835 | { | |
6836 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6837 | return 1; | |
6838 | } | |
6839 | ||
6840 | TCollection_AsciiString aCappingArg (theArgVec [4]); | |
6841 | if (aCappingArg != "on" && aCappingArg != "off" && | |
6842 | aCappingArg != "color" && aCappingArg != "texname" && | |
6843 | aCappingArg != "texscale" && aCappingArg != "texorigin" && | |
6844 | aCappingArg != "texrotate" && aCappingArg != "hatch") | |
6845 | { | |
6846 | theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n"; | |
6847 | return 1; | |
6848 | } | |
6849 | ||
6850 | if (aCappingArg == "on" || aCappingArg == "off") // on / off capping | |
6851 | { | |
6852 | aClipPlane->SetCapping (aCappingArg == "on"); | |
6853 | } | |
6854 | else if (aCappingArg == "color") // color aspect for capping | |
6855 | { | |
6856 | if (theArgsNb < 8) | |
6857 | { | |
6858 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6859 | return 1; | |
6860 | } | |
6861 | ||
6b62b2da | 6862 | Standard_Real aRed = Draw::Atof (theArgVec [5]); |
6863 | Standard_Real aGrn = Draw::Atof (theArgVec [6]); | |
6864 | Standard_Real aBlu = Draw::Atof (theArgVec [7]); | |
4269bd1b | 6865 | |
6866 | Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); | |
8aeeca44 | 6867 | Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB); |
6868 | aMat.SetAmbientColor (aColor); | |
6869 | aMat.SetDiffuseColor (aColor); | |
4269bd1b | 6870 | aClipPlane->SetCappingMaterial (aMat); |
6871 | } | |
6872 | else if (aCappingArg == "texname") // texture name | |
6873 | { | |
6874 | if (theArgsNb < 6) | |
6875 | { | |
6876 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6877 | return 1; | |
6878 | } | |
6879 | ||
6880 | TCollection_AsciiString aTextureName (theArgVec [5]); | |
6881 | ||
6882 | Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); | |
6883 | if (!aTexture->IsDone ()) | |
6884 | { | |
6885 | aClipPlane->SetCappingTexture (NULL); | |
6886 | } | |
6887 | else | |
6888 | { | |
6889 | aTexture->EnableModulate(); | |
6890 | aTexture->EnableRepeat(); | |
6891 | aClipPlane->SetCappingTexture (aTexture); | |
6892 | } | |
6893 | } | |
6894 | else if (aCappingArg == "texscale") // texture scale | |
6895 | { | |
6896 | if (aClipPlane->CappingTexture().IsNull()) | |
6897 | { | |
6898 | theDi << theArgVec[0] << ": no texture is set.\n"; | |
6899 | return 1; | |
6900 | } | |
6901 | ||
6902 | if (theArgsNb < 7) | |
6903 | { | |
6904 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6905 | return 1; | |
6906 | } | |
6907 | ||
6908 | Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]); | |
6909 | Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]); | |
6910 | ||
6911 | aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); | |
6912 | } | |
6913 | else if (aCappingArg == "texorigin") // texture origin | |
6914 | { | |
6915 | if (aClipPlane->CappingTexture().IsNull()) | |
6916 | { | |
6917 | theDi << theArgVec[0] << ": no texture is set.\n"; | |
6918 | return 1; | |
6919 | } | |
6920 | ||
6921 | if (theArgsNb < 7) | |
6922 | { | |
6923 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6924 | return 1; | |
6925 | } | |
6926 | ||
6927 | Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]); | |
6928 | Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]); | |
6929 | ||
6930 | aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); | |
6931 | } | |
6932 | else if (aCappingArg == "texrotate") // texture rotation | |
6933 | { | |
6934 | if (aClipPlane->CappingTexture().IsNull()) | |
6935 | { | |
6936 | theDi << theArgVec[0] << ": no texture is set.\n"; | |
6937 | return 1; | |
6938 | } | |
6939 | ||
6940 | if (theArgsNb < 6) | |
6941 | { | |
6942 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6943 | return 1; | |
6944 | } | |
6945 | ||
6946 | Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]); | |
6947 | ||
6948 | aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot); | |
6949 | } | |
6950 | else if (aCappingArg == "hatch") // hatch style | |
6951 | { | |
6952 | if (theArgsNb < 6) | |
6953 | { | |
6954 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6955 | return 1; | |
6956 | } | |
6957 | ||
6958 | TCollection_AsciiString aHatchStr (theArgVec [5]); | |
6959 | if (aHatchStr == "on") | |
6960 | { | |
6961 | aClipPlane->SetCappingHatchOn(); | |
6962 | } | |
6963 | else if (aHatchStr == "off") | |
6964 | { | |
6965 | aClipPlane->SetCappingHatchOff(); | |
6966 | } | |
6967 | else | |
6968 | { | |
6969 | aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5])); | |
6970 | } | |
6971 | } | |
6972 | } | |
6973 | ||
6974 | ViewerTest::RedrawAllViews(); | |
6975 | ||
6976 | return 0; | |
6977 | } | |
6978 | ||
6979 | theDi << theArgVec[0] << ": invalid command. Type help for more information.\n"; | |
6980 | return 1; | |
6981 | } | |
6982 | ||
6983 | //=============================================================================================== | |
6984 | //function : VSetTextureMode | |
6985 | //purpose : | |
6986 | //=============================================================================================== | |
6987 | static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
6988 | { | |
6989 | if (theArgsNb < 3) | |
6990 | { | |
6991 | theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n"; | |
6992 | return 1; | |
6993 | } | |
6994 | ||
6995 | TCollection_AsciiString aViewName (theArgVec[1]); | |
6996 | if (!ViewerTest_myViews.IsBound1 (aViewName)) | |
6997 | { | |
6998 | theDi << theArgVec[0] << ": view is not found.\n"; | |
6999 | return 1; | |
7000 | } | |
7001 | ||
7002 | const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName); | |
7003 | switch (atoi (theArgVec[2])) | |
7004 | { | |
7005 | case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break; | |
7006 | case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break; | |
7007 | case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break; | |
7008 | default: | |
7009 | theDi << theArgVec[0] << ": invalid mode.\n"; | |
7010 | return 1; | |
7011 | } | |
7012 | ||
7013 | aView->Redraw(); | |
7014 | return 0; | |
7015 | } | |
7016 | ||
b5ac8292 | 7017 | //=============================================================================================== |
7018 | //function : VZRange | |
7019 | //purpose : | |
7020 | //=============================================================================================== | |
7021 | static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
7022 | { | |
197ac94e | 7023 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
7024 | ||
7025 | if (aCurrentView.IsNull()) | |
b5ac8292 | 7026 | { |
197ac94e | 7027 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
b5ac8292 | 7028 | return 1; |
7029 | } | |
7030 | ||
197ac94e | 7031 | Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera(); |
b5ac8292 | 7032 | |
7033 | if (theArgsNb < 2) | |
7034 | { | |
7035 | theDi << "ZNear: " << aCamera->ZNear() << "\n"; | |
7036 | theDi << "ZFar: " << aCamera->ZFar() << "\n"; | |
7037 | return 0; | |
7038 | } | |
7039 | ||
7040 | if (theArgsNb == 3) | |
7041 | { | |
6b62b2da | 7042 | Standard_Real aNewZNear = Draw::Atof (theArgVec[1]); |
7043 | Standard_Real aNewZFar = Draw::Atof (theArgVec[2]); | |
197ac94e | 7044 | |
7045 | if (aNewZNear >= aNewZFar) | |
7046 | { | |
7047 | std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n"; | |
7048 | return 1; | |
7049 | } | |
7050 | ||
7051 | if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0)) | |
7052 | { | |
7053 | std::cout << theArgVec[0] << ": invalid arguments: "; | |
7054 | std::cout << "znear, zfar should be positive for perspective camera.\n"; | |
7055 | return 1; | |
7056 | } | |
7057 | ||
7058 | aCamera->SetZRange (aNewZNear, aNewZFar); | |
b5ac8292 | 7059 | } |
7060 | else | |
7061 | { | |
197ac94e | 7062 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
b5ac8292 | 7063 | return 1; |
7064 | } | |
7065 | ||
197ac94e | 7066 | aCurrentView->Redraw(); |
7067 | ||
b5ac8292 | 7068 | return 0; |
7069 | } | |
7070 | ||
7071 | //=============================================================================================== | |
7072 | //function : VAutoZFit | |
7073 | //purpose : | |
7074 | //=============================================================================================== | |
7075 | static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
7076 | { | |
197ac94e | 7077 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
7078 | ||
7079 | if (aCurrentView.IsNull()) | |
b5ac8292 | 7080 | { |
197ac94e | 7081 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
b5ac8292 | 7082 | return 1; |
7083 | } | |
7084 | ||
c357e426 | 7085 | Standard_Real aScale = aCurrentView->AutoZFitScaleFactor(); |
197ac94e | 7086 | |
7087 | if (theArgsNb > 3) | |
b5ac8292 | 7088 | { |
197ac94e | 7089 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
7090 | return 1; | |
b5ac8292 | 7091 | } |
7092 | ||
197ac94e | 7093 | if (theArgsNb < 2) |
b5ac8292 | 7094 | { |
586db386 | 7095 | theDi << "Auto z-fit mode: \n" |
c357e426 | 7096 | << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n" |
197ac94e | 7097 | << "Scale: " << aScale << "\n"; |
7098 | return 0; | |
b5ac8292 | 7099 | } |
197ac94e | 7100 | |
7101 | Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1; | |
7102 | ||
7103 | if (theArgsNb >= 3) | |
b5ac8292 | 7104 | { |
197ac94e | 7105 | aScale = Draw::Atoi (theArgVec[2]); |
b5ac8292 | 7106 | } |
7107 | ||
c357e426 | 7108 | aCurrentView->SetAutoZFitMode (isOn, aScale); |
7109 | aCurrentView->AutoZFit(); | |
197ac94e | 7110 | aCurrentView->Redraw(); |
7111 | ||
b5ac8292 | 7112 | return 0; |
7113 | } | |
7114 | ||
6b62b2da | 7115 | //! Auxiliary function to print projection type |
7116 | inline const char* projTypeName (Graphic3d_Camera::Projection theProjType) | |
7117 | { | |
7118 | switch (theProjType) | |
7119 | { | |
7120 | case Graphic3d_Camera::Projection_Orthographic: return "orthographic"; | |
7121 | case Graphic3d_Camera::Projection_Perspective: return "perspective"; | |
7122 | case Graphic3d_Camera::Projection_Stereo: return "stereoscopic"; | |
7123 | case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye"; | |
7124 | case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye"; | |
7125 | } | |
7126 | return "UNKNOWN"; | |
7127 | } | |
7128 | ||
b5ac8292 | 7129 | //=============================================================================================== |
6b62b2da | 7130 | //function : VCamera |
b5ac8292 | 7131 | //purpose : |
7132 | //=============================================================================================== | |
6b62b2da | 7133 | static int VCamera (Draw_Interpretor& theDI, |
7134 | Standard_Integer theArgsNb, | |
7135 | const char** theArgVec) | |
b5ac8292 | 7136 | { |
6b62b2da | 7137 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
7138 | if (aView.IsNull()) | |
b5ac8292 | 7139 | { |
6b62b2da | 7140 | std::cout << "Error: no active view.\n"; |
b5ac8292 | 7141 | return 1; |
7142 | } | |
7143 | ||
6b62b2da | 7144 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); |
7145 | if (theArgsNb < 2) | |
b5ac8292 | 7146 | { |
6b62b2da | 7147 | theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n"; |
7148 | theDI << "FOVy: " << aCamera->FOVy() << "\n"; | |
7149 | theDI << "Distance: " << aCamera->Distance() << "\n"; | |
7150 | theDI << "IOD: " << aCamera->IOD() << "\n"; | |
7151 | theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n"; | |
7152 | theDI << "ZFocus: " << aCamera->ZFocus() << "\n"; | |
7153 | theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n"; | |
7154 | return 0; | |
b5ac8292 | 7155 | } |
7156 | ||
6b62b2da | 7157 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) |
b5ac8292 | 7158 | { |
6b62b2da | 7159 | Standard_CString anArg = theArgVec[anArgIter]; |
7160 | TCollection_AsciiString anArgCase (anArg); | |
7161 | anArgCase.LowerCase(); | |
7162 | if (anArgCase == "-proj" | |
7163 | || anArgCase == "-projection" | |
7164 | || anArgCase == "-projtype" | |
7165 | || anArgCase == "-projectiontype") | |
7166 | { | |
7167 | theDI << projTypeName (aCamera->ProjectionType()) << " "; | |
7168 | } | |
7169 | else if (anArgCase == "-ortho" | |
7170 | || anArgCase == "-orthographic") | |
b5ac8292 | 7171 | { |
7172 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic); | |
6b62b2da | 7173 | } |
7174 | else if (anArgCase == "-persp" | |
7175 | || anArgCase == "-perspective" | |
7176 | || anArgCase == "-perspmono" | |
7177 | || anArgCase == "-perspectivemono" | |
7178 | || anArgCase == "-mono") | |
b5ac8292 | 7179 | { |
7180 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); | |
7181 | } | |
6b62b2da | 7182 | else if (anArgCase == "-stereo" |
7183 | || anArgCase == "-stereoscopic" | |
7184 | || anArgCase == "-perspstereo" | |
7185 | || anArgCase == "-perspectivestereo") | |
7186 | { | |
7187 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
7188 | } | |
7189 | else if (anArgCase == "-left" | |
7190 | || anArgCase == "-lefteye" | |
7191 | || anArgCase == "-monoleft" | |
7192 | || anArgCase == "-monolefteye" | |
7193 | || anArgCase == "-perpsleft" | |
7194 | || anArgCase == "-perpslefteye") | |
b5ac8292 | 7195 | { |
7196 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye); | |
7197 | } | |
6b62b2da | 7198 | else if (anArgCase == "-right" |
7199 | || anArgCase == "-righteye" | |
7200 | || anArgCase == "-monoright" | |
7201 | || anArgCase == "-monorighteye" | |
7202 | || anArgCase == "-perpsright") | |
b5ac8292 | 7203 | { |
7204 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye); | |
7205 | } | |
6b62b2da | 7206 | else if (anArgCase == "-dist" |
7207 | || anArgCase == "-distance") | |
b5ac8292 | 7208 | { |
6b62b2da | 7209 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
7210 | if (anArgValue != NULL | |
7211 | && *anArgValue != '-') | |
7212 | { | |
7213 | ++anArgIter; | |
7214 | aCamera->SetDistance (Draw::Atof (anArgValue)); | |
7215 | continue; | |
7216 | } | |
7217 | theDI << aCamera->Distance() << " "; | |
b5ac8292 | 7218 | } |
6b62b2da | 7219 | else if (anArgCase == "-iod") |
b5ac8292 | 7220 | { |
6b62b2da | 7221 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
7222 | if (anArgValue != NULL | |
7223 | && *anArgValue != '-') | |
7224 | { | |
7225 | ++anArgIter; | |
7226 | aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue)); | |
7227 | continue; | |
7228 | } | |
7229 | theDI << aCamera->IOD() << " "; | |
b5ac8292 | 7230 | } |
6b62b2da | 7231 | else if (anArgCase == "-iodtype") |
b5ac8292 | 7232 | { |
6b62b2da | 7233 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
7234 | TCollection_AsciiString anValueCase (anArgValue); | |
7235 | anValueCase.LowerCase(); | |
7236 | if (anValueCase == "abs" | |
7237 | || anValueCase == "absolute") | |
7238 | { | |
7239 | ++anArgIter; | |
7240 | aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD()); | |
7241 | continue; | |
7242 | } | |
7243 | else if (anValueCase == "rel" | |
7244 | || anValueCase == "relative") | |
7245 | { | |
7246 | ++anArgIter; | |
7247 | aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD()); | |
7248 | continue; | |
7249 | } | |
7250 | else if (*anArgValue != '-') | |
7251 | { | |
7252 | std::cout << "Error: unknown IOD type '" << anArgValue << "'\n"; | |
7253 | return 1; | |
7254 | } | |
7255 | switch (aCamera->GetIODType()) | |
7256 | { | |
7257 | case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break; | |
7258 | case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break; | |
7259 | } | |
b5ac8292 | 7260 | } |
6b62b2da | 7261 | else if (anArgCase == "-zfocus") |
b5ac8292 | 7262 | { |
6b62b2da | 7263 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
7264 | if (anArgValue != NULL | |
7265 | && *anArgValue != '-') | |
7266 | { | |
7267 | ++anArgIter; | |
7268 | aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue)); | |
7269 | continue; | |
7270 | } | |
7271 | theDI << aCamera->ZFocus() << " "; | |
b5ac8292 | 7272 | } |
6b62b2da | 7273 | else if (anArgCase == "-zfocustype") |
b5ac8292 | 7274 | { |
6b62b2da | 7275 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
7276 | TCollection_AsciiString anValueCase (anArgValue); | |
7277 | anValueCase.LowerCase(); | |
7278 | if (anValueCase == "abs" | |
7279 | || anValueCase == "absolute") | |
7280 | { | |
7281 | ++anArgIter; | |
7282 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus()); | |
7283 | continue; | |
7284 | } | |
7285 | else if (anValueCase == "rel" | |
7286 | || anValueCase == "relative") | |
7287 | { | |
7288 | ++anArgIter; | |
7289 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus()); | |
7290 | continue; | |
7291 | } | |
7292 | else if (*anArgValue != '-') | |
7293 | { | |
7294 | std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n"; | |
7295 | return 1; | |
7296 | } | |
7297 | switch (aCamera->ZFocusType()) | |
7298 | { | |
7299 | case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break; | |
7300 | case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break; | |
7301 | } | |
7302 | } | |
7303 | else if (anArgCase == "-fov" | |
7304 | || anArgCase == "-fovy") | |
b5ac8292 | 7305 | { |
6b62b2da | 7306 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
7307 | if (anArgValue != NULL | |
7308 | && *anArgValue != '-') | |
7309 | { | |
7310 | ++anArgIter; | |
7311 | aCamera->SetFOVy (Draw::Atof (anArgValue)); | |
7312 | continue; | |
7313 | } | |
7314 | theDI << aCamera->FOVy() << " "; | |
b5ac8292 | 7315 | } |
7316 | else | |
7317 | { | |
6b62b2da | 7318 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
b5ac8292 | 7319 | return 1; |
7320 | } | |
7321 | } | |
b5ac8292 | 7322 | |
c357e426 | 7323 | aView->AutoZFit(); |
6b62b2da | 7324 | aView->Redraw(); |
b5ac8292 | 7325 | |
7326 | return 0; | |
7327 | } | |
7328 | ||
f978241f | 7329 | //! Parse stereo output mode |
7330 | inline Standard_Boolean parseStereoMode (Standard_CString theArg, | |
7331 | Graphic3d_StereoMode& theMode) | |
7332 | { | |
7333 | TCollection_AsciiString aFlag (theArg); | |
7334 | aFlag.LowerCase(); | |
7335 | if (aFlag == "quadbuffer") | |
7336 | { | |
7337 | theMode = Graphic3d_StereoMode_QuadBuffer; | |
7338 | } | |
7339 | else if (aFlag == "anaglyph") | |
7340 | { | |
7341 | theMode = Graphic3d_StereoMode_Anaglyph; | |
7342 | } | |
7343 | else if (aFlag == "row" | |
7344 | || aFlag == "rowinterlaced") | |
7345 | { | |
7346 | theMode = Graphic3d_StereoMode_RowInterlaced; | |
7347 | } | |
7348 | else if (aFlag == "col" | |
7349 | || aFlag == "colinterlaced" | |
7350 | || aFlag == "columninterlaced") | |
7351 | { | |
7352 | theMode = Graphic3d_StereoMode_ColumnInterlaced; | |
7353 | } | |
7354 | else if (aFlag == "chess" | |
7355 | || aFlag == "chessboard") | |
7356 | { | |
7357 | theMode = Graphic3d_StereoMode_ChessBoard; | |
7358 | } | |
7359 | else if (aFlag == "sbs" | |
7360 | || aFlag == "sidebyside") | |
7361 | { | |
7362 | theMode = Graphic3d_StereoMode_SideBySide; | |
7363 | } | |
7364 | else if (aFlag == "ou" | |
7365 | || aFlag == "overunder") | |
7366 | { | |
7367 | theMode = Graphic3d_StereoMode_OverUnder; | |
7368 | } | |
7369 | else if (aFlag == "pageflip" | |
7370 | || aFlag == "softpageflip") | |
7371 | { | |
7372 | theMode = Graphic3d_StereoMode_SoftPageFlip; | |
7373 | } | |
7374 | else | |
7375 | { | |
7376 | return Standard_False; | |
7377 | } | |
7378 | return Standard_True; | |
7379 | } | |
7380 | ||
7381 | //! Parse anaglyph filter | |
7382 | inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg, | |
7383 | Graphic3d_RenderingParams::Anaglyph& theFilter) | |
7384 | { | |
7385 | TCollection_AsciiString aFlag (theArg); | |
7386 | aFlag.LowerCase(); | |
7387 | if (aFlag == "redcyansimple") | |
7388 | { | |
7389 | theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple; | |
7390 | } | |
7391 | else if (aFlag == "redcyan" | |
7392 | || aFlag == "redcyanoptimized") | |
7393 | { | |
7394 | theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized; | |
7395 | } | |
7396 | else if (aFlag == "yellowbluesimple") | |
7397 | { | |
7398 | theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple; | |
7399 | } | |
7400 | else if (aFlag == "yellowblue" | |
7401 | || aFlag == "yellowblueoptimized") | |
7402 | { | |
7403 | theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized; | |
7404 | } | |
7405 | else if (aFlag == "greenmagenta" | |
7406 | || aFlag == "greenmagentasimple") | |
7407 | { | |
7408 | theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple; | |
7409 | } | |
7410 | else | |
7411 | { | |
7412 | return Standard_False; | |
7413 | } | |
7414 | return Standard_True; | |
7415 | } | |
7416 | ||
b5ac8292 | 7417 | //============================================================================== |
7418 | //function : VStereo | |
7419 | //purpose : | |
7420 | //============================================================================== | |
7421 | ||
7422 | static int VStereo (Draw_Interpretor& theDI, | |
7423 | Standard_Integer theArgNb, | |
7424 | const char** theArgVec) | |
7425 | { | |
f978241f | 7426 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
b5ac8292 | 7427 | if (theArgNb < 2) |
7428 | { | |
b5ac8292 | 7429 | if (aView.IsNull()) |
7430 | { | |
f978241f | 7431 | std::cout << "Error: no active viewer!\n"; |
b5ac8292 | 7432 | return 0; |
7433 | } | |
7434 | ||
7435 | Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo; | |
7436 | theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n"; | |
bf02aa7d | 7437 | if (isActive) |
7438 | { | |
7439 | TCollection_AsciiString aMode; | |
7440 | switch (aView->RenderingParams().StereoMode) | |
7441 | { | |
7442 | case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break; | |
7443 | case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break; | |
7444 | case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break; | |
7445 | case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break; | |
7446 | case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break; | |
7447 | case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break; | |
7448 | case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break; | |
7449 | case Graphic3d_StereoMode_Anaglyph : | |
7450 | aMode = "anaglyph"; | |
7451 | switch (aView->RenderingParams().AnaglyphFilter) | |
7452 | { | |
7453 | case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break; | |
7454 | case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break; | |
7455 | case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break; | |
7456 | case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break; | |
7457 | case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break; | |
7458 | default: break; | |
7459 | } | |
7460 | default: break; | |
7461 | } | |
7462 | theDI << "Mode " << aMode << "\n"; | |
7463 | } | |
b5ac8292 | 7464 | return 0; |
7465 | } | |
7466 | ||
f978241f | 7467 | Handle(Graphic3d_Camera) aCamera; |
7468 | Graphic3d_RenderingParams* aParams = NULL; | |
7469 | Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer; | |
7470 | if (!aView.IsNull()) | |
7471 | { | |
7472 | aParams = &aView->ChangeRenderingParams(); | |
7473 | aMode = aParams->StereoMode; | |
7474 | aCamera = aView->Camera(); | |
7475 | } | |
7476 | ||
7477 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); | |
7478 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
7479 | { | |
7480 | Standard_CString anArg = theArgVec[anArgIter]; | |
7481 | TCollection_AsciiString aFlag (anArg); | |
7482 | aFlag.LowerCase(); | |
7483 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
7484 | { | |
7485 | continue; | |
7486 | } | |
7487 | else if (aFlag == "0" | |
7488 | || aFlag == "off") | |
7489 | { | |
7490 | if (++anArgIter < theArgNb) | |
7491 | { | |
7492 | std::cout << "Error: wrong number of arguments!\n"; | |
7493 | return 1; | |
7494 | } | |
7495 | ||
7496 | if (!aCamera.IsNull() | |
7497 | && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo) | |
7498 | { | |
7499 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); | |
7500 | } | |
7501 | ViewerTest_myDefaultCaps.contextStereo = Standard_False; | |
7502 | return 0; | |
7503 | } | |
7504 | else if (aFlag == "1" | |
7505 | || aFlag == "on") | |
7506 | { | |
7507 | if (++anArgIter < theArgNb) | |
7508 | { | |
7509 | std::cout << "Error: wrong number of arguments!\n"; | |
7510 | return 1; | |
7511 | } | |
7512 | ||
7513 | if (!aCamera.IsNull()) | |
7514 | { | |
7515 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
7516 | } | |
7517 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
7518 | return 0; | |
7519 | } | |
7520 | else if (aFlag == "-reverse" | |
7521 | || aFlag == "-reversed" | |
7522 | || aFlag == "-swap") | |
7523 | { | |
7524 | Standard_Boolean toEnable = Standard_True; | |
7525 | if (++anArgIter < theArgNb | |
a5565a3c | 7526 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 7527 | { |
7528 | --anArgIter; | |
7529 | } | |
7530 | aParams->ToReverseStereo = toEnable; | |
7531 | } | |
7532 | else if (aFlag == "-noreverse" | |
7533 | || aFlag == "-noswap") | |
7534 | { | |
7535 | Standard_Boolean toDisable = Standard_True; | |
7536 | if (++anArgIter < theArgNb | |
a5565a3c | 7537 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable)) |
f978241f | 7538 | { |
7539 | --anArgIter; | |
7540 | } | |
7541 | aParams->ToReverseStereo = !toDisable; | |
7542 | } | |
7543 | else if (aFlag == "-mode" | |
7544 | || aFlag == "-stereomode") | |
7545 | { | |
7546 | if (++anArgIter >= theArgNb | |
7547 | || !parseStereoMode (theArgVec[anArgIter], aMode)) | |
7548 | { | |
7549 | std::cout << "Error: syntax error at '" << anArg << "'\n"; | |
7550 | return 1; | |
7551 | } | |
7552 | ||
7553 | if (aMode == Graphic3d_StereoMode_QuadBuffer) | |
7554 | { | |
7555 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
7556 | } | |
7557 | } | |
7558 | else if (aFlag == "-anaglyph" | |
7559 | || aFlag == "-anaglyphfilter") | |
7560 | { | |
7561 | Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple; | |
7562 | if (++anArgIter >= theArgNb | |
7563 | || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter)) | |
7564 | { | |
7565 | std::cout << "Error: syntax error at '" << anArg << "'\n"; | |
7566 | return 1; | |
7567 | } | |
7568 | ||
7569 | aMode = Graphic3d_StereoMode_Anaglyph; | |
7570 | aParams->AnaglyphFilter = aFilter; | |
7571 | } | |
7572 | else if (parseStereoMode (anArg, aMode)) // short syntax | |
7573 | { | |
7574 | if (aMode == Graphic3d_StereoMode_QuadBuffer) | |
7575 | { | |
7576 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
7577 | } | |
7578 | } | |
7579 | else | |
7580 | { | |
7581 | std::cout << "Error: syntax error at '" << anArg << "'\n"; | |
7582 | return 1; | |
7583 | } | |
7584 | } | |
7585 | ||
7586 | if (!aView.IsNull()) | |
7587 | { | |
7588 | aParams->StereoMode = aMode; | |
7589 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
7590 | } | |
b5ac8292 | 7591 | return 0; |
7592 | } | |
7593 | ||
392ac980 | 7594 | //=============================================================================================== |
7595 | //function : VDefaults | |
7596 | //purpose : | |
7597 | //=============================================================================================== | |
7598 | static int VDefaults (Draw_Interpretor& theDi, | |
7599 | Standard_Integer theArgsNb, | |
7600 | const char** theArgVec) | |
7601 | { | |
7602 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
7603 | if (aCtx.IsNull()) | |
7604 | { | |
7605 | std::cerr << "No active viewer!\n"; | |
7606 | return 1; | |
7607 | } | |
7608 | ||
7609 | Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer(); | |
7610 | if (theArgsNb < 2) | |
7611 | { | |
7612 | if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE) | |
7613 | { | |
7614 | theDi << "DeflType: relative\n" | |
7615 | << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n"; | |
7616 | } | |
7617 | else | |
7618 | { | |
7619 | theDi << "DeflType: absolute\n" | |
7620 | << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n"; | |
7621 | } | |
7622 | theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n"; | |
4c513386 | 7623 | theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n"; |
392ac980 | 7624 | return 0; |
7625 | } | |
7626 | ||
7627 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
7628 | { | |
7629 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4c513386 | 7630 | anArg.UpperCase(); |
7631 | if (anArg == "-ABSDEFL" | |
7632 | || anArg == "-ABSOLUTEDEFLECTION" | |
7633 | || anArg == "-DEFL" | |
7634 | || anArg == "-DEFLECTION") | |
392ac980 | 7635 | { |
4c513386 | 7636 | if (++anArgIter >= theArgsNb) |
7637 | { | |
7638 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
7639 | return 1; | |
7640 | } | |
392ac980 | 7641 | aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE); |
4c513386 | 7642 | aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter])); |
392ac980 | 7643 | } |
4c513386 | 7644 | else if (anArg == "-RELDEFL" |
7645 | || anArg == "-RELATIVEDEFLECTION" | |
7646 | || anArg == "-DEVCOEFF" | |
7647 | || anArg == "-DEVIATIONCOEFF" | |
7648 | || anArg == "-DEVIATIONCOEFFICIENT") | |
392ac980 | 7649 | { |
4c513386 | 7650 | if (++anArgIter >= theArgsNb) |
7651 | { | |
7652 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
7653 | return 1; | |
7654 | } | |
392ac980 | 7655 | aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE); |
4c513386 | 7656 | aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter])); |
392ac980 | 7657 | } |
4c513386 | 7658 | else if (anArg == "-ANGDEFL" |
7659 | || anArg == "-ANGULARDEFL" | |
7660 | || anArg == "-ANGULARDEFLECTION") | |
392ac980 | 7661 | { |
4c513386 | 7662 | if (++anArgIter >= theArgsNb) |
7663 | { | |
7664 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
7665 | return 1; | |
7666 | } | |
392ac980 | 7667 | // currently HLRDeviationAngle is used instead of DeviationAngle in most places |
4c513386 | 7668 | aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0); |
7669 | } | |
385c43e7 | 7670 | else if (anArg == "-AUTOTR" |
7671 | || anArg == "-AUTOTRIANG" | |
7672 | || anArg == "-AUTOTRIANGULATION") | |
4c513386 | 7673 | { |
7674 | if (++anArgIter >= theArgsNb) | |
7675 | { | |
7676 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
7677 | return 1; | |
7678 | } | |
7679 | TCollection_AsciiString aValue (theArgVec[anArgIter]); | |
7680 | aValue.LowerCase(); | |
7681 | if (aValue == "on" | |
7682 | || aValue == "1") | |
7683 | { | |
7684 | aDefParams->SetAutoTriangulation (Standard_True); | |
7685 | } | |
7686 | else if (aValue == "off" | |
7687 | || aValue == "0") | |
7688 | { | |
7689 | aDefParams->SetAutoTriangulation (Standard_False); | |
7690 | } | |
392ac980 | 7691 | } |
7692 | else | |
7693 | { | |
7694 | std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n"; | |
7695 | } | |
7696 | } | |
7697 | ||
7698 | return 0; | |
7699 | } | |
7700 | ||
12381341 | 7701 | //! Auxiliary method |
7702 | inline void addLight (const Handle(V3d_Light)& theLightNew, | |
7703 | const Standard_Boolean theIsGlobal) | |
7704 | { | |
7705 | if (theLightNew.IsNull()) | |
7706 | { | |
7707 | return; | |
7708 | } | |
7709 | ||
7710 | if (theIsGlobal) | |
7711 | { | |
7712 | ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew); | |
7713 | } | |
7714 | else | |
7715 | { | |
7716 | ViewerTest::CurrentView()->SetLightOn (theLightNew); | |
7717 | } | |
7718 | } | |
7719 | ||
7720 | //! Auxiliary method | |
7721 | inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext) | |
7722 | { | |
7723 | TCollection_AsciiString anArgNextCase (theArgNext); | |
7724 | anArgNextCase.UpperCase(); | |
7725 | if (anArgNextCase.Length() > 5 | |
7726 | && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT")) | |
7727 | { | |
7728 | return theArgNext.SubString (6, theArgNext.Length()).IntegerValue(); | |
7729 | } | |
7730 | else | |
7731 | { | |
7732 | return theArgNext.IntegerValue(); | |
7733 | } | |
7734 | } | |
7735 | ||
7736 | //=============================================================================================== | |
7737 | //function : VLight | |
7738 | //purpose : | |
7739 | //=============================================================================================== | |
7740 | static int VLight (Draw_Interpretor& theDi, | |
7741 | Standard_Integer theArgsNb, | |
7742 | const char** theArgVec) | |
7743 | { | |
7744 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
7745 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
7746 | if (aView.IsNull() | |
7747 | || aViewer.IsNull()) | |
7748 | { | |
7749 | std::cerr << "No active viewer!\n"; | |
7750 | return 1; | |
7751 | } | |
7752 | ||
7753 | Standard_Real anXYZ[3]; | |
7754 | Quantity_Coefficient anAtten[2]; | |
7755 | if (theArgsNb < 2) | |
7756 | { | |
7757 | // print lights info | |
7758 | Standard_Integer aLightId = 0; | |
7759 | for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId) | |
7760 | { | |
7761 | Handle(V3d_Light) aLight = aView->ActiveLight(); | |
7762 | const Quantity_Color aColor = aLight->Color(); | |
7763 | theDi << "Light" << aLightId << "\n"; | |
7764 | switch (aLight->Type()) | |
7765 | { | |
7766 | case V3d_AMBIENT: | |
7767 | { | |
189f85a3 | 7768 | theDi << " Type: Ambient\n"; |
7769 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
12381341 | 7770 | break; |
7771 | } | |
7772 | case V3d_DIRECTIONAL: | |
7773 | { | |
7774 | Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight); | |
189f85a3 | 7775 | theDi << " Type: Directional\n"; |
7776 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
7777 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
7778 | theDi << " Smoothness: " << aLight->Smoothness() << "\n"; | |
12381341 | 7779 | if (!aLightDir.IsNull()) |
7780 | { | |
7781 | aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]); | |
189f85a3 | 7782 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
12381341 | 7783 | aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); |
189f85a3 | 7784 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
12381341 | 7785 | } |
7786 | break; | |
7787 | } | |
7788 | case V3d_POSITIONAL: | |
7789 | { | |
7790 | Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight); | |
189f85a3 | 7791 | theDi << " Type: Positional\n"; |
7792 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
7793 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
7794 | theDi << " Smoothness: " << aLight->Smoothness() << "\n"; | |
12381341 | 7795 | if (!aLightPos.IsNull()) |
7796 | { | |
7797 | aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]); | |
189f85a3 | 7798 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
12381341 | 7799 | aLightPos->Attenuation (anAtten[0], anAtten[1]); |
189f85a3 | 7800 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; |
12381341 | 7801 | } |
7802 | break; | |
7803 | } | |
7804 | case V3d_SPOT: | |
7805 | { | |
7806 | Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight); | |
189f85a3 | 7807 | theDi << " Type: Spot\n"; |
7808 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
7809 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
12381341 | 7810 | if (!aLightSpot.IsNull()) |
7811 | { | |
7812 | aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]); | |
189f85a3 | 7813 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
12381341 | 7814 | aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); |
189f85a3 | 7815 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
12381341 | 7816 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); |
189f85a3 | 7817 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; |
7818 | theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n"; | |
7819 | theDi << " Exponent: " << aLightSpot->Concentration() << "\n"; | |
12381341 | 7820 | } |
7821 | break; | |
7822 | } | |
7823 | default: | |
7824 | { | |
189f85a3 | 7825 | theDi << " Type: UNKNOWN\n"; |
12381341 | 7826 | break; |
7827 | } | |
7828 | } | |
7829 | theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n"; | |
7830 | } | |
7831 | } | |
7832 | ||
7833 | Handle(V3d_Light) aLightNew; | |
7834 | Handle(V3d_Light) aLightOld; | |
7835 | Standard_Boolean isGlobal = Standard_True; | |
7836 | Standard_Boolean toCreate = Standard_False; | |
7837 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
7838 | { | |
7839 | Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew; | |
7840 | Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr); | |
7841 | Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr); | |
7842 | Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr); | |
7843 | Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr); | |
7844 | ||
7845 | TCollection_AsciiString aName, aValue; | |
7846 | const TCollection_AsciiString anArg (theArgVec[anArgIt]); | |
7847 | TCollection_AsciiString anArgCase (anArg); | |
7848 | anArgCase.UpperCase(); | |
7849 | if (anArgCase.IsEqual ("NEW") | |
7850 | || anArgCase.IsEqual ("ADD") | |
7851 | || anArgCase.IsEqual ("CREATE")) | |
7852 | { | |
7853 | toCreate = Standard_True; | |
7854 | } | |
7855 | else if (anArgCase.IsEqual ("GLOB") | |
7856 | || anArgCase.IsEqual ("GLOBAL")) | |
7857 | { | |
7858 | isGlobal = Standard_True; | |
7859 | } | |
7860 | else if (anArgCase.IsEqual ("LOC") | |
7861 | || anArgCase.IsEqual ("LOCAL")) | |
7862 | { | |
7863 | isGlobal = Standard_False; | |
7864 | } | |
4fe9ad57 | 7865 | else if (anArgCase.IsEqual ("DEF") |
7866 | || anArgCase.IsEqual ("DEFAULTS")) | |
7867 | { | |
7868 | toCreate = Standard_False; | |
7869 | aViewer->SetDefaultLights(); | |
7870 | } | |
7871 | else if (anArgCase.IsEqual ("CLR") | |
7872 | || anArgCase.IsEqual ("CLEAR")) | |
7873 | { | |
7874 | toCreate = Standard_False; | |
7875 | aView->InitActiveLights(); | |
7876 | while (aView->MoreActiveLights()) | |
7877 | { | |
7878 | aViewer->DelLight (aView->ActiveLight()); | |
7879 | aView->InitActiveLights(); | |
7880 | } | |
7881 | } | |
12381341 | 7882 | else if (anArgCase.IsEqual ("AMB") |
7883 | || anArgCase.IsEqual ("AMBIENT") | |
7884 | || anArgCase.IsEqual ("AMBLIGHT")) | |
7885 | { | |
7886 | addLight (aLightNew, isGlobal); | |
7887 | if (!toCreate) | |
7888 | { | |
7889 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7890 | return 1; | |
7891 | } | |
7892 | toCreate = Standard_False; | |
7893 | aLightNew = new V3d_AmbientLight (aViewer); | |
7894 | } | |
7895 | else if (anArgCase.IsEqual ("DIRECTIONAL") | |
7896 | || anArgCase.IsEqual ("DIRLIGHT")) | |
7897 | { | |
7898 | addLight (aLightNew, isGlobal); | |
7899 | if (!toCreate) | |
7900 | { | |
7901 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7902 | return 1; | |
7903 | } | |
7904 | toCreate = Standard_False; | |
7905 | aLightNew = new V3d_DirectionalLight (aViewer); | |
7906 | } | |
7907 | else if (anArgCase.IsEqual ("SPOT") | |
7908 | || anArgCase.IsEqual ("SPOTLIGHT")) | |
7909 | { | |
7910 | addLight (aLightNew, isGlobal); | |
7911 | if (!toCreate) | |
7912 | { | |
7913 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7914 | return 1; | |
7915 | } | |
7916 | toCreate = Standard_False; | |
7917 | aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0); | |
7918 | } | |
7919 | else if (anArgCase.IsEqual ("POSLIGHT") | |
7920 | || anArgCase.IsEqual ("POSITIONAL")) | |
7921 | { | |
7922 | addLight (aLightNew, isGlobal); | |
7923 | if (!toCreate) | |
7924 | { | |
7925 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7926 | return 1; | |
7927 | } | |
7928 | toCreate = Standard_False; | |
7929 | aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0); | |
7930 | } | |
7931 | else if (anArgCase.IsEqual ("CHANGE")) | |
7932 | { | |
7933 | addLight (aLightNew, isGlobal); | |
7934 | aLightNew.Nullify(); | |
7935 | if (++anArgIt >= theArgsNb) | |
7936 | { | |
7937 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7938 | return 1; | |
7939 | } | |
7940 | ||
7941 | const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]); | |
7942 | Standard_Integer aLightIt = 0; | |
7943 | for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt) | |
7944 | { | |
7945 | if (aLightIt == aLightId) | |
7946 | { | |
7947 | aLightOld = aView->ActiveLight(); | |
7948 | break; | |
7949 | } | |
7950 | } | |
7951 | ||
7952 | if (aLightOld.IsNull()) | |
7953 | { | |
7954 | std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n"; | |
7955 | return 1; | |
7956 | } | |
7957 | } | |
7958 | else if (anArgCase.IsEqual ("DEL") | |
7959 | || anArgCase.IsEqual ("DELETE")) | |
7960 | { | |
7961 | Handle(V3d_Light) aLightDel; | |
7962 | if (++anArgIt >= theArgsNb) | |
7963 | { | |
7964 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7965 | return 1; | |
7966 | } | |
7967 | ||
7968 | const TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
7969 | const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]); | |
7970 | Standard_Integer aLightIt = 0; | |
7971 | for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt) | |
7972 | { | |
7973 | aLightDel = aView->ActiveLight(); | |
7974 | if (aLightIt == aLightDelId) | |
7975 | { | |
7976 | break; | |
7977 | } | |
7978 | } | |
7979 | if (!aLightDel.IsNull()) | |
7980 | { | |
7981 | aViewer->DelLight (aLightDel); | |
7982 | } | |
7983 | } | |
7984 | else if (anArgCase.IsEqual ("COLOR") | |
7985 | || anArgCase.IsEqual ("COLOUR")) | |
7986 | { | |
7987 | if (++anArgIt >= theArgsNb) | |
7988 | { | |
7989 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7990 | return 1; | |
7991 | } | |
7992 | ||
7993 | TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
7994 | anArgNext.UpperCase(); | |
7995 | const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString()); | |
7996 | if (!aLightCurr.IsNull()) | |
7997 | { | |
7998 | aLightCurr->SetColor (aColor); | |
7999 | } | |
8000 | } | |
8001 | else if (anArgCase.IsEqual ("POS") | |
8002 | || anArgCase.IsEqual ("POSITION")) | |
8003 | { | |
8004 | if ((anArgIt + 3) >= theArgsNb) | |
8005 | { | |
8006 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8007 | return 1; | |
8008 | } | |
8009 | ||
8010 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
8011 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
8012 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
8013 | if (!aLightDir.IsNull()) | |
8014 | { | |
8015 | aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); | |
8016 | } | |
8017 | else if (!aLightPos.IsNull()) | |
8018 | { | |
8019 | aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); | |
8020 | } | |
8021 | else if (!aLightSpot.IsNull()) | |
8022 | { | |
8023 | aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); | |
8024 | } | |
8025 | else | |
8026 | { | |
8027 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8028 | return 1; | |
8029 | } | |
8030 | } | |
8031 | else if (anArgCase.IsEqual ("DIR") | |
8032 | || anArgCase.IsEqual ("DIRECTION")) | |
8033 | { | |
8034 | if ((anArgIt + 3) >= theArgsNb) | |
8035 | { | |
8036 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8037 | return 1; | |
8038 | } | |
8039 | ||
8040 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
8041 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
8042 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
8043 | if (!aLightDir.IsNull()) | |
8044 | { | |
8045 | aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]); | |
8046 | } | |
8047 | else if (!aLightSpot.IsNull()) | |
8048 | { | |
8049 | aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]); | |
8050 | } | |
8051 | else | |
8052 | { | |
8053 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8054 | return 1; | |
8055 | } | |
8056 | } | |
189f85a3 | 8057 | else if (anArgCase.IsEqual ("SM") |
8058 | || anArgCase.IsEqual ("SMOOTHNESS")) | |
8059 | { | |
8060 | if (++anArgIt >= theArgsNb) | |
8061 | { | |
8062 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8063 | return 1; | |
8064 | } | |
8065 | ||
8066 | Standard_Real aSmoothness = Atof (theArgVec[anArgIt]); | |
8067 | ||
8068 | if (fabs (aSmoothness) < Precision::Confusion()) | |
8069 | { | |
8070 | aLightCurr->SetIntensity (1.f); | |
8071 | } | |
8072 | else if (fabs (aLightCurr->Smoothness()) < Precision::Confusion()) | |
8073 | { | |
8074 | aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f); | |
8075 | } | |
8076 | else | |
8077 | { | |
8078 | Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness()); | |
8079 | aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio)); | |
8080 | } | |
8081 | ||
8082 | if (!aLightPos.IsNull()) | |
8083 | { | |
8084 | aLightPos->SetSmoothRadius (aSmoothness); | |
8085 | } | |
8086 | else if (!aLightDir.IsNull()) | |
8087 | { | |
8088 | aLightDir->SetSmoothAngle (aSmoothness); | |
8089 | } | |
8090 | } | |
8091 | else if (anArgCase.IsEqual ("INT") | |
8092 | || anArgCase.IsEqual ("INTENSITY")) | |
8093 | { | |
8094 | if (++anArgIt >= theArgsNb) | |
8095 | { | |
8096 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8097 | return 1; | |
8098 | } | |
8099 | ||
8100 | Standard_Real aIntensity = Atof (theArgVec[anArgIt]); | |
8101 | ||
8102 | if (!aLightCurr.IsNull()) | |
8103 | { | |
8104 | aLightCurr->SetIntensity (aIntensity); | |
8105 | } | |
8106 | } | |
4fe9ad57 | 8107 | else if (anArgCase.IsEqual ("ANG") |
8108 | || anArgCase.IsEqual ("ANGLE")) | |
8109 | { | |
8110 | if (++anArgIt >= theArgsNb) | |
8111 | { | |
8112 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8113 | return 1; | |
8114 | } | |
8115 | ||
8116 | Standard_Real anAngle = Atof (theArgVec[anArgIt]); | |
8117 | ||
8118 | if (!aLightSpot.IsNull()) | |
8119 | { | |
8120 | aLightSpot->SetAngle (anAngle / 180.0 * M_PI); | |
8121 | } | |
8122 | } | |
12381341 | 8123 | else if (anArgCase.IsEqual ("CONSTATTEN") |
8124 | || anArgCase.IsEqual ("CONSTATTENUATION")) | |
8125 | { | |
8126 | if (++anArgIt >= theArgsNb) | |
8127 | { | |
8128 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8129 | return 1; | |
8130 | } | |
8131 | ||
8132 | if (!aLightPos.IsNull()) | |
8133 | { | |
8134 | aLightPos->Attenuation (anAtten[0], anAtten[1]); | |
8135 | anAtten[0] = Atof (theArgVec[anArgIt]); | |
8136 | aLightPos->SetAttenuation (anAtten[0], anAtten[1]); | |
8137 | } | |
8138 | else if (!aLightSpot.IsNull()) | |
8139 | { | |
8140 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); | |
8141 | anAtten[0] = Atof (theArgVec[anArgIt]); | |
8142 | aLightSpot->SetAttenuation (anAtten[0], anAtten[1]); | |
8143 | } | |
8144 | else | |
8145 | { | |
8146 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8147 | return 1; | |
8148 | } | |
8149 | } | |
8150 | else if (anArgCase.IsEqual ("LINATTEN") | |
8151 | || anArgCase.IsEqual ("LINEARATTEN") | |
8152 | || anArgCase.IsEqual ("LINEARATTENUATION")) | |
8153 | { | |
8154 | if (++anArgIt >= theArgsNb) | |
8155 | { | |
8156 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8157 | return 1; | |
8158 | } | |
8159 | ||
8160 | if (!aLightPos.IsNull()) | |
8161 | { | |
8162 | aLightPos->Attenuation (anAtten[0], anAtten[1]); | |
8163 | anAtten[1] = Atof (theArgVec[anArgIt]); | |
8164 | aLightPos->SetAttenuation (anAtten[0], anAtten[1]); | |
8165 | } | |
8166 | else if (!aLightSpot.IsNull()) | |
8167 | { | |
8168 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); | |
8169 | anAtten[1] = Atof (theArgVec[anArgIt]); | |
8170 | aLightSpot->SetAttenuation (anAtten[0], anAtten[1]); | |
8171 | } | |
8172 | else | |
8173 | { | |
8174 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8175 | return 1; | |
8176 | } | |
8177 | } | |
8178 | else if (anArgCase.IsEqual ("EXP") | |
8179 | || anArgCase.IsEqual ("EXPONENT") | |
8180 | || anArgCase.IsEqual ("SPOTEXP") | |
8181 | || anArgCase.IsEqual ("SPOTEXPONENT")) | |
8182 | { | |
8183 | if (++anArgIt >= theArgsNb) | |
8184 | { | |
8185 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8186 | return 1; | |
8187 | } | |
8188 | ||
8189 | if (!aLightSpot.IsNull()) | |
8190 | { | |
8191 | aLightSpot->SetConcentration (Atof (theArgVec[anArgIt])); | |
8192 | } | |
8193 | else | |
8194 | { | |
8195 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8196 | return 1; | |
8197 | } | |
8198 | } | |
8199 | else if (anArgCase.IsEqual ("HEAD") | |
8200 | || anArgCase.IsEqual ("HEADLIGHT")) | |
8201 | { | |
8202 | if (++anArgIt >= theArgsNb) | |
8203 | { | |
8204 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8205 | return 1; | |
8206 | } | |
8207 | ||
8208 | if (aLightAmb.IsNull() | |
8209 | && !aLightCurr.IsNull()) | |
8210 | { | |
8211 | aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0); | |
8212 | } | |
8213 | else | |
8214 | { | |
8215 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8216 | return 1; | |
8217 | } | |
8218 | } | |
8219 | else | |
8220 | { | |
8221 | std::cerr << "Warning: unknown argument '" << anArg << "'\n"; | |
8222 | } | |
8223 | } | |
8224 | ||
8225 | addLight (aLightNew, isGlobal); | |
8226 | aViewer->UpdateLights(); | |
8227 | ||
8228 | return 0; | |
8229 | } | |
8230 | ||
e276548b | 8231 | //======================================================================= |
bc8c79bb | 8232 | //function : VRenderParams |
8233 | //purpose : Enables/disables rendering features | |
e276548b | 8234 | //======================================================================= |
8235 | ||
bc8c79bb | 8236 | static Standard_Integer VRenderParams (Draw_Interpretor& theDI, |
8237 | Standard_Integer theArgNb, | |
8238 | const char** theArgVec) | |
e276548b | 8239 | { |
7ae4a307 | 8240 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
8241 | if (aView.IsNull()) | |
e276548b | 8242 | { |
bc8c79bb | 8243 | std::cerr << "Error: no active viewer!\n"; |
e276548b | 8244 | return 1; |
8245 | } | |
bc8c79bb | 8246 | |
8247 | Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); | |
6b62b2da | 8248 | TCollection_AsciiString aCmdName (theArgVec[0]); |
8249 | aCmdName.LowerCase(); | |
8250 | if (aCmdName == "vraytrace") | |
8251 | { | |
8252 | if (theArgNb == 1) | |
8253 | { | |
8254 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " "; | |
8255 | return 0; | |
8256 | } | |
8257 | else if (theArgNb == 2) | |
8258 | { | |
8259 | TCollection_AsciiString aValue (theArgVec[1]); | |
8260 | aValue.LowerCase(); | |
8261 | if (aValue == "on" | |
8262 | || aValue == "1") | |
8263 | { | |
8264 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
8265 | aView->Redraw(); | |
8266 | return 0; | |
8267 | } | |
8268 | else if (aValue == "off" | |
8269 | || aValue == "0") | |
8270 | { | |
8271 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
8272 | aView->Redraw(); | |
8273 | return 0; | |
8274 | } | |
8275 | else | |
8276 | { | |
8277 | std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n"; | |
8278 | return 1; | |
8279 | } | |
8280 | } | |
8281 | else | |
8282 | { | |
8283 | std::cout << "Error: wrong number of arguments\n"; | |
8284 | return 1; | |
8285 | } | |
8286 | } | |
bc8c79bb | 8287 | |
8288 | if (theArgNb < 2) | |
e276548b | 8289 | { |
bc8c79bb | 8290 | theDI << "renderMode: "; |
8291 | switch (aParams.Method) | |
8292 | { | |
8293 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
8294 | case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break; | |
8295 | } | |
8296 | theDI << "\n"; | |
3c4b62a4 | 8297 | theDI << "msaa: " << aParams.NbMsaaSamples << "\n"; |
8298 | theDI << "rayDepth: " << aParams.RaytracingDepth << "\n"; | |
189f85a3 | 8299 | theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n"; |
8300 | theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n"; | |
8301 | theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n"; | |
189f85a3 | 8302 | theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n"; |
8303 | theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n"; | |
8c820969 | 8304 | theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n"; |
8625ef7e | 8305 | theDI << "shadingModel: "; |
8306 | switch (aView->ShadingModel()) | |
8307 | { | |
8308 | case V3d_COLOR: theDI << "color"; break; | |
8309 | case V3d_FLAT: theDI << "flat"; break; | |
8310 | case V3d_GOURAUD: theDI << "gouraud"; break; | |
8311 | case V3d_PHONG: theDI << "phong"; break; | |
8312 | } | |
8313 | theDI << "\n"; | |
bc8c79bb | 8314 | return 0; |
e276548b | 8315 | } |
8316 | ||
bc8c79bb | 8317 | Standard_Boolean toPrint = Standard_False; |
8625ef7e | 8318 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
e276548b | 8319 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
8320 | { | |
bc8c79bb | 8321 | Standard_CString anArg (theArgVec[anArgIter]); |
8322 | TCollection_AsciiString aFlag (anArg); | |
8323 | aFlag.LowerCase(); | |
8625ef7e | 8324 | if (anUpdateTool.parseRedrawMode (aFlag)) |
8325 | { | |
8326 | continue; | |
8327 | } | |
8328 | else if (aFlag == "-echo" | |
8329 | || aFlag == "-print") | |
e276548b | 8330 | { |
bc8c79bb | 8331 | toPrint = Standard_True; |
8625ef7e | 8332 | anUpdateTool.Invalidate(); |
e276548b | 8333 | } |
bc8c79bb | 8334 | else if (aFlag == "-mode" |
8335 | || aFlag == "-rendermode" | |
8336 | || aFlag == "-render_mode") | |
e276548b | 8337 | { |
bc8c79bb | 8338 | if (toPrint) |
8339 | { | |
8340 | switch (aParams.Method) | |
8341 | { | |
8342 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
8343 | case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break; | |
8344 | } | |
8345 | continue; | |
8346 | } | |
e276548b | 8347 | else |
bc8c79bb | 8348 | { |
8349 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
8350 | return 1; | |
8351 | } | |
8352 | } | |
8353 | else if (aFlag == "-ray" | |
8354 | || aFlag == "-raytrace") | |
8355 | { | |
8356 | if (toPrint) | |
8357 | { | |
8358 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " "; | |
8359 | continue; | |
8360 | } | |
8361 | ||
8362 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
e276548b | 8363 | } |
bc8c79bb | 8364 | else if (aFlag == "-rast" |
8365 | || aFlag == "-raster" | |
8366 | || aFlag == "-rasterization") | |
e276548b | 8367 | { |
bc8c79bb | 8368 | if (toPrint) |
8369 | { | |
8370 | theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " "; | |
8371 | continue; | |
8372 | } | |
8373 | ||
8374 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
8375 | } | |
3c4b62a4 | 8376 | else if (aFlag == "-msaa") |
8377 | { | |
8378 | if (toPrint) | |
8379 | { | |
8380 | theDI << aParams.NbMsaaSamples << " "; | |
8381 | continue; | |
8382 | } | |
8383 | else if (++anArgIter >= theArgNb) | |
8384 | { | |
8385 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
8386 | return 1; | |
8387 | } | |
8388 | ||
8389 | const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]); | |
8390 | if (aNbSamples < 0) | |
8391 | { | |
8392 | std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n"; | |
8393 | return 1; | |
8394 | } | |
8395 | else | |
8396 | { | |
8397 | aParams.NbMsaaSamples = aNbSamples; | |
8398 | } | |
8399 | } | |
bc8c79bb | 8400 | else if (aFlag == "-raydepth" |
8401 | || aFlag == "-ray_depth") | |
8402 | { | |
8403 | if (toPrint) | |
8404 | { | |
8405 | theDI << aParams.RaytracingDepth << " "; | |
8406 | continue; | |
8407 | } | |
8408 | else if (++anArgIter >= theArgNb) | |
8409 | { | |
8410 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
8411 | return 1; | |
8412 | } | |
8413 | ||
8414 | const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]); | |
189f85a3 | 8415 | |
8416 | // We allow RaytracingDepth be more than 10 in case of GI enabled | |
8417 | if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled)) | |
bc8c79bb | 8418 | { |
8419 | std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n"; | |
8420 | return 1; | |
8421 | } | |
e276548b | 8422 | else |
bc8c79bb | 8423 | { |
8424 | aParams.RaytracingDepth = aDepth; | |
8425 | } | |
8426 | } | |
8427 | else if (aFlag == "-shad" | |
8428 | || aFlag == "-shadows") | |
8429 | { | |
8430 | if (toPrint) | |
8431 | { | |
8432 | theDI << (aParams.IsShadowEnabled ? "on" : "off") << " "; | |
8433 | continue; | |
8434 | } | |
8435 | ||
8436 | Standard_Boolean toEnable = Standard_True; | |
8437 | if (++anArgIter < theArgNb | |
a5565a3c | 8438 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 8439 | { |
8440 | --anArgIter; | |
8441 | } | |
8442 | aParams.IsShadowEnabled = toEnable; | |
8443 | } | |
8444 | else if (aFlag == "-refl" | |
8445 | || aFlag == "-reflections") | |
8446 | { | |
8447 | if (toPrint) | |
8448 | { | |
8449 | theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " "; | |
8450 | continue; | |
8451 | } | |
8452 | ||
8453 | Standard_Boolean toEnable = Standard_True; | |
8454 | if (++anArgIter < theArgNb | |
a5565a3c | 8455 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 8456 | { |
8457 | --anArgIter; | |
8458 | } | |
8459 | aParams.IsReflectionEnabled = toEnable; | |
8460 | } | |
8461 | else if (aFlag == "-fsaa") | |
8462 | { | |
8463 | if (toPrint) | |
8464 | { | |
8465 | theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " "; | |
8466 | continue; | |
8467 | } | |
8468 | ||
8469 | Standard_Boolean toEnable = Standard_True; | |
8470 | if (++anArgIter < theArgNb | |
a5565a3c | 8471 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 8472 | { |
8473 | --anArgIter; | |
8474 | } | |
8475 | aParams.IsAntialiasingEnabled = toEnable; | |
8476 | } | |
8477 | else if (aFlag == "-gleam") | |
8478 | { | |
8479 | if (toPrint) | |
8480 | { | |
8481 | theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " "; | |
8482 | continue; | |
8483 | } | |
8484 | ||
8485 | Standard_Boolean toEnable = Standard_True; | |
8486 | if (++anArgIter < theArgNb | |
a5565a3c | 8487 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 8488 | { |
8489 | --anArgIter; | |
8490 | } | |
8491 | aParams.IsTransparentShadowEnabled = toEnable; | |
e276548b | 8492 | } |
189f85a3 | 8493 | else if (aFlag == "-gi") |
8494 | { | |
8495 | if (toPrint) | |
8496 | { | |
8497 | theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " "; | |
8498 | continue; | |
8499 | } | |
8500 | ||
8501 | Standard_Boolean toEnable = Standard_True; | |
8502 | if (++anArgIter < theArgNb | |
a5565a3c | 8503 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
189f85a3 | 8504 | { |
8505 | --anArgIter; | |
8506 | } | |
8507 | aParams.IsGlobalIlluminationEnabled = toEnable; | |
8508 | if (!toEnable) | |
8509 | { | |
8510 | aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10); | |
8511 | } | |
8512 | } | |
8c820969 | 8513 | else if (aFlag == "-blockedrng" |
8514 | || aFlag == "-brng") | |
8515 | { | |
8516 | if (toPrint) | |
8517 | { | |
8518 | theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " "; | |
8519 | continue; | |
8520 | } | |
8521 | ||
8522 | Standard_Boolean toEnable = Standard_True; | |
8523 | if (++anArgIter < theArgNb | |
a5565a3c | 8524 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8c820969 | 8525 | { |
8526 | --anArgIter; | |
8527 | } | |
8528 | aParams.CoherentPathTracingMode = toEnable; | |
8529 | } | |
189f85a3 | 8530 | else if (aFlag == "-env") |
8531 | { | |
8532 | if (toPrint) | |
8533 | { | |
8534 | theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " "; | |
8535 | continue; | |
8536 | } | |
8537 | ||
8538 | Standard_Boolean toEnable = Standard_True; | |
8539 | if (++anArgIter < theArgNb | |
a5565a3c | 8540 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
189f85a3 | 8541 | { |
8542 | --anArgIter; | |
8543 | } | |
8544 | aParams.UseEnvironmentMapBackground = toEnable; | |
8545 | } | |
8625ef7e | 8546 | else if (aFlag == "-shademodel" |
8547 | || aFlag == "-shadingmodel" | |
8548 | || aFlag == "-shading") | |
8549 | { | |
8550 | if (toPrint) | |
8551 | { | |
8552 | switch (aView->ShadingModel()) | |
8553 | { | |
8554 | case V3d_COLOR: theDI << "color "; break; | |
8555 | case V3d_FLAT: theDI << "flat "; break; | |
8556 | case V3d_GOURAUD: theDI << "gouraud "; break; | |
8557 | case V3d_PHONG: theDI << "phong "; break; | |
8558 | } | |
8559 | continue; | |
8560 | } | |
8561 | ||
8562 | if (++anArgIter >= theArgNb) | |
8563 | { | |
8564 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
8565 | } | |
8566 | ||
8567 | TCollection_AsciiString aMode (theArgVec[anArgIter]); | |
8568 | aMode.LowerCase(); | |
8569 | if (aMode == "color" | |
8570 | || aMode == "none") | |
8571 | { | |
8572 | aView->SetShadingModel (V3d_COLOR); | |
8573 | } | |
8574 | else if (aMode == "flat" | |
8575 | || aMode == "facet") | |
8576 | { | |
8577 | aView->SetShadingModel (V3d_FLAT); | |
8578 | } | |
8579 | else if (aMode == "gouraud" | |
8580 | || aMode == "vertex" | |
8581 | || aMode == "vert") | |
8582 | { | |
8583 | aView->SetShadingModel (V3d_GOURAUD); | |
8584 | } | |
8585 | else if (aMode == "phong" | |
8586 | || aMode == "fragment" | |
8587 | || aMode == "frag" | |
8588 | || aMode == "pixel") | |
8589 | { | |
8590 | aView->SetShadingModel (V3d_PHONG); | |
8591 | } | |
8592 | else | |
8593 | { | |
8594 | std::cout << "Error: unknown shading model '" << aMode << "'\n"; | |
8595 | return 1; | |
8596 | } | |
8597 | } | |
4b1c8733 | 8598 | else if (aFlag == "-resolution") |
8599 | { | |
8600 | if (++anArgIter >= theArgNb) | |
8601 | { | |
8602 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
8603 | return 1; | |
8604 | } | |
8605 | ||
8606 | TCollection_AsciiString aResolution (theArgVec[anArgIter]); | |
8607 | if (aResolution.IsIntegerValue()) | |
8608 | { | |
8609 | aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString())); | |
8610 | } | |
8611 | else | |
8612 | { | |
8613 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
8614 | return 1; | |
8615 | } | |
8616 | } | |
e276548b | 8617 | else |
8618 | { | |
bc8c79bb | 8619 | std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n"; |
8620 | return 1; | |
e276548b | 8621 | } |
8622 | } | |
189f85a3 | 8623 | |
8624 | return 0; | |
8625 | } | |
8626 | ||
8627 | //======================================================================= | |
8628 | //function : VProgressiveMode | |
8629 | //purpose : | |
8630 | //======================================================================= | |
8631 | #if defined(_WIN32) | |
8632 | static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/, | |
8633 | Standard_Integer /*theNbArgs*/, | |
8634 | const char** /*theArgs*/) | |
8635 | { | |
8636 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
8637 | if (aView.IsNull()) | |
8638 | { | |
8639 | std::cerr << "Error: no active viewer!\n"; | |
8640 | return 1; | |
8641 | } | |
8642 | ||
8643 | std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl; | |
8644 | ||
8645 | for (;;) | |
8646 | { | |
8647 | aView->Redraw(); | |
8648 | ||
8649 | Standard_Boolean toExit = Standard_False; | |
8650 | ||
8651 | MSG aMsg; | |
7c65581d | 8652 | while (PeekMessage (&aMsg, NULL, 0, 0, PM_REMOVE)) |
189f85a3 | 8653 | { |
8654 | if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b)) | |
8655 | { | |
8656 | toExit = Standard_True; | |
8657 | } | |
8658 | ||
8659 | TranslateMessage (&aMsg); | |
8660 | DispatchMessage (&aMsg); | |
8661 | } | |
8662 | ||
8663 | if (toExit) | |
8664 | { | |
8665 | break; | |
8666 | } | |
8667 | } | |
8668 | ||
e276548b | 8669 | return 0; |
8670 | } | |
189f85a3 | 8671 | #endif |
e276548b | 8672 | |
b7cd4ba7 | 8673 | //======================================================================= |
8674 | //function : VFrustumCulling | |
8675 | //purpose : enables/disables view volume's culling. | |
8676 | //======================================================================= | |
8677 | static int VFrustumCulling (Draw_Interpretor& theDI, | |
8678 | Standard_Integer theArgNb, | |
8679 | const char** theArgVec) | |
8680 | { | |
8681 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
8682 | if (aView.IsNull()) | |
8683 | { | |
8684 | std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n"; | |
8685 | return 1; | |
8686 | } | |
8687 | ||
8688 | if (theArgNb < 2) | |
8689 | { | |
8690 | theDI << (aView->IsCullingEnabled() ? "on" : "off"); | |
8691 | return 0; | |
8692 | } | |
8693 | else if (theArgNb != 2) | |
8694 | { | |
8695 | std::cout << theArgVec[0] << " Syntax error: Specify the mode\n"; | |
8696 | return 1; | |
8697 | } | |
8698 | ||
8699 | TCollection_AsciiString aModeStr (theArgVec[1]); | |
8700 | aModeStr.LowerCase(); | |
8701 | Standard_Boolean toEnable = 0; | |
8702 | if (aModeStr == "on") | |
8703 | { | |
8704 | toEnable = 1; | |
8705 | } | |
8706 | else if (aModeStr == "off") | |
8707 | { | |
8708 | toEnable = 0; | |
8709 | } | |
8710 | else | |
8711 | { | |
8712 | toEnable = Draw::Atoi (theArgVec[1]) != 0; | |
8713 | } | |
8714 | ||
8715 | aView->SetFrustumCulling (toEnable); | |
8716 | aView->Redraw(); | |
8717 | return 0; | |
8718 | } | |
8719 | ||
c398b00e | 8720 | //======================================================================= |
8721 | //function : VHighlightSelected | |
8722 | //purpose : | |
8723 | //======================================================================= | |
8724 | static int VHighlightSelected (Draw_Interpretor& theDI, | |
8725 | Standard_Integer theArgNb, | |
8726 | const char** theArgVec) | |
8727 | { | |
8728 | if (ViewerTest::GetAISContext().IsNull()) | |
8729 | { | |
8730 | std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n"; | |
8731 | return 1; | |
8732 | } | |
8733 | ||
8734 | const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
8735 | ||
8736 | if (theArgNb < 2) | |
8737 | { | |
8738 | theDI << (aContext->ToHilightSelected() ? "on" : "off"); | |
8739 | return 0; | |
8740 | } | |
8741 | ||
8742 | if (theArgNb != 2) | |
8743 | { | |
8744 | std::cout << theArgVec[0] << " error : wrong number of parameters." | |
8745 | << "Type 'help" << theArgVec[0] << "' for more information."; | |
8746 | return 1; | |
8747 | } | |
8748 | ||
8749 | // Parse parameter | |
8750 | TCollection_AsciiString aMode (theArgVec[1]); | |
8751 | aMode.LowerCase(); | |
8752 | Standard_Boolean toEnable = Standard_False; | |
8753 | if (aMode.IsEqual ("on")) | |
8754 | { | |
8755 | toEnable = Standard_True; | |
8756 | } | |
8757 | else if (aMode.IsEqual ("off")) | |
8758 | { | |
8759 | toEnable = Standard_False; | |
8760 | } | |
8761 | else | |
8762 | { | |
8763 | toEnable = Draw::Atoi (theArgVec[1]) != 0; | |
8764 | } | |
8765 | ||
8766 | if (toEnable != aContext->ToHilightSelected()) | |
8767 | { | |
8768 | aContext->SetToHilightSelected (toEnable); | |
8769 | ||
8770 | // Move cursor to null position and back to process updating of detection | |
8771 | // and highlighting of selected object immediatly. | |
8772 | Standard_Integer aPixX = 0; | |
8773 | Standard_Integer aPixY = 0; | |
8774 | const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager(); | |
8775 | ||
8776 | anEventManager->GetCurrentPosition (aPixX, aPixY); | |
8777 | anEventManager->MoveTo (0, 0); | |
8778 | anEventManager->MoveTo (aPixX, aPixY); | |
8779 | } | |
8780 | ||
8781 | return 0; | |
8782 | } | |
8783 | ||
0717ddc1 | 8784 | //======================================================================= |
8785 | //function : VXRotate | |
8786 | //purpose : | |
8787 | //======================================================================= | |
8788 | static Standard_Integer VXRotate (Draw_Interpretor& di, | |
8789 | Standard_Integer argc, | |
8790 | const char ** argv) | |
8791 | { | |
8792 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
8793 | if (aContext.IsNull()) | |
8794 | { | |
586db386 | 8795 | di << argv[0] << "ERROR : use 'vinit' command before \n"; |
0717ddc1 | 8796 | return 1; |
8797 | } | |
8798 | ||
8799 | if (argc != 3) | |
8800 | { | |
586db386 | 8801 | di << "ERROR : Usage : " << argv[0] << " name angle\n"; |
0717ddc1 | 8802 | return 1; |
8803 | } | |
8804 | ||
8805 | TCollection_AsciiString aName (argv[1]); | |
8806 | Standard_Real anAngle = Draw::Atof (argv[2]); | |
8807 | ||
8808 | // find object | |
8809 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
8810 | Handle(AIS_InteractiveObject) anIObj; | |
8811 | if (!aMap.IsBound2 (aName) ) | |
8812 | { | |
586db386 | 8813 | di << "Use 'vdisplay' before\n"; |
0717ddc1 | 8814 | return 1; |
8815 | } | |
8816 | else | |
8817 | { | |
8818 | anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName)); | |
8819 | ||
8820 | gp_Trsf aTransform; | |
8821 | aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle); | |
8822 | aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart()); | |
8823 | ||
8824 | aContext->SetLocation (anIObj, aTransform); | |
8825 | aContext->UpdateCurrentViewer(); | |
8826 | } | |
8827 | ||
8828 | return 0; | |
8829 | } | |
8830 | ||
7fd59977 | 8831 | //======================================================================= |
8832 | //function : ViewerCommands | |
8833 | //purpose : | |
8834 | //======================================================================= | |
8835 | ||
8836 | void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) | |
8837 | { | |
8838 | ||
8839 | const char *group = "ZeViewer"; | |
18d715bd | 8840 | theCommands.Add("vinit", |
8841 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
8842 | "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" | |
8843 | #else | |
8844 | "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" | |
8845 | #endif | |
8846 | " - Creates new View window with specified name view_name.\n" | |
8847 | "By default the new view is created in the viewer and in" | |
8848 | " graphic driver shared with active view.\n" | |
8849 | " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n" | |
8850 | "If driverName isn't specified the driver will be shared with active view.\n" | |
8851 | "If viewerName isn't specified the viewer will be shared with active view.\n" | |
8852 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
8853 | " - display = HostName.DisplayNumber[:ScreenNumber] : if specified" | |
8854 | "is used in creation of graphic driver\n" | |
8855 | #endif | |
8856 | " - l, t: pixel position of left top corner of the window\n" | |
8857 | " - w,h: width and heigth of window respectively.\n" | |
8858 | "Additional commands for operations with views: vclose, vactivate, vviewlist.\n", | |
7fd59977 | 8859 | __FILE__,VInit,group); |
18d715bd | 8860 | theCommands.Add("vclose" , |
d0cc1cb7 | 8861 | "[view_id [keep_context=0|1]]\n" |
18d715bd | 8862 | "or vclose ALL - to remove all created views\n" |
8863 | " - removes view(viewer window) defined by its view_id.\n" | |
8864 | " - keep_context: by default 0; if 1 and the last view is deleted" | |
8865 | " the current context is not removed.", | |
8866 | __FILE__,VClose,group); | |
8867 | theCommands.Add("vactivate" , | |
8868 | "view_id" | |
8869 | " - activates view(viewer window) defined by its view_id", | |
8870 | __FILE__,VActivate,group); | |
8871 | theCommands.Add("vviewlist", | |
8872 | "vviewlist [format={tree, long}]" | |
8873 | " - prints current list of views per viewer and graphic_driver ID shared between viewers" | |
8874 | " - format: format of result output, if tree the output is a tree view;" | |
8875 | "otherwise it's a list of full view names. By default format = tree", | |
8876 | __FILE__,VViewList,group); | |
7fd59977 | 8877 | theCommands.Add("vhelp" , |
8878 | "vhelp : display help on the viewer commands", | |
8879 | __FILE__,VHelp,group); | |
8880 | theCommands.Add("vtop" , | |
27af3052 | 8881 | "vtop or <T> : Top view. Orientation +X+Y" , |
7fd59977 | 8882 | __FILE__,VTop,group); |
44b8f2d6 | 8883 | theCommands.Add("vbottom" , |
27af3052 | 8884 | "vbottom : Bottom view. Orientation +X-Y" , |
44b8f2d6 | 8885 | __FILE__,VBottom,group); |
8886 | theCommands.Add("vleft" , | |
27af3052 | 8887 | "vleft : Left view. Orientation -Y+Z" , |
44b8f2d6 | 8888 | __FILE__,VLeft,group); |
8889 | theCommands.Add("vright" , | |
27af3052 | 8890 | "vright : Right view. Orientation +Y+Z" , |
44b8f2d6 | 8891 | __FILE__,VRight,group); |
7fd59977 | 8892 | theCommands.Add("vaxo" , |
27af3052 | 8893 | " vaxo or <A> : Axonometric view. Orientation +X-Y+Z", |
7fd59977 | 8894 | __FILE__,VAxo,group); |
44b8f2d6 | 8895 | theCommands.Add("vfront" , |
27af3052 | 8896 | "vfront : Front view. Orientation +X+Z" , |
44b8f2d6 | 8897 | __FILE__,VFront,group); |
8898 | theCommands.Add("vback" , | |
27af3052 | 8899 | "vback : Back view. Orientation -X+Z" , |
44b8f2d6 | 8900 | __FILE__,VBack,group); |
7fd59977 | 8901 | theCommands.Add("vpick" , |
8902 | "vpick : vpick X Y Z [shape subshape] ( all variables as string )", | |
8903 | VPick,group); | |
8904 | theCommands.Add("vfit" , | |
b586500b | 8905 | "vfit or <F> [-selected]" |
8906 | "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects", | |
7fd59977 | 8907 | __FILE__,VFit,group); |
6262a303 | 8908 | theCommands.Add ("vfitarea", |
8909 | "vfitarea x1 y1 x2 y2" | |
8910 | "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2" | |
8911 | "\n\t\t: Fit view to show area located between two points" | |
8912 | "\n\t\t: given in world 2D or 3D corrdinates.", | |
8913 | __FILE__, VFitArea, group); | |
197ac94e | 8914 | theCommands.Add ("vzfit", "vzfit [scale]\n" |
8915 | " Matches Z near, Z far view volume planes to the displayed objects.\n" | |
8916 | " \"scale\" - specifies factor to scale computed z range.\n", | |
8917 | __FILE__, VZFit, group); | |
7fd59977 | 8918 | theCommands.Add("vrepaint", |
8919 | "vrepaint : vrepaint, force redraw", | |
8920 | __FILE__,VRepaint,group); | |
8921 | theCommands.Add("vclear", | |
faea8b40 | 8922 | "vclear : vclear" |
8923 | "\n\t\t: remove all the object from the viewer", | |
7fd59977 | 8924 | __FILE__,VClear,group); |
8925 | theCommands.Add("vsetbg", | |
8926 | "vsetbg : vsetbg imagefile [filltype] : Load image as background", | |
8927 | __FILE__,VSetBg,group); | |
f8b2ed36 | 8928 | theCommands.Add("vsetbgmode", |
8929 | "vsetbgmode : vsetbgmode filltype : Change background image fill type", | |
8930 | __FILE__,VSetBgMode,group); | |
7fd59977 | 8931 | theCommands.Add("vsetgradientbg", |
f8b2ed36 | 8932 | "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background", |
7fd59977 | 8933 | __FILE__,VSetGradientBg,group); |
f8b2ed36 | 8934 | theCommands.Add("vsetgrbgmode", |
8935 | "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type", | |
8936 | __FILE__,VSetGradientBgMode,group); | |
8937 | theCommands.Add("vsetcolorbg", | |
8938 | "vsetcolorbg : vsetcolorbg r g b : Set background color", | |
8939 | __FILE__,VSetColorBg,group); | |
f42753ed | 8940 | theCommands.Add("vsetdefaultbg", |
8941 | "vsetdefaultbg r g b\n" | |
8942 | "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode" | |
8943 | "\n\t\t: Set default viewer background fill color (flat/gradient).", | |
8944 | __FILE__,VSetDefaultBg,group); | |
7fd59977 | 8945 | theCommands.Add("vscale", |
8946 | "vscale : vscale X Y Z", | |
8947 | __FILE__,VScale,group); | |
8948 | theCommands.Add("vzbufftrihedron", | |
536d98e2 | 8949 | "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]" |
8950 | "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]" | |
8951 | "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]" | |
8952 | "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]" | |
8953 | "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]" | |
8954 | "\n\t\t: Displays a trihedron", | |
8955 | __FILE__,VZBuffTrihedron,group); | |
7fd59977 | 8956 | theCommands.Add("vrotate", |
4af098ba | 8957 | "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]" |
8958 | "\n : Option -mouseStart starts rotation according to the mouse position" | |
8959 | "\n : Option -mouseMove continues rotation with angle computed" | |
8960 | "\n : from last and new mouse position." | |
8961 | "\n : vrotate AX AY AZ [X Y Z]", | |
7fd59977 | 8962 | __FILE__,VRotate,group); |
8963 | theCommands.Add("vzoom", | |
8964 | "vzoom : vzoom coef", | |
8965 | __FILE__,VZoom,group); | |
8966 | theCommands.Add("vpan", | |
8967 | "vpan : vpan dx dy", | |
8968 | __FILE__,VPan,group); | |
8969 | theCommands.Add("vexport", | |
5cedc27f K |
8970 | "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }" |
8971 | " : exports the view to a vector file of a given format" | |
8972 | " : notice that EMF format requires patched gl2ps", | |
7fd59977 | 8973 | __FILE__,VExport,group); |
8974 | theCommands.Add("vcolorscale", | |
7a324550 | 8975 | "vcolorscale : vcolorscale name [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos " |
71215351 | 8976 | "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n" |
8977 | "-demo/-demoversion draw a demoversion of color scale.\n" | |
8978 | "-show/display display color scale.\n" | |
8979 | "-hide/erase erase color scale.\n" | |
8980 | "Please note that -show/-hide option must be the first argument!\n" | |
8981 | "-color Index R G B: set color for indexed interval\n" | |
8982 | "-color Index ColorName: set color for indexed interval\n" | |
8983 | "-colors R G B R G B ...: set colors for all intervals\n" | |
8984 | "-colors ColorName1 ColorName2 ...: set colors for all intervals\n" | |
8985 | "-colors supports both color names and rgb values in one call\n" | |
8986 | "-label Index Text: set label for indexed interval\n" | |
8987 | "-labels Text Text Text ...: set labels for all intervals\n" | |
8988 | "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n" | |
8989 | "Available text positions: left, right, center, none;\n", | |
7fd59977 | 8990 | __FILE__,VColorScale,group); |
8991 | theCommands.Add("vgraduatedtrihedron", | |
a79f67f8 | 8992 | "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n" |
8993 | "\t[-namefont Name] [-valuesfont Name]\n" | |
8994 | "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n" | |
8995 | "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]" | |
8996 | "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n" | |
8997 | "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n" | |
8998 | "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]" | |
8999 | "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n" | |
9000 | "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n" | |
9001 | "\t[-xticks Number] [-yticks Number] [-zticks Number]\n" | |
9002 | "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n" | |
536d98e2 | 9003 | "\t[-drawgrid on/off] [-drawaxes on/off]\n" |
a79f67f8 | 9004 | " - Displays or erases graduated trihedron" |
9005 | " - xname, yname, zname - names of axes, default: X, Y, Z\n" | |
9006 | " - namefont - font of axes names. Default: Arial\n" | |
9007 | " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n" | |
9008 | " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n" | |
9009 | " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n" | |
9010 | " - valuesfont - font of axes values. Default: Arial\n" | |
9011 | " - xcolor, ycolor, zcolor - color of axis and values\n" | |
9012 | " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n" | |
9013 | " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n", | |
7fd59977 | 9014 | __FILE__,VGraduatedTrihedron,group); |
7edf74fd | 9015 | theCommands.Add("vprintview" , |
b5ac8292 | 9016 | "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile", |
7edf74fd | 9017 | __FILE__,VPrintView,group); |
59f45b7c | 9018 | theCommands.Add("vzlayer", |
c5751993 | 9019 | "vzlayer add/del/get/settings/enable/disable [id]\n" |
9020 | " add - add new z layer to viewer and print its id\n" | |
9021 | " del - del z layer by its id\n" | |
9022 | " get - print sequence of z layers in increasing order of their overlay level\n" | |
9023 | " settings - print status of z layer settings\n" | |
9024 | " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n" | |
9025 | " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n" | |
9026 | " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n" | |
9027 | "\nWhere id is the layer identificator\n" | |
9028 | "\nExamples:\n" | |
9029 | " vzlayer add\n" | |
9030 | " vzlayer enable poffset 1\n" | |
9031 | " vzlayer disable depthtest 1\n" | |
9032 | " vzlayer del 1\n", | |
59f45b7c | 9033 | __FILE__,VZLayer,group); |
20637bd2 | 9034 | theCommands.Add("vlayerline", |
9035 | "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]", | |
9036 | __FILE__,VLayerLine,group); | |
2bd4c032 | 9037 | theCommands.Add ("vgrid", |
9038 | "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]" | |
9039 | " : Mode - rectangular or circular" | |
9040 | " : Type - lines or points", | |
9041 | __FILE__, VGrid, group); | |
c40b7d58 | 9042 | theCommands.Add ("vpriviledgedplane", |
9043 | "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]" | |
9044 | "\n\t\t: Ox, Oy, Oz - plane origin" | |
9045 | "\n\t\t: Nx, Ny, Nz - plane normal direction" | |
9046 | "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction" | |
9047 | "\n\t\t: Sets or prints viewer's priviledged plane geometry.", | |
9048 | __FILE__, VPriviledgedPlane, group); | |
f25b82d6 | 9049 | theCommands.Add ("vconvert", |
9050 | "vconvert v [Mode={window|view}]" | |
9051 | "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]" | |
9052 | "\n\t\t: vconvert x y z [Mode={window|grid}]" | |
9053 | "\n\t\t: window - convert to window coordinates, pixels" | |
9054 | "\n\t\t: view - convert to view projection plane" | |
9055 | "\n\t\t: grid - convert to model coordinates, given on grid" | |
9056 | "\n\t\t: ray - convert projection ray to model coordiantes" | |
9057 | "\n\t\t: - vconvert v window : convert view to window;" | |
9058 | "\n\t\t: - vconvert v view : convert window to view;" | |
9059 | "\n\t\t: - vconvert x y window : convert view to window;" | |
9060 | "\n\t\t: - vconvert x y view : convert window to view;" | |
9061 | "\n\t\t: - vconvert x y : convert window to model;" | |
9062 | "\n\t\t: - vconvert x y grid : convert window to model using grid;" | |
9063 | "\n\t\t: - vconvert x y ray : convert window projection line to model;" | |
9064 | "\n\t\t: - vconvert x y z window : convert model to window;" | |
9065 | "\n\t\t: - vconvert x y z grid : convert view to model using grid;" | |
9066 | "\n\t\t: Converts the given coordinates to window/view/model space.", | |
9067 | __FILE__, VConvert, group); | |
208e6839 | 9068 | theCommands.Add ("vfps", |
9069 | "vfps [framesNb=100] : estimate average frame rate for active view", | |
9070 | __FILE__, VFps, group); | |
58655684 | 9071 | theCommands.Add ("vgldebug", |
c87535af | 9072 | "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]" |
9073 | "\n\t\t: [-extraMsg {0|1}] [{0|1}]" | |
9074 | "\n\t\t: Request debug GL context. Should be called BEFORE vinit." | |
9075 | "\n\t\t: Debug context can be requested only on Windows" | |
9076 | "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!" | |
9077 | "\n\t\t: -sync - request synchronized debug GL context" | |
9078 | "\n\t\t: -glslWarn - log GLSL compiler/linker warnings," | |
9079 | "\n\t\t: which are suppressed by default," | |
9080 | "\n\t\t: -extraMsg - log extra diagnostic messages from GL context," | |
9081 | "\n\t\t: which are suppressed by default", | |
58655684 | 9082 | __FILE__, VGlDebug, group); |
208e6839 | 9083 | theCommands.Add ("vvbo", |
58655684 | 9084 | "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects", |
208e6839 | 9085 | __FILE__, VVbo, group); |
b5ac8292 | 9086 | theCommands.Add ("vstereo", |
f978241f | 9087 | "vstereo [0|1] [-mode Mode] [-reverse {0|1}]" |
9088 | "\n\t\t: [-anaglyph Filter]" | |
9089 | "\n\t\t: Control stereo output mode. Available modes for -mode:" | |
9090 | "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo," | |
9091 | "\n\t\t: requires driver support." | |
9092 | "\n\t\t: Should be called BEFORE vinit!" | |
9093 | "\n\t\t: anaglyph - Anaglyph glasses" | |
9094 | "\n\t\t: rowInterlaced - row-interlaced display" | |
9095 | "\n\t\t: columnInterlaced - column-interlaced display" | |
9096 | "\n\t\t: chessBoard - chess-board output" | |
9097 | "\n\t\t: sideBySide - horizontal pair" | |
9098 | "\n\t\t: overUnder - vertical pair" | |
9099 | "\n\t\t: Available Anaglyph filters for -anaglyph:" | |
9100 | "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple," | |
9101 | "\n\t\t: greenMagentaSimple", | |
b5ac8292 | 9102 | __FILE__, VStereo, group); |
a577aaab | 9103 | theCommands.Add ("vcaps", |
8625ef7e | 9104 | "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]" |
1dfe71a6 | 9105 | "\n\t\t: [-compatibleProfile {0|1}]" |
f978241f | 9106 | "\n\t\t: [-vsync {0|1}]" |
9107 | "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]" | |
8625ef7e | 9108 | "\n\t\t: [-softMode {0|1}] [-noupdate|-update]" |
9109 | "\n\t\t: Modify particular graphic driver options:" | |
9110 | "\n\t\t: FFP - use fixed-function pipeline instead of" | |
9111 | "\n\t\t: built-in GLSL programs" | |
4e1523ef | 9112 | "\n\t\t: (requires compatible profile)" |
8625ef7e | 9113 | "\n\t\t: VBO - use Vertex Buffer Object (copy vertex" |
9114 | "\n\t\t: arrays to GPU memory)" | |
9115 | "\n\t\t: sprite - use textured sprites instead of bitmaps" | |
f978241f | 9116 | "\n\t\t: vsync - switch VSync on or off" |
4e1523ef | 9117 | "\n\t\t: Context creation options:" |
9118 | "\n\t\t: softMode - software OpenGL implementation" | |
9119 | "\n\t\t: compatibleProfile - backward-compatible profile" | |
f978241f | 9120 | "\n\t\t: quadbuffer - QuadBuffer" |
8625ef7e | 9121 | "\n\t\t: Unlike vrenderparams, these parameters control alternative" |
9122 | "\n\t\t: rendering paths producing the same visual result when" | |
9123 | "\n\t\t: possible." | |
9124 | "\n\t\t: Command is intended for testing old hardware compatibility.", | |
a577aaab | 9125 | __FILE__, VCaps, group); |
f0430952 | 9126 | theCommands.Add ("vmemgpu", |
9127 | "vmemgpu [f]: print system-dependent GPU memory information if available;" | |
9128 | " with f option returns free memory in bytes", | |
9129 | __FILE__, VMemGpu, group); | |
85e096c3 | 9130 | theCommands.Add ("vreadpixel", |
9131 | "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]" | |
9132 | " : Read pixel value for active view", | |
9133 | __FILE__, VReadPixel, group); | |
692613e5 | 9134 | theCommands.Add("diffimage", |
9135 | "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]", | |
9136 | __FILE__, VDiffImage, group); | |
4754e164 | 9137 | theCommands.Add ("vselect", |
2157d6ac | 9138 | "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n" |
4754e164 | 9139 | "- emulates different types of selection:\n" |
9140 | "- 1) single click selection\n" | |
9141 | "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n" | |
9142 | "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n" | |
faea8b40 | 9143 | "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n" |
9144 | " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n" | |
9145 | " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. " | |
2157d6ac | 9146 | " (partial inclusion - overlap - is not allowed by default)\n" |
9147 | "- 5) any of these selections with shift button pressed", | |
4754e164 | 9148 | __FILE__, VSelect, group); |
9149 | theCommands.Add ("vmoveto", | |
9150 | "vmoveto x y" | |
9151 | "- emulates cursor movement to pixel postion (x,y)", | |
9152 | __FILE__, VMoveTo, group); | |
197ac94e | 9153 | theCommands.Add ("vviewparams", "vviewparams usage:\n" |
9154 | "- vviewparams\n" | |
9155 | "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n" | |
3dfe95cd | 9156 | " [-proj [x y z]] [-center x y] [-size sx]\n" |
197ac94e | 9157 | "- Gets or sets current view parameters.\n" |
9158 | "- If called without arguments, all view parameters are printed.\n" | |
9159 | "- The options are:\n" | |
3dfe95cd | 9160 | " -scale [s] : prints or sets viewport relative scale.\n" |
197ac94e | 9161 | " -eye [x y z] : prints or sets eye location.\n" |
9162 | " -at [x y z] : prints or sets center of look.\n" | |
9163 | " -up [x y z] : prints or sets direction of up vector.\n" | |
9164 | " -proj [x y z] : prints or sets direction of look.\n" | |
3dfe95cd | 9165 | " -center x y : sets location of center of the screen in pixels.\n" |
9166 | " -size [sx] : prints viewport projection width and height sizes\n" | |
9167 | " : or changes the size of its maximum dimension.\n", | |
197ac94e | 9168 | __FILE__, VViewParams, group); |
4754e164 | 9169 | theCommands.Add("vchangeselected", |
dc3fe572 | 9170 | "vchangeselected shape" |
4754e164 | 9171 | "- adds to shape to selection or remove one from it", |
9172 | __FILE__, VChangeSelected, group); | |
9173 | theCommands.Add("vzclipping", | |
9174 | "vzclipping [mode] [depth width]\n" | |
9175 | "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n" | |
9176 | "- gets or sets ZClipping mode, width and depth", | |
9177 | __FILE__,VZClipping,group); | |
9178 | theCommands.Add ("vnbselected", | |
faea8b40 | 9179 | "vnbselected" |
9180 | "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group); | |
6b62b2da | 9181 | theCommands.Add ("vcamera", |
9182 | "vcamera [-ortho] [-projtype]" | |
9183 | "\n\t\t: [-persp]" | |
9184 | "\n\t\t: [-fovy [Angle]] [-distance [Distance]]" | |
9185 | "\n\t\t: [-stereo] [-leftEye] [-rightEye]" | |
9186 | "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]" | |
9187 | "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]" | |
9188 | "\n\t\t: Manage camera parameters." | |
9189 | "\n\t\t: Prints current value when option called without argument." | |
9190 | "\n\t\t: Orthographic camera:" | |
9191 | "\n\t\t: -ortho activate orthographic projection" | |
9192 | "\n\t\t: Perspective camera:" | |
9193 | "\n\t\t: -persp activate perspective projection (mono)" | |
9194 | "\n\t\t: -fovy field of view in y axis, in degrees" | |
9195 | "\n\t\t: -distance distance of eye from camera center" | |
9196 | "\n\t\t: Stereoscopic camera:" | |
9197 | "\n\t\t: -stereo perspective projection (stereo)" | |
9198 | "\n\t\t: -leftEye perspective projection (left eye)" | |
9199 | "\n\t\t: -rightEye perspective projection (right eye)" | |
9200 | "\n\t\t: -iod intraocular distance value" | |
9201 | "\n\t\t: -iodType distance type, absolute or relative" | |
9202 | "\n\t\t: -zfocus stereographic focus value" | |
9203 | "\n\t\t: -zfocusType focus type, absolute or relative", | |
9204 | __FILE__, VCamera, group); | |
b5ac8292 | 9205 | theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n" |
197ac94e | 9206 | "- vautozfit [on={1|0}] [scale]\n" |
9207 | " Prints or changes parameters of automatic z-fit mode:\n" | |
9208 | " \"on\" - turns automatic z-fit on or off\n" | |
9209 | " \"scale\" - specifies factor to scale computed z range.\n", | |
9210 | __FILE__, VAutoZFit, group); | |
b5ac8292 | 9211 | theCommands.Add ("vzrange", "command to manually access znear and zfar values\n" |
9212 | " vzrange - without parameters shows current values\n" | |
9213 | " vzrange [znear] [zfar] - applies provided values to view", | |
9214 | __FILE__,VZRange, group); | |
4754e164 | 9215 | theCommands.Add("vantialiasing", |
faea8b40 | 9216 | "vantialiasing 1|0" |
9217 | "\n\t\t: Switches altialiasing on or off", | |
4754e164 | 9218 | __FILE__,VAntialiasing,group); |
9219 | theCommands.Add ("vpurgedisplay", | |
eb4320f2 | 9220 | "vpurgedisplay" |
4754e164 | 9221 | "- removes structures which don't belong to objects displayed in neutral point", |
9222 | __FILE__, VPurgeDisplay, group); | |
9223 | theCommands.Add("vsetviewsize", | |
9224 | "vsetviewsize size", | |
9225 | __FILE__,VSetViewSize,group); | |
9226 | theCommands.Add("vmoveview", | |
9227 | "vmoveview Dx Dy Dz [Start = 1|0]", | |
9228 | __FILE__,VMoveView,group); | |
9229 | theCommands.Add("vtranslateview", | |
9230 | "vtranslateview Dx Dy Dz [Start = 1|0)]", | |
9231 | __FILE__,VTranslateView,group); | |
9232 | theCommands.Add("vturnview", | |
9233 | "vturnview Ax Ay Az [Start = 1|0]", | |
9234 | __FILE__,VTurnView,group); | |
269294d6 | 9235 | theCommands.Add("vtextureenv", |
9236 | "Enables or disables environment mapping in the 3D view, loading the texture from the given standard " | |
9237 | "or user-defined file and optionally applying texture mapping parameters\n" | |
9238 | " Usage:\n" | |
9239 | " vtextureenv off - disables environment mapping\n" | |
9240 | " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n" | |
9241 | " std_texture = (0..7)\n" | |
9242 | " rep = {clamp|repeat}\n" | |
9243 | " mod = {decal|modulate}\n" | |
9244 | " flt = {nearest|bilinear|trilinear}\n" | |
9245 | " ss, st - scale factors for s and t texture coordinates\n" | |
9246 | " ts, tt - translation for s and t texture coordinates\n" | |
9247 | " rot - texture rotation angle in degrees", | |
9248 | __FILE__, VTextureEnv, group); | |
0a768f56 | 9249 | theCommands.Add("vhlr" , |
e9224045 | 9250 | "is_enabled={on|off} [show_hidden={1|0}]" |
0a768f56 | 9251 | " - Hidden line removal algorithm:" |
e9224045 | 9252 | " - is_enabled: if is on HLR algorithm is applied\n" |
9253 | " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n", | |
0a768f56 | 9254 | __FILE__,VHLR,group); |
9255 | theCommands.Add("vhlrtype" , | |
9256 | "algo_type={algo|polyalgo} [shape_1 ... shape_n]" | |
9257 | " - Changes the type of HLR algorithm using for shapes." | |
9258 | " - algo_type: if equals to algo, exact HLR algorithm is applied;\n" | |
9259 | " if equals to polyalgo, polygonal HLR algorithm is applied." | |
9260 | "If shapes are not given HLR algoithm of given type is applied" | |
9261 | " to all shapes in the view\n", | |
9262 | __FILE__,VHLRType,group); | |
4269bd1b | 9263 | theCommands.Add("vclipplane", "vclipplane usage: \n" |
9264 | " maxplanes <view_name> - get plane limit for view.\n" | |
9265 | " create <plane_name> - create new plane.\n" | |
9266 | " delete <plane_name> - delete plane.\n" | |
9267 | " clone <source_plane> <plane_name> - clone the plane definition.\n" | |
9268 | " set/unset <plane_name> object <object list> - set/unset plane for IO.\n" | |
9269 | " set/unset <plane_name> view <view list> - set/unset plane for view.\n" | |
9270 | " change <plane_name> on/off - turn clipping on/off.\n" | |
9271 | " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n" | |
9272 | " change <plane_name> capping on/off - turn capping on/off.\n" | |
9273 | " change <plane_name> capping color <r> <g> <b> - set color.\n" | |
9274 | " change <plane name> capping texname <texture> - set texture.\n" | |
9275 | " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n" | |
9276 | " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n" | |
9277 | " change <plane_name> capping texrotate <angle> - set tex rotation.\n" | |
9278 | " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n" | |
9279 | " please use VSetTextureMode command to enable texture rendering in view.\n" | |
9280 | , __FILE__, VClipPlane, group); | |
9281 | theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n" | |
9282 | " mode can be:\n" | |
9283 | " 0 - no textures enabled in view.\n" | |
9284 | " 1 - only environment textures enabled.\n" | |
9285 | " 2 - all textures enabled.\n" | |
9286 | " this command sets texture details mode for the specified view.\n" | |
9287 | , __FILE__, VSetTextureMode, group); | |
392ac980 | 9288 | theCommands.Add("vdefaults", |
4c513386 | 9289 | "vdefaults [-absDefl value]" |
9290 | "\n\t\t: [-devCoeff value]" | |
9291 | "\n\t\t: [-angDefl value]" | |
9292 | "\n\t\t: [-autoTriang {off/on | 0/1}]" | |
9293 | , __FILE__, VDefaults, group); | |
12381341 | 9294 | theCommands.Add("vlight", |
816d03ee | 9295 | "tool to manage light sources, without arguments shows list of lights." |
9296 | "\n Main commands: " | |
9297 | "\n 'clear' to clear lights" | |
9298 | "\n '{def}aults' to load deafault lights" | |
9299 | "\n 'add' (or 'new') <type> to add any light source" | |
9300 | "\n where <type> is one of {amb}ient|directional|{spot}light|positional" | |
9301 | "\n 'change' <lightId> to edit light source with specified lightId" | |
9302 | "\n\n In addition to 'add' and 'change' commands you can use light parameters:" | |
9303 | "\n {pos}ition X Y Z" | |
9304 | "\n {dir}ection X Y Z (for directional light or for spotlight)" | |
9305 | "\n color colorName" | |
9306 | "\n {head}light 0|1" | |
189f85a3 | 9307 | "\n {sm}oothness value" |
9308 | "\n {int}ensity value" | |
816d03ee | 9309 | "\n {constAtten}uation value" |
9310 | "\n {linearAtten}uation value" | |
9311 | "\n angle angleDeg" | |
9312 | "\n {spotexp}onent value" | |
9313 | "\n local|global" | |
9314 | "\n\n example: vlight add positional head 1 pos 0 1 1 color red" | |
9315 | "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2", | |
12381341 | 9316 | __FILE__, VLight, group); |
6b62b2da | 9317 | theCommands.Add("vraytrace", |
9318 | "vraytrace [0|1]" | |
189f85a3 | 9319 | "\n\t\t: Turns on/off ray-tracing renderer." |
6b62b2da | 9320 | "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'." |
9321 | "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.", | |
9322 | __FILE__, VRenderParams, group); | |
bc8c79bb | 9323 | theCommands.Add("vrenderparams", |
9324 | "\n Manages rendering parameters: " | |
8625ef7e | 9325 | "\n '-raster' Disables GPU ray-tracing" |
3c4b62a4 | 9326 | "\n '-msaa 0..4' Specifies number of samples for MSAA" |
9327 | "\n '-rayTrace' Enables GPU ray-tracing" | |
8625ef7e | 9328 | "\n '-rayDepth 0..10' Defines maximum ray-tracing depth" |
9329 | "\n '-shadows on|off' Enables/disables shadows rendering" | |
9330 | "\n '-reflections on|off' Enables/disables specular reflections" | |
9331 | "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing" | |
9332 | "\n '-gleam on|off' Enables/disables transparency shadow effects" | |
189f85a3 | 9333 | "\n '-gi on|off' Enables/disables global illumination effects" |
8c820969 | 9334 | "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)" |
189f85a3 | 9335 | "\n '-env on|off' Enables/disables environment map background" |
8625ef7e | 9336 | "\n '-shadingModel model' Controls shading model from enumeration" |
9337 | "\n color, flat, gouraud, phong" | |
4b1c8733 | 9338 | "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size" |
8625ef7e | 9339 | "\n Unlike vcaps, these parameters dramatically change visual properties." |
9340 | "\n Command is intended to control presentation quality depending on" | |
9341 | "\n hardware capabilities and performance.", | |
bc8c79bb | 9342 | __FILE__, VRenderParams, group); |
b7cd4ba7 | 9343 | theCommands.Add("vfrustumculling", |
9344 | "vfrustumculling [toEnable]: enables/disables objects clipping", | |
9345 | __FILE__,VFrustumCulling,group); | |
c398b00e | 9346 | theCommands.Add("vhighlightselected", |
9347 | "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n" | |
9348 | "Without arguments it shows if highlighting of selected objects is enabled now.", | |
9349 | __FILE__,VHighlightSelected,group); | |
49e1a5c7 | 9350 | theCommands.Add ("vplace", |
9351 | "vplace dx dy" | |
9352 | "\n\t\t: Places the point (in pixels) at the center of the window", | |
9353 | __FILE__, VPlace, group); | |
0717ddc1 | 9354 | theCommands.Add("vxrotate", |
9355 | "vxrotate", | |
9356 | __FILE__,VXRotate,group); | |
9357 | ||
189f85a3 | 9358 | #if defined(_WIN32) |
9359 | theCommands.Add("vprogressive", | |
9360 | "vprogressive", | |
9361 | __FILE__, VProgressiveMode, group); | |
9362 | #endif | |
7fd59977 | 9363 | } |