Salome HOME
global misprinting in the word "splitted" is replaced by "split"
[modules/hydro.git] / src / HYDROData / HYDROData_Obstacle.cxx
index 5a108d6ed36a968f714cbce20954af2ecf0390ba..9c738a117a80ee24fe011b18b5bf39cd68b5e196 100644 (file)
@@ -1,3 +1,20 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// 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"
 
+#ifdef WIN32
+  #pragma warning ( disable: 4251 )
+#endif
+
+#ifndef LIGHT_MODE
 #include <Basics_Utils.hxx>
+#endif
+
+#ifdef WIN32
+  #pragma warning ( default: 4251 )
+#endif
 
 #include <BRepTools.hxx>
 #include <BRep_Builder.hxx>
 
-#include <GEOMBase.h>
-
 #include <IGESControl_Reader.hxx>
 #include <IGESData_IGESModel.hxx>
 
 
 #include <TopExp_Explorer.hxx>
 
+#ifdef WIN32
+  #pragma warning ( disable: 4251 )
+#endif
+
 #include <QColor>
 #include <QFile>
 #include <QFileInfo>
 #include <QStringList>
 
+#ifdef WIN32
+  #pragma warning ( default: 4251 )
+#endif
+
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic
 
 #include <HYDROData_Projection.h>
@@ -46,7 +80,7 @@ IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Obstacle,HYDROData_ArtificialObject)
 
 
 HYDROData_Obstacle::HYDROData_Obstacle()
-: HYDROData_ArtificialObject()
+: HYDROData_ArtificialObject( Geom_3d )
 {
 }
 
@@ -54,7 +88,8 @@ HYDROData_Obstacle::~HYDROData_Obstacle()
 {
 }
 
-QStringList HYDROData_Obstacle::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+QStringList HYDROData_Obstacle::DumpToPython( const QString&       thePyScriptPath,
+                                              MapOfTreatedObjects& theTreatedObjects ) const
 {
   QStringList aResList = dumpObjectCreation( theTreatedObjects );
   
@@ -66,14 +101,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() )
@@ -100,21 +140,16 @@ QStringList HYDROData_Obstacle::DumpToPython( MapOfTreatedObjects& theTreatedObj
 
 void HYDROData_Obstacle::Update()
 {
-  removeGroupObjects();
+  RemoveGroupObjects();
   createGroupObjects();
   checkAndSetAltitudeObject();
 
   HYDROData_Entity::Update();
 }
 
-TopoDS_Shape HYDROData_Obstacle::GetTopShape() const
-{
-  return getTopShape();
-}
-
-TopoDS_Shape HYDROData_Obstacle::GetShape3D() const
+bool HYDROData_Obstacle::IsHas2dPrs() const
 {
-  return getShape3D();
+  return true;
 }
 
 void HYDROData_Obstacle::SetShape3D( const TopoDS_Shape& theShape )
@@ -124,12 +159,12 @@ void HYDROData_Obstacle::SetShape3D( const TopoDS_Shape& theShape )
   HYDROData_ArtificialObject::SetTopShape( aShape2d );
 }
 
-QColor HYDROData_Obstacle::DefaultFillingColor()
+QColor HYDROData_Obstacle::DefaultFillingColor() const
 {
   return QColor( Qt::yellow );
 }
 
-QColor HYDROData_Obstacle::DefaultBorderColor()
+QColor HYDROData_Obstacle::DefaultBorderColor() const
 {
   return QColor( Qt::transparent );
 }
@@ -190,16 +225,28 @@ QString HYDROData_Obstacle::GetFilePath() const
 
 bool HYDROData_Obstacle::ImportFromGeomIOR( const TCollection_AsciiString& theIOR )
 {
-  if ( theIOR.IsEmpty() )
-    return false;
-
-  TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() );
-  if ( aShape.IsNull() )
-    return false;
+  bool aRes = false;
 
-  SetShape3D( aShape );
+#ifndef LIGHT_MODE
+  if ( theIOR.IsEmpty() ) {
+    return aRes;
+  }
   
-  return true;
+  int aDocId = -1;
+  if ( !HYDROData_Document::DocumentId( HYDROData_Document::Document( myLab ), aDocId ) || aDocId < 0 ) {
+    return aRes;
+  }
+
+  // TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() );
+  TopoDS_Shape aShape = HYDROData_GeomTool::GetShapeFromIOR( aDocId, theIOR.ToCString() );
+
+  if ( !aShape.IsNull() ) {
+    SetShape3D( aShape );
+    aRes = true;
+  }
+#endif
+
+  return aRes;
 }
 
 void HYDROData_Obstacle::SetGeomObjectEntry( const TCollection_AsciiString& theEntry )
@@ -222,6 +269,29 @@ 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;
+  }
+
+#ifndef LIGHT_MODE
+  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() );
+    }
+  }
+#endif
+  return aRes;
+}
+
 void HYDROData_Obstacle::Translate( const double theDx,
                                     const double theDy,
                                     const double theDz )
@@ -251,6 +321,7 @@ TopoDS_Shape HYDROData_Obstacle::ImportIGES( const QString& theFilePath ) const
 {
   TopoDS_Shape aResShape;
 
+#ifndef LIGHT_MODE
   // Set "C" numeric locale to save numbers correctly
   Kernel_Utils::Localizer loc;
 
@@ -285,6 +356,7 @@ TopoDS_Shape HYDROData_Obstacle::ImportIGES( const QString& theFilePath ) const
   catch(Standard_Failure) {
     aResShape.Nullify();
   }
+#endif
 
   return aResShape;
 }
@@ -293,6 +365,7 @@ TopoDS_Shape HYDROData_Obstacle::ImportSTEP( const QString& theFilePath ) const
 {
   TopoDS_Shape aResShape;
 
+#ifndef LIGHT_MODE
   // Set "C" numeric locale to save numbers correctly
   Kernel_Utils::Localizer loc;
 
@@ -396,20 +469,11 @@ TopoDS_Shape HYDROData_Obstacle::ImportSTEP( const QString& theFilePath ) const
   catch (Standard_Failure) {
     aResShape.Nullify();
   }
+#endif
 
   return aResShape;
 }
 
-QColor HYDROData_Obstacle::getDefaultFillingColor() const
-{
-  return DefaultFillingColor();
-}
-
-QColor HYDROData_Obstacle::getDefaultBorderColor() const
-{
-  return DefaultBorderColor();
-}
-
 ObjectKind HYDROData_Obstacle::getAltitudeObjectType() const
 {
   return KIND_OBSTACLE_ALTITUDE;
@@ -477,3 +541,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 );
+}
+