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 if (theOriginal == NULL) return aGEOMObject._retn();
77 //Get the reference shape
78 Handle(GEOM_Object) anOriginal =
79 GetOperations()->GetEngine()->GetObject(theOriginal->GetStudyID(),
80 theOriginal->GetEntry());
82 if (anOriginal.IsNull()) return aGEOMObject._retn();
85 Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
87 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
89 return GetObject(anObject);
92 //=============================================================================
96 //=============================================================================
97 void GEOM_IInsertOperations_i::Export
98 (GEOM::GEOM_Object_ptr theOriginal,
99 const char* theFileName,
100 const char* theFormatName)
102 GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
104 //Set a not done flag
105 GetOperations()->SetNotDone();
107 if (theOriginal == NULL) return;
109 //Get the reference shape
110 Handle(GEOM_Object) anOriginal =
111 GetOperations()->GetEngine()->GetObject(theOriginal->GetStudyID(),
112 theOriginal->GetEntry());
114 if (anOriginal.IsNull()) return;
116 //Export the shape to the file
117 char* aFileName = strdup(theFileName);
118 char* aFormatName = strdup(theFormatName);
119 GetOperations()->Export(anOriginal, aFileName, aFormatName);
126 //=============================================================================
130 //=============================================================================
131 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::Import
132 (const char* theFileName,
133 const char* theFormatName)
135 GEOM::GEOM_Object_var aGEOMObject;
137 //Set a not done flag
138 GetOperations()->SetNotDone();
140 //Import the shape from the file
141 char* aFileName = strdup(theFileName);
142 char* aFormatName = strdup(theFormatName);
143 Handle(GEOM_Object) anObject = GetOperations()->Import(aFileName, aFormatName);
147 if (!GetOperations()->IsDone() || anObject.IsNull())
148 return aGEOMObject._retn();
150 return GetObject(anObject);
153 //=============================================================================
157 //=============================================================================
158 void GEOM_IInsertOperations_i::ImportTranslators
159 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
161 // allocate the CORBA arrays
162 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
163 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
165 // Get sequences of available formats
166 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
167 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
168 if (GetOperations()->ImportTranslators(aFormats, aPatterns)) {
169 const int formSize = aFormats->Length();
170 if (formSize == aPatterns->Length()) {
171 aFormatsArray->length(formSize);
172 aPatternsArray->length(formSize);
174 // fill the local CORBA arrays with values from sequences
176 for (; i <= formSize; i++) {
177 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
178 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
183 // initialize out-parameters with local arrays
184 theFormats = aFormatsArray._retn();
185 thePatterns = aPatternsArray._retn();
188 //=============================================================================
192 //=============================================================================
193 void GEOM_IInsertOperations_i::ExportTranslators
194 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
196 // allocate the CORBA arrays
197 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
198 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
200 // Get sequences of available formats
201 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
202 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
203 if (GetOperations()->ExportTranslators(aFormats, aPatterns)) {
204 const int formSize = aFormats->Length();
205 if (formSize == aPatterns->Length()) {
206 aFormatsArray->length(formSize);
207 aPatternsArray->length(formSize);
209 // fill the local CORBA arrays with values from sequences
211 for (; i <= formSize; i++) {
212 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
213 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
218 // initialize out-parameters with local arrays
219 theFormats = aFormatsArray._retn();
220 thePatterns = aPatternsArray._retn();