X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_MeshEditPreview.cxx;h=a99df65340fd33017a8f339461b322fc20def9e7;hp=358b2cf402a17b462dcd38ff266eef4be1224b37;hb=499f29d24922cec66e41b41a0039a954993bc6df;hpb=bd8f1aee7c78f7d2eb82bd4fec5e08c9e3d280ce diff --git a/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx b/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx index 358b2cf40..a99df6534 100644 --- a/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2022 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 @@ -28,23 +28,26 @@ #include "SMESHGUI_MeshEditPreview.h" #include "SMESHGUI_VTKUtils.h" - -#include -#include +#include "SMESH_Actor.h" +#include "SMESH_ActorUtils.h" // SALOME GUI includes -#include +#include #include +//#include // VTK includes -#include -#include #include -#include -#include -#include +#include #include +#include +#include #include +#include +#include +#include +#include +#include // Qt includes #include @@ -53,6 +56,8 @@ #include #include CORBA_SERVER_HEADER(SMESH_MeshEditor) +#include + //================================================================================ /*! * \brief Constructor @@ -86,7 +91,6 @@ SMESHGUI_MeshEditPreview::SMESHGUI_MeshEditPreview(SVTK_ViewWindow* theViewWindo aMapper->Delete(); myViewWindow->AddActor(myPreviewActor); - } //================================================================================ @@ -99,9 +103,15 @@ SMESHGUI_MeshEditPreview::~SMESHGUI_MeshEditPreview() { myGrid->Delete(); + for ( size_t iA = 0; iA < myLabelActors.size(); ++iA ) + if ( myLabelActors[iA] ) + { + myPreviewActor->GetRenderer()->RemoveActor( myLabelActors[iA] ); + myLabelActors[iA]->Delete(); + } + myViewWindow->RemoveActor(myPreviewActor); myPreviewActor->Delete(); - } //================================================================================ @@ -111,13 +121,14 @@ SMESHGUI_MeshEditPreview::~SMESHGUI_MeshEditPreview() //================================================================================ vtkIdType getCellType( const SMDSAbs_ElementType theType, - const bool thePoly, - const int theNbNodes ) + const bool thePoly, + const int theNbNodes ) { switch( theType ) { + case SMDSAbs_Ball: return VTK_VERTEX; case SMDSAbs_Node: return VTK_VERTEX; - case SMDSAbs_Edge: + case SMDSAbs_Edge: if( theNbNodes == 2 ) return VTK_LINE; else if ( theNbNodes == 3 ) return VTK_QUADRATIC_EDGE; else return VTK_EMPTY_CELL; @@ -127,6 +138,7 @@ vtkIdType getCellType( const SMDSAbs_ElementType theType, else if ( theNbNodes == 3 ) return VTK_TRIANGLE; else if ( theNbNodes == 4 ) return VTK_QUAD; else if ( theNbNodes == 6 ) return VTK_QUADRATIC_TRIANGLE; + else if ( theNbNodes == 7 ) return VTK_BIQUADRATIC_TRIANGLE; else if ( theNbNodes == 8 ) return VTK_QUADRATIC_QUAD; else if ( theNbNodes == 9 ) return VTK_BIQUADRATIC_QUAD; else return VTK_EMPTY_CELL; @@ -141,6 +153,7 @@ vtkIdType getCellType( const SMDSAbs_ElementType theType, else if ( theNbNodes == 20 ) return VTK_QUADRATIC_HEXAHEDRON; else if ( theNbNodes == 27 ) return VTK_TRIQUADRATIC_HEXAHEDRON; else if ( theNbNodes == 15 ) return VTK_QUADRATIC_WEDGE; + else if ( theNbNodes == 18 ) return VTK_BIQUADRATIC_QUADRATIC_WEDGE; else if ( theNbNodes == 13 ) return VTK_QUADRATIC_PYRAMID;//VTK_CONVEX_POINT_SET; else return VTK_EMPTY_CELL; @@ -154,14 +167,14 @@ vtkIdType getCellType( const SMDSAbs_ElementType theType, */ //================================================================================ -void SMESHGUI_MeshEditPreview::SetData (const SMESH::MeshPreviewStruct* previewData) +void SMESHGUI_MeshEditPreview::SetData (const SMESH::MeshPreviewStruct& previewData) { // Create points - const SMESH::nodes_array& aNodesXYZ = previewData->nodesXYZ; + const SMESH::nodes_array& aNodesXYZ = previewData.nodesXYZ; vtkPoints* aPoints = vtkPoints::New(); aPoints->SetNumberOfPoints(aNodesXYZ.length()); - for ( int i = 0; i < aNodesXYZ.length(); i++ ) { + for ( size_t i = 0; i < aNodesXYZ.length(); i++ ) { aPoints->SetPoint( i, aNodesXYZ[i].x, aNodesXYZ[i].y, aNodesXYZ[i].z ); } myGrid->SetPoints(aPoints); @@ -169,8 +182,8 @@ void SMESHGUI_MeshEditPreview::SetData (const SMESH::MeshPreviewStruct* previewD aPoints->Delete(); // Create cells - const SMESH::long_array& anElemConnectivity = previewData->elementConnectivities; - const SMESH::types_array& anElemTypes = previewData->elementTypes; + const SMESH::long_array& anElemConnectivity = previewData.elementConnectivities; + const SMESH::types_array& anElemTypes = previewData.elementTypes; vtkIdType aCellsSize = anElemConnectivity.length() + anElemTypes.length(); vtkIdType aNbCells = anElemTypes.length(); @@ -185,7 +198,7 @@ void SMESHGUI_MeshEditPreview::SetData (const SMESH::MeshPreviewStruct* previewD vtkIdList *anIdList = vtkIdList::New(); int aNodePos = 0; - for ( int i = 0; i < anElemTypes.length(); i++ ) { + for ( size_t i = 0; i < anElemTypes.length(); i++ ) { const SMESH::ElementSubType& anElementSubType = anElemTypes[i]; SMDSAbs_ElementType aType = SMDSAbs_ElementType(anElementSubType.SMDS_ElementType); vtkIdType aNbNodes = anElementSubType.nbNodesInElement; @@ -204,12 +217,13 @@ void SMESHGUI_MeshEditPreview::SetData (const SMESH::MeshPreviewStruct* previewD anIdList->Delete(); // Insert cells in grid - VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New(); + vtkIdTypeArray* aCellLocationsArray = vtkIdTypeArray::New(); aCellLocationsArray->SetNumberOfComponents( 1 ); aCellLocationsArray->SetNumberOfTuples( aNbCells ); aConnectivity->InitTraversal(); - for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) + vtkIdType const *pts(nullptr); + for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); myGrid->SetCells( aCellTypesArray, aCellLocationsArray, aConnectivity ); @@ -223,6 +237,128 @@ void SMESHGUI_MeshEditPreview::SetData (const SMESH::MeshPreviewStruct* previewD SetVisibility(true); } +//================================================================================ +/*! + * \brief Set shape of an arrow of a unit length and nb of arrows + */ +//================================================================================ + +void SMESHGUI_MeshEditPreview::SetArrowShapeAndNb( int nbArrows, + double headLength, + double headRadius, + double start, + const char* labels) +{ + const int theNbPoints = 10; // in one arrow + myUnitArrowPnts.reserve( theNbPoints ); + myUnitArrowPnts.clear(); + + // unit arrow || OZ + + for ( int i = 0; i < theNbPoints - 2; ++i ) + { + double angle = i * 2 * M_PI / ( theNbPoints - 2 ); + myUnitArrowPnts.push_back( gp_Pnt( headRadius * Cos( angle ), + headRadius * Sin( angle ), + 1. - headLength )); + } + myUnitArrowPnts.push_back( gp_Pnt( 0, 0, start )); + myUnitArrowPnts.push_back( gp_Pnt( 0, 0, 1 )); + + + // nodes of all arrows + + vtkPoints* aPoints = vtkPoints::New(); + aPoints->SetNumberOfPoints( theNbPoints * nbArrows ); + for ( int iP = 0, iA = 0; iA < nbArrows; ++iA ) + for ( int i = 0; i < theNbPoints; ++i, ++iP ) + aPoints->SetPoint( iP, + myUnitArrowPnts[i].X(), + myUnitArrowPnts[i].Y(), + myUnitArrowPnts[i].Z() ); + myGrid->SetPoints(aPoints); + aPoints->Delete(); + + // connectivity of all arrows + + const int theNbCells = ( theNbPoints - 1 ); // in one arrow + myGrid->Allocate( theNbCells * nbArrows ); + for ( int nP = 0, iA = 0; iA < nbArrows; ++iA, nP += theNbPoints ) + { + vtkIdType conn[3] = { theNbPoints - 1 + nP, // arrow end + theNbPoints - 3 + nP, // point on a circle + nP }; // point on a circle + for ( int i = 0; i < theNbCells-1; ++i ) + { + myGrid->InsertNextCell( VTK_TRIANGLE, 3, conn ); + conn[1] = conn[2]; + conn[2] = conn[2] + 1; + } + conn[1] = theNbPoints - 2 + nP; + myGrid->InsertNextCell( VTK_LINE, 2, conn ); + } + + myLabelActors.resize( nbArrows, ( vtkTextActor*) NULL ); + char label[] = "X"; + if ( labels ) + for ( int iA = 0; iA < nbArrows; ++iA ) + { + label[0] = labels[iA]; + vtkTextMapper* text = vtkTextMapper::New(); + text->SetInput( label ); + vtkCoordinate* coord = vtkCoordinate::New(); + + myLabelActors[iA] = vtkTextActor::New(); + //myLabelActors[iA]->SetMapper( text ); + myLabelActors[iA]->SetInput( label ); + myLabelActors[iA]->SetTextScaleModeToNone(); + myLabelActors[iA]->PickableOff(); + myLabelActors[iA]->GetPositionCoordinate()->SetReferenceCoordinate( coord ); + + text->Delete(); + coord->Delete(); + + myPreviewActor->GetRenderer()->AddActor(myLabelActors[iA]); + } +} + +//================================================================================ +/*! + * \brief Set data to show moved/rotated/scaled arrows + * \param [in] axes - location and direction of the arrows + * \param [in] length - length of arrows + */ +//================================================================================ + +void SMESHGUI_MeshEditPreview::SetArrows( const gp_Ax1* axes, + double length ) +{ + vtkPoints* aPoints = myGrid->GetPoints(); + + for ( int iP = 0, iA = 0; iA < (int) myLabelActors.size(); ++iA ) + { + gp_Trsf trsf; + trsf.SetTransformation( gp_Ax3( axes[iA].Location(), axes[iA].Direction() ), gp::XOY() ); + + for ( size_t i = 0; i < myUnitArrowPnts.size(); ++i, ++iP ) + { + gp_Pnt p = myUnitArrowPnts[i].Scaled( gp::Origin(), length ); + p.Transform( trsf ); + aPoints->SetPoint( iP, p.X(), p.Y(), p.Z() ); + } + if ( myLabelActors[iA] ) + if ( vtkCoordinate* aCoord = + myLabelActors[iA]->GetPositionCoordinate()->GetReferenceCoordinate() ) + { + double p[3]; + aPoints->GetPoint( iP-1, p ); + aCoord->SetValue( p ); + } + } + + myGrid->Modified(); +} + //================================================================================ /*! * \brief Set visibility @@ -232,6 +368,9 @@ void SMESHGUI_MeshEditPreview::SetData (const SMESH::MeshPreviewStruct* previewD void SMESHGUI_MeshEditPreview::SetVisibility (bool theVisibility) { myPreviewActor->SetVisibility(theVisibility); + for ( size_t iA = 0; iA < myLabelActors.size(); ++iA ) + if ( myLabelActors[iA] ) + myLabelActors[iA]->SetVisibility(theVisibility); SMESH::RepaintCurrentView(); } @@ -251,7 +390,30 @@ void SMESHGUI_MeshEditPreview::SetColor(double R, double G, double B) * \brief Get preview actor */ //================================================================================ + SALOME_Actor* SMESHGUI_MeshEditPreview::GetActor() const { return myPreviewActor; } + +//================================================================================ +/*! + * \brief Returns the priewed vtkUnstructuredGrid + */ +//================================================================================ + +vtkUnstructuredGrid* SMESHGUI_MeshEditPreview::GetGrid() const +{ + return myGrid; +} + +//================================================================================ +/*! + * \brief Returns myViewWindow + */ +//================================================================================ + +SVTK_ViewWindow* SMESHGUI_MeshEditPreview::GetViewWindow() const +{ + return myViewWindow; +}