]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_CustomPrs.cpp
Salome HOME
Issue #591 - Highlight of the first argument of constraints
[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 }
31
32 void PartSet_CustomPrs::setCustomized(const ObjectPtr& theObject)
33 {
34 /*  QMap<ResultPtr, QList<GeomShapePtr> > aNewCustomized;
35
36   QList<GeomShapePtr> aShapeList;
37   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
38   if (aResult.get()) {
39     aNewCustomized[aResult] = aShapeList;
40   }
41   else {
42     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
43     if (aFeature.get()) {
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);
49         if (anObject.get()) {
50           ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
51           if (aResult.get())
52             aNewCustomized[aResult] = aShapeList;
53         }
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);
60             if (anObject.get()) {
61               ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
62               if (aResult.get())
63                 aNewCustomized[aResult] = aShapeList;
64             }
65           }
66         }
67       }
68     }
69   }
70
71   bool isDone = false;
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;
84   }
85
86   myCustomized.clear();
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);
91     if (anAISObj.get()) {
92       Handle(AIS_InteractiveObject) anAISIO = anAISObj->impl<Handle(AIS_InteractiveObject)>();
93       aContext->Redisplay(anAISIO, false);
94     }
95     isDone = aDisplayer->customizeObject(aResult);
96   }
97
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);
103     if (anAISObj.get())
104       isDone = customisePresentation(aResult, anAISObj, 0) || isDone;
105   }
106   if (isDone)
107     aDisplayer->updateViewer();*/
108 }
109
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)
118 {
119   bool isDone = false;
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]);
124     /*
125     Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
126
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);
136         }
137       }
138     }
139     thePrs->setPointMarker(5, 5.); // Set point as a '+' symbol*/
140   }
141   /*
142   std::vector<int> aColor;
143
144   getResultColor(theResult, aColor);
145
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();
153   }
154   return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);*/
155   return isDone;
156 }