Salome HOME
lot 10 - warnings for DTM - untested
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_StreamOp.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 "HYDROGUI_StreamOp.h"
20
21 #include "HYDROGUI_Module.h"
22 #include <HYDROGUI_DataObject.h>
23 #include "HYDROGUI_Shape.h"
24 #include "HYDROGUI_StreamDlg.h"
25 #include "HYDROGUI_Tool.h"
26 #include "HYDROGUI_Tool2.h"
27 #include "HYDROGUI_UpdateFlags.h"
28
29 #include <HYDROData_Document.h>
30 #include <HYDROData_PolylineXY.h>
31 #include <HYDROData_Profile.h>
32 #include <HYDROData_DTM.h>
33
34 #include <LightApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <LightApp_UpdateFlags.h>
37
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_Desktop.h>
40 #include <QColor>
41 #include <QApplication>
42
43
44 #include <OCCViewer_ViewManager.h>
45 #include <OCCViewer_ViewModel.h>
46 #include <OCCViewer_ViewWindow.h>
47 #include <gp_Ax1.hxx>
48 #include <gp_Ax2.hxx>
49 #include <gp_Ax3.hxx>
50 #include <gp_Vec.hxx>
51 #include <gp_Pnt.hxx>
52 #include <gp_Pln.hxx>
53 #include <gp.hxx>
54 #include <TopoDS_Face.hxx>
55 #include <TopoDS.hxx>
56 #include <BRepBuilderAPI_MakeFace.hxx>
57 #include <QSet>
58
59 void insertProfileInToOrder( const QString& theProfileName,
60                              const double&  theProfilePar,
61                              QStringList&   theProfiles,
62                              QList<double>& theProfileParams )
63 {
64   bool anIsInserted = false;
65   for ( int k = 0; k < theProfileParams.length(); ++k )
66   {
67     const double& aParam = theProfileParams.value( k );
68     if ( theProfilePar < aParam )
69     {
70       theProfiles.insert( k, theProfileName );
71       theProfileParams.insert( k, theProfilePar );
72       anIsInserted = true;
73       break;
74     }
75   }
76   
77   if ( !anIsInserted )
78   {
79     theProfiles << theProfileName;
80     theProfileParams << theProfilePar;
81   }
82 }
83
84 HYDROGUI_StreamOp::HYDROGUI_StreamOp( HYDROGUI_Module* theModule, bool theIsEdit )
85 : HYDROGUI_Operation( theModule ), 
86   myIsEdit( theIsEdit ),
87   myPreviewPrs( NULL )
88 {
89   setName( theIsEdit ? tr( "EDIT_STREAM" ) : tr( "CREATE_STREAM" ) );
90 }
91
92 HYDROGUI_StreamOp::~HYDROGUI_StreamOp()
93 {
94   erasePreview();
95 }
96
97 void HYDROGUI_StreamOp::startOperation()
98 {
99   HYDROGUI_Operation::startOperation();
100
101   if ( !myIsEdit || isApplyAndClose() )
102     myEditedObject.Nullify();
103   myHydAxis.clear();
104   myProfiles.clear();
105   myProfileParams.clear();
106
107   // Get panel and reset its state
108   HYDROGUI_StreamDlg* aPanel = (HYDROGUI_StreamDlg*)inputPanel();
109   aPanel->reset();
110
111   QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STREAM_NAME" ) );
112   if ( myIsEdit )
113   {
114     if ( isApplyAndClose() )
115       myEditedObject =
116         Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
117     if ( !myEditedObject.IsNull() )
118     {
119       anObjectName = myEditedObject->GetName();
120
121       // Hydraulic axis
122       Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis();
123       
124       TopoDS_Face aPlane;
125       HYDROData_Stream::BuildRefFace( aPlane ) ;
126       if ( !aHydraulicAxis.IsNull() )
127         myHydAxis = aHydraulicAxis->GetName();
128
129       // Stream profiles
130       HYDROData_SequenceOfObjects aStreamProfiles = myEditedObject->GetProfiles();
131       for ( int i = 1, n = aStreamProfiles.Length(); i <= n; ++i )
132       {
133         Handle(HYDROData_Profile) aProfile = 
134           Handle(HYDROData_Profile)::DownCast( aStreamProfiles.Value( i ) );
135         if ( aProfile.IsNull() )
136           continue;
137
138         QString aProfileName = aProfile->GetName();        
139         myProfiles      << aProfileName;
140
141         if (!aHydraulicAxis.IsNull())
142         {
143           Standard_Real aProfilePar = 0.0;
144           HYDROData_Stream::HasIntersection( aHydraulicAxis, aProfile, aPlane, aProfilePar );
145           myProfileParams << aProfilePar;
146         }
147
148       }      
149
150     }
151   }
152
153   // Update the panel
154   // set the edited object name
155   aPanel->setObjectName( anObjectName );
156
157   // set the existing 2D polylines names to the panel
158   aPanel->setAxisNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
159
160   if (myIsEdit)
161   {
162     aPanel->setDDZ( myEditedObject->GetDDZ() );
163     aPanel->setSpatialStep( myEditedObject->GetSpatialStep() );
164   }
165
166   // synchronize the panel state with the edited object state
167   updatePanelData();
168
169   // Create preview
170   createPreview();
171 }
172
173 void HYDROGUI_StreamOp::abortOperation()
174 {
175   erasePreview();
176   HYDROGUI_Operation::abortOperation();
177 }
178
179 void HYDROGUI_StreamOp::commitOperation()
180 {
181   erasePreview();
182   HYDROGUI_Operation::commitOperation();
183 }
184
185 HYDROGUI_InputPanel* HYDROGUI_StreamOp::createInputPanel() const
186 {
187   HYDROGUI_StreamDlg* aPanel = new HYDROGUI_StreamDlg( module(), getName() );
188
189   connect( aPanel, SIGNAL( AddProfiles() ), this, SLOT( onAddProfiles() ) );
190   connect( aPanel, SIGNAL( RemoveProfiles( const QStringList& ) ), 
191            this, SLOT( onRemoveProfiles( const QStringList& ) ) );
192   connect( aPanel, SIGNAL( AxisChanged( const QString& ) ), 
193            this, SLOT( onAxisChanged( const QString& ) ) );
194
195   connect( aPanel, SIGNAL( DDZValueChanged( double ) ),  this, SLOT( onDDZValueChanged( double ) ) );
196   connect( aPanel, SIGNAL( SSValueChanged( double ) ),  this, SLOT( onSSValueChanged( double ) ) );
197   return aPanel;
198 }
199
200 void HYDROGUI_StreamOp::apply()
201 {
202   QApplication::setOverrideCursor( Qt::WaitCursor );
203
204   startDocOperation();
205
206   int anUpdateFlags = 0;
207   QString anErrorMsg;
208
209   bool aResult = false;
210   QStringList aBrowseObjectsEntries;
211
212   try
213   {
214     aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
215   }
216   catch ( Standard_Failure )
217   {
218     Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
219     anErrorMsg = aFailure->GetMessageString();
220     aResult = false;
221   }
222   catch ( ... )
223   {
224     aResult = false;
225   }
226   
227   QApplication::restoreOverrideCursor();
228
229   if ( aResult )
230   {
231     module()->update( anUpdateFlags );
232     commitDocOperation();
233     commit();
234     browseObjects( aBrowseObjectsEntries );
235   }
236   else
237   {
238     myEditedObject->Remove();
239     module()->setObjectRemoved( myEditedObject );  
240
241     if ( isToAbortOnApply() )
242       abortDocOperation();
243
244     abort();
245     SUIT_MessageBox::critical( module()->getApp()->desktop(),
246                                tr( "CREATE_STREAM_ERROR" ),
247                                anErrorMsg ); 
248
249   } 
250 }
251
252 bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags,
253                                       QString& theErrorMsg,
254                                       QStringList& theBrowseObjectsEntries )
255 {
256   HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
257   if ( !aPanel )
258     return false;
259
260   // Check whether the object name is not empty
261   QString anObjectName = aPanel->getObjectName().simplified();
262   if ( anObjectName.isEmpty() )
263   {
264     theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
265     return false;
266   }
267
268   // Check that there are no other objects with the same name in the document
269   if ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
270   {
271     Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
272     if( !anObject.IsNull() )
273     {
274       theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
275       return false;
276     }
277   }
278
279   if ( myEditedObject.IsNull() ) // Create new data model object
280     myEditedObject = Handle(HYDROData_Stream)::DownCast( doc()->CreateObject( KIND_STREAM ) );
281
282   Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast(
283     HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) );
284  //if ( aHydAxis.IsNull() )
285  //{
286  //  theErrorMsg = tr( "AXIS_NOT_DEFINED" );
287  //  return false;
288  //}
289
290   // Check if at least 2 profiles is set
291   HYDROData_SequenceOfObjects aRefProfiles;
292   for ( int i = 0; i < myProfiles.length(); ++i )
293   {
294     QString aProfileName = myProfiles.value( i );
295
296     Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
297       HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
298     if ( !aProfile.IsNull() )
299       aRefProfiles.Append( aProfile );
300   }
301
302   if ( aRefProfiles.Length() < 2 )
303   {
304     theErrorMsg = tr( "PROFILES_NOT_DEFINED" );
305     return false;
306   }
307
308   bool ToOrder = true;
309
310   if (aHydAxis.IsNull())
311     ToOrder = false;
312
313   myEditedObject->SetProfiles (aRefProfiles, ToOrder) ;
314   myEditedObject->SetName( anObjectName );
315
316   if (!aHydAxis.IsNull())
317     myEditedObject->SetHydraulicAxis( aHydAxis );
318   myEditedObject->SetProfiles( aRefProfiles, false );
319   myEditedObject->SetDDZ( aPanel->getDDZ() );
320   myEditedObject->SetSpatialStep( aPanel->getSpatialStep() );
321
322   if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) )
323   {
324     myEditedObject->Update();
325     NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>> warnings;
326     myEditedObject->GetWarnings(warnings);
327     QString totalWarning;
328    //for (NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>>::Iterator it(warnings); it.More(); it.Next())
329    //{
330    //  const QSet<QString>& V = it.Value();
331    //  if (V.empty())
332    //    continue;
333    //  const Handle(HYDROData_Profile)& K = it.Key();
334    //  QString ProfName = K->GetName();
335    //  foreach (QString str, V)
336    //  {
337    //    totalWarning + "Profile: " + ProfName + ":  " + str + "\n";    
338    //  }
339    //}
340    //if (totalWarning != "")
341    //  SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "WARNING" ), totalWarning);
342   }
343
344   if ( !myIsEdit )
345   {
346     myEditedObject->SetFillingColor( myEditedObject->DefaultFillingColor() );
347     myEditedObject->SetBorderColor( myEditedObject->DefaultBorderColor() );
348   }
349
350   // Erase preview
351   erasePreview();
352
353   // Show the object in case of creation mode of the operation
354   if( !myIsEdit ) {
355     module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true );
356     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
357     theBrowseObjectsEntries.append( anEntry );
358   }
359
360   module()->setIsToUpdate( myEditedObject );
361
362   // Set update flags
363   theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
364
365   return true;
366 }
367
368 void HYDROGUI_StreamOp::createPreview()
369 {
370   LightApp_Application* anApp = module()->getApp();
371   if ( !getPreviewManager() )
372   {
373     setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>( 
374                        anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
375   }
376
377   OCCViewer_ViewManager* aViewManager = getPreviewManager();
378   if ( aViewManager && !myPreviewPrs )
379   {
380     if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
381     {
382       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
383       if ( !aCtx.IsNull() )
384       {
385         myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
386
387         QColor aFillingColor = Qt::green;
388         QColor aBorderColor = Qt::transparent;
389         if ( !myEditedObject.IsNull() )
390         {
391           aFillingColor = myEditedObject->GetFillingColor();
392           aBorderColor = myEditedObject->GetBorderColor();
393         }
394
395         myPreviewPrs->setFillingColor( aFillingColor, false, false );
396         myPreviewPrs->setBorderColor( aBorderColor, false, false );
397       }
398     }
399   }
400
401   if ( !aViewManager || !myPreviewPrs )
402     return;
403
404   Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast(
405     HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) );
406
407   HYDROData_SequenceOfObjects aRefProfiles;
408   //std::vector<Handle(HYDROData_Profile)> aRefProfiles;
409   int plen = myProfiles.length();
410   for ( int i = 0; i < plen; ++i )
411   {
412     QString aProfileName = myProfiles.value( i );
413
414     Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
415       HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
416     if ( !aProfile.IsNull() )
417       aRefProfiles.Append( aProfile );
418   }
419
420   HYDROData_Stream::PrsDefinition aPrsDef;
421
422   TopoDS_Shape Out3dPres;
423   TopoDS_Shape Out2dPres;
424   TopoDS_Shape OutLeftB;
425   TopoDS_Shape OutRightB;
426   TopoDS_Shape OutInlet;
427   TopoDS_Shape OutOutlet;
428
429   HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
430   double ddz = aPanel->getDDZ();
431   double ss = aPanel->getSpatialStep();
432
433   std::set<int> InvInd;
434
435 #ifdef _DEBUG
436   const int MAX_POINTS_IN_PREVIEW = 50000;
437 #else
438   const int MAX_POINTS_IN_PREVIEW = 500000;
439 #endif
440
441   HYDROData_Bathymetry::AltitudePoints points;
442
443   bool ProjStat = true;
444   NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>> warnings;
445   bool ToEstimateWarnings = false;
446   HYDROData_DTM::CreateProfilesFromDTM( aRefProfiles, ddz, ss, points, Out3dPres, Out2dPres, OutLeftB, OutRightB,
447     OutInlet, OutOutlet, true, true, InvInd, MAX_POINTS_IN_PREVIEW, ProjStat, warnings, ToEstimateWarnings );
448
449   aPanel->clearAllBackgroundColorsForProfileList();
450  // for (std::set<int>::const_iterator it = InvInd.begin(); it != InvInd.end(); it++)
451  //   aPanel->setBackgroundColorForProfileList(*it, QColor(Qt::yellow));
452
453   aPrsDef.myInlet = OutInlet;
454   aPrsDef.myOutlet = OutOutlet;
455   aPrsDef.myLeftBank = OutLeftB;
456   aPrsDef.myRightBank = OutRightB;
457   if (ProjStat)
458     aPrsDef.myPrs2D = Out2dPres;
459   aPrsDef.myPrs3D = Out3dPres;
460
461   aPanel->clearWarnings();
462   if (!ProjStat)
463     aPanel->addWarning(tr("STREAM_PROJECTION_FAILED"));
464
465   for (NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>>::Iterator it(warnings); it.More(); it.Next())
466   {
467     const QSet<QString>& V = it.Value();
468     if (V.empty())
469       continue;
470     const Handle(HYDROData_Profile)& K = it.Key();
471     QString ProfName = K->GetName();
472     foreach (QString str, V)
473     {
474       aPanel->addWarning("Profile: " + ProfName + ":  " + str);    
475     }
476
477     aPanel->setBackgroundColorForProfileList(ProfName, QColor(Qt::yellow));
478   }
479
480   myPreviewPrs->setShape( aPrsDef.myPrs2D );
481 }
482
483 void HYDROGUI_StreamOp::erasePreview()
484 {
485   if( myPreviewPrs )
486   {
487     delete myPreviewPrs;
488     myPreviewPrs = 0;
489   }
490 }
491
492 void HYDROGUI_StreamOp::onAddProfiles()
493 {
494   Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast(
495     HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) );
496   //if ( aHydAxis.IsNull() )
497    // return;
498
499   TopoDS_Face aPlane;
500   HYDROData_Stream::BuildRefFace( aPlane );
501
502   // Get the current profiles list
503   QStringList aCurrentProfiles = myProfiles;
504     
505   // Get the selected profiles ( in the Object Browser )
506   QStringList anInvalidProfiles;
507   QStringList anExistingProfiles;
508   QStringList aHasNoIntersectionProfiles;
509   QStringList aVerifiedProfiles;
510
511   HYDROData_SequenceOfObjects aSelectedProfiles = HYDROGUI_Tool::GetSelectedObjects( module() ); 
512
513   for( int i = 1, n = aSelectedProfiles.Length(); i <= n; i++ )
514   {
515     Handle(HYDROData_Profile) aProfile = 
516       Handle(HYDROData_Profile)::DownCast( aSelectedProfiles.Value( i ) );
517     if ( aProfile.IsNull() )
518       continue;
519
520     QString aProfileName = aProfile->GetName();
521     Standard_Real aProfilePar = 0.0;
522
523     // Check the profile, if all is ok - add it to the list
524     if ( !aProfile->IsValid() )
525     {
526       // check whether the profile is valid
527       anInvalidProfiles << aProfileName;
528     }
529     else if ( aCurrentProfiles.contains( aProfileName ) )
530     {
531       // check whether the profile is already added
532       anExistingProfiles << aProfileName;
533     }
534     else if ( !HYDROData_Stream::HasIntersection( aHydAxis, aProfile, aPlane, aProfilePar ) )
535     {
536       // check whether the profile has intersection
537       aHasNoIntersectionProfiles << aProfileName;
538     }
539     else
540     {
541       // Insert profile in correct place
542       // if hidr axis is null => the params (myProfileParams) will be igrored. So ordering will be the same as in the aSelectedProfiles
543       insertProfileInToOrder( aProfileName, aProfilePar, myProfiles, myProfileParams );
544       aVerifiedProfiles << aProfileName;
545     }
546   }
547  
548   // Show message box with the ignored profiles
549   if ( !anInvalidProfiles.isEmpty() ||
550        !anExistingProfiles.isEmpty() ||
551        !aHasNoIntersectionProfiles.isEmpty() )
552   {
553     QString aMessage = tr( "IGNORED_PROFILES" );
554     if ( !anInvalidProfiles.isEmpty() )
555     {
556       aMessage.append( "\n\n" );
557       aMessage.append( tr("INVALID_PROFILES").arg( anInvalidProfiles.join( "\n" ) ) );
558     }
559     if ( !anExistingProfiles.isEmpty() )
560     {
561       aMessage.append( "\n\n" );
562       aMessage.append( tr("EXISTING_PROFILES").arg( anExistingProfiles.join( "\n" ) ) );
563     }
564     if ( !aHasNoIntersectionProfiles.isEmpty() )
565     {
566       aMessage.append( "\n\n" );
567       aMessage.append( tr("NOT_INTERSECTED_PROFILES").arg( aHasNoIntersectionProfiles.join( "\n" ) ) );
568     }
569
570     SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "WARNING" ), aMessage );
571   }
572
573   if ( aVerifiedProfiles.isEmpty() )
574     return;
575
576   // Update the panel
577   updatePanelData();
578
579   // Update preview
580   createPreview();
581 }
582
583 void HYDROGUI_StreamOp::onRemoveProfiles( const QStringList& theProfilesToRemove )
584 {
585   QStringList aToRemove = theProfilesToRemove;
586   
587   aToRemove.removeDuplicates();
588   if ( aToRemove.isEmpty() )
589     return;
590
591   bool isRemoved = false;
592
593   // Remove profiles
594   for ( int i = 0; i < aToRemove.length(); ++i )
595   {
596     const QString& aProfileName = aToRemove.value( i );
597
598     int aProfileId = myProfiles.indexOf( aProfileName );
599     if ( aProfileId < 0 )
600       continue;
601
602     myProfiles.removeAt( aProfileId );
603     myProfileParams.removeAt( aProfileId );
604     isRemoved = true;
605   }
606
607   if ( isRemoved )
608   {
609     // Update the panel
610     updatePanelData();
611
612     // Update preview
613     createPreview();
614   }
615 }
616
617 void HYDROGUI_StreamOp::onDDZValueChanged( double d )
618 {
619    createPreview();
620 }
621
622 void HYDROGUI_StreamOp::onSSValueChanged( double d )
623 {
624    createPreview();
625 }
626
627 void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis )
628 {
629   // Get axis object   
630   Handle(HYDROData_PolylineXY) aNewAxis = Handle(HYDROData_PolylineXY)::DownCast(
631     HYDROGUI_Tool::FindObjectByName( module(), theNewAxis, KIND_POLYLINEXY ) );
632
633   // Prepare data for intersection check
634   TopoDS_Face aPlane;
635   HYDROData_Stream::BuildRefFace( aPlane );
636   //{
637   //  SUIT_MessageBox::critical( module()->getApp()->desktop(), 
638   //                            tr( "BAD_SELECTED_POLYLINE_TLT" ),
639   //                            tr( "BAD_SELECTED_POLYLINE_MSG" ).arg( theNewAxis ) );
640   //  // To restore the old axis
641   //  updatePanelData();
642   //  return;
643   //}
644
645   QStringList   aNewProfiles;
646   QList<double> aNewProfileParams;
647   QStringList   aHasNoIntersectionProfiles;
648
649   // Get list of profiles which do not intersect the axis
650   for ( int i = 0; i < myProfiles.length(); ++i )
651   {
652     QString aProfileName = myProfiles.value( i );
653
654     Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
655       HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
656     if ( aProfile.IsNull() )
657       continue;
658       
659     Standard_Real aProfilePar = 0.0;
660     if ( HYDROData_Stream::HasIntersection( aNewAxis, aProfile, aPlane, aProfilePar ) )
661     {
662       // Insert profile in correct place
663       insertProfileInToOrder( aProfileName, aProfilePar, aNewProfiles, aNewProfileParams );
664     }
665     else
666     {
667       aHasNoIntersectionProfiles << aProfile->GetName();
668     }
669   }
670
671   // If there are profiles which don't intersect the new axis - show confirmation message box
672   bool isConfirmed = true;
673   if ( !aHasNoIntersectionProfiles.isEmpty() )
674   {
675     SUIT_MessageBox::StandardButtons aButtons = 
676       SUIT_MessageBox::Yes | SUIT_MessageBox::No;
677
678     QString aMsg = aHasNoIntersectionProfiles.join( "\n" );
679     isConfirmed = SUIT_MessageBox::question( module()->getApp()->desktop(),
680                                              tr( "CONFIRMATION" ),
681                                              tr( "CONFIRM_AXIS_CHANGE" ).arg( aMsg ),
682                                              aButtons, 
683                                              SUIT_MessageBox::Yes) == SUIT_MessageBox::Yes;
684   }
685
686   // Check if the user has confirmed axis change
687   if ( !isConfirmed )
688   {
689     // To restore the old axis
690     updatePanelData();
691   }
692   else
693   {
694     // Update data
695     myHydAxis = theNewAxis;
696     myProfiles = aNewProfiles;
697     myProfileParams = aNewProfileParams;
698
699     // Update the panel
700     updatePanelData();
701
702     // Update preview
703     createPreview();
704   }
705 }
706
707 void HYDROGUI_StreamOp::updatePanelData()
708 {
709   HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
710   if ( !aPanel )
711     return;
712
713   aPanel->setAxisName( myHydAxis );
714   aPanel->setProfiles( myProfiles );
715 }