1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #pragma warning( disable:4786 )
24 #include <Standard_Stream.hxx>
26 #include "GEOM_IInsertOperations_i.hh"
28 #include "utilities.h"
30 #include "Utils_ExceptHandlers.hxx"
32 #include "GEOM_Engine.hxx"
33 #include "GEOM_Object.hxx"
35 #include <TColStd_HSequenceOfAsciiString.hxx>
37 //=============================================================================
41 //=============================================================================
42 GEOM_IInsertOperations_i::GEOM_IInsertOperations_i (PortableServer::POA_ptr thePOA,
43 GEOM::GEOM_Gen_ptr theEngine,
44 ::GEOMImpl_IInsertOperations* theImpl)
45 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
47 MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
50 //=============================================================================
54 //=============================================================================
55 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
57 MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
61 //=============================================================================
65 //=============================================================================
66 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
68 GEOM::GEOM_Object_var aGEOMObject;
71 GetOperations()->SetNotDone();
73 if (theOriginal == NULL) return aGEOMObject._retn();
75 //Get the reference shape
76 Handle(GEOM_Object) anOriginal =
77 GetOperations()->GetEngine()->GetObject(theOriginal->GetStudyID(),
78 theOriginal->GetEntry());
80 if (anOriginal.IsNull()) return aGEOMObject._retn();
83 Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
85 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
87 return GetObject(anObject);
90 //=============================================================================
94 //=============================================================================
95 void GEOM_IInsertOperations_i::Export
96 (GEOM::GEOM_Object_ptr theOriginal,
97 const char* theFileName,
98 const char* theFormatName)
100 GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
102 //Set a not done flag
103 GetOperations()->SetNotDone();
105 if (theOriginal == NULL) return;
107 //Get the reference shape
108 Handle(GEOM_Object) anOriginal =
109 GetOperations()->GetEngine()->GetObject(theOriginal->GetStudyID(),
110 theOriginal->GetEntry());
112 if (anOriginal.IsNull()) return;
114 //Export the shape to the file
115 char* aFileName = strdup(theFileName);
116 char* aFormatName = strdup(theFormatName);
117 GetOperations()->Export(anOriginal, aFileName, aFormatName);
124 //=============================================================================
128 //=============================================================================
129 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::Import
130 (const char* theFileName,
131 const char* theFormatName)
133 GEOM::GEOM_Object_var aGEOMObject;
135 //Set a not done flag
136 GetOperations()->SetNotDone();
138 //Import the shape from the file
139 char* aFileName = strdup(theFileName);
140 char* aFormatName = strdup(theFormatName);
141 Handle(GEOM_Object) anObject = GetOperations()->Import(aFileName, aFormatName);
145 if (!GetOperations()->IsDone() || anObject.IsNull())
146 return aGEOMObject._retn();
148 return GetObject(anObject);
151 //=============================================================================
155 //=============================================================================
156 void GEOM_IInsertOperations_i::ImportTranslators
157 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
159 // allocate the CORBA arrays
160 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
161 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
163 // Get sequences of available formats
164 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
165 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
166 if (GetOperations()->ImportTranslators(aFormats, aPatterns)) {
167 const int formSize = aFormats->Length();
168 if (formSize == aPatterns->Length()) {
169 aFormatsArray->length(formSize);
170 aPatternsArray->length(formSize);
172 // fill the local CORBA arrays with values from sequences
174 for (; i <= formSize; i++) {
175 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
176 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
181 // initialize out-parameters with local arrays
182 theFormats = aFormatsArray._retn();
183 thePatterns = aPatternsArray._retn();
186 //=============================================================================
190 //=============================================================================
191 void GEOM_IInsertOperations_i::ExportTranslators
192 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
194 // allocate the CORBA arrays
195 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
196 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
198 // Get sequences of available formats
199 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
200 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
201 if (GetOperations()->ExportTranslators(aFormats, aPatterns)) {
202 const int formSize = aFormats->Length();
203 if (formSize == aPatterns->Length()) {
204 aFormatsArray->length(formSize);
205 aPatternsArray->length(formSize);
207 // fill the local CORBA arrays with values from sequences
209 for (; i <= formSize; i++) {
210 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
211 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
216 // initialize out-parameters with local arrays
217 theFormats = aFormatsArray._retn();
218 thePatterns = aPatternsArray._retn();