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 //********************************************************************
45 void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid)
47 ModuleBase_WidgetMultiSelector::restoreAttributeValue(theValid);
48 myExternalObjectMgr->removeExternal(sketch(), myFeature);
51 //********************************************************************
52 bool PartSet_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
54 TopoDS_Shape aShape = thePrs.shape();
55 if ((myTypeCombo->count() > 1) && (!aShape.IsNull())) {
56 TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->currentText());
57 if (aShape.ShapeType() != aType)
61 if (!thePrs.owner().IsNull()) {
62 ObjectPtr anObject = myWorkshop->selection()->getSelectableObject(thePrs.owner());
63 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
66 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs.object());
71 // We can not select a result of our feature
72 const std::list<ResultPtr>& aResList = myFeature->results();
73 std::list<ResultPtr>::const_iterator aIt;
74 bool isSkipSelf = false;
75 for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
76 if ((*aIt) == aResult) {
85 GeomShapePtr aGShape = GeomShapePtr();
86 const TopoDS_Shape& aTDSShape = thePrs.shape();
87 // if only result is selected, an empty shape is set to the model
88 if (aTDSShape.IsNull()) {
89 //aSelectionListAttr->append(aResult, GeomShapePtr());
92 aGShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
93 //GeomShapePtr aShape(new GeomAPI_Shape());
94 aGShape->setImpl(new TopoDS_Shape(aTDSShape));
95 // We can not select a result of our feature
96 if (aGShape->isEqual(aResult->shape())) {
97 //aSelectionListAttr->append(aResult, GeomShapePtr());
98 aGShape = GeomShapePtr();
101 //aSelectionListAttr->append(aResult, aShape);
105 setObject(aResult, aGShape);
109 //********************************************************************
110 bool PartSet_WidgetMultiSelector::setObject(const ObjectPtr& theSelectedObject,
111 const GeomShapePtr& theShape)
113 ObjectPtr aSelectedObject = theSelectedObject;
114 GeomShapePtr aShape = theShape;
116 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aSelectedObject);
117 //if (aSelectedFeature == myFeature) // In order to avoid selection of the same object
120 // Do check using of external feature
121 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
122 std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
124 // Do check that we can use external feature
125 if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myExternalObjectMgr->useExternal()))
128 if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myExternalObjectMgr->useExternal()) {
129 aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch());
133 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aSelectedObject);
135 DataPtr aData = myFeature->data();
136 AttributeSelectionListPtr aSelectionListAttr =
137 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
139 aSelectionListAttr->append(aResult, aShape);