Salome HOME
e760c49d1efedaa2edf60220c8bd674665887808
[modules/geom.git] / src / IGESPlugin / IGESPlugin_IOperations_i.cc
1 // Copyright (C) 2014-2023  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 "IGESPlugin_IOperations_i.hh"
22 #include "IGESPlugin_IOperations.hxx"
23
24 // KERNEL includes
25 #include <utilities.h>
26
27 //=============================================================================
28 /*!
29  *   constructor:
30  */
31 //=============================================================================
32 IGESPlugin_IOperations_i::IGESPlugin_IOperations_i( PortableServer::POA_ptr thePOA,
33                                                     GEOM::GEOM_Gen_ptr theEngine,
34                                                     IGESPlugin_IOperations* theImpl )
35 :GEOM_IOperations_i( thePOA, theEngine, theImpl )
36 {
37   MESSAGE( "IGESPlugin_IOperations_i::IGESPlugin_IOperations_i" );
38 }
39
40 //=============================================================================
41 /*!
42  *  destructor
43  */
44 //=============================================================================
45 IGESPlugin_IOperations_i::~IGESPlugin_IOperations_i()
46 {
47   MESSAGE( "IGESPlugin_IOperations_i::~IGESPlugin_IOperations_i" );
48 }
49
50 //=============================================================================
51 /*!
52  *  ExportIGES
53  *  Export a shape to IGES format
54  *  \param theOriginal The shape to export
55  *  \param theFileName The name of the exported file
56  *  \param theVersion  The version of IGES format which defines, whether to write
57  *                     only faces (5.1 IGES format) or shells and solids also (5.3 IGES format).
58  */
59 //=============================================================================
60 void IGESPlugin_IOperations_i::ExportIGES( GEOM::GEOM_Object_ptr theOriginal,
61                                            const char*           theFileName,
62                                            const char*           theVersion )
63 {
64   // duplicate the original shape
65   GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate( theOriginal );
66
67   //Set a not done flag
68   GetOperations()->SetNotDone();
69
70   //Get the reference shape
71   Handle(GEOM_Object) anOriginal = GetObjectImpl( theOriginal );
72   if (anOriginal.IsNull()) return;
73
74   GetOperations()->ExportIGES( anOriginal, theFileName, theVersion );
75 }
76
77 //=============================================================================
78 /*!
79  *  ImportIGES
80  *  Import a shape from IGES format
81  *  \param theFileName The name of the file to import
82  *  \param theIsIgnoreUnits If True, file length units will be ignored (set to 'meter')
83  *                          and result model will be scaled, if its units are not meters.
84  *                          If False (default), file length units will be taken into account.
85  *  \return List of GEOM_Objects, containing the created shape and propagation groups.
86  */
87 //=============================================================================
88 GEOM::ListOfGO* IGESPlugin_IOperations_i::ImportIGES( const char* theFileName,
89                                                       const bool  theIsIgnoreUnits = false )
90 {
91   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
92
93   //Set a not done flag
94   GetOperations()->SetNotDone();
95
96   //Import the shape from the file
97   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->ImportIGES( theFileName, theIsIgnoreUnits );
98
99   if( !GetOperations()->IsDone() || aHSeq.IsNull() )
100     return aSeq._retn();
101
102   // Copy created objects.
103   Standard_Integer aLength = aHSeq->Length();
104   aSeq->length( aLength );
105   for( Standard_Integer i = 1; i <= aLength; i++ )
106     aSeq[i-1] = GetObject( Handle(GEOM_Object)::DownCast( aHSeq->Value(i) ) );
107
108   return aSeq._retn();
109 }
110
111 //=============================================================================
112 /*!
113  *  ReadValue
114  */
115 //=============================================================================
116 char* IGESPlugin_IOperations_i::ReadValue( const char* theFileName,
117                                            const char* theParameterName )
118 {
119   //Set a not done flag
120   GetOperations()->SetNotDone();
121
122   TCollection_AsciiString aParam = GetOperations()->ReadValue( theFileName, theParameterName );
123
124   return CORBA::string_dup( aParam.ToCString() );
125 }
126
127 IGESPlugin_IOperations* IGESPlugin_IOperations_i::GetOperations()
128 {
129   return (IGESPlugin_IOperations*)GetImpl();
130 }