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_CenterPrs.h>
38 #include <PartSet_Tools.h>
39 #include <PartSet_ExternalObjectsMgr.h>
40 #include <SketchPlugin_Feature.h>
42 #include <SketchPlugin_ConstraintRigid.h>
44 #include <XGUI_Workshop.h>
48 PartSet_WidgetMultiSelector::PartSet_WidgetMultiSelector(QWidget* theParent,
49 ModuleBase_IWorkshop* theWorkshop,
50 const Config_WidgetAPI* theData)
51 : ModuleBase_WidgetMultiSelector(theParent, theWorkshop, theData)
53 myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
54 theData->getProperty("can_create_external"), false);
57 PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector()
59 delete myExternalObjectMgr;
62 //********************************************************************
63 bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
66 if (thePrs.get() && thePrs->interactive().get() &&
67 thePrs->interactive()->IsKind(STANDARD_TYPE(PartSet_CenterPrs)))
68 aValid = true; // we should not check acceptSubShape for such presentation
70 aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
73 ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
74 aValid = myExternalObjectMgr->isValidObject(anObject);
79 //********************************************************************
80 void PartSet_WidgetMultiSelector::restoreAttributeValue(const AttributePtr& theAttribute,
83 ModuleBase_WidgetMultiSelector::restoreAttributeValue(theAttribute, theValid);
85 myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
88 void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
90 GeomShapePtr& theShape)
92 ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape);
94 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
95 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
96 std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
97 // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
98 // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
99 if (aSPFeature.get() == NULL) {
100 ObjectPtr anExternalObject = ObjectPtr();
101 GeomShapePtr anExternalShape = GeomShapePtr();
102 if (myExternalObjectMgr->useExternal()) {
103 if (myExternalObjectMgr->canCreateExternal()) {
104 GeomShapePtr aShape = theShape;
106 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
108 aShape = aResult->shape();
110 if (aShape.get() != NULL && !aShape->isNull())
112 myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);
115 anExternalObject = theObject;
116 anExternalShape = theShape;
119 /// the object is null if the selected feature is "external"(not sketch entity feature of the
120 /// current sketch) and it is not created by object manager
121 theObject = anExternalObject;
122 theShape = anExternalShape;