]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_IInsertOperations_i.cc
Salome HOME
b32b3eb717457407857f29ab3b4e210d04ab90ff
[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
133   if( strcmp(aFormatName,"IGES_UNIT")==0 && !anObject.IsNull() ) {
134     free(aFileName);
135     free(aFormatName);
136     return GetObject(anObject);
137   }
138
139   free(aFileName);
140   free(aFormatName);
141
142   if (!GetOperations()->IsDone() || anObject.IsNull()) {
143     return aGEOMObject._retn();
144   }
145
146   return GetObject(anObject);
147 }
148
149 //=============================================================================
150 /*!
151  *  ImportTranslators
152  */
153 //=============================================================================
154 void GEOM_IInsertOperations_i::ImportTranslators
155   (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
156 {
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();
160
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);
169
170       // fill the local CORBA arrays with values from sequences
171       CORBA::Long i = 1;
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());
175       }
176     }
177   }
178
179   // initialize out-parameters with local arrays
180   theFormats  = aFormatsArray._retn();
181   thePatterns = aPatternsArray._retn();
182 }
183
184 //=============================================================================
185 /*!
186  *  ExportTranslators
187  */
188 //=============================================================================
189 void GEOM_IInsertOperations_i::ExportTranslators
190   (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
191 {
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();
195
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);
204
205       // fill the local CORBA arrays with values from sequences
206       CORBA::Long i = 1;
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());
210       }
211     }
212   }
213
214   // initialize out-parameters with local arrays
215   theFormats  = aFormatsArray._retn();
216   thePatterns = aPatternsArray._retn();
217 }