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"
28 #include "HYDROGUI_OCCDisplayer.h"
30 #include <HYDROData_Document.h>
31 #include <HYDROData_PolylineXY.h>
32 #include <HYDROData_Profile.h>
33 #include <HYDROData_DTM.h>
35 #include <LightApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
37 #include <LightApp_UpdateFlags.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_Desktop.h>
42 #include <QApplication>
45 #include <OCCViewer_ViewManager.h>
46 #include <OCCViewer_ViewModel.h>
47 #include <OCCViewer_ViewWindow.h>
48 #include <SVTK_ViewManager.h>
49 #include <SVTK_ViewModel.h>
57 #include <TopoDS_Face.hxx>
59 #include <BRepBuilderAPI_MakeFace.hxx>
61 #include <HYDROData_StreamLinearInterpolation.h>
64 #include "HYDRO_trace.hxx"
66 void insertProfileInToOrder( const QString& theProfileName,
67 const double& theProfilePar,
68 QStringList& theProfiles,
69 QList<double>& theProfileParams )
71 DEBTRACE("insertProfileInToOrder");
72 bool anIsInserted = false;
73 for ( int k = 0; k < theProfileParams.length(); ++k )
75 const double& aParam = theProfileParams.value( k );
76 if ( theProfilePar < aParam )
78 theProfiles.insert( k, theProfileName );
79 theProfileParams.insert( k, theProfilePar );
87 theProfiles << theProfileName;
88 theProfileParams << theProfilePar;
92 void HYDROGUI_StreamOp::hideBathy(HYDROGUI_Module *theModule)
94 DEBTRACE("HYDROGUI_StreamOp::hideBathy");
95 Handle(HYDROData_Stream) editedObject =
96 Handle(HYDROData_Stream)::DownCast(HYDROGUI_Tool::GetSelectedObject(theModule));
97 if (!editedObject.IsNull())
99 QString bathyName = editedObject->GetBathyName();
100 DEBTRACE("bathyName " << bathyName.toStdString());
101 if (!bathyName.isEmpty())
103 Handle(HYDROData_Entity) aBathyObject = HYDROGUI_Tool::FindObjectByName(theModule, bathyName);
104 if (!aBathyObject.IsNull())
106 DEBTRACE("Hide " << bathyName.toStdString());
107 int anUpdateFlags = UF_OCCViewer;
108 size_t aViewerId = HYDROGUI_Tool::GetActiveOCCViewId(theModule);
109 theModule->setObjectVisible(aViewerId, aBathyObject, false);
110 theModule->update( anUpdateFlags );
116 HYDROGUI_StreamOp::HYDROGUI_StreamOp(HYDROGUI_Module *theModule, bool theIsEdit) :
117 HYDROGUI_Operation(theModule), myIsEdit(theIsEdit), myPreviewPrs( NULL)
119 DEBTRACE("HYDROGUI_StreamOp");
120 setName(theIsEdit ? tr("EDIT_STREAM") : tr("CREATE_STREAM"));
123 HYDROGUI_StreamOp::~HYDROGUI_StreamOp()
125 DEBTRACE("~HYDROGUI_StreamOp");
129 void HYDROGUI_StreamOp::startOperation()
131 DEBTRACE("startOperation");
132 HYDROGUI_Operation::startOperation();
133 int mode = 0; //DTM mode by def
135 if ( !myIsEdit || isApplyAndClose() )
136 myEditedObject.Nullify();
139 myProfileParams.clear();
141 // Get panel and reset its state
142 HYDROGUI_StreamDlg* aPanel = (HYDROGUI_StreamDlg*)inputPanel();
145 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STREAM_NAME" ) );
148 if ( isApplyAndClose() )
150 Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
151 if ( !myEditedObject.IsNull() )
153 mode = myEditedObject->GetInterpolationMethod();
154 anObjectName = myEditedObject->GetName();
155 DEBTRACE("anObjectName " << anObjectName.toStdString());
156 //aPanel->setMode(mode);
159 Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis();
162 HYDROData_Stream::BuildRefFace( aPlane ) ;
163 if ( !aHydraulicAxis.IsNull() )
164 myHydAxis = aHydraulicAxis->GetName();
167 HYDROData_SequenceOfObjects aStreamProfiles = myEditedObject->GetProfiles();
168 for ( int i = 1, n = aStreamProfiles.Length(); i <= n; ++i )
170 Handle(HYDROData_Profile) aProfile =
171 Handle(HYDROData_Profile)::DownCast( aStreamProfiles.Value( i ) );
172 if ( aProfile.IsNull() )
175 QString aProfileName = aProfile->GetName();
176 myProfiles << aProfileName;
178 if (!aHydraulicAxis.IsNull())
180 Standard_Real aProfilePar = 0.0;
181 HYDROData_Stream::HasIntersection( aHydraulicAxis, aProfile, aPlane, aProfilePar );
182 myProfileParams << aProfilePar;
189 // set the edited object name
190 aPanel->setObjectName( anObjectName );
192 // set the existing 2D polylines names to the panel
193 aPanel->setAxisNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
195 aPanel->setLeftBankNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
196 aPanel->setRightBankNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
198 bool isBlocked = aPanel->blockSignals( true );
203 aPanel->setDDZ( myEditedObject->GetDDZ() );
207 aPanel->setNbProfilePoints( myEditedObject->GetNbProfilePoints() );
208 aPanel->setLeftBankName(myEditedObject->GetLeftBank()->GetName());
209 aPanel->setRightBankName(myEditedObject->GetRightBank()->GetName());
211 aPanel->setSpatialStep( myEditedObject->GetSpatialStep() );
214 aPanel->setMode(mode);
215 aPanel->blockSignals( isBlocked );
217 // synchronize the panel state with the edited object state
223 void HYDROGUI_StreamOp::abortOperation()
225 DEBTRACE("abortOperation");
227 HYDROGUI_Operation::abortOperation();
230 void HYDROGUI_StreamOp::commitOperation()
232 DEBTRACE("commitOperation");
234 HYDROGUI_Operation::commitOperation();
237 HYDROGUI_InputPanel* HYDROGUI_StreamOp::createInputPanel() const
239 DEBTRACE("createInputPanel");
240 HYDROGUI_StreamDlg* aPanel = new HYDROGUI_StreamDlg( module(), getName() );
242 connect( aPanel, SIGNAL( AddProfiles() ), this, SLOT( onAddProfiles() ) );
243 connect( aPanel, SIGNAL( RemoveProfiles( const QStringList& ) ),
244 this, SLOT( onRemoveProfiles( const QStringList& ) ) );
245 connect( aPanel, SIGNAL( AxisChanged( const QString& ) ),
246 this, SLOT( onAxisChanged( const QString& ) ) );
248 connect( aPanel, SIGNAL( DDZValueChanged( double ) ), this, SLOT( onDDZValueChanged( double ) ) );
249 connect( aPanel, SIGNAL( SSValueChanged( double ) ), this, SLOT( onSSValueChanged( double ) ) );
251 connect( aPanel, SIGNAL( LeftBankChanged( const QString& ) ),
252 this, SLOT( onLeftBankChanged( const QString& ) ) );
254 connect( aPanel, SIGNAL( RightBankChanged( const QString& ) ),
255 this, SLOT( onRightBankChanged( const QString& ) ) );
257 connect( aPanel, SIGNAL( ProfilePointsChanged( int ) ), this, SLOT( onProfilePointsChanged( int ) ) );
259 connect( aPanel, SIGNAL( ModeChanged( bool ) ), this, SLOT( onModeChanged( bool ) ) );
264 void HYDROGUI_StreamOp::apply()
267 QApplication::setOverrideCursor( Qt::WaitCursor );
270 QString anObjectName = myEditedObject->GetName();
271 DEBTRACE("anObjectName " << anObjectName.toStdString());
276 int anUpdateFlags = 0;
279 bool aResult = false;
280 QStringList aBrowseObjectsEntries;
284 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
286 catch ( Standard_Failure& e )
288 anErrorMsg = e.GetMessageString();
296 QApplication::restoreOverrideCursor();
300 module()->update( anUpdateFlags );
301 commitDocOperation();
303 browseObjects( aBrowseObjectsEntries );
307 myEditedObject->Remove();
308 module()->setObjectRemoved( myEditedObject );
310 if ( isToAbortOnApply() )
314 SUIT_MessageBox::critical( module()->getApp()->desktop(),
315 tr( "CREATE_STREAM_ERROR" ),
320 //#include <HYDROData_StreamLinearInterpolation.h>
321 bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags,
322 QString& theErrorMsg,
323 QStringList& theBrowseObjectsEntries )
325 DEBTRACE("processApply");
326 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
330 // Check whether the object name is not empty
331 QString anObjectName = aPanel->getObjectName().simplified();
332 if ( anObjectName.isEmpty() )
334 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
338 // Check that there are no other objects with the same name in the document
339 if ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
341 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
342 if( !anObject.IsNull() )
344 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
349 if ( myEditedObject.IsNull() ) // Create new data model object
350 myEditedObject = Handle(HYDROData_Stream)::DownCast( doc()->CreateObject( KIND_STREAM ) );
352 Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast(
353 HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) );
354 //if ( aHydAxis.IsNull() )
356 // theErrorMsg = tr( "AXIS_NOT_DEFINED" );
360 // Check if at least 2 profiles is set
361 HYDROData_SequenceOfObjects aRefProfiles;
362 for ( int i = 0; i < myProfiles.length(); ++i )
364 QString aProfileName = myProfiles.value( i );
366 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
367 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
368 if ( !aProfile.IsNull() )
369 aRefProfiles.Append( aProfile );
372 if ( aRefProfiles.Length() < 2 )
374 theErrorMsg = tr( "PROFILES_NOT_DEFINED" );
378 int InterpMethod = aPanel->getMode();
380 myEditedObject->SetInterpolationMethod(InterpMethod);
382 if (InterpMethod == 0)
385 bool ToOrder = !aHydAxis.IsNull();
386 myEditedObject->SetProfiles (aRefProfiles, ToOrder) ;
387 myEditedObject->SetName( anObjectName );
389 if (!aHydAxis.IsNull())
390 myEditedObject->SetHydraulicAxis( aHydAxis );
391 myEditedObject->SetProfiles( aRefProfiles, false );
392 myEditedObject->SetDDZ( aPanel->getDDZ() );
393 myEditedObject->SetSpatialStep( aPanel->getSpatialStep() );
395 else if (InterpMethod == 1)
398 myEditedObject->SetProfiles (aRefProfiles, false) ;
399 myEditedObject->SetName( anObjectName );
400 if (!aHydAxis.IsNull())
401 myEditedObject->SetHydraulicAxis( aHydAxis );
402 Handle(HYDROData_PolylineXY) aLeftBank = Handle(HYDROData_PolylineXY)::DownCast(
403 HYDROGUI_Tool::FindObjectByName( module(), aPanel->getLeftBankName(), KIND_POLYLINEXY ) );
404 Handle(HYDROData_PolylineXY) aRightBank = Handle(HYDROData_PolylineXY)::DownCast(
405 HYDROGUI_Tool::FindObjectByName( module(), aPanel->getRightBankName(), KIND_POLYLINEXY ) );
406 myEditedObject->SetLeftBank(aLeftBank);
407 myEditedObject->SetRightBank(aRightBank);
409 myEditedObject->SetNbProfilePoints( aPanel->getNbProfilePoints() );
410 myEditedObject->SetHaxStep( aPanel->getSpatialStep() );
413 if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) )
415 myEditedObject->Update();
416 //NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>> warnings;
417 //myEditedObject->GetWarnings(warnings);
418 //QString totalWarning;
419 //for (NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>>::Iterator it(warnings); it.More(); it.Next())
421 // const QSet<QString>& V = it.Value();
424 // const Handle(HYDROData_Profile)& K = it.Key();
425 // QString ProfName = K->GetName();
426 // foreach (QString str, V)
428 // totalWarning + "Profile: " + ProfName + ": " + str + "\n";
431 //if (totalWarning != "")
432 // SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "WARNING" ), totalWarning);
437 myEditedObject->SetFillingColor( myEditedObject->DefaultFillingColor() );
438 myEditedObject->SetBorderColor( myEditedObject->DefaultBorderColor() );
444 // Show the object in case of creation mode of the operation
446 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true );
447 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
448 theBrowseObjectsEntries.append( anEntry );
451 module()->setIsToUpdate( myEditedObject );
454 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
459 void HYDROGUI_StreamOp::createPreview()
461 DEBTRACE("createPreview");
462 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
463 int mode = aPanel->getMode();
465 LightApp_Application* anApp = module()->getApp();
466 if ( !getPreviewManager() )
468 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
469 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
472 OCCViewer_ViewManager* aViewManager = getPreviewManager();
473 if ( aViewManager && !myPreviewPrs )
475 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
477 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
478 if ( !aCtx.IsNull() )
480 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
482 QColor aFillingColor = Qt::green;
483 QColor aBorderColor = Qt::transparent;
484 if ( !myEditedObject.IsNull() )
486 aFillingColor = myEditedObject->GetFillingColor();
487 aBorderColor = myEditedObject->GetBorderColor();
490 myPreviewPrs->setFillingColor( aFillingColor, false, false );
491 myPreviewPrs->setBorderColor( aBorderColor, false, false );
496 if ( !aViewManager || !myPreviewPrs )
501 Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast(
502 HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) );
504 HYDROData_SequenceOfObjects aRefProfiles;
505 //std::vector<Handle(HYDROData_Profile)> aRefProfiles;
506 int plen = myProfiles.length();
507 for ( int i = 0; i < plen; ++i )
509 QString aProfileName = myProfiles.value( i );
511 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
512 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
513 if ( !aProfile.IsNull() )
514 aRefProfiles.Append( aProfile );
517 HYDROData_Stream::PrsDefinition aPrsDef;
519 TopoDS_Shape Out3dPres;
520 TopoDS_Shape Out2dPres;
521 TopoDS_Shape OutLeftB;
522 TopoDS_Shape OutRightB;
523 TopoDS_Shape OutInlet;
524 TopoDS_Shape OutOutlet;
526 double ddz = aPanel->getDDZ();
527 double ss = aPanel->getSpatialStep();
529 std::set<int> InvInd;
532 const int MAX_POINTS_IN_PREVIEW = 50000;
534 const int MAX_POINTS_IN_PREVIEW = 500000;
537 HYDROData_Bathymetry::AltitudePoints points;
539 bool ProjStat = true;
540 NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>> warnings;
541 bool ToEstimateWarnings = false;
542 HYDROData_DTM::CreateProfilesFromDTM( aRefProfiles, ddz, ss, points, Out3dPres, Out2dPres, OutLeftB, OutRightB,
543 OutInlet, OutOutlet, true, true, InvInd, MAX_POINTS_IN_PREVIEW, ProjStat, warnings, ToEstimateWarnings );
545 aPanel->clearAllBackgroundColorsForProfileList();
546 // for (std::set<int>::const_iterator it = InvInd.begin(); it != InvInd.end(); it++)
547 // aPanel->setBackgroundColorForProfileList(*it, QColor(Qt::yellow));
549 aPrsDef.myInlet = OutInlet;
550 aPrsDef.myOutlet = OutOutlet;
551 aPrsDef.myLeftBank = OutLeftB;
552 aPrsDef.myRightBank = OutRightB;
554 aPrsDef.myPrs2D = Out2dPres;
555 aPrsDef.myPrs3D = Out3dPres;
557 aPanel->clearWarnings();
559 aPanel->addWarning(tr("STREAM_PROJECTION_FAILED"));
561 QVector<QString> warningsStr;
563 for (NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>>::Iterator it(warnings); it.More(); it.Next())
565 QSet<QString> V = it.Value();
568 const Handle(HYDROData_Profile)& K = it.Key();
569 QString ProfName = K->GetName();
570 foreach (QString str, V)
572 warningsStr.append(ProfName + ": " + str);
573 //aPanel->addWarning(ProfName + ": " + str);
576 aPanel->setBackgroundColorForProfileList(ProfName, QColor(Qt::yellow));
579 std::sort(warningsStr.begin(), warningsStr.end());
580 for (int k=0;k<warningsStr.size();k++)
581 aPanel->addWarning(warningsStr[k]);
583 myPreviewPrs->setShape( aPrsDef.myPrs2D );
587 aPanel->clearAllBackgroundColorsForProfileList();
588 aPanel->clearWarnings();
589 int nbProfPoints = aPanel->getNbProfilePoints();
590 double ss = aPanel->getSpatialStep();
591 QString axisName = aPanel->getAxisName();
592 QString leftBankName = aPanel->getLeftBankName();
593 QString rightBankName = aPanel->getRightBankName();
594 QList<Handle(HYDROData_Entity)> listProf = aPanel->getProfiles();
595 HYDROData_SequenceOfObjects seqProf;
596 foreach (Handle(HYDROData_Entity) ent, listProf)
599 Handle(HYDROData_PolylineXY) axis = Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), axisName, KIND_POLYLINEXY ) );
600 Handle(HYDROData_PolylineXY) LB = Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), leftBankName, KIND_POLYLINEXY ) );
601 Handle(HYDROData_PolylineXY) RB = Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), rightBankName, KIND_POLYLINEXY ) );
602 HYDROData_Bathymetry::AltitudePoints outBathypoints;
604 std::vector<std::string> warnings;
605 HYDROData_Stream::PrsDefinition prsDef;
607 HYDROData_StreamLinearInterpolation::Perform(seqProf, 500, 1, axis, LB, RB, outBathypoints, true, true, prsDef, &warnings);
609 myPreviewPrs->setShape( prsDef.myPrs2D );
610 for (int i=0;i<warnings.size();i++)
611 aPanel->addWarning(warnings[i].c_str());
615 void HYDROGUI_StreamOp::erasePreview()
617 DEBTRACE("erasePreview");
625 void HYDROGUI_StreamOp::onAddProfiles()
627 DEBTRACE("onAddProfiles");
628 //TODO skip if mode == 1??
629 Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast(
630 HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) );
631 //if ( aHydAxis.IsNull() )
635 HYDROData_Stream::BuildRefFace( aPlane );
637 // Get the current profiles list
638 QStringList aCurrentProfiles = myProfiles;
640 // Get the selected profiles ( in the Object Browser )
641 QStringList anInvalidProfiles;
642 QStringList anExistingProfiles;
643 QStringList aHasNoIntersectionProfiles;
644 QStringList aVerifiedProfiles;
646 HYDROData_SequenceOfObjects aSelectedProfiles = HYDROGUI_Tool::GetSelectedObjects( module() );
648 for( int i = 1, n = aSelectedProfiles.Length(); i <= n; i++ )
650 Handle(HYDROData_Profile) aProfile =
651 Handle(HYDROData_Profile)::DownCast( aSelectedProfiles.Value( i ) );
652 if ( aProfile.IsNull() )
655 QString aProfileName = aProfile->GetName();
656 Standard_Real aProfilePar = 0.0;
658 // Check the profile, if all is ok - add it to the list
659 if ( !aProfile->IsValid() )
661 // check whether the profile is valid
662 anInvalidProfiles << aProfileName;
664 else if ( aCurrentProfiles.contains( aProfileName ) )
666 // check whether the profile is already added
667 anExistingProfiles << aProfileName;
669 else if ( !HYDROData_Stream::HasIntersection( aHydAxis, aProfile, aPlane, aProfilePar ) )
671 // check whether the profile has intersection
672 aHasNoIntersectionProfiles << aProfileName;
676 // Insert profile in correct place
677 // if hidr axis is null => the params (myProfileParams) will be igrored. So ordering will be the same as in the aSelectedProfiles
678 insertProfileInToOrder( aProfileName, aProfilePar, myProfiles, myProfileParams );
679 aVerifiedProfiles << aProfileName;
683 // Show message box with the ignored profiles
684 if ( !anInvalidProfiles.isEmpty() ||
685 !anExistingProfiles.isEmpty() ||
686 !aHasNoIntersectionProfiles.isEmpty() )
688 QString aMessage = tr( "IGNORED_PROFILES" );
689 if ( !anInvalidProfiles.isEmpty() )
691 aMessage.append( "\n\n" );
692 aMessage.append( tr("INVALID_PROFILES").arg( anInvalidProfiles.join( "\n" ) ) );
694 if ( !anExistingProfiles.isEmpty() )
696 aMessage.append( "\n\n" );
697 aMessage.append( tr("EXISTING_PROFILES").arg( anExistingProfiles.join( "\n" ) ) );
699 if ( !aHasNoIntersectionProfiles.isEmpty() )
701 aMessage.append( "\n\n" );
702 aMessage.append( tr("NOT_INTERSECTED_PROFILES").arg( aHasNoIntersectionProfiles.join( "\n" ) ) );
705 SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "WARNING" ), aMessage );
708 if ( aVerifiedProfiles.isEmpty() )
718 void HYDROGUI_StreamOp::onRemoveProfiles( const QStringList& theProfilesToRemove )
720 DEBTRACE("onRemoveProfiles");
721 QStringList aToRemove = theProfilesToRemove;
723 aToRemove.removeDuplicates();
724 if ( aToRemove.isEmpty() )
727 bool isRemoved = false;
730 for ( int i = 0; i < aToRemove.length(); ++i )
732 const QString& aProfileName = aToRemove.value( i );
734 int aProfileId = myProfiles.indexOf( aProfileName );
735 if ( aProfileId < 0 )
738 myProfiles.removeAt( aProfileId );
739 myProfileParams.removeAt( aProfileId );
753 void HYDROGUI_StreamOp::onDDZValueChanged( double d )
755 DEBTRACE("onDDZValueChanged");
756 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
759 if (aPanel->getMode() == 0)
763 void HYDROGUI_StreamOp::onSSValueChanged( double d )
765 DEBTRACE("onSSValueChanged");
766 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
772 void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis )
774 DEBTRACE("onAxisChanged");
775 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
779 Handle(HYDROData_PolylineXY) aNewAxis = Handle(HYDROData_PolylineXY)::DownCast(
780 HYDROGUI_Tool::FindObjectByName( module(), theNewAxis, KIND_POLYLINEXY ) );
782 // Prepare data for intersection check
784 HYDROData_Stream::BuildRefFace( aPlane );
786 // SUIT_MessageBox::critical( module()->getApp()->desktop(),
787 // tr( "BAD_SELECTED_POLYLINE_TLT" ),
788 // tr( "BAD_SELECTED_POLYLINE_MSG" ).arg( theNewAxis ) );
789 // // To restore the old axis
790 // updatePanelData();
794 QStringList aNewProfiles;
795 QList<double> aNewProfileParams;
796 QStringList aHasNoIntersectionProfiles;
798 // Get list of profiles which do not intersect the axis
799 for ( int i = 0; i < myProfiles.length(); ++i )
801 QString aProfileName = myProfiles.value( i );
803 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
804 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
805 if ( aProfile.IsNull() )
808 Standard_Real aProfilePar = 0.0;
809 if ( HYDROData_Stream::HasIntersection( aNewAxis, aProfile, aPlane, aProfilePar ) )
811 // Insert profile in correct place
812 insertProfileInToOrder( aProfileName, aProfilePar, aNewProfiles, aNewProfileParams );
816 aHasNoIntersectionProfiles << aProfile->GetName();
820 // If there are profiles which don't intersect the new axis - show confirmation message box
821 bool isConfirmed = true;
822 if ( !aHasNoIntersectionProfiles.isEmpty() )
824 SUIT_MessageBox::StandardButtons aButtons =
825 SUIT_MessageBox::Yes | SUIT_MessageBox::No;
827 QString aMsg = aHasNoIntersectionProfiles.join( "\n" );
828 isConfirmed = SUIT_MessageBox::question( module()->getApp()->desktop(),
829 tr( "CONFIRMATION" ),
830 tr( "CONFIRM_AXIS_CHANGE" ).arg( aMsg ),
832 SUIT_MessageBox::Yes) == SUIT_MessageBox::Yes;
835 // Check if the user has confirmed axis change
838 // To restore the old axis
844 myHydAxis = theNewAxis;
845 myProfiles = aNewProfiles;
846 myProfileParams = aNewProfileParams;
856 void HYDROGUI_StreamOp::onLeftBankChanged( const QString& theNewAxis )
858 DEBTRACE("onLeftBankChanged");
859 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
862 if (aPanel->getMode() == 1)
866 void HYDROGUI_StreamOp::onRightBankChanged( const QString& theNewAxis )
868 DEBTRACE("onRightBankChanged");
869 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
872 if (aPanel->getMode() == 1)
876 void HYDROGUI_StreamOp::onProfilePointsChanged( int d )
878 DEBTRACE("onProfilePointsChanged");
879 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
882 if (aPanel->getMode() == 1)
886 void HYDROGUI_StreamOp::onModeChanged( bool mode )
888 DEBTRACE("onModeChanged");
892 void HYDROGUI_StreamOp::updatePanelData()
894 DEBTRACE("updatePanelData");
895 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
899 aPanel->setAxisName( myHydAxis );
900 aPanel->setProfiles( myProfiles );