diff --git a/src/Draw/Draw.cxx b/src/Draw/Draw.cxx index b9ca5e765e..e961bf21d4 100755 --- a/src/Draw/Draw.cxx +++ b/src/Draw/Draw.cxx @@ -89,15 +89,16 @@ extern console_semaphore_value volatile console_semaphore; extern char console_command[1000]; #endif -static void ReadInitFile(char* filename) +static void ReadInitFile (const TCollection_AsciiString& theFileName) { + TCollection_AsciiString aPath = theFileName; #ifdef WNT if (!Draw_Batch) { try { OCC_CATCH_SIGNALS - for(Standard_Integer i = 0; filename[i] != 0; i++) - if(filename[i] == '\\') filename[i] = '/'; - sprintf(console_command,"source \"%s\"",filename); + aPath.ChangeAll ('\\', '/'); + + sprintf(console_command, "source \"%s\"", aPath.ToCString()); console_semaphore = HAS_CONSOLE_COMMAND; while (console_semaphore == HAS_CONSOLE_COMMAND) Sleep(10); @@ -108,9 +109,9 @@ static void ReadInitFile(char* filename) } } else { #endif - char* com = new char [strlen(filename)+strlen("source ")+2]; - sprintf(com,"source %s",filename); - Draw_Interprete(com); + char* com = new char [aPath.Length() + strlen ("source ") + 2]; + sprintf (com, "source %s", aPath.ToCString()); + Draw_Interprete (com); delete [] com; #ifdef WNT } @@ -159,7 +160,7 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In // analyze arguments // ***************************************************************** Draw_Batch = Standard_False; - char* runfile = NULL; + TCollection_AsciiString aRunFile; Standard_Integer i; Standard_Boolean isInteractiveForced = Standard_False; #ifndef WNT @@ -181,7 +182,7 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In } else if (strcasecmp(argv[i],"-f") == 0) { // -f option should be LAST! Draw_VirtualWindows = !isInteractiveForced; if (++i < argc) { - runfile = argv[i]; + aRunFile = TCollection_AsciiString (argv[i]); } break; } @@ -199,7 +200,7 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In Draw_VirtualWindows = !isInteractiveForced; p = strtok(NULL," \t"); if (p != NULL) { - runfile = p; + aRunFile = TCollection_AsciiString (p); } break; } @@ -261,35 +262,32 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In // read init files // ***************************************************************** // default - char* dflt = getenv("DRAWDEFAULT"); - if (dflt == NULL) + + if (getenv ("DRAWDEFAULT") == NULL) { - char* casroot = getenv("CASROOT"); - if (casroot == NULL) + if (getenv ("CASROOT") == NULL) { #ifdef WNT - ReadInitFile("ddefault"); + ReadInitFile ("ddefault"); #else - cout << " the CASROOT variable is mandatory to Run OpenCascade "<< endl; - cout << "No default file" << endl; + cout << " the CASROOT variable is mandatory to Run OpenCascade "<< endl; + cout << "No default file" << endl; #endif } else { - char* thedefault = (char *) malloc (128); - thedefault[0] = '\0'; - strcat(thedefault,casroot); - strcat (thedefault,"/src/DrawResources/DrawDefault"); - ReadInitFile(thedefault); + TCollection_AsciiString aDefStr (getenv ("CASROOT")); + aDefStr += "/src/DrawResources/DrawDefault"; + ReadInitFile (aDefStr); } } else { - ReadInitFile(dflt); + ReadInitFile (getenv ("DRAWDEFAULT")); } // pure batch - if (runfile) { + if (!aRunFile.IsEmpty()) { // do not map raise the windows, so test programs are discrete #ifndef WNT Draw_LowWindows = Standard_True; @@ -300,7 +298,7 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In Draw_LowWindows = Standard_False; #endif - ReadInitFile(runfile); + ReadInitFile (aRunFile); // provide a clean exit, this is usefull for some analysis tools #ifndef WNT return; diff --git a/src/Graphic3d/Graphic3d_GraphicDevice.cdl b/src/Graphic3d/Graphic3d_GraphicDevice.cdl index c3bc2245e3..282a268339 100755 --- a/src/Graphic3d/Graphic3d_GraphicDevice.cdl +++ b/src/Graphic3d/Graphic3d_GraphicDevice.cdl @@ -20,7 +20,8 @@ uses GraphicDriver from Aspect, Display from Aspect, GraphicDriver from Graphic3d, - TypeOfMapping from Xw + TypeOfMapping from Xw, + AsciiString from TCollection raises @@ -62,14 +63,14 @@ is ---Level: Internal ---Purpose: Sets the GraphicDriver. - ShrIsDefined ( me; - aShr : out CString from Standard ) - returns Boolean from Standard + ShrEnvString ( me ) + returns AsciiString from TCollection is private; ---Level: Internal - ---Purpose: Returns Standard_True if the shared library - -- is defined by the environment. - -- (variables : CSF_GraphicShr, CSF_Graphic3dLib, GRAPHICHOME) + ---Purpose: Returns the environment string for loading shared graphics library. + -- The string can be defined in environment by corresponding variables, + -- or default value will be used for loading from system library path + -- Environment variables : CSF_GraphicShr fields diff --git a/src/Graphic3d/Graphic3d_GraphicDevice.cxx b/src/Graphic3d/Graphic3d_GraphicDevice.cxx index 0b62b4b7b9..1acec330ed 100755 --- a/src/Graphic3d/Graphic3d_GraphicDevice.cxx +++ b/src/Graphic3d/Graphic3d_GraphicDevice.cxx @@ -14,12 +14,7 @@ is loading from the current PATH ************************************************************************/ -#define RIC120302 //GG Add new constructor to pass Display structure -// directly instead string connexion. - -#define XDESTROY - -#ifndef WNT +#if (!defined(_WIN32) && !defined(__WIN32__)) #include #include @@ -32,6 +27,7 @@ #include #include #include +#include #include #include @@ -73,7 +69,6 @@ Standard_Boolean status ; } -//RIC120302 Graphic3d_GraphicDevice::Graphic3d_GraphicDevice (const Aspect_Display pdisplay) : Xw_GraphicDevice () { @@ -104,18 +99,11 @@ Graphic3d_GraphicDevice::Graphic3d_GraphicDevice (const Aspect_Display pdisplay) this->InitMaps (connexion,Xw_TOM_READONLY,0,Standard_True); } -//RIC120302 // Destructor - -void Graphic3d_GraphicDevice::Destroy () { - -#ifdef DESTROY - cout << "Graphic3d_GraphicDevice::Destroy ()\n"; -#endif - - MyGraphicDriver->End (); - +void Graphic3d_GraphicDevice::Destroy() +{ + MyGraphicDriver->End(); } // Methods in order @@ -128,16 +116,11 @@ Handle(Aspect_GraphicDriver) Graphic3d_GraphicDevice::GraphicDriver () const { void Graphic3d_GraphicDevice::SetGraphicDriver () { -Standard_CString TheShr; + TCollection_AsciiString aShr = ShrEnvString (); - if (! ShrIsDefined (TheShr)) { - Aspect_GraphicDeviceDefinitionError::Raise - ("Bad environment, Graphic Library not defined"); - } + OSD_SharedLibrary TheSharedLibrary (aShr.ToCString()); -OSD_SharedLibrary TheSharedLibrary (TheShr); - -Standard_Boolean Result = TheSharedLibrary.DlOpen (OSD_RTLD_LAZY); + Standard_Boolean Result = TheSharedLibrary.DlOpen (OSD_RTLD_LAZY); if (! Result) { Aspect_GraphicDeviceDefinitionError::Raise @@ -148,7 +131,7 @@ Standard_Boolean Result = TheSharedLibrary.DlOpen (OSD_RTLD_LAZY); char *tracevalue = NULL; tracevalue = (char *)(getenv ("CSF_GraphicTrace")); if (tracevalue) - cout << "Information : " << TheShr << " loaded\n" << flush; + cout << "Information : " << aShr << " loaded\n" << flush; OSD_Function new_GLGraphicDriver = TheSharedLibrary.DlSymb ("MetaGraphicDriverFactory"); @@ -183,46 +166,22 @@ OSD_Function new_GLGraphicDriver = } -#define BAD(x) (((x) == NULL) || (strlen((x)) <= 0)) - -Standard_Boolean Graphic3d_GraphicDevice::ShrIsDefined (Standard_CString& aShr) const { - - char *glso, *glul, *pkno; - char *glshr, *casroot; - - casroot = getenv("CASROOT"); - glso = getenv("CSF_GraphicShr"); - glul = getenv("GRAPHICHOME"); - pkno = getenv("CSF_Graphic3dLib"); - - if (! BAD(glso)) { - glshr = getenv("CSF_GraphicShr"); - } else if (! BAD(casroot)) { - TCollection_AsciiString buffString(casroot); - struct utsname info; - uname (&info); - buffString = buffString + "/"; - buffString = buffString + info.sysname; -#if defined(__hpux) || defined(HPUX) - buffString = buffString + "/lib/libTKOpenGl.sl"; -#elif defined(WNT) - buffString = buffString + "/TKOpenGl.dll"; -#elif defined(__APPLE__) - buffString = buffString + "/lib/libTKOpenGl.dylib"; -#else - buffString = buffString + "/lib/libTKOpenGl.so"; -#endif - glshr = (char *) malloc (buffString.Length() + 1); - memcpy(glshr, buffString.ToCString(), buffString.Length() + 1); - } else { - aShr = NULL; - printf("You have not defined CSF_GraphicShr or CASROOT, aborting..."); - return Standard_False; +TCollection_AsciiString Graphic3d_GraphicDevice::ShrEnvString() const +{ + OSD_Environment aEnvShr ("CSF_GraphicShr"); + if (!aEnvShr.Value().IsEmpty()) + { + return aEnvShr.Value(); } - - aShr = glshr; - - return Standard_True; - + + // load TKOpenGl using default searching mechanisms in system +#if defined(__hpux) || defined(HPUX) + return TCollection_AsciiString ("libTKOpenGl.sl"); +#elif defined(__APPLE__) + return TCollection_AsciiString ("libTKOpenGl.dylib"); +#else + return TCollection_AsciiString ("libTKOpenGl.so"); +#endif } -#endif // WNT + +#endif // !WNT