Salome HOME
IPAL52974: Find Element by Point shows nodes that do not belong to current group
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshEditPreview.cxx
index f80c0dc524c920be61a65379f7afbb6ecc6fd000..73377c3b11b5aed9641ec11c88e2a08da5ebbaae 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  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
 #include "SMESHGUI_MeshEditPreview.h"
 
 #include "SMESHGUI_VTKUtils.h"
-
-#include <SMESH_Actor.h>
-#include <SMESH_ActorUtils.h>
+#include "SMESH_Actor.h"
+#include "SMESH_ActorUtils.h"
 
 // SALOME GUI includes
-#include <VTKViewer_CellLocationsArray.h>
+#include <SVTK_Renderer.h>
 #include <SVTK_ViewWindow.h>
+#include <VTKViewer_CellLocationsArray.h>
 
 // VTK includes
-#include <vtkPoints.h>
-#include <vtkIdList.h>
 #include <vtkCellArray.h>
-#include <vtkUnsignedCharArray.h>
-#include <vtkUnstructuredGrid.h>
-#include <vtkUnstructuredGridWriter.h>
+#include <vtkCoordinate.h>
 #include <vtkDataSetMapper.h>
+#include <vtkIdList.h>
+#include <vtkPoints.h>
 #include <vtkProperty.h>
+#include <vtkRenderer.h>
+#include <vtkTextActor.h>
+#include <vtkTextMapper.h>
+#include <vtkUnsignedCharArray.h>
+#include <vtkUnstructuredGrid.h>
 
 // Qt includes
 #include <QColor>
@@ -88,7 +91,6 @@ SMESHGUI_MeshEditPreview::SMESHGUI_MeshEditPreview(SVTK_ViewWindow* theViewWindo
   aMapper->Delete();
 
   myViewWindow->AddActor(myPreviewActor);
-
 }
 
 //================================================================================
@@ -101,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();
-
 }
 
 //================================================================================
@@ -118,8 +126,9 @@ vtkIdType getCellType( const SMDSAbs_ElementType theType,
 {
   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;
@@ -164,7 +173,7 @@ void SMESHGUI_MeshEditPreview::SetData (const SMESH::MeshPreviewStruct* previewD
   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);
@@ -188,7 +197,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;
@@ -232,10 +241,11 @@ void SMESHGUI_MeshEditPreview::SetData (const SMESH::MeshPreviewStruct* previewD
  */
 //================================================================================
 
-void SMESHGUI_MeshEditPreview::SetArrowShapeAndNb( int    nbArrows,
-                                                   double headLength,
-                                                   double headRadius,
-                                                   double start)
+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 );
@@ -286,7 +296,28 @@ void SMESHGUI_MeshEditPreview::SetArrowShapeAndNb( int    nbArrows,
     myGrid->InsertNextCell( VTK_LINE, 2, conn );
   }
 
-  myNbArrows = nbArrows;
+  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]);
+    }
 }
 
 //================================================================================
@@ -302,7 +333,7 @@ void SMESHGUI_MeshEditPreview::SetArrows( const gp_Ax1* axes,
 {
   vtkPoints* aPoints = myGrid->GetPoints();
 
-  for ( int iP = 0, iA = 0; iA < myNbArrows; ++iA )
+  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() );
@@ -313,6 +344,14 @@ void SMESHGUI_MeshEditPreview::SetArrows( const gp_Ax1* axes,
       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();
@@ -327,6 +366,9 @@ void SMESHGUI_MeshEditPreview::SetArrows( const gp_Ax1* axes,
 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();
 }
 
@@ -362,3 +404,14 @@ vtkUnstructuredGrid* SMESHGUI_MeshEditPreview::GetGrid() const
 {
   return myGrid;
 }
+
+//================================================================================
+/*!
+ * \brief Returns myViewWindow
+ */
+//================================================================================
+
+SVTK_ViewWindow* SMESHGUI_MeshEditPreview::GetViewWindow() const
+{
+  return myViewWindow;
+}