1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_OperationPrs.cpp
4 // Created: 01 Jul 2015
5 // Author: Natalia ERMOLAEVA
7 #include "PartSet_OperationPrs.h"
8 #include "PartSet_Tools.h"
10 #include <ModelAPI_Result.h>
11 #include <ModelAPI_Attribute.h>
12 #include <ModelAPI_AttributeRefAttr.h>
13 #include <ModelAPI_AttributeReference.h>
14 #include <ModelAPI_AttributeSelection.h>
15 #include <ModelAPI_AttributeSelectionList.h>
16 #include <GeomValidators_Tools.h>
18 #include <StdPrs_WFDeflectionShape.hxx>
22 IMPLEMENT_STANDARD_HANDLE(PartSet_OperationPrs, ViewerData_AISShape);
23 IMPLEMENT_STANDARD_RTTIEXT(PartSet_OperationPrs, ViewerData_AISShape);
25 PartSet_OperationPrs::PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop)
26 : ViewerData_AISShape(TopoDS_Shape()), myFeature(FeaturePtr()), myWorkshop(theWorkshop)
30 bool PartSet_OperationPrs::canActivate(const FeaturePtr& theFeature)
32 bool aHasSelectionAttribute = false;
34 std::list<AttributePtr> anAttributes = theFeature->data()->attributes("");
35 std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
36 for (; anIt != aLast && !aHasSelectionAttribute; anIt++)
37 aHasSelectionAttribute = isSelectionAttribute(*anIt);
39 return aHasSelectionAttribute;
42 void PartSet_OperationPrs::setFeature(const FeaturePtr& theFeature)
44 myFeature = theFeature;
48 bool PartSet_OperationPrs::dependOn(const ObjectPtr& theResult)
50 return myFeatureShapes.contains(theResult);
53 void PartSet_OperationPrs::updateShapes()
55 myFeatureShapes.clear();
56 getFeatureShapes(myFeatureShapes);
59 void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
60 const Handle(Prs3d_Presentation)& thePresentation,
61 const Standard_Integer theMode)
63 thePresentation->Clear();
65 // create presentations on the base of the shapes
66 Handle(Prs3d_Drawer) aDrawer = Attributes();
67 QMap<ObjectPtr, QList<GeomShapePtr> >::const_iterator anIt = myFeatureShapes.begin(),
68 aLast = myFeatureShapes.end();
69 for (; anIt != aLast; anIt++) {
70 QList<GeomShapePtr> aShapes = anIt.value();
71 QList<GeomShapePtr>::const_iterator aShIt = aShapes.begin(), aShLast = aShapes.end();
72 for (; aShIt != aShLast; aShIt++) {
73 GeomShapePtr aGeomShape = *aShIt;
74 TopoDS_Shape aShape = aGeomShape->impl<TopoDS_Shape>();
75 StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer);
80 void PartSet_OperationPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
81 const Standard_Integer aMode)
83 // the presentation is not used in the selection
86 void addValue(const ObjectPtr& theObject, const GeomShapePtr& theShape,
87 QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes)
89 if (theObjectShapes.contains(theObject))
90 theObjectShapes[theObject].append(theShape);
92 QList<GeomShapePtr> aShapes;
93 aShapes.append(theShape);
94 theObjectShapes[theObject] = aShapes;
98 void PartSet_OperationPrs::getFeatureShapes(QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes)
100 if (!myFeature.get())
103 QList<GeomShapePtr> aShapes;
104 std::list<AttributePtr> anAttributes = myFeature->data()->attributes("");
105 std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
106 for (; anIt != aLast; anIt++) {
107 AttributePtr anAttribute = *anIt;
108 if (!isSelectionAttribute(anAttribute))
111 std::string anAttrType = anAttribute->attributeType();
113 if (anAttrType == ModelAPI_AttributeSelectionList::typeId()) {
114 std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList =
115 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
116 for(int i = 0; i < aCurSelList->size(); i++) {
117 std::shared_ptr<ModelAPI_AttributeSelection> aSelAttribute = aCurSelList->value(i);
118 ResultPtr aResult = aSelAttribute->context();
119 GeomShapePtr aShape = aSelAttribute->value();
121 aShape = aResult->shape();
122 addValue(aResult, aShape, theObjectShapes);
128 if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
129 AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
130 if (anAttr->isObject()) {
131 anObject = anAttr->object();
134 aShape = PartSet_Tools::findShapeBy2DPoint(anAttr, myWorkshop);
135 // the distance point is not found if the point is selected in the 2nd time
136 // TODO: after debug, this check can be removed
139 anObject = anAttr->attr()->owner();
142 if (anAttrType == ModelAPI_AttributeSelection::typeId()) {
143 AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttribute);
144 anObject = anAttr->context();
145 aShape = anAttr->value();
147 if (anAttrType == ModelAPI_AttributeReference::typeId()) {
148 AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(anAttribute);
149 anObject = anAttr->value();
152 if (anObject.get()) {
154 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
156 aShape = aResult->shape();
158 addValue(anObject, aShape, theObjectShapes);
164 bool PartSet_OperationPrs::isSelectionAttribute(const AttributePtr& theAttribute)
166 std::string anAttrType = theAttribute->attributeType();
168 return anAttrType == ModelAPI_AttributeSelectionList::typeId() ||
169 anAttrType == ModelAPI_AttributeRefAttr::typeId() ||
170 anAttrType == ModelAPI_AttributeSelection::typeId() ||
171 anAttrType == ModelAPI_AttributeReference::typeId();