#include <ModuleBase_Tools.h>
#include <ModuleBase_Definitions.h>
-#include <GeomValidators_ShapeType.h>
-
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeRefList.h>
#include <Config_WidgetAPI.h>
const Config_WidgetAPI* theData,
const std::string& theParentId)
: ModuleBase_WidgetSelector(theParent, theWorkshop, theData, theParentId),
- mySelectionCount(0), myIsInValidate(false)
+ mySelectionCount(0)
{
QGridLayout* aMainLay = new QGridLayout(this);
ModuleBase_Tools::adjustMargins(aMainLay);
std::string aPropertyTypes = theData->getProperty("type_choice");
QString aTypesStr = aPropertyTypes.c_str();
- QStringList aShapeTypes = aTypesStr.split(' ');
+ QStringList aShapeTypes = aTypesStr.split(' ', QString::SkipEmptyParts);
myIsUseChoice = theData->getBooleanAttribute("use_choice", true);
- myTypeCombo->addItems(aShapeTypes);
+ if (!aShapeTypes.empty())
+ myTypeCombo->addItems(aShapeTypes);
aMainLay->addWidget(myTypeCombo, 0, 1);
// if the xml definition contains one type, the controls to select a type should not be shown
- if (aShapeTypes.size() == 1 || !myIsUseChoice) {
+ if (aShapeTypes.size() <= 1 || !myIsUseChoice) {
aTypeLabel->setVisible(false);
myTypeCombo->setVisible(false);
}
: tr("Selected objects:"), this);
aMainLay->addWidget(aListLabel, 1, 0);
// if the xml definition contains one type, an information label should be shown near to the latest
- if (aShapeTypes.size() == 1) {
+ if (aShapeTypes.size() <= 1) {
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
if (!aLabelIcon.isEmpty()) {
QLabel* aSelectedLabel = new QLabel("", this);
{
// the value is stored on the selection changed signal processing
// A rare case when plugin was not loaded.
- if(!myFeature)
+ if (!myFeature)
return false;
- DataPtr aData = myFeature->data();
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
-
- if (aSelectionListAttr) {
- // Store shapes type
- TopAbs_ShapeEnum aCurrentType =
- ModuleBase_Tools::shapeType(myTypeCombo->currentText());
+
+ AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
+ if (aSelectionListAttr.get()) {
aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
}
return true;
bool ModuleBase_WidgetMultiSelector::restoreValueCustom()
{
// A rare case when plugin was not loaded.
- if(!myFeature)
+ if (!myFeature)
return false;
- DataPtr aData = myFeature->data();
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
- if (aSelectionListAttr) {
+ AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
+ if (aSelectionListAttr.get()) {
// Restore shape type
if (!aSelectionListAttr->selectionType().empty())
setCurrentShapeType(ModuleBase_Tools::shapeType(aSelectionListAttr->selectionType().c_str()));
- updateSelectionList(aSelectionListAttr);
- return true;
}
- return false;
+ updateSelectionList();
+ return true;
}
//********************************************************************
void ModuleBase_WidgetMultiSelector::storeAttributeValue()
{
- myIsInValidate = true;
- DataPtr aData = myFeature->data();
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
- if (aSelectionListAttr.get() == NULL)
- return;
-
- mySelectionType = aSelectionListAttr->selectionType();
- mySelectionCount = aSelectionListAttr->size();
+ ModuleBase_WidgetValidated::storeAttributeValue();
+
+ AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
+ if (aSelectionListAttr.get()) {
+ mySelectionType = aSelectionListAttr->selectionType();
+ mySelectionCount = aSelectionListAttr->size();
+ }
+ else {
+ AttributeRefListPtr aRefListAttr = myFeature->data()->reflist(attributeID());
+ mySelectionCount = aRefListAttr->size();
+ }
}
//********************************************************************
-void ModuleBase_WidgetMultiSelector::clearAttribute()
+void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid)
{
- DataPtr aData = myFeature->data();
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
- aSelectionListAttr->clear();
+ ModuleBase_WidgetValidated::restoreAttributeValue(theValid);
+
+ // Store shape type
+ AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
+ if (aSelectionListAttr.get()) {
+ aSelectionListAttr->setSelectionType(mySelectionType);
+
+ // restore selection in the attribute. Indeed there is only one stored object
+ int aCountAppened = aSelectionListAttr->size() - mySelectionCount;
+ for (int i = 0; i < aCountAppened; i++)
+ aSelectionListAttr->removeLast();
+ }
+ else {
+ AttributeRefListPtr aRefListAttr = myFeature->data()->reflist(attributeID());
+ // restore objects in the attribute. Indeed there is only one stored object
+ int aCountAppened = aRefListAttr->size() - mySelectionCount;
+ for (int i = 0; i < aCountAppened; i++)
+ aRefListAttr->removeLast();
+ }
}
//********************************************************************
-void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
- GeomShapePtr theShape)
+void ModuleBase_WidgetMultiSelector::clearAttribute()
{
- DataPtr aData = myFeature->data();
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
-
- int aSelCount = aSelectionListAttr->size();
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
- aSelectionListAttr->append(aResult, theShape, myIsInValidate);
+ AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
+ if (aSelectionListAttr.get())
+ aSelectionListAttr->clear();
+ else {
+ AttributeRefListPtr aRefListAttr = myFeature->data()->reflist(attributeID());
+ aRefListAttr->clear();
+ }
}
//********************************************************************
-void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/)
+void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
+ GeomShapePtr theShape)
{
- myIsInValidate = false;
-
- // Store shape type
- DataPtr aData = myFeature->data();
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
- aSelectionListAttr->setSelectionType(mySelectionType);
-
- // restore selection in the attribute
- int aCountAppened = aSelectionListAttr->size() - mySelectionCount;
- for ( int i = 0; i < aCountAppened; i++)
- aSelectionListAttr->removeLast();
+ AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
+ if (aSelectionListAttr.get()) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
+ aSelectionListAttr->append(aResult, theShape, myIsInValidate);
+ }
+ else {
+ AttributeRefListPtr aRefListAttr = myFeature->data()->reflist(attributeID());
+ aRefListAttr->append(theSelectedObject);
+ }
}
//********************************************************************
}
else {
for (int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) {
- aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->itemText(i)));
+ TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->itemText(i));
+ aShapeTypes.append(aType);
+ if (aType == TopAbs_SOLID)
+ aShapeTypes.append(TopAbs_COMPSOLID);
}
}
return aShapeTypes;
QList<ModuleBase_ViewerPrs> aSelected;
// Restore selection in the viewer by the attribute selection list
if(myFeature) {
- DataPtr aData = myFeature->data();
- AttributeSelectionListPtr aListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
- if (aListAttr) {
- for (int i = 0; i < aListAttr->size(); i++) {
- AttributeSelectionPtr anAttr = aListAttr->value(i);
+ AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
+ if (aSelectionListAttr.get()) {
+ for (int i = 0; i < aSelectionListAttr->size(); i++) {
+ AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
ResultPtr anObject = anAttr->context();
if (anObject.get()) {
TopoDS_Shape aShape;
}
}
}
+ else {
+ AttributeRefListPtr aRefListAttr = myFeature->data()->reflist(attributeID());
+ if (aRefListAttr.get()) {
+ for (int i = 0; i < aRefListAttr->size(); i++) {
+ ObjectPtr anObject = aRefListAttr->object(i);
+ if (anObject.get()) {
+ aSelected.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL));
+ }
+ }
+ }
+ }
}
return aSelected;
}
//********************************************************************
-void ModuleBase_WidgetMultiSelector::updateSelectionList(AttributeSelectionListPtr theList)
+void ModuleBase_WidgetMultiSelector::updateSelectionList()
{
myListControl->clear();
- for (int i = 0; i < theList->size(); i++) {
- AttributeSelectionPtr aAttr = theList->value(i);
- myListControl->addItem(aAttr->namingName().c_str());
+
+ AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
+ if (aSelectionListAttr.get()) {
+ for (int i = 0; i < aSelectionListAttr->size(); i++) {
+ AttributeSelectionPtr aAttr = aSelectionListAttr->value(i);
+ myListControl->addItem(aAttr->namingName().c_str());
+ }
+ }
+ else {
+ AttributeRefListPtr aRefListAttr = myFeature->data()->reflist(attributeID());
+ for (int i = 0; i < aRefListAttr->size(); i++) {
+ ObjectPtr anObject = aRefListAttr->object(i);
+ if (anObject.get())
+ myListControl->addItem(anObject->data()->name().c_str());
+ }
}
// We have to call repaint because sometimes the List control is not updated
myListControl->repaint();