Salome HOME
updated copyright message
[modules/shaper.git] / src / PartSet / PartSet_WidgetShapeSelector.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "PartSet_WidgetShapeSelector.h"
21
22 #include "PartSet_CenterPrs.h"
23 #include "PartSet_Module.h"
24 #include "PartSet_SketcherMgr.h"
25
26 #include <ModelAPI_AttributeRefAttr.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Validator.h>
29
30 #include <ModuleBase_Definitions.h>
31 #include <ModuleBase_ViewerPrs.h>
32
33 #include <Config_WidgetAPI.h>
34
35 #include <PartSet_ExternalObjectsMgr.h>
36 #include <SketchPlugin_Feature.h>
37
38 #include <XGUI_Workshop.h>
39
40 #include <XGUI_ModuleConnector.h>
41 #include <XGUI_Displayer.h>
42 #include <XGUI_SelectionMgr.h>
43 #include <XGUI_Selection.h>
44 #include <XGUI_Tools.h>
45
46 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
47                                                          ModuleBase_IWorkshop* theWorkshop,
48                                                          const Config_WidgetAPI* theData)
49 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
50 {
51   myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
52   myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
53                                          theData->getProperty("can_create_external"), true);
54 }
55
56 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
57 {
58   delete myExternalObjectMgr;
59 }
60
61 //********************************************************************
62 void PartSet_WidgetShapeSelector::selectionFilters(QIntList& theModuleSelectionFilters,
63                                                    SelectMgr_ListOfFilter& theSelectionFilters)
64 {
65   ModuleBase_WidgetShapeSelector::selectionFilters(theModuleSelectionFilters, theSelectionFilters);
66
67   if (!myUseSketchPlane) {
68     if (theModuleSelectionFilters.contains(SF_SketchPlaneFilter))
69       theModuleSelectionFilters.removeAll(SF_SketchPlaneFilter);
70   }
71 }
72
73 //********************************************************************
74 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
75 {
76   bool aValid = false;
77   if (thePrs.get() && thePrs->interactive().get() &&
78       thePrs->interactive()->IsKind(STANDARD_TYPE(PartSet_CenterPrs)))
79     aValid = true; // we should not check acceptSubShape for such presentation
80   else
81     aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
82
83   if (aValid) {
84     ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
85     aValid = myExternalObjectMgr->isValidObject(anObject);
86   }
87   return aValid;
88 }
89
90 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
91                                                    ObjectPtr& theObject,
92                                                    GeomShapePtr& theShape)
93 {
94   ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
95
96   myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
97                                         myWorkshop, sketch(), myIsInValidate);
98 }
99
100 //********************************************************************
101 void PartSet_WidgetShapeSelector::restoreAttributeValue(const AttributePtr& theAttribute,
102                                                         const bool theValid)
103 {
104   ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
105   myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
106 }
107