]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetFeaturePointSelector.cpp
Salome HOME
#2027 Sketcher Trim feature - linux compilation correction: 100 symbols in a row
[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), myBaseSelected(false)
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 true;
66 }
67
68 //********************************************************************
69 bool PartSet_WidgetFeaturePointSelector::activateSelectionAndFilters(bool toActivate)
70 {
71 #ifdef HIGHLIGHT_STAYS_PROBLEM
72   Handle(AIS_InteractiveContext) aContext =
73                             XGUI_Tools::workshop(myWorkshop)->viewer()->AISContext();
74   Quantity_Color aColor;
75   Handle(Graphic3d_HighlightStyle) aHStyle = aContext->HighlightStyle();
76   Handle(Graphic3d_HighlightStyle) aSStyle = aContext->SelectionStyle();
77   if (toActivate) {
78     std::vector<int> aColors;
79     aColors = Config_PropManager::color("Visualization", "sketch_entity_color",
80                                        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     aHStyle->SetTransparency(0.5f);
87   }
88   else {
89     aColor = myHighlightColor;
90   }
91   aHStyle->SetColor(aColor);
92   aContext->SetHighlightStyle(aHStyle);
93
94   aSStyle->SetColor(aColor);
95   aContext->SetSelectionStyle(aSStyle);
96
97 #endif
98
99   return ModuleBase_WidgetShapeSelector::activateSelectionAndFilters(toActivate);
100 }
101
102 //********************************************************************
103 void PartSet_WidgetFeaturePointSelector::activateCustom()
104 {
105   ModuleBase_WidgetShapeSelector::activateCustom();
106
107   myBaseSelected = false;
108
109   myWorkshop->module()->activateCustomPrs(myFeature,
110                             ModuleBase_IModule::CustomizeHighlightedObjects, true);
111 }
112
113 //********************************************************************
114 void PartSet_WidgetFeaturePointSelector::deactivate()
115 {
116   ModuleBase_WidgetShapeSelector::deactivate();
117 }
118
119 //********************************************************************
120 void PartSet_WidgetFeaturePointSelector::mouseMoved(ModuleBase_IViewWindow* theWindow,
121                                                     QMouseEvent* theEvent)
122 {
123   ModuleBase_ISelection* aSelect = myWorkshop->selection();
124   QList<ModuleBase_ViewerPrsPtr> aHighlighted = aSelect->getHighlighted();
125
126   ModuleBase_ViewerPrsPtr aPrs = !aHighlighted.empty() ? aHighlighted.first()
127                                                        : ModuleBase_ViewerPrsPtr();
128   fillFeature(aPrs, theWindow, theEvent);
129 }
130
131 //********************************************************************
132 void PartSet_WidgetFeaturePointSelector::mouseReleased(ModuleBase_IViewWindow* theWindow,
133                                                        QMouseEvent* theEvent)
134 {
135   // the contex menu release by the right button should not be processed by this widget
136   if (theEvent->button() != Qt::LeftButton)
137     return;
138
139   myBaseSelected = true;
140   emit focusOutWidget(this);
141   // we need to deselect base feature for better visibility of selected feature
142   XGUI_Tools::workshop(myWorkshop)->displayer()->clearSelected(false);
143 }
144
145 //********************************************************************
146 bool PartSet_WidgetFeaturePointSelector::fillFeature(
147                             const std::shared_ptr<ModuleBase_ViewerPrs>& theSelectedPrs,
148                             ModuleBase_IViewWindow* theWindow,
149                             QMouseEvent* theEvent)
150 {
151   bool aFilled = false;
152   ObjectPtr anObject;
153   if (theSelectedPrs.get() && theSelectedPrs->object().get())
154     anObject = theSelectedPrs->object();
155
156   gp_Pnt aPnt = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
157   double aX, anY;
158   Handle(V3d_View) aView = theWindow->v3dView();
159   PartSet_Tools::convertTo2D(aPnt, mySketch, aView, aX, anY);
160
161   std::shared_ptr<ModelAPI_AttributeReference> aRef =
162                           std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
163                           feature()->data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
164   aRef->setValue(anObject);
165
166   std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint =
167                   std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
168                   feature()->data()->attribute(SketchPlugin_Trim::ENTITY_POINT()));
169   anAttributePoint->setValue(aX, anY);
170   // redisplay AIS presentation in viewer
171 #ifndef HIGHLIGHT_STAYS_PROBLEM
172   // an attempt to clear highlighted item in the viewer: but of OCCT
173   XGUI_Tools::workshop(myWorkshop)->displayer()->clearSelected(true);
174 #endif
175   updateObject(feature());
176   aFilled = true;
177
178   return aFilled;
179 }
180
181 //********************************************************************
182 QList<ModuleBase_ViewerPrsPtr> PartSet_WidgetFeaturePointSelector::getAttributeSelection() const
183 {
184   return QList<ModuleBase_ViewerPrsPtr>();
185 }
186
187 //********************************************************************
188 void PartSet_WidgetFeaturePointSelector::updateSelectionName()
189 {
190   if (myBaseSelected)
191     ModuleBase_WidgetShapeSelector::updateSelectionName();
192 }
193
194 //********************************************************************
195 bool PartSet_WidgetFeaturePointSelector::setSelection(
196                                           QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
197                                           const bool theToValidate)
198 {
199   // false is returned to do not emit focus out widget by selected sub-shape
200   return false;
201 }
202
203 void PartSet_WidgetFeaturePointSelector::setPreSelection(
204                                   const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected,
205                                   ModuleBase_IViewWindow* theWnd,
206                                   QMouseEvent* theEvent)
207 {
208   if (fillFeature(thePreSelected, theWnd, theEvent))
209     mouseReleased(theWnd, theEvent);
210 }