Salome HOME
Implementation of ACISPLUGIN as a GEOM plugin (added files)
[plugins/acisplugin.git] / src / ACISPlugin_Operations_i.cc
1 // Copyright (C) 2014  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 "ACISPlugin_Operations_i.hh"
22 #include <ACISPLUGIN_version.h>
23
24 // KERNEL includes
25 #include <utilities.h>
26
27 //=============================================================================
28 /*!
29  *   constructor:
30  */
31 //=============================================================================
32 ACISPlugin_Operations_i::ACISPlugin_Operations_i( PortableServer::POA_ptr thePOA,
33                                                             GEOM::GEOM_Gen_ptr theEngine,
34                                                             ::ACISPlugin_IOperations* theImpl )
35 :GEOM_IOperations_i( thePOA, theEngine, theImpl )
36 {
37   MESSAGE( "ACISPlugin_Operations_i::ACISPlugin_Operations_i" );
38 }
39
40 //=============================================================================
41 /*!
42  *  destructor
43  */
44 //=============================================================================
45 ACISPlugin_Operations_i::~ACISPlugin_Operations_i()
46 {
47   MESSAGE( "ACISPlugin_Operations_i::~ACISPlugin_Operations_i" );
48 }
49
50 //=============================================================================
51 /*!
52  *  ExportACIS
53  *  Export a shape to ACIS format
54  *  \param theOriginal The shape to export
55  *  \param theFileName The name of the exported file
56  */
57 //=============================================================================
58 void ACISPlugin_Operations_i::ExportACIS( GEOM::GEOM_Object_ptr theOriginal,
59                                                const char*           theFileName )
60 {
61   // duplicate the original shape
62   GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate( theOriginal );
63
64   //Set a not done flag
65   GetOperations()->SetNotDone();
66
67   //Get the reference shape
68   Handle(GEOM_Object) anOriginal = GetObjectImpl( theOriginal );
69   if (anOriginal.IsNull()) return;
70
71   //Export the shape to the file
72   char* aFileName = strdup( theFileName );
73
74   GetOperations()->ExportACIS( anOriginal, aFileName );
75   free( aFileName );
76 }
77
78 //=============================================================================
79 /*!
80  *  ImportACIS
81  *  Import a shape from ACIS format
82  *  \param theFileName The name of the file to import
83  *  \return List of GEOM_Objects, containing the created shape and propagation groups.
84  */
85 //=============================================================================
86 GEOM::ListOfGO* ACISPlugin_Operations_i::ImportACIS( const char* theFileName )
87 {
88   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
89
90   //Set a not done flag
91   GetOperations()->SetNotDone();
92
93   //Import the shape from the file
94   char* aFileName = strdup( theFileName );
95   TCollection_AsciiString fileName( aFileName );
96
97   //Import the shape from the file
98   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->ImportACIS( fileName );
99
100   free( aFileName );
101   if( !GetOperations()->IsDone() || aHSeq.IsNull() )
102     return aSeq._retn();
103
104   // Copy created objects.
105   Standard_Integer aLength = aHSeq->Length();
106   aSeq->length( aLength );
107   for( Standard_Integer i = 1; i <= aLength; i++ )
108     aSeq[i-1] = GetObject( Handle(GEOM_Object)::DownCast( aHSeq->Value(i) ) );
109
110   return aSeq._retn();
111 }
112
113 //=============================================================================
114 /*!
115  *  \brief Get version of the plugin.
116  *  \return the version of the plugin
117 */
118 //=============================================================================
119
120 int ACISPlugin_Operations_i::GetVersion()
121 {
122   return ACISPLUGIN_VERSION;
123 }
124 //=============================================================================
125 /*!
126  *  \brief Get version of the plugin.
127  *  \return the string representation of the plugin's version
128 */
129 //=============================================================================
130
131 char* ACISPlugin_Operations_i::GetVersionStr()
132 {
133   return (char*)ACISPLUGIN_VERSION_STR;
134 }