Salome HOME
compilation on Linux
[modules/hydro.git] / src / HYDROData / HYDROData_Obstacle.cxx
index 4dfae8672fad9e58e82e208ab9255230e52479db..f9e53b44a4060f48cce2d0fbb5f68d48624dff25 100644 (file)
@@ -1,3 +1,24 @@
+// 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 "HYDROData_Obstacle.h"
 
 #include "HYDROData_ShapesGroup.h"
 #include "HYDROData_ShapesTool.h"
 #include "HYDROData_Tool.h"
+#include "HYDROData_GeomTool.h"
 
 #include <Basics_Utils.hxx>
 
 #include <BRepTools.hxx>
 #include <BRep_Builder.hxx>
 
-#include <GEOMBase.h>
-
 #include <IGESControl_Reader.hxx>
 #include <IGESData_IGESModel.hxx>
 
@@ -66,14 +86,19 @@ QStringList HYDROData_Obstacle::DumpToPython( MapOfTreatedObjects& theTreatedObj
   if ( !aGeomObjectEntry.IsEmpty() )
   {
     QString aSalomeObjName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "obstacle_sobj" );
-    aResList << QString( "%1 = theStudy.FindObjectID( \"%2\" );" )
-                .arg( aSalomeObjName ).arg( aGeomObjectEntry.ToCString() );
-
-    aResList << QString( "%1.ImportFromGeomIOR( %2.GetIOR() );" )
-                .arg( anObstacleName ).arg( aSalomeObjName );
-
-    aResList << QString( "%1.SetGeomObjectEntry( \"%2\" );" )
-                .arg( anObstacleName ).arg( aGeomObjectEntry.ToCString() );
+    // aResList << QString( "%1 = theStudy.FindObjectID( \"%2\" );" )
+    //            .arg( aSalomeObjName ).arg( aGeomObjectEntry.ToCString() );
+    QString aGeomObjectName( GetGeomObjectName().ToCString() );
+    if ( !aGeomObjectName.isEmpty() ) {
+      aResList << QString( "%1 = theStudy.FindObjectByName( \"%2\", \"GEOM\" )[0];" )
+                  .arg( aSalomeObjName ).arg( aGeomObjectName );
+
+      aResList << QString( "%1.ImportFromGeomIOR( %2.GetIOR() );" )
+                  .arg( anObstacleName ).arg( aSalomeObjName );
+
+      aResList << QString( "%1.SetGeomObjectEntry( %2.GetID() );" )
+                  .arg( anObstacleName ).arg( aSalomeObjName );
+    }
     aResList << QString( "" );
   }
   else if ( !aFilePath.isEmpty() )
@@ -195,16 +220,26 @@ QString HYDROData_Obstacle::GetFilePath() const
 
 bool HYDROData_Obstacle::ImportFromGeomIOR( const TCollection_AsciiString& theIOR )
 {
-  if ( theIOR.IsEmpty() )
-    return false;
+  bool aRes = false;
 
-  TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() );
-  if ( aShape.IsNull() )
-    return false;
+  if ( theIOR.IsEmpty() ) {
+    return aRes;
+  }
+  
+  int aDocId = -1;
+  if ( !HYDROData_Document::DocumentId( HYDROData_Document::Document( myLab ), aDocId ) || aDocId < 0 ) {
+    return aRes;
+  }
 
-  SetShape3D( aShape );
+  // TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() );
+  TopoDS_Shape aShape = HYDROData_GeomTool::GetShapeFromIOR( aDocId, theIOR.ToCString() );
+
+  if ( !aShape.IsNull() ) {
+    SetShape3D( aShape );
+    aRes = true;
+  }
   
-  return true;
+  return aRes;
 }
 
 void HYDROData_Obstacle::SetGeomObjectEntry( const TCollection_AsciiString& theEntry )
@@ -227,6 +262,28 @@ TCollection_AsciiString HYDROData_Obstacle::GetGeomObjectEntry() const
   return aRes;
 }
 
+TCollection_AsciiString HYDROData_Obstacle::GetGeomObjectName() const
+{
+  TCollection_AsciiString aRes;
+
+  int aDocId = -1;
+  if ( !HYDROData_Document::DocumentId( HYDROData_Document::Document( myLab ), aDocId ) || aDocId < 0 ) {
+    return aRes;
+  }
+
+  SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( aDocId );
+
+  if ( !aDSStudy->_is_nil() ) {
+    TCollection_AsciiString anEntry = GetGeomObjectEntry();
+    SALOMEDS::SObject_var aSObject = aDSStudy->FindObjectID( anEntry.ToCString() );
+    if ( !aSObject->_is_nil() ) {
+      aRes = TCollection_AsciiString( aSObject->GetName() );
+    }
+  }
+
+  return aRes;
+}
+
 void HYDROData_Obstacle::Translate( const double theDx,
                                     const double theDy,
                                     const double theDz )
@@ -482,3 +539,8 @@ bool HYDROData_Obstacle::getTranslation( double& theDx, double& theDy, double& t
   return true;
 }
 
+void HYDROData_Obstacle::UpdateLocalCS( double theDx, double theDy )
+{
+  Translate( theDx, theDy, 0 );
+}
+