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 ),
59 myShowGeomObjects( true ),
62 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
65 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
70 void HYDROGUI_CalculationOp::startOperation()
72 HYDROGUI_Operation::startOperation();
77 HYDROGUI_CalculationDlg* aPanel =
78 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
82 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
83 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
85 foreach( aShortcut, aShortcuts )
87 if ( aShortcut->key() ==
88 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
89 SUIT_DataBrowser::RenameShortcut ) ) )
91 aShortcut->setEnabled( false );
97 QStringList anEntryList;
98 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
99 getNamesAndEntries( aSeq, aList, anEntryList );
100 aPanel->setAllGeomObjects( aList, anEntryList );
105 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
106 Handle(HYDROData_PolylineXY) aPolylineObj;
107 QString aPolylineName;
108 for ( ; anIter.More(); anIter.Next() )
110 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
112 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
114 // Check the polyline shape
115 TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
116 if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
117 aPolylineName = aPolylineObj->GetName();
118 if ( !aPolylineName.isEmpty() )
120 aList.append( aPolylineName );
121 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
126 aPanel->setPolylineNames( aList, anEntryList );
128 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
130 myEditedObject.Nullify();
133 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
134 if ( !myEditedObject.IsNull() )
136 aPanel->setMode( myEditedObject->GetAssignmentMode() );
137 anObjectName = myEditedObject->GetName();
138 aPolylineObj = myEditedObject->GetBoundaryPolyline();
139 if ( aPolylineObj.IsNull() )
141 aPanel->setBoundary( QString() );
145 aPolylineName = aPolylineObj->GetName();
146 aPanel->setBoundary( aPolylineName );
149 aSeq = myEditedObject->GetGeometryObjects();
150 getNamesAndEntries( aSeq, aList, anEntryList );
151 aPanel->includeGeomObjects( aList );
154 setRules( HYDROData_CalculationCase::DataTag_CustomRules );
160 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
161 myEditedObject->SetName( anObjectName );
162 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
165 aPanel->setObjectName( anObjectName );
166 aPanel->setEditedObject( myEditedObject );
171 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
172 QStringList& theNames, QStringList& theEntries ) const
177 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
178 for ( ; anIter.More(); anIter.Next() )
180 Handle(HYDROData_Entity) anEntity = anIter.Value();
181 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
184 theNames.append( anEntity->GetName() );
185 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
189 void HYDROGUI_CalculationOp::abortOperation()
194 HYDROGUI_Operation::abortOperation();
195 module()->getApp()->updateObjectBrowser();
198 void HYDROGUI_CalculationOp::commitOperation()
201 // Commit transaction
202 commitDocOperation();
203 HYDROGUI_Operation::commitOperation();
206 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
208 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
210 // Connect signals and slots
211 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
212 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
213 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
214 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
215 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
217 connect( aPanel, SIGNAL( changeLandCoverMode( int ) ), SLOT( onChangeLandCoverMode( int ) ) );
218 connect( aPanel, SIGNAL( addLandCovers() ), SLOT( onAddLandCovers() ) );
219 connect( aPanel, SIGNAL( removeLandCovers() ), SLOT( onRemoveLandCovers() ) );
221 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
222 connect( aPanel, SIGNAL( orderLandCoverChanged( bool& ) ), SLOT( onOrderLandCoverChanged( bool& ) ) );
224 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
225 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onBack( const int ) ) );
226 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
227 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
228 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
229 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
230 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
231 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
232 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
233 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
234 connect( aPanel, SIGNAL( objectsSelected() ),
235 SLOT( onObjectsSelected() ) );
236 connect( aPanel, SIGNAL( landCoversSelected() ),
237 SLOT( onLandCoversSelected() ) );
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();
493 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
495 QList<HYDROGUI_Zone*> aZonesList;
496 HYDROGUI_Zone* aZone;
497 // Get a list of dropped zones
498 for ( int i = 0; i < theZonesList.length(); i++ )
500 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
503 aZonesList.append( aZone );
506 if ( aZonesList.length() > 0 )
508 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
509 HYDROGUI_CalculationDlg* aPanel =
510 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
513 aPanel->refreshZonesBrowser();
519 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theAltitudeName )
521 HYDROGUI_CalculationDlg* aPanel =
522 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
525 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
528 aZone->setMergeType( theMergeType, theAltitudeName );
529 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
532 aShape->update( true, false );
535 aPanel->refreshZonesBrowser();
539 void HYDROGUI_CalculationOp::onAddObjects()
541 HYDROGUI_CalculationDlg* aPanel =
542 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
546 // Add geometry objects selected in the module browser to the calculation case
547 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
548 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
551 QStringList anAddedList;
552 for (int i = 0; i < aSelectedList.length(); i++)
554 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
555 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
556 if ( anObject.IsNull() )
559 if ( myEditedObject->AddGeometryObject( anObject ) )
560 anAddedList.append( anObject->GetName() );
563 if ( !anAddedList.isEmpty() )
565 aPanel->includeGeomObjects( anAddedList );
570 void HYDROGUI_CalculationOp::onRemoveObjects()
572 // Remove selected objects from the calculation case
573 HYDROGUI_CalculationDlg* aPanel =
574 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
578 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
579 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
582 for (int i = 0; i < aSelectedList.length(); i++)
584 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
585 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
586 if ( anObject.IsNull() )
589 setObjectVisibility( anObject, false );
590 myEditedObject->RemoveGeometryObject( anObject );
593 module()->update( UF_OCCViewer );
594 aPanel->excludeGeomObjects( aSelectedList );
597 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
599 // Check if the case is already modified or not
600 bool isConfirmed = myEditedObject->IsMustBeUpdated();
603 // If not modified check if the case has already defined regions with zones
604 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
605 if ( aSeq.Length() > 0 )
607 // If there are already defined zones then ask a user to confirm zones recalculation
608 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
609 tr( "REGIONS_CHANGED" ),
610 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
611 QMessageBox::Yes | QMessageBox::No,
612 QMessageBox::No ) == QMessageBox::Yes );
616 isConfirmed = true; // No regions - no zones - nothing to recalculate
622 bool HYDROGUI_CalculationOp::confirmOrderChange() const
624 // Check if the case is already modified or not
625 bool isConfirmed = myEditedObject->IsMustBeUpdated();
628 // If not modified check if the case has already defined regions with zones
629 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
630 if ( aSeq.Length() > 0 )
632 // If there are already defined zones then ask a user to confirm zones recalculation
633 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
634 tr( "ORDER_CHANGED" ),
635 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
636 QMessageBox::Yes | QMessageBox::No,
637 QMessageBox::No ) == QMessageBox::Yes );
641 isConfirmed = true; // No regions - no zones - nothing to recalculate
647 bool HYDROGUI_CalculationOp::confirmModeChange() const
649 // Check if the case is already modified or not
650 bool isConfirmed = myEditedObject->IsMustBeUpdated();
653 // If not modified check if the case has already defined regions with zones
654 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
655 if ( aSeq.Length() > 0 )
657 // If there are already defined zones then ask a user to confirm zones recalculation
658 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
659 tr( "MODE_CHANGED" ),
660 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
661 QMessageBox::Yes | QMessageBox::No,
662 QMessageBox::No ) == QMessageBox::Yes );
666 isConfirmed = true; // No regions - no zones - nothing to recalculate
672 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
674 HYDROData_WarningType aType = theWarning.Type;
675 if ( aType == WARN_OK ) {
683 case WARN_EMPTY_REGIONS:
684 aTitle = tr( "EMPTY_REGIONS" );
685 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
688 aTitle = tr( "WARNING" );
689 aMsg = theWarning.Data;
693 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
695 QMessageBox::Yes | QMessageBox::No,
698 return ( anAnswer == QMessageBox::Yes );
701 bool HYDROGUI_CalculationOp::confirmLandCoverModeChange() const
703 // Check if the case is already modified or not
704 bool isConfirmed = myEditedObject->IsMustBeUpdated();
707 // If not modified check if the case has already defined regions with zones
708 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
709 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
710 if ( aSeq.Length() > 0 )
712 // If there are already defined zones then ask a user to confirm zones recalculation
713 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
714 tr( "MODE_CHANGED" ),
715 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_MODE" ),
716 QMessageBox::Yes | QMessageBox::No,
717 QMessageBox::No ) == QMessageBox::Yes );
721 isConfirmed = true; // No regions - no zones - nothing to recalculate
727 bool HYDROGUI_CalculationOp::confirmLandCoverOrderChange() const
729 // Check if the case is already modified or not
730 bool isConfirmed = myEditedObject->IsMustBeUpdated();
733 // If not modified check if the case has already defined regions with zones
734 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
735 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
736 if ( aSeq.Length() > 0 )
738 // If there are already defined zones then ask a user to confirm zones recalculation
739 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
740 tr( "ORDER_CHANGED" ),
741 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
742 QMessageBox::Yes | QMessageBox::No,
743 QMessageBox::No ) == QMessageBox::Yes );
747 isConfirmed = true; // No regions - no zones - nothing to recalculate
753 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
754 QString& theErrorMsg,
755 QStringList& theBrowseObjectsEntries )
757 HYDROGUI_CalculationDlg* aPanel =
758 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
764 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
765 theBrowseObjectsEntries.append( anEntry );
768 // For manual mode priority rules are redundant
769 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
770 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
772 if ( aPanel->getLandCoverMode() == HYDROData_CalculationCase::MANUAL ) {
773 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, false );
776 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
781 void HYDROGUI_CalculationOp::onApply()
784 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
785 if ( aWarning.Type != WARN_OK ) {
786 if ( !confirmContinueWithWarning( aWarning ) ) {
787 // Go back to the first page
788 HYDROGUI_CalculationDlg* aPanel =
789 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
791 aPanel->onFirstPage();
797 QApplication::setOverrideCursor( Qt::WaitCursor );
799 int anUpdateFlags = 0;
801 QStringList aBrowseObjectsEntries;
803 bool aResult = false;
807 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
809 catch ( Standard_Failure )
811 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
812 anErrorMsg = aFailure->GetMessageString();
820 QApplication::restoreOverrideCursor();
824 module()->update( anUpdateFlags );
826 browseObjects( aBrowseObjectsEntries );
831 QString aMsg = tr( "INPUT_VALID_DATA" );
832 if( !anErrorMsg.isEmpty() )
833 aMsg.prepend( anErrorMsg + "\n" );
834 SUIT_MessageBox::critical( module()->getApp()->desktop(),
835 tr( "INSUFFICIENT_INPUT_DATA" ),
840 void HYDROGUI_CalculationOp::onNext( const int theIndex )
844 setAvailableGroups();
846 else if( theIndex==2 )
849 HYDROGUI_CalculationDlg* aPanel =
850 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
855 QStringList anEntryList;
856 HYDROData_SequenceOfObjects aSeq;
858 Handle(HYDROData_StricklerTable) aStricklerTableObj;
859 QString aStricklerTableName;
861 // Get all Strickler table objects to fill in combo-box
864 HYDROData_Iterator anIter( doc(), KIND_STRICKLER_TABLE );
865 for ( ; anIter.More(); anIter.Next() )
867 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
869 if ( !aStricklerTableObj.IsNull() )
871 aStricklerTableName = aStricklerTableObj->GetName();
872 if ( !aStricklerTableName.isEmpty() )
874 aList.append( aStricklerTableName );
875 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
879 aPanel->setStricklerTableNames( aList, anEntryList );
880 if ( !aList.isEmpty() )
881 aPanel->setStricklerTable( aList.at( 0 ), false );
883 // Fill in list widget with all available land covers
884 aSeq = HYDROGUI_Tool::GetLandCovers( module() );
885 getNamesAndEntries( aSeq, aList, anEntryList );
886 aPanel->setAllLandCovers( aList, anEntryList );
888 // Set list of included land covers
889 aSeq = myEditedObject->GetLandCovers();
890 getNamesAndEntries( aSeq, aList, anEntryList );
891 aPanel->includeLandCovers( aList, true );
893 if ( !myEditedObject.IsNull() )
897 // Select the certain Strickler table object in combo-box
898 aStricklerTableObj = myEditedObject->GetStricklerTable();
899 if ( aStricklerTableObj.IsNull() )
901 aPanel->setStricklerTable( QString() );
905 aStricklerTableName = aStricklerTableObj->GetName();
906 aPanel->setStricklerTable( aStricklerTableName );
909 // Set mode (Auto or Manual) to defined priority of land covers
910 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
912 // Set rules defined on land covers
913 setRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
917 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getLandCoverMode() );
921 else if( theIndex==3 )
923 HYDROGUI_CalculationDlg* aPanel =
924 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
928 QApplication::setOverrideCursor( Qt::WaitCursor );
930 setGeomObjectsVisible( false );
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();
982 //aPanel->setEditedObject( myEditedObject );
983 aPanel->refreshZonesBrowser();
988 anIsToUpdateOb = true;
990 myEditedObject->SetToUpdate( true );
994 setZonesVisible( true );
996 if ( isNameChanged ) {
997 module()->getDataModel()->updateObjectTree( myEditedObject );
1001 // Move this code to processing od the last panel (see below)
1002 if ( anIsToUpdateOb ) {
1003 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
1004 if ( anObjBrowser ) {
1005 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
1009 QApplication::restoreOverrideCursor();
1011 else if( theIndex==4 )
1013 // Partition of Land covers panel
1014 HYDROGUI_CalculationDlg* aPanel =
1015 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1019 QApplication::setOverrideCursor( Qt::WaitCursor );
1021 // Set parameters for automatic mode
1022 int aMode = aPanel->getLandCoverMode();
1023 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1025 // Set objects in the specified order
1026 if( myEditedObject->IsMustBeUpdated() )
1028 myEditedObject->RemoveLandCovers();
1029 foreach ( const QString& aName, aPanel->getAllLandCovers() )
1031 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast(
1032 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1033 if ( aLandCover.IsNull() )
1037 myEditedObject->AddLandCover( aLandCover );
1040 // Clear priority rules
1041 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true );
1042 // Set priority rules
1043 foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) {
1044 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1045 aRule.Object2, HYDROData_Zone::Merge_Object,
1046 HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
1050 aPanel->setEditLandCoversEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1052 QApplication::restoreOverrideCursor();
1056 void HYDROGUI_CalculationOp::onBack( const int theIndex )
1058 setGeomObjectsVisible( theIndex != 2 );
1059 setZonesVisible( false );
1062 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
1064 myShowZones = theIsVisible;
1065 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1066 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1067 HYDROData_SequenceOfObjects aZones;
1068 Handle(HYDROData_Region) aRegion;
1069 if ( myPreviewViewManager )
1071 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1073 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1074 if ( !aCtx.IsNull() )
1076 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1078 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1079 if ( !aRegion.IsNull() )
1081 aZones = aRegion->GetZones();
1082 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1083 for ( ; aZonesIter.More(); aZonesIter.Next() )
1085 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1091 module()->update( UF_OCCViewer );
1096 void HYDROGUI_CalculationOp::setGeomObjectsVisible( bool theIsVisible )
1098 myShowGeomObjects = theIsVisible;
1100 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
1102 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1103 for ( ; anIter.More(); anIter.Next() ) {
1104 setObjectVisibility( anIter.Value(), theIsVisible );
1108 void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
1110 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1111 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1112 HYDROData_SequenceOfObjects aZones;
1113 Handle(HYDROData_Region) aRegion;
1114 if ( myPreviewViewManager )
1116 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1118 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1119 if ( !aCtx.IsNull() )
1122 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1124 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1125 if ( !aRegion.IsNull() )
1127 aZones = aRegion->GetZones();
1128 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1129 for ( ; aZonesIter.More(); aZonesIter.Next() )
1132 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1133 if ( !aZone.IsNull() )
1135 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
1136 while (aFillingColor == Qt::red)
1137 aFillingColor = GenerateDefaultZonesColor(++aCounter);
1139 aZone->SetColor(aFillingColor);
1149 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
1150 float theSaturation/* = 0.5*/,
1151 float theValue/* = 0.95*/ ) const
1153 float aGoldenRatioConjugate = (float)(360./582.);
1154 float aHue = (float)rand();
1155 aHue += aGoldenRatioConjugate*theIndex;
1156 aHue -= floor(aHue);
1158 float aR = 0., aG = 0., aB = 0.;
1159 int aHueInt = (int)(aHue*6.);
1160 float aF = aHue*6. - aHueInt;
1161 float aP = theValue * (1. - theSaturation);
1162 float aQ = theValue * (1. - aF*theSaturation);
1163 float aT = theValue * (1. - (1. - aF) * theSaturation);
1166 case 0: { aR = theValue; aG = aT; aB = aP; break; }
1167 case 1: { aR = aQ; aG = theValue; aB = aP; break; }
1168 case 2: { aR = aP; aG = theValue; aB = aT; break; }
1169 case 3: { aR = aP; aG = aQ; aB = theValue; break; }
1170 case 4: { aR = aT; aG = aP; aB = theValue; break; }
1171 case 5: { aR = theValue; aG = aP; aB = aQ; break; }
1175 QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
1176 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
1179 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1181 HYDROGUI_CalculationDlg* aPanel =
1182 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1186 HYDROData_ListOfRules aRules;
1187 Handle(HYDROData_Entity) anObject1, anObject2;
1188 HYDROData_PriorityType aPriority;
1189 HYDROData_Zone::MergeAltitudesType aMergeType;
1190 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1191 for ( int anIndex = 0; ; anIndex++ )
1193 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1194 HYDROData_CustomRule aRule;
1195 aRule.Object1 = anObject1;
1196 aRule.Object2 = anObject2;
1197 aRule.Priority = aPriority;
1198 aRule.MergeType = aMergeType;
1206 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1207 aPanel->setRules( aRules );
1208 else if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomLandCoverRules )
1209 aPanel->setLandCoverRules( aRules );
1212 void HYDROGUI_CalculationOp::createPreview()
1214 LightApp_Application* anApp = module()->getApp();
1215 HYDROData_SequenceOfObjects aSeq;
1216 if ( myShowGeomObjects )
1218 HYDROData_SequenceOfObjects aGeomObj = myEditedObject->GetGeometryObjects();
1219 aSeq.Append( aGeomObj );
1221 Handle(HYDROData_Entity) anEntity;
1225 // Gather zones for displaying
1226 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1227 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1228 HYDROData_SequenceOfObjects aZones;
1229 Handle(HYDROData_Region) aRegion;
1230 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1232 anEntity = aRegionsIter.Value();
1233 if ( !anEntity.IsNull() )
1235 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1236 if ( !aRegion.IsNull() )
1238 aZones = aRegion->GetZones();
1239 aSeq.Append( aZones );
1245 // Get a boundary polyline if any
1246 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
1248 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1250 if ( !myActiveViewManager )
1252 if ( aSeq.IsEmpty() )
1255 myActiveViewManager = anApp->activeViewManager();
1258 if ( !myPreviewViewManager )
1260 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1261 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1262 if ( myPreviewViewManager )
1264 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1265 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1267 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1268 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1272 if ( !myPreviewViewManager )
1275 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1277 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1278 if ( !aCtx.IsNull() )
1280 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1281 for ( ; anIter.More(); anIter.Next() )
1283 setObjectVisibility( anIter.Value(), true );
1286 //Process the draw events for viewer
1287 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1288 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
1292 module()->update( UF_OCCViewer | UF_FitAll );
1296 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1298 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1302 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1304 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1308 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1313 void HYDROGUI_CalculationOp::closePreview()
1315 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1316 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1317 QShortcut* aShortcut;
1318 foreach( aShortcut, aShortcuts )
1320 if ( aShortcut->key() ==
1321 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1322 SUIT_DataBrowser::RenameShortcut ) ) )
1324 aShortcut->setEnabled( true );
1329 if( myPreviewViewManager )
1331 // Hide all the displayed objects in the preview view
1332 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1334 size_t aViewId = (size_t)aViewer;
1335 HYDROData_Iterator anIterator( doc() );
1336 for( ; anIterator.More(); anIterator.Next() ) {
1337 Handle(HYDROData_Entity) anObject = anIterator.Current();
1338 if( !anObject.IsNull() ) {
1339 module()->setObjectVisible( aViewId, anObject, false );
1344 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1345 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1347 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1348 myPreviewViewManager = NULL;
1351 if( myActiveViewManager )
1353 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1354 myActiveViewManager = NULL;
1358 void HYDROGUI_CalculationOp::setAvailableGroups()
1360 HYDROGUI_CalculationDlg* aPanel =
1361 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1363 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1364 QStringList aList, anEntryList;
1365 getNamesAndEntries( aSeq, aList, anEntryList );
1367 QStringList aGroupsNames;
1369 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1370 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1372 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1373 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1374 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1376 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1377 aGroupsNames.append( aGroup->GetName() );
1380 if( myEditedObject->IsMustBeUpdated() ) {
1381 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1382 Handle(HYDROData_ShapesGroup) aGeomGroup =
1383 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1384 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1385 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1390 aPanel->setAvailableGroups( aGroupsNames );
1391 aPanel->includeGroups( aList );
1393 bool isUpdated = myEditedObject->IsMustBeUpdated();
1396 void HYDROGUI_CalculationOp::onAddGroups()
1398 HYDROGUI_CalculationDlg* aPanel =
1399 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1403 // Add geometry objects selected in the module browser to the calculation case
1404 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1405 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1408 QStringList anAddedList;
1409 for (int i = 0; i < aSelectedList.length(); i++)
1411 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1412 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1413 if ( aGroup.IsNull() )
1416 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1417 anAddedList.append( aGroup->GetName() );
1420 if ( !anAddedList.isEmpty() )
1422 aPanel->includeGroups( anAddedList );
1426 void HYDROGUI_CalculationOp::onRemoveGroups()
1428 // Remove selected objects from the calculation case
1429 HYDROGUI_CalculationDlg* aPanel =
1430 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1434 QStringList aSelectedList = aPanel->getSelectedGroups();
1435 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1438 for (int i = 0; i < aSelectedList.length(); i++)
1440 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1441 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1442 if ( aGroup.IsNull() )
1445 myEditedObject->RemoveGeometryGroup( aGroup );
1448 aPanel->excludeGroups( aSelectedList );
1451 void HYDROGUI_CalculationOp::onChangeLandCoverMode( int theMode )
1453 HYDROGUI_CalculationDlg* aPanel =
1454 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1458 if ( !confirmLandCoverModeChange() ) {
1459 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
1463 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1464 aPanel->setLandCoverMode( theMode );
1467 void HYDROGUI_CalculationOp::onAddLandCovers()
1469 HYDROGUI_CalculationDlg* aPanel =
1470 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1474 // Add land covers selected in the module browser to the calculation case
1475 QStringList aSelectedList = aPanel->getSelectedAvailableLandCovers();
1476 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1479 QStringList anAddedList;
1480 for (int i = 0; i < aSelectedList.length(); i++)
1482 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1483 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1484 if ( anObject.IsNull() )
1487 if ( myEditedObject->AddLandCover( anObject ) )
1488 anAddedList.append( anObject->GetName() );
1491 if ( !anAddedList.isEmpty() )
1493 aPanel->includeLandCovers( anAddedList, false );
1494 // TODO: create preview of included land covers
1499 void HYDROGUI_CalculationOp::onRemoveLandCovers()
1501 // Remove selected objects from the calculation case
1502 HYDROGUI_CalculationDlg* aPanel =
1503 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1507 QStringList aSelectedList = aPanel->getSelectedLandCovers();
1508 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1511 for (int i = 0; i < aSelectedList.length(); i++)
1513 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1514 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1515 if ( anObject.IsNull() )
1518 setObjectVisibility( anObject, false );
1519 myEditedObject->RemoveLandCover( anObject );
1522 module()->update( UF_OCCViewer );
1523 aPanel->excludeLandCovers( aSelectedList );
1526 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1528 HYDROGUI_CalculationDlg* aPanel =
1529 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1533 if ( !confirmModeChange() ) {
1534 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1538 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1539 aPanel->setMode( theMode );
1542 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1544 HYDROGUI_CalculationDlg* aPanel =
1545 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1549 isConfirmed = confirmOrderChange();
1551 myEditedObject->SetToUpdate( true );
1554 void HYDROGUI_CalculationOp::onOrderLandCoverChanged( bool& isConfirmed )
1556 HYDROGUI_CalculationDlg* aPanel =
1557 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1561 isConfirmed = confirmLandCoverOrderChange();
1563 myEditedObject->SetToUpdate( true );