]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_IInsertOperations_i.cc
Salome HOME
0020230: Memory performance improvement.
[modules/geom.git] / src / GEOM_I / GEOM_IInsertOperations_i.cc
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 #ifdef WNT
23 #pragma warning( disable:4786 )
24 #endif
25
26 #include <Standard_Stream.hxx>
27
28 #include "GEOM_IInsertOperations_i.hh"
29
30 #include "utilities.h"
31 #include "OpUtil.hxx"
32 #include "Utils_ExceptHandlers.hxx"
33
34 #include "GEOM_Engine.hxx"
35 #include "GEOM_Object.hxx"
36
37 #include <TColStd_HSequenceOfAsciiString.hxx>
38
39 //=============================================================================
40 /*!
41  *   constructor:
42  */
43 //=============================================================================
44 GEOM_IInsertOperations_i::GEOM_IInsertOperations_i (PortableServer::POA_ptr thePOA,
45                                                     GEOM::GEOM_Gen_ptr theEngine,
46                                                     ::GEOMImpl_IInsertOperations* theImpl)
47      :GEOM_IOperations_i(thePOA, theEngine, theImpl)
48 {
49   MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
50 }
51
52 //=============================================================================
53 /*!
54  *  destructor
55  */
56 //=============================================================================
57 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
58 {
59   MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
60 }
61
62
63 //=============================================================================
64 /*!
65  *  MakeCopy
66  */
67 //=============================================================================
68 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
69 {
70   GEOM::GEOM_Object_var aGEOMObject;
71
72   //Set a not done flag
73   GetOperations()->SetNotDone();
74
75   //Get the reference shape
76   Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
77   if (anOriginal.IsNull()) return aGEOMObject._retn();
78
79   //Create the copy
80   Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
81
82   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
83
84   return GetObject(anObject);
85 }
86
87 //=============================================================================
88 /*!
89  *  Export
90  */
91 //=============================================================================
92 void GEOM_IInsertOperations_i::Export
93                    (GEOM::GEOM_Object_ptr theOriginal,
94                     const char*           theFileName,
95                     const char*           theFormatName)
96 {
97   GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
98
99   //Set a not done flag
100   GetOperations()->SetNotDone();
101
102   //Get the reference shape
103   Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
104   if (anOriginal.IsNull()) return;
105
106   //Export the shape to the file
107   char* aFileName   = strdup(theFileName);
108   char* aFormatName = strdup(theFormatName);
109   GetOperations()->Export(anOriginal, aFileName, aFormatName);
110   free(aFileName);
111   free(aFormatName);
112 }
113
114 //=============================================================================
115 /*!
116  *  Import
117  */
118 //=============================================================================
119 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::Import
120                    (const char* theFileName,
121                     const char* theFormatName)
122 {
123   GEOM::GEOM_Object_var aGEOMObject;
124
125   //Set a not done flag
126   GetOperations()->SetNotDone();
127
128   //Import the shape from the file
129   char* aFileName   = strdup(theFileName);
130   char* aFormatName = strdup(theFormatName);
131   Handle(GEOM_Object) anObject = GetOperations()->Import(aFileName, aFormatName);
132   free(aFileName);
133   free(aFormatName);
134
135   if (!GetOperations()->IsDone() || anObject.IsNull())
136     return aGEOMObject._retn();
137
138   return GetObject(anObject);
139 }
140
141 //=============================================================================
142 /*!
143  *  ImportTranslators
144  */
145 //=============================================================================
146 void GEOM_IInsertOperations_i::ImportTranslators
147   (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
148 {
149   // allocate the CORBA arrays
150   GEOM::string_array_var aFormatsArray  = new GEOM::string_array();
151   GEOM::string_array_var aPatternsArray = new GEOM::string_array();
152
153   // Get sequences of available formats
154   Handle(TColStd_HSequenceOfAsciiString) aFormats  = new TColStd_HSequenceOfAsciiString;
155   Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
156   if (GetOperations()->ImportTranslators(aFormats, aPatterns)) {
157     const int formSize = aFormats->Length();
158     if (formSize == aPatterns->Length()) {
159       aFormatsArray->length(formSize);
160       aPatternsArray->length(formSize);
161
162       // fill the local CORBA arrays with values from sequences
163       CORBA::Long i = 1;
164       for (; i <= formSize; i++) {
165         aFormatsArray[i-1]  = CORBA::string_dup(aFormats->Value(i).ToCString());
166         aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
167       }
168     }
169   }
170
171   // initialize out-parameters with local arrays
172   theFormats  = aFormatsArray._retn();
173   thePatterns = aPatternsArray._retn();
174 }
175
176 //=============================================================================
177 /*!
178  *  ExportTranslators
179  */
180 //=============================================================================
181 void GEOM_IInsertOperations_i::ExportTranslators
182   (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
183 {
184   // allocate the CORBA arrays
185   GEOM::string_array_var aFormatsArray  = new GEOM::string_array();
186   GEOM::string_array_var aPatternsArray = new GEOM::string_array();
187
188   // Get sequences of available formats
189   Handle(TColStd_HSequenceOfAsciiString) aFormats  = new TColStd_HSequenceOfAsciiString;
190   Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
191   if (GetOperations()->ExportTranslators(aFormats, aPatterns)) {
192     const int formSize = aFormats->Length();
193     if (formSize == aPatterns->Length()) {
194       aFormatsArray->length(formSize);
195       aPatternsArray->length(formSize);
196
197       // fill the local CORBA arrays with values from sequences
198       CORBA::Long i = 1;
199       for (; i <= formSize; i++) {
200         aFormatsArray[i-1]  = CORBA::string_dup(aFormats->Value(i).ToCString());
201         aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
202       }
203     }
204   }
205
206   // initialize out-parameters with local arrays
207   theFormats  = aFormatsArray._retn();
208   thePatterns = aPatternsArray._retn();
209 }