]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
4.12.2013. HasIntersection () method implementation. API is modified.
authorszy <szy@opencascade.com>
Wed, 4 Dec 2013 15:00:34 +0000 (15:00 +0000)
committerszy <szy@opencascade.com>
Wed, 4 Dec 2013 15:00:34 +0000 (15:00 +0000)
src/HYDROData/HYDROData_Stream.cxx
src/HYDROData/HYDROData_Stream.h
src/HYDROGUI/HYDROGUI_StreamOp.cxx

index 2e951d99a8347df1fc4de2d3fad76a5557df6182..061fa93576bcd5a669ab101be61c92a85c3c9886 100644 (file)
 #include <TopoDS_Wire.hxx>
 #include <TopoDS_Shell.hxx>
 #include <TopoDS_Face.hxx>
-
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+#include <BRepProj_Projection.hxx>
+#include <BRepExtrema_ExtCC.hxx>
+#include <gp_Ax1.hxx>
+#include <gp_Ax2.hxx>
+#include <gp_Ax3.hxx>
+#include <gp_Vec.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Pln.hxx>
+#include <gp.hxx>
+#include <Precision.hxx>
 #include <QStringList>
 
 #define PYTHON_STREAM_ID "KIND_STREAM"
@@ -194,19 +207,97 @@ void HYDROData_Stream::RemoveHydraulicAxis()
   SetToUpdate( true );
 }
 
-bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile ) const
+bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile, const TopoDS_Face& thePlane,
+                                                                          Standard_Real& outPar ) const
 {
   Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
   if ( theProfile.IsNull() || aHydAxis.IsNull() )
     return false; 
 
-  TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
+  TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() ); //guide line
   TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
   if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
     return false;
 
   // TODO
-
+  return true; // temporary
+  BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
+  if(!aProjector.IsDone())
+    return false;
+  TopoDS_Shape aPrjProfile = aProjector.Shape();
+  if(aPrjProfile.IsNull())
+    return false;
+  TopoDS_Vertex aV1, aV2;
+  if(aPrjProfile.ShapeType() == TopAbs_EDGE)
+         TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);          
+  else if(aPrjProfile.ShapeType() == TopAbs_WIRE)  
+         TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);          
+  else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
+    TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
+       if(anExp.More()) {
+               TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);        
+       } else {
+         anExp.Init(aPrjProfile, TopAbs_EDGE);
+         if(anExp.More()) {
+               TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);        
+         }
+       }
+  }
+  if(aV1.IsNull() || aV2.IsNull())
+       return false;
+  gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
+  gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
+  aPnt1.SetZ(0.0);
+  aPnt2.SetZ(0.0);
+  BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2); 
+  if(!aMk.IsDone())
+    return false;
+  const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
+  Standard_Integer aNum(0);
+  
+  TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
+  for(;anExplo.More();anExplo.Next()) aNum++;
+  // check for self-intersection
+  const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
+  Standard_Boolean hasInt(false);
+  Standard_Real aSqDist(DBL_MAX);
+  Standard_Integer anIndx(0);
+  BRepExtrema_ExtCC aCC;
+  aCC.Initialize(anEdg2);
+  outPar = 0.0;
+  anExplo.Init(aHydraulicWire, TopAbs_EDGE);
+  for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
+       const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
+       if(anEdg1.IsNull())
+         continue;     
+       aCC.Perform(anEdg1);
+    if(aCC.IsDone()) {
+    for(Standard_Integer i=1; i<= aCC.NbExt();i++)
+      if(aCC.SquareDistance(i) < aSqDist) {
+        aSqDist = aCC.SquareDistance(i);
+        anIndx = i;
+               hasInt = true;          
+         }  
+       }
+       if(hasInt) {    
+      if(aSqDist <= SquareTolerance) {
+        const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
+        if(aNum > 1) {
+          TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
+                 outPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
+           } else {
+          Standard_Real aPar = aCC.ParameterOnE1(anIndx);
+                 outPar = aPar;
+           }
+           break;
+         } else {
+        if(aNum > 1) {
+          TopExp::Vertices(anEdg1, aV1, aV2);
+             outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
+           }
+         }
+       }
+  }
   return true;
 }
 
@@ -214,8 +305,15 @@ bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
 {
   if ( theProfile.IsNull() )
     return false; 
-
-  if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile ) )
+  gp_Ax2 aX2(gp::XOY());
+  gp_Ax3 aX3(aX2);
+  gp_Pln aPln(aX3);
+  BRepBuilderAPI_MakeFace aMkr(aPln);
+  if(!aMkr.IsDone())
+       return false;
+  const TopoDS_Face& aPlane = TopoDS::Face(aMkr.Shape());
+  Standard_Real aPar(.0);
+  if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
     return false; // Object is already in reference list or it has no intersection
 
   insertProfileInToOrder( theProfile );
@@ -281,13 +379,20 @@ void HYDROData_Stream::updateProfilesOrder()
   Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
   if ( aHydAxis.IsNull() )
     return;
-
+  gp_Ax2 aX2(gp::XOY());
+  gp_Ax3 aX3(aX2);
+  gp_Pln aPln(aX3);
+  BRepBuilderAPI_MakeFace aMkr(aPln);
+  if(!aMkr.IsDone())
+       return;
+  const TopoDS_Face& aPlane = TopoDS::Face(aMkr.Shape());
+  Standard_Real aPar(.0);
   HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
   for ( ; anIter.More(); anIter.Next() )
   {
     Handle(HYDROData_Profile) aProfile =
       Handle(HYDROData_Profile)::DownCast( anIter.Value() );
-    if ( aProfile.IsNull() || !HasIntersection( aProfile ) )
+    if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
       continue;
 
     insertProfileInToOrder( aProfile );
index ce9eb426555f1d6c6e3f7a704019d767fedc8cbe..4c09d9d5e6341a1d0a313909eca7108310f5b97e 100644 (file)
@@ -3,7 +3,7 @@
 #define HYDROData_Stream_HeaderFile
 
 #include "HYDROData_NaturalObject.h"
-
+#include <TopoDS_Face.hxx>
 DEFINE_STANDARD_HANDLE(HYDROData_Stream, HYDROData_NaturalObject)
 
 class Handle(HYDROData_PolylineXY);
@@ -82,8 +82,11 @@ public:
 
   /**
    * Returns true if profile has the intersection with reference hydraulic axis.
+   * Returns the parameter of inresection point on axis if axis is presented by one curve,
+   * if axis presented by set of edges the <outPar> returns a common length of segments till the intersection point. 
    */
-  HYDRODATA_EXPORT virtual bool HasIntersection( const Handle(HYDROData_Profile)& theProfile ) const;
+  HYDRODATA_EXPORT virtual bool HasIntersection( const Handle(HYDROData_Profile)& theProfile, const TopoDS_Face& thePlane,
+                                                                                               Standard_Real& outPar) const;
 
 
   /**
index 36a50ca716c99ddb49a88d8960c181cc736544c0..ba88999270a8c94396d137e3824a6f303bd94961 100755 (executable)
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
 #include <OCCViewer_ViewWindow.h>
-
+#include <gp_Ax1.hxx>
+#include <gp_Ax2.hxx>
+#include <gp_Ax3.hxx>
+#include <gp_Vec.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Pln.hxx>
+#include <gp.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
 HYDROGUI_StreamOp::HYDROGUI_StreamOp( HYDROGUI_Module* theModule, bool theIsEdit )
 : HYDROGUI_Operation( theModule ), 
   myIsEdit( theIsEdit ),
@@ -237,6 +246,13 @@ void HYDROGUI_StreamOp::onAddProfiles()
 
   HYDROData_SequenceOfObjects aVerifiedProfiles;
   HYDROData_SequenceOfObjects aSelectedProfiles = HYDROGUI_Tool::GetSelectedObjects( module() );
+  gp_Ax2 aX2(gp::XOY());
+  gp_Ax3 aX3(aX2);
+  gp_Pln aPln(aX3);
+  BRepBuilderAPI_MakeFace aMkr(aPln);
+  if(!aMkr.IsDone())   return;
+  const TopoDS_Face& aPlane = TopoDS::Face(aMkr.Shape());
+  Standard_Real aPar(.0);
   for( int i = 1, n = aSelectedProfiles.Length(); i <= n; i++ ) {
     Handle(HYDROData_Profile) aProfile = 
       Handle(HYDROData_Profile)::DownCast( aSelectedProfiles.Value( i ) );
@@ -248,7 +264,7 @@ void HYDROGUI_StreamOp::onAddProfiles()
         anInvalidProfiles << aProfileName;
       } else if ( aCurrentProfiles.contains( aProfileName ) ) { // check whether the profile is already added
         anExistingProfiles << aProfileName;
-      } else if ( !myEditedObject->HasIntersection( aProfile ) ) {  // check whether the profile has intersection
+      } else if ( !myEditedObject->HasIntersection( aProfile, aPlane, aPar ) ) {  // check whether the profile has intersection
         aHasNoIntersectionProfiles << aProfileName;
       } else {
         aVerifiedProfiles.Append( aProfile );