Salome HOME
Issue #1860: fix end lines with spaces
[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"),
39                                         theData->getProperty("can_create_external"), false);
40 }
41
42 PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector()
43 {
44   delete myExternalObjectMgr;
45 }
46
47 //********************************************************************
48 bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
49 {
50   bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
51   if (aValid) {
52     ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
53     aValid = myExternalObjectMgr->isValidObject(anObject);
54   }
55   return aValid;
56 }
57
58 //********************************************************************
59 void PartSet_WidgetMultiSelector::restoreAttributeValue(const AttributePtr& theAttribute,
60                                                         const bool theValid)
61 {
62   ModuleBase_WidgetMultiSelector::restoreAttributeValue(theAttribute, theValid);
63
64   myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
65 }
66
67 void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
68                                                    ObjectPtr& theObject,
69                                                    GeomShapePtr& theShape)
70 {
71   ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape);
72
73   FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
74   std::shared_ptr<SketchPlugin_Feature> aSPFeature =
75           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
76   // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
77   // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
78   if (aSPFeature.get() == NULL) {
79     ObjectPtr anExternalObject = ObjectPtr();
80     GeomShapePtr anExternalShape = GeomShapePtr();
81     if (myExternalObjectMgr->useExternal()) {
82       if (myExternalObjectMgr->canCreateExternal()) {
83         GeomShapePtr aShape = theShape;
84         if (!aShape.get()) {
85           ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
86           if (aResult.get())
87             aShape = aResult->shape();
88         }
89         if (aShape.get() != NULL && !aShape->isNull())
90           anExternalObject =
91             myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);
92       }
93       else {
94         anExternalObject = theObject;
95         anExternalShape = theShape;
96       }
97     }
98     /// the object is null if the selected feature is "external"(not sketch entity feature of the
99     /// current sketch) and it is not created by object manager
100     theObject = anExternalObject;
101     theShape = anExternalShape;
102   }
103 }