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"
22 #include "PartSet_Module.h"
23 #include "PartSet_SketcherMgr.h"
25 #include <ModelAPI_AttributeRefAttr.h>
26 #include <ModelAPI_Session.h>
27 #include <ModelAPI_Validator.h>
29 #include <ModuleBase_Definitions.h>
30 #include <ModuleBase_ViewerPrs.h>
32 #include <Config_WidgetAPI.h>
34 #include <PartSet_ExternalObjectsMgr.h>
35 #include <SketchPlugin_Feature.h>
37 #include <XGUI_Workshop.h>
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>
45 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
46 ModuleBase_IWorkshop* theWorkshop,
47 const Config_WidgetAPI* theData)
48 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
50 myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
51 myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
52 theData->getProperty("can_create_external"), true);
55 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
57 delete myExternalObjectMgr;
60 //********************************************************************
61 bool PartSet_WidgetShapeSelector::activateSelectionAndFilters(bool toActivate)
63 bool aHasSelectionFilter = ModuleBase_WidgetShapeSelector::activateSelectionAndFilters
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);
71 return aHasSelectionFilter;
74 //********************************************************************
75 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
77 bool aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
79 ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
80 aValid = myExternalObjectMgr->isValidObject(anObject);
85 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
87 GeomShapePtr& theShape)
89 ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
91 myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
92 myWorkshop, sketch(), myIsInValidate);
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,
98 // try to create an exernal object
99 // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
100 if (aSPFeature.get() == NULL) {
101 ObjectPtr anExternalObject = ObjectPtr();
102 GeomShapePtr anExternalShape = GeomShapePtr();
103 if (myExternalObjectMgr->useExternal()) {
104 if (myExternalObjectMgr->canCreateExternal()) {
105 GeomShapePtr aShape = theShape;
107 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
109 aShape = aResult->shape();
111 if (aShape.get() != NULL && !aShape->isNull())
113 myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);
115 else { /// use objects of found selection
116 anExternalObject = theObject;
117 anExternalShape = theShape;
120 /// the object is null if the selected feature is "external"(not sketch entity feature of the
121 /// current sketch) and it is not created by object manager
122 theObject = anExternalObject;
123 theShape = anExternalShape;
127 //********************************************************************
128 void PartSet_WidgetShapeSelector::restoreAttributeValue(const AttributePtr& theAttribute,
131 ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
132 myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);