X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_Obstacle.cxx;h=f9e53b44a4060f48cce2d0fbb5f68d48624dff25;hb=9c3749501bcf6c4eed78966cb69934bab0a1a3b9;hp=6a4cb6357e132c7ac79a5a61736174daeaa2b7fb;hpb=97e331dedb6c4a834944e0c47e44e8d7e258edd4;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_Obstacle.cxx b/src/HYDROData/HYDROData_Obstacle.cxx index 6a4cb635..f9e53b44 100644 --- a/src/HYDROData/HYDROData_Obstacle.cxx +++ b/src/HYDROData/HYDROData_Obstacle.cxx @@ -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" @@ -5,14 +26,13 @@ #include "HYDROData_ShapesGroup.h" #include "HYDROData_ShapesTool.h" #include "HYDROData_Tool.h" +#include "HYDROData_GeomTool.h" #include #include #include -#include - #include #include @@ -26,6 +46,7 @@ #include #include +#include #include @@ -59,25 +80,42 @@ QStringList HYDROData_Obstacle::DumpToPython( MapOfTreatedObjects& theTreatedObj QString anObstacleName = GetObjPyName(); - QString aGeomObjectEntry = GetGeomObjectEntry(); + TCollection_AsciiString aGeomObjectEntry = GetGeomObjectEntry(); QString aFilePath = GetFilePath(); - if ( !aGeomObjectEntry.isEmpty() ) + if ( !aGeomObjectEntry.IsEmpty() ) { QString aSalomeObjName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "obstacle_sobj" ); - aResList << QString( "%1 = salome.sg.IDToObject( \"%2\" );" ) - .arg( aSalomeObjName ).arg( aGeomObjectEntry ); - - aResList << QString( "%1.ImportFromGeomIOR( %2.GetIOR() );" ) - .arg( anObstacleName ).arg( aSalomeObjName ); + // 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() ) { aResList << QString( "%1.ImportFromFile( \"%2\" );" ) .arg( anObstacleName ).arg( aFilePath ); + aResList << QString( "" ); } - aResList << QString( "" ); + // Write the translation points + double aDx, aDy, aDz; + if ( getTranslation( aDx, aDy, aDz ) ) + { + aResList << QString( "%1.Translate( %2, %3, %4 );" ) + .arg( anObstacleName ).arg( aDx ).arg( aDy ).arg( aDz ); + aResList << QString( "" ); + } aResList << QString( "%1.Update();" ).arg( anObstacleName ); aResList << QString( "" ); @@ -94,6 +132,11 @@ void HYDROData_Obstacle::Update() HYDROData_Entity::Update(); } +bool HYDROData_Obstacle::IsHas2dPrs() const +{ + return true; +} + TopoDS_Shape HYDROData_Obstacle::GetTopShape() const { return getTopShape(); @@ -154,18 +197,6 @@ bool HYDROData_Obstacle::ImportFromFile( const QString& theFilePath ) return aRes; } -bool HYDROData_Obstacle::ImportFromGeomIOR( const QString& theIOR ) -{ - TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR ); - if ( aShape.IsNull() ) - return false; - - SetShape3D( aShape ); - SetGeomObjectEntry( theIOR ); - - return true; -} - void HYDROData_Obstacle::SetFilePath( const QString& theFilePath ) { TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() ); @@ -187,27 +218,87 @@ QString HYDROData_Obstacle::GetFilePath() const return aRes; } -void HYDROData_Obstacle::SetGeomObjectEntry( const QString& theEntry ) +bool HYDROData_Obstacle::ImportFromGeomIOR( const TCollection_AsciiString& theIOR ) { - TCollection_AsciiString anAsciiStr( theEntry.toStdString().c_str() ); - TDataStd_AsciiString::Set( myLab.FindChild( DataTag_GeomObjectEntry ), anAsciiStr ); + bool aRes = false; + + if ( theIOR.IsEmpty() ) { + return aRes; + } + + 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; + } + + return aRes; } -QString HYDROData_Obstacle::GetGeomObjectEntry() const +void HYDROData_Obstacle::SetGeomObjectEntry( const TCollection_AsciiString& theEntry ) { - QString aRes; + TDataStd_AsciiString::Set( myLab.FindChild( DataTag_GeomObjectEntry ), theEntry ); +} + +TCollection_AsciiString HYDROData_Obstacle::GetGeomObjectEntry() const +{ + TCollection_AsciiString aRes; TDF_Label aLabel = myLab.FindChild( DataTag_GeomObjectEntry, false ); if ( !aLabel.IsNull() ) { Handle(TDataStd_AsciiString) anAsciiStr; if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) ) - aRes = QString( anAsciiStr->Get().ToCString() ); + aRes = anAsciiStr->Get(); } 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 ) +{ + TopoDS_Shape aShape3D = GetShape3D(); + + TopoDS_Shape aTranslatedShape3D = HYDROData_ShapesTool::Translated( aShape3D, theDx, theDy, theDz ); + if ( aTranslatedShape3D.IsNull() ) + return; + + SetShape3D( aTranslatedShape3D ); + + setTranslation( theDx, theDy, theDz ); +} + TopoDS_Shape HYDROData_Obstacle::ImportBREP( const QString& theFilePath ) const { TopoDS_Shape aResShape; @@ -381,6 +472,11 @@ QColor HYDROData_Obstacle::getDefaultBorderColor() const return DefaultBorderColor(); } +ObjectKind HYDROData_Obstacle::getAltitudeObjectType() const +{ + return KIND_OBSTACLE_ALTITUDE; +} + void HYDROData_Obstacle::createGroupObjects() { TopoDS_Shape anObstacleShape = GetTopShape(); @@ -400,10 +496,51 @@ void HYDROData_Obstacle::createGroupObjects() } } -ObjectKind HYDROData_Obstacle::getAltitudeObjectType() const +void HYDROData_Obstacle::setTranslation( const double theDx, + const double theDy, + const double theDz ) { - return KIND_OBSTACLE_ALTITUDE; + TDF_Label aLabel = myLab.FindChild( DataTag_Translation ); + + double aCurDx = theDx; + double aCurDy = theDy; + double aCurDz = theDz; + + double aPrevDx, aPrevDy, aPrevDz; + if ( getTranslation( aPrevDx, aPrevDy, aPrevDz ) ) + { + aCurDx += aPrevDx; + aCurDy += aPrevDy; + aCurDz += aPrevDz; + } + + Handle(TDataStd_RealArray) aCoeffsArray = TDataStd_RealArray::Set( aLabel, 1, 3 ); + aCoeffsArray->SetValue( 1, aCurDx ); + aCoeffsArray->SetValue( 2, aCurDy ); + aCoeffsArray->SetValue( 3, aCurDz ); } +bool HYDROData_Obstacle::getTranslation( double& theDx, double& theDy, double& theDz ) const +{ + theDx = theDy = theDz = 0.0; + + TDF_Label aLabel = myLab.FindChild( DataTag_Translation, false ); + if ( aLabel.IsNull() ) + return false; + + Handle(TDataStd_RealArray) aCoeffsArray; + if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aCoeffsArray ) ) + return false; + theDx = aCoeffsArray->Value( 1 ); + theDy = aCoeffsArray->Value( 2 ); + theDz = aCoeffsArray->Value( 3 ); + + return true; +} + +void HYDROData_Obstacle::UpdateLocalCS( double theDx, double theDy ) +{ + Translate( theDx, theDy, 0 ); +}