3 #include "GEOM_IInsertOperations_i.hh"
7 #include "Utils_ExceptHandlers.hxx"
9 #include "GEOM_Engine.hxx"
10 #include "GEOM_Object.hxx"
12 #include <TColStd_HSequenceOfAsciiString.hxx>
14 //=============================================================================
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)
24 MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
27 //=============================================================================
31 //=============================================================================
32 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
34 MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
38 //=============================================================================
42 //=============================================================================
43 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
45 GEOM::GEOM_Object_var aGEOMObject;
48 GetOperations()->SetNotDone();
50 if (theOriginal == NULL) return aGEOMObject._retn();
52 //Get the reference shape
53 Handle(GEOM_Object) anOriginal =
54 GetOperations()->GetEngine()->GetObject(theOriginal->GetStudyID(),
55 theOriginal->GetEntry());
57 if (anOriginal.IsNull()) return aGEOMObject._retn();
60 Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
62 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
64 return GetObject(anObject);
67 //=============================================================================
71 //=============================================================================
72 void GEOM_IInsertOperations_i::Export
73 (GEOM::GEOM_Object_ptr theOriginal,
74 const char* theFileName,
75 const char* theFormatName)
77 GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
80 GetOperations()->SetNotDone();
82 if (theOriginal == NULL) return;
84 //Get the reference shape
85 Handle(GEOM_Object) anOriginal =
86 GetOperations()->GetEngine()->GetObject(theOriginal->GetStudyID(),
87 theOriginal->GetEntry());
89 if (anOriginal.IsNull()) return;
91 //Export the shape to the file
92 char* aFileName = strdup(theFileName);
93 char* aFormatName = strdup(theFormatName);
94 GetOperations()->Export(anOriginal, aFileName, aFormatName);
101 //=============================================================================
105 //=============================================================================
106 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::Import
107 (const char* theFileName,
108 const char* theFormatName)
110 GEOM::GEOM_Object_var aGEOMObject;
112 //Set a not done flag
113 GetOperations()->SetNotDone();
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);
122 if (!GetOperations()->IsDone() || anObject.IsNull())
123 return aGEOMObject._retn();
125 return GetObject(anObject);
128 //=============================================================================
132 //=============================================================================
133 void GEOM_IInsertOperations_i::ImportTranslators
134 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
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())
142 aFormats->Clear(); aPatterns->Clear();
145 const int formSize = aFormats->Length(), pattSize = aPatterns->Length();
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);
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());
160 // initialize out-parameters with local arrays
161 theFormats = aFormatsArray._retn();
162 thePatterns = aPatternsArray._retn();
165 //=============================================================================
169 //=============================================================================
170 void GEOM_IInsertOperations_i::ExportTranslators
171 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
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;
178 const int formSize = aFormats->Length(), pattSize = aPatterns->Length();
179 if (formSize != pattSize) return;
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);
187 // fill the local CORBA arrays with values from sequences
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());
194 // initialize out-parameters with local arrays
195 theFormats = aFormatsArray._retn();
196 thePatterns = aPatternsArray._retn();