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