Salome HOME
refs #517: using not-georeferenced profiles in the channel/digue
authorasl <asl@opencascade.com>
Wed, 20 May 2015 07:11:00 +0000 (10:11 +0300)
committerasl <asl@opencascade.com>
Wed, 20 May 2015 07:11:00 +0000 (10:11 +0300)
src/HYDROData/HYDROData_Profile.cxx
src/HYDROData/HYDROData_Profile.h
src/HYDROGUI/HYDROGUI_ChannelOp.cxx

index 9cc693cc8b1a2ea0e88970444f5303a1e62d2baf..47418cdf8a0200b45a89d32b4df9534a93abd8b1 100755 (executable)
@@ -156,23 +156,32 @@ TopoDS_Shape HYDROData_Profile::GetTopShape() const
 
 TopoDS_Shape HYDROData_Profile::GetShape3D() const
 {
-  return getShape3D();
+  TopoDS_Shape aShape = getShape3D();
+  if( aShape.IsNull() )
+    aShape = CreateProfileWire( true );
+  return aShape;
 }
 
-void HYDROData_Profile::Update()
+TopoDS_Shape HYDROData_Profile::CreateProfileWire( bool canUseDefaultPoints ) const
 {
-  HYDROData_Object::Update();
-
   TopoDS_Wire aWire;
   Handle(HYDROData_ProfileUZ) aProfile = GetProfileUZ( false );
   if ( !aProfile.IsNull() )
   {
-    ProfilePoints aProfilePoints = GetProfilePoints( false );
+    ProfilePoints aProfilePoints = GetProfilePoints( false, canUseDefaultPoints );
     HYDROData_IPolyline::SectionType aSectionType = aProfile->GetSectionType( 0 );
 
     aWire = HYDROData_PolylineXY::BuildWire( aSectionType, false, aProfilePoints );
   }
-  SetShape3D( aWire );
+  return aWire;
+}
+
+void HYDROData_Profile::Update()
+{
+  HYDROData_Object::Update();
+
+  TopoDS_Shape aShape = CreateProfileWire( false );
+  SetShape3D( aShape );
 }
 
 QColor HYDROData_Profile::DefaultFillingColor()
@@ -226,16 +235,29 @@ void HYDROData_Profile::SetLeftPoint( const gp_XY& theGPoint, bool IsConvertFrom
   SetToUpdate( true );
 }
 
-bool HYDROData_Profile::GetLeftPoint( gp_XY& thePoint, bool IsConvertToGlobal ) const
+bool HYDROData_Profile::GetLeftPoint( gp_XY& thePoint, bool IsConvertToGlobal,
+                                      bool CanUseDefault ) const
 {
+  HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
+  if ( aParametricPoints.Length() < 2 )
+    return false;
+
+  thePoint = GetParametricPoints().First();
+
+  thePoint.SetX( 0 );
+  thePoint.SetY( 0 ); //default left point of not-georeferenced profile
   TDF_Label aLabel = myLab.FindChild( DataTag_FirstPoint, false );
   if ( aLabel.IsNull() )
-    return false;
+  {
+    return CanUseDefault;
+  }
 
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
   Handle(TDataStd_RealArray) anArray;
   if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
-    return false;
+  {
+    return CanUseDefault;
+  }
 
   thePoint.SetX( anArray->Value( 0 ) );
   thePoint.SetY( anArray->Value( 1 ) );
@@ -265,16 +287,27 @@ void HYDROData_Profile::SetRightPoint( const gp_XY& theGPoint, bool IsConvertFro
   SetToUpdate( true );
 }
 
-bool HYDROData_Profile::GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal ) const
+bool HYDROData_Profile::GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal,
+                                       bool CanUseDefault ) const
 {
+  HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
+  if ( aParametricPoints.Length() < 2 )
+    return false;
+
+  thePoint = GetParametricPoints().First();
+
   TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint, false );
   if ( aLabel.IsNull() )
-    return false;
+  {
+    return CanUseDefault;
+  }
 
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
   Handle(TDataStd_RealArray) anArray;
   if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
-    return false;
+  {
+    return CanUseDefault;
+  }
 
   thePoint.SetX( anArray->Value( 0 ) );
   thePoint.SetY( anArray->Value( 1 ) );
@@ -385,13 +418,14 @@ void HYDROData_Profile::SetProfilePoints( const ProfilePoints& thePoints, bool I
   SetRightPoint( aLastPoint, false );
 }
 
-HYDROData_Profile::ProfilePoints HYDROData_Profile::GetProfilePoints( bool IsConvertToGlobal ) const
+HYDROData_Profile::ProfilePoints HYDROData_Profile::GetProfilePoints
+  ( bool IsConvertToGlobal, bool CanUseDefaultLeftRight ) const
 {
   ProfilePoints aResPoints;
 
   gp_XY aFirstPoint, aLastPoint;
-  if ( !GetLeftPoint( aFirstPoint, IsConvertToGlobal ) ||
-       !GetRightPoint( aLastPoint, IsConvertToGlobal ) )
+  if ( !GetLeftPoint( aFirstPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) ||
+       !GetRightPoint( aLastPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) )
     return aResPoints;
 
   HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
index 22cd5cd2550f2366b6ed91757580dee13540edd2..0c3ab048806a7d44faf646a30638f71d69c9ef64 100644 (file)
@@ -125,7 +125,8 @@ public:
    * \param thePoint[out] profile first point
    * \return true if point has been set
    */
-  HYDRODATA_EXPORT bool GetLeftPoint( gp_XY& thePoint, bool IsConvertToGlobal = false ) const;
+  HYDRODATA_EXPORT bool GetLeftPoint( gp_XY& thePoint, bool IsConvertToGlobal = false,
+                                      bool CanUseDefault = false ) const;
 
   /**
    * Set last(right) point for profile.
@@ -138,8 +139,8 @@ public:
    * \param thePoint[out] profile last point
    * \return true if point has been set
    */
-  HYDRODATA_EXPORT bool GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal = false ) const;
-
+  HYDRODATA_EXPORT bool GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal = false,
+                                       bool CanUseDefault = false ) const;
 
   /**
    * Returns object which store parametric presentation of profile points.
@@ -185,7 +186,8 @@ public:
    * Empty sequence is returned if first or last point was not set.
    * \return profile points list
    */
-  HYDRODATA_EXPORT ProfilePoints GetProfilePoints( bool IsConvertToGlobal = false ) const;
+  HYDRODATA_EXPORT ProfilePoints GetProfilePoints( bool IsConvertToGlobal = false,
+                                                   bool CanUseDefaultLeftRight = false ) const;
 
 
   /**
@@ -256,6 +258,7 @@ protected:
    */
   HYDRODATA_EXPORT virtual void checkAndSetObject3D() {}
 
+  TopoDS_Shape CreateProfileWire( bool canUseDefaultPoints ) const;
 
 protected:
 
index afeff419c4dd7ece745a854d3daf89b701c3282e..71714929ed70681d4b79fb3ad459d350272b4e1b 100644 (file)
@@ -105,7 +105,7 @@ void HYDROGUI_ChannelOp::startOperation()
   }
 
   // collect information about existing profiles
-  QStringList aProfiles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_PROFILE, true );
+  QStringList aProfiles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_PROFILE, false );
 
   aPanel->setObjectName( anObjectName );