1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/
19 #include "OCCViewer_AISSelector.h"
24 OCCViewer_AISSelector::OCCViewer_AISSelector( QObject* parent,
25 const Handle (AIS_InteractiveContext)& aisContext) :
28 myEnableSelection( true ),
29 myEnableMultipleSelection( true )
31 myHilightColor = Quantity_NOC_CYAN1;
32 mySelectColor = Quantity_NOC_GRAY80;
34 setAISContext( aisContext );
40 OCCViewer_AISSelector::~OCCViewer_AISSelector()
45 Enables/disables selection
47 void OCCViewer_AISSelector::enableSelection( bool bEnable )
49 myEnableSelection = bEnable;
53 Enables/disables multiple selection i.e
54 selection of several objects at the same time.
56 void OCCViewer_AISSelector::enableMultipleSelection( bool bEnable )
58 myEnableMultipleSelection = bEnable;
59 if ( bEnable ) myEnableSelection = bEnable;
63 Sets the color to hilight the detected objects
65 void OCCViewer_AISSelector::setHilightColor ( Quantity_NameOfColor color )
67 myHilightColor = color;
68 if ( !myAISContext.IsNull() )
69 myAISContext->SetHilightColor( myHilightColor );
73 Sets the color to display the selected objects
75 void OCCViewer_AISSelector::setSelectColor ( Quantity_NameOfColor color )
77 mySelectColor = color;
78 if ( !myAISContext.IsNull() )
79 myAISContext->SelectionColor( mySelectColor );
83 Sets the interactive context for this selector
85 void OCCViewer_AISSelector::setAISContext ( const Handle (AIS_InteractiveContext)& aisContext )
87 myAISContext = aisContext;
88 if ( ! myAISContext.IsNull() ) {
89 myAISContext->SetHilightColor( myHilightColor );
90 myAISContext->SelectionColor( mySelectColor );
91 myAISContext->SetSubIntensityColor( Quantity_NOC_CYAN1 );
96 Checks the status of pick and emits 'selSelectionDone' or
98 Returns 'true' if no error, 'false' otherwise.
100 bool OCCViewer_AISSelector::checkSelection ( AIS_StatusOfPick status,
104 if ( myAISContext.IsNull() )
107 myNumSelected = myAISContext->NbCurrents(); /* update after the last selection */
109 if ( status == AIS_SOP_NothingSelected && !hadSelection ) {
110 emit selSelectionCancel( addTo );
112 else if ( status == AIS_SOP_NothingSelected && hadSelection ) {
113 emit selSelectionCancel( addTo ); /* unselected now */
115 else if ( status == AIS_SOP_OneSelected || status == AIS_SOP_SeveralSelected )
117 emit selSelectionDone( addTo ); /* selected ( the same object, may be ) */
119 return ( status != AIS_SOP_Error && status != AIS_SOP_NothingSelected );
123 Detects the interactive objects at position (x,y).
124 Returns 'true' if no error, 'false' otherwise.
126 bool OCCViewer_AISSelector::moveTo ( int x, int y, const Handle (V3d_View)& view )
128 if ( myAISContext.IsNull() )
131 if ( !myEnableSelection )
134 AIS_StatusOfDetection status = AIS_SOD_Error;
135 status = myAISContext->MoveTo (x, y, view);
137 return ( status != AIS_SOD_Error && status != AIS_SOD_AllBad );
141 Selects the detected interactive objects.
142 Calls checkSelection() for checking the status.
144 bool OCCViewer_AISSelector::select ()
146 if ( myAISContext.IsNull() )
149 if ( !myEnableSelection )
152 bool hadSelection = ( myNumSelected > 0 );
154 /* select and send notifications */
155 return checkSelection ( myAISContext->Select(), hadSelection, false );
159 Selects the objects covered by the rectangle.
160 Multiple selection must be enabled to get use of this function.
161 Calls checkSelection() for checking the status.
163 bool OCCViewer_AISSelector::select ( int left, int top, int right, int bottom,
164 const Handle (V3d_View)& view )
166 if ( myAISContext.IsNull() )
169 if ( !myEnableSelection || !myEnableMultipleSelection )
170 return false; /* selection with rectangle is considered as multiple selection */
172 bool hadSelection = ( myNumSelected > 0 );
174 /* select and send notifications */
175 return checkSelection ( myAISContext->Select(left, top, right, bottom, view),
176 hadSelection, false );
180 Adds new selected objects to the objects previously selected.
181 Multiple selection must be enabled to get use of this function.
182 Calls checkSelection() for checking the status.
184 bool OCCViewer_AISSelector::shiftSelect ()
186 if ( myAISContext.IsNull() )
189 if ( !myEnableSelection )
192 bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
193 if ( hadSelection && !myEnableMultipleSelection)
196 /* select and send notifications */
197 return checkSelection ( myAISContext->ShiftSelect(), hadSelection, true );
201 Adds new selected objects covered by the rectangle to the objects
203 Multiple selection must be enabled to get use of this function.
204 Calls checkSelection() for checking the status.
206 bool OCCViewer_AISSelector::shiftSelect ( int left, int top, int right, int bottom,
207 const Handle (V3d_View)& view )
210 if ( myAISContext.IsNull() )
213 if ( !myEnableSelection || !myEnableMultipleSelection )
214 return false; /* selection with rectangle is considered as multiple selection */
216 bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
217 if ( hadSelection && !myEnableMultipleSelection)
220 /* select and send notifications */
221 return checkSelection ( myAISContext->ShiftSelect(left,top,right,bottom, view),
222 hadSelection, true );