1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_WidgetMultiSelector.cpp
4 // Created: 15 Apr 2015
5 // Author: Natalia Ermolaeva
7 #include "PartSet_WidgetMultiSelector.h"
9 #include <ModelAPI_AttributeRefAttr.h>
10 #include <ModelAPI_AttributeSelectionList.h>
11 #include <ModelAPI_AttributeRefList.h>
12 #include <ModelAPI_Session.h>
13 #include <ModelAPI_Validator.h>
15 #include <ModuleBase_Definitions.h>
16 #include <ModuleBase_Tools.h>
17 #include <ModuleBase_IWorkshop.h>
18 #include <ModuleBase_ISelection.h>
20 #include <Config_WidgetAPI.h>
22 #include <PartSet_Tools.h>
23 #include <PartSet_ExternalObjectsMgr.h>
24 #include <SketchPlugin_Feature.h>
26 #include <SketchPlugin_ConstraintRigid.h>
28 #include <XGUI_Workshop.h>
32 PartSet_WidgetMultiSelector::PartSet_WidgetMultiSelector(QWidget* theParent,
33 ModuleBase_IWorkshop* theWorkshop,
34 const Config_WidgetAPI* theData,
35 const std::string& theParentId)
36 : ModuleBase_WidgetMultiSelector(theParent, theWorkshop, theData, theParentId)
38 myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), false);
41 PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector()
43 delete myExternalObjectMgr;
46 bool PartSet_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
47 const bool theToValidate)
49 bool aSucceed = ModuleBase_WidgetMultiSelector::setSelection(theValues, theToValidate);
51 // TODO(nds): unite with externalObject(), remove parameters
52 //myFeature->execute();
54 QObjectPtrList aListOfAttributeObjects;
56 AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
57 if (anAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) {
58 AttributeSelectionListPtr aSelectionListAttr =
59 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
60 for (int i = 0; i < aSelectionListAttr->size(); i++) {
61 AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
62 aListOfAttributeObjects.append(anAttr->context());
65 else if (anAttribute->attributeType() == ModelAPI_AttributeRefList::typeId()) {
66 AttributeRefListPtr aRefListAttr =
67 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
68 for (int i = 0; i < aRefListAttr->size(); i++) {
69 aListOfAttributeObjects.append(aRefListAttr->object(i));
73 myExternalObjectMgr->removeUnusedExternalObjects(aListOfAttributeObjects, sketch(), myFeature);
78 //********************************************************************
79 bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
81 bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
83 ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
84 aValid = myExternalObjectMgr->isValidObject(anObject);
89 //********************************************************************
90 void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid)
92 ModuleBase_WidgetMultiSelector::restoreAttributeValue(theValid);
94 myExternalObjectMgr->removeExternal/*Validated*/(sketch(), myFeature, myWorkshop, true);
97 void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
99 GeomShapePtr& theShape)
101 ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape);
103 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
104 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
105 std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
106 // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
107 // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
108 if (aSPFeature.get() == NULL && myExternalObjectMgr->useExternal()) {
109 GeomShapePtr aShape = theShape;
111 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
113 aShape = aResult->shape();
115 if (aShape.get() != NULL && !aShape->isNull()) {
116 //if (myIsInValidate)
117 // theObject = myExternalObjectMgr->externalObjectValidated(theObject, aShape, sketch());
119 theObject = myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);