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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "PartSet_WidgetShapeSelector.h"
21 #include "PartSet_Module.h"
22 #include "PartSet_SketcherMgr.h"
24 #include <ModelAPI_AttributeRefAttr.h>
25 #include <ModelAPI_Session.h>
26 #include <ModelAPI_Validator.h>
28 #include <ModuleBase_Definitions.h>
29 #include <ModuleBase_ViewerPrs.h>
31 #include <Config_WidgetAPI.h>
33 #include <PartSet_ExternalObjectsMgr.h>
34 #include <SketchPlugin_Feature.h>
36 #include <XGUI_Workshop.h>
38 #include <XGUI_ModuleConnector.h>
39 #include <XGUI_Displayer.h>
40 #include <XGUI_SelectionMgr.h>
41 #include <XGUI_Selection.h>
42 #include <XGUI_Tools.h>
44 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
45 ModuleBase_IWorkshop* theWorkshop,
46 const Config_WidgetAPI* theData)
47 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
49 myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
50 myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
51 theData->getProperty("can_create_external"), true);
54 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
56 delete myExternalObjectMgr;
59 //********************************************************************
60 bool PartSet_WidgetShapeSelector::activateSelectionAndFilters(bool toActivate)
62 bool aHasSelectionFilter = ModuleBase_WidgetShapeSelector::activateSelectionAndFilters
64 if (!myUseSketchPlane) {
65 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
66 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(aWorkshop->module());
67 bool isUsePlaneFilterOnly = !toActivate;
68 aModule->sketchMgr()->activatePlaneFilter(isUsePlaneFilterOnly);
70 return aHasSelectionFilter;
73 //********************************************************************
74 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
76 bool aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
78 ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
79 aValid = myExternalObjectMgr->isValidObject(anObject);
84 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
86 GeomShapePtr& theShape)
88 ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
90 myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
91 myWorkshop, sketch(), myIsInValidate);
93 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
94 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
95 std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
96 // there is no a sketch feature is selected, but the shape exists,
97 // 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);
114 else { /// use objects of found selection
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;
126 //********************************************************************
127 void PartSet_WidgetShapeSelector::restoreAttributeValue(const AttributePtr& theAttribute,
130 ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
131 myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);