Salome HOME
380c7da3bf8f18361629e433d4e2f4a41ee80851
[modules/shaper.git] / src / PartSet / PartSet_WidgetMultiSelector.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_WidgetMultiSelector.cpp
4 // Created:     15 Apr 2015
5 // Author:      Natalia Ermolaeva
6
7 #include "PartSet_WidgetMultiSelector.h"
8
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>
14
15 #include <ModuleBase_Definitions.h>
16 #include <ModuleBase_Tools.h>
17 #include <ModuleBase_IWorkshop.h>
18 #include <ModuleBase_ISelection.h>
19
20 #include <Config_WidgetAPI.h>
21
22 #include <PartSet_Tools.h>
23 #include <PartSet_ExternalObjectsMgr.h>
24 #include <SketchPlugin_Feature.h>
25
26 #include <SketchPlugin_ConstraintRigid.h>
27
28 #include <XGUI_Workshop.h>
29
30 #include <QComboBox>
31
32 PartSet_WidgetMultiSelector::PartSet_WidgetMultiSelector(QWidget* theParent,
33                                                          ModuleBase_IWorkshop* theWorkshop,
34                                                          const Config_WidgetAPI* theData)
35 : ModuleBase_WidgetMultiSelector(theParent, theWorkshop, theData)
36 {
37   myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), false);
38 }
39
40 PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector()
41 {
42   delete myExternalObjectMgr;
43 }
44
45 //********************************************************************
46 bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
47 {
48   bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
49   if (aValid) {
50     ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
51     aValid = myExternalObjectMgr->isValidObject(anObject);
52   }
53   return aValid;
54 }
55
56 //********************************************************************
57 void PartSet_WidgetMultiSelector::restoreAttributeValue(const AttributePtr& theAttribute,
58                                                         const bool theValid)
59 {
60   ModuleBase_WidgetMultiSelector::restoreAttributeValue(theAttribute, theValid);
61
62   myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
63 }
64
65 void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
66                                                    ObjectPtr& theObject,
67                                                    GeomShapePtr& theShape)
68 {
69   ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape);
70
71   FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
72   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
73           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
74   // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
75   // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
76   if (aSPFeature.get() == NULL && myExternalObjectMgr->useExternal()) {
77     GeomShapePtr aShape = theShape;
78     if (!aShape.get()) {
79       ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
80       if (aResult.get())
81         aShape = aResult->shape();
82     }
83     if (aShape.get() != NULL && !aShape->isNull())
84       theObject = myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);
85   }
86 }