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)
32 void PartSet_CustomPrs::setCustomized(const ObjectPtr& theObject)
34 /* QMap<ResultPtr, QList<GeomShapePtr> > aNewCustomized;
36 QList<GeomShapePtr> aShapeList;
37 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
39 aNewCustomized[aResult] = aShapeList;
42 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
44 std::list<AttributePtr> anAttributes = aFeature->data()->attributes("");
45 std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
46 for (; anIt != aLast; anIt++) {
47 AttributePtr anAttribute = *anIt;
48 ObjectPtr anObject = GeomValidators_Tools::getObject(anAttribute);
50 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
52 aNewCustomized[aResult] = aShapeList;
54 else if (anAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) {
55 std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList =
56 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
57 for(int i = 0; i < aCurSelList->size(); i++) {
58 std::shared_ptr<ModelAPI_AttributeSelection> aSelAttribute = aCurSelList->value(i);
59 ObjectPtr anObject = GeomValidators_Tools::getObject(aSelAttribute);
61 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
63 aNewCustomized[aResult] = aShapeList;
72 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
73 XGUI_Workshop* aWorkshop = aConnector->workshop();
74 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
75 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
76 // find objects which are not customized anymore
77 QMap<ResultPtr, QList<GeomShapePtr> > aNotCustomized;
78 QMap<ResultPtr, QList<GeomShapePtr> >::const_iterator anIt = myCustomized.begin(),
79 aLast = myCustomized.end();
80 for (; anIt != aLast; anIt++) {
81 ResultPtr aResult = anIt.key();
82 if (!aNewCustomized.contains(aResult))
83 aNotCustomized[aResult] = aShapeList;
87 // restore the previous state of the object if there is no such object in the new map
88 for (anIt = aNotCustomized.begin(), aLast = aNotCustomized.end(); anIt != aLast; anIt++) {
89 ResultPtr aResult = anIt.key();
90 AISObjectPtr anAISObj = aDisplayer->getAISObject(aResult);
92 Handle(AIS_InteractiveObject) anAISIO = anAISObj->impl<Handle(AIS_InteractiveObject)>();
93 aContext->Redisplay(anAISIO, false);
95 isDone = aDisplayer->customizeObject(aResult);
98 // set customized for the new objects
99 myCustomized = aNewCustomized;
100 for (anIt = myCustomized.begin(), aLast = myCustomized.end(); anIt != aLast; anIt++) {
101 ResultPtr aResult = anIt.key();
102 AISObjectPtr anAISObj = aDisplayer->getAISObject(aResult);
104 isDone = customisePresentation(aResult, anAISObj, 0) || isDone;
107 aDisplayer->updateViewer();*/
110 /*#include <AIS_InteractiveObject.hxx>
111 #include <AIS_Shape.hxx>
112 #include <TopExp_Explorer.hxx>
113 #include <TopoDS_Vertex.hxx>
114 #include <StdPrs_ShadedShape.hxx>
115 #include <StdPrs_WFDeflectionShape.hxx>*/
116 bool PartSet_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
117 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
120 if (myCustomized.contains(theResult)) {
121 std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
122 OPERATION_PARAMETER_COLOR);
123 isDone = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
125 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
127 const Handle(Prs3d_Presentation)& aPresentation = anAISIO->Presentation();
128 if (!aPresentation.IsNull()) {
129 Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAISIO);
130 if (!aShapeAIS.IsNull()) {
131 TopExp_Explorer anExp(aShapeAIS->Shape(), TopAbs_VERTEX);
132 Handle(Prs3d_Drawer) aDrawer = aShapeAIS->Attributes();
133 for (; anExp.More(); anExp.Next()) {
134 const TopoDS_Vertex& aVertex = (const TopoDS_Vertex&)anExp.Current();
135 StdPrs_WFDeflectionShape::Add(aPresentation, aVertex, aDrawer);
139 thePrs->setPointMarker(5, 5.); // Set point as a '+' symbol*/
142 std::vector<int> aColor;
144 getResultColor(theResult, aColor);
146 SessionPtr aMgr = ModelAPI_Session::get();
147 if (aMgr->activeDocument() != theResult->document()) {
148 QColor aQColor(aColor[0], aColor[1], aColor[2]);
149 QColor aNewColor = QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF()/3., aQColor.valueF());
150 aColor[0] = aNewColor.red();
151 aColor[1] = aNewColor.green();
152 aColor[2] = aNewColor.blue();
154 return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);*/