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 // 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())
146 aFormats->Clear(); aPatterns->Clear();
149 const int formSize = aFormats->Length(), pattSize = aPatterns->Length();
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);
157 // fill the local CORBA arrays with values from sequences
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());
164 // initialize out-parameters with local arrays
165 theFormats = aFormatsArray._retn();
166 thePatterns = aPatternsArray._retn();
169 //=============================================================================
173 //=============================================================================
174 void GEOM_IInsertOperations_i::ExportTranslators
175 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
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;
182 const int formSize = aFormats->Length(), pattSize = aPatterns->Length();
183 if (formSize != pattSize) return;
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);
191 // fill the local CORBA arrays with values from sequences
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());
198 // initialize out-parameters with local arrays
199 theFormats = aFormatsArray._retn();
200 thePatterns = aPatternsArray._retn();