1 // Copyright (C) 2007-2014 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 myAISContext->SetHilightColor( myHilightColor );
77 Sets the color to display the selected objects
79 void OCCViewer_AISSelector::setSelectColor ( Quantity_NameOfColor color )
81 mySelectColor = color;
82 if ( !myAISContext.IsNull() )
83 myAISContext->SelectionColor( mySelectColor );
87 Sets the interactive context for this selector
89 void OCCViewer_AISSelector::setAISContext ( const Handle (AIS_InteractiveContext)& aisContext )
91 myAISContext = aisContext;
92 if ( ! myAISContext.IsNull() ) {
93 myAISContext->SetHilightColor( myHilightColor );
94 myAISContext->SelectionColor( mySelectColor );
95 myAISContext->SetSubIntensityColor( Quantity_NOC_CYAN1 );
100 Checks the status of pick and emits 'selSelectionDone' or
101 'selSelectionCancel'.
102 Returns 'true' if no error, 'false' otherwise.
104 bool OCCViewer_AISSelector::checkSelection ( AIS_StatusOfPick status,
108 if ( myAISContext.IsNull() )
111 myNumSelected = myAISContext->NbCurrents(); /* update after the last selection */
113 if ( status == AIS_SOP_NothingSelected && !hadSelection ) {
114 emit selSelectionCancel( addTo );
116 else if ( status == AIS_SOP_NothingSelected && hadSelection ) {
117 emit selSelectionCancel( addTo ); /* unselected now */
119 else if ( status == AIS_SOP_OneSelected || status == AIS_SOP_SeveralSelected )
121 emit selSelectionDone( addTo ); /* selected ( the same object, may be ) */
123 return ( status != AIS_SOP_Error && status != AIS_SOP_NothingSelected );
127 Detects the interactive objects at position (x,y).
128 Returns 'true' if no error, 'false' otherwise.
130 bool OCCViewer_AISSelector::moveTo ( int x, int y, const Handle (V3d_View)& view )
132 if ( myAISContext.IsNull() )
135 if ( !myEnableSelection )
138 AIS_StatusOfDetection status = AIS_SOD_Error;
139 status = myAISContext->MoveTo (x, y, view);
141 return ( status != AIS_SOD_Error && status != AIS_SOD_AllBad );
145 Selects the detected interactive objects.
146 Calls checkSelection() for checking the status.
148 bool OCCViewer_AISSelector::select ()
150 if ( myAISContext.IsNull() )
153 if ( !myEnableSelection )
156 bool hadSelection = ( myNumSelected > 0 );
158 /* select and send notifications */
159 return checkSelection ( myAISContext->Select(), hadSelection, false );
163 Selects the objects covered by the rectangle.
164 Multiple selection must be enabled to get use of this function.
165 Calls checkSelection() for checking the status.
167 bool OCCViewer_AISSelector::select ( int left, int top, int right, int bottom,
168 const Handle (V3d_View)& view )
170 if ( myAISContext.IsNull() )
173 if ( !myEnableSelection || !myEnableMultipleSelection )
174 return false; /* selection with rectangle is considered as multiple selection */
176 bool hadSelection = ( myNumSelected > 0 );
178 /* select and send notifications */
179 return checkSelection ( myAISContext->Select(left, top, right, bottom, view),
180 hadSelection, false );
184 Adds new selected objects to the objects previously selected.
185 Multiple selection must be enabled to get use of this function.
186 Calls checkSelection() for checking the status.
188 bool OCCViewer_AISSelector::shiftSelect ()
190 if ( myAISContext.IsNull() )
193 if ( !myEnableSelection )
196 bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
197 if ( hadSelection && !myEnableMultipleSelection)
200 /* select and send notifications */
201 return checkSelection ( myAISContext->ShiftSelect(), hadSelection, true );
205 Adds new selected objects covered by the rectangle to the objects
207 Multiple selection must be enabled to get use of this function.
208 Calls checkSelection() for checking the status.
210 bool OCCViewer_AISSelector::shiftSelect ( int left, int top, int right, int bottom,
211 const Handle (V3d_View)& view )
214 if ( myAISContext.IsNull() )
217 if ( !myEnableSelection || !myEnableMultipleSelection )
218 return false; /* selection with rectangle is considered as multiple selection */
220 bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
221 if ( hadSelection && !myEnableMultipleSelection)
224 /* select and send notifications */
225 return checkSelection ( myAISContext->ShiftSelect(left,top,right,bottom, view),
226 hadSelection, true );