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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_StreamOp.h"
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"
29 #include <HYDROData_Document.h>
30 #include <HYDROData_PolylineXY.h>
31 #include <HYDROData_Profile.h>
32 #include <HYDROData_DTM.h>
34 #include <LightApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <LightApp_UpdateFlags.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_Desktop.h>
41 #include <QApplication>
44 #include <OCCViewer_ViewManager.h>
45 #include <OCCViewer_ViewModel.h>
46 #include <OCCViewer_ViewWindow.h>
54 #include <TopoDS_Face.hxx>
56 #include <BRepBuilderAPI_MakeFace.hxx>
58 #include <HYDROData_StreamLinearInterpolation.h>
60 void insertProfileInToOrder( const QString& theProfileName,
61 const double& theProfilePar,
62 QStringList& theProfiles,
63 QList<double>& theProfileParams )
65 bool anIsInserted = false;
66 for ( int k = 0; k < theProfileParams.length(); ++k )
68 const double& aParam = theProfileParams.value( k );
69 if ( theProfilePar < aParam )
71 theProfiles.insert( k, theProfileName );
72 theProfileParams.insert( k, theProfilePar );
80 theProfiles << theProfileName;
81 theProfileParams << theProfilePar;
85 HYDROGUI_StreamOp::HYDROGUI_StreamOp( HYDROGUI_Module* theModule, bool theIsEdit )
86 : HYDROGUI_Operation( theModule ),
87 myIsEdit( theIsEdit ),
90 setName( theIsEdit ? tr( "EDIT_STREAM" ) : tr( "CREATE_STREAM" ) );
93 HYDROGUI_StreamOp::~HYDROGUI_StreamOp()
98 void HYDROGUI_StreamOp::startOperation()
100 HYDROGUI_Operation::startOperation();
101 int mode = 0; //DTM mode by def
103 if ( !myIsEdit || isApplyAndClose() )
104 myEditedObject.Nullify();
107 myProfileParams.clear();
109 // Get panel and reset its state
110 HYDROGUI_StreamDlg* aPanel = (HYDROGUI_StreamDlg*)inputPanel();
113 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STREAM_NAME" ) );
116 if ( isApplyAndClose() )
118 Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
119 if ( !myEditedObject.IsNull() )
121 mode = myEditedObject->GetInterpolationMethod();
122 anObjectName = myEditedObject->GetName();
123 //aPanel->setMode(mode);
126 Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis();
129 HYDROData_Stream::BuildRefFace( aPlane ) ;
130 if ( !aHydraulicAxis.IsNull() )
131 myHydAxis = aHydraulicAxis->GetName();
134 HYDROData_SequenceOfObjects aStreamProfiles = myEditedObject->GetProfiles();
135 for ( int i = 1, n = aStreamProfiles.Length(); i <= n; ++i )
137 Handle(HYDROData_Profile) aProfile =
138 Handle(HYDROData_Profile)::DownCast( aStreamProfiles.Value( i ) );
139 if ( aProfile.IsNull() )
142 QString aProfileName = aProfile->GetName();
143 myProfiles << aProfileName;
145 if (!aHydraulicAxis.IsNull())
147 Standard_Real aProfilePar = 0.0;
148 HYDROData_Stream::HasIntersection( aHydraulicAxis, aProfile, aPlane, aProfilePar );
149 myProfileParams << aProfilePar;
158 // set the edited object name
159 aPanel->setObjectName( anObjectName );
161 // set the existing 2D polylines names to the panel
162 aPanel->setAxisNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
164 aPanel->setLeftBankNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
165 aPanel->setRightBankNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
167 bool isBlocked = aPanel->blockSignals( true );
172 aPanel->setDDZ( myEditedObject->GetDDZ() );
176 aPanel->setNbProfilePoints( myEditedObject->GetNbProfilePoints() );
177 aPanel->setLeftBankName(myEditedObject->GetLeftBank()->GetName());
178 aPanel->setRightBankName(myEditedObject->GetRightBank()->GetName());
180 aPanel->setSpatialStep( myEditedObject->GetSpatialStep() );
183 aPanel->setMode(mode);
184 aPanel->blockSignals( isBlocked );
186 // synchronize the panel state with the edited object state
192 void HYDROGUI_StreamOp::abortOperation()
195 HYDROGUI_Operation::abortOperation();
198 void HYDROGUI_StreamOp::commitOperation()
201 HYDROGUI_Operation::commitOperation();
204 HYDROGUI_InputPanel* HYDROGUI_StreamOp::createInputPanel() const
206 HYDROGUI_StreamDlg* aPanel = new HYDROGUI_StreamDlg( module(), getName() );
208 connect( aPanel, SIGNAL( AddProfiles() ), this, SLOT( onAddProfiles() ) );
209 connect( aPanel, SIGNAL( RemoveProfiles( const QStringList& ) ),
210 this, SLOT( onRemoveProfiles( const QStringList& ) ) );
211 connect( aPanel, SIGNAL( AxisChanged( const QString& ) ),
212 this, SLOT( onAxisChanged( const QString& ) ) );
214 connect( aPanel, SIGNAL( DDZValueChanged( double ) ), this, SLOT( onDDZValueChanged( double ) ) );
215 connect( aPanel, SIGNAL( SSValueChanged( double ) ), this, SLOT( onSSValueChanged( double ) ) );
217 connect( aPanel, SIGNAL( LeftBankChanged( const QString& ) ),
218 this, SLOT( onLeftBankChanged( const QString& ) ) );
220 connect( aPanel, SIGNAL( RightBankChanged( const QString& ) ),
221 this, SLOT( onRightBankChanged( const QString& ) ) );
223 connect( aPanel, SIGNAL( ProfilePointsChanged( int ) ), this, SLOT( onProfilePointsChanged( int ) ) );
225 connect( aPanel, SIGNAL( ModeChanged( bool ) ), this, SLOT( onModeChanged( bool ) ) );
230 void HYDROGUI_StreamOp::apply()
232 QApplication::setOverrideCursor( Qt::WaitCursor );
236 int anUpdateFlags = 0;
239 bool aResult = false;
240 QStringList aBrowseObjectsEntries;
244 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
246 catch ( Standard_Failure )
248 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
249 anErrorMsg = aFailure->GetMessageString();
257 QApplication::restoreOverrideCursor();
261 module()->update( anUpdateFlags );
262 commitDocOperation();
264 browseObjects( aBrowseObjectsEntries );
268 myEditedObject->Remove();
269 module()->setObjectRemoved( myEditedObject );
271 if ( isToAbortOnApply() )
275 SUIT_MessageBox::critical( module()->getApp()->desktop(),
276 tr( "CREATE_STREAM_ERROR" ),
281 //#include <HYDROData_StreamLinearInterpolation.h>
282 bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags,
283 QString& theErrorMsg,
284 QStringList& theBrowseObjectsEntries )
286 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
290 // Check whether the object name is not empty
291 QString anObjectName = aPanel->getObjectName().simplified();
292 if ( anObjectName.isEmpty() )
294 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
298 // Check that there are no other objects with the same name in the document
299 if ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
301 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
302 if( !anObject.IsNull() )
304 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
309 if ( myEditedObject.IsNull() ) // Create new data model object
310 myEditedObject = Handle(HYDROData_Stream)::DownCast( doc()->CreateObject( KIND_STREAM ) );
312 Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast(
313 HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) );
314 //if ( aHydAxis.IsNull() )
316 // theErrorMsg = tr( "AXIS_NOT_DEFINED" );
320 // Check if at least 2 profiles is set
321 HYDROData_SequenceOfObjects aRefProfiles;
322 for ( int i = 0; i < myProfiles.length(); ++i )
324 QString aProfileName = myProfiles.value( i );
326 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
327 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
328 if ( !aProfile.IsNull() )
329 aRefProfiles.Append( aProfile );
332 if ( aRefProfiles.Length() < 2 )
334 theErrorMsg = tr( "PROFILES_NOT_DEFINED" );
338 int InterpMethod = aPanel->getMode();
340 myEditedObject->SetInterpolationMethod(InterpMethod);
342 if (InterpMethod == 0)
345 bool ToOrder = !aHydAxis.IsNull();
346 myEditedObject->SetProfiles (aRefProfiles, ToOrder) ;
347 myEditedObject->SetName( anObjectName );
349 if (!aHydAxis.IsNull())
350 myEditedObject->SetHydraulicAxis( aHydAxis );
351 myEditedObject->SetProfiles( aRefProfiles, false );
352 myEditedObject->SetDDZ( aPanel->getDDZ() );
353 myEditedObject->SetSpatialStep( aPanel->getSpatialStep() );
355 else if (InterpMethod == 1)
358 myEditedObject->SetProfiles (aRefProfiles, false) ;
359 myEditedObject->SetName( anObjectName );
360 if (!aHydAxis.IsNull())
361 myEditedObject->SetHydraulicAxis( aHydAxis );
362 Handle(HYDROData_PolylineXY) aLeftBank = Handle(HYDROData_PolylineXY)::DownCast(
363 HYDROGUI_Tool::FindObjectByName( module(), aPanel->getLeftBankName(), KIND_POLYLINEXY ) );
364 Handle(HYDROData_PolylineXY) aRightBank = Handle(HYDROData_PolylineXY)::DownCast(
365 HYDROGUI_Tool::FindObjectByName( module(), aPanel->getRightBankName(), KIND_POLYLINEXY ) );
367 myEditedObject->SetLeftBank(aLeftBank);
368 myEditedObject->SetRightBank(aRightBank);
370 myEditedObject->SetNbProfilePoints( aPanel->getNbProfilePoints() );
371 myEditedObject->SetHaxStep( aPanel->getSpatialStep() );
374 if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) )
376 myEditedObject->Update();
377 //NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>> warnings;
378 //myEditedObject->GetWarnings(warnings);
379 //QString totalWarning;
380 //for (NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>>::Iterator it(warnings); it.More(); it.Next())
382 // const QSet<QString>& V = it.Value();
385 // const Handle(HYDROData_Profile)& K = it.Key();
386 // QString ProfName = K->GetName();
387 // foreach (QString str, V)
389 // totalWarning + "Profile: " + ProfName + ": " + str + "\n";
392 //if (totalWarning != "")
393 // SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "WARNING" ), totalWarning);
398 myEditedObject->SetFillingColor( myEditedObject->DefaultFillingColor() );
399 myEditedObject->SetBorderColor( myEditedObject->DefaultBorderColor() );
405 // Show the object in case of creation mode of the operation
407 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true );
408 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
409 theBrowseObjectsEntries.append( anEntry );
412 module()->setIsToUpdate( myEditedObject );
415 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
420 void HYDROGUI_StreamOp::createPreview()
422 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
423 int mode = aPanel->getMode();
425 LightApp_Application* anApp = module()->getApp();
426 if ( !getPreviewManager() )
428 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
429 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
432 OCCViewer_ViewManager* aViewManager = getPreviewManager();
433 if ( aViewManager && !myPreviewPrs )
435 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
437 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
438 if ( !aCtx.IsNull() )
440 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
442 QColor aFillingColor = Qt::green;
443 QColor aBorderColor = Qt::transparent;
444 if ( !myEditedObject.IsNull() )
446 aFillingColor = myEditedObject->GetFillingColor();
447 aBorderColor = myEditedObject->GetBorderColor();
450 myPreviewPrs->setFillingColor( aFillingColor, false, false );
451 myPreviewPrs->setBorderColor( aBorderColor, false, false );
456 if ( !aViewManager || !myPreviewPrs )
461 Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast(
462 HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) );
464 HYDROData_SequenceOfObjects aRefProfiles;
465 //std::vector<Handle(HYDROData_Profile)> aRefProfiles;
466 int plen = myProfiles.length();
467 for ( int i = 0; i < plen; ++i )
469 QString aProfileName = myProfiles.value( i );
471 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
472 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
473 if ( !aProfile.IsNull() )
474 aRefProfiles.Append( aProfile );
477 HYDROData_Stream::PrsDefinition aPrsDef;
479 TopoDS_Shape Out3dPres;
480 TopoDS_Shape Out2dPres;
481 TopoDS_Shape OutLeftB;
482 TopoDS_Shape OutRightB;
483 TopoDS_Shape OutInlet;
484 TopoDS_Shape OutOutlet;
486 double ddz = aPanel->getDDZ();
487 double ss = aPanel->getSpatialStep();
489 std::set<int> InvInd;
492 const int MAX_POINTS_IN_PREVIEW = 50000;
494 const int MAX_POINTS_IN_PREVIEW = 500000;
497 HYDROData_Bathymetry::AltitudePoints points;
499 bool ProjStat = true;
500 NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>> warnings;
501 bool ToEstimateWarnings = false;
502 HYDROData_DTM::CreateProfilesFromDTM( aRefProfiles, ddz, ss, points, Out3dPres, Out2dPres, OutLeftB, OutRightB,
503 OutInlet, OutOutlet, true, true, InvInd, MAX_POINTS_IN_PREVIEW, ProjStat, warnings, ToEstimateWarnings );
505 aPanel->clearAllBackgroundColorsForProfileList();
506 // for (std::set<int>::const_iterator it = InvInd.begin(); it != InvInd.end(); it++)
507 // aPanel->setBackgroundColorForProfileList(*it, QColor(Qt::yellow));
509 aPrsDef.myInlet = OutInlet;
510 aPrsDef.myOutlet = OutOutlet;
511 aPrsDef.myLeftBank = OutLeftB;
512 aPrsDef.myRightBank = OutRightB;
514 aPrsDef.myPrs2D = Out2dPres;
515 aPrsDef.myPrs3D = Out3dPres;
517 aPanel->clearWarnings();
519 aPanel->addWarning(tr("STREAM_PROJECTION_FAILED"));
521 QVector<QString> warningsStr;
523 for (NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>>::Iterator it(warnings); it.More(); it.Next())
525 QSet<QString> V = it.Value();
528 const Handle(HYDROData_Profile)& K = it.Key();
529 QString ProfName = K->GetName();
530 foreach (QString str, V)
532 warningsStr.append(ProfName + ": " + str);
533 //aPanel->addWarning(ProfName + ": " + str);
536 aPanel->setBackgroundColorForProfileList(ProfName, QColor(Qt::yellow));
539 std::sort(warningsStr.begin(), warningsStr.end());
540 for (int k=0;k<warningsStr.size();k++)
541 aPanel->addWarning(warningsStr[k]);
543 myPreviewPrs->setShape( aPrsDef.myPrs2D );
547 aPanel->clearAllBackgroundColorsForProfileList();
548 aPanel->clearWarnings();
549 int nbProfPoints = aPanel->getNbProfilePoints();
550 double ss = aPanel->getSpatialStep();
551 QString axisName = aPanel->getAxisName();
552 QString leftBankName = aPanel->getLeftBankName();
553 QString rightBankName = aPanel->getRightBankName();
554 QList<Handle(HYDROData_Entity)> listProf = aPanel->getProfiles();
555 HYDROData_SequenceOfObjects seqProf;
556 foreach (Handle(HYDROData_Entity) ent, listProf)
559 Handle(HYDROData_PolylineXY) axis = Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), axisName, KIND_POLYLINEXY ) );
560 Handle(HYDROData_PolylineXY) LB = Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), leftBankName, KIND_POLYLINEXY ) );
561 Handle(HYDROData_PolylineXY) RB = Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), rightBankName, KIND_POLYLINEXY ) );
562 HYDROData_Bathymetry::AltitudePoints outBathypoints;
564 std::vector<std::string> warnings;
565 HYDROData_Stream::PrsDefinition prsDef;
567 HYDROData_StreamLinearInterpolation::Perform(seqProf, 500, 1, axis, LB, RB, outBathypoints, true, true, prsDef, &warnings);
569 myPreviewPrs->setShape( prsDef.myPrs2D );
570 for (int i=0;i<warnings.size();i++)
571 aPanel->addWarning(warnings[i].c_str());
575 void HYDROGUI_StreamOp::erasePreview()
584 void HYDROGUI_StreamOp::onAddProfiles()
586 //TODO skip if mode == 1??
587 Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast(
588 HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) );
589 //if ( aHydAxis.IsNull() )
593 HYDROData_Stream::BuildRefFace( aPlane );
595 // Get the current profiles list
596 QStringList aCurrentProfiles = myProfiles;
598 // Get the selected profiles ( in the Object Browser )
599 QStringList anInvalidProfiles;
600 QStringList anExistingProfiles;
601 QStringList aHasNoIntersectionProfiles;
602 QStringList aVerifiedProfiles;
604 HYDROData_SequenceOfObjects aSelectedProfiles = HYDROGUI_Tool::GetSelectedObjects( module() );
606 for( int i = 1, n = aSelectedProfiles.Length(); i <= n; i++ )
608 Handle(HYDROData_Profile) aProfile =
609 Handle(HYDROData_Profile)::DownCast( aSelectedProfiles.Value( i ) );
610 if ( aProfile.IsNull() )
613 QString aProfileName = aProfile->GetName();
614 Standard_Real aProfilePar = 0.0;
616 // Check the profile, if all is ok - add it to the list
617 if ( !aProfile->IsValid() )
619 // check whether the profile is valid
620 anInvalidProfiles << aProfileName;
622 else if ( aCurrentProfiles.contains( aProfileName ) )
624 // check whether the profile is already added
625 anExistingProfiles << aProfileName;
627 else if ( !HYDROData_Stream::HasIntersection( aHydAxis, aProfile, aPlane, aProfilePar ) )
629 // check whether the profile has intersection
630 aHasNoIntersectionProfiles << aProfileName;
634 // Insert profile in correct place
635 // if hidr axis is null => the params (myProfileParams) will be igrored. So ordering will be the same as in the aSelectedProfiles
636 insertProfileInToOrder( aProfileName, aProfilePar, myProfiles, myProfileParams );
637 aVerifiedProfiles << aProfileName;
641 // Show message box with the ignored profiles
642 if ( !anInvalidProfiles.isEmpty() ||
643 !anExistingProfiles.isEmpty() ||
644 !aHasNoIntersectionProfiles.isEmpty() )
646 QString aMessage = tr( "IGNORED_PROFILES" );
647 if ( !anInvalidProfiles.isEmpty() )
649 aMessage.append( "\n\n" );
650 aMessage.append( tr("INVALID_PROFILES").arg( anInvalidProfiles.join( "\n" ) ) );
652 if ( !anExistingProfiles.isEmpty() )
654 aMessage.append( "\n\n" );
655 aMessage.append( tr("EXISTING_PROFILES").arg( anExistingProfiles.join( "\n" ) ) );
657 if ( !aHasNoIntersectionProfiles.isEmpty() )
659 aMessage.append( "\n\n" );
660 aMessage.append( tr("NOT_INTERSECTED_PROFILES").arg( aHasNoIntersectionProfiles.join( "\n" ) ) );
663 SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "WARNING" ), aMessage );
666 if ( aVerifiedProfiles.isEmpty() )
676 void HYDROGUI_StreamOp::onRemoveProfiles( const QStringList& theProfilesToRemove )
678 QStringList aToRemove = theProfilesToRemove;
680 aToRemove.removeDuplicates();
681 if ( aToRemove.isEmpty() )
684 bool isRemoved = false;
687 for ( int i = 0; i < aToRemove.length(); ++i )
689 const QString& aProfileName = aToRemove.value( i );
691 int aProfileId = myProfiles.indexOf( aProfileName );
692 if ( aProfileId < 0 )
695 myProfiles.removeAt( aProfileId );
696 myProfileParams.removeAt( aProfileId );
710 void HYDROGUI_StreamOp::onDDZValueChanged( double d )
712 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
715 if (aPanel->getMode() == 0)
719 void HYDROGUI_StreamOp::onSSValueChanged( double d )
721 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
727 void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis )
729 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
733 Handle(HYDROData_PolylineXY) aNewAxis = Handle(HYDROData_PolylineXY)::DownCast(
734 HYDROGUI_Tool::FindObjectByName( module(), theNewAxis, KIND_POLYLINEXY ) );
736 // Prepare data for intersection check
738 HYDROData_Stream::BuildRefFace( aPlane );
740 // SUIT_MessageBox::critical( module()->getApp()->desktop(),
741 // tr( "BAD_SELECTED_POLYLINE_TLT" ),
742 // tr( "BAD_SELECTED_POLYLINE_MSG" ).arg( theNewAxis ) );
743 // // To restore the old axis
744 // updatePanelData();
748 QStringList aNewProfiles;
749 QList<double> aNewProfileParams;
750 QStringList aHasNoIntersectionProfiles;
752 // Get list of profiles which do not intersect the axis
753 for ( int i = 0; i < myProfiles.length(); ++i )
755 QString aProfileName = myProfiles.value( i );
757 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
758 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
759 if ( aProfile.IsNull() )
762 Standard_Real aProfilePar = 0.0;
763 if ( HYDROData_Stream::HasIntersection( aNewAxis, aProfile, aPlane, aProfilePar ) )
765 // Insert profile in correct place
766 insertProfileInToOrder( aProfileName, aProfilePar, aNewProfiles, aNewProfileParams );
770 aHasNoIntersectionProfiles << aProfile->GetName();
774 // If there are profiles which don't intersect the new axis - show confirmation message box
775 bool isConfirmed = true;
776 if ( !aHasNoIntersectionProfiles.isEmpty() )
778 SUIT_MessageBox::StandardButtons aButtons =
779 SUIT_MessageBox::Yes | SUIT_MessageBox::No;
781 QString aMsg = aHasNoIntersectionProfiles.join( "\n" );
782 isConfirmed = SUIT_MessageBox::question( module()->getApp()->desktop(),
783 tr( "CONFIRMATION" ),
784 tr( "CONFIRM_AXIS_CHANGE" ).arg( aMsg ),
786 SUIT_MessageBox::Yes) == SUIT_MessageBox::Yes;
789 // Check if the user has confirmed axis change
792 // To restore the old axis
798 myHydAxis = theNewAxis;
799 myProfiles = aNewProfiles;
800 myProfileParams = aNewProfileParams;
810 void HYDROGUI_StreamOp::onLeftBankChanged( const QString& theNewAxis )
812 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
815 if (aPanel->getMode() == 1)
819 void HYDROGUI_StreamOp::onRightBankChanged( const QString& theNewAxis )
821 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
824 if (aPanel->getMode() == 1)
828 void HYDROGUI_StreamOp::onProfilePointsChanged( int d )
830 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
833 if (aPanel->getMode() == 1)
837 void HYDROGUI_StreamOp::onModeChanged( bool mode )
842 void HYDROGUI_StreamOp::updatePanelData()
844 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
848 aPanel->setAxisName( myHydAxis );
849 aPanel->setProfiles( myProfiles );