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