2 // File : OCCViewer_AISSelector.cxx
3 // Created : Wed Mar 20 10:58:50 2002
4 // Author : Nicolas REJNERI
7 // Copyright : Open CASCADE 2002
11 \class OCCViewer_AISSelector OCCViewer_AISSelector.h
12 \brief Selector for AIS interactive context.
14 Used only by Viewer Open CASCADE.
17 #include "OCCViewer_AISSelector.h"
22 OCCViewer_AISSelector::OCCViewer_AISSelector( const Handle (AIS_InteractiveContext)& aisContext) :
23 myAISContext ( aisContext )
31 OCCViewer_AISSelector::~OCCViewer_AISSelector()
37 Initialization ( internal )
39 void OCCViewer_AISSelector::initialize()
41 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
43 myHilightColor = Quantity_NOC_CYAN1;
44 mySelectColor = Quantity_NOC_GRAY80;
46 myAISContext->SetHilightColor( myHilightColor );
47 myAISContext->SelectionColor( mySelectColor );
48 myAISContext->SetSubIntensityColor( Quantity_NOC_CYAN1 );
54 void OCCViewer_AISSelector::cleanup()
59 Sets the color to hilight the detected objects
61 void OCCViewer_AISSelector::setHilightColor ( Quantity_NameOfColor color )
63 myHilightColor = color;
67 Sets the color to display the selected objects
69 void OCCViewer_AISSelector::setSelectColor ( Quantity_NameOfColor color )
71 mySelectColor = color;
75 Sets the interactive context for this selector
77 void OCCViewer_AISSelector::setContext ( const Handle (AIS_InteractiveContext)& aisContext )
79 QAD_ASSERT_DEBUG_ONLY ( !aisContext.IsNull() );
80 myAISContext = aisContext;
84 Checks the status of pick and emits 'selSelectionDone' or
86 Returns 'true' if no error, 'false' otherwise.
88 bool OCCViewer_AISSelector::checkSelection ( AIS_StatusOfPick status, bool hadSelection, bool addTo )
90 myNumSelected = myAISContext->NbCurrents(); /* update after the last selection */
92 if ( status == AIS_SOP_NothingSelected && !hadSelection ) {
93 emit selSelectionCancel( addTo );
95 else if ( status == AIS_SOP_NothingSelected && hadSelection ) {
96 emit selSelectionCancel( addTo ); /* unselected now */
98 else if ( status == AIS_SOP_OneSelected || status == AIS_SOP_SeveralSelected )
100 // if ( !hadSelection || status != AIS_SOP_SeveralSelected )
102 // MESSAGE (" AIS_StatusOfPick : " << AIS_SOP_OneSelected )
104 emit selSelectionDone( addTo ); /* selected ( the same object, may be ) */
106 return ( status != AIS_SOP_Error && status != AIS_SOP_NothingSelected );
111 Detects the interactive objects at position (x,y).
112 Returns 'true' if no error, 'false' otherwise.
114 bool OCCViewer_AISSelector::moveTo ( int x, int y, const Handle (V3d_View)& view )
116 if ( !myEnableSelection )
119 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
120 AIS_StatusOfDetection status = AIS_SOD_Error;
121 status = myAISContext->MoveTo (x, y, view);
123 return ( status != AIS_SOD_Error && status != AIS_SOD_AllBad );
127 Selects the detected interactive objects.
128 Calls checkSelection() for checking the status.
130 bool OCCViewer_AISSelector::select ()
132 if ( !myEnableSelection )
135 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
136 bool hadSelection = ( myNumSelected > 0 );
138 /* select and send notifications */
139 return checkSelection ( myAISContext->Select(), hadSelection, false );
143 Selects the objects covered by the rectangle.
144 Multiple selection must be enabled to get use of this function.
145 Calls checkSelection() for checking the status.
147 bool OCCViewer_AISSelector::select ( int left, int top, int right, int bottom,
148 const Handle (V3d_View)& view )
150 if ( !myEnableSelection || !myEnableMultipleSelection )
151 return false; /* selection with rectangle is considered as multiple selection */
153 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
154 bool hadSelection = ( myNumSelected > 0 );
156 /* select and send notifications */
157 return checkSelection ( myAISContext->Select(left, top, right, bottom, view),
158 hadSelection, false );
162 Adds new selected objects to the objects previously selected.
163 Multiple selection must be enabled to get use of this function.
164 Calls checkSelection() for checking the status.
166 bool OCCViewer_AISSelector::shiftSelect ()
168 if ( !myEnableSelection )
171 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
172 bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
173 if ( hadSelection && !myEnableMultipleSelection)
176 /* select and send notifications */
177 return checkSelection ( myAISContext->ShiftSelect(), hadSelection, true );
181 Adds new selected objects covered by the rectangle to the objects
183 Multiple selection must be enabled to get use of this function.
184 Calls checkSelection() for checking the status.
186 bool OCCViewer_AISSelector::shiftSelect ( int left, int top, int right, int bottom,
187 const Handle (V3d_View)& view )
190 if ( !myEnableSelection || !myEnableMultipleSelection )
191 return false; /* selection with rectangle is considered as multiple selection */
193 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
194 bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
195 if ( hadSelection && !myEnableMultipleSelection)
198 /* select and send notifications */
199 return checkSelection ( myAISContext->ShiftSelect(left,top,right,bottom, view),
200 hadSelection, true );