1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_SketcherMgr.h
4 // Created: 19 Dec 2014
5 // Author: Vitaly SMETANNIKOV
7 #ifndef PartSet_SketcherMgr_H
8 #define PartSet_SketcherMgr_H
12 #include <ModelAPI_Feature.h>
13 #include <ModelAPI_Attribute.h>
14 #include <ModelAPI_CompositeFeature.h>
15 #include <ModelAPI_Result.h>
17 #include <ModuleBase_ViewerFilters.h>
18 #include <ModuleBase_Definitions.h>
20 #include <GeomAPI_Pln.h>
21 #include <SelectMgr_IndexedMapOfOwner.hxx>
28 class ModuleBase_IViewWindow;
29 class ModuleBase_ModelWidget;
30 class ModuleBase_Operation;
35 * A class for management of sketch operations
36 At the time of the sketcher operation active, only the sketch sub-feature results are
37 displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
38 are hidden, the sketch feature result is displayed
40 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
43 /// Struct to define gp point, with the state is the point is initialized
49 myIsInitialized = false;
56 /// clear the initialized flag.
59 myIsInitialized = false;
61 /// set the point and switch on the initialized flag
62 /// \param thePoint the point
63 void setValue(const double theX, const double theY)
65 myIsInitialized = true;
70 bool myIsInitialized; /// the state whether the point is set
71 double myCurX, myCurY; /// the point coordinates
75 /// \param theModule a pointer to PartSet module
76 PartSet_SketcherMgr(PartSet_Module* theModule);
78 virtual ~PartSet_SketcherMgr();
80 /// Returns true if the operation is the sketch
81 /// \param theOperation an operation
82 /// \return the boolean result
83 static bool isSketchOperation(ModuleBase_Operation* theOperation);
85 /// Returns true if the operation id is in the sketch operation id list
86 /// \param theOperation an operation
87 /// \return the boolean result
88 static bool isNestedSketchOperation(ModuleBase_Operation* theOperation);
90 /// Returns whethe the current operation is a sketch distance - lenght, distance or radius
91 /// \param the operation
92 /// \return a boolean value
93 static bool isDistanceOperation(ModuleBase_Operation* theOperation);
95 /// Launches the operation from current highlighting
98 /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
99 CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
101 /// Starts sketch operation
102 void startSketch(ModuleBase_Operation* );
104 /// Stops sketch operation
105 void stopSketch(ModuleBase_Operation* );
107 /// Starts sketch operation
108 void startNestedSketch(ModuleBase_Operation* );
110 /// Stops sketch operation
111 void stopNestedSketch(ModuleBase_Operation* );
113 /// Returns True if there are available Undos and the sketch manager allows undo
114 /// \return the boolean result
115 bool canUndo() const;
117 //! Returns True if there are available Redos and the sketch manager allows redo
118 /// \return the boolean result
119 bool canRedo() const;
121 /// Returns whether the object can be displayed at the bounds of the active operation.
122 /// Display only current operation results for usual operation and ask the sketcher manager
123 /// if it is a sketch operation
124 /// \param theObject a model object
125 bool canDisplayObject() const;
128 /// Process sketch plane selected event
129 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
131 /// Listens the value changed signal and display the current operation feature
132 void onValuesChangedInPropertyPanel();
135 /// Process the enter mouse to the view port. If the current operation is a create of
136 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
137 void onEnterViewPort();
138 /// Process the leave mouse of the view port. If the current operation is a create of
139 /// a nested sketch feature, it hides the feature in the viewer
140 void onLeaveViewPort();
142 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
143 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
144 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
145 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
146 void onApplicationStarted();
147 void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
150 /// Returns list of strings which contains id's of sketch operations
151 static QStringList sketchOperationIdList();
153 /// Converts mouse position to 2d coordinates.
154 /// Member myCurrentSketch has to be correctly defined
155 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
158 typedef QList<AttributePtr> AttributeList;
159 typedef QMap<FeaturePtr, AttributeList> FeatureToAttributesMap;
160 typedef std::map<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
161 FeatureToSelectionMap;
162 /// Obtains the current selection of the object in the workshop viewer by a map of feature to attributes
163 /// It calls the next method for each feature
164 /// \param theFeatureToAttributes a map of feature to attributes
165 /// \param theSketch a current sketch feature
166 /// \param theWorkshop a workshop to have an access to AIS context and displayer
167 /// \param theSelection a container for the selection, to save results and attributres for a feature
168 static void getCurrentSelection(const FeatureToAttributesMap& theFeatureToAttributes,
169 const FeaturePtr& theSketch,
170 ModuleBase_IWorkshop* theWorkshop,
171 FeatureToSelectionMap& theSelection);
173 /// Obtains the current selection of the object in the workshop viewer
174 /// It includes the selection in all modes of activation, even local context - vertices, edges
175 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
176 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
177 /// the feature, if the owner is edge, the current result is added to the container of results.
178 /// \param theFeature a feature or result object
179 /// \param theSketch a current sketch feature
180 /// \param theWorkshop a workshop to have an access to AIS context and displayer
181 /// \param theSelection a container for the selection, to save results and attributres for a feature
182 static void getCurrentSelection(const FeaturePtr& theFeature,
183 const FeaturePtr& theSketch,
184 ModuleBase_IWorkshop* theWorkshop,
185 FeatureToSelectionMap& theSelection);
187 /// Applyes the current selection to the object in the workshop viewer
188 /// It includes the selection in all modes of activation, even local context - vertexes, edges
189 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
190 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
191 /// the feature and if it is in the container of selected attributes, the owner is put in the
192 /// out container. If the owner is edge and the current result is in the container of selected
193 /// results, the owner is put in the out container.
194 /// \param theFeature a feature or result object
195 /// \param theSketch a current sketch feature
196 /// \param theWorkshop a workshop to have an access to AIS context and displayer
197 /// \param theSelection a container of the selection, it has results and attributres for a feature
198 /// \param theOwnersToSelect an out container of found owners
199 static void getSelectionOwners(const FeaturePtr& theFeature,
200 const FeaturePtr& theSketch,
201 ModuleBase_IWorkshop* theWorkshop,
202 const FeatureToSelectionMap& theSelection,
203 SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
205 /// Connects or disconnects to the value changed signal of the property panel widgets
206 /// \param isToConnect a boolean value whether connect or disconnect
207 void connectToPropertyPanel(const bool isToConnect);
209 /// Returns true if the created feature is visible
211 bool isVisibleCreatedFeature() const;
213 /// Returns true if the current operation is create a nested feature
214 //// \return boolean value
215 bool isNestedCreateOperation() const;
217 /// Erase or display the feature of the current operation. If the mouse over the active view or
218 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
219 void updateVisibilityOfCreatedFeature();
222 PartSet_Module* myModule;
224 bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer
227 bool myIsPropertyPanelValueChanged; /// the state that value in the property panel is changed
228 bool myIsMouseOverWindow; /// the state that the mouse over the view
229 bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method
230 Point myCurrentPoint;
231 Point myClickedPoint;
233 CompositeFeaturePtr myCurrentSketch;
235 FeatureToAttributesMap myFeature2AttributeMap; /// a map of a feature to attributes
237 Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;