0023830: BRepExtrema_DistShapeShape does not find intersection of face with edge
[occt.git] / src / Xw / Xw_Window.cxx
CommitLineData
b311480e 1// Created by: NW,JPB,CAL,GG
2// Copyright (c) 1991-1999 Matra Datavision
3// Copyright (c) 1999-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20#define BUC60701 //GG 23/06/00 Enable to dump an exact image size
21// according to the window size
22#define RIC120302 //GG Add a NEW XParentWindow methods which enable
23// to retrieve the parent of the actual Xwindow ID.
24
7fd59977 25
26//-Version
27
28//-Design Creation d'une fenetre X
29
30//-Warning
31
32//-References
33
34//-Language C++ 2.0
35
36//-Declarations
37
38// for the class
39#include <Xw_Window.ixx>
40// Routines C a declarer en extern
41//extern "C" {
42#include <Xw_Cextern.hxx>
43//}
44#include <Aspect_Convert.hxx>
dc3fe572 45#include <Aspect_DisplayConnection.hxx>
692613e5 46#include <Image_AlienPixMap.hxx>
dc3fe572 47#include <Standard_PCharacter.hxx>
7fd59977 48
49#include <Xw_Extension.h>
50
51//-Static data definitions
52
53static XW_STATUS status ;
54
55//============================================================================
56//==== HashCode : Returns a HashCode CString
57//============================================================================
58inline Standard_Integer HashCode (const Standard_CString Value)
59{
60Standard_Integer i,n,aHashCode = 0;
61union {
62 char charPtr[80];
63 int intPtr[20];
64} u;
65
66 n = strlen(Value);
67
68 if( n > 0 ) {
69 if( n < 80 ) {
70 n = (n+3)/4;
71 u.intPtr[n-1] = 0;
72 strcpy(u.charPtr,Value);
73 } else {
74 n = 20;
75 strncpy(u.charPtr,Value,80);
76 }
77
78 for( i=0 ; i<n ; i++ ) {
79 aHashCode = aHashCode ^ u.intPtr[i];
80 }
81 }
82
83//printf(" HashCode of '%s' is %d\n",Value,aHashCode);
84
85 return Abs(aHashCode) + 1;
86}
87
88void Xw_Window::PrintError() {
89Standard_CString ErrorMessag ;
90Standard_Integer ErrorNumber ;
91Standard_Integer ErrorGravity ;
92
93 status = XW_SUCCESS ;
94 ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
95 Xw_print_error() ;
96}
97
98//-Aliases
99
100//-Global data definitions
101
102//-Constructors
103
dc3fe572 104Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
105: Aspect_Window(),
106 myDisplayConnection (theDisplayConnection)
7fd59977 107{
108 Init();
109}
110
111
112//=======================================================================
113//function : Xw_Window
114//purpose :
115//=======================================================================
dc3fe572 116Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theDisplayConnection,
7fd59977 117 const Standard_Integer aPart1,
118 const Standard_Integer aPart2,
7fd59977 119 const Quantity_NameOfColor BackColor)
dc3fe572 120: Aspect_Window(),
121 myDisplayConnection (theDisplayConnection)
7fd59977 122{
123 Init();
124 Aspect_Handle aWindow = (aPart1 << 16) | (aPart2 & 0xFFFF);
dc3fe572 125 SetWindow (aWindow, BackColor);
7fd59977 126}
127
128//=======================================================================
129//function : Xw_Window
130//purpose :
131//=======================================================================
dc3fe572 132Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theDisplayConnection,
7fd59977 133 const Aspect_Handle aWindow,
7fd59977 134 const Quantity_NameOfColor BackColor)
dc3fe572 135: Aspect_Window(),
136 myDisplayConnection (theDisplayConnection)
7fd59977 137{
138 Init();
dc3fe572 139 SetWindow (aWindow, BackColor);
7fd59977 140}
141
142//=======================================================================
143//function : Xw_Window
144//purpose :
145//=======================================================================
dc3fe572 146Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theDisplayConnection,
7fd59977 147 const Standard_CString theTitle,
148 const Standard_Integer thePxLeft,
149 const Standard_Integer thePxTop,
150 const Standard_Integer theWidth,
151 const Standard_Integer theHeight,
7fd59977 152 const Quantity_NameOfColor theBackColor,
153 const Aspect_Handle theParent)
dc3fe572 154: Aspect_Window (),
155 myDisplayConnection (theDisplayConnection)
7fd59977 156{
157 Init();
158
7fd59977 159 Standard_Integer aParentSizeX = 1;
160 Standard_Integer aParentSizeY = 1;
161
162 Aspect_Handle aRoot, aColormap, *aDisplay;
163 Xw_TypeOfVisual aVisualClass;
164 Standard_Integer aVisualDepth;
165 Xw_get_display_info (MyExtendedDisplay,
166 &aDisplay, &aRoot, &aColormap, &aVisualClass, &aVisualDepth);
167 Xw_get_screen_size (MyExtendedDisplay, &aParentSizeX, &aParentSizeY);
168 if (theParent)
169 {
170 XWindowAttributes anAttributes;
171 if(XGetWindowAttributes ((Display* )aDisplay, theParent, &anAttributes))
172 {
173 aParentSizeX = anAttributes.width;
174 aParentSizeY = anAttributes.height;
175 }
176 }
177 Quantity_Parameter aQCenterX, aQCenterY, aQSizeX, aQSizeY;
178 Aspect_Convert::ConvertCoordinates (aParentSizeX, aParentSizeY,
179 thePxLeft, thePxTop, theWidth, theHeight,
180 aQCenterX, aQCenterY, aQSizeX, aQSizeY);
181 SetWindow (theTitle, aQCenterX, aQCenterY, aQSizeX, aQSizeY,
dc3fe572 182 theBackColor, theParent);
7fd59977 183}
184
185void Xw_Window::Init()
186{
7fd59977 187 MyXWindow = 0 ;
188 MyXParentWindow = 0 ;
dc3fe572 189#if defined(__APPLE__) && !defined(MACOSX_USE_GLX)
190 MyExtendedDisplay = NULL;
191#else
192 MyExtendedDisplay = Xw_set_display (myDisplayConnection->GetDisplay());
193#endif
7fd59977 194 MyExtendedWindow = NULL ;
dc3fe572 195 MyVisualClass = Xw_TOV_TRUECOLOR;
7fd59977 196}
197
198//=======================================================================
199//function : SetWindow
200//purpose :
201//=======================================================================
202
203void Xw_Window::SetWindow (const Aspect_Handle aWindow,
7fd59977 204 const Quantity_NameOfColor BackColor)
205{
dc3fe572 206 Aspect_Handle window,root,colormap,pixmap ;
207 Xw_TypeOfVisual visualclass ;
208 int visualdepth,visualid ;
7fd59977 209
dc3fe572 210 MyXWindow = aWindow ;
211 MyXParentWindow = aWindow ;
7fd59977 212
dc3fe572 213 if( !MyXWindow ) {
214 PrintError() ;
215 }
7fd59977 216
dc3fe572 217 MyExtendedWindow =
218 Xw_def_window (MyExtendedDisplay,MyXWindow,Standard_False);
7fd59977 219
dc3fe572 220 status = Xw_get_window_info(MyExtendedWindow,&window,&pixmap,
221 &root,&colormap,&visualclass,
222 &visualdepth,&visualid);
223 if( !status ) {
224 PrintError() ;
7fd59977 225 }
dc3fe572 226
227 SetBackground(BackColor) ;
7fd59977 228}
229
230//=======================================================================
231//function : SetWindow
232//purpose :
233//=======================================================================
234
235void Xw_Window::SetWindow (const Standard_CString Title,
236 const Quantity_Parameter Xc,
237 const Quantity_Parameter Yc,
238 const Quantity_Parameter Width,
239 const Quantity_Parameter Height,
7fd59977 240 const Quantity_NameOfColor BackColor,
241 const Aspect_Handle Parent)
242{
dc3fe572 243 Standard_Integer istransparent = Standard_False ;
7fd59977 244
7fd59977 245 MyXParentWindow = Parent ;
246 MyXWindow = 0 ;
7fd59977 247
dc3fe572 248 MyXWindow = Xw_open_window(MyExtendedDisplay,MyVisualClass,MyXParentWindow,
249 (float)Xc,(float)Yc,(float)Width,(float)Height,
250 (Standard_PCharacter)Title,istransparent) ;
251 if( !MyXWindow ) {
252 PrintError() ;
7fd59977 253 }
254
dc3fe572 255 MyExtendedWindow =
256 Xw_def_window (MyExtendedDisplay,MyXWindow,istransparent);
7fd59977 257
dc3fe572 258 SetBackground(BackColor) ;
7fd59977 259
dc3fe572 260 if( MyXParentWindow && (MyXWindow != MyXParentWindow) ) Map() ;
7fd59977 261
7fd59977 262}
263
264void Xw_Window::Map () const {
265#ifdef RIC120302
266 if( MyXWindow == MyXParentWindow ) return;
267#endif
268 if (IsVirtual()) return;
269 status = Xw_set_window_state (MyExtendedWindow, XW_MAP);
270 if( !status ) {
271 PrintError() ;
272 }
273}
274
275void Xw_Window::Unmap () const {
276#ifdef RIC120302
277 if( MyXWindow == MyXParentWindow ) return;
278#endif
279 status = Xw_set_window_state (MyExtendedWindow, XW_ICONIFY);
280 if( !status ) {
281 PrintError() ;
282 }
283}
284
285Aspect_TypeOfResize Xw_Window::DoResize () const {
286XW_RESIZETYPE state ;
287
288 state = Xw_resize_window (MyExtendedWindow);
289// if( state == Aspect_TOR_UNKNOWN ) {
290 if( state == XW_TOR_UNKNOWN ) {
291 PrintError() ;
292 }
293
294 return (Aspect_TypeOfResize(state)) ;
295}
296
297Standard_Boolean Xw_Window::DoMapping () const {
298int pxc,pyc,width,height;
299XW_WINDOWSTATE state;
300
301 state = Xw_get_window_position (MyExtendedWindow,&pxc,&pyc,&width,&height);
302
303 return IsMapped();
304}
305
306void Xw_Window::Destroy () {
307Standard_Boolean destroy =
308 ( MyXWindow == MyXParentWindow ) ? Standard_False : Standard_True;
309
310 status = Xw_close_window (MyExtendedWindow,destroy);
311 if( !status ) {
312 PrintError() ;
313 }
314
315 MyXWindow = 0 ;
316 MyExtendedWindow = NULL ;
7fd59977 317}
318
319void Xw_Window::SetCursor (const Standard_Integer anId, const Quantity_NameOfColor aColor) const {
320Quantity_Color Color(aColor) ;
321Standard_Real r,g,b ;
322
323 Color.Values(r,g,b,Quantity_TOC_RGB) ;
324
325 status = Xw_set_hard_cursor (MyExtendedWindow,(int)anId,0,
326 (float)r,
327 (float)g,
328 (float)b) ;
329
330 if( !status ) {
331 PrintError() ;
332 }
333}
334
7fd59977 335Standard_Boolean Xw_Window::IsMapped () const {
336 if (IsVirtual()) {
337 return Standard_True;
338 }
339XW_WINDOWSTATE state;
340 state = Xw_get_window_state (MyExtendedWindow);
341 switch (state) {
342 case XW_WS_UNKNOWN:
343 return Standard_False;
344 case XW_ICONIFY:
345 return Standard_False;
346 case XW_PUSH:
347 return Standard_True;
348 case XW_MAP:
349 return Standard_True;
350#ifndef DEB
351 default:
352 return Standard_False;
353#endif
354 }
355 return Standard_False;
356}
357
358Standard_Real Xw_Window::Ratio () const {
359int width, height;
360
361 status = Xw_get_window_size (MyExtendedWindow,&width,&height);
362 if( !status ) {
363 Xw_print_error() ;
364 }
365
366 return ((Standard_Real)width/height) ;
367}
368
7fd59977 369void Xw_Window::Size (Standard_Integer &Width, Standard_Integer &Height) const {
370int width, height;
371 status = Xw_get_window_size (MyExtendedWindow,&width,&height);
372 if( !status ) {
373 Xw_print_error() ;
374 }
375
376 Width = width ;
377 Height = height ;
378}
379
7fd59977 380void Xw_Window::Position (Standard_Integer &X1, Standard_Integer &Y1, Standard_Integer &X2, Standard_Integer &Y2) const {
381XW_WINDOWSTATE state = XW_WS_UNKNOWN ;
382int pxc, pyc;
383int width, height;
384
385 state = Xw_get_window_position (MyExtendedWindow,
386 &pxc,&pyc,&width,&height);
387 if( state == XW_WS_UNKNOWN ) {
388 Xw_print_error() ;
389 }
390
391 X1 = pxc - width/2 ; Y1 = pyc - height/2 ;
392 X2 = X1 + width - 1 ; Y2 = Y1 + height - 1 ;
393}
394
7fd59977 395Aspect_Handle Xw_Window::XWindow () const {
396
397 return (MyXWindow);
398
399}
400
401void Xw_Window::XWindow (Standard_Integer& aPart1, Standard_Integer& aPart2) const {
402
403 aPart1 = (Standard_Integer)((MyXWindow >> 16 ) & 0xffff);
404 aPart2 = (Standard_Integer)(MyXWindow & 0xffff);
405}
406
407// RIC120302
408Aspect_Handle Xw_Window::XParentWindow () const {
409
410 return (MyXParentWindow);
411
412}
413
414void Xw_Window::XParentWindow (Standard_Integer& aPart1, Standard_Integer& aPart2) const {
415
416 aPart1 = (Standard_Integer)((MyXParentWindow >> 16 ) & 0xffff);
417 aPart2 = (Standard_Integer)(MyXParentWindow & 0xffff);
418}
419// RIC120302
420
421Aspect_Handle Xw_Window::XPixmap () const {
422Aspect_Handle window,pixmap,root,colormap ;
423Xw_TypeOfVisual visualclass ;
424int visualdepth,visualid ;
425
426 status = Xw_get_window_info(MyExtendedWindow,&window,&pixmap,
427 &root,&colormap,&visualclass,&visualdepth,&visualid) ;
428
429 return (pixmap);
430}
431
7fd59977 432Standard_Boolean Xw_Window::PointerPosition (Standard_Integer& X, Standard_Integer& Y) const {
433Standard_Boolean cstatus ;
434int x,y ;
435
436 cstatus = Xw_get_cursor_position(MyExtendedWindow,&x,&y) ;
437 X = x ;
438 Y = y ;
439
440 return (cstatus);
441}
442
443Xw_TypeOfVisual Xw_Window::VisualClass () const {
444
445 return (MyVisualClass);
446
447}
448
7fd59977 449Standard_Boolean Xw_Window::BackgroundPixel ( Standard_Integer &aPixel ) const {
450unsigned long pixel ;
451
452 status = Xw_get_background_pixel(MyExtendedWindow,&pixel) ;
453 if( !status ) PrintError() ;
454
455 aPixel = Standard_Integer(pixel);
456
457 return status;
458}
459
460
461Standard_Address Xw_Window::ExtendedWindow () const {
462
463 return (MyExtendedWindow);
464
465}