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_Tools.h>
17 #include <PartSet_ExternalObjectsMgr.h>
18 #include <SketchPlugin_Feature.h>
20 #include <SketchPlugin_ConstraintRigid.h>
22 #include <XGUI_Workshop.h>
24 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
25 ModuleBase_IWorkshop* theWorkshop,
26 const Config_WidgetAPI* theData,
27 const std::string& theParentId)
28 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId)
30 myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), true);
33 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
35 delete myExternalObjectMgr;
38 bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
40 ObjectPtr aSelectedObject = theSelectedObject;
41 GeomShapePtr aShape = theShape;
43 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aSelectedObject);
44 if (aSelectedFeature == myFeature) // In order to avoid selection of the same object
46 // Do check using of external feature
47 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
48 std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
50 // Do check that we can use external feature
51 if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myExternalObjectMgr->useExternal()))
54 if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myExternalObjectMgr->useExternal()) {
55 aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch());
57 // Processing of sketch object
58 DataPtr aData = myFeature->data();
60 AttributePtr aAttr = aData->attribute(attributeID());
61 AttributeRefAttrPtr aRefAttr =
62 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
64 // it is possible that the point feature is selected. It should be used itself
65 // instead of searching an attribute for the shape
66 bool aShapeIsResult = false;
67 /*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
68 if (aResult.get() != NULL) {
69 GeomShapePtr aShapePtr = aResult->shape();
70 // it is important to call isEqual of the shape of result.
71 // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is
72 // GeomAPI_Shape. It is important to use the realization of the isEqual method from
73 // GeomAPI_Vertex class
74 aShapeIsResult = aShapePtr.get() != NULL && aShapePtr->isEqual(theShape);
77 AttributePtr aPntAttr;
78 if (!aShapeIsResult) {
79 TopoDS_Shape aTDSShape = aShape->impl<TopoDS_Shape>();
80 aPntAttr = PartSet_Tools::findAttributeBy2dPoint(aSelectedObject, aTDSShape, mySketch);
82 // this is an alternative, whether the attribute should be set or object in the attribute
83 // the first check is the attribute because the object already exist
84 // the object is set only if there is no selected attribute
85 // test case is - preselection for distance operation, which contains two points selected on lines
87 aRefAttr->setAttr(aPntAttr);
88 else if (aSelectedObject)
89 aRefAttr->setObject(aSelectedObject);
94 return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, aShape);
97 //********************************************************************
98 void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
100 ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid);
101 myExternalObjectMgr->removeExternal(sketch(), myFeature);