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