Salome HOME
Merge remote branch 'origin/V7_dev'
[modules/geom.git] / src / BREPPlugin / BREPPlugin_ImportDriver.cxx
1 // Copyright (C) 2014-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // internal includes
21 #include "BREPPlugin_ImportDriver.hxx"
22 #include "BREPPlugin_IImport.hxx"
23
24 // KERNEL includes
25 #include <utilities.h>
26 #include <Basics_Utils.hxx>
27
28 // GEOM includes
29 #include "GEOM_Function.hxx"
30 #include "GEOMImpl_Types.hxx"
31
32 // OOCT includes
33 #include <BRepTools.hxx>
34 #include <BRep_Builder.hxx>
35
36 //=======================================================================
37 //function : GetID
38 //purpose  :
39 //=======================================================================
40 const Standard_GUID& BREPPlugin_ImportDriver::GetID()
41 {
42   static Standard_GUID aGUID("7e1b28ec-8513-4217-b09c-7652fbe8149e");
43   return aGUID;
44 }
45
46 //=======================================================================
47 //function : BREPPlugin_ImportDriver
48 //purpose  :
49 //=======================================================================
50 BREPPlugin_ImportDriver::BREPPlugin_ImportDriver()
51 {
52 }
53
54 //=======================================================================
55 //function : Execute
56 //purpose  :
57 //=======================================================================
58 Standard_Integer BREPPlugin_ImportDriver::Execute( TFunction_Logbook& log ) const
59 {
60   if( Label().IsNull() ) return 0;
61   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
62
63   BREPPlugin_IImport aData( aFunction );
64
65   TCollection_AsciiString aFileName = aData.GetFileName().ToCString();
66
67   MESSAGE("Import BREP from file " << aFileName);
68
69   // Set "C" numeric locale to save numbers correctly
70   Kernel_Utils::Localizer loc;
71
72   TopoDS_Shape aShape;
73   BRep_Builder B;
74   BRepTools::Read(aShape, aFileName.ToCString(), B);
75   if( aShape.IsNull() ) return 0;
76
77   aFunction->SetValue( aShape );
78
79   log.SetTouched( Label() );
80
81   return 1;
82 }
83
84 //=======================================================================
85 //function : MustExecute
86 //purpose  :
87 //=======================================================================
88 Standard_Boolean BREPPlugin_ImportDriver::MustExecute( const TFunction_Logbook& ) const
89 {
90   return Standard_True;
91 }
92
93 //================================================================================
94 /*!
95  * \brief Returns a name of creation operation and names and values of creation parameters
96  */
97 //================================================================================
98
99 bool BREPPlugin_ImportDriver::
100 GetCreationInformation( std::string&             theOperationName,
101                         std::vector<GEOM_Param>& theParams )
102 {
103   if( Label().IsNull() ) return 0;
104   Handle(GEOM_Function) function = GEOM_Function::GetFunction( Label() );
105
106   BREPPlugin_IImport aCI( function );
107   Standard_Integer aType = function->GetType();
108
109   theOperationName = "ImportBREP";
110
111   switch ( aType ) {
112   case IMPORT_SHAPE:
113     AddParam( theParams, "File name", aCI.GetFileName() );
114     break;
115   default:
116     return false;
117   }
118   return true;
119 }
120
121 IMPLEMENT_STANDARD_HANDLE( BREPPlugin_ImportDriver, GEOM_BaseDriver );
122 IMPLEMENT_STANDARD_RTTIEXT( BREPPlugin_ImportDriver, GEOM_BaseDriver );