Salome HOME
Updated copyright comment
[modules/yacs.git] / src / genericgui / SchemaDirContainersItem.cxx
1 // Copyright (C) 2006-2024  CEA, EDF
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 "SchemaDirContainersItem.hxx"
21 #include "SchemaContainerItem.hxx"
22 #include "SchemaModel.hxx"
23 #include "QtGuiContext.hxx"
24 #include "ComponentInstance.hxx"
25 #include "Container.hxx"
26 #include "Menus.hxx"
27
28 #include <QIcon>
29 #include <cassert>
30
31 //#define _DEVDEBUG_
32 #include "YacsTrace.hxx"
33
34 using namespace std;
35 using namespace YACS::ENGINE;
36 using namespace YACS::HMI;
37
38 SchemaDirContainersItem::SchemaDirContainersItem(SchemaItem *parent, QString label, Subject* subject)
39   : SchemaItem(parent, label, subject)
40 {
41   _itemDeco.replace(YLabel, QIcon("icons:folder_cyan.png"));
42   _schemaContItemMap.clear();
43   _waitingCompItemMap.clear();
44 }
45
46 void SchemaDirContainersItem::popupMenu(QWidget *caller, const QPoint &globalPos)
47 {
48   ContainerDirMenu m;
49   m.popupMenu(caller, globalPos);
50 }
51
52
53
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
57  */
58 void SchemaDirContainersItem::addContainerItem(Subject* subject)
59 {
60   DEBTRACE("SchemaDirContainersItem::addContainerItem");
61   SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
62   int nbsons = childCount();
63   string contName = subject->getName();
64
65   model->beginInsertRows(modelIndex(), nbsons, nbsons);
66   SchemaContainerItem *item = new SchemaContainerItem(this,
67                                                       contName.c_str(),
68                                                       subject);
69   model->endInsertRows();
70
71   _schemaContItemMap[contName] = item;
72 }
73
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
77  */
78 void SchemaDirContainersItem::addComponentItem(Subject* subject)
79 {
80   DEBTRACE("SchemaDirContainersItem::addComponentItem");
81   SubjectComponent *aSComp = dynamic_cast<SubjectComponent*>(subject);
82   YASSERT(aSComp);
83   ComponentInstance* component = aSComp->getComponent();
84   YASSERT(component);
85
86   string contName = "DefaultContainer";
87   Container *container = component->getContainer();
88   if (container)
89     contName = container->getName();
90   else
91     {
92       if (!_schemaContItemMap.count(contName)) // no container and default container not created
93         {
94           SubjectProc* sProc = QtGuiContext::getQtCurrent()->getSubjectProc();
95           sProc->addContainer(contName);
96         }
97     }
98
99   YASSERT(_schemaContItemMap.count(contName));
100   SchemaContainerItem *sci = _schemaContItemMap[contName];
101   aSComp->associateToContainer(static_cast<SubjectContainer*>(sci->getSubject()));
102 }
103
104 QVariant SchemaDirContainersItem::editionWhatsThis(int column) const
105 {
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>";
109 }