SHAPER  9.12.0
PartSet_SketcherMgr.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_SketcherMgr_H
21 #define PartSet_SketcherMgr_H
22 
23 #include "PartSet.h"
24 
25 #include "PartSet_PreviewSketchPlane.h"
26 #include "PartSet_Tools.h"
27 
28 #include <ModelAPI_Feature.h>
29 #include <ModelAPI_Attribute.h>
30 #include <ModelAPI_CompositeFeature.h>
31 #include <ModelAPI_Result.h>
32 #include <Events_Listener.h>
33 #include <ModuleBase_SelectionFilterType.h>
34 
35 #include <ModuleBase_Definitions.h>
36 #include <ModuleBase_ModelWidget.h>
37 
38 #include <GeomAPI_Pln.h>
39 #include <GeomAPI_AISObject.h>
40 
41 #ifdef HAVE_SALOME
42  #include <OCCViewer_ViewModel.h>
43 #else
44  #include <AppElements_Viewer.h>
45 #endif
46 
47 
48 #include <SelectMgr_IndexedMapOfOwner.hxx>
49 #include <SelectMgr_ListOfFilter.hxx>
50 
51 #include <TopoDS_Shape.hxx>
52 #include <TopTools_MapOfShape.hxx>
53 #include <AIS_Shape.hxx>
54 
55 #include <QObject>
56 #include <QList>
57 #include <QMap>
58 #include <QPoint>
59 
60 #include <set>
61 
62 class PartSet_Module;
66 class XGUI_OperationMgr;
67 class XGUI_Workshop;
68 class XGUI_Displayer;
70 
72 
73 class QMouseEvent;
75 
76 #ifdef HAVE_SALOME
77 class PartSet_Fitter : public OCCViewer_Fitter
78 #else
80 #endif
81 {
82 public:
83  PartSet_Fitter(PartSet_SketcherMgr* theSketchMgr):
84  mySketchMgr(theSketchMgr) {}
85 
86  virtual ~PartSet_Fitter() {}
87 
90  virtual void fitAll(Handle(V3d_View) theView);
91 
92 private:
93  PartSet_SketcherMgr* mySketchMgr;
94 };
95 
96 
97 
105 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject, public Events_Listener
106 {
107  Q_OBJECT
109  struct Point
110  {
112  Point()
113  {
114  myIsInitialized = false;
115  }
117  ~Point()
118  {
119  }
120 
122  void clear()
123  {
124  myIsInitialized = false;
125  }
128  void setValue(const double theX, const double theY)
129  {
130  myIsInitialized = true;
131  myCurX = theX;
132  myCurY = theY;
133  }
134 
135  bool myIsInitialized;
136  double myCurX, myCurY;
137  };
138 
139 public:
142  {
144  std::map<AttributePtr, int> myAttributes;
145  std::set<ResultPtr> myResults;
146  TopoDS_Shape myFirstResultShape;
147  TopTools_MapOfShape myLocalSelectedShapes;
148  };
149  typedef QMap<FeaturePtr, SelectionInfo> FeatureToSelectionMap;
150 
151 public:
155 
156  virtual ~PartSet_SketcherMgr();
157 
161  static bool isSketchOperation(ModuleBase_Operation* theOperation);
162 
167  bool isNestedSketchOperation(ModuleBase_Operation* theOperation) const;
168 
173  bool isNestedSketchFeature(const QString& theFeatureKind) const;
174 
179  bool isNestedCreateOperation(ModuleBase_Operation* theOperation,
180  const CompositeFeaturePtr& /*theSketch*/) const;
181 
185  bool isNestedEditOperation(ModuleBase_Operation* theOperation,
186  const CompositeFeaturePtr& /*theSketch*/) const;
187 
191  static bool isEntity(const std::string& theId);
192 
196  static bool isExternalFeature(const FeaturePtr& theFeature);
197 
201  static bool isDistanceOperation(ModuleBase_Operation* theOperation);
202 
206  static bool isDistanceKind(std::string& theKind);
207 
209  bool isMouseOverWindow() { return myIsMouseOverWindow; }
210 
212  CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
213 
216  PartSet_PreviewSketchPlane* previewSketchPlane() const { return mySketchPlane; }
217 
219  void startSketch(ModuleBase_Operation* );
220 
222  void stopSketch(ModuleBase_Operation* );
223 
226  void startNestedSketch(ModuleBase_Operation* theOperation);
227 
230  void stopNestedSketch(ModuleBase_Operation* theOperation);
231 
234  void commitNestedSketch(ModuleBase_Operation* theOperation);
235 
239  bool sketchSelectionFilter(const ModuleBase_SelectionFilterType theFilterType);
240 
244  void registerSelectionFilter(const ModuleBase_SelectionFilterType theFilterType,
245  const Handle(SelectMgr_Filter)& theFilter);
246 
250  bool operationActivatedByPreselection();
251 
254  bool canUndo() const;
255 
258  bool canRedo() const;
259 
262  //bool canCommitOperation() const;
263 
267  bool canEraseObject(const ObjectPtr& theObject) const;
268 
273  bool canDisplayObject(const ObjectPtr& theObject) const;
274 
281  bool canDisplayConstraint(const FeaturePtr& theObject,
283  bool& isProcessed) const;
284 
288  //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
289 
292  bool canDisplayCurrentCreatedFeature() const;
293 
296  bool canChangeCursor(ModuleBase_Operation* theOperation) const;
297 
299  const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
300 
304  bool isObjectOfSketch(const ObjectPtr& theObject) const;
305 
308  ST_HighlightType,
310  ST_SelectAndHighlightType
311  };
312 
318  void storeSelection(const SelectionType theType, FeatureToSelectionMap& theCurrentSelection);
319 
322  void restoreSelection(FeatureToSelectionMap& theCurrentSelection);
323 
326  bool sketchSolverError();
327 
333  QString getFeatureError(const FeaturePtr& theFeature);
334 
336  void clearClickedFlags();
337 
339  static const QStringList& replicationsIdList();
340 
342  static const QStringList& constraintsIdList();
343 
347  static void sketchSelectionModes(const CompositeFeaturePtr& theSketch, QIntList& theModes);
348 
352  Handle(AIS_InteractiveObject) createPresentation(const ObjectPtr& theResult);
353 
357  void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
358 
361  void widgetStateChanged(int thePreviousState);
362 
366  //void customisePresentation(const ObjectPtr& theObject);
367 
368  void customizeSketchPresentation(const ObjectPtr& theObject, const AISObjectPtr& thePrs) const;
369 
373  void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType,
374  bool theState);
375 
376  bool isShowFreePointsShown() const {
377  return myPointsHighlight.size() > 0;
378  }
379 
380  PartSet_Module* module() const { return myModule; }
381 
385  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
386 
388  bool isDragModeCreation() const;
389 
390 
391 public slots:
393  void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
394 
397  void onShowPoints(bool toShow);
398 
399 private slots:
401  void onShowConstraintsToggle(int theType, bool theState);
404  void onEnterViewPort();
407  void onLeaveViewPort();
409  //void onBeforeValuesChangedInPropertyPanel();
412  //void onAfterValuesChangedInPropertyPanel();
413 
414  void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
415  void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
416  void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
417  void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
418  void onApplicationStarted();
419  //void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
420 
421  void onBeforeContextMenu();
422  void onAfterContextMenu();
423 
424 private:
426  void launchEditing();
427 
430  void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
431  Point& thePoint);
432 
436  static bool setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
437  ModuleBase_IWorkshop* theWorkshop,
438  bool& theCanCommitOperation);
439 
452  static void getSelectionOwners(const FeaturePtr& theFeature,
453  const FeaturePtr& theSketch,
454  ModuleBase_IWorkshop* theWorkshop,
455  const FeatureToSelectionMap& theSelection,
456  SelectMgr_IndexedMapOfOwner& theOwnersToSelect);
457 
460  bool isVisibleCreatedFeature() const;
461 
464  ModuleBase_Operation* getCurrentOperation() const;
465 
467  ModuleBase_ModelWidget* getActiveWidget() const;
468 
474  void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
475  const bool isToDisplay, const bool isFlushRedisplay = true);
476 
477 private:
481  void updateSelectionPriority(ObjectPtr theObject, FeaturePtr theFeature);
483  XGUI_Workshop* workshop() const;
485  XGUI_OperationMgr* operationMgr() const;
486 
487  std::vector<int> colorOfObject(const ObjectPtr& theObject,
488  const FeaturePtr& aFeature, bool isConstruction) const;
489 
490 private:
491  PartSet_Module* myModule;
492  PartSet_PreviewSketchPlane* mySketchPlane; // display/erase sketch plane on start/stop sketch
493 
494  bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
495  bool myIsEditLaunching;
496  bool myIsDragging;
497  bool myDragDone;
498  bool myIsMouseOverWindow;
500  bool myIsMouseOverViewProcessed;
501  bool myIsPopupMenuActive;
502  Point myCurrentPoint;
503  //Point myClickedPoint;
504 
505  CompositeFeaturePtr myCurrentSketch;
506 
507  std::set<ModuleBase_SelectionFilterType> mySelectionFilterTypes;
508 
509  FeatureToSelectionMap myCurrentSelection;
510  bool myPreviousUpdateViewerEnabled;
511 
512  QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;
513 
514  PartSet_ExternalPointsMgr* myExternalPointsMgr;
515 
516  QMap<ResultPtr, Handle(AIS_Shape)> myPointsHighlight;
517 
518  bool myNoDragMoving;
519 
520  QPoint myMousePoint;
521 };
522 
523 
524 #endif
Base interface for any event listener.
Definition: Events_Listener.h:37
virtual EVENTS_EXPORT void processEvent(const std::shared_ptr< Events_Message > &theMessage)=0
This method is called by loop when the event is started to process.
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
An abstract custom widget class.
Definition: ModuleBase_ModelWidget.h:60
Base class for all operations.
Definition: ModuleBase_Operation.h:53
A class to manage display of presentations of center points of circular edges outside of a current sk...
Definition: PartSet_ExternalPointsMgr.h:46
Definition: PartSet_SketcherMgr.h:81
virtual void fitAll(HandlettheView)
A method which has top be reimplemented to provide alterantive implementation FitAll command.
Definition: PartSet_SketcherMgr.cpp:2363
Implementation of Partset module.
Definition: PartSet_Module.h:69
A class to show/hide sketch preview plane.
Definition: PartSet_PreviewSketchPlane.h:39
A class for management of sketch operations At the time of the sketcher operation active,...
Definition: PartSet_SketcherMgr.h:106
SelectionType
Enumeration for selection mode used.
Definition: PartSet_SketcherMgr.h:307
@ ST_SelectType
Only highlighted objects.
Definition: PartSet_SketcherMgr.h:309
CompositeFeaturePtr activeSketch() const
Returns current Sketch feature/ Returns NULL if there is no launched sketch operation.
Definition: PartSet_SketcherMgr.h:212
bool isMouseOverWindow()
Returns true if a mouse cursor is over viewer window.
Definition: PartSet_SketcherMgr.h:209
PartSet_PreviewSketchPlane * previewSketchPlane() const
Returns help class to visualize sketcher plane.
Definition: PartSet_SketcherMgr.h:216
ConstraintVisibleState
types of constraints which visible state can be changed in the sketch widget
Definition: PartSet_Tools.h:68
Displayer.
Definition: XGUI_Displayer.h:172
Operation manager.
Definition: XGUI_OperationMgr.h:49
Class which defines a configuration of the application (Workshop) and launches it.
Definition: XGUI_Workshop.h:82
XGUI_Workshop * workshop(ModuleBase_IWorkshop *theWorkshop)
Definition: XGUI_Tools.cpp:244
Struct to define selection model information to store/restore selection.
Definition: PartSet_SketcherMgr.h:142
TopoDS_Shape myFirstResultShape
the selected results
Definition: PartSet_SketcherMgr.h:146
std::map< AttributePtr, int > myAttributes
the selected attributes and indices of points if array
Definition: PartSet_SketcherMgr.h:144
TopTools_MapOfShape myLocalSelectedShapes
the first shape of feature result
Definition: PartSet_SketcherMgr.h:147