Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

exotkAF_Application.cxx

Go to the documentation of this file.
00001 
00002 //   exotkAF_Application.cxx
00004 //    Copyright (C) 2001  Stephane Routelous
00005 //
00006 //    This file is part of exoTK.
00007 //
00008 //    exoTK is free software; you can redistribute it and/or modify
00009 //    it under the terms of the GNU General Public License as published by
00010 //    the Free Software Foundation; either version 2 of the License, or
00011 //    (at your option) any later version.
00012 //
00013 //    exoTK is distributed in the hope that it will be useful,
00014 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 //    GNU General Public License for more details.
00017 //
00018 //    You should have received a copy of the GNU General Public License
00019 //    along with exoTK; if not, write to the Free Software
00020 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 // Foreach ancestors, we add a IMPLEMENT_STANDARD_SUPERTYPE and 
00071 // a IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY macro.
00072 // We must respect the order: from the direct ancestor class
00073 // to the base class.
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 // Function name        : exotkAF_Application::exotkAF_Application
00104 //==================================================================================
00105 // Written by       : Stephane Routelous - 2001-11-06 16:06:54
00106 // Description      : 
00107 // Return type          : 
00108 //==================================================================================
00109 exotkAF_Application::exotkAF_Application()
00110 {
00111         myDocuments = new exotkAF_HSetOfDocument();
00112 }
00113 
00114 
00115 //==================================================================================
00116 // Function name        : exotkAF_Application::~exotkAF_Application
00117 //==================================================================================
00118 // Written by       : Stephane Routelous - 2001-11-06 16:06:55
00119 // Description      : 
00120 // Return type          : 
00121 //==================================================================================
00122 exotkAF_Application::~exotkAF_Application()
00123 {
00124         myDocuments->Clear();
00125         exotkAF::SetApplication(Handle_exotkAF_Application());
00126 }
00127 
00128 //==================================================================================
00129 // Function name        : exotkAF_Application::SetOpenCASCADEEnvironmentVariables
00130 //==================================================================================
00131 // Written by       : Stephane Routelous - 2001-11-06 16:07:24
00132 // Description      : 
00133 // Return type          : Standard_Boolean 
00134 //==================================================================================
00135 // Argument         : const TCollection_AsciiString& aCSFGraphicShr
00136 // Argument         : const TCollection_AsciiString& aCSFUnitsDefinition
00137 // Argument         : const TCollection_AsciiString& aCSFUnitsLexicon
00138 // Argument         : const TCollection_AsciiString& aCSFMDTVFontDirectory
00139 // Argument         : const TCollection_AsciiString& aCSFMDTVTexturesDirectory
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 // Function name        : exotkAF_Application::AddDocument
00168 //==================================================================================
00169 // Written by       : Stephane Routelous - 2001-11-06 16:07:31
00170 // Description      : 
00171 // Return type          : Standard_Boolean 
00172 //==================================================================================
00173 // Argument         : const Handle_exotkAF_Document &aDocument
00174 Standard_Boolean exotkAF_Application::AddDocument(const Handle_exotkAF_Document &aDocument)
00175 {
00176         return myDocuments->Add(aDocument);
00177 }
00178 
00179 //==================================================================================
00180 // Function name        : exotkAF_Application::RemoveDocument
00181 //==================================================================================
00182 // Written by       : Stephane Routelous - 2001-11-06 16:07:33
00183 // Description      : 
00184 // Return type          : Standard_Boolean 
00185 //==================================================================================
00186 // Argument         : const Handle_exotkAF_Document &aDocument
00187 Standard_Boolean exotkAF_Application::RemoveDocument(const Handle_exotkAF_Document &aDocument)
00188 {
00189         return myDocuments->Remove(aDocument);
00190 }
00191 
00192 //==================================================================================
00193 // Function name        : exotkAF_Application::InitDocIterator
00194 //==================================================================================
00195 // Written by       : Stephane Routelous - 2001-11-06 16:07:34
00196 // Description      : 
00197 // Return type          : void 
00198 //==================================================================================
00199 void exotkAF_Application::InitDocIterator()
00200 {
00201         exotkAF_Application_Datas::theDocIterator.Initialize(myDocuments->Set());
00202 }
00203 
00204 //==================================================================================
00205 // Function name        : exotkAF_Application::MoreDocIterator
00206 //==================================================================================
00207 // Written by       : Stephane Routelous - 2001-11-06 16:07:36
00208 // Description      : 
00209 // Return type          : Standard_Boolean 
00210 //==================================================================================
00211 Standard_Boolean exotkAF_Application::MoreDocIterator()
00212 {
00213         return exotkAF_Application_Datas::theDocIterator.More();
00214 }
00215 
00216 //==================================================================================
00217 // Function name        : exotkAF_Application::NextDocIterator
00218 //==================================================================================
00219 // Written by       : Stephane Routelous - 2001-11-06 16:07:38
00220 // Description      : 
00221 // Return type          : void 
00222 //==================================================================================
00223 void exotkAF_Application::NextDocIterator()
00224 {
00225         exotkAF_Application_Datas::theDocIterator.Next();
00226 }
00227 
00228 //==================================================================================
00229 // Function name        : exotkAF_Application::CurrentDocIterator
00230 //==================================================================================
00231 // Written by       : Stephane Routelous - 2001-11-06 16:07:40
00232 // Description      : 
00233 // Return type          : Handle_exotkAF_Document 
00234 //==================================================================================
00235 Handle_exotkAF_Document exotkAF_Application::CurrentDocIterator()
00236 {
00237         return exotkAF_Application_Datas::theDocIterator.Value();
00238 }
00239 
00240 //==================================================================================
00241 // Function name        : exotkAF_Application::NbDocuments
00242 //==================================================================================
00243 // Written by       : Stephane Routelous - 2001-11-06 16:07:41
00244 // Description      : 
00245 // Return type          : Standard_Integer 
00246 //==================================================================================
00247 Standard_Integer exotkAF_Application::NbDocuments()
00248 {
00249         return myDocuments->Extent();
00250 }
00251 
00252 
00253 //==================================================================================
00254 // Function name        : exotkAF_Application::SetPluginPath
00255 //==================================================================================
00256 // Written by       : Stephane Routelous - 2001-11-22 14:07:52
00257 // Description      : 
00258 // Return type          : void 
00259 //==================================================================================
00260 // Argument         : const TCollection_AsciiString& aPluginPath
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 // Function name        : exotkAF_Application::PluginPath
00282 //==================================================================================
00283 // Written by       : Stephane Routelous - 2001-11-22 14:07:54
00284 // Description      : 
00285 // Return type          : TCollection_AsciiString 
00286 //==================================================================================
00287 TCollection_AsciiString exotkAF_Application::PluginPath()
00288 {
00289         return myPluginPath;
00290 }
00291 
00292 
00293 //==================================================================================
00294 // Function name        : exotkAF_Application::LoadPlugins
00295 //==================================================================================
00296 // Written by       : Stephane Routelous - 2001-11-22 14:11:11
00297 // Description      : 
00298 // Return type          : Standard_Boolean 
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 // Function name        : exotkAF_Application::DispatchPlugin
00340 //==================================================================================
00341 // Written by       : Stephane Routelous - 2002-01-02 00:15:58
00342 // Description      : 
00343 // Return type          : void 
00344 //==================================================================================
00345 // Argument         : const Handle_exotkPlugin_Plugin& aPlugin
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 // Function name        : exotkAF_Application::SetActiveDocument
00380 //==================================================================================
00381 // Written by       : Stephane Routelous - 2001-11-27 12:31:30
00382 // Description      : 
00383 // Return type          : Standard_Boolean 
00384 //==================================================================================
00385 // Argument         : const Handle_exotkAF_Document &aDocument
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 // Function name        : exotkAF_Application::ActiveDocument
00399 //==================================================================================
00400 // Written by       : Stephane Routelous - 2001-11-27 12:31:31
00401 // Description      : 
00402 // Return type          : Handle_exotkAF_Document 
00403 //==================================================================================
00404 Handle_exotkAF_Document exotkAF_Application::ActiveDocument()
00405 {
00406         return myActiveDocument;
00407 }

Generated on Wed Jan 23 12:16:38 2002 for exotk by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001