]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetFeaturePointSelector.cpp
Salome HOME
Task 2.4. Ability to modify the radius of circles and arcs of circle with the mouse
[modules/shaper.git] / src / PartSet / PartSet_WidgetFeaturePointSelector.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_WidgetFeaturePointSelector.cpp
4 // Created:     28 Feb 2017
5 // Author:      Natalia ERMOLAEVA
6
7 #include <Config_WidgetAPI.h>
8
9 #include <Events_Loop.h>
10
11 #include <GeomDataAPI_Point2D.h>
12 #include <GeomDataAPI_Point.h>
13 #include <GeomAPI_Edge.h>
14 #include <GeomAPI_Pnt2d.h>
15 #include <GeomAlgoAPI_ShapeTools.h>
16
17 #include <ModuleBase_ISelection.h>
18 #include <ModuleBase_ViewerPrs.h>
19
20 #include <ModelAPI_Events.h>
21 #include <ModelAPI_Feature.h>
22 #include <ModelAPI_Tools.h>
23
24 #include <ModuleBase_IViewWindow.h>
25 #include <ModuleBase_IWorkshop.h>
26 #include <ModuleBase_IModule.h>
27
28 #include "PartSet_WidgetFeaturePointSelector.h"
29 #include "PartSet_Tools.h"
30
31 //#include <SketchPlugin_ConstraintCoincidence.h>
32 //#include <SketchPlugin_Constraint.h>
33 #include <SketchPlugin_Point.h>
34 #include <SketchPlugin_Trim.h>
35
36 #include <XGUI_Tools.h>
37 #include <XGUI_Workshop.h>
38 #include <XGUI_Displayer.h>
39 #include <XGUI_ViewerProxy.h>
40
41 #include <QWidget>
42 #include <QMouseEvent>
43
44 #define HIGHLIGHT_STAYS_PROBLEM
45 #ifdef HIGHLIGHT_STAYS_PROBLEM
46 #include <Quantity_Color.hxx>
47 #define SKETCH_ENTITY_COLOR "225,0,0"
48 #endif
49
50 PartSet_WidgetFeaturePointSelector::PartSet_WidgetFeaturePointSelector(QWidget* theParent,
51                                                          ModuleBase_IWorkshop* theWorkshop,
52                                                          const Config_WidgetAPI* theData)
53 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
54 {
55 }
56
57 PartSet_WidgetFeaturePointSelector::~PartSet_WidgetFeaturePointSelector()
58 {
59 }
60
61 //********************************************************************
62 bool PartSet_WidgetFeaturePointSelector::isValidSelection(
63                                         const std::shared_ptr<ModuleBase_ViewerPrs>& theValue)
64 {
65   return ModuleBase_WidgetShapeSelector::isValidSelection(theValue);
66   //return true;
67 }
68
69 //********************************************************************
70 bool PartSet_WidgetFeaturePointSelector::activateSelectionAndFilters(bool toActivate)
71 {
72 #ifdef HIGHLIGHT_STAYS_PROBLEM
73   Handle(AIS_InteractiveContext) aContext =
74                             XGUI_Tools::workshop(myWorkshop)->viewer()->AISContext();
75   Quantity_Color aColor;
76   Handle(Graphic3d_HighlightStyle) aHStyle = aContext->HighlightStyle();
77   Handle(Graphic3d_HighlightStyle) aSStyle = aContext->SelectionStyle();
78   if (toActivate) {
79     std::vector<int> aColors;
80     aColors = Config_PropManager::color("Visualization", "sketch_entity_color");
81     aColor = Quantity_Color(aColors[0] / 255., aColors[1] / 255., aColors[2] / 255.,
82                             Quantity_TOC_RGB);
83     myHighlightColor = aHStyle->Color();
84     mySelectionColor = aSStyle->Color();
85   }
86   else {
87     aColor = myHighlightColor;
88   }
89   aHStyle->SetColor(aColor);
90   aContext->SetHighlightStyle(aHStyle);
91
92   aSStyle->SetColor(aColor);
93   aContext->SetSelectionStyle(aSStyle);
94
95 #endif
96
97   return ModuleBase_WidgetShapeSelector::activateSelectionAndFilters(toActivate);
98 }
99
100 //********************************************************************
101 void PartSet_WidgetFeaturePointSelector::activateCustom()
102 {
103   ModuleBase_WidgetShapeSelector::activateCustom();
104
105   myWorkshop->module()->activateCustomPrs(myFeature,
106                             ModuleBase_IModule::CustomizeHighlightedObjects, true);
107 }
108
109 //********************************************************************
110 void PartSet_WidgetFeaturePointSelector::deactivate()
111 {
112   ModuleBase_WidgetShapeSelector::deactivate();
113 }
114
115 //********************************************************************
116 void PartSet_WidgetFeaturePointSelector::mouseMoved(ModuleBase_IViewWindow* theWindow,
117                                                     QMouseEvent* theEvent)
118 {
119   ModuleBase_ISelection* aSelect = myWorkshop->selection();
120   QList<ModuleBase_ViewerPrsPtr> aHighlighted = aSelect->getHighlighted();
121
122   ModuleBase_ViewerPrsPtr aPrs = !aHighlighted.empty() ? aHighlighted.first()
123                                                        : ModuleBase_ViewerPrsPtr();
124   fillFeature(aPrs, theWindow, theEvent);
125 }
126
127 //********************************************************************
128 void PartSet_WidgetFeaturePointSelector::mouseReleased(ModuleBase_IViewWindow* theWindow,
129                                                        QMouseEvent* theEvent)
130 {
131   // the contex menu release by the right button should not be processed by this widget
132   if (theEvent->button() != Qt::LeftButton)
133     return;
134
135   std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
136                           std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
137                           feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
138   ObjectPtr aPreviewObject = aRefPreviewAttr->value();
139   // do not move focus from the current widget if the object is not highlighted/selected
140   if (!aPreviewObject.get())
141     return;
142
143   // set parameters of preview into parameters of selection in the feature
144   std::shared_ptr<ModelAPI_AttributeReference> aRefSelectedAttr =
145                           std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
146                           feature()->data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
147   aRefSelectedAttr->setValue(aRefPreviewAttr->value());
148
149   std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
150                           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
151                           feature()->data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
152   std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
153                           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
154                           feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
155   aPointSelectedAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
156
157   updateObject(feature());
158
159   emit focusOutWidget(this);
160   // we need to deselect base feature for better visibility of selected feature
161   XGUI_Tools::workshop(myWorkshop)->displayer()->clearSelected(false);
162 }
163
164 //********************************************************************
165 bool PartSet_WidgetFeaturePointSelector::fillFeature(
166                             const std::shared_ptr<ModuleBase_ViewerPrs>& theSelectedPrs,
167                             ModuleBase_IViewWindow* theWindow,
168                             QMouseEvent* theEvent)
169 {
170   bool aFilled = false;
171   ObjectPtr anObject;
172   if (theSelectedPrs.get() && theSelectedPrs->object().get())
173     anObject = theSelectedPrs->object();
174
175   std::shared_ptr<ModelAPI_AttributeReference> aRef =
176                           std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
177                           feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
178   aRef->setValue(anObject);
179
180   std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint =
181                   std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
182                   feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
183   std::shared_ptr<GeomAPI_Pnt2d> aPoint = PartSet_Tools::getPnt2d(theEvent, theWindow, mySketch);
184   anAttributePoint->setValue(aPoint);
185   // redisplay AIS presentation in viewer
186 #ifndef HIGHLIGHT_STAYS_PROBLEM
187   // an attempt to clear highlighted item in the viewer: but of OCCT
188   XGUI_Tools::workshop(myWorkshop)->displayer()->clearSelected(true);
189 #endif
190   updateObject(feature());
191   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
192
193   aFilled = true;
194
195   return aFilled;
196 }
197
198 //********************************************************************
199 QList<ModuleBase_ViewerPrsPtr> PartSet_WidgetFeaturePointSelector::getAttributeSelection() const
200 {
201   return QList<ModuleBase_ViewerPrsPtr>();
202 }
203
204 //********************************************************************
205 bool PartSet_WidgetFeaturePointSelector::setSelection(
206                                           QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
207                                           const bool theToValidate)
208 {
209   // false is returned to do not emit focus out widget by selected sub-shape
210   return false;
211 }
212
213 void PartSet_WidgetFeaturePointSelector::setPreSelection(
214                                   const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected,
215                                   ModuleBase_IViewWindow* theWnd,
216                                   QMouseEvent* theEvent)
217 {
218   // the method is empty because firstly by starging of the feature there is no selection of
219   // sub-segments in the viewer, secondly preselection of restart operation is processed by
220   // special reentrant message sent by the feature
221 }