X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHEXABLOCKGUI%2FHEXABLOCKGUI_VtkDocumentGraphicView.cxx;h=0c4d3bdc4b49201139eb705d8f2946d56baa03b2;hb=3ebce928a3a516c4bea70eaa793eec41d7273089;hp=5f0d860ea85bf8859fda5a01edb9c22c28c0db13;hpb=f518b3d7ebd90c8a2b7166a229e735ebc08f762e;p=modules%2Fhexablock.git diff --git a/src/HEXABLOCKGUI/HEXABLOCKGUI_VtkDocumentGraphicView.cxx b/src/HEXABLOCKGUI/HEXABLOCKGUI_VtkDocumentGraphicView.cxx index 5f0d860..0c4d3bd 100755 --- a/src/HEXABLOCKGUI/HEXABLOCKGUI_VtkDocumentGraphicView.cxx +++ b/src/HEXABLOCKGUI/HEXABLOCKGUI_VtkDocumentGraphicView.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2009-2012 CEA/DEN, EDF R&D +// Copyright (C) 2009-2013 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -19,83 +19,23 @@ //#define _DEVDEBUG_ -#include - -#include - -#include - -#include "utilities.h" - -#include - - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - // VTK includes #include -#include -#include -#include -#include -#include -// test tutorial (sphere) -#include -#include - -// test point (cf. SMESHGUI) -#include -#include -#include #include #include -#include -#include - -#include -#include -#include - -#include "vtkLookupTable.h" -#include "vtkPoints.h" #include "vtkCellArray.h" -#include "vtkFloatArray.h" #include "vtkPolyData.h" -#include "vtkPolyDataMapper.h" -#include "vtkActor.h" -#include "vtkPointData.h" -#include "vtkProperty.h" - - -// #include "vtkStructuredGridReader.h" -#include "vtkUnstructuredGridReader.h" #include - - - - - -#ifndef M_PI -#define M_PI 3.1415927 -#endif +#include #include "HEXABLOCKGUI_Trace.hxx" -#include "HEXABLOCKGUI_DocumentModel.hxx" #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx" #include "HEXABLOCKGUI.hxx" - +#ifndef M_PI +#define M_PI 3.1415927 +#endif using namespace std; using namespace HEXABLOCK::GUI; @@ -106,12 +46,13 @@ Document_Actor::Document_Actor( Document* doc, const QString& entry ): _doc( doc ) { DEBTRACE("Document_Actor::Document_Actor " << entry.toLatin1() ); - Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK" );//,theName); CS_TODO + const char* docName = ((doc != NULL) ? doc->getName() : ""); + Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK", docName );//,theName); CS_TODO setIO(anIO); vtkUnstructuredGrid* aGrid = getUnstructuredGrid(); - // std::cout << "Document_Actor aGrid->GetNumberOfCells() =>"<< aGrid->GetNumberOfCells(); vtkDataSetMapper* aMapper = vtkDataSetMapper::New(); - aMapper->SetInputData(aGrid); + aMapper->SetInputData(aGrid); // saclay +// aMapper->SetInput(aGrid); aGrid->Delete(); SetVisibility( true );//VisibilityOff(); @@ -121,15 +62,14 @@ Document_Actor::Document_Actor( Document* doc, const QString& entry ): vtkProperty* aProp = vtkProperty::New(); - // aProp->SetRepresentationToSurface(); +// aProp->SetRepresentationToSurface(); aProp->SetRepresentationToWireframe(); - // aProp->SetRepresentationToPoints(); +// aProp->SetRepresentationToPoints(); aProp->EdgeVisibilityOn (); aProp->SetPointSize(5); SetProperty( aProp ); aProp->Delete(); - // SetPointRepresentation(true); - +// SetPointRepresentation(true); } Document_Actor::~Document_Actor() @@ -301,12 +241,14 @@ Associate_Actor::Associate_Actor( Document* doc, const QString& entry) : SALOME_Actor(), _doc( doc ) { DEBTRACE("Associate_Actor::Associate_Actor " << entry.toLatin1() ); - Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK" );//,theName); CS_TODO + const char* docName = ((doc != NULL) ? doc->getName() : ""); + Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK", docName );//,theName); CS_TODO setIO(anIO); vtkUnstructuredGrid* aGrid = getUnstructuredGrid(); vtkDataSetMapper* aMapper = vtkDataSetMapper::New(); - aMapper->SetInputData(aGrid); + aMapper->SetInputData(aGrid); // saclay +// aMapper->SetInput (aGrid); aGrid->Delete(); SetVisibility( true );//VisibilityOff(); @@ -316,14 +258,14 @@ Associate_Actor::Associate_Actor( Document* doc, const QString& entry) vtkProperty* aProp = vtkProperty::New(); aProp->SetColor(0,255,0); - // aProp->SetRepresentationToSurface(); +// aProp->SetRepresentationToSurface(); aProp->SetRepresentationToWireframe(); - // aProp->SetRepresentationToPoints(); +// aProp->SetRepresentationToPoints(); aProp->EdgeVisibilityOn (); aProp->SetPointSize(5); SetProperty( aProp ); aProp->Delete(); - // SetPointRepresentation(true); +// SetPointRepresentation(true); } // ===================================================== getUnstructuredGrid @@ -357,7 +299,6 @@ vtkUnstructuredGrid* Associate_Actor::getUnstructuredGrid() aPoints->Delete(); // theGrid->SetCells( 0, 0, 0, 0, 0 ); - // Calculate cells size int nb0DElement = _doc->countVertex(); int nbEdge = _doc->countEdge(); @@ -501,22 +442,21 @@ VtkDocumentGraphicView::VtkDocumentGraphicView( DocumentModel* documentModel, //Model setModel(documentModel); patternDataModel = new PatternDataModel(parent); - patternBuilderModel = new PatternBuilderModel(parent); patternGeomModel = new PatternGeomModel(parent); groupsModel = new GroupsModel(parent); meshModel = new MeshModel(parent); + patternDataModel->setSourceModel(documentModel); - patternBuilderModel->setSourceModel(documentModel); patternGeomModel->setSourceModel(documentModel); groupsModel->setSourceModel(documentModel); meshModel->setSourceModel(documentModel); //Selection Model patternDataSelectionModel = new PatternDataSelectionModel(patternDataModel); - patternBuilderSelectionModel = new PatternBuilderSelectionModel(patternBuilderModel, patternDataSelectionModel); patternGeomSelectionModel = new PatternGeomSelectionModel(patternGeomModel); groupsSelectionModel = new GroupsSelectionModel(groupsModel); meshSelectionModel = new MeshSelectionModel(meshModel ); + setSelectionModel(patternDataSelectionModel); } @@ -549,13 +489,11 @@ VtkDocumentGraphicView::~VtkDocumentGraphicView() //Delete Model delete patternDataModel; - delete patternBuilderModel; delete groupsModel; delete meshModel; //Delete Selection Model/ Disconnect signals on delete (Qt) // delete patternDataSelectionModel; -// delete patternBuilderSelectionModel; // delete groupsSelectionModel; // delete meshSelectionModel; } @@ -580,12 +518,11 @@ void VtkDocumentGraphicView::removeActor() void VtkDocumentGraphicView::update() { - DocumentModel* theModel = dynamic_cast( model() ); if (theModel == NULL || viewWindow == NULL) return; Document* theDocumentImpl = theModel->documentImpl(); - QString theDocumentEntry = theModel->documentEntry(); + QString theDocumentEntry = theModel->documentEntry(); if ( documentActor ){ viewWindow->RemoveActor( documentActor ); @@ -606,26 +543,16 @@ void VtkDocumentGraphicView::update() void VtkDocumentGraphicView::setVertexSelection() { setSelectionMode(NodeSelection); -// // NodeSelection, -// // CellSelection, -// // EdgeOfCellSelection, -// // EdgeSelection, -// // FaceSelection, -// // VolumeSelection, -// // ActorSelection }; - selectionMode = VERTEX_TREE; } void VtkDocumentGraphicView::setEdgeSelection() { setSelectionMode(EdgeSelection); - selectionMode = EDGE_TREE; } void VtkDocumentGraphicView::setQuadSelection() { setSelectionMode(FaceSelection); - selectionMode = QUAD_TREE; } void VtkDocumentGraphicView::setHexaSelection() @@ -644,13 +571,12 @@ void VtkDocumentGraphicView::setAllSelection() void VtkDocumentGraphicView::setSelectionMode(Selection_Mode theMode) { + if (viewWindow == NULL || selectionMode == theMode) + return; - if ( viewWindow != NULL ) - { - viewWindow->SetSelectionMode( theMode ); - selectionMode = theMode; - } - + HEXABLOCKGUI::selectionMgr()->clearSelected(); + viewWindow->SetSelectionMode( theMode ); + selectionMode = theMode; } void VtkDocumentGraphicView::setSelectionMode( const QModelIndex& eltIndex ) @@ -681,13 +607,14 @@ void VtkDocumentGraphicView::setSelectionMode( const QModelIndex& eltIndex ) case PROPAGATION_TREE : case PROPAGATION_DIR_TREE : setEdgeSelection(); break; default: setAllSelection(); -// CellSelection, -// EdgeOfCellSelection, -// VolumeSelection, -// ActorSelection } } +void VtkDocumentGraphicView::getSelected(SALOME_ListIO& selectedObjects) +{ + HEXABLOCKGUI::selectionMgr()->selectedObjects( selectedObjects, SVTK_Viewer::Type()); +} + void VtkDocumentGraphicView::clearSelection() { if (viewWindow != NULL) @@ -709,14 +636,16 @@ void VtkDocumentGraphicView::highlight( const QModelIndex& ielt ) void VtkDocumentGraphicView::highlight( const QModelIndexList& elts ) { - if (elts.size() == 0 || viewWindow == NULL || documentActor == NULL) return; + if (elts.size() == 0 || viewWindow == NULL || documentActor == NULL) + return; SVTK_Selector* selector = viewWindow->GetSelector(); - if ( selector == NULL ) return; -// // Set selection mode in VTK view + if ( selector == NULL ) + return; + // Set selection mode in VTK view // viewWindow->SetSelectionMode(VolumeSelection); // --- elements highlight --- - TColStd_MapOfInteger aMap; + TColStd_IndexedMapOfInteger aMap; int vtkElemsId; QString eltEntry; @@ -725,13 +654,12 @@ void VtkDocumentGraphicView::highlight( const QModelIndexList& elts ) { eltEntry = iElt.data( HEXA_ENTRY_ROLE ).toString(); vtkElemsId = documentActor->vtkElemsId[ eltEntry.toInt() ]; - if ( vtkElemsId > 0 ) aMap.Add( vtkElemsId ); + if ( vtkElemsId > 0 ) + aMap.Add( vtkElemsId ); } } - selector->AddOrRemoveIndex( documentActor->getIO(), aMap, false ); //true + selector->AddOrRemoveIndex( documentActor->getIO(), aMap, false ); viewWindow->highlight( documentActor->getIO(), true, true ); - documentActor->highlight( false ); //unhighlight de la bounding box rouge - } @@ -743,12 +671,10 @@ void VtkDocumentGraphicView::highlightGroups( const QModelIndex& eltIndex ) QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE ); if ( !treeVariant.isValid()) - //INFOS("data from model not valid"); return; int eltType = treeVariant.toInt(); if ( eltType != GROUP_TREE ) - //INFOS("bad element type : not a group item" << eltType ); return; //Get elements to highlight @@ -794,12 +720,10 @@ void VtkDocumentGraphicView::highlightPropagation( const QModelIndex& eltIndex ) QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE ); if ( !treeVariant.isValid()) - //INFOS("data from model not valid"); return; int eltType = treeVariant.toInt(); if ( eltType != PROPAGATION_TREE ) - //INFOS("bad element type : not a group item" << eltType ); return; // Get elements to highlight @@ -836,11 +760,9 @@ void VtkDocumentGraphicView::highlightPropagation( const QModelIndex& eltIndex ) /******************************************************************************** * ABSTRACT METHOD ( MUST BE IMPLEMENTED ) ********************************************************************************/ - /* Returns the item that covers the coordinate given in the view. */ - QModelIndex VtkDocumentGraphicView::indexAt(const QPoint &point) const { return QModelIndex(); @@ -850,7 +772,6 @@ void VtkDocumentGraphicView::scrollTo(const QModelIndex &index, ScrollHint) { } - /* Returns the position of the item in viewport coordinates. */ @@ -899,8 +820,6 @@ QRegion VtkDocumentGraphicView::visualRegionForSelection(const QItemSelection &s } - - /******************************************************************************** * PROTECTED SLOTS ********************************************************************************/ @@ -914,7 +833,6 @@ void VtkDocumentGraphicView::commitData ( QWidget * editor ) void VtkDocumentGraphicView::currentChanged( const QModelIndex & current, const QModelIndex & previous ) { - // openPersistentEditor( current ); _currentChanged = true; } @@ -922,7 +840,6 @@ void VtkDocumentGraphicView::dataChanged ( const QModelIndex & topLeft, const QM { update(); _currentChanged = false; - // updateObject(topLeft); } void VtkDocumentGraphicView::editorDestroyed ( QObject * editor ) @@ -945,261 +862,19 @@ void VtkDocumentGraphicView::updateGeometries () { } -// bool DocumentGraphicView::canBeDisplayed( const QString& entry, const QString& viewer_type ) const //CS_TODO -// { -// bool result = false; -// -// result = (viewer_type==SVTK_Viewer::Type()); -// // QStringList es = entry.split( "_" );22 -// // bool result = ( es.count() == 3 && es[ 0 ] == "ATOMSOLVGUI" && viewer_type == SVTK_Viewer::Type() ); -// // // printf ( " canBeDisplayed : entry = %s, count = %d, res = %d \n", entry.latin1(), es.count(), result ); -// std::cout << "canBeDisplayed => "<< result << std::endl; -// return result; // entry of an atom for sure -// } - -// SALOME_Prs* HEXABLOCKGUI_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame) -// { -// SALOME_Prs* prs = 0; -// -// SALOME_View* aViewFrame = theViewFrame ? theViewFrame : GetActiveView(); -// -// if ( aViewFrame ) -// { -// SVTK_Viewer* vtk_viewer = dynamic_cast( aViewFrame ); -// if (vtk_viewer) -// { -// SUIT_ViewWindow* wnd = vtk_viewer->getViewManager()->getActiveView(); -// SALOME_Actor* anActor = myGraphicView->FindActorByEntry( wnd, entry.toLatin1().data() ); -// if (!anActor) -// { -// // anActor = myGraphicView->CreateActor( study()->studyDS(), entry.toLatin1().data(), true ); -// anActor = myGraphicView->CreateActor(entry.toLatin1().data()); -// } -// if (anActor) -// { -// // Display actor : -// SVTK_ViewWindow* vtkWnd = dynamic_cast (wnd); -// if (vtkWnd != NULL) -// { -// vtkWnd->AddActor(anActor); -// vtkWnd->Repaint(); -// prs = LightApp_Displayer::buildPresentation(entry.toLatin1().data(), aViewFrame); -// } -// } -// if (prs) -// { -// UpdatePrs(prs); -// } -// else if (anActor) -// { -// //SMESH::RemoveActor( vtk_viewer->getViewManager()->getActiveView(), anActor ); -// std::cout << "Remove Actor" << std::endl; -// } -// } -// } -// -// return prs; -// } - -// SALOME_Prs* SMESHGUI_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame ) -// { -// SALOME_Prs* prs = 0; -// -// SALOME_View* aViewFrame = theViewFrame ? theViewFrame : GetActiveView(); -// -// if ( aViewFrame ) -// { -// SVTK_Viewer* vtk_viewer = dynamic_cast( aViewFrame ); -// if( vtk_viewer ) -// { -// SUIT_ViewWindow* wnd = vtk_viewer->getViewManager()->getActiveView(); -// SMESH_Actor* anActor = SMESH::FindActorByEntry( wnd, entry.toLatin1().data() ); -// if( !anActor ) -// anActor = SMESH::CreateActor( study()->studyDS(), entry.toLatin1().data(), true ); -// if( anActor ) -// { -// SMESH::DisplayActor( wnd, anActor ); -// prs = LightApp_Displayer::buildPresentation( entry.toLatin1().data(), aViewFrame ); -// } -// if( prs ) -// UpdatePrs( prs ); -// else if( anActor ) -// SMESH::RemoveActor( vtk_viewer->getViewManager()->getActiveView(), anActor ); -// } -// } -// -// return prs; -// } - -// -// void DocumentGraphicView::RemoveActor(SUIT_ViewWindow *theWnd, SALOME_Actor* theActor) -// { -// std::cout << "RemoveActor() : 1" << std::endl; -// SVTK_ViewWindow* myViewWindow = dynamic_cast(theWnd); -// // SVTK_ViewWindow* myViewWindow = dynamic_cast(_suitView); -// if (myViewWindow != NULL) -// { -// myViewWindow->RemoveActor(theActor); -// if(theActor->hasIO()) -// { -// std::cout << "RemoveActor() : 2" << std::endl; -// Handle(SALOME_InteractiveObject) anIO = theActor->getIO(); -// if(anIO->hasEntry()) -// { -// std::cout << "RemoveActor() : 3" << std::endl; -// std::string anEntry = anIO->getEntry(); -// SalomeApp_Study* aStudy = dynamic_cast( myViewWindow->getViewManager()->study() ); -// int aStudyId = aStudy->id(); -// // TVisualObjCont::key_type aKey(aStudyId,anEntry); -// // VISUAL_OBJ_CONT.erase(aKey); -// } -// } -// theActor->Delete(); -// myViewWindow->Repaint(); -// std::cout << "RemoveActor() : 4" << std::endl; -// } -// } - -// bool DocumentGraphicView::eventFilter(QObject *obj, QEvent *event) -// { -// std::cout << event->type() << std::endl; -// // if ( event->type() == QEvent::FocusIn ){ //QEvent::KeyPress) { -// // return false; -// // } else { -// // // standard event processing -// // // return QObject::eventFilter(obj, event); -// -// if ( event->type() == QEvent::Paint ) { //QEvent::FocusIn ){ -// std::cout << "PAINTTTTTTTTTT"<< std::endl; -// // loadVTK( "/tmp/load.vtk"); //CS_TEST -// } -// return _suitView->event(event); -// // } -// } -// -// - -//show the actor when show=true and hide it when show=false -//void VtkDocumentGraphicView::showActor(bool show) -//{ -// SVTK_ViewWindow* theVTKViewWindow = dynamic_cast(_suitView); -// if (theVTKViewWindow == NULL || _documentActor == NULL) -// return; -// -// if (show) -// { -// _documentActor->SetVisibility(1); -// theVTKViewWindow->onFitAll(); -// } -// else -// { -// _documentActor->SetVisibility(0); -// theVTKViewWindow->onResetView (); -// } -//} void VtkDocumentGraphicView::setModel ( QAbstractItemModel * model ) { QAbstractItemView::setModel( model ); - // PatternDataModel* pdm = dynamic_cast(model); - // if (pdm){ - // connect( pdm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) ); - // } +// PatternDataModel* pdm = dynamic_cast(model); +// if (pdm) +// connect( pdm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) ); DocumentModel* dm = dynamic_cast(model); if (dm){ - // setWindowTitle( dm->getName() ); +// setWindowTitle( dm->getName() ); connect( dm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) ); - // connect( dm, SIGNAL( nameChanged(const QString&) ), this, SLOT ( setWindowTitle(const QString&) ) ); +// connect( dm, SIGNAL( nameChanged(const QString&) ), this, SLOT ( setWindowTitle(const QString&) ) ); } } - -// void DocumentGraphicView::loadVTK( const QString& path ) //CS_TEST -// { -// std::cout << "DocumentGraphicView::loadVTK=>"<(_suitView); -// -// // vtkStructuredGridReader -// vtkUnstructuredGridReader* r = vtkUnstructuredGridReader::New(); -// // r->SetFileName( path.toLocal8Bit().constData() ); -// r->SetInputString( vtkData.toLocal8Bit().constData() ); -// r->SetReadFromInputString( true ); -// r->Update(); -// -// vtkUnstructuredGrid* myGrid = r->GetOutput();//vtkUnstructuredGrid::New(); -// std::cout << "GetNumberOfCells =>"<< myGrid->GetNumberOfCells(); -// // Create and display actor -// -// vtkDataSetMapper* myMapper = vtkDataSetMapper::New(); -// myMapper->SetInput(myGrid); -// -// // if ( myPreviewActor ){ -// // myVTKViewWindow->RemoveActor(myPreviewActor); -// // myPreviewActor->Delete(); -// // } -// -// SALOME_Actor* myPreviewActor = SALOME_Actor::New(); -// myPreviewActor = SALOME_Actor::New(); -// Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(QString::number( reinterpret_cast(_hexaDocument) ),"HEXABLOCK");//,theName); -// myPreviewActor->setIO(anIO); -// -// // myPreviewActor->PickableOff(); -// myPreviewActor->SetVisibility( true );//VisibilityOff(); -// myPreviewActor->SetPickable( true ); -// myPreviewActor->SetMapper(myMapper); -// -// vtkProperty* aProp = vtkProperty::New(); -// // aProp->SetRepresentationToWireframe(); -// aProp->SetRepresentationToSurface(); -// aProp->EdgeVisibilityOn (); -// -// // aProp->SetColor(10, 10, 250); -// aProp->SetPointSize(5); -// myPreviewActor->SetProperty(aProp); -// aProp->Delete(); -// -// /*vtkProperty* myBackProp = vtkProperty::New(); -// GetColor( "SMESH", "backface_color", aBackRGB[0], aBackRGB[1], aBackRGB[2], QColor( 0, 0, 255 ) ); -// myBackProp->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] ); -// myPreviewActor->SetBackfaceProperty( myBackProp ); -// myBackProp->Delete()*/; -// myVTKViewWindow->AddActor(myPreviewActor); -// myVTKViewWindow->getRenderer()->Render(); -// myVTKViewWindow->Repaint(); -// myVTKViewWindow->onFitAll(); -// -// myVTKViewWindow->SetSelectionMode( ActorSelection ); -// // myVTKViewWindow->SetSelectionMode( NodeSelection ); -// // myVTKViewWindow->SetSelectionMode( EdgeSelection ); -// // myVTKViewWindow->SetSelectionMode( FaceSelection ); -// } - -// void DocumentGraphicView::rowsInserted ( const QModelIndex & parent, int start, int end ) -// { -// -// // std::cout << "DocumentGraphicView::rowsInserted : " << parent.data().toString().toStdString() << std::endl; -// QModelIndex newRow; -// -// SVTK_ViewWindow* myViewWindow = dynamic_cast(_suitView); -// SUIT_ViewManager* vman = myViewWindow->getViewManager(); -// SUIT_ViewModel* vmodel = vman->getViewModel(); -// -// for ( int i = start; i<= end; ++i ){ -// newRow = parent.child(i,0); -// // std::cout << "newRow.data().toString() =>" << newRow.data().toString().toStdString() << std::endl; -// QString entry = newRow.data(HEXA_ENTRY_ROLE).toString();//.toStdString(); -// Display(entry, true, dynamic_cast(vmodel)); -// UpdateViewer(); -// -// // addObject(newRow); -// } -// }