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"
9 #include <ModelAPI_AttributeRefAttr.h>
10 #include <ModelAPI_Session.h>
11 #include <ModelAPI_Validator.h>
13 #include <ModuleBase_Definitions.h>
14 #include <Config_WidgetAPI.h>
16 #include <PartSet_ExternalObjectsMgr.h>
17 #include <SketchPlugin_Feature.h>
19 #include <XGUI_Workshop.h>
21 #include <XGUI_ModuleConnector.h>
22 #include <XGUI_Displayer.h>
23 #include <XGUI_SelectionMgr.h>
24 #include <XGUI_Selection.h>
26 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
27 ModuleBase_IWorkshop* theWorkshop,
28 const Config_WidgetAPI* theData,
29 const std::string& theParentId)
30 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId)
32 myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), true);
35 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
37 delete myExternalObjectMgr;
40 //********************************************************************
41 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
43 bool aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
45 ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
46 aValid = myExternalObjectMgr->isValidObject(anObject);
51 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
53 GeomShapePtr& theShape)
55 ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
57 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
58 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
59 std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
60 // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
61 // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
62 if (aSPFeature.get() == NULL && myExternalObjectMgr->useExternal()) {
63 GeomShapePtr aShape = theShape;
65 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
67 aShape = aResult->shape();
69 if (aShape.get() != NULL && !aShape->isNull())
70 theObject = myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);
74 //********************************************************************
75 void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
77 ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid);
78 myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);