1 #include "OCCViewer_AISSelector.h"
6 OCCViewer_AISSelector::OCCViewer_AISSelector( QObject* parent,
7 const Handle (AIS_InteractiveContext)& aisContext) :
10 myEnableSelection( true ),
11 myEnableMultipleSelection( true )
13 myHilightColor = Quantity_NOC_CYAN1;
14 mySelectColor = Quantity_NOC_GRAY80;
16 setAISContext( aisContext );
22 OCCViewer_AISSelector::~OCCViewer_AISSelector()
27 Enables/disables selection
29 void OCCViewer_AISSelector::enableSelection( bool bEnable )
31 myEnableSelection = bEnable;
35 Enables/disables multiple selection i.e
36 selection of several objects at the same time.
38 void OCCViewer_AISSelector::enableMultipleSelection( bool bEnable )
40 myEnableMultipleSelection = bEnable;
41 if ( bEnable ) myEnableSelection = bEnable;
45 Sets the color to hilight the detected objects
47 void OCCViewer_AISSelector::setHilightColor ( Quantity_NameOfColor color )
49 myHilightColor = color;
50 if ( !myAISContext.IsNull() )
51 myAISContext->SetHilightColor( myHilightColor );
55 Sets the color to display the selected objects
57 void OCCViewer_AISSelector::setSelectColor ( Quantity_NameOfColor color )
59 mySelectColor = color;
60 if ( !myAISContext.IsNull() )
61 myAISContext->SelectionColor( mySelectColor );
65 Sets the interactive context for this selector
67 void OCCViewer_AISSelector::setAISContext ( const Handle (AIS_InteractiveContext)& aisContext )
69 myAISContext = aisContext;
70 if ( ! myAISContext.IsNull() ) {
71 myAISContext->SetHilightColor( myHilightColor );
72 myAISContext->SelectionColor( mySelectColor );
73 myAISContext->SetSubIntensityColor( Quantity_NOC_CYAN1 );
78 Checks the status of pick and emits 'selSelectionDone' or
80 Returns 'true' if no error, 'false' otherwise.
82 bool OCCViewer_AISSelector::checkSelection ( AIS_StatusOfPick status,
86 if ( myAISContext.IsNull() )
89 myNumSelected = myAISContext->NbCurrents(); /* update after the last selection */
91 if ( status == AIS_SOP_NothingSelected && !hadSelection ) {
92 emit selSelectionCancel( addTo );
94 else if ( status == AIS_SOP_NothingSelected && hadSelection ) {
95 emit selSelectionCancel( addTo ); /* unselected now */
97 else if ( status == AIS_SOP_OneSelected || status == AIS_SOP_SeveralSelected )
99 emit selSelectionDone( addTo ); /* selected ( the same object, may be ) */
101 return ( status != AIS_SOP_Error && status != AIS_SOP_NothingSelected );
105 Detects the interactive objects at position (x,y).
106 Returns 'true' if no error, 'false' otherwise.
108 bool OCCViewer_AISSelector::moveTo ( int x, int y, const Handle (V3d_View)& view )
110 if ( myAISContext.IsNull() )
113 if ( !myEnableSelection )
116 AIS_StatusOfDetection status = AIS_SOD_Error;
117 status = myAISContext->MoveTo (x, y, view);
119 return ( status != AIS_SOD_Error && status != AIS_SOD_AllBad );
123 Selects the detected interactive objects.
124 Calls checkSelection() for checking the status.
126 bool OCCViewer_AISSelector::select ()
128 if ( myAISContext.IsNull() )
131 if ( !myEnableSelection )
134 bool hadSelection = ( myNumSelected > 0 );
136 /* select and send notifications */
137 return checkSelection ( myAISContext->Select(), hadSelection, false );
141 Selects the objects covered by the rectangle.
142 Multiple selection must be enabled to get use of this function.
143 Calls checkSelection() for checking the status.
145 bool OCCViewer_AISSelector::select ( int left, int top, int right, int bottom,
146 const Handle (V3d_View)& view )
148 if ( myAISContext.IsNull() )
151 if ( !myEnableSelection || !myEnableMultipleSelection )
152 return false; /* selection with rectangle is considered as multiple selection */
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 ( myAISContext.IsNull() )
171 if ( !myEnableSelection )
174 bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
175 if ( hadSelection && !myEnableMultipleSelection)
178 /* select and send notifications */
179 return checkSelection ( myAISContext->ShiftSelect(), hadSelection, true );
183 Adds new selected objects covered by the rectangle to the objects
185 Multiple selection must be enabled to get use of this function.
186 Calls checkSelection() for checking the status.
188 bool OCCViewer_AISSelector::shiftSelect ( int left, int top, int right, int bottom,
189 const Handle (V3d_View)& view )
192 if ( myAISContext.IsNull() )
195 if ( !myEnableSelection || !myEnableMultipleSelection )
196 return false; /* selection with rectangle is considered as multiple selection */
198 bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
199 if ( hadSelection && !myEnableMultipleSelection)
202 /* select and send notifications */
203 return checkSelection ( myAISContext->ShiftSelect(left,top,right,bottom, view),
204 hadSelection, true );