From: adv Date: Mon, 20 Jan 2014 06:57:43 +0000 (+0000) Subject: Import of geom curve. X-Git-Tag: BR_hydro_v_1_0~61 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e5123a9d71157c50c9f1c6f68bccdfadc49f2360;p=modules%2Fhydro.git Import of geom curve. --- diff --git a/src/HYDROData/HYDROData_Obstacle.cxx b/src/HYDROData/HYDROData_Obstacle.cxx index 6a4cb635..560d91e1 100644 --- a/src/HYDROData/HYDROData_Obstacle.cxx +++ b/src/HYDROData/HYDROData_Obstacle.cxx @@ -59,17 +59,20 @@ 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 = salome.myStudy.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() ); } else if ( !aFilePath.isEmpty() ) { @@ -154,18 +157,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,22 +178,35 @@ 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 ); + if ( theIOR.IsEmpty() ) + return false; + + TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() ); + if ( aShape.IsNull() ) + return false; + + SetShape3D( aShape ); + + return true; } -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; diff --git a/src/HYDROData/HYDROData_Obstacle.h b/src/HYDROData/HYDROData_Obstacle.h index 194dae8b..2e38854b 100644 --- a/src/HYDROData/HYDROData_Obstacle.h +++ b/src/HYDROData/HYDROData_Obstacle.h @@ -83,13 +83,6 @@ public: */ HYDRODATA_EXPORT virtual bool ImportFromFile( const QString& theFilePath ); - /** - * Imports shape from IOR. - * \param theIOR the IOR of Geom object - * \return \c true if shape has been successfully imported - */ - HYDRODATA_EXPORT virtual bool ImportFromGeomIOR( const QString& theIOR ); - /** * Stores the file path of the imported file. * \param theFilePath file path @@ -101,16 +94,24 @@ public: */ HYDRODATA_EXPORT QString GetFilePath() const; - /** + + /** + * Imports shape from IOR. + * \param theIOR the IOR of Geom object + * \return \c true if shape has been successfully imported + */ + HYDRODATA_EXPORT virtual bool ImportFromGeomIOR( const TCollection_AsciiString& theIOR ); + + /** * Stores the study entry of the imported GEOM object. * \param theEntry GEOM object entry */ - HYDRODATA_EXPORT void SetGeomObjectEntry( const QString& theEntry ); + HYDRODATA_EXPORT void SetGeomObjectEntry( const TCollection_AsciiString& theEntry ); /** * Returns the imported GEOM object entry. */ - HYDRODATA_EXPORT QString GetGeomObjectEntry() const; + HYDRODATA_EXPORT TCollection_AsciiString GetGeomObjectEntry() const; protected: diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index cdbc3752..d40212e2 100755 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -13,6 +13,8 @@ #include #include +#include + #include #include #include @@ -36,6 +38,7 @@ #include +#include #include #include #include @@ -121,31 +124,51 @@ QStringList HYDROData_PolylineXY::DumpToPython( MapOfTreatedObjects& theTreatedO aResList << QString( "" ); } - // Set polilyne data - NCollection_Sequence aSectNames; - NCollection_Sequence aSectTypes; - NCollection_Sequence aSectClosures; - GetSections( aSectNames, aSectTypes, aSectClosures ); - - for ( int i = 1, n = aSectNames.Size(); i <= n; ++i ) + bool anIsEditable = IsEditable(); + if ( !anIsEditable ) { - const TCollection_AsciiString& aSectName = aSectNames.Value( i ); - const SectionType& aSectType = aSectTypes.Value( i ); - bool aSectClosure = aSectClosures.Value( i ); + // If polyline is not editable we try to import the shape from geom + TCollection_AsciiString aGeomObjectEntry = GetGeomObjectEntry(); + if ( !aGeomObjectEntry.IsEmpty() ) + { + QString aSalomeObjName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "polyline_sobj" ); + aResList << QString( "%1 = salome.myStudy.FindObjectID( \"%2\" );" ) + .arg( aSalomeObjName ).arg( aGeomObjectEntry.ToCString() ); - aResList << QString( "%1.AddSection( \"%2\", %3, %4 );" ).arg( aPolylineName ) - .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure ); + aResList << QString( "%1.ImportFromGeomIOR( %2.GetIOR() );" ) + .arg( aPolylineName ).arg( aSalomeObjName ); - HYDROData_IPolyline::PointsList aSectPointsList = GetPoints( i - 1 ); - for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k ) + aResList << QString( "%1.SetGeomObjectEntry( \"%2\" );" ) + .arg( aPolylineName ).arg( aGeomObjectEntry.ToCString() ); + } + } + else + { + // Set polilyne data + NCollection_Sequence aSectNames; + NCollection_Sequence aSectTypes; + NCollection_Sequence aSectClosures; + GetSections( aSectNames, aSectTypes, aSectClosures ); + + for ( int i = 1, n = aSectNames.Size(); i <= n; ++i ) { - const Point& aSectPoint = aSectPointsList.Value( k ); + const TCollection_AsciiString& aSectName = aSectNames.Value( i ); + const SectionType& aSectType = aSectTypes.Value( i ); + bool aSectClosure = aSectClosures.Value( i ); + + aResList << QString( "%1.AddSection( \"%2\", %3, %4 );" ).arg( aPolylineName ) + .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure ); - aResList << QString( "%1.AddPoint( %2, gp_XY( %3, %4 ) );" ).arg( aPolylineName ) - .arg( i - 1 ).arg( aSectPoint.X() ).arg( aSectPoint.Y() ); + HYDROData_IPolyline::PointsList aSectPointsList = GetPoints( i - 1 ); + for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k ) + { + const Point& aSectPoint = aSectPointsList.Value( k ); + + aResList << QString( "%1.AddPoint( %2, gp_XY( %3, %4 ) );" ).arg( aPolylineName ) + .arg( i - 1 ).arg( aSectPoint.X() ).arg( aSectPoint.Y() ); + } } } - aResList << QString( "" ); aResList << QString( "%1.Update();" ).arg( aPolylineName ); aResList << QString( "" ); @@ -168,6 +191,38 @@ QColor HYDROData_PolylineXY::DefaultWireColor() return QColor( Qt::red ); } +bool HYDROData_PolylineXY::ImportFromGeomIOR( const TCollection_AsciiString& theIOR ) +{ + if ( theIOR.IsEmpty() ) + return false; + + TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() ); + if ( aShape.IsNull() ) + return false; + + return ImportShape( aShape ); +} + +void HYDROData_PolylineXY::SetGeomObjectEntry( const TCollection_AsciiString& theEntry ) +{ + TDataStd_AsciiString::Set( myLab.FindChild( DataTag_GeomObjectEntry ), theEntry ); +} + +TCollection_AsciiString HYDROData_PolylineXY::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 = anAsciiStr->Get(); + } + + return aRes; +} + TopoDS_Shape HYDROData_PolylineXY::GetShape() const { return getPolylineShape(); diff --git a/src/HYDROData/HYDROData_PolylineXY.h b/src/HYDROData/HYDROData_PolylineXY.h index 32732b08..ccbdaba6 100644 --- a/src/HYDROData/HYDROData_PolylineXY.h +++ b/src/HYDROData/HYDROData_PolylineXY.h @@ -23,6 +23,7 @@ protected: enum DataTag { DataTag_First = HYDROData_IPolyline::DataTag_First + 100, ///< first tag, to reserve + DataTag_GeomObjectEntry, ///< study entry of the imported GEOM object }; public: @@ -67,6 +68,26 @@ public: const bool& theIsClosed, const NCollection_Sequence& thePoints ); +public: + + /** + * Imports shape from IOR. + * \param theIOR the IOR of Geom object + * \return \c true if shape has been successfully imported + */ + HYDRODATA_EXPORT virtual bool ImportFromGeomIOR( const TCollection_AsciiString& theIOR ); + + /** + * Stores the study entry of the imported GEOM object. + * \param theEntry GEOM object entry + */ + HYDRODATA_EXPORT void SetGeomObjectEntry( const TCollection_AsciiString& theEntry ); + + /** + * Returns the imported GEOM object entry. + */ + HYDRODATA_EXPORT TCollection_AsciiString GetGeomObjectEntry() const; + public: /** diff --git a/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx b/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx index 60b0384b..c27ebb93 100644 --- a/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx @@ -215,11 +215,12 @@ bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags, Handle(HYDROData_Obstacle) anObstacle = Handle(HYDROData_Obstacle)::DownCast( anObject ); anObstacle->SetFillingColor( HYDROData_Obstacle::DefaultFillingColor() ); anObstacle->SetBorderColor( HYDROData_Obstacle::DefaultBorderColor() ); - anObstacle->SetGeomObjectEntry( anEntry ); + anObstacle->SetGeomObjectEntry( anEntry.toLatin1().constData() ); } else if ( myOpType == ImportSelectedAsPolyline ) { anObject = doc()->CreateObject( KIND_POLYLINEXY ); Handle(HYDROData_PolylineXY) aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anObject ); aPolylineObj->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() ); + aPolylineObj->SetGeomObjectEntry( anEntry.toLatin1().constData() ); } } else { anObject = anObjectToEdit; diff --git a/src/HYDROPy/HYDROData_Obstacle.sip b/src/HYDROPy/HYDROData_Obstacle.sip index ca3e321c..14cce6d6 100644 --- a/src/HYDROPy/HYDROData_Obstacle.sip +++ b/src/HYDROPy/HYDROData_Obstacle.sip @@ -57,13 +57,6 @@ public: bool ImportFromFile( const QString& theFilePath ); - /** - * Imports shape from IOR. - * \param theIOR the IOR of Geom object - * \return \c true if shape has been successfully imported - */ - bool ImportFromGeomIOR( const QString& theIOR ); - /** * Stores the file path of the imported file. * \param theFilePath file path @@ -75,16 +68,27 @@ public: */ QString GetFilePath() const; - /** + +public: + + /** + * Imports shape from IOR. + * \param theIOR the IOR of Geom object + * \return \c true if shape has been successfully imported + */ + bool ImportFromGeomIOR( const TCollection_AsciiString& theIOR ); + + /** * Stores the study entry of the imported GEOM object. * \param theEntry GEOM object entry */ - void SetGeomObjectEntry(const QString& theEntry); + void SetGeomObjectEntry( const TCollection_AsciiString& theEntry ); /** * Returns the imported GEOM object entry. */ - QString GetGeomObjectEntry() const; + TCollection_AsciiString GetGeomObjectEntry() const; + protected: diff --git a/src/HYDROPy/HYDROData_PolylineXY.sip b/src/HYDROPy/HYDROData_PolylineXY.sip index 4286dee3..e1aea5d3 100644 --- a/src/HYDROPy/HYDROData_PolylineXY.sip +++ b/src/HYDROPy/HYDROData_PolylineXY.sip @@ -65,6 +65,29 @@ public: virtual bool IsEditable() const; +public: + + /** + * Imports shape from IOR. + * \param theIOR the IOR of Geom object + * \return \c true if shape has been successfully imported + */ + bool ImportFromGeomIOR( const TCollection_AsciiString& theIOR ); + + /** + * Stores the study entry of the imported GEOM object. + * \param theEntry GEOM object entry + */ + void SetGeomObjectEntry( const TCollection_AsciiString& theEntry ); + + /** + * Returns the imported GEOM object entry. + */ + TCollection_AsciiString GetGeomObjectEntry() const; + + +public: + /** * Returns true if polyline is closed * \param theIsSimpleCheck flag indicating the type of checking