Salome HOME
c690274fe1e438427670cb68c136031992ca5f5c
[modules/yacs.git] / src / genericgui / VisitorSaveGuiSchema.cxx
1 // Copyright (C) 2006-2020  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 "VisitorSaveGuiSchema.hxx"
21 #include "Proc.hxx"
22 #include "QtGuiContext.hxx"
23 #include "guiObservers.hxx"
24 #include "SceneItem.hxx"
25 #include "SceneNodeItem.hxx"
26
27 #include <cassert>
28
29 //#define _DEVDEBUG_
30 #include "YacsTrace.hxx"
31
32 using namespace std;
33 using namespace YACS::HMI;
34 using namespace YACS::ENGINE;
35
36 VisitorSaveGuiSchema::VisitorSaveGuiSchema(YACS::ENGINE::Proc* proc)
37   : VisitorSaveSalomeSchema(proc), _proc(proc)
38 {
39   DEBTRACE("VisitorSaveGuiSchema::VisitorSaveGuiSchema");
40 }
41
42 VisitorSaveGuiSchema::~VisitorSaveGuiSchema()
43 {
44   DEBTRACE("VisitorSaveGuiSchema::~VisitorSaveGuiSchema");
45 }
46
47 void VisitorSaveGuiSchema::visitProc()
48 {
49   DEBTRACE("VisitorSaveGuiSchema::visitProc");
50   VisitorSaveSalomeSchema::visitProc(_proc);
51   writePresentation();
52 }
53
54 void VisitorSaveGuiSchema::writePresentation()
55 {
56   DEBTRACE("VisitorSaveGuiSchema::writePresentation");
57   set<Node*> nodeSet = getAllNodes(_proc);
58
59   for (set<Node*>::iterator iter = nodeSet.begin(); iter != nodeSet.end(); ++iter)
60   {
61     Node* node = *iter;
62     SubjectNode * snode = QtGuiContext::getQtCurrent()->_mapOfSubjectNode[node];
63     SceneItem* item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[snode];
64     YASSERT(item);
65     SceneNodeItem* inode = dynamic_cast<SceneNodeItem*>(item);
66     YASSERT(inode);
67     writeItem(_proc->getChildName(node), inode);
68   }
69
70   SubjectNode * sproc = QtGuiContext::getQtCurrent()->getSubjectProc();
71   SceneItem* item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sproc];
72   YASSERT(item);
73   SceneNodeItem* inode = dynamic_cast<SceneNodeItem*>(item);
74   YASSERT(inode);
75   writeItem("__ROOT__", inode);
76 }
77
78  void VisitorSaveGuiSchema::writeItem(std::string name, SceneNodeItem* item)
79 {
80   int depth = 1;
81   _out << indent(depth) << "<presentation";
82   _out                  << " name=\""       << name                      << "\"";
83   _out                  << " x=\""          << item->x()                 << "\"";
84   _out                  << " y=\""          << item->y()                 << "\"";
85   _out                  << " width=\""      << item->getWidth()          << "\"";
86   _out                  << " height=\""     << item->getHeight()         << "\"";
87   _out                  << " expanded=\""   << item->isExpanded()        << "\"";
88   _out                  << " expx=\""       << item->getExpandedX()      << "\"";
89   _out                  << " expy=\""       << item->getExpandedY()      << "\"";
90   _out                  << " expWidth=\""   << item->getExpandedWidth()  << "\"";
91   _out                  << " expHeight=\""  << item->getExpandedHeight() << "\"";
92   _out                  << " shownState=\"" << item->getShownState()     << "\"";
93   _out                  << "/>" << endl;
94 }