X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_Obstacle.cxx;h=29b0a64c4a9e8505f6fe2acce5a707be77d6ee8e;hb=f86cf7ecf17dbae2a1d84e0ebbab07c732208c2f;hp=0a48be15c79f29510c0da3a164a361b5c7134160;hpb=b6156e45d774963f6c126415e9fb42d32d994bd5;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_Obstacle.cxx b/src/HYDROData/HYDROData_Obstacle.cxx index 0a48be15..29b0a64c 100644 --- a/src/HYDROData/HYDROData_Obstacle.cxx +++ b/src/HYDROData/HYDROData_Obstacle.cxx @@ -1,9 +1,40 @@ +// 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_Document.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 +#endif + +#ifdef WIN32 + #pragma warning ( default: 4251 ) +#endif #include #include @@ -15,32 +46,43 @@ #include +#include #include #include +#include #include +#include #include #include +#ifdef WIN32 + #pragma warning ( disable: 4251 ) +#endif + #include #include #include #include +#ifdef WIN32 + #pragma warning ( default: 4251 ) +#endif + #include // CAREFUL ! position of this file is critic #include -#define PYTHON_OBSTACLE_ID "KIND_OBSTACLE" +#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" -IMPLEMENT_STANDARD_HANDLE(HYDROData_Obstacle,HYDROData_ArtificialObject) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Obstacle,HYDROData_ArtificialObject) HYDROData_Obstacle::HYDROData_Obstacle() -: HYDROData_ArtificialObject() +: HYDROData_ArtificialObject( Geom_3d ) { } @@ -48,58 +90,85 @@ HYDROData_Obstacle::~HYDROData_Obstacle() { } -QStringList HYDROData_Obstacle::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_Obstacle::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { - QStringList aResList; - - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); - if ( aDocument.IsNull() ) - return aResList; + QStringList aResList = dumpObjectCreation( theTreatedObjects ); + + QString anObstacleName = GetObjPyName(); + + TCollection_AsciiString aGeomObjectEntry = GetGeomObjectEntry(); + QString aFilePath = GetFilePath(); + + if ( !aGeomObjectEntry.IsEmpty() ) + { + QString aSalomeObjName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "obstacle_sobj" ); + // 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( "" ); + } - QString aDocName = aDocument->GetDocPyName(); - QString anObstacleName = GetName(); + // 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 = %2.CreateObject( %3 );" ) - .arg( anObstacleName ).arg( aDocName ).arg( PYTHON_OBSTACLE_ID ); - aResList << QString( "%1.SetName( \"%2\" );" ) - .arg( anObstacleName ).arg( anObstacleName ); + aResList << QString( "%1.Update()" ).arg( anObstacleName ); aResList << QString( "" ); - // TODO - return aResList; } -TopoDS_Shape HYDROData_Obstacle::GetTopShape() const +void HYDROData_Obstacle::Update() { - // TODO - return getTopShape(); -} + RemoveGroupObjects(); + createGroupObjects(); + checkAndSetAltitudeObject(); -TopoDS_Shape HYDROData_Obstacle::GetShape3D() const -{ - // TODO - return getShape3D(); + HYDROData_Entity::Update(); } -QColor HYDROData_Obstacle::DefaultFillingColor() +bool HYDROData_Obstacle::IsHas2dPrs() const { - return QColor( Qt::yellow ); + return true; } -QColor HYDROData_Obstacle::DefaultBorderColor() +void HYDROData_Obstacle::SetShape3D( const TopoDS_Shape& theShape ) { - return QColor( Qt::transparent ); + TopoDS_Face aShape2d = HYDROData_Projection::MakeProjection( theShape ); + HYDROData_ArtificialObject::SetShape3D( theShape ); + HYDROData_ArtificialObject::SetTopShape( aShape2d ); } -QColor HYDROData_Obstacle::getDefaultFillingColor() const +QColor HYDROData_Obstacle::DefaultFillingColor() const { - return DefaultFillingColor(); + return QColor( Qt::yellow ); } -QColor HYDROData_Obstacle::getDefaultBorderColor() const +QColor HYDROData_Obstacle::DefaultBorderColor() const { - return DefaultBorderColor(); + return QColor( Qt::transparent ); } bool HYDROData_Obstacle::ImportFromFile( const QString& theFilePath ) @@ -145,30 +214,101 @@ QString HYDROData_Obstacle::GetFilePath() const { QString aRes; - Handle(TDataStd_AsciiString) anAsciiStr; - if ( myLab.FindChild( DataTag_FilePath ).FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) ) - aRes = QString( anAsciiStr->Get().ToCString() ); + TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false ); + if ( !aLabel.IsNull() ) + { + Handle(TDataStd_AsciiString) anAsciiStr; + if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) ) + aRes = QString( anAsciiStr->Get().ToCString() ); + } + + return aRes; +} + +bool HYDROData_Obstacle::ImportFromGeomIOR( const TCollection_AsciiString& theIOR ) +{ + bool aRes = false; + +#ifndef LIGHT_MODE + 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; + } +#endif return aRes; } -void HYDROData_Obstacle::SetGeomObjectEntry( const QString& theEntry ) +void HYDROData_Obstacle::SetGeomObjectEntry( const TCollection_AsciiString& theEntry ) { - TCollection_AsciiString anAsciiStr( theEntry.toStdString().c_str() ); - TDataStd_AsciiString::Set( myLab.FindChild( DataTag_GeomObjectEntry ), anAsciiStr ); + TDataStd_AsciiString::Set( myLab.FindChild( DataTag_GeomObjectEntry ), theEntry ); } -QString HYDROData_Obstacle::GetGeomObjectEntry() const +TCollection_AsciiString HYDROData_Obstacle::GetGeomObjectEntry() const { - QString aRes; + 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 = 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; + } - Handle(TDataStd_AsciiString) anAsciiStr; - if ( myLab.FindChild( DataTag_GeomObjectEntry ).FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) ) - aRes = QString( anAsciiStr->Get().ToCString() ); +#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 ) +{ + 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; @@ -183,6 +323,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; @@ -217,6 +358,7 @@ TopoDS_Shape HYDROData_Obstacle::ImportIGES( const QString& theFilePath ) const catch(Standard_Failure) { aResShape.Nullify(); } +#endif return aResShape; } @@ -225,6 +367,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; @@ -328,13 +471,81 @@ TopoDS_Shape HYDROData_Obstacle::ImportSTEP( const QString& theFilePath ) const catch (Standard_Failure) { aResShape.Nullify(); } +#endif return aResShape; } -void HYDROData_Obstacle::SetShape3D( const TopoDS_Shape& theShape ) +ObjectKind HYDROData_Obstacle::getAltitudeObjectType() const { - TopoDS_Face aShape2d = HYDROData_Projection::MakeProjection( theShape ); - HYDROData_ArtificialObject::SetShape3D( theShape ); - HYDROData_ArtificialObject::SetTopShape( aShape2d ); + DEBTRACE("HYDROData_Obstacle::getAltitudeObjectType"); + return KIND_OBSTACLE_ALTITUDE; +} + +void HYDROData_Obstacle::createGroupObjects() +{ + TopoDS_Shape anObstacleShape = GetTopShape(); + if ( !anObstacleShape.IsNull() ) + { + TopTools_SequenceOfShape aWireEdges; + HYDROData_ShapesTool::ExploreShapeToShapes( anObstacleShape, TopAbs_EDGE, aWireEdges ); + if ( !aWireEdges.IsEmpty() ) + { + QString aWireGroupName = GetName() + "_Outer_Wire"; + + Handle(HYDROData_ShapesGroup) anExtWireGroup = createGroupObject(); + anExtWireGroup->SetName( aWireGroupName ); + + anExtWireGroup->SetShapes( aWireEdges ); + } + } +} + +void HYDROData_Obstacle::setTranslation( const double theDx, + const double theDy, + const double theDz ) +{ + 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 ); +} +