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 : ModuleBase_WidgetMultiSelector(theParent, theWorkshop, theData)
37 myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), false);
40 PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector()
42 delete myExternalObjectMgr;
45 //********************************************************************
46 bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
48 bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
50 ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
51 aValid = myExternalObjectMgr->isValidObject(anObject);
56 //********************************************************************
57 void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid)
59 ModuleBase_WidgetMultiSelector::restoreAttributeValue(theValid);
61 myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
64 void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
66 GeomShapePtr& theShape)
68 ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape);
70 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
71 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
72 std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
73 // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
74 // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
75 if (aSPFeature.get() == NULL && myExternalObjectMgr->useExternal()) {
76 GeomShapePtr aShape = theShape;
78 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
80 aShape = aResult->shape();
82 if (aShape.get() != NULL && !aShape->isNull())
83 theObject = myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);