37a2de29418bddbecdd7c7dbb5361a16f31f2823
[occt.git] / src / Xw / Xw_WidthMap.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19
20 #include <Xw_WidthMap.ixx>
21 #include <Aspect_WidthOfLine.hxx>
22 #include <Standard_PCharacter.hxx>
23
24 // Routines C a declarer en extern
25 //extern "C" {
26 #include <Xw_Cextern.hxx>
27 //}
28
29 //-Static data definitions
30
31 static char *ErrorMessag ;
32 static int ErrorNumber ;
33 static int ErrorGravity ;
34 static XW_STATUS status ;
35
36 Xw_WidthMap::Xw_WidthMap () {
37 }
38
39 Xw_WidthMap::Xw_WidthMap (const Standard_CString Connexion) {
40
41         MyExtendedDisplay = Xw_open_display((Standard_PCharacter)Connexion) ;
42
43         if( !MyExtendedDisplay ) {
44             ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
45             if( ErrorGravity )
46                 Aspect_WidthMapDefinitionError::Raise (ErrorMessag) ;
47             else Xw_print_error() ;
48         }
49
50         MyExtendedWidthMap = Xw_def_widthmap(MyExtendedDisplay,(int)0) ;
51         
52         if( !Xw_isdefine_widthmap(MyExtendedWidthMap) ) {
53             ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; 
54             if( ErrorGravity ) 
55                 Aspect_WidthMapDefinitionError::Raise (ErrorMessag) ;
56             else Xw_print_error() ;
57         } 
58 }
59
60 void Xw_WidthMap::SetEntry (const Aspect_WidthMapEntry& Entry) {
61 int fwidth = (int) Entry.Index() ;
62 float width = (float) TOMILLIMETER(Entry.Width()) ;
63
64     if( fwidth ) {      /* Don't change Default index 0,One pixel Width */
65         status = Xw_def_width(MyExtendedWidthMap,fwidth,width) ;
66
67         if( !status ) {
68             ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; 
69             if( ErrorGravity > 2 ) 
70                 Aspect_BadAccess::Raise (ErrorMessag) ;
71             else Xw_print_error() ;
72         } 
73     }
74
75 }
76
77 void Xw_WidthMap::SetEntries (const Handle(Aspect_WidthMap)& Widthmap) {
78 Standard_Integer size = Widthmap->Size() ;
79 Standard_Integer i ;
80
81         if( !Xw_isdefine_widthmap(MyExtendedWidthMap) ) {
82             ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
83             if( ErrorGravity > 2 )
84                 Aspect_WidthMapDefinitionError::Raise (ErrorMessag) ;
85             else Xw_print_error() ;
86         }
87
88         for( i=1 ; i<=size ; i++ ) {
89             SetEntry(Widthmap->Entry(i)) ;
90         }
91 }
92
93 void Xw_WidthMap::Destroy() {
94
95         if( MyExtendedWidthMap ) {
96             Xw_close_widthmap(MyExtendedWidthMap) ;
97             MyExtendedWidthMap = NULL ;
98         }
99 }
100
101 Standard_Integer Xw_WidthMap::FreeWidths( ) const {
102 Standard_Integer nwidth ;
103 int mwidth,uwidth,dwidth,fwidth ;
104
105         status = Xw_get_widthmap_info(MyExtendedWidthMap,
106                                 &mwidth,&uwidth,&dwidth,&fwidth) ;
107
108         if( !status ) {
109             ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; 
110             if( ErrorGravity > 2 ) 
111                 Aspect_BadAccess::Raise (ErrorMessag) ;
112             else Xw_print_error() ;
113         } 
114
115         nwidth = uwidth - dwidth ;
116
117         return (nwidth) ;
118 }
119
120 Standard_Address Xw_WidthMap::ExtendedWidthMap () const {
121
122         return (MyExtendedWidthMap);
123
124 }