]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
split zones (draft)
authorisn <isn@opencascade.com>
Mon, 5 Sep 2016 06:17:06 +0000 (09:17 +0300)
committerisn <isn@opencascade.com>
Tue, 6 Sep 2016 11:41:32 +0000 (14:41 +0300)
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_CalculationCase.h
src/HYDROData/HYDROData_SplitToZonesTool.cxx
src/HYDROData/HYDROData_SplitToZonesTool.h
src/HYDROGUI/HYDROGUI_CalculationOp.cxx
src/HYDROGUI/HYDROGUI_CalculationOp.h
src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx
src/HYDRO_tests/test_HYDROData_LandCoverMap.h

index 8c2752409ddd0044853091330e7a4f32b0bd8bd5..28a6059589541eeeee2a1f362dc97b96eaebd23b 100644 (file)
@@ -282,12 +282,15 @@ void HYDROData_CalculationCase::Update()
   HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
 
   Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
+
+  HYDROData_SequenceOfObjects InterPolys = GetInterPolyObjects();
+
   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
   if ( !aGeomObjects.IsEmpty() ) {
     HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
 
     HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
-      HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
+      HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline, InterPolys );
     if ( !aSplitObjects.isEmpty() ) {
       HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
       while( anIter.hasNext() ) {
@@ -1379,3 +1382,32 @@ bool HYDROData_CalculationCase::GetRule( int theIndex,
   return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
     theObject1, thePriority, theObject2, theMergeType );
 }
+
+bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
+{
+  HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
+
+  if ( HasReference( theInterPolyline, aDataTag ) )
+    return false; 
+
+  AddReferenceObject( theInterPolyline, aDataTag );
+
+  return true;
+}
+
+HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
+{
+  return GetReferenceObjects( DataTag_InterPoly ); 
+}
+
+void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline ) 
+{
+  if ( theInterPolyline.IsNull() )
+    return;
+
+  RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );
+
+}
+
+
+
index 1780ca9c682f246a4734398b3972a4acd3b39e08..e71b191a81105fc5688e2b2f621b394c0d0238d4 100644 (file)
@@ -96,6 +96,7 @@ public:
     DataTag_CustomRules,               ///< custom rules
     DataTag_AssignmentMode,            ///< assignment mode
     DataTag_StricklerTable,            ///< reference Strickler table
+    DataTag_InterPoly,                 ///< intersection polyline
 
     DataTag_LandCover_Obsolete,                 ///< reference land covers
     DataTag_CustomLandCoverRules_Obsolete,      ///< custom rules for land covers priority
@@ -274,6 +275,12 @@ public:
    */
   HYDRODATA_EXPORT virtual void RemoveSplitGroups();
 
+  HYDRODATA_EXPORT virtual bool AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline );
+
+  HYDRODATA_EXPORT virtual void RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline );
+
+  HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetInterPolyObjects() const;
+
   /**
    * Exports the calculation case data (shell and groups) to GEOM module.
    * \param theStudyId the id of the study where the GEOM module should be used for export
index ba3359c295842b39e27564f0de103373f189e50a..e5a1d8428aa7d3b87393a9bd3eb1f5e7eb896f5c 100644 (file)
@@ -40,6 +40,9 @@
 #include <Geom_Plane.hxx>
 #include <BRepBuilderAPI_FindPlane.hxx>
 
+#include <BOPAlgo_BOP.hxx>
+#include <BOPAlgo_Builder.hxx>
+
 //#define DEB_SPLIT_TO_ZONES 1
 //#define DEB_SPLIT_TO_ZONES_CHECK_PARTITION 1
 #if (defined (DEB_SPLIT_TO_ZONES) || defined(DEB_SPLIT_TO_ZONES_CHECK_PARTITION))
@@ -130,7 +133,8 @@ Standard_Integer HYDROData_SplitToZonesTool::SplitFaces(const TopoDS_Compound& t
 HYDROData_SplitToZonesTool::SplitDataList
   HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects&  theObjectList,
                                      const HYDROData_SequenceOfObjects&  theGroupsList,
-                                     const Handle(HYDROData_PolylineXY)& thePolyline )
+                                     const Handle(HYDROData_PolylineXY)& thePolyline,
+                                     const HYDROData_SequenceOfObjects& InterPolys)
 {
   DEBTRACE("Split");
   SplitDataList anOutputSplitDataList;
@@ -547,6 +551,9 @@ HYDROData_SplitToZonesTool::SplitDataList
       }
     }
   }
+
+  AddInternalEdges(aDM2, InterPolys);
+
   // Step 4. Fill output structure.
 #ifdef DEB_SPLIT_TO_ZONES
   TCollection_AsciiString aNam4 ("SC_");
@@ -609,6 +616,78 @@ HYDROData_SplitToZonesTool::SplitDataList
 {
   HYDROData_SequenceOfObjects aGeomGroups;
   Handle(HYDROData_PolylineXY) aPolyline;
+  HYDROData_SequenceOfObjects InterPolys;
+
+  return Split( theObjectList, aGeomGroups, aPolyline, InterPolys );
+}
+
+void HYDROData_SplitToZonesTool::AddInternalEdges(HYDROData_DataMapOfShapeListOfShape& DM,
+   const HYDROData_SequenceOfObjects& thePolylines)
+{
+
+  HYDROData_SequenceOfObjects::Iterator it(thePolylines);
+  TopTools_ListOfShape Wires;
+  for (;it.More();it.Next())
+  {
+    Handle(HYDROData_PolylineXY) P = Handle(HYDROData_PolylineXY)::DownCast(it.Value());
+    Wires.Append(P->GetShape());
+    //Handle(TopTools_HSequenceOfShape) aConnectedWires = new TopTools_HSequenceOfShape;
+    //if (P->GetNbConnectedWires(aConnectedWires) > 0)
+    //  Wires.Append(aConnectedWires->Value(1));
+  }
+
+  HYDROData_DataMapOfShapeListOfShape newDM;
+
+  for (int i = 1; i <= DM.Extent();i++)
+  {
+    const TopoDS_Shape& K = DM.FindKey(i);
+    const TopTools_ListOfShape& V = DM.FindFromIndex(i);
+    TopTools_ListOfShape out;
+    if (K.ShapeType() == TopAbs_FACE)
+    {
+      CutByEdges(K, Wires, out);
+      TopTools_ListIteratorOfListOfShape it(out);
+      for (;it.More(); it.Next())
+      {
+        const TopoDS_Shape& NF = it.Value();
+        if (!NF.IsNull())
+          newDM.Add(NF, V);
+      }
+    }
+    else
+      newDM.Add(K, V); // ignore edges, wires...
+  }
+
+  DM = newDM;
+}
+
+
+int HYDROData_SplitToZonesTool::CutByEdges(const TopoDS_Shape& InSh, const TopTools_ListOfShape& InEdges,
+  TopTools_ListOfShape& outShs)
+{
+  int anError;
+  if (InSh.IsNull())
+    return -1;
+  if (InEdges.IsEmpty())
+  {
+    outShs.Clear();
+    outShs.Append(InSh);
+    return 0;
+  }
+  TopTools_ListIteratorOfListOfShape anIt;
+  BOPAlgo_Builder anAlgo;
+  anAlgo.AddArgument(InSh);
+  anIt.Initialize( InEdges );
+  for( ; anIt.More(); anIt.Next() )
+    anAlgo.AddArgument( anIt.Value() );
+
+  anAlgo.Perform(); 
+  anError = anAlgo.ErrorStatus();
+  if (anError)
+    return anError;
 
-  return Split( theObjectList, aGeomGroups, aPolyline );
+  outShs = anAlgo.Modified( InSh );
+  if (outShs.IsEmpty())
+    outShs.Append(InSh);
+  return 0;
 }
index eaa58208496cd17581c277b36cf2792c8fcd9427..530e7f2aba241f1606e998177afb99c67fe4df50 100644 (file)
@@ -87,10 +87,17 @@ public:
 
   static SplitDataList       Split( const HYDROData_SequenceOfObjects&  theObjectList,
                                     const HYDROData_SequenceOfObjects&  theGroupsList,
-                                    const Handle(HYDROData_PolylineXY)& thePolyline );
+                                    const Handle(HYDROData_PolylineXY)& thePolyline,
+                                    const HYDROData_SequenceOfObjects& InterPolys );
 
   static SplitDataList       Split( const HYDROData_SequenceOfObjects&  theObjectList );
 
+  static void AddInternalEdges(HYDROData_DataMapOfShapeListOfShape& DM,
+                               const HYDROData_SequenceOfObjects& thePolylines);
+
+  static int CutByEdges(const TopoDS_Shape& InSh, const TopTools_ListOfShape& InEdges,
+                        TopTools_ListOfShape& outShs);
+
   static void SetFileNames(const QString& theNameBefore, const QString& theNameAfter);
 
 private:
index 0af2109beca5c87a95531b072d709da9c1e8a64f..024b5487b5ca5f12000663da4f73477320b8f30c 100644 (file)
@@ -98,6 +98,13 @@ void HYDROGUI_CalculationOp::startOperation()
   QStringList anEntryList;
   HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
   getNamesAndEntries( aSeq, aList, anEntryList );
+  
+  QStringList List1;
+  QStringList EList1;
+
+  //add intersection polylines
+  AddInterPolylinesToList(aList, anEntryList);
+  
   aPanel->setAllGeomObjects( aList, anEntryList );
 
   // Get all polylines
@@ -171,6 +178,26 @@ void HYDROGUI_CalculationOp::startOperation()
   createPreview( false );
 }
 
+void HYDROGUI_CalculationOp::AddInterPolylinesToList(QStringList& theList, QStringList& theEntryList)
+{
+  HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
+  Handle(HYDROData_PolylineXY) aPolylineObj;
+  QString aPolylineName;
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
+    if ( !aPolylineObj.IsNull())
+    { 
+      aPolylineName = aPolylineObj->GetName();
+      if ( !aPolylineName.isEmpty() && !theList.contains(aPolylineName) )
+      {
+        theList.append( aPolylineName );
+        theEntryList.append(HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ));
+      }
+    }
+  }
+}
+
 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq, 
                                                 QStringList& theNames, QStringList& theEntries ) const
 {
@@ -510,6 +537,17 @@ void HYDROGUI_CalculationOp::onAddObjects()
       anAddedList.append( anObject->GetName() );
   }
 
+  for (int i = 0; i < aSelectedList.length(); i++)
+  {
+    Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast( 
+      HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
+    if ( aPoly.IsNull() )
+      continue;
+
+    if ( myEditedObject->AddInterPoly( aPoly ) )
+      anAddedList.append( aPoly->GetName() );
+  }
+
   if ( !anAddedList.isEmpty() )
   {
     aPanel->includeGeomObjects( anAddedList );
@@ -540,6 +578,17 @@ void HYDROGUI_CalculationOp::onRemoveObjects()
     myEditedObject->RemoveGeometryObject( anObject );
   }
 
+  for (int i = 0; i < aSelectedList.length(); i++)
+  {
+    Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast( 
+      HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
+    if ( aPoly.IsNull() )
+      continue;
+
+    setObjectVisibility( aPoly, false );
+    myEditedObject->RemoveInterPolyObject ( aPoly ); 
+  }
+
   module()->update( UF_OCCViewer );
   aPanel->excludeGeomObjects( aSelectedList );
 }
@@ -1156,7 +1205,9 @@ void HYDROGUI_CalculationOp::createPreview( const bool theLandCoverMap )
   else if ( !theLandCoverMap && myShowGeomObjects )
   {
     HYDROData_SequenceOfObjects aSeqGO = myEditedObject->GetGeometryObjects();
+    HYDROData_SequenceOfObjects aSeqP = myEditedObject->GetInterPolyObjects();
     aSeq.Append( aSeqGO );
+    aSeq.Append( aSeqP );
   }
 
   Handle(HYDROData_Entity) anEntity;
index 42599f59614c65804b3b47dca438998bd22a12d1..909256474537af6d9825243262e5f4621c0921dc 100644 (file)
@@ -163,6 +163,8 @@ private:
 
   bool                            createRegion( const QList<SUIT_DataObject*>& theZonesList );
 
+  void                            AddInterPolylinesToList(QStringList& theList, QStringList& theEntryList);
+
   bool confirmRegionsChange() const;
   bool confirmModeChange() const;
   bool confirmOrderChange() const;
index df9deb4c9b47e1eecf2ca2e51db9d7090bb4d447..a66ae5ef73181787d0930d5deb528ff34b9e4aef 100644 (file)
@@ -44,6 +44,7 @@
 #include <BRep_Builder.hxx>
 #include <BRepCheck_Analyzer.hxx>
 #include <OSD_Timer.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
 
 #define _DEVDEBUG_
 #include "HYDRO_trace.hxx"
@@ -1277,3 +1278,24 @@ void test_HYDROData_LandCoverMap::test_shp_clc_classification_check()
 
 }
 
+void test_HYDROData_LandCoverMap::test_add_int_edges_1()
+{
+  TopoDS_Shape out;
+  TopTools_ListOfShape Wires;
+
+  BRep_Builder B;
+  TopoDS_Shape InF;
+  TopoDS_Shape InP;
+  BRepTools::Read(InP, "d:/p2.brep", B); //TODO
+  BRepTools::Read(InF, "d:/r2.brep", B);
+  Wires.Append(InP);
+
+  TopTools_ListOfShape OutSh;
+  HYDROData_SplitToZonesTool::CutByEdges(InF, Wires, OutSh);
+  TopTools_ListIteratorOfListOfShape it(OutSh);
+  for (;it.More();it.Next())
+  {
+    TopoDS_Shape Sh = it.Value();
+  }
+}
+
index c473c4a1a3f858c0034e5c957eb50f3f389e6bd5..cdf06fa39828f6983112ef293de05877d8bba48a 100644 (file)
@@ -52,6 +52,7 @@ class test_HYDROData_LandCoverMap : public CppUnit::TestFixture
   CPPUNIT_TEST( test_shp_loop_back );
   CPPUNIT_TEST( test_shp_clc_classification_perf );
   CPPUNIT_TEST( test_shp_clc_classification_check );
+  CPPUNIT_TEST( test_add_int_edges_1 );
 #endif
   CPPUNIT_TEST_SUITE_END();
 
@@ -81,6 +82,7 @@ public:
   void test_copy();
   void test_shp_clc_classification_perf();
   void test_shp_clc_classification_check();
+  void test_add_int_edges_1();
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_LandCoverMap );