]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 2 Feb 2016 04:19:00 +0000 (23:19 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 2 Feb 2016 04:19:00 +0000 (23:19 -0500)
lib/cpPlugins/Interface/ParametersQtDialog.cxx
lib/cpPlugins/Interface/ParametersQtDialog.h
lib/cpPlugins/Plugins/IO/MeshReader.cxx
lib/cpPlugins/Plugins/IO/MeshWriter.cxx

index 456704b0300f2c1fc8e0613ce8307139737de05b..32cd8c4bea84b706d1c7f7d83045a39f2831874c 100644 (file)
@@ -65,6 +65,7 @@ int cpPlugins::Interface::ParametersQtDialog::
 exec( )
 {
   this->_updateWidgets( );
+  this->updateView( );
 
   int ret = this->QDialog::exec( );
   if( ret == 1 )
@@ -268,6 +269,26 @@ updateView( )
   } // rof
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+_addButtons( )
+{
+  // Add buttons
+  this->m_Buttons = new QDialogButtonBox(
+    QDialogButtonBox::Ok | QDialogButtonBox::Cancel
+    );
+  this->connect(
+    this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
+    );
+  this->connect(
+    this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
+    );
+  this->m_ToolsLayout->addWidget( this->m_Buttons );
+
+  this->updateView( );
+  this->m_WidgetsUpdated = true;
+}
+
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::ParametersQtDialog::
 _updateWidgets( )
@@ -512,21 +533,8 @@ _updateWidgets( )
 
   } // rof
 
-  // Add buttons
-  this->m_Buttons = new QDialogButtonBox(
-    QDialogButtonBox::Ok | QDialogButtonBox::Cancel
-    );
-  this->connect(
-    this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
-    );
-  this->connect(
-    this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
-    );
-  this->m_ToolsLayout->addWidget( this->m_Buttons );
-
   // Update values
-  this->updateView( );
-  this->m_WidgetsUpdated = true;
+  this->_addButtons( );
 }
 
 // -------------------------------------------------------------------------
index 421f707038c97314ff967d0e58479a4556cc21cf..04b76eda75bc5bbd43c56dd8aa4d1531f2980db8 100644 (file)
@@ -36,11 +36,12 @@ namespace cpPlugins
 
       virtual int exec( );
 
-      void updateParameters( );
-      void updateView( );
+      virtual void updateParameters( );
+      virtual void updateView( );
 
     protected:
-      void _updateWidgets( );
+      virtual void _addButtons( );
+      virtual void _updateWidgets( );
 
     protected slots:
       virtual void _dlg_OpenSingleFile( );
index 60bb57d4dfe4eb9c9f8dd95fa96ac0f7734e7b82..8dce5610aa72221d108b4f991b8b6767227c18dc 100644 (file)
@@ -1,8 +1,11 @@
 #include "MeshReader.h"
 #include <cpPlugins/Interface/Mesh.h>
 
+#include <cstring>
+
 #include <vtkPolyData.h>
 #include <vtkPolyDataReader.h>
+#include <vtkSTLReader.h>
 
 // -------------------------------------------------------------------------
 cpPlugins::IO::MeshReader::
@@ -67,16 +70,41 @@ _GD1( )
   // Get filename
   std::string fname = this->m_Parameters->GetOpenFileName( "FileName" );
 
-  vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
-  pdr->SetFileName( fname.c_str( ) );
-  pdr->Update( );
+  // Get file extension
+  std::istringstream fname_str( fname );
+  std::string token, ext;
+  while( std::getline( fname_str, token, '.' ) )
+    ext = token;
+  std::transform( ext.begin( ), ext.end( ), ext.begin( ), tolower );
+
+  // Real read
+  if( ext == "stl" )
+  {
+    vtkSTLReader* stlr = this->_CreateVTK< vtkSTLReader >( );
+    stlr->SetFileName( fname.c_str( ) );
+    stlr->Update( );
+
+    auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" );
+    if( out != NULL )
+      out->SetVTK( stlr->GetOutput( ) );
+    else
+      return( "MeshReader: output not correctly created." );
+    return( "" );
+  }
+  else if( ext == "vtk" )
+  {
+    vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
+    pdr->SetFileName( fname.c_str( ) );
+    pdr->Update( );
+
+    auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" );
+    if( out != NULL )
+      out->SetVTK( pdr->GetOutput( ) );
+    else
+      return( "MeshReader: output not correctly created." );
+    return( "" );
 
-  auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" );
-  if( out != NULL )
-    out->SetVTK( pdr->GetOutput( ) );
-  else
-    return( "MeshReader: output not correctly created." );
-  return( "" );
+  } // fi
 }
 
 // eof - $RCSfile$
index 7f0bba051cb22066f053231cca525cfe05ceb339..b0b7227ba7897b4b24b77bed685d409f81a40fad 100644 (file)
@@ -39,6 +39,7 @@ _GenerateData( )
   vtkPolyDataWriter* pdw = this->_CreateVTK< vtkPolyDataWriter >( );
   pdw->SetInputData( i );
   pdw->SetFileName( fname.c_str( ) );
+  pdw->SetFileTypeToBinary( );
   pdw->Update( );
   if( pdw->GetErrorCode( ) != 0 )
     return( "MeshWriter: someting wrong happened." );