Salome HOME
ec700c49573edbee4c5ecba1519443c8aaa5f60f
[modules/geom.git] / src / GEOM_I / GEOM_IOperations_i.cc
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, 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_IOperations_i.hh"
24
25 #include "GEOM_Engine.hxx"
26 #include "GEOM_Gen_Session_i.hh"
27 #include <SALOME_NamingService.hxx>
28
29 #include "utilities.h"
30 #include "OpUtil.hxx"
31 #include "Utils_ExceptHandlers.hxx"
32
33 #include <Standard_Stream.hxx>
34 #include <TCollection_AsciiString.hxx>
35 #include <TDF_Tool.hxx>
36
37 #include CORBA_SERVER_HEADER(SALOME_Session)
38
39 //=============================================================================
40 /*!
41  *  default constructor:
42  */
43 //=============================================================================
44
45 GEOM_IOperations_i::GEOM_IOperations_i(PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine, ::GEOM_IOperations* theImpl)
46 :SALOME::GenericObj_i( thePOA ), _impl(theImpl), _engine(theEngine)
47 {
48 }
49
50 //=============================================================================
51 /*!
52  *  destructor
53  */
54 //=============================================================================
55
56 GEOM_IOperations_i::~GEOM_IOperations_i()
57 {}
58
59
60 //=============================================================================
61 /*!
62  *  IsDone
63  */
64 //=============================================================================
65 CORBA::Boolean GEOM_IOperations_i::IsDone()
66 {
67   return _impl->IsDone();
68 }
69
70
71 //=============================================================================
72 /*!
73  *  SetErrorCode
74  */
75 //=============================================================================
76 void GEOM_IOperations_i::SetErrorCode(const char* theErrorCode)
77 {
78   _impl->SetErrorCode((char*)theErrorCode);
79 }
80
81 //=============================================================================
82 /*!
83  *  GetErrorCode
84  */
85 //=============================================================================
86 char* GEOM_IOperations_i::GetErrorCode()
87 {
88   return CORBA::string_dup(_impl->GetErrorCode());
89 }
90
91 //=============================================================================
92 /*!
93  *  StartOperation
94  */
95 //=============================================================================
96 void GEOM_IOperations_i::StartOperation()
97 {
98   _impl->StartOperation();
99 }
100
101 //=============================================================================
102 /*!
103  *  FinishOperation
104  */
105 //=============================================================================
106 void GEOM_IOperations_i::FinishOperation()
107 {
108   _impl->FinishOperation();
109 }
110
111
112 //=============================================================================
113 /*!
114  *  AbortOperation
115  */
116 //=============================================================================
117 void GEOM_IOperations_i::AbortOperation()
118 {
119   _impl->AbortOperation();
120 }
121
122 //=============================================================================
123 /*!
124  *  GetObject
125  */
126 //=============================================================================
127 GEOM::GEOM_BaseObject_ptr
128 GEOM_IOperations_i::GetBaseObject(Handle(::GEOM_BaseObject) theObject)
129 {
130   GEOM::GEOM_BaseObject_var GO;
131   if (theObject.IsNull()) return GO._retn();
132   TCollection_AsciiString anEntry;
133   TDF_Tool::Entry(theObject->GetEntry(), anEntry);
134   GO = _engine->GetObject((char*) anEntry.ToCString());
135   return GO._retn();
136 }
137
138 //=============================================================================
139 /*!
140  *  GetObjectImpl
141  */
142 //=============================================================================
143 Handle(::GEOM_BaseObject)
144 GEOM_IOperations_i::GetBaseObjectImpl(GEOM::GEOM_BaseObject_ptr theObject)
145 {
146   Handle(::GEOM_BaseObject) anImpl;
147   if (!CORBA::is_nil(theObject)) {
148     CORBA::String_var anEntry = theObject->GetEntry();
149     anImpl = GetImpl()->GetEngine()->GetObject( anEntry );
150   }
151   return anImpl;
152 }
153
154 //=============================================================================
155 /*!
156  *  GetObject
157  */
158 //=============================================================================
159 GEOM::GEOM_Object_ptr GEOM_IOperations_i::GetObject(Handle(::GEOM_Object) theObject)
160 {
161   return GEOM::GEOM_Object::_narrow( GetBaseObject( theObject ));
162 }
163
164 //=============================================================================
165 /*!
166  *  GetObjectImpl
167  */
168 //=============================================================================
169 Handle(::GEOM_Object) GEOM_IOperations_i::GetObjectImpl(GEOM::GEOM_Object_ptr theObject)
170 {
171   return Handle(::GEOM_Object)::DownCast( GetBaseObjectImpl( theObject ));
172 }
173
174 //=============================================================================
175 /*!
176  *  GetListOfObjectsImpl
177  */
178 //=============================================================================
179 Handle(TColStd_HSequenceOfTransient) GEOM_IOperations_i::GetListOfObjectsImpl
180               (const GEOM::ListOfGO& theObjects)
181 {
182   Handle(TColStd_HSequenceOfTransient) aResult =
183     new TColStd_HSequenceOfTransient;
184
185   int i;
186   int aNbObj = theObjects.length();
187
188   for (i = 0; i < aNbObj; i++) {
189     Handle(::GEOM_Object) anObj = GetObjectImpl(theObjects[i]);
190
191     if (anObj.IsNull()) {
192       aResult.Nullify();
193       break;
194     }
195
196     aResult->Append(anObj);
197   }
198
199   return aResult;
200 }
201
202 //=======================================================================
203 //function : GetListOfObjectsImpl
204 //purpose  : 
205 //=======================================================================
206
207 bool GEOM_IOperations_i::GetListOfObjectsImpl(const GEOM::ListOfGO&             theObjects,
208                                               std::list< Handle(::GEOM_Object) >& theList)
209 {
210   int i;
211   int aNbObj = theObjects.length();
212
213   for (i = 0; i < aNbObj; i++) {
214     Handle(::GEOM_Object) anObj = GetObjectImpl(theObjects[i]);
215
216     if (anObj.IsNull())
217       return false;
218
219     theList.push_back(anObj);
220   }
221
222   return true;
223 }
224
225 //=============================================================================
226 /*!
227  *  UpdateGUIForObject
228  */
229 //=============================================================================
230 void GEOM_IOperations_i::UpdateGUIForObject(GEOM::GEOM_Object_ptr theObj)
231 {
232   if (!CORBA::is_nil (theObj)) {
233     // Cast _engine to GEOM_Gen_i type.
234     PortableServer::Servant aServant = myPOA->reference_to_servant(_engine.in());
235     GEOM_Gen_Session_i *anEngine = dynamic_cast<GEOM_Gen_Session_i *>(aServant);
236
237     if (anEngine) {
238       SALOME_NamingService *aNameService = anEngine->GetNS();
239       CORBA::Object_var aSessionObj = aNameService->Resolve("/Kernel/Session");
240       SALOME::Session_var aSession = SALOME::Session::_narrow(aSessionObj);
241   
242       if (!aSession->_is_nil())
243       {
244         std::string aMsg("GEOM/modified/");
245         CORBA::String_var anIOR = anEngine->GetORB()->object_to_string(theObj);
246   
247         aMsg += anIOR.in();
248         aSession->emitMessageOneWay(aMsg.c_str());
249       }
250     }
251   }
252 }
253
254 //=============================================================================
255 /*!
256  *  ConvertStringArray
257  */
258 //=============================================================================
259 Handle(TColStd_HArray1OfExtendedString) GEOM_IOperations_i::ConvertStringArray
260         (const GEOM::string_array &theInArray)
261 {
262   Handle(TColStd_HArray1OfExtendedString) anOutArray;
263   const int                               n = theInArray.length();
264   int                                     i;
265
266   if (n <= 0) {
267     return anOutArray;
268   }
269
270   anOutArray = new TColStd_HArray1OfExtendedString( 1, n );
271
272   for (i = 0; i < n; i++) {
273     anOutArray->SetValue(i + 1, TCollection_ExtendedString(theInArray[i].in()));
274   }
275
276   return anOutArray;
277 }