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