Salome HOME
49f4dca2159a3126401bb8966f8de75d21b9cce6
[modules/geom.git] / src / STLPlugin / STLPlugin_IOperations_i.cc
1 // Copyright (C) 2014-2021  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 "STLPlugin_IOperations_i.hh"
22 #include "STLPlugin_IOperations.hxx"
23
24 // KERNEL includes
25 #include <utilities.h>
26
27 //=============================================================================
28 /*!
29  *   constructor:
30  */
31 //=============================================================================
32 STLPlugin_IOperations_i::STLPlugin_IOperations_i( PortableServer::POA_ptr thePOA,
33                                                   GEOM::GEOM_Gen_ptr theEngine,
34                                                   STLPlugin_IOperations* theImpl )
35 :GEOM_IOperations_i( thePOA, theEngine, theImpl )
36 {
37   MESSAGE( "STLPlugin_IOperations_i::STLPlugin_IOperations_i" );
38 }
39
40 //=============================================================================
41 /*!
42  *  destructor
43  */
44 //=============================================================================
45 STLPlugin_IOperations_i::~STLPlugin_IOperations_i()
46 {
47   MESSAGE( "STLPlugin_IOperations_i::~STLPlugin_IOperations_i" );
48 }
49
50 //=============================================================================
51 /*!
52  *  ExportSTL
53  *  Export a shape to STL format
54  *  \param theOriginal The shape to export
55  *  \param theIsASCII The format of the exported file (ASCII or Binary)
56  *  \param theFileName The name of the exported file
57  *  \param theDeflection The deflection of the exported shape
58  */
59 //=============================================================================
60 void STLPlugin_IOperations_i::ExportSTL( GEOM::GEOM_Object_ptr theOriginal,
61                                          const char*           theFileName,
62                                          const bool            theIsASCII,
63                                          const double          theDeflection,
64                                          const bool            theIsRelative )
65 {
66   // duplicate the original shape
67   GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate( theOriginal );
68
69   //Set a not done flag
70   GetOperations()->SetNotDone();
71
72   //Get the reference shape
73   Handle(GEOM_Object) anOriginal = GetObjectImpl( theOriginal );
74   if (anOriginal.IsNull()) return;
75
76   GetOperations()->ExportSTL( anOriginal, theFileName, theIsASCII, theDeflection, theIsRelative );
77 }
78
79 //=============================================================================
80 /*!
81  *  ImportSTL
82  *  Import a shape from STL format
83  *  \param theFileName The name of the file to import
84  *  \return List of GEOM_Objects, containing the created shape and propagation groups.
85  */
86 //=============================================================================
87 GEOM::ListOfGO* STLPlugin_IOperations_i::ImportSTL( const char* theFileName )
88 {
89   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
90
91   //Set a not done flag
92   GetOperations()->SetNotDone();
93
94   //Import the shape from the file
95   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->ImportSTL( theFileName );
96
97   if( !GetOperations()->IsDone() || aHSeq.IsNull() )
98     return aSeq._retn();
99
100   // Copy created objects.
101   Standard_Integer aLength = aHSeq->Length();
102   aSeq->length( aLength );
103   for( Standard_Integer i = 1; i <= aLength; i++ )
104     aSeq[i-1] = GetObject( Handle(GEOM_Object)::DownCast( aHSeq->Value(i) ) );
105
106   return aSeq._retn();
107 }
108
109 STLPlugin_IOperations* STLPlugin_IOperations_i::GetOperations()
110 {
111   return (STLPlugin_IOperations*)GetImpl();
112 }