]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #567: HYDROData_LandCover::buildShape() method returns the error message now.
authormzn <mzn@opencascade.com>
Mon, 22 Jun 2015 11:15:42 +0000 (14:15 +0300)
committermzn <mzn@opencascade.com>
Mon, 22 Jun 2015 11:15:42 +0000 (14:15 +0300)
src/HYDROData/HYDROData_LandCover.cxx
src/HYDROData/HYDROData_LandCover.h
src/HYDROGUI/HYDROGUI_LandCoverOp.cxx
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index b588c1faa7b9c6878d298db512696ba779c76d9e..815bc3b58b5fdd37680b0f084003508716d6a167 100644 (file)
@@ -30,6 +30,7 @@
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Wire.hxx>
 #include <TopoDS_Face.hxx>
+#include <TopExp_Explorer.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 #include <NCollection_IncAllocator.hxx>
@@ -120,7 +121,8 @@ void HYDROData_LandCover::Update()
   
   removeShape();
 
-  TopoDS_Shape aResShape = buildShape();
+  TCollection_AsciiString anErrorMsg;
+  TopoDS_Shape aResShape = buildShape( GetPolylines(), anErrorMsg );
   
   setShape( aResShape );
 }
@@ -196,42 +198,62 @@ void HYDROData_LandCover::removeShape()
   }
 }
  
-TopoDS_Shape HYDROData_LandCover::buildShape() const
+TopoDS_Shape HYDROData_LandCover::buildShape( const HYDROData_SequenceOfObjects& thePolylines,
+                                              TCollection_AsciiString& theErrorMsg )
 {
+  theErrorMsg.Clear();
   TopoDS_Shape aResShape;
 
   BRepBuilderAPI_MakeWire aMakeWire;
   
   TopTools_ListOfShape aClosedWires;
 
-  HYDROData_SequenceOfObjects aRefPolylines = GetPolylines();
-  for ( int i = 1, n = aRefPolylines.Length(); i <= n; ++i ) {
+  int aNbPolylines = thePolylines.Length();
+  for ( int i = 1; i <= aNbPolylines; ++i ) {
     Handle(HYDROData_PolylineXY) aPolyline = 
-      Handle(HYDROData_PolylineXY)::DownCast( aRefPolylines.Value( i ) );
+      Handle(HYDROData_PolylineXY)::DownCast( thePolylines.Value( i ) );
     
     if ( aPolyline.IsNull() ) {
       continue;
     }
 
     TopoDS_Shape aPolyShape = aPolyline->GetShape();
-    if ( aPolyShape.IsNull() || aPolyShape.ShapeType() != TopAbs_WIRE ) {
+    if ( aPolyShape.IsNull() ) {
       continue;
     }
 
-    const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolyShape );
-    if ( aPolylineWire.IsNull() ) {
-      continue;
+    // Extract polyline wire(s)
+    TopTools_ListOfShape aPolylineWires;
+      
+    if ( aPolyShape.ShapeType() == TopAbs_WIRE ) {
+      const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolyShape );
+      if ( !aPolylineWire.IsNull() ) {
+        aPolylineWires.Append( aPolylineWire );
+      }
+    } else if ( aPolyShape.ShapeType() == TopAbs_COMPOUND ) {
+      TopExp_Explorer anExp( aPolyShape, TopAbs_WIRE );
+      for (; anExp.More(); anExp.Next() ) {
+        if(!anExp.Current().IsNull()) {
+          const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() );
+          aPolylineWires.Append( aWire );
+        }
+      }
     }
-
-    if ( aPolylineWire.Closed() ) {
-      aClosedWires.Append( aPolylineWire );
-    } else {
-      aMakeWire.Add( aPolylineWire );
-      aMakeWire.Build();
-      if ( aMakeWire.IsDone() ) {
-        if ( aMakeWire.Wire().Closed() ) {
-          aClosedWires.Append( aMakeWire.Wire() );
-          aMakeWire = BRepBuilderAPI_MakeWire();
+    
+    TopTools_ListIteratorOfListOfShape anIt( aPolylineWires );
+    for ( ; anIt.More(); anIt.Next() ) {
+      TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() );
+      
+      if ( aWire.Closed() ) {
+        aClosedWires.Append( aWire );
+      } else {
+        aMakeWire.Add( aWire );
+        aMakeWire.Build();
+        if ( aMakeWire.IsDone() ) {
+          if ( aMakeWire.Wire().Closed() ) {
+            aClosedWires.Append( aMakeWire.Wire() );
+            aMakeWire = BRepBuilderAPI_MakeWire();
+          }
         }
       }
     }
@@ -260,6 +282,10 @@ TopoDS_Shape HYDROData_LandCover::buildShape() const
     }
 
     aResShape = aCompound;
+  } else if ( aNbPolylines > 0 ) {
+    TCollection_AsciiString aSourceName = aNbPolylines > 1 ? "polylines" : "polyline";
+    theErrorMsg = "Can't build closed contour on the given ";
+    theErrorMsg += aSourceName;
   }
 
   ///< \TODO to be reimplemented
index 3bba4a9e7e895d07d7a049b06ad2c843d5fab3cf..398d6cdd78db92a7cc0b193b2d48f96f85e8d82f 100644 (file)
@@ -126,6 +126,12 @@ public:
    */
   HYDRODATA_EXPORT static QColor DefaultBorderColor();
 
+  /**
+   * Build the shape presentation of the land cover.
+   */
+  HYDRODATA_EXPORT static TopoDS_Shape buildShape( const HYDROData_SequenceOfObjects& thePolylines,
+                                                   TCollection_AsciiString& theErrorMsg );
+
 protected:
   /**
    * Sets the shape presentation of the land cover.
@@ -136,11 +142,6 @@ protected:
    * Removes the shape from data label of the land cover object.
    */
   HYDRODATA_EXPORT virtual void removeShape();
-
-  /**
-   * Build the shape presentation of the land cover.
-   */
-  HYDRODATA_EXPORT virtual TopoDS_Shape buildShape() const;
 };
 
 #endif
index 5240b42d86bdcbdbcd2879078db995073d854b55..00b32548846d5db87d1f9a82b87997da5af6e189 100644 (file)
@@ -189,17 +189,25 @@ bool HYDROGUI_LandCoverOp::processApply( int& theUpdateFlags,
     }
   }
 
+  if ( aZonePolylines.IsEmpty() )
+  {
+    theErrorMsg = tr( "POLYLINES_NOT_DEFINED" );
+    return false;
+  }
+
   QString aSelectedStricklerType = aPanel->getSelectedAdditionalParamName();
   
-  // TODO: Generate TopoDS_Shape based on the set of polylines, implement generateTopShape data model method
-  /*
-  if ( HYDROData_LandCover::generateTopShape( aZonePolylines ).IsNull() )
+  TCollection_AsciiString anError;
+  if ( HYDROData_LandCover::buildShape( aZonePolylines, anError ).IsNull() )
   {
-    theErrorMsg = tr( "ZONE_OBJECT_CANNOT_BE_CREATED" );
+    if ( !anError.IsEmpty() ) {
+      theErrorMsg = HYDROGUI_Tool::ToQString( anError );
+    } else {
+      theErrorMsg = tr( "LAND_COVER_OBJECT_CANNOT_BE_CREATED" );
+    }
     return false;
   }
-  */
-
+  
   Handle(HYDROData_LandCover) aZoneObj = myIsEdit ? myEditedObject :
     Handle(HYDROData_LandCover)::DownCast( doc()->CreateObject( KIND_LAND_COVER ) );
 
index c464bb86e6c4d97a6eb13a4f4992bbbbc4b243f5..c8eb087d3940e96544c03d43dce5195638eb4909 100644 (file)
@@ -2370,7 +2370,7 @@ file cannot be correctly imported for an Obstacle definition.</translation>
     </message>
     <message>
       <source>AXIS_NOT_DEFINED</source>
-      <translation>Hydraulic axis is not defiled.</translation>
+      <translation>Hydraulic axis is not defined.</translation>
     </message>
     <message>
       <source>PROFILES_NOT_DEFINED</source>
@@ -2599,6 +2599,14 @@ Polyline should consist from one not closed curve.</translation>
       <source>CONFIRM_LAND_COVER_RECALCULATION</source>
       <translation>Land cover object already exists and will be recalculated after polylines list modification. Do you confirm the recalculation?</translation>
     </message>
+    <message>
+      <source>POLYLINES_NOT_DEFINED</source>
+      <translation>At least 1 polyline should be defined.</translation>
+    </message>
+    <message>
+      <source>LAND_COVER_OBJECT_CANNOT_BE_CREATED</source>
+      <translation>Land Cover object can not be created</translation>
+    </message>
   </context>
 
   <context>