0023414: Remove deprecated classes Xw_PixMap and WNT_PixMap
[occt.git] / src / Xw / Xw_TypeMap.cxx
CommitLineData
b311480e 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
7fd59977 19
20#include <Xw_TypeMap.ixx>
21#include <Aspect_TypeOfLine.hxx>
22#include <Aspect_LineStyle.hxx>
23#include <Standard_ShortReal.hxx>
24#include <TShort_Array1OfShortReal.hxx>
25#include <TColQuantity_Array1OfLength.hxx>
26
27// Routines C a declarer en extern
28//extern "C" {
29#include <Xw_Cextern.hxx>
30//}
31
32//-Static data definitions
33
34static char *ErrorMessag ;
35static int ErrorNumber ;
36static int ErrorGravity ;
37static XW_STATUS status ;
38
39Xw_TypeMap::Xw_TypeMap () {
40}
41
42Xw_TypeMap::Xw_TypeMap (const Standard_CString Connexion) {
43
44 MyExtendedDisplay = Xw_open_display((Standard_PCharacter)Connexion) ;
45
46 if( !MyExtendedDisplay ) {
47 ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
48 if( ErrorGravity )
49 Aspect_TypeMapDefinitionError::Raise (ErrorMessag) ;
50 else Xw_print_error() ;
51 }
52
53 MyExtendedTypeMap = Xw_def_typemap(MyExtendedDisplay,(int)0) ;
54
55 if( !Xw_isdefine_typemap(MyExtendedTypeMap) ) {
56 ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
57 if( ErrorGravity )
58 Aspect_TypeMapDefinitionError::Raise (ErrorMessag) ;
59 else Xw_print_error() ;
60 }
61}
62
63void Xw_TypeMap::SetEntry (const Aspect_TypeMapEntry& Entry) {
64Aspect_LineStyle style = Entry.Type() ;
65int length = (int) style.Length() ;
66int ftype = (int) Entry.Index() ;
67const TColQuantity_Array1OfLength& values(style.Values()) ;
68TShort_Array1OfShortReal svalues(values.Lower(),values.Length()) ;
69float *V = (float*) &svalues.Value(values.Lower()) ;
70Standard_Integer i ;
71
72 if( ftype ) { /* Index 0 is default SOLID Line ,cann't be changed */
73 for( i=values.Lower() ; i<=values.Upper() ; i++)
74 svalues(i) = TOMILLIMETER(Standard_ShortReal(values(i))) ;
75
76 status = Xw_def_type(MyExtendedTypeMap,ftype,length,V) ;
77
78 if( !status ) {
79 ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
80 if( ErrorGravity > 2 )
81 Aspect_BadAccess::Raise (ErrorMessag) ;
82 else Xw_print_error() ;
83 }
84 }
85}
86
87void Xw_TypeMap::SetEntries (const Handle(Aspect_TypeMap)& Typemap) {
88Standard_Integer size = Typemap->Size() ;
89Standard_Integer i ;
90
91 if( !Xw_isdefine_typemap(MyExtendedTypeMap) ) {
92 ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
93 if( ErrorGravity > 2 )
94 Aspect_TypeMapDefinitionError::Raise (ErrorMessag) ;
95 else Xw_print_error() ;
96 }
97
98 for( i=1 ; i<=size ; i++ ) {
99 SetEntry(Typemap->Entry(i)) ;
100 }
101}
102
103void Xw_TypeMap::Destroy() {
104
105 if( MyExtendedTypeMap ) {
106 Xw_close_typemap(MyExtendedTypeMap) ;
107 MyExtendedTypeMap = NULL ;
108 }
109}
110
111Standard_Integer Xw_TypeMap::FreeTypes( ) const {
112Standard_Integer ntype ;
113int mtype,utype,dtype,ftype ;
114
115 status = Xw_get_typemap_info(MyExtendedTypeMap,
116 &mtype,&utype,&dtype,&ftype) ;
117
118 if( !status ) {
119 ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
120 if( ErrorGravity > 2 )
121 Aspect_BadAccess::Raise (ErrorMessag) ;
122 else Xw_print_error() ;
123 }
124
125 ntype = utype - dtype ;
126
127 return (ntype) ;
128}
129
130Standard_Address Xw_TypeMap::ExtendedTypeMap () const {
131
132 return (MyExtendedTypeMap);
133
134}