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_Filter.h>
14 #include <ModuleBase_IModule.h>
15 #include <ModuleBase_ViewerPrs.h>
16 #include <ModuleBase_IconFactory.h>
18 #include <Config_Translator.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>
43 #include <GeomAPI_Shape.h>
45 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
46 #include <TopoDS_Shape.hxx>
47 #include <TopExp_Explorer.hxx>
53 #include <QToolButton>
56 #include <QDockWidget>
57 #include <QApplication>
58 #include <QFormLayout>
60 #include <TopExp_Explorer.hxx>
61 #include <TopoDS_Shape.hxx>
68 ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent,
69 ModuleBase_IWorkshop* theWorkshop,
70 const Config_WidgetAPI* theData)
71 : ModuleBase_WidgetSelector(theParent, theWorkshop, theData)
73 QFormLayout* aLayout = new QFormLayout(this);
74 ModuleBase_Tools::adjustMargins(aLayout);
76 QString aLabelText = translate(theData->widgetLabel());
77 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
78 myLabel = new QLabel(aLabelText, this);
79 if (!aLabelIcon.isEmpty())
80 myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
83 QString aToolTip = translate(theData->widgetTooltip());
84 myTextLine = new QLineEdit(this);
85 QString anObjName = QString::fromStdString(attributeID());
86 myTextLine->setObjectName(anObjName);
87 myTextLine->setReadOnly(true);
88 myTextLine->setToolTip(aToolTip);
89 myTextLine->installEventFilter(this);
91 aLayout->addRow(myLabel, myTextLine);
92 myLabel->setToolTip(aToolTip);
94 std::string aTypes = theData->getProperty("shape_types");
95 myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts);
98 //********************************************************************
99 ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector()
103 //********************************************************************
104 bool ModuleBase_WidgetShapeSelector::storeValueCustom()
106 // the value is stored on the selection changed signal processing
110 //********************************************************************
111 bool ModuleBase_WidgetShapeSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
112 const bool theToValidate)
114 if (theValues.empty()) {
115 // In order to make reselection possible, set empty object and shape should be done
116 setSelectionCustom(std::shared_ptr<ModuleBase_ViewerPrs>(new ModuleBase_ViewerPrs(
117 ObjectPtr(), GeomShapePtr(), NULL)));
120 // it removes the processed value from the parameters list
121 ModuleBase_ViewerPrsPtr aValue = theValues.takeFirst();
124 if (!theToValidate || isValidInFilters(aValue)) {
125 isDone = setSelectionCustom(aValue);
126 // updateObject - to update/redisplay feature
127 // it is commented in order to perfom it outside the method
128 //updateObject(myFeature);
130 //emit valuesChanged();
135 //********************************************************************
136 QList<ModuleBase_ViewerPrsPtr> ModuleBase_WidgetShapeSelector::getAttributeSelection() const
138 QList<ModuleBase_ViewerPrsPtr> aSelected;
140 DataPtr aData = myFeature->data();
141 AttributePtr anAttribute = myFeature->attribute(attributeID());
143 ObjectPtr anObject = ModuleBase_Tools::getObject(anAttribute);
144 std::shared_ptr<GeomAPI_Shape> aShapePtr = getShape();
145 ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs(anObject, aShapePtr, NULL));
146 aSelected.append(aPrs);
151 //********************************************************************
152 bool ModuleBase_WidgetShapeSelector::restoreValueCustom()
154 bool isBlocked = this->blockSignals(true);
155 updateSelectionName();
156 this->blockSignals(isBlocked);
161 //********************************************************************
162 QList<QWidget*> ModuleBase_WidgetShapeSelector::getControls() const
164 QList<QWidget*> aControls;
165 aControls.append(myTextLine);
169 void ModuleBase_WidgetShapeSelector::updateFocus()
171 emit focusOutWidget(this);
174 //********************************************************************
175 QIntList ModuleBase_WidgetShapeSelector::shapeTypes() const
177 QIntList aShapeTypes;
178 foreach(QString aType, myShapeTypes) {
179 aShapeTypes.append(ModuleBase_Tools::shapeType(aType));
184 //********************************************************************
185 GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const
188 DataPtr aData = myFeature->data();
189 if (aData->isValid()) {
190 AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
191 aShape = ModuleBase_Tools::getShape(anAttribute, myWorkshop);
196 //********************************************************************
197 void ModuleBase_WidgetShapeSelector::updateSelectionName()
199 DataPtr aData = myFeature->data();
200 if (!aData->isValid())
203 bool isNameUpdated = false;
204 AttributeSelectionPtr aSelect = aData->selection(attributeID());
206 myTextLine->setText(QString::fromStdString(aSelect->namingName(getDefaultValue())));
207 isNameUpdated = true;
209 if (!isNameUpdated) {
210 ObjectPtr anObject = ModuleBase_Tools::getObject(myFeature->attribute(attributeID()));
211 if (anObject.get() != NULL) {
212 std::string aName = anObject->data()->name();
213 myTextLine->setText(QString::fromStdString(aName));
215 AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
216 if (aRefAttr && aRefAttr->attr().get() != NULL) {
217 //myIsObject = aRefAttr->isObject();
218 std::string anAttrName = generateName(aRefAttr->attr(), myWorkshop);
219 myTextLine->setText(QString::fromStdString(anAttrName));
222 myTextLine->setText(getDefaultValue().c_str());