]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetShapeSelector.cpp
Salome HOME
Prevent crash of small arcs presentations
[modules/shaper.git] / src / PartSet / PartSet_WidgetShapeSelector.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "PartSet_WidgetShapeSelector.h"
22
23 #include "PartSet_CenterPrs.h"
24 #include "PartSet_Module.h"
25 #include "PartSet_SketcherMgr.h"
26
27 #include <ModelAPI_AttributeRefAttr.h>
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_Validator.h>
30
31 #include <ModuleBase_Definitions.h>
32 #include <ModuleBase_ViewerPrs.h>
33
34 #include <Config_WidgetAPI.h>
35
36 #include <PartSet_ExternalObjectsMgr.h>
37 #include <SketchPlugin_Feature.h>
38
39 #include <XGUI_Workshop.h>
40
41 #include <XGUI_ModuleConnector.h>
42 #include <XGUI_Displayer.h>
43 #include <XGUI_SelectionMgr.h>
44 #include <XGUI_Selection.h>
45 #include <XGUI_Tools.h>
46
47 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
48                                                          ModuleBase_IWorkshop* theWorkshop,
49                                                          const Config_WidgetAPI* theData)
50 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
51 {
52   myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
53   myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
54                                          theData->getProperty("can_create_external"), true);
55 }
56
57 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
58 {
59   delete myExternalObjectMgr;
60 }
61
62 //********************************************************************
63 void PartSet_WidgetShapeSelector::selectionFilters(QIntList& theModuleSelectionFilters,
64                                                    SelectMgr_ListOfFilter& theSelectionFilters)
65 {
66   ModuleBase_WidgetShapeSelector::selectionFilters(theModuleSelectionFilters, theSelectionFilters);
67
68   if (!myUseSketchPlane) {
69     if (theModuleSelectionFilters.contains(SF_SketchPlaneFilter))
70       theModuleSelectionFilters.removeAll(SF_SketchPlaneFilter);
71   }
72 }
73
74 //********************************************************************
75 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
76 {
77   bool aValid = false;
78   if (thePrs.get() && thePrs->interactive().get() &&
79       thePrs->interactive()->IsKind(STANDARD_TYPE(PartSet_CenterPrs)))
80     aValid = true; // we should not check acceptSubShape for such presentation
81   else
82     aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
83
84   if (aValid) {
85     ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
86     aValid = myExternalObjectMgr->isValidObject(anObject);
87   }
88   return aValid;
89 }
90
91 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
92                                                    ObjectPtr& theObject,
93                                                    GeomShapePtr& theShape)
94 {
95   ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
96
97   myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
98                                         myWorkshop, sketch(), myIsInValidate);
99 }
100
101 //********************************************************************
102 void PartSet_WidgetShapeSelector::restoreAttributeValue(const AttributePtr& theAttribute,
103                                                         const bool theValid)
104 {
105   ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
106   myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
107 }
108