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_IOperations_i.hh"
25 #include "GEOM_Engine.hxx"
26 #include "GEOM_Gen_i.hh"
27 #include <SALOME_NamingService.hxx>
29 #include "utilities.h"
31 #include "Utils_ExceptHandlers.hxx"
33 #include <Standard_Stream.hxx>
34 #include <TCollection_AsciiString.hxx>
35 #include <TDF_Tool.hxx>
37 #include CORBA_SERVER_HEADER(SALOME_Session)
39 //=============================================================================
41 * default constructor:
43 //=============================================================================
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)
50 //=============================================================================
54 //=============================================================================
56 GEOM_IOperations_i::~GEOM_IOperations_i()
60 //=============================================================================
64 //=============================================================================
65 CORBA::Boolean GEOM_IOperations_i::IsDone()
67 return _impl->IsDone();
71 //=============================================================================
75 //=============================================================================
76 void GEOM_IOperations_i::SetErrorCode(const char* theErrorCode)
78 _impl->SetErrorCode((char*)theErrorCode);
81 //=============================================================================
85 //=============================================================================
86 char* GEOM_IOperations_i::GetErrorCode()
88 return CORBA::string_dup(_impl->GetErrorCode());
91 //=============================================================================
95 //=============================================================================
96 CORBA::Long GEOM_IOperations_i::GetStudyID()
98 return _impl->GetDocID();
101 //=============================================================================
105 //=============================================================================
106 void GEOM_IOperations_i::StartOperation()
108 _impl->StartOperation();
111 //=============================================================================
115 //=============================================================================
116 void GEOM_IOperations_i::FinishOperation()
118 _impl->FinishOperation();
122 //=============================================================================
126 //=============================================================================
127 void GEOM_IOperations_i::AbortOperation()
129 _impl->AbortOperation();
132 //=============================================================================
136 //=============================================================================
137 GEOM::GEOM_BaseObject_ptr
138 GEOM_IOperations_i::GetBaseObject(HANDLE_NAMESPACE(GEOM_BaseObject) theObject)
140 GEOM::GEOM_BaseObject_var GO;
141 if (theObject.IsNull()) return GO._retn();
142 TCollection_AsciiString anEntry;
143 TDF_Tool::Entry(theObject->GetEntry(), anEntry);
144 GO = _engine->GetObject(theObject->GetDocID(), (char*) anEntry.ToCString());
148 //=============================================================================
152 //=============================================================================
153 HANDLE_NAMESPACE(GEOM_BaseObject)
154 GEOM_IOperations_i::GetBaseObjectImpl(GEOM::GEOM_BaseObject_ptr theObject)
156 HANDLE_NAMESPACE(GEOM_BaseObject) anImpl;
157 if (!CORBA::is_nil(theObject)) {
158 CORBA::String_var anEntry = theObject->GetEntry();
159 anImpl = GetImpl()->GetEngine()->GetObject( theObject->GetStudyID(), anEntry );
164 //=============================================================================
168 //=============================================================================
169 GEOM::GEOM_Object_ptr GEOM_IOperations_i::GetObject(HANDLE_NAMESPACE(GEOM_Object) theObject)
171 return GEOM::GEOM_Object::_narrow( GetBaseObject( theObject ));
174 //=============================================================================
178 //=============================================================================
179 HANDLE_NAMESPACE(GEOM_Object) GEOM_IOperations_i::GetObjectImpl(GEOM::GEOM_Object_ptr theObject)
181 return HANDLE_NAMESPACE(GEOM_Object)::DownCast( GetBaseObjectImpl( theObject ));
184 //=============================================================================
186 * GetListOfObjectsImpl
188 //=============================================================================
189 Handle(TColStd_HSequenceOfTransient) GEOM_IOperations_i::GetListOfObjectsImpl
190 (const GEOM::ListOfGO& theObjects)
192 Handle(TColStd_HSequenceOfTransient) aResult =
193 new TColStd_HSequenceOfTransient;
196 int aNbObj = theObjects.length();
198 for (i = 0; i < aNbObj; i++) {
199 HANDLE_NAMESPACE(GEOM_Object) anObj = GetObjectImpl(theObjects[i]);
201 if (anObj.IsNull()) {
206 aResult->Append(anObj);
212 //=======================================================================
213 //function : GetListOfObjectsImpl
215 //=======================================================================
217 bool GEOM_IOperations_i::GetListOfObjectsImpl(const GEOM::ListOfGO& theObjects,
218 std::list< HANDLE_NAMESPACE(GEOM_Object) >& theList)
221 int aNbObj = theObjects.length();
223 for (i = 0; i < aNbObj; i++) {
224 HANDLE_NAMESPACE(GEOM_Object) anObj = GetObjectImpl(theObjects[i]);
229 theList.push_back(anObj);
235 //=============================================================================
239 //=============================================================================
240 void GEOM_IOperations_i::UpdateGUIForObject(GEOM::GEOM_Object_ptr theObj)
242 if (!CORBA::is_nil (theObj)) {
243 // Cast _engine to GEOM_Gen_i type.
244 PortableServer::Servant aServant = myPOA->reference_to_servant(_engine.in());
245 GEOM_Gen_i *anEngine = dynamic_cast<GEOM_Gen_i *>(aServant);
248 SALOME_NamingService *aNameService = anEngine->GetNS();
249 CORBA::Object_var aSessionObj = aNameService->Resolve("/Kernel/Session");
250 SALOME::Session_var aSession = SALOME::Session::_narrow(aSessionObj);
252 if (!aSession->_is_nil())
254 std::string aMsg("GEOM/modified/");
255 CORBA::String_var anIOR = anEngine->GetORB()->object_to_string(theObj);
258 aSession->emitMessageOneWay(aMsg.c_str());
264 //=============================================================================
268 //=============================================================================
269 Handle(TColStd_HArray1OfExtendedString) GEOM_IOperations_i::ConvertStringArray
270 (const GEOM::string_array &theInArray)
272 Handle(TColStd_HArray1OfExtendedString) anOutArray;
273 const int n = theInArray.length();
280 anOutArray = new TColStd_HArray1OfExtendedString( 1, n );
282 for (i = 0; i < n; i++) {
283 anOutArray->SetValue(i + 1, TCollection_ExtendedString(theInArray[i].in()));