0022627: Change OCCT memory management defaults
[occt.git] / src / Xw / Xw_WidthMap.cxx
1
2 #include <Xw_WidthMap.ixx>
3 #include <Aspect_WidthOfLine.hxx>
4
5 // Routines C a declarer en extern
6 //extern "C" {
7 #include <Xw_Cextern.hxx>
8 //}
9
10 //-Static data definitions
11
12 static char *ErrorMessag ;
13 static int ErrorNumber ;
14 static int ErrorGravity ;
15 static XW_STATUS status ;
16
17 Xw_WidthMap::Xw_WidthMap () {
18 }
19
20 Xw_WidthMap::Xw_WidthMap (const Standard_CString Connexion) {
21
22         MyExtendedDisplay = Xw_open_display((Standard_PCharacter)Connexion) ;
23
24         if( !MyExtendedDisplay ) {
25             ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
26             if( ErrorGravity )
27                 Aspect_WidthMapDefinitionError::Raise (ErrorMessag) ;
28             else Xw_print_error() ;
29         }
30
31         MyExtendedWidthMap = Xw_def_widthmap(MyExtendedDisplay,(int)0) ;
32         
33         if( !Xw_isdefine_widthmap(MyExtendedWidthMap) ) {
34             ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; 
35             if( ErrorGravity ) 
36                 Aspect_WidthMapDefinitionError::Raise (ErrorMessag) ;
37             else Xw_print_error() ;
38         } 
39 }
40
41 void Xw_WidthMap::SetEntry (const Aspect_WidthMapEntry& Entry) {
42 int fwidth = (int) Entry.Index() ;
43 float width = (float) TOMILLIMETER(Entry.Width()) ;
44
45     if( fwidth ) {      /* Don't change Default index 0,One pixel Width */
46         status = Xw_def_width(MyExtendedWidthMap,fwidth,width) ;
47
48         if( !status ) {
49             ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; 
50             if( ErrorGravity > 2 ) 
51                 Aspect_BadAccess::Raise (ErrorMessag) ;
52             else Xw_print_error() ;
53         } 
54     }
55
56 }
57
58 void Xw_WidthMap::SetEntries (const Handle(Aspect_WidthMap)& Widthmap) {
59 Standard_Integer size = Widthmap->Size() ;
60 Standard_Integer i ;
61
62         if( !Xw_isdefine_widthmap(MyExtendedWidthMap) ) {
63             ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
64             if( ErrorGravity > 2 )
65                 Aspect_WidthMapDefinitionError::Raise (ErrorMessag) ;
66             else Xw_print_error() ;
67         }
68
69         for( i=1 ; i<=size ; i++ ) {
70             SetEntry(Widthmap->Entry(i)) ;
71         }
72 }
73
74 void Xw_WidthMap::Destroy() {
75
76         if( MyExtendedWidthMap ) {
77             Xw_close_widthmap(MyExtendedWidthMap) ;
78             MyExtendedWidthMap = NULL ;
79         }
80 }
81
82 Standard_Integer Xw_WidthMap::FreeWidths( ) const {
83 Standard_Integer nwidth ;
84 int mwidth,uwidth,dwidth,fwidth ;
85
86         status = Xw_get_widthmap_info(MyExtendedWidthMap,
87                                 &mwidth,&uwidth,&dwidth,&fwidth) ;
88
89         if( !status ) {
90             ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; 
91             if( ErrorGravity > 2 ) 
92                 Aspect_BadAccess::Raise (ErrorMessag) ;
93             else Xw_print_error() ;
94         } 
95
96         nwidth = uwidth - dwidth ;
97
98         return (nwidth) ;
99 }
100
101 Standard_Address Xw_WidthMap::ExtendedWidthMap () const {
102
103         return (MyExtendedWidthMap);
104
105 }