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)) return;
141 const int formSize = aFormats->Length(), pattSize = aPatterns->Length();
142 if (formSize != pattSize) return;
144 // allocate the CORBA arrays
145 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
146 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
147 aFormatsArray->length(formSize);
148 aPatternsArray->length(formSize);
150 // fill the local CORBA arrays with values from sequences
152 for (; i <= formSize; i++) {
153 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
154 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
157 // initialize out-parameters with local arrays
158 theFormats = aFormatsArray._retn();
159 thePatterns = aPatternsArray._retn();
162 //=============================================================================
166 //=============================================================================
167 void GEOM_IInsertOperations_i::ExportTranslators
168 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
170 // Get sequences of available formats
171 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
172 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
173 if (!GetOperations()->ExportTranslators(aFormats, aPatterns)) return;
175 const int formSize = aFormats->Length(), pattSize = aPatterns->Length();
176 if (formSize != pattSize) return;
178 // allocate the CORBA arrays
179 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
180 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
181 aFormatsArray->length(formSize);
182 aPatternsArray->length(formSize);
184 // fill the local CORBA arrays with values from sequences
186 for (; i <= formSize; i++) {
187 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
188 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
191 // initialize out-parameters with local arrays
192 theFormats = aFormatsArray._retn();
193 thePatterns = aPatternsArray._retn();