| 1 | // Created on: 1998-09-01 |
| 2 | // Created by: Robert COUBLANC |
| 3 | // Copyright (c) 1998-1999 Matra Datavision |
| 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
| 5 | // |
| 6 | // This file is part of Open CASCADE Technology software library. |
| 7 | // |
| 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 |
| 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. |
| 13 | // |
| 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 15 | // commercial license or contractual agreement. |
| 16 | |
| 17 | #include <OpenGl_GlCore20.hxx> |
| 18 | #include <AIS_Shape.hxx> |
| 19 | #include <AIS_InteractiveObject.hxx> |
| 20 | #include <AIS_ListOfInteractive.hxx> |
| 21 | #include <AIS_ListIteratorOfListOfInteractive.hxx> |
| 22 | #include <DBRep.hxx> |
| 23 | #include <Graphic3d_AspectMarker3d.hxx> |
| 24 | #include <Graphic3d_ExportFormat.hxx> |
| 25 | #include <Graphic3d_NameOfTextureEnv.hxx> |
| 26 | #include <Graphic3d_GraduatedTrihedron.hxx> |
| 27 | #include <Graphic3d_TextureEnv.hxx> |
| 28 | #include <Graphic3d_TextureParams.hxx> |
| 29 | #include <Graphic3d_TypeOfTextureFilter.hxx> |
| 30 | #include <Graphic3d_AspectFillArea3d.hxx> |
| 31 | #include <ViewerTest.hxx> |
| 32 | #include <ViewerTest_AutoUpdater.hxx> |
| 33 | #include <ViewerTest_EventManager.hxx> |
| 34 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
| 35 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> |
| 36 | #include <Visual3d_View.hxx> |
| 37 | #include <Visual3d_ViewManager.hxx> |
| 38 | #include <V3d_AmbientLight.hxx> |
| 39 | #include <V3d_ColorScale.hxx> |
| 40 | #include <V3d_DirectionalLight.hxx> |
| 41 | #include <V3d_LayerMgr.hxx> |
| 42 | #include <V3d_LayerMgrPointer.hxx> |
| 43 | #include <V3d_PositionalLight.hxx> |
| 44 | #include <V3d_SpotLight.hxx> |
| 45 | #include <NCollection_DoubleMap.hxx> |
| 46 | #include <NCollection_List.hxx> |
| 47 | #include <NCollection_Vector.hxx> |
| 48 | #include <AIS_InteractiveContext.hxx> |
| 49 | #include <Draw_Interpretor.hxx> |
| 50 | #include <Draw.hxx> |
| 51 | #include <Draw_Appli.hxx> |
| 52 | #include <Aspect_PrintAlgo.hxx> |
| 53 | #include <Image_AlienPixMap.hxx> |
| 54 | #include <OpenGl_GraphicDriver.hxx> |
| 55 | #include <OSD_Timer.hxx> |
| 56 | #include <TColStd_HSequenceOfAsciiString.hxx> |
| 57 | #include <TColStd_SequenceOfInteger.hxx> |
| 58 | #include <TColStd_HSequenceOfReal.hxx> |
| 59 | #include <TColgp_Array1OfPnt2d.hxx> |
| 60 | #include <TColStd_MapOfAsciiString.hxx> |
| 61 | #include <Visual3d_LayerItem.hxx> |
| 62 | #include <Aspect_TypeOfLine.hxx> |
| 63 | #include <Image_Diff.hxx> |
| 64 | #include <Aspect_DisplayConnection.hxx> |
| 65 | #include <gp_Pnt.hxx> |
| 66 | #include <gp_Dir.hxx> |
| 67 | #include <gp_Pln.hxx> |
| 68 | #include <PrsMgr_PresentableObject.hxx> |
| 69 | #include <Graphic3d_ClipPlane.hxx> |
| 70 | #include <NCollection_DataMap.hxx> |
| 71 | #include <Graphic3d_Texture2Dmanual.hxx> |
| 72 | #include <Prs3d_ShadingAspect.hxx> |
| 73 | #include <Prs3d_Drawer.hxx> |
| 74 | |
| 75 | #ifdef WNT |
| 76 | #undef DrawText |
| 77 | #endif |
| 78 | |
| 79 | #include <Visual3d_Layer.hxx> |
| 80 | #include <cstdlib> |
| 81 | |
| 82 | #if defined(_WIN32) |
| 83 | #include <WNT_WClass.hxx> |
| 84 | #include <WNT_Window.hxx> |
| 85 | |
| 86 | #if defined(_MSC_VER) |
| 87 | #define _CRT_SECURE_NO_DEPRECATE |
| 88 | #pragma warning (disable:4996) |
| 89 | #endif |
| 90 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
| 91 | #include <Cocoa_Window.hxx> |
| 92 | #else |
| 93 | #include <Xw_Window.hxx> |
| 94 | #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */ |
| 95 | #include <X11/Xutil.h> |
| 96 | #include <tk.h> |
| 97 | #endif |
| 98 | |
| 99 | inline Standard_Boolean parseOnOff (Standard_CString theArg, |
| 100 | Standard_Boolean& theIsOn) |
| 101 | { |
| 102 | TCollection_AsciiString aFlag (theArg); |
| 103 | aFlag.LowerCase(); |
| 104 | if (aFlag == "on" |
| 105 | || aFlag == "1") |
| 106 | { |
| 107 | theIsOn = Standard_True; |
| 108 | return Standard_True; |
| 109 | } |
| 110 | else if (aFlag == "off" |
| 111 | || aFlag == "0") |
| 112 | { |
| 113 | theIsOn = Standard_False; |
| 114 | return Standard_True; |
| 115 | } |
| 116 | return Standard_False; |
| 117 | } |
| 118 | |
| 119 | // Auxiliary definitions |
| 120 | static const char THE_KEY_DELETE = 127; |
| 121 | |
| 122 | //============================================================================== |
| 123 | // VIEWER GLOBAL VARIABLES |
| 124 | //============================================================================== |
| 125 | |
| 126 | Standard_IMPORT Standard_Boolean Draw_VirtualWindows; |
| 127 | Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand); |
| 128 | |
| 129 | Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv); |
| 130 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
| 131 | |
| 132 | extern int VErase (Draw_Interpretor& theDI, |
| 133 | Standard_Integer theArgNb, |
| 134 | const char** theArgVec); |
| 135 | |
| 136 | #if defined(_WIN32) |
| 137 | static Handle(WNT_Window)& VT_GetWindow() { |
| 138 | static Handle(WNT_Window) WNTWin; |
| 139 | return WNTWin; |
| 140 | } |
| 141 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
| 142 | static Handle(Cocoa_Window)& VT_GetWindow() |
| 143 | { |
| 144 | static Handle(Cocoa_Window) aWindow; |
| 145 | return aWindow; |
| 146 | } |
| 147 | extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow); |
| 148 | extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle); |
| 149 | extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight); |
| 150 | |
| 151 | #else |
| 152 | static Handle(Xw_Window)& VT_GetWindow(){ |
| 153 | static Handle(Xw_Window) XWWin; |
| 154 | return XWWin; |
| 155 | } |
| 156 | |
| 157 | static void VProcessEvents(ClientData,int); |
| 158 | #endif |
| 159 | |
| 160 | static Handle(Aspect_DisplayConnection)& GetDisplayConnection() |
| 161 | { |
| 162 | static Handle(Aspect_DisplayConnection) aDisplayConnection; |
| 163 | return aDisplayConnection; |
| 164 | } |
| 165 | |
| 166 | static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection) |
| 167 | { |
| 168 | GetDisplayConnection() = theDisplayConnection; |
| 169 | } |
| 170 | |
| 171 | #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
| 172 | Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow) |
| 173 | { |
| 174 | Aspect_Handle aWindowHandle = (Aspect_Handle)NULL; |
| 175 | #if defined(_WIN32) |
| 176 | const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow); |
| 177 | if (!aWindow.IsNull()) |
| 178 | return aWindow->HWindow(); |
| 179 | #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
| 180 | const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow); |
| 181 | if (!aWindow.IsNull()) |
| 182 | return aWindow->XWindow(); |
| 183 | #endif |
| 184 | return aWindowHandle; |
| 185 | } |
| 186 | #endif |
| 187 | |
| 188 | static Standard_Boolean MyHLRIsOn = Standard_False; |
| 189 | |
| 190 | NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews; |
| 191 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts; |
| 192 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers; |
| 193 | static OpenGl_Caps ViewerTest_myDefaultCaps; |
| 194 | |
| 195 | #define ZCLIPWIDTH 1. |
| 196 | |
| 197 | static void OSWindowSetup(); |
| 198 | |
| 199 | //============================================================================== |
| 200 | // EVENT GLOBAL VARIABLES |
| 201 | //============================================================================== |
| 202 | |
| 203 | static int Start_Rot = 0; |
| 204 | static int ZClipIsOn = 0; |
| 205 | int X_Motion = 0; // Current cursor position |
| 206 | int Y_Motion = 0; |
| 207 | int X_ButtonPress = 0; // Last ButtonPress position |
| 208 | int Y_ButtonPress = 0; |
| 209 | Standard_Boolean IsDragged = Standard_False; |
| 210 | Standard_Boolean DragFirst = Standard_False; |
| 211 | |
| 212 | //============================================================================== |
| 213 | |
| 214 | #ifdef WNT |
| 215 | static LRESULT WINAPI ViewerWindowProc( |
| 216 | HWND hwnd, |
| 217 | UINT uMsg, |
| 218 | WPARAM wParam, |
| 219 | LPARAM lParam ); |
| 220 | static LRESULT WINAPI AdvViewerWindowProc( |
| 221 | HWND hwnd, |
| 222 | UINT uMsg, |
| 223 | WPARAM wParam, |
| 224 | LPARAM lParam ); |
| 225 | #endif |
| 226 | |
| 227 | |
| 228 | //============================================================================== |
| 229 | //function : WClass |
| 230 | //purpose : |
| 231 | //============================================================================== |
| 232 | |
| 233 | const Handle(MMgt_TShared)& ViewerTest::WClass() |
| 234 | { |
| 235 | static Handle(MMgt_TShared) theWClass; |
| 236 | #if defined(_WIN32) |
| 237 | if (theWClass.IsNull()) |
| 238 | { |
| 239 | theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc, |
| 240 | CS_VREDRAW | CS_HREDRAW, 0, 0, |
| 241 | ::LoadCursor (NULL, IDC_ARROW)); |
| 242 | } |
| 243 | #endif |
| 244 | return theWClass; |
| 245 | } |
| 246 | |
| 247 | //============================================================================== |
| 248 | //function : CreateName |
| 249 | //purpose : Create numerical name for new object in theMap |
| 250 | //============================================================================== |
| 251 | template <typename ObjectType> |
| 252 | TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap, |
| 253 | const TCollection_AsciiString& theDefaultString) |
| 254 | { |
| 255 | if (theObjectMap.IsEmpty()) |
| 256 | return theDefaultString + TCollection_AsciiString(1); |
| 257 | |
| 258 | Standard_Integer aNextKey = 1; |
| 259 | Standard_Boolean isFound = Standard_False; |
| 260 | while (!isFound) |
| 261 | { |
| 262 | TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey); |
| 263 | // Look for objects with default names |
| 264 | if (theObjectMap.IsBound1(aStringKey)) |
| 265 | { |
| 266 | aNextKey++; |
| 267 | } |
| 268 | else |
| 269 | isFound = Standard_True; |
| 270 | } |
| 271 | |
| 272 | return theDefaultString + TCollection_AsciiString(aNextKey); |
| 273 | } |
| 274 | |
| 275 | //============================================================================== |
| 276 | //structure : ViewerTest_Names |
| 277 | //purpose : Allow to operate with full view name: driverName/viewerName/viewName |
| 278 | //============================================================================== |
| 279 | struct ViewerTest_Names |
| 280 | { |
| 281 | private: |
| 282 | TCollection_AsciiString myDriverName; |
| 283 | TCollection_AsciiString myViewerName; |
| 284 | TCollection_AsciiString myViewName; |
| 285 | |
| 286 | public: |
| 287 | |
| 288 | const TCollection_AsciiString& GetDriverName () const |
| 289 | { |
| 290 | return myDriverName; |
| 291 | } |
| 292 | void SetDriverName (const TCollection_AsciiString& theDriverName) |
| 293 | { |
| 294 | myDriverName = theDriverName; |
| 295 | } |
| 296 | const TCollection_AsciiString& GetViewerName () const |
| 297 | { |
| 298 | return myViewerName; |
| 299 | } |
| 300 | void SetViewerName (const TCollection_AsciiString& theViewerName) |
| 301 | { |
| 302 | myViewerName = theViewerName; |
| 303 | } |
| 304 | const TCollection_AsciiString& GetViewName () const |
| 305 | { |
| 306 | return myViewName; |
| 307 | } |
| 308 | void SetViewName (const TCollection_AsciiString& theViewName) |
| 309 | { |
| 310 | myViewName = theViewName; |
| 311 | } |
| 312 | |
| 313 | //=========================================================================== |
| 314 | //function : Constructor for ViewerTest_Names |
| 315 | //purpose : Get view, viewer, driver names from custom string |
| 316 | //=========================================================================== |
| 317 | |
| 318 | ViewerTest_Names (const TCollection_AsciiString& theInputString) |
| 319 | { |
| 320 | TCollection_AsciiString aName(theInputString); |
| 321 | if (theInputString.IsEmpty()) |
| 322 | { |
| 323 | // Get current configuration |
| 324 | if (ViewerTest_myDrivers.IsEmpty()) |
| 325 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> |
| 326 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); |
| 327 | else |
| 328 | myDriverName = ViewerTest_myDrivers.Find2 |
| 329 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); |
| 330 | |
| 331 | if(ViewerTest_myContexts.IsEmpty()) |
| 332 | { |
| 333 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> |
| 334 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); |
| 335 | } |
| 336 | else |
| 337 | myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext()); |
| 338 | |
| 339 | myViewName = CreateName <Handle(V3d_View)> |
| 340 | (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View")); |
| 341 | } |
| 342 | else |
| 343 | { |
| 344 | // There is at least view name |
| 345 | Standard_Integer aParserNumber = 0; |
| 346 | for (Standard_Integer i = 0; i < 3; ++i) |
| 347 | { |
| 348 | Standard_Integer aParserPos = aName.SearchFromEnd("/"); |
| 349 | if(aParserPos != -1) |
| 350 | { |
| 351 | aParserNumber++; |
| 352 | aName.Split(aParserPos-1); |
| 353 | } |
| 354 | else |
| 355 | break; |
| 356 | } |
| 357 | if (aParserNumber == 0) |
| 358 | { |
| 359 | // Only view name |
| 360 | if (!ViewerTest::GetAISContext().IsNull()) |
| 361 | { |
| 362 | myDriverName = ViewerTest_myDrivers.Find2 |
| 363 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); |
| 364 | myViewerName = ViewerTest_myContexts.Find2 |
| 365 | (ViewerTest::GetAISContext()); |
| 366 | } |
| 367 | else |
| 368 | { |
| 369 | // There is no opened contexts here, need to create names for viewer and driver |
| 370 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> |
| 371 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); |
| 372 | |
| 373 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> |
| 374 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); |
| 375 | } |
| 376 | myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString); |
| 377 | } |
| 378 | else if (aParserNumber == 1) |
| 379 | { |
| 380 | // Here is viewerName/viewName |
| 381 | if (!ViewerTest::GetAISContext().IsNull()) |
| 382 | myDriverName = ViewerTest_myDrivers.Find2 |
| 383 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); |
| 384 | else |
| 385 | { |
| 386 | // There is no opened contexts here, need to create name for driver |
| 387 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> |
| 388 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); |
| 389 | } |
| 390 | myViewerName = TCollection_AsciiString(myDriverName + "/" + aName); |
| 391 | |
| 392 | myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString); |
| 393 | } |
| 394 | else |
| 395 | { |
| 396 | //Here is driverName/viewerName/viewName |
| 397 | myDriverName = TCollection_AsciiString(aName); |
| 398 | |
| 399 | TCollection_AsciiString aViewerName(theInputString); |
| 400 | aViewerName.Split(aViewerName.SearchFromEnd("/") - 1); |
| 401 | myViewerName = TCollection_AsciiString(aViewerName); |
| 402 | |
| 403 | myViewName = TCollection_AsciiString(theInputString); |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | }; |
| 408 | |
| 409 | //============================================================================== |
| 410 | //function : FindContextByView |
| 411 | //purpose : Find AIS_InteractiveContext by View |
| 412 | //============================================================================== |
| 413 | |
| 414 | Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView) |
| 415 | { |
| 416 | Handle(AIS_InteractiveContext) anAISContext; |
| 417 | |
| 418 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator |
| 419 | anIter (ViewerTest_myContexts); anIter.More(); anIter.Next()) |
| 420 | { |
| 421 | if (anIter.Value()->CurrentViewer() == theView->Viewer()) |
| 422 | return anIter.Key2(); |
| 423 | } |
| 424 | return anAISContext; |
| 425 | } |
| 426 | |
| 427 | |
| 428 | //============================================================================== |
| 429 | //function : SetWindowTitle |
| 430 | //purpose : Set window title |
| 431 | //============================================================================== |
| 432 | |
| 433 | void SetWindowTitle (const Handle(Aspect_Window)& theWindow, |
| 434 | Standard_CString theTitle) |
| 435 | { |
| 436 | #if defined(_WIN32) |
| 437 | SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(), |
| 438 | theTitle); |
| 439 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
| 440 | SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle); |
| 441 | #else |
| 442 | if(GetDisplayConnection()->GetDisplay()) |
| 443 | { |
| 444 | Window aWindow = |
| 445 | Handle(Xw_Window)::DownCast(theWindow)->XWindow(); |
| 446 | XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle); |
| 447 | } |
| 448 | #endif |
| 449 | } |
| 450 | |
| 451 | //============================================================================== |
| 452 | //function : IsWindowOverlapped |
| 453 | //purpose : Check if theWindow overlapp another view |
| 454 | //============================================================================== |
| 455 | |
| 456 | Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft, |
| 457 | const Standard_Integer thePxTop, |
| 458 | const Standard_Integer thePxRight, |
| 459 | const Standard_Integer thePxBottom, |
| 460 | TCollection_AsciiString& theViewId) |
| 461 | { |
| 462 | for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator |
| 463 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) |
| 464 | { |
| 465 | Standard_Integer aTop = 0, |
| 466 | aLeft = 0, |
| 467 | aRight = 0, |
| 468 | aBottom = 0; |
| 469 | anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom); |
| 470 | if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || |
| 471 | (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) || |
| 472 | (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || |
| 473 | (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom)) |
| 474 | { |
| 475 | theViewId = anIter.Key1(); |
| 476 | return Standard_True; |
| 477 | } |
| 478 | } |
| 479 | return Standard_False; |
| 480 | } |
| 481 | |
| 482 | // Workaround: to create and delete non-orthographic views outside ViewerTest |
| 483 | void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName) |
| 484 | { |
| 485 | ViewerTest_myViews.UnBind1 (theName); |
| 486 | } |
| 487 | |
| 488 | void ViewerTest::InitViewName (const TCollection_AsciiString& theName, |
| 489 | const Handle(V3d_View)& theView) |
| 490 | { |
| 491 | ViewerTest_myViews.Bind (theName, theView); |
| 492 | } |
| 493 | |
| 494 | TCollection_AsciiString ViewerTest::GetCurrentViewName () |
| 495 | { |
| 496 | return ViewerTest_myViews.Find2( ViewerTest::CurrentView()); |
| 497 | } |
| 498 | //============================================================================== |
| 499 | //function : ViewerInit |
| 500 | //purpose : Create the window viewer and initialize all the global variable |
| 501 | //============================================================================== |
| 502 | |
| 503 | TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft, |
| 504 | const Standard_Integer thePxTop, |
| 505 | const Standard_Integer thePxWidth, |
| 506 | const Standard_Integer thePxHeight, |
| 507 | Standard_CString theViewName, |
| 508 | Standard_CString theDisplayName) |
| 509 | { |
| 510 | // Default position and dimension of the viewer window. |
| 511 | // Note that left top corner is set to be sufficiently small to have |
| 512 | // window fit in the small screens (actual for remote desktops, see #23003). |
| 513 | // The position corresponds to the window's client area, thus some |
| 514 | // gap is added for window frame to be visible. |
| 515 | Standard_Integer aPxLeft = 20; |
| 516 | Standard_Integer aPxTop = 40; |
| 517 | Standard_Integer aPxWidth = 409; |
| 518 | Standard_Integer aPxHeight = 409; |
| 519 | Standard_Boolean toCreateViewer = Standard_False; |
| 520 | |
| 521 | Handle(OpenGl_GraphicDriver) aGraphicDriver; |
| 522 | ViewerTest_Names aViewNames(theViewName); |
| 523 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ())) |
| 524 | aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View")); |
| 525 | |
| 526 | if (thePxLeft != 0) |
| 527 | aPxLeft = thePxLeft; |
| 528 | if (thePxTop != 0) |
| 529 | aPxTop = thePxTop; |
| 530 | if (thePxWidth != 0) |
| 531 | aPxWidth = thePxWidth; |
| 532 | if (thePxHeight != 0) |
| 533 | aPxHeight = thePxHeight; |
| 534 | |
| 535 | // Get graphic driver (create it or get from another view) |
| 536 | if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName())) |
| 537 | { |
| 538 | // Get connection string |
| 539 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
| 540 | TCollection_AsciiString aDisplayName(theDisplayName); |
| 541 | if (!aDisplayName.IsEmpty()) |
| 542 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
| 543 | else |
| 544 | SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName)); |
| 545 | #else |
| 546 | (void)theDisplayName; // avoid warning on unused argument |
| 547 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
| 548 | #endif |
| 549 | aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection()); |
| 550 | aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps; |
| 551 | ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver); |
| 552 | toCreateViewer = Standard_True; |
| 553 | } |
| 554 | else |
| 555 | { |
| 556 | aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName())); |
| 557 | } |
| 558 | |
| 559 | //Dispose the window if input parameters are default |
| 560 | if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0) |
| 561 | { |
| 562 | Standard_Integer aTop = 0, |
| 563 | aLeft = 0, |
| 564 | aRight = 0, |
| 565 | aBottom = 0, |
| 566 | aScreenWidth = 0, |
| 567 | aScreenHeight = 0; |
| 568 | |
| 569 | // Get screen resolution |
| 570 | #if defined(_WIN32) || defined(__WIN32__) |
| 571 | RECT aWindowSize; |
| 572 | GetClientRect(GetDesktopWindow(), &aWindowSize); |
| 573 | aScreenHeight = aWindowSize.bottom; |
| 574 | aScreenWidth = aWindowSize.right; |
| 575 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
| 576 | GetCocoaScreenResolution (aScreenWidth, aScreenHeight); |
| 577 | #else |
| 578 | Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay()); |
| 579 | aScreenWidth = WidthOfScreen(aScreen); |
| 580 | aScreenHeight = HeightOfScreen(aScreen); |
| 581 | #endif |
| 582 | |
| 583 | TCollection_AsciiString anOverlappedViewId(""); |
| 584 | |
| 585 | while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)) |
| 586 | { |
| 587 | ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom); |
| 588 | |
| 589 | if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId) |
| 590 | && aRight + 2*aPxWidth + 40 > aScreenWidth) |
| 591 | { |
| 592 | if (aBottom + aPxHeight + 40 > aScreenHeight) |
| 593 | { |
| 594 | aPxLeft = 20; |
| 595 | aPxTop = 40; |
| 596 | break; |
| 597 | } |
| 598 | aPxLeft = 20; |
| 599 | aPxTop = aBottom + 40; |
| 600 | } |
| 601 | else |
| 602 | aPxLeft = aRight + 20; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | // Get viewer name |
| 607 | TCollection_AsciiString aTitle("3D View - "); |
| 608 | aTitle = aTitle + aViewNames.GetViewName() + "(*)"; |
| 609 | |
| 610 | // Change name of current active window |
| 611 | if (!ViewerTest::CurrentView().IsNull()) |
| 612 | { |
| 613 | TCollection_AsciiString aTitle("3D View - "); |
| 614 | aTitle = aTitle |
| 615 | + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); |
| 616 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); |
| 617 | } |
| 618 | |
| 619 | // Create viewer |
| 620 | Handle(V3d_Viewer) a3DViewer; |
| 621 | // If it's the single view, we first look for empty context |
| 622 | if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty()) |
| 623 | { |
| 624 | NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator |
| 625 | anIter(ViewerTest_myContexts); |
| 626 | if (anIter.More()) |
| 627 | ViewerTest::SetAISContext (anIter.Value()); |
| 628 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); |
| 629 | } |
| 630 | else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())) |
| 631 | { |
| 632 | ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName())); |
| 633 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); |
| 634 | } |
| 635 | else if (a3DViewer.IsNull()) |
| 636 | { |
| 637 | toCreateViewer = Standard_True; |
| 638 | TCollection_ExtendedString NameOfWindow("Viewer3D"); |
| 639 | a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString()); |
| 640 | |
| 641 | NameOfWindow = TCollection_ExtendedString("Collector"); |
| 642 | |
| 643 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); |
| 644 | } |
| 645 | |
| 646 | // AIS context setup |
| 647 | if (ViewerTest::GetAISContext().IsNull() || |
| 648 | !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))) |
| 649 | { |
| 650 | Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer); |
| 651 | ViewerTest::SetAISContext (aContext); |
| 652 | ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext()); |
| 653 | } |
| 654 | else |
| 655 | { |
| 656 | ViewerTest::ResetEventManager(); |
| 657 | } |
| 658 | |
| 659 | // Create window |
| 660 | #if defined(_WIN32) |
| 661 | VT_GetWindow() = new WNT_Window (aTitle.ToCString(), |
| 662 | Handle(WNT_WClass)::DownCast (WClass()), |
| 663 | Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW, |
| 664 | aPxLeft, aPxTop, |
| 665 | aPxWidth, aPxHeight, |
| 666 | Quantity_NOC_BLACK); |
| 667 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
| 668 | VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(), |
| 669 | aPxLeft, aPxTop, |
| 670 | aPxWidth, aPxHeight); |
| 671 | ViewerTest_SetCocoaEventManagerView (VT_GetWindow()); |
| 672 | #else |
| 673 | VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(), |
| 674 | aTitle.ToCString(), |
| 675 | aPxLeft, aPxTop, |
| 676 | aPxWidth, aPxHeight); |
| 677 | #endif |
| 678 | VT_GetWindow()->SetVirtual (Draw_VirtualWindows); |
| 679 | |
| 680 | // View setup |
| 681 | Handle(V3d_View) aView = a3DViewer->CreateView(); |
| 682 | aView->SetWindow (VT_GetWindow()); |
| 683 | |
| 684 | ViewerTest::CurrentView(aView); |
| 685 | ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView); |
| 686 | |
| 687 | // Setup for X11 or NT |
| 688 | OSWindowSetup(); |
| 689 | |
| 690 | // Set parameters for V3d_View and V3d_Viewer |
| 691 | const Handle (V3d_View) aV3dView = ViewerTest::CurrentView(); |
| 692 | aV3dView->SetComputedMode(Standard_False); |
| 693 | MyHLRIsOn = aV3dView->ComputedMode(); |
| 694 | aV3dView->SetZClippingDepth(0.5); |
| 695 | aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.); |
| 696 | |
| 697 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); |
| 698 | if (toCreateViewer) |
| 699 | { |
| 700 | a3DViewer->SetDefaultLights(); |
| 701 | a3DViewer->SetLightOn(); |
| 702 | } |
| 703 | |
| 704 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
| 705 | #if TCL_MAJOR_VERSION < 8 |
| 706 | Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
| 707 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
| 708 | #else |
| 709 | Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
| 710 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
| 711 | #endif |
| 712 | #endif |
| 713 | |
| 714 | VT_GetWindow()->Map(); |
| 715 | |
| 716 | // Set the handle of created view in the event manager |
| 717 | ViewerTest::ResetEventManager(); |
| 718 | |
| 719 | ViewerTest::CurrentView()->Redraw(); |
| 720 | |
| 721 | aView.Nullify(); |
| 722 | a3DViewer.Nullify(); |
| 723 | |
| 724 | return aViewNames.GetViewName(); |
| 725 | } |
| 726 | |
| 727 | //============================================================================== |
| 728 | //function : RedrawAllViews |
| 729 | //purpose : Redraw all created views |
| 730 | //============================================================================== |
| 731 | void ViewerTest::RedrawAllViews() |
| 732 | { |
| 733 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); |
| 734 | for (; aViewIt.More(); aViewIt.Next()) |
| 735 | { |
| 736 | const Handle(V3d_View)& aView = aViewIt.Key2(); |
| 737 | aView->Redraw(); |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | //============================================================================== |
| 742 | //function : Vinit |
| 743 | //purpose : Create the window viewer and initialize all the global variable |
| 744 | // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event |
| 745 | //============================================================================== |
| 746 | |
| 747 | static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
| 748 | { |
| 749 | if (theArgsNb > 9) |
| 750 | { |
| 751 | std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n" |
| 752 | << "Type help for more information.\n"; |
| 753 | return 1; |
| 754 | } |
| 755 | |
| 756 | TCollection_AsciiString aViewName, aDisplayName; |
| 757 | Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0; |
| 758 | TCollection_AsciiString aName, aValue; |
| 759 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) |
| 760 | { |
| 761 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; |
| 762 | TCollection_AsciiString anArgCase = anArg; |
| 763 | anArgCase.UpperCase(); |
| 764 | if (ViewerTest::SplitParameter (anArg, aName, aValue)) |
| 765 | { |
| 766 | aName.UpperCase(); |
| 767 | if (aName.IsEqual ("NAME")) |
| 768 | { |
| 769 | aViewName = aValue; |
| 770 | } |
| 771 | else if (aName.IsEqual ("L") |
| 772 | || aName.IsEqual ("LEFT")) |
| 773 | { |
| 774 | aPxLeft = aValue.IntegerValue(); |
| 775 | } |
| 776 | else if (aName.IsEqual ("T") |
| 777 | || aName.IsEqual ("TOP")) |
| 778 | { |
| 779 | aPxTop = aValue.IntegerValue(); |
| 780 | } |
| 781 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
| 782 | else if (aName.IsEqual ("DISP") |
| 783 | || aName.IsEqual ("DISPLAY")) |
| 784 | { |
| 785 | aDisplayName = aValue; |
| 786 | } |
| 787 | #endif |
| 788 | else if (aName.IsEqual ("W") |
| 789 | || aName.IsEqual ("WIDTH")) |
| 790 | { |
| 791 | aPxWidth = aValue.IntegerValue(); |
| 792 | } |
| 793 | else if (aName.IsEqual ("H") |
| 794 | || aName.IsEqual ("HEIGHT")) |
| 795 | { |
| 796 | aPxHeight = aValue.IntegerValue(); |
| 797 | } |
| 798 | else |
| 799 | { |
| 800 | std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n"; |
| 801 | } |
| 802 | } |
| 803 | else if (aViewName.IsEmpty()) |
| 804 | { |
| 805 | aViewName = anArg; |
| 806 | } |
| 807 | else |
| 808 | { |
| 809 | std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n"; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | ViewerTest_Names aViewNames (aViewName); |
| 814 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName())) |
| 815 | { |
| 816 | TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName(); |
| 817 | theDi.Eval (aCommand.ToCString()); |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight, |
| 822 | aViewName.ToCString(), |
| 823 | aDisplayName.ToCString()); |
| 824 | theDi << aViewId; |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | //============================================================================== |
| 829 | //function : VHLR |
| 830 | //purpose : hidden lines removal algorithm |
| 831 | //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}] |
| 832 | //============================================================================== |
| 833 | |
| 834 | static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 835 | { |
| 836 | if (ViewerTest::CurrentView().IsNull()) |
| 837 | { |
| 838 | di << argv[0] << ": Call vinit before this command, please.\n"; |
| 839 | return 1; |
| 840 | } |
| 841 | |
| 842 | if (argc < 2) |
| 843 | { |
| 844 | di << argv[0] << ": Wrong number of command arguments.\n" |
| 845 | << "Type help " << argv[0] << " for more information.\n"; |
| 846 | return 1; |
| 847 | } |
| 848 | |
| 849 | // Enable or disable HLR mode. |
| 850 | Standard_Boolean isHLROn = |
| 851 | (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False; |
| 852 | |
| 853 | if (isHLROn != MyHLRIsOn) |
| 854 | { |
| 855 | MyHLRIsOn = isHLROn; |
| 856 | ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn); |
| 857 | } |
| 858 | |
| 859 | // Show or hide hidden lines in HLR mode. |
| 860 | Standard_Boolean isCurrentShowHidden |
| 861 | = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine(); |
| 862 | |
| 863 | Standard_Boolean isShowHidden = |
| 864 | (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False) |
| 865 | : isCurrentShowHidden; |
| 866 | |
| 867 | |
| 868 | if (isShowHidden != isCurrentShowHidden) |
| 869 | { |
| 870 | if (isShowHidden) |
| 871 | { |
| 872 | ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine(); |
| 873 | } |
| 874 | else |
| 875 | { |
| 876 | ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine(); |
| 877 | } |
| 878 | |
| 879 | // Redisplay shapes. |
| 880 | if (MyHLRIsOn) |
| 881 | { |
| 882 | AIS_ListOfInteractive aListOfShapes; |
| 883 | ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes); |
| 884 | |
| 885 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next()) |
| 886 | { |
| 887 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value()); |
| 888 | if (aShape.IsNull()) |
| 889 | { |
| 890 | continue; |
| 891 | } |
| 892 | ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False); |
| 893 | } |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | ViewerTest::CurrentView()->Update(); |
| 898 | return 0; |
| 899 | } |
| 900 | |
| 901 | //============================================================================== |
| 902 | //function : VHLRType |
| 903 | //purpose : change type of using HLR algorithm |
| 904 | //============================================================================== |
| 905 | |
| 906 | static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 907 | { |
| 908 | if (ViewerTest::CurrentView().IsNull()) |
| 909 | { |
| 910 | di << argv[0] << ": Call vinit before this command, please.\n"; |
| 911 | return 1; |
| 912 | } |
| 913 | |
| 914 | if (argc < 2) |
| 915 | { |
| 916 | di << argv[0] << ": Wrong number of command arguments.\n" |
| 917 | << "Type help " << argv[0] << " for more information.\n"; |
| 918 | return 1; |
| 919 | } |
| 920 | |
| 921 | Prs3d_TypeOfHLR aTypeOfHLR = |
| 922 | (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo; |
| 923 | |
| 924 | if (argc == 2) |
| 925 | { |
| 926 | AIS_ListOfInteractive aListOfShapes; |
| 927 | ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes); |
| 928 | ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR); |
| 929 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); |
| 930 | anIter.More(); anIter.Next()) |
| 931 | { |
| 932 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); |
| 933 | if (aShape.IsNull()) |
| 934 | continue; |
| 935 | if (aShape->TypeOfHLR() != aTypeOfHLR) |
| 936 | aShape->SetTypeOfHLR (aTypeOfHLR); |
| 937 | if (MyHLRIsOn) |
| 938 | ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False); |
| 939 | } |
| 940 | ViewerTest::CurrentView()->Update(); |
| 941 | return 0; |
| 942 | } |
| 943 | else |
| 944 | { |
| 945 | for (Standard_Integer i = 2; i < argc; ++i) |
| 946 | { |
| 947 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); |
| 948 | TCollection_AsciiString aName (argv[i]); |
| 949 | |
| 950 | if (!aMap.IsBound2 (aName)) |
| 951 | { |
| 952 | di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n"; |
| 953 | continue; |
| 954 | } |
| 955 | Handle(AIS_Shape) anAISObject = |
| 956 | Handle(AIS_Shape)::DownCast (aMap.Find2(aName)); |
| 957 | if (anAISObject.IsNull()) |
| 958 | continue; |
| 959 | anAISObject->SetTypeOfHLR (aTypeOfHLR); |
| 960 | if (MyHLRIsOn) |
| 961 | ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False); |
| 962 | } |
| 963 | ViewerTest::CurrentView()->Update(); |
| 964 | } |
| 965 | |
| 966 | return 0; |
| 967 | } |
| 968 | |
| 969 | //============================================================================== |
| 970 | //function : FindViewIdByWindowHandle |
| 971 | //purpose : Find theView Id in the map of views by window handle |
| 972 | //============================================================================== |
| 973 | #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
| 974 | TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle) |
| 975 | { |
| 976 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator |
| 977 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) |
| 978 | { |
| 979 | Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window()); |
| 980 | if (aWindowHandle == theWindowHandle) |
| 981 | return anIter.Key1(); |
| 982 | } |
| 983 | return TCollection_AsciiString(""); |
| 984 | } |
| 985 | #endif |
| 986 | |
| 987 | //============================================================================== |
| 988 | //function : ActivateView |
| 989 | //purpose : Make the view active |
| 990 | //============================================================================== |
| 991 | |
| 992 | void ActivateView (const TCollection_AsciiString& theViewName) |
| 993 | { |
| 994 | const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); |
| 995 | if (!aView.IsNull()) |
| 996 | { |
| 997 | Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView); |
| 998 | if (!anAISContext.IsNull()) |
| 999 | { |
| 1000 | if (!ViewerTest::CurrentView().IsNull()) |
| 1001 | { |
| 1002 | TCollection_AsciiString aTitle("3D View - "); |
| 1003 | aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); |
| 1004 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); |
| 1005 | } |
| 1006 | |
| 1007 | ViewerTest::CurrentView (aView); |
| 1008 | // Update degenerate mode |
| 1009 | MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode(); |
| 1010 | ViewerTest::SetAISContext (anAISContext); |
| 1011 | TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - "); |
| 1012 | aTitle = aTitle + theViewName + "(*)"; |
| 1013 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); |
| 1014 | #if defined(_WIN32) || defined(__WIN32__) |
| 1015 | VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window()); |
| 1016 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
| 1017 | VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window()); |
| 1018 | #else |
| 1019 | VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window()); |
| 1020 | #endif |
| 1021 | SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
| 1022 | ViewerTest::CurrentView()->Redraw(); |
| 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | //============================================================================== |
| 1028 | //function : RemoveView |
| 1029 | //purpose : |
| 1030 | //============================================================================== |
| 1031 | void ViewerTest::RemoveView (const Handle(V3d_View)& theView, |
| 1032 | const Standard_Boolean theToRemoveContext) |
| 1033 | { |
| 1034 | if (!ViewerTest_myViews.IsBound2 (theView)) |
| 1035 | { |
| 1036 | return; |
| 1037 | } |
| 1038 | |
| 1039 | const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView); |
| 1040 | RemoveView (aViewName, theToRemoveContext); |
| 1041 | } |
| 1042 | |
| 1043 | //============================================================================== |
| 1044 | //function : RemoveView |
| 1045 | //purpose : Close and remove view from display, clear maps if neccessary |
| 1046 | //============================================================================== |
| 1047 | void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved) |
| 1048 | { |
| 1049 | if (!ViewerTest_myViews.IsBound1(theViewName)) |
| 1050 | { |
| 1051 | cout << "Wrong view name\n"; |
| 1052 | return; |
| 1053 | } |
| 1054 | |
| 1055 | // Activate another view if it's active now |
| 1056 | if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView()) |
| 1057 | { |
| 1058 | if (ViewerTest_myViews.Extent() > 1) |
| 1059 | { |
| 1060 | TCollection_AsciiString aNewViewName; |
| 1061 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator |
| 1062 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) |
| 1063 | if (anIter.Key1() != theViewName) |
| 1064 | { |
| 1065 | aNewViewName = anIter.Key1(); |
| 1066 | break; |
| 1067 | } |
| 1068 | ActivateView (aNewViewName); |
| 1069 | } |
| 1070 | else |
| 1071 | { |
| 1072 | Handle(V3d_View) anEmptyView; |
| 1073 | #if defined(_WIN32) || defined(__WIN32__) |
| 1074 | Handle(WNT_Window) anEmptyWindow; |
| 1075 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
| 1076 | Handle(Cocoa_Window) anEmptyWindow; |
| 1077 | #else |
| 1078 | Handle(Xw_Window) anEmptyWindow; |
| 1079 | #endif |
| 1080 | VT_GetWindow() = anEmptyWindow; |
| 1081 | ViewerTest::CurrentView (anEmptyView); |
| 1082 | if (isContextRemoved) |
| 1083 | { |
| 1084 | Handle(AIS_InteractiveContext) anEmptyContext; |
| 1085 | ViewerTest::SetAISContext(anEmptyContext); |
| 1086 | } |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | // Delete view |
| 1091 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); |
| 1092 | Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView); |
| 1093 | |
| 1094 | // Remove view resources |
| 1095 | ViewerTest_myViews.UnBind1(theViewName); |
| 1096 | aView->Remove(); |
| 1097 | |
| 1098 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
| 1099 | XFlush (GetDisplayConnection()->GetDisplay()); |
| 1100 | #endif |
| 1101 | |
| 1102 | // Keep context opened only if the closed view is last to avoid |
| 1103 | // unused empty contexts |
| 1104 | if (!aCurrentContext.IsNull()) |
| 1105 | { |
| 1106 | // Check if there are more difined views in the viewer |
| 1107 | aCurrentContext->CurrentViewer()->InitDefinedViews(); |
| 1108 | if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews()) |
| 1109 | { |
| 1110 | // Remove driver if there is no viewers that use it |
| 1111 | Standard_Boolean isRemoveDriver = Standard_True; |
| 1112 | for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator |
| 1113 | anIter(ViewerTest_myContexts); anIter.More(); anIter.Next()) |
| 1114 | { |
| 1115 | if (aCurrentContext != anIter.Key2() && |
| 1116 | aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver()) |
| 1117 | { |
| 1118 | isRemoveDriver = Standard_False; |
| 1119 | break; |
| 1120 | } |
| 1121 | } |
| 1122 | if(isRemoveDriver) |
| 1123 | { |
| 1124 | ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver()); |
| 1125 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
| 1126 | #if TCL_MAJOR_VERSION < 8 |
| 1127 | Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); |
| 1128 | #else |
| 1129 | Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); |
| 1130 | #endif |
| 1131 | #endif |
| 1132 | } |
| 1133 | |
| 1134 | ViewerTest_myContexts.UnBind2(aCurrentContext); |
| 1135 | } |
| 1136 | } |
| 1137 | cout << "3D View - " << theViewName << " was deleted.\n"; |
| 1138 | |
| 1139 | } |
| 1140 | |
| 1141 | //============================================================================== |
| 1142 | //function : VClose |
| 1143 | //purpose : Remove the view defined by its name |
| 1144 | //============================================================================== |
| 1145 | |
| 1146 | static int VClose (Draw_Interpretor& /*theDi*/, |
| 1147 | Standard_Integer theArgsNb, |
| 1148 | const char** theArgVec) |
| 1149 | { |
| 1150 | NCollection_List<TCollection_AsciiString> aViewList; |
| 1151 | if (theArgsNb > 1) |
| 1152 | { |
| 1153 | TCollection_AsciiString anArg (theArgVec[1]); |
| 1154 | anArg.UpperCase(); |
| 1155 | if (anArg.IsEqual ("ALL") |
| 1156 | || anArg.IsEqual ("*")) |
| 1157 | { |
| 1158 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews); |
| 1159 | anIter.More(); anIter.Next()) |
| 1160 | { |
| 1161 | aViewList.Append (anIter.Key1()); |
| 1162 | } |
| 1163 | if (aViewList.IsEmpty()) |
| 1164 | { |
| 1165 | std::cout << "No view to close\n"; |
| 1166 | return 0; |
| 1167 | } |
| 1168 | } |
| 1169 | else |
| 1170 | { |
| 1171 | ViewerTest_Names aViewName (theArgVec[1]); |
| 1172 | if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName())) |
| 1173 | { |
| 1174 | std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n"; |
| 1175 | return 1; |
| 1176 | } |
| 1177 | aViewList.Append (aViewName.GetViewName()); |
| 1178 | } |
| 1179 | } |
| 1180 | else |
| 1181 | { |
| 1182 | // close active view |
| 1183 | if (ViewerTest::CurrentView().IsNull()) |
| 1184 | { |
| 1185 | std::cerr << "No active view!\n"; |
| 1186 | return 1; |
| 1187 | } |
| 1188 | aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView())); |
| 1189 | } |
| 1190 | |
| 1191 | Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1); |
| 1192 | for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList); |
| 1193 | anIter.More(); anIter.Next()) |
| 1194 | { |
| 1195 | ViewerTest::RemoveView (anIter.Value(), toRemoveContext); |
| 1196 | } |
| 1197 | |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
| 1201 | //============================================================================== |
| 1202 | //function : VActivate |
| 1203 | //purpose : Activate the view defined by its ID |
| 1204 | //============================================================================== |
| 1205 | |
| 1206 | static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
| 1207 | { |
| 1208 | if (theArgsNb > 2) |
| 1209 | { |
| 1210 | theDi << theArgVec[0] << ": wrong number of command arguments.\n" |
| 1211 | << "Usage: " << theArgVec[0] << " ViewID\n"; |
| 1212 | return 1; |
| 1213 | } |
| 1214 | if(theArgsNb == 1) |
| 1215 | { |
| 1216 | theDi.Eval("vviewlist"); |
| 1217 | return 0; |
| 1218 | } |
| 1219 | |
| 1220 | TCollection_AsciiString aNameString(theArgVec[1]); |
| 1221 | if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 ) |
| 1222 | { |
| 1223 | TCollection_AsciiString aTitle("3D View - "); |
| 1224 | aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView()); |
| 1225 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); |
| 1226 | Handle(V3d_View) anEmptyView; |
| 1227 | #if defined(_WIN32) || defined(__WIN32__) |
| 1228 | Handle(WNT_Window) anEmptyWindow; |
| 1229 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
| 1230 | Handle(Cocoa_Window) anEmptyWindow; |
| 1231 | #else |
| 1232 | Handle(Xw_Window) anEmptyWindow; |
| 1233 | #endif |
| 1234 | VT_GetWindow() = anEmptyWindow; |
| 1235 | ViewerTest::CurrentView (anEmptyView); |
| 1236 | ViewerTest::ResetEventManager(); |
| 1237 | theDi << theArgVec[0] << ": all views are inactive\n"; |
| 1238 | return 0; |
| 1239 | } |
| 1240 | |
| 1241 | ViewerTest_Names aViewNames(aNameString); |
| 1242 | |
| 1243 | // Check if this view exists in the viewer with the driver |
| 1244 | if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName())) |
| 1245 | { |
| 1246 | theDi << "Wrong view name\n"; |
| 1247 | return 1; |
| 1248 | } |
| 1249 | |
| 1250 | // Check if it is active already |
| 1251 | if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName())) |
| 1252 | { |
| 1253 | theDi << theArgVec[0] << ": the view is active already\n"; |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | ActivateView (aViewNames.GetViewName()); |
| 1258 | return 0; |
| 1259 | } |
| 1260 | |
| 1261 | //============================================================================== |
| 1262 | //function : VViewList |
| 1263 | //purpose : Print current list of views per viewer and graphic driver ID |
| 1264 | // shared between viewers |
| 1265 | //============================================================================== |
| 1266 | |
| 1267 | static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
| 1268 | { |
| 1269 | if (theArgsNb > 2) |
| 1270 | { |
| 1271 | theDi << theArgVec[0] << ": Wrong number of command arguments\n" |
| 1272 | << "Usage: " << theArgVec[0] << " name"; |
| 1273 | return 1; |
| 1274 | } |
| 1275 | if (ViewerTest_myContexts.Size() < 1) |
| 1276 | return 0; |
| 1277 | |
| 1278 | Standard_Boolean isTreeView = |
| 1279 | (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 )); |
| 1280 | |
| 1281 | if (isTreeView) |
| 1282 | theDi << theArgVec[0] <<":\n"; |
| 1283 | |
| 1284 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator |
| 1285 | aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next()) |
| 1286 | { |
| 1287 | if (isTreeView) |
| 1288 | theDi << aDriverIter.Key1() << ":\n"; |
| 1289 | |
| 1290 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator |
| 1291 | aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next()) |
| 1292 | { |
| 1293 | if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1) |
| 1294 | { |
| 1295 | if (isTreeView) |
| 1296 | { |
| 1297 | TCollection_AsciiString aContextName(aContextIter.Key1()); |
| 1298 | theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n"; |
| 1299 | } |
| 1300 | |
| 1301 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator |
| 1302 | aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next()) |
| 1303 | { |
| 1304 | if (aViewIter.Key1().Search(aContextIter.Key1()) != -1) |
| 1305 | { |
| 1306 | TCollection_AsciiString aViewName(aViewIter.Key1()); |
| 1307 | if (isTreeView) |
| 1308 | { |
| 1309 | if (aViewIter.Value() == ViewerTest::CurrentView()) |
| 1310 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n"; |
| 1311 | else |
| 1312 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n"; |
| 1313 | } |
| 1314 | else |
| 1315 | { |
| 1316 | theDi << aViewName << " "; |
| 1317 | } |
| 1318 | } |
| 1319 | } |
| 1320 | } |
| 1321 | } |
| 1322 | } |
| 1323 | return 0; |
| 1324 | } |
| 1325 | |
| 1326 | //============================================================================== |
| 1327 | //function : VT_ProcessKeyPress |
| 1328 | //purpose : Handle KeyPress event from a CString |
| 1329 | //============================================================================== |
| 1330 | void VT_ProcessKeyPress (const char* buf_ret) |
| 1331 | { |
| 1332 | //cout << "KeyPress" << endl; |
| 1333 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 1334 | // Letter in alphabetic order |
| 1335 | |
| 1336 | if (!strcasecmp (buf_ret, "A")) |
| 1337 | { |
| 1338 | // AXO |
| 1339 | aView->SetProj(V3d_XposYnegZpos); |
| 1340 | } |
| 1341 | else if (!strcasecmp (buf_ret, "D")) |
| 1342 | { |
| 1343 | // Reset |
| 1344 | aView->Reset(); |
| 1345 | } |
| 1346 | else if (!strcasecmp (buf_ret, "F")) |
| 1347 | { |
| 1348 | if (ViewerTest::GetAISContext()->NbSelected() > 0) |
| 1349 | { |
| 1350 | ViewerTest::GetAISContext()->FitSelected (aView); |
| 1351 | } |
| 1352 | else |
| 1353 | { |
| 1354 | // FitAll |
| 1355 | aView->FitAll(); |
| 1356 | } |
| 1357 | } |
| 1358 | else if (!strcasecmp (buf_ret, "H")) |
| 1359 | { |
| 1360 | // HLR |
| 1361 | cout << "HLR" << endl; |
| 1362 | aView->SetComputedMode (!aView->ComputedMode()); |
| 1363 | MyHLRIsOn = aView->ComputedMode(); |
| 1364 | } |
| 1365 | else if (!strcasecmp (buf_ret, "P")) |
| 1366 | { |
| 1367 | // Type of HLR |
| 1368 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 1369 | if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo) |
| 1370 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo); |
| 1371 | else |
| 1372 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo); |
| 1373 | if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0) |
| 1374 | { |
| 1375 | AIS_ListOfInteractive aListOfShapes; |
| 1376 | aContext->DisplayedObjects(aListOfShapes); |
| 1377 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); |
| 1378 | anIter.More(); anIter.Next()) |
| 1379 | { |
| 1380 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); |
| 1381 | if (aShape.IsNull()) |
| 1382 | continue; |
| 1383 | if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) |
| 1384 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); |
| 1385 | else |
| 1386 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); |
| 1387 | aContext->Redisplay (aShape, Standard_False); |
| 1388 | } |
| 1389 | } |
| 1390 | else |
| 1391 | { |
| 1392 | for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()) |
| 1393 | { |
| 1394 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current()); |
| 1395 | if (aShape.IsNull()) |
| 1396 | continue; |
| 1397 | if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) |
| 1398 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); |
| 1399 | else |
| 1400 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); |
| 1401 | aContext->Redisplay (aShape, Standard_False); |
| 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | aContext->UpdateCurrentViewer(); |
| 1406 | |
| 1407 | } |
| 1408 | else if (!strcasecmp (buf_ret, "S")) |
| 1409 | { |
| 1410 | std::cout << "setup Shaded display mode" << std::endl; |
| 1411 | |
| 1412 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
| 1413 | if(Ctx->NbCurrents()==0 || |
| 1414 | Ctx->NbSelected()==0) |
| 1415 | Ctx->SetDisplayMode(AIS_Shaded); |
| 1416 | else{ |
| 1417 | if(Ctx->HasOpenedContext()){ |
| 1418 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) |
| 1419 | Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False); |
| 1420 | } |
| 1421 | else{ |
| 1422 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) |
| 1423 | Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False); |
| 1424 | } |
| 1425 | Ctx->UpdateCurrentViewer(); |
| 1426 | } |
| 1427 | } |
| 1428 | else if (!strcasecmp (buf_ret, "U")) |
| 1429 | { |
| 1430 | // Unset display mode |
| 1431 | std::cout << "reset display mode to defaults" << std::endl; |
| 1432 | |
| 1433 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
| 1434 | if(Ctx->NbCurrents()==0 || |
| 1435 | Ctx->NbSelected()==0) |
| 1436 | Ctx->SetDisplayMode(AIS_WireFrame); |
| 1437 | else{ |
| 1438 | if(Ctx->HasOpenedContext()){ |
| 1439 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) |
| 1440 | Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False); |
| 1441 | } |
| 1442 | else{ |
| 1443 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) |
| 1444 | Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False); |
| 1445 | } |
| 1446 | Ctx->UpdateCurrentViewer(); |
| 1447 | } |
| 1448 | |
| 1449 | } |
| 1450 | else if (!strcasecmp (buf_ret, "T")) |
| 1451 | { |
| 1452 | // Top |
| 1453 | aView->SetProj(V3d_Zpos); |
| 1454 | } |
| 1455 | else if (!strcasecmp (buf_ret, "B")) |
| 1456 | { |
| 1457 | // Bottom |
| 1458 | aView->SetProj(V3d_Zneg); |
| 1459 | } |
| 1460 | else if (!strcasecmp (buf_ret, "L")) |
| 1461 | { |
| 1462 | // Left |
| 1463 | aView->SetProj(V3d_Xneg); |
| 1464 | } |
| 1465 | else if (!strcasecmp (buf_ret, "R")) |
| 1466 | { |
| 1467 | // Right |
| 1468 | aView->SetProj(V3d_Xpos); |
| 1469 | } |
| 1470 | else if (!strcasecmp (buf_ret, "W")) |
| 1471 | { |
| 1472 | std::cout << "setup WireFrame display mode" << std::endl; |
| 1473 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
| 1474 | if(Ctx->NbCurrents()==0 || |
| 1475 | Ctx->NbSelected()==0) |
| 1476 | Ctx->SetDisplayMode(AIS_WireFrame); |
| 1477 | else{ |
| 1478 | if(Ctx->HasOpenedContext()){ |
| 1479 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) |
| 1480 | Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False); |
| 1481 | } |
| 1482 | else{ |
| 1483 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) |
| 1484 | Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False); |
| 1485 | } |
| 1486 | Ctx->UpdateCurrentViewer(); |
| 1487 | } |
| 1488 | } |
| 1489 | else if (!strcasecmp (buf_ret, "Z")) |
| 1490 | { |
| 1491 | // ZCLIP |
| 1492 | if ( ZClipIsOn ) { |
| 1493 | cout << "ZClipping OFF" << endl; |
| 1494 | ZClipIsOn = 0; |
| 1495 | |
| 1496 | aView->SetZClippingType(V3d_OFF); |
| 1497 | aView->Redraw(); |
| 1498 | } |
| 1499 | else { |
| 1500 | cout << "ZClipping ON" << endl; |
| 1501 | ZClipIsOn = 1; |
| 1502 | |
| 1503 | aView->SetZClippingType(V3d_FRONT); |
| 1504 | aView->Redraw(); |
| 1505 | } |
| 1506 | } |
| 1507 | else if (!strcasecmp (buf_ret, ",")) |
| 1508 | { |
| 1509 | ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView()); |
| 1510 | } |
| 1511 | else if (!strcasecmp (buf_ret, ".")) |
| 1512 | { |
| 1513 | ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView()); |
| 1514 | } |
| 1515 | else if (*buf_ret == THE_KEY_DELETE) |
| 1516 | { |
| 1517 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); |
| 1518 | if (!aCtx.IsNull() |
| 1519 | && aCtx->NbCurrents() > 0 |
| 1520 | && aCtx->NbSelected() > 0) |
| 1521 | { |
| 1522 | Draw_Interprete ("verase"); |
| 1523 | } |
| 1524 | } |
| 1525 | else |
| 1526 | { |
| 1527 | // Number |
| 1528 | Standard_Integer Num = Draw::Atoi(buf_ret); |
| 1529 | if(Num>=0 && Num<=7) |
| 1530 | ViewerTest::StandardModeActivation(Num); |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | //============================================================================== |
| 1535 | //function : VT_ProcessExpose |
| 1536 | //purpose : Redraw the View on an Expose Event |
| 1537 | //============================================================================== |
| 1538 | void VT_ProcessExpose() |
| 1539 | { |
| 1540 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); |
| 1541 | if (!aView3d.IsNull()) |
| 1542 | { |
| 1543 | aView3d->Redraw(); |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | //============================================================================== |
| 1548 | //function : VT_ProcessConfigure |
| 1549 | //purpose : Resize the View on an Configure Event |
| 1550 | //============================================================================== |
| 1551 | void VT_ProcessConfigure() |
| 1552 | { |
| 1553 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); |
| 1554 | if (aView3d.IsNull()) |
| 1555 | { |
| 1556 | return; |
| 1557 | } |
| 1558 | |
| 1559 | aView3d->MustBeResized(); |
| 1560 | aView3d->Update(); |
| 1561 | aView3d->Redraw(); |
| 1562 | } |
| 1563 | |
| 1564 | //============================================================================== |
| 1565 | //function : VT_ProcessButton1Press |
| 1566 | //purpose : Picking |
| 1567 | //============================================================================== |
| 1568 | Standard_Boolean VT_ProcessButton1Press (Standard_Integer , |
| 1569 | const char** theArgVec, |
| 1570 | Standard_Boolean theToPick, |
| 1571 | Standard_Boolean theIsShift) |
| 1572 | { |
| 1573 | if (theToPick) |
| 1574 | { |
| 1575 | Standard_Real X, Y, Z; |
| 1576 | ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z); |
| 1577 | |
| 1578 | Draw::Set (theArgVec[1], X); |
| 1579 | Draw::Set (theArgVec[2], Y); |
| 1580 | Draw::Set (theArgVec[3], Z); |
| 1581 | } |
| 1582 | |
| 1583 | if (theIsShift) |
| 1584 | { |
| 1585 | ViewerTest::CurrentEventManager()->ShiftSelect(); |
| 1586 | } |
| 1587 | else |
| 1588 | { |
| 1589 | ViewerTest::CurrentEventManager()->Select(); |
| 1590 | } |
| 1591 | |
| 1592 | return Standard_False; |
| 1593 | } |
| 1594 | |
| 1595 | //============================================================================== |
| 1596 | //function : VT_ProcessButton1Release |
| 1597 | //purpose : End selecting |
| 1598 | //============================================================================== |
| 1599 | void VT_ProcessButton1Release (Standard_Boolean theIsShift) |
| 1600 | { |
| 1601 | if (IsDragged) |
| 1602 | { |
| 1603 | IsDragged = Standard_False; |
| 1604 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); |
| 1605 | if (theIsShift) |
| 1606 | { |
| 1607 | EM->ShiftSelect (X_ButtonPress, Y_ButtonPress, |
| 1608 | X_Motion, Y_Motion); |
| 1609 | } |
| 1610 | else |
| 1611 | { |
| 1612 | EM->Select (X_ButtonPress, Y_ButtonPress, |
| 1613 | X_Motion, Y_Motion); |
| 1614 | } |
| 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | //============================================================================== |
| 1619 | //function : VT_ProcessButton3Press |
| 1620 | //purpose : Start Rotation |
| 1621 | //============================================================================== |
| 1622 | void VT_ProcessButton3Press() |
| 1623 | { |
| 1624 | Start_Rot = 1; |
| 1625 | if (MyHLRIsOn) |
| 1626 | { |
| 1627 | ViewerTest::CurrentView()->SetComputedMode (Standard_False); |
| 1628 | } |
| 1629 | ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress ); |
| 1630 | } |
| 1631 | |
| 1632 | //============================================================================== |
| 1633 | //function : VT_ProcessButton3Release |
| 1634 | //purpose : End rotation |
| 1635 | //============================================================================== |
| 1636 | void VT_ProcessButton3Release() |
| 1637 | { |
| 1638 | if (Start_Rot) |
| 1639 | { |
| 1640 | Start_Rot = 0; |
| 1641 | if (MyHLRIsOn) |
| 1642 | { |
| 1643 | ViewerTest::CurrentView()->SetComputedMode (Standard_True); |
| 1644 | } |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | //============================================================================== |
| 1649 | //function : ProcessZClipMotion |
| 1650 | //purpose : Zoom |
| 1651 | //============================================================================== |
| 1652 | |
| 1653 | void ProcessZClipMotion() |
| 1654 | { |
| 1655 | Handle(V3d_View) a3DView = ViewerTest::CurrentView(); |
| 1656 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { |
| 1657 | |
| 1658 | //Quantity_Length VDX, VDY; |
| 1659 | //a3DView->Size(VDX,VDY); |
| 1660 | //Standard_Real VDZ = a3DView->ZSize(); |
| 1661 | //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ); |
| 1662 | |
| 1663 | Quantity_Length aDx = a3DView->Convert(X_Motion - X_ButtonPress); |
| 1664 | |
| 1665 | // Front = Depth + width/2. |
| 1666 | Standard_Real aDepth = 0.5; |
| 1667 | Standard_Real aWidth = 0.1; |
| 1668 | a3DView->ZClipping(aDepth,aWidth); |
| 1669 | |
| 1670 | aDepth += aDx; |
| 1671 | |
| 1672 | //printf("dx %lf Depth %lf Width %lf\n", dx, D, W); |
| 1673 | |
| 1674 | a3DView->SetZClippingDepth(aDepth); |
| 1675 | |
| 1676 | a3DView->Redraw(); |
| 1677 | |
| 1678 | X_ButtonPress = X_Motion; |
| 1679 | Y_ButtonPress = Y_Motion; |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | //============================================================================== |
| 1684 | //function : ProcessControlButton1Motion |
| 1685 | //purpose : Zoom |
| 1686 | //============================================================================== |
| 1687 | |
| 1688 | #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX) |
| 1689 | static void ProcessControlButton1Motion() |
| 1690 | { |
| 1691 | ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion); |
| 1692 | |
| 1693 | X_ButtonPress = X_Motion; |
| 1694 | Y_ButtonPress = Y_Motion; |
| 1695 | } |
| 1696 | #endif |
| 1697 | |
| 1698 | //============================================================================== |
| 1699 | //function : VT_ProcessControlButton2Motion |
| 1700 | //purpose : Panning |
| 1701 | //============================================================================== |
| 1702 | void VT_ProcessControlButton2Motion() |
| 1703 | { |
| 1704 | Standard_Integer aDx = X_Motion - X_ButtonPress; |
| 1705 | Standard_Integer aDy = Y_Motion - Y_ButtonPress; |
| 1706 | |
| 1707 | aDy = -aDy; // Xwindow Y axis is from top to Bottom |
| 1708 | |
| 1709 | ViewerTest::CurrentView()->Pan (aDx, aDy); |
| 1710 | |
| 1711 | X_ButtonPress = X_Motion; |
| 1712 | Y_ButtonPress = Y_Motion; |
| 1713 | } |
| 1714 | |
| 1715 | //============================================================================== |
| 1716 | //function : VT_ProcessControlButton3Motion |
| 1717 | //purpose : Rotation |
| 1718 | //============================================================================== |
| 1719 | void VT_ProcessControlButton3Motion() |
| 1720 | { |
| 1721 | if (Start_Rot) |
| 1722 | { |
| 1723 | ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion); |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | //============================================================================== |
| 1728 | //function : VT_ProcessMotion |
| 1729 | //purpose : |
| 1730 | //============================================================================== |
| 1731 | void VT_ProcessMotion() |
| 1732 | { |
| 1733 | //pre-hilights detected objects at mouse position |
| 1734 | |
| 1735 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); |
| 1736 | EM->MoveTo(X_Motion, Y_Motion); |
| 1737 | } |
| 1738 | |
| 1739 | |
| 1740 | void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix) |
| 1741 | { |
| 1742 | Xpix = X_Motion;Ypix=Y_Motion; |
| 1743 | } |
| 1744 | |
| 1745 | //============================================================================== |
| 1746 | //function : ViewProject: implements VAxo, VTop, VLeft, ... |
| 1747 | //purpose : Switches to an axonometric, top, left and other views |
| 1748 | //============================================================================== |
| 1749 | |
| 1750 | static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori) |
| 1751 | { |
| 1752 | if ( ViewerTest::CurrentView().IsNull() ) |
| 1753 | { |
| 1754 | di<<"Call vinit before this command, please"<<"\n"; |
| 1755 | return 1; |
| 1756 | } |
| 1757 | |
| 1758 | ViewerTest::CurrentView()->SetProj(ori); |
| 1759 | return 0; |
| 1760 | } |
| 1761 | |
| 1762 | //============================================================================== |
| 1763 | //function : VAxo |
| 1764 | //purpose : Switch to an Axonometric view |
| 1765 | //Draw arg : No args |
| 1766 | //============================================================================== |
| 1767 | |
| 1768 | static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** ) |
| 1769 | { |
| 1770 | return ViewProject(di, V3d_XposYnegZpos); |
| 1771 | } |
| 1772 | |
| 1773 | //============================================================================== |
| 1774 | //function : VTop |
| 1775 | //purpose : Switch to a Top View |
| 1776 | //Draw arg : No args |
| 1777 | //============================================================================== |
| 1778 | |
| 1779 | static int VTop(Draw_Interpretor& di, Standard_Integer , const char** ) |
| 1780 | { |
| 1781 | return ViewProject(di, V3d_Zpos); |
| 1782 | } |
| 1783 | |
| 1784 | //============================================================================== |
| 1785 | //function : VBottom |
| 1786 | //purpose : Switch to a Bottom View |
| 1787 | //Draw arg : No args |
| 1788 | //============================================================================== |
| 1789 | |
| 1790 | static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** ) |
| 1791 | { |
| 1792 | return ViewProject(di, V3d_Zneg); |
| 1793 | } |
| 1794 | |
| 1795 | //============================================================================== |
| 1796 | //function : VLeft |
| 1797 | //purpose : Switch to a Left View |
| 1798 | //Draw arg : No args |
| 1799 | //============================================================================== |
| 1800 | |
| 1801 | static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** ) |
| 1802 | { |
| 1803 | return ViewProject(di, V3d_Ypos); |
| 1804 | } |
| 1805 | |
| 1806 | //============================================================================== |
| 1807 | //function : VRight |
| 1808 | //purpose : Switch to a Right View |
| 1809 | //Draw arg : No args |
| 1810 | //============================================================================== |
| 1811 | |
| 1812 | static int VRight(Draw_Interpretor& di, Standard_Integer , const char** ) |
| 1813 | { |
| 1814 | return ViewProject(di, V3d_Yneg); |
| 1815 | } |
| 1816 | |
| 1817 | //============================================================================== |
| 1818 | //function : VFront |
| 1819 | //purpose : Switch to a Front View |
| 1820 | //Draw arg : No args |
| 1821 | //============================================================================== |
| 1822 | |
| 1823 | static int VFront(Draw_Interpretor& di, Standard_Integer , const char** ) |
| 1824 | { |
| 1825 | return ViewProject(di, V3d_Xpos); |
| 1826 | } |
| 1827 | |
| 1828 | //============================================================================== |
| 1829 | //function : VBack |
| 1830 | //purpose : Switch to a Back View |
| 1831 | //Draw arg : No args |
| 1832 | //============================================================================== |
| 1833 | |
| 1834 | static int VBack(Draw_Interpretor& di, Standard_Integer , const char** ) |
| 1835 | { |
| 1836 | return ViewProject(di, V3d_Xneg); |
| 1837 | } |
| 1838 | |
| 1839 | //============================================================================== |
| 1840 | //function : VHelp |
| 1841 | //purpose : Dsiplay help on viewer Keyboead and mouse commands |
| 1842 | //Draw arg : No args |
| 1843 | //============================================================================== |
| 1844 | |
| 1845 | static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** ) |
| 1846 | { |
| 1847 | |
| 1848 | di << "Q : Quit the application" << "\n"; |
| 1849 | |
| 1850 | di << "========================="<<"\n"; |
| 1851 | di << "F : FitAll" << "\n"; |
| 1852 | di << "T : TopView" << "\n"; |
| 1853 | di << "B : BottomView" << "\n"; |
| 1854 | di << "R : RightView" << "\n"; |
| 1855 | di << "L : LeftView" << "\n"; |
| 1856 | di << "A : AxonometricView" << "\n"; |
| 1857 | di << "D : ResetView" << "\n"; |
| 1858 | |
| 1859 | di << "========================="<<"\n"; |
| 1860 | di << "S : Shading" << "\n"; |
| 1861 | di << "W : Wireframe" << "\n"; |
| 1862 | di << "H : HidelLineRemoval" << "\n"; |
| 1863 | di << "U : Unset display mode" << "\n"; |
| 1864 | di << "Delete : Remove selection from viewer" << "\n"; |
| 1865 | |
| 1866 | di << "========================="<<"\n"; |
| 1867 | di << "Selection mode "<<"\n"; |
| 1868 | di << "0 : Shape" <<"\n"; |
| 1869 | di << "1 : Vertex" <<"\n"; |
| 1870 | di << "2 : Edge" <<"\n"; |
| 1871 | di << "3 : Wire" <<"\n"; |
| 1872 | di << "4 : Face" <<"\n"; |
| 1873 | di << "5 : Shell" <<"\n"; |
| 1874 | di << "6 : Solid" <<"\n"; |
| 1875 | di << "7 : Compound" <<"\n"; |
| 1876 | |
| 1877 | di << "========================="<<"\n"; |
| 1878 | di << "Z : Switch Z clipping On/Off" << "\n"; |
| 1879 | di << ", : Hilight next detected" << "\n"; |
| 1880 | di << ". : Hilight previous detected" << "\n"; |
| 1881 | |
| 1882 | return 0; |
| 1883 | } |
| 1884 | |
| 1885 | #ifdef WNT |
| 1886 | |
| 1887 | static Standard_Boolean Ppick = 0; |
| 1888 | static Standard_Integer Pargc = 0; |
| 1889 | static const char** Pargv = NULL; |
| 1890 | |
| 1891 | |
| 1892 | static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd, |
| 1893 | UINT Msg, |
| 1894 | WPARAM wParam, |
| 1895 | LPARAM lParam ) |
| 1896 | { |
| 1897 | if (!ViewerTest_myViews.IsEmpty()) { |
| 1898 | |
| 1899 | WPARAM fwKeys = wParam; |
| 1900 | |
| 1901 | switch( Msg ) { |
| 1902 | case WM_CLOSE: |
| 1903 | { |
| 1904 | // Delete view from map of views |
| 1905 | ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd)); |
| 1906 | return 0; |
| 1907 | } |
| 1908 | break; |
| 1909 | case WM_ACTIVATE: |
| 1910 | if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE |
| 1911 | || ViewerTest::CurrentView().IsNull()) |
| 1912 | { |
| 1913 | // Activate inactive window |
| 1914 | if(GetWindowHandle(VT_GetWindow()) != hwnd) |
| 1915 | { |
| 1916 | ActivateView (FindViewIdByWindowHandle(hwnd)); |
| 1917 | } |
| 1918 | } |
| 1919 | break; |
| 1920 | case WM_LBUTTONUP: |
| 1921 | if (!DragFirst) |
| 1922 | { |
| 1923 | HDC hdc = GetDC( hwnd ); |
| 1924 | SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) ); |
| 1925 | SetROP2( hdc, R2_NOT ); |
| 1926 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
| 1927 | ReleaseDC( hwnd, hdc ); |
| 1928 | VT_ProcessButton1Release (fwKeys & MK_SHIFT); |
| 1929 | } |
| 1930 | IsDragged = Standard_False; |
| 1931 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); |
| 1932 | |
| 1933 | case WM_LBUTTONDOWN: |
| 1934 | if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) ) |
| 1935 | { |
| 1936 | IsDragged = Standard_True; |
| 1937 | DragFirst = Standard_True; |
| 1938 | X_ButtonPress = LOWORD(lParam); |
| 1939 | Y_ButtonPress = HIWORD(lParam); |
| 1940 | } |
| 1941 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); |
| 1942 | |
| 1943 | break; |
| 1944 | |
| 1945 | case WM_MOUSEMOVE: |
| 1946 | if( IsDragged ) |
| 1947 | { |
| 1948 | HDC hdc = GetDC( hwnd ); |
| 1949 | |
| 1950 | HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) ); |
| 1951 | SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) ); |
| 1952 | SetROP2( hdc, R2_NOT ); |
| 1953 | |
| 1954 | if( !DragFirst ) |
| 1955 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
| 1956 | |
| 1957 | DragFirst = Standard_False; |
| 1958 | X_Motion = LOWORD(lParam); |
| 1959 | Y_Motion = HIWORD(lParam); |
| 1960 | |
| 1961 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
| 1962 | |
| 1963 | SelectObject( hdc, anObj ); |
| 1964 | |
| 1965 | ReleaseDC( hwnd, hdc ); |
| 1966 | } |
| 1967 | else |
| 1968 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); |
| 1969 | break; |
| 1970 | |
| 1971 | default: |
| 1972 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); |
| 1973 | } |
| 1974 | return 0; |
| 1975 | } |
| 1976 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); |
| 1977 | } |
| 1978 | |
| 1979 | |
| 1980 | static LRESULT WINAPI ViewerWindowProc( HWND hwnd, |
| 1981 | UINT Msg, |
| 1982 | WPARAM wParam, |
| 1983 | LPARAM lParam ) |
| 1984 | { |
| 1985 | static int Up = 1; |
| 1986 | |
| 1987 | if ( !ViewerTest::CurrentView().IsNull() ) { |
| 1988 | PAINTSTRUCT ps; |
| 1989 | |
| 1990 | switch( Msg ) { |
| 1991 | case WM_PAINT: |
| 1992 | BeginPaint(hwnd, &ps); |
| 1993 | EndPaint(hwnd, &ps); |
| 1994 | VT_ProcessExpose(); |
| 1995 | break; |
| 1996 | |
| 1997 | case WM_SIZE: |
| 1998 | VT_ProcessConfigure(); |
| 1999 | break; |
| 2000 | |
| 2001 | case WM_KEYDOWN: |
| 2002 | if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL)) |
| 2003 | { |
| 2004 | char c[2]; |
| 2005 | c[0] = (char) wParam; |
| 2006 | c[1] = '\0'; |
| 2007 | if (wParam == VK_DELETE) |
| 2008 | { |
| 2009 | c[0] = THE_KEY_DELETE; |
| 2010 | } |
| 2011 | // comma |
| 2012 | else if (wParam == VK_OEM_COMMA) |
| 2013 | { |
| 2014 | c[0] = ','; |
| 2015 | } |
| 2016 | // dot |
| 2017 | else if (wParam == VK_OEM_PERIOD) |
| 2018 | { |
| 2019 | c[0] = '.'; |
| 2020 | } |
| 2021 | VT_ProcessKeyPress (c); |
| 2022 | } |
| 2023 | break; |
| 2024 | |
| 2025 | case WM_LBUTTONUP: |
| 2026 | case WM_MBUTTONUP: |
| 2027 | case WM_RBUTTONUP: |
| 2028 | Up = 1; |
| 2029 | VT_ProcessButton3Release(); |
| 2030 | break; |
| 2031 | |
| 2032 | case WM_LBUTTONDOWN: |
| 2033 | case WM_MBUTTONDOWN: |
| 2034 | case WM_RBUTTONDOWN: |
| 2035 | { |
| 2036 | WPARAM fwKeys = wParam; |
| 2037 | |
| 2038 | Up = 0; |
| 2039 | |
| 2040 | X_ButtonPress = LOWORD(lParam); |
| 2041 | Y_ButtonPress = HIWORD(lParam); |
| 2042 | |
| 2043 | if (Msg == WM_LBUTTONDOWN) |
| 2044 | { |
| 2045 | if (fwKeys & MK_CONTROL) |
| 2046 | { |
| 2047 | Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT)); |
| 2048 | } |
| 2049 | else |
| 2050 | { |
| 2051 | VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT)); |
| 2052 | } |
| 2053 | } |
| 2054 | else if (Msg == WM_RBUTTONDOWN) |
| 2055 | { |
| 2056 | // Start rotation |
| 2057 | VT_ProcessButton3Press(); |
| 2058 | } |
| 2059 | } |
| 2060 | break; |
| 2061 | |
| 2062 | case WM_MOUSEMOVE: |
| 2063 | { |
| 2064 | //cout << "\t WM_MOUSEMOVE" << endl; |
| 2065 | WPARAM fwKeys = wParam; |
| 2066 | X_Motion = LOWORD(lParam); |
| 2067 | Y_Motion = HIWORD(lParam); |
| 2068 | |
| 2069 | if ( Up && |
| 2070 | fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) { |
| 2071 | Up = 0; |
| 2072 | X_ButtonPress = LOWORD(lParam); |
| 2073 | Y_ButtonPress = HIWORD(lParam); |
| 2074 | |
| 2075 | if ( fwKeys & MK_RBUTTON ) { |
| 2076 | // Start rotation |
| 2077 | VT_ProcessButton3Press(); |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | if ( fwKeys & MK_CONTROL ) { |
| 2082 | if ( fwKeys & MK_LBUTTON ) { |
| 2083 | ProcessControlButton1Motion(); |
| 2084 | } |
| 2085 | else if ( fwKeys & MK_MBUTTON || |
| 2086 | ((fwKeys&MK_LBUTTON) && |
| 2087 | (fwKeys&MK_RBUTTON) ) ){ |
| 2088 | VT_ProcessControlButton2Motion(); |
| 2089 | } |
| 2090 | else if ( fwKeys & MK_RBUTTON ) { |
| 2091 | VT_ProcessControlButton3Motion(); |
| 2092 | } |
| 2093 | } |
| 2094 | #ifdef BUG |
| 2095 | else if ( fwKeys & MK_SHIFT ) { |
| 2096 | if ( fwKeys & MK_MBUTTON || |
| 2097 | ((fwKeys&MK_LBUTTON) && |
| 2098 | (fwKeys&MK_RBUTTON) ) ) { |
| 2099 | cout << "ProcessZClipMotion()" << endl; |
| 2100 | ProcessZClipMotion(); |
| 2101 | } |
| 2102 | } |
| 2103 | #endif |
| 2104 | else if (GetWindowHandle (VT_GetWindow()) == hwnd) |
| 2105 | { |
| 2106 | if ((fwKeys & MK_MBUTTON |
| 2107 | || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON)))) |
| 2108 | { |
| 2109 | ProcessZClipMotion(); |
| 2110 | } |
| 2111 | else |
| 2112 | { |
| 2113 | VT_ProcessMotion(); |
| 2114 | } |
| 2115 | } |
| 2116 | } |
| 2117 | break; |
| 2118 | |
| 2119 | default: |
| 2120 | return( DefWindowProc( hwnd, Msg, wParam, lParam )); |
| 2121 | } |
| 2122 | return 0L; |
| 2123 | } |
| 2124 | |
| 2125 | return DefWindowProc( hwnd, Msg, wParam, lParam ); |
| 2126 | } |
| 2127 | |
| 2128 | |
| 2129 | |
| 2130 | |
| 2131 | //============================================================================== |
| 2132 | //function : ViewerMainLoop |
| 2133 | //purpose : Get a Event on the view and dispatch it |
| 2134 | //============================================================================== |
| 2135 | |
| 2136 | |
| 2137 | int ViewerMainLoop(Standard_Integer argc, const char** argv) |
| 2138 | { |
| 2139 | Ppick = (argc > 0)? 1 : 0; |
| 2140 | Pargc = argc; |
| 2141 | Pargv = argv; |
| 2142 | |
| 2143 | if ( Ppick ) { |
| 2144 | MSG msg; |
| 2145 | msg.wParam = 1; |
| 2146 | |
| 2147 | cout << "Start picking" << endl; |
| 2148 | |
| 2149 | while ( Ppick == 1 ) { |
| 2150 | // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0 |
| 2151 | if (GetMessage(&msg, NULL, 0, 0) ) { |
| 2152 | TranslateMessage(&msg); |
| 2153 | DispatchMessage(&msg); |
| 2154 | } |
| 2155 | } |
| 2156 | |
| 2157 | cout << "Picking done" << endl; |
| 2158 | } |
| 2159 | |
| 2160 | return Ppick; |
| 2161 | } |
| 2162 | |
| 2163 | #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
| 2164 | |
| 2165 | int min( int a, int b ) |
| 2166 | { |
| 2167 | if( a<b ) |
| 2168 | return a; |
| 2169 | else |
| 2170 | return b; |
| 2171 | } |
| 2172 | |
| 2173 | int max( int a, int b ) |
| 2174 | { |
| 2175 | if( a>b ) |
| 2176 | return a; |
| 2177 | else |
| 2178 | return b; |
| 2179 | } |
| 2180 | |
| 2181 | int ViewerMainLoop(Standard_Integer argc, const char** argv) |
| 2182 | |
| 2183 | { |
| 2184 | static XEvent aReport; |
| 2185 | Standard_Boolean pick = argc > 0; |
| 2186 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); |
| 2187 | XNextEvent (aDisplay, &aReport); |
| 2188 | |
| 2189 | // Handle event for the chosen display connection |
| 2190 | switch (aReport.type) { |
| 2191 | case ClientMessage: |
| 2192 | { |
| 2193 | if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW)) |
| 2194 | { |
| 2195 | // Close the window |
| 2196 | ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window)); |
| 2197 | } |
| 2198 | } |
| 2199 | return 0; |
| 2200 | case FocusIn: |
| 2201 | { |
| 2202 | // Activate inactive view |
| 2203 | Window aWindow = GetWindowHandle(VT_GetWindow()); |
| 2204 | if(aWindow != aReport.xfocus.window) |
| 2205 | { |
| 2206 | ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window)); |
| 2207 | } |
| 2208 | } |
| 2209 | break; |
| 2210 | case Expose: |
| 2211 | { |
| 2212 | VT_ProcessExpose(); |
| 2213 | } |
| 2214 | break; |
| 2215 | case ConfigureNotify: |
| 2216 | { |
| 2217 | VT_ProcessConfigure(); |
| 2218 | } |
| 2219 | break; |
| 2220 | case KeyPress: |
| 2221 | { |
| 2222 | |
| 2223 | KeySym ks_ret ; |
| 2224 | char buf_ret[11] ; |
| 2225 | int ret_len ; |
| 2226 | XComposeStatus status_in_out; |
| 2227 | |
| 2228 | ret_len = XLookupString( ( XKeyEvent *)&aReport , |
| 2229 | (char *) buf_ret , 10 , |
| 2230 | &ks_ret , &status_in_out ) ; |
| 2231 | |
| 2232 | |
| 2233 | buf_ret[ret_len] = '\0' ; |
| 2234 | |
| 2235 | if (ret_len) |
| 2236 | { |
| 2237 | VT_ProcessKeyPress (buf_ret); |
| 2238 | } |
| 2239 | } |
| 2240 | break; |
| 2241 | case ButtonPress: |
| 2242 | { |
| 2243 | X_ButtonPress = aReport.xbutton.x; |
| 2244 | Y_ButtonPress = aReport.xbutton.y; |
| 2245 | |
| 2246 | if (aReport.xbutton.button == Button1) |
| 2247 | { |
| 2248 | if (aReport.xbutton.state & ControlMask) |
| 2249 | { |
| 2250 | pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask)); |
| 2251 | } |
| 2252 | else |
| 2253 | { |
| 2254 | IsDragged = Standard_True; |
| 2255 | DragFirst = Standard_True; |
| 2256 | } |
| 2257 | } |
| 2258 | else if (aReport.xbutton.button == Button3) |
| 2259 | { |
| 2260 | // Start rotation |
| 2261 | VT_ProcessButton3Press(); |
| 2262 | } |
| 2263 | } |
| 2264 | break; |
| 2265 | case ButtonRelease: |
| 2266 | { |
| 2267 | if( IsDragged ) |
| 2268 | { |
| 2269 | if( !DragFirst ) |
| 2270 | { |
| 2271 | Aspect_Handle aWindow = VT_GetWindow()->XWindow(); |
| 2272 | GC gc = XCreateGC( aDisplay, aWindow, 0, 0 ); |
| 2273 | XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) ); |
| 2274 | } |
| 2275 | |
| 2276 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); |
| 2277 | if( aContext.IsNull() ) |
| 2278 | { |
| 2279 | cout << "The context is null. Please use vinit before createmesh" << endl; |
| 2280 | return 0; |
| 2281 | } |
| 2282 | |
| 2283 | Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask ); |
| 2284 | if( aReport.xbutton.button==1 ) |
| 2285 | if( DragFirst ) |
| 2286 | if( ShiftPressed ) |
| 2287 | { |
| 2288 | aContext->ShiftSelect(); |
| 2289 | } |
| 2290 | else |
| 2291 | { |
| 2292 | aContext->Select(); |
| 2293 | } |
| 2294 | else |
| 2295 | if( ShiftPressed ) |
| 2296 | { |
| 2297 | aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), |
| 2298 | max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), |
| 2299 | ViewerTest::CurrentView()); |
| 2300 | } |
| 2301 | else |
| 2302 | { |
| 2303 | aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), |
| 2304 | max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), |
| 2305 | ViewerTest::CurrentView() ); |
| 2306 | } |
| 2307 | else |
| 2308 | VT_ProcessButton3Release(); |
| 2309 | |
| 2310 | IsDragged = Standard_False; |
| 2311 | } |
| 2312 | else |
| 2313 | VT_ProcessButton3Release(); |
| 2314 | } |
| 2315 | break; |
| 2316 | case MotionNotify: |
| 2317 | { |
| 2318 | if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window) |
| 2319 | { |
| 2320 | break; |
| 2321 | } |
| 2322 | if( IsDragged ) |
| 2323 | { |
| 2324 | Aspect_Handle aWindow = VT_GetWindow()->XWindow(); |
| 2325 | GC gc = XCreateGC( aDisplay, aWindow, 0, 0 ); |
| 2326 | XSetFunction( aDisplay, gc, GXinvert ); |
| 2327 | |
| 2328 | if( !DragFirst ) |
| 2329 | XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) ); |
| 2330 | |
| 2331 | X_Motion = aReport.xmotion.x; |
| 2332 | Y_Motion = aReport.xmotion.y; |
| 2333 | DragFirst = Standard_False; |
| 2334 | |
| 2335 | XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) ); |
| 2336 | } |
| 2337 | else |
| 2338 | { |
| 2339 | X_Motion = aReport.xmotion.x; |
| 2340 | Y_Motion = aReport.xmotion.y; |
| 2341 | |
| 2342 | // remove all the ButtonMotionMaskr |
| 2343 | while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ; |
| 2344 | |
| 2345 | if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) { |
| 2346 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { |
| 2347 | |
| 2348 | Quantity_Length VDX, VDY; |
| 2349 | |
| 2350 | ViewerTest::CurrentView()->Size(VDX,VDY); |
| 2351 | Standard_Real VDZ =0 ; |
| 2352 | VDZ = ViewerTest::CurrentView()->ZSize(); |
| 2353 | |
| 2354 | printf("%f,%f,%f\n", VDX, VDY, VDZ); |
| 2355 | |
| 2356 | Quantity_Length dx = 0 ; |
| 2357 | dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress); |
| 2358 | |
| 2359 | cout << dx << endl; |
| 2360 | |
| 2361 | dx = dx / VDX * VDZ; |
| 2362 | |
| 2363 | cout << dx << endl; |
| 2364 | |
| 2365 | ViewerTest::CurrentView()->Redraw(); |
| 2366 | } |
| 2367 | } |
| 2368 | |
| 2369 | if ( aReport.xmotion.state & ControlMask ) { |
| 2370 | if ( aReport.xmotion.state & Button1Mask ) { |
| 2371 | ProcessControlButton1Motion(); |
| 2372 | } |
| 2373 | else if ( aReport.xmotion.state & Button2Mask ) { |
| 2374 | VT_ProcessControlButton2Motion(); |
| 2375 | } |
| 2376 | else if ( aReport.xmotion.state & Button3Mask ) { |
| 2377 | VT_ProcessControlButton3Motion(); |
| 2378 | } |
| 2379 | } |
| 2380 | else |
| 2381 | { |
| 2382 | VT_ProcessMotion(); |
| 2383 | } |
| 2384 | } |
| 2385 | } |
| 2386 | break; |
| 2387 | } |
| 2388 | return pick; |
| 2389 | } |
| 2390 | |
| 2391 | //============================================================================== |
| 2392 | //function : VProcessEvents |
| 2393 | //purpose : call by Tk_CreateFileHandler() to be able to manage the |
| 2394 | // event in the Viewer window |
| 2395 | //============================================================================== |
| 2396 | |
| 2397 | static void VProcessEvents(ClientData,int) |
| 2398 | { |
| 2399 | NCollection_Vector<int> anEventNumbers; |
| 2400 | // Get number of messages from every display |
| 2401 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator |
| 2402 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next()) |
| 2403 | { |
| 2404 | anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay())); |
| 2405 | } |
| 2406 | // Handle events for every display |
| 2407 | int anEventIter = 0; |
| 2408 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator |
| 2409 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++) |
| 2410 | { |
| 2411 | for (int i = 0; i < anEventNumbers.Value(anEventIter) && |
| 2412 | XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i) |
| 2413 | { |
| 2414 | SetDisplayConnection (anIter.Key2()->GetDisplayConnection()); |
| 2415 | int anEventResult = ViewerMainLoop( 0, NULL); |
| 2416 | // If window is closed or context was not found finish current event processing loop |
| 2417 | if (!anEventResult) |
| 2418 | return; |
| 2419 | } |
| 2420 | } |
| 2421 | |
| 2422 | SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection()); |
| 2423 | |
| 2424 | } |
| 2425 | #endif |
| 2426 | |
| 2427 | //============================================================================== |
| 2428 | //function : OSWindowSetup |
| 2429 | //purpose : Setup for the X11 window to be able to cath the event |
| 2430 | //============================================================================== |
| 2431 | |
| 2432 | |
| 2433 | static void OSWindowSetup() |
| 2434 | { |
| 2435 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
| 2436 | // X11 |
| 2437 | |
| 2438 | Window window = VT_GetWindow()->XWindow(); |
| 2439 | SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
| 2440 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); |
| 2441 | XSynchronize(aDisplay, 1); |
| 2442 | |
| 2443 | // X11 : For keyboard on SUN |
| 2444 | XWMHints wmhints; |
| 2445 | wmhints.flags = InputHint; |
| 2446 | wmhints.input = 1; |
| 2447 | |
| 2448 | XSetWMHints( aDisplay, window, &wmhints); |
| 2449 | |
| 2450 | XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | |
| 2451 | ButtonPressMask | ButtonReleaseMask | |
| 2452 | StructureNotifyMask | |
| 2453 | PointerMotionMask | |
| 2454 | Button1MotionMask | Button2MotionMask | |
| 2455 | Button3MotionMask | FocusChangeMask |
| 2456 | ); |
| 2457 | Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW); |
| 2458 | XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1); |
| 2459 | |
| 2460 | XSynchronize(aDisplay, 0); |
| 2461 | |
| 2462 | #else |
| 2463 | // WNT |
| 2464 | #endif |
| 2465 | |
| 2466 | } |
| 2467 | |
| 2468 | //============================================================================== |
| 2469 | //function : VFit |
| 2470 | |
| 2471 | //purpose : Fitall, no DRAW arguments |
| 2472 | //Draw arg : No args |
| 2473 | //============================================================================== |
| 2474 | |
| 2475 | static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgc, const char** theArgv) |
| 2476 | { |
| 2477 | if (theArgc > 2) |
| 2478 | { |
| 2479 | std::cout << "Wrong number of arguments! Use: vfit [-selected]" << std::endl; |
| 2480 | } |
| 2481 | |
| 2482 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 2483 | |
| 2484 | if (theArgc == 2) |
| 2485 | { |
| 2486 | TCollection_AsciiString anArg (theArgv[1]); |
| 2487 | anArg.LowerCase(); |
| 2488 | if (anArg == "-selected") |
| 2489 | { |
| 2490 | ViewerTest::GetAISContext()->FitSelected (aView); |
| 2491 | return 0; |
| 2492 | } |
| 2493 | } |
| 2494 | if (aView.IsNull() == Standard_False) { |
| 2495 | |
| 2496 | aView->FitAll(); |
| 2497 | } |
| 2498 | return 0; |
| 2499 | } |
| 2500 | |
| 2501 | //======================================================================= |
| 2502 | //function : VFitArea |
| 2503 | //purpose : Fit view to show area located between two points |
| 2504 | // : given in world 2D or 3D coordinates. |
| 2505 | //======================================================================= |
| 2506 | static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) |
| 2507 | { |
| 2508 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 2509 | if (aView.IsNull()) |
| 2510 | { |
| 2511 | std::cerr << theArgVec[0] << "Error: No active view.\n"; |
| 2512 | return 1; |
| 2513 | } |
| 2514 | |
| 2515 | // Parse arguments. |
| 2516 | gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0); |
| 2517 | gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0); |
| 2518 | |
| 2519 | if (theArgNb == 5) |
| 2520 | { |
| 2521 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); |
| 2522 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); |
| 2523 | aWorldPnt2.SetX (Draw::Atof (theArgVec[3])); |
| 2524 | aWorldPnt2.SetY (Draw::Atof (theArgVec[4])); |
| 2525 | } |
| 2526 | else if (theArgNb == 7) |
| 2527 | { |
| 2528 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); |
| 2529 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); |
| 2530 | aWorldPnt1.SetZ (Draw::Atof (theArgVec[3])); |
| 2531 | aWorldPnt2.SetX (Draw::Atof (theArgVec[4])); |
| 2532 | aWorldPnt2.SetY (Draw::Atof (theArgVec[5])); |
| 2533 | aWorldPnt2.SetZ (Draw::Atof (theArgVec[6])); |
| 2534 | } |
| 2535 | else |
| 2536 | { |
| 2537 | std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n"; |
| 2538 | theDI.PrintHelp(theArgVec[0]); |
| 2539 | return 1; |
| 2540 | } |
| 2541 | |
| 2542 | // Convert model coordinates to view space |
| 2543 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); |
| 2544 | gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1); |
| 2545 | gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2); |
| 2546 | |
| 2547 | // Determine fit area |
| 2548 | gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y())); |
| 2549 | gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y())); |
| 2550 | |
| 2551 | Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner); |
| 2552 | |
| 2553 | if (aDiagonal < Precision::Confusion()) |
| 2554 | { |
| 2555 | std::cerr << theArgVec[0] << "Error: view area is too small.\n"; |
| 2556 | return 1; |
| 2557 | } |
| 2558 | |
| 2559 | aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y()); |
| 2560 | return 0; |
| 2561 | } |
| 2562 | |
| 2563 | //============================================================================== |
| 2564 | //function : VZFit |
| 2565 | //purpose : ZFitall, no DRAW arguments |
| 2566 | //Draw arg : No args |
| 2567 | //============================================================================== |
| 2568 | static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) |
| 2569 | { |
| 2570 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
| 2571 | |
| 2572 | if (aCurrentView.IsNull()) |
| 2573 | { |
| 2574 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
| 2575 | return 1; |
| 2576 | } |
| 2577 | |
| 2578 | if (theArgsNb == 1) |
| 2579 | { |
| 2580 | aCurrentView->View()->ZFitAll(); |
| 2581 | aCurrentView->Redraw(); |
| 2582 | return 0; |
| 2583 | } |
| 2584 | |
| 2585 | Standard_Real aScale = 1.0; |
| 2586 | |
| 2587 | if (theArgsNb >= 2) |
| 2588 | { |
| 2589 | aScale = Draw::Atoi (theArgVec[1]); |
| 2590 | } |
| 2591 | |
| 2592 | aCurrentView->View()->ZFitAll (aScale); |
| 2593 | aCurrentView->Redraw(); |
| 2594 | |
| 2595 | return 0; |
| 2596 | } |
| 2597 | |
| 2598 | //============================================================================== |
| 2599 | //function : VRepaint |
| 2600 | //purpose : |
| 2601 | //============================================================================== |
| 2602 | static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** ) |
| 2603 | { |
| 2604 | Handle(V3d_View) V = ViewerTest::CurrentView(); |
| 2605 | if ( !V.IsNull() ) V->Redraw(); return 0; |
| 2606 | } |
| 2607 | |
| 2608 | //============================================================================== |
| 2609 | //function : VClear |
| 2610 | //purpose : Remove all the object from the viewer |
| 2611 | //Draw arg : No args |
| 2612 | //============================================================================== |
| 2613 | |
| 2614 | static int VClear(Draw_Interpretor& , Standard_Integer , const char** ) |
| 2615 | { |
| 2616 | Handle(V3d_View) V = ViewerTest::CurrentView(); |
| 2617 | if(!V.IsNull()) |
| 2618 | ViewerTest::Clear(); |
| 2619 | return 0; |
| 2620 | } |
| 2621 | |
| 2622 | //============================================================================== |
| 2623 | //function : VPick |
| 2624 | //purpose : |
| 2625 | //============================================================================== |
| 2626 | |
| 2627 | static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 2628 | { if (ViewerTest::CurrentView().IsNull() ) return 1; |
| 2629 | |
| 2630 | if ( argc < 4 ) { |
| 2631 | di << argv[0] << "Invalid number of arguments" << "\n"; |
| 2632 | return 1; |
| 2633 | } |
| 2634 | |
| 2635 | while (ViewerMainLoop( argc, argv)) { |
| 2636 | } |
| 2637 | |
| 2638 | return 0; |
| 2639 | } |
| 2640 | |
| 2641 | //============================================================================== |
| 2642 | //function : VSetBg |
| 2643 | //purpose : Load image as background |
| 2644 | //============================================================================== |
| 2645 | |
| 2646 | static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 2647 | { |
| 2648 | if (argc < 2 || argc > 3) |
| 2649 | { |
| 2650 | di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n"; |
| 2651 | di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n"; |
| 2652 | return 1; |
| 2653 | } |
| 2654 | |
| 2655 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); |
| 2656 | if(AISContext.IsNull()) |
| 2657 | { |
| 2658 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 2659 | return 1; |
| 2660 | } |
| 2661 | |
| 2662 | Aspect_FillMethod aFillType = Aspect_FM_CENTERED; |
| 2663 | if (argc == 3) |
| 2664 | { |
| 2665 | const char* szType = argv[2]; |
| 2666 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; |
| 2667 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; |
| 2668 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; |
| 2669 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; |
| 2670 | else |
| 2671 | { |
| 2672 | di << "Wrong fill type : " << szType << "\n"; |
| 2673 | di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; |
| 2674 | return 1; |
| 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
| 2679 | V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True); |
| 2680 | |
| 2681 | return 0; |
| 2682 | } |
| 2683 | |
| 2684 | //============================================================================== |
| 2685 | //function : VSetBgMode |
| 2686 | //purpose : Change background image fill type |
| 2687 | //============================================================================== |
| 2688 | |
| 2689 | static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 2690 | { |
| 2691 | if (argc != 2) |
| 2692 | { |
| 2693 | di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n"; |
| 2694 | di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; |
| 2695 | return 1; |
| 2696 | } |
| 2697 | |
| 2698 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); |
| 2699 | if(AISContext.IsNull()) |
| 2700 | { |
| 2701 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 2702 | return 1; |
| 2703 | } |
| 2704 | Aspect_FillMethod aFillType = Aspect_FM_NONE; |
| 2705 | const char* szType = argv[1]; |
| 2706 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; |
| 2707 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; |
| 2708 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; |
| 2709 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; |
| 2710 | else |
| 2711 | { |
| 2712 | di << "Wrong fill type : " << szType << "\n"; |
| 2713 | di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; |
| 2714 | return 1; |
| 2715 | } |
| 2716 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
| 2717 | V3dView->SetBgImageStyle(aFillType, Standard_True); |
| 2718 | return 0; |
| 2719 | } |
| 2720 | |
| 2721 | //============================================================================== |
| 2722 | //function : VSetGradientBg |
| 2723 | //purpose : Mount gradient background |
| 2724 | //============================================================================== |
| 2725 | static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 2726 | { |
| 2727 | if (argc != 8 ) |
| 2728 | { |
| 2729 | di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n"; |
| 2730 | di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n"; |
| 2731 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; |
| 2732 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; |
| 2733 | return 1; |
| 2734 | } |
| 2735 | |
| 2736 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); |
| 2737 | if(AISContext.IsNull()) |
| 2738 | { |
| 2739 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 2740 | return 1; |
| 2741 | } |
| 2742 | if (argc == 8) |
| 2743 | { |
| 2744 | |
| 2745 | Standard_Real R1 = Draw::Atof(argv[1])/255.; |
| 2746 | Standard_Real G1 = Draw::Atof(argv[2])/255.; |
| 2747 | Standard_Real B1 = Draw::Atof(argv[3])/255.; |
| 2748 | Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB); |
| 2749 | |
| 2750 | Standard_Real R2 = Draw::Atof(argv[4])/255.; |
| 2751 | Standard_Real G2 = Draw::Atof(argv[5])/255.; |
| 2752 | Standard_Real B2 = Draw::Atof(argv[6])/255.; |
| 2753 | |
| 2754 | Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB); |
| 2755 | int aType = Draw::Atoi(argv[7]); |
| 2756 | if( aType < 0 || aType > 8 ) |
| 2757 | { |
| 2758 | di << "Wrong fill type " << "\n"; |
| 2759 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; |
| 2760 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; |
| 2761 | return 1; |
| 2762 | } |
| 2763 | |
| 2764 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); |
| 2765 | |
| 2766 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
| 2767 | V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1); |
| 2768 | } |
| 2769 | |
| 2770 | return 0; |
| 2771 | } |
| 2772 | |
| 2773 | //============================================================================== |
| 2774 | //function : VSetGradientBgMode |
| 2775 | //purpose : Change gradient background fill style |
| 2776 | //============================================================================== |
| 2777 | static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 2778 | { |
| 2779 | if (argc != 2 ) |
| 2780 | { |
| 2781 | di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n"; |
| 2782 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; |
| 2783 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; |
| 2784 | return 1; |
| 2785 | } |
| 2786 | |
| 2787 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); |
| 2788 | if(AISContext.IsNull()) |
| 2789 | { |
| 2790 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 2791 | return 1; |
| 2792 | } |
| 2793 | if (argc == 2) |
| 2794 | { |
| 2795 | int aType = Draw::Atoi(argv[1]); |
| 2796 | if( aType < 0 || aType > 8 ) |
| 2797 | { |
| 2798 | di << "Wrong fill type " << "\n"; |
| 2799 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; |
| 2800 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; |
| 2801 | return 1; |
| 2802 | } |
| 2803 | |
| 2804 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); |
| 2805 | |
| 2806 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
| 2807 | V3dView->SetBgGradientStyle( aMethod, 1 ); |
| 2808 | } |
| 2809 | |
| 2810 | return 0; |
| 2811 | } |
| 2812 | |
| 2813 | //============================================================================== |
| 2814 | //function : VSetColorBg |
| 2815 | //purpose : Set color background |
| 2816 | //============================================================================== |
| 2817 | static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 2818 | { |
| 2819 | if (argc != 4 ) |
| 2820 | { |
| 2821 | di << "Usage : " << argv[0] << " R G B : Set color background" << "\n"; |
| 2822 | di << "R,G,B = [0..255]" << "\n"; |
| 2823 | return 1; |
| 2824 | } |
| 2825 | |
| 2826 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); |
| 2827 | if(AISContext.IsNull()) |
| 2828 | { |
| 2829 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 2830 | return 1; |
| 2831 | } |
| 2832 | if (argc == 4) |
| 2833 | { |
| 2834 | |
| 2835 | Standard_Real R = Draw::Atof(argv[1])/255.; |
| 2836 | Standard_Real G = Draw::Atof(argv[2])/255.; |
| 2837 | Standard_Real B = Draw::Atof(argv[3])/255.; |
| 2838 | Quantity_Color aColor(R,G,B,Quantity_TOC_RGB); |
| 2839 | |
| 2840 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
| 2841 | V3dView->SetBackgroundColor( aColor ); |
| 2842 | V3dView->Update(); |
| 2843 | } |
| 2844 | |
| 2845 | return 0; |
| 2846 | } |
| 2847 | |
| 2848 | //============================================================================== |
| 2849 | //function : VScale |
| 2850 | //purpose : View Scaling |
| 2851 | //============================================================================== |
| 2852 | |
| 2853 | static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 2854 | { |
| 2855 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
| 2856 | if ( V3dView.IsNull() ) return 1; |
| 2857 | |
| 2858 | if ( argc != 4 ) { |
| 2859 | di << argv[0] << "Invalid number of arguments" << "\n"; |
| 2860 | return 1; |
| 2861 | } |
| 2862 | V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) ); |
| 2863 | return 0; |
| 2864 | } |
| 2865 | //============================================================================== |
| 2866 | //function : VZBuffTrihedron |
| 2867 | //purpose : |
| 2868 | //============================================================================== |
| 2869 | |
| 2870 | static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/, |
| 2871 | Standard_Integer theArgNb, |
| 2872 | const char** theArgVec) |
| 2873 | { |
| 2874 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 2875 | if (aView.IsNull()) |
| 2876 | { |
| 2877 | std::cout << "Error: no active viewer!\n"; |
| 2878 | return 1; |
| 2879 | } |
| 2880 | |
| 2881 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
| 2882 | |
| 2883 | Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER; |
| 2884 | V3d_TypeOfVisualization aVisType = V3d_ZBUFFER; |
| 2885 | Quantity_Color aLabelsColor = Quantity_NOC_WHITE; |
| 2886 | Quantity_Color anArrowColorX = Quantity_NOC_RED; |
| 2887 | Quantity_Color anArrowColorY = Quantity_NOC_GREEN; |
| 2888 | Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1; |
| 2889 | Standard_Real aScale = 0.1; |
| 2890 | Standard_Real aSizeRatio = 0.8; |
| 2891 | Standard_Real anArrowDiam = 0.05; |
| 2892 | Standard_Integer aNbFacets = 12; |
| 2893 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
| 2894 | { |
| 2895 | Standard_CString anArg = theArgVec[anArgIter]; |
| 2896 | TCollection_AsciiString aFlag (anArg); |
| 2897 | aFlag.LowerCase(); |
| 2898 | if (anUpdateTool.parseRedrawMode (aFlag)) |
| 2899 | { |
| 2900 | continue; |
| 2901 | } |
| 2902 | else if (aFlag == "-on") |
| 2903 | { |
| 2904 | continue; |
| 2905 | } |
| 2906 | else if (aFlag == "-off") |
| 2907 | { |
| 2908 | aView->TriedronErase(); |
| 2909 | return 0; |
| 2910 | } |
| 2911 | else if (aFlag == "-pos" |
| 2912 | || aFlag == "-position" |
| 2913 | || aFlag == "-corner") |
| 2914 | { |
| 2915 | if (++anArgIter >= theArgNb) |
| 2916 | { |
| 2917 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
| 2918 | return 1; |
| 2919 | } |
| 2920 | |
| 2921 | TCollection_AsciiString aPosName (theArgVec[anArgIter]); |
| 2922 | aPosName.LowerCase(); |
| 2923 | if (aPosName == "center") |
| 2924 | { |
| 2925 | aPosition = Aspect_TOTP_CENTER; |
| 2926 | } |
| 2927 | else if (aPosName == "left_lower" |
| 2928 | || aPosName == "lower_left" |
| 2929 | || aPosName == "leftlower" |
| 2930 | || aPosName == "lowerleft") |
| 2931 | { |
| 2932 | aPosition = Aspect_TOTP_LEFT_LOWER; |
| 2933 | } |
| 2934 | else if (aPosName == "left_upper" |
| 2935 | || aPosName == "upper_left" |
| 2936 | || aPosName == "leftupper" |
| 2937 | || aPosName == "upperleft") |
| 2938 | { |
| 2939 | aPosition = Aspect_TOTP_LEFT_UPPER; |
| 2940 | } |
| 2941 | else if (aPosName == "right_lower" |
| 2942 | || aPosName == "lower_right" |
| 2943 | || aPosName == "rightlower" |
| 2944 | || aPosName == "lowerright") |
| 2945 | { |
| 2946 | aPosition = Aspect_TOTP_RIGHT_LOWER; |
| 2947 | } |
| 2948 | else if (aPosName == "right_upper" |
| 2949 | || aPosName == "upper_right" |
| 2950 | || aPosName == "rightupper" |
| 2951 | || aPosName == "upperright") |
| 2952 | { |
| 2953 | aPosition = Aspect_TOTP_RIGHT_UPPER; |
| 2954 | } |
| 2955 | else |
| 2956 | { |
| 2957 | std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n"; |
| 2958 | return 1; |
| 2959 | } |
| 2960 | } |
| 2961 | else if (aFlag == "-type") |
| 2962 | { |
| 2963 | if (++anArgIter >= theArgNb) |
| 2964 | { |
| 2965 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
| 2966 | return 1; |
| 2967 | } |
| 2968 | |
| 2969 | TCollection_AsciiString aTypeName (theArgVec[anArgIter]); |
| 2970 | aTypeName.LowerCase(); |
| 2971 | if (aTypeName == "wireframe" |
| 2972 | || aTypeName == "wire") |
| 2973 | { |
| 2974 | aVisType = V3d_WIREFRAME; |
| 2975 | } |
| 2976 | else if (aTypeName == "zbuffer" |
| 2977 | || aTypeName == "shaded") |
| 2978 | { |
| 2979 | aVisType = V3d_ZBUFFER; |
| 2980 | } |
| 2981 | else |
| 2982 | { |
| 2983 | std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n"; |
| 2984 | } |
| 2985 | } |
| 2986 | else if (aFlag == "-scale") |
| 2987 | { |
| 2988 | if (++anArgIter >= theArgNb) |
| 2989 | { |
| 2990 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
| 2991 | return 1; |
| 2992 | } |
| 2993 | |
| 2994 | aScale = Draw::Atof (theArgVec[anArgIter]); |
| 2995 | } |
| 2996 | else if (aFlag == "-size" |
| 2997 | || aFlag == "-sizeratio") |
| 2998 | { |
| 2999 | if (++anArgIter >= theArgNb) |
| 3000 | { |
| 3001 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
| 3002 | return 1; |
| 3003 | } |
| 3004 | |
| 3005 | aSizeRatio = Draw::Atof (theArgVec[anArgIter]); |
| 3006 | } |
| 3007 | else if (aFlag == "-arrowdiam" |
| 3008 | || aFlag == "-arrowdiameter") |
| 3009 | { |
| 3010 | if (++anArgIter >= theArgNb) |
| 3011 | { |
| 3012 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
| 3013 | return 1; |
| 3014 | } |
| 3015 | |
| 3016 | anArrowDiam = Draw::Atof (theArgVec[anArgIter]); |
| 3017 | } |
| 3018 | else if (aFlag == "-nbfacets") |
| 3019 | { |
| 3020 | if (++anArgIter >= theArgNb) |
| 3021 | { |
| 3022 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
| 3023 | return 1; |
| 3024 | } |
| 3025 | |
| 3026 | aNbFacets = Draw::Atoi (theArgVec[anArgIter]); |
| 3027 | } |
| 3028 | else if (aFlag == "-colorlabel" |
| 3029 | || aFlag == "-colorlabels") |
| 3030 | { |
| 3031 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
| 3032 | theArgVec + anArgIter + 1, |
| 3033 | aLabelsColor); |
| 3034 | if (aNbParsed == 0) |
| 3035 | { |
| 3036 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
| 3037 | return 1; |
| 3038 | } |
| 3039 | anArgIter += aNbParsed; |
| 3040 | } |
| 3041 | else if (aFlag == "-colorarrowx") |
| 3042 | { |
| 3043 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
| 3044 | theArgVec + anArgIter + 1, |
| 3045 | anArrowColorX); |
| 3046 | if (aNbParsed == 0) |
| 3047 | { |
| 3048 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
| 3049 | return 1; |
| 3050 | } |
| 3051 | anArgIter += aNbParsed; |
| 3052 | } |
| 3053 | else if (aFlag == "-colorarrowy") |
| 3054 | { |
| 3055 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
| 3056 | theArgVec + anArgIter + 1, |
| 3057 | anArrowColorY); |
| 3058 | if (aNbParsed == 0) |
| 3059 | { |
| 3060 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
| 3061 | return 1; |
| 3062 | } |
| 3063 | anArgIter += aNbParsed; |
| 3064 | } |
| 3065 | else if (aFlag == "-colorarrowz") |
| 3066 | { |
| 3067 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
| 3068 | theArgVec + anArgIter + 1, |
| 3069 | anArrowColorZ); |
| 3070 | if (aNbParsed == 0) |
| 3071 | { |
| 3072 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
| 3073 | return 1; |
| 3074 | } |
| 3075 | anArgIter += aNbParsed; |
| 3076 | } |
| 3077 | else |
| 3078 | { |
| 3079 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
| 3080 | return 1; |
| 3081 | } |
| 3082 | } |
| 3083 | |
| 3084 | aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(), |
| 3085 | aSizeRatio, anArrowDiam, aNbFacets); |
| 3086 | aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType); |
| 3087 | aView->View()->ZFitAll(); |
| 3088 | return 0; |
| 3089 | } |
| 3090 | |
| 3091 | //============================================================================== |
| 3092 | //function : VRotate |
| 3093 | //purpose : Camera Rotating |
| 3094 | //============================================================================== |
| 3095 | |
| 3096 | static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec) |
| 3097 | { |
| 3098 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 3099 | if (aView.IsNull()) |
| 3100 | { |
| 3101 | std::cout << "No active view!\n"; |
| 3102 | return 1; |
| 3103 | } |
| 3104 | |
| 3105 | Standard_Boolean hasFlags = Standard_False; |
| 3106 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
| 3107 | { |
| 3108 | Standard_CString anArg (theArgVec[anArgIter]); |
| 3109 | TCollection_AsciiString aFlag (anArg); |
| 3110 | aFlag.LowerCase(); |
| 3111 | if (aFlag == "-mousestart" |
| 3112 | || aFlag == "-mousefrom") |
| 3113 | { |
| 3114 | hasFlags = Standard_True; |
| 3115 | if (anArgIter + 2 >= theArgNb) |
| 3116 | { |
| 3117 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; |
| 3118 | return 1; |
| 3119 | } |
| 3120 | |
| 3121 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); |
| 3122 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); |
| 3123 | aView->StartRotation (anX, anY); |
| 3124 | } |
| 3125 | else if (aFlag == "-mousemove") |
| 3126 | { |
| 3127 | hasFlags = Standard_True; |
| 3128 | if (anArgIter + 2 >= theArgNb) |
| 3129 | { |
| 3130 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; |
| 3131 | return 1; |
| 3132 | } |
| 3133 | |
| 3134 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); |
| 3135 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); |
| 3136 | aView->Rotation (anX, anY); |
| 3137 | } |
| 3138 | else if (theArgNb != 4 |
| 3139 | && theArgNb != 7) |
| 3140 | { |
| 3141 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; |
| 3142 | return 1; |
| 3143 | } |
| 3144 | } |
| 3145 | |
| 3146 | if (hasFlags) |
| 3147 | { |
| 3148 | return 0; |
| 3149 | } |
| 3150 | else if (theArgNb == 4) |
| 3151 | { |
| 3152 | Standard_Real anAX = Draw::Atof (theArgVec[1]); |
| 3153 | Standard_Real anAY = Draw::Atof (theArgVec[2]); |
| 3154 | Standard_Real anAZ = Draw::Atof (theArgVec[3]); |
| 3155 | aView->Rotate (anAX, anAY, anAZ); |
| 3156 | return 0; |
| 3157 | } |
| 3158 | else if (theArgNb == 7) |
| 3159 | { |
| 3160 | Standard_Real anAX = Draw::Atof (theArgVec[1]); |
| 3161 | Standard_Real anAY = Draw::Atof (theArgVec[2]); |
| 3162 | Standard_Real anAZ = Draw::Atof (theArgVec[3]); |
| 3163 | |
| 3164 | Standard_Real anX = Draw::Atof (theArgVec[4]); |
| 3165 | Standard_Real anY = Draw::Atof (theArgVec[5]); |
| 3166 | Standard_Real anZ = Draw::Atof (theArgVec[6]); |
| 3167 | |
| 3168 | aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ); |
| 3169 | return 0; |
| 3170 | } |
| 3171 | |
| 3172 | std::cout << "Error: Invalid number of arguments\n"; |
| 3173 | return 1; |
| 3174 | } |
| 3175 | |
| 3176 | //============================================================================== |
| 3177 | //function : VZoom |
| 3178 | //purpose : View zoom in / out (relative to current zoom) |
| 3179 | //============================================================================== |
| 3180 | |
| 3181 | static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { |
| 3182 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
| 3183 | if ( V3dView.IsNull() ) { |
| 3184 | return 1; |
| 3185 | } |
| 3186 | |
| 3187 | if ( argc == 2 ) { |
| 3188 | Standard_Real coef = Draw::Atof(argv[1]); |
| 3189 | if ( coef <= 0.0 ) { |
| 3190 | di << argv[1] << "Invalid value" << "\n"; |
| 3191 | return 1; |
| 3192 | } |
| 3193 | V3dView->SetZoom( Draw::Atof(argv[1]) ); |
| 3194 | return 0; |
| 3195 | } else { |
| 3196 | di << argv[0] << " Invalid number of arguments" << "\n"; |
| 3197 | return 1; |
| 3198 | } |
| 3199 | } |
| 3200 | |
| 3201 | //============================================================================== |
| 3202 | //function : VPan |
| 3203 | //purpose : View panning (in pixels) |
| 3204 | //============================================================================== |
| 3205 | |
| 3206 | static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { |
| 3207 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
| 3208 | if ( V3dView.IsNull() ) return 1; |
| 3209 | |
| 3210 | if ( argc == 3 ) { |
| 3211 | V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) ); |
| 3212 | return 0; |
| 3213 | } else { |
| 3214 | di << argv[0] << " Invalid number of arguments" << "\n"; |
| 3215 | return 1; |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | //============================================================================== |
| 3220 | //function : VPlace |
| 3221 | //purpose : Place the point (in pixels) at the center of the window |
| 3222 | //============================================================================== |
| 3223 | static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs) |
| 3224 | { |
| 3225 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 3226 | if (aView.IsNull()) |
| 3227 | { |
| 3228 | std::cerr << theArgs[0] << "Error: no active view." << std::endl; |
| 3229 | return 1; |
| 3230 | } |
| 3231 | |
| 3232 | if (theArgNb != 3) |
| 3233 | { |
| 3234 | std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl; |
| 3235 | return 1; |
| 3236 | } |
| 3237 | |
| 3238 | aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale()); |
| 3239 | |
| 3240 | return 0; |
| 3241 | } |
| 3242 | |
| 3243 | //============================================================================== |
| 3244 | //function : VExport |
| 3245 | //purpose : Export the view to a vector graphic format (PS, EMF, PDF) |
| 3246 | //============================================================================== |
| 3247 | |
| 3248 | static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 3249 | { |
| 3250 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
| 3251 | if (V3dView.IsNull()) |
| 3252 | return 1; |
| 3253 | |
| 3254 | if (argc == 1) |
| 3255 | { |
| 3256 | std::cout << "Usage: " << argv[0] << " Filename [Format]\n"; |
| 3257 | return 1; |
| 3258 | } |
| 3259 | |
| 3260 | Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF; |
| 3261 | TCollection_AsciiString aFormatStr; |
| 3262 | |
| 3263 | TCollection_AsciiString aFileName (argv[1]); |
| 3264 | Standard_Integer aLen = aFileName.Length(); |
| 3265 | |
| 3266 | if (argc > 2) |
| 3267 | { |
| 3268 | aFormatStr = TCollection_AsciiString (argv[2]); |
| 3269 | } |
| 3270 | else if (aLen >= 4) |
| 3271 | { |
| 3272 | if (aFileName.Value (aLen - 2) == '.') |
| 3273 | { |
| 3274 | aFormatStr = aFileName.SubString (aLen - 1, aLen); |
| 3275 | } |
| 3276 | else if (aFileName.Value (aLen - 3) == '.') |
| 3277 | { |
| 3278 | aFormatStr = aFileName.SubString (aLen - 2, aLen); |
| 3279 | } |
| 3280 | else |
| 3281 | { |
| 3282 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; |
| 3283 | return 1; |
| 3284 | } |
| 3285 | } |
| 3286 | else |
| 3287 | { |
| 3288 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; |
| 3289 | return 1; |
| 3290 | } |
| 3291 | |
| 3292 | aFormatStr.UpperCase(); |
| 3293 | if (aFormatStr == "PS") |
| 3294 | anExpFormat = Graphic3d_EF_PostScript; |
| 3295 | else if (aFormatStr == "EPS") |
| 3296 | anExpFormat = Graphic3d_EF_EnhPostScript; |
| 3297 | else if (aFormatStr == "TEX") |
| 3298 | anExpFormat = Graphic3d_EF_TEX; |
| 3299 | else if (aFormatStr == "PDF") |
| 3300 | anExpFormat = Graphic3d_EF_PDF; |
| 3301 | else if (aFormatStr == "SVG") |
| 3302 | anExpFormat = Graphic3d_EF_SVG; |
| 3303 | else if (aFormatStr == "PGF") |
| 3304 | anExpFormat = Graphic3d_EF_PGF; |
| 3305 | else if (aFormatStr == "EMF") |
| 3306 | anExpFormat = Graphic3d_EF_EMF; |
| 3307 | else |
| 3308 | { |
| 3309 | std::cout << "Invalid export format '" << aFormatStr << "'\n"; |
| 3310 | return 1; |
| 3311 | } |
| 3312 | |
| 3313 | try { |
| 3314 | if (!V3dView->View()->Export (argv[1], anExpFormat)) |
| 3315 | { |
| 3316 | di << "Error: export of image to " << aFormatStr << " failed!\n"; |
| 3317 | } |
| 3318 | } |
| 3319 | catch (Standard_Failure) |
| 3320 | { |
| 3321 | di << "Error: export of image to " << aFormatStr << " failed"; |
| 3322 | di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")"; |
| 3323 | } |
| 3324 | return 0; |
| 3325 | } |
| 3326 | |
| 3327 | //============================================================================== |
| 3328 | //function : VColorScale |
| 3329 | //purpose : representation color scale |
| 3330 | //============================================================================== |
| 3331 | |
| 3332 | static Standard_Boolean checkColor (const TCollection_AsciiString& theRed, |
| 3333 | const TCollection_AsciiString& theGreen, |
| 3334 | const TCollection_AsciiString& theBlue, |
| 3335 | Standard_Real& theRedValue, |
| 3336 | Standard_Real& theGreenValue, |
| 3337 | Standard_Real& theBlueValue) |
| 3338 | { |
| 3339 | if (!theRed.IsRealValue() |
| 3340 | || !theGreen.IsRealValue() |
| 3341 | || !theBlue.IsRealValue()) |
| 3342 | { |
| 3343 | std::cout << "Error: RGB color values should be real!\n"; |
| 3344 | return Standard_True; |
| 3345 | } |
| 3346 | theRedValue = theRed .RealValue(); |
| 3347 | theGreenValue = theGreen.RealValue(); |
| 3348 | theBlueValue = theBlue .RealValue(); |
| 3349 | if (theRedValue < 0.0 || theRedValue > 1.0 |
| 3350 | || theGreenValue < 0.0 || theGreenValue > 1.0 |
| 3351 | || theBlueValue < 0.0 || theBlueValue > 1.0) |
| 3352 | { |
| 3353 | std::cout << "Error: RGB color values should be within range 0..1!\n"; |
| 3354 | return Standard_True; |
| 3355 | } |
| 3356 | return Standard_False; |
| 3357 | } |
| 3358 | |
| 3359 | static int VColorScale (Draw_Interpretor& theDI, |
| 3360 | Standard_Integer theArgNb, |
| 3361 | const char** theArgVec) |
| 3362 | { |
| 3363 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 3364 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 3365 | if (aContext.IsNull()) |
| 3366 | { |
| 3367 | std::cout << "Error: no active view!\n"; |
| 3368 | return 1; |
| 3369 | } |
| 3370 | |
| 3371 | Handle(V3d_ColorScale) aCS = Handle(V3d_ColorScale)::DownCast (aView->ColorScale()); |
| 3372 | if (aCS.IsNull()) |
| 3373 | { |
| 3374 | std::cout << "Error: color scale is undefined!\n"; |
| 3375 | return 1; |
| 3376 | } |
| 3377 | |
| 3378 | Standard_Real aMinRange = aCS->GetMin(); |
| 3379 | Standard_Real aMaxRange = aCS->GetMax(); |
| 3380 | Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals(); |
| 3381 | Standard_Integer aTextHeight = aCS->GetTextHeight(); |
| 3382 | Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition(); |
| 3383 | gp_XY aPos (aCS->GetXPosition(), aCS->GetYPosition()); |
| 3384 | |
| 3385 | ViewerTest_AutoUpdater anUpdateTool (aContext, aView); |
| 3386 | |
| 3387 | if (theArgNb <= 1) |
| 3388 | { |
| 3389 | theDI << "Current color scale parameters:\n" |
| 3390 | << "Min range: " << aMinRange << "\n" |
| 3391 | << "Max range: " << aMaxRange << "\n" |
| 3392 | << "Number of intervals: " << aNbIntervals << "\n" |
| 3393 | << "Text height: " << aTextHeight << "\n" |
| 3394 | << "Color scale position: " << aPos.X() <<" "<< aPos.Y()<< "\n" |
| 3395 | << "Color scale title: " << aCS->GetTitle() << "\n" |
| 3396 | << "Label position: "; |
| 3397 | switch (aLabPosition) |
| 3398 | { |
| 3399 | case Aspect_TOCSP_NONE: |
| 3400 | theDI << "None\n"; |
| 3401 | break; |
| 3402 | case Aspect_TOCSP_LEFT: |
| 3403 | theDI << "Left\n"; |
| 3404 | break; |
| 3405 | case Aspect_TOCSP_RIGHT: |
| 3406 | theDI << "Right\n"; |
| 3407 | break; |
| 3408 | case Aspect_TOCSP_CENTER: |
| 3409 | theDI << "Center\n"; |
| 3410 | break; |
| 3411 | } |
| 3412 | return 0; |
| 3413 | } |
| 3414 | Standard_CString aFirstArg = theArgVec[1]; |
| 3415 | TCollection_AsciiString aFlag (aFirstArg); |
| 3416 | aFlag.LowerCase(); |
| 3417 | if (aFlag == "-hide" || |
| 3418 | aFlag == "-erase") |
| 3419 | { |
| 3420 | if (theArgNb > 2) |
| 3421 | { |
| 3422 | std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n"; |
| 3423 | return 1; |
| 3424 | } |
| 3425 | if (!aView->ColorScaleIsDisplayed()) |
| 3426 | { |
| 3427 | std::cout << "Error: color scale is not displayed!\n"; |
| 3428 | return 1; |
| 3429 | } |
| 3430 | else |
| 3431 | { |
| 3432 | aView->ColorScaleErase(); |
| 3433 | return 0; |
| 3434 | } |
| 3435 | } |
| 3436 | else if (aFlag == "-show" || |
| 3437 | aFlag == "-display") |
| 3438 | { |
| 3439 | if (theArgNb > 2) |
| 3440 | { |
| 3441 | std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n"; |
| 3442 | return 1; |
| 3443 | } |
| 3444 | aView->ColorScaleDisplay(); |
| 3445 | return 0; |
| 3446 | } |
| 3447 | |
| 3448 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
| 3449 | { |
| 3450 | Standard_CString anArg = theArgVec[anArgIter]; |
| 3451 | TCollection_AsciiString aFlag (anArg); |
| 3452 | aFlag.LowerCase(); |
| 3453 | if (anUpdateTool.parseRedrawMode (aFlag)) |
| 3454 | { |
| 3455 | continue; |
| 3456 | } |
| 3457 | else if (aFlag == "-range") |
| 3458 | { |
| 3459 | if (anArgIter + 3 >= theArgNb) |
| 3460 | { |
| 3461 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; |
| 3462 | return 1; |
| 3463 | } |
| 3464 | |
| 3465 | TCollection_AsciiString anArg1 (theArgVec[++anArgIter]); |
| 3466 | TCollection_AsciiString anArg2 (theArgVec[++anArgIter]); |
| 3467 | TCollection_AsciiString anArg3 (theArgVec[++anArgIter]); |
| 3468 | if (!anArg1.IsRealValue()) |
| 3469 | { |
| 3470 | std::cout << "Error: the minRange value should be real!\n"; |
| 3471 | return 1; |
| 3472 | } |
| 3473 | else if (!anArg2.IsRealValue()) |
| 3474 | { |
| 3475 | std::cout << "Error: the maxRange value should be real!\n"; |
| 3476 | return 1; |
| 3477 | } |
| 3478 | else if (!anArg3.IsIntegerValue()) |
| 3479 | { |
| 3480 | std::cout << "Error: the number of intervals should be integer!\n"; |
| 3481 | return 1; |
| 3482 | } |
| 3483 | |
| 3484 | aMinRange = anArg1.RealValue(); |
| 3485 | aMaxRange = anArg2.RealValue(); |
| 3486 | aNbIntervals = anArg3.IntegerValue(); |
| 3487 | } |
| 3488 | else if (aFlag == "-font") |
| 3489 | { |
| 3490 | if (anArgIter + 1 >= theArgNb) |
| 3491 | { |
| 3492 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; |
| 3493 | return 1; |
| 3494 | } |
| 3495 | TCollection_AsciiString anArg (theArgVec[anArgIter + 1]); |
| 3496 | if (!anArg.IsIntegerValue()) |
| 3497 | { |
| 3498 | std::cout << "Error: HeightFont value should be integer!\n"; |
| 3499 | return 1; |
| 3500 | } |
| 3501 | |
| 3502 | aTextHeight = anArg.IntegerValue(); |
| 3503 | anArgIter += 1; |
| 3504 | } |
| 3505 | else if (aFlag == "-textpos") |
| 3506 | { |
| 3507 | if (anArgIter + 1 >= theArgNb) |
| 3508 | { |
| 3509 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; |
| 3510 | return 1; |
| 3511 | } |
| 3512 | TCollection_AsciiString anArg (theArgVec[++anArgIter]); |
| 3513 | anArg.LowerCase(); |
| 3514 | if (anArg == "none") |
| 3515 | { |
| 3516 | aLabPosition = Aspect_TOCSP_NONE; |
| 3517 | } |
| 3518 | else if (anArg == "left") |
| 3519 | { |
| 3520 | aLabPosition = Aspect_TOCSP_LEFT; |
| 3521 | } |
| 3522 | else if (anArg == "right") |
| 3523 | { |
| 3524 | aLabPosition = Aspect_TOCSP_RIGHT; |
| 3525 | } |
| 3526 | else if (anArg == "center") |
| 3527 | { |
| 3528 | aLabPosition = Aspect_TOCSP_CENTER; |
| 3529 | } |
| 3530 | else |
| 3531 | { |
| 3532 | std::cout << "Error: unknown position '" << anArg << "'!\n"; |
| 3533 | return 1; |
| 3534 | } |
| 3535 | } |
| 3536 | else if (aFlag == "-xy") |
| 3537 | { |
| 3538 | if (anArgIter + 2 >= theArgNb) |
| 3539 | { |
| 3540 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; |
| 3541 | return 1; |
| 3542 | } |
| 3543 | |
| 3544 | TCollection_AsciiString aX (theArgVec[++anArgIter]); |
| 3545 | TCollection_AsciiString aY (theArgVec[++anArgIter]); |
| 3546 | if (!aX.IsRealValue() |
| 3547 | || !aY.IsRealValue()) |
| 3548 | { |
| 3549 | std::cout << "Error: coordinates should be real values!\n"; |
| 3550 | return 1; |
| 3551 | } |
| 3552 | |
| 3553 | aPos.SetCoord (aX.RealValue(), aY.RealValue()); |
| 3554 | } |
| 3555 | else if (aFlag == "-color") |
| 3556 | { |
| 3557 | if (aCS->GetColorType() != Aspect_TOCSD_USER) |
| 3558 | { |
| 3559 | std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n"; |
| 3560 | return 1; |
| 3561 | } |
| 3562 | |
| 3563 | Quantity_NameOfColor aColorName; |
| 3564 | if (anArgIter + 4 >= theArgNb) |
| 3565 | { |
| 3566 | if (anArgIter + 2 >= theArgNb) |
| 3567 | { |
| 3568 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; |
| 3569 | return 1; |
| 3570 | } |
| 3571 | else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName)) |
| 3572 | { |
| 3573 | std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n"; |
| 3574 | return 1; |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | TCollection_AsciiString anInd (theArgVec[anArgIter + 1]); |
| 3579 | if (!anInd.IsIntegerValue()) |
| 3580 | { |
| 3581 | std::cout << "Error: Index value should be integer!\n"; |
| 3582 | return 1; |
| 3583 | } |
| 3584 | |
| 3585 | Standard_Integer anIndex = anInd.IntegerValue(); |
| 3586 | if (anIndex < 0 |
| 3587 | || anIndex > aNbIntervals - 1) |
| 3588 | { |
| 3589 | std::cout << "Error: Index value should be within range 0..." << (aNbIntervals - 1) <<"!\n"; |
| 3590 | return 1; |
| 3591 | } |
| 3592 | |
| 3593 | if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName)) |
| 3594 | { |
| 3595 | aCS->SetColor (Quantity_Color (aColorName), anIndex); |
| 3596 | aCS->SetColorType(Aspect_TOCSD_USER); |
| 3597 | anArgIter += 2; |
| 3598 | continue; |
| 3599 | } |
| 3600 | |
| 3601 | TCollection_AsciiString aRed (theArgVec[anArgIter + 2]); |
| 3602 | TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]); |
| 3603 | TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]); |
| 3604 | Standard_Real aRedValue,aGreenValue, aBlueValue; |
| 3605 | if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue)) |
| 3606 | { |
| 3607 | return 1; |
| 3608 | } |
| 3609 | aCS->SetColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex); |
| 3610 | aCS->SetColorType (Aspect_TOCSD_USER); |
| 3611 | anArgIter += 4; |
| 3612 | } |
| 3613 | else if (aFlag == "-label") |
| 3614 | { |
| 3615 | if (aCS->GetColorType() != Aspect_TOCSD_USER) |
| 3616 | { |
| 3617 | std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n"; |
| 3618 | return 1; |
| 3619 | } |
| 3620 | else if (anArgIter + 2 >= theArgNb) |
| 3621 | { |
| 3622 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; |
| 3623 | return 1; |
| 3624 | } |
| 3625 | |
| 3626 | Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]); |
| 3627 | if (anIndex < 0 |
| 3628 | || anIndex > aNbIntervals) |
| 3629 | { |
| 3630 | std::cout << "Error: Index value should be within range 0..." << aNbIntervals <<"!\n"; |
| 3631 | return 1; |
| 3632 | } |
| 3633 | |
| 3634 | TCollection_ExtendedString aText (theArgVec[anArgIter + 2]); |
| 3635 | aCS->SetLabel (aText, anIndex); |
| 3636 | aCS->SetLabelType (Aspect_TOCSD_USER); |
| 3637 | anArgIter += 2; |
| 3638 | } |
| 3639 | else if (aFlag == "-colors") |
| 3640 | { |
| 3641 | Aspect_SequenceOfColor aSeq; |
| 3642 | if (anArgIter + aNbIntervals + 1 > theArgNb) |
| 3643 | { |
| 3644 | std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the " |
| 3645 | << aNbIntervals << " intervals\n"; |
| 3646 | return 1; |
| 3647 | } |
| 3648 | |
| 3649 | Standard_Integer aColorIter = anArgIter + 1; |
| 3650 | while (aColorIter < theArgNb) |
| 3651 | { |
| 3652 | if (theArgVec[aColorIter][0] == '-') |
| 3653 | { |
| 3654 | break; |
| 3655 | } |
| 3656 | |
| 3657 | else if (theArgVec[aColorIter][0] >= 97 |
| 3658 | && theArgVec[aColorIter][0] <= 122) |
| 3659 | { |
| 3660 | Quantity_NameOfColor aColorName; |
| 3661 | if (!Quantity_Color::ColorFromName (theArgVec[aColorIter], aColorName)) |
| 3662 | { |
| 3663 | std::cout << "Error: wrong color name: " << theArgVec[aColorIter] << " !\n"; |
| 3664 | return 1; |
| 3665 | } |
| 3666 | aSeq.Append (Quantity_Color (aColorName)); |
| 3667 | aColorIter++; |
| 3668 | anArgIter++; |
| 3669 | } |
| 3670 | else |
| 3671 | { |
| 3672 | TCollection_AsciiString aRed (theArgVec[aColorIter]); |
| 3673 | TCollection_AsciiString aGreen (theArgVec[aColorIter + 1]); |
| 3674 | TCollection_AsciiString aBlue (theArgVec[aColorIter + 2]); |
| 3675 | Standard_Real aRedValue,aGreenValue, aBlueValue; |
| 3676 | if (checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue)) |
| 3677 | { |
| 3678 | return 1; |
| 3679 | } |
| 3680 | aSeq.Append (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB)); |
| 3681 | aColorIter += 3; |
| 3682 | anArgIter += 3; |
| 3683 | } |
| 3684 | } |
| 3685 | if (aSeq.Length() < aNbIntervals) |
| 3686 | { |
| 3687 | std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the " |
| 3688 | << aNbIntervals << " intervals\n"; |
| 3689 | return 1; |
| 3690 | } |
| 3691 | |
| 3692 | aCS->SetColors (aSeq); |
| 3693 | aCS->SetColorType (Aspect_TOCSD_USER); |
| 3694 | } |
| 3695 | else if (aFlag == "-labels") |
| 3696 | { |
| 3697 | if (anArgIter + aNbIntervals + 1 >= theArgNb) |
| 3698 | { |
| 3699 | std::cout << "Error: not enough arguments! You should provide " << (aNbIntervals + 1) |
| 3700 | << " text labels for " << aNbIntervals << " intervals.\n"; |
| 3701 | return 1; |
| 3702 | } |
| 3703 | |
| 3704 | TColStd_SequenceOfExtendedString aSeq; |
| 3705 | for (int aLabelIter = anArgIter + 1; aLabelIter <= anArgIter + aNbIntervals + 1; aLabelIter += 1) |
| 3706 | { |
| 3707 | aSeq.Append (TCollection_ExtendedString (theArgVec[aLabelIter])); |
| 3708 | } |
| 3709 | aCS->SetLabels (aSeq); |
| 3710 | aCS->SetLabelType (Aspect_TOCSD_USER); |
| 3711 | anArgIter += aSeq.Length(); |
| 3712 | } |
| 3713 | else if (aFlag == "-title") |
| 3714 | { |
| 3715 | if (anArgIter + 1 >= theArgNb) |
| 3716 | { |
| 3717 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; |
| 3718 | return 1; |
| 3719 | } |
| 3720 | |
| 3721 | Standard_Boolean isTwoArgs = Standard_False; |
| 3722 | if (anArgIter + 2 < theArgNb) |
| 3723 | { |
| 3724 | TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]); |
| 3725 | aSecondArg.LowerCase(); |
| 3726 | if (aSecondArg == "none") |
| 3727 | { |
| 3728 | aCS->SetTitlePosition (Aspect_TOCSP_NONE); |
| 3729 | isTwoArgs = Standard_True; |
| 3730 | } |
| 3731 | else if (aSecondArg == "left") |
| 3732 | { |
| 3733 | aCS->SetTitlePosition (Aspect_TOCSP_LEFT); |
| 3734 | isTwoArgs = Standard_True; |
| 3735 | } |
| 3736 | else if (aSecondArg == "right") |
| 3737 | { |
| 3738 | aCS->SetTitlePosition (Aspect_TOCSP_RIGHT); |
| 3739 | isTwoArgs = Standard_True; |
| 3740 | } |
| 3741 | else if (aSecondArg == "center") |
| 3742 | { |
| 3743 | aCS->SetTitlePosition (Aspect_TOCSP_CENTER); |
| 3744 | isTwoArgs = Standard_True; |
| 3745 | } |
| 3746 | } |
| 3747 | |
| 3748 | aCS->SetTitle (theArgVec[anArgIter + 1]); |
| 3749 | if (isTwoArgs) |
| 3750 | { |
| 3751 | anArgIter += 1; |
| 3752 | } |
| 3753 | anArgIter += 1; |
| 3754 | } |
| 3755 | else if (aFlag == "-demoversion" |
| 3756 | || aFlag == "-demo") |
| 3757 | { |
| 3758 | aPos.SetCoord (0.0, 0.0); |
| 3759 | aTextHeight = 16; |
| 3760 | aMinRange = 0.0; |
| 3761 | aMaxRange = 100; |
| 3762 | aNbIntervals = 10; |
| 3763 | aLabPosition = Aspect_TOCSP_RIGHT; |
| 3764 | aCS->SetColorType(Aspect_TOCSD_AUTO); |
| 3765 | aCS->SetLabelType(Aspect_TOCSD_AUTO); |
| 3766 | } |
| 3767 | else |
| 3768 | { |
| 3769 | std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n"; |
| 3770 | return 1; |
| 3771 | } |
| 3772 | } |
| 3773 | |
| 3774 | aCS->SetPosition (aPos.X(), aPos.Y()); |
| 3775 | aCS->SetHeight (0.95); |
| 3776 | aCS->SetTextHeight (aTextHeight); |
| 3777 | aCS->SetRange (aMinRange, aMaxRange); |
| 3778 | aCS->SetNumberOfIntervals (aNbIntervals); |
| 3779 | aCS->SetLabelPosition (aLabPosition); |
| 3780 | |
| 3781 | if (!aView->ColorScaleIsDisplayed()) |
| 3782 | { |
| 3783 | aView->ColorScaleDisplay(); |
| 3784 | } |
| 3785 | |
| 3786 | return 0; |
| 3787 | } |
| 3788 | |
| 3789 | //============================================================================== |
| 3790 | //function : VGraduatedTrihedron |
| 3791 | //purpose : Displays or hides a graduated trihedron |
| 3792 | //============================================================================== |
| 3793 | static Standard_Boolean GetColor (const TCollection_AsciiString& theValue, |
| 3794 | Quantity_Color& theColor) |
| 3795 | { |
| 3796 | Quantity_NameOfColor aColorName; |
| 3797 | TCollection_AsciiString aVal = theValue; |
| 3798 | aVal.UpperCase(); |
| 3799 | if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName)) |
| 3800 | { |
| 3801 | return Standard_False; |
| 3802 | } |
| 3803 | theColor = Quantity_Color (aColorName); |
| 3804 | return Standard_True; |
| 3805 | } |
| 3806 | |
| 3807 | static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs) |
| 3808 | { |
| 3809 | if (theArgNum < 2) |
| 3810 | { |
| 3811 | std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help" |
| 3812 | << theArgs[0] <<"' for more information.\n"; |
| 3813 | return 1; //TCL_ERROR |
| 3814 | } |
| 3815 | |
| 3816 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs; |
| 3817 | TCollection_AsciiString aParseKey; |
| 3818 | for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt) |
| 3819 | { |
| 3820 | TCollection_AsciiString anArg (theArgs [anArgIt]); |
| 3821 | |
| 3822 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) |
| 3823 | { |
| 3824 | aParseKey = anArg; |
| 3825 | aParseKey.Remove (1); |
| 3826 | aParseKey.LowerCase(); |
| 3827 | aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); |
| 3828 | continue; |
| 3829 | } |
| 3830 | |
| 3831 | if (aParseKey.IsEmpty()) |
| 3832 | { |
| 3833 | continue; |
| 3834 | } |
| 3835 | |
| 3836 | aMapOfArgs(aParseKey)->Append (anArg); |
| 3837 | } |
| 3838 | |
| 3839 | // Check parameters |
| 3840 | for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs); |
| 3841 | aMapIt.More(); aMapIt.Next()) |
| 3842 | { |
| 3843 | const TCollection_AsciiString& aKey = aMapIt.Key(); |
| 3844 | const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value(); |
| 3845 | |
| 3846 | // Bool key, without arguments |
| 3847 | if ((aKey.IsEqual ("on") || aKey.IsEqual ("off")) |
| 3848 | && anArgs->IsEmpty()) |
| 3849 | { |
| 3850 | continue; |
| 3851 | } |
| 3852 | |
| 3853 | // One argument |
| 3854 | if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname")) |
| 3855 | && anArgs->Length() == 1) |
| 3856 | { |
| 3857 | continue; |
| 3858 | } |
| 3859 | |
| 3860 | // On/off arguments |
| 3861 | if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname") |
| 3862 | || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks") |
| 3863 | || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues") |
| 3864 | || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes")) |
| 3865 | && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off"))) |
| 3866 | { |
| 3867 | continue; |
| 3868 | } |
| 3869 | |
| 3870 | // One string argument |
| 3871 | if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor") |
| 3872 | || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor")) |
| 3873 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) |
| 3874 | { |
| 3875 | continue; |
| 3876 | } |
| 3877 | |
| 3878 | // One integer argument |
| 3879 | if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks") |
| 3880 | || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength") |
| 3881 | || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset") |
| 3882 | || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset")) |
| 3883 | && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue()) |
| 3884 | { |
| 3885 | continue; |
| 3886 | } |
| 3887 | |
| 3888 | // One real argument |
| 3889 | if ( aKey.IsEqual ("arrowlength") |
| 3890 | && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue())) |
| 3891 | { |
| 3892 | continue; |
| 3893 | } |
| 3894 | |
| 3895 | // Two string arguments |
| 3896 | if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont")) |
| 3897 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) |
| 3898 | { |
| 3899 | continue; |
| 3900 | } |
| 3901 | |
| 3902 | TCollection_AsciiString aLowerKey; |
| 3903 | aLowerKey = "-"; |
| 3904 | aLowerKey += aKey; |
| 3905 | aLowerKey.LowerCase(); |
| 3906 | std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n"; |
| 3907 | std::cout << "Type help for more information.\n"; |
| 3908 | return 1; |
| 3909 | } |
| 3910 | |
| 3911 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); |
| 3912 | if (anAISContext.IsNull()) |
| 3913 | { |
| 3914 | std::cout << theArgs[0] << ": " << " please use 'vinit' command to initialize view.\n"; |
| 3915 | return 1; |
| 3916 | } |
| 3917 | |
| 3918 | Standard_Boolean toDisplay = Standard_True; |
| 3919 | Quantity_Color aColor; |
| 3920 | Graphic3d_GraduatedTrihedron aTrihedronData; |
| 3921 | // Process parameters |
| 3922 | Handle(TColStd_HSequenceOfAsciiString) aValues; |
| 3923 | if (aMapOfArgs.Find ("off", aValues)) |
| 3924 | { |
| 3925 | toDisplay = Standard_False; |
| 3926 | } |
| 3927 | |
| 3928 | // AXES NAMES |
| 3929 | if (aMapOfArgs.Find ("xname", aValues)) |
| 3930 | { |
| 3931 | aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1)); |
| 3932 | } |
| 3933 | if (aMapOfArgs.Find ("yname", aValues)) |
| 3934 | { |
| 3935 | aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1)); |
| 3936 | } |
| 3937 | if (aMapOfArgs.Find ("zname", aValues)) |
| 3938 | { |
| 3939 | aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1)); |
| 3940 | } |
| 3941 | if (aMapOfArgs.Find ("xdrawname", aValues)) |
| 3942 | { |
| 3943 | aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
| 3944 | } |
| 3945 | if (aMapOfArgs.Find ("ydrawname", aValues)) |
| 3946 | { |
| 3947 | aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
| 3948 | } |
| 3949 | if (aMapOfArgs.Find ("zdrawname", aValues)) |
| 3950 | { |
| 3951 | aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
| 3952 | } |
| 3953 | if (aMapOfArgs.Find ("xnameoffset", aValues)) |
| 3954 | { |
| 3955 | aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); |
| 3956 | } |
| 3957 | if (aMapOfArgs.Find ("ynameoffset", aValues)) |
| 3958 | { |
| 3959 | aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); |
| 3960 | } |
| 3961 | if (aMapOfArgs.Find ("znameoffset", aValues)) |
| 3962 | { |
| 3963 | aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); |
| 3964 | } |
| 3965 | |
| 3966 | // COLORS |
| 3967 | if (aMapOfArgs.Find ("xnamecolor", aValues)) |
| 3968 | { |
| 3969 | if (!GetColor (aValues->Value(1), aColor)) |
| 3970 | { |
| 3971 | std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n"; |
| 3972 | return 1; |
| 3973 | } |
| 3974 | aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor); |
| 3975 | } |
| 3976 | if (aMapOfArgs.Find ("ynamecolor", aValues)) |
| 3977 | { |
| 3978 | if (!GetColor (aValues->Value(1), aColor)) |
| 3979 | { |
| 3980 | std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n"; |
| 3981 | return 1; |
| 3982 | } |
| 3983 | aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor); |
| 3984 | } |
| 3985 | if (aMapOfArgs.Find ("znamecolor", aValues)) |
| 3986 | { |
| 3987 | if (!GetColor (aValues->Value(1), aColor)) |
| 3988 | { |
| 3989 | std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n"; |
| 3990 | return 1; |
| 3991 | } |
| 3992 | aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor); |
| 3993 | } |
| 3994 | if (aMapOfArgs.Find ("xcolor", aValues)) |
| 3995 | { |
| 3996 | if (!GetColor (aValues->Value(1), aColor)) |
| 3997 | { |
| 3998 | std::cout << theArgs[0] << "error: -xcolor wrong color name.\n"; |
| 3999 | return 1; |
| 4000 | } |
| 4001 | aTrihedronData.ChangeXAxisAspect().SetColor (aColor); |
| 4002 | } |
| 4003 | if (aMapOfArgs.Find ("ycolor", aValues)) |
| 4004 | { |
| 4005 | if (!GetColor (aValues->Value(1), aColor)) |
| 4006 | { |
| 4007 | std::cout << theArgs[0] << "error: -ycolor wrong color name.\n"; |
| 4008 | return 1; |
| 4009 | } |
| 4010 | aTrihedronData.ChangeYAxisAspect().SetColor (aColor); |
| 4011 | } |
| 4012 | if (aMapOfArgs.Find ("zcolor", aValues)) |
| 4013 | { |
| 4014 | if (!GetColor (aValues->Value(1), aColor)) |
| 4015 | { |
| 4016 | std::cout << theArgs[0] << "error: -zcolor wrong color name.\n"; |
| 4017 | return 1; |
| 4018 | } |
| 4019 | aTrihedronData.ChangeZAxisAspect().SetColor (aColor); |
| 4020 | } |
| 4021 | |
| 4022 | // TICKMARKS |
| 4023 | if (aMapOfArgs.Find ("xticks", aValues)) |
| 4024 | { |
| 4025 | aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
| 4026 | } |
| 4027 | if (aMapOfArgs.Find ("yticks", aValues)) |
| 4028 | { |
| 4029 | aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
| 4030 | } |
| 4031 | if (aMapOfArgs.Find ("zticks", aValues)) |
| 4032 | { |
| 4033 | aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
| 4034 | } |
| 4035 | if (aMapOfArgs.Find ("xticklength", aValues)) |
| 4036 | { |
| 4037 | aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
| 4038 | } |
| 4039 | if (aMapOfArgs.Find ("yticklength", aValues)) |
| 4040 | { |
| 4041 | aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
| 4042 | } |
| 4043 | if (aMapOfArgs.Find ("zticklength", aValues)) |
| 4044 | { |
| 4045 | aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
| 4046 | } |
| 4047 | if (aMapOfArgs.Find ("xdrawticks", aValues)) |
| 4048 | { |
| 4049 | aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
| 4050 | } |
| 4051 | if (aMapOfArgs.Find ("ydrawticks", aValues)) |
| 4052 | { |
| 4053 | aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
| 4054 | } |
| 4055 | if (aMapOfArgs.Find ("zdrawticks", aValues)) |
| 4056 | { |
| 4057 | aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
| 4058 | } |
| 4059 | |
| 4060 | // VALUES |
| 4061 | if (aMapOfArgs.Find ("xdrawvalues", aValues)) |
| 4062 | { |
| 4063 | aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
| 4064 | } |
| 4065 | if (aMapOfArgs.Find ("ydrawvalues", aValues)) |
| 4066 | { |
| 4067 | aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
| 4068 | } |
| 4069 | if (aMapOfArgs.Find ("zdrawvalues", aValues)) |
| 4070 | { |
| 4071 | aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
| 4072 | } |
| 4073 | if (aMapOfArgs.Find ("xvaluesoffset", aValues)) |
| 4074 | { |
| 4075 | aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); |
| 4076 | } |
| 4077 | if (aMapOfArgs.Find ("yvaluesoffset", aValues)) |
| 4078 | { |
| 4079 | aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); |
| 4080 | } |
| 4081 | if (aMapOfArgs.Find ("zvaluesoffset", aValues)) |
| 4082 | { |
| 4083 | aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); |
| 4084 | } |
| 4085 | |
| 4086 | // ARROWS |
| 4087 | if (aMapOfArgs.Find ("arrowlength", aValues)) |
| 4088 | { |
| 4089 | aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue()); |
| 4090 | } |
| 4091 | |
| 4092 | // FONTS |
| 4093 | if (aMapOfArgs.Find ("namefont", aValues)) |
| 4094 | { |
| 4095 | aTrihedronData.SetNamesFont (aValues->Value(1)); |
| 4096 | } |
| 4097 | if (aMapOfArgs.Find ("valuesfont", aValues)) |
| 4098 | { |
| 4099 | aTrihedronData.SetValuesFont (aValues->Value(1)); |
| 4100 | } |
| 4101 | |
| 4102 | if (aMapOfArgs.Find ("drawgrid", aValues)) |
| 4103 | { |
| 4104 | aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on")); |
| 4105 | } |
| 4106 | if (aMapOfArgs.Find ("drawaxes", aValues)) |
| 4107 | { |
| 4108 | aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on")); |
| 4109 | } |
| 4110 | |
| 4111 | // The final step: display of erase trihedron |
| 4112 | if (toDisplay) |
| 4113 | { |
| 4114 | ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData); |
| 4115 | } |
| 4116 | else |
| 4117 | { |
| 4118 | ViewerTest::CurrentView()->GraduatedTrihedronErase(); |
| 4119 | } |
| 4120 | |
| 4121 | ViewerTest::GetAISContext()->UpdateCurrentViewer(); |
| 4122 | ViewerTest::CurrentView()->Redraw(); |
| 4123 | |
| 4124 | return 0; |
| 4125 | } |
| 4126 | |
| 4127 | //============================================================================== |
| 4128 | //function : VPrintView |
| 4129 | //purpose : Test printing algorithm, print the view to image file with given |
| 4130 | // width and height. Printing implemented only for WNT. |
| 4131 | //============================================================================== |
| 4132 | static int VPrintView (Draw_Interpretor& di, Standard_Integer argc, |
| 4133 | const char** argv) |
| 4134 | { |
| 4135 | #ifndef WNT |
| 4136 | di << "Printing implemented only for wnt!\n"; |
| 4137 | return 0; |
| 4138 | #else |
| 4139 | |
| 4140 | Handle(AIS_InteractiveContext) aContextAIS = NULL; |
| 4141 | Handle(V3d_View) aView = NULL; |
| 4142 | aContextAIS = ViewerTest::GetAISContext(); |
| 4143 | if (!aContextAIS.IsNull()) |
| 4144 | { |
| 4145 | const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer(); |
| 4146 | Vwr->InitActiveViews(); |
| 4147 | if(Vwr->MoreActiveViews()) |
| 4148 | aView = Vwr->ActiveView(); |
| 4149 | } |
| 4150 | |
| 4151 | // check for errors |
| 4152 | if (aView.IsNull()) |
| 4153 | { |
| 4154 | di << "Call vinit before!\n"; |
| 4155 | return 1; |
| 4156 | } |
| 4157 | else if (argc < 4) |
| 4158 | { |
| 4159 | di << "Use: " << argv[0]; |
| 4160 | di << " width height filename [print algo=0] [tile_width tile_height]\n"; |
| 4161 | di << "width, height of the intermediate buffer for operation\n"; |
| 4162 | di << "algo : {0|1}\n"; |
| 4163 | di << " 0 - stretch algorithm\n"; |
| 4164 | di << " 1 - tile algorithm\n"; |
| 4165 | di << "test printing algorithms into an intermediate buffer\n"; |
| 4166 | di << "using specific tile size if provided\n"; |
| 4167 | di << "with saving output to an image file\n"; |
| 4168 | return 1; |
| 4169 | } |
| 4170 | |
| 4171 | // get the input params |
| 4172 | Standard_Integer aWidth = Draw::Atoi (argv[1]); |
| 4173 | Standard_Integer aHeight = Draw::Atoi (argv[2]); |
| 4174 | Standard_Integer aMode = 0; |
| 4175 | TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]); |
| 4176 | if (argc >= 5) |
| 4177 | aMode = Draw::Atoi (argv[4]); |
| 4178 | |
| 4179 | Standard_Integer aTileWidth = 0; |
| 4180 | Standard_Integer aTileHeight = 0; |
| 4181 | Standard_Boolean isTileSizeProvided = Standard_False; |
| 4182 | if (argc == 7) |
| 4183 | { |
| 4184 | isTileSizeProvided = Standard_True; |
| 4185 | aTileWidth = Draw::Atoi (argv[5]); |
| 4186 | aTileHeight = Draw::Atoi (argv[6]); |
| 4187 | } |
| 4188 | |
| 4189 | // check the input parameters |
| 4190 | if (aWidth <= 0 || aHeight <= 0) |
| 4191 | { |
| 4192 | di << "Width and height must be positive values!\n"; |
| 4193 | return 1; |
| 4194 | } |
| 4195 | if (aMode != 0 && aMode != 1) |
| 4196 | aMode = 0; |
| 4197 | |
| 4198 | // define compatible bitmap |
| 4199 | HDC anDC = CreateCompatibleDC(0); |
| 4200 | BITMAPINFO aBitmapData; |
| 4201 | memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER)); |
| 4202 | aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); |
| 4203 | aBitmapData.bmiHeader.biWidth = aWidth ; |
| 4204 | aBitmapData.bmiHeader.biHeight = aHeight; |
| 4205 | aBitmapData.bmiHeader.biPlanes = 1; |
| 4206 | aBitmapData.bmiHeader.biBitCount = 24; |
| 4207 | aBitmapData.bmiHeader.biXPelsPerMeter = 0; |
| 4208 | aBitmapData.bmiHeader.biYPelsPerMeter = 0; |
| 4209 | aBitmapData.bmiHeader.biClrUsed = 0; |
| 4210 | aBitmapData.bmiHeader.biClrImportant = 0; |
| 4211 | aBitmapData.bmiHeader.biCompression = BI_RGB; |
| 4212 | aBitmapData.bmiHeader.biSizeImage = 0; |
| 4213 | |
| 4214 | // Create Device Independent Bitmap |
| 4215 | void* aBitsOut = NULL; |
| 4216 | HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS, |
| 4217 | &aBitsOut, NULL, 0); |
| 4218 | HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap); |
| 4219 | |
| 4220 | Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False; |
| 4221 | if (aBitsOut != NULL) |
| 4222 | { |
| 4223 | if (aMode == 0) |
| 4224 | isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH); |
| 4225 | else |
| 4226 | { |
| 4227 | if (isTileSizeProvided) |
| 4228 | { |
| 4229 | Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView()); |
| 4230 | Graphic3d_PtrFrameBuffer anOldBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO); |
| 4231 | aCView->ptrFBO = aView->View()->FBOCreate (aTileWidth, aTileHeight); |
| 4232 | |
| 4233 | isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE); |
| 4234 | |
| 4235 | Graphic3d_PtrFrameBuffer aNewBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO); |
| 4236 | aView->View()->FBORelease (aNewBuffer); |
| 4237 | aCView->ptrFBO = anOldBuffer; |
| 4238 | } |
| 4239 | else |
| 4240 | { |
| 4241 | isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE); |
| 4242 | } |
| 4243 | } |
| 4244 | |
| 4245 | // succesfully printed into an intermediate buffer |
| 4246 | if (isPrinted) |
| 4247 | { |
| 4248 | Image_PixMap aWrapper; |
| 4249 | aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4); |
| 4250 | aWrapper.SetTopDown (false); |
| 4251 | |
| 4252 | Image_AlienPixMap anImageBitmap; |
| 4253 | anImageBitmap.InitCopy (aWrapper); |
| 4254 | isSaved = anImageBitmap.Save (aFileName); |
| 4255 | } |
| 4256 | else |
| 4257 | { |
| 4258 | di << "Print operation failed due to printing errors or\n"; |
| 4259 | di << "insufficient memory available\n"; |
| 4260 | di << "Please, try to use smaller dimensions for this test\n"; |
| 4261 | di << "command, as it allocates intermediate buffer for storing\n"; |
| 4262 | di << "the result\n"; |
| 4263 | } |
| 4264 | } |
| 4265 | else |
| 4266 | { |
| 4267 | di << "Can't allocate memory for intermediate buffer\n"; |
| 4268 | di << "Please use smaller dimensions\n"; |
| 4269 | } |
| 4270 | |
| 4271 | if (aMemoryBitmap) |
| 4272 | { |
| 4273 | SelectObject (anDC, anOldBitmap); |
| 4274 | DeleteObject (aMemoryBitmap); |
| 4275 | DeleteDC(anDC); |
| 4276 | } |
| 4277 | |
| 4278 | if (!isSaved) |
| 4279 | { |
| 4280 | di << "Save to file operation failed. This operation may fail\n"; |
| 4281 | di << "if you don't have enough available memory, then you can\n"; |
| 4282 | di << "use smaller dimensions for the output file\n"; |
| 4283 | return 1; |
| 4284 | } |
| 4285 | |
| 4286 | return 0; |
| 4287 | |
| 4288 | #endif |
| 4289 | } |
| 4290 | |
| 4291 | //============================================================================== |
| 4292 | //function : VZLayer |
| 4293 | //purpose : Test z layer operations for v3d viewer |
| 4294 | //============================================================================== |
| 4295 | static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 4296 | { |
| 4297 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext (); |
| 4298 | if (aContextAIS.IsNull()) |
| 4299 | { |
| 4300 | di << "Call vinit before!\n"; |
| 4301 | return 1; |
| 4302 | } |
| 4303 | else if (argc < 2) |
| 4304 | { |
| 4305 | di << "Use: vzlayer "; |
| 4306 | di << " add/del/get/settings/enable/disable [id]\n"; |
| 4307 | di << " add - add new z layer to viewer and print its id\n"; |
| 4308 | di << " del - del z layer by its id\n"; |
| 4309 | di << " get - print sequence of z layers in increasing order of their overlay level\n"; |
| 4310 | di << " settings - print status of z layer settings\n"; |
| 4311 | di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"; |
| 4312 | di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"; |
| 4313 | di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"; |
| 4314 | di << "\nWhere id is the layer identificator\n"; |
| 4315 | di << "\nExamples:\n"; |
| 4316 | di << " vzlayer add\n"; |
| 4317 | di << " vzlayer enable poffset 1\n"; |
| 4318 | di << " vzlayer disable depthtest 1\n"; |
| 4319 | di << " vzlayer del 1\n"; |
| 4320 | return 1; |
| 4321 | } |
| 4322 | |
| 4323 | const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); |
| 4324 | if (aViewer.IsNull()) |
| 4325 | { |
| 4326 | di << "No active viewer!\n"; |
| 4327 | return 1; |
| 4328 | } |
| 4329 | |
| 4330 | // perform operation |
| 4331 | TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]); |
| 4332 | if (anOp == "add") |
| 4333 | { |
| 4334 | Standard_Integer aNewId; |
| 4335 | if (!aViewer->AddZLayer (aNewId)) |
| 4336 | { |
| 4337 | di << "Impossible to add new z layer!\n"; |
| 4338 | return 1; |
| 4339 | } |
| 4340 | |
| 4341 | di << "New z layer added with index: " << aNewId << "\n"; |
| 4342 | } |
| 4343 | else if (anOp == "del") |
| 4344 | { |
| 4345 | if (argc < 3) |
| 4346 | { |
| 4347 | di << "Please also provide as argument id of z layer to remove\n"; |
| 4348 | return 1; |
| 4349 | } |
| 4350 | |
| 4351 | Standard_Integer aDelId = Draw::Atoi (argv[2]); |
| 4352 | if (!aViewer->RemoveZLayer (aDelId)) |
| 4353 | { |
| 4354 | di << "Impossible to remove the z layer or invalid id!\n"; |
| 4355 | return 1; |
| 4356 | } |
| 4357 | |
| 4358 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); |
| 4359 | anObjIter.More(); anObjIter.Next()) |
| 4360 | { |
| 4361 | Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1()); |
| 4362 | if (aPrs.IsNull() |
| 4363 | || aPrs->ZLayer() != aDelId) |
| 4364 | { |
| 4365 | continue; |
| 4366 | } |
| 4367 | aPrs->SetZLayer (Graphic3d_ZLayerId_Default); |
| 4368 | } |
| 4369 | |
| 4370 | di << "Z layer " << aDelId << " has been removed\n"; |
| 4371 | } |
| 4372 | else if (anOp == "get") |
| 4373 | { |
| 4374 | TColStd_SequenceOfInteger anIds; |
| 4375 | aViewer->GetAllZLayers (anIds); |
| 4376 | for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++) |
| 4377 | { |
| 4378 | di << anIds.Value (aSeqIdx) << " "; |
| 4379 | } |
| 4380 | |
| 4381 | di << "\n"; |
| 4382 | } |
| 4383 | else if (anOp == "settings") |
| 4384 | { |
| 4385 | if (argc < 3) |
| 4386 | { |
| 4387 | di << "Please also provide an id\n"; |
| 4388 | return 1; |
| 4389 | } |
| 4390 | |
| 4391 | Standard_Integer anId = Draw::Atoi (argv[2]); |
| 4392 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId); |
| 4393 | |
| 4394 | di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n"; |
| 4395 | di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n"; |
| 4396 | di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n"; |
| 4397 | di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n"; |
| 4398 | |
| 4399 | } |
| 4400 | else if (anOp == "enable") |
| 4401 | { |
| 4402 | if (argc < 3) |
| 4403 | { |
| 4404 | di << "Please also provide an option to enable\n"; |
| 4405 | return 1; |
| 4406 | } |
| 4407 | |
| 4408 | if (argc < 4) |
| 4409 | { |
| 4410 | di << "Please also provide a layer id\n"; |
| 4411 | return 1; |
| 4412 | } |
| 4413 | |
| 4414 | TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]); |
| 4415 | Standard_Integer anId = Draw::Atoi (argv[3]); |
| 4416 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId); |
| 4417 | |
| 4418 | if (aSubOp == "depthtest" || aSubOp == "test") |
| 4419 | { |
| 4420 | aSettings.EnableSetting (Graphic3d_ZLayerDepthTest); |
| 4421 | } |
| 4422 | else if (aSubOp == "depthwrite" || aSubOp == "write") |
| 4423 | { |
| 4424 | aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite); |
| 4425 | } |
| 4426 | else if (aSubOp == "depthclear" || aSubOp == "clear") |
| 4427 | { |
| 4428 | aSettings.EnableSetting (Graphic3d_ZLayerDepthClear); |
| 4429 | } |
| 4430 | else if (aSubOp == "depthoffset" || aSubOp == "offset") |
| 4431 | { |
| 4432 | if (argc < 6) |
| 4433 | { |
| 4434 | di << "Please also provide a factor and units values for depth offset\n"; |
| 4435 | di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n"; |
| 4436 | return 1; |
| 4437 | } |
| 4438 | |
| 4439 | Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3])); |
| 4440 | Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4])); |
| 4441 | anId = Draw::Atoi (argv[5]); |
| 4442 | aSettings = aViewer->ZLayerSettings (anId); |
| 4443 | |
| 4444 | aSettings.DepthOffsetFactor = aFactor; |
| 4445 | aSettings.DepthOffsetUnits = aUnits; |
| 4446 | |
| 4447 | aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset); |
| 4448 | } |
| 4449 | else if (aSubOp == "positiveoffset" || aSubOp == "poffset") |
| 4450 | { |
| 4451 | aSettings.SetDepthOffsetPositive(); |
| 4452 | } |
| 4453 | else if (aSubOp == "negativeoffset" || aSubOp == "noffset") |
| 4454 | { |
| 4455 | aSettings.SetDepthOffsetNegative(); |
| 4456 | } |
| 4457 | |
| 4458 | aViewer->SetZLayerSettings (anId, aSettings); |
| 4459 | } |
| 4460 | else if (anOp == "disable") |
| 4461 | { |
| 4462 | if (argc < 3) |
| 4463 | { |
| 4464 | di << "Please also provide an option to disable\n"; |
| 4465 | return 1; |
| 4466 | } |
| 4467 | |
| 4468 | if (argc < 4) |
| 4469 | { |
| 4470 | di << "Please also provide a layer id\n"; |
| 4471 | return 1; |
| 4472 | } |
| 4473 | |
| 4474 | TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]); |
| 4475 | Standard_Integer anId = Draw::Atoi (argv[3]); |
| 4476 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId); |
| 4477 | |
| 4478 | if (aSubOp == "depthtest" || aSubOp == "test") |
| 4479 | { |
| 4480 | aSettings.DisableSetting (Graphic3d_ZLayerDepthTest); |
| 4481 | } |
| 4482 | else if (aSubOp == "depthwrite" || aSubOp == "write") |
| 4483 | { |
| 4484 | aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite); |
| 4485 | } |
| 4486 | else if (aSubOp == "depthclear" || aSubOp == "clear") |
| 4487 | { |
| 4488 | aSettings.DisableSetting (Graphic3d_ZLayerDepthClear); |
| 4489 | } |
| 4490 | else if (aSubOp == "depthoffset" || aSubOp == "offset") |
| 4491 | { |
| 4492 | aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset); |
| 4493 | } |
| 4494 | |
| 4495 | aViewer->SetZLayerSettings (anId, aSettings); |
| 4496 | } |
| 4497 | else |
| 4498 | { |
| 4499 | di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n"; |
| 4500 | return 1; |
| 4501 | } |
| 4502 | |
| 4503 | return 0; |
| 4504 | } |
| 4505 | |
| 4506 | DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem) |
| 4507 | |
| 4508 | // this class provides a presentation of text item in v3d view under-/overlayer |
| 4509 | class V3d_TextItem : public Visual3d_LayerItem |
| 4510 | { |
| 4511 | public: |
| 4512 | |
| 4513 | // CASCADE RTTI |
| 4514 | DEFINE_STANDARD_RTTI(V3d_TextItem) |
| 4515 | |
| 4516 | // constructor |
| 4517 | Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText, |
| 4518 | const Standard_Real theX1, |
| 4519 | const Standard_Real theY1, |
| 4520 | const Standard_Real theHeight, |
| 4521 | const TCollection_AsciiString& theFontName, |
| 4522 | const Quantity_Color& theColor, |
| 4523 | const Quantity_Color& theSubtitleColor, |
| 4524 | const Aspect_TypeOfDisplayText& theTypeOfDisplay, |
| 4525 | const Handle(Visual3d_Layer)& theLayer); |
| 4526 | |
| 4527 | // redraw method |
| 4528 | Standard_EXPORT void RedrawLayerPrs(); |
| 4529 | |
| 4530 | private: |
| 4531 | |
| 4532 | Standard_Real myX1; |
| 4533 | Standard_Real myY1; |
| 4534 | TCollection_AsciiString myText; |
| 4535 | Standard_Real myHeight; |
| 4536 | Handle(Visual3d_Layer) myLayer; |
| 4537 | Quantity_Color myColor; |
| 4538 | Quantity_Color mySubtitleColor; |
| 4539 | Aspect_TypeOfDisplayText myType; |
| 4540 | TCollection_AsciiString myFontName; |
| 4541 | }; |
| 4542 | |
| 4543 | IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem) |
| 4544 | IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem) |
| 4545 | |
| 4546 | // create and add to display the text item |
| 4547 | V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText, |
| 4548 | const Standard_Real theX1, |
| 4549 | const Standard_Real theY1, |
| 4550 | const Standard_Real theHeight, |
| 4551 | const TCollection_AsciiString& theFontName, |
| 4552 | const Quantity_Color& theColor, |
| 4553 | const Quantity_Color& theSubtitleColor, |
| 4554 | const Aspect_TypeOfDisplayText& theTypeOfDisplay, |
| 4555 | const Handle(Visual3d_Layer)& theLayer) |
| 4556 | : myX1 (theX1), myY1 (theY1), |
| 4557 | myText (theText), |
| 4558 | myHeight (theHeight), |
| 4559 | myLayer (theLayer), |
| 4560 | myColor (theColor), |
| 4561 | mySubtitleColor (theSubtitleColor), |
| 4562 | myType (theTypeOfDisplay), |
| 4563 | myFontName (theFontName) |
| 4564 | { |
| 4565 | if (!myLayer.IsNull ()) |
| 4566 | myLayer->AddLayerItem (this); |
| 4567 | } |
| 4568 | |
| 4569 | // render item |
| 4570 | void V3d_TextItem::RedrawLayerPrs () |
| 4571 | { |
| 4572 | if (myLayer.IsNull ()) |
| 4573 | return; |
| 4574 | |
| 4575 | myLayer->SetColor (myColor); |
| 4576 | myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor); |
| 4577 | myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight); |
| 4578 | } |
| 4579 | |
| 4580 | DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem) |
| 4581 | |
| 4582 | // The Visual3d_LayerItem line item for "vlayerline" command |
| 4583 | // it provides a presentation of line with user-defined |
| 4584 | // linewidth, linetype and transparency. |
| 4585 | class V3d_LineItem : public Visual3d_LayerItem |
| 4586 | { |
| 4587 | public: |
| 4588 | // CASCADE RTTI |
| 4589 | DEFINE_STANDARD_RTTI(V3d_LineItem) |
| 4590 | |
| 4591 | // constructor |
| 4592 | Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1, |
| 4593 | Standard_Real X2, Standard_Real Y2, |
| 4594 | V3d_LayerMgrPointer theLayerMgr, |
| 4595 | Aspect_TypeOfLine theType = Aspect_TOL_SOLID, |
| 4596 | Standard_Real theWidth = 0.5, |
| 4597 | Standard_Real theTransp = 1.0); |
| 4598 | |
| 4599 | // redraw method |
| 4600 | Standard_EXPORT void RedrawLayerPrs(); |
| 4601 | |
| 4602 | private: |
| 4603 | |
| 4604 | Standard_Real myX1, myY1, myX2, myY2; |
| 4605 | V3d_LayerMgrPointer myLayerMgr; |
| 4606 | Aspect_TypeOfLine myType; |
| 4607 | Standard_Real myWidth; |
| 4608 | Standard_Real myTransparency; |
| 4609 | }; |
| 4610 | |
| 4611 | IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem) |
| 4612 | IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem) |
| 4613 | |
| 4614 | // default constructor for line item |
| 4615 | V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1, |
| 4616 | Standard_Real X2, Standard_Real Y2, |
| 4617 | V3d_LayerMgrPointer theLayerMgr, |
| 4618 | Aspect_TypeOfLine theType, |
| 4619 | Standard_Real theWidth, |
| 4620 | Standard_Real theTransp) : |
| 4621 | myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr), |
| 4622 | myType(theType), myWidth(theWidth), myTransparency(theTransp) |
| 4623 | { |
| 4624 | if (myLayerMgr && !myLayerMgr->Overlay().IsNull()) |
| 4625 | myLayerMgr->Overlay()->AddLayerItem (this); |
| 4626 | } |
| 4627 | |
| 4628 | // render line |
| 4629 | void V3d_LineItem::RedrawLayerPrs () |
| 4630 | { |
| 4631 | Handle (Visual3d_Layer) aOverlay; |
| 4632 | |
| 4633 | if (myLayerMgr) |
| 4634 | aOverlay = myLayerMgr->Overlay(); |
| 4635 | |
| 4636 | if (!aOverlay.IsNull()) |
| 4637 | { |
| 4638 | Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB); |
| 4639 | aOverlay->SetColor(aColor); |
| 4640 | aOverlay->SetTransparency((Standard_ShortReal)myTransparency); |
| 4641 | aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth); |
| 4642 | aOverlay->BeginPolyline(); |
| 4643 | aOverlay->AddVertex(myX1, myY1); |
| 4644 | aOverlay->AddVertex(myX2, myY2); |
| 4645 | aOverlay->ClosePrimitive(); |
| 4646 | } |
| 4647 | } |
| 4648 | |
| 4649 | //============================================================================= |
| 4650 | //function : VLayerLine |
| 4651 | //purpose : Draws line in the v3d view layer with given attributes: linetype, |
| 4652 | // : linewidth, transparency coefficient |
| 4653 | //============================================================================ |
| 4654 | static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 4655 | { |
| 4656 | // get the active view |
| 4657 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 4658 | if (aView.IsNull()) |
| 4659 | { |
| 4660 | di << "Call vinit before!\n"; |
| 4661 | return 1; |
| 4662 | } |
| 4663 | else if (argc < 5) |
| 4664 | { |
| 4665 | di << "Use: " << argv[0]; |
| 4666 | di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n"; |
| 4667 | di << " linetype : { 0 | 1 | 2 | 3 } \n"; |
| 4668 | di << " 0 - solid \n"; |
| 4669 | di << " 1 - dashed \n"; |
| 4670 | di << " 2 - dot \n"; |
| 4671 | di << " 3 - dashdot\n"; |
| 4672 | di << " transparency : { 0.0 - 1.0 } \n"; |
| 4673 | di << " 0.0 - transparent\n"; |
| 4674 | di << " 1.0 - visible \n"; |
| 4675 | return 1; |
| 4676 | } |
| 4677 | |
| 4678 | // get the input params |
| 4679 | Standard_Real X1 = Draw::Atof(argv[1]); |
| 4680 | Standard_Real Y1 = Draw::Atof(argv[2]); |
| 4681 | Standard_Real X2 = Draw::Atof(argv[3]); |
| 4682 | Standard_Real Y2 = Draw::Atof(argv[4]); |
| 4683 | |
| 4684 | Standard_Real aWidth = 0.5; |
| 4685 | Standard_Integer aType = 0; |
| 4686 | Standard_Real aTransparency = 1.0; |
| 4687 | |
| 4688 | // has width |
| 4689 | if (argc > 5) |
| 4690 | aWidth = Draw::Atof(argv[5]); |
| 4691 | |
| 4692 | // has type |
| 4693 | if (argc > 6) |
| 4694 | aType = (Standard_Integer) Draw::Atoi(argv[6]); |
| 4695 | |
| 4696 | // has transparency |
| 4697 | if (argc > 7) |
| 4698 | { |
| 4699 | aTransparency = Draw::Atof(argv[7]); |
| 4700 | if (aTransparency < 0 || aTransparency > 1.0) |
| 4701 | aTransparency = 1.0; |
| 4702 | } |
| 4703 | |
| 4704 | // select appropriate line type |
| 4705 | Aspect_TypeOfLine aLineType; |
| 4706 | switch (aType) |
| 4707 | { |
| 4708 | case 1: |
| 4709 | aLineType = Aspect_TOL_DASH; |
| 4710 | break; |
| 4711 | |
| 4712 | case 2: |
| 4713 | aLineType = Aspect_TOL_DOT; |
| 4714 | break; |
| 4715 | |
| 4716 | case 3: |
| 4717 | aLineType = Aspect_TOL_DOTDASH; |
| 4718 | break; |
| 4719 | |
| 4720 | default: |
| 4721 | aLineType = Aspect_TOL_SOLID; |
| 4722 | } |
| 4723 | |
| 4724 | // replace layer manager |
| 4725 | Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView); |
| 4726 | aView->SetLayerMgr(aMgr); |
| 4727 | |
| 4728 | // add line item |
| 4729 | Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2, |
| 4730 | aMgr.operator->(), |
| 4731 | aLineType, aWidth, |
| 4732 | aTransparency); |
| 4733 | |
| 4734 | // update view |
| 4735 | aView->MustBeResized(); |
| 4736 | aView->Redraw(); |
| 4737 | |
| 4738 | return 0; |
| 4739 | } |
| 4740 | |
| 4741 | //======================================================================= |
| 4742 | //function : VOverlayText |
| 4743 | //purpose : Test text displaying in view overlay |
| 4744 | //======================================================================= |
| 4745 | static int VOverlayText (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 << "No active view. Please call vinit.\n"; |
| 4752 | return 1; |
| 4753 | } |
| 4754 | else if (argc < 4 || argc > 13) |
| 4755 | { |
| 4756 | di << "Use: " << argv[0]; |
| 4757 | di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n"; |
| 4758 | di << "[background_color: R G B]\n"; |
| 4759 | di << " height - pixel height of the text (default=10.0)\n"; |
| 4760 | di << " font_name - name of font (default=courier)\n"; |
| 4761 | di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n"; |
| 4762 | di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n"; |
| 4763 | di << " background_color- R G B values used for subtitle and decal text\n"; |
| 4764 | di << "(default=255.0 255.0 255.0)\n"; |
| 4765 | return 1; |
| 4766 | } |
| 4767 | |
| 4768 | TCollection_AsciiString aText (argv[1]); |
| 4769 | Standard_Real aPosX = Draw::Atof(argv[2]); |
| 4770 | Standard_Real aPosY = Draw::Atof(argv[3]); |
| 4771 | Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0; |
| 4772 | |
| 4773 | // font name |
| 4774 | TCollection_AsciiString aFontName = "Courier"; |
| 4775 | if (argc >= 6) |
| 4776 | aFontName = TCollection_AsciiString (argv[5]); |
| 4777 | |
| 4778 | // text colors |
| 4779 | Quantity_Parameter aColorRed = 1.0; |
| 4780 | Quantity_Parameter aColorGreen = 1.0; |
| 4781 | Quantity_Parameter aColorBlue = 1.0; |
| 4782 | if (argc >= 9) |
| 4783 | { |
| 4784 | aColorRed = Draw::Atof (argv[6])/255.; |
| 4785 | aColorGreen = Draw::Atof (argv[7])/255.; |
| 4786 | aColorBlue = Draw::Atof (argv[8])/255.; |
| 4787 | } |
| 4788 | |
| 4789 | // display type |
| 4790 | TCollection_AsciiString aDispStr; |
| 4791 | if (argc >= 10) |
| 4792 | aDispStr = TCollection_AsciiString (argv[9]); |
| 4793 | |
| 4794 | Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL; |
| 4795 | if (aDispStr.IsEqual ("subtitle")) |
| 4796 | aTextType = Aspect_TODT_SUBTITLE; |
| 4797 | else if (aDispStr.IsEqual ("decal")) |
| 4798 | aTextType = Aspect_TODT_DEKALE; |
| 4799 | else if (aDispStr.IsEqual ("blend")) |
| 4800 | aTextType = Aspect_TODT_BLEND; |
| 4801 | else if (aDispStr.IsEqual ("dimension")) |
| 4802 | aTextType = Aspect_TODT_DIMENSION; |
| 4803 | |
| 4804 | // subtitle color |
| 4805 | Quantity_Parameter aSubRed = 1.0; |
| 4806 | Quantity_Parameter aSubGreen = 1.0; |
| 4807 | Quantity_Parameter aSubBlue = 1.0; |
| 4808 | if (argc == 13) |
| 4809 | { |
| 4810 | aSubRed = Draw::Atof (argv[10])/255.; |
| 4811 | aSubGreen = Draw::Atof (argv[11])/255.; |
| 4812 | aSubBlue = Draw::Atof (argv[12])/255.; |
| 4813 | } |
| 4814 | |
| 4815 | // check fo current overlay |
| 4816 | Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer (); |
| 4817 | if (anOverlay.IsNull ()) |
| 4818 | { |
| 4819 | Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView); |
| 4820 | anOverlay = aMgr->Overlay (); |
| 4821 | aView->SetLayerMgr (aMgr); |
| 4822 | } |
| 4823 | |
| 4824 | Quantity_Color aTextColor (aColorRed, aColorGreen, |
| 4825 | aColorBlue, Quantity_TOC_RGB); |
| 4826 | Quantity_Color aSubtColor (aSubRed, aSubGreen, |
| 4827 | aSubBlue, Quantity_TOC_RGB); |
| 4828 | |
| 4829 | // add text item |
| 4830 | Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY, |
| 4831 | aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay); |
| 4832 | |
| 4833 | // update view |
| 4834 | aView->MustBeResized(); |
| 4835 | aView->Redraw(); |
| 4836 | |
| 4837 | return 0; |
| 4838 | } |
| 4839 | |
| 4840 | //============================================================================== |
| 4841 | //function : VGrid |
| 4842 | //purpose : |
| 4843 | //============================================================================== |
| 4844 | |
| 4845 | static int VGrid (Draw_Interpretor& /*theDI*/, |
| 4846 | Standard_Integer theArgNb, |
| 4847 | const char** theArgVec) |
| 4848 | { |
| 4849 | // get the active view |
| 4850 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 4851 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); |
| 4852 | if (aView.IsNull() || aViewer.IsNull()) |
| 4853 | { |
| 4854 | std::cerr << "No active view. Please call vinit.\n"; |
| 4855 | return 1; |
| 4856 | } |
| 4857 | |
| 4858 | Aspect_GridType aType = aViewer->GridType(); |
| 4859 | Aspect_GridDrawMode aMode = aViewer->GridDrawMode(); |
| 4860 | |
| 4861 | Standard_Integer anIter = 1; |
| 4862 | for (; anIter < theArgNb; ++anIter) |
| 4863 | { |
| 4864 | const char* aValue = theArgVec[anIter]; |
| 4865 | if (*aValue == 'r') |
| 4866 | { |
| 4867 | aType = Aspect_GT_Rectangular; |
| 4868 | } |
| 4869 | else if (*aValue == 'c') |
| 4870 | { |
| 4871 | aType = Aspect_GT_Circular; |
| 4872 | } |
| 4873 | else if (*aValue == 'l') |
| 4874 | { |
| 4875 | aMode = Aspect_GDM_Lines; |
| 4876 | } |
| 4877 | else if (*aValue == 'p') |
| 4878 | { |
| 4879 | aMode = Aspect_GDM_Points; |
| 4880 | } |
| 4881 | else if (strcmp (aValue, "off" ) == 0) |
| 4882 | { |
| 4883 | aViewer->DeactivateGrid(); |
| 4884 | return 0; |
| 4885 | } |
| 4886 | else |
| 4887 | { |
| 4888 | break; |
| 4889 | } |
| 4890 | } |
| 4891 | |
| 4892 | Standard_Integer aTail = (theArgNb - anIter); |
| 4893 | if (aTail == 0) |
| 4894 | { |
| 4895 | aViewer->ActivateGrid (aType, aMode); |
| 4896 | return 0; |
| 4897 | } |
| 4898 | else if (aTail != 2 && aTail != 5) |
| 4899 | { |
| 4900 | std::cerr << "Incorrect arguments number! Usage:\n" |
| 4901 | << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n"; |
| 4902 | return 1; |
| 4903 | } |
| 4904 | |
| 4905 | Quantity_Length anOriginX, anOriginY; |
| 4906 | Quantity_PlaneAngle aRotAngle; |
| 4907 | if (aType == Aspect_GT_Rectangular) |
| 4908 | { |
| 4909 | Quantity_Length aRStepX, aRStepY; |
| 4910 | aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); |
| 4911 | |
| 4912 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
| 4913 | anOriginY = Draw::Atof (theArgVec[anIter++]); |
| 4914 | if (aTail == 5) |
| 4915 | { |
| 4916 | aRStepX = Draw::Atof (theArgVec[anIter++]); |
| 4917 | aRStepY = Draw::Atof (theArgVec[anIter++]); |
| 4918 | aRotAngle = Draw::Atof (theArgVec[anIter++]); |
| 4919 | } |
| 4920 | aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); |
| 4921 | aViewer->ActivateGrid (aType, aMode); |
| 4922 | } |
| 4923 | else if (aType == Aspect_GT_Circular) |
| 4924 | { |
| 4925 | Quantity_Length aRadiusStep; |
| 4926 | Standard_Integer aDivisionNumber; |
| 4927 | aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); |
| 4928 | |
| 4929 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
| 4930 | anOriginY = Draw::Atof (theArgVec[anIter++]); |
| 4931 | if (aTail == 5) |
| 4932 | { |
| 4933 | aRadiusStep = Draw::Atof (theArgVec[anIter++]); |
| 4934 | aDivisionNumber = Draw::Atoi (theArgVec[anIter++]); |
| 4935 | aRotAngle = Draw::Atof (theArgVec[anIter++]); |
| 4936 | } |
| 4937 | |
| 4938 | aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); |
| 4939 | aViewer->ActivateGrid (aType, aMode); |
| 4940 | } |
| 4941 | |
| 4942 | return 0; |
| 4943 | } |
| 4944 | |
| 4945 | //============================================================================== |
| 4946 | //function : VPriviledgedPlane |
| 4947 | //purpose : |
| 4948 | //============================================================================== |
| 4949 | |
| 4950 | static int VPriviledgedPlane (Draw_Interpretor& theDI, |
| 4951 | Standard_Integer theArgNb, |
| 4952 | const char** theArgVec) |
| 4953 | { |
| 4954 | if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10) |
| 4955 | { |
| 4956 | std::cerr << "Error: wrong number of arguments! See usage:\n"; |
| 4957 | theDI.PrintHelp (theArgVec[0]); |
| 4958 | return 1; |
| 4959 | } |
| 4960 | |
| 4961 | // get the active viewer |
| 4962 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); |
| 4963 | if (aViewer.IsNull()) |
| 4964 | { |
| 4965 | std::cerr << "Error: no active viewer. Please call vinit.\n"; |
| 4966 | return 1; |
| 4967 | } |
| 4968 | |
| 4969 | if (theArgNb == 1) |
| 4970 | { |
| 4971 | gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane(); |
| 4972 | const gp_Pnt& anOrig = aPriviledgedPlane.Location(); |
| 4973 | const gp_Dir& aNorm = aPriviledgedPlane.Direction(); |
| 4974 | const gp_Dir& aXDir = aPriviledgedPlane.XDirection(); |
| 4975 | theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " " |
| 4976 | << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " " |
| 4977 | << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n"; |
| 4978 | return 0; |
| 4979 | } |
| 4980 | |
| 4981 | Standard_Integer anArgIdx = 1; |
| 4982 | Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]); |
| 4983 | Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]); |
| 4984 | Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]); |
| 4985 | Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]); |
| 4986 | Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]); |
| 4987 | Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]); |
| 4988 | |
| 4989 | gp_Ax3 aPriviledgedPlane; |
| 4990 | gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ); |
| 4991 | gp_Dir aNorm (aNormX, aNormY, aNormZ); |
| 4992 | if (theArgNb > 7) |
| 4993 | { |
| 4994 | Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]); |
| 4995 | Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]); |
| 4996 | Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]); |
| 4997 | gp_Dir aXDir (aXDirX, aXDirY, aXDirZ); |
| 4998 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir); |
| 4999 | } |
| 5000 | else |
| 5001 | { |
| 5002 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm); |
| 5003 | } |
| 5004 | |
| 5005 | aViewer->SetPrivilegedPlane (aPriviledgedPlane); |
| 5006 | |
| 5007 | return 0; |
| 5008 | } |
| 5009 | |
| 5010 | //============================================================================== |
| 5011 | //function : VConvert |
| 5012 | //purpose : |
| 5013 | //============================================================================== |
| 5014 | |
| 5015 | static int VConvert (Draw_Interpretor& theDI, |
| 5016 | Standard_Integer theArgNb, |
| 5017 | const char** theArgVec) |
| 5018 | { |
| 5019 | // get the active view |
| 5020 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 5021 | if (aView.IsNull()) |
| 5022 | { |
| 5023 | std::cerr << "Error: no active view. Please call vinit.\n"; |
| 5024 | return 1; |
| 5025 | } |
| 5026 | |
| 5027 | enum { Model, Ray, View, Window, Grid } aMode = Model; |
| 5028 | |
| 5029 | // access coordinate arguments |
| 5030 | TColStd_SequenceOfReal aCoord; |
| 5031 | Standard_Integer anArgIdx = 1; |
| 5032 | for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx) |
| 5033 | { |
| 5034 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); |
| 5035 | if (!anArg.IsRealValue()) |
| 5036 | { |
| 5037 | break; |
| 5038 | } |
| 5039 | aCoord.Append (anArg.RealValue()); |
| 5040 | } |
| 5041 | |
| 5042 | // non-numeric argument too early |
| 5043 | if (aCoord.IsEmpty()) |
| 5044 | { |
| 5045 | std::cerr << "Error: wrong number of arguments! See usage:\n"; |
| 5046 | theDI.PrintHelp (theArgVec[0]); |
| 5047 | return 1; |
| 5048 | } |
| 5049 | |
| 5050 | // collect all other arguments and options |
| 5051 | for (; anArgIdx < theArgNb; ++anArgIdx) |
| 5052 | { |
| 5053 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); |
| 5054 | anArg.LowerCase(); |
| 5055 | if (anArg == "window") aMode = Window; |
| 5056 | else if (anArg == "view") aMode = View; |
| 5057 | else if (anArg == "grid") aMode = Grid; |
| 5058 | else if (anArg == "ray") aMode = Ray; |
| 5059 | else |
| 5060 | { |
| 5061 | std::cerr << "Error: wrong argument " << anArg << "! See usage:\n"; |
| 5062 | theDI.PrintHelp (theArgVec[0]); |
| 5063 | return 1; |
| 5064 | } |
| 5065 | } |
| 5066 | |
| 5067 | // complete input checks |
| 5068 | if ((aCoord.Length() == 1 && theArgNb > 3) || |
| 5069 | (aCoord.Length() == 2 && theArgNb > 4) || |
| 5070 | (aCoord.Length() == 3 && theArgNb > 5)) |
| 5071 | { |
| 5072 | std::cerr << "Error: wrong number of arguments! See usage:\n"; |
| 5073 | theDI.PrintHelp (theArgVec[0]); |
| 5074 | return 1; |
| 5075 | } |
| 5076 | |
| 5077 | Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; |
| 5078 | Standard_Integer aXYp[2] = {0, 0}; |
| 5079 | |
| 5080 | // convert one-dimensional coordinate |
| 5081 | if (aCoord.Length() == 1) |
| 5082 | { |
| 5083 | switch (aMode) |
| 5084 | { |
| 5085 | case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0; |
| 5086 | case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0; |
| 5087 | default: |
| 5088 | std::cerr << "Error: wrong arguments! See usage:\n"; |
| 5089 | theDI.PrintHelp (theArgVec[0]); |
| 5090 | return 1; |
| 5091 | } |
| 5092 | } |
| 5093 | |
| 5094 | // convert 2D coordinates from projection or view reference space |
| 5095 | if (aCoord.Length() == 2) |
| 5096 | { |
| 5097 | switch (aMode) |
| 5098 | { |
| 5099 | case Model : |
| 5100 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); |
| 5101 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; |
| 5102 | return 0; |
| 5103 | |
| 5104 | case View : |
| 5105 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]); |
| 5106 | theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n"; |
| 5107 | return 0; |
| 5108 | |
| 5109 | case Window : |
| 5110 | aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]); |
| 5111 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; |
| 5112 | return 0; |
| 5113 | |
| 5114 | case Grid : |
| 5115 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); |
| 5116 | aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]); |
| 5117 | theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; |
| 5118 | return 0; |
| 5119 | |
| 5120 | case Ray : |
| 5121 | aView->ConvertWithProj ((Standard_Integer) aCoord (1), |
| 5122 | (Standard_Integer) aCoord (2), |
| 5123 | aXYZ[0], aXYZ[1], aXYZ[2], |
| 5124 | aXYZ[3], aXYZ[4], aXYZ[5]); |
| 5125 | theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; |
| 5126 | return 0; |
| 5127 | |
| 5128 | default: |
| 5129 | std::cerr << "Error: wrong arguments! See usage:\n"; |
| 5130 | theDI.PrintHelp (theArgVec[0]); |
| 5131 | return 1; |
| 5132 | } |
| 5133 | } |
| 5134 | |
| 5135 | // convert 3D coordinates from view reference space |
| 5136 | else if (aCoord.Length() == 3) |
| 5137 | { |
| 5138 | switch (aMode) |
| 5139 | { |
| 5140 | case Window : |
| 5141 | aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]); |
| 5142 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; |
| 5143 | return 0; |
| 5144 | |
| 5145 | case Grid : |
| 5146 | aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]); |
| 5147 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; |
| 5148 | return 0; |
| 5149 | |
| 5150 | default: |
| 5151 | std::cerr << "Error: wrong arguments! See usage:\n"; |
| 5152 | theDI.PrintHelp (theArgVec[0]); |
| 5153 | return 1; |
| 5154 | } |
| 5155 | } |
| 5156 | |
| 5157 | return 0; |
| 5158 | } |
| 5159 | |
| 5160 | //============================================================================== |
| 5161 | //function : VFps |
| 5162 | //purpose : |
| 5163 | //============================================================================== |
| 5164 | |
| 5165 | static int VFps (Draw_Interpretor& theDI, |
| 5166 | Standard_Integer theArgNb, |
| 5167 | const char** theArgVec) |
| 5168 | { |
| 5169 | // get the active view |
| 5170 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 5171 | if (aView.IsNull()) |
| 5172 | { |
| 5173 | std::cerr << "No active view. Please call vinit.\n"; |
| 5174 | return 1; |
| 5175 | } |
| 5176 | |
| 5177 | Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100; |
| 5178 | if (aFramesNb <= 0) |
| 5179 | { |
| 5180 | std::cerr << "Incorrect arguments!\n"; |
| 5181 | return 1; |
| 5182 | } |
| 5183 | |
| 5184 | // the time is meaningless for first call |
| 5185 | // due to async OpenGl rendering |
| 5186 | aView->Redraw(); |
| 5187 | |
| 5188 | // redraw view in loop to estimate average values |
| 5189 | OSD_Timer aTimer; |
| 5190 | aTimer.Start(); |
| 5191 | for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter) |
| 5192 | { |
| 5193 | aView->Redraw(); |
| 5194 | } |
| 5195 | aTimer.Stop(); |
| 5196 | Standard_Real aCpu; |
| 5197 | const Standard_Real aTime = aTimer.ElapsedTime(); |
| 5198 | aTimer.OSD_Chronometer::Show (aCpu); |
| 5199 | |
| 5200 | const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime; |
| 5201 | const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb); |
| 5202 | |
| 5203 | // return statistics |
| 5204 | theDI << "FPS: " << aFpsAver << "\n" |
| 5205 | << "CPU: " << (1000.0 * aCpuAver) << " msec\n"; |
| 5206 | |
| 5207 | return 0; |
| 5208 | } |
| 5209 | |
| 5210 | //============================================================================== |
| 5211 | //function : VGlDebug |
| 5212 | //purpose : |
| 5213 | //============================================================================== |
| 5214 | |
| 5215 | static int VGlDebug (Draw_Interpretor& theDI, |
| 5216 | Standard_Integer theArgNb, |
| 5217 | const char** theArgVec) |
| 5218 | { |
| 5219 | Handle(OpenGl_GraphicDriver) aDriver; |
| 5220 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 5221 | if (!aView.IsNull()) |
| 5222 | { |
| 5223 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver()); |
| 5224 | } |
| 5225 | OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps; |
| 5226 | OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL; |
| 5227 | |
| 5228 | if (theArgNb < 2) |
| 5229 | { |
| 5230 | TCollection_AsciiString aDebActive, aSyncActive; |
| 5231 | if (aCaps == NULL) |
| 5232 | { |
| 5233 | aCaps = aDefCaps; |
| 5234 | } |
| 5235 | else |
| 5236 | { |
| 5237 | Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS), |
| 5238 | "GL_ARB_debug_output"); |
| 5239 | aDebActive = isActive ? " (active)" : " (inactive)"; |
| 5240 | if (isActive) |
| 5241 | { |
| 5242 | // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB |
| 5243 | aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)"; |
| 5244 | } |
| 5245 | } |
| 5246 | |
| 5247 | theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n" |
| 5248 | << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n" |
| 5249 | << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n" |
| 5250 | << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n"; |
| 5251 | return 0; |
| 5252 | } |
| 5253 | |
| 5254 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
| 5255 | { |
| 5256 | Standard_CString anArg = theArgVec[anArgIter]; |
| 5257 | TCollection_AsciiString anArgCase (anArg); |
| 5258 | anArgCase.LowerCase(); |
| 5259 | Standard_Boolean toEnableDebug = Standard_True; |
| 5260 | if (anArgCase == "-glsl" |
| 5261 | || anArgCase == "-glslwarn" |
| 5262 | || anArgCase == "-glslwarns" |
| 5263 | || anArgCase == "-glslwarnings") |
| 5264 | { |
| 5265 | Standard_Boolean toShowWarns = Standard_True; |
| 5266 | if (++anArgIter < theArgNb |
| 5267 | && !parseOnOff (theArgVec[anArgIter], toShowWarns)) |
| 5268 | { |
| 5269 | --anArgIter; |
| 5270 | } |
| 5271 | aDefCaps->glslWarnings = toShowWarns; |
| 5272 | if (aCaps != NULL) |
| 5273 | { |
| 5274 | aCaps->glslWarnings = toShowWarns; |
| 5275 | } |
| 5276 | } |
| 5277 | else if (anArgCase == "-extra" |
| 5278 | || anArgCase == "-extramsg" |
| 5279 | || anArgCase == "-extramessages") |
| 5280 | { |
| 5281 | Standard_Boolean toShow = Standard_True; |
| 5282 | if (++anArgIter < theArgNb |
| 5283 | && !parseOnOff (theArgVec[anArgIter], toShow)) |
| 5284 | { |
| 5285 | --anArgIter; |
| 5286 | } |
| 5287 | aDefCaps->suppressExtraMsg = !toShow; |
| 5288 | if (aCaps != NULL) |
| 5289 | { |
| 5290 | aCaps->suppressExtraMsg = !toShow; |
| 5291 | } |
| 5292 | } |
| 5293 | else if (anArgCase == "-noextra" |
| 5294 | || anArgCase == "-noextramsg" |
| 5295 | || anArgCase == "-noextramessages") |
| 5296 | { |
| 5297 | Standard_Boolean toSuppress = Standard_True; |
| 5298 | if (++anArgIter < theArgNb |
| 5299 | && !parseOnOff (theArgVec[anArgIter], toSuppress)) |
| 5300 | { |
| 5301 | --anArgIter; |
| 5302 | } |
| 5303 | aDefCaps->suppressExtraMsg = toSuppress; |
| 5304 | if (aCaps != NULL) |
| 5305 | { |
| 5306 | aCaps->suppressExtraMsg = toSuppress; |
| 5307 | } |
| 5308 | } |
| 5309 | else if (anArgCase == "-sync") |
| 5310 | { |
| 5311 | Standard_Boolean toSync = Standard_True; |
| 5312 | if (++anArgIter < theArgNb |
| 5313 | && !parseOnOff (theArgVec[anArgIter], toSync)) |
| 5314 | { |
| 5315 | --anArgIter; |
| 5316 | } |
| 5317 | aDefCaps->contextSyncDebug = toSync; |
| 5318 | if (toSync) |
| 5319 | { |
| 5320 | aDefCaps->contextDebug = Standard_True; |
| 5321 | } |
| 5322 | } |
| 5323 | else if (anArgCase == "-debug") |
| 5324 | { |
| 5325 | if (++anArgIter < theArgNb |
| 5326 | && !parseOnOff (theArgVec[anArgIter], toEnableDebug)) |
| 5327 | { |
| 5328 | --anArgIter; |
| 5329 | } |
| 5330 | aDefCaps->contextDebug = toEnableDebug; |
| 5331 | } |
| 5332 | else if (parseOnOff (anArg, toEnableDebug) |
| 5333 | && (anArgIter + 1 == theArgNb)) |
| 5334 | { |
| 5335 | // simple alias to turn on almost everything |
| 5336 | aDefCaps->contextDebug = toEnableDebug; |
| 5337 | aDefCaps->contextSyncDebug = toEnableDebug; |
| 5338 | aDefCaps->glslWarnings = toEnableDebug; |
| 5339 | } |
| 5340 | else |
| 5341 | { |
| 5342 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; |
| 5343 | return 1; |
| 5344 | } |
| 5345 | } |
| 5346 | |
| 5347 | return 0; |
| 5348 | } |
| 5349 | |
| 5350 | //============================================================================== |
| 5351 | //function : VVbo |
| 5352 | //purpose : |
| 5353 | //============================================================================== |
| 5354 | |
| 5355 | static int VVbo (Draw_Interpretor& theDI, |
| 5356 | Standard_Integer theArgNb, |
| 5357 | const char** theArgVec) |
| 5358 | { |
| 5359 | const Standard_Boolean toSet = (theArgNb > 1); |
| 5360 | const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1; |
| 5361 | if (toSet) |
| 5362 | { |
| 5363 | ViewerTest_myDefaultCaps.vboDisable = toUseVbo; |
| 5364 | } |
| 5365 | |
| 5366 | // get the context |
| 5367 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); |
| 5368 | if (aContextAIS.IsNull()) |
| 5369 | { |
| 5370 | if (!toSet) |
| 5371 | { |
| 5372 | std::cerr << "No active view!\n"; |
| 5373 | } |
| 5374 | return 1; |
| 5375 | } |
| 5376 | Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver()); |
| 5377 | if (!aDriver.IsNull()) |
| 5378 | { |
| 5379 | if (!toSet) |
| 5380 | { |
| 5381 | theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n"; |
| 5382 | } |
| 5383 | else |
| 5384 | { |
| 5385 | aDriver->ChangeOptions().vboDisable = toUseVbo; |
| 5386 | } |
| 5387 | } |
| 5388 | |
| 5389 | return 0; |
| 5390 | } |
| 5391 | |
| 5392 | //============================================================================== |
| 5393 | //function : VCaps |
| 5394 | //purpose : |
| 5395 | //============================================================================== |
| 5396 | |
| 5397 | static int VCaps (Draw_Interpretor& theDI, |
| 5398 | Standard_Integer theArgNb, |
| 5399 | const char** theArgVec) |
| 5400 | { |
| 5401 | OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps; |
| 5402 | Handle(OpenGl_GraphicDriver) aDriver; |
| 5403 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 5404 | if (!aContext.IsNull()) |
| 5405 | { |
| 5406 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver()); |
| 5407 | aCaps = &aDriver->ChangeOptions(); |
| 5408 | } |
| 5409 | |
| 5410 | if (theArgNb < 2) |
| 5411 | { |
| 5412 | theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n"; |
| 5413 | theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n"; |
| 5414 | theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n"; |
| 5415 | theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n"; |
| 5416 | theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n"; |
| 5417 | return 0; |
| 5418 | } |
| 5419 | |
| 5420 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
| 5421 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
| 5422 | { |
| 5423 | Standard_CString anArg = theArgVec[anArgIter]; |
| 5424 | TCollection_AsciiString anArgCase (anArg); |
| 5425 | anArgCase.LowerCase(); |
| 5426 | if (anUpdateTool.parseRedrawMode (anArg)) |
| 5427 | { |
| 5428 | continue; |
| 5429 | } |
| 5430 | else if (anArgCase == "-ffp") |
| 5431 | { |
| 5432 | Standard_Boolean toEnable = Standard_True; |
| 5433 | if (++anArgIter < theArgNb |
| 5434 | && !parseOnOff (theArgVec[anArgIter], toEnable)) |
| 5435 | { |
| 5436 | --anArgIter; |
| 5437 | } |
| 5438 | aCaps->ffpEnable = toEnable; |
| 5439 | } |
| 5440 | else if (anArgCase == "-vbo") |
| 5441 | { |
| 5442 | Standard_Boolean toEnable = Standard_True; |
| 5443 | if (++anArgIter < theArgNb |
| 5444 | && !parseOnOff (theArgVec[anArgIter], toEnable)) |
| 5445 | { |
| 5446 | --anArgIter; |
| 5447 | } |
| 5448 | aCaps->vboDisable = !toEnable; |
| 5449 | } |
| 5450 | else if (anArgCase == "-sprite" |
| 5451 | || anArgCase == "-sprites") |
| 5452 | { |
| 5453 | Standard_Boolean toEnable = Standard_True; |
| 5454 | if (++anArgIter < theArgNb |
| 5455 | && !parseOnOff (theArgVec[anArgIter], toEnable)) |
| 5456 | { |
| 5457 | --anArgIter; |
| 5458 | } |
| 5459 | aCaps->pntSpritesDisable = !toEnable; |
| 5460 | } |
| 5461 | else if (anArgCase == "-softmode") |
| 5462 | { |
| 5463 | Standard_Boolean toEnable = Standard_True; |
| 5464 | if (++anArgIter < theArgNb |
| 5465 | && !parseOnOff (theArgVec[anArgIter], toEnable)) |
| 5466 | { |
| 5467 | --anArgIter; |
| 5468 | } |
| 5469 | aCaps->contextNoAccel = toEnable; |
| 5470 | } |
| 5471 | else if (anArgCase == "-accel" |
| 5472 | || anArgCase == "-acceleration") |
| 5473 | { |
| 5474 | Standard_Boolean toEnable = Standard_True; |
| 5475 | if (++anArgIter < theArgNb |
| 5476 | && !parseOnOff (theArgVec[anArgIter], toEnable)) |
| 5477 | { |
| 5478 | --anArgIter; |
| 5479 | } |
| 5480 | aCaps->contextNoAccel = !toEnable; |
| 5481 | } |
| 5482 | else if (anArgCase == "-compat" |
| 5483 | || anArgCase == "-compatprofile" |
| 5484 | || anArgCase == "-compatible" |
| 5485 | || anArgCase == "-compatibleprofile") |
| 5486 | { |
| 5487 | Standard_Boolean toEnable = Standard_True; |
| 5488 | if (++anArgIter < theArgNb |
| 5489 | && !parseOnOff (theArgVec[anArgIter], toEnable)) |
| 5490 | { |
| 5491 | --anArgIter; |
| 5492 | } |
| 5493 | aCaps->contextCompatible = toEnable; |
| 5494 | if (!aCaps->contextCompatible) |
| 5495 | { |
| 5496 | aCaps->ffpEnable = Standard_False; |
| 5497 | } |
| 5498 | } |
| 5499 | else if (anArgCase == "-core" |
| 5500 | || anArgCase == "-coreprofile") |
| 5501 | { |
| 5502 | Standard_Boolean toEnable = Standard_True; |
| 5503 | if (++anArgIter < theArgNb |
| 5504 | && !parseOnOff (theArgVec[anArgIter], toEnable)) |
| 5505 | { |
| 5506 | --anArgIter; |
| 5507 | } |
| 5508 | aCaps->contextCompatible = !toEnable; |
| 5509 | if (!aCaps->contextCompatible) |
| 5510 | { |
| 5511 | aCaps->ffpEnable = Standard_False; |
| 5512 | } |
| 5513 | } |
| 5514 | else |
| 5515 | { |
| 5516 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
| 5517 | return 1; |
| 5518 | } |
| 5519 | } |
| 5520 | if (aCaps != &ViewerTest_myDefaultCaps) |
| 5521 | { |
| 5522 | ViewerTest_myDefaultCaps = *aCaps; |
| 5523 | } |
| 5524 | return 0; |
| 5525 | } |
| 5526 | |
| 5527 | //============================================================================== |
| 5528 | //function : VMemGpu |
| 5529 | //purpose : |
| 5530 | //============================================================================== |
| 5531 | |
| 5532 | static int VMemGpu (Draw_Interpretor& theDI, |
| 5533 | Standard_Integer theArgNb, |
| 5534 | const char** theArgVec) |
| 5535 | { |
| 5536 | // get the context |
| 5537 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); |
| 5538 | if (aContextAIS.IsNull()) |
| 5539 | { |
| 5540 | std::cerr << "No active view. Please call vinit.\n"; |
| 5541 | return 1; |
| 5542 | } |
| 5543 | |
| 5544 | Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver(); |
| 5545 | if (aDriver.IsNull()) |
| 5546 | { |
| 5547 | std::cerr << "Graphic driver not available.\n"; |
| 5548 | return 1; |
| 5549 | } |
| 5550 | |
| 5551 | Standard_Size aFreeBytes = 0; |
| 5552 | TCollection_AsciiString anInfo; |
| 5553 | if (!aDriver->MemoryInfo (aFreeBytes, anInfo)) |
| 5554 | { |
| 5555 | std::cerr << "Information not available.\n"; |
| 5556 | return 1; |
| 5557 | } |
| 5558 | |
| 5559 | if (theArgNb > 1 && *theArgVec[1] == 'f') |
| 5560 | { |
| 5561 | theDI << Standard_Real (aFreeBytes); |
| 5562 | } |
| 5563 | else |
| 5564 | { |
| 5565 | theDI << anInfo; |
| 5566 | } |
| 5567 | |
| 5568 | return 0; |
| 5569 | } |
| 5570 | |
| 5571 | // ============================================================================== |
| 5572 | // function : VReadPixel |
| 5573 | // purpose : |
| 5574 | // ============================================================================== |
| 5575 | static int VReadPixel (Draw_Interpretor& theDI, |
| 5576 | Standard_Integer theArgNb, |
| 5577 | const char** theArgVec) |
| 5578 | { |
| 5579 | // get the active view |
| 5580 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 5581 | if (aView.IsNull()) |
| 5582 | { |
| 5583 | std::cerr << "No active view. Please call vinit.\n"; |
| 5584 | return 1; |
| 5585 | } |
| 5586 | else if (theArgNb < 3) |
| 5587 | { |
| 5588 | std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n"; |
| 5589 | return 1; |
| 5590 | } |
| 5591 | |
| 5592 | Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; |
| 5593 | Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA; |
| 5594 | |
| 5595 | Standard_Integer aWidth, aHeight; |
| 5596 | aView->Window()->Size (aWidth, aHeight); |
| 5597 | const Standard_Integer anX = Draw::Atoi (theArgVec[1]); |
| 5598 | const Standard_Integer anY = Draw::Atoi (theArgVec[2]); |
| 5599 | if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight) |
| 5600 | { |
| 5601 | std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n"; |
| 5602 | return 1; |
| 5603 | } |
| 5604 | |
| 5605 | Standard_Boolean toShowName = Standard_False; |
| 5606 | Standard_Boolean toShowHls = Standard_False; |
| 5607 | for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter) |
| 5608 | { |
| 5609 | const char* aParam = theArgVec[anIter]; |
| 5610 | if ( strcasecmp( aParam, "rgb" ) == 0 ) |
| 5611 | { |
| 5612 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; |
| 5613 | aBufferType = Graphic3d_BT_RGB; |
| 5614 | } |
| 5615 | else if ( strcasecmp( aParam, "hls" ) == 0 ) |
| 5616 | { |
| 5617 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; |
| 5618 | aBufferType = Graphic3d_BT_RGB; |
| 5619 | toShowHls = Standard_True; |
| 5620 | } |
| 5621 | else if ( strcasecmp( aParam, "rgbf" ) == 0 ) |
| 5622 | { |
| 5623 | aFormat = Image_PixMap::ImgRGBF; |
| 5624 | aBufferType = Graphic3d_BT_RGB; |
| 5625 | } |
| 5626 | else if ( strcasecmp( aParam, "rgba" ) == 0 ) |
| 5627 | { |
| 5628 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; |
| 5629 | aBufferType = Graphic3d_BT_RGBA; |
| 5630 | } |
| 5631 | else if ( strcasecmp( aParam, "rgbaf" ) == 0 ) |
| 5632 | { |
| 5633 | aFormat = Image_PixMap::ImgRGBAF; |
| 5634 | aBufferType = Graphic3d_BT_RGBA; |
| 5635 | } |
| 5636 | else if ( strcasecmp( aParam, "depth" ) == 0 ) |
| 5637 | { |
| 5638 | aFormat = Image_PixMap::ImgGrayF; |
| 5639 | aBufferType = Graphic3d_BT_Depth; |
| 5640 | } |
| 5641 | else if ( strcasecmp( aParam, "name" ) == 0 ) |
| 5642 | { |
| 5643 | toShowName = Standard_True; |
| 5644 | } |
| 5645 | } |
| 5646 | |
| 5647 | Image_PixMap anImage; |
| 5648 | if (!anImage.InitTrash (aFormat, aWidth, aHeight)) |
| 5649 | { |
| 5650 | std::cerr << "Image allocation failed\n"; |
| 5651 | return 1; |
| 5652 | } |
| 5653 | else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType)) |
| 5654 | { |
| 5655 | std::cerr << "Image dump failed\n"; |
| 5656 | return 1; |
| 5657 | } |
| 5658 | |
| 5659 | Quantity_Parameter anAlpha; |
| 5660 | Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha); |
| 5661 | if (toShowName) |
| 5662 | { |
| 5663 | if (aBufferType == Graphic3d_BT_RGBA) |
| 5664 | { |
| 5665 | theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha; |
| 5666 | } |
| 5667 | else |
| 5668 | { |
| 5669 | theDI << Quantity_Color::StringName (aColor.Name()); |
| 5670 | } |
| 5671 | } |
| 5672 | else |
| 5673 | { |
| 5674 | switch (aBufferType) |
| 5675 | { |
| 5676 | default: |
| 5677 | case Graphic3d_BT_RGB: |
| 5678 | { |
| 5679 | if (toShowHls) |
| 5680 | { |
| 5681 | theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation(); |
| 5682 | } |
| 5683 | else |
| 5684 | { |
| 5685 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue(); |
| 5686 | } |
| 5687 | break; |
| 5688 | } |
| 5689 | case Graphic3d_BT_RGBA: |
| 5690 | { |
| 5691 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha; |
| 5692 | break; |
| 5693 | } |
| 5694 | case Graphic3d_BT_Depth: |
| 5695 | { |
| 5696 | theDI << aColor.Red(); |
| 5697 | break; |
| 5698 | } |
| 5699 | } |
| 5700 | } |
| 5701 | |
| 5702 | return 0; |
| 5703 | } |
| 5704 | |
| 5705 | //============================================================================== |
| 5706 | //function : VDiffImage |
| 5707 | //purpose : The draw-command compares two images. |
| 5708 | //============================================================================== |
| 5709 | |
| 5710 | static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) |
| 5711 | { |
| 5712 | if (theArgNb < 6) |
| 5713 | { |
| 5714 | theDI << "Not enough arguments.\n"; |
| 5715 | return 1; |
| 5716 | } |
| 5717 | |
| 5718 | // image file names |
| 5719 | const char* anImgPathRef = theArgVec[1]; |
| 5720 | const char* anImgPathNew = theArgVec[2]; |
| 5721 | |
| 5722 | // get string tolerance and check its validity |
| 5723 | Standard_Real aTolColor = Draw::Atof (theArgVec[3]); |
| 5724 | if (aTolColor < 0.0) |
| 5725 | aTolColor = 0.0; |
| 5726 | if (aTolColor > 1.0) |
| 5727 | aTolColor = 1.0; |
| 5728 | |
| 5729 | Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1); |
| 5730 | Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1); |
| 5731 | |
| 5732 | // image file of difference |
| 5733 | const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL; |
| 5734 | |
| 5735 | // compare the images |
| 5736 | Image_Diff aComparer; |
| 5737 | if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite)) |
| 5738 | { |
| 5739 | return 1; |
| 5740 | } |
| 5741 | |
| 5742 | aComparer.SetColorTolerance (aTolColor); |
| 5743 | aComparer.SetBorderFilterOn (isBorderFilterOn); |
| 5744 | Standard_Integer aDiffColorsNb = aComparer.Compare(); |
| 5745 | theDI << aDiffColorsNb << "\n"; |
| 5746 | |
| 5747 | // save image of difference |
| 5748 | if (aDiffColorsNb >0 && aDiffImagePath != NULL) |
| 5749 | { |
| 5750 | aComparer.SaveDiffImage (aDiffImagePath); |
| 5751 | } |
| 5752 | |
| 5753 | return 0; |
| 5754 | } |
| 5755 | |
| 5756 | //======================================================================= |
| 5757 | //function : VSelect |
| 5758 | //purpose : Emulates different types of selection by mouse: |
| 5759 | // 1) single click selection |
| 5760 | // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2) |
| 5761 | // 3) selection with polygon having corners at |
| 5762 | // pixel positions (x1,y1),...,(xn,yn) |
| 5763 | // 4) any of these selections with shift button pressed |
| 5764 | //======================================================================= |
| 5765 | static Standard_Integer VSelect (Draw_Interpretor& di, |
| 5766 | Standard_Integer argc, |
| 5767 | const char ** argv) |
| 5768 | { |
| 5769 | if(argc < 3) |
| 5770 | { |
| 5771 | di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n"; |
| 5772 | return 1; |
| 5773 | } |
| 5774 | |
| 5775 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); |
| 5776 | if(myAIScontext.IsNull()) |
| 5777 | { |
| 5778 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 5779 | return 1; |
| 5780 | } |
| 5781 | |
| 5782 | const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1)); |
| 5783 | Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1; |
| 5784 | TCollection_AsciiString anArg; |
| 5785 | anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2]; |
| 5786 | anArg.LowerCase(); |
| 5787 | if (anArg == "-allowoverlap") |
| 5788 | { |
| 5789 | Standard_Boolean isValidated = isShiftSelection ? argc == 8 |
| 5790 | : argc == 7; |
| 5791 | if (!isValidated) |
| 5792 | { |
| 5793 | di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection"; |
| 5794 | return 1; |
| 5795 | } |
| 5796 | |
| 5797 | Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]); |
| 5798 | myAIScontext->MainSelector()->AllowOverlapDetection((Standard_Boolean)isToAllow); |
| 5799 | aCoordsNb -= 2; |
| 5800 | } |
| 5801 | |
| 5802 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); |
| 5803 | aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2])); |
| 5804 | if(aCoordsNb == 2) |
| 5805 | { |
| 5806 | if(isShiftSelection) |
| 5807 | aCurrentEventManager->ShiftSelect(); |
| 5808 | else |
| 5809 | aCurrentEventManager->Select(); |
| 5810 | } |
| 5811 | else if(aCoordsNb == 4) |
| 5812 | { |
| 5813 | if(isShiftSelection) |
| 5814 | aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False); |
| 5815 | else |
| 5816 | aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False); |
| 5817 | } |
| 5818 | else |
| 5819 | { |
| 5820 | TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2); |
| 5821 | |
| 5822 | for(Standard_Integer i=1;i<=aCoordsNb / 2;++i) |
| 5823 | aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i]))); |
| 5824 | |
| 5825 | if(isShiftSelection) |
| 5826 | aCurrentEventManager->ShiftSelect(aPolyline); |
| 5827 | else |
| 5828 | aCurrentEventManager->Select(aPolyline); |
| 5829 | } |
| 5830 | return 0; |
| 5831 | } |
| 5832 | |
| 5833 | //======================================================================= |
| 5834 | //function : VMoveTo |
| 5835 | //purpose : Emulates cursor movement to defined pixel position |
| 5836 | //======================================================================= |
| 5837 | static Standard_Integer VMoveTo (Draw_Interpretor& di, |
| 5838 | Standard_Integer argc, |
| 5839 | const char ** argv) |
| 5840 | { |
| 5841 | if(argc != 3) |
| 5842 | { |
| 5843 | di << "Usage : " << argv[0] << " x y" << "\n"; |
| 5844 | return 1; |
| 5845 | } |
| 5846 | |
| 5847 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 5848 | if(aContext.IsNull()) |
| 5849 | { |
| 5850 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 5851 | return 1; |
| 5852 | } |
| 5853 | ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2])); |
| 5854 | return 0; |
| 5855 | } |
| 5856 | |
| 5857 | //================================================================================================= |
| 5858 | //function : VViewParams |
| 5859 | //purpose : Gets or sets AIS View characteristics |
| 5860 | //================================================================================================= |
| 5861 | static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
| 5862 | { |
| 5863 | Handle(V3d_View) anAISView = ViewerTest::CurrentView(); |
| 5864 | if (anAISView.IsNull()) |
| 5865 | { |
| 5866 | std::cout << theArgVec[0] << ": please initialize or activate view.\n"; |
| 5867 | return 1; |
| 5868 | } |
| 5869 | |
| 5870 | if (theArgsNb == 1) |
| 5871 | { |
| 5872 | // print all of the available view parameters |
| 5873 | Quantity_Factor anAISViewScale = anAISView->Scale(); |
| 5874 | |
| 5875 | Standard_Real anAISViewProjX = 0.0; |
| 5876 | Standard_Real anAISViewProjY = 0.0; |
| 5877 | Standard_Real anAISViewProjZ = 0.0; |
| 5878 | anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ); |
| 5879 | |
| 5880 | Standard_Real anAISViewUpX = 0.0; |
| 5881 | Standard_Real anAISViewUpY = 0.0; |
| 5882 | Standard_Real anAISViewUpZ = 0.0; |
| 5883 | anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ); |
| 5884 | |
| 5885 | Standard_Real anAISViewAtX = 0.0; |
| 5886 | Standard_Real anAISViewAtY = 0.0; |
| 5887 | Standard_Real anAISViewAtZ = 0.0; |
| 5888 | anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ); |
| 5889 | |
| 5890 | Standard_Real anAISViewEyeX = 0.0; |
| 5891 | Standard_Real anAISViewEyeY = 0.0; |
| 5892 | Standard_Real anAISViewEyeZ = 0.0; |
| 5893 | anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ); |
| 5894 | |
| 5895 | theDi << "Scale of current view: " << anAISViewScale << "\n"; |
| 5896 | theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n"; |
| 5897 | theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n"; |
| 5898 | theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n"; |
| 5899 | theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n"; |
| 5900 | return 0; |
| 5901 | } |
| 5902 | |
| 5903 | // ------------------------- |
| 5904 | // Parse options and values |
| 5905 | // ------------------------- |
| 5906 | |
| 5907 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues; |
| 5908 | TCollection_AsciiString aParseKey; |
| 5909 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) |
| 5910 | { |
| 5911 | TCollection_AsciiString anArg (theArgVec [anArgIt]); |
| 5912 | |
| 5913 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) |
| 5914 | { |
| 5915 | aParseKey = anArg; |
| 5916 | aParseKey.Remove (1); |
| 5917 | aParseKey.UpperCase(); |
| 5918 | aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); |
| 5919 | continue; |
| 5920 | } |
| 5921 | |
| 5922 | if (aParseKey.IsEmpty()) |
| 5923 | { |
| 5924 | std::cout << theArgVec[0] << ": values should be passed with key.\n"; |
| 5925 | std::cout << "Type help for more information.\n"; |
| 5926 | return 1; |
| 5927 | } |
| 5928 | |
| 5929 | aMapOfKeysByValues(aParseKey)->Append (anArg); |
| 5930 | } |
| 5931 | |
| 5932 | // --------------------------------------------- |
| 5933 | // Change or print parameters, order plays role |
| 5934 | // --------------------------------------------- |
| 5935 | |
| 5936 | // Check arguments for validity |
| 5937 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues); |
| 5938 | for (; aMapIt.More(); aMapIt.Next()) |
| 5939 | { |
| 5940 | const TCollection_AsciiString& aKey = aMapIt.Key(); |
| 5941 | const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value(); |
| 5942 | |
| 5943 | if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty())) |
| 5944 | && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty())) |
| 5945 | && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty())) |
| 5946 | && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty())) |
| 5947 | && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty())) |
| 5948 | && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty())) |
| 5949 | && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2)) |
| 5950 | { |
| 5951 | TCollection_AsciiString aLowerKey; |
| 5952 | aLowerKey = "-"; |
| 5953 | aLowerKey += aKey; |
| 5954 | aLowerKey.LowerCase(); |
| 5955 | std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n"; |
| 5956 | std::cout << "Type help for more information.\n"; |
| 5957 | return 1; |
| 5958 | } |
| 5959 | } |
| 5960 | |
| 5961 | Handle(TColStd_HSequenceOfAsciiString) aValues; |
| 5962 | |
| 5963 | // Change view parameters in proper order |
| 5964 | if (aMapOfKeysByValues.Find ("SCALE", aValues)) |
| 5965 | { |
| 5966 | if (aValues->IsEmpty()) |
| 5967 | { |
| 5968 | theDi << "Scale: " << anAISView->Scale() << "\n"; |
| 5969 | } |
| 5970 | else |
| 5971 | { |
| 5972 | anAISView->SetScale (aValues->Value(1).RealValue()); |
| 5973 | } |
| 5974 | } |
| 5975 | if (aMapOfKeysByValues.Find ("SIZE", aValues)) |
| 5976 | { |
| 5977 | if (aValues->IsEmpty()) |
| 5978 | { |
| 5979 | Standard_Real aSizeX = 0.0; |
| 5980 | Standard_Real aSizeY = 0.0; |
| 5981 | anAISView->Size (aSizeX, aSizeY); |
| 5982 | theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n"; |
| 5983 | } |
| 5984 | else |
| 5985 | { |
| 5986 | anAISView->SetSize (aValues->Value(1).RealValue()); |
| 5987 | } |
| 5988 | } |
| 5989 | if (aMapOfKeysByValues.Find ("EYE", aValues)) |
| 5990 | { |
| 5991 | if (aValues->IsEmpty()) |
| 5992 | { |
| 5993 | Standard_Real anEyeX = 0.0; |
| 5994 | Standard_Real anEyeY = 0.0; |
| 5995 | Standard_Real anEyeZ = 0.0; |
| 5996 | anAISView->Eye (anEyeX, anEyeY, anEyeZ); |
| 5997 | theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n"; |
| 5998 | } |
| 5999 | else |
| 6000 | { |
| 6001 | anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
| 6002 | } |
| 6003 | } |
| 6004 | if (aMapOfKeysByValues.Find ("AT", aValues)) |
| 6005 | { |
| 6006 | if (aValues->IsEmpty()) |
| 6007 | { |
| 6008 | Standard_Real anAtX = 0.0; |
| 6009 | Standard_Real anAtY = 0.0; |
| 6010 | Standard_Real anAtZ = 0.0; |
| 6011 | anAISView->At (anAtX, anAtY, anAtZ); |
| 6012 | theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n"; |
| 6013 | } |
| 6014 | else |
| 6015 | { |
| 6016 | anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
| 6017 | } |
| 6018 | } |
| 6019 | if (aMapOfKeysByValues.Find ("PROJ", aValues)) |
| 6020 | { |
| 6021 | if (aValues->IsEmpty()) |
| 6022 | { |
| 6023 | Standard_Real aProjX = 0.0; |
| 6024 | Standard_Real aProjY = 0.0; |
| 6025 | Standard_Real aProjZ = 0.0; |
| 6026 | anAISView->Proj (aProjX, aProjY, aProjZ); |
| 6027 | theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n"; |
| 6028 | } |
| 6029 | else |
| 6030 | { |
| 6031 | anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
| 6032 | } |
| 6033 | } |
| 6034 | if (aMapOfKeysByValues.Find ("UP", aValues)) |
| 6035 | { |
| 6036 | if (aValues->IsEmpty()) |
| 6037 | { |
| 6038 | Standard_Real anUpX = 0.0; |
| 6039 | Standard_Real anUpY = 0.0; |
| 6040 | Standard_Real anUpZ = 0.0; |
| 6041 | anAISView->Up (anUpX, anUpY, anUpZ); |
| 6042 | theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n"; |
| 6043 | } |
| 6044 | else |
| 6045 | { |
| 6046 | anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
| 6047 | } |
| 6048 | } |
| 6049 | if (aMapOfKeysByValues.Find ("CENTER", aValues)) |
| 6050 | { |
| 6051 | anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue()); |
| 6052 | } |
| 6053 | |
| 6054 | return 0; |
| 6055 | } |
| 6056 | |
| 6057 | //======================================================================= |
| 6058 | //function : VChangeSelected |
| 6059 | //purpose : Adds the shape to selection or remove one from it |
| 6060 | //======================================================================= |
| 6061 | static Standard_Integer VChangeSelected (Draw_Interpretor& di, |
| 6062 | Standard_Integer argc, |
| 6063 | const char ** argv) |
| 6064 | { |
| 6065 | if(argc != 2) |
| 6066 | { |
| 6067 | di<<"Usage : " << argv[0] << " shape \n"; |
| 6068 | return 1; |
| 6069 | } |
| 6070 | //get AIS_Shape: |
| 6071 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 6072 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); |
| 6073 | TCollection_AsciiString aName(argv[1]); |
| 6074 | Handle(AIS_InteractiveObject) anAISObject; |
| 6075 | |
| 6076 | if(!aMap.IsBound2(aName)) |
| 6077 | { |
| 6078 | di<<"Use 'vdisplay' before"; |
| 6079 | return 1; |
| 6080 | } |
| 6081 | else |
| 6082 | { |
| 6083 | anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName)); |
| 6084 | if(anAISObject.IsNull()){ |
| 6085 | di<<"No interactive object \n"; |
| 6086 | return 1; |
| 6087 | } |
| 6088 | |
| 6089 | if(aContext->HasOpenedContext()) |
| 6090 | { |
| 6091 | aContext->AddOrRemoveSelected(anAISObject); |
| 6092 | } |
| 6093 | else |
| 6094 | { |
| 6095 | aContext->AddOrRemoveCurrentObject(anAISObject); |
| 6096 | } |
| 6097 | } |
| 6098 | return 0; |
| 6099 | } |
| 6100 | |
| 6101 | //======================================================================= |
| 6102 | //function : VZClipping |
| 6103 | //purpose : Gets or sets ZClipping mode, width and depth |
| 6104 | //======================================================================= |
| 6105 | static Standard_Integer VZClipping (Draw_Interpretor& di, |
| 6106 | Standard_Integer argc, |
| 6107 | const char ** argv) |
| 6108 | { |
| 6109 | if(argc>4) |
| 6110 | { |
| 6111 | di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n" |
| 6112 | <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; |
| 6113 | return -1; |
| 6114 | } |
| 6115 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 6116 | if(aContext.IsNull()) |
| 6117 | { |
| 6118 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 6119 | return 1; |
| 6120 | } |
| 6121 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 6122 | V3d_TypeOfZclipping aZClippingMode = V3d_OFF; |
| 6123 | if(argc==1) |
| 6124 | { |
| 6125 | TCollection_AsciiString aZClippingModeString; |
| 6126 | Quantity_Length aDepth, aWidth; |
| 6127 | aZClippingMode = aView->ZClipping(aDepth, aWidth); |
| 6128 | switch (aZClippingMode) |
| 6129 | { |
| 6130 | case V3d_OFF: |
| 6131 | aZClippingModeString.Copy("OFF"); |
| 6132 | break; |
| 6133 | case V3d_BACK: |
| 6134 | aZClippingModeString.Copy("BACK"); |
| 6135 | break; |
| 6136 | case V3d_FRONT: |
| 6137 | aZClippingModeString.Copy("FRONT"); |
| 6138 | break; |
| 6139 | case V3d_SLICE: |
| 6140 | aZClippingModeString.Copy("SLICE"); |
| 6141 | break; |
| 6142 | default: |
| 6143 | aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode)); |
| 6144 | break; |
| 6145 | } |
| 6146 | di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n" |
| 6147 | << "ZClipping depth = " << aDepth << "\n" |
| 6148 | << "ZClipping width = " << aWidth << "\n"; |
| 6149 | } |
| 6150 | else |
| 6151 | { |
| 6152 | if(argc !=3) |
| 6153 | { |
| 6154 | Standard_Integer aStatus = 0; |
| 6155 | if ( strcmp (argv [1], "OFF") == 0 ) { |
| 6156 | aStatus = 1; |
| 6157 | aZClippingMode = V3d_OFF; |
| 6158 | } |
| 6159 | if ( strcmp (argv [1], "BACK") == 0 ) { |
| 6160 | aStatus = 1; |
| 6161 | aZClippingMode = V3d_BACK; |
| 6162 | } |
| 6163 | if ( strcmp (argv [1], "FRONT") == 0 ) { |
| 6164 | aStatus = 1; |
| 6165 | aZClippingMode = V3d_FRONT; |
| 6166 | } |
| 6167 | if ( strcmp (argv [1], "SLICE") == 0 ) { |
| 6168 | aStatus = 1; |
| 6169 | aZClippingMode = V3d_SLICE; |
| 6170 | } |
| 6171 | if (aStatus != 1) |
| 6172 | { |
| 6173 | di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n" |
| 6174 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; |
| 6175 | return 1; |
| 6176 | } |
| 6177 | aView->SetZClippingType(aZClippingMode); |
| 6178 | } |
| 6179 | if(argc >2) |
| 6180 | { |
| 6181 | Quantity_Length aDepth = 0., aWidth = 1.; |
| 6182 | if(argc == 3) |
| 6183 | { |
| 6184 | aDepth = Draw::Atof (argv[1]); |
| 6185 | aWidth = Draw::Atof (argv[2]); |
| 6186 | } |
| 6187 | else if(argc == 4) |
| 6188 | { |
| 6189 | aDepth = Draw::Atof (argv[2]); |
| 6190 | aWidth = Draw::Atof (argv[3]); |
| 6191 | } |
| 6192 | |
| 6193 | if(aDepth<0. || aDepth>1.) |
| 6194 | { |
| 6195 | di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n" |
| 6196 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; |
| 6197 | return 1; |
| 6198 | } |
| 6199 | if(aWidth<0. || aWidth>1.) |
| 6200 | { |
| 6201 | di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n" |
| 6202 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; |
| 6203 | return 1; |
| 6204 | } |
| 6205 | |
| 6206 | aView->SetZClippingDepth(aDepth); |
| 6207 | aView->SetZClippingWidth(aWidth); |
| 6208 | } |
| 6209 | aView->Redraw(); |
| 6210 | } |
| 6211 | return 0; |
| 6212 | } |
| 6213 | |
| 6214 | //======================================================================= |
| 6215 | //function : VNbSelected |
| 6216 | //purpose : Returns number of selected objects |
| 6217 | //======================================================================= |
| 6218 | static Standard_Integer VNbSelected (Draw_Interpretor& di, |
| 6219 | Standard_Integer argc, |
| 6220 | const char ** argv) |
| 6221 | { |
| 6222 | if(argc != 1) |
| 6223 | { |
| 6224 | di << "Usage : " << argv[0] << "\n"; |
| 6225 | return 1; |
| 6226 | } |
| 6227 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 6228 | if(aContext.IsNull()) |
| 6229 | { |
| 6230 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 6231 | return 1; |
| 6232 | } |
| 6233 | di << aContext->NbSelected() << "\n"; |
| 6234 | return 0; |
| 6235 | } |
| 6236 | |
| 6237 | //======================================================================= |
| 6238 | //function : VAntialiasing |
| 6239 | //purpose : Switches altialiasing on or off |
| 6240 | //======================================================================= |
| 6241 | static Standard_Integer VAntialiasing (Draw_Interpretor& di, |
| 6242 | Standard_Integer argc, |
| 6243 | const char ** argv) |
| 6244 | { |
| 6245 | if(argc > 2) |
| 6246 | { |
| 6247 | di << "Usage : " << argv[0] << " [1|0]" << "\n"; |
| 6248 | return 1; |
| 6249 | } |
| 6250 | |
| 6251 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 6252 | if(aContext.IsNull()) |
| 6253 | { |
| 6254 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 6255 | return 1; |
| 6256 | } |
| 6257 | |
| 6258 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 6259 | |
| 6260 | if((argc == 2) && (atof(argv[1]) == 0)) |
| 6261 | aView->SetAntialiasingOff(); |
| 6262 | else |
| 6263 | aView->SetAntialiasingOn(); |
| 6264 | aView->Update(); |
| 6265 | return 0; |
| 6266 | } |
| 6267 | |
| 6268 | //======================================================================= |
| 6269 | //function : VPurgeDisplay |
| 6270 | //purpose : Switches altialiasing on or off |
| 6271 | //======================================================================= |
| 6272 | static Standard_Integer VPurgeDisplay (Draw_Interpretor& di, |
| 6273 | Standard_Integer argc, |
| 6274 | const char ** argv) |
| 6275 | { |
| 6276 | if (argc > 1) |
| 6277 | { |
| 6278 | di << "Usage : " << argv[0] << "\n"; |
| 6279 | return 1; |
| 6280 | } |
| 6281 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 6282 | if (aContext.IsNull()) |
| 6283 | { |
| 6284 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 6285 | return 1; |
| 6286 | } |
| 6287 | aContext->CloseAllContexts(Standard_False); |
| 6288 | di << aContext->PurgeDisplay() << "\n"; |
| 6289 | return 0; |
| 6290 | } |
| 6291 | |
| 6292 | //======================================================================= |
| 6293 | //function : VSetViewSize |
| 6294 | //purpose : |
| 6295 | //======================================================================= |
| 6296 | static Standard_Integer VSetViewSize (Draw_Interpretor& di, |
| 6297 | Standard_Integer argc, |
| 6298 | const char ** argv) |
| 6299 | { |
| 6300 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 6301 | if(aContext.IsNull()) |
| 6302 | { |
| 6303 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 6304 | return 1; |
| 6305 | } |
| 6306 | if(argc != 2) |
| 6307 | { |
| 6308 | di<<"Usage : " << argv[0] << " Size\n"; |
| 6309 | return 1; |
| 6310 | } |
| 6311 | Standard_Real aSize = Draw::Atof (argv[1]); |
| 6312 | if (aSize <= 0.) |
| 6313 | { |
| 6314 | di<<"Bad Size value : " << aSize << "\n"; |
| 6315 | return 1; |
| 6316 | } |
| 6317 | |
| 6318 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 6319 | aView->SetSize(aSize); |
| 6320 | return 0; |
| 6321 | } |
| 6322 | |
| 6323 | //======================================================================= |
| 6324 | //function : VMoveView |
| 6325 | //purpose : |
| 6326 | //======================================================================= |
| 6327 | static Standard_Integer VMoveView (Draw_Interpretor& di, |
| 6328 | Standard_Integer argc, |
| 6329 | const char ** argv) |
| 6330 | { |
| 6331 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 6332 | if(aContext.IsNull()) |
| 6333 | { |
| 6334 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 6335 | return 1; |
| 6336 | } |
| 6337 | if(argc < 4 || argc > 5) |
| 6338 | { |
| 6339 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; |
| 6340 | return 1; |
| 6341 | } |
| 6342 | Standard_Real Dx = Draw::Atof (argv[1]); |
| 6343 | Standard_Real Dy = Draw::Atof (argv[2]); |
| 6344 | Standard_Real Dz = Draw::Atof (argv[3]); |
| 6345 | Standard_Boolean aStart = Standard_True; |
| 6346 | if (argc == 5) |
| 6347 | { |
| 6348 | aStart = (Draw::Atoi (argv[4]) > 0); |
| 6349 | } |
| 6350 | |
| 6351 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 6352 | aView->Move(Dx,Dy,Dz,aStart); |
| 6353 | return 0; |
| 6354 | } |
| 6355 | |
| 6356 | //======================================================================= |
| 6357 | //function : VTranslateView |
| 6358 | //purpose : |
| 6359 | //======================================================================= |
| 6360 | static Standard_Integer VTranslateView (Draw_Interpretor& di, |
| 6361 | Standard_Integer argc, |
| 6362 | const char ** argv) |
| 6363 | { |
| 6364 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 6365 | if(aContext.IsNull()) |
| 6366 | { |
| 6367 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 6368 | return 1; |
| 6369 | } |
| 6370 | if(argc < 4 || argc > 5) |
| 6371 | { |
| 6372 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; |
| 6373 | return 1; |
| 6374 | } |
| 6375 | Standard_Real Dx = Draw::Atof (argv[1]); |
| 6376 | Standard_Real Dy = Draw::Atof (argv[2]); |
| 6377 | Standard_Real Dz = Draw::Atof (argv[3]); |
| 6378 | Standard_Boolean aStart = Standard_True; |
| 6379 | if (argc == 5) |
| 6380 | { |
| 6381 | aStart = (Draw::Atoi (argv[4]) > 0); |
| 6382 | } |
| 6383 | |
| 6384 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 6385 | aView->Translate(Dx,Dy,Dz,aStart); |
| 6386 | return 0; |
| 6387 | } |
| 6388 | |
| 6389 | //======================================================================= |
| 6390 | //function : VTurnView |
| 6391 | //purpose : |
| 6392 | //======================================================================= |
| 6393 | static Standard_Integer VTurnView (Draw_Interpretor& di, |
| 6394 | Standard_Integer argc, |
| 6395 | const char ** argv) |
| 6396 | { |
| 6397 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 6398 | if(aContext.IsNull()) { |
| 6399 | di << "use 'vinit' command before " << argv[0] << "\n"; |
| 6400 | return 1; |
| 6401 | } |
| 6402 | if(argc < 4 || argc > 5){ |
| 6403 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n"; |
| 6404 | return 1; |
| 6405 | } |
| 6406 | Standard_Real Ax = Draw::Atof (argv[1]); |
| 6407 | Standard_Real Ay = Draw::Atof (argv[2]); |
| 6408 | Standard_Real Az = Draw::Atof (argv[3]); |
| 6409 | Standard_Boolean aStart = Standard_True; |
| 6410 | if (argc == 5) |
| 6411 | { |
| 6412 | aStart = (Draw::Atoi (argv[4]) > 0); |
| 6413 | } |
| 6414 | |
| 6415 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 6416 | aView->Turn(Ax,Ay,Az,aStart); |
| 6417 | return 0; |
| 6418 | } |
| 6419 | |
| 6420 | //============================================================================== |
| 6421 | //function : VTextureEnv |
| 6422 | //purpose : ENables or disables environment mapping |
| 6423 | //============================================================================== |
| 6424 | class OCC_TextureEnv : public Graphic3d_TextureEnv |
| 6425 | { |
| 6426 | public: |
| 6427 | OCC_TextureEnv(const Standard_CString FileName); |
| 6428 | OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName); |
| 6429 | void SetTextureParameters(const Standard_Boolean theRepeatFlag, |
| 6430 | const Standard_Boolean theModulateFlag, |
| 6431 | const Graphic3d_TypeOfTextureFilter theFilter, |
| 6432 | const Standard_ShortReal theXScale, |
| 6433 | const Standard_ShortReal theYScale, |
| 6434 | const Standard_ShortReal theXShift, |
| 6435 | const Standard_ShortReal theYShift, |
| 6436 | const Standard_ShortReal theAngle); |
| 6437 | DEFINE_STANDARD_RTTI(OCC_TextureEnv); |
| 6438 | }; |
| 6439 | DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv); |
| 6440 | IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv); |
| 6441 | IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv); |
| 6442 | |
| 6443 | OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName) |
| 6444 | : Graphic3d_TextureEnv(theFileName) |
| 6445 | { |
| 6446 | } |
| 6447 | |
| 6448 | OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId) |
| 6449 | : Graphic3d_TextureEnv(theTexId) |
| 6450 | { |
| 6451 | } |
| 6452 | |
| 6453 | void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag, |
| 6454 | const Standard_Boolean theModulateFlag, |
| 6455 | const Graphic3d_TypeOfTextureFilter theFilter, |
| 6456 | const Standard_ShortReal theXScale, |
| 6457 | const Standard_ShortReal theYScale, |
| 6458 | const Standard_ShortReal theXShift, |
| 6459 | const Standard_ShortReal theYShift, |
| 6460 | const Standard_ShortReal theAngle) |
| 6461 | { |
| 6462 | myParams->SetRepeat (theRepeatFlag); |
| 6463 | myParams->SetModulate (theModulateFlag); |
| 6464 | myParams->SetFilter (theFilter); |
| 6465 | myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale)); |
| 6466 | myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift)); |
| 6467 | myParams->SetRotation (theAngle); |
| 6468 | } |
| 6469 | |
| 6470 | static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec) |
| 6471 | { |
| 6472 | // get the active view |
| 6473 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 6474 | if (aView.IsNull()) |
| 6475 | { |
| 6476 | std::cerr << "No active view. Please call vinit.\n"; |
| 6477 | return 1; |
| 6478 | } |
| 6479 | |
| 6480 | // Checking the input arguments |
| 6481 | Standard_Boolean anEnableFlag = Standard_False; |
| 6482 | Standard_Boolean isOk = theArgNb >= 2; |
| 6483 | if (isOk) |
| 6484 | { |
| 6485 | TCollection_AsciiString anEnableOpt(theArgVec[1]); |
| 6486 | anEnableFlag = anEnableOpt.IsEqual("on"); |
| 6487 | isOk = anEnableFlag || anEnableOpt.IsEqual("off"); |
| 6488 | } |
| 6489 | if (anEnableFlag) |
| 6490 | { |
| 6491 | isOk = (theArgNb == 3 || theArgNb == 11); |
| 6492 | if (isOk) |
| 6493 | { |
| 6494 | TCollection_AsciiString aTextureOpt(theArgVec[2]); |
| 6495 | isOk = (!aTextureOpt.IsIntegerValue() || |
| 6496 | (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN)); |
| 6497 | |
| 6498 | if (isOk && theArgNb == 11) |
| 6499 | { |
| 6500 | TCollection_AsciiString aRepeatOpt (theArgVec[3]), |
| 6501 | aModulateOpt(theArgVec[4]), |
| 6502 | aFilterOpt (theArgVec[5]), |
| 6503 | aSScaleOpt (theArgVec[6]), |
| 6504 | aTScaleOpt (theArgVec[7]), |
| 6505 | aSTransOpt (theArgVec[8]), |
| 6506 | aTTransOpt (theArgVec[9]), |
| 6507 | anAngleOpt (theArgVec[10]); |
| 6508 | isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) && |
| 6509 | (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) && |
| 6510 | (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) && |
| 6511 | aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() && |
| 6512 | aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() && |
| 6513 | anAngleOpt.IsRealValue()); |
| 6514 | } |
| 6515 | } |
| 6516 | } |
| 6517 | |
| 6518 | if (!isOk) |
| 6519 | { |
| 6520 | std::cerr << "Usage :" << std::endl; |
| 6521 | std::cerr << theArgVec[0] << " off" << std::endl; |
| 6522 | 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; |
| 6523 | return 1; |
| 6524 | } |
| 6525 | |
| 6526 | if (anEnableFlag) |
| 6527 | { |
| 6528 | TCollection_AsciiString aTextureOpt(theArgVec[2]); |
| 6529 | Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ? |
| 6530 | new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) : |
| 6531 | new OCC_TextureEnv(theArgVec[2]); |
| 6532 | |
| 6533 | if (theArgNb == 11) |
| 6534 | { |
| 6535 | TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]); |
| 6536 | aTexEnv->SetTextureParameters( |
| 6537 | aRepeatOpt. IsEqual("repeat"), |
| 6538 | aModulateOpt.IsEqual("modulate"), |
| 6539 | aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST : |
| 6540 | aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR : |
| 6541 | Graphic3d_TOTF_TRILINEAR, |
| 6542 | (Standard_ShortReal)Draw::Atof(theArgVec[6]), |
| 6543 | (Standard_ShortReal)Draw::Atof(theArgVec[7]), |
| 6544 | (Standard_ShortReal)Draw::Atof(theArgVec[8]), |
| 6545 | (Standard_ShortReal)Draw::Atof(theArgVec[9]), |
| 6546 | (Standard_ShortReal)Draw::Atof(theArgVec[10]) |
| 6547 | ); |
| 6548 | } |
| 6549 | aView->SetTextureEnv(aTexEnv); |
| 6550 | aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT); |
| 6551 | } |
| 6552 | else // Disabling environment mapping |
| 6553 | { |
| 6554 | aView->SetSurfaceDetail(V3d_TEX_NONE); |
| 6555 | Handle(Graphic3d_TextureEnv) aTexture; |
| 6556 | aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data |
| 6557 | } |
| 6558 | |
| 6559 | aView->Redraw(); |
| 6560 | return 0; |
| 6561 | } |
| 6562 | |
| 6563 | //=============================================================================================== |
| 6564 | //function : VClipPlane |
| 6565 | //purpose : |
| 6566 | //=============================================================================================== |
| 6567 | static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
| 6568 | { |
| 6569 | // use short-cut for created clip planes map of created (or "registered by name") clip planes |
| 6570 | typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes; |
| 6571 | static MapOfPlanes aRegPlanes; |
| 6572 | |
| 6573 | if (theArgsNb < 2) |
| 6574 | { |
| 6575 | theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n"; |
| 6576 | return 1; |
| 6577 | } |
| 6578 | |
| 6579 | TCollection_AsciiString aCommand (theArgVec[1]); |
| 6580 | |
| 6581 | // print maximum number of planes for current viewer |
| 6582 | if (aCommand == "maxplanes") |
| 6583 | { |
| 6584 | if (theArgsNb < 3) |
| 6585 | { |
| 6586 | theDi << theArgVec[0] << ": view name is required. Type help for more information.\n"; |
| 6587 | return 1; |
| 6588 | } |
| 6589 | |
| 6590 | TCollection_AsciiString aViewName (theArgVec[2]); |
| 6591 | |
| 6592 | if (!ViewerTest_myViews.IsBound1 (aViewName)) |
| 6593 | { |
| 6594 | theDi << theArgVec[0] << ": view is not found.\n"; |
| 6595 | return 1; |
| 6596 | } |
| 6597 | |
| 6598 | const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName); |
| 6599 | |
| 6600 | theDi << theArgVec[0] << ": " |
| 6601 | << aView->Viewer()->Driver()->InquirePlaneLimit() |
| 6602 | << " plane slots provided by driver." |
| 6603 | << " Note that 2 more planes might be used (reserved for z-clipping).\n"; |
| 6604 | |
| 6605 | return 0; |
| 6606 | } |
| 6607 | |
| 6608 | // create / delete plane instance |
| 6609 | if (aCommand == "create" || aCommand == "delete" || aCommand == "clone") |
| 6610 | { |
| 6611 | if (theArgsNb < 3) |
| 6612 | { |
| 6613 | theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n"; |
| 6614 | return 1; |
| 6615 | } |
| 6616 | |
| 6617 | Standard_Boolean toCreate = (aCommand == "create"); |
| 6618 | Standard_Boolean toClone = (aCommand == "clone"); |
| 6619 | TCollection_AsciiString aPlane (theArgVec[2]); |
| 6620 | |
| 6621 | if (toCreate) |
| 6622 | { |
| 6623 | if (aRegPlanes.IsBound (aPlane)) |
| 6624 | { |
| 6625 | theDi << theArgVec[0] << ": plane name is in use.\n"; |
| 6626 | return 1; |
| 6627 | } |
| 6628 | |
| 6629 | aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane()); |
| 6630 | } |
| 6631 | else if (toClone) // toClone |
| 6632 | { |
| 6633 | if (!aRegPlanes.IsBound (aPlane)) |
| 6634 | { |
| 6635 | theDi << theArgVec[0] << ": no such plane.\n"; |
| 6636 | return 1; |
| 6637 | } |
| 6638 | |
| 6639 | if (theArgsNb < 4) |
| 6640 | { |
| 6641 | theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n"; |
| 6642 | return 1; |
| 6643 | } |
| 6644 | |
| 6645 | TCollection_AsciiString aClone (theArgVec[3]); |
| 6646 | if (aRegPlanes.IsBound (aClone)) |
| 6647 | { |
| 6648 | theDi << theArgVec[0] << ": plane name is in use.\n"; |
| 6649 | return 1; |
| 6650 | } |
| 6651 | |
| 6652 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); |
| 6653 | |
| 6654 | aRegPlanes.Bind (aClone, aClipPlane->Clone()); |
| 6655 | } |
| 6656 | else// toDelete |
| 6657 | { |
| 6658 | if (!aRegPlanes.IsBound (aPlane)) |
| 6659 | { |
| 6660 | theDi << theArgVec[0] << ": no such plane.\n"; |
| 6661 | return 1; |
| 6662 | } |
| 6663 | |
| 6664 | Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane); |
| 6665 | aRegPlanes.UnBind (aPlane); |
| 6666 | |
| 6667 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS()); |
| 6668 | for (; anIObjIt.More(); anIObjIt.Next()) |
| 6669 | { |
| 6670 | Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1()); |
| 6671 | aPrs->RemoveClipPlane(aClipPlane); |
| 6672 | } |
| 6673 | |
| 6674 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); |
| 6675 | for (; aViewIt.More(); aViewIt.Next()) |
| 6676 | { |
| 6677 | const Handle(V3d_View)& aView = aViewIt.Key2(); |
| 6678 | aView->RemoveClipPlane(aClipPlane); |
| 6679 | } |
| 6680 | |
| 6681 | ViewerTest::RedrawAllViews(); |
| 6682 | } |
| 6683 | |
| 6684 | return 0; |
| 6685 | } |
| 6686 | |
| 6687 | // set / unset plane command |
| 6688 | if (aCommand == "set" || aCommand == "unset") |
| 6689 | { |
| 6690 | if (theArgsNb < 4) |
| 6691 | { |
| 6692 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; |
| 6693 | return 1; |
| 6694 | } |
| 6695 | |
| 6696 | Standard_Boolean toSet = (aCommand == "set"); |
| 6697 | TCollection_AsciiString aPlane (theArgVec [2]); |
| 6698 | if (!aRegPlanes.IsBound (aPlane)) |
| 6699 | { |
| 6700 | theDi << theArgVec[0] << ": no such plane.\n"; |
| 6701 | return 1; |
| 6702 | } |
| 6703 | |
| 6704 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); |
| 6705 | |
| 6706 | TCollection_AsciiString aTarget (theArgVec [3]); |
| 6707 | if (aTarget != "object" && aTarget != "view") |
| 6708 | { |
| 6709 | theDi << theArgVec[0] << ": invalid target.\n"; |
| 6710 | return 1; |
| 6711 | } |
| 6712 | |
| 6713 | if (aTarget == "object" || aTarget == "view") |
| 6714 | { |
| 6715 | if (theArgsNb < 5) |
| 6716 | { |
| 6717 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; |
| 6718 | return 1; |
| 6719 | } |
| 6720 | |
| 6721 | Standard_Boolean isObject = (aTarget == "object"); |
| 6722 | |
| 6723 | for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt) |
| 6724 | { |
| 6725 | TCollection_AsciiString anEntityName (theArgVec[anIt]); |
| 6726 | if (isObject) // to object |
| 6727 | { |
| 6728 | if (!GetMapOfAIS().IsBound2 (anEntityName)) |
| 6729 | { |
| 6730 | theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n"; |
| 6731 | continue; |
| 6732 | } |
| 6733 | |
| 6734 | Handle(AIS_InteractiveObject) aIObj = |
| 6735 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName)); |
| 6736 | |
| 6737 | if (toSet) |
| 6738 | aIObj->AddClipPlane (aClipPlane); |
| 6739 | else |
| 6740 | aIObj->RemoveClipPlane (aClipPlane); |
| 6741 | } |
| 6742 | else // to view |
| 6743 | { |
| 6744 | if (!ViewerTest_myViews.IsBound1 (anEntityName)) |
| 6745 | { |
| 6746 | theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n"; |
| 6747 | continue; |
| 6748 | } |
| 6749 | |
| 6750 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName); |
| 6751 | if (toSet) |
| 6752 | aView->AddClipPlane (aClipPlane); |
| 6753 | else |
| 6754 | aView->RemoveClipPlane (aClipPlane); |
| 6755 | } |
| 6756 | } |
| 6757 | |
| 6758 | ViewerTest::RedrawAllViews(); |
| 6759 | } |
| 6760 | |
| 6761 | return 0; |
| 6762 | } |
| 6763 | |
| 6764 | // change plane command |
| 6765 | if (aCommand == "change") |
| 6766 | { |
| 6767 | if (theArgsNb < 4) |
| 6768 | { |
| 6769 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; |
| 6770 | return 1; |
| 6771 | } |
| 6772 | |
| 6773 | TCollection_AsciiString aPlane (theArgVec [2]); |
| 6774 | if (!aRegPlanes.IsBound (aPlane)) |
| 6775 | { |
| 6776 | theDi << theArgVec[0] << ": no such plane.\n"; |
| 6777 | return 1; |
| 6778 | } |
| 6779 | |
| 6780 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); |
| 6781 | |
| 6782 | TCollection_AsciiString aChangeArg (theArgVec [3]); |
| 6783 | if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation") |
| 6784 | { |
| 6785 | theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n"; |
| 6786 | return 1; |
| 6787 | } |
| 6788 | |
| 6789 | if (aChangeArg == "on" || aChangeArg == "off") // on / off |
| 6790 | { |
| 6791 | aClipPlane->SetOn (aChangeArg == "on"); |
| 6792 | } |
| 6793 | else if (aChangeArg == "equation") // change equation |
| 6794 | { |
| 6795 | if (theArgsNb < 8) |
| 6796 | { |
| 6797 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; |
| 6798 | return 1; |
| 6799 | } |
| 6800 | |
| 6801 | Standard_Real aCoeffA = Draw::Atof (theArgVec [4]); |
| 6802 | Standard_Real aCoeffB = Draw::Atof (theArgVec [5]); |
| 6803 | Standard_Real aCoeffC = Draw::Atof (theArgVec [6]); |
| 6804 | Standard_Real aCoeffD = Draw::Atof (theArgVec [7]); |
| 6805 | aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD)); |
| 6806 | } |
| 6807 | else if (aChangeArg == "capping") // change capping aspects |
| 6808 | { |
| 6809 | if (theArgsNb < 5) |
| 6810 | { |
| 6811 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; |
| 6812 | return 1; |
| 6813 | } |
| 6814 | |
| 6815 | TCollection_AsciiString aCappingArg (theArgVec [4]); |
| 6816 | if (aCappingArg != "on" && aCappingArg != "off" && |
| 6817 | aCappingArg != "color" && aCappingArg != "texname" && |
| 6818 | aCappingArg != "texscale" && aCappingArg != "texorigin" && |
| 6819 | aCappingArg != "texrotate" && aCappingArg != "hatch") |
| 6820 | { |
| 6821 | theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n"; |
| 6822 | return 1; |
| 6823 | } |
| 6824 | |
| 6825 | if (aCappingArg == "on" || aCappingArg == "off") // on / off capping |
| 6826 | { |
| 6827 | aClipPlane->SetCapping (aCappingArg == "on"); |
| 6828 | } |
| 6829 | else if (aCappingArg == "color") // color aspect for capping |
| 6830 | { |
| 6831 | if (theArgsNb < 8) |
| 6832 | { |
| 6833 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; |
| 6834 | return 1; |
| 6835 | } |
| 6836 | |
| 6837 | Standard_Real aRed = Draw::Atof (theArgVec [5]); |
| 6838 | Standard_Real aGrn = Draw::Atof (theArgVec [6]); |
| 6839 | Standard_Real aBlu = Draw::Atof (theArgVec [7]); |
| 6840 | |
| 6841 | Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); |
| 6842 | Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB); |
| 6843 | aMat.SetAmbientColor (aColor); |
| 6844 | aMat.SetDiffuseColor (aColor); |
| 6845 | aClipPlane->SetCappingMaterial (aMat); |
| 6846 | } |
| 6847 | else if (aCappingArg == "texname") // texture name |
| 6848 | { |
| 6849 | if (theArgsNb < 6) |
| 6850 | { |
| 6851 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; |
| 6852 | return 1; |
| 6853 | } |
| 6854 | |
| 6855 | TCollection_AsciiString aTextureName (theArgVec [5]); |
| 6856 | |
| 6857 | Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); |
| 6858 | if (!aTexture->IsDone ()) |
| 6859 | { |
| 6860 | aClipPlane->SetCappingTexture (NULL); |
| 6861 | } |
| 6862 | else |
| 6863 | { |
| 6864 | aTexture->EnableModulate(); |
| 6865 | aTexture->EnableRepeat(); |
| 6866 | aClipPlane->SetCappingTexture (aTexture); |
| 6867 | } |
| 6868 | } |
| 6869 | else if (aCappingArg == "texscale") // texture scale |
| 6870 | { |
| 6871 | if (aClipPlane->CappingTexture().IsNull()) |
| 6872 | { |
| 6873 | theDi << theArgVec[0] << ": no texture is set.\n"; |
| 6874 | return 1; |
| 6875 | } |
| 6876 | |
| 6877 | if (theArgsNb < 7) |
| 6878 | { |
| 6879 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; |
| 6880 | return 1; |
| 6881 | } |
| 6882 | |
| 6883 | Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]); |
| 6884 | Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]); |
| 6885 | |
| 6886 | aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); |
| 6887 | } |
| 6888 | else if (aCappingArg == "texorigin") // texture origin |
| 6889 | { |
| 6890 | if (aClipPlane->CappingTexture().IsNull()) |
| 6891 | { |
| 6892 | theDi << theArgVec[0] << ": no texture is set.\n"; |
| 6893 | return 1; |
| 6894 | } |
| 6895 | |
| 6896 | if (theArgsNb < 7) |
| 6897 | { |
| 6898 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; |
| 6899 | return 1; |
| 6900 | } |
| 6901 | |
| 6902 | Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]); |
| 6903 | Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]); |
| 6904 | |
| 6905 | aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); |
| 6906 | } |
| 6907 | else if (aCappingArg == "texrotate") // texture rotation |
| 6908 | { |
| 6909 | if (aClipPlane->CappingTexture().IsNull()) |
| 6910 | { |
| 6911 | theDi << theArgVec[0] << ": no texture is set.\n"; |
| 6912 | return 1; |
| 6913 | } |
| 6914 | |
| 6915 | if (theArgsNb < 6) |
| 6916 | { |
| 6917 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; |
| 6918 | return 1; |
| 6919 | } |
| 6920 | |
| 6921 | Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]); |
| 6922 | |
| 6923 | aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot); |
| 6924 | } |
| 6925 | else if (aCappingArg == "hatch") // hatch style |
| 6926 | { |
| 6927 | if (theArgsNb < 6) |
| 6928 | { |
| 6929 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; |
| 6930 | return 1; |
| 6931 | } |
| 6932 | |
| 6933 | TCollection_AsciiString aHatchStr (theArgVec [5]); |
| 6934 | if (aHatchStr == "on") |
| 6935 | { |
| 6936 | aClipPlane->SetCappingHatchOn(); |
| 6937 | } |
| 6938 | else if (aHatchStr == "off") |
| 6939 | { |
| 6940 | aClipPlane->SetCappingHatchOff(); |
| 6941 | } |
| 6942 | else |
| 6943 | { |
| 6944 | aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5])); |
| 6945 | } |
| 6946 | } |
| 6947 | } |
| 6948 | |
| 6949 | ViewerTest::RedrawAllViews(); |
| 6950 | |
| 6951 | return 0; |
| 6952 | } |
| 6953 | |
| 6954 | theDi << theArgVec[0] << ": invalid command. Type help for more information.\n"; |
| 6955 | return 1; |
| 6956 | } |
| 6957 | |
| 6958 | //=============================================================================================== |
| 6959 | //function : VSetTextureMode |
| 6960 | //purpose : |
| 6961 | //=============================================================================================== |
| 6962 | static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
| 6963 | { |
| 6964 | if (theArgsNb < 3) |
| 6965 | { |
| 6966 | theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n"; |
| 6967 | return 1; |
| 6968 | } |
| 6969 | |
| 6970 | TCollection_AsciiString aViewName (theArgVec[1]); |
| 6971 | if (!ViewerTest_myViews.IsBound1 (aViewName)) |
| 6972 | { |
| 6973 | theDi << theArgVec[0] << ": view is not found.\n"; |
| 6974 | return 1; |
| 6975 | } |
| 6976 | |
| 6977 | const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName); |
| 6978 | switch (atoi (theArgVec[2])) |
| 6979 | { |
| 6980 | case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break; |
| 6981 | case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break; |
| 6982 | case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break; |
| 6983 | default: |
| 6984 | theDi << theArgVec[0] << ": invalid mode.\n"; |
| 6985 | return 1; |
| 6986 | } |
| 6987 | |
| 6988 | aView->Redraw(); |
| 6989 | return 0; |
| 6990 | } |
| 6991 | |
| 6992 | //=============================================================================================== |
| 6993 | //function : VZRange |
| 6994 | //purpose : |
| 6995 | //=============================================================================================== |
| 6996 | static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
| 6997 | { |
| 6998 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
| 6999 | |
| 7000 | if (aCurrentView.IsNull()) |
| 7001 | { |
| 7002 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
| 7003 | return 1; |
| 7004 | } |
| 7005 | |
| 7006 | Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera(); |
| 7007 | |
| 7008 | if (theArgsNb < 2) |
| 7009 | { |
| 7010 | theDi << "ZNear: " << aCamera->ZNear() << "\n"; |
| 7011 | theDi << "ZFar: " << aCamera->ZFar() << "\n"; |
| 7012 | return 0; |
| 7013 | } |
| 7014 | |
| 7015 | if (theArgsNb == 3) |
| 7016 | { |
| 7017 | Standard_Real aNewZNear = Draw::Atof (theArgVec[1]); |
| 7018 | Standard_Real aNewZFar = Draw::Atof (theArgVec[2]); |
| 7019 | |
| 7020 | if (aNewZNear >= aNewZFar) |
| 7021 | { |
| 7022 | std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n"; |
| 7023 | return 1; |
| 7024 | } |
| 7025 | |
| 7026 | if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0)) |
| 7027 | { |
| 7028 | std::cout << theArgVec[0] << ": invalid arguments: "; |
| 7029 | std::cout << "znear, zfar should be positive for perspective camera.\n"; |
| 7030 | return 1; |
| 7031 | } |
| 7032 | |
| 7033 | aCamera->SetZRange (aNewZNear, aNewZFar); |
| 7034 | } |
| 7035 | else |
| 7036 | { |
| 7037 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
| 7038 | return 1; |
| 7039 | } |
| 7040 | |
| 7041 | aCurrentView->Redraw(); |
| 7042 | |
| 7043 | return 0; |
| 7044 | } |
| 7045 | |
| 7046 | //=============================================================================================== |
| 7047 | //function : VAutoZFit |
| 7048 | //purpose : |
| 7049 | //=============================================================================================== |
| 7050 | static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
| 7051 | { |
| 7052 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
| 7053 | |
| 7054 | if (aCurrentView.IsNull()) |
| 7055 | { |
| 7056 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
| 7057 | return 1; |
| 7058 | } |
| 7059 | |
| 7060 | Standard_Real aScale = aCurrentView->View()->AutoZFitScaleFactor(); |
| 7061 | |
| 7062 | if (theArgsNb > 3) |
| 7063 | { |
| 7064 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
| 7065 | return 1; |
| 7066 | } |
| 7067 | |
| 7068 | if (theArgsNb < 2) |
| 7069 | { |
| 7070 | theDi << "Auto z-fit mode: " << "\n" |
| 7071 | << "On: " << (aCurrentView->View()->AutoZFitMode() ? "enabled" : "disabled") << "\n" |
| 7072 | << "Scale: " << aScale << "\n"; |
| 7073 | return 0; |
| 7074 | } |
| 7075 | |
| 7076 | Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1; |
| 7077 | |
| 7078 | if (theArgsNb >= 3) |
| 7079 | { |
| 7080 | aScale = Draw::Atoi (theArgVec[2]); |
| 7081 | } |
| 7082 | |
| 7083 | aCurrentView->View()->SetAutoZFitMode (isOn, aScale); |
| 7084 | aCurrentView->View()->AutoZFit(); |
| 7085 | aCurrentView->Redraw(); |
| 7086 | |
| 7087 | return 0; |
| 7088 | } |
| 7089 | |
| 7090 | //! Auxiliary function to print projection type |
| 7091 | inline const char* projTypeName (Graphic3d_Camera::Projection theProjType) |
| 7092 | { |
| 7093 | switch (theProjType) |
| 7094 | { |
| 7095 | case Graphic3d_Camera::Projection_Orthographic: return "orthographic"; |
| 7096 | case Graphic3d_Camera::Projection_Perspective: return "perspective"; |
| 7097 | case Graphic3d_Camera::Projection_Stereo: return "stereoscopic"; |
| 7098 | case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye"; |
| 7099 | case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye"; |
| 7100 | } |
| 7101 | return "UNKNOWN"; |
| 7102 | } |
| 7103 | |
| 7104 | //=============================================================================================== |
| 7105 | //function : VCamera |
| 7106 | //purpose : |
| 7107 | //=============================================================================================== |
| 7108 | static int VCamera (Draw_Interpretor& theDI, |
| 7109 | Standard_Integer theArgsNb, |
| 7110 | const char** theArgVec) |
| 7111 | { |
| 7112 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 7113 | if (aView.IsNull()) |
| 7114 | { |
| 7115 | std::cout << "Error: no active view.\n"; |
| 7116 | return 1; |
| 7117 | } |
| 7118 | |
| 7119 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); |
| 7120 | if (theArgsNb < 2) |
| 7121 | { |
| 7122 | theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n"; |
| 7123 | theDI << "FOVy: " << aCamera->FOVy() << "\n"; |
| 7124 | theDI << "Distance: " << aCamera->Distance() << "\n"; |
| 7125 | theDI << "IOD: " << aCamera->IOD() << "\n"; |
| 7126 | theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n"; |
| 7127 | theDI << "ZFocus: " << aCamera->ZFocus() << "\n"; |
| 7128 | theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n"; |
| 7129 | return 0; |
| 7130 | } |
| 7131 | |
| 7132 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) |
| 7133 | { |
| 7134 | Standard_CString anArg = theArgVec[anArgIter]; |
| 7135 | TCollection_AsciiString anArgCase (anArg); |
| 7136 | anArgCase.LowerCase(); |
| 7137 | if (anArgCase == "-proj" |
| 7138 | || anArgCase == "-projection" |
| 7139 | || anArgCase == "-projtype" |
| 7140 | || anArgCase == "-projectiontype") |
| 7141 | { |
| 7142 | theDI << projTypeName (aCamera->ProjectionType()) << " "; |
| 7143 | } |
| 7144 | else if (anArgCase == "-ortho" |
| 7145 | || anArgCase == "-orthographic") |
| 7146 | { |
| 7147 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic); |
| 7148 | } |
| 7149 | else if (anArgCase == "-persp" |
| 7150 | || anArgCase == "-perspective" |
| 7151 | || anArgCase == "-perspmono" |
| 7152 | || anArgCase == "-perspectivemono" |
| 7153 | || anArgCase == "-mono") |
| 7154 | { |
| 7155 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); |
| 7156 | } |
| 7157 | else if (anArgCase == "-stereo" |
| 7158 | || anArgCase == "-stereoscopic" |
| 7159 | || anArgCase == "-perspstereo" |
| 7160 | || anArgCase == "-perspectivestereo") |
| 7161 | { |
| 7162 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); |
| 7163 | } |
| 7164 | else if (anArgCase == "-left" |
| 7165 | || anArgCase == "-lefteye" |
| 7166 | || anArgCase == "-monoleft" |
| 7167 | || anArgCase == "-monolefteye" |
| 7168 | || anArgCase == "-perpsleft" |
| 7169 | || anArgCase == "-perpslefteye") |
| 7170 | { |
| 7171 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye); |
| 7172 | } |
| 7173 | else if (anArgCase == "-right" |
| 7174 | || anArgCase == "-righteye" |
| 7175 | || anArgCase == "-monoright" |
| 7176 | || anArgCase == "-monorighteye" |
| 7177 | || anArgCase == "-perpsright") |
| 7178 | { |
| 7179 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye); |
| 7180 | } |
| 7181 | else if (anArgCase == "-dist" |
| 7182 | || anArgCase == "-distance") |
| 7183 | { |
| 7184 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
| 7185 | if (anArgValue != NULL |
| 7186 | && *anArgValue != '-') |
| 7187 | { |
| 7188 | ++anArgIter; |
| 7189 | aCamera->SetDistance (Draw::Atof (anArgValue)); |
| 7190 | continue; |
| 7191 | } |
| 7192 | theDI << aCamera->Distance() << " "; |
| 7193 | } |
| 7194 | else if (anArgCase == "-iod") |
| 7195 | { |
| 7196 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
| 7197 | if (anArgValue != NULL |
| 7198 | && *anArgValue != '-') |
| 7199 | { |
| 7200 | ++anArgIter; |
| 7201 | aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue)); |
| 7202 | continue; |
| 7203 | } |
| 7204 | theDI << aCamera->IOD() << " "; |
| 7205 | } |
| 7206 | else if (anArgCase == "-iodtype") |
| 7207 | { |
| 7208 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
| 7209 | TCollection_AsciiString anValueCase (anArgValue); |
| 7210 | anValueCase.LowerCase(); |
| 7211 | if (anValueCase == "abs" |
| 7212 | || anValueCase == "absolute") |
| 7213 | { |
| 7214 | ++anArgIter; |
| 7215 | aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD()); |
| 7216 | continue; |
| 7217 | } |
| 7218 | else if (anValueCase == "rel" |
| 7219 | || anValueCase == "relative") |
| 7220 | { |
| 7221 | ++anArgIter; |
| 7222 | aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD()); |
| 7223 | continue; |
| 7224 | } |
| 7225 | else if (*anArgValue != '-') |
| 7226 | { |
| 7227 | std::cout << "Error: unknown IOD type '" << anArgValue << "'\n"; |
| 7228 | return 1; |
| 7229 | } |
| 7230 | switch (aCamera->GetIODType()) |
| 7231 | { |
| 7232 | case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break; |
| 7233 | case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break; |
| 7234 | } |
| 7235 | } |
| 7236 | else if (anArgCase == "-zfocus") |
| 7237 | { |
| 7238 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
| 7239 | if (anArgValue != NULL |
| 7240 | && *anArgValue != '-') |
| 7241 | { |
| 7242 | ++anArgIter; |
| 7243 | aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue)); |
| 7244 | continue; |
| 7245 | } |
| 7246 | theDI << aCamera->ZFocus() << " "; |
| 7247 | } |
| 7248 | else if (anArgCase == "-zfocustype") |
| 7249 | { |
| 7250 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
| 7251 | TCollection_AsciiString anValueCase (anArgValue); |
| 7252 | anValueCase.LowerCase(); |
| 7253 | if (anValueCase == "abs" |
| 7254 | || anValueCase == "absolute") |
| 7255 | { |
| 7256 | ++anArgIter; |
| 7257 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus()); |
| 7258 | continue; |
| 7259 | } |
| 7260 | else if (anValueCase == "rel" |
| 7261 | || anValueCase == "relative") |
| 7262 | { |
| 7263 | ++anArgIter; |
| 7264 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus()); |
| 7265 | continue; |
| 7266 | } |
| 7267 | else if (*anArgValue != '-') |
| 7268 | { |
| 7269 | std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n"; |
| 7270 | return 1; |
| 7271 | } |
| 7272 | switch (aCamera->ZFocusType()) |
| 7273 | { |
| 7274 | case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break; |
| 7275 | case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break; |
| 7276 | } |
| 7277 | } |
| 7278 | else if (anArgCase == "-fov" |
| 7279 | || anArgCase == "-fovy") |
| 7280 | { |
| 7281 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
| 7282 | if (anArgValue != NULL |
| 7283 | && *anArgValue != '-') |
| 7284 | { |
| 7285 | ++anArgIter; |
| 7286 | aCamera->SetFOVy (Draw::Atof (anArgValue)); |
| 7287 | continue; |
| 7288 | } |
| 7289 | theDI << aCamera->FOVy() << " "; |
| 7290 | } |
| 7291 | else |
| 7292 | { |
| 7293 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
| 7294 | return 1; |
| 7295 | } |
| 7296 | } |
| 7297 | |
| 7298 | aView->View()->AutoZFit(); |
| 7299 | aView->Redraw(); |
| 7300 | |
| 7301 | return 0; |
| 7302 | } |
| 7303 | |
| 7304 | //============================================================================== |
| 7305 | //function : VStereo |
| 7306 | //purpose : |
| 7307 | //============================================================================== |
| 7308 | |
| 7309 | static int VStereo (Draw_Interpretor& theDI, |
| 7310 | Standard_Integer theArgNb, |
| 7311 | const char** theArgVec) |
| 7312 | { |
| 7313 | if (theArgNb < 2) |
| 7314 | { |
| 7315 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 7316 | if (aView.IsNull()) |
| 7317 | { |
| 7318 | std::cerr << "No active view. Please call vinit.\n"; |
| 7319 | return 0; |
| 7320 | } |
| 7321 | |
| 7322 | Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo; |
| 7323 | theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n"; |
| 7324 | return 0; |
| 7325 | } |
| 7326 | |
| 7327 | ViewerTest_myDefaultCaps.contextStereo = Draw::Atoi (theArgVec[1]) != 0; |
| 7328 | return 0; |
| 7329 | } |
| 7330 | |
| 7331 | //=============================================================================================== |
| 7332 | //function : VDefaults |
| 7333 | //purpose : |
| 7334 | //=============================================================================================== |
| 7335 | static int VDefaults (Draw_Interpretor& theDi, |
| 7336 | Standard_Integer theArgsNb, |
| 7337 | const char** theArgVec) |
| 7338 | { |
| 7339 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
| 7340 | if (aCtx.IsNull()) |
| 7341 | { |
| 7342 | std::cerr << "No active viewer!\n"; |
| 7343 | return 1; |
| 7344 | } |
| 7345 | |
| 7346 | Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer(); |
| 7347 | if (theArgsNb < 2) |
| 7348 | { |
| 7349 | if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE) |
| 7350 | { |
| 7351 | theDi << "DeflType: relative\n" |
| 7352 | << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n"; |
| 7353 | } |
| 7354 | else |
| 7355 | { |
| 7356 | theDi << "DeflType: absolute\n" |
| 7357 | << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n"; |
| 7358 | } |
| 7359 | theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n"; |
| 7360 | theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n"; |
| 7361 | return 0; |
| 7362 | } |
| 7363 | |
| 7364 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) |
| 7365 | { |
| 7366 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
| 7367 | anArg.UpperCase(); |
| 7368 | if (anArg == "-ABSDEFL" |
| 7369 | || anArg == "-ABSOLUTEDEFLECTION" |
| 7370 | || anArg == "-DEFL" |
| 7371 | || anArg == "-DEFLECTION") |
| 7372 | { |
| 7373 | if (++anArgIter >= theArgsNb) |
| 7374 | { |
| 7375 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 7376 | return 1; |
| 7377 | } |
| 7378 | aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE); |
| 7379 | aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter])); |
| 7380 | } |
| 7381 | else if (anArg == "-RELDEFL" |
| 7382 | || anArg == "-RELATIVEDEFLECTION" |
| 7383 | || anArg == "-DEVCOEFF" |
| 7384 | || anArg == "-DEVIATIONCOEFF" |
| 7385 | || anArg == "-DEVIATIONCOEFFICIENT") |
| 7386 | { |
| 7387 | if (++anArgIter >= theArgsNb) |
| 7388 | { |
| 7389 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 7390 | return 1; |
| 7391 | } |
| 7392 | aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE); |
| 7393 | aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter])); |
| 7394 | } |
| 7395 | else if (anArg == "-ANGDEFL" |
| 7396 | || anArg == "-ANGULARDEFL" |
| 7397 | || anArg == "-ANGULARDEFLECTION") |
| 7398 | { |
| 7399 | if (++anArgIter >= theArgsNb) |
| 7400 | { |
| 7401 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 7402 | return 1; |
| 7403 | } |
| 7404 | // currently HLRDeviationAngle is used instead of DeviationAngle in most places |
| 7405 | aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0); |
| 7406 | } |
| 7407 | else if (anArg == "-AUTOTR" |
| 7408 | || anArg == "-AUTOTRIANG" |
| 7409 | || anArg == "-AUTOTRIANGULATION") |
| 7410 | { |
| 7411 | if (++anArgIter >= theArgsNb) |
| 7412 | { |
| 7413 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 7414 | return 1; |
| 7415 | } |
| 7416 | TCollection_AsciiString aValue (theArgVec[anArgIter]); |
| 7417 | aValue.LowerCase(); |
| 7418 | if (aValue == "on" |
| 7419 | || aValue == "1") |
| 7420 | { |
| 7421 | aDefParams->SetAutoTriangulation (Standard_True); |
| 7422 | } |
| 7423 | else if (aValue == "off" |
| 7424 | || aValue == "0") |
| 7425 | { |
| 7426 | aDefParams->SetAutoTriangulation (Standard_False); |
| 7427 | } |
| 7428 | } |
| 7429 | else |
| 7430 | { |
| 7431 | std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n"; |
| 7432 | } |
| 7433 | } |
| 7434 | |
| 7435 | return 0; |
| 7436 | } |
| 7437 | |
| 7438 | //! Auxiliary method |
| 7439 | inline void addLight (const Handle(V3d_Light)& theLightNew, |
| 7440 | const Standard_Boolean theIsGlobal) |
| 7441 | { |
| 7442 | if (theLightNew.IsNull()) |
| 7443 | { |
| 7444 | return; |
| 7445 | } |
| 7446 | |
| 7447 | if (theIsGlobal) |
| 7448 | { |
| 7449 | ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew); |
| 7450 | } |
| 7451 | else |
| 7452 | { |
| 7453 | ViewerTest::CurrentView()->SetLightOn (theLightNew); |
| 7454 | } |
| 7455 | } |
| 7456 | |
| 7457 | //! Auxiliary method |
| 7458 | inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext) |
| 7459 | { |
| 7460 | TCollection_AsciiString anArgNextCase (theArgNext); |
| 7461 | anArgNextCase.UpperCase(); |
| 7462 | if (anArgNextCase.Length() > 5 |
| 7463 | && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT")) |
| 7464 | { |
| 7465 | return theArgNext.SubString (6, theArgNext.Length()).IntegerValue(); |
| 7466 | } |
| 7467 | else |
| 7468 | { |
| 7469 | return theArgNext.IntegerValue(); |
| 7470 | } |
| 7471 | } |
| 7472 | |
| 7473 | //=============================================================================================== |
| 7474 | //function : VLight |
| 7475 | //purpose : |
| 7476 | //=============================================================================================== |
| 7477 | static int VLight (Draw_Interpretor& theDi, |
| 7478 | Standard_Integer theArgsNb, |
| 7479 | const char** theArgVec) |
| 7480 | { |
| 7481 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 7482 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); |
| 7483 | if (aView.IsNull() |
| 7484 | || aViewer.IsNull()) |
| 7485 | { |
| 7486 | std::cerr << "No active viewer!\n"; |
| 7487 | return 1; |
| 7488 | } |
| 7489 | |
| 7490 | Standard_Real anXYZ[3]; |
| 7491 | Quantity_Coefficient anAtten[2]; |
| 7492 | if (theArgsNb < 2) |
| 7493 | { |
| 7494 | // print lights info |
| 7495 | Standard_Integer aLightId = 0; |
| 7496 | for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId) |
| 7497 | { |
| 7498 | Handle(V3d_Light) aLight = aView->ActiveLight(); |
| 7499 | const Quantity_Color aColor = aLight->Color(); |
| 7500 | theDi << "Light" << aLightId << "\n"; |
| 7501 | switch (aLight->Type()) |
| 7502 | { |
| 7503 | case V3d_AMBIENT: |
| 7504 | { |
| 7505 | theDi << " Type: Ambient\n"; |
| 7506 | theDi << " Intensity: " << aLight->Intensity() << "\n"; |
| 7507 | break; |
| 7508 | } |
| 7509 | case V3d_DIRECTIONAL: |
| 7510 | { |
| 7511 | Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight); |
| 7512 | theDi << " Type: Directional\n"; |
| 7513 | theDi << " Intensity: " << aLight->Intensity() << "\n"; |
| 7514 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; |
| 7515 | theDi << " Smoothness: " << aLight->Smoothness() << "\n"; |
| 7516 | if (!aLightDir.IsNull()) |
| 7517 | { |
| 7518 | aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]); |
| 7519 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
| 7520 | aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); |
| 7521 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
| 7522 | } |
| 7523 | break; |
| 7524 | } |
| 7525 | case V3d_POSITIONAL: |
| 7526 | { |
| 7527 | Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight); |
| 7528 | theDi << " Type: Positional\n"; |
| 7529 | theDi << " Intensity: " << aLight->Intensity() << "\n"; |
| 7530 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; |
| 7531 | theDi << " Smoothness: " << aLight->Smoothness() << "\n"; |
| 7532 | if (!aLightPos.IsNull()) |
| 7533 | { |
| 7534 | aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]); |
| 7535 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
| 7536 | aLightPos->Attenuation (anAtten[0], anAtten[1]); |
| 7537 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; |
| 7538 | } |
| 7539 | break; |
| 7540 | } |
| 7541 | case V3d_SPOT: |
| 7542 | { |
| 7543 | Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight); |
| 7544 | theDi << " Type: Spot\n"; |
| 7545 | theDi << " Intensity: " << aLight->Intensity() << "\n"; |
| 7546 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; |
| 7547 | if (!aLightSpot.IsNull()) |
| 7548 | { |
| 7549 | aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]); |
| 7550 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
| 7551 | aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); |
| 7552 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
| 7553 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); |
| 7554 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; |
| 7555 | theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n"; |
| 7556 | theDi << " Exponent: " << aLightSpot->Concentration() << "\n"; |
| 7557 | } |
| 7558 | break; |
| 7559 | } |
| 7560 | default: |
| 7561 | { |
| 7562 | theDi << " Type: UNKNOWN\n"; |
| 7563 | break; |
| 7564 | } |
| 7565 | } |
| 7566 | theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n"; |
| 7567 | } |
| 7568 | } |
| 7569 | |
| 7570 | Handle(V3d_Light) aLightNew; |
| 7571 | Handle(V3d_Light) aLightOld; |
| 7572 | Standard_Boolean isGlobal = Standard_True; |
| 7573 | Standard_Boolean toCreate = Standard_False; |
| 7574 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) |
| 7575 | { |
| 7576 | Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew; |
| 7577 | Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr); |
| 7578 | Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr); |
| 7579 | Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr); |
| 7580 | Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr); |
| 7581 | |
| 7582 | TCollection_AsciiString aName, aValue; |
| 7583 | const TCollection_AsciiString anArg (theArgVec[anArgIt]); |
| 7584 | TCollection_AsciiString anArgCase (anArg); |
| 7585 | anArgCase.UpperCase(); |
| 7586 | if (anArgCase.IsEqual ("NEW") |
| 7587 | || anArgCase.IsEqual ("ADD") |
| 7588 | || anArgCase.IsEqual ("CREATE")) |
| 7589 | { |
| 7590 | toCreate = Standard_True; |
| 7591 | } |
| 7592 | else if (anArgCase.IsEqual ("GLOB") |
| 7593 | || anArgCase.IsEqual ("GLOBAL")) |
| 7594 | { |
| 7595 | isGlobal = Standard_True; |
| 7596 | } |
| 7597 | else if (anArgCase.IsEqual ("LOC") |
| 7598 | || anArgCase.IsEqual ("LOCAL")) |
| 7599 | { |
| 7600 | isGlobal = Standard_False; |
| 7601 | } |
| 7602 | else if (anArgCase.IsEqual ("DEF") |
| 7603 | || anArgCase.IsEqual ("DEFAULTS")) |
| 7604 | { |
| 7605 | toCreate = Standard_False; |
| 7606 | aViewer->SetDefaultLights(); |
| 7607 | } |
| 7608 | else if (anArgCase.IsEqual ("CLR") |
| 7609 | || anArgCase.IsEqual ("CLEAR")) |
| 7610 | { |
| 7611 | toCreate = Standard_False; |
| 7612 | aView->InitActiveLights(); |
| 7613 | while (aView->MoreActiveLights()) |
| 7614 | { |
| 7615 | aViewer->DelLight (aView->ActiveLight()); |
| 7616 | aView->InitActiveLights(); |
| 7617 | } |
| 7618 | } |
| 7619 | else if (anArgCase.IsEqual ("AMB") |
| 7620 | || anArgCase.IsEqual ("AMBIENT") |
| 7621 | || anArgCase.IsEqual ("AMBLIGHT")) |
| 7622 | { |
| 7623 | addLight (aLightNew, isGlobal); |
| 7624 | if (!toCreate) |
| 7625 | { |
| 7626 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7627 | return 1; |
| 7628 | } |
| 7629 | toCreate = Standard_False; |
| 7630 | aLightNew = new V3d_AmbientLight (aViewer); |
| 7631 | } |
| 7632 | else if (anArgCase.IsEqual ("DIRECTIONAL") |
| 7633 | || anArgCase.IsEqual ("DIRLIGHT")) |
| 7634 | { |
| 7635 | addLight (aLightNew, isGlobal); |
| 7636 | if (!toCreate) |
| 7637 | { |
| 7638 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7639 | return 1; |
| 7640 | } |
| 7641 | toCreate = Standard_False; |
| 7642 | aLightNew = new V3d_DirectionalLight (aViewer); |
| 7643 | } |
| 7644 | else if (anArgCase.IsEqual ("SPOT") |
| 7645 | || anArgCase.IsEqual ("SPOTLIGHT")) |
| 7646 | { |
| 7647 | addLight (aLightNew, isGlobal); |
| 7648 | if (!toCreate) |
| 7649 | { |
| 7650 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7651 | return 1; |
| 7652 | } |
| 7653 | toCreate = Standard_False; |
| 7654 | aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0); |
| 7655 | } |
| 7656 | else if (anArgCase.IsEqual ("POSLIGHT") |
| 7657 | || anArgCase.IsEqual ("POSITIONAL")) |
| 7658 | { |
| 7659 | addLight (aLightNew, isGlobal); |
| 7660 | if (!toCreate) |
| 7661 | { |
| 7662 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7663 | return 1; |
| 7664 | } |
| 7665 | toCreate = Standard_False; |
| 7666 | aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0); |
| 7667 | } |
| 7668 | else if (anArgCase.IsEqual ("CHANGE")) |
| 7669 | { |
| 7670 | addLight (aLightNew, isGlobal); |
| 7671 | aLightNew.Nullify(); |
| 7672 | if (++anArgIt >= theArgsNb) |
| 7673 | { |
| 7674 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7675 | return 1; |
| 7676 | } |
| 7677 | |
| 7678 | const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]); |
| 7679 | Standard_Integer aLightIt = 0; |
| 7680 | for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt) |
| 7681 | { |
| 7682 | if (aLightIt == aLightId) |
| 7683 | { |
| 7684 | aLightOld = aView->ActiveLight(); |
| 7685 | break; |
| 7686 | } |
| 7687 | } |
| 7688 | |
| 7689 | if (aLightOld.IsNull()) |
| 7690 | { |
| 7691 | std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n"; |
| 7692 | return 1; |
| 7693 | } |
| 7694 | } |
| 7695 | else if (anArgCase.IsEqual ("DEL") |
| 7696 | || anArgCase.IsEqual ("DELETE")) |
| 7697 | { |
| 7698 | Handle(V3d_Light) aLightDel; |
| 7699 | if (++anArgIt >= theArgsNb) |
| 7700 | { |
| 7701 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7702 | return 1; |
| 7703 | } |
| 7704 | |
| 7705 | const TCollection_AsciiString anArgNext (theArgVec[anArgIt]); |
| 7706 | const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]); |
| 7707 | Standard_Integer aLightIt = 0; |
| 7708 | for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt) |
| 7709 | { |
| 7710 | aLightDel = aView->ActiveLight(); |
| 7711 | if (aLightIt == aLightDelId) |
| 7712 | { |
| 7713 | break; |
| 7714 | } |
| 7715 | } |
| 7716 | if (!aLightDel.IsNull()) |
| 7717 | { |
| 7718 | aViewer->DelLight (aLightDel); |
| 7719 | } |
| 7720 | } |
| 7721 | else if (anArgCase.IsEqual ("COLOR") |
| 7722 | || anArgCase.IsEqual ("COLOUR")) |
| 7723 | { |
| 7724 | if (++anArgIt >= theArgsNb) |
| 7725 | { |
| 7726 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7727 | return 1; |
| 7728 | } |
| 7729 | |
| 7730 | TCollection_AsciiString anArgNext (theArgVec[anArgIt]); |
| 7731 | anArgNext.UpperCase(); |
| 7732 | const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString()); |
| 7733 | if (!aLightCurr.IsNull()) |
| 7734 | { |
| 7735 | aLightCurr->SetColor (aColor); |
| 7736 | } |
| 7737 | } |
| 7738 | else if (anArgCase.IsEqual ("POS") |
| 7739 | || anArgCase.IsEqual ("POSITION")) |
| 7740 | { |
| 7741 | if ((anArgIt + 3) >= theArgsNb) |
| 7742 | { |
| 7743 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7744 | return 1; |
| 7745 | } |
| 7746 | |
| 7747 | anXYZ[0] = Atof (theArgVec[++anArgIt]); |
| 7748 | anXYZ[1] = Atof (theArgVec[++anArgIt]); |
| 7749 | anXYZ[2] = Atof (theArgVec[++anArgIt]); |
| 7750 | if (!aLightDir.IsNull()) |
| 7751 | { |
| 7752 | aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); |
| 7753 | } |
| 7754 | else if (!aLightPos.IsNull()) |
| 7755 | { |
| 7756 | aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); |
| 7757 | } |
| 7758 | else if (!aLightSpot.IsNull()) |
| 7759 | { |
| 7760 | aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); |
| 7761 | } |
| 7762 | else |
| 7763 | { |
| 7764 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7765 | return 1; |
| 7766 | } |
| 7767 | } |
| 7768 | else if (anArgCase.IsEqual ("DIR") |
| 7769 | || anArgCase.IsEqual ("DIRECTION")) |
| 7770 | { |
| 7771 | if ((anArgIt + 3) >= theArgsNb) |
| 7772 | { |
| 7773 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7774 | return 1; |
| 7775 | } |
| 7776 | |
| 7777 | anXYZ[0] = Atof (theArgVec[++anArgIt]); |
| 7778 | anXYZ[1] = Atof (theArgVec[++anArgIt]); |
| 7779 | anXYZ[2] = Atof (theArgVec[++anArgIt]); |
| 7780 | if (!aLightDir.IsNull()) |
| 7781 | { |
| 7782 | aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]); |
| 7783 | } |
| 7784 | else if (!aLightSpot.IsNull()) |
| 7785 | { |
| 7786 | aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]); |
| 7787 | } |
| 7788 | else |
| 7789 | { |
| 7790 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7791 | return 1; |
| 7792 | } |
| 7793 | } |
| 7794 | else if (anArgCase.IsEqual ("SM") |
| 7795 | || anArgCase.IsEqual ("SMOOTHNESS")) |
| 7796 | { |
| 7797 | if (++anArgIt >= theArgsNb) |
| 7798 | { |
| 7799 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7800 | return 1; |
| 7801 | } |
| 7802 | |
| 7803 | Standard_Real aSmoothness = Atof (theArgVec[anArgIt]); |
| 7804 | |
| 7805 | if (fabs (aSmoothness) < Precision::Confusion()) |
| 7806 | { |
| 7807 | aLightCurr->SetIntensity (1.f); |
| 7808 | } |
| 7809 | else if (fabs (aLightCurr->Smoothness()) < Precision::Confusion()) |
| 7810 | { |
| 7811 | aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f); |
| 7812 | } |
| 7813 | else |
| 7814 | { |
| 7815 | Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness()); |
| 7816 | aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio)); |
| 7817 | } |
| 7818 | |
| 7819 | if (!aLightPos.IsNull()) |
| 7820 | { |
| 7821 | aLightPos->SetSmoothRadius (aSmoothness); |
| 7822 | } |
| 7823 | else if (!aLightDir.IsNull()) |
| 7824 | { |
| 7825 | aLightDir->SetSmoothAngle (aSmoothness); |
| 7826 | } |
| 7827 | } |
| 7828 | else if (anArgCase.IsEqual ("INT") |
| 7829 | || anArgCase.IsEqual ("INTENSITY")) |
| 7830 | { |
| 7831 | if (++anArgIt >= theArgsNb) |
| 7832 | { |
| 7833 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7834 | return 1; |
| 7835 | } |
| 7836 | |
| 7837 | Standard_Real aIntensity = Atof (theArgVec[anArgIt]); |
| 7838 | |
| 7839 | if (!aLightCurr.IsNull()) |
| 7840 | { |
| 7841 | aLightCurr->SetIntensity (aIntensity); |
| 7842 | } |
| 7843 | } |
| 7844 | else if (anArgCase.IsEqual ("ANG") |
| 7845 | || anArgCase.IsEqual ("ANGLE")) |
| 7846 | { |
| 7847 | if (++anArgIt >= theArgsNb) |
| 7848 | { |
| 7849 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7850 | return 1; |
| 7851 | } |
| 7852 | |
| 7853 | Standard_Real anAngle = Atof (theArgVec[anArgIt]); |
| 7854 | |
| 7855 | if (!aLightSpot.IsNull()) |
| 7856 | { |
| 7857 | aLightSpot->SetAngle (anAngle / 180.0 * M_PI); |
| 7858 | } |
| 7859 | } |
| 7860 | else if (anArgCase.IsEqual ("CONSTATTEN") |
| 7861 | || anArgCase.IsEqual ("CONSTATTENUATION")) |
| 7862 | { |
| 7863 | if (++anArgIt >= theArgsNb) |
| 7864 | { |
| 7865 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7866 | return 1; |
| 7867 | } |
| 7868 | |
| 7869 | if (!aLightPos.IsNull()) |
| 7870 | { |
| 7871 | aLightPos->Attenuation (anAtten[0], anAtten[1]); |
| 7872 | anAtten[0] = Atof (theArgVec[anArgIt]); |
| 7873 | aLightPos->SetAttenuation (anAtten[0], anAtten[1]); |
| 7874 | } |
| 7875 | else if (!aLightSpot.IsNull()) |
| 7876 | { |
| 7877 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); |
| 7878 | anAtten[0] = Atof (theArgVec[anArgIt]); |
| 7879 | aLightSpot->SetAttenuation (anAtten[0], anAtten[1]); |
| 7880 | } |
| 7881 | else |
| 7882 | { |
| 7883 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7884 | return 1; |
| 7885 | } |
| 7886 | } |
| 7887 | else if (anArgCase.IsEqual ("LINATTEN") |
| 7888 | || anArgCase.IsEqual ("LINEARATTEN") |
| 7889 | || anArgCase.IsEqual ("LINEARATTENUATION")) |
| 7890 | { |
| 7891 | if (++anArgIt >= theArgsNb) |
| 7892 | { |
| 7893 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7894 | return 1; |
| 7895 | } |
| 7896 | |
| 7897 | if (!aLightPos.IsNull()) |
| 7898 | { |
| 7899 | aLightPos->Attenuation (anAtten[0], anAtten[1]); |
| 7900 | anAtten[1] = Atof (theArgVec[anArgIt]); |
| 7901 | aLightPos->SetAttenuation (anAtten[0], anAtten[1]); |
| 7902 | } |
| 7903 | else if (!aLightSpot.IsNull()) |
| 7904 | { |
| 7905 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); |
| 7906 | anAtten[1] = Atof (theArgVec[anArgIt]); |
| 7907 | aLightSpot->SetAttenuation (anAtten[0], anAtten[1]); |
| 7908 | } |
| 7909 | else |
| 7910 | { |
| 7911 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7912 | return 1; |
| 7913 | } |
| 7914 | } |
| 7915 | else if (anArgCase.IsEqual ("EXP") |
| 7916 | || anArgCase.IsEqual ("EXPONENT") |
| 7917 | || anArgCase.IsEqual ("SPOTEXP") |
| 7918 | || anArgCase.IsEqual ("SPOTEXPONENT")) |
| 7919 | { |
| 7920 | if (++anArgIt >= theArgsNb) |
| 7921 | { |
| 7922 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7923 | return 1; |
| 7924 | } |
| 7925 | |
| 7926 | if (!aLightSpot.IsNull()) |
| 7927 | { |
| 7928 | aLightSpot->SetConcentration (Atof (theArgVec[anArgIt])); |
| 7929 | } |
| 7930 | else |
| 7931 | { |
| 7932 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7933 | return 1; |
| 7934 | } |
| 7935 | } |
| 7936 | else if (anArgCase.IsEqual ("HEAD") |
| 7937 | || anArgCase.IsEqual ("HEADLIGHT")) |
| 7938 | { |
| 7939 | if (++anArgIt >= theArgsNb) |
| 7940 | { |
| 7941 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7942 | return 1; |
| 7943 | } |
| 7944 | |
| 7945 | if (aLightAmb.IsNull() |
| 7946 | && !aLightCurr.IsNull()) |
| 7947 | { |
| 7948 | aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0); |
| 7949 | } |
| 7950 | else |
| 7951 | { |
| 7952 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; |
| 7953 | return 1; |
| 7954 | } |
| 7955 | } |
| 7956 | else |
| 7957 | { |
| 7958 | std::cerr << "Warning: unknown argument '" << anArg << "'\n"; |
| 7959 | } |
| 7960 | } |
| 7961 | |
| 7962 | addLight (aLightNew, isGlobal); |
| 7963 | aViewer->UpdateLights(); |
| 7964 | |
| 7965 | return 0; |
| 7966 | } |
| 7967 | |
| 7968 | //======================================================================= |
| 7969 | //function : VRenderParams |
| 7970 | //purpose : Enables/disables rendering features |
| 7971 | //======================================================================= |
| 7972 | |
| 7973 | static Standard_Integer VRenderParams (Draw_Interpretor& theDI, |
| 7974 | Standard_Integer theArgNb, |
| 7975 | const char** theArgVec) |
| 7976 | { |
| 7977 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 7978 | if (aView.IsNull()) |
| 7979 | { |
| 7980 | std::cerr << "Error: no active viewer!\n"; |
| 7981 | return 1; |
| 7982 | } |
| 7983 | |
| 7984 | Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); |
| 7985 | TCollection_AsciiString aCmdName (theArgVec[0]); |
| 7986 | aCmdName.LowerCase(); |
| 7987 | if (aCmdName == "vraytrace") |
| 7988 | { |
| 7989 | if (theArgNb == 1) |
| 7990 | { |
| 7991 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " "; |
| 7992 | return 0; |
| 7993 | } |
| 7994 | else if (theArgNb == 2) |
| 7995 | { |
| 7996 | TCollection_AsciiString aValue (theArgVec[1]); |
| 7997 | aValue.LowerCase(); |
| 7998 | if (aValue == "on" |
| 7999 | || aValue == "1") |
| 8000 | { |
| 8001 | aParams.Method = Graphic3d_RM_RAYTRACING; |
| 8002 | aView->Redraw(); |
| 8003 | return 0; |
| 8004 | } |
| 8005 | else if (aValue == "off" |
| 8006 | || aValue == "0") |
| 8007 | { |
| 8008 | aParams.Method = Graphic3d_RM_RASTERIZATION; |
| 8009 | aView->Redraw(); |
| 8010 | return 0; |
| 8011 | } |
| 8012 | else |
| 8013 | { |
| 8014 | std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n"; |
| 8015 | return 1; |
| 8016 | } |
| 8017 | } |
| 8018 | else |
| 8019 | { |
| 8020 | std::cout << "Error: wrong number of arguments\n"; |
| 8021 | return 1; |
| 8022 | } |
| 8023 | } |
| 8024 | |
| 8025 | if (theArgNb < 2) |
| 8026 | { |
| 8027 | theDI << "renderMode: "; |
| 8028 | switch (aParams.Method) |
| 8029 | { |
| 8030 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; |
| 8031 | case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break; |
| 8032 | } |
| 8033 | theDI << "\n"; |
| 8034 | theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n"; |
| 8035 | theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n"; |
| 8036 | theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n"; |
| 8037 | theDI << "rayDepth: " << aParams.RaytracingDepth << "\n"; |
| 8038 | theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n"; |
| 8039 | theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n"; |
| 8040 | theDI << "shadingModel: "; |
| 8041 | switch (aView->ShadingModel()) |
| 8042 | { |
| 8043 | case V3d_COLOR: theDI << "color"; break; |
| 8044 | case V3d_FLAT: theDI << "flat"; break; |
| 8045 | case V3d_GOURAUD: theDI << "gouraud"; break; |
| 8046 | case V3d_PHONG: theDI << "phong"; break; |
| 8047 | } |
| 8048 | theDI << "\n"; |
| 8049 | return 0; |
| 8050 | } |
| 8051 | |
| 8052 | Standard_Boolean toPrint = Standard_False; |
| 8053 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
| 8054 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
| 8055 | { |
| 8056 | Standard_CString anArg (theArgVec[anArgIter]); |
| 8057 | TCollection_AsciiString aFlag (anArg); |
| 8058 | aFlag.LowerCase(); |
| 8059 | if (anUpdateTool.parseRedrawMode (aFlag)) |
| 8060 | { |
| 8061 | continue; |
| 8062 | } |
| 8063 | else if (aFlag == "-echo" |
| 8064 | || aFlag == "-print") |
| 8065 | { |
| 8066 | toPrint = Standard_True; |
| 8067 | anUpdateTool.Invalidate(); |
| 8068 | } |
| 8069 | else if (aFlag == "-mode" |
| 8070 | || aFlag == "-rendermode" |
| 8071 | || aFlag == "-render_mode") |
| 8072 | { |
| 8073 | if (toPrint) |
| 8074 | { |
| 8075 | switch (aParams.Method) |
| 8076 | { |
| 8077 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; |
| 8078 | case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break; |
| 8079 | } |
| 8080 | continue; |
| 8081 | } |
| 8082 | else |
| 8083 | { |
| 8084 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; |
| 8085 | return 1; |
| 8086 | } |
| 8087 | } |
| 8088 | else if (aFlag == "-ray" |
| 8089 | || aFlag == "-raytrace") |
| 8090 | { |
| 8091 | if (toPrint) |
| 8092 | { |
| 8093 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " "; |
| 8094 | continue; |
| 8095 | } |
| 8096 | |
| 8097 | aParams.Method = Graphic3d_RM_RAYTRACING; |
| 8098 | } |
| 8099 | else if (aFlag == "-rast" |
| 8100 | || aFlag == "-raster" |
| 8101 | || aFlag == "-rasterization") |
| 8102 | { |
| 8103 | if (toPrint) |
| 8104 | { |
| 8105 | theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " "; |
| 8106 | continue; |
| 8107 | } |
| 8108 | |
| 8109 | aParams.Method = Graphic3d_RM_RASTERIZATION; |
| 8110 | } |
| 8111 | else if (aFlag == "-raydepth" |
| 8112 | || aFlag == "-ray_depth") |
| 8113 | { |
| 8114 | if (toPrint) |
| 8115 | { |
| 8116 | theDI << aParams.RaytracingDepth << " "; |
| 8117 | continue; |
| 8118 | } |
| 8119 | else if (++anArgIter >= theArgNb) |
| 8120 | { |
| 8121 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; |
| 8122 | return 1; |
| 8123 | } |
| 8124 | |
| 8125 | const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]); |
| 8126 | |
| 8127 | // We allow RaytracingDepth be more than 10 in case of GI enabled |
| 8128 | if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled)) |
| 8129 | { |
| 8130 | std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n"; |
| 8131 | return 1; |
| 8132 | } |
| 8133 | else |
| 8134 | { |
| 8135 | aParams.RaytracingDepth = aDepth; |
| 8136 | } |
| 8137 | } |
| 8138 | else if (aFlag == "-shad" |
| 8139 | || aFlag == "-shadows") |
| 8140 | { |
| 8141 | if (toPrint) |
| 8142 | { |
| 8143 | theDI << (aParams.IsShadowEnabled ? "on" : "off") << " "; |
| 8144 | continue; |
| 8145 | } |
| 8146 | |
| 8147 | Standard_Boolean toEnable = Standard_True; |
| 8148 | if (++anArgIter < theArgNb |
| 8149 | && !parseOnOff (theArgVec[anArgIter], toEnable)) |
| 8150 | { |
| 8151 | --anArgIter; |
| 8152 | } |
| 8153 | aParams.IsShadowEnabled = toEnable; |
| 8154 | } |
| 8155 | else if (aFlag == "-refl" |
| 8156 | || aFlag == "-reflections") |
| 8157 | { |
| 8158 | if (toPrint) |
| 8159 | { |
| 8160 | theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " "; |
| 8161 | continue; |
| 8162 | } |
| 8163 | |
| 8164 | Standard_Boolean toEnable = Standard_True; |
| 8165 | if (++anArgIter < theArgNb |
| 8166 | && !parseOnOff (theArgVec[anArgIter], toEnable)) |
| 8167 | { |
| 8168 | --anArgIter; |
| 8169 | } |
| 8170 | aParams.IsReflectionEnabled = toEnable; |
| 8171 | } |
| 8172 | else if (aFlag == "-fsaa") |
| 8173 | { |
| 8174 | if (toPrint) |
| 8175 | { |
| 8176 | theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " "; |
| 8177 | continue; |
| 8178 | } |
| 8179 | |
| 8180 | Standard_Boolean toEnable = Standard_True; |
| 8181 | if (++anArgIter < theArgNb |
| 8182 | && !parseOnOff (theArgVec[anArgIter], toEnable)) |
| 8183 | { |
| 8184 | --anArgIter; |
| 8185 | } |
| 8186 | aParams.IsAntialiasingEnabled = toEnable; |
| 8187 | } |
| 8188 | else if (aFlag == "-gleam") |
| 8189 | { |
| 8190 | if (toPrint) |
| 8191 | { |
| 8192 | theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " "; |
| 8193 | continue; |
| 8194 | } |
| 8195 | |
| 8196 | Standard_Boolean toEnable = Standard_True; |
| 8197 | if (++anArgIter < theArgNb |
| 8198 | && !parseOnOff (theArgVec[anArgIter], toEnable)) |
| 8199 | { |
| 8200 | --anArgIter; |
| 8201 | } |
| 8202 | aParams.IsTransparentShadowEnabled = toEnable; |
| 8203 | } |
| 8204 | else if (aFlag == "-gi") |
| 8205 | { |
| 8206 | if (toPrint) |
| 8207 | { |
| 8208 | theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " "; |
| 8209 | continue; |
| 8210 | } |
| 8211 | |
| 8212 | Standard_Boolean toEnable = Standard_True; |
| 8213 | if (++anArgIter < theArgNb |
| 8214 | && !parseOnOff (theArgVec[anArgIter], toEnable)) |
| 8215 | { |
| 8216 | --anArgIter; |
| 8217 | } |
| 8218 | aParams.IsGlobalIlluminationEnabled = toEnable; |
| 8219 | if (!toEnable) |
| 8220 | { |
| 8221 | aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10); |
| 8222 | } |
| 8223 | } |
| 8224 | else if (aFlag == "-env") |
| 8225 | { |
| 8226 | if (toPrint) |
| 8227 | { |
| 8228 | theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " "; |
| 8229 | continue; |
| 8230 | } |
| 8231 | |
| 8232 | Standard_Boolean toEnable = Standard_True; |
| 8233 | if (++anArgIter < theArgNb |
| 8234 | && !parseOnOff (theArgVec[anArgIter], toEnable)) |
| 8235 | { |
| 8236 | --anArgIter; |
| 8237 | } |
| 8238 | aParams.UseEnvironmentMapBackground = toEnable; |
| 8239 | } |
| 8240 | else if (aFlag == "-shademodel" |
| 8241 | || aFlag == "-shadingmodel" |
| 8242 | || aFlag == "-shading") |
| 8243 | { |
| 8244 | if (toPrint) |
| 8245 | { |
| 8246 | switch (aView->ShadingModel()) |
| 8247 | { |
| 8248 | case V3d_COLOR: theDI << "color "; break; |
| 8249 | case V3d_FLAT: theDI << "flat "; break; |
| 8250 | case V3d_GOURAUD: theDI << "gouraud "; break; |
| 8251 | case V3d_PHONG: theDI << "phong "; break; |
| 8252 | } |
| 8253 | continue; |
| 8254 | } |
| 8255 | |
| 8256 | if (++anArgIter >= theArgNb) |
| 8257 | { |
| 8258 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; |
| 8259 | } |
| 8260 | |
| 8261 | TCollection_AsciiString aMode (theArgVec[anArgIter]); |
| 8262 | aMode.LowerCase(); |
| 8263 | if (aMode == "color" |
| 8264 | || aMode == "none") |
| 8265 | { |
| 8266 | aView->SetShadingModel (V3d_COLOR); |
| 8267 | } |
| 8268 | else if (aMode == "flat" |
| 8269 | || aMode == "facet") |
| 8270 | { |
| 8271 | aView->SetShadingModel (V3d_FLAT); |
| 8272 | } |
| 8273 | else if (aMode == "gouraud" |
| 8274 | || aMode == "vertex" |
| 8275 | || aMode == "vert") |
| 8276 | { |
| 8277 | aView->SetShadingModel (V3d_GOURAUD); |
| 8278 | } |
| 8279 | else if (aMode == "phong" |
| 8280 | || aMode == "fragment" |
| 8281 | || aMode == "frag" |
| 8282 | || aMode == "pixel") |
| 8283 | { |
| 8284 | aView->SetShadingModel (V3d_PHONG); |
| 8285 | } |
| 8286 | else |
| 8287 | { |
| 8288 | std::cout << "Error: unknown shading model '" << aMode << "'\n"; |
| 8289 | return 1; |
| 8290 | } |
| 8291 | } |
| 8292 | else |
| 8293 | { |
| 8294 | std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n"; |
| 8295 | return 1; |
| 8296 | } |
| 8297 | } |
| 8298 | |
| 8299 | return 0; |
| 8300 | } |
| 8301 | |
| 8302 | //======================================================================= |
| 8303 | //function : VProgressiveMode |
| 8304 | //purpose : |
| 8305 | //======================================================================= |
| 8306 | #if defined(_WIN32) |
| 8307 | static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/, |
| 8308 | Standard_Integer /*theNbArgs*/, |
| 8309 | const char** /*theArgs*/) |
| 8310 | { |
| 8311 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 8312 | if (aView.IsNull()) |
| 8313 | { |
| 8314 | std::cerr << "Error: no active viewer!\n"; |
| 8315 | return 1; |
| 8316 | } |
| 8317 | |
| 8318 | std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl; |
| 8319 | |
| 8320 | for (;;) |
| 8321 | { |
| 8322 | aView->Redraw(); |
| 8323 | |
| 8324 | Standard_Boolean toExit = Standard_False; |
| 8325 | |
| 8326 | MSG aMsg; |
| 8327 | while (PeekMessage (&aMsg, NULL, NULL, NULL, PM_REMOVE)) |
| 8328 | { |
| 8329 | if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b)) |
| 8330 | { |
| 8331 | toExit = Standard_True; |
| 8332 | } |
| 8333 | |
| 8334 | TranslateMessage (&aMsg); |
| 8335 | DispatchMessage (&aMsg); |
| 8336 | } |
| 8337 | |
| 8338 | if (toExit) |
| 8339 | { |
| 8340 | break; |
| 8341 | } |
| 8342 | } |
| 8343 | |
| 8344 | return 0; |
| 8345 | } |
| 8346 | #endif |
| 8347 | |
| 8348 | //======================================================================= |
| 8349 | //function : VFrustumCulling |
| 8350 | //purpose : enables/disables view volume's culling. |
| 8351 | //======================================================================= |
| 8352 | static int VFrustumCulling (Draw_Interpretor& theDI, |
| 8353 | Standard_Integer theArgNb, |
| 8354 | const char** theArgVec) |
| 8355 | { |
| 8356 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 8357 | if (aView.IsNull()) |
| 8358 | { |
| 8359 | std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n"; |
| 8360 | return 1; |
| 8361 | } |
| 8362 | |
| 8363 | if (theArgNb < 2) |
| 8364 | { |
| 8365 | theDI << (aView->IsCullingEnabled() ? "on" : "off"); |
| 8366 | return 0; |
| 8367 | } |
| 8368 | else if (theArgNb != 2) |
| 8369 | { |
| 8370 | std::cout << theArgVec[0] << " Syntax error: Specify the mode\n"; |
| 8371 | return 1; |
| 8372 | } |
| 8373 | |
| 8374 | TCollection_AsciiString aModeStr (theArgVec[1]); |
| 8375 | aModeStr.LowerCase(); |
| 8376 | Standard_Boolean toEnable = 0; |
| 8377 | if (aModeStr == "on") |
| 8378 | { |
| 8379 | toEnable = 1; |
| 8380 | } |
| 8381 | else if (aModeStr == "off") |
| 8382 | { |
| 8383 | toEnable = 0; |
| 8384 | } |
| 8385 | else |
| 8386 | { |
| 8387 | toEnable = Draw::Atoi (theArgVec[1]) != 0; |
| 8388 | } |
| 8389 | |
| 8390 | aView->SetFrustumCulling (toEnable); |
| 8391 | aView->Redraw(); |
| 8392 | return 0; |
| 8393 | } |
| 8394 | |
| 8395 | //======================================================================= |
| 8396 | //function : VHighlightSelected |
| 8397 | //purpose : |
| 8398 | //======================================================================= |
| 8399 | static int VHighlightSelected (Draw_Interpretor& theDI, |
| 8400 | Standard_Integer theArgNb, |
| 8401 | const char** theArgVec) |
| 8402 | { |
| 8403 | if (ViewerTest::GetAISContext().IsNull()) |
| 8404 | { |
| 8405 | std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n"; |
| 8406 | return 1; |
| 8407 | } |
| 8408 | |
| 8409 | const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 8410 | |
| 8411 | if (theArgNb < 2) |
| 8412 | { |
| 8413 | theDI << (aContext->ToHilightSelected() ? "on" : "off"); |
| 8414 | return 0; |
| 8415 | } |
| 8416 | |
| 8417 | if (theArgNb != 2) |
| 8418 | { |
| 8419 | std::cout << theArgVec[0] << " error : wrong number of parameters." |
| 8420 | << "Type 'help" << theArgVec[0] << "' for more information."; |
| 8421 | return 1; |
| 8422 | } |
| 8423 | |
| 8424 | // Parse parameter |
| 8425 | TCollection_AsciiString aMode (theArgVec[1]); |
| 8426 | aMode.LowerCase(); |
| 8427 | Standard_Boolean toEnable = Standard_False; |
| 8428 | if (aMode.IsEqual ("on")) |
| 8429 | { |
| 8430 | toEnable = Standard_True; |
| 8431 | } |
| 8432 | else if (aMode.IsEqual ("off")) |
| 8433 | { |
| 8434 | toEnable = Standard_False; |
| 8435 | } |
| 8436 | else |
| 8437 | { |
| 8438 | toEnable = Draw::Atoi (theArgVec[1]) != 0; |
| 8439 | } |
| 8440 | |
| 8441 | if (toEnable != aContext->ToHilightSelected()) |
| 8442 | { |
| 8443 | aContext->SetToHilightSelected (toEnable); |
| 8444 | |
| 8445 | // Move cursor to null position and back to process updating of detection |
| 8446 | // and highlighting of selected object immediatly. |
| 8447 | Standard_Integer aPixX = 0; |
| 8448 | Standard_Integer aPixY = 0; |
| 8449 | const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager(); |
| 8450 | |
| 8451 | anEventManager->GetCurrentPosition (aPixX, aPixY); |
| 8452 | anEventManager->MoveTo (0, 0); |
| 8453 | anEventManager->MoveTo (aPixX, aPixY); |
| 8454 | } |
| 8455 | |
| 8456 | return 0; |
| 8457 | } |
| 8458 | |
| 8459 | //======================================================================= |
| 8460 | //function : VXRotate |
| 8461 | //purpose : |
| 8462 | //======================================================================= |
| 8463 | static Standard_Integer VXRotate (Draw_Interpretor& di, |
| 8464 | Standard_Integer argc, |
| 8465 | const char ** argv) |
| 8466 | { |
| 8467 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 8468 | if (aContext.IsNull()) |
| 8469 | { |
| 8470 | di << argv[0] << "ERROR : use 'vinit' command before " << "\n"; |
| 8471 | return 1; |
| 8472 | } |
| 8473 | |
| 8474 | if (argc != 3) |
| 8475 | { |
| 8476 | di << "ERROR : Usage : " << argv[0] << " name angle" << "\n"; |
| 8477 | return 1; |
| 8478 | } |
| 8479 | |
| 8480 | TCollection_AsciiString aName (argv[1]); |
| 8481 | Standard_Real anAngle = Draw::Atof (argv[2]); |
| 8482 | |
| 8483 | // find object |
| 8484 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); |
| 8485 | Handle(AIS_InteractiveObject) anIObj; |
| 8486 | if (!aMap.IsBound2 (aName) ) |
| 8487 | { |
| 8488 | di << "Use 'vdisplay' before" << "\n"; |
| 8489 | return 1; |
| 8490 | } |
| 8491 | else |
| 8492 | { |
| 8493 | anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName)); |
| 8494 | |
| 8495 | gp_Trsf aTransform; |
| 8496 | aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle); |
| 8497 | aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart()); |
| 8498 | |
| 8499 | aContext->SetLocation (anIObj, aTransform); |
| 8500 | aContext->UpdateCurrentViewer(); |
| 8501 | } |
| 8502 | |
| 8503 | return 0; |
| 8504 | } |
| 8505 | |
| 8506 | //======================================================================= |
| 8507 | //function : ViewerCommands |
| 8508 | //purpose : |
| 8509 | //======================================================================= |
| 8510 | |
| 8511 | void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) |
| 8512 | { |
| 8513 | |
| 8514 | const char *group = "ZeViewer"; |
| 8515 | theCommands.Add("vinit", |
| 8516 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
| 8517 | "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" |
| 8518 | #else |
| 8519 | "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" |
| 8520 | #endif |
| 8521 | " - Creates new View window with specified name view_name.\n" |
| 8522 | "By default the new view is created in the viewer and in" |
| 8523 | " graphic driver shared with active view.\n" |
| 8524 | " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n" |
| 8525 | "If driverName isn't specified the driver will be shared with active view.\n" |
| 8526 | "If viewerName isn't specified the viewer will be shared with active view.\n" |
| 8527 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
| 8528 | " - display = HostName.DisplayNumber[:ScreenNumber] : if specified" |
| 8529 | "is used in creation of graphic driver\n" |
| 8530 | #endif |
| 8531 | " - l, t: pixel position of left top corner of the window\n" |
| 8532 | " - w,h: width and heigth of window respectively.\n" |
| 8533 | "Additional commands for operations with views: vclose, vactivate, vviewlist.\n", |
| 8534 | __FILE__,VInit,group); |
| 8535 | theCommands.Add("vclose" , |
| 8536 | "[view_id [keep_context=0|1]]\n" |
| 8537 | "or vclose ALL - to remove all created views\n" |
| 8538 | " - removes view(viewer window) defined by its view_id.\n" |
| 8539 | " - keep_context: by default 0; if 1 and the last view is deleted" |
| 8540 | " the current context is not removed.", |
| 8541 | __FILE__,VClose,group); |
| 8542 | theCommands.Add("vactivate" , |
| 8543 | "view_id" |
| 8544 | " - activates view(viewer window) defined by its view_id", |
| 8545 | __FILE__,VActivate,group); |
| 8546 | theCommands.Add("vviewlist", |
| 8547 | "vviewlist [format={tree, long}]" |
| 8548 | " - prints current list of views per viewer and graphic_driver ID shared between viewers" |
| 8549 | " - format: format of result output, if tree the output is a tree view;" |
| 8550 | "otherwise it's a list of full view names. By default format = tree", |
| 8551 | __FILE__,VViewList,group); |
| 8552 | theCommands.Add("vhelp" , |
| 8553 | "vhelp : display help on the viewer commands", |
| 8554 | __FILE__,VHelp,group); |
| 8555 | theCommands.Add("vtop" , |
| 8556 | "vtop or <T> : Top view" , |
| 8557 | __FILE__,VTop,group); |
| 8558 | theCommands.Add("vbottom" , |
| 8559 | "vbottom : Bottom view" , |
| 8560 | __FILE__,VBottom,group); |
| 8561 | theCommands.Add("vleft" , |
| 8562 | "vleft : Left view" , |
| 8563 | __FILE__,VLeft,group); |
| 8564 | theCommands.Add("vright" , |
| 8565 | "vright : Right view" , |
| 8566 | __FILE__,VRight,group); |
| 8567 | theCommands.Add("vaxo" , |
| 8568 | " vaxo or <A> : Axonometric view ", |
| 8569 | __FILE__,VAxo,group); |
| 8570 | theCommands.Add("vfront" , |
| 8571 | "vfront : Front view" , |
| 8572 | __FILE__,VFront,group); |
| 8573 | theCommands.Add("vback" , |
| 8574 | "vback : Back view" , |
| 8575 | __FILE__,VBack,group); |
| 8576 | theCommands.Add("vpick" , |
| 8577 | "vpick : vpick X Y Z [shape subshape] ( all variables as string )", |
| 8578 | VPick,group); |
| 8579 | theCommands.Add("vfit" , |
| 8580 | "vfit or <F> [-selected]" |
| 8581 | "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects", |
| 8582 | __FILE__,VFit,group); |
| 8583 | theCommands.Add ("vfitarea", |
| 8584 | "vfitarea x1 y1 x2 y2" |
| 8585 | "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2" |
| 8586 | "\n\t\t: Fit view to show area located between two points" |
| 8587 | "\n\t\t: given in world 2D or 3D corrdinates.", |
| 8588 | __FILE__, VFitArea, group); |
| 8589 | theCommands.Add ("vzfit", "vzfit [scale]\n" |
| 8590 | " Matches Z near, Z far view volume planes to the displayed objects.\n" |
| 8591 | " \"scale\" - specifies factor to scale computed z range.\n", |
| 8592 | __FILE__, VZFit, group); |
| 8593 | theCommands.Add("vrepaint", |
| 8594 | "vrepaint : vrepaint, force redraw", |
| 8595 | __FILE__,VRepaint,group); |
| 8596 | theCommands.Add("vclear", |
| 8597 | "vclear : vclear", |
| 8598 | __FILE__,VClear,group); |
| 8599 | theCommands.Add("vsetbg", |
| 8600 | "vsetbg : vsetbg imagefile [filltype] : Load image as background", |
| 8601 | __FILE__,VSetBg,group); |
| 8602 | theCommands.Add("vsetbgmode", |
| 8603 | "vsetbgmode : vsetbgmode filltype : Change background image fill type", |
| 8604 | __FILE__,VSetBgMode,group); |
| 8605 | theCommands.Add("vsetgradientbg", |
| 8606 | "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background", |
| 8607 | __FILE__,VSetGradientBg,group); |
| 8608 | theCommands.Add("vsetgrbgmode", |
| 8609 | "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type", |
| 8610 | __FILE__,VSetGradientBgMode,group); |
| 8611 | theCommands.Add("vsetcolorbg", |
| 8612 | "vsetcolorbg : vsetcolorbg r g b : Set background color", |
| 8613 | __FILE__,VSetColorBg,group); |
| 8614 | theCommands.Add("vscale", |
| 8615 | "vscale : vscale X Y Z", |
| 8616 | __FILE__,VScale,group); |
| 8617 | theCommands.Add("vzbufftrihedron", |
| 8618 | "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]" |
| 8619 | "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]" |
| 8620 | "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]" |
| 8621 | "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]" |
| 8622 | "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]" |
| 8623 | "\n\t\t: Displays a trihedron", |
| 8624 | __FILE__,VZBuffTrihedron,group); |
| 8625 | theCommands.Add("vrotate", |
| 8626 | "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]" |
| 8627 | "\n : Option -mouseStart starts rotation according to the mouse position" |
| 8628 | "\n : Option -mouseMove continues rotation with angle computed" |
| 8629 | "\n : from last and new mouse position." |
| 8630 | "\n : vrotate AX AY AZ [X Y Z]", |
| 8631 | __FILE__,VRotate,group); |
| 8632 | theCommands.Add("vzoom", |
| 8633 | "vzoom : vzoom coef", |
| 8634 | __FILE__,VZoom,group); |
| 8635 | theCommands.Add("vpan", |
| 8636 | "vpan : vpan dx dy", |
| 8637 | __FILE__,VPan,group); |
| 8638 | theCommands.Add("vexport", |
| 8639 | "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }" |
| 8640 | " : exports the view to a vector file of a given format" |
| 8641 | " : notice that EMF format requires patched gl2ps", |
| 8642 | __FILE__,VExport,group); |
| 8643 | theCommands.Add("vcolorscale", |
| 8644 | "vcolorscale : vcolorscale [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos " |
| 8645 | "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n" |
| 8646 | "-demo/-demoversion draw a demoversion of color scale.\n" |
| 8647 | "-show/display display color scale.\n" |
| 8648 | "-hide/erase erase color scale.\n" |
| 8649 | "Please note that -show/-hide option must be the first argument!\n" |
| 8650 | "-color Index R G B: set color for indexed interval\n" |
| 8651 | "-color Index ColorName: set color for indexed interval\n" |
| 8652 | "-colors R G B R G B ...: set colors for all intervals\n" |
| 8653 | "-colors ColorName1 ColorName2 ...: set colors for all intervals\n" |
| 8654 | "-colors supports both color names and rgb values in one call\n" |
| 8655 | "-label Index Text: set label for indexed interval\n" |
| 8656 | "-labels Text Text Text ...: set labels for all intervals\n" |
| 8657 | "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n" |
| 8658 | "Available text positions: left, right, center, none;\n", |
| 8659 | __FILE__,VColorScale,group); |
| 8660 | theCommands.Add("vgraduatedtrihedron", |
| 8661 | "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n" |
| 8662 | "\t[-namefont Name] [-valuesfont Name]\n" |
| 8663 | "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n" |
| 8664 | "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]" |
| 8665 | "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n" |
| 8666 | "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n" |
| 8667 | "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]" |
| 8668 | "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n" |
| 8669 | "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n" |
| 8670 | "\t[-xticks Number] [-yticks Number] [-zticks Number]\n" |
| 8671 | "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n" |
| 8672 | "\t[-drawgrid on/off] [-drawaxes on/off]\n" |
| 8673 | " - Displays or erases graduated trihedron" |
| 8674 | " - xname, yname, zname - names of axes, default: X, Y, Z\n" |
| 8675 | " - namefont - font of axes names. Default: Arial\n" |
| 8676 | " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n" |
| 8677 | " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n" |
| 8678 | " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n" |
| 8679 | " - valuesfont - font of axes values. Default: Arial\n" |
| 8680 | " - xcolor, ycolor, zcolor - color of axis and values\n" |
| 8681 | " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n" |
| 8682 | " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n", |
| 8683 | __FILE__,VGraduatedTrihedron,group); |
| 8684 | theCommands.Add("vprintview" , |
| 8685 | "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile", |
| 8686 | __FILE__,VPrintView,group); |
| 8687 | theCommands.Add("vzlayer", |
| 8688 | "vzlayer add/del/get/settings/enable/disable [id]\n" |
| 8689 | " add - add new z layer to viewer and print its id\n" |
| 8690 | " del - del z layer by its id\n" |
| 8691 | " get - print sequence of z layers in increasing order of their overlay level\n" |
| 8692 | " settings - print status of z layer settings\n" |
| 8693 | " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n" |
| 8694 | " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n" |
| 8695 | " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n" |
| 8696 | "\nWhere id is the layer identificator\n" |
| 8697 | "\nExamples:\n" |
| 8698 | " vzlayer add\n" |
| 8699 | " vzlayer enable poffset 1\n" |
| 8700 | " vzlayer disable depthtest 1\n" |
| 8701 | " vzlayer del 1\n", |
| 8702 | __FILE__,VZLayer,group); |
| 8703 | theCommands.Add("voverlaytext", |
| 8704 | "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]" |
| 8705 | " : height - pixel height of the text (default=10.0)" |
| 8706 | " : font_name - name of font (default=courier)" |
| 8707 | " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) " |
| 8708 | " : display_type = {normal/subtitle/decal/blend}, (default=normal) " |
| 8709 | " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ", |
| 8710 | __FILE__,VOverlayText,group); |
| 8711 | theCommands.Add("vlayerline", |
| 8712 | "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]", |
| 8713 | __FILE__,VLayerLine,group); |
| 8714 | theCommands.Add ("vgrid", |
| 8715 | "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]" |
| 8716 | " : Mode - rectangular or circular" |
| 8717 | " : Type - lines or points", |
| 8718 | __FILE__, VGrid, group); |
| 8719 | theCommands.Add ("vpriviledgedplane", |
| 8720 | "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]" |
| 8721 | "\n\t\t: Ox, Oy, Oz - plane origin" |
| 8722 | "\n\t\t: Nx, Ny, Nz - plane normal direction" |
| 8723 | "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction" |
| 8724 | "\n\t\t: Sets or prints viewer's priviledged plane geometry.", |
| 8725 | __FILE__, VPriviledgedPlane, group); |
| 8726 | theCommands.Add ("vconvert", |
| 8727 | "vconvert v [Mode={window|view}]" |
| 8728 | "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]" |
| 8729 | "\n\t\t: vconvert x y z [Mode={window|grid}]" |
| 8730 | "\n\t\t: window - convert to window coordinates, pixels" |
| 8731 | "\n\t\t: view - convert to view projection plane" |
| 8732 | "\n\t\t: grid - convert to model coordinates, given on grid" |
| 8733 | "\n\t\t: ray - convert projection ray to model coordiantes" |
| 8734 | "\n\t\t: - vconvert v window : convert view to window;" |
| 8735 | "\n\t\t: - vconvert v view : convert window to view;" |
| 8736 | "\n\t\t: - vconvert x y window : convert view to window;" |
| 8737 | "\n\t\t: - vconvert x y view : convert window to view;" |
| 8738 | "\n\t\t: - vconvert x y : convert window to model;" |
| 8739 | "\n\t\t: - vconvert x y grid : convert window to model using grid;" |
| 8740 | "\n\t\t: - vconvert x y ray : convert window projection line to model;" |
| 8741 | "\n\t\t: - vconvert x y z window : convert model to window;" |
| 8742 | "\n\t\t: - vconvert x y z grid : convert view to model using grid;" |
| 8743 | "\n\t\t: Converts the given coordinates to window/view/model space.", |
| 8744 | __FILE__, VConvert, group); |
| 8745 | theCommands.Add ("vfps", |
| 8746 | "vfps [framesNb=100] : estimate average frame rate for active view", |
| 8747 | __FILE__, VFps, group); |
| 8748 | theCommands.Add ("vgldebug", |
| 8749 | "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]" |
| 8750 | "\n\t\t: [-extraMsg {0|1}] [{0|1}]" |
| 8751 | "\n\t\t: Request debug GL context. Should be called BEFORE vinit." |
| 8752 | "\n\t\t: Debug context can be requested only on Windows" |
| 8753 | "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!" |
| 8754 | "\n\t\t: -sync - request synchronized debug GL context" |
| 8755 | "\n\t\t: -glslWarn - log GLSL compiler/linker warnings," |
| 8756 | "\n\t\t: which are suppressed by default," |
| 8757 | "\n\t\t: -extraMsg - log extra diagnostic messages from GL context," |
| 8758 | "\n\t\t: which are suppressed by default", |
| 8759 | __FILE__, VGlDebug, group); |
| 8760 | theCommands.Add ("vvbo", |
| 8761 | "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects", |
| 8762 | __FILE__, VVbo, group); |
| 8763 | theCommands.Add ("vstereo", |
| 8764 | "\nvstereo [{0|1}] : turn stereo usage On/Off; affects only newly displayed objects", |
| 8765 | __FILE__, VStereo, group); |
| 8766 | theCommands.Add ("vcaps", |
| 8767 | "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]" |
| 8768 | "\n\t\t: [-compatibleContext {0|1}]" |
| 8769 | "\n\t\t: [-softMode {0|1}] [-noupdate|-update]" |
| 8770 | "\n\t\t: Modify particular graphic driver options:" |
| 8771 | "\n\t\t: FFP - use fixed-function pipeline instead of" |
| 8772 | "\n\t\t: built-in GLSL programs" |
| 8773 | "\n\t\t: (requires compatible profile)" |
| 8774 | "\n\t\t: VBO - use Vertex Buffer Object (copy vertex" |
| 8775 | "\n\t\t: arrays to GPU memory)" |
| 8776 | "\n\t\t: sprite - use textured sprites instead of bitmaps" |
| 8777 | "\n\t\t: Context creation options:" |
| 8778 | "\n\t\t: softMode - software OpenGL implementation" |
| 8779 | "\n\t\t: compatibleProfile - backward-compatible profile" |
| 8780 | "\n\t\t: Unlike vrenderparams, these parameters control alternative" |
| 8781 | "\n\t\t: rendering paths producing the same visual result when" |
| 8782 | "\n\t\t: possible." |
| 8783 | "\n\t\t: Command is intended for testing old hardware compatibility.", |
| 8784 | __FILE__, VCaps, group); |
| 8785 | theCommands.Add ("vmemgpu", |
| 8786 | "vmemgpu [f]: print system-dependent GPU memory information if available;" |
| 8787 | " with f option returns free memory in bytes", |
| 8788 | __FILE__, VMemGpu, group); |
| 8789 | theCommands.Add ("vreadpixel", |
| 8790 | "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]" |
| 8791 | " : Read pixel value for active view", |
| 8792 | __FILE__, VReadPixel, group); |
| 8793 | theCommands.Add("diffimage", |
| 8794 | "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]", |
| 8795 | __FILE__, VDiffImage, group); |
| 8796 | theCommands.Add ("vselect", |
| 8797 | "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n" |
| 8798 | "- emulates different types of selection:\n" |
| 8799 | "- 1) single click selection\n" |
| 8800 | "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n" |
| 8801 | "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n" |
| 8802 | "- 4) -allowoverlap determines will partially included objects be selected in rectangular selection" |
| 8803 | " (partial inclusion - overlap - is not allowed by default)\n" |
| 8804 | "- 5) any of these selections with shift button pressed", |
| 8805 | __FILE__, VSelect, group); |
| 8806 | theCommands.Add ("vmoveto", |
| 8807 | "vmoveto x y" |
| 8808 | "- emulates cursor movement to pixel postion (x,y)", |
| 8809 | __FILE__, VMoveTo, group); |
| 8810 | theCommands.Add ("vviewparams", "vviewparams usage:\n" |
| 8811 | "- vviewparams\n" |
| 8812 | "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n" |
| 8813 | " [-proj [x y z]] [-center x y] [-size sx]\n" |
| 8814 | "- Gets or sets current view parameters.\n" |
| 8815 | "- If called without arguments, all view parameters are printed.\n" |
| 8816 | "- The options are:\n" |
| 8817 | " -scale [s] : prints or sets viewport relative scale.\n" |
| 8818 | " -eye [x y z] : prints or sets eye location.\n" |
| 8819 | " -at [x y z] : prints or sets center of look.\n" |
| 8820 | " -up [x y z] : prints or sets direction of up vector.\n" |
| 8821 | " -proj [x y z] : prints or sets direction of look.\n" |
| 8822 | " -center x y : sets location of center of the screen in pixels.\n" |
| 8823 | " -size [sx] : prints viewport projection width and height sizes\n" |
| 8824 | " : or changes the size of its maximum dimension.\n", |
| 8825 | __FILE__, VViewParams, group); |
| 8826 | theCommands.Add("vchangeselected", |
| 8827 | "vchangeselected shape" |
| 8828 | "- adds to shape to selection or remove one from it", |
| 8829 | __FILE__, VChangeSelected, group); |
| 8830 | theCommands.Add("vzclipping", |
| 8831 | "vzclipping [mode] [depth width]\n" |
| 8832 | "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n" |
| 8833 | "- gets or sets ZClipping mode, width and depth", |
| 8834 | __FILE__,VZClipping,group); |
| 8835 | theCommands.Add ("vnbselected", |
| 8836 | "vnbselected", __FILE__, VNbSelected, group); |
| 8837 | theCommands.Add ("vcamera", |
| 8838 | "vcamera [-ortho] [-projtype]" |
| 8839 | "\n\t\t: [-persp]" |
| 8840 | "\n\t\t: [-fovy [Angle]] [-distance [Distance]]" |
| 8841 | "\n\t\t: [-stereo] [-leftEye] [-rightEye]" |
| 8842 | "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]" |
| 8843 | "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]" |
| 8844 | "\n\t\t: Manage camera parameters." |
| 8845 | "\n\t\t: Prints current value when option called without argument." |
| 8846 | "\n\t\t: Orthographic camera:" |
| 8847 | "\n\t\t: -ortho activate orthographic projection" |
| 8848 | "\n\t\t: Perspective camera:" |
| 8849 | "\n\t\t: -persp activate perspective projection (mono)" |
| 8850 | "\n\t\t: -fovy field of view in y axis, in degrees" |
| 8851 | "\n\t\t: -distance distance of eye from camera center" |
| 8852 | "\n\t\t: Stereoscopic camera:" |
| 8853 | "\n\t\t: -stereo perspective projection (stereo)" |
| 8854 | "\n\t\t: -leftEye perspective projection (left eye)" |
| 8855 | "\n\t\t: -rightEye perspective projection (right eye)" |
| 8856 | "\n\t\t: -iod intraocular distance value" |
| 8857 | "\n\t\t: -iodType distance type, absolute or relative" |
| 8858 | "\n\t\t: -zfocus stereographic focus value" |
| 8859 | "\n\t\t: -zfocusType focus type, absolute or relative", |
| 8860 | __FILE__, VCamera, group); |
| 8861 | theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n" |
| 8862 | "- vautozfit [on={1|0}] [scale]\n" |
| 8863 | " Prints or changes parameters of automatic z-fit mode:\n" |
| 8864 | " \"on\" - turns automatic z-fit on or off\n" |
| 8865 | " \"scale\" - specifies factor to scale computed z range.\n", |
| 8866 | __FILE__, VAutoZFit, group); |
| 8867 | theCommands.Add ("vzrange", "command to manually access znear and zfar values\n" |
| 8868 | " vzrange - without parameters shows current values\n" |
| 8869 | " vzrange [znear] [zfar] - applies provided values to view", |
| 8870 | __FILE__,VZRange, group); |
| 8871 | theCommands.Add("vantialiasing", |
| 8872 | "vantialiasing 1|0", |
| 8873 | __FILE__,VAntialiasing,group); |
| 8874 | theCommands.Add ("vpurgedisplay", |
| 8875 | "vpurgedisplay" |
| 8876 | "- removes structures which don't belong to objects displayed in neutral point", |
| 8877 | __FILE__, VPurgeDisplay, group); |
| 8878 | theCommands.Add("vsetviewsize", |
| 8879 | "vsetviewsize size", |
| 8880 | __FILE__,VSetViewSize,group); |
| 8881 | theCommands.Add("vmoveview", |
| 8882 | "vmoveview Dx Dy Dz [Start = 1|0]", |
| 8883 | __FILE__,VMoveView,group); |
| 8884 | theCommands.Add("vtranslateview", |
| 8885 | "vtranslateview Dx Dy Dz [Start = 1|0)]", |
| 8886 | __FILE__,VTranslateView,group); |
| 8887 | theCommands.Add("vturnview", |
| 8888 | "vturnview Ax Ay Az [Start = 1|0]", |
| 8889 | __FILE__,VTurnView,group); |
| 8890 | theCommands.Add("vtextureenv", |
| 8891 | "Enables or disables environment mapping in the 3D view, loading the texture from the given standard " |
| 8892 | "or user-defined file and optionally applying texture mapping parameters\n" |
| 8893 | " Usage:\n" |
| 8894 | " vtextureenv off - disables environment mapping\n" |
| 8895 | " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n" |
| 8896 | " std_texture = (0..7)\n" |
| 8897 | " rep = {clamp|repeat}\n" |
| 8898 | " mod = {decal|modulate}\n" |
| 8899 | " flt = {nearest|bilinear|trilinear}\n" |
| 8900 | " ss, st - scale factors for s and t texture coordinates\n" |
| 8901 | " ts, tt - translation for s and t texture coordinates\n" |
| 8902 | " rot - texture rotation angle in degrees", |
| 8903 | __FILE__, VTextureEnv, group); |
| 8904 | theCommands.Add("vhlr" , |
| 8905 | "is_enabled={on|off} [show_hidden={1|0}]" |
| 8906 | " - Hidden line removal algorithm:" |
| 8907 | " - is_enabled: if is on HLR algorithm is applied\n" |
| 8908 | " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n", |
| 8909 | __FILE__,VHLR,group); |
| 8910 | theCommands.Add("vhlrtype" , |
| 8911 | "algo_type={algo|polyalgo} [shape_1 ... shape_n]" |
| 8912 | " - Changes the type of HLR algorithm using for shapes." |
| 8913 | " - algo_type: if equals to algo, exact HLR algorithm is applied;\n" |
| 8914 | " if equals to polyalgo, polygonal HLR algorithm is applied." |
| 8915 | "If shapes are not given HLR algoithm of given type is applied" |
| 8916 | " to all shapes in the view\n", |
| 8917 | __FILE__,VHLRType,group); |
| 8918 | theCommands.Add("vclipplane", "vclipplane usage: \n" |
| 8919 | " maxplanes <view_name> - get plane limit for view.\n" |
| 8920 | " create <plane_name> - create new plane.\n" |
| 8921 | " delete <plane_name> - delete plane.\n" |
| 8922 | " clone <source_plane> <plane_name> - clone the plane definition.\n" |
| 8923 | " set/unset <plane_name> object <object list> - set/unset plane for IO.\n" |
| 8924 | " set/unset <plane_name> view <view list> - set/unset plane for view.\n" |
| 8925 | " change <plane_name> on/off - turn clipping on/off.\n" |
| 8926 | " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n" |
| 8927 | " change <plane_name> capping on/off - turn capping on/off.\n" |
| 8928 | " change <plane_name> capping color <r> <g> <b> - set color.\n" |
| 8929 | " change <plane name> capping texname <texture> - set texture.\n" |
| 8930 | " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n" |
| 8931 | " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n" |
| 8932 | " change <plane_name> capping texrotate <angle> - set tex rotation.\n" |
| 8933 | " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n" |
| 8934 | " please use VSetTextureMode command to enable texture rendering in view.\n" |
| 8935 | , __FILE__, VClipPlane, group); |
| 8936 | theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n" |
| 8937 | " mode can be:\n" |
| 8938 | " 0 - no textures enabled in view.\n" |
| 8939 | " 1 - only environment textures enabled.\n" |
| 8940 | " 2 - all textures enabled.\n" |
| 8941 | " this command sets texture details mode for the specified view.\n" |
| 8942 | , __FILE__, VSetTextureMode, group); |
| 8943 | theCommands.Add("vdefaults", |
| 8944 | "vdefaults [-absDefl value]" |
| 8945 | "\n\t\t: [-devCoeff value]" |
| 8946 | "\n\t\t: [-angDefl value]" |
| 8947 | "\n\t\t: [-autoTriang {off/on | 0/1}]" |
| 8948 | , __FILE__, VDefaults, group); |
| 8949 | theCommands.Add("vlight", |
| 8950 | "tool to manage light sources, without arguments shows list of lights." |
| 8951 | "\n Main commands: " |
| 8952 | "\n 'clear' to clear lights" |
| 8953 | "\n '{def}aults' to load deafault lights" |
| 8954 | "\n 'add' (or 'new') <type> to add any light source" |
| 8955 | "\n where <type> is one of {amb}ient|directional|{spot}light|positional" |
| 8956 | "\n 'change' <lightId> to edit light source with specified lightId" |
| 8957 | "\n\n In addition to 'add' and 'change' commands you can use light parameters:" |
| 8958 | "\n {pos}ition X Y Z" |
| 8959 | "\n {dir}ection X Y Z (for directional light or for spotlight)" |
| 8960 | "\n color colorName" |
| 8961 | "\n {head}light 0|1" |
| 8962 | "\n {sm}oothness value" |
| 8963 | "\n {int}ensity value" |
| 8964 | "\n {constAtten}uation value" |
| 8965 | "\n {linearAtten}uation value" |
| 8966 | "\n angle angleDeg" |
| 8967 | "\n {spotexp}onent value" |
| 8968 | "\n local|global" |
| 8969 | "\n\n example: vlight add positional head 1 pos 0 1 1 color red" |
| 8970 | "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2", |
| 8971 | __FILE__, VLight, group); |
| 8972 | theCommands.Add("vraytrace", |
| 8973 | "vraytrace [0|1]" |
| 8974 | "\n\t\t: Turns on/off ray-tracing renderer." |
| 8975 | "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'." |
| 8976 | "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.", |
| 8977 | __FILE__, VRenderParams, group); |
| 8978 | theCommands.Add("vrenderparams", |
| 8979 | "\n Manages rendering parameters: " |
| 8980 | "\n '-rayTrace' Enables GPU ray-tracing" |
| 8981 | "\n '-raster' Disables GPU ray-tracing" |
| 8982 | "\n '-rayDepth 0..10' Defines maximum ray-tracing depth" |
| 8983 | "\n '-shadows on|off' Enables/disables shadows rendering" |
| 8984 | "\n '-reflections on|off' Enables/disables specular reflections" |
| 8985 | "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing" |
| 8986 | "\n '-gleam on|off' Enables/disables transparency shadow effects" |
| 8987 | "\n '-gi on|off' Enables/disables global illumination effects" |
| 8988 | "\n '-env on|off' Enables/disables environment map background" |
| 8989 | "\n '-shadingModel model' Controls shading model from enumeration" |
| 8990 | "\n color, flat, gouraud, phong" |
| 8991 | "\n Unlike vcaps, these parameters dramatically change visual properties." |
| 8992 | "\n Command is intended to control presentation quality depending on" |
| 8993 | "\n hardware capabilities and performance.", |
| 8994 | __FILE__, VRenderParams, group); |
| 8995 | theCommands.Add("vfrustumculling", |
| 8996 | "vfrustumculling [toEnable]: enables/disables objects clipping", |
| 8997 | __FILE__,VFrustumCulling,group); |
| 8998 | theCommands.Add("vhighlightselected", |
| 8999 | "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n" |
| 9000 | "Without arguments it shows if highlighting of selected objects is enabled now.", |
| 9001 | __FILE__,VHighlightSelected,group); |
| 9002 | theCommands.Add ("vplace", |
| 9003 | "vplace dx dy" |
| 9004 | "\n\t\t: Places the point (in pixels) at the center of the window", |
| 9005 | __FILE__, VPlace, group); |
| 9006 | theCommands.Add("vxrotate", |
| 9007 | "vxrotate", |
| 9008 | __FILE__,VXRotate,group); |
| 9009 | |
| 9010 | #if defined(_WIN32) |
| 9011 | theCommands.Add("vprogressive", |
| 9012 | "vprogressive", |
| 9013 | __FILE__, VProgressiveMode, group); |
| 9014 | #endif |
| 9015 | } |