From 9f1a66957ba9a2308f8fdc3f9397140af9df5fd0 Mon Sep 17 00:00:00 2001 From: smh Date: Tue, 7 Feb 2006 14:14:31 +0000 Subject: [PATCH] Merge from OCC_development_generic_2006 Preparation of 3.2.0a1 --- doc/salome/tui/SUIT/doxyfile | 12 +- src/CAF/CAF_Tools.cxx | 45 +- src/CAF/CAF_Tools.h | 11 + src/CAM/CAM_Application.cxx | 39 +- src/DDS/DDS_DicItem.cxx | 15 + src/DDS/DDS_DicItem.h | 5 + src/GLViewer/GLViewer_Drawer.cxx | 476 ++++-- src/GLViewer/GLViewer_Drawer.h | 79 +- src/GLViewer/GLViewer_Object.cxx | 3 + src/GLViewer/GLViewer_Object.h | 2 +- src/GLViewer/GLViewer_ViewPort.cxx | 2 +- src/GLViewer/GLViewer_Viewer2d.cxx | 2 + src/GLViewer/GLViewer_Viewer2d.h | 5 + src/LightApp/LightApp_Application.cxx | 2 + src/LightApp/LightApp_Driver.cxx | 34 +- src/LightApp/LightApp_Driver.h | 16 +- src/LightApp/LightApp_Module.cxx | 29 +- src/LightApp/LightApp_OBSelector.cxx | 19 +- src/LightApp/LightApp_OBSelector.h | 7 + src/LightApp/LightApp_PreferencesDlg.cxx | 32 +- src/LightApp/LightApp_PreferencesDlg.h | 1 + src/LightApp/LightApp_Study.cxx | 32 +- src/LightApp/LightApp_VTKSelector.cxx | 25 +- src/LightApp/LightApp_VTKSelector.h | 8 +- src/LightApp/Makefile.in | 8 +- src/LightApp/resources/LightApp_msg_en.po | 9 + src/OBJECT/Makefile.in | 2 - src/OBJECT/SALOME_Actor.cxx | 308 ---- src/OBJECT/SALOME_Actor.h | 187 --- src/ObjBrowser/OB_Browser.cxx | 271 +++- src/ObjBrowser/OB_Browser.h | 14 +- src/ObjBrowser/OB_ListItem.cxx | 65 +- src/ObjBrowser/OB_ListItem.h | 6 +- src/Plot2d/Plot2d_ViewFrame.cxx | 22 +- src/Plot2d/resources/Plot2d_msg_en.po | 9 + src/QDS/QDS_CheckBox.cxx | 30 +- src/QDS/QDS_CheckBox.h | 3 + src/QDS/QDS_ComboBox.cxx | 12 + src/QDS/QDS_Datum.cxx | 38 +- src/QDS/QDS_Datum.h | 10 +- src/QDS/QDS_LineEdit.h | 2 +- src/QDS/QDS_RadioBox.cxx | 379 +++++ src/QDS/QDS_RadioBox.h | 75 + src/QDS/QDS_SpinBox.cxx | 19 +- src/QDS/QDS_SpinBox.h | 4 +- src/QDS/QDS_SpinBoxDbl.cxx | 14 +- src/Qtx/Makefile.in | 9 +- src/Qtx/QtxActionMenuMgr.cxx | 2 +- src/Qtx/QtxActionMgr.h | 4 +- src/Qtx/QtxDblSpinBox.cxx | 8 +- src/Qtx/QtxDblValidator.cxx | 47 + src/Qtx/QtxDblValidator.h | 39 + src/Qtx/QtxDialog.cxx | 18 +- src/Qtx/QtxListResourceEdit.cxx | 2 + src/Qtx/QtxMRUAction.h | 6 +- src/Qtx/QtxResourceEdit.cxx | 7 +- src/Qtx/QtxResourceMgr.cxx | 76 +- src/Qtx/QtxResourceMgr.h | 16 +- src/Qtx/QtxToolTip.cxx | 2 +- src/SALOME_PY/SalomePy.cxx | 6 +- src/STD/STD_Application.cxx | 22 +- src/SUIT/Makefile.in | 3 +- src/SUIT/SUIT_Application.cxx | 21 +- src/SUIT/SUIT_Application.h | 4 +- src/SUIT/SUIT_DataOwner.h | 2 + src/SUIT/SUIT_FileDlg.cxx | 16 + src/SUIT/SUIT_FileDlg.h | 3 + src/SUIT/SUIT_Operation.cxx | 2 +- src/SUIT/SUIT_Operation.h | 18 +- src/SUIT/SUIT_TreeSync.h | 177 +++ src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx | 1 + src/SUPERVGraph/SUPERVGraph_ViewModel.h | 1 + src/SVTK/Makefile.in | 115 +- src/SVTK/SALOME_Actor.cxx | 743 ++++++++++ src/SVTK/SALOME_Actor.h | 228 +++ src/SVTK/SVTK.cxx | 60 + src/SVTK/SVTK_Actor.cxx | 193 ++- src/SVTK/SVTK_Actor.h | 59 +- src/SVTK/SVTK_CubeAxesDlg.cxx | 572 +++++++ src/SVTK/SVTK_CubeAxesDlg.h | 144 ++ src/SVTK/SVTK_DeviceActor.cxx | 419 ++++++ src/SVTK/SVTK_DeviceActor.h | 209 +++ src/SVTK/SVTK_Event.h | 68 + src/SVTK/SVTK_FontWidget.cxx | 149 ++ src/SVTK/SVTK_FontWidget.h | 68 + src/SVTK/SVTK_Functor.h | 29 +- .../SVTK_GenericRenderWindowInteractor.cxx | 138 ++ src/SVTK/SVTK_GenericRenderWindowInteractor.h | 126 ++ src/SVTK/SVTK_InteractorStyle.cxx | 1310 ++++++++--------- src/SVTK/SVTK_InteractorStyle.h | 299 ++-- src/SVTK/SVTK_MainWindow.cxx | 701 +++++++++ src/SVTK/SVTK_MainWindow.h | 238 +++ src/SVTK/SVTK_NonIsometricDlg.cxx | 200 +++ src/SVTK/SVTK_NonIsometricDlg.h | 73 + src/SVTK/SVTK_RectPicker.cxx | 489 ++++++ src/SVTK/SVTK_RectPicker.h | 112 ++ src/SVTK/SVTK_RenderWindow.cxx | 179 --- src/SVTK/SVTK_RenderWindow.h | 83 -- src/SVTK/SVTK_RenderWindowInteractor.cxx | 1119 +++++--------- src/SVTK/SVTK_RenderWindowInteractor.h | 437 +++--- src/SVTK/SVTK_Renderer.cxx | 655 +++++++++ src/SVTK/SVTK_Renderer.h | 245 +++ src/SVTK/SVTK_Selection.h | 20 +- src/SVTK/SVTK_SelectionEvent.h | 55 + src/SVTK/SVTK_Selector.cxx | 99 +- src/SVTK/SVTK_Selector.h | 89 +- src/SVTK/SVTK_SelectorDef.h | 43 +- src/SVTK/SVTK_SpaceMouse.cxx | 196 +++ src/SVTK/SVTK_SpaceMouse.h | 75 + src/SVTK/SVTK_View.cxx | 546 +++++++ src/SVTK/SVTK_View.h | 248 ++++ src/SVTK/SVTK_ViewManager.h | 4 + src/SVTK/SVTK_ViewModel.cxx | 231 ++- src/SVTK/SVTK_ViewModel.h | 75 +- src/SVTK/SVTK_ViewModelBase.h | 27 + src/SVTK/SVTK_ViewWindow.cxx | 949 +++--------- src/SVTK/SVTK_ViewWindow.h | 392 +++-- src/SalomeApp/SalomeApp_Application.cxx | 21 +- src/SalomeApp/SalomeApp_DataModel.cxx | 279 +++- src/SalomeApp/SalomeApp_DataModel.h | 11 +- src/SalomeApp/SalomeApp_DataObject.cxx | 4 +- src/SalomeApp/SalomeApp_Study.cxx | 23 +- src/SalomeApp/resources/SalomeApp.xml | 74 +- src/Style/SalomeStyle.cxx | 78 +- src/VTKViewer/Makefile.in | 37 +- src/VTKViewer/VTKViewer.cxx | 57 + src/VTKViewer/VTKViewer_Actor.cxx | 521 ++++--- src/VTKViewer/VTKViewer_Actor.h | 389 +++-- src/VTKViewer/VTKViewer_AppendFilter.cxx | 363 +++++ src/VTKViewer/VTKViewer_AppendFilter.h | 91 ++ src/VTKViewer/VTKViewer_ConvexTool.cxx | 306 +++- src/VTKViewer/VTKViewer_ConvexTool.h | 2 + src/VTKViewer/VTKViewer_GeometryFilter.cxx | 1031 +++++++++---- src/VTKViewer/VTKViewer_GeometryFilter.h | 13 +- src/VTKViewer/VTKViewer_InteractorStyle.cxx | 1 + .../VTKViewer_RenderWindowInteractor.cxx | 1 + src/VTKViewer/resources/VTKViewerM_images.po | 40 + src/VTKViewer/resources/VTKViewerM_msg_en.po | 109 ++ .../resources/view_graduated_axes.png | Bin 0 -> 351 bytes src/VTKViewer/resources/view_scaling.png | Bin 0 -> 453 bytes 140 files changed, 13998 insertions(+), 4862 deletions(-) delete mode 100755 src/OBJECT/SALOME_Actor.cxx delete mode 100755 src/OBJECT/SALOME_Actor.h create mode 100644 src/QDS/QDS_RadioBox.cxx create mode 100644 src/QDS/QDS_RadioBox.h create mode 100644 src/Qtx/QtxDblValidator.cxx create mode 100644 src/Qtx/QtxDblValidator.h create mode 100644 src/SUIT/SUIT_TreeSync.h create mode 100644 src/SVTK/SALOME_Actor.cxx create mode 100644 src/SVTK/SALOME_Actor.h create mode 100644 src/SVTK/SVTK.cxx create mode 100644 src/SVTK/SVTK_CubeAxesDlg.cxx create mode 100644 src/SVTK/SVTK_CubeAxesDlg.h create mode 100644 src/SVTK/SVTK_DeviceActor.cxx create mode 100644 src/SVTK/SVTK_DeviceActor.h create mode 100644 src/SVTK/SVTK_Event.h create mode 100644 src/SVTK/SVTK_FontWidget.cxx create mode 100644 src/SVTK/SVTK_FontWidget.h create mode 100644 src/SVTK/SVTK_GenericRenderWindowInteractor.cxx create mode 100644 src/SVTK/SVTK_GenericRenderWindowInteractor.h create mode 100644 src/SVTK/SVTK_MainWindow.cxx create mode 100644 src/SVTK/SVTK_MainWindow.h create mode 100644 src/SVTK/SVTK_NonIsometricDlg.cxx create mode 100644 src/SVTK/SVTK_NonIsometricDlg.h create mode 100644 src/SVTK/SVTK_RectPicker.cxx create mode 100644 src/SVTK/SVTK_RectPicker.h delete mode 100644 src/SVTK/SVTK_RenderWindow.cxx delete mode 100644 src/SVTK/SVTK_RenderWindow.h create mode 100644 src/SVTK/SVTK_Renderer.cxx create mode 100644 src/SVTK/SVTK_Renderer.h create mode 100644 src/SVTK/SVTK_SelectionEvent.h create mode 100644 src/SVTK/SVTK_SpaceMouse.cxx create mode 100644 src/SVTK/SVTK_SpaceMouse.h create mode 100644 src/SVTK/SVTK_View.cxx create mode 100644 src/SVTK/SVTK_View.h create mode 100644 src/SVTK/SVTK_ViewModelBase.h create mode 100644 src/VTKViewer/VTKViewer.cxx create mode 100644 src/VTKViewer/VTKViewer_AppendFilter.cxx create mode 100644 src/VTKViewer/VTKViewer_AppendFilter.h create mode 100644 src/VTKViewer/resources/VTKViewerM_images.po create mode 100644 src/VTKViewer/resources/VTKViewerM_msg_en.po create mode 100755 src/VTKViewer/resources/view_graduated_axes.png create mode 100644 src/VTKViewer/resources/view_scaling.png diff --git a/doc/salome/tui/SUIT/doxyfile b/doc/salome/tui/SUIT/doxyfile index 7d82b803d..87b647b83 100755 --- a/doc/salome/tui/SUIT/doxyfile +++ b/doc/salome/tui/SUIT/doxyfile @@ -10,10 +10,10 @@ CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English USE_WINDOWS_ENCODING = NO BRIEF_MEMBER_DESC = YES -REPEAT_BRIEF = NO +REPEAT_BRIEF = YES ABBREVIATE_BRIEF = -ALWAYS_DETAILED_SEC = YES -INLINE_INHERITED_MEMB = YES +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO FULL_PATH_NAMES = NO STRIP_FROM_PATH = STRIP_FROM_INC_PATH = @@ -21,7 +21,7 @@ SHORT_NAMES = NO JAVADOC_AUTOBRIEF = YES MULTILINE_CPP_IS_BRIEF = NO DETAILS_AT_TOP = NO -INHERIT_DOCS = YES +INHERIT_DOCS = NO DISTRIBUTE_GROUP_DOC = NO TAB_SIZE = 5 ALIASES = @@ -37,8 +37,8 @@ EXTRACT_PRIVATE = YES EXTRACT_STATIC = YES EXTRACT_LOCAL_CLASSES = YES EXTRACT_LOCAL_METHODS = NO -HIDE_UNDOC_MEMBERS = NO -HIDE_UNDOC_CLASSES = NO +HIDE_UNDOC_MEMBERS = YES +HIDE_UNDOC_CLASSES = YES HIDE_FRIEND_COMPOUNDS = NO HIDE_IN_BODY_DOCS = NO INTERNAL_DOCS = YES diff --git a/src/CAF/CAF_Tools.cxx b/src/CAF/CAF_Tools.cxx index 41b56f6e1..c32d4a27e 100755 --- a/src/CAF/CAF_Tools.cxx +++ b/src/CAF/CAF_Tools.cxx @@ -29,7 +29,26 @@ */ QString CAF_Tools::toQString ( const TCollection_ExtendedString& src ) { - return QString( (const QChar*)src.ToExtString(), src.Length() ); + return QString( (const QChar*)src.ToExtString(), src.Length() ); +} + +/*! + Converts TCollection_AsciiString'src' to Qt string. [ static ] +*/ +QString CAF_Tools::toQString( const TCollection_AsciiString& src ) +{ + return QString( src.ToCString() ); +} + +/*! + Converts Qt string to TCollection_AsciiString. [ static ] +*/ +TCollection_AsciiString CAF_Tools::toAsciiString( const QString& src ) +{ + TCollection_AsciiString res; + if ( !src.isEmpty() ) + res = TCollection_AsciiString( (char*)src.latin1() ); + return res; } /*! @@ -37,8 +56,24 @@ QString CAF_Tools::toQString ( const TCollection_ExtendedString& src ) */ TCollection_ExtendedString CAF_Tools::toExtString ( const QString& src ) { - TCollection_ExtendedString result; - for ( int i = 0; i < (int)src.length(); i++ ) - result.Insert( i + 1, src[ i ].unicode() ); - return result; + TCollection_ExtendedString result; + for ( int i = 0; i < (int)src.length(); i++ ) + result.Insert( i + 1, src[ i ].unicode() ); + return result; +} + +Quantity_Color CAF_Tools::color( const QColor& c ) +{ + Quantity_Color aColor; + if ( c.isValid() ) + aColor = Quantity_Color( c.red() / 255., c.green() / 255., + c.blue() / 255., Quantity_TOC_RGB ); + return aColor; +} + +QColor CAF_Tools::color( const Quantity_Color& c ) +{ + return QColor ( int( c.Red() * 255 ), + int( c.Green() * 255 ), + int( c.Blue() * 255 ) ); } diff --git a/src/CAF/CAF_Tools.h b/src/CAF/CAF_Tools.h index 8af84f9fe..e04d1c9d8 100755 --- a/src/CAF/CAF_Tools.h +++ b/src/CAF/CAF_Tools.h @@ -26,13 +26,24 @@ #include +#include + +#include + +#include #include class CAF_EXPORT CAF_Tools : public SUIT_Tools { public: + static QString toQString( const TCollection_AsciiString& ); static QString toQString( const TCollection_ExtendedString& ); + static TCollection_ExtendedString toExtString( const QString& ); + static TCollection_AsciiString toAsciiString( const QString& ); + + static Quantity_Color color( const QColor& ); + static QColor color( const Quantity_Color& ); }; #endif diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index eb7060abd..ef7cd09e4 100755 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef WIN32 #include @@ -428,31 +429,23 @@ void CAM_Application::readModuleList() QStringList modList; - // parse command line arguments - int nbArgs = qApp->argc(); - char** CmdLine = qApp->argv(); - QString CmdStr; - for ( int i = 0; i < nbArgs; i++ ) - { - CmdStr.append(CmdLine[i]); - CmdStr.append(" "); - } - int startId = CmdStr.find("--modules ("); - if ( startId != -1 ) { // application launch with --modules option - startId = CmdStr.find("(", startId); - int stopId = CmdStr.find(" )", startId); - QString ModStr = CmdStr.mid( startId+1, stopId - (startId+1) ).stripWhiteSpace(); - int i = 0; - while ( i < ModStr.length() ) - { - int nextId = ModStr.find( ":", i ); - modList.append( ModStr.mid( i, nextId - i ).stripWhiteSpace() ); - i = nextId + 1; + QStringList args; + for (int i = 1; i < qApp->argc(); i++) + args.append( qApp->argv()[i] ); + + QRegExp rx("--modules\\s+\\(\\s*(.*)\\s*\\)"); + rx.setMinimal( true ); + if ( rx.search( args.join(" ") ) >= 0 && rx.capturedTexts().count() > 0 ) { + QString modules = rx.capturedTexts()[1]; + QStringList mods = QStringList::split(":",modules,false); + for ( uint i = 0; i < mods.count(); i++ ) { + if ( !mods[i].stripWhiteSpace().isEmpty() ) + modList.append( mods[i].stripWhiteSpace() ); } } - else { - QString modStr = resMgr->stringValue( "launch", "modules", QString::null ); - modList = QStringList::split( ",", modStr ); + if ( modList.isEmpty() ) { + QString mods = resMgr->stringValue( "launch", "modules", QString::null ); + modList = QStringList::split( ",", mods ); } for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it ) diff --git a/src/DDS/DDS_DicItem.cxx b/src/DDS/DDS_DicItem.cxx index fd59f3cd6..0c8b01c6d 100644 --- a/src/DDS/DDS_DicItem.cxx +++ b/src/DDS/DDS_DicItem.cxx @@ -305,6 +305,14 @@ Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal, const UnitSystem& return aRes; } +/*! + Returns 'true' if specified data exist. +*/ +Standard_Boolean DDS_DicItem::HasData( const Standard_Integer flag ) const +{ + return ( myData & flag ) == flag; +} + /*! Parse record in XML file and retrieve information relevant for this data dic item */ @@ -436,15 +444,22 @@ void DDS_DicItem::FillDataMap( TCollection_AsciiString theID, const LDOM_Element else if ( aType.IsEqual( "Integer" ) ) aEnumType = Integer; + if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MINV" ) ).isNull() ) + myData |= MinValue; aMinV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MINV" ) ); aMinV.RemoveAll( ' ' ); if ( aMinV.IsRealValue() ) aRealMinV = aMinV.RealValue(); + if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MAXV" ) ).isNull() ) + myData |= MaxValue; aMaxV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MAXV" ) ); aMaxV.RemoveAll( ' ' ); if ( aMaxV.IsRealValue() ) aRealMaxV = aMaxV.RealValue(); aDefV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) ); + if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_DEFV" ) ).isNull() ) + myData |= DefaultValue; + aDefV.RemoveAll( ' ' ); if ( aDefV.IsRealValue() ) aRealDefV = aDefV.RealValue(); diff --git a/src/DDS/DDS_DicItem.h b/src/DDS/DDS_DicItem.h index 871149407..dbbedc0a7 100644 --- a/src/DDS/DDS_DicItem.h +++ b/src/DDS/DDS_DicItem.h @@ -30,6 +30,7 @@ class DDS_DicItem : public MMgt_TShared { public: enum Type { String, Float, Integer, List, Unknown }; + enum Data { MinValue = 0x01, MaxValue = 0x02, DefaultValue = 0x04 }; // This struct is intended for map of Format, Units, Precision and Scale struct UnitData @@ -134,6 +135,8 @@ public: Standard_EXPORT Standard_Real FromSI( const Standard_Real, const UnitSystem& ) const; // convert value to and from default SI units according to current units + Standard_EXPORT Standard_Boolean HasData( const Standard_Integer ) const; + private: DDS_DicItem( const DDS_DicItem& ); // Copy constructor @@ -200,6 +203,8 @@ private: Standard_Real myDefValue; TCollection_ExtendedString myDefString; + Standard_Integer myData; + // valueList TCollection_ExtendedString myListName; diff --git a/src/GLViewer/GLViewer_Drawer.cxx b/src/GLViewer/GLViewer_Drawer.cxx index 841fb6b84..9a0f3ef6b 100644 --- a/src/GLViewer/GLViewer_Drawer.cxx +++ b/src/GLViewer/GLViewer_Drawer.cxx @@ -33,19 +33,20 @@ #include #endif +#include + #include #include #define TEXT_GAP 5 +// Two texture components for texmapped fonts: luminance and alpha +#define NB_TEX_COMP 2 +// A font is split into rows each containing 32 characters +#define TEX_ROW_LEN 32 +// Gap in pixels between two character rows in a font texture +#define TEX_ROW_GAP 2 -GLboolean TFLoaded = GL_FALSE; - -GLdouble modelMatrix[16], projMatrix[16]; -GLint viewport[4]; -GLdouble winx, winy, winz; -GLint status; - -GLViewer_TexFont* staticGlFont; +GLfloat modelMatrix[16]; //================================================================ // Class : GLViewer_TexFont @@ -75,24 +76,14 @@ void GLViewer_TexFont::clearTextBases() // Purpose : //======================================================================= GLViewer_TexFont::GLViewer_TexFont() +: myMaxRowWidth( 0 ), myFontHeight( 0 ) { myQFont = QFont::defaultFont(); - QFontMetrics aFM( myQFont ); - myWidths = new int[LastSymbolNumber - FirstSymbolNumber+1]; - myPositions = new int[LastSymbolNumber - FirstSymbolNumber+1]; mySeparator = 2; - for( int k = FirstSymbolNumber, aWidth = 0; k <= LastSymbolNumber; k++ ) - { - myWidths[ k - FirstSymbolNumber ] = aFM.width( k ); - myPositions[ k - FirstSymbolNumber ] = aWidth; - aWidth += myWidths[ k - FirstSymbolNumber ] + 2;//mySeparator; - } - - myTexFontWidth = 0; - myTexFontHeight = 0; myIsResizeable = false; - //myMinMagFilter = GL_NEAREST; - myMinMagFilter = GL_LINEAR_ATTENUATION ; + myMinMagFilter = GL_LINEAR; + + init(); } //====================================================================== @@ -100,24 +91,14 @@ GLViewer_TexFont::GLViewer_TexFont() // Purpose : //======================================================================= GLViewer_TexFont::GLViewer_TexFont( QFont* theFont, int theSeparator, bool theIsResizeable, GLuint theMinMagFilter ) +: myMaxRowWidth( 0 ), myFontHeight( 0 ) { myQFont = *theFont; - QFontMetrics aFM( myQFont ); - myWidths = new int[LastSymbolNumber - FirstSymbolNumber+1]; - myPositions = new int[LastSymbolNumber - FirstSymbolNumber+1]; mySeparator = theSeparator; - for( int k = FirstSymbolNumber, aWidth = 0; k <= LastSymbolNumber; k++ ) - { - myWidths[ k - FirstSymbolNumber ] = aFM.width( k ); - myPositions[ k - FirstSymbolNumber ] = aWidth; - aWidth += myWidths[ k - FirstSymbolNumber ] + 2;//mySeparator; - } - - myTexFontWidth = 0; - myTexFontHeight = 0; myIsResizeable = theIsResizeable; myMinMagFilter = theMinMagFilter; - + + init(); } //====================================================================== @@ -129,17 +110,56 @@ GLViewer_TexFont::~GLViewer_TexFont() delete[] myWidths; delete[] myPositions; } + +//====================================================================== +// Function: init +// Purpose : +//======================================================================= +void GLViewer_TexFont::init() +{ + myNbSymbols = LastSymbolNumber - FirstSymbolNumber + 1; + + // It is unsafe to draw all characters in a single row - + // this leads to problems on some graphic cards with small GL_MAX_TEXTURE_SIZE. + // So splitting the characters into rows each containing 32 characters (or less). + // Assuming contant height of each row (64 pixels) to simplify texture mapping. + // However, this can be improved if necessary. + QFontMetrics aFM( myQFont ); + myFontHeight = aFM.height(); + + myWidths = new int[myNbSymbols]; + myPositions = new int[myNbSymbols]; + + for( int i = 0, k = FirstSymbolNumber, aWidth = 0; i < myNbSymbols; i++, k++ ) + { + // is it time to start a new row? + if ( !( i % TEX_ROW_LEN ) ) + { + if( aWidth > myMaxRowWidth ) + myMaxRowWidth = aWidth; + aWidth = 0; + } + myWidths[i] = aFM.width( k ); + myPositions[i] = aWidth; + aWidth += myWidths[i] + 2; + } + + myTexFontWidth = 0; + myTexFontHeight = 0; +} //====================================================================== // Function: generateTexture // Purpose : //======================================================================= -void GLViewer_TexFont::generateTexture() +bool GLViewer_TexFont::generateTexture() { - QFontMetrics aFM( myQFont ); - GLViewer_TexFindId aFindFont; - aFindFont.myFontString = myQFont.toString(); + aFindFont.myFontFamily = myQFont.family();//myQFont.toString(); + aFindFont.myIsBold = myQFont.bold(); + aFindFont.myIsItal = myQFont.italic(); + aFindFont.myIsUndl = myQFont.underline(); + aFindFont.myPointSize = myQFont.pointSize(); aFindFont.myViewPortId = (int)QGLContext::currentContext(); if( TexFontBase.contains( aFindFont ) ) @@ -151,34 +171,51 @@ void GLViewer_TexFont::generateTexture() } else { - QString aStr; - int pixelsWidth = 0; - int pixelsHight = aFM.height(); - myTexFontWidth = 64; + // Adding some pixels to have a gap between rows + int aRowPixelHeight = myFontHeight + TEX_ROW_GAP; + int aDescent = QFontMetrics( myQFont ).descent(); + + int aNumRows = myNbSymbols / TEX_ROW_LEN; + if ( myNbSymbols % TEX_ROW_LEN ) + aNumRows++; + int pixelsHight = aNumRows * aRowPixelHeight; + + myTexFontWidth = 64; myTexFontHeight = 64; - - pixelsWidth = myWidths[LastSymbolNumber - FirstSymbolNumber] + - myPositions[LastSymbolNumber - FirstSymbolNumber]; - while( myTexFontWidth < pixelsWidth ) - myTexFontWidth = myTexFontWidth * 2; + while( myTexFontWidth < myMaxRowWidth ) + myTexFontWidth <<= 1; while( myTexFontHeight < pixelsHight ) - myTexFontHeight = myTexFontHeight * 2; + myTexFontHeight <<= 1; + + // Checking whether the texture dimensions for the requested font + // do not exceed the maximum size supported by the OpenGL implementation + int maxSize; + glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxSize ); + if ( myTexFontWidth > maxSize || myTexFontHeight > maxSize ) + return false; QPixmap aPixmap( myTexFontWidth, myTexFontHeight ); aPixmap.fill( QColor( 0, 0, 0) ); QPainter aPainter( &aPixmap ); aPainter.setFont( myQFont ); - for( int l = 0/*, gap = 0*/; l < LastSymbolNumber - FirstSymbolNumber; l++ ) + int row; + for( int l = 0; l < myNbSymbols; l++ ) { + row = l / TEX_ROW_LEN; QString aLetter; aLetter += (char)(FirstSymbolNumber + l); aPainter.setPen( QColor( 255,255,255) ); - aPainter.drawText ( myPositions[l], pixelsHight, aLetter ); + aPainter.drawText( myPositions[l], ( row + 1 ) * aRowPixelHeight - aDescent, aLetter ); } QImage aImage = aPixmap.convertToImage(); - char* pixels = new char[myTexFontWidth * myTexFontHeight * 2]; + + //int qqq = 0; + //if (qqq) + // aImage.save("w:\\work\\CATHARE\\texture.png", "PNG"); + + char* pixels = new char[myTexFontWidth * myTexFontHeight * NB_TEX_COMP]; for( int i = 0; i < myTexFontHeight; i++ ) { @@ -190,13 +227,13 @@ void GLViewer_TexFont::generateTexture() if( aRed != 0 || aGreen != 0 || aBlue != 0 ) { - pixels[i * myTexFontWidth * 2 + j * 2] = (GLubyte)( (aRed + aGreen + aBlue)/3 ); - pixels[i * myTexFontWidth * 2 + j * 2 + 1]= (GLubyte) 255; + pixels[i * myTexFontWidth * NB_TEX_COMP + j * NB_TEX_COMP] = (GLubyte)( (aRed + aGreen + aBlue)/3 ); + pixels[i * myTexFontWidth * NB_TEX_COMP + j * NB_TEX_COMP + 1]= (GLubyte) 255; } else { - pixels[i * myTexFontWidth * 2 + j * 2] = (GLubyte) 0; - pixels[i * myTexFontWidth * 2 + j * 2 + 1]= (GLubyte) 0; + pixels[i * myTexFontWidth * NB_TEX_COMP + j * NB_TEX_COMP] = (GLubyte) 0; + pixels[i * myTexFontWidth * NB_TEX_COMP + j * NB_TEX_COMP + 1]= (GLubyte) 0; } } } @@ -204,11 +241,8 @@ void GLViewer_TexFont::generateTexture() glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &myTexFont); glBindTexture(GL_TEXTURE_2D, myTexFont); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, myMinMagFilter); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, myMinMagFilter); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY, @@ -228,33 +262,35 @@ void GLViewer_TexFont::generateTexture() TexFontBase.insert( aFindFont, aTexture ); } + return true; } //====================================================================== // Function: drawString // Purpose : //======================================================================= -void GLViewer_TexFont::drawString( QString theStr, GLdouble theX , GLdouble theY ) +void GLViewer_TexFont::drawString( QString theStr, GLdouble theX , GLdouble theY, GLfloat theScale ) { - double aXScale = 1., aYScale = 1.; - // store attributes - glPushAttrib( GL_ENABLE_BIT | GL_TEXTURE_BIT ); + // Adding some pixels to have a gap between rows + int aRowPixelHeight = myFontHeight + TEX_ROW_GAP; + float aXScale = 1.f, aYScale = 1.f; if ( !myIsResizeable ) { - glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix); + glGetFloatv (GL_MODELVIEW_MATRIX, modelMatrix); aXScale = modelMatrix[0]; - aYScale = modelMatrix[5]; + aYScale = modelMatrix[5]; + } + else if ( theScale > 0.f ) + { + aXScale = aXScale / theScale; + aYScale = aYScale / theScale; } - glEnable(GL_TEXTURE_2D); - - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, myMinMagFilter); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, myMinMagFilter); + // store attributes + glPushAttrib( GL_ENABLE_BIT | GL_TEXTURE_BIT ); + glEnable(GL_TEXTURE_2D); glPixelTransferi(GL_MAP_COLOR, 0); glAlphaFunc(GL_GEQUAL, 0.05F); @@ -264,27 +300,31 @@ void GLViewer_TexFont::drawString( QString theStr, GLdouble theX , GLdouble theY glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glBindTexture(GL_TEXTURE_2D, myTexFont); - glBegin(GL_QUADS); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - theY = theY - ( myTexFontHeight - QFontMetrics( myQFont ).height() ) / aYScale; + glBegin(GL_QUADS); - double aLettBegin, aLettEnd, aDY = ( myTexFontHeight - 1 ) / aYScale, aDX; + float aLettBeginS, aLettEndS, aLettBeginT, aLettEndT; + float aDY = ( aRowPixelHeight - 1 ) / aYScale, aDX; char aLetter; - int aLettIndex; + int aLettIndex, row; for( int i = 0; i < theStr.length(); i++ ) { aLetter = theStr.data()[i]; aLettIndex = (int)aLetter - FirstSymbolNumber; + row = aLettIndex / TEX_ROW_LEN; - aLettBegin = (double)myPositions[aLettIndex] / ( (double)myTexFontWidth - 1. ); - aLettEnd = aLettBegin + ( (double)myWidths[aLettIndex] - 1. ) / ( (double)myTexFontWidth - 1. ); + aLettBeginS = (float)myPositions[aLettIndex] / ( (float)myTexFontWidth - 1.f ); + aLettEndS = aLettBeginS + ( (float)myWidths[aLettIndex] - 1.f ) / ( (float)myTexFontWidth - 1.f ); + aLettBeginT = ( myTexFontHeight - ( row + 1 ) * aRowPixelHeight ) / ( (float)myTexFontHeight - 1.f ); + aLettEndT = aLettBeginT + ( (float)aRowPixelHeight - 1.f ) / ( (float)myTexFontHeight - 1.f ); - aDX = ( (double)myWidths[aLettIndex] - 1. ) / aXScale; + aDX = ( (float)myWidths[aLettIndex] - 1.f ) / aXScale; - glTexCoord2d( aLettBegin, 0.0 ); glVertex3d( theX, theY, 1.0 ); - glTexCoord2d( aLettBegin, 1.0 ); glVertex3d( theX, theY + aDY, 1.0 ); - glTexCoord2d( aLettEnd, 1.0 ); glVertex3d( theX + aDX, theY + aDY, 1.0 ); - glTexCoord2d( aLettEnd, 0.0 ); glVertex3d( theX + aDX, theY, 1.0 ); + glTexCoord2f( aLettBeginS, aLettBeginT ); glVertex3f( theX, theY, 1.f ); + glTexCoord2f( aLettBeginS, aLettEndT ); glVertex3f( theX, theY + aDY, 1.f ); + glTexCoord2f( aLettEndS, aLettEndT ); glVertex3f( theX + aDX, theY + aDY, 1.f ); + glTexCoord2f( aLettEndS, aLettBeginT ); glVertex3f( theX + aDX, theY, 1.f ); theX += aDX + mySeparator / aXScale; } @@ -324,10 +364,16 @@ int GLViewer_TexFont::getStringHeight() //! function for generation list base for bitmap fonts static GLuint displayListBase( QFont* theFont ) { + if ( !theFont ) + return 0; GLuint aList = 0; //static QMap fontCache; GLViewer_TexFindId aFindFont; - aFindFont.myFontString = theFont->toString(); + aFindFont.myFontFamily = theFont->family();//theFont->toString(); + aFindFont.myIsBold = theFont->bold(); + aFindFont.myIsItal = theFont->italic(); + aFindFont.myIsUndl = theFont->underline(); + aFindFont.myPointSize = theFont->pointSize(); #ifdef WIN32 HGLRC ctx = ::wglGetCurrentContext(); @@ -392,16 +438,17 @@ static GLuint displayListBase( QFont* theFont ) //glXUseXFont( (Font)(theFont->handle()), 0, 256, listBase ); int aFontCont = 0; - char** xFontList = XListFonts( aDisp, aFindFont.myFontString.data(), 1, &aFontCont ); + QString aFontDef = theFont->toString(); + char** xFontList = XListFonts( aDisp, aFontDef.latin1()/*aFindFont.myFontString.data()*/, 1, &aFontCont ); if( !theFont->handle() ) { #ifdef _DEBUG_ - printf( "Can't load font %s. loading default font....\n", aFindFont.myFontString.data() ); + printf( "Can't load font %s. loading default font....\n", aFontDef.latin1()/*aFindFont.myFontString.data()*/ ); #endif QString aFontMask ("-*-*-*-r-*-*-"); - aFontMask += aFindFont.myFontString.section( ',', 1, 1 ); + aFontMask += aFontDef/*aFindFont.myFontString*/.section( ',', 1, 1 ); #ifdef _DEBUG_ - printf( "Height of Default font: %s\n", aFindFont.myFontString.section( ',', 1, 1 ).data() ); + printf( "Height of Default font: %s\n", aFontDef/*aFindFont.myFontString*/.section( ',', 1, 1 ).data() ); #endif aFontMask += "-*-*-*-m-*-*-*"; xFontList = XListFonts( aDisp, aFontMask.data()/*"-*-*-*-r-*-*-12-*-*-*-m-*-*-*"*/, 1, &aFontCont ); @@ -445,6 +492,7 @@ GLViewer_Drawer::GLViewer_Drawer() myObjectType = "GLViewer_Object"; myPriority = 0; myTextFormat = DTF_BITMAP; + myTextScale = 0.125; } //====================================================================== @@ -716,8 +764,14 @@ void GLViewer_Drawer::drawText( const QString& text, GLfloat xPos, GLfloat yPos, if( theFormat != DTF_BITMAP ) { GLViewer_TexFont aTexFont( theFont, theSeparator, theFormat == DTF_TEXTURE_SCALABLE, GL_LINEAR ); - aTexFont.generateTexture(); - aTexFont.drawString( text, xPos, yPos ); + // Font texture was not found or generated --> cannot draw text + if ( !aTexFont.generateTexture() ) + return; + + if ( theFormat == DTF_TEXTURE_SCALABLE ) + aTexFont.drawString( text, xPos, yPos, textScale() ); + else + aTexFont.drawString( text, xPos, yPos ); } else { @@ -758,9 +812,11 @@ void GLViewer_Drawer::drawGLText( QString text, float x, float y, if( smallFont ) aFont.setPointSize( aFont.pointSize() * 0.8 ); + GLfloat scale = textScale() > 0. ? textScale() : 1.; + QFontMetrics aFontMetrics( aFont ); - float width = myTextFormat == DTF_TEXTURE_SCALABLE ? aFontMetrics.width( text ) : aFontMetrics.width( text ) / myXScale; - float height = myTextFormat == DTF_TEXTURE_SCALABLE ? aFontMetrics.height() : aFontMetrics.height() / myYScale; + float width = myTextFormat == DTF_TEXTURE_SCALABLE ? aFontMetrics.width( text ) * scale : aFontMetrics.width( text ) / myXScale; + float height = myTextFormat == DTF_TEXTURE_SCALABLE ? aFontMetrics.height() * scale : aFontMetrics.height() / myYScale; float gap = 5 / myXScale; switch( hPosition ) @@ -782,6 +838,21 @@ void GLViewer_Drawer::drawGLText( QString text, float x, float y, drawText( text, x, y, color, &aFont, 2, myTextFormat ); } +//====================================================================== +// Function: textRect +// Purpose : +//======================================================================= +GLViewer_Rect GLViewer_Drawer::textRect( const QString& text ) const +{ + GLfloat scale = textScale() > 0. ? textScale() : 1.; + + QFontMetrics aFontMetrics( myFont ); + float width = myTextFormat == DTF_TEXTURE_SCALABLE ? aFontMetrics.width( text ) * scale : aFontMetrics.width( text ); + float height = myTextFormat == DTF_TEXTURE_SCALABLE ? aFontMetrics.height() * scale : aFontMetrics.height(); + + return GLViewer_Rect( 0, width, height, 0 ); +} + //====================================================================== // Function: drawRectangle // Purpose : @@ -846,3 +917,224 @@ bool GLViewer_Drawer::translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, return result; } #endif + +//====================================================================== +// Function: drawRectangle +// Purpose : +//======================================================================= +void GLViewer_Drawer::drawRectangle( GLViewer_Rect* rect, GLfloat lineWidth, GLfloat gap, + QColor color, bool filled, QColor fillingColor ) +{ + if( !rect ) + return; + + float x1 = rect->left() - gap; + float x2 = rect->right() + gap; + float y1 = rect->bottom() - gap; + float y2 = rect->top() + gap; + + if( filled ) + { + glColor3f( ( GLfloat )fillingColor.red() / 255, + ( GLfloat )fillingColor.green() / 255, + ( GLfloat )fillingColor.blue() / 255 ); + glBegin( GL_POLYGON ); + glVertex2f( x1, y1 ); + glVertex2f( x1, y2 ); + glVertex2f( x2, y2 ); + glVertex2f( x2, y1 ); + glEnd(); + } + + glColor3f( ( GLfloat )color.red() / 255, + ( GLfloat )color.green() / 255, + ( GLfloat )color.blue() / 255 ); + glLineWidth( lineWidth ); + + glBegin( GL_LINE_LOOP ); + glVertex2f( x1, y1 ); + glVertex2f( x1, y2 ); + glVertex2f( x2, y2 ); + glVertex2f( x2, y1 ); + glEnd(); +} + +//====================================================================== +// Function: drawContour +// Purpose : +//======================================================================= +void GLViewer_Drawer::drawContour( const GLViewer_PntList& pntList, QColor color, GLfloat lineWidth ) +{ + glColor3f( ( GLfloat )color.red() / 255, + ( GLfloat )color.green() / 255, + ( GLfloat )color.blue() / 255 ); + glLineWidth( lineWidth ); + + glBegin( GL_LINES ); + QValueList::const_iterator it = pntList.begin(); + for( ; it != pntList.end(); ++it ) + glVertex2f( (*it).x(), (*it).y() ); + glEnd(); +} + +//====================================================================== +// Function: drawContour +// Purpose : +//======================================================================= +void GLViewer_Drawer::drawContour( GLViewer_Rect* rect, QColor color, GLfloat lineWidth, + GLushort pattern, bool isStripe ) +{ + float x1 = rect->left(); + float x2 = rect->right(); + float y1 = rect->bottom(); + float y2 = rect->top(); + + glColor3f( ( GLfloat )color.red() / 255, + ( GLfloat )color.green() / 255, + ( GLfloat )color.blue() / 255 ); + glLineWidth( lineWidth ); + + if ( isStripe ) + { + glEnable( GL_LINE_STIPPLE ); + glLineStipple( 1, pattern ); + } + + glBegin( GL_LINE_LOOP ); + + glVertex2f( x1, y1 ); + glVertex2f( x1, y2 ); + glVertex2f( x2, y2 ); + glVertex2f( x2, y1 ); + + glEnd(); + glDisable( GL_LINE_STIPPLE ); +} + +//====================================================================== +// Function: drawPolygon +// Purpose : +//======================================================================= +void GLViewer_Drawer::drawPolygon( const GLViewer_PntList& pntList, QColor color ) +{ + glColor3f( ( GLfloat )color.red() / 255, + ( GLfloat )color.green() / 255, + ( GLfloat )color.blue() / 255 ); + glBegin( GL_POLYGON ); + QValueList::const_iterator it = pntList.begin(); + for( ; it != pntList.end(); ++it ) + glVertex2f( (*it).x(), (*it).y() ); + glEnd(); +} + +//====================================================================== +// Function: drawPolygon +// Purpose : +//======================================================================= +void GLViewer_Drawer::drawPolygon( GLViewer_Rect* rect, QColor color, + GLushort pattern, bool isStripe ) +{ + float x1 = rect->left(); + float x2 = rect->right(); + float y1 = rect->bottom(); + float y2 = rect->top(); + glColor3f( ( GLfloat )color.red() / 255, + ( GLfloat )color.green() / 255, + ( GLfloat )color.blue() / 255 ); + + if ( isStripe ) + { + glEnable( GL_LINE_STIPPLE ); + glLineStipple( 1, pattern ); + } + glBegin( GL_POLYGON ); + + glVertex2f( x1, y1 ); + glVertex2f( x1, y2 ); + glVertex2f( x2, y2 ); + glVertex2f( x2, y1 ); + + glEnd(); + glDisable( GL_LINE_STIPPLE ); +} + +//====================================================================== +// Function: drawVertex +// Purpose : +//======================================================================= +GLubyte rasterVertex[5] = { 0x70, 0xf8, 0xf8, 0xf8, 0x70 }; +void GLViewer_Drawer::drawVertex( GLfloat x, GLfloat y, QColor color ) +{ + glColor3f( ( GLfloat )color.red() / 255, ( GLfloat )color.green() / 255, ( GLfloat )color.blue() / 255 ); + glRasterPos2f( x, y ); + glBitmap( 5, 5, 2, 2, 0, 0, rasterVertex ); +} + +//====================================================================== +// Function: drawCross +// Purpose : +//======================================================================= +GLubyte rasterCross[7] = { 0x82, 0x44, 0x28, 0x10, 0x28, 0x44, 0x82 }; +void GLViewer_Drawer::drawCross( GLfloat x, GLfloat y, QColor color ) +{ + glColor3f( ( GLfloat )color.red() / 255, ( GLfloat )color.green() / 255, ( GLfloat )color.blue() / 255 ); + glRasterPos2f( x, y ); + glBitmap( 7, 7, 3, 3, 0, 0, rasterCross ); +} + +//====================================================================== +// Function: drawArrow +// Purpose : +//======================================================================= +void GLViewer_Drawer::drawArrow( const GLfloat red, const GLfloat green, const GLfloat blue, + GLfloat lineWidth, + GLfloat staff, GLfloat length, GLfloat width, + GLfloat x, GLfloat y, GLfloat angle, GLboolean filled ) +{ + GLfloat vx1 = x; + GLfloat vy1 = y + staff + length; + GLfloat vx2 = vx1 - width / 2; + GLfloat vy2 = vy1 - length; + GLfloat vx3 = vx1 + width / 2; + GLfloat vy3 = vy1 - length; + + gp_Pnt2d p0( x, y ); + gp_Pnt2d p1( vx1, vy1 ); + gp_Pnt2d p2( vx2, vy2 ); + gp_Pnt2d p3( vx3, vy3 ); + + p1.Rotate( p0, angle ); + p2.Rotate( p0, angle ); + p3.Rotate( p0, angle ); + + vx1 = p1.X(); vy1 = p1.Y(); + vx2 = p2.X(); vy2 = p2.Y(); + vx3 = p3.X(); vy3 = p3.Y(); + + glColor3f( red, green, blue ); + glLineWidth( lineWidth ); + + glBegin( GL_LINES ); + glVertex2f( x, y ); + glVertex2f( vx1, vy1 ); + glEnd(); + + filled = true; + if( !filled ) + { + glBegin( GL_LINES ); + glVertex2f( vx1, vy1 ); + glVertex2f( vx2, vy2 ); + glVertex2f( vx1, vy1 ); + glVertex2f( vx3, vy3 ); + glEnd(); + } + else + { + glBegin( GL_POLYGON ); + glVertex2f( vx1, vy1 ); + glVertex2f( vx2, vy2 ); + glVertex2f( vx3, vy3 ); + glEnd(); + } +} diff --git a/src/GLViewer/GLViewer_Drawer.h b/src/GLViewer/GLViewer_Drawer.h index 56bbdbbec..4b66e7b20 100644 --- a/src/GLViewer/GLViewer_Drawer.h +++ b/src/GLViewer/GLViewer_Drawer.h @@ -39,6 +39,7 @@ #include "GLViewer.h" #include "GLViewer_Defs.h" +#include "GLViewer_Geom.h" class GLViewer_Object; class GLViewer_Rect; @@ -67,15 +68,33 @@ struct GLVIEWER_API GLViewer_TexIdStored */ struct GLVIEWER_API GLViewer_TexFindId { - //! Font description - QString myFontString; + //! Font family description + QString myFontFamily; + //! Bold parameter + bool myIsBold; + //! Italic parameter + bool myIsItal; + //! Underline parameter + bool myIsUndl; + //! Font Size + int myPointSize; //! View POrt ID int myViewPortId; //! Overloaded operator for using struct as MAP key bool operator < (const GLViewer_TexFindId theStruct) const { - if ( myViewPortId != theStruct.myViewPortId ) return myViewPortId < theStruct.myViewPortId; - else return myFontString < theStruct.myFontString; + if ( myViewPortId != theStruct.myViewPortId ) + return myViewPortId < theStruct.myViewPortId; + else if ( myPointSize != theStruct.myPointSize ) + return myPointSize < theStruct.myPointSize; + else if ( myIsBold != theStruct.myIsBold ) + return myIsBold < theStruct.myIsBold; + else if ( myIsItal != theStruct.myIsItal ) + return myIsItal < theStruct.myIsItal; + else if ( myIsUndl != theStruct.myIsUndl ) + return myIsUndl < theStruct.myIsUndl; + else + return myFontFamily < theStruct.myFontFamily; } }; @@ -110,9 +129,12 @@ public: ~GLViewer_TexFont(); //! Generating font texture - void generateTexture(); + bool generateTexture(); //! Drawing string theStr in point with coords theX and theY - void drawString( QString theStr, GLdouble theX = 0.0, GLdouble theY = 0.0 ); + void drawString( QString theStr, + GLdouble theX = 0.0, + GLdouble theY = 0.0, + GLfloat theScale = 1.0 ); //! Returns separator between letters int getSeparator(){ return mySeparator; } @@ -131,8 +153,14 @@ public: static QMap TexFontBase; //! Map for strorage generated bitmaps fonts static QMap BitmapFontCache; + +private: + //! Initializes font parameters + void init(); -protected: +private: + //! Number of characters in the font texture + int myNbSymbols; //! Array of letter width int* myWidths; //! Array of letter positions in texture @@ -151,6 +179,10 @@ protected: bool myIsResizeable; //! Min/mag filter GLuint myMinMagFilter; + //! Font height + int myFontHeight; + //! Diagnostic information + int myMaxRowWidth; }; /*************************************************************************** @@ -359,15 +391,42 @@ public: /*! *\param format - the default text displaying format */ - inline void setTextFormat( DisplayTextFormat format ) { myTextFormat = format; } + inline void setTextFormat( const DisplayTextFormat format ) { myTextFormat = format; } //! Returns a default text displaying format used by drawGLText method inline DisplayTextFormat textFormat() const { return myTextFormat; } + //! Sets a text string displaying scale factor (used only with text format DTF_TEXTURE_SCALABLE) + /*! + *\param factor - scale factor + */ + inline void setTextScale( const GLfloat factor ) { myTextScale = factor; } + + //! Returns a text string displaying scale factor + inline GLfloat textScale() const { return myTextScale; } + + //! Returns a rectangle of text (without viewer scale) + GLViewer_Rect textRect( const QString& ) const; + + //! Draw rectangle with predefined color static void drawRectangle( GLViewer_Rect* theRect, QColor = Qt::black ); protected: + //! Draw basic primitives: rectangle, contour, polygon, vertex, cross, arrow + //* with predefined color + static void drawRectangle( GLViewer_Rect*, GLfloat, GLfloat = 0, QColor = Qt::black, + bool = false, QColor = Qt::white ); + static void drawContour( GLViewer_Rect*, QColor, GLfloat, GLushort, bool ); + static void drawContour( const GLViewer_PntList&, QColor, GLfloat ); + static void drawPolygon( GLViewer_Rect*, QColor, GLushort, bool ); + static void drawPolygon( const GLViewer_PntList&, QColor ); + static void drawVertex( GLfloat, GLfloat, QColor ); + static void drawCross( GLfloat, GLfloat, QColor ); + static void drawArrow( const GLfloat red, const GLfloat green, const GLfloat blue, + GLfloat, GLfloat, GLfloat, GLfloat, + GLfloat, GLfloat, GLfloat, GLboolean = GL_FALSE ); + //! Draw object text virtual void drawText( GLViewer_Object* theObject ); @@ -390,6 +449,10 @@ protected: QFont myFont; //! Default text displaying format for drawGLText() method DisplayTextFormat myTextFormat; + + //! Scale factor for text string draw, by default 0.125 + //! (used only with text format DTF_TEXTURE_SCALABLE) + GLfloat myTextScale; }; #ifdef WNT diff --git a/src/GLViewer/GLViewer_Object.cxx b/src/GLViewer/GLViewer_Object.cxx index d2aaf4e97..f5972674b 100644 --- a/src/GLViewer/GLViewer_Object.cxx +++ b/src/GLViewer/GLViewer_Object.cxx @@ -283,6 +283,9 @@ bool GLViewer_Object::initializeFromByteCopy( QByteArray theArray ) void GLViewer_Object::setGroup( GLViewer_Group* theGroup ) { + if ( myGroup == theGroup ) + return; + if( myGroup ) myGroup->removeObject( this ); diff --git a/src/GLViewer/GLViewer_Object.h b/src/GLViewer/GLViewer_Object.h index 39c9d9883..6cd21b294 100644 --- a/src/GLViewer/GLViewer_Object.h +++ b/src/GLViewer/GLViewer_Object.h @@ -185,7 +185,7 @@ public: virtual bool finishMove() { return true; } //! Returns visible object status - bool getVisible() const { return myIsVisible; } + virtual bool getVisible() const { return myIsVisible; } //! Installs visible object status virtual void setVisible( bool theStatus ) { myIsVisible = theStatus; } diff --git a/src/GLViewer/GLViewer_ViewPort.cxx b/src/GLViewer/GLViewer_ViewPort.cxx index 973342f84..78767afa1 100644 --- a/src/GLViewer/GLViewer_ViewPort.cxx +++ b/src/GLViewer/GLViewer_ViewPort.cxx @@ -31,7 +31,7 @@ //#include -#if !defined WNT +#if !(defined WNT) && !(defined QT_CLEAN_NAMESPACE) #define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */ #endif diff --git a/src/GLViewer/GLViewer_Viewer2d.cxx b/src/GLViewer/GLViewer_Viewer2d.cxx index c7a1d297d..f98f5e2ae 100644 --- a/src/GLViewer/GLViewer_Viewer2d.cxx +++ b/src/GLViewer/GLViewer_Viewer2d.cxx @@ -969,6 +969,8 @@ void GLViewer_Viewer2d::startOperations( QWheelEvent* e ) update = anObject->updateZoom( zoomIn ) || update; } + emit wheelZoomChange( zoomIn ); + if( update ) updateAll(); } diff --git a/src/GLViewer/GLViewer_Viewer2d.h b/src/GLViewer/GLViewer_Viewer2d.h index 94a5bd254..21840335f 100644 --- a/src/GLViewer/GLViewer_Viewer2d.h +++ b/src/GLViewer/GLViewer_Viewer2d.h @@ -180,6 +180,11 @@ public: //! Repaints view \param theView. If \param theView = NULL repaints all views. void repaintView( GLViewer_ViewFrame* theView = NULL, bool makeCurrent = false ); +signals: + //! Signal needs for optimum recompute of zoom depending objects + //! Warning: use recompute without update viewer + void wheelZoomChange( bool ); + public slots: //void onSketchDelObject(); //void onSketchUndoLast(); diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 50f5fe543..ca93892ff 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -1210,6 +1210,8 @@ void LightApp_Application::onDesktopActivated() QString LightApp_Application::getFileFilter() const { return "(*.bin)"; + // HDF persistence not yet completed - to be uncommented later + //return "(*.hdf)"; } /*! Gets file name*/ diff --git a/src/LightApp/LightApp_Driver.cxx b/src/LightApp/LightApp_Driver.cxx index 5b56e03b7..122890390 100644 --- a/src/LightApp/LightApp_Driver.cxx +++ b/src/LightApp/LightApp_Driver.cxx @@ -38,6 +38,7 @@ /*! Constructor.*/ LightApp_Driver::LightApp_Driver() +: myIsTemp( false ) { } @@ -354,6 +355,10 @@ LightApp_Driver::ListOfFiles LightApp_Driver::PutStreamToFiles( const unsigned c // Create a temporary directory for the component's data files std::string aDir = GetTmpDir(); + // Remember that the files are in a temporary location that should be deleted + // when a study is closed + SetIsTemporary( true ); + //Get a temporary directory for saving a file TCollection_AsciiString aTmpDir(const_cast(aDir.c_str())); @@ -430,9 +435,17 @@ void LightApp_Driver::RemoveFiles( const ListOfFiles& theFiles, const bool IsDir if(IsDirDeleted) { OSD_Path aPath(aDirName); OSD_Directory aDir(aPath); - OSD_FileIterator anIterator(aPath, '*'); - - if(aDir.Exists() && !anIterator.More()) aDir.Remove(); + // san -- Using a special code block below is essential - it ensures that + // OSD_FileIterator instance is destroyed by the moment when + // OSD_Directory::Remove() is called. + // Otherwise, the directory remains locked (at least on Windows) + // by the iterator and cannot be removed. + { + OSD_FileIterator anIterator(aPath, '*'); + if(!aDir.Exists() || anIterator.More()) + return; + } + aDir.Remove(); } } @@ -461,9 +474,13 @@ void LightApp_Driver::ClearDriverContents() for ( it = myMap.begin(); it != myMap.end(); ++it ) { const char* aModuleName = const_cast(it->first.c_str()); - RemoveTemporaryFiles( aModuleName, false ); + // If the driver contains temporary files - + // remove them along with the temporary directory + RemoveTemporaryFiles( aModuleName, IsTemporary() ); } - myMap.clear(); + myMap.clear(); + // Reset the "temporary" flag + SetIsTemporary( false ); } //============================================================================ @@ -523,7 +540,12 @@ std::string LightApp_Driver::GetTmpDir() aDir = OSD_Directory(aPath); } - OSD_Protection aProtection(OSD_RW, OSD_RWX, OSD_RX, OSD_RX); +#ifdef WIN32 + // Workaround for OSD_Protection bug on Windows + OSD_Protection aProtection(OSD_RWXD, OSD_RWXD, OSD_RWXD, OSD_RWXD); +#else + OSD_Protection aProtection(OSD_RX, OSD_RWXD, OSD_RX, OSD_RX); +#endif aDir.Build(aProtection); myTmpDir = aTmpDir.ToCString(); diff --git a/src/LightApp/LightApp_Driver.h b/src/LightApp/LightApp_Driver.h index 022ce16ec..f995ce27d 100644 --- a/src/LightApp/LightApp_Driver.h +++ b/src/LightApp/LightApp_Driver.h @@ -40,9 +40,9 @@ public: typedef std::vector ListOfFiles; - bool SaveDatasInFile (const char* theFileName, bool isMultiFile ); - bool ReadDatasFromFile (const char* theFileName, bool isMultiFile ); - virtual std::string GetTmpDir (const char* theURL, const bool isMultiFile); + virtual bool SaveDatasInFile (const char* theFileName, bool isMultiFile); + virtual bool ReadDatasFromFile (const char* theFileName, bool isMultiFile); + virtual std::string GetTmpDir (const char* theURL, const bool isMultiFile); ListOfFiles GetListOfFiles (const char* theModuleName); virtual void SetListOfFiles (const char* theModuleName, const ListOfFiles theListOfFiles); @@ -51,7 +51,7 @@ public: virtual void ClearDriverContents(); -private: +protected: void PutFilesToStream(const std::string& theModuleName, unsigned char*& theBuffer, long& theBufferSize, bool theNamesOnly = false); ListOfFiles PutStreamToFiles(const unsigned char* theBuffer, @@ -60,10 +60,16 @@ private: std::string GetTmpDir(); std::string GetDirFromPath(const std::string& thePath); -private: + void SetIsTemporary( bool theFlag ) { myIsTemp = theFlag; } + bool IsTemporary() const { return myIsTemp; } + +protected: typedef std::map MapOfListOfFiles; MapOfListOfFiles myMap; std::string myTmpDir; + +private: + bool myIsTemp; }; #endif diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index 283c49c89..6b4de40b6 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -9,6 +9,7 @@ #include "LightApp_Application.h" #include "LightApp_DataModel.h" +#include "LightApp_DataObject.h" #include "LightApp_Study.h" #include "LightApp_Preferences.h" #include "LightApp_Selection.h" @@ -92,13 +93,27 @@ void LightApp_Module::contextMenuPopup( const QString& client, QPopupMenu* menu, /*!Update object browser. * For updating model or whole object browser use update() method can be used. */ -void LightApp_Module::updateObjBrowser( bool updateDataModel, SUIT_DataObject* root ) -{ - if( updateDataModel ) - if( CAM_DataModel* aDataModel = dataModel() ) - if( LightApp_DataModel* aModel = dynamic_cast( aDataModel ) ) - aModel->update( 0, dynamic_cast( getApp()->activeStudy() ) ); - getApp()->objectBrowser()->updateTree( root ); +void LightApp_Module::updateObjBrowser( bool theIsUpdateDataModel, + SUIT_DataObject* theDataObject ) +{ + SUIT_DataObject* aDataObject = theDataObject; + if( theIsUpdateDataModel ){ + if( CAM_DataModel* aDataModel = dataModel() ){ + if ( LightApp_DataModel* aModel = dynamic_cast( aDataModel ) ) { + SUIT_DataObject* aParent = NULL; + if(theDataObject && theDataObject != aDataModel->root()) + aParent = theDataObject->parent(); + + LightApp_DataObject* anObject = dynamic_cast(theDataObject); + LightApp_Study* aStudy = dynamic_cast(getApp()->activeStudy()); + aModel->update( anObject, aStudy ); + + if(aParent && aParent->childPos(anObject) < 0) + aDataObject = dynamic_cast(aParent); + } + } + } + getApp()->objectBrowser()->updateTree( aDataObject ); } /*!NOT IMPLEMENTED*/ diff --git a/src/LightApp/LightApp_OBSelector.cxx b/src/LightApp/LightApp_OBSelector.cxx index 537f270bb..ebe8571b4 100644 --- a/src/LightApp/LightApp_OBSelector.cxx +++ b/src/LightApp/LightApp_OBSelector.cxx @@ -36,6 +36,8 @@ LightApp_OBSelector::LightApp_OBSelector( OB_Browser* ob, SUIT_SelectionMgr* mgr if ( myBrowser ) { connect( myBrowser, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) ); } + + setModified(); } /*! @@ -85,15 +87,16 @@ void LightApp_OBSelector::setSelection( const SUIT_DataOwnerPtrList& theList ) if ( !myBrowser ) return; - QMap themap; - fillEntries( themap ); + if( myEntries.count() == 0 || + myModifiedTime < myBrowser->getModifiedTime() ) + fillEntries( myEntries ); DataObjectList objList; for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it ) { const LightApp_DataOwner* owner = dynamic_cast( (*it).operator->() ); - if ( owner && themap.contains( owner->entry() ) ) - objList.append( themap[owner->entry()] ); + if ( owner && myEntries.contains( owner->entry() ) ) + objList.append( myEntries[owner->entry()] ); } myBrowser->setSelected( objList ); @@ -124,4 +127,12 @@ void LightApp_OBSelector::fillEntries( QMap& enti if ( obj ) entires.insert( obj->entry(), obj ); } + + setModified(); +} + +/*!Update modified time.*/ +void LightApp_OBSelector::setModified() +{ + myModifiedTime = clock(); } diff --git a/src/LightApp/LightApp_OBSelector.h b/src/LightApp/LightApp_OBSelector.h index 3669610ff..e8fc44371 100644 --- a/src/LightApp/LightApp_OBSelector.h +++ b/src/LightApp/LightApp_OBSelector.h @@ -40,6 +40,9 @@ public: /*!Return "ObjectBrowser"*/ virtual QString type() const { return "ObjectBrowser"; } + void setModified(); + unsigned long getModifiedTime() { return myModifiedTime; } + private slots: void onSelectionChanged(); @@ -53,6 +56,10 @@ private: private: OB_Browser* myBrowser; SUIT_DataOwnerPtrList mySelectedList; + + QMap myEntries; + + unsigned long myModifiedTime; }; #endif diff --git a/src/LightApp/LightApp_PreferencesDlg.cxx b/src/LightApp/LightApp_PreferencesDlg.cxx index 5d0f1ead4..af26451f7 100644 --- a/src/LightApp/LightApp_PreferencesDlg.cxx +++ b/src/LightApp/LightApp_PreferencesDlg.cxx @@ -23,8 +23,12 @@ #include "LightApp_Preferences.h" -#include +#include "QtxResourceMgr.h" + +#include #include +#include +#include /*! Constructor. @@ -50,6 +54,10 @@ myPrefs( prefs ), mySaved ( false ) connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) ); connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) ); + + QButton* defBtn = userButton( insertButton( tr( "DEFAULT_BTN_TEXT" ) ) ); + if ( defBtn ) + connect( defBtn, SIGNAL( clicked() ), this, SLOT( onDefault() ) ); } /*! @@ -99,6 +107,28 @@ void LightApp_PreferencesDlg::onHelp() void LightApp_PreferencesDlg::onApply() { myPrefs->store(); + + // Fix for Bug PAL11197: Restoring the corrected values from resource manager. + // (Correcting in VisuGUI.cxx and SMESHGUI.cxx in methods + // ::preferencesChanged( const QString& sect, const QString& name )) + myPrefs->retrieve(); + // + myPrefs->toBackup(); mySaved = true; } + +/*! Restore default preferences*/ +void LightApp_PreferencesDlg::onDefault() +{ + if( QMessageBox::Ok == QMessageBox::information( this, tr( "WARNING" ), tr( "DEFAULT_QUESTION" ), QMessageBox::Ok, QMessageBox::Cancel ) ) + { + if ( myPrefs && myPrefs->resourceMgr() ) + { + bool prev = myPrefs->resourceMgr()->ignoreUserValues(); + myPrefs->resourceMgr()->setIgnoreUserValues( true ); + myPrefs->retrieve(); + myPrefs->resourceMgr()->setIgnoreUserValues( prev ); + } + } +} diff --git a/src/LightApp/LightApp_PreferencesDlg.h b/src/LightApp/LightApp_PreferencesDlg.h index ea7bf55fe..771714519 100644 --- a/src/LightApp/LightApp_PreferencesDlg.h +++ b/src/LightApp/LightApp_PreferencesDlg.h @@ -46,6 +46,7 @@ public: private slots: void onHelp(); void onApply(); + void onDefault(); private: LightApp_Preferences* myPrefs; diff --git a/src/LightApp/LightApp_Study.cxx b/src/LightApp/LightApp_Study.cxx index e6b6f04a2..a2e5e4ba9 100644 --- a/src/LightApp/LightApp_Study.cxx +++ b/src/LightApp/LightApp_Study.cxx @@ -23,7 +23,8 @@ #include "LightApp_DataModel.h" #include "LightApp_DataObject.h" #include "LightApp_RootObject.h" -#include "LightApp_Driver.h" +// HDF persistence not yet completed +//#include "LightApp_HDFDriver.h" #include "SUIT_ResourceMgr.h" #include "SUIT_DataObjectIterator.h" @@ -50,6 +51,8 @@ LightApp_Study::LightApp_Study( SUIT_Application* app ) : CAM_Study( app ) { + // HDF persistence not yet completed + //myDriver = new LightApp_HDFDriver(); myDriver = new LightApp_Driver(); } @@ -229,16 +232,14 @@ bool LightApp_Study::saveDocument() //================================================================ void LightApp_Study::closeDocument(bool permanently) { - // Remove temporary files - ModelList aList; - dataModels( aList ); - myDriver->ClearDriverContents(); - // Inform everybody that this study is going to close when it's most safe to, // i.e. in the very beginning emit closed( this ); CAM_Study::closeDocument(permanently); + + // Remove temporary files + myDriver->ClearDriverContents(); } //================================================================ @@ -264,6 +265,18 @@ void LightApp_Study::children( const QString&, QStringList& ) const //================================================================ bool LightApp_Study::isComponent( const QString& entry ) const { + if( !root() ) + return false; + + DataObjectList ch; + root()->children( ch ); + DataObjectList::const_iterator anIt = ch.begin(), aLast = ch.end(); + for( ; anIt!=aLast; anIt++ ) + { + LightApp_DataObject* obj = dynamic_cast( *anIt ); + if( obj && obj->entry()==entry ) + return true; + } return false; } @@ -311,8 +324,8 @@ bool LightApp_Study::isSaved() const } //======================================================================= -// name : saveModuleData -/*! Purpose : Create SComponent for module, necessary for SalomeApp study */ +// name : addComponent +/*! Purpose : Create SComponent for module, necessary for SalomeApp study */ //======================================================================= void LightApp_Study::addComponent(const CAM_DataModel* dm) { @@ -451,7 +464,7 @@ void LightApp_Study::RemoveTemporaryFiles (const char* theModuleName, const bool } //================================================================ -// Function : RemoveTemporaryFiles +// Function : components /*! Purpose : to be used by modules*/ //================================================================ void LightApp_Study::components( QStringList& comp ) const @@ -465,4 +478,3 @@ void LightApp_Study::components( QStringList& comp ) const comp.append( obj->entry() ); } } - diff --git a/src/LightApp/LightApp_VTKSelector.cxx b/src/LightApp/LightApp_VTKSelector.cxx index 7b0b64333..b393b3043 100644 --- a/src/LightApp/LightApp_VTKSelector.cxx +++ b/src/LightApp/LightApp_VTKSelector.cxx @@ -19,7 +19,7 @@ #include "LightApp_VTKSelector.h" #include "LightApp_DataOwner.h" -#include "SVTK_ViewModel.h" +#include "SVTK_ViewModelBase.h" #include "SVTK_Selector.h" #include "SVTK_ViewWindow.h" #include "SVTK_Functor.h" @@ -36,9 +36,9 @@ */ LightApp_SVTKDataOwner ::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO, - const TColStd_IndexedMapOfInteger& theIds, - Selection_Mode theMode, - SALOME_Actor* theActor): + const TColStd_IndexedMapOfInteger& theIds, + Selection_Mode theMode, + SALOME_Actor* theActor): LightApp_DataOwner( theIO ), mySelectionMode(theMode), myActor(theActor) @@ -68,8 +68,8 @@ LightApp_SVTKDataOwner Constructor. */ LightApp_VTKSelector -::LightApp_VTKSelector( SVTK_Viewer* viewer, - SUIT_SelectionMgr* mgr ): +::LightApp_VTKSelector( SVTK_ViewModelBase* viewer, + SUIT_SelectionMgr* mgr ): SUIT_Selector( mgr, viewer ), myViewer( viewer ) { @@ -88,7 +88,7 @@ LightApp_VTKSelector /*! Gets viewer. */ -SVTK_Viewer* +SVTK_ViewModelBase* LightApp_VTKSelector ::viewer() const { @@ -96,13 +96,13 @@ LightApp_VTKSelector } /*! - Gets type of vtk viewer. + Gets type of salome vtk viewer. */ QString LightApp_VTKSelector ::type() const { - return SVTK_Viewer::Type(); + return myViewer->getType(); } /*! @@ -135,9 +135,10 @@ LightApp_VTKSelector TColStd_IndexedMapOfInteger anIds; aSelector->GetIndex(anIO,anIds); SALOME_Actor* anActor = aSelector->GetActor(anIO); - if( !anActor ) - anActor = VTK::Find(aView->getRenderer()->GetActors(),VTK::TIsSameIObject(anIO)); - + if( !anActor ){ + using namespace SVTK; + anActor = Find(aView->getRenderer()->GetActors(),TIsSameIObject(anIO)); + } aList.append(new LightApp_SVTKDataOwner(anIO,anIds,aMode,anActor)); } } diff --git a/src/LightApp/LightApp_VTKSelector.h b/src/LightApp/LightApp_VTKSelector.h index e7550ada5..14c6523ce 100644 --- a/src/LightApp/LightApp_VTKSelector.h +++ b/src/LightApp/LightApp_VTKSelector.h @@ -32,7 +32,7 @@ #include "SALOME_InteractiveObject.hxx" class SALOME_Actor; -class SVTK_Viewer; +class SVTK_ViewModelBase; /*! Provide salome vtk data owner list. @@ -75,10 +75,10 @@ class LIGHTAPP_EXPORT LightApp_VTKSelector : public SUIT_Selector Q_OBJECT; public: - LightApp_VTKSelector( SVTK_Viewer*, SUIT_SelectionMgr* ); + LightApp_VTKSelector( SVTK_ViewModelBase*, SUIT_SelectionMgr* ); virtual ~LightApp_VTKSelector(); - SVTK_Viewer* viewer() const; + SVTK_ViewModelBase* viewer() const; virtual QString type() const; @@ -90,7 +90,7 @@ protected: virtual void setSelection( const SUIT_DataOwnerPtrList& ); private: - SVTK_Viewer* myViewer; + SVTK_ViewModelBase* myViewer; }; #endif diff --git a/src/LightApp/Makefile.in b/src/LightApp/Makefile.in index 092b071f7..3ffef0449 100755 --- a/src/LightApp/Makefile.in +++ b/src/LightApp/Makefile.in @@ -41,6 +41,7 @@ EXPORT_HEADERS= LightApp.h \ LightApp_UpdateFlags.h \ LightApp_VTKSelector.h \ LightApp_WidgetContainer.h +# LightApp_HDFDriver.h \ # .po files to transform in .qm PO_FILES = LightApp_images.po \ @@ -75,6 +76,7 @@ LIB_SRC= LightApp_AboutDlg.cxx \ LightApp_PreferencesDlg.cxx \ LightApp_VTKSelector.cxx \ LightApp_WidgetContainer.cxx +# LightApp_HDFDriver.cxx \ LIB_MOC = LightApp_AboutDlg.h \ LightApp_Application.h \ @@ -105,9 +107,11 @@ RESOURCES_FILES = icon_about.png \ LightApp.ini \ LightApp.xml -CPPFLAGS+=$(PYTHON_INCLUDES) $(QT_INCLUDES) $(QWT_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) +CPPFLAGS+=$(PYTHON_INCLUDES) $(QT_INCLUDES) $(QWT_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) + #$(HDF5_INCLUDES) LDFLAGS+=$(PYTHON_LIBS) $(QT_MT_LIBS) -LIBS+= -lsuit -lstd -lCAM -lObjBrowser -lLogWindow $(CAS_KERNEL) -lGLViewer -lOCCViewer -lVTKViewer -lSalomeObject -lSOCC -lSVTK -lSPlot2d -lSUPERVGraph -lPyInterp -lPythonConsole +LIBS+= -lsuit -lstd -lCAM -lObjBrowser -lLogWindow $(CAS_KERNEL) -lGLViewer -lOCCViewer -lVTKViewer -lSalomeObject -lSOCC -lSVTK -lSPlot2d -lSUPERVGraph -lPyInterp -lPythonConsole + #$(HDF5_LIBS) -lSalomeHDFPersistCopy @CONCLUDE@ diff --git a/src/LightApp/resources/LightApp_msg_en.po b/src/LightApp/resources/LightApp_msg_en.po index 5c3215335..c5b364d56 100644 --- a/src/LightApp/resources/LightApp_msg_en.po +++ b/src/LightApp/resources/LightApp_msg_en.po @@ -256,6 +256,15 @@ msgstr "Auto size for first column" msgid "LightApp_PreferencesDlg::CAPTION" msgstr "Preferences" +msgid "LightApp_PreferencesDlg::DEFAULT_BTN_TEXT" +msgstr "Defaults" + +msgid "LightApp_PreferencesDlg::WARNING" +msgstr "Warning" + +msgid "LightApp_PreferencesDlg::DEFAULT_QUESTION" +msgstr "Do you want to retrieve default preferences?" + //======================================================================================= msgid "LightApp_Module::TOP_DISPLAY" diff --git a/src/OBJECT/Makefile.in b/src/OBJECT/Makefile.in index 9bcbc4cec..0fb5e50a7 100755 --- a/src/OBJECT/Makefile.in +++ b/src/OBJECT/Makefile.in @@ -9,7 +9,6 @@ VPATH=.:@srcdir@:@top_srcdir@/idl EXPORT_HEADERS = SALOME_InteractiveObject.hxx \ Handle_SALOME_InteractiveObject.hxx \ - SALOME_Actor.h \ SALOME_GLOwner.h \ SALOME_AISShape.hxx \ Handle_SALOME_AISShape.hxx \ @@ -33,7 +32,6 @@ EXPORT_HEADERS = SALOME_InteractiveObject.hxx \ LIB = libSalomeObject.la LIB_SRC = SALOME_InteractiveObject.cxx \ - SALOME_Actor.cxx \ SALOME_GLOwner.cxx \ SALOME_AISShape.cxx\ SALOME_AISObject.cxx\ diff --git a/src/OBJECT/SALOME_Actor.cxx b/src/OBJECT/SALOME_Actor.cxx deleted file mode 100755 index 385cb4d93..000000000 --- a/src/OBJECT/SALOME_Actor.cxx +++ /dev/null @@ -1,308 +0,0 @@ -// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers -// -// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : SALOME_Actor.cxx -// Author : Nicolas REJNERI -// Module : SALOME -// $Header$ - -/*! - \class SALOME_Actor SALOME_Actor.h - \brief Abstract class of SALOME Objects in VTK. -*/ - - -#include "SALOME_Actor.h" - -#include "VTKViewer_Transform.h" -#include "VTKViewer_TransformFilter.h" -#include "VTKViewer_PassThroughFilter.h" -#include "VTKViewer_GeometryFilter.h" - -// SALOME Includes -//#include "utilities.h" - -// VTK Includes -#include -#include -#include -#include -#include -#include -#include - -//using namespace std; - - -#if defined __GNUC__ - #if __GNUC__ == 2 - #define __GNUC_2__ - #endif -#endif - -int SALOME_POINT_SIZE = 3; - - -vtkStandardNewMacro(SALOME_Actor); - - -SALOME_Actor::SALOME_Actor(){ - myIsHighlighted = myIsPreselected = false; - - myRepresentation = 1; - myDisplayMode = myRepresentation - 1; - - myProperty = vtkProperty::New(); - PreviewProperty = NULL; - - myIsInfinite = false; - - myIsResolveCoincidentTopology = true; - - vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, - myPolygonOffsetUnits); - myStoreMapping = false; - myGeomFilter = VTKViewer_GeometryFilter::New(); - - myTransformFilter = VTKViewer_TransformFilter::New(); - - for(int i = 0; i < 6; i++) - myPassFilter.push_back(VTKViewer_PassThroughFilter::New()); -} - - -SALOME_Actor::~SALOME_Actor(){ - SetPreviewProperty(NULL); - - myGeomFilter->UnRegisterAllOutputs(); - myGeomFilter->Delete(); - - myTransformFilter->UnRegisterAllOutputs(); - myTransformFilter->Delete(); - - for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){ - if(myPassFilter[i]){ - myPassFilter[i]->UnRegisterAllOutputs(); - myPassFilter[i]->Delete(); - } - } - - myProperty->Delete(); -} - - -void SALOME_Actor::AddToRender(vtkRenderer* theRenderer){ - theRenderer->AddActor(this); -} - -void SALOME_Actor::RemoveFromRender(vtkRenderer* theRenderer){ - theRenderer->RemoveActor(this); -} - - -void SALOME_Actor::SetTransform(VTKViewer_Transform* theTransform){ - myTransformFilter->SetTransform(theTransform); -} - - -void SALOME_Actor::SetMapper(vtkMapper* theMapper){ - InitPipeLine(theMapper); -} - -void SALOME_Actor::InitPipeLine(vtkMapper* theMapper){ - if(theMapper){ - int anId = 0; - myPassFilter[ anId ]->SetInput( theMapper->GetInput() ); - myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() ); - - anId++; // 1 - myGeomFilter->SetStoreMapping( myStoreMapping ); - myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() ); - - anId++; // 2 - myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); - myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); - - anId++; // 3 - myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); - - anId++; // 4 - myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() ); - myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); - - anId++; // 5 - if(vtkDataSetMapper* aMapper = dynamic_cast(theMapper)){ - aMapper->SetInput(myPassFilter[anId]->GetOutput()); - }else if(vtkPolyDataMapper* aMapper = dynamic_cast(theMapper)){ - aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput()); - } - } - vtkLODActor::SetMapper(theMapper); -} - - -void SALOME_Actor::Render(vtkRenderer *ren, vtkMapper* m){ - if(myIsResolveCoincidentTopology){ - int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology(); - float aFactor, aUnit; - vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); - - vtkMapper::SetResolveCoincidentTopologyToPolygonOffset(); - vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, - myPolygonOffsetUnits); - vtkLODActor::Render(ren,m); - - vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); - vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology); - }else{ - vtkLODActor::Render(ren,m); - } -} - - -void SALOME_Actor::SetResolveCoincidentTopology(bool theIsResolve) { - myIsResolveCoincidentTopology = theIsResolve; -} - -void SALOME_Actor::SetPolygonOffsetParameters(float factor, float units){ - myPolygonOffsetFactor = factor; - myPolygonOffsetUnits = units; -} - -void SALOME_Actor::GetPolygonOffsetParameters(float& factor, float& units){ - factor = myPolygonOffsetFactor; - units = myPolygonOffsetUnits; -} - - -vtkDataSet* SALOME_Actor::GetInput(){ - return myPassFilter.front()->GetOutput(); -} - - -unsigned long int SALOME_Actor::GetMTime(){ - unsigned long mTime = this->Superclass::GetMTime(); - unsigned long time = myTransformFilter->GetMTime(); - mTime = ( time > mTime ? time : mTime ); - if(vtkDataSet *aDataSet = myPassFilter[0]->GetInput()){ - time = aDataSet->GetMTime(); - mTime = ( time > mTime ? time : mTime ); - } - return mTime; -} - - -void SALOME_Actor::SetRepresentation(int theMode) { - switch(myRepresentation){ - case VTK_POINTS : - case VTK_SURFACE : - myProperty->DeepCopy(GetProperty()); - } - switch(theMode){ - case VTK_POINTS : - case VTK_SURFACE : - GetProperty()->DeepCopy(myProperty); - break; - default: - GetProperty()->SetAmbient(1.0); - GetProperty()->SetDiffuse(0.0); - GetProperty()->SetSpecular(0.0); - } - switch(theMode){ - case 3 : - myGeomFilter->SetInside(true); - GetProperty()->SetRepresentation(1); - break; - case VTK_POINTS : - GetProperty()->SetPointSize(SALOME_POINT_SIZE); - default : - GetProperty()->SetRepresentation(theMode); - myGeomFilter->SetInside(false); - } - myRepresentation = theMode; -} - -int SALOME_Actor::GetRepresentation(){ - return myRepresentation; -} - - -vtkCell* SALOME_Actor::GetElemCell(int theObjID){ - return GetInput()->GetCell(theObjID); -} - - -float* SALOME_Actor::GetNodeCoord(int theObjID){ - return GetInput()->GetPoint(theObjID); -} - - -//================================================================================= -// function : GetObjDimension -// purpose : Return object dimension. -// Virtual method shoulb be redifined by derived classes -//================================================================================= -int SALOME_Actor::GetObjDimension( const int theObjId ) -{ - if ( vtkCell* aCell = GetElemCell(theObjId) ) - return aCell->GetCellDimension(); - return 0; -} - - -bool SALOME_Actor::IsInfinitive(){ - return myIsInfinite; -} - - -void SALOME_Actor::SetOpacity(float theOpacity){ - myOpacity = theOpacity; - GetProperty()->SetOpacity(theOpacity); -} - -float SALOME_Actor::GetOpacity(){ - return myOpacity; -} - - -void SALOME_Actor::SetColor(float r,float g,float b){ - GetProperty()->SetColor(r,g,b); -} - -void SALOME_Actor::GetColor(float& r,float& g,float& b){ - float aColor[3]; - GetProperty()->GetColor(aColor); - r = aColor[0]; - g = aColor[1]; - b = aColor[2]; -} - - -int SALOME_Actor::getDisplayMode(){ - return myDisplayMode; -} - -void SALOME_Actor::setDisplayMode(int theMode){ - SetRepresentation(theMode+1); - myDisplayMode = GetRepresentation() - 1; -} diff --git a/src/OBJECT/SALOME_Actor.h b/src/OBJECT/SALOME_Actor.h deleted file mode 100755 index 2467f1e89..000000000 --- a/src/OBJECT/SALOME_Actor.h +++ /dev/null @@ -1,187 +0,0 @@ -// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers -// -// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : SALOME_Actor.h -// Author : Nicolas REJNERI -// Module : SALOME -// $Header$ - -#ifndef SALOME_ACTOR_H -#define SALOME_ACTOR_H - -#include "SALOME_InteractiveObject.hxx" // INCLUDES "using namespace std" -#ifndef _Handle_SALOME_InteractiveObject_HeaderFile -#include "Handle_SALOME_InteractiveObject.hxx" -#endif - -#include // INCLUDES "stdio.h" -#include - -// to overcome the conflict between std::ostream and io::ostream -// the following variable must be defined: -// VTK_USE_ANSI_STDLIB - -#include - -class vtkCell; -class vtkDataSet; -class vtkPolyData; -class vtkCamera; -class vtkProperty; - -class VTKViewer_Transform; -class VTKViewer_GeometryFilter; -class VTKViewer_TransformFilter; -class VTKViewer_PassThroughFilter; - -extern int SALOME_POINT_SIZE; - -#ifdef WNT -#define SALOME_OBJECT_EXPORT __declspec (dllexport) -#else -#define SALOME_OBJECT_EXPORT -#endif - -#include - -class SALOME_OBJECT_EXPORT SALOME_Actor : public VTKViewer_Actor { - public: - static SALOME_Actor* New(); - - vtkTypeMacro(SALOME_Actor,vtkLODActor); - - virtual Standard_Boolean hasIO() { return !myIO.IsNull(); } - virtual const Handle(SALOME_InteractiveObject)& getIO() { return myIO; } - virtual void setIO(const Handle(SALOME_InteractiveObject)& io) { myIO = io; } - - virtual const char* getName() { return myName.c_str(); } - virtual void setName(const char* theName){ - if(hasIO()) myIO->setName(theName); - myName = theName; - } - - // To generate highlight automaticaly - virtual bool hasHighlight() { return false; } - virtual void highlight(bool theHighlight) { myIsHighlighted = theHighlight; } - virtual bool isHighlighted() { return myIsHighlighted; } - - virtual void SetOpacity(float theOpacity); - virtual float GetOpacity(); - - virtual void SetColor(float r,float g,float b); - virtual void GetColor(float& r,float& g,float& b); - void SetColor(const float theRGB[3]){ - SetColor(theRGB[0],theRGB[1],theRGB[2]); - } - - vtkSetObjectMacro(PreviewProperty,vtkProperty); - - virtual void SetPreSelected(bool thePreselect = false) { myIsPreselected = thePreselect;} - - - // Used to obtain all dependent actors - virtual void GetChildActors(vtkActorCollection*) {}; - - virtual void AddToRender(vtkRenderer* theRenderer); - virtual void RemoveFromRender(vtkRenderer* theRenderer); - - - // For selection mapping purpose - virtual int GetNodeObjId(int theVtkID) { return theVtkID;} - virtual float* GetNodeCoord(int theObjID); - - virtual int GetElemObjId(int theVtkID) { return theVtkID;} - virtual vtkCell* GetElemCell(int theObjID); - - virtual int GetObjDimension( const int theObjId ); - - virtual void SetMapper(vtkMapper* theMapper); - virtual vtkDataSet* GetInput(); - - - virtual void SetTransform(VTKViewer_Transform* theTransform); - virtual unsigned long int GetMTime(); - - virtual void SetRepresentation(int theMode); - virtual int GetRepresentation(); - - virtual int getDisplayMode(); - virtual void setDisplayMode(int theMode); - - // Infinitive means actor without size (point for example), - // which is not taken into account in calculation of boundaries of the scene - void SetInfinitive(bool theIsInfinite) { myIsInfinite = theIsInfinite; } - virtual bool IsInfinitive(); - - void SetResolveCoincidentTopology(bool theIsResolve); - void SetPolygonOffsetParameters(float factor, float units); - void GetPolygonOffsetParameters(float& factor, float& units); - - virtual void Render(vtkRenderer *, vtkMapper *); - - virtual float GetShrinkFactor() { return 1.0;} - - virtual bool IsShrunkable() { return false;} - virtual bool IsShrunk() { return false;} - - virtual void SetShrink() {} - virtual void UnShrink() {} - - virtual bool IsSetCamera() const { return false; } - virtual bool IsResizable() const { return false; } - virtual void SetSize( const float ) {} - virtual void SetCamera( vtkCamera* ) {} - - protected: - bool myIsResolveCoincidentTopology; - float myPolygonOffsetFactor; - float myPolygonOffsetUnits; - - Handle(SALOME_InteractiveObject) myIO; - std::string myName; - - vtkProperty *PreviewProperty; - bool myIsPreselected; - - float myOpacity; - bool myIsHighlighted; - int myDisplayMode; - bool myIsInfinite; - - bool myStoreMapping; - VTKViewer_GeometryFilter *myGeomFilter; - VTKViewer_TransformFilter *myTransformFilter; - std::vector myPassFilter; - - int myRepresentation; - vtkProperty *myProperty; - - void InitPipeLine(vtkMapper* theMapper); - - SALOME_Actor(); - ~SALOME_Actor(); -}; - - -#endif // SALOME_ACTOR_H - diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index fff6ab535..5b4bc28e3 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -22,6 +22,9 @@ #include "OB_ListItem.h" #include "OB_ListView.h" +#include +#include + #include #include #include @@ -29,6 +32,9 @@ #include #include #include +#include + +#include /*! Class: OB_Browser::ToolTip @@ -79,6 +85,138 @@ void OB_Browser::ToolTip::maybeTip( const QPoint& pos ) tip( aRect, aText ); } + +typedef SUIT_DataObject* ObjPtr; +typedef OB_ListItem* ItemPtr; +/*! + Class: OB_BrowserSync + Descr: Auxiliary class for synchronizing tree of SUIT_DataObjects and list view items +*/ + +class OB_BrowserSync +{ +public: + OB_BrowserSync( OB_Browser* ); + bool isEqual( const ObjPtr&, const ItemPtr& ) const; + ObjPtr nullSrc() const; + ItemPtr nullTrg() const; + ItemPtr createItem( const ObjPtr&, const ItemPtr&, const ItemPtr&, const bool ) const; + void updateItem( const ItemPtr& ) const; + void deleteItemWithChildren( const ItemPtr& ) const; + void children( const ObjPtr&, QValueList& ) const; + void children( const ItemPtr&, QValueList& ) const; + ItemPtr parent( const ItemPtr& ) const; +private: + bool needUpdate( const ItemPtr& ) const; + OB_Browser* myBrowser; +}; + + +OB_BrowserSync::OB_BrowserSync( OB_Browser* ob ) +: myBrowser( ob ) +{ +} + +bool OB_BrowserSync::needUpdate( const ItemPtr& item ) const +{ + bool update = false; + if ( item ) { + SUIT_DataObject* obj = item->dataObject(); + if ( obj ) { + // 1. check text + update = ( item->text( 0 ) != obj->name() ); + if ( !update ) { + // 2. check pixmap (compare serialNumber()-s) + QPixmap objPix = obj->icon(); + const QPixmap* itemPix = item->pixmap( 0 ); + update = ( objPix.isNull() && ( itemPix && !itemPix->isNull() ) ) || + ( !objPix.isNull() && ( !itemPix || itemPix->isNull() ) ); + if ( !update && !objPix.isNull() && itemPix && !itemPix->isNull() ) { + int aIconW = objPix.width(); + if( aIconW > 20 ) { + QWMatrix aM; + double aScale = 20.0 / aIconW; + aM.scale( aScale, aScale ); + objPix = objPix.xForm( aM ); + } + update = ( objPix.serialNumber() != itemPix->serialNumber() ); + } + } + } + } + return update; +} + +void OB_BrowserSync::updateItem( const ItemPtr& p ) const +{ + if ( p && needUpdate( p ) ) { + // printf( "--- needUpdate for %s = true ---\n", p->text( 0 ).latin1() ); + p->update(); + } +} + +ItemPtr OB_BrowserSync::createItem( const ObjPtr& src, + const ItemPtr& parent, const ItemPtr& after, + const bool asFirst ) const +{ + ItemPtr i = myBrowser ? dynamic_cast( myBrowser->createItem( src, parent, after, asFirst ) ) : 0; + if( i ) + i->setOpen( src->isOpen() ); + return i; +} + +void OB_BrowserSync::deleteItemWithChildren( const ItemPtr& i ) const +{ + if( myBrowser && myBrowser->myItems.contains( i->dataObject() ) ) + { + myBrowser->removeReferences( i ); + delete i; + } +} + +bool OB_BrowserSync::isEqual( const ObjPtr& p, const ItemPtr& q ) const +{ + return ( !p && !q ) || ( p && q && q->dataObject()==p ); +} + +ObjPtr OB_BrowserSync::nullSrc() const +{ + return 0; +} + +ItemPtr OB_BrowserSync::nullTrg() const +{ + return 0; +} + +void OB_BrowserSync::children( const ObjPtr& p, QValueList& ch ) const +{ + DataObjectList l; + if( p ) + { + p->children( l ); + ch.clear(); + for( SUIT_DataObject* o = l.first(); o; o = l.next() ) + ch.append( o ); + } +} + +void OB_BrowserSync::children( const ItemPtr& p, QValueList& ch ) const +{ + for( QListViewItem* item = p->firstChild(); item; item = item->nextSibling() ) + { + ItemPtr p = dynamic_cast( item ); + if( p ) + ch.append( p ); + } +} + +ItemPtr OB_BrowserSync::parent( const ItemPtr& p ) const +{ + return p ? dynamic_cast( p->parent() ) : 0; +} + + /*! Class: OB_Browser Descr: Hierarchical tree object browser. @@ -115,6 +253,8 @@ myRootDecorated( true ) this, SLOT( onDoubleClicked( QListViewItem* ) ) ); setRootObject( root ); + + setModified(); } OB_Browser::~OB_Browser() @@ -219,6 +359,8 @@ void OB_Browser::setRootObject( SUIT_DataObject* theRoot ) autoOpenBranches(); + setModified(); + if ( selNum != numberOfSelected() ) emit selectionChanged(); } @@ -508,6 +650,8 @@ void OB_Browser::setAppropriateColumn( const int id, const bool on ) void OB_Browser::updateTree( SUIT_DataObject* obj, const bool autoOpen ) { +// QTime t1 = QTime::currentTime(); + if ( !obj && !(obj = getRootObject()) ) return; @@ -526,8 +670,13 @@ void OB_Browser::updateTree( SUIT_DataObject* obj, const bool autoOpen ) if( autoOpen ) autoOpenBranches(); + setModified(); + if ( selNum != numberOfSelected() ) emit selectionChanged(); + +// QTime t2 = QTime::currentTime(); +// qDebug( QString( "update tree time = %1 msecs" ).arg( t1.msecsTo( t2 ) ) ); } void OB_Browser::replaceTree( SUIT_DataObject* src, SUIT_DataObject* trg ) @@ -564,88 +713,73 @@ void OB_Browser::replaceTree( SUIT_DataObject* src, SUIT_DataObject* trg ) autoOpenBranches(); + setModified(); + if ( selNum != numberOfSelected() ) emit selectionChanged(); } -void OB_Browser::updateView( const SUIT_DataObject* theStartObj ) +void OB_Browser::updateView( SUIT_DataObject* startObj ) { QListView* lv = listView(); if ( !lv ) return; - if ( !theStartObj || theStartObj->root() != getRootObject() ) + if ( !startObj || startObj->root() != getRootObject() ) return; - QListViewItem* after = 0; - QListViewItem* parent = 0; - QListViewItem* startItem = listViewItem( theStartObj ); - - if ( theStartObj->parent() ) - parent = listViewItem( theStartObj->parent() ); - - QListViewItem* prv = 0; - QListViewItem* cur = parent ? parent->firstChild() : lv->firstChild(); - while ( !after && cur ) + if( startObj==myRoot ) { - if ( cur == startItem ) - after = prv; + DataObjectList ch; + myRoot->children( ch ); - prv = cur; - cur = cur->nextSibling(); - } - - QPtrList delList; - if ( !startItem && theStartObj == getRootObject() ) - { - for ( QListViewItem* item = lv->firstChild(); item; item = item->nextSibling() ) - delList.append( item ); - } - else - delList.append( startItem ); + ItemMap exist; + QListViewItem* st = lv->firstChild(); + for( ; st; st = st->nextSibling() ) + { + OB_ListItem* ob_item = dynamic_cast( st ); + exist.insert( ob_item->dataObject(), ob_item ); + } - for ( QPtrListIterator it( delList ); it.current(); ++it ) - { - removeReferences( it.current() ); - delete it.current(); - } + SUIT_DataObject* local_root = ch.first(); + for( ; local_root; local_root = ch.next() ) + { + OB_BrowserSync sync( this ); + OB_ListItem* local_item = dynamic_cast( listViewItem( local_root ) ); + + // QString srcName = ( local_root && !local_root->name().isNull() ) ? local_root->name() : ""; + // QString trgName = ( local_item && !local_item->text(0).isNull() ) ? local_item->text(0) : ""; + // printf( "--- OB_Browser::updateView() calls synchronize()_1: src = %s, trg = %s ---\n", srcName.latin1(), trgName.latin1() ); + + synchronize( local_root, local_item, sync ); + exist[local_root] = 0; + } - // for myRoot object, if myShowRoot==false, then creating multiple top-level QListViewItem-s - // (which will correspond to myRoot's children = Modules). - if ( rootIsDecorated() && theStartObj == myRoot ) - { - DataObjectList lst; - theStartObj->children( lst ); - DataObjectListIterator it ( lst ); - // iterating backward to preserve the order of elements in the tree - for ( it.toLast(); it.current(); --it ) - createTree( it.current(), 0, 0 ); + ItemMap::const_iterator anIt = exist.begin(), aLast = exist.end(); + for( ; anIt!=aLast; anIt++ ) + if( anIt.data() ) + { + removeReferences( anIt.data() ); + OB_ListItem* item = dynamic_cast( anIt.data() ); + if( item && myItems.contains( item->dataObject() ) ) + delete anIt.data(); + } } else - createTree( theStartObj, parent, after ? after : parent ); -} - -QListViewItem* OB_Browser::createTree( const SUIT_DataObject* obj, - QListViewItem* parent, QListViewItem* after ) -{ - if ( !obj ) - return 0; - - QListViewItem* item = createItem( obj, parent, after ); - - DataObjectList lst; - obj->children( lst ); - for ( DataObjectListIterator it ( lst ); it.current(); ++it ) - createTree( it.current(), item ); + { + OB_BrowserSync sync( this ); + OB_ListItem* startItem = dynamic_cast( listViewItem( startObj ) ); - if ( item ) - item->setOpen( obj->isOpen() ); + // QString srcName = ( startObj && !startObj->name().isNull() ) ? startObj->name() : ""; + // QString trgName = ( startItem && !startItem->text(0).isNull() ) ? startItem->text(0) : ""; + // printf( "--- OB_Browser::updateView() calls synchronize()_2: src = %s, trg = %s ---\n", srcName.latin1(), trgName.latin1() ); - return item; + synchronize( startObj, startItem, sync ); + } } -QListViewItem* OB_Browser::createItem( const SUIT_DataObject* o, - QListViewItem* parent, QListViewItem* after ) +QListViewItem* OB_Browser::createItem( const SUIT_DataObject* o, QListViewItem* parent, + QListViewItem* after, const bool asFirstChild ) { QListView* lv = listView(); @@ -676,7 +810,7 @@ QListViewItem* OB_Browser::createItem( const SUIT_DataObject* o, after = after->nextSibling(); } - if ( after ) + if ( after && !asFirstChild ) { if ( type == -1 ) item = new OB_ListItem( obj, parent, after ); @@ -701,7 +835,6 @@ QListViewItem* OB_Browser::createItem( const SUIT_DataObject* o, myItems.insert( obj, item ); obj->connect( this, SLOT( onDestroyed( SUIT_DataObject* ) ) ); - updateText( item ); return item; @@ -1089,7 +1222,7 @@ void OB_Browser::removeObject( SUIT_DataObject* obj, const bool autoUpd ) return; } - if ( !autoUpd ) + if( !autoUpd ) return; if ( isAutoUpdate() ) @@ -1097,8 +1230,8 @@ void OB_Browser::removeObject( SUIT_DataObject* obj, const bool autoUpd ) SUIT_DataObject* pObj = item && item->parent() ? dataObject( item->parent() ) : 0; updateTree( pObj, false ); } - else - delete item; + + delete item; } void OB_Browser::autoOpenBranches() @@ -1134,3 +1267,9 @@ void OB_Browser::onDoubleClicked( QListViewItem* item ) if ( item ) emit doubleClicked( dataObject( item ) ); } + +void OB_Browser::setModified() +{ + myModifiedTime = clock(); +} + diff --git a/src/ObjBrowser/OB_Browser.h b/src/ObjBrowser/OB_Browser.h index cd0b48889..a6e3cd421 100755 --- a/src/ObjBrowser/OB_Browser.h +++ b/src/ObjBrowser/OB_Browser.h @@ -37,6 +37,7 @@ class QToolTip; class OB_Filter; class OB_ListView; +class OB_ListItem; class OB_EXPORT OB_Browser : public QFrame, public SUIT_PopupClient { @@ -117,6 +118,9 @@ public: virtual void contextMenuPopup( QPopupMenu* ); + void setModified(); + unsigned long getModifiedTime() { return myModifiedTime; } + signals: void selectionChanged(); void doubleClicked( SUIT_DataObject* ); @@ -131,7 +135,7 @@ private slots: protected: void adjustWidth( QListViewItem* ); - virtual void updateView( const SUIT_DataObject* theStartObj = 0 ); + virtual void updateView( SUIT_DataObject* = 0 ); virtual void updateText(); virtual void keyPressEvent( QKeyEvent* ); @@ -162,8 +166,8 @@ private: DataObjectKey objectKey( QListViewItem* ) const; DataObjectKey objectKey( SUIT_DataObject* ) const; - QListViewItem* createTree( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0 ); - QListViewItem* createItem( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0 ); + QListViewItem* createTree( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0, const bool = false ); + QListViewItem* createItem( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0, const bool = false ); SUIT_DataObject* storeState( DataObjectMap&, DataObjectMap&, DataObjectKeyMap&, DataObjectKeyMap&, DataObjectKey& ) const; @@ -171,6 +175,8 @@ private: const DataObjectKeyMap&, const DataObjectKeyMap&, const DataObjectKey& ); private: + friend class OB_BrowserSync; + OB_ListView* myView; SUIT_DataObject* myRoot; ItemMap myItems; @@ -183,6 +189,8 @@ private: int myAutoOpenLevel; friend class OB_Browser::ToolTip; + + unsigned long myModifiedTime; }; #endif diff --git a/src/ObjBrowser/OB_ListItem.cxx b/src/ObjBrowser/OB_ListItem.cxx index b2ced5c7b..49ad75741 100755 --- a/src/ObjBrowser/OB_ListItem.cxx +++ b/src/ObjBrowser/OB_ListItem.cxx @@ -34,7 +34,7 @@ using namespace std; */ template -ListItemF::ListItemF( T& theT, SUIT_DataObject* obj ) : +ListItemF::ListItemF( T* theT, SUIT_DataObject* obj ) : myT( theT ), myObject( obj ) { @@ -61,7 +61,7 @@ void ListItemF::paintC( QPainter* p, QColorGroup& cg, int c, int w, int align } - p->fillRect( 0, 0, w, myT.height(), cg.brush( QColorGroup::Base ) ); + p->fillRect( 0, 0, w, myT->height(), cg.brush( QColorGroup::Base ) ); //int itemW = myT.width( p->fontMetrics(), myT.listView(), c ); //myT.paintCell( p, colorGrp, c, itemW, align ); @@ -71,18 +71,18 @@ template void ListItemF::paintFoc( QPainter* p, QColorGroup& cg, const QRect& r ) { QRect rect = r; - rect.setWidth( myT.width( p->fontMetrics(), myT.listView(), 0 ) ); + rect.setWidth( myT->width( p->fontMetrics(), myT->listView(), 0 ) ); //myT.paintFocus( p, cg, rect ); } template void ListItemF::setSel( bool s ) { - QListView* lv = myT.listView(); + QListView* lv = myT->listView(); if ( s && lv && lv->inherits( "OB_ListView" ) ) { OB_ListView* objlv = (OB_ListView*)lv; - s = s && objlv->isOk( &myT ); + s = s && objlv->isOk( myT ); } //myT.setSelected( s ); @@ -95,24 +95,27 @@ void ListItemF::update() if ( !obj ) return; - myT.setText( 0, obj->name() ); + QString n = obj->name(); + if( myT->text( 0 )!=n ) + myT->setText( 0, n ); - int aIconW = obj->icon().width(); - if ( aIconW > 0 ) + QPixmap p = obj->icon(); + int aIconW = p.width(); + if( aIconW > 0 ) { - if ( aIconW > 20 ) + if( aIconW > 20 ) { QWMatrix aM; double aScale = 20.0 / aIconW; aM.scale( aScale, aScale ); - myT.setPixmap( 0, obj->icon().xForm( aM ) ); + myT->setPixmap( 0, p.xForm( aM ) ); } else - myT.setPixmap( 0, obj->icon() ); + myT->setPixmap( 0, p ); } - myT.setDragEnabled( obj->isDragable() ); - myT.setDropEnabled( true ); + myT->setDragEnabled( obj->isDragable() ); + myT->setDropEnabled( true ); } /*! @@ -121,31 +124,31 @@ void ListItemF::update() */ OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListView* parent ) -: ListItemF( *this, obj ), +: ListItemF( this, obj ), QListViewItem(parent) { - update(); + update(); } OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListViewItem* parent ) -: ListItemF( *this, obj), +: ListItemF( this, obj ), QListViewItem(parent) { - update(); + update(); } OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after ) -: ListItemF( *this, obj), +: ListItemF( this, obj), QListViewItem(parent, after ) { - update(); + update(); } OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after ) -: ListItemF( *this,obj), +: ListItemF( this,obj), QListViewItem(parent, after ) { - update(); + update(); } OB_ListItem::~OB_ListItem() @@ -154,8 +157,8 @@ OB_ListItem::~OB_ListItem() void OB_ListItem::setSelected( bool s ) { - setSel( s ); - QListViewItem::setSelected( s ); + setSel( s ); + QListViewItem::setSelected( s ); } void OB_ListItem::paintFocus( QPainter* p, const QColorGroup& cg, const QRect& r ) @@ -209,39 +212,39 @@ void OB_ListItem::setText( int column, const QString& text ) */ OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, Type type ) -: ListItemF( *this, obj), +: ListItemF( this, obj), QCheckListItem( parent, "", type ) { - update(); + update(); } OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, Type type ) -: ListItemF( *this, obj), +: ListItemF( this, obj), QCheckListItem( parent, "", type ) { - update(); + update(); } OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after, Type type ) -: ListItemF( *this, obj), +: ListItemF( this, obj), #if defined(QT_VERSION) && QT_VERSION >= 0x030101 QCheckListItem( parent, after, "", type ) #else QCheckListItem( parent, "", type ) #endif { - update(); + update(); } OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after, Type type ) -: ListItemF( *this, obj), +: ListItemF( this, obj), #if defined(QT_VERSION) && QT_VERSION >= 0x030101 QCheckListItem( parent, after, "", type ) #else QCheckListItem( parent, "", type ) #endif { - update(); + update(); } OB_CheckListItem::~OB_CheckListItem() diff --git a/src/ObjBrowser/OB_ListItem.h b/src/ObjBrowser/OB_ListItem.h index 6b06cd842..112c3c8c9 100755 --- a/src/ObjBrowser/OB_ListItem.h +++ b/src/ObjBrowser/OB_ListItem.h @@ -33,7 +33,7 @@ class SUIT_DataObject; template class ListItemF { public: - ListItemF(T&, SUIT_DataObject* ); + ListItemF( T*, SUIT_DataObject* ); /*ListItem( SUIT_DataObject*, QListView* ); ListItem( SUIT_DataObject*, QListViewItem* ); ListItem( SUIT_DataObject*, QListView*, QListViewItem* ); @@ -49,12 +49,12 @@ public: void paintFoc( QPainter* p, QColorGroup& cg, const QRect& r ); void paintC( QPainter* p, QColorGroup& cg, int c, int w, int align ); -protected: +//protected: void update(); protected: SUIT_DataObject* myObject; - T& myT; + T* myT; }; /* diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index 67933dbae..30a25e808 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -593,6 +593,7 @@ void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update ) { if ( !curve ) return; + // san -- Protection against QwtCurve bug in Qwt 0.4.x: // it crashes if switched to X/Y logarithmic mode, when one or more points have // non-positive X/Y coordinate @@ -601,7 +602,6 @@ void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update ) if ( myYMode && curve->getMinY() <= 0. ) setVerScaleMode( 0, false ); - if ( hasCurve( curve ) ) { updateCurve( curve, update ); } @@ -1330,10 +1330,8 @@ void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update ) } myXMode = mode; - if ( myXMode == 0 ) // linear - myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false ); - else // logarithmic - myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, true ); + + myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, myXMode != 0 ); if ( update ) fitAll(); @@ -1353,16 +1351,10 @@ void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update ) } myYMode = mode; - if ( myYMode == 0 ) { // linear - myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false ); - if (mySecondY) - myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false ); - } - else { // logarithmic - myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, true ); - if (mySecondY) - myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, true ); - } + myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, myYMode != 0 ); + if (mySecondY) + myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, myYMode != 0 ); + if ( update ) fitAll(); emit vpModeVerChanged(); diff --git a/src/Plot2d/resources/Plot2d_msg_en.po b/src/Plot2d/resources/Plot2d_msg_en.po index a646152b5..055cd5f4c 100755 --- a/src/Plot2d/resources/Plot2d_msg_en.po +++ b/src/Plot2d/resources/Plot2d_msg_en.po @@ -150,6 +150,15 @@ msgstr "Error" msgid "BUT_OK" msgstr "Ok" +msgid "WARNING" +msgstr "Warning" + +msgid "WRN_XLOG_NOT_ALLOWED" +msgstr "Some points with non-positive abscissa values have been detected.\nLogarithmic scale for abscissa axis is not allowed." + +msgid "WRN_YLOG_NOT_ALLOWED" +msgstr "Some points with non-positive ordinate values have been detected.\nLogarithmic scale for ordinate axis is not allowed." + # ------------------------------------ # Plot2d_SetupViewDlg # ------------------------------------ diff --git a/src/QDS/QDS_CheckBox.cxx b/src/QDS/QDS_CheckBox.cxx index 7f1924d97..ded537716 100644 --- a/src/QDS/QDS_CheckBox.cxx +++ b/src/QDS/QDS_CheckBox.cxx @@ -18,12 +18,23 @@ QDS_CheckBox::~QDS_CheckBox() { } +/*! + Sets the state "NoChange" for checkbox. +*/ +void QDS_CheckBox::clear() +{ + setStringValue( "-1" ); +} + /*! Returns string from QCheckBox widget. */ QString QDS_CheckBox::getString() const { - return checkBox() && checkBox()->isChecked() ? "1" : "0"; + QString val; + if ( checkBox() && checkBox()->state() != QButton::NoChange ) + val = checkBox()->isChecked() ? "1" : "0"; + return val; } /*! @@ -31,9 +42,17 @@ QString QDS_CheckBox::getString() const */ void QDS_CheckBox::setString( const QString& txt ) { + if ( !checkBox() ) + return; + bool isOk; int val = (int)txt.toDouble( &isOk ); - if ( checkBox() ) + if ( isOk && val < 0 ) + { + checkBox()->setTristate(); + checkBox()->setNoChange(); + } + else checkBox()->setChecked( isOk && val != 0 ); } @@ -53,6 +72,7 @@ QWidget* QDS_CheckBox::createControl( QWidget* parent ) QCheckBox* cb = new QCheckBox( parent ); connect( cb, SIGNAL( stateChanged( int ) ), SLOT( onParamChanged() ) ); connect( cb, SIGNAL( toggled( bool ) ), SIGNAL( toggled( bool ) ) ); + connect( cb, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged( int ) ) ); return cb; } @@ -64,6 +84,12 @@ void QDS_CheckBox::onParamChanged() emit paramChanged(); } +void QDS_CheckBox::onStateChanged( int state ) +{ + if ( state != QButton::NoChange && checkBox() ) + checkBox()->setTristate( false ); +} + void QDS_CheckBox::setChecked( const bool theState ) { if ( checkBox() ) diff --git a/src/QDS/QDS_CheckBox.h b/src/QDS/QDS_CheckBox.h index 7c04edaad..8b1344b93 100644 --- a/src/QDS/QDS_CheckBox.h +++ b/src/QDS/QDS_CheckBox.h @@ -16,11 +16,14 @@ public: bool isChecked() const; void setChecked( const bool ); + virtual void clear(); + signals: void toggled( bool ); private slots: void onParamChanged(); + void onStateChanged( int ); protected: QCheckBox* checkBox() const; diff --git a/src/QDS/QDS_ComboBox.cxx b/src/QDS/QDS_ComboBox.cxx index f5e9ef80b..fac69b6b4 100644 --- a/src/QDS/QDS_ComboBox.cxx +++ b/src/QDS/QDS_ComboBox.cxx @@ -98,6 +98,8 @@ int QDS_ComboBox::integerValue() const */ double QDS_ComboBox::doubleValue() const { + initDatum(); + QComboBox* cb = comboBox(); QString cur = getString(); if ( cb && cb->count() > 0 && cb->currentItem() >= 0 ) @@ -114,6 +116,8 @@ double QDS_ComboBox::doubleValue() const */ void QDS_ComboBox::setIntegerValue( const int id ) { + initDatum(); + if ( myValue.contains( id ) ) setString( myValue[id] ); else @@ -125,6 +129,8 @@ void QDS_ComboBox::setIntegerValue( const int id ) */ void QDS_ComboBox::setDoubleValue( const double val ) { + initDatum(); + int id = (int)val; if ( myValue.contains( id ) ) setString( myValue[id] ); @@ -166,6 +172,8 @@ void QDS_ComboBox::setState( const bool on, const int id, const bool append ) */ void QDS_ComboBox::setState( const bool on, const QValueList& ids, const bool append ) { + initDatum(); + if ( ids.isEmpty() && append ) return; @@ -200,6 +208,8 @@ void QDS_ComboBox::setState( const bool on, const QValueList& ids, const bo */ void QDS_ComboBox::setValues( const QValueList& ids, const QStringList& names ) { + initDatum(); + if ( ids.count() != names.count() ) return; @@ -214,6 +224,8 @@ void QDS_ComboBox::setValues( const QValueList& ids, const QStringList& nam */ void QDS_ComboBox::setValues( const QStringList& names ) { + initDatum(); + QValueList< int > ids; for ( int i = 0, n = names.count(); i < n; i++ ) ids.append( i ); diff --git a/src/QDS/QDS_Datum.cxx b/src/QDS/QDS_Datum.cxx index ff3ed8aca..f7a76b649 100644 --- a/src/QDS/QDS_Datum.cxx +++ b/src/QDS/QDS_Datum.cxx @@ -43,6 +43,7 @@ myWid( 0 ) { QHBoxLayout* base = new QHBoxLayout( this ); base->setAutoAdd( true ); + setFocusPolicy( StrongFocus ); } QDS_Datum::Wrapper::~Wrapper() @@ -70,6 +71,7 @@ void QDS_Datum::Wrapper::setWidget( QWidget* wid ) if ( myWid->parent() != this ) myWid->reparent( this, QPoint( 0, 0 ) ); + setTabOrder( this, myWid ); setFocusProxy( myWid ); myWid->updateGeometry(); @@ -154,6 +156,11 @@ QDS_Datum::~QDS_Datum() */ } +QDS_Datum::operator QWidget*() const +{ + return widget( Control ); +} + QString QDS_Datum::id() const { initDatum(); @@ -241,8 +248,8 @@ QString QDS_Datum::minimumValue() const initDatum(); QString min; - if ( !myDicItem.IsNull() ) - min = format( format(), type(), myDicItem->GetMinValue() ); + if ( !myDicItem.IsNull() && myDicItem->HasData( DDS_DicItem::MinValue ) ) + min = format( format(), type(), myDicItem->GetMinValue() ); return min; } @@ -251,7 +258,7 @@ QString QDS_Datum::maximumValue() const initDatum(); QString max; - if ( !myDicItem.IsNull() ) + if ( !myDicItem.IsNull() && myDicItem->HasData( DDS_DicItem::MaxValue ) ) max = format( format(), type(), myDicItem->GetMaxValue() ); return max; } @@ -276,6 +283,14 @@ QString QDS_Datum::shortDescription() const return sdStr; } +QVariant QDS_Datum::value() const +{ + QVariant val; + if ( !isEmpty() ) + val = stringValue(); + return val; +} + QString QDS_Datum::stringValue() const { initDatum(); @@ -375,6 +390,14 @@ void QDS_Datum::clear() } } +void QDS_Datum::setValue( const QVariant& val ) +{ + if ( val.isValid() && val.canCast( QVariant::String ) ) + setStringValue( val.toString() ); + else + clear(); +} + void QDS_Datum::setStringValue( const QString& txt ) { initDatum(); @@ -541,10 +564,15 @@ bool QDS_Datum::isValid( const bool msgBox, const QString& extMsg, const QString if ( type() == DDS_DicItem::String && isDoubleFormat( format() ) ) return true; + QString req; + if ( !dicItem().IsNull() ) + req = toQString( dicItem()->GetRequired() ); + bool aState = true; QString aStr = getString(); + if ( aStr.isEmpty() ) - aState = false; + aState = !( req == QString( "yes" ) || req == QString( "true" ) || req.toInt() ); else aState = validate( aStr ); @@ -604,7 +632,7 @@ bool QDS_Datum::isValid( const bool msgBox, const QString& extMsg, const QString info = QString( "

%1

" ).arg( msg ); QMessageBox::critical( controlWidget() ? controlWidget()->topLevelWidget() : 0, - tr( "DATA_ERR_TITLE" ), info, tr( "BUT_OK" ) ); + tr( "DATA_ERR_TITLE" ), info, tr( "OK" ) ); if ( controlWidget() ) controlWidget()->setFocus(); } diff --git a/src/QDS/QDS_Datum.h b/src/QDS/QDS_Datum.h index be0247441..3a1a92985 100644 --- a/src/QDS/QDS_Datum.h +++ b/src/QDS/QDS_Datum.h @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -41,6 +42,8 @@ public: QString minimumValue() const; QString maximumValue() const; + virtual QVariant value() const; + virtual QString stringValue() const; virtual double doubleValue() const; virtual int integerValue() const; @@ -52,6 +55,8 @@ public: virtual void reset(); virtual void clear(); + virtual void setValue( const QVariant& ); + virtual void setStringValue( const QString& ); virtual void setDoubleValue( const double ); virtual void setIntegerValue( const int ); @@ -87,6 +92,8 @@ public: virtual bool eventFilter( QObject*, QEvent* ); + operator QWidget*() const; + signals: void paramChanged(); void paramChanged( QString& ); @@ -137,9 +144,10 @@ protected: virtual void unitSystemChanged( const QString& ); + void initDatum() const; + private: void initialize(); - void initDatum() const; Wrapper* wrapper( QWidget* ) const; Wrapper* wrapper( const int ) const; diff --git a/src/QDS/QDS_LineEdit.h b/src/QDS/QDS_LineEdit.h index 883d38cb7..ec9ad48a2 100644 --- a/src/QDS/QDS_LineEdit.h +++ b/src/QDS/QDS_LineEdit.h @@ -28,8 +28,8 @@ private slots: void onTextChanged( const QString& ); protected: - QLineEdit* lineEdit() const; virtual QWidget* createControl( QWidget* ); + QLineEdit* lineEdit() const; virtual QString getString() const; virtual void setString( const QString& ); diff --git a/src/QDS/QDS_RadioBox.cxx b/src/QDS/QDS_RadioBox.cxx new file mode 100644 index 000000000..1b3350fb3 --- /dev/null +++ b/src/QDS/QDS_RadioBox.cxx @@ -0,0 +1,379 @@ +#include "QDS_RadioBox.h" + +#include + +#include +#include +#include + +#include +#include +#include + +/*! + Constructor. +*/ +QDS_RadioBox::QDS_RadioBox( const QString& id, QWidget* parent, const int flags, const QString& comp ) +: QDS_Datum( id, parent, flags & ~( Label | Units ), comp ) +{ +} + +/*! + Destructor. +*/ +QDS_RadioBox::~QDS_RadioBox() +{ +} + +/*! + Returns number of items in ComboBox. If total is 'false' then only + visible items are taken into account otherwise all items. +*/ +int QDS_RadioBox::count( bool total ) const +{ + if ( total ) + return myValue.count(); + else + { + QPtrList bList; + buttons( bList ); + return bList.count(); + } +} + +/*! + Returns list of ids. If total is 'false' then only visible items + are taken into account otherwise all items. +*/ +void QDS_RadioBox::values( QValueList& ids, bool total ) const +{ + ids.clear(); + for ( QIntList::const_iterator it = myDataIds.begin(); it != myDataIds.end(); ++it ) + if ( total || ( myState.contains( *it ) && myState[*it] ) ) + ids.append( *it ); +} + +/*! + Returns visible state of identificator. +*/ +bool QDS_RadioBox::state( const int id ) const +{ + bool state = false; + if ( myState.contains( id ) ) + state = myState[id]; + return state; +} + +/*! + Sets the visible state of identificator. If 'id' is -1 then specified + state will be set to all ids. +*/ +void QDS_RadioBox::setState( const bool on, const int id, const bool append ) +{ + QValueList lst; + if ( id < 0 ) + { + for ( IdStateMap::Iterator it = myState.begin(); it != myState.end(); ++it ) + lst.append( it.key() ); + } + else + lst.append( id ); + + setState( on, lst, append ); +} + +/*! + Sets the visible state of identificator from the specified list. +*/ +void QDS_RadioBox::setState( const bool on, const QValueList& ids, const bool append ) +{ + if ( ids.isEmpty() && append ) + return; + + bool changed = false; + + QMap aMap; + for ( uint i = 0; i < ids.count(); i++ ) + aMap.insert( *ids.at( i ), 0 ); + + for ( IdStateMap::Iterator it = myState.begin(); it != myState.end(); ++it ) + { + if ( aMap.contains( it.key() ) ) + { + if ( it.data() != on ) + { + it.data() = on; + changed = true; + } + } + else if ( !append && it.data() == on ) + { + it.data() = !on; + changed = true; + } + } + if ( changed ) + updateRadioBox(); +} + +/*! + Sets the user items into the combo box. +*/ +void QDS_RadioBox::setValues( const QValueList& ids, const QStringList& names ) +{ + if ( ids.count() != names.count() ) + return; + + myUserIds = ids; + myUserNames = names; +} + +/*! + This is an overloaded member function, provided for convenience. + It behaves essentially like the above function. It creates + QValueList (0, 1, 2 ... ) and call previous method +*/ +void QDS_RadioBox::setValues( const QStringList& names ) +{ + QValueList< int > ids; + for ( int i = 0, n = names.count(); i < n; i++ ) + ids.append( i ); + setValues( ids, names ); +} + +/*! + Returns string from control. +*/ +QString QDS_RadioBox::getString() const +{ + QString res; + QButtonGroup* bg = buttonGroup(); + if ( bg ) + { + int id = bg->selectedId(); + if ( id != -1 ) + res = QString::number( id ); + } + return res; +} + +/*! + Sets the string into control. +*/ +void QDS_RadioBox::setString( const QString& txt ) +{ + QButtonGroup* bg = buttonGroup(); + if ( !bg ) + return; + + int oldId = bg->selectedId(); + + if ( txt.isEmpty() ) + { + QPtrList bList; + buttons( bList ); + for ( QPtrListIterator it( bList ); it.current(); ++it ) + it.current()->setChecked( false ); + } + else + { + bool ok; + int id = txt.toInt( &ok ); + if ( !ok ) + id = -1; + + bool block = signalsBlocked(); + blockSignals( true ); + bg->setButton( id ); + blockSignals( block ); + } + + int newId = bg->selectedId(); + + if ( oldId != newId ) + { + onParamChanged(); + QString str = getString(); + emit activated( newId ); + emit paramChanged(); + emit paramChanged( str ); + } +} + +/*! + Returns pointer to QButtonGroup widget. +*/ +QButtonGroup* QDS_RadioBox::buttonGroup() const +{ + return ::qt_cast( controlWidget() ); +} + +/*! + Create QComboBox widget as control subwidget. +*/ +QWidget* QDS_RadioBox::createControl( QWidget* parent ) +{ + QButtonGroup* bg = new QButtonGroup( 1, Qt::Vertical, "", parent ); + bg->setExclusive( true ); + bg->setRadioButtonExclusive( true ); + return bg; +} + +void QDS_RadioBox::unitSystemChanged( const QString& system ) +{ + QDS_Datum::unitSystemChanged( system ); + + Handle(TColStd_HArray1OfInteger) anIds; + Handle(TColStd_HArray1OfExtendedString) aValues, anIcons; + + Handle(DDS_DicItem) aDicItem = dicItem(); + if ( !aDicItem.IsNull() ) + aDicItem->GetListOfValues( aValues, anIds, anIcons ); + + myValue.clear(); + myDataIds.clear(); + + QMap userMap; + QIntList::iterator iIt = myUserIds.begin(); + QStringList::iterator sIt = myUserNames.begin(); + for ( ; iIt != myUserIds.end() && sIt != myUserNames.end(); ++iIt, ++sIt ) + userMap.insert( *iIt, *sIt ); + + if ( !anIds.IsNull() && !aValues.IsNull() && + anIds->Length() == aValues->Length() ) + { + for ( int i = anIds->Lower(); i <= anIds->Upper(); i++ ) + { + QString aValue; + int id = anIds->Value( i ); + if ( userMap.contains( id ) ) + aValue = userMap[id]; + else + aValue = toQString( aValues->Value( i ) ); + + myDataIds.append( id ); + myValue.insert( id, aValue ); + myState.insert( id, true ); + } + } + + for ( iIt = myUserIds.begin(); iIt != myUserIds.end(); ++iIt ) + { + int id = *iIt; + if ( !myValue.contains( id ) ) + { + myDataIds.append( id ); + myValue.insert( id, userMap[id] ); + } + } + + QIntList del, add; + for ( IdStateMap::Iterator it1 = myState.begin(); it1 != myState.end(); ++it1 ) + if ( !myValue.contains( it1.key() ) ) + del.append( it1.key() ); + + for ( IdValueMap::Iterator it2 = myValue.begin(); it2 != myValue.end(); ++it2 ) + if ( !myState.contains( it2.key() ) ) + add.append( it2.key() ); + + for ( QIntList::iterator iter1 = del.begin(); iter1 != del.end(); ++iter1 ) + myState.remove( *iter1 ); + + for ( QIntList::iterator iter2 = add.begin(); iter2 != add.end(); ++iter2 ) + myState.insert( *iter2, true ); + + QButtonGroup* bg = buttonGroup(); + if ( bg ) + bg->setTitle( label() ); + + updateRadioBox(); +} + +/*! + Notify about state changed in line edit of RadioBox. +*/ +void QDS_RadioBox::onToggled( bool on ) +{ + if ( !on ) + return; + + onParamChanged(); + emit paramChanged(); + QString str = getString(); + emit paramChanged( str ); +} + +/*! + Updates RadioBox after have change of visible state or items have been inserted / removed. +*/ +void QDS_RadioBox::updateRadioBox() +{ + QButtonGroup* bg = buttonGroup(); + if ( !bg ) + return; + + int curId = bg->selectedId(); + + QPtrList bList; + buttons( bList ); + for ( QPtrListIterator itr( bList ); itr.current(); ++itr ) + delete itr.current(); + + for ( QIntList::const_iterator it = myDataIds.begin(); it != myDataIds.end(); ++it ) + { + int id = *it; + if ( !myValue.contains( id ) || !myState.contains( id ) || !myState[id] ) + continue; + + QRadioButton* rb = new QRadioButton( myValue[id], bg ); + bg->insert( rb, id ); + + connect( rb, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) ); + } + + if ( curId != -1 ) + { + int id = curId; + if ( !bg->find( id ) ) + { + QPtrList bList; + buttons( bList ); + if ( !bList.isEmpty() ) + id = bg->id( bList.getFirst() ); + } + + bool block = signalsBlocked(); + blockSignals( true ); + bg->setButton( id ); + blockSignals( block ); + } + + if ( curId != bg->selectedId() ) + { + onParamChanged(); + emit paramChanged(); + emit paramChanged( getString() ); + } +} + +void QDS_RadioBox::buttons( QPtrList& lst ) const +{ + lst.setAutoDelete( false ); + lst.clear(); + + QButtonGroup* bg = buttonGroup(); + if ( !bg ) + return; + + QObjectList* objs = bg->queryList( "QRadioButton" ); + if ( objs ) + { + for ( QObjectListIt it( *objs ); it.current(); ++it ) + { + QRadioButton* rb = ::qt_cast( it.current() ); + if ( rb ) + lst.append( rb ); + } + } + delete objs; +} diff --git a/src/QDS/QDS_RadioBox.h b/src/QDS/QDS_RadioBox.h new file mode 100644 index 000000000..769a537ed --- /dev/null +++ b/src/QDS/QDS_RadioBox.h @@ -0,0 +1,75 @@ +#ifndef QDS_RADIOBOX_H +#define QDS_RADIOBOX_H + +#include "QDS_Datum.h" + +#include + +#include +#include +#include + +#ifdef WNT +#pragma warning( disable:4251 ) +#endif + +class QButtonGroup; +class QRadioButton; + +class QDS_EXPORT QDS_RadioBox : public QDS_Datum +{ + Q_OBJECT + +public: + QDS_RadioBox( const QString&, QWidget* = 0, const int = All, const QString& = QString::null ); + virtual ~QDS_RadioBox(); + + int count( bool = false ) const; + void values( QValueList&, bool = false ) const; + + int columns() const; + void setColumns( const int ); + + bool state( const int ) const; + void setState( const bool, const int, const bool = true ); + void setState( const bool, const QValueList&, const bool = true ); + void setValues( const QValueList&, const QStringList& ); + void setValues( const QStringList& ); + +signals: + void activated( int ); + +protected slots: + virtual void onToggled( bool ); + +protected: + QButtonGroup* buttonGroup() const; + virtual QWidget* createControl( QWidget* ); + void buttons( QPtrList& ) const; + + virtual QString getString() const; + virtual void setString( const QString& ); + + virtual void unitSystemChanged( const QString& ); + +private: + void updateRadioBox(); + +private: + typedef QMap IdValueMap; + typedef QMap IdStateMap; + +private: + IdValueMap myValue; + IdStateMap myState; + + QIntList myDataIds; + QIntList myUserIds; + QStringList myUserNames; +}; + +#ifdef WNT +#pragma warning( default:4251 ) +#endif + +#endif diff --git a/src/QDS/QDS_SpinBox.cxx b/src/QDS/QDS_SpinBox.cxx index d25322c3f..b77aa8ba0 100644 --- a/src/QDS/QDS_SpinBox.cxx +++ b/src/QDS/QDS_SpinBox.cxx @@ -1,6 +1,7 @@ #include "QDS_SpinBox.h" -#include +#include + #include /*! @@ -24,8 +25,8 @@ QDS_SpinBox::~QDS_SpinBox() QString QDS_SpinBox::getString() const { QString res; - QSpinBox* aSpinBox = spinBox(); - if ( aSpinBox ) + QtxIntSpinBox* aSpinBox = spinBox(); + if ( aSpinBox && !aSpinBox->isCleared() ) { res = aSpinBox->text(); if ( !aSpinBox->suffix().isEmpty() ) @@ -41,16 +42,20 @@ QString QDS_SpinBox::getString() const */ void QDS_SpinBox::setString( const QString& txt ) { - if ( spinBox() ) + if ( !spinBox() ) + return; + + spinBox()->setCleared( txt.isEmpty() ); + if ( !txt.isEmpty() ) spinBox()->setValue( txt.toInt() ); } /*! Returns pointer to QSpinBox widget. */ -QSpinBox* QDS_SpinBox::spinBox() const +QtxIntSpinBox* QDS_SpinBox::spinBox() const { - return ::qt_cast( controlWidget() ); + return ::qt_cast( controlWidget() ); } /*! @@ -58,7 +63,7 @@ QSpinBox* QDS_SpinBox::spinBox() const */ QWidget* QDS_SpinBox::createControl( QWidget* parent ) { - QSpinBox* aSpinBox = new QSpinBox( parent ); + QtxIntSpinBox* aSpinBox = new QtxIntSpinBox( parent ); aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); connect( aSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged( int ) ) ); return aSpinBox; diff --git a/src/QDS/QDS_SpinBox.h b/src/QDS/QDS_SpinBox.h index d6490edbf..f018ddfb8 100644 --- a/src/QDS/QDS_SpinBox.h +++ b/src/QDS/QDS_SpinBox.h @@ -3,7 +3,7 @@ #include "QDS_Datum.h" -class QSpinBox; +class QtxIntSpinBox; class QDS_EXPORT QDS_SpinBox : public QDS_Datum { @@ -20,7 +20,7 @@ private slots: void onValueChanged( int ); protected: - QSpinBox* spinBox() const; + QtxIntSpinBox* spinBox() const; virtual QWidget* createControl( QWidget* ); diff --git a/src/QDS/QDS_SpinBoxDbl.cxx b/src/QDS/QDS_SpinBoxDbl.cxx index 42d1e2f9e..8a4160e70 100644 --- a/src/QDS/QDS_SpinBoxDbl.cxx +++ b/src/QDS/QDS_SpinBoxDbl.cxx @@ -28,7 +28,7 @@ QString QDS_SpinBoxDbl::getString() const { QString res; QtxDblSpinBox* sb = spinBox(); - if ( sb ) + if ( sb && !sb->isCleared() ) { bool hasFocus = sb->hasFocus(); if ( hasFocus ) @@ -52,12 +52,16 @@ QString QDS_SpinBoxDbl::getString() const */ void QDS_SpinBoxDbl::setString( const QString& txt ) { - if ( spinBox() ) + if ( !spinBox() ) + return; + + spinBox()->setCleared( txt.isEmpty() ); + if ( !txt.isEmpty() ) spinBox()->setValue( txt.toDouble() ); } /*! - Returns pointer to XMLGUI_SpinBoxDbl widget. + Returns pointer to QtxDblSpinBox widget. */ QtxDblSpinBox* QDS_SpinBoxDbl::spinBox() const { @@ -130,6 +134,6 @@ void QDS_SpinBoxDbl::unitSystemChanged( const QString& system ) sb->setPrecision( aPreci ); sb->setLineStep( .1 ); - sb->setMinValue( minValue().toDouble() ); - sb->setMaxValue( maxValue().toDouble() ); + sb->setMinValue( minValue().isEmpty() ? -DBL_MAX : minValue().toDouble() ); + sb->setMaxValue( maxValue().isEmpty() ? DBL_MAX : maxValue().toDouble() ); } diff --git a/src/Qtx/Makefile.in b/src/Qtx/Makefile.in index 0a92974f9..aa682b59d 100755 --- a/src/Qtx/Makefile.in +++ b/src/Qtx/Makefile.in @@ -48,7 +48,8 @@ EXPORT_HEADERS= Qtx.h \ QtxWorkstack.h \ QtxResourceEdit.h \ QtxListView.h \ - QtxDirListEditor.h + QtxDirListEditor.h \ + QtxDblValidator.h # .po files to transform in .qm @@ -95,7 +96,8 @@ LIB_SRC= \ QtxResourceEdit.cxx \ QtxWorkstack.cxx \ QtxListView.cxx \ - QtxDirListEditor.cxx + QtxDirListEditor.cxx \ + QtxDblValidator.cxx LIB_MOC = \ QtxAction.h \ @@ -127,7 +129,8 @@ LIB_MOC = \ QtxWorkstack.h \ QtxListView.h \ QtxListResourceEdit.h \ - QtxDirListEditor.h + QtxDirListEditor.h \ + QtxDblValidator.h RESOURCES_FILES = \ diff --git a/src/Qtx/QtxActionMenuMgr.cxx b/src/Qtx/QtxActionMenuMgr.cxx index d49bbf482..7782a7b57 100644 --- a/src/Qtx/QtxActionMenuMgr.cxx +++ b/src/Qtx/QtxActionMenuMgr.cxx @@ -143,7 +143,7 @@ myMenu( mw ) QtxActionMenuMgr::~QtxActionMenuMgr() { - for ( NodeListIterator it( myRoot.children ); it.current(); ++it ) + for ( NodeListIterator it( myRoot.children ); it.current() && myMenu; ++it ) { QAction* a = itemAction( it.current()->id ); if ( !a ) diff --git a/src/Qtx/QtxActionMgr.h b/src/Qtx/QtxActionMgr.h index 4cd9f2e38..60fc342c0 100644 --- a/src/Qtx/QtxActionMgr.h +++ b/src/Qtx/QtxActionMgr.h @@ -26,6 +26,7 @@ #include #include +#include class QAction; class QDomNode; @@ -81,7 +82,8 @@ protected: int generateId() const; private: - typedef QMap ActionMap; + typedef QGuardedPtr ActionPtr; + typedef QMap ActionMap; private: bool myUpdate; diff --git a/src/Qtx/QtxDblSpinBox.cxx b/src/Qtx/QtxDblSpinBox.cxx index 081259255..b10c28bd6 100755 --- a/src/Qtx/QtxDblSpinBox.cxx +++ b/src/Qtx/QtxDblSpinBox.cxx @@ -25,6 +25,8 @@ #include #include +#include + /* Class: QtxDblSpinBox::Validator [internal] Descr: Validator for QtxDblSpinBox (getted from Trolltech Qt - SpinBoxValidator) @@ -93,10 +95,10 @@ myCleared( false ), myBlocked( false ), myPrecision( 0 ) { - myMin = QRangeControl::minValue(); - myMax = QRangeControl::maxValue(); + myMin = -DBL_MAX; + myMax = DBL_MAX; myStep = QRangeControl::lineStep(); - myValue = myMin; + myValue = 0; setValidator( new Validator( this, "double_spinbox_validator" ) ); rangeChange(); updateDisplay(); diff --git a/src/Qtx/QtxDblValidator.cxx b/src/Qtx/QtxDblValidator.cxx new file mode 100644 index 000000000..2769fd406 --- /dev/null +++ b/src/Qtx/QtxDblValidator.cxx @@ -0,0 +1,47 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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/ +// +// File: QtxDblValidator.cxx +// Author: Alexandre SOLOVYOV + +#include "QtxDblValidator.h" + +QtxDblValidator::QtxDblValidator( const double bot, const double top, const int dec, + QObject* o, const char* name ) +: QDoubleValidator( bot, top, dec, o, name ) +{ +} + +QtxDblValidator::~QtxDblValidator() +{ +} + +void QtxDblValidator::fixup( QString& str ) const +{ + bool ok = false; + double d = str.toDouble( &ok ); + if( ok ) + { + if( dtop() ) + str = QString::number( top() ); + } + else + str = "0"; +} diff --git a/src/Qtx/QtxDblValidator.h b/src/Qtx/QtxDblValidator.h new file mode 100644 index 000000000..bae6c03ea --- /dev/null +++ b/src/Qtx/QtxDblValidator.h @@ -0,0 +1,39 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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/ +// +// File: QtxDblValidator.h +// Author: Alexandre SOLOVYOV + +#ifndef QTX_DOUBLE_VALIDATOR +#define QTX_DOUBLE_VALIDATOR + +#include + +class QtxDblValidator : public QDoubleValidator +{ + Q_OBJECT + +public: + QtxDblValidator( const double, const double, const int, + QObject*, const char* = 0 ); + ~QtxDblValidator(); + + virtual void fixup( QString& ) const; +}; + +#endif diff --git a/src/Qtx/QtxDialog.cxx b/src/Qtx/QtxDialog.cxx index bf827df57..347479e55 100755 --- a/src/Qtx/QtxDialog.cxx +++ b/src/Qtx/QtxDialog.cxx @@ -236,7 +236,7 @@ void QtxDialog::Area::layoutButtons() center.append( it.current() ); } - delete layout(); + delete layout(); QBoxLayout* buttonLayout = 0; if ( myOrientation == Qt::Vertical ) @@ -267,6 +267,22 @@ void QtxDialog::Area::layoutButtons() buttonLayout->addStretch( 1 ); } } + + QWidgetList wids; + if ( layout() ) + { + for ( QLayoutIterator it = layout()->iterator(); it.current(); ++it ) + { + if ( !it.current()->widget() ) + continue; + + if ( QApplication::reverseLayout() ) + wids.prepend( it.current()->widget() ); + else + wids.append( it.current()->widget() ); + } + } + Qtx::setTabOrder( wids ); } /*! diff --git a/src/Qtx/QtxListResourceEdit.cxx b/src/Qtx/QtxListResourceEdit.cxx index 75e74e998..60a5fbe4c 100644 --- a/src/Qtx/QtxListResourceEdit.cxx +++ b/src/Qtx/QtxListResourceEdit.cxx @@ -168,6 +168,8 @@ void QtxListResourceEdit::updateState() myStack->show(); else myStack->hide(); + + myList->setShown( myList->count() > 1 ); } void QtxListResourceEdit::updateVisible() diff --git a/src/Qtx/QtxMRUAction.h b/src/Qtx/QtxMRUAction.h index 12a87e024..debd6bdfb 100755 --- a/src/Qtx/QtxMRUAction.h +++ b/src/Qtx/QtxMRUAction.h @@ -38,9 +38,11 @@ class QTX_EXPORT QtxMRUAction : public QtxAction { Q_OBJECT + Q_PROPERTY( int visibleCount READ visibleCount WRITE setVisibleCount ) + public: - typedef enum { Items, SubMenu } PopupMode; - typedef enum { MoveFirst, MoveLast, AddFirst, AddLast } InsertMode; + enum { Items, SubMenu }; + enum { MoveFirst, MoveLast, AddFirst, AddLast }; public: QtxMRUAction( QObject* = 0, const char* = 0 ); diff --git a/src/Qtx/QtxResourceEdit.cxx b/src/Qtx/QtxResourceEdit.cxx index e1c9e7538..e499236ff 100644 --- a/src/Qtx/QtxResourceEdit.cxx +++ b/src/Qtx/QtxResourceEdit.cxx @@ -35,8 +35,13 @@ QtxResourceEdit::QtxResourceEdit( QtxResourceMgr* mgr ) QtxResourceEdit::~QtxResourceEdit() { + ItemMap items; for ( ItemMap::ConstIterator it = myItems.begin(); it != myItems.end(); ++it ) - delete it.data(); + items.insert( it.key(), it.data() ); + + for ( ItemMap::ConstIterator itr = items.begin(); itr != items.end(); ++itr ) + if ( myItems.contains( itr.key() ) ) + delete itr.data(); } QtxResourceMgr* QtxResourceEdit::resourceMgr() const diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index 29e178a19..d5376b7e0 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -36,8 +36,9 @@ Level: Internal */ -QtxResourceMgr::Resources::Resources( const QString& fileName ) -: myFileName( fileName ) +QtxResourceMgr::Resources::Resources( const QtxResourceMgr* mgr, const QString& fileName ) +: myFileName( fileName ), + myMgr( const_cast( mgr ) ) { } @@ -130,6 +131,11 @@ QString QtxResourceMgr::Resources::path( const QString& sec, const QString& pref return filePath; } +QtxResourceMgr* QtxResourceMgr::Resources::resMgr() const +{ + return myMgr; +} + QtxResourceMgr::Section& QtxResourceMgr::Resources::section( const QString& sn ) { if ( !mySections.contains( sn ) ) @@ -157,12 +163,30 @@ QString QtxResourceMgr::Resources::fileName( const QString& sect, const QString& path = Qtx::addSlash( path ) + name; } } - return QDir::convertSeparators( path ); + if( !path.isEmpty() ) + { + QString fname = QDir::convertSeparators( path ); + QFileInfo inf( fname ); + fname = inf.absFilePath(); + return fname; + } + return QString(); } QPixmap QtxResourceMgr::Resources::loadPixmap( const QString& sect, const QString& prefix, const QString& name ) const { - return QPixmap( fileName( sect, prefix, name ) ); + QString fname = fileName( sect, prefix, name ); + bool toCache = resMgr() ? resMgr()->isPixmapCached() : false; + QPixmap p; + if( toCache && myPixmapCache.contains( fname ) ) + p = myPixmapCache[fname]; + else + { + p.load( fname ); + if( toCache ) + ( ( QMap& )myPixmapCache ).insert( fname, p ); + } + return p; } QTranslator* QtxResourceMgr::Resources::loadTranslator( const QString& sect, const QString& prefix, const QString& name ) const @@ -639,10 +663,14 @@ bool QtxResourceMgr::Format::save( Resources* res ) function userFileName(). Any resource looking firstly in the user home resources then resource directories used in the specified order. All setted resources always stored into the resource file at the user home. Only user home resource file is saved. + If you want to ignore of loading of Local User Preferences, you needs setup setIngoreUserValues() + as true. */ QtxResourceMgr::QtxResourceMgr( const QString& appName, const QString& resVarTemplate ) : myAppName( appName ), -myCheckExist( true ) + myCheckExist( true ), + myIsPixmapCached( true ), + myIsIgnoreUserValues( false ) { QString envVar = !resVarTemplate.isEmpty() ? resVarTemplate : QString( "%1Resources" ); if ( envVar.contains( "%1" ) ) @@ -721,18 +749,35 @@ void QtxResourceMgr::initialize( const bool autoLoad ) const QtxResourceMgr* that = (QtxResourceMgr*)this; if ( !userFileName( appName() ).isEmpty() ) - that->myResources.append( new Resources( userFileName( appName() ) ) ); + that->myResources.append( new Resources( this, userFileName( appName() ) ) ); for ( QStringList::const_iterator it = myDirList.begin(); it != myDirList.end(); ++it ) { QString path = Qtx::addSlash( *it ) + globalFileName( appName() ); - that->myResources.append( new Resources( path ) ); + that->myResources.append( new Resources( this, path ) ); } if ( autoLoad ) that->load(); } +/*! + \brief Return true if all loaded pixmaps are stored in internal map; by default: true +*/ +bool QtxResourceMgr::isPixmapCached() const +{ + return myIsPixmapCached; +} + +/*! + \brief Set true, if it is necessary to store all loaded pixmap in internal map + (it accelerates following calls of loadPixmap) +*/ +void QtxResourceMgr::setIsPixmapCached( const bool on ) +{ + myIsPixmapCached = on; +} + /*! \brief Removes all resources from the manager. */ @@ -742,6 +787,16 @@ void QtxResourceMgr::clear() it.current()->clear(); } +void QtxResourceMgr::setIgnoreUserValues( const bool val ) +{ + myIsIgnoreUserValues = val; +} + +bool QtxResourceMgr::ignoreUserValues() const +{ + return myIsIgnoreUserValues; +} + /*! \brief Get the resource value as integer. Returns 'true' if it successfull otherwise returns 'false'. @@ -906,7 +961,12 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QString& v initialize(); bool ok = false; - for ( ResListIterator it( myResources ); it.current() && !ok; ++it ) + + ResListIterator it( myResources ); + if ( ignoreUserValues() ) + ++it; + + for ( ; it.current() && !ok; ++it ) { ok = it.current()->hasValue( sect, name ); if ( ok ) diff --git a/src/Qtx/QtxResourceMgr.h b/src/Qtx/QtxResourceMgr.h index 868dc9fde..f75345425 100644 --- a/src/Qtx/QtxResourceMgr.h +++ b/src/Qtx/QtxResourceMgr.h @@ -68,8 +68,14 @@ public: bool checkExisting() const; virtual void setCheckExisting( const bool ); + bool isPixmapCached() const; + void setIsPixmapCached( const bool ); + void clear(); + void setIgnoreUserValues( const bool = true ); + bool ignoreUserValues() const; + bool value( const QString&, const QString&, int& ) const; bool value( const QString&, const QString&, double& ) const; bool value( const QString&, const QString&, bool& ) const; @@ -165,6 +171,9 @@ private: bool myCheckExist; TransListMap myTranslator; QPixmap myDefaultPix; + bool myIsPixmapCached; + + bool myIsIgnoreUserValues; }; /*! @@ -202,7 +211,7 @@ private: class QtxResourceMgr::Resources { public: - Resources( const QString& ); + Resources( const QtxResourceMgr*, const QString& ); virtual ~Resources(); QString file() const; @@ -230,6 +239,9 @@ public: QString path( const QString&, const QString&, const QString& ) const; +protected: + QtxResourceMgr* resMgr() const; + private: Section& section( const QString& ); const Section& section( const QString& ) const; @@ -242,6 +254,8 @@ private: private: SectionMap mySections; QString myFileName; + QMap myPixmapCache; + QtxResourceMgr* myMgr; friend class QtxResourceMgr::Format; }; diff --git a/src/Qtx/QtxToolTip.cxx b/src/Qtx/QtxToolTip.cxx index 0365ba135..5141e127d 100755 --- a/src/Qtx/QtxToolTip.cxx +++ b/src/Qtx/QtxToolTip.cxx @@ -31,7 +31,7 @@ #define TOOLTIP_HIDE_DELAY 7000 QtxToolTip::QtxToolTip( QWidget* parent ) -: QLabel( parent, "", WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WStyle_StaysOnTop | WType_TopLevel ) +: QLabel( parent, "", WStyle_Customize | WStyle_NoBorder | WX11BypassWM | WStyle_Tool | WStyle_StaysOnTop | WType_TopLevel ) { setIndent( 3 ); setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); diff --git a/src/SALOME_PY/SalomePy.cxx b/src/SALOME_PY/SalomePy.cxx index 1013f34cc..69ef49106 100755 --- a/src/SALOME_PY/SalomePy.cxx +++ b/src/SALOME_PY/SalomePy.cxx @@ -42,8 +42,6 @@ #include "SVTK_ViewManager.h" #include "SVTK_ViewWindow.h" -#include "SVTK_RenderWindow.h" -#include "SVTK_RenderWindowInteractor.h" using namespace std; @@ -132,7 +130,7 @@ public: virtual void Execute() { if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow() ) { PyObject* aPyClass = GetPyClass("vtkRenderWindow"); - vtkRenderWindow* aVTKObject = aVTKViewWindow->getRenderWindow()->getRenderWindow(); + vtkRenderWindow* aVTKObject = aVTKViewWindow->getRenderWindow(); myResult = PyVTKObject_New(aPyClass,aVTKObject); } } @@ -153,7 +151,7 @@ public: virtual void Execute() { if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow() ) { PyObject* aPyClass = GetPyClass("vtkRenderWindowInteractor"); - vtkRenderWindowInteractor* aVTKObject = aVTKViewWindow->getRWInteractor(); + vtkRenderWindowInteractor* aVTKObject = aVTKViewWindow->getInteractor(); myResult = PyVTKObject_New(aPyClass,aVTKObject); } } diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 3e955e6c9..a3ab1739e 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -93,7 +93,17 @@ void STD_Application::closeApplication() { if ( desktop() ) savePreferences(); + SUIT_Study* study = activeStudy(); + + if ( study ){ + study->closeDocument(); + + setActiveStudy( 0 ); + delete study; + } + setDesktop( 0 ); + SUIT_Application::closeApplication(); } @@ -112,18 +122,6 @@ void STD_Application::onDesktopClosing( SUIT_Desktop*, QCloseEvent* e ) return; } - SUIT_Study* study = activeStudy(); - - if ( study ) - study->closeDocument(); - - setActiveStudy( 0 ); - delete study; - - savePreferences(); - - setDesktop( 0 ); - closeApplication(); } diff --git a/src/SUIT/Makefile.in b/src/SUIT/Makefile.in index f08c897d0..a6bab14a7 100755 --- a/src/SUIT/Makefile.in +++ b/src/SUIT/Makefile.in @@ -41,7 +41,8 @@ EXPORT_HEADERS= SUIT.h \ SUIT_ViewModel.h \ SUIT_ViewWindow.h \ SUIT_SelectionFilter.h \ - SUIT_Accel.h + SUIT_Accel.h \ + SUIT_TreeSync.h # .po files to transform in .qm PO_FILES = SUIT_images.po \ diff --git a/src/SUIT/SUIT_Application.cxx b/src/SUIT/SUIT_Application.cxx index 4ae8aec86..f187bfabd 100755 --- a/src/SUIT/SUIT_Application.cxx +++ b/src/SUIT/SUIT_Application.cxx @@ -120,16 +120,19 @@ SUIT_ResourceMgr* SUIT_Application::resourceMgr() const #define DEFAULT_MESSAGE_DELAY 3000 void SUIT_Application::putInfo ( const QString& msg, const int msec ) { - if ( desktop() ) { - //desktop()->statusBar()->message( msg, msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec ); - if ( !myStatusLabel ) { - myStatusLabel = new QLabel (desktop()->statusBar()); - desktop()->statusBar()->addWidget(myStatusLabel, /*int stretch = */1); - } - myStatusLabel->setText(msg); - if( msec != -1 ) - QTimer::singleShot(msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec, myStatusLabel, SLOT(clear())); + if ( !desktop() ) + return; + + if ( !myStatusLabel ) + { + myStatusLabel = new QLabel( desktop()->statusBar() ); + desktop()->statusBar()->addWidget( myStatusLabel, 1 ); + myStatusLabel->show(); } + + myStatusLabel->setText( msg ); + if ( msec != -1 ) + QTimer::singleShot( msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec, myStatusLabel, SLOT( clear() ) ); } SUIT_Application* SUIT_Application::startApplication( int argc, char** argv ) const diff --git a/src/SUIT/SUIT_Application.h b/src/SUIT/SUIT_Application.h index 43f6f29ed..b630177e6 100755 --- a/src/SUIT/SUIT_Application.h +++ b/src/SUIT/SUIT_Application.h @@ -56,10 +56,12 @@ public: //! Returns main widget (Desktop) of the application (if it exists) virtual SUIT_Desktop* desktop(); - /*! Returns FALSE if applic ation can not be closed (because of non saved data for example). + /*! Returns FALSE if application can not be closed (because of non saved data for example). This method called by SUIT_Session whin closing of application was requested. */ virtual bool isPossibleToClose(); + /*! Performs some finalization of life cycle of this application. + For instance, the application can force its documents(s) to close. */ virtual void closeApplication(); //! Returns active Study. If Application supports wirking with several studies this method should be redefined diff --git a/src/SUIT/SUIT_DataOwner.h b/src/SUIT/SUIT_DataOwner.h index 8f8caadff..cbc5b8464 100755 --- a/src/SUIT/SUIT_DataOwner.h +++ b/src/SUIT/SUIT_DataOwner.h @@ -25,6 +25,7 @@ #include #ifdef WIN32 +#pragma warning( disable:4251 ) #pragma warning( disable:4275 ) #endif @@ -81,6 +82,7 @@ private: }; #ifdef WIN32 +#pragma warning( default:4251 ) #pragma warning( default:4275 ) #endif diff --git a/src/SUIT/SUIT_FileDlg.cxx b/src/SUIT/SUIT_FileDlg.cxx index 80a6ad589..ec580efd6 100755 --- a/src/SUIT/SUIT_FileDlg.cxx +++ b/src/SUIT/SUIT_FileDlg.cxx @@ -521,3 +521,19 @@ QString SUIT_FileDlg::getExistingDirectory( QWidget* parent, return dirname; } + +/*! + QFileDialog::dirPath() has a bug on Linux Debian (1 level up from correct + directory is returned). This function fixes the bug. +*/ +QString SUIT_FileDlg::dirPath() const +{ + if ( !mySelectedFile.isNull() ) + return QFileInfo( mySelectedFile ).dirPath(); + + const QDir* aDir = dir(); + if ( aDir->exists() ) + return aDir->absPath(); + + return QFileDialog::dirPath(); +} diff --git a/src/SUIT/SUIT_FileDlg.h b/src/SUIT/SUIT_FileDlg.h index bb9ae4e3f..fcdb7da13 100755 --- a/src/SUIT/SUIT_FileDlg.h +++ b/src/SUIT/SUIT_FileDlg.h @@ -45,6 +45,9 @@ public: void setValidator( SUIT_FileValidator* ); + QString dirPath() const; // QFileDialog::dirPath() has a bug on Linux Debian (1 level up from correct + // directory is returned). This redefinition fixes the bug. + static QString getFileName( QWidget* parent, const QString& initial, const QStringList& filters, const QString& caption, const bool open, const bool showQuickDir = true, SUIT_FileValidator* validator = 0 ); diff --git a/src/SUIT/SUIT_Operation.cxx b/src/SUIT/SUIT_Operation.cxx index 11beaef40..658ff2017 100755 --- a/src/SUIT/SUIT_Operation.cxx +++ b/src/SUIT/SUIT_Operation.cxx @@ -416,7 +416,7 @@ void SUIT_Operation::start( SUIT_Operation* op, const bool check ) return; if ( study() ) - study()->start( op, false ); + study()->start( op, check ); else { connect( this, SIGNAL( stopped( SUIT_Operation* ) ), op, SLOT( abort() ) ); diff --git a/src/SUIT/SUIT_Operation.h b/src/SUIT/SUIT_Operation.h index 6d44d9502..4f1b617b9 100755 --- a/src/SUIT/SUIT_Operation.h +++ b/src/SUIT/SUIT_Operation.h @@ -31,10 +31,11 @@ #ifndef SUIT_OPERATION_H #define SUIT_OPERATION_H -#include - #include "SUIT.h" +#include +#include + class SUIT_Study; class SUIT_Application; @@ -54,6 +55,10 @@ class SUIT_Application; * - virtual void resumeOperation(); * - virtual void suspendOperation(); */ +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + class SUIT_EXPORT SUIT_Operation : public QObject { Q_OBJECT @@ -152,14 +157,21 @@ protected: void start( SUIT_Operation*, const bool = false ); +private: + typedef QGuardedPtr StudyPtr; + private: SUIT_Application* myApp; //!< application for this operation int myFlags; //!< operation flags - SUIT_Study* myStudy; //!< study for this operation + StudyPtr myStudy; //!< study for this operation OperationState myState; //!< Operation state ExecStatus myExecStatus; //!< Execution status friend class SUIT_Study; }; +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + #endif diff --git a/src/SUIT/SUIT_TreeSync.h b/src/SUIT/SUIT_TreeSync.h new file mode 100644 index 000000000..d38f6fcdf --- /dev/null +++ b/src/SUIT/SUIT_TreeSync.h @@ -0,0 +1,177 @@ + +#ifndef SUIT_TREE_SYNC_HEADER +#define SUIT_TREE_SYNC_HEADER + +#include +#include + +template +struct DiffItem +{ + SrcItem mySrc; //if it is null, then this item is to deleted + TrgItem myTrg; //if it is null, then this item is to added + //if both fields aren't null, then this item is to update +}; + +template +TrgItem synchronize( const SrcItem&, const TrgItem&, const TreeData& ); + +template +void diffSiblings( const SrcItem&, const TrgItem&, + QValueList < DiffItem < SrcItem,TrgItem > >&, + const TreeData& ); + +template +TrgItem createSubTree( const SrcItem&, const TrgItem&, const TrgItem&, const bool, const TreeData& ); + +template +const typename QValueList::const_iterator findEqual( const QValueList& l, + const typename QValueList::const_iterator& first, + const SrcItem& it, + const TreeData& td ); + + + + + +//int gSync = 0; +template +TrgItem synchronize( const SrcItem& r1, const TrgItem& r2, const TreeData& td ) +{ + // printf( "--- synchronize : %d ---\n", ++gSync ); + + if( td.isEqual( r1, r2 ) ) + { + QValueList< DiffItem< SrcItem, TrgItem > > d; + diffSiblings( r1, r2, d, td ); + + typename QValueList< DiffItem< SrcItem, TrgItem > >::const_iterator anIt = d.begin(), aLast = d.end(); + bool isFirst = true; + TrgItem lastItem = td.nullTrg(); + // TrgItem tail = td.nullTrg(); + for( ; anIt!=aLast; anIt++ ) + { + const DiffItem& item = *anIt; + if( item.mySrc==td.nullSrc() ) + if( item.myTrg==td.nullTrg() ) + qDebug( "error: both null" ); + else + //to delete + td.deleteItemWithChildren( item.myTrg ); + else { + if( item.myTrg==td.nullTrg() ) + { + //to add + lastItem = createSubTree( item.mySrc, r2, lastItem, isFirst, td ); + } + else + { + //to update + td.updateItem( item.myTrg ); + synchronize( item.mySrc, item.myTrg, td ); + lastItem = item.myTrg; + } + isFirst = false; + } + } + + return r2; + } + else + { + TrgItem new_r2 = createSubTree( r1, td.parent( r2 ), r2, false, td ); + if( r2!=td.nullTrg() ) + td.deleteItemWithChildren( r2 ); + return new_r2; + } +} + +template +const typename QValueList::const_iterator findEqual( const QValueList& l, + const typename QValueList::const_iterator& first, + const SrcItem& it, + const TreeData& td ) +{ + typename QValueList::const_iterator cur = first, last = l.end(); + for( ; cur!=last; cur++ ) + if( td.isEqual( it, *cur ) ) + return cur; + return last; +} + +template +void diffSiblings( const SrcItem& src, const TrgItem& trg, + QValueList < DiffItem < SrcItem,TrgItem > >& d, + const TreeData& td ) +{ + if( src==td.nullSrc() || trg==td.nullTrg() ) + return; + + QValueList src_ch; + QValueList trg_ch; + td.children( src, src_ch ); + td.children( trg, trg_ch ); + + typename QValueList::const_iterator src_it = src_ch.begin(), src_last = src_ch.end(); + typename QValueList::const_iterator cur = trg_ch.begin(), trg_last = trg_ch.end(); + + for( ; src_it!=src_last; src_it++ ) + { + typename QValueList::const_iterator f = + findEqual( trg_ch, cur, *src_it, td ); + if( f!=trg_last ) //is found + { + //mark all items before found as "to be deleted" + for( typename QValueList::const_iterator it = cur; it!=f; it++ ) + { + DiffItem ndiff; + ndiff.mySrc = td.nullSrc(); + ndiff.myTrg = *it; //to delete; + d.append( ndiff ); + } + cur = f; + DiffItem ndiff; + ndiff.mySrc = *src_it; + ndiff.myTrg = *cur; //update this item + d.append( ndiff ); + cur++; + } + else //not found + { + DiffItem ndiff; + ndiff.mySrc = *src_it; + ndiff.myTrg = td.nullTrg(); //add this item + d.append( ndiff ); + } + } + for( ; cur!=trg_last; cur++ ) + { + DiffItem ndiff; + ndiff.mySrc = td.nullSrc(); + ndiff.myTrg = *cur; //to delete; + d.append( ndiff ); + } +} + +template +TrgItem createSubTree( const SrcItem& src, const TrgItem& parent, + const TrgItem& after, const bool asFirst, + const TreeData& td ) +{ + if( src==td.nullSrc() ) + return td.nullTrg(); + + TrgItem nitem = td.createItem( src, parent, after, asFirst ); + if( nitem==td.nullTrg() ) + return nitem; + + QValueList ch; + td.children( src, ch ); + typename QValueList::const_iterator anIt = ch.begin(), aLast = ch.end(); + for( ; anIt!=aLast; anIt++ ) + createSubTree( *anIt, nitem, td.nullTrg(), false, td ); + + return nitem; +} + +#endif diff --git a/src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx b/src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx index 1a8362daa..716cc8fca 100755 --- a/src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx +++ b/src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx @@ -133,6 +133,7 @@ SUPERVGraph_View* SUPERVGraph_ViewFrame::getViewWidget() void SUPERVGraph_ViewFrame::setViewWidget( SUPERVGraph_View* theView ) { myView = theView; + setFocusProxy( myView ); // mkr : IPAL11388 } diff --git a/src/SUPERVGraph/SUPERVGraph_ViewModel.h b/src/SUPERVGraph/SUPERVGraph_ViewModel.h index 695f1a8fc..82c6f6f93 100644 --- a/src/SUPERVGraph/SUPERVGraph_ViewModel.h +++ b/src/SUPERVGraph/SUPERVGraph_ViewModel.h @@ -34,6 +34,7 @@ public: virtual ~SUPERVGraph_Viewer(); virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop); + virtual QString getType() const { return Type(); } }; diff --git a/src/SVTK/Makefile.in b/src/SVTK/Makefile.in index c395159b7..58c7e6fdb 100755 --- a/src/SVTK/Makefile.in +++ b/src/SVTK/Makefile.in @@ -1,7 +1,7 @@ # File : Makefile.in # Author : Alexander Solovyov(OCN) # Module : SVTK -# $Header: /dn06/SALOME_CVS/GUI_SRC/src/SVTK/Makefile.in,v 1.1 +# $Header: top_srcdir=@top_srcdir@ top_builddir=../.. @@ -12,47 +12,88 @@ VPATH=.:@srcdir@:@srcdir@/resources @COMMENCE@ # header files -EXPORT_HEADERS= SVTK.h \ - SVTK_Prs.h \ - SVTK_Actor.h \ - SVTK_CubeAxesActor2D.h \ - SVTK_Functor.h \ - SVTK_ViewManager.h \ - SVTK_ViewModel.h \ - SVTK_ViewWindow.h \ - SVTK_RenderWindow.h \ - SVTK_InteractorStyle.h \ - SVTK_RenderWindowInteractor.h \ - SVTK_Selector.h \ - SVTK_Selection.h +EXPORT_HEADERS= \ + SVTK.h \ + SVTK_Prs.h \ + SVTK_Actor.h \ + SALOME_Actor.h \ + SVTK_RectPicker.h \ + SVTK_DeviceActor.h \ + SVTK_FontWidget.h \ + SVTK_CubeAxesActor2D.h \ + SVTK_Functor.h \ + SVTK_MainWindow.h \ + SVTK_View.h \ + SVTK_ViewManager.h \ + SVTK_ViewModel.h \ + SVTK_ViewWindow.h \ + SVTK_Renderer.h \ + SVTK_InteractorStyle.h \ + SVTK_RenderWindowInteractor.h \ + SVTK_GenericRenderWindowInteractor.h \ + SVTK_Selector.h \ + SVTK_Selection.h \ + SVTK_SelectionEvent.h \ + SVTK_SpaceMouse.h \ + SVTK_Event.h \ + SVTK_ViewModelBase.h PO_FILES = SVTK_msg_en.po # Libraries targets LIB = libSVTK.la -LIB_SRC= SVTK_Prs.cxx \ - SVTK_Actor.cxx \ - SVTK_CubeAxesActor2D.cxx \ - SVTK_Trihedron.cxx \ - SVTK_ViewManager.cxx \ - SVTK_ViewModel.cxx \ - SVTK_ViewWindow.cxx \ - SVTK_RenderWindow.cxx \ - SVTK_InteractorStyle.cxx \ - SVTK_RenderWindowInteractor.cxx \ - SVTK_Selector.cxx - -LIB_MOC = SVTK_RenderWindowInteractor.h \ - SVTK_InteractorStyle.h \ - SVTK_RenderWindow.h \ - SVTK_ViewWindow.h \ - SVTK_ViewModel.h \ - SVTK_ViewManager.h - -CPPFLAGS+=$(QT_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) $(BOOST_CPPFLAGS) - -LDFLAGS+=$(QT_MT_LIBS) $(OCC_LIBS) $(VTK_LIBS) -LIBS+= -lsuit -lCAM -lSalomeObject -lSalomePrs -lVTKViewer +LIB_SRC= \ + SVTK_Prs.cxx \ + SVTK_Actor.cxx \ + SALOME_Actor.cxx \ + SVTK_RectPicker.cxx \ + SVTK_DeviceActor.cxx \ + SVTK_CubeAxesActor2D.cxx \ + SVTK_NonIsometricDlg.cxx \ + SVTK_CubeAxesDlg.cxx \ + SVTK_FontWidget.cxx \ + SVTK_Trihedron.cxx \ + SVTK_MainWindow.cxx \ + SVTK_View.cxx \ + SVTK_ViewManager.cxx \ + SVTK_ViewModel.cxx \ + SVTK_Renderer.cxx \ + SVTK_ViewWindow.cxx \ + SVTK_InteractorStyle.cxx \ + SVTK_RenderWindowInteractor.cxx \ + SVTK_GenericRenderWindowInteractor.cxx \ + SVTK_SpaceMouse.cxx \ + SVTK_Selector.cxx + +LIB_MOC = \ + SVTK_GenericRenderWindowInteractor.h \ + SVTK_RenderWindowInteractor.h \ + SVTK_NonIsometricDlg.h \ + SVTK_CubeAxesDlg.h \ + SVTK_FontWidget.h \ + SVTK_ViewModelBase.h \ + SVTK_ViewManager.h \ + SVTK_ViewWindow.h \ + SVTK_MainWindow.h \ + SVTK_ViewModel.h \ + SVTK_View.h + +BIN = SVTK + +CPPFLAGS+= \ + $(QT_INCLUDES) \ + $(OCC_INCLUDES) \ + $(VTK_INCLUDES) \ + $(BOOST_CPPFLAGS) + +LDFLAGS+= \ + $(QT_MT_LIBS) \ + $(OCC_LIBS) \ + $(VTK_LIBS) + +LIBS+= -lqtx -lsuit -lstd -lCAM -lSalomeObject -lSalomePrs -lVTKViewer + +LDFLAGSFORBIN=$(LDFLAGS) $(LIBS) @CONCLUDE@ diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx new file mode 100644 index 000000000..9b1b7937d --- /dev/null +++ b/src/SVTK/SALOME_Actor.cxx @@ -0,0 +1,743 @@ +// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SALOME_Actor.cxx +// Author : Nicolas REJNERI +// Module : SALOME +// $Header$ + +/*! + \class SALOME_Actor SALOME_Actor.h + \brief Abstract class of SALOME Objects in VTK. +*/ + + +#include "SALOME_Actor.h" + +#include "VTKViewer_Transform.h" +#include "VTKViewer_TransformFilter.h" +#include "VTKViewer_PassThroughFilter.h" +#include "VTKViewer_GeometryFilter.h" +#include "SVTK_RectPicker.h" + +#include "SVTK_Actor.h" + +// VTK Includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +using namespace std; + +#if defined __GNUC__ + #if __GNUC__ == 2 + #define __GNUC_2__ + #endif +#endif + +int SALOME_POINT_SIZE = 5; +int SALOME_LINE_WIDTH = 3; + +//---------------------------------------------------------------------------- +namespace +{ + int + GetEdgeId(SALOME_Actor* theActor, + vtkPicker* thePicker, + int theObjId) + { + int anEdgeId = 0; + if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) { + float aPickPosition[3]; + thePicker->GetPickPosition(aPickPosition); + float aMinDist = 1000000.0, aDist = 0; + for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){ + if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){ + int subId; float pcoords[3], closestPoint[3], weights[3]; + aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights); + if (aDist < aMinDist) { + aMinDist = aDist; + anEdgeId = -1 - i; + } + } + } + } + return anEdgeId; + } + + inline + bool + CheckDimensionId(Selection_Mode theMode, + SALOME_Actor *theActor, + vtkIdType theObjId) + { + switch(theMode){ + case CellSelection: + return true; + case EdgeSelection: + return ( theActor->GetObjDimension( theObjId ) == 1 ); + case FaceSelection: + return ( theActor->GetObjDimension( theObjId ) == 2 ); + case VolumeSelection: + return ( theActor->GetObjDimension( theObjId ) == 3 ); + }; + return false; + } + +} + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(SALOME_Actor); + + +//---------------------------------------------------------------------------- +SALOME_Actor +::SALOME_Actor(): + myRenderer(NULL), + myInteractor(NULL), + mySelectionMode(ActorSelection), + myPreHighlightActor(SVTK_Actor::New()), + myHighlightActor(SVTK_Actor::New()), + myOutline(vtkOutlineSource::New()), + myOutlineActor(VTKViewer_Actor::New()) +{ + myPreHighlightActor->Delete(); + myPreHighlightActor->Initialize(); + myPreHighlightActor->PickableOff(); + myPreHighlightActor->SetVisibility( false ); + + myHighlightActor->Delete(); + myHighlightActor->Initialize(); + myHighlightActor->PickableOff(); + myHighlightActor->SetVisibility( false ); + + myOutline->Delete(); + + vtkPolyDataMapper* anOutlineMapper = vtkPolyDataMapper::New(); + anOutlineMapper->SetInput(myOutline->GetOutput()); + + myOutlineActor->Delete(); + myOutlineActor->SetMapper( anOutlineMapper ); + anOutlineMapper->Delete(); + + myOutlineActor->PickableOff(); + myOutlineActor->DragableOff(); + myOutlineActor->GetProperty()->SetColor(1.0,0.0,0.0); + myOutlineActor->GetProperty()->SetAmbient(1.0); + myOutlineActor->GetProperty()->SetDiffuse(0.0); + myOutlineActor->SetVisibility( false ); +} + + +//---------------------------------------------------------------------------- +SALOME_Actor +::~SALOME_Actor() +{} + + +//---------------------------------------------------------------------------- +Standard_Boolean +SALOME_Actor +::hasIO() +{ + return !myIO.IsNull(); +} + +const Handle(SALOME_InteractiveObject)& +SALOME_Actor +::getIO() +{ + return myIO; +} + +void +SALOME_Actor +::setIO(const Handle(SALOME_InteractiveObject)& theIO) +{ + myIO = theIO; +} + +void +SALOME_Actor +::setName(const char* theName) +{ + if(hasIO()) + myIO->setName(theName); + Superclass::setName(theName); +} + + +//---------------------------------------------------------------------------- +void +SALOME_Actor +::AddToRender(vtkRenderer* theRenderer) +{ + Superclass::AddToRender(theRenderer); + + myRenderer = theRenderer; + + theRenderer->AddActor( myPreHighlightActor.GetPointer() ); + theRenderer->AddActor( myHighlightActor.GetPointer() ); + theRenderer->AddActor( myOutlineActor.GetPointer() ); +} + +void +SALOME_Actor +::RemoveFromRender(vtkRenderer* theRenderer) +{ + Superclass::RemoveFromRender(theRenderer); + + theRenderer->RemoveActor( myPreHighlightActor.GetPointer() ); + theRenderer->RemoveActor( myHighlightActor.GetPointer() ); + theRenderer->RemoveActor( myOutlineActor.GetPointer() ); +} + +vtkRenderer* +SALOME_Actor +::GetRenderer() +{ + return myRenderer; +} + + +//---------------------------------------------------------------------------- +void +SALOME_Actor +::SetInteractor(vtkRenderWindowInteractor* theInteractor) +{ + myInteractor = theInteractor; +} + +void +SALOME_Actor +::Update() +{ + myInteractor->CreateTimer(VTKI_TIMER_UPDATE); +} + + +//---------------------------------------------------------------------------- +void +SALOME_Actor +::SetTransform(VTKViewer_Transform* theTransform) +{ + Superclass::SetTransform(theTransform); + + myPreHighlightActor->SetTransform(theTransform); + myHighlightActor->SetTransform(theTransform); + myOutlineActor->SetTransform(theTransform); +} + + +void +SALOME_Actor +::SetPosition(float _arg1, float _arg2, float _arg3) +{ + Superclass::SetPosition(_arg1,_arg2,_arg3); + + myPreHighlightActor->SetPosition(_arg1,_arg2,_arg3); + myHighlightActor->SetPosition(_arg1,_arg2,_arg3); + myOutlineActor->SetPosition(_arg1,_arg2,_arg3); +} + + +void +SALOME_Actor +::SetPosition(float _arg[3]) +{ + SetPosition(_arg[0],_arg[1],_arg[2]); +} + + +//---------------------------------------------------------------- +void +SALOME_Actor +::SetVisibility( int theVisibility ) +{ + Superclass::SetVisibility( theVisibility ); + + myOutlineActor->SetVisibility( theVisibility && isHighlighted() && !hasHighlight() ); + + myPreHighlightActor->SetVisibility( theVisibility && myIsPreselected ); + + if(mySelector.GetPointer() && hasIO()){ + if(mySelector->SelectionMode() != ActorSelection){ + int aHasIndex = mySelector->HasIndex( getIO() ); + myHighlightActor->SetVisibility( theVisibility && isHighlighted() && aHasIndex); + } + } +} + + +//---------------------------------------------------------------- +void +SALOME_Actor +::SetSelector(SVTK_Selector* theSelector) +{ + mySelector = theSelector; +} + +void +SALOME_Actor +::Highlight(bool theIsHighlight) +{ + mySelectionMode = mySelector->SelectionMode(); + myHighlightActor->SetVisibility( false ); + myOutlineActor->SetVisibility( false ); + + if(mySelector.GetPointer()){ + if(mySelectionMode != ActorSelection){ + TColStd_IndexedMapOfInteger aMapIndex; + mySelector->GetIndex( getIO(), aMapIndex ); + switch( mySelectionMode ){ + case NodeSelection: + myHighlightActor->GetProperty()->SetRepresentationToPoints(); + myHighlightActor->MapPoints( this, aMapIndex ); + break; + case EdgeOfCellSelection: + myHighlightActor->GetProperty()->SetRepresentationToWireframe(); + myHighlightActor->MapEdge( this, aMapIndex ); + break; + case CellSelection: + case EdgeSelection: + case FaceSelection: + case VolumeSelection: + myHighlightActor->GetProperty()->SetRepresentationToSurface(); + myHighlightActor->MapCells( this, aMapIndex ); + break; + } + myHighlightActor->SetVisibility( GetVisibility() && theIsHighlight ); + } + } + + highlight(theIsHighlight); +} + +void +SALOME_Actor +::highlight(bool theIsHighlight) +{ + float aBounds[6]; + GetInput()->GetBounds(aBounds); + myOutline->SetBounds(aBounds); + myOutlineActor->SetVisibility( GetVisibility() && theIsHighlight ); + + Superclass::highlight(theIsHighlight); +} + + +//---------------------------------------------------------------- +bool +SALOME_Actor +::PreHighlight(vtkInteractorStyle *theInteractorStyle, + SVTK_SelectionEvent* theSelectionEvent, + bool theIsHighlight) +{ + vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer(); + // + myPreHighlightActor->SetVisibility( false ); + bool anIsPreselected = myIsPreselected; + + Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode; + bool anIsChanged = (mySelectionMode != aSelectionMode); + + float x = theSelectionEvent->myX; + float y = theSelectionEvent->myY; + float z = 0.0; + + if( !theIsHighlight ) { + SetPreSelected( false ); + vtkActorCollection* theActors = aRenderer->GetActors(); + theActors->InitTraversal(); + while( vtkActor *ac = theActors->GetNextActor() ) + if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) + if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) ) + anActor->SetPreSelected( false ); + + }else{ + switch(aSelectionMode){ + case NodeSelection: + { + myPointPicker->Pick( x, y, z, aRenderer ); + + int aVtkId = myPointPicker->GetPointId(); + if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) { + int anObjId = GetNodeObjId( aVtkId ); + myIsPreselected = (anObjId >= 0); + if(myIsPreselected){ + const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex(); + int anExtent = aMapIndex.Extent(); + anIsChanged |= (anExtent == 0 || anExtent > 0 && anObjId != aMapIndex(1)); + if(anIsChanged){ + TColStd_IndexedMapOfInteger aMapIndex; + aMapIndex.Add( anObjId ); + + myPreHighlightActor->GetProperty()->SetRepresentationToPoints(); + myPreHighlightActor->MapPoints( this, aMapIndex ); + } + myPreHighlightActor->SetVisibility( true ); + } + } + break; + } + case CellSelection: + case EdgeSelection: + case FaceSelection: + case VolumeSelection: + { + myCellPicker->Pick( x, y, z, aRenderer ); + + int aVtkId = myCellPicker->GetCellId(); + if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) && hasIO() ) { + int anObjId = GetElemObjId (aVtkId ); + if ( anObjId >= 0 ) { + myIsPreselected = CheckDimensionId(aSelectionMode,this,anObjId); + if(myIsPreselected){ + const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex(); + int anExtent = aMapIndex.Extent(); + anIsChanged |= (anExtent == 0 || anExtent > 0 && anObjId != aMapIndex(1)); + if(anIsChanged){ + TColStd_IndexedMapOfInteger aMapIndex; + aMapIndex.Add( anObjId ); + + myPreHighlightActor->GetProperty()->SetRepresentationToSurface(); + myPreHighlightActor->MapCells( this, aMapIndex ); + } + myPreHighlightActor->SetVisibility( true ); + } + } + } + break; + } + case EdgeOfCellSelection: + { + 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); + myIsPreselected = anEdgeId < 0; + if(myIsPreselected){ + const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex(); + int anExtent = aMapIndex.Extent(); + anIsChanged |= (anExtent == 0); + anIsChanged |= (anExtent == 2 && (anObjId != aMapIndex(1) || anEdgeId != aMapIndex(2))); + if(anIsChanged){ + TColStd_IndexedMapOfInteger aMapIndex; + aMapIndex.Add( anObjId ); + aMapIndex.Add( anEdgeId ); + + myPreHighlightActor->GetProperty()->SetRepresentationToWireframe(); + myPreHighlightActor->MapEdge( this, aMapIndex ); + } + myPreHighlightActor->SetVisibility( true ); + } + } + } + break; + } + case ActorSelection : + { + if( !mySelector->IsSelected( myIO ) ) { + SetPreSelected( true ); + + vtkActorCollection* theActors = aRenderer->GetActors(); + theActors->InitTraversal(); + while( vtkActor *anAct = theActors->GetNextActor() ) { + if( anAct != this ) + if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( anAct ) ) + if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) ) + anActor->SetPreSelected( true ); + } + } + } + default: + break; + } + } + + mySelectionMode = aSelectionMode; + anIsChanged |= (anIsPreselected != myIsPreselected); + + return anIsChanged; +} + + +//---------------------------------------------------------------- +bool +SALOME_Actor +::Highlight(vtkInteractorStyle *theInteractorStyle, + SVTK_SelectionEvent* theSelectionEvent, + bool theIsHighlight) +{ + myOutlineActor->SetVisibility( false ); + myHighlightActor->SetVisibility( false ); + + vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer(); + // + Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode; + bool anIsShift = theSelectionEvent->myIsShift; + if( !anIsShift ) { + mySelector->RemoveIObject( this ); + } + + float x = theSelectionEvent->myX; + float y = theSelectionEvent->myY; + float z = 0.0; + + if( !theSelectionEvent->myIsRectangle ) { + switch(aSelectionMode){ + case NodeSelection: { + myPointPicker->Pick( x, y, z, aRenderer ); + + int aVtkId = myPointPicker->GetPointId(); + if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) { + int anObjId = GetNodeObjId( aVtkId ); + if( anObjId >= 0 ) { + mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift ); + mySelector->AddIObject( this ); + } + } + break; + } + case CellSelection: + case EdgeSelection: + case FaceSelection: + case VolumeSelection: + { + 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 ( CheckDimensionId(aSelectionMode,this,anObjId) ) { + mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift ); + mySelector->AddIObject( this ); + } + } + } + break; + } + case EdgeOfCellSelection: + { + 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( anEdgeId < 0 ) { + mySelector->AddOrRemoveIndex( myIO, anObjId, false ); + mySelector->AddOrRemoveIndex( myIO, anEdgeId, true ); + mySelector->AddIObject( this ); + } + } + } + break; + } + case ActorSelection : + { + if( mySelector->IsSelected( myIO ) && anIsShift ) + mySelector->RemoveIObject( this ); + else { + mySelector->AddIObject( this ); + } + break; + } + default: + break; + } + }else{ + float xLast = theSelectionEvent->myLastX; + float yLast = theSelectionEvent->myLastY; + float zLast = 0.0; + + float x1 = x < xLast ? x : xLast; + float y1 = y < yLast ? y : yLast; + float z1 = z < zLast ? z : zLast; + float x2 = x > xLast ? x : xLast; + float y2 = y > yLast ? y : yLast; + float z2 = z > zLast ? z : zLast; + + switch(aSelectionMode){ + case NodeSelection: { + myPointRectPicker->InitializePickList(); + myPointRectPicker->AddPickList(this); + myPointRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer ); + + const SVTK_RectPicker::TVectorIdsMap& aVectorIdsMap = myPointRectPicker->GetPointIdsMap(); + SVTK_RectPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this); + TColStd_MapOfInteger anIndexes; + if(aMapIter != aVectorIdsMap.end()){ + const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second; + vtkIdType anEnd = aVectorIds.size(); + SVTK_RectPicker::TVectorIds::const_iterator anIdIter = aVectorIds.begin(); + for(vtkIdType anId = 0; anId < anEnd; anId++ ) { + int aPointId = aVectorIds[anId]; + if( aPointId >= 0 && mySelector->IsValid( this, aPointId, true ) ) { + int anObjId = GetNodeObjId( aPointId ); + anIndexes.Add( anObjId ); + } + } + } + + if( !anIndexes.IsEmpty() ) { + mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift ); + mySelector->AddIObject( this ); + anIndexes.Clear(); + } + else + mySelector->RemoveIObject( this ); + + break; + } + case ActorSelection : + { + float aPnt[3]; + float* aBounds = GetBounds(); + + bool anIsPicked = true; + for( int i = 0; i <= 1; i++ ) { + for( int j = 2; j <= 3; j++ ) { + for( int k = 4; k <= 5; k++ ) { + 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; + } + } + } + } + + if( anIsPicked ) + mySelector->AddIObject(this); + + break; + } + case CellSelection: + case EdgeSelection: + case FaceSelection: + case VolumeSelection: + { + myCellRectPicker->InitializePickList(); + myCellRectPicker->AddPickList(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); + TColStd_MapOfInteger anIndexes; + if(aMapIter != aVectorIdsMap.end()){ + const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second; + vtkIdType anEnd = aVectorIds.size(); + SVTK_RectPicker::TVectorIds::const_iterator anIdIter = aVectorIds.begin(); + for(vtkIdType anId = 0; anId < anEnd; anId++ ) { + int aCellId = aVectorIds[anId]; + if ( !mySelector->IsValid( this, aCellId ) ) + continue; + + int anObjId = GetElemObjId( aCellId ); + if( anObjId != -1 ) + if ( CheckDimensionId(aSelectionMode,this,anObjId) ) { + anIndexes.Add(anObjId); + } + } + } + mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift ); + mySelector->AddIObject( this ); + } + default: + break; + } + } + + mySelectionMode = aSelectionMode; + + return true; +} + +//---------------------------------------------------------------------------- +void +SALOME_Actor +::SetPointPicker(vtkPointPicker* thePointPicker) +{ + myPointPicker = thePointPicker; +} + +void +SALOME_Actor +::SetCellPicker(vtkCellPicker* theCellPicker) +{ + myCellPicker = theCellPicker; +} + +void +SALOME_Actor +::SetPointRectPicker(SVTK_RectPicker* theRectPicker) +{ + myPointRectPicker = theRectPicker; +} + +void +SALOME_Actor +::SetCellRectPicker(SVTK_RectPicker* theRectPicker) +{ + myCellRectPicker = theRectPicker; +} + +//---------------------------------------------------------------------------- +void +SALOME_Actor +::SetPreHighlightProperty(vtkProperty* theProperty) +{ + myPreHighlightActor->SetProperty(theProperty); +} + +void +SALOME_Actor +::SetHighlightProperty(vtkProperty* theProperty) +{ + myHighlightActor->SetProperty(theProperty); +} diff --git a/src/SVTK/SALOME_Actor.h b/src/SVTK/SALOME_Actor.h new file mode 100644 index 000000000..d377ff633 --- /dev/null +++ b/src/SVTK/SALOME_Actor.h @@ -0,0 +1,228 @@ +// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SALOME_Actor.h +// Author : Nicolas REJNERI +// Module : SALOME +// $Header$ + +#ifndef SALOME_ACTOR_H +#define SALOME_ACTOR_H + +#include "SVTK_SelectionEvent.h" +#include "SVTK_Selector.h" +#include "SVTK.h" + +#include "SALOME_InteractiveObject.hxx" + +// undefining min and max because CASCADE's defines them and +// it clashes with std::min(), std::max() +#undef min +#undef max + +#include "VTKViewer_Actor.h" + +#include + +class vtkPointPicker; +class vtkCellPicker; +class vtkOutlineSource; +class vtkInteractorStyle; +class vtkRenderWindowInteractor; + +class SVTK_Actor; +class SVTK_RectPicker; +class SVTK_InteractorStyle; + +extern int SALOME_POINT_SIZE; +extern int SALOME_LINE_WIDTH; + +//! The class is a basic one for all SALOME VTK presentation. +/*! + It provide highlight and prehighlight capabilites, + common way to publish and remove VTK presentation, + mapping of VTK and object IDs and so on. + */ +class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor +{ + public: + static SALOME_Actor* New(); + + vtkTypeMacro(SALOME_Actor,VTKViewer_Actor); + + //---------------------------------------------------------------------------- + //! To check, if the #SALOME_Actor has a reference to #SALOME_InteractiveObject + virtual + Standard_Boolean + hasIO(); + + //! Get correspoinding reference to #SALOME_InteractiveObject + virtual + const Handle(SALOME_InteractiveObject)& + getIO(); + + //! Set reference to #SALOME_InteractiveObject + virtual + void + setIO(const Handle(SALOME_InteractiveObject)& theIO); + + //! Name the #SALOME_Actor + virtual + void + setName(const char* theName); + + //---------------------------------------------------------------------------- + //! Apply view transformation + virtual + void + SetTransform(VTKViewer_Transform* theTransform); + + //! Apply additional position + virtual + void + SetPosition(float _arg1, float _arg2, float _arg3); + + //! Apply additional position + virtual + void + SetPosition(float _arg[3]); + + //---------------------------------------------------------------------------- + //! Visibility management + virtual + void + SetVisibility( int ); + + //---------------------------------------------------------------------------- + //! To publish the actor an all its internal devices + virtual + void + AddToRender(vtkRenderer* theRendere); + + //! To remove the actor an all its internal devices + virtual + void + RemoveFromRender(vtkRenderer* theRendere); + + //! Get reference on renderer where it is published + vtkRenderer* + GetRenderer(); + + //---------------------------------------------------------------------------- + //! To set interactor in order to use #vtkInteractorObserver devices + virtual + void + SetInteractor(vtkRenderWindowInteractor* theInteractor); + + //! Put a request to redraw the view + virtual + void + Update(); + + //---------------------------------------------------------------------------- + //! Set selector in order to the actor at any time can restore current selection + virtual + void + SetSelector(SVTK_Selector* theSelector); + + //! Just to update visibility of the highlight devices + virtual + void + highlight(bool theHighlight); + + //! To map current selection to VTK representation + virtual + void + Highlight(bool theHighlight); + + //---------------------------------------------------------------------------- + //! To process prehighlight (called from #SVTK_InteractorStyle) + virtual + bool + PreHighlight(vtkInteractorStyle* theInteractorStyle, + SVTK_SelectionEvent* theSelectionEvent, + bool theIsHighlight); + + //! To process highlight (called from #SVTK_InteractorStyle) + virtual + bool + Highlight(vtkInteractorStyle* theInteractorStyle, + SVTK_SelectionEvent* theSelectionEvent, + bool theIsHighlight); + + //---------------------------------------------------------------------------- + //! To set up a picker for nodal selection (initialized by #SVTK_Renderer::AddActor) + void + SetPointPicker(vtkPointPicker* thePointPicker); + + //! To set up a picker for cell selection (initialized by #SVTK_Renderer::AddActor) + void + SetCellPicker(vtkCellPicker* theCellPicker); + + //! To set up a picker for point rectangle selection (initialized by #SVTK_Renderer::AddActor) + void + SetPointRectPicker(SVTK_RectPicker* theRectPicker); + + //! To set up a picker for cell rectangle selection (initialized by #SVTK_Renderer::AddActor) + void + SetCellRectPicker(SVTK_RectPicker* theRectPicker); + + //---------------------------------------------------------------------------- + //! To set up a prehighlight property (initialized by #SVTK_Renderer::AddActor) + void + SetPreHighlightProperty(vtkProperty* theProperty); + + //! To set up a highlight property (initialized by #SVTK_Renderer::AddActor) + void + SetHighlightProperty(vtkProperty* theProperty); + + protected: + //---------------------------------------------------------------------------- + vtkRenderWindowInteractor* myInteractor; + vtkRenderer* myRenderer; + + Handle(SALOME_InteractiveObject) myIO; + + SALOME_Actor(); + ~SALOME_Actor(); + + protected: + Selection_Mode mySelectionMode; + vtkSmartPointer mySelector; + + //---------------------------------------------------------------------------- + // Highlight/ Prehighlight devices + vtkSmartPointer myPointPicker; + vtkSmartPointer myCellPicker; + + vtkSmartPointer myPointRectPicker; + vtkSmartPointer myCellRectPicker; + + vtkSmartPointer myPreHighlightActor; + vtkSmartPointer myHighlightActor; + + vtkSmartPointer myOutlineActor; + vtkSmartPointer myOutline; +}; + +#endif // SALOME_ACTOR_H diff --git a/src/SVTK/SVTK.cxx b/src/SVTK/SVTK.cxx new file mode 100644 index 000000000..0be0d5cfd --- /dev/null +++ b/src/SVTK/SVTK.cxx @@ -0,0 +1,60 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ + +#include "SVTK.h" +#include "SVTK_Prs.h" +#include "SVTK_Actor.h" +#include "SALOME_Actor.h" +#include "SVTK_RectPicker.h" +#include "SVTK_DeviceActor.h" +#include "SVTK_CubeAxesActor2D.h" +#include "SVTK_Functor.h" +#include "SVTK_View.h" +#include "SVTK_MainWindow.h" +#include "SVTK_MainWindow.h" +#include "SVTK_NonIsometricDlg.h" +#include "SVTK_CubeAxesDlg.h" +#include "SVTK_FontWidget.h" +#include "SVTK_ViewModel.h" +#include "SVTK_ViewWindow.h" +#include "SVTK_Renderer.h" +#include "SVTK_InteractorStyle.h" +#include "SVTK_RenderWindowInteractor.h" +#include "SVTK_GenericRenderWindowInteractor.h" +#include "SVTK_Selector.h" +#include "SVTK_Selection.h" +#include "SVTK_SelectionEvent.h" +#include "SVTK_SpaceMouse.h" +#include "SVTK_Event.h" +#include "SVTK_ViewModelBase.h" + +int +main(int argc, char** argv) +{ + return 0; +} diff --git a/src/SVTK/SVTK_Actor.cxx b/src/SVTK/SVTK_Actor.cxx index c958f2852..337075bb1 100644 --- a/src/SVTK/SVTK_Actor.cxx +++ b/src/SVTK/SVTK_Actor.cxx @@ -18,8 +18,7 @@ // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org #include "SVTK_Actor.h" - -#include "VTKViewer_PassThroughFilter.h" +#include "SALOME_Actor.h" // VTK Includes #include @@ -29,18 +28,14 @@ #include #include -#include using namespace std; -#ifdef _DEBUG_ -static int MYDEBUG = 0; -#else -static int MYDEBUG = 0; -#endif - -static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet){ +static +void +CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet) +{ vtkPoints *aPoints = vtkPoints::New(); vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints(); aPoints->SetNumberOfPoints(iEnd); @@ -55,90 +50,81 @@ static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSe vtkStandardNewMacro(SVTK_Actor); -SVTK_Actor::SVTK_Actor() +SVTK_Actor +::SVTK_Actor(): + myUnstructuredGrid(vtkUnstructuredGrid::New()) { - myRenderer = NULL; - myIsInfinite = true; + myIsShaded = true; Visibility = Pickable = false; - myUnstructuredGrid = vtkUnstructuredGrid::New(); + myUnstructuredGrid->Delete(); myUnstructuredGrid->Allocate(); +} - myIsShrunk = false; - myIsShrinkable = true; - myShrinkFilter = vtkShrinkFilter::New(); +//---------------------------------------------------------------------------- +void +SVTK_Actor +::Initialize() +{ + SetInput(GetSource()); +} - myMapper = vtkDataSetMapper::New(); - myMapper->SetInput(myUnstructuredGrid); - Superclass::InitPipeLine(myMapper); +//---------------------------------------------------------------------------- +void +SVTK_Actor +::SetSource(vtkUnstructuredGrid* theUnstructuredGrid) +{ + if(GetSource() == theUnstructuredGrid) + return; - SetResolveCoincidentTopology(false); -} + myUnstructuredGrid = theUnstructuredGrid; -void SVTK_Actor::SetShrinkFactor(float theValue){ - myShrinkFilter->SetShrinkFactor(theValue); - Modified(); + SetInput(theUnstructuredGrid); } -void SVTK_Actor::SetShrink() +vtkUnstructuredGrid* +SVTK_Actor +::GetSource() { - if ( !myIsShrinkable ) return; - if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() ) - { - myShrinkFilter->SetInput( aDataSet ); - myPassFilter[1]->SetInput( myShrinkFilter->GetOutput() ); - myIsShrunk = true; - } + return myUnstructuredGrid.GetPointer(); } -void SVTK_Actor::UnShrink() + +//---------------------------------------------------------------------------- +SVTK_Actor +::~SVTK_Actor() { - if ( !myIsShrunk ) return; - if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() ) - { - myPassFilter[1]->SetInput( aDataSet ); - myPassFilter[1]->Modified(); - myIsShrunk = false; - Modified(); - } } //---------------------------------------------------------------------------- -SVTK_Actor::~SVTK_Actor() +const TColStd_IndexedMapOfInteger& +SVTK_Actor +::GetMapIndex() const { - //if(MYDEBUG) INFOS("VTKViewer_Actor::~VTKViewer_Actor()"); - - myMapper->RemoveAllInputs(); - myMapper->Delete(); - - myShrinkFilter->UnRegisterAllOutputs(); - myShrinkFilter->Delete(); - - myUnstructuredGrid->Delete(); + return myMapIndex; } //---------------------------------------------------------------------------- -void SVTK_Actor::MapCells(SALOME_Actor* theMapActor, - const TColStd_IndexedMapOfInteger& theMapIndex) +void +SVTK_Actor +::MapCells(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex) { - myUnstructuredGrid->Reset(); + myUnstructuredGrid->Initialize(); + myUnstructuredGrid->Allocate(); vtkDataSet *aSourceDataSet = theMapActor->GetInput(); - CopyPoints(myUnstructuredGrid,aSourceDataSet); + CopyPoints(GetSource(),aSourceDataSet); int aNbOfParts = theMapIndex.Extent(); for(int ind = 1; ind <= aNbOfParts; ind++){ int aPartId = theMapIndex( ind ); - vtkCell* aCell = theMapActor->GetElemCell(aPartId); - myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); - //for (int i = 0, iEnd = aCell->GetNumberOfEdges(); i < iEnd; i++){ - // vtkCell* anEdgeCell = aCell->GetEdge(i); - // myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds()); - //} + if(vtkCell* aCell = theMapActor->GetElemCell(aPartId)) + myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); } UnShrink(); @@ -146,76 +132,69 @@ void SVTK_Actor::MapCells(SALOME_Actor* theMapActor, SetShrinkFactor(theMapActor->GetShrinkFactor()); SetShrink(); } + + myMapIndex = theMapIndex; } //---------------------------------------------------------------------------- -void SVTK_Actor::MapPoints(SALOME_Actor* theMapActor, - const TColStd_IndexedMapOfInteger& theMapIndex) +void +SVTK_Actor +::MapPoints(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex) { - myUnstructuredGrid->Reset(); + myUnstructuredGrid->Initialize(); + myUnstructuredGrid->Allocate(); + if(int aNbOfParts = theMapIndex.Extent()){ vtkPoints *aPoints = vtkPoints::New(); aPoints->SetNumberOfPoints(aNbOfParts); for(int i = 0; i < aNbOfParts; i++){ int aPartId = theMapIndex( i+1 ); - float* aCoord = theMapActor->GetNodeCoord(aPartId); - aPoints->SetPoint(i,aCoord); - myUnstructuredGrid->InsertNextCell(VTK_VERTEX,1,&i); + if(float* aCoord = theMapActor->GetNodeCoord(aPartId)){ + aPoints->SetPoint(i,aCoord); + myUnstructuredGrid->InsertNextCell(VTK_VERTEX,1,&i); + } } myUnstructuredGrid->SetPoints(aPoints); aPoints->Delete(); } UnShrink(); + + myMapIndex = theMapIndex; } //---------------------------------------------------------------------------- -void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor, - const TColStd_IndexedMapOfInteger& theMapIndex) +void +SVTK_Actor +::MapEdge(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex) { - myUnstructuredGrid->Reset(); + myUnstructuredGrid->Initialize(); + myUnstructuredGrid->Allocate(); vtkDataSet *aSourceDataSet = theMapActor->GetInput(); - CopyPoints(myUnstructuredGrid,aSourceDataSet); - - int iEnd = theMapIndex.Extent(); - int aCellId = -1, aCellCounter = 0; - for(int i = 1; i <= iEnd; i++){ - int anId = theMapIndex( i ); - if(anId > 0) { - aCellCounter++; - aCellId = anId; - } - } - - if(aCellCounter == 1){ - vtkCell* aCell = theMapActor->GetElemCell(aCellId); - if(aCell->GetCellType() <= VTK_LINE){ - myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); - }else{ - int aNbOfParts = aCell->GetNumberOfEdges(); - for(int i = 1; i <= iEnd; i++){ - int aPartId = theMapIndex(i); - if( aPartId < 0){ - aPartId = -aPartId-1; - if(0 > aPartId || aPartId >= aNbOfParts) break; - vtkCell* anEdgeCell = aCell->GetEdge(aPartId); - myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds()); + CopyPoints(GetSource(),aSourceDataSet); + + + if(theMapIndex.Extent() == 2){ + int anEdgeId = theMapIndex(1) < 0 ? theMapIndex(1) : theMapIndex(2); + int aCellId = theMapIndex(1) < 0 ? theMapIndex(2) : theMapIndex(1); + + if(aCellId > 0){ + if(vtkCell* aCell = theMapActor->GetElemCell(aCellId)){ + if(anEdgeId < 0){ + anEdgeId = -anEdgeId - 1; + int aNbOfEdges = aCell->GetNumberOfEdges(); + if(0 <= anEdgeId || anEdgeId < aNbOfEdges){ + if(vtkCell* anEdge = aCell->GetEdge(anEdgeId)) + myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdge->GetPointIds()); + } } } } - }else{ - int aNbOfParts = aSourceDataSet->GetNumberOfCells(); - for(int i = 1; i <= iEnd; i++){ - int aPartId = theMapIndex( i ); - if(aPartId > 0){ - if(aPartId >= aNbOfParts) break; - vtkCell* aCell = aSourceDataSet->GetCell(aPartId); - myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); - } - } } UnShrink(); @@ -223,6 +202,8 @@ void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor, SetShrinkFactor(theMapActor->GetShrinkFactor()); SetShrink(); } + + myMapIndex = theMapIndex; } //---------------------------------------------------------------------------- diff --git a/src/SVTK/SVTK_Actor.h b/src/SVTK/SVTK_Actor.h index 7a9b4a641..9d1dcb224 100644 --- a/src/SVTK/SVTK_Actor.h +++ b/src/SVTK/SVTK_Actor.h @@ -28,41 +28,58 @@ class vtkDataSetMapper; class vtkUnstructuredGrid; #include "SVTK.h" -#include "SALOME_Actor.h" +#include "SVTK_DeviceActor.h" -class SVTK_EXPORT SVTK_Actor : public SALOME_Actor +#include + +class SALOME_Actor; + +//! This class used for internal SVTK package purpose (highlight and prehighlight) +class SVTK_EXPORT SVTK_Actor : public SVTK_DeviceActor { public: - virtual ~SVTK_Actor(); - static SVTK_Actor* New(); - vtkTypeMacro(SVTK_Actor,SALOME_Actor); + vtkTypeMacro(SVTK_Actor,SVTK_DeviceActor); - void SetShrinkFactor(float value); - virtual void SetShrink(); - virtual void UnShrink(); + //! Initialiaze the instance completely + void + Initialize(); - void MapCells(SALOME_Actor* theMapActor, - const TColStd_IndexedMapOfInteger& theMapIndex); + //! Allows to set an external source + void + SetSource(vtkUnstructuredGrid* theUnstructuredGrid); - void MapPoints(SALOME_Actor* theMapActor, - const TColStd_IndexedMapOfInteger& theMapIndex); + //! Get its internal data set + vtkUnstructuredGrid* + GetSource(); - void MapEdge(SALOME_Actor* theMapActor, - const TColStd_IndexedMapOfInteger& theMapIndex); + //! Allow to recostruct selected cells from source SALOME_Actor and map of subindexes + void + MapCells(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex); - protected: - vtkUnstructuredGrid* myUnstructuredGrid; - vtkDataSetMapper* myMapper; + //! Allow to recostruct selected points from source SALOME_Actor and map of subindexes + void + MapPoints(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex); - vtkRenderer* myRenderer; + //! Allow to recostruct selected edges from source SALOME_Actor and map of subindexes + void + MapEdge(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex); + + const TColStd_IndexedMapOfInteger& + GetMapIndex() const; + + protected: + TColStd_IndexedMapOfInteger myMapIndex; - vtkShrinkFilter* myShrinkFilter; - bool myIsShrinkable; - bool myIsShrunk; + vtkSmartPointer myUnstructuredGrid; SVTK_Actor(); + virtual + ~SVTK_Actor(); }; #endif diff --git a/src/SVTK/SVTK_CubeAxesDlg.cxx b/src/SVTK/SVTK_CubeAxesDlg.cxx new file mode 100644 index 000000000..daed6845e --- /dev/null +++ b/src/SVTK/SVTK_CubeAxesDlg.cxx @@ -0,0 +1,572 @@ +// VISU VISUGUI : GUI for SMESH component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_CubeAxesDlg.cxx +// Author : Sergey LITONIN +// Module : VISU + +#include "SVTK_CubeAxesDlg.h" + +#include "SVTK_MainWindow.h" +#include "SVTK_FontWidget.h" + +#include "SVTK_CubeAxesActor2D.h" + +#include "QtxAction.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/*! + * Class : AxisWg + * Description : Tab of dialog + */ + +//======================================================================= +// name : SVTK_AxisWidget::AxisWg +// Purpose : Constructor +//======================================================================= +SVTK_AxisWidget::SVTK_AxisWidget (QWidget* theParent) +: QFrame(theParent) +{ + QValueList< QLabel* > aLabels; + + // "Name" grp + + myNameGrp = new QGroupBox(3, Qt::Vertical, tr("AXIS_NAME"), this); + myIsNameVisible = new QCheckBox(tr("IS_VISIBLE"), myNameGrp); + + QHBox* aHBox = new QHBox(myNameGrp); + aHBox->setSpacing(5); + QLabel* aLabel = new QLabel(tr("NAME"), aHBox); + myAxisName = new QLineEdit(aHBox); + aLabels.append(aLabel); + + aHBox = new QHBox(myNameGrp); + aHBox->setSpacing(5); + aLabel = new QLabel(tr("FONT"), aHBox); + myNameFont = new SVTK_FontWidget(aHBox); + aLabels.append(aLabel); + + + // "Labels" grp + + myLabelsGrp = new QGroupBox(4, Qt::Vertical, tr("LABELS"), this); + myIsLabelsVisible = new QCheckBox(tr("IS_VISIBLE"), myLabelsGrp); + + aHBox = new QHBox(myLabelsGrp); + aHBox->setSpacing(5); + aLabel = new QLabel(tr("NUMBER"), aHBox); + myLabelNumber = new QLineEdit(aHBox); + myLabelNumber->setValidator(new QIntValidator(0, 25, this)); + myLabelNumber->installEventFilter(this); + aLabels.append(aLabel); + + aHBox = new QHBox(myLabelsGrp); + aHBox->setSpacing(5); + aLabel = new QLabel(tr("OFFSET"), aHBox); + myLabelOffset = new QLineEdit(aHBox); + aLabels.append(aLabel); + + aHBox = new QHBox(myLabelsGrp); + aHBox->setSpacing(5); + aLabel = new QLabel(tr("FONT"), aHBox); + myLabelsFont = new SVTK_FontWidget(aHBox); + aLabels.append(aLabel); + + // "Tick marks" grp + + myTicksGrp = new QGroupBox(2, Qt::Vertical, tr("TICK_MARKS"), this); + myIsTicksVisible = new QCheckBox(tr("IS_VISIBLE"), myTicksGrp); + + aHBox = new QHBox(myTicksGrp); + aHBox->setSpacing(5); + aLabel = new QLabel(tr("LENGTH"), aHBox); + myTickLength = new QLineEdit(aHBox); + aLabels.append(aLabel); + + // Layout + + QVBoxLayout* aLay = new QVBoxLayout(this, 0, 5); + aLay->addWidget(myNameGrp); + aLay->addWidget(myLabelsGrp); + aLay->addWidget(myTicksGrp); + + // init + myIsNameVisible->setChecked(true); + myIsLabelsVisible->setChecked(true); + myIsTicksVisible->setChecked(true); + updateControlState(); + + // Adjust label widths + QValueList< QLabel* >::iterator anIter; + int aMaxWidth = 0; + for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++) + aMaxWidth = QMAX(aMaxWidth, (*anIter)->sizeHint().width()); + for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++) + (*anIter)->setFixedWidth(aMaxWidth); + + // connect signals and slots + connect(myIsNameVisible, SIGNAL(stateChanged(int)), SLOT(onNameChecked())); + connect(myIsLabelsVisible, SIGNAL(stateChanged(int)), SLOT(onLabelsChecked())); + connect(myIsTicksVisible, SIGNAL(stateChanged(int)), SLOT(onTicksChecked())); +} + +SVTK_AxisWidget::~SVTK_AxisWidget() +{ +} + +void SVTK_AxisWidget::updateControlState() +{ + onNameChecked(); + onLabelsChecked(); + onTicksChecked(); +} + +bool SVTK_AxisWidget::eventFilter(QObject* o, QEvent* e) +{ + if (e->type() == QEvent::FocusOut) { + bool isOK = false; + int k = myLabelNumber->text().toInt(&isOK); + if (isOK && k > 25) myLabelNumber->setText("25"); + } + return false; +} + +//======================================================================= +// name : SVTK_AxisWidget::onNameChecked +// Purpose : +//======================================================================= +void SVTK_AxisWidget::setEnabled(QGroupBox* theGrp, const bool theState) +{ + QObjectList aChildren(*theGrp->children()); + QObject* anObj; + for(anObj = aChildren.first(); anObj !=0; anObj = aChildren.next()) + if (anObj !=0 && anObj->inherits("QHBox")) + ((QHBox*)anObj)->setEnabled(theState); +} + +//======================================================================= +// Labels : SVTK_AxisWidget::onLabelsChecked +// Purpose : +//======================================================================= +void SVTK_AxisWidget::onLabelsChecked() +{ + setEnabled(myLabelsGrp, myIsLabelsVisible->isChecked()); +} + +//======================================================================= +// Labels : SVTK_AxisWidget::onTicksChecked +// Purpose : +//======================================================================= +void SVTK_AxisWidget::onTicksChecked() +{ + setEnabled(myTicksGrp, myIsTicksVisible->isChecked()); +} + +//======================================================================= +// name : SVTK_AxisWidget::onNameChecked +// Purpose : +//======================================================================= +void SVTK_AxisWidget::onNameChecked() +{ + setEnabled(myNameGrp, myIsNameVisible->isChecked()); +} + +//======================================================================= +// name : SVTK_AxisWidget::UseName +// Purpose : +//======================================================================= +void SVTK_AxisWidget::UseName(const bool toUse) +{ + myIsNameVisible->setChecked(toUse); +} + +//======================================================================= +// name : SVTK_AxisWidget::SetName +// Purpose : +//================================================== ===================== +void SVTK_AxisWidget::SetName(const QString& theName) +{ + myAxisName->setText(theName); +} + +//======================================================================= +// name : SVTK_AxisWidget::SetNameFont +// Purpose : +//======================================================================= +void SVTK_AxisWidget::SetNameFont(const QColor& theColor, + const int theFont, + const bool theIsBold, + const bool theIsItalic, + const bool theIsShadow) +{ + myNameFont->SetData(theColor, theFont, theIsBold, theIsItalic, theIsShadow); +} + +//======================================================================= +// name : SVTK_AxisWidget::SetNameFont +// Purpose : +//======================================================================= +bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor) +{ + if (theActor == 0) + return false; + + // Name + + bool useName = theActor->GetTitleVisibility(); + QString aTitle(theActor->GetTitle()); + + QColor aTitleColor(255, 255, 255); + int aTitleFontFamily = VTK_ARIAL; + bool isTitleBold = false; + bool isTitleItalic = false; + bool isTitleShadow = false; + + vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty(); + if (aTitleProp !=0) + { + float c[ 3 ]; + aTitleProp->GetColor(c); + aTitleColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255)); + aTitleFontFamily = aTitleProp->GetFontFamily(); + isTitleBold = aTitleProp->GetBold() ? true : false; + isTitleItalic = aTitleProp->GetItalic() ? true : false; + isTitleShadow = aTitleProp->GetShadow() ? true : false; + } + + myIsNameVisible->setChecked(useName); + myAxisName->setText(aTitle); + myNameFont->SetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow); + + // Labels + + bool useLabels = theActor->GetLabelVisibility(); + int nbLabels = theActor->GetNumberOfLabels(); + int anOffset = theActor->GetTickOffset(); + + QColor aLabelsColor(255, 255, 255); + int aLabelsFontFamily = VTK_ARIAL; + bool isLabelsBold = false; + bool isLabelsItalic = false; + bool isLabelsShadow = false; + + vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty(); + if (aLabelsProp !=0) + { + float c[ 3 ]; + aLabelsProp->GetColor(c); + aLabelsColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255)); + aLabelsFontFamily = aLabelsProp->GetFontFamily(); + isLabelsBold = aLabelsProp->GetBold() ? true : false; + isLabelsItalic = aLabelsProp->GetItalic() ? true : false; + isLabelsShadow = aLabelsProp->GetShadow() ? true : false; + } + + myIsLabelsVisible->setChecked(useLabels); + myLabelNumber->setText(QString("%1").arg(nbLabels)); + myLabelOffset->setText(QString("%1").arg(anOffset)); + myLabelsFont->SetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow); + + // Tick marks + bool useTickMarks = theActor->GetTickVisibility(); + int aTickLength = theActor->GetTickLength(); + + myIsTicksVisible->setChecked(useTickMarks); + myTickLength->setText(QString("%1").arg(aTickLength)); + + return true; +} + +//======================================================================= +// name : SVTK_CubeAxesDlg::Apply +// Purpose : +//======================================================================= +bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor) +{ + if (theActor == 0) + return false; + + // Name + + theActor->SetTitleVisibility(myIsNameVisible->isChecked() ? 1 : 0); + theActor->SetTitle(myAxisName->text().latin1()); + + QColor aTitleColor(255, 255, 255); + int aTitleFontFamily = VTK_ARIAL; + bool isTitleBold = false; + bool isTitleItalic = false; + bool isTitleShadow = false; + + myNameFont->GetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow); + vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty(); + if (aTitleProp) + { + aTitleProp->SetColor(aTitleColor.red() / 255., + aTitleColor.green() / 255., + aTitleColor.blue() / 255.); + aTitleProp->SetFontFamily(aTitleFontFamily); + + aTitleProp->SetBold(isTitleBold ? 1 : 0); + aTitleProp->SetItalic(isTitleItalic ? 1 : 0); + aTitleProp->SetShadow(isTitleShadow ? 1 : 0); + + theActor->SetTitleTextProperty(aTitleProp); + } + + // Labels + + theActor->SetLabelVisibility(myIsLabelsVisible->isChecked() ? 1 : 0); + + bool isOk = false; + int nbLabels = myLabelNumber->text().toInt(&isOk); + if (isOk) + theActor->SetNumberOfLabels(nbLabels); + + int anOffset = myLabelOffset->text().toInt(&isOk); + if (isOk) + theActor->SetTickOffset(anOffset); + + QColor aLabelsColor(255, 255, 255); + int aLabelsFontFamily = VTK_ARIAL; + bool isLabelsBold = false; + bool isLabelsItalic = false; + bool isLabelsShadow = false; + + myLabelsFont->GetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow); + vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty(); + if (aLabelsProp) + { + aLabelsProp->SetColor(aLabelsColor.red() / 255., + aLabelsColor.green() / 255., + aLabelsColor.blue() / 255.); + aLabelsProp->SetFontFamily(aLabelsFontFamily); + + aLabelsProp->SetBold(isLabelsBold ? 1 : 0); + aLabelsProp->SetItalic(isLabelsItalic ? 1 : 0); + aLabelsProp->SetShadow(isLabelsShadow ? 1 : 0); + + aLabelsProp->Modified(); + theActor->SetLabelTextProperty(aLabelsProp); + } + + + // Tick marks + theActor->SetTickVisibility(myIsTicksVisible->isChecked()); + int aTickLength = myTickLength->text().toInt(&isOk); + if (isOk) + theActor->SetTickLength(aTickLength); + + return true; +} + +/* + Class : SVTK_CubeAxesDlg + Description : Dialog for specifynig cube axes properties +*/ + +//======================================================================= +// name : SVTK_CubeAxesDlg::SVTK_CubeAxesDlg +// Purpose : Constructor +//======================================================================= +SVTK_CubeAxesDlg::SVTK_CubeAxesDlg(SVTK_MainWindow* theParent, + const char* theName, + QtxAction* theAction): + QDialog(theParent, + theName, + false, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), + myMainWindow(theParent), + myAction(theAction) +{ + setCaption(tr("CAPTION")); + + QVBoxLayout* aLay = new QVBoxLayout(this, 5, 5); + aLay->addWidget(createMainFrame(this)); + aLay->addWidget(createButtonFrame(this)); +} + +//======================================================================= +// name : SVTK_CubeAxesDlg::createMainFrame +// Purpose : Create frame containing dialog's input fields +//======================================================================= +QWidget* SVTK_CubeAxesDlg::createMainFrame(QWidget* theParent) +{ + QFrame* aFrame = new QFrame(theParent); + + myTabWg = new QTabWidget(aFrame); + + myAxes[ 0 ] = new SVTK_AxisWidget(myTabWg); + myAxes[ 1 ] = new SVTK_AxisWidget(myTabWg); + myAxes[ 2 ] = new SVTK_AxisWidget(myTabWg); + + myTabWg->addTab(myAxes[ 0 ], tr("X_AXIS")); + myTabWg->addTab(myAxes[ 1 ], tr("Y_AXIS")); + myTabWg->addTab(myAxes[ 2 ], tr("Z_AXIS")); + + myTabWg->setMargin(5); + + myIsVisible = new QCheckBox(tr("IS_VISIBLE"), aFrame); + + QVBoxLayout* aLay = new QVBoxLayout(aFrame, 0, 5); + aLay->addWidget(myTabWg); + aLay->addWidget(myIsVisible); + + return aFrame; +} + +//======================================================================= +// name : SVTK_CubeAxesDlg::createButtonFrame +// Purpose : Create frame containing buttons +//======================================================================= +QWidget* SVTK_CubeAxesDlg::createButtonFrame(QWidget* theParent) +{ + QFrame* aFrame = new QFrame(theParent); + aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken); + + myOkBtn = new QPushButton(tr("BUT_OK"), aFrame); + myApplyBtn = new QPushButton(tr("BUT_APPLY"), aFrame); + myCloseBtn = new QPushButton(tr("BUT_CLOSE"), aFrame); + + QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); + + QHBoxLayout* aLay = new QHBoxLayout(aFrame, 5, 5); + + aLay->addWidget(myOkBtn); + aLay->addWidget(myApplyBtn); + aLay->addItem(aSpacer); + aLay->addWidget(myCloseBtn); + + connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk())); + connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply())); + connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose())); + + return aFrame; +} + +//======================================================================= +// name : SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg +// Purpose : Destructor +//======================================================================= +SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg() +{ +} + +//======================================================================= +// name : SVTK_CubeAxesDlg::Update +// Purpose : Update dialog fields, connect signals and slots, show dialog +//======================================================================= +void SVTK_CubeAxesDlg::Update() +{ + myActor = myMainWindow->GetCubeAxes(); + + myAxes[ 0 ]->ReadData(myActor->GetXAxisActor2D()); + myAxes[ 1 ]->ReadData(myActor->GetYAxisActor2D()); + myAxes[ 2 ]->ReadData(myActor->GetZAxisActor2D()); + + myIsVisible->setChecked(myActor->GetVisibility() ? true : false); +} + +//======================================================================= +// name : SVTK_CubeAxesDlg::isValid +// Purpose : Verify validity of entry data +//======================================================================= +bool SVTK_CubeAxesDlg::isValid() const +{ + return true; +} + +//======================================================================= +// name : SVTK_CubeAxesDlg::onApply +// Purpose : Verify validity of entry data +//======================================================================= +bool SVTK_CubeAxesDlg::onApply() +{ + bool isOk = true; + + try + { + isOk = isOk && myAxes[ 0 ]->Apply(myActor->GetXAxisActor2D()); + isOk = isOk && myAxes[ 1 ]->Apply(myActor->GetYAxisActor2D()); + isOk = isOk && myAxes[ 2 ]->Apply(myActor->GetZAxisActor2D()); + + + //myActor->SetXLabel(myAxes[ 0 ]->myAxisName->text()); + //myActor->SetYLabel(myAxes[ 1 ]->myAxisName->text()); + //myActor->SetZLabel(myAxes[ 2 ]->myAxisName->text()); + + //myActor->SetNumberOfLabels(myActor->GetXAxisActor2D()->GetNumberOfLabels()); + if (myIsVisible->isChecked()) + myActor->VisibilityOn(); + else + myActor->VisibilityOff(); + + if (isOk) + myMainWindow->Repaint(); + } + catch(...) + { + isOk = false; + } + + return isOk; +} + +//======================================================================= +// name : SVTK_CubeAxesDlg::onOk +// Purpose : SLOT called when "Ok" button pressed. +//======================================================================= +void SVTK_CubeAxesDlg::onOk() +{ + if (onApply()) + onClose(); +} + +//======================================================================= +// name : SVTK_CubeAxesDlg::onClose +// Purpose : SLOT called when "Close" button pressed. Close dialog +//======================================================================= +void SVTK_CubeAxesDlg::onClose() +{ + reject(); + + myAction->setOn( false ); +} + +void SVTK_CubeAxesDlg::done( int r ) +{ + myAction->setOn( false ); + QDialog::done( r ); +} diff --git a/src/SVTK/SVTK_CubeAxesDlg.h b/src/SVTK/SVTK_CubeAxesDlg.h new file mode 100644 index 000000000..bd7e5254c --- /dev/null +++ b/src/SVTK/SVTK_CubeAxesDlg.h @@ -0,0 +1,144 @@ +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_CubeAxesDlg.h +// Author : Sergey LITONIN +// Module : VISU + + +#ifndef SVTK_CubeAxesDlg_H +#define SVTK_CubeAxesDlg_H + +#include +#include + +class QWidget; +class QFrame; +class QPushButton; +class QTabWidget; +class QCheckBox; +class QLineEdit; +class QGroupBox; + +class QtxAction; + +class vtkAxisActor2D; +class SVTK_CubeAxesActor2D; + +class SVTK_FontWidget; +class SVTK_AxisWidget; +class SVTK_MainWindow; + +/*! + * Class : SVTK_CubeAxesDlg + * Description : Dialog for specifynig cube axes properties + */ +class SVTK_CubeAxesDlg : public QDialog +{ + Q_OBJECT + +public: + SVTK_CubeAxesDlg(SVTK_MainWindow* theParent, + const char* theName, + QtxAction* theAction); + virtual ~SVTK_CubeAxesDlg(); + + void Update(); + +private slots: + void onOk(); + bool onApply(); + void onClose(); + + virtual void done( int ); + +private: + QWidget* createButtonFrame( QWidget* ); + QWidget* createMainFrame ( QWidget* ); + bool isValid() const; + +private: + SVTK_MainWindow *myMainWindow; + SVTK_CubeAxesActor2D* myActor; + QtxAction* myAction; + + QTabWidget* myTabWg; + QCheckBox* myIsVisible; + + QPushButton* myOkBtn; + QPushButton* myApplyBtn; + QPushButton* myCloseBtn; + SVTK_AxisWidget* myAxes[ 3 ]; +}; + +/*! + * Class : SVTK_AxisWidget + * Description : Tab of dialog + */ +class SVTK_AxisWidget : public QFrame +{ + Q_OBJECT + +public: + SVTK_AxisWidget( QWidget* ); + ~SVTK_AxisWidget(); + + void UseName( const bool ); + void SetName( const QString& ); + void SetNameFont( const QColor&, const int, const bool, const bool, const bool ); + bool ReadData( vtkAxisActor2D* ); + bool Apply( vtkAxisActor2D* ); + +protected: + bool eventFilter(QObject*, QEvent*); + +private slots: + void onNameChecked(); + void onLabelsChecked(); + void onTicksChecked(); + +private: + void updateControlState(); + void setEnabled( QGroupBox*, const bool ); + +private: + // name + QGroupBox* myNameGrp; + QCheckBox* myIsNameVisible; + QLineEdit* myAxisName; + SVTK_FontWidget* myNameFont; + + // labels + QGroupBox* myLabelsGrp; + QCheckBox* myIsLabelsVisible; + QLineEdit* myLabelNumber; + QLineEdit* myLabelOffset; + SVTK_FontWidget* myLabelsFont; + + // tick marks + QGroupBox* myTicksGrp; + QCheckBox* myIsTicksVisible; + QLineEdit* myTickLength; + + friend class SVTK_CubeAxesDlg; +}; + +#endif diff --git a/src/SVTK/SVTK_DeviceActor.cxx b/src/SVTK/SVTK_DeviceActor.cxx new file mode 100644 index 000000000..be959115c --- /dev/null +++ b/src/SVTK/SVTK_DeviceActor.cxx @@ -0,0 +1,419 @@ +// SVTK OBJECT : interactive object for SVTK visualization +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_DeviceActor.cxx +// Author : +// Module : +// $Header$ + + +#include "SVTK_DeviceActor.h" + +#include "VTKViewer_Transform.h" +#include "VTKViewer_TransformFilter.h" +#include "VTKViewer_PassThroughFilter.h" +#include "VTKViewer_GeometryFilter.h" + +// VTK Includes +#include +#include + +#include +#include + +#include +#include + +using namespace std; + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(SVTK_DeviceActor); + + +//---------------------------------------------------------------------------- +SVTK_DeviceActor +::SVTK_DeviceActor() +{ + myIsShrunk = false; + myIsShrinkable = true; + + myIsShaded = true; + myProperty = vtkProperty::New(); + myRepresentation = SVTK::Representation::Surface; + + myIsResolveCoincidentTopology = false; + vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, + myPolygonOffsetUnits); + + myMapper = vtkDataSetMapper::New(); + + myShrinkFilter = vtkShrinkFilter::New(); + + myGeomFilter = VTKViewer_GeometryFilter::New(); + + myTransformFilter = VTKViewer_TransformFilter::New(); + + for(int i = 0; i < 6; i++) + myPassFilter.push_back(VTKViewer_PassThroughFilter::New()); +} + + +//---------------------------------------------------------------------------- +SVTK_DeviceActor +::~SVTK_DeviceActor() +{ + myMapper->Delete(); + + myProperty->Delete(); + + myGeomFilter->Delete(); + + myTransformFilter->Delete(); + + myShrinkFilter->Delete(); + + for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++) + myPassFilter[i]->Delete(); +} + + +//---------------------------------------------------------------------------- +void +SVTK_DeviceActor +::SetMapper(vtkMapper* theMapper) +{ + InitPipeLine(theMapper); +} + +void +SVTK_DeviceActor +::InitPipeLine(vtkMapper* theMapper) +{ + if(theMapper){ + int anId = 0; + myPassFilter[ anId ]->SetInput( theMapper->GetInput() ); + myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() ); + + anId++; // 1 + myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() ); + + anId++; // 2 + myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); + myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); + + anId++; // 3 + myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); + + anId++; // 4 + myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() ); + myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); + + anId++; // 5 + if(vtkDataSetMapper* aMapper = dynamic_cast(theMapper)){ + aMapper->SetInput(myPassFilter[anId]->GetOutput()); + }else if(vtkPolyDataMapper* aMapper = dynamic_cast(theMapper)){ + aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput()); + } + }else + myPassFilter[ 0 ]->SetInput( NULL ); + Superclass::SetMapper(theMapper); +} + +//---------------------------------------------------------------------------- +vtkDataSet* +SVTK_DeviceActor +::GetInput() +{ + return myPassFilter.front()->GetOutput(); +} + +void +SVTK_DeviceActor +::SetInput(vtkDataSet* theDataSet) +{ + myMapper->SetInput(theDataSet); + InitPipeLine(myMapper); +} + +//---------------------------------------------------------------------------- +void +SVTK_DeviceActor:: +SetStoreMapping(bool theStoreMapping) +{ + myGeomFilter->SetStoreMapping(theStoreMapping); +} + + + +//---------------------------------------------------------------------------- +unsigned long int +SVTK_DeviceActor +::GetMTime() +{ + unsigned long mTime = this->Superclass::GetMTime(); + + mTime = max(mTime,myGeomFilter->GetMTime()); + + mTime = max(mTime,myTransformFilter->GetMTime()); + + if(myIsShrunk) + mTime = max(mTime,myShrinkFilter->GetMTime()); + + for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++) + max(mTime,myPassFilter[i]->GetMTime()); + + return mTime; +} + + +//---------------------------------------------------------------------------- +void +SVTK_DeviceActor +::SetTransform(VTKViewer_Transform* theTransform) +{ + myTransformFilter->SetTransform(theTransform); +} + + +//---------------------------------------------------------------------------- +bool +SVTK_DeviceActor +::IsShrunkable() +{ + return myIsShrinkable; +} + +void +SVTK_DeviceActor +::SetShrinkable(bool theIsShrinkable) +{ + myIsShrinkable = theIsShrinkable; +} + +bool +SVTK_DeviceActor +::IsShrunk() +{ + return myIsShrunk; +} + +void +SVTK_DeviceActor +::SetShrink() +{ + if ( !myIsShrinkable ) + return; + if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() ) + { + myShrinkFilter->SetInput( aDataSet ); + myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() ); + myIsShrunk = true; + } +} + +void +SVTK_DeviceActor +::UnShrink() +{ + if ( !myIsShrunk ) return; + if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() ) + { + myPassFilter[ 1 ]->SetInput( aDataSet ); + myIsShrunk = false; + } +} + +float +SVTK_DeviceActor +::GetShrinkFactor() +{ + return myShrinkFilter->GetShrinkFactor(); +} + +void +SVTK_DeviceActor +::SetShrinkFactor(float theValue) +{ + myShrinkFilter->SetShrinkFactor(theValue); +} + + + +//---------------------------------------------------------------------------- +void +SVTK_DeviceActor +::SetRepresentation(SVTK::Representation::Type theMode) +{ + using namespace SVTK::Representation; + if(IsShaded()){ + switch(myRepresentation){ + case Points : + case Surface : + myProperty->DeepCopy(GetProperty()); + } + + switch(theMode){ + case Points : + case Surface : + GetProperty()->DeepCopy(myProperty); + break; + default: + GetProperty()->SetAmbient(1.0); + GetProperty()->SetDiffuse(0.0); + GetProperty()->SetSpecular(0.0); + } + } + + switch(theMode){ + case Insideframe : + myGeomFilter->SetInside(true); + myGeomFilter->SetWireframeMode(true); + GetProperty()->SetRepresentation(VTK_WIREFRAME); + break; + case Points : + GetProperty()->SetPointSize(GetDefaultPointSize()); + GetProperty()->SetRepresentation(VTK_POINTS); + myGeomFilter->SetWireframeMode(false); + myGeomFilter->SetInside(false); + break; + case Wireframe : + GetProperty()->SetRepresentation(VTK_WIREFRAME); + myGeomFilter->SetWireframeMode(true); + myGeomFilter->SetInside(false); + break; + case Surface : + GetProperty()->SetRepresentation(VTK_SURFACE); + myGeomFilter->SetWireframeMode(false); + myGeomFilter->SetInside(false); + break; + } + + myRepresentation = theMode; +} + +SVTK::Representation::Type +SVTK_DeviceActor +::GetRepresentation() +{ + return myRepresentation; +} + +float +SVTK_DeviceActor +::GetDefaultPointSize() +{ + return 5; +} + +float +SVTK_DeviceActor +::GetDefaultLineWidth() +{ + return 3; +} + + +bool +SVTK_DeviceActor +::IsShaded() +{ + return myIsShaded; +} + +void +SVTK_DeviceActor +::SetShaded(bool theShaded) +{ + myIsShaded = theShaded; +} + + +//---------------------------------------------------------------------------- +int +SVTK_DeviceActor +::GetNodeObjId(int theVtkID) +{ + return theVtkID; +} + +float* +SVTK_DeviceActor +::GetNodeCoord(int theObjID) +{ + return GetInput()->GetPoint(theObjID); +} + + +vtkCell* +SVTK_DeviceActor +::GetElemCell(int theObjID) +{ + return GetInput()->GetCell(theObjID); +} + +int +SVTK_DeviceActor +::GetElemObjId(int theVtkID) +{ + return theVtkID; +} + + +//---------------------------------------------------------------------------- +void +SVTK_DeviceActor +::Render(vtkRenderer *ren, vtkMapper* m) +{ + if(myIsResolveCoincidentTopology){ + int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology(); + float aFactor, aUnit; + vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); + + vtkMapper::SetResolveCoincidentTopologyToPolygonOffset(); + vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, + myPolygonOffsetUnits); + Superclass::Render(ren,m); + + vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); + vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology); + }else{ + Superclass::Render(ren,m); + } +} + + +void +SVTK_DeviceActor +::SetPolygonOffsetParameters(float factor, float units) +{ + myPolygonOffsetFactor = factor; + myPolygonOffsetUnits = units; +} + +void +SVTK_DeviceActor +::GetPolygonOffsetParameters(float& factor, float& units) +{ + factor = myPolygonOffsetFactor; + units = myPolygonOffsetUnits; +} diff --git a/src/SVTK/SVTK_DeviceActor.h b/src/SVTK/SVTK_DeviceActor.h new file mode 100644 index 000000000..f8a49bc36 --- /dev/null +++ b/src/SVTK/SVTK_DeviceActor.h @@ -0,0 +1,209 @@ +// SVTK OBJECT : interactive object for SVTK visualization +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_DeviceActor.h +// Author : +// Module : +// $Header$ + +#ifndef SVTK_DEVICE_ACTOR_H +#define SVTK_DEVICE_ACTOR_H + +#include + +#include +#include + +class VTKViewer_Transform; +class VTKViewer_TransformFilter; +class VTKViewer_PassThroughFilter; +class VTKViewer_GeometryFilter; + +class vtkCell; +class vtkDataSet; +class vtkShrinkFilter; +class vtkDataSetMapper; + +//---------------------------------------------------------------------------- +namespace SVTK +{ + namespace Representation + { + typedef int Type; + const Type Points = VTK_POINTS; + const Type Wireframe = VTK_WIREFRAME; + const Type Surface = VTK_SURFACE; + const Type Insideframe = Surface + 1; + } +} + + +//---------------------------------------------------------------------------- +class SVTK_DeviceActor: public vtkLODActor +{ + public: + vtkTypeMacro(SVTK_DeviceActor,vtkLODActor); + + static + SVTK_DeviceActor* + New(); + + //! Apply a view transformation + virtual + void + SetTransform(VTKViewer_Transform* theTransform); + + //! To insert some additional filters and then sets the given #vtkMapper + virtual + void + SetMapper(vtkMapper* theMapper); + + //! Allows to get initial #vtkDataSet + virtual + vtkDataSet* + GetInput(); + + //! Allows to set initial #vtkDataSet + virtual + void + SetInput(vtkDataSet* theDataSet); + + /** @name For selection mapping purpose */ + //@{ + virtual + int + GetNodeObjId(int theVtkID); + + virtual + float* + GetNodeCoord(int theObjID); + + virtual + int + GetElemObjId(int theVtkID); + + virtual + vtkCell* + GetElemCell(int theObjID); + + //! To provide VTK to Object and backward mapping + virtual + void + SetStoreMapping(bool theStoreMapping); + //@} + + virtual + unsigned long int + GetMTime(); + + /** @name For shrink mamnagement purpose */ + //@{ + float + GetShrinkFactor(); + + virtual + void + SetShrinkFactor(float value); + + virtual + void + SetShrinkable(bool theIsShrinkable); + + bool + IsShrunkable(); + + bool + IsShrunk(); + + virtual + void + SetShrink(); + + virtual + void + UnShrink(); + //@} + + /** @name For representation mamnagement purpose */ + virtual + void + SetRepresentation(SVTK::Representation::Type theMode); + + SVTK::Representation::Type + GetRepresentation(); + + virtual + float + GetDefaultPointSize(); + + virtual + float + GetDefaultLineWidth(); + + bool + IsShaded(); + + void + SetShaded(bool theShaded); + //@} + + virtual + void + Render(vtkRenderer *, vtkMapper *); + + protected: + SVTK::Representation::Type myRepresentation; + vtkProperty *myProperty; + bool myIsShaded; + + //! To initialize internal pipeline + void + InitPipeLine(vtkMapper* theMapper); + + VTKViewer_GeometryFilter *myGeomFilter; + VTKViewer_TransformFilter *myTransformFilter; + std::vector myPassFilter; + vtkShrinkFilter* myShrinkFilter; + vtkDataSetMapper* myMapper; + + bool myIsShrinkable; + bool myIsShrunk; + + bool myIsResolveCoincidentTopology; + float myPolygonOffsetFactor; + float myPolygonOffsetUnits; + + void SetPolygonOffsetParameters(float factor, float units); + void GetPolygonOffsetParameters(float& factor, float& units); + + SVTK_DeviceActor(); + ~SVTK_DeviceActor(); + + private: + SVTK_DeviceActor(const SVTK_DeviceActor&); // Not implemented + void operator=(const SVTK_DeviceActor&); // Not implemented + +}; + + +#endif //SVTK_DEVICE_ACTOR_H diff --git a/src/SVTK/SVTK_Event.h b/src/SVTK/SVTK_Event.h new file mode 100644 index 000000000..f4c1c42ec --- /dev/null +++ b/src/SVTK/SVTK_Event.h @@ -0,0 +1,68 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : Alexander SLADKOV +// Module : SALOME +// $Header$ + +#ifndef SVTK_Event_h +#define SVTK_Event_h + +#include + +namespace SVTK +{ + enum Event + { + SpaceMouseMoveEvent = vtkCommand::UserEvent + 1000, + SpaceMouseButtonEvent, + PanLeftEvent, + PanRightEvent, + PanUpEvent, + PanDownEvent, + ZoomInEvent, + ZoomOutEvent, + RotateLeftEvent, + RotateRightEvent, + RotateUpEvent, + RotateDownEvent, + PlusSpeedIncrementEvent, + MinusSpeedIncrementEvent, + SetSpeedIncrementEvent, + + SetSMDecreaseSpeedEvent, + SetSMIncreaseSpeedEvent, + SetSMDominantCombinedSwitchEvent, + + StartZoom, + StartPan, + StartRotate, + StartGlobalPan, + StartFitArea, + + LastEvent + }; +} + +#endif diff --git a/src/SVTK/SVTK_FontWidget.cxx b/src/SVTK/SVTK_FontWidget.cxx new file mode 100644 index 000000000..edaa9a6c0 --- /dev/null +++ b/src/SVTK/SVTK_FontWidget.cxx @@ -0,0 +1,149 @@ +// VISU VISUGUI : GUI for SMESH component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : Sergey LITONIN +// Module : + +#include "SVTK_FontWidget.h" + +#include +#include +#include +#include + +#include + +/*! + * Class : SVTK_FontWidget + * Description : Dialog for specifynig font + */ + +//======================================================================= +// name : SVTK_FontWidget +// Purpose : Constructor +//======================================================================= +SVTK_FontWidget::SVTK_FontWidget( QWidget* theParent ) +: QHBox( theParent ) +{ + setSpacing( 5 ); + myColorBtn = new QToolButton( this ); + myColorBtn->setMinimumWidth( 20 ); + + myFamily = new QComboBox( this ); + myFamily->insertItem( tr( "ARIAL" ) ); + myFamily->insertItem( tr( "COURIER" ) ); + myFamily->insertItem( tr( "TIMES" ) ); + + myBold = new QCheckBox( tr( "BOLD" ), this ); + myItalic = new QCheckBox( tr( "ITALIC" ), this ); + myShadow = new QCheckBox( tr( "SHADOW" ), this ); + + connect( myColorBtn, SIGNAL( clicked() ), SLOT( onColor() ) ); +} + +//======================================================================= +// name : ~SVTK_FontWidget +// Purpose : Destructor +//======================================================================= +SVTK_FontWidget::~SVTK_FontWidget() +{ +} + +//======================================================================= +// name : SetColor +// Purpose : +//======================================================================= +void SVTK_FontWidget::SetColor( const QColor& theColor ) +{ + myColorBtn->setPaletteBackgroundColor( theColor ); +} + +//======================================================================= +// name : GetColor +// Purpose : +//======================================================================= +QColor SVTK_FontWidget::GetColor() const +{ + return myColorBtn->paletteBackgroundColor(); +} + +//======================================================================= +// name : onColor +// Purpose : +//======================================================================= +void SVTK_FontWidget::onColor() +{ + QColor aColor = QColorDialog::getColor( GetColor(), this ); + if ( aColor.isValid() ) + SetColor( aColor ); +} + +//======================================================================= +// name : SetData +// Purpose : +//======================================================================= +void SVTK_FontWidget::SetData( const QColor& theColor, + const int theFamily, + const bool theBold, + const bool theItalic, + const bool theShadow ) +{ + SetColor( theColor ); + + if ( theFamily == VTK_ARIAL ) + myFamily->setCurrentItem( 0 ); + else if ( theFamily == VTK_COURIER ) + myFamily->setCurrentItem( 1 ); + else + myFamily->setCurrentItem( 2 ); + + myBold->setChecked( theBold ); + myItalic->setChecked( theItalic ); + myShadow->setChecked( theShadow ); +} + +//======================================================================= +// name : GetData +// Purpose : +//======================================================================= +void SVTK_FontWidget::GetData( QColor& theColor, + int& theFamily, + bool& theBold, + bool& theItalic, + bool& theShadow ) const +{ + theColor = GetColor(); + + int anItem =myFamily->currentItem(); + if ( anItem == 0 ) + theFamily = VTK_ARIAL; + else if ( anItem == 1 ) + theFamily = VTK_COURIER; + else + theFamily = VTK_TIMES; + + theBold = myBold->isChecked(); + theItalic = myItalic->isChecked(); + theShadow = myShadow->isChecked(); +} diff --git a/src/SVTK/SVTK_FontWidget.h b/src/SVTK/SVTK_FontWidget.h new file mode 100644 index 000000000..c06e1e459 --- /dev/null +++ b/src/SVTK/SVTK_FontWidget.h @@ -0,0 +1,68 @@ +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : Sergey LITONIN +// Module : + + +#ifndef SVTK_FontWidget_H +#define SVTK_FontWidget_H + +#include + +class QToolButton; +class QComboBox; +class QCheckBox; +class QColor; + + +/*! + * Class : SVTK_FontWidget + * Description : Dialog for specifynig font + */ +class SVTK_FontWidget : public QHBox +{ + Q_OBJECT + +public: + SVTK_FontWidget( QWidget* ); + virtual ~SVTK_FontWidget(); + + void SetColor( const QColor& ); + QColor GetColor() const; + + void SetData( const QColor&, const int, const bool, const bool, const bool ); + + void GetData( QColor&, int&, bool&, bool&, bool& ) const; + +private slots: + void onColor(); + +private: + QToolButton* myColorBtn; + QComboBox* myFamily; + QCheckBox* myBold; + QCheckBox* myItalic; + QCheckBox* myShadow; +}; + +#endif diff --git a/src/SVTK/SVTK_Functor.h b/src/SVTK/SVTK_Functor.h index bc7e2f720..b47d26e6c 100644 --- a/src/SVTK/SVTK_Functor.h +++ b/src/SVTK/SVTK_Functor.h @@ -27,13 +27,26 @@ #include "SALOME_InteractiveObject.hxx" -namespace VTK +/*! + \file SVTK_Functor.h + This file contains numbers of functors that allows user to perform corresponding operations with existing presentations. + Combination with algorithms it gives powerful, flexible and simple to extend way to introduce new type of operation. +*/ + +namespace SVTK { + using namespace VTK; + + //! This functor check, if the actor have pointed entry template struct TIsSameEntry { std::string myEntry; - TIsSameEntry(const char* theEntry): myEntry(theEntry) {} + //! To construct the functor + TIsSameEntry(const char* theEntry): + myEntry(theEntry) + {} + //! To calculate the functor bool operator()(TActor* theActor) { if ( theActor->hasIO() ) @@ -48,13 +61,16 @@ namespace VTK //---------------------------------------------------------------- + //! This functor check, if the actor point to the same #SALOME_InteractiveObject template struct TIsSameIObject { Handle(SALOME_InteractiveObject) myIObject; + //! To construct the functor TIsSameIObject(const Handle(SALOME_InteractiveObject)& theIObject): myIObject(theIObject) {} + //! To calculate the functor bool operator()(TActor* theActor) { if(theActor->hasIO()) @@ -68,11 +84,18 @@ namespace VTK //---------------------------------------------------------------- + /*! + This highlight every input actor + */ template struct THighlight { bool myIsHighlight; - THighlight(bool theIsHighlight): myIsHighlight( theIsHighlight ) {} + //! To construct the functor + THighlight(bool theIsHighlight): + myIsHighlight( theIsHighlight ) + {} + //! To calculate the functor void operator()(TActor* theActor) { if(theActor->GetVisibility() && theActor->GetMapper()) diff --git a/src/SVTK/SVTK_GenericRenderWindowInteractor.cxx b/src/SVTK/SVTK_GenericRenderWindowInteractor.cxx new file mode 100644 index 000000000..e3cb3c8e2 --- /dev/null +++ b/src/SVTK/SVTK_GenericRenderWindowInteractor.cxx @@ -0,0 +1,138 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#include "SVTK_GenericRenderWindowInteractor.h" +#include "SVTK_Selector.h" + +#include +#include + +#include + +using namespace std; + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(QVTK_GenericRenderWindowInteractor); + +QVTK_GenericRenderWindowInteractor +::QVTK_GenericRenderWindowInteractor() +{ + myTimer = new QTimer( ) ; + connect(myTimer, SIGNAL(timeout()), this, SLOT(OnTimeOut())) ; +} + +QVTK_GenericRenderWindowInteractor +::~QVTK_GenericRenderWindowInteractor() +{ + delete myTimer; +} + + +//---------------------------------------------------------------------------- +void +QVTK_GenericRenderWindowInteractor +::OnTimeOut() +{ + if( GetEnabled() ) { + this->InvokeEvent(vtkCommand::TimerEvent,NULL); + } +} + +int +QVTK_GenericRenderWindowInteractor +::CreateTimer(int vtkNotUsed(timertype)) +{ + // + // Start a one-shot timer for ms. + // + static int DELAY = 1; + myTimer->start(DELAY,TRUE); + return 1; +} + +int +QVTK_GenericRenderWindowInteractor +::DestroyTimer(void) +{ + // + // :TRICKY: Tue May 2 00:17:32 2000 Pagey + // + // QTimer will automatically expire after 10ms. So + // we do not need to do anything here. In fact, we + // should not even Stop() the QTimer here because doing + // this will skip some of the processing that the TimerFunc() + // does and will result in undesirable effects. For + // example, this will result in vtkLODActor to leave + // the models in low-res mode after the mouse stops + // moving. + // + return 1; +} + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(SVTK_GenericRenderWindowInteractor); + +SVTK_GenericRenderWindowInteractor +::SVTK_GenericRenderWindowInteractor(): + myRenderWidget(NULL) +{ +} + +SVTK_GenericRenderWindowInteractor +::~SVTK_GenericRenderWindowInteractor() +{ +} + +SVTK_Selector* +SVTK_GenericRenderWindowInteractor +::GetSelector() +{ + return mySelector.GetPointer(); +} + +void +SVTK_GenericRenderWindowInteractor +::SetSelector(SVTK_Selector* theSelector) +{ + mySelector = theSelector; +} + +QWidget* +SVTK_GenericRenderWindowInteractor +::GetRenderWidget() +{ + return myRenderWidget; +} + +void +SVTK_GenericRenderWindowInteractor +::SetRenderWidget(QWidget* theRenderWidget) +{ + myRenderWidget = theRenderWidget; +} diff --git a/src/SVTK/SVTK_GenericRenderWindowInteractor.h b/src/SVTK/SVTK_GenericRenderWindowInteractor.h new file mode 100644 index 000000000..d15fdc557 --- /dev/null +++ b/src/SVTK/SVTK_GenericRenderWindowInteractor.h @@ -0,0 +1,126 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#ifndef SVTK_GenericRenderWindowInteractor_h +#define SVTK_GenericRenderWindowInteractor_h + +#include "SVTK.h" + +#include +#include +#include + +class QTimer; +class QWidget; + +class SVTK_Selector; +class SVTK_Renderer; + + +//============================================================================ +//! Introduction of the class is intended to implement Qt based #CreateTimer and #DestroyTimer functionality. +/*! + The class intendes to implement platform indepenedant subclass of vtkRenderWindowInteractor. + This is done by usage of Qt library. + \note + The Signal/Slot mechanism used by Qt requires that QObject + appear as the first class when using multiple inheritance. + Hence the order of the two classes QObject and vtkRenderWindowInteractor + matters here. So, be careful, not to change the sequence of the inheritance by accident. +*/ +class SVTK_EXPORT QVTK_GenericRenderWindowInteractor: + public QObject, + public vtkGenericRenderWindowInteractor +{ + Q_OBJECT; + + public: + static QVTK_GenericRenderWindowInteractor* New(); + vtkTypeMacro(QVTK_GenericRenderWindowInteractor,vtkGenericRenderWindowInteractor); + + //! Starts the QTimer instance on defined microseconds + virtual + int + CreateTimer( int ) ; + + //! Stops the QTimer instance + virtual + int + DestroyTimer() ; + + protected slots: + //! The slot connects to QTimer::timeout signal to invoke vtkCommand::TimerEvent + void + OnTimeOut(); + + protected: + QVTK_GenericRenderWindowInteractor(); //!< Instatiate QTimer + ~QVTK_GenericRenderWindowInteractor(); //!< Destroy the instance of QTimer + + QTimer* myTimer; //!< Qt timer device +}; + + +//============================================================================ +//! This class introduce SALOME specific to the base one +/*! + In this class new members is added (#mySelector and #myRenderWidget). + They are used for initialization of #SVTK_InteractorStyle by redefinition of + #SVTK_InteractorStyle::SetInteractor method +*/ +class SVTK_EXPORT SVTK_GenericRenderWindowInteractor: public QVTK_GenericRenderWindowInteractor +{ + public: + static SVTK_GenericRenderWindowInteractor* New(); + vtkTypeMacro(SVTK_GenericRenderWindowInteractor,QVTK_GenericRenderWindowInteractor); + + //! To get access to SVTK_Selector + SVTK_Selector* + GetSelector(); + + //! To initialize mySelector field + void + SetSelector(SVTK_Selector* theSelector); + + //! To get access to QWidget, where vtkRenderWindow maps to. + QWidget* + GetRenderWidget(); + + //! To initialize myRenderWidget field. + void + SetRenderWidget(QWidget* theRenderWidget); + + protected: + SVTK_GenericRenderWindowInteractor(); + ~SVTK_GenericRenderWindowInteractor(); + + vtkSmartPointer mySelector; //!< Keeps a pointer to SVTK_Selector + QWidget* myRenderWidget; //!< Keeps a pointer to QWidget, where vtkRenderWindow maps to. +}; + +#endif diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 4e8d08df1..963aa1894 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -21,31 +21,26 @@ // // // -// File : SVTK_InteractorStyle.cxx -// Author : Christophe ATTANASIO +// File : +// Author : // Module : SALOME // $Header$ #include "SVTK_InteractorStyle.h" -#include "VTKViewer_CellRectPicker.h" #include "VTKViewer_Utilities.h" -#include "VTKViewer_RectPicker.h" +#include "SVTK_GenericRenderWindowInteractor.h" -#include "SVTK_RenderWindowInteractor.h" -#include "SVTK_RenderWindow.h" -#include "SVTK_ViewWindow.h" - -#include "SALOME_Actor.h" -#include "SVTK_Actor.h" +#include "SVTK_Selection.h" +#include "SVTK_Event.h" #include "SVTK_Selector.h" +#include "SVTK_Functor.h" -#include "SALOME_ListIteratorOfListIO.hxx" -#include "SALOME_ListIO.hxx" +#include "VTKViewer_Algorithm.h" +#include "SVTK_Functor.h" -#include "SUIT_Session.h" -#include "CAM_Application.h" +#include "SALOME_Actor.h" #include #include @@ -53,15 +48,13 @@ #include #include #include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include #include +#include //VRV: porting on Qt 3.0.5 #if QT_VERSION >= 0x030005 #include @@ -71,136 +64,128 @@ using namespace std; - namespace { - int - GetEdgeId(vtkPicker *thePicker, SALOME_Actor *theActor, int theObjId) + inline + void + GetEventPosition(vtkRenderWindowInteractor* theInteractor, + int& theX, + int& theY) { - int anEdgeId = -1; - if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) { - float aPickPosition[3]; - thePicker->GetPickPosition(aPickPosition); - float aMinDist = 1000000.0, aDist = 0; - for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){ - if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){ - int subId; float pcoords[3], closestPoint[3], weights[3]; - aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights); - if (aDist < aMinDist) { - aMinDist = aDist; - anEdgeId = i; - } - } - } - } - return anEdgeId; + theInteractor->GetEventPosition(theX,theY); + theY = theInteractor->GetSize()[1] - theY - 1; } - - - bool CheckDimensionId(Selection_Mode theMode, SALOME_Actor *theActor, vtkIdType theObjId){ - switch(theMode){ - case CellSelection: - return true; - case EdgeSelection: - return ( theActor->GetObjDimension( theObjId ) == 1 ); - case FaceSelection: - return ( theActor->GetObjDimension( theObjId ) == 2 ); - case VolumeSelection: - return ( theActor->GetObjDimension( theObjId ) == 3 ); - }; - return false; + //================================================================== + // function : GetFirstSALOMEActor + // purpose : + //================================================================== + struct THaveIO + { + bool + operator()(SALOME_Actor* theActor) + { + return theActor->hasIO(); + } + }; + + inline + SALOME_Actor* + GetFirstSALOMEActor(vtkPicker *thePicker) + { + return VTK::Find(thePicker->GetActors(),THaveIO()); } -} - +} + + //---------------------------------------------------------------------------- vtkStandardNewMacro(SVTK_InteractorStyle); //---------------------------------------------------------------------------- - SVTK_InteractorStyle -::SVTK_InteractorStyle() +::SVTK_InteractorStyle(): + mySelectionEvent(new SVTK_SelectionEvent()), + myPicker(vtkPicker::New()), + myLastHighlitedActor(NULL), + myLastPreHighlitedActor(NULL), + myControllerIncrement(SVTK_ControllerIncrement::New()), + myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New()) { - myPreViewActor = NULL; - myInteractor = NULL; - myViewWindow = NULL; - myGUIWindow = NULL; + myPicker->Delete(); + this->MotionFactor = 10.0; this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE; this->RadianToDegree = 180.0 / vtkMath::Pi(); this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE; + loadCursors(); - myPreSelectionActor = SVTK_Actor::New(); - myPreSelectionActor->GetProperty()->SetColor(0,1,1); - myPreSelectionActor->GetProperty()->SetLineWidth(5); - myPreSelectionActor->GetProperty()->SetPointSize(5); + // set custom event handling function (to handle 3d space mouse events) + EventCallbackCommand->SetCallback( SVTK_InteractorStyle::ProcessEvents ); - OnSelectionModeChanged(); + // set default values of properties. user may edit them in preferences. + mySMDecreaseSpeedBtn = 1; + mySMIncreaseSpeedBtn = 2; + mySMDominantCombinedSwitchBtn = 9; + // + myControllerIncrement->Delete(); + myControllerOnKeyDown->Delete(); } //---------------------------------------------------------------------------- SVTK_InteractorStyle ::~SVTK_InteractorStyle() { - myViewWindow->RemoveActor(myPreSelectionActor); } //---------------------------------------------------------------------------- -SVTK_Selector* +QWidget* SVTK_InteractorStyle -::GetSelector() +::GetRenderWidget() { - return myViewWindow->GetSelector(); + return myInteractor->GetRenderWidget(); } -//---------------------------------------------------------------------------- -void +SVTK_Selector* SVTK_InteractorStyle -::setPreselectionProp(const double& theRed, - const double& theGreen, - const double& theBlue, - const int& theWidth) +::GetSelector() { - if ( myPreSelectionActor->GetProperty() == 0 ) - return; - myPreSelectionActor->GetProperty()->SetColor(theRed, theGreen, theBlue); - myPreSelectionActor->GetProperty()->SetLineWidth(theWidth); - myPreSelectionActor->GetProperty()->SetPointSize(theWidth); + return myInteractor->GetSelector(); } //---------------------------------------------------------------------------- -void +SVTK_SelectionEvent* SVTK_InteractorStyle -::SetInteractor(vtkRenderWindowInteractor *theInteractor) +::GetSelectionEvent() { - myInteractor = dynamic_cast(theInteractor); - Superclass::SetInteractor(theInteractor); -} + mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode(); -//---------------------------------------------------------------------------- -int -SVTK_InteractorStyle -::GetState() -{ - return State | ForcedState; -} + mySelectionEvent->myIsCtrl = Interactor->GetControlKey(); + mySelectionEvent->myIsShift = Interactor->GetShiftKey(); -//---------------------------------------------------------------------------- -void -SVTK_InteractorStyle -::setViewWindow(SVTK_ViewWindow* theViewWindow) -{ - myViewWindow = theViewWindow; - myViewWindow->AddActor(myPreSelectionActor); - myPreSelectionActor->Delete(); + mySelectionEvent->myLastX = mySelectionEvent->myX; + mySelectionEvent->myLastY = mySelectionEvent->myY; + + GetEventPosition( this->Interactor, mySelectionEvent->myX, mySelectionEvent->myY ); + + return mySelectionEvent.get(); } //---------------------------------------------------------------------------- -void +SVTK_SelectionEvent* SVTK_InteractorStyle -::setGUIWindow(QWidget* theWindow) +::GetSelectionEventFlipY() { - myGUIWindow = theWindow; + mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode(); + + mySelectionEvent->myIsCtrl = Interactor->GetControlKey(); + mySelectionEvent->myIsShift = Interactor->GetShiftKey(); + + mySelectionEvent->myLastX = mySelectionEvent->myX; + mySelectionEvent->myLastY = mySelectionEvent->myY; + + this->Interactor->GetEventPosition(mySelectionEvent->myX, mySelectionEvent->myY); + + return mySelectionEvent.get(); } //---------------------------------------------------------------------------- @@ -208,29 +193,24 @@ void SVTK_InteractorStyle ::RotateXY(int dx, int dy) { - double rxf; - double ryf; - vtkCamera *cam; - - if (this->CurrentRenderer == NULL) - { - return; - } + if(GetCurrentRenderer() == NULL) + return; - int *size = this->CurrentRenderer->GetRenderWindow()->GetSize(); - this->DeltaElevation = -20.0 / size[1]; - this->DeltaAzimuth = -20.0 / size[0]; + int *size = GetCurrentRenderer()->GetRenderWindow()->GetSize(); + double aDeltaElevation = -20.0 / size[1]; + double aDeltaAzimuth = -20.0 / size[0]; - rxf = (double)dx * this->DeltaAzimuth * this->MotionFactor; - ryf = (double)dy * this->DeltaElevation * this->MotionFactor; + double rxf = double(dx) * aDeltaAzimuth * this->MotionFactor; + double ryf = double(dy) * aDeltaElevation * this->MotionFactor; - cam = this->CurrentRenderer->GetActiveCamera(); + vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera(); cam->Azimuth(rxf); cam->Elevation(ryf); cam->OrthogonalizeViewUp(); - ::ResetCameraClippingRange(this->CurrentRenderer); - //this->Interactor->Render(); - myGUIWindow->update(); + + GetCurrentRenderer()->ResetCameraClippingRange(); + + this->Render(); } //---------------------------------------------------------------------------- @@ -239,8 +219,7 @@ SVTK_InteractorStyle ::PanXY(int x, int y, int oldX, int oldY) { TranslateView(x, y, oldX, oldY); - //this->Interactor->Render(); - myGUIWindow->update(); + this->Render(); } @@ -249,23 +228,23 @@ void SVTK_InteractorStyle ::DollyXY(int dx, int dy) { - if (this->CurrentRenderer == NULL) return; + if (GetCurrentRenderer() == NULL) + return; - double dxf = this->MotionFactor * (double)(dx) / (double)(this->CurrentRenderer->GetCenter()[1]); - double dyf = this->MotionFactor * (double)(dy) / (double)(this->CurrentRenderer->GetCenter()[1]); + double dxf = this->MotionFactor * (double)(dx) / (double)(GetCurrentRenderer()->GetCenter()[1]); + double dyf = this->MotionFactor * (double)(dy) / (double)(GetCurrentRenderer()->GetCenter()[1]); double zoomFactor = pow((double)1.1, dxf + dyf); - vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera(); + vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera(); if (aCam->GetParallelProjection()) aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor); else{ aCam->Dolly(zoomFactor); - ::ResetCameraClippingRange(this->CurrentRenderer); + GetCurrentRenderer()->ResetCameraClippingRange(); } - //this->Interactor->Render(); - myGUIWindow->update(); + this->Render(); } //---------------------------------------------------------------------------- @@ -275,25 +254,122 @@ SVTK_InteractorStyle { vtkCamera *cam; - if (this->CurrentRenderer == NULL) - { - return; - } + if (GetCurrentRenderer() == NULL) + return; - double newAngle = atan2((double)(y - this->CurrentRenderer->GetCenter()[1]), - (double)(x - this->CurrentRenderer->GetCenter()[0])); - double oldAngle = atan2((double)(oldY -this->CurrentRenderer->GetCenter()[1]), - (double)(oldX - this->CurrentRenderer->GetCenter()[0])); + double newAngle = atan2((double)(y - GetCurrentRenderer()->GetCenter()[1]), + (double)(x - GetCurrentRenderer()->GetCenter()[0])); + double oldAngle = atan2((double)(oldY -GetCurrentRenderer()->GetCenter()[1]), + (double)(oldX - GetCurrentRenderer()->GetCenter()[0])); newAngle *= this->RadianToDegree; oldAngle *= this->RadianToDegree; - cam = this->CurrentRenderer->GetActiveCamera(); + cam = GetCurrentRenderer()->GetActiveCamera(); cam->Roll(newAngle - oldAngle); cam->OrthogonalizeViewUp(); - //this->Interactor->Render(); - myGUIWindow->update(); + this->Render(); +} + + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnConfigure() +{ + this->FindPokedRenderer(0,0); + this->GetCurrentRenderer()->InvokeEvent(vtkCommand::ConfigureEvent,NULL); +} + + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnMouseMove() +{ + int x, y; + GetEventPosition( this->Interactor, x, y ); + this->OnMouseMove( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); +} + + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnLeftButtonDown() +{ + int x, y; + GetEventPosition( this->Interactor, x, y ); + this->OnLeftButtonDown( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); +} + + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnLeftButtonUp() +{ + int x, y; + GetEventPosition( this->Interactor, x, y ); + this->OnLeftButtonUp( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); +} + + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnMiddleButtonDown() +{ + int x, y; + GetEventPosition( this->Interactor, x, y ); + this->OnMiddleButtonDown( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); +} + + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnMiddleButtonUp() +{ + int x, y; + GetEventPosition( this->Interactor, x, y ); + this->OnMiddleButtonUp( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); +} + + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnRightButtonDown() +{ + int x, y; + GetEventPosition( this->Interactor, x, y ); + this->OnRightButtonDown( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnRightButtonUp() +{ + int x, y; + GetEventPosition( this->Interactor, x, y ); + this->OnRightButtonUp( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); } @@ -318,14 +394,10 @@ SVTK_InteractorStyle ::OnLeftButtonDown(int ctrl, int shift, int x, int y) { - if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) { - this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL); - return; - } this->FindPokedRenderer(x, y); - if (this->CurrentRenderer == NULL) { + if(GetCurrentRenderer() == NULL) return; - } + myShiftState = shift; // finishing current viewer operation if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) { @@ -369,16 +441,10 @@ SVTK_InteractorStyle int shift, int x, int y) { - if (this->HasObserver(vtkCommand::MiddleButtonPressEvent)) - { - this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL); - return; - } this->FindPokedRenderer(x, y); - if (this->CurrentRenderer == NULL) - { - return; - } + if(GetCurrentRenderer() == NULL) + return; + myShiftState = shift; // finishing current viewer operation if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) { @@ -420,16 +486,10 @@ SVTK_InteractorStyle int shift, int x, int y) { - if (this->HasObserver(vtkCommand::RightButtonPressEvent)) - { - this->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL); - return; - } this->FindPokedRenderer(x, y); - if (this->CurrentRenderer == NULL) - { - return; - } + if(GetCurrentRenderer() == NULL) + return; + myShiftState = shift; // finishing current viewer operation if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) { @@ -547,33 +607,17 @@ void SVTK_InteractorStyle ::loadCursors() { - myDefCursor = QCursor(ArrowCursor); - myHandCursor = QCursor(PointingHandCursor); - myPanCursor = QCursor(SizeAllCursor); + myDefCursor = QCursor(Qt::ArrowCursor); + myHandCursor = QCursor(Qt::PointingHandCursor); + myPanCursor = QCursor(Qt::SizeAllCursor); myZoomCursor = QCursor(QPixmap(imageZoomCursor)); myRotateCursor = QCursor(QPixmap(imageRotateCursor)); mySpinCursor = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!! - myGlobalPanCursor = QCursor(CrossCursor); + myGlobalPanCursor = QCursor(Qt::CrossCursor); myCursorState = false; } -//---------------------------------------------------------------------------- -// event filter - controls mouse and keyboard events during viewer operations -bool -SVTK_InteractorStyle -::eventFilter(QObject* object, QEvent* event) -{ - if (!myGUIWindow) return false; - if ( (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress) && object != myGUIWindow) - { - qApp->removeEventFilter(this); - startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE); - } - return QObject::eventFilter(object, event); -} - - //---------------------------------------------------------------------------- // starts Zoom operation (e.g. through menu command) void @@ -587,7 +631,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM; - qApp->installEventFilter(this); } @@ -604,7 +647,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN; - qApp->installEventFilter(this); } //---------------------------------------------------------------------------- @@ -620,7 +662,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE; - qApp->installEventFilter(this); } @@ -637,7 +678,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN; - qApp->installEventFilter(this); } @@ -655,7 +695,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT; - qApp->installEventFilter(this); } @@ -674,28 +713,11 @@ SVTK_InteractorStyle ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN; // store current zoom scale - vtkCamera *cam = this->CurrentRenderer->GetActiveCamera(); - myScale = cam->GetParallelScale(); - - if (myViewWindow) myViewWindow->onFitAll(); - - if (myGUIWindow) myGUIWindow->update(); - - qApp->installEventFilter(this); -} + myScale = GetCurrentRenderer()->GetActiveCamera()->GetParallelScale(); + GetCurrentRenderer()->ResetCamera(); -//---------------------------------------------------------------------------- -// returns TRUE if needs redrawing -bool -SVTK_InteractorStyle -::needsRedrawing() -{ - return State == VTK_INTERACTOR_STYLE_CAMERA_ZOOM || - State == VTK_INTERACTOR_STYLE_CAMERA_PAN || - State == VTK_INTERACTOR_STYLE_CAMERA_ROTATE || - State == VTK_INTERACTOR_STYLE_CAMERA_SPIN || - State == VTK_INTERACTOR_STYLE_CAMERA_NONE; + this->Render(); } @@ -708,30 +730,31 @@ SVTK_InteractorStyle const int right, const int bottom) { - if (this->CurrentRenderer == NULL) return; + if (GetCurrentRenderer() == NULL) + return; // move camera int x = (left + right)/2; int y = (top + bottom)/2; - int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize(); + int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize(); int oldX = aSize[0]/2; int oldY = aSize[1]/2; TranslateView(oldX, oldY, x, y); // zoom camera - double dxf = (double)(aSize[0]) / (double)(abs(right - left)); - double dyf = (double)(aSize[1]) / (double)(abs(bottom - top)); + double dxf = right == left ? 1.0 : (double)(aSize[0]) / (double)(abs(right - left)); + double dyf = bottom == top ? 1.0 : (double)(aSize[1]) / (double)(abs(bottom - top)); double zoomFactor = (dxf + dyf)/2 ; - vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera(); + vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera(); if(aCam->GetParallelProjection()) aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor); else{ aCam->Dolly(zoomFactor); - ::ResetCameraClippingRange(this->CurrentRenderer); + GetCurrentRenderer()->ResetCameraClippingRange(); } - myGUIWindow->update(); + this->Render(); } @@ -772,37 +795,37 @@ void SVTK_InteractorStyle ::setCursor(const int operation) { - if (!myGUIWindow) return; + if (!GetRenderWidget()) return; switch (operation) { case VTK_INTERACTOR_STYLE_CAMERA_ZOOM: - myGUIWindow->setCursor(myZoomCursor); + GetRenderWidget()->setCursor(myZoomCursor); myCursorState = true; break; case VTK_INTERACTOR_STYLE_CAMERA_PAN: - myGUIWindow->setCursor(myPanCursor); + GetRenderWidget()->setCursor(myPanCursor); myCursorState = true; break; case VTK_INTERACTOR_STYLE_CAMERA_ROTATE: - myGUIWindow->setCursor(myRotateCursor); + GetRenderWidget()->setCursor(myRotateCursor); myCursorState = true; break; case VTK_INTERACTOR_STYLE_CAMERA_SPIN: - myGUIWindow->setCursor(mySpinCursor); + GetRenderWidget()->setCursor(mySpinCursor); myCursorState = true; break; case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN: - myGUIWindow->setCursor(myGlobalPanCursor); + GetRenderWidget()->setCursor(myGlobalPanCursor); myCursorState = true; break; case VTK_INTERACTOR_STYLE_CAMERA_FIT: case VTK_INTERACTOR_STYLE_CAMERA_SELECT: - myGUIWindow->setCursor(myHandCursor); + GetRenderWidget()->setCursor(myHandCursor); myCursorState = true; break; case VTK_INTERACTOR_STYLE_CAMERA_NONE: default: - myGUIWindow->setCursor(myDefCursor); + GetRenderWidget()->setCursor(myDefCursor); myCursorState = false; break; } @@ -815,14 +838,14 @@ void SVTK_InteractorStyle ::onStartOperation() { - if (!myGUIWindow) return; + if (!GetRenderWidget()) return; // VSV: LOD actor activisation // this->Interactor->GetRenderWindow()->SetDesiredUpdateRate(this->Interactor->GetDesiredUpdateRate()); switch (State) { case VTK_INTERACTOR_STYLE_CAMERA_SELECT: case VTK_INTERACTOR_STYLE_CAMERA_FIT: { - QPainter p(myGUIWindow); + QPainter p(GetRenderWidget()); p.setPen(Qt::lightGray); p.setRasterOp(Qt::XorROP); p.drawRect(QRect(myPoint, myOtherPoint)); @@ -844,285 +867,81 @@ void SVTK_InteractorStyle ::onFinishOperation() { - if (!myGUIWindow) + if (!GetRenderWidget()) return; // VSV: LOD actor activisation // rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate()); - Selection_Mode aSelectionMode = myViewWindow->SelectionMode(); - bool aSelActiveCompOnly = false; - - QString aComponentDataType; - if(SUIT_Session* aSession = SUIT_Session::session()) - if(SUIT_Application* aSUITApp = aSession->activeApplication()) - if(CAM_Application* aCAMApp = dynamic_cast(aSUITApp)) - if(CAM_Module* aModule = aCAMApp->activeModule()) - aComponentDataType = aModule->name(); + SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY(); switch (State) { case VTK_INTERACTOR_STYLE_CAMERA_SELECT: case VTK_INTERACTOR_STYLE_CAMERA_FIT: { - QPainter p(myGUIWindow); - p.setPen(Qt::lightGray); - p.setRasterOp(Qt::XorROP); - QRect rect(myPoint, myOtherPoint); - p.drawRect(rect); - rect = rect.normalize(); + QPainter aPainter(GetRenderWidget()); + aPainter.setPen(Qt::lightGray); + aPainter.setRasterOp(Qt::XorROP); + QRect aRect(myPoint, myOtherPoint); + aPainter.drawRect(aRect); + aRect = aRect.normalize(); + if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) { // making fit rect opeation int w, h; - myInteractor->GetSize(w, h); - int x1, y1, x2, y2; - x1 = rect.left(); - y1 = h - rect.top() - 1; - x2 = rect.right(); - y2 = h - rect.bottom() - 1; + Interactor->GetSize(w, h); + int x1 = aRect.left(); + int y1 = h - aRect.top() - 1; + int x2 = aRect.right(); + int y2 = h - aRect.bottom() - 1; fitRect(x1, y1, x2, y2); } else { if (myPoint == myOtherPoint) { // process point selection - int w, h, x, y; - myInteractor->GetSize(w, h); - x = myPoint.x(); - y = h - myPoint.y() - 1; - - this->FindPokedRenderer(x, y); - myInteractor->StartPickCallback(); - - vtkPicker* aPicker = vtkPicker::SafeDownCast(myInteractor->GetPicker()); - aPicker->Pick(x, y, 0.0, this->CurrentRenderer); - - SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aPicker->GetActor()); - - if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) { - int aVtkId = picker->GetCellId(); - if ( aVtkId >= 0 && aSActor && aSActor->hasIO() && IsValid( aSActor, aVtkId ) ) { - int anObjId = aSActor->GetElemObjId(aVtkId); - if(anObjId >= 0){ - Handle(SALOME_InteractiveObject) anIO = aSActor->getIO(); - if(aSelectionMode != EdgeOfCellSelection) { - if(CheckDimensionId(aSelectionMode,aSActor,anObjId)){ - if (GetSelector()->IsSelected(anIO)) { - // This IO is already in the selection - GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState); - } else { - if (!myShiftState) { - this->HighlightProp( NULL ); - GetSelector()->ClearIObjects(); - } - GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState); - GetSelector()->AddIObject(aSActor); - } - } - }else{ - if (!myShiftState) { - this->HighlightProp( NULL ); - GetSelector()->ClearIObjects(); - } - int anEdgeId = GetEdgeId(picker,aSActor,anObjId); - if (anEdgeId >= 0) { - GetSelector()->AddOrRemoveIndex(anIO,anObjId,false); - GetSelector()->AddOrRemoveIndex(anIO,-anEdgeId-1,true); - GetSelector()->AddIObject(aSActor); - } - } - } - } else { - this->HighlightProp( NULL ); - GetSelector()->ClearIObjects(); - } - } else if ( vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker) ) { - int aVtkId = picker->GetPointId(); - if ( aVtkId >= 0 && IsValid( aSActor, aVtkId, true ) ) { - if ( aSActor && aSActor->hasIO() ) { - int anObjId = aSActor->GetNodeObjId(aVtkId); - if(anObjId >= 0){ - Handle(SALOME_InteractiveObject) anIO = aSActor->getIO(); - if(GetSelector()->IsSelected(anIO)) { - // This IO is already in the selection - GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState); - } else { - if(!myShiftState) { - this->HighlightProp( NULL ); - GetSelector()->ClearIObjects(); - } - GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState); - GetSelector()->AddIObject(aSActor); - } - } - } - } else { - this->HighlightProp( NULL ); - GetSelector()->ClearIObjects(); - } - } else { - if ( aSActor && aSActor->hasIO() ) { - this->PropPicked++; - Handle(SALOME_InteractiveObject) anIO = aSActor->getIO(); - if(GetSelector()->IsSelected(anIO)) { - // This IO is already in the selection - if(myShiftState) { - GetSelector()->RemoveIObject(aSActor); - } - } - else { - if(!myShiftState) { - this->HighlightProp( NULL ); - GetSelector()->ClearIObjects(); - } - GetSelector()->AddIObject(aSActor); - } - }else{ - // No selection clear all - this->PropPicked = 0; - this->HighlightProp( NULL ); + this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY); + Interactor->StartPickCallback(); + + myPicker->Pick(aSelectionEvent->myX, + aSelectionEvent->myY, + 0.0, + GetCurrentRenderer()); + // + SALOME_Actor* anActor = GetFirstSALOMEActor(myPicker.GetPointer()); + aSelectionEvent->myIsRectangle = false; + if(anActor){ + anActor->Highlight( this, aSelectionEvent, true ); + }else{ + if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != anActor) + myLastHighlitedActor->Highlight( this, aSelectionEvent, false ); + if(!myShiftState) GetSelector()->ClearIObjects(); - } } - myInteractor->EndPickCallback(); - } else { + myLastHighlitedActor = anActor; + } + else { //processing rectangle selection - if(aSelActiveCompOnly && aComponentDataType.isEmpty()) return; - myInteractor->StartPickCallback(); + Interactor->StartPickCallback(); + GetSelector()->StartPickCallback(); + aSelectionEvent->myIsRectangle = true; - if (!myShiftState) { - this->PropPicked = 0; - this->HighlightProp( NULL ); + if(!myShiftState) GetSelector()->ClearIObjects(); - } - // Compute bounds - // vtkCamera *cam = this->CurrentRenderer->GetActiveCamera(); - QRect rect(myPoint, myOtherPoint); - rect = rect.normalize(); - int w, h; - myInteractor->GetSize(w, h); - int x1, y1, x2, y2; - x1 = rect.left(); - y1 = h - rect.top() - 1; - x2 = rect.right(); - y2 = h - rect.bottom() - 1; - - switch (aSelectionMode) { - case NodeSelection: { - if ( vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(myInteractor->GetPicker()) ) { - vtkActorCollection* aListActors = this->CurrentRenderer->GetActors(); - aListActors->InitTraversal(); - while (vtkActor* aActor = aListActors->GetNextActor()) { - if (!aActor->GetVisibility()) - continue; - if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) { - if (aSActor->hasIO()) { - Handle(SALOME_InteractiveObject) anIO = aSActor->getIO(); - if (anIO.IsNull()) - continue; - if (aSelActiveCompOnly && aComponentDataType != anIO->getComponentDataType()) - continue; - if (vtkDataSet* aDataSet = aSActor->GetInput()) { - TColStd_MapOfInteger anIndices; - for(int i = 0; i < aDataSet->GetNumberOfPoints(); i++) { - float aPoint[3]; - aDataSet->GetPoint(i,aPoint); - if (IsInRect(aPoint,x1,y1,x2,y2)){ - float aDisp[3]; - ComputeWorldToDisplay(aPoint[0],aPoint[1],aPoint[2],aDisp); - if(aPointPicker->Pick(aDisp[0],aDisp[1],0.0,CurrentRenderer)){ - if(vtkActorCollection *anActorCollection = aPointPicker->GetActors()){ - if(anActorCollection->IsItemPresent(aSActor)){ - float aPickedPoint[3]; - aPointPicker->GetMapperPosition(aPickedPoint); - vtkIdType aVtkId = aDataSet->FindPoint(aPickedPoint); - if ( aVtkId >= 0 && IsValid( aSActor, aVtkId, true ) ){ - int anObjId = aSActor->GetNodeObjId(aVtkId); - anIndices.Add(anObjId); - } - } - } - } - } - } - if (!anIndices.IsEmpty()) { - GetSelector()->AddOrRemoveIndex(anIO,anIndices,true); // ENK false to true - GetSelector()->AddIObject(aSActor); - anIndices.Clear(); - }else{ - GetSelector()->RemoveIObject(aSActor); - } - } - } + vtkActorCollection* aListActors = GetCurrentRenderer()->GetActors(); + aListActors->InitTraversal(); + while(vtkActor* aActor = aListActors->GetNextActor()){ + if(aActor->GetVisibility()){ + if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)){ + if(aSActor->hasIO()){ + aSActor->Highlight( this, aSelectionEvent, true ); } } } - break; } - case CellSelection: - case EdgeOfCellSelection: - case EdgeSelection: - case FaceSelection: - case VolumeSelection: - { - vtkSmartPointer picker = VTKViewer_CellRectPicker::New(); - picker->SetTolerance(0.001); - picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer); - - vtkActorCollection* aListActors = picker->GetActors(); - aListActors->InitTraversal(); - while(vtkActor* aActor = aListActors->GetNextActor()) { - if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) { - if (aSActor->hasIO()) { - Handle(SALOME_InteractiveObject) anIO = aSActor->getIO(); - if (aSelActiveCompOnly && aComponentDataType != anIO->getComponentDataType()) - continue; - VTKViewer_CellDataSet cellList = picker->GetCellData(aActor); - if ( !cellList.empty() ) { - TColStd_MapOfInteger anIndexes; - VTKViewer_CellDataSet::iterator it; - for ( it = cellList.begin(); it != cellList.end(); ++it ) { - int aCellId = (*it).cellId; - - if ( !IsValid( aSActor, aCellId ) ) - continue; - - int anObjId = aSActor->GetElemObjId(aCellId); - if (anObjId != -1){ - if ( CheckDimensionId(aSelectionMode,aSActor,anObjId) ) { - anIndexes.Add(anObjId); - } - } - } - GetSelector()->AddOrRemoveIndex(anIO,anIndexes,true); - GetSelector()->AddIObject(aSActor); - } - } - } - } - } - break; - case ActorSelection: // objects selection - { - vtkSmartPointer picker = VTKViewer_RectPicker::New(); - picker->SetTolerance(0.001); - picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer); - - vtkActorCollection* aListActors = picker->GetActors(); - aListActors->InitTraversal(); - while(vtkActor* aActor = aListActors->GetNextActor()) { - if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) { - if (aSActor->hasIO()) { - Handle(SALOME_InteractiveObject) anIO = aSActor->getIO(); - GetSelector()->AddIObject(aSActor); - this->PropPicked++; - } - } - } - } // end case 4 - } //end switch - myInteractor->EndPickCallback(); } - myViewWindow->onSelectionChanged(); + Interactor->EndPickCallback(); + GetSelector()->EndPickCallback(); } } break; @@ -1134,55 +953,48 @@ SVTK_InteractorStyle case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN: { int w, h, x, y; - myInteractor->GetSize(w, h); + Interactor->GetSize(w, h); x = myPoint.x(); y = h - myPoint.y() - 1; Place(x, y); } break; } - if (myGUIWindow) myGUIWindow->update(); + this->Render(); } // called during viewer operation when user moves mouse (!put necessary processing here!) +//---------------------------------------------------------------------------- void SVTK_InteractorStyle ::onOperation(QPoint mousePos) { - if (!myGUIWindow) return; - int w, h; - GetInteractor()->GetSize(w, h); + if (!GetRenderWidget()) + return; + switch (State) { case VTK_INTERACTOR_STYLE_CAMERA_PAN: { - // processing panning - //this->FindPokedCamera(mousePos.x(), mousePos.y()); this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y()); myPoint = mousePos; break; } case VTK_INTERACTOR_STYLE_CAMERA_ZOOM: { - // processing zooming - //this->FindPokedCamera(mousePos.x(), mousePos.y()); this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y()); myPoint = mousePos; break; } case VTK_INTERACTOR_STYLE_CAMERA_ROTATE: { - // processing rotation - //this->FindPokedCamera(mousePos.x(), mousePos.y()); this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y()); myPoint = mousePos; break; } case VTK_INTERACTOR_STYLE_CAMERA_SPIN: { - // processing spinning - //this->FindPokedCamera(mousePos.x(), mousePos.y()); this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y()); myPoint = mousePos; break; @@ -1198,7 +1010,7 @@ SVTK_InteractorStyle } case VTK_INTERACTOR_STYLE_CAMERA_FIT: { - QPainter p(myGUIWindow); + QPainter p(GetRenderWidget()); p.setPen(Qt::lightGray); p.setRasterOp(Qt::XorROP); p.drawRect(QRect(myPoint, myOtherPoint)); @@ -1207,182 +1019,73 @@ SVTK_InteractorStyle break; } } - this->LastPos[0] = mousePos.x(); - this->LastPos[1] = h - mousePos.y() - 1; -} - -// called when selection mode changed (!put necessary initialization here!) -void -SVTK_InteractorStyle -::OnSelectionModeChanged() -{ - - myPreSelectionActor->SetVisibility(false); - myElemId = myEdgeId = myNodeId = -1; - mySelectedActor = NULL; } // called when user moves mouse inside viewer window and there is no active viewer operation // (!put necessary processing here!) +//---------------------------------------------------------------------------- void SVTK_InteractorStyle ::onCursorMove(QPoint mousePos) { // processing highlighting - Selection_Mode aSelectionMode = myViewWindow->SelectionMode(); - - int w, h, x, y; - myInteractor->GetSize(w, h); - x = mousePos.x(); y = h - mousePos.y() - 1; + SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY(); + this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY); - this->FindPokedRenderer(x,y); - myInteractor->StartPickCallback(); - myPreSelectionActor->SetVisibility(false); + bool anIsChanged = false; - vtkPicker* aPicker = vtkPicker::SafeDownCast(myInteractor->GetPicker()); - aPicker->Pick(x, y, 0.0, this->CurrentRenderer); + myPicker->Pick(aSelectionEvent->myX, + aSelectionEvent->myY, + 0.0, + GetCurrentRenderer()); + + SALOME_Actor *anActor = GetFirstSALOMEActor(myPicker.GetPointer()); + if (anActor){ + anIsChanged |= anActor->PreHighlight( this, aSelectionEvent, true ); + } - SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aPicker->GetActor()); + if(myLastPreHighlitedActor.GetPointer() && myLastPreHighlitedActor.GetPointer() != anActor) + anIsChanged |= myLastPreHighlitedActor->PreHighlight( this, aSelectionEvent, false ); - if (aSActor && myPreSelectionActor){ - float aPos[3]; - aSActor->GetPosition(aPos); - myPreSelectionActor->SetPosition(aPos); - } + myLastPreHighlitedActor = anActor; - if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) { - int aVtkId = picker->GetCellId(); - if ( aVtkId >= 0 ) { - int anObjId = aSActor->GetElemObjId(aVtkId); - if ( aSActor && aSActor->hasIO() && IsValid( aSActor, aVtkId ) ) { - bool anIsSameObjId = (mySelectedActor == aSActor && myElemId == anObjId); - bool aResult = anIsSameObjId; - if(!anIsSameObjId) { - if(aSelectionMode != EdgeOfCellSelection) { - aResult = CheckDimensionId(aSelectionMode,aSActor,anObjId); - if(aResult){ - mySelectedActor = aSActor; - myElemId = anObjId; - myInteractor->setCellData(anObjId,aSActor,myPreSelectionActor); - } - } - } - if(aSelectionMode == EdgeOfCellSelection){ - int anEdgeId = GetEdgeId(picker,aSActor,anObjId); - bool anIsSameEdgeId = (myEdgeId != anEdgeId) && anIsSameObjId; - aResult = anIsSameEdgeId; - if(!anIsSameEdgeId) { - aResult = (anEdgeId >= 0); - if (aResult) { - mySelectedActor = aSActor; - myEdgeId = anEdgeId; - myElemId = anObjId; - myInteractor->setEdgeData(anObjId,aSActor,-anEdgeId-1,myPreSelectionActor); - } - } - } - if(aResult) { - myPreSelectionActor->GetProperty()->SetRepresentationToSurface(); - myPreSelectionActor->SetVisibility(true); - } - } - } - } - else if (vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker)) { - int aVtkId = picker->GetPointId(); - if ( aVtkId >= 0 && IsValid( aSActor, aVtkId, true ) ) { - if ( aSActor && aSActor->hasIO() ) { - int anObjId = aSActor->GetNodeObjId(aVtkId); - bool anIsSameObjId = (mySelectedActor == aSActor && myNodeId == anObjId); - if(!anIsSameObjId) { - mySelectedActor = aSActor; - myNodeId = anObjId; - myInteractor->setPointData(anObjId,aSActor,myPreSelectionActor); - } - myPreSelectionActor->GetProperty()->SetRepresentationToSurface(); - myPreSelectionActor->SetVisibility(true); - } - } - } - else if ( vtkPicker::SafeDownCast(aPicker) ) { - if ( aSActor ) { - if ( myPreViewActor != aSActor ) { - if ( myPreViewActor != NULL ) { - myPreViewActor->SetPreSelected( false ); - } - myPreViewActor = aSActor; - - if ( aSActor->hasIO() ) { - Handle( SALOME_InteractiveObject) IO = aSActor->getIO(); - if ( !GetSelector()->IsSelected(IO) ) { - // Find All actors with same IO - vtkActorCollection* theActors = this->CurrentRenderer->GetActors(); - theActors->InitTraversal(); - while( vtkActor *ac = theActors->GetNextActor() ) { - if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) { - if ( anActor->hasIO() ) { - Handle(SALOME_InteractiveObject) IOS = anActor->getIO(); - if(IO->isSame(IOS)) { - anActor->SetPreSelected( true ); - } - } - } - } - } - } - } - } else { - myPreViewActor = NULL; - vtkActorCollection* theActors = this->CurrentRenderer->GetActors(); - theActors->InitTraversal(); - while( vtkActor *ac = theActors->GetNextActor() ) { - if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) { - anActor->SetPreSelected( false ); - } - } - } - } - myInteractor->EndPickCallback(); - //myInteractor->Render(); - myGUIWindow->update(); - - this->LastPos[0] = x; - this->LastPos[1] = y; + if(anIsChanged) + this->Render(); } // called on finsh GlobalPan operation +//---------------------------------------------------------------------------- void SVTK_InteractorStyle ::Place(const int theX, const int theY) { - if (this->CurrentRenderer == NULL) { + if (GetCurrentRenderer() == NULL) return; - } //translate view - int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize(); + int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize(); int centerX = aSize[0]/2; int centerY = aSize[1]/2; TranslateView(centerX, centerY, theX, theY); // restore zoom scale - vtkCamera *cam = this->CurrentRenderer->GetActiveCamera(); + vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera(); cam->SetParallelScale(myScale); - ::ResetCameraClippingRange(this->CurrentRenderer); - - if (myGUIWindow) myGUIWindow->update(); + GetCurrentRenderer()->ResetCameraClippingRange(); + this->Render(); } // Translates view from Point to Point +//---------------------------------------------------------------------------- void SVTK_InteractorStyle ::TranslateView(int toX, int toY, int fromX, int fromY) { - vtkCamera *cam = this->CurrentRenderer->GetActiveCamera(); + vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera(); double viewFocus[4], focalDepth, viewPoint[3]; float newPickPoint[4], oldPickPoint[4], motionVector[3]; cam->GetFocalPoint(viewFocus); @@ -1411,135 +1114,310 @@ SVTK_InteractorStyle motionVector[2] + viewPoint[2]); } - -/// Checks: is the given Actor within display coordinates? -bool +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle -::IsInRect(vtkActor* theActor, - const int left, const int top, - const int right, const int bottom) -{ - float* aBounds = theActor->GetBounds(); - float aMin[3], aMax[3]; - ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin); - ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax); - if (aMin[0] > aMax[0]) { - float aBuf = aMin[0]; - aMin[0] = aMax[0]; - aMax[0] = aBuf; - } - if (aMin[1] > aMax[1]) { - float aBuf = aMin[1]; - aMin[1] = aMax[1]; - aMax[1] = aBuf; - } - - return ((aMin[0]>left) && (aMax[0]bottom) && (aMax[1]PanXY( incrX, incrY, 0, 0 ); } - -/// Checks: is the given Cell within display coordinates? -bool +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle -::IsInRect(vtkCell* theCell, - const int left, const int top, - const int right, const int bottom) -{ - float* aBounds = theCell->GetBounds(); - float aMin[3], aMax[3]; - ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin); - ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax); - if (aMin[0] > aMax[0]) { - float aBuf = aMin[0]; - aMin[0] = aMax[0]; - aMax[0] = aBuf; - } - if (aMin[1] > aMax[1]) { - float aBuf = aMin[1]; - aMin[1] = aMax[1]; - aMax[1] = aBuf; - } - - return ((aMin[0]>left) && (aMax[0]bottom) && (aMax[1]DollyXY( incr, incr ); } - -bool +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle -::IsInRect(float* thePoint, - const int left, const int top, - const int right, const int bottom) +::IncrementalRotate( const int incrX, const int incrY ) { - float aPnt[3]; - ComputeWorldToDisplay(thePoint[0], thePoint[1], thePoint[2], aPnt); - - return ((aPnt[0]>left) && (aPnt[0]bottom) && (aPnt[1]RotateXY( incrX, -incrY ); } +//---------------------------------------------------------------------------- void SVTK_InteractorStyle -::SetFilter( const Handle(VTKViewer_Filter)& theFilter ) +::SetInteractor( vtkRenderWindowInteractor* theInteractor ) { - myFilters[ theFilter->GetId() ] = theFilter; + // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc) + Superclass::SetInteractor( theInteractor ); + + myInteractor = dynamic_cast(theInteractor); + + if(theInteractor) { + // register EventCallbackCommand as observer of custorm event (3d space mouse event) + theInteractor->AddObserver( SVTK::SpaceMouseMoveEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::SpaceMouseButtonEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::PanLeftEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::PanRightEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::PanUpEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::PanDownEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::ZoomInEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::ZoomOutEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::RotateLeftEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::RotateRightEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::RotateUpEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::RotateDownEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::PlusSpeedIncrementEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::MinusSpeedIncrementEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::SetSpeedIncrementEvent, EventCallbackCommand, Priority ); + + theInteractor->AddObserver( SVTK::SetSMDecreaseSpeedEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::SetSMIncreaseSpeedEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::SetSMDominantCombinedSwitchEvent, EventCallbackCommand, Priority ); + + theInteractor->AddObserver( SVTK::StartZoom, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::StartPan, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::StartRotate, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::StartGlobalPan, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::StartFitArea, EventCallbackCommand, Priority ); + } } -bool + +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle -::IsFilterPresent( const int theId ) +::OnTimer() { - return myFilters.find( theId ) != myFilters.end(); + //vtkInteractorStyle::OnTimer(); + this->Interactor->Render(); } -void +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle -::RemoveFilter( const int theId ) +::Render() { - if ( IsFilterPresent( theId ) ) - myFilters.erase( theId ); + this->Interactor->CreateTimer(VTKI_TIMER_FIRST); } - -bool +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle -::IsValid( SALOME_Actor* theActor, - const int theId, - const bool theIsNode ) +::onSpaceMouseMove( double* data ) { - std::map::const_iterator anIter; - for ( anIter = myFilters.begin(); anIter != myFilters.end(); ++anIter ) - { - const Handle(VTKViewer_Filter)& aFilter = anIter->second; - if ( theIsNode == aFilter->IsNodeFilter() && - !aFilter->IsValid( theActor, theId ) ) - return false; - } - return true; + // general things, do SetCurrentRenderer() within FindPokedRenderer() + int x, y; + GetEventPosition( this->Interactor, x, y ); // current mouse position (from last mouse move event or any other event) + FindPokedRenderer( x, y ); // calls SetCurrentRenderer + + IncrementalZoom( (int)data[2] ); // 1. push toward / pull backward = zoom out / zoom in + IncrementalPan( (int)data[0], (int)data[1] );// 2. pull up / push down = pan up / down, 3. move left / right = pan left / right + IncrementalRotate( 0, (int)data[4] ); // 4. twist the control = rotate around Y axis + IncrementalRotate( (int)data[3], 0 ); // 5. tilt the control forward/backward = rotate around X axis (Z axis of local coordinate system of space mouse) } -Handle(VTKViewer_Filter) +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle -::GetFilter( const int theId ) +::onSpaceMouseButton( int button ) { - return IsFilterPresent( theId ) ? myFilters[ theId ] : Handle(VTKViewer_Filter)(); + if( mySMDecreaseSpeedBtn == button ) { + ControllerIncrement()->Decrease(); + } + if( mySMIncreaseSpeedBtn == button ) { + ControllerIncrement()->Increase(); + } + if( mySMDominantCombinedSwitchBtn == button ) + DominantCombinedSwitch(); } +//---------------------------------------------------------------------------- void SVTK_InteractorStyle -::IncrementalPan( const int incrX, const int incrY ) +::DominantCombinedSwitch() { - this->PanXY( incrX, incrY, 0, 0 ); + printf( "\n--DominantCombinedSwitch() NOT IMPLEMENTED--\n" ); } +//---------------------------------------------------------------------------- void SVTK_InteractorStyle -::IncrementalZoom( const int incr ) +::ProcessEvents( vtkObject* object, + unsigned long event, + void* clientData, + void* callData ) { - this->DollyXY( incr, incr ); + if ( clientData ) { + vtkObject* anObject = reinterpret_cast( clientData ); + SVTK_InteractorStyle* self = dynamic_cast( anObject ); + int aSpeedIncrement=self->ControllerIncrement()->Current(); + if ( self ) { + switch ( event ) { + case SVTK::SpaceMouseMoveEvent : + self->onSpaceMouseMove( (double*)callData ); + return; + case SVTK::SpaceMouseButtonEvent : + self->onSpaceMouseButton( *((int*)callData) ); + return; + case SVTK::PanLeftEvent: + self->IncrementalPan(-aSpeedIncrement, 0); + return; + case SVTK::PanRightEvent: + self->IncrementalPan(aSpeedIncrement, 0); + return; + case SVTK::PanUpEvent: + self->IncrementalPan(0, aSpeedIncrement); + return; + case SVTK::PanDownEvent: + self->IncrementalPan(0, -aSpeedIncrement); + return; + case SVTK::ZoomInEvent: + self->IncrementalZoom(aSpeedIncrement); + return; + case SVTK::ZoomOutEvent: + self->IncrementalZoom(-aSpeedIncrement); + return; + case SVTK::RotateLeftEvent: + self->IncrementalRotate(-aSpeedIncrement, 0); + return; + case SVTK::RotateRightEvent: + self->IncrementalRotate(aSpeedIncrement, 0); + return; + case SVTK::RotateUpEvent: + self->IncrementalRotate(0, -aSpeedIncrement); + return; + case SVTK::RotateDownEvent: + self->IncrementalRotate(0, aSpeedIncrement); + return; + case SVTK::PlusSpeedIncrementEvent: + self->ControllerIncrement()->Increase(); + return; + case SVTK::MinusSpeedIncrementEvent: + self->ControllerIncrement()->Decrease(); + return; + case SVTK::SetSpeedIncrementEvent: + self->ControllerIncrement()->SetStartValue(*((int*)callData)); + return; + + case SVTK::SetSMDecreaseSpeedEvent: + self->mySMDecreaseSpeedBtn = *((int*)callData); + return; + case SVTK::SetSMIncreaseSpeedEvent: + self->mySMIncreaseSpeedBtn = *((int*)callData); + return; + case SVTK::SetSMDominantCombinedSwitchEvent: + self->mySMDominantCombinedSwitchBtn = *((int*)callData); + return; + + case SVTK::StartZoom: + self->startZoom(); + return; + case SVTK::StartPan: + self->startPan(); + return; + case SVTK::StartRotate: + self->startRotate(); + return; + case SVTK::StartGlobalPan: + self->startGlobalPan(); + return; + case SVTK::StartFitArea: + self->startFitArea(); + return; + } + } + } + + Superclass::ProcessEvents( object, event, clientData, callData ); +} +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle::OnChar() +{ +} +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle::OnKeyDown() +{ + bool bInvokeSuperclass=myControllerOnKeyDown->OnKeyDown(this); + if (bInvokeSuperclass){ + Superclass::OnKeyDown(); + } +} +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle::ActionPicking() +{ + int x, y; + Interactor->GetEventPosition( x, y ); + FindPokedRenderer( x, y ); + + myOtherPoint = myPoint = QPoint(x, y); + + startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT); + onFinishOperation(); + startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE); +} +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle::SetControllerOnKeyDown(SVTK_ControllerOnKeyDown* theController) +{ + myControllerOnKeyDown=theController; +} +//---------------------------------------------------------------------------- +SVTK_ControllerOnKeyDown* SVTK_InteractorStyle::ControllerOnKeyDown() +{ + return myControllerOnKeyDown.GetPointer(); +} +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle::SetControllerIncrement(SVTK_ControllerIncrement* theController) +{ + myControllerIncrement=theController; +} +//---------------------------------------------------------------------------- +SVTK_ControllerIncrement* SVTK_InteractorStyle::ControllerIncrement() +{ + return myControllerIncrement.GetPointer(); } -void -SVTK_InteractorStyle -::IncrementalRotate( const int incrX, const int incrY ) +vtkStandardNewMacro(SVTK_ControllerIncrement); +//---------------------------------------------------------------------------- +SVTK_ControllerIncrement::SVTK_ControllerIncrement() { - this->RotateXY( incrX, -incrY ); + myIncrement=10; +} +//---------------------------------------------------------------------------- +SVTK_ControllerIncrement::~SVTK_ControllerIncrement() +{ +} +//---------------------------------------------------------------------------- +void SVTK_ControllerIncrement::SetStartValue(const int theValue) +{ + myIncrement=theValue; +} +//---------------------------------------------------------------------------- +int SVTK_ControllerIncrement::Current()const +{ + return myIncrement; +} +//---------------------------------------------------------------------------- +int SVTK_ControllerIncrement::Increase() +{ + ++myIncrement; + return myIncrement; +} +//---------------------------------------------------------------------------- +int SVTK_ControllerIncrement::Decrease() +{ + if (myIncrement>1){ + --myIncrement; + } + return myIncrement; +} + +vtkStandardNewMacro(SVTK_ControllerOnKeyDown); +//---------------------------------------------------------------------------- +SVTK_ControllerOnKeyDown::SVTK_ControllerOnKeyDown() +{ +} +//---------------------------------------------------------------------------- +SVTK_ControllerOnKeyDown::~SVTK_ControllerOnKeyDown() +{ +} +//---------------------------------------------------------------------------- +bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS) +{ + return true; } diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index 53039e86b..7ea671df4 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -31,26 +31,83 @@ #include "SVTK.h" -#include +#include "SVTK_SelectionEvent.h" -class vtkCell; -class vtkRenderWindowInteractor; +#include + +#include +#include -#include #include +#include #include -#include "VTKViewer_Filter.h" +#include +// +//------------------------------------------- +//! Control the value of increment in SALOME way. +/*! + This class controls of value of increment, + for pan/rotate/zoom operations in SALOME way +*/ +class SVTK_ControllerIncrement : public vtkObject{ + public: + vtkTypeMacro(SVTK_ControllerIncrement, vtkObject); + static SVTK_ControllerIncrement* New(); + + //! Set start value of increment + void SetStartValue(const int ); + + //! Get current value of increment + int Current()const; -class VTKViewer_Trihedron; + //! Increace the increment value by add 1 + virtual int Increase(); + + //! Decreace the increment value by subtract 1 + virtual int Decrease(); + protected: + SVTK_ControllerIncrement(); + virtual ~SVTK_ControllerIncrement(); + protected: + int myIncrement; + private: + SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);//Not implemented + void operator=(const SVTK_ControllerIncrement&); //Not implemented +}; +// +//------------------------------------------- +//! Control the behaviour of KeyDown event in SALOME way. +/*! + This class controls the behaviour of KeyDown event + in SALOME way +*/ +class SVTK_ControllerOnKeyDown : public vtkObject{ + public: + vtkTypeMacro(SVTK_ControllerOnKeyDown, vtkObject); + static SVTK_ControllerOnKeyDown* New(); + + //! Provides the action on event + virtual bool OnKeyDown(vtkInteractorStyle* ); + + protected: + SVTK_ControllerOnKeyDown(); + virtual ~SVTK_ControllerOnKeyDown(); + + private: + SVTK_ControllerOnKeyDown(const SVTK_ControllerOnKeyDown&);//Not implemented + void operator=(const SVTK_ControllerOnKeyDown&); //Not implemented +}; +//------------------------------------------- + +class vtkCell; +class vtkPicker; class SALOME_Actor; -class SVTK_Actor; -class SVTK_Viewer; + class SVTK_Selector; -class SVTK_ViewWindow; -class SVTK_RenderWindowInteractor; +class SVTK_GenericRenderWindowInteractor; #define VTK_INTERACTOR_STYLE_CAMERA_NONE 0 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE 1 @@ -61,63 +118,126 @@ class SVTK_RenderWindowInteractor; #define VTK_INTERACTOR_STYLE_CAMERA_SELECT 6 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7 -class SVTK_EXPORT SVTK_InteractorStyle : public QObject, - public vtkInteractorStyle +//! Introduce SALOME way of user interaction +/*! + This class defines SALOME way of user interaction for VTK viewer, as well, + as introduce a new selection mechanism +*/ +class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle { - Q_OBJECT; - public: - // Description: - // This class must be supplied with a vtkRenderWindowInteractor wrapper or - // parent. This class should not normally be instantiated by application - // programmers. static SVTK_InteractorStyle *New(); vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle); - virtual void SetInteractor(vtkRenderWindowInteractor *theInteractor); - void setViewWindow(SVTK_ViewWindow* theViewWindow); - void setGUIWindow(QWidget* theWindow); + typedef boost::shared_ptr PSelectionEvent; - virtual int GetState(); + - //merge with V2_2_0_VISU_improvements:void setTriedron(VTKViewer_Trihedron* theTrihedron); - void setPreselectionProp(const double& theRed = 0, - const double& theGreen = 1, - const double& theBlue = 1, - const int& theWidth = 5); + //! Generate special #SVTK_SelectionEvent + virtual + SVTK_SelectionEvent* + GetSelectionEvent(); - // Generic event bindings must be overridden in subclasses - void OnMouseMove (int ctrl, int shift, int x, int y); - void OnLeftButtonDown(int ctrl, int shift, int x, int y); - void OnLeftButtonUp (int ctrl, int shift, int x, int y); - void OnMiddleButtonDown(int ctrl, int shift, int x, int y); - void OnMiddleButtonUp (int ctrl, int shift, int x, int y); - void OnRightButtonDown(int ctrl, int shift, int x, int y); - void OnRightButtonUp (int ctrl, int shift, int x, int y); - - void OnSelectionModeChanged(); - - //merge with V2_2_0_VISU_improvements:void ViewFitAll(); - - void SetFilter( const Handle(VTKViewer_Filter)& ); - Handle(VTKViewer_Filter) GetFilter( const int ); - bool IsFilterPresent( const int ); - void RemoveFilter( const int ); - bool IsValid( SALOME_Actor* theActor, - const int theId, - const bool theIsNode = false ); + //! Generate special #SVTK_SelectionEvent with flipped Y coordinate + virtual + SVTK_SelectionEvent* + GetSelectionEventFlipY(); + + //! Redefined in order to add an observer (callback) for custorm event (space mouse event) + virtual + void + SetInteractor( vtkRenderWindowInteractor* ); + + //! To invoke #vtkRenderWindowInteractor::CreateTimer + virtual + void + Render(); + + //! To implement cached rendering + virtual + void + OnTimer(); + + //! To reset reset view + virtual + void + OnConfigure(); + + //! To handle mouse move event + virtual + void + OnMouseMove(); + + //! To handle left mouse button down event (reimplemented from #vtkInteractorStyle) + virtual + void + OnLeftButtonDown(); + + //! To handle left mouse button up event (reimplemented from #vtkInteractorStyle) + virtual + void + OnLeftButtonUp(); + + //! To handle middle mouse button down event (reimplemented from #vtkInteractorStyle) + virtual + void + OnMiddleButtonDown(); + + //! To handle middle mouse button up event (reimplemented from #vtkInteractorStyle) + virtual + void + OnMiddleButtonUp(); + + //! To handle right mouse button down event (reimplemented from #vtkInteractorStyle) + virtual + void + OnRightButtonDown(); + + //! To handle right mouse button up event (reimplemented from #vtkInteractorStyle) + virtual + void + OnRightButtonUp(); + + //! To handle keyboard event (reimplemented from #vtkInteractorStyle) + virtual + void + OnChar(); + + //! To set current increment controller + void SetControllerIncrement(SVTK_ControllerIncrement*); + + //! To get current increment controller + SVTK_ControllerIncrement* ControllerIncrement(); + + //! Redefine vtkInteractorStyle::OnKeyDown + virtual void OnKeyDown(); + + //! Provide instructions for Picking + void ActionPicking(); + + //! To set current OnKeyDown controller + void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*); + + //! To get current OnKeyDown controller + SVTK_ControllerOnKeyDown* ControllerOnKeyDown(); - void IncrementalPan ( const int incrX, const int incrY ); - void IncrementalZoom ( const int incr ); - void IncrementalRotate( const int incrX, const int incrY ); + SVTK_Selector* GetSelector(); protected: SVTK_InteractorStyle(); ~SVTK_InteractorStyle(); - SVTK_InteractorStyle(const SVTK_InteractorStyle&) {}; - void operator=(const SVTK_InteractorStyle&) {}; - SVTK_Selector* GetSelector(); + QWidget* + GetRenderWidget(); + + // Generic event bindings must be overridden in subclasses + virtual void OnMouseMove (int ctrl, int shift, int x, int y); + virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y); + virtual void OnLeftButtonUp (int ctrl, int shift, int x, int y); + virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y); + virtual void OnMiddleButtonUp (int ctrl, int shift, int x, int y); + virtual void OnRightButtonDown(int ctrl, int shift, int x, int y); + virtual void OnRightButtonUp (int ctrl, int shift, int x, int y); void RotateXY(int dx, int dy); void PanXY(int x, int y, int oldX, int oldY); @@ -126,47 +246,50 @@ class SVTK_EXPORT SVTK_InteractorStyle : public QObject, void fitRect(const int left, const int top, const int right, const int bottom); void Place(const int theX, const int theY); void TranslateView(int toX, int toY, int fromX, int fromY); - bool IsInRect(vtkActor* theActor, - const int left, const int top, - const int right, const int bottom); - bool IsInRect(vtkCell* theCell, - const int left, const int top, - const int right, const int bottom); - bool IsInRect(float* thePoint, - const int left, const int top, - const int right, const int bottom); + + void + IncrementalPan( const int incrX, const int incrY ); + + void + IncrementalZoom( const int incr ); + + void + IncrementalRotate( const int incrX, const int incrY ); + + // Main process event method (reimplemented from #vtkInteractorStyle) + static + void + ProcessEvents(vtkObject* object, + unsigned long event, + void* clientData, + void* callData ); float MotionFactor; float RadianToDegree; // constant: for conv from deg to rad double myScale; - SALOME_Actor* myPreViewActor; - - SVTK_Actor* myPreSelectionActor; - SALOME_Actor* mySelectedActor; - int myElemId; - int myEdgeId; - int myNodeId; - - public: - bool eventFilter(QObject* object, QEvent* event); + protected: void startZoom(); void startPan(); void startGlobalPan(); void startRotate(); void startFitArea(); void startSpin(); - bool needsRedrawing(); protected: void loadCursors(); void startOperation(int operation); void onStartOperation(); - void onFinishOperation(); + virtual void onFinishOperation(); void onOperation(QPoint mousePos); void onCursorMove(QPoint mousePos); void setCursor(const int operation); + void onSpaceMouseMove( double* data ); + virtual void onSpaceMouseButton( int button ); + + void DominantCombinedSwitch(); + protected: QCursor myDefCursor; QCursor myPanCursor; @@ -180,18 +303,26 @@ class SVTK_EXPORT SVTK_InteractorStyle : public QObject, bool myCursorState; bool myShiftState; int ForcedState; + + vtkSmartPointer myLastHighlitedActor; + vtkSmartPointer myLastPreHighlitedActor; + + //! "Increment" controller for pan/rotate/zoom operations + vtkSmartPointer myControllerIncrement; + + //!controls the behaviour of KeyDown event in SALOME way + vtkSmartPointer myControllerOnKeyDown; + + // SpaceMouse short cuts + int mySMDecreaseSpeedBtn; + int mySMIncreaseSpeedBtn; + int mySMDominantCombinedSwitchBtn; - SVTK_RenderWindowInteractor* myInteractor; - SVTK_ViewWindow* myViewWindow; - //merge with V2_2_0_VISU_improvements:VTKViewer_Trihedron* myTrihedron; - QWidget* myGUIWindow; - - std::map myFilters; + vtkSmartPointer myInteractor; + + PSelectionEvent mySelectionEvent; - // members from old version - double DeltaElevation; - double DeltaAzimuth; - int LastPos[2]; + vtkSmartPointer myPicker; }; #endif diff --git a/src/SVTK/SVTK_MainWindow.cxx b/src/SVTK/SVTK_MainWindow.cxx new file mode 100644 index 000000000..ad01609bc --- /dev/null +++ b/src/SVTK/SVTK_MainWindow.cxx @@ -0,0 +1,701 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#include "SALOME_Actor.h" + +#include +#include + +#include "QtxAction.h" + +#include "SUIT_ToolButton.h" +#include "SUIT_MessageBox.h" +#include "SUIT_ViewWindow.h" + +#include "SUIT_Tools.h" +#include "SUIT_ResourceMgr.h" +#include "SVTK_NonIsometricDlg.h" +#include "SVTK_CubeAxesDlg.h" + +#include "SVTK_MainWindow.h" +#include "SVTK_Event.h" +#include "SVTK_Renderer.h" +#include "SVTK_RenderWindowInteractor.h" + +#include "SVTK_Selector.h" + +#include + + +//---------------------------------------------------------------------------- +SVTK_MainWindow +::SVTK_MainWindow(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr, + SUIT_ViewWindow* theViewWindow) : + QMainWindow(theParent,theName,0), + myViewWindow(theViewWindow) +{ + myToolBar = new QToolBar(this); + myToolBar->setCloseMode(QDockWindow::Undocked); + myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); + + createActions(theResourceMgr); + createToolBar(); +} + +void +SVTK_MainWindow +::Initialize(SVTK_RenderWindowInteractor* theInteractor) +{ + myInteractor = theInteractor; + SetEventDispatcher(myInteractor->GetDevice()); + + setCentralWidget(myInteractor); + myInteractor->setBackgroundMode(Qt::NoBackground); + + myInteractor->setFocusPolicy(StrongFocus); + myInteractor->setFocus(); + setFocusProxy(myInteractor); +} + + +//---------------------------------------------------------------------------- +SVTK_MainWindow +::~SVTK_MainWindow() +{ +} + + +//---------------------------------------------------------------------------- +SVTK_RenderWindowInteractor* +SVTK_MainWindow +::GetInteractor() +{ + return myInteractor; +} + +vtkRenderWindowInteractor* +SVTK_MainWindow +::getInteractor() +{ + return GetInteractor()->GetDevice(); +} + +vtkRenderWindow* +SVTK_MainWindow +::getRenderWindow() +{ + return GetInteractor()->getRenderWindow(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::Repaint(bool theUpdateTrihedron) +{ + if(theUpdateTrihedron) + GetRenderer()->OnAdjustTrihedron(); + + GetInteractor()->update(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::InvokeEvent(unsigned long theEvent, void* theCallData) +{ + GetInteractor()->InvokeEvent(theEvent,theCallData); +} + +//---------------------------------------------------------------------------- +vtkInteractorStyle* +SVTK_MainWindow +::GetInteractorStyle() +{ + return GetInteractor()->GetInteractorStyle(); +} + +void +SVTK_MainWindow +::PushInteractorStyle(vtkInteractorStyle* theStyle) +{ + GetInteractor()->PushInteractorStyle(theStyle); +} + +void +SVTK_MainWindow +::PopInteractorStyle() +{ + GetInteractor()->PopInteractorStyle(); +} + +//---------------------------------------------------------------------------- +SVTK_Selector* +SVTK_MainWindow +::GetSelector() +{ + return GetInteractor()->GetSelector(); +} + +Selection_Mode +SVTK_MainWindow +::SelectionMode() +{ + return GetSelector()->SelectionMode(); +} + +void +SVTK_MainWindow +::SetSelectionMode(Selection_Mode theMode) +{ + GetSelector()->SetSelectionMode(theMode); +} + + +//---------------------------------------------------------------------------- +SVTK_Renderer* +SVTK_MainWindow +::GetRenderer() +{ + return GetInteractor()->GetRenderer(); +} + +vtkRenderer* +SVTK_MainWindow +::getRenderer() +{ + return GetInteractor()->getRenderer(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::SetBackgroundColor(const QColor& theColor) +{ + getRenderer()->SetBackground(theColor.red()/255.0, + theColor.green()/255.0, + theColor.blue()/255.0); +} + +QColor +SVTK_MainWindow +::BackgroundColor() +{ + float aBackgroundColor[3]; + getRenderer()->GetBackground(aBackgroundColor); + return QColor(int(aBackgroundColor[0]*255), + int(aBackgroundColor[1]*255), + int(aBackgroundColor[2]*255)); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::GetScale( double theScale[3] ) +{ + GetRenderer()->GetScale( theScale ); +} + +void +SVTK_MainWindow +::SetScale( double theScale[3] ) +{ + GetRenderer()->SetScale( theScale ); + Repaint(); +} + + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::AddActor(VTKViewer_Actor* theActor, + bool theIsUpdate) +{ + GetRenderer()->AddActor(theActor); + if(theIsUpdate) + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::RemoveActor(VTKViewer_Actor* theActor, + bool theIsUpdate) +{ + GetRenderer()->RemoveActor(theActor); + if(theIsUpdate) + Repaint(); +} + + +//---------------------------------------------------------------------------- +int +SVTK_MainWindow +::GetTrihedronSize() +{ + return GetRenderer()->GetTrihedronSize(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::SetTrihedronSize( const int theSize ) +{ + GetRenderer()->SetTrihedronSize(theSize); + Repaint(); +} + + +//---------------------------------------------------------------------------- +/*! If parameter theIsForcedUpdate is true, recalculate parameters for + * trihedron and cube axes, even if trihedron and cube axes is invisible. + */ +void +SVTK_MainWindow +::AdjustActors() +{ + GetRenderer()->AdjustActors(); + Repaint(); +} + +//---------------------------------------------------------------------------- +bool +SVTK_MainWindow +::IsTrihedronDisplayed() +{ + return GetRenderer()->IsTrihedronDisplayed(); +} + +//---------------------------------------------------------------------------- +bool +SVTK_MainWindow +::IsCubeAxesDisplayed() +{ + return GetRenderer()->IsCubeAxesDisplayed(); +} + +//---------------------------------------------------------------------------- +VTKViewer_Trihedron* +SVTK_MainWindow +::GetTrihedron() +{ + return GetRenderer()->GetTrihedron(); +} + +//---------------------------------------------------------------------------- +SVTK_CubeAxesActor2D* +SVTK_MainWindow +::GetCubeAxes() +{ + return GetRenderer()->GetCubeAxes(); +} + + +//---------------------------------------------------------------------------- +QToolBar* +SVTK_MainWindow +::getToolBar() +{ + return myToolBar; +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::SetEventDispatcher(vtkObject* theDispatcher) +{ + myEventDispatcher = theDispatcher; +} + +//---------------------------------------------------------------------------- +#if defined(WIN32) && !defined(_DEBUG) +#pragma optimize( "", off ) +#endif + +void +SVTK_MainWindow +::createActions(SUIT_ResourceMgr* theResourceMgr) +{ + if(!myActionsMap.isEmpty()) + return; + + QtxAction* anAction; + + // Dump view + anAction = new QtxAction(tr("MNU_DUMP_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ), + tr( "MNU_DUMP_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_DUMP_VIEW")); + connect(anAction, SIGNAL(activated()), myViewWindow, SLOT(onDumpView())); + myActionsMap[ DumpId ] = anAction; + + // FitAll + anAction = new QtxAction(tr("MNU_FITALL"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ), + tr( "MNU_FITALL" ), 0, this); + anAction->setStatusTip(tr("DSC_FITALL")); + connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll())); + myActionsMap[ FitAllId ] = anAction; + + // FitRect + anAction = new QtxAction(tr("MNU_FITRECT"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ), + tr( "MNU_FITRECT" ), 0, this); + anAction->setStatusTip(tr("DSC_FITRECT")); + connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit())); + myActionsMap[ FitRectId ] = anAction; + + // Zoom + anAction = new QtxAction(tr("MNU_ZOOM_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ), + tr( "MNU_ZOOM_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_ZOOM_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom())); + myActionsMap[ ZoomId ] = anAction; + + // Panning + anAction = new QtxAction(tr("MNU_PAN_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ), + tr( "MNU_PAN_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_PAN_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning())); + myActionsMap[ PanId ] = anAction; + + // Global Panning + anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ), + tr( "MNU_GLOBALPAN_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning())); + myActionsMap[ GlobalPanId ] = anAction; + + // Rotation + anAction = new QtxAction(tr("MNU_ROTATE_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ), + tr( "MNU_ROTATE_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_ROTATE_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation())); + myActionsMap[ RotationId ] = anAction; + + // Projections + anAction = new QtxAction(tr("MNU_FRONT_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ), + tr( "MNU_FRONT_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_FRONT_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView())); + myActionsMap[ FrontId ] = anAction; + + anAction = new QtxAction(tr("MNU_BACK_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ), + tr( "MNU_BACK_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_BACK_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onBackView())); + myActionsMap[ BackId ] = anAction; + + anAction = new QtxAction(tr("MNU_TOP_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ), + tr( "MNU_TOP_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_TOP_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onTopView())); + myActionsMap[ TopId ] = anAction; + + anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ), + tr( "MNU_BOTTOM_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_BOTTOM_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView())); + myActionsMap[ BottomId ] = anAction; + + anAction = new QtxAction(tr("MNU_LEFT_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ), + tr( "MNU_LEFT_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_LEFT_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView())); + myActionsMap[ LeftId ] = anAction; + + anAction = new QtxAction(tr("MNU_RIGHT_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ), + tr( "MNU_RIGHT_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_RIGHT_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onRightView())); + myActionsMap[ RightId ] = anAction; + + // Reset + anAction = new QtxAction(tr("MNU_RESET_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ), + tr( "MNU_RESET_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_RESET_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onResetView())); + myActionsMap[ ResetId ] = anAction; + + // onViewTrihedron: Shows - Hides Trihedron + anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ), + tr( "MNU_SHOW_TRIHEDRON" ), 0, this); + anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON")); + connect(anAction, SIGNAL(activated()), this, SLOT(onViewTrihedron())); + myActionsMap[ ViewTrihedronId ] = anAction; + + // onNonIsometric: Manage non-isometric params + anAction = new QtxAction(tr("MNU_SVTK_SCALING"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ), + tr( "MNU_SVTK_SCALING" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_SCALING")); + anAction->setToggleAction(true); + connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool))); + myActionsMap[ NonIsometric ] = anAction; + + myNonIsometricDlg = new SVTK_NonIsometricDlg(this,"SVTK_NonIsometricDlg",anAction); + + // onGraduatedAxes: Manage graduated axes params + anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_GRADUATED_AXES" ) ), + tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES")); + anAction->setToggleAction(true); + connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool))); + myActionsMap[ GraduatedAxes ] = anAction; + + myCubeAxesDlg = new SVTK_CubeAxesDlg(this,"SVTK_CubeAxesDlg",anAction); +} + +#if defined(WIN32) && !defined(_DEBUG) +#pragma optimize( "", on ) +#endif + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::createToolBar() +{ + myActionsMap[DumpId]->addTo(myToolBar); + myActionsMap[ViewTrihedronId]->addTo(myToolBar); + + SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar); + aScaleBtn->AddAction(myActionsMap[FitAllId]); + aScaleBtn->AddAction(myActionsMap[FitRectId]); + aScaleBtn->AddAction(myActionsMap[ZoomId]); + + SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar); + aPanningBtn->AddAction(myActionsMap[PanId]); + aPanningBtn->AddAction(myActionsMap[GlobalPanId]); + + myActionsMap[RotationId]->addTo(myToolBar); + + SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar); + aViewsBtn->AddAction(myActionsMap[FrontId]); + aViewsBtn->AddAction(myActionsMap[BackId]); + aViewsBtn->AddAction(myActionsMap[TopId]); + aViewsBtn->AddAction(myActionsMap[BottomId]); + aViewsBtn->AddAction(myActionsMap[LeftId]); + aViewsBtn->AddAction(myActionsMap[RightId]); + + myActionsMap[ResetId]->addTo(myToolBar); + + myActionsMap[NonIsometric]->addTo(myToolBar); + myActionsMap[GraduatedAxes]->addTo(myToolBar); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::activateZoom() +{ + myEventDispatcher->InvokeEvent(SVTK::StartZoom,0); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::activatePanning() +{ + myEventDispatcher->InvokeEvent(SVTK::StartPan,0); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::activateRotation() +{ + myEventDispatcher->InvokeEvent(SVTK::StartRotate,0); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::activateGlobalPanning() +{ + myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::activateWindowFit() +{ + myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onFrontView() +{ + GetRenderer()->OnFrontView(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onBackView() +{ + GetRenderer()->OnBackView(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onTopView() +{ + GetRenderer()->OnTopView(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onBottomView() +{ + GetRenderer()->OnBottomView(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onLeftView() +{ + GetRenderer()->OnLeftView(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onRightView() +{ + GetRenderer()->OnRightView(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onResetView() +{ + GetRenderer()->OnResetView(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onFitAll() +{ + GetRenderer()->OnFitAll(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onViewTrihedron() +{ + GetRenderer()->OnViewTrihedron(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onViewCubeAxes() +{ + GetRenderer()->OnViewCubeAxes(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onNonIsometric(bool theIsActivate) +{ + if(theIsActivate){ + myNonIsometricDlg->Update(); + myNonIsometricDlg->show(); + }else + myNonIsometricDlg->hide(); +} + +void +SVTK_MainWindow +::onGraduatedAxes(bool theIsActivate) +{ + if(theIsActivate){ + myCubeAxesDlg->Update(); + myCubeAxesDlg->show(); + }else + myCubeAxesDlg->hide(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onAdjustTrihedron() +{ + GetRenderer()->OnAdjustTrihedron(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onAdjustCubeAxes() +{ + GetRenderer()->OnAdjustCubeAxes(); +} + +//---------------------------------------------------------------------------- +QImage +SVTK_MainWindow +::dumpView() +{ + QPixmap px = QPixmap::grabWindow( GetInteractor()->winId() ); + return px.convertToImage(); +} diff --git a/src/SVTK/SVTK_MainWindow.h b/src/SVTK/SVTK_MainWindow.h new file mode 100644 index 000000000..758093797 --- /dev/null +++ b/src/SVTK/SVTK_MainWindow.h @@ -0,0 +1,238 @@ +#ifndef SVTK_MAINWINDOW_H +#define SVTK_MAINWINDOW_H + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +#include "SVTK.h" +#include "SVTK_Selection.h" + +#include + +#include + +class QtxAction; + +class vtkObject; +class vtkRenderer; +class vtkRenderWindow; +class vtkInteractorStyle; +class vtkRenderWindowInteractor; + +class SUIT_ResourceMgr; +class SUIT_ViewWindow; + +class SVTK_RenderWindowInteractor; +class SVTK_NonIsometricDlg; +class SVTK_CubeAxesActor2D; +class SVTK_CubeAxesDlg; + +class VTKViewer_Trihedron; +class VTKViewer_Transform; +class VTKViewer_Actor; + +class SVTK_Renderer; +class SVTK_Selector; + + +//---------------------------------------------------------------------------- +//! The class is a container for #SVTK_RenderWindowInteractor. +/*! + The class contains #SVTK_RenderWindowInteractor instance and + adds predefined viewer actions and toolbar for user interaction. +*/ +class SVTK_EXPORT SVTK_MainWindow: public QMainWindow +{ + Q_OBJECT; + +public: + SVTK_MainWindow(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr, + SUIT_ViewWindow* theViewWindow); + + //! To initialize the class + virtual + void + Initialize(SVTK_RenderWindowInteractor* theInteractor); + + virtual + ~SVTK_MainWindow(); + + //---------------------------------------------------------------------------- + //! Get used #SVTK_RenderWindowInteractor + SVTK_RenderWindowInteractor* + GetInteractor(); + + //! Get used #vtkRenderWindowInteractor (obsolete) + vtkRenderWindowInteractor* + getInteractor(); + + //! Get used #vtkRenderWindow (obsolete) + vtkRenderWindow* + getRenderWindow(); + + //! To repaint the view + void + Repaint(bool theUpdateTrihedron = true); + + //! To invoke a VTK event on #SVTK_RenderWindowInteractor instance + void + InvokeEvent(unsigned long theEvent, void* theCallData); + + //---------------------------------------------------------------------------- + //! Redirect the request to #SVTK_RenderWindowInteractor::GetInteractorStyle + vtkInteractorStyle* + GetInteractorStyle(); + + //! Redirect the request to #SVTK_RenderWindowInteractor::PushInteractorStyle + void + PushInteractorStyle(vtkInteractorStyle* theStyle); + + //! Redirect the request to #SVTK_RenderWindowInteractor::PopInteractorStyle + void + PopInteractorStyle(); + + //---------------------------------------------------------------------------- + //! Redirect the request to #SVTK_RenderWindowInteractor::GetSelector + SVTK_Selector* + GetSelector(); + + //! Redirect the request to #SVTK_RenderWindowInteractor::SelectionMode + Selection_Mode + SelectionMode(); + + //! Redirect the request to #SVTK_RenderWindowInteractor::SetSelectionMode + void + SetSelectionMode(Selection_Mode theMode); + + //---------------------------------------------------------------------------- + //! Redirect the request to #SVTK_RenderWindowInteractor::GetRenderer + SVTK_Renderer* + GetRenderer(); + + //! Redirect the request to #SVTK_RenderWindowInteractor::getRenderer + vtkRenderer* + getRenderer(); + + //! Set background color to the view + void + SetBackgroundColor(const QColor& theColor); + + //! Get background color of the view + QColor + BackgroundColor(); + + //! Redirect the request to #SVTK_Renderer::SetScale + void + SetScale(double theScale[3]); + + //! Redirect the request to #SVTK_Renderer::GetScale + void + GetScale(double theScale[3]); + + //! Redirect the request to #SVTK_Renderer::AddActor + virtual + void + AddActor(VTKViewer_Actor* theActor, + bool theIsUpdate = false); + + //! Redirect the request to #SVTK_Renderer::RemoveActor + virtual + void + RemoveActor(VTKViewer_Actor* theActor, + bool theIsUpdate = false); + + //! Redirect the request to #SVTK_Renderer::GetTrihedronSize + int + GetTrihedronSize(); + + //! Redirect the request to #SVTK_Renderer::SetTrihedronSize + void + SetTrihedronSize(const int theSize); + + //! Redirect the request to #SVTK_Renderer::AdjustActors + void + AdjustActors(); + + //! Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed + bool + IsTrihedronDisplayed(); + + //! Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed + bool + IsCubeAxesDisplayed(); + + //! Redirect the request to #SVTK_Renderer::GetTrihedron + VTKViewer_Trihedron* + GetTrihedron(); + + //! Redirect the request to #SVTK_Renderer::GetCubeAxes + SVTK_CubeAxesActor2D* + GetCubeAxes(); + + //---------------------------------------------------------------------------- + QToolBar* getToolBar(); + + public slots: + void activateZoom(); + void activateWindowFit(); + void activateRotation(); + void activatePanning(); + void activateGlobalPanning(); + + void onFrontView(); + void onBackView(); + void onTopView(); + void onBottomView(); + void onRightView(); + void onLeftView(); + + void onResetView(); + void onFitAll(); + + void onViewTrihedron(); + void onViewCubeAxes(); + + void onNonIsometric(bool theIsActivate); + void onGraduatedAxes(bool theIsActivate); + + void onAdjustTrihedron(); + void onAdjustCubeAxes(); + + public: + QImage dumpView(); + + protected: + void + createActions(SUIT_ResourceMgr* theResourceMgr); + + void + createToolBar(); + + void + SetEventDispatcher(vtkObject* theDispatcher); + + enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId, + FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, + ViewTrihedronId, NonIsometric, GraduatedAxes}; + typedef QMap TActionsMap; + + SUIT_ViewWindow* myViewWindow; + + SVTK_NonIsometricDlg* myNonIsometricDlg; + SVTK_CubeAxesDlg* myCubeAxesDlg; + + vtkSmartPointer myEventDispatcher; + TActionsMap myActionsMap; + QToolBar* myToolBar; + + SVTK_RenderWindowInteractor* myInteractor; +}; + +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif diff --git a/src/SVTK/SVTK_NonIsometricDlg.cxx b/src/SVTK/SVTK_NonIsometricDlg.cxx new file mode 100644 index 000000000..a01bcbdcb --- /dev/null +++ b/src/SVTK/SVTK_NonIsometricDlg.cxx @@ -0,0 +1,200 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#include "SVTK_NonIsometricDlg.h" +#include "SVTK_MainWindow.h" +#include "SVTK_Renderer.h" + +#include "QtxDblSpinBox.h" +#include "QtxAction.h" + +#include +#include +#include +#include + +using namespace std; + +/*! + Constructor +*/ +SVTK_NonIsometricDlg +::SVTK_NonIsometricDlg(SVTK_MainWindow* theParent, + const char* theName, + QtxAction* theAction): + QDialog(theParent, + theName, + false, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ), + m_MainWindow(theParent), + m_Action(theAction) +{ + setCaption(tr("DLG_TITLE")); + setSizeGripEnabled(TRUE); + + // Create layout for this dialog + QGridLayout* layoutDlg = new QGridLayout (this); + layoutDlg->setSpacing(6); + layoutDlg->setMargin(11); + + // Create croup box with grid layout + QGroupBox* GroupBox = new QGroupBox(this, "GroupBox"); + QGridLayout* glGroupBox = new QGridLayout(GroupBox); + glGroupBox->setMargin(11); + glGroupBox->setSpacing(6); + + // "X" scaling + QLabel* TextLabelX = new QLabel (tr("LBL_X"), GroupBox, "TextLabelX"); + m_sbXcoeff = new QtxDblSpinBox(-VTK_LARGE_FLOAT, VTK_LARGE_FLOAT, 0.1, GroupBox); + m_sbXcoeff->setMinimumWidth(80); + m_sbXcoeff->setValue(1.0); + + // "Y" scaling + QLabel* TextLabelY = new QLabel (tr("LBL_Y"), GroupBox, "TextLabelY"); + m_sbYcoeff = new QtxDblSpinBox(-VTK_LARGE_FLOAT, VTK_LARGE_FLOAT, 0.1, GroupBox); + m_sbYcoeff->setMinimumWidth(80); + m_sbYcoeff->setValue(1.0); + + // "Z" scaling + QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), GroupBox, "TextLabelZ"); + m_sbZcoeff = new QtxDblSpinBox(-VTK_LARGE_FLOAT, VTK_LARGE_FLOAT, 0.1, GroupBox); + m_sbZcoeff->setMinimumWidth(80); + m_sbZcoeff->setValue(1.0); + + // Create button + m_bReset = new QPushButton(tr("&Reset"), GroupBox, "m_bReset"); + + // Layout widgets in the group box + glGroupBox->addWidget(TextLabelX, 0, 0); + glGroupBox->addWidget(m_sbXcoeff, 0, 1); + glGroupBox->addWidget(TextLabelY, 0, 2); + glGroupBox->addWidget(m_sbYcoeff, 0, 3); + glGroupBox->addWidget(TextLabelZ, 0, 4); + glGroupBox->addWidget(m_sbZcoeff, 0, 5); + glGroupBox->addWidget(m_bReset, 0, 6); + + // OK, CANCEL, Apply button + QGroupBox* aWgt = new QGroupBox(this); + QHBoxLayout* aHBoxLayout = new QHBoxLayout(aWgt); + aHBoxLayout->setMargin(11); + aHBoxLayout->setSpacing(6); + // Create button + QPushButton* m_bOk = new QPushButton(tr("O&K"), aWgt, "m_bOk"); + m_bOk->setDefault(TRUE); + m_bOk->setAutoDefault(TRUE); + // Create button + QPushButton* m_bApply = new QPushButton(tr("&Apply"), aWgt, "m_bApply"); + m_bApply->setAutoDefault(TRUE); + // Create button + QPushButton* m_bCancel = new QPushButton(tr("&Cancel"), aWgt, "m_bCancel"); + m_bCancel->setAutoDefault(TRUE); + + // Layout buttons + aHBoxLayout->addWidget(m_bOk); + aHBoxLayout->addWidget(m_bApply); + aHBoxLayout->addStretch(); + aHBoxLayout->addWidget(m_bCancel); + + // Layout top level widgets + layoutDlg->addWidget(GroupBox,0,0); + layoutDlg->addWidget(aWgt,1,0); + + // signals and slots connections + connect(m_bCancel, SIGNAL(clicked()), this, SLOT(onClickClose())); + connect(m_bOk, SIGNAL(clicked()), this, SLOT(onClickOk())); + connect(m_bApply, SIGNAL(clicked()), this, SLOT(onClickApply())); + connect(m_bReset, SIGNAL(clicked()), this, SLOT(onClickReset())); + + this->resize(100, this->sizeHint().height()); +} + +/* + * Destroys the object and frees any allocated resources + */ +SVTK_NonIsometricDlg +::~SVTK_NonIsometricDlg() +{ + // no need to delete child widgets, Qt does it all for us +} + +void +SVTK_NonIsometricDlg +::Update() +{ + // Get values from the VTK view + double aScaleFactor[3]; + m_MainWindow->GetScale(aScaleFactor); + m_sbXcoeff->setValue(aScaleFactor[0]); + m_sbYcoeff->setValue(aScaleFactor[1]); + m_sbZcoeff->setValue(aScaleFactor[2]); +} + +void +SVTK_NonIsometricDlg +::onClickOk() +{ + //apply changes + onClickApply(); + //Close dialog + accept(); +} + +void +SVTK_NonIsometricDlg +::onClickApply() +{ + double aScale[3] = {m_sbXcoeff->value(), m_sbYcoeff->value(), m_sbZcoeff->value()}; + m_MainWindow->SetScale(aScale); +} + +void +SVTK_NonIsometricDlg +::onClickReset() +{ + m_bReset->setFocus(); + m_sbXcoeff->setValue(1.0); + m_sbYcoeff->setValue(1.0); + m_sbZcoeff->setValue(1.0); +} + +void +SVTK_NonIsometricDlg +::onClickClose() +{ + reject(); + + m_Action->setOn( false ); +} + +void +SVTK_NonIsometricDlg +::done( int r ) +{ + m_Action->setOn( false ); + QDialog::done( r ); +} diff --git a/src/SVTK/SVTK_NonIsometricDlg.h b/src/SVTK/SVTK_NonIsometricDlg.h new file mode 100644 index 000000000..6a11a14f6 --- /dev/null +++ b/src/SVTK/SVTK_NonIsometricDlg.h @@ -0,0 +1,73 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#ifndef SVTK_NONISOMETRICDLG_H +#define SVTK_NONISOMETRICDLG_H + +#include + +class SVTK_MainWindow; + +class QtxDblSpinBox; +class QtxAction; + +class QPushButton; + + +class SVTK_NonIsometricDlg : public QDialog +{ + Q_OBJECT; + +public: + SVTK_NonIsometricDlg(SVTK_MainWindow* theParent, + const char* theName, + QtxAction* theAction); + + ~SVTK_NonIsometricDlg(); + + void Update(); + +protected: + SVTK_MainWindow *m_MainWindow; + QtxAction* m_Action; + + QtxDblSpinBox* m_sbXcoeff; + QtxDblSpinBox* m_sbYcoeff; + QtxDblSpinBox* m_sbZcoeff; + QPushButton* m_bReset; + +protected slots: + void onClickApply(); + void onClickReset(); + void onClickOk(); + void onClickClose(); + + virtual void done( int ); +}; + +#endif // SVTK_NONISOMETRICDLG_H diff --git a/src/SVTK/SVTK_RectPicker.cxx b/src/SVTK/SVTK_RectPicker.cxx new file mode 100644 index 000000000..775782e80 --- /dev/null +++ b/src/SVTK/SVTK_RectPicker.cxx @@ -0,0 +1,489 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_RectPicker.cxx +// Author : +// Module : SALOME + +#include "SVTK_RectPicker.h" + +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +//---------------------------------------------------------------------------- +namespace +{ + //---------------------------------------------------------------------------- + inline + float + 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], + float theTolerance, + float theDZ, + int theDX, + int theDY) + { + int aRet = 0; + float 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 = {"<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()-> + GetCompositePerspectiveTransformMatrix(1,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 = {"<GetPoint(aPntId,aX); + + float 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(); + + float 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 "< 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 float theBounds[6], + float 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, + float 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 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()-> + GetCompositePerspectiveTransformMatrix(1,0,1)); + + for(vtkIdType aCellId = 0; aCellId < aNumCells; aCellId++){ + vtkCell* aCell = theInput->GetCell(aCellId); + + float aBounds[6]; + aCell->GetBounds(aBounds); + + float aCenter[3]; + GetCenter(aBounds,aCenter); + + float aView[4]; + float 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(); + + float 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 = "<GetNumberOfPoints(); + bool anIsVisible = true; + for(vtkIdType anId = 0; anId < aNumPts; anId++){ + vtkIdType aPntId = aCell->GetPointId(anId); + //cout<SetDisplayPoint(theSelectionX, theSelectionY, theSelectionZ); + theRenderer->DisplayToWorld(); + float* 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(float, float, float, vtkRenderer*) +{ + return 0; +} + +//---------------------------------------------------------------------------- +int +SVTK_RectPicker +::Pick(float theSelection[3], float theSelection2[3], vtkRenderer *theRenderer) +{ + return Pick(theSelection[0], theSelection[1], theSelection[2], + theSelection2[0], theSelection2[1], theSelection2[2], + theRenderer); +} + +//---------------------------------------------------------------------------- +int +SVTK_RectPicker +::Pick(float theSelectionX, float theSelectionY, float theSelectionZ, + float theSelectionX2, float theSelectionY2, float 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(); + + float aCameraFP[4]; + aCamera->GetFocalPoint(aCameraFP); + aCameraFP[3] = 1.0; + + theRenderer->SetWorldPoint(aCameraFP); + theRenderer->WorldToDisplay(); + float* aDisplayCoords = theRenderer->GetDisplayPoint(); + float 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->GetProps(); + + 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()->GetProp(); + 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; +} + diff --git a/src/SVTK/SVTK_RectPicker.h b/src/SVTK/SVTK_RectPicker.h new file mode 100644 index 000000000..a9837c2d9 --- /dev/null +++ b/src/SVTK/SVTK_RectPicker.h @@ -0,0 +1,112 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_RectPicker.h +// Author : +// Module : SALOME + +#ifndef __SVTK_RectPicker_h +#define __SVTK_RectPicker_h + +#include "SVTK.h" + +#include +#include + +#include + +class vtkRenderer; + +/*! \class vtkAbstractPropPicker + * \brief For more information see VTK documentation + */ +/*! \class VTKViewer_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,float); + vtkGetMacro(Tolerance,float); + + //! Use these methods to pick points or points and cells + vtkSetMacro(PickPoints,int); + vtkGetMacro(PickPoints,int); + vtkBooleanMacro(PickPoints,int); + + virtual + int + Pick(float theSelectionX, float theSelectionY, float theSelectionZ, + float theSelectionX2, float theSelectionY2, float theSelectionZ2, + vtkRenderer *theRenderer); + + int + Pick(float theSelection[3], float theSelection2[3], vtkRenderer *theRenderer); + + typedef std::vector TVectorIds; + typedef std::map TVectorIdsMap; + + const TVectorIdsMap& + GetPointIdsMap() const; + + const TVectorIdsMap& + GetCellIdsMap() const; + + protected: + SVTK_RectPicker(); + ~SVTK_RectPicker(); + + //! tolerance for computation (% of window) + float Tolerance; + + //! use the following to control picking mode + int PickPoints; + + //! second rectangle selection point in window (pixel) coordinates + float SelectionPoint2[3]; + + //! second rectangle selection point in world coordinates + float PickPosition2[3]; + + TVectorIdsMap myPointIdsMap; + TVectorIdsMap myCellIdsMap; + + private: + virtual + int + Pick(float, float, float, vtkRenderer*); +}; + +#endif + + diff --git a/src/SVTK/SVTK_RenderWindow.cxx b/src/SVTK/SVTK_RenderWindow.cxx deleted file mode 100644 index d24e0a15a..000000000 --- a/src/SVTK/SVTK_RenderWindow.cxx +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// -// 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/ -// -#include "SVTK_RenderWindow.h" - -#include -#include - -#include -#include - -#include -#include -#include -#ifndef WNT -#include -//#include -//#include -//#include -#else -#include -#endif - -#if QT_VERSION > 300 -#include -#endif - -//========================================================== -SVTK_RenderWindow -::SVTK_RenderWindow(QWidget* parent, const char* name) : - QWidget(parent, name, - Qt::WStyle_NoBorder | Qt::WDestructiveClose | - Qt::WResizeNoErase | Qt::WRepaintNoErase) -{ - myRW = vtkRenderWindow::New(); -#ifndef WNT - myRW->SetDisplayId((void*)x11Display()); -#endif - myRW->SetWindowId((void*)winId()); - myRW->DoubleBufferOn(); - setMouseTracking(true); -} - -//========================================================== -SVTK_RenderWindow -::~SVTK_RenderWindow() -{ - myRW->Delete(); -} - -//========================================================== -void -SVTK_RenderWindow -::paintEvent(QPaintEvent* theEvent) -{ - myRW->Render(); -} - -//========================================================== -void -SVTK_RenderWindow -::resizeEvent(QResizeEvent* theEvent) -{ - int aWidth = myRW->GetSize()[0], aHeight = myRW->GetSize()[1]; - if(vtkRenderWindowInteractor* aRWI = myRW->GetInteractor()) - aRWI->UpdateSize(width(), height()); - if(aWidth != width() || aHeight != height()){ - vtkRendererCollection * aRenderers = myRW->GetRenderers(); - aRenderers->InitTraversal(); - double aCoeff = 1.0; - if(vtkRenderer *aRenderer = aRenderers->GetNextItem()){ - vtkCamera *aCamera = aRenderer->GetActiveCamera(); - double aScale = aCamera->GetParallelScale(); - if((aWidth - width())*(aHeight - height()) > 0) - aCoeff = sqrt(double(aWidth)/double(width())*double(height())/double(aHeight)); - else - aCoeff = double(aWidth)/double(width()); - aCamera->SetParallelScale(aScale*aCoeff); - } - } -} - -//========================================================== -void -SVTK_RenderWindow -::mouseMoveEvent(QMouseEvent* event) -{ - emit MouseMove(event) ; -} - -//========================================================== -void -SVTK_RenderWindow -::mousePressEvent(QMouseEvent* event) -{ - emit MouseButtonPressed( event ); -} - -//========================================================== -void -SVTK_RenderWindow -::mouseReleaseEvent( QMouseEvent *event ) -{ - emit MouseButtonReleased( event ); -} - -//========================================================== -void -SVTK_RenderWindow::mouseDoubleClickEvent( QMouseEvent* event ) -{ - emit MouseDoubleClicked( event ); -} - -//========================================================== -void -SVTK_RenderWindow -::keyPressEvent (QKeyEvent* event) -{ - emit KeyPressed(event) ; -} - -//========================================================== -void -SVTK_RenderWindow -::keyReleaseEvent (QKeyEvent * event) -{ - emit KeyReleased(event) ; -} - -//========================================================== -void -SVTK_RenderWindow -::wheelEvent(QWheelEvent* event) -{ - emit WheelMoved(event) ; -} - -//========================================================== -void -SVTK_RenderWindow -::onChangeBackgroundColor() -{ - //float red, green, blue; - float backint[3]; - - vtkRendererCollection * theRenderers = myRW->GetRenderers(); - theRenderers->InitTraversal(); - vtkRenderer * theRenderer = theRenderers->GetNextItem(); - theRenderer->GetBackground(backint); - - QColor selColor = QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL ); - if ( selColor.isValid() ) { - theRenderer->SetBackground( selColor.red()/255., selColor.green()/255., selColor.blue()/255. ); - } -} - -//========================================================== -void -SVTK_RenderWindow -::contextMenuEvent ( QContextMenuEvent * e ) -{ - if ( e->reason() != QContextMenuEvent::Mouse ) - emit contextMenuRequested( e ); -} diff --git a/src/SVTK/SVTK_RenderWindow.h b/src/SVTK/SVTK_RenderWindow.h deleted file mode 100644 index 35f5b6d21..000000000 --- a/src/SVTK/SVTK_RenderWindow.h +++ /dev/null @@ -1,83 +0,0 @@ -// SALOME VTKViewer : build VTK viewer into Salome desktop -// -// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : VTKViewer_RenderWindow.h -// Author : Nicolas REJNERI -// Module : SALOME -// $Header$ - -#ifndef SVTK_RenderWindow_h -#define SVTK_RenderWindow_h - -#include - -#include "SVTK.h" - -class vtkRenderWindow; - -class SVTK_EXPORT SVTK_RenderWindow : public QWidget -{ - Q_OBJECT; - -public: - SVTK_RenderWindow(QWidget *parent, const char *name); - virtual ~SVTK_RenderWindow() ; - - vtkRenderWindow* getRenderWindow() { return myRW; } - - protected: - virtual void mouseMoveEvent( QMouseEvent* ); - virtual void mousePressEvent( QMouseEvent* ); - virtual void mouseReleaseEvent( QMouseEvent* ); - virtual void mouseDoubleClickEvent( QMouseEvent* ); - virtual void wheelEvent( QWheelEvent* ); - virtual void keyPressEvent( QKeyEvent* ); - virtual void keyReleaseEvent( QKeyEvent* ); - virtual void paintEvent( QPaintEvent* ); - virtual void resizeEvent( QResizeEvent* ); - virtual void onChangeBackgroundColor(); - virtual void contextMenuEvent( QContextMenuEvent * e ); - - signals: - void MouseMove( QMouseEvent* ); - void MouseButtonPressed( QMouseEvent* ); - void MouseButtonReleased( QMouseEvent* ); - void MouseDoubleClicked( QMouseEvent* ); - void WheelMoved( QWheelEvent* ); - void LeftButtonPressed(const QMouseEvent *event) ; - void LeftButtonReleased(const QMouseEvent *event) ; - void MiddleButtonPressed(const QMouseEvent *event) ; - void MiddleButtonReleased(const QMouseEvent *event) ; - void RightButtonPressed(const QMouseEvent *event) ; - void RightButtonReleased(const QMouseEvent *event) ; - void ButtonPressed(const QMouseEvent *event); - void ButtonReleased(const QMouseEvent *event); - void KeyPressed( QKeyEvent* ); - void KeyReleased( QKeyEvent* ); - void contextMenuRequested( QContextMenuEvent *e ); - - protected: - vtkRenderWindow* myRW; -}; - -#endif diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index 55dd794e7..a2b8aa176 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -21,980 +21,641 @@ // // // -// File : VTKViewer_RenderWindowInteractor.cxx -// Author : Nicolas REJNERI +// File : +// Author : // Module : SALOME // $Header$ #include "SVTK_RenderWindowInteractor.h" +#include "SVTK_GenericRenderWindowInteractor.h" #include "SVTK_InteractorStyle.h" -#include "SVTK_RenderWindow.h" -#include "SVTK_ViewWindow.h" - -#include "VTKViewer_Algorithm.h" +#include "SVTK_Renderer.h" #include "SVTK_Functor.h" -#include "SVTK_Actor.h" +#include "SALOME_Actor.h" -#include -#include -#include -#include +#include "SVTK_SpaceMouse.h" +#include "SVTK_Event.h" + +#include "VTKViewer_Algorithm.h" // VTK Includes #include -#include -#include -#include #include #include +#include +#include +#include +#include +#include // QT Includes -#include - -#include +#include +#include +#include +#include using namespace std; -SVTK_RenderWindowInteractor* -SVTK_RenderWindowInteractor -::New() -{ - vtkObject *ret = vtkObjectFactory::CreateInstance("SVTK_RenderWindowInteractor") ; - if( ret ) { - return dynamic_cast(ret) ; - } - return new SVTK_RenderWindowInteractor; -} - -SVTK_RenderWindowInteractor -::SVTK_RenderWindowInteractor() -{ - this->Enabled = 0 ; - this->mTimer = new QTimer( this ) ; - myDisplayMode = 0; - myGUIWindow = 0; - - myBasicPicker = vtkPicker::New(); - myCellPicker = vtkCellPicker::New(); - myPointPicker = vtkPointPicker::New(); +static bool GENERATE_SUIT_EVENTS = false; +static bool FOCUS_UNDER_MOUSE = false; - myCellActor = SVTK_Actor::New(); - myCellActor->PickableOff(); - myCellActor->GetProperty()->SetColor(1,1,0); - myCellActor->GetProperty()->SetLineWidth(5); - myCellActor->GetProperty()->SetRepresentationToSurface(); - myEdgeActor = SVTK_Actor::New(); - myEdgeActor->PickableOff(); - myEdgeActor->GetProperty()->SetColor(1,0,0); - myEdgeActor->GetProperty()->SetLineWidth(5); - myEdgeActor->GetProperty()->SetRepresentationToWireframe(); +//---------------------------------------------------------------------------- +QVTK_RenderWindowInteractor +::QVTK_RenderWindowInteractor(QWidget* theParent, + const char* theName): + QWidget(theParent,theName,Qt::WNoAutoErase), + myRenderWindow(vtkRenderWindow::New()) +{ + setMouseTracking(true); - myPointActor = SVTK_Actor::New(); - myPointActor->PickableOff(); - myPointActor->GetProperty()->SetColor(1,1,0); - myPointActor->GetProperty()->SetPointSize(5); - myPointActor->GetProperty()->SetRepresentationToPoints(); + myRenderWindow->Delete(); + myRenderWindow->DoubleBufferOn(); - connect(mTimer, SIGNAL(timeout()), this, SLOT(TimerFunc())) ; +#ifndef WNT + myRenderWindow->SetDisplayId((void*)x11Display()); +#endif + myRenderWindow->SetWindowId((void*)winId()); } -SVTK_RenderWindowInteractor -::~SVTK_RenderWindowInteractor() +void +QVTK_RenderWindowInteractor +::Initialize(vtkGenericRenderWindowInteractor* theDevice) { - delete mTimer ; + if(GetDevice()) + myDevice->SetRenderWindow(NULL); - myViewWindow->RemoveActor(myCellActor); - myViewWindow->RemoveActor(myEdgeActor); - myViewWindow->RemoveActor(myPointActor); + myDevice = theDevice; - myCellActor->Delete(); - myEdgeActor->Delete(); - myPointActor->Delete(); - - myBasicPicker->Delete(); - myCellPicker->Delete(); - myPointPicker->Delete(); + if(theDevice) + theDevice->SetRenderWindow(getRenderWindow()); } -// -// We never allow the SVTK_RenderWindowInteractor to control -// the event loop. The application always has the control. -// -void -SVTK_RenderWindowInteractor -::Initialize() -{ - // - // We cannot do much unless there is a render window - // associated with this interactor. - // - if( ! RenderWindow ) { - vtkErrorMacro(<< "SVTK_RenderWindowInteractor::Initialize(): No render window attached!") ; - return ; - } - - // - // We cannot hand a render window which is not a VTKViewer_RenderWindow. - // One way to force this is to use dynamic_cast and hope that - // it works. If the dynamic_cast does not work, we flag an error - // and get the hell out. - // - vtkRenderWindow *aRenderWindow = dynamic_cast(RenderWindow) ; - if( !aRenderWindow ) { - vtkErrorMacro(<< "SVTK_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ; - return ; - } - - // - // If the render window has zero size, then set it to a default - // value of 300x300. - // - int* aSize = aRenderWindow->GetSize(); - this->Size[0] = ((aSize[0] > 0) ? aSize[0] : 300); - this->Size[1] = ((aSize[1] > 0) ? aSize[1] : 300); - - this->SetPicker(myBasicPicker); - - SetSelectionTolerance(); - - // - // Enable the interactor. - // - this->Enable() ; - - // - // Start the rendering of the window. - // - aRenderWindow->Start() ; - - // - // The interactor has been initialized. - // - this->Initialized = 1 ; - - return ; +//---------------------------------------------------------------------------- +QVTK_RenderWindowInteractor +::~QVTK_RenderWindowInteractor() +{ + if(SVTK_SpaceMouse* aSpaceMouse = SVTK_SpaceMouse::getInstance()) + if(aSpaceMouse->isSpaceMouseOn()) + aSpaceMouse->close(x11Display()); } //---------------------------------------------------------------------------- -void -SVTK_RenderWindowInteractor -::setGUIWindow(QWidget* theWindow) +vtkGenericRenderWindowInteractor* +QVTK_RenderWindowInteractor +::GetDevice() { - myGUIWindow = theWindow; + return myDevice.GetPointer(); } //---------------------------------------------------------------------------- -void -SVTK_RenderWindowInteractor -::setViewWindow(SVTK_ViewWindow* theViewWindow) +vtkRenderWindow* +QVTK_RenderWindowInteractor +::getRenderWindow() { - myViewWindow = theViewWindow; - - myViewWindow->InsertActor(myCellActor); - myViewWindow->InsertActor(myEdgeActor); - myViewWindow->InsertActor(myPointActor); + return myRenderWindow.GetPointer(); } //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::MoveInternalActors() +QVTK_RenderWindowInteractor +::InvokeEvent(unsigned long theEvent, void* theCallData) { - myViewWindow->MoveActor(myCellActor); - myViewWindow->MoveActor(myEdgeActor); - myViewWindow->MoveActor(myPointActor); + GetDevice()->InvokeEvent(theEvent,theCallData); } //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::SetInteractorStyle(vtkInteractorObserver *theInteractor) +QVTK_RenderWindowInteractor +::show() { - myInteractorStyle = dynamic_cast(theInteractor); - vtkRenderWindowInteractor::SetInteractorStyle(theInteractor); + QWidget::show(); + update(); // needed for initial contents display on Win32 } - +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::SetSelectionMode(Selection_Mode theMode) +QVTK_RenderWindowInteractor +::polish() { - myCellActor->SetVisibility(false); - myEdgeActor->SetVisibility(false); - myPointActor->SetVisibility(false); - - switch(theMode){ - case ActorSelection: - this->SetPicker(myBasicPicker); - break; - case NodeSelection: - this->SetPicker(myPointPicker); - break; - case CellSelection: - case EdgeSelection: - case FaceSelection: - case VolumeSelection: - case EdgeOfCellSelection: - this->SetPicker(myCellPicker); - break; + // Final initialization just before the widget is displayed + GetDevice()->SetSize(width(),height()); + if(!GetDevice()->GetInitialized()){ + GetDevice()->Initialize(); + GetDevice()->ConfigureEvent(); } - - myInteractorStyle->OnSelectionModeChanged(); } +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::SetSelectionProp(const double& theRed, - const double& theGreen, - const double& theBlue, - const int& theWidth) +QVTK_RenderWindowInteractor +::resize(int w, int h) { - myCellActor->GetProperty()->SetColor(theRed, theGreen, theBlue); - myCellActor->GetProperty()->SetLineWidth(theWidth); - - myPointActor->GetProperty()->SetColor(theRed, theGreen, theBlue); - myPointActor->GetProperty()->SetPointSize(theWidth); + GetDevice()->UpdateSize(w,h); } +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::SetSelectionTolerance(const double& theTolNodes, - const double& theTolItems) +QVTK_RenderWindowInteractor +::paintEvent( QPaintEvent* theEvent ) { - myTolNodes = theTolNodes; - myTolItems = theTolItems; - - myBasicPicker->SetTolerance(myTolItems); - myCellPicker->SetTolerance(myTolItems); - myPointPicker->SetTolerance(myTolNodes); - + GetDevice()->Render(); } -// ================================== -void -SVTK_RenderWindowInteractor -::Start() -{ - // - // We do not allow this interactor to control the - // event loop. Only the QtApplication objects are - // allowed to do that. - // - vtkErrorMacro(<<"SVTK_RenderWindowInteractor::Start() not allowed to start event loop.") ; - return ; -} +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::UpdateSize(int w, int h) -{ - // if the size changed send this on to the RenderWindow - if ((w != this->Size[0])||(h != this->Size[1])) { - this->Size[0] = w; - this->Size[1] = h; - this->RenderWindow->SetSize(w,h); +QVTK_RenderWindowInteractor +::resizeEvent( QResizeEvent* theEvent ) +{ + int* aSize = getRenderWindow()->GetSize(); + int aWidth = aSize[0]; + int aHeight = aSize[1]; + + GetDevice()->UpdateSize(width(),height()); + + if(isVisible() && aWidth && aHeight){ + if( aWidth != width() || aHeight != height() ) { + vtkRendererCollection * aRenderers = getRenderWindow()->GetRenderers(); + aRenderers->InitTraversal(); + double aCoeff = 1.0; + if(vtkRenderer *aRenderer = aRenderers->GetNextItem()) { + vtkCamera *aCamera = aRenderer->GetActiveCamera(); + double aScale = aCamera->GetParallelScale(); + if((aWidth - width())*(aHeight - height()) > 0) + aCoeff = sqrt(double(aWidth)/double(width())*double(height())/double(aHeight)); + else + aCoeff = double(aWidth)/double(width()); + aCamera->SetParallelScale(aScale*aCoeff); + } + } } -} -int -SVTK_RenderWindowInteractor -::CreateTimer(int vtkNotUsed(timertype)) -{ - // - // Start a one-shot timer for 10ms. - // - mTimer->start(10, TRUE) ; - return 1 ; + update(); } -int -SVTK_RenderWindowInteractor -::DestroyTimer(void) -{ - // - // :TRICKY: Tue May 2 00:17:32 2000 Pagey - // - // QTimer will automatically expire after 10ms. So - // we do not need to do anything here. In fact, we - // should not even Stop() the QTimer here because doing - // this will skip some of the processing that the TimerFunc() - // does and will result in undesirable effects. For - // example, this will result in vtkLODActor to leave - // the models in low-res mode after the mouse stops - // moving. - // - return 1 ; -} +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::TimerFunc() -{ - if( ! this->Enabled ) { - return ; - } +QVTK_RenderWindowInteractor +::contextMenuEvent( QContextMenuEvent* event ) +{} - myInteractorStyle->OnTimer(); - emit RenderWindowModified(); +//---------------------------------------------------------------------------- +void +QVTK_RenderWindowInteractor +::mouseMoveEvent( QMouseEvent* event ) +{ + GetDevice()->SetEventInformationFlipY(event->x(), + event->y(), + event->state() & ControlButton, + event->state() & ShiftButton); + GetDevice()->MouseMoveEvent(); } + +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::MouseMove(const QMouseEvent *event) +QVTK_RenderWindowInteractor +::mousePressEvent( QMouseEvent* event ) { - if( ! this->Enabled ) { - return ; - } - myInteractorStyle->OnMouseMove(0, 0, event->x(), event->y()/*this->Size[1] - event->y() - 1*/) ; - if (myInteractorStyle->needsRedrawing() ) - emit RenderWindowModified() ; + GetDevice()->SetEventInformationFlipY(event->x(), + event->y(), + event->state() & ControlButton, + event->state() & ShiftButton); + if( event->button() & LeftButton ) + GetDevice()->LeftButtonPressEvent(); + else if( event->button() & MidButton ) + GetDevice()->MiddleButtonPressEvent(); + else if( event->button() & RightButton ) + GetDevice()->RightButtonPressEvent(); } + +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::LeftButtonPressed(const QMouseEvent *event) +QVTK_RenderWindowInteractor +::mouseReleaseEvent( QMouseEvent *event ) { - if( ! this->Enabled ) { - return ; - } - myInteractorStyle->OnLeftButtonDown((event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y()); + GetDevice()->SetEventInformationFlipY(event->x(), + event->y(), + event->state() & ControlButton, + event->state() & ShiftButton); + + if( event->button() & LeftButton ) + GetDevice()->LeftButtonReleaseEvent(); + else if( event->button() & MidButton ) + GetDevice()->MiddleButtonReleaseEvent(); + else if( event->button() & RightButton ) + GetDevice()->RightButtonReleaseEvent(); } + +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::LeftButtonReleased(const QMouseEvent *event) { - if( ! this->Enabled ) { - return ; - } - myInteractorStyle->OnLeftButtonUp( (event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; -} +QVTK_RenderWindowInteractor +::mouseDoubleClickEvent( QMouseEvent* event ) +{} -void -SVTK_RenderWindowInteractor -::MiddleButtonPressed(const QMouseEvent *event) -{ - if( ! this->Enabled ) { - return ; - } - myInteractorStyle->OnMiddleButtonDown((event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; -} +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::MiddleButtonReleased(const QMouseEvent *event) +QVTK_RenderWindowInteractor +::wheelEvent( QWheelEvent* event ) { - if( ! this->Enabled ) { - return ; - } - myInteractorStyle->OnMiddleButtonUp( (event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; + setActiveWindow(); + setFocus(); } + +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::RightButtonPressed(const QMouseEvent *event) +QVTK_RenderWindowInteractor +::keyPressEvent( QKeyEvent* event ) { - if( ! this->Enabled ) { - return ; - } - myInteractorStyle->OnRightButtonDown( (event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; + GetDevice()->SetKeyEventInformation(event->state() & ControlButton, + event->state() & ShiftButton, + event->key()); + GetDevice()->KeyPressEvent(); + GetDevice()->CharEvent(); } +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::RightButtonReleased(const QMouseEvent *event) +QVTK_RenderWindowInteractor +::keyReleaseEvent( QKeyEvent * event ) { - if( ! this->Enabled ) { - return ; - } - myInteractorStyle->OnRightButtonUp( (event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; - - if(myInteractorStyle->GetState() == VTK_INTERACTOR_STYLE_CAMERA_NONE && !( event->state() & KeyButtonMask )){ - QContextMenuEvent aEvent( QContextMenuEvent::Mouse, - event->pos(), event->globalPos(), - event->state() ); - emit contextMenuRequested( &aEvent ); - } + GetDevice()->SetKeyEventInformation(event->state() & ControlButton, + event->state() & ShiftButton, + event->key()); + GetDevice()->KeyReleaseEvent(); } -void -SVTK_RenderWindowInteractor -::ButtonPressed(const QMouseEvent *event) + +//---------------------------------------------------------------------------- +void +QVTK_RenderWindowInteractor +::enterEvent( QEvent* event ) { - return ; + if(FOCUS_UNDER_MOUSE){ + setActiveWindow(); + setFocus(); + } + GetDevice()->EnterEvent(); } -void -SVTK_RenderWindowInteractor -::ButtonReleased(const QMouseEvent *event) +//---------------------------------------------------------------------------- +void +QVTK_RenderWindowInteractor +::leaveEvent( QEvent * ) { - return ; + GetDevice()->LeaveEvent(); } -int -SVTK_RenderWindowInteractor -::GetDisplayMode() -{ - return myDisplayMode; +//---------------------------------------------------------------------------- +void +QVTK_RenderWindowInteractor +::focusInEvent( QFocusEvent* event ) +{ + QWidget::focusInEvent( event ); + + // register set space mouse events receiver + if(SVTK_SpaceMouse* aSpaceMouse = SVTK_SpaceMouse::getInstance()){ + if(!aSpaceMouse->isSpaceMouseOn()) {// initialize 3D space mouse driver + aSpaceMouse->initialize(x11Display(),winId()); + }else{ + aSpaceMouse->setWindow(x11Display(),winId()); + } + } } -void -SVTK_RenderWindowInteractor -::SetDisplayMode(int theMode) +//---------------------------------------------------------------------------- +void +QVTK_RenderWindowInteractor +::focusOutEvent ( QFocusEvent* event ) { - if(theMode == 0) - ChangeRepresentationToWireframe(); - else - ChangeRepresentationToSurface(); - myDisplayMode = theMode; + QWidget::focusOutEvent( event ); + + // unregister set space mouse events receiver + if(SVTK_SpaceMouse* aSpaceMouse = SVTK_SpaceMouse::getInstance()){ + if(aSpaceMouse->isSpaceMouseOn()) + aSpaceMouse->setWindow(x11Display(),0); + } } -void -SVTK_RenderWindowInteractor -::SetDisplayMode(const Handle(SALOME_InteractiveObject)& theIObject, - int theMode) -{ - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetFunction - (&SALOME_Actor::setDisplayMode,theMode)); +//---------------------------------------------------------------------------- +bool +QVTK_RenderWindowInteractor +::x11Event( XEvent *xEvent ) +{ + // handle 3d space mouse events + if(SVTK_SpaceMouse* aSpaceMouse = SVTK_SpaceMouse::getInstance()){ + if(aSpaceMouse->isSpaceMouseOn() && xEvent->type == ClientMessage){ + SVTK_SpaceMouse::MoveEvent anEvent; + int type = aSpaceMouse->translateEvent( x11Display(), xEvent, &anEvent, 1.0, 1.0 ); + switch( type ){ + case SVTK_SpaceMouse::SpaceMouseMove : + GetDevice()->InvokeEvent(SVTK::SpaceMouseMoveEvent, anEvent.data ); + break; + case SVTK_SpaceMouse::SpaceButtonPress : + GetDevice()->InvokeEvent( SVTK::SpaceMouseButtonEvent, &anEvent.button ); + break; + case SVTK_SpaceMouse::SpaceButtonRelease : + break; + } + return true; // stop handling the event + } + } + + return QWidget::x11Event( xEvent ); } -void +//---------------------------------------------------------------------------- SVTK_RenderWindowInteractor -::ChangeRepresentationToWireframe() +::SVTK_RenderWindowInteractor(QWidget* theParent, + const char* theName): + QVTK_RenderWindowInteractor(theParent,theName), + myEventCallbackCommand(vtkCallbackCommand::New()) { - ChangeRepresentationToWireframe(GetRenderer()->GetActors()); + myEventCallbackCommand->Delete(); + + myEventCallbackCommand->SetClientData(this); + myPriority = 0.0; + + myEventCallbackCommand->SetCallback(SVTK_RenderWindowInteractor::ProcessEvents); } void SVTK_RenderWindowInteractor -::ChangeRepresentationToSurface() +::Initialize(vtkGenericRenderWindowInteractor* theDevice, + SVTK_Renderer* theRenderer, + SVTK_Selector* theSelector) { - ChangeRepresentationToSurface(GetRenderer()->GetActors()); + QVTK_RenderWindowInteractor::Initialize(theDevice); + SetRenderer(theRenderer); + SetSelector(theSelector); } - -void +//---------------------------------------------------------------------------- SVTK_RenderWindowInteractor -::ChangeRepresentationToWireframe(vtkActorCollection* theCollection) +::~SVTK_RenderWindowInteractor() { - using namespace VTK; - ForEach(theCollection, - TSetFunction - (&SALOME_Actor::setDisplayMode,0)); - emit RenderWindowModified(); + // Sequence of the destruction call are fixed and should be changed. + // vtkRenderWindow instance should be destroyed after all vtkRenderer's + GetDevice()->SetInteractorStyle(NULL); + while(!myInteractorStyles.empty()){ + const PInteractorStyle& aStyle = myInteractorStyles.top(); + aStyle->SetInteractor(NULL); + myInteractorStyles.pop(); + } + + SetRenderer(NULL); + + GetDevice()->SetRenderWindow(NULL); } -void +//---------------------------------------------------------------------------- +SVTK_Renderer* SVTK_RenderWindowInteractor -::ChangeRepresentationToSurface(vtkActorCollection* theCollection) +::GetRenderer() { - using namespace VTK; - ForEach(theCollection, - TSetFunction - (&SALOME_Actor::setDisplayMode,1)); - emit RenderWindowModified(); + return myRenderer.GetPointer(); } - vtkRenderer* SVTK_RenderWindowInteractor -::GetRenderer() +::getRenderer() { - vtkRendererCollection * theRenderers = this->RenderWindow->GetRenderers(); - theRenderers->InitTraversal(); - return theRenderers->GetNextItem(); + return GetRenderer()->GetDevice(); } - -struct TErase{ - VTK::TSetFunction mySetFunction; - TErase(): - mySetFunction(&vtkActor::SetVisibility,false) - {} - void operator()(SALOME_Actor* theActor){ - theActor->SetVisibility(false); - // Erase dependent actors - vtkActorCollection* aCollection = vtkActorCollection::New(); - theActor->GetChildActors(aCollection); - VTK::ForEach(aCollection,mySetFunction); - aCollection->Delete(); - } -}; - void SVTK_RenderWindowInteractor -::EraseAll() -{ - using namespace VTK; - ForEach(GetRenderer()->GetActors(), - TErase()); +::SetRenderer(SVTK_Renderer* theRenderer) +{ + if(theRenderer == myRenderer.GetPointer()) + return; - emit RenderWindowModified() ; -} + if(GetRenderer()) + myRenderWindow->RemoveRenderer(getRenderer()); -void -SVTK_RenderWindowInteractor -::DisplayAll() -{ - vtkActorCollection* aCollection = GetRenderer()->GetActors(); - using namespace VTK; - ForEach(aCollection,TSetVisibility(true)); + myRenderer = theRenderer; - emit RenderWindowModified() ; + if(GetRenderer()) + myRenderWindow->AddRenderer(getRenderer()); } +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::Erase(SALOME_Actor* theActor, bool update) +::InitInteractorStyle(vtkInteractorStyle* theStyle) { - TErase()(theActor); - - if(update) - emit RenderWindowModified(); + GetDevice()->SetInteractorStyle(theStyle); } +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::Erase(const Handle(SALOME_InteractiveObject)& theIObject, - bool update) +::PushInteractorStyle(vtkInteractorStyle* theStyle) { - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - TErase()); - - if(update) - emit RenderWindowModified(); + myInteractorStyles.push(PInteractorStyle(theStyle)); + InitInteractorStyle(theStyle); } -struct TRemoveAction{ - vtkRenderer* myRen; - TRemoveAction(vtkRenderer* theRen): myRen(theRen){} - void operator()(SALOME_Actor* theActor){ - myRen->RemoveActor(theActor); - } -}; - -void -SVTK_RenderWindowInteractor -::Remove(const Handle(SALOME_InteractiveObject)& theIObject, - bool update) -{ - vtkRenderer* aRen = GetRenderer(); - - using namespace VTK; - ForEachIf(aRen->GetActors(), - TIsSameIObject(theIObject), - TRemoveAction(aRen)); -} - +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::Remove( SALOME_Actor* SActor, bool updateViewer ) +::PopInteractorStyle() { - if ( SActor != 0 ) - { - GetRenderer()->RemoveProp( SActor ); - if ( updateViewer ) - emit RenderWindowModified(); - } -} - -void -SVTK_RenderWindowInteractor -::RemoveAll( const bool updateViewer ) -{ - vtkRenderer* aRenderer = GetRenderer(); - vtkActorCollection* anActors = aRenderer->GetActors(); - if ( anActors ) - { - anActors->InitTraversal(); - while ( vtkActor *anAct = anActors->GetNextActor() ) - { - if ( anAct->IsA( "SALOME_Actor" ) ) - { - SALOME_Actor* aSAct = (SALOME_Actor*)anAct; - if ( aSAct->hasIO() && aSAct->getIO()->hasEntry() ) - aRenderer->RemoveActor( anAct ); - } - } - - if ( updateViewer ) - emit RenderWindowModified(); - } + if(GetInteractorStyle()) + myInteractorStyles.pop(); + + if(GetInteractorStyle()) + InitInteractorStyle(GetInteractorStyle()); } -float +//---------------------------------------------------------------------------- +vtkInteractorStyle* SVTK_RenderWindowInteractor -::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject) +::GetInteractorStyle() { - using namespace VTK; - SALOME_Actor* anActor = - Find(GetRenderer()->GetActors(), - TIsSameIObject(theIObject)); - if(anActor) - return 1.0 - anActor->GetOpacity(); - return -1.0; + return myInteractorStyles.empty() ? 0 : myInteractorStyles.top().GetPointer(); } -void +//---------------------------------------------------------------------------- +SVTK_Selector* SVTK_RenderWindowInteractor -::SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, - float theTrans) -{ - float anOpacity = 1.0 - theTrans; - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetFunction - (&SALOME_Actor::SetOpacity,anOpacity)); +::GetSelector() +{ + return mySelector.GetPointer(); } void SVTK_RenderWindowInteractor -::Display(SALOME_Actor* theActor, bool update) -{ - GetRenderer()->AddActor(theActor); - theActor->SetVisibility(true); +::SetSelector(SVTK_Selector* theSelector) +{ + if(mySelector.GetPointer()) + mySelector->RemoveObserver(myEventCallbackCommand.GetPointer()); + + mySelector = theSelector; - if(update) - emit RenderWindowModified(); + if(mySelector.GetPointer()) + mySelector->AddObserver(vtkCommand::EndPickEvent, + myEventCallbackCommand.GetPointer(), + myPriority); } -void +//---------------------------------------------------------------------------- +void SVTK_RenderWindowInteractor -::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update) +::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) { - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetVisibility(true)); + SVTK_RenderWindowInteractor* self = reinterpret_cast(theClientData); - if(update) - emit RenderWindowModified() ; + switch(theEvent){ + case vtkCommand::EndPickEvent: + self->onEmitSelectionChanged(); + break; + } } +//---------------------------------------------------------------- void SVTK_RenderWindowInteractor -::KeyPressed(QKeyEvent *event) -{} - - -struct THighlightAction{ - bool myIsHighlight; - SVTK_InteractorStyle* myInteractorStyle; - THighlightAction(SVTK_InteractorStyle* theInteractorStyle, - bool theIsHighlight): - myInteractorStyle(theInteractorStyle), - myIsHighlight(theIsHighlight) - {} - void operator()(SALOME_Actor* theActor){ - if(theActor->GetMapper()){ - if(theActor->hasHighlight()) - theActor->highlight(myIsHighlight); - else{ - if(theActor->GetVisibility() && myIsHighlight) - myInteractorStyle->HighlightProp(theActor); - else if(!myIsHighlight) - myInteractorStyle->HighlightProp(NULL); - } - } - } -}; - -bool -SVTK_RenderWindowInteractor -::highlight( const Handle(SALOME_InteractiveObject)& theIObject, - bool hilight, - bool update) +::SetSelectionMode(Selection_Mode theMode) { - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - THighlightAction(myInteractorStyle,hilight)); - - if(update) - emit RenderWindowModified(); - - return false; + mySelector->SetSelectionMode(theMode); } -struct TUpdateAction{ - void operator()(vtkActor* theActor){ - theActor->ApplyProperties(); - } -}; - -void +//---------------------------------------------------------------- +Selection_Mode SVTK_RenderWindowInteractor -::Update() +::SelectionMode() const { - vtkRenderer* aRen = GetRenderer(); - - using namespace VTK; - ForEach(aRen->GetActors(),TUpdateAction()); - - aRen->ResetCamera(); - - emit RenderWindowModified(); + return mySelector->SelectionMode(); } +//---------------------------------------------------------------- void SVTK_RenderWindowInteractor -::unHighlightSubSelection() +::onEmitSelectionChanged() { - myPointActor->SetVisibility(false); - myEdgeActor->SetVisibility(false); - myCellActor->SetVisibility(false); + return emit selectionChanged(); } -bool +//---------------------------------------------------------------------------- +void SVTK_RenderWindowInteractor -::unHighlightAll() +::mouseMoveEvent( QMouseEvent* event ) { - unHighlightSubSelection(); - - using namespace VTK; - ForEach(GetRenderer()->GetActors(), - THighlightAction(myInteractorStyle,false)); + QVTK_RenderWindowInteractor::mouseMoveEvent(event); - emit RenderWindowModified() ; - - return false; + if(GENERATE_SUIT_EVENTS) + emit MouseMove( event ); } -//----------------- -// Color methods -//----------------- +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::SetColor(const Handle(SALOME_InteractiveObject)& theIObject,QColor theColor) +::mousePressEvent( QMouseEvent* event ) { - float aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.}; - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetFunction - (&SALOME_Actor::SetColor,aColor)); -} - + QVTK_RenderWindowInteractor::mousePressEvent(event); -QColor -SVTK_RenderWindowInteractor -::GetColor(const Handle(SALOME_InteractiveObject)& theIObject) -{ - using namespace VTK; - SALOME_Actor* anActor = - Find(GetRenderer()->GetActors(), - TIsSameIObject(theIObject)); - if(anActor){ - float r,g,b; - anActor->GetColor(r,g,b); - return QColor(int(r*255),int(g*255),int(b*255)); - } - return QColor(0,0,0); + if(GENERATE_SUIT_EVENTS) + emit MouseButtonPressed( event ); } -bool +//---------------------------------------------------------------------------- +void SVTK_RenderWindowInteractor -::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject) +::mouseReleaseEvent( QMouseEvent *event ) { - using namespace VTK; - SALOME_Actor* anActor = - Find(GetRenderer()->GetActors(), - TIsSameIObject(theIObject)); - return anActor != NULL; -} + QVTK_RenderWindowInteractor::mouseReleaseEvent(event); - -bool -SVTK_RenderWindowInteractor -::isVisible(const Handle(SALOME_InteractiveObject)& theIObject) -{ - using namespace VTK; - SALOME_Actor* anActor = - Find(GetRenderer()->GetActors(), - TIsSameIObject(theIObject)); - return anActor != NULL && anActor->GetVisibility(); + if(GENERATE_SUIT_EVENTS) + emit MouseButtonReleased( event ); } +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::rename(const Handle(SALOME_InteractiveObject)& theIObject, QString theName) +::mouseDoubleClickEvent( QMouseEvent* event ) { - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetFunction - (&SALOME_Actor::setName,theName.latin1())); + QVTK_RenderWindowInteractor::mouseDoubleClickEvent(event); + + if(GENERATE_SUIT_EVENTS) + emit MouseDoubleClicked( event ); } //---------------------------------------------------------------------------- -bool -SVTK_RenderWindowInteractor -::highlight(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor, - TUpdateActor theFun, - bool hilight, - bool update) -{ - if(theMapIndex.Extent() == 0) return false; - - if (hilight) { - setActorData(theMapIndex,theMapActor,theActor,theFun); - theActor->SetVisibility(true); - } - else { - theActor->SetVisibility(false); - } - - if(update){ - this->RenderWindow->Render(); - emit RenderWindowModified() ; - } - - return false; -} - void SVTK_RenderWindowInteractor -::setActorData(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor *theActor, - TUpdateActor theFun) +::wheelEvent( QWheelEvent* event ) { - (*theFun)(theMapIndex,theMapActor,theActor); - float aPos[3]; - theMapActor->GetPosition(aPos); - theActor->SetPosition(aPos); -} + QVTK_RenderWindowInteractor::wheelEvent(event); + if(event->delta() > 0) + GetDevice()->InvokeEvent(SVTK::ZoomInEvent,NULL); + else + GetDevice()->InvokeEvent(SVTK::ZoomOutEvent,NULL); -//---------------------------------------------------------------------------- -static void CellsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor) -{ - theActor->MapCells(theMapActor,theMapIndex); -} - -bool -SVTK_RenderWindowInteractor -::highlightCell(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - bool hilight, - bool update) -{ - return highlight(theMapIndex,theMapActor,myCellActor,&CellsUpdateActor,hilight,update); -} - -void -SVTK_RenderWindowInteractor -::setCellData(const int& theIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor) -{ - TColStd_IndexedMapOfInteger MapIndex; - MapIndex.Add(theIndex); - theActor->MapCells(theMapActor,MapIndex); + if(GENERATE_SUIT_EVENTS) + emit WheelMoved( event ); } //---------------------------------------------------------------------------- -static void PointsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor) -{ - theActor->MapPoints(theMapActor,theMapIndex); -} - -bool +void SVTK_RenderWindowInteractor -::highlightPoint(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - bool hilight, - bool update) +::keyPressEvent( QKeyEvent* event ) { - return highlight(theMapIndex,theMapActor,myPointActor,&PointsUpdateActor,hilight,update); + QVTK_RenderWindowInteractor::keyPressEvent(event); + + if(GENERATE_SUIT_EVENTS) + emit KeyPressed( event ); } - + +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::setPointData(const int& theIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor) +::keyReleaseEvent( QKeyEvent * event ) { - TColStd_IndexedMapOfInteger MapIndex; - MapIndex.Add(theIndex); - theActor->MapPoints(theMapActor,MapIndex); + QVTK_RenderWindowInteractor::keyReleaseEvent(event); + + if(GENERATE_SUIT_EVENTS) + emit KeyReleased( event ); } - //---------------------------------------------------------------------------- -static void EdgesUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor) -{ - theActor->MapEdge(theMapActor,theMapIndex); -} - -bool +void SVTK_RenderWindowInteractor -::highlightEdge(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - bool hilight, - bool update) +::contextMenuEvent( QContextMenuEvent* event ) { - return highlight(theMapIndex,theMapActor,myEdgeActor,&EdgesUpdateActor,hilight,update); -} - -void -SVTK_RenderWindowInteractor -::setEdgeData(const int& theCellIndex, - SALOME_Actor* theMapActor, - const int& theEdgeIndex, - SVTK_Actor* theActor ) -{ - TColStd_IndexedMapOfInteger MapIndex; - MapIndex.Add(theCellIndex); - MapIndex.Add(theEdgeIndex); - theActor->MapEdge(theMapActor,MapIndex); + if( !( event->state() & KeyButtonMask ) ) + emit contextMenuRequested( event ); } diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index 55b07e806..bc0020ddf 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -21,8 +21,8 @@ // // // -// File : SVTK_RenderWindowInteractor.h -// Author : Nicolas REJNERI +// File : +// Author : // Module : SALOME // $Header$ @@ -30,242 +30,223 @@ #define SVTK_RenderWindowInteractor_h #include "SVTK.h" - #include "SVTK_Selection.h" -#include "SALOME_InteractiveObject.hxx" - -// QT Includes -#include -#include - -// VTK Includes -#include -#include - -// Open CASCADE Includes -#include -#include -#include - -class vtkPicker; -class vtkCellPicker; -class vtkPointPicker; -class vtkActorCollection; - -class SALOME_Actor; -class SVTK_Actor; - -class SVTK_ViewWindow; -class SVTK_RenderWindow; -class SVTK_InteractorStyle; - -// ------------------------------------------------------------ -// :TRICKY: Fri Apr 21 22:19:27 2000 Pagey -// The Signal/Slot mechanism used by Qt requires that QObject -// appear as the first class when using multiple inheritance. -// Hence the order of the two classes QObject and vtkRenderWindowInteractor -// matters here. Be careful not to change it by accident. -// ------------------------------------------------------------ -class SVTK_EXPORT SVTK_RenderWindowInteractor: public QObject, - public vtkRenderWindowInteractor + +#include +#include + +// undefining min and max because CASCADE's defines them and +// it clashes with std::min(), std::max() +#undef min +#undef max + +#include + +class vtkGenericRenderWindowInteractor; +class vtkInteractorStyle; +class vtkCallbackCommand; +class vtkRenderWindow; +class vtkRenderer; +class vtkObject; + +class SVTK_Selector; +class SVTK_Renderer; + +//============================================================================ +//! Implemements Qt based vtkRenderWindowInteractor. +/*! + The class inherits #QWidget class in order to be possible process Qt events. + It invokes corresponding VTK events through usage of its device - a #vtkGenericRenderWindowInteractor. + Also, it creates, initialize and holds vtkRenderWindow instance. +*/ +class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget { - Q_OBJECT ; - friend class SVTK_ViewWindow; -public: - - static SVTK_RenderWindowInteractor *New() ; - - vtkTypeMacro(SVTK_RenderWindowInteractor,vtkRenderWindowInteractor); - - // Description: - // Initializes the event handlers without an XtAppContext. This is - // good for when you don`t have a user interface, but you still - // want to have mouse interaction. - virtual void Initialize(); - - virtual void SetInteractorStyle(vtkInteractorObserver *); - SVTK_InteractorStyle* GetSInteractorStyle(){ return myInteractorStyle;} - - // Description: - // This will start up the X event loop and never return. If you - // call this method it will loop processing X events until the - // application is exited. - virtual void Start(); - - // Description: - // Event loop notification member for Window size change - virtual void UpdateSize(int x,int y); - - // Description: - // Timer methods must be overridden by platform dependent subclasses. - // flag is passed to indicate if this is first timer set or an update - // as Win32 uses repeating timers, whereas X uses One shot more timer - // if flag==VTKXI_TIMER_FIRST Win32 and X should createtimer - // otherwise Win32 should exit and X should perform AddTimeOut() - virtual int CreateTimer(int ) ; - virtual int DestroyTimer() ; - - /* Selection Management */ - bool highlightCell(const TColStd_IndexedMapOfInteger& MapIndex, - SALOME_Actor* theMapActor, - bool hilight, - bool update = true ); - bool highlightEdge(const TColStd_IndexedMapOfInteger& MapIndex, - SALOME_Actor* theMapActor, - bool hilight, - bool update = true ); - bool highlightPoint(const TColStd_IndexedMapOfInteger& MapIndex, - SALOME_Actor* theMapActor, - bool hilight, - bool update = true ); - bool highlight(const Handle(SALOME_InteractiveObject)& IObject, - bool hiligth, - bool immediatly = true ); - void unHighlightSubSelection(); - bool unHighlightAll(); - - bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject); - bool isVisible( const Handle(SALOME_InteractiveObject)& IObject); - void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName); - - void SetSelectionMode(Selection_Mode mode); - void SetSelectionProp(const double& theRed = 1, - const double& theGreen = 1, - const double& theBlue = 0, - const int& theWidth = 5); - void SetSelectionTolerance(const double& theTolNodes = 0.025, - const double& theTolCell = 0.001); - - // Displaymode management - int GetDisplayMode(); - void SetDisplayMode(int); - - // Switch representation wireframe/shading - void SetDisplayMode(const Handle(SALOME_InteractiveObject)& IObject, int theMode); - - // Change all actors to wireframe or surface - void ChangeRepresentationToWireframe(); - void ChangeRepresentationToSurface(); - - // Change to wireframe or surface a list of vtkactor - void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors); - void ChangeRepresentationToSurface(vtkActorCollection* ListofActors); - - // Erase Display functions - void EraseAll(); - void DisplayAll(); - void RemoveAll( const bool immediatly ); - void Erase(const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly=true); - void Remove(const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly=true); - void Display(const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly=true); - - void Display( SALOME_Actor* SActor, - bool immediatly = true ); - void Erase( SALOME_Actor* SActor, - bool immediatly = true ); - void Remove( SALOME_Actor* SActor, - bool updateViewer = true ); - - // Transparency - void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject, - float trans); - float GetTransparency(const Handle(SALOME_InteractiveObject)& IObject); - - // Color - void SetColor(const Handle(SALOME_InteractiveObject)& IObject, - QColor thecolor); - QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject); - - void Update(); - - vtkRenderer* GetRenderer(); - - void setGUIWindow(QWidget* theWindow); - - void setViewWindow(SVTK_ViewWindow* theViewWindow); - - void setCellData(const int& theIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor); - void setEdgeData(const int& theCellIndex, - SALOME_Actor* theMapActor, - const int& theEdgeIndex, - SVTK_Actor* theActor ); //NB - void setPointData(const int& theIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor); - - typedef void (*TUpdateActor)(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor); - protected: + Q_OBJECT; - SVTK_RenderWindowInteractor(); - ~SVTK_RenderWindowInteractor(); + public: + QVTK_RenderWindowInteractor(QWidget* theParent, + const char* theName); + + ~QVTK_RenderWindowInteractor(); + + //! To initialize by #vtkGenericRenderWindowInteractor instance + virtual + void + Initialize(vtkGenericRenderWindowInteractor* theDevice); - SVTK_InteractorStyle* myInteractorStyle; - - bool highlight(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor, - TUpdateActor theFun, - bool hilight, - bool update); - void setActorData(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor *theActor, - TUpdateActor theFun); - - // Timer used during various mouse events to figure - // out mouse movements. - QTimer *mTimer ; - - int myDisplayMode; - - //NRI: Selection mode - SVTK_Actor* myPointActor; - SVTK_Actor* myEdgeActor; - SVTK_Actor* myCellActor; - void MoveInternalActors(); - - vtkPicker* myBasicPicker; - vtkCellPicker* myCellPicker; - vtkPointPicker* myPointPicker; - - // User for switching to stereo mode. - int PositionBeforeStereo[2]; + vtkGenericRenderWindowInteractor* + GetDevice(); + + vtkRenderWindow* + getRenderWindow(); + + //! Just to simplify usage of its device (#vtkGenericRenderWindowInteractor) + virtual + void + InvokeEvent(unsigned long theEvent, void* theCallData); public slots: - void MouseMove(const QMouseEvent *event) ; - void LeftButtonPressed(const QMouseEvent *event) ; - void LeftButtonReleased(const QMouseEvent *event) ; - void MiddleButtonPressed(const QMouseEvent *event) ; - void MiddleButtonReleased(const QMouseEvent *event) ; - void RightButtonPressed(const QMouseEvent *event) ; - void RightButtonReleased(const QMouseEvent *event) ; - void ButtonPressed(const QMouseEvent *event) ; - void ButtonReleased(const QMouseEvent *event) ; - void KeyPressed(QKeyEvent *event) ; - - private slots: - // Not all of these slots are needed in VTK_MAJOR_VERSION=3, - // but moc does not understand "#if VTK_MAJOR_VERSION". Hence, - // we have to include all of these for the time being. Once, - // this bug in MOC is fixed, we can separate these. - void TimerFunc() ; + //! Need for initial contents display on Win32 + virtual void show(); + + //! To implement final initialization, just before the widget is displayed + virtual void polish(); + //! To adjust widget and vtkRenderWindow size + virtual void resize(int w, int h); + + protected: + virtual void paintEvent( QPaintEvent* ); + virtual void resizeEvent( QResizeEvent* ); + + virtual void mouseMoveEvent( QMouseEvent* ); + virtual void mousePressEvent( QMouseEvent* ); + virtual void mouseReleaseEvent( QMouseEvent* ); + virtual void mouseDoubleClickEvent( QMouseEvent* ); + virtual void wheelEvent( QWheelEvent* ); + virtual void keyPressEvent( QKeyEvent* ); + virtual void keyReleaseEvent( QKeyEvent* ); + virtual void enterEvent( QEvent * ); + virtual void leaveEvent( QEvent * ); + + virtual void contextMenuEvent( QContextMenuEvent * e ); + + // reimplemented from QWidget in order to set window - receiver + // of space mouse events. + virtual void focusInEvent( QFocusEvent* ); + virtual void focusOutEvent( QFocusEvent* ); + + //! To handle native X11 events (from such devices as SpaceMouse) + virtual bool x11Event( XEvent *e ); + + vtkSmartPointer myRenderWindow; + vtkSmartPointer myDevice; +}; + + +//============================================================================ +//! Extends QVTK_RenderWindowInteractor functionality. +/*! + Implements such features as + support of selection, + run-time interactor style management, + one render window per one renderer collaboration and + SUIT_ViewWindow events invocation. +*/ +class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteractor +{ + Q_OBJECT; + + public: + SVTK_RenderWindowInteractor(QWidget* theParent, + const char* theName); + + ~SVTK_RenderWindowInteractor(); + + //! To initialize properly the class + virtual + void + Initialize(vtkGenericRenderWindowInteractor* theDevice, + SVTK_Renderer* theRenderer, + SVTK_Selector* theSelector); + + //---------------------------------------------------------------------------- + //! To get corresponding SVTK_Renderer instance + SVTK_Renderer* + GetRenderer(); + + //! To get corresponding SVTK_Renderer device (just to simplify collobaration with SVTK_Renderer) + vtkRenderer* + getRenderer(); + + //---------------------------------------------------------------------------- + //! To get current interactor style + vtkInteractorStyle* + GetInteractorStyle(); + + //! To change current interactor style by pushing the new one into the container + void + PushInteractorStyle(vtkInteractorStyle* theStyle); + + //! To restore previous interactor style + void + PopInteractorStyle(); + + //---------------------------------------------------------------------------- + //! To get corresponding SVTK_Selector + SVTK_Selector* + GetSelector(); + + //! To get current selection mode (just to simplify collobaration with SVTK_Selector) + Selection_Mode + SelectionMode() const; + + //! To change selection mode (just to simplify collobaration with SVTK_Selector) + void + SetSelectionMode(Selection_Mode theMode); + + public: + //! To transform vtkCommand::EndPickEvent to Qt selectionChanged signal + void + onEmitSelectionChanged(); + + public: signals: - void RenderWindowModified() ; + void MouseMove( QMouseEvent* ); + void MouseButtonPressed( QMouseEvent* ); + void MouseButtonReleased( QMouseEvent* ); + void MouseDoubleClicked( QMouseEvent* ); + void ButtonPressed(const QMouseEvent *event); + void ButtonReleased(const QMouseEvent *event); + void WheelMoved( QWheelEvent* ); + void KeyPressed( QKeyEvent* ); + void KeyReleased( QKeyEvent* ); void contextMenuRequested( QContextMenuEvent *e ); - private: - SVTK_ViewWindow* myViewWindow; - QWidget* myGUIWindow; - double myTolNodes; - double myTolItems; + void selectionChanged(); + + protected: + virtual void mouseMoveEvent( QMouseEvent* ); + virtual void mousePressEvent( QMouseEvent* ); + virtual void mouseReleaseEvent( QMouseEvent* ); + virtual void mouseDoubleClickEvent( QMouseEvent* ); + virtual void wheelEvent( QWheelEvent* ); + virtual void keyPressEvent( QKeyEvent* ); + virtual void keyReleaseEvent( QKeyEvent* ); + virtual void contextMenuEvent( QContextMenuEvent * e ); + + void + SetRenderer(SVTK_Renderer *theRenderer); + + void + SetSelector(SVTK_Selector* theSelector); + + void + InitInteractorStyle(vtkInteractorStyle* theStyle); + + //---------------------------------------------------------------- + // Main process VTK event method + static + void + ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* theCallData); + + // Used to process VTK events + vtkSmartPointer myEventCallbackCommand; + + // Priority at which events are processed + float myPriority; + + //---------------------------------------------------------------- + vtkSmartPointer mySelector; + + vtkSmartPointer myRenderer; + + typedef vtkSmartPointer PInteractorStyle; + typedef std::stack TInteractorStyles; + TInteractorStyles myInteractorStyles; }; diff --git a/src/SVTK/SVTK_Renderer.cxx b/src/SVTK/SVTK_Renderer.cxx new file mode 100644 index 000000000..cad43a139 --- /dev/null +++ b/src/SVTK/SVTK_Renderer.cxx @@ -0,0 +1,655 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ + +#include "SVTK_Renderer.h" + +#include "SVTK_Trihedron.h" +#include "SVTK_CubeAxesActor2D.h" +#include "SVTK_RectPicker.h" + +#include "SALOME_Actor.h" +#include "VTKViewer_Actor.h" +#include "VTKViewer_Transform.h" +#include "VTKViewer_Utilities.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +// undefining min and max because CASCADE's defines them and +// it clashes with std::min(), std::max() included in utilities.h +#undef min +#undef max + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(SVTK_Renderer); + +//---------------------------------------------------------------------------- +SVTK_Renderer +::SVTK_Renderer(): + myDevice(vtkRenderer::New()), + myInteractor(NULL), + myPriority(0.0), + myEventCallbackCommand(vtkCallbackCommand::New()), + myPointPicker(vtkPointPicker::New()), + myCellPicker(vtkCellPicker::New()), + myPointRectPicker(SVTK_RectPicker::New()), + myCellRectPicker(SVTK_RectPicker::New()), + myPreHighlightProperty(vtkProperty::New()), + myHighlightProperty(vtkProperty::New()), + myTransform(VTKViewer_Transform::New()), + myCubeAxes(SVTK_CubeAxesActor2D::New()), + myTrihedron(SVTK_Trihedron::New()), + myTrihedronSize(105) +{ + myDevice->Delete(); + myTransform->Delete(); + + SetSelectionTolerance(); + + myPointPicker->Delete(); + myCellPicker->Delete(); + + myPointRectPicker->Delete(); + myPointRectPicker->PickFromListOn(); + + myCellRectPicker->Delete(); + myCellRectPicker->PickFromListOn(); + myCellRectPicker->PickPointsOff(); + + //SetPreselectionProp(); + myPreHighlightProperty->Delete(); + myPreHighlightProperty->SetColor(0,1,1); + myPreHighlightProperty->SetPointSize(SALOME_POINT_SIZE+2); + myPreHighlightProperty->SetLineWidth(SALOME_LINE_WIDTH+2); + myPreHighlightProperty->SetRepresentationToPoints(); + + //SetSelectionProp(); + myHighlightProperty->Delete(); + myHighlightProperty->SetColor(1,1,0); + myHighlightProperty->SetPointSize(SALOME_POINT_SIZE+2); + myHighlightProperty->SetLineWidth(SALOME_LINE_WIDTH+2); + myHighlightProperty->SetRepresentationToPoints(); + + myTrihedron->Delete(); + myCubeAxes->Delete(); + myEventCallbackCommand->Delete(); + + myTrihedron->AddToRender(GetDevice()); + GetDevice()->AddProp(GetCubeAxes()); + + myBndBox[0] = myBndBox[2] = myBndBox[4] = 0; + myBndBox[1] = myBndBox[3] = myBndBox[5] = myTrihedron->GetSize(); + + myCubeAxes->SetBounds(myBndBox); + myCubeAxes->SetCamera(GetDevice()->GetActiveCamera()); + + myCubeAxes->SetLabelFormat("%6.4g"); + myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee + myCubeAxes->SetFontFactor(0.8); + myCubeAxes->SetCornerOffset(0); + myCubeAxes->SetScaling(0); + myCubeAxes->SetNumberOfLabels(5); + myCubeAxes->VisibilityOff(); + myCubeAxes->SetTransform(GetTransform()); + + vtkTextProperty* aTextProp = vtkTextProperty::New(); + aTextProp->SetColor(1, 1, 1); + aTextProp->ShadowOn(); + myCubeAxes->SetAxisTitleTextProperty(aTextProp); + myCubeAxes->SetAxisLabelTextProperty(aTextProp); + aTextProp->Delete(); + + GetDevice()->GetActiveCamera()->ParallelProjectionOn(); + GetDevice()->LightFollowCameraOn(); + GetDevice()->TwoSidedLightingOn(); + + myEventCallbackCommand->SetClientData(this); + myEventCallbackCommand->SetCallback(SVTK_Renderer::ProcessEvents); + GetDevice()->AddObserver(vtkCommand::ConfigureEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + GetDevice()->AddObserver(vtkCommand::ResetCameraEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + GetDevice()->AddObserver(vtkCommand::ResetCameraClippingRangeEvent, + myEventCallbackCommand.GetPointer(), + myPriority); +} + +SVTK_Renderer +::~SVTK_Renderer() +{ + vtkActorCollection* anActors = GetDevice()->GetActors(); + vtkActorCollection* anActors2 = vtkActorCollection::New(); + + anActors->InitTraversal(); + while(vtkActor* anAct = anActors->GetNextActor()){ + if(SALOME_Actor* anActor = dynamic_cast(anAct)){ + anActors2->AddItem(anActor); + } + } + + anActors2->InitTraversal(); + while(vtkActor* anAct = anActors2->GetNextActor()){ + if(SALOME_Actor* anActor = dynamic_cast(anAct)){ + RemoveActor(anActor); + } + } + + anActors2->Delete(); +} + + +void +SVTK_Renderer +::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + SVTK_Renderer* self = reinterpret_cast(theClientData); + + switch(theEvent){ + case vtkCommand::ConfigureEvent: + self->OnResetView(); + break; + case vtkCommand::ResetCameraEvent: + self->OnFitAll(); + break; + case vtkCommand::ResetCameraClippingRangeEvent: + self->OnResetClippingRange(); + break; + } +} + +//---------------------------------------------------------------------------- +vtkRenderer* +SVTK_Renderer +::GetDevice() +{ + return myDevice.GetPointer(); +} + +void +SVTK_Renderer +::Initialize(vtkRenderWindowInteractor* theInteractor, + SVTK_Selector* theSelector) +{ + myInteractor = theInteractor; + mySelector = theSelector; +} + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::AddActor(VTKViewer_Actor* theActor) +{ + if(SALOME_Actor* anActor = dynamic_cast(theActor)){ + anActor->SetInteractor(myInteractor); + anActor->SetTransform(GetTransform()); + anActor->SetSelector(mySelector.GetPointer()); + + anActor->SetPointPicker(myPointPicker.GetPointer()); + anActor->SetCellPicker(myCellPicker.GetPointer()); + + anActor->SetPointRectPicker(myPointRectPicker.GetPointer()); + anActor->SetCellRectPicker(myCellRectPicker.GetPointer()); + + anActor->SetPreHighlightProperty(myPreHighlightProperty.GetPointer()); + anActor->SetHighlightProperty(myHighlightProperty.GetPointer()); + + anActor->AddToRender(GetDevice()); + AdjustActors(); + } +} + +void +SVTK_Renderer +::RemoveActor(VTKViewer_Actor* theActor) +{ + if(SALOME_Actor* anActor = dynamic_cast(theActor)){ + // Order of the calls are important because VTKViewer_Actor::RemoveFromRender + // can leads do destruction of the actor + anActor->SetInteractor(NULL); + anActor->SetTransform(NULL); + anActor->SetSelector(NULL); + + anActor->SetPointPicker(NULL); + anActor->SetCellPicker(NULL); + + anActor->SetPointRectPicker(NULL); + anActor->SetCellRectPicker(NULL); + + anActor->SetPreHighlightProperty(NULL); + anActor->SetHighlightProperty(NULL); + + anActor->RemoveFromRender(GetDevice()); + AdjustActors(); + } +} + +VTKViewer_Transform* +SVTK_Renderer +::GetTransform() +{ + return myTransform.GetPointer(); +} + +void +SVTK_Renderer +::GetScale( double theScale[3] ) +{ + myTransform->GetMatrixScale( theScale ); +} + +void +SVTK_Renderer +::SetScale( double theScale[3] ) +{ + myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] ); + AdjustActors(); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::SetSelectionProp(const double& theRed, + const double& theGreen, + const double& theBlue, + const int& theWidth) +{ + myHighlightProperty->SetColor( theRed, theGreen, theBlue ); + myHighlightProperty->SetLineWidth( theWidth ); + myHighlightProperty->SetPointSize( theWidth ); +} + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::SetPreselectionProp(const double& theRed, + const double& theGreen, + const double& theBlue, + const int& theWidth) +{ + myPreHighlightProperty->SetColor( theRed, theGreen, theBlue ); + myPreHighlightProperty->SetLineWidth( theWidth ); + myPreHighlightProperty->SetPointSize( theWidth ); +} + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::SetSelectionTolerance(const double& theTolNodes, + const double& theTolCell) +{ + myPointPicker->SetTolerance( theTolNodes ); + myCellPicker->SetTolerance( theTolCell ); + + myPointRectPicker->SetTolerance( theTolNodes ); + myCellRectPicker->SetTolerance( theTolCell ); +} + + +//---------------------------------------------------------------------------- +/*! If parameter theIsForcedUpdate is true, recalculate parameters for + * trihedron and cube axes, even if trihedron and cube axes is invisible. + */ + +inline +bool +CheckBndBox(const float theBounds[6]) +{ + if(theBounds[0] > -VTK_LARGE_FLOAT && theBounds[1] < VTK_LARGE_FLOAT && + theBounds[2] > -VTK_LARGE_FLOAT && theBounds[3] < VTK_LARGE_FLOAT && + theBounds[4] > -VTK_LARGE_FLOAT && theBounds[5] < VTK_LARGE_FLOAT) + return true; + return false; +} + +bool +SVTK_Renderer +::OnAdjustActors() +{ + bool aTDisplayed = IsTrihedronDisplayed(); + bool aCDisplayed = IsCubeAxesDisplayed(); + + float aNewBndBox[6]; + aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_LARGE_FLOAT; + aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_LARGE_FLOAT; + + int aVisibleNum = myTrihedron->GetVisibleActorCount(GetDevice()); + if(aVisibleNum){ + if(aTDisplayed) + myTrihedron->VisibilityOff(); + + if(aCDisplayed) + myCubeAxes->VisibilityOff(); + + // if the new trihedron size have sufficient difference, then apply the value + double aSize = myTrihedron->GetSize(); + ComputeTrihedronSize(GetDevice(),aSize,aSize,myTrihedronSize); + myTrihedron->SetSize(aSize); + + // iterate through displayed objects and set size if necessary + vtkActorCollection* anActors = GetDevice()->GetActors(); + anActors->InitTraversal(); + while(vtkActor* anAct = anActors->GetNextActor()){ + if(SALOME_Actor* anActor = dynamic_cast(anAct)){ + if(anActor->IsResizable()) + anActor->SetSize(0.5*aSize); + if(anActor->GetVisibility() && !anActor->IsInfinitive()){ + float *aBounds = anActor->GetBounds(); + if(CheckBndBox(aBounds)) + for(int i = 0; i < 5; i = i + 2){ + if(aBounds[i] < aNewBndBox[i]) + aNewBndBox[i] = aBounds[i]; + if(aBounds[i+1] > aNewBndBox[i+1]) + aNewBndBox[i+1] = aBounds[i+1]; + } + } + } + } + + if(aTDisplayed) + myTrihedron->VisibilityOn(); + + if(aCDisplayed) + myCubeAxes->VisibilityOn(); + + }else{ + double aSize = myTrihedron->GetSize(); + aNewBndBox[0] = aNewBndBox[2] = aNewBndBox[4] = 0; + aNewBndBox[1] = aNewBndBox[3] = aNewBndBox[5] = aSize; + } + + if(CheckBndBox(aNewBndBox)){ + for(int i = 0; i < 6; i++) + myBndBox[i] = aNewBndBox[i]; + myCubeAxes->SetBounds(myBndBox); + return true; + } + + return false; +} + +void +SVTK_Renderer +::AdjustActors() +{ + if(OnAdjustActors()) + ::ResetCameraClippingRange(GetDevice()); +} + +void +SVTK_Renderer +::SetTrihedronSize(int theSize) +{ + if(myTrihedronSize != theSize){ + myTrihedronSize = theSize; + AdjustActors(); + } +} + +int +SVTK_Renderer +::GetTrihedronSize() const +{ + return myTrihedronSize; +} + + +//---------------------------------------------------------------------------- +VTKViewer_Trihedron* +SVTK_Renderer +::GetTrihedron() +{ + return myTrihedron.GetPointer(); +} + +bool +SVTK_Renderer +::IsTrihedronDisplayed() +{ + return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn; +} + +void +SVTK_Renderer +::OnViewTrihedron() +{ + if(IsTrihedronDisplayed()) + myTrihedron->VisibilityOff(); + else + myTrihedron->VisibilityOn(); +} + +void +SVTK_Renderer +::OnAdjustTrihedron() +{ + AdjustActors(); +} + + +//---------------------------------------------------------------------------- +SVTK_CubeAxesActor2D* +SVTK_Renderer +::GetCubeAxes() +{ + return myCubeAxes.GetPointer(); +} + +bool +SVTK_Renderer +::IsCubeAxesDisplayed() +{ + return myCubeAxes->GetVisibility() == 1; +} + +void +SVTK_Renderer +::OnViewCubeAxes() +{ + if(IsCubeAxesDisplayed()) + myCubeAxes->VisibilityOff(); + else + myCubeAxes->VisibilityOn(); +} + +void +SVTK_Renderer +::OnAdjustCubeAxes() +{ + AdjustActors(); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::OnResetView() +{ + int aTrihedronIsVisible = IsTrihedronDisplayed(); + int aCubeAxesIsVisible = IsCubeAxesDisplayed(); + + myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn ); + myCubeAxes->SetVisibility(0); + + ::ResetCamera(GetDevice(),true); + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); + aCamera->SetPosition(1,-1,1); + aCamera->SetViewUp(0,0,1); + ::ResetCamera(GetDevice(),true); + + if(aTrihedronIsVisible) + myTrihedron->VisibilityOn(); + else + myTrihedron->VisibilityOff(); + + if(aCubeAxesIsVisible) + myCubeAxes->VisibilityOn(); + else + myCubeAxes->VisibilityOff(); + + static float aCoeff = 3.0; + aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale()); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::OnFitAll() +{ + int aTrihedronWasVisible = false; + int aCubeAxesWasVisible = false; + + aTrihedronWasVisible = IsTrihedronDisplayed(); + if(aTrihedronWasVisible) + myTrihedron->VisibilityOff(); + + aCubeAxesWasVisible = IsCubeAxesDisplayed(); + if(aCubeAxesWasVisible) + myCubeAxes->VisibilityOff(); + + if(myTrihedron->GetVisibleActorCount(GetDevice())){ + myTrihedron->VisibilityOff(); + myCubeAxes->VisibilityOff(); + ::ResetCamera(GetDevice()); + }else{ + myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn); + myCubeAxes->SetVisibility(2); + ::ResetCamera(GetDevice(),true); + } + + if(aTrihedronWasVisible) + myTrihedron->VisibilityOn(); + else + myTrihedron->VisibilityOff(); + + if(aCubeAxesWasVisible) + myCubeAxes->VisibilityOn(); + else + myCubeAxes->VisibilityOff(); + + ::ResetCameraClippingRange(GetDevice()); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::OnResetClippingRange() +{ + return; + ::ResetCameraClippingRange(GetDevice()); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::OnFrontView() +{ + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); + aCamera->SetPosition(1,0,0); + aCamera->SetViewUp(0,0,1); + aCamera->SetFocalPoint(0,0,0); + this->OnFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::OnBackView() +{ + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); + aCamera->SetPosition(-1,0,0); + aCamera->SetViewUp(0,0,1); + aCamera->SetFocalPoint(0,0,0); + this->OnFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::OnTopView() +{ + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); + aCamera->SetPosition(0,0,1); + aCamera->SetViewUp(0,1,0); + aCamera->SetFocalPoint(0,0,0); + this->OnFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::OnBottomView() +{ + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); + aCamera->SetPosition(0,0,-1); + aCamera->SetViewUp(0,1,0); + aCamera->SetFocalPoint(0,0,0); + this->OnFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::OnLeftView() +{ + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); + aCamera->SetPosition(0,-1,0); + aCamera->SetViewUp(0,0,1); + aCamera->SetFocalPoint(0,0,0); + this->OnFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::OnRightView() +{ + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); + aCamera->SetPosition(0,1,0); + aCamera->SetViewUp(0,0,1); + aCamera->SetFocalPoint(0,0,0); + this->OnFitAll(); +} diff --git a/src/SVTK/SVTK_Renderer.h b/src/SVTK/SVTK_Renderer.h new file mode 100644 index 000000000..5f486543c --- /dev/null +++ b/src/SVTK/SVTK_Renderer.h @@ -0,0 +1,245 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#ifndef SVTK_Renderer_h +#define SVTK_Renderer_h + +#include "SVTK.h" + +#include +#include + +class vtkRenderer; +class vtkCallbackCommand; +class vtkRenderWindowInteractor; + +class vtkPicker; +class vtkPointPicker; +class vtkCellPicker; +class vtkProperty; + +class SVTK_RectPicker; + +class VTKViewer_Trihedron; +class VTKViewer_Transform; +class SVTK_CubeAxesActor2D; +class VTKViewer_Actor; +class SVTK_Selector; + + +//! The class is a container for #vtkRenderer instance. +/*! + Main goal of the class is to apply common behaviour to all #SALOME_Actor, like + selection and preselection colors. + Also, the class is responsible for management of internal actors like trihedron an so on. + */ +//============================================================================ +class SVTK_EXPORT SVTK_Renderer : public vtkObject +{ + public: + vtkTypeMacro(SVTK_Renderer,vtkObject); + static SVTK_Renderer* New(); + + //---------------------------------------------------------------------------- + //! Get its device + vtkRenderer* + GetDevice(); + + //! Initialize the class + virtual + void + Initialize(vtkRenderWindowInteractor* theInteractor, + SVTK_Selector* theSelector); + + //---------------------------------------------------------------------------- + //! This method publishes pointed actor into the renderer + virtual + void + AddActor(VTKViewer_Actor* theActor); + + //! This method removes pointed actor from the renderer + virtual + void + RemoveActor(VTKViewer_Actor* theActor); + + //! Get special container that keeps scaling of the scene + VTKViewer_Transform* + GetTransform(); + + //! This method allow to apply a scale on the whole scene + virtual + void + SetScale( double theScale[3] ); + + //! This method allow to get a scale that is applied on the whole scene + void + GetScale( double theScale[3] ); + + //---------------------------------------------------------------------------- + //! Applies color and size (PointSize and LineWidth) of primitives in selection mode + void + SetSelectionProp(const double& theRed = 1, + const double& theGreen = 1, + const double& theBlue = 0, + const int& theWidth = 5); + + //! Applies color and size (PointSize and LineWidth) of primitives in preselection mode + void + SetPreselectionProp(const double& theRed = 0, + const double& theGreen = 1, + const double& theBlue = 1, + const int& theWidth = 5); + + //! Setup requested tollerance for the picking + void + SetSelectionTolerance(const double& theTolNodes = 0.025, + const double& theTolCell = 0.001); + + //---------------------------------------------------------------------------- + //! Adjust all intenal actors (trihedron and graduated rules) to the scene + void + AdjustActors(); + + //! Set size of the trihedron in percents from bounding box of the scene + void + SetTrihedronSize(int theSize); + + //! Get size of the trihedron in percents from bounding box of the scene + int + GetTrihedronSize() const; + + //---------------------------------------------------------------------------- + //! Get trihedron control + VTKViewer_Trihedron* + GetTrihedron(); + + //! Is trihedron displayed + bool + IsTrihedronDisplayed(); + + //! Toggle trihedron visibility + void + OnViewTrihedron(); + + //! Adjust size of the trihedron to the bounding box of the scene + void + OnAdjustTrihedron(); + + //---------------------------------------------------------------------------- + //! Get graduated rules control + SVTK_CubeAxesActor2D* + GetCubeAxes(); + + //! Is graduated rules displayed + bool + IsCubeAxesDisplayed(); + + //! Toggle graduated rules visibility + void + OnViewCubeAxes(); + + //! Adjust size of the graduated rules to the bounding box of the scene + void + OnAdjustCubeAxes(); + + //---------------------------------------------------------------------------- + //! Fit all presentation in the scene into the window + void OnFitAll(); + + //! Set camera into predefined state + void OnResetView(); + + //! Reset camera clipping range to adjust the range to the bounding box of the scene + void OnResetClippingRange(); + + //! To reset direction of the camera to front view + void OnFrontView(); + + //! To reset direction of the camera to back view + void OnBackView(); + + //! To reset direction of the camera to top view + void OnTopView(); + + //! To reset direction of the camera to bottom view + void OnBottomView(); + + //! To reset direction of the camera to right view + void OnRightView(); + + //! To reset direction of the camera to left view + void OnLeftView(); + + protected: + SVTK_Renderer(); + ~SVTK_Renderer(); + + virtual + bool + OnAdjustActors(); + + //---------------------------------------------------------------------------- + // Priority at which events are processed + float myPriority; + + // Used to process events + vtkSmartPointer myEventCallbackCommand; + + // Description: + // Main process event method + static void ProcessEvents(vtkObject* object, + unsigned long event, + void* clientdata, + void* calldata); + + vtkSmartPointer myDevice; + vtkRenderWindowInteractor* myInteractor; + vtkSmartPointer mySelector; + + //---------------------------------------------------------------------------- + vtkSmartPointer myTransform; + + //---------------------------------------------------------------------------- + // Highlight/ Prehighlight devices + vtkSmartPointer myPointPicker; + vtkSmartPointer myCellPicker; + + vtkSmartPointer myPointRectPicker; + vtkSmartPointer myCellRectPicker; + + vtkSmartPointer myPreHighlightProperty; + vtkSmartPointer myHighlightProperty; + + //---------------------------------------------------------------------------- + vtkSmartPointer myCubeAxes; + vtkSmartPointer myTrihedron; + int myTrihedronSize; + float myBndBox[6]; +}; + +#endif diff --git a/src/SVTK/SVTK_Selection.h b/src/SVTK/SVTK_Selection.h index ef5e662c6..3307565c2 100644 --- a/src/SVTK/SVTK_Selection.h +++ b/src/SVTK/SVTK_Selection.h @@ -30,16 +30,16 @@ #define SVTK_SELECTION_H -enum Selection_Mode -{ - NodeSelection, - CellSelection, - EdgeOfCellSelection, - EdgeSelection, - FaceSelection, - VolumeSelection, - ActorSelection -}; +//! It is possible to introduce new type of selection +typedef int Selection_Mode; + +const Selection_Mode NodeSelection = 0; +const Selection_Mode CellSelection = 1; +const Selection_Mode EdgeOfCellSelection = 2; +const Selection_Mode EdgeSelection = 3; +const Selection_Mode FaceSelection = 4; +const Selection_Mode VolumeSelection = 5; +const Selection_Mode ActorSelection = 6; #endif diff --git a/src/SVTK/SVTK_SelectionEvent.h b/src/SVTK/SVTK_SelectionEvent.h new file mode 100644 index 000000000..cfa753f97 --- /dev/null +++ b/src/SVTK/SVTK_SelectionEvent.h @@ -0,0 +1,55 @@ +// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_SelectionEvent.h +// Author : +// Module : SALOME +// $Header$ + +#ifndef SVTK_SELECTIONEVENT_H +#define SVTK_SELECTIONEVENT_H + +#include "SVTK_Selection.h" + +//! The structure is used for passing all infromation necessary for claculation of the selection. +/*! + The SVTK_SelectionEvent is generated by #SVTK_InteractorStyle. + In its turn the #SVTK_InteractorStyle uses for it generation #vtkRenderWindowInteractor and + #SVTK_Selector instances. + */ +struct SVTK_SelectionEvent +{ + //! Through usage of the parameter any new type of selection can be introduced + Selection_Mode mySelectionMode; + int myX; //!< Current X position of the mouse + int myY; //!< Current Y position of the mouse + 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 myIsCtrl; //!< Is Ctrl key are pressed + bool myIsShift; //!< Is Shift key are pressed + int myKeyCode; //!< Code of the pressed key + int myRepeatCount; //!< Number of repetion of the key pressing +}; + +#endif diff --git a/src/SVTK/SVTK_Selector.cxx b/src/SVTK/SVTK_Selector.cxx index 471c3b8ec..bc6dad148 100644 --- a/src/SVTK/SVTK_Selector.cxx +++ b/src/SVTK/SVTK_Selector.cxx @@ -27,19 +27,27 @@ // $Header$ +#include "SVTK_SelectorDef.h" + +#include "SALOME_Actor.h" + #include #include +#include -#include "SALOME_Actor.h" -#include "SVTK_ViewModel.h" -#include "SVTK_ViewWindow.h" - -#include "SVTK_SelectorDef.h" +SVTK_Selector* +SVTK_Selector +::New() +{ + return new SVTK_SelectorDef(); +} +//---------------------------------------------------------------------------- SVTK_SelectorDef ::SVTK_SelectorDef() { + mySelectionMode = ActorSelection; } SVTK_SelectorDef @@ -47,11 +55,32 @@ SVTK_SelectorDef { } +//---------------------------------------------------------------------------- +void +SVTK_SelectorDef +::StartPickCallback() +{ + this->InvokeEvent(vtkCommand::StartPickEvent,NULL); +} + +//---------------------------------------------------------------------------- +void +SVTK_SelectorDef +::EndPickCallback() +{ + this->InvokeEvent(vtkCommand::EndPickEvent,NULL); +} + +//---------------------------------------------------------------------------- void SVTK_SelectorDef ::SetSelectionMode(Selection_Mode theMode) { - mySelectionMode = theMode; + if(mySelectionMode != theMode){ + mySelectionMode = theMode; + myMapIOSubIndex.clear(); + this->EndPickCallback(); + } } void @@ -68,7 +97,7 @@ bool SVTK_SelectorDef ::IsSelected(const Handle(SALOME_InteractiveObject)& theIO) const { - return myIObjects.find(theIO) != myIObjects.end(); + return !theIO.IsNull() && (myIObjects.find(theIO) != myIObjects.end()); } bool @@ -333,3 +362,59 @@ SVTK_SelectorDef { myMapIOSubIndex.clear(); } + +//---------------------------------------------------------------------------- +void +SVTK_SelectorDef +::SetFilter(const Handle(VTKViewer_Filter)& theFilter) +{ + myFilters.insert(TFilters::value_type(theFilter->GetId(),theFilter)); +} + +//---------------------------------------------------------------------------- +bool +SVTK_SelectorDef +::IsFilterPresent(const TFilterID theId) const +{ + return myFilters.find(theId) != myFilters.end(); +} + +//---------------------------------------------------------------------------- +void +SVTK_SelectorDef +::RemoveFilter(const TFilterID theId) +{ + if(IsFilterPresent(theId)) + myFilters.erase(theId); +} + +//---------------------------------------------------------------------------- +bool +SVTK_SelectorDef +::IsValid(SALOME_Actor* theActor, + const TFilterID theId, + const bool theIsNode) const +{ + TFilters::const_iterator anIter = myFilters.begin(); + for(; anIter != myFilters.end(); ++anIter){ + const Handle(VTKViewer_Filter)& aFilter = anIter->second; + if(theIsNode == aFilter->IsNodeFilter() && + !aFilter->IsValid(theActor,theId)) + return false; + } + return true; +} + +//---------------------------------------------------------------------------- +Handle(VTKViewer_Filter) +SVTK_SelectorDef +::GetFilter(const TFilterID theId) const +{ + TFilters::const_iterator anIter = myFilters.find(theId); + if(anIter != myFilters.end()){ + const Handle(VTKViewer_Filter)& aFilter = anIter->second; + return aFilter; + } + return Handle(VTKViewer_Filter)(); +} + diff --git a/src/SVTK/SVTK_Selector.h b/src/SVTK/SVTK_Selector.h index 26150b4f4..37ec0acb1 100644 --- a/src/SVTK/SVTK_Selector.h +++ b/src/SVTK/SVTK_Selector.h @@ -29,102 +29,181 @@ #ifndef SVTK_SELECTOR_H #define SVTK_SELECTOR_H +#include "SVTK_Selection.h" +#include "SALOME_ListIO.hxx" +#include "VTKViewer_Filter.h" +#include "SALOME_InteractiveObject.hxx" + #include #include -#include "SVTK_Selection.h" -#include "SALOME_ListIO.hxx" +#include class SALOME_Actor; -class SVTK_Selector +//! Define an abstract interface for selection in SVTK package +/*! + The class implements selection functionality through storing corresponding + references to #SALOME_InteractiveObject. For implementation of subselection + modes it keeps a corresponding map of sub indexes. + \note + Also, for each #SALOME_InteractiveObject it tries to keep corresponding refenrence to #SALOME_Actor + */ +class SVTK_Selector: public vtkObject { public: - virtual ~SVTK_Selector() {}; + static SVTK_Selector* New(); + + vtkTypeMacro(SVTK_Selector,vtkObject); + //! To change current Selection_Mode (as outside effect, it invokes selectionChange signal) virtual void - SetSelectionMode( Selection_Mode theMode ) = 0; + SetSelectionMode(Selection_Mode theMode) = 0; + //! Get current Selection_Mode virtual Selection_Mode SelectionMode() const = 0; + //! Clear selection virtual void ClearIObjects() = 0; + //! Try to find corresponding #SALOME_Actor for given reference on #SALOME_InteractiveObject virtual SALOME_Actor* GetActor(const Handle(SALOME_InteractiveObject)& theIO) const = 0; + //! Check, is the #SALOME_InteractiveObject is present into selection virtual bool IsSelected(const Handle(SALOME_InteractiveObject)& theIO) const = 0; + //! Check, is the #SALOME_Actor is present into selection virtual bool IsSelected(SALOME_Actor* theActor) const = 0; + //! Modify the selection by adding new reference on #SALOME_InteractiveObject virtual bool AddIObject(const Handle(SALOME_InteractiveObject)& theIO) = 0; + //! Modify the selection by adding new reference on #SALOME_Actor virtual bool AddIObject(SALOME_Actor* theActor) = 0; + //! Modify the selection by removing a reference on #SALOME_InteractiveObject virtual bool RemoveIObject(const Handle(SALOME_InteractiveObject)& theIO) = 0; + //! Modify the selection by removing a reference on #SALOME_Actor virtual bool RemoveIObject(SALOME_Actor* theActor) = 0; + //! Get all #SALOME_InteractiveObject references that is present into selection virtual const SALOME_ListIO& StoredIObjects() const = 0; + //! Get number of selected objects virtual int IObjectCount() const = 0; + //! Check, if the #SALOME_InteractiveObject has a subselection virtual bool HasIndex(const Handle(SALOME_InteractiveObject)& theIO ) const = 0; + //! Get indexes of subslection for given #SALOME_InteractiveObject virtual void GetIndex( const Handle(SALOME_InteractiveObject)& theIO, TColStd_IndexedMapOfInteger& theIndex ) = 0; + //! Change indexes of subslection for given #SALOME_InteractiveObject virtual bool AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, const TColStd_IndexedMapOfInteger& theIndices, bool theIsModeShift) = 0; + + //! Change indexes of subslection for given #SALOME_InteractiveObject virtual bool AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, const TColStd_MapOfInteger& theIndices, bool theIsModeShift) = 0; + + //! Change index of subslection for given #SALOME_InteractiveObject virtual bool AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, int theIndex, bool theIsModeShift) = 0; + + //! Change index of subslection for given #SALOME_InteractiveObject virtual void RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, int theIndex) = 0; + + //! Check, if the given index is present in subslection virtual bool IsIndexSelected(const Handle(SALOME_InteractiveObject)& theIO, int theIndex) const = 0; + + //! Clear subselection virtual void ClearIndex() = 0; + + //---------------------------------------------------------------------------- + typedef int TFilterID; + + //! To apply a filter on the selection + virtual + void + SetFilter(const Handle(VTKViewer_Filter)& theFilter) = 0; + + //! To get a section filter by its number + virtual + Handle(VTKViewer_Filter) + GetFilter(const TFilterID theId) const = 0; + + //! Check, if a filter with given number is applyed + virtual + bool + IsFilterPresent(const TFilterID theId) const = 0; + + //! To remove a filter from the selection + virtual + void + RemoveFilter(const TFilterID theId) = 0; + + //! Check, if the index satisfy to the installed filters + virtual + bool + IsValid(SALOME_Actor* theActor, + const int theId, + const bool theIsNode = false) const = 0; + + //---------------------------------------------------------------------------- + virtual + void + StartPickCallback() = 0; + + //! To invoke selectionChanged signals + virtual + void + EndPickCallback() = 0; }; diff --git a/src/SVTK/SVTK_SelectorDef.h b/src/SVTK/SVTK_SelectorDef.h index 47f593e9a..050a6838a 100644 --- a/src/SVTK/SVTK_SelectorDef.h +++ b/src/SVTK/SVTK_SelectorDef.h @@ -51,7 +51,7 @@ public: virtual void - SetSelectionMode( Selection_Mode theMode ); + SetSelectionMode(Selection_Mode theMode); virtual Selection_Mode @@ -133,8 +133,40 @@ public: void ClearIndex(); + //---------------------------------------------------------------------------- + virtual + void + SetFilter(const Handle(VTKViewer_Filter)& theFilter); + + virtual + Handle(VTKViewer_Filter) + GetFilter(const TFilterID theId) const; + + virtual + bool + IsFilterPresent(const TFilterID theId) const; + + virtual + void + RemoveFilter(const int theId); + + virtual + bool + IsValid(SALOME_Actor* theActor, + const TFilterID theId, + const bool theIsNode = false) const; + + //---------------------------------------------------------------------------- + virtual + void + StartPickCallback(); + + virtual + void + EndPickCallback(); + private: - Selection_Mode mySelectionMode; + int mySelectionMode; struct TIOLessThan { @@ -146,7 +178,8 @@ private: } }; - struct TIndexedMapOfInteger{ + struct TIndexedMapOfInteger + { TColStd_IndexedMapOfInteger myMap; TIndexedMapOfInteger() {} @@ -170,7 +203,9 @@ private: TIndexedMapOfInteger, TIOLessThan> TMapIOSubIndex; TMapIOSubIndex myMapIOSubIndex; -}; + typedef std::map TFilters; + TFilters myFilters; +}; #endif diff --git a/src/SVTK/SVTK_SpaceMouse.cxx b/src/SVTK/SVTK_SpaceMouse.cxx new file mode 100644 index 000000000..620e97ec0 --- /dev/null +++ b/src/SVTK/SVTK_SpaceMouse.cxx @@ -0,0 +1,196 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_SpaceMouse.cxx +// Author : Alexander SLADKOV +// Module : SALOME +// $Header$ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "SVTK_SpaceMouse.h" + +//--------------------------------------------- +SVTK_SpaceMouse* SVTK_SpaceMouse::myInstance = 0; + +//--------------------------------------------- +SVTK_SpaceMouse* SVTK_SpaceMouse::getInstance() +{ + if ( !myInstance ) + myInstance = new SVTK_SpaceMouse(); + return myInstance; +} + +//--------------------------------------------- +SVTK_SpaceMouse::SVTK_SpaceMouse() +{ + win = InputFocus; + spaceMouseOn = 0; +} + +//--------------------------------------------- +int SVTK_SpaceMouse::initialize( Display *display, Window window ) +{ + XMotionEvent = XInternAtom( display, "MotionEvent", 1 ); + XButtonPressEvent = XInternAtom( display, "ButtonPressEvent", 1 ); + XButtonReleaseEvent = XInternAtom( display, "ButtonReleaseEvent", 1 ); + XCommandEvent = XInternAtom( display, "CommandEvent", 1 ); + + spaceMouseOn = (XMotionEvent != 0) && + (XButtonPressEvent != 0) && + (XButtonReleaseEvent != 0) && + (XCommandEvent != 0); + if ( !spaceMouseOn ) + return 0; + + spaceMouseOn = setWindow( display, window ); + if ( !spaceMouseOn ) + return 0; + + return spaceMouseOn; +} + +//--------------------------------------------- +static int errorCallback( Display *display, XErrorEvent *Error ) +{ + char msg[ 128 ]; + if ( Error->error_code != BadWindow ) { + XGetErrorText( display,Error->error_code,msg,sizeof( msg ) ); + fprintf( stderr, "SpaceMouse reported error = %s. Exit ... \n", msg ); + } + return 0; +} + +//--------------------------------------------- +int SVTK_SpaceMouse::setWindow( Display *display, Window window ) +{ + XTextProperty winName; + XEvent xEvent; + Atom type; + int format; + unsigned long NItems, BytesReturn; + unsigned char *PropReturn; + Window root; + int result; + int (*errorHandler)(Display *,XErrorEvent *); + + result = 1; + errorHandler = XSetErrorHandler( errorCallback ); + + root = RootWindow( display, DefaultScreen(display) ); + + PropReturn = NULL; + XGetWindowProperty( display, root, XCommandEvent, 0,1, 0, + AnyPropertyType, &type, &format, &NItems, + &BytesReturn, &PropReturn ); + + win = InputFocus; + if ( PropReturn != NULL ) { + win = *(Window *) PropReturn; + XFree( PropReturn ); + } + else + return result = 0; + + if ( XGetWMName( display, win, &winName ) == 0 ) + return result = 0; + + if ( strcmp( (char *) "Magellan Window", (char *) winName.value) != 0 ) + return result = 0; + + xEvent.type = ClientMessage; + xEvent.xclient.format = 16; + xEvent.xclient.send_event = 0; + xEvent.xclient.display = display; + xEvent.xclient.window = win; + xEvent.xclient.message_type = XCommandEvent; + + xEvent.xclient.data.s[0] = (short) ((window>>16)&0x0000FFFF); + xEvent.xclient.data.s[1] = (short) (window&0x0000FFFF); + xEvent.xclient.data.s[2] = 27695; + + if ( XSendEvent( display, win, 0, 0x0000, &xEvent ) == 0 ) + return result = 0; + + XFlush( display ); + + XSetErrorHandler( errorHandler ); + return result; +} + +//--------------------------------------------- +int SVTK_SpaceMouse::close(Display *display) +{ + initialize( display, (Window)InputFocus ); + spaceMouseOn = 0; + + return 1; +} + +//--------------------------------------------- +int SVTK_SpaceMouse::translateEvent( Display* display, XEvent* xEvent, MoveEvent* spaceMouseEvent, + double scale, double rScale ) +{ + if ( !spaceMouseOn ) + return 0; + + if ( xEvent->type == ClientMessage ) { + if ( xEvent->xclient.message_type == XMotionEvent ) { + spaceMouseEvent->type = SpaceMouseMove; + spaceMouseEvent->data[ x ] = + xEvent->xclient.data.s[2] * scale; + spaceMouseEvent->data[ y ] = + xEvent->xclient.data.s[3] * scale; + spaceMouseEvent->data[ z ] = + xEvent->xclient.data.s[4] * scale; + spaceMouseEvent->data[ a ] = + xEvent->xclient.data.s[5] * rScale; + spaceMouseEvent->data[ b ] = + xEvent->xclient.data.s[6] * rScale; + spaceMouseEvent->data[ c ] = + xEvent->xclient.data.s[7] * rScale; + spaceMouseEvent->period = xEvent->xclient.data.s[8]; + return 1; + } + else if ( xEvent->xclient.message_type == XButtonPressEvent ) { + spaceMouseEvent->type = SpaceButtonPress; + spaceMouseEvent->button = xEvent->xclient.data.s[2]; + return 2; + } + else if ( xEvent->xclient.message_type == XButtonReleaseEvent ) { + spaceMouseEvent->type = SpaceButtonRelease; + spaceMouseEvent->button = xEvent->xclient.data.s[2]; + return 3; + } + } + return (!display); +} + diff --git a/src/SVTK/SVTK_SpaceMouse.h b/src/SVTK/SVTK_SpaceMouse.h new file mode 100644 index 000000000..57a6f8470 --- /dev/null +++ b/src/SVTK/SVTK_SpaceMouse.h @@ -0,0 +1,75 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_SpaceMouse.h +// Author : Alexander SLADKOV +// Module : SALOME +// $Header$ + +#ifndef SVTK_SpaceMouse_h +#define SVTK_SpaceMouse_h + +extern "C" +{ +#include +#include +} + +class SVTK_SpaceMouse +{ + public: + + // access to SpaceMouse utility class + static SVTK_SpaceMouse* getInstance(); + + enum MoveData { x, y, z, a, b, c }; + enum EventType { SpaceMouseMove = 1, SpaceButtonPress, SpaceButtonRelease }; + + typedef struct { + int type; + int button; + double data[6]; + int period; + } MoveEvent; + + bool isSpaceMouseOn() const { return spaceMouseOn != 0; } + + int initialize ( Display*, Window ); + int setWindow ( Display*, Window ); + int translateEvent ( Display*, XEvent*, MoveEvent*, double, double ); + int close ( Display* ); + + private: + SVTK_SpaceMouse(); + static SVTK_SpaceMouse* myInstance; + + Atom XMotionEvent; + Atom XButtonPressEvent; + Atom XButtonReleaseEvent; + Atom XCommandEvent; + + Window win; + int spaceMouseOn; +}; + +#endif diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx new file mode 100644 index 000000000..966ff2340 --- /dev/null +++ b/src/SVTK/SVTK_View.cxx @@ -0,0 +1,546 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#include "SALOME_Actor.h" + +#include "SVTK_View.h" +#include "SVTK_Renderer.h" +#include "SVTK_MainWindow.h" +#include "SVTK_RenderWindowInteractor.h" +#include "SALOME_ListIteratorOfListIO.hxx" + +#include "VTKViewer_Algorithm.h" +#include "SVTK_Functor.h" + +#include +#include + + +//---------------------------------------------------------------------------- +SVTK_SignalHandler +::SVTK_SignalHandler(SVTK_MainWindow* theMainWindow): + QObject(theMainWindow), + myMainWindow(theMainWindow) +{ + SVTK_RenderWindowInteractor* anInteractor = theMainWindow->GetInteractor(); + + connect(anInteractor,SIGNAL(KeyPressed(QKeyEvent*)), + this,SIGNAL(KeyPressed(QKeyEvent*)) ); + connect(anInteractor,SIGNAL(KeyReleased(QKeyEvent*)), + this,SIGNAL(KeyReleased(QKeyEvent*))); + connect(anInteractor,SIGNAL(MouseButtonPressed(QMouseEvent*)), + this,SIGNAL(MouseButtonPressed(QMouseEvent*))); + connect(anInteractor,SIGNAL(MouseButtonReleased(QMouseEvent*)), + this,SIGNAL(MouseButtonReleased(QMouseEvent*))); + connect(anInteractor,SIGNAL(MouseDoubleClicked(QMouseEvent*)), + this,SIGNAL(MouseDoubleClicked(QMouseEvent*))); + connect(anInteractor,SIGNAL(MouseMove(QMouseEvent*)), + this,SIGNAL(MouseMove(QMouseEvent*))); + connect(anInteractor,SIGNAL(contextMenuRequested(QContextMenuEvent*)), + this,SIGNAL(contextMenuRequested(QContextMenuEvent*))); + connect(anInteractor,SIGNAL(selectionChanged()), + this,SIGNAL(selectionChanged())); +} + +SVTK_SignalHandler +::~SVTK_SignalHandler() +{ +} + +SVTK_MainWindow* +SVTK_SignalHandler +::GetMainWindow() +{ + return myMainWindow; +} + + +//---------------------------------------------------------------- +void +SVTK_SignalHandler +::Repaint(bool theUpdateTrihedron) +{ + myMainWindow->Repaint(theUpdateTrihedron); +} + +//---------------------------------------------------------------------------- +SVTK_Renderer* +SVTK_SignalHandler +::GetRenderer() +{ + return myMainWindow->GetRenderer(); +} + +vtkRenderer* +SVTK_SignalHandler +::getRenderer() +{ + return myMainWindow->getRenderer(); +} + +//---------------------------------------------------------------- +namespace SVTK +{ + struct THighlightAction + { + bool myIsHighlight; + THighlightAction( bool theIsHighlight ): + myIsHighlight( theIsHighlight ) + {} + + void + operator()( SALOME_Actor* theActor) + { + if(theActor->GetMapper() && theActor->hasIO()){ + theActor->Highlight( myIsHighlight ); + } + } + }; +} + +void +SVTK_SignalHandler +::onSelectionChanged() +{ + vtkActorCollection* anActors = myMainWindow->getRenderer()->GetActors(); + + using namespace SVTK; + ForEach(anActors, + THighlightAction( false )); + SVTK_Selector* aSelector = myMainWindow->GetSelector(); + const SALOME_ListIO& aListIO = aSelector->StoredIObjects(); + SALOME_ListIteratorOfListIO anIter(aListIO); + for(; anIter.More(); anIter.Next()){ + ForEachIf(anActors, + TIsSameIObject(anIter.Value()), + THighlightAction(true)); + } + + myMainWindow->Repaint(false); +} + + +//---------------------------------------------------------------------------- +SVTK_View +::SVTK_View(SVTK_MainWindow* theMainWindow) : + SVTK_SignalHandler(theMainWindow) +{ +} + +//---------------------------------------------------------------------------- +SVTK_View +::~SVTK_View() +{ +} + +//---------------------------------------------------------------- +void +SVTK_View +::unHighlightAll() +{ + using namespace SVTK; + ForEach(getRenderer()->GetActors(), + THighlightAction( false )); + Repaint(); +} + +//---------------------------------------------------------------- +void +SVTK_View +::highlight( const Handle(SALOME_InteractiveObject)& theIO, + bool theIsHighlight, + bool theIsUpdate ) +{ + using namespace SVTK; + ForEachIf(getRenderer()->GetActors(), + TIsSameIObject( theIO ), + THighlightAction(theIsHighlight)); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_View +::SetSelectionProp(const double& theRed, + const double& theGreen, + const double& theBlue, + const int& theWidth) +{ + GetRenderer()->SetSelectionProp(theRed,theGreen,theBlue,theWidth); +} + +//---------------------------------------------------------------------------- +void +SVTK_View +::SetPreselectionProp(const double& theRed, + const double& theGreen, + const double& theBlue, + const int& theWidth) +{ + GetRenderer()->SetPreselectionProp(theRed,theGreen,theBlue,theWidth); +} + +//---------------------------------------------------------------------------- +void +SVTK_View +::SetSelectionTolerance(const double& theTolNodes, + const double& theTolCell) +{ + GetRenderer()->SetSelectionTolerance(theTolNodes,theTolCell); +} + +//---------------------------------------------------------------------------- +bool +SVTK_View +::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject) +{ + using namespace SVTK; + SALOME_Actor* anActor = + Find(getRenderer()->GetActors(), + TIsSameIObject(theIObject)); + return anActor != NULL; +} + +//---------------------------------------------------------------------------- +bool +SVTK_View +::isVisible(const Handle(SALOME_InteractiveObject)& theIObject) +{ + using namespace SVTK; + SALOME_Actor* anActor = + Find(getRenderer()->GetActors(), + TIsSameIObject(theIObject)); + return anActor != NULL && anActor->GetVisibility(); +} + +//---------------------------------------------------------------------------- +void +SVTK_View +::rename(const Handle(SALOME_InteractiveObject)& theIObject, + const QString& theName) +{ + using namespace SVTK; + ForEachIf(getRenderer()->GetActors(), + TIsSameIObject(theIObject), + TSetFunction + (&SALOME_Actor::setName,theName.latin1())); +} + +//---------------------------------------------------------------------------- +int +SVTK_View +::GetDisplayMode() +{ + return myDisplayMode; +} + +void +SVTK_View +::SetDisplayMode(int theMode) +{ + if(theMode == 0) + ChangeRepresentationToWireframe(); + else + ChangeRepresentationToSurface(); + myDisplayMode = theMode; +} + +void +SVTK_View +::SetDisplayMode(const Handle(SALOME_InteractiveObject)& theIObject, + int theMode) +{ + using namespace SVTK; + ForEachIf(getRenderer()->GetActors(), + TIsSameIObject(theIObject), + TSetFunction + (&SALOME_Actor::setDisplayMode,theMode)); +} + +//---------------------------------------------------------------------------- +void +SVTK_View +::ChangeRepresentationToWireframe() +{ + ChangeRepresentationToWireframe(getRenderer()->GetActors()); +} + +void +SVTK_View +::ChangeRepresentationToSurface() +{ + ChangeRepresentationToSurface(getRenderer()->GetActors()); +} + + +void +SVTK_View +::ChangeRepresentationToWireframe(vtkActorCollection* theCollection) +{ + using namespace SVTK; + ForEach(theCollection, + TSetFunction + (&SALOME_Actor::setDisplayMode,0)); + Repaint(); +} + +void +SVTK_View +::ChangeRepresentationToSurface(vtkActorCollection* theCollection) +{ + using namespace SVTK; + ForEach(theCollection, + TSetFunction + (&SALOME_Actor::setDisplayMode,1)); + Repaint(); +} + +//---------------------------------------------------------------------------- +namespace SVTK +{ + struct TErase + { + VTK::TSetFunction mySetFunction; + TErase(): + mySetFunction(&vtkActor::SetVisibility,false) + {} + void + operator()(SALOME_Actor* theActor) + { + theActor->SetVisibility(false); + // Erase dependent actors + vtkActorCollection* aCollection = vtkActorCollection::New(); + theActor->GetChildActors(aCollection); + VTK::ForEach(aCollection,mySetFunction); + aCollection->Delete(); + } + }; +} + +void +SVTK_View +::EraseAll() +{ + using namespace SVTK; + ForEach(getRenderer()->GetActors(), + TErase()); + Repaint(); +} + +void +SVTK_View +::DisplayAll() +{ + using namespace SVTK; + ForEach(getRenderer()->GetActors(), + TSetVisibility(true)); + Repaint(); +} + + +void +SVTK_View +::Erase(SALOME_Actor* theActor, + bool theIsUpdate) +{ + SVTK::TErase()(theActor); + + if(theIsUpdate) + Repaint(); +} + + +void +SVTK_View +::Erase(const Handle(SALOME_InteractiveObject)& theIObject, + bool theIsUpdate) +{ + using namespace SVTK; + ForEachIf(getRenderer()->GetActors(), + TIsSameIObject(theIObject), + TErase()); + if(theIsUpdate) + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_View +::Display(SALOME_Actor* theActor, + bool theIsUpdate) +{ + GetRenderer()->AddActor(theActor); + theActor->SetVisibility(true); + + if(theIsUpdate) + Repaint(); +} + +void +SVTK_View +::Display(const Handle(SALOME_InteractiveObject)& theIObject, + bool theIsUpdate) +{ + using namespace SVTK; + ForEachIf(getRenderer()->GetActors(), + TIsSameIObject(theIObject), + TSetVisibility(true)); + + if(theIsUpdate) + Repaint(); +} + +void +SVTK_View +::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject) +{ + EraseAll(); + Display(theIObject); +} + + +//---------------------------------------------------------------------------- +namespace SVTK +{ + struct TRemoveAction + { + SVTK_Renderer* myRenderer; + TRemoveAction(SVTK_Renderer* theRenderer): + myRenderer(theRenderer) + {} + void + operator()(SALOME_Actor* theActor) + { + myRenderer->RemoveActor(theActor); + } + }; +} + +void +SVTK_View +::Remove(const Handle(SALOME_InteractiveObject)& theIObject, + bool theIsUpdate) +{ + using namespace SVTK; + ForEachIf(getRenderer()->GetActors(), + TIsSameIObject(theIObject), + TRemoveAction(GetRenderer())); + if(theIsUpdate) + Repaint(); +} + +void +SVTK_View +::Remove(SALOME_Actor* theActor, + bool theIsUpdate) +{ + GetRenderer()->RemoveActor(theActor); + if(theIsUpdate) + Repaint(); +} + +void +SVTK_View +::RemoveAll(bool theIsUpdate) +{ + vtkRenderer* aRenderer = getRenderer(); + if(vtkActorCollection* anActors = aRenderer->GetActors()){ + anActors->InitTraversal(); + while(vtkActor *anAct = anActors->GetNextActor()){ + if(SALOME_Actor* aSAct = SALOME_Actor::SafeDownCast(anAct)){ + if(aSAct->hasIO() && aSAct->getIO()->hasEntry()) + aRenderer->RemoveActor( anAct ); + } + } + + if(theIsUpdate) + Repaint(); + } +} + +//---------------------------------------------------------------------------- +float +SVTK_View +::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject) +{ + using namespace SVTK; + SALOME_Actor* anActor = + Find(getRenderer()->GetActors(), + TIsSameIObject(theIObject)); + if(anActor) + return 1.0 - anActor->GetOpacity(); + return -1.0; +} + + +void +SVTK_View +::SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, + float theTrans) +{ + float anOpacity = 1.0 - theTrans; + using namespace SVTK; + ForEachIf(getRenderer()->GetActors(), + TIsSameIObject(theIObject), + TSetFunction + (&SALOME_Actor::SetOpacity,anOpacity)); +} + +//---------------------------------------------------------------------------- +void +SVTK_View +::SetColor(const Handle(SALOME_InteractiveObject)& theIObject, + const QColor& theColor) +{ + float aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.}; + + using namespace SVTK; + ForEachIf(getRenderer()->GetActors(), + TIsSameIObject(theIObject), + TSetFunction + (&SALOME_Actor::SetColor,aColor)); +} + + +QColor +SVTK_View +::GetColor(const Handle(SALOME_InteractiveObject)& theIObject) +{ + using namespace SVTK; + SALOME_Actor* anActor = + Find(getRenderer()->GetActors(), + TIsSameIObject(theIObject)); + if(anActor){ + float r,g,b; + anActor->GetColor(r,g,b); + return QColor(int(r*255),int(g*255),int(b*255)); + } + + return QColor(0,0,0); +} + diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h new file mode 100644 index 000000000..2512c3497 --- /dev/null +++ b/src/SVTK/SVTK_View.h @@ -0,0 +1,248 @@ +#ifndef SVTK_VIEW_H +#define SVTK_VIEW_H + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +#include "SVTK.h" +#include "SALOME_InteractiveObject.hxx" + +#include + +class vtkActorCollection; +class vtkRenderer; + +class SVTK_MainWindow; +class SVTK_Renderer; + +class SALOME_Actor; + +//---------------------------------------------------------------------------- +//! Main purpose of the class is to provide a way to customize #SVTK_MainWindow. +/*! + This class is initialized by #SVTK_MainWindow and just pass Qt signals from + corresponding #SVTK_RenderWindowInteractor of the #SVTK_MainWindow. + Its main purpose is to provide a simple and flexible way to customize the #SVTK_MainWindow. + So, in your own viewer it is possible to derive new #SVTK_MainWindow and + use existing functionality without any modifications. + */ +class SVTK_EXPORT SVTK_SignalHandler : public QObject +{ + Q_OBJECT; + +public: + SVTK_SignalHandler(SVTK_MainWindow* theMainWindow); + + virtual + ~SVTK_SignalHandler(); + + //! Get reference to its #SVTK_MainWindow + SVTK_MainWindow* + GetMainWindow(); + + //---------------------------------------------------------------------------- + //! Redirect the request to #SVTK_MainWindow::Repaint (just for flexibility) + void + Repaint(bool theUpdateTrihedron = true); + + //---------------------------------------------------------------------------- + //! Redirect the request to #SVTK_MainWindow::GetRenderer (just for flexibility) + SVTK_Renderer* + GetRenderer(); + + //! Redirect the request to #SVTK_MainWindow::getRenderer (just for flexibility) + vtkRenderer* + getRenderer(); + + //---------------------------------------------------------------------------- + public slots: + void onSelectionChanged(); + + public: + signals: + void MouseMove( QMouseEvent* ); + void MouseButtonPressed( QMouseEvent* ); + void MouseButtonReleased( QMouseEvent* ); + void MouseDoubleClicked( QMouseEvent* ); + void ButtonPressed(const QMouseEvent *event); + void ButtonReleased(const QMouseEvent *event); + void WheelMoved( QWheelEvent* ); + void KeyPressed( QKeyEvent* ); + void KeyReleased( QKeyEvent* ); + void contextMenuRequested( QContextMenuEvent *e ); + void selectionChanged(); + + protected: + SVTK_MainWindow* myMainWindow; +}; + + +//---------------------------------------------------------------------------- +//! This class is introduced just for compatibility with old code. +/*! + This class contains frequantly used functionality in old code. + Now, you are supposed to extend existing functionality through + writing corresponding functors (see SVTK_Functor.h for example). + */ +class SVTK_EXPORT SVTK_View : public SVTK_SignalHandler +{ + Q_OBJECT; + +public: + SVTK_View(SVTK_MainWindow* theMainWindow); + + virtual + ~SVTK_View(); + + /* interactive object management */ + //! To highlight a VTK presentation with the same #SALOME_InteractiveObject + void + highlight(const Handle(SALOME_InteractiveObject)& IObject, + bool highlight, + bool immediatly = true); + + //! To unhighlight all VTK presentations + void + unHighlightAll(); + + /* Selection Management */ + Handle(SALOME_InteractiveObject) + FindIObject(const char* Entry); + + //! Check, if the viewer contains a presentatin with defined #SALOME_InteractiveObject + bool + isInViewer(const Handle(SALOME_InteractiveObject)& IObject); + + //! Check, if a presentatin with defined #SALOME_InteractiveObject is visible + bool + isVisible(const Handle(SALOME_InteractiveObject)& IObject); + + void + rename(const Handle(SALOME_InteractiveObject)& IObject, + const QString& newName); + + //---------------------------------------------------------------------------- + // Displaymode management + //! Get current display mode (obsolete) + int + GetDisplayMode(); + + //! Set current display mode + void + SetDisplayMode(int); + + //! Switch representation wireframe/shading + void + SetDisplayMode(const Handle(SALOME_InteractiveObject)& IObject, + int theMode); + + //! Change all actors to wireframe + void + ChangeRepresentationToWireframe(); + + //! Change all actors to surface + void + ChangeRepresentationToSurface(); + + //! Change to wireframe a list of vtkactor + void + ChangeRepresentationToWireframe(vtkActorCollection* theListofActors); + + //! Change to surface a list of vtkactor + void + ChangeRepresentationToSurface(vtkActorCollection* theListofActors); + + //! Change transparency + void + SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, + float trans); + + //! Get current transparency + float + GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject); + + //! Change color + void + SetColor(const Handle(SALOME_InteractiveObject)& theIObject, + const QColor& theColor); + + //! Get current color + QColor + GetColor(const Handle(SALOME_InteractiveObject)& theIObject); + + //---------------------------------------------------------------------------- + // Erase Display functions + //! To erase all existing VTK presentations + void + EraseAll(); + + //! To display all existing VTK presentations + void + DisplayAll(); + + //! To remove from the view all existing VTK presentations + void + RemoveAll( const bool immediatly ); + + //! To erase VTK presentation with defined #SALOME_InteractiveObject + void + Erase(const Handle(SALOME_InteractiveObject)& IObject, + bool immediatly = true); + void + Remove(const Handle(SALOME_InteractiveObject)& IObject, + bool immediatly = true); + + //! To display VTK presentation with defined #SALOME_InteractiveObject + void + Display(const Handle(SALOME_InteractiveObject)& IObject, + bool immediatly = true); + + //! To display VTK presentation with defined #SALOME_InteractiveObject and erase all anothers + void + DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject); + + //! To display the VTK presentation + void + Display(SALOME_Actor* SActor, + bool immediatly = true); + + //! To erase the VTK presentation + void + Erase(SALOME_Actor* SActor, + bool immediatly = true); + + //! To remove the VTK presentation + void + Remove(SALOME_Actor* SActor, + bool updateViewer = true); + + //---------------------------------------------------------------------------- + //! Redirect the request to #SVTK_Renderer::SetPreselectionProp + void + SetSelectionProp(const double& theRed = 1, + const double& theGreen = 1, + const double& theBlue = 0, + const int& theWidth = 5); + + //! Redirect the request to #SVTK_Renderer::SetPreselectionProp + void + SetPreselectionProp(const double& theRed = 0, + const double& theGreen = 1, + const double& theBlue = 1, + const int& theWidth = 5); + + //! Redirect the request to #SVTK_Renderer::SetPreselectionProp + void + SetSelectionTolerance(const double& theTolNodes = 0.025, + const double& theTolCell = 0.001); + + protected: + int myDisplayMode; +}; + +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif diff --git a/src/SVTK/SVTK_ViewManager.h b/src/SVTK/SVTK_ViewManager.h index ae3bf47f8..b200ccc5b 100644 --- a/src/SVTK/SVTK_ViewManager.h +++ b/src/SVTK/SVTK_ViewManager.h @@ -24,12 +24,16 @@ class SUIT_Desktop; +//! Extend SUIT_ViewManager to deal with SVTK_Viewer class SVTK_EXPORT SVTK_ViewManager : public SUIT_ViewManager { Q_OBJECT public: + //! Construct the view manager SVTK_ViewManager( SUIT_Study* study, SUIT_Desktop* ); + + //! Destroy the view manager virtual ~SVTK_ViewManager(); protected: diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index a8a11fbd2..08c2169d5 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -28,29 +28,15 @@ #include "SVTK_Selection.h" #include "SVTK_ViewModel.h" #include "SVTK_ViewWindow.h" +#include "SVTK_View.h" +#include "SVTK_MainWindow.h" #include "SVTK_Prs.h" #include "VTKViewer_ViewModel.h" -#include "SVTK_RenderWindowInteractor.h" -#include "SVTK_RenderWindow.h" - -//#include - #include #include -// Temporarily commented to avoid awful dependecy on SALOMEDS -// TODO: better mechanism of storing display/erse status in a study -// should be provided... -//#include "Utils_ORB_INIT.hxx" -//#include "Utils_SINGLETON.hxx" -//#include "SALOME_ModuleCatalog_impl.hxx" -//#include "SALOME_NamingService.hxx" - -//#include "SALOMEDSClient.hxx" -//#include "SALOMEDS_StudyManager.hxx" - // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study. // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from // SALOMEDS::StudyManager - no linkage with SalomeApp. @@ -76,7 +62,7 @@ //========================================================== SVTK_Viewer::SVTK_Viewer() { - myTrihedronSize = 100; + myTrihedronSize = 105; } //========================================================== @@ -84,24 +70,44 @@ SVTK_Viewer::~SVTK_Viewer() { } -QColor SVTK_Viewer::backgroundColor() const +QColor +SVTK_Viewer +::backgroundColor() const { return myBgColor; } -void SVTK_Viewer::setBackgroundColor( const QColor& c ) +void +SVTK_Viewer +::setBackgroundColor( const QColor& theColor ) { - if ( c.isValid() ) - myBgColor = c; + if ( !theColor.isValid() ) + return; + + QPtrVector aViews = myViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ + if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){ + if(TViewWindow* aView = dynamic_cast(aViewWindow)){ + aView->getMainWindow()->SetBackgroundColor(theColor); + } + } + } + + myBgColor = theColor; } //========================================================== -SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop ) +SUIT_ViewWindow* +SVTK_Viewer:: +createView( SUIT_Desktop* theDesktop ) { - SVTK_ViewWindow* vw = new SVTK_ViewWindow( theDesktop, this ); - vw->setBackgroundColor( backgroundColor() ); - vw->SetTrihedronSize( trihedronSize() ); - return vw; + SVTK_ViewWindow* aViewWindow = new SVTK_ViewWindow(theDesktop); + aViewWindow->Initialize(this); + + aViewWindow->setBackgroundColor( backgroundColor() ); + aViewWindow->SetTrihedronSize( trihedronSize() ); + + return aViewWindow; } int SVTK_Viewer::trihedronSize() const @@ -148,75 +154,39 @@ void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager) } //========================================================== -void SVTK_Viewer::contextMenuPopup( QPopupMenu* thePopup ) +void +SVTK_Viewer +::contextMenuPopup( QPopupMenu* thePopup ) { thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) ); thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) ); thePopup->insertSeparator(); - SVTK_ViewWindow* aView = (SVTK_ViewWindow*)(myViewManager->getActiveView()); - if ( aView && !aView->getToolBar()->isVisible() ) - thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) ); -} - -//========================================================== -void SVTK_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event) -{ - if(SVTK_ViewWindow* aVW = dynamic_cast(vw)){ - if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){ - switch(event->button()) { - case LeftButton: - aRWI->LeftButtonPressed(event) ; - break ; - case MidButton: - aRWI->MiddleButtonPressed(event) ; - break ; - case RightButton: - aRWI->RightButtonPressed(event) ; - break; - default: - break ; - } + if(TViewWindow* aView = dynamic_cast(myViewManager->getActiveView())){ + if ( !aView->getView()->GetMainWindow()->getToolBar()->isVisible() ){ + thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) ); } } } +//========================================================== +void +SVTK_Viewer +::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event) +{} + //========================================================== void SVTK_Viewer ::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event) -{ - if(SVTK_ViewWindow* aVW = dynamic_cast(vw)){ - if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){ - aRWI->MouseMove( event ); - } - } -} +{} //========================================================== void SVTK_Viewer ::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event) -{ - if(SVTK_ViewWindow* aVW = dynamic_cast(vw)){ - if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){ - switch(event->button()) { - case LeftButton: - aRWI->LeftButtonReleased(event) ; - break ; - case MidButton: - aRWI->MiddleButtonReleased(event) ; - break ; - case RightButton: - aRWI->RightButtonReleased(event) ; - break; - default: - break ; - } - } - } -} +{} //========================================================== void @@ -236,21 +206,22 @@ SVTK_Viewer //!! To be done for view windows } -void SVTK_Viewer::onDumpView() +void +SVTK_Viewer +::onDumpView() { - SVTK_ViewWindow* aView = dynamic_cast(myViewManager->getActiveView()); - if ( aView ) + if(SUIT_ViewWindow* aView = myViewManager->getActiveView()) aView->onDumpView(); } //========================================================== -void SVTK_Viewer::onChangeBgColor() +void +SVTK_Viewer +::onChangeBgColor() { - SVTK_ViewWindow* aView = dynamic_cast(myViewManager->getActiveView()); - if ( aView ) { - QColor aColor = QColorDialog::getColor( aView->backgroundColor(), aView ); - if ( aColor.isValid() ) - aView->setBackgroundColor( aColor ); + if(SUIT_ViewWindow* aView = myViewManager->getActiveView()){ + QColor aColor = QColorDialog::getColor( backgroundColor(), aView); + setBackgroundColor(aColor); } } @@ -260,10 +231,11 @@ SVTK_Viewer ::onShowToolbar() { QPtrVector aViews = myViewManager->getViews(); - for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) - if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) - if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)) - aView->getToolBar()->show(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ + if(TViewWindow* aView = dynamic_cast(aViews.at(i))){ + aView->getView()->GetMainWindow()->getToolBar()->show(); + } + } } //========================================================== @@ -295,14 +267,12 @@ SVTK_Viewer // just display the object QPtrVector aViews = myViewManager->getViews(); for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ - if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){ - if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)){ - if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor()){ - aRWI->Display(anAct,false); - if(anAct->IsSetCamera()){ - vtkRenderer* aRenderer = aView->getRenderer(); - anAct->SetCamera( aRenderer->GetActiveCamera() ); - } + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))){ + if(SVTK_View* aView = aViewWindow->getView()){ + aView->Display(anAct,false); + if(anAct->IsSetCamera()){ + vtkRenderer* aRenderer = aView->getRenderer(); + anAct->SetCamera( aRenderer->GetActiveCamera() ); } } } @@ -342,13 +312,12 @@ SVTK_Viewer // just display the object QPtrVector aViews = myViewManager->getViews(); for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ - if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) - if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)) - if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor()) - if ( forced ) - aRWI->Remove(anAct,false); - else - aRWI->Erase(anAct,forced); + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))) + if(SVTK_View* aView = aViewWindow->getView()) + if ( forced ) + aView->Remove(anAct,false); + else + aView->Erase(anAct,forced); } } } @@ -366,11 +335,8 @@ SVTK_Viewer //_PTR(Study) aStudy(getStudyDS()); QPtrVector aViews = myViewManager->getViews(); for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ - if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){ - if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)){ - - aView->unHighlightAll(); - + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))) + if(SVTK_View* aView = aViewWindow->getView()){ vtkRenderer* aRenderer = aView->getRenderer(); vtkActorCollection* anActorCollection = aRenderer->GetActors(); anActorCollection->InitTraversal(); @@ -399,7 +365,6 @@ SVTK_Viewer } } } - } } Repaint(); } @@ -411,16 +376,19 @@ SVTK_Viewer { SVTK_Prs* prs = new SVTK_Prs(); if ( entry ) { - vtkRenderer* rnr = ( (SVTK_ViewWindow*) getViewManager()->getActiveView() )->getRenderer(); - vtkActorCollection* theActors = rnr->GetActors(); - theActors->InitTraversal(); - vtkActor* ac; - while( ( ac = theActors->GetNextActor() ) ) { - SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ); - if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) { - prs->AddObject( ac ); + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(getViewManager()->getActiveView())) + if(SVTK_View* aView = aViewWindow->getView()){ + vtkRenderer* aRenderer = aView->getRenderer(); + vtkActorCollection* theActors = aRenderer->GetActors(); + theActors->InitTraversal(); + vtkActor* ac; + while( ( ac = theActors->GetNextActor() ) ) { + SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ); + if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) { + prs->AddObject( ac ); + } + } } - } } return prs; } @@ -447,11 +415,11 @@ SVTK_Viewer { QPtrVector aViews = myViewManager->getViews(); for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) - if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) - if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)) - if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor()) - if(!aRWI->isVisible( io )) - return false; + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))) + if(SVTK_View* aView = aViewWindow->getView()) + if(!aView->isVisible( io )) + return false; + return true; } @@ -463,16 +431,7 @@ SVTK_Viewer // if (theUpdateTrihedron) onAdjustTrihedron(); QPtrVector aViews = myViewManager->getViews(); for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) - if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) - if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)) - if(SVTK_RenderWindow* aRW = aView->getRenderWindow()) - aRW->update(); + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))) + if(SVTK_View* aView = aViewWindow->getView()) + aView->Repaint(); } - -void -SVTK_Viewer -::onSelectionChanged() -{ - emit selectionChanged(); -} - diff --git a/src/SVTK/SVTK_ViewModel.h b/src/SVTK/SVTK_ViewModel.h index 7e70759fa..5875d465e 100644 --- a/src/SVTK/SVTK_ViewModel.h +++ b/src/SVTK/SVTK_ViewModel.h @@ -21,33 +21,52 @@ #include "SVTK.h" #include "SUIT_ViewModel.h" +#include "SVTK_ViewModelBase.h" #include "SALOME_Prs.h" #include "SALOME_InteractiveObject.hxx" #include -class SVTK_EXPORT SVTK_Viewer : public SUIT_ViewModel, public SALOME_View +class SVTK_ViewWindow; + +//! Extends two interfaces #SVTK_ViewModelBase and #SALOME_View +class SVTK_EXPORT SVTK_Viewer : public SVTK_ViewModelBase, public SALOME_View { Q_OBJECT; public: + typedef SVTK_ViewWindow TViewWindow; + + //! Define string representation of the viewer type static QString Type() { return "VTKViewer"; } SVTK_Viewer(); virtual ~SVTK_Viewer(); + //! See #SUIT_ViewModel::createView virtual SUIT_ViewWindow* createView(SUIT_Desktop*); - virtual void setViewManager(SUIT_ViewManager* theViewManager); - virtual void contextMenuPopup( QPopupMenu* ); - virtual QString getType() const { return Type(); } + //! See #SUIT_ViewModel::createView + virtual void setViewManager(SUIT_ViewManager* theViewManager); + + //! See #SUIT_ViewModel::contextMenuPopup + virtual void contextMenuPopup( QPopupMenu* ); + //! See #SUIT_ViewModel::getType + virtual QString getType() const { return Type(); } + + //! Get background color of the viewer QColor backgroundColor() const; - void setBackgroundColor( const QColor& ); - int trihedronSize() const; - void setTrihedronSize( const int ); + //! Set background color to the viewer + void setBackgroundColor( const QColor& ); + + //! Get size of trihedron of the viewer (see #SVTK_Renderer::SetTrihedronSize) + int trihedronSize() const; + + //! Set size of trihedron of the viewer (see #SVTK_Renderer::SetTrihedronSize) + void setTrihedronSize( const int ); public: void enableSelection(bool isEnabled); @@ -59,24 +78,30 @@ public: int getSelectionCount() const; /* Reimplemented from SALOME_View */ - void Display( const SALOME_VTKPrs* ); - void Erase( const SALOME_VTKPrs*, const bool = false ); - void EraseAll( const bool = false ); - SALOME_Prs* CreatePrs( const char* entry = 0 ); - virtual void BeforeDisplay( SALOME_Displayer* d ); - virtual void AfterDisplay ( SALOME_Displayer* d ); - virtual bool isVisible( const Handle(SALOME_InteractiveObject)& ); - virtual void Repaint(); - - //implemented in SOCC, but were not found in VTKVIEwer_ViewFrame, so not implemented here.. - //?virtual void LocalSelection( const SALOME_OCCPrs*, const int ); - //?virtual void GlobalSelection( const bool = false ) const; - -public slots: - void onSelectionChanged(); - - signals: - void selectionChanged(); + + //! See #SALOME_View::Display( const SALOME_Prs* ) + void Display( const SALOME_VTKPrs* ); + + //! See #SALOME_View::Erase( const SALOME_VTKPrs*, const bool = false ) + void Erase( const SALOME_VTKPrs*, const bool = false ); + + //! See #SALOME_View::EraseAll( const bool = false ) + void EraseAll( const bool = false ); + + //! See #SALOME_View::CreatePrs( const char* entry = 0 ) + SALOME_Prs* CreatePrs( const char* entry = 0 ); + + //! See #SALOME_View::BeforeDisplay( SALOME_Displayer* d ) + virtual void BeforeDisplay( SALOME_Displayer* d ); + + //! See #SALOME_View::AfterDisplay( SALOME_Displayer* d ) + virtual void AfterDisplay( SALOME_Displayer* d ); + + //! See #SALOME_View::isVisible( const Handle(SALOME_InteractiveObject)& ) + virtual bool isVisible( const Handle(SALOME_InteractiveObject)& ); + + //! See #SALOME_View::Repaint() + virtual void Repaint(); protected slots: void onMousePress(SUIT_ViewWindow*, QMouseEvent*); diff --git a/src/SVTK/SVTK_ViewModelBase.h b/src/SVTK/SVTK_ViewModelBase.h new file mode 100644 index 000000000..d58827229 --- /dev/null +++ b/src/SVTK/SVTK_ViewModelBase.h @@ -0,0 +1,27 @@ +#ifndef SVTK_SELECTIONCHANGED_H +#define SVTK_SELECTIONCHANGED_H + +#include + +#include "SVTK.h" +#include "SUIT_ViewModel.h" + + +//! To define minimal interface for #SVTK_ViewWindow initialization +class SVTK_EXPORT SVTK_ViewModelBase: public SUIT_ViewModel +{ + Q_OBJECT; + +public slots: + //! To invoke Qt #selectionChanged signal + void onSelectionChanged() + { + emit selectionChanged(); + } + + signals: + //! To declare signal on selection changed + void selectionChanged(); +}; + +#endif diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 6ee41df13..b95a23d20 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include "QtxAction.h" @@ -36,350 +38,152 @@ #include "SUIT_Tools.h" #include "SUIT_ResourceMgr.h" +#include "SUIT_Accel.h" -#include "VTKViewer_Transform.h" #include "VTKViewer_Utilities.h" -#include "SVTK_Trihedron.h" -#include "SVTK_CubeAxesActor2D.h" +#include "SVTK_View.h" +#include "SVTK_MainWindow.h" +#include "SVTK_Selector.h" + +#include "SVTK_Event.h" +#include "SVTK_Renderer.h" #include "SVTK_ViewWindow.h" -#include "SVTK_ViewModel.h" -#include "SVTK_RenderWindow.h" -#include "SVTK_RenderWindowInteractor.h" +#include "SVTK_ViewModelBase.h" #include "SVTK_InteractorStyle.h" +#include "SVTK_RenderWindowInteractor.h" +#include "SVTK_GenericRenderWindowInteractor.h" #include "SALOME_ListIteratorOfListIO.hxx" -#include "SVTK_SelectorDef.h" - #include "VTKViewer_Algorithm.h" #include "SVTK_Functor.h" //---------------------------------------------------------------------------- SVTK_ViewWindow -::SVTK_ViewWindow( SUIT_Desktop* theDesktop, - SVTK_Viewer* theModel) - : SUIT_ViewWindow( theDesktop ), - myTrihedronSize( 100 ) -{ - myModel = theModel; - mySelector = new SVTK_SelectorDef(); - connect(this,SIGNAL(selectionChanged()),theModel,SLOT(onSelectionChanged())); - - myTransform = VTKViewer_Transform::New(); - myTrihedron = SVTK_Trihedron::New(); - myCubeAxes = SVTK_CubeAxesActor2D::New(); - myRenderer = vtkRenderer::New() ; - - myTrihedron->AddToRender( myRenderer ); - myRenderer->AddProp(myCubeAxes); - - myRenderWindow = new SVTK_RenderWindow( this, "RenderWindow" ); - setCentralWidget(myRenderWindow); - myRenderWindow->setFocusPolicy( StrongFocus ); - myRenderWindow->setFocus(); - - myRenderWindow->getRenderWindow()->AddRenderer( myRenderer ); - - myRenderer->GetActiveCamera()->ParallelProjectionOn(); - myRenderer->LightFollowCameraOn(); - myRenderer->TwoSidedLightingOn(); - - // Set BackgroundColor - QString BgrColorRed = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed"); - QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen"); - QString BgrColorBlue = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue"); - - if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() ) - myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. ); - else - myRenderer->SetBackground( 0, 0, 0 ); - - // Create an interactor. - myRWInteractor = SVTK_RenderWindowInteractor::New(); - myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() ); - myRWInteractor->setViewWindow( this ); - - SVTK_InteractorStyle* RWS = SVTK_InteractorStyle::New(); - RWS->setGUIWindow( myRenderWindow ); - RWS->setViewWindow( this ); - - myRWInteractor->SetInteractorStyle( RWS ); - myRWInteractor->Initialize(); - - //merge with V2_2_0_VISU_improvements:RWS->setTriedron( myTrihedron ); - RWS->FindPokedRenderer( 0, 0 ); - - SetSelectionMode(ActorSelection); - - vtkTextProperty* tprop = vtkTextProperty::New(); - tprop->SetColor(1, 1, 1); - tprop->ShadowOn(); - - float bnd[6]; - bnd[0] = bnd[2] = bnd[4] = 0; - bnd[1] = bnd[3] = bnd[5] = myTrihedron->GetSize(); - myCubeAxes->SetLabelFormat("%6.4g"); - myCubeAxes->SetBounds(bnd); - myCubeAxes->SetCamera(myRenderer->GetActiveCamera()); - myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee - myCubeAxes->SetFontFactor(0.8); - myCubeAxes->SetAxisTitleTextProperty(tprop); - myCubeAxes->SetAxisLabelTextProperty(tprop); - myCubeAxes->SetCornerOffset(0); - myCubeAxes->SetScaling(0); - myCubeAxes->SetNumberOfLabels(5); - myCubeAxes->VisibilityOff(); - myCubeAxes->SetTransform(myTransform); - tprop->Delete(); - - setCentralWidget( myRenderWindow ); - - myToolBar = new QToolBar(this); - myToolBar->setCloseMode(QDockWindow::Undocked); - myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); - - createActions(); - createToolBar(); - - connect( myRenderWindow, SIGNAL(KeyPressed( QKeyEvent* )), - this, SLOT(onKeyPressed( QKeyEvent* )) ); - connect( myRenderWindow, SIGNAL(KeyReleased( QKeyEvent* )), - this, SLOT(onKeyReleased( QKeyEvent* )) ); - connect( myRenderWindow, SIGNAL(MouseButtonPressed( QMouseEvent* )), - this, SLOT(onMousePressed( QMouseEvent* )) ); - connect( myRenderWindow, SIGNAL(MouseButtonReleased( QMouseEvent* )), - this, SLOT(onMouseReleased( QMouseEvent* )) ); - connect( myRenderWindow, SIGNAL(MouseDoubleClicked( QMouseEvent* )), - this, SLOT(onMouseDoubleClicked( QMouseEvent* )) ); - connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )), - this, SLOT(onMouseMoving( QMouseEvent* )) ); - - connect( myRWInteractor, SIGNAL(RenderWindowModified()), - myRenderWindow, SLOT(update()) ); - connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )), - this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) ); - - onResetView(); -} +::SVTK_ViewWindow(SUIT_Desktop* theDesktop): + SUIT_ViewWindow(theDesktop), + myMainWindow(NULL), + myView(NULL) +{} -//---------------------------------------------------------------------------- +void SVTK_ViewWindow -::~SVTK_ViewWindow() +::Initialize(SVTK_ViewModelBase* theModel) { - myTransform->Delete(); - // In order to ensure that the interactor unregisters - // this RenderWindow, we assign a NULL RenderWindow to - // it before deleting it. - myRWInteractor->SetRenderWindow( NULL ); - myRWInteractor->Delete(); - - //m_RW->Delete() ; - myRenderer->RemoveAllProps(); - //m_Renderer->Delete(); - myTrihedron->Delete(); - myCubeAxes->Delete(); + if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){ + myMainWindow = new SVTK_MainWindow(this,"SVTK_MainWindow",aResourceMgr,this); + + SVTK_RenderWindowInteractor* anIteractor = + new SVTK_RenderWindowInteractor(myMainWindow,"SVTK_RenderWindowInteractor"); + + SVTK_Selector* aSelector = SVTK_Selector::New(); + + SVTK_GenericRenderWindowInteractor* aDevice = + SVTK_GenericRenderWindowInteractor::New(); + aDevice->SetRenderWidget(anIteractor); + aDevice->SetSelector(aSelector); + + SVTK_Renderer* aRenderer = SVTK_Renderer::New(); + aRenderer->Initialize(aDevice,aSelector); + + anIteractor->Initialize(aDevice,aRenderer,aSelector); + + aDevice->Delete(); + aRenderer->Delete(); + aSelector->Delete(); + + myMainWindow->Initialize(anIteractor); + + SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New(); + anIteractor->PushInteractorStyle(aStyle); + aStyle->Delete(); + + setCentralWidget(myMainWindow); + + myView = new SVTK_View(myMainWindow); + Initialize(myView,theModel); + } } -//---------------------------------------------------------------------------- void SVTK_ViewWindow -::activateZoom() +::Initialize(SVTK_View* theView, + SVTK_ViewModelBase* theModel) { - myRWInteractor->GetSInteractorStyle()->startZoom(); + connect(theView,SIGNAL(KeyPressed(QKeyEvent*)), + this,SLOT(onKeyPressed(QKeyEvent*)) ); + connect(theView,SIGNAL(KeyReleased(QKeyEvent*)), + this,SLOT(onKeyReleased(QKeyEvent*))); + connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)), + this,SLOT(onMousePressed(QMouseEvent*))); + connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)), + this,SLOT(onMouseReleased(QMouseEvent*))); + connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)), + this,SLOT(onMouseDoubleClicked(QMouseEvent*))); + connect(theView,SIGNAL(MouseMove(QMouseEvent*)), + this,SLOT(onMouseMoving(QMouseEvent*))); + connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)), + this,SIGNAL(contextMenuRequested(QContextMenuEvent *))); + connect(theView,SIGNAL(selectionChanged()), + theModel,SLOT(onSelectionChanged())); } -//---------------------------------------------------------------------------- -void SVTK_ViewWindow -::activatePanning() -{ - myRWInteractor->GetSInteractorStyle()->startPan(); -} +::~SVTK_ViewWindow() +{} + //---------------------------------------------------------------------------- -void +SVTK_View* SVTK_ViewWindow -::activateRotation() -{ - myRWInteractor->GetSInteractorStyle()->startRotate(); +::getView() +{ + return myView; } -//---------------------------------------------------------------------------- -void +SVTK_MainWindow* SVTK_ViewWindow -::activateGlobalPanning() -{ - if(myTrihedron->GetVisibleActorCount(myRenderer)) - myRWInteractor->GetSInteractorStyle()->startGlobalPan(); +::getMainWindow() +{ + return myMainWindow; } -//---------------------------------------------------------------------------- -void +vtkRenderWindow* SVTK_ViewWindow -::activateWindowFit() +::getRenderWindow() { - myRWInteractor->GetSInteractorStyle()->startFitArea(); + return getMainWindow()->getRenderWindow(); } -//---------------------------------------------------------------------------- -#if defined(WIN32) && !defined(_DEBUG) -#pragma optimize( "", off ) -#endif -void +vtkRenderWindowInteractor* SVTK_ViewWindow -::createActions() +::getInteractor() { - if (!myActionsMap.isEmpty()) return; - - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - - QtxAction* aAction; - - // Dump view - aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ), - tr( "MNU_DUMP_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_DUMP_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView())); - myActionsMap[ DumpId ] = aAction; - - // FitAll - aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ), - tr( "MNU_FITALL" ), 0, this); - aAction->setStatusTip(tr("DSC_FITALL")); - connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll())); - myActionsMap[ FitAllId ] = aAction; - - // FitRect - aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ), - tr( "MNU_FITRECT" ), 0, this); - aAction->setStatusTip(tr("DSC_FITRECT")); - connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit())); - myActionsMap[ FitRectId ] = aAction; - - // Zoom - aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ), - tr( "MNU_ZOOM_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_ZOOM_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom())); - myActionsMap[ ZoomId ] = aAction; - - // Panning - aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ), - tr( "MNU_PAN_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_PAN_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning())); - myActionsMap[ PanId ] = aAction; - - // Global Panning - aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ), - tr( "MNU_GLOBALPAN_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning())); - myActionsMap[ GlobalPanId ] = aAction; - - // Rotation - aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ), - tr( "MNU_ROTATE_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_ROTATE_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation())); - myActionsMap[ RotationId ] = aAction; - - // Projections - aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ), - tr( "MNU_FRONT_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_FRONT_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView())); - myActionsMap[ FrontId ] = aAction; - - aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ), - tr( "MNU_BACK_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_BACK_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onBackView())); - myActionsMap[ BackId ] = aAction; - - aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ), - tr( "MNU_TOP_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_TOP_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onTopView())); - myActionsMap[ TopId ] = aAction; - - aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ), - tr( "MNU_BOTTOM_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_BOTTOM_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView())); - myActionsMap[ BottomId ] = aAction; - - aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ), - tr( "MNU_LEFT_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_LEFT_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView())); - myActionsMap[ LeftId ] = aAction; - - aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ), - tr( "MNU_RIGHT_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_RIGHT_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onRightView())); - myActionsMap[ RightId ] = aAction; - - // Reset - aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ), - tr( "MNU_RESET_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_RESET_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onResetView())); - myActionsMap[ ResetId ] = aAction; - - // onViewTrihedron: Shows - Hides Trihedron - aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ), - tr( "MNU_SHOW_TRIHEDRON" ), 0, this); - aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON")); - connect(aAction, SIGNAL(activated()), this, SLOT(onViewTrihedron())); - myActionsMap[ ViewTrihedronId ] = aAction; + return getMainWindow()->getInteractor(); } -#if defined(WIN32) && !defined(_DEBUG) -#pragma optimize( "", on ) -#endif -//---------------------------------------------------------------------------- -void +vtkRenderer* SVTK_ViewWindow -::createToolBar() +::getRenderer() { - myActionsMap[DumpId]->addTo(myToolBar); - myActionsMap[ViewTrihedronId]->addTo(myToolBar); - - SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar); - aScaleBtn->AddAction(myActionsMap[FitAllId]); - aScaleBtn->AddAction(myActionsMap[FitRectId]); - aScaleBtn->AddAction(myActionsMap[ZoomId]); - - SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar); - aPanningBtn->AddAction(myActionsMap[PanId]); - aPanningBtn->AddAction(myActionsMap[GlobalPanId]); - - myActionsMap[RotationId]->addTo(myToolBar); - - SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar); - aViewsBtn->AddAction(myActionsMap[FrontId]); - aViewsBtn->AddAction(myActionsMap[BackId]); - aViewsBtn->AddAction(myActionsMap[TopId]); - aViewsBtn->AddAction(myActionsMap[BottomId]); - aViewsBtn->AddAction(myActionsMap[LeftId]); - aViewsBtn->AddAction(myActionsMap[RightId]); + return myMainWindow->getRenderer(); +} - myActionsMap[ResetId]->addTo(myToolBar); +SVTK_Selector* +SVTK_ViewWindow +::GetSelector() +{ + return myMainWindow->GetSelector(); } + //---------------------------------------------------------------------------- void SVTK_ViewWindow ::onFrontView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(1,0,0); - camera->SetViewUp(0,0,1); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myMainWindow->onFrontView(); } //---------------------------------------------------------------------------- @@ -387,11 +191,7 @@ void SVTK_ViewWindow ::onBackView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(-1,0,0); - camera->SetViewUp(0,0,1); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myMainWindow->onBackView(); } //---------------------------------------------------------------------------- @@ -399,11 +199,7 @@ void SVTK_ViewWindow ::onTopView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(0,0,1); - camera->SetViewUp(0,1,0); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myMainWindow->onTopView(); } //---------------------------------------------------------------------------- @@ -411,11 +207,7 @@ void SVTK_ViewWindow ::onBottomView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(0,0,-1); - camera->SetViewUp(0,1,0); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myMainWindow->onBottomView(); } //---------------------------------------------------------------------------- @@ -423,11 +215,7 @@ void SVTK_ViewWindow ::onLeftView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(0,-1,0); - camera->SetViewUp(0,0,1); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myMainWindow->onLeftView(); } //---------------------------------------------------------------------------- @@ -435,11 +223,7 @@ void SVTK_ViewWindow ::onRightView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(0,1,0); - camera->SetViewUp(0,0,1); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myMainWindow->onRightView(); } //---------------------------------------------------------------------------- @@ -447,27 +231,7 @@ void SVTK_ViewWindow ::onResetView() { - int aTrihedronIsVisible = isTrihedronDisplayed(); - int aCubeAxesIsVisible = isCubeAxesDisplayed(); - - myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn ); - myCubeAxes->SetVisibility(0); - - ::ResetCamera(myRenderer,true); - vtkCamera* aCamera = myRenderer->GetActiveCamera(); - aCamera->SetPosition(1,-1,1); - aCamera->SetViewUp(0,0,1); - ::ResetCamera(myRenderer,true); - - if (aTrihedronIsVisible) myTrihedron->VisibilityOn(); - else myTrihedron->VisibilityOff(); - - if (aCubeAxesIsVisible) myCubeAxes->VisibilityOn(); - else myCubeAxes->VisibilityOff(); - - static float aCoeff = 3.0; - aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale()); - Repaint(); + myMainWindow->onResetView(); } //---------------------------------------------------------------------------- @@ -475,43 +239,7 @@ void SVTK_ViewWindow ::onFitAll() { - int aTrihedronWasVisible = false; - int aCubeAxesWasVisible = false; - if (myTrihedron) { - aTrihedronWasVisible = isTrihedronDisplayed(); - if (aTrihedronWasVisible) - myTrihedron->VisibilityOff(); - } - - if (myCubeAxes) { - aCubeAxesWasVisible = isCubeAxesDisplayed(); - if (aCubeAxesWasVisible) - myCubeAxes->VisibilityOff(); - } - - if (myTrihedron->GetVisibleActorCount(myRenderer)) { - myTrihedron->VisibilityOff(); - myCubeAxes->VisibilityOff(); - ::ResetCamera(myRenderer); - } else { - myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn); - myCubeAxes->SetVisibility(2); - ::ResetCamera(myRenderer,true); - } - - if (aTrihedronWasVisible) - myTrihedron->VisibilityOn(); - else - myTrihedron->VisibilityOff(); - - if (aCubeAxesWasVisible) - myCubeAxes->VisibilityOn(); - else - myCubeAxes->VisibilityOff(); - - ::ResetCameraClippingRange(myRenderer); - - Repaint(); + myMainWindow->onFitAll(); } //---------------------------------------------------------------- @@ -519,15 +247,7 @@ void SVTK_ViewWindow ::onSelectionChanged() { - unHighlightAll(); - - const SALOME_ListIO& aListIO = mySelector->StoredIObjects(); - SALOME_ListIteratorOfListIO anIter(aListIO); - for(; anIter.More(); anIter.Next()){ - highlight(anIter.Value(),true,!anIter.More()); - } - - emit selectionChanged(); + myView->onSelectionChanged(); } //---------------------------------------------------------------- @@ -535,8 +255,7 @@ void SVTK_ViewWindow ::SetSelectionMode(Selection_Mode theMode) { - mySelector->SetSelectionMode(theMode); - myRWInteractor->SetSelectionMode(theMode); + myMainWindow->SetSelectionMode( theMode ); } //---------------------------------------------------------------- @@ -544,7 +263,7 @@ Selection_Mode SVTK_ViewWindow ::SelectionMode() const { - return mySelector->SelectionMode(); + return myMainWindow->SelectionMode(); } //---------------------------------------------------------------- @@ -552,43 +271,17 @@ void SVTK_ViewWindow ::unHighlightAll() { - myRWInteractor->unHighlightAll(); + myView->unHighlightAll(); } //---------------------------------------------------------------- void SVTK_ViewWindow -::highlight( const Handle(SALOME_InteractiveObject)& theIO, - bool theIsHighlight, - bool theIsUpdate ) +::highlight(const Handle(SALOME_InteractiveObject)& theIO, + bool theIsHighlight, + bool theIsUpdate ) { - myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate); - - if(mySelector->HasIndex(theIO) && theIO->hasEntry()){ - TColStd_IndexedMapOfInteger aMapIndex; - mySelector->GetIndex(theIO,aMapIndex); - using namespace VTK; - const char* anEntry = theIO->getEntry(); - vtkActorCollection* aCollection = myRenderer->GetActors(); - if(SALOME_Actor* anActor = Find(aCollection,TIsSameEntry(anEntry))){ - switch (mySelector->SelectionMode()) { - case NodeSelection: - myRWInteractor->highlightPoint(aMapIndex,anActor,theIsHighlight,theIsUpdate); - break; - case EdgeOfCellSelection: - myRWInteractor->highlightEdge(aMapIndex,anActor,theIsHighlight,theIsUpdate); - break; - case CellSelection: - case EdgeSelection: - case FaceSelection: - case VolumeSelection: - myRWInteractor->highlightCell(aMapIndex,anActor,theIsHighlight,theIsUpdate); - break; - } - } - }else{ - myRWInteractor->unHighlightSubSelection(); - } + myView->highlight( theIO, theIsHighlight, theIsUpdate ); } //---------------------------------------------------------------- @@ -596,7 +289,7 @@ bool SVTK_ViewWindow ::isInViewer( const Handle(SALOME_InteractiveObject)& theIO ) { - return myRWInteractor->isInViewer( theIO ); + return myView->isInViewer( theIO ); } //---------------------------------------------------------------- @@ -604,7 +297,45 @@ bool SVTK_ViewWindow ::isVisible( const Handle(SALOME_InteractiveObject)& theIO ) { - return myRWInteractor->isVisible( theIO ); + return myView->isVisible( theIO ); +} + +//---------------------------------------------------------------- +void +SVTK_ViewWindow +::Display(const Handle(SALOME_InteractiveObject)& theIO, + bool theImmediatly) +{ + myView->Display(theIO,theImmediatly); +} + +void +SVTK_ViewWindow +::Erase(const Handle(SALOME_InteractiveObject)& theIO, + bool theImmediatly) +{ + myView->Erase(theIO,theImmediatly); +} + +void +SVTK_ViewWindow +::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO) +{ + myView->DisplayOnly(theIO); +} + +void +SVTK_ViewWindow +::DisplayAll() +{ + myView->DisplayAll(); +} + +void +SVTK_ViewWindow +::EraseAll() +{ + myView->EraseAll(); } //---------------------------------------------------------------------------- @@ -612,8 +343,7 @@ void SVTK_ViewWindow ::setBackgroundColor( const QColor& color ) { - if ( myRenderer ) - myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. ); + myMainWindow->SetBackgroundColor( color ); } //---------------------------------------------------------------------------- @@ -621,12 +351,7 @@ QColor SVTK_ViewWindow ::backgroundColor() const { - float backint[3]; - if ( myRenderer ) { - myRenderer->GetBackground( backint ); - return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)); - } - return SUIT_ViewWindow::backgroundColor(); + return myMainWindow->BackgroundColor(); } //---------------------------------------------------------------------------- @@ -634,9 +359,7 @@ void SVTK_ViewWindow ::Repaint(bool theUpdateTrihedron) { - if (theUpdateTrihedron) - onAdjustTrihedron(); - myRenderWindow->update(); + myMainWindow->Repaint( theUpdateTrihedron ); } //---------------------------------------------------------------------------- @@ -644,7 +367,7 @@ void SVTK_ViewWindow ::GetScale( double theScale[3] ) { - myTransform->GetMatrixScale( theScale ); + myMainWindow->GetScale( theScale ); } //---------------------------------------------------------------------------- @@ -652,9 +375,7 @@ void SVTK_ViewWindow ::SetScale( double theScale[3] ) { - myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] ); - myRWInteractor->Render(); - Repaint(); + myMainWindow->SetScale( theScale ); } //---------------------------------------------------------------------------- @@ -662,14 +383,14 @@ bool SVTK_ViewWindow ::isTrihedronDisplayed() { - return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn; + return myMainWindow->IsTrihedronDisplayed(); } bool SVTK_ViewWindow ::isCubeAxesDisplayed() { - return myCubeAxes->GetVisibility() == 1; + return myMainWindow->IsCubeAxesDisplayed(); } //---------------------------------------------------------------------------- @@ -677,80 +398,43 @@ void SVTK_ViewWindow ::onViewTrihedron() { - if(!myTrihedron) - return; - - if(isTrihedronDisplayed()) - myTrihedron->VisibilityOff(); - else - myTrihedron->VisibilityOn(); - - Repaint(); + myMainWindow->onViewTrihedron(); } void SVTK_ViewWindow ::onViewCubeAxes() { - if(!myCubeAxes) - return; - - if(isCubeAxesDisplayed()) - myCubeAxes->VisibilityOff(); - else - myCubeAxes->VisibilityOn(); - - Repaint(); + myMainWindow->onViewCubeAxes(); } //---------------------------------------------------------------------------- -/*bool -SVTK_ViewWindow -::ComputeTrihedronSize( double& theNewSize, double& theSize ) +VTKViewer_Trihedron* +SVTK_ViewWindow:: +GetTrihedron() { - // calculating diagonal of visible props of the renderer - float aBndBox[ 6 ]; - myTrihedron->VisibilityOff(); - - if ( ::ComputeVisiblePropBounds( myRenderer, aBndBox ) == 0 ) { - aBndBox[ 1 ] = aBndBox[ 3 ] = aBndBox[ 5 ] = 100; - aBndBox[ 0 ] = aBndBox[ 2 ] = aBndBox[ 4 ] = 0; - } - - myTrihedron->VisibilityOn(); - float aLength = 0; - static bool aCalcByDiag = false; - if ( aCalcByDiag ) { - aLength = sqrt( ( aBndBox[1]-aBndBox[0])*(aBndBox[1]-aBndBox[0] )+ - ( aBndBox[3]-aBndBox[2])*(aBndBox[3]-aBndBox[2] )+ - ( aBndBox[5]-aBndBox[4])*(aBndBox[5]-aBndBox[4] ) ); - } else { - aLength = aBndBox[ 1 ]-aBndBox[ 0 ]; - aLength = max( ( aBndBox[ 3 ] - aBndBox[ 2 ] ),aLength ); - aLength = max( ( aBndBox[ 5 ] - aBndBox[ 4 ] ),aLength ); - } - - float aSizeInPercents = myTrihedronSize; - - static float EPS_SIZE = 5.0E-3; - theSize = myTrihedron->GetSize(); - theNewSize = aLength * aSizeInPercents / 100.0; + return myMainWindow->GetTrihedron(); +} - // if the new trihedron size have sufficient difference, then apply the value - return fabs( theNewSize - theSize) > theSize * EPS_SIZE || - fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE; -}*/ +SVTK_CubeAxesActor2D* +SVTK_ViewWindow +::GetCubeAxes() +{ + return myMainWindow->GetCubeAxes(); +} -//---------------------------------------------------------------------------- -int SVTK_ViewWindow::GetTrihedronSize() const +int +SVTK_ViewWindow +::GetTrihedronSize() const { - return myTrihedronSize; + return myMainWindow->GetTrihedronSize(); } -void SVTK_ViewWindow::SetTrihedronSize( const int sz ) +void +SVTK_ViewWindow +::SetTrihedronSize(const int theSize) { - myTrihedronSize = sz; - AdjustTrihedrons( true ); + myMainWindow->SetTrihedronSize(theSize); } /*! If parameter theIsForcedUpdate is true, recalculate parameters for @@ -760,81 +444,7 @@ void SVTK_ViewWindow ::AdjustTrihedrons(const bool theIsForcedUpdate) { - if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate) - return; - - float bnd[ 6 ]; - float newbnd[6]; - newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT; - newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT; - - myCubeAxes->GetBounds(bnd); - - int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer ); - - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - bool isRelativeSize = aResMgr->booleanValue( "VTKViewer", "relative_size", true ); - - //if (aVisibleNum || theIsForcedUpdate) { - if (aVisibleNum || !isRelativeSize) { - // if the new trihedron size have sufficient difference, then apply the value - double aNewSize = 100, anOldSize=myTrihedron->GetSize(); - bool aTDisplayed = isTrihedronDisplayed(); - bool aCDisplayed = isCubeAxesDisplayed(); - if(aTDisplayed) myTrihedron->VisibilityOff(); - if(aCDisplayed) myCubeAxes->VisibilityOff(); - - int aDefaultSize = 100; - if (isRelativeSize) aDefaultSize = 105; - int aSizeFromPreferences = aResMgr->integerValue( "VTKViewer", "trihedron_size", aDefaultSize ); - - //bool isComputeTrihedronSize = - if (isRelativeSize) - ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, (float)aSizeFromPreferences); - else - aNewSize = (double)aSizeFromPreferences; - - myTrihedron->SetSize( aNewSize ); - - // iterate through displayed objects and set size if necessary - vtkActorCollection* anActors = getRenderer()->GetActors(); - anActors->InitTraversal(); - while (vtkActor* anActor = anActors->GetNextActor()) - { - if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor )) - { - if (aSActor->IsResizable()) - aSActor->SetSize( 0.5 * aNewSize ); - if (aSActor->GetVisibility() && !aSActor->IsInfinitive()) { - float *abounds = aSActor->GetBounds(); - if (abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT && - abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT && - abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT) - for (int i = 0; i < 5; i = i + 2) { - if (abounds[i] < newbnd[i]) newbnd[i] = abounds[i]; - if (abounds[i+1] > newbnd[i+1]) newbnd[i+1] = abounds[i+1]; - } - } - } - } - if (aTDisplayed) myTrihedron->VisibilityOn(); - if (aCDisplayed) myCubeAxes->VisibilityOn(); - - } else { - double aSize = myTrihedron->GetSize(); - newbnd[0] = newbnd[2] = newbnd[4] = 0; - newbnd[1] = newbnd[3] = newbnd[5] = aSize; - } - - if (newbnd[0] < VTK_LARGE_FLOAT && newbnd[2] < VTK_LARGE_FLOAT && newbnd[4] < VTK_LARGE_FLOAT && - newbnd[1] >-VTK_LARGE_FLOAT && newbnd[3] >-VTK_LARGE_FLOAT && newbnd[5] >-VTK_LARGE_FLOAT) { - for(int i=0;i<6;i++) bnd[i] = newbnd[i]; - myCubeAxes->SetBounds(bnd); - } - - myCubeAxes->SetBounds(bnd); - - ::ResetCameraClippingRange(myRenderer); + myMainWindow->AdjustActors(); } //---------------------------------------------------------------------------- @@ -842,115 +452,14 @@ void SVTK_ViewWindow ::onAdjustTrihedron() { - AdjustTrihedrons( false ); + myMainWindow->onAdjustTrihedron(); } void SVTK_ViewWindow ::onAdjustCubeAxes() { - AdjustTrihedrons(false); -} - -#define INCREMENT_FOR_OP 10 - -//======================================================================= -// name : onPanLeft -// Purpose : Performs incremental panning to the left -//======================================================================= -void -SVTK_ViewWindow -::onPanLeft() -{ - myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 ); -} - -//======================================================================= -// name : onPanRight -// Purpose : Performs incremental panning to the right -//======================================================================= -void -SVTK_ViewWindow -::onPanRight() -{ - myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 ); -} - -//======================================================================= -// name : onPanUp -// Purpose : Performs incremental panning to the top -//======================================================================= -void -SVTK_ViewWindow -::onPanUp() -{ - myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP ); -} - -//======================================================================= -// name : onPanDown -// Purpose : Performs incremental panning to the bottom -//======================================================================= -void -SVTK_ViewWindow -::onPanDown() -{ - myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP ); -} - -//======================================================================= -// name : onZoomIn -// Purpose : Performs incremental zooming in -//======================================================================= -void -SVTK_ViewWindow -::onZoomIn() -{ - myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP ); -} - -//======================================================================= -// name : onZoomOut -// Purpose : Performs incremental zooming out -//======================================================================= -void -SVTK_ViewWindow -::onZoomOut() -{ - myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP ); -} - -//======================================================================= -// name : onRotateLeft -// Purpose : Performs incremental rotating to the left -//======================================================================= -void -SVTK_ViewWindow -::onRotateLeft() -{ - myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 ); -} - -//======================================================================= -// name : onRotateRight -// Purpose : Performs incremental rotating to the right -//======================================================================= -void -SVTK_ViewWindow -::onRotateRight() -{ - myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 ); -} - -//======================================================================= -// name : onRotateUp -// Purpose : Performs incremental rotating to the top -//======================================================================= -void -SVTK_ViewWindow -::onRotateUp() -{ - myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP ); + myMainWindow->onAdjustCubeAxes(); } //======================================================================= @@ -1001,82 +510,90 @@ SVTK_ViewWindow emit mouseDoubleClicked( this, event ); } -//======================================================================= -// name : onRotateDown -// Purpose : Performs incremental rotating to the bottom -//======================================================================= +//---------------------------------------------------------------------------- void SVTK_ViewWindow -::onRotateDown() +::AddActor( VTKViewer_Actor* theActor, + bool theUpdate ) { - myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP ); + myMainWindow->AddActor( theActor, theUpdate ); } //---------------------------------------------------------------------------- void SVTK_ViewWindow -::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors ) +::RemoveActor( VTKViewer_Actor* theActor, + bool theUpdate ) { - theActor->AddToRender(myRenderer); - theActor->SetTransform(myTransform); - if(theMoveInternalActors) - myRWInteractor->MoveInternalActors(); + myMainWindow->RemoveActor( theActor, theUpdate ); } //---------------------------------------------------------------------------- -void +QImage SVTK_ViewWindow -::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ) +::dumpView() { - InsertActor(theActor); - if(theUpdate) - Repaint(); + return myMainWindow->dumpView(); } //---------------------------------------------------------------------------- void SVTK_ViewWindow -::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ) +::SetSelectionProp(const double& theRed, + const double& theGreen, + const double& theBlue, + const int& theWidth) { - theActor->RemoveFromRender(myRenderer); - if(theUpdate) - Repaint(); + myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth); } //---------------------------------------------------------------------------- void SVTK_ViewWindow -::MoveActor( SALOME_Actor* theActor) +::SetPreselectionProp(const double& theRed, + const double& theGreen, + const double& theBlue, + const int& theWidth) { - RemoveActor(theActor); - InsertActor(theActor,true); + myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth); } //---------------------------------------------------------------------------- -QImage +void SVTK_ViewWindow -::dumpView() +::SetSelectionTolerance(const double& theTolNodes, + const double& theTolItems) { - QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() ); - return px.convertToImage(); + myView->SetSelectionTolerance(theTolNodes,theTolItems); +} + +//---------------------------------------------------------------------------- +int convertAction( const int accelAction ) +{ + switch ( accelAction ) { + case SUIT_Accel::PanLeft : return SVTK::PanLeftEvent; + case SUIT_Accel::PanRight : return SVTK::PanRightEvent; + case SUIT_Accel::PanUp : return SVTK::PanUpEvent; + case SUIT_Accel::PanDown : return SVTK::PanDownEvent; + case SUIT_Accel::ZoomIn : return SVTK::ZoomInEvent; + case SUIT_Accel::ZoomOut : return SVTK::ZoomOutEvent; + case SUIT_Accel::RotateLeft : return SVTK::RotateLeftEvent; + case SUIT_Accel::RotateRight : return SVTK::RotateRightEvent; + case SUIT_Accel::RotateUp : return SVTK::RotateUpEvent; + case SUIT_Accel::RotateDown : return SVTK::RotateDownEvent; + } + return accelAction; } //---------------------------------------------------------------------------- void SVTK_ViewWindow -::action( const int theAction ) +::action( const int accelAction ) { - switch ( theAction ) { - case SUIT_Accel::PanLeft : onPanLeft(); break; - case SUIT_Accel::PanRight : onPanRight(); break; - case SUIT_Accel::PanUp : onPanUp(); break; - case SUIT_Accel::PanDown : onPanDown(); break; - case SUIT_Accel::ZoomIn : onZoomIn(); break; - case SUIT_Accel::ZoomOut : onZoomOut(); break; - case SUIT_Accel::ZoomFit : onFitAll(); break; - case SUIT_Accel::RotateLeft : onRotateLeft(); break; - case SUIT_Accel::RotateRight : onRotateRight(); break; - case SUIT_Accel::RotateUp : onRotateUp(); break; - case SUIT_Accel::RotateDown : onRotateDown(); break; - } + if ( accelAction == SUIT_Accel::ZoomFit ) + onFitAll(); + else { + int anEvent = convertAction( accelAction ); + myMainWindow->InvokeEvent( anEvent, 0 ); + } } diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 2aec73b8d..1fc559c78 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -24,132 +24,293 @@ #endif #include "SVTK.h" -#include "SUIT_ViewWindow.h" - #include "SVTK_Selection.h" +#include "SUIT_ViewWindow.h" #include "SALOME_InteractiveObject.hxx" -class vtkRenderer; - -class QtxAction; class SUIT_Desktop; +class VTKViewer_Actor; class VTKViewer_Trihedron; -class VTKViewer_Transform; - -class SALOME_Actor; -class SVTK_Viewer; +class SVTK_ViewModelBase; +class SVTK_MainWindow; class SVTK_Selector; +class SVTK_View; + +class SVTK_InteractorStyle; class SVTK_CubeAxesActor2D; class SVTK_RenderWindow; -class SVTK_InteractorStyle; class SVTK_RenderWindowInteractor; +class vtkRenderer; +class vtkRenderWindow; +class vtkRenderWindowInteractor; + +//! Define a container for SALOME VTK view window class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow { Q_OBJECT; -public: - SVTK_ViewWindow( SUIT_Desktop*, SVTK_Viewer* ); - virtual ~SVTK_ViewWindow(); + public: + //! To construct #SVTK_ViewWindow instance + SVTK_ViewWindow(SUIT_Desktop* theDesktop); + + virtual + ~SVTK_ViewWindow(); - QToolBar* getToolBar() { return myToolBar; } + //! To initialize #SVTK_ViewWindow instance + virtual + void + Initialize(SVTK_ViewModelBase* theModel); + + //! Get #SVTK_View + SVTK_View* + getView(); + + //! Get #SVTK_MainWindow + SVTK_MainWindow* + getMainWindow(); + + //! Redirect the request to #SVTK_MainWindow::getRenderWindow + vtkRenderWindow* + getRenderWindow(); + + //! Redirect the request to #SVTK_MainWindow::getInteractor + vtkRenderWindowInteractor* + getInteractor(); + + //! Redirect the request to #SVTK_MainWindow::getRenderer + vtkRenderer* + getRenderer(); + + //! Redirect the request to #SVTK_MainWindow::GetSelector + SVTK_Selector* + GetSelector(); - void setBackgroundColor( const QColor& ); - QColor backgroundColor() const; - - vtkRenderer* getRenderer() {return myRenderer;} - SVTK_Selector* GetSelector() {return mySelector;} - SVTK_RenderWindow* getRenderWindow() {return myRenderWindow;} - SVTK_RenderWindowInteractor* getRWInteractor() {return myRWInteractor;} - Selection_Mode SelectionMode() const; - void SetSelectionMode(Selection_Mode theMode); - - bool isTrihedronDisplayed(); - bool isCubeAxesDisplayed(); + //! Redirect the request to #SVTK_Selector::SelectionMode + Selection_Mode + SelectionMode() const; + + //! Change selection mode + virtual + void + SetSelectionMode(Selection_Mode theMode); + + //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor + virtual + void + setBackgroundColor( const QColor& ); + + //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor + QColor + backgroundColor() const; + + //! Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed + bool + isTrihedronDisplayed(); + + //! Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed + bool + isCubeAxesDisplayed(); /* interactive object management */ - void highlight( const Handle(SALOME_InteractiveObject)& IObject, - bool highlight, bool immediatly = true ); - void unHighlightAll(); - bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject ); - bool isVisible( const Handle(SALOME_InteractiveObject)& IObject ); + //! Redirect the request to #SVTK_View::highlight (to support old code) + virtual + void + highlight(const Handle(SALOME_InteractiveObject)& theIO, + bool theIsHighlight = true, + bool theIsUpdate = true); + + //! Redirect the request to #SVTK_View::unHighlightAll (to support old code) + virtual + void + unHighlightAll(); + + //! Redirect the request to #SVTK_View::isInViewer (to support old code) + bool + isInViewer(const Handle(SALOME_InteractiveObject)& theIObject); + + //! Redirect the request to #SVTK_View::isVisible (to support old code) + bool + isVisible(const Handle(SALOME_InteractiveObject)& theIObject); /* selection */ - Handle(SALOME_InteractiveObject) FindIObject(const char* Entry); + //---------------------------------------------------------------------------- + Handle(SALOME_InteractiveObject) + FindIObject(const char* theEntry); /* display */ - void Display( const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly = true ); - void DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject ); - void Erase( const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly = true ); - void DisplayAll(); - void EraseAll(); - void Repaint( bool theUpdateTrihedron ); - void Repaint() { Repaint(true); } - - //apply existing transformation on adding SALOME_Actor - void SetScale( double theScale[3] ); - void GetScale( double theScale[3] ); - void AddActor( SALOME_Actor*, bool update = false ); - void RemoveActor(SALOME_Actor*, bool update = false); - - void AdjustTrihedrons( const bool forced ); - //merge with V2_2_0_VISU_improvements:bool ComputeTrihedronSize( double& theNewSize, - //merge with V2_2_0_VISU_improvements: double& theOldSize ); - - int GetTrihedronSize() const; - void SetTrihedronSize( const int ); - - VTKViewer_Trihedron* GetTrihedron() {return this->myTrihedron;}; - SVTK_CubeAxesActor2D* GetCubeAxes() {return this->myCubeAxes;}; - + //---------------------------------------------------------------------------- + //! Redirect the request to #SVTK_View::Display (to support old code) + virtual + void + Display(const Handle(SALOME_InteractiveObject)& theIObject, + bool theImmediatly = true); + + //! Redirect the request to #SVTK_View::DisplayOnly (to support old code) + virtual + void + DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject); + + //! Redirect the request to #SVTK_View::Erase (to support old code) + virtual + void + Erase(const Handle(SALOME_InteractiveObject)& theIObject, + bool theImmediatly = true); + + //! Redirect the request to #SVTK_View::DisplayAll (to support old code) + virtual + void + DisplayAll(); + + //! Redirect the request to #SVTK_View::EraseAll (to support old code) + virtual + void + EraseAll(); + + //! To repaint the viewer + virtual + void + Repaint(bool theUpdateTrihedron = true); + + //---------------------------------------------------------------------------- + //! Redirect the request to #SVTK_Renderer::SetScale + virtual + void + SetScale( double theScale[3] ); + + //! Redirect the request to #SVTK_Renderer::GetScale + virtual + void + GetScale( double theScale[3] ); + + //! Redirect the request to #SVTK_Renderer::AddActor + virtual + void + AddActor(VTKViewer_Actor* theActor, + bool theIsUpdate = false); + + //! Redirect the request to #SVTK_Renderer::RemoveActor + virtual + void + RemoveActor(VTKViewer_Actor* theActor, + bool theIsUpdate = false); + + //---------------------------------------------------------------------------- + //! Redirect the request to #SVTK_Renderer::AdjustActors + virtual + void + AdjustTrihedrons(const bool theIsForced); + + //! Redirect the request to #SVTK_Renderer::GetTrihedron + VTKViewer_Trihedron* + GetTrihedron(); + + //! Redirect the request to #SVTK_Renderer::GetCubeAxes + SVTK_CubeAxesActor2D* + GetCubeAxes(); + + //! Redirect the request to #SVTK_Renderer::GetTrihedronSize + int + GetTrihedronSize() const; + + //! Redirect the request to #SVTK_Renderer::SetTrihedronSize + virtual + void + SetTrihedronSize( const int ); + + //! Redirect the request to #SVTK_Renderer::SetSelectionProp + virtual + void + SetSelectionProp(const double& theRed = 1, + const double& theGreen = 1, + const double& theBlue = 0, + const int& theWidth = 5); + + //! Redirect the request to #SVTK_Renderer::SetPreselectionProp + virtual + void + SetPreselectionProp(const double& theRed = 0, + const double& theGreen = 1, + const double& theBlue = 1, + const int& theWidth = 5); + + //! Redirect the request to #SVTK_Renderer::SetSelectionTolerance + virtual + void + SetSelectionTolerance(const double& theTolNodes = 0.025, + const double& theTolCell = 0.001); + public slots: - void onSelectionChanged(); + virtual + void + onSelectionChanged(); signals: void selectionChanged(); public slots: - void onFrontView(); - void onBackView(); - void onTopView(); - void onBottomView(); - void onRightView(); - void onLeftView(); - - void onResetView(); - void onFitAll(); - - void onViewTrihedron(); - void onViewCubeAxes(); - - void onAdjustTrihedron(); - void onAdjustCubeAxes(); - - void onPanLeft(); - void onPanRight(); - void onPanUp(); - void onPanDown(); - void onZoomIn(); - void onZoomOut(); - void onRotateLeft(); - void onRotateRight(); - void onRotateUp(); - void onRotateDown(); - - void activateZoom(); - void activateWindowFit(); - void activateRotation(); - void activatePanning(); - void activateGlobalPanning(); - -protected: - QImage dumpView(); - virtual void action( const int ); + //! Redirect the request to #SVTK_Renderer::OnFrontView + virtual + void + onFrontView(); + + //! Redirect the request to #SVTK_Renderer::OnBackView + virtual + void + onBackView(); + + //! Redirect the request to #SVTK_Renderer::OnTopView + virtual + void + onTopView(); + + //! Redirect the request to #SVTK_Renderer::OnBottomView + virtual + void + onBottomView(); + + //! Redirect the request to #SVTK_Renderer::OnRightView + virtual + void + onRightView(); + + //! Redirect the request to #SVTK_Renderer::OnLeftView + virtual + void + onLeftView(); + + //! Redirect the request to #SVTK_Renderer::OnResetView + virtual + void + onResetView(); + + //! Redirect the request to #SVTK_Renderer::OnFitAll + virtual + void + onFitAll(); + + //! Redirect the request to #SVTK_Renderer::OnViewTrihedron + virtual + void + onViewTrihedron(); + + //! Redirect the request to #SVTK_Renderer::OnViewCubeAxes + virtual + void + onViewCubeAxes(); + + //! Redirect the request to #SVTK_Renderer::OnAdjustTrihedron + virtual + void + onAdjustTrihedron(); + + //! Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes + virtual + void + onAdjustCubeAxes(); protected slots: void onKeyPressed(QKeyEvent* event); @@ -159,39 +320,18 @@ protected slots: void onMouseReleased(QMouseEvent* event); void onMouseMoving(QMouseEvent* event); -private: - void InitialSetup(); - void InsertActor( SALOME_Actor* theActor, - bool theMoveInternalActors = false ); - void MoveActor( SALOME_Actor* theActor ); - -private: - enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId, - FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, ViewTrihedronId }; - typedef QMap ActionsMap; - - void createActions(); - void createToolBar(); - - vtkRenderer* myRenderer; - - SVTK_Viewer* myModel; - SVTK_Selector* mySelector; - - SVTK_RenderWindow* myRenderWindow; - SVTK_RenderWindowInteractor* myRWInteractor; +protected: + virtual + void + Initialize(SVTK_View* theView, + SVTK_ViewModelBase* theModel); - VTKViewer_Transform* myTransform; - VTKViewer_Trihedron* myTrihedron; - int myTrihedronSize; - SVTK_CubeAxesActor2D* myCubeAxes; - - QToolBar* myToolBar; - ActionsMap myActionsMap; - - double myCurScale; + QImage dumpView(); + virtual void action( const int ); - friend class SVTK_RenderWindowInteractor; + SVTK_View* myView; + SVTK_MainWindow* myMainWindow; + SVTK_ViewModelBase* myModel; }; #ifdef WIN32 diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 690b13b52..5139ce4f2 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -122,7 +122,7 @@ void SalomeApp_Application::createActions() //! Registry Display createAction( RegDisplayId, tr( "TOT_DESK_REGISTRY_DISPLAY" ), QIconSet(), tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ), - SHIFT+Key_D, desk, false, this, SLOT( onRegDisplay() ) ); + /*SHIFT+Key_D*/0, desk, false, this, SLOT( onRegDisplay() ) ); int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 ); @@ -743,9 +743,6 @@ void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* t 3. update object browser if it existing */ void SalomeApp_Application::updateObjectBrowser( const bool updateModels ) { - // update existing data models (already loaded SComponents) - LightApp_Application::updateObjectBrowser(updateModels); - // update "non-existing" (not loaded yet) data models SalomeApp_Study* study = dynamic_cast(activeStudy()); if ( study ) @@ -760,16 +757,24 @@ void SalomeApp_Application::updateObjectBrowser( const bool updateModels ) if ( aComponent->ComponentDataType() == "Interface Applicative" ) continue; // skip the magic "Interface Applicative" component - SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true ); + OB_Browser* ob = static_cast( getWindow( WT_ObjectBrowser )); + const bool isAutoUpdate = ob->isAutoUpdate(); + ob->setAutoUpdate( false ); + SalomeApp_DataModel::synchronize( aComponent, study ); + ob->setAutoUpdate( isAutoUpdate ); + //SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true ); } } } - if ( objectBrowser() ) + // update existing data models (already loaded SComponents) + LightApp_Application::updateObjectBrowser( updateModels ); + +/* if ( objectBrowser() ) { objectBrowser()->updateGeometry(); - objectBrowser()->updateTree( 0, false ); - } + objectBrowser()->updateTree(); + }*/ } /*!Display Catalog Genenerator dialog */ diff --git a/src/SalomeApp/SalomeApp_DataModel.cxx b/src/SalomeApp/SalomeApp_DataModel.cxx index 48838709e..5fcae7b7b 100644 --- a/src/SalomeApp/SalomeApp_DataModel.cxx +++ b/src/SalomeApp/SalomeApp_DataModel.cxx @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include "SALOMEDS_Tool.hxx" @@ -24,67 +26,151 @@ #include CORBA_SERVER_HEADER(SALOME_Exception) //======================================================================= -// name : BuildTree -/*!Purpose : static method used by SalomeApp_Study and SalomeApp_DataModel classes - * to create default SALOMEDS-based data object tree - */ +// name : SalomeApp_DataModelSync +/*!Purpose : Auxiliary class for synchronizing tree of kernel objects and SUIT_DataObjects */ //======================================================================= -SUIT_DataObject* SalomeApp_DataModel::BuildTree( const _PTR(SObject)& obj, - SUIT_DataObject* parent, - SalomeApp_Study* study, - bool skip ) + +typedef _PTR(SObject) kerPtr; +typedef SUIT_DataObject* suitPtr; + +class SalomeApp_DataModelSync { - SalomeApp_DataObject* aDataObj = 0; - if ( !obj || !study ) - return aDataObj; +public: + SalomeApp_DataModelSync( _PTR( Study ), SUIT_DataObject* ); - _PTR(SObject) refObj; - if ( obj->GetName().size() || obj->ReferencedObject( refObj ) ) // skip nameless non references SObjects - { - _PTR(SComponent) aSComp( obj ); + suitPtr createItem( const kerPtr&, const suitPtr&, const suitPtr&, const bool ) const; + void deleteItemWithChildren( const suitPtr& ) const; + bool isEqual( const kerPtr&, const suitPtr& ) const; + kerPtr nullSrc() const; + suitPtr nullTrg() const; + void children( const kerPtr&, QValueList& ) const; + void children( const suitPtr&, QValueList& ) const; + suitPtr parent( const suitPtr& ) const; + bool isCorrect( const kerPtr& ) const; + void updateItem( const suitPtr& ) const; + +private: + _PTR( Study ) myStudy; + SUIT_DataObject* myRoot; +}; + + +SalomeApp_DataModelSync::SalomeApp_DataModelSync( _PTR( Study ) aStudy, SUIT_DataObject* aRoot ) +: myStudy( aStudy ), + myRoot( aRoot ) +{ +} + +bool SalomeApp_DataModelSync::isCorrect( const kerPtr& so ) const +{ + kerPtr refObj; + QString name = so->GetName(); + bool res = so && ( so->GetName().size() || so->ReferencedObject( refObj ) ); + return res; +} - // patch for bug IPAL9313 - if ( aSComp && parent && skip ) +suitPtr SalomeApp_DataModelSync::createItem( const kerPtr& so, + const suitPtr& parent, + const suitPtr& after, + const bool asFirst ) const +{ + if( !isCorrect( so ) ) + return 0; + + _PTR(SComponent) aSComp( so ); + suitPtr nitem = aSComp ? new SalomeApp_ModuleObject( aSComp, 0 ) : + new SalomeApp_DataObject( so, 0 ); + if( parent ) + if( after ) { - QString aSName( aSComp->GetName().c_str() ); - DataObjectList allComponents = parent->children( /*recursive=*/false ); - for ( DataObjectListIterator it( allComponents ); it.current(); ++it ) { - SUIT_DataObject* componentObj = it.current(); - if ( componentObj->name() == aSName ) { - // mkr : modifications for update of already published in - // object browser, but not loaded yet components - LightApp_Application* anApp = dynamic_cast - (SUIT_Session::session()->activeApplication() ); - // asv : corresponding DataObjects are DELETED before update (so they are re-built). - if (anApp && !anApp->module(aSName)) { // if module is not loaded, delete it's DataObject - // jfa: remove children before DataObject deletion - DataObjectList chilren = componentObj->children(/*recursive=*/true); - for (DataObjectListIterator itc (chilren); itc.current(); ++itc) - componentObj->removeChild(itc.current()); - - // delete DataObject itself and re-create it and all its sub-objects - delete componentObj; - // don't do anything here, because iterator may be corrupted (deleted object inside it) - break; // proceed to build_a_data_object code below - } - else - return componentObj; - } - } + DataObjectList ch; + parent->children( ch ); + int pos = ch.find( after ); + if( pos>=0 ) + parent->insertChild( nitem, pos+1 ); + else + parent->appendChild( nitem ); } + else if( asFirst ) + parent->insertChild( nitem, 0 ); + else + parent->appendChild( nitem ); + else if( myRoot ) + myRoot->appendChild( nitem ); + return nitem; +} - aDataObj = aSComp ? new SalomeApp_ModuleObject( aSComp, parent ) : - new SalomeApp_DataObject ( obj, parent ); +void SalomeApp_DataModelSync::deleteItemWithChildren( const suitPtr& p ) const +{ + if( !p ) + return; - _PTR(ChildIterator) it ( study->studyDS()->NewChildIterator( obj ) ); - for ( ; it->More(); it->Next() ) { - // don't use shared_ptr here, for Data Object will take - // ownership of this pointer - _PTR(SObject) aSO( it->Value() ); - BuildTree( aSO, aDataObj, study ); - } + DataObjectList ch; + p->children( ch ); + DataObjectList::const_iterator anIt = ch.begin(), aLast = ch.end(); + for( ; anIt!=aLast; anIt++ ) + deleteItemWithChildren( *anIt ); + delete p; +} + +bool SalomeApp_DataModelSync::isEqual( const kerPtr& p, const suitPtr& q ) const +{ + LightApp_DataObject* obj = dynamic_cast( q ); + return ( !p && !q ) || ( obj && isCorrect( p ) && p->GetID()==obj->entry() ); +} + +kerPtr SalomeApp_DataModelSync::nullSrc() const +{ + return kerPtr(); +} + +suitPtr SalomeApp_DataModelSync::nullTrg() const +{ + return suitPtr( 0 ); +} + +void SalomeApp_DataModelSync::children( const kerPtr& obj, QValueList& ch ) const +{ + ch.clear(); + _PTR(ChildIterator) it ( myStudy->NewChildIterator( obj ) ); + for( ; it->More(); it->Next() ) + ch.append( it->Value() ); +} + +void SalomeApp_DataModelSync::children( const suitPtr& p, QValueList& ch ) const +{ + DataObjectList l; + if( p ) + { + p->children( l ); + ch.clear(); + for( SUIT_DataObject* o = l.first(); o; o = l.next() ) + ch.append( o ); + } +} + +suitPtr SalomeApp_DataModelSync::parent( const suitPtr& p ) const +{ + return p ? p->parent(): 0; +} + +void SalomeApp_DataModelSync::updateItem( const suitPtr& ) const +{ +} + +void showTree( SUIT_DataObject* root ) +{ + qDebug( root ? "" : "" ); + if( !root ) + return; + + SUIT_DataObjectIterator it( root, SUIT_DataObjectIterator::DepthLeft ); + for( ; it.current(); ++it ) + { + QString marg; marg.fill( ' ', 3*it.depth() ); + QString nnn = "%1 '%2'"; + qDebug( nnn.arg( marg ).arg( it.current()->name() ) ); } - return aDataObj; } //======================================================================= @@ -121,13 +207,23 @@ bool SalomeApp_DataModel::open( const QString& name, CAM_Study* study, QStringLi _PTR(Study) aStudy ( aDoc->studyDS() ); // shared_ptr cannot be used here _PTR(SComponent) aSComp ( aStudy->FindComponentID( std::string( anId.latin1() ) ) ); if ( aSComp ) - buildTree( aSComp, 0, aDoc ); + updateTree( aSComp, aDoc ); QStringList listOfFiles; LightApp_DataModel::open(name, study, listOfFiles); return true; } +//================================================================ +// Function : create +/*! Purpose : Create data model*/ +//================================================================ +bool SalomeApp_DataModel::create( CAM_Study* theStudy ) +{ + update(NULL, (LightApp_Study*)theStudy); + return true; +} + //================================================================ // Function : update /*! Purpose : Update application.*/ @@ -136,7 +232,7 @@ void SalomeApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study ) { SalomeApp_Study* aSStudy = dynamic_cast(study); LightApp_RootObject* studyRoot = 0; - _PTR(SObject) sobj; + _PTR(SComponent) sobj; SalomeApp_DataObject* modelRoot = dynamic_cast( root() ); if ( !modelRoot ){ // not yet connected to a study -> try using argument if ( !aSStudy ) @@ -161,26 +257,73 @@ void SalomeApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study ) } } } - buildTree( sobj, studyRoot, aSStudy ); + if ( sobj && aSStudy ) + updateTree( sobj, aSStudy ); } //================================================================ -// Function : buildTree -/*! Purpose : private method, build tree.*/ +// Function : synchronize +/*! Purpose : synchronizes kernel tree and suit data tree starting from component 'sobj' */ //================================================================ -void SalomeApp_DataModel::buildTree( const _PTR(SObject)& obj, - SUIT_DataObject* parent, - SalomeApp_Study* study ) +SUIT_DataObject* SalomeApp_DataModel::synchronize( const _PTR( SComponent )& sobj, SalomeApp_Study* study ) { - if ( !obj ) - return; - //if ( !root() ){ // Build default SALOMEDS-based data object tree and insert it into study - SalomeApp_ModuleObject* aNewRoot = dynamic_cast( BuildTree( obj, parent, study ) ); - if ( aNewRoot ){ - aNewRoot->setDataModel( this ); - setRoot( aNewRoot ); + if( !study || !study->root() || !sobj ) + return 0; + + DataObjectList ch; study->root()->children( ch ); + DataObjectList::const_iterator anIt = ch.begin(), aLast = ch.end(); + SalomeApp_DataObject* suitObj = 0; + for( ; anIt!=aLast; anIt++ ) + { + SalomeApp_DataObject* dobj = dynamic_cast( *anIt ); + if( dobj && dobj->name()==sobj->GetName().c_str() ) + { + suitObj = dobj; + break; } - //} + } + + SalomeApp_DataModelSync sync( study->studyDS(), study->root() ); + + // QString srcName = sobj ? sobj->GetName().c_str() : ""; + // QString trgName = ( suitObj && !suitObj->name().isNull() ) ? suitObj->name() : ""; + // printf( "--- SalomeApp_DataModel::syncronize() calls synchronize()_1: src = %s, trg = %s ---\n", srcName.latin1(), trgName.latin1() ); + + SUIT_DataObject* o = ::synchronize( sobj, suitObj, sync ); +// showTree( o ); + return o; +} + +//================================================================ +// Function : synchronize +/*! Purpose : synchronizes kernel tree and suit data tree starting from 'sobj' and 'obj' correspondly */ +//================================================================ +SUIT_DataObject* SalomeApp_DataModel::synchronize( const _PTR( SObject )& sobj, SUIT_DataObject* obj, + SalomeApp_Study* study ) +{ + if( !study ) + return 0; + SalomeApp_DataModelSync sync( study->studyDS(), study->root() ); + + // QString srcName = sobj ? sobj->GetName().c_str() : ""; + // QString trgName = ( obj && !obj->name().isNull() ) ? obj->name() : ""; + // printf( "--- SalomeApp_DataModel::syncronize() calls synchronize()_2: src = s, trg = %s ---\n", srcName.latin1(), trgName.latin1() ); + + return ::synchronize( sobj, obj, sync ); +} + +//================================================================ +// Function : updateTree +/*! Purpose : updates tree.*/ +//================================================================ +void SalomeApp_DataModel::updateTree( const _PTR( SComponent )& comp, SalomeApp_Study* study ) +{ + SalomeApp_ModuleObject* aNewRoot = dynamic_cast( synchronize( comp, study ) ); + if( aNewRoot ) + { + aNewRoot->setDataModel( this ); + setRoot( aNewRoot ); + } } //================================================================ diff --git a/src/SalomeApp/SalomeApp_DataModel.h b/src/SalomeApp/SalomeApp_DataModel.h index 4dab54d9b..62e649bc3 100644 --- a/src/SalomeApp/SalomeApp_DataModel.h +++ b/src/SalomeApp/SalomeApp_DataModel.h @@ -26,15 +26,14 @@ class SALOMEAPP_EXPORT SalomeApp_DataModel : public LightApp_DataModel Q_OBJECT public: - static SUIT_DataObject* BuildTree(const _PTR(SObject)& obj, - SUIT_DataObject* parent, - SalomeApp_Study* study, - bool skip = false ); + static SUIT_DataObject* synchronize( const _PTR( SComponent )&, SalomeApp_Study* ); + static SUIT_DataObject* synchronize( const _PTR( SObject )&, SUIT_DataObject*, SalomeApp_Study* ); SalomeApp_DataModel ( CAM_Module* theModule ); virtual ~SalomeApp_DataModel(); virtual bool open( const QString&, CAM_Study*, QStringList ); + virtual bool create( CAM_Study* ); virtual void update( LightApp_DataObject* = 0, LightApp_Study* = 0 ); QString getRootEntry( SalomeApp_Study* ) const; @@ -42,8 +41,8 @@ public: protected: SalomeApp_Study* getStudy() const; - - virtual void buildTree(const _PTR(SObject)&, SUIT_DataObject*, SalomeApp_Study* ); + virtual void updateTree( const _PTR( SComponent )&, SalomeApp_Study* ); }; + #endif diff --git a/src/SalomeApp/SalomeApp_DataObject.cxx b/src/SalomeApp/SalomeApp_DataObject.cxx index 938754e92..ef7b8df7b 100644 --- a/src/SalomeApp/SalomeApp_DataObject.cxx +++ b/src/SalomeApp/SalomeApp_DataObject.cxx @@ -111,8 +111,8 @@ QPixmap SalomeApp_DataObject::icon() const QString pixmapName = QObject::tr( aPixAttr->GetPixMap().c_str() ); LightApp_RootObject* aRoot = dynamic_cast( root() ); if ( aRoot && aRoot->study() ) { - QPixmap pixmap = aRoot->study()->application()->resourceMgr()->loadPixmap( componentDataType(), pixmapName, false ); - return pixmap; + SUIT_ResourceMgr* mgr = aRoot->study()->application()->resourceMgr(); + return mgr->loadPixmap( componentDataType(), pixmapName, false ); } } } diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 3073e544e..f3de08660 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -195,12 +195,13 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName ) return false; bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ), - isAscii = resMgr->booleanValue( "Study", "ascii_file", false ); - isAscii ? SalomeApp_Application::studyMgr()->SaveAsASCII( theFileName.latin1(), studyDS(), isMultiFile ) : - SalomeApp_Application::studyMgr()->SaveAs ( theFileName.latin1(), studyDS(), isMultiFile ); + isAscii = resMgr->booleanValue( "Study", "ascii_file", false ), + res = isAscii ? + SalomeApp_Application::studyMgr()->SaveAsASCII( theFileName.latin1(), studyDS(), isMultiFile ) : + SalomeApp_Application::studyMgr()->SaveAs ( theFileName.latin1(), studyDS(), isMultiFile ) && + CAM_Study::saveDocumentAs( theFileName ) && //SRN: BugID IPAL9377, removed usage of uninitialized variable + saveStudyData(theFileName); - bool res = CAM_Study::saveDocumentAs( theFileName ); //SRN: BugID IPAL9377, removed usage of uninitialized variable - res = res && saveStudyData(theFileName); if ( res ) emit saved( this ); @@ -230,11 +231,10 @@ bool SalomeApp_Study::saveDocument() return false; bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ), - isAscii = resMgr->booleanValue( "Study", "ascii_file", false ); - isAscii ? SalomeApp_Application::studyMgr()->SaveASCII( studyDS(), isMultiFile ) : - SalomeApp_Application::studyMgr()->Save ( studyDS(), isMultiFile ); - - bool res = CAM_Study::saveDocument(); + isAscii = resMgr->booleanValue( "Study", "ascii_file", false ), + res = isAscii ? + SalomeApp_Application::studyMgr()->SaveASCII( studyDS(), isMultiFile ) : + SalomeApp_Application::studyMgr()->Save ( studyDS(), isMultiFile ) && CAM_Study::saveDocument(); res = res && saveStudyData(studyName()); if ( res ) @@ -396,7 +396,8 @@ void SalomeApp_Study::addComponent(const CAM_DataModel* dm) } // Set default engine IOR aBuilder->DefineComponentInstance(aComp, SalomeApp_Application::defaultEngineIOR().latin1()); - SalomeApp_DataModel::BuildTree( aComp, root(), this, /*skipExisitng=*/true ); + //SalomeApp_DataModel::BuildTree( aComp, root(), this, /*skipExisitng=*/true ); + SalomeApp_DataModel::synchronize( aComp, this ); } } } diff --git a/src/SalomeApp/resources/SalomeApp.xml b/src/SalomeApp/resources/SalomeApp.xml index ffdee1fd9..4c290584a 100644 --- a/src/SalomeApp/resources/SalomeApp.xml +++ b/src/SalomeApp/resources/SalomeApp.xml @@ -17,14 +17,14 @@ - +
- +
@@ -48,6 +48,7 @@ + @@ -152,8 +153,8 @@ - - + + @@ -203,6 +204,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/Style/SalomeStyle.cxx b/src/Style/SalomeStyle.cxx index bcdc6f1ac..8126eb8ec 100644 --- a/src/Style/SalomeStyle.cxx +++ b/src/Style/SalomeStyle.cxx @@ -422,33 +422,33 @@ void SalomeStyle::drawPrimitive( PrimitiveElement pe, QPainter* p, const QRect& drawGradient( p, rr, act ? cg.highlight() : cg.dark(), col, horiz ? LeftToRight : UpToDown, linear ); - - QRect rt = rr; - if ( flags & Style_Horizontal ) - rt.addCoords( 0, 20, 0, 0 ); - else - rt.addCoords( 0, 0, -20, 0 ); - - int textW = flags & Style_Horizontal ? rt.height() : rt.width(); - int textH = flags & Style_Horizontal ? rt.width() : rt.height(); - - QString title = titleText( wnd->caption(), textW, p->fontMetrics() ); - - if ( wnd ) - { - QColorGroup cgroup = wnd->isActiveWindow() ? wnd->palette().active() : wnd->palette().inactive(); - p->setPen( cgroup.highlightedText() ); - - if ( flags & Style_Horizontal ) - { - p->rotate( 270.0 ); - p->translate( -(rt.height()+rt.y()), (rt.width()-rt.x()) ); - p->drawText( 0, 0, title ); - } - else - p->drawText( 2, 2, textW, textH, AlignLeft, title ); - } - } + + QRect rt = rr; + if ( flags & Style_Horizontal ) + rt.addCoords( 0, 20, 0, 0 ); + else + rt.addCoords( 0, 0, -20, 0 ); + + int textW = flags & Style_Horizontal ? rt.height() : rt.width(); + int textH = flags & Style_Horizontal ? rt.width() : rt.height(); + + QString title = titleText( wnd->caption(), textW, p->fontMetrics() ); + + if ( wnd ) + { + QColorGroup cgroup = wnd->isActiveWindow() ? wnd->palette().active() : wnd->palette().inactive(); + p->setPen( cgroup.highlightedText() ); + + if ( flags & Style_Horizontal ) + { + p->rotate( 270.0 ); + p->translate( -(rt.height()+rt.y()), (rt.width()-rt.x()) ); + p->drawText( 0, 0, title ); + } + else + p->drawText( 2, 2, textW, textH, AlignLeft, title ); + } + } break; } @@ -1013,10 +1013,10 @@ void SalomeStyle::drawControl( ControlElement element, QPainter* p, const QWidge r2.setRect( r2.left(), r2.top(), r2.width() - 2, r2.height() - 1 ); p->setPen( cg.foreground() ); - drawGradient( p, QRect( r2.left(), r2.top(), r2.width(), r2.height() - 1 ), - selected ? cg.highlight() : cg.dark(), cg.background(), UpToDown, linear ); + drawGradient( p, QRect( r2.left(), r2.top(), r2.width(), r2.height() - 1 ), + selected ? cg.highlight() : cg.dark(), cg.background(), UpToDown, linear ); -// p->fillRect( r2.left(), r2.top(), r2.width(), r2.height() - 1, selected ? cg.highlight() : cg.background() ); +// p->fillRect( r2.left(), r2.top(), r2.width(), r2.height() - 1, selected ? cg.highlight() : cg.background() ); p->drawRect( r2.left(), r2.top(), r2.width(), r2.height() - 1 ); if ( selected ) @@ -1028,15 +1028,15 @@ void SalomeStyle::drawControl( ControlElement element, QPainter* p, const QWidge break; } - - case CE_TabBarLabel: - { - QColorGroup tmp( cg ); - if ( flags & Style_Selected ) - tmp.setColor( QColorGroup::Foreground, tmp.highlightedText() ); - PARENT_STYLE::drawControl( element, p, widget, r, tmp, flags, opt ); - } - break; + + case CE_TabBarLabel: + { + QColorGroup tmp( cg ); + if ( flags & Style_Selected ) + tmp.setColor( QColorGroup::Foreground, tmp.highlightedText() ); + PARENT_STYLE::drawControl( element, p, widget, r, tmp, flags, opt ); + } + break; case CE_PushButton: { diff --git a/src/VTKViewer/Makefile.in b/src/VTKViewer/Makefile.in index 4c72c0d5c..dd5f7ea29 100755 --- a/src/VTKViewer/Makefile.in +++ b/src/VTKViewer/Makefile.in @@ -18,6 +18,7 @@ EXPORT_HEADERS= VTKViewer_Actor.h \ VTKViewer_ConvexTool.h \ VTKViewer_Filter.h \ VTKViewer_GeometryFilter.h \ + VTKViewer_AppendFilter.h \ VTKViewer_Algorithm.h \ VTKViewer.h \ VTKViewer_InteractorStyle.h \ @@ -36,9 +37,12 @@ EXPORT_HEADERS= VTKViewer_Actor.h \ VTKViewer_ViewWindow.h \ VTKViewer_Functor.h -PO_FILES = VTKViewer_images.po \ - VTKViewer_msg_en.po - +PO_FILES = \ + VTKViewer_images.po \ + VTKViewer_msg_en.po \ + VTKViewerM_images.po \ + VTKViewerM_msg_en.po + # Libraries targets LIB = libVTKViewer.la @@ -47,6 +51,7 @@ LIB_SRC= VTKViewer_Actor.cxx \ VTKViewer_ExtractUnstructuredGrid.cxx \ VTKViewer_Filter.cxx \ VTKViewer_GeometryFilter.cxx \ + VTKViewer_AppendFilter.cxx \ VTKViewer_InteractorStyle.cxx \ VTKViewer_PassThroughFilter.cxx \ VTKViewer_RectPicker.cxx \ @@ -62,7 +67,6 @@ LIB_SRC= VTKViewer_Actor.cxx \ VTKViewer_ViewModel.cxx \ VTKViewer_ConvexTool.cxx \ VTKViewer_ViewWindow.cxx - LIB_MOC = \ VTKViewer_RenderWindow.h \ @@ -70,28 +74,13 @@ LIB_MOC = \ VTKViewer_ViewManager.h \ VTKViewer_ViewModel.h \ VTKViewer_ViewWindow.h - -RESOURCES_FILES = \ - view_back.png \ - view_bottom.png \ - view_camera_dump.png \ - view_fitall.png \ - view_fitarea.png \ - view_front.png \ - view_glpan.png \ - view_left.png \ - view_pan.png \ - view_reset.png \ - view_right.png \ - view_rotate.png \ - view_top.png \ - view_triedre.png \ - view_zoom.png -CPPFLAGS+=$(QT_INCLUDES) $(VTK_INCLUDES) $(OCC_INCLUDES) +BIN = VTKViewer -LDFLAGS+=$(VTK_LIBS) $(QT_MT_LIBS) $(CAS_KERNEL) -lsuit +CPPFLAGS+=$(QT_INCLUDES) $(VTK_INCLUDES) $(OCC_INCLUDES) -@CONCLUDE@ +LDFLAGS+=$(VTK_LIBS) $(QT_MT_LIBS) $(CAS_KERNEL) +LDFLAGSFORBIN=$(LDFLAGS) -lqtx -lsuit +@CONCLUDE@ \ No newline at end of file diff --git a/src/VTKViewer/VTKViewer.cxx b/src/VTKViewer/VTKViewer.cxx new file mode 100644 index 000000000..9755466c0 --- /dev/null +++ b/src/VTKViewer/VTKViewer.cxx @@ -0,0 +1,57 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ + +#include "VTKViewer_Actor.h" +#include "VTKViewer_CellRectPicker.h" +#include "VTKViewer_ExtractUnstructuredGrid.h" +#include "VTKViewer_ConvexTool.h" +#include "VTKViewer_Filter.h" +#include "VTKViewer_GeometryFilter.h" +#include "VTKViewer_AppendFilter.h" +#include "VTKViewer_Algorithm.h" +#include "VTKViewer_InteractorStyle.h" +#include "VTKViewer_PassThroughFilter.h" +#include "VTKViewer_RectPicker.h" +#include "VTKViewer_RenderWindow.h" +#include "VTKViewer_RenderWindowInteractor.h" +#include "VTKViewer_ShrinkFilter.h" +#include "VTKViewer_TransformFilter.h" +#include "VTKViewer_Transform.h" +#include "VTKViewer_Trihedron.h" +#include "VTKViewer_Utilities.h" +#include "VTKViewer_VectorText.h" +#include "VTKViewer_ViewManager.h" +#include "VTKViewer_ViewModel.h" +#include "VTKViewer_ViewWindow.h" +#include "VTKViewer_Functor.h" + +int +main(int argc, char** argv) +{ + return 0; +} diff --git a/src/VTKViewer/VTKViewer_Actor.cxx b/src/VTKViewer/VTKViewer_Actor.cxx index 7b9e00353..da05fc98d 100755 --- a/src/VTKViewer/VTKViewer_Actor.cxx +++ b/src/VTKViewer/VTKViewer_Actor.cxx @@ -1,134 +1,167 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers +// +// Copyright (C) 2003 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 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. // -// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org // -// 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/ // +// File : SALOME_Actor.cxx +// Author : Nicolas REJNERI +// Module : SALOME +// $Header$ + +/*! + \class SALOME_Actor SALOME_Actor.h + \brief Abstract class of SALOME Objects in VTK. +*/ + + #include "VTKViewer_Actor.h" + #include "VTKViewer_Transform.h" -#include "VTKViewer_GeometryFilter.h" #include "VTKViewer_TransformFilter.h" #include "VTKViewer_PassThroughFilter.h" +#include "VTKViewer_GeometryFilter.h" // VTK Includes +#include +#include #include #include #include +#include #include -#include -#include -#include +using namespace std; -/* -static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet){ - vtkPoints *aPoints = vtkPoints::New(); - vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints(); - aPoints->SetNumberOfPoints(iEnd); - for(vtkIdType i = 0; i < iEnd; i++){ - aPoints->SetPoint(i,theSourceDataSet->GetPoint(i)); - } - theGrid->SetPoints(aPoints); - aPoints->Delete(); -} -*/ +#if defined __GNUC__ + #if __GNUC__ == 2 + #define __GNUC_2__ + #endif +#endif +int VTKViewer_POINT_SIZE = 5; +int VTKViewer_LINE_WIDTH = 3; +//---------------------------------------------------------------------------- vtkStandardNewMacro(VTKViewer_Actor); -/*!Constructor.Initialize default parameters.*/ -VTKViewer_Actor::VTKViewer_Actor(){ - myIsHighlighted = myIsPreselected = false; - - myRepresentation = 1; - myDisplayMode = myRepresentation - 1; - - myProperty = vtkProperty::New(); - PreviewProperty = NULL; - - myIsInfinite = false; - myIsResolveCoincidentTopology = true; - +//---------------------------------------------------------------------------- +VTKViewer_Actor +::VTKViewer_Actor(): + myIsHighlighted(false), + myIsPreselected(false), + myRepresentation(VTK_SURFACE), + myDisplayMode(1), + myProperty(vtkProperty::New()), + PreviewProperty(NULL), + myIsInfinite(false), + myIsResolveCoincidentTopology(true), + myStoreMapping(false), + myGeomFilter(VTKViewer_GeometryFilter::New()), + myTransformFilter(VTKViewer_TransformFilter::New()) +{ vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, myPolygonOffsetUnits); - myStoreMapping = false; - myGeomFilter = VTKViewer_GeometryFilter::New(); - - myTransformFilter = VTKViewer_TransformFilter::New(); for(int i = 0; i < 6; i++) myPassFilter.push_back(VTKViewer_PassThroughFilter::New()); - - Visibility = Pickable = true; } -/*!Destructor.*/ -VTKViewer_Actor::~VTKViewer_Actor(){ +//---------------------------------------------------------------------------- +VTKViewer_Actor +::~VTKViewer_Actor() +{ SetPreviewProperty(NULL); - myGeomFilter->UnRegisterAllOutputs(); myGeomFilter->Delete(); - myTransformFilter->UnRegisterAllOutputs(); myTransformFilter->Delete(); - for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){ - if(myPassFilter[i]){ - myPassFilter[i]->UnRegisterAllOutputs(); + for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++) + if(myPassFilter[i]) myPassFilter[i]->Delete(); - } - } + myProperty->Delete(); } -/*!Add VTKViewer_Actor to renderer. - *\param theRenderer - vtkRenderer - */ -void VTKViewer_Actor::AddToRender(vtkRenderer* theRenderer){ + +//---------------------------------------------------------------------------- +const char* +VTKViewer_Actor +::getName() +{ + return myName.c_str(); +} + +void +VTKViewer_Actor +::setName(const char* theName) +{ + myName = theName; +} + + +//---------------------------------------------------------------------------- +void +VTKViewer_Actor +::AddToRender(vtkRenderer* theRenderer) +{ theRenderer->AddActor(this); } -/*!Remove VTKViewer_Actor from renderer. - *\param theRenderer - vtkRenderer - */ -void VTKViewer_Actor::RemoveFromRender(vtkRenderer* theRenderer){ +void +VTKViewer_Actor +::RemoveFromRender(vtkRenderer* theRenderer) +{ theRenderer->RemoveActor(this); } -/*!Add transformation to transform filter. - *\param theTransform - transformation. - */ -void VTKViewer_Actor::SetTransform(VTKViewer_Transform* theTransform){ +void +VTKViewer_Actor +::GetChildActors(vtkActorCollection*) +{} + + +//---------------------------------------------------------------------------- +void +VTKViewer_Actor +::SetTransform(VTKViewer_Transform* theTransform) +{ myTransformFilter->SetTransform(theTransform); } -/*!Set mapper to pipeline.\n - *Call method for pipeline initialization. - *\param theMapper - mapper - */ -void VTKViewer_Actor::SetMapper(vtkMapper* theMapper){ + +void +VTKViewer_Actor +::SetMapper(vtkMapper* theMapper) +{ InitPipeLine(theMapper); } -/*!Initialize sequence of filters for mapper, if \a theMapper is not null. - *\param theMapper - mapper - */ -void VTKViewer_Actor::InitPipeLine(vtkMapper* theMapper){ +void +VTKViewer_Actor +::InitPipeLine(vtkMapper* theMapper) +{ if(theMapper){ int anId = 0; myPassFilter[ anId ]->SetInput( theMapper->GetInput() ); @@ -156,11 +189,15 @@ void VTKViewer_Actor::InitPipeLine(vtkMapper* theMapper){ aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput()); } } - vtkLODActor::SetMapper(theMapper); + Superclass::SetMapper(theMapper); } -/*!*/ -void VTKViewer_Actor::Render(vtkRenderer *ren, vtkMapper* m){ + +//---------------------------------------------------------------------------- +void +VTKViewer_Actor +::Render(vtkRenderer *ren, vtkMapper* m) +{ if(myIsResolveCoincidentTopology){ int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology(); float aFactor, aUnit; @@ -169,52 +206,86 @@ void VTKViewer_Actor::Render(vtkRenderer *ren, vtkMapper* m){ vtkMapper::SetResolveCoincidentTopologyToPolygonOffset(); vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, myPolygonOffsetUnits); - vtkLODActor::Render(ren,m); + Superclass::Render(ren,m); vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology); }else{ - vtkLODActor::Render(ren,m); + Superclass::Render(ren,m); } } -/*!Set flag myIsResolveCoincidentTopology to \a theIsResolve. - *\param theIsResolve - bool flag. - */ -void VTKViewer_Actor::SetResolveCoincidentTopology(bool theIsResolve) { + +void +VTKViewer_Actor +::SetResolveCoincidentTopology(bool theIsResolve) +{ myIsResolveCoincidentTopology = theIsResolve; } -/*!Sets polygon offset factor and polygon offset units. - *\param factor - float factor - *\param units - float units - */ -void VTKViewer_Actor::SetPolygonOffsetParameters(float factor, float units){ +void +VTKViewer_Actor +::SetPolygonOffsetParameters(float factor, float units) +{ myPolygonOffsetFactor = factor; myPolygonOffsetUnits = units; } -/*!Gets polygon offset factor and polygon offset units. - *\param factor - output float - *\param units - output float - */ -void VTKViewer_Actor::GetPolygonOffsetParameters(float& factor, float& units){ +void +VTKViewer_Actor +::GetPolygonOffsetParameters(float& factor, float& units) +{ factor = myPolygonOffsetFactor; units = myPolygonOffsetUnits; } -/*!Get input data set. - *\retval vtkDataSet pointer. - */ -vtkDataSet* VTKViewer_Actor::GetInput(){ +//---------------------------------------------------------------------------- +float +VTKViewer_Actor +::GetShrinkFactor() +{ + return 1.0; +} + +bool +VTKViewer_Actor +::IsShrunkable() +{ + return false; +} + +bool +VTKViewer_Actor +::IsShrunk() +{ + return false; +} + +void +VTKViewer_Actor +::SetShrink() +{} + +void +VTKViewer_Actor +::UnShrink() +{} + + +//---------------------------------------------------------------------------- +vtkDataSet* +VTKViewer_Actor +::GetInput() +{ return myPassFilter.front()->GetOutput(); } -/*!Get modification time. - *\retval time - unsigned long. - */ -unsigned long int VTKViewer_Actor::GetMTime(){ + +unsigned long int +VTKViewer_Actor +::GetMTime() +{ unsigned long mTime = this->Superclass::GetMTime(); unsigned long time = myTransformFilter->GetMTime(); mTime = ( time > mTime ? time : mTime ); @@ -225,10 +296,12 @@ unsigned long int VTKViewer_Actor::GetMTime(){ return mTime; } -/*!Set representation mode. - *\param theMode - int. - */ -void VTKViewer_Actor::SetRepresentation(int theMode) { + +//---------------------------------------------------------------------------- +void +VTKViewer_Actor +::SetRepresentation(int theMode) +{ switch(myRepresentation){ case VTK_POINTS : case VTK_SURFACE : @@ -240,7 +313,6 @@ void VTKViewer_Actor::SetRepresentation(int theMode) { GetProperty()->DeepCopy(myProperty); break; default: - break; GetProperty()->SetAmbient(1.0); GetProperty()->SetDiffuse(0.0); GetProperty()->SetSpecular(0.0); @@ -248,93 +320,175 @@ void VTKViewer_Actor::SetRepresentation(int theMode) { switch(theMode){ case 3 : myGeomFilter->SetInside(true); - GetProperty()->SetRepresentation(1); + myGeomFilter->SetWireframeMode(true); + GetProperty()->SetRepresentation(VTK_WIREFRAME); break; case VTK_POINTS : GetProperty()->SetPointSize(VTKViewer_POINT_SIZE); - default : GetProperty()->SetRepresentation(theMode); + myGeomFilter->SetWireframeMode(false); + myGeomFilter->SetInside(false); + break; + case VTK_WIREFRAME : + GetProperty()->SetRepresentation(theMode); + myGeomFilter->SetWireframeMode(true); myGeomFilter->SetInside(false); + break; + case VTK_SURFACE : + GetProperty()->SetRepresentation(theMode); + myGeomFilter->SetWireframeMode(false); + myGeomFilter->SetInside(false); + break; } myRepresentation = theMode; } -/*!Get representation. - *\retval representation mode. - */ -int VTKViewer_Actor::GetRepresentation(){ +int +VTKViewer_Actor +::GetRepresentation() +{ return myRepresentation; } -/*!Get VTK cell by object ID. - *\param theObjID - object ID. - *\retval vtkCell pointer. - */ -vtkCell* VTKViewer_Actor::GetElemCell(int theObjID){ - return GetInput()->GetCell(theObjID); + +//---------------------------------------------------------------------------- +int +VTKViewer_Actor +::GetNodeObjId(int theVtkID) +{ + return theVtkID; } -/*!Get node coordinates by node ID. - *\param theObjID - node ID. - *\retval float array of coordinates. - * \li array[0] - X coordinate. - * \li array[1] - Y coordinate. - * \li array[2] - Z coordinate. - */ -float* VTKViewer_Actor::GetNodeCoord(int theObjID){ +float* +VTKViewer_Actor +::GetNodeCoord(int theObjID) +{ return GetInput()->GetPoint(theObjID); } +vtkCell* +VTKViewer_Actor +::GetElemCell(int theObjID) +{ + return GetInput()->GetCell(theObjID); +} + +int +VTKViewer_Actor +::GetElemObjId(int theVtkID) +{ + return theVtkID; +} + //================================================================================= // function : GetObjDimension -/*! purpose : Return object dimension.\n - * Virtual method shoulb be redifined by derived classes - *\param theObjId - object ID. - */ +// purpose : Return object dimension. +// Virtual method shoulb be redifined by derived classes //================================================================================= -int VTKViewer_Actor::GetObjDimension( const int theObjId ) +int +VTKViewer_Actor +::GetObjDimension( const int theObjId ) { if ( vtkCell* aCell = GetElemCell(theObjId) ) return aCell->GetCellDimension(); return 0; } -/*!Get infinite flag*/ -bool VTKViewer_Actor::IsInfinitive(){ + +void +VTKViewer_Actor +::SetInfinitive(bool theIsInfinite) +{ + myIsInfinite = theIsInfinite; +} + + +bool +VTKViewer_Actor +::IsInfinitive() +{ return myIsInfinite; } -/*!Set property - opacity. - *\param theOpacity - new apacity - */ -void VTKViewer_Actor::SetOpacity(float theOpacity){ + +float* +VTKViewer_Actor +::GetBounds() +{ + return Superclass::GetBounds(); +} + + +void +VTKViewer_Actor +::GetBounds(float theBounds[6]) +{ + Superclass::GetBounds(theBounds); +} + + +//---------------------------------------------------------------------------- +bool +VTKViewer_Actor +::IsSetCamera() const +{ + return false; +} + +bool +VTKViewer_Actor +::IsResizable() const +{ + return false; +} + +void +VTKViewer_Actor +::SetSize( const float ) +{} + + +void +VTKViewer_Actor +::SetCamera( vtkCamera* ) +{} + +//---------------------------------------------------------------------------- +void +VTKViewer_Actor +::SetOpacity(float theOpacity) +{ myOpacity = theOpacity; GetProperty()->SetOpacity(theOpacity); } -/*!Get property - opacity. - *\retval float value. - */ -float VTKViewer_Actor::GetOpacity(){ +float +VTKViewer_Actor +::GetOpacity() +{ return myOpacity; } -/*!Set property - color - *\param r - float Red value - *\param g - float Green value - *\param b - float Blue value - */ -void VTKViewer_Actor::SetColor(float r,float g,float b){ + +void +VTKViewer_Actor +::SetColor(float r,float g,float b) +{ GetProperty()->SetColor(r,g,b); } -/*!Get property - color - *\param r - output float Red value - *\param g - output float Green value - *\param b - output float Blue value - */ -void VTKViewer_Actor::GetColor(float& r,float& g,float& b){ +void +VTKViewer_Actor +::SetColor(const float theRGB[3]) +{ + SetColor(theRGB[0],theRGB[1],theRGB[2]); +} + +void +VTKViewer_Actor +::GetColor(float& r,float& g,float& b) +{ float aColor[3]; GetProperty()->GetColor(aColor); r = aColor[0]; @@ -342,18 +496,53 @@ void VTKViewer_Actor::GetColor(float& r,float& g,float& b){ b = aColor[2]; } -/*!Get display mode. - *\retval int value - */ -int VTKViewer_Actor::getDisplayMode(){ + +//---------------------------------------------------------------------------- +int +VTKViewer_Actor +::getDisplayMode() +{ return myDisplayMode; } -/*!Set display mode - *\param theMode - integer value. - */ -void VTKViewer_Actor::setDisplayMode(int theMode){ - SetRepresentation(theMode+1); +void +VTKViewer_Actor +::setDisplayMode(int theMode) +{ + SetRepresentation(theMode + 1); myDisplayMode = GetRepresentation() - 1; } + +//---------------------------------------------------------------------------- +bool +VTKViewer_Actor +::hasHighlight() +{ + return false; +} + +bool +VTKViewer_Actor +::isHighlighted() +{ + return myIsHighlighted; +} + +void +VTKViewer_Actor +::SetPreSelected(bool thePreselect) +{ + myIsPreselected = thePreselect; +} + + +//---------------------------------------------------------------- +void +VTKViewer_Actor +::highlight(bool theIsHighlight) +{ + myIsHighlighted = theIsHighlight; +} + +vtkCxxSetObjectMacro(VTKViewer_Actor,PreviewProperty,vtkProperty); diff --git a/src/VTKViewer/VTKViewer_Actor.h b/src/VTKViewer/VTKViewer_Actor.h index 2a4371200..55711a8c0 100755 --- a/src/VTKViewer/VTKViewer_Actor.h +++ b/src/VTKViewer/VTKViewer_Actor.h @@ -1,164 +1,327 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers +// +// Copyright (C) 2003 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. // -// 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. +// 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 // -// 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. +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org // -// 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/ // +// File : SALOME_Actor.h +// Author : Nicolas REJNERI +// Module : SALOME +// $Header$ + #ifndef VTKVIEVER_ACTOR_H #define VTKVIEVER_ACTOR_H #include "VTKViewer.h" -#include -#include -#include -#include -#include - +#include #include +#include + class vtkCell; +class vtkPointPicker; +class vtkCellPicker; class vtkDataSet; -class vtkPolyData; +class vtkCamera; +class vtkProperty; +class vtkRenderer; class VTKViewer_Transform; class VTKViewer_GeometryFilter; class VTKViewer_TransformFilter; class VTKViewer_PassThroughFilter; -#define VTKViewer_POINT_SIZE 3 +extern int VTKViewer_POINT_SIZE; +extern int VTKViewer_LINE_WIDTH; + /*! \class vtkLODActor * \brief For more information see VTK documentation */ -class VTKVIEWER_EXPORT VTKViewer_Actor : public vtkLODActor +class VTKVIEWER_EXPORT VTKViewer_Actor : public vtkLODActor { -public: - /*!Create new instance of actor.*/ + public: static VTKViewer_Actor* New(); - - vtkTypeMacro( VTKViewer_Actor, vtkLODActor ); - - /*!Get name of the actor*/ - virtual const char* getName() { return myName.c_str(); } - /*!Set name of the actor*/ - virtual void setName(const char* theName){ myName = theName;} - - //! To generate highlight automaticaly - virtual bool hasHighlight() { return false; } - //! Sets highlight. - virtual void highlight(bool theHighlight) { myIsHighlighted = theHighlight; } - //! Check highlight. - virtual bool isHighlighted() { return myIsHighlighted; } - virtual void SetOpacity(float theOpacity); - virtual float GetOpacity(); - - virtual void SetColor(float r,float g,float b); - virtual void GetColor(float& r,float& g,float& b); - void SetColor(const float theRGB[3]){ SetColor(theRGB[0],theRGB[1],theRGB[2]); } - - vtkSetObjectMacro(PreviewProperty,vtkProperty); - - virtual void SetPreSelected(bool thePreselect = false) { myIsPreselected = thePreselect;} - - //! Used to obtain all dependent actors - virtual void GetChildActors(vtkActorCollection*) {}; - - virtual void AddToRender(vtkRenderer* theRenderer); - virtual void RemoveFromRender(vtkRenderer* theRenderer); - - - /** @name For selection mapping purpose */ - //@{ - virtual int GetNodeObjId(int theVtkID) { return theVtkID;} - virtual float* GetNodeCoord(int theObjID); - - virtual int GetElemObjId(int theVtkID) { return theVtkID;} - virtual vtkCell* GetElemCell(int theObjID); - //@} - - virtual int GetObjDimension( const int theObjId ); - - virtual void SetMapper(vtkMapper* theMapper); - virtual vtkDataSet* GetInput(); - - virtual void SetTransform(VTKViewer_Transform* theTransform); - virtual unsigned long int GetMTime(); - - virtual void SetRepresentation(int theMode); - virtual int GetRepresentation(); - - virtual int getDisplayMode(); - virtual void setDisplayMode(int theMode); - - /*! Infinitive means actor without size (point for example), \n - * which is not taken into account in calculation of boundaries of the scene - */ - void SetInfinitive(bool theIsInfinite) { myIsInfinite = theIsInfinite; } - virtual bool IsInfinitive(); + vtkTypeMacro(VTKViewer_Actor,vtkLODActor); + + //---------------------------------------------------------------------------- + //! Get its name + virtual + const char* + getName(); + + //! Name the #VTKViewer_Actor + virtual + void + setName(const char* theName); + + //---------------------------------------------------------------------------- + //! Change opacity + virtual + void + SetOpacity(float theOpacity); + + //! Get current opacity + virtual + float + GetOpacity(); + + //! Change color + virtual + void + SetColor(float r,float g,float b); + + //! Get current color + virtual + void + GetColor(float& r,float& g,float& b); + + //! Change color + virtual + void + SetColor(const float theRGB[3]); + + //---------------------------------------------------------------------------- + // For selection mapping purpose + //! Maps VTK index of a node to corresponding object index + virtual + int + GetNodeObjId(int theVtkID); + + //! Get coordinates of a node for given object index + virtual + float* + GetNodeCoord(int theObjID); + + //! Maps VTK index of a cell to corresponding object index + virtual + int + GetElemObjId(int theVtkID); + + //! Get corresponding #vtkCell for given object index + virtual + vtkCell* + GetElemCell(int theObjID); + + //---------------------------------------------------------------------------- + //! Get dimension of corresponding mesh element + virtual + int + GetObjDimension( const int theObjId ); + + //! To insert some additional filters and then sets the given #vtkMapper + virtual + void + SetMapper(vtkMapper* theMapper); + + //! Allows to get initial #vtkDataSet + virtual + vtkDataSet* + GetInput(); + + //! Apply view transformation + virtual + void + SetTransform(VTKViewer_Transform* theTransform); + + //! To calculatate last modified time + virtual + unsigned long int + GetMTime(); + + //---------------------------------------------------------------------------- + //! Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on) + virtual + void + SetRepresentation(int theMode); + + //! Get current representation mode + virtual + int + GetRepresentation(); + + //! Get current display mode (obsolete) + virtual + int + getDisplayMode(); + + //! Set display mode (obsolete) + virtual + void + setDisplayMode(int theMode); + + //---------------------------------------------------------------------------- + //! Set infinive flag + /*! + Infinitive means actor without size (point for example), + which is not taken into account in calculation of boundaries of the scene + */ + void + SetInfinitive(bool theIsInfinite); + + //! Get infinive flag + virtual + bool + IsInfinitive(); - void SetResolveCoincidentTopology(bool theIsResolve); - void SetPolygonOffsetParameters(float factor, float units); - void GetPolygonOffsetParameters(float& factor, float& units); - - virtual void Render(vtkRenderer *, vtkMapper *); + //! To calcualte current bounding box + virtual + float* + GetBounds(); + + //! To calcualte current bounding box + void + GetBounds(float bounds[6]); + + //---------------------------------------------------------------------------- + virtual + bool + IsSetCamera() const; + + virtual + bool + IsResizable() const; + + virtual + void + SetSize( const float ); + + virtual + void + SetCamera( vtkCamera* ); + + //---------------------------------------------------------------------------- + //! Set ResolveCoincidentTopology flag + void + SetResolveCoincidentTopology(bool theIsResolve); + + //! Set ResolveCoincidentTopology parameters + void + SetPolygonOffsetParameters(float factor, float units); + + //! Get current ResolveCoincidentTopology parameters + void + GetPolygonOffsetParameters(float& factor, float& units); + + virtual + void + Render(vtkRenderer *, vtkMapper *); + + //---------------------------------------------------------------------------- + //! Get current shrink factor + virtual + float + GetShrinkFactor(); + + //! Is the actor is shrunkable + virtual + bool + IsShrunkable(); + + //! Is the actor is shrunk + virtual + bool + IsShrunk(); + + //! Insert shrink filter into pipeline + virtual + void + SetShrink(); + + //! Remove shrink filter from pipeline + virtual + void + UnShrink(); + + //---------------------------------------------------------------------------- + //! To publish the actor an all its internal devices + virtual + void + AddToRender(vtkRenderer* theRendere); + + //! To remove the actor an all its internal devices + virtual + void + RemoveFromRender(vtkRenderer* theRendere); -protected: - /*!resolve coincedent topology flag*/ + //! Used to obtain all dependent actors + virtual + void + GetChildActors(vtkActorCollection*); + + //---------------------------------------------------------------------------- + //! Ask, if the descendant of the VTKViewer_Actor will implement its own highlight or not + virtual + bool + hasHighlight(); + + //! Ask, if the VTKViewer_Actor is already highlighted + virtual + bool + isHighlighted(); + + //! Set preselection mode + virtual + void + SetPreSelected(bool thePreselect = false); + + //---------------------------------------------------------------------------- + //! Just to update visibility of the highlight devices + virtual + void + highlight(bool theHighlight); + + void + SetPreviewProperty(vtkProperty* theProperty); + + protected: + //---------------------------------------------------------------------------- bool myIsResolveCoincidentTopology; - /*!polygon offset factor*/ float myPolygonOffsetFactor; - /*!polygon offset units*/ float myPolygonOffsetUnits; - /*!Actor name.*/ std::string myName; - /*!preview property*/ - vtkProperty *PreviewProperty; - /*!preselected flag*/ - bool myIsPreselected; - - /*!opacity*/ float myOpacity; - /*!highlighted flag*/ - bool myIsHighlighted; - /*!display mode*/ int myDisplayMode; - /*!infinite flag*/ bool myIsInfinite; - /*!store mapping flag*/ bool myStoreMapping; - /*!geometry filter*/ VTKViewer_GeometryFilter *myGeomFilter; - /*!transform filter*/ VTKViewer_TransformFilter *myTransformFilter; - /*!vector of passive filters(siz filters used)*/ std::vector myPassFilter; - /*!presentation mode*/ int myRepresentation; - /*!property*/ vtkProperty *myProperty; - //! Main method, which calculate output. - void InitPipeLine(vtkMapper* theMapper); + void + InitPipeLine(vtkMapper* theMapper); VTKViewer_Actor(); ~VTKViewer_Actor(); + + protected: + vtkProperty *PreviewProperty; + bool myIsPreselected; + bool myIsHighlighted; }; -#endif +#endif // VTKVIEVER_ACTOR_H diff --git a/src/VTKViewer/VTKViewer_AppendFilter.cxx b/src/VTKViewer/VTKViewer_AppendFilter.cxx new file mode 100644 index 000000000..dce05c44e --- /dev/null +++ b/src/VTKViewer/VTKViewer_AppendFilter.cxx @@ -0,0 +1,363 @@ +// SALOME OBJECT : kernel of SALOME component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VTKViewer_GeometryFilter.cxx +// Author : +// Module : SALOME +// $Header$ + +#include "VTKViewer_AppendFilter.h" + +#include "VTKViewer_ConvexTool.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +using namespace std; + + +#ifdef _DEBUG_ +//static int MYDEBUG = 0; +//static int MYDEBUGWITHFILES = 0; +#else +//static int MYDEBUG = 0; +//static int MYDEBUGWITHFILES = 0; +#endif + +#if defined __GNUC__ + #if __GNUC__ == 2 + #define __GNUC_2__ + #endif +#endif + +vtkCxxRevisionMacro(VTKViewer_AppendFilter, "$Revision$"); +vtkStandardNewMacro(VTKViewer_AppendFilter); + +VTKViewer_AppendFilter +::VTKViewer_AppendFilter() +{ + myDoMappingFlag=false; +} + +VTKViewer_AppendFilter +::~VTKViewer_AppendFilter() +{} + +void +VTKViewer_AppendFilter +::SetDoMappingFlag(const bool theFlag) +{ + myDoMappingFlag=theFlag; +} + +bool +VTKViewer_AppendFilter +::DoMappingFlag() const +{ + return myDoMappingFlag; +} + +void +VTKViewer_AppendFilter +::SetPoints(vtkPoints* thePoints) +{ + myPoints = thePoints; +} + +vtkPoints* +VTKViewer_AppendFilter +::GetPoints() +{ + return myPoints.GetPointer(); +} + +void +VTKViewer_AppendFilter +::Execute() +{ + if (myPoints.GetPointer()) { + MakeOutput(); + } + else { + vtkAppendFilter::Execute(); + } + if (myDoMappingFlag){ + DoMapping(); + } +} + +void +VTKViewer_AppendFilter +::Reset() +{ + myNodeIds.clear(); + myCellIds.clear(); + myNodeRanges.clear(); + myCellRanges.clear(); + myNodeMapObjIDVtkID.clear(); + myCellMapObjIDVtkID.clear(); +} +//================================================================== +// function: DoMapping +// purpose : +//================================================================== +void +VTKViewer_AppendFilter +::DoMapping() +{ + int i, j, i1, i2, iNodeCnt, iCellCnt; + IteratorOfDataMapOfIntegerInteger aMapIt; + vtkIdType aNbPnts, aNbCells, aId; + vtkDataSet *pDS; + // + Reset(); + // + iNodeCnt=0; + iCellCnt=0; + for (i=0; iGetNumberOfPoints(); + i1=myNodeIds.size(); + i2=i1+aNbPnts-1; + myNodeRanges.push_back(i1); + myNodeRanges.push_back(i2); + // + for(j=0; jGetNumberOfCells(); + i1=myCellIds.size(); + i2=i1+aNbCells-1; + myCellRanges.push_back(i1); + myCellRanges.push_back(i2); + for(j=0; j=aNb) { + return aRetID; + } + // + aRetID=(int)myNodeIds[theOutputID]; + // + aNbRanges=myNodeRanges.size()/2; + for (i=0; i=i1 && theOutputID<=i2) { + theInputDataSetID=i; + } + } + // + return aRetID; +} + + +//--------------------------------------------------------------- +vtkIdType +VTKViewer_AppendFilter +::GetCellInputID(vtkIdType theOutputID, + vtkIdType& theInputDataSetID) +{ + int aNb, aNbRanges, aRetID, i, i1, i2, j; + // + aRetID=-1; + theInputDataSetID=-1; + // + aNb=myCellIds.size(); + if (theOutputID<0 || theOutputID>=aNb) { + return aRetID; + } + // + aRetID=(int)myCellIds[theOutputID]; + // + aNbRanges=myCellRanges.size()/2; + for (i=0; i=i1 && theOutputID<=i2) { + theInputDataSetID=i; + } + } + // + return aRetID; +} + + +//--------------------------------------------------------------- +void +VTKViewer_AppendFilter +::MakeOutput() +{ + int idx; + vtkIdType numPts, numCells, newCellId, cellId; + vtkCellData *cd; + vtkIdList *ptIds; + vtkDataSet *ds; + vtkUnstructuredGrid *output = this->GetOutput(); + // + numPts = myPoints->GetNumberOfPoints(); + if (numPts < 1) { + return; + } + // + numCells = 0; + for (idx = 0; idx < this->NumberOfInputs; ++idx) { + ds = (vtkDataSet *)(this->Inputs[idx]); + if (ds != NULL) { + if ( ds->GetNumberOfPoints() <= 0 && ds->GetNumberOfCells() <= 0 ) { + continue; //no input, just skip + } + numCells += ds->GetNumberOfCells(); + }//if non-empty dataset + }//for all inputs + if (numCells < 1) { + return; + } + // + // Now can allocate memory + output->Allocate(numCells); + ptIds = vtkIdList::New(); + ptIds->Allocate(VTK_CELL_SIZE); + // + // Append each input dataset together + // + // 1.points + output->SetPoints(myPoints.GetPointer()); + // 2.cells + for (idx = 0; idx < this->NumberOfInputs; ++idx) { + ds = (vtkDataSet *)(this->Inputs[idx]); + if (ds != NULL) { + numCells = ds->GetNumberOfCells(); + cd = ds->GetCellData(); + // copy cell and cell data + for (cellId=0; cellIdGetCellPoints(cellId, ptIds); + newCellId = output->InsertNextCell(ds->GetCellType(cellId), ptIds); + } + } + } + // + ptIds->Delete(); +} + diff --git a/src/VTKViewer/VTKViewer_AppendFilter.h b/src/VTKViewer/VTKViewer_AppendFilter.h new file mode 100644 index 000000000..f9c6b245a --- /dev/null +++ b/src/VTKViewer/VTKViewer_AppendFilter.h @@ -0,0 +1,91 @@ +#ifndef VTKVIEWER_APPENDFILTER_H +#define VTKVIEWER_APPENDFILTER_H + +#include "VTKViewer.h" + +#include +#include + +#include +#include + +class vtkPoints; + +/*! \brief This class used same as vtkAppendFilter. See documentation on VTK for more information. + */ +class VTKVIEWER_EXPORT VTKViewer_AppendFilter : public vtkAppendFilter +{ +public: + /*! \fn static VTKViewer_AppendFilter *New() + */ + static VTKViewer_AppendFilter *New(); + + /*! \fn vtkTypeRevisionMacro(VTKViewer_AppendFilter, vtkAppendFilter) + * \brief VTK type revision macros. + */ + vtkTypeRevisionMacro(VTKViewer_AppendFilter, vtkAppendFilter); + + void SetDoMappingFlag(const bool theFlag); + + bool DoMappingFlag() const; + + void + SetPoints(vtkPoints* thePoints); + + vtkPoints* + GetPoints(); + + vtkIdType + GetPointOutputID(vtkIdType theInputID); + + vtkIdType + GetCellOutputID(vtkIdType theInputID); + + vtkIdType + GetPointInputID(vtkIdType theOutputID, + vtkIdType& theInputDataSetID); + + vtkIdType + GetCellInputID(vtkIdType theOutputID, + vtkIdType& theInputDataSetID); + +protected: + /*! \fn VTKViewer_AppendFilter(); + * \brief Constructor + */ + VTKViewer_AppendFilter(); + /*! \fn ~VTKViewer_AppendFilter(); + * \brief Destructor. + */ + ~VTKViewer_AppendFilter(); + /*! \fn void Execute(); + * \brief Filter culculation method. + */ + virtual void Execute(); + // + void DoMapping(); + + void Reset(); + + void MakeOutput(); + + // + vtkSmartPointer myPoints; + +private: + typedef std::vector TVectorId; + typedef std::vector VectorInt; + typedef std::map DataMapOfIntegerInteger; + typedef DataMapOfIntegerInteger::iterator IteratorOfDataMapOfIntegerInteger; + typedef DataMapOfIntegerInteger::value_type PairOfDataMapOfIntegerInteger; +private: + bool myDoMappingFlag; + TVectorId myNodeIds; + TVectorId myCellIds; + VectorInt myNodeRanges; + VectorInt myCellRanges; + DataMapOfIntegerInteger myNodeMapObjIDVtkID; + DataMapOfIntegerInteger myCellMapObjIDVtkID; +}; + +#endif diff --git a/src/VTKViewer/VTKViewer_ConvexTool.cxx b/src/VTKViewer/VTKViewer_ConvexTool.cxx index 1bb641de8..679e48428 100644 --- a/src/VTKViewer/VTKViewer_ConvexTool.cxx +++ b/src/VTKViewer/VTKViewer_ConvexTool.cxx @@ -32,45 +32,66 @@ #include #include #include +#include #include +#include #include #include #include #include +typedef vtkUnstructuredGrid TInput; + typedef std::set TUIDS; // unique ids typedef std::map TPTOIDS; // id points -> unique ids namespace CONVEX_TOOL { + // all pairs + typedef std::pair TPair; + typedef std::set TSet; + + void + WriteToFile(vtkUnstructuredGrid* theDataSet, const std::string& theFileName) + { + vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New(); + aWriter->SetFileName(theFileName.c_str()); + aWriter->SetInput(theDataSet); + aWriter->Write(); + aWriter->Delete(); + } static float FACE_ANGLE_TOLERANCE=1.5; +#define EPS 1.0e-38 +#define EPS_T 1.0e-3 #ifdef _DEBUG_ static int MYDEBUG = 0; + static int MYDEBUG_REMOVE = 0; #else static int MYDEBUG = 0; + static int MYDEBUG_REMOVE = 0; #endif -/*! \fn static void GetCenter(vtkUnstructuredGrid* theGrid,TCell theptIds,float *center) +/*! \fn static void GetCenter(TInput* theGrid,TCell theptIds,float *center) * \brief Calculation of geometry center. - * \param theGrid - vtkUnstructuredGrid cell. + * \param theGrid - TInput cell. * \param theptIds - point ids. * \retval center - output array[3] with coordinates of geometry center. */ -static void GetCenter(vtkUnstructuredGrid* theGrid,TCell theptIds,float center[3]) +static void GetCenter(vtkPoints* thePoints,float center[3]) { float p[3]; center[0] = center[1] = center[2] = 0.0; - int numIds = theptIds.size(); - if (numIds == 0) return; + int numPts = thePoints->GetNumberOfPoints(); + if (numPts == 0) return; // get the center of the cell - for (int i = 0; i < numIds; i++) + for (int i = 0; i < numPts; i++) { - theGrid->GetPoint(theptIds[i], p); + thePoints->GetPoint(i, p); for (int j = 0; j < 3; j++) { center[j] += p[j]; @@ -78,7 +99,7 @@ static void GetCenter(vtkUnstructuredGrid* theGrid,TCell theptIds,float center[3 } for (int j = 0; j < 3; j++) { - center[j] /= numIds; + center[j] /= numPts; } } @@ -154,16 +175,16 @@ void GetFriends(const TPTOIDS p2faces,const TCellArray f2points,TPTOIDS& face2fa } } -/*! \fn bool IsConnectedFacesOnOnePlane( vtkUnstructuredGrid* theGrid,vtkIdType theFId1, vtkIdType theFId2,TUIDS FpIds1, TUIDS FpIds2 ) +/*! \fn bool IsConnectedFacesOnOnePlane( TInput* theGrid,vtkIdType theFId1, vtkIdType theFId2,TUIDS FpIds1, TUIDS FpIds2 ) * \brief Check is connected faces on one plane. - * \param theGrid - vtkUnstructuredGrid + * \param theGrid - TInput * \param theFId1 - id of first face * \param theFId2 - id of second face * \param FpIds1 - first face points ids. * \param FpIds2 - second face points ids. * \return TRUE if two faces on one plane, else FALSE. */ -bool IsConnectedFacesOnOnePlane( vtkUnstructuredGrid* theGrid, +bool IsConnectedFacesOnOnePlane( TInput* theGrid, vtkIdType theFId1, vtkIdType theFId2, TUIDS FpIds1, TUIDS FpIds2 ) { @@ -252,7 +273,7 @@ bool IsConnectedFacesOnOnePlane( vtkUnstructuredGrid* theGrid, } cout << p[k][2] << ") "; } - cout << "angle="<GetPoint(current_points_ids[0],P[0]); + points->GetPoint(current_points_ids[1],P[1]); + TUIDS::iterator aPointsIter = input_points_ids.begin(); + for(;aPointsIter!=input_points_ids.end();aPointsIter++){ + if(iscurrent_points_changed){ + points->GetPoint(current_points_ids[0],P[0]); + points->GetPoint(current_points_ids[1],P[1]); + iscurrent_points_changed = false; + if (MYDEBUG_REMOVE) + cout << " " << current_points_ids[0] << " " << current_points_ids[1] << endl; + } + // check: is point on line input_two_points_ids + points->GetPoint(*aPointsIter,P[2]); + if (MYDEBUG_REMOVE) { + cout << "\t" << current_points_ids[0] << ":"< coeff[0][0] = (x-x1), coeff[0][1] = x2-x1 + // y-y1=(y2-y1)*t -> coeff[1][0] = (y-y1), coeff[1][1] = y2-y1 + // z-z1=(z2-z1)*t -> coeff[2][0] = (z-z1), coeff[2][1] = z2-z1 + float coeff[3][2]; + for(int i=0;i<3;i++){ + coeff[i][0] = P[2][i]-P[0][i]; + coeff[i][1] = P[1][i]-P[0][i]; + } + bool isok_coord[3]; + bool isok = true; + float t[3]; + for(int i=0;i<3;i++){ + isok_coord[i] = false; + if( fabs(coeff[i][0]) <= EPS && fabs(coeff[i][1]) <= EPS) { + isok_coord[i] = true; + continue; + } + if( fabs(coeff[i][1]) <= EPS && fabs(coeff[i][0]) > EPS) {isok = false;t[i]=1.0/EPS;break;} + t[i] = (coeff[i][0])/(coeff[i][1]); + } + for(int i=0;i<3;i++) + if (MYDEBUG_REMOVE) + cout << __LINE__ << " " + << coeff[i][0] << ","<t[0],t[1],t[2] + // anilize bounds of line + for(int i=0;i<3;i++){ + for(int j=0;j<3;j++) + if(!isok_coord[j]) param[i] = (P[i][j]-P[0][j])/(P[1][j]-P[0][j]); + } + if (MYDEBUG_REMOVE) cout << "Params: " << param[0] << "," << param[1] << "," << param[2] << endl; + vtkIdType imax,imin; + float min,max; + for(vtkIdType i=0;i<3;i++) + if(!isok_coord[i]){ + min = param[0];imin=0; + max = param[0];imax=0; + break; + } + for(vtkIdType i=0;i<3;i++){ + if(min > param[i]) {min = param[i]; imin=i;} + if(max < param[i]) {max = param[i]; imax=i;} + } + if (MYDEBUG_REMOVE) + cout << "\t min="<"< RemoveAllUnneededPoints(vtkConvexPointSet* convex){ + vtkSmartPointer out = vtkConvexPointSet::New(); + + TUIDS two_points,input_points,out_two_points_ids,removed_points_ids,loc_removed_points_ids; + vtkIdList* aPointIds = convex->GetPointIds(); + int numIds = aPointIds->GetNumberOfIds(); + if (numIds<2) return out; + TSet good_point_ids; + TSet aLists[numIds-2]; + for(int i=0;iGetId(aFirId) << "," << aSecId <<":"<GetId(aSecId)<< " --- "; + for(vtkIdType k=aSecId+1;kGetId(k) << ","; + } + if (MYDEBUG_REMOVE) { + cout << endl; + cout << "\t"; + for(TUIDS::iterator aDelIter = loc_removed_points_ids.begin();aDelIter!=loc_removed_points_ids.end();aDelIter++) + cout << *aDelIter<<","; + cout << endl; + } + GetAndRemoveIdsOnOneLine(convex->Points, + input_points, + two_points, + out_two_points_ids, + loc_removed_points_ids); + TUIDS::iterator aOutIter = out_two_points_ids.begin(); + vtkIdType aFirst=*aOutIter;aOutIter++;vtkIdType aSecond=*aOutIter; + TPair aPair(aFirst,aSecond); + good_point_ids.insert(aPair); + if (MYDEBUG_REMOVE){ + cout << "Output: "; + TUIDS::iterator aIter = out_two_points_ids.begin(); + for(;aIter!=out_two_points_ids.end();aIter++) + cout << *aIter << ","; + cout << " --- "; + } + TUIDS::iterator aDelIter = loc_removed_points_ids.begin(); + for(;aDelIter!=loc_removed_points_ids.end();aDelIter++){ + removed_points_ids.insert(*aDelIter); + if (MYDEBUG_REMOVE) cout << *aDelIter << ","; + } + if (MYDEBUG_REMOVE) cout << endl; + } + } + if (MYDEBUG_REMOVE) { + cout << "============ Resultat ================" <Points->SetNumberOfPoints(result_ids.size()); + out->PointIds->SetNumberOfIds(result_ids.size()); + int aId=0; + if(MYDEBUG_REMOVE) cout << "Result out:"; + for(TUIDS::iterator aIter=result_ids.begin();aIter!=result_ids.end();aIter++,aId++){ + float P[3]; + convex->Points->GetPoint(*aIter,P); + out->Points->SetPoint(aId,P); + out->PointIds->SetId(aId,aPointIds->GetId(*aIter)); + if (MYDEBUG_REMOVE) cout << *aIter << ":" << aPointIds->GetId(*aIter) << " , "; + } + if(MYDEBUG_REMOVE) cout << endl; + out->Modified(); + out->Initialize(); + + return out; +} + void GetPolygonalFaces(vtkUnstructuredGrid* theGrid,int cellId,TCellArray &outputCellArray) { if (theGrid->GetCellType(cellId) == VTK_CONVEX_POINT_SET){ // get vtkCell type = VTK_CONVEX_POINT_SET - if(vtkConvexPointSet* convex = static_cast(theGrid->GetCell(cellId))){ + if(vtkConvexPointSet* convex_in = static_cast(theGrid->GetCell(cellId))){ + vtkSmartPointer convex = RemoveAllUnneededPoints(convex_in); TCellArray f2points; float convex_center[3]; // convex center point coorinat int aNbFaces = convex->GetNumberOfFaces(); int numPts = convex->GetNumberOfPoints(); - TCell convex_ids; + if(MYDEBUG_REMOVE) cout << "aNbFaces="< #include @@ -46,16 +45,16 @@ #include #include +#include +#include +#include +#include + +#include +#include #include #include -using namespace std; - - -#ifdef _DEBUG_ -static int MYDEBUG = 0; -#else -static int MYDEBUG = 0; -#endif +#include #if defined __GNUC__ #if __GNUC__ == 2 @@ -63,20 +62,29 @@ static int MYDEBUG = 0; #endif #endif +#define USE_ROBUST_TRIANGULATION + +//---------------------------------------------------------------------------- vtkCxxRevisionMacro(VTKViewer_GeometryFilter, "$Revision$"); vtkStandardNewMacro(VTKViewer_GeometryFilter); -VTKViewer_GeometryFilter::VTKViewer_GeometryFilter(): +VTKViewer_GeometryFilter +::VTKViewer_GeometryFilter(): myShowInside(0), - myStoreMapping(0) + myStoreMapping(0), + myIsWireframeMode(0) {} -VTKViewer_GeometryFilter::~VTKViewer_GeometryFilter() +VTKViewer_GeometryFilter +::~VTKViewer_GeometryFilter() {} -void VTKViewer_GeometryFilter::Execute() +//---------------------------------------------------------------------------- +void +VTKViewer_GeometryFilter +::Execute() { vtkDataSet *input= this->GetInput(); vtkIdType numCells=input->GetNumberOfCells(); @@ -94,27 +102,20 @@ void VTKViewer_GeometryFilter::Execute() } -void VTKViewer_GeometryFilter::SetStoreMapping(int theStoreMapping){ - myStoreMapping = theStoreMapping; - this->Modified(); -} - - -vtkIdType VTKViewer_GeometryFilter::GetElemObjId(int theVtkID){ - if(myVTK2ObjIds.empty() || theVtkID > myVTK2ObjIds.size()) return -1; -#if defined __GNUC_2__ - return myVTK2ObjIds[theVtkID]; -#else - return myVTK2ObjIds.at(theVtkID); -#endif -} - - -void VTKViewer_GeometryFilter::UnstructuredGridExecute() +//---------------------------------------------------------------------------- +void +VTKViewer_GeometryFilter +::UnstructuredGridExecute() { vtkUnstructuredGrid *input= (vtkUnstructuredGrid *)this->GetInput(); vtkCellArray *Connectivity = input->GetCells(); - if (Connectivity == NULL) {return;} + // Check input + if ( Connectivity == NULL ) + { + vtkDebugMacro(<<"Nothing to extract"); + return; + } + vtkIdType cellId; int i; int allVisible; @@ -127,9 +128,24 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() vtkPolyData *output = this->GetOutput(); vtkPointData *outputPD = output->GetPointData(); +#ifdef USE_ROBUST_TRIANGULATION + vtkUnstructuredGrid* anUnstructuredGrid = vtkUnstructuredGrid::New(); + vtkPoints* aDelaunayPoints = vtkPoints::New(); + + vtkDelaunay3D* aDelaunay3D = vtkDelaunay3D::New(); + aDelaunay3D->SetInput(anUnstructuredGrid); + + vtkGeometryFilter* aGeometryFilter = vtkGeometryFilter::New(); + aGeometryFilter->SetInput(aDelaunay3D->GetOutput()); +#endif + vtkCellData *outputCD = output->GetCellData(); - //vtkCellArray *Verts, *Lines, *Polys, *Strips; - vtkIdList *cellIds, *faceIds; + vtkGenericCell *cell = vtkGenericCell::New(); + + + vtkIdList *cellIds = vtkIdList::New(); + vtkIdList *faceIds = vtkIdList::New(); + char *cellVis; vtkIdType newCellId; int faceId, *faceVerts, numFacePts; @@ -161,16 +177,7 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() cellGhostLevels = ((vtkUnsignedCharArray*)temp)->GetPointer(0); } - // Check input - if ( Connectivity == NULL ) - { - vtkDebugMacro(<<"Nothing to extract"); - return; - } - // Determine nature of what we have to do - cellIds = vtkIdList::New(); - faceIds = vtkIdList::New(); if ( (!this->CellClipping) && (!this->PointClipping) && (!this->ExtentClipping) ) { @@ -190,14 +197,6 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() outputCD->CopyAllocate(cd,numCells,numCells/2); output->Allocate(numCells/4+1,numCells); - //Verts = vtkCellArray::New(); - //Verts->Allocate(numCells/4+1,numCells); - //Lines = vtkCellArray::New(); - //Lines->Allocate(numCells/4+1,numCells); - //Polys = vtkCellArray::New(); - //Polys->Allocate(numCells/4+1,numCells); - //Strips = vtkCellArray::New(); - //Strips->Allocate(numCells/4+1,numCells); // Loop over the cells determining what's visible if (!allVisible) @@ -278,9 +277,8 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() case VTK_LINE: case VTK_POLY_LINE: newCellId = output->InsertNextCell(aCellType,npts,pts); - if(myStoreMapping){ - myVTK2ObjIds.push_back(cellId); //apo - } + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); outputCD->CopyData(cd,cellId,newCellId); break; @@ -288,58 +286,319 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() case VTK_QUAD: case VTK_POLYGON: newCellId = output->InsertNextCell(aCellType,npts,pts); - if(myStoreMapping){ - myVTK2ObjIds.push_back(cellId); //apo - } + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); outputCD->CopyData(cd,cellId,newCellId); break; case VTK_TRIANGLE_STRIP: newCellId = output->InsertNextCell(aCellType,npts,pts); - if(myStoreMapping){ - myVTK2ObjIds.push_back(cellId); //apo - } + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); outputCD->CopyData(cd,cellId,newCellId); break; case VTK_PIXEL: newCellId = output->InsertNextCell(aCellType,npts,pts); - if(myStoreMapping){ - myVTK2ObjIds.push_back(cellId); //apo - } + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); outputCD->CopyData(cd,cellId,newCellId); break; - case VTK_CONVEX_POINT_SET:{ - TCellArray tmpCellArray; - try{ - CONVEX_TOOL::GetPolygonalFaces(input,cellId,tmpCellArray); // "VTKViewer_ConvexTool.cxx" - } catch (const std::exception& theExc){ - cout << __FILE__ << "[" << __LINE__ << "] " << "Exception:" << theExc.what() << endl; - } catch (...) { - cout << __FILE__ << "[" << __LINE__ << "] " << "Exception was occured"<< endl; + case VTK_CONVEX_POINT_SET: { + //cout<<"cellId = "<Initialize(); + anUnstructuredGrid->Allocate(); + anUnstructuredGrid->SetPoints(aDelaunayPoints); + + vtkIdType *aPts; + input->GetCellPoints(cellId,aNumPts,aPts); + { + float aPntCoord[3]; + aDelaunayPoints->SetNumberOfPoints(aNumPts); + vtkPoints *anInputPoints = input->GetPoints(); + for (int aPntId = 0; aPntId < aNumPts; aPntId++) { + anInputPoints->GetPoint(aPts[aPntId],aPntCoord); + aDelaunayPoints->SetPoint(aPntId,aPntCoord); + } } - TCellArray::iterator aFaceIter = tmpCellArray.begin(); - for (; aFaceIter!=tmpCellArray.end(); aFaceIter++){ - TCell cell = aFaceIter->second; - numFacePts = cell.size(); - if(numFacePts>3) - aCellType = VTK_POLYGON; - else if(numFacePts == 3) - aCellType = VTK_TRIANGLE; - else if(numFacePts<3) +#else + input->GetCell(cellId,cell); + aPoints = input->GetPoints(); + aNumPts = cell->GetNumberOfPoints(); +#endif + // To calculate the bary center of the cell + float aCellCenter[3] = {0.0, 0.0, 0.0}; + { + float aPntCoord[3]; + for (int aPntId = 0; aPntId < aNumPts; aPntId++) { +#ifdef USE_ROBUST_TRIANGULATION + aPoints->GetPoint(aPntId,aPntCoord); +#else + aPoints->GetPoint(cell->GetPointId(aPntId),aPntCoord); +#endif + //cout<<"\t\taPntId = "<Update(); + vtkPolyData* aPolyData = aGeometryFilter->GetOutput(); + + float aCellLength = aPolyData->GetLength(); + int aNumFaces = aPolyData->GetNumberOfCells(); +#else + float aCellLength = sqrt(cell->GetLength2()); + int aNumFaces = cell->GetNumberOfFaces(); +#endif + + static float EPS = 1.0E-5; + float aDistEps = aCellLength * EPS; + + // To initialize set of points that belong to the cell + typedef std::set TPointIds; + TPointIds anInitialPointIds; + for(vtkIdType aPntId = 0; aPntId < aNumPts; aPntId++){ +#ifdef USE_ROBUST_TRIANGULATION + anInitialPointIds.insert(aPntId); +#else + anInitialPointIds.insert(cell->GetPointId(aPntId)); +#endif + } + + // To initialize set of points by face that belong to the cell and backward + typedef std::set TFace2Visibility; + TFace2Visibility aFace2Visibility; + + typedef std::set TFace2PointIds; + TFace2PointIds aFace2PointIds; + + for (int aFaceId = 0; aFaceId < aNumFaces; aFaceId++) { +#ifdef USE_ROBUST_TRIANGULATION + vtkCell* aFace = aPolyData->GetCell(aFaceId); +#else + vtkCell* aFace = cell->GetFace(aFaceId); +#endif + vtkIdList *anIdList = aFace->PointIds; + aNewPts[0] = anIdList->GetId(0); + aNewPts[1] = anIdList->GetId(1); + aNewPts[2] = anIdList->GetId(2); + +#ifdef USE_ROBUST_TRIANGULATION + faceIds->Reset(); + faceIds->InsertNextId(aPts[aNewPts[0]]); + faceIds->InsertNextId(aPts[aNewPts[1]]); + faceIds->InsertNextId(aPts[aNewPts[2]]); + input->GetCellNeighbors(cellId, faceIds, cellIds); +#else + input->GetCellNeighbors(cellId, anIdList, cellIds); +#endif + if((!allVisible && !cellVis[cellIds->GetId(0)]) || + cellIds->GetNumberOfIds() <= 0 || + myShowInside) + { + TPointIds aPointIds; + aPointIds.insert(aNewPts[0]); + aPointIds.insert(aNewPts[1]); + aPointIds.insert(aNewPts[2]); + + aFace2PointIds.insert(aPointIds); + aFace2Visibility.insert(aFaceId); + } + } + + for (int aFaceId = 0; aFaceId < aNumFaces; aFaceId++) { + if(aFace2Visibility.find(aFaceId) == aFace2Visibility.end()) continue; + +#ifdef USE_ROBUST_TRIANGULATION + vtkCell* aFace = aPolyData->GetCell(aFaceId); +#else + vtkCell* aFace = cell->GetFace(aFaceId); +#endif + vtkIdList *anIdList = aFace->PointIds; + aNewPts[0] = anIdList->GetId(0); + aNewPts[1] = anIdList->GetId(1); + aNewPts[2] = anIdList->GetId(2); - for ( i=0; i < numFacePts; i++) + // To initialize set of points for the plane where the trinangle face belong to + TPointIds aPointIds; + aPointIds.insert(aNewPts[0]); + aPointIds.insert(aNewPts[1]); + aPointIds.insert(aNewPts[2]); + + // To get know, if the points of the trinagle were already observed + bool anIsObserved = aFace2PointIds.find(aPointIds) == aFace2PointIds.end(); + //cout<<"\taFaceId = "<GetPoint(aNewPts[0],aCoord[0]); + aPoints->GetPoint(aNewPts[1],aCoord[1]); + aPoints->GetPoint(aNewPts[2],aCoord[2]); + + // To calculate plane normal + float aVector01[3] = { aCoord[1][0] - aCoord[0][0], + aCoord[1][1] - aCoord[0][1], + aCoord[1][2] - aCoord[0][2] }; + + float aVector02[3] = { aCoord[2][0] - aCoord[0][0], + aCoord[2][1] - aCoord[0][1], + aCoord[2][2] - aCoord[0][2] }; + + float aCross21[3]; + vtkMath::Cross(aVector02,aVector01,aCross21); + + vtkMath::Normalize(aCross21); + + // To calculate what points belong to the plane + // To calculate bounds of the point set + float aCenter[3] = {0.0, 0.0, 0.0}; + { + TPointIds::const_iterator anIter = anInitialPointIds.begin(); + TPointIds::const_iterator anEndIter = anInitialPointIds.end(); + for(; anIter != anEndIter; anIter++){ + float aPntCoord[3]; + vtkIdType aPntId = *anIter; + aPoints->GetPoint(aPntId,aPntCoord); + float aDist = vtkPlane::DistanceToPlane(aPntCoord,aCross21,aCoord[0]); + //cout<<"\t\taPntId = "< 0){ + aCross21[0] = -aCross21[0]; + aCross21[1] = -aCross21[1]; + aCross21[2] = -aCross21[2]; + } + + vtkMath::Normalize(aVector0); + + //cout<<"\t\taCenter = {"< TSortedPointIds; + TSortedPointIds aSortedPointIds; + + TPointIds::const_iterator anIter = aPointIds.begin(); + TPointIds::const_iterator anEndIter = aPointIds.end(); + for(; anIter != anEndIter; anIter++){ + float aPntCoord[3]; + vtkIdType aPntId = *anIter; + aPoints->GetPoint(aPntId,aPntCoord); + float aVector[3] = { aPntCoord[0] - aCenter[0], + aPntCoord[1] - aCenter[1], + aPntCoord[2] - aCenter[2] }; + vtkMath::Normalize(aVector); + + float aCross[3]; + vtkMath::Cross(aVector,aVector0,aCross); + bool aGreaterThanPi = vtkMath::Dot(aCross,aCross21) < 0; + float aCosinus = vtkMath::Dot(aVector,aVector0); + if(aCosinus > 1.0) + aCosinus = 1.0; + if(aCosinus < -1.0) + aCosinus = -1.0; + static float a2Pi = 2.0 * vtkMath::Pi(); + float anAngle = acos(aCosinus); + //cout<<"\t\taPntId = "< aConnectivities(numFacePts); + TSortedPointIds::const_iterator anIter = aSortedPointIds.begin(); + TSortedPointIds::const_iterator anEndIter = aSortedPointIds.end(); + for(vtkIdType anId = 0; anIter != anEndIter; anIter++, anId++){ + vtkIdType aPntId = anIter->second; +#ifdef USE_ROBUST_TRIANGULATION + aConnectivities[anId] = aPts[aPntId]; +#else + aConnectivities[anId] = aPntId; +#endif + } + newCellId = output->InsertNextCell(aCellType,numFacePts,&aConnectivities[0]); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + outputCD->CopyData(cd,cellId,newCellId); + } } - newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping){ - myVTK2ObjIds.push_back(cellId); } - outputCD->CopyData(cd,cellId,newCellId); } + break; } case VTK_TETRA: { @@ -350,20 +609,17 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() faceIds->InsertNextId(pts[faceVerts[0]]); faceIds->InsertNextId(pts[faceVerts[1]]); faceIds->InsertNextId(pts[faceVerts[2]]); - numFacePts = 3; aCellType = VTK_TRIANGLE; + numFacePts = 3; input->GetCellNeighbors(cellId, faceIds, cellIds); - if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 || + if ( cellIds->GetNumberOfIds() <= 0 || myShowInside || (!allVisible && !cellVis[cellIds->GetId(0)]) ) { for ( i=0; i < numFacePts; i++) - { aNewPts[i] = pts[faceVerts[i]]; - } newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping){ - myVTK2ObjIds.push_back(cellId); //apo - } + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); outputCD->CopyData(cd,cellId,newCellId); } } @@ -378,20 +634,17 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() faceIds->InsertNextId(pts[faceVerts[1]]); faceIds->InsertNextId(pts[faceVerts[2]]); faceIds->InsertNextId(pts[faceVerts[3]]); - numFacePts = 4; aCellType = VTK_QUAD; + numFacePts = 4; input->GetCellNeighbors(cellId, faceIds, cellIds); - if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 || + if ( cellIds->GetNumberOfIds() <= 0 || myShowInside || (!allVisible && !cellVis[cellIds->GetId(0)]) ) { for ( i=0; i < numFacePts; i++) - { aNewPts[i] = pts[faceVerts[PixelConvert[i]]]; - } newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping){ - myVTK2ObjIds.push_back(cellId); //apo - } + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); outputCD->CopyData(cd,cellId,newCellId); } } @@ -406,20 +659,17 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() faceIds->InsertNextId(pts[faceVerts[1]]); faceIds->InsertNextId(pts[faceVerts[2]]); faceIds->InsertNextId(pts[faceVerts[3]]); - numFacePts = 4; aCellType = VTK_QUAD; + numFacePts = 4; input->GetCellNeighbors(cellId, faceIds, cellIds); - if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 || + if ( cellIds->GetNumberOfIds() <= 0 || myShowInside || (!allVisible && !cellVis[cellIds->GetId(0)]) ) { for ( i=0; i < numFacePts; i++) - { aNewPts[i] = pts[faceVerts[i]]; - } newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping){ - myVTK2ObjIds.push_back(cellId); //apo - } + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); outputCD->CopyData(cd,cellId,newCellId); } } @@ -433,26 +683,23 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() faceIds->InsertNextId(pts[faceVerts[0]]); faceIds->InsertNextId(pts[faceVerts[1]]); faceIds->InsertNextId(pts[faceVerts[2]]); - numFacePts = 3; aCellType = VTK_TRIANGLE; + numFacePts = 3; if (faceVerts[3] >= 0) { faceIds->InsertNextId(pts[faceVerts[3]]); - numFacePts = 4; aCellType = VTK_QUAD; + numFacePts = 4; } input->GetCellNeighbors(cellId, faceIds, cellIds); - if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 || + if ( cellIds->GetNumberOfIds() <= 0 || myShowInside || (!allVisible && !cellVis[cellIds->GetId(0)]) ) { for ( i=0; i < numFacePts; i++) - { aNewPts[i] = pts[faceVerts[i]]; - } newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping){ - myVTK2ObjIds.push_back(cellId); //apo - } + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); outputCD->CopyData(cd,cellId,newCellId); } } @@ -466,230 +713,335 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() faceIds->InsertNextId(pts[faceVerts[0]]); faceIds->InsertNextId(pts[faceVerts[1]]); faceIds->InsertNextId(pts[faceVerts[2]]); - numFacePts = 3; aCellType = VTK_TRIANGLE; + numFacePts = 3; if (faceVerts[3] >= 0) { faceIds->InsertNextId(pts[faceVerts[3]]); - numFacePts = 4; aCellType = VTK_QUAD; + numFacePts = 4; } input->GetCellNeighbors(cellId, faceIds, cellIds); - if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 || + if ( cellIds->GetNumberOfIds() <= 0 || myShowInside || (!allVisible && !cellVis[cellIds->GetId(0)]) ) { for ( i=0; i < numFacePts; i++) - { aNewPts[i] = pts[faceVerts[i]]; - } newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping){ - myVTK2ObjIds.push_back(cellId); //apo - } + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); outputCD->CopyData(cd,cellId,newCellId); } } break; } //Quadratic cells - case VTK_QUADRATIC_EDGE: { - newCellId = output->InsertNextCell(VTK_POLY_LINE,npts,pts); - if(myStoreMapping) - myVTK2ObjIds.push_back(cellId); - - outputCD->CopyData(cd,cellId,newCellId); - - break; - } - case VTK_QUADRATIC_TRIANGLE: { - numFacePts = 6; - aCellType = VTK_POLYGON; - - aNewPts[0] = pts[0]; - aNewPts[1] = pts[3]; - aNewPts[2] = pts[1]; - aNewPts[3] = pts[4]; - aNewPts[4] = pts[2]; - aNewPts[5] = pts[5]; - - newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping) - myVTK2ObjIds.push_back(cellId); - - outputCD->CopyData(cd,cellId,newCellId); - break; - } - case VTK_QUADRATIC_QUAD: { - numFacePts = 8; - aCellType = VTK_POLYGON; - - aNewPts[0] = pts[0]; - aNewPts[1] = pts[4]; - aNewPts[2] = pts[1]; - aNewPts[3] = pts[5]; - aNewPts[4] = pts[2]; - aNewPts[5] = pts[6]; - aNewPts[6] = pts[3]; - aNewPts[7] = pts[7]; - - newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping) - myVTK2ObjIds.push_back(cellId); - - outputCD->CopyData(cd,cellId,newCellId); - break; - } - case VTK_QUADRATIC_TETRA: { - numFacePts = 8; - aCellType = VTK_POLYGON; - - aNewPts[0] = pts[0]; - aNewPts[1] = pts[4]; - aNewPts[2] = pts[1]; - aNewPts[3] = pts[5]; - aNewPts[4] = pts[2]; - aNewPts[5] = pts[6]; - aNewPts[6] = pts[3]; - aNewPts[7] = pts[7]; - - newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping) - myVTK2ObjIds.push_back(cellId); - - outputCD->CopyData(cd,cellId,newCellId); - break; - } - case VTK_QUADRATIC_HEXAHEDRON: { - numFacePts = 8; - aCellType = VTK_POLYGON; - - //--------------------------------------------------------------- - aNewPts[0] = pts[0]; - aNewPts[1] = pts[8]; - aNewPts[2] = pts[1]; - aNewPts[3] = pts[17]; - aNewPts[4] = pts[5]; - aNewPts[5] = pts[12]; - aNewPts[6] = pts[4]; - aNewPts[7] = pts[16]; - - newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping) - myVTK2ObjIds.push_back(cellId); - - outputCD->CopyData(cd,cellId,newCellId); - - //--------------------------------------------------------------- - aNewPts[0] = pts[1]; - aNewPts[1] = pts[9]; - aNewPts[2] = pts[2]; - aNewPts[3] = pts[18]; - aNewPts[4] = pts[6]; - aNewPts[5] = pts[13]; - aNewPts[6] = pts[5]; - aNewPts[7] = pts[17]; - - newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping) - myVTK2ObjIds.push_back(cellId); - - outputCD->CopyData(cd,cellId,newCellId); - - //--------------------------------------------------------------- - aNewPts[0] = pts[2]; - aNewPts[1] = pts[10]; - aNewPts[2] = pts[3]; - aNewPts[3] = pts[19]; - aNewPts[4] = pts[7]; - aNewPts[5] = pts[14]; - aNewPts[6] = pts[6]; - aNewPts[7] = pts[18]; - - newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping) - myVTK2ObjIds.push_back(cellId); - - outputCD->CopyData(cd,cellId,newCellId); - - //--------------------------------------------------------------- - aNewPts[0] = pts[3]; - aNewPts[1] = pts[11]; - aNewPts[2] = pts[0]; - aNewPts[3] = pts[16]; - aNewPts[4] = pts[4]; - aNewPts[5] = pts[15]; - aNewPts[6] = pts[7]; - aNewPts[7] = pts[19]; - - newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping) - myVTK2ObjIds.push_back(cellId); - - outputCD->CopyData(cd,cellId,newCellId); - - //--------------------------------------------------------------- - aNewPts[0] = pts[0]; - aNewPts[1] = pts[8]; - aNewPts[2] = pts[1]; - aNewPts[3] = pts[9]; - aNewPts[4] = pts[2]; - aNewPts[5] = pts[10]; - aNewPts[6] = pts[3]; - aNewPts[7] = pts[11]; - - newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping) - myVTK2ObjIds.push_back(cellId); + case VTK_QUADRATIC_EDGE: + case VTK_QUADRATIC_TRIANGLE: + case VTK_QUADRATIC_QUAD: + case VTK_QUADRATIC_TETRA: + case VTK_QUADRATIC_HEXAHEDRON: + if(!myIsWireframeMode){ + input->GetCell(cellId,cell); + vtkIdList *pts = vtkIdList::New(); + vtkPoints *coords = vtkPoints::New(); + vtkIdList *cellIds = vtkIdList::New(); + vtkIdType newCellId; + + if ( cell->GetCellDimension() == 1 ) { + aCellType = VTK_LINE; + numFacePts = 2; + cell->Triangulate(0,pts,coords); + for (i=0; i < pts->GetNumberOfIds(); i+=2) { + aNewPts[0] = pts->GetId(i); + aNewPts[1] = pts->GetId(i+1); + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + outputCD->CopyData(cd,cellId,newCellId); + } + } + else if ( cell->GetCellDimension() == 2 ) { + aCellType = VTK_TRIANGLE; + numFacePts = 3; + cell->Triangulate(0,pts,coords); + for (i=0; i < pts->GetNumberOfIds(); i+=3) { + aNewPts[0] = pts->GetId(i); + aNewPts[1] = pts->GetId(i+1); + aNewPts[2] = pts->GetId(i+2); + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + outputCD->CopyData(cd,cellId,newCellId); + } + } + else //3D nonlinear cell + { + aCellType = VTK_TRIANGLE; + numFacePts = 3; + for (int j=0; j < cell->GetNumberOfFaces(); j++){ + vtkCell *face = cell->GetFace(j); + input->GetCellNeighbors(cellId, face->PointIds, cellIds); + if ( cellIds->GetNumberOfIds() <= 0 || myShowInside ) { + face->Triangulate(0,pts,coords); + for (i=0; i < pts->GetNumberOfIds(); i+=3) { + aNewPts[0] = pts->GetId(i); + aNewPts[1] = pts->GetId(i+1); + aNewPts[2] = pts->GetId(i+2); + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + outputCD->CopyData(cd,cellId,newCellId); + } + } + } + } //3d cell + cellIds->Delete(); + coords->Delete(); + pts->Delete(); + break; + }else{ + switch(aCellType){ + case VTK_QUADRATIC_EDGE: { + aCellType = VTK_POLY_LINE; + numFacePts = 3; + + aNewPts[0] = pts[0]; + aNewPts[2] = pts[1]; + aNewPts[1] = pts[2]; + + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + + outputCD->CopyData(cd,cellId,newCellId); + break; + } + case VTK_QUADRATIC_TRIANGLE: { + aCellType = VTK_POLYGON; + numFacePts = 6; + + aNewPts[0] = pts[0]; + aNewPts[1] = pts[3]; + aNewPts[2] = pts[1]; + aNewPts[3] = pts[4]; + aNewPts[4] = pts[2]; + aNewPts[5] = pts[5]; + + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + + outputCD->CopyData(cd,cellId,newCellId); + break; + } + case VTK_QUADRATIC_QUAD: { + aCellType = VTK_POLYGON; + numFacePts = 8; + + aNewPts[0] = pts[0]; + aNewPts[1] = pts[4]; + aNewPts[2] = pts[1]; + aNewPts[3] = pts[5]; + aNewPts[4] = pts[2]; + aNewPts[5] = pts[6]; + aNewPts[6] = pts[3]; + aNewPts[7] = pts[7]; + + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + + outputCD->CopyData(cd,cellId,newCellId); + break; + } + case VTK_QUADRATIC_TETRA: { + aCellType = VTK_POLYGON; + numFacePts = 6; + + //--------------------------------------------------------------- + aNewPts[0] = pts[0]; + aNewPts[1] = pts[4]; + aNewPts[2] = pts[1]; + aNewPts[3] = pts[5]; + aNewPts[4] = pts[2]; + aNewPts[5] = pts[6]; + + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + + outputCD->CopyData(cd,cellId,newCellId); - outputCD->CopyData(cd,cellId,newCellId); + //--------------------------------------------------------------- + aNewPts[0] = pts[0]; + aNewPts[1] = pts[7]; + aNewPts[2] = pts[3]; + aNewPts[3] = pts[8]; + aNewPts[4] = pts[1]; + aNewPts[5] = pts[4]; + + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + + outputCD->CopyData(cd,cellId,newCellId); - //--------------------------------------------------------------- - aNewPts[0] = pts[4]; - aNewPts[1] = pts[12]; - aNewPts[2] = pts[5]; - aNewPts[3] = pts[13]; - aNewPts[4] = pts[6]; - aNewPts[5] = pts[14]; - aNewPts[6] = pts[7]; - aNewPts[7] = pts[15]; - - newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping) - myVTK2ObjIds.push_back(cellId); + //--------------------------------------------------------------- + aNewPts[0] = pts[1]; + aNewPts[1] = pts[8]; + aNewPts[2] = pts[3]; + aNewPts[3] = pts[9]; + aNewPts[4] = pts[2]; + aNewPts[5] = pts[5]; + + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + + outputCD->CopyData(cd,cellId,newCellId); - outputCD->CopyData(cd,cellId,newCellId); + //--------------------------------------------------------------- + aNewPts[0] = pts[2]; + aNewPts[1] = pts[9]; + aNewPts[2] = pts[3]; + aNewPts[3] = pts[7]; + aNewPts[4] = pts[0]; + aNewPts[5] = pts[6]; + + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + + outputCD->CopyData(cd,cellId,newCellId); - break; - } - } //switch + break; + } + case VTK_QUADRATIC_HEXAHEDRON: { + aCellType = VTK_POLYGON; + numFacePts = 8; + + //--------------------------------------------------------------- + aNewPts[0] = pts[0]; + aNewPts[1] = pts[8]; + aNewPts[2] = pts[1]; + aNewPts[3] = pts[17]; + aNewPts[4] = pts[5]; + aNewPts[5] = pts[12]; + aNewPts[6] = pts[4]; + aNewPts[7] = pts[16]; + + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + + outputCD->CopyData(cd,cellId,newCellId); + + //--------------------------------------------------------------- + aNewPts[0] = pts[1]; + aNewPts[1] = pts[9]; + aNewPts[2] = pts[2]; + aNewPts[3] = pts[18]; + aNewPts[4] = pts[6]; + aNewPts[5] = pts[13]; + aNewPts[6] = pts[5]; + aNewPts[7] = pts[17]; + + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + + outputCD->CopyData(cd,cellId,newCellId); + + //--------------------------------------------------------------- + aNewPts[0] = pts[2]; + aNewPts[1] = pts[10]; + aNewPts[2] = pts[3]; + aNewPts[3] = pts[19]; + aNewPts[4] = pts[7]; + aNewPts[5] = pts[14]; + aNewPts[6] = pts[6]; + aNewPts[7] = pts[18]; + + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + + outputCD->CopyData(cd,cellId,newCellId); + + //--------------------------------------------------------------- + aNewPts[0] = pts[3]; + aNewPts[1] = pts[11]; + aNewPts[2] = pts[0]; + aNewPts[3] = pts[16]; + aNewPts[4] = pts[4]; + aNewPts[5] = pts[15]; + aNewPts[6] = pts[7]; + aNewPts[7] = pts[19]; + + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + + outputCD->CopyData(cd,cellId,newCellId); + + //--------------------------------------------------------------- + aNewPts[0] = pts[0]; + aNewPts[1] = pts[8]; + aNewPts[2] = pts[1]; + aNewPts[3] = pts[9]; + aNewPts[4] = pts[2]; + aNewPts[5] = pts[10]; + aNewPts[6] = pts[3]; + aNewPts[7] = pts[11]; + + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + + outputCD->CopyData(cd,cellId,newCellId); + + //--------------------------------------------------------------- + aNewPts[0] = pts[4]; + aNewPts[1] = pts[12]; + aNewPts[2] = pts[5]; + aNewPts[3] = pts[13]; + aNewPts[4] = pts[6]; + aNewPts[5] = pts[14]; + aNewPts[6] = pts[7]; + aNewPts[7] = pts[15]; + + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + + outputCD->CopyData(cd,cellId,newCellId); + + break; + }} + } + } //switch } //if visible } //for all cells - if(MYDEBUG && myStoreMapping){ - for(int i = 0, iEnd = myVTK2ObjIds.size(); i < iEnd; i++){ - cout<SetVerts(Verts); - //Verts->Delete(); - //output->SetLines(Lines); - //Lines->Delete(); - //output->SetPolys(Polys); - //Polys->Delete(); - //output->SetStrips(Strips); - //Strips->Delete(); - output->Squeeze(); vtkDebugMacro(<<"Extracted " << input->GetNumberOfPoints() << " points," << output->GetNumberOfCells() << " cells."); +#ifdef USE_ROBUST_TRIANGULATION + anUnstructuredGrid->Delete(); + aDelaunayPoints->Delete(); + + aDelaunay3D->Delete(); + aGeometryFilter->Delete(); +#endif + + cell->Delete(); + cellIds->Delete(); faceIds->Delete(); + if ( cellVis ) { delete [] cellVis; @@ -697,11 +1049,72 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() } -void VTKViewer_GeometryFilter::SetInside(int theShowInside){ - if(myShowInside == theShowInside) return; +//---------------------------------------------------------------------------- +void +VTKViewer_GeometryFilter +::SetInside(int theShowInside) +{ + if(myShowInside == theShowInside) + return; + myShowInside = theShowInside; this->Modified(); } -int VTKViewer_GeometryFilter::GetInside(){ + +int +VTKViewer_GeometryFilter +::GetInside() +{ return myShowInside; } + + +//---------------------------------------------------------------------------- +void +VTKViewer_GeometryFilter +::SetWireframeMode(int theIsWireframeMode) +{ + if(myIsWireframeMode == theIsWireframeMode) + return; + + myIsWireframeMode = theIsWireframeMode; + this->Modified(); +} + +int +VTKViewer_GeometryFilter +::GetWireframeMode() +{ + return myIsWireframeMode; +} + + +//---------------------------------------------------------------------------- +void +VTKViewer_GeometryFilter +::SetStoreMapping(int theStoreMapping) +{ + if(myStoreMapping == theStoreMapping) + return; + + myStoreMapping = theStoreMapping; + this->Modified(); +} + +int +VTKViewer_GeometryFilter +::GetStoreMapping() +{ + return myStoreMapping; +} + + +//---------------------------------------------------------------------------- +vtkIdType VTKViewer_GeometryFilter::GetElemObjId(int theVtkID){ + if(myVTK2ObjIds.empty() || theVtkID > myVTK2ObjIds.size()) return -1; +#if defined __GNUC_2__ + return myVTK2ObjIds[theVtkID]; +#else + return myVTK2ObjIds.at(theVtkID); +#endif +} diff --git a/src/VTKViewer/VTKViewer_GeometryFilter.h b/src/VTKViewer/VTKViewer_GeometryFilter.h index b302dd04a..329064036 100755 --- a/src/VTKViewer/VTKViewer_GeometryFilter.h +++ b/src/VTKViewer/VTKViewer_GeometryFilter.h @@ -47,6 +47,16 @@ public: * \retval myShowInside */ int GetInside(); + /*! \fn void SetWireframeMode(int theIsWireframeMode) + * \brief Sets \a myIsWireframeMode flag. \a myIsWireframeMode is changed, call this->Modified(). + * \param theIsWireframeMode - used for changing value of \a myIsWireframeMode variable. + */ + void SetWireframeMode(int theIsWireframeMode); + /*! \fn int GetWireframeMode() + * \brief Return value of \a myIsWireframeMode + * \retval myIsWireframeMode + */ + int GetWireframeMode(); /*! \fn void SetStoreMapping(int theStoreMapping); * \brief Sets \a myStoreMapping flag and call this->Modified() * \param theStoreMapping - used for changing value of \a myStoreMapping variable. @@ -56,7 +66,7 @@ public: * \brief Return value of \a myStoreMapping * \retval myStoreMapping */ - int GetStoreMapping(){ return myStoreMapping;} + int GetStoreMapping(); /*! \fn virtual vtkIdType GetNodeObjId(int theVtkID) * \brief Return input value theVtkID * \retval theVtkID @@ -93,6 +103,7 @@ private: TVectorId myVTK2ObjIds; int myShowInside; int myStoreMapping; + int myIsWireframeMode; }; #endif diff --git a/src/VTKViewer/VTKViewer_InteractorStyle.cxx b/src/VTKViewer/VTKViewer_InteractorStyle.cxx index fa407641d..1f69e6085 100644 --- a/src/VTKViewer/VTKViewer_InteractorStyle.cxx +++ b/src/VTKViewer/VTKViewer_InteractorStyle.cxx @@ -50,6 +50,7 @@ #include #include #include +#include #include //VRV: porting on Qt 3.0.5 diff --git a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx index db601ab4a..daf93e15c 100755 --- a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx +++ b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx @@ -51,6 +51,7 @@ #include #include #include +#include // QT Includes #include diff --git a/src/VTKViewer/resources/VTKViewerM_images.po b/src/VTKViewer/resources/VTKViewerM_images.po new file mode 100644 index 000000000..ce2c6c728 --- /dev/null +++ b/src/VTKViewer/resources/VTKViewerM_images.po @@ -0,0 +1,40 @@ +# VISU VISUGUI : GUI of VISU component +# +# Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : +# Module : + +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"POT-Creation-Date: 2002-05-28 10:57:43 AM CEST\n" +"PO-Revision-Date: 2005-05-10 15:20+0400\n" +"Last-Translator: FULLNAME \n" +"Content-Type: text/plain; charset=iso-8859-1\n" + + +msgid "ICON_SVTK_SCALING" +msgstr "view_scaling.png" + +msgid "ICON_GRADUATED_AXES" +msgstr "view_graduated_axes.png" diff --git a/src/VTKViewer/resources/VTKViewerM_msg_en.po b/src/VTKViewer/resources/VTKViewerM_msg_en.po new file mode 100644 index 000000000..7f2c72c31 --- /dev/null +++ b/src/VTKViewer/resources/VTKViewerM_msg_en.po @@ -0,0 +1,109 @@ +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"POT-Creation-Date: 2002-02-22 16:56:46 CET\n" +"PO-Revision-Date: 2005-06-27 12:38+0400\n" +"Last-Translator: FULLNAME \n" +"Content-Type: text/plain; charset=iso-8859-1\n" + + +#: SVTK_NonIsometricDlg.cxx + +msgid "SVTK_NonIsometricDlg::MEN_SCALING" +msgstr "Scaling" + +msgid "SVTK_NonIsometricDlg::O&K" +msgstr "" + +msgid "SVTK_NonIsometricDlg::&Apply" +msgstr "" + +msgid "SVTK_NonIsometricDlg::&Cancel" +msgstr "" + +msgid "SVTK_NonIsometricDlg::&Reset" +msgstr "" + +msgid "SVTK_NonIsometricDlg::DLG_TITLE" +msgstr "Scaling" + +msgid "SVTK_NonIsometricDlg::LBL_X" +msgstr "X :" + +msgid "SVTK_NonIsometricDlg::LBL_Y" +msgstr "Y :" + +msgid "SVTK_NonIsometricDlg::LBL_Z" +msgstr "Z :" + +msgid "SVTK_MainWindow::MNU_SVTK_SCALING" +msgstr "Scaling" + +msgid "SVTK_MainWindow::DSC_SVTK_SCALING" +msgstr "Scaling" + +msgid "SVTK_FontWidget::ARIAL" +msgstr "Arial" + +msgid "SVTK_FontWidget::COURIER" +msgstr "Courier" + +msgid "SVTK_FontWidget::TIMES" +msgstr "Times" + +msgid "SVTK_FontWidget::BOLD" +msgstr "Bold" + +msgid "SVTK_FontWidget::ITALIC" +msgstr "Italic" + +msgid "SVTK_FontWidget::SHADOW" +msgstr "Shadow" + +msgid "SVTK_CubeAxesDlg::CAPTION" +msgstr "Graduated axes" + +msgid "SVTK_CubeAxesDlg::X_AXIS" +msgstr "X axis" + +msgid "SVTK_CubeAxesDlg::Y_AXIS" +msgstr "Y axis" + +msgid "SVTK_CubeAxesDlg::Z_AXIS" +msgstr "Z axis" + +msgid "SVTK_CubeAxesDlg::IS_VISIBLE" +msgstr "Is visible" + +msgid "SVTK_AxisWidget::AXIS_NAME" +msgstr "Axis name" + +msgid "SVTK_AxisWidget::IS_VISIBLE" +msgstr "Is visible" + +msgid "SVTK_AxisWidget::NAME" +msgstr "Name" + +msgid "SVTK_AxisWidget::FONT" +msgstr "Font" + +msgid "SVTK_AxisWidget::LABELS" +msgstr "Labels" + +msgid "SVTK_AxisWidget::NUMBER" +msgstr "Number" + +msgid "SVTK_AxisWidget::OFFSET" +msgstr "Offset" + +msgid "SVTK_AxisWidget::TICK_MARKS" +msgstr "Tick marks" + +msgid "SVTK_AxisWidget::LENGTH" +msgstr "Length" + +msgid "SVTK_MainWindow::MNU_SVTK_GRADUATED_AXES" +msgstr "Graduated axes" + +msgid "SVTK_MainWindow::DSC_SVTK_GRADUATED_AXES" +msgstr "Graduated axes" \ No newline at end of file diff --git a/src/VTKViewer/resources/view_graduated_axes.png b/src/VTKViewer/resources/view_graduated_axes.png new file mode 100755 index 0000000000000000000000000000000000000000..9c9f3d20f9a1c9b43688dfbe06956373be0605fb GIT binary patch literal 351 zcmV-l0igbgP)dQQu^Rd0_eIO zw%@u?(1n7uPDC){__FTiy$Y)`1rgEie0P3?Ss#1!gA65@4V7R-L}c4CHbQO3(CstyWOGV68Jhg&)CVui>>_|4@#Fvi002ovPDHLkV1hK&k+A>( literal 0 HcmV?d00001 diff --git a/src/VTKViewer/resources/view_scaling.png b/src/VTKViewer/resources/view_scaling.png new file mode 100644 index 0000000000000000000000000000000000000000..5d3443634a69abf41d825b5fdbd331808066cbda GIT binary patch literal 453 zcmV;$0XqJPP)Po92!IiWcWARVf8UuMehUVxU!Hz^ z5f56#t2#PWfNiO<0o+x?B5WVo4EKQ*e-_w!F6>dmN?0+Lro6P-)DMJ@bM4ThIOU@b^V*pBXJDE)Ec)66%zq5v} zehjZCTW5+kpMTqjo2`@kf9-F^Z6D^)c+e{Oxt+Z|TmSVjD%qku5kW*U0RPyptkEvj v&T52V$YQbZe1K-N$!s?J7YrZ_L%aS33LLx=