From: admin Date: Mon, 19 Dec 2005 14:01:52 +0000 (+0000) Subject: This commit was generated by cvs2git to create tag X-Git-Tag: TG-D5-38-2003_D2005-20-12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d74feefef312129b662a3644380ca0fc66249acd;p=modules%2Fgui.git This commit was generated by cvs2git to create tag 'TG-D5-38-2003_D2005-20-12'. Sprout from master 2005-12-19 14:01:51 UTC asv 'missing include is added.' Cherrypick from master 2005-10-03 06:19:30 UTC apo 'To provide correct memory management': src/SVTK/SVTK_ViewManager.cxx src/VTKViewer/VTKViewer.h src/VTKViewer/VTKViewer_Actor.cxx src/VTKViewer/VTKViewer_Actor.h src/VTKViewer/VTKViewer_CellRectPicker.cxx src/VTKViewer/VTKViewer_ExtractUnstructuredGrid.h src/VTKViewer/VTKViewer_PassThroughFilter.h src/VTKViewer/VTKViewer_RenderWindow.cxx src/VTKViewer/VTKViewer_RenderWindow.h src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx src/VTKViewer/VTKViewer_RenderWindowInteractor.h src/VTKViewer/VTKViewer_ShrinkFilter.h src/VTKViewer/VTKViewer_Transform.h src/VTKViewer/VTKViewer_TransformFilter.h src/VTKViewer/VTKViewer_Trihedron.cxx src/VTKViewer/VTKViewer_Trihedron.h src/VTKViewer/VTKViewer_Utilities.cxx src/VTKViewer/VTKViewer_Utilities.h src/VTKViewer/VTKViewer_VectorText.cxx src/VTKViewer/VTKViewer_VectorText.h src/VTKViewer/VTKViewer_ViewManager.cxx src/VTKViewer/VTKViewer_ViewManager.h src/VTKViewer/VTKViewer_ViewModel.cxx src/VTKViewer/VTKViewer_ViewModel.h src/VTKViewer/VTKViewer_ViewWindow.h Cherrypick from master 2005-10-28 09:58:41 UTC jfa 'Fix for bug 10411: Attempt to create polyhedral volume calls error message': src/VTKViewer/VTKViewer_ConvexTool.cxx Cherrypick from BR-D5-38-2003 2005-12-16 15:29:05 UTC apo 'Adjust to HEAD modifications': doc/salome/tui/SUIT/doxyfile src/LightApp/LightApp_Module.cxx src/LightApp/LightApp_OBSelector.cxx src/LightApp/LightApp_OBSelector.h src/LightApp/LightApp_VTKSelector.cxx src/LightApp/LightApp_VTKSelector.h src/OBJECT/Makefile.in src/ObjBrowser/OB_Browser.cxx src/ObjBrowser/OB_Browser.h src/SALOME_PY/SalomePy.cxx src/SVTK/Makefile.in src/SVTK/SALOME_Actor.cxx src/SVTK/SALOME_Actor.h src/SVTK/SVTK.cxx src/SVTK/SVTK_Actor.cxx src/SVTK/SVTK_Actor.h src/SVTK/SVTK_CubeAxesDlg.cxx src/SVTK/SVTK_CubeAxesDlg.h src/SVTK/SVTK_Event.h src/SVTK/SVTK_FontWidget.cxx src/SVTK/SVTK_FontWidget.h src/SVTK/SVTK_Functor.h src/SVTK/SVTK_GenericRenderWindowInteractor.cxx src/SVTK/SVTK_GenericRenderWindowInteractor.h src/SVTK/SVTK_InteractorStyle.cxx src/SVTK/SVTK_InteractorStyle.h src/SVTK/SVTK_MainWindow.cxx src/SVTK/SVTK_MainWindow.h src/SVTK/SVTK_NonIsometricDlg.cxx src/SVTK/SVTK_NonIsometricDlg.h src/SVTK/SVTK_RenderWindowInteractor.cxx src/SVTK/SVTK_RenderWindowInteractor.h src/SVTK/SVTK_Renderer.cxx src/SVTK/SVTK_Renderer.h src/SVTK/SVTK_Selection.h src/SVTK/SVTK_SelectionEvent.h src/SVTK/SVTK_Selector.cxx src/SVTK/SVTK_Selector.h src/SVTK/SVTK_SelectorDef.h src/SVTK/SVTK_SpaceMouse.cxx src/SVTK/SVTK_SpaceMouse.h src/SVTK/SVTK_View.cxx src/SVTK/SVTK_View.h src/SVTK/SVTK_ViewManager.h src/SVTK/SVTK_ViewModel.cxx src/SVTK/SVTK_ViewModel.h src/SVTK/SVTK_ViewModelBase.h src/SVTK/SVTK_ViewWindow.cxx src/SVTK/SVTK_ViewWindow.h src/SalomeApp/SalomeApp_DataModel.cxx src/SalomeApp/resources/SalomeApp.xml src/VTKViewer/Makefile.in src/VTKViewer/VTKViewer_AppendFilter.cxx src/VTKViewer/VTKViewer_AppendFilter.h src/VTKViewer/VTKViewer_GeometryFilter.cxx src/VTKViewer/VTKViewer_GeometryFilter.h src/VTKViewer/VTKViewer_ViewWindow.cxx src/VTKViewer/resources/VTKViewerM_images.po src/VTKViewer/resources/VTKViewerM_msg_en.po src/VTKViewer/resources/view_graduated_axes.png src/VTKViewer/resources/view_scaling.png Delete: src/OBJECT/SALOME_Actor.cxx src/OBJECT/SALOME_Actor.h src/SVTK/SVTK_RenderWindow.cxx src/SVTK/SVTK_RenderWindow.h --- diff --git a/doc/salome/tui/SUIT/doxyfile b/doc/salome/tui/SUIT/doxyfile index 02d73d5e5..15f59d894 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/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index 46d3f82af..8db02d3be 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 e7f5a4d09..a2c7dba9f 100644 --- a/src/LightApp/LightApp_OBSelector.cxx +++ b/src/LightApp/LightApp_OBSelector.cxx @@ -1,21 +1,3 @@ -// 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 "LightApp_OBSelector.h" #include "LightApp_DataOwner.h" @@ -35,6 +17,8 @@ LightApp_OBSelector::LightApp_OBSelector( OB_Browser* ob, SUIT_SelectionMgr* mgr if ( myBrowser ) { connect( myBrowser, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) ); } + + setModified(); } /*! @@ -81,15 +65,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 ); @@ -116,4 +101,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 e4bc2c883..a48432b1e 100644 --- a/src/LightApp/LightApp_OBSelector.h +++ b/src/LightApp/LightApp_OBSelector.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef LIGHTAPP_OBSELECTOR_H #define LIGHTAPP_OBSELECTOR_H @@ -39,6 +21,9 @@ public: /*!Return "ObjectBrowser"*/ virtual QString type() const { return "ObjectBrowser"; } + void setModified(); + unsigned long getModifiedTime() { return myModifiedTime; } + private slots: void onSelectionChanged(); @@ -51,6 +36,10 @@ private: private: OB_Browser* myBrowser; + + QMap myEntries; + + unsigned long myModifiedTime; }; #endif diff --git a/src/LightApp/LightApp_VTKSelector.cxx b/src/LightApp/LightApp_VTKSelector.cxx index 7b0b64333..caf33ff5e 100644 --- a/src/LightApp/LightApp_VTKSelector.cxx +++ b/src/LightApp/LightApp_VTKSelector.cxx @@ -1,25 +1,7 @@ -// 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 "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 +18,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 +50,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 +70,7 @@ LightApp_VTKSelector /*! Gets viewer. */ -SVTK_Viewer* +SVTK_ViewModelBase* LightApp_VTKSelector ::viewer() const { @@ -96,13 +78,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 +117,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..5e3073db2 100644 --- a/src/LightApp/LightApp_VTKSelector.h +++ b/src/LightApp/LightApp_VTKSelector.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef LIGHTAPP_VTKSELECTOR_H #define LIGHTAPP_VTKSELECTOR_H @@ -32,7 +14,7 @@ #include "SALOME_InteractiveObject.hxx" class SALOME_Actor; -class SVTK_Viewer; +class SVTK_ViewModelBase; /*! Provide salome vtk data owner list. @@ -75,10 +57,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 +72,7 @@ protected: virtual void setSelection( const SUIT_DataOwnerPtrList& ); private: - SVTK_Viewer* myViewer; + SVTK_ViewModelBase* myViewer; }; #endif diff --git a/src/OBJECT/Makefile.in b/src/OBJECT/Makefile.in index 9bcbc4cec..ca3a3d701 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\ @@ -52,7 +50,7 @@ LIB_CLIENT_IDL = BIN = BIN_SRC = -CPPFLAGS+=$(PYTHON_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) $(QT_INCLUDES) $(OGL_INCLUDES) +CPPFLAGS+=$(PYTHON_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) $(QT_INCLUDES) $(OGL_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome LDFLAGS+= $(PYTHON_LIBS) $(VTK_LIBS) $(QT_LIBS) $(OGL_LIBS) $(CAS_LDPATH) -lTKV3d -lVTKViewer -lsuit 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 272a4b661..4ec44404d 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -1,21 +1,3 @@ -// 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 "OB_Browser.h" #include "OB_Filter.h" @@ -115,6 +97,8 @@ myRootDecorated( true ) this, SLOT( onDoubleClicked( QListViewItem* ) ) ); setRootObject( root ); + + setModified(); } OB_Browser::~OB_Browser() @@ -219,6 +203,8 @@ void OB_Browser::setRootObject( SUIT_DataObject* theRoot ) autoOpenBranches(); + setModified(); + if ( selNum != numberOfSelected() ) emit selectionChanged(); } @@ -525,6 +511,8 @@ void OB_Browser::updateTree( SUIT_DataObject* obj ) autoOpenBranches(); + setModified(); + if ( selNum != numberOfSelected() ) emit selectionChanged(); } @@ -563,6 +551,8 @@ void OB_Browser::replaceTree( SUIT_DataObject* src, SUIT_DataObject* trg ) autoOpenBranches(); + setModified(); + if ( selNum != numberOfSelected() ) emit selectionChanged(); } @@ -1119,3 +1109,8 @@ 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 5d7575b47..419511e1e 100755 --- a/src/ObjBrowser/OB_Browser.h +++ b/src/ObjBrowser/OB_Browser.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef OB_BROWSER_H #define OB_BROWSER_H @@ -117,6 +99,9 @@ public: virtual void contextMenuPopup( QPopupMenu* ); + void setModified(); + unsigned long getModifiedTime() { return myModifiedTime; } + signals: void selectionChanged(); void doubleClicked( SUIT_DataObject* ); @@ -183,6 +168,8 @@ private: int myAutoOpenLevel; friend class OB_Browser::ToolTip; + + unsigned long myModifiedTime; }; #endif 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/SVTK/Makefile.in b/src/SVTK/Makefile.in index c395159b7..73ac9bfe4 100755 --- a/src/SVTK/Makefile.in +++ b/src/SVTK/Makefile.in @@ -1,58 +1,98 @@ # 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=../.. srcdir=@srcdir@ -VPATH=.:@srcdir@:@srcdir@/resources +VPATH=.:@srcdir@ @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 - -PO_FILES = SVTK_msg_en.po +EXPORT_HEADERS= \ + SVTK.h \ + SVTK_Prs.h \ + SVTK_Actor.h \ + SALOME_Actor.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 # 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_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) \ + -I$(KERNEL_ROOT_DIR)/include/salome + +LDFLAGS+= \ + $(QT_MT_LIBS) \ + $(OCC_LIBS) \ + $(VTK_LIBS) \ + -L$(KERNEL_ROOT_DIR)/lib/salome + +LIBS+= -lsuit -lCAM -lSalomeObject -lSalomePrs -lVTKViewer -lOpUtil -lToolsGUI -lSalomeDS + +LDFLAGSFORBIN=$(LDFLAGS) $(LIBS) \ + -lqtx -lstd -lSALOMELocalTrace -lSalomeNS -lTOOLSDS -lSalomeHDFPersist -lSalomeDSImpl \ + -lSalomeGenericObj -lSalomeLifeCycleCORBA -lSALOMEBasics -lSalomeContainer \ + -lSalomeResourcesManager -lRegistry -lSalomeNotification @CONCLUDE@ diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx new file mode 100644 index 000000000..5e4064ddd --- /dev/null +++ b/src/SVTK/SALOME_Actor.cxx @@ -0,0 +1,1205 @@ +// 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 "VTKViewer_CellRectPicker.h" + +#include "SVTK_Actor.h" + +// VTK Includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "utilities.h" + +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif + +#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), + 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()), + myPreHighlightActor(SVTK_Actor::New()), + myHighlightActor(SVTK_Actor::New()), + myOutline(vtkOutlineSource::New()), + myOutlineActor(VTKViewer_Actor::New()) +{ + if(MYDEBUG) MESSAGE("SALOME_Actor::SALOME_Actor - this = "<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() +{ + if(MYDEBUG) MESSAGE("SALOME_Actor::~SALOME_Actor - this = "<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(); +} + + +//---------------------------------------------------------------------------- +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; +} + +const char* +SALOME_Actor +::getName() +{ + return myName.c_str(); +} + +void +SALOME_Actor +::setName(const char* theName) +{ + if(hasIO()) + myIO->setName(theName); + myName = theName; +} + + +//---------------------------------------------------------------------------- +void +SALOME_Actor +::AddToRender(vtkRenderer* theRenderer) +{ + myRenderer = theRenderer; + + theRenderer->AddActor(this); + + theRenderer->AddActor( myPreHighlightActor.GetPointer() ); + theRenderer->AddActor( myHighlightActor.GetPointer() ); + theRenderer->AddActor( myOutlineActor.GetPointer() ); +} + +void +SALOME_Actor +::RemoveFromRender(vtkRenderer* theRenderer) +{ + theRenderer->RemoveActor(this); + + theRenderer->RemoveActor( myPreHighlightActor.GetPointer() ); + theRenderer->RemoveActor( myHighlightActor.GetPointer() ); + theRenderer->RemoveActor( myOutlineActor.GetPointer() ); +} + +vtkRenderer* +SALOME_Actor +::GetRenderer() +{ + return myRenderer; +} + +void +SALOME_Actor +::GetChildActors(vtkActorCollection*) +{} + + +//---------------------------------------------------------------------------- +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 +::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()); + } + } + Superclass::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); + Superclass::Render(ren,m); + + vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); + vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology); + }else{ + Superclass::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; +} + + +//---------------------------------------------------------------------------- +float +SALOME_Actor +::GetShrinkFactor() +{ + return 1.0; +} + +bool +SALOME_Actor +::IsShrunkable() +{ + return false; +} + +bool +SALOME_Actor +::IsShrunk() +{ + return false; +} + +void +SALOME_Actor +::SetShrink() +{} + +void +SALOME_Actor +::UnShrink() +{} + + +//---------------------------------------------------------------------------- +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); + myGeomFilter->SetWireframeMode(true); + GetProperty()->SetRepresentation(1); + break; + case VTK_POINTS : + GetProperty()->SetPointSize(SALOME_POINT_SIZE); + 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; +} + +int +SALOME_Actor +::GetRepresentation() +{ + return myRepresentation; +} + + +//---------------------------------------------------------------------------- +int +SALOME_Actor +::GetNodeObjId(int theVtkID) +{ + return theVtkID; +} + +float* +SALOME_Actor +::GetNodeCoord(int theObjID) +{ + return GetInput()->GetPoint(theObjID); +} + +vtkCell* +SALOME_Actor +::GetElemCell(int theObjID) +{ + return GetInput()->GetCell(theObjID); +} + +int +SALOME_Actor +::GetElemObjId(int theVtkID) +{ + return theVtkID; +} + + +//================================================================================= +// 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; +} + + +void +SALOME_Actor +::SetInfinitive(bool theIsInfinite) +{ + myIsInfinite = theIsInfinite; +} + + +bool +SALOME_Actor +::IsInfinitive() +{ + return myIsInfinite; +} + + +float* +SALOME_Actor +::GetBounds() +{ + return Superclass::GetBounds(); +} + + +void +SALOME_Actor +::GetBounds(float theBounds[6]) +{ + Superclass::GetBounds(theBounds); +} + + +//---------------------------------------------------------------------------- +bool +SALOME_Actor +::IsSetCamera() const +{ + return false; +} + +bool +SALOME_Actor +::IsResizable() const +{ + return false; +} + +void +SALOME_Actor +::SetSize( const float ) +{} + + +void +SALOME_Actor +::SetCamera( vtkCamera* ) +{} + +//---------------------------------------------------------------------------- +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 +::SetColor(const float theRGB[3]) +{ + SetColor(theRGB[0],theRGB[1],theRGB[2]); +} + +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; +} + + +//---------------------------------------------------------------- +void +SALOME_Actor +::SetVisibility( int theVisibility ) +{ + Superclass::SetVisibility( theVisibility ); + + myOutlineActor->SetVisibility( theVisibility && isHighlighted() && !hasHighlight() ); + + myPreHighlightActor->SetVisibility( theVisibility && myIsPreselected ); + + if(mySelector.GetPointer()){ + if(mySelector->SelectionMode() != ActorSelection){ + int aHasIndex = mySelector->HasIndex( getIO() ); + myHighlightActor->SetVisibility( theVisibility && isHighlighted() && aHasIndex); + } + } +} + + +//---------------------------------------------------------------------------- +bool +SALOME_Actor +::hasHighlight() +{ + return false; +} + +bool +SALOME_Actor +::isHighlighted() +{ + return myIsHighlighted; +} + +void +SALOME_Actor +::SetPreSelected(bool thePreselect) +{ + myIsPreselected = thePreselect; +} + + +//---------------------------------------------------------------- +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(MYDEBUG) MESSAGE("SALOME_Actor::highlight - this = "< +#include + +#include + +class vtkCell; +class vtkPicker; +class vtkPointPicker; +class vtkCellPicker; +class vtkDataSet; +class vtkPolyData; +class vtkCamera; +class vtkProperty; +class vtkOutlineSource; +class vtkRenderer; +class vtkInteractorStyle; +class vtkRenderWindowInteractor; + +class VTKViewer_Transform; +class VTKViewer_GeometryFilter; +class VTKViewer_TransformFilter; +class VTKViewer_PassThroughFilter; +class VTKViewer_CellRectPicker; + +class SVTK_Actor; +class SVTK_InteractorStyle; + +extern int SALOME_POINT_SIZE; +extern int SALOME_LINE_WIDTH; + +class SALOME_Actor; + +//! 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); + + //! Get its name + virtual + const char* + getName(); + + //! Name the #SALOME_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); + + //! Apply additional position + virtual + void + SetPosition(float _arg1, float _arg2, float _arg3); + + //! Apply additional position + virtual + void + SetPosition(float _arg[3]); + + //! 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(); + + //! 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(); + + //---------------------------------------------------------------------------- + //! 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(); + + //! Used to obtain all dependent actors + virtual + void + GetChildActors(vtkActorCollection*); + + //---------------------------------------------------------------------------- + //! To set interactor in order to use #vtkInteractorObserver devices + virtual + void + SetInteractor(vtkRenderWindowInteractor* theInteractor); + + //! Put a request to redraw the view + virtual + void + Update(); + + //---------------------------------------------------------------------------- + //! Ask, if the descendant of the SALOME_Actor will implement its own highlight or not + virtual + bool + hasHighlight(); + + //! Ask, if the SALOME_Actor is already highlighted + virtual + bool + isHighlighted(); + + //! Set preselection mode + virtual + void + SetPreSelected(bool thePreselect = false); + + //---------------------------------------------------------------------------- + //! 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 cell rectangle selection (initialized by #SVTK_Renderer::AddActor) + void + SetCellRectPicker(VTKViewer_CellRectPicker* theCellRectPicker); + + //---------------------------------------------------------------------------- + //! 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); + + vtkSetObjectMacro(PreviewProperty,vtkProperty); + + protected: + //---------------------------------------------------------------------------- + vtkRenderWindowInteractor* myInteractor; + vtkRenderer* myRenderer; + + bool myIsResolveCoincidentTopology; + float myPolygonOffsetFactor; + float myPolygonOffsetUnits; + + Handle(SALOME_InteractiveObject) myIO; + std::string myName; + + float myOpacity; + 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(); + + protected: + vtkProperty *PreviewProperty; + bool myIsPreselected; + bool myIsHighlighted; + Selection_Mode mySelectionMode; + vtkSmartPointer mySelector; + + //---------------------------------------------------------------------------- + // Highlight/ Prehighlight devices + vtkSmartPointer myPointPicker; + vtkSmartPointer myCellPicker; + 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..a8f334e13 --- /dev/null +++ b/src/SVTK/SVTK.cxx @@ -0,0 +1,58 @@ +// 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_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..f78ecc1e8 100644 --- a/src/SVTK/SVTK_Actor.cxx +++ b/src/SVTK/SVTK_Actor.cxx @@ -31,6 +31,8 @@ #include #include +#include "utilities.h" + using namespace std; #ifdef _DEBUG_ @@ -40,7 +42,10 @@ 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,14 +60,18 @@ static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSe vtkStandardNewMacro(SVTK_Actor); -SVTK_Actor::SVTK_Actor() +SVTK_Actor +::SVTK_Actor(): + myUnstructuredGrid(vtkUnstructuredGrid::New()) { + if(MYDEBUG) INFOS("SVTK_Actor - "<Delete(); myUnstructuredGrid->Allocate(); myIsShrunk = false; @@ -71,18 +80,56 @@ SVTK_Actor::SVTK_Actor() myMapper = vtkDataSetMapper::New(); - myMapper->SetInput(myUnstructuredGrid); + SetResolveCoincidentTopology(false); +} + +//---------------------------------------------------------------------------- +void +SVTK_Actor +::Initialize() +{ + myMapper->SetInput(GetSource()); Superclass::InitPipeLine(myMapper); +} - SetResolveCoincidentTopology(false); + +//---------------------------------------------------------------------------- +void +SVTK_Actor +::SetSource(vtkUnstructuredGrid* theUnstructuredGrid) +{ + if(GetSource() == theUnstructuredGrid) + return; + + myUnstructuredGrid = theUnstructuredGrid; + + myMapper->SetInput(theUnstructuredGrid); + + Superclass::InitPipeLine(myMapper); + + Modified(); } -void SVTK_Actor::SetShrinkFactor(float theValue){ +vtkUnstructuredGrid* +SVTK_Actor +::GetSource() +{ + return myUnstructuredGrid.GetPointer(); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Actor +::SetShrinkFactor(float theValue) +{ myShrinkFilter->SetShrinkFactor(theValue); Modified(); } -void SVTK_Actor::SetShrink() +void +SVTK_Actor +::SetShrink() { if ( !myIsShrinkable ) return; if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() ) @@ -93,7 +140,9 @@ void SVTK_Actor::SetShrink() } } -void SVTK_Actor::UnShrink() +void +SVTK_Actor +::UnShrink() { if ( !myIsShrunk ) return; if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() ) @@ -107,38 +156,42 @@ void SVTK_Actor::UnShrink() //---------------------------------------------------------------------------- -SVTK_Actor::~SVTK_Actor() +SVTK_Actor +::~SVTK_Actor() { - //if(MYDEBUG) INFOS("VTKViewer_Actor::~VTKViewer_Actor()"); + if(MYDEBUG) INFOS("~SVTK_Actor()"); - myMapper->RemoveAllInputs(); myMapper->Delete(); - myShrinkFilter->UnRegisterAllOutputs(); myShrinkFilter->Delete(); +} - myUnstructuredGrid->Delete(); + +//---------------------------------------------------------------------------- +const TColStd_IndexedMapOfInteger& +SVTK_Actor +::GetMapIndex() const +{ + 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(); 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,12 +199,16 @@ 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(); if(int aNbOfParts = theMapIndex.Extent()){ @@ -159,26 +216,31 @@ void SVTK_Actor::MapPoints(SALOME_Actor* theMapActor, 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(); vtkDataSet *aSourceDataSet = theMapActor->GetInput(); - CopyPoints(myUnstructuredGrid,aSourceDataSet); + CopyPoints(GetSource(),aSourceDataSet); int iEnd = theMapIndex.Extent(); int aCellId = -1, aCellCounter = 0; @@ -191,18 +253,19 @@ void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor, } 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()); + if(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; + if(vtkCell* anEdgeCell = aCell->GetEdge(aPartId)) + myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds()); + } } } } @@ -223,6 +286,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..cfb4d4b94 100644 --- a/src/SVTK/SVTK_Actor.h +++ b/src/SVTK/SVTK_Actor.h @@ -30,32 +30,65 @@ class vtkUnstructuredGrid; #include "SVTK.h" #include "SALOME_Actor.h" -class SVTK_EXPORT SVTK_Actor : public SALOME_Actor +//! This class used for internal SVTK package purpose (highlight and prehighlight) +class SVTK_EXPORT SVTK_Actor : public VTKViewer_Actor { public: virtual ~SVTK_Actor(); static SVTK_Actor* New(); - vtkTypeMacro(SVTK_Actor,SALOME_Actor); + vtkTypeMacro(SVTK_Actor,VTKViewer_Actor); - 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); + //! To manage shrink functionality + void + SetShrinkFactor(float value); + + //! To manage shrink functionality + virtual + void + SetShrink(); + + //! To manage shrink functionality + virtual + void + UnShrink(); + + //! Allow to recostruct selected cells from source SALOME_Actor and map of subindexes + void + MapCells(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex); + + //! Allow to recostruct selected points from source SALOME_Actor and map of subindexes + void + MapPoints(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex); + + //! 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: - vtkUnstructuredGrid* myUnstructuredGrid; - vtkDataSetMapper* myMapper; + TColStd_IndexedMapOfInteger myMapIndex; + vtkSmartPointer myUnstructuredGrid; + vtkDataSetMapper* myMapper; vtkRenderer* myRenderer; vtkShrinkFilter* myShrinkFilter; 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_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..162d563b9 100644 --- a/src/SVTK/SVTK_Functor.h +++ b/src/SVTK/SVTK_Functor.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef SVTK_Functor_H #define SVTK_Functor_H @@ -27,13 +9,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 +43,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 +66,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..e2d349867 --- /dev/null +++ b/src/SVTK/SVTK_GenericRenderWindowInteractor.cxx @@ -0,0 +1,150 @@ +// 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 "utilities.h" + +#include +#include + +#include + +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(QVTK_GenericRenderWindowInteractor); + +QVTK_GenericRenderWindowInteractor +::QVTK_GenericRenderWindowInteractor() +{ + if(MYDEBUG) INFOS("QVTK_GenericRenderWindowInteractor() - "<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) +{ + if(MYDEBUG) INFOS("SVTK_GenericRenderWindowInteractor() - "< +#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..8e1a1a8e7 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 @@ -69,138 +62,141 @@ //VRV: porting on Qt 3.0.5 #include +#include "utilities.h" + using namespace std; +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif 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(); + + if(MYDEBUG) INFOS("SVTK_InteractorStyle() - "<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); + if(MYDEBUG) INFOS("~SVTK_InteractorStyle() - "<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 +204,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 +230,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 +239,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 +265,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 +405,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 +452,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 +497,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 +618,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 +642,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM; - qApp->installEventFilter(this); } @@ -604,7 +658,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN; - qApp->installEventFilter(this); } //---------------------------------------------------------------------------- @@ -620,7 +673,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE; - qApp->installEventFilter(this); } @@ -637,7 +689,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN; - qApp->installEventFilter(this); } @@ -655,7 +706,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT; - qApp->installEventFilter(this); } @@ -674,28 +724,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,12 +741,13 @@ 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); @@ -723,15 +757,15 @@ SVTK_InteractorStyle double dyf = (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 +806,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 +849,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 +878,78 @@ 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 ); - GetSelector()->ClearIObjects(); - } + 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 ); + 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(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 +961,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 +1018,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 +1027,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(); + SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY(); + this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY); - int w, h, x, y; - myInteractor->GetSize(w, h); - x = mousePos.x(); y = h - mousePos.y() - 1; + bool anIsChanged = false; - this->FindPokedRenderer(x,y); - myInteractor->StartPickCallback(); - myPreSelectionActor->SetVisibility(false); + myPicker->Pick(aSelectionEvent->myX, + aSelectionEvent->myY, + 0.0, + GetCurrentRenderer()); + + SALOME_Actor *anActor = GetFirstSALOMEActor(myPicker.GetPointer()); + if (anActor){ + anIsChanged |= anActor->PreHighlight( this, aSelectionEvent, true ); + } - vtkPicker* aPicker = vtkPicker::SafeDownCast(myInteractor->GetPicker()); - aPicker->Pick(x, y, 0.0, this->CurrentRenderer); + if(myLastPreHighlitedActor.GetPointer() && myLastPreHighlitedActor.GetPointer() != anActor) + anIsChanged |= myLastPreHighlitedActor->PreHighlight( this, aSelectionEvent, false ); - SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aPicker->GetActor()); + myLastPreHighlitedActor = anActor; - if (aSActor && myPreSelectionActor){ - float aPos[3]; - aSActor->GetPosition(aPos); - myPreSelectionActor->SetPosition(aPos); - } - - 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 +1122,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..c5e260cd7 --- /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_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 + +#include "utilities.h" + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + + +//---------------------------------------------------------------------------- +SVTK_MainWindow +::SVTK_MainWindow(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr) : + QMainWindow(theParent,theName,0) +{ + if(MYDEBUG) INFOS("SVTK_MainWindow() - "<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() +{ + if(MYDEBUG) INFOS("~SVTK_MainWindow() - "<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; +} + +//---------------------------------------------------------------------------- +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()), this, 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); +} + +//---------------------------------------------------------------------------- +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(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onBackView() +{ + GetRenderer()->OnBackView(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onTopView() +{ + GetRenderer()->OnTopView(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onBottomView() +{ + GetRenderer()->OnBottomView(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onLeftView() +{ + GetRenderer()->OnLeftView(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onRightView() +{ + GetRenderer()->OnRightView(); +} + +//---------------------------------------------------------------------------- +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(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::onDumpView() +{} + +//---------------------------------------------------------------------------- +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..223a4a6b5 --- /dev/null +++ b/src/SVTK/SVTK_MainWindow.h @@ -0,0 +1,236 @@ +#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 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); + + //! 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(); + + void onDumpView(); + + 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; + + 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..10af3818d --- /dev/null +++ b/src/SVTK/SVTK_NonIsometricDlg.cxx @@ -0,0 +1,202 @@ +// 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 "utilities.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_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..aa2a98210 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -21,980 +21,660 @@ // // // -// 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 +#include "utilities.h" 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(); +#ifdef _DEBUG_ +static int MYDEBUG = 0; +static int MYVTKDEBUG = 0; +#else +static int MYDEBUG = 0; +static int MYVTKDEBUG = 0; +#endif - myCellActor = SVTK_Actor::New(); - myCellActor->PickableOff(); - myCellActor->GetProperty()->SetColor(1,1,0); - myCellActor->GetProperty()->SetLineWidth(5); - myCellActor->GetProperty()->SetRepresentationToSurface(); +static bool GENERATE_SUIT_EVENTS = false; - myEdgeActor = SVTK_Actor::New(); - myEdgeActor->PickableOff(); - myEdgeActor->GetProperty()->SetColor(1,0,0); - myEdgeActor->GetProperty()->SetLineWidth(5); - myEdgeActor->GetProperty()->SetRepresentationToWireframe(); - myPointActor = SVTK_Actor::New(); - myPointActor->PickableOff(); - myPointActor->GetProperty()->SetColor(1,1,0); - myPointActor->GetProperty()->SetPointSize(5); - myPointActor->GetProperty()->SetRepresentationToPoints(); +//---------------------------------------------------------------------------- +QVTK_RenderWindowInteractor +::QVTK_RenderWindowInteractor(QWidget* theParent, + const char* theName): + QWidget(theParent,theName,Qt::WNoAutoErase), + myRenderWindow(vtkRenderWindow::New()) +{ + if(MYDEBUG) INFOS("QVTK_RenderWindowInteractor() - "<Delete(); + myRenderWindow->DoubleBufferOn(); } -SVTK_RenderWindowInteractor -::~SVTK_RenderWindowInteractor() +void +QVTK_RenderWindowInteractor +::Initialize(vtkGenericRenderWindowInteractor* theDevice) { - delete mTimer ; - - myViewWindow->RemoveActor(myCellActor); - myViewWindow->RemoveActor(myEdgeActor); - myViewWindow->RemoveActor(myPointActor); + if(GetDevice()) + myDevice->SetRenderWindow(NULL); - myCellActor->Delete(); - myEdgeActor->Delete(); - myPointActor->Delete(); + myDevice = theDevice; - 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() ; +//---------------------------------------------------------------------------- +QVTK_RenderWindowInteractor +::~QVTK_RenderWindowInteractor() +{ + if(MYDEBUG) INFOS("~QVTK_RenderWindowInteractor() - "<Start() ; + if(SVTK_SpaceMouse* aSpaceMouse = SVTK_SpaceMouse::getInstance()) + if(aSpaceMouse->isSpaceMouseOn()) + aSpaceMouse->close(x11Display()); +} - // - // The interactor has been initialized. - // - this->Initialized = 1 ; - return ; +//---------------------------------------------------------------------------- +vtkGenericRenderWindowInteractor* +QVTK_RenderWindowInteractor +::GetDevice() +{ + return myDevice.GetPointer(); } +//---------------------------------------------------------------------------- +vtkRenderWindow* +QVTK_RenderWindowInteractor +::getRenderWindow() +{ + return myRenderWindow.GetPointer(); +} //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::setGUIWindow(QWidget* theWindow) +QVTK_RenderWindowInteractor +::InvokeEvent(unsigned long theEvent, void* theCallData) { - myGUIWindow = theWindow; + GetDevice()->InvokeEvent(theEvent,theCallData); } //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::setViewWindow(SVTK_ViewWindow* theViewWindow) +QVTK_RenderWindowInteractor +::show() { - myViewWindow = theViewWindow; - - myViewWindow->InsertActor(myCellActor); - myViewWindow->InsertActor(myEdgeActor); - myViewWindow->InsertActor(myPointActor); + QWidget::show(); + update(); // needed for initial contents display on Win32 } //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::MoveInternalActors() +QVTK_RenderWindowInteractor +::polish() { - myViewWindow->MoveActor(myCellActor); - myViewWindow->MoveActor(myEdgeActor); - myViewWindow->MoveActor(myPointActor); + // Final initialization just before the widget is displayed + GetDevice()->SetSize(width(),height()); +#ifndef WNT + getRenderWindow()->SetDisplayId((void*)x11Display()); +#endif + getRenderWindow()->SetWindowId((void*)winId()); + GetDevice()->Enable(); } //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::SetInteractorStyle(vtkInteractorObserver *theInteractor) +QVTK_RenderWindowInteractor +::resize(int w, int h) { - myInteractorStyle = dynamic_cast(theInteractor); - vtkRenderWindowInteractor::SetInteractorStyle(theInteractor); + GetDevice()->UpdateSize(w,h); } - +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::SetSelectionMode(Selection_Mode theMode) +QVTK_RenderWindowInteractor +::paintEvent( QPaintEvent* theEvent ) { - 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; + if(GetDevice()->GetEnabled()){ + if(!GetDevice()->GetInitialized()){ + GetDevice()->Initialize(); + GetDevice()->ConfigureEvent(); + } + GetDevice()->Render(); } - - myInteractorStyle->OnSelectionModeChanged(); } + +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::SetSelectionProp(const double& theRed, - const double& theGreen, - const double& theBlue, - const int& theWidth) -{ - myCellActor->GetProperty()->SetColor(theRed, theGreen, theBlue); - myCellActor->GetProperty()->SetLineWidth(theWidth); +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); + } + } + } - myPointActor->GetProperty()->SetColor(theRed, theGreen, theBlue); - myPointActor->GetProperty()->SetPointSize(theWidth); + update(); } -void -SVTK_RenderWindowInteractor -::SetSelectionTolerance(const double& theTolNodes, - const double& theTolItems) -{ - myTolNodes = theTolNodes; - myTolItems = theTolItems; - myBasicPicker->SetTolerance(myTolItems); - myCellPicker->SetTolerance(myTolItems); - myPointPicker->SetTolerance(myTolNodes); +//---------------------------------------------------------------------------- +void +QVTK_RenderWindowInteractor +::contextMenuEvent( QContextMenuEvent* event ) +{} -} -// ================================== +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::Start() +QVTK_RenderWindowInteractor +::mouseMoveEvent( QMouseEvent* event ) { - // - // 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 ; + GetDevice()->SetEventInformationFlipY(event->x(), + event->y(), + event->state() & ControlButton, + event->state() & ShiftButton); + GetDevice()->MouseMoveEvent(); } + +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::UpdateSize(int w, int h) +QVTK_RenderWindowInteractor +::mousePressEvent( QMouseEvent* event ) { - // 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); - } + 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(); } -int -SVTK_RenderWindowInteractor -::CreateTimer(int vtkNotUsed(timertype)) + +//---------------------------------------------------------------------------- +void +QVTK_RenderWindowInteractor +::mouseReleaseEvent( QMouseEvent *event ) { - // - // Start a one-shot timer for 10ms. - // - mTimer->start(10, TRUE) ; - return 1 ; -} + GetDevice()->SetEventInformationFlipY(event->x(), + event->y(), + event->state() & ControlButton, + event->state() & ShiftButton); -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 ; + if( event->button() & LeftButton ) + GetDevice()->LeftButtonReleaseEvent(); + else if( event->button() & MidButton ) + GetDevice()->MiddleButtonReleaseEvent(); + else if( event->button() & RightButton ) + GetDevice()->RightButtonReleaseEvent(); } + +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::TimerFunc() -{ - if( ! this->Enabled ) { - return ; - } +QVTK_RenderWindowInteractor +::mouseDoubleClickEvent( QMouseEvent* event ) +{} - myInteractorStyle->OnTimer(); - emit RenderWindowModified(); -} +//---------------------------------------------------------------------------- +void +QVTK_RenderWindowInteractor +::wheelEvent( QWheelEvent* event ) +{} + +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::MouseMove(const QMouseEvent *event) +QVTK_RenderWindowInteractor +::keyPressEvent( QKeyEvent* 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()->SetKeyEventInformation(event->state() & ControlButton, + event->state() & ShiftButton, + event->key()); + GetDevice()->KeyPressEvent(); + GetDevice()->CharEvent(); } +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::LeftButtonPressed(const QMouseEvent *event) +QVTK_RenderWindowInteractor +::keyReleaseEvent( QKeyEvent * event ) { - if( ! this->Enabled ) { - return ; - } - myInteractorStyle->OnLeftButtonDown((event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y()); + GetDevice()->SetKeyEventInformation(event->state() & ControlButton, + event->state() & ShiftButton, + event->key()); + GetDevice()->KeyReleaseEvent(); } -void -SVTK_RenderWindowInteractor -::LeftButtonReleased(const QMouseEvent *event) { - if( ! this->Enabled ) { - return ; - } - myInteractorStyle->OnLeftButtonUp( (event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; -} -void -SVTK_RenderWindowInteractor -::MiddleButtonPressed(const QMouseEvent *event) +//---------------------------------------------------------------------------- +void +QVTK_RenderWindowInteractor +::enterEvent( QEvent* event ) { - if( ! this->Enabled ) { - return ; - } - myInteractorStyle->OnMiddleButtonDown((event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; + setActiveWindow(); + setFocus(); + + GetDevice()->EnterEvent(); } -void -SVTK_RenderWindowInteractor -::MiddleButtonReleased(const QMouseEvent *event) +//---------------------------------------------------------------------------- +void +QVTK_RenderWindowInteractor +::leaveEvent( QEvent * ) { - if( ! this->Enabled ) { - return ; - } - myInteractorStyle->OnMiddleButtonUp( (event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; + GetDevice()->LeaveEvent(); } -void -SVTK_RenderWindowInteractor -::RightButtonPressed(const QMouseEvent *event) -{ - if( ! this->Enabled ) { - return ; + +//---------------------------------------------------------------------------- +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()); + } } - myInteractorStyle->OnRightButtonDown( (event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; } -void -SVTK_RenderWindowInteractor -::RightButtonReleased(const QMouseEvent *event) +//---------------------------------------------------------------------------- +void +QVTK_RenderWindowInteractor +::focusOutEvent ( QFocusEvent* 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 ); + 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 -::ButtonPressed(const QMouseEvent *event) -{ - return ; -} -void -SVTK_RenderWindowInteractor -::ButtonReleased(const QMouseEvent *event) -{ - return ; +//---------------------------------------------------------------------------- +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 ); } -int +//---------------------------------------------------------------------------- SVTK_RenderWindowInteractor -::GetDisplayMode() +::SVTK_RenderWindowInteractor(QWidget* theParent, + const char* theName): + QVTK_RenderWindowInteractor(theParent,theName), + myEventCallbackCommand(vtkCallbackCommand::New()) { - return myDisplayMode; -} + if(MYDEBUG) INFOS("SVTK_RenderWindowInteractor() - "<Delete(); + myEventCallbackCommand->SetClientData(this); + myPriority = 0.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)); + myEventCallbackCommand->SetCallback(SVTK_RenderWindowInteractor::ProcessEvents); } - void SVTK_RenderWindowInteractor -::ChangeRepresentationToWireframe() +::Initialize(vtkGenericRenderWindowInteractor* theDevice, + SVTK_Renderer* theRenderer, + SVTK_Selector* theSelector) { - ChangeRepresentationToWireframe(GetRenderer()->GetActors()); + QVTK_RenderWindowInteractor::Initialize(theDevice); + SetRenderer(theRenderer); + SetSelector(theSelector); } -void +//---------------------------------------------------------------------------- SVTK_RenderWindowInteractor -::ChangeRepresentationToSurface() +::~SVTK_RenderWindowInteractor() { - ChangeRepresentationToSurface(GetRenderer()->GetActors()); -} + if(MYDEBUG) INFOS("~SVTK_RenderWindowInteractor() - "<DebugOn(); + getRenderer()->DebugOn(); + GetDevice()->DebugOn(); + } + GetDevice()->SetInteractorStyle(NULL); + while(!myInteractorStyles.empty()){ + const PInteractorStyle& aStyle = myInteractorStyles.top(); + aStyle->SetInteractor(NULL); + if(MYVTKDEBUG) aStyle->DebugOn(); + myInteractorStyles.pop(); + } -void -SVTK_RenderWindowInteractor -::ChangeRepresentationToWireframe(vtkActorCollection* theCollection) -{ - using namespace VTK; - ForEach(theCollection, - TSetFunction - (&SALOME_Actor::setDisplayMode,0)); - emit RenderWindowModified(); + 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()); - if(update) - emit RenderWindowModified(); + mySelector = theSelector; + + 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)); - - emit RenderWindowModified() ; + QVTK_RenderWindowInteractor::mouseMoveEvent(event); - 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); + + if(GENERATE_SUIT_EVENTS) + emit WheelMoved( event ); } //---------------------------------------------------------------------------- -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 +void SVTK_RenderWindowInteractor -::setCellData(const int& theIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor) +::keyPressEvent( QKeyEvent* event ) { - TColStd_IndexedMapOfInteger MapIndex; - MapIndex.Add(theIndex); - theActor->MapCells(theMapActor,MapIndex); -} + QVTK_RenderWindowInteractor::keyPressEvent(event); + if(GENERATE_SUIT_EVENTS) + emit KeyPressed( event ); +} //---------------------------------------------------------------------------- -static void PointsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor) -{ - theActor->MapPoints(theMapActor,theMapIndex); -} - -bool -SVTK_RenderWindowInteractor -::highlightPoint(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - bool hilight, - bool update) -{ - return highlight(theMapIndex,theMapActor,myPointActor,&PointsUpdateActor,hilight,update); -} - 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..e0459678b --- /dev/null +++ b/src/SVTK/SVTK_Renderer.cxx @@ -0,0 +1,641 @@ +// 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 "VTKViewer_CellRectPicker.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 + +#include "utilities.h" + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(SVTK_Renderer); + +//---------------------------------------------------------------------------- +SVTK_Renderer +::SVTK_Renderer(): + myDevice(vtkRenderer::New()), + myInteractor(NULL), + myPriority(0.0), + myEventCallbackCommand(vtkCallbackCommand::New()), + myPointPicker(vtkPointPicker::New()), + myCellPicker(vtkCellPicker::New()), + myCellRectPicker(VTKViewer_CellRectPicker::New()), + myPreHighlightProperty(vtkProperty::New()), + myHighlightProperty(vtkProperty::New()), + myTransform(VTKViewer_Transform::New()), + myCubeAxes(SVTK_CubeAxesActor2D::New()), + myTrihedron(SVTK_Trihedron::New()), + myTrihedronSize(105) +{ + if(MYDEBUG) INFOS("SVTK_Renderer() - "<Delete(); + myTransform->Delete(); + + SetSelectionTolerance(); + myPointPicker->Delete(); + myCellPicker->Delete(); + myCellRectPicker->Delete(); + + //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() +{ + if(MYDEBUG) INFOS("~SVTK_Renderer() - "<GetActors(); + anActors->InitTraversal(); + while(vtkActor* anAct = anActors->GetNextActor()){ + if(SALOME_Actor* anActor = dynamic_cast(anAct)){ + RemoveActor(anActor); + } + } +} + + +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->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->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 ); + 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..9770f4614 --- /dev/null +++ b/src/SVTK/SVTK_Renderer.h @@ -0,0 +1,243 @@ +// 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 VTKViewer_CellRectPicker; + +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 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 625593eca..59b52a696 100644 --- a/src/SVTK/SVTK_Selector.cxx +++ b/src/SVTK/SVTK_Selector.cxx @@ -27,19 +27,29 @@ // $Header$ +#include "SVTK_SelectorDef.h" + +#include "SALOME_Actor.h" + +#include "utilities.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 +57,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 +99,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 @@ -329,3 +360,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..180149fd1 --- /dev/null +++ b/src/SVTK/SVTK_View.cxx @@ -0,0 +1,559 @@ +// 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 + +#include "utilities.h" + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + + +//---------------------------------------------------------------------------- +SVTK_SignalHandler +::SVTK_SignalHandler(SVTK_MainWindow* theMainWindow): + QObject(theMainWindow), + myMainWindow(theMainWindow) +{ + if(MYDEBUG) INFOS("SVTK_SignalHandler() - "<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() +{ + if(MYDEBUG) INFOS("~SVTK_SignalHandler() - "<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) +{ + if(MYDEBUG) INFOS("SVTK_View() - "<(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.cxx b/src/SVTK/SVTK_ViewManager.cxx index 4822bf639..25fcbdfd6 100644 --- a/src/SVTK/SVTK_ViewManager.cxx +++ b/src/SVTK/SVTK_ViewManager.cxx @@ -1,24 +1,8 @@ -// 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_ViewManager.h" #include "SVTK_ViewModel.h" +#include + int SVTK_ViewManager::_SVTKViewMgr_Id = 0; //*************************************************************** @@ -39,5 +23,5 @@ SVTK_ViewManager::~SVTK_ViewManager() void SVTK_ViewManager::setViewName(SUIT_ViewWindow* theView) { int aPos = myViews.find(theView); - theView->setCaption( tr( "VTK_VIEW_TITLE" ).arg( myId ).arg( aPos + 1 ) ); + theView->setCaption( VTKViewer_ViewManager::tr( "VTK_VIEW_TITLE" ).arg( myId ).arg( aPos + 1 ) ); } diff --git a/src/SVTK/SVTK_ViewManager.h b/src/SVTK/SVTK_ViewManager.h index ae3bf47f8..e003d7a12 100644 --- a/src/SVTK/SVTK_ViewManager.h +++ b/src/SVTK/SVTK_ViewManager.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef SVTK_VIEWMANAGER_H #define SVTK_VIEWMANAGER_H @@ -24,12 +6,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 60942b844..2215bdc96 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -1,477 +1,419 @@ -// 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 -#include - -#include -#include -#include - -#include "SUIT_Session.h" - -#include "SVTK_Selection.h" -#include "SVTK_ViewModel.h" -#include "SVTK_ViewWindow.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. - -// Temporarily commented to avoid awful dependecy on SALOMEDS -// TODO: better mechanism of storing display/erse status in a study -// should be provided... -//static _PTR(Study) getStudyDS() -//{ -// SALOMEDSClient_Study* aStudy = NULL; -// _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() ); - // get id of SUIT_Study, if it's a SalomeApp_Study, it will return - // id of its underlying SALOMEDS::Study -// SUIT_Application* app = SUIT_Session::session()->activeApplication(); -// if ( !app ) return _PTR(Study)(aStudy); -// SUIT_Study* stud = app->activeStudy(); -// if ( !stud ) return _PTR(Study)(aStudy); -// const int id = stud->id(); // virtual method, must return SALOMEDS_Study id - // get SALOMEDS_Study with this id from StudyMgr -// return aMgr->GetStudyByID( id ); -//} - -//========================================================== -SVTK_Viewer::SVTK_Viewer() -{ - myTrihedronSize = 100; -} - -//========================================================== -SVTK_Viewer::~SVTK_Viewer() -{ -} - -QColor SVTK_Viewer::backgroundColor() const -{ - return myBgColor; -} - -void SVTK_Viewer::setBackgroundColor( const QColor& c ) -{ - if ( c.isValid() ) - myBgColor = c; -} - -//========================================================== -SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop ) -{ - SVTK_ViewWindow* vw = new SVTK_ViewWindow( theDesktop, this ); - vw->setBackgroundColor( backgroundColor() ); - vw->SetTrihedronSize( trihedronSize() ); - return vw; -} - -int SVTK_Viewer::trihedronSize() const -{ - return myTrihedronSize; -} - -void SVTK_Viewer::setTrihedronSize( const int sz ) -{ - myTrihedronSize = sz; - - SUIT_ViewManager* vm = getViewManager(); - if ( !vm ) - return; - - QPtrVector vec = vm->getViews(); - for ( int i = 0; i < vec.count(); i++ ) - { - SUIT_ViewWindow* win = vec.at( i ); - if ( !win || !win->inherits( "SVTK_ViewWindow" ) ) - continue; - - SVTK_ViewWindow* vw = (SVTK_ViewWindow*)win; - vw->SetTrihedronSize( sz ); - } -} - -//========================================================== -void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager) -{ - SUIT_ViewModel::setViewManager(theViewManager); - - if ( !theViewManager ) - return; - - connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), - this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); - - connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), - this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*))); - - connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), - this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*))); -} - -//========================================================== -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 ; - } - } - } -} - -//========================================================== -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 -SVTK_Viewer -::enableSelection(bool isEnabled) -{ - mySelectionEnabled = isEnabled; - //!! To be done for view windows -} - -//========================================================== -void -SVTK_Viewer -::enableMultiselection(bool isEnable) -{ - myMultiSelectionEnabled = isEnable; - //!! To be done for view windows -} - -void SVTK_Viewer::onDumpView() -{ - SVTK_ViewWindow* aView = (SVTK_ViewWindow*)(myViewManager->getActiveView()); - if ( aView ) - aView->onDumpView(); -} - -//========================================================== -void SVTK_Viewer::onChangeBgColor() -{ - 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)){ - QColor aColor = QColorDialog::getColor( aView->backgroundColor(), aView); - if ( aColor.isValid() ) - aView->setBackgroundColor(aColor); - } -} - -//========================================================== -void -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(); -} - -//========================================================== -void -SVTK_Viewer -::Display( const SALOME_VTKPrs* prs ) -{ - // try do downcast object - if(const SVTK_Prs* aPrs = dynamic_cast( prs )){ - if(aPrs->IsNull()) - return; - if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){ - // get SALOMEDS Study - // Temporarily commented to avoid awful dependecy on SALOMEDS - // TODO: better mechanism of storing display/erse status in a study - // should be provided... - // _PTR(Study) aStudy(getStudyDS()); - anActorCollection->InitTraversal(); - while(vtkActor* anActor = anActorCollection->GetNextActor()){ - if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){ - // Set visibility flag - // Temporarily commented to avoid awful dependecy on SALOMEDS - // TODO: better mechanism of storing display/erse status in a study - // should be provided... - //Handle(SALOME_InteractiveObject) anObj = anAct->getIO(); - //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){ - // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),true,this); - //} - // 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() ); - } - } - } - } - } - } - } - } - } -} - -//========================================================== -void -SVTK_Viewer -::Erase( const SALOME_VTKPrs* prs, const bool forced ) -{ - // try do downcast object - if(const SVTK_Prs* aPrs = dynamic_cast( prs )){ - if(aPrs->IsNull()) - return; - if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){ - // get SALOMEDS Study - // Temporarily commented to avoid awful dependecy on SALOMEDS - // TODO: better mechanism of storing display/erse status in a study - // should be provided... - //_PTR(Study) aStudy(getStudyDS()); - anActorCollection->InitTraversal(); - while(vtkActor* anActor = anActorCollection->GetNextActor()) - if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){ - // Set visibility flag - // Temporarily commented to avoid awful dependecy on SALOMEDS - // TODO: better mechanism of storing display/erse status in a study - // should be provided... - //Handle(SALOME_InteractiveObject) anObj = anAct->getIO(); - //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){ - // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this); - //} - // 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); - } - } - } - } -} - -//========================================================== -void -SVTK_Viewer -::EraseAll( const bool forced ) -{ - // Temporarily commented to avoid awful dependecy on SALOMEDS - // TODO: better mechanism of storing display/erse status in a study - // should be provided... - //_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)){ - vtkRenderer* aRenderer = aView->getRenderer(); - vtkActorCollection* anActorCollection = aRenderer->GetActors(); - anActorCollection->InitTraversal(); - while(vtkActor* anActor = anActorCollection->GetNextActor()){ - if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){ - // Set visibility flag - // Temporarily commented to avoid awful dependecy on SALOMEDS - // TODO: better mechanism of storing display/erse status in a study - // should be provided... - //Handle(SALOME_InteractiveObject) anObj = anAct->getIO(); - //if(!anObj.IsNull() && anObj->hasEntry() && aStudy) - // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this); - if(forced) - aRenderer->RemoveActor(anAct); - else{ - // just erase actor - anAct->SetVisibility( false ); - // erase dependent actors - vtkActorCollection* aCollection = vtkActorCollection::New(); - anAct->GetChildActors( aCollection ); - aCollection->InitTraversal(); - while(vtkActor* aSubAct = aCollection->GetNextActor()) - aSubAct->SetVisibility( false ); - aCollection->Delete(); - } - } - } - } - } - } - Repaint(); -} - -//========================================================== -SALOME_Prs* -SVTK_Viewer -::CreatePrs( const char* entry ) -{ - 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 ); - } - } - } - return prs; -} - -//========================================================== -void -SVTK_Viewer -::BeforeDisplay( SALOME_Displayer* d ) -{ - d->BeforeDisplay( this, SALOME_VTKViewType() ); -} - -//========================================================== -void -SVTK_Viewer::AfterDisplay( SALOME_Displayer* d ) -{ - d->AfterDisplay( this, SALOME_VTKViewType() ); -} - -//========================================================== -bool -SVTK_Viewer -::isVisible( const Handle(SALOME_InteractiveObject)& io ) -{ - 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; - return true; -} - -//========================================================== -void -SVTK_Viewer -::Repaint() -{ -// 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(); -} - -void -SVTK_Viewer -::onSelectionChanged() -{ - emit selectionChanged(); -} - +#include +#include + +#include +#include +#include + +#include "SUIT_Session.h" + +#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 "SALOME_Actor.h" +#include "SALOME_InteractiveObject.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. + +// Temporarily commented to avoid awful dependecy on SALOMEDS +// TODO: better mechanism of storing display/erse status in a study +// should be provided... +//static _PTR(Study) getStudyDS() +//{ +// SALOMEDSClient_Study* aStudy = NULL; +// _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() ); + // get id of SUIT_Study, if it's a SalomeApp_Study, it will return + // id of its underlying SALOMEDS::Study +// SUIT_Application* app = SUIT_Session::session()->activeApplication(); +// if ( !app ) return _PTR(Study)(aStudy); +// SUIT_Study* stud = app->activeStudy(); +// if ( !stud ) return _PTR(Study)(aStudy); +// const int id = stud->id(); // virtual method, must return SALOMEDS_Study id + // get SALOMEDS_Study with this id from StudyMgr +// return aMgr->GetStudyByID( id ); +//} + +//========================================================== +SVTK_Viewer::SVTK_Viewer() +{ + myTrihedronSize = 105; +} + +//========================================================== +SVTK_Viewer::~SVTK_Viewer() +{ +} + +QColor +SVTK_Viewer +::backgroundColor() const +{ + return myBgColor; +} + +void +SVTK_Viewer +::setBackgroundColor( const QColor& theColor ) +{ + 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 ) +{ + SVTK_ViewWindow* aViewWindow = new SVTK_ViewWindow(theDesktop); + aViewWindow->Initialize(this); + + aViewWindow->setBackgroundColor( backgroundColor() ); + aViewWindow->SetTrihedronSize( trihedronSize() ); + + return aViewWindow; +} + +int SVTK_Viewer::trihedronSize() const +{ + return myTrihedronSize; +} + +void SVTK_Viewer::setTrihedronSize( const int sz ) +{ + myTrihedronSize = sz; + + SUIT_ViewManager* vm = getViewManager(); + if ( !vm ) + return; + + QPtrVector vec = vm->getViews(); + for ( int i = 0; i < vec.count(); i++ ) + { + SUIT_ViewWindow* win = vec.at( i ); + if ( !win || !win->inherits( "SVTK_ViewWindow" ) ) + continue; + + SVTK_ViewWindow* vw = (SVTK_ViewWindow*)win; + vw->SetTrihedronSize( sz ); + } +} + +//========================================================== +void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager) +{ + SUIT_ViewModel::setViewManager(theViewManager); + + if ( !theViewManager ) + return; + + connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), + this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + + connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), + this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*))); + + connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), + this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*))); +} + +//========================================================== +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(); + + 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) +{} + +//========================================================== +void +SVTK_Viewer +::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event) +{} + +//========================================================== +void +SVTK_Viewer +::enableSelection(bool isEnabled) +{ + mySelectionEnabled = isEnabled; + //!! To be done for view windows +} + +//========================================================== +void +SVTK_Viewer +::enableMultiselection(bool isEnable) +{ + myMultiSelectionEnabled = isEnable; + //!! To be done for view windows +} + +void +SVTK_Viewer +::onDumpView() +{ + if(SUIT_ViewWindow* aView = myViewManager->getActiveView()) + aView->onDumpView(); +} + +//========================================================== +void +SVTK_Viewer +::onChangeBgColor() +{ + if(SUIT_ViewWindow* aView = myViewManager->getActiveView()){ + QColor aColor = QColorDialog::getColor( backgroundColor(), aView); + setBackgroundColor(aColor); + } +} + +//========================================================== +void +SVTK_Viewer +::onShowToolbar() +{ + QPtrVector aViews = myViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ + if(TViewWindow* aView = dynamic_cast(aViews.at(i))){ + aView->getView()->GetMainWindow()->getToolBar()->show(); + } + } +} + +//========================================================== +void +SVTK_Viewer +::Display( const SALOME_VTKPrs* prs ) +{ + // try do downcast object + if(const SVTK_Prs* aPrs = dynamic_cast( prs )){ + if(aPrs->IsNull()) + return; + if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){ + // get SALOMEDS Study + // Temporarily commented to avoid awful dependecy on SALOMEDS + // TODO: better mechanism of storing display/erse status in a study + // should be provided... + // _PTR(Study) aStudy(getStudyDS()); + anActorCollection->InitTraversal(); + while(vtkActor* anActor = anActorCollection->GetNextActor()){ + if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){ + // Set visibility flag + // Temporarily commented to avoid awful dependecy on SALOMEDS + // TODO: better mechanism of storing display/erse status in a study + // should be provided... + //Handle(SALOME_InteractiveObject) anObj = anAct->getIO(); + //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){ + // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),true,this); + //} + // just display the object + QPtrVector aViews = myViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ + 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() ); + } + } + } + } + } + } + } + } +} + +//========================================================== +void +SVTK_Viewer +::Erase( const SALOME_VTKPrs* prs, const bool forced ) +{ + // try do downcast object + if(const SVTK_Prs* aPrs = dynamic_cast( prs )){ + if(aPrs->IsNull()) + return; + if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){ + // get SALOMEDS Study + // Temporarily commented to avoid awful dependecy on SALOMEDS + // TODO: better mechanism of storing display/erse status in a study + // should be provided... + //_PTR(Study) aStudy(getStudyDS()); + anActorCollection->InitTraversal(); + while(vtkActor* anActor = anActorCollection->GetNextActor()) + if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){ + // Set visibility flag + // Temporarily commented to avoid awful dependecy on SALOMEDS + // TODO: better mechanism of storing display/erse status in a study + // should be provided... + //Handle(SALOME_InteractiveObject) anObj = anAct->getIO(); + //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){ + // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this); + //} + // just display the object + QPtrVector aViews = myViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ + 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); + } + } + } + } +} + +//========================================================== +void +SVTK_Viewer +::EraseAll( const bool forced ) +{ + // Temporarily commented to avoid awful dependecy on SALOMEDS + // TODO: better mechanism of storing display/erse status in a study + // should be provided... + //_PTR(Study) aStudy(getStudyDS()); + QPtrVector aViews = myViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ + 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(); + while(vtkActor* anActor = anActorCollection->GetNextActor()){ + if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){ + // Set visibility flag + // Temporarily commented to avoid awful dependecy on SALOMEDS + // TODO: better mechanism of storing display/erse status in a study + // should be provided... + //Handle(SALOME_InteractiveObject) anObj = anAct->getIO(); + //if(!anObj.IsNull() && anObj->hasEntry() && aStudy) + // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this); + if(forced) + aRenderer->RemoveActor(anAct); + else{ + // just erase actor + anAct->SetVisibility( false ); + // erase dependent actors + vtkActorCollection* aCollection = vtkActorCollection::New(); + anAct->GetChildActors( aCollection ); + aCollection->InitTraversal(); + while(vtkActor* aSubAct = aCollection->GetNextActor()) + aSubAct->SetVisibility( false ); + aCollection->Delete(); + } + } + } + } + } + Repaint(); +} + +//========================================================== +SALOME_Prs* +SVTK_Viewer +::CreatePrs( const char* entry ) +{ + SVTK_Prs* prs = new SVTK_Prs(); + if ( entry ) { + 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; +} + +//========================================================== +void +SVTK_Viewer +::BeforeDisplay( SALOME_Displayer* d ) +{ + d->BeforeDisplay( this, SALOME_VTKViewType() ); +} + +//========================================================== +void +SVTK_Viewer::AfterDisplay( SALOME_Displayer* d ) +{ + d->AfterDisplay( this, SALOME_VTKViewType() ); +} + +//========================================================== +bool +SVTK_Viewer +::isVisible( const Handle(SALOME_InteractiveObject)& io ) +{ + QPtrVector aViews = myViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))) + if(SVTK_View* aView = aViewWindow->getView()) + if(!aView->isVisible( io )) + return false; + + return true; +} + +//========================================================== +void +SVTK_Viewer +::Repaint() +{ +// if (theUpdateTrihedron) onAdjustTrihedron(); + QPtrVector aViews = myViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))) + if(SVTK_View* aView = aViewWindow->getView()) + aView->Repaint(); +} diff --git a/src/SVTK/SVTK_ViewModel.h b/src/SVTK/SVTK_ViewModel.h index 7e70759fa..03a593f51 100644 --- a/src/SVTK/SVTK_ViewModel.h +++ b/src/SVTK/SVTK_ViewModel.h @@ -1,53 +1,54 @@ -// 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/ -// #ifndef SVTK_VIEWMODEL_H #define SVTK_VIEWMODEL_H #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 +60,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 cbe8d968c..9e91d02f0 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -1,24 +1,9 @@ -// 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 "SALOME_Actor.h" #include +#include +#include +#include #include #include @@ -26,360 +11,164 @@ #include #include #include +#include +#include #include "QtxAction.h" #include "SUIT_Session.h" #include "SUIT_ToolButton.h" #include "SUIT_MessageBox.h" -#include "SUIT_Accel.h" #include "SUIT_Tools.h" #include "SUIT_ResourceMgr.h" +#include "SUIT_Accel.h" -#include "VTKViewer_Transform.h" #include "VTKViewer_Utilities.h" +#include "VTKViewer_CellRectPicker.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); + + 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 +176,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 +184,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 +192,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 +200,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 +208,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 +216,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 +224,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 +232,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 +240,7 @@ void SVTK_ViewWindow ::SetSelectionMode(Selection_Mode theMode) { - mySelector->SetSelectionMode(theMode); - myRWInteractor->SetSelectionMode(theMode); + myMainWindow->SetSelectionMode( theMode ); } //---------------------------------------------------------------- @@ -544,7 +248,7 @@ Selection_Mode SVTK_ViewWindow ::SelectionMode() const { - return mySelector->SelectionMode(); + return myMainWindow->SelectionMode(); } //---------------------------------------------------------------- @@ -552,43 +256,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 +274,7 @@ bool SVTK_ViewWindow ::isInViewer( const Handle(SALOME_InteractiveObject)& theIO ) { - return myRWInteractor->isInViewer( theIO ); + return myView->isInViewer( theIO ); } //---------------------------------------------------------------- @@ -604,7 +282,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 +328,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 +336,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 +344,7 @@ void SVTK_ViewWindow ::Repaint(bool theUpdateTrihedron) { - if (theUpdateTrihedron) - onAdjustTrihedron(); - myRenderWindow->update(); + myMainWindow->Repaint( theUpdateTrihedron ); } //---------------------------------------------------------------------------- @@ -644,7 +352,7 @@ void SVTK_ViewWindow ::GetScale( double theScale[3] ) { - myTransform->GetMatrixScale( theScale ); + myMainWindow->GetScale( theScale ); } //---------------------------------------------------------------------------- @@ -652,9 +360,7 @@ void SVTK_ViewWindow ::SetScale( double theScale[3] ) { - myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] ); - myRWInteractor->Render(); - Repaint(); + myMainWindow->SetScale( theScale ); } //---------------------------------------------------------------------------- @@ -662,14 +368,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,83 +383,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; - - // 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; -}*/ + return myMainWindow->GetTrihedron(); +} -//---------------------------------------------------------------------------- -int SVTK_ViewWindow::GetTrihedronSize() const +SVTK_CubeAxesActor2D* +SVTK_ViewWindow +::GetCubeAxes() { - return myTrihedronSize; + return myMainWindow->GetCubeAxes(); } -void SVTK_ViewWindow::SetTrihedronSize( const int sz ) +int +SVTK_ViewWindow +::GetTrihedronSize() const { - if ( myTrihedronSize == sz ) - return; + return myMainWindow->GetTrihedronSize(); +} - myTrihedronSize = sz; - AdjustTrihedrons( true ); +void +SVTK_ViewWindow +::SetTrihedronSize(const int theSize) +{ + myMainWindow->SetTrihedronSize(theSize); } /*! If parameter theIsForcedUpdate is true, recalculate parameters for @@ -763,74 +429,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 ); - //if (aVisibleNum || theIsForcedUpdate) { - if (aVisibleNum) { - // 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(); - - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QString aSetting = aResMgr->stringValue("Viewer", "TrihedronSize", "105"); - static float aSizeInPercents = aSetting.toFloat(); - - //bool isComputeTrihedronSize = - ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, aSizeInPercents); - - 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(); } //---------------------------------------------------------------------------- @@ -838,115 +437,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(); } //======================================================================= @@ -997,82 +495,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..2aa64c5fa 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef SVTK_VIEWWINDOW_H #define SVTK_VIEWWINDOW_H @@ -24,132 +6,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 +302,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_DataModel.cxx b/src/SalomeApp/SalomeApp_DataModel.cxx index 48838709e..1b2995e9b 100644 --- a/src/SalomeApp/SalomeApp_DataModel.cxx +++ b/src/SalomeApp/SalomeApp_DataModel.cxx @@ -132,36 +132,87 @@ bool SalomeApp_DataModel::open( const QString& name, CAM_Study* study, QStringLi // Function : update /*! Purpose : Update application.*/ //================================================================ -void SalomeApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study ) +namespace { - SalomeApp_Study* aSStudy = dynamic_cast(study); - LightApp_RootObject* studyRoot = 0; - _PTR(SObject) sobj; - SalomeApp_DataObject* modelRoot = dynamic_cast( root() ); - if ( !modelRoot ){ // not yet connected to a study -> try using argument + LightApp_DataObject* FindDataObject(const _PTR(SObject)& theSObject, + SUIT_DataObject* theDataObject) + { + std::string anID = theSObject->GetID(); + DataObjectList aList; + theDataObject->children(aList); + DataObjectListIterator aDataObjectIter(aList); + while(SUIT_DataObject* aDataObject = aDataObjectIter.current()){ + if(LightApp_DataObject* aChildDataObject = dynamic_cast(aDataObject)){ + QString anEntry = aChildDataObject->entry(); + if(anID == anEntry.latin1()) + return aChildDataObject; + } + ++aDataObjectIter; + } + return NULL; + } + + void BuildTree(const _PTR(SObject)& theSObject, + SUIT_DataObject* theDataObject, + const _PTR(Study)& theStudyDS) + { + _PTR(ChildIterator) aSObjectIter(theStudyDS->NewChildIterator(theSObject)); + for(; aSObjectIter->More(); aSObjectIter->Next()){ + _PTR(SObject) aChildSObject(aSObjectIter->Value()); + std::string aName = aChildSObject->GetName(); + if(aName.empty()) + continue; + SUIT_DataObject* aChildDataObject = FindDataObject(aChildSObject,theDataObject); + if(!aChildDataObject) + aChildDataObject = new SalomeApp_DataObject(aChildSObject,theDataObject); + BuildTree(aChildSObject,aChildDataObject,theStudyDS); + } + } +} + +void SalomeApp_DataModel::update( LightApp_DataObject* theDataObject, LightApp_Study* theStudy ) +{ + SalomeApp_Study* aSStudy = dynamic_cast(theStudy); + _PTR(SObject) aSObject; + LightApp_RootObject* aRootObject = NULL; + SalomeApp_DataObject* aModelRoot = dynamic_cast( root() ); + if ( !aModelRoot ){ // not yet connected to a study -> try using argument if ( !aSStudy ) aSStudy = dynamic_cast( getModule()->getApp()->activeStudy() ); if ( aSStudy ){ - studyRoot = dynamic_cast( aSStudy->root() ); + aRootObject = dynamic_cast( aSStudy->root() ); QString anId = getRootEntry( aSStudy ); if ( !anId.isEmpty() ){ // if nothing is published in the study for this module -> do nothing _PTR(Study) aStudy ( aSStudy->studyDS() ); - sobj = aStudy->FindComponentID( std::string( anId.latin1() ) ); + aSObject = aStudy->FindComponentID( std::string( anId.latin1() ) ); } } } else{ - studyRoot = dynamic_cast( modelRoot->root() ); - if ( studyRoot ) { - aSStudy = dynamic_cast( studyRoot->study() ); // value should not change here theoretically, but just to make sure + aRootObject = dynamic_cast( aModelRoot->root() ); + if ( aRootObject ) { + aSStudy = dynamic_cast( aRootObject->study() ); // value should not change here theoretically, but just to make sure if ( aSStudy ) { _PTR(Study) aStudy ( aSStudy->studyDS() ); - // modelRoot->object() cannot be reused here: it is about to be deleted by buildTree() soon - sobj = aStudy->FindComponentID( std::string( modelRoot->entry().latin1() ) ); + // aModelRoot->object() cannot be reused here: it is about to be deleted by buildTree() soon + aSObject = aStudy->FindComponentID( aModelRoot->entry().latin1() ); } } } - buildTree( sobj, studyRoot, aSStudy ); + if(!theDataObject) + buildTree( aSObject, aRootObject, aSStudy ); + else{ + _PTR(Study) aStudyDS(aSStudy->studyDS()); + QString anEntry = theDataObject->entry(); + if(_PTR(SObject) aSObject = aStudyDS->FindObjectID(anEntry.latin1())){ + std::string aName = aSObject->GetName(); + if(aName.empty()){ + if(SUIT_DataObject* aParentDataObject = theDataObject->parent()) + aParentDataObject->removeChild(theDataObject); + }else + ::BuildTree(aSObject,theDataObject,aStudyDS); + } + } } //================================================================ diff --git a/src/SalomeApp/resources/SalomeApp.xml b/src/SalomeApp/resources/SalomeApp.xml index 5b525482a..60ae73502 100644 --- a/src/SalomeApp/resources/SalomeApp.xml +++ b/src/SalomeApp/resources/SalomeApp.xml @@ -23,7 +23,7 @@
- +
@@ -157,7 +157,6 @@ -
@@ -184,6 +183,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/VTKViewer/Makefile.in b/src/VTKViewer/Makefile.in index 4c72c0d5c..f36e73620 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 \ @@ -70,23 +75,6 @@ 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) diff --git a/src/VTKViewer/VTKViewer.h b/src/VTKViewer/VTKViewer.h index 27934b610..58fc3055b 100755 --- a/src/VTKViewer/VTKViewer.h +++ b/src/VTKViewer/VTKViewer.h @@ -1,21 +1,3 @@ -// 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/ -// #ifdef WNT #ifdef VTKVIEWER_EXPORTS #define VTKVIEWER_EXPORT __declspec( dllexport ) diff --git a/src/VTKViewer/VTKViewer_Actor.cxx b/src/VTKViewer/VTKViewer_Actor.cxx index 7b9e00353..5f71ef5dd 100755 --- a/src/VTKViewer/VTKViewer_Actor.cxx +++ b/src/VTKViewer/VTKViewer_Actor.cxx @@ -1,21 +1,3 @@ -// 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 "VTKViewer_Actor.h" #include "VTKViewer_Transform.h" #include "VTKViewer_GeometryFilter.h" diff --git a/src/VTKViewer/VTKViewer_Actor.h b/src/VTKViewer/VTKViewer_Actor.h index 2a4371200..ad050d321 100755 --- a/src/VTKViewer/VTKViewer_Actor.h +++ b/src/VTKViewer/VTKViewer_Actor.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEVER_ACTOR_H #define 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_CellRectPicker.cxx b/src/VTKViewer/VTKViewer_CellRectPicker.cxx index 36b1741b5..e6647d908 100755 --- a/src/VTKViewer/VTKViewer_CellRectPicker.cxx +++ b/src/VTKViewer/VTKViewer_CellRectPicker.cxx @@ -1,21 +1,3 @@ -// 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 #include "vtkGenericCell.h" diff --git a/src/VTKViewer/VTKViewer_ConvexTool.cxx b/src/VTKViewer/VTKViewer_ConvexTool.cxx index 1bb641de8..64e712e97 100644 --- a/src/VTKViewer/VTKViewer_ConvexTool.cxx +++ b/src/VTKViewer/VTKViewer_ConvexTool.cxx @@ -1,21 +1,3 @@ -// 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/ -// // 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 diff --git a/src/VTKViewer/VTKViewer_ExtractUnstructuredGrid.h b/src/VTKViewer/VTKViewer_ExtractUnstructuredGrid.h index a820bd25b..acdbddb84 100755 --- a/src/VTKViewer/VTKViewer_ExtractUnstructuredGrid.h +++ b/src/VTKViewer/VTKViewer_ExtractUnstructuredGrid.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEWER_EXTRACTUNSTRUCTUREDGRID_H #define VTKVIEWER_EXTRACTUNSTRUCTUREDGRID_H diff --git a/src/VTKViewer/VTKViewer_GeometryFilter.cxx b/src/VTKViewer/VTKViewer_GeometryFilter.cxx index 10dec386c..d1baa5b11 100755 --- a/src/VTKViewer/VTKViewer_GeometryFilter.cxx +++ b/src/VTKViewer/VTKViewer_GeometryFilter.cxx @@ -51,24 +51,20 @@ using namespace std; -#ifdef _DEBUG_ -static int MYDEBUG = 0; -#else -static int MYDEBUG = 0; -#endif - #if defined __GNUC__ #if __GNUC__ == 2 #define __GNUC_2__ #endif #endif +//---------------------------------------------------------------------------- vtkCxxRevisionMacro(VTKViewer_GeometryFilter, "$Revision$"); vtkStandardNewMacro(VTKViewer_GeometryFilter); VTKViewer_GeometryFilter::VTKViewer_GeometryFilter(): myShowInside(0), - myStoreMapping(0) + myStoreMapping(0), + myIsWireframeMode(0) {} @@ -76,6 +72,7 @@ VTKViewer_GeometryFilter::~VTKViewer_GeometryFilter() {} +//---------------------------------------------------------------------------- void VTKViewer_GeometryFilter::Execute() { vtkDataSet *input= this->GetInput(); @@ -94,22 +91,7 @@ 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() { vtkUnstructuredGrid *input= (vtkUnstructuredGrid *)this->GetInput(); @@ -128,7 +110,6 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() vtkPointData *outputPD = output->GetPointData(); vtkCellData *outputCD = output->GetCellData(); - //vtkCellArray *Verts, *Lines, *Polys, *Strips; vtkIdList *cellIds, *faceIds; char *cellVis; vtkIdType newCellId; @@ -190,14 +171,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 +251,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,25 +260,22 @@ 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; @@ -350,20 +319,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 +344,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 +369,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 +393,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,223 +423,319 @@ 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); - - 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 + case VTK_QUADRATIC_EDGE: + case VTK_QUADRATIC_TRIANGLE: + case VTK_QUADRATIC_QUAD: + case VTK_QUADRATIC_TETRA: + case VTK_QUADRATIC_HEXAHEDRON: + if(!myIsWireframeMode){ + vtkGenericCell *cell = vtkGenericCell::New(); + 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(); + cell->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); + + //--------------------------------------------------------------- + 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[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); + + //--------------------------------------------------------------- + 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; + } + 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," @@ -697,11 +750,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..fc46ef294 100755 --- a/src/VTKViewer/VTKViewer_GeometryFilter.h +++ b/src/VTKViewer/VTKViewer_GeometryFilter.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEWER_GEOMETRYFILTER_H #define VTKVIEWER_GEOMETRYFILTER_H @@ -47,6 +29,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 +48,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 +85,7 @@ private: TVectorId myVTK2ObjIds; int myShowInside; int myStoreMapping; + int myIsWireframeMode; }; #endif diff --git a/src/VTKViewer/VTKViewer_PassThroughFilter.h b/src/VTKViewer/VTKViewer_PassThroughFilter.h index 09bc8149f..0cacb2531 100755 --- a/src/VTKViewer/VTKViewer_PassThroughFilter.h +++ b/src/VTKViewer/VTKViewer_PassThroughFilter.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEWER_PASSTHROUGHFILTER_H #define VTKVIEWER_PASSTHROUGHFILTER_H diff --git a/src/VTKViewer/VTKViewer_RenderWindow.cxx b/src/VTKViewer/VTKViewer_RenderWindow.cxx index a6ccdfd6a..cfffd5671 100755 --- a/src/VTKViewer/VTKViewer_RenderWindow.cxx +++ b/src/VTKViewer/VTKViewer_RenderWindow.cxx @@ -1,21 +1,3 @@ -// 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 "VTKViewer_RenderWindow.h" #include diff --git a/src/VTKViewer/VTKViewer_RenderWindow.h b/src/VTKViewer/VTKViewer_RenderWindow.h index c83b0307e..e535d3c1d 100755 --- a/src/VTKViewer/VTKViewer_RenderWindow.h +++ b/src/VTKViewer/VTKViewer_RenderWindow.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEWER_RENDERWINDOW_H #define VTKVIEWER_RENDERWINDOW_H diff --git a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx index db601ab4a..bba404e1f 100755 --- a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx +++ b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx @@ -1,21 +1,3 @@ -// 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 "VTKViewer_RenderWindowInteractor.h" #include "VTKViewer_RenderWindow.h" #include "VTKViewer_InteractorStyle.h" diff --git a/src/VTKViewer/VTKViewer_RenderWindowInteractor.h b/src/VTKViewer/VTKViewer_RenderWindowInteractor.h index 9d06598b8..16aa877fd 100755 --- a/src/VTKViewer/VTKViewer_RenderWindowInteractor.h +++ b/src/VTKViewer/VTKViewer_RenderWindowInteractor.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEWER_RENDERWINDOWINTERACTOR_H #define VTKVIEWER_RENDERWINDOWINTERACTOR_H diff --git a/src/VTKViewer/VTKViewer_ShrinkFilter.h b/src/VTKViewer/VTKViewer_ShrinkFilter.h index 9b60d4978..51b4e6624 100755 --- a/src/VTKViewer/VTKViewer_ShrinkFilter.h +++ b/src/VTKViewer/VTKViewer_ShrinkFilter.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEWER_SHRINKFILTER_H #define VTKVIEWER_SHRINKFILTER_H diff --git a/src/VTKViewer/VTKViewer_Transform.h b/src/VTKViewer/VTKViewer_Transform.h index 478d982c6..25b6d07be 100755 --- a/src/VTKViewer/VTKViewer_Transform.h +++ b/src/VTKViewer/VTKViewer_Transform.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEWER_TRANSFORM_H #define VTKVIEWER_TRANSFORM_H diff --git a/src/VTKViewer/VTKViewer_TransformFilter.h b/src/VTKViewer/VTKViewer_TransformFilter.h index ecc2b3cb2..c82b63298 100755 --- a/src/VTKViewer/VTKViewer_TransformFilter.h +++ b/src/VTKViewer/VTKViewer_TransformFilter.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEWER_TRANSFORMFILTER_H #define VTKVIEWER_TRANSFORMFILTER_H diff --git a/src/VTKViewer/VTKViewer_Trihedron.cxx b/src/VTKViewer/VTKViewer_Trihedron.cxx index a6670cb87..9ff5e6946 100755 --- a/src/VTKViewer/VTKViewer_Trihedron.cxx +++ b/src/VTKViewer/VTKViewer_Trihedron.cxx @@ -1,21 +1,3 @@ -// 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 "VTKViewer_Trihedron.h" #include "VTKViewer_Actor.h" diff --git a/src/VTKViewer/VTKViewer_Trihedron.h b/src/VTKViewer/VTKViewer_Trihedron.h index e40e3bc90..74aebace8 100755 --- a/src/VTKViewer/VTKViewer_Trihedron.h +++ b/src/VTKViewer/VTKViewer_Trihedron.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEWER_TRIHEDRON_H #define VTKVIEWER_TRIHEDRON_H diff --git a/src/VTKViewer/VTKViewer_Utilities.cxx b/src/VTKViewer/VTKViewer_Utilities.cxx index a05b0a36f..9ed586d6f 100755 --- a/src/VTKViewer/VTKViewer_Utilities.cxx +++ b/src/VTKViewer/VTKViewer_Utilities.cxx @@ -1,21 +1,3 @@ -// 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 "VTKViewer_Actor.h" // VTK Includes diff --git a/src/VTKViewer/VTKViewer_Utilities.h b/src/VTKViewer/VTKViewer_Utilities.h index 6341e885d..d733fc541 100755 --- a/src/VTKViewer/VTKViewer_Utilities.h +++ b/src/VTKViewer/VTKViewer_Utilities.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEWER_UTILITIES_H #define VTKVIEWER_UTILITIES_H diff --git a/src/VTKViewer/VTKViewer_VectorText.cxx b/src/VTKViewer/VTKViewer_VectorText.cxx index b4e62266a..1fd9d6a19 100755 --- a/src/VTKViewer/VTKViewer_VectorText.cxx +++ b/src/VTKViewer/VTKViewer_VectorText.cxx @@ -1,21 +1,3 @@ -// 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/ -// /*========================================================================= Program: Visualization Toolkit diff --git a/src/VTKViewer/VTKViewer_VectorText.h b/src/VTKViewer/VTKViewer_VectorText.h index 8ce64cdd4..15c6a57f3 100755 --- a/src/VTKViewer/VTKViewer_VectorText.h +++ b/src/VTKViewer/VTKViewer_VectorText.h @@ -1,21 +1,3 @@ -// 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/ -// /*========================================================================= Program: Visualization Toolkit diff --git a/src/VTKViewer/VTKViewer_ViewManager.cxx b/src/VTKViewer/VTKViewer_ViewManager.cxx index 2dedb7984..4ce4414ab 100755 --- a/src/VTKViewer/VTKViewer_ViewManager.cxx +++ b/src/VTKViewer/VTKViewer_ViewManager.cxx @@ -1,21 +1,3 @@ -// 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 "VTKViewer_ViewManager.h" #include "VTKViewer_ViewModel.h" diff --git a/src/VTKViewer/VTKViewer_ViewManager.h b/src/VTKViewer/VTKViewer_ViewManager.h index 03f6d21da..1d23edaca 100755 --- a/src/VTKViewer/VTKViewer_ViewManager.h +++ b/src/VTKViewer/VTKViewer_ViewManager.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEWER_VIEWMANAGER_H #define VTKVIEWER_VIEWMANAGER_H diff --git a/src/VTKViewer/VTKViewer_ViewModel.cxx b/src/VTKViewer/VTKViewer_ViewModel.cxx index f8fd9913e..b762a6a5e 100755 --- a/src/VTKViewer/VTKViewer_ViewModel.cxx +++ b/src/VTKViewer/VTKViewer_ViewModel.cxx @@ -1,21 +1,3 @@ -// 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 "VTKViewer_ViewModel.h" #include "VTKViewer_ViewWindow.h" #include "VTKViewer_ViewManager.h" diff --git a/src/VTKViewer/VTKViewer_ViewModel.h b/src/VTKViewer/VTKViewer_ViewModel.h index 0ca65ab79..efd3078a0 100755 --- a/src/VTKViewer/VTKViewer_ViewModel.h +++ b/src/VTKViewer/VTKViewer_ViewModel.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEWER_VIEWMODEL_H #define VTKVIEWER_VIEWMODEL_H diff --git a/src/VTKViewer/VTKViewer_ViewWindow.cxx b/src/VTKViewer/VTKViewer_ViewWindow.cxx index d4500095a..405462b59 100755 --- a/src/VTKViewer/VTKViewer_ViewWindow.cxx +++ b/src/VTKViewer/VTKViewer_ViewWindow.cxx @@ -1,21 +1,3 @@ -// 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 "VTKViewer_ViewWindow.h" #include "VTKViewer_ViewModel.h" #include "VTKViewer_RenderWindow.h" diff --git a/src/VTKViewer/VTKViewer_ViewWindow.h b/src/VTKViewer/VTKViewer_ViewWindow.h index 951d96d4c..6b95c671e 100755 --- a/src/VTKViewer/VTKViewer_ViewWindow.h +++ b/src/VTKViewer/VTKViewer_ViewWindow.h @@ -1,21 +1,3 @@ -// 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/ -// #ifndef VTKVIEWER_VIEWWINDOW_H #define VTKVIEWER_VIEWWINDOW_H 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 000000000..9c9f3d20f Binary files /dev/null and b/src/VTKViewer/resources/view_graduated_axes.png differ diff --git a/src/VTKViewer/resources/view_scaling.png b/src/VTKViewer/resources/view_scaling.png new file mode 100644 index 000000000..5d3443634 Binary files /dev/null and b/src/VTKViewer/resources/view_scaling.png differ