Version: 8.3.0
GuiObserver_i.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #include "GuiObserver_i.hxx"
21 #include "GuiExecutor.hxx"
22 #include "Proc.hxx"
23 
24 #include <QApplication>
25 #include <cassert>
26 
27 //#define _DEVDEBUG_
28 #include "YacsTrace.hxx"
29 
30 using namespace std;
31 using namespace YACS::HMI;
32 using namespace YACS::ENGINE;
33 
34 YACSEvent::YACSEvent(std::pair<int,std::string> aYACSEvent)
35  : QEvent(QEvent::User)
36 {
37  _event = aYACSEvent;
38 }
39 
40 
42 {
43  DEBTRACE("GuiObserver_i::GuiObserver_i");
44  _guiProc = guiProc;
45  _engineProc = YACS_ORB::ProcExec::_nil();
46  _impl = 0;
47  _guiToEngineMap.clear();
48  _engineToGuiMap.clear();
49 }
50 
52 {
53  DEBTRACE("GuiObserver_i::~GuiObserver_i");
54 }
55 
56 void GuiObserver_i::notifyObserver(CORBA::Long numid, const char* event)
57 {
58  DEBTRACE("GuiObserver_i::notifyObserver " << numid << " " << event);
59  pair<int,string> myEvent(numid, event);
60  YACSEvent* evt = new YACSEvent(myEvent);
61  QApplication::postEvent(_impl, evt); // Qt will delete it when done
62 }
63 
65 {
66  DEBTRACE("GuiObserver_i::setConversion");
67  YASSERT(!CORBA::is_nil(_engineProc));
68  YACS_ORB::stringArray_var engineNames;
69  YACS_ORB::longArray_var engineIds;
70  //DEBTRACE("---");
71  _engineProc->getIds(engineIds.out(), engineNames.out());
72  int iLength = engineIds->length();
73  int nLength = engineNames->length();
74  if (nLength < iLength) iLength = nLength;
75  for(int i=0; i<iLength; i++)
76  {
77  string aName = "";
78  aName = engineNames[i];
79  int iEng = engineIds[i];
80  DEBTRACE("--- " << aName << " " << iEng);
81  if (aName != "_root_")
82  {
83  int iGui = _guiProc->getChildByName(aName)->getNumId();
84  //DEBTRACE("---");
85  _guiToEngineMap[iGui] = iEng;
86  _engineToGuiMap[iEng] = iGui;
87  }
88  else
89  {
90  int iGui = _guiProc->getNumId();
91  _guiToEngineMap[iGui] = iEng;
92  _engineToGuiMap[iEng] = iGui;
93  }
94  }
95 }
96 
98 {
99  DEBTRACE("GuiObserver_i::SetImpl");
100  _impl = impl;
101 }
102 
103 void GuiObserver_i::SetRemoteProc(YACS_ORB::ProcExec_ptr engineProc)
104 {
105  DEBTRACE("GuiObserver_i::SetRemoteProc");
106  _engineProc = YACS_ORB::ProcExec::_duplicate(engineProc);
107 }
108