--- /dev/null
+/*!
+
+\page common_functionality_page Common functionality
+
+\anchor viewer_background
+<h2>Background</h2>
+
+Viewers background can be customized using the "Change background"
+popup menu command that opens the following dialog box:
+
+\image html change_background_dlg.png
+
+The following types of the background are supported:
+
+- Single color: the background is colored with the solid color
+ specified by the user in the dialog box.
+
+- Gradient background: the background is gradiently colored according
+ to two colors and the gradient type specified in the dialog box. The
+ following types of background are supported:
+
+ - Horizontal
+
+ - Vertical
+
+ - First diagonal
+
+ - Second diagonal
+
+ - First corner
+
+ - Second corner
+
+ - Third corner
+
+ - Fourth corner
+
+- Image: allows to set image as viewer background and define filling type:
+
+ - Center: the image is located at the center of the viewer backgound
+
+ - Tile: the image fills the entire viewer backgound one by one
+
+ - Stretch: the image is stretched to the entire viewer backgound.
+
+Default background for the OCC viewer is specified via the
+\ref occ_preferences "OCC 3D Viewer Preferences" and for the
+VTK viewer via the \ref vtk_preferences "VTK 3D Viewer Preferences".
+
+<hr>
+
+<h2>Selection</h2>
+
+For selecting it is necessary to click by left mouse button on the required
+element. Thus, this element will be selected.
+
+Also, holding down the <b>Shift</b> key while selecting objects will
+produce multi selection.
+
+In the viewers there are two mechanism for selecting: rectangle and
+polyline selection.
+
+<h3>Rectangle selection</h3>
+
+The Rectangle Selection tool is designed to select rectangular regions:
+it is the most basic of the selection tools and very commonly used.
+
+For selecting area by rectangle press left mouse button and draw it on
+the viewer holding down the left mouse button.
+
+To add an area to the existing selection it is necessary to hold down
+<b>Shift</b> key while selecting.
+
+\image html rectselectionvtk.png
+As a result, only a rectangle is selected.
+\image html rectselectionvtk2.png
+
+<h3>Polyline selection</h3>
+
+OCC and VTK Viewers features a special Polyline Selection mechanism,
+which allows selecting an arbitraty part of the graphic area using a
+polygon frame (rubber band), instead of the usual selection with a
+rectangular frame.
+
+To produce a Polyline Selection, lock the right mouse button and draw
+the first side of the polygon, then change the direction by clicking
+the left mouse button add draw another side, etc. The whole selection
+frame is drawn with the locked right mouse button.
+
+To add an area to the existing selection it is necessary to hold down
+<b>Shift</b> key while selecting.
+
+\image html polyselectionvtk11.png
+As a result, only the faces within the frame are selected.
+\image html polyselectionvtk21.png
+
+<hr>
+
+\anchor viewer_navigation_modes
+<h2>Navigation modes</h2>
+
+OCC and VTK 3D viewers support two different navigation modes:
+
+- <b>Salome standard controls</b>
+
+ Rectangle selection in this mode is performed by left mouse button,
+ polyline selection is done by right mouse button;
+ multiple selection is available when \b Shift button is pressed.
+
+ Also, holding \b Ctrl key pressed in conjunction with
+ mouse buttons performs view transformations:
+ - \b Ctrl + left mouse button - zooming;
+ - \b Ctrl + middle mouse button - panning;
+ - \b Ctrl + right mouse button - rotation.
+
+- <b>Keyboard free style</b>
+
+ This mode allows to process all view transformations without using
+ keyboard (only by mouse):
+ - \b Left mouse button performs view rotation;
+ - \b Middle mouse button performs panning;
+ - \b Right mouse button makes zooming.
+ .
+
+ In this style selection of objects in view is performed by pressing
+ "S" key or by left mouse button click. Rectangle selection is done
+ by left mouse button when holding \b Ctrl key; polyline selection
+ is done by right mouse button with \b Ctrl key pressed.
+
+*/
\image html occ_view_style_switch.png
-<b>Interaction style switch</b> - allows to switch between standard
-and "keyboard free" interaction styles. "Keyboard free" style allows
-to process all view transformations without using keyboard (only by
-mouse) and perform selection in view by pressing "S" key. By default,
-rotation in this mode is performed by left mouse button, panning - by
-middle mouse button, zooming - by left and middle mouse buttons
-pressed simultaneously.
+<b>Interaction style switch</b> - allows to switch between "Salome
+standard controls" and "Keyboard free" \ref viewer_navigation_modes "interaction styles".
+
<hr>
\image html occ_view_zooming_style_switch.png
synchronization of the views is performed, i.e. any zoom, pan, rotate
or other view operation done in one view is automatically applied to
the other view.
-<hr>
-
-\anchor occ_background
-<h2>Background</h2>
-
-OCC Viewer background can be customized using the "Change background"
-popup menu command that opens the following dialog box:
-
-\image html change_background_dlg.png
-
-The following types of the background are supported:
-
-- Single color: the background is colored with the solid color
- specified by the user in the dialog box.
-
-- Gradient background: the background is gradiently colored according
- to two colors and the gradient type specified in the dialog box. The
- following types of background are supported:
-
- - Horizontal
-
- - Vertical
-
- - First diagonal
-
- - Second diagonal
-
- - First corner
-
- - Second corner
-
- - Third corner
-
- - Fourth corner
-
-- Image: allows to set image as viewer background and define filling type:
-
- - Center: the image is located at the center of the viewer backgound
-
- - Tile: the image fills the entire viewer backgound one by one
-
- - Stretch: the image is stretched to the entire viewer backgound.
-
-Default background for the viewer is specified via the
-\ref occ_preferences "application preferences".
-
-<h2>Polyline selection</h2>
-
-OCC Viewer features a special <b>Polyline Selection</b> mechanism,
-which allows selecting an arbitraty part of the graphic area using a
-polygon frame (rubber band), instead of the usual selection with a
-rectangular frame.
-
-To produce a Polyline Selection, lock the right mouse button and draw
-the first side of the polygon, then change the direction by clicking
-the left mouse button add draw another side, etc. The whole selection
-frame is drawn with the locked right mouse button.
-
-\image html polyselection1.png
-
-As a result, only the nodes within the frame are selected.
-
-\image html polyselection2.png
*/
- \b Auto - shows full paths to the files only if some files from
different locations have the same name.
-\anchor occ_preferences
-<h2>OCC 3D Viewer Preferences</h2>
+<h2>3D Viewer Preferences</h2>
-\image html pref_salome_occviewer.png
+\image html pref_salome_3dviewer.png
-- <b>Trihedron</b> - viewer trihedron settings:
- - <b>Size</b> - size of the coordinate axes (global trihedron)
- displayed in the viewer.
- - <b>Relative size</b> - if this option is switched on, trihedron
- axes scale to fit the size of the scene displayed in 3D viewer.
- - <b>Show static trihedron</b> - allows to show/hide the static
- mini-trihedron located in the bottom-left corner of the viewer.
-- <b>Number of isolines</b> - this submenu allows to specify the
- number of isolines along the axes of coordinates:
- - <b>Along U</b> and
- - <b>Along V</b>
-- <b>Background</b> - specifies the default background for the viewers,
- separately for (for more details, refer to the \ref occ_background
- "this page"):
- - <b>3D View</b>
- - <b>XZ View</b>
- - <b>YZ View</b>
- - <b>XY View</b>
- <b>Navigation style</b> - this option allows to choose one of the
modes of work with mouse in OCC and VTK 3D viewers.
- <b>Salome Standard Controls</b> - allows to manipulate objects in the
relatively to its center.
- <b>Relative to the cursor</b> - allows to zoom the view
relatively to the current cursor position.
+- <b>Trihedron</b> - viewer trihedron settings:
+ - <b>Size</b> - size of the coordinate axes (global trihedron)
+ displayed in the viewer.
+ - <b>Relative size</b> - if this option is switched on, trihedron
+ axes scale to fit the size of the scene displayed in 3D viewer.
+ - <b>Show static trihedron</b> - allows to show/hide the static
+ mini-trihedron located in the bottom-left corner of the viewer.
+
+\anchor occ_preferences
+<h2>OCC 3D Viewer Preferences</h2>
+
+\image html pref_salome_occviewer.png
+
+- <b>Background</b> - specifies the default background for the viewers,
+ separately for (for more details, refer to the \ref viewer_background
+ "this page"):
+ - <b>3D View</b>
+ - <b>XZ View</b>
+ - <b>YZ View</b>
+ - <b>XY View</b>
\anchor vtk_preferences
<h2>VTK 3D Viewer Preferences</h2>
- <b>Projection mode</b> - allows choosing between \b Orthogonal and
\b Perspective projection mode.
- <b>Background</b> - specifies the default background for the viewer;
- for more details, refer to the \ref vtk_background "this page".
-- <b>Navigation style</b> - this option allows to choose one of the
- modes of work with mouse in OCC and VTK 3D viewers (for more details
- see \ref occ_preferences "preferences for OCC Viewer 3d").
-- <b>Zooming style</b> - this option allows to choose a zooming mode
- (for more details see \ref occ_preferences "preferences for OCC Viewer 3d").
+ for more details, refer to the \ref viewer_background "this page".
- <b>Speed Increment</b> - defines the number of units by
which the speed increases or respectively decreases after pressing [+]
or [-] keyboard buttons.
- <b>Modification Mode</b> - allows choosing between \b Arithmetic
and \b Geometrical progression used for zooming.
- <b>Dynamic pre-selection</b> - switches dynamic pre-selection on/off.
-- <b>Trihedron</b> - viewer trihedron settings:
- - <b>Size</b> - size of the coordinate axes displayed in the viewer.
- - <b>Relative size</b> - if this option is switched on, trihedron
- axes scale to fit the size of the scene displayed in 3D viewer.
- - <b>Show static trihedron</b> - allows to show/hide the static
- mini-trihedron located in the bottom-left corner of the viewer.
- <b>Spacemouse</b> - a mouse-like manipulator device specially designed
for working with 3D presentations, objects, etc. You can reassign the
actions listed below to any of its buttons.
developed on the basis of Qt QGraphicsView scene. This viewer is used
in SALOME YACS module for visualization of computation schemes.
+- \subpage common_functionality_page used in OCC and VTK 3d viewers.
+
*/
\image html vtk_view_style_switch.png
-<b>Interaction style switch</b> - allows to switch between standard
-and "keyboard free" interaction styles. "Keyboard free" style allows
-to process all view transformations without using keyboard (only by
-mouse) and perform selection in view by pressing "S" key. By default,
-rotation in this mode is performed by left mouse button, panning - by
-middle mouse button, zooming - by left and middle mouse buttons
-pressed simultaneously.
+<b>Interaction style switch</b> - allows to switch between "Salome
+standard controls" and "Keyboard free" \ref viewer_navigation_modes "interaction styles".
+
<hr>
\image html vtk_view_zooming_style_switch.png
- <b>Stop recording</b> - stop recording.
-<hr>
-
-\anchor vtk_background
-<h2>Background</h2>
-
-VTK Viewer background can be customized using the "Change background"
-popup menu command that opens the following dialog box:
-
-\image html change_background_dlg.png
-
-The following types of the background are supported:
-
-- Single color: the background is colored with the solid color
- specified by the user in the dialog box.
-
-- Gradient background: the background is gradiently colored according
- to two colors and the gradient type specified in the dialog
- box. The following types of background are supported:
-
- - Horizontal
-
- - Vertical
-
- - First diagonal
-
- - Second diagonal
-
- - First corner
-
- - Second corner
-
- - Third corner
-
- - Fourth corner
-
-- Image: allows to set image as viewer background and define filling type:
-
- - Center: the image is located at the center of the viewer backgound
-
- - Tile: the image fills the entire viewer backgound one by one
-
- - Stretch: the image is stretched to the entire viewer backgound.
-
-
-Default background for the viewer is specified via the
-\ref vtk_preferences "application preferences".
-
*/
vm->setBackground( OCCViewer_ViewFrame::BOTTOM_RIGHT,
resMgr->backgroundValue( "OCCViewer", "background", vm->background(OCCViewer_ViewFrame::MAIN_VIEW) ) );
- vm->setTrihedronSize( resMgr->doubleValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ),
- resMgr->booleanValue( "OCCViewer", "relative_size", vm->trihedronRelative() ));
- vm->setInteractionStyle( resMgr->integerValue( "OCCViewer", "navigation_mode", vm->interactionStyle() ) );
- vm->setZoomingStyle( resMgr->integerValue( "OCCViewer", "zooming_mode", vm->zoomingStyle() ) );
+ vm->setTrihedronSize( resMgr->doubleValue( "3DViewer", "trihedron_size", vm->trihedronSize() ),
+ resMgr->booleanValue( "3DViewer", "relative_size", vm->trihedronRelative() ));
+ vm->setInteractionStyle( resMgr->integerValue( "3DViewer", "navigation_mode", vm->interactionStyle() ) );
+ vm->setZoomingStyle( resMgr->integerValue( "3DViewer", "zooming_mode", vm->zoomingStyle() ) );
viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
}
{
vm->setProjectionMode( resMgr->integerValue( "VTKViewer", "projection_mode", vm->projectionMode() ) );
vm->setBackground( resMgr->backgroundValue( "VTKViewer", "background", vm->background() ) );
- vm->setTrihedronSize( resMgr->doubleValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ),
- resMgr->booleanValue( "VTKViewer", "relative_size", vm->trihedronRelative() ) );
- vm->setStaticTrihedronVisible( resMgr->booleanValue( "VTKViewer", "show_static_trihedron", vm->isStaticTrihedronVisible() ) );
- vm->setInteractionStyle( resMgr->integerValue( "VTKViewer", "navigation_mode", vm->interactionStyle() ) );
- vm->setZoomingStyle( resMgr->integerValue( "VTKViewer", "zooming_mode", vm->zoomingStyle() ) );
+ vm->setTrihedronSize( resMgr->doubleValue( "3DViewer", "trihedron_size", vm->trihedronSize() ),
+ resMgr->booleanValue( "3DViewer", "relative_size", vm->trihedronRelative() ) );
+ vm->setStaticTrihedronVisible( resMgr->booleanValue( "3DViewer", "show_static_trihedron", vm->isStaticTrihedronVisible() ) );
+ vm->setInteractionStyle( resMgr->integerValue( "3DViewer", "navigation_mode", vm->interactionStyle() ) );
+ vm->setZoomingStyle( resMgr->integerValue( "3DViewer", "zooming_mode", vm->zoomingStyle() ) );
vm->setDynamicPreSelection( resMgr->booleanValue( "VTKViewer", "dynamic_preselection", vm->dynamicPreSelection() ) );
vm->setIncrementalSpeed( resMgr->integerValue( "VTKViewer", "speed_value", vm->incrementalSpeed() ),
resMgr->integerValue( "VTKViewer", "speed_mode", vm->incrementalSpeedMode() ) );
// ... "MRU" preferences group <<end>>
// .. "General" preferences tab <<end>>
- // .. "OCC viewer" group <<start>>
- int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), salomeCat );
-
+ // .. "3D viewer" group <<start>>
+ int Viewer3DGroup = pref->addPreference( tr( "PREF_GROUP_3DVIEWER" ), salomeCat );
+ // ... -> navigation mode
+ int vtkStyleMode = pref->addPreference( tr( "PREF_NAVIGATION" ), Viewer3DGroup,
+ LightApp_Preferences::Selector, "3DViewer", "navigation_mode" );
+ aValuesList.clear();
+ anIndicesList.clear();
+ aValuesList << tr("PREF_STANDARD_STYLE") << tr("PREF_KEYFREE_STYLE");
+ anIndicesList << 0 << 1;
+ pref->setItemProperty( "strings", aValuesList, vtkStyleMode );
+ pref->setItemProperty( "indexes", anIndicesList, vtkStyleMode );
+ // ... -> zooming mode
+ #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
+ int occZoomingStyleMode = pref->addPreference( tr( "PREF_ZOOMING" ), Viewer3DGroup,
+ LightApp_Preferences::Selector, "3DViewer", "zooming_mode" );
+ aValuesList.clear();
+ anIndicesList.clear();
+ aValuesList << tr("PREF_ZOOMING_AT_CENTER") << tr("PREF_ZOOMING_AT_CURSOR");
+ anIndicesList << 0 << 1;
+ pref->setItemProperty( "strings", aValuesList, occZoomingStyleMode );
+ pref->setItemProperty( "indexes", anIndicesList, occZoomingStyleMode );
+ #endif
// ... "Trihedron" group <<start>>
- int occTriGroup = pref->addPreference( tr( "PREF_TRIHEDRON" ), occGroup );
+ int occTriGroup = pref->addPreference( tr( "PREF_TRIHEDRON" ), Viewer3DGroup );
pref->setItemProperty( "columns", 2, occTriGroup );
// .... -> trihedron size
int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occTriGroup,
- LightApp_Preferences::DblSpin, "OCCViewer", "trihedron_size" );
+ LightApp_Preferences::DblSpin, "3DViewer", "trihedron_size" );
pref->setItemProperty( "min", 1.0E-06, occTS );
pref->setItemProperty( "max", 1000, occTS );
// .... -> relative size of trihedron
- pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), occTriGroup, LightApp_Preferences::Bool, "OCCViewer", "relative_size" );
+ pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), occTriGroup, LightApp_Preferences::Bool, "3DViewer", "relative_size" );
// .... -> show static trihedron
- pref->addPreference( tr( "PREF_SHOW_STATIC_TRIHEDRON" ), occTriGroup, LightApp_Preferences::Bool, "OCCViewer", "show_static_trihedron" );
+ pref->addPreference( tr( "PREF_SHOW_STATIC_TRIHEDRON" ), occTriGroup, LightApp_Preferences::Bool, "3DViewer", "show_static_trihedron" );
// ... "Trihedron" group <<end>>
+ // .. "3D viewer" group <<end>>
+
+ // .. "OCC viewer" group <<start>>
+ int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), salomeCat );
+
// ... "Background" group <<start>>
int bgGroup = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup );
// pref->setItemProperty( "columns", 2, bgGroup );
int occGen = pref->addPreference( "", occGroup, LightApp_Preferences::Frame );
pref->setItemProperty( "margin", 0, occGen );
pref->setItemProperty( "columns", 2, occGen );
- // .... -> navigation mode
- int occStyleMode = pref->addPreference( tr( "PREF_NAVIGATION" ), occGen,
- LightApp_Preferences::Selector, "OCCViewer", "navigation_mode" );
- aValuesList.clear();
- anIndicesList.clear();
- aValuesList << tr("PREF_STANDARD_STYLE") << tr("PREF_KEYFREE_STYLE");
- anIndicesList << 0 << 1;
- pref->setItemProperty( "strings", aValuesList, occStyleMode );
- pref->setItemProperty( "indexes", anIndicesList, occStyleMode );
- // .... -> zooming mode
-#if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
- int occZoomingStyleMode = pref->addPreference( tr( "PREF_ZOOMING" ), occGen,
- LightApp_Preferences::Selector, "OCCViewer", "zooming_mode" );
- aValuesList.clear();
- anIndicesList.clear();
- aValuesList << tr("PREF_ZOOMING_AT_CENTER") << tr("PREF_ZOOMING_AT_CURSOR");
- anIndicesList << 0 << 1;
- pref->setItemProperty( "strings", aValuesList, occZoomingStyleMode );
- pref->setItemProperty( "indexes", anIndicesList, occZoomingStyleMode );
-#endif
// ... -> empty frame (for layout) <<end>>
// .. "OCC viewer" group <<end>>
pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
pref->setItemProperty( "custom_enabled", false, bgId );
pref->setItemProperty( "image_formats", formats, bgId );
- // .... -> navigation mode
- int vtkStyleMode = pref->addPreference( tr( "PREF_NAVIGATION" ), vtkGen,
- LightApp_Preferences::Selector, "VTKViewer", "navigation_mode" );
- aValuesList.clear();
- anIndicesList.clear();
- aValuesList << tr("PREF_STANDARD_STYLE") << tr("PREF_KEYFREE_STYLE");
- anIndicesList << 0 << 1;
- pref->setItemProperty( "strings", aValuesList, vtkStyleMode );
- pref->setItemProperty( "indexes", anIndicesList, vtkStyleMode );
- // .... -> zooming mode
- int vtkZoomingStyleMode = pref->addPreference( tr( "PREF_ZOOMING" ), vtkGen,
- LightApp_Preferences::Selector, "VTKViewer", "zooming_mode" );
- aValuesList.clear();
- anIndicesList.clear();
- aValuesList << tr("PREF_ZOOMING_AT_CENTER") << tr("PREF_ZOOMING_AT_CURSOR");
- anIndicesList << 0 << 1;
- pref->setItemProperty( "strings", aValuesList, vtkZoomingStyleMode );
- pref->setItemProperty( "indexes", anIndicesList, vtkZoomingStyleMode );
// .... -> speed increment
int vtkSpeed = pref->addPreference( tr( "PREF_INCREMENTAL_SPEED" ), vtkGen,
LightApp_Preferences::IntSpin, "VTKViewer", "speed_value" );
pref->addPreference( tr( "PREF_DYNAMIC_PRESELECTION" ), vtkGen, LightApp_Preferences::Bool, "VTKViewer", "dynamic_preselection" );
// ... -> empty frame (for layout) <<end>>
- // ... "Trihedron" group <<start>>
- int vtkTriGroup = pref->addPreference( tr( "PREF_TRIHEDRON" ), vtkGroup );
- pref->setItemProperty( "columns", 2, vtkTriGroup );
- // .... -> trihedron size
- int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkTriGroup,
- LightApp_Preferences::DblSpin, "VTKViewer", "trihedron_size" );
- pref->setItemProperty( "min", 1.0E-06, vtkTS );
- pref->setItemProperty( "max", 150, vtkTS );
- // .... -> relative size of trihedron
- pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), vtkTriGroup, LightApp_Preferences::Bool, "VTKViewer", "relative_size" );
- // .... -> static trihedron
- pref->addPreference( tr( "PREF_SHOW_STATIC_TRIHEDRON" ), vtkTriGroup, LightApp_Preferences::Bool, "VTKViewer", "show_static_trihedron" );
- // ... "Trihedron" group <<end>>
-
// ... space mouse sub-group <<start>>
int vtkSM = pref->addPreference( tr( "PREF_FRAME_SPACEMOUSE" ), vtkGroup, LightApp_Preferences::GroupBox );
//pref->setItemProperty( "columns", 2, vtkSM );
}
}
-#ifndef DISABLE_OCCVIEWER
- if ( sec == QString( "OCCViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )))
+ if ( sec == QString( "3DViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )))
{
double sz = resMgr->doubleValue( sec, "trihedron_size", -1 );
bool relative = resMgr->booleanValue( sec, "relative_size", true );
QList<SUIT_ViewManager*> lst;
+#ifndef DISABLE_OCCVIEWER
viewManagers( OCCViewer_Viewer::Type(), lst );
- QListIterator<SUIT_ViewManager*> it( lst );
- while ( it.hasNext() && sz >= 0 )
+ QListIterator<SUIT_ViewManager*> itOCC( lst );
+ while ( itOCC.hasNext() && sz >= 0 )
{
- SUIT_ViewModel* vm = it.next()->getViewModel();
+ SUIT_ViewModel* vm = itOCC.next()->getViewModel();
if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
continue;
occVM->setTrihedronSize( sz, relative );
occVM->getAISContext()->UpdateCurrentViewer();
}
- }
#endif
-
-#ifndef DISABLE_OCCVIEWER
- if ( sec == QString( "OCCViewer" ) && param == QString( "show_static_trihedron" ) )
- {
- bool isVisible = resMgr->booleanValue( "OCCViewer", "show_static_trihedron", true );
- QList<SUIT_ViewManager*> lst;
- viewManagers( OCCViewer_Viewer::Type(), lst );
- QListIterator<SUIT_ViewManager*> it( lst );
- while ( it.hasNext() )
+#ifndef DISABLE_VTKVIEWER
+#ifndef DISABLE_SALOMEOBJECT
+ viewManagers( SVTK_Viewer::Type(), lst );
+ QListIterator<SUIT_ViewManager*> itVTK( lst );
+ while ( itVTK.hasNext() && sz >= 0 )
{
- SUIT_ViewModel* vm = it.next()->getViewModel();
- if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
+ SUIT_ViewModel* vm = itVTK.next()->getViewModel();
+ if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
continue;
- OCCViewer_Viewer* occVM = dynamic_cast<OCCViewer_Viewer*>( vm );
- if( occVM )
+ SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
+ if( vtkVM )
{
- occVM->setStaticTrihedronDisplayed( isVisible );
+ vtkVM->setTrihedronSize( sz, relative );
+ vtkVM->Repaint();
}
}
- }
#endif
-
-#ifndef DISABLE_OCCVIEWER
- if ( sec == QString( "OCCViewer" ) && param == QString( "navigation_mode" ) )
- {
- int mode = resMgr->integerValue( "OCCViewer", "navigation_mode", 0 );
- QList<SUIT_ViewManager*> lst;
- viewManagers( OCCViewer_Viewer::Type(), lst );
- QListIterator<SUIT_ViewManager*> it( lst );
- while ( it.hasNext() )
- {
- SUIT_ViewModel* vm = it.next()->getViewModel();
- if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
- continue;
-
- OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
- occVM->setInteractionStyle( mode );
- }
- }
#endif
+ }
-#ifndef DISABLE_OCCVIEWER
- if ( sec == QString( "OCCViewer" ) && param == QString( "zooming_mode" ) )
+ if ( sec == QString( "3DViewer" ) && param == QString( "show_static_trihedron" ) )
{
- int mode = resMgr->integerValue( "OCCViewer", "zooming_mode", 0 );
+ bool isVisible = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
QList<SUIT_ViewManager*> lst;
+#ifndef DISABLE_OCCVIEWER
viewManagers( OCCViewer_Viewer::Type(), lst );
- QListIterator<SUIT_ViewManager*> it( lst );
- while ( it.hasNext() )
+ QListIterator<SUIT_ViewManager*> itOCC( lst );
+ while ( itOCC.hasNext() )
{
- SUIT_ViewModel* vm = it.next()->getViewModel();
+ SUIT_ViewModel* vm = itOCC.next()->getViewModel();
if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
continue;
- OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
- occVM->setZoomingStyle( mode );
+ OCCViewer_Viewer* occVM = dynamic_cast<OCCViewer_Viewer*>( vm );
+ if( occVM )
+ {
+ occVM->setStaticTrihedronDisplayed( isVisible );
+ }
}
- }
#endif
-
#ifndef DISABLE_VTKVIEWER
- if ( sec == QString( "VTKViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )) )
- {
- double sz = resMgr->doubleValue( "VTKViewer", "trihedron_size", -1 );
- bool isRelative = resMgr->booleanValue( "VTKViewer", "relative_size", true );
- QList<SUIT_ViewManager*> lst;
#ifndef DISABLE_SALOMEOBJECT
viewManagers( SVTK_Viewer::Type(), lst );
- QListIterator<SUIT_ViewManager*> it( lst );
- while ( it.hasNext() && sz >= 0 )
+ QListIterator<SUIT_ViewManager*> itVTK( lst );
+ while ( itVTK.hasNext() )
{
- SUIT_ViewModel* vm = it.next()->getViewModel();
+ SUIT_ViewModel* vm = itVTK.next()->getViewModel();
if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
continue;
SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
if( vtkVM )
{
- vtkVM->setTrihedronSize( sz, isRelative );
+ vtkVM->setStaticTrihedronVisible( isVisible );
vtkVM->Repaint();
}
}
#endif
- }
#endif
+ }
-#ifndef DISABLE_VTKVIEWER
- if ( sec == QString( "VTKViewer" ) && (param == QString( "speed_value" ) || param == QString( "speed_mode" )) )
+ if ( sec == QString( "3DViewer" ) && param == QString( "navigation_mode" ) )
{
- int speed = resMgr->integerValue( "VTKViewer", "speed_value", 10 );
- int mode = resMgr->integerValue( "VTKViewer", "speed_mode", 0 );
+ int mode = resMgr->integerValue( "3DViewer", "navigation_mode", 0 );
QList<SUIT_ViewManager*> lst;
-#ifndef DISABLE_SALOMEOBJECT
- viewManagers( SVTK_Viewer::Type(), lst );
- QListIterator<SUIT_ViewManager*> it( lst );
- while ( it.hasNext() )
+#ifndef DISABLE_OCCVIEWER
+ viewManagers( OCCViewer_Viewer::Type(), lst );
+ QListIterator<SUIT_ViewManager*> itOCC( lst );
+ while ( itOCC.hasNext() )
{
- SUIT_ViewModel* vm = it.next()->getViewModel();
- if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
+ SUIT_ViewModel* vm = itOCC.next()->getViewModel();
+ if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
continue;
- SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
- if( vtkVM ) vtkVM->setIncrementalSpeed( speed, mode );
+ OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
+ occVM->setInteractionStyle( mode );
}
#endif
- }
-#endif
-
#ifndef DISABLE_VTKVIEWER
- if ( sec == QString( "VTKViewer" ) && param == QString( "projection_mode" ) )
- {
- int mode = resMgr->integerValue( "VTKViewer", "projection_mode", 0 );
- QList<SUIT_ViewManager*> lst;
#ifndef DISABLE_SALOMEOBJECT
viewManagers( SVTK_Viewer::Type(), lst );
- QListIterator<SUIT_ViewManager*> it( lst );
- while ( it.hasNext() )
+ QListIterator<SUIT_ViewManager*> itVTK( lst );
+ while ( itVTK.hasNext() )
{
- SUIT_ViewModel* vm = it.next()->getViewModel();
+ SUIT_ViewModel* vm = itVTK.next()->getViewModel();
if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
continue;
SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
- if( vtkVM ) vtkVM->setProjectionMode( mode );
+ if( vtkVM ) vtkVM->setInteractionStyle( mode );
}
#endif
- }
#endif
+ }
-#ifndef DISABLE_VTKVIEWER
- if ( sec == QString( "VTKViewer" ) && param == QString( "navigation_mode" ) )
+ if ( sec == QString( "3DViewer" ) && param == QString( "zooming_mode" ) )
{
- int mode = resMgr->integerValue( "VTKViewer", "navigation_mode", 0 );
+ int mode = resMgr->integerValue( "3DViewer", "zooming_mode", 0 );
QList<SUIT_ViewManager*> lst;
+#ifndef DISABLE_OCCVIEWER
+ viewManagers( OCCViewer_Viewer::Type(), lst );
+ QListIterator<SUIT_ViewManager*> itOCC( lst );
+ while ( itOCC.hasNext() )
+ {
+ SUIT_ViewModel* vm = itOCC.next()->getViewModel();
+ if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
+ continue;
+
+ OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
+ occVM->setZoomingStyle( mode );
+ }
+#endif
+#ifndef DISABLE_VTKVIEWER
#ifndef DISABLE_SALOMEOBJECT
viewManagers( SVTK_Viewer::Type(), lst );
- QListIterator<SUIT_ViewManager*> it( lst );
- while ( it.hasNext() )
+ QListIterator<SUIT_ViewManager*> itVTK( lst );
+ while ( itVTK.hasNext() )
{
- SUIT_ViewModel* vm = it.next()->getViewModel();
+ SUIT_ViewModel* vm = itVTK.next()->getViewModel();
if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
continue;
SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
- if( vtkVM ) vtkVM->setInteractionStyle( mode );
+ if( vtkVM ) vtkVM->setZoomingStyle( mode );
}
#endif
- }
#endif
+ }
#ifndef DISABLE_VTKVIEWER
- if ( sec == QString( "VTKViewer" ) && param == QString( "zooming_mode" ) )
+ if ( sec == QString( "VTKViewer" ) && (param == QString( "speed_value" ) || param == QString( "speed_mode" )) )
{
- int mode = resMgr->integerValue( "VTKViewer", "zooming_mode", 0 );
+ int speed = resMgr->integerValue( "VTKViewer", "speed_value", 10 );
+ int mode = resMgr->integerValue( "VTKViewer", "speed_mode", 0 );
QList<SUIT_ViewManager*> lst;
#ifndef DISABLE_SALOMEOBJECT
viewManagers( SVTK_Viewer::Type(), lst );
continue;
SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
- if( vtkVM ) vtkVM->setZoomingStyle( mode );
+ if( vtkVM ) vtkVM->setIncrementalSpeed( speed, mode );
}
#endif
}
#endif
#ifndef DISABLE_VTKVIEWER
- if ( sec == QString( "VTKViewer" ) && param == QString( "dynamic_preselection" ) )
+ if ( sec == QString( "VTKViewer" ) && param == QString( "projection_mode" ) )
{
- bool mode = resMgr->booleanValue( "VTKViewer", "dynamic_preselection", true );
+ int mode = resMgr->integerValue( "VTKViewer", "projection_mode", 0 );
QList<SUIT_ViewManager*> lst;
#ifndef DISABLE_SALOMEOBJECT
viewManagers( SVTK_Viewer::Type(), lst );
continue;
SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
- if( vtkVM ) vtkVM->setDynamicPreSelection( mode );
+ if( vtkVM ) vtkVM->setProjectionMode( mode );
}
#endif
}
#endif
#ifndef DISABLE_VTKVIEWER
- if ( sec == QString( "VTKViewer" ) && param == QString( "show_static_trihedron" ) )
+ if ( sec == QString( "VTKViewer" ) && param == QString( "dynamic_preselection" ) )
{
- bool isVisible = resMgr->booleanValue( "VTKViewer", "show_static_trihedron", true );
+ bool mode = resMgr->booleanValue( "VTKViewer", "dynamic_preselection", true );
QList<SUIT_ViewManager*> lst;
#ifndef DISABLE_SALOMEOBJECT
viewManagers( SVTK_Viewer::Type(), lst );
continue;
SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
- if( vtkVM )
- {
- vtkVM->setStaticTrihedronVisible( isVisible );
- vtkVM->Repaint();
- }
+ if( vtkVM ) vtkVM->setDynamicPreSelection( mode );
}
#endif
}
<source>PREF_GROUP_COMMON</source>
<translation>Common</translation>
</message>
+ <message>
+ <source>PREF_GROUP_3DVIEWER</source>
+ <translation>3D Viewer</translation>
+ </message>
<message>
<source>PREF_GROUP_OCCVIEWER</source>
<translation>OCC 3D Viewer</translation>
<source>PREF_GROUP_COMMON</source>
<translation>Commun</translation>
</message>
+ <message>
+ <source>PREF_GROUP_3DVIEWER</source>
+ <translation>Scène 3D</translation>
+ </message>
<message>
<source>PREF_GROUP_OCCVIEWER</source>
<translation>Scène OCC 3D</translation>
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
if(resMgr)
- myShowStaticTrihedron = resMgr->booleanValue( "OCCViewer", "show_static_trihedron", true );
+ myShowStaticTrihedron = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
}
/*!
if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
- if (!aView || aView->interactionStyle() != SUIT_ViewModel::STANDARD)
+ if (!aView )
return;
myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
if ( aMaxSide < Precision::Confusion() )
return false;
- float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("OCCViewer","trihedron_size", 100.);
+ float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("3DViewer","trihedron_size", 100.);
static float EPS = 5.0E-3;
theSize = getTrihedron()->Size();
myType( type ),
mypData( 0 ),
myResult( Neutral ),
-myButtonState( 0 )
+myButtonState( 0 ),
+myHasShift( false )
{
}
return myButtonState;
}
+bool OCCViewer_ViewSketcher::isHasShift() const
+{
+ return myHasShift;
+}
+
void OCCViewer_ViewSketcher::onActivate()
{
}
{
OCCViewer_ViewPort3d* avp = mypViewWindow->getViewPort();
+ QMouseEvent* me = (QMouseEvent*)e;
SketchState state = EnTrain;
bool ignore = false;
if ( o == avp )
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
{
- QMouseEvent* me = (QMouseEvent*)e;
myButtonState = me->buttons();
if ( e->type() == QEvent::MouseButtonPress )
state = Fin;
ignore = true;
+ myHasShift = ( me->modifiers() & Qt::ShiftModifier );
break;
}
case QEvent::Hide:
int type() const;
int result() const;
int buttonState() const;
+ bool isHasShift() const;
void* data() const;
void activate();
QCursor mySavedCursor;
QPoint myStart, myCurr;
int myButtonState;
+ bool myHasShift;
};
/*!
myRectBand = 0;
IsSketcherStyle = false;
+ myIsKeyFree = false;
mypSketcher = 0;
myCurSketch = -1;
default:
/* Try to activate a transformation */
- switch ( getButtonState(theEvent, anInteractionStyle) ) {
+ OperationType aState;
+ if ( interactionStyle() == SUIT_ViewModel::STANDARD )
+ aState = getButtonState(theEvent, anInteractionStyle);
+ else {
+ aState = OCCViewer_ViewWindow::NOTHING;
+ myIsKeyFree = true;
+ }
+ switch ( aState ) {
case ZOOMVIEW:
myViewPort->startZoomAtPoint( myStartX, myStartY );
activateZoom();
break;
case PANVIEW:
- activatePanning();
+ activatePanning();
break;
case ROTATE:
- activateRotation();
- myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
+ activateRotation();
+ myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
break;
default:
if ( myRotationPointSelection )
*/
void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
{
+ if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
+ myIsKeyFree = false;
+ switch ( getButtonState( theEvent, interactionStyle() ) ) {
+ case ZOOMVIEW:
+ myViewPort->startZoomAtPoint( myStartX, myStartY );
+ activateZoom();
+ break;
+ case PANVIEW:
+ activatePanning();
+ break;
+ case ROTATE:
+ activateRotation();
+ myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
+ break;
+ default:
+ break;
+ }
+ }
+
myCurrX = theEvent->x();
myCurrY = theEvent->y();
switch (myOperation) {
int aState = theEvent->modifiers();
int aButton = theEvent->buttons();
int anInteractionStyle = interactionStyle();
- if ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
- aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) {
+ if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
+ aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
+ ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
+ aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
myDrawRect = myEnableDrawMode;
if ( myDrawRect ) {
drawRect();
}
emit mouseMoving( this, theEvent );
}
- else if ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
- aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) {
+ else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
+ aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
+ ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
+ aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
OCCViewer_ViewSketcher* sketcher = 0;
QList<OCCViewer_ViewSketcher*>::Iterator it;
for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
{
Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
- bool append = bool( mypSketcher->buttonState() & Qt::ShiftModifier );
+ bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
switch( mypSketcher->type() )
{
case Rect:
bool myEnableDrawMode;
bool myPaintersRedrawing; // set to draw with external painters
bool IsSketcherStyle;
+ bool myIsKeyFree;
QCursor myCursor;
// "key free" interaction style
SUIT_ViewModel::myStateMap[KEY_FREE][ZOOM] = Qt::NoModifier;
- SUIT_ViewModel::myButtonMap[KEY_FREE][ZOOM] = Qt::LeftButton | Qt::MidButton;
+ SUIT_ViewModel::myButtonMap[KEY_FREE][ZOOM] = Qt::RightButton;
SUIT_ViewModel::myStateMap[KEY_FREE][PAN] = Qt::NoModifier;
SUIT_ViewModel::myButtonMap[KEY_FREE][PAN] = Qt::MidButton;
SVTK_Prs.cxx
SVTK_Actor.cxx
SALOME_Actor.cxx
- SVTK_RectPicker.cxx
+ SVTK_AreaPicker.cxx
SVTK_DeviceActor.cxx
SVTK_CubeAxesActor2D.cxx
SVTK_NonIsometricDlg.cxx
SVTK_Prs.h
SVTK_Actor.h
SALOME_Actor.h
- SVTK_RectPicker.h
+ SVTK_AreaPicker.h
SVTK_DeviceActor.h
SVTK_FontWidget.h
SVTK_CubeAxesActor2D.h
SVTK_Prs.h \
SVTK_Actor.h \
SALOME_Actor.h \
- SVTK_RectPicker.h \
+ SVTK_AreaPicker.h \
SVTK_DeviceActor.h \
SVTK_FontWidget.h \
SVTK_CubeAxesActor2D.h \
SVTK_Prs.cxx \
SVTK_Actor.cxx \
SALOME_Actor.cxx \
- SVTK_RectPicker.cxx \
+ SVTK_AreaPicker.cxx \
SVTK_DeviceActor.cxx \
SVTK_CubeAxesActor2D.cxx \
SVTK_NonIsometricDlg.cxx \
#include "VTKViewer_TransformFilter.h"
#include "VTKViewer_GeometryFilter.h"
#include "VTKViewer_FramedTextActor.h"
-#include "SVTK_RectPicker.h"
+#include "SVTK_AreaPicker.h"
#include "SVTK_Actor.h"
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkOutlineSource.h>
+#include <vtkPolygon.h>
#include <vtkInteractorStyle.h>
#include <vtkRenderWindowInteractor.h>
#include <TColStd_MapOfInteger.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
+#include <math.h>
+#include <QPoint>
+#include <QVector>
+
#if defined __GNUC__
#if __GNUC__ == 2
#define __GNUC_2__
double x = theSelectionEvent->myX;
double y = theSelectionEvent->myY;
- double z = 0.0;
- if( !theSelectionEvent->myIsRectangle ) {
- switch(aSelectionMode){
- case NodeSelection: {
- SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
- myPointPicker->Pick( x, y, z, aRenderer );
-
- int aVtkId = myPointPicker->GetPointId();
- if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) {
- int anObjId = GetNodeObjId( aVtkId );
- if( hasIO() && anObjId >= 0 ) {
- mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift );
- mySelector->AddIObject( this );
- }
- }
- break;
- }
- case CellSelection:
- case EdgeSelection:
- case FaceSelection:
- case VolumeSelection:
- case Elem0DSelection:
- case BallSelection:
- {
- SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
- myCellPicker->Pick( x, y, z, aRenderer );
-
- int aVtkId = myCellPicker->GetCellId();
- if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) {
- int anObjId = GetElemObjId( aVtkId );
- if( anObjId >= 0 ) {
- if ( hasIO() && CheckDimensionId(aSelectionMode,this,anObjId) ) {
- mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift );
- mySelector->AddIObject( this );
- }
- }
- }
- break;
- }
- case EdgeOfCellSelection:
- {
- SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
- myCellPicker->Pick( x, y, z, aRenderer );
-
- int aVtkId = myCellPicker->GetCellId();
- if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) {
- int anObjId = GetElemObjId( aVtkId );
- if( anObjId >= 0 ) {
- int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
- if( hasIO() && anEdgeId < 0 ) {
- mySelector->AddOrRemoveIndex( myIO, anObjId, false );
- mySelector->AddOrRemoveIndex( myIO, anEdgeId, true );
- mySelector->AddIObject( this );
- }
- }
- }
- break;
- }
- case ActorSelection :
- {
- if ( hasIO() ) {
- if( mySelector->IsSelected( myIO ) && anIsShift )
- mySelector->RemoveIObject( this );
- else {
- mySelector->AddIObject( this );
- }
- }
- break;
- }
- default:
- break;
- }
- }else{
+ if( theSelectionEvent->myIsRectangle || theSelectionEvent->myIsPolygon ) {
double xLast = theSelectionEvent->myLastX;
double yLast = theSelectionEvent->myLastY;
- double zLast = 0.0;
double x1 = x < xLast ? x : xLast;
double y1 = y < yLast ? y : yLast;
- double z1 = z < zLast ? z : zLast;
double x2 = x > xLast ? x : xLast;
double y2 = y > yLast ? y : yLast;
- double z2 = z > zLast ? z : zLast;
switch(aSelectionMode){
case NodeSelection: {
- SVTK::TPickLimiter aPickLimiter( myPointRectPicker, this );
- myPointRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer );
+ SVTK::TPickLimiter aPickLimiter( myPointAreaPicker, this );
+ if ( theSelectionEvent->myIsRectangle )
+ myPointAreaPicker->Pick( x1, y1, x2, y2, aRenderer, SVTK_AreaPicker::RectangleMode );
+ else if( theSelectionEvent->myIsPolygon )
+ myPointAreaPicker->Pick( theSelectionEvent->myPolygonPoints, aRenderer, SVTK_AreaPicker::PolygonMode );
- const SVTK_RectPicker::TVectorIdsMap& aVectorIdsMap = myPointRectPicker->GetPointIdsMap();
- SVTK_RectPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
+ const SVTK_AreaPicker::TVectorIdsMap& aVectorIdsMap = myPointAreaPicker->GetPointIdsMap();
+ SVTK_AreaPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
TColStd_MapOfInteger anIndexes;
if(aMapIter != aVectorIdsMap.end()){
- const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second;
+ const SVTK_AreaPicker::TVectorIds& aVectorIds = aMapIter->second;
vtkIdType anEnd = aVectorIds.size();
for(vtkIdType anId = 0; anId < anEnd; anId++ ) {
int aPointId = aVectorIds[anId];
aRenderer->SetWorldPoint( aBounds[ i ], aBounds[ j ], aBounds[ k ], 1.0 );
aRenderer->WorldToDisplay();
aRenderer->GetDisplayPoint( aPnt );
-
- if( aPnt[0] < x1 || aPnt[0] > x2 || aPnt[1] < y1 || aPnt[1] > y2 ) {
- anIsPicked = false;
- break;
+ bool anIsPointInSelection;
+ if( theSelectionEvent->myIsRectangle )
+ anIsPointInSelection = aPnt[0] > x1 && aPnt[0] < x2 && aPnt[1] > y1 && aPnt[1] < y2;
+ else if( theSelectionEvent->myIsPolygon )
+ anIsPointInSelection = myPointAreaPicker->isPointInPolygon( QPoint( aPnt[0], aPnt[1] ),
+ theSelectionEvent->myPolygonPoints );
+
+ if( !anIsPointInSelection ) {
+ anIsPicked = false;
+ break;
}
}
}
}
- if( anIsPicked )
- mySelector->AddIObject(this);
+ if ( hasIO() ) {
+ if( anIsPicked && mySelector->IsSelected( myIO ) && anIsShift )
+ mySelector->RemoveIObject( this );
+ else if ( anIsPicked ){
+ mySelector->AddIObject( this );
+ }
+ }
break;
}
case Elem0DSelection:
case BallSelection:
{
- SVTK::TPickLimiter aPickLimiter( myCellRectPicker, this );
- myCellRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer );
-
- const SVTK_RectPicker::TVectorIdsMap& aVectorIdsMap = myCellRectPicker->GetCellIdsMap();
- SVTK_RectPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
+ SVTK::TPickLimiter aPickLimiter( myCellAreaPicker, this );
+ if( theSelectionEvent->myIsRectangle )
+ myCellAreaPicker->Pick( x1, y1, x2, y2, aRenderer, SVTK_AreaPicker::RectangleMode );
+ else if( theSelectionEvent->myIsPolygon )
+ myCellAreaPicker->Pick( theSelectionEvent->myPolygonPoints, aRenderer, SVTK_AreaPicker::PolygonMode );
+
+ const SVTK_AreaPicker::TVectorIdsMap& aVectorIdsMap = myCellAreaPicker->GetCellIdsMap();
+ SVTK_AreaPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
TColStd_MapOfInteger anIndexes;
if(aMapIter != aVectorIdsMap.end()){
- const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second;
+ const SVTK_AreaPicker::TVectorIds& aVectorIds = aMapIter->second;
vtkIdType anEnd = aVectorIds.size();
for(vtkIdType anId = 0; anId < anEnd; anId++ ) {
int aCellId = aVectorIds[anId];
break;
}
}
+ else {
+ switch(aSelectionMode){
+ case NodeSelection: {
+ SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
+ myPointPicker->Pick( x, y, 0.0, aRenderer );
+
+ int aVtkId = myPointPicker->GetPointId();
+ if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) {
+ int anObjId = GetNodeObjId( aVtkId );
+ if( hasIO() && anObjId >= 0 ) {
+ mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift );
+ mySelector->AddIObject( this );
+ }
+ }
+ break;
+ }
+ case CellSelection:
+ case EdgeSelection:
+ case FaceSelection:
+ case VolumeSelection:
+ case Elem0DSelection:
+ case BallSelection:
+ {
+ SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
+ myCellPicker->Pick( x, y, 0.0, aRenderer );
+
+ int aVtkId = myCellPicker->GetCellId();
+ if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) {
+ int anObjId = GetElemObjId( aVtkId );
+ if( anObjId >= 0 ) {
+ if ( hasIO() && CheckDimensionId(aSelectionMode,this,anObjId) ) {
+ mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift );
+ mySelector->AddIObject( this );
+ }
+ }
+ }
+ break;
+ }
+ case EdgeOfCellSelection:
+ {
+ SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
+ myCellPicker->Pick( x, y, 0.0, aRenderer );
+
+ int aVtkId = myCellPicker->GetCellId();
+ if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) {
+ int anObjId = GetElemObjId( aVtkId );
+ if( anObjId >= 0 ) {
+ int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
+ if( hasIO() && anEdgeId < 0 ) {
+ mySelector->AddOrRemoveIndex( myIO, anObjId, false );
+ mySelector->AddOrRemoveIndex( myIO, anEdgeId, true );
+ mySelector->AddIObject( this );
+ }
+ }
+ }
+ break;
+ }
+ case ActorSelection :
+ {
+ if ( hasIO() ) {
+ if( mySelector->IsSelected( myIO ) && anIsShift )
+ mySelector->RemoveIObject( this );
+ else {
+ mySelector->AddIObject( this );
+ }
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ }
mySelectionMode = aSelectionMode;
}
/*!
- To set up a picker for point rectangle selection (initialized by SVTK_Renderer::AddActor)
- \param theRectPicker - new picker
+ To set up a picker for point rectangle or polygonal selection (initialized by SVTK_Renderer::AddActor)
+ \param theAreaPicker - new picker
*/
void
SALOME_Actor
-::SetPointRectPicker(SVTK_RectPicker* theRectPicker)
+::SetPointAreaPicker(SVTK_AreaPicker* theAreaPicker)
{
- myPointRectPicker = theRectPicker;
+ myPointAreaPicker = theAreaPicker;
}
/*!
- To set up a picker for cell rectangle selection (initialized by SVTK_Renderer::AddActor)
- \param theRectPicker - new picker
+ To set up a picker for cell rectangle of polygonal selection (initialized by SVTK_Renderer::AddActor)
+ \param theAreaPicker - new picker
*/
void
SALOME_Actor
-::SetCellRectPicker(SVTK_RectPicker* theRectPicker)
+::SetCellAreaPicker(SVTK_AreaPicker* theAreaPicker)
{
- myCellRectPicker = theRectPicker;
+ myCellAreaPicker = theAreaPicker;
}
/*!
class VTKViewer_FramedTextActor;
class SVTK_Actor;
-class SVTK_RectPicker;
+class SVTK_AreaPicker;
class SVTK_InteractorStyle;
SVTK_EXPORT extern int SALOME_POINT_SIZE;
//! To set up a picker for point rectangle selection (initialized by #SVTK_Renderer::AddActor)
void
- SetPointRectPicker(SVTK_RectPicker* theRectPicker);
+ SetPointAreaPicker(SVTK_AreaPicker* theAreaPicker);
//! To set up a picker for cell rectangle selection (initialized by #SVTK_Renderer::AddActor)
void
- SetCellRectPicker(SVTK_RectPicker* theRectPicker);
+ SetCellAreaPicker(SVTK_AreaPicker* theAreaPicker);
//----------------------------------------------------------------------------
//! To set up a prehighlight property (initialized by #SVTK_Renderer::AddActor)
vtkSmartPointer<vtkPointPicker> myPointPicker;
vtkSmartPointer<vtkCellPicker> myCellPicker;
- vtkSmartPointer<SVTK_RectPicker> myPointRectPicker;
- vtkSmartPointer<SVTK_RectPicker> myCellRectPicker;
+ vtkSmartPointer<SVTK_AreaPicker> myPointAreaPicker;
+ vtkSmartPointer<SVTK_AreaPicker> myCellAreaPicker;
vtkSmartPointer<SVTK_Actor> myPreHighlightActor;
vtkSmartPointer<SVTK_Actor> myHighlightActor;
#include "SVTK_Prs.h"
#include "SVTK_Actor.h"
#include "SALOME_Actor.h"
-#include "SVTK_RectPicker.h"
+#include "SVTK_AreaPicker.h"
#include "SVTK_DeviceActor.h"
#include "SVTK_CubeAxesActor2D.h"
#include "SVTK_Functor.h"
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// SALOME VTKViewer : build VTK viewer into Salome desktop
+// File : SVTK_AreaPicker.cxx
+// Author :
+// Module : SALOME
+//
+#include "SVTK_AreaPicker.h"
+
+#include <set>
+
+#include <vtkObjectFactory.h>
+#include <vtkCommand.h>
+
+#include <vtkAbstractMapper3D.h>
+#include <vtkMapper.h>
+#include <vtkProperty.h>
+
+#include <vtkAssemblyPath.h>
+#include <vtkAssemblyNode.h>
+
+#include <vtkRenderWindow.h>
+#include <vtkMatrix4x4.h>
+#include <vtkRenderer.h>
+#include <vtkPoints.h>
+#include <vtkCamera.h>
+#include <vtkCell.h>
+
+namespace
+{
+ //----------------------------------------------------------------------------
+ inline
+ double GetZ( float* theZPtr, int theSelection[4], int theDX, int theDY )
+ {
+ return theZPtr[theDX - theSelection[0]
+ + ( theDY - theSelection[1] )
+ * ( theSelection[2] - theSelection[0] + 1 )];
+ }
+
+ //----------------------------------------------------------------------------
+ inline
+ int Check( float* theZPtr, int theSelection[4], double theTolerance,
+ double theDZ, int theDX, int theDY )
+ {
+ int aRet = 0;
+ double aZ = -1.0;
+ if ( theDX >= theSelection[0] && theDX <= theSelection[2]
+ && theDY >= theSelection[1] && theDY <= theSelection[3] ) {
+ // Access the value from the captured zbuffer. Note, we only
+ // captured a portion of the zbuffer, so we need to offset dx by
+ // the selection window.
+ aZ = GetZ( theZPtr, theSelection, theDX, theDY );
+ if ( aZ > theTolerance && aZ < 1.0 - theTolerance ) {
+ aRet = fabs( aZ - theDZ ) <= theTolerance;
+ }
+ }
+ return aRet;
+ }
+
+ //----------------------------------------------------------------------------
+ inline
+ void GetCenter( const double theBounds[6], double theCenter[3] )
+ {
+ theCenter[0] = ( theBounds[1] + theBounds[0] ) / 2.0;
+ theCenter[1] = ( theBounds[3] + theBounds[2] ) / 2.0;
+ theCenter[2] = ( theBounds[5] + theBounds[4] ) / 2.0;
+ }
+
+ //----------------------------------------------------------------------------
+ void CalculatePickPosition( vtkRenderer *theRenderer, double theSelectionX,
+ double theSelectionY, double theSelectionZ, double thePickPosition[3] )
+ {
+ // Convert the selection point into world coordinates.
+ //
+ theRenderer->SetDisplayPoint( theSelectionX, theSelectionY, theSelectionZ );
+ theRenderer->DisplayToWorld();
+ double* aWorldCoords = theRenderer->GetWorldPoint();
+ if ( aWorldCoords[3] != 0.0 ) {
+ for ( int i = 0; i < 3; i++ ) {
+ thePickPosition[i] = aWorldCoords[i] / aWorldCoords[3];
+ }
+ }
+ }
+}
+
+vtkStandardNewMacro( SVTK_AreaPicker )
+;
+
+SVTK_AreaPicker::SVTK_AreaPicker()
+{
+ this->Tolerance = 0.005;
+ this->PickPoints = 1;
+}
+
+SVTK_AreaPicker::~SVTK_AreaPicker()
+{
+}
+
+int SVTK_AreaPicker::Pick( double, double, double, vtkRenderer* )
+{
+ return 0;
+}
+
+int SVTK_AreaPicker::Pick( double theSelectionX, double theSelectionY,
+ double theSelectionX2, double theSelectionY2, vtkRenderer *theRenderer,
+ SelectionMode theMode )
+{
+ QVector< QPoint > aPoints;
+ aPoints.append( QPoint( theSelectionX, theSelectionY ) );
+ aPoints.append( QPoint( theSelectionX2, theSelectionY2 ) );
+ return Pick( aPoints, theRenderer, theMode );
+}
+
+int SVTK_AreaPicker::Pick( QVector< QPoint >& thePoints,
+ vtkRenderer *theRenderer, SelectionMode theMode )
+{
+ // Initialize picking process
+ this->Initialize();
+ myCellIdsMap.clear();
+ myPointIdsMap.clear();
+ this->Renderer = theRenderer;
+
+ if ( theMode == RectangleMode ) {
+ mySelection = {thePoints[0].x(), thePoints[0].y(), thePoints[1].x(), thePoints[1].y()};
+ }
+ else if( theMode == PolygonMode ) {
+ int minX, minY, maxX, maxY;
+ minX = maxX = thePoints[0].x();
+ minY = maxY = thePoints[0].y();
+ for ( int i=0; i < thePoints.size(); i++ ) {
+ if ( thePoints[i].x() < minX )
+ minX = thePoints[i].x();
+ if ( thePoints[i].x() > maxX )
+ maxX = thePoints[i].x();
+ if ( thePoints[i].y() < minY )
+ minY = thePoints[i].y();
+ if ( thePoints[i].y() > maxY )
+ maxY = thePoints[i].y();
+ }
+ mySelection = {minX, minY, maxX, maxY};
+ }
+
+ // Invoke start pick method if defined
+ this->InvokeEvent( vtkCommand::StartPickEvent, NULL );
+
+ vtkPropCollection *aProps;
+ if ( this->PickFromList ) aProps = this->GetPickList();
+ else
+ aProps = theRenderer->GetViewProps();
+
+ aProps->InitTraversal();
+ while( vtkProp* aProp = aProps->GetNextProp() ) {
+ aProp->InitPathTraversal();
+ while( vtkAssemblyPath* aPath = aProp->GetNextPath() ) {
+ vtkMapper *aMapper = NULL;
+ bool anIsPickable = false;
+ vtkActor* anActor = NULL;
+ vtkProp *aPropCandidate = aPath->GetLastNode()->GetViewProp();
+ if ( aPropCandidate->GetPickable() && aPropCandidate->GetVisibility() ) {
+ anIsPickable = true;
+ anActor = vtkActor::SafeDownCast( aPropCandidate );
+ if ( anActor ) {
+ aMapper = anActor->GetMapper();
+ if ( anActor->GetProperty()->GetOpacity() <= 0.0 ) anIsPickable =
+ false;
+ }
+ }
+ if ( anIsPickable && aMapper && aMapper->GetInput() ) {
+ if ( this->PickPoints ) {
+ TVectorIds& aVisibleIds = myPointIdsMap[anActor];
+ TVectorIds anInVisibleIds;
+ SelectVisiblePoints( thePoints, theRenderer, aMapper->GetInput(),
+ aVisibleIds, anInVisibleIds, this->Tolerance, theMode );
+ if ( aVisibleIds.empty() ) {
+ myPointIdsMap.erase( myPointIdsMap.find( anActor ) );
+ }
+ }
+ else {
+ TVectorIds& aVectorIds = myCellIdsMap[anActor];
+ SelectVisibleCells( thePoints, theRenderer, aMapper->GetInput(),
+ aVectorIds, this->Tolerance, theMode );
+ if ( aVectorIds.empty() ) {
+ myCellIdsMap.erase( myCellIdsMap.find( anActor ) );
+ }
+ }
+ }
+ }
+ }
+
+ // Invoke end pick method if defined
+ this->InvokeEvent( vtkCommand::EndPickEvent, NULL );
+
+ return myPointIdsMap.empty() || myCellIdsMap.empty();
+}
+
+//----------------------------------------------------------------------------
+void SVTK_AreaPicker::SelectVisiblePoints( QVector< QPoint >& thePoints,
+ vtkRenderer *theRenderer, vtkDataSet *theInput,
+ SVTK_AreaPicker::TVectorIds& theVisibleIds,
+ SVTK_AreaPicker::TVectorIds& theInVisibleIds, double theTolerance,
+ SelectionMode theMode )
+{
+ theVisibleIds.clear();
+ theInVisibleIds.clear();
+
+ vtkIdType aNumPts = theInput->GetNumberOfPoints();
+ if ( aNumPts < 1 ) return;
+
+ theVisibleIds.reserve( aNumPts / 2 + 1 );
+ theInVisibleIds.reserve( aNumPts / 2 + 1 );
+
+ // Grab the composite perspective transform. This matrix is used to convert
+ // each point to view coordinates. vtkRenderer provides a WorldToView()
+ // method but it computes the composite perspective transform each time
+ // WorldToView() is called. This is expensive, so we get the matrix once
+ // and handle the transformation ourselves.
+ vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
+ aMatrix->DeepCopy(
+ theRenderer->GetActiveCamera()->GetCompositeProjectionTransformMatrix(
+ theRenderer->GetTiledAspectRatio(), 0, 1 ) );
+
+ // We grab the z-buffer for the selection region all at once and probe the resulting array.
+ float *aZPtr = theRenderer->GetRenderWindow()->GetZbufferData( mySelection[0],
+ mySelection[1], mySelection[2], mySelection[3] );
+
+ for ( vtkIdType aPntId = 0; aPntId < aNumPts; aPntId++ ) {
+ // perform conversion
+ double aX[4] = { 1.0, 1.0, 1.0, 1.0 };
+ theInput->GetPoint( aPntId, aX );
+
+ double aView[4];
+ aMatrix->MultiplyPoint( aX, aView );
+ if ( aView[3] == 0.0 ) continue;
+ theRenderer->SetViewPoint( aView[0] / aView[3], aView[1] / aView[3],
+ aView[2] / aView[3] );
+ theRenderer->ViewToDisplay();
+
+ double aDX[3];
+ theRenderer->GetDisplayPoint( aDX );
+
+ bool isInSelection;
+ if ( theMode == RectangleMode ) isInSelection = aDX[0] >= mySelection[0]
+ && aDX[0] <= mySelection[2] && aDX[1] >= mySelection[1]
+ && aDX[1] <= mySelection[3];
+ else
+ if ( theMode == PolygonMode ) isInSelection =
+ SVTK_AreaPicker::isPointInPolygon( QPoint( aDX[0], aDX[1] ),
+ thePoints );
+
+ // check whether visible and in selection window
+ if ( isInSelection ) {
+ int aDX0 = int( aDX[0] );
+ int aDX1 = int( aDX[1] );
+
+ int aRet = Check( aZPtr, mySelection, theTolerance, aDX[2], aDX0, aDX1 );
+ if ( aRet > 0 ) goto ADD_VISIBLE;
+ if ( aRet < 0 ) goto ADD_INVISIBLE;
+
+ static int aMaxRadius = 5;
+ for ( int aRadius = 1; aRadius < aMaxRadius; aRadius++ ) {
+ int aStartDX[2] = { aDX0 - aRadius, aDX1 - aRadius };
+ for ( int i = 0; i <= aRadius; i++ ) {
+ int aRet = Check( aZPtr, mySelection, theTolerance, aDX[2],
+ aStartDX[0]++, aStartDX[1] );
+ if ( aRet > 0 ) goto ADD_VISIBLE;
+ if ( aRet < 0 ) goto ADD_INVISIBLE;
+ }
+ for ( int i = 0; i <= aRadius; i++ ) {
+ int aRet = Check( aZPtr, mySelection, theTolerance, aDX[2],
+ aStartDX[0], aStartDX[1]++ );
+ if ( aRet > 0 ) goto ADD_VISIBLE;
+ if ( aRet < 0 ) goto ADD_INVISIBLE;
+ }
+ for ( int i = 0; i <= aRadius; i++ ) {
+ int aRet = Check( aZPtr, mySelection, theTolerance, aDX[2],
+ aStartDX[0]--, aStartDX[1] );
+ if ( aRet > 0 ) goto ADD_VISIBLE;
+ if ( aRet < 0 ) goto ADD_INVISIBLE;
+ }
+ for ( int i = 0; i <= aRadius; i++ ) {
+ int aRet = Check( aZPtr, mySelection, theTolerance, aDX[2],
+ aStartDX[0], aStartDX[1]-- );
+ if ( aRet > 0 ) goto ADD_VISIBLE;
+ if ( aRet < 0 ) goto ADD_INVISIBLE;
+ }
+ }
+ if ( false ) ADD_VISIBLE:theVisibleIds.push_back( aPntId );
+ if ( false ) ADD_INVISIBLE:theInVisibleIds.push_back( aPntId );
+ }
+ } //for all points
+
+ aMatrix->Delete();
+
+ if ( aZPtr ) delete[] aZPtr;
+}
+
+void SVTK_AreaPicker::SelectVisibleCells( QVector< QPoint >& thePoints,
+ vtkRenderer *theRenderer, vtkDataSet *theInput,
+ SVTK_AreaPicker::TVectorIds& theVectorIds, double theTolerance,
+ SelectionMode theMode )
+{
+ theVectorIds.clear();
+
+ vtkIdType aNumCells = theInput->GetNumberOfCells();
+ if ( aNumCells < 1 ) return;
+
+ theVectorIds.reserve( aNumCells / 2 + 1 );
+
+ SVTK_AreaPicker::TVectorIds aVisiblePntIds;
+ SVTK_AreaPicker::TVectorIds anInVisiblePntIds;
+ SelectVisiblePoints( thePoints, theRenderer, theInput, aVisiblePntIds,
+ anInVisiblePntIds, theTolerance, theMode );
+
+ typedef std::set< vtkIdType > TIdsSet;
+ TIdsSet aVisibleIds( aVisiblePntIds.begin(), aVisiblePntIds.end() );
+ TIdsSet anInVisibleIds( anInVisiblePntIds.begin(), anInVisiblePntIds.end() );
+
+ // Grab the composite perspective transform. This matrix is used to convert
+ // each point to view coordinates. vtkRenderer provides a WorldToView()
+ // method but it computes the composite perspective transform each time
+ // WorldToView() is called. This is expensive, so we get the matrix once
+ // and handle the transformation ourselves.
+ vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
+ aMatrix->DeepCopy(
+ theRenderer->GetActiveCamera()->GetCompositeProjectionTransformMatrix(
+ theRenderer->GetTiledAspectRatio(), 0, 1 ) );
+
+ for ( vtkIdType aCellId = 0; aCellId < aNumCells; aCellId++ ) {
+ vtkCell* aCell = theInput->GetCell( aCellId );
+
+ double aBounds[6];
+ aCell->GetBounds( aBounds );
+
+ double aCenter[3];
+ GetCenter( aBounds, aCenter );
+
+ double aView[4];
+ double aX[4] = { aCenter[0], aCenter[1], aCenter[2], 1.0 };
+ aMatrix->MultiplyPoint( aX, aView );
+
+ if ( aView[3] == 0.0 ) continue;
+
+ theRenderer->SetViewPoint( aView[0] / aView[3], aView[1] / aView[3],
+ aView[2] / aView[3] );
+ theRenderer->ViewToDisplay();
+
+ double aDX[3];
+ theRenderer->GetDisplayPoint( aDX );
+
+ bool isInSelection;
+ if ( theMode == RectangleMode ) isInSelection = aDX[0] >= mySelection[0]
+ && aDX[0] <= mySelection[2] && aDX[1] >= mySelection[1]
+ && aDX[1] <= mySelection[3];
+ else
+ if ( theMode == PolygonMode ) isInSelection =
+ SVTK_AreaPicker::isPointInPolygon( QPoint( aDX[0], aDX[1] ),
+ thePoints );
+ // check whether visible and in selection window
+ if ( isInSelection ) {
+ vtkIdType aNumPts = aCell->GetNumberOfPoints();
+ bool anIsVisible = true;
+ for ( vtkIdType anId = 0; anId < aNumPts; anId++ ) {
+ vtkIdType aPntId = aCell->GetPointId( anId );
+ anIsVisible = aVisibleIds.find( aPntId ) != aVisibleIds.end();
+ if ( !anIsVisible ) break;
+ }
+ if ( anIsVisible ) theVectorIds.push_back( aCellId );
+ }
+ } //for all parts
+}
+
+bool SVTK_AreaPicker::isPointInPolygon( const QPoint& thePoint,
+ const QVector< QPoint >& thePolygon )
+{
+ double eps = 1.0;
+ if ( thePolygon.size() < 3 ) return false;
+
+ QVector< QPoint >::const_iterator end = thePolygon.end();
+ QPoint last_pt = thePolygon.back();
+
+ last_pt.setX( last_pt.x() - thePoint.x() );
+ last_pt.setY( last_pt.y() - thePoint.y() );
+
+ double sum = 0.0;
+
+ for ( QVector< QPoint >::const_iterator iter = thePolygon.begin();
+ iter != end; ++iter ) {
+ QPoint cur_pt = *iter;
+ cur_pt.setX( cur_pt.x() - thePoint.x() );
+ cur_pt.setY( cur_pt.y() - thePoint.y() );
+
+ double del = last_pt.x() * cur_pt.y() - cur_pt.x() * last_pt.y();
+ double xy = cur_pt.x() * last_pt.x() + cur_pt.y() * last_pt.y();
+
+ sum +=
+ ( atan(
+ ( last_pt.x() * last_pt.x() + last_pt.y() * last_pt.y() - xy )
+ / del )
+ + atan(
+ ( cur_pt.x() * cur_pt.x() + cur_pt.y() * cur_pt.y() - xy )
+ / del ) );
+
+ last_pt = cur_pt;
+ }
+ return fabs( sum ) > eps;
+}
+
+const SVTK_AreaPicker::TVectorIdsMap&
+SVTK_AreaPicker::GetPointIdsMap() const
+{
+ return myPointIdsMap;
+}
+
+const SVTK_AreaPicker::TVectorIdsMap&
+SVTK_AreaPicker::GetCellIdsMap() const
+{
+ return myCellIdsMap;
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// SALOME VTKViewer : build VTK viewer into Salome desktop
+// File : SVTK_AreaPicker.h
+// Author :
+// Module : SALOME
+//
+#ifndef __SVTK_AreaPicker_h
+#define __SVTK_AreaPicker_h
+
+#include "SVTK.h"
+#include "VTKViewer.h"
+
+#include <map>
+#include <vector>
+
+#include <vtkAbstractPropPicker.h>
+#include <vtkDataSet.h>
+#include <QVector>
+#include <QPoint>
+
+class vtkRenderer;
+
+#ifdef WIN32
+#pragma warning ( disable:4251 )
+#endif
+
+/*! \class vtkAbstractPropPicker
+ * \brief For more information see <a href="http://www.vtk.org/">VTK documentation
+ */
+/*! \class SVTK_AreaPicker
+ * \brief Rectangular picker class.
+ */
+class SVTK_EXPORT SVTK_AreaPicker : public vtkAbstractPropPicker
+{
+ public:
+
+ enum SelectionMode { RectangleMode, PolygonMode };
+
+ static
+ SVTK_AreaPicker *New();
+
+ vtkTypeMacro(SVTK_AreaPicker,vtkAbstractPropPicker);
+
+ /*!
+ Specify tolerance for performing pick operation. Tolerance is specified
+ as fraction of rendering window size. (Rendering window size is measured
+ across diagonal.)
+ */
+ vtkSetMacro(Tolerance,double);
+ vtkGetMacro(Tolerance,double);
+
+ //! Use these methods to pick points or points and cells
+ vtkSetMacro(PickPoints,int);
+ vtkGetMacro(PickPoints,int);
+ vtkBooleanMacro(PickPoints,int);
+
+ int
+ Pick( QVector<QPoint>& thePoints,
+ vtkRenderer *theRenderer,
+ SelectionMode theMode );
+
+ int
+ Pick( double theSelectionX,
+ double theSelectionY,
+ double theSelectionX2,
+ double theSelectionY2,
+ vtkRenderer *theRenderer,
+ SelectionMode theMode );
+
+ static bool
+ isPointInPolygon( const QPoint& thePoint,const QVector<QPoint>& thePolygon );
+
+ typedef std::vector<vtkIdType> TVectorIds;
+ typedef std::map<vtkActor*,TVectorIds> TVectorIdsMap;
+
+ const TVectorIdsMap&
+ GetPointIdsMap() const;
+
+ const TVectorIdsMap&
+ GetCellIdsMap() const;
+
+ protected:
+ SVTK_AreaPicker();
+ ~SVTK_AreaPicker();
+
+ //! tolerance for computation (% of window)
+ double Tolerance;
+
+ //! use the following to control picking mode
+ int PickPoints;
+
+ //! coordinates of bounding box of selection
+ int mySelection[4];
+
+ TVectorIdsMap myPointIdsMap;
+ TVectorIdsMap myCellIdsMap;
+
+ private:
+ virtual
+ int
+ Pick(double,
+ double,
+ double,
+ vtkRenderer*);
+
+ void
+ SelectVisiblePoints( QVector<QPoint>& thePoints,
+ vtkRenderer *theRenderer,
+ vtkDataSet *theInput,
+ SVTK_AreaPicker::TVectorIds& theVisibleIds,
+ SVTK_AreaPicker::TVectorIds& theInVisibleIds,
+ double theTolerance,
+ SelectionMode theMode );
+ void
+ SelectVisibleCells( QVector<QPoint>& thePoints,
+ vtkRenderer *theRenderer,
+ vtkDataSet *theInput,
+ SVTK_AreaPicker::TVectorIds& theVectorIds,
+ double theTolerance,
+ SelectionMode theMode );
+};
+
+#ifdef WIN32
+#pragma warning ( default:4251 )
+#endif
+
+#endif
+
+
#include <QPixmap>
#include <QWidget>
#include <QRubberBand>
+#include <QPolygon>
#include <algorithm>
#include <iostream>
myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New()),
myHighlightSelectionPointActor(SVTK_Actor::New()),
myRectBand(0),
- myIsAdvancedZoomingEnabled(false)
+ myPolygonBand(0),
+ myIsAdvancedZoomingEnabled(false),
+ myPoligonState( Disable )
{
myPointPicker->Delete();
SVTK_InteractorStyle::~SVTK_InteractorStyle()
{
endDrawRect();
+ endDrawPolygon();
}
/*!
myOtherPoint = QPoint(x, y);
}
+/*!
+ To handle mouse double click event
+*/
+void SVTK_InteractorStyle::OnMouseButtonDoubleClick()
+{
+ if( myPoligonState == InProcess ) {
+ onFinishOperation();
+ myPoligonState = Finished;
+ }
+}
+
/*!
To handle mouse move event
*/
int shift,
int x, int y)
{
+ if ( myPoligonState == Start ) {
+ // if right button was pressed and mouse is moved
+ // we can to draw a polygon for polygonal selection
+ myPoligonState = InProcess;
+ startOperation( VTK_INTERACTOR_STYLE_CAMERA_SELECT );
+ }
myShiftState = shift;
if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
onOperation(QPoint(x, y));
if(GetCurrentRenderer() == NULL)
return;
+ if ( myPoligonState != Disable )
+ return;
+
myShiftState = shift;
// finishing current viewer operation
if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
*/
void SVTK_InteractorStyle::OnLeftButtonUp(int vtkNotUsed(ctrl),
int shift,
- int vtkNotUsed(x),
- int vtkNotUsed(y))
+ int x,
+ int y)
{
myShiftState = shift;
+ if( myPoligonState == InProcess ) { // add a new point of polygon
+ myPolygonPoints.append( QPoint( x, y ) );
+ this->Interactor->GetEventPosition( mySelectionEvent->myX, mySelectionEvent->myY );
+ mySelectionEvent->myPolygonPoints.append( QPoint( mySelectionEvent->myX, mySelectionEvent->myY ) );
+ return;
+ }
+ else if ( myPoligonState == Closed ) { // close polygon and apply a selection
+ onFinishOperation();
+ myPoligonState = Finished;
+ return;
+ }
+ else if( myPoligonState == Finished || myPoligonState == NotValid )
+ return;
// finishing current viewer operation
if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
onFinishOperation();
if(GetCurrentRenderer() == NULL)
return;
+ if ( myPoligonState != Disable )
+ return;
+
myShiftState = shift;
// finishing current viewer operation
if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
int vtkNotUsed(x),
int vtkNotUsed(y))
{
+ if( myPoligonState == InProcess ) { // delete a point of polygon
+ if ( myPolygonPoints.size() > 2 ) {
+ myPolygonPoints.remove( myPolygonPoints.size() - 1 );
+ mySelectionEvent->myPolygonPoints.remove( mySelectionEvent->myPolygonPoints.size() - 1 );
+ }
+ return;
+ }
myShiftState = shift;
// finishing current viewer operation
if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
return;
myShiftState = shift;
+
+ if ( !ctrl ) {
+ myPoligonState = Start;
+ this->Interactor->GetEventPosition(mySelectionEvent->myX, mySelectionEvent->myY);
+ mySelectionEvent->myPolygonPoints.append( QPoint( mySelectionEvent->myX, mySelectionEvent->myY) );
+ }
// finishing current viewer operation
if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
onFinishOperation();
int vtkNotUsed(x),
int vtkNotUsed(y))
{
+ if( myPoligonState == Start ) { // if right button was pressed but mouse is not moved
+ myPoligonState = Disable;
+ mySelectionEvent->myPolygonPoints.clear();
+ }
+
+ if( myPoligonState != Disable ) {
+ endDrawPolygon();
+ myPoligonState = Finished;
+ startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
+ return;
+ }
+
myShiftState = shift;
// finishing current viewer operation
if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
case VTK_INTERACTOR_STYLE_CAMERA_FIT:
{
- drawRect();
+ if ( myPoligonState == InProcess )
+ drawPolygon();
+ else
+ drawRect();
break;
}
case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
}
else {
if (myPoint == myOtherPoint)
- {
- // process point selection
- this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY);
- Interactor->StartPickCallback();
+ {
+ // process point selection
+ this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY);
+ Interactor->StartPickCallback();
- SALOME_Actor* aHighlightedActor = NULL;
- vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
-
- aSelectionEvent->myIsRectangle = false;
+ SALOME_Actor* aHighlightedActor = NULL;
+ vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
- if(!myShiftState)
- GetSelector()->ClearIObjects();
+ aSelectionEvent->myIsRectangle = false;
+ aSelectionEvent->myIsPolygon = false;
+ if(!myShiftState)
+ GetSelector()->ClearIObjects();
- if( anActorCollection )
+ if( anActorCollection )
+ {
+ anActorCollection->InitTraversal();
+ while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
{
- anActorCollection->InitTraversal();
- while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
+ if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
{
- if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
+ if( anActor->Highlight( this, aSelectionEvent, true ) )
{
- if( anActor->Highlight( this, aSelectionEvent, true ) )
- {
- aHighlightedActor = anActor;
- break;
- }
+ aHighlightedActor = anActor;
+ break;
}
}
}
+ }
- if( !aHighlightedActor )
- {
- if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != aHighlightedActor)
- myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
- }
- myLastHighlitedActor = aHighlightedActor;
- }
- else
+ if( !aHighlightedActor )
{
- //processing rectangle selection
- Interactor->StartPickCallback();
- GetSelector()->StartPickCallback();
+ if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != aHighlightedActor)
+ myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
+ }
+ myLastHighlitedActor = aHighlightedActor;
+ }
+ else
+ {
+ if ( myPoligonState == InProcess || myPoligonState == Closed )
+ aSelectionEvent->myIsPolygon = true;
+ else
aSelectionEvent->myIsRectangle = true;
- if(!myShiftState)
- GetSelector()->ClearIObjects();
+ //processing polygonal selection
+ Interactor->StartPickCallback();
+ GetSelector()->StartPickCallback();
+
+ if(!myShiftState)
+ GetSelector()->ClearIObjects();
- VTK::ActorCollectionCopy aCopy(GetCurrentRenderer()->GetActors());
- vtkActorCollection* aListActors = aCopy.GetActors();
- aListActors->InitTraversal();
- while(vtkActor* aActor = aListActors->GetNextActor())
+ VTK::ActorCollectionCopy aCopy(GetCurrentRenderer()->GetActors());
+ vtkActorCollection* aListActors = aCopy.GetActors();
+ aListActors->InitTraversal();
+ while(vtkActor* aActor = aListActors->GetNextActor())
+ {
+ if(aActor->GetVisibility())
+ {
+ if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor))
{
- if(aActor->GetVisibility())
- {
- if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor))
- {
- if(aSActor->hasIO())
- aSActor->Highlight( this, aSelectionEvent, true );
- }
- }
+ if(aSActor->hasIO())
+ aSActor->Highlight( this, aSelectionEvent, true );
}
+ }
}
+ }
+ aSelectionEvent->myIsRectangle = false;
+ aSelectionEvent->myIsPolygon = false;
+ aSelectionEvent->myPolygonPoints.clear();
+ endDrawPolygon();
Interactor->EndPickCallback();
GetSelector()->EndPickCallback();
}
- }
- break;
- case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
- case VTK_INTERACTOR_STYLE_CAMERA_PAN:
- case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
- case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
- break;
- case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
+ break;
+ }
+ case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
+ case VTK_INTERACTOR_STYLE_CAMERA_PAN:
+ case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
+ case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
+ break;
+ case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
{
int w, h, x, y;
Interactor->GetSize(w, h);
case VTK_INTERACTOR_STYLE_CAMERA_FIT:
{
myOtherPoint = mousePos;
- drawRect();
+ if ( myPoligonState == InProcess || myPoligonState == Closed || myPoligonState == NotValid )
+ drawPolygon();
+ else if ( myPoligonState != Finished )
+ drawRect();
break;
}
}
myRectBand->setVisible( aRect.isValid() );
}
+bool isIntersect( const QPoint& theStart1, const QPoint& theEnd1,
+ const QPoint& theStart2, const QPoint& theEnd2 )
+{
+ if ( ( theStart1 == theStart2 && theEnd1 == theEnd2 ) ||
+ ( theStart1 == theEnd2 && theEnd1 == theStart2 ) )
+ return true;
+
+ if ( theStart1 == theStart2 || theStart2 == theEnd1 ||
+ theStart1 == theEnd2 || theEnd1 == theEnd2 )
+ return false;
+
+ double x11 = theStart1.x() * 1.0;
+ double x12 = theEnd1.x() * 1.0;
+ double y11 = theStart1.y() * 1.0;
+ double y12 = theEnd1.y() * 1.0;
+
+ double x21 = theStart2.x() * 1.0;
+ double x22 = theEnd2.x() * 1.0;
+ double y21 = theStart2.y() * 1.0;
+ double y22 = theEnd2.y() * 1.0;
+
+ double k1 = x12 == x11 ? 0 : ( y12 - y11 ) / ( x12 - x11 );
+ double k2 = x22 == x21 ? 0 : ( y22 - y21 ) / ( x22 - x21 );
+
+ double b1 = y11 - k1 * x11;
+ double b2 = y21 - k2 * x21;
+
+ if ( k1 == k2 )
+ {
+ if ( b1 != b2 )
+ return false;
+ else
+ return !( ( qMax( x11, x12 ) <= qMin( x21, x22 ) ||
+ qMin( x11, x12 ) >= qMax( x21, x22 ) ) &&
+ ( qMax( y11, y12 ) <= qMin( y21, y22 ) ||
+ qMin( y11, y12 ) >= qMax( y21, y22 ) ) );
+ }
+ else
+ {
+ double x0 = ( b2 - b1 ) / ( k1 - k2 );
+ double y0 = ( k1 * b2 - k2 * b1 ) / ( k1 - k2 );
+
+ if ( qMin( x11, x12 ) < x0 && x0 < qMax( x11, x12 ) &&
+ qMin( y11, y12 ) < y0 && y0 < qMax( y11, y12 ) &&
+ qMin( x21, x22 ) < x0 && x0 < qMax( x21, x22 ) &&
+ qMin( y21, y22 ) < y0 && y0 < qMax( y21, y22 ) )
+ return true;
+ }
+ return false;
+}
+
+bool isValid( const QPolygon* thePoints, const QPoint& theCurrent )
+{
+ if ( !thePoints->count() )
+ return true;
+
+ if ( thePoints->count() == 1 && thePoints->point( 0 ) == theCurrent )
+ return false;
+
+ const QPoint& aLast = thePoints->point( thePoints->count() - 1 );
+
+ if ( aLast == theCurrent )
+ return true;
+
+ bool res = true;
+ for ( uint i = 0; i < thePoints->count() - 1 && res; i++ )
+ {
+ const QPoint& aStart = thePoints->point( i );
+ const QPoint& anEnd = thePoints->point( i + 1 );
+ res = !isIntersect( aStart, anEnd, theCurrent, aLast );
+ }
+ return res;
+}
+
+/*!
+ Draws polygon
+*/
+void SVTK_InteractorStyle::drawPolygon()
+{
+ QSize aToler( 5, 5 );
+ if ( !myPolygonBand ) {
+ myPolygonBand = new QtxPolyRubberBand( GetRenderWidget() );
+ QPalette palette;
+ palette.setColor( myPolygonBand->foregroundRole(), Qt::white );
+ myPolygonBand->setPalette( palette );
+ myPolygonPoints.append( QPoint( myPoint.x(), myPoint.y() ) );
+ }
+ myPolygonBand->hide();
+
+ bool closed = false;
+ bool valid = GetRenderWidget()->rect().contains( QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
+ if ( !myPolygonPoints.at(0).isNull() )
+ {
+ QRect aRect( myPolygonPoints.at(0).x() - aToler.width(), myPolygonPoints.at(0).y() - aToler.height(),
+ 2 * aToler.width(), 2 * aToler.height() );
+ closed = aRect.contains( QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
+ }
+
+ QPolygon* points = new QPolygon( myPolygonPoints );
+ valid = valid && isValid( points, QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
+ myPoligonState = valid ? InProcess : NotValid;
+ delete points;
+ if ( closed && !valid )
+ closed = false;
+
+ if ( closed && myPolygonPoints.size() > 2 ) {
+ GetRenderWidget()->setCursor( Qt::CrossCursor );
+ myPoligonState = Closed;
+ }
+ else if ( valid )
+ GetRenderWidget()->setCursor( Qt::PointingHandCursor );
+ else
+ GetRenderWidget()->setCursor( Qt::ForbiddenCursor );
+
+ myPolygonPoints.append( QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
+
+ QPolygon aPolygon( myPolygonPoints );
+ myPolygonBand->initGeometry( aPolygon );
+ myPolygonBand->setVisible( true );
+
+ if ( myPolygonPoints.size() > 1 ) {
+ myPolygonPoints.remove( myPolygonPoints.size() - 1 );
+ }
+}
+
/*!
\brief Delete rubber band on the end on the dragging operation.
*/
myRectBand = 0;
}
+/*!
+ \brief Delete rubber band on the end on the dragging operation.
+*/
+void SVTK_InteractorStyle::endDrawPolygon()
+{
+ if ( myPolygonBand ) myPolygonBand->hide();
+
+ delete myPolygonBand;
+ myPolygonBand = 0;
+
+ myPolygonPoints.clear();
+}
+
/*!
Main process event method (reimplemented from #vtkInteractorStyle)
*/
#include <vtkSmartPointer.h>
#include <QCursor>
+#include <QtxRubberBand.h>
#include <map>
#define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
#define VTK_INTERACTOR_STYLE_CAMERA_SELECT_ROTATION_POINT 8
+enum PolygonState { Disable, Start, InProcess, Finished, Closed, NotValid };
+
//! Introduce SALOME way of user interaction
/*!
This class defines SALOME way of user interaction for VTK viewer, as well,
//! To handle mouse wheel backward event (reimplemented from #vtkInteractorStyle)
virtual void OnMouseWheelBackward();
+ //! To handle mouse button double click event
+ virtual void OnMouseButtonDoubleClick();
+
//! To handle keyboard event (reimplemented from #vtkInteractorStyle)
virtual void OnChar();
SVTK_Selector* GetSelector();
- int CurrentState() const { return State; }
+ int CurrentState() const { return State; }
+ PolygonState GetPolygonState() const { return myPoligonState; }
+ void SetPolygonState( const PolygonState& thePolygonState )
+ { myPoligonState = thePolygonState; }
void SetAdvancedZoomingEnabled( const bool theState ) { myIsAdvancedZoomingEnabled = theState; }
bool IsAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; }
void drawRect();
void endDrawRect();
+ void drawPolygon();
+ void endDrawPolygon();
protected:
QCursor myDefCursor;
vtkSmartPointer<SVTK_Actor> myHighlightSelectionPointActor;
vtkSmartPointer<vtkPointPicker> myPointPicker;
- double myBBCenter[3];
+ double myBBCenter[3];
bool myBBFirstCheck;
QRubberBand* myRectBand; //!< selection rectangle rubber band
+ QtxPolyRubberBand* myPolygonBand; //!< polygonal selection
+ QVector<QPoint> myPolygonPoints;
+ PolygonState myPoligonState;
bool myIsAdvancedZoomingEnabled;
};
//----------------------------------------------------------------------------
SVTK_KeyFreeInteractorStyle::SVTK_KeyFreeInteractorStyle():
- myIsMidButtonDown( false ),
- myIsLeftButtonDown( false )
+ myIsLeftButtonDown( false ),
+ myIsRightButtonDown( false )
{
}
{
}
+//----------------------------------------------------------------------------
+void SVTK_KeyFreeInteractorStyle::OnMouseMove(int ctrl,
+ int shift,
+ int x, int y)
+{
+ // OnLeftButtonDown + OnMouseMove = Rotate
+ if ( myIsLeftButtonDown ) {
+ OnLeftButtonDown( ctrl, shift, x, y );
+ myIsLeftButtonDown = false;
+ }
+ // OnRightButtonDown + OnMouseMove = Zoom
+ if ( myIsRightButtonDown ) {
+ OnRightButtonDown( ctrl, shift, x, y );
+ myIsRightButtonDown = false;
+ }
+ SVTK_InteractorStyle::OnMouseMove( ctrl, shift, x, y );
+}
+
//----------------------------------------------------------------------------
void SVTK_KeyFreeInteractorStyle::OnLeftButtonDown(int ctrl, int shift,
int x, int y)
{
- myIsLeftButtonDown = true;
+ if ( ctrl ) {
+ SVTK_InteractorStyle::OnLeftButtonDown( !ctrl, shift, x, y );
+ return;
+ }
+
+ if( !myIsLeftButtonDown ) {
+ myIsLeftButtonDown = true;
+ return;
+ }
if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
startOperation(ForcedState);
}
- else {
- if (!(ctrl||shift)){
- if (myIsMidButtonDown){
- startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
- }
- else{
- startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
- }
- }
- }
+ else if ( !shift )
+ startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
+
return;
}
int shift,
int x, int y)
{
- myIsMidButtonDown = true;
+ if ( ctrl ) {
+ SVTK_InteractorStyle::OnMiddleButtonDown( !ctrl, shift, x, y );
+ return;
+ }
if (this->HasObserver(vtkCommand::MiddleButtonPressEvent)) {
this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
startOperation(ForcedState);
}
- else {
- if (!(ctrl||shift)){
- if ( myIsLeftButtonDown ){
- startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
- }
- else{
- startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
- }
- }
+ else if ( !shift )
+ startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
+}
+
+//----------------------------------------------------------------------------
+void SVTK_KeyFreeInteractorStyle::OnRightButtonDown( int ctrl,
+ int shift,
+ int x, int y )
+{
+ if ( ctrl ) {
+ SVTK_InteractorStyle::OnRightButtonDown( !ctrl, shift, x, y );
+ return;
}
+
+ if( !myIsRightButtonDown ) {
+ myIsRightButtonDown = true;
+ return;
+ }
+
+ if( this->HasObserver( vtkCommand::RightButtonPressEvent ) ) {
+ this->InvokeEvent( vtkCommand::RightButtonPressEvent, NULL );
+ return;
+ }
+ this->FindPokedRenderer( x, y );
+ if( this->CurrentRenderer == NULL ) {
+ return;
+ }
+ myShiftState = shift;
+ // finishing current viewer operation
+ if ( State != VTK_INTERACTOR_STYLE_CAMERA_NONE ) {
+ onFinishOperation();
+ startOperation( VTK_INTERACTOR_STYLE_CAMERA_NONE );
+ }
+ myOtherPoint = myPoint = QPoint(x, y);
+ if ( ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE ) {
+ startOperation(ForcedState);
+ }
+ else if ( !shift )
+ startOperation( VTK_INTERACTOR_STYLE_CAMERA_ZOOM );
}
//----------------------------------------------------------------------------
void SVTK_KeyFreeInteractorStyle::OnLeftButtonUp(int ctrl, int shift, int x, int y)
{
- myIsLeftButtonDown = false;
+ // OnLeftButtonDown + OnLeftButtonUp = Select
+ if ( myIsLeftButtonDown ) {
+ SVTK_InteractorStyle::OnLeftButtonDown( ctrl, shift, x, y );
+ myIsLeftButtonDown = false;
+ }
SVTK_InteractorStyle::OnLeftButtonUp( ctrl, shift, x, y );
-
- if ( myIsMidButtonDown )
- OnMiddleButtonDown( ctrl, shift, x, y );
}
//----------------------------------------------------------------------------
void SVTK_KeyFreeInteractorStyle::OnMiddleButtonUp(int ctrl, int shift, int x, int y)
{
- myIsMidButtonDown = false;
SVTK_InteractorStyle::OnMiddleButtonUp( ctrl, shift, x, y );
+}
- if ( myIsLeftButtonDown )
- OnLeftButtonDown( ctrl, shift, x, y );
+//----------------------------------------------------------------------------
+void SVTK_KeyFreeInteractorStyle::OnRightButtonUp(int ctrl, int shift, int x, int y)
+{
+ // OnRightButtonDown + OnRightButtonUp = Open context menu
+ if( myIsRightButtonDown ) {
+ myIsRightButtonDown = false;
+ SVTK_InteractorStyle::OnRightButtonDown( ctrl, shift, x, y );
+ }
+ SVTK_InteractorStyle::OnRightButtonUp( ctrl, shift, x, y );
}
//----------------------------------------------------------------------------
// Generic event bindings must be overridden in subclasses
+ //! Redefine SVTK_InteractorStyle::OnMouseMove
+ virtual void OnMouseMove(int ctrl, int shift, int x, int y);
+
//! Redefine SVTK_InteractorStyle::OnLeftButtonDown
virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y);
//! Redefine SVTK_InteractorStyle::OnMiddleButtonDown
virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
+ //! Redefine SVTK_InteractorStyle::OnRightButtonDown
+ virtual void OnRightButtonDown(int ctrl, int shift, int x, int y);
+
//! Redefine SVTK_InteractorStyle::OnLeftButtonUp
virtual void OnLeftButtonUp(int ctrl, int shift, int x, int y);
//! Redefine SVTK_InteractorStyle::OnMiddleButtonUp
virtual void OnMiddleButtonUp(int ctrl, int shift, int x, int y);
+ //! Redefine SVTK_InteractorStyle::OnRightButtonUp
+ virtual void OnRightButtonUp(int ctrl, int shift, int x, int y);
+
//! Redefine SVTK_InteractorStyle::OnChar
virtual void OnChar();
-
- bool myIsMidButtonDown;
+
bool myIsLeftButtonDown;
+ bool myIsRightButtonDown;
};
#endif
+++ /dev/null
-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-
-// SALOME VTKViewer : build VTK viewer into Salome desktop
-// File : SVTK_RectPicker.cxx
-// Author :
-// Module : SALOME
-//
-#include "SVTK_RectPicker.h"
-
-#include <set>
-
-#include <vtkObjectFactory.h>
-#include <vtkCommand.h>
-
-#include <vtkAbstractMapper3D.h>
-#include <vtkMapper.h>
-#include <vtkProperty.h>
-
-#include <vtkAssemblyPath.h>
-#include <vtkAssemblyNode.h>
-
-#include <vtkRenderWindow.h>
-#include <vtkMatrix4x4.h>
-#include <vtkRenderer.h>
-#include <vtkDataSet.h>
-#include <vtkPoints.h>
-#include <vtkCamera.h>
-#include <vtkCell.h>
-
-namespace
-{
- //----------------------------------------------------------------------------
- inline
- double
- GetZ(float* theZPtr,
- int theSelection[4],
- int theDX,
- int theDY)
- {
- return theZPtr[theDX - theSelection[0] + (theDY - theSelection[1])*(theSelection[2] - theSelection[0] + 1)];
- }
-
-
- //----------------------------------------------------------------------------
- inline
- int
- Check(float* theZPtr,
- int theSelection[4],
- double theTolerance,
- double theDZ,
- int theDX,
- int theDY)
- {
- int aRet = 0;
- double aZ = -1.0;
- if(theDX >= theSelection[0] && theDX <= theSelection[2] &&
- theDY >= theSelection[1] && theDY <= theSelection[3])
- {
- // Access the value from the captured zbuffer. Note, we only
- // captured a portion of the zbuffer, so we need to offset dx by
- // the selection window.
- aZ = GetZ(theZPtr,theSelection,theDX,theDY);
- if(aZ > theTolerance && aZ < 1.0 - theTolerance){
- aRet = fabs(aZ - theDZ) <= theTolerance;
- }
- }
-
- //cout<<"\tCheck = {"<<theDX<<", "<<theDY<<", "<<theDZ<<", "<<aZ<<"} = "<<aRet<<"\n";
- return aRet;
- }
-
-
- //----------------------------------------------------------------------------
- void
- SelectVisiblePoints(int theSelection[4],
- vtkRenderer *theRenderer,
- vtkDataSet *theInput,
- SVTK_RectPicker::TVectorIds& theVisibleIds,
- SVTK_RectPicker::TVectorIds& theInVisibleIds,
- double theTolerance)
- {
- theVisibleIds.clear();
- theInVisibleIds.clear();
-
- vtkIdType aNumPts = theInput->GetNumberOfPoints();
- if(aNumPts < 1)
- return;
-
- theVisibleIds.reserve(aNumPts/2 + 1);
- theInVisibleIds.reserve(aNumPts/2 + 1);
-
- // Grab the composite perspective transform. This matrix is used to convert
- // each point to view coordinates. vtkRenderer provides a WorldToView()
- // method but it computes the composite perspective transform each time
- // WorldToView() is called. This is expensive, so we get the matrix once
- // and handle the transformation ourselves.
- vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
- aMatrix->DeepCopy( theRenderer->GetActiveCamera()->
- GetCompositeProjectionTransformMatrix( theRenderer->GetTiledAspectRatio(), 0, 1 ) );
-
- // We grab the z-buffer for the selection region all at once and probe the resulting array.
- float *aZPtr = theRenderer->GetRenderWindow()->
- GetZbufferData(theSelection[0], theSelection[1], theSelection[2], theSelection[3]);
-
- //cout<<"theSelection = {"<<theSelection[0]<<", "<<theSelection[1]<<", "<<theSelection[2]<<", "<<theSelection[3]<<"}\n";
-
- //cout<<"\t";
- for(int iX = theSelection[0]; iX <= theSelection[2]; iX++){
- //cout<<iX<<"\t";
- }
- //cout<<endl;
-
- for(int iY = theSelection[1]; iY <= theSelection[3]; iY++){
- //cout<<iY<<"\t";
- for(int iX = theSelection[0]; iX <= theSelection[2]; iX++){
- //cout<<std::setprecision(4)<<GetZ(aZPtr,theSelection,iX,iY)<<"\t";
- }
- //cout<<endl;
- }
-
- for(vtkIdType aPntId = 0; aPntId < aNumPts; aPntId++){
- // perform conversion
- double aX[4] = {1.0, 1.0, 1.0, 1.0};
- theInput->GetPoint(aPntId,aX);
-
- double aView[4];
- aMatrix->MultiplyPoint(aX,aView);
- if(aView[3] == 0.0)
- continue;
- theRenderer->SetViewPoint(aView[0]/aView[3],
- aView[1]/aView[3],
- aView[2]/aView[3]);
- theRenderer->ViewToDisplay();
-
- double aDX[3];
- theRenderer->GetDisplayPoint(aDX);
-
- // check whether visible and in selection window
- if(aDX[0] >= theSelection[0] && aDX[0] <= theSelection[2] &&
- aDX[1] >= theSelection[1] && aDX[1] <= theSelection[3])
- {
- //cout<<"aPntId "<<aPntId<<"; aDX = {"<<aDX[0]<<", "<<aDX[1]<<", "<<aDX[2]<<"}\n";
- int aDX0 = int(aDX[0]);
- int aDX1 = int(aDX[1]);
-
- int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aDX0,aDX1);
- if(aRet > 0)
- goto ADD_VISIBLE;
- if(aRet < 0)
- goto ADD_INVISIBLE;
-
- static int aMaxRadius = 5;
- for(int aRadius = 1; aRadius < aMaxRadius; aRadius++){
- int aStartDX[2] = {aDX0 - aRadius, aDX1 - aRadius};
- for(int i = 0; i <= aRadius; i++){
- int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0]++,aStartDX[1]);
- if(aRet > 0)
- goto ADD_VISIBLE;
- if(aRet < 0)
- goto ADD_INVISIBLE;
- }
- for(int i = 0; i <= aRadius; i++){
- int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0],aStartDX[1]++);
- if(aRet > 0)
- goto ADD_VISIBLE;
- if(aRet < 0)
- goto ADD_INVISIBLE;
- }
- for(int i = 0; i <= aRadius; i++){
- int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0]--,aStartDX[1]);
- if(aRet > 0)
- goto ADD_VISIBLE;
- if(aRet < 0)
- goto ADD_INVISIBLE;
- }
- for(int i = 0; i <= aRadius; i++){
- int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0],aStartDX[1]--);
- if(aRet > 0)
- goto ADD_VISIBLE;
- if(aRet < 0)
- goto ADD_INVISIBLE;
- }
- }
- if(false)
- ADD_VISIBLE : theVisibleIds.push_back(aPntId);
- if(false)
- ADD_INVISIBLE : theInVisibleIds.push_back(aPntId);
- }
- }//for all points
-
- aMatrix->Delete();
-
- if(aZPtr)
- delete [] aZPtr;
- }
-
-
- //----------------------------------------------------------------------------
- inline
- void
- GetCenter(const double theBounds[6],
- double theCenter[3])
- {
- theCenter[0] = (theBounds[1] + theBounds[0]) / 2.0;
- theCenter[1] = (theBounds[3] + theBounds[2]) / 2.0;
- theCenter[2] = (theBounds[5] + theBounds[4]) / 2.0;
- }
-
- void
- SelectVisibleCells(int theSelection[4],
- vtkRenderer *theRenderer,
- vtkDataSet *theInput,
- SVTK_RectPicker::TVectorIds& theVectorIds,
- double theTolerance)
- {
- theVectorIds.clear();
-
- vtkIdType aNumCells = theInput->GetNumberOfCells();
- if(aNumCells < 1)
- return;
-
- theVectorIds.reserve(aNumCells/2 + 1);
-
- SVTK_RectPicker::TVectorIds aVisiblePntIds;
- SVTK_RectPicker::TVectorIds anInVisiblePntIds;
- SelectVisiblePoints(theSelection,
- theRenderer,
- theInput,
- aVisiblePntIds,
- anInVisiblePntIds,
- theTolerance);
-
- typedef std::set<vtkIdType> TIdsSet;
- TIdsSet aVisibleIds(aVisiblePntIds.begin(),aVisiblePntIds.end());
- TIdsSet anInVisibleIds(anInVisiblePntIds.begin(),anInVisiblePntIds.end());
-
- // Grab the composite perspective transform. This matrix is used to convert
- // each point to view coordinates. vtkRenderer provides a WorldToView()
- // method but it computes the composite perspective transform each time
- // WorldToView() is called. This is expensive, so we get the matrix once
- // and handle the transformation ourselves.
- vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
- aMatrix->DeepCopy(theRenderer->GetActiveCamera()->
- GetCompositeProjectionTransformMatrix( theRenderer->GetTiledAspectRatio(), 0, 1 ) );
-
- for(vtkIdType aCellId = 0; aCellId < aNumCells; aCellId++){
- vtkCell* aCell = theInput->GetCell(aCellId);
-
- double aBounds[6];
- aCell->GetBounds(aBounds);
-
- double aCenter[3];
- GetCenter(aBounds,aCenter);
-
- double aView[4];
- double aX[4] = {aCenter[0], aCenter[1], aCenter[2], 1.0};
- aMatrix->MultiplyPoint(aX,aView);
-
- if(aView[3] == 0.0)
- continue;
-
- theRenderer->SetViewPoint(aView[0]/aView[3],
- aView[1]/aView[3],
- aView[2]/aView[3]);
- theRenderer->ViewToDisplay();
-
- double aDX[3];
- theRenderer->GetDisplayPoint(aDX);
-
- // check whether visible and in selection window
- if(aDX[0] >= theSelection[0] && aDX[0] <= theSelection[2] &&
- aDX[1] >= theSelection[1] && aDX[1] <= theSelection[3])
- {
-
- //cout<<"aCellId = "<<aCellId<<": ";
- vtkIdType aNumPts = aCell->GetNumberOfPoints();
- bool anIsVisible = true;
- for(vtkIdType anId = 0; anId < aNumPts; anId++){
- vtkIdType aPntId = aCell->GetPointId(anId);
- //cout<<aPntId<<"; ";
- anIsVisible = aVisibleIds.find(aPntId) != aVisibleIds.end();
- if(!anIsVisible)
- break;
- }
- //cout<<"\t"<<anIsVisible<<"\n";
- if(anIsVisible)
- theVectorIds.push_back(aCellId);
- }
- }//for all parts
- }
-
- //----------------------------------------------------------------------------
- void
- CalculatePickPosition(vtkRenderer *theRenderer,
- double theSelectionX,
- double theSelectionY,
- double theSelectionZ,
- double thePickPosition[3])
- {
- // Convert the selection point into world coordinates.
- //
- theRenderer->SetDisplayPoint(theSelectionX, theSelectionY, theSelectionZ);
- theRenderer->DisplayToWorld();
- double* aWorldCoords = theRenderer->GetWorldPoint();
- if ( aWorldCoords[3] != 0.0 ) {
- for (int i=0; i < 3; i++) {
- thePickPosition[i] = aWorldCoords[i] / aWorldCoords[3];
- }
- }
- }
-}
-
-vtkStandardNewMacro(SVTK_RectPicker);
-
-SVTK_RectPicker
-::SVTK_RectPicker()
-{
- this->Tolerance = 0.005;
- this->PickPoints = 1;
-}
-
-SVTK_RectPicker
-::~SVTK_RectPicker()
-{}
-
-int
-SVTK_RectPicker
-::Pick(double,
- double,
- double,
- vtkRenderer*)
-{
- return 0;
-}
-
-int
-SVTK_RectPicker
-::Pick(double theSelection[3],
- double theSelection2[3],
- vtkRenderer *theRenderer)
-{
- return Pick(theSelection[0], theSelection[1], theSelection[2],
- theSelection2[0], theSelection2[1], theSelection2[2],
- theRenderer);
-}
-
-int
-SVTK_RectPicker
-::Pick(double theSelectionX,
- double theSelectionY,
- double theSelectionZ,
- double theSelectionX2,
- double theSelectionY2,
- double theSelectionZ2,
- vtkRenderer *theRenderer)
-{
- // Initialize picking process
- this->Initialize();
- myCellIdsMap.clear();
- myPointIdsMap.clear();
- this->Renderer = theRenderer;
-
- // Get camera focal point and position. Convert to display (screen)
- // coordinates. We need a depth value for z-buffer.
- //
- vtkCamera* aCamera = theRenderer->GetActiveCamera();
-
- double aCameraFP[4];
- aCamera->GetFocalPoint(aCameraFP);
- aCameraFP[3] = 1.0;
-
- theRenderer->SetWorldPoint(aCameraFP);
- theRenderer->WorldToDisplay();
- double* aDisplayCoords = theRenderer->GetDisplayPoint();
- double aSelectionZ = aDisplayCoords[2];
-
- this->SelectionPoint[0] = theSelectionX;
- this->SelectionPoint[1] = theSelectionY;
- this->SelectionPoint[2] = theSelectionZ;
-
- // Convert the selection point into world coordinates.
- //
- CalculatePickPosition(theRenderer,
- theSelectionX,
- theSelectionY,
- aSelectionZ,
- this->PickPosition);
-
- this->SelectionPoint2[0] = theSelectionX2;
- this->SelectionPoint2[1] = theSelectionY2;
- this->SelectionPoint2[2] = theSelectionZ2;
-
- // Convert the selection point into world coordinates.
- //
- CalculatePickPosition(theRenderer,
- theSelectionX2,
- theSelectionY2,
- aSelectionZ,
- this->PickPosition2);
-
- // Invoke start pick method if defined
- this->InvokeEvent(vtkCommand::StartPickEvent,NULL);
-
- vtkPropCollection *aProps;
- if ( this->PickFromList )
- aProps = this->GetPickList();
- else
- aProps = theRenderer->GetViewProps();
-
- aProps->InitTraversal();
- while ( vtkProp* aProp = aProps->GetNextProp() ) {
- aProp->InitPathTraversal();
- while ( vtkAssemblyPath* aPath = aProp->GetNextPath() ) {
- vtkMapper *aMapper = NULL;
- bool anIsPickable = false;
- vtkActor* anActor = NULL;
- vtkProp *aPropCandidate = aPath->GetLastNode()->GetViewProp();
- if ( aPropCandidate->GetPickable() && aPropCandidate->GetVisibility() ) {
- anIsPickable = true;
- anActor = vtkActor::SafeDownCast(aPropCandidate);
- if ( anActor ) {
- aMapper = anActor->GetMapper();
- if ( anActor->GetProperty()->GetOpacity() <= 0.0 )
- anIsPickable = false;
- }
- }
- if ( anIsPickable && aMapper && aMapper->GetInput()) {
- int aSelectionPoint[4] = {int(theSelectionX),
- int(theSelectionY),
- int(theSelectionX2),
- int(theSelectionY2)};
- if ( this->PickPoints ) {
- TVectorIds& aVisibleIds = myPointIdsMap[anActor];
- TVectorIds anInVisibleIds;
- SelectVisiblePoints(aSelectionPoint,
- theRenderer,
- aMapper->GetInput(),
- aVisibleIds,
- anInVisibleIds,
- this->Tolerance);
- if ( aVisibleIds.empty() ) {
- myPointIdsMap.erase(myPointIdsMap.find(anActor));
- }
- } else {
- TVectorIds& aVectorIds = myCellIdsMap[anActor];
- SelectVisibleCells(aSelectionPoint,
- theRenderer,
- aMapper->GetInput(),
- aVectorIds,
- this->Tolerance);
- if ( aVectorIds.empty() ) {
- myCellIdsMap.erase(myCellIdsMap.find(anActor));
- }
- }
- }
- }
- }
-
- // Invoke end pick method if defined
- this->InvokeEvent(vtkCommand::EndPickEvent,NULL);
-
- return myPointIdsMap.empty() || myCellIdsMap.empty();
-}
-
-
-const SVTK_RectPicker::TVectorIdsMap&
-SVTK_RectPicker
-::GetPointIdsMap() const
-{
- return myPointIdsMap;
-}
-
-const SVTK_RectPicker::TVectorIdsMap&
-SVTK_RectPicker
-::GetCellIdsMap() const
-{
- return myCellIdsMap;
-}
+++ /dev/null
-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-
-// SALOME VTKViewer : build VTK viewer into Salome desktop
-// File : SVTK_RectPicker.h
-// Author :
-// Module : SALOME
-//
-#ifndef __SVTK_RectPicker_h
-#define __SVTK_RectPicker_h
-
-#include "SVTK.h"
-#include "VTKViewer.h"
-
-#include <map>
-#include <vector>
-
-#include <vtkAbstractPropPicker.h>
-
-class vtkRenderer;
-
-#ifdef WIN32
-#pragma warning ( disable:4251 )
-#endif
-
-/*! \class vtkAbstractPropPicker
- * \brief For more information see <a href="http://www.vtk.org/">VTK documentation
- */
-/*! \class SVTK_RectPicker
- * \brief Rectangular picker class.
- */
-class SVTK_EXPORT SVTK_RectPicker : public vtkAbstractPropPicker
-{
- public:
- static
- SVTK_RectPicker *New();
-
- vtkTypeMacro(SVTK_RectPicker,vtkAbstractPropPicker);
-
- /*!
- Specify tolerance for performing pick operation. Tolerance is specified
- as fraction of rendering window size. (Rendering window size is measured
- across diagonal.)
- */
- vtkSetMacro(Tolerance,double);
- vtkGetMacro(Tolerance,double);
-
- //! Use these methods to pick points or points and cells
- vtkSetMacro(PickPoints,int);
- vtkGetMacro(PickPoints,int);
- vtkBooleanMacro(PickPoints,int);
-
- virtual
- int
- Pick(double theSelectionX,
- double theSelectionY,
- double theSelectionZ,
- double theSelectionX2,
- double theSelectionY2,
- double theSelectionZ2,
- vtkRenderer *theRenderer);
-
- int
- Pick(double theSelection[3],
- double theSelection2[3],
- vtkRenderer *theRenderer);
-
- typedef std::vector<vtkIdType> TVectorIds;
- typedef std::map<vtkActor*,TVectorIds> TVectorIdsMap;
-
- const TVectorIdsMap&
- GetPointIdsMap() const;
-
- const TVectorIdsMap&
- GetCellIdsMap() const;
-
- protected:
- SVTK_RectPicker();
- ~SVTK_RectPicker();
-
- //! tolerance for computation (% of window)
- double Tolerance;
-
- //! use the following to control picking mode
- int PickPoints;
-
- //! second rectangle selection point in window (pixel) coordinates
- double SelectionPoint2[3];
-
- //! second rectangle selection point in world coordinates
- double PickPosition2[3];
-
- TVectorIdsMap myPointIdsMap;
- TVectorIdsMap myCellIdsMap;
-
- private:
- virtual
- int
- Pick(double,
- double,
- double,
- vtkRenderer*);
-};
-
-#ifdef WIN32
-#pragma warning ( default:4251 )
-#endif
-
-#endif
-
-
SVTK_RenderWindowInteractor
::mouseReleaseEvent( QMouseEvent *event )
{
+ SVTK_InteractorStyle* style = 0;
bool aRightBtn = event->button() == Qt::RightButton;
bool isOperation = false;
+ bool isPolygonalSelection = false;
if( aRightBtn && GetInteractorStyle()) {
- SVTK_InteractorStyle* style = dynamic_cast<SVTK_InteractorStyle*>( GetInteractorStyle() );
+ style = dynamic_cast<SVTK_InteractorStyle*>( GetInteractorStyle() );
if ( style )
isOperation = style->CurrentState() != VTK_INTERACTOR_STYLE_CAMERA_NONE;
}
QVTK_RenderWindowInteractor::mouseReleaseEvent(event);
- if ( aRightBtn && !isOperation && !( event->modifiers() & Qt::ControlModifier ) &&
+ if ( style ) {
+ isPolygonalSelection = style->GetPolygonState() == Finished;
+ style->SetPolygonState( Disable );
+ }
+
+ if ( aRightBtn && !isOperation && !isPolygonalSelection &&
+ !( event->modifiers() & Qt::ControlModifier ) &&
!( event->modifiers() & Qt::ShiftModifier ) ) {
QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
event->pos(), event->globalPos() );
SVTK_RenderWindowInteractor
::mouseDoubleClickEvent( QMouseEvent* event )
{
+ if( GetInteractorStyle() && event->button() == Qt::LeftButton ) {
+ SVTK_InteractorStyle* style = dynamic_cast<SVTK_InteractorStyle*>( GetInteractorStyle() );
+ if ( style )
+ style->OnMouseButtonDoubleClick();
+ }
+
QVTK_RenderWindowInteractor::mouseDoubleClickEvent(event);
if(GENERATE_SUIT_EVENTS)
#include "SVTK_Trihedron.h"
#include "SVTK_CubeAxesActor2D.h"
-#include "SVTK_RectPicker.h"
+#include "SVTK_AreaPicker.h"
#include "SALOME_Actor.h"
#include "VTKViewer_Actor.h"
myEventCallbackCommand(vtkCallbackCommand::New()),
myPointPicker(vtkPointPicker::New()),
myCellPicker(vtkCellPicker::New()),
- myPointRectPicker(SVTK_RectPicker::New()),
- myCellRectPicker(SVTK_RectPicker::New()),
+ myPointAreaPicker(SVTK_AreaPicker::New()),
+ myCellAreaPicker(SVTK_AreaPicker::New()),
myPreHighlightProperty(vtkProperty::New()),
myHighlightProperty(vtkProperty::New()),
myTransform(VTKViewer_Transform::New()),
myPointPicker->Delete();
myCellPicker->Delete();
- myPointRectPicker->Delete();
- myPointRectPicker->PickFromListOn();
+ myPointAreaPicker->Delete();
+ myPointAreaPicker->PickFromListOn();
- myCellRectPicker->Delete();
- myCellRectPicker->PickFromListOn();
- myCellRectPicker->PickPointsOff();
+ myCellAreaPicker->Delete();
+ myCellAreaPicker->PickFromListOn();
+ myCellAreaPicker->PickPointsOff();
//SetPreselectionProp();
myPreHighlightProperty->Delete();
anActor->SetPointPicker(myPointPicker.GetPointer());
anActor->SetCellPicker(myCellPicker.GetPointer());
- anActor->SetPointRectPicker(myPointRectPicker.GetPointer());
- anActor->SetCellRectPicker(myCellRectPicker.GetPointer());
+ anActor->SetPointAreaPicker(myPointAreaPicker.GetPointer());
+ anActor->SetCellAreaPicker(myCellAreaPicker.GetPointer());
anActor->SetPreHighlightProperty(myPreHighlightProperty.GetPointer());
anActor->SetHighlightProperty(myHighlightProperty.GetPointer());
anActor->SetPointPicker(NULL);
anActor->SetCellPicker(NULL);
- anActor->SetPointRectPicker(NULL);
- anActor->SetCellRectPicker(NULL);
+ anActor->SetPointAreaPicker(NULL);
+ anActor->SetCellAreaPicker(NULL);
anActor->SetPreHighlightProperty(NULL);
anActor->SetHighlightProperty(NULL);
myPointPicker->SetTolerance( theTolNodes );
myCellPicker->SetTolerance( theTolCell );
- myPointRectPicker->SetTolerance( theTolNodes );
- myCellRectPicker->SetTolerance( theTolCell );
+ myPointAreaPicker->SetTolerance( theTolNodes );
+ myCellAreaPicker->SetTolerance( theTolCell );
mySelector->SetTolerance( theTolObjects );
}
class vtkCellPicker;
class vtkProperty;
-class SVTK_RectPicker;
+class SVTK_AreaPicker;
class VTKViewer_Trihedron;
class VTKViewer_Transform;
vtkSmartPointer<vtkPointPicker> myPointPicker;
vtkSmartPointer<vtkCellPicker> myCellPicker;
- vtkSmartPointer<SVTK_RectPicker> myPointRectPicker;
- vtkSmartPointer<SVTK_RectPicker> myCellRectPicker;
+ vtkSmartPointer<SVTK_AreaPicker> myPointAreaPicker;
+ vtkSmartPointer<SVTK_AreaPicker> myCellAreaPicker;
vtkSmartPointer<vtkProperty> myPreHighlightProperty;
vtkSmartPointer<vtkProperty> myHighlightProperty;
#define SVTK_SELECTIONEVENT_H
#include "SVTK_Selection.h"
+#include <QPoint>
+#include <QVector>
//! The structure is used for passing all infromation necessary for claculation of the selection.
/*!
int myLastX; //!< Last X position of the mouse before starting any complex operation (like rectangle selection)
int myLastY; //!< Last Y position of the mouse before starting any complex operation
bool myIsRectangle; //!< A flag to define is it necessary provide rectangle selection for current #Selection_Mode
+ bool myIsPolygon; //!< A flag to define is it necessary provide polygonal selection for current #Selection_Mode
+ QVector<QPoint> myPolygonPoints; //!< Vector of points for polygonal selection
bool myIsCtrl; //!< Is Ctrl key are pressed
bool myIsShift; //!< Is Shift key are pressed
int myKeyCode; //!< Code of the pressed key
case FaceSelection:
case VolumeSelection:
{
- vtkSmartPointer<VTKViewer_CellRectPicker> picker = VTKViewer_CellRectPicker::New();
+ vtkSmartPointer<VTKViewer_CellAreaPicker> picker = VTKViewer_CellRectPicker::New();
picker->SetTolerance(0.001);
picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
break;
case ActorSelection: // objects selection
{
- vtkSmartPointer<VTKViewer_RectPicker> picker = VTKViewer_RectPicker::New();
+ vtkSmartPointer<VTKViewer_AreaPicker> picker = VTKViewer_AreaPicker::New();
picker->SetTolerance(0.001);
picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);