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);
}
} 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
}
// analyze arguments
// *****************************************************************
Draw_Batch = Standard_False;
- char* runfile = NULL;
+ TCollection_AsciiString aRunFile;
Standard_Integer i;
Standard_Boolean isInteractiveForced = Standard_False;
#ifndef WNT
} 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;
}
Draw_VirtualWindows = !isInteractiveForced;
p = strtok(NULL," \t");
if (p != NULL) {
- runfile = p;
+ aRunFile = TCollection_AsciiString (p);
}
break;
}
// 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;
Draw_LowWindows = Standard_False;
#endif
- ReadInitFile(runfile);
+ ReadInitFile (aRunFile);
// provide a clean exit, this is usefull for some analysis tools
#ifndef WNT
return;
GraphicDriver from Aspect,
Display from Aspect,
GraphicDriver from Graphic3d,
- TypeOfMapping from Xw
+ TypeOfMapping from Xw,
+ AsciiString from TCollection
raises
---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
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 <stdio.h>
#include <sys/utsname.h>
#include <Graphic3d_GraphicDevice.ixx>
#include <Graphic3d_GraphicDriver.hxx>
#include <OSD_Function.hxx>
+#include <OSD_Environment.hxx>
#include <TCollection_AsciiString.hxx>
#include <Xw_Cextern.hxx>
}
-//RIC120302
Graphic3d_GraphicDevice::Graphic3d_GraphicDevice (const Aspect_Display pdisplay)
: Xw_GraphicDevice ()
{
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
void Graphic3d_GraphicDevice::SetGraphicDriver () {
-Standard_CString TheShr;
-
- if (! ShrIsDefined (TheShr)) {
- Aspect_GraphicDeviceDefinitionError::Raise
- ("Bad environment, Graphic Library not defined");
- }
+ TCollection_AsciiString aShr = ShrEnvString ();
-OSD_SharedLibrary TheSharedLibrary (TheShr);
+ OSD_SharedLibrary TheSharedLibrary (aShr.ToCString());
-Standard_Boolean Result = TheSharedLibrary.DlOpen (OSD_RTLD_LAZY);
+ Standard_Boolean Result = TheSharedLibrary.DlOpen (OSD_RTLD_LAZY);
if (! Result) {
Aspect_GraphicDeviceDefinitionError::Raise
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");
}
-#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");
+TCollection_AsciiString Graphic3d_GraphicDevice::ShrEnvString() const
+{
+ OSD_Environment aEnvShr ("CSF_GraphicShr");
+ if (!aEnvShr.Value().IsEmpty())
+ {
+ return aEnvShr.Value();
+ }
- 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;
+ // load TKOpenGl using default searching mechanisms in system
#if defined(__hpux) || defined(HPUX)
- buffString = buffString + "/lib/libTKOpenGl.sl";
-#elif defined(WNT)
- buffString = buffString + "/TKOpenGl.dll";
+ return TCollection_AsciiString ("libTKOpenGl.sl");
#elif defined(__APPLE__)
- buffString = buffString + "/lib/libTKOpenGl.dylib";
+ return TCollection_AsciiString ("libTKOpenGl.dylib");
#else
- buffString = buffString + "/lib/libTKOpenGl.so";
+ return TCollection_AsciiString ("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;
- }
-
- aShr = glshr;
-
- return Standard_True;
-
}
-#endif // WNT
+
+#endif // !WNT