1 // Copyright (C) 2006-2012 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GuiObserver_i.hxx"
21 #include "GuiExecutor.hxx"
24 #include <QApplication>
28 #include "YacsTrace.hxx"
31 using namespace YACS::HMI;
32 using namespace YACS::ENGINE;
34 YACSEvent::YACSEvent(std::pair<int,std::string> aYACSEvent)
35 : QEvent(QEvent::User)
41 GuiObserver_i::GuiObserver_i(YACS::ENGINE::Proc* guiProc)
43 DEBTRACE("GuiObserver_i::GuiObserver_i");
45 _engineProc = YACS_ORB::ProcExec::_nil();
47 _guiToEngineMap.clear();
48 _engineToGuiMap.clear();
51 GuiObserver_i::~GuiObserver_i()
53 DEBTRACE("GuiObserver_i::~GuiObserver_i");
56 void GuiObserver_i::notifyObserver(CORBA::Long numid, const char* event)
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
64 void GuiObserver_i::setConversion()
66 DEBTRACE("GuiObserver_i::setConversion");
67 YASSERT(!CORBA::is_nil(_engineProc));
68 YACS_ORB::stringArray_var engineNames;
69 YACS_ORB::longArray_var engineIds;
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++)
78 aName = engineNames[i];
79 int iEng = engineIds[i];
80 DEBTRACE("--- " << aName << " " << iEng);
81 if (aName != "_root_")
83 int iGui = _guiProc->getChildByName(aName)->getNumId();
85 _guiToEngineMap[iGui] = iEng;
86 _engineToGuiMap[iEng] = iGui;
90 int iGui = _guiProc->getNumId();
91 _guiToEngineMap[iGui] = iEng;
92 _engineToGuiMap[iEng] = iGui;
97 void GuiObserver_i::SetImpl(GuiExecutor* impl)
99 DEBTRACE("GuiObserver_i::SetImpl");
103 void GuiObserver_i::SetRemoteProc(YACS_ORB::ProcExec_ptr engineProc)
105 DEBTRACE("GuiObserver_i::SetRemoteProc");
106 _engineProc = YACS_ORB::ProcExec::_duplicate(engineProc);