Salome HOME
PAL7360
[modules/geom.git] / src / GEOM_I / GEOM_IInsertOperations_i.cc
1 using namespace std; 
2
3 #include "GEOM_IInsertOperations_i.hh"
4
5 #include "utilities.h"
6 #include "OpUtil.hxx"
7 #include "Utils_ExceptHandlers.hxx"
8
9 #include "GEOM_Engine.hxx"
10 #include "GEOM_Object.hxx"
11
12 #include <TColStd_HSequenceOfAsciiString.hxx>
13
14 //=============================================================================
15 /*!
16  *   constructor:
17  */
18 //=============================================================================
19 GEOM_IInsertOperations_i::GEOM_IInsertOperations_i (PortableServer::POA_ptr thePOA,
20                                                     GEOM::GEOM_Gen_ptr theEngine,
21                                                     ::GEOMImpl_IInsertOperations* theImpl)
22      :GEOM_IOperations_i(thePOA, theEngine, theImpl)
23 {
24   MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
25 }
26
27 //=============================================================================
28 /*!
29  *  destructor
30  */
31 //=============================================================================
32 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
33 {
34   MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
35 }
36
37
38 //=============================================================================
39 /*!
40  *  MakeCopy
41  */
42 //=============================================================================
43 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
44 {
45   GEOM::GEOM_Object_var aGEOMObject;
46
47   //Set a not done flag
48   GetOperations()->SetNotDone();
49
50   if (theOriginal == NULL) return aGEOMObject._retn();
51
52   //Get the reference shape
53   Handle(GEOM_Object) anOriginal =
54     GetOperations()->GetEngine()->GetObject(theOriginal->GetStudyID(),
55                                             theOriginal->GetEntry());
56
57   if (anOriginal.IsNull()) return aGEOMObject._retn();
58
59   //Create the copy
60   Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
61
62   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
63
64   return GetObject(anObject);
65 }
66
67 //=============================================================================
68 /*!
69  *  Export
70  */
71 //=============================================================================
72 void GEOM_IInsertOperations_i::Export
73                    (GEOM::GEOM_Object_ptr theOriginal,
74                     const char*           theFileName,
75                     const char*           theFormatName)
76 {
77   GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
78
79   //Set a not done flag
80   GetOperations()->SetNotDone();
81
82   if (theOriginal == NULL) return;
83
84   //Get the reference shape
85   Handle(GEOM_Object) anOriginal =
86     GetOperations()->GetEngine()->GetObject(theOriginal->GetStudyID(),
87                                             theOriginal->GetEntry());
88
89   if (anOriginal.IsNull()) return;
90
91   //Export the shape to the file
92   char* aFileName   = strdup(theFileName);
93   char* aFormatName = strdup(theFormatName);
94   GetOperations()->Export(anOriginal, aFileName, aFormatName);
95   free(aFileName);
96   free(aFormatName);
97
98   return;
99 }
100
101 //=============================================================================
102 /*!
103  *  Import
104  */
105 //=============================================================================
106 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::Import
107                    (const char* theFileName,
108                     const char* theFormatName)
109 {
110   GEOM::GEOM_Object_var aGEOMObject;
111
112   //Set a not done flag
113   GetOperations()->SetNotDone();
114
115   //Import the shape from the file
116   char* aFileName   = strdup(theFileName);
117   char* aFormatName = strdup(theFormatName);
118   Handle(GEOM_Object) anObject = GetOperations()->Import(aFileName, aFormatName);
119   free(aFileName);
120   free(aFormatName);
121
122   if (!GetOperations()->IsDone() || anObject.IsNull())
123     return aGEOMObject._retn();
124
125   return GetObject(anObject);
126 }
127
128 //=============================================================================
129 /*!
130  *  ImportTranslators
131  */
132 //=============================================================================
133 void GEOM_IInsertOperations_i::ImportTranslators
134   (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
135 {
136   // Get sequences of available formats
137   Handle(TColStd_HSequenceOfAsciiString) aFormats  = new TColStd_HSequenceOfAsciiString;
138   Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
139   if (!GetOperations()->ImportTranslators(aFormats, aPatterns)) return;
140
141   const int formSize = aFormats->Length(), pattSize = aPatterns->Length();
142   if (formSize != pattSize) return;
143
144   // allocate the CORBA arrays
145   GEOM::string_array_var aFormatsArray  = new GEOM::string_array();
146   GEOM::string_array_var aPatternsArray = new GEOM::string_array();
147   aFormatsArray->length(formSize);
148   aPatternsArray->length(formSize);
149
150   // fill the local CORBA arrays with values from sequences
151   CORBA::Long i = 1;
152   for (; i <= formSize; i++) {
153     aFormatsArray[i-1]  = CORBA::string_dup(aFormats->Value(i).ToCString());
154     aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
155   }
156
157   // initialize out-parameters with local arrays
158   theFormats = aFormatsArray._retn();
159   thePatterns = aPatternsArray._retn();
160 }
161
162 //=============================================================================
163 /*!
164  *  ExportTranslators
165  */
166 //=============================================================================
167 void GEOM_IInsertOperations_i::ExportTranslators
168   (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
169 {
170   // Get sequences of available formats
171   Handle(TColStd_HSequenceOfAsciiString) aFormats  = new TColStd_HSequenceOfAsciiString;
172   Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
173   if (!GetOperations()->ExportTranslators(aFormats, aPatterns)) return;
174
175   const int formSize = aFormats->Length(), pattSize = aPatterns->Length();
176   if (formSize != pattSize) return;
177
178   // allocate the CORBA arrays
179   GEOM::string_array_var aFormatsArray  = new GEOM::string_array();
180   GEOM::string_array_var aPatternsArray = new GEOM::string_array();
181   aFormatsArray->length(formSize);
182   aPatternsArray->length(formSize);
183
184   // fill the local CORBA arrays with values from sequences
185   CORBA::Long i = 1;
186   for (; i <= formSize; i++) {
187     aFormatsArray[i-1]  = CORBA::string_dup(aFormats->Value(i).ToCString());
188     aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
189   }
190
191   // initialize out-parameters with local arrays
192   theFormats = aFormatsArray._retn();
193   thePatterns = aPatternsArray._retn();
194 }