-using namespace std;
-// File : VisuGUI_Selection.cxx
-// Created : Wed Aug 01 10:23:06 2001
-// Author : Laurent CORNABE & Hubert ROLLAND
-// Project : SALOME
-// Module : VISUGUI
-// Copyright : PRINCIPIA
+// VISU VISUGUI : GUI of VISU component
+//
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : VisuGUI_Selection.cxx
+// Author : Laurent CORNABE & Hubert ROLLAND
+// Module : VISU
// $Header$
-#include "utilities.h"
-#include <TColStd_MapOfInteger.hxx>
-#include <TColStd_MapIteratorOfMapOfInteger.hxx>
-#include "SALOME_ListIteratorOfListIO.hxx"
+#include "VisuGUI_Selection.h"
+
+#include "VisuGUI.h"
+#include "VisuGUI_Tools.h"
-#include "SALOME_Selection.h"
#include "VISU_Actor.h"
+#include "VISU_PrsObject_i.hh"
+#include "VISU_Prs3d_i.hh"
+#include "VISU_PipeLine.hxx"
+
+#include "SalomeApp_Study.h"
+#include "SalomeApp_Application.h"
+#include "LightApp_SelectionMgr.h"
+#include "LightApp_VTKSelector.h"
+
+#include "SUIT_MessageBox.h"
+#include "SUIT_ViewWindow.h"
+#include "SUIT_Session.h"
+
+#include "SALOME_ListIO.hxx"
+#include "SALOME_ListIteratorOfListIO.hxx"
+
+#include "SVTK_ViewWindow.h"
+#include "SVTK_ViewModel.h"
+#include "SVTK_Selector.h"
+#include "utilities.h"
+
+// OCCT Includes
+#include <TColStd_IndexedMapOfInteger.hxx>
+#include <TColStd_MapOfInteger.hxx>
+
+// QT Includes
#include <qstring.h>
-#include <qfiledialog.h>
-#include <qapplication.h>
-#include <qcolordialog.h>
#include <qlabel.h>
#include <qspinbox.h>
#include <qlistbox.h>
+#include <qlayout.h>
+#include <qhbuttongroup.h>
+#include <qradiobutton.h>
+#include <qvalidator.h>
+#include <qpushbutton.h>
+#include <qwidgetstack.h>
+#include <qvbox.h>
+#include <qgroupbox.h>
+#include <qlineedit.h>
+#include <qvalidator.h>
+#include <qtable.h>
+// VTK Includes
#include <vtkDataSetMapper.h>
-#include <vtkDataSetReader.h>
-#include <vtkPointPicker.h>
-#include <vtkLookupTable.h>
-#include <vtkPolyDataSource.h>
#include <vtkDataSet.h>
+#include <vtkPointData.h>
+#include <vtkCellData.h>
#include <vtkCell.h>
-#include <vtkMaskPoints.h>
-#include <vtkUnstructuredGrid.h>
-#include "VisuGUI_CellsResultsDlg.h"
-#include "VisuGUI_PointsResultsDlg.h"
-#include "VisuGUI_Selection.h"
+// STL Includes
+#include <map>
+
+using namespace std;
- int mode=0;
- int scal=0;
- int vect=0;
- char Msg[80]="";
-
- int id=0;
- char Msg_1[150]="";
- char Msg_2[150]="";
- float Coord[3];
- float ScalarValue=0;
- float VectorValue[3];
-
-int VisuGUI_Selection::PickViewer(QAD_Study *ActiveStudy, int mode)
+static VisuGUI_SelectionDlg* mySelectionDlg = NULL;
+
+VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent)
+ : QDialog(parent, 0, false, WStyle_Customize | WStyle_NormalBorder |
+ WStyle_Title | WStyle_SysMenu | WDestructiveClose),
+ mySelectionMgr(NULL)
{
- SALOME_Selection *Sel = SALOME_Selection::Selection(ActiveStudy->getSelection());
- SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
- for(;It.More();It.Next())
- {
- Handle(SALOME_InteractiveObject)IObject = It.Value();
- if (Sel->SelectionMode() == mode ) // Selection MODE
- {
- if (Sel->HasIndex(IObject))
- {
- TColStd_MapOfInteger MapIndex ;
- Sel->GetIndex(IObject, MapIndex) ;
- TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
- for (;ite.More(); ite.Next())
- {
- MESSAGE("Cell ID =" << ite.Key())
- return (ite.Key());
- }
- }
- }
- }
- return (-1);
+ if (mySelectionDlg)
+ mySelectionDlg->close(true);
+
+ setCaption( "Data on elements" );
+ setSizeGripEnabled(TRUE);
+
+ QGridLayout* TopLayout = new QGridLayout (this);
+ TopLayout->setSpacing(6);
+ TopLayout->setMargin(11);
+ TopLayout->setRowStretch(0, 0);
+ TopLayout->setRowStretch(1, 0);
+ TopLayout->setRowStretch(2, 1);
+ TopLayout->setRowStretch(3, 0);
+
+ QHButtonGroup* aTypeBox = new QHButtonGroup ("Selection", this);
+
+ QRadioButton* aPointBtn =
+ new QRadioButton ("Point", aTypeBox);
+ new QRadioButton ("Cell" , aTypeBox);
+ new QRadioButton ("Actor", aTypeBox);
+ aPointBtn->setChecked(true);
+
+ connect(aTypeBox, SIGNAL(clicked(int)), this, SLOT(onSelectionChange(int)));
+
+ TopLayout->addWidget(aTypeBox, 0, 0);
+
+ QWidget* aNamePane = new QWidget (this);
+ QGridLayout* aNameLay = new QGridLayout (aNamePane);
+
+ QLabel* aMeshLbl = new QLabel ("Mesh name: ", aNamePane);
+ myMeshName = new QLabel (aNamePane);
+
+ QLabel* aFieldLbl = new QLabel ("Field name: ", aNamePane);
+ myFieldName = new QLabel (aNamePane);
+
+ aNameLay->addWidget(aMeshLbl, 0, 0);
+ aNameLay->addWidget(myMeshName, 0, 1);
+ aNameLay->addWidget(aFieldLbl, 1, 0);
+ aNameLay->addWidget(myFieldName, 1, 1);
+
+ TopLayout->addWidget(aNamePane, 1, 0);
+
+ myWidgetStack = new QWidgetStack (this);
+
+ // Create Points pane
+ myPointsPane = new QVBox (myWidgetStack);
+ myPointsPane->layout()->setSpacing(6);
+
+ QGroupBox* aDataGrp = new QGroupBox (2, Qt::Horizontal, "Data of Point", myPointsPane);
+ aDataGrp->layout()->setSpacing(6);
+
+ new QLabel ("ID:", aDataGrp);
+ myIDValLbl = new QLineEdit ("", aDataGrp);
+ QIntValidator* aIntValidator = new QIntValidator (myIDValLbl);
+ aIntValidator->setBottom(0);
+ myIDValLbl->setValidator(aIntValidator);
+ connect(myIDValLbl, SIGNAL(textChanged(const QString&)), this, SLOT(onPointIdEdit(const QString&)));
+
+ new QLabel ("Scalar Value:", aDataGrp);
+ myScalarValLbl = new QLabel ("", aDataGrp);
+ new QLabel ("Vector Value:", aDataGrp);
+ myVectorValLbl = new QLabel ("", aDataGrp);
+ myVectorValLbl->setMinimumWidth(150);
+
+ QGroupBox* aCoordGrp = new QGroupBox (2, Qt::Horizontal, "Coordinates", myPointsPane);
+ aCoordGrp->layout()->setSpacing(6);
+ new QLabel ("X:", aCoordGrp);
+ myXValLbl = new QLabel ("", aCoordGrp);
+ new QLabel ("Y:", aCoordGrp);
+ myYValLbl = new QLabel ("", aCoordGrp);
+ new QLabel ("Z:",aCoordGrp );
+ myZValLbl = new QLabel ("", aCoordGrp);
+
+
+ myWidgetStack->addWidget(myPointsPane, 0);
+
+ // Create Cells pane
+ myCellsPane = new QWidget (myWidgetStack);
+ QGridLayout* aCellLayout = new QGridLayout (myCellsPane);
+ aCellLayout->setSpacing(6);
+ aCellLayout->setRowStretch(0, 0);
+ aCellLayout->setRowStretch(1, 1);
+
+ QGroupBox* aCellGrp = new QGroupBox(2, Qt::Horizontal, "Data of Cell", myCellsPane);
+
+ new QLabel ("ID:", aCellGrp);
+ myCellIDValLbl = new QLineEdit ("", aCellGrp);
+ myCellIDValLbl->setValidator(aIntValidator);
+ connect(myCellIDValLbl, SIGNAL(textChanged(const QString&)), this, SLOT(onCellIdEdit(const QString&)));
+
+ new QLabel ("Scalar Value:", aCellGrp);
+ myCellScalarValLbl = new QLabel ("", aCellGrp);
+ new QLabel ("Vector Value:", aCellGrp);
+ myCellVectorValLbl = new QLabel ("", aCellGrp);
+
+ aCellLayout->addWidget(aCellGrp, 0, 0);
+
+ myListPoints = new QTable (myCellsPane);
+ myListPoints->setReadOnly(true);
+ myListPoints->setNumCols(6);
+ myListPoints->setNumRows(0);
+ myListPoints->setColumnWidth(0, 40);
+ myListPoints->setColumnWidth(1, 40);
+ myListPoints->setColumnWidth(2, 40);
+ myListPoints->setColumnWidth(3, 40);
+ myListPoints->setSelectionMode(QTable::NoSelection);
+ QHeader* aHeader = myListPoints->horizontalHeader();
+ aHeader->setLabel( 0, "ID" );
+ aHeader->setLabel( 1, "X" );
+ aHeader->setLabel( 2, "Y" );
+ aHeader->setLabel( 3, "Z" );
+ aHeader->setLabel( 4, "Scalar" );
+ aHeader->setLabel( 5, "Vector" );
+
+ aCellLayout->addWidget(myListPoints, 1, 0);
+
+ myWidgetStack->addWidget(myCellsPane, 1);
+
+ // Actor Pane
+ myActorsPane = new QVBox (myWidgetStack);
+ myActorsPane->layout()->setSpacing(6);
+
+ QGroupBox* aPosGrp = new QGroupBox (2, Qt::Horizontal, "Position", myActorsPane);
+ aPosGrp->layout()->setSpacing(6);
+ new QLabel ("X:", aPosGrp);
+ myXPosLbl = new QLabel ("0", aPosGrp);
+ new QLabel ("Y:", aPosGrp);
+ myYPosLbl = new QLabel ("0", aPosGrp);
+ new QLabel ("Z:", aPosGrp);
+ myZPosLbl = new QLabel ("0", aPosGrp);
+
+ QGroupBox* aSizeGrp = new QGroupBox (2, Qt::Horizontal, "Size", myActorsPane);
+ aSizeGrp->layout()->setSpacing(6);
+ new QLabel ("dX:", aSizeGrp);
+ myDXLbl = new QLabel ("0", aSizeGrp);
+ new QLabel ("dY:", aSizeGrp);
+ myDYLbl = new QLabel ("0", aSizeGrp);
+ new QLabel ("dZ:",aSizeGrp );
+ myDZLbl = new QLabel ("0", aSizeGrp);
+
+ myWidgetStack->addWidget(myActorsPane, 2);
+
+
+ TopLayout->addWidget(myWidgetStack, 2, 0);
+
+ // Create buttons group
+ QHBox* aBtnBox = new QHBox (this);
+ QHBoxLayout* aBtnLayout = (QHBoxLayout*)aBtnBox->layout();
+ aBtnLayout->addStretch();
+
+ QPushButton* aCloseBtn = new QPushButton (tr("BUT_CLOSE"), aBtnBox);
+ connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
+
+ TopLayout->addWidget(aBtnBox, 3, 0);
+
+ SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
+ (SUIT_Session::session()->activeApplication());
+ mySelectionMgr = anApp->selectionMgr();
+ connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionEvent()));
+
+ //connect(visuGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(close()));
+
+ myFl = false;
+
+ // Activate Points pane
+ SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
+ myWidgetStack->raiseWidget(myPointsPane);
+ if (aSVTKVW)
+ aSVTKVW->SetSelectionMode(NodeSelection);
+ onSelectionEvent();
+
+ mySelectionDlg = this;
}
-void VisuGUI_Selection::PickingResults(QAD_Study *ActiveStudy, int mode, VISU_Actor *Actor)
+VisuGUI_SelectionDlg::~VisuGUI_SelectionDlg()
{
-
- if ( (mode == SelectionCell) || (mode == SelectionEdge) ) // Cell mode
- {
- PickingCell(ActiveStudy, Actor);
- }
+}
- else if (mode == SelectionPoint) // Point Mode
- {
- PickingPoint(ActiveStudy, Actor);
+void VisuGUI_SelectionDlg::onSelectionChange (int theId)
+{
+ SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
+ if (!aSVTKVW) return;
+
+ switch (theId) {
+ case 0: // Points
+ myWidgetStack->raiseWidget(myPointsPane);
+ aSVTKVW->SetSelectionMode(NodeSelection);
+ onPointIdEdit(myIDValLbl->text());
+ break;
+ case 1: // Cells
+ myWidgetStack->raiseWidget(myCellsPane);
+ aSVTKVW->SetSelectionMode(CellSelection);
+ onCellIdEdit(myCellIDValLbl->text());
+ break;
+ case 2: // Actor
+ myWidgetStack->raiseWidget(myActorsPane);
+ aSVTKVW->SetSelectionMode(ActorSelection);
+ onSelectionEvent();
}
}
-// ============================================================================================ //
-// PICKING CELL //
-// ============================================================================================ //
-void VisuGUI_Selection::PickingCell(QAD_Study *ActiveStudy, VISU_Actor *Actor)
+void VisuGUI_SelectionDlg::closeEvent (QCloseEvent* theEvent)
{
- vtkDataSet *Data ;
- vtkScalars *Scalar;
- vtkVectors *Vector;
- vtkCell *Cell;
- vtkIdList *PointList;
- vtkCellData *CellData;
- vtkPointData *PointData;
- vtkPoints *Points = vtkPoints::New();
- float Point_Coord[12][3];
- float CoordCurrent[3];
- int idCurrent;
-
- mode = SelectionCell;
-
- vtkActor* anActor = vtkActor::SafeDownCast( Actor );
- id=PickViewer(ActiveStudy,mode);
- if (id >= 0) // Cell exist
- {
- VisuGUI_CellsResultsDlg *ResultsDlg = new VisuGUI_CellsResultsDlg(QAD_Application::getDesktop(), 0, TRUE, 0);
-
- vtkDataSetMapper *Mapper = (vtkDataSetMapper*) (anActor->GetMapper());
- Mapper->SetInput(anActor->GetMapper()->GetInput());
- Data=Mapper->GetInput();
- Cell=Data->GetCell(id);
- CellData=Data->GetCellData();
- int NbOfPoints=Cell->GetNumberOfPoints();
- PointList=Cell->GetPointIds();
- QListViewItem* item = 0;
- for(int i=0; i<NbOfPoints; i++)
- {
- idCurrent = PointList->GetId(i);
- Data->GetPoint(idCurrent,CoordCurrent);
- for (int j=0; j<3; j++)
- Point_Coord[i][j]=CoordCurrent[j];
- item = new QListViewItem(ResultsDlg->ListPoints,
- item,
- QString::number( idCurrent ),
- QString::number( Point_Coord[i][0] ),
- QString::number( Point_Coord[i][1] ),
- QString::number( Point_Coord[i][2] ));
- }
-
- // Scalar result
- Scalar=CellData->GetScalars();
- if (Scalar!=NULL)
- {
- scal = 1;
- ScalarValue=Scalar->GetScalar(id);
- sprintf(Msg_1,"( %s ) %4f",Actor->FieldName,ScalarValue);
- }
- else
- {
- scal = 2;
- sprintf(Msg_1,"No scalar on Cell");
- }
-
- // Vector result
- Vector=CellData->GetVectors();
- if (Vector!=NULL)
- {
- vect = 1;
- Vector->GetVector(id,VectorValue);
- sprintf(Msg_2,"( %s ) %.4f %.4f %.4f",Actor->FieldName,VectorValue[0],VectorValue[1],VectorValue[2]);
- }
- else
- {
- vect = 2;
- sprintf(Msg_2,"No Vector on Cell");
- }
-
- ResultsDlg->IdCell->setText( QString::number( id ) );
- ResultsDlg->NbPoint->setText( QString::number( NbOfPoints ) );
- ResultsDlg->ScalValue->setText( Msg_1 );
- ResultsDlg->VectTxt->setText( Msg_2 );
- ResultsDlg->exec();
- delete ResultsDlg;
+ SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
+
+ mySelectionDlg = NULL;
+ if (aSVTKVW)
+ aSVTKVW->SetSelectionMode(ActorSelection);
+ disconnect(mySelectionMgr,0,0,0);
+ QDialog::closeEvent(theEvent);
+}
+
+template<class TData> QString getValue(TData* theData, int theId){
+ if (vtkDataArray *aScalar = theData->GetScalars()){
+ float aVal = aScalar->GetTuple1(theId);
+ return QString::number(aVal);
+ } else {
+ return QString("No data");
}
}
+template<class TData> QString getVector(TData* theData, int theId){
+ if (vtkDataArray *aVector = theData->GetVectors()) {
+ float *aVal = aVector->GetTuple3(theId);
+ return QString("%1; %2; %3").arg(aVal[0]).arg(aVal[1]).arg(aVal[2]);
+ } else {
+ return QString("No data");
+ }
+}
-// ============================================================================================ //
-// PICKING POINT //
-// ============================================================================================ //
+#define ABS(a) (a>=0)?a:-a
-void VisuGUI_Selection::PickingPoint(QAD_Study *ActiveStudy, VISU_Actor *Actor)
-{
- vtkDataSet *Data ;
- vtkScalars *Scalar;
- vtkVectors *Vector;
- vtkPointData *PointData;
-
- mode = SelectionPoint;
-
- id=PickViewer(ActiveStudy,mode);
- if (id >= 0)
- {
- VisuGUI_PointsResultsDlg *ResultsDlg = new VisuGUI_PointsResultsDlg(QAD_Application::getDesktop(), 0, TRUE, 0);
- vtkDataSetMapper *Mapper = (vtkDataSetMapper*) (Actor->GetMapper());
- Data=Mapper->GetInput();
- PointData=Data->GetPointData();
-
- Data->GetPoint(id,Coord);
- ResultsDlg->CoordX->setText( QString::number( Coord[0] ) );
- ResultsDlg->CoordY->setText( QString::number( Coord[1] ) );
- ResultsDlg->CoordZ->setText( QString::number( Coord[2] ) );
-// ActiveStudy->setMessage(Msg);
-
- Scalar=PointData->GetScalars();
- if (Scalar!=NULL)
- {
- scal = 1;
- ScalarValue=Scalar->GetScalar(id);
- sprintf(Msg_1,"( %s ) %4f",Actor->FieldName,ScalarValue);
- }
- else
- {
- scal = 2;
- sprintf(Msg_1,"No scalar at Point");
- }
-// ActiveStudy->setMessage(Msg_1);
-
- // Vector result
- Vector=PointData->GetVectors();
- if (Vector!=NULL)
- {
- vect = 1;
- Vector->GetVector(id,VectorValue);
- sprintf(Msg_2,"( %s ) %.4f %.4f %.4f",Actor->FieldName,VectorValue[0],VectorValue[1],VectorValue[2]);
- }
- else
- {
- vect = 2;
- sprintf(Msg_2,"No Vector at Point");
- }
- ResultsDlg->IdPoint->setText( QString::number(id) );
- ResultsDlg->ScalValue->setText(Msg_1);
- ResultsDlg->VectTxt->setText(Msg_2);
- ResultsDlg->exec();
- delete ResultsDlg;
-
-// ActiveStudy->setMessage( Msg_2 ) ;
+void VisuGUI_SelectionDlg::onSelectionEvent() {
+ SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
+ if (!aSVTKVW) return;
+
+ if (myFl) return;
+ myFl = true;
+
+ int aType = myWidgetStack->id(myWidgetStack->visibleWidget());
+
+ SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
+ (SUIT_Session::session()->activeApplication());
+
+ SVTK_Selector* aSelector = aSVTKVW->GetSelector();
+
+ VISU::Prs3d_i* aPrs3d = NULL;
+ _PTR(SObject) aSObject;
+ Handle(SALOME_InteractiveObject) anIO;
+
+ SALOME_ListIO aListIO;
+ mySelectionMgr->selectedObjects(aListIO, SVTK_Viewer::Type());
+
+ if (aListIO.Extent() == 1) {
+ anIO = aListIO.First();
+
+ if (anIO->hasEntry()) {
+ SalomeApp_Study* theStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
+ _PTR(Study) aStudy = theStudy->studyDS();
+ aSObject = aStudy->FindObjectID(anIO->getEntry());
+
+ if (aSObject) {
+ CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
+
+ if (!CORBA::is_nil(anObject)) {
+ PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
+
+ if (aServant.in()) {
+ aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
+ }
+ }
+ }
+ }
}
-}
-// ============================================================================================ //
-// HIGHLIGHT CELL //
-// ============================================================================================ //
-//
-void VisuGUI_Selection::HighlightCell(int idCell, VISU_Actor *Actor, vtkRenderer *ren)
-{
- MESSAGE("HighlightCell")
- vtkActor *Cell_Actor = vtkActor::New();
-
- vtkUnstructuredGrid* Cell_UGrid = vtkUnstructuredGrid::New();
- if ( Actor->GetMapper()->GetInput()->IsA("vtkUnstructuredGrid") ) {
- vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::SafeDownCast( Actor->GetMapper()->GetInput() );
-// if (UGrid != NULL) // LCO 1707
-// {
- vtkIdList *ptIds = vtkIdList::New(); ptIds->Allocate(12);
- vtkDataSetMapper* Cell_Mapper = vtkDataSetMapper::New();
-
- Cell_UGrid->SetPoints( UGrid->GetPoints() );
- UGrid->GetCellPoints( idCell, ptIds );
- Cell_UGrid->InsertNextCell(Actor->GetMapper()->GetInput()->GetCellType( idCell ), ptIds);
-
- Cell_Mapper->SetInput(Cell_UGrid);
- Cell_Actor->SetMapper(Cell_Mapper);
-
- ren->AddActor( Cell_Actor );
-
- Cell_Actor->GetProperty()->SetColor(1,1,0);
- Cell_Actor->GetProperty()->SetRepresentationToSurface();
- Cell_Actor->VisibilityOn();
-
- ren->Render();
- } // LCO
- Cell_Actor->Delete();
-}
-
-// ============================================================================================ //
-// HIGHLIGHT POINT //
-// ============================================================================================ //
-//
-void VisuGUI_Selection::HighlightPoint(int idPoint, int nbPoints, VISU_Actor *Actor, vtkRenderer *ren)
-{
- vtkActor *Point_Actor = vtkActor::New();
-
- MESSAGE("HighlightPoint")
- if ( Actor->GetMapper()->GetInput()->IsA("vtkUnstructuredGrid") ) {
- vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::SafeDownCast( Actor->GetMapper()->GetInput() );
-// if (UGrid != NULL) // LCO 1707
-// {
- vtkUnstructuredGrid* Point_UGrid = vtkUnstructuredGrid::New();
- float pts[3];
-
- vtkPoints *Points = vtkPoints::New();
- vtkMaskPoints* verts = vtkMaskPoints::New();
- vtkPolyDataMapper* vertMapper = vtkPolyDataMapper::New();
- Points->SetNumberOfPoints(nbPoints);
-
- UGrid->GetPoint( idPoint, pts) ;
- // Points->SetPoint(idPoint, 0., 0., 0. );
- Points->SetPoint(idPoint, pts);
- Point_UGrid->SetPoints(Points);
- verts->SetInput(Point_UGrid);
- verts->SetGenerateVertices(1);
- verts->SetOnRatio(1);
- vertMapper->SetInput(verts->GetOutput());
- Point_Actor->SetMapper(vertMapper);
- ren->AddActor( Point_Actor );
- Point_Actor->GetProperty()->SetColor(1,1,0);
- Point_Actor->GetProperty()->SetRepresentationToSurface();
- Point_Actor->VisibilityOn();
- ren->Render();
- } //LCO
- Point_Actor->Delete();
-}
-
-// ============================================================================================ //
-// Function to return results individual //
-// ============================================================================================ //
-
-int VisuGUI_Selection::getId()
-{
- return (id);
-}
+ if (aPrs3d) {
+ VISU::Storable::TRestoringMap aMap;
+ if (aSObject) {
+ _PTR(GenericAttribute) anAttr;
+ if (aSObject->FindAttribute(anAttr, "AttributeComment")) {
+ _PTR(AttributeComment) aComment (anAttr);
+ std::string aString = aComment->Value();
+ QString strIn( aString.c_str() );
+ VISU::Storable::StrToMap(strIn, aMap);
+ }
+ }
-char *VisuGUI_Selection::getMsg(int nb)
-{
- if (nb==1)
- return (Msg_1);
- else
- return (Msg_2);
+ QString aMeshName("NULL"), aFieldName("NULL");
+ if (!aMap.empty()) {
+ aMeshName = VISU::Storable::FindValue(aMap, "myMeshName");
+ aFieldName = VISU::Storable::FindValue(aMap, "myFieldName");
+ }
+
+ myMeshName ->setText((aMeshName == "NULL") ? QString("No name") : aMeshName);
+ myFieldName->setText((aFieldName == "NULL") ? QString("No name") : aFieldName);
+
+ VISU_Actor* anVISUActor =
+ VISU::FindActor(aSVTKVW, aSObject->GetID().c_str());
+ if (anVISUActor) {
+ float aCoord[6];
+ anVISUActor->GetBounds(aCoord);
+ myXPosLbl->setText(QString::number( aCoord[0] ));
+ myYPosLbl->setText(QString::number( aCoord[2] ));
+ myZPosLbl->setText(QString::number( aCoord[4] ));
+
+ myDXLbl->setText(QString::number( ABS(aCoord[1]-aCoord[0]) ));
+ myDYLbl->setText(QString::number( ABS(aCoord[3]-aCoord[2]) ));
+ myDZLbl->setText(QString::number( ABS(aCoord[5]-aCoord[4]) ));
+
+ TColStd_IndexedMapOfInteger aMapIndex;
+ typedef map<int,float*> PointsMap;
+ PointsMap aPointsMap;
+
+ aSelector->GetIndex(anIO, aMapIndex);
+
+ vtkDataSet* aDataSet = anVISUActor->GetInput();
+ vtkPointData* aPntData = aDataSet->GetPointData();
+
+ for (int ind = 1; ind <= aMapIndex.Extent(); ind++) {
+ int aID = aMapIndex(ind);
+
+ switch (aType) {
+ case 0:
+ {
+ float aCoord[3];
+ aDataSet->GetPoint(aID, aCoord);
+ myXValLbl->setText( QString::number( aCoord[0] ) );
+ myYValLbl->setText( QString::number( aCoord[1] ) );
+ myZValLbl->setText( QString::number( aCoord[2] ) );
+ myIDValLbl->setText( QString::number(aID) );
+ myScalarValLbl->setText(getValue(aPntData, aID));
+ myVectorValLbl->setText(getVector(aPntData, aID));
+ }
+ break;
+ case 1:
+ {
+ vtkCellData* aData = aDataSet->GetCellData();
+ vtkCell* aCell = aDataSet->GetCell(aID);
+ if (aCell != NULL) {
+ int aNbOfPoints = aCell->GetNumberOfPoints();
+ if (aNbOfPoints <=1 ) { // Cell is point
+ clearFields();
+ } else {
+ myCellIDValLbl->setText( QString::number(aID) );
+ myCellScalarValLbl->setText(getValue(aData, aID));
+ myCellVectorValLbl->setText(getVector(aData, aID));
+
+ float* aCoord;
+ vtkIdList *aPointList = aCell->GetPointIds();
+
+ for (int i = 0; i < aNbOfPoints; i++) {
+ int idCurrent = aPointList->GetId(i);
+ aCoord = aDataSet->GetPoint(idCurrent);
+ aPointsMap.insert(PointsMap::value_type(idCurrent,aCoord));
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ myListPoints->setNumRows(aPointsMap.size());
+ PointsMap::const_iterator It = aPointsMap.begin();
+ for (int i = 0; It != aPointsMap.end() && i < myListPoints->numRows(); It++, i++) {
+ myListPoints->verticalHeader()->setLabel(i, QString::number( i ));
+ int id = It->first;
+ myListPoints->setText(i, 0, QString::number( id ));
+ float* aCoord = It->second;
+ myListPoints->setText(i, 1, QString::number( aCoord[0] ));
+ myListPoints->setText(i, 2, QString::number( aCoord[1] ));
+ myListPoints->setText(i, 3, QString::number( aCoord[2] ));
+ myListPoints->setText(i, 4, getValue(aPntData, id));
+ myListPoints->setText(i, 5, getVector(aPntData, id));
+ }
+ }
+ } else {
+ clearFields();
+ }
+ myFl = false;
}
+#undef ABS
-float *VisuGUI_Selection::getCoord()
-{
- return (Coord);
+
+void VisuGUI_SelectionDlg::clearFields() {
+ int aType = myWidgetStack->id(myWidgetStack->visibleWidget());
+ switch (aType) {
+ case 0:
+ myXValLbl->setText( "" );
+ myYValLbl->setText( "" );
+ myZValLbl->setText( "" );
+ myIDValLbl->setText( "" );
+ myScalarValLbl->setText("");
+ myVectorValLbl->setText("");
+ break;
+ case 1:
+ myCellIDValLbl->setText( "" );
+ myCellScalarValLbl->setText("");
+ myCellVectorValLbl->setText("");
+ myListPoints->setNumRows(0);
+ break;
+ case 2:
+ myXPosLbl->setText("");
+ myYPosLbl->setText("");
+ myZPosLbl->setText("");
+ myDXLbl->setText("");
+ myDYLbl->setText("");
+ myDZLbl->setText("");
+ }
}
-
-float VisuGUI_Selection::getScalar()
+
+typedef vtkIdType (vtkDataSet::* TDataSetMethod)();
+
+bool onIdEdit (const QString& theText,
+ TDataSetMethod theMethod,
+ bool theIsCell,
+ LightApp_SelectionMgr* theSelectionMgr,
+ QLabel* theMeshName,
+ QString theValue,
+ QLabel* theFieldName)
{
- if (scal == 1)
- return (ScalarValue);
- else
- return (0);
+ SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
+ (SUIT_Session::session()->activeApplication());
+ SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
+ if (!aSVTKVW) return false;
+ SVTK_Selector* aSelector = aSVTKVW->GetSelector();
+
+ VISU::Prs3d_i* aPrs3d = NULL;
+ Handle(SALOME_InteractiveObject) anIO;
+
+ SALOME_ListIO aListIO;
+ theSelectionMgr->selectedObjects(aListIO, SVTK_Viewer::Type());
+
+ if (aListIO.Extent() == 1) {
+ anIO = aListIO.First();
+
+ if (anIO->hasEntry()) {
+ SalomeApp_Study* theStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
+ _PTR(Study) aStudy = theStudy->studyDS();
+ _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
+
+ if (aSObject) {
+ CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
+
+ if (!CORBA::is_nil(anObject)) {
+ PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
+
+ if (aServant.in()) {
+ aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
+ }
+ }
+ }
+ }
+ }
+
+ if (aPrs3d) {
+ int anId = theText.toInt();
+ vtkDataSet* aDataSet = aPrs3d->GetPL()->GetMapper()->GetInput();
+ int aMaxId = (aDataSet->*theMethod)();
+ if (anId < 0) anId = 0;
+ if (anId >= aMaxId) anId = aMaxId - 1;
+
+ TColStd_MapOfInteger newIndices;
+ newIndices.Add(anId);
+ aSelector->AddOrRemoveIndex(anIO, newIndices, false);
+ aSVTKVW->highlight(anIO, true, true);
+
+ return true;
+
+ } else {
+ theMeshName->setText(theValue);
+ theFieldName->setText("");
+ }
+ return false;
}
-float *VisuGUI_Selection::getVector()
+void VisuGUI_SelectionDlg::onPointIdEdit (const QString& theText)
{
- if (vect == 1)
- return (VectorValue);
- else
- return (0);
+ if (myFl) return;
+ TDataSetMethod aMethod = &vtkDataSet::GetNumberOfPoints;
+ bool anIsSelected = onIdEdit(theText,aMethod,false,mySelectionMgr,
+ myMeshName,tr("WRN_NO_AVAILABLE_DATA"),
+ myFieldName);
+ if (anIsSelected)
+ // as selection manager doesn't send signal currentSelectionChanged()
+ onSelectionEvent();
+ else
+ clearFields();
}
-int VisuGUI_Selection::getMode()
+void VisuGUI_SelectionDlg::onCellIdEdit (const QString& theText)
{
- return (mode );
+ if (myFl) return;
+ TDataSetMethod aMethod = &vtkDataSet::GetNumberOfCells;
+ bool anIsSelected = onIdEdit(theText,aMethod,true,mySelectionMgr,
+ myMeshName,tr("WRN_NO_AVAILABLE_DATA"),
+ myFieldName);
+ if (anIsSelected)
+ // as selection manager doesn't send signal currentSelectionChanged()
+ onSelectionEvent();
+ else
+ clearFields();
}