]> SALOME platform Git repositories - modules/yacs.git/blob - src/genericgui/SchemaDirContainersItem.cxx
Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / genericgui / SchemaDirContainersItem.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 "SchemaDirContainersItem.hxx"
20 #include "SchemaContainerItem.hxx"
21 #include "SchemaModel.hxx"
22 #include "QtGuiContext.hxx"
23 #include "ComponentInstance.hxx"
24 #include "Container.hxx"
25
26 #include <QIcon>
27 #include <cassert>
28
29 //#define _DEVDEBUG_
30 #include "YacsTrace.hxx"
31
32 using namespace std;
33 using namespace YACS::ENGINE;
34 using namespace YACS::HMI;
35
36 SchemaDirContainersItem::SchemaDirContainersItem(SchemaItem *parent, QString label, Subject* subject)
37   : SchemaItem::SchemaItem(parent, label, subject)
38 {
39   _itemDeco.replace(YLabel, QIcon("icons:folder_cyan.png"));
40   _schemaContItemMap.clear();
41   _waitingCompItemMap.clear();
42 }
43
44 /*! When loading a schema, a container may appear after a component using this container.
45  *  After creating the SchemaContainerItem, check if there are SchemaComponentItems to
46  *  to create as children of this SchemaContainerItem
47  */
48 void SchemaDirContainersItem::addContainerItem(Subject* subject)
49 {
50   DEBTRACE("SchemaDirContainersItem::addContainerItem");
51   SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
52   int nbsons = childCount();
53   string contName = subject->getName();
54
55   model->beginInsertRows(modelIndex(), nbsons, nbsons);
56   SchemaContainerItem *item = new SchemaContainerItem(this,
57                                                       contName.c_str(),
58                                                       subject);
59   model->endInsertRows();
60
61   _schemaContItemMap[contName] = item;
62 }
63
64 /*! If a component is not associated to a container, it will be associated to a default container.
65  *  If this default container does not exist, it is created.
66  *  When loading a schema, container must be created before component: @see SubjectProc::loadProc
67  */
68 void SchemaDirContainersItem::addComponentItem(Subject* subject)
69 {
70   DEBTRACE("SchemaDirContainersItem::addComponentItem");
71   SubjectComponent *aSComp = dynamic_cast<SubjectComponent*>(subject);
72   assert(aSComp);
73   ComponentInstance* component = aSComp->getComponent();
74   assert(component);
75
76   string contName = "DefaultContainer";
77   Container *container = component->getContainer();
78   if (container)
79     contName = container->getName();
80   else
81     {
82       if (!_schemaContItemMap.count(contName)) // no container and default container not created
83         {
84           SubjectProc* sProc = QtGuiContext::getQtCurrent()->getSubjectProc();
85           sProc->addContainer(contName);
86         }
87     }
88
89   assert(_schemaContItemMap.count(contName));
90   SchemaContainerItem *sci = _schemaContItemMap[contName];
91   aSComp->associateToContainer(static_cast<SubjectContainer*>(sci->getSubject()));
92 }