Salome HOME
Moving to GUI module
[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   if (theOriginal == NULL) return aGEOMObject._retn();
76
77   //Get the reference shape
78   Handle(GEOM_Object) anOriginal =
79     GetOperations()->GetEngine()->GetObject(theOriginal->GetStudyID(),
80                                             theOriginal->GetEntry());
81
82   if (anOriginal.IsNull()) return aGEOMObject._retn();
83
84   //Create the copy
85   Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
86
87   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
88
89   return GetObject(anObject);
90 }
91
92 //=============================================================================
93 /*!
94  *  Export
95  */
96 //=============================================================================
97 void GEOM_IInsertOperations_i::Export
98                    (GEOM::GEOM_Object_ptr theOriginal,
99                     const char*           theFileName,
100                     const char*           theFormatName)
101 {
102   GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
103
104   //Set a not done flag
105   GetOperations()->SetNotDone();
106
107   if (theOriginal == NULL) return;
108
109   //Get the reference shape
110   Handle(GEOM_Object) anOriginal =
111     GetOperations()->GetEngine()->GetObject(theOriginal->GetStudyID(),
112                                             theOriginal->GetEntry());
113
114   if (anOriginal.IsNull()) return;
115
116   //Export the shape to the file
117   char* aFileName   = strdup(theFileName);
118   char* aFormatName = strdup(theFormatName);
119   GetOperations()->Export(anOriginal, aFileName, aFormatName);
120   free(aFileName);
121   free(aFormatName);
122
123   return;
124 }
125
126 //=============================================================================
127 /*!
128  *  Import
129  */
130 //=============================================================================
131 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::Import
132                    (const char* theFileName,
133                     const char* theFormatName)
134 {
135   GEOM::GEOM_Object_var aGEOMObject;
136
137   //Set a not done flag
138   GetOperations()->SetNotDone();
139
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);
144   free(aFileName);
145   free(aFormatName);
146
147   if (!GetOperations()->IsDone() || anObject.IsNull())
148     return aGEOMObject._retn();
149
150   return GetObject(anObject);
151 }
152
153 //=============================================================================
154 /*!
155  *  ImportTranslators
156  */
157 //=============================================================================
158 void GEOM_IInsertOperations_i::ImportTranslators
159   (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
160 {
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();
164
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);
173
174       // fill the local CORBA arrays with values from sequences
175       CORBA::Long i = 1;
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());
179       }
180     }
181   }
182
183   // initialize out-parameters with local arrays
184   theFormats  = aFormatsArray._retn();
185   thePatterns = aPatternsArray._retn();
186 }
187
188 //=============================================================================
189 /*!
190  *  ExportTranslators
191  */
192 //=============================================================================
193 void GEOM_IInsertOperations_i::ExportTranslators
194   (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
195 {
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();
199
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);
208
209       // fill the local CORBA arrays with values from sequences
210       CORBA::Long i = 1;
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());
214       }
215     }
216   }
217
218   // initialize out-parameters with local arrays
219   theFormats  = aFormatsArray._retn();
220   thePatterns = aPatternsArray._retn();
221 }