]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Child profile object is added for Polyline 3D if bathymetry is selcted (Bug #235).
authoradv <adv@opencascade.com>
Fri, 13 Dec 2013 11:56:08 +0000 (11:56 +0000)
committeradv <adv@opencascade.com>
Fri, 13 Dec 2013 11:56:08 +0000 (11:56 +0000)
src/HYDROData/HYDROData_Polyline3D.cxx
src/HYDROData/HYDROData_Polyline3D.h
src/HYDROData/HYDROData_Stream.cxx
src/HYDROGUI/HYDROGUI_DataModel.cxx
src/HYDROGUI/HYDROGUI_Poly3DOp.cxx
src/HYDROGUI/HYDROGUI_ProfileOp.cxx
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index 5cf9287fbf69bb7950fd0e566138823b62527d12..0507b2e8bcba9ce1396bdbbdb563a0561e1da307 100644 (file)
@@ -4,7 +4,9 @@
 #include "HYDROData_Bathymetry.h"
 #include "HYDROData_Document.h"
 #include "HYDROData_PolylineXY.h"
+#include "HYDROData_Profile.h"
 #include "HYDROData_ProfileUZ.h"
+#include "HYDROData_Tool.h"
 
 #include <gp_Pnt2d.hxx>
 #include <gp_XY.hxx>
@@ -64,6 +66,10 @@ HYDROData_SequenceOfObjects HYDROData_Polyline3D::GetAllReferenceObjects() const
   if ( !aProfileUZ.IsNull() )
     aResSeq.Append( aProfileUZ );
 
+  Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
+  if ( !aChildProfileUZ.IsNull() )
+    aResSeq.Append( aChildProfileUZ );
+
   return aResSeq;
 }
 
@@ -77,34 +83,6 @@ TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const
   return getShape3D();
 }
 
-HYDROData_IPolyline::PointsList generateProfileUZPoints(
-  const Handle(HYDROData_PolylineXY)& thePolyline,
-  const Handle(HYDROData_Bathymetry)& theBathymetry )
-{
-  HYDROData_IPolyline::PointsList aPointsList;
-  if ( thePolyline.IsNull() || theBathymetry.IsNull() )
-    return aPointsList;
-
-  bool anIsSectionClosed = thePolyline->IsClosedSection( 0 );
-  HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 );
-  HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 );
-  if ( aPolylinePoints.IsEmpty() )
-    return aPointsList;
-
-  for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i )
-  {
-    const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i );
-
-    double aPointDistance = thePolyline->GetDistance( 0, i - 1 );
-    double aPointDepth = theBathymetry->GetAltitudeForPoint( aSectPoint );
-
-    HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth );
-    aPointsList.Append( anAltitudePoint );
-  }
-
-  return aPointsList;
-}
-
 void HYDROData_Polyline3D::Update()
 {
   HYDROData_Object::Update();
@@ -119,20 +97,16 @@ void HYDROData_Polyline3D::Update()
   if ( aPolylinePoints.IsEmpty() )
     return;
 
-  HYDROData_IPolyline::PointsList aProfilePoints;
-
   Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
+
   Handle(HYDROData_Bathymetry) aBathymetry = GetBathymetry();
+  if ( !aBathymetry.IsNull() )
+    aProfileUZ = GetChildProfileUZ();
 
-  if ( !aProfileUZ.IsNull() )
-  {
-    aProfilePoints = aProfileUZ->GetPoints();
-  }
-  else if ( !aBathymetry.IsNull() )
-  {
-    aProfilePoints = generateProfileUZPoints( aPolylineXY, aBathymetry );
-  }
+  if ( aProfileUZ.IsNull() )
+    return;
 
+  HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints();
   if ( aProfilePoints.IsEmpty() )
     return;
 
@@ -191,7 +165,8 @@ QColor HYDROData_Polyline3D::getDefaultBorderColor() const
   return DefaultBorderColor();
 }
 
-bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline )
+bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline,
+                                          const bool                          theIsUpdateProfile )
 {
   if ( thePolyline.IsNull() )
     return false;
@@ -202,6 +177,10 @@ bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& th
 
   SetReferenceObject( thePolyline, DataTag_PolylineXY );
 
+  // Update the child profile object 
+  if ( theIsUpdateProfile )
+    updateChildProfilePoints();
+
   // Indicate model of the need to update the polyline presentation
   SetToUpdate( true );
 
@@ -264,15 +243,125 @@ void HYDROData_Polyline3D::RemoveProfileUZ()
   SetToUpdate( true );
 }
 
-
 bool HYDROData_Polyline3D::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
 {
+  Handle(HYDROData_Bathymetry) aPrevBathymetry = GetBathymetry();
+
   if ( !HYDROData_Object::SetBathymetry( theBathymetry ) )
     return false;
 
+  if ( IsEqual( aPrevBathymetry, theBathymetry ) )
+    return true;
+
   // Remove the u,z profile, because one altitude object can be presented at time
   RemoveProfileUZ();
 
+  // Create the child profile object 
+  updateChildProfilePoints();
+
   return true;
 }
 
+
+void HYDROData_Polyline3D::RemoveBathymetry()
+{
+  HYDROData_Object::RemoveBathymetry();
+
+  // Remove the child profile object 
+  removeChildProfileUZ();
+}
+
+Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetChildProfileUZ( const bool theIsCreate ) const
+{
+  Handle(HYDROData_ProfileUZ) aProfileUZ =
+    Handle(HYDROData_ProfileUZ)::DownCast( GetReferenceObject( DataTag_ChildProfileUZ ) );
+  if ( !theIsCreate || !aProfileUZ.IsNull() )
+    return aProfileUZ;
+
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() )
+    return aProfileUZ;
+
+  Handle(HYDROData_Profile) aProfile =
+    Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
+  
+  QString aProfilePref = GetName() + "_Profile";
+  QString aProfileName = HYDROData_Tool::GenerateObjectName( aDocument, aProfilePref );
+
+  aProfile->SetName( aProfileName );
+
+  aProfileUZ = aProfile->GetProfileUZ();
+
+  Handle(HYDROData_Polyline3D) me = this;
+  me->SetReferenceObject( aProfileUZ, DataTag_ChildProfileUZ );
+
+  return aProfileUZ;
+}
+
+HYDROData_IPolyline::PointsList generateProfileUZPoints(
+  const Handle(HYDROData_PolylineXY)& thePolyline,
+  const Handle(HYDROData_Bathymetry)& theBathymetry )
+{
+  HYDROData_IPolyline::PointsList aPointsList;
+  if ( thePolyline.IsNull() || theBathymetry.IsNull() )
+    return aPointsList;
+
+  bool anIsSectionClosed = thePolyline->IsClosedSection( 0 );
+  HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 );
+  HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 );
+  if ( aPolylinePoints.IsEmpty() )
+    return aPointsList;
+
+  for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i )
+  {
+    const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i );
+
+    double aPointDistance = thePolyline->GetDistance( 0, i - 1 );
+    double aPointDepth = theBathymetry->GetAltitudeForPoint( aSectPoint );
+
+    HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth );
+    aPointsList.Append( anAltitudePoint );
+  }
+
+  return aPointsList;
+}
+
+void HYDROData_Polyline3D::updateChildProfilePoints()
+{
+  Handle(HYDROData_Bathymetry) aBathymetry = GetBathymetry();
+  if ( aBathymetry.IsNull() )
+    return;
+
+  Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ();
+  if ( aChildProfileUZ.IsNull() )
+    return;
+
+  Handle(HYDROData_Profile) aProfile = 
+    Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
+  if ( aProfile.IsNull() )
+    return;
+
+  HYDROData_IPolyline::PointsList aProfilePoints = 
+    generateProfileUZPoints( GetPolylineXY(), GetBathymetry() );
+  aProfile->SetParametricPoints( aProfilePoints );
+
+  aProfile->Update();
+}
+
+void HYDROData_Polyline3D::removeChildProfileUZ()
+{
+  Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
+  if ( aChildProfileUZ.IsNull() )
+    return;
+
+  ClearReferenceObjects( DataTag_ChildProfileUZ );
+
+  /* Uncomment if removing is requested
+  Handle(HYDROData_Profile) aProfile = 
+    Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
+  if ( !aProfile.IsNull() )
+    aProfile->Remove();
+  */
+}
+
+
index f6e883b80d2ccf52d84712df165bb828f61c6514..98d655ec971e0a67d8d8b7e500106a17d62d4ace 100644 (file)
@@ -30,6 +30,7 @@ protected:
     DataTag_First = HYDROData_Object::DataTag_First + 100, ///< first tag, to reserve
     DataTag_PolylineXY,          ///< reference hydraulic axis
     DataTag_ProfileUZ,           ///< reference profile
+    DataTag_ChildProfileUZ,      ///< reference profile
   };
 
 public:
@@ -83,7 +84,8 @@ public:
   /**
    * Sets reference x,y polyline object for 3D polyline.
    */
-  HYDRODATA_EXPORT virtual bool SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline );
+  HYDRODATA_EXPORT virtual bool SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline,
+                                               const bool                          theIsUpdateProfile = true );
 
   /**
    * Returns reference x,y polyline object of 3D polyline.
@@ -118,6 +120,18 @@ public:
    */
   HYDRODATA_EXPORT virtual bool SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry );
 
+  /**
+   * Clear the reference bathymetry object for geometry object.
+   * Reimplemented to remove child u,z profile.
+   */
+  HYDRODATA_EXPORT virtual void RemoveBathymetry();
+
+
+  /**
+   * Returns the child u,z profile which has been generated from bathymetry.
+   */
+  HYDRODATA_EXPORT Handle(HYDROData_ProfileUZ) GetChildProfileUZ( const bool theIsCreate = true ) const;
+
 
 protected:
 
@@ -138,6 +152,14 @@ protected:
   HYDRODATA_EXPORT virtual void checkAndSetObject3D() {}
 
 
+protected:
+
+
+  void updateChildProfilePoints();
+
+  void removeChildProfileUZ();
+
+
 protected:
 
   friend class HYDROData_Iterator;
index 426159b29adf1e15e97278bae879334e21bbfa6b..22a913c9469d43f1f7469525e2afebf65f15907a 100644 (file)
@@ -145,7 +145,7 @@ void HYDROData_Stream::Update()
 
   Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
   HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
-  if ( aHydAxis.IsNull() || aRefProfiles.IsEmpty() )
+  if ( aHydAxis.IsNull() || aRefProfiles.Length() < 2 )
     return; 
  
   bool anIsFirst = true;
index ca645914050cc0e2e43b44d96d0d82c044243928..e43410b4be30caec6ab3904c337c8d1b7401d45d 100644 (file)
@@ -755,6 +755,40 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
     if ( !aBathymetry.IsNull() && !aBathymetry->IsRemoved() )
       createObject( aBathSect, aBathymetry, aGuiObj->entry(), false );
   }
+  else if ( anObjectKind == KIND_POLYLINE )
+  {
+    Handle(HYDROData_Polyline3D) aPolyline3D =
+      Handle(HYDROData_Polyline3D)::DownCast( aDataObj );
+
+    LightApp_DataObject* aPolylineSect = 
+      createObject( aGuiObj, tr( "POLYLINE3D_POLYLINE" ), aGuiObj->entry() );
+
+    Handle(HYDROData_PolylineXY) aPolylineXY = aPolyline3D->GetPolylineXY();
+    if ( !aPolylineXY.IsNull() && !aPolylineXY->IsRemoved() )
+      createObject( aPolylineSect, aPolylineXY, aGuiObj->entry(), false );
+
+    LightApp_DataObject* aProfileSect = 
+      createObject( aGuiObj, tr( "POLYLINE3D_PROFILE" ), aGuiObj->entry() );
+
+    Handle(HYDROData_ProfileUZ) aProfileUZ = aPolyline3D->GetProfileUZ();
+    if ( aProfileUZ.IsNull() || aProfileUZ->IsRemoved() )
+      aProfileUZ = aPolyline3D->GetChildProfileUZ( false );
+
+    if ( !aProfileUZ.IsNull() && !aProfileUZ->IsRemoved() )
+    {
+      Handle(HYDROData_Profile) aProfile = 
+        Handle(HYDROData_Profile)::DownCast( aProfileUZ->GetFatherObject() );
+      if ( !aProfile.IsNull() && !aProfile->IsRemoved() )
+        createObject( aProfileSect, aProfile, aGuiObj->entry(), false );
+    }
+
+    LightApp_DataObject* aBathSect = 
+      createObject( aGuiObj, tr( "POLYLINE3D_BATHYMETRY" ), aGuiObj->entry() );
+
+    Handle(HYDROData_Bathymetry) aBathymetry = aPolyline3D->GetBathymetry();
+    if ( !aBathymetry.IsNull() && !aBathymetry->IsRemoved() )
+      createObject( aBathSect, aBathymetry, aGuiObj->entry(), false );
+  }
   else if ( anObjectKind == KIND_CALCULATION )
   {
     Handle(HYDROData_CalculationCase) aCaseObj =
index 26c9e374f23feb1fecba62e11402c5021aec9681..7a4bd951fb8a8848fdcfd4c9ba5e24b6836ff792 100644 (file)
@@ -145,9 +145,6 @@ bool HYDROGUI_Poly3DOp::processApply( int& theUpdateFlags,
   if( myIsEdit )
   {
     aResult = myEditedObject;
-    aResult->RemoveProfileUZ();
-    aResult->RemovePolylineXY();
-    aResult->RemoveBathymetry();
   }
   else
   {
@@ -159,6 +156,7 @@ bool HYDROGUI_Poly3DOp::processApply( int& theUpdateFlags,
 
   aResult->SetName( aResultName );
 
+  aResult->SetPolylineXY( aPolyline, false );
   if ( !aProfile.IsNull() )
   {
     Handle(HYDROData_ProfileUZ) aProfileUZ = aProfile->GetProfileUZ();
@@ -172,8 +170,6 @@ bool HYDROGUI_Poly3DOp::processApply( int& theUpdateFlags,
     aResult->SetBathymetry( aBath );
   }
 
-  aResult->SetPolylineXY( aPolyline );
-
   if( !myIsEdit )
   {
     aResult->SetBorderColor( HYDROData_Polyline3D::DefaultBorderColor() );
index fa0ad6d72479b52aa4b85484c41c7acb1466ad3c..a81c4f7648455244ece0e12d9f06b6697fe9f605 100644 (file)
@@ -228,6 +228,11 @@ bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
     aProfileObj->SetBorderColor( HYDROData_Profile::DefaultBorderColor() );
   }
 
+  // At first we update the child u,z profile object
+  aProfileUZ->SetToUpdate( true );
+  aProfileUZ->Update();
+
+  // And now we update our edited object
   aProfileObj->Update();
 
   theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
index a64b53a4d7feae53fd01d87427521a05210d7630..7267eefba9ae300e4a9129891377ad685c052a59 100644 (file)
@@ -173,6 +173,18 @@ All supported formats (*.brep *.iges *.igs *.step *.stp)</translation>
       <source>COORDINATES_INFO</source>
       <translation>X: %1, Y: %2</translation>
     </message>
+    <message>
+      <source>POLYLINE3D_POLYLINE</source>
+      <translation>Polyline</translation>
+    </message>
+    <message>
+      <source>POLYLINE3D_PROFILE</source>
+      <translation>Profile</translation>
+    </message>
+    <message>
+      <source>POLYLINE3D_BATHYMETRY</source>
+      <translation>Bathymetry</translation>
+    </message>
   </context>
 
   <context>