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 );
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() ) );
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( boundarySelected( const QString & ) ),
237 SLOT( onBoundarySelected( const QString & ) ) );
238 connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
239 SLOT( onStricklerTableSelected( const QString & ) ) );
244 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
246 bool anIsToUpdateViewer = false;
248 // Remove the old boundary from the operation viewer
249 Handle(HYDROData_PolylineXY) aPrevPolyline =
250 myEditedObject->GetBoundaryPolyline();
251 if ( !aPrevPolyline.IsNull() )
253 setObjectVisibility( aPrevPolyline, false );
254 anIsToUpdateViewer = true;
257 // Set the selected boundary polyline to the calculation case
258 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
259 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
260 myEditedObject->SetBoundaryPolyline( aNewPolyline );
262 if ( myPreviewViewManager )
264 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
267 if ( !aNewPolyline.IsNull() )
269 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
270 if ( !aCtx.IsNull() )
272 setObjectVisibility( aNewPolyline, true );
273 anIsToUpdateViewer = true;
277 if ( anIsToUpdateViewer )
278 module()->update( UF_OCCViewer );
283 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
285 bool anIsToUpdateViewer = false;
287 // Remove old presentations of land covers from the operation viewer
288 Handle(HYDROData_Entity) anEntity;
289 Handle(HYDROData_LandCover) aLandCover;
290 HYDROData_SequenceOfObjects aLandCovers;
291 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
292 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
293 for ( ; anIter.More(); anIter.Next() )
295 anEntity = anIter.Value();
296 if ( !anEntity.IsNull() )
298 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
299 if ( !aLandCover.IsNull() )
301 aLandCovers.Append( aLandCover );
302 setObjectVisibility( aLandCover, false );
303 anIsToUpdateViewer = true;
308 // Set the selected Strickler table to the calculation case
309 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
310 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
311 myEditedObject->SetStricklerTable( aNewStricklerTable );
313 if ( myPreviewViewManager )
315 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
318 if ( !aNewStricklerTable.IsNull() )
320 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
321 if ( !aCtx.IsNull() )
323 HYDROData_SequenceOfObjects::Iterator anIter( aLandCovers );
324 for ( ; anIter.More(); anIter.Next() )
326 anEntity = anIter.Value();
327 if ( !anEntity.IsNull() )
329 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
330 if ( !aLandCover.IsNull() )
332 setObjectVisibility( aLandCover, true );
333 anIsToUpdateViewer = true;
340 if ( anIsToUpdateViewer )
341 module()->update( UF_OCCViewer );
346 void HYDROGUI_CalculationOp::onObjectsSelected()
348 HYDROGUI_CalculationDlg* aPanel =
349 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
351 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
352 QMap<QString, bool> aSelectedObjsMap;
353 foreach( QString aName, aSelectedObjs )
354 aSelectedObjsMap[aName] = true;
357 // Select the appropriate geometry object shape in the viewer
358 selectionMgr()->clearSelected();
360 // Unhighlight all objects except selected
361 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
362 Handle(HYDROData_Entity) anEntity;
363 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
364 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
367 for ( ; anIter.More(); anIter.Next() )
369 anEntity = anIter.Value();
370 if ( !anEntity.IsNull() )
372 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
375 aName = anEntity->GetName();
376 isSelected = aSelectedObjsMap.contains( aName );
377 aShape->highlight( isSelected, false );
378 aShape->update( false, false );
384 aLastShape->update( true, false );
387 void HYDROGUI_CalculationOp::onLandCoversSelected()
389 HYDROGUI_CalculationDlg* aPanel =
390 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
392 QStringList aSelectedObjs = aPanel->getSelectedLandCovers();
393 QMap<QString, bool> aSelectedObjsMap;
394 foreach( QString aName, aSelectedObjs )
395 aSelectedObjsMap[aName] = true;
398 // Select the appropriate land cover shape in the viewer
399 selectionMgr()->clearSelected();
401 // Unhighlight all land covers except selected
402 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
403 Handle(HYDROData_Entity) anEntity;
404 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
405 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
408 for ( ; anIter.More(); anIter.Next() )
410 anEntity = anIter.Value();
411 if ( !anEntity.IsNull() )
413 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
416 aName = anEntity->GetName();
417 isSelected = aSelectedObjsMap.contains( aName );
418 aShape->highlight( isSelected, false );
419 aShape->update( false, false );
425 aLastShape->update( true, false );
428 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
430 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
431 HYDROGUI_Zone* aZoneItem;
432 selectionMgr()->clearSelected();
435 // Select a region in preview
436 SUIT_DataOwnerPtrList aList( true );
437 DataObjectList aZones = aRegionItem->children();
438 for ( int i = 0; i < aZones.length(); i++ )
440 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
443 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
446 selectionMgr()->setSelected( aList );
450 // select a single zone
451 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
454 SUIT_DataOwnerPtrList aList( true );
455 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
456 selectionMgr()->setSelected( aList );
461 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
463 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
466 QList<HYDROGUI_Zone*> aZonesList;
467 HYDROGUI_Zone* aZone;
468 // Get a list of dropped zones
469 for ( int i = 0; i < theZonesList.length(); i++ )
471 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
474 aZonesList.append( aZone );
477 if ( aZonesList.length() > 0 )
479 aRegion->addZones( aZonesList );
480 HYDROGUI_CalculationDlg* aPanel =
481 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
484 aPanel->refreshZonesBrowser();
491 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
493 QList<HYDROGUI_Zone*> aZonesList;
494 HYDROGUI_Zone* aZone;
495 // Get a list of dropped zones
496 for ( int i = 0; i < theZonesList.length(); i++ )
498 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
501 aZonesList.append( aZone );
504 if ( aZonesList.length() > 0 )
506 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
507 HYDROGUI_CalculationDlg* aPanel =
508 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
511 aPanel->refreshZonesBrowser();
517 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theAltitudeName )
519 HYDROGUI_CalculationDlg* aPanel =
520 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
523 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
526 aZone->setMergeType( theMergeType, theAltitudeName );
527 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
530 aShape->update( true, false );
533 aPanel->refreshZonesBrowser();
537 void HYDROGUI_CalculationOp::onAddObjects()
539 HYDROGUI_CalculationDlg* aPanel =
540 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
544 // Add geometry objects selected in the module browser to the calculation case
545 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
546 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
549 QStringList anAddedList;
550 for (int i = 0; i < aSelectedList.length(); i++)
552 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
553 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
554 if ( anObject.IsNull() )
557 if ( myEditedObject->AddGeometryObject( anObject ) )
558 anAddedList.append( anObject->GetName() );
561 if ( !anAddedList.isEmpty() )
563 aPanel->includeGeomObjects( anAddedList );
568 void HYDROGUI_CalculationOp::onRemoveObjects()
570 // Remove selected objects from the calculation case
571 HYDROGUI_CalculationDlg* aPanel =
572 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
576 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
577 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
580 for (int i = 0; i < aSelectedList.length(); i++)
582 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
583 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
584 if ( anObject.IsNull() )
587 setObjectVisibility( anObject, false );
588 myEditedObject->RemoveGeometryObject( anObject );
591 module()->update( UF_OCCViewer );
592 aPanel->excludeGeomObjects( aSelectedList );
595 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
597 // Check if the case is already modified or not
598 bool isConfirmed = myEditedObject->IsMustBeUpdated();
601 // If not modified check if the case has already defined regions with zones
602 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
603 if ( aSeq.Length() > 0 )
605 // If there are already defined zones then ask a user to confirm zones recalculation
606 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
607 tr( "REGIONS_CHANGED" ),
608 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
609 QMessageBox::Yes | QMessageBox::No,
610 QMessageBox::No ) == QMessageBox::Yes );
614 isConfirmed = true; // No regions - no zones - nothing to recalculate
620 bool HYDROGUI_CalculationOp::confirmOrderChange() const
622 // Check if the case is already modified or not
623 bool isConfirmed = myEditedObject->IsMustBeUpdated();
626 // If not modified check if the case has already defined regions with zones
627 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
628 if ( aSeq.Length() > 0 )
630 // If there are already defined zones then ask a user to confirm zones recalculation
631 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
632 tr( "ORDER_CHANGED" ),
633 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
634 QMessageBox::Yes | QMessageBox::No,
635 QMessageBox::No ) == QMessageBox::Yes );
639 isConfirmed = true; // No regions - no zones - nothing to recalculate
645 bool HYDROGUI_CalculationOp::confirmModeChange() const
647 // Check if the case is already modified or not
648 bool isConfirmed = myEditedObject->IsMustBeUpdated();
651 // If not modified check if the case has already defined regions with zones
652 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
653 if ( aSeq.Length() > 0 )
655 // If there are already defined zones then ask a user to confirm zones recalculation
656 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
657 tr( "MODE_CHANGED" ),
658 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
659 QMessageBox::Yes | QMessageBox::No,
660 QMessageBox::No ) == QMessageBox::Yes );
664 isConfirmed = true; // No regions - no zones - nothing to recalculate
670 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
672 HYDROData_WarningType aType = theWarning.Type;
673 if ( aType == WARN_OK ) {
681 case WARN_EMPTY_REGIONS:
682 aTitle = tr( "EMPTY_REGIONS" );
683 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
686 aTitle = tr( "WARNING" );
687 aMsg = theWarning.Data;
691 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
693 QMessageBox::Yes | QMessageBox::No,
696 return ( anAnswer == QMessageBox::Yes );
699 bool HYDROGUI_CalculationOp::confirmLandCoverModeChange() const
701 // Check if the case is already modified or not
702 bool isConfirmed = myEditedObject->IsMustBeUpdated();
705 // If not modified check if the case has already defined regions with zones
706 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
707 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
708 if ( aSeq.Length() > 0 )
710 // If there are already defined zones then ask a user to confirm zones recalculation
711 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
712 tr( "MODE_CHANGED" ),
713 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_MODE" ),
714 QMessageBox::Yes | QMessageBox::No,
715 QMessageBox::No ) == QMessageBox::Yes );
719 isConfirmed = true; // No regions - no zones - nothing to recalculate
725 bool HYDROGUI_CalculationOp::confirmLandCoverOrderChange() const
727 // Check if the case is already modified or not
728 bool isConfirmed = myEditedObject->IsMustBeUpdated();
731 // If not modified check if the case has already defined regions with zones
732 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
733 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
734 if ( aSeq.Length() > 0 )
736 // If there are already defined zones then ask a user to confirm zones recalculation
737 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
738 tr( "ORDER_CHANGED" ),
739 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
740 QMessageBox::Yes | QMessageBox::No,
741 QMessageBox::No ) == QMessageBox::Yes );
745 isConfirmed = true; // No regions - no zones - nothing to recalculate
751 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
752 QString& theErrorMsg,
753 QStringList& theBrowseObjectsEntries )
755 HYDROGUI_CalculationDlg* aPanel =
756 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
762 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
763 theBrowseObjectsEntries.append( anEntry );
766 // For manual mode priority rules are redundant
767 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
768 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
770 if ( aPanel->getLandCoverMode() == HYDROData_CalculationCase::MANUAL ) {
771 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, false );
774 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
779 void HYDROGUI_CalculationOp::onApply()
782 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
783 if ( aWarning.Type != WARN_OK ) {
784 if ( !confirmContinueWithWarning( aWarning ) ) {
785 // Go back to the first page
786 HYDROGUI_CalculationDlg* aPanel =
787 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
789 aPanel->onFirstPage();
795 QApplication::setOverrideCursor( Qt::WaitCursor );
797 int anUpdateFlags = 0;
799 QStringList aBrowseObjectsEntries;
801 bool aResult = false;
805 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
807 catch ( Standard_Failure )
809 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
810 anErrorMsg = aFailure->GetMessageString();
818 QApplication::restoreOverrideCursor();
822 module()->update( anUpdateFlags );
824 browseObjects( aBrowseObjectsEntries );
829 QString aMsg = tr( "INPUT_VALID_DATA" );
830 if( !anErrorMsg.isEmpty() )
831 aMsg.prepend( anErrorMsg + "\n" );
832 SUIT_MessageBox::critical( module()->getApp()->desktop(),
833 tr( "INSUFFICIENT_INPUT_DATA" ),
838 void HYDROGUI_CalculationOp::onNext( const int theIndex )
842 setAvailableGroups();
844 else if( theIndex==2 )
847 HYDROGUI_CalculationDlg* aPanel =
848 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
853 QStringList anEntryList;
854 HYDROData_SequenceOfObjects aSeq;
856 Handle(HYDROData_StricklerTable) aStricklerTableObj;
857 QString aStricklerTableName;
859 // Get all Strickler table objects to fill in combo-box
862 HYDROData_Iterator anIter( doc(), KIND_STRICKLER_TABLE );
863 for ( ; anIter.More(); anIter.Next() )
865 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
867 if ( !aStricklerTableObj.IsNull() )
869 aStricklerTableName = aStricklerTableObj->GetName();
870 if ( !aStricklerTableName.isEmpty() )
872 aList.append( aStricklerTableName );
873 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
877 aPanel->setStricklerTableNames( aList, anEntryList );
878 if ( !aList.isEmpty() )
879 aPanel->setStricklerTable( aList.at( 0 ), false );
881 // Fill in list widget with all available land covers
882 aSeq = HYDROGUI_Tool::GetLandCovers( module() );
883 getNamesAndEntries( aSeq, aList, anEntryList );
884 aPanel->setAllLandCovers( aList, anEntryList );
886 // Set list of included land covers
887 aSeq = myEditedObject->GetLandCovers();
888 getNamesAndEntries( aSeq, aList, anEntryList );
889 aPanel->includeLandCovers( aList, true );
891 if ( !myEditedObject.IsNull() )
895 // Select the certain Strickler table object in combo-box
896 aStricklerTableObj = myEditedObject->GetStricklerTable();
897 if ( aStricklerTableObj.IsNull() )
899 aPanel->setStricklerTable( QString() );
903 aStricklerTableName = aStricklerTableObj->GetName();
904 aPanel->setStricklerTable( aStricklerTableName );
907 // Set mode (Auto or Manual) to defined priority of land covers
908 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
910 // Set rules defined on land covers
911 setRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
915 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getLandCoverMode() );
919 else if( theIndex==3 )
921 HYDROGUI_CalculationDlg* aPanel =
922 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
926 QApplication::setOverrideCursor( Qt::WaitCursor );
928 QString aNewCaseName = aPanel->getObjectName();
929 QString anOldCaseName = myEditedObject->GetName();
930 bool isNameChanged = anOldCaseName != aNewCaseName;
932 bool anIsToUpdateOb = isNameChanged;
934 // At first we must to update the case name because of
935 // automatic names generation for regions and zones
936 myEditedObject->SetName( aNewCaseName );
938 // Set parameters for automatic mode
939 int aMode = aPanel->getMode();
940 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
942 // Set objects in the specified order
943 if( myEditedObject->IsMustBeUpdated() )
945 myEditedObject->RemoveGeometryObjects();
946 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
948 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
949 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
950 if ( anObject.IsNull() )
954 myEditedObject->AddGeometryObject( anObject );
957 // Clear priority rules
958 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
959 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
961 // Set priority rules
962 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
963 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
964 aRule.Object2, aRule.MergeType,
965 HYDROData_CalculationCase::DataTag_CustomRules );
969 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
971 if ( myEditedObject->IsMustBeUpdated() )
974 myEditedObject->Update();
976 AssignDefaultZonesColors();
978 //aPanel->setEditedObject( myEditedObject );
979 aPanel->refreshZonesBrowser();
984 anIsToUpdateOb = true;
986 myEditedObject->SetToUpdate( true );
990 setZonesVisible( true );
992 if ( isNameChanged ) {
993 module()->getDataModel()->updateObjectTree( myEditedObject );
997 // Move this code to processing od the last panel (see below)
998 if ( anIsToUpdateOb ) {
999 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
1000 if ( anObjBrowser ) {
1001 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
1005 QApplication::restoreOverrideCursor();
1007 else if( theIndex==4 )
1009 // Partition of Land covers panel
1010 HYDROGUI_CalculationDlg* aPanel =
1011 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1015 QApplication::setOverrideCursor( Qt::WaitCursor );
1017 // Set parameters for automatic mode
1018 int aMode = aPanel->getLandCoverMode();
1019 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1021 // Set objects in the specified order
1022 if( myEditedObject->IsMustBeUpdated() )
1024 myEditedObject->RemoveLandCovers();
1025 foreach ( const QString& aName, aPanel->getAllLandCovers() )
1027 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast(
1028 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1029 if ( aLandCover.IsNull() )
1033 myEditedObject->AddLandCover( aLandCover );
1036 // Clear priority rules
1037 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true );
1038 // Set priority rules
1039 foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) {
1040 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1041 aRule.Object2, HYDROData_Zone::Merge_Object,
1042 HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
1046 aPanel->setEditLandCoversEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1048 QApplication::restoreOverrideCursor();
1052 void HYDROGUI_CalculationOp::onHideZones()
1054 setZonesVisible( false );
1057 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
1059 myShowZones = theIsVisible;
1060 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1061 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1062 HYDROData_SequenceOfObjects aZones;
1063 Handle(HYDROData_Region) aRegion;
1064 if ( myPreviewViewManager )
1066 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1068 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1069 if ( !aCtx.IsNull() )
1071 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1073 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1074 if ( !aRegion.IsNull() )
1076 aZones = aRegion->GetZones();
1077 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1078 for ( ; aZonesIter.More(); aZonesIter.Next() )
1080 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1086 module()->update( UF_OCCViewer );
1091 void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
1093 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1094 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1095 HYDROData_SequenceOfObjects aZones;
1096 Handle(HYDROData_Region) aRegion;
1097 if ( myPreviewViewManager )
1099 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1101 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1102 if ( !aCtx.IsNull() )
1105 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1107 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1108 if ( !aRegion.IsNull() )
1110 aZones = aRegion->GetZones();
1111 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1112 for ( ; aZonesIter.More(); aZonesIter.Next() )
1115 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1116 if ( !aZone.IsNull() )
1118 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
1119 while (aFillingColor == Qt::red)
1120 aFillingColor = GenerateDefaultZonesColor(++aCounter);
1122 aZone->SetColor(aFillingColor);
1132 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
1133 float theSaturation/* = 0.5*/,
1134 float theValue/* = 0.95*/ ) const
1136 float aGoldenRatioConjugate = (float)(360./582.);
1137 float aHue = (float)rand();
1138 aHue += aGoldenRatioConjugate*theIndex;
1139 aHue -= floor(aHue);
1141 float aR = 0., aG = 0., aB = 0.;
1142 int aHueInt = (int)(aHue*6.);
1143 float aF = aHue*6. - aHueInt;
1144 float aP = theValue * (1. - theSaturation);
1145 float aQ = theValue * (1. - aF*theSaturation);
1146 float aT = theValue * (1. - (1. - aF) * theSaturation);
1149 case 0: { aR = theValue; aG = aT; aB = aP; break; }
1150 case 1: { aR = aQ; aG = theValue; aB = aP; break; }
1151 case 2: { aR = aP; aG = theValue; aB = aT; break; }
1152 case 3: { aR = aP; aG = aQ; aB = theValue; break; }
1153 case 4: { aR = aT; aG = aP; aB = theValue; break; }
1154 case 5: { aR = theValue; aG = aP; aB = aQ; break; }
1158 QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
1159 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
1162 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1164 HYDROGUI_CalculationDlg* aPanel =
1165 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1169 HYDROData_ListOfRules aRules;
1170 Handle(HYDROData_Entity) anObject1, anObject2;
1171 HYDROData_PriorityType aPriority;
1172 HYDROData_Zone::MergeAltitudesType aMergeType;
1173 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1174 for ( int anIndex = 0; ; anIndex++ )
1176 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1177 HYDROData_CustomRule aRule;
1178 aRule.Object1 = anObject1;
1179 aRule.Object2 = anObject2;
1180 aRule.Priority = aPriority;
1181 aRule.MergeType = aMergeType;
1189 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1190 aPanel->setRules( aRules );
1191 else if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomLandCoverRules )
1192 aPanel->setLandCoverRules( aRules );
1195 void HYDROGUI_CalculationOp::createPreview()
1197 LightApp_Application* anApp = module()->getApp();
1198 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
1199 Handle(HYDROData_Entity) anEntity;
1203 // Gather zones for displaying
1204 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1205 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1206 HYDROData_SequenceOfObjects aZones;
1207 Handle(HYDROData_Region) aRegion;
1208 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1210 anEntity = aRegionsIter.Value();
1211 if ( !anEntity.IsNull() )
1213 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1214 if ( !aRegion.IsNull() )
1216 aZones = aRegion->GetZones();
1217 aSeq.Append( aZones );
1223 // Get a boundary polyline if any
1224 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
1226 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1228 if ( !myActiveViewManager )
1230 if ( aSeq.IsEmpty() )
1233 myActiveViewManager = anApp->activeViewManager();
1236 if ( !myPreviewViewManager )
1238 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1239 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1240 if ( myPreviewViewManager )
1242 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1243 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1245 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1246 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1250 if ( !myPreviewViewManager )
1253 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1255 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1256 if ( !aCtx.IsNull() )
1258 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1259 for ( ; anIter.More(); anIter.Next() )
1261 setObjectVisibility( anIter.Value(), true );
1264 //Process the draw events for viewer
1265 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1266 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
1270 module()->update( UF_OCCViewer | UF_FitAll );
1274 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1276 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1280 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1282 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1286 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1291 void HYDROGUI_CalculationOp::closePreview()
1293 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1294 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1295 QShortcut* aShortcut;
1296 foreach( aShortcut, aShortcuts )
1298 if ( aShortcut->key() ==
1299 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1300 SUIT_DataBrowser::RenameShortcut ) ) )
1302 aShortcut->setEnabled( true );
1307 if( myPreviewViewManager )
1309 // Hide all the displayed objects in the preview view
1310 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1312 size_t aViewId = (size_t)aViewer;
1313 HYDROData_Iterator anIterator( doc() );
1314 for( ; anIterator.More(); anIterator.Next() ) {
1315 Handle(HYDROData_Entity) anObject = anIterator.Current();
1316 if( !anObject.IsNull() ) {
1317 module()->setObjectVisible( aViewId, anObject, false );
1322 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1323 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1325 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1326 myPreviewViewManager = NULL;
1329 if( myActiveViewManager )
1331 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1332 myActiveViewManager = NULL;
1336 void HYDROGUI_CalculationOp::setAvailableGroups()
1338 HYDROGUI_CalculationDlg* aPanel =
1339 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1341 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1342 QStringList aList, anEntryList;
1343 getNamesAndEntries( aSeq, aList, anEntryList );
1345 QStringList aGroupsNames;
1347 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1348 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1350 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1351 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1352 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1354 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1355 aGroupsNames.append( aGroup->GetName() );
1358 if( myEditedObject->IsMustBeUpdated() ) {
1359 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1360 Handle(HYDROData_ShapesGroup) aGeomGroup =
1361 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1362 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1363 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1368 aPanel->setAvailableGroups( aGroupsNames );
1369 aPanel->includeGroups( aList );
1371 bool isUpdated = myEditedObject->IsMustBeUpdated();
1374 void HYDROGUI_CalculationOp::onAddGroups()
1376 HYDROGUI_CalculationDlg* aPanel =
1377 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1381 // Add geometry objects selected in the module browser to the calculation case
1382 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1383 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1386 QStringList anAddedList;
1387 for (int i = 0; i < aSelectedList.length(); i++)
1389 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1390 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1391 if ( aGroup.IsNull() )
1394 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1395 anAddedList.append( aGroup->GetName() );
1398 if ( !anAddedList.isEmpty() )
1400 aPanel->includeGroups( anAddedList );
1404 void HYDROGUI_CalculationOp::onRemoveGroups()
1406 // Remove selected objects from the calculation case
1407 HYDROGUI_CalculationDlg* aPanel =
1408 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1412 QStringList aSelectedList = aPanel->getSelectedGroups();
1413 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1416 for (int i = 0; i < aSelectedList.length(); i++)
1418 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1419 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1420 if ( aGroup.IsNull() )
1423 myEditedObject->RemoveGeometryGroup( aGroup );
1426 aPanel->excludeGroups( aSelectedList );
1429 void HYDROGUI_CalculationOp::onChangeLandCoverMode( int theMode )
1431 HYDROGUI_CalculationDlg* aPanel =
1432 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1436 if ( !confirmLandCoverModeChange() ) {
1437 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
1441 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1442 aPanel->setLandCoverMode( theMode );
1445 void HYDROGUI_CalculationOp::onAddLandCovers()
1447 HYDROGUI_CalculationDlg* aPanel =
1448 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1452 // Add land covers selected in the module browser to the calculation case
1453 QStringList aSelectedList = aPanel->getSelectedAvailableLandCovers();
1454 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1457 QStringList anAddedList;
1458 for (int i = 0; i < aSelectedList.length(); i++)
1460 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1461 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1462 if ( anObject.IsNull() )
1465 if ( myEditedObject->AddLandCover( anObject ) )
1466 anAddedList.append( anObject->GetName() );
1469 if ( !anAddedList.isEmpty() )
1471 aPanel->includeLandCovers( anAddedList, false );
1472 // TODO: create preview of included land covers
1477 void HYDROGUI_CalculationOp::onRemoveLandCovers()
1479 // Remove selected objects from the calculation case
1480 HYDROGUI_CalculationDlg* aPanel =
1481 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1485 QStringList aSelectedList = aPanel->getSelectedLandCovers();
1486 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1489 for (int i = 0; i < aSelectedList.length(); i++)
1491 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1492 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1493 if ( anObject.IsNull() )
1496 setObjectVisibility( anObject, false );
1497 myEditedObject->RemoveLandCover( anObject );
1500 module()->update( UF_OCCViewer );
1501 aPanel->excludeLandCovers( aSelectedList );
1504 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1506 HYDROGUI_CalculationDlg* aPanel =
1507 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1511 if ( !confirmModeChange() ) {
1512 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1516 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1517 aPanel->setMode( theMode );
1520 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1522 HYDROGUI_CalculationDlg* aPanel =
1523 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1527 isConfirmed = confirmOrderChange();
1529 myEditedObject->SetToUpdate( true );
1532 void HYDROGUI_CalculationOp::onOrderLandCoverChanged( bool& isConfirmed )
1534 HYDROGUI_CalculationDlg* aPanel =
1535 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1539 isConfirmed = confirmLandCoverOrderChange();
1541 myEditedObject->SetToUpdate( true );