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_Session.h>
11 #include <ModelAPI_Validator.h>
13 #include <ModuleBase_Definitions.h>
14 #include <ModuleBase_Tools.h>
15 #include <ModuleBase_IWorkshop.h>
16 #include <ModuleBase_ISelection.h>
18 #include <Config_WidgetAPI.h>
20 #include <PartSet_Tools.h>
21 #include <PartSet_ExternalObjectsMgr.h>
22 #include <SketchPlugin_Feature.h>
24 #include <SketchPlugin_ConstraintRigid.h>
26 #include <XGUI_Workshop.h>
30 PartSet_WidgetMultiSelector::PartSet_WidgetMultiSelector(QWidget* theParent,
31 ModuleBase_IWorkshop* theWorkshop,
32 const Config_WidgetAPI* theData,
33 const std::string& theParentId)
34 : ModuleBase_WidgetMultiSelector(theParent, theWorkshop, theData, theParentId)
36 myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), false);
39 PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector()
41 delete myExternalObjectMgr;
44 bool PartSet_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
45 const bool theToValidate)
47 bool aSucceed = ModuleBase_WidgetMultiSelector::setSelection(theValues, theToValidate);
49 // TODO(nds): unite with externalObject(), remove parameters
50 //myFeature->execute();
52 DataPtr aData = myFeature->data();
53 AttributeSelectionListPtr aSelectionListAttr =
54 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
56 QObjectPtrList aListOfAttributeObjects;
57 for (int i = 0; i < aSelectionListAttr->size(); i++) {
58 AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
59 aListOfAttributeObjects.append(anAttr->context());
61 myExternalObjectMgr->removeUnusedExternalObjects(aListOfAttributeObjects, sketch(), myFeature);
66 //********************************************************************
67 bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
69 bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
71 ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
72 aValid = myExternalObjectMgr->isValidObject(anObject);
77 //********************************************************************
78 void PartSet_WidgetMultiSelector::storeAttributeValue()
80 myIsInVaildate = true;
81 ModuleBase_WidgetMultiSelector::storeAttributeValue();
84 //********************************************************************
85 void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid)
87 myIsInVaildate = false;
88 ModuleBase_WidgetMultiSelector::restoreAttributeValue(theValid);
90 myExternalObjectMgr->removeExternalValidated(sketch(), myFeature, myWorkshop);
93 void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
95 GeomShapePtr& theShape)
97 ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape);
99 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
100 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
101 std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
102 // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
103 // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
104 if (aSPFeature.get() == NULL && myExternalObjectMgr->useExternal()) {
105 GeomShapePtr aShape = theShape;
107 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
109 aShape = aResult->shape();
111 if (aShape.get() != NULL && !aShape->isNull()) {
113 theObject = myExternalObjectMgr->externalObjectValidated(theObject, aShape, sketch());
115 theObject = myExternalObjectMgr->externalObject(theObject, aShape, sketch());