]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_IInsertOperations_i.cc
Salome HOME
1a525dc291458ea1c901dc8b98f4d6ed59f7544a
[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   // Get sequences of available formats
141   Handle(TColStd_HSequenceOfAsciiString) aFormats  = new TColStd_HSequenceOfAsciiString;
142   Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
143   if (!GetOperations()->ImportTranslators(aFormats, aPatterns) ||
144       aFormats->Length() != aPatterns->Length())
145   {
146     aFormats->Clear(); aPatterns->Clear();
147   }
148
149   const int formSize = aFormats->Length(), pattSize = aPatterns->Length();
150
151   // allocate the CORBA arrays
152   GEOM::string_array_var aFormatsArray  = new GEOM::string_array();
153   GEOM::string_array_var aPatternsArray = new GEOM::string_array();
154   aFormatsArray->length(formSize);
155   aPatternsArray->length(formSize);
156
157   // fill the local CORBA arrays with values from sequences
158   CORBA::Long i = 1;
159   for (; i <= formSize; i++) {
160     aFormatsArray[i-1]  = CORBA::string_dup(aFormats->Value(i).ToCString());
161     aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
162   }
163
164   // initialize out-parameters with local arrays
165   theFormats = aFormatsArray._retn();
166   thePatterns = aPatternsArray._retn();
167 }
168
169 //=============================================================================
170 /*!
171  *  ExportTranslators
172  */
173 //=============================================================================
174 void GEOM_IInsertOperations_i::ExportTranslators
175   (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
176 {
177   // Get sequences of available formats
178   Handle(TColStd_HSequenceOfAsciiString) aFormats  = new TColStd_HSequenceOfAsciiString;
179   Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
180   if (!GetOperations()->ExportTranslators(aFormats, aPatterns)) return;
181
182   const int formSize = aFormats->Length(), pattSize = aPatterns->Length();
183   if (formSize != pattSize) return;
184
185   // allocate the CORBA arrays
186   GEOM::string_array_var aFormatsArray  = new GEOM::string_array();
187   GEOM::string_array_var aPatternsArray = new GEOM::string_array();
188   aFormatsArray->length(formSize);
189   aPatternsArray->length(formSize);
190
191   // fill the local CORBA arrays with values from sequences
192   CORBA::Long i = 1;
193   for (; i <= formSize; i++) {
194     aFormatsArray[i-1]  = CORBA::string_dup(aFormats->Value(i).ToCString());
195     aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
196   }
197
198   // initialize out-parameters with local arrays
199   theFormats = aFormatsArray._retn();
200   thePatterns = aPatternsArray._retn();
201 }