]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetMultiSelector.cpp
Salome HOME
Preselection using in operations: using of external objects correction.
[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_Session.h>
11 #include <ModelAPI_Validator.h>
12
13 #include <ModuleBase_Definitions.h>
14 #include <ModuleBase_Tools.h>
15 #include <ModuleBase_IWorkshop.h>
16 #include <ModuleBase_ISelection.h>
17
18 #include <Config_WidgetAPI.h>
19
20 #include <PartSet_Tools.h>
21 #include <PartSet_ExternalObjectsMgr.h>
22 #include <SketchPlugin_Feature.h>
23
24 #include <SketchPlugin_ConstraintRigid.h>
25
26 #include <XGUI_Workshop.h>
27
28 #include <QComboBox>
29
30 PartSet_WidgetMultiSelector::PartSet_WidgetMultiSelector(QWidget* theParent,
31                                                          ModuleBase_IWorkshop* theWorkshop,
32                                                          const Config_WidgetAPI* theData,
33                                                          const std::string& theParentId)
34 : ModuleBase_WidgetMultiSelector(theParent, theWorkshop, theData, theParentId)
35 {
36   myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), false);
37 }
38
39 PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector()
40 {
41   delete myExternalObjectMgr;
42 }
43
44 //********************************************************************
45 void PartSet_WidgetMultiSelector::onSelectionChanged()
46 {
47   ModuleBase_WidgetMultiSelector::onSelectionChanged();
48   // TODO(nds): unite with externalObject(), remove parameters
49   //myFeature->execute();
50
51   DataPtr aData = myFeature->data();
52   AttributeSelectionListPtr aSelectionListAttr = 
53     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
54
55   QObjectPtrList aListOfAttributeObjects;
56   for (int i = 0; i < aSelectionListAttr->size(); i++) {
57     AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
58     aListOfAttributeObjects.append(anAttr->context());
59   }
60
61   myExternalObjectMgr->removeUnusedExternalObjects(aListOfAttributeObjects, sketch(), myFeature);
62 }
63
64 //********************************************************************
65 bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
66 {
67   bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
68   if (aValid) {
69     ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
70     aValid = myExternalObjectMgr->isValidObject(anObject);
71   }
72   return aValid;
73 }
74
75 //********************************************************************
76 void PartSet_WidgetMultiSelector::storeAttributeValue()
77 {
78   myIsInVaildate = true;
79   ModuleBase_WidgetMultiSelector::storeAttributeValue();
80
81 }
82
83 //********************************************************************
84 void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid)
85 {
86   myIsInVaildate = false;
87   ModuleBase_WidgetMultiSelector::restoreAttributeValue(theValid);
88
89   myExternalObjectMgr->removeExternalValidated(sketch(), myFeature);
90 }
91
92 void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
93                                                    ObjectPtr& theObject,
94                                                    GeomShapePtr& theShape)
95 {
96   ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape);
97
98   FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
99   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
100           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
101   // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
102   if (aSPFeature.get() == NULL && theShape.get() != NULL && !theShape->isNull() &&
103       myExternalObjectMgr->useExternal()) {
104     if (myIsInVaildate)
105       theObject = myExternalObjectMgr->externalObjectValidated(theObject, theShape, sketch());
106     else
107       theObject = myExternalObjectMgr->externalObject(theObject, theShape, sketch());
108   }
109 }