1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "PartSet_WidgetShapeSelector.h"
22 #include "PartSet_CenterPrs.h"
23 #include "PartSet_Module.h"
24 #include "PartSet_SketcherMgr.h"
26 #include <ModelAPI_AttributeRefAttr.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Validator.h>
30 #include <ModuleBase_Definitions.h>
31 #include <ModuleBase_ViewerPrs.h>
33 #include <Config_WidgetAPI.h>
35 #include <PartSet_ExternalObjectsMgr.h>
36 #include <SketchPlugin_Feature.h>
38 #include <XGUI_Workshop.h>
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>
46 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
47 ModuleBase_IWorkshop* theWorkshop,
48 const Config_WidgetAPI* theData)
49 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
51 myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
52 myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
53 theData->getProperty("can_create_external"), true);
56 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
58 delete myExternalObjectMgr;
61 //********************************************************************
62 void PartSet_WidgetShapeSelector::selectionFilters(QIntList& theModuleSelectionFilters,
63 SelectMgr_ListOfFilter& theSelectionFilters)
65 ModuleBase_WidgetShapeSelector::selectionFilters(theModuleSelectionFilters, theSelectionFilters);
67 if (!myUseSketchPlane) {
68 if (theModuleSelectionFilters.contains(SF_SketchPlaneFilter))
69 theModuleSelectionFilters.removeAll(SF_SketchPlaneFilter);
73 //********************************************************************
74 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
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
81 aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
84 ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
85 aValid = myExternalObjectMgr->isValidObject(anObject);
90 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
92 GeomShapePtr& theShape)
94 ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
96 myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
97 myWorkshop, sketch(), myIsInValidate);
100 //********************************************************************
101 void PartSet_WidgetShapeSelector::restoreAttributeValue(const AttributePtr& theAttribute,
104 ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
105 myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);