Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1998-09-01 |
2 | // Created by: Robert COUBLANC | |
3 | // Copyright (c) 1998-1999 Matra Datavision | |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
5 | // | |
6 | // The content of this file is subject to the Open CASCADE Technology Public | |
7 | // License Version 6.5 (the "License"). You may not use the content of this file | |
8 | // except in compliance with the License. Please obtain a copy of the License | |
9 | // at http://www.opencascade.org and read it completely before using this file. | |
10 | // | |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
13 | // | |
14 | // The Original Code and all software distributed under the License is | |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
16 | // Initial Developer hereby disclaims all such warranties, including without | |
17 | // limitation, any warranties of merchantability, fitness for a particular | |
18 | // purpose or non-infringement. Please see the License for the specific terms | |
19 | // and conditions governing the rights and limitations under the License. | |
20 | ||
7fd59977 | 21 | #ifdef HAVE_CONFIG_H |
e276548b | 22 | #include <config.h> |
7fd59977 | 23 | #endif |
24 | ||
58655684 | 25 | #include <OpenGl_GlCore20.hxx> |
0a768f56 | 26 | #include <AIS_Shape.hxx> |
27 | #include <AIS_Drawer.hxx> | |
28 | #include <AIS_InteractiveObject.hxx> | |
29 | #include <AIS_ListOfInteractive.hxx> | |
30 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
31 | #include <DBRep.hxx> | |
2bd4c032 | 32 | #include <Graphic3d_AspectMarker3d.hxx> |
7fd59977 | 33 | #include <Graphic3d_ExportFormat.hxx> |
269294d6 | 34 | #include <Graphic3d_NameOfTextureEnv.hxx> |
35 | #include <Graphic3d_TextureEnv.hxx> | |
36 | #include <Graphic3d_TextureParams.hxx> | |
37 | #include <Graphic3d_TypeOfTextureFilter.hxx> | |
4269bd1b | 38 | #include <Graphic3d_AspectFillArea3d.hxx> |
7fd59977 | 39 | #include <ViewerTest.hxx> |
40 | #include <ViewerTest_EventManager.hxx> | |
4754e164 | 41 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
4269bd1b | 42 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> |
7fd59977 | 43 | #include <Visual3d_View.hxx> |
25289ec1 | 44 | #include <Visual3d_ViewManager.hxx> |
45 | #include <V3d_LayerMgr.hxx> | |
18d715bd | 46 | #include <NCollection_DoubleMap.hxx> |
47 | #include <NCollection_List.hxx> | |
48 | #include <NCollection_Vector.hxx> | |
7fd59977 | 49 | #include <NIS_View.hxx> |
50 | #include <NIS_Triangulated.hxx> | |
51 | #include <NIS_InteractiveContext.hxx> | |
52 | #include <AIS_InteractiveContext.hxx> | |
53 | #include <Draw_Interpretor.hxx> | |
54 | #include <Draw.hxx> | |
55 | #include <Draw_Appli.hxx> | |
7edf74fd | 56 | #include <Aspect_PrintAlgo.hxx> |
692613e5 | 57 | #include <Image_AlienPixMap.hxx> |
58655684 | 58 | #include <OpenGl_GraphicDriver.hxx> |
208e6839 | 59 | #include <OSD_Timer.hxx> |
59f45b7c | 60 | #include <TColStd_SequenceOfInteger.hxx> |
4754e164 | 61 | #include <TColStd_HSequenceOfReal.hxx> |
62 | #include <TColgp_Array1OfPnt2d.hxx> | |
20637bd2 | 63 | #include <Visual3d_LayerItem.hxx> |
64 | #include <V3d_LayerMgr.hxx> | |
65 | #include <V3d_LayerMgrPointer.hxx> | |
66 | #include <Aspect_TypeOfLine.hxx> | |
692613e5 | 67 | #include <Image_Diff.hxx> |
dc3fe572 | 68 | #include <Aspect_DisplayConnection.hxx> |
69 | #include <Graphic3d.hxx> | |
4269bd1b | 70 | #include <gp_Pnt.hxx> |
71 | #include <gp_Dir.hxx> | |
72 | #include <gp_Pln.hxx> | |
73 | #include <PrsMgr_PresentableObject.hxx> | |
74 | #include <Graphic3d_ClipPlane.hxx> | |
75 | #include <NCollection_DataMap.hxx> | |
76 | #include <Graphic3d_Texture2Dmanual.hxx> | |
77 | #include <Prs3d_ShadingAspect.hxx> | |
7fd59977 | 78 | |
25289ec1 | 79 | #ifdef WNT |
80 | #undef DrawText | |
81 | #endif | |
82 | ||
83 | #include <Visual3d_Layer.hxx> | |
692613e5 | 84 | #include <cstdlib> |
25289ec1 | 85 | |
58655684 | 86 | #if defined(_WIN32) |
4fe56619 | 87 | #include <WNT_WClass.hxx> |
88 | #include <WNT_Window.hxx> | |
89 | ||
90 | #if defined(_MSC_VER) | |
91 | #define _CRT_SECURE_NO_DEPRECATE | |
92 | #pragma warning (disable:4996) | |
93 | #endif | |
94 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
4fe56619 | 95 | #include <Cocoa_Window.hxx> |
7fd59977 | 96 | #else |
4fe56619 | 97 | #include <Xw_Window.hxx> |
98 | #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */ | |
99 | #include <X11/Xutil.h> | |
100 | #include <tk.h> | |
7fd59977 | 101 | #endif |
102 | ||
b514beda | 103 | // Auxiliary definitions |
104 | static const char THE_KEY_DELETE = 127; | |
7fd59977 | 105 | |
106 | //============================================================================== | |
107 | // VIEWER GLOBAL VARIABLES | |
108 | //============================================================================== | |
109 | ||
110 | Standard_IMPORT Standard_Boolean Draw_VirtualWindows; | |
b514beda | 111 | Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand); |
7fd59977 | 112 | |
113 | Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv); | |
114 | extern const Handle(NIS_InteractiveContext)& TheNISContext(); | |
4754e164 | 115 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
7fd59977 | 116 | |
b514beda | 117 | extern int VErase (Draw_Interpretor& theDI, |
118 | Standard_Integer theArgNb, | |
119 | const char** theArgVec); | |
120 | ||
58655684 | 121 | #if defined(_WIN32) |
7fd59977 | 122 | static Handle(WNT_Window)& VT_GetWindow() { |
123 | static Handle(WNT_Window) WNTWin; | |
124 | return WNTWin; | |
125 | } | |
4fe56619 | 126 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
4fe56619 | 127 | static Handle(Cocoa_Window)& VT_GetWindow() |
128 | { | |
129 | static Handle(Cocoa_Window) aWindow; | |
130 | return aWindow; | |
131 | } | |
132 | extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow); | |
18d715bd | 133 | extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle); |
134 | extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight); | |
135 | ||
7fd59977 | 136 | #else |
7fd59977 | 137 | static Handle(Xw_Window)& VT_GetWindow(){ |
138 | static Handle(Xw_Window) XWWin; | |
139 | return XWWin; | |
140 | } | |
7fd59977 | 141 | |
142 | static void VProcessEvents(ClientData,int); | |
143 | #endif | |
144 | ||
18d715bd | 145 | static Handle(Aspect_DisplayConnection)& GetDisplayConnection() |
146 | { | |
147 | static Handle(Aspect_DisplayConnection) aDisplayConnection; | |
148 | return aDisplayConnection; | |
149 | } | |
150 | ||
151 | static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection) | |
152 | { | |
153 | GetDisplayConnection() = theDisplayConnection; | |
154 | } | |
155 | ||
58655684 | 156 | #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
18d715bd | 157 | Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow) |
dc3fe572 | 158 | { |
0ebaa4db | 159 | Aspect_Handle aWindowHandle = (Aspect_Handle)NULL; |
58655684 | 160 | #if defined(_WIN32) |
18d715bd | 161 | const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow); |
162 | if (!aWindow.IsNull()) | |
163 | return aWindow->HWindow(); | |
164 | #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
165 | const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow); | |
166 | if (!aWindow.IsNull()) | |
167 | return aWindow->XWindow(); | |
168 | #endif | |
169 | return aWindowHandle; | |
dc3fe572 | 170 | } |
18d715bd | 171 | #endif |
dc3fe572 | 172 | |
de75ed09 | 173 | static Standard_Boolean MyHLRIsOn = Standard_False; |
7fd59977 | 174 | |
18d715bd | 175 | NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews; |
58655684 | 176 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts; |
18d715bd | 177 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers; |
58655684 | 178 | static OpenGl_Caps ViewerTest_myDefaultCaps; |
18d715bd | 179 | |
7fd59977 | 180 | #define ZCLIPWIDTH 1. |
181 | ||
182 | static void OSWindowSetup(); | |
183 | ||
184 | //============================================================================== | |
185 | // EVENT GLOBAL VARIABLES | |
186 | //============================================================================== | |
187 | ||
188 | static int Start_Rot = 0; | |
189 | static int ZClipIsOn = 0; | |
4fe56619 | 190 | int X_Motion = 0; // Current cursor position |
191 | int Y_Motion = 0; | |
192 | int X_ButtonPress = 0; // Last ButtonPress position | |
193 | int Y_ButtonPress = 0; | |
194 | Standard_Boolean IsDragged = Standard_False; | |
195 | Standard_Boolean DragFirst; | |
7fd59977 | 196 | |
197 | //============================================================================== | |
198 | ||
199 | #ifdef WNT | |
200 | static LRESULT WINAPI ViewerWindowProc( | |
201 | HWND hwnd, | |
202 | UINT uMsg, | |
203 | WPARAM wParam, | |
204 | LPARAM lParam ); | |
205 | static LRESULT WINAPI AdvViewerWindowProc( | |
206 | HWND hwnd, | |
207 | UINT uMsg, | |
208 | WPARAM wParam, | |
209 | LPARAM lParam ); | |
210 | #endif | |
211 | ||
212 | ||
213 | //============================================================================== | |
214 | //function : WClass | |
215 | //purpose : | |
216 | //============================================================================== | |
217 | ||
218 | const Handle(MMgt_TShared)& ViewerTest::WClass() | |
219 | { | |
220 | static Handle(MMgt_TShared) theWClass; | |
58655684 | 221 | #if defined(_WIN32) |
4fe56619 | 222 | if (theWClass.IsNull()) |
223 | { | |
7fd59977 | 224 | theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc, |
225 | CS_VREDRAW | CS_HREDRAW, 0, 0, | |
226 | ::LoadCursor (NULL, IDC_ARROW)); | |
227 | } | |
228 | #endif | |
229 | return theWClass; | |
230 | } | |
231 | ||
18d715bd | 232 | //============================================================================== |
233 | //function : CreateName | |
234 | //purpose : Create numerical name for new object in theMap | |
235 | //============================================================================== | |
236 | template <typename ObjectType> | |
237 | TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap, | |
238 | const TCollection_AsciiString& theDefaultString) | |
239 | { | |
240 | if (theObjectMap.IsEmpty()) | |
241 | return theDefaultString + TCollection_AsciiString(1); | |
242 | ||
243 | Standard_Integer aNextKey = 1; | |
244 | Standard_Boolean isFound = Standard_False; | |
245 | while (!isFound) | |
246 | { | |
247 | TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey); | |
248 | // Look for objects with default names | |
249 | if (theObjectMap.IsBound1(aStringKey)) | |
250 | { | |
251 | aNextKey++; | |
252 | } | |
253 | else | |
254 | isFound = Standard_True; | |
255 | } | |
256 | ||
257 | return theDefaultString + TCollection_AsciiString(aNextKey); | |
258 | } | |
259 | ||
260 | //============================================================================== | |
261 | //structure : ViewerTest_Names | |
262 | //purpose : Allow to operate with full view name: driverName/viewerName/viewName | |
263 | //============================================================================== | |
264 | struct ViewerTest_Names | |
265 | { | |
266 | private: | |
267 | TCollection_AsciiString myDriverName; | |
268 | TCollection_AsciiString myViewerName; | |
269 | TCollection_AsciiString myViewName; | |
270 | ||
271 | public: | |
272 | ||
273 | const TCollection_AsciiString& GetDriverName () const | |
274 | { | |
275 | return myDriverName; | |
276 | } | |
277 | void SetDriverName (const TCollection_AsciiString& theDriverName) | |
278 | { | |
279 | myDriverName = theDriverName; | |
280 | } | |
281 | const TCollection_AsciiString& GetViewerName () const | |
282 | { | |
283 | return myViewerName; | |
284 | } | |
285 | void SetViewerName (const TCollection_AsciiString& theViewerName) | |
286 | { | |
287 | myViewerName = theViewerName; | |
288 | } | |
289 | const TCollection_AsciiString& GetViewName () const | |
290 | { | |
291 | return myViewName; | |
292 | } | |
293 | void SetViewName (const TCollection_AsciiString& theViewName) | |
294 | { | |
295 | myViewName = theViewName; | |
296 | } | |
297 | ||
298 | //=========================================================================== | |
299 | //function : Constructor for ViewerTest_Names | |
300 | //purpose : Get view, viewer, driver names from custom string | |
301 | //=========================================================================== | |
302 | ||
303 | ViewerTest_Names (const TCollection_AsciiString& theInputString) | |
304 | { | |
305 | TCollection_AsciiString aName(theInputString); | |
306 | if (theInputString.IsEmpty()) | |
307 | { | |
308 | // Get current configuration | |
309 | if (ViewerTest_myDrivers.IsEmpty()) | |
310 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
311 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
312 | else | |
313 | myDriverName = ViewerTest_myDrivers.Find2 | |
314 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
315 | ||
316 | if(ViewerTest_myContexts.IsEmpty()) | |
317 | { | |
318 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
319 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
320 | } | |
321 | else | |
322 | myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext()); | |
323 | ||
324 | myViewName = CreateName <Handle(V3d_View)> | |
325 | (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View")); | |
326 | } | |
327 | else | |
328 | { | |
329 | // There is at least view name | |
330 | Standard_Integer aParserNumber = 0; | |
331 | for (Standard_Integer i = 0; i < 3; ++i) | |
332 | { | |
333 | Standard_Integer aParserPos = aName.SearchFromEnd("/"); | |
334 | if(aParserPos != -1) | |
335 | { | |
336 | aParserNumber++; | |
337 | aName.Split(aParserPos-1); | |
338 | } | |
339 | else | |
340 | break; | |
341 | } | |
342 | if (aParserNumber == 0) | |
343 | { | |
344 | // Only view name | |
345 | if (!ViewerTest::GetAISContext().IsNull()) | |
346 | { | |
347 | myDriverName = ViewerTest_myDrivers.Find2 | |
348 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
349 | myViewerName = ViewerTest_myContexts.Find2 | |
350 | (ViewerTest::GetAISContext()); | |
351 | } | |
352 | else | |
353 | { | |
354 | // There is no opened contexts here, need to create names for viewer and driver | |
355 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
356 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
357 | ||
358 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
359 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
360 | } | |
361 | myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString); | |
362 | } | |
363 | else if (aParserNumber == 1) | |
364 | { | |
365 | // Here is viewerName/viewName | |
366 | if (!ViewerTest::GetAISContext().IsNull()) | |
367 | myDriverName = ViewerTest_myDrivers.Find2 | |
368 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
369 | else | |
370 | { | |
371 | // There is no opened contexts here, need to create name for driver | |
372 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
373 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
374 | } | |
375 | myViewerName = TCollection_AsciiString(myDriverName + "/" + aName); | |
376 | ||
377 | myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString); | |
378 | } | |
379 | else | |
380 | { | |
381 | //Here is driverName/viewerName/viewName | |
382 | myDriverName = TCollection_AsciiString(aName); | |
383 | ||
384 | TCollection_AsciiString aViewerName(theInputString); | |
385 | aViewerName.Split(aViewerName.SearchFromEnd("/") - 1); | |
386 | myViewerName = TCollection_AsciiString(aViewerName); | |
387 | ||
388 | myViewName = TCollection_AsciiString(theInputString); | |
389 | } | |
390 | } | |
391 | } | |
392 | }; | |
393 | ||
394 | //============================================================================== | |
395 | //function : FindContextByView | |
396 | //purpose : Find AIS_InteractiveContext by View | |
397 | //============================================================================== | |
398 | ||
399 | Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView) | |
400 | { | |
401 | Handle(AIS_InteractiveContext) anAISContext; | |
402 | ||
403 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
404 | anIter (ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
405 | { | |
406 | if (anIter.Value()->CurrentViewer() == theView->Viewer()) | |
407 | return anIter.Key2(); | |
408 | } | |
409 | return anAISContext; | |
410 | } | |
411 | ||
412 | ||
413 | //============================================================================== | |
414 | //function : SetWindowTitle | |
415 | //purpose : Set window title | |
416 | //============================================================================== | |
417 | ||
418 | void SetWindowTitle (const Handle(Aspect_Window)& theWindow, | |
419 | Standard_CString theTitle) | |
420 | { | |
58655684 | 421 | #if defined(_WIN32) |
18d715bd | 422 | SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(), |
423 | theTitle); | |
424 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
425 | SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle); | |
426 | #else | |
427 | if(GetDisplayConnection()->GetDisplay()) | |
428 | { | |
429 | Window aWindow = | |
430 | Handle(Xw_Window)::DownCast(theWindow)->XWindow(); | |
431 | XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle); | |
432 | } | |
433 | #endif | |
434 | } | |
435 | ||
436 | //============================================================================== | |
437 | //function : IsWindowOverlapped | |
438 | //purpose : Check if theWindow overlapp another view | |
439 | //============================================================================== | |
440 | ||
441 | Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft, | |
442 | const Standard_Integer thePxTop, | |
443 | const Standard_Integer thePxRight, | |
444 | const Standard_Integer thePxBottom, | |
445 | TCollection_AsciiString& theViewId) | |
446 | { | |
447 | for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
448 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
449 | { | |
450 | Standard_Integer aTop = 0, | |
451 | aLeft = 0, | |
452 | aRight = 0, | |
453 | aBottom = 0; | |
454 | anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom); | |
455 | if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
456 | (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) || | |
457 | (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
458 | (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom)) | |
459 | { | |
460 | theViewId = anIter.Key1(); | |
461 | return Standard_True; | |
462 | } | |
463 | } | |
464 | return Standard_False; | |
465 | } | |
466 | ||
467 | // Workaround: to create and delete non-orthographic views outside ViewerTest | |
468 | void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName) | |
469 | { | |
470 | ViewerTest_myViews.UnBind1 (theName); | |
471 | } | |
472 | ||
473 | void ViewerTest::InitViewName (const TCollection_AsciiString& theName, | |
474 | const Handle(V3d_View)& theView) | |
475 | { | |
476 | ViewerTest_myViews.Bind (theName, theView); | |
477 | } | |
478 | ||
479 | TCollection_AsciiString ViewerTest::GetCurrentViewName () | |
480 | { | |
481 | return ViewerTest_myViews.Find2( ViewerTest::CurrentView()); | |
482 | } | |
7fd59977 | 483 | //============================================================================== |
484 | //function : ViewerInit | |
485 | //purpose : Create the window viewer and initialize all the global variable | |
486 | //============================================================================== | |
487 | ||
18d715bd | 488 | TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft, |
489 | const Standard_Integer thePxTop, | |
490 | const Standard_Integer thePxWidth, | |
491 | const Standard_Integer thePxHeight, | |
492 | Standard_CString theViewName, | |
493 | Standard_CString theDisplayName) | |
7fd59977 | 494 | { |
8c3c9904 | 495 | // Default position and dimension of the viewer window. |
4fe56619 | 496 | // Note that left top corner is set to be sufficiently small to have |
8c3c9904 | 497 | // window fit in the small screens (actual for remote desktops, see #23003). |
4fe56619 | 498 | // The position corresponds to the window's client area, thus some |
8c3c9904 | 499 | // gap is added for window frame to be visible. |
500 | Standard_Integer aPxLeft = 20; | |
501 | Standard_Integer aPxTop = 40; | |
7fd59977 | 502 | Standard_Integer aPxWidth = 409; |
503 | Standard_Integer aPxHeight = 409; | |
18d715bd | 504 | Standard_Boolean toCreateViewer = Standard_False; |
505 | ||
58655684 | 506 | Handle(OpenGl_GraphicDriver) aGraphicDriver; |
18d715bd | 507 | ViewerTest_Names aViewNames(theViewName); |
508 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ())) | |
509 | aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View")); | |
510 | ||
511 | if (thePxLeft != 0) | |
512 | aPxLeft = thePxLeft; | |
513 | if (thePxTop != 0) | |
514 | aPxTop = thePxTop; | |
515 | if (thePxWidth != 0) | |
516 | aPxWidth = thePxWidth; | |
517 | if (thePxHeight != 0) | |
7fd59977 | 518 | aPxHeight = thePxHeight; |
4269bd1b | 519 | |
18d715bd | 520 | // Get graphic driver (create it or get from another view) |
521 | if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName())) | |
522 | { | |
523 | // Get connection string | |
58655684 | 524 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
18d715bd | 525 | TCollection_AsciiString aDisplayName(theDisplayName); |
498ce76b | 526 | if (!aDisplayName.IsEmpty()) |
18d715bd | 527 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
528 | else | |
529 | SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName)); | |
18d715bd | 530 | #else |
498ce76b | 531 | (void)theDisplayName; // avoid warning on unused argument |
18d715bd | 532 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
533 | #endif | |
65993a95 | 534 | aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection()); |
58655684 | 535 | aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps; |
18d715bd | 536 | ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver); |
537 | toCreateViewer = Standard_True; | |
538 | } | |
539 | else | |
540 | { | |
58655684 | 541 | aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName())); |
7fd59977 | 542 | } |
543 | ||
18d715bd | 544 | //Dispose the window if input parameters are default |
545 | if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0) | |
7fd59977 | 546 | { |
18d715bd | 547 | Standard_Integer aTop = 0, |
548 | aLeft = 0, | |
549 | aRight = 0, | |
550 | aBottom = 0, | |
551 | aScreenWidth = 0, | |
552 | aScreenHeight = 0; | |
553 | ||
554 | // Get screen resolution | |
555 | #if defined(_WIN32) || defined(__WIN32__) | |
556 | RECT aWindowSize; | |
557 | GetClientRect(GetDesktopWindow(), &aWindowSize); | |
558 | aScreenHeight = aWindowSize.bottom; | |
559 | aScreenWidth = aWindowSize.right; | |
560 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
561 | GetCocoaScreenResolution (aScreenWidth, aScreenHeight); | |
562 | #else | |
563 | Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay()); | |
564 | aScreenWidth = WidthOfScreen(aScreen); | |
565 | aScreenHeight = HeightOfScreen(aScreen); | |
566 | #endif | |
567 | ||
568 | TCollection_AsciiString anOverlappedViewId(""); | |
773f53f1 | 569 | |
570 | while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)) | |
dc3fe572 | 571 | { |
18d715bd | 572 | ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom); |
573 | ||
574 | if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId) | |
575 | && aRight + 2*aPxWidth + 40 > aScreenWidth) | |
576 | { | |
577 | if (aBottom + aPxHeight + 40 > aScreenHeight) | |
578 | { | |
579 | aPxLeft = 20; | |
580 | aPxTop = 40; | |
581 | break; | |
582 | } | |
583 | aPxLeft = 20; | |
584 | aPxTop = aBottom + 40; | |
585 | } | |
586 | else | |
587 | aPxLeft = aRight + 20; | |
dc3fe572 | 588 | } |
18d715bd | 589 | } |
590 | ||
591 | // Get viewer name | |
592 | TCollection_AsciiString aTitle("3D View - "); | |
593 | aTitle = aTitle + aViewNames.GetViewName() + "(*)"; | |
594 | ||
595 | // Change name of current active window | |
596 | if (!ViewerTest::CurrentView().IsNull()) | |
597 | { | |
598 | TCollection_AsciiString aTitle("3D View - "); | |
599 | aTitle = aTitle | |
600 | + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); | |
601 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
602 | } | |
603 | ||
604 | // Create viewer | |
eb4320f2 | 605 | Handle(V3d_Viewer) a3DViewer; |
18d715bd | 606 | // If it's the single view, we first look for empty context |
607 | if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty()) | |
608 | { | |
609 | NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
610 | anIter(ViewerTest_myContexts); | |
611 | if (anIter.More()) | |
612 | ViewerTest::SetAISContext (anIter.Value()); | |
613 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 614 | } |
615 | else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())) | |
616 | { | |
617 | ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName())); | |
618 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 619 | } |
eb4320f2 | 620 | else if (a3DViewer.IsNull()) |
18d715bd | 621 | { |
622 | toCreateViewer = Standard_True; | |
623 | TCollection_ExtendedString NameOfWindow("Viewer3D"); | |
624 | a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString()); | |
625 | ||
626 | NameOfWindow = TCollection_ExtendedString("Collector"); | |
18d715bd | 627 | |
628 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); | |
18d715bd | 629 | } |
630 | ||
631 | // AIS context setup | |
632 | if (ViewerTest::GetAISContext().IsNull() || | |
633 | !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))) | |
634 | { | |
635 | Handle(AIS_InteractiveContext) aContext = | |
eb4320f2 | 636 | new AIS_InteractiveContext(a3DViewer); |
18d715bd | 637 | ViewerTest::SetAISContext (aContext); |
638 | ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext()); | |
639 | } | |
640 | else | |
641 | ViewerTest::ResetEventManager(); | |
642 | ||
643 | // Create window | |
4fe56619 | 644 | #if defined(_WIN32) || defined(__WIN32__) |
18d715bd | 645 | VT_GetWindow() = new WNT_Window (aTitle.ToCString(), |
7fd59977 | 646 | Handle(WNT_WClass)::DownCast (WClass()), |
abe46077 | 647 | Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW, |
7fd59977 | 648 | aPxLeft, aPxTop, |
649 | aPxWidth, aPxHeight, | |
650 | Quantity_NOC_BLACK); | |
4fe56619 | 651 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
18d715bd | 652 | VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(), |
4fe56619 | 653 | aPxLeft, aPxTop, |
654 | aPxWidth, aPxHeight); | |
655 | ViewerTest_SetCocoaEventManagerView (VT_GetWindow()); | |
7fd59977 | 656 | #else |
18d715bd | 657 | VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(), |
658 | aTitle.ToCString(), | |
7fd59977 | 659 | aPxLeft, aPxTop, |
ed97f43c | 660 | aPxWidth, aPxHeight); |
7fd59977 | 661 | #endif |
18d715bd | 662 | VT_GetWindow()->SetVirtual (Draw_VirtualWindows); |
7fd59977 | 663 | |
18d715bd | 664 | // NIS setup |
665 | Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow()); | |
4269bd1b | 666 | |
18d715bd | 667 | ViewerTest::CurrentView(aView); |
668 | ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView); | |
669 | TheNISContext()->AttachView (aView); | |
7fd59977 | 670 | |
18d715bd | 671 | // Setup for X11 or NT |
672 | OSWindowSetup(); | |
7fd59977 | 673 | |
18d715bd | 674 | // Set parameters for V3d_View and V3d_Viewer |
675 | const Handle (V3d_View) aV3dView = ViewerTest::CurrentView(); | |
676 | aV3dView->SetComputedMode(Standard_False); | |
677 | MyHLRIsOn = aV3dView->ComputedMode(); | |
678 | aV3dView->SetZClippingDepth(0.5); | |
679 | aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.); | |
7fd59977 | 680 | |
18d715bd | 681 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); |
682 | if (toCreateViewer) | |
683 | { | |
7fd59977 | 684 | a3DViewer->SetDefaultLights(); |
685 | a3DViewer->SetLightOn(); | |
18d715bd | 686 | } |
7fd59977 | 687 | |
4fe56619 | 688 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
689 | #if TCL_MAJOR_VERSION < 8 | |
18d715bd | 690 | Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 691 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
4fe56619 | 692 | #else |
18d715bd | 693 | Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 694 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
4fe56619 | 695 | #endif |
696 | #endif | |
7fd59977 | 697 | |
7fd59977 | 698 | VT_GetWindow()->Map(); |
4269bd1b | 699 | |
18d715bd | 700 | // Set the handle of created view in the event manager |
701 | ViewerTest::ResetEventManager(); | |
702 | ||
4fe56619 | 703 | ViewerTest::CurrentView()->Redraw(); |
18d715bd | 704 | |
705 | aView.Nullify(); | |
706 | a3DViewer.Nullify(); | |
18d715bd | 707 | |
708 | return aViewNames.GetViewName(); | |
709 | } | |
710 | ||
4269bd1b | 711 | //============================================================================== |
712 | //function : RedrawAllViews | |
713 | //purpose : Redraw all created views | |
714 | //============================================================================== | |
715 | void ViewerTest::RedrawAllViews() | |
716 | { | |
717 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
718 | for (; aViewIt.More(); aViewIt.Next()) | |
719 | { | |
720 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
721 | aView->Redraw(); | |
722 | } | |
723 | } | |
724 | ||
18d715bd | 725 | //============================================================================== |
392ac980 | 726 | //function : splitParameter |
727 | //purpose : Split parameter string to parameter name an parameter value | |
18d715bd | 728 | //============================================================================== |
392ac980 | 729 | Standard_Boolean splitParameter (const TCollection_AsciiString& theString, |
730 | TCollection_AsciiString& theName, | |
731 | TCollection_AsciiString& theValue) | |
18d715bd | 732 | { |
733 | Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length()); | |
734 | if (aParamNameEnd == 0) | |
735 | return Standard_False; | |
736 | TCollection_AsciiString aString(theString); | |
737 | if (aParamNameEnd != 0) | |
738 | { | |
739 | theValue = aString.Split(aParamNameEnd); | |
740 | aString.Split(aString.Length()-1); | |
741 | theName = aString; | |
742 | } | |
743 | return Standard_True; | |
7fd59977 | 744 | } |
745 | ||
746 | //============================================================================== | |
747 | //function : Vinit | |
748 | //purpose : Create the window viewer and initialize all the global variable | |
749 | // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event | |
750 | //============================================================================== | |
751 | ||
18d715bd | 752 | static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 753 | { |
18d715bd | 754 | if (theArgsNb > 9) |
755 | { | |
756 | theDi << theArgVec[0] << ": incorrect number of command arguments.\n" | |
757 | << "Type help for more information.\n"; | |
758 | return 1; | |
759 | } | |
760 | TCollection_AsciiString aViewName (""), | |
761 | aDisplayName (""); | |
762 | Standard_Integer aPxLeft = 0, | |
763 | aPxTop = 0, | |
764 | aPxWidth = 0, | |
765 | aPxHeight = 0; | |
766 | ||
767 | for (Standard_Integer i = 1; i < theArgsNb; ++i) | |
768 | { | |
769 | TCollection_AsciiString aName = "", aValue = ""; | |
392ac980 | 770 | if(!splitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2) |
18d715bd | 771 | { |
772 | // In case of syntax: vinit ViewName | |
773 | aViewName = theArgVec[1]; | |
774 | } | |
775 | else | |
776 | { | |
777 | if (aName == "name") | |
778 | { | |
779 | aViewName = aValue; | |
780 | } | |
781 | else if (aName == "l" || aName == "left") | |
782 | aPxLeft = aValue.IntegerValue(); | |
783 | else if (aName == "t" || aName == "top") | |
784 | aPxTop = aValue.IntegerValue(); | |
785 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
786 | else if (aName == "display") | |
787 | aDisplayName = aValue; | |
788 | #endif | |
789 | else if (aName == "w" || aName == "width") | |
790 | aPxWidth = aValue.IntegerValue(); | |
791 | else if (aName == "h" || aName == "height") | |
792 | aPxHeight = aValue.IntegerValue(); | |
793 | else | |
794 | { | |
795 | theDi << theArgVec[0] << ": Warning: unknown parameter " << aName.ToCString() << ".\n"; | |
796 | } | |
797 | } | |
798 | } | |
799 | ||
800 | ViewerTest_Names aViewNames (aViewName); | |
801 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ())) | |
802 | { | |
803 | TCollection_AsciiString aCommand("vactivate "); | |
804 | aCommand = aCommand + aViewNames.GetViewName(); | |
805 | theDi.Eval(aCommand.ToCString()); | |
806 | return 0; | |
807 | } | |
808 | ||
809 | TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight, | |
810 | aViewName.ToCString(), | |
811 | aDisplayName.ToCString()); | |
812 | cout << theArgVec[0] << ": 3D View - " << aViewId << " was created.\n"; | |
7fd59977 | 813 | return 0; |
814 | } | |
815 | ||
0a768f56 | 816 | //============================================================================== |
817 | //function : VHLR | |
818 | //purpose : hidden lines removal algorithm | |
819 | //============================================================================== | |
820 | ||
821 | static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
822 | { | |
823 | if (ViewerTest::CurrentView().IsNull()) | |
824 | { | |
825 | di << argv[0] << ": Call vinit before this command, please.\n"; | |
826 | return 1; | |
827 | } | |
828 | ||
829 | if (argc != 2) | |
830 | { | |
831 | di << argv[0] << ": Wrong number of command arguments.\n" | |
832 | << "Type help " << argv[0] << " for more information.\n"; | |
833 | return 1; | |
834 | } | |
835 | ||
836 | Standard_Boolean isHLROn = | |
837 | (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False; | |
838 | ||
839 | if (isHLROn == MyHLRIsOn) | |
840 | { | |
841 | return 0; | |
842 | } | |
843 | ||
844 | MyHLRIsOn = isHLROn; | |
845 | ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn); | |
846 | ||
847 | return 0; | |
848 | } | |
849 | ||
850 | //============================================================================== | |
851 | //function : VHLRType | |
852 | //purpose : change type of using HLR algorithm | |
853 | //============================================================================== | |
854 | ||
855 | static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
856 | { | |
857 | if (ViewerTest::CurrentView().IsNull()) | |
858 | { | |
859 | di << argv[0] << ": Call vinit before this command, please.\n"; | |
860 | return 1; | |
861 | } | |
862 | ||
863 | if (argc < 2) | |
864 | { | |
865 | di << argv[0] << ": Wrong number of command arguments.\n" | |
866 | << "Type help " << argv[0] << " for more information.\n"; | |
867 | return 1; | |
868 | } | |
869 | ||
870 | Prs3d_TypeOfHLR aTypeOfHLR = | |
871 | (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo; | |
872 | ||
873 | if (argc == 2) | |
874 | { | |
875 | AIS_ListOfInteractive aListOfShapes; | |
876 | ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes); | |
877 | ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR); | |
878 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); | |
879 | anIter.More(); anIter.Next()) | |
880 | { | |
881 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
882 | if (aShape.IsNull()) | |
883 | continue; | |
884 | if (aShape->TypeOfHLR() != aTypeOfHLR) | |
885 | aShape->SetTypeOfHLR (aTypeOfHLR); | |
886 | if (MyHLRIsOn) | |
887 | aShape->Redisplay(); | |
888 | } | |
889 | ViewerTest::CurrentView()->Update(); | |
890 | return 0; | |
891 | } | |
892 | else | |
893 | { | |
894 | for (Standard_Integer i = 2; i < argc; ++i) | |
895 | { | |
896 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
897 | TCollection_AsciiString aName (argv[i]); | |
898 | ||
899 | if (!aMap.IsBound2 (aName)) | |
900 | { | |
901 | di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n"; | |
902 | continue; | |
903 | } | |
904 | Handle(AIS_Shape) anAISObject = | |
905 | Handle(AIS_Shape)::DownCast (aMap.Find2(aName)); | |
906 | if (anAISObject.IsNull()) | |
907 | continue; | |
908 | anAISObject->SetTypeOfHLR (aTypeOfHLR); | |
909 | if (MyHLRIsOn) | |
910 | anAISObject->Redisplay(); | |
911 | } | |
912 | ViewerTest::CurrentView()->Update(); | |
913 | } | |
914 | ||
915 | return 0; | |
916 | } | |
917 | ||
18d715bd | 918 | //============================================================================== |
919 | //function : FindViewIdByWindowHandle | |
920 | //purpose : Find theView Id in the map of views by window handle | |
921 | //============================================================================== | |
922 | #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
923 | TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle) | |
924 | { | |
925 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
926 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
927 | { | |
928 | Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window()); | |
929 | if (aWindowHandle == theWindowHandle) | |
930 | return anIter.Key1(); | |
931 | } | |
932 | return TCollection_AsciiString(""); | |
933 | } | |
934 | #endif | |
935 | ||
936 | //============================================================================== | |
937 | //function : ActivateView | |
938 | //purpose : Make the view active | |
939 | //============================================================================== | |
940 | ||
941 | void ActivateView (const TCollection_AsciiString& theViewName) | |
942 | { | |
943 | const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
944 | if (!aView.IsNull()) | |
945 | { | |
946 | Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView); | |
947 | if (!anAISContext.IsNull()) | |
948 | { | |
949 | if (!ViewerTest::CurrentView().IsNull()) | |
950 | { | |
951 | TCollection_AsciiString aTitle("3D View - "); | |
952 | aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); | |
953 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
954 | } | |
955 | ||
956 | ViewerTest::CurrentView (aView); | |
957 | // Update degenerate mode | |
958 | MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode(); | |
959 | ViewerTest::SetAISContext (anAISContext); | |
960 | TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - "); | |
961 | aTitle = aTitle + theViewName + "(*)"; | |
962 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
963 | #if defined(_WIN32) || defined(__WIN32__) | |
964 | VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
965 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
966 | VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
967 | #else | |
968 | VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
969 | #endif | |
970 | SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); | |
971 | ViewerTest::CurrentView()->Redraw(); | |
972 | } | |
973 | } | |
974 | } | |
975 | ||
976 | //============================================================================== | |
977 | //function : RemoveView | |
978 | //purpose : Close and remove view from display, clear maps if neccessary | |
979 | //============================================================================== | |
980 | void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved) | |
981 | { | |
982 | if (!ViewerTest_myViews.IsBound1(theViewName)) | |
983 | { | |
984 | cout << "Wrong view name\n"; | |
985 | return; | |
986 | } | |
987 | ||
988 | // Activate another view if it's active now | |
989 | if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView()) | |
990 | { | |
991 | if (ViewerTest_myViews.Extent() > 1) | |
992 | { | |
993 | TCollection_AsciiString aNewViewName; | |
994 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator | |
995 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
996 | if (anIter.Key1() != theViewName) | |
997 | { | |
998 | aNewViewName = anIter.Key1(); | |
999 | break; | |
1000 | } | |
1001 | ActivateView (aNewViewName); | |
1002 | } | |
1003 | else | |
1004 | { | |
1005 | Handle(V3d_View) anEmptyView; | |
1006 | #if defined(_WIN32) || defined(__WIN32__) | |
1007 | Handle(WNT_Window) anEmptyWindow; | |
1008 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1009 | Handle(Cocoa_Window) anEmptyWindow; | |
1010 | #else | |
1011 | Handle(Xw_Window) anEmptyWindow; | |
1012 | #endif | |
1013 | VT_GetWindow() = anEmptyWindow; | |
1014 | ViewerTest::CurrentView (anEmptyView); | |
1015 | if (isContextRemoved) | |
1016 | { | |
1017 | Handle(AIS_InteractiveContext) anEmptyContext; | |
1018 | ViewerTest::SetAISContext(anEmptyContext); | |
1019 | } | |
1020 | } | |
1021 | } | |
1022 | ||
1023 | // Delete view | |
1024 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
1025 | Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView); | |
1026 | ||
1027 | // Remove view resources | |
1028 | TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView)); | |
1029 | ViewerTest_myViews.UnBind1(theViewName); | |
1030 | aView->Remove(); | |
1031 | ||
1032 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
1033 | XFlush (GetDisplayConnection()->GetDisplay()); | |
1034 | #endif | |
1035 | ||
1036 | // Keep context opened only if the closed view is last to avoid | |
1037 | // unused empty contexts | |
1038 | if (!aCurrentContext.IsNull()) | |
1039 | { | |
1040 | // Check if there are more difined views in the viewer | |
1041 | aCurrentContext->CurrentViewer()->InitDefinedViews(); | |
1042 | if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews()) | |
1043 | { | |
1044 | // Remove driver if there is no viewers that use it | |
1045 | Standard_Boolean isRemoveDriver = Standard_True; | |
1046 | for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1047 | anIter(ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
1048 | { | |
1049 | if (aCurrentContext != anIter.Key2() && | |
1050 | aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver()) | |
1051 | { | |
1052 | isRemoveDriver = Standard_False; | |
1053 | break; | |
1054 | } | |
1055 | } | |
1056 | if(isRemoveDriver) | |
1057 | { | |
1058 | ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver()); | |
1059 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
1060 | #if TCL_MAJOR_VERSION < 8 | |
1061 | Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); | |
1062 | #else | |
1063 | Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); | |
1064 | #endif | |
1065 | #endif | |
1066 | } | |
1067 | ||
1068 | ViewerTest_myContexts.UnBind2(aCurrentContext); | |
1069 | } | |
1070 | } | |
1071 | cout << "3D View - " << theViewName << " was deleted.\n"; | |
1072 | ||
1073 | } | |
1074 | ||
1075 | //============================================================================== | |
1076 | //function : VClose | |
1077 | //purpose : Remove the view defined by its name | |
1078 | //============================================================================== | |
1079 | ||
d0cc1cb7 | 1080 | static int VClose (Draw_Interpretor& /*theDi*/, |
1081 | Standard_Integer theArgsNb, | |
1082 | const char** theArgVec) | |
18d715bd | 1083 | { |
18d715bd | 1084 | NCollection_List<TCollection_AsciiString> aViewList; |
d0cc1cb7 | 1085 | if (theArgsNb > 1) |
18d715bd | 1086 | { |
d0cc1cb7 | 1087 | TCollection_AsciiString anArg (theArgVec[1]); |
1088 | anArg.UpperCase(); | |
1089 | if (anArg.IsEqual ("ALL") | |
1090 | || anArg.IsEqual ("*")) | |
1091 | { | |
1092 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews); | |
1093 | anIter.More(); anIter.Next()) | |
1094 | { | |
1095 | aViewList.Append (anIter.Key1()); | |
1096 | } | |
1097 | if (aViewList.IsEmpty()) | |
1098 | { | |
1099 | std::cout << "No view to close\n"; | |
1100 | return 0; | |
1101 | } | |
1102 | } | |
1103 | else | |
18d715bd | 1104 | { |
d0cc1cb7 | 1105 | ViewerTest_Names aViewName (theArgVec[1]); |
1106 | if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName())) | |
1107 | { | |
1108 | std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n"; | |
1109 | return 1; | |
1110 | } | |
1111 | aViewList.Append (aViewName.GetViewName()); | |
18d715bd | 1112 | } |
1113 | } | |
1114 | else | |
1115 | { | |
d0cc1cb7 | 1116 | // close active view |
1117 | if (ViewerTest::CurrentView().IsNull()) | |
1118 | { | |
1119 | std::cerr << "No active view!\n"; | |
1120 | return 1; | |
1121 | } | |
1122 | aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView())); | |
18d715bd | 1123 | } |
1124 | ||
d0cc1cb7 | 1125 | Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1); |
18d715bd | 1126 | for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList); |
1127 | anIter.More(); anIter.Next()) | |
1128 | { | |
d0cc1cb7 | 1129 | ViewerTest::RemoveView (anIter.Value(), toRemoveContext); |
18d715bd | 1130 | } |
1131 | ||
1132 | return 0; | |
1133 | } | |
1134 | ||
1135 | //============================================================================== | |
1136 | //function : VActivate | |
1137 | //purpose : Activate the view defined by its ID | |
1138 | //============================================================================== | |
1139 | ||
1140 | static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
1141 | { | |
1142 | if (theArgsNb > 2) | |
1143 | { | |
1144 | theDi << theArgVec[0] << ": wrong number of command arguments.\n" | |
1145 | << "Usage: " << theArgVec[0] << " ViewID\n"; | |
1146 | return 1; | |
1147 | } | |
1148 | if(theArgsNb == 1) | |
1149 | { | |
1150 | theDi.Eval("vviewlist"); | |
1151 | return 0; | |
1152 | } | |
1153 | ||
1154 | TCollection_AsciiString aNameString(theArgVec[1]); | |
29cb310a | 1155 | if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 ) |
18d715bd | 1156 | { |
1157 | TCollection_AsciiString aTitle("3D View - "); | |
1158 | aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView()); | |
1159 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1160 | Handle(V3d_View) anEmptyView; | |
1161 | #if defined(_WIN32) || defined(__WIN32__) | |
1162 | Handle(WNT_Window) anEmptyWindow; | |
1163 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1164 | Handle(Cocoa_Window) anEmptyWindow; | |
1165 | #else | |
1166 | Handle(Xw_Window) anEmptyWindow; | |
1167 | #endif | |
1168 | VT_GetWindow() = anEmptyWindow; | |
1169 | ViewerTest::CurrentView (anEmptyView); | |
1170 | ViewerTest::ResetEventManager(); | |
1171 | theDi << theArgVec[0] << ": all views are inactive\n"; | |
1172 | return 0; | |
1173 | } | |
1174 | ||
1175 | ViewerTest_Names aViewNames(aNameString); | |
1176 | ||
1177 | // Check if this view exists in the viewer with the driver | |
1178 | if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName())) | |
1179 | { | |
1180 | theDi << "Wrong view name\n"; | |
1181 | return 1; | |
1182 | } | |
1183 | ||
1184 | // Check if it is active already | |
1185 | if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName())) | |
1186 | { | |
1187 | theDi << theArgVec[0] << ": the view is active already\n"; | |
1188 | return 0; | |
1189 | } | |
1190 | ||
1191 | ActivateView (aViewNames.GetViewName()); | |
1192 | return 0; | |
1193 | } | |
1194 | ||
1195 | //============================================================================== | |
1196 | //function : VViewList | |
1197 | //purpose : Print current list of views per viewer and graphic driver ID | |
1198 | // shared between viewers | |
1199 | //============================================================================== | |
1200 | ||
1201 | static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
1202 | { | |
1203 | if (theArgsNb > 2) | |
1204 | { | |
1205 | theDi << theArgVec[0] << ": Wrong number of command arguments\n" | |
29cb310a | 1206 | << "Usage: " << theArgVec[0] << " name"; |
18d715bd | 1207 | return 1; |
1208 | } | |
1209 | if (ViewerTest_myContexts.Size() < 1) | |
1210 | return 0; | |
1211 | ||
18d715bd | 1212 | Standard_Boolean isTreeView = |
29cb310a | 1213 | (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 )); |
18d715bd | 1214 | |
1215 | if (isTreeView) | |
1216 | theDi << theArgVec[0] <<":\n"; | |
1217 | ||
1218 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
1219 | aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next()) | |
1220 | { | |
1221 | if (isTreeView) | |
1222 | theDi << aDriverIter.Key1() << ":\n"; | |
1223 | ||
1224 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1225 | aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next()) | |
1226 | { | |
1227 | if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1) | |
1228 | { | |
1229 | if (isTreeView) | |
1230 | { | |
1231 | TCollection_AsciiString aContextName(aContextIter.Key1()); | |
1232 | theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n"; | |
1233 | } | |
1234 | ||
1235 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
1236 | aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next()) | |
1237 | { | |
1238 | if (aViewIter.Key1().Search(aContextIter.Key1()) != -1) | |
1239 | { | |
1240 | TCollection_AsciiString aViewName(aViewIter.Key1()); | |
1241 | if (isTreeView) | |
1242 | { | |
1243 | if (aViewIter.Value() == ViewerTest::CurrentView()) | |
1244 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n"; | |
1245 | else | |
1246 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n"; | |
1247 | } | |
1248 | else | |
1249 | { | |
1250 | theDi << aViewName << " "; | |
1251 | } | |
1252 | } | |
1253 | } | |
1254 | } | |
1255 | } | |
1256 | } | |
1257 | return 0; | |
1258 | } | |
1259 | ||
7fd59977 | 1260 | //============================================================================== |
4fe56619 | 1261 | //function : VT_ProcessKeyPress |
7fd59977 | 1262 | //purpose : Handle KeyPress event from a CString |
1263 | //============================================================================== | |
4fe56619 | 1264 | void VT_ProcessKeyPress (const char* buf_ret) |
7fd59977 | 1265 | { |
1266 | //cout << "KeyPress" << endl; | |
1267 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
1268 | const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView); | |
1269 | // Letter in alphabetic order | |
1270 | ||
b514beda | 1271 | if (!strcasecmp (buf_ret, "A")) |
1272 | { | |
7fd59977 | 1273 | // AXO |
1274 | aView->SetProj(V3d_XposYnegZpos); | |
1275 | } | |
b514beda | 1276 | else if (!strcasecmp (buf_ret, "D")) |
1277 | { | |
7fd59977 | 1278 | // Reset |
1279 | aView->Reset(); | |
1280 | } | |
b514beda | 1281 | else if (!strcasecmp (buf_ret, "F")) |
1282 | { | |
7fd59977 | 1283 | // FitAll |
1284 | if (aNisView.IsNull()) | |
1285 | aView->FitAll(); | |
1286 | else | |
1287 | aNisView->FitAll3d(); | |
1288 | } | |
b514beda | 1289 | else if (!strcasecmp (buf_ret, "H")) |
1290 | { | |
7fd59977 | 1291 | // HLR |
1292 | cout << "HLR" << endl; | |
de75ed09 | 1293 | aView->SetComputedMode (!aView->ComputedMode()); |
1294 | MyHLRIsOn = aView->ComputedMode(); | |
7fd59977 | 1295 | } |
b514beda | 1296 | else if (!strcasecmp (buf_ret, "P")) |
1297 | { | |
0a768f56 | 1298 | // Type of HLR |
1299 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
1300 | if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo) | |
1301 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo); | |
1302 | else | |
1303 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo); | |
1304 | if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0) | |
1305 | { | |
1306 | AIS_ListOfInteractive aListOfShapes; | |
1307 | aContext->DisplayedObjects(aListOfShapes); | |
1308 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); | |
1309 | anIter.More(); anIter.Next()) | |
1310 | { | |
1311 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
1312 | if (aShape.IsNull()) | |
1313 | continue; | |
1314 | if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1315 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1316 | else | |
1317 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
1318 | aShape->Redisplay(); | |
1319 | } | |
1320 | } | |
1321 | else | |
1322 | { | |
1323 | for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()) | |
1324 | { | |
1325 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current()); | |
1326 | if (aShape.IsNull()) | |
1327 | continue; | |
1328 | if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1329 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1330 | else | |
1331 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
1332 | aShape->Redisplay(); | |
1333 | } | |
1334 | } | |
1335 | ||
1336 | aContext->UpdateCurrentViewer(); | |
4269bd1b | 1337 | |
0a768f56 | 1338 | } |
b514beda | 1339 | else if (!strcasecmp (buf_ret, "S")) |
1340 | { | |
1341 | std::cout << "setup Shaded display mode" << std::endl; | |
4fe56619 | 1342 | |
7fd59977 | 1343 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
1344 | if(Ctx->NbCurrents()==0 || | |
1345 | Ctx->NbSelected()==0) | |
1346 | Ctx->SetDisplayMode(AIS_Shaded); | |
1347 | else{ | |
1348 | if(Ctx->HasOpenedContext()){ | |
1349 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1350 | Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False); | |
1351 | } | |
1352 | else{ | |
1353 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
1354 | Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False); | |
1355 | } | |
1356 | Ctx->UpdateCurrentViewer(); | |
1357 | } | |
1358 | } | |
b514beda | 1359 | else if (!strcasecmp (buf_ret, "U")) |
1360 | { | |
41811896 | 1361 | // Unset display mode |
b514beda | 1362 | std::cout << "reset display mode to defaults" << std::endl; |
4fe56619 | 1363 | |
7fd59977 | 1364 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
1365 | if(Ctx->NbCurrents()==0 || | |
1366 | Ctx->NbSelected()==0) | |
1367 | Ctx->SetDisplayMode(AIS_WireFrame); | |
1368 | else{ | |
1369 | if(Ctx->HasOpenedContext()){ | |
1370 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1371 | Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False); | |
1372 | } | |
1373 | else{ | |
1374 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
1375 | Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False); | |
1376 | } | |
1377 | Ctx->UpdateCurrentViewer(); | |
1378 | } | |
1379 | ||
1380 | } | |
b514beda | 1381 | else if (!strcasecmp (buf_ret, "T")) |
1382 | { | |
7fd59977 | 1383 | // Top |
1384 | aView->SetProj(V3d_Zpos); | |
1385 | } | |
b514beda | 1386 | else if (!strcasecmp (buf_ret, "B")) |
1387 | { | |
41811896 | 1388 | // Bottom |
7fd59977 | 1389 | aView->SetProj(V3d_Zneg); |
1390 | } | |
b514beda | 1391 | else if (!strcasecmp (buf_ret, "L")) |
1392 | { | |
41811896 | 1393 | // Left |
7fd59977 | 1394 | aView->SetProj(V3d_Xneg); |
1395 | } | |
b514beda | 1396 | else if (!strcasecmp (buf_ret, "R")) |
1397 | { | |
41811896 | 1398 | // Right |
7fd59977 | 1399 | aView->SetProj(V3d_Xpos); |
1400 | } | |
b514beda | 1401 | else if (!strcasecmp (buf_ret, "W")) |
1402 | { | |
1403 | std::cout << "setup WireFrame display mode" << std::endl; | |
7fd59977 | 1404 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
1405 | if(Ctx->NbCurrents()==0 || | |
1406 | Ctx->NbSelected()==0) | |
1407 | Ctx->SetDisplayMode(AIS_WireFrame); | |
1408 | else{ | |
1409 | if(Ctx->HasOpenedContext()){ | |
1410 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1411 | Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False); | |
1412 | } | |
1413 | else{ | |
1414 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
1415 | Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False); | |
1416 | } | |
1417 | Ctx->UpdateCurrentViewer(); | |
1418 | } | |
1419 | } | |
b514beda | 1420 | else if (!strcasecmp (buf_ret, "Z")) |
1421 | { | |
7fd59977 | 1422 | // ZCLIP |
7fd59977 | 1423 | if ( ZClipIsOn ) { |
1424 | cout << "ZClipping OFF" << endl; | |
1425 | ZClipIsOn = 0; | |
1426 | ||
1427 | aView->SetZClippingType(V3d_OFF); | |
1428 | aView->Redraw(); | |
1429 | } | |
1430 | else { | |
1431 | cout << "ZClipping ON" << endl; | |
1432 | ZClipIsOn = 1; | |
1433 | ||
1434 | aView->SetZClippingType(V3d_FRONT); | |
1435 | aView->Redraw(); | |
1436 | } | |
1437 | } | |
b514beda | 1438 | else if (!strcasecmp (buf_ret, ",")) |
1439 | { | |
7fd59977 | 1440 | ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView()); |
7fd59977 | 1441 | } |
b514beda | 1442 | else if (!strcasecmp (buf_ret, ".")) |
1443 | { | |
7fd59977 | 1444 | ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView()); |
1445 | } | |
b514beda | 1446 | else if (*buf_ret == THE_KEY_DELETE) |
1447 | { | |
1448 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
1449 | if (!aCtx.IsNull() | |
1450 | && aCtx->NbCurrents() > 0 | |
1451 | && aCtx->NbSelected() > 0) | |
1452 | { | |
1453 | Draw_Interprete ("verase"); | |
1454 | } | |
1455 | } | |
1456 | else | |
1457 | { | |
1458 | // Number | |
91322f44 | 1459 | Standard_Integer Num = Draw::Atoi(buf_ret); |
7fd59977 | 1460 | if(Num>=0 && Num<=7) |
1461 | ViewerTest::StandardModeActivation(Num); | |
1462 | } | |
1463 | } | |
1464 | ||
1465 | //============================================================================== | |
4fe56619 | 1466 | //function : VT_ProcessExpose |
7fd59977 | 1467 | //purpose : Redraw the View on an Expose Event |
1468 | //============================================================================== | |
4fe56619 | 1469 | void VT_ProcessExpose() |
1470 | { | |
1471 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); | |
1472 | if (!aView3d.IsNull()) | |
1473 | { | |
1474 | aView3d->Redraw(); | |
1475 | } | |
7fd59977 | 1476 | } |
1477 | ||
1478 | //============================================================================== | |
4fe56619 | 1479 | //function : VT_ProcessConfigure |
7fd59977 | 1480 | //purpose : Resize the View on an Configure Event |
1481 | //============================================================================== | |
4fe56619 | 1482 | void VT_ProcessConfigure() |
7fd59977 | 1483 | { |
4fe56619 | 1484 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); |
1485 | if (aView3d.IsNull()) | |
1486 | { | |
1487 | return; | |
1488 | } | |
1489 | ||
1490 | aView3d->MustBeResized(); | |
1491 | aView3d->Update(); | |
1492 | aView3d->Redraw(); | |
7fd59977 | 1493 | } |
1494 | ||
1495 | //============================================================================== | |
4fe56619 | 1496 | //function : VT_ProcessButton1Press |
7fd59977 | 1497 | //purpose : Picking |
1498 | //============================================================================== | |
4fe56619 | 1499 | Standard_Boolean VT_ProcessButton1Press( |
7fd59977 | 1500 | Standard_Integer , |
4fe56619 | 1501 | const char** argv, |
7fd59977 | 1502 | Standard_Boolean pick, |
4fe56619 | 1503 | Standard_Boolean shift) |
7fd59977 | 1504 | { |
1505 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1506 | if ( pick ) { | |
1507 | Standard_Real X, Y, Z; | |
1508 | ||
1509 | ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z); | |
1510 | ||
1511 | Draw::Set(argv[1], X); | |
1512 | Draw::Set(argv[2], Y); | |
1513 | Draw::Set(argv[3], Z);} | |
1514 | ||
1515 | if(shift) | |
1516 | EM->ShiftSelect(); | |
1517 | else | |
1518 | EM->Select(); | |
1519 | ||
1520 | pick = 0; | |
1521 | return pick; | |
1522 | } | |
1523 | ||
1524 | //============================================================================== | |
4fe56619 | 1525 | //function : VT_ProcessButton1Release |
1526 | //purpose : End selecting | |
7fd59977 | 1527 | //============================================================================== |
4fe56619 | 1528 | void VT_ProcessButton1Release (Standard_Boolean theIsShift) |
1529 | { | |
1530 | if (IsDragged) | |
1531 | { | |
1532 | IsDragged = Standard_False; | |
1533 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1534 | if (theIsShift) | |
1535 | { | |
1536 | EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion), | |
1537 | Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion)); | |
1538 | } | |
1539 | else | |
1540 | { | |
1541 | EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion), | |
1542 | Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion)); | |
1543 | } | |
1544 | } | |
1545 | } | |
7fd59977 | 1546 | |
4fe56619 | 1547 | //============================================================================== |
1548 | //function : VT_ProcessButton3Press | |
1549 | //purpose : Start Rotation | |
1550 | //============================================================================== | |
1551 | void VT_ProcessButton3Press() | |
1552 | { | |
7fd59977 | 1553 | Start_Rot = 1; |
de75ed09 | 1554 | if (MyHLRIsOn) |
1555 | { | |
1556 | ViewerTest::CurrentView()->SetComputedMode (Standard_False); | |
1557 | } | |
7fd59977 | 1558 | ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress ); |
7fd59977 | 1559 | } |
4fe56619 | 1560 | |
7fd59977 | 1561 | //============================================================================== |
4fe56619 | 1562 | //function : VT_ProcessButton3Release |
1563 | //purpose : End rotation | |
7fd59977 | 1564 | //============================================================================== |
4fe56619 | 1565 | void VT_ProcessButton3Release() |
1566 | { | |
1567 | if (Start_Rot) | |
1568 | { | |
7fd59977 | 1569 | Start_Rot = 0; |
de75ed09 | 1570 | if (MyHLRIsOn) |
1571 | { | |
1572 | ViewerTest::CurrentView()->SetComputedMode (Standard_True); | |
1573 | } | |
7fd59977 | 1574 | } |
7fd59977 | 1575 | } |
1576 | ||
1577 | //============================================================================== | |
1578 | //function : ProcessZClipMotion | |
1579 | //purpose : Zoom | |
1580 | //============================================================================== | |
1581 | ||
1582 | void ProcessZClipMotion() | |
1583 | { | |
1584 | Handle(V3d_View) a3DView = ViewerTest::CurrentView(); | |
1585 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { | |
1586 | static Standard_Real CurZPos = 0.; | |
1587 | ||
1588 | //Quantity_Length VDX, VDY; | |
1589 | //a3DView->Size(VDX,VDY); | |
1590 | //Standard_Real VDZ = a3DView->ZSize(); | |
1591 | //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ); | |
1592 | ||
1593 | Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress); | |
1594 | ||
1595 | // Front = Depth + width/2. | |
1596 | Standard_Real D = 0.5; | |
1597 | Standard_Real W = 0.1; | |
1598 | ||
1599 | CurZPos += (dx); | |
1600 | ||
1601 | D += CurZPos; | |
1602 | ||
1603 | //printf("dx %lf Depth %lf Width %lf\n", dx, D, W); | |
1604 | ||
1605 | a3DView->SetZClippingType(V3d_OFF); | |
1606 | a3DView->SetZClippingDepth(D); | |
1607 | a3DView->SetZClippingWidth(W); | |
1608 | a3DView->SetZClippingType(V3d_FRONT); | |
1609 | ||
1610 | a3DView->Redraw(); | |
1611 | ||
1612 | X_ButtonPress = X_Motion; | |
1613 | Y_ButtonPress = Y_Motion; | |
1614 | } | |
1615 | } | |
1616 | ||
1617 | //============================================================================== | |
1618 | //function : ProcessControlButton1Motion | |
1619 | //purpose : Zoom | |
1620 | //============================================================================== | |
1621 | ||
1622 | static void ProcessControlButton1Motion() | |
1623 | { | |
1624 | ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion); | |
1625 | ||
1626 | X_ButtonPress = X_Motion; | |
1627 | Y_ButtonPress = Y_Motion; | |
1628 | } | |
1629 | ||
1630 | //============================================================================== | |
4fe56619 | 1631 | //function : VT_ProcessControlButton2Motion |
1632 | //purpose : Panning | |
7fd59977 | 1633 | //============================================================================== |
4fe56619 | 1634 | void VT_ProcessControlButton2Motion() |
7fd59977 | 1635 | { |
1636 | Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress); | |
1637 | Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress); | |
1638 | ||
1639 | dy = -dy; // Xwindow Y axis is from top to Bottom | |
1640 | ||
1641 | ViewerTest::CurrentView()->Panning( dx, dy ); | |
1642 | ||
1643 | X_ButtonPress = X_Motion; | |
1644 | Y_ButtonPress = Y_Motion; | |
1645 | } | |
1646 | ||
1647 | //============================================================================== | |
4fe56619 | 1648 | //function : VT_ProcessControlButton3Motion |
7fd59977 | 1649 | //purpose : Rotation |
1650 | //============================================================================== | |
4fe56619 | 1651 | void VT_ProcessControlButton3Motion() |
7fd59977 | 1652 | { |
4fe56619 | 1653 | if (Start_Rot) |
1654 | { | |
1655 | ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion); | |
1656 | } | |
7fd59977 | 1657 | } |
1658 | ||
1659 | //============================================================================== | |
4fe56619 | 1660 | //function : VT_ProcessMotion |
1661 | //purpose : | |
7fd59977 | 1662 | //============================================================================== |
4fe56619 | 1663 | void VT_ProcessMotion() |
7fd59977 | 1664 | { |
1665 | //pre-hilights detected objects at mouse position | |
1666 | ||
1667 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1668 | EM->MoveTo(X_Motion, Y_Motion); | |
1669 | } | |
1670 | ||
1671 | ||
1672 | void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix) | |
1673 | { | |
1674 | Xpix = X_Motion;Ypix=Y_Motion; | |
1675 | } | |
1676 | ||
44b8f2d6 | 1677 | //============================================================================== |
1678 | //function : ViewProject: implements VAxo, VTop, VLeft, ... | |
1679 | //purpose : Switches to an axonometric, top, left and other views | |
1680 | //============================================================================== | |
1681 | ||
1682 | static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori) | |
1683 | { | |
4fe56619 | 1684 | if ( ViewerTest::CurrentView().IsNull() ) |
44b8f2d6 | 1685 | { |
1686 | di<<"Call vinit before this command, please"<<"\n"; | |
1687 | return 1; | |
1688 | } | |
1689 | ||
1690 | ViewerTest::CurrentView()->SetProj(ori); | |
1691 | return 0; | |
1692 | } | |
1693 | ||
7fd59977 | 1694 | //============================================================================== |
1695 | //function : VAxo | |
1696 | //purpose : Switch to an Axonometric view | |
1697 | //Draw arg : No args | |
1698 | //============================================================================== | |
1699 | ||
1700 | static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** ) | |
44b8f2d6 | 1701 | { |
1702 | return ViewProject(di, V3d_XposYnegZpos); | |
7fd59977 | 1703 | } |
1704 | ||
1705 | //============================================================================== | |
1706 | //function : VTop | |
1707 | //purpose : Switch to a Top View | |
1708 | //Draw arg : No args | |
1709 | //============================================================================== | |
1710 | ||
1711 | static int VTop(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1712 | { | |
44b8f2d6 | 1713 | return ViewProject(di, V3d_Zpos); |
1714 | } | |
7fd59977 | 1715 | |
44b8f2d6 | 1716 | //============================================================================== |
1717 | //function : VBottom | |
1718 | //purpose : Switch to a Bottom View | |
1719 | //Draw arg : No args | |
1720 | //============================================================================== | |
7fd59977 | 1721 | |
44b8f2d6 | 1722 | static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** ) |
1723 | { | |
1724 | return ViewProject(di, V3d_Zneg); | |
1725 | } | |
7fd59977 | 1726 | |
44b8f2d6 | 1727 | //============================================================================== |
1728 | //function : VLeft | |
1729 | //purpose : Switch to a Left View | |
1730 | //Draw arg : No args | |
1731 | //============================================================================== | |
1732 | ||
1733 | static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1734 | { | |
1735 | return ViewProject(di, V3d_Ypos); | |
1736 | } | |
1737 | ||
1738 | //============================================================================== | |
1739 | //function : VRight | |
1740 | //purpose : Switch to a Right View | |
1741 | //Draw arg : No args | |
1742 | //============================================================================== | |
1743 | ||
1744 | static int VRight(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1745 | { | |
1746 | return ViewProject(di, V3d_Yneg); | |
1747 | } | |
7fd59977 | 1748 | |
44b8f2d6 | 1749 | //============================================================================== |
1750 | //function : VFront | |
1751 | //purpose : Switch to a Front View | |
1752 | //Draw arg : No args | |
1753 | //============================================================================== | |
1754 | ||
1755 | static int VFront(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1756 | { | |
1757 | return ViewProject(di, V3d_Xpos); | |
1758 | } | |
1759 | ||
1760 | //============================================================================== | |
1761 | //function : VBack | |
1762 | //purpose : Switch to a Back View | |
1763 | //Draw arg : No args | |
1764 | //============================================================================== | |
1765 | ||
1766 | static int VBack(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1767 | { | |
1768 | return ViewProject(di, V3d_Xneg); | |
7fd59977 | 1769 | } |
1770 | ||
1771 | //============================================================================== | |
1772 | //function : VHelp | |
1773 | //purpose : Dsiplay help on viewer Keyboead and mouse commands | |
1774 | //Draw arg : No args | |
1775 | //============================================================================== | |
1776 | ||
1777 | static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1778 | { | |
1779 | ||
1780 | di << "Q : Quit the application" << "\n"; | |
1781 | ||
1782 | di << "========================="<<"\n"; | |
1783 | di << "F : FitAll" << "\n"; | |
1784 | di << "T : TopView" << "\n"; | |
41811896 | 1785 | di << "B : BottomView" << "\n"; |
1786 | di << "R : RightView" << "\n"; | |
1787 | di << "L : LeftView" << "\n"; | |
7fd59977 | 1788 | di << "A : AxonometricView" << "\n"; |
41811896 | 1789 | di << "D : ResetView" << "\n"; |
7fd59977 | 1790 | |
1791 | di << "========================="<<"\n"; | |
1792 | di << "S : Shading" << "\n"; | |
1793 | di << "W : Wireframe" << "\n"; | |
1794 | di << "H : HidelLineRemoval" << "\n"; | |
41811896 | 1795 | di << "U : Unset display mode" << "\n"; |
b514beda | 1796 | di << "Delete : Remove selection from viewer" << "\n"; |
7fd59977 | 1797 | |
1798 | di << "========================="<<"\n"; | |
1799 | di << "Selection mode "<<"\n"; | |
1800 | di << "0 : Shape" <<"\n"; | |
1801 | di << "1 : Vertex" <<"\n"; | |
1802 | di << "2 : Edge" <<"\n"; | |
1803 | di << "3 : Wire" <<"\n"; | |
1804 | di << "4 : Face" <<"\n"; | |
1805 | di << "5 : Shell" <<"\n"; | |
1806 | di << "6 : Solid" <<"\n"; | |
1807 | di << "7 : Compound" <<"\n"; | |
1808 | ||
41811896 | 1809 | di << "========================="<<"\n"; |
1810 | di << "Z : Switch Z clipping On/Off" << "\n"; | |
1811 | di << ", : Hilight next detected" << "\n"; | |
1812 | di << ". : Hilight previous detected" << "\n"; | |
7fd59977 | 1813 | |
1814 | return 0; | |
1815 | } | |
1816 | ||
7fd59977 | 1817 | #ifdef WNT |
1818 | ||
1819 | static Standard_Boolean Ppick = 0; | |
1820 | static Standard_Integer Pargc = 0; | |
1821 | static const char** Pargv = NULL; | |
1822 | ||
1823 | ||
1824 | static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd, | |
1825 | UINT Msg, | |
1826 | WPARAM wParam, | |
1827 | LPARAM lParam ) | |
1828 | { | |
18d715bd | 1829 | if (!ViewerTest_myViews.IsEmpty()) { |
7fd59977 | 1830 | |
1831 | WPARAM fwKeys = wParam; | |
1832 | ||
1833 | switch( Msg ) { | |
18d715bd | 1834 | case WM_CLOSE: |
1835 | { | |
1836 | // Delete view from map of views | |
1837 | ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd)); | |
1838 | return 0; | |
1839 | } | |
1840 | break; | |
1841 | case WM_ACTIVATE: | |
1842 | if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE | |
1843 | || ViewerTest::CurrentView().IsNull()) | |
1844 | { | |
1845 | // Activate inactive window | |
1846 | if(GetWindowHandle(VT_GetWindow()) != hwnd) | |
1847 | { | |
1848 | ActivateView (FindViewIdByWindowHandle(hwnd)); | |
1849 | } | |
1850 | } | |
1851 | break; | |
7fd59977 | 1852 | case WM_LBUTTONUP: |
1853 | IsDragged = Standard_False; | |
1854 | if( !DragFirst ) | |
1855 | { | |
1856 | HDC hdc = GetDC( hwnd ); | |
7fd59977 | 1857 | SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) ); |
1858 | SetROP2( hdc, R2_NOT ); | |
4fe56619 | 1859 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
7fd59977 | 1860 | ReleaseDC( hwnd, hdc ); |
1861 | ||
1862 | const Handle(ViewerTest_EventManager) EM = | |
1863 | ViewerTest::CurrentEventManager(); | |
1864 | if ( fwKeys & MK_SHIFT ) | |
4fe56619 | 1865 | EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), |
1866 | max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion )); | |
7fd59977 | 1867 | else |
4fe56619 | 1868 | EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), |
1869 | max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion )); | |
7fd59977 | 1870 | } |
1871 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1872 | ||
1873 | case WM_LBUTTONDOWN: | |
1874 | if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) ) | |
1875 | { | |
1876 | IsDragged = Standard_True; | |
1877 | DragFirst = Standard_True; | |
4fe56619 | 1878 | X_ButtonPress = LOWORD(lParam); |
1879 | Y_ButtonPress = HIWORD(lParam); | |
7fd59977 | 1880 | } |
1881 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1882 | ||
1883 | break; | |
1884 | ||
1885 | case WM_MOUSEMOVE: | |
1886 | if( IsDragged ) | |
1887 | { | |
1888 | HDC hdc = GetDC( hwnd ); | |
1889 | ||
1890 | HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) ); | |
1891 | SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) ); | |
1892 | SetROP2( hdc, R2_NOT ); | |
1893 | ||
1894 | if( !DragFirst ) | |
4fe56619 | 1895 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
7fd59977 | 1896 | |
1897 | DragFirst = Standard_False; | |
4fe56619 | 1898 | X_Motion = LOWORD(lParam); |
1899 | Y_Motion = HIWORD(lParam); | |
7fd59977 | 1900 | |
4fe56619 | 1901 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
7fd59977 | 1902 | |
1903 | SelectObject( hdc, anObj ); | |
1904 | ||
1905 | ReleaseDC( hwnd, hdc ); | |
1906 | } | |
1907 | else | |
1908 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1909 | break; | |
1910 | ||
1911 | default: | |
1912 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1913 | } | |
1914 | return 0; | |
1915 | } | |
1916 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1917 | } | |
1918 | ||
1919 | ||
1920 | static LRESULT WINAPI ViewerWindowProc( HWND hwnd, | |
1921 | UINT Msg, | |
1922 | WPARAM wParam, | |
1923 | LPARAM lParam ) | |
1924 | { | |
7fd59977 | 1925 | static int Up = 1; |
1926 | ||
1927 | if ( !ViewerTest::CurrentView().IsNull() ) { | |
1928 | PAINTSTRUCT ps; | |
1929 | ||
1930 | switch( Msg ) { | |
7fd59977 | 1931 | case WM_PAINT: |
7fd59977 | 1932 | BeginPaint(hwnd, &ps); |
1933 | EndPaint(hwnd, &ps); | |
4fe56619 | 1934 | VT_ProcessExpose(); |
7fd59977 | 1935 | break; |
1936 | ||
1937 | case WM_SIZE: | |
4fe56619 | 1938 | VT_ProcessConfigure(); |
7fd59977 | 1939 | break; |
1940 | ||
1941 | case WM_KEYDOWN: | |
4fe56619 | 1942 | if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL)) |
1943 | { | |
7fd59977 | 1944 | char c[2]; |
1945 | c[0] = (char) wParam; | |
1946 | c[1] = '\0'; | |
b514beda | 1947 | if (wParam == VK_DELETE) |
1948 | { | |
1949 | c[0] = THE_KEY_DELETE; | |
1950 | } | |
4fe56619 | 1951 | VT_ProcessKeyPress (c); |
7fd59977 | 1952 | } |
1953 | break; | |
1954 | ||
1955 | case WM_LBUTTONUP: | |
1956 | case WM_MBUTTONUP: | |
1957 | case WM_RBUTTONUP: | |
7fd59977 | 1958 | Up = 1; |
4fe56619 | 1959 | VT_ProcessButton3Release(); |
7fd59977 | 1960 | break; |
1961 | ||
1962 | case WM_LBUTTONDOWN: | |
1963 | case WM_MBUTTONDOWN: | |
1964 | case WM_RBUTTONDOWN: | |
1965 | { | |
7fd59977 | 1966 | WPARAM fwKeys = wParam; |
1967 | ||
1968 | Up = 0; | |
1969 | ||
1970 | X_ButtonPress = LOWORD(lParam); | |
1971 | Y_ButtonPress = HIWORD(lParam); | |
1972 | ||
4fe56619 | 1973 | if (Msg == WM_LBUTTONDOWN) |
1974 | { | |
1975 | if (fwKeys & MK_CONTROL) | |
1976 | { | |
1977 | Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT)); | |
1978 | } | |
1979 | else | |
1980 | { | |
1981 | VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT)); | |
1982 | } | |
7fd59977 | 1983 | } |
4fe56619 | 1984 | else if (Msg == WM_RBUTTONDOWN) |
1985 | { | |
7fd59977 | 1986 | // Start rotation |
4fe56619 | 1987 | VT_ProcessButton3Press(); |
7fd59977 | 1988 | } |
1989 | } | |
1990 | break; | |
1991 | ||
1992 | case WM_MOUSEMOVE: | |
1993 | { | |
1994 | //cout << "\t WM_MOUSEMOVE" << endl; | |
1995 | WPARAM fwKeys = wParam; | |
1996 | X_Motion = LOWORD(lParam); | |
1997 | Y_Motion = HIWORD(lParam); | |
1998 | ||
1999 | if ( Up && | |
2000 | fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) { | |
2001 | Up = 0; | |
2002 | X_ButtonPress = LOWORD(lParam); | |
2003 | Y_ButtonPress = HIWORD(lParam); | |
2004 | ||
2005 | if ( fwKeys & MK_RBUTTON ) { | |
2006 | // Start rotation | |
4fe56619 | 2007 | VT_ProcessButton3Press(); |
7fd59977 | 2008 | } |
2009 | } | |
2010 | ||
2011 | if ( fwKeys & MK_CONTROL ) { | |
2012 | if ( fwKeys & MK_LBUTTON ) { | |
2013 | ProcessControlButton1Motion(); | |
2014 | } | |
2015 | else if ( fwKeys & MK_MBUTTON || | |
2016 | ((fwKeys&MK_LBUTTON) && | |
2017 | (fwKeys&MK_RBUTTON) ) ){ | |
4fe56619 | 2018 | VT_ProcessControlButton2Motion(); |
7fd59977 | 2019 | } |
2020 | else if ( fwKeys & MK_RBUTTON ) { | |
4fe56619 | 2021 | VT_ProcessControlButton3Motion(); |
7fd59977 | 2022 | } |
2023 | } | |
2024 | #ifdef BUG | |
2025 | else if ( fwKeys & MK_SHIFT ) { | |
2026 | if ( fwKeys & MK_MBUTTON || | |
2027 | ((fwKeys&MK_LBUTTON) && | |
2028 | (fwKeys&MK_RBUTTON) ) ) { | |
2029 | cout << "ProcessZClipMotion()" << endl; | |
2030 | ProcessZClipMotion(); | |
2031 | } | |
2032 | } | |
2033 | #endif | |
08398024 | 2034 | else if (GetWindowHandle (VT_GetWindow()) == hwnd) |
2035 | { | |
4fe56619 | 2036 | if ((fwKeys & MK_MBUTTON |
2037 | || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON)))) | |
2038 | { | |
7fd59977 | 2039 | ProcessZClipMotion(); |
2040 | } | |
4fe56619 | 2041 | else |
2042 | { | |
2043 | VT_ProcessMotion(); | |
7fd59977 | 2044 | } |
08398024 | 2045 | } |
7fd59977 | 2046 | } |
2047 | break; | |
2048 | ||
2049 | default: | |
2050 | return( DefWindowProc( hwnd, Msg, wParam, lParam )); | |
2051 | } | |
2052 | return 0L; | |
2053 | } | |
2054 | ||
2055 | return DefWindowProc( hwnd, Msg, wParam, lParam ); | |
2056 | } | |
2057 | ||
2058 | ||
2059 | ||
2060 | ||
2061 | //============================================================================== | |
2062 | //function : ViewerMainLoop | |
2063 | //purpose : Get a Event on the view and dispatch it | |
2064 | //============================================================================== | |
2065 | ||
2066 | ||
8263fcd3 | 2067 | int ViewerMainLoop(Standard_Integer argc, const char** argv) |
7fd59977 | 2068 | { |
7fd59977 | 2069 | Ppick = (argc > 0)? 1 : 0; |
2070 | Pargc = argc; | |
2071 | Pargv = argv; | |
2072 | ||
2073 | if ( Ppick ) { | |
2074 | MSG msg; | |
2075 | msg.wParam = 1; | |
2076 | ||
2077 | cout << "Start picking" << endl; | |
2078 | ||
7fd59977 | 2079 | while ( Ppick == 1 ) { |
4fe56619 | 2080 | // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0 |
7fd59977 | 2081 | if (GetMessage(&msg, NULL, 0, 0) ) { |
2082 | TranslateMessage(&msg); | |
2083 | DispatchMessage(&msg); | |
2084 | } | |
2085 | } | |
2086 | ||
2087 | cout << "Picking done" << endl; | |
2088 | } | |
2089 | ||
2090 | return Ppick; | |
2091 | } | |
2092 | ||
4fe56619 | 2093 | #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 2094 | |
2095 | int min( int a, int b ) | |
2096 | { | |
2097 | if( a<b ) | |
2098 | return a; | |
2099 | else | |
2100 | return b; | |
2101 | } | |
2102 | ||
2103 | int max( int a, int b ) | |
2104 | { | |
2105 | if( a>b ) | |
2106 | return a; | |
2107 | else | |
2108 | return b; | |
2109 | } | |
2110 | ||
2111 | int ViewerMainLoop(Standard_Integer argc, const char** argv) | |
2112 | ||
4269bd1b | 2113 | { |
18d715bd | 2114 | static XEvent aReport; |
2115 | Standard_Boolean pick = argc > 0; | |
2116 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2117 | XNextEvent (aDisplay, &aReport); | |
7fd59977 | 2118 | |
18d715bd | 2119 | // Handle event for the chosen display connection |
2120 | switch (aReport.type) { | |
2121 | case ClientMessage: | |
2122 | { | |
2123 | if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW)) | |
2124 | { | |
2125 | // Close the window | |
2126 | ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window)); | |
2127 | } | |
2128 | } | |
2129 | return 0; | |
2130 | case FocusIn: | |
2131 | { | |
2132 | // Activate inactive view | |
2133 | Window aWindow = GetWindowHandle(VT_GetWindow()); | |
2134 | if(aWindow != aReport.xfocus.window) | |
2135 | { | |
2136 | ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window)); | |
2137 | } | |
2138 | } | |
2139 | break; | |
7fd59977 | 2140 | case Expose: |
2141 | { | |
4fe56619 | 2142 | VT_ProcessExpose(); |
7fd59977 | 2143 | } |
2144 | break; | |
2145 | case ConfigureNotify: | |
2146 | { | |
4fe56619 | 2147 | VT_ProcessConfigure(); |
7fd59977 | 2148 | } |
2149 | break; | |
2150 | case KeyPress: | |
2151 | { | |
2152 | ||
2153 | KeySym ks_ret ; | |
2154 | char buf_ret[11] ; | |
2155 | int ret_len ; | |
2156 | XComposeStatus status_in_out; | |
2157 | ||
18d715bd | 2158 | ret_len = XLookupString( ( XKeyEvent *)&aReport , |
7fd59977 | 2159 | (char *) buf_ret , 10 , |
2160 | &ks_ret , &status_in_out ) ; | |
2161 | ||
2162 | ||
2163 | buf_ret[ret_len] = '\0' ; | |
2164 | ||
4fe56619 | 2165 | if (ret_len) |
2166 | { | |
2167 | VT_ProcessKeyPress (buf_ret); | |
7fd59977 | 2168 | } |
2169 | } | |
2170 | break; | |
2171 | case ButtonPress: | |
7fd59977 | 2172 | { |
18d715bd | 2173 | X_ButtonPress = aReport.xbutton.x; |
2174 | Y_ButtonPress = aReport.xbutton.y; | |
7fd59977 | 2175 | |
18d715bd | 2176 | if (aReport.xbutton.button == Button1) |
4fe56619 | 2177 | { |
18d715bd | 2178 | if (aReport.xbutton.state & ControlMask) |
4fe56619 | 2179 | { |
18d715bd | 2180 | pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask)); |
4fe56619 | 2181 | } |
7fd59977 | 2182 | else |
2183 | { | |
2184 | IsDragged = Standard_True; | |
7fd59977 | 2185 | DragFirst = Standard_True; |
2186 | } | |
4fe56619 | 2187 | } |
18d715bd | 2188 | else if (aReport.xbutton.button == Button3) |
4fe56619 | 2189 | { |
7fd59977 | 2190 | // Start rotation |
4fe56619 | 2191 | VT_ProcessButton3Press(); |
2192 | } | |
7fd59977 | 2193 | } |
2194 | break; | |
2195 | case ButtonRelease: | |
2196 | { | |
7fd59977 | 2197 | if( IsDragged ) |
2198 | { | |
2199 | if( !DragFirst ) | |
2200 | { | |
2201 | Aspect_Handle aWindow = VT_GetWindow()->XWindow(); | |
18d715bd | 2202 | GC gc = XCreateGC( aDisplay, aWindow, 0, 0 ); |
2203 | XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) ); | |
7fd59977 | 2204 | } |
2205 | ||
2206 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
2207 | if( aContext.IsNull() ) | |
2208 | { | |
2209 | cout << "The context is null. Please use vinit before createmesh" << endl; | |
2210 | return 0; | |
2211 | } | |
2212 | ||
18d715bd | 2213 | Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask ); |
2214 | if( aReport.xbutton.button==1 ) | |
7fd59977 | 2215 | if( DragFirst ) |
2216 | if( ShiftPressed ) | |
2217 | { | |
2218 | aContext->ShiftSelect(); | |
7fd59977 | 2219 | } |
2220 | else | |
2221 | { | |
2222 | aContext->Select(); | |
7fd59977 | 2223 | } |
2224 | else | |
2225 | if( ShiftPressed ) | |
2226 | { | |
4fe56619 | 2227 | aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), |
2228 | max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), | |
7fd59977 | 2229 | ViewerTest::CurrentView()); |
7fd59977 | 2230 | } |
2231 | else | |
2232 | { | |
4fe56619 | 2233 | aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), |
2234 | max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), | |
7fd59977 | 2235 | ViewerTest::CurrentView() ); |
7fd59977 | 2236 | } |
2237 | else | |
4fe56619 | 2238 | VT_ProcessButton3Release(); |
7fd59977 | 2239 | |
2240 | IsDragged = Standard_False; | |
2241 | } | |
2242 | else | |
4fe56619 | 2243 | VT_ProcessButton3Release(); |
7fd59977 | 2244 | } |
2245 | break; | |
2246 | case MotionNotify: | |
2247 | { | |
08398024 | 2248 | if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window) |
2249 | { | |
2250 | break; | |
2251 | } | |
7fd59977 | 2252 | if( IsDragged ) |
2253 | { | |
2254 | Aspect_Handle aWindow = VT_GetWindow()->XWindow(); | |
18d715bd | 2255 | GC gc = XCreateGC( aDisplay, aWindow, 0, 0 ); |
2256 | XSetFunction( aDisplay, gc, GXinvert ); | |
7fd59977 | 2257 | |
2258 | if( !DragFirst ) | |
18d715bd | 2259 | XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) ); |
7fd59977 | 2260 | |
18d715bd | 2261 | X_Motion = aReport.xmotion.x; |
2262 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2263 | DragFirst = Standard_False; |
2264 | ||
18d715bd | 2265 | XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) ); |
7fd59977 | 2266 | } |
2267 | else | |
2268 | { | |
18d715bd | 2269 | X_Motion = aReport.xmotion.x; |
2270 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2271 | |
18d715bd | 2272 | // remove all the ButtonMotionMaskr |
2273 | while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ; | |
7fd59977 | 2274 | |
18d715bd | 2275 | if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) { |
7fd59977 | 2276 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { |
2277 | ||
2278 | Quantity_Length VDX, VDY; | |
2279 | ||
2280 | ViewerTest::CurrentView()->Size(VDX,VDY); | |
2281 | Standard_Real VDZ =0 ; | |
2282 | VDZ = ViewerTest::CurrentView()->ZSize(); | |
2283 | ||
7fd59977 | 2284 | printf("%f,%f,%f\n", VDX, VDY, VDZ); |
2285 | ||
2286 | Quantity_Length dx = 0 ; | |
2287 | dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress); | |
2288 | ||
2289 | cout << dx << endl; | |
2290 | ||
2291 | dx = dx / VDX * VDZ; | |
2292 | ||
2293 | cout << dx << endl; | |
2294 | ||
7fd59977 | 2295 | ViewerTest::CurrentView()->Redraw(); |
2296 | } | |
2297 | } | |
2298 | ||
18d715bd | 2299 | if ( aReport.xmotion.state & ControlMask ) { |
2300 | if ( aReport.xmotion.state & Button1Mask ) { | |
7fd59977 | 2301 | ProcessControlButton1Motion(); |
2302 | } | |
18d715bd | 2303 | else if ( aReport.xmotion.state & Button2Mask ) { |
4fe56619 | 2304 | VT_ProcessControlButton2Motion(); |
7fd59977 | 2305 | } |
18d715bd | 2306 | else if ( aReport.xmotion.state & Button3Mask ) { |
4fe56619 | 2307 | VT_ProcessControlButton3Motion(); |
7fd59977 | 2308 | } |
2309 | } | |
4fe56619 | 2310 | else |
2311 | { | |
2312 | VT_ProcessMotion(); | |
7fd59977 | 2313 | } |
2314 | } | |
2315 | } | |
2316 | break; | |
2317 | } | |
7fd59977 | 2318 | return pick; |
2319 | } | |
2320 | ||
2321 | //============================================================================== | |
2322 | //function : VProcessEvents | |
2323 | //purpose : call by Tk_CreateFileHandler() to be able to manage the | |
2324 | // event in the Viewer window | |
2325 | //============================================================================== | |
2326 | ||
2327 | static void VProcessEvents(ClientData,int) | |
2328 | { | |
18d715bd | 2329 | NCollection_Vector<int> anEventNumbers; |
2330 | // Get number of messages from every display | |
2331 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2332 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next()) | |
2333 | { | |
2334 | anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay())); | |
4269bd1b | 2335 | } |
18d715bd | 2336 | // Handle events for every display |
2337 | int anEventIter = 0; | |
2338 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2339 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++) | |
2340 | { | |
4269bd1b | 2341 | for (int i = 0; i < anEventNumbers.Value(anEventIter) && |
18d715bd | 2342 | XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i) |
2343 | { | |
2344 | SetDisplayConnection (anIter.Key2()->GetDisplayConnection()); | |
2345 | int anEventResult = ViewerMainLoop( 0, NULL); | |
2346 | // If window is closed or context was not found finish current event processing loop | |
2347 | if (!anEventResult) | |
2348 | return; | |
2349 | } | |
7fd59977 | 2350 | } |
4269bd1b | 2351 | |
18d715bd | 2352 | SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection()); |
4269bd1b | 2353 | |
7fd59977 | 2354 | } |
2355 | #endif | |
2356 | ||
2357 | //============================================================================== | |
2358 | //function : OSWindowSetup | |
2359 | //purpose : Setup for the X11 window to be able to cath the event | |
2360 | //============================================================================== | |
2361 | ||
2362 | ||
2363 | static void OSWindowSetup() | |
2364 | { | |
4fe56619 | 2365 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
7fd59977 | 2366 | // X11 |
2367 | ||
2368 | Window window = VT_GetWindow()->XWindow(); | |
18d715bd | 2369 | SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
2370 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2371 | XSynchronize(aDisplay, 1); | |
7fd59977 | 2372 | |
2373 | // X11 : For keyboard on SUN | |
2374 | XWMHints wmhints; | |
2375 | wmhints.flags = InputHint; | |
2376 | wmhints.input = 1; | |
2377 | ||
18d715bd | 2378 | XSetWMHints( aDisplay, window, &wmhints); |
7fd59977 | 2379 | |
18d715bd | 2380 | XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | |
7fd59977 | 2381 | ButtonPressMask | ButtonReleaseMask | |
2382 | StructureNotifyMask | | |
2383 | PointerMotionMask | | |
2384 | Button1MotionMask | Button2MotionMask | | |
18d715bd | 2385 | Button3MotionMask | FocusChangeMask |
7fd59977 | 2386 | ); |
18d715bd | 2387 | Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW); |
2388 | XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1); | |
7fd59977 | 2389 | |
18d715bd | 2390 | XSynchronize(aDisplay, 0); |
7fd59977 | 2391 | |
2392 | #else | |
2393 | // WNT | |
2394 | #endif | |
2395 | ||
2396 | } | |
2397 | ||
2398 | ||
2399 | //============================================================================== | |
2400 | //function : VFit | |
2401 | ||
2402 | //purpose : Fitall, no DRAW arguments | |
2403 | //Draw arg : No args | |
2404 | //============================================================================== | |
2405 | ||
2406 | static int VFit(Draw_Interpretor& , Standard_Integer , const char** ) | |
2407 | { | |
2408 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
2409 | Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView); | |
2410 | if (V.IsNull() == Standard_False) { | |
2411 | V->FitAll3d(); | |
2412 | } else if (aView.IsNull() == Standard_False) { | |
2413 | aView->FitAll(); | |
2414 | } | |
2415 | return 0; | |
2416 | } | |
2417 | ||
2418 | //============================================================================== | |
2419 | //function : VZFit | |
2420 | //purpose : ZFitall, no DRAW arguments | |
2421 | //Draw arg : No args | |
2422 | //============================================================================== | |
2423 | ||
2424 | static int VZFit(Draw_Interpretor& , Standard_Integer , const char** ) | |
2425 | { | |
2426 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
2427 | if ( !V.IsNull() ) V->ZFitAll(); return 0; } | |
2428 | ||
2429 | ||
2430 | static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** ) | |
2431 | { | |
2432 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
2433 | if ( !V.IsNull() ) V->Redraw(); return 0; | |
2434 | } | |
2435 | ||
2436 | ||
2437 | //============================================================================== | |
2438 | //function : VClear | |
2439 | //purpose : Remove all the object from the viewer | |
2440 | //Draw arg : No args | |
2441 | //============================================================================== | |
2442 | ||
2443 | static int VClear(Draw_Interpretor& , Standard_Integer , const char** ) | |
2444 | { | |
2445 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
2446 | if(!V.IsNull()) | |
2447 | ViewerTest::Clear(); | |
2448 | return 0; | |
2449 | } | |
2450 | ||
2451 | //============================================================================== | |
2452 | //function : VPick | |
2453 | //purpose : | |
2454 | //============================================================================== | |
2455 | ||
2456 | static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2457 | { if (ViewerTest::CurrentView().IsNull() ) return 1; | |
2458 | ||
2459 | if ( argc < 4 ) { | |
2460 | di << argv[0] << "Invalid number of arguments" << "\n"; | |
2461 | return 1; | |
2462 | } | |
2463 | ||
2464 | while (ViewerMainLoop( argc, argv)) { | |
2465 | } | |
2466 | ||
2467 | return 0; | |
2468 | } | |
2469 | ||
7fd59977 | 2470 | //============================================================================== |
2471 | //function : InitViewerTest | |
2472 | //purpose : initialisation de toutes les variables static de ViewerTest (dp) | |
2473 | //============================================================================== | |
2474 | ||
18d715bd | 2475 | void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext) |
7fd59977 | 2476 | { |
18d715bd | 2477 | Handle(V3d_Viewer) aViewer = theContext->CurrentViewer(); |
2478 | ViewerTest::SetAISContext(theContext); | |
2479 | aViewer->InitActiveViews(); | |
2480 | Handle(V3d_View) aView = aViewer->ActiveView(); | |
2481 | if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView); | |
7fd59977 | 2482 | ViewerTest::ResetEventManager(); |
18d715bd | 2483 | Handle(Aspect_Window) aWindow = aView->Window(); |
4fe56619 | 2484 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
7fd59977 | 2485 | // X11 |
18d715bd | 2486 | VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow); |
7fd59977 | 2487 | OSWindowSetup(); |
18d715bd | 2488 | static int aFirst = 1; |
2489 | if ( aFirst ) { | |
7fd59977 | 2490 | #if TCL_MAJOR_VERSION < 8 |
18d715bd | 2491 | Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 2492 | TK_READABLE, VProcessEvents, (ClientData) 0); |
2493 | #else | |
18d715bd | 2494 | Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 2495 | TK_READABLE, VProcessEvents, (ClientData) 0); |
2496 | #endif | |
18d715bd | 2497 | aFirst = 0; |
7fd59977 | 2498 | } |
2499 | #endif | |
2500 | } | |
2501 | ||
7fd59977 | 2502 | //============================================================================== |
2503 | //function : VSetBg | |
2504 | //purpose : Load image as background | |
2505 | //============================================================================== | |
2506 | ||
2507 | static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2508 | { | |
2509 | if (argc < 2 || argc > 3) | |
2510 | { | |
2511 | di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n"; | |
f8b2ed36 | 2512 | di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n"; |
7fd59977 | 2513 | return 1; |
2514 | } | |
2515 | ||
2516 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2517 | if(AISContext.IsNull()) | |
2518 | { | |
2519 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2520 | return 1; | |
2521 | } | |
2522 | ||
2523 | Aspect_FillMethod aFillType = Aspect_FM_CENTERED; | |
2524 | if (argc == 3) | |
2525 | { | |
2526 | const char* szType = argv[2]; | |
2527 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
2528 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
2529 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
2530 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
2531 | else | |
2532 | { | |
2533 | di << "Wrong fill type : " << szType << "\n"; | |
2534 | di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
2535 | return 1; | |
2536 | } | |
2537 | } | |
2538 | ||
2539 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2540 | V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True); | |
2541 | ||
2542 | return 0; | |
2543 | } | |
2544 | ||
f8b2ed36 | 2545 | //============================================================================== |
2546 | //function : VSetBgMode | |
2547 | //purpose : Change background image fill type | |
2548 | //============================================================================== | |
2549 | ||
2550 | static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2551 | { | |
2552 | if (argc != 2) | |
2553 | { | |
2554 | di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n"; | |
2555 | di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
2556 | return 1; | |
2557 | } | |
2558 | ||
2559 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2560 | if(AISContext.IsNull()) | |
2561 | { | |
2562 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2563 | return 1; | |
2564 | } | |
1d47d8d0 | 2565 | Aspect_FillMethod aFillType = Aspect_FM_NONE; |
2566 | const char* szType = argv[1]; | |
2567 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
2568 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
2569 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
2570 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
2571 | else | |
f8b2ed36 | 2572 | { |
1d47d8d0 | 2573 | di << "Wrong fill type : " << szType << "\n"; |
2574 | di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
2575 | return 1; | |
f8b2ed36 | 2576 | } |
f8b2ed36 | 2577 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
2578 | V3dView->SetBgImageStyle(aFillType, Standard_True); | |
f8b2ed36 | 2579 | return 0; |
2580 | } | |
2581 | ||
7fd59977 | 2582 | //============================================================================== |
2583 | //function : VSetGradientBg | |
2584 | //purpose : Mount gradient background | |
2585 | //============================================================================== | |
2586 | static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2587 | { | |
2588 | if (argc != 8 ) | |
2589 | { | |
2590 | di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n"; | |
2591 | di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n"; | |
2592 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2593 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2594 | return 1; | |
2595 | } | |
2596 | ||
2597 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2598 | if(AISContext.IsNull()) | |
2599 | { | |
2600 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2601 | return 1; | |
2602 | } | |
2603 | if (argc == 8) | |
2604 | { | |
2605 | ||
91322f44 | 2606 | Standard_Real R1 = Draw::Atof(argv[1])/255.; |
2607 | Standard_Real G1 = Draw::Atof(argv[2])/255.; | |
2608 | Standard_Real B1 = Draw::Atof(argv[3])/255.; | |
7fd59977 | 2609 | Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB); |
2610 | ||
91322f44 | 2611 | Standard_Real R2 = Draw::Atof(argv[4])/255.; |
2612 | Standard_Real G2 = Draw::Atof(argv[5])/255.; | |
2613 | Standard_Real B2 = Draw::Atof(argv[6])/255.; | |
7fd59977 | 2614 | |
2615 | Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB); | |
91322f44 | 2616 | int aType = Draw::Atoi(argv[7]); |
7fd59977 | 2617 | if( aType < 0 || aType > 8 ) |
2618 | { | |
2619 | di << "Wrong fill type " << "\n"; | |
2620 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2621 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2622 | return 1; | |
2623 | } | |
2624 | ||
2625 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
2626 | ||
2627 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2628 | V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1); | |
2629 | } | |
2630 | ||
2631 | return 0; | |
2632 | } | |
2633 | ||
f8b2ed36 | 2634 | //============================================================================== |
2635 | //function : VSetGradientBgMode | |
2636 | //purpose : Change gradient background fill style | |
2637 | //============================================================================== | |
2638 | static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2639 | { | |
2640 | if (argc != 2 ) | |
2641 | { | |
2642 | di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n"; | |
2643 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2644 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2645 | return 1; | |
2646 | } | |
2647 | ||
2648 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2649 | if(AISContext.IsNull()) | |
2650 | { | |
2651 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2652 | return 1; | |
2653 | } | |
2654 | if (argc == 2) | |
2655 | { | |
91322f44 | 2656 | int aType = Draw::Atoi(argv[1]); |
f8b2ed36 | 2657 | if( aType < 0 || aType > 8 ) |
2658 | { | |
2659 | di << "Wrong fill type " << "\n"; | |
2660 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2661 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2662 | return 1; | |
2663 | } | |
2664 | ||
2665 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
2666 | ||
2667 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2668 | V3dView->SetBgGradientStyle( aMethod, 1 ); | |
2669 | } | |
2670 | ||
2671 | return 0; | |
2672 | } | |
2673 | ||
2674 | //============================================================================== | |
2675 | //function : VSetColorBg | |
2676 | //purpose : Set color background | |
2677 | //============================================================================== | |
2678 | static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2679 | { | |
2680 | if (argc != 4 ) | |
2681 | { | |
2682 | di << "Usage : " << argv[0] << " R G B : Set color background" << "\n"; | |
2683 | di << "R,G,B = [0..255]" << "\n"; | |
2684 | return 1; | |
2685 | } | |
2686 | ||
2687 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2688 | if(AISContext.IsNull()) | |
2689 | { | |
2690 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2691 | return 1; | |
2692 | } | |
2693 | if (argc == 4) | |
2694 | { | |
2695 | ||
91322f44 | 2696 | Standard_Real R = Draw::Atof(argv[1])/255.; |
2697 | Standard_Real G = Draw::Atof(argv[2])/255.; | |
2698 | Standard_Real B = Draw::Atof(argv[3])/255.; | |
f8b2ed36 | 2699 | Quantity_Color aColor(R,G,B,Quantity_TOC_RGB); |
2700 | ||
2701 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2702 | V3dView->SetBackgroundColor( aColor ); | |
2703 | V3dView->Update(); | |
2704 | } | |
2705 | ||
2706 | return 0; | |
2707 | } | |
2708 | ||
7fd59977 | 2709 | //============================================================================== |
2710 | //function : VScale | |
2711 | //purpose : View Scaling | |
2712 | //============================================================================== | |
2713 | ||
2714 | static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2715 | { | |
2716 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2717 | if ( V3dView.IsNull() ) return 1; | |
2718 | ||
2719 | if ( argc != 4 ) { | |
2720 | di << argv[0] << "Invalid number of arguments" << "\n"; | |
2721 | return 1; | |
2722 | } | |
91322f44 | 2723 | V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) ); |
7fd59977 | 2724 | return 0; |
2725 | } | |
2726 | //============================================================================== | |
2727 | //function : VTestZBuffTrihedron | |
7c8a8fcc | 2728 | //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron |
7fd59977 | 2729 | //============================================================================== |
2730 | ||
2731 | static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2732 | { | |
2733 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2734 | if ( V3dView.IsNull() ) return 1; | |
2735 | ||
7fd59977 | 2736 | V3dView->ZBufferTriedronSetup(); |
7c8a8fcc | 2737 | |
2738 | if ( argc == 1 ) { | |
2739 | // Set up default trihedron parameters | |
2740 | V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER ); | |
2741 | } else | |
2742 | if ( argc == 7 ) | |
2743 | { | |
2744 | Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER; | |
2745 | const char* aPosType = argv[1]; | |
2746 | ||
2747 | if ( strcmp(aPosType, "center") == 0 ) | |
2748 | { | |
2749 | aPosition = Aspect_TOTP_CENTER; | |
2750 | } else | |
2751 | if (strcmp(aPosType, "left_lower") == 0) | |
2752 | { | |
2753 | aPosition = Aspect_TOTP_LEFT_LOWER; | |
2754 | } else | |
2755 | if (strcmp(aPosType, "left_upper") == 0) | |
2756 | { | |
2757 | aPosition = Aspect_TOTP_LEFT_UPPER; | |
2758 | } else | |
2759 | if (strcmp(aPosType, "right_lower") == 0) | |
2760 | { | |
2761 | aPosition = Aspect_TOTP_RIGHT_LOWER; | |
2762 | } else | |
2763 | if (strcmp(aPosType, "right_upper") == 0) | |
2764 | { | |
2765 | aPosition = Aspect_TOTP_RIGHT_UPPER; | |
2766 | } else | |
2767 | { | |
2768 | di << argv[1] << " Invalid type of alignment" << "\n"; | |
2769 | di << "Must be one of [ center, left_lower," << "\n"; | |
2770 | di << "left_upper, right_lower, right_upper ]" << "\n"; | |
2771 | return 1; | |
2772 | } | |
2773 | ||
91322f44 | 2774 | Standard_Real R = Draw::Atof(argv[2])/255.; |
2775 | Standard_Real G = Draw::Atof(argv[3])/255.; | |
2776 | Standard_Real B = Draw::Atof(argv[4])/255.; | |
7c8a8fcc | 2777 | Quantity_Color aColor(R, G, B, Quantity_TOC_RGB); |
2778 | ||
91322f44 | 2779 | Standard_Real aScale = Draw::Atof(argv[5]); |
7c8a8fcc | 2780 | |
2781 | if( aScale <= 0.0 ) | |
2782 | { | |
2783 | di << argv[5] << " Invalid value. Must be > 0" << "\n"; | |
2784 | return 1; | |
2785 | } | |
2786 | ||
2787 | V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER; | |
2788 | const char* aPresType = argv[6]; | |
2789 | ||
2790 | if ( strcmp(aPresType, "wireframe") == 0 ) | |
2791 | { | |
2792 | aPresentation = V3d_WIREFRAME; | |
2793 | } else | |
2794 | if (strcmp(aPresType, "zbuffer") == 0) | |
2795 | { | |
2796 | aPresentation = V3d_ZBUFFER; | |
2797 | } else | |
2798 | { | |
2799 | di << argv[6] << " Invalid type of visualization" << "\n"; | |
2800 | di << "Must be one of [ wireframe, zbuffer ]" << "\n"; | |
2801 | return 1; | |
2802 | } | |
2803 | ||
2804 | V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation ); | |
2805 | ||
2806 | } else | |
2807 | { | |
2808 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
2809 | return 1; | |
2810 | } | |
2811 | ||
7fd59977 | 2812 | V3dView->ZFitAll(); |
7c8a8fcc | 2813 | |
7fd59977 | 2814 | return 0; |
2815 | } | |
2816 | ||
2817 | //============================================================================== | |
2818 | //function : VRotate | |
2819 | //purpose : Camera Rotating | |
2820 | //============================================================================== | |
2821 | ||
2822 | static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
2823 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2824 | if ( V3dView.IsNull() ) { | |
2825 | return 1; | |
2826 | } | |
2827 | ||
2828 | if ( argc == 4 ) { | |
91322f44 | 2829 | V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) ); |
7fd59977 | 2830 | return 0; |
2831 | } else if ( argc == 7 ) { | |
91322f44 | 2832 | V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Draw::Atof(argv[6]) ); |
7fd59977 | 2833 | return 0; |
2834 | } else { | |
2835 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
2836 | return 1; | |
2837 | } | |
2838 | } | |
2839 | ||
2840 | //============================================================================== | |
2841 | //function : VZoom | |
2842 | //purpose : View zoom in / out (relative to current zoom) | |
2843 | //============================================================================== | |
2844 | ||
2845 | static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
2846 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2847 | if ( V3dView.IsNull() ) { | |
2848 | return 1; | |
2849 | } | |
2850 | ||
2851 | if ( argc == 2 ) { | |
91322f44 | 2852 | Standard_Real coef = Draw::Atof(argv[1]); |
7fd59977 | 2853 | if ( coef <= 0.0 ) { |
2854 | di << argv[1] << "Invalid value" << "\n"; | |
2855 | return 1; | |
2856 | } | |
91322f44 | 2857 | V3dView->SetZoom( Draw::Atof(argv[1]) ); |
7fd59977 | 2858 | return 0; |
2859 | } else { | |
2860 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
2861 | return 1; | |
2862 | } | |
2863 | } | |
2864 | ||
2865 | //============================================================================== | |
2866 | //function : VPan | |
2867 | //purpose : View panning (in pixels) | |
2868 | //============================================================================== | |
2869 | ||
2870 | static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
2871 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2872 | if ( V3dView.IsNull() ) return 1; | |
2873 | ||
2874 | if ( argc == 3 ) { | |
91322f44 | 2875 | V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) ); |
7fd59977 | 2876 | return 0; |
2877 | } else { | |
2878 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
2879 | return 1; | |
2880 | } | |
2881 | } | |
2882 | ||
2883 | ||
2884 | //============================================================================== | |
2885 | //function : VExport | |
5cedc27f | 2886 | //purpose : Export the view to a vector graphic format (PS, EMF, PDF) |
7fd59977 | 2887 | //============================================================================== |
2888 | ||
2889 | static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2890 | { | |
2891 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
5cedc27f K |
2892 | if (V3dView.IsNull()) |
2893 | return 1; | |
7fd59977 | 2894 | |
5cedc27f K |
2895 | if (argc == 1) |
2896 | { | |
2897 | std::cout << "Usage: " << argv[0] << " Filename [Format]\n"; | |
7fd59977 | 2898 | return 1; |
2899 | } | |
2900 | ||
5cedc27f K |
2901 | Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF; |
2902 | TCollection_AsciiString aFormatStr; | |
2903 | ||
2904 | TCollection_AsciiString aFileName (argv[1]); | |
2905 | Standard_Integer aLen = aFileName.Length(); | |
2906 | ||
2907 | if (argc > 2) | |
2908 | { | |
2909 | aFormatStr = TCollection_AsciiString (argv[2]); | |
2910 | } | |
2911 | else if (aLen >= 4) | |
2912 | { | |
2913 | if (aFileName.Value (aLen - 2) == '.') | |
2914 | { | |
2915 | aFormatStr = aFileName.SubString (aLen - 1, aLen); | |
2916 | } | |
2917 | else if (aFileName.Value (aLen - 3) == '.') | |
2918 | { | |
2919 | aFormatStr = aFileName.SubString (aLen - 2, aLen); | |
2920 | } | |
2921 | else | |
2922 | { | |
2923 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
2924 | return 1; | |
2925 | } | |
2926 | } | |
2927 | else | |
2928 | { | |
2929 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
2930 | return 1; | |
2931 | } | |
2932 | ||
2933 | aFormatStr.UpperCase(); | |
2934 | if (aFormatStr == "PS") | |
2935 | anExpFormat = Graphic3d_EF_PostScript; | |
2936 | else if (aFormatStr == "EPS") | |
2937 | anExpFormat = Graphic3d_EF_EnhPostScript; | |
2938 | else if (aFormatStr == "TEX") | |
2939 | anExpFormat = Graphic3d_EF_TEX; | |
2940 | else if (aFormatStr == "PDF") | |
2941 | anExpFormat = Graphic3d_EF_PDF; | |
2942 | else if (aFormatStr == "SVG") | |
2943 | anExpFormat = Graphic3d_EF_SVG; | |
2944 | else if (aFormatStr == "PGF") | |
2945 | anExpFormat = Graphic3d_EF_PGF; | |
2946 | else if (aFormatStr == "EMF") | |
2947 | anExpFormat = Graphic3d_EF_EMF; | |
2948 | else | |
2949 | { | |
2950 | std::cout << "Invalid export format '" << aFormatStr << "'\n"; | |
2951 | return 1; | |
2952 | } | |
2953 | ||
9753e6de | 2954 | try { |
2955 | if (!V3dView->View()->Export (argv[1], anExpFormat)) | |
2956 | { | |
2957 | di << "Error: export of image to " << aFormatStr << " failed!\n"; | |
2958 | } | |
2959 | } | |
2960 | catch (Standard_Failure) | |
5cedc27f | 2961 | { |
9753e6de | 2962 | di << "Error: export of image to " << aFormatStr << " failed"; |
2963 | di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")"; | |
5cedc27f | 2964 | } |
7fd59977 | 2965 | return 0; |
2966 | } | |
2967 | ||
2968 | //============================================================================== | |
2969 | //function : VColorScale | |
2970 | //purpose : representation color scale | |
2971 | //============================================================================== | |
2972 | #include <V3d_ColorScale.hxx> | |
2973 | ||
2974 | static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) | |
2975 | { | |
2976 | if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 ) | |
2977 | { | |
2978 | di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n"; | |
2979 | return 1; | |
2980 | } | |
2981 | ||
2982 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
2983 | if(aContext.IsNull()) { | |
2984 | di << argv[0] << " ERROR : use 'vinit' command before " << "\n"; | |
2985 | return -1; | |
2986 | } | |
2987 | ||
2988 | Standard_Real minRange = 0. , maxRange = 100. ; | |
2989 | ||
2990 | Standard_Integer numIntervals = 10 ; | |
208e6839 | 2991 | Standard_Integer textHeight = 16; |
7fd59977 | 2992 | Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT; |
2993 | Standard_Real X = 0., Y = 0. ; | |
2994 | ||
2995 | if ( argc < 9 ) | |
2996 | { | |
2997 | if( argc > 3 ) | |
2998 | { | |
91322f44 | 2999 | minRange = Draw::Atof( argv[1] ); |
3000 | maxRange = Draw::Atof( argv[2] ); | |
3001 | numIntervals = Draw::Atoi( argv[3] ); | |
7fd59977 | 3002 | } |
3003 | if ( argc > 4 ) | |
91322f44 | 3004 | textHeight = Draw::Atoi( argv[4] ); |
7fd59977 | 3005 | if ( argc > 5 ) |
91322f44 | 3006 | position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] ); |
7fd59977 | 3007 | if ( argc > 7 ) |
3008 | { | |
91322f44 | 3009 | X = Draw::Atof( argv[6] ); |
3010 | Y = Draw::Atof( argv[7] ); | |
7fd59977 | 3011 | } |
3012 | } | |
3013 | Handle(V3d_View) curView = ViewerTest::CurrentView( ); | |
3014 | if ( curView.IsNull( ) ) | |
3015 | return 1; | |
3016 | Handle(Aspect_ColorScale) aCSV = curView->ColorScale( ); | |
3017 | Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) ); | |
3018 | if( ! aCS.IsNull( ) ) | |
3019 | { | |
3020 | aCS->SetPosition( X , Y ); | |
3021 | aCS->SetHeight( 0.95) ; | |
3022 | aCS->SetTextHeight( textHeight ); | |
3023 | aCS->SetRange( minRange , maxRange ); | |
3024 | aCS->SetNumberOfIntervals( numIntervals ); | |
3025 | aCS->SetLabelPosition( position ); | |
3026 | if( !curView->ColorScaleIsDisplayed() ) | |
3027 | curView->ColorScaleDisplay( ); | |
3028 | } | |
3029 | return 0; | |
3030 | } | |
3031 | ||
3032 | //============================================================================== | |
3033 | //function : VGraduatedTrihedron | |
3034 | //purpose : Displays a graduated trihedron | |
3035 | //============================================================================== | |
13a22457 S |
3036 | |
3037 | static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg) | |
3038 | { | |
3039 | const char *str = arg; | |
3040 | while (*str) | |
3041 | { | |
3042 | unsigned short c1 = *str++; | |
3043 | unsigned short c2 = *str++; | |
3044 | if (!c1 || !c2) break; | |
3045 | name += (Standard_ExtCharacter)((c1 << 8) | c2); | |
3046 | } | |
3047 | } | |
3048 | ||
7fd59977 | 3049 | static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
3050 | { | |
13a22457 S |
3051 | // Check arguments |
3052 | if (argc != 2 && argc < 5) | |
3053 | { | |
3054 | di<<"Error: "<<argv[0]<<" - invalid number of arguments\n"; | |
3055 | di<<"Usage: type help "<<argv[0]<<"\n"; | |
3056 | return 1; //TCL_ERROR | |
3057 | } | |
7fd59977 | 3058 | |
13a22457 S |
3059 | Handle(V3d_View) aV3dView = ViewerTest::CurrentView(); |
3060 | ||
3061 | // Create 3D view if it doesn't exist | |
3062 | if ( aV3dView.IsNull() ) | |
7fd59977 | 3063 | { |
4fe56619 | 3064 | ViewerTest::ViewerInit(); |
13a22457 S |
3065 | aV3dView = ViewerTest::CurrentView(); |
3066 | if( aV3dView.IsNull() ) | |
3067 | { | |
3068 | di << "Error: Cannot create a 3D view\n"; | |
3069 | return 1; //TCL_ERROR | |
3070 | } | |
7fd59977 | 3071 | } |
3072 | ||
13a22457 | 3073 | // Erase (==0) or display (!=0) |
91322f44 | 3074 | const int display = Draw::Atoi(argv[1]); |
7fd59977 | 3075 | |
13a22457 | 3076 | if (display) |
7fd59977 | 3077 | { |
13a22457 S |
3078 | // Text font |
3079 | TCollection_AsciiString font; | |
3080 | if (argc < 6) | |
3081 | font.AssignCat("Courier"); | |
3082 | else | |
3083 | font.AssignCat(argv[5]); | |
3084 | ||
3085 | // Text is multibyte | |
91322f44 | 3086 | const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0); |
13a22457 S |
3087 | |
3088 | // Set axis names | |
3089 | TCollection_ExtendedString xname, yname, zname; | |
3090 | if (argc >= 5) | |
3091 | { | |
3092 | if (isMultibyte) | |
7fd59977 | 3093 | { |
13a22457 S |
3094 | AddMultibyteString(xname, argv[2]); |
3095 | AddMultibyteString(yname, argv[3]); | |
3096 | AddMultibyteString(zname, argv[4]); | |
7fd59977 | 3097 | } |
13a22457 S |
3098 | else |
3099 | { | |
3100 | xname += argv[2]; | |
3101 | yname += argv[3]; | |
3102 | zname += argv[4]; | |
3103 | } | |
3104 | } | |
3105 | else | |
3106 | { | |
3107 | xname += "X (mm)"; | |
3108 | yname += "Y (mm)"; | |
3109 | zname += "Z (mm)"; | |
3110 | } | |
7fd59977 | 3111 | |
13a22457 S |
3112 | aV3dView->GraduatedTrihedronDisplay(xname, yname, zname, |
3113 | Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/, | |
3114 | Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/, | |
3115 | Standard_True/*drawgrid*/, | |
3116 | Standard_True/*drawaxes*/, | |
3117 | 5/*nbx*/, 5/*nby*/, 5/*nbz*/, | |
3118 | 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/, | |
3119 | 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/, | |
3120 | Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/, | |
3121 | 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/, | |
3122 | Quantity_NOC_WHITE/*gridcolor*/, | |
3123 | Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/, | |
3124 | Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font); | |
3125 | } | |
7fd59977 | 3126 | else |
13a22457 | 3127 | aV3dView->GraduatedTrihedronErase(); |
7fd59977 | 3128 | |
3129 | ViewerTest::GetAISContext()->UpdateCurrentViewer(); | |
13a22457 S |
3130 | aV3dView->Redraw(); |
3131 | ||
7fd59977 | 3132 | return 0; |
3133 | } | |
3134 | ||
7edf74fd A |
3135 | //============================================================================== |
3136 | //function : VPrintView | |
3137 | //purpose : Test printing algorithm, print the view to image file with given | |
3138 | // width and height. Printing implemented only for WNT. | |
3139 | //============================================================================== | |
4fe56619 | 3140 | static int VPrintView (Draw_Interpretor& di, Standard_Integer argc, |
7edf74fd A |
3141 | const char** argv) |
3142 | { | |
3143 | #ifndef WNT | |
3144 | di << "Printing implemented only for wnt!\n"; | |
3145 | return 1; | |
3146 | #else | |
3147 | ||
3148 | Handle(AIS_InteractiveContext) aContextAIS = NULL; | |
3149 | Handle(V3d_View) aView = NULL; | |
3150 | aContextAIS = ViewerTest::GetAISContext(); | |
3151 | if (!aContextAIS.IsNull()) | |
3152 | { | |
3153 | const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer(); | |
3154 | Vwr->InitActiveViews(); | |
3155 | if(Vwr->MoreActiveViews()) | |
3156 | aView = Vwr->ActiveView(); | |
3157 | } | |
3158 | ||
3159 | // check for errors | |
3160 | if (aView.IsNull()) | |
3161 | { | |
3162 | di << "Call vinit before!\n"; | |
3163 | return 1; | |
3164 | } | |
3165 | else if (argc < 4) | |
3166 | { | |
3167 | di << "Use: " << argv[0]; | |
3168 | di << " width height filename [print algo=0]\n"; | |
3169 | di << "width, height of the intermediate buffer for operation\n"; | |
3170 | di << "algo : {0|1}\n"; | |
3171 | di << " 0 - stretch algorithm\n"; | |
3172 | di << " 1 - tile algorithm\n"; | |
3173 | di << "test printing algorithms into an intermediate buffer\n"; | |
3174 | di << "with saving output to an image file\n"; | |
3175 | return 1; | |
3176 | } | |
3177 | ||
3178 | // get the input params | |
91322f44 | 3179 | Standard_Integer aWidth = Draw::Atoi (argv[1]); |
3180 | Standard_Integer aHeight = Draw::Atoi (argv[2]); | |
7edf74fd A |
3181 | Standard_Integer aMode = 0; |
3182 | TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]); | |
3183 | if (argc==5) | |
91322f44 | 3184 | aMode = Draw::Atoi (argv[4]); |
7edf74fd A |
3185 | |
3186 | // check the input parameters | |
3187 | if (aWidth <= 0 || aHeight <= 0) | |
3188 | { | |
3189 | di << "Width and height must be positive values!\n"; | |
3190 | return 1; | |
3191 | } | |
3192 | if (aMode != 0 && aMode != 1) | |
3193 | aMode = 0; | |
3194 | ||
7edf74fd | 3195 | // define compatible bitmap |
692613e5 | 3196 | HDC anDC = CreateCompatibleDC(0); |
7edf74fd A |
3197 | BITMAPINFO aBitmapData; |
3198 | memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER)); | |
3199 | aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); | |
3200 | aBitmapData.bmiHeader.biWidth = aWidth ; | |
3201 | aBitmapData.bmiHeader.biHeight = aHeight; | |
3202 | aBitmapData.bmiHeader.biPlanes = 1; | |
3203 | aBitmapData.bmiHeader.biBitCount = 24; | |
3204 | aBitmapData.bmiHeader.biXPelsPerMeter = 0; | |
3205 | aBitmapData.bmiHeader.biYPelsPerMeter = 0; | |
3206 | aBitmapData.bmiHeader.biClrUsed = 0; | |
3207 | aBitmapData.bmiHeader.biClrImportant = 0; | |
3208 | aBitmapData.bmiHeader.biCompression = BI_RGB; | |
3209 | aBitmapData.bmiHeader.biSizeImage = 0; | |
3210 | ||
3211 | // Create Device Independent Bitmap | |
692613e5 | 3212 | void* aBitsOut = NULL; |
7edf74fd | 3213 | HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS, |
692613e5 | 3214 | &aBitsOut, NULL, 0); |
7edf74fd A |
3215 | HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap); |
3216 | ||
3217 | Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False; | |
692613e5 | 3218 | if (aBitsOut != NULL) |
4fe56619 | 3219 | { |
7edf74fd A |
3220 | if (aMode == 0) |
3221 | isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH); | |
3222 | else | |
3223 | isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE); | |
3224 | ||
3225 | // succesfully printed into an intermediate buffer | |
3226 | if (isPrinted) | |
3227 | { | |
692613e5 | 3228 | Image_PixMap aWrapper; |
3229 | aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4); | |
3230 | aWrapper.SetTopDown (false); | |
3231 | ||
3232 | Image_AlienPixMap anImageBitmap; | |
3233 | anImageBitmap.InitCopy (aWrapper); | |
3234 | isSaved = anImageBitmap.Save (aFileName); | |
7edf74fd A |
3235 | } |
3236 | else | |
3237 | { | |
3238 | di << "Print operation failed due to printing errors or\n"; | |
3239 | di << "insufficient memory available\n"; | |
3240 | di << "Please, try to use smaller dimensions for this test\n"; | |
3241 | di << "command, as it allocates intermediate buffer for storing\n"; | |
3242 | di << "the result\n"; | |
3243 | } | |
3244 | } | |
3245 | else | |
3246 | { | |
3247 | di << "Can't allocate memory for intermediate buffer\n"; | |
3248 | di << "Please use smaller dimensions\n"; | |
3249 | } | |
3250 | ||
3251 | if (aMemoryBitmap) | |
3252 | { | |
3253 | SelectObject (anDC, anOldBitmap); | |
3254 | DeleteObject (aMemoryBitmap); | |
3255 | DeleteDC(anDC); | |
3256 | } | |
3257 | ||
3258 | if (!isSaved) | |
3259 | { | |
3260 | di << "Save to file operation failed. This operation may fail\n"; | |
3261 | di << "if you don't have enough available memory, then you can\n"; | |
3262 | di << "use smaller dimensions for the output file\n"; | |
3263 | return 1; | |
3264 | } | |
3265 | ||
3266 | return 0; | |
3267 | ||
3268 | #endif | |
3269 | } | |
3270 | ||
59f45b7c | 3271 | //============================================================================== |
3272 | //function : VZLayer | |
3273 | //purpose : Test z layer operations for v3d viewer | |
3274 | //============================================================================== | |
3275 | static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3276 | { | |
3277 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext (); | |
3278 | if (aContextAIS.IsNull()) | |
3279 | { | |
3280 | di << "Call vinit before!\n"; | |
3281 | return 1; | |
3282 | } | |
3283 | else if (argc < 2) | |
3284 | { | |
3285 | di << "Use: vzlayer " << argv[0]; | |
3286 | di << " add/del/get [id]\n"; | |
3287 | di << " add - add new z layer to viewer and print its id\n"; | |
3288 | di << " del - del z layer by its id\n"; | |
3289 | di << " get - print sequence of z layers in increasing order of their overlay level\n"; | |
3290 | di << "id - the layer identificator value defined when removing z layer\n"; | |
3291 | return 1; | |
3292 | } | |
3293 | ||
3294 | const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); | |
3295 | if (aViewer.IsNull()) | |
3296 | { | |
3297 | di << "No active viewer!\n"; | |
3298 | return 1; | |
3299 | } | |
3300 | ||
3301 | // perform operation | |
3302 | TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]); | |
3303 | if (anOp == "add") | |
3304 | { | |
3305 | Standard_Integer aNewId; | |
3306 | if (!aViewer->AddZLayer (aNewId)) | |
3307 | { | |
3308 | di << "Impossible to add new z layer!\n"; | |
3309 | return 1; | |
3310 | } | |
3311 | ||
3312 | di << "New z layer added with index: " << aNewId << "\n"; | |
3313 | } | |
3314 | else if (anOp == "del") | |
3315 | { | |
3316 | if (argc < 3) | |
3317 | { | |
3318 | di << "Please also provide as argument id of z layer to remove\n"; | |
3319 | return 1; | |
3320 | } | |
3321 | ||
91322f44 | 3322 | Standard_Integer aDelId = Draw::Atoi (argv[2]); |
59f45b7c | 3323 | if (!aViewer->RemoveZLayer (aDelId)) |
3324 | { | |
3325 | di << "Impossible to remove the z layer or invalid id!\n"; | |
3326 | return 1; | |
3327 | } | |
3328 | ||
3329 | di << "Z layer " << aDelId << " has been removed\n"; | |
3330 | } | |
3331 | else if (anOp == "get") | |
3332 | { | |
3333 | TColStd_SequenceOfInteger anIds; | |
3334 | aViewer->GetAllZLayers (anIds); | |
3335 | for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++) | |
3336 | { | |
3337 | di << anIds.Value (aSeqIdx) << " "; | |
3338 | } | |
3339 | ||
3340 | di << "\n"; | |
3341 | } | |
3342 | else | |
3343 | { | |
3344 | di << "Invalid operation, please use { add / del / get }\n"; | |
3345 | return 1; | |
3346 | } | |
3347 | ||
3348 | return 0; | |
3349 | } | |
3350 | ||
25289ec1 | 3351 | DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem) |
3352 | ||
3353 | // this class provides a presentation of text item in v3d view under-/overlayer | |
3354 | class V3d_TextItem : public Visual3d_LayerItem | |
3355 | { | |
3356 | public: | |
3357 | ||
3358 | // CASCADE RTTI | |
3359 | DEFINE_STANDARD_RTTI(V3d_TextItem) | |
3360 | ||
3361 | // constructor | |
3362 | Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText, | |
3363 | const Standard_Real theX1, | |
3364 | const Standard_Real theY1, | |
3365 | const Standard_Real theHeight, | |
3366 | const TCollection_AsciiString& theFontName, | |
3367 | const Quantity_Color& theColor, | |
3368 | const Quantity_Color& theSubtitleColor, | |
3369 | const Aspect_TypeOfDisplayText& theTypeOfDisplay, | |
3370 | const Handle(Visual3d_Layer)& theLayer); | |
3371 | ||
3372 | // redraw method | |
3373 | Standard_EXPORT void RedrawLayerPrs(); | |
3374 | ||
3375 | private: | |
3376 | ||
3377 | Standard_Real myX1; | |
3378 | Standard_Real myY1; | |
25289ec1 | 3379 | TCollection_AsciiString myText; |
eafb234b | 3380 | Standard_Real myHeight; |
3381 | Handle(Visual3d_Layer) myLayer; | |
25289ec1 | 3382 | Quantity_Color myColor; |
3383 | Quantity_Color mySubtitleColor; | |
3384 | Aspect_TypeOfDisplayText myType; | |
eafb234b | 3385 | TCollection_AsciiString myFontName; |
25289ec1 | 3386 | }; |
3387 | ||
3388 | IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem) | |
3389 | IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem) | |
3390 | ||
3391 | // create and add to display the text item | |
3392 | V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText, | |
3393 | const Standard_Real theX1, | |
3394 | const Standard_Real theY1, | |
3395 | const Standard_Real theHeight, | |
3396 | const TCollection_AsciiString& theFontName, | |
3397 | const Quantity_Color& theColor, | |
3398 | const Quantity_Color& theSubtitleColor, | |
3399 | const Aspect_TypeOfDisplayText& theTypeOfDisplay, | |
3400 | const Handle(Visual3d_Layer)& theLayer) | |
3401 | : myX1 (theX1), myY1 (theY1), | |
3402 | myText (theText), | |
3403 | myHeight (theHeight), | |
3404 | myLayer (theLayer), | |
3405 | myColor (theColor), | |
3406 | mySubtitleColor (theSubtitleColor), | |
3407 | myType (theTypeOfDisplay), | |
3408 | myFontName (theFontName) | |
3409 | { | |
3410 | if (!myLayer.IsNull ()) | |
3411 | myLayer->AddLayerItem (this); | |
3412 | } | |
3413 | ||
3414 | // render item | |
3415 | void V3d_TextItem::RedrawLayerPrs () | |
4fe56619 | 3416 | { |
25289ec1 | 3417 | if (myLayer.IsNull ()) |
3418 | return; | |
3419 | ||
3420 | myLayer->SetColor (myColor); | |
3421 | myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor); | |
3422 | myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight); | |
3423 | } | |
3424 | ||
20637bd2 | 3425 | DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem) |
3426 | ||
3427 | // The Visual3d_LayerItem line item for "vlayerline" command | |
4fe56619 | 3428 | // it provides a presentation of line with user-defined |
20637bd2 | 3429 | // linewidth, linetype and transparency. |
4fe56619 | 3430 | class V3d_LineItem : public Visual3d_LayerItem |
20637bd2 | 3431 | { |
3432 | public: | |
3433 | // CASCADE RTTI | |
4fe56619 | 3434 | DEFINE_STANDARD_RTTI(V3d_LineItem) |
3435 | ||
20637bd2 | 3436 | // constructor |
3437 | Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1, | |
3438 | Standard_Real X2, Standard_Real Y2, | |
3439 | V3d_LayerMgrPointer theLayerMgr, | |
3440 | Aspect_TypeOfLine theType = Aspect_TOL_SOLID, | |
3441 | Standard_Real theWidth = 0.5, | |
3442 | Standard_Real theTransp = 1.0); | |
3443 | ||
3444 | // redraw method | |
3445 | Standard_EXPORT void RedrawLayerPrs(); | |
3446 | ||
3447 | private: | |
3448 | ||
3449 | Standard_Real myX1, myY1, myX2, myY2; | |
eafb234b | 3450 | V3d_LayerMgrPointer myLayerMgr; |
3451 | Aspect_TypeOfLine myType; | |
20637bd2 | 3452 | Standard_Real myWidth; |
3453 | Standard_Real myTransparency; | |
20637bd2 | 3454 | }; |
3455 | ||
3456 | IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem) | |
3457 | IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem) | |
3458 | ||
3459 | // default constructor for line item | |
4fe56619 | 3460 | V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1, |
20637bd2 | 3461 | Standard_Real X2, Standard_Real Y2, |
3462 | V3d_LayerMgrPointer theLayerMgr, | |
3463 | Aspect_TypeOfLine theType, | |
3464 | Standard_Real theWidth, | |
3465 | Standard_Real theTransp) : | |
3466 | myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr), | |
3467 | myType(theType), myWidth(theWidth), myTransparency(theTransp) | |
3468 | { | |
9e4c2fbb | 3469 | if (myLayerMgr && !myLayerMgr->Overlay().IsNull()) |
20637bd2 | 3470 | myLayerMgr->Overlay()->AddLayerItem (this); |
3471 | } | |
3472 | ||
3473 | // render line | |
3474 | void V3d_LineItem::RedrawLayerPrs () | |
3475 | { | |
3476 | Handle (Visual3d_Layer) aOverlay; | |
4fe56619 | 3477 | |
20637bd2 | 3478 | if (myLayerMgr) |
3479 | aOverlay = myLayerMgr->Overlay(); | |
3480 | ||
3481 | if (!aOverlay.IsNull()) | |
3482 | { | |
3483 | Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB); | |
3484 | aOverlay->SetColor(aColor); | |
3485 | aOverlay->SetTransparency((Standard_ShortReal)myTransparency); | |
3486 | aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth); | |
3487 | aOverlay->BeginPolyline(); | |
3488 | aOverlay->AddVertex(myX1, myY1); | |
3489 | aOverlay->AddVertex(myX2, myY2); | |
3490 | aOverlay->ClosePrimitive(); | |
3491 | } | |
3492 | } | |
3493 | ||
3494 | //============================================================================= | |
3495 | //function : VLayerLine | |
3496 | //purpose : Draws line in the v3d view layer with given attributes: linetype, | |
3497 | // : linewidth, transparency coefficient | |
3498 | //============================================================================ | |
3499 | static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3500 | { | |
3501 | // get the active view | |
3502 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3503 | if (aView.IsNull()) | |
3504 | { | |
3505 | di << "Call vinit before!\n"; | |
3506 | return 1; | |
3507 | } | |
3508 | else if (argc < 5) | |
3509 | { | |
3510 | di << "Use: " << argv[0]; | |
3511 | di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n"; | |
3512 | di << " linetype : { 0 | 1 | 2 | 3 } \n"; | |
3513 | di << " 0 - solid \n"; | |
3514 | di << " 1 - dashed \n"; | |
3515 | di << " 2 - dot \n"; | |
3516 | di << " 3 - dashdot\n"; | |
3517 | di << " transparency : { 0.0 - 1.0 } \n"; | |
3518 | di << " 0.0 - transparent\n"; | |
3519 | di << " 1.0 - visible \n"; | |
3520 | return 1; | |
3521 | } | |
3522 | ||
3523 | // get the input params | |
91322f44 | 3524 | Standard_Real X1 = Draw::Atof(argv[1]); |
3525 | Standard_Real Y1 = Draw::Atof(argv[2]); | |
3526 | Standard_Real X2 = Draw::Atof(argv[3]); | |
3527 | Standard_Real Y2 = Draw::Atof(argv[4]); | |
20637bd2 | 3528 | |
3529 | Standard_Real aWidth = 0.5; | |
3530 | Standard_Integer aType = 0; | |
3531 | Standard_Real aTransparency = 1.0; | |
3532 | ||
3533 | // has width | |
3534 | if (argc > 5) | |
91322f44 | 3535 | aWidth = Draw::Atof(argv[5]); |
20637bd2 | 3536 | |
3537 | // has type | |
3538 | if (argc > 6) | |
91322f44 | 3539 | aType = (Standard_Integer) Draw::Atoi(argv[6]); |
20637bd2 | 3540 | |
3541 | // has transparency | |
3542 | if (argc > 7) | |
3543 | { | |
91322f44 | 3544 | aTransparency = Draw::Atof(argv[7]); |
4fe56619 | 3545 | if (aTransparency < 0 || aTransparency > 1.0) |
20637bd2 | 3546 | aTransparency = 1.0; |
3547 | } | |
3548 | ||
3549 | // select appropriate line type | |
3550 | Aspect_TypeOfLine aLineType; | |
3551 | switch (aType) | |
3552 | { | |
3553 | case 1: | |
3554 | aLineType = Aspect_TOL_DASH; | |
3555 | break; | |
3556 | ||
3557 | case 2: | |
3558 | aLineType = Aspect_TOL_DOT; | |
3559 | break; | |
3560 | ||
3561 | case 3: | |
3562 | aLineType = Aspect_TOL_DOTDASH; | |
3563 | break; | |
3564 | ||
3565 | default: | |
3566 | aLineType = Aspect_TOL_SOLID; | |
3567 | } | |
3568 | ||
3569 | // replace layer manager | |
3570 | Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView); | |
3571 | aView->SetLayerMgr(aMgr); | |
3572 | ||
3573 | // add line item | |
4fe56619 | 3574 | Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2, |
20637bd2 | 3575 | aMgr.operator->(), |
4fe56619 | 3576 | aLineType, aWidth, |
20637bd2 | 3577 | aTransparency); |
3578 | ||
3579 | // update view | |
3580 | aView->MustBeResized(); | |
3581 | aView->Redraw(); | |
3582 | ||
3583 | return 0; | |
3584 | } | |
3585 | ||
25289ec1 | 3586 | //======================================================================= |
3587 | //function : VOverlayText | |
3588 | //purpose : Test text displaying in view overlay | |
3589 | //======================================================================= | |
3590 | static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv) | |
3591 | { | |
3592 | // get the active view | |
3593 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3594 | if (aView.IsNull()) | |
3595 | { | |
3596 | di << "No active view. Please call vinit.\n"; | |
3597 | return 1; | |
3598 | } | |
3599 | else if (argc < 4 || argc > 13) | |
3600 | { | |
3601 | di << "Use: " << argv[0]; | |
3602 | di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n"; | |
3603 | di << "[background_color: R G B]\n"; | |
3604 | di << " height - pixel height of the text (default=10.0)\n"; | |
3605 | di << " font_name - name of font (default=courier)\n"; | |
3606 | di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n"; | |
a6eb515f | 3607 | di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n"; |
25289ec1 | 3608 | di << " background_color- R G B values used for subtitle and decal text\n"; |
3609 | di << "(default=255.0 255.0 255.0)\n"; | |
3610 | return 1; | |
3611 | } | |
4fe56619 | 3612 | |
25289ec1 | 3613 | TCollection_AsciiString aText (argv[1]); |
91322f44 | 3614 | Standard_Real aPosX = Draw::Atof(argv[2]); |
3615 | Standard_Real aPosY = Draw::Atof(argv[3]); | |
3616 | Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0; | |
25289ec1 | 3617 | |
3618 | // font name | |
3619 | TCollection_AsciiString aFontName = "Courier"; | |
3620 | if (argc >= 6) | |
3621 | aFontName = TCollection_AsciiString (argv[5]); | |
3622 | ||
3623 | // text colors | |
3624 | Quantity_Parameter aColorRed = 1.0; | |
3625 | Quantity_Parameter aColorGreen = 1.0; | |
3626 | Quantity_Parameter aColorBlue = 1.0; | |
3627 | if (argc >= 9) | |
3628 | { | |
91322f44 | 3629 | aColorRed = Draw::Atof (argv[6])/255.; |
3630 | aColorGreen = Draw::Atof (argv[7])/255.; | |
3631 | aColorBlue = Draw::Atof (argv[8])/255.; | |
25289ec1 | 3632 | } |
3633 | ||
3634 | // display type | |
3635 | TCollection_AsciiString aDispStr; | |
3636 | if (argc >= 10) | |
3637 | aDispStr = TCollection_AsciiString (argv[9]); | |
3638 | ||
3639 | Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL; | |
3640 | if (aDispStr.IsEqual ("subtitle")) | |
3641 | aTextType = Aspect_TODT_SUBTITLE; | |
3642 | else if (aDispStr.IsEqual ("decal")) | |
3643 | aTextType = Aspect_TODT_DEKALE; | |
3644 | else if (aDispStr.IsEqual ("blend")) | |
3645 | aTextType = Aspect_TODT_BLEND; | |
a6eb515f | 3646 | else if (aDispStr.IsEqual ("dimension")) |
3647 | aTextType = Aspect_TODT_DIMENSION; | |
25289ec1 | 3648 | |
3649 | // subtitle color | |
3650 | Quantity_Parameter aSubRed = 1.0; | |
3651 | Quantity_Parameter aSubGreen = 1.0; | |
3652 | Quantity_Parameter aSubBlue = 1.0; | |
3653 | if (argc == 13) | |
3654 | { | |
91322f44 | 3655 | aSubRed = Draw::Atof (argv[10])/255.; |
3656 | aSubGreen = Draw::Atof (argv[11])/255.; | |
3657 | aSubBlue = Draw::Atof (argv[12])/255.; | |
25289ec1 | 3658 | } |
3659 | ||
3660 | // check fo current overlay | |
3661 | Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer (); | |
3662 | if (anOverlay.IsNull ()) | |
3663 | { | |
3664 | Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView); | |
3665 | anOverlay = aMgr->Overlay (); | |
3666 | aView->SetLayerMgr (aMgr); | |
3667 | } | |
3668 | ||
4fe56619 | 3669 | Quantity_Color aTextColor (aColorRed, aColorGreen, |
25289ec1 | 3670 | aColorBlue, Quantity_TOC_RGB); |
4fe56619 | 3671 | Quantity_Color aSubtColor (aSubRed, aSubGreen, |
25289ec1 | 3672 | aSubBlue, Quantity_TOC_RGB); |
3673 | ||
3674 | // add text item | |
3675 | Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY, | |
3676 | aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay); | |
3677 | ||
3678 | // update view | |
3679 | aView->MustBeResized(); | |
3680 | aView->Redraw(); | |
3681 | ||
3682 | return 0; | |
3683 | } | |
3684 | ||
2bd4c032 | 3685 | //============================================================================== |
3686 | //function : VGrid | |
3687 | //purpose : | |
3688 | //============================================================================== | |
3689 | ||
35e08fe8 | 3690 | static int VGrid (Draw_Interpretor& /*theDI*/, |
2bd4c032 | 3691 | Standard_Integer theArgNb, |
3692 | const char** theArgVec) | |
3693 | { | |
3694 | // get the active view | |
3695 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3696 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
3697 | if (aView.IsNull() || aViewer.IsNull()) | |
3698 | { | |
3699 | std::cerr << "No active view. Please call vinit.\n"; | |
3700 | return 1; | |
3701 | } | |
3702 | ||
3703 | Aspect_GridType aType = aViewer->GridType(); | |
3704 | Aspect_GridDrawMode aMode = aViewer->GridDrawMode(); | |
3705 | ||
3706 | Standard_Integer anIter = 1; | |
3707 | for (; anIter < theArgNb; ++anIter) | |
3708 | { | |
3709 | const char* aValue = theArgVec[anIter]; | |
3710 | if (*aValue == 'r') | |
3711 | { | |
3712 | aType = Aspect_GT_Rectangular; | |
3713 | } | |
3714 | else if (*aValue == 'c') | |
3715 | { | |
3716 | aType = Aspect_GT_Circular; | |
3717 | } | |
3718 | else if (*aValue == 'l') | |
3719 | { | |
3720 | aMode = Aspect_GDM_Lines; | |
3721 | } | |
3722 | else if (*aValue == 'p') | |
3723 | { | |
3724 | aMode = Aspect_GDM_Points; | |
3725 | } | |
3726 | else if (strcmp (aValue, "off" ) == 0) | |
3727 | { | |
3728 | aViewer->DeactivateGrid(); | |
3729 | return 0; | |
3730 | } | |
3731 | else | |
3732 | { | |
3733 | break; | |
3734 | } | |
3735 | } | |
3736 | ||
3737 | Standard_Integer aTail = (theArgNb - anIter); | |
3738 | if (aTail == 0) | |
3739 | { | |
3740 | aViewer->ActivateGrid (aType, aMode); | |
3741 | return 0; | |
3742 | } | |
3743 | else if (aTail != 2 && aTail != 5) | |
3744 | { | |
3745 | std::cerr << "Incorrect arguments number! Usage:\n" | |
3746 | << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n"; | |
3747 | return 1; | |
3748 | } | |
3749 | ||
3750 | Quantity_Length anOriginX, anOriginY; | |
3751 | Quantity_PlaneAngle aRotAngle; | |
3752 | if (aType == Aspect_GT_Rectangular) | |
3753 | { | |
3754 | Quantity_Length aRStepX, aRStepY; | |
3755 | aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); | |
3756 | ||
91322f44 | 3757 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
3758 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 3759 | if (aTail == 5) |
3760 | { | |
91322f44 | 3761 | aRStepX = Draw::Atof (theArgVec[anIter++]); |
3762 | aRStepY = Draw::Atof (theArgVec[anIter++]); | |
3763 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 3764 | } |
3765 | aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); | |
3766 | aViewer->ActivateGrid (aType, aMode); | |
3767 | } | |
3768 | else if (aType == Aspect_GT_Circular) | |
3769 | { | |
3770 | Quantity_Length aRadiusStep; | |
3771 | Standard_Integer aDivisionNumber; | |
3772 | aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
3773 | ||
91322f44 | 3774 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
3775 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 3776 | if (aTail == 5) |
3777 | { | |
91322f44 | 3778 | aRadiusStep = Draw::Atof (theArgVec[anIter++]); |
3779 | aDivisionNumber = Draw::Atoi (theArgVec[anIter++]); | |
3780 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 3781 | } |
3782 | ||
3783 | aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
3784 | aViewer->ActivateGrid (aType, aMode); | |
3785 | } | |
3786 | ||
3787 | return 0; | |
3788 | } | |
3789 | ||
208e6839 | 3790 | //============================================================================== |
3791 | //function : VFps | |
3792 | //purpose : | |
3793 | //============================================================================== | |
3794 | ||
3795 | static int VFps (Draw_Interpretor& theDI, | |
3796 | Standard_Integer theArgNb, | |
3797 | const char** theArgVec) | |
3798 | { | |
3799 | // get the active view | |
3800 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3801 | if (aView.IsNull()) | |
3802 | { | |
3803 | std::cerr << "No active view. Please call vinit.\n"; | |
3804 | return 1; | |
3805 | } | |
3806 | ||
91322f44 | 3807 | Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100; |
208e6839 | 3808 | if (aFramesNb <= 0) |
3809 | { | |
3810 | std::cerr << "Incorrect arguments!\n"; | |
3811 | return 1; | |
3812 | } | |
3813 | ||
3814 | // the time is meaningless for first call | |
3815 | // due to async OpenGl rendering | |
3816 | aView->Redraw(); | |
3817 | ||
3818 | // redraw view in loop to estimate average values | |
3819 | OSD_Timer aTimer; | |
3820 | aTimer.Start(); | |
3821 | for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter) | |
3822 | { | |
3823 | aView->Redraw(); | |
3824 | } | |
3825 | aTimer.Stop(); | |
3826 | Standard_Real aCpu; | |
3827 | const Standard_Real aTime = aTimer.ElapsedTime(); | |
3828 | aTimer.OSD_Chronometer::Show (aCpu); | |
3829 | ||
3830 | const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime; | |
3831 | const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb); | |
3832 | ||
3833 | // return statistics | |
3834 | theDI << "FPS: " << aFpsAver << "\n" | |
3835 | << "CPU: " << (1000.0 * aCpuAver) << " msec\n"; | |
3836 | ||
3837 | return 0; | |
3838 | } | |
3839 | ||
58655684 | 3840 | //============================================================================== |
3841 | //function : VGlDebug | |
3842 | //purpose : | |
3843 | //============================================================================== | |
3844 | ||
3845 | static int VGlDebug (Draw_Interpretor& theDI, | |
3846 | Standard_Integer theArgNb, | |
3847 | const char** theArgVec) | |
3848 | { | |
3849 | if (theArgNb < 2) | |
3850 | { | |
3851 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3852 | if (aView.IsNull()) | |
3853 | { | |
3854 | std::cerr << "No active view. Please call vinit.\n"; | |
3855 | return 0; | |
3856 | } | |
3857 | ||
3858 | Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS), | |
3859 | "GL_ARB_debug_output"); | |
3860 | std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n"; | |
3861 | theDI << (isActive ? "1" : "0"); | |
3862 | return 0; | |
3863 | } | |
3864 | ||
3865 | ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0; | |
3866 | return 0; | |
3867 | } | |
208e6839 | 3868 | |
3869 | //============================================================================== | |
3870 | //function : VVbo | |
3871 | //purpose : | |
3872 | //============================================================================== | |
3873 | ||
58655684 | 3874 | static int VVbo (Draw_Interpretor& theDI, |
208e6839 | 3875 | Standard_Integer theArgNb, |
3876 | const char** theArgVec) | |
3877 | { | |
58655684 | 3878 | const Standard_Boolean toSet = (theArgNb > 1); |
3879 | const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1; | |
3880 | if (toSet) | |
208e6839 | 3881 | { |
58655684 | 3882 | ViewerTest_myDefaultCaps.vboDisable = toUseVbo; |
208e6839 | 3883 | } |
3884 | ||
58655684 | 3885 | // get the context |
3886 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
3887 | if (aContextAIS.IsNull()) | |
208e6839 | 3888 | { |
58655684 | 3889 | if (!toSet) |
3890 | { | |
3891 | std::cerr << "No active view!\n"; | |
3892 | } | |
208e6839 | 3893 | return 1; |
3894 | } | |
58655684 | 3895 | Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver()); |
3896 | if (!aDriver.IsNull()) | |
208e6839 | 3897 | { |
58655684 | 3898 | if (!toSet) |
3899 | { | |
3900 | theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n"; | |
3901 | } | |
3902 | else | |
3903 | { | |
3904 | aDriver->ChangeOptions().vboDisable = toUseVbo; | |
3905 | } | |
208e6839 | 3906 | } |
3907 | ||
208e6839 | 3908 | return 0; |
3909 | } | |
3910 | ||
a577aaab | 3911 | //============================================================================== |
3912 | //function : VCaps | |
3913 | //purpose : | |
3914 | //============================================================================== | |
3915 | ||
3916 | static int VCaps (Draw_Interpretor& theDI, | |
3917 | Standard_Integer theArgNb, | |
3918 | const char** theArgVec) | |
3919 | { | |
3920 | OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps; | |
3921 | Handle(OpenGl_GraphicDriver) aDriver; | |
3922 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
3923 | if (!aContextAIS.IsNull()) | |
3924 | { | |
3925 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver()); | |
3926 | aCaps = &aDriver->ChangeOptions(); | |
3927 | } | |
3928 | ||
3929 | if (theArgNb < 2) | |
3930 | { | |
3931 | theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n"; | |
3932 | theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n"; | |
abe46077 | 3933 | theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n"; |
a577aaab | 3934 | return 0; |
3935 | } | |
3936 | ||
3937 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
3938 | { | |
3939 | const TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
3940 | if (anArg.Search ("vbo=") > -1) | |
3941 | { | |
3942 | aCaps->vboDisable = anArg.Token ("=", 2).IntegerValue() == 0; | |
3943 | } | |
3944 | else if (anArg.Search ("sprites=") > -1) | |
3945 | { | |
3946 | aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0; | |
3947 | } | |
abe46077 | 3948 | else if (anArg.Search ("soft=") > -1) |
3949 | { | |
3950 | aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0; | |
3951 | } | |
a577aaab | 3952 | else |
3953 | { | |
3954 | std::cerr << "Unknown argument: " << anArg << "\n"; | |
3955 | } | |
3956 | } | |
3957 | if (aCaps != &ViewerTest_myDefaultCaps) | |
3958 | { | |
3959 | ViewerTest_myDefaultCaps = *aCaps; | |
3960 | } | |
3961 | return 0; | |
3962 | } | |
3963 | ||
f0430952 | 3964 | //============================================================================== |
3965 | //function : VMemGpu | |
3966 | //purpose : | |
3967 | //============================================================================== | |
3968 | ||
3969 | static int VMemGpu (Draw_Interpretor& theDI, | |
3970 | Standard_Integer theArgNb, | |
3971 | const char** theArgVec) | |
3972 | { | |
3973 | // get the context | |
3974 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
3975 | if (aContextAIS.IsNull()) | |
3976 | { | |
3977 | std::cerr << "No active view. Please call vinit.\n"; | |
3978 | return 1; | |
3979 | } | |
3980 | ||
dc3fe572 | 3981 | Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver(); |
f0430952 | 3982 | if (aDriver.IsNull()) |
3983 | { | |
3984 | std::cerr << "Graphic driver not available.\n"; | |
3985 | return 1; | |
3986 | } | |
3987 | ||
3988 | Standard_Size aFreeBytes = 0; | |
3989 | TCollection_AsciiString anInfo; | |
3990 | if (!aDriver->MemoryInfo (aFreeBytes, anInfo)) | |
3991 | { | |
3992 | std::cerr << "Information not available.\n"; | |
3993 | return 1; | |
3994 | } | |
3995 | ||
3996 | if (theArgNb > 1 && *theArgVec[1] == 'f') | |
3997 | { | |
3998 | theDI << Standard_Real (aFreeBytes); | |
3999 | } | |
4000 | else | |
4001 | { | |
4002 | theDI << anInfo; | |
4003 | } | |
4004 | ||
4005 | return 0; | |
4006 | } | |
4007 | ||
85e096c3 | 4008 | // ============================================================================== |
4009 | // function : VReadPixel | |
4010 | // purpose : | |
4011 | // ============================================================================== | |
4012 | static int VReadPixel (Draw_Interpretor& theDI, | |
4013 | Standard_Integer theArgNb, | |
4014 | const char** theArgVec) | |
4015 | { | |
4016 | // get the active view | |
4017 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4018 | if (aView.IsNull()) | |
4019 | { | |
4020 | std::cerr << "No active view. Please call vinit.\n"; | |
4021 | return 1; | |
4022 | } | |
4023 | else if (theArgNb < 3) | |
4024 | { | |
4025 | std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n"; | |
4026 | return 1; | |
4027 | } | |
4028 | ||
692613e5 | 4029 | Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; |
4030 | Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA; | |
4031 | ||
85e096c3 | 4032 | Standard_Integer aWidth, aHeight; |
4033 | aView->Window()->Size (aWidth, aHeight); | |
91322f44 | 4034 | const Standard_Integer anX = Draw::Atoi (theArgVec[1]); |
4035 | const Standard_Integer anY = Draw::Atoi (theArgVec[2]); | |
85e096c3 | 4036 | if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight) |
4037 | { | |
4038 | std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n"; | |
4039 | return 1; | |
4040 | } | |
4041 | ||
4042 | Standard_Boolean toShowName = Standard_False; | |
4043 | Standard_Boolean toShowHls = Standard_False; | |
4044 | for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter) | |
4045 | { | |
29cb310a | 4046 | const char* aParam = theArgVec[anIter]; |
4047 | if ( strcasecmp( aParam, "rgb" ) == 0 ) | |
85e096c3 | 4048 | { |
692613e5 | 4049 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; |
4050 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 4051 | } |
29cb310a | 4052 | else if ( strcasecmp( aParam, "hls" ) == 0 ) |
85e096c3 | 4053 | { |
692613e5 | 4054 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; |
4055 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 4056 | toShowHls = Standard_True; |
4057 | } | |
29cb310a | 4058 | else if ( strcasecmp( aParam, "rgbf" ) == 0 ) |
85e096c3 | 4059 | { |
692613e5 | 4060 | aFormat = Image_PixMap::ImgRGBF; |
4061 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 4062 | } |
29cb310a | 4063 | else if ( strcasecmp( aParam, "rgba" ) == 0 ) |
85e096c3 | 4064 | { |
692613e5 | 4065 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; |
4066 | aBufferType = Graphic3d_BT_RGBA; | |
85e096c3 | 4067 | } |
29cb310a | 4068 | else if ( strcasecmp( aParam, "rgbaf" ) == 0 ) |
85e096c3 | 4069 | { |
692613e5 | 4070 | aFormat = Image_PixMap::ImgRGBAF; |
4071 | aBufferType = Graphic3d_BT_RGBA; | |
85e096c3 | 4072 | } |
29cb310a | 4073 | else if ( strcasecmp( aParam, "depth" ) == 0 ) |
85e096c3 | 4074 | { |
692613e5 | 4075 | aFormat = Image_PixMap::ImgGrayF; |
4076 | aBufferType = Graphic3d_BT_Depth; | |
85e096c3 | 4077 | } |
29cb310a | 4078 | else if ( strcasecmp( aParam, "name" ) == 0 ) |
85e096c3 | 4079 | { |
4080 | toShowName = Standard_True; | |
4081 | } | |
4082 | } | |
4083 | ||
692613e5 | 4084 | Image_PixMap anImage; |
4085 | if (!anImage.InitTrash (aFormat, aWidth, aHeight)) | |
4086 | { | |
4087 | std::cerr << "Image allocation failed\n"; | |
4088 | return 1; | |
4089 | } | |
4090 | else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType)) | |
85e096c3 | 4091 | { |
4092 | std::cerr << "Image dump failed\n"; | |
4093 | return 1; | |
4094 | } | |
4095 | ||
4096 | Quantity_Parameter anAlpha; | |
692613e5 | 4097 | Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha); |
85e096c3 | 4098 | if (toShowName) |
4099 | { | |
692613e5 | 4100 | if (aBufferType == Graphic3d_BT_RGBA) |
85e096c3 | 4101 | { |
4102 | theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n"; | |
4103 | } | |
4104 | else | |
4105 | { | |
4106 | theDI << Quantity_Color::StringName (aColor.Name()) << "\n"; | |
4107 | } | |
4108 | } | |
4109 | else | |
4110 | { | |
4111 | switch (aBufferType) | |
4112 | { | |
4113 | default: | |
692613e5 | 4114 | case Graphic3d_BT_RGB: |
85e096c3 | 4115 | { |
4116 | if (toShowHls) | |
4117 | { | |
4118 | theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n"; | |
4119 | } | |
4120 | else | |
4121 | { | |
4122 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n"; | |
4123 | } | |
4124 | break; | |
4125 | } | |
692613e5 | 4126 | case Graphic3d_BT_RGBA: |
85e096c3 | 4127 | { |
4128 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n"; | |
4129 | break; | |
4130 | } | |
692613e5 | 4131 | case Graphic3d_BT_Depth: |
85e096c3 | 4132 | { |
4133 | theDI << aColor.Red() << "\n"; | |
4134 | break; | |
4135 | } | |
4136 | } | |
4137 | } | |
4138 | ||
4139 | return 0; | |
4140 | } | |
4141 | ||
692613e5 | 4142 | //============================================================================== |
4143 | //function : VDiffImage | |
4144 | //purpose : The draw-command compares two images. | |
4145 | //============================================================================== | |
4146 | ||
4147 | static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
4148 | { | |
4149 | if (theArgNb < 6) | |
4150 | { | |
4151 | theDI << "Not enough arguments.\n"; | |
4152 | return 1; | |
4153 | } | |
4154 | ||
4155 | // image file names | |
4156 | const char* anImgPathRef = theArgVec[1]; | |
4157 | const char* anImgPathNew = theArgVec[2]; | |
4158 | ||
4159 | // get string tolerance and check its validity | |
91322f44 | 4160 | Standard_Real aTolColor = Draw::Atof (theArgVec[3]); |
692613e5 | 4161 | if (aTolColor < 0.0) |
4162 | aTolColor = 0.0; | |
4163 | if (aTolColor > 1.0) | |
4164 | aTolColor = 1.0; | |
4165 | ||
91322f44 | 4166 | Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1); |
4167 | Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1); | |
692613e5 | 4168 | |
4169 | // image file of difference | |
4170 | const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL; | |
4171 | ||
4172 | // compare the images | |
4173 | Image_Diff aComparer; | |
4174 | if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite)) | |
4175 | { | |
4176 | return 1; | |
4177 | } | |
4178 | ||
4179 | aComparer.SetColorTolerance (aTolColor); | |
4180 | aComparer.SetBorderFilterOn (isBorderFilterOn); | |
4181 | Standard_Integer aDiffColorsNb = aComparer.Compare(); | |
4182 | theDI << aDiffColorsNb << "\n"; | |
4183 | ||
4184 | // save image of difference | |
4185 | if (aDiffImagePath != NULL) | |
4186 | { | |
4187 | aComparer.SaveDiffImage (aDiffImagePath); | |
4188 | } | |
4189 | ||
4190 | return 0; | |
4191 | } | |
4192 | ||
4754e164 | 4193 | //======================================================================= |
4194 | //function : VSelect | |
4195 | //purpose : Emulates different types of selection by mouse: | |
4196 | // 1) single click selection | |
4197 | // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2) | |
4198 | // 3) selection with polygon having corners at | |
dc3fe572 | 4199 | // pixel positions (x1,y1),...,(xn,yn) |
4754e164 | 4200 | // 4) any of these selections with shift button pressed |
4201 | //======================================================================= | |
4202 | static Standard_Integer VSelect (Draw_Interpretor& di, | |
4203 | Standard_Integer argc, | |
4204 | const char ** argv) | |
4205 | { | |
dc3fe572 | 4206 | if(argc < 3) |
4754e164 | 4207 | { |
4208 | di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n"; | |
4209 | return 1; | |
4210 | } | |
4211 | ||
4212 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); | |
dc3fe572 | 4213 | if(myAIScontext.IsNull()) |
4754e164 | 4214 | { |
4215 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4216 | return 1; | |
4217 | } | |
4218 | const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1)); | |
4219 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); | |
4220 | aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2])); | |
4221 | if(argc <= 4) | |
4222 | { | |
4223 | if(isShiftSelection) | |
4224 | aCurrentEventManager->ShiftSelect(); | |
4225 | else | |
4226 | aCurrentEventManager->Select(); | |
4227 | } | |
4228 | else if(argc <= 6) | |
4229 | { | |
4230 | if(isShiftSelection) | |
4231 | aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4])); | |
4232 | else | |
4233 | aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4])); | |
4234 | } | |
4235 | else | |
4236 | { | |
4237 | Standard_Integer anUpper = 0; | |
4238 | ||
4239 | if(isShiftSelection) | |
4240 | anUpper = (argc-1)/2; | |
4241 | else | |
4242 | anUpper = argc/2; | |
4243 | TColgp_Array1OfPnt2d aPolyline(1,anUpper); | |
4244 | ||
4245 | for(Standard_Integer i=1;i<=anUpper;++i) | |
4246 | aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i]))); | |
4247 | ||
4248 | if(isShiftSelection) | |
4249 | aCurrentEventManager->ShiftSelect(aPolyline); | |
4250 | else | |
4251 | aCurrentEventManager->Select(aPolyline); | |
4252 | } | |
4253 | return 0; | |
4254 | } | |
4255 | ||
4256 | //======================================================================= | |
4257 | //function : VMoveTo | |
dc3fe572 | 4258 | //purpose : Emulates cursor movement to defined pixel position |
4754e164 | 4259 | //======================================================================= |
4260 | static Standard_Integer VMoveTo (Draw_Interpretor& di, | |
4261 | Standard_Integer argc, | |
4262 | const char ** argv) | |
4263 | { | |
dc3fe572 | 4264 | if(argc != 3) |
4754e164 | 4265 | { |
4266 | di << "Usage : " << argv[0] << " x y" << "\n"; | |
4267 | return 1; | |
4268 | } | |
4269 | ||
4270 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
dc3fe572 | 4271 | if(aContext.IsNull()) |
4754e164 | 4272 | { |
4273 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4274 | return 1; | |
4275 | } | |
4276 | ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2])); | |
4277 | return 0; | |
4278 | } | |
4279 | ||
4280 | //======================================================================= | |
4281 | //function : VViewParams | |
dc3fe572 | 4282 | //purpose : Gets or sets AIS View characteristics |
4754e164 | 4283 | //======================================================================= |
4284 | static Standard_Integer VViewParams (Draw_Interpretor& di, | |
4285 | Standard_Integer argc, | |
4286 | const char ** argv) | |
4287 | { | |
dc3fe572 | 4288 | if ( argc != 1 && argc != 13) |
4754e164 | 4289 | { |
4290 | di << "Usage : " << argv[0] << "\n"; | |
4291 | return 1; | |
4292 | } | |
4293 | Handle (V3d_View) anAISView = ViewerTest::CurrentView (); | |
dc3fe572 | 4294 | if ( anAISView.IsNull () ) |
4754e164 | 4295 | { |
4296 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4297 | return 1; | |
4298 | } | |
4299 | if(argc==1){ | |
4300 | Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale (); | |
4301 | Standard_Real anAISViewCenterCoordinateX = 0.0; | |
4302 | Standard_Real anAISViewCenterCoordinateY = 0.0; | |
4303 | anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY); | |
4304 | Standard_Real anAISViewProjX = 0.0; | |
4305 | Standard_Real anAISViewProjY = 0.0; | |
4306 | Standard_Real anAISViewProjZ = 0.0; | |
4307 | anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ); | |
4308 | Standard_Real anAISViewUpX = 0.0; | |
4309 | Standard_Real anAISViewUpY = 0.0; | |
4310 | Standard_Real anAISViewUpZ = 0.0; | |
4311 | anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ); | |
4312 | Standard_Real anAISViewAtX = 0.0; | |
4313 | Standard_Real anAISViewAtY = 0.0; | |
4314 | Standard_Real anAISViewAtZ = 0.0; | |
4315 | anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ); | |
4316 | di << "Scale of current view: " << anAISViewScale << "\n"; | |
4317 | di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n"; | |
4318 | di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n"; | |
4319 | di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n"; | |
4320 | di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n"; | |
4321 | } | |
4322 | else | |
4323 | { | |
4324 | Quantity_Factor anAISViewScale = atof (argv [1]); | |
4325 | Standard_Real anAISViewCenterCoordinateX = atof (argv [2]); | |
4326 | Standard_Real anAISViewCenterCoordinateY = atof (argv [3]); | |
4327 | Standard_Real anAISViewProjX = atof (argv [4]); | |
4328 | Standard_Real anAISViewProjY = atof (argv [5]); | |
4329 | Standard_Real anAISViewProjZ = atof (argv [6]); | |
4330 | Standard_Real anAISViewUpX = atof (argv [7]); | |
4331 | Standard_Real anAISViewUpY = atof (argv [8]); | |
4332 | Standard_Real anAISViewUpZ = atof (argv [9]); | |
4333 | Standard_Real anAISViewAtX = atof (argv [10]); | |
4334 | Standard_Real anAISViewAtY = atof (argv [11]); | |
4335 | Standard_Real anAISViewAtZ = atof (argv [12]); | |
4336 | anAISView -> V3d_View::SetScale (anAISViewScale); | |
4337 | anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY); | |
4338 | anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ); | |
4339 | anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ); | |
4340 | anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ); | |
4341 | } | |
4342 | return 0; | |
4343 | } | |
4344 | ||
4345 | //======================================================================= | |
4346 | //function : VChangeSelected | |
dc3fe572 | 4347 | //purpose : Adds the shape to selection or remove one from it |
4754e164 | 4348 | //======================================================================= |
4349 | static Standard_Integer VChangeSelected (Draw_Interpretor& di, | |
4350 | Standard_Integer argc, | |
4351 | const char ** argv) | |
4352 | { | |
4353 | if(argc != 2) | |
4354 | { | |
4355 | di<<"Usage : " << argv[0] << " shape \n"; | |
4356 | return 1; | |
4357 | } | |
4358 | //get AIS_Shape: | |
4359 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4360 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4361 | TCollection_AsciiString aName(argv[1]); | |
4362 | Handle(AIS_InteractiveObject) anAISObject; | |
4363 | ||
4364 | if(!aMap.IsBound2(aName)) | |
4365 | { | |
4366 | di<<"Use 'vdisplay' before"; | |
4367 | return 1; | |
4368 | } | |
4369 | else | |
4370 | { | |
4371 | anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName)); | |
4372 | if(anAISObject.IsNull()){ | |
4373 | di<<"No interactive object \n"; | |
4374 | return 1; | |
4375 | } | |
4376 | ||
4377 | if(aContext->HasOpenedContext()) | |
4378 | { | |
4379 | aContext->AddOrRemoveSelected(anAISObject); | |
4380 | } | |
dc3fe572 | 4381 | else |
4754e164 | 4382 | { |
4383 | aContext->AddOrRemoveCurrentObject(anAISObject); | |
4384 | } | |
4385 | } | |
4386 | return 0; | |
4387 | } | |
4388 | ||
4389 | //======================================================================= | |
4390 | //function : VZClipping | |
dc3fe572 | 4391 | //purpose : Gets or sets ZClipping mode, width and depth |
4754e164 | 4392 | //======================================================================= |
4393 | static Standard_Integer VZClipping (Draw_Interpretor& di, | |
4394 | Standard_Integer argc, | |
4395 | const char ** argv) | |
4396 | { | |
dc3fe572 | 4397 | if(argc>4) |
4754e164 | 4398 | { |
4399 | di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
4400 | <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
4401 | return -1; | |
4402 | } | |
4403 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
dc3fe572 | 4404 | if(aContext.IsNull()) |
4754e164 | 4405 | { |
4406 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4407 | return 1; | |
4408 | } | |
4409 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
1d47d8d0 | 4410 | V3d_TypeOfZclipping aZClippingMode = V3d_OFF; |
4754e164 | 4411 | if(argc==1) |
4412 | { | |
4413 | TCollection_AsciiString aZClippingModeString; | |
4414 | Quantity_Length aDepth, aWidth; | |
4415 | aZClippingMode = aView->ZClipping(aDepth, aWidth); | |
4416 | switch (aZClippingMode) | |
4417 | { | |
4418 | case V3d_OFF: | |
4419 | aZClippingModeString.Copy("OFF"); | |
4420 | break; | |
4421 | case V3d_BACK: | |
4422 | aZClippingModeString.Copy("BACK"); | |
4423 | break; | |
4424 | case V3d_FRONT: | |
4425 | aZClippingModeString.Copy("FRONT"); | |
4426 | break; | |
4427 | case V3d_SLICE: | |
4428 | aZClippingModeString.Copy("SLICE"); | |
4429 | break; | |
4430 | default: | |
4431 | aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode)); | |
4432 | break; | |
4433 | } | |
4434 | di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n" | |
4435 | << "ZClipping depth = " << aDepth << "\n" | |
4436 | << "ZClipping width = " << aWidth << "\n"; | |
4437 | } | |
4438 | else | |
4439 | { | |
4440 | if(argc !=3) | |
4441 | { | |
4442 | Standard_Integer aStatus = 0; | |
4443 | if ( strcmp (argv [1], "OFF") == 0 ) { | |
4444 | aStatus = 1; | |
4445 | aZClippingMode = V3d_OFF; | |
4446 | } | |
4447 | if ( strcmp (argv [1], "BACK") == 0 ) { | |
4448 | aStatus = 1; | |
4449 | aZClippingMode = V3d_BACK; | |
4450 | } | |
4451 | if ( strcmp (argv [1], "FRONT") == 0 ) { | |
4452 | aStatus = 1; | |
4453 | aZClippingMode = V3d_FRONT; | |
4454 | } | |
4455 | if ( strcmp (argv [1], "SLICE") == 0 ) { | |
4456 | aStatus = 1; | |
4457 | aZClippingMode = V3d_SLICE; | |
4458 | } | |
4459 | if (aStatus != 1) | |
4460 | { | |
4461 | di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
4462 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
4463 | return 1; | |
dc3fe572 | 4464 | } |
4754e164 | 4465 | aView->SetZClippingType(aZClippingMode); |
4466 | } | |
4467 | if(argc >2) | |
4468 | { | |
4469 | Quantity_Length aDepth = 0., aWidth = 1.; | |
4470 | if(argc == 3) | |
4471 | { | |
4472 | aDepth = atof(argv[1]); | |
4473 | aWidth = atof(argv[2]); | |
4474 | } | |
4475 | else if(argc == 4) | |
4476 | { | |
4477 | aDepth = atof(argv[2]); | |
4478 | aWidth = atof(argv[3]); | |
4479 | } | |
dc3fe572 | 4480 | |
4754e164 | 4481 | if(aDepth<0. || aDepth>1.) |
4482 | { | |
4483 | di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
4484 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
4485 | return 1; | |
4486 | } | |
4487 | if(aWidth<0. || aWidth>1.) | |
4488 | { | |
4489 | di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
4490 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
4491 | return 1; | |
4492 | } | |
4493 | ||
4494 | aView->SetZClippingDepth(aDepth); | |
4495 | aView->SetZClippingWidth(aWidth); | |
4496 | } | |
4497 | aView->Redraw(); | |
4498 | } | |
4499 | return 0; | |
4500 | } | |
4501 | ||
4502 | //======================================================================= | |
4503 | //function : VNbSelected | |
dc3fe572 | 4504 | //purpose : Returns number of selected objects |
4754e164 | 4505 | //======================================================================= |
4506 | static Standard_Integer VNbSelected (Draw_Interpretor& di, | |
4507 | Standard_Integer argc, | |
4508 | const char ** argv) | |
4509 | { | |
4510 | if(argc != 1) | |
4511 | { | |
4512 | di << "Usage : " << argv[0] << "\n"; | |
4513 | return 1; | |
4514 | } | |
4515 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4516 | if(aContext.IsNull()) | |
4517 | { | |
4518 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4519 | return 1; | |
4520 | } | |
4521 | di << aContext->NbSelected() << "\n"; | |
4522 | return 0; | |
4523 | } | |
4524 | ||
4525 | //======================================================================= | |
4526 | //function : VAntialiasing | |
dc3fe572 | 4527 | //purpose : Switches altialiasing on or off |
4754e164 | 4528 | //======================================================================= |
4529 | static Standard_Integer VAntialiasing (Draw_Interpretor& di, | |
4530 | Standard_Integer argc, | |
4531 | const char ** argv) | |
4532 | { | |
4533 | if(argc > 2) | |
4534 | { | |
4535 | di << "Usage : " << argv[0] << " [1|0]" << "\n"; | |
4536 | return 1; | |
4537 | } | |
4538 | ||
4539 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4540 | if(aContext.IsNull()) | |
4541 | { | |
4542 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4543 | return 1; | |
4544 | } | |
4545 | ||
4546 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4547 | ||
4548 | if((argc == 2) && (atof(argv[1]) == 0)) | |
4549 | aView->SetAntialiasingOff(); | |
4550 | else | |
4551 | aView->SetAntialiasingOn(); | |
4552 | aView->Update(); | |
4553 | return 0; | |
4554 | } | |
4555 | ||
4556 | //======================================================================= | |
4557 | //function : VPurgeDisplay | |
dc3fe572 | 4558 | //purpose : Switches altialiasing on or off |
4754e164 | 4559 | //======================================================================= |
4560 | static Standard_Integer VPurgeDisplay (Draw_Interpretor& di, | |
4561 | Standard_Integer argc, | |
4562 | const char ** argv) | |
4563 | { | |
eb4320f2 | 4564 | if (argc > 1) |
4754e164 | 4565 | { |
eb4320f2 | 4566 | di << "Usage : " << argv[0] << "\n"; |
4754e164 | 4567 | return 1; |
4568 | } | |
4754e164 | 4569 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
4570 | if (aContext.IsNull()) | |
4571 | { | |
4572 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4573 | return 1; | |
4574 | } | |
4575 | aContext->CloseAllContexts(Standard_False); | |
eb4320f2 | 4576 | di << aContext->PurgeDisplay() << "\n"; |
4754e164 | 4577 | return 0; |
4578 | } | |
4579 | ||
4580 | //======================================================================= | |
4581 | //function : VSetViewSize | |
4582 | //purpose : | |
4583 | //======================================================================= | |
4584 | static Standard_Integer VSetViewSize (Draw_Interpretor& di, | |
4585 | Standard_Integer argc, | |
4586 | const char ** argv) | |
4587 | { | |
4588 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4589 | if(aContext.IsNull()) | |
4590 | { | |
4591 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4592 | return 1; | |
4593 | } | |
4594 | if(argc != 2) | |
4595 | { | |
4596 | di<<"Usage : " << argv[0] << " Size\n"; | |
4597 | return 1; | |
4598 | } | |
4599 | Standard_Real aSize = atof(argv[1]); | |
4600 | if (aSize <= 0.) | |
4601 | { | |
4602 | di<<"Bad Size value : " << aSize << "\n"; | |
4603 | return 1; | |
4604 | } | |
4605 | ||
4606 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4607 | aView->SetSize(aSize); | |
4608 | return 0; | |
4609 | } | |
4610 | ||
4611 | //======================================================================= | |
4612 | //function : VMoveView | |
4613 | //purpose : | |
4614 | //======================================================================= | |
4615 | static Standard_Integer VMoveView (Draw_Interpretor& di, | |
4616 | Standard_Integer argc, | |
4617 | const char ** argv) | |
4618 | { | |
4619 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4620 | if(aContext.IsNull()) | |
4621 | { | |
4622 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4623 | return 1; | |
4624 | } | |
4625 | if(argc < 4 || argc > 5) | |
4626 | { | |
4627 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
4628 | return 1; | |
4629 | } | |
4630 | Standard_Real Dx = atof(argv[1]); | |
4631 | Standard_Real Dy = atof(argv[2]); | |
4632 | Standard_Real Dz = atof(argv[3]); | |
4633 | Standard_Boolean aStart = Standard_True; | |
4634 | if (argc == 5) | |
4635 | { | |
4636 | aStart = (atoi(argv[4]) > 0); | |
4637 | } | |
4638 | ||
4639 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4640 | aView->Move(Dx,Dy,Dz,aStart); | |
4641 | return 0; | |
4642 | } | |
4643 | ||
4644 | //======================================================================= | |
4645 | //function : VTranslateView | |
4646 | //purpose : | |
4647 | //======================================================================= | |
4648 | static Standard_Integer VTranslateView (Draw_Interpretor& di, | |
4649 | Standard_Integer argc, | |
4650 | const char ** argv) | |
4651 | { | |
4652 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4653 | if(aContext.IsNull()) | |
4654 | { | |
4655 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4656 | return 1; | |
4657 | } | |
4658 | if(argc < 4 || argc > 5) | |
4659 | { | |
4660 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
4661 | return 1; | |
4662 | } | |
4663 | Standard_Real Dx = atof(argv[1]); | |
4664 | Standard_Real Dy = atof(argv[2]); | |
4665 | Standard_Real Dz = atof(argv[3]); | |
4666 | Standard_Boolean aStart = Standard_True; | |
dc3fe572 | 4667 | if (argc == 5) |
4754e164 | 4668 | { |
4669 | aStart = (atoi(argv[4]) > 0); | |
4670 | } | |
4671 | ||
4672 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4673 | aView->Translate(Dx,Dy,Dz,aStart); | |
4674 | return 0; | |
4675 | } | |
4676 | ||
4677 | //======================================================================= | |
4678 | //function : VTurnView | |
4679 | //purpose : | |
4680 | //======================================================================= | |
4681 | static Standard_Integer VTurnView (Draw_Interpretor& di, | |
4682 | Standard_Integer argc, | |
4683 | const char ** argv) | |
4684 | { | |
4685 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4686 | if(aContext.IsNull()) { | |
4687 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4688 | return 1; | |
4689 | } | |
4690 | if(argc < 4 || argc > 5){ | |
4691 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n"; | |
4692 | return 1; | |
4693 | } | |
4694 | Standard_Real Ax = atof(argv[1]); | |
4695 | Standard_Real Ay = atof(argv[2]); | |
4696 | Standard_Real Az = atof(argv[3]); | |
4697 | Standard_Boolean aStart = Standard_True; | |
dc3fe572 | 4698 | if (argc == 5) |
4754e164 | 4699 | { |
4700 | aStart = (atoi(argv[4]) > 0); | |
4701 | } | |
4702 | ||
4703 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4704 | aView->Turn(Ax,Ay,Az,aStart); | |
4705 | return 0; | |
4706 | } | |
4707 | ||
269294d6 | 4708 | //============================================================================== |
4709 | //function : VTextureEnv | |
4710 | //purpose : ENables or disables environment mapping | |
4711 | //============================================================================== | |
4712 | class OCC_TextureEnv : public Graphic3d_TextureEnv | |
4713 | { | |
4714 | public: | |
4715 | OCC_TextureEnv(const Standard_CString FileName); | |
4716 | OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName); | |
4717 | void SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
4718 | const Standard_Boolean theModulateFlag, | |
4719 | const Graphic3d_TypeOfTextureFilter theFilter, | |
4720 | const Standard_ShortReal theXScale, | |
4721 | const Standard_ShortReal theYScale, | |
4722 | const Standard_ShortReal theXShift, | |
4723 | const Standard_ShortReal theYShift, | |
4724 | const Standard_ShortReal theAngle); | |
4725 | DEFINE_STANDARD_RTTI(OCC_TextureEnv); | |
4726 | }; | |
4727 | DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv); | |
4728 | IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv); | |
4729 | IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv); | |
4730 | ||
4731 | OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName) | |
4732 | : Graphic3d_TextureEnv(theFileName) | |
4733 | { | |
4734 | } | |
4735 | ||
4736 | OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId) | |
4737 | : Graphic3d_TextureEnv(theTexId) | |
4738 | { | |
4739 | } | |
4740 | ||
4741 | void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
4742 | const Standard_Boolean theModulateFlag, | |
4743 | const Graphic3d_TypeOfTextureFilter theFilter, | |
4744 | const Standard_ShortReal theXScale, | |
4745 | const Standard_ShortReal theYScale, | |
4746 | const Standard_ShortReal theXShift, | |
4747 | const Standard_ShortReal theYShift, | |
4748 | const Standard_ShortReal theAngle) | |
4749 | { | |
4750 | myParams->SetRepeat (theRepeatFlag); | |
4751 | myParams->SetModulate (theModulateFlag); | |
4752 | myParams->SetFilter (theFilter); | |
4753 | myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale)); | |
4754 | myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift)); | |
4755 | myParams->SetRotation (theAngle); | |
4756 | } | |
4757 | ||
35e08fe8 | 4758 | static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec) |
269294d6 | 4759 | { |
4760 | // get the active view | |
4761 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4762 | if (aView.IsNull()) | |
4763 | { | |
4764 | std::cerr << "No active view. Please call vinit.\n"; | |
4765 | return 1; | |
4766 | } | |
4767 | ||
4768 | // Checking the input arguments | |
4769 | Standard_Boolean anEnableFlag = Standard_False; | |
4770 | Standard_Boolean isOk = theArgNb >= 2; | |
4771 | if (isOk) | |
4772 | { | |
4773 | TCollection_AsciiString anEnableOpt(theArgVec[1]); | |
4774 | anEnableFlag = anEnableOpt.IsEqual("on"); | |
4775 | isOk = anEnableFlag || anEnableOpt.IsEqual("off"); | |
4776 | } | |
4777 | if (anEnableFlag) | |
4778 | { | |
4779 | isOk = (theArgNb == 3 || theArgNb == 11); | |
4780 | if (isOk) | |
4781 | { | |
4782 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
4783 | isOk = (!aTextureOpt.IsIntegerValue() || | |
4784 | (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN)); | |
4785 | ||
4786 | if (isOk && theArgNb == 11) | |
4787 | { | |
4788 | TCollection_AsciiString aRepeatOpt (theArgVec[3]), | |
4789 | aModulateOpt(theArgVec[4]), | |
4790 | aFilterOpt (theArgVec[5]), | |
4791 | aSScaleOpt (theArgVec[6]), | |
4792 | aTScaleOpt (theArgVec[7]), | |
4793 | aSTransOpt (theArgVec[8]), | |
4794 | aTTransOpt (theArgVec[9]), | |
4795 | anAngleOpt (theArgVec[10]); | |
4796 | isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) && | |
4797 | (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) && | |
4798 | (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) && | |
4799 | aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() && | |
4800 | aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() && | |
4801 | anAngleOpt.IsRealValue()); | |
4802 | } | |
4803 | } | |
4804 | } | |
4805 | ||
4806 | if (!isOk) | |
4807 | { | |
4808 | std::cerr << "Usage :" << std::endl; | |
4809 | std::cerr << theArgVec[0] << " off" << std::endl; | |
4810 | 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; | |
4811 | return 1; | |
4812 | } | |
4813 | ||
4814 | if (anEnableFlag) | |
4815 | { | |
4816 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
4817 | Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ? | |
4818 | new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) : | |
4819 | new OCC_TextureEnv(theArgVec[2]); | |
4820 | ||
4821 | if (theArgNb == 11) | |
4822 | { | |
4823 | TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]); | |
4824 | aTexEnv->SetTextureParameters( | |
4825 | aRepeatOpt. IsEqual("repeat"), | |
4826 | aModulateOpt.IsEqual("modulate"), | |
4827 | aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST : | |
4828 | aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR : | |
4829 | Graphic3d_TOTF_TRILINEAR, | |
4830 | (Standard_ShortReal)Draw::Atof(theArgVec[6]), | |
4831 | (Standard_ShortReal)Draw::Atof(theArgVec[7]), | |
4832 | (Standard_ShortReal)Draw::Atof(theArgVec[8]), | |
4833 | (Standard_ShortReal)Draw::Atof(theArgVec[9]), | |
4834 | (Standard_ShortReal)Draw::Atof(theArgVec[10]) | |
4835 | ); | |
4836 | } | |
4837 | aView->SetTextureEnv(aTexEnv); | |
4838 | aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT); | |
4839 | } | |
4840 | else // Disabling environment mapping | |
4841 | { | |
4842 | aView->SetSurfaceDetail(V3d_TEX_NONE); | |
4843 | Handle(Graphic3d_TextureEnv) aTexture; | |
4844 | aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data | |
4845 | } | |
4846 | ||
4847 | aView->Redraw(); | |
4848 | return 0; | |
4849 | } | |
4850 | ||
4269bd1b | 4851 | //=============================================================================================== |
4852 | //function : VClipPlane | |
4853 | //purpose : | |
4854 | //=============================================================================================== | |
4855 | static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
4856 | { | |
4857 | // use short-cut for created clip planes map of created (or "registered by name") clip planes | |
4858 | typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes; | |
4859 | static MapOfPlanes aRegPlanes; | |
4860 | ||
4861 | if (theArgsNb < 2) | |
4862 | { | |
4863 | theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n"; | |
4864 | return 1; | |
4865 | } | |
4866 | ||
4867 | TCollection_AsciiString aCommand (theArgVec[1]); | |
4868 | ||
4869 | // print maximum number of planes for current viewer | |
4870 | if (aCommand == "maxplanes") | |
4871 | { | |
4872 | if (theArgsNb < 3) | |
4873 | { | |
4874 | theDi << theArgVec[0] << ": view name is required. Type help for more information.\n"; | |
4875 | return 1; | |
4876 | } | |
4877 | ||
4878 | TCollection_AsciiString aViewName (theArgVec[2]); | |
4879 | ||
4880 | if (!ViewerTest_myViews.IsBound1 (aViewName)) | |
4881 | { | |
4882 | theDi << theArgVec[0] << ": view is not found.\n"; | |
4883 | return 1; | |
4884 | } | |
4885 | ||
4886 | const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName); | |
4887 | ||
4888 | theDi << theArgVec[0] << ": " | |
4889 | << aView->Viewer()->Driver()->InquirePlaneLimit() | |
4890 | << " plane slots provided by driver." | |
4891 | << " Note that 2 more planes might be used (reserved for z-clipping).\n"; | |
4892 | ||
4893 | return 0; | |
4894 | } | |
4895 | ||
4896 | // create / delete plane instance | |
4897 | if (aCommand == "create" || aCommand == "delete" || aCommand == "clone") | |
4898 | { | |
4899 | if (theArgsNb < 3) | |
4900 | { | |
4901 | theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n"; | |
4902 | return 1; | |
4903 | } | |
4904 | ||
4905 | Standard_Boolean toCreate = (aCommand == "create"); | |
4906 | Standard_Boolean toClone = (aCommand == "clone"); | |
4907 | TCollection_AsciiString aPlane (theArgVec[2]); | |
4908 | ||
4909 | if (toCreate) | |
4910 | { | |
4911 | if (aRegPlanes.IsBound (aPlane)) | |
4912 | { | |
4913 | theDi << theArgVec[0] << ": plane name is in use.\n"; | |
4914 | return 1; | |
4915 | } | |
4916 | ||
4917 | aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane()); | |
4918 | } | |
4919 | else if (toClone) // toClone | |
4920 | { | |
4921 | if (!aRegPlanes.IsBound (aPlane)) | |
4922 | { | |
4923 | theDi << theArgVec[0] << ": no such plane.\n"; | |
4924 | return 1; | |
4925 | } | |
4926 | ||
4927 | if (theArgsNb < 4) | |
4928 | { | |
4929 | theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n"; | |
4930 | return 1; | |
4931 | } | |
4932 | ||
4933 | TCollection_AsciiString aClone (theArgVec[3]); | |
4934 | if (aRegPlanes.IsBound (aClone)) | |
4935 | { | |
4936 | theDi << theArgVec[0] << ": plane name is in use.\n"; | |
4937 | return 1; | |
4938 | } | |
4939 | ||
4940 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
4941 | ||
4942 | aRegPlanes.Bind (aClone, aClipPlane->Clone()); | |
4943 | } | |
4944 | else// toDelete | |
4945 | { | |
4946 | if (!aRegPlanes.IsBound (aPlane)) | |
4947 | { | |
4948 | theDi << theArgVec[0] << ": no such plane.\n"; | |
4949 | return 1; | |
4950 | } | |
4951 | ||
4952 | Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane); | |
4953 | aRegPlanes.UnBind (aPlane); | |
4954 | ||
4955 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS()); | |
4956 | for (; anIObjIt.More(); anIObjIt.Next()) | |
4957 | { | |
4958 | Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1()); | |
4959 | aPrs->RemoveClipPlane(aClipPlane); | |
4960 | } | |
4961 | ||
4962 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
4963 | for (; aViewIt.More(); aViewIt.Next()) | |
4964 | { | |
4965 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
4966 | aView->RemoveClipPlane(aClipPlane); | |
4967 | } | |
4968 | ||
4969 | ViewerTest::RedrawAllViews(); | |
4970 | } | |
4971 | ||
4972 | return 0; | |
4973 | } | |
4974 | ||
4975 | // set / unset plane command | |
4976 | if (aCommand == "set" || aCommand == "unset") | |
4977 | { | |
4978 | if (theArgsNb < 4) | |
4979 | { | |
4980 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
4981 | return 1; | |
4982 | } | |
4983 | ||
4984 | Standard_Boolean toSet = (aCommand == "set"); | |
4985 | TCollection_AsciiString aPlane (theArgVec [2]); | |
4986 | if (!aRegPlanes.IsBound (aPlane)) | |
4987 | { | |
4988 | theDi << theArgVec[0] << ": no such plane.\n"; | |
4989 | return 1; | |
4990 | } | |
4991 | ||
4992 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
4993 | ||
4994 | TCollection_AsciiString aTarget (theArgVec [3]); | |
4995 | if (aTarget != "object" && aTarget != "view") | |
4996 | { | |
4997 | theDi << theArgVec[0] << ": invalid target.\n"; | |
4998 | return 1; | |
4999 | } | |
5000 | ||
5001 | if (aTarget == "object" || aTarget == "view") | |
5002 | { | |
5003 | if (theArgsNb < 5) | |
5004 | { | |
5005 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5006 | return 1; | |
5007 | } | |
5008 | ||
5009 | Standard_Boolean isObject = (aTarget == "object"); | |
5010 | ||
5011 | for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt) | |
5012 | { | |
5013 | TCollection_AsciiString anEntityName (theArgVec[anIt]); | |
5014 | if (isObject) // to object | |
5015 | { | |
5016 | if (!GetMapOfAIS().IsBound2 (anEntityName)) | |
5017 | { | |
5018 | theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n"; | |
5019 | continue; | |
5020 | } | |
5021 | ||
5022 | Handle(AIS_InteractiveObject) aIObj = | |
5023 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName)); | |
5024 | ||
5025 | if (toSet) | |
5026 | aIObj->AddClipPlane (aClipPlane); | |
5027 | else | |
5028 | aIObj->RemoveClipPlane (aClipPlane); | |
5029 | } | |
5030 | else // to view | |
5031 | { | |
5032 | if (!ViewerTest_myViews.IsBound1 (anEntityName)) | |
5033 | { | |
5034 | theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n"; | |
5035 | continue; | |
5036 | } | |
5037 | ||
5038 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName); | |
5039 | if (toSet) | |
5040 | aView->AddClipPlane (aClipPlane); | |
5041 | else | |
5042 | aView->RemoveClipPlane (aClipPlane); | |
5043 | } | |
5044 | } | |
5045 | ||
5046 | ViewerTest::RedrawAllViews(); | |
5047 | } | |
5048 | ||
5049 | return 0; | |
5050 | } | |
5051 | ||
5052 | // change plane command | |
5053 | if (aCommand == "change") | |
5054 | { | |
5055 | if (theArgsNb < 4) | |
5056 | { | |
5057 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5058 | return 1; | |
5059 | } | |
5060 | ||
5061 | TCollection_AsciiString aPlane (theArgVec [2]); | |
5062 | if (!aRegPlanes.IsBound (aPlane)) | |
5063 | { | |
5064 | theDi << theArgVec[0] << ": no such plane.\n"; | |
5065 | return 1; | |
5066 | } | |
5067 | ||
5068 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
5069 | ||
5070 | TCollection_AsciiString aChangeArg (theArgVec [3]); | |
5071 | if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation") | |
5072 | { | |
5073 | theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n"; | |
5074 | return 1; | |
5075 | } | |
5076 | ||
5077 | if (aChangeArg == "on" || aChangeArg == "off") // on / off | |
5078 | { | |
5079 | aClipPlane->SetOn (aChangeArg == "on"); | |
5080 | } | |
5081 | else if (aChangeArg == "equation") // change equation | |
5082 | { | |
5083 | if (theArgsNb < 8) | |
5084 | { | |
5085 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5086 | return 1; | |
5087 | } | |
5088 | ||
5089 | Standard_Real aCoeffA = atof (theArgVec [4]); | |
5090 | Standard_Real aCoeffB = atof (theArgVec [5]); | |
5091 | Standard_Real aCoeffC = atof (theArgVec [6]); | |
5092 | Standard_Real aCoeffD = atof (theArgVec [7]); | |
5093 | aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD)); | |
5094 | } | |
5095 | else if (aChangeArg == "capping") // change capping aspects | |
5096 | { | |
5097 | if (theArgsNb < 5) | |
5098 | { | |
5099 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5100 | return 1; | |
5101 | } | |
5102 | ||
5103 | TCollection_AsciiString aCappingArg (theArgVec [4]); | |
5104 | if (aCappingArg != "on" && aCappingArg != "off" && | |
5105 | aCappingArg != "color" && aCappingArg != "texname" && | |
5106 | aCappingArg != "texscale" && aCappingArg != "texorigin" && | |
5107 | aCappingArg != "texrotate" && aCappingArg != "hatch") | |
5108 | { | |
5109 | theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n"; | |
5110 | return 1; | |
5111 | } | |
5112 | ||
5113 | if (aCappingArg == "on" || aCappingArg == "off") // on / off capping | |
5114 | { | |
5115 | aClipPlane->SetCapping (aCappingArg == "on"); | |
5116 | } | |
5117 | else if (aCappingArg == "color") // color aspect for capping | |
5118 | { | |
5119 | if (theArgsNb < 8) | |
5120 | { | |
5121 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5122 | return 1; | |
5123 | } | |
5124 | ||
5125 | Standard_Real aRed = atof (theArgVec [5]); | |
5126 | Standard_Real aGrn = atof (theArgVec [6]); | |
5127 | Standard_Real aBlu = atof (theArgVec [7]); | |
5128 | ||
5129 | Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); | |
5130 | aMat.SetColor (Quantity_Color (aRed, aGrn, aBlu, Quantity_TOC_RGB)); | |
5131 | aClipPlane->SetCappingMaterial (aMat); | |
5132 | } | |
5133 | else if (aCappingArg == "texname") // texture name | |
5134 | { | |
5135 | if (theArgsNb < 6) | |
5136 | { | |
5137 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5138 | return 1; | |
5139 | } | |
5140 | ||
5141 | TCollection_AsciiString aTextureName (theArgVec [5]); | |
5142 | ||
5143 | Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); | |
5144 | if (!aTexture->IsDone ()) | |
5145 | { | |
5146 | aClipPlane->SetCappingTexture (NULL); | |
5147 | } | |
5148 | else | |
5149 | { | |
5150 | aTexture->EnableModulate(); | |
5151 | aTexture->EnableRepeat(); | |
5152 | aClipPlane->SetCappingTexture (aTexture); | |
5153 | } | |
5154 | } | |
5155 | else if (aCappingArg == "texscale") // texture scale | |
5156 | { | |
5157 | if (aClipPlane->CappingTexture().IsNull()) | |
5158 | { | |
5159 | theDi << theArgVec[0] << ": no texture is set.\n"; | |
5160 | return 1; | |
5161 | } | |
5162 | ||
5163 | if (theArgsNb < 7) | |
5164 | { | |
5165 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5166 | return 1; | |
5167 | } | |
5168 | ||
5169 | Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]); | |
5170 | Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]); | |
5171 | ||
5172 | aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); | |
5173 | } | |
5174 | else if (aCappingArg == "texorigin") // texture origin | |
5175 | { | |
5176 | if (aClipPlane->CappingTexture().IsNull()) | |
5177 | { | |
5178 | theDi << theArgVec[0] << ": no texture is set.\n"; | |
5179 | return 1; | |
5180 | } | |
5181 | ||
5182 | if (theArgsNb < 7) | |
5183 | { | |
5184 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5185 | return 1; | |
5186 | } | |
5187 | ||
5188 | Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]); | |
5189 | Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]); | |
5190 | ||
5191 | aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); | |
5192 | } | |
5193 | else if (aCappingArg == "texrotate") // texture rotation | |
5194 | { | |
5195 | if (aClipPlane->CappingTexture().IsNull()) | |
5196 | { | |
5197 | theDi << theArgVec[0] << ": no texture is set.\n"; | |
5198 | return 1; | |
5199 | } | |
5200 | ||
5201 | if (theArgsNb < 6) | |
5202 | { | |
5203 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5204 | return 1; | |
5205 | } | |
5206 | ||
5207 | Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]); | |
5208 | ||
5209 | aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot); | |
5210 | } | |
5211 | else if (aCappingArg == "hatch") // hatch style | |
5212 | { | |
5213 | if (theArgsNb < 6) | |
5214 | { | |
5215 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
5216 | return 1; | |
5217 | } | |
5218 | ||
5219 | TCollection_AsciiString aHatchStr (theArgVec [5]); | |
5220 | if (aHatchStr == "on") | |
5221 | { | |
5222 | aClipPlane->SetCappingHatchOn(); | |
5223 | } | |
5224 | else if (aHatchStr == "off") | |
5225 | { | |
5226 | aClipPlane->SetCappingHatchOff(); | |
5227 | } | |
5228 | else | |
5229 | { | |
5230 | aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5])); | |
5231 | } | |
5232 | } | |
5233 | } | |
5234 | ||
5235 | ViewerTest::RedrawAllViews(); | |
5236 | ||
5237 | return 0; | |
5238 | } | |
5239 | ||
5240 | theDi << theArgVec[0] << ": invalid command. Type help for more information.\n"; | |
5241 | return 1; | |
5242 | } | |
5243 | ||
5244 | //=============================================================================================== | |
5245 | //function : VSetTextureMode | |
5246 | //purpose : | |
5247 | //=============================================================================================== | |
5248 | static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
5249 | { | |
5250 | if (theArgsNb < 3) | |
5251 | { | |
5252 | theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n"; | |
5253 | return 1; | |
5254 | } | |
5255 | ||
5256 | TCollection_AsciiString aViewName (theArgVec[1]); | |
5257 | if (!ViewerTest_myViews.IsBound1 (aViewName)) | |
5258 | { | |
5259 | theDi << theArgVec[0] << ": view is not found.\n"; | |
5260 | return 1; | |
5261 | } | |
5262 | ||
5263 | const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName); | |
5264 | switch (atoi (theArgVec[2])) | |
5265 | { | |
5266 | case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break; | |
5267 | case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break; | |
5268 | case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break; | |
5269 | default: | |
5270 | theDi << theArgVec[0] << ": invalid mode.\n"; | |
5271 | return 1; | |
5272 | } | |
5273 | ||
5274 | aView->Redraw(); | |
5275 | return 0; | |
5276 | } | |
5277 | ||
392ac980 | 5278 | //=============================================================================================== |
5279 | //function : VDefaults | |
5280 | //purpose : | |
5281 | //=============================================================================================== | |
5282 | static int VDefaults (Draw_Interpretor& theDi, | |
5283 | Standard_Integer theArgsNb, | |
5284 | const char** theArgVec) | |
5285 | { | |
5286 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
5287 | if (aCtx.IsNull()) | |
5288 | { | |
5289 | std::cerr << "No active viewer!\n"; | |
5290 | return 1; | |
5291 | } | |
5292 | ||
5293 | Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer(); | |
5294 | if (theArgsNb < 2) | |
5295 | { | |
5296 | if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE) | |
5297 | { | |
5298 | theDi << "DeflType: relative\n" | |
5299 | << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n"; | |
5300 | } | |
5301 | else | |
5302 | { | |
5303 | theDi << "DeflType: absolute\n" | |
5304 | << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n"; | |
5305 | } | |
5306 | theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n"; | |
5307 | return 0; | |
5308 | } | |
5309 | ||
5310 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
5311 | { | |
5312 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
5313 | TCollection_AsciiString aKey, aValue; | |
5314 | if (!splitParameter (anArg, aKey, aValue) | |
5315 | || aValue.IsEmpty()) | |
5316 | { | |
5317 | std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n"; | |
5318 | return 1; | |
5319 | } | |
5320 | ||
5321 | aKey.UpperCase(); | |
5322 | if (aKey == "ABSDEFL" | |
5323 | || aKey == "ABSOLUTEDEFLECTION" | |
5324 | || aKey == "DEFL" | |
5325 | || aKey == "DEFLECTION") | |
5326 | { | |
5327 | aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE); | |
5328 | aDefParams->SetMaximalChordialDeviation (aValue.RealValue()); | |
5329 | } | |
5330 | else if (aKey == "RELDEFL" | |
5331 | || aKey == "RELATIVEDEFLECTION" | |
5332 | || aKey == "DEVCOEFF" | |
5333 | || aKey == "DEVIATIONCOEFF" | |
5334 | || aKey == "DEVIATIONCOEFFICIENT") | |
5335 | { | |
5336 | aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE); | |
5337 | aDefParams->SetDeviationCoefficient (aValue.RealValue()); | |
5338 | } | |
5339 | else if (aKey == "ANGDEFL" | |
5340 | || aKey == "ANGULARDEFL" | |
5341 | || aKey == "ANGULARDEFLECTION") | |
5342 | { | |
5343 | // currently HLRDeviationAngle is used instead of DeviationAngle in most places | |
5344 | aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0); | |
5345 | } | |
5346 | else | |
5347 | { | |
5348 | std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n"; | |
5349 | } | |
5350 | } | |
5351 | ||
5352 | return 0; | |
5353 | } | |
5354 | ||
e276548b | 5355 | //============================================================================== |
5356 | //function : VClInfo | |
5357 | //purpose : Prints info about active OpenCL device | |
5358 | //============================================================================== | |
5359 | ||
7ae4a307 | 5360 | static Standard_Integer VClInfo (Draw_Interpretor& theDi, |
e276548b | 5361 | Standard_Integer, |
5362 | const char**) | |
5363 | { | |
e276548b | 5364 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); |
e276548b | 5365 | if (aContextAIS.IsNull()) |
5366 | { | |
7ae4a307 | 5367 | std::cerr << "Call vinit before!\n"; |
e276548b | 5368 | return 1; |
5369 | } | |
5370 | ||
5371 | Handle(OpenGl_GraphicDriver) aDrv = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver()); | |
7ae4a307 | 5372 | Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView()); |
e276548b | 5373 | NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> anInfo; |
7ae4a307 | 5374 | if (aDrv.IsNull() |
5375 | || aCView == NULL | |
5376 | || !aDrv->GetOpenClDeviceInfo (*aCView, anInfo)) | |
e276548b | 5377 | { |
7ae4a307 | 5378 | theDi << "OpenCL device info is unavailable!\n"; |
e276548b | 5379 | return 0; |
5380 | } | |
e276548b | 5381 | |
7ae4a307 | 5382 | theDi << "OpenCL device info:\n"; |
5383 | for (NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>::Iterator anIter (anInfo); | |
5384 | anIter.More(); anIter.Next()) | |
e276548b | 5385 | { |
7ae4a307 | 5386 | theDi << anIter.Key() << ": \t" << anIter.Value() << "\n"; |
e276548b | 5387 | } |
e276548b | 5388 | return 0; |
5389 | } | |
5390 | ||
5391 | //======================================================================= | |
5392 | //function : VRaytrace | |
5393 | //purpose : Enables/disables OpenCL-based ray-tracing | |
5394 | //======================================================================= | |
5395 | ||
7ae4a307 | 5396 | static Standard_Integer VRaytrace (Draw_Interpretor& , |
5397 | Standard_Integer theArgNb, | |
5398 | const char** theArgVec) | |
e276548b | 5399 | { |
7ae4a307 | 5400 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
5401 | if (aView.IsNull()) | |
e276548b | 5402 | { |
5403 | std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n"; | |
5404 | return 1; | |
5405 | } | |
5406 | ||
7ae4a307 | 5407 | if (theArgNb < 2 |
5408 | || Draw::Atoi (theArgVec[1])) | |
e276548b | 5409 | { |
e276548b | 5410 | aView->SetRaytracingMode(); |
7ae4a307 | 5411 | } |
e276548b | 5412 | else |
7ae4a307 | 5413 | { |
e276548b | 5414 | aView->SetRasterizationMode(); |
7ae4a307 | 5415 | } |
e276548b | 5416 | aView->Redraw(); |
e276548b | 5417 | return 0; |
5418 | } | |
5419 | ||
e276548b | 5420 | //======================================================================= |
5421 | //function : VSetRaytraceMode | |
5422 | //purpose : Enables/disables features of OpenCL-based ray-tracing | |
5423 | //======================================================================= | |
5424 | ||
e276548b | 5425 | static Standard_Integer VSetRaytraceMode (Draw_Interpretor&, |
5426 | Standard_Integer theArgNb, | |
5427 | const char ** theArgVec) | |
5428 | { | |
7ae4a307 | 5429 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
5430 | if (aView.IsNull()) | |
e276548b | 5431 | { |
5432 | std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n"; | |
5433 | return 1; | |
5434 | } | |
7ae4a307 | 5435 | else if (theArgNb < 2) |
e276548b | 5436 | { |
5437 | std::cerr << "Usage : " << theArgVec[0] << " [shad=0|1] [refl=0|1] [aa=0|1]\n"; | |
5438 | return 1; | |
5439 | } | |
5440 | ||
e276548b | 5441 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
5442 | { | |
5443 | const TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
5444 | ||
5445 | if (anArg.Search ("shad=") > -1) | |
5446 | { | |
5447 | if (anArg.Token ("=", 2).IntegerValue() != 0) | |
5448 | aView->EnableRaytracedShadows(); | |
5449 | else | |
5450 | aView->DisableRaytracedShadows(); | |
5451 | } | |
5452 | else if (anArg.Search ("refl=") > -1) | |
5453 | { | |
5454 | if (anArg.Token ("=", 2).IntegerValue() != 0) | |
5455 | aView->EnableRaytracedReflections(); | |
5456 | else | |
5457 | aView->DisableRaytracedReflections(); | |
5458 | } | |
5459 | else if (anArg.Search ("aa=") > -1) | |
5460 | { | |
5461 | if (anArg.Token ("=", 2).IntegerValue() != 0) | |
5462 | aView->EnableRaytracedAntialiasing(); | |
5463 | else | |
5464 | aView->DisableRaytracedAntialiasing(); | |
5465 | } | |
5466 | else | |
5467 | { | |
5468 | std::cerr << "Unknown argument: " << anArg << "\n"; | |
5469 | } | |
5470 | } | |
5471 | ||
5472 | aView->Redraw(); | |
e276548b | 5473 | return 0; |
5474 | } | |
5475 | ||
7fd59977 | 5476 | //======================================================================= |
5477 | //function : ViewerCommands | |
5478 | //purpose : | |
5479 | //======================================================================= | |
5480 | ||
5481 | void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) | |
5482 | { | |
5483 | ||
5484 | const char *group = "ZeViewer"; | |
18d715bd | 5485 | theCommands.Add("vinit", |
5486 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
5487 | "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" | |
5488 | #else | |
5489 | "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" | |
5490 | #endif | |
5491 | " - Creates new View window with specified name view_name.\n" | |
5492 | "By default the new view is created in the viewer and in" | |
5493 | " graphic driver shared with active view.\n" | |
5494 | " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n" | |
5495 | "If driverName isn't specified the driver will be shared with active view.\n" | |
5496 | "If viewerName isn't specified the viewer will be shared with active view.\n" | |
5497 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
5498 | " - display = HostName.DisplayNumber[:ScreenNumber] : if specified" | |
5499 | "is used in creation of graphic driver\n" | |
5500 | #endif | |
5501 | " - l, t: pixel position of left top corner of the window\n" | |
5502 | " - w,h: width and heigth of window respectively.\n" | |
5503 | "Additional commands for operations with views: vclose, vactivate, vviewlist.\n", | |
7fd59977 | 5504 | __FILE__,VInit,group); |
18d715bd | 5505 | theCommands.Add("vclose" , |
d0cc1cb7 | 5506 | "[view_id [keep_context=0|1]]\n" |
18d715bd | 5507 | "or vclose ALL - to remove all created views\n" |
5508 | " - removes view(viewer window) defined by its view_id.\n" | |
5509 | " - keep_context: by default 0; if 1 and the last view is deleted" | |
5510 | " the current context is not removed.", | |
5511 | __FILE__,VClose,group); | |
5512 | theCommands.Add("vactivate" , | |
5513 | "view_id" | |
5514 | " - activates view(viewer window) defined by its view_id", | |
5515 | __FILE__,VActivate,group); | |
5516 | theCommands.Add("vviewlist", | |
5517 | "vviewlist [format={tree, long}]" | |
5518 | " - prints current list of views per viewer and graphic_driver ID shared between viewers" | |
5519 | " - format: format of result output, if tree the output is a tree view;" | |
5520 | "otherwise it's a list of full view names. By default format = tree", | |
5521 | __FILE__,VViewList,group); | |
7fd59977 | 5522 | theCommands.Add("vhelp" , |
5523 | "vhelp : display help on the viewer commands", | |
5524 | __FILE__,VHelp,group); | |
5525 | theCommands.Add("vtop" , | |
44b8f2d6 | 5526 | "vtop or <T> : Top view" , |
7fd59977 | 5527 | __FILE__,VTop,group); |
44b8f2d6 | 5528 | theCommands.Add("vbottom" , |
5529 | "vbottom : Bottom view" , | |
5530 | __FILE__,VBottom,group); | |
5531 | theCommands.Add("vleft" , | |
5532 | "vleft : Left view" , | |
5533 | __FILE__,VLeft,group); | |
5534 | theCommands.Add("vright" , | |
5535 | "vright : Right view" , | |
5536 | __FILE__,VRight,group); | |
7fd59977 | 5537 | theCommands.Add("vaxo" , |
5538 | " vaxo or <A> : Axonometric view ", | |
5539 | __FILE__,VAxo,group); | |
44b8f2d6 | 5540 | theCommands.Add("vfront" , |
5541 | "vfront : Front view" , | |
5542 | __FILE__,VFront,group); | |
5543 | theCommands.Add("vback" , | |
5544 | "vback : Back view" , | |
5545 | __FILE__,VBack,group); | |
7fd59977 | 5546 | theCommands.Add("vpick" , |
5547 | "vpick : vpick X Y Z [shape subshape] ( all variables as string )", | |
5548 | VPick,group); | |
5549 | theCommands.Add("vfit" , | |
5550 | "vfit or <F> : vfit", | |
5551 | __FILE__,VFit,group); | |
5552 | theCommands.Add("vzfit" , | |
5553 | "vzfit", | |
5554 | __FILE__,VZFit,group); | |
5555 | theCommands.Add("vrepaint", | |
5556 | "vrepaint : vrepaint, force redraw", | |
5557 | __FILE__,VRepaint,group); | |
5558 | theCommands.Add("vclear", | |
5559 | "vclear : vclear", | |
5560 | __FILE__,VClear,group); | |
5561 | theCommands.Add("vsetbg", | |
5562 | "vsetbg : vsetbg imagefile [filltype] : Load image as background", | |
5563 | __FILE__,VSetBg,group); | |
f8b2ed36 | 5564 | theCommands.Add("vsetbgmode", |
5565 | "vsetbgmode : vsetbgmode filltype : Change background image fill type", | |
5566 | __FILE__,VSetBgMode,group); | |
7fd59977 | 5567 | theCommands.Add("vsetgradientbg", |
f8b2ed36 | 5568 | "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background", |
7fd59977 | 5569 | __FILE__,VSetGradientBg,group); |
f8b2ed36 | 5570 | theCommands.Add("vsetgrbgmode", |
5571 | "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type", | |
5572 | __FILE__,VSetGradientBgMode,group); | |
5573 | theCommands.Add("vsetcolorbg", | |
5574 | "vsetcolorbg : vsetcolorbg r g b : Set background color", | |
5575 | __FILE__,VSetColorBg,group); | |
7fd59977 | 5576 | theCommands.Add("vscale", |
5577 | "vscale : vscale X Y Z", | |
5578 | __FILE__,VScale,group); | |
5579 | theCommands.Add("vzbufftrihedron", | |
7c8a8fcc | 5580 | "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper" |
5581 | " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]" | |
5582 | " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron", | |
7fd59977 | 5583 | __FILE__,VTestZBuffTrihedron,group); |
5584 | theCommands.Add("vrotate", | |
5585 | "vrotate : vrotate AX AY AZ [X Y Z]", | |
5586 | __FILE__,VRotate,group); | |
5587 | theCommands.Add("vzoom", | |
5588 | "vzoom : vzoom coef", | |
5589 | __FILE__,VZoom,group); | |
5590 | theCommands.Add("vpan", | |
5591 | "vpan : vpan dx dy", | |
5592 | __FILE__,VPan,group); | |
5593 | theCommands.Add("vexport", | |
5cedc27f K |
5594 | "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }" |
5595 | " : exports the view to a vector file of a given format" | |
5596 | " : notice that EMF format requires patched gl2ps", | |
7fd59977 | 5597 | __FILE__,VExport,group); |
5598 | theCommands.Add("vcolorscale", | |
5599 | "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale", | |
5600 | __FILE__,VColorScale,group); | |
5601 | theCommands.Add("vgraduatedtrihedron", | |
13a22457 | 5602 | "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]", |
7fd59977 | 5603 | __FILE__,VGraduatedTrihedron,group); |
7edf74fd A |
5604 | theCommands.Add("vprintview" , |
5605 | "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile", | |
5606 | __FILE__,VPrintView,group); | |
59f45b7c | 5607 | theCommands.Add("vzlayer", |
5608 | "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids", | |
5609 | __FILE__,VZLayer,group); | |
25289ec1 | 5610 | theCommands.Add("voverlaytext", |
5611 | "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]" | |
5612 | " : height - pixel height of the text (default=10.0)" | |
5613 | " : font_name - name of font (default=courier)" | |
5614 | " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) " | |
5615 | " : display_type = {normal/subtitle/decal/blend}, (default=normal) " | |
5616 | " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ", | |
5617 | __FILE__,VOverlayText,group); | |
20637bd2 | 5618 | theCommands.Add("vlayerline", |
5619 | "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]", | |
5620 | __FILE__,VLayerLine,group); | |
2bd4c032 | 5621 | theCommands.Add ("vgrid", |
5622 | "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]" | |
5623 | " : Mode - rectangular or circular" | |
5624 | " : Type - lines or points", | |
5625 | __FILE__, VGrid, group); | |
208e6839 | 5626 | theCommands.Add ("vfps", |
5627 | "vfps [framesNb=100] : estimate average frame rate for active view", | |
5628 | __FILE__, VFps, group); | |
58655684 | 5629 | theCommands.Add ("vgldebug", |
5630 | "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n" | |
5631 | " : this function is implemented only for Windows\n" | |
5632 | " : GL_ARB_debug_output extension should be exported by OpenGL driver!", | |
5633 | __FILE__, VGlDebug, group); | |
208e6839 | 5634 | theCommands.Add ("vvbo", |
58655684 | 5635 | "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects", |
208e6839 | 5636 | __FILE__, VVbo, group); |
a577aaab | 5637 | theCommands.Add ("vcaps", |
abe46077 | 5638 | "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options", |
a577aaab | 5639 | __FILE__, VCaps, group); |
f0430952 | 5640 | theCommands.Add ("vmemgpu", |
5641 | "vmemgpu [f]: print system-dependent GPU memory information if available;" | |
5642 | " with f option returns free memory in bytes", | |
5643 | __FILE__, VMemGpu, group); | |
85e096c3 | 5644 | theCommands.Add ("vreadpixel", |
5645 | "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]" | |
5646 | " : Read pixel value for active view", | |
5647 | __FILE__, VReadPixel, group); | |
692613e5 | 5648 | theCommands.Add("diffimage", |
5649 | "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]", | |
5650 | __FILE__, VDiffImage, group); | |
4754e164 | 5651 | theCommands.Add ("vselect", |
5652 | "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n" | |
5653 | "- emulates different types of selection:\n" | |
5654 | "- 1) single click selection\n" | |
5655 | "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n" | |
5656 | "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n" | |
5657 | "- 4) any of these selections with shift button pressed", | |
5658 | __FILE__, VSelect, group); | |
5659 | theCommands.Add ("vmoveto", | |
5660 | "vmoveto x y" | |
5661 | "- emulates cursor movement to pixel postion (x,y)", | |
5662 | __FILE__, VMoveTo, group); | |
5663 | theCommands.Add("vviewparams", | |
5664 | "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]" | |
5665 | "- gets or sets current view characteristics", | |
5666 | __FILE__,VViewParams, group); | |
5667 | theCommands.Add("vchangeselected", | |
dc3fe572 | 5668 | "vchangeselected shape" |
4754e164 | 5669 | "- adds to shape to selection or remove one from it", |
5670 | __FILE__, VChangeSelected, group); | |
5671 | theCommands.Add("vzclipping", | |
5672 | "vzclipping [mode] [depth width]\n" | |
5673 | "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n" | |
5674 | "- gets or sets ZClipping mode, width and depth", | |
5675 | __FILE__,VZClipping,group); | |
5676 | theCommands.Add ("vnbselected", | |
5677 | "vnbselected", __FILE__, VNbSelected, group); | |
5678 | theCommands.Add("vantialiasing", | |
5679 | "vantialiasing 1|0", | |
5680 | __FILE__,VAntialiasing,group); | |
5681 | theCommands.Add ("vpurgedisplay", | |
eb4320f2 | 5682 | "vpurgedisplay" |
4754e164 | 5683 | "- removes structures which don't belong to objects displayed in neutral point", |
5684 | __FILE__, VPurgeDisplay, group); | |
5685 | theCommands.Add("vsetviewsize", | |
5686 | "vsetviewsize size", | |
5687 | __FILE__,VSetViewSize,group); | |
5688 | theCommands.Add("vmoveview", | |
5689 | "vmoveview Dx Dy Dz [Start = 1|0]", | |
5690 | __FILE__,VMoveView,group); | |
5691 | theCommands.Add("vtranslateview", | |
5692 | "vtranslateview Dx Dy Dz [Start = 1|0)]", | |
5693 | __FILE__,VTranslateView,group); | |
5694 | theCommands.Add("vturnview", | |
5695 | "vturnview Ax Ay Az [Start = 1|0]", | |
5696 | __FILE__,VTurnView,group); | |
269294d6 | 5697 | theCommands.Add("vtextureenv", |
5698 | "Enables or disables environment mapping in the 3D view, loading the texture from the given standard " | |
5699 | "or user-defined file and optionally applying texture mapping parameters\n" | |
5700 | " Usage:\n" | |
5701 | " vtextureenv off - disables environment mapping\n" | |
5702 | " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n" | |
5703 | " std_texture = (0..7)\n" | |
5704 | " rep = {clamp|repeat}\n" | |
5705 | " mod = {decal|modulate}\n" | |
5706 | " flt = {nearest|bilinear|trilinear}\n" | |
5707 | " ss, st - scale factors for s and t texture coordinates\n" | |
5708 | " ts, tt - translation for s and t texture coordinates\n" | |
5709 | " rot - texture rotation angle in degrees", | |
5710 | __FILE__, VTextureEnv, group); | |
0a768f56 | 5711 | theCommands.Add("vhlr" , |
5712 | "is_enabled={on|off}" | |
5713 | " - Hidden line removal algorithm:" | |
5714 | " - is_enabled: if is on HLR algorithm is applied\n", | |
5715 | __FILE__,VHLR,group); | |
5716 | theCommands.Add("vhlrtype" , | |
5717 | "algo_type={algo|polyalgo} [shape_1 ... shape_n]" | |
5718 | " - Changes the type of HLR algorithm using for shapes." | |
5719 | " - algo_type: if equals to algo, exact HLR algorithm is applied;\n" | |
5720 | " if equals to polyalgo, polygonal HLR algorithm is applied." | |
5721 | "If shapes are not given HLR algoithm of given type is applied" | |
5722 | " to all shapes in the view\n", | |
5723 | __FILE__,VHLRType,group); | |
4269bd1b | 5724 | theCommands.Add("vclipplane", "vclipplane usage: \n" |
5725 | " maxplanes <view_name> - get plane limit for view.\n" | |
5726 | " create <plane_name> - create new plane.\n" | |
5727 | " delete <plane_name> - delete plane.\n" | |
5728 | " clone <source_plane> <plane_name> - clone the plane definition.\n" | |
5729 | " set/unset <plane_name> object <object list> - set/unset plane for IO.\n" | |
5730 | " set/unset <plane_name> view <view list> - set/unset plane for view.\n" | |
5731 | " change <plane_name> on/off - turn clipping on/off.\n" | |
5732 | " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n" | |
5733 | " change <plane_name> capping on/off - turn capping on/off.\n" | |
5734 | " change <plane_name> capping color <r> <g> <b> - set color.\n" | |
5735 | " change <plane name> capping texname <texture> - set texture.\n" | |
5736 | " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n" | |
5737 | " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n" | |
5738 | " change <plane_name> capping texrotate <angle> - set tex rotation.\n" | |
5739 | " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n" | |
5740 | " please use VSetTextureMode command to enable texture rendering in view.\n" | |
5741 | , __FILE__, VClipPlane, group); | |
5742 | theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n" | |
5743 | " mode can be:\n" | |
5744 | " 0 - no textures enabled in view.\n" | |
5745 | " 1 - only environment textures enabled.\n" | |
5746 | " 2 - all textures enabled.\n" | |
5747 | " this command sets texture details mode for the specified view.\n" | |
5748 | , __FILE__, VSetTextureMode, group); | |
392ac980 | 5749 | theCommands.Add("vdefaults", |
5750 | "vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]", | |
5751 | __FILE__, VDefaults, group); | |
e276548b | 5752 | theCommands.Add("vraytrace", |
5753 | "vraytrace 0|1", | |
5754 | __FILE__,VRaytrace,group); | |
5755 | theCommands.Add("vclinfo", | |
5756 | "vclinfo", | |
5757 | __FILE__,VClInfo,group); | |
5758 | theCommands.Add("vsetraytracemode", | |
5759 | "vsetraytracemode [shad=0|1] [refl=0|1] [aa=0|1]", | |
5760 | __FILE__,VSetRaytraceMode,group); | |
7fd59977 | 5761 | } |