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( setMergeStricklerType( int, QString& ) ), SLOT( onSetMergeStricklerType( int, QString& ) ) );
227 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>&, bool ) ),
228 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>&, bool ) ) );
229 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
230 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
231 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
232 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
233 connect( aPanel, SIGNAL( objectsSelected() ),
234 SLOT( onObjectsSelected() ) );
235 connect( aPanel, SIGNAL( landCoversSelected() ),
236 SLOT( onLandCoversSelected() ) );
237 connect( aPanel, SIGNAL( createLandCoverRegion( const QList<SUIT_DataObject*>& ) ),
238 SLOT( onCreateLandCoverRegion( const QList<SUIT_DataObject*>& ) ) );
239 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
240 SLOT( onBoundarySelected( const QString & ) ) );
241 connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
242 SLOT( onStricklerTableSelected( const QString & ) ) );
247 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
249 bool anIsToUpdateViewer = false;
251 // Remove the old boundary from the operation viewer
252 Handle(HYDROData_PolylineXY) aPrevPolyline =
253 myEditedObject->GetBoundaryPolyline();
254 if ( !aPrevPolyline.IsNull() )
256 setObjectVisibility( aPrevPolyline, false );
257 anIsToUpdateViewer = true;
260 // Set the selected boundary polyline to the calculation case
261 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
262 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
263 myEditedObject->SetBoundaryPolyline( aNewPolyline );
265 if ( myPreviewViewManager )
267 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
270 if ( !aNewPolyline.IsNull() )
272 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
273 if ( !aCtx.IsNull() )
275 setObjectVisibility( aNewPolyline, true );
276 anIsToUpdateViewer = true;
280 if ( anIsToUpdateViewer )
281 module()->update( UF_OCCViewer );
286 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
288 bool anIsToUpdateViewer = false;
290 // Remove old presentations of land covers from the operation viewer
291 Handle(HYDROData_Entity) anEntity;
292 Handle(HYDROData_LandCover) aLandCover;
293 HYDROData_SequenceOfObjects aLandCovers;
294 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
295 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
296 for ( ; anIter.More(); anIter.Next() )
298 anEntity = anIter.Value();
299 if ( !anEntity.IsNull() )
301 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
302 if ( !aLandCover.IsNull() )
304 aLandCovers.Append( aLandCover );
305 setObjectVisibility( aLandCover, false );
306 anIsToUpdateViewer = true;
311 // Set the selected Strickler table to the calculation case
312 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
313 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
314 myEditedObject->SetStricklerTable( aNewStricklerTable );
316 if ( myPreviewViewManager )
318 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
321 if ( !aNewStricklerTable.IsNull() )
323 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
324 if ( !aCtx.IsNull() )
326 HYDROData_SequenceOfObjects::Iterator anIter( aLandCovers );
327 for ( ; anIter.More(); anIter.Next() )
329 anEntity = anIter.Value();
330 if ( !anEntity.IsNull() )
332 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
333 if ( !aLandCover.IsNull() )
335 setObjectVisibility( aLandCover, true );
336 anIsToUpdateViewer = true;
343 if ( anIsToUpdateViewer )
344 module()->update( UF_OCCViewer );
349 void HYDROGUI_CalculationOp::onObjectsSelected()
351 HYDROGUI_CalculationDlg* aPanel =
352 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
354 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
355 QMap<QString, bool> aSelectedObjsMap;
356 foreach( QString aName, aSelectedObjs )
357 aSelectedObjsMap[aName] = true;
360 // Select the appropriate geometry object shape in the viewer
361 selectionMgr()->clearSelected();
363 // Unhighlight all objects except selected
364 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
365 Handle(HYDROData_Entity) anEntity;
366 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
367 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
370 for ( ; anIter.More(); anIter.Next() )
372 anEntity = anIter.Value();
373 if ( !anEntity.IsNull() )
375 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
378 aName = anEntity->GetName();
379 isSelected = aSelectedObjsMap.contains( aName );
380 aShape->highlight( isSelected, false );
381 aShape->update( false, false );
387 aLastShape->update( true, false );
390 void HYDROGUI_CalculationOp::onLandCoversSelected()
392 HYDROGUI_CalculationDlg* aPanel =
393 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
395 QStringList aSelectedObjs = aPanel->getSelectedLandCovers();
396 QMap<QString, bool> aSelectedObjsMap;
397 foreach( QString aName, aSelectedObjs )
398 aSelectedObjsMap[aName] = true;
401 // Select the appropriate land cover shape in the viewer
402 selectionMgr()->clearSelected();
404 // Unhighlight all land covers except selected
405 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
406 Handle(HYDROData_Entity) anEntity;
407 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
408 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
411 for ( ; anIter.More(); anIter.Next() )
413 anEntity = anIter.Value();
414 if ( !anEntity.IsNull() )
416 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
419 aName = anEntity->GetName();
420 isSelected = aSelectedObjsMap.contains( aName );
421 aShape->highlight( isSelected, false );
422 aShape->update( false, false );
428 aLastShape->update( true, false );
431 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
433 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
434 HYDROGUI_Zone* aZoneItem;
435 selectionMgr()->clearSelected();
438 // Select a region in preview
439 SUIT_DataOwnerPtrList aList( true );
440 DataObjectList aZones = aRegionItem->children();
441 for ( int i = 0; i < aZones.length(); i++ )
443 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
446 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
449 selectionMgr()->setSelected( aList );
453 // select a single zone
454 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
457 SUIT_DataOwnerPtrList aList( true );
458 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
459 selectionMgr()->setSelected( aList );
464 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem,
465 const QList<SUIT_DataObject*>& theZonesList,
468 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
471 QList<HYDROGUI_Zone*> aZonesList;
472 HYDROGUI_Zone* aZone;
473 // Get a list of dropped zones
474 for ( int i = 0; i < theZonesList.length(); i++ )
476 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
479 aZonesList.append( aZone );
482 if ( aZonesList.length() > 0 )
484 aRegion->addZones( aZonesList );
485 HYDROGUI_CalculationDlg* aPanel =
486 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
489 theLandCover ? aPanel->refreshLandCoverZonesBrowser(): aPanel->refreshZonesBrowser();
491 createPreview( theLandCover );
496 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
498 if ( createRegion( theZonesList, false ) )
500 HYDROGUI_CalculationDlg* aPanel =
501 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
504 aPanel->refreshZonesBrowser();
506 createPreview( false );
510 void HYDROGUI_CalculationOp::onCreateLandCoverRegion( const QList<SUIT_DataObject*>& theZonesList )
512 if ( createRegion( theZonesList, true ) )
514 HYDROGUI_CalculationDlg* aPanel =
515 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
518 aPanel->refreshLandCoverZonesBrowser();
520 createPreview( true );
524 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theMergeObjectName )
526 HYDROGUI_CalculationDlg* aPanel =
527 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
530 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
533 aZone->setMergeType( theMergeType, theMergeObjectName );
534 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
537 aShape->update( true, false );
540 aPanel->refreshZonesBrowser();
544 void HYDROGUI_CalculationOp::onSetMergeStricklerType( int theMergeType, QString& theStricklerTypeName )
546 HYDROGUI_CalculationDlg* aPanel =
547 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
550 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
553 aZone->setMergeType( theMergeType, theStricklerTypeName );
554 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
557 aShape->update( true, false );
560 aPanel->refreshLandCoverZonesBrowser();
564 void HYDROGUI_CalculationOp::onAddObjects()
566 HYDROGUI_CalculationDlg* aPanel =
567 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
571 // Add geometry objects selected in the module browser to the calculation case
572 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
573 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
576 QStringList anAddedList;
577 for (int i = 0; i < aSelectedList.length(); i++)
579 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
580 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
581 if ( anObject.IsNull() )
584 if ( myEditedObject->AddGeometryObject( anObject ) )
585 anAddedList.append( anObject->GetName() );
588 if ( !anAddedList.isEmpty() )
590 aPanel->includeGeomObjects( anAddedList );
591 createPreview( false );
595 void HYDROGUI_CalculationOp::onRemoveObjects()
597 // Remove selected objects from the calculation case
598 HYDROGUI_CalculationDlg* aPanel =
599 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
603 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
604 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
607 for (int i = 0; i < aSelectedList.length(); i++)
609 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
610 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
611 if ( anObject.IsNull() )
614 setObjectVisibility( anObject, false );
615 myEditedObject->RemoveGeometryObject( anObject );
618 module()->update( UF_OCCViewer );
619 aPanel->excludeGeomObjects( aSelectedList );
622 bool HYDROGUI_CalculationOp::confirmRegionsChange() 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( false );
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( "REGIONS_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::confirmOrderChange() 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( false );
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( "ORDER_CHANGED" ),
660 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
661 QMessageBox::Yes | QMessageBox::No,
662 QMessageBox::No ) == QMessageBox::Yes );
666 isConfirmed = true; // No regions - no zones - nothing to recalculate
672 bool HYDROGUI_CalculationOp::confirmModeChange() const
674 // Check if the case is already modified or not
675 bool isConfirmed = myEditedObject->IsMustBeUpdated();
678 // If not modified check if the case has already defined regions with zones
679 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
680 if ( aSeq.Length() > 0 )
682 // If there are already defined zones then ask a user to confirm zones recalculation
683 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
684 tr( "MODE_CHANGED" ),
685 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
686 QMessageBox::Yes | QMessageBox::No,
687 QMessageBox::No ) == QMessageBox::Yes );
691 isConfirmed = true; // No regions - no zones - nothing to recalculate
697 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
699 HYDROData_WarningType aType = theWarning.Type;
700 if ( aType == WARN_OK ) {
708 case WARN_EMPTY_REGIONS:
709 aTitle = tr( "EMPTY_REGIONS" );
710 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
713 aTitle = tr( "WARNING" );
714 aMsg = theWarning.Data;
718 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
720 QMessageBox::Yes | QMessageBox::No,
723 return ( anAnswer == QMessageBox::Yes );
726 bool HYDROGUI_CalculationOp::confirmLandCoverModeChange() const
728 // Check if the case is already modified or not
729 bool isConfirmed = myEditedObject->IsMustBeUpdated();
732 // If not modified check if the case has already defined regions with zones
733 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
734 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
735 if ( aSeq.Length() > 0 )
737 // If there are already defined zones then ask a user to confirm zones recalculation
738 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
739 tr( "MODE_CHANGED" ),
740 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_MODE" ),
741 QMessageBox::Yes | QMessageBox::No,
742 QMessageBox::No ) == QMessageBox::Yes );
746 isConfirmed = true; // No regions - no zones - nothing to recalculate
752 bool HYDROGUI_CalculationOp::confirmLandCoverOrderChange() const
754 // Check if the case is already modified or not
755 bool isConfirmed = myEditedObject->IsMustBeUpdated();
758 // If not modified check if the case has already defined regions with zones
759 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
760 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
761 if ( aSeq.Length() > 0 )
763 // If there are already defined zones then ask a user to confirm zones recalculation
764 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
765 tr( "ORDER_CHANGED" ),
766 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
767 QMessageBox::Yes | QMessageBox::No,
768 QMessageBox::No ) == QMessageBox::Yes );
772 isConfirmed = true; // No regions - no zones - nothing to recalculate
778 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
779 QString& theErrorMsg,
780 QStringList& theBrowseObjectsEntries )
782 HYDROGUI_CalculationDlg* aPanel =
783 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
789 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
790 theBrowseObjectsEntries.append( anEntry );
793 // For manual mode priority rules are redundant
794 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
795 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
797 if ( aPanel->getLandCoverMode() == HYDROData_CalculationCase::MANUAL ) {
798 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, false );
801 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
806 void HYDROGUI_CalculationOp::onApply()
809 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
810 if ( aWarning.Type != WARN_OK ) {
811 if ( !confirmContinueWithWarning( aWarning ) ) {
812 // Go back to the first page
813 HYDROGUI_CalculationDlg* aPanel =
814 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
816 aPanel->onFirstPage();
822 QApplication::setOverrideCursor( Qt::WaitCursor );
824 int anUpdateFlags = 0;
826 QStringList aBrowseObjectsEntries;
828 bool aResult = false;
832 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
834 catch ( Standard_Failure )
836 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
837 anErrorMsg = aFailure->GetMessageString();
845 QApplication::restoreOverrideCursor();
849 module()->update( anUpdateFlags );
851 browseObjects( aBrowseObjectsEntries );
856 QString aMsg = tr( "INPUT_VALID_DATA" );
857 if( !anErrorMsg.isEmpty() )
858 aMsg.prepend( anErrorMsg + "\n" );
859 SUIT_MessageBox::critical( module()->getApp()->desktop(),
860 tr( "INSUFFICIENT_INPUT_DATA" ),
865 void HYDROGUI_CalculationOp::onNext( const int theIndex )
869 setAvailableGroups();
871 else if( theIndex==2 )
874 HYDROGUI_CalculationDlg* aPanel =
875 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
880 QStringList anEntryList;
881 HYDROData_SequenceOfObjects aSeq;
883 Handle(HYDROData_StricklerTable) aStricklerTableObj;
884 QString aStricklerTableName;
886 // Get all Strickler table objects to fill in combo-box
889 HYDROData_Iterator anIter( doc(), KIND_STRICKLER_TABLE );
890 for ( ; anIter.More(); anIter.Next() )
892 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
894 if ( !aStricklerTableObj.IsNull() )
896 aStricklerTableName = aStricklerTableObj->GetName();
897 if ( !aStricklerTableName.isEmpty() )
899 aList.append( aStricklerTableName );
900 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
904 aPanel->setStricklerTableNames( aList, anEntryList );
905 if ( !aList.isEmpty() )
906 aPanel->setStricklerTable( aList.at( 0 ), false );
908 // Fill in list widget with all available land covers
909 aSeq = HYDROGUI_Tool::GetLandCovers( module() );
910 getNamesAndEntries( aSeq, aList, anEntryList );
911 aPanel->setAllLandCovers( aList, anEntryList );
913 // Set list of included land covers
914 aSeq = myEditedObject->GetLandCovers();
915 getNamesAndEntries( aSeq, aList, anEntryList );
916 aPanel->includeLandCovers( aList, true );
918 if ( !myEditedObject.IsNull() )
922 // Select the certain Strickler table object in combo-box
923 aStricklerTableObj = myEditedObject->GetStricklerTable();
924 if ( aStricklerTableObj.IsNull() )
926 aPanel->setStricklerTable( QString() );
930 aStricklerTableName = aStricklerTableObj->GetName();
931 aPanel->setStricklerTable( aStricklerTableName );
934 // Set mode (Auto or Manual) to defined priority of land covers
935 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
937 // Set rules defined on land covers
938 setRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
942 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getLandCoverMode() );
946 closePreview( false );
947 createPreview( true );
949 else if( theIndex==3 )
951 HYDROGUI_CalculationDlg* aPanel =
952 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
956 QApplication::setOverrideCursor( Qt::WaitCursor );
958 QString aNewCaseName = aPanel->getObjectName();
959 QString anOldCaseName = myEditedObject->GetName();
960 bool isNameChanged = anOldCaseName != aNewCaseName;
962 bool anIsToUpdateOb = isNameChanged;
964 // At first we must to update the case name because of
965 // automatic names generation for regions and zones
966 myEditedObject->SetName( aNewCaseName );
968 // Set parameters for automatic mode
969 int aMode = aPanel->getMode();
970 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
972 // Set objects in the specified order
973 if( myEditedObject->IsMustBeUpdated() )
975 myEditedObject->RemoveGeometryObjects();
976 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
978 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
979 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
980 if ( anObject.IsNull() )
984 myEditedObject->AddGeometryObject( anObject );
987 // Clear priority rules
988 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
989 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
991 // Set priority rules
992 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
993 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
994 aRule.Object2, aRule.MergeType,
995 HYDROData_CalculationCase::DataTag_CustomRules );
999 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1001 if ( myEditedObject->IsMustBeUpdated() )
1004 myEditedObject->Update();
1006 AssignDefaultZonesColors( false );
1008 //aPanel->setEditedObject( myEditedObject );
1009 aPanel->refreshZonesBrowser();
1011 closePreview( false );
1012 createPreview( false );
1014 anIsToUpdateOb = true;
1016 myEditedObject->SetToUpdate( true );
1021 setZonesVisible( true, false );
1023 if ( isNameChanged ) {
1024 module()->getDataModel()->updateObjectTree( myEditedObject );
1028 QApplication::restoreOverrideCursor();
1030 else if( theIndex==4 )
1032 // Partition of Land covers panel
1033 HYDROGUI_CalculationDlg* aPanel =
1034 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1038 QApplication::setOverrideCursor( Qt::WaitCursor );
1040 // Set parameters for automatic mode
1041 int aMode = aPanel->getLandCoverMode();
1042 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1044 // Set objects in the specified order
1045 if( myEditedObject->IsMustBeUpdated() )
1047 myEditedObject->RemoveLandCovers();
1048 foreach ( const QString& aName, aPanel->getAllLandCovers() )
1050 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast(
1051 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1052 if ( aLandCover.IsNull() )
1056 myEditedObject->AddLandCover( aLandCover );
1059 // Clear priority rules
1060 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true );
1061 // Set priority rules
1062 foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) {
1063 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1064 aRule.Object2, HYDROData_Zone::Merge_Object,
1065 HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
1069 aPanel->setEditLandCoverZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1071 bool anIsToUpdateOb = false;
1072 bool anIsToUpdate = myEditedObject->IsMustBeUpdated();
1076 myEditedObject->Update();
1078 AssignDefaultZonesColors( true );
1080 aPanel->refreshLandCoverZonesBrowser();
1082 anIsToUpdateOb = true;
1085 closePreview( false );
1086 createPreview( true );
1088 if ( !anIsToUpdate )
1091 setZonesVisible( false, false );
1092 // Show land cover zones
1093 setZonesVisible( true, true );
1096 if ( anIsToUpdateOb ) {
1097 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
1098 if ( anObjBrowser ) {
1099 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
1103 QApplication::restoreOverrideCursor();
1107 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
1111 closePreview( false );
1112 createPreview( false );
1116 closePreview( false );
1117 createPreview( true );
1120 setZonesVisible( false, false );
1122 setZonesVisible( false, true );
1124 else if( theIndex==3 )
1126 AssignDefaultZonesColors( false );
1128 closePreview( false );
1129 createPreview( false );
1131 // Hide land cover zones
1132 setZonesVisible( false, true );
1134 setZonesVisible( true, false );
1138 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible, const bool theLandCover )
1140 myShowZones = theIsVisible;
1141 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1142 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1143 HYDROData_SequenceOfObjects aZones;
1144 Handle(HYDROData_Region) aRegion;
1145 if ( myPreviewViewManager )
1147 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1149 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1150 if ( !aCtx.IsNull() )
1152 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1154 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1155 if ( !aRegion.IsNull() )
1157 aZones = aRegion->GetZones();
1158 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1159 for ( ; aZonesIter.More(); aZonesIter.Next() )
1161 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1167 module()->update( UF_OCCViewer );
1172 void HYDROGUI_CalculationOp::AssignDefaultZonesColors( const bool theLandCover )
1174 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1175 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1176 HYDROData_SequenceOfObjects aZones;
1177 Handle(HYDROData_Region) aRegion;
1178 if ( myPreviewViewManager )
1180 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1182 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1183 if ( !aCtx.IsNull() )
1186 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1188 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1189 if ( !aRegion.IsNull() )
1191 aZones = aRegion->GetZones();
1192 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1193 for ( ; aZonesIter.More(); aZonesIter.Next() )
1196 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1197 if ( !aZone.IsNull() )
1199 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
1200 while (aFillingColor == Qt::red)
1201 aFillingColor = GenerateDefaultZonesColor(++aCounter);
1203 aZone->SetColor(aFillingColor);
1213 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
1214 float theSaturation/* = 0.5*/,
1215 float theValue/* = 0.95*/ ) const
1217 float aGoldenRatioConjugate = (float)(360./582.);
1218 float aHue = (float)rand();
1219 aHue += aGoldenRatioConjugate*theIndex;
1220 aHue -= floor(aHue);
1222 float aR = 0., aG = 0., aB = 0.;
1223 int aHueInt = (int)(aHue*6.);
1224 float aF = aHue*6. - aHueInt;
1225 float aP = theValue * (1. - theSaturation);
1226 float aQ = theValue * (1. - aF*theSaturation);
1227 float aT = theValue * (1. - (1. - aF) * theSaturation);
1230 case 0: { aR = theValue; aG = aT; aB = aP; break; }
1231 case 1: { aR = aQ; aG = theValue; aB = aP; break; }
1232 case 2: { aR = aP; aG = theValue; aB = aT; break; }
1233 case 3: { aR = aP; aG = aQ; aB = theValue; break; }
1234 case 4: { aR = aT; aG = aP; aB = theValue; break; }
1235 case 5: { aR = theValue; aG = aP; aB = aQ; break; }
1239 QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
1240 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
1243 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1245 HYDROGUI_CalculationDlg* aPanel =
1246 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1250 HYDROData_ListOfRules aRules;
1251 Handle(HYDROData_Entity) anObject1, anObject2;
1252 HYDROData_PriorityType aPriority;
1253 HYDROData_Zone::MergeType aMergeType;
1254 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1255 for ( int anIndex = 0; ; anIndex++ )
1257 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1258 HYDROData_CustomRule aRule;
1259 aRule.Object1 = anObject1;
1260 aRule.Object2 = anObject2;
1261 aRule.Priority = aPriority;
1262 aRule.MergeType = aMergeType;
1270 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1271 aPanel->setRules( aRules );
1272 else if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomLandCoverRules )
1273 aPanel->setLandCoverRules( aRules );
1276 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList,
1277 const bool theLandCover )
1279 bool aRetValue = false;
1281 QList<HYDROGUI_Zone*> aZonesList;
1282 HYDROGUI_Zone* aZone;
1283 // Get a list of dropped zones
1284 for ( int i = 0; i < theZonesList.length(); i++ )
1286 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1289 aZonesList.append( aZone );
1292 if ( aZonesList.length() > 0 )
1294 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList, theLandCover );
1301 void HYDROGUI_CalculationOp::createPreview( const bool theLandCover )
1303 LightApp_Application* anApp = module()->getApp();
1304 HYDROData_SequenceOfObjects aSeq;
1306 aSeq = myEditedObject->GetLandCovers();
1308 aSeq = myEditedObject->GetGeometryObjects();
1309 Handle(HYDROData_Entity) anEntity;
1313 // Gather zones for displaying
1314 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1315 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1316 HYDROData_SequenceOfObjects aZones;
1317 Handle(HYDROData_Region) aRegion;
1318 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1320 anEntity = aRegionsIter.Value();
1321 if ( !anEntity.IsNull() )
1323 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1324 if ( !aRegion.IsNull() )
1326 aZones = aRegion->GetZones();
1327 aSeq.Append( aZones );
1333 // Get a boundary polyline if any
1334 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
1336 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1338 if ( !myActiveViewManager )
1340 if ( aSeq.IsEmpty() )
1343 myActiveViewManager = anApp->activeViewManager();
1346 if ( !myPreviewViewManager )
1348 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1349 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1350 if ( myPreviewViewManager )
1352 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1353 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1355 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1356 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1360 if ( !myPreviewViewManager )
1363 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1365 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1366 if ( !aCtx.IsNull() )
1368 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1369 for ( ; anIter.More(); anIter.Next() )
1371 setObjectVisibility( anIter.Value(), true );
1374 //Process the draw events for viewer
1375 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1376 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
1380 module()->update( UF_OCCViewer | UF_FitAll );
1384 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1386 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1390 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1392 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1396 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1401 void HYDROGUI_CalculationOp::closePreview( bool theRemoveViewManager )
1403 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1404 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1405 QShortcut* aShortcut;
1406 foreach( aShortcut, aShortcuts )
1408 if ( aShortcut->key() ==
1409 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1410 SUIT_DataBrowser::RenameShortcut ) ) )
1412 aShortcut->setEnabled( true );
1417 if( myPreviewViewManager )
1419 // Hide all the displayed objects in the preview view
1420 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1422 size_t aViewId = (size_t)aViewer;
1423 HYDROData_Iterator anIterator( doc() );
1424 for( ; anIterator.More(); anIterator.Next() ) {
1425 Handle(HYDROData_Entity) anObject = anIterator.Current();
1426 if( !anObject.IsNull() ) {
1427 module()->setObjectVisible( aViewId, anObject, false );
1432 if ( theRemoveViewManager )
1434 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1435 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1437 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1438 myPreviewViewManager = NULL;
1442 if( myActiveViewManager && theRemoveViewManager )
1444 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1445 myActiveViewManager = NULL;
1449 void HYDROGUI_CalculationOp::setAvailableGroups()
1451 HYDROGUI_CalculationDlg* aPanel =
1452 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1454 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1455 QStringList aList, anEntryList;
1456 getNamesAndEntries( aSeq, aList, anEntryList );
1458 QStringList aGroupsNames;
1460 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1461 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1463 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1464 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1465 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1467 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1468 aGroupsNames.append( aGroup->GetName() );
1471 if( myEditedObject->IsMustBeUpdated() ) {
1472 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1473 Handle(HYDROData_ShapesGroup) aGeomGroup =
1474 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1475 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1476 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1481 aPanel->setAvailableGroups( aGroupsNames );
1482 aPanel->includeGroups( aList );
1484 bool isUpdated = myEditedObject->IsMustBeUpdated();
1487 void HYDROGUI_CalculationOp::onAddGroups()
1489 HYDROGUI_CalculationDlg* aPanel =
1490 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1494 // Add geometry objects selected in the module browser to the calculation case
1495 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1496 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1499 QStringList anAddedList;
1500 for (int i = 0; i < aSelectedList.length(); i++)
1502 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1503 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1504 if ( aGroup.IsNull() )
1507 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1508 anAddedList.append( aGroup->GetName() );
1511 if ( !anAddedList.isEmpty() )
1513 aPanel->includeGroups( anAddedList );
1517 void HYDROGUI_CalculationOp::onRemoveGroups()
1519 // Remove selected objects from the calculation case
1520 HYDROGUI_CalculationDlg* aPanel =
1521 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1525 QStringList aSelectedList = aPanel->getSelectedGroups();
1526 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1529 for (int i = 0; i < aSelectedList.length(); i++)
1531 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1532 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1533 if ( aGroup.IsNull() )
1536 myEditedObject->RemoveGeometryGroup( aGroup );
1539 aPanel->excludeGroups( aSelectedList );
1542 void HYDROGUI_CalculationOp::onChangeLandCoverMode( int theMode )
1544 HYDROGUI_CalculationDlg* aPanel =
1545 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1549 if ( !confirmLandCoverModeChange() ) {
1550 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
1554 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1555 aPanel->setLandCoverMode( theMode );
1558 void HYDROGUI_CalculationOp::onAddLandCovers()
1560 HYDROGUI_CalculationDlg* aPanel =
1561 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1565 // Add land covers selected in the module browser to the calculation case
1566 QStringList aSelectedList = aPanel->getSelectedAvailableLandCovers();
1567 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1570 QStringList anAddedList;
1571 for (int i = 0; i < aSelectedList.length(); i++)
1573 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1574 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1575 if ( anObject.IsNull() )
1578 if ( myEditedObject->AddLandCover( anObject ) )
1579 anAddedList.append( anObject->GetName() );
1582 if ( !anAddedList.isEmpty() )
1584 aPanel->includeLandCovers( anAddedList, false );
1585 createPreview( true );
1589 void HYDROGUI_CalculationOp::onRemoveLandCovers()
1591 // Remove selected objects from the calculation case
1592 HYDROGUI_CalculationDlg* aPanel =
1593 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1597 QStringList aSelectedList = aPanel->getSelectedLandCovers();
1598 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1601 for (int i = 0; i < aSelectedList.length(); i++)
1603 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1604 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1605 if ( anObject.IsNull() )
1608 setObjectVisibility( anObject, false );
1609 myEditedObject->RemoveLandCover( anObject );
1612 module()->update( UF_OCCViewer );
1613 aPanel->excludeLandCovers( aSelectedList );
1616 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1618 HYDROGUI_CalculationDlg* aPanel =
1619 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1623 if ( !confirmModeChange() ) {
1624 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1628 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1629 aPanel->setMode( theMode );
1632 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1634 HYDROGUI_CalculationDlg* aPanel =
1635 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1639 isConfirmed = confirmOrderChange();
1641 myEditedObject->SetToUpdate( true );
1644 void HYDROGUI_CalculationOp::onOrderLandCoverChanged( bool& isConfirmed )
1646 HYDROGUI_CalculationDlg* aPanel =
1647 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1651 isConfirmed = confirmLandCoverOrderChange();
1653 myEditedObject->SetToUpdate( true );