#include "HYDROData_Tool.h"
#include "HYDROData_PolylineXY.h"
+#include <boost/math/special_functions/fpclassify.hpp>
+
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
return aRes;
}
-bool HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc,
- const TCollection_AsciiString& theFileName )
+int HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc,
+ const TCollection_AsciiString& theFileName,
+ NCollection_Sequence<int>& theBadProfilesIds )
{
if ( theDoc.IsNull() || theFileName.IsEmpty() )
- return false;
+ return 0;
OSD_File aFile( theFileName );
if ( !aFile.IsReadable() )
- return false;
+ return 0;
aFile.Open( OSD_ReadOnly, OSD_Protection() );
if ( !aFile.IsOpen() )
- return false;
+ return 0;
NCollection_Sequence<Handle(HYDROData_Profile)> aCreatedProfiles;
+ int aProfileId = 1;
Handle(HYDROData_Profile) aNewProfile;
- while ( !aFile.IsAtEnd() )
+ for ( ; !aFile.IsAtEnd(); ++aProfileId )
{
if ( aNewProfile.IsNull() )
aNewProfile = Handle(HYDROData_Profile)::DownCast( theDoc->CreateObject( KIND_PROFILE ) );
- if ( aNewProfile->ImportFromFile( aFile ) )
+ bool anIsRead = false;
+ if ( aNewProfile->ImportFromFile( aFile, &anIsRead ) )
{
aCreatedProfiles.Append( aNewProfile );
aNewProfile.Nullify();
}
+ else if ( anIsRead )
+ {
+ theBadProfilesIds.Append( aProfileId );
+ }
}
if ( !aNewProfile.IsNull() )
aProfile->SetBorderColor( HYDROData_Profile::DefaultBorderColor() );
}
- return !aCreatedProfiles.IsEmpty();
+ return aCreatedProfiles.Length();
}
-bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileName )
+bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileName,
+ bool* theIsRead )
{
+ if ( theIsRead )
+ *theIsRead = false;
+
// Try to open the file
OSD_File aFile( theFileName );
if ( !aFile.IsReadable() )
if ( !aFile.IsOpen() )
return false;
- bool aRes = ImportFromFile( aFile );
+ bool aRes = ImportFromFile( aFile, theIsRead );
// Close the file
aFile.Close();
return aRes;
}
-bool HYDROData_Profile::ImportFromFile( OSD_File& theFile )
+bool HYDROData_Profile::ImportFromFile( OSD_File& theFile,
+ bool* theIsRead )
{
+ if ( theIsRead )
+ *theIsRead = false;
+
if ( !theFile.IsOpen() )
return false;
break; // Next profile started
}
+ // Set flag of read status to true
+ if ( theIsRead )
+ *theIsRead = true;
+
TCollection_AsciiString aValX = aLine.Token( " \t", 1 );
TCollection_AsciiString aValY = aLine.Token( " \t", 2 );
TCollection_AsciiString aValZ = aLine.Token( " \t", 3 );
double aCoordX = aValX.RealValue();
double aCoordY = aValY.RealValue();
+ if ( boost::math::isnan( aCoordX ) || boost::math::isinf( aCoordX ) ||
+ boost::math::isnan( aCoordY ) || boost::math::isinf( aCoordY ) )
+ aRes = false;
+
if ( anIsParametric )
{
if ( aCoordX < aPrevVal )
}
double aCoordZ = aValZ.RealValue();
+ if ( boost::math::isnan( aCoordZ ) || boost::math::isinf( aCoordZ ) )
+ aRes = false;
ProfilePoint aPoint( aCoordX, aCoordY, aCoordZ );
aPointsXYZ.Append( aPoint );
* - georeferenced presentation of profile (3 points in line X,Y,Z)
* Create as many objects as many profiles in the file are defined.
* \param theFileName the path to file
- * \return \c true if file has been successfully read
+ * \return \c number of successfully imported profiles
*/
- HYDRODATA_EXPORT static bool ImportFromFile( const Handle(HYDROData_Document)& theDoc,
- const TCollection_AsciiString& theFileName );
+ HYDRODATA_EXPORT static int ImportFromFile( const Handle(HYDROData_Document)& theDoc,
+ const TCollection_AsciiString& theFileName,
+ NCollection_Sequence<int>& theBadProfilesIds );
/**
* Imports Profile data from file.
* \param theFileName the path to file
+ * \param theIsRead set to true if at least one non empty string was read from file
* \return \c true if file has been successfully read
*/
- HYDRODATA_EXPORT virtual bool ImportFromFile( const TCollection_AsciiString& theFileName );
+ HYDRODATA_EXPORT virtual bool ImportFromFile( const TCollection_AsciiString& theFileName,
+ bool* theIsRead = 0 );
/**
* Imports Profile data from file.
* \param theFile file to read
+ * \param theIsRead set to true if at least one non empty string was read from file
* \return \c true if file has been successfully read
*/
- HYDRODATA_EXPORT virtual bool ImportFromFile( OSD_File& theFile );
+ HYDRODATA_EXPORT virtual bool ImportFromFile( OSD_File& theFile,
+ bool* theIsRead = 0 );
protected:
#include "HYDROGUI_DataModel.h"
#include "HYDROGUI_Module.h"
#include "HYDROGUI_UpdateFlags.h"
+#include "HYDROGUI_Tool.h"
#include <HYDROData_Profile.h>
#include <SUIT_Desktop.h>
#include <SUIT_FileDlg.h>
+#include <SUIT_MessageBox.h>
+#include <QApplication>
#include <QFileInfo>
HYDROGUI_ImportProfilesOp::HYDROGUI_ImportProfilesOp( HYDROGUI_Module* theModule )
myFileDlg->exec();
}
-bool HYDROGUI_ImportProfilesOp::processApply( int& theUpdateFlags,
- QString& theErrorMsg )
+void HYDROGUI_ImportProfilesOp::onApply()
{
- if ( !myFileDlg ) {
- return false;
+ if ( !myFileDlg )
+ {
+ abort();
+ return;
}
- bool aRes = false;
-
// Get the selected files
QStringList aFileNames = myFileDlg->selectedFiles();
+ if ( aFileNames.isEmpty() )
+ {
+ abort();
+ return;
+ }
+
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+
+ startDocOperation();
// Import each of the selected files, fill the list of bad imported files
QString aBadImportedFiles;
- foreach ( const QString& aFileName, aFileNames ) {
- if ( !HYDROData_Profile::ImportFromFile( doc(), qPrintable( aFileName ) ) ) {
- aBadImportedFiles += aFileName + "\n";
+ int aTotalNbImported = 0;
+
+ foreach ( const QString& aFileName, aFileNames )
+ {
+ NCollection_Sequence<int> aBadProfilesIds;
+ TCollection_AsciiString anAsciiFileName = HYDROGUI_Tool::ToAsciiString( aFileName );
+
+ int aNbImported = HYDROData_Profile::ImportFromFile( doc(), anAsciiFileName, aBadProfilesIds );
+ if ( aNbImported == 0 || !aBadProfilesIds.IsEmpty() )
+ {
+ aBadImportedFiles += QFileInfo( aFileName ).fileName();
+ if ( !aBadProfilesIds.IsEmpty() && aNbImported > 0 )
+ {
+ aBadImportedFiles += ", " + tr( "BAD_PROFILE_IDS" ) + " : ";
+ for ( int i = 1, n = aBadProfilesIds.Length(); i <= n; ++i )
+ aBadImportedFiles += QString::number( aBadProfilesIds.Value( i ) ) + ", ";
+ aBadImportedFiles.remove( aBadImportedFiles.length() - 2, 2 );
+ }
+ aBadImportedFiles += ";\n";
}
+
+ aTotalNbImported += aNbImported;
}
- // Operation is successful if all the selected files imported succesfully
- if ( aBadImportedFiles.isEmpty() ) {
- aRes = true;
- } else {
- theErrorMsg = tr( "BAD_IMPORTED_PROFILES_FILES" ).arg( aBadImportedFiles );
+ if ( aTotalNbImported == 0 )
+ {
+ QApplication::restoreOverrideCursor();
+
+ SUIT_MessageBox::critical( module()->getApp()->desktop(),
+ tr( "BAD_IMPORTED_PROFILES_FILES_TLT" ),
+ tr( "NO_ONE_PROFILE_IMPORTED" ) );
+
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+
+ abortDocOperation();
abort();
}
+ else
+ {
+ if ( !aBadImportedFiles.isEmpty() )
+ {
+ QApplication::restoreOverrideCursor();
+
+ aBadImportedFiles = aBadImportedFiles.simplified();
+ SUIT_MessageBox::warning( module()->getApp()->desktop(),
+ tr( "BAD_IMPORTED_PROFILES_FILES_TLT" ),
+ tr( "BAD_IMPORTED_PROFILES_FILES" ).arg( aBadImportedFiles ) );
+
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+ }
- theUpdateFlags = UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
+ commitDocOperation();
+ commit();
- return aRes;
+ module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
+ }
+
+ QApplication::restoreOverrideCursor();
}
+
protected:
virtual void startOperation();
- virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg );
+ virtual void onApply();
private:
SUIT_FileDlg* myFileDlg;
<source>PROFILE_FILTER</source>
<translation>All files (*.* *)</translation>
</message>
+ <message>
+ <source>BAD_PROFILE_IDS</source>
+ <translation>numbers of bad profiles</translation>
+ </message>
+ <message>
+ <source>BAD_IMPORTED_PROFILES_FILES_TLT</source>
+ <translation>Profiles import error</translation>
+ </message>
+ <message>
+ <source>NO_ONE_PROFILE_IMPORTED</source>
+ <translation>No one profile has been import from selected file(s).</translation>
+ </message>
<message>
<source>BAD_IMPORTED_PROFILES_FILES</source>
- <translation>The following files cannot be correctly imported for a Profile definition:
+ <translation>The data from following files cannot be completely imported:
%1
</translation>
</message>