Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / genericgui / VisitorSaveGuiSchema.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 "VisitorSaveGuiSchema.hxx"
20 #include "Proc.hxx"
21 #include "QtGuiContext.hxx"
22 #include "guiObservers.hxx"
23 #include "SceneItem.hxx"
24
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 VisitorSaveGuiSchema::VisitorSaveGuiSchema(YACS::ENGINE::Proc* proc)
35   : VisitorSaveSalomeSchema(proc), _proc(proc)
36 {
37   DEBTRACE("VisitorSaveGuiSchema::VisitorSaveGuiSchema");
38 }
39
40 VisitorSaveGuiSchema::~VisitorSaveGuiSchema()
41 {
42   DEBTRACE("VisitorSaveGuiSchema::~VisitorSaveGuiSchema");
43 }
44
45 void VisitorSaveGuiSchema::visitProc()
46 {
47   DEBTRACE("VisitorSaveGuiSchema::visitProc");
48   VisitorSaveSalomeSchema::visitProc(_proc);
49   writePresentation();
50 }
51
52 void VisitorSaveGuiSchema::writePresentation()
53 {
54   DEBTRACE("VisitorSaveGuiSchema::writePresentation");
55   set<Node*> nodeSet = getAllNodes(_proc);
56
57   for (set<Node*>::iterator iter = nodeSet.begin(); iter != nodeSet.end(); ++iter)
58   {
59     Node* node = *iter;
60     SubjectNode * snode = QtGuiContext::getQtCurrent()->_mapOfSubjectNode[node];
61     SceneItem* item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[snode];
62     assert(item);
63     writeItem(_proc->getChildName(node), item);
64   }
65
66   SubjectNode * sproc = QtGuiContext::getQtCurrent()->getSubjectProc();
67   SceneItem* item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sproc];
68   assert(item);
69   writeItem("__ROOT__", item);
70 }
71
72  void VisitorSaveGuiSchema::writeItem(std::string name, SceneItem* item)
73 {
74   int depth = 1;
75   _out << indent(depth) << "<presentation";
76   _out                  << " name=\""  << name               << "\"";
77   _out                  << " x=\""     << item->x()          << "\"";
78   _out                  << " y=\""     << item->y()          << "\"";
79   _out                  << " width=\"" << item->getWidth()   << "\"";
80   _out                  << " height=\""<< item->getHeight()  << "\"";
81   _out                  << "/>" << endl;
82 }