7fd59977 |
1 | /*********************************************************************** |
2 | |
3 | FONCTION : |
4 | ---------- |
5 | Classe Graphic3d_GraphicDevice.cxx : |
6 | |
7 | |
8 | HISTORIQUE DES MODIFICATIONS : |
9 | -------------------------------- |
10 | Janvier 1994 : CAL ; Creation. |
11 | 04-02-97 : FMN ; Suppression appel call_tox_set_colormap_mapping() |
12 | 10-09-00 : GG ; NEW OpenGl driver loading specification |
13 | when nothing is defined the driver libTKOpenGl[.so|.sl] |
14 | is loading from the current PATH |
15 | |
16 | ************************************************************************/ |
17 | #define RIC120302 //GG Add new constructor to pass Display structure |
18 | // directly instead string connexion. |
19 | |
20 | #define XDESTROY |
21 | |
22 | #ifndef WNT |
23 | |
24 | #include <stdio.h> |
25 | #include <sys/utsname.h> |
26 | |
27 | /*----------------------------------------------------------------------*/ |
28 | /* |
29 | * Includes |
30 | */ |
31 | |
32 | #include <Graphic3d_GraphicDevice.ixx> |
33 | #include <Graphic3d_GraphicDriver.hxx> |
34 | #include <OSD_Function.hxx> |
35 | #include <TCollection_AsciiString.hxx> |
36 | |
37 | #include <Xw_Cextern.hxx> |
38 | |
39 | //-Static data definitions |
40 | |
41 | static char LocalMessag[80] ; |
42 | |
43 | //-Aliases |
44 | |
45 | //-Global data definitions |
46 | |
47 | //-Constructor |
48 | |
49 | Graphic3d_GraphicDevice::Graphic3d_GraphicDevice (const Standard_CString Connexion, const Xw_TypeOfMapping /*Mapping*/, const Standard_Integer Ncolors, const Standard_Boolean UseDefault ): |
50 | Xw_GraphicDevice () { |
51 | Standard_CString connexion = (Connexion) ? Connexion : Standard_CString("") ; |
52 | Standard_Boolean status ; |
53 | |
54 | MyExtendedDisplay = Xw_open_display((Standard_PCharacter)connexion) ; |
55 | |
56 | if( !MyExtendedDisplay ) { |
57 | sprintf(LocalMessag,"Cannot connect to server '%s'",connexion) ; |
58 | Aspect_GraphicDeviceDefinitionError::Raise (LocalMessag); |
59 | } |
60 | |
61 | SetGraphicDriver (); |
62 | |
63 | status = MyGraphicDriver->Begin (connexion); |
64 | |
65 | if( !status ) { |
66 | sprintf(LocalMessag,"Cannot connect to graphic library from '%s'", |
67 | connexion) ; |
68 | Aspect_GraphicDeviceDefinitionError::Raise (LocalMessag); |
69 | } |
70 | |
71 | this->InitMaps (connexion,Xw_TOM_READONLY,Ncolors,UseDefault); |
81bba717 |
72 | |
7fd59977 |
73 | |
74 | } |
75 | |
76 | //RIC120302 |
77 | Graphic3d_GraphicDevice::Graphic3d_GraphicDevice (const Aspect_Display pdisplay) |
78 | : Xw_GraphicDevice () |
79 | { |
80 | Standard_Boolean status ; |
81 | |
82 | if( !pdisplay ) |
83 | Aspect_GraphicDeviceDefinitionError::Raise ("Bad display pointer"); |
84 | MyExtendedDisplay = Xw_set_display(pdisplay) ; |
85 | Standard_CString connexion = Xw_get_display_name(MyExtendedDisplay); |
86 | |
87 | if( !MyExtendedDisplay ) { |
88 | if( connexion ) |
89 | sprintf(LocalMessag,"Cannot connect to server '%s'",connexion) ; |
90 | else |
91 | sprintf(LocalMessag,"Cannot connect to an UNKNOWN server") ; |
92 | Aspect_GraphicDeviceDefinitionError::Raise (LocalMessag); |
93 | } |
94 | |
95 | SetGraphicDriver (); |
96 | |
97 | status = MyGraphicDriver->Begin (pdisplay); |
98 | |
99 | if( !status ) { |
100 | sprintf(LocalMessag,"Cannot connect to graphic library from '%s'", |
101 | connexion) ; |
102 | Aspect_GraphicDeviceDefinitionError::Raise (LocalMessag); |
103 | } |
104 | |
105 | this->InitMaps (connexion,Xw_TOM_READONLY,0,Standard_True); |
106 | } |
107 | //RIC120302 |
108 | |
109 | // Destructor |
110 | |
111 | void Graphic3d_GraphicDevice::Destroy () { |
112 | |
113 | #ifdef DESTROY |
114 | cout << "Graphic3d_GraphicDevice::Destroy ()\n"; |
115 | #endif |
116 | |
117 | MyGraphicDriver->End (); |
118 | |
119 | } |
120 | |
121 | // Methods in order |
122 | |
123 | Handle(Aspect_GraphicDriver) Graphic3d_GraphicDevice::GraphicDriver () const { |
124 | |
125 | return MyGraphicDriver; |
126 | |
127 | } |
128 | |
129 | void Graphic3d_GraphicDevice::SetGraphicDriver () { |
130 | |
131 | Standard_CString TheShr; |
132 | |
133 | if (! ShrIsDefined (TheShr)) { |
134 | Aspect_GraphicDeviceDefinitionError::Raise |
135 | ("Bad environment, Graphic Library not defined"); |
136 | } |
137 | |
138 | OSD_SharedLibrary TheSharedLibrary (TheShr); |
139 | |
140 | Standard_Boolean Result = TheSharedLibrary.DlOpen (OSD_RTLD_LAZY); |
141 | |
142 | if (! Result) { |
143 | Aspect_GraphicDeviceDefinitionError::Raise |
144 | (TheSharedLibrary.DlError ()); |
145 | } |
146 | else { |
81bba717 |
147 | // Management of traces |
7fd59977 |
148 | char *tracevalue = NULL; |
149 | tracevalue = (char *)(getenv ("CSF_GraphicTrace")); |
150 | if (tracevalue) |
151 | cout << "Information : " << TheShr << " loaded\n" << flush; |
152 | |
153 | OSD_Function new_GLGraphicDriver = |
154 | TheSharedLibrary.DlSymb ("MetaGraphicDriverFactory"); |
155 | if (tracevalue) |
156 | cout << "Information : MetaGraphicDriverFactory " |
157 | << (new_GLGraphicDriver ? "found\n" : "not found\n") << flush; |
158 | if (! new_GLGraphicDriver) { |
159 | Aspect_GraphicDeviceDefinitionError::Raise |
160 | (TheSharedLibrary.DlError ()); |
161 | } |
162 | else { |
81bba717 |
163 | // Sequence : |
164 | // new_GLGraphicDriver is OSD_Function : |
7fd59977 |
165 | // typedef int (* OSD_Function)(...); |
81bba717 |
166 | // that is why good cast in GraphicDriver. |
7fd59977 |
167 | Handle(Graphic3d_GraphicDriver) |
168 | (*fp) (Standard_CString) = NULL; |
169 | fp = (Handle(Graphic3d_GraphicDriver) |
170 | (*) (Standard_CString)) new_GLGraphicDriver; |
171 | if (tracevalue) cout << "FP == "<<(void *) fp<<endl; |
172 | Standard_CString aSharedName = TheSharedLibrary.Name (); |
173 | MyGraphicDriver = (*fp) (aSharedName); |
174 | |
175 | // MyGraphicDriver = (*fp) (TheSharedLibrary.Name ()); |
176 | |
81bba717 |
177 | // Management of traces |
7fd59977 |
178 | if (tracevalue) |
179 | MyGraphicDriver->SetTrace |
180 | ((Standard_Integer) atoi (tracevalue)); |
181 | } |
182 | } |
183 | |
184 | } |
185 | |
186 | #define BAD(x) (((x) == NULL) || (strlen((x)) <= 0)) |
187 | |
188 | Standard_Boolean Graphic3d_GraphicDevice::ShrIsDefined (Standard_CString& aShr) const { |
189 | |
190 | char *glso, *glul, *pkno; |
191 | char *glshr, *casroot; |
192 | |
193 | casroot = getenv("CASROOT"); |
194 | glso = getenv("CSF_GraphicShr"); |
195 | glul = getenv("GRAPHICHOME"); |
196 | pkno = getenv("CSF_Graphic3dLib"); |
197 | |
198 | if (! BAD(glso)) { |
199 | glshr = getenv("CSF_GraphicShr"); |
200 | } else if (! BAD(casroot)) { |
201 | TCollection_AsciiString buffString(casroot); |
202 | struct utsname info; |
203 | uname (&info); |
204 | buffString = buffString + "/"; |
205 | buffString = buffString + info.sysname; |
206 | #if defined(__hpux) || defined(HPUX) |
207 | buffString = buffString + "/lib/libTKOpenGl.sl"; |
208 | #elif defined(WNT) |
209 | buffString = buffString + "/TKOpenGl.dll"; |
210 | #elif defined(__APPLE__) |
211 | buffString = buffString + "/lib/libTKOpenGl.dylib"; |
212 | #else |
213 | buffString = buffString + "/lib/libTKOpenGl.so"; |
214 | #endif |
215 | glshr = (char *) malloc (buffString.Length() + 1); |
216 | memcpy(glshr, buffString.ToCString(), buffString.Length() + 1); |
217 | } else { |
218 | aShr = NULL; |
219 | printf("You have not defined CSF_GraphicShr or CASROOT, aborting..."); |
220 | return Standard_False; |
221 | } |
222 | |
223 | aShr = glshr; |
224 | |
225 | return Standard_True; |
226 | |
227 | } |
228 | #endif // WNT |