1 // Copyright (C) 2007-2008 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.
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
22 #include "OCCViewer_AISSelector.h"
27 OCCViewer_AISSelector::OCCViewer_AISSelector( QObject* parent,
28 const Handle (AIS_InteractiveContext)& aisContext) :
31 myEnableSelection( true ),
32 myEnableMultipleSelection( true )
34 myHilightColor = Quantity_NOC_CYAN1;
35 mySelectColor = Quantity_NOC_GRAY80;
37 setAISContext( aisContext );
43 OCCViewer_AISSelector::~OCCViewer_AISSelector()
48 Enables/disables selection
50 void OCCViewer_AISSelector::enableSelection( bool bEnable )
52 myEnableSelection = bEnable;
56 Enables/disables multiple selection i.e
57 selection of several objects at the same time.
59 void OCCViewer_AISSelector::enableMultipleSelection( bool bEnable )
61 myEnableMultipleSelection = bEnable;
62 if ( bEnable ) myEnableSelection = bEnable;
66 Sets the color to hilight the detected objects
68 void OCCViewer_AISSelector::setHilightColor ( Quantity_NameOfColor color )
70 myHilightColor = color;
71 if ( !myAISContext.IsNull() )
72 myAISContext->SetHilightColor( myHilightColor );
76 Sets the color to display the selected objects
78 void OCCViewer_AISSelector::setSelectColor ( Quantity_NameOfColor color )
80 mySelectColor = color;
81 if ( !myAISContext.IsNull() )
82 myAISContext->SelectionColor( mySelectColor );
86 Sets the interactive context for this selector
88 void OCCViewer_AISSelector::setAISContext ( const Handle (AIS_InteractiveContext)& aisContext )
90 myAISContext = aisContext;
91 if ( ! myAISContext.IsNull() ) {
92 myAISContext->SetHilightColor( myHilightColor );
93 myAISContext->SelectionColor( mySelectColor );
94 myAISContext->SetSubIntensityColor( Quantity_NOC_CYAN1 );
99 Checks the status of pick and emits 'selSelectionDone' or
100 'selSelectionCancel'.
101 Returns 'true' if no error, 'false' otherwise.
103 bool OCCViewer_AISSelector::checkSelection ( AIS_StatusOfPick status,
107 if ( myAISContext.IsNull() )
110 myNumSelected = myAISContext->NbCurrents(); /* update after the last selection */
112 if ( status == AIS_SOP_NothingSelected && !hadSelection ) {
113 emit selSelectionCancel( addTo );
115 else if ( status == AIS_SOP_NothingSelected && hadSelection ) {
116 emit selSelectionCancel( addTo ); /* unselected now */
118 else if ( status == AIS_SOP_OneSelected || status == AIS_SOP_SeveralSelected )
120 emit selSelectionDone( addTo ); /* selected ( the same object, may be ) */
122 return ( status != AIS_SOP_Error && status != AIS_SOP_NothingSelected );
126 Detects the interactive objects at position (x,y).
127 Returns 'true' if no error, 'false' otherwise.
129 bool OCCViewer_AISSelector::moveTo ( int x, int y, const Handle (V3d_View)& view )
131 if ( myAISContext.IsNull() )
134 if ( !myEnableSelection )
137 AIS_StatusOfDetection status = AIS_SOD_Error;
138 status = myAISContext->MoveTo (x, y, view);
140 return ( status != AIS_SOD_Error && status != AIS_SOD_AllBad );
144 Selects the detected interactive objects.
145 Calls checkSelection() for checking the status.
147 bool OCCViewer_AISSelector::select ()
149 if ( myAISContext.IsNull() )
152 if ( !myEnableSelection )
155 bool hadSelection = ( myNumSelected > 0 );
157 /* select and send notifications */
158 return checkSelection ( myAISContext->Select(), hadSelection, false );
162 Selects the objects covered by the rectangle.
163 Multiple selection must be enabled to get use of this function.
164 Calls checkSelection() for checking the status.
166 bool OCCViewer_AISSelector::select ( int left, int top, int right, int bottom,
167 const Handle (V3d_View)& view )
169 if ( myAISContext.IsNull() )
172 if ( !myEnableSelection || !myEnableMultipleSelection )
173 return false; /* selection with rectangle is considered as multiple selection */
175 bool hadSelection = ( myNumSelected > 0 );
177 /* select and send notifications */
178 return checkSelection ( myAISContext->Select(left, top, right, bottom, view),
179 hadSelection, false );
183 Adds new selected objects to the objects previously selected.
184 Multiple selection must be enabled to get use of this function.
185 Calls checkSelection() for checking the status.
187 bool OCCViewer_AISSelector::shiftSelect ()
189 if ( myAISContext.IsNull() )
192 if ( !myEnableSelection )
195 bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
196 if ( hadSelection && !myEnableMultipleSelection)
199 /* select and send notifications */
200 return checkSelection ( myAISContext->ShiftSelect(), hadSelection, true );
204 Adds new selected objects covered by the rectangle to the objects
206 Multiple selection must be enabled to get use of this function.
207 Calls checkSelection() for checking the status.
209 bool OCCViewer_AISSelector::shiftSelect ( int left, int top, int right, int bottom,
210 const Handle (V3d_View)& view )
213 if ( myAISContext.IsNull() )
216 if ( !myEnableSelection || !myEnableMultipleSelection )
217 return false; /* selection with rectangle is considered as multiple selection */
219 bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
220 if ( hadSelection && !myEnableMultipleSelection)
223 /* select and send notifications */
224 return checkSelection ( myAISContext->ShiftSelect(left,top,right,bottom, view),
225 hadSelection, true );