-// Copyright (C) 2014-2020 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include <ModuleBase_IPropertyPanel.h>
#include <ModuleBase_OperationFeature.h>
#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_ChoiceCtrl.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_ISelectionActivate.h>
#include <Config_WidgetAPI.h>
#include <QMessageBox>
#include <QMainWindow>
+#ifdef WIN32
+#pragma warning(disable : 4456) // for nested foreach
+#endif
+
#define DEBUG_UNDO_INVALID_SKETCH
+
+
+QStringList getIconsList(const QStringList& theNames)
+{
+ QStringList aIcons;
+ foreach(QString aName, theNames) {
+ QString aUName = aName.toUpper();
+ if ((aUName == "VERTICES") || (aUName == "VERTEX"))
+ aIcons << ":pictures/vertex32.png";
+ else if ((aUName == "EDGES") || (aUName == "EDGE"))
+ aIcons << ":pictures/edge32.png";
+ else if ((aUName == "FACES") || (aUName == "FACE"))
+ aIcons << ":pictures/face32.png";
+ }
+ return aIcons;
+}
+
+
+
PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent,
PartSet_Module* theModule,
const Config_WidgetAPI* theData)
aLayout->addWidget(mySizeOfViewWidget);
aLayout->addWidget(myLabel);
- aLayout->addStretch(1);
std::string aTypes = theData->getProperty("shape_types");
myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts);
+ myIsUseChoice = theData->getBooleanAttribute("use_choice", false);
+
+ QStringList aIconsList;
+ std::string aIcons = theData->getProperty("type_icons");
+ if (aIcons.size() > 0)
+ aIconsList = QString(aIcons.c_str()).split(' ', QString::SkipEmptyParts);
+
+ if (aIconsList.size() != myShapeTypes.size())
+ aIconsList = getIconsList(myShapeTypes);
+
+ myTypeCtrl = new ModuleBase_ChoiceCtrl(this, myShapeTypes, aIconsList);
+ myTypeCtrl->setLabel(tr("Type"));
+ if (!myShapeTypes.empty()) {
+ std::string aDefType = theData->getProperty("default_type");
+ if (aDefType.size() > 0) {
+ bool aOk = false;
+ int aId = QString(aDefType.c_str()).toInt(&aOk);
+ if (aOk) {
+ myTypeCtrl->setValue(aId);
+ myDefMode = myShapeTypes.at(aId).toStdString();
+ }
+ }
+ if (myDefMode.size() == 0) {
+ myTypeCtrl->setValue(0);
+ myDefMode = myShapeTypes.first().toStdString();
+ }
+ }
+ aLayout->addWidget(myTypeCtrl);
+ // There is no sense to parameterize list of types while we can not parameterize selection mode
+ // if the xml definition contains one type, the controls to select a type should not be shown
+ if (myShapeTypes.size() <= 1 || !myIsUseChoice) {
+ myTypeCtrl->setVisible(false);
+ }
+ connect(myTypeCtrl, SIGNAL(valueChanged(int)), this, SLOT(onSelectionTypeChanged()));
+ aLayout->addStretch(1);
myPreviewPlanes = new PartSet_PreviewPlanes();
}
QIntList PartSet_WidgetSketchCreator::shapeTypes() const
{
QIntList aShapeTypes;
- foreach(QString aType, myShapeTypes) {
- aShapeTypes.append(ModuleBase_Tools::shapeType(aType));
+ if (myShapeTypes.length() > 1 && myIsUseChoice) {
+ QStringList aTypes = myTypeCtrl->textValue().split("|", QString::SkipEmptyParts);
+ foreach(QString aType, aTypes) {
+ aShapeTypes.append(ModuleBase_Tools::shapeType(aType));
+ }
+ }
+ else {
+ foreach(QString aType, myShapeTypes) {
+ QStringList aSubTypes = aType.split("|", QString::SkipEmptyParts);
+ foreach(QString asubType, aSubTypes) {
+ aShapeTypes.append(ModuleBase_Tools::shapeType(asubType));
+ }
+ }
}
return aShapeTypes;
}
bool PartSet_WidgetSketchCreator::hasSubObjects() const
{
bool aHasSubObjects = false;
-
- bool aCanSetFocus = true;
CompositeFeaturePtr aComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
if (aComposite.get())
aHasSubObjects = aComposite->numberOfSubs() > 0;
}
// manually deactivation because the widget was not activated as has no focus acceptin controls
deactivate();
- bool aHidePreview = myPreviewPlanes->isPreviewDisplayed();
myPreviewPlanes->erasePreviewPlanes(myWorkshop);
// start edit operation for the sketch
AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID);
if (aCompFeature->numberOfSubs() > 0) {
// set the sub feature to attribute selection list and check whether sketch is valid
- SessionPtr aMgr = ModelAPI_Session::get();
const static std::string aNestedOpID("Set Sketch result into Selection list");
aMgr->startOperation(aNestedOpID, false); // false to not attach to Extrusion operation
setSketchObjectToList(aCompFeature, anAttrList);
(aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
ResultPtr aRes = aSelAttr.get() ? aSelAttr->context() : ResultPtr();
if (aRes.get()) {
- SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
AttributePtr anAttribute = myFeature->attribute(anObjectsAttribute);
std::string aValidatorID;
eachControl->setEnabled(theEnabled);
}
}
+
+void PartSet_WidgetSketchCreator::onSelectionTypeChanged()
+{
+ // Clear current selection in order to avoid updating of object browser with obsolete indexes
+ // which can appear because of results deletetion after changing a type of selection
+ QString aSelectionType = myTypeCtrl->textValue();
+ QList<ModuleBase_ViewerPrsPtr> aEmptyList;
+ myWorkshop->setSelected(aEmptyList);
+
+ updateSelectionModesAndFilters(true);
+ myWorkshop->selectionActivate()->updateSelectionModes();
+
+ if (!myFeature)
+ return;
+
+ if (aSelectionType != "Faces") {
+ setVisibleSelectionControl(false);
+ myWorkshop->propertyPanel()->activateNextWidget();
+ }
+
+ /// store the selected type
+ AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID);
+ anAttrList->setSelectionType(aSelectionType.toStdString());
+ anAttrList->clear();
+
+ // update object is necessary to flush update signal. It leads to objects references map update
+ // and the operation presentation will not contain deleted items visualized as parameters of
+ // the feature.
+ updateObject(myFeature);
+ myWorkshop->propertyPanel()->activeWidget()->restoreValue();
+ myWorkshop->setSelected(getAttributeSelection());
+ // may be the feature's result is not displayed, but attributes should be
+ // hope that something is redisplayed by object updated
+ myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeArguments, true);
+}
\ No newline at end of file