1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "OCCViewer_AISSelector.h"
28 OCCViewer_AISSelector::OCCViewer_AISSelector( QObject* parent,
29 const Handle (AIS_InteractiveContext)& aisContext) :
32 myEnableSelection( true ),
33 myEnableMultipleSelection( true )
35 myHilightColor = Quantity_NOC_CYAN1;
36 mySelectColor = Quantity_NOC_GRAY80;
38 setAISContext( aisContext );
44 OCCViewer_AISSelector::~OCCViewer_AISSelector()
49 Enables/disables selection
51 void OCCViewer_AISSelector::enableSelection( bool bEnable )
53 myEnableSelection = bEnable;
57 Enables/disables multiple selection i.e
58 selection of several objects at the same time.
60 void OCCViewer_AISSelector::enableMultipleSelection( bool bEnable )
62 myEnableMultipleSelection = bEnable;
63 if ( bEnable ) myEnableSelection = bEnable;
67 Sets the color to hilight the detected objects
69 void OCCViewer_AISSelector::setHilightColor ( Quantity_NameOfColor color )
71 myHilightColor = color;
72 if ( !myAISContext.IsNull() ) {
73 const Handle(Graphic3d_HighlightStyle)& hStyle = myAISContext->HighlightStyle();
74 hStyle->SetColor( myHilightColor );
79 Sets the color to display the selected objects
81 void OCCViewer_AISSelector::setSelectColor ( Quantity_NameOfColor color )
83 mySelectColor = color;
84 if ( !myAISContext.IsNull() ) {
85 const Handle(Graphic3d_HighlightStyle)& sStyle = myAISContext->SelectionStyle();
86 sStyle->SetColor( mySelectColor );
91 Sets the interactive context for this selector
93 void OCCViewer_AISSelector::setAISContext ( const Handle (AIS_InteractiveContext)& aisContext )
95 myAISContext = aisContext;
96 if ( ! myAISContext.IsNull() ) {
97 const Handle(Graphic3d_HighlightStyle)& hStyle = myAISContext->HighlightStyle();
98 const Handle(Graphic3d_HighlightStyle)& sStyle = myAISContext->SelectionStyle();
99 hStyle->SetColor( myHilightColor );
100 sStyle->SetColor( mySelectColor );
101 myAISContext->SetSubIntensityColor( Quantity_NOC_CYAN1 );
106 Checks the status of pick and emits 'selSelectionDone' or
107 'selSelectionCancel'.
108 Returns 'true' if no error, 'false' otherwise.
110 bool OCCViewer_AISSelector::checkSelection ( AIS_StatusOfPick status,
114 if ( myAISContext.IsNull() )
117 myNumSelected = myAISContext->NbCurrents(); /* update after the last selection */
119 if ( status == AIS_SOP_NothingSelected && !hadSelection ) {
120 emit selSelectionCancel( addTo );
122 else if ( status == AIS_SOP_NothingSelected && hadSelection ) {
123 emit selSelectionCancel( addTo ); /* unselected now */
125 else if ( status == AIS_SOP_OneSelected || status == AIS_SOP_SeveralSelected )
127 emit selSelectionDone( addTo ); /* selected ( the same object, may be ) */
129 return ( status != AIS_SOP_Error && status != AIS_SOP_NothingSelected );
133 Detects the interactive objects at position (x,y).
134 Returns 'true' if no error, 'false' otherwise.
136 bool OCCViewer_AISSelector::moveTo ( int x, int y, const Handle (V3d_View)& view )
138 if ( myAISContext.IsNull() )
141 if ( !myEnableSelection )
144 AIS_StatusOfDetection status = AIS_SOD_Error;
145 status = myAISContext->MoveTo ( x, y, view, Standard_True );
146 return ( status != AIS_SOD_Error && status != AIS_SOD_AllBad );
150 Selects the detected interactive objects.
151 Calls checkSelection() for checking the status.
153 bool OCCViewer_AISSelector::select ()
155 if ( myAISContext.IsNull() )
158 if ( !myEnableSelection )
161 bool hadSelection = ( myNumSelected > 0 );
163 /* select and send notifications */
164 return checkSelection ( myAISContext->Select( Standard_True ), hadSelection, false );
168 Selects the objects covered by the rectangle.
169 Multiple selection must be enabled to get use of this function.
170 Calls checkSelection() for checking the status.
172 bool OCCViewer_AISSelector::select ( int left, int top, int right, int bottom,
173 const Handle (V3d_View)& view )
175 if ( myAISContext.IsNull() )
178 if ( !myEnableSelection || !myEnableMultipleSelection )
179 return false; /* selection with rectangle is considered as multiple selection */
181 bool hadSelection = ( myNumSelected > 0 );
183 /* select and send notifications */
184 return checkSelection ( myAISContext->Select( left, top, right, bottom, view, Standard_True ),
185 hadSelection, false );
189 Adds new selected objects to the objects previously selected.
190 Multiple selection must be enabled to get use of this function.
191 Calls checkSelection() for checking the status.
193 bool OCCViewer_AISSelector::shiftSelect ()
195 if ( myAISContext.IsNull() )
198 if ( !myEnableSelection )
201 bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
202 if ( hadSelection && !myEnableMultipleSelection)
205 /* select and send notifications */
206 return checkSelection ( myAISContext->ShiftSelect( Standard_True ), hadSelection, true );
210 Adds new selected objects covered by the rectangle to the objects
212 Multiple selection must be enabled to get use of this function.
213 Calls checkSelection() for checking the status.
215 bool OCCViewer_AISSelector::shiftSelect ( int left, int top, int right, int bottom,
216 const Handle (V3d_View)& view )
219 if ( myAISContext.IsNull() )
222 if ( !myEnableSelection || !myEnableMultipleSelection )
223 return false; /* selection with rectangle is considered as multiple selection */
225 bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
226 if ( hadSelection && !myEnableMultipleSelection)
229 /* select and send notifications */
230 return checkSelection ( myAISContext->ShiftSelect( left, top, right, bottom, view, Standard_True ),
231 hadSelection, true );