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>
19 #include <ModuleBase_ViewerPrs.h>
21 #include <Config_WidgetAPI.h>
23 #include <PartSet_Tools.h>
24 #include <PartSet_ExternalObjectsMgr.h>
25 #include <SketchPlugin_Feature.h>
27 #include <SketchPlugin_ConstraintRigid.h>
29 #include <XGUI_Workshop.h>
33 PartSet_WidgetMultiSelector::PartSet_WidgetMultiSelector(QWidget* theParent,
34 ModuleBase_IWorkshop* theWorkshop,
35 const Config_WidgetAPI* theData)
36 : ModuleBase_WidgetMultiSelector(theParent, theWorkshop, theData)
38 myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
39 theData->getProperty("can_create_external"), false);
42 PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector()
44 delete myExternalObjectMgr;
47 //********************************************************************
48 bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
50 bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
52 ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
53 aValid = myExternalObjectMgr->isValidObject(anObject);
58 //********************************************************************
59 void PartSet_WidgetMultiSelector::restoreAttributeValue(const AttributePtr& theAttribute,
62 ModuleBase_WidgetMultiSelector::restoreAttributeValue(theAttribute, theValid);
64 myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
67 void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
69 GeomShapePtr& theShape)
71 ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape);
73 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
74 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
75 std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
76 // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
77 // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
78 if (aSPFeature.get() == NULL) {
79 ObjectPtr anExternalObject = ObjectPtr();
80 GeomShapePtr anExternalShape = GeomShapePtr();
81 if (myExternalObjectMgr->useExternal()) {
82 if (myExternalObjectMgr->canCreateExternal()) {
83 GeomShapePtr aShape = theShape;
85 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
87 aShape = aResult->shape();
89 if (aShape.get() != NULL && !aShape->isNull())
91 myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);
94 anExternalObject = theObject;
95 anExternalShape = theShape;
98 /// the object is null if the selected feature is "external"(not sketch entity feature of the
99 /// current sketch) and it is not created by object manager
100 theObject = anExternalObject;
101 theShape = anExternalShape;