]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Stream creation corrected (Bug #272).
authoradv <adv@opencascade.com>
Fri, 20 Dec 2013 12:26:40 +0000 (12:26 +0000)
committeradv <adv@opencascade.com>
Fri, 20 Dec 2013 12:26:40 +0000 (12:26 +0000)
src/HYDROData/HYDROData_Stream.cxx
src/HYDROData/HYDROData_Stream.h
src/HYDROGUI/HYDROGUI_StreamOp.cxx
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index 2fb2adb47ae1790871e6b0bc9de746fb0daa4ec3..b9605be3b0074cee90ec60837dc18b35b9391eac 100644 (file)
@@ -298,6 +298,20 @@ QColor HYDROData_Stream::DefaultBorderColor()
   return QColor( Qt::transparent );
 }
 
+bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
+{
+  if ( theHydAxis.IsNull() )
+    return false;
+
+  TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
+  if ( aHydraulicShape.IsNull() || 
+       aHydraulicShape.ShapeType() != TopAbs_WIRE ||
+       BRep_Tool::IsClosed( aHydraulicShape ) )
+    return false; // The polyline must be a single not closed wire
+
+  return true;
+}
+
 QColor HYDROData_Stream::getDefaultFillingColor() const
 {
   return DefaultFillingColor();
@@ -310,20 +324,12 @@ QColor HYDROData_Stream::getDefaultBorderColor() const
 
 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
 {
-  Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
-
-  if ( theAxis.IsNull() )
-  {
-    RemoveHydraulicAxis();
-    return !aPrevAxis.IsNull();
-  }
-
-  if ( IsEqual( aPrevAxis, theAxis ) )
+  if ( !IsValidAsAxis( theAxis ) )
     return false;
 
-  TopoDS_Wire aHydraulicWire = TopoDS::Wire( theAxis->GetShape() );
-  if ( aHydraulicWire.IsNull() )
-    return false; // The polyline must be a single wire
+  Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
+  if ( IsEqual( aPrevAxis, theAxis ) )
+    return true;
 
   SetReferenceObject( theAxis, DataTag_HydraulicAxis );
 
@@ -362,7 +368,7 @@ bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theH
                                         const TopoDS_Face& thePlane,
                                                               Standard_Real& outPar)
 {
-  if ( theProfile.IsNull() || theHydAxis.IsNull() )
+  if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
     return false; 
 
   TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
@@ -567,11 +573,14 @@ void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)&
     InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
 }
 
-bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis, TopoDS_Face& thePlane) const
+bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
+                                  TopoDS_Face&                        thePlane ) const
 {
-  if ( theHydAxis.IsNull() ) return false;
+  if ( !IsValidAsAxis( theHydAxis ) )
+    return false;
+
   TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
-  if(aHydraulicWire.IsNull()) return false;
+
   gp_Ax2 aX2(gp::XOY());
   gp_Ax3 aX3(aX2);
   gp_Pln aPln(aX3);   
index 4f3644060af53742c1ba0a8d8c70b5043a903d6c..4e968be7919f1cd201e3a3d2db508abc111911e8 100644 (file)
@@ -73,6 +73,10 @@ public:
    */
   HYDRODATA_EXPORT static QColor DefaultBorderColor();
 
+  /**
+   * Returns true if given polyline can be used as stream axis.
+   */
+  HYDRODATA_EXPORT static bool IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theAxis );
 
 public:      
   // Public methods to work with Stream
index 5882c2f868ac21fb9d092cc03a0c5d17f7ab7af7..822175bea726c700120df58211018fe62b41b9a6 100755 (executable)
@@ -366,11 +366,15 @@ void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis )
 
   // Prepare data for intersection check
   TopoDS_Face aPlane;
-  if ( anAxis.IsNull() || !myEditedObject->BuildFace(anAxis, aPlane) ) {
+  if ( !myEditedObject->BuildFace(anAxis, aPlane) ) {
+    SUIT_MessageBox::critical( module()->getApp()->desktop(), 
+                              tr( "BAD_SELECTED_POLYLINE_TLT" ),
+                              tr( "BAD_SELECTED_POLYLINE_MSG" ).arg( theNewAxis ) );
     // To restore the old axis
     updatePanelData();
     return;
   }
+
   Standard_Real aPar(.0);
 
   // Get list of profiles which do not intersect the axis
index bc4dc6cdc33e7fc910c2e2325483040331f85098..7b28a0386b4562c13931cccb67f7a72c72c272b2 100644 (file)
@@ -1807,6 +1807,15 @@ file cannot be correctly imported for an Obstacle definition.</translation>
 
 Do you want to remove these profiles and continue?</translation>
     </message>
+    <message>
+      <source>BAD_SELECTED_POLYLINE_TLT</source>
+      <translation>Polyline is not appropriate for channel creation</translation>
+    </message>
+    <message>
+      <source>BAD_SELECTED_POLYLINE_MSG</source>
+      <translation>Polyline '%1' can not be used as hydraulic axis for channel.
+Polyline should consist from one not closed curve.</translation>
+    </message>
   </context>
 
   <context>