1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_WidgetFeaturePointSelector.cpp
4 // Created: 28 Feb 2017
5 // Author: Natalia ERMOLAEVA
7 #include <Config_WidgetAPI.h>
9 #include <Events_Loop.h>
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>
17 #include <ModuleBase_ISelection.h>
18 #include <ModuleBase_ViewerPrs.h>
20 #include <ModelAPI_Events.h>
21 #include <ModelAPI_Feature.h>
22 #include <ModelAPI_Tools.h>
24 #include <ModuleBase_IViewWindow.h>
25 #include <ModuleBase_IWorkshop.h>
26 #include <ModuleBase_IModule.h>
28 #include "PartSet_WidgetFeaturePointSelector.h"
29 #include "PartSet_Tools.h"
31 //#include <SketchPlugin_ConstraintCoincidence.h>
32 //#include <SketchPlugin_Constraint.h>
33 #include <SketchPlugin_Point.h>
34 #include <SketchPlugin_Trim.h>
36 #include <XGUI_Tools.h>
37 #include <XGUI_Workshop.h>
38 #include <XGUI_Displayer.h>
39 #include <XGUI_ViewerProxy.h>
42 #include <QMouseEvent>
44 #define HIGHLIGHT_STAYS_PROBLEM
45 #ifdef HIGHLIGHT_STAYS_PROBLEM
46 #include <Quantity_Color.hxx>
47 #define SKETCH_ENTITY_COLOR "225,0,0"
50 PartSet_WidgetFeaturePointSelector::PartSet_WidgetFeaturePointSelector(QWidget* theParent,
51 ModuleBase_IWorkshop* theWorkshop,
52 const Config_WidgetAPI* theData)
53 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData), myBaseSelected(false)
57 PartSet_WidgetFeaturePointSelector::~PartSet_WidgetFeaturePointSelector()
61 //********************************************************************
62 bool PartSet_WidgetFeaturePointSelector::isValidSelection(
63 const std::shared_ptr<ModuleBase_ViewerPrs>& theValue)
68 //********************************************************************
69 bool PartSet_WidgetFeaturePointSelector::activateSelectionAndFilters(bool toActivate)
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();
78 std::vector<int> aColors;
79 aColors = Config_PropManager::color("Visualization", "sketch_entity_color");
80 aColor = Quantity_Color(aColors[0] / 255., aColors[1] / 255., aColors[2] / 255.,
82 myHighlightColor = aHStyle->Color();
83 mySelectionColor = aSStyle->Color();
85 aHStyle->SetTransparency(0.5f);
88 aColor = myHighlightColor;
90 aHStyle->SetColor(aColor);
91 aContext->SetHighlightStyle(aHStyle);
93 aSStyle->SetColor(aColor);
94 aContext->SetSelectionStyle(aSStyle);
98 return ModuleBase_WidgetShapeSelector::activateSelectionAndFilters(toActivate);
101 //********************************************************************
102 void PartSet_WidgetFeaturePointSelector::activateCustom()
104 ModuleBase_WidgetShapeSelector::activateCustom();
106 myBaseSelected = false;
108 myWorkshop->module()->activateCustomPrs(myFeature,
109 ModuleBase_IModule::CustomizeHighlightedObjects, true);
112 //********************************************************************
113 void PartSet_WidgetFeaturePointSelector::deactivate()
115 ModuleBase_WidgetShapeSelector::deactivate();
118 //********************************************************************
119 void PartSet_WidgetFeaturePointSelector::mouseMoved(ModuleBase_IViewWindow* theWindow,
120 QMouseEvent* theEvent)
122 ModuleBase_ISelection* aSelect = myWorkshop->selection();
123 QList<ModuleBase_ViewerPrsPtr> aHighlighted = aSelect->getHighlighted();
125 ModuleBase_ViewerPrsPtr aPrs = !aHighlighted.empty() ? aHighlighted.first()
126 : ModuleBase_ViewerPrsPtr();
127 fillFeature(aPrs, theWindow, theEvent);
130 //********************************************************************
131 void PartSet_WidgetFeaturePointSelector::mouseReleased(ModuleBase_IViewWindow* theWindow,
132 QMouseEvent* theEvent)
134 // the contex menu release by the right button should not be processed by this widget
135 if (theEvent->button() != Qt::LeftButton)
138 myBaseSelected = true;
139 emit focusOutWidget(this);
140 // we need to deselect base feature for better visibility of selected feature
141 XGUI_Tools::workshop(myWorkshop)->displayer()->clearSelected(false);
144 //********************************************************************
145 bool PartSet_WidgetFeaturePointSelector::fillFeature(
146 const std::shared_ptr<ModuleBase_ViewerPrs>& theSelectedPrs,
147 ModuleBase_IViewWindow* theWindow,
148 QMouseEvent* theEvent)
150 bool aFilled = false;
152 if (theSelectedPrs.get() && theSelectedPrs->object().get())
153 anObject = theSelectedPrs->object();
155 gp_Pnt aPnt = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
157 Handle(V3d_View) aView = theWindow->v3dView();
158 PartSet_Tools::convertTo2D(aPnt, mySketch, aView, aX, anY);
160 std::shared_ptr<ModelAPI_AttributeReference> aRef =
161 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
162 feature()->data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
163 aRef->setValue(anObject);
165 std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint =
166 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
167 feature()->data()->attribute(SketchPlugin_Trim::ENTITY_POINT()));
168 anAttributePoint->setValue(aX, anY);
169 // redisplay AIS presentation in viewer
170 #ifndef HIGHLIGHT_STAYS_PROBLEM
171 // an attempt to clear highlighted item in the viewer: but of OCCT
172 XGUI_Tools::workshop(myWorkshop)->displayer()->clearSelected(true);
174 updateObject(feature());
180 //********************************************************************
181 QList<ModuleBase_ViewerPrsPtr> PartSet_WidgetFeaturePointSelector::getAttributeSelection() const
183 return QList<ModuleBase_ViewerPrsPtr>();
186 //********************************************************************
187 void PartSet_WidgetFeaturePointSelector::updateSelectionName()
190 ModuleBase_WidgetShapeSelector::updateSelectionName();
193 //********************************************************************
194 bool PartSet_WidgetFeaturePointSelector::setSelection(
195 QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
196 const bool theToValidate)
198 // false is returned to do not emit focus out widget by selected sub-shape
202 void PartSet_WidgetFeaturePointSelector::setPreSelection(
203 const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected,
204 ModuleBase_IViewWindow* theWnd,
205 QMouseEvent* theEvent)
207 if (fillFeature(thePreSelected, theWnd, theEvent))
208 mouseReleased(theWnd, theEvent);