1 // Copyright (C) 2014-2021 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 for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
78 dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0)->findChild<QCheckBox*>());
79 if (aButton->isChecked())
80 anAttributeList->append(myConcealedResults[i]);
85 bool ModuleBase_WidgetConcealedObjects::restoreValueCustom()
87 FeaturePtr aBaseFeature;
90 anObject = ModuleBase_Tools::getObject(myFeature->attribute(myBaseShapeAttribute));
91 if (anObject.get() != NULL)
92 aBaseFeature = ModelAPI_Feature::feature(anObject);
94 if (myBaseFeature != aBaseFeature) {
95 myView->setRowCount(0);
96 myConcealedResults.clear();
97 myBaseFeature = aBaseFeature;
98 if (myBaseFeature.get()) {
99 std::list<std::shared_ptr<ModelAPI_Result> > aResults;
100 std::set<ResultBodyPtr> aParents;
101 ModelAPI_Tools::getConcealedResults(myBaseFeature, aResults);
102 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator anIt = aResults.begin(),
103 aLast = aResults.end();
104 for (; anIt != aLast; anIt++) {
105 ResultPtr aResult = *anIt;
106 if (myPickConcealedParents) {
107 // pick the parent result of the concealed object
108 ResultBodyPtr aRootParent = ModelAPI_Tools::bodyOwner(aResult, true);
110 if (aParents.find(aRootParent) == aParents.end()) {
111 aResult = aRootParent;
112 aParents.insert(aRootParent);
114 else // do not add parent compound once again
119 int aRowId = myView->rowCount();
121 myConcealedResults[aRowId] = aResult;
126 DataPtr aData = myFeature->data();
127 AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
128 for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
129 ResultPtr aResult = myConcealedResults[i];
131 dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0)->findChild<QCheckBox*>());
132 bool isChecked = anAttributeList->isInList(aResult);
134 bool aBlocked = aButton->blockSignals(true);
135 aButton->setChecked(isChecked);
136 aButton->blockSignals(aBlocked);
141 QList<QWidget*> ModuleBase_WidgetConcealedObjects::getControls() const
143 QList<QWidget*> result;
148 void ModuleBase_WidgetConcealedObjects::addViewRow(
149 const std::shared_ptr<ModelAPI_Result>& theResult)
151 int anId = myView->rowCount();
152 myView->setRowCount(anId+1);
154 QWidget* aVisibilityWdg = new QWidget(this);
155 QVBoxLayout* aVisibilityLay = new QVBoxLayout(aVisibilityWdg);
156 aVisibilityLay->setContentsMargins(2, 2, 2, 2);
157 QCheckBox* aVisibilityBtn = new QCheckBox(aVisibilityWdg);
158 aVisibilityLay->addWidget(aVisibilityBtn, 0, Qt::AlignHCenter);
159 connect(aVisibilityBtn, SIGNAL(toggled(bool)), this, SLOT(onItemToggled(bool)));
160 aVisibilityBtn->setChecked(false);
162 myView->setCellWidget(anId, 0, aVisibilityWdg);
163 myView->setItem(anId, 1,
164 new QTableWidgetItem(QString::fromStdWString(theResult->data()->name())));
167 myView->setColumnWidth(0, myView->verticalHeader()->defaultSectionSize());
168 myView->setColumnWidth(1, DEFAULT_NAME_COLUMN_WIDTH);
172 void ModuleBase_WidgetConcealedObjects::onItemToggled(bool /*theState*/)
174 emit valuesChanged();
175 updateObject(myFeature);