2014-02-20 18:25:37 +06:00
|
|
|
// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
|
2012-08-09 16:03:55 +06:00
|
|
|
//
|
|
|
|
// Copyright (C) 2003-2007 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
|
2014-02-20 18:25:37 +06:00
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
2012-08-09 16:03:55 +06:00
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
//
|
|
|
|
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
|
|
|
//
|
|
|
|
// File : SMESH_NodeLabelActor.cxx
|
|
|
|
// Author : Roman NIKOLAEV
|
|
|
|
// Module : SMESH
|
|
|
|
//
|
|
|
|
#include "SMESH_NodeLabelActor.h"
|
|
|
|
|
|
|
|
#include <VTKViewer_TransformFilter.h>
|
|
|
|
|
|
|
|
#include <vtkObjectFactory.h>
|
|
|
|
#include <vtkCallbackCommand.h>
|
|
|
|
#include <vtkMaskPoints.h>
|
|
|
|
#include <vtkSelectVisiblePoints.h>
|
|
|
|
#include <vtkLabeledDataMapper.h>
|
|
|
|
#include <vtkActor2D.h>
|
|
|
|
#include <vtkTextProperty.h>
|
|
|
|
#include <vtkPointData.h>
|
|
|
|
#include <vtkProperty2D.h>
|
|
|
|
#include <vtkRenderer.h>
|
|
|
|
#include <vtkUnstructuredGrid.h>
|
|
|
|
|
|
|
|
vtkStandardNewMacro(SMESH_NodeLabelActor);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Constructor.
|
|
|
|
*/
|
|
|
|
SMESH_NodeLabelActor::SMESH_NodeLabelActor() {
|
|
|
|
//Definition of points numbering pipeline
|
|
|
|
//---------------------------------------
|
|
|
|
myPointsNumDataSet = vtkUnstructuredGrid::New();
|
|
|
|
|
|
|
|
myPtsMaskPoints = vtkMaskPoints::New();
|
2013-03-01 19:13:25 +06:00
|
|
|
myPtsMaskPoints->SetInputData(myPointsNumDataSet);
|
2012-08-09 16:03:55 +06:00
|
|
|
myPtsMaskPoints->SetOnRatio(1);
|
|
|
|
|
|
|
|
myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
|
2013-03-01 19:13:25 +06:00
|
|
|
myPtsSelectVisiblePoints->SetInputConnection(myPtsMaskPoints->GetOutputPort());
|
2012-08-09 16:03:55 +06:00
|
|
|
myPtsSelectVisiblePoints->SelectInvisibleOff();
|
|
|
|
myPtsSelectVisiblePoints->SetTolerance(0.1);
|
|
|
|
|
|
|
|
myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
|
2013-03-01 19:13:25 +06:00
|
|
|
myPtsLabeledDataMapper->SetInputConnection(myPtsSelectVisiblePoints->GetOutputPort());
|
2012-08-09 16:03:55 +06:00
|
|
|
myPtsLabeledDataMapper->SetLabelFormat("%d");
|
|
|
|
myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
|
|
|
|
|
2013-02-12 20:37:44 +06:00
|
|
|
myPtsTextProp = vtkTextProperty::New();
|
|
|
|
myPtsTextProp->SetFontFamilyToTimes();
|
|
|
|
myPtsTextProp->SetFontSize(10);
|
|
|
|
myPtsTextProp->SetBold(1);
|
|
|
|
myPtsTextProp->SetItalic(0);
|
|
|
|
myPtsTextProp->SetShadow(0);
|
|
|
|
myPtsTextProp->SetColor( 1, 1, 1 );
|
|
|
|
myPtsLabeledDataMapper->SetLabelTextProperty(myPtsTextProp);
|
2012-08-09 16:03:55 +06:00
|
|
|
|
|
|
|
myIsPointsLabeled = false;
|
|
|
|
|
|
|
|
myPointLabels = vtkActor2D::New();
|
|
|
|
myPointLabels->SetMapper(myPtsLabeledDataMapper);
|
|
|
|
myPointLabels->SetVisibility(myIsPointsLabeled);
|
|
|
|
|
|
|
|
vtkCallbackCommand* callBackCommand = vtkCallbackCommand::New();
|
|
|
|
callBackCommand->SetClientData(this);
|
|
|
|
callBackCommand->SetCallback(SMESH_NodeLabelActor::ProcessEvents);
|
|
|
|
|
|
|
|
myTransformFilter->AddObserver("VTKViewer_TransformFilter::TransformationFinished",
|
2013-02-12 20:37:44 +06:00
|
|
|
callBackCommand);
|
2012-08-09 16:03:55 +06:00
|
|
|
callBackCommand->Delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Destructor
|
|
|
|
*/
|
|
|
|
SMESH_NodeLabelActor::~SMESH_NodeLabelActor() {
|
|
|
|
//Deleting of points numbering pipeline
|
|
|
|
//---------------------------------------
|
|
|
|
myPointsNumDataSet->Delete();
|
|
|
|
|
|
|
|
// commented: porting to vtk 5.0
|
|
|
|
// myPtsLabeledDataMapper->RemoveAllInputs();
|
|
|
|
myPtsLabeledDataMapper->Delete();
|
|
|
|
|
|
|
|
// commented: porting to vtk 5.0
|
|
|
|
// myPtsSelectVisiblePoints->UnRegisterAllOutputs();
|
|
|
|
myPtsSelectVisiblePoints->Delete();
|
|
|
|
|
|
|
|
// commented: porting to vtk 5.0
|
|
|
|
// myPtsMaskPoints->UnRegisterAllOutputs();
|
|
|
|
myPtsMaskPoints->Delete();
|
|
|
|
myPointLabels->Delete();
|
2013-02-12 20:37:44 +06:00
|
|
|
myPtsTextProp->Delete();
|
|
|
|
}
|
2012-08-09 16:03:55 +06:00
|
|
|
|
2013-02-12 20:37:44 +06:00
|
|
|
void SMESH_NodeLabelActor::SetFontProperties( SMESH::LabelFont family, int size,
|
|
|
|
bool bold, bool italic, bool shadow,
|
2013-03-01 19:13:25 +06:00
|
|
|
double r, double g, double b )
|
2013-02-12 20:37:44 +06:00
|
|
|
{
|
|
|
|
switch ( family ) {
|
|
|
|
case SMESH::FntArial:
|
|
|
|
myPtsTextProp->SetFontFamilyToArial(); break;
|
|
|
|
case SMESH::FntCourier:
|
|
|
|
myPtsTextProp->SetFontFamilyToCourier(); break;
|
|
|
|
case SMESH::FntTimes:
|
|
|
|
default:
|
|
|
|
myPtsTextProp->SetFontFamilyToTimes(); break;
|
|
|
|
}
|
|
|
|
myPtsTextProp->SetFontSize( size );
|
|
|
|
myPtsTextProp->SetBold( bold );
|
|
|
|
myPtsTextProp->SetItalic( italic );
|
|
|
|
myPtsTextProp->SetShadow( shadow );
|
|
|
|
myPtsTextProp->SetColor( r, g, b );
|
2012-08-09 16:03:55 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
void SMESH_NodeLabelActor::SetPointsLabeled(bool theIsPointsLabeled) {
|
|
|
|
myTransformFilter->Update();
|
|
|
|
vtkDataSet* aGrid = vtkUnstructuredGrid::SafeDownCast(myTransformFilter->GetOutput());
|
|
|
|
|
|
|
|
if(!aGrid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
|
|
|
|
|
|
|
|
if ( myIsPointsLabeled )
|
|
|
|
{
|
|
|
|
myPointsNumDataSet->ShallowCopy(aGrid);
|
|
|
|
vtkUnstructuredGrid *aDataSet = myPointsNumDataSet;
|
|
|
|
|
|
|
|
int aNbElem = aDataSet->GetNumberOfPoints();
|
|
|
|
|
|
|
|
vtkIntArray *anArray = vtkIntArray::New();
|
|
|
|
anArray->SetNumberOfValues( aNbElem );
|
|
|
|
|
|
|
|
for ( vtkIdType anId = 0; anId < aNbElem; anId++ )
|
|
|
|
{
|
|
|
|
int aSMDSId = myVisualObj->GetNodeObjId( anId );
|
|
|
|
anArray->SetValue( anId, aSMDSId );
|
|
|
|
}
|
|
|
|
|
|
|
|
aDataSet->GetPointData()->SetScalars( anArray );
|
2013-03-01 19:13:25 +06:00
|
|
|
myPtsMaskPoints->SetInputData( aDataSet );
|
2012-08-09 16:03:55 +06:00
|
|
|
myPointLabels->SetVisibility( GetVisibility() );
|
|
|
|
anArray->Delete();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
myPointLabels->SetVisibility( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SMESH_NodeLabelActor::SetVisibility(int theMode)
|
|
|
|
{
|
|
|
|
SMESH_DeviceActor::SetVisibility(theMode);
|
|
|
|
myPointLabels->VisibilityOff();
|
|
|
|
if(myIsPointsLabeled && theMode)
|
|
|
|
myPointLabels->VisibilityOn();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SMESH_NodeLabelActor::AddToRender(vtkRenderer* theRenderer)
|
|
|
|
{
|
|
|
|
SMESH_DeviceActor::AddToRender(theRenderer);
|
|
|
|
myPtsSelectVisiblePoints->SetRenderer(theRenderer);
|
|
|
|
theRenderer->AddActor2D(myPointLabels);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SMESH_NodeLabelActor::RemoveFromRender(vtkRenderer* theRenderer)
|
|
|
|
{
|
|
|
|
theRenderer->RemoveActor(myPointLabels);
|
|
|
|
SMESH_DeviceActor::RemoveFromRender(theRenderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SMESH_NodeLabelActor::UpdateLabels() {
|
|
|
|
if(myIsPointsLabeled)
|
|
|
|
SetPointsLabeled(myIsPointsLabeled);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SMESH_NodeLabelActor::ProcessEvents(vtkObject* vtkNotUsed(theObject),
|
2013-02-12 20:37:44 +06:00
|
|
|
unsigned long theEvent,
|
|
|
|
void* theClientData,
|
|
|
|
void* vtkNotUsed(theCallData)) {
|
2012-08-09 16:03:55 +06:00
|
|
|
SMESH_NodeLabelActor* self = reinterpret_cast<SMESH_NodeLabelActor*>(theClientData);
|
|
|
|
if(self)
|
|
|
|
self->UpdateLabels();
|
|
|
|
}
|