]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetShapeSelector.cpp
Salome HOME
#1352 Selection mode is invalid on edit Partition
[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 #include "PartSet_Module.h"
9 #include "PartSet_SketcherMgr.h"
10
11 #include <ModelAPI_AttributeRefAttr.h>
12 #include <ModelAPI_Session.h>
13 #include <ModelAPI_Validator.h>
14
15 #include <ModuleBase_Definitions.h>
16 #include <Config_WidgetAPI.h>
17
18 #include <PartSet_ExternalObjectsMgr.h>
19 #include <SketchPlugin_Feature.h>
20
21 #include <XGUI_Workshop.h>
22
23 #include <XGUI_ModuleConnector.h>
24 #include <XGUI_Displayer.h>
25 #include <XGUI_SelectionMgr.h>
26 #include <XGUI_Selection.h>
27 #include <XGUI_Tools.h>
28
29 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
30                                                          ModuleBase_IWorkshop* theWorkshop,
31                                                          const Config_WidgetAPI* theData,
32                                                          const std::string& theParentId)
33 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId)
34 {
35   myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
36   myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), true);
37 }
38
39 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
40 {
41   delete myExternalObjectMgr;
42 }
43
44 //********************************************************************
45 bool PartSet_WidgetShapeSelector::activateSelectionAndFilters(bool toActivate)
46 {
47   bool aHasSelectionFilter = ModuleBase_WidgetShapeSelector::activateSelectionAndFilters
48                                                                            (toActivate);
49   if (!myUseSketchPlane) {
50     XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
51     PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(aWorkshop->module());
52     bool isUsePlaneFilterOnly = !toActivate;
53     aModule->sketchMgr()->activatePlaneFilter(isUsePlaneFilterOnly);
54   }
55   return aHasSelectionFilter;
56 }
57
58 //********************************************************************
59 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
60 {
61   bool aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
62   if (aValid) {
63     ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
64     aValid = myExternalObjectMgr->isValidObject(anObject);
65   }
66   return aValid;
67 }
68
69 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
70                                                    ObjectPtr& theObject,
71                                                    GeomShapePtr& theShape)
72 {
73   ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
74
75   FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
76   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
77           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
78   // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
79   // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
80   if (aSPFeature.get() == NULL && myExternalObjectMgr->useExternal()) {
81     GeomShapePtr aShape = theShape;
82     if (!aShape.get()) {
83       ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
84       if (aResult.get())
85         aShape = aResult->shape();
86     }
87     if (aShape.get() != NULL && !aShape->isNull())
88       theObject = myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);
89   }
90 }
91
92 //********************************************************************
93 void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
94 {
95   ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid);
96   myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
97 }
98