]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_IPropertyPanel.cpp
Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ModuleBase / ModuleBase_IPropertyPanel.cpp
1 // Copyright (C) 2014-2017  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<mailto:webmaster.salome@opencascade.com>
18 //
19
20 /*
21  * ModuleBase_IPropertyPanel.cpp
22  *
23  *  Created on: Oct 01, 2014
24  *      Author: vsv
25  */
26
27 #include "ModuleBase_IPropertyPanel.h"
28 #include "ModuleBase_ModelWidget.h"
29 #include "ModuleBase_ToolBox.h"
30
31 #include <ModelAPI_Validator.h>
32 #include <ModelAPI_Session.h>
33
34 ModuleBase_IPropertyPanel::ModuleBase_IPropertyPanel(QWidget* theParent)
35  : QDockWidget(theParent), myIsEditing(false)
36 {
37 }
38
39 ModuleBase_ModelWidget* ModuleBase_IPropertyPanel::modelWidget(
40                                           const std::string& theAttributeId) const
41 {
42   ModuleBase_ModelWidget* aWidget = 0;
43   QList<ModuleBase_ModelWidget*> aWidgets = modelWidgets();
44   ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
45   for (QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin();
46     anIt != aWidgets.end() && !aWidget; anIt++) {
47     ModuleBase_ModelWidget* aCurrentWidget = *anIt;
48     if (aCurrentWidget->attributeID() == theAttributeId &&
49         aCurrentWidget->canAcceptFocus() &&
50         aValidators->isCase(aCurrentWidget->feature(), aCurrentWidget->attributeID()))
51       aWidget = aCurrentWidget;
52   }
53
54   return aWidget;
55 }
56
57 ModuleBase_ModelWidget* ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget()
58 {
59   return ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget(modelWidgets());
60 }
61
62 ModuleBase_ModelWidget* ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget(
63                                         const QList<ModuleBase_ModelWidget*>& theWidgets)
64 {
65   ModuleBase_ModelWidget* aFirstWidget = 0;
66
67   ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
68
69   ModuleBase_ModelWidget* aWgt;
70   QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
71   bool isOffToolBox = false;
72   for (aWIt = theWidgets.begin(); aWIt != theWidgets.end() && !aFirstWidget; ++aWIt) {
73     aWgt = (*aWIt);
74     if (!aValidators->isCase(aWgt->feature(), aWgt->attributeID()))
75       continue; // this attribute is not participated in the current case
76
77     if (!aWgt->canAcceptFocus())
78       continue;
79
80     /// workaround for the same attributes used in different stacked widgets(attribute types)
81     if (ModuleBase_ToolBox::isOffToolBoxParent(aWgt))
82       continue;
83
84     aFirstWidget = aWgt;
85   }
86   return aFirstWidget;
87 }