Salome HOME
PAL13460 (PAL EDF 301 force the mesh to go through a point)
authoreap <eap@opencascade.com>
Wed, 21 Feb 2007 17:03:13 +0000 (17:03 +0000)
committereap <eap@opencascade.com>
Wed, 21 Feb 2007 17:03:13 +0000 (17:03 +0000)
   add SMESHGUI_MeshEditPreview.* showing SMESH::MeshPreviewStruct

src/SMESHGUI/Makefile.in
src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx [new file with mode: 0644]
src/SMESHGUI/SMESHGUI_MeshEditPreview.h [new file with mode: 0644]

index c56a3d56477390a2c76b1802bd57234f21437adb..9a9385c7178dda78a3e1db6ded1125ebd2b80292 100644 (file)
@@ -111,7 +111,8 @@ LIB_SRC =   SMESHGUI.cxx \
                SMESHGUI_ShapeByMeshDlg.cxx \
                SMESHGUI_AddQuadraticElementDlg.cxx \
                SMESHGUI_ConvToQuadDlg.cxx \
-               SMESHGUI_ConvToQuadOp.cxx
+               SMESHGUI_ConvToQuadOp.cxx \
+               SMESHGUI_MeshEditPreview.cxx
 
 LIB_MOC = \
                SMESHGUI.h \
diff --git a/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx b/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx
new file mode 100644 (file)
index 0000000..d571868
--- /dev/null
@@ -0,0 +1,236 @@
+//  SMESH SMESHGUI : GUI for SMESH 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+//
+//
+//  File   : SMESHGUI_MeshEditPreview.cxx
+//  Module : SMESH
+//  $Header:
+
+#include "SMESHGUI_MeshEditPreview.h"
+
+#include "VTKViewer_CellLocationsArray.h"
+#include "SVTK_ViewWindow.h"
+
+#include "SMESH_Actor.h"
+#include "SMESH_ActorUtils.h"
+#include "SMESHGUI_VTKUtils.h"
+
+// VTK Includes
+#include <vtkPoints.h>
+#include <vtkIdList.h>
+#include <vtkCellArray.h>
+#include <vtkUnsignedCharArray.h>
+#include <vtkUnstructuredGrid.h>
+#include <vtkUnstructuredGridWriter.h>
+#include <vtkDataSetMapper.h>
+#include <vtkProperty.h>
+
+// QT Includes
+#include <qcolor.h>
+
+// IDL Headers
+#include "SALOMEconfig.h"
+#include CORBA_SERVER_HEADER(SMESH_Mesh)
+
+using namespace SMESH;
+
+//================================================================================
+/*!
+ * \brief Constructor
+ */
+//================================================================================
+
+SMESHGUI_MeshEditPreview::SMESHGUI_MeshEditPreview(SVTK_ViewWindow* theViewWindow):
+  myViewWindow(theViewWindow)
+{
+  myGrid = vtkUnstructuredGrid::New();
+
+  // Create and display actor
+  vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
+  aMapper->SetInput( myGrid );
+
+  vtkProperty* aProp = vtkProperty::New();
+  vtkFloatingPointType anRGB[3];
+  GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
+  aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
+
+  myPreviewActor = SALOME_Actor::New();
+  myPreviewActor->SetInfinitive(true);
+  myPreviewActor->VisibilityOn();
+  myPreviewActor->PickableOff();
+  myPreviewActor->SetProperty( aProp );
+  aProp->Delete();
+
+  myPreviewActor->SetMapper( aMapper );
+  aMapper->Delete();
+
+  myViewWindow->AddActor(myPreviewActor);
+
+}
+
+//================================================================================
+/*!
+ * \brief Destroy
+ */
+//================================================================================
+
+SMESHGUI_MeshEditPreview::~SMESHGUI_MeshEditPreview()
+{
+  myGrid->Delete();
+
+  myViewWindow->RemoveActor(myPreviewActor);
+  myPreviewActor->Delete();
+
+}
+
+//================================================================================
+/*!
+ * \brief Returns vtk cell type
+ */
+//================================================================================
+
+vtkIdType getCellType( const SMDSAbs_ElementType theType,
+                       const bool thePoly,
+                       const int theNbNodes )
+{
+  switch( theType ) 
+  {
+  case SMDSAbs_Edge: 
+    if( theNbNodes == 2 )         return VTK_LINE;
+    else if ( theNbNodes == 3 )   return VTK_QUADRATIC_EDGE;
+    else return VTK_EMPTY_CELL;
+
+  case SMDSAbs_Face  :
+    if (thePoly && theNbNodes>2 ) return VTK_POLYGON;
+    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 == 8 )   return VTK_QUADRATIC_QUAD;
+    else return VTK_EMPTY_CELL;
+
+  case SMDSAbs_Volume:
+    if (thePoly && theNbNodes>3 ) return VTK_CONVEX_POINT_SET;
+    else if ( theNbNodes == 4 )   return VTK_TETRA;
+    else if ( theNbNodes == 5 )   return VTK_PYRAMID;
+    else if ( theNbNodes == 6 )   return VTK_WEDGE;
+    else if ( theNbNodes == 8 )   return VTK_HEXAHEDRON;
+    else if ( theNbNodes == 10 )  {
+      return VTK_QUADRATIC_TETRA;
+    }
+    else if ( theNbNodes == 20 )  {
+      return VTK_QUADRATIC_HEXAHEDRON;
+    }
+    else if ( theNbNodes==13 || theNbNodes==15 )  {
+      return VTK_CONVEX_POINT_SET;
+    }
+    else return VTK_EMPTY_CELL;
+
+  default: return VTK_EMPTY_CELL;
+  }
+}
+
+//================================================================================
+/*!
+ * \brief Set preview data
+ */
+//================================================================================
+
+void SMESHGUI_MeshEditPreview::SetData (const SMESH::MeshPreviewStruct* previewData)
+{
+  // Create points
+  const SMESH::nodes_array& aNodesXYZ = previewData->nodesXYZ;
+  vtkPoints* aPoints = vtkPoints::New();
+  aPoints->SetNumberOfPoints(aNodesXYZ.length());
+
+  for ( int i = 0; i < aNodesXYZ.length(); i++ ) {
+    aPoints->SetPoint( i, aNodesXYZ[i].x, aNodesXYZ[i].y, aNodesXYZ[i].z );
+  }
+  myGrid->SetPoints(aPoints);
+
+  aPoints->Delete();
+
+  // Create cells
+  const SMESH::long_array&  anElemConnectivity = previewData->elementConnectivities;
+  const SMESH::types_array& anElemTypes = previewData->elementTypes;
+
+  vtkIdType aCellsSize = anElemConnectivity.length() + anElemTypes.length();
+  vtkIdType aNbCells = anElemTypes.length();
+
+  vtkCellArray* aConnectivity = vtkCellArray::New();
+  aConnectivity->Allocate( aCellsSize, 0 );
+
+  vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
+  aCellTypesArray->SetNumberOfComponents( 1 );
+  aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
+
+  vtkIdList *anIdList = vtkIdList::New();
+  int aNodePos = 0;
+
+  for ( int i = 0; i < anElemTypes.length(); i++ ) {
+    const ElementSubType& anElementSubType = anElemTypes[i];
+    SMDSAbs_ElementType aType = SMDSAbs_ElementType(anElementSubType.SMDS_ElementType);
+    vtkIdType aNbNodes = anElementSubType.nbNodesInElement;
+    anIdList->SetNumberOfIds( aNbNodes );
+
+    for ( vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++ ){
+      anIdList->SetId( aNodeId, anElemConnectivity[aNodePos] );
+      aNodePos++;
+    }
+
+    aConnectivity->InsertNextCell( anIdList );
+    aCellTypesArray->InsertNextValue( getCellType( aType,
+                                                   anElemTypes[i].isPoly, 
+                                                   aNbNodes ) );
+  }
+  anIdList->Delete();
+
+  // Insert cells in grid
+  VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
+  aCellLocationsArray->SetNumberOfComponents( 1 );
+  aCellLocationsArray->SetNumberOfTuples( aNbCells );
+
+  aConnectivity->InitTraversal();
+  for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
+    aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
+
+  myGrid->SetCells( aCellTypesArray, aCellLocationsArray, aConnectivity );
+
+  myPreviewActor->GetMapper()->Update();
+
+  aCellTypesArray->Delete();
+  aCellLocationsArray->Delete();
+  aConnectivity->Delete();
+
+  SetVisibility(true);
+}
+
+//================================================================================
+/*!
+ * \brief Set visibility
+ */
+//================================================================================
+
+void SMESHGUI_MeshEditPreview::SetVisibility (bool theVisibility)
+{
+  myPreviewActor->SetVisibility(theVisibility);
+  RepaintCurrentView();
+}
diff --git a/src/SMESHGUI/SMESHGUI_MeshEditPreview.h b/src/SMESHGUI/SMESHGUI_MeshEditPreview.h
new file mode 100644 (file)
index 0000000..2178863
--- /dev/null
@@ -0,0 +1,58 @@
+//  SMESH SMESHGUI : GUI for SMESH 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+//
+//
+//  File   : SMESHGUI_MeshEditPreview.cxx
+//  Module : SMESH
+//  $Header:
+
+#ifndef SMESHGUI_MESHEDITPREVIEW_H
+#define SMESHGUI_MESHEDITPREVIEW_H
+
+class SVTK_ViewWindow;
+class vtkUnstructuredGrid;
+class SALOME_Actor;
+namespace SMESH {
+  class MeshPreviewStruct;
+}
+
+/*!
+ * \brief Displayer of the mesh edition preview
+ */
+class SMESHGUI_MeshEditPreview {
+  SVTK_ViewWindow* myViewWindow;
+
+  vtkUnstructuredGrid* myGrid;
+  SALOME_Actor* myPreviewActor;
+
+public:
+
+  SMESHGUI_MeshEditPreview(SVTK_ViewWindow* theViewWindow);
+  ~SMESHGUI_MeshEditPreview();
+
+  void SetData (const SMESH::MeshPreviewStruct* theMeshPreviewStruct);
+
+  void SetVisibility (bool theVisibility);
+
+};
+
+#endif