1 // Copyright (C) 2006-2008 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
19 #include "GuiObserver_i.hxx"
20 #include "GuiExecutor.hxx"
23 #include <QApplication>
27 #include "YacsTrace.hxx"
30 using namespace YACS::HMI;
31 using namespace YACS::ENGINE;
33 YACSEvent::YACSEvent(std::pair<int,std::string> aYACSEvent)
34 : QEvent(QEvent::User)
40 GuiObserver_i::GuiObserver_i(YACS::ENGINE::Proc* guiProc)
42 DEBTRACE("GuiObserver_i::GuiObserver_i");
44 _engineProc = YACS_ORB::ProcExec::_nil();
46 _guiToEngineMap.clear();
47 _engineToGuiMap.clear();
50 GuiObserver_i::~GuiObserver_i()
52 DEBTRACE("GuiObserver_i::~GuiObserver_i");
55 void GuiObserver_i::notifyObserver(CORBA::Long numid, const char* event)
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
63 void GuiObserver_i::setConversion()
65 DEBTRACE("GuiObserver_i::setConversion");
66 assert(!CORBA::is_nil(_engineProc));
67 YACS_ORB::stringArray_var engineNames;
68 YACS_ORB::longArray_var engineIds;
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++)
77 aName = engineNames[i];
78 int iEng = engineIds[i];
79 DEBTRACE("--- " << aName << " " << iEng);
80 if (aName != "_root_")
82 int iGui = _guiProc->getChildByName(aName)->getNumId();
84 _guiToEngineMap[iGui] = iEng;
85 _engineToGuiMap[iEng] = iGui;
89 int iGui = _guiProc->getNumId();
90 _guiToEngineMap[iGui] = iEng;
91 _engineToGuiMap[iEng] = iGui;
96 void GuiObserver_i::SetImpl(GuiExecutor* impl)
98 DEBTRACE("GuiObserver_i::SetImpl");
102 void GuiObserver_i::SetRemoteProc(YACS_ORB::ProcExec_ptr engineProc)
104 DEBTRACE("GuiObserver_i::SetRemoteProc");
105 _engineProc = YACS_ORB::ProcExec::_duplicate(engineProc);