Salome HOME
Issue #1618 naming in sketch is broken: external object creation should use the shape...
[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 #include <ModuleBase_ViewerPrs.h>
20
21 #include <Config_WidgetAPI.h>
22
23 #include <PartSet_Tools.h>
24 #include <PartSet_ExternalObjectsMgr.h>
25 #include <SketchPlugin_Feature.h>
26
27 #include <SketchPlugin_ConstraintRigid.h>
28
29 #include <XGUI_Workshop.h>
30
31 #include <QComboBox>
32
33 PartSet_WidgetMultiSelector::PartSet_WidgetMultiSelector(QWidget* theParent,
34                                                          ModuleBase_IWorkshop* theWorkshop,
35                                                          const Config_WidgetAPI* theData)
36 : ModuleBase_WidgetMultiSelector(theParent, theWorkshop, theData)
37 {
38   myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), false);
39 }
40
41 PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector()
42 {
43   delete myExternalObjectMgr;
44 }
45
46 //********************************************************************
47 bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
48 {
49   bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
50   if (aValid) {
51     ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
52     aValid = myExternalObjectMgr->isValidObject(anObject);
53   }
54   return aValid;
55 }
56
57 //********************************************************************
58 void PartSet_WidgetMultiSelector::restoreAttributeValue(const AttributePtr& theAttribute,
59                                                         const bool theValid)
60 {
61   ModuleBase_WidgetMultiSelector::restoreAttributeValue(theAttribute, theValid);
62
63   myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
64 }
65
66 void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
67                                                    ObjectPtr& theObject,
68                                                    GeomShapePtr& theShape)
69 {
70   ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape);
71
72   FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
73   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
74           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
75   // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
76   // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
77   if (aSPFeature.get() == NULL) {
78     ObjectPtr anExternalObject = ObjectPtr();
79     if (myExternalObjectMgr->useExternal()) {
80       GeomShapePtr aShape = theShape;
81       if (!aShape.get()) {
82         ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
83         if (aResult.get())
84           aShape = aResult->shape();
85       }
86       if (aShape.get() != NULL && !aShape->isNull())
87         anExternalObject = myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);
88     }
89     /// the object is null if the selected feature is "external"(not sketch entity feature of the
90     /// current sketch) and it is not created by object manager
91     theObject = anExternalObject;
92   }
93 }