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