Salome HOME
WIN32 compilation.
[modules/geom.git] / src / GEOM_I / GEOM_IOperations_i.cc
1 // Copyright (C) 2007-2013  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.
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_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  *  GetStudyID
94  */
95 //=============================================================================
96 CORBA::Long GEOM_IOperations_i::GetStudyID()
97 {
98   return _impl->GetDocID();
99 }
100
101 //=============================================================================
102 /*!
103  *  StartOperation
104  */
105 //=============================================================================
106 void GEOM_IOperations_i::StartOperation()
107 {
108   _impl->StartOperation();
109 }
110
111 //=============================================================================
112 /*!
113  *  FinishOperation
114  */
115 //=============================================================================
116 void GEOM_IOperations_i::FinishOperation()
117 {
118   _impl->FinishOperation();
119 }
120
121
122 //=============================================================================
123 /*!
124  *  AbortOperation
125  */
126 //=============================================================================
127 void GEOM_IOperations_i::AbortOperation()
128 {
129   _impl->AbortOperation();
130 }
131
132 //=============================================================================
133 /*!
134  *  GetObject
135  */
136 //=============================================================================
137 GEOM::GEOM_Object_ptr GEOM_IOperations_i::GetObject(Handle(GEOM_Object) theObject)
138 {
139   GEOM::GEOM_Object_var GO;
140   if (theObject.IsNull()) return GO._retn();
141   TCollection_AsciiString anEntry;
142   TDF_Tool::Entry(theObject->GetEntry(), anEntry);
143   GO = _engine->GetObject(theObject->GetDocID(), (char*) anEntry.ToCString());
144   return GO._retn();
145 }
146
147 //=============================================================================
148 /*!
149  *  GetObjectImpl
150  */
151 //=============================================================================
152 Handle(GEOM_Object) GEOM_IOperations_i::GetObjectImpl(GEOM::GEOM_Object_ptr theObject)
153 {
154   Handle(GEOM_Object) anImpl;
155   if (!CORBA::is_nil(theObject)) {
156     CORBA::String_var anEntry = theObject->GetEntry();
157     anImpl = GetImpl()->GetEngine()->GetObject
158       (theObject->GetStudyID(), anEntry);
159   }
160   return anImpl;
161 }
162
163 //=============================================================================
164 /*!
165  *  GetListOfObjectsImpl
166  */
167 //=============================================================================
168 Handle(TColStd_HSequenceOfTransient) GEOM_IOperations_i::GetListOfObjectsImpl
169               (const GEOM::ListOfGO& theObjects)
170 {
171   Handle(TColStd_HSequenceOfTransient) aResult =
172     new TColStd_HSequenceOfTransient;
173
174   int i;
175   int aNbObj = theObjects.length();
176
177   for (i = 0; i < aNbObj; i++) {
178     Handle(GEOM_Object) anObj = GetObjectImpl(theObjects[i]);
179
180     if (anObj.IsNull()) {
181       aResult.Nullify();
182       break;
183     }
184
185     aResult->Append(anObj);
186   }
187
188   return aResult;
189 }
190
191 //=============================================================================
192 /*!
193  *  UpdateGUIForObject
194  */
195 //=============================================================================
196 void GEOM_IOperations_i::UpdateGUIForObject(GEOM::GEOM_Object_ptr theObj)
197 {
198   if (!CORBA::is_nil (theObj)) {
199     // Cast _engine to GEOM_Gen_i type.
200     PortableServer::Servant aServant = myPOA->reference_to_servant(_engine.in());
201     GEOM_Gen_i *anEngine = dynamic_cast<GEOM_Gen_i *>(aServant);
202
203     if (anEngine) {
204       SALOME_NamingService *aNameService = anEngine->GetNS();
205       CORBA::Object_var aSessionObj = aNameService->Resolve("/Kernel/Session");
206       SALOME::Session_var aSession = SALOME::Session::_narrow(aSessionObj);
207   
208       if (!aSession->_is_nil())
209       {
210         std::string aMsg("GEOM/modified/");
211         CORBA::String_var anIOR = anEngine->GetORB()->object_to_string(theObj);
212   
213         aMsg += anIOR.in();
214         aSession->emitMessageOneWay(aMsg.c_str());
215       }
216     }
217   }
218 }