Salome HOME
2990969e94f9d4c6355deb77b5b44c6aadcc44b1
[modules/shaper.git] / src / PartSet / PartSet_CustomPrs.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_CustomPrs.cpp
4 // Created:     30 Jun 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include <PartSet_CustomPrs.h>
8
9 #include <XGUI_ModuleConnector.h>
10 #include <XGUI_Workshop.h>
11 #include <XGUI_Displayer.h>
12
13 #include <ModuleBase_IWorkshop.h>
14 #include <ModuleBase_IViewer.h>
15
16 #include <GeomValidators_Tools.h>
17
18 #include <ModelAPI_Attribute.h>
19 #include <ModelAPI_AttributeSelectionList.h>
20
21 #include <Config_PropManager.h>
22
23 #include <AIS_InteractiveContext.hxx>
24
25 #define OPERATION_PARAMETER_COLOR "255, 255, 0"
26
27 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
28   : myWorkshop(theWorkshop)
29 {
30   Handle(PartSet_OperationPrs) myOperationPrs = new PartSet_OperationPrs(); /// AIS presentation for the feature of operation
31 }
32
33 void PartSet_CustomPrs::setCustomized(const FeaturePtr& theFeature)
34 {
35
36   myOperationPrs->setFeature(theFeature);
37   /*  QMap<ResultPtr, QList<GeomShapePtr> > aNewCustomized;
38
39   QList<GeomShapePtr> aShapeList;
40   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
41   if (aResult.get()) {
42     aNewCustomized[aResult] = aShapeList;
43   }
44   else {
45     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
46     if (aFeature.get()) {
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);
52         if (anObject.get()) {
53           ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
54           if (aResult.get())
55             aNewCustomized[aResult] = aShapeList;
56         }
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);
63             if (anObject.get()) {
64               ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
65               if (aResult.get())
66                 aNewCustomized[aResult] = aShapeList;
67             }
68           }
69         }
70       }
71     }
72   }
73
74   bool isDone = false;
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;
87   }
88
89   myCustomized.clear();
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);
94     if (anAISObj.get()) {
95       Handle(AIS_InteractiveObject) anAISIO = anAISObj->impl<Handle(AIS_InteractiveObject)>();
96       aContext->Redisplay(anAISIO, false);
97     }
98     isDone = aDisplayer->customizeObject(aResult);
99   }
100
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);
106     if (anAISObj.get())
107       isDone = customisePresentation(aResult, anAISObj, 0) || isDone;
108   }
109   if (isDone)
110     aDisplayer->updateViewer();*/
111 }
112
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)
121 {
122   bool isDone = false;
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]);
127     /*
128     Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
129
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);
139         }
140       }
141     }
142     thePrs->setPointMarker(5, 5.); // Set point as a '+' symbol*+/
143   }
144   /*
145   std::vector<int> aColor;
146
147   getResultColor(theResult, aColor);
148
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();
156   }
157   return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);*/
158   return isDone;
159 }