1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <ModuleBase_WidgetConcealedObjects.h>
21 #include <ModuleBase_Tools.h>
23 #include <ModelAPI_Result.h>
24 #include <ModelAPI_ResultBody.h>
25 #include <ModelAPI_AttributeReference.h>
26 #include <ModelAPI_AttributeRefList.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Validator.h>
29 #include <ModelAPI_Tools.h>
31 #include <Config_WidgetAPI.h>
33 #include <QGridLayout>
36 #include <QTableWidget>
37 #include <QHeaderView>
39 #include <QVBoxLayout>
43 const int DEFAULT_NAME_COLUMN_WIDTH = 200;
45 ModuleBase_WidgetConcealedObjects::ModuleBase_WidgetConcealedObjects(QWidget* theParent,
46 const Config_WidgetAPI* theData)
47 : ModuleBase_ModelWidget(theParent, theData)
49 myBaseShapeAttribute = theData->getProperty("base_shape_attribute");
50 std::string aPickParents = theData->getProperty("pick_concealed_parents");
51 std::transform(aPickParents.begin(), aPickParents.end(), aPickParents.begin(), ::tolower);
52 myPickConcealedParents = aPickParents == "1" || aPickParents == "true" || aPickParents == "yes";
54 QGridLayout* aMainLay = new QGridLayout(this);
55 ModuleBase_Tools::adjustMargins(aMainLay);
57 myView = new QTableWidget(this);
58 aMainLay->addWidget(myView);
60 myView->setColumnCount(2);
61 myView->horizontalHeader()->setVisible(false);
62 myView->verticalHeader()->setVisible(false);
65 ModuleBase_WidgetConcealedObjects::~ModuleBase_WidgetConcealedObjects()
69 bool ModuleBase_WidgetConcealedObjects::storeValueCustom()
73 DataPtr aData = myFeature->data();
74 AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
75 anAttributeList->clear();
76 int aSize1 = anAttributeList->size(false);
77 for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
79 dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0)->findChild<QCheckBox*>());
80 if (aButton->isChecked())
81 anAttributeList->append(myConcealedResults[i]);
83 int aSize = anAttributeList->size(false);
87 bool ModuleBase_WidgetConcealedObjects::restoreValueCustom()
89 FeaturePtr aBaseFeature;
92 anObject = ModuleBase_Tools::getObject(myFeature->attribute(myBaseShapeAttribute));
93 if (anObject.get() != NULL)
94 aBaseFeature = ModelAPI_Feature::feature(anObject);
96 if (myBaseFeature != aBaseFeature) {
97 myView->setRowCount(0);
98 myConcealedResults.clear();
99 myBaseFeature = aBaseFeature;
100 if (myBaseFeature.get()) {
101 std::list<std::shared_ptr<ModelAPI_Result> > aResults;
102 std::set<ResultBodyPtr> aParents;
103 ModelAPI_Tools::getConcealedResults(myBaseFeature, aResults);
104 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator anIt = aResults.begin(),
105 aLast = aResults.end();
106 for (; anIt != aLast; anIt++) {
107 ResultPtr aResult = *anIt;
108 if (myPickConcealedParents) {
109 // pick the parent result of the concealed object
110 ResultBodyPtr aRootParent = ModelAPI_Tools::bodyOwner(aResult, true);
112 if (aParents.find(aRootParent) == aParents.end()) {
113 aResult = aRootParent;
114 aParents.insert(aRootParent);
116 else // do not add parent compound once again
121 int aRowId = myView->rowCount();
123 myConcealedResults[aRowId] = aResult;
128 DataPtr aData = myFeature->data();
129 AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
130 int aSize = anAttributeList->size();
131 for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
132 ResultPtr aResult = myConcealedResults[i];
134 dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0)->findChild<QCheckBox*>());
135 bool isChecked = anAttributeList->isInList(aResult);
137 bool aBlocked = aButton->blockSignals(true);
138 aButton->setChecked(isChecked);
139 aButton->blockSignals(aBlocked);
144 QList<QWidget*> ModuleBase_WidgetConcealedObjects::getControls() const
146 QList<QWidget*> result;
151 void ModuleBase_WidgetConcealedObjects::addViewRow(
152 const std::shared_ptr<ModelAPI_Result>& theResult)
154 int anId = myView->rowCount();
155 myView->setRowCount(anId+1);
157 QWidget* aVisibilityWdg = new QWidget(this);
158 QVBoxLayout* aVisibilityLay = new QVBoxLayout(aVisibilityWdg);
159 aVisibilityLay->setContentsMargins(2, 2, 2, 2);
160 QCheckBox* aVisibilityBtn = new QCheckBox(aVisibilityWdg);
161 aVisibilityLay->addWidget(aVisibilityBtn, 0, Qt::AlignHCenter);
162 connect(aVisibilityBtn, SIGNAL(toggled(bool)), this, SLOT(onItemToggled(bool)));
163 aVisibilityBtn->setChecked(false);
165 myView->setCellWidget(anId, 0, aVisibilityWdg);
166 myView->setItem(anId, 1, new QTableWidgetItem(theResult->data()->name().c_str()));
169 myView->setColumnWidth(0, myView->verticalHeader()->defaultSectionSize());
170 myView->setColumnWidth(1, DEFAULT_NAME_COLUMN_WIDTH);
174 void ModuleBase_WidgetConcealedObjects::onItemToggled(bool theState)
176 emit valuesChanged();
177 updateObject(myFeature);