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