X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FOBJECT%2FSMESH_NodeLabelActor.cxx;h=4ac4c90f20faabb31a0df0dd2216adf4653b4274;hb=f20db3c5b3a2f78f9ff7579a59c7bd1d3eece20a;hp=5d7b33507218119af1ad000723f2ee523d49c764;hpb=bd4e115a78b52e3fbc016e5e30bb0e19b2a9e7d6;p=modules%2Fsmesh.git diff --git a/src/OBJECT/SMESH_NodeLabelActor.cxx b/src/OBJECT/SMESH_NodeLabelActor.cxx index 5d7b33507..4ac4c90f2 100644 --- a/src/OBJECT/SMESH_NodeLabelActor.cxx +++ b/src/OBJECT/SMESH_NodeLabelActor.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -6,7 +6,7 @@ // 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 @@ -39,45 +39,44 @@ #include #include -vtkStandardNewMacro(SMESH_NodeLabelActor); +vtkStandardNewMacro(SMESH_NodeLabelActor) /*! Constructor. */ -SMESH_NodeLabelActor::SMESH_NodeLabelActor() { +SMESH_NodeLabelActor::SMESH_NodeLabelActor() +{ //Definition of points numbering pipeline //--------------------------------------- myPointsNumDataSet = vtkUnstructuredGrid::New(); myPtsMaskPoints = vtkMaskPoints::New(); - myPtsMaskPoints->SetInput(myPointsNumDataSet); + myPtsMaskPoints->SetInputData(myPointsNumDataSet); myPtsMaskPoints->SetOnRatio(1); myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New(); - myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput()); + myPtsSelectVisiblePoints->SetInputConnection(myPtsMaskPoints->GetOutputPort()); myPtsSelectVisiblePoints->SelectInvisibleOff(); myPtsSelectVisiblePoints->SetTolerance(0.1); - + myPtsLabeledDataMapper = vtkLabeledDataMapper::New(); - myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput()); - myPtsLabeledDataMapper->SetLabelFormat("%d"); + myPtsLabeledDataMapper->SetInputConnection(myPtsSelectVisiblePoints->GetOutputPort()); + //myPtsLabeledDataMapper->SetLabelFormat("%d"); myPtsLabeledDataMapper->SetLabelModeToLabelScalars(); - - vtkTextProperty* aPtsTextProp = vtkTextProperty::New(); - aPtsTextProp->SetFontFamilyToTimes(); - static int aPointsFontSize = 10; - aPtsTextProp->SetFontSize(aPointsFontSize); - aPtsTextProp->SetBold(1); - aPtsTextProp->SetItalic(0); - aPtsTextProp->SetShadow(0); - myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp); - aPtsTextProp->Delete(); + + 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); myIsPointsLabeled = false; myPointLabels = vtkActor2D::New(); myPointLabels->SetMapper(myPtsLabeledDataMapper); - myPointLabels->GetProperty()->SetColor(1,1,1); myPointLabels->SetVisibility(myIsPointsLabeled); vtkCallbackCommand* callBackCommand = vtkCallbackCommand::New(); @@ -85,67 +84,84 @@ SMESH_NodeLabelActor::SMESH_NodeLabelActor() { callBackCommand->SetCallback(SMESH_NodeLabelActor::ProcessEvents); myTransformFilter->AddObserver("VTKViewer_TransformFilter::TransformationFinished", - callBackCommand); + callBackCommand); callBackCommand->Delete(); } /*! Destructor */ -SMESH_NodeLabelActor::~SMESH_NodeLabelActor() { +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(); + myPtsTextProp->Delete(); +} +void SMESH_NodeLabelActor::SetFontProperties( SMESH::LabelFont family, int size, + bool bold, bool italic, bool shadow, + double r, double g, double b ) +{ + 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 ); } -void SMESH_NodeLabelActor::SetPointsLabeled(bool theIsPointsLabeled) { +void SMESH_NodeLabelActor::SetPointsLabeled(bool theIsPointsLabeled) +{ + myIsPointsLabeled = theIsPointsLabeled; + + myPointLabels->SetVisibility( false ); + myTransformFilter->Update(); vtkDataSet* aGrid = vtkUnstructuredGrid::SafeDownCast(myTransformFilter->GetOutput()); - if(!aGrid) - return; - - myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints(); - - if ( myIsPointsLabeled ) + if ( myIsPointsLabeled && aGrid ) { myPointsNumDataSet->ShallowCopy(aGrid); vtkUnstructuredGrid *aDataSet = myPointsNumDataSet; - - int aNbElem = aDataSet->GetNumberOfPoints(); - - vtkIntArray *anArray = vtkIntArray::New(); + + vtkIdType aNbElem = aDataSet->GetNumberOfPoints(); + + vtkIdTypeArray *anArray = vtkIdTypeArray::New(); anArray->SetNumberOfValues( aNbElem ); - + for ( vtkIdType anId = 0; anId < aNbElem; anId++ ) { - int aSMDSId = myVisualObj->GetNodeObjId( anId ); + vtkIdType aSMDSId = myVisualObj->GetNodeObjId( anId ); anArray->SetValue( anId, aSMDSId ); } - + aDataSet->GetPointData()->SetScalars( anArray ); - myPtsMaskPoints->SetInput( aDataSet ); + myPtsMaskPoints->SetInputData( aDataSet ); myPointLabels->SetVisibility( GetVisibility() ); anArray->Delete(); } - else - { - myPointLabels->SetVisibility( false ); - } } @@ -171,17 +187,19 @@ void SMESH_NodeLabelActor::RemoveFromRender(vtkRenderer* theRenderer) SMESH_DeviceActor::RemoveFromRender(theRenderer); } -void SMESH_NodeLabelActor::UpdateLabels() { +void SMESH_NodeLabelActor::UpdateLabels() +{ if(myIsPointsLabeled) SetPointsLabeled(myIsPointsLabeled); } void SMESH_NodeLabelActor::ProcessEvents(vtkObject* vtkNotUsed(theObject), - unsigned long theEvent, - void* theClientData, - void* vtkNotUsed(theCallData)) { - SMESH_NodeLabelActor* self = reinterpret_cast(theClientData); + unsigned long /*theEvent*/, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + SMESH_NodeLabelActor* self = reinterpret_cast(theClientData); if(self) self->UpdateLabels(); }