Salome HOME
Task 2.4. Ability to modify the radius of circles and arcs of circle with the mouse
[modules/shaper.git] / src / ModuleBase / ModuleBase_IPropertyPanel.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * ModuleBase_IPropertyPanel.cpp
5  *
6  *  Created on: Oct 01, 2014
7  *      Author: vsv
8  */
9
10 #include "ModuleBase_IPropertyPanel.h"
11 #include "ModuleBase_ModelWidget.h"
12 #include "ModuleBase_ToolBox.h"
13
14 #include <ModelAPI_Validator.h>
15 #include <ModelAPI_Session.h>
16
17 ModuleBase_IPropertyPanel::ModuleBase_IPropertyPanel(QWidget* theParent)
18  : QDockWidget(theParent), myIsEditing(false)
19 {
20 }
21
22 ModuleBase_ModelWidget* ModuleBase_IPropertyPanel::modelWidget(
23                                           const std::string& theAttributeId) const
24 {
25   ModuleBase_ModelWidget* aWidget = 0;
26   QList<ModuleBase_ModelWidget*> aWidgets = modelWidgets();
27   ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
28   for (QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin();
29     anIt != aWidgets.end() && !aWidget; anIt++) {
30     ModuleBase_ModelWidget* aCurrentWidget = *anIt;
31     if (aCurrentWidget->attributeID() == theAttributeId &&
32         aCurrentWidget->canAcceptFocus() &&
33         aValidators->isCase(aCurrentWidget->feature(), aCurrentWidget->attributeID()))
34       aWidget = aCurrentWidget;
35   }
36
37   return aWidget;
38 }
39
40 ModuleBase_ModelWidget* ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget()
41 {
42   return ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget(modelWidgets());
43 }
44
45 ModuleBase_ModelWidget* ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget(
46                                         const QList<ModuleBase_ModelWidget*>& theWidgets)
47 {
48   ModuleBase_ModelWidget* aFirstWidget = 0;
49
50   ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
51
52   ModuleBase_ModelWidget* aWgt;
53   QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
54   bool isOffToolBox = false;
55   for (aWIt = theWidgets.begin(); aWIt != theWidgets.end() && !aFirstWidget; ++aWIt) {
56     aWgt = (*aWIt);
57     if (!aValidators->isCase(aWgt->feature(), aWgt->attributeID()))
58       continue; // this attribute is not participated in the current case
59
60     if (!aWgt->canAcceptFocus())
61       continue;
62
63     /// workaround for the same attributes used in different stacked widgets(attribute types)
64     if (ModuleBase_ToolBox::isOffToolBoxParent(aWgt))
65       continue;
66
67     aFirstWidget = aWgt;
68   }
69   return aFirstWidget;
70 }