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)
57 PartSet_WidgetFeaturePointSelector::~PartSet_WidgetFeaturePointSelector()
61 //********************************************************************
62 bool PartSet_WidgetFeaturePointSelector::isValidSelection(
63 const std::shared_ptr<ModuleBase_ViewerPrs>& theValue)
68 //********************************************************************
69 void PartSet_WidgetFeaturePointSelector::activateCustom()
71 ModuleBase_WidgetShapeSelector::activateCustom();
73 myWorkshop->module()->activateCustomPrs(myFeature,
74 ModuleBase_IModule::CustomizeHighlightedObjects, true);
76 Handle(AIS_InteractiveContext) aContext =
77 XGUI_Tools::workshop(myWorkshop)->viewer()->AISContext();
79 std::vector<int> aColors;
80 aColors = Config_PropManager::color("Visualization", "sketch_entity_color",
82 Quantity_Color aColor(aColors[0] / 255., aColors[1] / 255., aColors[2] / 255., Quantity_TOC_RGB);
84 #ifdef HIGHLIGHT_STAYS_PROBLEM
85 Handle(Graphic3d_HighlightStyle) aHStyle = aContext->HighlightStyle();
86 myHighlightColor = aHStyle->Color();
87 aHStyle->SetColor(aColor);
88 aContext->SetHighlightStyle(aHStyle);
90 Handle(Graphic3d_HighlightStyle) aSStyle = aContext->SelectionStyle();
91 mySelectionColor = aSStyle->Color();
92 aSStyle->SetColor(aColor);
93 aContext->SetSelectionStyle(aSStyle);
97 //********************************************************************
98 void PartSet_WidgetFeaturePointSelector::deactivate()
100 ModuleBase_WidgetShapeSelector::deactivate();
102 Handle(AIS_InteractiveContext) aContext =
103 XGUI_Tools::workshop(myWorkshop)->viewer()->AISContext();
105 #ifdef HIGHLIGHT_STAYS_PROBLEM
106 Handle(Graphic3d_HighlightStyle) aHStyle = aContext->HighlightStyle();
107 aHStyle->SetColor(myHighlightColor);
108 aContext->SetHighlightStyle(aHStyle);
110 Handle(Graphic3d_HighlightStyle) aSStyle = aContext->SelectionStyle();
111 aSStyle->SetColor(mySelectionColor);
112 aContext->SetSelectionStyle(aSStyle);
116 //********************************************************************
117 void PartSet_WidgetFeaturePointSelector::mouseMoved(ModuleBase_IViewWindow* theWindow,
118 QMouseEvent* theEvent)
120 ModuleBase_ISelection* aSelect = myWorkshop->selection();
121 QList<ModuleBase_ViewerPrsPtr> aHighlighted = aSelect->getHighlighted();
123 if (!aHighlighted.empty()) {
124 ModuleBase_ViewerPrsPtr aPrs = aHighlighted.first();
125 fillFeature(aPrs, theWindow, theEvent);
129 //********************************************************************
130 void PartSet_WidgetFeaturePointSelector::mouseReleased(ModuleBase_IViewWindow* theWindow,
131 QMouseEvent* theEvent)
133 // the contex menu release by the right button should not be processed by this widget
134 if (theEvent->button() != Qt::LeftButton)
137 emit focusOutWidget(this);
138 // we need to deselect base feature for better visibility of selected feature
139 XGUI_Tools::workshop(myWorkshop)->displayer()->clearSelected(false);
142 //********************************************************************
143 bool PartSet_WidgetFeaturePointSelector::fillFeature(
144 const std::shared_ptr<ModuleBase_ViewerPrs>& theSelectedPrs,
145 ModuleBase_IViewWindow* theWindow,
146 QMouseEvent* theEvent)
148 bool aFilled = false;
149 if (theSelectedPrs.get() && theSelectedPrs->object().get()) {
150 ObjectPtr anObject = theSelectedPrs->object();
151 gp_Pnt aPnt = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
153 Handle(V3d_View) aView = theWindow->v3dView();
154 PartSet_Tools::convertTo2D(aPnt, mySketch, aView, aX, anY);
156 std::shared_ptr<ModelAPI_AttributeReference> aRef =
157 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
158 feature()->data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
159 aRef->setValue(anObject);
161 std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint =
162 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
163 feature()->data()->attribute(SketchPlugin_Trim::ENTITY_POINT()));
164 anAttributePoint->setValue(aX, anY);
165 // redisplay AIS presentation in viewer
166 #ifndef HIGHLIGHT_STAYS_PROBLEM
167 // an attempt to clear highlighted item in the viewer: but of OCCT
168 XGUI_Tools::workshop(myWorkshop)->displayer()->clearSelected(true);
170 updateObject(feature());
176 //********************************************************************
177 QList<ModuleBase_ViewerPrsPtr> PartSet_WidgetFeaturePointSelector::getAttributeSelection() const
179 return QList<ModuleBase_ViewerPrsPtr>();
183 //********************************************************************
184 bool PartSet_WidgetFeaturePointSelector::setSelection(
185 QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
186 const bool theToValidate)
188 // false is returned to do not emit focus out widget by selected sub-shape
192 void PartSet_WidgetFeaturePointSelector::setPreSelection(
193 const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected,
194 ModuleBase_IViewWindow* theWnd,
195 QMouseEvent* theEvent)
197 if (fillFeature(thePreSelected, theWnd, theEvent))
198 mouseReleased(theWnd, theEvent);