]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
#refs 522 (very draft) //import only
authorisn <isn@opencascade.com>
Thu, 21 May 2015 13:54:37 +0000 (17:54 +0400)
committerisn <isn@opencascade.com>
Fri, 22 May 2015 09:16:53 +0000 (12:16 +0300)
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_ImportPolylineOp.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_Operations.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index 6f684a9cc2beec33024595311867bd6976be0280..b87cd343a966a41fc5c46f0582b6dd4484bb1003 100644 (file)
@@ -32,6 +32,7 @@ set(PROJECT_HEADERS
     HYDROGUI_ImportBathymetryOp.h
     HYDROGUI_ImportImageDlg.h
     HYDROGUI_ImportImageOp.h
+    HYDROGUI_ImportPolylineOp.h
     HYDROGUI_InputPanel.h
     HYDROGUI_LocalCSDlg.h
     HYDROGUI_LocalCSOp.h
@@ -143,6 +144,7 @@ set(PROJECT_SOURCES
     HYDROGUI_ImportBathymetryOp.cxx
     HYDROGUI_ImportImageDlg.cxx
     HYDROGUI_ImportImageOp.cxx
+    HYDROGUI_ImportPolylineOp.cxx
     HYDROGUI_InputPanel.cxx
     HYDROGUI_LocalCSDlg.cxx
     HYDROGUI_LocalCSOp.cxx
diff --git a/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx b/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx
new file mode 100644 (file)
index 0000000..f5d365d
--- /dev/null
@@ -0,0 +1,245 @@
+// 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
+//
+// 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, 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
+// 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
+//
+
+#include "HYDROGUI_ImportPolylineOp.h"
+
+#include "HYDROGUI_DataModel.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_UpdateFlags.h"
+#include "HYDROGUI_Tool.h"
+#include <HYDROData_PolylineXY.h>
+#include <HYDROData_Polyline3D.h>
+#include <HYDROGUI_DataObject.h>
+#include <HYDROData_Bathymetry.h>
+
+#include <HYDROData_Profile.h>
+
+#include <SUIT_Desktop.h>
+#include <SUIT_FileDlg.h>
+#include <LightApp_Application.h>
+
+#include <QApplication>
+#include <QFile>
+
+HYDROGUI_ImportPolylineOp::HYDROGUI_ImportPolylineOp( HYDROGUI_Module* theModule )
+: HYDROGUI_Operation( theModule )
+{
+  setName( tr( "IMPORT_POLYLINE" ) );
+}
+
+HYDROGUI_ImportPolylineOp::~HYDROGUI_ImportPolylineOp()
+{
+}
+
+void HYDROGUI_ImportPolylineOp::startOperation()
+{
+  HYDROGUI_Operation::startOperation();
+
+  myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
+  myFileDlg->setWindowTitle( getName() );
+  myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
+  myFileDlg->setFilter( tr("POLYLINE_FILTER") );
+
+  connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
+  connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
+
+  myFileDlg->exec();
+}
+
+void HYDROGUI_ImportPolylineOp::onApply()
+{
+  if ( !myFileDlg )
+  {
+    abort();
+    return;
+  }
+
+  QString aFileName = myFileDlg->selectedFile();
+  if ( aFileName.isEmpty() )
+  {
+    abort();
+    return;
+  }
+
+  QFile aFile (aFileName);
+  aFile.open(QIODevice::ReadOnly);
+
+  Parse(aFile);
+
+  QApplication::setOverrideCursor( Qt::WaitCursor );
+
+  startDocOperation();
+
+  Process();
+
+  commitDocOperation();
+  commit();
+
+  module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
+
+  aFile.close();
+
+  QApplication::restoreOverrideCursor();
+}
+
+void HYDROGUI_ImportPolylineOp::Process()
+{
+
+  Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) );
+
+  Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( doc()->CreateObject( KIND_POLYLINE ) );
+
+  Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( doc()->CreateObject( KIND_BATHYMETRY ) );;
+  HYDROData_Bathymetry::AltitudePoints aAPoints;
+
+  int aNSect = myCurveBlocks.size();
+  for ( int i = 0 ; i < aNSect ; i++ )
+  {
+    bool aSectClosure = true;
+    HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE; 
+    aPolylineXY->AddSection( TCollection_AsciiString(myCurveBlocks[i].myName.toStdString().c_str()), aSectType, myCurveBlocks[i].myIsClosed );
+
+    for ( int k = 0 ; k < myCurveBlocks[i].myXYZPoints.size() ; k+=3 )
+    {
+      HYDROData_PolylineXY::Point aSectPoint;
+      aSectPoint.SetX( myCurveBlocks[i].myXYZPoints[k].X() );
+      aSectPoint.SetY( myCurveBlocks[i].myXYZPoints[k].Y() );
+      aPolylineXY->AddPoint( i, aSectPoint );
+
+         aAPoints.Append(myCurveBlocks[i].myXYZPoints[k]);
+    }
+  }
+  aPolylineXY->SetName("P_XY");
+  aPolylineXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor());
+  aPolylineXY->Update();
+  
+  aBath->SetAltitudePoints(aAPoints);
+  aBath->SetName("P_B");
+
+  aPolylineObj->SetPolylineXY (aPolylineXY, false);
+  aPolylineObj->SetAltitudeObject(aBath);
+
+  aPolylineObj->SetBorderColor( HYDROData_Polyline3D::DefaultBorderColor() );
+  aPolylineObj->SetName("P_3D");
+  
+  aPolylineObj->Update();
+
+
+  size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
+  if ( anActiveViewId == 0 )
+    anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() );
+
+  module()->setObjectVisible( anActiveViewId, aPolylineXY, true );
+  module()->setObjectVisible( anActiveViewId, aPolylineObj, true );
+
+  module()->setIsToUpdate( aPolylineObj );
+}
+
+bool HYDROGUI_ImportPolylineOp::Parse( QFile& theFile)
+{
+  if ( !theFile.isOpen() )
+    return false;
+
+  QString aLine;
+  QString aBLine;
+  QStringList aList;
+  QStringList aBList;
+  myCurveBlocks.clear();
+  bool aTotStat = true;
+
+  aLine = theFile.readLine().simplified();
+  aList = aLine.split( ' ', QString::SkipEmptyParts );
+
+  for (;!theFile.atEnd();) 
+  {
+    if (aList[0] == "B" && (aList[1] == "C" || aList[1] == "P" || aList[1] == "N"))
+    {  
+      HYDROGUI_CurveBlock aCurveBlockInfo;
+      if (aList[1] == "C")
+        aCurveBlockInfo.myType = 1;
+      else if (aList[1] == "P")
+        aCurveBlockInfo.myType = 2;
+      else if (aList[1] == "N")
+        aCurveBlockInfo.myType = 2;
+
+      QString Name;
+      do
+      {
+        aBLine = theFile.readLine().simplified();
+        aBList = aBLine.split( ' ', QString::SkipEmptyParts );
+         
+        if (aBList[0] == "CP")
+        {
+          if (aBList.size() == 2 && (aBList[1] == "0" || aBList[1] == "1" || aBList[1] == "2"))
+            aCurveBlockInfo.myCurvePlane = aBList[1].toInt();
+          if (aBList.size() == 3 && (aBList[1] == "0" || aBList[1] == "1") && (aBList[2] == "0" || aBList[2] == "1"))
+          {
+            aCurveBlockInfo.myIsClosed = aBList[1].toInt();
+            aCurveBlockInfo.myIsClosed = aBList[2].toInt();
+          }
+        }
+        if (aBList[0] == "CN")
+        {
+           for (int i = 1; i < aBList.size(); i++)
+             Name += aBList[i] + "_"; 
+           Name.remove(Name.size() - 1, 1);
+           aCurveBlockInfo.myName = Name;
+        }
+      } while (!theFile.atEnd() && aBLine[0] == 'C' );
+
+      bool aStat;
+      aTotStat = true;
+      do
+      {
+        if (aBList.size() >= 3 && aBLine[0] != 'B' && aBLine[0] != 'C') {
+          gp_XYZ anXYZ;
+          anXYZ.SetX (aBList[0].toDouble(&aStat));  
+          aTotStat = aTotStat && aStat;
+          anXYZ.SetY (aBList[1].toDouble(&aStat));
+          aTotStat = aTotStat && aStat;
+          anXYZ.SetZ (aBList[2].toDouble(&aStat));
+          aTotStat = aTotStat && aStat;
+
+          aCurveBlockInfo.myXYZPoints.push_back(anXYZ);
+          
+          aBLine = theFile.readLine().simplified();
+          aBList = aBLine.split( ' ', QString::SkipEmptyParts );
+        }
+        else 
+          break;
+    
+      } while (!theFile.atEnd()/* && aBLine[0] == 'B'*/ );
+      if (aTotStat)
+        myCurveBlocks.push_back(aCurveBlockInfo);
+
+    }
+    else
+    {
+      aLine = theFile.readLine().simplified();
+      aList = aLine.split( ' ', QString::SkipEmptyParts );
+    }
+
+  }
+
+  return true;
+
+}
\ No newline at end of file
diff --git a/src/HYDROGUI/HYDROGUI_ImportPolylineOp.h b/src/HYDROGUI/HYDROGUI_ImportPolylineOp.h
new file mode 100644 (file)
index 0000000..4e7a066
--- /dev/null
@@ -0,0 +1,60 @@
+// 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
+//
+// 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, 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
+// 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
+//
+
+#ifndef HYDROGUI_IMPORTPOLYLINE_H
+#define HYDROGUI_IMPORTPOLYLINE_H
+
+#include "HYDROGUI_Operation.h"
+#include <vector>
+
+class SUIT_FileDlg;
+class QFile;
+class gp_XYZ;
+struct HYDROGUI_CurveBlock
+{
+  std::vector<gp_XYZ> myXYZPoints;
+  bool myType;
+  bool myIsConnected;
+  bool myIsClosed;
+  int myCurvePlane;
+  QString myName;
+};
+
+class HYDROGUI_ImportPolylineOp : public HYDROGUI_Operation
+{
+  Q_OBJECT
+
+public:
+  HYDROGUI_ImportPolylineOp( HYDROGUI_Module* theModule );
+  virtual ~HYDROGUI_ImportPolylineOp();
+
+protected:
+  virtual void startOperation();
+  virtual void onApply();
+  virtual void Process();
+  bool Parse( QFile&  theFile );
+private:
+  SUIT_FileDlg* myFileDlg;
+  std::vector<HYDROGUI_CurveBlock> myCurveBlocks;
+};
+
+#endif
index c51d90b675925d7a1916c358de575fe24f0d30df..2bef316e6167315c4a8a1dc96a7e34dcf44aa8eb 100644 (file)
@@ -31,6 +31,7 @@
 #include "HYDROGUI_DigueOp.h"
 #include "HYDROGUI_ExportImageOp.h"
 #include "HYDROGUI_ImportImageOp.h"
+#include "HYDROGUI_ImportPolylineOp.h"
 #include "HYDROGUI_ImportBathymetryOp.h"
 #include "HYDROGUI_ImmersibleZoneOp.h"
 #include "HYDROGUI_Module.h"
@@ -119,6 +120,8 @@ void HYDROGUI_Module::createActions()
   createAction( ObserveImageId, "OBSERVE_IMAGE", "OBSERVE_IMAGE_ICO" );
   createAction( ExportImageId, "EXPORT_IMAGE", "EXPORT_IMAGE_ICO" );
   createAction( RemoveImageRefsId, "REMOVE_IMAGE_REFERENCE", "REMOVE_IMAGE_REFERENCE_ICO" );
+  
+  createAction( ImportPolylineId, "IMPORT_POLYLINE" );
 
   createAction( CreatePolylineId, "CREATE_POLYLINE", "CREATE_POLYLINE_ICO" );
   createAction( EditPolylineId, "EDIT_POLYLINE", "EDIT_POLYLINE_ICO" ); 
@@ -186,6 +189,7 @@ void HYDROGUI_Module::createActions()
   createAction( RiverBottomId, "CREATE_STREAM_BOTTOM", "CREATE_STREAM_BOTTOM_ICO" );
   createAction( RiverBottomContextId, "CREATE_STREAM_BOTTOM", "CREATE_STREAM_BOTTOM_ICO" );
   createAction( ProfileInterpolateId, "PROFILE_INTERPOLATE", "PROFILE_INTERPOLATE_ICO" );
 }
 
 void HYDROGUI_Module::createMenus()
@@ -205,6 +209,7 @@ void HYDROGUI_Module::createMenus()
   int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
   int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
   createMenu( ImportImageId, aHydroId, -1, -1 );
+  createMenu( ImportPolylineId, aHydroId, -1, -1 );
   createMenu( ImportBathymetryId, aHydroId, -1, -1 );
   createMenu( CreatePolylineId, aHydroId, -1, -1 );
   createMenu( CreatePolyline3DId, aHydroId, -1, -1 );
@@ -249,6 +254,7 @@ void HYDROGUI_Module::createToolbars()
 
   createTool( separator(), aToolBar );
   createTool( ImportImageId, aToolBar );
+  createTool( ImportPolylineId, aToolBar );
   createTool( ImportBathymetryId, aToolBar );
   createTool( CreatePolylineId, aToolBar );
   createTool( CreatePolyline3DId, aToolBar );
@@ -401,6 +407,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
   case EditImportedImageId:
     anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
     break;
+  case ImportPolylineId:
+    anOp = new HYDROGUI_ImportPolylineOp( aModule/*, theId == EditImportedPolylineId*/ );
+    break;
   case ObserveImageId:
     anOp = new HYDROGUI_ObserveImageOp( aModule );
     break;
index 6c154564f98cc558f7de57203e39e88ac4d0f3ad..1d61da4577de97bfa6d2c0884c753d013e0e9633 100644 (file)
@@ -109,7 +109,11 @@ enum OperationId
 
   RiverBottomId,
   RiverBottomContextId,
-  ProfileInterpolateId
+  ProfileInterpolateId,
+
+  ImportPolylineId,
+  ExportPolylineId
+
 };
 
 #endif
index 9e3ffb0d4d44422fd709f88747f315138dcec46a..ba09b49d26780fa6292b7605a22bc288dc6b3872 100644 (file)
@@ -798,6 +798,10 @@ Would you like to remove all references from the image?</translation>
       <source>DSK_IMPORT_IMAGE</source>
       <translation>Import image</translation>
     </message>
+    <message>
+      <source>DSK_IMPORT_POLYLINE</source>
+      <translation>Import polyline from file(s)</translation>
+    </message>
     <message>
       <source>DSK_LOAD_VISUAL_STATE</source>
       <translation>Load visual state</translation>
@@ -1050,6 +1054,10 @@ Would you like to remove all references from the image?</translation>
       <source>MEN_IMPORT_IMAGE</source>
       <translation>Import image</translation>
     </message>
+    <message>
+      <source>MEN_IMPORT_POLYLINE</source>
+      <translation>Import polyline</translation>
+    </message>
     <message>
       <source>MEN_LOAD_VISUAL_STATE</source>
       <translation>Load visual state</translation>
@@ -1278,6 +1286,10 @@ Would you like to remove all references from the image?</translation>
       <source>STB_IMPORT_IMAGE</source>
       <translation>Import image</translation>
     </message>
+    <message>
+      <source>STB_IMPORT_POLYLINE</source>
+      <translation>Import polyline</translation>
+    </message>
     <message>
       <source>STB_LOAD_VISUAL_STATE</source>
       <translation>Load visual state</translation>
@@ -1875,6 +1887,34 @@ file cannot be correctly imported for an Obstacle definition.</translation>
 </translation>
     </message>
   </context>
+
+  <context>
+    <name>HYDROGUI_ImportPolylineOp</name>
+    <message>
+      <source>IMPORT_POLYLINE</source>
+      <translation>Import Polyline</translation>
+    </message>
+    <message>
+      <source>POLYLINE_FILTER</source>
+      <translation>SinusX Files (*.sx)</translation>
+    </message>
+    <message>
+      <source>BAD_IMPORTED_POLYLINE_FILES_TLT</source>
+      <translation>Polyline import error</translation>
+    </message>
+    <message>
+      <source>NO_ONE_POLYLINE_IMPORTED</source>
+      <translation>Polyline cannot be read from seleted file</translation>
+    </message>
+    <message>
+      <source>BAD_IMPORTED_POLYLINE_FILES</source>
+      <translation>The data from following files cannot be completely imported:
+%1
+</translation>
+    </message>
+
+  </context>
+
    
   <context>
     <name>HYDROGUI_GeoreferencementDlg</name>