summaryrefslogtreecommitdiff
path: root/src/Xw/Xw_TypeMap.cxx
blob: 402ad561ff21b82db677ab7e729c98dc70f9034f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

#include <Xw_TypeMap.ixx>
#include <Aspect_TypeOfLine.hxx>
#include <Aspect_LineStyle.hxx>
#include <Standard_ShortReal.hxx>
#include <TShort_Array1OfShortReal.hxx>
#include <TColQuantity_Array1OfLength.hxx>

// Routines C a declarer en extern
//extern "C" {
#include <Xw_Cextern.hxx>
//}

//-Static data definitions

static char *ErrorMessag ;
static int ErrorNumber ;
static int ErrorGravity ;
static XW_STATUS status ;

Xw_TypeMap::Xw_TypeMap () {
}

Xw_TypeMap::Xw_TypeMap (const Standard_CString Connexion) {

        MyExtendedDisplay = Xw_open_display((Standard_PCharacter)Connexion) ;

        if( !MyExtendedDisplay ) {
            ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
            if( ErrorGravity )
                Aspect_TypeMapDefinitionError::Raise (ErrorMessag) ;
            else Xw_print_error() ;
        }

	MyExtendedTypeMap = Xw_def_typemap(MyExtendedDisplay,(int)0) ;
	
	if( !Xw_isdefine_typemap(MyExtendedTypeMap) ) {
	    ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; 
	    if( ErrorGravity ) 
		Aspect_TypeMapDefinitionError::Raise (ErrorMessag) ;
	    else Xw_print_error() ;
	} 
}

void Xw_TypeMap::SetEntry (const Aspect_TypeMapEntry& Entry) {
Aspect_LineStyle style = Entry.Type() ;
int length = (int) style.Length() ;
int ftype = (int) Entry.Index() ;
const TColQuantity_Array1OfLength& values(style.Values()) ;
TShort_Array1OfShortReal svalues(values.Lower(),values.Length()) ;
float *V = (float*) &svalues.Value(values.Lower()) ;
Standard_Integer i ;

    if( ftype ) {	/* Index 0 is default SOLID Line ,cann't be changed */
	for( i=values.Lower() ; i<=values.Upper() ; i++) 
		svalues(i) = TOMILLIMETER(Standard_ShortReal(values(i))) ;
	
	status = Xw_def_type(MyExtendedTypeMap,ftype,length,V) ;

	if( !status ) {
	    ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; 
	    if( ErrorGravity > 2 ) 
		Aspect_BadAccess::Raise (ErrorMessag) ;
	    else Xw_print_error() ;
	} 
    }
}

void Xw_TypeMap::SetEntries (const Handle(Aspect_TypeMap)& Typemap) {
Standard_Integer size = Typemap->Size() ;
Standard_Integer i ;

        if( !Xw_isdefine_typemap(MyExtendedTypeMap) ) {
            ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
            if( ErrorGravity > 2 )
                Aspect_TypeMapDefinitionError::Raise (ErrorMessag) ;
            else Xw_print_error() ;
        }

        for( i=1 ; i<=size ; i++ ) {
            SetEntry(Typemap->Entry(i)) ;
        }
}

void Xw_TypeMap::Destroy() {

        if( MyExtendedTypeMap ) {
            Xw_close_typemap(MyExtendedTypeMap) ;
            MyExtendedTypeMap = NULL ;
        }
}

Standard_Integer Xw_TypeMap::FreeTypes( ) const {
Standard_Integer ntype ;
int mtype,utype,dtype,ftype ;

	status = Xw_get_typemap_info(MyExtendedTypeMap,
				&mtype,&utype,&dtype,&ftype) ;

	if( !status ) {
	    ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; 
	    if( ErrorGravity > 2 ) 
		Aspect_BadAccess::Raise (ErrorMessag) ;
	    else Xw_print_error() ;
	} 

	ntype = utype - dtype ;

	return (ntype) ;
}

Standard_Address Xw_TypeMap::ExtendedTypeMap () const {

        return (MyExtendedTypeMap);

}