Salome HOME
Issue #2206 Avoid the ability to cancel the current sketch when saving,
[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 #include "PartSet_Module.h"
23 #include "PartSet_SketcherMgr.h"
24
25 #include <ModelAPI_AttributeRefAttr.h>
26 #include <ModelAPI_Session.h>
27 #include <ModelAPI_Validator.h>
28
29 #include <ModuleBase_Definitions.h>
30 #include <ModuleBase_ViewerPrs.h>
31
32 #include <Config_WidgetAPI.h>
33
34 #include <PartSet_ExternalObjectsMgr.h>
35 #include <SketchPlugin_Feature.h>
36
37 #include <XGUI_Workshop.h>
38
39 #include <XGUI_ModuleConnector.h>
40 #include <XGUI_Displayer.h>
41 #include <XGUI_SelectionMgr.h>
42 #include <XGUI_Selection.h>
43 #include <XGUI_Tools.h>
44
45 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
46                                                          ModuleBase_IWorkshop* theWorkshop,
47                                                          const Config_WidgetAPI* theData)
48 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
49 {
50   myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
51   myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
52                                          theData->getProperty("can_create_external"), true);
53 }
54
55 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
56 {
57   delete myExternalObjectMgr;
58 }
59
60 //********************************************************************
61 bool PartSet_WidgetShapeSelector::activateSelectionAndFilters(bool toActivate)
62 {
63   bool aHasSelectionFilter = ModuleBase_WidgetShapeSelector::activateSelectionAndFilters
64                                                                            (toActivate);
65   if (!myUseSketchPlane) {
66     XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
67     PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(aWorkshop->module());
68     bool isUsePlaneFilterOnly = !toActivate;
69     aModule->sketchMgr()->activatePlaneFilter(isUsePlaneFilterOnly);
70   }
71   return aHasSelectionFilter;
72 }
73
74 //********************************************************************
75 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
76 {
77   bool aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
78   if (aValid) {
79     ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
80     aValid = myExternalObjectMgr->isValidObject(anObject);
81   }
82   return aValid;
83 }
84
85 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
86                                                    ObjectPtr& theObject,
87                                                    GeomShapePtr& theShape)
88 {
89   ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
90
91   myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
92                                         myWorkshop, sketch(), myIsInValidate);
93 }
94
95 //********************************************************************
96 void PartSet_WidgetShapeSelector::restoreAttributeValue(const AttributePtr& theAttribute,
97                                                         const bool theValid)
98 {
99   ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
100   myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
101 }
102