b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | |
19 | #include <Xw_Extension.h> |
20 | |
b311480e |
21 | /* ifdef then trace on */ |
7fd59977 |
22 | #ifdef TRACE |
23 | #define TRACE_DEF_TYPE |
24 | #endif |
25 | |
26 | /* |
27 | STATUS Xw_def_type (atypemap,index,length,desc): |
28 | XW_EXT_TYPEMAP *atypemap |
29 | int index Line type index |
30 | int length Descriptor length |
31 | float *desc Type Descriptor |
32 | |
33 | Update Line Type Extended typemap index with the specified TYPE values . Descriptor is an array of float.Each value give the subline length |
34 | in MM .First subline is the draw part,Second the hidden part, |
35 | Thirst the drawn part ... |
36 | NOTE than type index 0 is the Default Type (SOLID) |
37 | and cann't be REDEFINED |
38 | |
39 | Returns ERROR if BadType Index |
40 | Returns SUCCESS if Successful |
41 | |
42 | */ |
43 | |
44 | #ifdef XW_PROTOTYPE |
45 | XW_STATUS Xw_def_type (void* atypemap, |
46 | int index,int length,float* desc) |
47 | #else |
48 | XW_STATUS Xw_def_type (atypemap,index,length,desc) |
49 | void *atypemap; |
50 | int index ; |
51 | int length ; |
52 | float *desc ; |
53 | #endif /*XW_PROTOTYPE*/ |
54 | { |
55 | XW_EXT_TYPEMAP *ptypemap = (XW_EXT_TYPEMAP*)atypemap ; |
56 | Screen *screen ; |
57 | unsigned char *pdesc ; |
58 | int i,ptype ; |
59 | |
60 | if ( !Xw_isdefine_typeindex(ptypemap,index) ) { |
61 | /*Bad Type index*/ |
62 | Xw_set_error(18,"Xw_def_type",&index) ; |
63 | return (XW_ERROR) ; |
64 | } |
65 | |
66 | if( !desc || length < 0 ) { |
67 | /*Bad Type descriptor data*/ |
68 | Xw_set_error(19,"Xw_def_type",&index) ; |
69 | return (XW_ERROR) ; |
70 | } |
71 | |
72 | if( ptypemap->types[index] ) Xw_free(ptypemap->types[index]) ; |
73 | ptypemap->types[index] = NULL ; |
74 | |
75 | if( length ) { |
76 | ptypemap->types[index] = pdesc = (unsigned char*) Xw_malloc(length+1) ; |
77 | |
78 | screen = ScreenOfDisplay(_TDISPLAY,DefaultScreen(_TDISPLAY)) ; |
79 | |
80 | for( i=0 ; i<length ; i++ ) { |
81 | pdesc[i] = 1 ; |
82 | ptype = (int) (0.5 + (desc[i] * (float)WidthOfScreen(screen)/ |
83 | (float)WidthMMOfScreen(screen))) ; |
84 | if( desc[i] == 0. || ptype < 0 || ptype > 255 ) { |
85 | /*Bad Type descriptor data*/ |
86 | Xw_set_error(19,"Xw_def_type",&index) ; |
87 | } |
88 | pdesc[i] = (unsigned char) (ptype) ? ptype : 1 ; |
89 | } |
90 | |
91 | pdesc[length] ='\0' ; |
92 | } |
93 | |
94 | #ifdef TRACE_DEF_TYPE |
95 | if( Xw_get_trace() ) { |
96 | printf (" Xw_def_type(%lx,%d,%d,{",(long ) ptypemap,index,length); |
97 | for ( i=0 ; i<length-1 ; i++ ) printf("%f,",desc[i]) ; |
98 | printf("%f})\n",desc[length-1]) ; |
99 | } |
100 | #endif |
101 | |
102 | return (XW_SUCCESS); |
103 | } |