SHAPER  9.12.0
PartSet_WidgetPoint2d.h
1 // Copyright (C) 2014-2023 CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef PartSet_WidgetPoint2D_H
21 #define PartSet_WidgetPoint2D_H
22 
23 #include "PartSet.h"
24 #include "PartSet_MouseProcessor.h"
25 
26 #include <ModelAPI_CompositeFeature.h>
27 #include <ModuleBase_ModelWidget.h>
28 #include <ModuleBase_ViewerPrs.h>
29 
30 #include <QObject>
31 
32 #include <TopoDS_Shape.hxx>
33 #include <V3d_View.hxx>
34 
35 class ModelAPI_Feature;
43 class GeomAPI_Pnt2d;
45 
46 class QGroupBox;
47 class QMouseEvent;
48 
57 class PARTSET_EXPORT PartSet_WidgetPoint2D : public ModuleBase_ModelWidget,
59 {
60 Q_OBJECT
61  public:
66  PartSet_WidgetPoint2D(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
67  const Config_WidgetAPI* theData);
69  virtual ~PartSet_WidgetPoint2D();
70 
74  virtual void selectionModes(int& theModuleSelectionModes, QIntList& theModes);
75 
79  virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
80 
87  bool isValidSelectionForAttribute_(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
88  const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
89 
92  bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
93 
98  virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
99  const bool theToValidate);
100 
102  //virtual void selectContent();
103 
106  virtual QList<QWidget*> getControls() const;
107 
108  //bool initFromPrevious(ObjectPtr theObject);
109 
111  virtual void deactivate();
112 
114  CompositeFeaturePtr sketch() const { return mySketch; }
115 
117  void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
118 
123  bool setPoint(double theX, double theY);
124 
126  double x() const;
127 
129  double y() const;
130 
132  virtual bool processEnter();
133 
136  virtual bool useSelectedShapes() const;
137 
141  virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
142 
146  virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
147 
149  //virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected);
150  virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected,
151  ModuleBase_IViewWindow* theWnd,
152  QMouseEvent* theEvent);
153 
158  void getGeomSelection_(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
159  std::shared_ptr<ModelAPI_Object>& theObject,
160  std::shared_ptr<GeomAPI_Shape>& theShape);
161 
164  PartSet_ExternalObjectsMgr* getExternalObjectMgr() const { return myExternalObjectMgr; }
165 
166 signals:
169 
170 protected:
173  virtual bool storeValueCustom();
174 
176  virtual bool restoreValueCustom();
177 
179  void storeCurentValue();
180 
183  bool restoreCurentValue();
184 
187  virtual bool resetCustom();
188 
190  virtual void activateCustom();
191 
193  virtual void setHighlighted(bool isHighlighted);
194 
201  bool isFeatureContainsPoint(const FeaturePtr& theFeature, double theX, double theY);
202 
203 //private slots:
205  //void onValuesChanged();
206 
212  virtual void initializeValueByActivate();
213 
214  private:
218  bool setConstraintToPoint(double theClickedX, double theClickedY,
219  const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
220 
224  bool setConstraintToObject(const ObjectPtr& theObject);
225 
230  void processSelection(const ModuleBase_ViewerPrsPtr& theValue, double theX, double theY);
231 
232 
233 public:
243  static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch,
244  double theX, double theY);
245 
250  static bool shapeExploreHasVertex(const std::shared_ptr<GeomAPI_Shape>& theShape,
251  const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
252  const CompositeFeaturePtr& theSketch);
253 
258  static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPointInArgumentFeatures(
259  const FeaturePtr& theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
260 
265  static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPoint(const FeaturePtr& theFeature,
266  const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
267 
273  static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPointInSketch(
274  const CompositeFeaturePtr& theSketch,
275  const FeaturePtr& theSkipFeature,
276  const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
277 
278 private:
281  std::shared_ptr<ModelAPI_AttributeRefAttr> attributeRefAttr() const;
282 
286  void fillRefAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
287  void fillRefAttribute(double theClickedX, double theClickedY,
288  const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
289  void fillRefAttribute(const ObjectPtr& theObject);
290 
291  ObjectPtr getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
292 
293 protected:
295 
296 private:
297  QGroupBox* myGroupBox;
298  //ModuleBase_ParamSpinBox* myXSpin; ///< the spin box for the X coordinate
299  //ModuleBase_ParamSpinBox* myYSpin; ///< the spin box for the Y coordinate
300  ModuleBase_LabelValue* myXSpin;
301  ModuleBase_LabelValue* myYSpin;
302  PartSet_ExternalObjectsMgr* myExternalObjectMgr;
303 
305  std::shared_ptr<ModuleBase_ViewerPrs> myPreSelected;
306 
308  CompositeFeaturePtr mySketch;
309 
310  std::string myRefAttribute;
311  bool myValueIsCashed;
312  bool myIsFeatureVisibleInCash;
313  double myXValueInCash;
314  double myYValueInCash;
315 };
316 
317 #endif
Provides low-level API for WidgetFactory for reading xml definitions of widgets.
Definition: Config_WidgetAPI.h:46
2D point defined by two coordinates
Definition: GeomAPI_Pnt2d.h:36
Attribute that contains 2D point coordinates.
Definition: GeomDataAPI_Point2D.h:37
Attribute that contains reference to an attribute of a feature or reference to a feature (switchable)
Definition: ModelAPI_AttributeRefAttr.h:33
Feature function that represents the particular functionality of this operation.
Definition: ModelAPI_Feature.h:39
Interface to ViewWindow object which contains 3d scene.
Definition: ModuleBase_IViewWindow.h:34
Class which provides access to Workshop object services.
Definition: ModuleBase_IWorkshop.h:48
Implementation of model widget for a label control.
Definition: ModuleBase_LabelValue.h:34
An abstract custom widget class.
Definition: ModuleBase_ModelWidget.h:60
virtual void selectionModes(int &theModuleSelectionModes, QIntList &theModes)
Fills given container with selection modes if the widget has it.
Definition: ModuleBase_ModelWidget.cpp:116
virtual void setHighlighted(bool isHighlighted)
Switch On/Off highlighting of the widget.
Definition: ModuleBase_ModelWidget.cpp:234
virtual void activateCustom()
The method called when widget is activated.
Definition: ModuleBase_ModelWidget.h:410
virtual bool isValidSelectionCustom(const std::shared_ptr< ModuleBase_ViewerPrs > &theValue)
Checks if the selection presentation is valid in widget.
Definition: ModuleBase_ModelWidget.h:176
virtual bool processSelection()
Returns true if envent is processed. It applyes workshop selection for the widget attribute.
Definition: ModuleBase_ModelWidget.cpp:515
virtual QList< QWidget * > getControls() const =0
Returns list of widget controls.
virtual bool setSelection(QList< std::shared_ptr< ModuleBase_ViewerPrs >> &theValues, const bool theToValidate)
Set the given wrapped value to the current widget This value should be processed in the widget accord...
Definition: ModuleBase_ModelWidget.h:163
virtual void initializeValueByActivate()
Compute the feature default value and fill the controls with it or store the control value to the fea...
Definition: ModuleBase_ModelWidget.cpp:315
virtual void deactivate()
The method called when widget is deactivated.
Definition: ModuleBase_ModelWidget.cpp:303
virtual bool storeValueCustom()=0
Saves the internal parameters to the given feature.
virtual bool restoreValueCustom()=0
Restore value from attribute data to the widget's control.
virtual bool resetCustom()
Fills the widget with default values.
Definition: ModuleBase_ModelWidget.h:407
An extension of a double spin box which let to use parameters and expressions for value definition.
Definition: ModuleBase_ParamSpinBox.h:37
Customosation of ModuleBase_WidgetShapeSelector in order to provide working with sketch specific obje...
Definition: PartSet_ExternalObjectsMgr.h:43
This is an interface to allow processing of mouse events.
Definition: PartSet_MouseProcessor.h:40
virtual void mouseMoved(ModuleBase_IViewWindow *theWindow, QMouseEvent *theEvent)
Processing the mouse move event in the viewer.
Definition: PartSet_MouseProcessor.h:45
virtual void setPreSelection(const std::shared_ptr< ModuleBase_ViewerPrs > &thePreSelected, ModuleBase_IViewWindow *theWnd, QMouseEvent *theEvent)
Fill preselection used in mouseReleased.
Definition: PartSet_MouseProcessor.h:64
virtual void mouseReleased(ModuleBase_IViewWindow *theWindow, QMouseEvent *theEvent)
Processing the mouse release event in the viewer.
Definition: PartSet_MouseProcessor.h:55
Implementation of model widget to provide widget to input point 2d In XML can be defined as folloung:
Definition: PartSet_WidgetPoint2d.h:59
PartSet_ExternalObjectsMgr * getExternalObjectMgr() const
Return reference to external objects manager.
Definition: PartSet_WidgetPoint2d.h:164
void setSketch(CompositeFeaturePtr theSketch)
Set sketch instance.
Definition: PartSet_WidgetPoint2d.h:117
ModuleBase_IWorkshop * myWorkshop
workshop
Definition: PartSet_WidgetPoint2d.h:294
void vertexSelected()
Signal about selection of an existing vertex from an object.
CompositeFeaturePtr sketch() const
Definition: PartSet_WidgetPoint2d.h:114