]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetMultiSelector.cpp
Salome HOME
#1371 Using auxilliary Sketch elements in any Feature: code improvement to separate...
[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 bool theValid)
58 {
59   ModuleBase_WidgetMultiSelector::restoreAttributeValue(theValid);
60
61   myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
62 }
63
64 void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
65                                                    ObjectPtr& theObject,
66                                                    GeomShapePtr& theShape)
67 {
68   ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape);
69
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;
77     if (!aShape.get()) {
78       ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
79       if (aResult.get())
80         aShape = aResult->shape();
81     }
82     if (aShape.get() != NULL && !aShape->isNull())
83       theObject = myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);
84   }
85 }