1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #pragma warning( disable:4786 )
26 #include <Standard_Stream.hxx>
28 #include "GEOM_IInsertOperations_i.hh"
30 #include "utilities.h"
32 #include "Utils_ExceptHandlers.hxx"
34 #include "GEOM_Engine.hxx"
35 #include "GEOM_Object.hxx"
37 #include <TColStd_HSequenceOfAsciiString.hxx>
39 //=============================================================================
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)
49 MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
52 //=============================================================================
56 //=============================================================================
57 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
59 MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
63 //=============================================================================
67 //=============================================================================
68 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
70 GEOM::GEOM_Object_var aGEOMObject;
73 GetOperations()->SetNotDone();
75 //Get the reference shape
76 Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
77 if (anOriginal.IsNull()) return aGEOMObject._retn();
80 Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
82 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
84 return GetObject(anObject);
87 //=============================================================================
91 //=============================================================================
92 void GEOM_IInsertOperations_i::Export
93 (GEOM::GEOM_Object_ptr theOriginal,
94 const char* theFileName,
95 const char* theFormatName)
97 GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
100 GetOperations()->SetNotDone();
102 //Get the reference shape
103 Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
104 if (anOriginal.IsNull()) return;
106 //Export the shape to the file
107 char* aFileName = strdup(theFileName);
108 char* aFormatName = strdup(theFormatName);
109 GetOperations()->Export(anOriginal, aFileName, aFormatName);
114 //=============================================================================
118 //=============================================================================
119 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::Import
120 (const char* theFileName,
121 const char* theFormatName)
123 GEOM::GEOM_Object_var aGEOMObject;
125 //Set a not done flag
126 GetOperations()->SetNotDone();
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);
133 if( strcmp(aFormatName,"IGES_UNIT")==0 && !anObject.IsNull() ) {
136 return GetObject(anObject);
142 if (!GetOperations()->IsDone() || anObject.IsNull()) {
143 return aGEOMObject._retn();
146 return GetObject(anObject);
149 //=============================================================================
153 //=============================================================================
154 void GEOM_IInsertOperations_i::ImportTranslators
155 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
157 // allocate the CORBA arrays
158 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
159 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
161 // Get sequences of available formats
162 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
163 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
164 if (GetOperations()->ImportTranslators(aFormats, aPatterns)) {
165 const int formSize = aFormats->Length();
166 if (formSize == aPatterns->Length()) {
167 aFormatsArray->length(formSize);
168 aPatternsArray->length(formSize);
170 // fill the local CORBA arrays with values from sequences
172 for (; i <= formSize; i++) {
173 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
174 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
179 // initialize out-parameters with local arrays
180 theFormats = aFormatsArray._retn();
181 thePatterns = aPatternsArray._retn();
184 //=============================================================================
188 //=============================================================================
189 void GEOM_IInsertOperations_i::ExportTranslators
190 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
192 // allocate the CORBA arrays
193 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
194 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
196 // Get sequences of available formats
197 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
198 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
199 if (GetOperations()->ExportTranslators(aFormats, aPatterns)) {
200 const int formSize = aFormats->Length();
201 if (formSize == aPatterns->Length()) {
202 aFormatsArray->length(formSize);
203 aPatternsArray->length(formSize);
205 // fill the local CORBA arrays with values from sequences
207 for (; i <= formSize; i++) {
208 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
209 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
214 // initialize out-parameters with local arrays
215 theFormats = aFormatsArray._retn();
216 thePatterns = aPatternsArray._retn();