1 // SALOME OCCViewer : build OCC Viewer into Salome desktop
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : OCCViewer_AISSelector.cxx
25 // Author : Nicolas REJNERI
31 \class OCCViewer_AISSelector OCCViewer_AISSelector.h
32 \brief Selector for AIS interactive context.
34 Used only by Viewer Open CASCADE.
37 #include "OCCViewer_AISSelector.h"
42 OCCViewer_AISSelector::OCCViewer_AISSelector( const Handle (AIS_InteractiveContext)& aisContext) :
43 myAISContext ( aisContext )
51 OCCViewer_AISSelector::~OCCViewer_AISSelector()
57 Initialization ( internal )
59 void OCCViewer_AISSelector::initialize()
61 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
63 myHilightColor = Quantity_NOC_CYAN1;
64 mySelectColor = Quantity_NOC_GRAY80;
66 myAISContext->SetHilightColor( myHilightColor );
67 myAISContext->SelectionColor( mySelectColor );
68 myAISContext->SetSubIntensityColor( Quantity_NOC_CYAN1 );
74 void OCCViewer_AISSelector::cleanup()
79 Sets the color to hilight the detected objects
81 void OCCViewer_AISSelector::setHilightColor ( Quantity_NameOfColor color )
83 myHilightColor = color;
87 Sets the color to display the selected objects
89 void OCCViewer_AISSelector::setSelectColor ( Quantity_NameOfColor color )
91 mySelectColor = color;
95 Sets the interactive context for this selector
97 void OCCViewer_AISSelector::setContext ( const Handle (AIS_InteractiveContext)& aisContext )
99 QAD_ASSERT_DEBUG_ONLY ( !aisContext.IsNull() );
100 myAISContext = aisContext;
104 Checks the status of pick and emits 'selSelectionDone' or
105 'selSelectionCancel'.
106 Returns 'true' if no error, 'false' otherwise.
108 bool OCCViewer_AISSelector::checkSelection ( AIS_StatusOfPick status, bool hadSelection, bool addTo )
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 // if ( !hadSelection || status != AIS_SOP_SeveralSelected )
122 // MESSAGE (" AIS_StatusOfPick : " << AIS_SOP_OneSelected )
124 emit selSelectionDone( addTo ); /* selected ( the same object, may be ) */
126 return ( status != AIS_SOP_Error && status != AIS_SOP_NothingSelected );
131 Detects the interactive objects at position (x,y).
132 Returns 'true' if no error, 'false' otherwise.
134 bool OCCViewer_AISSelector::moveTo ( int x, int y, const Handle (V3d_View)& view )
136 if ( !myEnableSelection )
139 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
140 AIS_StatusOfDetection status = AIS_SOD_Error;
141 status = myAISContext->MoveTo (x, y, view);
143 return ( status != AIS_SOD_Error && status != AIS_SOD_AllBad );
147 Selects the detected interactive objects.
148 Calls checkSelection() for checking the status.
150 bool OCCViewer_AISSelector::select ()
152 if ( !myEnableSelection )
155 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
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 ( !myEnableSelection || !myEnableMultipleSelection )
171 return false; /* selection with rectangle is considered as multiple selection */
173 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
174 bool hadSelection = ( myNumSelected > 0 );
176 /* select and send notifications */
177 return checkSelection ( myAISContext->Select(left, top, right, bottom, view),
178 hadSelection, false );
182 Adds new selected objects to the objects previously selected.
183 Multiple selection must be enabled to get use of this function.
184 Calls checkSelection() for checking the status.
186 bool OCCViewer_AISSelector::shiftSelect ()
188 if ( !myEnableSelection )
191 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
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 ( !myEnableSelection || !myEnableMultipleSelection )
211 return false; /* selection with rectangle is considered as multiple selection */
213 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
214 bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
215 if ( hadSelection && !myEnableMultipleSelection)
218 /* select and send notifications */
219 return checkSelection ( myAISContext->ShiftSelect(left,top,right,bottom, view),
220 hadSelection, true );