]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_Stream.cxx
Salome HOME
lot 11 (linear interpolation of stream) untested
[modules/hydro.git] / src / HYDROData / HYDROData_Stream.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROData_Stream.h"
20
21 #include "HYDROData_Document.h"
22 #include "HYDROData_PolylineXY.h"
23 #include "HYDROData_Polyline3D.h"
24 #include "HYDROData_Profile.h"
25 #include "HYDROData_ShapesGroup.h"
26 #include "HYDROData_ShapesTool.h"
27 #include "HYDROData_IAltitudeObject.h"
28 #include "HYDROData_IProfilesInterpolator.h"
29 #include "HYDROData_Tool.h"
30 #include "HYDROData_DTM.h"
31 #include "HYDROData_LISM.h"
32
33 #include <HYDROData_Bathymetry.h>
34
35 #include <TDataStd_RealArray.hxx>
36
37 #include <Precision.hxx>
38
39 #include <NCollection_DataMap.hxx>
40
41 #include <TColStd_Array1OfReal.hxx>
42 #include <TColStd_ListOfReal.hxx>
43 #include <TColStd_ListIteratorOfListOfReal.hxx>
44 #include <TColgp_Array1OfPnt.hxx>
45 #include <TColgp_HArray1OfPnt.hxx>
46
47 #include <TopoDS.hxx>
48 #include <TopoDS_Wire.hxx>
49 #include <TopoDS_Shell.hxx>
50 #include <TopoDS_Face.hxx>
51 #include <TopoDS_Edge.hxx>
52 #include <TopoDS_Vertex.hxx>
53 #include <TopExp.hxx>
54 #include <TopExp_Explorer.hxx>
55
56 #include <Bnd_Box.hxx>
57
58 #include <BRep_Builder.hxx>
59 #include <BRepBuilderAPI_MakeEdge.hxx>
60 #include <BRepBuilderAPI_MakeWire.hxx>
61 #include <BRepBuilderAPI_MakeFace.hxx>
62
63 #include <BRepBndLib.hxx>
64 #include <BRepProj_Projection.hxx>
65 #include <BRepExtrema_ExtCC.hxx>
66 #include <BRepCheck_Analyzer.hxx>
67
68 #include <gp.hxx>
69 #include <gp_Ax1.hxx>
70 #include <gp_Ax2.hxx>
71 #include <gp_Ax3.hxx>
72 #include <gp_Vec.hxx>
73 #include <gp_Pnt.hxx>
74 #include <gp_Pln.hxx>
75
76 #include <GeomAPI_Interpolate.hxx>
77 #include <Geom_BSplineCurve.hxx>
78
79 #include <TopTools_HArray1OfShape.hxx>
80 #include <TopTools_IndexedMapOfOrientedShape.hxx>
81 #include <TopTools_ListIteratorOfListOfShape.hxx>
82 #include <TopTools_SequenceOfShape.hxx>
83 #include <TopTools_IndexedMapOfShape.hxx>
84
85 #include <QColor>
86 #include <QStringList>
87 #include <QVector>
88
89 //#define DEB_STREAM 1
90 #ifdef DEB_STREAM
91 //#define DEB_HASINT 1
92 //#define DEB_UPDATE 1
93 #include <BRepTools.hxx>
94 #include <TCollection_AsciiString.hxx>
95 #endif
96
97 #define _DEVDEBUG_
98 #include "HYDRO_trace.hxx"
99
100 #include <assert.h>
101
102 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
103
104 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Stream,HYDROData_NaturalObject)
105
106
107 HYDROData_Stream::HYDROData_Stream()
108 : HYDROData_NaturalObject( Geom_3d )
109 {
110 }
111
112 HYDROData_Stream::~HYDROData_Stream()
113 {
114 }
115
116 QStringList HYDROData_Stream::DumpToPython( const QString&       thePyScriptPath,
117                                             MapOfTreatedObjects& theTreatedObjects ) const
118 {
119   QStringList aResList = dumpObjectCreation( theTreatedObjects );
120   QString aName = GetObjPyName();
121
122   Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
123   setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
124
125   HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
126   for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
127   {
128     const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
129     setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aProfile, "AddProfile" );
130   }
131
132   // Set bottom polyline if exists
133   const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
134   if ( !aBottomPolyline.IsNull() ) {
135     setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBottomPolyline, "SetBottomPolyline" );
136   }
137
138   QString aDDZs = QString::number( GetDDZ(), 'f', 3 );
139   QString aSSteps = QString::number( GetSpatialStep(), 'f', 3 );
140   aResList << QString( "%1.SetDDZ( %2 )" ).arg( aName ).arg( aDDZs );
141   aResList << QString( "%1.SetSpatialStep( %2 )" ).arg( aName ).arg( aSSteps );
142
143   aResList << QString( "" );
144   aResList << QString( "%1.Update()" ).arg( aName );
145   aResList << QString( "" );
146
147   return aResList;
148 }
149
150 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
151 {
152   HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
153
154   Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
155   if ( !aHydAxis.IsNull() )
156     aResSeq.Append( aHydAxis );
157
158   HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
159   aResSeq.Append( aSeqOfProfiles );
160
161   return aResSeq;
162 }
163
164 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve( 
165   const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
166 {
167   Handle(Geom_BSplineCurve) aBSpline;
168   GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5); 
169   anInterpolator.Perform() ;
170   if (anInterpolator.IsDone()) 
171     aBSpline = anInterpolator.Curve();
172   return aBSpline; 
173 }
174
175 void HYDROData_Stream::GetWarnings(NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>>& warnings)
176 {
177   warnings = myWarnings;
178 }  
179
180 void HYDROData_Stream::Update()
181 {
182   if (GetInterpolationMethod() == 0)
183   {
184     if (!GetHydraulicAxis().IsNull())
185       updateProfilesOrder();
186
187     // Update bottom polyline if exists
188     const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
189     if ( !aBottomPolyline.IsNull() ) {
190       if ( GenerateBottomPolyline() ) {
191         Handle(HYDROData_PolylineXY) aPolylineXY = aBottomPolyline->GetPolylineXY();
192         if ( !aPolylineXY.IsNull() ) {
193           aPolylineXY->Update();
194         }
195         aBottomPolyline->Update();
196       }
197     }
198
199     Handle(HYDROData_DTM) dtm = DTM();
200     dtm->Update();
201     UpdatePrs( dtm );
202
203     myWarnings.Clear();
204     dtm->GetWarnings(myWarnings);
205   }
206   else
207   {
208     Handle(HYDROData_LISM) lism = LISM();
209     lism->Update();
210     UpdatePrs( lism );
211
212     myWarnings.Clear();
213     //lism->GetWarnings(myWarnings);
214     //TODO warnings
215   }
216
217   HYDROData_NaturalObject::Update();
218 }
219
220 bool HYDROData_Stream::IsHas2dPrs() const
221 {
222   return true;
223 }
224
225 bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_DTM)& theDTM,
226                                             PrsDefinition&              thePrs )
227 {
228   if ( theDTM.IsNull() )
229     return false;
230
231   HYDROData_SequenceOfObjects profiles = theDTM->GetProfiles();
232   if( profiles.Length() < 2 )
233     return false;
234
235   TopoDS_Shape Out3dPres;
236   TopoDS_Shape Out2dPres;
237   TopoDS_Shape OutLeftB;
238   TopoDS_Shape OutRightB;
239   TopoDS_Shape OutInlet;
240   TopoDS_Shape OutOutlet;
241
242   theDTM->GetPresentationShapes(Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet);
243
244   thePrs.myInlet = OutInlet;
245   thePrs.myOutlet = OutOutlet;
246   thePrs.myLeftBank = OutLeftB;
247   thePrs.myRightBank = OutRightB;
248   thePrs.myPrs2D = Out2dPres;
249   thePrs.myPrs3D = Out3dPres;
250   /*std::vector<TopoDS_Wire> profiles3d;
251   profiles3d.reserve(profiles.Length());
252
253   // Pre-processing
254   HYDROData_SequenceOfObjects::Iterator anIter( profiles );
255   for (int i=1 ; anIter.More(); anIter.Next(),i++ )
256   {
257     Handle(HYDROData_Profile) aProfile =
258       Handle(HYDROData_Profile)::DownCast( anIter.Value() );
259
260     if ( aProfile.IsNull() )
261       continue;
262
263     const TopoDS_Shape& aProfileShape = aProfile->GetShape3D();
264     //TopExp_Explorer exp(aProfileShape, TopAbs_EDGE);
265     profiles3d.push_back( TopoDS::Wire(aProfileShape) );
266   }*/
267
268   return true;
269 }
270
271 void HYDROData_Stream::internalUpdatePrs( const PrsDefinition& aResultPrs )
272 {
273   SetShape3D( aResultPrs.myPrs3D );
274   SetTopShape( aResultPrs.myPrs2D );
275
276   // Create the stream groups
277   QString aLeftGroupName = GetName() + "_Left_Bank";
278
279   Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
280   aLeftGroup->SetName( aLeftGroupName );
281   aLeftGroup->AddShape( aResultPrs.myLeftBank );
282
283   QString aRightGroupName = GetName() + "_Right_Bank";
284
285   Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
286   aRightGroup->SetName( aRightGroupName );
287   aRightGroup->AddShape( aResultPrs.myRightBank );
288
289   QString anInGroupName = GetName() + "_Inlet";
290
291   Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
292   anInGroup->SetName( anInGroupName );
293   anInGroup->AddShape( aResultPrs.myInlet );
294
295   QString anOutGroupName = GetName() + "_Outlet";
296   
297   Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
298   anOutGroup->SetName( anOutGroupName );
299   anOutGroup->AddShape( aResultPrs.myOutlet );
300 }
301
302
303 void HYDROData_Stream::UpdatePrs( const Handle(HYDROData_DTM)& theDTM )
304 {
305   HYDROData_NaturalObject::Update();
306   
307   PrsDefinition aResultPrs;
308   if ( !CreatePresentations( theDTM, aResultPrs ) )
309     return;
310
311   internalUpdatePrs(aResultPrs);
312 }
313
314 void HYDROData_Stream::UpdatePrs( const Handle(HYDROData_LISM)& theLISM )
315 {
316   HYDROData_NaturalObject::Update();
317   PrsDefinition prsDef;
318   theLISM->GetShapePresentations(prsDef);
319
320   internalUpdatePrs(prsDef);
321 }
322
323 QColor HYDROData_Stream::DefaultFillingColor() const
324 {
325   return QColor( Qt::green );
326 }
327
328 QColor HYDROData_Stream::DefaultBorderColor() const
329 {
330   return QColor( Qt::transparent );
331 }
332
333 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
334 {
335   if ( theHydAxis.IsNull() )
336     return true;
337
338   TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
339   if ( aHydraulicShape.IsNull() || 
340        aHydraulicShape.ShapeType() != TopAbs_WIRE ||
341        BRep_Tool::IsClosed( aHydraulicShape ) )
342     return false; // The polyline must be a single not closed wire
343
344   return true;
345 }
346
347 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
348 {
349   HYDROData_SequenceOfObjects aGroups = GetGroups();
350   return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 1);
351 }
352
353 TopoDS_Shape HYDROData_Stream::GetRightShape() const
354 {
355   HYDROData_SequenceOfObjects aGroups = GetGroups();
356   return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 2);
357 }
358
359 TopoDS_Shape HYDROData_Stream::GetInletShape() const
360 {
361   HYDROData_SequenceOfObjects aGroups = GetGroups();
362   return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 3);
363 }
364
365 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
366 {
367   HYDROData_SequenceOfObjects aGroups = GetGroups();
368   return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 4);
369 }
370
371 Handle(HYDROData_DTM) HYDROData_Stream::DTM() const
372 {
373   const_cast<HYDROData_Stream*>( this )->checkAndSetAltitudeObject();
374   return Handle(HYDROData_DTM)::DownCast( GetAltitudeObject() );
375 }
376
377 Handle(HYDROData_LISM) HYDROData_Stream::LISM() const
378 {
379   const_cast<HYDROData_Stream*>( this )->checkAndSetAltitudeObject();
380   return Handle(HYDROData_LISM)::DownCast( GetAltitudeObject() );
381 }
382
383 double HYDROData_Stream::GetDDZ() const
384 {
385   return DTM()->GetDDZ();
386 }
387
388 void HYDROData_Stream::SetDDZ( double theDDZ )
389 {
390   DTM()->SetDDZ( theDDZ );
391   Changed( Geom_3d );
392 }
393
394 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetLeftBank() const
395 {
396   return LISM()->GetLeftBank();
397 }
398
399 void HYDROData_Stream::SetLeftBank( const Handle(HYDROData_PolylineXY)& theBank )
400 {
401   LISM()->SetLeftBank( theBank );
402   Changed( Geom_3d );
403 }
404
405 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetRightBank() const
406 {
407   return LISM()->GetRightBank();
408 }
409
410 void HYDROData_Stream::SetRightBank( const Handle(HYDROData_PolylineXY)& theBank )
411 {
412   LISM()->SetRightBank( theBank );
413   Changed( Geom_3d );
414 }
415   
416   
417 double HYDROData_Stream::GetHaxStep() const
418 {
419   return LISM()->GetHaxStep();
420 }
421
422 void HYDROData_Stream::SetHaxStep( double theHaxStep )
423 {
424   LISM()->SetHaxStep( theHaxStep );
425   Changed( Geom_3d );
426 }
427
428 int HYDROData_Stream::GetNbProfilePoints() const
429 {
430   return LISM()->GetNbProfilePoints();
431 }
432
433 void HYDROData_Stream::SetNbProfilePoints( int theNbPoints )
434 {
435   LISM()->SetNbProfilePoints( theNbPoints );
436   Changed( Geom_3d );
437 }
438   
439 double HYDROData_Stream::GetSpatialStep() const
440 {
441   if (GetInterpolationMethod() == 0)
442     return DTM()->GetSpatialStep();
443   else
444     return LISM()->GetHaxStep();
445 }
446
447 void HYDROData_Stream::SetSpatialStep( double theSpatialStep )
448 {
449   if (GetInterpolationMethod() == 0 )  
450     DTM()->SetSpatialStep( theSpatialStep );
451   else
452     LISM()->SetHaxStep( theSpatialStep );
453   Changed( Geom_3d );
454 }
455
456 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
457 {
458   if (GetInterpolationMethod() == 0)
459   {
460     if ( !IsValidAsAxis( theAxis ) )
461       return false;
462
463     Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
464     if ( IsEqual( aPrevAxis, theAxis ) )
465       return true;
466
467     SetReferenceObject( theAxis, DataTag_HydraulicAxis );
468
469     // Update the order of profiles
470     updateProfilesOrder();
471
472     // Indicate model of the need to update the stream presentation
473     Changed( Geom_3d );
474   }
475   else
476   {
477     LISM()->SetHydraulicAxis( theAxis );
478     Changed( Geom_3d );
479   }
480
481   return true;
482 }
483
484 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
485 {
486   if (GetInterpolationMethod() == 0)
487     return Handle(HYDROData_PolylineXY)::DownCast( GetReferenceObject( DataTag_HydraulicAxis ) );
488   else
489     return LISM()->GetHydraulicAxis();
490 }
491
492 void HYDROData_Stream::RemoveHydraulicAxis()
493 {
494   Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
495   if ( aPrevAxis.IsNull() )
496     return;
497
498   ClearReferenceObjects( DataTag_HydraulicAxis );
499
500   // We remove the reference profiles
501   RemoveProfiles();
502
503   // Indicate model of the need to update the stream presentation
504   Changed( Geom_3d );
505 }
506
507 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile,
508                                         const TopoDS_Face&               thePlane,
509                                         Standard_Real&                   theOutPar ) const
510 {
511   Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
512   return HasIntersection( aHydAxis, theProfile, thePlane, theOutPar );
513 }
514
515 #include <BRepAlgo_NormalProjection.hxx>
516
517 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis, 
518                                         const Handle(HYDROData_Profile)&    theProfile, 
519                                         const TopoDS_Face&                  thePlane,
520                                         Standard_Real&                      theOutPar )
521 {
522   if ( theProfile.IsNull() /*|| !IsValidAsAxis( theHydAxis )*/ )
523     return false; 
524
525   if (theHydAxis.IsNull())
526     return true; //empty h_axis; its's OK
527
528   TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
529   TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
530   if ( aProfileWire.IsNull() )
531     {
532       DEBTRACE("aProfileWire.IsNull");
533       return false;
534     }
535
536   //BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
537   BRepAlgo_NormalProjection nproj(thePlane);
538   nproj.Add(aProfileWire);
539   nproj.SetDefaultParams();
540   nproj.Build();
541   if(!nproj.IsDone())
542     {
543       DEBTRACE("!nproj.IsDone");
544       return false;
545     }
546   TopoDS_Shape aPrjProfile = nproj.Projection();
547   if(aPrjProfile.IsNull())
548     {
549       DEBTRACE("aPrjProfile.IsNull");
550       return false;
551     }
552   TopoDS_Vertex aV1, aV2;
553   if(aPrjProfile.ShapeType() == TopAbs_EDGE)
554     TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
555   else if(aPrjProfile.ShapeType() == TopAbs_WIRE)  
556     TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
557   else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
558     TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
559     if(anExp.More()) {
560       TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
561     } else {
562       anExp.Init(aPrjProfile, TopAbs_EDGE);
563       if(anExp.More()) {
564         TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
565       }
566     }
567   }
568   if(aV1.IsNull() || aV2.IsNull())
569     {
570       DEBTRACE("aV1.IsNull() || aV2.IsNull()");
571       return false;
572     }
573   gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
574   gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
575   aPnt1.SetZ(0.0);
576   aPnt2.SetZ(0.0);
577   BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2); 
578   if(!aMk.IsDone())
579     {
580       DEBTRACE("!aMk.IsDone()");
581       return false;
582     }
583   const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
584   Standard_Integer aNum(0);
585   
586   TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
587   for(;anExplo.More();anExplo.Next()) aNum++;
588   // check for self-intersection
589   const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
590   Standard_Boolean hasInt(false);
591   Standard_Real aSqDist(DBL_MAX);
592   Standard_Integer anIndx(0);
593   BRepExtrema_ExtCC aCC;
594   aCC.Initialize(anEdg2);
595   theOutPar = 0.0;
596   anExplo.Init(aHydraulicWire, TopAbs_EDGE);
597   for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
598     const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
599     if(anEdg1.IsNull())
600       continue;
601     Standard_Boolean hasSol(false);
602     aCC.Perform(anEdg1);
603     if(aCC.IsDone()) {
604     // find minimal dist
605     for(Standard_Integer i=1; i<= aCC.NbExt();i++)
606       if(aCC.SquareDistance(i) < aSqDist) {
607         aSqDist = aCC.SquareDistance(i);
608         anIndx = i;
609         hasSol = true;
610       }  
611     }
612     if(hasSol) {
613       if(aSqDist <= SquareTolerance) { // hasInt
614         const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
615         if(aNum > 1) {
616           TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
617           theOutPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
618         } else {
619           Standard_Real aPar = aCC.ParameterOnE1(anIndx);
620           theOutPar = aPar;
621         }
622         hasInt = true;
623         break;
624       } else {
625           // no ints-n
626         if(aNum > 1) {
627           TopExp::Vertices(anEdg1, aV1, aV2);
628           theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
629         }
630       }
631     } else if(aNum > 1) {
632       TopExp::Vertices(anEdg1, aV1, aV2);
633       theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
634     }
635   }
636   if(hasInt)
637     return true;
638   DEBTRACE("!hasInt " << aPnt1.X() << " " << aPnt1.Y() << " " << aPnt2.X() << " " << aPnt2.Y() << " --- " << aSqDist);
639   return false;
640 }
641
642 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
643 {
644   if ( theProfile.IsNull() )
645     return false;
646
647  // Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
648  // if ( aHydAxis.IsNull() )
649  //   return false;
650
651   TopoDS_Face aPlane;
652   BuildRefFace( aPlane );
653
654   Standard_Real aPar(.0);
655   if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
656     return false; // Object is already in reference list or it has no intersection
657   //DEBTRACE("AddProfile - insertParameter " << aPar);
658   int aProfileIndex = insertParameter( aPar );
659   insertProfileInToOrder( theProfile, aProfileIndex );
660
661   if (GetInterpolationMethod()==0)
662     DTM()->SetProfiles( GetProfiles() );
663   else
664     LISM()->SetProfiles( GetProfiles() );
665   
666   // Indicate model of the need to update the stream presentation
667   Changed( Geom_3d );
668
669   return true;
670 }
671
672 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
673                                     const bool&                        theIsToOrder )
674 {
675   DEBTRACE(" --- SetProfiles " <<theIsToOrder );
676   if ( theIsToOrder )
677   {
678     for ( int i = 1; i <= theProfiles.Length(); ++i )
679     {
680       Handle(HYDROData_Profile) aProfile = 
681         Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) );
682       if ( aProfile.IsNull() )
683         continue;
684
685       if ( !AddProfile( aProfile ) )
686       {
687         DTM()->SetProfiles( HYDROData_SequenceOfObjects() );
688         return false;
689       }
690     }
691   }
692   else // Just store the sequence of objects as is
693   {
694     bool anIsToUpdate = true;
695
696     HYDROData_SequenceOfObjects anOldProfiles = GetProfiles();
697     if ( anOldProfiles.Length() == theProfiles.Length() )
698     {
699       anIsToUpdate = false;
700
701       for ( int i = 1; i <= theProfiles.Length(); ++i )
702       {
703         Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i );
704         Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i );
705         if ( !IsEqual( anOldProfile, aNewProfile ) )
706         {
707           anIsToUpdate = true;
708           break;
709         }
710       }
711     }
712     
713     SetReferenceObjects( theProfiles, DataTag_Profile );
714
715     if ( anIsToUpdate )
716       Changed( Geom_3d );
717   }
718
719   if (GetInterpolationMethod()==0)
720     DTM()->SetProfiles( GetProfiles() );
721   else
722     LISM()->SetProfiles( GetProfiles() );
723   return true;
724 }
725
726 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
727 {
728   return GetReferenceObjects( DataTag_Profile );
729 }
730
731 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
732 {
733   if ( theProfile.IsNull() )
734     return false;
735
736   int aProfileIndex = -1;
737
738   HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
739   HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
740   for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
741   {
742     Handle(HYDROData_Profile) aProfile =
743       Handle(HYDROData_Profile)::DownCast( anIter.Value() );
744     if ( aProfile.IsNull() )
745       continue;
746
747     if ( IsEqual( theProfile, aProfile ) )
748     {
749       aProfileIndex = i;
750       break;
751     }
752   }
753
754   if ( aProfileIndex == -1 )
755     return false;
756
757   RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
758
759   // Remove parameter for removed profile
760   removeParameter( aProfileIndex );
761
762   // Indicate model of the need to update the stream presentation
763   Changed( Geom_3d );
764
765   return true;
766 }
767
768 void HYDROData_Stream::RemoveProfiles()
769 {
770   ClearReferenceObjects( DataTag_Profile );
771
772   // Remove the parameters array
773   removeParametersArray();
774
775   // Indicate model of the need to update the stream presentation
776   Changed( Geom_3d );
777 }
778
779
780 int HYDROData_Stream::GetInterpolationMethod() const
781 {
782   return GetInteger( DataTag_InterpMethod );
783 }
784
785 void HYDROData_Stream::SetInterpolationMethod( int theMethod ) //if DTM => 0 ; if LISM => 1
786 {
787   SetInteger( DataTag_InterpMethod, theMethod );
788   Changed( Geom_3d );
789 }
790
791
792 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
793                                                const int                        theBeforeIndex )
794 {
795   //Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
796   if ( theProfile.IsNull() )
797     return; 
798
799   //TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
800   TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
801   if ( aProfileWire.IsNull() )
802     return;
803
804   if ( theBeforeIndex == -1 )
805     AddReferenceObject( theProfile, DataTag_Profile );
806   else
807     InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
808 }
809
810 void HYDROData_Stream::BuildRefFace( TopoDS_Face& thePlane )
811 {
812   thePlane = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1))).Face();
813 }
814
815 void HYDROData_Stream::updateProfilesOrder()
816 {
817   HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
818   if ( aRefProfiles.IsEmpty() )
819     return;
820
821   // At first we remove all profiles from order
822   RemoveProfiles();
823
824   Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
825   if ( aHydAxis.IsNull() )
826     return; 
827
828   TopoDS_Face aPlane;
829   BuildRefFace( aPlane );
830
831   Standard_Real aPar( .0 );
832
833 #ifdef DEB_HASINT
834   BRep_Builder aBB;
835   TopoDS_Compound aCmp;
836   aBB.MakeCompound(aCmp);
837 #endif
838
839   HYDROData_DataMapOfRealOfHDProfile aDM;  
840   TColStd_ListOfReal aList;
841   HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
842   for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
843   {
844     Handle(HYDROData_Profile) aProfile =
845       Handle(HYDROData_Profile)::DownCast( anIter.Value() );
846 #ifdef DEB_HASINT
847   TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
848   aBB.Add( aCmp, aProfileWire ); 
849 #endif
850     if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
851       continue;
852     
853     aDM.Bind( aPar, aProfile );
854     aList.Append( aPar );
855   }
856   
857   if ( aList.IsEmpty() )
858     return;
859
860   QVector<double> anArr( aList.Extent() );
861
862   TColStd_ListIteratorOfListOfReal it( aList );
863   for ( int j = 1; it.More(); it.Next(), j++ )
864     anArr[j-1] = it.Value();
865
866   // sorting
867   if ( aList.Extent() > 1 )
868   {
869     //TCollection_CompareOfReal Compar;
870     //SortTools_QuickSortOfReal::Sort( anArr, Compar );
871     std::sort( anArr.begin(), anArr.end() );
872
873     for (int j = 1; j <= anArr.size(); j++) {
874       const Standard_Real aKey =  anArr[j-1];
875       const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
876       insertProfileInToOrder( aProfile );
877     }
878   } else if ( aList.Extent() == 1 ) {
879      const Standard_Real aKey = aList.Last();
880      const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
881      insertProfileInToOrder( aProfile );
882   } 
883
884   setParametersArray( anArr );
885
886 #ifdef DEB_HASINT
887   TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
888   BRepTools::Write(aHydraulicWire, "Path.brep");
889   BRepTools::Write(aCmp, "Prof.brep");
890 #endif
891 }
892
893 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
894 {
895   int InterpMethod = GetInterpolationMethod();
896   if (InterpMethod == 1)
897     return KIND_LISM;
898   else
899     return KIND_DTM;
900 }
901
902 void HYDROData_Stream::setParametersArray( const QVector<double>& theArray )
903 {
904   if ( theArray.size() == 0 )
905   {
906     removeParametersArray();
907     return;
908   }
909
910   TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
911   
912   int n = theArray.size();
913   Handle(TDataStd_RealArray) aParamsArray = 
914     TDataStd_RealArray::Set( aLabel, 1, n );
915   aParamsArray->SetID(TDataStd_RealArray::GetID());
916   for ( int i = 0; i < n; ++i )
917   {
918     const Standard_Real& aParam = theArray[i];
919     aParamsArray->SetValue( i+1, aParam );
920   }
921 }
922
923 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
924 {
925   TColStd_Array1OfReal* anArray = NULL;
926
927   TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
928   if ( !aLabel.IsNull() )
929   {
930     Handle(TDataStd_RealArray) aParamsArray;
931     if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
932     {
933       anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
934       for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
935       {
936         const Standard_Real& aParam = aParamsArray->Value( i );
937         anArray->SetValue( i, aParam );
938       }
939     }
940   }
941
942   return anArray;
943 }
944
945 void HYDROData_Stream::removeParametersArray()
946 {
947   TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
948   if ( !aLabel.IsNull() )
949     aLabel.ForgetAllAttributes();
950 }
951
952 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
953 {
954   int aResIndex = -1;
955
956   TColStd_Array1OfReal* anArr = getParametersArray();
957   if ( anArr )
958   {
959     aResIndex = 0;
960
961     QVector<double> aNewArr( anArr->Upper() +1 );
962     bool isInserted = false;
963     for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
964     {
965       const Standard_Real& aStoredParam = anArr->Value( i );
966       if ( !isInserted )
967       {
968         if ( theParam > aStoredParam )
969         {
970           aResIndex++;
971         }
972         else
973         {
974           if (j<=n+1)
975             aNewArr[j-1] = theParam;
976           isInserted = true;
977           ++j;
978         }
979       }
980       if (j<=n+1)
981         aNewArr[j-1] = aStoredParam;
982     }
983
984     if ( !isInserted )
985     {
986       aResIndex = -1;
987       aNewArr[aNewArr.size()-1] = theParam;
988     }
989     
990     setParametersArray( aNewArr );
991     delete anArr;
992   }
993   else
994   {
995     QVector<double> aNewArr( 1 );
996     aNewArr[0] = theParam;
997     setParametersArray( aNewArr );
998   }
999
1000   return aResIndex;
1001 }
1002
1003 void HYDROData_Stream::removeParameter( const int& theIndex )
1004 {
1005   TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
1006   if ( aLabel.IsNull() )
1007     return;
1008
1009   Handle(TDataStd_RealArray) aParamsArray;
1010   if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
1011     return;
1012
1013   if ( aParamsArray->Length() == 1 )
1014   {
1015     removeParametersArray();
1016     return;
1017   }
1018
1019   QVector<double> aNewArr( aParamsArray->Upper() - 2 );
1020
1021   for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
1022   {
1023     const Standard_Real& aStoredParam = aParamsArray->Value( i );
1024     if ( k == theIndex )
1025       continue;
1026
1027     aNewArr[j-1] = aStoredParam;
1028     ++j;
1029   }
1030
1031   setParametersArray( aNewArr );
1032 }
1033
1034 bool HYDROData_Stream::GenerateBottomPolyline()
1035 {
1036   // Get the document
1037   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
1038   if ( aDocument.IsNull() ) {
1039     return false;
1040   }
1041
1042   // Collect bottom points ( one bottom point from each profile of the stream )
1043   HYDROData_Profile::ProfilePoints aBottomPoints;
1044   
1045   HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
1046   for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; i++ ) {
1047     const Handle(HYDROData_Profile) aProfile = 
1048       Handle(HYDROData_Profile)::DownCast( aSeqOfProfiles.Value( i ) );
1049     if ( aProfile.IsNull() ) {
1050       continue;
1051     }
1052     
1053     aBottomPoints.Append( aProfile->GetBottomPoint() );
1054   }
1055
1056   int aNbBottomPoints = aBottomPoints.Size();
1057
1058   if ( aNbBottomPoints < 2 ) {
1059     return false;
1060   }
1061
1062   // Create bottom polyline object if the stream doesn't contain it yet
1063   Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
1064   if ( aBottom.IsNull() ) {
1065     aBottom = Handle(HYDROData_Polyline3D)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );  
1066     QString aBaseName = GetName() + "_bottom";
1067     QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
1068     aBottom->SetName( aName );
1069
1070     SetReferenceObject( aBottom, DataTag_BottomPolyline );
1071   }
1072   
1073   // Create 2D polyline if the bottom polyline doesn't contain it yet
1074   Handle(HYDROData_PolylineXY) aPolylineXY = aBottom->GetPolylineXY();
1075   if ( aPolylineXY.IsNull() ) {
1076     aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
1077     QString aBaseName = GetName() + "_bottom_2d";
1078     QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
1079     aPolylineXY->SetName( aName );
1080     aBottom->SetPolylineXY( aPolylineXY, false );
1081   }
1082
1083   aPolylineXY->RemoveSections();
1084   aPolylineXY->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false );
1085   
1086   // Create profile if the bottom polyline doesn't contain it yet
1087   Handle(HYDROData_ProfileUZ) aProfileUZ = aBottom->GetProfileUZ();
1088   if ( aProfileUZ.IsNull() ) {
1089     Handle(HYDROData_Profile) aProfile = 
1090       Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
1091     QString aBaseName = GetName() + "_bottom_profile";
1092     QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
1093     aProfile->SetName( aName );
1094     aProfileUZ = aProfile->GetProfileUZ( true );
1095     aBottom->SetProfileUZ( aProfileUZ );
1096   }
1097   
1098   aProfileUZ->RemoveSection( 0 );
1099
1100   aProfileUZ->CalculateAndAddPoints(aBottomPoints, aPolylineXY, true);
1101   
1102   return true;
1103 }
1104
1105 Handle(HYDROData_Polyline3D) HYDROData_Stream::GetBottomPolyline() const
1106 {
1107   return Handle(HYDROData_Polyline3D)::DownCast( 
1108            GetReferenceObject( DataTag_BottomPolyline ) );
1109 }
1110
1111 bool HYDROData_Stream::SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom )
1112 {
1113   if ( theBottom.IsNull() ) {
1114     return false;
1115   }
1116
1117   SetReferenceObject( theBottom, DataTag_BottomPolyline );
1118
1119   return true;
1120 }
1121
1122 bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpolator )
1123 {
1124   // Get the document
1125   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
1126   if ( aDocument.IsNull() ) {
1127     return false;
1128   }
1129   
1130   if ( theInterpolator->GetCalculatedProfilesNumber() < 1 ) {
1131     theInterpolator->Calculate();
1132   }
1133
1134   if ( theInterpolator->GetErrorCode() != OK ) {
1135     return false;
1136   }
1137
1138   bool isOK = true;
1139
1140   for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) {
1141     // Get calculated point coordinates
1142     HYDROData_Profile::ProfilePoints aResultPoints = theInterpolator->GetResultProfilePoints( aProfileInd );
1143     if ( aResultPoints.IsEmpty() ) {
1144       isOK = false;
1145       continue;
1146     }
1147         
1148     // Create profile object
1149     Handle(HYDROData_Profile) aProfile = 
1150       Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
1151     QString aBaseName = GetName() + "_interp_profile";
1152     QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName );
1153     aProfile->SetName( aName );
1154
1155     // Fill the profile with points
1156     aProfile->SetProfilePoints( aResultPoints );
1157
1158     // Add profile to the stream
1159     bool isAdded = AddProfile( aProfile );
1160     if ( !isAdded ) {
1161       aProfile->Remove();
1162     }
1163     else
1164       aProfile->Update();
1165   }
1166
1167   if ( isOK )
1168     Update();
1169
1170   return isOK;
1171 }
1172
1173 void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
1174                                bool isGenerateNewName ) const
1175 {
1176   // Get the document
1177   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
1178   if ( aDocument.IsNull() ) {
1179     return;
1180   }
1181
1182   // Call base method
1183   HYDROData_Entity::CopyTo( theDestination, isGenerateNewName );
1184
1185   Handle(HYDROData_Stream) aStreamCopy = 
1186     Handle(HYDROData_Stream)::DownCast( theDestination );
1187
1188   // Copy bottom polyline if exists
1189   if ( !aStreamCopy.IsNull() ) {
1190     const Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
1191     if ( !aBottom.IsNull() ) {
1192       aStreamCopy->ClearReferenceObjects( DataTag_BottomPolyline );
1193       aStreamCopy->GenerateBottomPolyline();
1194       const Handle(HYDROData_Polyline3D) aBottomCopy = aStreamCopy->GetBottomPolyline();
1195       if ( !aBottomCopy.IsNull() && !aBottomCopy->GetPolylineXY().IsNull() ) {
1196         aBottomCopy->GetPolylineXY()->Update();
1197         aBottomCopy->Update();
1198       }
1199     }
1200   }
1201 }
1202 void HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt)     theArrayOfFPnt,
1203                                             const Handle(TColgp_HArray1OfPnt)     theArrayOfLPnt,
1204                                             const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
1205                                             PrsDefinition&                        thePrs )
1206 {
1207
1208   HYDROData_Bathymetry::AltitudePoints left;
1209   for (int i = theArrayOfLPnt->Lower(); i <= theArrayOfLPnt->Upper(); i++)
1210   {
1211     left.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfLPnt->Value(i).X(), 
1212       theArrayOfLPnt->Value(i).Y(),
1213       theArrayOfLPnt->Value(i).Z()));
1214   }
1215
1216   HYDROData_Bathymetry::AltitudePoints right;
1217   for (int i = theArrayOfFPnt->Lower(); i <= theArrayOfFPnt->Upper(); i++)
1218   {
1219     right.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfFPnt->Value(i).X(), 
1220       theArrayOfFPnt->Value(i).Y(),
1221       theArrayOfFPnt->Value(i).Z()));
1222   }
1223
1224   std::vector<HYDROData_Bathymetry::AltitudePoints> dummy;
1225   TopTools_IndexedMapOfOrientedShape ll = HYDROData_DTM::Create3DShape(left, right, dummy);
1226
1227   TopoDS_Shape LB, RB, IL, OL;
1228
1229   if (!ll.IsEmpty())
1230   {
1231     TopAbs_ShapeEnum ll1_sht = ll(1).ShapeType();
1232     TopAbs_ShapeEnum ll2_sht = ll(2).ShapeType();
1233     if ((ll1_sht == TopAbs_WIRE || ll1_sht == TopAbs_EDGE) &&
1234       (ll2_sht == TopAbs_WIRE || ll2_sht == TopAbs_EDGE))
1235     {
1236       LB = ll(1);
1237       RB = ll(2);
1238     }
1239   }
1240
1241   IL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Lower())); //TODO check that
1242   OL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Upper()));
1243
1244   //make new compound so it's shapes will be in known order to build correct projection
1245   BRep_Builder BB;
1246   TopoDS_Compound newCmp;
1247   BB.MakeCompound(newCmp);
1248   BB.Add(newCmp, LB);
1249   BB.Add(newCmp, IL);
1250   BB.Add(newCmp, OL);
1251   BB.Add(newCmp, RB);
1252
1253   thePrs.myPrs3D = newCmp;
1254
1255   TopTools_SequenceOfShape LS;
1256   //HYDROData_DTM::Get2dFaceFrom3dPres( newCmp, TopoDS::Face(thePrs.myPrs2D), &LS, ind );
1257   
1258   HYDROData_DTM::GetPlanarFaceFromBanks(TopoDS::Edge(LB), TopoDS::Edge(RB), TopoDS::Face(thePrs.myPrs2D), &LS);
1259
1260 #ifndef NDEBUG
1261   TopTools_IndexedMapOfShape EE;
1262   TopExp::MapShapes(thePrs.myPrs2D, TopAbs_EDGE, EE);
1263   int noncontNb = 0;
1264   for (int i = 1; i <= 4; i++)
1265   {
1266     TopoDS_Shape W = LS(i);
1267     TopTools_IndexedMapOfShape EW;
1268     TopExp::MapShapes(W, TopAbs_EDGE, EW);
1269     for (int k = 1; k <= EW.Extent(); k++)
1270       noncontNb += !EE.Contains(EW(k));
1271   }
1272   //noncontNb > 0 => some problem with edge history
1273   assert(noncontNb == 0);
1274 #endif
1275
1276   thePrs.myLeftBank = LS(1);  
1277   thePrs.myInlet = LS(2);  
1278   thePrs.myOutlet = LS(3);  
1279   thePrs.myRightBank = LS(4);
1280
1281 }