1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "GEOM_BaseObject_i.hh"
25 #include "GEOMImpl_Types.hxx"
26 #include "GEOM_BaseDriver.hxx"
28 #include <utilities.h>
29 //#include <OpUtil.hxx>
30 //#include <Utils_ExceptHandlers.hxx>
32 #include <TCollection_AsciiString.hxx>
33 #include <TDF_Label.hxx>
34 #include <TDF_Tool.hxx>
35 #include <Standard_ErrorHandler.hxx>
36 #include <Standard_Failure.hxx>
43 #pragma warning( disable:4786 )
46 //=============================================================================
50 //=============================================================================
52 GEOM_BaseObject_i::GEOM_BaseObject_i (PortableServer::POA_ptr thePOA,
53 GEOM::GEOM_Gen_ptr theEngine,
54 HANDLE_NAMESPACE(GEOM_BaseObject) theImpl)
55 : SALOME::GenericObj_i( thePOA ), _engine(theEngine), _impl(theImpl)
59 //=============================================================================
63 //=============================================================================
65 GEOM_BaseObject_i::~GEOM_BaseObject_i()
67 MESSAGE("GEOM_BaseObject_i::~GEOM_BaseObject_i");
68 GEOM_Engine::GetEngine()->RemoveObject(_impl);
71 //=============================================================================
75 //=============================================================================
77 char* GEOM_BaseObject_i::GetEntry()
79 const TDF_Label& aLabel = _impl->GetEntry();
80 TCollection_AsciiString anEntry;
81 TDF_Tool::Entry(aLabel, anEntry);
82 const char* anEntstr = anEntry.ToCString();
83 return CORBA::string_dup(anEntstr);
86 //=============================================================================
90 //=============================================================================
92 CORBA::Long GEOM_BaseObject_i::GetStudyID()
94 return _impl->GetDocID();
97 //=============================================================================
101 //=============================================================================
103 CORBA::Long GEOM_BaseObject_i::GetType()
105 return _impl->GetType();
108 //=============================================================================
112 //=============================================================================
114 CORBA::Long GEOM_BaseObject_i::GetTick()
116 return _impl->GetTic();
119 //=============================================================================
123 //=============================================================================
124 void GEOM_BaseObject_i::SetName(const char* theName)
126 _impl->SetName(theName);
129 //=============================================================================
133 //=============================================================================
135 char* GEOM_BaseObject_i::GetName()
137 TCollection_AsciiString aName = _impl->GetName();
138 return CORBA::string_dup( aName.ToCString() );
141 //=============================================================================
145 //=============================================================================
147 void GEOM_BaseObject_i::SetStudyEntry(const char* theEntry)
149 _impl->SetAuxData(theEntry);
152 //=============================================================================
156 //=============================================================================
158 char* GEOM_BaseObject_i::GetStudyEntry()
160 TCollection_AsciiString anEntry = _impl->GetAuxData();
161 return CORBA::string_dup(anEntry.ToCString());
164 //=============================================================================
168 //=============================================================================
169 GEOM::ListOfGBO* GEOM_BaseObject_i::GetDependency()
171 GEOM::ListOfGBO_var aList = new GEOM::ListOfGBO();
174 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetAllDependency();
175 if (aSeq.IsNull()) return aList._retn();
176 int aLength = aSeq->Length();
177 if (aLength == 0) return aList._retn();
179 aList->length(aLength);
181 TCollection_AsciiString anEntry;
183 for (int i = 1; i<=aLength; i++) {
184 HANDLE_NAMESPACE(GEOM_BaseObject) anObj = HANDLE_NAMESPACE(GEOM_BaseObject)::DownCast(aSeq->Value(i));
185 if (anObj.IsNull()) continue;
186 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
187 GEOM::GEOM_BaseObject_var obj = _engine->GetObject(anObj->GetDocID(), (char*) anEntry.ToCString());
191 return aList._retn();
194 //=============================================================================
198 //=============================================================================
199 GEOM::ListOfGBO* GEOM_BaseObject_i::GetLastDependency()
201 GEOM::ListOfGBO_var aList = new GEOM::ListOfGBO();
204 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetLastDependency();
205 if (aSeq.IsNull()) return aList._retn();
206 int aLength = aSeq->Length();
207 if (aLength == 0) return aList._retn();
209 aList->length(aLength);
211 TCollection_AsciiString anEntry;
213 for (int i = 1; i<=aLength; i++) {
214 HANDLE_NAMESPACE(GEOM_BaseObject) anObj = HANDLE_NAMESPACE(GEOM_BaseObject)::DownCast(aSeq->Value(i));
215 if (anObj.IsNull()) continue;
216 GEOM::GEOM_BaseObject_var obj = _engine->GetObject(anObj->GetDocID(),
217 anObj->GetEntryString().ToCString());
218 aList[i-1] = GEOM::GEOM_BaseObject::_duplicate( obj );
221 return aList._retn();
224 //================================================================================
228 //================================================================================
230 bool GEOM_BaseObject_i::IsSame(GEOM::GEOM_BaseObject_ptr other)
232 if ( CORBA::is_nil( other ))
235 PortableServer::Servant aServant = myPOA->reference_to_servant( other );
236 GEOM_BaseObject_i * other_i = dynamic_cast<GEOM_BaseObject_i*>(aServant);
240 return _impl->GetEntry() == other_i->_impl->GetEntry();
243 //================================================================================
247 //================================================================================
249 void GEOM_BaseObject_i::SetParameters(const char* theParameters)
251 _impl->SetParameters((char*)theParameters);
254 //================================================================================
258 //================================================================================
260 char* GEOM_BaseObject_i::GetParameters()
262 return CORBA::string_dup(_impl->GetParameters().ToCString());
265 //================================================================================
269 //================================================================================
271 GEOM::CreationInformationSeq* GEOM_BaseObject_i::GetCreationInformation()
273 GEOM::CreationInformationSeq_var info = new GEOM::CreationInformationSeq();
275 int nbFun = _impl->GetNbFunctions();
276 info->length( nbFun );
278 for ( int i = 1; i <= nbFun; ++i )
280 HANDLE_NAMESPACE(GEOM_BaseDriver) driver =
281 HANDLE_NAMESPACE(GEOM_BaseDriver)::DownCast( _impl->GetCreationDriver( i ));
282 if ( !driver.IsNull() )
284 std::vector<GEOM_Param> params;
285 std::string operationName;
289 if ( driver->GetCreationInformation( operationName, params ))
291 info[nbI].operationName = operationName.c_str();
292 info[nbI].params.length( params.size() );
293 for ( size_t i = 0; i < params.size(); ++i )
295 info[nbI].params[i].name = params[i].name.c_str();
296 info[nbI].params[i].value = params[i].value.c_str();
301 if ( operationName.empty() )
303 cout << endl << endl << endl << "Warning: " << endl << "Dear developer!!!" << endl
304 << " Consider implementing "
305 << typeid(*(driver.operator->())).name() << "::GetCreationInformation() " << endl
306 << " for the case of operation which has created '" << GetName() << "' object" << endl
307 << "PLEEEEEEEASE" << endl
308 << "\tPLEEEEEEEASE" << endl
309 << "\t\tPLEEEEEEEASE" << endl
310 << "\t\t\tPLEEEEEEEASE" << endl
311 << "\t\t\t\tPLEEEEEEEASE" << endl;
318 cout << "Ecxeption in GEOM_BaseObject_i::GetCreationInformation()" << endl;