Version: 8.3.0
SchemaDirContainersItem.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 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 
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 {
49  m.popupMenu(caller, globalPos);
50 }
51 
52 
53 
59 {
60  DEBTRACE("SchemaDirContainersItem::addContainerItem");
62  int nbsons = childCount();
63  string contName = subject->getName();
64 
65  model->beginInsertRows(modelIndex(), nbsons, nbsons);
67  contName.c_str(),
68  subject);
69  model->endInsertRows();
70 
71  _schemaContItemMap[contName] = item;
72 }
73 
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  {
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 
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 }