SHAPER 9.16.0
PartSet_SketcherMgr.h
1// Copyright (C) 2014-2026 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
62class PartSet_Module;
67class XGUI_Workshop;
68class XGUI_Displayer;
71
73
74class QMouseEvent;
76
77#ifdef HAVE_SALOME
78class PartSet_Fitter : public OCCViewer_Fitter
79#else
81#endif
82{
83public:
85 mySketchMgr(theSketchMgr) {}
86
87 virtual ~PartSet_Fitter() {}
88
91 virtual void fitAll(Handle(V3d_View) theView);
92
93private:
94 PartSet_SketcherMgr* mySketchMgr;
95};
96
97
98
106class PARTSET_EXPORT PartSet_SketcherMgr : public QObject, public Events_Listener
107{
108 Q_OBJECT
110 struct Point
111 {
113 Point()
114 {
115 myIsInitialized = false;
116 }
118 ~Point()
119 {
120 }
121
123 void clear()
124 {
125 myIsInitialized = false;
126 }
129 void setValue(const double theX, const double theY)
130 {
131 myIsInitialized = true;
132 myCurX = theX;
133 myCurY = theY;
134 }
135
136 bool myIsInitialized;
137 double myCurX, myCurY;
138 };
139
140public:
143 {
145 std::map<AttributePtr, int> myAttributes;
146 std::set<ResultPtr> myResults;
147 TopoDS_Shape myFirstResultShape;
148 TopTools_MapOfShape myLocalSelectedShapes;
149 };
150 typedef QMap<FeaturePtr, SelectionInfo> FeatureToSelectionMap;
151
152public:
156
157 virtual ~PartSet_SketcherMgr();
158
162 static bool isSketchOperation(ModuleBase_Operation* theOperation);
163
168 bool isNestedSketchOperation(ModuleBase_Operation* theOperation) const;
169
174 bool isNestedSketchFeature(const QString& theFeatureKind) const;
175
180 bool isNestedCreateOperation(ModuleBase_Operation* theOperation,
181 const CompositeFeaturePtr& /*theSketch*/) const;
182
186 bool isNestedEditOperation(ModuleBase_Operation* theOperation,
187 const CompositeFeaturePtr& /*theSketch*/) const;
188
192 static bool isEntity(const std::string& theId);
193
197 static bool isExternalFeature(const FeaturePtr& theFeature);
198
202 static bool isDistanceOperation(ModuleBase_Operation* theOperation);
203
207 static bool isDistanceKind(std::string& theKind);
208
210 bool isMouseOverWindow() { return myIsMouseOverWindow; }
211
213 CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
214
217 PartSet_PreviewSketchPlane* previewSketchPlane() const { return mySketchPlane; }
218
220 void startSketch(ModuleBase_Operation* );
221
223 void stopSketch(ModuleBase_Operation* );
224
227 void startNestedSketch(ModuleBase_Operation* theOperation);
228
231 void stopNestedSketch(ModuleBase_Operation* theOperation);
232
235 void commitNestedSketch(ModuleBase_Operation* theOperation);
236
240 bool sketchSelectionFilter(const ModuleBase_SelectionFilterType theFilterType);
241
245 void registerSelectionFilter(const ModuleBase_SelectionFilterType theFilterType,
246 const Handle(SelectMgr_Filter)& theFilter);
247
251 bool operationActivatedByPreselection();
252
255 bool canUndo() const;
256
259 bool canRedo() const;
260
263 //bool canCommitOperation() const;
264
268 bool canEraseObject(const ObjectPtr& theObject) const;
269
274 bool canDisplayObject(const ObjectPtr& theObject) const;
275
282 bool canDisplayConstraint(const FeaturePtr& theObject,
284 bool& isProcessed) const;
285
289 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
290
293 bool canDisplayCurrentCreatedFeature() const;
294
297 bool canChangeCursor(ModuleBase_Operation* theOperation) const;
298
300 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
301
305 bool isObjectOfSketch(const ObjectPtr& theObject) const;
306
309 ST_HighlightType,
311 ST_SelectAndHighlightType
312 };
313
319 void storeSelection(const SelectionType theType, FeatureToSelectionMap& theCurrentSelection);
320
323 void restoreSelection(FeatureToSelectionMap& theCurrentSelection);
324
327 bool sketchSolverError();
328
334 QString getFeatureError(const FeaturePtr& theFeature);
335
337 void clearClickedFlags();
338
340 static const QStringList& replicationsIdList();
341
343 static const QStringList& constraintsIdList();
344
348 static void sketchSelectionModes(const CompositeFeaturePtr& theSketch, QIntList& theModes);
349
353 Handle(AIS_InteractiveObject) createPresentation(const ObjectPtr& theResult);
354
358 void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
359
362 void widgetStateChanged(int thePreviousState);
363
367 //void customisePresentation(const ObjectPtr& theObject);
368
369 void customizeSketchPresentation(const ObjectPtr& theObject, const AISObjectPtr& thePrs) const;
370
374 void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType,
375 bool theState);
376
377 bool isShowFreePointsShown() const {
378 return myPointsHighlight.size() > 0;
379 }
380
381 PartSet_Module* module() const { return myModule; }
382
386 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
387
389 bool isDragModeCreation() const;
390
391 // Get constraints browser
392 XGUI_SketchConstraintsBrowser* constraintsBrowser();
393
394public slots:
396 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
397
400 void onShowPoints(bool toShow);
401
402 void onEditValues();
403 void onUpdateConstraintsList();
404 void onDeactivate(bool isNeedDeactivate, std::vector<FeaturePtr> theFeatures);
405
406private slots:
408 void onShowConstraintsToggle(int theType, bool theState);
411 void onEnterViewPort();
414 void onLeaveViewPort();
416 //void onBeforeValuesChangedInPropertyPanel();
419 //void onAfterValuesChangedInPropertyPanel();
420
421 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
422 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
423 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
424 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
425 void onApplicationStarted();
426 //void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
427
428 void onBeforeContextMenu();
429 void onAfterContextMenu();
430
431private:
433 void launchEditing();
434
438 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
439 Point& thePoint, bool theSnap = true);
440
444 static bool setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
445 ModuleBase_IWorkshop* theWorkshop,
446 bool& theCanCommitOperation);
447
460 static void getSelectionOwners(const FeaturePtr& theFeature,
461 const FeaturePtr& theSketch,
462 ModuleBase_IWorkshop* theWorkshop,
463 const FeatureToSelectionMap& theSelection,
464 SelectMgr_IndexedMapOfOwner& theOwnersToSelect);
465
468 bool isVisibleCreatedFeature() const;
469
472 ModuleBase_Operation* getCurrentOperation() const;
473
475 ModuleBase_ModelWidget* getActiveWidget() const;
476
482 void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
483 const bool isToDisplay, const bool isFlushRedisplay = true);
484
485private:
489 void updateSelectionPriority(ObjectPtr theObject, FeaturePtr theFeature);
491 XGUI_Workshop* workshop() const;
493 XGUI_OperationMgr* operationMgr() const;
494
495 std::vector<int> colorOfObject(const ObjectPtr& theObject,
496 const FeaturePtr& aFeature, bool isConstruction, bool isSuppressedConstraint) const;
497
498 friend class PartSet_PreviewSketchPlane;
499
500private:
501 PartSet_Module* myModule;
502 PartSet_PreviewSketchPlane* mySketchPlane; // display/erase sketch plane on start/stop sketch
503
504 bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
505 bool myIsEditLaunching;
506 bool myIsDragging;
507 bool myDragDone;
508 bool myIsMouseOverWindow;
510 bool myIsMouseOverViewProcessed;
511 bool myIsPopupMenuActive;
512 Point myCurrentPoint;
513 //Point myClickedPoint;
514
515 CompositeFeaturePtr myCurrentSketch;
516
517 std::set<ModuleBase_SelectionFilterType> mySelectionFilterTypes;
518
519 FeatureToSelectionMap myCurrentSelection;
520 bool myPreviousUpdateViewerEnabled;
521
522 QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;
523
524 PartSet_ExternalPointsMgr* myExternalPointsMgr;
525
526 QMap<ResultPtr, Handle(AIS_Shape)> myPointsHighlight;
527
528 bool myNoDragMoving;
529
530 QPoint myMousePoint;
531
532 QDockWidget* myConstraintsBrowser;
533};
534
535
536#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:82
virtual void fitAll(Handle theView)
A method which has top be reimplemented to provide alterantive implementation FitAll command.
Definition: PartSet_SketcherMgr.cpp:2538
Implementation of Partset module.
Definition: PartSet_Module.h:69
Visualization of 2D-bluebrint' accessories: translucent rectangular substrate, basis axes,...
Definition: PartSet_PreviewSketchPlane.h:51
A class for management of sketch operations At the time of the sketcher operation active,...
Definition: PartSet_SketcherMgr.h:107
SelectionType
Enumeration for selection mode used.
Definition: PartSet_SketcherMgr.h:308
@ ST_SelectType
Only highlighted objects.
Definition: PartSet_SketcherMgr.h:310
CompositeFeaturePtr activeSketch() const
Returns current Sketch feature/ Returns NULL if there is no launched sketch operation.
Definition: PartSet_SketcherMgr.h:213
PartSet_PreviewSketchPlane * previewSketchPlane() const
Returns help class to visualize sketcher plane.
Definition: PartSet_SketcherMgr.h:217
bool isMouseOverWindow()
Returns true if a mouse cursor is over viewer window.
Definition: PartSet_SketcherMgr.h:210
ConstraintVisibleState
types of constraints which visible state can be changed in the sketch widget
Definition: PartSet_Tools.h:74
Displayer.
Definition: XGUI_Displayer.h:172
Operation manager.
Definition: XGUI_OperationMgr.h:49
Object browser window object.
Definition: XGUI_SketchConstraintsBrowser.h:92
Class which defines a configuration of the application (Workshop) and launches it.
Definition: XGUI_Workshop.h:83
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:143
TopoDS_Shape myFirstResultShape
the selected results
Definition: PartSet_SketcherMgr.h:147
std::map< AttributePtr, int > myAttributes
the selected attributes and indices of points if array
Definition: PartSet_SketcherMgr.h:145
TopTools_MapOfShape myLocalSelectedShapes
the first shape of feature result
Definition: PartSet_SketcherMgr.h:148