Salome HOME
b432ab805b5bfcc9f6d3f440748c62b9dedede84
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ExportDriver.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // internal includes
24 #include "GEOMImpl_ExportDriver.hxx"
25 #include "GEOMImpl_IImportExport.hxx"
26 #include "GEOMImpl_IECallBack.hxx"
27 #include "GEOMImpl_Types.hxx"
28
29 // GEOM includes
30 #include <GEOM_Function.hxx>
31
32 // OCC includes
33 #include <Standard_Stream.hxx>
34 #include <TopoDS_Shape.hxx>
35
36
37 //=======================================================================
38 //function : GetID
39 //purpose  :
40 //======================================================================= 
41 const Standard_GUID& GEOMImpl_ExportDriver::GetID()
42 {
43   static Standard_GUID aExportDriver("FF1BBB58-5D14-4df2-980B-3A668264EA16");
44   return aExportDriver; 
45 }
46
47
48 //=======================================================================
49 //function : GEOMImpl_ExportDriver
50 //purpose  : 
51 //=======================================================================
52 GEOMImpl_ExportDriver::GEOMImpl_ExportDriver() 
53 {
54 }
55
56 //=======================================================================
57 //function : Execute
58 //purpose  :
59 //======================================================================= 
60 Standard_Integer GEOMImpl_ExportDriver::Execute(Handle(TFunction_Logbook)& log) const
61 {
62   if (Label().IsNull()) return 0;    
63   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
64
65   GEOMImpl_IImportExport aCI (aFunction);
66
67   // retrieve the being exported shape
68   TopoDS_Shape aShape;
69   Handle(GEOM_Function) aRefFunction = aCI.GetOriginal();
70   if (aRefFunction.IsNull()) return 0;
71   aShape = aRefFunction->GetValue();
72   if (aShape.IsNull()) return 0;
73   // !!! set the result of function to be used by next operations
74   aFunction->SetValue(aShape);
75
76   TDF_Label aLabel = aRefFunction->GetOwnerEntry();
77   if (aLabel.IsRoot()) return 0;
78   Handle(GEOM_Object) obj = GEOM_Object::GetObject( aLabel );
79   if ( obj.IsNull() ) return 0;
80
81   // retrieve the file and format names
82   TCollection_AsciiString aFileName   = aCI.GetFileName();
83   TCollection_AsciiString aFormatName = aCI.GetFormatName();
84   TCollection_AsciiString aLibName    = aCI.GetPluginName();
85   if (aFileName.IsEmpty() || aFormatName.IsEmpty() || aLibName.IsEmpty())
86     return 0;
87
88   if( !GEOMImpl_IECallBack::GetCallBack( aFormatName )->Export( obj, aFileName, aFormatName ) )
89     return 0;
90
91   log->SetTouched(Label());
92
93   return 1;
94 }
95
96 //================================================================================
97 /*!
98  * \brief Returns a name of creation operation and names and values of creation parameters
99  */
100 //================================================================================
101
102 bool GEOMImpl_ExportDriver::
103 GetCreationInformation(std::string& /*theOperationName*/,
104                        std::vector<GEOM_Param>& /*theParams*/)
105 {
106   return false;
107 }
108
109 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ExportDriver,GEOM_BaseDriver)