From 08c34c8d3f0e4c5c8db1a208fe1ee288665f23d0 Mon Sep 17 00:00:00 2001 From: srn Date: Mon, 6 Feb 2006 11:25:01 +0000 Subject: [PATCH] update of the package --- src/CAM/CAM_Application.cxx | 39 +- src/LightApp/LightApp_Module.cxx | 46 +- src/LightApp/LightApp_Module.h | 3 - src/LightApp/LightApp_OBSelector.cxx | 19 +- src/LightApp/LightApp_OBSelector.h | 7 + src/LightApp/LightApp_PreferencesDlg.cxx | 25 +- src/LightApp/LightApp_PreferencesDlg.h | 1 + src/LightApp/LightApp_Study.cxx | 12 + src/LightApp/LightApp_VTKSelector.cxx | 25 +- src/LightApp/LightApp_VTKSelector.h | 8 +- src/OBJECT/Makefile.in | 2 - src/OBJECT/SALOME_Actor.cxx | 308 ----------- src/OBJECT/SALOME_Actor.h | 187 ------- src/ObjBrowser/OB_Browser.cxx | 271 ++++++--- src/ObjBrowser/OB_Browser.h | 14 +- src/ObjBrowser/OB_ListItem.cxx | 65 +-- src/ObjBrowser/OB_ListItem.h | 6 +- src/QDS/QDS_CheckBox.cxx | 30 +- src/QDS/QDS_CheckBox.h | 3 + src/QDS/QDS_ComboBox.cxx | 12 + src/QDS/QDS_Datum.cxx | 16 + src/QDS/QDS_Datum.h | 8 +- src/QDS/QDS_LineEdit.h | 2 +- src/QDS/QDS_RadioBox.cxx | 379 +++++++++++++ src/QDS/QDS_RadioBox.h | 75 +++ src/Qtx/QtxResourceMgr.cxx | 76 ++- src/Qtx/QtxResourceMgr.h | 16 +- src/Qtx/QtxToolTip.cxx | 2 +- src/SALOME_PY/SalomePy.cxx | 6 +- src/SUIT/Makefile.in | 3 +- src/SUIT/SUIT_Application.cxx | 21 +- src/SUIT/SUIT_FileDlg.cxx | 16 + src/SUIT/SUIT_FileDlg.h | 3 + src/SUIT/SUIT_Operation.h | 18 +- src/SUIT/SUIT_TreeSync.h | 177 ++++++ src/SUIT/SUIT_ViewWindow.cxx | 13 - src/SUIT/SUIT_ViewWindow.h | 3 - src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx | 1 + src/SUPERVGraph/SUPERVGraph_ViewModel.h | 1 + src/SalomeApp/Makefile.in | 2 - src/SalomeApp/SalomeApp.h | 1 - src/SalomeApp/SalomeApp_Application.cxx | 21 +- src/SalomeApp/SalomeApp_Application.h | 3 - src/SalomeApp/SalomeApp_DataModel.cxx | 279 +++++++--- src/SalomeApp/SalomeApp_DataModel.h | 11 +- src/SalomeApp/SalomeApp_DataObject.cxx | 4 +- src/VTKViewer/Makefile.in | 9 +- src/VTKViewer/VTKViewer.cxx | 57 ++ src/VTKViewer/VTKViewer_Actor.cxx | 521 ++++++++++++------ src/VTKViewer/VTKViewer_Actor.h | 389 +++++++++---- src/VTKViewer/VTKViewer_GeometryFilter.cxx | 385 +++++++++++-- src/VTKViewer/VTKViewer_InteractorStyle.cxx | 1 + .../VTKViewer_RenderWindowInteractor.cxx | 1 + 53 files changed, 2469 insertions(+), 1134 deletions(-) delete mode 100755 src/OBJECT/SALOME_Actor.cxx delete mode 100755 src/OBJECT/SALOME_Actor.h create mode 100644 src/QDS/QDS_RadioBox.cxx create mode 100644 src/QDS/QDS_RadioBox.h create mode 100644 src/SUIT/SUIT_TreeSync.h create mode 100644 src/VTKViewer/VTKViewer.cxx diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index eb7060abd..ef7cd09e4 100755 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef WIN32 #include @@ -428,31 +429,23 @@ void CAM_Application::readModuleList() QStringList modList; - // parse command line arguments - int nbArgs = qApp->argc(); - char** CmdLine = qApp->argv(); - QString CmdStr; - for ( int i = 0; i < nbArgs; i++ ) - { - CmdStr.append(CmdLine[i]); - CmdStr.append(" "); - } - int startId = CmdStr.find("--modules ("); - if ( startId != -1 ) { // application launch with --modules option - startId = CmdStr.find("(", startId); - int stopId = CmdStr.find(" )", startId); - QString ModStr = CmdStr.mid( startId+1, stopId - (startId+1) ).stripWhiteSpace(); - int i = 0; - while ( i < ModStr.length() ) - { - int nextId = ModStr.find( ":", i ); - modList.append( ModStr.mid( i, nextId - i ).stripWhiteSpace() ); - i = nextId + 1; + QStringList args; + for (int i = 1; i < qApp->argc(); i++) + args.append( qApp->argv()[i] ); + + QRegExp rx("--modules\\s+\\(\\s*(.*)\\s*\\)"); + rx.setMinimal( true ); + if ( rx.search( args.join(" ") ) >= 0 && rx.capturedTexts().count() > 0 ) { + QString modules = rx.capturedTexts()[1]; + QStringList mods = QStringList::split(":",modules,false); + for ( uint i = 0; i < mods.count(); i++ ) { + if ( !mods[i].stripWhiteSpace().isEmpty() ) + modList.append( mods[i].stripWhiteSpace() ); } } - else { - QString modStr = resMgr->stringValue( "launch", "modules", QString::null ); - modList = QStringList::split( ",", modStr ); + if ( modList.isEmpty() ) { + QString mods = resMgr->stringValue( "launch", "modules", QString::null ); + modList = QStringList::split( ",", mods ); } for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it ) diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index 4d09dca2f..6b4de40b6 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -9,6 +9,7 @@ #include "LightApp_Application.h" #include "LightApp_DataModel.h" +#include "LightApp_DataObject.h" #include "LightApp_Study.h" #include "LightApp_Preferences.h" #include "LightApp_Selection.h" @@ -92,13 +93,27 @@ void LightApp_Module::contextMenuPopup( const QString& client, QPopupMenu* menu, /*!Update object browser. * For updating model or whole object browser use update() method can be used. */ -void LightApp_Module::updateObjBrowser( bool updateDataModel, SUIT_DataObject* root ) -{ - if( updateDataModel ) - if( CAM_DataModel* aDataModel = dataModel() ) - if( LightApp_DataModel* aModel = dynamic_cast( aDataModel ) ) - aModel->update( 0, dynamic_cast( getApp()->activeStudy() ) ); - getApp()->objectBrowser()->updateTree( root ); +void LightApp_Module::updateObjBrowser( bool theIsUpdateDataModel, + SUIT_DataObject* theDataObject ) +{ + SUIT_DataObject* aDataObject = theDataObject; + if( theIsUpdateDataModel ){ + if( CAM_DataModel* aDataModel = dataModel() ){ + if ( LightApp_DataModel* aModel = dynamic_cast( aDataModel ) ) { + SUIT_DataObject* aParent = NULL; + if(theDataObject && theDataObject != aDataModel->root()) + aParent = theDataObject->parent(); + + LightApp_DataObject* anObject = dynamic_cast(theDataObject); + LightApp_Study* aStudy = dynamic_cast(getApp()->activeStudy()); + aModel->update( anObject, aStudy ); + + if(aParent && aParent->childPos(anObject) < 0) + aDataObject = dynamic_cast(aParent); + } + } + } + getApp()->objectBrowser()->updateTree( aDataObject ); } /*!NOT IMPLEMENTED*/ @@ -424,23 +439,6 @@ LightApp_Displayer* LightApp_Module::displayer() return 0; } -/*! - * \brief Virtual public - * - * This method is called just before the study document is saved, so the module has a possibility - * to store visual parameters in AttributeParameter attribue(s) - */ -void LightApp_Module::storeVisualParameters(int savePoint) {} - -/*! - * \brief Virtual public - * - * This method is called after the study document is opened, so the module has a possibility to restore - * visual parameters - */ -void LightApp_Module::restoreVisualParameters(int savePoint) {} - - void LightApp_Module::onShowHide() { if( !sender()->inherits( "QAction" ) || !popupMgr() ) diff --git a/src/LightApp/LightApp_Module.h b/src/LightApp/LightApp_Module.h index 87c051a0f..2df7aab61 100644 --- a/src/LightApp/LightApp_Module.h +++ b/src/LightApp/LightApp_Module.h @@ -66,9 +66,6 @@ public: virtual LightApp_Displayer* displayer(); - virtual void storeVisualParameters(int savePoint); - virtual void restoreVisualParameters(int savePoint); - public slots: virtual bool activateModule( SUIT_Study* ); virtual bool deactivateModule( SUIT_Study* ); diff --git a/src/LightApp/LightApp_OBSelector.cxx b/src/LightApp/LightApp_OBSelector.cxx index 537f270bb..ebe8571b4 100644 --- a/src/LightApp/LightApp_OBSelector.cxx +++ b/src/LightApp/LightApp_OBSelector.cxx @@ -36,6 +36,8 @@ LightApp_OBSelector::LightApp_OBSelector( OB_Browser* ob, SUIT_SelectionMgr* mgr if ( myBrowser ) { connect( myBrowser, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) ); } + + setModified(); } /*! @@ -85,15 +87,16 @@ void LightApp_OBSelector::setSelection( const SUIT_DataOwnerPtrList& theList ) if ( !myBrowser ) return; - QMap themap; - fillEntries( themap ); + if( myEntries.count() == 0 || + myModifiedTime < myBrowser->getModifiedTime() ) + fillEntries( myEntries ); DataObjectList objList; for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it ) { const LightApp_DataOwner* owner = dynamic_cast( (*it).operator->() ); - if ( owner && themap.contains( owner->entry() ) ) - objList.append( themap[owner->entry()] ); + if ( owner && myEntries.contains( owner->entry() ) ) + objList.append( myEntries[owner->entry()] ); } myBrowser->setSelected( objList ); @@ -124,4 +127,12 @@ void LightApp_OBSelector::fillEntries( QMap& enti if ( obj ) entires.insert( obj->entry(), obj ); } + + setModified(); +} + +/*!Update modified time.*/ +void LightApp_OBSelector::setModified() +{ + myModifiedTime = clock(); } diff --git a/src/LightApp/LightApp_OBSelector.h b/src/LightApp/LightApp_OBSelector.h index 3669610ff..e8fc44371 100644 --- a/src/LightApp/LightApp_OBSelector.h +++ b/src/LightApp/LightApp_OBSelector.h @@ -40,6 +40,9 @@ public: /*!Return "ObjectBrowser"*/ virtual QString type() const { return "ObjectBrowser"; } + void setModified(); + unsigned long getModifiedTime() { return myModifiedTime; } + private slots: void onSelectionChanged(); @@ -53,6 +56,10 @@ private: private: OB_Browser* myBrowser; SUIT_DataOwnerPtrList mySelectedList; + + QMap myEntries; + + unsigned long myModifiedTime; }; #endif diff --git a/src/LightApp/LightApp_PreferencesDlg.cxx b/src/LightApp/LightApp_PreferencesDlg.cxx index 7b615d87c..af26451f7 100644 --- a/src/LightApp/LightApp_PreferencesDlg.cxx +++ b/src/LightApp/LightApp_PreferencesDlg.cxx @@ -23,8 +23,12 @@ #include "LightApp_Preferences.h" -#include +#include "QtxResourceMgr.h" + +#include #include +#include +#include /*! Constructor. @@ -50,6 +54,10 @@ myPrefs( prefs ), mySaved ( false ) connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) ); connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) ); + + QButton* defBtn = userButton( insertButton( tr( "DEFAULT_BTN_TEXT" ) ) ); + if ( defBtn ) + connect( defBtn, SIGNAL( clicked() ), this, SLOT( onDefault() ) ); } /*! @@ -109,3 +117,18 @@ void LightApp_PreferencesDlg::onApply() myPrefs->toBackup(); mySaved = true; } + +/*! Restore default preferences*/ +void LightApp_PreferencesDlg::onDefault() +{ + if( QMessageBox::Ok == QMessageBox::information( this, tr( "WARNING" ), tr( "DEFAULT_QUESTION" ), QMessageBox::Ok, QMessageBox::Cancel ) ) + { + if ( myPrefs && myPrefs->resourceMgr() ) + { + bool prev = myPrefs->resourceMgr()->ignoreUserValues(); + myPrefs->resourceMgr()->setIgnoreUserValues( true ); + myPrefs->retrieve(); + myPrefs->resourceMgr()->setIgnoreUserValues( prev ); + } + } +} diff --git a/src/LightApp/LightApp_PreferencesDlg.h b/src/LightApp/LightApp_PreferencesDlg.h index ea7bf55fe..771714519 100644 --- a/src/LightApp/LightApp_PreferencesDlg.h +++ b/src/LightApp/LightApp_PreferencesDlg.h @@ -46,6 +46,7 @@ public: private slots: void onHelp(); void onApply(); + void onDefault(); private: LightApp_Preferences* myPrefs; diff --git a/src/LightApp/LightApp_Study.cxx b/src/LightApp/LightApp_Study.cxx index e6b6f04a2..b32f4945e 100644 --- a/src/LightApp/LightApp_Study.cxx +++ b/src/LightApp/LightApp_Study.cxx @@ -264,6 +264,18 @@ void LightApp_Study::children( const QString&, QStringList& ) const //================================================================ bool LightApp_Study::isComponent( const QString& entry ) const { + if( !root() ) + return false; + + DataObjectList ch; + root()->children( ch ); + DataObjectList::const_iterator anIt = ch.begin(), aLast = ch.end(); + for( ; anIt!=aLast; anIt++ ) + { + LightApp_DataObject* obj = dynamic_cast( *anIt ); + if( obj && obj->entry()==entry ) + return true; + } return false; } diff --git a/src/LightApp/LightApp_VTKSelector.cxx b/src/LightApp/LightApp_VTKSelector.cxx index 7b0b64333..b393b3043 100644 --- a/src/LightApp/LightApp_VTKSelector.cxx +++ b/src/LightApp/LightApp_VTKSelector.cxx @@ -19,7 +19,7 @@ #include "LightApp_VTKSelector.h" #include "LightApp_DataOwner.h" -#include "SVTK_ViewModel.h" +#include "SVTK_ViewModelBase.h" #include "SVTK_Selector.h" #include "SVTK_ViewWindow.h" #include "SVTK_Functor.h" @@ -36,9 +36,9 @@ */ LightApp_SVTKDataOwner ::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO, - const TColStd_IndexedMapOfInteger& theIds, - Selection_Mode theMode, - SALOME_Actor* theActor): + const TColStd_IndexedMapOfInteger& theIds, + Selection_Mode theMode, + SALOME_Actor* theActor): LightApp_DataOwner( theIO ), mySelectionMode(theMode), myActor(theActor) @@ -68,8 +68,8 @@ LightApp_SVTKDataOwner Constructor. */ LightApp_VTKSelector -::LightApp_VTKSelector( SVTK_Viewer* viewer, - SUIT_SelectionMgr* mgr ): +::LightApp_VTKSelector( SVTK_ViewModelBase* viewer, + SUIT_SelectionMgr* mgr ): SUIT_Selector( mgr, viewer ), myViewer( viewer ) { @@ -88,7 +88,7 @@ LightApp_VTKSelector /*! Gets viewer. */ -SVTK_Viewer* +SVTK_ViewModelBase* LightApp_VTKSelector ::viewer() const { @@ -96,13 +96,13 @@ LightApp_VTKSelector } /*! - Gets type of vtk viewer. + Gets type of salome vtk viewer. */ QString LightApp_VTKSelector ::type() const { - return SVTK_Viewer::Type(); + return myViewer->getType(); } /*! @@ -135,9 +135,10 @@ LightApp_VTKSelector TColStd_IndexedMapOfInteger anIds; aSelector->GetIndex(anIO,anIds); SALOME_Actor* anActor = aSelector->GetActor(anIO); - if( !anActor ) - anActor = VTK::Find(aView->getRenderer()->GetActors(),VTK::TIsSameIObject(anIO)); - + if( !anActor ){ + using namespace SVTK; + anActor = Find(aView->getRenderer()->GetActors(),TIsSameIObject(anIO)); + } aList.append(new LightApp_SVTKDataOwner(anIO,anIds,aMode,anActor)); } } diff --git a/src/LightApp/LightApp_VTKSelector.h b/src/LightApp/LightApp_VTKSelector.h index e7550ada5..14c6523ce 100644 --- a/src/LightApp/LightApp_VTKSelector.h +++ b/src/LightApp/LightApp_VTKSelector.h @@ -32,7 +32,7 @@ #include "SALOME_InteractiveObject.hxx" class SALOME_Actor; -class SVTK_Viewer; +class SVTK_ViewModelBase; /*! Provide salome vtk data owner list. @@ -75,10 +75,10 @@ class LIGHTAPP_EXPORT LightApp_VTKSelector : public SUIT_Selector Q_OBJECT; public: - LightApp_VTKSelector( SVTK_Viewer*, SUIT_SelectionMgr* ); + LightApp_VTKSelector( SVTK_ViewModelBase*, SUIT_SelectionMgr* ); virtual ~LightApp_VTKSelector(); - SVTK_Viewer* viewer() const; + SVTK_ViewModelBase* viewer() const; virtual QString type() const; @@ -90,7 +90,7 @@ protected: virtual void setSelection( const SUIT_DataOwnerPtrList& ); private: - SVTK_Viewer* myViewer; + SVTK_ViewModelBase* myViewer; }; #endif diff --git a/src/OBJECT/Makefile.in b/src/OBJECT/Makefile.in index 9bcbc4cec..0fb5e50a7 100755 --- a/src/OBJECT/Makefile.in +++ b/src/OBJECT/Makefile.in @@ -9,7 +9,6 @@ VPATH=.:@srcdir@:@top_srcdir@/idl EXPORT_HEADERS = SALOME_InteractiveObject.hxx \ Handle_SALOME_InteractiveObject.hxx \ - SALOME_Actor.h \ SALOME_GLOwner.h \ SALOME_AISShape.hxx \ Handle_SALOME_AISShape.hxx \ @@ -33,7 +32,6 @@ EXPORT_HEADERS = SALOME_InteractiveObject.hxx \ LIB = libSalomeObject.la LIB_SRC = SALOME_InteractiveObject.cxx \ - SALOME_Actor.cxx \ SALOME_GLOwner.cxx \ SALOME_AISShape.cxx\ SALOME_AISObject.cxx\ diff --git a/src/OBJECT/SALOME_Actor.cxx b/src/OBJECT/SALOME_Actor.cxx deleted file mode 100755 index 385cb4d93..000000000 --- a/src/OBJECT/SALOME_Actor.cxx +++ /dev/null @@ -1,308 +0,0 @@ -// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : SALOME_Actor.cxx -// Author : Nicolas REJNERI -// Module : SALOME -// $Header$ - -/*! - \class SALOME_Actor SALOME_Actor.h - \brief Abstract class of SALOME Objects in VTK. -*/ - - -#include "SALOME_Actor.h" - -#include "VTKViewer_Transform.h" -#include "VTKViewer_TransformFilter.h" -#include "VTKViewer_PassThroughFilter.h" -#include "VTKViewer_GeometryFilter.h" - -// SALOME Includes -//#include "utilities.h" - -// VTK Includes -#include -#include -#include -#include -#include -#include -#include - -//using namespace std; - - -#if defined __GNUC__ - #if __GNUC__ == 2 - #define __GNUC_2__ - #endif -#endif - -int SALOME_POINT_SIZE = 3; - - -vtkStandardNewMacro(SALOME_Actor); - - -SALOME_Actor::SALOME_Actor(){ - myIsHighlighted = myIsPreselected = false; - - myRepresentation = 1; - myDisplayMode = myRepresentation - 1; - - myProperty = vtkProperty::New(); - PreviewProperty = NULL; - - myIsInfinite = false; - - myIsResolveCoincidentTopology = true; - - vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, - myPolygonOffsetUnits); - myStoreMapping = false; - myGeomFilter = VTKViewer_GeometryFilter::New(); - - myTransformFilter = VTKViewer_TransformFilter::New(); - - for(int i = 0; i < 6; i++) - myPassFilter.push_back(VTKViewer_PassThroughFilter::New()); -} - - -SALOME_Actor::~SALOME_Actor(){ - SetPreviewProperty(NULL); - - myGeomFilter->UnRegisterAllOutputs(); - myGeomFilter->Delete(); - - myTransformFilter->UnRegisterAllOutputs(); - myTransformFilter->Delete(); - - for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){ - if(myPassFilter[i]){ - myPassFilter[i]->UnRegisterAllOutputs(); - myPassFilter[i]->Delete(); - } - } - - myProperty->Delete(); -} - - -void SALOME_Actor::AddToRender(vtkRenderer* theRenderer){ - theRenderer->AddActor(this); -} - -void SALOME_Actor::RemoveFromRender(vtkRenderer* theRenderer){ - theRenderer->RemoveActor(this); -} - - -void SALOME_Actor::SetTransform(VTKViewer_Transform* theTransform){ - myTransformFilter->SetTransform(theTransform); -} - - -void SALOME_Actor::SetMapper(vtkMapper* theMapper){ - InitPipeLine(theMapper); -} - -void SALOME_Actor::InitPipeLine(vtkMapper* theMapper){ - if(theMapper){ - int anId = 0; - myPassFilter[ anId ]->SetInput( theMapper->GetInput() ); - myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() ); - - anId++; // 1 - myGeomFilter->SetStoreMapping( myStoreMapping ); - myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() ); - - anId++; // 2 - myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); - myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); - - anId++; // 3 - myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); - - anId++; // 4 - myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() ); - myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); - - anId++; // 5 - if(vtkDataSetMapper* aMapper = dynamic_cast(theMapper)){ - aMapper->SetInput(myPassFilter[anId]->GetOutput()); - }else if(vtkPolyDataMapper* aMapper = dynamic_cast(theMapper)){ - aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput()); - } - } - vtkLODActor::SetMapper(theMapper); -} - - -void SALOME_Actor::Render(vtkRenderer *ren, vtkMapper* m){ - if(myIsResolveCoincidentTopology){ - int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology(); - float aFactor, aUnit; - vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); - - vtkMapper::SetResolveCoincidentTopologyToPolygonOffset(); - vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, - myPolygonOffsetUnits); - vtkLODActor::Render(ren,m); - - vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); - vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology); - }else{ - vtkLODActor::Render(ren,m); - } -} - - -void SALOME_Actor::SetResolveCoincidentTopology(bool theIsResolve) { - myIsResolveCoincidentTopology = theIsResolve; -} - -void SALOME_Actor::SetPolygonOffsetParameters(float factor, float units){ - myPolygonOffsetFactor = factor; - myPolygonOffsetUnits = units; -} - -void SALOME_Actor::GetPolygonOffsetParameters(float& factor, float& units){ - factor = myPolygonOffsetFactor; - units = myPolygonOffsetUnits; -} - - -vtkDataSet* SALOME_Actor::GetInput(){ - return myPassFilter.front()->GetOutput(); -} - - -unsigned long int SALOME_Actor::GetMTime(){ - unsigned long mTime = this->Superclass::GetMTime(); - unsigned long time = myTransformFilter->GetMTime(); - mTime = ( time > mTime ? time : mTime ); - if(vtkDataSet *aDataSet = myPassFilter[0]->GetInput()){ - time = aDataSet->GetMTime(); - mTime = ( time > mTime ? time : mTime ); - } - return mTime; -} - - -void SALOME_Actor::SetRepresentation(int theMode) { - switch(myRepresentation){ - case VTK_POINTS : - case VTK_SURFACE : - myProperty->DeepCopy(GetProperty()); - } - switch(theMode){ - case VTK_POINTS : - case VTK_SURFACE : - GetProperty()->DeepCopy(myProperty); - break; - default: - GetProperty()->SetAmbient(1.0); - GetProperty()->SetDiffuse(0.0); - GetProperty()->SetSpecular(0.0); - } - switch(theMode){ - case 3 : - myGeomFilter->SetInside(true); - GetProperty()->SetRepresentation(1); - break; - case VTK_POINTS : - GetProperty()->SetPointSize(SALOME_POINT_SIZE); - default : - GetProperty()->SetRepresentation(theMode); - myGeomFilter->SetInside(false); - } - myRepresentation = theMode; -} - -int SALOME_Actor::GetRepresentation(){ - return myRepresentation; -} - - -vtkCell* SALOME_Actor::GetElemCell(int theObjID){ - return GetInput()->GetCell(theObjID); -} - - -float* SALOME_Actor::GetNodeCoord(int theObjID){ - return GetInput()->GetPoint(theObjID); -} - - -//================================================================================= -// function : GetObjDimension -// purpose : Return object dimension. -// Virtual method shoulb be redifined by derived classes -//================================================================================= -int SALOME_Actor::GetObjDimension( const int theObjId ) -{ - if ( vtkCell* aCell = GetElemCell(theObjId) ) - return aCell->GetCellDimension(); - return 0; -} - - -bool SALOME_Actor::IsInfinitive(){ - return myIsInfinite; -} - - -void SALOME_Actor::SetOpacity(float theOpacity){ - myOpacity = theOpacity; - GetProperty()->SetOpacity(theOpacity); -} - -float SALOME_Actor::GetOpacity(){ - return myOpacity; -} - - -void SALOME_Actor::SetColor(float r,float g,float b){ - GetProperty()->SetColor(r,g,b); -} - -void SALOME_Actor::GetColor(float& r,float& g,float& b){ - float aColor[3]; - GetProperty()->GetColor(aColor); - r = aColor[0]; - g = aColor[1]; - b = aColor[2]; -} - - -int SALOME_Actor::getDisplayMode(){ - return myDisplayMode; -} - -void SALOME_Actor::setDisplayMode(int theMode){ - SetRepresentation(theMode+1); - myDisplayMode = GetRepresentation() - 1; -} diff --git a/src/OBJECT/SALOME_Actor.h b/src/OBJECT/SALOME_Actor.h deleted file mode 100755 index 2467f1e89..000000000 --- a/src/OBJECT/SALOME_Actor.h +++ /dev/null @@ -1,187 +0,0 @@ -// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : SALOME_Actor.h -// Author : Nicolas REJNERI -// Module : SALOME -// $Header$ - -#ifndef SALOME_ACTOR_H -#define SALOME_ACTOR_H - -#include "SALOME_InteractiveObject.hxx" // INCLUDES "using namespace std" -#ifndef _Handle_SALOME_InteractiveObject_HeaderFile -#include "Handle_SALOME_InteractiveObject.hxx" -#endif - -#include // INCLUDES "stdio.h" -#include - -// to overcome the conflict between std::ostream and io::ostream -// the following variable must be defined: -// VTK_USE_ANSI_STDLIB - -#include - -class vtkCell; -class vtkDataSet; -class vtkPolyData; -class vtkCamera; -class vtkProperty; - -class VTKViewer_Transform; -class VTKViewer_GeometryFilter; -class VTKViewer_TransformFilter; -class VTKViewer_PassThroughFilter; - -extern int SALOME_POINT_SIZE; - -#ifdef WNT -#define SALOME_OBJECT_EXPORT __declspec (dllexport) -#else -#define SALOME_OBJECT_EXPORT -#endif - -#include - -class SALOME_OBJECT_EXPORT SALOME_Actor : public VTKViewer_Actor { - public: - static SALOME_Actor* New(); - - vtkTypeMacro(SALOME_Actor,vtkLODActor); - - virtual Standard_Boolean hasIO() { return !myIO.IsNull(); } - virtual const Handle(SALOME_InteractiveObject)& getIO() { return myIO; } - virtual void setIO(const Handle(SALOME_InteractiveObject)& io) { myIO = io; } - - virtual const char* getName() { return myName.c_str(); } - virtual void setName(const char* theName){ - if(hasIO()) myIO->setName(theName); - myName = theName; - } - - // To generate highlight automaticaly - virtual bool hasHighlight() { return false; } - virtual void highlight(bool theHighlight) { myIsHighlighted = theHighlight; } - virtual bool isHighlighted() { return myIsHighlighted; } - - virtual void SetOpacity(float theOpacity); - virtual float GetOpacity(); - - virtual void SetColor(float r,float g,float b); - virtual void GetColor(float& r,float& g,float& b); - void SetColor(const float theRGB[3]){ - SetColor(theRGB[0],theRGB[1],theRGB[2]); - } - - vtkSetObjectMacro(PreviewProperty,vtkProperty); - - virtual void SetPreSelected(bool thePreselect = false) { myIsPreselected = thePreselect;} - - - // Used to obtain all dependent actors - virtual void GetChildActors(vtkActorCollection*) {}; - - virtual void AddToRender(vtkRenderer* theRenderer); - virtual void RemoveFromRender(vtkRenderer* theRenderer); - - - // For selection mapping purpose - virtual int GetNodeObjId(int theVtkID) { return theVtkID;} - virtual float* GetNodeCoord(int theObjID); - - virtual int GetElemObjId(int theVtkID) { return theVtkID;} - virtual vtkCell* GetElemCell(int theObjID); - - virtual int GetObjDimension( const int theObjId ); - - virtual void SetMapper(vtkMapper* theMapper); - virtual vtkDataSet* GetInput(); - - - virtual void SetTransform(VTKViewer_Transform* theTransform); - virtual unsigned long int GetMTime(); - - virtual void SetRepresentation(int theMode); - virtual int GetRepresentation(); - - virtual int getDisplayMode(); - virtual void setDisplayMode(int theMode); - - // Infinitive means actor without size (point for example), - // which is not taken into account in calculation of boundaries of the scene - void SetInfinitive(bool theIsInfinite) { myIsInfinite = theIsInfinite; } - virtual bool IsInfinitive(); - - void SetResolveCoincidentTopology(bool theIsResolve); - void SetPolygonOffsetParameters(float factor, float units); - void GetPolygonOffsetParameters(float& factor, float& units); - - virtual void Render(vtkRenderer *, vtkMapper *); - - virtual float GetShrinkFactor() { return 1.0;} - - virtual bool IsShrunkable() { return false;} - virtual bool IsShrunk() { return false;} - - virtual void SetShrink() {} - virtual void UnShrink() {} - - virtual bool IsSetCamera() const { return false; } - virtual bool IsResizable() const { return false; } - virtual void SetSize( const float ) {} - virtual void SetCamera( vtkCamera* ) {} - - protected: - bool myIsResolveCoincidentTopology; - float myPolygonOffsetFactor; - float myPolygonOffsetUnits; - - Handle(SALOME_InteractiveObject) myIO; - std::string myName; - - vtkProperty *PreviewProperty; - bool myIsPreselected; - - float myOpacity; - bool myIsHighlighted; - int myDisplayMode; - bool myIsInfinite; - - bool myStoreMapping; - VTKViewer_GeometryFilter *myGeomFilter; - VTKViewer_TransformFilter *myTransformFilter; - std::vector myPassFilter; - - int myRepresentation; - vtkProperty *myProperty; - - void InitPipeLine(vtkMapper* theMapper); - - SALOME_Actor(); - ~SALOME_Actor(); -}; - - -#endif // SALOME_ACTOR_H - diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index fff6ab535..5b4bc28e3 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -22,6 +22,9 @@ #include "OB_ListItem.h" #include "OB_ListView.h" +#include +#include + #include #include #include @@ -29,6 +32,9 @@ #include #include #include +#include + +#include /*! Class: OB_Browser::ToolTip @@ -79,6 +85,138 @@ void OB_Browser::ToolTip::maybeTip( const QPoint& pos ) tip( aRect, aText ); } + +typedef SUIT_DataObject* ObjPtr; +typedef OB_ListItem* ItemPtr; +/*! + Class: OB_BrowserSync + Descr: Auxiliary class for synchronizing tree of SUIT_DataObjects and list view items +*/ + +class OB_BrowserSync +{ +public: + OB_BrowserSync( OB_Browser* ); + bool isEqual( const ObjPtr&, const ItemPtr& ) const; + ObjPtr nullSrc() const; + ItemPtr nullTrg() const; + ItemPtr createItem( const ObjPtr&, const ItemPtr&, const ItemPtr&, const bool ) const; + void updateItem( const ItemPtr& ) const; + void deleteItemWithChildren( const ItemPtr& ) const; + void children( const ObjPtr&, QValueList& ) const; + void children( const ItemPtr&, QValueList& ) const; + ItemPtr parent( const ItemPtr& ) const; +private: + bool needUpdate( const ItemPtr& ) const; + OB_Browser* myBrowser; +}; + + +OB_BrowserSync::OB_BrowserSync( OB_Browser* ob ) +: myBrowser( ob ) +{ +} + +bool OB_BrowserSync::needUpdate( const ItemPtr& item ) const +{ + bool update = false; + if ( item ) { + SUIT_DataObject* obj = item->dataObject(); + if ( obj ) { + // 1. check text + update = ( item->text( 0 ) != obj->name() ); + if ( !update ) { + // 2. check pixmap (compare serialNumber()-s) + QPixmap objPix = obj->icon(); + const QPixmap* itemPix = item->pixmap( 0 ); + update = ( objPix.isNull() && ( itemPix && !itemPix->isNull() ) ) || + ( !objPix.isNull() && ( !itemPix || itemPix->isNull() ) ); + if ( !update && !objPix.isNull() && itemPix && !itemPix->isNull() ) { + int aIconW = objPix.width(); + if( aIconW > 20 ) { + QWMatrix aM; + double aScale = 20.0 / aIconW; + aM.scale( aScale, aScale ); + objPix = objPix.xForm( aM ); + } + update = ( objPix.serialNumber() != itemPix->serialNumber() ); + } + } + } + } + return update; +} + +void OB_BrowserSync::updateItem( const ItemPtr& p ) const +{ + if ( p && needUpdate( p ) ) { + // printf( "--- needUpdate for %s = true ---\n", p->text( 0 ).latin1() ); + p->update(); + } +} + +ItemPtr OB_BrowserSync::createItem( const ObjPtr& src, + const ItemPtr& parent, const ItemPtr& after, + const bool asFirst ) const +{ + ItemPtr i = myBrowser ? dynamic_cast( myBrowser->createItem( src, parent, after, asFirst ) ) : 0; + if( i ) + i->setOpen( src->isOpen() ); + return i; +} + +void OB_BrowserSync::deleteItemWithChildren( const ItemPtr& i ) const +{ + if( myBrowser && myBrowser->myItems.contains( i->dataObject() ) ) + { + myBrowser->removeReferences( i ); + delete i; + } +} + +bool OB_BrowserSync::isEqual( const ObjPtr& p, const ItemPtr& q ) const +{ + return ( !p && !q ) || ( p && q && q->dataObject()==p ); +} + +ObjPtr OB_BrowserSync::nullSrc() const +{ + return 0; +} + +ItemPtr OB_BrowserSync::nullTrg() const +{ + return 0; +} + +void OB_BrowserSync::children( const ObjPtr& p, QValueList& ch ) const +{ + DataObjectList l; + if( p ) + { + p->children( l ); + ch.clear(); + for( SUIT_DataObject* o = l.first(); o; o = l.next() ) + ch.append( o ); + } +} + +void OB_BrowserSync::children( const ItemPtr& p, QValueList& ch ) const +{ + for( QListViewItem* item = p->firstChild(); item; item = item->nextSibling() ) + { + ItemPtr p = dynamic_cast( item ); + if( p ) + ch.append( p ); + } +} + +ItemPtr OB_BrowserSync::parent( const ItemPtr& p ) const +{ + return p ? dynamic_cast( p->parent() ) : 0; +} + + /*! Class: OB_Browser Descr: Hierarchical tree object browser. @@ -115,6 +253,8 @@ myRootDecorated( true ) this, SLOT( onDoubleClicked( QListViewItem* ) ) ); setRootObject( root ); + + setModified(); } OB_Browser::~OB_Browser() @@ -219,6 +359,8 @@ void OB_Browser::setRootObject( SUIT_DataObject* theRoot ) autoOpenBranches(); + setModified(); + if ( selNum != numberOfSelected() ) emit selectionChanged(); } @@ -508,6 +650,8 @@ void OB_Browser::setAppropriateColumn( const int id, const bool on ) void OB_Browser::updateTree( SUIT_DataObject* obj, const bool autoOpen ) { +// QTime t1 = QTime::currentTime(); + if ( !obj && !(obj = getRootObject()) ) return; @@ -526,8 +670,13 @@ void OB_Browser::updateTree( SUIT_DataObject* obj, const bool autoOpen ) if( autoOpen ) autoOpenBranches(); + setModified(); + if ( selNum != numberOfSelected() ) emit selectionChanged(); + +// QTime t2 = QTime::currentTime(); +// qDebug( QString( "update tree time = %1 msecs" ).arg( t1.msecsTo( t2 ) ) ); } void OB_Browser::replaceTree( SUIT_DataObject* src, SUIT_DataObject* trg ) @@ -564,88 +713,73 @@ void OB_Browser::replaceTree( SUIT_DataObject* src, SUIT_DataObject* trg ) autoOpenBranches(); + setModified(); + if ( selNum != numberOfSelected() ) emit selectionChanged(); } -void OB_Browser::updateView( const SUIT_DataObject* theStartObj ) +void OB_Browser::updateView( SUIT_DataObject* startObj ) { QListView* lv = listView(); if ( !lv ) return; - if ( !theStartObj || theStartObj->root() != getRootObject() ) + if ( !startObj || startObj->root() != getRootObject() ) return; - QListViewItem* after = 0; - QListViewItem* parent = 0; - QListViewItem* startItem = listViewItem( theStartObj ); - - if ( theStartObj->parent() ) - parent = listViewItem( theStartObj->parent() ); - - QListViewItem* prv = 0; - QListViewItem* cur = parent ? parent->firstChild() : lv->firstChild(); - while ( !after && cur ) + if( startObj==myRoot ) { - if ( cur == startItem ) - after = prv; + DataObjectList ch; + myRoot->children( ch ); - prv = cur; - cur = cur->nextSibling(); - } - - QPtrList delList; - if ( !startItem && theStartObj == getRootObject() ) - { - for ( QListViewItem* item = lv->firstChild(); item; item = item->nextSibling() ) - delList.append( item ); - } - else - delList.append( startItem ); + ItemMap exist; + QListViewItem* st = lv->firstChild(); + for( ; st; st = st->nextSibling() ) + { + OB_ListItem* ob_item = dynamic_cast( st ); + exist.insert( ob_item->dataObject(), ob_item ); + } - for ( QPtrListIterator it( delList ); it.current(); ++it ) - { - removeReferences( it.current() ); - delete it.current(); - } + SUIT_DataObject* local_root = ch.first(); + for( ; local_root; local_root = ch.next() ) + { + OB_BrowserSync sync( this ); + OB_ListItem* local_item = dynamic_cast( listViewItem( local_root ) ); + + // QString srcName = ( local_root && !local_root->name().isNull() ) ? local_root->name() : ""; + // QString trgName = ( local_item && !local_item->text(0).isNull() ) ? local_item->text(0) : ""; + // printf( "--- OB_Browser::updateView() calls synchronize()_1: src = %s, trg = %s ---\n", srcName.latin1(), trgName.latin1() ); + + synchronize( local_root, local_item, sync ); + exist[local_root] = 0; + } - // for myRoot object, if myShowRoot==false, then creating multiple top-level QListViewItem-s - // (which will correspond to myRoot's children = Modules). - if ( rootIsDecorated() && theStartObj == myRoot ) - { - DataObjectList lst; - theStartObj->children( lst ); - DataObjectListIterator it ( lst ); - // iterating backward to preserve the order of elements in the tree - for ( it.toLast(); it.current(); --it ) - createTree( it.current(), 0, 0 ); + ItemMap::const_iterator anIt = exist.begin(), aLast = exist.end(); + for( ; anIt!=aLast; anIt++ ) + if( anIt.data() ) + { + removeReferences( anIt.data() ); + OB_ListItem* item = dynamic_cast( anIt.data() ); + if( item && myItems.contains( item->dataObject() ) ) + delete anIt.data(); + } } else - createTree( theStartObj, parent, after ? after : parent ); -} - -QListViewItem* OB_Browser::createTree( const SUIT_DataObject* obj, - QListViewItem* parent, QListViewItem* after ) -{ - if ( !obj ) - return 0; - - QListViewItem* item = createItem( obj, parent, after ); - - DataObjectList lst; - obj->children( lst ); - for ( DataObjectListIterator it ( lst ); it.current(); ++it ) - createTree( it.current(), item ); + { + OB_BrowserSync sync( this ); + OB_ListItem* startItem = dynamic_cast( listViewItem( startObj ) ); - if ( item ) - item->setOpen( obj->isOpen() ); + // QString srcName = ( startObj && !startObj->name().isNull() ) ? startObj->name() : ""; + // QString trgName = ( startItem && !startItem->text(0).isNull() ) ? startItem->text(0) : ""; + // printf( "--- OB_Browser::updateView() calls synchronize()_2: src = %s, trg = %s ---\n", srcName.latin1(), trgName.latin1() ); - return item; + synchronize( startObj, startItem, sync ); + } } -QListViewItem* OB_Browser::createItem( const SUIT_DataObject* o, - QListViewItem* parent, QListViewItem* after ) +QListViewItem* OB_Browser::createItem( const SUIT_DataObject* o, QListViewItem* parent, + QListViewItem* after, const bool asFirstChild ) { QListView* lv = listView(); @@ -676,7 +810,7 @@ QListViewItem* OB_Browser::createItem( const SUIT_DataObject* o, after = after->nextSibling(); } - if ( after ) + if ( after && !asFirstChild ) { if ( type == -1 ) item = new OB_ListItem( obj, parent, after ); @@ -701,7 +835,6 @@ QListViewItem* OB_Browser::createItem( const SUIT_DataObject* o, myItems.insert( obj, item ); obj->connect( this, SLOT( onDestroyed( SUIT_DataObject* ) ) ); - updateText( item ); return item; @@ -1089,7 +1222,7 @@ void OB_Browser::removeObject( SUIT_DataObject* obj, const bool autoUpd ) return; } - if ( !autoUpd ) + if( !autoUpd ) return; if ( isAutoUpdate() ) @@ -1097,8 +1230,8 @@ void OB_Browser::removeObject( SUIT_DataObject* obj, const bool autoUpd ) SUIT_DataObject* pObj = item && item->parent() ? dataObject( item->parent() ) : 0; updateTree( pObj, false ); } - else - delete item; + + delete item; } void OB_Browser::autoOpenBranches() @@ -1134,3 +1267,9 @@ void OB_Browser::onDoubleClicked( QListViewItem* item ) if ( item ) emit doubleClicked( dataObject( item ) ); } + +void OB_Browser::setModified() +{ + myModifiedTime = clock(); +} + diff --git a/src/ObjBrowser/OB_Browser.h b/src/ObjBrowser/OB_Browser.h index cd0b48889..a6e3cd421 100755 --- a/src/ObjBrowser/OB_Browser.h +++ b/src/ObjBrowser/OB_Browser.h @@ -37,6 +37,7 @@ class QToolTip; class OB_Filter; class OB_ListView; +class OB_ListItem; class OB_EXPORT OB_Browser : public QFrame, public SUIT_PopupClient { @@ -117,6 +118,9 @@ public: virtual void contextMenuPopup( QPopupMenu* ); + void setModified(); + unsigned long getModifiedTime() { return myModifiedTime; } + signals: void selectionChanged(); void doubleClicked( SUIT_DataObject* ); @@ -131,7 +135,7 @@ private slots: protected: void adjustWidth( QListViewItem* ); - virtual void updateView( const SUIT_DataObject* theStartObj = 0 ); + virtual void updateView( SUIT_DataObject* = 0 ); virtual void updateText(); virtual void keyPressEvent( QKeyEvent* ); @@ -162,8 +166,8 @@ private: DataObjectKey objectKey( QListViewItem* ) const; DataObjectKey objectKey( SUIT_DataObject* ) const; - QListViewItem* createTree( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0 ); - QListViewItem* createItem( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0 ); + QListViewItem* createTree( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0, const bool = false ); + QListViewItem* createItem( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0, const bool = false ); SUIT_DataObject* storeState( DataObjectMap&, DataObjectMap&, DataObjectKeyMap&, DataObjectKeyMap&, DataObjectKey& ) const; @@ -171,6 +175,8 @@ private: const DataObjectKeyMap&, const DataObjectKeyMap&, const DataObjectKey& ); private: + friend class OB_BrowserSync; + OB_ListView* myView; SUIT_DataObject* myRoot; ItemMap myItems; @@ -183,6 +189,8 @@ private: int myAutoOpenLevel; friend class OB_Browser::ToolTip; + + unsigned long myModifiedTime; }; #endif diff --git a/src/ObjBrowser/OB_ListItem.cxx b/src/ObjBrowser/OB_ListItem.cxx index b2ced5c7b..49ad75741 100755 --- a/src/ObjBrowser/OB_ListItem.cxx +++ b/src/ObjBrowser/OB_ListItem.cxx @@ -34,7 +34,7 @@ using namespace std; */ template -ListItemF::ListItemF( T& theT, SUIT_DataObject* obj ) : +ListItemF::ListItemF( T* theT, SUIT_DataObject* obj ) : myT( theT ), myObject( obj ) { @@ -61,7 +61,7 @@ void ListItemF::paintC( QPainter* p, QColorGroup& cg, int c, int w, int align } - p->fillRect( 0, 0, w, myT.height(), cg.brush( QColorGroup::Base ) ); + p->fillRect( 0, 0, w, myT->height(), cg.brush( QColorGroup::Base ) ); //int itemW = myT.width( p->fontMetrics(), myT.listView(), c ); //myT.paintCell( p, colorGrp, c, itemW, align ); @@ -71,18 +71,18 @@ template void ListItemF::paintFoc( QPainter* p, QColorGroup& cg, const QRect& r ) { QRect rect = r; - rect.setWidth( myT.width( p->fontMetrics(), myT.listView(), 0 ) ); + rect.setWidth( myT->width( p->fontMetrics(), myT->listView(), 0 ) ); //myT.paintFocus( p, cg, rect ); } template void ListItemF::setSel( bool s ) { - QListView* lv = myT.listView(); + QListView* lv = myT->listView(); if ( s && lv && lv->inherits( "OB_ListView" ) ) { OB_ListView* objlv = (OB_ListView*)lv; - s = s && objlv->isOk( &myT ); + s = s && objlv->isOk( myT ); } //myT.setSelected( s ); @@ -95,24 +95,27 @@ void ListItemF::update() if ( !obj ) return; - myT.setText( 0, obj->name() ); + QString n = obj->name(); + if( myT->text( 0 )!=n ) + myT->setText( 0, n ); - int aIconW = obj->icon().width(); - if ( aIconW > 0 ) + QPixmap p = obj->icon(); + int aIconW = p.width(); + if( aIconW > 0 ) { - if ( aIconW > 20 ) + if( aIconW > 20 ) { QWMatrix aM; double aScale = 20.0 / aIconW; aM.scale( aScale, aScale ); - myT.setPixmap( 0, obj->icon().xForm( aM ) ); + myT->setPixmap( 0, p.xForm( aM ) ); } else - myT.setPixmap( 0, obj->icon() ); + myT->setPixmap( 0, p ); } - myT.setDragEnabled( obj->isDragable() ); - myT.setDropEnabled( true ); + myT->setDragEnabled( obj->isDragable() ); + myT->setDropEnabled( true ); } /*! @@ -121,31 +124,31 @@ void ListItemF::update() */ OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListView* parent ) -: ListItemF( *this, obj ), +: ListItemF( this, obj ), QListViewItem(parent) { - update(); + update(); } OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListViewItem* parent ) -: ListItemF( *this, obj), +: ListItemF( this, obj ), QListViewItem(parent) { - update(); + update(); } OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after ) -: ListItemF( *this, obj), +: ListItemF( this, obj), QListViewItem(parent, after ) { - update(); + update(); } OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after ) -: ListItemF( *this,obj), +: ListItemF( this,obj), QListViewItem(parent, after ) { - update(); + update(); } OB_ListItem::~OB_ListItem() @@ -154,8 +157,8 @@ OB_ListItem::~OB_ListItem() void OB_ListItem::setSelected( bool s ) { - setSel( s ); - QListViewItem::setSelected( s ); + setSel( s ); + QListViewItem::setSelected( s ); } void OB_ListItem::paintFocus( QPainter* p, const QColorGroup& cg, const QRect& r ) @@ -209,39 +212,39 @@ void OB_ListItem::setText( int column, const QString& text ) */ OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, Type type ) -: ListItemF( *this, obj), +: ListItemF( this, obj), QCheckListItem( parent, "", type ) { - update(); + update(); } OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, Type type ) -: ListItemF( *this, obj), +: ListItemF( this, obj), QCheckListItem( parent, "", type ) { - update(); + update(); } OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after, Type type ) -: ListItemF( *this, obj), +: ListItemF( this, obj), #if defined(QT_VERSION) && QT_VERSION >= 0x030101 QCheckListItem( parent, after, "", type ) #else QCheckListItem( parent, "", type ) #endif { - update(); + update(); } OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after, Type type ) -: ListItemF( *this, obj), +: ListItemF( this, obj), #if defined(QT_VERSION) && QT_VERSION >= 0x030101 QCheckListItem( parent, after, "", type ) #else QCheckListItem( parent, "", type ) #endif { - update(); + update(); } OB_CheckListItem::~OB_CheckListItem() diff --git a/src/ObjBrowser/OB_ListItem.h b/src/ObjBrowser/OB_ListItem.h index 6b06cd842..112c3c8c9 100755 --- a/src/ObjBrowser/OB_ListItem.h +++ b/src/ObjBrowser/OB_ListItem.h @@ -33,7 +33,7 @@ class SUIT_DataObject; template class ListItemF { public: - ListItemF(T&, SUIT_DataObject* ); + ListItemF( T*, SUIT_DataObject* ); /*ListItem( SUIT_DataObject*, QListView* ); ListItem( SUIT_DataObject*, QListViewItem* ); ListItem( SUIT_DataObject*, QListView*, QListViewItem* ); @@ -49,12 +49,12 @@ public: void paintFoc( QPainter* p, QColorGroup& cg, const QRect& r ); void paintC( QPainter* p, QColorGroup& cg, int c, int w, int align ); -protected: +//protected: void update(); protected: SUIT_DataObject* myObject; - T& myT; + T* myT; }; /* diff --git a/src/QDS/QDS_CheckBox.cxx b/src/QDS/QDS_CheckBox.cxx index 7f1924d97..ded537716 100644 --- a/src/QDS/QDS_CheckBox.cxx +++ b/src/QDS/QDS_CheckBox.cxx @@ -18,12 +18,23 @@ QDS_CheckBox::~QDS_CheckBox() { } +/*! + Sets the state "NoChange" for checkbox. +*/ +void QDS_CheckBox::clear() +{ + setStringValue( "-1" ); +} + /*! Returns string from QCheckBox widget. */ QString QDS_CheckBox::getString() const { - return checkBox() && checkBox()->isChecked() ? "1" : "0"; + QString val; + if ( checkBox() && checkBox()->state() != QButton::NoChange ) + val = checkBox()->isChecked() ? "1" : "0"; + return val; } /*! @@ -31,9 +42,17 @@ QString QDS_CheckBox::getString() const */ void QDS_CheckBox::setString( const QString& txt ) { + if ( !checkBox() ) + return; + bool isOk; int val = (int)txt.toDouble( &isOk ); - if ( checkBox() ) + if ( isOk && val < 0 ) + { + checkBox()->setTristate(); + checkBox()->setNoChange(); + } + else checkBox()->setChecked( isOk && val != 0 ); } @@ -53,6 +72,7 @@ QWidget* QDS_CheckBox::createControl( QWidget* parent ) QCheckBox* cb = new QCheckBox( parent ); connect( cb, SIGNAL( stateChanged( int ) ), SLOT( onParamChanged() ) ); connect( cb, SIGNAL( toggled( bool ) ), SIGNAL( toggled( bool ) ) ); + connect( cb, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged( int ) ) ); return cb; } @@ -64,6 +84,12 @@ void QDS_CheckBox::onParamChanged() emit paramChanged(); } +void QDS_CheckBox::onStateChanged( int state ) +{ + if ( state != QButton::NoChange && checkBox() ) + checkBox()->setTristate( false ); +} + void QDS_CheckBox::setChecked( const bool theState ) { if ( checkBox() ) diff --git a/src/QDS/QDS_CheckBox.h b/src/QDS/QDS_CheckBox.h index 7c04edaad..8b1344b93 100644 --- a/src/QDS/QDS_CheckBox.h +++ b/src/QDS/QDS_CheckBox.h @@ -16,11 +16,14 @@ public: bool isChecked() const; void setChecked( const bool ); + virtual void clear(); + signals: void toggled( bool ); private slots: void onParamChanged(); + void onStateChanged( int ); protected: QCheckBox* checkBox() const; diff --git a/src/QDS/QDS_ComboBox.cxx b/src/QDS/QDS_ComboBox.cxx index f5e9ef80b..fac69b6b4 100644 --- a/src/QDS/QDS_ComboBox.cxx +++ b/src/QDS/QDS_ComboBox.cxx @@ -98,6 +98,8 @@ int QDS_ComboBox::integerValue() const */ double QDS_ComboBox::doubleValue() const { + initDatum(); + QComboBox* cb = comboBox(); QString cur = getString(); if ( cb && cb->count() > 0 && cb->currentItem() >= 0 ) @@ -114,6 +116,8 @@ double QDS_ComboBox::doubleValue() const */ void QDS_ComboBox::setIntegerValue( const int id ) { + initDatum(); + if ( myValue.contains( id ) ) setString( myValue[id] ); else @@ -125,6 +129,8 @@ void QDS_ComboBox::setIntegerValue( const int id ) */ void QDS_ComboBox::setDoubleValue( const double val ) { + initDatum(); + int id = (int)val; if ( myValue.contains( id ) ) setString( myValue[id] ); @@ -166,6 +172,8 @@ void QDS_ComboBox::setState( const bool on, const int id, const bool append ) */ void QDS_ComboBox::setState( const bool on, const QValueList& ids, const bool append ) { + initDatum(); + if ( ids.isEmpty() && append ) return; @@ -200,6 +208,8 @@ void QDS_ComboBox::setState( const bool on, const QValueList& ids, const bo */ void QDS_ComboBox::setValues( const QValueList& ids, const QStringList& names ) { + initDatum(); + if ( ids.count() != names.count() ) return; @@ -214,6 +224,8 @@ void QDS_ComboBox::setValues( const QValueList& ids, const QStringList& nam */ void QDS_ComboBox::setValues( const QStringList& names ) { + initDatum(); + QValueList< int > ids; for ( int i = 0, n = names.count(); i < n; i++ ) ids.append( i ); diff --git a/src/QDS/QDS_Datum.cxx b/src/QDS/QDS_Datum.cxx index f2a4919ba..f7a76b649 100644 --- a/src/QDS/QDS_Datum.cxx +++ b/src/QDS/QDS_Datum.cxx @@ -283,6 +283,14 @@ QString QDS_Datum::shortDescription() const return sdStr; } +QVariant QDS_Datum::value() const +{ + QVariant val; + if ( !isEmpty() ) + val = stringValue(); + return val; +} + QString QDS_Datum::stringValue() const { initDatum(); @@ -382,6 +390,14 @@ void QDS_Datum::clear() } } +void QDS_Datum::setValue( const QVariant& val ) +{ + if ( val.isValid() && val.canCast( QVariant::String ) ) + setStringValue( val.toString() ); + else + clear(); +} + void QDS_Datum::setStringValue( const QString& txt ) { initDatum(); diff --git a/src/QDS/QDS_Datum.h b/src/QDS/QDS_Datum.h index a3a056d7d..3a1a92985 100644 --- a/src/QDS/QDS_Datum.h +++ b/src/QDS/QDS_Datum.h @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -41,6 +42,8 @@ public: QString minimumValue() const; QString maximumValue() const; + virtual QVariant value() const; + virtual QString stringValue() const; virtual double doubleValue() const; virtual int integerValue() const; @@ -52,6 +55,8 @@ public: virtual void reset(); virtual void clear(); + virtual void setValue( const QVariant& ); + virtual void setStringValue( const QString& ); virtual void setDoubleValue( const double ); virtual void setIntegerValue( const int ); @@ -139,9 +144,10 @@ protected: virtual void unitSystemChanged( const QString& ); + void initDatum() const; + private: void initialize(); - void initDatum() const; Wrapper* wrapper( QWidget* ) const; Wrapper* wrapper( const int ) const; diff --git a/src/QDS/QDS_LineEdit.h b/src/QDS/QDS_LineEdit.h index 883d38cb7..ec9ad48a2 100644 --- a/src/QDS/QDS_LineEdit.h +++ b/src/QDS/QDS_LineEdit.h @@ -28,8 +28,8 @@ private slots: void onTextChanged( const QString& ); protected: - QLineEdit* lineEdit() const; virtual QWidget* createControl( QWidget* ); + QLineEdit* lineEdit() const; virtual QString getString() const; virtual void setString( const QString& ); diff --git a/src/QDS/QDS_RadioBox.cxx b/src/QDS/QDS_RadioBox.cxx new file mode 100644 index 000000000..1b3350fb3 --- /dev/null +++ b/src/QDS/QDS_RadioBox.cxx @@ -0,0 +1,379 @@ +#include "QDS_RadioBox.h" + +#include + +#include +#include +#include + +#include +#include +#include + +/*! + Constructor. +*/ +QDS_RadioBox::QDS_RadioBox( const QString& id, QWidget* parent, const int flags, const QString& comp ) +: QDS_Datum( id, parent, flags & ~( Label | Units ), comp ) +{ +} + +/*! + Destructor. +*/ +QDS_RadioBox::~QDS_RadioBox() +{ +} + +/*! + Returns number of items in ComboBox. If total is 'false' then only + visible items are taken into account otherwise all items. +*/ +int QDS_RadioBox::count( bool total ) const +{ + if ( total ) + return myValue.count(); + else + { + QPtrList bList; + buttons( bList ); + return bList.count(); + } +} + +/*! + Returns list of ids. If total is 'false' then only visible items + are taken into account otherwise all items. +*/ +void QDS_RadioBox::values( QValueList& ids, bool total ) const +{ + ids.clear(); + for ( QIntList::const_iterator it = myDataIds.begin(); it != myDataIds.end(); ++it ) + if ( total || ( myState.contains( *it ) && myState[*it] ) ) + ids.append( *it ); +} + +/*! + Returns visible state of identificator. +*/ +bool QDS_RadioBox::state( const int id ) const +{ + bool state = false; + if ( myState.contains( id ) ) + state = myState[id]; + return state; +} + +/*! + Sets the visible state of identificator. If 'id' is -1 then specified + state will be set to all ids. +*/ +void QDS_RadioBox::setState( const bool on, const int id, const bool append ) +{ + QValueList lst; + if ( id < 0 ) + { + for ( IdStateMap::Iterator it = myState.begin(); it != myState.end(); ++it ) + lst.append( it.key() ); + } + else + lst.append( id ); + + setState( on, lst, append ); +} + +/*! + Sets the visible state of identificator from the specified list. +*/ +void QDS_RadioBox::setState( const bool on, const QValueList& ids, const bool append ) +{ + if ( ids.isEmpty() && append ) + return; + + bool changed = false; + + QMap aMap; + for ( uint i = 0; i < ids.count(); i++ ) + aMap.insert( *ids.at( i ), 0 ); + + for ( IdStateMap::Iterator it = myState.begin(); it != myState.end(); ++it ) + { + if ( aMap.contains( it.key() ) ) + { + if ( it.data() != on ) + { + it.data() = on; + changed = true; + } + } + else if ( !append && it.data() == on ) + { + it.data() = !on; + changed = true; + } + } + if ( changed ) + updateRadioBox(); +} + +/*! + Sets the user items into the combo box. +*/ +void QDS_RadioBox::setValues( const QValueList& ids, const QStringList& names ) +{ + if ( ids.count() != names.count() ) + return; + + myUserIds = ids; + myUserNames = names; +} + +/*! + This is an overloaded member function, provided for convenience. + It behaves essentially like the above function. It creates + QValueList (0, 1, 2 ... ) and call previous method +*/ +void QDS_RadioBox::setValues( const QStringList& names ) +{ + QValueList< int > ids; + for ( int i = 0, n = names.count(); i < n; i++ ) + ids.append( i ); + setValues( ids, names ); +} + +/*! + Returns string from control. +*/ +QString QDS_RadioBox::getString() const +{ + QString res; + QButtonGroup* bg = buttonGroup(); + if ( bg ) + { + int id = bg->selectedId(); + if ( id != -1 ) + res = QString::number( id ); + } + return res; +} + +/*! + Sets the string into control. +*/ +void QDS_RadioBox::setString( const QString& txt ) +{ + QButtonGroup* bg = buttonGroup(); + if ( !bg ) + return; + + int oldId = bg->selectedId(); + + if ( txt.isEmpty() ) + { + QPtrList bList; + buttons( bList ); + for ( QPtrListIterator it( bList ); it.current(); ++it ) + it.current()->setChecked( false ); + } + else + { + bool ok; + int id = txt.toInt( &ok ); + if ( !ok ) + id = -1; + + bool block = signalsBlocked(); + blockSignals( true ); + bg->setButton( id ); + blockSignals( block ); + } + + int newId = bg->selectedId(); + + if ( oldId != newId ) + { + onParamChanged(); + QString str = getString(); + emit activated( newId ); + emit paramChanged(); + emit paramChanged( str ); + } +} + +/*! + Returns pointer to QButtonGroup widget. +*/ +QButtonGroup* QDS_RadioBox::buttonGroup() const +{ + return ::qt_cast( controlWidget() ); +} + +/*! + Create QComboBox widget as control subwidget. +*/ +QWidget* QDS_RadioBox::createControl( QWidget* parent ) +{ + QButtonGroup* bg = new QButtonGroup( 1, Qt::Vertical, "", parent ); + bg->setExclusive( true ); + bg->setRadioButtonExclusive( true ); + return bg; +} + +void QDS_RadioBox::unitSystemChanged( const QString& system ) +{ + QDS_Datum::unitSystemChanged( system ); + + Handle(TColStd_HArray1OfInteger) anIds; + Handle(TColStd_HArray1OfExtendedString) aValues, anIcons; + + Handle(DDS_DicItem) aDicItem = dicItem(); + if ( !aDicItem.IsNull() ) + aDicItem->GetListOfValues( aValues, anIds, anIcons ); + + myValue.clear(); + myDataIds.clear(); + + QMap userMap; + QIntList::iterator iIt = myUserIds.begin(); + QStringList::iterator sIt = myUserNames.begin(); + for ( ; iIt != myUserIds.end() && sIt != myUserNames.end(); ++iIt, ++sIt ) + userMap.insert( *iIt, *sIt ); + + if ( !anIds.IsNull() && !aValues.IsNull() && + anIds->Length() == aValues->Length() ) + { + for ( int i = anIds->Lower(); i <= anIds->Upper(); i++ ) + { + QString aValue; + int id = anIds->Value( i ); + if ( userMap.contains( id ) ) + aValue = userMap[id]; + else + aValue = toQString( aValues->Value( i ) ); + + myDataIds.append( id ); + myValue.insert( id, aValue ); + myState.insert( id, true ); + } + } + + for ( iIt = myUserIds.begin(); iIt != myUserIds.end(); ++iIt ) + { + int id = *iIt; + if ( !myValue.contains( id ) ) + { + myDataIds.append( id ); + myValue.insert( id, userMap[id] ); + } + } + + QIntList del, add; + for ( IdStateMap::Iterator it1 = myState.begin(); it1 != myState.end(); ++it1 ) + if ( !myValue.contains( it1.key() ) ) + del.append( it1.key() ); + + for ( IdValueMap::Iterator it2 = myValue.begin(); it2 != myValue.end(); ++it2 ) + if ( !myState.contains( it2.key() ) ) + add.append( it2.key() ); + + for ( QIntList::iterator iter1 = del.begin(); iter1 != del.end(); ++iter1 ) + myState.remove( *iter1 ); + + for ( QIntList::iterator iter2 = add.begin(); iter2 != add.end(); ++iter2 ) + myState.insert( *iter2, true ); + + QButtonGroup* bg = buttonGroup(); + if ( bg ) + bg->setTitle( label() ); + + updateRadioBox(); +} + +/*! + Notify about state changed in line edit of RadioBox. +*/ +void QDS_RadioBox::onToggled( bool on ) +{ + if ( !on ) + return; + + onParamChanged(); + emit paramChanged(); + QString str = getString(); + emit paramChanged( str ); +} + +/*! + Updates RadioBox after have change of visible state or items have been inserted / removed. +*/ +void QDS_RadioBox::updateRadioBox() +{ + QButtonGroup* bg = buttonGroup(); + if ( !bg ) + return; + + int curId = bg->selectedId(); + + QPtrList bList; + buttons( bList ); + for ( QPtrListIterator itr( bList ); itr.current(); ++itr ) + delete itr.current(); + + for ( QIntList::const_iterator it = myDataIds.begin(); it != myDataIds.end(); ++it ) + { + int id = *it; + if ( !myValue.contains( id ) || !myState.contains( id ) || !myState[id] ) + continue; + + QRadioButton* rb = new QRadioButton( myValue[id], bg ); + bg->insert( rb, id ); + + connect( rb, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) ); + } + + if ( curId != -1 ) + { + int id = curId; + if ( !bg->find( id ) ) + { + QPtrList bList; + buttons( bList ); + if ( !bList.isEmpty() ) + id = bg->id( bList.getFirst() ); + } + + bool block = signalsBlocked(); + blockSignals( true ); + bg->setButton( id ); + blockSignals( block ); + } + + if ( curId != bg->selectedId() ) + { + onParamChanged(); + emit paramChanged(); + emit paramChanged( getString() ); + } +} + +void QDS_RadioBox::buttons( QPtrList& lst ) const +{ + lst.setAutoDelete( false ); + lst.clear(); + + QButtonGroup* bg = buttonGroup(); + if ( !bg ) + return; + + QObjectList* objs = bg->queryList( "QRadioButton" ); + if ( objs ) + { + for ( QObjectListIt it( *objs ); it.current(); ++it ) + { + QRadioButton* rb = ::qt_cast( it.current() ); + if ( rb ) + lst.append( rb ); + } + } + delete objs; +} diff --git a/src/QDS/QDS_RadioBox.h b/src/QDS/QDS_RadioBox.h new file mode 100644 index 000000000..769a537ed --- /dev/null +++ b/src/QDS/QDS_RadioBox.h @@ -0,0 +1,75 @@ +#ifndef QDS_RADIOBOX_H +#define QDS_RADIOBOX_H + +#include "QDS_Datum.h" + +#include + +#include +#include +#include + +#ifdef WNT +#pragma warning( disable:4251 ) +#endif + +class QButtonGroup; +class QRadioButton; + +class QDS_EXPORT QDS_RadioBox : public QDS_Datum +{ + Q_OBJECT + +public: + QDS_RadioBox( const QString&, QWidget* = 0, const int = All, const QString& = QString::null ); + virtual ~QDS_RadioBox(); + + int count( bool = false ) const; + void values( QValueList&, bool = false ) const; + + int columns() const; + void setColumns( const int ); + + bool state( const int ) const; + void setState( const bool, const int, const bool = true ); + void setState( const bool, const QValueList&, const bool = true ); + void setValues( const QValueList&, const QStringList& ); + void setValues( const QStringList& ); + +signals: + void activated( int ); + +protected slots: + virtual void onToggled( bool ); + +protected: + QButtonGroup* buttonGroup() const; + virtual QWidget* createControl( QWidget* ); + void buttons( QPtrList& ) const; + + virtual QString getString() const; + virtual void setString( const QString& ); + + virtual void unitSystemChanged( const QString& ); + +private: + void updateRadioBox(); + +private: + typedef QMap IdValueMap; + typedef QMap IdStateMap; + +private: + IdValueMap myValue; + IdStateMap myState; + + QIntList myDataIds; + QIntList myUserIds; + QStringList myUserNames; +}; + +#ifdef WNT +#pragma warning( default:4251 ) +#endif + +#endif diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index 29e178a19..d5376b7e0 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -36,8 +36,9 @@ Level: Internal */ -QtxResourceMgr::Resources::Resources( const QString& fileName ) -: myFileName( fileName ) +QtxResourceMgr::Resources::Resources( const QtxResourceMgr* mgr, const QString& fileName ) +: myFileName( fileName ), + myMgr( const_cast( mgr ) ) { } @@ -130,6 +131,11 @@ QString QtxResourceMgr::Resources::path( const QString& sec, const QString& pref return filePath; } +QtxResourceMgr* QtxResourceMgr::Resources::resMgr() const +{ + return myMgr; +} + QtxResourceMgr::Section& QtxResourceMgr::Resources::section( const QString& sn ) { if ( !mySections.contains( sn ) ) @@ -157,12 +163,30 @@ QString QtxResourceMgr::Resources::fileName( const QString& sect, const QString& path = Qtx::addSlash( path ) + name; } } - return QDir::convertSeparators( path ); + if( !path.isEmpty() ) + { + QString fname = QDir::convertSeparators( path ); + QFileInfo inf( fname ); + fname = inf.absFilePath(); + return fname; + } + return QString(); } QPixmap QtxResourceMgr::Resources::loadPixmap( const QString& sect, const QString& prefix, const QString& name ) const { - return QPixmap( fileName( sect, prefix, name ) ); + QString fname = fileName( sect, prefix, name ); + bool toCache = resMgr() ? resMgr()->isPixmapCached() : false; + QPixmap p; + if( toCache && myPixmapCache.contains( fname ) ) + p = myPixmapCache[fname]; + else + { + p.load( fname ); + if( toCache ) + ( ( QMap& )myPixmapCache ).insert( fname, p ); + } + return p; } QTranslator* QtxResourceMgr::Resources::loadTranslator( const QString& sect, const QString& prefix, const QString& name ) const @@ -639,10 +663,14 @@ bool QtxResourceMgr::Format::save( Resources* res ) function userFileName(). Any resource looking firstly in the user home resources then resource directories used in the specified order. All setted resources always stored into the resource file at the user home. Only user home resource file is saved. + If you want to ignore of loading of Local User Preferences, you needs setup setIngoreUserValues() + as true. */ QtxResourceMgr::QtxResourceMgr( const QString& appName, const QString& resVarTemplate ) : myAppName( appName ), -myCheckExist( true ) + myCheckExist( true ), + myIsPixmapCached( true ), + myIsIgnoreUserValues( false ) { QString envVar = !resVarTemplate.isEmpty() ? resVarTemplate : QString( "%1Resources" ); if ( envVar.contains( "%1" ) ) @@ -721,18 +749,35 @@ void QtxResourceMgr::initialize( const bool autoLoad ) const QtxResourceMgr* that = (QtxResourceMgr*)this; if ( !userFileName( appName() ).isEmpty() ) - that->myResources.append( new Resources( userFileName( appName() ) ) ); + that->myResources.append( new Resources( this, userFileName( appName() ) ) ); for ( QStringList::const_iterator it = myDirList.begin(); it != myDirList.end(); ++it ) { QString path = Qtx::addSlash( *it ) + globalFileName( appName() ); - that->myResources.append( new Resources( path ) ); + that->myResources.append( new Resources( this, path ) ); } if ( autoLoad ) that->load(); } +/*! + \brief Return true if all loaded pixmaps are stored in internal map; by default: true +*/ +bool QtxResourceMgr::isPixmapCached() const +{ + return myIsPixmapCached; +} + +/*! + \brief Set true, if it is necessary to store all loaded pixmap in internal map + (it accelerates following calls of loadPixmap) +*/ +void QtxResourceMgr::setIsPixmapCached( const bool on ) +{ + myIsPixmapCached = on; +} + /*! \brief Removes all resources from the manager. */ @@ -742,6 +787,16 @@ void QtxResourceMgr::clear() it.current()->clear(); } +void QtxResourceMgr::setIgnoreUserValues( const bool val ) +{ + myIsIgnoreUserValues = val; +} + +bool QtxResourceMgr::ignoreUserValues() const +{ + return myIsIgnoreUserValues; +} + /*! \brief Get the resource value as integer. Returns 'true' if it successfull otherwise returns 'false'. @@ -906,7 +961,12 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QString& v initialize(); bool ok = false; - for ( ResListIterator it( myResources ); it.current() && !ok; ++it ) + + ResListIterator it( myResources ); + if ( ignoreUserValues() ) + ++it; + + for ( ; it.current() && !ok; ++it ) { ok = it.current()->hasValue( sect, name ); if ( ok ) diff --git a/src/Qtx/QtxResourceMgr.h b/src/Qtx/QtxResourceMgr.h index 868dc9fde..f75345425 100644 --- a/src/Qtx/QtxResourceMgr.h +++ b/src/Qtx/QtxResourceMgr.h @@ -68,8 +68,14 @@ public: bool checkExisting() const; virtual void setCheckExisting( const bool ); + bool isPixmapCached() const; + void setIsPixmapCached( const bool ); + void clear(); + void setIgnoreUserValues( const bool = true ); + bool ignoreUserValues() const; + bool value( const QString&, const QString&, int& ) const; bool value( const QString&, const QString&, double& ) const; bool value( const QString&, const QString&, bool& ) const; @@ -165,6 +171,9 @@ private: bool myCheckExist; TransListMap myTranslator; QPixmap myDefaultPix; + bool myIsPixmapCached; + + bool myIsIgnoreUserValues; }; /*! @@ -202,7 +211,7 @@ private: class QtxResourceMgr::Resources { public: - Resources( const QString& ); + Resources( const QtxResourceMgr*, const QString& ); virtual ~Resources(); QString file() const; @@ -230,6 +239,9 @@ public: QString path( const QString&, const QString&, const QString& ) const; +protected: + QtxResourceMgr* resMgr() const; + private: Section& section( const QString& ); const Section& section( const QString& ) const; @@ -242,6 +254,8 @@ private: private: SectionMap mySections; QString myFileName; + QMap myPixmapCache; + QtxResourceMgr* myMgr; friend class QtxResourceMgr::Format; }; diff --git a/src/Qtx/QtxToolTip.cxx b/src/Qtx/QtxToolTip.cxx index 0365ba135..5141e127d 100755 --- a/src/Qtx/QtxToolTip.cxx +++ b/src/Qtx/QtxToolTip.cxx @@ -31,7 +31,7 @@ #define TOOLTIP_HIDE_DELAY 7000 QtxToolTip::QtxToolTip( QWidget* parent ) -: QLabel( parent, "", WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WStyle_StaysOnTop | WType_TopLevel ) +: QLabel( parent, "", WStyle_Customize | WStyle_NoBorder | WX11BypassWM | WStyle_Tool | WStyle_StaysOnTop | WType_TopLevel ) { setIndent( 3 ); setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); diff --git a/src/SALOME_PY/SalomePy.cxx b/src/SALOME_PY/SalomePy.cxx index 1013f34cc..69ef49106 100755 --- a/src/SALOME_PY/SalomePy.cxx +++ b/src/SALOME_PY/SalomePy.cxx @@ -42,8 +42,6 @@ #include "SVTK_ViewManager.h" #include "SVTK_ViewWindow.h" -#include "SVTK_RenderWindow.h" -#include "SVTK_RenderWindowInteractor.h" using namespace std; @@ -132,7 +130,7 @@ public: virtual void Execute() { if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow() ) { PyObject* aPyClass = GetPyClass("vtkRenderWindow"); - vtkRenderWindow* aVTKObject = aVTKViewWindow->getRenderWindow()->getRenderWindow(); + vtkRenderWindow* aVTKObject = aVTKViewWindow->getRenderWindow(); myResult = PyVTKObject_New(aPyClass,aVTKObject); } } @@ -153,7 +151,7 @@ public: virtual void Execute() { if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow() ) { PyObject* aPyClass = GetPyClass("vtkRenderWindowInteractor"); - vtkRenderWindowInteractor* aVTKObject = aVTKViewWindow->getRWInteractor(); + vtkRenderWindowInteractor* aVTKObject = aVTKViewWindow->getInteractor(); myResult = PyVTKObject_New(aPyClass,aVTKObject); } } diff --git a/src/SUIT/Makefile.in b/src/SUIT/Makefile.in index f08c897d0..a6bab14a7 100755 --- a/src/SUIT/Makefile.in +++ b/src/SUIT/Makefile.in @@ -41,7 +41,8 @@ EXPORT_HEADERS= SUIT.h \ SUIT_ViewModel.h \ SUIT_ViewWindow.h \ SUIT_SelectionFilter.h \ - SUIT_Accel.h + SUIT_Accel.h \ + SUIT_TreeSync.h # .po files to transform in .qm PO_FILES = SUIT_images.po \ diff --git a/src/SUIT/SUIT_Application.cxx b/src/SUIT/SUIT_Application.cxx index 4ae8aec86..f187bfabd 100755 --- a/src/SUIT/SUIT_Application.cxx +++ b/src/SUIT/SUIT_Application.cxx @@ -120,16 +120,19 @@ SUIT_ResourceMgr* SUIT_Application::resourceMgr() const #define DEFAULT_MESSAGE_DELAY 3000 void SUIT_Application::putInfo ( const QString& msg, const int msec ) { - if ( desktop() ) { - //desktop()->statusBar()->message( msg, msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec ); - if ( !myStatusLabel ) { - myStatusLabel = new QLabel (desktop()->statusBar()); - desktop()->statusBar()->addWidget(myStatusLabel, /*int stretch = */1); - } - myStatusLabel->setText(msg); - if( msec != -1 ) - QTimer::singleShot(msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec, myStatusLabel, SLOT(clear())); + if ( !desktop() ) + return; + + if ( !myStatusLabel ) + { + myStatusLabel = new QLabel( desktop()->statusBar() ); + desktop()->statusBar()->addWidget( myStatusLabel, 1 ); + myStatusLabel->show(); } + + myStatusLabel->setText( msg ); + if ( msec != -1 ) + QTimer::singleShot( msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec, myStatusLabel, SLOT( clear() ) ); } SUIT_Application* SUIT_Application::startApplication( int argc, char** argv ) const diff --git a/src/SUIT/SUIT_FileDlg.cxx b/src/SUIT/SUIT_FileDlg.cxx index 80a6ad589..ec580efd6 100755 --- a/src/SUIT/SUIT_FileDlg.cxx +++ b/src/SUIT/SUIT_FileDlg.cxx @@ -521,3 +521,19 @@ QString SUIT_FileDlg::getExistingDirectory( QWidget* parent, return dirname; } + +/*! + QFileDialog::dirPath() has a bug on Linux Debian (1 level up from correct + directory is returned). This function fixes the bug. +*/ +QString SUIT_FileDlg::dirPath() const +{ + if ( !mySelectedFile.isNull() ) + return QFileInfo( mySelectedFile ).dirPath(); + + const QDir* aDir = dir(); + if ( aDir->exists() ) + return aDir->absPath(); + + return QFileDialog::dirPath(); +} diff --git a/src/SUIT/SUIT_FileDlg.h b/src/SUIT/SUIT_FileDlg.h index bb9ae4e3f..fcdb7da13 100755 --- a/src/SUIT/SUIT_FileDlg.h +++ b/src/SUIT/SUIT_FileDlg.h @@ -45,6 +45,9 @@ public: void setValidator( SUIT_FileValidator* ); + QString dirPath() const; // QFileDialog::dirPath() has a bug on Linux Debian (1 level up from correct + // directory is returned). This redefinition fixes the bug. + static QString getFileName( QWidget* parent, const QString& initial, const QStringList& filters, const QString& caption, const bool open, const bool showQuickDir = true, SUIT_FileValidator* validator = 0 ); diff --git a/src/SUIT/SUIT_Operation.h b/src/SUIT/SUIT_Operation.h index 6d44d9502..4f1b617b9 100755 --- a/src/SUIT/SUIT_Operation.h +++ b/src/SUIT/SUIT_Operation.h @@ -31,10 +31,11 @@ #ifndef SUIT_OPERATION_H #define SUIT_OPERATION_H -#include - #include "SUIT.h" +#include +#include + class SUIT_Study; class SUIT_Application; @@ -54,6 +55,10 @@ class SUIT_Application; * - virtual void resumeOperation(); * - virtual void suspendOperation(); */ +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + class SUIT_EXPORT SUIT_Operation : public QObject { Q_OBJECT @@ -152,14 +157,21 @@ protected: void start( SUIT_Operation*, const bool = false ); +private: + typedef QGuardedPtr StudyPtr; + private: SUIT_Application* myApp; //!< application for this operation int myFlags; //!< operation flags - SUIT_Study* myStudy; //!< study for this operation + StudyPtr myStudy; //!< study for this operation OperationState myState; //!< Operation state ExecStatus myExecStatus; //!< Execution status friend class SUIT_Study; }; +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + #endif diff --git a/src/SUIT/SUIT_TreeSync.h b/src/SUIT/SUIT_TreeSync.h new file mode 100644 index 000000000..d38f6fcdf --- /dev/null +++ b/src/SUIT/SUIT_TreeSync.h @@ -0,0 +1,177 @@ + +#ifndef SUIT_TREE_SYNC_HEADER +#define SUIT_TREE_SYNC_HEADER + +#include +#include + +template +struct DiffItem +{ + SrcItem mySrc; //if it is null, then this item is to deleted + TrgItem myTrg; //if it is null, then this item is to added + //if both fields aren't null, then this item is to update +}; + +template +TrgItem synchronize( const SrcItem&, const TrgItem&, const TreeData& ); + +template +void diffSiblings( const SrcItem&, const TrgItem&, + QValueList < DiffItem < SrcItem,TrgItem > >&, + const TreeData& ); + +template +TrgItem createSubTree( const SrcItem&, const TrgItem&, const TrgItem&, const bool, const TreeData& ); + +template +const typename QValueList::const_iterator findEqual( const QValueList& l, + const typename QValueList::const_iterator& first, + const SrcItem& it, + const TreeData& td ); + + + + + +//int gSync = 0; +template +TrgItem synchronize( const SrcItem& r1, const TrgItem& r2, const TreeData& td ) +{ + // printf( "--- synchronize : %d ---\n", ++gSync ); + + if( td.isEqual( r1, r2 ) ) + { + QValueList< DiffItem< SrcItem, TrgItem > > d; + diffSiblings( r1, r2, d, td ); + + typename QValueList< DiffItem< SrcItem, TrgItem > >::const_iterator anIt = d.begin(), aLast = d.end(); + bool isFirst = true; + TrgItem lastItem = td.nullTrg(); + // TrgItem tail = td.nullTrg(); + for( ; anIt!=aLast; anIt++ ) + { + const DiffItem& item = *anIt; + if( item.mySrc==td.nullSrc() ) + if( item.myTrg==td.nullTrg() ) + qDebug( "error: both null" ); + else + //to delete + td.deleteItemWithChildren( item.myTrg ); + else { + if( item.myTrg==td.nullTrg() ) + { + //to add + lastItem = createSubTree( item.mySrc, r2, lastItem, isFirst, td ); + } + else + { + //to update + td.updateItem( item.myTrg ); + synchronize( item.mySrc, item.myTrg, td ); + lastItem = item.myTrg; + } + isFirst = false; + } + } + + return r2; + } + else + { + TrgItem new_r2 = createSubTree( r1, td.parent( r2 ), r2, false, td ); + if( r2!=td.nullTrg() ) + td.deleteItemWithChildren( r2 ); + return new_r2; + } +} + +template +const typename QValueList::const_iterator findEqual( const QValueList& l, + const typename QValueList::const_iterator& first, + const SrcItem& it, + const TreeData& td ) +{ + typename QValueList::const_iterator cur = first, last = l.end(); + for( ; cur!=last; cur++ ) + if( td.isEqual( it, *cur ) ) + return cur; + return last; +} + +template +void diffSiblings( const SrcItem& src, const TrgItem& trg, + QValueList < DiffItem < SrcItem,TrgItem > >& d, + const TreeData& td ) +{ + if( src==td.nullSrc() || trg==td.nullTrg() ) + return; + + QValueList src_ch; + QValueList trg_ch; + td.children( src, src_ch ); + td.children( trg, trg_ch ); + + typename QValueList::const_iterator src_it = src_ch.begin(), src_last = src_ch.end(); + typename QValueList::const_iterator cur = trg_ch.begin(), trg_last = trg_ch.end(); + + for( ; src_it!=src_last; src_it++ ) + { + typename QValueList::const_iterator f = + findEqual( trg_ch, cur, *src_it, td ); + if( f!=trg_last ) //is found + { + //mark all items before found as "to be deleted" + for( typename QValueList::const_iterator it = cur; it!=f; it++ ) + { + DiffItem ndiff; + ndiff.mySrc = td.nullSrc(); + ndiff.myTrg = *it; //to delete; + d.append( ndiff ); + } + cur = f; + DiffItem ndiff; + ndiff.mySrc = *src_it; + ndiff.myTrg = *cur; //update this item + d.append( ndiff ); + cur++; + } + else //not found + { + DiffItem ndiff; + ndiff.mySrc = *src_it; + ndiff.myTrg = td.nullTrg(); //add this item + d.append( ndiff ); + } + } + for( ; cur!=trg_last; cur++ ) + { + DiffItem ndiff; + ndiff.mySrc = td.nullSrc(); + ndiff.myTrg = *cur; //to delete; + d.append( ndiff ); + } +} + +template +TrgItem createSubTree( const SrcItem& src, const TrgItem& parent, + const TrgItem& after, const bool asFirst, + const TreeData& td ) +{ + if( src==td.nullSrc() ) + return td.nullTrg(); + + TrgItem nitem = td.createItem( src, parent, after, asFirst ); + if( nitem==td.nullTrg() ) + return nitem; + + QValueList ch; + td.children( src, ch ); + typename QValueList::const_iterator anIt = ch.begin(), aLast = ch.end(); + for( ; anIt!=aLast; anIt++ ) + createSubTree( *anIt, nitem, td.nullTrg(), false, td ); + + return nitem; +} + +#endif diff --git a/src/SUIT/SUIT_ViewWindow.cxx b/src/SUIT/SUIT_ViewWindow.cxx index 68faecb85..bd4c32e69 100755 --- a/src/SUIT/SUIT_ViewWindow.cxx +++ b/src/SUIT/SUIT_ViewWindow.cxx @@ -158,16 +158,3 @@ void SUIT_ViewWindow::onAccelAction( int _action ) void SUIT_ViewWindow::action( const int ) { } - -/*! The method returns the visual parameters of this view as a formated string - */ -QString SUIT_ViewWindow::getVisualParameters() -{ - return " "; -} - -/* The method restors visual parameters of this view from a formated string - */ -void SUIT_ViewWindow::setVisualParameters( const QString& parameters ) -{ -} diff --git a/src/SUIT/SUIT_ViewWindow.h b/src/SUIT/SUIT_ViewWindow.h index 91d6a49e7..1ac79a504 100755 --- a/src/SUIT/SUIT_ViewWindow.h +++ b/src/SUIT/SUIT_ViewWindow.h @@ -52,9 +52,6 @@ public: void onAccelAction( int ); - virtual QString getVisualParameters(); - virtual void setVisualParameters( const QString& parameters ); - public slots: virtual void onDumpView(); diff --git a/src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx b/src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx index 1a8362daa..716cc8fca 100755 --- a/src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx +++ b/src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx @@ -133,6 +133,7 @@ SUPERVGraph_View* SUPERVGraph_ViewFrame::getViewWidget() void SUPERVGraph_ViewFrame::setViewWidget( SUPERVGraph_View* theView ) { myView = theView; + setFocusProxy( myView ); // mkr : IPAL11388 } diff --git a/src/SUPERVGraph/SUPERVGraph_ViewModel.h b/src/SUPERVGraph/SUPERVGraph_ViewModel.h index 695f1a8fc..82c6f6f93 100644 --- a/src/SUPERVGraph/SUPERVGraph_ViewModel.h +++ b/src/SUPERVGraph/SUPERVGraph_ViewModel.h @@ -34,6 +34,7 @@ public: virtual ~SUPERVGraph_Viewer(); virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop); + virtual QString getType() const { return Type(); } }; diff --git a/src/SalomeApp/Makefile.in b/src/SalomeApp/Makefile.in index 98b8492b2..308e5126b 100755 --- a/src/SalomeApp/Makefile.in +++ b/src/SalomeApp/Makefile.in @@ -26,7 +26,6 @@ EXPORT_HEADERS= SalomeApp.h \ SalomeApp_TypeFilter.h \ SalomeApp_StudyPropertiesDlg.h \ SalomeApp_CheckFileDlg.h -# SalomeApp_VisualParameters.h # .po files to transform in .qm PO_FILES = SalomeApp_images.po \ @@ -50,7 +49,6 @@ LIB_SRC= SalomeApp_Module.cxx \ SalomeApp_StudyPropertiesDlg.cxx \ SalomeApp_ListView.cxx \ SalomeApp_CheckFileDlg.cxx -# SalomeApp_VisualParameters.cxx LIB_MOC = SalomeApp_Application.h \ SalomeApp_DataModel.h \ diff --git a/src/SalomeApp/SalomeApp.h b/src/SalomeApp/SalomeApp.h index b5b65c0d3..d590d27a7 100644 --- a/src/SalomeApp/SalomeApp.h +++ b/src/SalomeApp/SalomeApp.h @@ -28,4 +28,3 @@ #pragma warning ( disable: 4251 ) #endif - diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 690b13b52..5139ce4f2 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -122,7 +122,7 @@ void SalomeApp_Application::createActions() //! Registry Display createAction( RegDisplayId, tr( "TOT_DESK_REGISTRY_DISPLAY" ), QIconSet(), tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ), - SHIFT+Key_D, desk, false, this, SLOT( onRegDisplay() ) ); + /*SHIFT+Key_D*/0, desk, false, this, SLOT( onRegDisplay() ) ); int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 ); @@ -743,9 +743,6 @@ void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* t 3. update object browser if it existing */ void SalomeApp_Application::updateObjectBrowser( const bool updateModels ) { - // update existing data models (already loaded SComponents) - LightApp_Application::updateObjectBrowser(updateModels); - // update "non-existing" (not loaded yet) data models SalomeApp_Study* study = dynamic_cast(activeStudy()); if ( study ) @@ -760,16 +757,24 @@ void SalomeApp_Application::updateObjectBrowser( const bool updateModels ) if ( aComponent->ComponentDataType() == "Interface Applicative" ) continue; // skip the magic "Interface Applicative" component - SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true ); + OB_Browser* ob = static_cast( getWindow( WT_ObjectBrowser )); + const bool isAutoUpdate = ob->isAutoUpdate(); + ob->setAutoUpdate( false ); + SalomeApp_DataModel::synchronize( aComponent, study ); + ob->setAutoUpdate( isAutoUpdate ); + //SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true ); } } } - if ( objectBrowser() ) + // update existing data models (already loaded SComponents) + LightApp_Application::updateObjectBrowser( updateModels ); + +/* if ( objectBrowser() ) { objectBrowser()->updateGeometry(); - objectBrowser()->updateTree( 0, false ); - } + objectBrowser()->updateTree(); + }*/ } /*!Display Catalog Genenerator dialog */ diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index 02adaa065..2462e557b 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -26,7 +26,6 @@ class QComboBox; class QDockWindow; class LightApp_Preferences; -class SalomeApp_Study; class SalomeApp_Module; class SALOME_LifeCycleCORBA; @@ -95,8 +94,6 @@ private slots: void onCatalogGen(); void onRegDisplay(); void onOpenWith(); - - friend class SalomeApp_Study; }; #ifdef WIN32 diff --git a/src/SalomeApp/SalomeApp_DataModel.cxx b/src/SalomeApp/SalomeApp_DataModel.cxx index 48838709e..5fcae7b7b 100644 --- a/src/SalomeApp/SalomeApp_DataModel.cxx +++ b/src/SalomeApp/SalomeApp_DataModel.cxx @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include "SALOMEDS_Tool.hxx" @@ -24,67 +26,151 @@ #include CORBA_SERVER_HEADER(SALOME_Exception) //======================================================================= -// name : BuildTree -/*!Purpose : static method used by SalomeApp_Study and SalomeApp_DataModel classes - * to create default SALOMEDS-based data object tree - */ +// name : SalomeApp_DataModelSync +/*!Purpose : Auxiliary class for synchronizing tree of kernel objects and SUIT_DataObjects */ //======================================================================= -SUIT_DataObject* SalomeApp_DataModel::BuildTree( const _PTR(SObject)& obj, - SUIT_DataObject* parent, - SalomeApp_Study* study, - bool skip ) + +typedef _PTR(SObject) kerPtr; +typedef SUIT_DataObject* suitPtr; + +class SalomeApp_DataModelSync { - SalomeApp_DataObject* aDataObj = 0; - if ( !obj || !study ) - return aDataObj; +public: + SalomeApp_DataModelSync( _PTR( Study ), SUIT_DataObject* ); - _PTR(SObject) refObj; - if ( obj->GetName().size() || obj->ReferencedObject( refObj ) ) // skip nameless non references SObjects - { - _PTR(SComponent) aSComp( obj ); + suitPtr createItem( const kerPtr&, const suitPtr&, const suitPtr&, const bool ) const; + void deleteItemWithChildren( const suitPtr& ) const; + bool isEqual( const kerPtr&, const suitPtr& ) const; + kerPtr nullSrc() const; + suitPtr nullTrg() const; + void children( const kerPtr&, QValueList& ) const; + void children( const suitPtr&, QValueList& ) const; + suitPtr parent( const suitPtr& ) const; + bool isCorrect( const kerPtr& ) const; + void updateItem( const suitPtr& ) const; + +private: + _PTR( Study ) myStudy; + SUIT_DataObject* myRoot; +}; + + +SalomeApp_DataModelSync::SalomeApp_DataModelSync( _PTR( Study ) aStudy, SUIT_DataObject* aRoot ) +: myStudy( aStudy ), + myRoot( aRoot ) +{ +} + +bool SalomeApp_DataModelSync::isCorrect( const kerPtr& so ) const +{ + kerPtr refObj; + QString name = so->GetName(); + bool res = so && ( so->GetName().size() || so->ReferencedObject( refObj ) ); + return res; +} - // patch for bug IPAL9313 - if ( aSComp && parent && skip ) +suitPtr SalomeApp_DataModelSync::createItem( const kerPtr& so, + const suitPtr& parent, + const suitPtr& after, + const bool asFirst ) const +{ + if( !isCorrect( so ) ) + return 0; + + _PTR(SComponent) aSComp( so ); + suitPtr nitem = aSComp ? new SalomeApp_ModuleObject( aSComp, 0 ) : + new SalomeApp_DataObject( so, 0 ); + if( parent ) + if( after ) { - QString aSName( aSComp->GetName().c_str() ); - DataObjectList allComponents = parent->children( /*recursive=*/false ); - for ( DataObjectListIterator it( allComponents ); it.current(); ++it ) { - SUIT_DataObject* componentObj = it.current(); - if ( componentObj->name() == aSName ) { - // mkr : modifications for update of already published in - // object browser, but not loaded yet components - LightApp_Application* anApp = dynamic_cast - (SUIT_Session::session()->activeApplication() ); - // asv : corresponding DataObjects are DELETED before update (so they are re-built). - if (anApp && !anApp->module(aSName)) { // if module is not loaded, delete it's DataObject - // jfa: remove children before DataObject deletion - DataObjectList chilren = componentObj->children(/*recursive=*/true); - for (DataObjectListIterator itc (chilren); itc.current(); ++itc) - componentObj->removeChild(itc.current()); - - // delete DataObject itself and re-create it and all its sub-objects - delete componentObj; - // don't do anything here, because iterator may be corrupted (deleted object inside it) - break; // proceed to build_a_data_object code below - } - else - return componentObj; - } - } + DataObjectList ch; + parent->children( ch ); + int pos = ch.find( after ); + if( pos>=0 ) + parent->insertChild( nitem, pos+1 ); + else + parent->appendChild( nitem ); } + else if( asFirst ) + parent->insertChild( nitem, 0 ); + else + parent->appendChild( nitem ); + else if( myRoot ) + myRoot->appendChild( nitem ); + return nitem; +} - aDataObj = aSComp ? new SalomeApp_ModuleObject( aSComp, parent ) : - new SalomeApp_DataObject ( obj, parent ); +void SalomeApp_DataModelSync::deleteItemWithChildren( const suitPtr& p ) const +{ + if( !p ) + return; - _PTR(ChildIterator) it ( study->studyDS()->NewChildIterator( obj ) ); - for ( ; it->More(); it->Next() ) { - // don't use shared_ptr here, for Data Object will take - // ownership of this pointer - _PTR(SObject) aSO( it->Value() ); - BuildTree( aSO, aDataObj, study ); - } + DataObjectList ch; + p->children( ch ); + DataObjectList::const_iterator anIt = ch.begin(), aLast = ch.end(); + for( ; anIt!=aLast; anIt++ ) + deleteItemWithChildren( *anIt ); + delete p; +} + +bool SalomeApp_DataModelSync::isEqual( const kerPtr& p, const suitPtr& q ) const +{ + LightApp_DataObject* obj = dynamic_cast( q ); + return ( !p && !q ) || ( obj && isCorrect( p ) && p->GetID()==obj->entry() ); +} + +kerPtr SalomeApp_DataModelSync::nullSrc() const +{ + return kerPtr(); +} + +suitPtr SalomeApp_DataModelSync::nullTrg() const +{ + return suitPtr( 0 ); +} + +void SalomeApp_DataModelSync::children( const kerPtr& obj, QValueList& ch ) const +{ + ch.clear(); + _PTR(ChildIterator) it ( myStudy->NewChildIterator( obj ) ); + for( ; it->More(); it->Next() ) + ch.append( it->Value() ); +} + +void SalomeApp_DataModelSync::children( const suitPtr& p, QValueList& ch ) const +{ + DataObjectList l; + if( p ) + { + p->children( l ); + ch.clear(); + for( SUIT_DataObject* o = l.first(); o; o = l.next() ) + ch.append( o ); + } +} + +suitPtr SalomeApp_DataModelSync::parent( const suitPtr& p ) const +{ + return p ? p->parent(): 0; +} + +void SalomeApp_DataModelSync::updateItem( const suitPtr& ) const +{ +} + +void showTree( SUIT_DataObject* root ) +{ + qDebug( root ? "" : "" ); + if( !root ) + return; + + SUIT_DataObjectIterator it( root, SUIT_DataObjectIterator::DepthLeft ); + for( ; it.current(); ++it ) + { + QString marg; marg.fill( ' ', 3*it.depth() ); + QString nnn = "%1 '%2'"; + qDebug( nnn.arg( marg ).arg( it.current()->name() ) ); } - return aDataObj; } //======================================================================= @@ -121,13 +207,23 @@ bool SalomeApp_DataModel::open( const QString& name, CAM_Study* study, QStringLi _PTR(Study) aStudy ( aDoc->studyDS() ); // shared_ptr cannot be used here _PTR(SComponent) aSComp ( aStudy->FindComponentID( std::string( anId.latin1() ) ) ); if ( aSComp ) - buildTree( aSComp, 0, aDoc ); + updateTree( aSComp, aDoc ); QStringList listOfFiles; LightApp_DataModel::open(name, study, listOfFiles); return true; } +//================================================================ +// Function : create +/*! Purpose : Create data model*/ +//================================================================ +bool SalomeApp_DataModel::create( CAM_Study* theStudy ) +{ + update(NULL, (LightApp_Study*)theStudy); + return true; +} + //================================================================ // Function : update /*! Purpose : Update application.*/ @@ -136,7 +232,7 @@ void SalomeApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study ) { SalomeApp_Study* aSStudy = dynamic_cast(study); LightApp_RootObject* studyRoot = 0; - _PTR(SObject) sobj; + _PTR(SComponent) sobj; SalomeApp_DataObject* modelRoot = dynamic_cast( root() ); if ( !modelRoot ){ // not yet connected to a study -> try using argument if ( !aSStudy ) @@ -161,26 +257,73 @@ void SalomeApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study ) } } } - buildTree( sobj, studyRoot, aSStudy ); + if ( sobj && aSStudy ) + updateTree( sobj, aSStudy ); } //================================================================ -// Function : buildTree -/*! Purpose : private method, build tree.*/ +// Function : synchronize +/*! Purpose : synchronizes kernel tree and suit data tree starting from component 'sobj' */ //================================================================ -void SalomeApp_DataModel::buildTree( const _PTR(SObject)& obj, - SUIT_DataObject* parent, - SalomeApp_Study* study ) +SUIT_DataObject* SalomeApp_DataModel::synchronize( const _PTR( SComponent )& sobj, SalomeApp_Study* study ) { - if ( !obj ) - return; - //if ( !root() ){ // Build default SALOMEDS-based data object tree and insert it into study - SalomeApp_ModuleObject* aNewRoot = dynamic_cast( BuildTree( obj, parent, study ) ); - if ( aNewRoot ){ - aNewRoot->setDataModel( this ); - setRoot( aNewRoot ); + if( !study || !study->root() || !sobj ) + return 0; + + DataObjectList ch; study->root()->children( ch ); + DataObjectList::const_iterator anIt = ch.begin(), aLast = ch.end(); + SalomeApp_DataObject* suitObj = 0; + for( ; anIt!=aLast; anIt++ ) + { + SalomeApp_DataObject* dobj = dynamic_cast( *anIt ); + if( dobj && dobj->name()==sobj->GetName().c_str() ) + { + suitObj = dobj; + break; } - //} + } + + SalomeApp_DataModelSync sync( study->studyDS(), study->root() ); + + // QString srcName = sobj ? sobj->GetName().c_str() : ""; + // QString trgName = ( suitObj && !suitObj->name().isNull() ) ? suitObj->name() : ""; + // printf( "--- SalomeApp_DataModel::syncronize() calls synchronize()_1: src = %s, trg = %s ---\n", srcName.latin1(), trgName.latin1() ); + + SUIT_DataObject* o = ::synchronize( sobj, suitObj, sync ); +// showTree( o ); + return o; +} + +//================================================================ +// Function : synchronize +/*! Purpose : synchronizes kernel tree and suit data tree starting from 'sobj' and 'obj' correspondly */ +//================================================================ +SUIT_DataObject* SalomeApp_DataModel::synchronize( const _PTR( SObject )& sobj, SUIT_DataObject* obj, + SalomeApp_Study* study ) +{ + if( !study ) + return 0; + SalomeApp_DataModelSync sync( study->studyDS(), study->root() ); + + // QString srcName = sobj ? sobj->GetName().c_str() : ""; + // QString trgName = ( obj && !obj->name().isNull() ) ? obj->name() : ""; + // printf( "--- SalomeApp_DataModel::syncronize() calls synchronize()_2: src = s, trg = %s ---\n", srcName.latin1(), trgName.latin1() ); + + return ::synchronize( sobj, obj, sync ); +} + +//================================================================ +// Function : updateTree +/*! Purpose : updates tree.*/ +//================================================================ +void SalomeApp_DataModel::updateTree( const _PTR( SComponent )& comp, SalomeApp_Study* study ) +{ + SalomeApp_ModuleObject* aNewRoot = dynamic_cast( synchronize( comp, study ) ); + if( aNewRoot ) + { + aNewRoot->setDataModel( this ); + setRoot( aNewRoot ); + } } //================================================================ diff --git a/src/SalomeApp/SalomeApp_DataModel.h b/src/SalomeApp/SalomeApp_DataModel.h index 4dab54d9b..62e649bc3 100644 --- a/src/SalomeApp/SalomeApp_DataModel.h +++ b/src/SalomeApp/SalomeApp_DataModel.h @@ -26,15 +26,14 @@ class SALOMEAPP_EXPORT SalomeApp_DataModel : public LightApp_DataModel Q_OBJECT public: - static SUIT_DataObject* BuildTree(const _PTR(SObject)& obj, - SUIT_DataObject* parent, - SalomeApp_Study* study, - bool skip = false ); + static SUIT_DataObject* synchronize( const _PTR( SComponent )&, SalomeApp_Study* ); + static SUIT_DataObject* synchronize( const _PTR( SObject )&, SUIT_DataObject*, SalomeApp_Study* ); SalomeApp_DataModel ( CAM_Module* theModule ); virtual ~SalomeApp_DataModel(); virtual bool open( const QString&, CAM_Study*, QStringList ); + virtual bool create( CAM_Study* ); virtual void update( LightApp_DataObject* = 0, LightApp_Study* = 0 ); QString getRootEntry( SalomeApp_Study* ) const; @@ -42,8 +41,8 @@ public: protected: SalomeApp_Study* getStudy() const; - - virtual void buildTree(const _PTR(SObject)&, SUIT_DataObject*, SalomeApp_Study* ); + virtual void updateTree( const _PTR( SComponent )&, SalomeApp_Study* ); }; + #endif diff --git a/src/SalomeApp/SalomeApp_DataObject.cxx b/src/SalomeApp/SalomeApp_DataObject.cxx index 938754e92..ef7b8df7b 100644 --- a/src/SalomeApp/SalomeApp_DataObject.cxx +++ b/src/SalomeApp/SalomeApp_DataObject.cxx @@ -111,8 +111,8 @@ QPixmap SalomeApp_DataObject::icon() const QString pixmapName = QObject::tr( aPixAttr->GetPixMap().c_str() ); LightApp_RootObject* aRoot = dynamic_cast( root() ); if ( aRoot && aRoot->study() ) { - QPixmap pixmap = aRoot->study()->application()->resourceMgr()->loadPixmap( componentDataType(), pixmapName, false ); - return pixmap; + SUIT_ResourceMgr* mgr = aRoot->study()->application()->resourceMgr(); + return mgr->loadPixmap( componentDataType(), pixmapName, false ); } } } diff --git a/src/VTKViewer/Makefile.in b/src/VTKViewer/Makefile.in index f36e73620..dd5f7ea29 100755 --- a/src/VTKViewer/Makefile.in +++ b/src/VTKViewer/Makefile.in @@ -67,7 +67,6 @@ LIB_SRC= VTKViewer_Actor.cxx \ VTKViewer_ViewModel.cxx \ VTKViewer_ConvexTool.cxx \ VTKViewer_ViewWindow.cxx - LIB_MOC = \ VTKViewer_RenderWindow.h \ @@ -76,10 +75,12 @@ LIB_MOC = \ VTKViewer_ViewModel.h \ VTKViewer_ViewWindow.h -CPPFLAGS+=$(QT_INCLUDES) $(VTK_INCLUDES) $(OCC_INCLUDES) +BIN = VTKViewer -LDFLAGS+=$(VTK_LIBS) $(QT_MT_LIBS) $(CAS_KERNEL) -lsuit +CPPFLAGS+=$(QT_INCLUDES) $(VTK_INCLUDES) $(OCC_INCLUDES) -@CONCLUDE@ +LDFLAGS+=$(VTK_LIBS) $(QT_MT_LIBS) $(CAS_KERNEL) +LDFLAGSFORBIN=$(LDFLAGS) -lqtx -lsuit +@CONCLUDE@ \ No newline at end of file diff --git a/src/VTKViewer/VTKViewer.cxx b/src/VTKViewer/VTKViewer.cxx new file mode 100644 index 000000000..9755466c0 --- /dev/null +++ b/src/VTKViewer/VTKViewer.cxx @@ -0,0 +1,57 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ + +#include "VTKViewer_Actor.h" +#include "VTKViewer_CellRectPicker.h" +#include "VTKViewer_ExtractUnstructuredGrid.h" +#include "VTKViewer_ConvexTool.h" +#include "VTKViewer_Filter.h" +#include "VTKViewer_GeometryFilter.h" +#include "VTKViewer_AppendFilter.h" +#include "VTKViewer_Algorithm.h" +#include "VTKViewer_InteractorStyle.h" +#include "VTKViewer_PassThroughFilter.h" +#include "VTKViewer_RectPicker.h" +#include "VTKViewer_RenderWindow.h" +#include "VTKViewer_RenderWindowInteractor.h" +#include "VTKViewer_ShrinkFilter.h" +#include "VTKViewer_TransformFilter.h" +#include "VTKViewer_Transform.h" +#include "VTKViewer_Trihedron.h" +#include "VTKViewer_Utilities.h" +#include "VTKViewer_VectorText.h" +#include "VTKViewer_ViewManager.h" +#include "VTKViewer_ViewModel.h" +#include "VTKViewer_ViewWindow.h" +#include "VTKViewer_Functor.h" + +int +main(int argc, char** argv) +{ + return 0; +} diff --git a/src/VTKViewer/VTKViewer_Actor.cxx b/src/VTKViewer/VTKViewer_Actor.cxx index 7b9e00353..da05fc98d 100755 --- a/src/VTKViewer/VTKViewer_Actor.cxx +++ b/src/VTKViewer/VTKViewer_Actor.cxx @@ -1,134 +1,167 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ // +// File : SALOME_Actor.cxx +// Author : Nicolas REJNERI +// Module : SALOME +// $Header$ + +/*! + \class SALOME_Actor SALOME_Actor.h + \brief Abstract class of SALOME Objects in VTK. +*/ + + #include "VTKViewer_Actor.h" + #include "VTKViewer_Transform.h" -#include "VTKViewer_GeometryFilter.h" #include "VTKViewer_TransformFilter.h" #include "VTKViewer_PassThroughFilter.h" +#include "VTKViewer_GeometryFilter.h" // VTK Includes +#include +#include #include #include #include +#include #include -#include -#include -#include +using namespace std; -/* -static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet){ - vtkPoints *aPoints = vtkPoints::New(); - vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints(); - aPoints->SetNumberOfPoints(iEnd); - for(vtkIdType i = 0; i < iEnd; i++){ - aPoints->SetPoint(i,theSourceDataSet->GetPoint(i)); - } - theGrid->SetPoints(aPoints); - aPoints->Delete(); -} -*/ +#if defined __GNUC__ + #if __GNUC__ == 2 + #define __GNUC_2__ + #endif +#endif +int VTKViewer_POINT_SIZE = 5; +int VTKViewer_LINE_WIDTH = 3; +//---------------------------------------------------------------------------- vtkStandardNewMacro(VTKViewer_Actor); -/*!Constructor.Initialize default parameters.*/ -VTKViewer_Actor::VTKViewer_Actor(){ - myIsHighlighted = myIsPreselected = false; - - myRepresentation = 1; - myDisplayMode = myRepresentation - 1; - - myProperty = vtkProperty::New(); - PreviewProperty = NULL; - - myIsInfinite = false; - myIsResolveCoincidentTopology = true; - +//---------------------------------------------------------------------------- +VTKViewer_Actor +::VTKViewer_Actor(): + myIsHighlighted(false), + myIsPreselected(false), + myRepresentation(VTK_SURFACE), + myDisplayMode(1), + myProperty(vtkProperty::New()), + PreviewProperty(NULL), + myIsInfinite(false), + myIsResolveCoincidentTopology(true), + myStoreMapping(false), + myGeomFilter(VTKViewer_GeometryFilter::New()), + myTransformFilter(VTKViewer_TransformFilter::New()) +{ vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, myPolygonOffsetUnits); - myStoreMapping = false; - myGeomFilter = VTKViewer_GeometryFilter::New(); - - myTransformFilter = VTKViewer_TransformFilter::New(); for(int i = 0; i < 6; i++) myPassFilter.push_back(VTKViewer_PassThroughFilter::New()); - - Visibility = Pickable = true; } -/*!Destructor.*/ -VTKViewer_Actor::~VTKViewer_Actor(){ +//---------------------------------------------------------------------------- +VTKViewer_Actor +::~VTKViewer_Actor() +{ SetPreviewProperty(NULL); - myGeomFilter->UnRegisterAllOutputs(); myGeomFilter->Delete(); - myTransformFilter->UnRegisterAllOutputs(); myTransformFilter->Delete(); - for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){ - if(myPassFilter[i]){ - myPassFilter[i]->UnRegisterAllOutputs(); + for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++) + if(myPassFilter[i]) myPassFilter[i]->Delete(); - } - } + myProperty->Delete(); } -/*!Add VTKViewer_Actor to renderer. - *\param theRenderer - vtkRenderer - */ -void VTKViewer_Actor::AddToRender(vtkRenderer* theRenderer){ + +//---------------------------------------------------------------------------- +const char* +VTKViewer_Actor +::getName() +{ + return myName.c_str(); +} + +void +VTKViewer_Actor +::setName(const char* theName) +{ + myName = theName; +} + + +//---------------------------------------------------------------------------- +void +VTKViewer_Actor +::AddToRender(vtkRenderer* theRenderer) +{ theRenderer->AddActor(this); } -/*!Remove VTKViewer_Actor from renderer. - *\param theRenderer - vtkRenderer - */ -void VTKViewer_Actor::RemoveFromRender(vtkRenderer* theRenderer){ +void +VTKViewer_Actor +::RemoveFromRender(vtkRenderer* theRenderer) +{ theRenderer->RemoveActor(this); } -/*!Add transformation to transform filter. - *\param theTransform - transformation. - */ -void VTKViewer_Actor::SetTransform(VTKViewer_Transform* theTransform){ +void +VTKViewer_Actor +::GetChildActors(vtkActorCollection*) +{} + + +//---------------------------------------------------------------------------- +void +VTKViewer_Actor +::SetTransform(VTKViewer_Transform* theTransform) +{ myTransformFilter->SetTransform(theTransform); } -/*!Set mapper to pipeline.\n - *Call method for pipeline initialization. - *\param theMapper - mapper - */ -void VTKViewer_Actor::SetMapper(vtkMapper* theMapper){ + +void +VTKViewer_Actor +::SetMapper(vtkMapper* theMapper) +{ InitPipeLine(theMapper); } -/*!Initialize sequence of filters for mapper, if \a theMapper is not null. - *\param theMapper - mapper - */ -void VTKViewer_Actor::InitPipeLine(vtkMapper* theMapper){ +void +VTKViewer_Actor +::InitPipeLine(vtkMapper* theMapper) +{ if(theMapper){ int anId = 0; myPassFilter[ anId ]->SetInput( theMapper->GetInput() ); @@ -156,11 +189,15 @@ void VTKViewer_Actor::InitPipeLine(vtkMapper* theMapper){ aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput()); } } - vtkLODActor::SetMapper(theMapper); + Superclass::SetMapper(theMapper); } -/*!*/ -void VTKViewer_Actor::Render(vtkRenderer *ren, vtkMapper* m){ + +//---------------------------------------------------------------------------- +void +VTKViewer_Actor +::Render(vtkRenderer *ren, vtkMapper* m) +{ if(myIsResolveCoincidentTopology){ int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology(); float aFactor, aUnit; @@ -169,52 +206,86 @@ void VTKViewer_Actor::Render(vtkRenderer *ren, vtkMapper* m){ vtkMapper::SetResolveCoincidentTopologyToPolygonOffset(); vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, myPolygonOffsetUnits); - vtkLODActor::Render(ren,m); + Superclass::Render(ren,m); vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology); }else{ - vtkLODActor::Render(ren,m); + Superclass::Render(ren,m); } } -/*!Set flag myIsResolveCoincidentTopology to \a theIsResolve. - *\param theIsResolve - bool flag. - */ -void VTKViewer_Actor::SetResolveCoincidentTopology(bool theIsResolve) { + +void +VTKViewer_Actor +::SetResolveCoincidentTopology(bool theIsResolve) +{ myIsResolveCoincidentTopology = theIsResolve; } -/*!Sets polygon offset factor and polygon offset units. - *\param factor - float factor - *\param units - float units - */ -void VTKViewer_Actor::SetPolygonOffsetParameters(float factor, float units){ +void +VTKViewer_Actor +::SetPolygonOffsetParameters(float factor, float units) +{ myPolygonOffsetFactor = factor; myPolygonOffsetUnits = units; } -/*!Gets polygon offset factor and polygon offset units. - *\param factor - output float - *\param units - output float - */ -void VTKViewer_Actor::GetPolygonOffsetParameters(float& factor, float& units){ +void +VTKViewer_Actor +::GetPolygonOffsetParameters(float& factor, float& units) +{ factor = myPolygonOffsetFactor; units = myPolygonOffsetUnits; } -/*!Get input data set. - *\retval vtkDataSet pointer. - */ -vtkDataSet* VTKViewer_Actor::GetInput(){ +//---------------------------------------------------------------------------- +float +VTKViewer_Actor +::GetShrinkFactor() +{ + return 1.0; +} + +bool +VTKViewer_Actor +::IsShrunkable() +{ + return false; +} + +bool +VTKViewer_Actor +::IsShrunk() +{ + return false; +} + +void +VTKViewer_Actor +::SetShrink() +{} + +void +VTKViewer_Actor +::UnShrink() +{} + + +//---------------------------------------------------------------------------- +vtkDataSet* +VTKViewer_Actor +::GetInput() +{ return myPassFilter.front()->GetOutput(); } -/*!Get modification time. - *\retval time - unsigned long. - */ -unsigned long int VTKViewer_Actor::GetMTime(){ + +unsigned long int +VTKViewer_Actor +::GetMTime() +{ unsigned long mTime = this->Superclass::GetMTime(); unsigned long time = myTransformFilter->GetMTime(); mTime = ( time > mTime ? time : mTime ); @@ -225,10 +296,12 @@ unsigned long int VTKViewer_Actor::GetMTime(){ return mTime; } -/*!Set representation mode. - *\param theMode - int. - */ -void VTKViewer_Actor::SetRepresentation(int theMode) { + +//---------------------------------------------------------------------------- +void +VTKViewer_Actor +::SetRepresentation(int theMode) +{ switch(myRepresentation){ case VTK_POINTS : case VTK_SURFACE : @@ -240,7 +313,6 @@ void VTKViewer_Actor::SetRepresentation(int theMode) { GetProperty()->DeepCopy(myProperty); break; default: - break; GetProperty()->SetAmbient(1.0); GetProperty()->SetDiffuse(0.0); GetProperty()->SetSpecular(0.0); @@ -248,93 +320,175 @@ void VTKViewer_Actor::SetRepresentation(int theMode) { switch(theMode){ case 3 : myGeomFilter->SetInside(true); - GetProperty()->SetRepresentation(1); + myGeomFilter->SetWireframeMode(true); + GetProperty()->SetRepresentation(VTK_WIREFRAME); break; case VTK_POINTS : GetProperty()->SetPointSize(VTKViewer_POINT_SIZE); - default : GetProperty()->SetRepresentation(theMode); + myGeomFilter->SetWireframeMode(false); + myGeomFilter->SetInside(false); + break; + case VTK_WIREFRAME : + GetProperty()->SetRepresentation(theMode); + myGeomFilter->SetWireframeMode(true); myGeomFilter->SetInside(false); + break; + case VTK_SURFACE : + GetProperty()->SetRepresentation(theMode); + myGeomFilter->SetWireframeMode(false); + myGeomFilter->SetInside(false); + break; } myRepresentation = theMode; } -/*!Get representation. - *\retval representation mode. - */ -int VTKViewer_Actor::GetRepresentation(){ +int +VTKViewer_Actor +::GetRepresentation() +{ return myRepresentation; } -/*!Get VTK cell by object ID. - *\param theObjID - object ID. - *\retval vtkCell pointer. - */ -vtkCell* VTKViewer_Actor::GetElemCell(int theObjID){ - return GetInput()->GetCell(theObjID); + +//---------------------------------------------------------------------------- +int +VTKViewer_Actor +::GetNodeObjId(int theVtkID) +{ + return theVtkID; } -/*!Get node coordinates by node ID. - *\param theObjID - node ID. - *\retval float array of coordinates. - * \li array[0] - X coordinate. - * \li array[1] - Y coordinate. - * \li array[2] - Z coordinate. - */ -float* VTKViewer_Actor::GetNodeCoord(int theObjID){ +float* +VTKViewer_Actor +::GetNodeCoord(int theObjID) +{ return GetInput()->GetPoint(theObjID); } +vtkCell* +VTKViewer_Actor +::GetElemCell(int theObjID) +{ + return GetInput()->GetCell(theObjID); +} + +int +VTKViewer_Actor +::GetElemObjId(int theVtkID) +{ + return theVtkID; +} + //================================================================================= // function : GetObjDimension -/*! purpose : Return object dimension.\n - * Virtual method shoulb be redifined by derived classes - *\param theObjId - object ID. - */ +// purpose : Return object dimension. +// Virtual method shoulb be redifined by derived classes //================================================================================= -int VTKViewer_Actor::GetObjDimension( const int theObjId ) +int +VTKViewer_Actor +::GetObjDimension( const int theObjId ) { if ( vtkCell* aCell = GetElemCell(theObjId) ) return aCell->GetCellDimension(); return 0; } -/*!Get infinite flag*/ -bool VTKViewer_Actor::IsInfinitive(){ + +void +VTKViewer_Actor +::SetInfinitive(bool theIsInfinite) +{ + myIsInfinite = theIsInfinite; +} + + +bool +VTKViewer_Actor +::IsInfinitive() +{ return myIsInfinite; } -/*!Set property - opacity. - *\param theOpacity - new apacity - */ -void VTKViewer_Actor::SetOpacity(float theOpacity){ + +float* +VTKViewer_Actor +::GetBounds() +{ + return Superclass::GetBounds(); +} + + +void +VTKViewer_Actor +::GetBounds(float theBounds[6]) +{ + Superclass::GetBounds(theBounds); +} + + +//---------------------------------------------------------------------------- +bool +VTKViewer_Actor +::IsSetCamera() const +{ + return false; +} + +bool +VTKViewer_Actor +::IsResizable() const +{ + return false; +} + +void +VTKViewer_Actor +::SetSize( const float ) +{} + + +void +VTKViewer_Actor +::SetCamera( vtkCamera* ) +{} + +//---------------------------------------------------------------------------- +void +VTKViewer_Actor +::SetOpacity(float theOpacity) +{ myOpacity = theOpacity; GetProperty()->SetOpacity(theOpacity); } -/*!Get property - opacity. - *\retval float value. - */ -float VTKViewer_Actor::GetOpacity(){ +float +VTKViewer_Actor +::GetOpacity() +{ return myOpacity; } -/*!Set property - color - *\param r - float Red value - *\param g - float Green value - *\param b - float Blue value - */ -void VTKViewer_Actor::SetColor(float r,float g,float b){ + +void +VTKViewer_Actor +::SetColor(float r,float g,float b) +{ GetProperty()->SetColor(r,g,b); } -/*!Get property - color - *\param r - output float Red value - *\param g - output float Green value - *\param b - output float Blue value - */ -void VTKViewer_Actor::GetColor(float& r,float& g,float& b){ +void +VTKViewer_Actor +::SetColor(const float theRGB[3]) +{ + SetColor(theRGB[0],theRGB[1],theRGB[2]); +} + +void +VTKViewer_Actor +::GetColor(float& r,float& g,float& b) +{ float aColor[3]; GetProperty()->GetColor(aColor); r = aColor[0]; @@ -342,18 +496,53 @@ void VTKViewer_Actor::GetColor(float& r,float& g,float& b){ b = aColor[2]; } -/*!Get display mode. - *\retval int value - */ -int VTKViewer_Actor::getDisplayMode(){ + +//---------------------------------------------------------------------------- +int +VTKViewer_Actor +::getDisplayMode() +{ return myDisplayMode; } -/*!Set display mode - *\param theMode - integer value. - */ -void VTKViewer_Actor::setDisplayMode(int theMode){ - SetRepresentation(theMode+1); +void +VTKViewer_Actor +::setDisplayMode(int theMode) +{ + SetRepresentation(theMode + 1); myDisplayMode = GetRepresentation() - 1; } + +//---------------------------------------------------------------------------- +bool +VTKViewer_Actor +::hasHighlight() +{ + return false; +} + +bool +VTKViewer_Actor +::isHighlighted() +{ + return myIsHighlighted; +} + +void +VTKViewer_Actor +::SetPreSelected(bool thePreselect) +{ + myIsPreselected = thePreselect; +} + + +//---------------------------------------------------------------- +void +VTKViewer_Actor +::highlight(bool theIsHighlight) +{ + myIsHighlighted = theIsHighlight; +} + +vtkCxxSetObjectMacro(VTKViewer_Actor,PreviewProperty,vtkProperty); diff --git a/src/VTKViewer/VTKViewer_Actor.h b/src/VTKViewer/VTKViewer_Actor.h index 2a4371200..55711a8c0 100755 --- a/src/VTKViewer/VTKViewer_Actor.h +++ b/src/VTKViewer/VTKViewer_Actor.h @@ -1,164 +1,327 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ // +// File : SALOME_Actor.h +// Author : Nicolas REJNERI +// Module : SALOME +// $Header$ + #ifndef VTKVIEVER_ACTOR_H #define VTKVIEVER_ACTOR_H #include "VTKViewer.h" -#include -#include -#include -#include -#include - +#include #include +#include + class vtkCell; +class vtkPointPicker; +class vtkCellPicker; class vtkDataSet; -class vtkPolyData; +class vtkCamera; +class vtkProperty; +class vtkRenderer; class VTKViewer_Transform; class VTKViewer_GeometryFilter; class VTKViewer_TransformFilter; class VTKViewer_PassThroughFilter; -#define VTKViewer_POINT_SIZE 3 +extern int VTKViewer_POINT_SIZE; +extern int VTKViewer_LINE_WIDTH; + /*! \class vtkLODActor * \brief For more information see VTK documentation */ -class VTKVIEWER_EXPORT VTKViewer_Actor : public vtkLODActor +class VTKVIEWER_EXPORT VTKViewer_Actor : public vtkLODActor { -public: - /*!Create new instance of actor.*/ + public: static VTKViewer_Actor* New(); - - vtkTypeMacro( VTKViewer_Actor, vtkLODActor ); - - /*!Get name of the actor*/ - virtual const char* getName() { return myName.c_str(); } - /*!Set name of the actor*/ - virtual void setName(const char* theName){ myName = theName;} - - //! To generate highlight automaticaly - virtual bool hasHighlight() { return false; } - //! Sets highlight. - virtual void highlight(bool theHighlight) { myIsHighlighted = theHighlight; } - //! Check highlight. - virtual bool isHighlighted() { return myIsHighlighted; } - virtual void SetOpacity(float theOpacity); - virtual float GetOpacity(); - - virtual void SetColor(float r,float g,float b); - virtual void GetColor(float& r,float& g,float& b); - void SetColor(const float theRGB[3]){ SetColor(theRGB[0],theRGB[1],theRGB[2]); } - - vtkSetObjectMacro(PreviewProperty,vtkProperty); - - virtual void SetPreSelected(bool thePreselect = false) { myIsPreselected = thePreselect;} - - //! Used to obtain all dependent actors - virtual void GetChildActors(vtkActorCollection*) {}; - - virtual void AddToRender(vtkRenderer* theRenderer); - virtual void RemoveFromRender(vtkRenderer* theRenderer); - - - /** @name For selection mapping purpose */ - //@{ - virtual int GetNodeObjId(int theVtkID) { return theVtkID;} - virtual float* GetNodeCoord(int theObjID); - - virtual int GetElemObjId(int theVtkID) { return theVtkID;} - virtual vtkCell* GetElemCell(int theObjID); - //@} - - virtual int GetObjDimension( const int theObjId ); - - virtual void SetMapper(vtkMapper* theMapper); - virtual vtkDataSet* GetInput(); - - virtual void SetTransform(VTKViewer_Transform* theTransform); - virtual unsigned long int GetMTime(); - - virtual void SetRepresentation(int theMode); - virtual int GetRepresentation(); - - virtual int getDisplayMode(); - virtual void setDisplayMode(int theMode); - - /*! Infinitive means actor without size (point for example), \n - * which is not taken into account in calculation of boundaries of the scene - */ - void SetInfinitive(bool theIsInfinite) { myIsInfinite = theIsInfinite; } - virtual bool IsInfinitive(); + vtkTypeMacro(VTKViewer_Actor,vtkLODActor); + + //---------------------------------------------------------------------------- + //! Get its name + virtual + const char* + getName(); + + //! Name the #VTKViewer_Actor + virtual + void + setName(const char* theName); + + //---------------------------------------------------------------------------- + //! Change opacity + virtual + void + SetOpacity(float theOpacity); + + //! Get current opacity + virtual + float + GetOpacity(); + + //! Change color + virtual + void + SetColor(float r,float g,float b); + + //! Get current color + virtual + void + GetColor(float& r,float& g,float& b); + + //! Change color + virtual + void + SetColor(const float theRGB[3]); + + //---------------------------------------------------------------------------- + // For selection mapping purpose + //! Maps VTK index of a node to corresponding object index + virtual + int + GetNodeObjId(int theVtkID); + + //! Get coordinates of a node for given object index + virtual + float* + GetNodeCoord(int theObjID); + + //! Maps VTK index of a cell to corresponding object index + virtual + int + GetElemObjId(int theVtkID); + + //! Get corresponding #vtkCell for given object index + virtual + vtkCell* + GetElemCell(int theObjID); + + //---------------------------------------------------------------------------- + //! Get dimension of corresponding mesh element + virtual + int + GetObjDimension( const int theObjId ); + + //! To insert some additional filters and then sets the given #vtkMapper + virtual + void + SetMapper(vtkMapper* theMapper); + + //! Allows to get initial #vtkDataSet + virtual + vtkDataSet* + GetInput(); + + //! Apply view transformation + virtual + void + SetTransform(VTKViewer_Transform* theTransform); + + //! To calculatate last modified time + virtual + unsigned long int + GetMTime(); + + //---------------------------------------------------------------------------- + //! Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on) + virtual + void + SetRepresentation(int theMode); + + //! Get current representation mode + virtual + int + GetRepresentation(); + + //! Get current display mode (obsolete) + virtual + int + getDisplayMode(); + + //! Set display mode (obsolete) + virtual + void + setDisplayMode(int theMode); + + //---------------------------------------------------------------------------- + //! Set infinive flag + /*! + Infinitive means actor without size (point for example), + which is not taken into account in calculation of boundaries of the scene + */ + void + SetInfinitive(bool theIsInfinite); + + //! Get infinive flag + virtual + bool + IsInfinitive(); - void SetResolveCoincidentTopology(bool theIsResolve); - void SetPolygonOffsetParameters(float factor, float units); - void GetPolygonOffsetParameters(float& factor, float& units); - - virtual void Render(vtkRenderer *, vtkMapper *); + //! To calcualte current bounding box + virtual + float* + GetBounds(); + + //! To calcualte current bounding box + void + GetBounds(float bounds[6]); + + //---------------------------------------------------------------------------- + virtual + bool + IsSetCamera() const; + + virtual + bool + IsResizable() const; + + virtual + void + SetSize( const float ); + + virtual + void + SetCamera( vtkCamera* ); + + //---------------------------------------------------------------------------- + //! Set ResolveCoincidentTopology flag + void + SetResolveCoincidentTopology(bool theIsResolve); + + //! Set ResolveCoincidentTopology parameters + void + SetPolygonOffsetParameters(float factor, float units); + + //! Get current ResolveCoincidentTopology parameters + void + GetPolygonOffsetParameters(float& factor, float& units); + + virtual + void + Render(vtkRenderer *, vtkMapper *); + + //---------------------------------------------------------------------------- + //! Get current shrink factor + virtual + float + GetShrinkFactor(); + + //! Is the actor is shrunkable + virtual + bool + IsShrunkable(); + + //! Is the actor is shrunk + virtual + bool + IsShrunk(); + + //! Insert shrink filter into pipeline + virtual + void + SetShrink(); + + //! Remove shrink filter from pipeline + virtual + void + UnShrink(); + + //---------------------------------------------------------------------------- + //! To publish the actor an all its internal devices + virtual + void + AddToRender(vtkRenderer* theRendere); + + //! To remove the actor an all its internal devices + virtual + void + RemoveFromRender(vtkRenderer* theRendere); -protected: - /*!resolve coincedent topology flag*/ + //! Used to obtain all dependent actors + virtual + void + GetChildActors(vtkActorCollection*); + + //---------------------------------------------------------------------------- + //! Ask, if the descendant of the VTKViewer_Actor will implement its own highlight or not + virtual + bool + hasHighlight(); + + //! Ask, if the VTKViewer_Actor is already highlighted + virtual + bool + isHighlighted(); + + //! Set preselection mode + virtual + void + SetPreSelected(bool thePreselect = false); + + //---------------------------------------------------------------------------- + //! Just to update visibility of the highlight devices + virtual + void + highlight(bool theHighlight); + + void + SetPreviewProperty(vtkProperty* theProperty); + + protected: + //---------------------------------------------------------------------------- bool myIsResolveCoincidentTopology; - /*!polygon offset factor*/ float myPolygonOffsetFactor; - /*!polygon offset units*/ float myPolygonOffsetUnits; - /*!Actor name.*/ std::string myName; - /*!preview property*/ - vtkProperty *PreviewProperty; - /*!preselected flag*/ - bool myIsPreselected; - - /*!opacity*/ float myOpacity; - /*!highlighted flag*/ - bool myIsHighlighted; - /*!display mode*/ int myDisplayMode; - /*!infinite flag*/ bool myIsInfinite; - /*!store mapping flag*/ bool myStoreMapping; - /*!geometry filter*/ VTKViewer_GeometryFilter *myGeomFilter; - /*!transform filter*/ VTKViewer_TransformFilter *myTransformFilter; - /*!vector of passive filters(siz filters used)*/ std::vector myPassFilter; - /*!presentation mode*/ int myRepresentation; - /*!property*/ vtkProperty *myProperty; - //! Main method, which calculate output. - void InitPipeLine(vtkMapper* theMapper); + void + InitPipeLine(vtkMapper* theMapper); VTKViewer_Actor(); ~VTKViewer_Actor(); + + protected: + vtkProperty *PreviewProperty; + bool myIsPreselected; + bool myIsHighlighted; }; -#endif +#endif // VTKVIEVER_ACTOR_H diff --git a/src/VTKViewer/VTKViewer_GeometryFilter.cxx b/src/VTKViewer/VTKViewer_GeometryFilter.cxx index d1baa5b11..df096cf7a 100755 --- a/src/VTKViewer/VTKViewer_GeometryFilter.cxx +++ b/src/VTKViewer/VTKViewer_GeometryFilter.cxx @@ -27,7 +27,6 @@ // $Header$ #include "VTKViewer_GeometryFilter.h" -#include "VTKViewer_ConvexTool.h" #include #include @@ -46,10 +45,16 @@ #include #include +#include +#include +#include +#include + +#include +#include #include #include -using namespace std; - +#include #if defined __GNUC__ #if __GNUC__ == 2 @@ -57,23 +62,29 @@ using namespace std; #endif #endif +#define USE_ROBUST_TRIANGULATION + //---------------------------------------------------------------------------- vtkCxxRevisionMacro(VTKViewer_GeometryFilter, "$Revision$"); vtkStandardNewMacro(VTKViewer_GeometryFilter); -VTKViewer_GeometryFilter::VTKViewer_GeometryFilter(): +VTKViewer_GeometryFilter +::VTKViewer_GeometryFilter(): myShowInside(0), myStoreMapping(0), myIsWireframeMode(0) {} -VTKViewer_GeometryFilter::~VTKViewer_GeometryFilter() +VTKViewer_GeometryFilter +::~VTKViewer_GeometryFilter() {} //---------------------------------------------------------------------------- -void VTKViewer_GeometryFilter::Execute() +void +VTKViewer_GeometryFilter +::Execute() { vtkDataSet *input= this->GetInput(); vtkIdType numCells=input->GetNumberOfCells(); @@ -92,11 +103,19 @@ void VTKViewer_GeometryFilter::Execute() //---------------------------------------------------------------------------- -void VTKViewer_GeometryFilter::UnstructuredGridExecute() +void +VTKViewer_GeometryFilter +::UnstructuredGridExecute() { vtkUnstructuredGrid *input= (vtkUnstructuredGrid *)this->GetInput(); vtkCellArray *Connectivity = input->GetCells(); - if (Connectivity == NULL) {return;} + // Check input + if ( Connectivity == NULL ) + { + vtkDebugMacro(<<"Nothing to extract"); + return; + } + vtkIdType cellId; int i; int allVisible; @@ -109,8 +128,24 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() vtkPolyData *output = this->GetOutput(); vtkPointData *outputPD = output->GetPointData(); +#ifdef USE_ROBUST_TRIANGULATION + vtkUnstructuredGrid* anUnstructuredGrid = vtkUnstructuredGrid::New(); + vtkPoints* aDelaunayPoints = vtkPoints::New(); + + vtkDelaunay3D* aDelaunay3D = vtkDelaunay3D::New(); + aDelaunay3D->SetInput(anUnstructuredGrid); + + vtkGeometryFilter* aGeometryFilter = vtkGeometryFilter::New(); + aGeometryFilter->SetInput(aDelaunay3D->GetOutput()); +#endif + vtkCellData *outputCD = output->GetCellData(); - vtkIdList *cellIds, *faceIds; + vtkGenericCell *cell = vtkGenericCell::New(); + + + vtkIdList *cellIds = vtkIdList::New(); + vtkIdList *faceIds = vtkIdList::New(); + char *cellVis; vtkIdType newCellId; int faceId, *faceVerts, numFacePts; @@ -142,16 +177,7 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() cellGhostLevels = ((vtkUnsignedCharArray*)temp)->GetPointer(0); } - // Check input - if ( Connectivity == NULL ) - { - vtkDebugMacro(<<"Nothing to extract"); - return; - } - // Determine nature of what we have to do - cellIds = vtkIdList::New(); - faceIds = vtkIdList::New(); if ( (!this->CellClipping) && (!this->PointClipping) && (!this->ExtentClipping) ) { @@ -279,36 +305,300 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() outputCD->CopyData(cd,cellId,newCellId); break; - case VTK_CONVEX_POINT_SET:{ - TCellArray tmpCellArray; - try{ - CONVEX_TOOL::GetPolygonalFaces(input,cellId,tmpCellArray); // "VTKViewer_ConvexTool.cxx" - } catch (const std::exception& theExc){ - cout << __FILE__ << "[" << __LINE__ << "] " << "Exception:" << theExc.what() << endl; - } catch (...) { - cout << __FILE__ << "[" << __LINE__ << "] " << "Exception was occured"<< endl; + case VTK_CONVEX_POINT_SET: { + //cout<<"cellId = "<Initialize(); + anUnstructuredGrid->Allocate(); + anUnstructuredGrid->SetPoints(aDelaunayPoints); + + vtkIdType *aPts; + input->GetCellPoints(cellId,aNumPts,aPts); + { + float aPntCoord[3]; + aDelaunayPoints->SetNumberOfPoints(aNumPts); + vtkPoints *anInputPoints = input->GetPoints(); + for (int aPntId = 0; aPntId < aNumPts; aPntId++) { + anInputPoints->GetPoint(aPts[aPntId],aPntCoord); + aDelaunayPoints->SetPoint(aPntId,aPntCoord); + } } - TCellArray::iterator aFaceIter = tmpCellArray.begin(); - for (; aFaceIter!=tmpCellArray.end(); aFaceIter++){ - TCell cell = aFaceIter->second; - numFacePts = cell.size(); - if(numFacePts>3) - aCellType = VTK_POLYGON; - else if(numFacePts == 3) - aCellType = VTK_TRIANGLE; - else if(numFacePts<3) +#else + input->GetCell(cellId,cell); + aPoints = input->GetPoints(); + aNumPts = cell->GetNumberOfPoints(); +#endif + // To calculate the bary center of the cell + float aCellCenter[3] = {0.0, 0.0, 0.0}; + { + float aPntCoord[3]; + for (int aPntId = 0; aPntId < aNumPts; aPntId++) { +#ifdef USE_ROBUST_TRIANGULATION + aPoints->GetPoint(aPntId,aPntCoord); +#else + aPoints->GetPoint(cell->GetPointId(aPntId),aPntCoord); +#endif + //cout<<"\t\taPntId = "<Update(); + vtkPolyData* aPolyData = aGeometryFilter->GetOutput(); + + float aCellLength = aPolyData->GetLength(); + int aNumFaces = aPolyData->GetNumberOfCells(); +#else + float aCellLength = sqrt(cell->GetLength2()); + int aNumFaces = cell->GetNumberOfFaces(); +#endif + + static float EPS = 1.0E-5; + float aDistEps = aCellLength * EPS; + + // To initialize set of points that belong to the cell + typedef std::set TPointIds; + TPointIds anInitialPointIds; + for(vtkIdType aPntId = 0; aPntId < aNumPts; aPntId++){ +#ifdef USE_ROBUST_TRIANGULATION + anInitialPointIds.insert(aPntId); +#else + anInitialPointIds.insert(cell->GetPointId(aPntId)); +#endif + } + + // To initialize set of points by face that belong to the cell and backward + typedef std::set TFace2Visibility; + TFace2Visibility aFace2Visibility; + + typedef std::set TFace2PointIds; + TFace2PointIds aFace2PointIds; + + for (int aFaceId = 0; aFaceId < aNumFaces; aFaceId++) { +#ifdef USE_ROBUST_TRIANGULATION + vtkCell* aFace = aPolyData->GetCell(aFaceId); +#else + vtkCell* aFace = cell->GetFace(aFaceId); +#endif + vtkIdList *anIdList = aFace->PointIds; + aNewPts[0] = anIdList->GetId(0); + aNewPts[1] = anIdList->GetId(1); + aNewPts[2] = anIdList->GetId(2); + +#ifdef USE_ROBUST_TRIANGULATION + faceIds->Reset(); + faceIds->InsertNextId(aPts[aNewPts[0]]); + faceIds->InsertNextId(aPts[aNewPts[1]]); + faceIds->InsertNextId(aPts[aNewPts[2]]); + input->GetCellNeighbors(cellId, faceIds, cellIds); +#else + input->GetCellNeighbors(cellId, anIdList, cellIds); +#endif + if((!allVisible && !cellVis[cellIds->GetId(0)]) || + cellIds->GetNumberOfIds() <= 0 || + myShowInside) + { + TPointIds aPointIds; + aPointIds.insert(aNewPts[0]); + aPointIds.insert(aNewPts[1]); + aPointIds.insert(aNewPts[2]); + + aFace2PointIds.insert(aPointIds); + aFace2Visibility.insert(aFaceId); + } + } + + for (int aFaceId = 0; aFaceId < aNumFaces; aFaceId++) { + if(aFace2Visibility.find(aFaceId) == aFace2Visibility.end()) continue; + +#ifdef USE_ROBUST_TRIANGULATION + vtkCell* aFace = aPolyData->GetCell(aFaceId); +#else + vtkCell* aFace = cell->GetFace(aFaceId); +#endif + vtkIdList *anIdList = aFace->PointIds; + aNewPts[0] = anIdList->GetId(0); + aNewPts[1] = anIdList->GetId(1); + aNewPts[2] = anIdList->GetId(2); - for ( i=0; i < numFacePts; i++) + // To initialize set of points for the plane where the trinangle face belong to + TPointIds aPointIds; + aPointIds.insert(aNewPts[0]); + aPointIds.insert(aNewPts[1]); + aPointIds.insert(aNewPts[2]); + + // To get know, if the points of the trinagle were already observed + bool anIsObserved = aFace2PointIds.find(aPointIds) == aFace2PointIds.end(); + //cout<<"\taFaceId = "<GetPoint(aNewPts[0],aCoord[0]); + aPoints->GetPoint(aNewPts[1],aCoord[1]); + aPoints->GetPoint(aNewPts[2],aCoord[2]); + + // To calculate plane normal + float aVector01[3] = { aCoord[1][0] - aCoord[0][0], + aCoord[1][1] - aCoord[0][1], + aCoord[1][2] - aCoord[0][2] }; + + float aVector02[3] = { aCoord[2][0] - aCoord[0][0], + aCoord[2][1] - aCoord[0][1], + aCoord[2][2] - aCoord[0][2] }; + + float aCross21[3]; + vtkMath::Cross(aVector02,aVector01,aCross21); + + vtkMath::Normalize(aCross21); + + // To calculate what points belong to the plane + // To calculate bounds of the point set + float aCenter[3] = {0.0, 0.0, 0.0}; { - aNewPts[i] = cell[i]; + TPointIds::const_iterator anIter = anInitialPointIds.begin(); + TPointIds::const_iterator anEndIter = anInitialPointIds.end(); + for(; anIter != anEndIter; anIter++){ + float aPntCoord[3]; + vtkIdType aPntId = *anIter; + aPoints->GetPoint(aPntId,aPntCoord); + float aDist = vtkPlane::DistanceToPlane(aPntCoord,aCross21,aCoord[0]); + //cout<<"\t\taPntId = "< 0){ + aCross21[0] = -aCross21[0]; + aCross21[1] = -aCross21[1]; + aCross21[2] = -aCross21[2]; + } + + vtkMath::Normalize(aVector0); + + //cout<<"\t\taCenter = {"< TSortedPointIds; + TSortedPointIds aSortedPointIds; + + TPointIds::const_iterator anIter = aPointIds.begin(); + TPointIds::const_iterator anEndIter = aPointIds.end(); + for(; anIter != anEndIter; anIter++){ + float aPntCoord[3]; + vtkIdType aPntId = *anIter; + aPoints->GetPoint(aPntId,aPntCoord); + float aVector[3] = { aPntCoord[0] - aCenter[0], + aPntCoord[1] - aCenter[1], + aPntCoord[2] - aCenter[2] }; + vtkMath::Normalize(aVector); + + float aCross[3]; + vtkMath::Cross(aVector,aVector0,aCross); + bool aGreaterThanPi = vtkMath::Dot(aCross,aCross21) < 0; + float aCosinus = vtkMath::Dot(aVector,aVector0); + if(aCosinus > 1.0) + aCosinus = 1.0; + if(aCosinus < -1.0) + aCosinus = -1.0; + static float a2Pi = 2.0 * vtkMath::Pi(); + float anAngle = acos(aCosinus); + //cout<<"\t\taPntId = "< aConnectivities(numFacePts); + TSortedPointIds::const_iterator anIter = aSortedPointIds.begin(); + TSortedPointIds::const_iterator anEndIter = aSortedPointIds.end(); + for(vtkIdType anId = 0; anIter != anEndIter; anIter++, anId++){ + vtkIdType aPntId = anIter->second; +#ifdef USE_ROBUST_TRIANGULATION + aConnectivities[anId] = aPts[aPntId]; +#else + aConnectivities[anId] = aPntId; +#endif + } + newCellId = output->InsertNextCell(aCellType,numFacePts,&aConnectivities[0]); + if(myStoreMapping) + myVTK2ObjIds.push_back(cellId); + outputCD->CopyData(cd,cellId,newCellId); + } } - newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); - if(myStoreMapping){ - myVTK2ObjIds.push_back(cellId); } - outputCD->CopyData(cd,cellId,newCellId); } + break; } case VTK_TETRA: { @@ -452,7 +742,6 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() 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(); @@ -510,7 +799,6 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() cellIds->Delete(); coords->Delete(); pts->Delete(); - cell->Delete(); break; }else{ switch(aCellType){ @@ -741,8 +1029,19 @@ void VTKViewer_GeometryFilter::UnstructuredGridExecute() vtkDebugMacro(<<"Extracted " << input->GetNumberOfPoints() << " points," << output->GetNumberOfCells() << " cells."); +#ifdef USE_ROBUST_TRIANGULATION + anUnstructuredGrid->Delete(); + aDelaunayPoints->Delete(); + + aDelaunay3D->Delete(); + aGeometryFilter->Delete(); +#endif + + cell->Delete(); + cellIds->Delete(); faceIds->Delete(); + if ( cellVis ) { delete [] cellVis; diff --git a/src/VTKViewer/VTKViewer_InteractorStyle.cxx b/src/VTKViewer/VTKViewer_InteractorStyle.cxx index fa407641d..1f69e6085 100644 --- a/src/VTKViewer/VTKViewer_InteractorStyle.cxx +++ b/src/VTKViewer/VTKViewer_InteractorStyle.cxx @@ -50,6 +50,7 @@ #include #include #include +#include #include //VRV: porting on Qt 3.0.5 diff --git a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx index db601ab4a..daf93e15c 100755 --- a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx +++ b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx @@ -51,6 +51,7 @@ #include #include #include +#include // QT Includes #include -- 2.39.2