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_WidgetMultiSelector.h"
23 #include <ModelAPI_AttributeRefAttr.h>
24 #include <ModelAPI_AttributeSelectionList.h>
25 #include <ModelAPI_AttributeRefList.h>
26 #include <ModelAPI_Session.h>
27 #include <ModelAPI_Validator.h>
29 #include <ModuleBase_Definitions.h>
30 #include <ModuleBase_Tools.h>
31 #include <ModuleBase_IWorkshop.h>
32 #include <ModuleBase_ISelection.h>
33 #include <ModuleBase_ViewerPrs.h>
35 #include <Config_WidgetAPI.h>
37 #include <PartSet_Tools.h>
38 #include <PartSet_ExternalObjectsMgr.h>
39 #include <SketchPlugin_Feature.h>
41 #include <SketchPlugin_ConstraintRigid.h>
43 #include <XGUI_Workshop.h>
47 PartSet_WidgetMultiSelector::PartSet_WidgetMultiSelector(QWidget* theParent,
48 ModuleBase_IWorkshop* theWorkshop,
49 const Config_WidgetAPI* theData)
50 : ModuleBase_WidgetMultiSelector(theParent, theWorkshop, theData)
52 myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
53 theData->getProperty("can_create_external"), false);
56 PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector()
58 delete myExternalObjectMgr;
61 //********************************************************************
62 bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
64 bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
66 ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
67 aValid = myExternalObjectMgr->isValidObject(anObject);
72 //********************************************************************
73 void PartSet_WidgetMultiSelector::restoreAttributeValue(const AttributePtr& theAttribute,
76 ModuleBase_WidgetMultiSelector::restoreAttributeValue(theAttribute, theValid);
78 myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
81 void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
83 GeomShapePtr& theShape)
85 ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape);
87 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
88 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
89 std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
90 // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
91 // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
92 if (aSPFeature.get() == NULL) {
93 ObjectPtr anExternalObject = ObjectPtr();
94 GeomShapePtr anExternalShape = GeomShapePtr();
95 if (myExternalObjectMgr->useExternal()) {
96 if (myExternalObjectMgr->canCreateExternal()) {
97 GeomShapePtr aShape = theShape;
99 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
101 aShape = aResult->shape();
103 if (aShape.get() != NULL && !aShape->isNull())
105 myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);
108 anExternalObject = theObject;
109 anExternalShape = theShape;
112 /// the object is null if the selected feature is "external"(not sketch entity feature of the
113 /// current sketch) and it is not created by object manager
114 theObject = anExternalObject;
115 theShape = anExternalShape;