Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / genericgui / GuiObserver_i.cxx
1 //  Copyright (C) 2006-2008  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.
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 #include "GuiObserver_i.hxx"
20 #include "GuiExecutor.hxx"
21 #include "Proc.hxx"
22
23 #include <QApplication>
24 #include <cassert>
25
26 //#define _DEVDEBUG_
27 #include "YacsTrace.hxx"
28
29 using namespace std;
30 using namespace YACS::HMI;
31 using namespace YACS::ENGINE;
32
33 YACSEvent::YACSEvent(std::pair<int,std::string> aYACSEvent)
34   : QEvent(QEvent::User)
35 {
36   _event = aYACSEvent;
37 }
38
39
40 GuiObserver_i::GuiObserver_i(YACS::ENGINE::Proc* guiProc)
41 {
42   DEBTRACE("GuiObserver_i::GuiObserver_i");
43   _guiProc = guiProc;
44   _engineProc = YACS_ORB::ProcExec::_nil();
45   _impl = 0;
46   _guiToEngineMap.clear();
47   _engineToGuiMap.clear();
48 }
49
50 GuiObserver_i::~GuiObserver_i()
51 {
52   DEBTRACE("GuiObserver_i::~GuiObserver_i");
53 }
54
55 void GuiObserver_i::notifyObserver(CORBA::Long numid, const char* event)
56 {
57   DEBTRACE("GuiObserver_i::notifyObserver");
58   pair<int,string> myEvent(numid, event);
59   YACSEvent* evt = new YACSEvent(myEvent);
60   QApplication::postEvent(_impl, evt);  // Qt will delete it when done
61 }
62
63 void GuiObserver_i::setConversion()
64 {
65   DEBTRACE("GuiObserver_i::setConversion");
66   assert(!CORBA::is_nil(_engineProc));
67   YACS_ORB::stringArray_var engineNames;
68   YACS_ORB::longArray_var engineIds;
69   //DEBTRACE("---");
70   _engineProc->getIds(engineIds.out(), engineNames.out());
71   int iLength = engineIds->length();
72   int nLength = engineNames->length();
73   if (nLength < iLength) iLength = nLength;
74   for(int i=0; i<iLength; i++)
75     {
76       string aName = "";
77       aName = engineNames[i];
78       int iEng = engineIds[i];
79       DEBTRACE("--- " << aName << " " << iEng);
80       if (aName != "_root_")
81         {
82           int iGui = _guiProc->getChildByName(aName)->getNumId();
83           //DEBTRACE("---");
84           _guiToEngineMap[iGui] = iEng;
85           _engineToGuiMap[iEng] = iGui;
86         }
87       else
88         {
89           int iGui = _guiProc->getNumId();
90           _guiToEngineMap[iGui] = iEng;
91           _engineToGuiMap[iEng] = iGui;
92         }
93     }
94 }
95
96 void GuiObserver_i::SetImpl(GuiExecutor* impl)
97 {
98   DEBTRACE("GuiObserver_i::SetImpl");
99   _impl = impl;
100 }
101
102 void GuiObserver_i::SetRemoteProc(YACS_ORB::ProcExec_ptr engineProc)
103 {
104   DEBTRACE("GuiObserver_i::SetRemoteProc");
105   _engineProc = YACS_ORB::ProcExec::_duplicate(engineProc);
106 }
107