1 // Copyright (C) 2006-2014 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, or (at your option) any later version.
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 "SchemaDirContainersItem.hxx"
21 #include "SchemaContainerItem.hxx"
22 #include "SchemaModel.hxx"
23 #include "QtGuiContext.hxx"
24 #include "ComponentInstance.hxx"
25 #include "Container.hxx"
32 #include "YacsTrace.hxx"
35 using namespace YACS::ENGINE;
36 using namespace YACS::HMI;
38 SchemaDirContainersItem::SchemaDirContainersItem(SchemaItem *parent, QString label, Subject* subject)
39 : SchemaItem(parent, label, subject)
41 _itemDeco.replace(YLabel, QIcon("icons:folder_cyan.png"));
42 _schemaContItemMap.clear();
43 _waitingCompItemMap.clear();
46 void SchemaDirContainersItem::popupMenu(QWidget *caller, const QPoint &globalPos)
49 m.popupMenu(caller, globalPos);
54 /*! When loading a schema, a container may appear after a component using this container.
55 * After creating the SchemaContainerItem, check if there are SchemaComponentItems to
56 * to create as children of this SchemaContainerItem
58 void SchemaDirContainersItem::addContainerItem(Subject* subject)
60 DEBTRACE("SchemaDirContainersItem::addContainerItem");
61 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
62 int nbsons = childCount();
63 string contName = subject->getName();
65 model->beginInsertRows(modelIndex(), nbsons, nbsons);
66 SchemaContainerItem *item = new SchemaContainerItem(this,
69 model->endInsertRows();
71 _schemaContItemMap[contName] = item;
74 /*! If a component is not associated to a container, it will be associated to a default container.
75 * If this default container does not exist, it is created.
76 * When loading a schema, container must be created before component: @see SubjectProc::loadProc
78 void SchemaDirContainersItem::addComponentItem(Subject* subject)
80 DEBTRACE("SchemaDirContainersItem::addComponentItem");
81 SubjectComponent *aSComp = dynamic_cast<SubjectComponent*>(subject);
83 ComponentInstance* component = aSComp->getComponent();
86 string contName = "DefaultContainer";
87 Container *container = component->getContainer();
89 contName = container->getName();
92 if (!_schemaContItemMap.count(contName)) // no container and default container not created
94 SubjectProc* sProc = QtGuiContext::getQtCurrent()->getSubjectProc();
95 sProc->addContainer(contName);
99 YASSERT(_schemaContItemMap.count(contName));
100 SchemaContainerItem *sci = _schemaContItemMap[contName];
101 aSComp->associateToContainer(static_cast<SubjectContainer*>(sci->getSubject()));
104 QVariant SchemaDirContainersItem::editionWhatsThis(int column) const
106 return "<p>Containers used in this schema appears in this folder.\n" \
107 "You can add containers by using the context menu (entry \"Create container\") " \
108 "and then edit its properties in the input panel. <a href=\"modification.html#property-page-for-container\">More...</a></p>";