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