Salome HOME
updated copyright message
[modules/geom.git] / src / STEPPlugin / STEPPlugin_IOperations_i.cc
1 // Copyright (C) 2014-2023  CEA, EDF, 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 "STEPPlugin_IOperations_i.hh"
22 #include "STEPPlugin_IOperations.hxx"
23
24 // KERNEL includes
25 #include <utilities.h>
26
27 //=============================================================================
28 /*!
29  *   constructor:
30  */
31 //=============================================================================
32 STEPPlugin_IOperations_i::STEPPlugin_IOperations_i( PortableServer::POA_ptr thePOA,
33                                                     GEOM::GEOM_Gen_ptr theEngine,
34                                                     STEPPlugin_IOperations* theImpl )
35 :GEOM_IOperations_i( thePOA, theEngine, theImpl )
36 {
37   MESSAGE( "STEPPlugin_IOperations_i::STEPPlugin_IOperations_i" );
38 }
39
40 //=============================================================================
41 /*!
42  *  destructor
43  */
44 //=============================================================================
45 STEPPlugin_IOperations_i::~STEPPlugin_IOperations_i()
46 {
47   MESSAGE( "STEPPlugin_IOperations_i::~STEPPlugin_IOperations_i" );
48 }
49
50 //=============================================================================
51 /*!
52  *  ExportSTEP
53  *  Export a shape to STEP format
54  *  \param theOriginal The shape to export
55  *  \param theFileName The name of the exported file
56  *  \param theUnit the length unit.
57  */
58 //=============================================================================
59 void STEPPlugin_IOperations_i::ExportSTEP(GEOM::GEOM_Object_ptr theOriginal,
60                                           const char*           theFileName,
61                                           GEOM::length_unit     theUnit)
62 {
63   // duplicate the original shape
64   GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate( theOriginal );
65
66   //Set a not done flag
67   GetOperations()->SetNotDone();
68
69   //Get the reference shape
70   Handle(GEOM_Object) anOriginal = GetObjectImpl( theOriginal );
71   if (anOriginal.IsNull()) return;
72
73   STEPPlugin_IOperations::LengthUnit aUnit;
74
75   switch (theUnit) {
76   case GEOM::LU_INCH:
77     aUnit = STEPPlugin_IOperations::LengthUnit_Inch;
78     break;
79   case GEOM::LU_MILLIMETER:
80     aUnit = STEPPlugin_IOperations::LengthUnit_Millimeter;
81     break;
82   case GEOM::LU_FOOT:
83     aUnit = STEPPlugin_IOperations::LengthUnit_Foot;
84     break;
85   case GEOM::LU_MILE:
86     aUnit = STEPPlugin_IOperations::LengthUnit_Mile;
87     break;
88   case GEOM::LU_METER:
89     aUnit = STEPPlugin_IOperations::LengthUnit_Meter;
90     break;
91   case GEOM::LU_KILOMETER:
92     aUnit = STEPPlugin_IOperations::LengthUnit_Kilometer;
93     break;
94   case GEOM::LU_MILLIINCH:
95     aUnit = STEPPlugin_IOperations::LengthUnit_Milliinch;
96     break;
97   case GEOM::LU_MICROMETER:
98     aUnit = STEPPlugin_IOperations::LengthUnit_Micrometer;
99     break;
100   case GEOM::LU_CENTIMETER:
101     aUnit = STEPPlugin_IOperations::LengthUnit_Centimeter;
102     break;
103   case GEOM::LU_MICROINCH:
104     aUnit = STEPPlugin_IOperations::LengthUnit_Microinch;
105     break;
106   default:
107     return;
108   }
109
110   //Export the shape to the file
111   GetOperations()->ExportSTEP( anOriginal, theFileName, aUnit );
112 }
113
114 //=============================================================================
115 /*!
116  *  ImportSTEP
117  *  Import a shape from STEP format
118  *  \param theFileName The name of the file to import
119  *  \param theIsIgnoreUnits If True, file length units will be ignored (set to 'meter')
120  *                          and result model will be scaled, if its units are not meters.
121  *                          If False (default), file length units will be taken into account.
122  *  \param IsCreateAssemblies If True, for each assembly compound is created
123  *                          in the result. If False Compounds that contain a
124  *                          single shape are eliminated from the result.
125  *  \return List of GEOM_Objects, containing the created shape and propagation groups.
126  */
127 //=============================================================================
128 GEOM::ListOfGO* STEPPlugin_IOperations_i::ImportSTEP
129                           (const char *theFileName,
130                            const bool  theIsIgnoreUnits,
131                            const bool  IsCreateAssemblies)
132 {
133   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
134
135   //Set a not done flag
136   GetOperations()->SetNotDone();
137
138   //Import the shape from the file
139   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->ImportSTEP
140     (theFileName, theIsIgnoreUnits, IsCreateAssemblies);
141
142   if( !GetOperations()->IsDone() || aHSeq.IsNull() )
143     return aSeq._retn();
144
145   // Copy created objects.
146   Standard_Integer aLength = aHSeq->Length();
147   aSeq->length( aLength );
148   for( Standard_Integer i = 1; i <= aLength; i++ )
149     aSeq[i-1] = GetObject( Handle(GEOM_Object)::DownCast( aHSeq->Value(i) ) );
150
151   return aSeq._retn();
152 }
153
154 //=============================================================================
155 /*!
156  *  ReadValue
157  */
158 //=============================================================================
159 char* STEPPlugin_IOperations_i::ReadValue( const char* theFileName,
160                                            const char* theParameterName )
161 {
162   //Set a not done flag
163   GetOperations()->SetNotDone();
164
165   TCollection_AsciiString aParam = GetOperations()->ReadValue( theFileName, theParameterName );
166
167   return CORBA::string_dup( aParam.ToCString() );
168 }
169
170 STEPPlugin_IOperations* STEPPlugin_IOperations_i::GetOperations()
171 {
172   return (STEPPlugin_IOperations*)GetImpl();
173 }