1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_WidgetShapeSelector.cpp
4 // Created: 27 Nov 2014
5 // Author: Vitaly Smetannikov
7 #include "PartSet_WidgetShapeSelector.h"
8 #include "PartSet_Module.h"
9 #include "PartSet_SketcherMgr.h"
11 #include <ModelAPI_AttributeRefAttr.h>
12 #include <ModelAPI_Session.h>
13 #include <ModelAPI_Validator.h>
15 #include <ModuleBase_Definitions.h>
16 #include <ModuleBase_ViewerPrs.h>
18 #include <Config_WidgetAPI.h>
20 #include <PartSet_ExternalObjectsMgr.h>
21 #include <SketchPlugin_Feature.h>
23 #include <XGUI_Workshop.h>
25 #include <XGUI_ModuleConnector.h>
26 #include <XGUI_Displayer.h>
27 #include <XGUI_SelectionMgr.h>
28 #include <XGUI_Selection.h>
29 #include <XGUI_Tools.h>
31 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
32 ModuleBase_IWorkshop* theWorkshop,
33 const Config_WidgetAPI* theData)
34 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
36 myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
37 myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), true);
40 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
42 delete myExternalObjectMgr;
45 //********************************************************************
46 bool PartSet_WidgetShapeSelector::activateSelectionAndFilters(bool toActivate)
48 bool aHasSelectionFilter = ModuleBase_WidgetShapeSelector::activateSelectionAndFilters
50 if (!myUseSketchPlane) {
51 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
52 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(aWorkshop->module());
53 bool isUsePlaneFilterOnly = !toActivate;
54 aModule->sketchMgr()->activatePlaneFilter(isUsePlaneFilterOnly);
56 return aHasSelectionFilter;
59 //********************************************************************
60 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
62 bool aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
64 ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
65 aValid = myExternalObjectMgr->isValidObject(anObject);
70 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
72 GeomShapePtr& theShape)
74 ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
76 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
77 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
78 std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
79 // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
80 // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
81 if (aSPFeature.get() == NULL && myExternalObjectMgr->useExternal()) {
82 GeomShapePtr aShape = theShape;
84 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
86 aShape = aResult->shape();
88 if (aShape.get() != NULL && !aShape->isNull())
89 theObject = myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);
93 //********************************************************************
94 void PartSet_WidgetShapeSelector::restoreAttributeValue(const AttributePtr& theAttribute,
97 ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
98 myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);