-// Copyright (C) 2009-2013 CEA/DEN, EDF R&D
+// Copyright (C) 2009-2014 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
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
//#define _DEVDEBUG_
-#include <sstream>
-
-#include <iostream>
-
-#include <math.h>
-
-#include "utilities.h"
-
-#include <QtGui>
-
-
-#include <LightApp_Application.h>
-
-#include <SUIT_ViewManager.h>
-#include <SUIT_ViewWindow.h>
-#include <SVTK_ViewManager.h>
-#include <SVTK_ViewModel.h>
-#include <SVTK_ViewWindow.h>
-#include <SVTK_Prs.h>
-#include <SALOME_Actor.h>
-#include <VTKViewer_Algorithm.h>
-#include <SalomeApp_Study.h>
-
// VTK includes
#include <vtkRenderer.h>
-#include <vtkActorCollection.h>
-#include <vtkUnstructuredGrid.h>
-#include <vtkRenderWindowInteractor.h>
-#include <vtkSmartPointer.h>
-#include <SVTK_View.h>
-// test tutorial (sphere)
-#include <vtkPolyDataMapper.h>
-#include <vtkSphereSource.h>
-
-// test point (cf. SMESHGUI)
-#include <vtkIdList.h>
-#include <vtkCellArray.h>
-#include <vtkUnsignedCharArray.h>
#include <vtkUnstructuredGrid.h>
#include <vtkDataSetMapper.h>
-#include <vtkProperty.h>
-#include <vtkLineSource.h>
-
-#include <vtkLine.h>
-#include <vtkQuad.h>
-#include <vtkHexahedron.h>
-
-#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 <VTKViewer_CellLocationsArray.h>
-
-
-
-
-
-#ifndef M_PI
-#define M_PI 3.1415927
-#endif
+#include <SVTK_ViewModel.h>
#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;
_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();
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()
: 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();
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
aPoints->Delete();
// theGrid->SetCells( 0, 0, 0, 0, 0 );
-
// Calculate cells size
int nb0DElement = _doc->countVertex();
int nbEdge = _doc->countEdge();
//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);
}
//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;
}
void VtkDocumentGraphicView::update()
{
-
DocumentModel* theModel = dynamic_cast<DocumentModel*>( model() );
if (theModel == NULL || viewWindow == NULL) return;
Document* theDocumentImpl = theModel->documentImpl();
- QString theDocumentEntry = theModel->documentEntry();
+ QString theDocumentEntry = theModel->documentEntry();
if ( documentActor ){
viewWindow->RemoveActor( documentActor );
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()
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 )
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)
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;
{
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
-
}
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
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
/********************************************************************************
* 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();
{
}
-
/*
Returns the position of the item in viewport coordinates.
*/
}
-
-
/********************************************************************************
* PROTECTED SLOTS
********************************************************************************/
void VtkDocumentGraphicView::currentChanged( const QModelIndex & current, const QModelIndex & previous )
{
- // openPersistentEditor( current );
_currentChanged = true;
}
{
update();
_currentChanged = false;
- // updateObject(topLeft);
}
void VtkDocumentGraphicView::editorDestroyed ( QObject * editor )
{
}
-// 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<SVTK_Viewer*>( 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<SVTK_ViewWindow*> (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<SVTK_Viewer*>( 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<SVTK_ViewWindow*>(theWnd);
-// // SVTK_ViewWindow* myViewWindow = dynamic_cast<SVTK_ViewWindow*>(_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<SalomeApp_Study*>( 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<SVTK_ViewWindow*>(_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<PatternDataModel*>(model);
- // if (pdm){
- // connect( pdm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) );
- // }
+// PatternDataModel* pdm = dynamic_cast<PatternDataModel*>(model);
+// if (pdm)
+// connect( pdm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) );
DocumentModel* dm = dynamic_cast<DocumentModel*>(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=>"<<std::endl;
-// QFile file(path);
-// if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
-// return;
-// // QByteArray vtkData = file.readAll ();
-// QString vtkData = file.readAll ();
-// vtkData.replace(",",".");
-//
-//
-// SVTK_ViewWindow* myVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>(_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<intptr_t>(_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<SVTK_ViewWindow*>(_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<SALOME_View*>(vmodel));
-// UpdateViewer();
-//
-// // addObject(newRow);
-// }
-// }