Salome HOME
Merge branch 'V9_11_BR'
[modules/geom.git] / src / GEOM_I / GEOM_BaseObject_i.cc
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "GEOM_BaseObject_i.hh"
24
25 #include "GEOMImpl_Types.hxx"
26 #include "GEOM_BaseDriver.hxx"
27
28 #include <utilities.h>
29 //#include <OpUtil.hxx>
30 //#include <Utils_ExceptHandlers.hxx>
31
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>
37
38 #ifdef _DEBUG_
39 #include <typeinfo>
40 #endif
41
42 #ifdef WIN32
43 #pragma warning( disable:4786 )
44 #endif
45
46 //=============================================================================
47 /*!
48  *   constructor:
49  */
50 //=============================================================================
51
52 GEOM_BaseObject_i::GEOM_BaseObject_i (PortableServer::POA_ptr thePOA,
53                                       GEOM::GEOM_Gen_ptr      theEngine,
54                                       Handle(::GEOM_BaseObject) theImpl)
55   : SALOME::GenericObj_i( thePOA ), _engine(theEngine), _impl(theImpl)
56 {
57 }
58
59 //=============================================================================
60 /*!
61  *  destructor
62  */
63 //=============================================================================
64
65 GEOM_BaseObject_i::~GEOM_BaseObject_i()
66 {
67   //MESSAGE("GEOM_BaseObject_i::~GEOM_BaseObject_i");
68   GEOM_Engine::GetEngine()->RemoveObject(_impl);
69 }
70
71 //=============================================================================
72 /*!
73  *  GetEntry
74  */
75 //=============================================================================
76
77 char* GEOM_BaseObject_i::GetEntry()
78 {
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);
84 }
85
86 //=============================================================================
87 /*!
88  *  GetType
89  */
90 //=============================================================================
91
92 CORBA::Long GEOM_BaseObject_i::GetType()
93 {
94   return _impl->GetType();
95 }
96
97 //=============================================================================
98 /*!
99  *  GetTick
100  */
101 //=============================================================================
102
103 CORBA::Long GEOM_BaseObject_i::GetTick()
104 {
105   return _impl->GetTic();
106 }
107
108 //=============================================================================
109 /*!
110  *  SetName
111  */
112 //=============================================================================
113 void GEOM_BaseObject_i::SetName(const char* theName)
114 {
115   _impl->SetName(theName);
116 }
117
118 //=============================================================================
119 /*!
120  *  GetName
121  */
122 //=============================================================================
123
124 char* GEOM_BaseObject_i::GetName()
125 {
126   TCollection_AsciiString aName = _impl->GetName();
127   return CORBA::string_dup( aName.ToCString() );
128 }
129
130 //=============================================================================
131 /*!
132  *  SetStudyEntry
133  */
134 //=============================================================================
135
136 void GEOM_BaseObject_i::SetStudyEntry(const char* theEntry)
137 {
138   _impl->SetAuxData(theEntry);
139 }
140
141 //=============================================================================
142 /*!
143  *  GetStudyEntry
144  */
145 //=============================================================================
146
147 char* GEOM_BaseObject_i::GetStudyEntry()
148 {
149   TCollection_AsciiString anEntry = _impl->GetAuxData();
150   return CORBA::string_dup(anEntry.ToCString());
151 }
152
153 //=============================================================================
154 /*!
155  *  GetDependency
156  */
157 //=============================================================================
158 GEOM::ListOfGBO* GEOM_BaseObject_i::GetDependency()
159 {
160   GEOM::ListOfGBO_var aList = new GEOM::ListOfGBO();
161   aList->length(0);
162
163   Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetAllDependency();
164   if (aSeq.IsNull()) return aList._retn();
165   int aLength = aSeq->Length();
166   if (aLength == 0) return aList._retn();
167
168   aList->length(aLength);
169
170   TCollection_AsciiString anEntry;
171
172   for (int i = 1; i<=aLength; i++) {
173     Handle(::GEOM_BaseObject) anObj = Handle(::GEOM_BaseObject)::DownCast(aSeq->Value(i));
174     if (anObj.IsNull()) continue;
175     TDF_Tool::Entry(anObj->GetEntry(), anEntry);
176     GEOM::GEOM_BaseObject_var obj = _engine->GetObject((char*) anEntry.ToCString());
177     aList[i-1] = obj;
178   }
179
180   return aList._retn();
181 }
182
183 //=============================================================================
184 /*!
185  * GetLastDependency
186  */
187 //=============================================================================
188 GEOM::ListOfGBO* GEOM_BaseObject_i::GetLastDependency()
189 {
190   GEOM::ListOfGBO_var aList = new GEOM::ListOfGBO();
191   aList->length(0);
192
193   Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetLastDependency();
194   if (aSeq.IsNull()) return aList._retn();
195   int aLength = aSeq->Length();
196   if (aLength == 0) return aList._retn();
197
198   aList->length(aLength);
199
200   TCollection_AsciiString anEntry;
201
202   for (int i = 1; i<=aLength; i++) {
203      Handle(::GEOM_BaseObject) anObj = Handle(::GEOM_BaseObject)::DownCast(aSeq->Value(i));
204      if (anObj.IsNull()) continue;
205      GEOM::GEOM_BaseObject_var obj = _engine->GetObject(anObj->GetEntryString().ToCString());
206      aList[i-1] = GEOM::GEOM_BaseObject::_duplicate( obj );
207   }
208
209   return aList._retn();
210 }
211
212 //================================================================================
213 /*!
214  * \brief 
215  */
216 //================================================================================
217
218 bool GEOM_BaseObject_i::IsSame(GEOM::GEOM_BaseObject_ptr other)
219 {
220   if ( CORBA::is_nil( other ))
221     return false;
222
223   PortableServer::Servant aServant = myPOA->reference_to_servant( other );
224   GEOM_BaseObject_i * other_i = dynamic_cast<GEOM_BaseObject_i*>(aServant);
225   if ( !other_i )
226     return false;
227
228   return _impl->GetEntry() == other_i->_impl->GetEntry();
229 }
230
231 //================================================================================
232 /*!
233  * \brief 
234  */
235 //================================================================================
236
237 void GEOM_BaseObject_i::SetParameters(const char* theParameters)
238 {
239   _impl->SetParameters((char*)theParameters);
240 }
241
242 //================================================================================
243 /*!
244  * \brief 
245  */
246 //================================================================================
247
248 char* GEOM_BaseObject_i::GetParameters()
249 {
250   return CORBA::string_dup(_impl->GetParameters().ToCString());
251 }
252
253 //================================================================================
254 /*!
255  * \brief 
256  */
257 //================================================================================
258
259 GEOM::CreationInformationSeq* GEOM_BaseObject_i::GetCreationInformation()
260 {
261   GEOM::CreationInformationSeq_var info = new GEOM::CreationInformationSeq();
262
263   int nbFun = _impl->GetNbFunctions();
264   info->length( nbFun );
265   int nbI = 0;
266   for ( int i = 1; i <= nbFun; ++i )
267   {
268     Handle(::GEOM_BaseDriver) driver =
269       Handle(::GEOM_BaseDriver)::DownCast( _impl->GetCreationDriver( i ));
270     if ( !driver.IsNull() )
271     {
272       std::vector<GEOM_Param> params;
273       std::string             operationName;
274       try
275       {
276         OCC_CATCH_SIGNALS;
277         if ( driver->GetCreationInformation( operationName, params ))
278         {
279           info[nbI].operationName = operationName.c_str();
280           info[nbI].params.length( params.size() );
281           for ( size_t i = 0; i < params.size(); ++i )
282           {
283             info[nbI].params[i].name  = params[i].name.c_str();
284             info[nbI].params[i].value = params[i].value.c_str();
285           }
286           nbI++;
287         }
288 #ifdef _DEBUG_
289         if ( operationName.empty() )
290         {
291           std::cout << std::endl << std::endl << std::endl << "Warning: " << std::endl << "Dear developer!!!" << std::endl
292                     << "  Consider implementing "
293                     <<    typeid(*(driver.operator->())).name() << "::GetCreationInformation() " << std::endl
294                     << "  for the case of operation which has created '" << GetName() << "' object" << std::endl
295                     << "PLEEEEEEEASE" << std::endl
296                     << "\tPLEEEEEEEASE" << std::endl
297                     << "\t\tPLEEEEEEEASE" << std::endl
298                     << "\t\t\tPLEEEEEEEASE" << std::endl
299                     << "\t\t\t\tPLEEEEEEEASE" << std::endl;
300         }
301 #endif
302       }
303       catch(...)
304       {
305 #ifdef _DEBUG_
306         std::cout << "Ecxeption in GEOM_BaseObject_i::GetCreationInformation()" << std::endl;
307 #endif
308       }
309     }
310   }
311   info->length( nbI );
312
313   return info._retn();
314 }
315
316 //================================================================================
317 /*!
318  * \brief Return the engine creating this object
319  */
320 //================================================================================
321
322 GEOM::GEOM_Gen_ptr GEOM_BaseObject_i::GetGen()
323 {
324   return GEOM::GEOM_Gen::_duplicate( _engine );
325 }