1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "PartSet_WidgetShapeSelector.h"
23 #include "PartSet_CenterPrs.h"
24 #include "PartSet_Module.h"
25 #include "PartSet_SketcherMgr.h"
27 #include <ModelAPI_AttributeRefAttr.h>
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_Validator.h>
31 #include <ModuleBase_Definitions.h>
32 #include <ModuleBase_ViewerPrs.h>
34 #include <Config_WidgetAPI.h>
36 #include <PartSet_ExternalObjectsMgr.h>
37 #include <SketchPlugin_Feature.h>
39 #include <XGUI_Workshop.h>
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>
47 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
48 ModuleBase_IWorkshop* theWorkshop,
49 const Config_WidgetAPI* theData)
50 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
52 myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
53 myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
54 theData->getProperty("can_create_external"), true);
57 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
59 delete myExternalObjectMgr;
62 //********************************************************************
63 void PartSet_WidgetShapeSelector::selectionFilters(QIntList& theModuleSelectionFilters,
64 SelectMgr_ListOfFilter& theSelectionFilters)
66 ModuleBase_WidgetShapeSelector::selectionFilters(theModuleSelectionFilters, theSelectionFilters);
68 if (!myUseSketchPlane) {
69 if (theModuleSelectionFilters.contains(SF_SketchPlaneFilter))
70 theModuleSelectionFilters.removeAll(SF_SketchPlaneFilter);
74 //********************************************************************
75 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
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
82 aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
85 ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
86 aValid = myExternalObjectMgr->isValidObject(anObject);
91 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
93 GeomShapePtr& theShape)
95 ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
97 myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
98 myWorkshop, sketch(), myIsInValidate);
101 //********************************************************************
102 void PartSet_WidgetShapeSelector::restoreAttributeValue(const AttributePtr& theAttribute,
105 ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
106 myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);