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; | |
1082 | if (TCollection_AsciiString::ISSIMILAR (anInputString, TCollection_AsciiString("ALL"))) | |
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]); | |
1126 | if (TCollection_AsciiString::ISSIMILAR (aNameString, TCollection_AsciiString("NONE"))) | |
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" | |
1177 | << "Usage: " << theArgVec[0]; | |
1178 | return 1; | |
1179 | } | |
1180 | if (ViewerTest_myContexts.Size() < 1) | |
1181 | return 0; | |
1182 | ||
1183 | TCollection_AsciiString aNameString(theArgsNb==2?theArgVec[1]:""); | |
1184 | Standard_Boolean isTreeView = | |
1185 | TCollection_AsciiString::ISSIMILAR (aNameString, TCollection_AsciiString("long"))? | |
1186 | Standard_False:Standard_True; | |
1187 | ||
1188 | if (isTreeView) | |
1189 | theDi << theArgVec[0] <<":\n"; | |
1190 | ||
1191 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
1192 | aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next()) | |
1193 | { | |
1194 | if (isTreeView) | |
1195 | theDi << aDriverIter.Key1() << ":\n"; | |
1196 | ||
1197 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1198 | aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next()) | |
1199 | { | |
1200 | if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1) | |
1201 | { | |
1202 | if (isTreeView) | |
1203 | { | |
1204 | TCollection_AsciiString aContextName(aContextIter.Key1()); | |
1205 | theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n"; | |
1206 | } | |
1207 | ||
1208 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
1209 | aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next()) | |
1210 | { | |
1211 | if (aViewIter.Key1().Search(aContextIter.Key1()) != -1) | |
1212 | { | |
1213 | TCollection_AsciiString aViewName(aViewIter.Key1()); | |
1214 | if (isTreeView) | |
1215 | { | |
1216 | if (aViewIter.Value() == ViewerTest::CurrentView()) | |
1217 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n"; | |
1218 | else | |
1219 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n"; | |
1220 | } | |
1221 | else | |
1222 | { | |
1223 | theDi << aViewName << " "; | |
1224 | } | |
1225 | } | |
1226 | } | |
1227 | } | |
1228 | } | |
1229 | } | |
1230 | return 0; | |
1231 | } | |
1232 | ||
7fd59977 | 1233 | //============================================================================== |
4fe56619 | 1234 | //function : VT_ProcessKeyPress |
7fd59977 | 1235 | //purpose : Handle KeyPress event from a CString |
1236 | //============================================================================== | |
4fe56619 | 1237 | void VT_ProcessKeyPress (const char* buf_ret) |
7fd59977 | 1238 | { |
1239 | //cout << "KeyPress" << endl; | |
1240 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
1241 | const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView); | |
1242 | // Letter in alphabetic order | |
1243 | ||
1244 | if ( !strcasecmp(buf_ret, "A") ) { | |
1245 | // AXO | |
1246 | aView->SetProj(V3d_XposYnegZpos); | |
1247 | } | |
1248 | else if ( !strcasecmp(buf_ret, "D") ) { | |
1249 | // Reset | |
1250 | aView->Reset(); | |
1251 | } | |
1252 | else if ( !strcasecmp(buf_ret, "F") ) { | |
1253 | // FitAll | |
1254 | if (aNisView.IsNull()) | |
1255 | aView->FitAll(); | |
1256 | else | |
1257 | aNisView->FitAll3d(); | |
1258 | } | |
1259 | else if ( !strcasecmp(buf_ret, "H") ) { | |
1260 | // HLR | |
1261 | cout << "HLR" << endl; | |
de75ed09 | 1262 | aView->SetComputedMode (!aView->ComputedMode()); |
1263 | MyHLRIsOn = aView->ComputedMode(); | |
7fd59977 | 1264 | } |
0a768f56 | 1265 | else if ( !strcasecmp(buf_ret, "P") ) { |
1266 | // Type of HLR | |
1267 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
1268 | if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo) | |
1269 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo); | |
1270 | else | |
1271 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo); | |
1272 | if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0) | |
1273 | { | |
1274 | AIS_ListOfInteractive aListOfShapes; | |
1275 | aContext->DisplayedObjects(aListOfShapes); | |
1276 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); | |
1277 | anIter.More(); anIter.Next()) | |
1278 | { | |
1279 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
1280 | if (aShape.IsNull()) | |
1281 | continue; | |
1282 | if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1283 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1284 | else | |
1285 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
1286 | aShape->Redisplay(); | |
1287 | } | |
1288 | } | |
1289 | else | |
1290 | { | |
1291 | for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()) | |
1292 | { | |
1293 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current()); | |
1294 | if (aShape.IsNull()) | |
1295 | continue; | |
1296 | if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1297 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1298 | else | |
1299 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
1300 | aShape->Redisplay(); | |
1301 | } | |
1302 | } | |
1303 | ||
1304 | aContext->UpdateCurrentViewer(); | |
1305 | ||
1306 | } | |
7fd59977 | 1307 | else if ( !strcasecmp(buf_ret, "S") ) { |
1308 | // SHADING | |
1309 | cout << "passage en mode 1 (shading pour les shapes)" << endl; | |
4fe56619 | 1310 | |
7fd59977 | 1311 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
1312 | if(Ctx->NbCurrents()==0 || | |
1313 | Ctx->NbSelected()==0) | |
1314 | Ctx->SetDisplayMode(AIS_Shaded); | |
1315 | else{ | |
1316 | if(Ctx->HasOpenedContext()){ | |
1317 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1318 | Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False); | |
1319 | } | |
1320 | else{ | |
1321 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
1322 | Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False); | |
1323 | } | |
1324 | Ctx->UpdateCurrentViewer(); | |
1325 | } | |
1326 | } | |
1327 | else if ( !strcasecmp(buf_ret, "U") ) { | |
41811896 | 1328 | // Unset display mode |
7fd59977 | 1329 | cout<<"passage au mode par defaut"<<endl; |
4fe56619 | 1330 | |
7fd59977 | 1331 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
1332 | if(Ctx->NbCurrents()==0 || | |
1333 | Ctx->NbSelected()==0) | |
1334 | Ctx->SetDisplayMode(AIS_WireFrame); | |
1335 | else{ | |
1336 | if(Ctx->HasOpenedContext()){ | |
1337 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1338 | Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False); | |
1339 | } | |
1340 | else{ | |
1341 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
1342 | Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False); | |
1343 | } | |
1344 | Ctx->UpdateCurrentViewer(); | |
1345 | } | |
1346 | ||
1347 | } | |
1348 | else if ( !strcasecmp(buf_ret, "T") ) { | |
1349 | // Top | |
1350 | aView->SetProj(V3d_Zpos); | |
1351 | } | |
1352 | else if ( !strcasecmp(buf_ret, "B") ) { | |
41811896 | 1353 | // Bottom |
7fd59977 | 1354 | aView->SetProj(V3d_Zneg); |
1355 | } | |
1356 | else if ( !strcasecmp(buf_ret, "L") ) { | |
41811896 | 1357 | // Left |
7fd59977 | 1358 | aView->SetProj(V3d_Xneg); |
1359 | } | |
1360 | else if ( !strcasecmp(buf_ret, "R") ) { | |
41811896 | 1361 | // Right |
7fd59977 | 1362 | aView->SetProj(V3d_Xpos); |
1363 | } | |
1364 | ||
1365 | else if ( !strcasecmp(buf_ret, "W") ) { | |
1366 | // WIREFRAME | |
7fd59977 | 1367 | cout << "passage en mode 0 (filaire pour les shapes)" << endl; |
7fd59977 | 1368 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
1369 | if(Ctx->NbCurrents()==0 || | |
1370 | Ctx->NbSelected()==0) | |
1371 | Ctx->SetDisplayMode(AIS_WireFrame); | |
1372 | else{ | |
1373 | if(Ctx->HasOpenedContext()){ | |
1374 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1375 | Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False); | |
1376 | } | |
1377 | else{ | |
1378 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
1379 | Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False); | |
1380 | } | |
1381 | Ctx->UpdateCurrentViewer(); | |
1382 | } | |
1383 | } | |
1384 | else if ( !strcasecmp(buf_ret, "Z") ) { | |
1385 | // ZCLIP | |
1386 | ||
1387 | if ( ZClipIsOn ) { | |
1388 | cout << "ZClipping OFF" << endl; | |
1389 | ZClipIsOn = 0; | |
1390 | ||
1391 | aView->SetZClippingType(V3d_OFF); | |
1392 | aView->Redraw(); | |
1393 | } | |
1394 | else { | |
1395 | cout << "ZClipping ON" << endl; | |
1396 | ZClipIsOn = 1; | |
1397 | ||
1398 | aView->SetZClippingType(V3d_FRONT); | |
1399 | aView->Redraw(); | |
1400 | } | |
1401 | } | |
1402 | else if ( !strcasecmp(buf_ret, ",") ) { | |
1403 | ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView()); | |
1404 | ||
1405 | ||
1406 | } | |
1407 | else if ( !strcasecmp(buf_ret, ".") ) { | |
1408 | ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView()); | |
1409 | } | |
1410 | // Number | |
1411 | else{ | |
91322f44 | 1412 | Standard_Integer Num = Draw::Atoi(buf_ret); |
7fd59977 | 1413 | if(Num>=0 && Num<=7) |
1414 | ViewerTest::StandardModeActivation(Num); | |
1415 | } | |
1416 | } | |
1417 | ||
1418 | //============================================================================== | |
4fe56619 | 1419 | //function : VT_ProcessExpose |
7fd59977 | 1420 | //purpose : Redraw the View on an Expose Event |
1421 | //============================================================================== | |
4fe56619 | 1422 | void VT_ProcessExpose() |
1423 | { | |
1424 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); | |
1425 | if (!aView3d.IsNull()) | |
1426 | { | |
1427 | aView3d->Redraw(); | |
1428 | } | |
7fd59977 | 1429 | } |
1430 | ||
1431 | //============================================================================== | |
4fe56619 | 1432 | //function : VT_ProcessConfigure |
7fd59977 | 1433 | //purpose : Resize the View on an Configure Event |
1434 | //============================================================================== | |
4fe56619 | 1435 | void VT_ProcessConfigure() |
7fd59977 | 1436 | { |
4fe56619 | 1437 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); |
1438 | if (aView3d.IsNull()) | |
1439 | { | |
1440 | return; | |
1441 | } | |
1442 | ||
1443 | aView3d->MustBeResized(); | |
1444 | aView3d->Update(); | |
1445 | aView3d->Redraw(); | |
7fd59977 | 1446 | } |
1447 | ||
1448 | //============================================================================== | |
4fe56619 | 1449 | //function : VT_ProcessButton1Press |
7fd59977 | 1450 | //purpose : Picking |
1451 | //============================================================================== | |
4fe56619 | 1452 | Standard_Boolean VT_ProcessButton1Press( |
7fd59977 | 1453 | Standard_Integer , |
4fe56619 | 1454 | const char** argv, |
7fd59977 | 1455 | Standard_Boolean pick, |
4fe56619 | 1456 | Standard_Boolean shift) |
7fd59977 | 1457 | { |
1458 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1459 | if ( pick ) { | |
1460 | Standard_Real X, Y, Z; | |
1461 | ||
1462 | ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z); | |
1463 | ||
1464 | Draw::Set(argv[1], X); | |
1465 | Draw::Set(argv[2], Y); | |
1466 | Draw::Set(argv[3], Z);} | |
1467 | ||
1468 | if(shift) | |
1469 | EM->ShiftSelect(); | |
1470 | else | |
1471 | EM->Select(); | |
1472 | ||
1473 | pick = 0; | |
1474 | return pick; | |
1475 | } | |
1476 | ||
1477 | //============================================================================== | |
4fe56619 | 1478 | //function : VT_ProcessButton1Release |
1479 | //purpose : End selecting | |
7fd59977 | 1480 | //============================================================================== |
4fe56619 | 1481 | void VT_ProcessButton1Release (Standard_Boolean theIsShift) |
1482 | { | |
1483 | if (IsDragged) | |
1484 | { | |
1485 | IsDragged = Standard_False; | |
1486 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1487 | if (theIsShift) | |
1488 | { | |
1489 | EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion), | |
1490 | Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion)); | |
1491 | } | |
1492 | else | |
1493 | { | |
1494 | EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion), | |
1495 | Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion)); | |
1496 | } | |
1497 | } | |
1498 | } | |
7fd59977 | 1499 | |
4fe56619 | 1500 | //============================================================================== |
1501 | //function : VT_ProcessButton3Press | |
1502 | //purpose : Start Rotation | |
1503 | //============================================================================== | |
1504 | void VT_ProcessButton3Press() | |
1505 | { | |
7fd59977 | 1506 | Start_Rot = 1; |
de75ed09 | 1507 | if (MyHLRIsOn) |
1508 | { | |
1509 | ViewerTest::CurrentView()->SetComputedMode (Standard_False); | |
1510 | } | |
7fd59977 | 1511 | ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress ); |
7fd59977 | 1512 | } |
4fe56619 | 1513 | |
7fd59977 | 1514 | //============================================================================== |
4fe56619 | 1515 | //function : VT_ProcessButton3Release |
1516 | //purpose : End rotation | |
7fd59977 | 1517 | //============================================================================== |
4fe56619 | 1518 | void VT_ProcessButton3Release() |
1519 | { | |
1520 | if (Start_Rot) | |
1521 | { | |
7fd59977 | 1522 | Start_Rot = 0; |
de75ed09 | 1523 | if (MyHLRIsOn) |
1524 | { | |
1525 | ViewerTest::CurrentView()->SetComputedMode (Standard_True); | |
1526 | } | |
7fd59977 | 1527 | } |
7fd59977 | 1528 | } |
1529 | ||
1530 | //============================================================================== | |
1531 | //function : ProcessZClipMotion | |
1532 | //purpose : Zoom | |
1533 | //============================================================================== | |
1534 | ||
1535 | void ProcessZClipMotion() | |
1536 | { | |
1537 | Handle(V3d_View) a3DView = ViewerTest::CurrentView(); | |
1538 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { | |
1539 | static Standard_Real CurZPos = 0.; | |
1540 | ||
1541 | //Quantity_Length VDX, VDY; | |
1542 | //a3DView->Size(VDX,VDY); | |
1543 | //Standard_Real VDZ = a3DView->ZSize(); | |
1544 | //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ); | |
1545 | ||
1546 | Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress); | |
1547 | ||
1548 | // Front = Depth + width/2. | |
1549 | Standard_Real D = 0.5; | |
1550 | Standard_Real W = 0.1; | |
1551 | ||
1552 | CurZPos += (dx); | |
1553 | ||
1554 | D += CurZPos; | |
1555 | ||
1556 | //printf("dx %lf Depth %lf Width %lf\n", dx, D, W); | |
1557 | ||
1558 | a3DView->SetZClippingType(V3d_OFF); | |
1559 | a3DView->SetZClippingDepth(D); | |
1560 | a3DView->SetZClippingWidth(W); | |
1561 | a3DView->SetZClippingType(V3d_FRONT); | |
1562 | ||
1563 | a3DView->Redraw(); | |
1564 | ||
1565 | X_ButtonPress = X_Motion; | |
1566 | Y_ButtonPress = Y_Motion; | |
1567 | } | |
1568 | } | |
1569 | ||
1570 | //============================================================================== | |
1571 | //function : ProcessControlButton1Motion | |
1572 | //purpose : Zoom | |
1573 | //============================================================================== | |
1574 | ||
1575 | static void ProcessControlButton1Motion() | |
1576 | { | |
1577 | ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion); | |
1578 | ||
1579 | X_ButtonPress = X_Motion; | |
1580 | Y_ButtonPress = Y_Motion; | |
1581 | } | |
1582 | ||
1583 | //============================================================================== | |
4fe56619 | 1584 | //function : VT_ProcessControlButton2Motion |
1585 | //purpose : Panning | |
7fd59977 | 1586 | //============================================================================== |
4fe56619 | 1587 | void VT_ProcessControlButton2Motion() |
7fd59977 | 1588 | { |
1589 | Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress); | |
1590 | Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress); | |
1591 | ||
1592 | dy = -dy; // Xwindow Y axis is from top to Bottom | |
1593 | ||
1594 | ViewerTest::CurrentView()->Panning( dx, dy ); | |
1595 | ||
1596 | X_ButtonPress = X_Motion; | |
1597 | Y_ButtonPress = Y_Motion; | |
1598 | } | |
1599 | ||
1600 | //============================================================================== | |
4fe56619 | 1601 | //function : VT_ProcessControlButton3Motion |
7fd59977 | 1602 | //purpose : Rotation |
1603 | //============================================================================== | |
4fe56619 | 1604 | void VT_ProcessControlButton3Motion() |
7fd59977 | 1605 | { |
4fe56619 | 1606 | if (Start_Rot) |
1607 | { | |
1608 | ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion); | |
1609 | } | |
7fd59977 | 1610 | } |
1611 | ||
1612 | //============================================================================== | |
4fe56619 | 1613 | //function : VT_ProcessMotion |
1614 | //purpose : | |
7fd59977 | 1615 | //============================================================================== |
4fe56619 | 1616 | void VT_ProcessMotion() |
7fd59977 | 1617 | { |
1618 | //pre-hilights detected objects at mouse position | |
1619 | ||
1620 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1621 | EM->MoveTo(X_Motion, Y_Motion); | |
1622 | } | |
1623 | ||
1624 | ||
1625 | void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix) | |
1626 | { | |
1627 | Xpix = X_Motion;Ypix=Y_Motion; | |
1628 | } | |
1629 | ||
44b8f2d6 | 1630 | //============================================================================== |
1631 | //function : ViewProject: implements VAxo, VTop, VLeft, ... | |
1632 | //purpose : Switches to an axonometric, top, left and other views | |
1633 | //============================================================================== | |
1634 | ||
1635 | static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori) | |
1636 | { | |
4fe56619 | 1637 | if ( ViewerTest::CurrentView().IsNull() ) |
44b8f2d6 | 1638 | { |
1639 | di<<"Call vinit before this command, please"<<"\n"; | |
1640 | return 1; | |
1641 | } | |
1642 | ||
1643 | ViewerTest::CurrentView()->SetProj(ori); | |
1644 | return 0; | |
1645 | } | |
1646 | ||
7fd59977 | 1647 | //============================================================================== |
1648 | //function : VAxo | |
1649 | //purpose : Switch to an Axonometric view | |
1650 | //Draw arg : No args | |
1651 | //============================================================================== | |
1652 | ||
1653 | static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** ) | |
44b8f2d6 | 1654 | { |
1655 | return ViewProject(di, V3d_XposYnegZpos); | |
7fd59977 | 1656 | } |
1657 | ||
1658 | //============================================================================== | |
1659 | //function : VTop | |
1660 | //purpose : Switch to a Top View | |
1661 | //Draw arg : No args | |
1662 | //============================================================================== | |
1663 | ||
1664 | static int VTop(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1665 | { | |
44b8f2d6 | 1666 | return ViewProject(di, V3d_Zpos); |
1667 | } | |
7fd59977 | 1668 | |
44b8f2d6 | 1669 | //============================================================================== |
1670 | //function : VBottom | |
1671 | //purpose : Switch to a Bottom View | |
1672 | //Draw arg : No args | |
1673 | //============================================================================== | |
7fd59977 | 1674 | |
44b8f2d6 | 1675 | static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** ) |
1676 | { | |
1677 | return ViewProject(di, V3d_Zneg); | |
1678 | } | |
7fd59977 | 1679 | |
44b8f2d6 | 1680 | //============================================================================== |
1681 | //function : VLeft | |
1682 | //purpose : Switch to a Left View | |
1683 | //Draw arg : No args | |
1684 | //============================================================================== | |
1685 | ||
1686 | static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1687 | { | |
1688 | return ViewProject(di, V3d_Ypos); | |
1689 | } | |
1690 | ||
1691 | //============================================================================== | |
1692 | //function : VRight | |
1693 | //purpose : Switch to a Right View | |
1694 | //Draw arg : No args | |
1695 | //============================================================================== | |
1696 | ||
1697 | static int VRight(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1698 | { | |
1699 | return ViewProject(di, V3d_Yneg); | |
1700 | } | |
7fd59977 | 1701 | |
44b8f2d6 | 1702 | //============================================================================== |
1703 | //function : VFront | |
1704 | //purpose : Switch to a Front View | |
1705 | //Draw arg : No args | |
1706 | //============================================================================== | |
1707 | ||
1708 | static int VFront(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1709 | { | |
1710 | return ViewProject(di, V3d_Xpos); | |
1711 | } | |
1712 | ||
1713 | //============================================================================== | |
1714 | //function : VBack | |
1715 | //purpose : Switch to a Back View | |
1716 | //Draw arg : No args | |
1717 | //============================================================================== | |
1718 | ||
1719 | static int VBack(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1720 | { | |
1721 | return ViewProject(di, V3d_Xneg); | |
7fd59977 | 1722 | } |
1723 | ||
1724 | //============================================================================== | |
1725 | //function : VHelp | |
1726 | //purpose : Dsiplay help on viewer Keyboead and mouse commands | |
1727 | //Draw arg : No args | |
1728 | //============================================================================== | |
1729 | ||
1730 | static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1731 | { | |
1732 | ||
1733 | di << "Q : Quit the application" << "\n"; | |
1734 | ||
1735 | di << "========================="<<"\n"; | |
1736 | di << "F : FitAll" << "\n"; | |
1737 | di << "T : TopView" << "\n"; | |
41811896 | 1738 | di << "B : BottomView" << "\n"; |
1739 | di << "R : RightView" << "\n"; | |
1740 | di << "L : LeftView" << "\n"; | |
7fd59977 | 1741 | di << "A : AxonometricView" << "\n"; |
41811896 | 1742 | di << "D : ResetView" << "\n"; |
7fd59977 | 1743 | |
1744 | di << "========================="<<"\n"; | |
1745 | di << "S : Shading" << "\n"; | |
1746 | di << "W : Wireframe" << "\n"; | |
1747 | di << "H : HidelLineRemoval" << "\n"; | |
41811896 | 1748 | di << "U : Unset display mode" << "\n"; |
7fd59977 | 1749 | |
1750 | di << "========================="<<"\n"; | |
1751 | di << "Selection mode "<<"\n"; | |
1752 | di << "0 : Shape" <<"\n"; | |
1753 | di << "1 : Vertex" <<"\n"; | |
1754 | di << "2 : Edge" <<"\n"; | |
1755 | di << "3 : Wire" <<"\n"; | |
1756 | di << "4 : Face" <<"\n"; | |
1757 | di << "5 : Shell" <<"\n"; | |
1758 | di << "6 : Solid" <<"\n"; | |
1759 | di << "7 : Compound" <<"\n"; | |
1760 | ||
41811896 | 1761 | di << "========================="<<"\n"; |
1762 | di << "Z : Switch Z clipping On/Off" << "\n"; | |
1763 | di << ", : Hilight next detected" << "\n"; | |
1764 | di << ". : Hilight previous detected" << "\n"; | |
7fd59977 | 1765 | |
1766 | return 0; | |
1767 | } | |
1768 | ||
7fd59977 | 1769 | #ifdef WNT |
1770 | ||
1771 | static Standard_Boolean Ppick = 0; | |
1772 | static Standard_Integer Pargc = 0; | |
1773 | static const char** Pargv = NULL; | |
1774 | ||
1775 | ||
1776 | static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd, | |
1777 | UINT Msg, | |
1778 | WPARAM wParam, | |
1779 | LPARAM lParam ) | |
1780 | { | |
18d715bd | 1781 | if (!ViewerTest_myViews.IsEmpty()) { |
7fd59977 | 1782 | |
1783 | WPARAM fwKeys = wParam; | |
1784 | ||
1785 | switch( Msg ) { | |
18d715bd | 1786 | case WM_CLOSE: |
1787 | { | |
1788 | // Delete view from map of views | |
1789 | ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd)); | |
1790 | return 0; | |
1791 | } | |
1792 | break; | |
1793 | case WM_ACTIVATE: | |
1794 | if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE | |
1795 | || ViewerTest::CurrentView().IsNull()) | |
1796 | { | |
1797 | // Activate inactive window | |
1798 | if(GetWindowHandle(VT_GetWindow()) != hwnd) | |
1799 | { | |
1800 | ActivateView (FindViewIdByWindowHandle(hwnd)); | |
1801 | } | |
1802 | } | |
1803 | break; | |
7fd59977 | 1804 | case WM_LBUTTONUP: |
1805 | IsDragged = Standard_False; | |
1806 | if( !DragFirst ) | |
1807 | { | |
1808 | HDC hdc = GetDC( hwnd ); | |
7fd59977 | 1809 | SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) ); |
1810 | SetROP2( hdc, R2_NOT ); | |
4fe56619 | 1811 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
7fd59977 | 1812 | ReleaseDC( hwnd, hdc ); |
1813 | ||
1814 | const Handle(ViewerTest_EventManager) EM = | |
1815 | ViewerTest::CurrentEventManager(); | |
1816 | if ( fwKeys & MK_SHIFT ) | |
4fe56619 | 1817 | EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), |
1818 | max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion )); | |
7fd59977 | 1819 | else |
4fe56619 | 1820 | EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), |
1821 | max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion )); | |
7fd59977 | 1822 | } |
1823 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1824 | ||
1825 | case WM_LBUTTONDOWN: | |
1826 | if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) ) | |
1827 | { | |
1828 | IsDragged = Standard_True; | |
1829 | DragFirst = Standard_True; | |
4fe56619 | 1830 | X_ButtonPress = LOWORD(lParam); |
1831 | Y_ButtonPress = HIWORD(lParam); | |
7fd59977 | 1832 | } |
1833 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1834 | ||
1835 | break; | |
1836 | ||
1837 | case WM_MOUSEMOVE: | |
1838 | if( IsDragged ) | |
1839 | { | |
1840 | HDC hdc = GetDC( hwnd ); | |
1841 | ||
1842 | HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) ); | |
1843 | SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) ); | |
1844 | SetROP2( hdc, R2_NOT ); | |
1845 | ||
1846 | if( !DragFirst ) | |
4fe56619 | 1847 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
7fd59977 | 1848 | |
1849 | DragFirst = Standard_False; | |
4fe56619 | 1850 | X_Motion = LOWORD(lParam); |
1851 | Y_Motion = HIWORD(lParam); | |
7fd59977 | 1852 | |
4fe56619 | 1853 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
7fd59977 | 1854 | |
1855 | SelectObject( hdc, anObj ); | |
1856 | ||
1857 | ReleaseDC( hwnd, hdc ); | |
1858 | } | |
1859 | else | |
1860 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1861 | break; | |
1862 | ||
1863 | default: | |
1864 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1865 | } | |
1866 | return 0; | |
1867 | } | |
1868 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1869 | } | |
1870 | ||
1871 | ||
1872 | static LRESULT WINAPI ViewerWindowProc( HWND hwnd, | |
1873 | UINT Msg, | |
1874 | WPARAM wParam, | |
1875 | LPARAM lParam ) | |
1876 | { | |
7fd59977 | 1877 | static int Up = 1; |
1878 | ||
1879 | if ( !ViewerTest::CurrentView().IsNull() ) { | |
1880 | PAINTSTRUCT ps; | |
1881 | ||
1882 | switch( Msg ) { | |
7fd59977 | 1883 | case WM_PAINT: |
7fd59977 | 1884 | BeginPaint(hwnd, &ps); |
1885 | EndPaint(hwnd, &ps); | |
4fe56619 | 1886 | VT_ProcessExpose(); |
7fd59977 | 1887 | break; |
1888 | ||
1889 | case WM_SIZE: | |
4fe56619 | 1890 | VT_ProcessConfigure(); |
7fd59977 | 1891 | break; |
1892 | ||
1893 | case WM_KEYDOWN: | |
4fe56619 | 1894 | if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL)) |
1895 | { | |
7fd59977 | 1896 | char c[2]; |
1897 | c[0] = (char) wParam; | |
1898 | c[1] = '\0'; | |
4fe56619 | 1899 | VT_ProcessKeyPress (c); |
7fd59977 | 1900 | } |
1901 | break; | |
1902 | ||
1903 | case WM_LBUTTONUP: | |
1904 | case WM_MBUTTONUP: | |
1905 | case WM_RBUTTONUP: | |
7fd59977 | 1906 | Up = 1; |
4fe56619 | 1907 | VT_ProcessButton3Release(); |
7fd59977 | 1908 | break; |
1909 | ||
1910 | case WM_LBUTTONDOWN: | |
1911 | case WM_MBUTTONDOWN: | |
1912 | case WM_RBUTTONDOWN: | |
1913 | { | |
7fd59977 | 1914 | WPARAM fwKeys = wParam; |
1915 | ||
1916 | Up = 0; | |
1917 | ||
1918 | X_ButtonPress = LOWORD(lParam); | |
1919 | Y_ButtonPress = HIWORD(lParam); | |
1920 | ||
4fe56619 | 1921 | if (Msg == WM_LBUTTONDOWN) |
1922 | { | |
1923 | if (fwKeys & MK_CONTROL) | |
1924 | { | |
1925 | Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT)); | |
1926 | } | |
1927 | else | |
1928 | { | |
1929 | VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT)); | |
1930 | } | |
7fd59977 | 1931 | } |
4fe56619 | 1932 | else if (Msg == WM_RBUTTONDOWN) |
1933 | { | |
7fd59977 | 1934 | // Start rotation |
4fe56619 | 1935 | VT_ProcessButton3Press(); |
7fd59977 | 1936 | } |
1937 | } | |
1938 | break; | |
1939 | ||
1940 | case WM_MOUSEMOVE: | |
1941 | { | |
1942 | //cout << "\t WM_MOUSEMOVE" << endl; | |
1943 | WPARAM fwKeys = wParam; | |
1944 | X_Motion = LOWORD(lParam); | |
1945 | Y_Motion = HIWORD(lParam); | |
1946 | ||
1947 | if ( Up && | |
1948 | fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) { | |
1949 | Up = 0; | |
1950 | X_ButtonPress = LOWORD(lParam); | |
1951 | Y_ButtonPress = HIWORD(lParam); | |
1952 | ||
1953 | if ( fwKeys & MK_RBUTTON ) { | |
1954 | // Start rotation | |
4fe56619 | 1955 | VT_ProcessButton3Press(); |
7fd59977 | 1956 | } |
1957 | } | |
1958 | ||
1959 | if ( fwKeys & MK_CONTROL ) { | |
1960 | if ( fwKeys & MK_LBUTTON ) { | |
1961 | ProcessControlButton1Motion(); | |
1962 | } | |
1963 | else if ( fwKeys & MK_MBUTTON || | |
1964 | ((fwKeys&MK_LBUTTON) && | |
1965 | (fwKeys&MK_RBUTTON) ) ){ | |
4fe56619 | 1966 | VT_ProcessControlButton2Motion(); |
7fd59977 | 1967 | } |
1968 | else if ( fwKeys & MK_RBUTTON ) { | |
4fe56619 | 1969 | VT_ProcessControlButton3Motion(); |
7fd59977 | 1970 | } |
1971 | } | |
1972 | #ifdef BUG | |
1973 | else if ( fwKeys & MK_SHIFT ) { | |
1974 | if ( fwKeys & MK_MBUTTON || | |
1975 | ((fwKeys&MK_LBUTTON) && | |
1976 | (fwKeys&MK_RBUTTON) ) ) { | |
1977 | cout << "ProcessZClipMotion()" << endl; | |
1978 | ProcessZClipMotion(); | |
1979 | } | |
1980 | } | |
1981 | #endif | |
1982 | else | |
4fe56619 | 1983 | if ((fwKeys & MK_MBUTTON |
1984 | || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON)))) | |
1985 | { | |
7fd59977 | 1986 | ProcessZClipMotion(); |
1987 | } | |
4fe56619 | 1988 | else |
1989 | { | |
1990 | VT_ProcessMotion(); | |
7fd59977 | 1991 | } |
1992 | } | |
1993 | break; | |
1994 | ||
1995 | default: | |
1996 | return( DefWindowProc( hwnd, Msg, wParam, lParam )); | |
1997 | } | |
1998 | return 0L; | |
1999 | } | |
2000 | ||
2001 | return DefWindowProc( hwnd, Msg, wParam, lParam ); | |
2002 | } | |
2003 | ||
2004 | ||
2005 | ||
2006 | ||
2007 | //============================================================================== | |
2008 | //function : ViewerMainLoop | |
2009 | //purpose : Get a Event on the view and dispatch it | |
2010 | //============================================================================== | |
2011 | ||
2012 | ||
2013 | static int ViewerMainLoop(Standard_Integer argc, const char** argv) | |
2014 | { | |
7fd59977 | 2015 | Ppick = (argc > 0)? 1 : 0; |
2016 | Pargc = argc; | |
2017 | Pargv = argv; | |
2018 | ||
2019 | if ( Ppick ) { | |
2020 | MSG msg; | |
2021 | msg.wParam = 1; | |
2022 | ||
2023 | cout << "Start picking" << endl; | |
2024 | ||
7fd59977 | 2025 | while ( Ppick == 1 ) { |
4fe56619 | 2026 | // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0 |
7fd59977 | 2027 | if (GetMessage(&msg, NULL, 0, 0) ) { |
2028 | TranslateMessage(&msg); | |
2029 | DispatchMessage(&msg); | |
2030 | } | |
2031 | } | |
2032 | ||
2033 | cout << "Picking done" << endl; | |
2034 | } | |
2035 | ||
2036 | return Ppick; | |
2037 | } | |
2038 | ||
4fe56619 | 2039 | #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 2040 | |
2041 | int min( int a, int b ) | |
2042 | { | |
2043 | if( a<b ) | |
2044 | return a; | |
2045 | else | |
2046 | return b; | |
2047 | } | |
2048 | ||
2049 | int max( int a, int b ) | |
2050 | { | |
2051 | if( a>b ) | |
2052 | return a; | |
2053 | else | |
2054 | return b; | |
2055 | } | |
2056 | ||
2057 | int ViewerMainLoop(Standard_Integer argc, const char** argv) | |
2058 | ||
18d715bd | 2059 | { |
2060 | static XEvent aReport; | |
2061 | Standard_Boolean pick = argc > 0; | |
2062 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2063 | XNextEvent (aDisplay, &aReport); | |
7fd59977 | 2064 | |
18d715bd | 2065 | // Handle event for the chosen display connection |
2066 | switch (aReport.type) { | |
2067 | case ClientMessage: | |
2068 | { | |
2069 | if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW)) | |
2070 | { | |
2071 | // Close the window | |
2072 | ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window)); | |
2073 | } | |
2074 | } | |
2075 | return 0; | |
2076 | case FocusIn: | |
2077 | { | |
2078 | // Activate inactive view | |
2079 | Window aWindow = GetWindowHandle(VT_GetWindow()); | |
2080 | if(aWindow != aReport.xfocus.window) | |
2081 | { | |
2082 | ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window)); | |
2083 | } | |
2084 | } | |
2085 | break; | |
7fd59977 | 2086 | case Expose: |
2087 | { | |
4fe56619 | 2088 | VT_ProcessExpose(); |
7fd59977 | 2089 | } |
2090 | break; | |
2091 | case ConfigureNotify: | |
2092 | { | |
4fe56619 | 2093 | VT_ProcessConfigure(); |
7fd59977 | 2094 | } |
2095 | break; | |
2096 | case KeyPress: | |
2097 | { | |
2098 | ||
2099 | KeySym ks_ret ; | |
2100 | char buf_ret[11] ; | |
2101 | int ret_len ; | |
2102 | XComposeStatus status_in_out; | |
2103 | ||
18d715bd | 2104 | ret_len = XLookupString( ( XKeyEvent *)&aReport , |
7fd59977 | 2105 | (char *) buf_ret , 10 , |
2106 | &ks_ret , &status_in_out ) ; | |
2107 | ||
2108 | ||
2109 | buf_ret[ret_len] = '\0' ; | |
2110 | ||
4fe56619 | 2111 | if (ret_len) |
2112 | { | |
2113 | VT_ProcessKeyPress (buf_ret); | |
7fd59977 | 2114 | } |
2115 | } | |
2116 | break; | |
2117 | case ButtonPress: | |
7fd59977 | 2118 | { |
18d715bd | 2119 | X_ButtonPress = aReport.xbutton.x; |
2120 | Y_ButtonPress = aReport.xbutton.y; | |
7fd59977 | 2121 | |
18d715bd | 2122 | if (aReport.xbutton.button == Button1) |
4fe56619 | 2123 | { |
18d715bd | 2124 | if (aReport.xbutton.state & ControlMask) |
4fe56619 | 2125 | { |
18d715bd | 2126 | pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask)); |
4fe56619 | 2127 | } |
7fd59977 | 2128 | else |
2129 | { | |
2130 | IsDragged = Standard_True; | |
7fd59977 | 2131 | DragFirst = Standard_True; |
2132 | } | |
4fe56619 | 2133 | } |
18d715bd | 2134 | else if (aReport.xbutton.button == Button3) |
4fe56619 | 2135 | { |
7fd59977 | 2136 | // Start rotation |
4fe56619 | 2137 | VT_ProcessButton3Press(); |
2138 | } | |
7fd59977 | 2139 | } |
2140 | break; | |
2141 | case ButtonRelease: | |
2142 | { | |
7fd59977 | 2143 | if( IsDragged ) |
2144 | { | |
2145 | if( !DragFirst ) | |
2146 | { | |
2147 | Aspect_Handle aWindow = VT_GetWindow()->XWindow(); | |
18d715bd | 2148 | GC gc = XCreateGC( aDisplay, aWindow, 0, 0 ); |
2149 | 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 | 2150 | } |
2151 | ||
2152 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
2153 | if( aContext.IsNull() ) | |
2154 | { | |
2155 | cout << "The context is null. Please use vinit before createmesh" << endl; | |
2156 | return 0; | |
2157 | } | |
2158 | ||
18d715bd | 2159 | Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask ); |
2160 | if( aReport.xbutton.button==1 ) | |
7fd59977 | 2161 | if( DragFirst ) |
2162 | if( ShiftPressed ) | |
2163 | { | |
2164 | aContext->ShiftSelect(); | |
7fd59977 | 2165 | } |
2166 | else | |
2167 | { | |
2168 | aContext->Select(); | |
7fd59977 | 2169 | } |
2170 | else | |
2171 | if( ShiftPressed ) | |
2172 | { | |
4fe56619 | 2173 | aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), |
2174 | max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), | |
7fd59977 | 2175 | ViewerTest::CurrentView()); |
7fd59977 | 2176 | } |
2177 | else | |
2178 | { | |
4fe56619 | 2179 | aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), |
2180 | max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), | |
7fd59977 | 2181 | ViewerTest::CurrentView() ); |
7fd59977 | 2182 | } |
2183 | else | |
4fe56619 | 2184 | VT_ProcessButton3Release(); |
7fd59977 | 2185 | |
2186 | IsDragged = Standard_False; | |
2187 | } | |
2188 | else | |
4fe56619 | 2189 | VT_ProcessButton3Release(); |
7fd59977 | 2190 | } |
2191 | break; | |
2192 | case MotionNotify: | |
2193 | { | |
7fd59977 | 2194 | if( IsDragged ) |
2195 | { | |
2196 | Aspect_Handle aWindow = VT_GetWindow()->XWindow(); | |
18d715bd | 2197 | GC gc = XCreateGC( aDisplay, aWindow, 0, 0 ); |
2198 | XSetFunction( aDisplay, gc, GXinvert ); | |
7fd59977 | 2199 | |
2200 | if( !DragFirst ) | |
18d715bd | 2201 | 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 | 2202 | |
18d715bd | 2203 | X_Motion = aReport.xmotion.x; |
2204 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2205 | DragFirst = Standard_False; |
2206 | ||
18d715bd | 2207 | 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 | 2208 | } |
2209 | else | |
2210 | { | |
18d715bd | 2211 | X_Motion = aReport.xmotion.x; |
2212 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2213 | |
18d715bd | 2214 | // remove all the ButtonMotionMaskr |
2215 | while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ; | |
7fd59977 | 2216 | |
18d715bd | 2217 | if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) { |
7fd59977 | 2218 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { |
2219 | ||
2220 | Quantity_Length VDX, VDY; | |
2221 | ||
2222 | ViewerTest::CurrentView()->Size(VDX,VDY); | |
2223 | Standard_Real VDZ =0 ; | |
2224 | VDZ = ViewerTest::CurrentView()->ZSize(); | |
2225 | ||
7fd59977 | 2226 | printf("%f,%f,%f\n", VDX, VDY, VDZ); |
2227 | ||
2228 | Quantity_Length dx = 0 ; | |
2229 | dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress); | |
2230 | ||
2231 | cout << dx << endl; | |
2232 | ||
2233 | dx = dx / VDX * VDZ; | |
2234 | ||
2235 | cout << dx << endl; | |
2236 | ||
7fd59977 | 2237 | ViewerTest::CurrentView()->Redraw(); |
2238 | } | |
2239 | } | |
2240 | ||
18d715bd | 2241 | if ( aReport.xmotion.state & ControlMask ) { |
2242 | if ( aReport.xmotion.state & Button1Mask ) { | |
7fd59977 | 2243 | ProcessControlButton1Motion(); |
2244 | } | |
18d715bd | 2245 | else if ( aReport.xmotion.state & Button2Mask ) { |
4fe56619 | 2246 | VT_ProcessControlButton2Motion(); |
7fd59977 | 2247 | } |
18d715bd | 2248 | else if ( aReport.xmotion.state & Button3Mask ) { |
4fe56619 | 2249 | VT_ProcessControlButton3Motion(); |
7fd59977 | 2250 | } |
2251 | } | |
4fe56619 | 2252 | else |
2253 | { | |
2254 | VT_ProcessMotion(); | |
7fd59977 | 2255 | } |
2256 | } | |
2257 | } | |
2258 | break; | |
2259 | } | |
7fd59977 | 2260 | return pick; |
2261 | } | |
2262 | ||
2263 | //============================================================================== | |
2264 | //function : VProcessEvents | |
2265 | //purpose : call by Tk_CreateFileHandler() to be able to manage the | |
2266 | // event in the Viewer window | |
2267 | //============================================================================== | |
2268 | ||
2269 | static void VProcessEvents(ClientData,int) | |
2270 | { | |
18d715bd | 2271 | NCollection_Vector<int> anEventNumbers; |
2272 | // Get number of messages from every display | |
2273 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2274 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next()) | |
2275 | { | |
2276 | anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay())); | |
2277 | } | |
2278 | // Handle events for every display | |
2279 | int anEventIter = 0; | |
2280 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2281 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++) | |
2282 | { | |
2283 | for (int i = 0; i < anEventNumbers.Value(anEventIter) && | |
2284 | XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i) | |
2285 | { | |
2286 | SetDisplayConnection (anIter.Key2()->GetDisplayConnection()); | |
2287 | int anEventResult = ViewerMainLoop( 0, NULL); | |
2288 | // If window is closed or context was not found finish current event processing loop | |
2289 | if (!anEventResult) | |
2290 | return; | |
2291 | } | |
7fd59977 | 2292 | } |
18d715bd | 2293 | |
2294 | SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection()); | |
2295 | ||
7fd59977 | 2296 | } |
2297 | #endif | |
2298 | ||
2299 | //============================================================================== | |
2300 | //function : OSWindowSetup | |
2301 | //purpose : Setup for the X11 window to be able to cath the event | |
2302 | //============================================================================== | |
2303 | ||
2304 | ||
2305 | static void OSWindowSetup() | |
2306 | { | |
4fe56619 | 2307 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
7fd59977 | 2308 | // X11 |
2309 | ||
2310 | Window window = VT_GetWindow()->XWindow(); | |
18d715bd | 2311 | SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
2312 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2313 | XSynchronize(aDisplay, 1); | |
7fd59977 | 2314 | |
2315 | // X11 : For keyboard on SUN | |
2316 | XWMHints wmhints; | |
2317 | wmhints.flags = InputHint; | |
2318 | wmhints.input = 1; | |
2319 | ||
18d715bd | 2320 | XSetWMHints( aDisplay, window, &wmhints); |
7fd59977 | 2321 | |
18d715bd | 2322 | XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | |
7fd59977 | 2323 | ButtonPressMask | ButtonReleaseMask | |
2324 | StructureNotifyMask | | |
2325 | PointerMotionMask | | |
2326 | Button1MotionMask | Button2MotionMask | | |
18d715bd | 2327 | Button3MotionMask | FocusChangeMask |
7fd59977 | 2328 | ); |
18d715bd | 2329 | Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW); |
2330 | XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1); | |
7fd59977 | 2331 | |
18d715bd | 2332 | XSynchronize(aDisplay, 0); |
7fd59977 | 2333 | |
2334 | #else | |
2335 | // WNT | |
2336 | #endif | |
2337 | ||
2338 | } | |
2339 | ||
2340 | ||
2341 | //============================================================================== | |
2342 | //function : VFit | |
2343 | ||
2344 | //purpose : Fitall, no DRAW arguments | |
2345 | //Draw arg : No args | |
2346 | //============================================================================== | |
2347 | ||
2348 | static int VFit(Draw_Interpretor& , Standard_Integer , const char** ) | |
2349 | { | |
2350 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
2351 | Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView); | |
2352 | if (V.IsNull() == Standard_False) { | |
2353 | V->FitAll3d(); | |
2354 | } else if (aView.IsNull() == Standard_False) { | |
2355 | aView->FitAll(); | |
2356 | } | |
2357 | return 0; | |
2358 | } | |
2359 | ||
2360 | //============================================================================== | |
2361 | //function : VZFit | |
2362 | //purpose : ZFitall, no DRAW arguments | |
2363 | //Draw arg : No args | |
2364 | //============================================================================== | |
2365 | ||
2366 | static int VZFit(Draw_Interpretor& , Standard_Integer , const char** ) | |
2367 | { | |
2368 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
2369 | if ( !V.IsNull() ) V->ZFitAll(); return 0; } | |
2370 | ||
2371 | ||
2372 | static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** ) | |
2373 | { | |
2374 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
2375 | if ( !V.IsNull() ) V->Redraw(); return 0; | |
2376 | } | |
2377 | ||
2378 | ||
2379 | //============================================================================== | |
2380 | //function : VClear | |
2381 | //purpose : Remove all the object from the viewer | |
2382 | //Draw arg : No args | |
2383 | //============================================================================== | |
2384 | ||
2385 | static int VClear(Draw_Interpretor& , Standard_Integer , const char** ) | |
2386 | { | |
2387 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
2388 | if(!V.IsNull()) | |
2389 | ViewerTest::Clear(); | |
2390 | return 0; | |
2391 | } | |
2392 | ||
2393 | //============================================================================== | |
2394 | //function : VPick | |
2395 | //purpose : | |
2396 | //============================================================================== | |
2397 | ||
2398 | static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2399 | { if (ViewerTest::CurrentView().IsNull() ) return 1; | |
2400 | ||
2401 | if ( argc < 4 ) { | |
2402 | di << argv[0] << "Invalid number of arguments" << "\n"; | |
2403 | return 1; | |
2404 | } | |
2405 | ||
2406 | while (ViewerMainLoop( argc, argv)) { | |
2407 | } | |
2408 | ||
2409 | return 0; | |
2410 | } | |
2411 | ||
7fd59977 | 2412 | //============================================================================== |
2413 | //function : InitViewerTest | |
2414 | //purpose : initialisation de toutes les variables static de ViewerTest (dp) | |
2415 | //============================================================================== | |
2416 | ||
18d715bd | 2417 | void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext) |
7fd59977 | 2418 | { |
18d715bd | 2419 | Handle(V3d_Viewer) aViewer = theContext->CurrentViewer(); |
2420 | ViewerTest::SetAISContext(theContext); | |
2421 | aViewer->InitActiveViews(); | |
2422 | Handle(V3d_View) aView = aViewer->ActiveView(); | |
2423 | if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView); | |
7fd59977 | 2424 | ViewerTest::ResetEventManager(); |
18d715bd | 2425 | Handle(Aspect_Window) aWindow = aView->Window(); |
4fe56619 | 2426 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
7fd59977 | 2427 | // X11 |
18d715bd | 2428 | VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow); |
7fd59977 | 2429 | OSWindowSetup(); |
18d715bd | 2430 | static int aFirst = 1; |
2431 | if ( aFirst ) { | |
7fd59977 | 2432 | #if TCL_MAJOR_VERSION < 8 |
18d715bd | 2433 | Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 2434 | TK_READABLE, VProcessEvents, (ClientData) 0); |
2435 | #else | |
18d715bd | 2436 | Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 2437 | TK_READABLE, VProcessEvents, (ClientData) 0); |
2438 | #endif | |
18d715bd | 2439 | aFirst = 0; |
7fd59977 | 2440 | } |
2441 | #endif | |
2442 | } | |
2443 | ||
7fd59977 | 2444 | //============================================================================== |
2445 | //function : VSetBg | |
2446 | //purpose : Load image as background | |
2447 | //============================================================================== | |
2448 | ||
2449 | static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2450 | { | |
2451 | if (argc < 2 || argc > 3) | |
2452 | { | |
2453 | di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n"; | |
f8b2ed36 | 2454 | di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n"; |
7fd59977 | 2455 | return 1; |
2456 | } | |
2457 | ||
2458 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2459 | if(AISContext.IsNull()) | |
2460 | { | |
2461 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2462 | return 1; | |
2463 | } | |
2464 | ||
2465 | Aspect_FillMethod aFillType = Aspect_FM_CENTERED; | |
2466 | if (argc == 3) | |
2467 | { | |
2468 | const char* szType = argv[2]; | |
2469 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
2470 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
2471 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
2472 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
2473 | else | |
2474 | { | |
2475 | di << "Wrong fill type : " << szType << "\n"; | |
2476 | di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
2477 | return 1; | |
2478 | } | |
2479 | } | |
2480 | ||
2481 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2482 | V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True); | |
2483 | ||
2484 | return 0; | |
2485 | } | |
2486 | ||
f8b2ed36 | 2487 | //============================================================================== |
2488 | //function : VSetBgMode | |
2489 | //purpose : Change background image fill type | |
2490 | //============================================================================== | |
2491 | ||
2492 | static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2493 | { | |
2494 | if (argc != 2) | |
2495 | { | |
2496 | di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n"; | |
2497 | di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
2498 | return 1; | |
2499 | } | |
2500 | ||
2501 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2502 | if(AISContext.IsNull()) | |
2503 | { | |
2504 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2505 | return 1; | |
2506 | } | |
2507 | ||
2508 | Aspect_FillMethod aFillType; | |
2509 | if (argc == 2) | |
2510 | { | |
2511 | const char* szType = argv[1]; | |
2512 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
2513 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
2514 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
2515 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
2516 | else | |
2517 | { | |
2518 | di << "Wrong fill type : " << szType << "\n"; | |
2519 | di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
2520 | return 1; | |
2521 | } | |
2522 | } | |
2523 | ||
2524 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2525 | V3dView->SetBgImageStyle(aFillType, Standard_True); | |
2526 | ||
2527 | return 0; | |
2528 | } | |
2529 | ||
7fd59977 | 2530 | //============================================================================== |
2531 | //function : VSetGradientBg | |
2532 | //purpose : Mount gradient background | |
2533 | //============================================================================== | |
2534 | static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2535 | { | |
2536 | if (argc != 8 ) | |
2537 | { | |
2538 | di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n"; | |
2539 | di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n"; | |
2540 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2541 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2542 | return 1; | |
2543 | } | |
2544 | ||
2545 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2546 | if(AISContext.IsNull()) | |
2547 | { | |
2548 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2549 | return 1; | |
2550 | } | |
2551 | if (argc == 8) | |
2552 | { | |
2553 | ||
91322f44 | 2554 | Standard_Real R1 = Draw::Atof(argv[1])/255.; |
2555 | Standard_Real G1 = Draw::Atof(argv[2])/255.; | |
2556 | Standard_Real B1 = Draw::Atof(argv[3])/255.; | |
7fd59977 | 2557 | Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB); |
2558 | ||
91322f44 | 2559 | Standard_Real R2 = Draw::Atof(argv[4])/255.; |
2560 | Standard_Real G2 = Draw::Atof(argv[5])/255.; | |
2561 | Standard_Real B2 = Draw::Atof(argv[6])/255.; | |
7fd59977 | 2562 | |
2563 | Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB); | |
91322f44 | 2564 | int aType = Draw::Atoi(argv[7]); |
7fd59977 | 2565 | if( aType < 0 || aType > 8 ) |
2566 | { | |
2567 | di << "Wrong fill type " << "\n"; | |
2568 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2569 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2570 | return 1; | |
2571 | } | |
2572 | ||
2573 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
2574 | ||
2575 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2576 | V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1); | |
2577 | } | |
2578 | ||
2579 | return 0; | |
2580 | } | |
2581 | ||
f8b2ed36 | 2582 | //============================================================================== |
2583 | //function : VSetGradientBgMode | |
2584 | //purpose : Change gradient background fill style | |
2585 | //============================================================================== | |
2586 | static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2587 | { | |
2588 | if (argc != 2 ) | |
2589 | { | |
2590 | di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n"; | |
2591 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2592 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2593 | return 1; | |
2594 | } | |
2595 | ||
2596 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2597 | if(AISContext.IsNull()) | |
2598 | { | |
2599 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2600 | return 1; | |
2601 | } | |
2602 | if (argc == 2) | |
2603 | { | |
91322f44 | 2604 | int aType = Draw::Atoi(argv[1]); |
f8b2ed36 | 2605 | if( aType < 0 || aType > 8 ) |
2606 | { | |
2607 | di << "Wrong fill type " << "\n"; | |
2608 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2609 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2610 | return 1; | |
2611 | } | |
2612 | ||
2613 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
2614 | ||
2615 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2616 | V3dView->SetBgGradientStyle( aMethod, 1 ); | |
2617 | } | |
2618 | ||
2619 | return 0; | |
2620 | } | |
2621 | ||
2622 | //============================================================================== | |
2623 | //function : VSetColorBg | |
2624 | //purpose : Set color background | |
2625 | //============================================================================== | |
2626 | static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2627 | { | |
2628 | if (argc != 4 ) | |
2629 | { | |
2630 | di << "Usage : " << argv[0] << " R G B : Set color background" << "\n"; | |
2631 | di << "R,G,B = [0..255]" << "\n"; | |
2632 | return 1; | |
2633 | } | |
2634 | ||
2635 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2636 | if(AISContext.IsNull()) | |
2637 | { | |
2638 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2639 | return 1; | |
2640 | } | |
2641 | if (argc == 4) | |
2642 | { | |
2643 | ||
91322f44 | 2644 | Standard_Real R = Draw::Atof(argv[1])/255.; |
2645 | Standard_Real G = Draw::Atof(argv[2])/255.; | |
2646 | Standard_Real B = Draw::Atof(argv[3])/255.; | |
f8b2ed36 | 2647 | Quantity_Color aColor(R,G,B,Quantity_TOC_RGB); |
2648 | ||
2649 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2650 | V3dView->SetBackgroundColor( aColor ); | |
2651 | V3dView->Update(); | |
2652 | } | |
2653 | ||
2654 | return 0; | |
2655 | } | |
2656 | ||
7fd59977 | 2657 | //============================================================================== |
2658 | //function : VScale | |
2659 | //purpose : View Scaling | |
2660 | //============================================================================== | |
2661 | ||
2662 | static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2663 | { | |
2664 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2665 | if ( V3dView.IsNull() ) return 1; | |
2666 | ||
2667 | if ( argc != 4 ) { | |
2668 | di << argv[0] << "Invalid number of arguments" << "\n"; | |
2669 | return 1; | |
2670 | } | |
91322f44 | 2671 | V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) ); |
7fd59977 | 2672 | return 0; |
2673 | } | |
2674 | //============================================================================== | |
2675 | //function : VTestZBuffTrihedron | |
7c8a8fcc | 2676 | //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron |
7fd59977 | 2677 | //============================================================================== |
2678 | ||
2679 | static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2680 | { | |
2681 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2682 | if ( V3dView.IsNull() ) return 1; | |
2683 | ||
7fd59977 | 2684 | V3dView->ZBufferTriedronSetup(); |
7c8a8fcc | 2685 | |
2686 | if ( argc == 1 ) { | |
2687 | // Set up default trihedron parameters | |
2688 | V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER ); | |
2689 | } else | |
2690 | if ( argc == 7 ) | |
2691 | { | |
2692 | Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER; | |
2693 | const char* aPosType = argv[1]; | |
2694 | ||
2695 | if ( strcmp(aPosType, "center") == 0 ) | |
2696 | { | |
2697 | aPosition = Aspect_TOTP_CENTER; | |
2698 | } else | |
2699 | if (strcmp(aPosType, "left_lower") == 0) | |
2700 | { | |
2701 | aPosition = Aspect_TOTP_LEFT_LOWER; | |
2702 | } else | |
2703 | if (strcmp(aPosType, "left_upper") == 0) | |
2704 | { | |
2705 | aPosition = Aspect_TOTP_LEFT_UPPER; | |
2706 | } else | |
2707 | if (strcmp(aPosType, "right_lower") == 0) | |
2708 | { | |
2709 | aPosition = Aspect_TOTP_RIGHT_LOWER; | |
2710 | } else | |
2711 | if (strcmp(aPosType, "right_upper") == 0) | |
2712 | { | |
2713 | aPosition = Aspect_TOTP_RIGHT_UPPER; | |
2714 | } else | |
2715 | { | |
2716 | di << argv[1] << " Invalid type of alignment" << "\n"; | |
2717 | di << "Must be one of [ center, left_lower," << "\n"; | |
2718 | di << "left_upper, right_lower, right_upper ]" << "\n"; | |
2719 | return 1; | |
2720 | } | |
2721 | ||
91322f44 | 2722 | Standard_Real R = Draw::Atof(argv[2])/255.; |
2723 | Standard_Real G = Draw::Atof(argv[3])/255.; | |
2724 | Standard_Real B = Draw::Atof(argv[4])/255.; | |
7c8a8fcc | 2725 | Quantity_Color aColor(R, G, B, Quantity_TOC_RGB); |
2726 | ||
91322f44 | 2727 | Standard_Real aScale = Draw::Atof(argv[5]); |
7c8a8fcc | 2728 | |
2729 | if( aScale <= 0.0 ) | |
2730 | { | |
2731 | di << argv[5] << " Invalid value. Must be > 0" << "\n"; | |
2732 | return 1; | |
2733 | } | |
2734 | ||
2735 | V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER; | |
2736 | const char* aPresType = argv[6]; | |
2737 | ||
2738 | if ( strcmp(aPresType, "wireframe") == 0 ) | |
2739 | { | |
2740 | aPresentation = V3d_WIREFRAME; | |
2741 | } else | |
2742 | if (strcmp(aPresType, "zbuffer") == 0) | |
2743 | { | |
2744 | aPresentation = V3d_ZBUFFER; | |
2745 | } else | |
2746 | { | |
2747 | di << argv[6] << " Invalid type of visualization" << "\n"; | |
2748 | di << "Must be one of [ wireframe, zbuffer ]" << "\n"; | |
2749 | return 1; | |
2750 | } | |
2751 | ||
2752 | V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation ); | |
2753 | ||
2754 | } else | |
2755 | { | |
2756 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
2757 | return 1; | |
2758 | } | |
2759 | ||
7fd59977 | 2760 | V3dView->ZFitAll(); |
7c8a8fcc | 2761 | |
7fd59977 | 2762 | return 0; |
2763 | } | |
2764 | ||
2765 | //============================================================================== | |
2766 | //function : VRotate | |
2767 | //purpose : Camera Rotating | |
2768 | //============================================================================== | |
2769 | ||
2770 | static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
2771 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2772 | if ( V3dView.IsNull() ) { | |
2773 | return 1; | |
2774 | } | |
2775 | ||
2776 | if ( argc == 4 ) { | |
91322f44 | 2777 | V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) ); |
7fd59977 | 2778 | return 0; |
2779 | } else if ( argc == 7 ) { | |
91322f44 | 2780 | 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 | 2781 | return 0; |
2782 | } else { | |
2783 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
2784 | return 1; | |
2785 | } | |
2786 | } | |
2787 | ||
2788 | //============================================================================== | |
2789 | //function : VZoom | |
2790 | //purpose : View zoom in / out (relative to current zoom) | |
2791 | //============================================================================== | |
2792 | ||
2793 | static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
2794 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2795 | if ( V3dView.IsNull() ) { | |
2796 | return 1; | |
2797 | } | |
2798 | ||
2799 | if ( argc == 2 ) { | |
91322f44 | 2800 | Standard_Real coef = Draw::Atof(argv[1]); |
7fd59977 | 2801 | if ( coef <= 0.0 ) { |
2802 | di << argv[1] << "Invalid value" << "\n"; | |
2803 | return 1; | |
2804 | } | |
91322f44 | 2805 | V3dView->SetZoom( Draw::Atof(argv[1]) ); |
7fd59977 | 2806 | return 0; |
2807 | } else { | |
2808 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
2809 | return 1; | |
2810 | } | |
2811 | } | |
2812 | ||
2813 | //============================================================================== | |
2814 | //function : VPan | |
2815 | //purpose : View panning (in pixels) | |
2816 | //============================================================================== | |
2817 | ||
2818 | static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
2819 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2820 | if ( V3dView.IsNull() ) return 1; | |
2821 | ||
2822 | if ( argc == 3 ) { | |
91322f44 | 2823 | V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) ); |
7fd59977 | 2824 | return 0; |
2825 | } else { | |
2826 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
2827 | return 1; | |
2828 | } | |
2829 | } | |
2830 | ||
2831 | ||
2832 | //============================================================================== | |
2833 | //function : VExport | |
5cedc27f | 2834 | //purpose : Export the view to a vector graphic format (PS, EMF, PDF) |
7fd59977 | 2835 | //============================================================================== |
2836 | ||
2837 | static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2838 | { | |
2839 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
5cedc27f K |
2840 | if (V3dView.IsNull()) |
2841 | return 1; | |
7fd59977 | 2842 | |
5cedc27f K |
2843 | if (argc == 1) |
2844 | { | |
2845 | std::cout << "Usage: " << argv[0] << " Filename [Format]\n"; | |
7fd59977 | 2846 | return 1; |
2847 | } | |
2848 | ||
5cedc27f K |
2849 | Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF; |
2850 | TCollection_AsciiString aFormatStr; | |
2851 | ||
2852 | TCollection_AsciiString aFileName (argv[1]); | |
2853 | Standard_Integer aLen = aFileName.Length(); | |
2854 | ||
2855 | if (argc > 2) | |
2856 | { | |
2857 | aFormatStr = TCollection_AsciiString (argv[2]); | |
2858 | } | |
2859 | else if (aLen >= 4) | |
2860 | { | |
2861 | if (aFileName.Value (aLen - 2) == '.') | |
2862 | { | |
2863 | aFormatStr = aFileName.SubString (aLen - 1, aLen); | |
2864 | } | |
2865 | else if (aFileName.Value (aLen - 3) == '.') | |
2866 | { | |
2867 | aFormatStr = aFileName.SubString (aLen - 2, aLen); | |
2868 | } | |
2869 | else | |
2870 | { | |
2871 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
2872 | return 1; | |
2873 | } | |
2874 | } | |
2875 | else | |
2876 | { | |
2877 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
2878 | return 1; | |
2879 | } | |
2880 | ||
2881 | aFormatStr.UpperCase(); | |
2882 | if (aFormatStr == "PS") | |
2883 | anExpFormat = Graphic3d_EF_PostScript; | |
2884 | else if (aFormatStr == "EPS") | |
2885 | anExpFormat = Graphic3d_EF_EnhPostScript; | |
2886 | else if (aFormatStr == "TEX") | |
2887 | anExpFormat = Graphic3d_EF_TEX; | |
2888 | else if (aFormatStr == "PDF") | |
2889 | anExpFormat = Graphic3d_EF_PDF; | |
2890 | else if (aFormatStr == "SVG") | |
2891 | anExpFormat = Graphic3d_EF_SVG; | |
2892 | else if (aFormatStr == "PGF") | |
2893 | anExpFormat = Graphic3d_EF_PGF; | |
2894 | else if (aFormatStr == "EMF") | |
2895 | anExpFormat = Graphic3d_EF_EMF; | |
2896 | else | |
2897 | { | |
2898 | std::cout << "Invalid export format '" << aFormatStr << "'\n"; | |
2899 | return 1; | |
2900 | } | |
2901 | ||
9753e6de | 2902 | try { |
2903 | if (!V3dView->View()->Export (argv[1], anExpFormat)) | |
2904 | { | |
2905 | di << "Error: export of image to " << aFormatStr << " failed!\n"; | |
2906 | } | |
2907 | } | |
2908 | catch (Standard_Failure) | |
5cedc27f | 2909 | { |
9753e6de | 2910 | di << "Error: export of image to " << aFormatStr << " failed"; |
2911 | di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")"; | |
5cedc27f | 2912 | } |
7fd59977 | 2913 | return 0; |
2914 | } | |
2915 | ||
2916 | //============================================================================== | |
2917 | //function : VColorScale | |
2918 | //purpose : representation color scale | |
2919 | //============================================================================== | |
2920 | #include <V3d_ColorScale.hxx> | |
2921 | ||
2922 | static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) | |
2923 | { | |
2924 | if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 ) | |
2925 | { | |
2926 | di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n"; | |
2927 | return 1; | |
2928 | } | |
2929 | ||
2930 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
2931 | if(aContext.IsNull()) { | |
2932 | di << argv[0] << " ERROR : use 'vinit' command before " << "\n"; | |
2933 | return -1; | |
2934 | } | |
2935 | ||
2936 | Standard_Real minRange = 0. , maxRange = 100. ; | |
2937 | ||
2938 | Standard_Integer numIntervals = 10 ; | |
208e6839 | 2939 | Standard_Integer textHeight = 16; |
7fd59977 | 2940 | Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT; |
2941 | Standard_Real X = 0., Y = 0. ; | |
2942 | ||
2943 | if ( argc < 9 ) | |
2944 | { | |
2945 | if( argc > 3 ) | |
2946 | { | |
91322f44 | 2947 | minRange = Draw::Atof( argv[1] ); |
2948 | maxRange = Draw::Atof( argv[2] ); | |
2949 | numIntervals = Draw::Atoi( argv[3] ); | |
7fd59977 | 2950 | } |
2951 | if ( argc > 4 ) | |
91322f44 | 2952 | textHeight = Draw::Atoi( argv[4] ); |
7fd59977 | 2953 | if ( argc > 5 ) |
91322f44 | 2954 | position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] ); |
7fd59977 | 2955 | if ( argc > 7 ) |
2956 | { | |
91322f44 | 2957 | X = Draw::Atof( argv[6] ); |
2958 | Y = Draw::Atof( argv[7] ); | |
7fd59977 | 2959 | } |
2960 | } | |
2961 | Handle(V3d_View) curView = ViewerTest::CurrentView( ); | |
2962 | if ( curView.IsNull( ) ) | |
2963 | return 1; | |
2964 | Handle(Aspect_ColorScale) aCSV = curView->ColorScale( ); | |
2965 | Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) ); | |
2966 | if( ! aCS.IsNull( ) ) | |
2967 | { | |
2968 | aCS->SetPosition( X , Y ); | |
2969 | aCS->SetHeight( 0.95) ; | |
2970 | aCS->SetTextHeight( textHeight ); | |
2971 | aCS->SetRange( minRange , maxRange ); | |
2972 | aCS->SetNumberOfIntervals( numIntervals ); | |
2973 | aCS->SetLabelPosition( position ); | |
2974 | if( !curView->ColorScaleIsDisplayed() ) | |
2975 | curView->ColorScaleDisplay( ); | |
2976 | } | |
2977 | return 0; | |
2978 | } | |
2979 | ||
2980 | //============================================================================== | |
2981 | //function : VGraduatedTrihedron | |
2982 | //purpose : Displays a graduated trihedron | |
2983 | //============================================================================== | |
13a22457 S |
2984 | |
2985 | static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg) | |
2986 | { | |
2987 | const char *str = arg; | |
2988 | while (*str) | |
2989 | { | |
2990 | unsigned short c1 = *str++; | |
2991 | unsigned short c2 = *str++; | |
2992 | if (!c1 || !c2) break; | |
2993 | name += (Standard_ExtCharacter)((c1 << 8) | c2); | |
2994 | } | |
2995 | } | |
2996 | ||
7fd59977 | 2997 | static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
2998 | { | |
13a22457 S |
2999 | // Check arguments |
3000 | if (argc != 2 && argc < 5) | |
3001 | { | |
3002 | di<<"Error: "<<argv[0]<<" - invalid number of arguments\n"; | |
3003 | di<<"Usage: type help "<<argv[0]<<"\n"; | |
3004 | return 1; //TCL_ERROR | |
3005 | } | |
7fd59977 | 3006 | |
13a22457 S |
3007 | Handle(V3d_View) aV3dView = ViewerTest::CurrentView(); |
3008 | ||
3009 | // Create 3D view if it doesn't exist | |
3010 | if ( aV3dView.IsNull() ) | |
7fd59977 | 3011 | { |
4fe56619 | 3012 | ViewerTest::ViewerInit(); |
13a22457 S |
3013 | aV3dView = ViewerTest::CurrentView(); |
3014 | if( aV3dView.IsNull() ) | |
3015 | { | |
3016 | di << "Error: Cannot create a 3D view\n"; | |
3017 | return 1; //TCL_ERROR | |
3018 | } | |
7fd59977 | 3019 | } |
3020 | ||
13a22457 | 3021 | // Erase (==0) or display (!=0) |
91322f44 | 3022 | const int display = Draw::Atoi(argv[1]); |
7fd59977 | 3023 | |
13a22457 | 3024 | if (display) |
7fd59977 | 3025 | { |
13a22457 S |
3026 | // Text font |
3027 | TCollection_AsciiString font; | |
3028 | if (argc < 6) | |
3029 | font.AssignCat("Courier"); | |
3030 | else | |
3031 | font.AssignCat(argv[5]); | |
3032 | ||
3033 | // Text is multibyte | |
91322f44 | 3034 | const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0); |
13a22457 S |
3035 | |
3036 | // Set axis names | |
3037 | TCollection_ExtendedString xname, yname, zname; | |
3038 | if (argc >= 5) | |
3039 | { | |
3040 | if (isMultibyte) | |
7fd59977 | 3041 | { |
13a22457 S |
3042 | AddMultibyteString(xname, argv[2]); |
3043 | AddMultibyteString(yname, argv[3]); | |
3044 | AddMultibyteString(zname, argv[4]); | |
7fd59977 | 3045 | } |
13a22457 S |
3046 | else |
3047 | { | |
3048 | xname += argv[2]; | |
3049 | yname += argv[3]; | |
3050 | zname += argv[4]; | |
3051 | } | |
3052 | } | |
3053 | else | |
3054 | { | |
3055 | xname += "X (mm)"; | |
3056 | yname += "Y (mm)"; | |
3057 | zname += "Z (mm)"; | |
3058 | } | |
7fd59977 | 3059 | |
13a22457 S |
3060 | aV3dView->GraduatedTrihedronDisplay(xname, yname, zname, |
3061 | Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/, | |
3062 | Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/, | |
3063 | Standard_True/*drawgrid*/, | |
3064 | Standard_True/*drawaxes*/, | |
3065 | 5/*nbx*/, 5/*nby*/, 5/*nbz*/, | |
3066 | 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/, | |
3067 | 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/, | |
3068 | Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/, | |
3069 | 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/, | |
3070 | Quantity_NOC_WHITE/*gridcolor*/, | |
3071 | Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/, | |
3072 | Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font); | |
3073 | } | |
7fd59977 | 3074 | else |
13a22457 | 3075 | aV3dView->GraduatedTrihedronErase(); |
7fd59977 | 3076 | |
3077 | ViewerTest::GetAISContext()->UpdateCurrentViewer(); | |
13a22457 S |
3078 | aV3dView->Redraw(); |
3079 | ||
7fd59977 | 3080 | return 0; |
3081 | } | |
3082 | ||
7edf74fd A |
3083 | //============================================================================== |
3084 | //function : VPrintView | |
3085 | //purpose : Test printing algorithm, print the view to image file with given | |
3086 | // width and height. Printing implemented only for WNT. | |
3087 | //============================================================================== | |
4fe56619 | 3088 | static int VPrintView (Draw_Interpretor& di, Standard_Integer argc, |
7edf74fd A |
3089 | const char** argv) |
3090 | { | |
3091 | #ifndef WNT | |
3092 | di << "Printing implemented only for wnt!\n"; | |
3093 | return 1; | |
3094 | #else | |
3095 | ||
3096 | Handle(AIS_InteractiveContext) aContextAIS = NULL; | |
3097 | Handle(V3d_View) aView = NULL; | |
3098 | aContextAIS = ViewerTest::GetAISContext(); | |
3099 | if (!aContextAIS.IsNull()) | |
3100 | { | |
3101 | const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer(); | |
3102 | Vwr->InitActiveViews(); | |
3103 | if(Vwr->MoreActiveViews()) | |
3104 | aView = Vwr->ActiveView(); | |
3105 | } | |
3106 | ||
3107 | // check for errors | |
3108 | if (aView.IsNull()) | |
3109 | { | |
3110 | di << "Call vinit before!\n"; | |
3111 | return 1; | |
3112 | } | |
3113 | else if (argc < 4) | |
3114 | { | |
3115 | di << "Use: " << argv[0]; | |
3116 | di << " width height filename [print algo=0]\n"; | |
3117 | di << "width, height of the intermediate buffer for operation\n"; | |
3118 | di << "algo : {0|1}\n"; | |
3119 | di << " 0 - stretch algorithm\n"; | |
3120 | di << " 1 - tile algorithm\n"; | |
3121 | di << "test printing algorithms into an intermediate buffer\n"; | |
3122 | di << "with saving output to an image file\n"; | |
3123 | return 1; | |
3124 | } | |
3125 | ||
3126 | // get the input params | |
91322f44 | 3127 | Standard_Integer aWidth = Draw::Atoi (argv[1]); |
3128 | Standard_Integer aHeight = Draw::Atoi (argv[2]); | |
7edf74fd A |
3129 | Standard_Integer aMode = 0; |
3130 | TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]); | |
3131 | if (argc==5) | |
91322f44 | 3132 | aMode = Draw::Atoi (argv[4]); |
7edf74fd A |
3133 | |
3134 | // check the input parameters | |
3135 | if (aWidth <= 0 || aHeight <= 0) | |
3136 | { | |
3137 | di << "Width and height must be positive values!\n"; | |
3138 | return 1; | |
3139 | } | |
3140 | if (aMode != 0 && aMode != 1) | |
3141 | aMode = 0; | |
3142 | ||
7edf74fd | 3143 | // define compatible bitmap |
692613e5 | 3144 | HDC anDC = CreateCompatibleDC(0); |
7edf74fd A |
3145 | BITMAPINFO aBitmapData; |
3146 | memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER)); | |
3147 | aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); | |
3148 | aBitmapData.bmiHeader.biWidth = aWidth ; | |
3149 | aBitmapData.bmiHeader.biHeight = aHeight; | |
3150 | aBitmapData.bmiHeader.biPlanes = 1; | |
3151 | aBitmapData.bmiHeader.biBitCount = 24; | |
3152 | aBitmapData.bmiHeader.biXPelsPerMeter = 0; | |
3153 | aBitmapData.bmiHeader.biYPelsPerMeter = 0; | |
3154 | aBitmapData.bmiHeader.biClrUsed = 0; | |
3155 | aBitmapData.bmiHeader.biClrImportant = 0; | |
3156 | aBitmapData.bmiHeader.biCompression = BI_RGB; | |
3157 | aBitmapData.bmiHeader.biSizeImage = 0; | |
3158 | ||
3159 | // Create Device Independent Bitmap | |
692613e5 | 3160 | void* aBitsOut = NULL; |
7edf74fd | 3161 | HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS, |
692613e5 | 3162 | &aBitsOut, NULL, 0); |
7edf74fd A |
3163 | HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap); |
3164 | ||
3165 | Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False; | |
692613e5 | 3166 | if (aBitsOut != NULL) |
4fe56619 | 3167 | { |
7edf74fd A |
3168 | if (aMode == 0) |
3169 | isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH); | |
3170 | else | |
3171 | isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE); | |
3172 | ||
3173 | // succesfully printed into an intermediate buffer | |
3174 | if (isPrinted) | |
3175 | { | |
692613e5 | 3176 | Image_PixMap aWrapper; |
3177 | aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4); | |
3178 | aWrapper.SetTopDown (false); | |
3179 | ||
3180 | Image_AlienPixMap anImageBitmap; | |
3181 | anImageBitmap.InitCopy (aWrapper); | |
3182 | isSaved = anImageBitmap.Save (aFileName); | |
7edf74fd A |
3183 | } |
3184 | else | |
3185 | { | |
3186 | di << "Print operation failed due to printing errors or\n"; | |
3187 | di << "insufficient memory available\n"; | |
3188 | di << "Please, try to use smaller dimensions for this test\n"; | |
3189 | di << "command, as it allocates intermediate buffer for storing\n"; | |
3190 | di << "the result\n"; | |
3191 | } | |
3192 | } | |
3193 | else | |
3194 | { | |
3195 | di << "Can't allocate memory for intermediate buffer\n"; | |
3196 | di << "Please use smaller dimensions\n"; | |
3197 | } | |
3198 | ||
3199 | if (aMemoryBitmap) | |
3200 | { | |
3201 | SelectObject (anDC, anOldBitmap); | |
3202 | DeleteObject (aMemoryBitmap); | |
3203 | DeleteDC(anDC); | |
3204 | } | |
3205 | ||
3206 | if (!isSaved) | |
3207 | { | |
3208 | di << "Save to file operation failed. This operation may fail\n"; | |
3209 | di << "if you don't have enough available memory, then you can\n"; | |
3210 | di << "use smaller dimensions for the output file\n"; | |
3211 | return 1; | |
3212 | } | |
3213 | ||
3214 | return 0; | |
3215 | ||
3216 | #endif | |
3217 | } | |
3218 | ||
59f45b7c | 3219 | //============================================================================== |
3220 | //function : VZLayer | |
3221 | //purpose : Test z layer operations for v3d viewer | |
3222 | //============================================================================== | |
3223 | static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3224 | { | |
3225 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext (); | |
3226 | if (aContextAIS.IsNull()) | |
3227 | { | |
3228 | di << "Call vinit before!\n"; | |
3229 | return 1; | |
3230 | } | |
3231 | else if (argc < 2) | |
3232 | { | |
3233 | di << "Use: vzlayer " << argv[0]; | |
3234 | di << " add/del/get [id]\n"; | |
3235 | di << " add - add new z layer to viewer and print its id\n"; | |
3236 | di << " del - del z layer by its id\n"; | |
3237 | di << " get - print sequence of z layers in increasing order of their overlay level\n"; | |
3238 | di << "id - the layer identificator value defined when removing z layer\n"; | |
3239 | return 1; | |
3240 | } | |
3241 | ||
3242 | const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); | |
3243 | if (aViewer.IsNull()) | |
3244 | { | |
3245 | di << "No active viewer!\n"; | |
3246 | return 1; | |
3247 | } | |
3248 | ||
3249 | // perform operation | |
3250 | TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]); | |
3251 | if (anOp == "add") | |
3252 | { | |
3253 | Standard_Integer aNewId; | |
3254 | if (!aViewer->AddZLayer (aNewId)) | |
3255 | { | |
3256 | di << "Impossible to add new z layer!\n"; | |
3257 | return 1; | |
3258 | } | |
3259 | ||
3260 | di << "New z layer added with index: " << aNewId << "\n"; | |
3261 | } | |
3262 | else if (anOp == "del") | |
3263 | { | |
3264 | if (argc < 3) | |
3265 | { | |
3266 | di << "Please also provide as argument id of z layer to remove\n"; | |
3267 | return 1; | |
3268 | } | |
3269 | ||
91322f44 | 3270 | Standard_Integer aDelId = Draw::Atoi (argv[2]); |
59f45b7c | 3271 | if (!aViewer->RemoveZLayer (aDelId)) |
3272 | { | |
3273 | di << "Impossible to remove the z layer or invalid id!\n"; | |
3274 | return 1; | |
3275 | } | |
3276 | ||
3277 | di << "Z layer " << aDelId << " has been removed\n"; | |
3278 | } | |
3279 | else if (anOp == "get") | |
3280 | { | |
3281 | TColStd_SequenceOfInteger anIds; | |
3282 | aViewer->GetAllZLayers (anIds); | |
3283 | for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++) | |
3284 | { | |
3285 | di << anIds.Value (aSeqIdx) << " "; | |
3286 | } | |
3287 | ||
3288 | di << "\n"; | |
3289 | } | |
3290 | else | |
3291 | { | |
3292 | di << "Invalid operation, please use { add / del / get }\n"; | |
3293 | return 1; | |
3294 | } | |
3295 | ||
3296 | return 0; | |
3297 | } | |
3298 | ||
25289ec1 | 3299 | DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem) |
3300 | ||
3301 | // this class provides a presentation of text item in v3d view under-/overlayer | |
3302 | class V3d_TextItem : public Visual3d_LayerItem | |
3303 | { | |
3304 | public: | |
3305 | ||
3306 | // CASCADE RTTI | |
3307 | DEFINE_STANDARD_RTTI(V3d_TextItem) | |
3308 | ||
3309 | // constructor | |
3310 | Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText, | |
3311 | const Standard_Real theX1, | |
3312 | const Standard_Real theY1, | |
3313 | const Standard_Real theHeight, | |
3314 | const TCollection_AsciiString& theFontName, | |
3315 | const Quantity_Color& theColor, | |
3316 | const Quantity_Color& theSubtitleColor, | |
3317 | const Aspect_TypeOfDisplayText& theTypeOfDisplay, | |
3318 | const Handle(Visual3d_Layer)& theLayer); | |
3319 | ||
3320 | // redraw method | |
3321 | Standard_EXPORT void RedrawLayerPrs(); | |
3322 | ||
3323 | private: | |
3324 | ||
3325 | Standard_Real myX1; | |
3326 | Standard_Real myY1; | |
3327 | Standard_Real myHeight; | |
3328 | TCollection_AsciiString myText; | |
3329 | TCollection_AsciiString myFontName; | |
3330 | Quantity_Color myColor; | |
3331 | Quantity_Color mySubtitleColor; | |
3332 | Aspect_TypeOfDisplayText myType; | |
3333 | Handle(Visual3d_Layer) myLayer; | |
3334 | ||
3335 | }; | |
3336 | ||
3337 | IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem) | |
3338 | IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem) | |
3339 | ||
3340 | // create and add to display the text item | |
3341 | V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText, | |
3342 | const Standard_Real theX1, | |
3343 | const Standard_Real theY1, | |
3344 | const Standard_Real theHeight, | |
3345 | const TCollection_AsciiString& theFontName, | |
3346 | const Quantity_Color& theColor, | |
3347 | const Quantity_Color& theSubtitleColor, | |
3348 | const Aspect_TypeOfDisplayText& theTypeOfDisplay, | |
3349 | const Handle(Visual3d_Layer)& theLayer) | |
3350 | : myX1 (theX1), myY1 (theY1), | |
3351 | myText (theText), | |
3352 | myHeight (theHeight), | |
3353 | myLayer (theLayer), | |
3354 | myColor (theColor), | |
3355 | mySubtitleColor (theSubtitleColor), | |
3356 | myType (theTypeOfDisplay), | |
3357 | myFontName (theFontName) | |
3358 | { | |
3359 | if (!myLayer.IsNull ()) | |
3360 | myLayer->AddLayerItem (this); | |
3361 | } | |
3362 | ||
3363 | // render item | |
3364 | void V3d_TextItem::RedrawLayerPrs () | |
4fe56619 | 3365 | { |
25289ec1 | 3366 | if (myLayer.IsNull ()) |
3367 | return; | |
3368 | ||
3369 | myLayer->SetColor (myColor); | |
3370 | myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor); | |
3371 | myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight); | |
3372 | } | |
3373 | ||
20637bd2 | 3374 | DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem) |
3375 | ||
3376 | // The Visual3d_LayerItem line item for "vlayerline" command | |
4fe56619 | 3377 | // it provides a presentation of line with user-defined |
20637bd2 | 3378 | // linewidth, linetype and transparency. |
4fe56619 | 3379 | class V3d_LineItem : public Visual3d_LayerItem |
20637bd2 | 3380 | { |
3381 | public: | |
3382 | // CASCADE RTTI | |
4fe56619 | 3383 | DEFINE_STANDARD_RTTI(V3d_LineItem) |
3384 | ||
20637bd2 | 3385 | // constructor |
3386 | Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1, | |
3387 | Standard_Real X2, Standard_Real Y2, | |
3388 | V3d_LayerMgrPointer theLayerMgr, | |
3389 | Aspect_TypeOfLine theType = Aspect_TOL_SOLID, | |
3390 | Standard_Real theWidth = 0.5, | |
3391 | Standard_Real theTransp = 1.0); | |
3392 | ||
3393 | // redraw method | |
3394 | Standard_EXPORT void RedrawLayerPrs(); | |
3395 | ||
3396 | private: | |
3397 | ||
3398 | Standard_Real myX1, myY1, myX2, myY2; | |
3399 | Standard_Real myWidth; | |
3400 | Standard_Real myTransparency; | |
3401 | Aspect_TypeOfLine myType; | |
3402 | V3d_LayerMgrPointer myLayerMgr; | |
3403 | }; | |
3404 | ||
3405 | IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem) | |
3406 | IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem) | |
3407 | ||
3408 | // default constructor for line item | |
4fe56619 | 3409 | V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1, |
20637bd2 | 3410 | Standard_Real X2, Standard_Real Y2, |
3411 | V3d_LayerMgrPointer theLayerMgr, | |
3412 | Aspect_TypeOfLine theType, | |
3413 | Standard_Real theWidth, | |
3414 | Standard_Real theTransp) : | |
3415 | myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr), | |
3416 | myType(theType), myWidth(theWidth), myTransparency(theTransp) | |
3417 | { | |
9e4c2fbb | 3418 | if (myLayerMgr && !myLayerMgr->Overlay().IsNull()) |
20637bd2 | 3419 | myLayerMgr->Overlay()->AddLayerItem (this); |
3420 | } | |
3421 | ||
3422 | // render line | |
3423 | void V3d_LineItem::RedrawLayerPrs () | |
3424 | { | |
3425 | Handle (Visual3d_Layer) aOverlay; | |
4fe56619 | 3426 | |
20637bd2 | 3427 | if (myLayerMgr) |
3428 | aOverlay = myLayerMgr->Overlay(); | |
3429 | ||
3430 | if (!aOverlay.IsNull()) | |
3431 | { | |
3432 | Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB); | |
3433 | aOverlay->SetColor(aColor); | |
3434 | aOverlay->SetTransparency((Standard_ShortReal)myTransparency); | |
3435 | aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth); | |
3436 | aOverlay->BeginPolyline(); | |
3437 | aOverlay->AddVertex(myX1, myY1); | |
3438 | aOverlay->AddVertex(myX2, myY2); | |
3439 | aOverlay->ClosePrimitive(); | |
3440 | } | |
3441 | } | |
3442 | ||
3443 | //============================================================================= | |
3444 | //function : VLayerLine | |
3445 | //purpose : Draws line in the v3d view layer with given attributes: linetype, | |
3446 | // : linewidth, transparency coefficient | |
3447 | //============================================================================ | |
3448 | static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3449 | { | |
3450 | // get the active view | |
3451 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3452 | if (aView.IsNull()) | |
3453 | { | |
3454 | di << "Call vinit before!\n"; | |
3455 | return 1; | |
3456 | } | |
3457 | else if (argc < 5) | |
3458 | { | |
3459 | di << "Use: " << argv[0]; | |
3460 | di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n"; | |
3461 | di << " linetype : { 0 | 1 | 2 | 3 } \n"; | |
3462 | di << " 0 - solid \n"; | |
3463 | di << " 1 - dashed \n"; | |
3464 | di << " 2 - dot \n"; | |
3465 | di << " 3 - dashdot\n"; | |
3466 | di << " transparency : { 0.0 - 1.0 } \n"; | |
3467 | di << " 0.0 - transparent\n"; | |
3468 | di << " 1.0 - visible \n"; | |
3469 | return 1; | |
3470 | } | |
3471 | ||
3472 | // get the input params | |
91322f44 | 3473 | Standard_Real X1 = Draw::Atof(argv[1]); |
3474 | Standard_Real Y1 = Draw::Atof(argv[2]); | |
3475 | Standard_Real X2 = Draw::Atof(argv[3]); | |
3476 | Standard_Real Y2 = Draw::Atof(argv[4]); | |
20637bd2 | 3477 | |
3478 | Standard_Real aWidth = 0.5; | |
3479 | Standard_Integer aType = 0; | |
3480 | Standard_Real aTransparency = 1.0; | |
3481 | ||
3482 | // has width | |
3483 | if (argc > 5) | |
91322f44 | 3484 | aWidth = Draw::Atof(argv[5]); |
20637bd2 | 3485 | |
3486 | // has type | |
3487 | if (argc > 6) | |
91322f44 | 3488 | aType = (Standard_Integer) Draw::Atoi(argv[6]); |
20637bd2 | 3489 | |
3490 | // has transparency | |
3491 | if (argc > 7) | |
3492 | { | |
91322f44 | 3493 | aTransparency = Draw::Atof(argv[7]); |
4fe56619 | 3494 | if (aTransparency < 0 || aTransparency > 1.0) |
20637bd2 | 3495 | aTransparency = 1.0; |
3496 | } | |
3497 | ||
3498 | // select appropriate line type | |
3499 | Aspect_TypeOfLine aLineType; | |
3500 | switch (aType) | |
3501 | { | |
3502 | case 1: | |
3503 | aLineType = Aspect_TOL_DASH; | |
3504 | break; | |
3505 | ||
3506 | case 2: | |
3507 | aLineType = Aspect_TOL_DOT; | |
3508 | break; | |
3509 | ||
3510 | case 3: | |
3511 | aLineType = Aspect_TOL_DOTDASH; | |
3512 | break; | |
3513 | ||
3514 | default: | |
3515 | aLineType = Aspect_TOL_SOLID; | |
3516 | } | |
3517 | ||
3518 | // replace layer manager | |
3519 | Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView); | |
3520 | aView->SetLayerMgr(aMgr); | |
3521 | ||
3522 | // add line item | |
4fe56619 | 3523 | Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2, |
20637bd2 | 3524 | aMgr.operator->(), |
4fe56619 | 3525 | aLineType, aWidth, |
20637bd2 | 3526 | aTransparency); |
3527 | ||
3528 | // update view | |
3529 | aView->MustBeResized(); | |
3530 | aView->Redraw(); | |
3531 | ||
3532 | return 0; | |
3533 | } | |
3534 | ||
25289ec1 | 3535 | //======================================================================= |
3536 | //function : VOverlayText | |
3537 | //purpose : Test text displaying in view overlay | |
3538 | //======================================================================= | |
3539 | static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv) | |
3540 | { | |
3541 | // get the active view | |
3542 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3543 | if (aView.IsNull()) | |
3544 | { | |
3545 | di << "No active view. Please call vinit.\n"; | |
3546 | return 1; | |
3547 | } | |
3548 | else if (argc < 4 || argc > 13) | |
3549 | { | |
3550 | di << "Use: " << argv[0]; | |
3551 | di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n"; | |
3552 | di << "[background_color: R G B]\n"; | |
3553 | di << " height - pixel height of the text (default=10.0)\n"; | |
3554 | di << " font_name - name of font (default=courier)\n"; | |
3555 | di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n"; | |
3556 | di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n"; | |
3557 | di << " background_color- R G B values used for subtitle and decal text\n"; | |
3558 | di << "(default=255.0 255.0 255.0)\n"; | |
3559 | return 1; | |
3560 | } | |
4fe56619 | 3561 | |
25289ec1 | 3562 | TCollection_AsciiString aText (argv[1]); |
91322f44 | 3563 | Standard_Real aPosX = Draw::Atof(argv[2]); |
3564 | Standard_Real aPosY = Draw::Atof(argv[3]); | |
3565 | Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0; | |
25289ec1 | 3566 | |
3567 | // font name | |
3568 | TCollection_AsciiString aFontName = "Courier"; | |
3569 | if (argc >= 6) | |
3570 | aFontName = TCollection_AsciiString (argv[5]); | |
3571 | ||
3572 | // text colors | |
3573 | Quantity_Parameter aColorRed = 1.0; | |
3574 | Quantity_Parameter aColorGreen = 1.0; | |
3575 | Quantity_Parameter aColorBlue = 1.0; | |
3576 | if (argc >= 9) | |
3577 | { | |
91322f44 | 3578 | aColorRed = Draw::Atof (argv[6])/255.; |
3579 | aColorGreen = Draw::Atof (argv[7])/255.; | |
3580 | aColorBlue = Draw::Atof (argv[8])/255.; | |
25289ec1 | 3581 | } |
3582 | ||
3583 | // display type | |
3584 | TCollection_AsciiString aDispStr; | |
3585 | if (argc >= 10) | |
3586 | aDispStr = TCollection_AsciiString (argv[9]); | |
3587 | ||
3588 | Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL; | |
3589 | if (aDispStr.IsEqual ("subtitle")) | |
3590 | aTextType = Aspect_TODT_SUBTITLE; | |
3591 | else if (aDispStr.IsEqual ("decal")) | |
3592 | aTextType = Aspect_TODT_DEKALE; | |
3593 | else if (aDispStr.IsEqual ("blend")) | |
3594 | aTextType = Aspect_TODT_BLEND; | |
3595 | ||
3596 | // subtitle color | |
3597 | Quantity_Parameter aSubRed = 1.0; | |
3598 | Quantity_Parameter aSubGreen = 1.0; | |
3599 | Quantity_Parameter aSubBlue = 1.0; | |
3600 | if (argc == 13) | |
3601 | { | |
91322f44 | 3602 | aSubRed = Draw::Atof (argv[10])/255.; |
3603 | aSubGreen = Draw::Atof (argv[11])/255.; | |
3604 | aSubBlue = Draw::Atof (argv[12])/255.; | |
25289ec1 | 3605 | } |
3606 | ||
3607 | // check fo current overlay | |
3608 | Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer (); | |
3609 | if (anOverlay.IsNull ()) | |
3610 | { | |
3611 | Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView); | |
3612 | anOverlay = aMgr->Overlay (); | |
3613 | aView->SetLayerMgr (aMgr); | |
3614 | } | |
3615 | ||
4fe56619 | 3616 | Quantity_Color aTextColor (aColorRed, aColorGreen, |
25289ec1 | 3617 | aColorBlue, Quantity_TOC_RGB); |
4fe56619 | 3618 | Quantity_Color aSubtColor (aSubRed, aSubGreen, |
25289ec1 | 3619 | aSubBlue, Quantity_TOC_RGB); |
3620 | ||
3621 | // add text item | |
3622 | Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY, | |
3623 | aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay); | |
3624 | ||
3625 | // update view | |
3626 | aView->MustBeResized(); | |
3627 | aView->Redraw(); | |
3628 | ||
3629 | return 0; | |
3630 | } | |
3631 | ||
2bd4c032 | 3632 | //============================================================================== |
3633 | //function : VGrid | |
3634 | //purpose : | |
3635 | //============================================================================== | |
3636 | ||
35e08fe8 | 3637 | static int VGrid (Draw_Interpretor& /*theDI*/, |
2bd4c032 | 3638 | Standard_Integer theArgNb, |
3639 | const char** theArgVec) | |
3640 | { | |
3641 | // get the active view | |
3642 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3643 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
3644 | if (aView.IsNull() || aViewer.IsNull()) | |
3645 | { | |
3646 | std::cerr << "No active view. Please call vinit.\n"; | |
3647 | return 1; | |
3648 | } | |
3649 | ||
3650 | Aspect_GridType aType = aViewer->GridType(); | |
3651 | Aspect_GridDrawMode aMode = aViewer->GridDrawMode(); | |
3652 | ||
3653 | Standard_Integer anIter = 1; | |
3654 | for (; anIter < theArgNb; ++anIter) | |
3655 | { | |
3656 | const char* aValue = theArgVec[anIter]; | |
3657 | if (*aValue == 'r') | |
3658 | { | |
3659 | aType = Aspect_GT_Rectangular; | |
3660 | } | |
3661 | else if (*aValue == 'c') | |
3662 | { | |
3663 | aType = Aspect_GT_Circular; | |
3664 | } | |
3665 | else if (*aValue == 'l') | |
3666 | { | |
3667 | aMode = Aspect_GDM_Lines; | |
3668 | } | |
3669 | else if (*aValue == 'p') | |
3670 | { | |
3671 | aMode = Aspect_GDM_Points; | |
3672 | } | |
3673 | else if (strcmp (aValue, "off" ) == 0) | |
3674 | { | |
3675 | aViewer->DeactivateGrid(); | |
3676 | return 0; | |
3677 | } | |
3678 | else | |
3679 | { | |
3680 | break; | |
3681 | } | |
3682 | } | |
3683 | ||
3684 | Standard_Integer aTail = (theArgNb - anIter); | |
3685 | if (aTail == 0) | |
3686 | { | |
3687 | aViewer->ActivateGrid (aType, aMode); | |
3688 | return 0; | |
3689 | } | |
3690 | else if (aTail != 2 && aTail != 5) | |
3691 | { | |
3692 | std::cerr << "Incorrect arguments number! Usage:\n" | |
3693 | << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n"; | |
3694 | return 1; | |
3695 | } | |
3696 | ||
3697 | Quantity_Length anOriginX, anOriginY; | |
3698 | Quantity_PlaneAngle aRotAngle; | |
3699 | if (aType == Aspect_GT_Rectangular) | |
3700 | { | |
3701 | Quantity_Length aRStepX, aRStepY; | |
3702 | aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); | |
3703 | ||
91322f44 | 3704 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
3705 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 3706 | if (aTail == 5) |
3707 | { | |
91322f44 | 3708 | aRStepX = Draw::Atof (theArgVec[anIter++]); |
3709 | aRStepY = Draw::Atof (theArgVec[anIter++]); | |
3710 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 3711 | } |
3712 | aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); | |
3713 | aViewer->ActivateGrid (aType, aMode); | |
3714 | } | |
3715 | else if (aType == Aspect_GT_Circular) | |
3716 | { | |
3717 | Quantity_Length aRadiusStep; | |
3718 | Standard_Integer aDivisionNumber; | |
3719 | aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
3720 | ||
91322f44 | 3721 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
3722 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 3723 | if (aTail == 5) |
3724 | { | |
91322f44 | 3725 | aRadiusStep = Draw::Atof (theArgVec[anIter++]); |
3726 | aDivisionNumber = Draw::Atoi (theArgVec[anIter++]); | |
3727 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 3728 | } |
3729 | ||
3730 | aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
3731 | aViewer->ActivateGrid (aType, aMode); | |
3732 | } | |
3733 | ||
3734 | return 0; | |
3735 | } | |
3736 | ||
208e6839 | 3737 | //============================================================================== |
3738 | //function : VFps | |
3739 | //purpose : | |
3740 | //============================================================================== | |
3741 | ||
3742 | static int VFps (Draw_Interpretor& theDI, | |
3743 | Standard_Integer theArgNb, | |
3744 | const char** theArgVec) | |
3745 | { | |
3746 | // get the active view | |
3747 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3748 | if (aView.IsNull()) | |
3749 | { | |
3750 | std::cerr << "No active view. Please call vinit.\n"; | |
3751 | return 1; | |
3752 | } | |
3753 | ||
91322f44 | 3754 | Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100; |
208e6839 | 3755 | if (aFramesNb <= 0) |
3756 | { | |
3757 | std::cerr << "Incorrect arguments!\n"; | |
3758 | return 1; | |
3759 | } | |
3760 | ||
3761 | // the time is meaningless for first call | |
3762 | // due to async OpenGl rendering | |
3763 | aView->Redraw(); | |
3764 | ||
3765 | // redraw view in loop to estimate average values | |
3766 | OSD_Timer aTimer; | |
3767 | aTimer.Start(); | |
3768 | for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter) | |
3769 | { | |
3770 | aView->Redraw(); | |
3771 | } | |
3772 | aTimer.Stop(); | |
3773 | Standard_Real aCpu; | |
3774 | const Standard_Real aTime = aTimer.ElapsedTime(); | |
3775 | aTimer.OSD_Chronometer::Show (aCpu); | |
3776 | ||
3777 | const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime; | |
3778 | const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb); | |
3779 | ||
3780 | // return statistics | |
3781 | theDI << "FPS: " << aFpsAver << "\n" | |
3782 | << "CPU: " << (1000.0 * aCpuAver) << " msec\n"; | |
3783 | ||
3784 | return 0; | |
3785 | } | |
3786 | ||
3787 | ||
3788 | //============================================================================== | |
3789 | //function : VVbo | |
3790 | //purpose : | |
3791 | //============================================================================== | |
3792 | ||
35e08fe8 | 3793 | static int VVbo (Draw_Interpretor& /*theDI*/, |
208e6839 | 3794 | Standard_Integer theArgNb, |
3795 | const char** theArgVec) | |
3796 | { | |
3797 | // get the context | |
3798 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
3799 | if (aContextAIS.IsNull()) | |
3800 | { | |
3801 | std::cerr << "No active view. Please call vinit.\n"; | |
3802 | return 1; | |
3803 | } | |
3804 | ||
dc3fe572 | 3805 | Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver(); |
3806 | ||
208e6839 | 3807 | if (aDriver.IsNull()) |
3808 | { | |
3809 | std::cerr << "Graphic driver not available.\n"; | |
3810 | return 1; | |
3811 | } | |
3812 | ||
3813 | if (theArgNb < 2) | |
3814 | { | |
3815 | //theDI << "VBO: " << aDriver->ToUseVBO() << "\n"; | |
3816 | //return 0; | |
3817 | std::cerr << "Wrong number of arguments.\n"; | |
3818 | return 1; | |
3819 | } | |
3820 | ||
91322f44 | 3821 | aDriver->EnableVBO (Draw::Atoi(theArgVec[1]) != 0); |
208e6839 | 3822 | return 0; |
3823 | } | |
3824 | ||
f0430952 | 3825 | //============================================================================== |
3826 | //function : VMemGpu | |
3827 | //purpose : | |
3828 | //============================================================================== | |
3829 | ||
3830 | static int VMemGpu (Draw_Interpretor& theDI, | |
3831 | Standard_Integer theArgNb, | |
3832 | const char** theArgVec) | |
3833 | { | |
3834 | // get the context | |
3835 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
3836 | if (aContextAIS.IsNull()) | |
3837 | { | |
3838 | std::cerr << "No active view. Please call vinit.\n"; | |
3839 | return 1; | |
3840 | } | |
3841 | ||
dc3fe572 | 3842 | Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver(); |
3843 | ||
f0430952 | 3844 | if (aDriver.IsNull()) |
3845 | { | |
3846 | std::cerr << "Graphic driver not available.\n"; | |
3847 | return 1; | |
3848 | } | |
3849 | ||
3850 | Standard_Size aFreeBytes = 0; | |
3851 | TCollection_AsciiString anInfo; | |
3852 | if (!aDriver->MemoryInfo (aFreeBytes, anInfo)) | |
3853 | { | |
3854 | std::cerr << "Information not available.\n"; | |
3855 | return 1; | |
3856 | } | |
3857 | ||
3858 | if (theArgNb > 1 && *theArgVec[1] == 'f') | |
3859 | { | |
3860 | theDI << Standard_Real (aFreeBytes); | |
3861 | } | |
3862 | else | |
3863 | { | |
3864 | theDI << anInfo; | |
3865 | } | |
3866 | ||
3867 | return 0; | |
3868 | } | |
3869 | ||
85e096c3 | 3870 | // ============================================================================== |
3871 | // function : VReadPixel | |
3872 | // purpose : | |
3873 | // ============================================================================== | |
3874 | static int VReadPixel (Draw_Interpretor& theDI, | |
3875 | Standard_Integer theArgNb, | |
3876 | const char** theArgVec) | |
3877 | { | |
3878 | // get the active view | |
3879 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3880 | if (aView.IsNull()) | |
3881 | { | |
3882 | std::cerr << "No active view. Please call vinit.\n"; | |
3883 | return 1; | |
3884 | } | |
3885 | else if (theArgNb < 3) | |
3886 | { | |
3887 | std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n"; | |
3888 | return 1; | |
3889 | } | |
3890 | ||
692613e5 | 3891 | Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; |
3892 | Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA; | |
3893 | ||
85e096c3 | 3894 | Standard_Integer aWidth, aHeight; |
3895 | aView->Window()->Size (aWidth, aHeight); | |
91322f44 | 3896 | const Standard_Integer anX = Draw::Atoi (theArgVec[1]); |
3897 | const Standard_Integer anY = Draw::Atoi (theArgVec[2]); | |
85e096c3 | 3898 | if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight) |
3899 | { | |
3900 | std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n"; | |
3901 | return 1; | |
3902 | } | |
3903 | ||
3904 | Standard_Boolean toShowName = Standard_False; | |
3905 | Standard_Boolean toShowHls = Standard_False; | |
3906 | for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter) | |
3907 | { | |
3908 | TCollection_AsciiString aParam (theArgVec[anIter]); | |
3909 | if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgb"))) | |
3910 | { | |
692613e5 | 3911 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; |
3912 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 3913 | } |
3914 | else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("hls"))) | |
3915 | { | |
692613e5 | 3916 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; |
3917 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 3918 | toShowHls = Standard_True; |
3919 | } | |
3920 | else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbf"))) | |
3921 | { | |
692613e5 | 3922 | aFormat = Image_PixMap::ImgRGBF; |
3923 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 3924 | } |
3925 | else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgba"))) | |
3926 | { | |
692613e5 | 3927 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; |
3928 | aBufferType = Graphic3d_BT_RGBA; | |
85e096c3 | 3929 | } |
3930 | else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbaf"))) | |
3931 | { | |
692613e5 | 3932 | aFormat = Image_PixMap::ImgRGBAF; |
3933 | aBufferType = Graphic3d_BT_RGBA; | |
85e096c3 | 3934 | } |
3935 | else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("depth"))) | |
3936 | { | |
692613e5 | 3937 | aFormat = Image_PixMap::ImgGrayF; |
3938 | aBufferType = Graphic3d_BT_Depth; | |
85e096c3 | 3939 | } |
3940 | else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("name"))) | |
3941 | { | |
3942 | toShowName = Standard_True; | |
3943 | } | |
3944 | } | |
3945 | ||
692613e5 | 3946 | Image_PixMap anImage; |
3947 | if (!anImage.InitTrash (aFormat, aWidth, aHeight)) | |
3948 | { | |
3949 | std::cerr << "Image allocation failed\n"; | |
3950 | return 1; | |
3951 | } | |
3952 | else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType)) | |
85e096c3 | 3953 | { |
3954 | std::cerr << "Image dump failed\n"; | |
3955 | return 1; | |
3956 | } | |
3957 | ||
3958 | Quantity_Parameter anAlpha; | |
692613e5 | 3959 | Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha); |
85e096c3 | 3960 | if (toShowName) |
3961 | { | |
692613e5 | 3962 | if (aBufferType == Graphic3d_BT_RGBA) |
85e096c3 | 3963 | { |
3964 | theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n"; | |
3965 | } | |
3966 | else | |
3967 | { | |
3968 | theDI << Quantity_Color::StringName (aColor.Name()) << "\n"; | |
3969 | } | |
3970 | } | |
3971 | else | |
3972 | { | |
3973 | switch (aBufferType) | |
3974 | { | |
3975 | default: | |
692613e5 | 3976 | case Graphic3d_BT_RGB: |
85e096c3 | 3977 | { |
3978 | if (toShowHls) | |
3979 | { | |
3980 | theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n"; | |
3981 | } | |
3982 | else | |
3983 | { | |
3984 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n"; | |
3985 | } | |
3986 | break; | |
3987 | } | |
692613e5 | 3988 | case Graphic3d_BT_RGBA: |
85e096c3 | 3989 | { |
3990 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n"; | |
3991 | break; | |
3992 | } | |
692613e5 | 3993 | case Graphic3d_BT_Depth: |
85e096c3 | 3994 | { |
3995 | theDI << aColor.Red() << "\n"; | |
3996 | break; | |
3997 | } | |
3998 | } | |
3999 | } | |
4000 | ||
4001 | return 0; | |
4002 | } | |
4003 | ||
692613e5 | 4004 | //============================================================================== |
4005 | //function : VDiffImage | |
4006 | //purpose : The draw-command compares two images. | |
4007 | //============================================================================== | |
4008 | ||
4009 | static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
4010 | { | |
4011 | if (theArgNb < 6) | |
4012 | { | |
4013 | theDI << "Not enough arguments.\n"; | |
4014 | return 1; | |
4015 | } | |
4016 | ||
4017 | // image file names | |
4018 | const char* anImgPathRef = theArgVec[1]; | |
4019 | const char* anImgPathNew = theArgVec[2]; | |
4020 | ||
4021 | // get string tolerance and check its validity | |
91322f44 | 4022 | Standard_Real aTolColor = Draw::Atof (theArgVec[3]); |
692613e5 | 4023 | if (aTolColor < 0.0) |
4024 | aTolColor = 0.0; | |
4025 | if (aTolColor > 1.0) | |
4026 | aTolColor = 1.0; | |
4027 | ||
91322f44 | 4028 | Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1); |
4029 | Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1); | |
692613e5 | 4030 | |
4031 | // image file of difference | |
4032 | const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL; | |
4033 | ||
4034 | // compare the images | |
4035 | Image_Diff aComparer; | |
4036 | if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite)) | |
4037 | { | |
4038 | return 1; | |
4039 | } | |
4040 | ||
4041 | aComparer.SetColorTolerance (aTolColor); | |
4042 | aComparer.SetBorderFilterOn (isBorderFilterOn); | |
4043 | Standard_Integer aDiffColorsNb = aComparer.Compare(); | |
4044 | theDI << aDiffColorsNb << "\n"; | |
4045 | ||
4046 | // save image of difference | |
4047 | if (aDiffImagePath != NULL) | |
4048 | { | |
4049 | aComparer.SaveDiffImage (aDiffImagePath); | |
4050 | } | |
4051 | ||
4052 | return 0; | |
4053 | } | |
4054 | ||
4754e164 | 4055 | //======================================================================= |
4056 | //function : VSelect | |
4057 | //purpose : Emulates different types of selection by mouse: | |
4058 | // 1) single click selection | |
4059 | // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2) | |
4060 | // 3) selection with polygon having corners at | |
dc3fe572 | 4061 | // pixel positions (x1,y1),...,(xn,yn) |
4754e164 | 4062 | // 4) any of these selections with shift button pressed |
4063 | //======================================================================= | |
4064 | static Standard_Integer VSelect (Draw_Interpretor& di, | |
4065 | Standard_Integer argc, | |
4066 | const char ** argv) | |
4067 | { | |
dc3fe572 | 4068 | if(argc < 3) |
4754e164 | 4069 | { |
4070 | di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n"; | |
4071 | return 1; | |
4072 | } | |
4073 | ||
4074 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); | |
dc3fe572 | 4075 | if(myAIScontext.IsNull()) |
4754e164 | 4076 | { |
4077 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4078 | return 1; | |
4079 | } | |
4080 | const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1)); | |
4081 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); | |
4082 | aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2])); | |
4083 | if(argc <= 4) | |
4084 | { | |
4085 | if(isShiftSelection) | |
4086 | aCurrentEventManager->ShiftSelect(); | |
4087 | else | |
4088 | aCurrentEventManager->Select(); | |
4089 | } | |
4090 | else if(argc <= 6) | |
4091 | { | |
4092 | if(isShiftSelection) | |
4093 | aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4])); | |
4094 | else | |
4095 | aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4])); | |
4096 | } | |
4097 | else | |
4098 | { | |
4099 | Standard_Integer anUpper = 0; | |
4100 | ||
4101 | if(isShiftSelection) | |
4102 | anUpper = (argc-1)/2; | |
4103 | else | |
4104 | anUpper = argc/2; | |
4105 | TColgp_Array1OfPnt2d aPolyline(1,anUpper); | |
4106 | ||
4107 | for(Standard_Integer i=1;i<=anUpper;++i) | |
4108 | aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i]))); | |
4109 | ||
4110 | if(isShiftSelection) | |
4111 | aCurrentEventManager->ShiftSelect(aPolyline); | |
4112 | else | |
4113 | aCurrentEventManager->Select(aPolyline); | |
4114 | } | |
4115 | return 0; | |
4116 | } | |
4117 | ||
4118 | //======================================================================= | |
4119 | //function : VMoveTo | |
dc3fe572 | 4120 | //purpose : Emulates cursor movement to defined pixel position |
4754e164 | 4121 | //======================================================================= |
4122 | static Standard_Integer VMoveTo (Draw_Interpretor& di, | |
4123 | Standard_Integer argc, | |
4124 | const char ** argv) | |
4125 | { | |
dc3fe572 | 4126 | if(argc != 3) |
4754e164 | 4127 | { |
4128 | di << "Usage : " << argv[0] << " x y" << "\n"; | |
4129 | return 1; | |
4130 | } | |
4131 | ||
4132 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
dc3fe572 | 4133 | if(aContext.IsNull()) |
4754e164 | 4134 | { |
4135 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4136 | return 1; | |
4137 | } | |
4138 | ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2])); | |
4139 | return 0; | |
4140 | } | |
4141 | ||
4142 | //======================================================================= | |
4143 | //function : VViewParams | |
dc3fe572 | 4144 | //purpose : Gets or sets AIS View characteristics |
4754e164 | 4145 | //======================================================================= |
4146 | static Standard_Integer VViewParams (Draw_Interpretor& di, | |
4147 | Standard_Integer argc, | |
4148 | const char ** argv) | |
4149 | { | |
dc3fe572 | 4150 | if ( argc != 1 && argc != 13) |
4754e164 | 4151 | { |
4152 | di << "Usage : " << argv[0] << "\n"; | |
4153 | return 1; | |
4154 | } | |
4155 | Handle (V3d_View) anAISView = ViewerTest::CurrentView (); | |
dc3fe572 | 4156 | if ( anAISView.IsNull () ) |
4754e164 | 4157 | { |
4158 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4159 | return 1; | |
4160 | } | |
4161 | if(argc==1){ | |
4162 | Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale (); | |
4163 | Standard_Real anAISViewCenterCoordinateX = 0.0; | |
4164 | Standard_Real anAISViewCenterCoordinateY = 0.0; | |
4165 | anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY); | |
4166 | Standard_Real anAISViewProjX = 0.0; | |
4167 | Standard_Real anAISViewProjY = 0.0; | |
4168 | Standard_Real anAISViewProjZ = 0.0; | |
4169 | anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ); | |
4170 | Standard_Real anAISViewUpX = 0.0; | |
4171 | Standard_Real anAISViewUpY = 0.0; | |
4172 | Standard_Real anAISViewUpZ = 0.0; | |
4173 | anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ); | |
4174 | Standard_Real anAISViewAtX = 0.0; | |
4175 | Standard_Real anAISViewAtY = 0.0; | |
4176 | Standard_Real anAISViewAtZ = 0.0; | |
4177 | anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ); | |
4178 | di << "Scale of current view: " << anAISViewScale << "\n"; | |
4179 | di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n"; | |
4180 | di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n"; | |
4181 | di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n"; | |
4182 | di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n"; | |
4183 | } | |
4184 | else | |
4185 | { | |
4186 | Quantity_Factor anAISViewScale = atof (argv [1]); | |
4187 | Standard_Real anAISViewCenterCoordinateX = atof (argv [2]); | |
4188 | Standard_Real anAISViewCenterCoordinateY = atof (argv [3]); | |
4189 | Standard_Real anAISViewProjX = atof (argv [4]); | |
4190 | Standard_Real anAISViewProjY = atof (argv [5]); | |
4191 | Standard_Real anAISViewProjZ = atof (argv [6]); | |
4192 | Standard_Real anAISViewUpX = atof (argv [7]); | |
4193 | Standard_Real anAISViewUpY = atof (argv [8]); | |
4194 | Standard_Real anAISViewUpZ = atof (argv [9]); | |
4195 | Standard_Real anAISViewAtX = atof (argv [10]); | |
4196 | Standard_Real anAISViewAtY = atof (argv [11]); | |
4197 | Standard_Real anAISViewAtZ = atof (argv [12]); | |
4198 | anAISView -> V3d_View::SetScale (anAISViewScale); | |
4199 | anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY); | |
4200 | anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ); | |
4201 | anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ); | |
4202 | anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ); | |
4203 | } | |
4204 | return 0; | |
4205 | } | |
4206 | ||
4207 | //======================================================================= | |
4208 | //function : VChangeSelected | |
dc3fe572 | 4209 | //purpose : Adds the shape to selection or remove one from it |
4754e164 | 4210 | //======================================================================= |
4211 | static Standard_Integer VChangeSelected (Draw_Interpretor& di, | |
4212 | Standard_Integer argc, | |
4213 | const char ** argv) | |
4214 | { | |
4215 | if(argc != 2) | |
4216 | { | |
4217 | di<<"Usage : " << argv[0] << " shape \n"; | |
4218 | return 1; | |
4219 | } | |
4220 | //get AIS_Shape: | |
4221 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4222 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4223 | TCollection_AsciiString aName(argv[1]); | |
4224 | Handle(AIS_InteractiveObject) anAISObject; | |
4225 | ||
4226 | if(!aMap.IsBound2(aName)) | |
4227 | { | |
4228 | di<<"Use 'vdisplay' before"; | |
4229 | return 1; | |
4230 | } | |
4231 | else | |
4232 | { | |
4233 | anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName)); | |
4234 | if(anAISObject.IsNull()){ | |
4235 | di<<"No interactive object \n"; | |
4236 | return 1; | |
4237 | } | |
4238 | ||
4239 | if(aContext->HasOpenedContext()) | |
4240 | { | |
4241 | aContext->AddOrRemoveSelected(anAISObject); | |
4242 | } | |
dc3fe572 | 4243 | else |
4754e164 | 4244 | { |
4245 | aContext->AddOrRemoveCurrentObject(anAISObject); | |
4246 | } | |
4247 | } | |
4248 | return 0; | |
4249 | } | |
4250 | ||
4251 | //======================================================================= | |
4252 | //function : VZClipping | |
dc3fe572 | 4253 | //purpose : Gets or sets ZClipping mode, width and depth |
4754e164 | 4254 | //======================================================================= |
4255 | static Standard_Integer VZClipping (Draw_Interpretor& di, | |
4256 | Standard_Integer argc, | |
4257 | const char ** argv) | |
4258 | { | |
dc3fe572 | 4259 | if(argc>4) |
4754e164 | 4260 | { |
4261 | di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
4262 | <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
4263 | return -1; | |
4264 | } | |
4265 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
dc3fe572 | 4266 | if(aContext.IsNull()) |
4754e164 | 4267 | { |
4268 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4269 | return 1; | |
4270 | } | |
4271 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4272 | V3d_TypeOfZclipping aZClippingMode; | |
4273 | if(argc==1) | |
4274 | { | |
4275 | TCollection_AsciiString aZClippingModeString; | |
4276 | Quantity_Length aDepth, aWidth; | |
4277 | aZClippingMode = aView->ZClipping(aDepth, aWidth); | |
4278 | switch (aZClippingMode) | |
4279 | { | |
4280 | case V3d_OFF: | |
4281 | aZClippingModeString.Copy("OFF"); | |
4282 | break; | |
4283 | case V3d_BACK: | |
4284 | aZClippingModeString.Copy("BACK"); | |
4285 | break; | |
4286 | case V3d_FRONT: | |
4287 | aZClippingModeString.Copy("FRONT"); | |
4288 | break; | |
4289 | case V3d_SLICE: | |
4290 | aZClippingModeString.Copy("SLICE"); | |
4291 | break; | |
4292 | default: | |
4293 | aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode)); | |
4294 | break; | |
4295 | } | |
4296 | di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n" | |
4297 | << "ZClipping depth = " << aDepth << "\n" | |
4298 | << "ZClipping width = " << aWidth << "\n"; | |
4299 | } | |
4300 | else | |
4301 | { | |
4302 | if(argc !=3) | |
4303 | { | |
4304 | Standard_Integer aStatus = 0; | |
4305 | if ( strcmp (argv [1], "OFF") == 0 ) { | |
4306 | aStatus = 1; | |
4307 | aZClippingMode = V3d_OFF; | |
4308 | } | |
4309 | if ( strcmp (argv [1], "BACK") == 0 ) { | |
4310 | aStatus = 1; | |
4311 | aZClippingMode = V3d_BACK; | |
4312 | } | |
4313 | if ( strcmp (argv [1], "FRONT") == 0 ) { | |
4314 | aStatus = 1; | |
4315 | aZClippingMode = V3d_FRONT; | |
4316 | } | |
4317 | if ( strcmp (argv [1], "SLICE") == 0 ) { | |
4318 | aStatus = 1; | |
4319 | aZClippingMode = V3d_SLICE; | |
4320 | } | |
4321 | if (aStatus != 1) | |
4322 | { | |
4323 | di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
4324 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
4325 | return 1; | |
dc3fe572 | 4326 | } |
4754e164 | 4327 | aView->SetZClippingType(aZClippingMode); |
4328 | } | |
4329 | if(argc >2) | |
4330 | { | |
4331 | Quantity_Length aDepth = 0., aWidth = 1.; | |
4332 | if(argc == 3) | |
4333 | { | |
4334 | aDepth = atof(argv[1]); | |
4335 | aWidth = atof(argv[2]); | |
4336 | } | |
4337 | else if(argc == 4) | |
4338 | { | |
4339 | aDepth = atof(argv[2]); | |
4340 | aWidth = atof(argv[3]); | |
4341 | } | |
dc3fe572 | 4342 | |
4754e164 | 4343 | if(aDepth<0. || aDepth>1.) |
4344 | { | |
4345 | di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
4346 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
4347 | return 1; | |
4348 | } | |
4349 | if(aWidth<0. || aWidth>1.) | |
4350 | { | |
4351 | di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
4352 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
4353 | return 1; | |
4354 | } | |
4355 | ||
4356 | aView->SetZClippingDepth(aDepth); | |
4357 | aView->SetZClippingWidth(aWidth); | |
4358 | } | |
4359 | aView->Redraw(); | |
4360 | } | |
4361 | return 0; | |
4362 | } | |
4363 | ||
4364 | //======================================================================= | |
4365 | //function : VNbSelected | |
dc3fe572 | 4366 | //purpose : Returns number of selected objects |
4754e164 | 4367 | //======================================================================= |
4368 | static Standard_Integer VNbSelected (Draw_Interpretor& di, | |
4369 | Standard_Integer argc, | |
4370 | const char ** argv) | |
4371 | { | |
4372 | if(argc != 1) | |
4373 | { | |
4374 | di << "Usage : " << argv[0] << "\n"; | |
4375 | return 1; | |
4376 | } | |
4377 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4378 | if(aContext.IsNull()) | |
4379 | { | |
4380 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4381 | return 1; | |
4382 | } | |
4383 | di << aContext->NbSelected() << "\n"; | |
4384 | return 0; | |
4385 | } | |
4386 | ||
4387 | //======================================================================= | |
4388 | //function : VAntialiasing | |
dc3fe572 | 4389 | //purpose : Switches altialiasing on or off |
4754e164 | 4390 | //======================================================================= |
4391 | static Standard_Integer VAntialiasing (Draw_Interpretor& di, | |
4392 | Standard_Integer argc, | |
4393 | const char ** argv) | |
4394 | { | |
4395 | if(argc > 2) | |
4396 | { | |
4397 | di << "Usage : " << argv[0] << " [1|0]" << "\n"; | |
4398 | return 1; | |
4399 | } | |
4400 | ||
4401 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4402 | if(aContext.IsNull()) | |
4403 | { | |
4404 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4405 | return 1; | |
4406 | } | |
4407 | ||
4408 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4409 | ||
4410 | if((argc == 2) && (atof(argv[1]) == 0)) | |
4411 | aView->SetAntialiasingOff(); | |
4412 | else | |
4413 | aView->SetAntialiasingOn(); | |
4414 | aView->Update(); | |
4415 | return 0; | |
4416 | } | |
4417 | ||
4418 | //======================================================================= | |
4419 | //function : VPurgeDisplay | |
dc3fe572 | 4420 | //purpose : Switches altialiasing on or off |
4754e164 | 4421 | //======================================================================= |
4422 | static Standard_Integer VPurgeDisplay (Draw_Interpretor& di, | |
4423 | Standard_Integer argc, | |
4424 | const char ** argv) | |
4425 | { | |
4426 | if (argc > 2) | |
4427 | { | |
4428 | di << "Usage : " << argv[0] << " [CollectorToo = 0|1]" << "\n"; | |
4429 | return 1; | |
4430 | } | |
4431 | Standard_Boolean isCollectorToo = Standard_False; | |
4432 | if (argc == 2) | |
4433 | { | |
4434 | isCollectorToo = (atoi(argv [1]) != 0); | |
4435 | } | |
4436 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4437 | if (aContext.IsNull()) | |
4438 | { | |
4439 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4440 | return 1; | |
4441 | } | |
4442 | aContext->CloseAllContexts(Standard_False); | |
4443 | di << aContext->PurgeDisplay(isCollectorToo) << "\n"; | |
4444 | return 0; | |
4445 | } | |
4446 | ||
4447 | //======================================================================= | |
4448 | //function : VSetViewSize | |
4449 | //purpose : | |
4450 | //======================================================================= | |
4451 | static Standard_Integer VSetViewSize (Draw_Interpretor& di, | |
4452 | Standard_Integer argc, | |
4453 | const char ** argv) | |
4454 | { | |
4455 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4456 | if(aContext.IsNull()) | |
4457 | { | |
4458 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4459 | return 1; | |
4460 | } | |
4461 | if(argc != 2) | |
4462 | { | |
4463 | di<<"Usage : " << argv[0] << " Size\n"; | |
4464 | return 1; | |
4465 | } | |
4466 | Standard_Real aSize = atof(argv[1]); | |
4467 | if (aSize <= 0.) | |
4468 | { | |
4469 | di<<"Bad Size value : " << aSize << "\n"; | |
4470 | return 1; | |
4471 | } | |
4472 | ||
4473 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4474 | aView->SetSize(aSize); | |
4475 | return 0; | |
4476 | } | |
4477 | ||
4478 | //======================================================================= | |
4479 | //function : VMoveView | |
4480 | //purpose : | |
4481 | //======================================================================= | |
4482 | static Standard_Integer VMoveView (Draw_Interpretor& di, | |
4483 | Standard_Integer argc, | |
4484 | const char ** argv) | |
4485 | { | |
4486 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4487 | if(aContext.IsNull()) | |
4488 | { | |
4489 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4490 | return 1; | |
4491 | } | |
4492 | if(argc < 4 || argc > 5) | |
4493 | { | |
4494 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
4495 | return 1; | |
4496 | } | |
4497 | Standard_Real Dx = atof(argv[1]); | |
4498 | Standard_Real Dy = atof(argv[2]); | |
4499 | Standard_Real Dz = atof(argv[3]); | |
4500 | Standard_Boolean aStart = Standard_True; | |
4501 | if (argc == 5) | |
4502 | { | |
4503 | aStart = (atoi(argv[4]) > 0); | |
4504 | } | |
4505 | ||
4506 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4507 | aView->Move(Dx,Dy,Dz,aStart); | |
4508 | return 0; | |
4509 | } | |
4510 | ||
4511 | //======================================================================= | |
4512 | //function : VTranslateView | |
4513 | //purpose : | |
4514 | //======================================================================= | |
4515 | static Standard_Integer VTranslateView (Draw_Interpretor& di, | |
4516 | Standard_Integer argc, | |
4517 | const char ** argv) | |
4518 | { | |
4519 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4520 | if(aContext.IsNull()) | |
4521 | { | |
4522 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4523 | return 1; | |
4524 | } | |
4525 | if(argc < 4 || argc > 5) | |
4526 | { | |
4527 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
4528 | return 1; | |
4529 | } | |
4530 | Standard_Real Dx = atof(argv[1]); | |
4531 | Standard_Real Dy = atof(argv[2]); | |
4532 | Standard_Real Dz = atof(argv[3]); | |
4533 | Standard_Boolean aStart = Standard_True; | |
dc3fe572 | 4534 | if (argc == 5) |
4754e164 | 4535 | { |
4536 | aStart = (atoi(argv[4]) > 0); | |
4537 | } | |
4538 | ||
4539 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4540 | aView->Translate(Dx,Dy,Dz,aStart); | |
4541 | return 0; | |
4542 | } | |
4543 | ||
4544 | //======================================================================= | |
4545 | //function : VTurnView | |
4546 | //purpose : | |
4547 | //======================================================================= | |
4548 | static Standard_Integer VTurnView (Draw_Interpretor& di, | |
4549 | Standard_Integer argc, | |
4550 | const char ** argv) | |
4551 | { | |
4552 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4553 | if(aContext.IsNull()) { | |
4554 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
4555 | return 1; | |
4556 | } | |
4557 | if(argc < 4 || argc > 5){ | |
4558 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n"; | |
4559 | return 1; | |
4560 | } | |
4561 | Standard_Real Ax = atof(argv[1]); | |
4562 | Standard_Real Ay = atof(argv[2]); | |
4563 | Standard_Real Az = atof(argv[3]); | |
4564 | Standard_Boolean aStart = Standard_True; | |
dc3fe572 | 4565 | if (argc == 5) |
4754e164 | 4566 | { |
4567 | aStart = (atoi(argv[4]) > 0); | |
4568 | } | |
4569 | ||
4570 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4571 | aView->Turn(Ax,Ay,Az,aStart); | |
4572 | return 0; | |
4573 | } | |
4574 | ||
269294d6 | 4575 | //============================================================================== |
4576 | //function : VTextureEnv | |
4577 | //purpose : ENables or disables environment mapping | |
4578 | //============================================================================== | |
4579 | class OCC_TextureEnv : public Graphic3d_TextureEnv | |
4580 | { | |
4581 | public: | |
4582 | OCC_TextureEnv(const Standard_CString FileName); | |
4583 | OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName); | |
4584 | void SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
4585 | const Standard_Boolean theModulateFlag, | |
4586 | const Graphic3d_TypeOfTextureFilter theFilter, | |
4587 | const Standard_ShortReal theXScale, | |
4588 | const Standard_ShortReal theYScale, | |
4589 | const Standard_ShortReal theXShift, | |
4590 | const Standard_ShortReal theYShift, | |
4591 | const Standard_ShortReal theAngle); | |
4592 | DEFINE_STANDARD_RTTI(OCC_TextureEnv); | |
4593 | }; | |
4594 | DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv); | |
4595 | IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv); | |
4596 | IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv); | |
4597 | ||
4598 | OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName) | |
4599 | : Graphic3d_TextureEnv(theFileName) | |
4600 | { | |
4601 | } | |
4602 | ||
4603 | OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId) | |
4604 | : Graphic3d_TextureEnv(theTexId) | |
4605 | { | |
4606 | } | |
4607 | ||
4608 | void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
4609 | const Standard_Boolean theModulateFlag, | |
4610 | const Graphic3d_TypeOfTextureFilter theFilter, | |
4611 | const Standard_ShortReal theXScale, | |
4612 | const Standard_ShortReal theYScale, | |
4613 | const Standard_ShortReal theXShift, | |
4614 | const Standard_ShortReal theYShift, | |
4615 | const Standard_ShortReal theAngle) | |
4616 | { | |
4617 | myParams->SetRepeat (theRepeatFlag); | |
4618 | myParams->SetModulate (theModulateFlag); | |
4619 | myParams->SetFilter (theFilter); | |
4620 | myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale)); | |
4621 | myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift)); | |
4622 | myParams->SetRotation (theAngle); | |
4623 | } | |
4624 | ||
35e08fe8 | 4625 | static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec) |
269294d6 | 4626 | { |
4627 | // get the active view | |
4628 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4629 | if (aView.IsNull()) | |
4630 | { | |
4631 | std::cerr << "No active view. Please call vinit.\n"; | |
4632 | return 1; | |
4633 | } | |
4634 | ||
4635 | // Checking the input arguments | |
4636 | Standard_Boolean anEnableFlag = Standard_False; | |
4637 | Standard_Boolean isOk = theArgNb >= 2; | |
4638 | if (isOk) | |
4639 | { | |
4640 | TCollection_AsciiString anEnableOpt(theArgVec[1]); | |
4641 | anEnableFlag = anEnableOpt.IsEqual("on"); | |
4642 | isOk = anEnableFlag || anEnableOpt.IsEqual("off"); | |
4643 | } | |
4644 | if (anEnableFlag) | |
4645 | { | |
4646 | isOk = (theArgNb == 3 || theArgNb == 11); | |
4647 | if (isOk) | |
4648 | { | |
4649 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
4650 | isOk = (!aTextureOpt.IsIntegerValue() || | |
4651 | (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN)); | |
4652 | ||
4653 | if (isOk && theArgNb == 11) | |
4654 | { | |
4655 | TCollection_AsciiString aRepeatOpt (theArgVec[3]), | |
4656 | aModulateOpt(theArgVec[4]), | |
4657 | aFilterOpt (theArgVec[5]), | |
4658 | aSScaleOpt (theArgVec[6]), | |
4659 | aTScaleOpt (theArgVec[7]), | |
4660 | aSTransOpt (theArgVec[8]), | |
4661 | aTTransOpt (theArgVec[9]), | |
4662 | anAngleOpt (theArgVec[10]); | |
4663 | isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) && | |
4664 | (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) && | |
4665 | (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) && | |
4666 | aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() && | |
4667 | aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() && | |
4668 | anAngleOpt.IsRealValue()); | |
4669 | } | |
4670 | } | |
4671 | } | |
4672 | ||
4673 | if (!isOk) | |
4674 | { | |
4675 | std::cerr << "Usage :" << std::endl; | |
4676 | std::cerr << theArgVec[0] << " off" << std::endl; | |
4677 | 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; | |
4678 | return 1; | |
4679 | } | |
4680 | ||
4681 | if (anEnableFlag) | |
4682 | { | |
4683 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
4684 | Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ? | |
4685 | new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) : | |
4686 | new OCC_TextureEnv(theArgVec[2]); | |
4687 | ||
4688 | if (theArgNb == 11) | |
4689 | { | |
4690 | TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]); | |
4691 | aTexEnv->SetTextureParameters( | |
4692 | aRepeatOpt. IsEqual("repeat"), | |
4693 | aModulateOpt.IsEqual("modulate"), | |
4694 | aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST : | |
4695 | aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR : | |
4696 | Graphic3d_TOTF_TRILINEAR, | |
4697 | (Standard_ShortReal)Draw::Atof(theArgVec[6]), | |
4698 | (Standard_ShortReal)Draw::Atof(theArgVec[7]), | |
4699 | (Standard_ShortReal)Draw::Atof(theArgVec[8]), | |
4700 | (Standard_ShortReal)Draw::Atof(theArgVec[9]), | |
4701 | (Standard_ShortReal)Draw::Atof(theArgVec[10]) | |
4702 | ); | |
4703 | } | |
4704 | aView->SetTextureEnv(aTexEnv); | |
4705 | aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT); | |
4706 | } | |
4707 | else // Disabling environment mapping | |
4708 | { | |
4709 | aView->SetSurfaceDetail(V3d_TEX_NONE); | |
4710 | Handle(Graphic3d_TextureEnv) aTexture; | |
4711 | aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data | |
4712 | } | |
4713 | ||
4714 | aView->Redraw(); | |
4715 | return 0; | |
4716 | } | |
4717 | ||
7fd59977 | 4718 | //======================================================================= |
4719 | //function : ViewerCommands | |
4720 | //purpose : | |
4721 | //======================================================================= | |
4722 | ||
4723 | void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) | |
4724 | { | |
4725 | ||
4726 | const char *group = "ZeViewer"; | |
18d715bd | 4727 | theCommands.Add("vinit", |
4728 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
4729 | "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" | |
4730 | #else | |
4731 | "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" | |
4732 | #endif | |
4733 | " - Creates new View window with specified name view_name.\n" | |
4734 | "By default the new view is created in the viewer and in" | |
4735 | " graphic driver shared with active view.\n" | |
4736 | " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n" | |
4737 | "If driverName isn't specified the driver will be shared with active view.\n" | |
4738 | "If viewerName isn't specified the viewer will be shared with active view.\n" | |
4739 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
4740 | " - display = HostName.DisplayNumber[:ScreenNumber] : if specified" | |
4741 | "is used in creation of graphic driver\n" | |
4742 | #endif | |
4743 | " - l, t: pixel position of left top corner of the window\n" | |
4744 | " - w,h: width and heigth of window respectively.\n" | |
4745 | "Additional commands for operations with views: vclose, vactivate, vviewlist.\n", | |
7fd59977 | 4746 | __FILE__,VInit,group); |
18d715bd | 4747 | theCommands.Add("vclose" , |
4748 | "view_id [keep_context=0|1]\n" | |
4749 | "or vclose ALL - to remove all created views\n" | |
4750 | " - removes view(viewer window) defined by its view_id.\n" | |
4751 | " - keep_context: by default 0; if 1 and the last view is deleted" | |
4752 | " the current context is not removed.", | |
4753 | __FILE__,VClose,group); | |
4754 | theCommands.Add("vactivate" , | |
4755 | "view_id" | |
4756 | " - activates view(viewer window) defined by its view_id", | |
4757 | __FILE__,VActivate,group); | |
4758 | theCommands.Add("vviewlist", | |
4759 | "vviewlist [format={tree, long}]" | |
4760 | " - prints current list of views per viewer and graphic_driver ID shared between viewers" | |
4761 | " - format: format of result output, if tree the output is a tree view;" | |
4762 | "otherwise it's a list of full view names. By default format = tree", | |
4763 | __FILE__,VViewList,group); | |
7fd59977 | 4764 | theCommands.Add("vhelp" , |
4765 | "vhelp : display help on the viewer commands", | |
4766 | __FILE__,VHelp,group); | |
4767 | theCommands.Add("vtop" , | |
44b8f2d6 | 4768 | "vtop or <T> : Top view" , |
7fd59977 | 4769 | __FILE__,VTop,group); |
44b8f2d6 | 4770 | theCommands.Add("vbottom" , |
4771 | "vbottom : Bottom view" , | |
4772 | __FILE__,VBottom,group); | |
4773 | theCommands.Add("vleft" , | |
4774 | "vleft : Left view" , | |
4775 | __FILE__,VLeft,group); | |
4776 | theCommands.Add("vright" , | |
4777 | "vright : Right view" , | |
4778 | __FILE__,VRight,group); | |
7fd59977 | 4779 | theCommands.Add("vaxo" , |
4780 | " vaxo or <A> : Axonometric view ", | |
4781 | __FILE__,VAxo,group); | |
44b8f2d6 | 4782 | theCommands.Add("vfront" , |
4783 | "vfront : Front view" , | |
4784 | __FILE__,VFront,group); | |
4785 | theCommands.Add("vback" , | |
4786 | "vback : Back view" , | |
4787 | __FILE__,VBack,group); | |
7fd59977 | 4788 | theCommands.Add("vpick" , |
4789 | "vpick : vpick X Y Z [shape subshape] ( all variables as string )", | |
4790 | VPick,group); | |
4791 | theCommands.Add("vfit" , | |
4792 | "vfit or <F> : vfit", | |
4793 | __FILE__,VFit,group); | |
4794 | theCommands.Add("vzfit" , | |
4795 | "vzfit", | |
4796 | __FILE__,VZFit,group); | |
4797 | theCommands.Add("vrepaint", | |
4798 | "vrepaint : vrepaint, force redraw", | |
4799 | __FILE__,VRepaint,group); | |
4800 | theCommands.Add("vclear", | |
4801 | "vclear : vclear", | |
4802 | __FILE__,VClear,group); | |
4803 | theCommands.Add("vsetbg", | |
4804 | "vsetbg : vsetbg imagefile [filltype] : Load image as background", | |
4805 | __FILE__,VSetBg,group); | |
f8b2ed36 | 4806 | theCommands.Add("vsetbgmode", |
4807 | "vsetbgmode : vsetbgmode filltype : Change background image fill type", | |
4808 | __FILE__,VSetBgMode,group); | |
7fd59977 | 4809 | theCommands.Add("vsetgradientbg", |
f8b2ed36 | 4810 | "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background", |
7fd59977 | 4811 | __FILE__,VSetGradientBg,group); |
f8b2ed36 | 4812 | theCommands.Add("vsetgrbgmode", |
4813 | "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type", | |
4814 | __FILE__,VSetGradientBgMode,group); | |
4815 | theCommands.Add("vsetcolorbg", | |
4816 | "vsetcolorbg : vsetcolorbg r g b : Set background color", | |
4817 | __FILE__,VSetColorBg,group); | |
7fd59977 | 4818 | theCommands.Add("vscale", |
4819 | "vscale : vscale X Y Z", | |
4820 | __FILE__,VScale,group); | |
4821 | theCommands.Add("vzbufftrihedron", | |
7c8a8fcc | 4822 | "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper" |
4823 | " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]" | |
4824 | " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron", | |
7fd59977 | 4825 | __FILE__,VTestZBuffTrihedron,group); |
4826 | theCommands.Add("vrotate", | |
4827 | "vrotate : vrotate AX AY AZ [X Y Z]", | |
4828 | __FILE__,VRotate,group); | |
4829 | theCommands.Add("vzoom", | |
4830 | "vzoom : vzoom coef", | |
4831 | __FILE__,VZoom,group); | |
4832 | theCommands.Add("vpan", | |
4833 | "vpan : vpan dx dy", | |
4834 | __FILE__,VPan,group); | |
4835 | theCommands.Add("vexport", | |
5cedc27f K |
4836 | "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }" |
4837 | " : exports the view to a vector file of a given format" | |
4838 | " : notice that EMF format requires patched gl2ps", | |
7fd59977 | 4839 | __FILE__,VExport,group); |
4840 | theCommands.Add("vcolorscale", | |
4841 | "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale", | |
4842 | __FILE__,VColorScale,group); | |
4843 | theCommands.Add("vgraduatedtrihedron", | |
13a22457 | 4844 | "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]", |
7fd59977 | 4845 | __FILE__,VGraduatedTrihedron,group); |
7edf74fd A |
4846 | theCommands.Add("vprintview" , |
4847 | "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile", | |
4848 | __FILE__,VPrintView,group); | |
59f45b7c | 4849 | theCommands.Add("vzlayer", |
4850 | "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids", | |
4851 | __FILE__,VZLayer,group); | |
25289ec1 | 4852 | theCommands.Add("voverlaytext", |
4853 | "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]" | |
4854 | " : height - pixel height of the text (default=10.0)" | |
4855 | " : font_name - name of font (default=courier)" | |
4856 | " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) " | |
4857 | " : display_type = {normal/subtitle/decal/blend}, (default=normal) " | |
4858 | " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ", | |
4859 | __FILE__,VOverlayText,group); | |
20637bd2 | 4860 | theCommands.Add("vlayerline", |
4861 | "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]", | |
4862 | __FILE__,VLayerLine,group); | |
2bd4c032 | 4863 | theCommands.Add ("vgrid", |
4864 | "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]" | |
4865 | " : Mode - rectangular or circular" | |
4866 | " : Type - lines or points", | |
4867 | __FILE__, VGrid, group); | |
208e6839 | 4868 | theCommands.Add ("vfps", |
4869 | "vfps [framesNb=100] : estimate average frame rate for active view", | |
4870 | __FILE__, VFps, group); | |
4871 | theCommands.Add ("vvbo", | |
4872 | "vvbo {0|1} : turn VBO usage On/Off; affects only newly displayed objects", | |
4873 | __FILE__, VVbo, group); | |
f0430952 | 4874 | theCommands.Add ("vmemgpu", |
4875 | "vmemgpu [f]: print system-dependent GPU memory information if available;" | |
4876 | " with f option returns free memory in bytes", | |
4877 | __FILE__, VMemGpu, group); | |
85e096c3 | 4878 | theCommands.Add ("vreadpixel", |
4879 | "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]" | |
4880 | " : Read pixel value for active view", | |
4881 | __FILE__, VReadPixel, group); | |
692613e5 | 4882 | theCommands.Add("diffimage", |
4883 | "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]", | |
4884 | __FILE__, VDiffImage, group); | |
4754e164 | 4885 | theCommands.Add ("vselect", |
4886 | "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n" | |
4887 | "- emulates different types of selection:\n" | |
4888 | "- 1) single click selection\n" | |
4889 | "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n" | |
4890 | "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n" | |
4891 | "- 4) any of these selections with shift button pressed", | |
4892 | __FILE__, VSelect, group); | |
4893 | theCommands.Add ("vmoveto", | |
4894 | "vmoveto x y" | |
4895 | "- emulates cursor movement to pixel postion (x,y)", | |
4896 | __FILE__, VMoveTo, group); | |
4897 | theCommands.Add("vviewparams", | |
4898 | "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]" | |
4899 | "- gets or sets current view characteristics", | |
4900 | __FILE__,VViewParams, group); | |
4901 | theCommands.Add("vchangeselected", | |
dc3fe572 | 4902 | "vchangeselected shape" |
4754e164 | 4903 | "- adds to shape to selection or remove one from it", |
4904 | __FILE__, VChangeSelected, group); | |
4905 | theCommands.Add("vzclipping", | |
4906 | "vzclipping [mode] [depth width]\n" | |
4907 | "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n" | |
4908 | "- gets or sets ZClipping mode, width and depth", | |
4909 | __FILE__,VZClipping,group); | |
4910 | theCommands.Add ("vnbselected", | |
4911 | "vnbselected", __FILE__, VNbSelected, group); | |
4912 | theCommands.Add("vantialiasing", | |
4913 | "vantialiasing 1|0", | |
4914 | __FILE__,VAntialiasing,group); | |
4915 | theCommands.Add ("vpurgedisplay", | |
4916 | "vpurgedisplay [CollectorToo = 0|1]" | |
4917 | "- removes structures which don't belong to objects displayed in neutral point", | |
4918 | __FILE__, VPurgeDisplay, group); | |
4919 | theCommands.Add("vsetviewsize", | |
4920 | "vsetviewsize size", | |
4921 | __FILE__,VSetViewSize,group); | |
4922 | theCommands.Add("vmoveview", | |
4923 | "vmoveview Dx Dy Dz [Start = 1|0]", | |
4924 | __FILE__,VMoveView,group); | |
4925 | theCommands.Add("vtranslateview", | |
4926 | "vtranslateview Dx Dy Dz [Start = 1|0)]", | |
4927 | __FILE__,VTranslateView,group); | |
4928 | theCommands.Add("vturnview", | |
4929 | "vturnview Ax Ay Az [Start = 1|0]", | |
4930 | __FILE__,VTurnView,group); | |
269294d6 | 4931 | theCommands.Add("vtextureenv", |
4932 | "Enables or disables environment mapping in the 3D view, loading the texture from the given standard " | |
4933 | "or user-defined file and optionally applying texture mapping parameters\n" | |
4934 | " Usage:\n" | |
4935 | " vtextureenv off - disables environment mapping\n" | |
4936 | " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n" | |
4937 | " std_texture = (0..7)\n" | |
4938 | " rep = {clamp|repeat}\n" | |
4939 | " mod = {decal|modulate}\n" | |
4940 | " flt = {nearest|bilinear|trilinear}\n" | |
4941 | " ss, st - scale factors for s and t texture coordinates\n" | |
4942 | " ts, tt - translation for s and t texture coordinates\n" | |
4943 | " rot - texture rotation angle in degrees", | |
4944 | __FILE__, VTextureEnv, group); | |
0a768f56 | 4945 | theCommands.Add("vhlr" , |
4946 | "is_enabled={on|off}" | |
4947 | " - Hidden line removal algorithm:" | |
4948 | " - is_enabled: if is on HLR algorithm is applied\n", | |
4949 | __FILE__,VHLR,group); | |
4950 | theCommands.Add("vhlrtype" , | |
4951 | "algo_type={algo|polyalgo} [shape_1 ... shape_n]" | |
4952 | " - Changes the type of HLR algorithm using for shapes." | |
4953 | " - algo_type: if equals to algo, exact HLR algorithm is applied;\n" | |
4954 | " if equals to polyalgo, polygonal HLR algorithm is applied." | |
4955 | "If shapes are not given HLR algoithm of given type is applied" | |
4956 | " to all shapes in the view\n", | |
4957 | __FILE__,VHLRType,group); | |
7fd59977 | 4958 | } |