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

exotkDX.cxx

Go to the documentation of this file.
00001 
00002 //   exotkDX.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 
00029 #include <exotkDX.hxx>
00030 #ifndef  _exotkDX_Root_HeaderFile
00031 #include <exotkDX_Root.hxx>
00032 #endif
00033 #ifndef  _TColStd_SequenceOfTransient_HeaderFile
00034 #include <TColStd_SequenceOfTransient.hxx>
00035 #endif
00036 #ifndef  _TCollection_AsciiString_HeaderFile
00037 #include <TCollection_AsciiString.hxx>
00038 #endif
00039 #ifndef  _exotkPlugin_Plugin_HeaderFile
00040 #include <exotkPlugin_Plugin.hxx>
00041 #endif
00042 #ifndef  _TopoDS_Shape_HeaderFile
00043 #include <TopoDS_Shape.hxx>
00044 #endif
00045 #ifndef  _TopTools_HSequenceOfShape_HeaderFile
00046 #include <TopTools_HSequenceOfShape.hxx>
00047 #endif
00048 #ifndef  _TColStd_HSequenceOfTransient_HeaderFile
00049 #include <TColStd_HSequenceOfTransient.hxx>
00050 #endif
00051 #ifndef  _exotkDX_FormatDescriptor_HeaderFile
00052 #include <exotkDX_FormatDescriptor.hxx>
00053 #endif
00054 #ifndef  _exotkTrace_HeaderFile
00055 #include <exotkTrace.hxx>
00056 #endif
00057 
00063 namespace exotkDX_Datas
00064 {
00066         TColStd_SequenceOfTransient thePluginRoots;
00067 }
00068 
00072 typedef void(*PLUGINID_FCT)(TCollection_AsciiString& anID);
00076 typedef void(*CREATE_FCT)(Handle_exotkDX_Root& aRoot);
00077 
00078 Standard_Boolean exotkDX::RegisterPlugin(const Handle_exotkPlugin_Plugin& aPlugin)
00079 {
00080         Standard_Boolean theReturnValue = Standard_False;
00081         if (!aPlugin.IsNull())
00082         {
00083                 OSD_Function theFunction = aPlugin->Function("PluginID");
00084                 if (theFunction != NULL)
00085                 {
00086                         PLUGINID_FCT thePluginIDFonction = (PLUGINID_FCT)theFunction;
00087                         if (thePluginIDFonction != NULL)
00088                         {
00089                                 TCollection_AsciiString thePluginID;
00090                                 (thePluginIDFonction)(thePluginID);
00091                                 if (!thePluginID.IsEmpty())
00092                                 {
00093                                         if (thePluginID == TCollection_AsciiString("DX"))
00094                                         {
00095                                                 theFunction = aPlugin->Function("Create");
00096                                                 if (theFunction != NULL)
00097                                                 {
00098                                                         CREATE_FCT theCreateFunction = (CREATE_FCT)theFunction;
00099                                                         if (theCreateFunction != NULL)
00100                                                         {
00101                                                                 Handle_exotkDX_Root theRoot;
00102                                                                 (theCreateFunction)(theRoot);
00103                                                                 if (!theRoot.IsNull())
00104                                                                 {
00105                                                                         exotkDX_Datas::thePluginRoots.Append(theRoot);
00106                                                                         theReturnValue = Standard_True;
00107                                                                 }
00108                                                         }
00109                                                 }
00110                                         }
00111                                 }
00112                         }
00113                 }
00114         }
00115         return theReturnValue;
00116 }
00117 Handle_exotkDX_Root exotkDX::FindPluginRoot(const TCollection_AsciiString& aFilename)
00118 {
00119         Handle_exotkDX_Root thePluginRoot;
00120         if (!exotkDX_Datas::thePluginRoots.IsEmpty() && !aFilename.IsEmpty())
00121         {
00122                 for (int iter = 1; (iter <= exotkDX_Datas::thePluginRoots.Length()) && ( thePluginRoot.IsNull() ); iter++)
00123                 {
00124                         Handle_Standard_Transient theTransient = exotkDX_Datas::thePluginRoots.Value(iter);
00125                         if ( !theTransient.IsNull() )
00126                         {
00127                                 Handle_exotkDX_Root thePluginRootToTest = Handle_exotkDX_Root::DownCast(theTransient);
00128                                 if ( !thePluginRootToTest.IsNull() )
00129                                 {
00130                                         if ( thePluginRootToTest->Match(aFilename) )
00131                                         {
00132                                                 thePluginRoot = thePluginRootToTest;
00133                                         }
00134                                 }
00135                         }
00136                 }
00137         }
00138         return thePluginRoot;
00139 }
00140 Standard_Boolean exotkDX::LoadShape(const TCollection_AsciiString &aFilename, TopoDS_Shape& aReturnedShape)
00141 {
00142         Standard_Boolean theReadIsDone = Standard_False;
00143         Handle_exotkDX_Root thePluginRoot = FindPluginRoot(aFilename);
00144         if ( !thePluginRoot.IsNull() && thePluginRoot->AllowImport() )
00145         {
00146                 exotkTrace::Debug("plugin found for %s",aFilename.ToCString());
00147                 thePluginRoot->SetFilename(aFilename);
00148                 aReturnedShape = thePluginRoot->LoadShape();
00149                 theReadIsDone = ( !aReturnedShape.IsNull() );
00150                 if ( !theReadIsDone )
00151                 {
00152                         exotkTrace::Error("the plugin cannot read the shape");
00153                 }
00154         }
00155         else
00156         {
00157                 exotkTrace::Error("Cannot find a plugin for %s",aFilename.ToCString());
00158         }
00159         return theReadIsDone;
00160 }
00161 
00162 Standard_Boolean exotkDX::LoadShapes(const TCollection_AsciiString &aFilename, Handle_TopTools_HSequenceOfShape& aReturnedSequenceOfShapes)
00163 {
00164         Standard_Boolean theReadIsDone = Standard_False;
00165         Handle_exotkDX_Root thePluginRoot = FindPluginRoot(aFilename);
00166         if ( !thePluginRoot.IsNull()  && thePluginRoot->AllowImport() )
00167         {
00168                 exotkTrace::Debug("plugin found for %s",aFilename.ToCString());
00169                 thePluginRoot->SetFilename(aFilename);
00170                 aReturnedSequenceOfShapes = thePluginRoot->LoadShapes();
00171                 theReadIsDone = ( !aReturnedSequenceOfShapes.IsNull() && !aReturnedSequenceOfShapes->IsEmpty() );
00172                 if ( !theReadIsDone )
00173                 {
00174                         exotkTrace::Error("the plugin cannot read the shape");
00175                 }
00176         }
00177         else
00178         {
00179                 exotkTrace::Error("Cannot find a plugin for %s",aFilename.ToCString());
00180         }
00181         return theReadIsDone;
00182 }
00183 Standard_Boolean exotkDX::SaveShape(const TCollection_AsciiString& aFilename,const TopoDS_Shape& aShape)
00184 {
00185         Standard_Boolean theWriteIsDone = Standard_False;
00186         Handle_exotkDX_Root thePluginRoot = FindPluginRoot(aFilename);
00187         if ( !thePluginRoot.IsNull()  && thePluginRoot->AllowExport() )
00188         {
00189                 thePluginRoot->SetFilename(aFilename);
00190                 theWriteIsDone  = thePluginRoot->SaveShape(aShape);
00191         }
00192         return theWriteIsDone;
00193 }
00194 Standard_Boolean exotkDX::SaveShapes(const TCollection_AsciiString& aFilename,const Handle_TopTools_HSequenceOfShape& aSequenceOfShapes)
00195 {
00196         Standard_Boolean theWriteIsDone = Standard_False;
00197         Handle_exotkDX_Root thePluginRoot = FindPluginRoot(aFilename);
00198         if ( !thePluginRoot.IsNull()  && thePluginRoot->AllowExport() )
00199         {
00200                 thePluginRoot->SetFilename(aFilename);
00201                 theWriteIsDone  = thePluginRoot->SaveShapes(aSequenceOfShapes);
00202         }
00203         return theWriteIsDone;
00204 }
00205 
00206 Handle_TColStd_HSequenceOfTransient exotkDX::ImportFileDestriptors()
00207 {
00208         Handle_TColStd_HSequenceOfTransient theSequence;
00209         if (!exotkDX_Datas::thePluginRoots.IsEmpty() )
00210         {
00211                 for (int iter = 1; iter <= exotkDX_Datas::thePluginRoots.Length() ; iter++)
00212                 {
00213                         Handle_Standard_Transient theTransient = exotkDX_Datas::thePluginRoots.Value(iter);
00214                         Handle_exotkDX_Root thePluginRoot = Handle_exotkDX_Root::DownCast(theTransient);
00215                         if ( !thePluginRoot.IsNull() )
00216                         {
00217                                 if ( thePluginRoot->AllowImport() )
00218                                 {
00219                                         Handle_exotkDX_FormatDescriptor theDescriptor = new exotkDX_FormatDescriptor(thePluginRoot);
00220                                         if ( theDescriptor->IsValid() )
00221                                         {
00222                                                 if ( theSequence.IsNull() )
00223                                                 {
00224                                                         theSequence = new TColStd_HSequenceOfTransient();
00225                                                 }
00226                                                 theSequence->Append(theDescriptor);
00227                                         }
00228                                 }
00229                         }
00230                 }
00231         }
00232         return theSequence;
00233 }
00234 Handle_TColStd_HSequenceOfTransient exotkDX::ExportFileDestriptors()
00235 {
00236         Handle_TColStd_HSequenceOfTransient theSequence;
00237         if (!exotkDX_Datas::thePluginRoots.IsEmpty() )
00238         {
00239                 for (int iter = 1; iter <= exotkDX_Datas::thePluginRoots.Length() ; iter++)
00240                 {
00241                         Handle_Standard_Transient theTransient = exotkDX_Datas::thePluginRoots.Value(iter);
00242                         Handle_exotkDX_Root thePluginRoot = Handle_exotkDX_Root::DownCast(theTransient);
00243                         if ( !thePluginRoot.IsNull() )
00244                         {
00245                                 if ( thePluginRoot->AllowExport() )
00246                                 {
00247                                         Handle_exotkDX_FormatDescriptor theDescriptor = new exotkDX_FormatDescriptor(thePluginRoot);
00248                                         if ( theDescriptor->IsValid() )
00249                                         {
00250                                                 if ( theSequence.IsNull() )
00251                                                 {
00252                                                         theSequence = new TColStd_HSequenceOfTransient();
00253                                                 }
00254                                                 theSequence->Append(theDescriptor);
00255                                         }
00256                                 }
00257                         }
00258                 }
00259         }
00260         return theSequence;
00261 }

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