1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_CustomPrs.cpp
4 // Created: 30 Jun 2015
5 // Author: Natalia ERMOLAEVA
7 #include <PartSet_CustomPrs.h>
9 #include <XGUI_ModuleConnector.h>
10 #include <XGUI_Workshop.h>
11 #include <XGUI_Displayer.h>
13 #include <ModuleBase_IWorkshop.h>
14 #include <ModuleBase_IViewer.h>
16 #include <GeomValidators_Tools.h>
18 #include <ModelAPI_Attribute.h>
19 #include <ModelAPI_AttributeSelectionList.h>
21 #include <Config_PropManager.h>
23 #include <AIS_InteractiveContext.hxx>
25 #define OPERATION_PARAMETER_COLOR "255, 255, 0"
27 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
28 : myWorkshop(theWorkshop)
30 Handle(PartSet_OperationPrs) myOperationPrs = new PartSet_OperationPrs(); /// AIS presentation for the feature of operation
33 void PartSet_CustomPrs::setCustomized(const FeaturePtr& theFeature)
36 myOperationPrs->setFeature(theFeature);
37 /* QMap<ResultPtr, QList<GeomShapePtr> > aNewCustomized;
39 QList<GeomShapePtr> aShapeList;
40 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
42 aNewCustomized[aResult] = aShapeList;
45 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
47 std::list<AttributePtr> anAttributes = aFeature->data()->attributes("");
48 std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
49 for (; anIt != aLast; anIt++) {
50 AttributePtr anAttribute = *anIt;
51 ObjectPtr anObject = GeomValidators_Tools::getObject(anAttribute);
53 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
55 aNewCustomized[aResult] = aShapeList;
57 else if (anAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) {
58 std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList =
59 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
60 for(int i = 0; i < aCurSelList->size(); i++) {
61 std::shared_ptr<ModelAPI_AttributeSelection> aSelAttribute = aCurSelList->value(i);
62 ObjectPtr anObject = GeomValidators_Tools::getObject(aSelAttribute);
64 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
66 aNewCustomized[aResult] = aShapeList;
75 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
76 XGUI_Workshop* aWorkshop = aConnector->workshop();
77 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
78 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
79 // find objects which are not customized anymore
80 QMap<ResultPtr, QList<GeomShapePtr> > aNotCustomized;
81 QMap<ResultPtr, QList<GeomShapePtr> >::const_iterator anIt = myCustomized.begin(),
82 aLast = myCustomized.end();
83 for (; anIt != aLast; anIt++) {
84 ResultPtr aResult = anIt.key();
85 if (!aNewCustomized.contains(aResult))
86 aNotCustomized[aResult] = aShapeList;
90 // restore the previous state of the object if there is no such object in the new map
91 for (anIt = aNotCustomized.begin(), aLast = aNotCustomized.end(); anIt != aLast; anIt++) {
92 ResultPtr aResult = anIt.key();
93 AISObjectPtr anAISObj = aDisplayer->getAISObject(aResult);
95 Handle(AIS_InteractiveObject) anAISIO = anAISObj->impl<Handle(AIS_InteractiveObject)>();
96 aContext->Redisplay(anAISIO, false);
98 isDone = aDisplayer->customizeObject(aResult);
101 // set customized for the new objects
102 myCustomized = aNewCustomized;
103 for (anIt = myCustomized.begin(), aLast = myCustomized.end(); anIt != aLast; anIt++) {
104 ResultPtr aResult = anIt.key();
105 AISObjectPtr anAISObj = aDisplayer->getAISObject(aResult);
107 isDone = customisePresentation(aResult, anAISObj, 0) || isDone;
110 aDisplayer->updateViewer();*/
113 /*#include <AIS_InteractiveObject.hxx>
114 #include <AIS_Shape.hxx>
115 #include <TopExp_Explorer.hxx>
116 #include <TopoDS_Vertex.hxx>
117 #include <StdPrs_ShadedShape.hxx>
118 #include <StdPrs_WFDeflectionShape.hxx>*/
119 bool PartSet_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
120 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
123 /*if (myCustomized.contains(theResult)) {
124 std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
125 OPERATION_PARAMETER_COLOR);
126 isDone = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
128 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
130 const Handle(Prs3d_Presentation)& aPresentation = anAISIO->Presentation();
131 if (!aPresentation.IsNull()) {
132 Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAISIO);
133 if (!aShapeAIS.IsNull()) {
134 TopExp_Explorer anExp(aShapeAIS->Shape(), TopAbs_VERTEX);
135 Handle(Prs3d_Drawer) aDrawer = aShapeAIS->Attributes();
136 for (; anExp.More(); anExp.Next()) {
137 const TopoDS_Vertex& aVertex = (const TopoDS_Vertex&)anExp.Current();
138 StdPrs_WFDeflectionShape::Add(aPresentation, aVertex, aDrawer);
142 thePrs->setPointMarker(5, 5.); // Set point as a '+' symbol*+/
145 std::vector<int> aColor;
147 getResultColor(theResult, aColor);
149 SessionPtr aMgr = ModelAPI_Session::get();
150 if (aMgr->activeDocument() != theResult->document()) {
151 QColor aQColor(aColor[0], aColor[1], aColor[2]);
152 QColor aNewColor = QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF()/3., aQColor.valueF());
153 aColor[0] = aNewColor.red();
154 aColor[1] = aNewColor.green();
155 aColor[2] = aNewColor.blue();
157 return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);*/