Salome HOME
Copyright update 2022
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ImportDriver.cxx
1 // Copyright (C) 2007-2022  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_ImportDriver.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 //function : GetID
38 //purpose  :
39 //=======================================================================
40 const Standard_GUID& GEOMImpl_ImportDriver::GetID()
41 {
42   static Standard_GUID aImportDriver("FF1BBB60-5D14-4df2-980B-3A668264EA16");
43   return aImportDriver;
44 }
45
46 //=======================================================================
47 //function : GEOMImpl_ImportDriver
48 //purpose  :
49 //=======================================================================
50 GEOMImpl_ImportDriver::GEOMImpl_ImportDriver()
51 {
52 }
53
54 //=======================================================================
55 //function : Execute
56 //purpose  :
57 //=======================================================================
58 Standard_Integer GEOMImpl_ImportDriver::Execute(Handle(TFunction_Logbook)& log) const
59 {
60   if (Label().IsNull()) return 0;
61   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
62
63   GEOMImpl_IImportExport aCI (aFunction);
64
65   // retrieve the file and plugin library names
66   TCollection_AsciiString aFileName   = aCI.GetFileName();
67   TCollection_AsciiString aFormatName = aCI.GetFormatName();
68   if (aFileName.IsEmpty() || aFormatName.IsEmpty() )
69     return 0;
70
71   Handle(TColStd_HSequenceOfTransient) aSeq =
72     GEOMImpl_IECallBack::GetCallBack( aFormatName )->Import( aFormatName, aFileName );
73   if( aSeq.IsNull() )
74     return 0;
75
76   Handle(GEOM_Object) anImported = Handle(GEOM_Object)::DownCast( aSeq->Value(1) );
77   TopoDS_Shape aShape = anImported->GetValue();
78   aFunction->SetValue( aShape );
79   log->SetTouched(Label());
80
81   return 1;
82 }
83
84 bool GEOMImpl_ImportDriver::
85 GetCreationInformation(std::string&             theOperationName,
86                        std::vector<GEOM_Param>& theParams)
87 {
88   if (Label().IsNull()) return 0;
89   Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
90
91   GEOMImpl_IImportExport aCI( function );
92   Standard_Integer aType = function->GetType();
93
94   theOperationName = "IMPORT";
95
96   switch ( aType ) {
97   case IMPORT_SHAPE:
98     AddParam( theParams, "File name", aCI.GetFileName() );
99     AddParam( theParams, "Format", aCI.GetFormatName() );
100     AddParam( theParams, "Plugin name", aCI.GetPluginName() );
101     break;
102   default:
103     return false;
104   }
105   
106   return true;
107 }
108
109 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ImportDriver,GEOM_BaseDriver)