Salome HOME
Copyright update 2022
[modules/yacs.git] / src / genericgui / EditionContainer.cxx
1 // Copyright (C) 2006-2022  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 "EditionContainer.hxx"
21
22 //#define _DEVDEBUG_
23 #include "YacsTrace.hxx"
24
25 #include "FormContainerDecorator.hxx"
26 #include "QtGuiContext.hxx"
27 #include "guiObservers.hxx"
28 #include "Proc.hxx"
29 #include "Message.hxx"
30
31 #include <cassert>
32
33 using namespace std;
34
35 using namespace YACS;
36 using namespace YACS::HMI;
37 using namespace YACS::ENGINE;
38
39 EditionContainer::EditionContainer(Subject* subject, QWidget* parent, const char* name):ItemEdition(subject, parent, name)
40 {
41   _wContainer = new FormContainerDecorator(getContainer(),this);
42   _wid->gridLayout1->addWidget(_wContainer);
43   connect(_wContainer, SIGNAL(resourceMousePressed()), this, SLOT(fillContainerPanel()));
44   connect(_wContainer->tb_container, SIGNAL(toggled(bool)), this, SLOT(fillContainerPanel())); // --- to update display of current selection
45   _wContainer->tb_container->toggle();
46 }
47
48 EditionContainer::~EditionContainer()
49 {
50 }
51
52 void EditionContainer::update(GuiEvent event, int type, Subject* son)
53 {
54   DEBTRACE("EditionContainer::update");
55   ItemEdition::update(event, type, son);
56   switch (event)
57     {
58     case RENAME:
59     case UPDATE:
60       _wContainer->setName(son->getName());
61       fillContainerPanel();
62       break;
63     default:
64       ;
65     }
66 }
67
68 void EditionContainer::fillContainerPanel()
69 {
70   DEBTRACE("EditionContainer::fillContainerPanel");
71   _wContainer->FillPanel(getContainer());
72 }
73
74 void EditionContainer::onApply()
75 {
76   DEBTRACE("EditionContainer::onApply");
77   bool edited = true;
78   if (!_wContainer->onApply())
79     {
80       _isEdited = true;
81       Message mess(GuiContext::getCurrent()->_lastErrorMessage);
82       return;
83     }
84   edited = false;
85   _isEdited = _isEdited || edited;
86   ItemEdition::onApply();
87 }
88
89 void EditionContainer::onCancel()
90 {
91   DEBTRACE("EditionContainer::onCancel");
92   _wContainer->onCancel();
93   ItemEdition::onCancel();
94 }
95
96 YACS::ENGINE::Container *EditionContainer::getContainer()
97 {
98   SubjectContainerBase *scont(dynamic_cast<SubjectContainerBase*>(_subject));
99   YASSERT(scont);
100   return scont->getContainer();
101 }