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_CalculationOp.h"
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_CalculationDlg.h"
23 #include "HYDROGUI_Module.h"
24 #include "HYDROGUI_Tool.h"
25 #include "HYDROGUI_UpdateFlags.h"
26 #include "HYDROGUI_Zone.h"
27 #include "HYDROGUI_Region.h"
29 #include <HYDROData_PolylineXY.h>
30 #include <HYDROData_ShapesGroup.h>
31 #include <HYDROData_Iterator.h>
32 #include <HYDROData_ImmersibleZone.h>
33 #include <HYDROData_Object.h>
34 #include <HYDROData_Tool.h>
35 #include <HYDROData_StricklerTable.h>
37 #include <OCCViewer_ViewManager.h>
38 #include <OCCViewer_ViewModel.h>
39 #include <OCCViewer_ViewWindow.h>
41 #include <LightApp_Application.h>
42 #include <LightApp_UpdateFlags.h>
43 #include <LightApp_SelectionMgr.h>
44 #include <LightApp_DataOwner.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_DataBrowser.h>
50 #include <QApplication>
51 #include <QKeySequence>
54 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
55 : HYDROGUI_Operation( theModule ),
56 myIsEdit( theIsEdit ),
57 myActiveViewManager( NULL ),
58 myPreviewViewManager( NULL )
60 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
63 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
68 void HYDROGUI_CalculationOp::startOperation()
70 HYDROGUI_Operation::startOperation();
75 HYDROGUI_CalculationDlg* aPanel =
76 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
80 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
81 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
83 foreach( aShortcut, aShortcuts )
85 if ( aShortcut->key() ==
86 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
87 SUIT_DataBrowser::RenameShortcut ) ) )
89 aShortcut->setEnabled( false );
95 QStringList anEntryList;
96 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
97 getNamesAndEntries( aSeq, aList, anEntryList );
98 aPanel->setAllGeomObjects( aList, anEntryList );
103 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
104 Handle(HYDROData_PolylineXY) aPolylineObj;
105 QString aPolylineName;
106 for ( ; anIter.More(); anIter.Next() )
108 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
110 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
112 // Check the polyline shape
113 TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
114 if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
115 aPolylineName = aPolylineObj->GetName();
116 if ( !aPolylineName.isEmpty() )
118 aList.append( aPolylineName );
119 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
124 aPanel->setPolylineNames( aList, anEntryList );
126 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
128 myEditedObject.Nullify();
131 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
132 if ( !myEditedObject.IsNull() )
134 aPanel->setMode( myEditedObject->GetAssignmentMode() );
135 anObjectName = myEditedObject->GetName();
136 aPolylineObj = myEditedObject->GetBoundaryPolyline();
137 if ( aPolylineObj.IsNull() )
139 aPanel->setBoundary( QString() );
143 aPolylineName = aPolylineObj->GetName();
144 aPanel->setBoundary( aPolylineName );
147 aSeq = myEditedObject->GetGeometryObjects();
148 getNamesAndEntries( aSeq, aList, anEntryList );
149 aPanel->includeGeomObjects( aList );
152 setRules( HYDROData_CalculationCase::DataTag_CustomRules );
158 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
159 myEditedObject->SetName( anObjectName );
160 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
163 aPanel->setObjectName( anObjectName );
164 aPanel->setEditedObject( myEditedObject );
166 createPreview( false );
169 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
170 QStringList& theNames, QStringList& theEntries ) const
175 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
176 for ( ; anIter.More(); anIter.Next() )
178 Handle(HYDROData_Entity) anEntity = anIter.Value();
179 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
182 theNames.append( anEntity->GetName() );
183 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
187 void HYDROGUI_CalculationOp::abortOperation()
192 HYDROGUI_Operation::abortOperation();
193 module()->getApp()->updateObjectBrowser();
196 void HYDROGUI_CalculationOp::commitOperation()
199 // Commit transaction
200 commitDocOperation();
201 HYDROGUI_Operation::commitOperation();
204 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
206 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
208 // Connect signals and slots
209 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
210 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
211 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
212 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
213 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
215 connect( aPanel, SIGNAL( changeLandCoverMode( int ) ), SLOT( onChangeLandCoverMode( int ) ) );
216 connect( aPanel, SIGNAL( addLandCovers() ), SLOT( onAddLandCovers() ) );
217 connect( aPanel, SIGNAL( removeLandCovers() ), SLOT( onRemoveLandCovers() ) );
219 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
220 connect( aPanel, SIGNAL( orderLandCoverChanged( bool& ) ), SLOT( onOrderLandCoverChanged( bool& ) ) );
222 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
223 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones( const int ) ) );
224 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
225 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
226 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
227 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
228 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
229 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
230 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
231 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
232 connect( aPanel, SIGNAL( objectsSelected() ),
233 SLOT( onObjectsSelected() ) );
234 connect( aPanel, SIGNAL( landCoversSelected() ),
235 SLOT( onLandCoversSelected() ) );
236 connect( aPanel, SIGNAL( createLandCoverRegion( const QList<SUIT_DataObject*>& ) ),
237 SLOT( onCreateLandCoverRegion( const QList<SUIT_DataObject*>& ) ) );
238 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
239 SLOT( onBoundarySelected( const QString & ) ) );
240 connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
241 SLOT( onStricklerTableSelected( const QString & ) ) );
246 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
248 bool anIsToUpdateViewer = false;
250 // Remove the old boundary from the operation viewer
251 Handle(HYDROData_PolylineXY) aPrevPolyline =
252 myEditedObject->GetBoundaryPolyline();
253 if ( !aPrevPolyline.IsNull() )
255 setObjectVisibility( aPrevPolyline, false );
256 anIsToUpdateViewer = true;
259 // Set the selected boundary polyline to the calculation case
260 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
261 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
262 myEditedObject->SetBoundaryPolyline( aNewPolyline );
264 if ( myPreviewViewManager )
266 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
269 if ( !aNewPolyline.IsNull() )
271 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
272 if ( !aCtx.IsNull() )
274 setObjectVisibility( aNewPolyline, true );
275 anIsToUpdateViewer = true;
279 if ( anIsToUpdateViewer )
280 module()->update( UF_OCCViewer );
285 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
287 bool anIsToUpdateViewer = false;
289 // Remove old presentations of land covers from the operation viewer
290 Handle(HYDROData_Entity) anEntity;
291 Handle(HYDROData_LandCover) aLandCover;
292 HYDROData_SequenceOfObjects aLandCovers;
293 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
294 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
295 for ( ; anIter.More(); anIter.Next() )
297 anEntity = anIter.Value();
298 if ( !anEntity.IsNull() )
300 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
301 if ( !aLandCover.IsNull() )
303 aLandCovers.Append( aLandCover );
304 setObjectVisibility( aLandCover, false );
305 anIsToUpdateViewer = true;
310 // Set the selected Strickler table to the calculation case
311 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
312 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
313 myEditedObject->SetStricklerTable( aNewStricklerTable );
315 if ( myPreviewViewManager )
317 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
320 if ( !aNewStricklerTable.IsNull() )
322 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
323 if ( !aCtx.IsNull() )
325 HYDROData_SequenceOfObjects::Iterator anIter( aLandCovers );
326 for ( ; anIter.More(); anIter.Next() )
328 anEntity = anIter.Value();
329 if ( !anEntity.IsNull() )
331 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
332 if ( !aLandCover.IsNull() )
334 setObjectVisibility( aLandCover, true );
335 anIsToUpdateViewer = true;
342 if ( anIsToUpdateViewer )
343 module()->update( UF_OCCViewer );
348 void HYDROGUI_CalculationOp::onObjectsSelected()
350 HYDROGUI_CalculationDlg* aPanel =
351 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
353 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
354 QMap<QString, bool> aSelectedObjsMap;
355 foreach( QString aName, aSelectedObjs )
356 aSelectedObjsMap[aName] = true;
359 // Select the appropriate geometry object shape in the viewer
360 selectionMgr()->clearSelected();
362 // Unhighlight all objects except selected
363 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
364 Handle(HYDROData_Entity) anEntity;
365 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
366 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
369 for ( ; anIter.More(); anIter.Next() )
371 anEntity = anIter.Value();
372 if ( !anEntity.IsNull() )
374 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
377 aName = anEntity->GetName();
378 isSelected = aSelectedObjsMap.contains( aName );
379 aShape->highlight( isSelected, false );
380 aShape->update( false, false );
386 aLastShape->update( true, false );
389 void HYDROGUI_CalculationOp::onLandCoversSelected()
391 HYDROGUI_CalculationDlg* aPanel =
392 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
394 QStringList aSelectedObjs = aPanel->getSelectedLandCovers();
395 QMap<QString, bool> aSelectedObjsMap;
396 foreach( QString aName, aSelectedObjs )
397 aSelectedObjsMap[aName] = true;
400 // Select the appropriate land cover shape in the viewer
401 selectionMgr()->clearSelected();
403 // Unhighlight all land covers except selected
404 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
405 Handle(HYDROData_Entity) anEntity;
406 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
407 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
410 for ( ; anIter.More(); anIter.Next() )
412 anEntity = anIter.Value();
413 if ( !anEntity.IsNull() )
415 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
418 aName = anEntity->GetName();
419 isSelected = aSelectedObjsMap.contains( aName );
420 aShape->highlight( isSelected, false );
421 aShape->update( false, false );
427 aLastShape->update( true, false );
430 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
432 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
433 HYDROGUI_Zone* aZoneItem;
434 selectionMgr()->clearSelected();
437 // Select a region in preview
438 SUIT_DataOwnerPtrList aList( true );
439 DataObjectList aZones = aRegionItem->children();
440 for ( int i = 0; i < aZones.length(); i++ )
442 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
445 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
448 selectionMgr()->setSelected( aList );
452 // select a single zone
453 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
456 SUIT_DataOwnerPtrList aList( true );
457 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
458 selectionMgr()->setSelected( aList );
463 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
465 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
468 QList<HYDROGUI_Zone*> aZonesList;
469 HYDROGUI_Zone* aZone;
470 // Get a list of dropped zones
471 for ( int i = 0; i < theZonesList.length(); i++ )
473 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
476 aZonesList.append( aZone );
479 if ( aZonesList.length() > 0 )
481 aRegion->addZones( aZonesList );
482 HYDROGUI_CalculationDlg* aPanel =
483 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
486 aPanel->refreshZonesBrowser();
488 createPreview( false );
493 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
495 if ( createRegion( theZonesList, false ) )
497 HYDROGUI_CalculationDlg* aPanel =
498 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
501 aPanel->refreshZonesBrowser();
503 createPreview( false );
507 void HYDROGUI_CalculationOp::onCreateLandCoverRegion( const QList<SUIT_DataObject*>& theZonesList )
509 if ( createRegion( theZonesList, true ) )
511 HYDROGUI_CalculationDlg* aPanel =
512 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
515 aPanel->refreshLandCoverZonesBrowser();
517 createPreview( true );
521 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theAltitudeName )
523 HYDROGUI_CalculationDlg* aPanel =
524 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
527 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
530 aZone->setMergeType( theMergeType, theAltitudeName );
531 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
534 aShape->update( true, false );
537 aPanel->refreshZonesBrowser();
541 void HYDROGUI_CalculationOp::onAddObjects()
543 HYDROGUI_CalculationDlg* aPanel =
544 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
548 // Add geometry objects selected in the module browser to the calculation case
549 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
550 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
553 QStringList anAddedList;
554 for (int i = 0; i < aSelectedList.length(); i++)
556 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
557 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
558 if ( anObject.IsNull() )
561 if ( myEditedObject->AddGeometryObject( anObject ) )
562 anAddedList.append( anObject->GetName() );
565 if ( !anAddedList.isEmpty() )
567 aPanel->includeGeomObjects( anAddedList );
568 createPreview( false );
572 void HYDROGUI_CalculationOp::onRemoveObjects()
574 // Remove selected objects from the calculation case
575 HYDROGUI_CalculationDlg* aPanel =
576 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
580 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
581 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
584 for (int i = 0; i < aSelectedList.length(); i++)
586 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
587 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
588 if ( anObject.IsNull() )
591 setObjectVisibility( anObject, false );
592 myEditedObject->RemoveGeometryObject( anObject );
595 module()->update( UF_OCCViewer );
596 aPanel->excludeGeomObjects( aSelectedList );
599 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
601 // Check if the case is already modified or not
602 bool isConfirmed = myEditedObject->IsMustBeUpdated();
605 // If not modified check if the case has already defined regions with zones
606 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
607 if ( aSeq.Length() > 0 )
609 // If there are already defined zones then ask a user to confirm zones recalculation
610 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
611 tr( "REGIONS_CHANGED" ),
612 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
613 QMessageBox::Yes | QMessageBox::No,
614 QMessageBox::No ) == QMessageBox::Yes );
618 isConfirmed = true; // No regions - no zones - nothing to recalculate
624 bool HYDROGUI_CalculationOp::confirmOrderChange() const
626 // Check if the case is already modified or not
627 bool isConfirmed = myEditedObject->IsMustBeUpdated();
630 // If not modified check if the case has already defined regions with zones
631 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
632 if ( aSeq.Length() > 0 )
634 // If there are already defined zones then ask a user to confirm zones recalculation
635 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
636 tr( "ORDER_CHANGED" ),
637 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
638 QMessageBox::Yes | QMessageBox::No,
639 QMessageBox::No ) == QMessageBox::Yes );
643 isConfirmed = true; // No regions - no zones - nothing to recalculate
649 bool HYDROGUI_CalculationOp::confirmModeChange() const
651 // Check if the case is already modified or not
652 bool isConfirmed = myEditedObject->IsMustBeUpdated();
655 // If not modified check if the case has already defined regions with zones
656 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
657 if ( aSeq.Length() > 0 )
659 // If there are already defined zones then ask a user to confirm zones recalculation
660 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
661 tr( "MODE_CHANGED" ),
662 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
663 QMessageBox::Yes | QMessageBox::No,
664 QMessageBox::No ) == QMessageBox::Yes );
668 isConfirmed = true; // No regions - no zones - nothing to recalculate
674 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
676 HYDROData_WarningType aType = theWarning.Type;
677 if ( aType == WARN_OK ) {
685 case WARN_EMPTY_REGIONS:
686 aTitle = tr( "EMPTY_REGIONS" );
687 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
690 aTitle = tr( "WARNING" );
691 aMsg = theWarning.Data;
695 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
697 QMessageBox::Yes | QMessageBox::No,
700 return ( anAnswer == QMessageBox::Yes );
703 bool HYDROGUI_CalculationOp::confirmLandCoverModeChange() const
705 // Check if the case is already modified or not
706 bool isConfirmed = myEditedObject->IsMustBeUpdated();
709 // If not modified check if the case has already defined regions with zones
710 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
711 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
712 if ( aSeq.Length() > 0 )
714 // If there are already defined zones then ask a user to confirm zones recalculation
715 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
716 tr( "MODE_CHANGED" ),
717 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_MODE" ),
718 QMessageBox::Yes | QMessageBox::No,
719 QMessageBox::No ) == QMessageBox::Yes );
723 isConfirmed = true; // No regions - no zones - nothing to recalculate
729 bool HYDROGUI_CalculationOp::confirmLandCoverOrderChange() const
731 // Check if the case is already modified or not
732 bool isConfirmed = myEditedObject->IsMustBeUpdated();
735 // If not modified check if the case has already defined regions with zones
736 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
737 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
738 if ( aSeq.Length() > 0 )
740 // If there are already defined zones then ask a user to confirm zones recalculation
741 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
742 tr( "ORDER_CHANGED" ),
743 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
744 QMessageBox::Yes | QMessageBox::No,
745 QMessageBox::No ) == QMessageBox::Yes );
749 isConfirmed = true; // No regions - no zones - nothing to recalculate
755 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
756 QString& theErrorMsg,
757 QStringList& theBrowseObjectsEntries )
759 HYDROGUI_CalculationDlg* aPanel =
760 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
766 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
767 theBrowseObjectsEntries.append( anEntry );
770 // For manual mode priority rules are redundant
771 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
772 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
774 if ( aPanel->getLandCoverMode() == HYDROData_CalculationCase::MANUAL ) {
775 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, false );
778 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
783 void HYDROGUI_CalculationOp::onApply()
786 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
787 if ( aWarning.Type != WARN_OK ) {
788 if ( !confirmContinueWithWarning( aWarning ) ) {
789 // Go back to the first page
790 HYDROGUI_CalculationDlg* aPanel =
791 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
793 aPanel->onFirstPage();
799 QApplication::setOverrideCursor( Qt::WaitCursor );
801 int anUpdateFlags = 0;
803 QStringList aBrowseObjectsEntries;
805 bool aResult = false;
809 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
811 catch ( Standard_Failure )
813 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
814 anErrorMsg = aFailure->GetMessageString();
822 QApplication::restoreOverrideCursor();
826 module()->update( anUpdateFlags );
828 browseObjects( aBrowseObjectsEntries );
833 QString aMsg = tr( "INPUT_VALID_DATA" );
834 if( !anErrorMsg.isEmpty() )
835 aMsg.prepend( anErrorMsg + "\n" );
836 SUIT_MessageBox::critical( module()->getApp()->desktop(),
837 tr( "INSUFFICIENT_INPUT_DATA" ),
842 void HYDROGUI_CalculationOp::onNext( const int theIndex )
846 setAvailableGroups();
848 else if( theIndex==2 )
851 HYDROGUI_CalculationDlg* aPanel =
852 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
857 QStringList anEntryList;
858 HYDROData_SequenceOfObjects aSeq;
860 Handle(HYDROData_StricklerTable) aStricklerTableObj;
861 QString aStricklerTableName;
863 // Get all Strickler table objects to fill in combo-box
866 HYDROData_Iterator anIter( doc(), KIND_STRICKLER_TABLE );
867 for ( ; anIter.More(); anIter.Next() )
869 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
871 if ( !aStricklerTableObj.IsNull() )
873 aStricklerTableName = aStricklerTableObj->GetName();
874 if ( !aStricklerTableName.isEmpty() )
876 aList.append( aStricklerTableName );
877 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
881 aPanel->setStricklerTableNames( aList, anEntryList );
882 if ( !aList.isEmpty() )
883 aPanel->setStricklerTable( aList.at( 0 ), false );
885 // Fill in list widget with all available land covers
886 aSeq = HYDROGUI_Tool::GetLandCovers( module() );
887 getNamesAndEntries( aSeq, aList, anEntryList );
888 aPanel->setAllLandCovers( aList, anEntryList );
890 // Set list of included land covers
891 aSeq = myEditedObject->GetLandCovers();
892 getNamesAndEntries( aSeq, aList, anEntryList );
893 aPanel->includeLandCovers( aList, true );
895 if ( !myEditedObject.IsNull() )
899 // Select the certain Strickler table object in combo-box
900 aStricklerTableObj = myEditedObject->GetStricklerTable();
901 if ( aStricklerTableObj.IsNull() )
903 aPanel->setStricklerTable( QString() );
907 aStricklerTableName = aStricklerTableObj->GetName();
908 aPanel->setStricklerTable( aStricklerTableName );
911 // Set mode (Auto or Manual) to defined priority of land covers
912 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
914 // Set rules defined on land covers
915 setRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
919 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getLandCoverMode() );
923 else if( theIndex==3 )
925 HYDROGUI_CalculationDlg* aPanel =
926 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
930 QApplication::setOverrideCursor( Qt::WaitCursor );
932 QString aNewCaseName = aPanel->getObjectName();
933 QString anOldCaseName = myEditedObject->GetName();
934 bool isNameChanged = anOldCaseName != aNewCaseName;
936 bool anIsToUpdateOb = isNameChanged;
938 // At first we must to update the case name because of
939 // automatic names generation for regions and zones
940 myEditedObject->SetName( aNewCaseName );
942 // Set parameters for automatic mode
943 int aMode = aPanel->getMode();
944 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
946 // Set objects in the specified order
947 if( myEditedObject->IsMustBeUpdated() )
949 myEditedObject->RemoveGeometryObjects();
950 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
952 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
953 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
954 if ( anObject.IsNull() )
958 myEditedObject->AddGeometryObject( anObject );
961 // Clear priority rules
962 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
963 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
965 // Set priority rules
966 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
967 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
968 aRule.Object2, aRule.MergeType,
969 HYDROData_CalculationCase::DataTag_CustomRules );
973 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
975 if ( myEditedObject->IsMustBeUpdated() )
978 myEditedObject->Update();
980 AssignDefaultZonesColors( false );
982 //aPanel->setEditedObject( myEditedObject );
983 aPanel->refreshZonesBrowser();
986 createPreview( false );
988 anIsToUpdateOb = true;
990 myEditedObject->SetToUpdate( true );
995 setZonesVisible( true, false );
997 if ( isNameChanged ) {
998 module()->getDataModel()->updateObjectTree( myEditedObject );
1002 QApplication::restoreOverrideCursor();
1004 else if( theIndex==4 )
1006 // Partition of Land covers panel
1007 HYDROGUI_CalculationDlg* aPanel =
1008 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1012 QApplication::setOverrideCursor( Qt::WaitCursor );
1014 // Set parameters for automatic mode
1015 int aMode = aPanel->getLandCoverMode();
1016 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1018 // Set objects in the specified order
1019 if( myEditedObject->IsMustBeUpdated() )
1021 myEditedObject->RemoveLandCovers();
1022 foreach ( const QString& aName, aPanel->getAllLandCovers() )
1024 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast(
1025 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1026 if ( aLandCover.IsNull() )
1030 myEditedObject->AddLandCover( aLandCover );
1033 // Clear priority rules
1034 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true );
1035 // Set priority rules
1036 foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) {
1037 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1038 aRule.Object2, HYDROData_Zone::Merge_Object,
1039 HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
1043 aPanel->setEditLandCoversEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1045 bool anIsToUpdateOb = false;
1046 if ( myEditedObject->IsMustBeUpdated() )
1049 myEditedObject->Update();
1051 AssignDefaultZonesColors( true );
1053 aPanel->refreshLandCoverZonesBrowser();
1056 createPreview( true );
1058 anIsToUpdateOb = true;
1060 myEditedObject->SetToUpdate( true );
1065 setZonesVisible( false, false );
1066 // Show land cover zones
1067 setZonesVisible( true, true );
1070 if ( anIsToUpdateOb ) {
1071 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
1072 if ( anObjBrowser ) {
1073 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
1077 QApplication::restoreOverrideCursor();
1081 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
1086 setZonesVisible( false, false );
1088 else if( theIndex==4 )
1090 // Hide land cover zones
1091 setZonesVisible( false, true );
1095 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible, const bool theLandCover )
1097 myShowZones = theIsVisible;
1098 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1099 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1100 HYDROData_SequenceOfObjects aZones;
1101 Handle(HYDROData_Region) aRegion;
1102 if ( myPreviewViewManager )
1104 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1106 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1107 if ( !aCtx.IsNull() )
1109 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1111 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1112 if ( !aRegion.IsNull() )
1114 aZones = aRegion->GetZones();
1115 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1116 for ( ; aZonesIter.More(); aZonesIter.Next() )
1118 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1124 module()->update( UF_OCCViewer );
1129 void HYDROGUI_CalculationOp::AssignDefaultZonesColors( const bool theLandCover )
1131 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1132 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1133 HYDROData_SequenceOfObjects aZones;
1134 Handle(HYDROData_Region) aRegion;
1135 if ( myPreviewViewManager )
1137 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1139 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1140 if ( !aCtx.IsNull() )
1143 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1145 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1146 if ( !aRegion.IsNull() )
1148 aZones = aRegion->GetZones();
1149 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1150 for ( ; aZonesIter.More(); aZonesIter.Next() )
1153 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1154 if ( !aZone.IsNull() )
1156 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
1157 while (aFillingColor == Qt::red)
1158 aFillingColor = GenerateDefaultZonesColor(++aCounter);
1160 aZone->SetColor(aFillingColor);
1170 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
1171 float theSaturation/* = 0.5*/,
1172 float theValue/* = 0.95*/ ) const
1174 float aGoldenRatioConjugate = (float)(360./582.);
1175 float aHue = (float)rand();
1176 aHue += aGoldenRatioConjugate*theIndex;
1177 aHue -= floor(aHue);
1179 float aR = 0., aG = 0., aB = 0.;
1180 int aHueInt = (int)(aHue*6.);
1181 float aF = aHue*6. - aHueInt;
1182 float aP = theValue * (1. - theSaturation);
1183 float aQ = theValue * (1. - aF*theSaturation);
1184 float aT = theValue * (1. - (1. - aF) * theSaturation);
1187 case 0: { aR = theValue; aG = aT; aB = aP; break; }
1188 case 1: { aR = aQ; aG = theValue; aB = aP; break; }
1189 case 2: { aR = aP; aG = theValue; aB = aT; break; }
1190 case 3: { aR = aP; aG = aQ; aB = theValue; break; }
1191 case 4: { aR = aT; aG = aP; aB = theValue; break; }
1192 case 5: { aR = theValue; aG = aP; aB = aQ; break; }
1196 QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
1197 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
1200 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1202 HYDROGUI_CalculationDlg* aPanel =
1203 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1207 HYDROData_ListOfRules aRules;
1208 Handle(HYDROData_Entity) anObject1, anObject2;
1209 HYDROData_PriorityType aPriority;
1210 HYDROData_Zone::MergeAltitudesType aMergeType;
1211 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1212 for ( int anIndex = 0; ; anIndex++ )
1214 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1215 HYDROData_CustomRule aRule;
1216 aRule.Object1 = anObject1;
1217 aRule.Object2 = anObject2;
1218 aRule.Priority = aPriority;
1219 aRule.MergeType = aMergeType;
1227 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1228 aPanel->setRules( aRules );
1229 else if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomLandCoverRules )
1230 aPanel->setLandCoverRules( aRules );
1233 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList,
1234 const bool theLandCover )
1236 bool aRetValue = false;
1238 QList<HYDROGUI_Zone*> aZonesList;
1239 HYDROGUI_Zone* aZone;
1240 // Get a list of dropped zones
1241 for ( int i = 0; i < theZonesList.length(); i++ )
1243 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1246 aZonesList.append( aZone );
1249 if ( aZonesList.length() > 0 )
1251 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList, theLandCover );
1258 void HYDROGUI_CalculationOp::createPreview( const bool theLandCover )
1260 LightApp_Application* anApp = module()->getApp();
1261 HYDROData_SequenceOfObjects aSeq;
1263 aSeq = myEditedObject->GetLandCovers();
1265 aSeq = myEditedObject->GetGeometryObjects();
1266 Handle(HYDROData_Entity) anEntity;
1270 // Gather zones for displaying
1271 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1272 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1273 HYDROData_SequenceOfObjects aZones;
1274 Handle(HYDROData_Region) aRegion;
1275 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1277 anEntity = aRegionsIter.Value();
1278 if ( !anEntity.IsNull() )
1280 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1281 if ( !aRegion.IsNull() )
1283 aZones = aRegion->GetZones();
1284 aSeq.Append( aZones );
1290 // Get a boundary polyline if any
1291 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
1293 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1295 if ( !myActiveViewManager )
1297 if ( aSeq.IsEmpty() )
1300 myActiveViewManager = anApp->activeViewManager();
1303 if ( !myPreviewViewManager )
1305 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1306 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1307 if ( myPreviewViewManager )
1309 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1310 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1312 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1313 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1317 if ( !myPreviewViewManager )
1320 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1322 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1323 if ( !aCtx.IsNull() )
1325 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1326 for ( ; anIter.More(); anIter.Next() )
1328 setObjectVisibility( anIter.Value(), true );
1331 //Process the draw events for viewer
1332 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1333 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
1337 module()->update( UF_OCCViewer | UF_FitAll );
1341 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1343 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1347 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1349 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1353 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1358 void HYDROGUI_CalculationOp::closePreview()
1360 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1361 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1362 QShortcut* aShortcut;
1363 foreach( aShortcut, aShortcuts )
1365 if ( aShortcut->key() ==
1366 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1367 SUIT_DataBrowser::RenameShortcut ) ) )
1369 aShortcut->setEnabled( true );
1374 if( myPreviewViewManager )
1376 // Hide all the displayed objects in the preview view
1377 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1379 size_t aViewId = (size_t)aViewer;
1380 HYDROData_Iterator anIterator( doc() );
1381 for( ; anIterator.More(); anIterator.Next() ) {
1382 Handle(HYDROData_Entity) anObject = anIterator.Current();
1383 if( !anObject.IsNull() ) {
1384 module()->setObjectVisible( aViewId, anObject, false );
1389 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1390 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1392 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1393 myPreviewViewManager = NULL;
1396 if( myActiveViewManager )
1398 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1399 myActiveViewManager = NULL;
1403 void HYDROGUI_CalculationOp::setAvailableGroups()
1405 HYDROGUI_CalculationDlg* aPanel =
1406 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1408 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1409 QStringList aList, anEntryList;
1410 getNamesAndEntries( aSeq, aList, anEntryList );
1412 QStringList aGroupsNames;
1414 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1415 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1417 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1418 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1419 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1421 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1422 aGroupsNames.append( aGroup->GetName() );
1425 if( myEditedObject->IsMustBeUpdated() ) {
1426 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1427 Handle(HYDROData_ShapesGroup) aGeomGroup =
1428 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1429 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1430 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1435 aPanel->setAvailableGroups( aGroupsNames );
1436 aPanel->includeGroups( aList );
1438 bool isUpdated = myEditedObject->IsMustBeUpdated();
1441 void HYDROGUI_CalculationOp::onAddGroups()
1443 HYDROGUI_CalculationDlg* aPanel =
1444 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1448 // Add geometry objects selected in the module browser to the calculation case
1449 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1450 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1453 QStringList anAddedList;
1454 for (int i = 0; i < aSelectedList.length(); i++)
1456 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1457 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1458 if ( aGroup.IsNull() )
1461 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1462 anAddedList.append( aGroup->GetName() );
1465 if ( !anAddedList.isEmpty() )
1467 aPanel->includeGroups( anAddedList );
1471 void HYDROGUI_CalculationOp::onRemoveGroups()
1473 // Remove selected objects from the calculation case
1474 HYDROGUI_CalculationDlg* aPanel =
1475 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1479 QStringList aSelectedList = aPanel->getSelectedGroups();
1480 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1483 for (int i = 0; i < aSelectedList.length(); i++)
1485 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1486 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1487 if ( aGroup.IsNull() )
1490 myEditedObject->RemoveGeometryGroup( aGroup );
1493 aPanel->excludeGroups( aSelectedList );
1496 void HYDROGUI_CalculationOp::onChangeLandCoverMode( int theMode )
1498 HYDROGUI_CalculationDlg* aPanel =
1499 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1503 if ( !confirmLandCoverModeChange() ) {
1504 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
1508 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1509 aPanel->setLandCoverMode( theMode );
1512 void HYDROGUI_CalculationOp::onAddLandCovers()
1514 HYDROGUI_CalculationDlg* aPanel =
1515 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1519 // Add land covers selected in the module browser to the calculation case
1520 QStringList aSelectedList = aPanel->getSelectedAvailableLandCovers();
1521 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1524 QStringList anAddedList;
1525 for (int i = 0; i < aSelectedList.length(); i++)
1527 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1528 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1529 if ( anObject.IsNull() )
1532 if ( myEditedObject->AddLandCover( anObject ) )
1533 anAddedList.append( anObject->GetName() );
1536 if ( !anAddedList.isEmpty() )
1538 aPanel->includeLandCovers( anAddedList, false );
1539 createPreview( true );
1543 void HYDROGUI_CalculationOp::onRemoveLandCovers()
1545 // Remove selected objects from the calculation case
1546 HYDROGUI_CalculationDlg* aPanel =
1547 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1551 QStringList aSelectedList = aPanel->getSelectedLandCovers();
1552 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1555 for (int i = 0; i < aSelectedList.length(); i++)
1557 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1558 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1559 if ( anObject.IsNull() )
1562 setObjectVisibility( anObject, false );
1563 myEditedObject->RemoveLandCover( anObject );
1566 module()->update( UF_OCCViewer );
1567 aPanel->excludeLandCovers( aSelectedList );
1570 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1572 HYDROGUI_CalculationDlg* aPanel =
1573 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1577 if ( !confirmModeChange() ) {
1578 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1582 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1583 aPanel->setMode( theMode );
1586 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1588 HYDROGUI_CalculationDlg* aPanel =
1589 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1593 isConfirmed = confirmOrderChange();
1595 myEditedObject->SetToUpdate( true );
1598 void HYDROGUI_CalculationOp::onOrderLandCoverChanged( bool& isConfirmed )
1600 HYDROGUI_CalculationDlg* aPanel =
1601 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1605 isConfirmed = confirmLandCoverOrderChange();
1607 myEditedObject->SetToUpdate( true );