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
30 \class OCCViewer_AISSelector OCCViewer_AISSelector.h
31 \brief Selector for AIS interactive context.
33 Used only by Viewer Open CASCADE.
36 #include "OCCViewer_AISSelector.h"
42 OCCViewer_AISSelector::OCCViewer_AISSelector( const Handle (AIS_InteractiveContext)& aisContext) :
43 myAISContext ( aisContext ),
44 myEnableSelection( true ),
45 myEnableMultipleSelection( true )
53 OCCViewer_AISSelector::~OCCViewer_AISSelector()
59 Initialization ( internal )
61 void OCCViewer_AISSelector::initialize()
63 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
65 myHilightColor = Quantity_NOC_CYAN1;
66 mySelectColor = Quantity_NOC_WHITE;
68 myAISContext->SetHilightColor( myHilightColor );
69 myAISContext->SelectionColor( mySelectColor );
70 myAISContext->SetSubIntensityColor( Quantity_NOC_CYAN1 );
76 void OCCViewer_AISSelector::cleanup()
81 Sets the color to hilight the detected objects
83 void OCCViewer_AISSelector::setHilightColor ( Quantity_NameOfColor color )
85 myHilightColor = color;
89 Sets the color to display the selected objects
91 void OCCViewer_AISSelector::setSelectColor ( Quantity_NameOfColor color )
93 mySelectColor = color;
97 Sets the interactive context for this selector
99 void OCCViewer_AISSelector::setContext ( const Handle (AIS_InteractiveContext)& aisContext )
101 QAD_ASSERT_DEBUG_ONLY ( !aisContext.IsNull() );
102 myAISContext = aisContext;
106 Checks the status of pick and emits 'selSelectionDone' or
107 'selSelectionCancel'.
108 Returns 'true' if no error, 'false' otherwise.
110 void OCCViewer_AISSelector::checkSelection ( int numSelBefore )
112 int numSelAfter = numSelected();
113 if ( numSelAfter < 1 && numSelBefore > 0 )
114 emit selSelectionCancel( false );
115 else if ( numSelAfter > 0 )
116 emit selSelectionDone( numSelAfter > 1 );
121 Detects the interactive objects at position (x,y).
122 Returns 'true' if no error, 'false' otherwise.
124 void OCCViewer_AISSelector::moveTo ( int x, int y, const Handle (V3d_View)& view )
126 if ( !myEnableSelection )
129 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
130 myAISContext->MoveTo (x, y, view);
134 Selects the detected interactive objects.
135 Calls checkSelection() for checking the status.
137 void OCCViewer_AISSelector::select ()
139 if ( !myEnableSelection )
142 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
143 int numBefore = numSelected();
145 myAISContext->Select();
147 /* send notifications */
148 checkSelection ( numBefore );
152 Selects the objects covered by the rectangle.
153 Multiple selection must be enabled to get use of this function.
154 Calls checkSelection() for checking the status.
156 void OCCViewer_AISSelector::select ( int left, int top, int right, int bottom,
157 const Handle (V3d_View)& view )
159 if ( !myEnableSelection || !myEnableMultipleSelection )
160 return; /* selection with rectangle is considered as multiple selection */
162 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
163 int numBefore = numSelected();
165 myAISContext->Select(left, top, right, bottom, view);
167 /* send notifications */
168 checkSelection ( numBefore );
172 Adds new selected objects to the objects previously selected.
173 Multiple selection must be enabled to get use of this function.
174 Calls checkSelection() for checking the status.
176 void OCCViewer_AISSelector::shiftSelect ()
178 if ( !myEnableSelection )
181 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
182 int numBefore = numSelected();
184 if ( numBefore && !myEnableMultipleSelection)
185 myAISContext->Select();
187 myAISContext->ShiftSelect();
189 /* send notifications */
190 checkSelection ( numBefore );
194 Adds new selected objects covered by the rectangle to the objects
196 Multiple selection must be enabled to get use of this function.
197 Calls checkSelection() for checking the status.
199 void OCCViewer_AISSelector::shiftSelect ( int left, int top, int right, int bottom,
200 const Handle (V3d_View)& view )
203 if ( !myEnableSelection || !myEnableMultipleSelection )
204 return; /* selection with rectangle is considered as multiple selection */
206 QAD_ASSERT_DEBUG_ONLY ( !myAISContext.IsNull() );
207 int numBefore = numSelected();
209 myAISContext->ShiftSelect(left,top,right,bottom, view);
211 /* send notifications */
212 checkSelection ( numBefore );
216 Enables/disables selection
218 void OCCViewer_AISSelector::enableSelection( bool bEnable )
220 myEnableSelection = bEnable;
224 Enables/disables multiple selection i.e
225 selection of several objects at the same time.
226 If enabled, non-multiple selection is enabled as well.
228 void OCCViewer_AISSelector::enableMultipleSelection( bool bEnable )
230 myEnableMultipleSelection = bEnable;
231 if ( bEnable ) myEnableSelection = bEnable;
235 Returns the number of selected objects.
237 int OCCViewer_AISSelector::numSelected() const
239 if ( myAISContext.IsNull() )
242 if ( myAISContext->HasOpenedContext() )
243 return myAISContext->NbSelected();
244 return myAISContext->NbCurrents();