00001
00002
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00027 #include <exotkAF_Application.hxx>
00028 #ifndef _exotkUtils_OSD_HeaderFile
00029 #include <exotkUtils_OSD.hxx>
00030 #endif
00031 #ifndef _TCollection_AsciiString_HeaderFile
00032 #include <TCollection_AsciiString.hxx>
00033 #endif
00034 #ifndef _Handle_exotkAF_Application_HeaderFile
00035 #include <Handle_exotkAF_Application.hxx>
00036 #endif
00037 #ifndef _exotkAF_HeaderFile
00038 #include <exotkAF.hxx>
00039 #endif
00040 #ifndef _exotkAF_HSetOfDocument_HeaderFile
00041 #include <exotkAF_HSetOfDocument.hxx>
00042 #endif
00043 #ifndef _exotkAF_SetIteratorOfSetOfDocument_HeaderFile
00044 #include <exotkAF_SetIteratorOfSetOfDocument.hxx>
00045 #endif
00046 #ifndef _exotkPlugin_HeaderFile
00047 #include <exotkPlugin.hxx>
00048 #endif
00049 #ifndef _OSD_FileIterator_HeaderFile
00050 #include <OSD_FileIterator.hxx>
00051 #endif
00052 #ifndef _exotkPlugin_Plugin_HeaderFile
00053 #include <exotkPlugin_Plugin.hxx>
00054 #endif
00055 #ifndef _exotkDX_HeaderFile
00056 #include <exotkDX.hxx>
00057 #endif
00058 #ifndef _Standard_DefineHandle_HeaderFile
00059 #include <Standard_DefineHandle.hxx>
00060 #endif
00061 #ifndef _exotkTrace_HeaderFile
00062 #include <exotkTrace.hxx>
00063 #endif
00064 #include <io.h>
00065
00066
00067 IMPLEMENT_STANDARD_HANDLE(exotkAF_Application, MMgt_TShared)
00068 IMPLEMENT_STANDARD_RTTI(exotkAF_Application, MMgt_TShared)
00069
00070
00071
00072
00073
00074
00075
00076 IMPLEMENT_STANDARD_TYPE(exotkAF_Application)
00077 IMPLEMENT_STANDARD_SUPERTYPE(MMgt_TShared)
00078 IMPLEMENT_STANDARD_SUPERTYPE(Standard_Transient)
00079 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY()
00080 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(MMgt_TShared)
00081 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(Standard_Transient)
00082 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END()
00083 IMPLEMENT_STANDARD_TYPE_END(exotkAF_Application)
00084
00090 namespace exotkAF_Application_Datas
00091 {
00093 exotkAF_SetIteratorOfSetOfDocument theDocIterator;
00094 }
00095
00100 typedef void (*PLUGINID_FCT)(TCollection_AsciiString& anID);
00101
00102
00103
00104
00105
00106
00107
00108
00109 exotkAF_Application::exotkAF_Application()
00110 {
00111 myDocuments = new exotkAF_HSetOfDocument();
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 exotkAF_Application::~exotkAF_Application()
00123 {
00124 myDocuments->Clear();
00125 exotkAF::SetApplication(Handle_exotkAF_Application());
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 Standard_Boolean exotkAF_Application::SetOpenCASCADEEnvironmentVariables(const TCollection_AsciiString& aCSFGraphicShr, const TCollection_AsciiString& aCSFUnitsDefinition , const TCollection_AsciiString& aCSFUnitsLexicon , const TCollection_AsciiString& aCSFMDTVFontDirectory , const TCollection_AsciiString& aCSFMDTVTexturesDirectory)
00141 {
00142 if ( !exotkUtils_OSD::FileExists(aCSFGraphicShr) )
00143 return Standard_False;
00144
00145 if ( !exotkUtils_OSD::FileExists(aCSFUnitsDefinition) )
00146 return Standard_False;
00147
00148 if ( !exotkUtils_OSD::FileExists(aCSFUnitsLexicon) )
00149 return Standard_False;
00150
00151 if ( !exotkUtils_OSD::FileExists(aCSFMDTVFontDirectory) )
00152 return Standard_False;
00153
00154 if ( !exotkUtils_OSD::FileExists(aCSFMDTVTexturesDirectory) )
00155 return Standard_False;
00156
00157 return (exotkUtils_OSD::AddEnvironmentVariable("CSF_GraphicSHR", aCSFGraphicShr)
00158 && exotkUtils_OSD::AddEnvironmentVariable("CSF_UnitsDefinition", aCSFUnitsDefinition)
00159 && exotkUtils_OSD::AddEnvironmentVariable("CSF_UnitsLexicon", aCSFUnitsLexicon)
00160 && exotkUtils_OSD::AddEnvironmentVariable("CSF_MDTVFontDirectory", aCSFMDTVFontDirectory)
00161 && exotkUtils_OSD::AddEnvironmentVariable("CSF_MDTVTexturesDirectory", aCSFMDTVTexturesDirectory)
00162 );
00163 }
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 Standard_Boolean exotkAF_Application::AddDocument(const Handle_exotkAF_Document &aDocument)
00175 {
00176 return myDocuments->Add(aDocument);
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 Standard_Boolean exotkAF_Application::RemoveDocument(const Handle_exotkAF_Document &aDocument)
00188 {
00189 return myDocuments->Remove(aDocument);
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199 void exotkAF_Application::InitDocIterator()
00200 {
00201 exotkAF_Application_Datas::theDocIterator.Initialize(myDocuments->Set());
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211 Standard_Boolean exotkAF_Application::MoreDocIterator()
00212 {
00213 return exotkAF_Application_Datas::theDocIterator.More();
00214 }
00215
00216
00217
00218
00219
00220
00221
00222
00223 void exotkAF_Application::NextDocIterator()
00224 {
00225 exotkAF_Application_Datas::theDocIterator.Next();
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235 Handle_exotkAF_Document exotkAF_Application::CurrentDocIterator()
00236 {
00237 return exotkAF_Application_Datas::theDocIterator.Value();
00238 }
00239
00240
00241
00242
00243
00244
00245
00246
00247 Standard_Integer exotkAF_Application::NbDocuments()
00248 {
00249 return myDocuments->Extent();
00250 }
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 Standard_Boolean exotkAF_Application::SetPluginPath(const TCollection_AsciiString& aPluginPath)
00262 {
00263 Standard_Boolean thePluginPathIsOK = Standard_False;
00264 myPluginPath = aPluginPath;
00265 if ( !myPluginPath.IsEmpty() )
00266 {
00267 #if 0
00268 OSD_Directory theDirectory(OSD_Path(myPluginPath));
00269 thePluginPathIsOK = theDirectory.Exists();
00270 #else
00271 if ( _access(myPluginPath.ToCString(),0) != -1 )
00272 {
00273 thePluginPathIsOK = Standard_True;
00274 }
00275 #endif
00276 }
00277 return thePluginPathIsOK;
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287 TCollection_AsciiString exotkAF_Application::PluginPath()
00288 {
00289 return myPluginPath;
00290 }
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 Standard_Boolean exotkAF_Application::LoadPlugins()
00301 {
00302 Standard_Boolean theReturnValue = Standard_False;
00303 if ( !myPluginPath.IsEmpty() )
00304 {
00305 #ifdef _DEBUG
00306 TCollection_AsciiString theMask("*.pgid");
00307 #else
00308 TCollection_AsciiString theMask("*.pgi");
00309 #endif
00310 OSD_FileIterator theFileIterator(myPluginPath,theMask);
00311 for ( ; theFileIterator.More() ; theFileIterator.Next() )
00312 {
00313 OSD_File theCurrentFile = theFileIterator.Values();
00314 OSD_Path theCurrentFilePath;
00315 theCurrentFile.Path(theCurrentFilePath);
00316 OSD_Path theCompletePluginPath(myPluginPath);
00317 theCompletePluginPath.SetName(theCurrentFilePath.Name());
00318 theCompletePluginPath.SetExtension(theCurrentFilePath.Extension());
00319 TCollection_AsciiString theExtension = theCurrentFilePath.Extension();
00320 theExtension.LowerCase();
00321 TCollection_AsciiString theTmpMask = theMask;
00322 theTmpMask.LowerCase();
00323 theTmpMask.Remove(1,1);
00324 if ( theTmpMask == theExtension )
00325 {
00326 TCollection_AsciiString theCurrentFilePathString;
00327 theCompletePluginPath.SystemName(theCurrentFilePathString);
00328 Handle_exotkPlugin_Plugin thePlugin = exotkPlugin::RegisterPlugin(theCurrentFilePathString);
00329 DispatchPlugin(thePlugin);
00330 }
00331 }
00332 theReturnValue = Standard_True;
00333 }
00334 return theReturnValue;
00335 }
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346 void exotkAF_Application::DispatchPlugin(const Handle_exotkPlugin_Plugin& aPlugin)
00347 {
00348 if ( !aPlugin.IsNull() )
00349 {
00350 OSD_Function theFunction = aPlugin->Function("PluginID");
00351 if ( theFunction!=NULL)
00352 {
00353 PLUGINID_FCT thePluginIDFonction = (PLUGINID_FCT)theFunction;
00354 if ( thePluginIDFonction!=NULL)
00355 {
00356 TCollection_AsciiString thePluginID;
00357 (thePluginIDFonction)(thePluginID);
00358 if ( !thePluginID.IsEmpty() )
00359 {
00360 if ( thePluginID == TCollection_AsciiString("DX") )
00361 {
00362 if ( !exotkDX::RegisterPlugin(aPlugin) )
00363 {
00364 exotkTrace::Error("Cannot register the DX Plugin : %s",aPlugin->Filename().ToCString());
00365 }
00366 else
00367 {
00368 exotkTrace::Info("the DX Plugin %s is successfully registered",aPlugin->Filename().ToCString());
00369 }
00370 }
00371 }
00372 }
00373 }
00374 }
00375 }
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386 Standard_Boolean exotkAF_Application::SetActiveDocument(const Handle_exotkAF_Document &aDocument)
00387 {
00388 Standard_Boolean theSuccess = Standard_False;
00389 if ( !aDocument.IsNull() && !myDocuments.IsNull() && myDocuments->Contains(aDocument) )
00390 {
00391 myActiveDocument = aDocument;
00392 theSuccess = Standard_True;
00393 }
00394 return theSuccess;
00395 }
00396
00397
00398
00399
00400
00401
00402
00403
00404 Handle_exotkAF_Document exotkAF_Application::ActiveDocument()
00405 {
00406 return myActiveDocument;
00407 }