1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetShapeSelector.cpp
4 // Created: 2 June 2014
5 // Author: Vitaly Smetannikov
7 #include <ModuleBase_WidgetShapeSelector.h>
8 #include <ModuleBase_Definitions.h>
9 #include <ModuleBase_ISelection.h>
10 #include <ModuleBase_IWorkshop.h>
11 #include <ModuleBase_IViewer.h>
12 #include <ModuleBase_Tools.h>
13 #include <ModuleBase_FilterFactory.h>
14 #include <ModuleBase_Filter.h>
15 #include <ModuleBase_IModule.h>
16 #include <ModuleBase_ViewerPrs.h>
17 #include <ModuleBase_IconFactory.h>
19 #include <Config_WidgetAPI.h>
20 #include <Events_Loop.h>
21 #include <Events_Message.h>
22 #include <GeomAPI_Interface.h>
23 #include <GeomAPI_Shape.h>
25 #include <ModelAPI_AttributeReference.h>
26 #include <ModelAPI_Data.h>
27 #include <ModelAPI_Document.h>
28 #include <ModelAPI_Events.h>
29 #include <ModelAPI_Feature.h>
30 #include <ModelAPI_Result.h>
31 #include <ModelAPI_ResultConstruction.h>
32 #include <ModelAPI_AttributeReference.h>
33 #include <ModelAPI_AttributeSelection.h>
34 #include <ModelAPI_Session.h>
35 #include <ModelAPI_Tools.h>
36 #include <ModelAPI_ResultBody.h>
37 #include <ModelAPI_AttributeRefAttr.h>
38 #include <ModelAPI_Validator.h>
39 #include <ModelAPI_AttributeValidator.h>
41 #include <Config_WidgetAPI.h>
42 #include <Events_Error.h>
44 #include <GeomAPI_Shape.h>
46 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
47 #include <TopoDS_Shape.hxx>
48 #include <TopExp_Explorer.hxx>
54 #include <QToolButton>
57 #include <QDockWidget>
58 #include <QApplication>
59 #include <QFormLayout>
61 #include <TopExp_Explorer.hxx>
62 #include <TopoDS_Shape.hxx>
69 ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent,
70 ModuleBase_IWorkshop* theWorkshop,
71 const Config_WidgetAPI* theData)
72 : ModuleBase_WidgetSelector(theParent, theWorkshop, theData)
74 QFormLayout* aLayout = new QFormLayout(this);
75 ModuleBase_Tools::adjustMargins(aLayout);
77 QString aLabelText = QString::fromStdString(theData->widgetLabel());
78 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
79 myLabel = new QLabel(aLabelText, this);
80 if (!aLabelIcon.isEmpty())
81 myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
84 QString aToolTip = QString::fromStdString(theData->widgetTooltip());
85 myTextLine = new QLineEdit(this);
86 QString anObjName = QString::fromStdString(attributeID());
87 myTextLine->setObjectName(anObjName);
88 myTextLine->setReadOnly(true);
89 myTextLine->setToolTip(aToolTip);
90 myTextLine->installEventFilter(this);
92 aLayout->addRow(myLabel, myTextLine);
93 myLabel->setToolTip(aToolTip);
95 std::string aTypes = theData->getProperty("shape_types");
96 myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts);
99 //********************************************************************
100 ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector()
104 //********************************************************************
105 bool ModuleBase_WidgetShapeSelector::storeValueCustom()
107 // the value is stored on the selection changed signal processing
111 //********************************************************************
112 bool ModuleBase_WidgetShapeSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
113 const bool theToValidate)
115 if (theValues.empty()) {
116 // In order to make reselection possible, set empty object and shape should be done
117 setSelectionCustom(std::shared_ptr<ModuleBase_ViewerPrs>(new ModuleBase_ViewerPrs(
118 ObjectPtr(), GeomShapePtr(), NULL)));
121 // it removes the processed value from the parameters list
122 ModuleBase_ViewerPrsPtr aValue = theValues.takeFirst();
125 if (!theToValidate || isValidInFilters(aValue)) {
126 isDone = setSelectionCustom(aValue);
127 // updateObject - to update/redisplay feature
128 // it is commented in order to perfom it outside the method
129 //updateObject(myFeature);
131 //emit valuesChanged();
136 //********************************************************************
137 QList<ModuleBase_ViewerPrsPtr> ModuleBase_WidgetShapeSelector::getAttributeSelection() const
139 QList<ModuleBase_ViewerPrsPtr> aSelected;
141 DataPtr aData = myFeature->data();
142 AttributePtr anAttribute = myFeature->attribute(attributeID());
144 ObjectPtr anObject = ModuleBase_Tools::getObject(anAttribute);
145 std::shared_ptr<GeomAPI_Shape> aShapePtr = getShape();
146 ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs(anObject, aShapePtr, NULL));
147 aSelected.append(aPrs);
152 //********************************************************************
153 bool ModuleBase_WidgetShapeSelector::restoreValueCustom()
155 bool isBlocked = this->blockSignals(true);
156 updateSelectionName();
157 this->blockSignals(isBlocked);
162 //********************************************************************
163 QList<QWidget*> ModuleBase_WidgetShapeSelector::getControls() const
165 QList<QWidget*> aControls;
166 aControls.append(myTextLine);
170 void ModuleBase_WidgetShapeSelector::updateFocus()
172 emit focusOutWidget(this);
175 //********************************************************************
176 QIntList ModuleBase_WidgetShapeSelector::getShapeTypes() const
178 QIntList aShapeTypes;
179 foreach(QString aType, myShapeTypes) {
180 aShapeTypes.append(ModuleBase_Tools::shapeType(aType));
185 //********************************************************************
186 GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const
189 DataPtr aData = myFeature->data();
190 if (aData->isValid()) {
191 AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
192 aShape = ModuleBase_Tools::getShape(anAttribute, myWorkshop);
197 //********************************************************************
198 void ModuleBase_WidgetShapeSelector::updateSelectionName()
200 DataPtr aData = myFeature->data();
201 if (!aData->isValid())
204 bool isNameUpdated = false;
205 AttributeSelectionPtr aSelect = aData->selection(attributeID());
207 myTextLine->setText(QString::fromStdString(aSelect->namingName(getDefaultValue())));
208 isNameUpdated = true;
210 if (!isNameUpdated) {
211 ObjectPtr anObject = ModuleBase_Tools::getObject(myFeature->attribute(attributeID()));
212 if (anObject.get() != NULL) {
213 std::string aName = anObject->data()->name();
214 myTextLine->setText(QString::fromStdString(aName));
216 AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
217 if (aRefAttr && aRefAttr->attr().get() != NULL) {
218 //myIsObject = aRefAttr->isObject();
219 std::string anAttrName = generateName(aRefAttr->attr(), myWorkshop);
220 myTextLine->setText(QString::fromStdString(anAttrName));
223 myTextLine->setText(getDefaultValue().c_str());