2 #pragma warning( disable:4786 )
5 #include <Standard_Stream.hxx>
7 #include "GEOM_IInsertOperations_i.hh"
11 #include "Utils_ExceptHandlers.hxx"
13 #include "GEOM_Engine.hxx"
14 #include "GEOM_Object.hxx"
16 #include <TColStd_HSequenceOfAsciiString.hxx>
18 //=============================================================================
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)
28 MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
31 //=============================================================================
35 //=============================================================================
36 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
38 MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
42 //=============================================================================
46 //=============================================================================
47 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
49 GEOM::GEOM_Object_var aGEOMObject;
52 GetOperations()->SetNotDone();
54 if (theOriginal == NULL) return aGEOMObject._retn();
56 //Get the reference shape
57 Handle(GEOM_Object) anOriginal =
58 GetOperations()->GetEngine()->GetObject(theOriginal->GetStudyID(),
59 theOriginal->GetEntry());
61 if (anOriginal.IsNull()) return aGEOMObject._retn();
64 Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
66 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
68 return GetObject(anObject);
71 //=============================================================================
75 //=============================================================================
76 void GEOM_IInsertOperations_i::Export
77 (GEOM::GEOM_Object_ptr theOriginal,
78 const char* theFileName,
79 const char* theFormatName)
81 GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
84 GetOperations()->SetNotDone();
86 if (theOriginal == NULL) return;
88 //Get the reference shape
89 Handle(GEOM_Object) anOriginal =
90 GetOperations()->GetEngine()->GetObject(theOriginal->GetStudyID(),
91 theOriginal->GetEntry());
93 if (anOriginal.IsNull()) return;
95 //Export the shape to the file
96 char* aFileName = strdup(theFileName);
97 char* aFormatName = strdup(theFormatName);
98 GetOperations()->Export(anOriginal, aFileName, aFormatName);
105 //=============================================================================
109 //=============================================================================
110 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::Import
111 (const char* theFileName,
112 const char* theFormatName)
114 GEOM::GEOM_Object_var aGEOMObject;
116 //Set a not done flag
117 GetOperations()->SetNotDone();
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);
126 if (!GetOperations()->IsDone() || anObject.IsNull())
127 return aGEOMObject._retn();
129 return GetObject(anObject);
132 //=============================================================================
136 //=============================================================================
137 void GEOM_IInsertOperations_i::ImportTranslators
138 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
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();
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);
153 // fill the local CORBA arrays with values from sequences
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());
162 // initialize out-parameters with local arrays
163 theFormats = aFormatsArray._retn();
164 thePatterns = aPatternsArray._retn();
167 //=============================================================================
171 //=============================================================================
172 void GEOM_IInsertOperations_i::ExportTranslators
173 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
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();
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);
188 // fill the local CORBA arrays with values from sequences
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());
197 // initialize out-parameters with local arrays
198 theFormats = aFormatsArray._retn();
199 thePatterns = aPatternsArray._retn();