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 else if( theIndex==3 )
948 HYDROGUI_CalculationDlg* aPanel =
949 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
953 QApplication::setOverrideCursor( Qt::WaitCursor );
955 QString aNewCaseName = aPanel->getObjectName();
956 QString anOldCaseName = myEditedObject->GetName();
957 bool isNameChanged = anOldCaseName != aNewCaseName;
959 bool anIsToUpdateOb = isNameChanged;
961 // At first we must to update the case name because of
962 // automatic names generation for regions and zones
963 myEditedObject->SetName( aNewCaseName );
965 // Set parameters for automatic mode
966 int aMode = aPanel->getMode();
967 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
969 // Set objects in the specified order
970 if( myEditedObject->IsMustBeUpdated() )
972 myEditedObject->RemoveGeometryObjects();
973 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
975 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
976 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
977 if ( anObject.IsNull() )
981 myEditedObject->AddGeometryObject( anObject );
984 // Clear priority rules
985 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
986 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
988 // Set priority rules
989 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
990 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
991 aRule.Object2, aRule.MergeType,
992 HYDROData_CalculationCase::DataTag_CustomRules );
996 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
998 if ( myEditedObject->IsMustBeUpdated() )
1001 myEditedObject->Update();
1003 AssignDefaultZonesColors( false );
1005 //aPanel->setEditedObject( myEditedObject );
1006 aPanel->refreshZonesBrowser();
1009 createPreview( false );
1011 anIsToUpdateOb = true;
1013 myEditedObject->SetToUpdate( true );
1018 setZonesVisible( true, false );
1020 if ( isNameChanged ) {
1021 module()->getDataModel()->updateObjectTree( myEditedObject );
1025 QApplication::restoreOverrideCursor();
1027 else if( theIndex==4 )
1029 // Partition of Land covers panel
1030 HYDROGUI_CalculationDlg* aPanel =
1031 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1035 QApplication::setOverrideCursor( Qt::WaitCursor );
1037 // Set parameters for automatic mode
1038 int aMode = aPanel->getLandCoverMode();
1039 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1041 // Set objects in the specified order
1042 if( myEditedObject->IsMustBeUpdated() )
1044 myEditedObject->RemoveLandCovers();
1045 foreach ( const QString& aName, aPanel->getAllLandCovers() )
1047 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast(
1048 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1049 if ( aLandCover.IsNull() )
1053 myEditedObject->AddLandCover( aLandCover );
1056 // Clear priority rules
1057 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true );
1058 // Set priority rules
1059 foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) {
1060 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1061 aRule.Object2, HYDROData_Zone::Merge_Object,
1062 HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
1066 aPanel->setEditLandCoverZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1068 bool anIsToUpdateOb = false;
1069 if ( myEditedObject->IsMustBeUpdated() )
1072 myEditedObject->Update();
1074 AssignDefaultZonesColors( true );
1076 aPanel->refreshLandCoverZonesBrowser();
1079 createPreview( true );
1081 anIsToUpdateOb = true;
1083 myEditedObject->SetToUpdate( true );
1088 setZonesVisible( false, false );
1089 // Show land cover zones
1090 setZonesVisible( true, true );
1093 if ( anIsToUpdateOb ) {
1094 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
1095 if ( anObjBrowser ) {
1096 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
1100 QApplication::restoreOverrideCursor();
1104 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
1109 setZonesVisible( false, false );
1111 else if( theIndex==4 )
1113 // Hide land cover zones
1114 setZonesVisible( false, true );
1118 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible, const bool theLandCover )
1120 myShowZones = theIsVisible;
1121 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1122 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1123 HYDROData_SequenceOfObjects aZones;
1124 Handle(HYDROData_Region) aRegion;
1125 if ( myPreviewViewManager )
1127 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1129 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1130 if ( !aCtx.IsNull() )
1132 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1134 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1135 if ( !aRegion.IsNull() )
1137 aZones = aRegion->GetZones();
1138 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1139 for ( ; aZonesIter.More(); aZonesIter.Next() )
1141 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1147 module()->update( UF_OCCViewer );
1152 void HYDROGUI_CalculationOp::AssignDefaultZonesColors( const bool theLandCover )
1154 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1155 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1156 HYDROData_SequenceOfObjects aZones;
1157 Handle(HYDROData_Region) aRegion;
1158 if ( myPreviewViewManager )
1160 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1162 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1163 if ( !aCtx.IsNull() )
1166 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1168 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1169 if ( !aRegion.IsNull() )
1171 aZones = aRegion->GetZones();
1172 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1173 for ( ; aZonesIter.More(); aZonesIter.Next() )
1176 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1177 if ( !aZone.IsNull() )
1179 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
1180 while (aFillingColor == Qt::red)
1181 aFillingColor = GenerateDefaultZonesColor(++aCounter);
1183 aZone->SetColor(aFillingColor);
1193 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
1194 float theSaturation/* = 0.5*/,
1195 float theValue/* = 0.95*/ ) const
1197 float aGoldenRatioConjugate = (float)(360./582.);
1198 float aHue = (float)rand();
1199 aHue += aGoldenRatioConjugate*theIndex;
1200 aHue -= floor(aHue);
1202 float aR = 0., aG = 0., aB = 0.;
1203 int aHueInt = (int)(aHue*6.);
1204 float aF = aHue*6. - aHueInt;
1205 float aP = theValue * (1. - theSaturation);
1206 float aQ = theValue * (1. - aF*theSaturation);
1207 float aT = theValue * (1. - (1. - aF) * theSaturation);
1210 case 0: { aR = theValue; aG = aT; aB = aP; break; }
1211 case 1: { aR = aQ; aG = theValue; aB = aP; break; }
1212 case 2: { aR = aP; aG = theValue; aB = aT; break; }
1213 case 3: { aR = aP; aG = aQ; aB = theValue; break; }
1214 case 4: { aR = aT; aG = aP; aB = theValue; break; }
1215 case 5: { aR = theValue; aG = aP; aB = aQ; break; }
1219 QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
1220 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
1223 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1225 HYDROGUI_CalculationDlg* aPanel =
1226 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1230 HYDROData_ListOfRules aRules;
1231 Handle(HYDROData_Entity) anObject1, anObject2;
1232 HYDROData_PriorityType aPriority;
1233 HYDROData_Zone::MergeType aMergeType;
1234 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1235 for ( int anIndex = 0; ; anIndex++ )
1237 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1238 HYDROData_CustomRule aRule;
1239 aRule.Object1 = anObject1;
1240 aRule.Object2 = anObject2;
1241 aRule.Priority = aPriority;
1242 aRule.MergeType = aMergeType;
1250 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1251 aPanel->setRules( aRules );
1252 else if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomLandCoverRules )
1253 aPanel->setLandCoverRules( aRules );
1256 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList,
1257 const bool theLandCover )
1259 bool aRetValue = false;
1261 QList<HYDROGUI_Zone*> aZonesList;
1262 HYDROGUI_Zone* aZone;
1263 // Get a list of dropped zones
1264 for ( int i = 0; i < theZonesList.length(); i++ )
1266 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1269 aZonesList.append( aZone );
1272 if ( aZonesList.length() > 0 )
1274 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList, theLandCover );
1281 void HYDROGUI_CalculationOp::createPreview( const bool theLandCover )
1283 LightApp_Application* anApp = module()->getApp();
1284 HYDROData_SequenceOfObjects aSeq;
1286 aSeq = myEditedObject->GetLandCovers();
1288 aSeq = myEditedObject->GetGeometryObjects();
1289 Handle(HYDROData_Entity) anEntity;
1293 // Gather zones for displaying
1294 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1295 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1296 HYDROData_SequenceOfObjects aZones;
1297 Handle(HYDROData_Region) aRegion;
1298 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1300 anEntity = aRegionsIter.Value();
1301 if ( !anEntity.IsNull() )
1303 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1304 if ( !aRegion.IsNull() )
1306 aZones = aRegion->GetZones();
1307 aSeq.Append( aZones );
1313 // Get a boundary polyline if any
1314 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
1316 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1318 if ( !myActiveViewManager )
1320 if ( aSeq.IsEmpty() )
1323 myActiveViewManager = anApp->activeViewManager();
1326 if ( !myPreviewViewManager )
1328 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1329 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1330 if ( myPreviewViewManager )
1332 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1333 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1335 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1336 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1340 if ( !myPreviewViewManager )
1343 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1345 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1346 if ( !aCtx.IsNull() )
1348 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1349 for ( ; anIter.More(); anIter.Next() )
1351 setObjectVisibility( anIter.Value(), true );
1354 //Process the draw events for viewer
1355 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1356 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
1360 module()->update( UF_OCCViewer | UF_FitAll );
1364 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1366 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1370 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1372 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1376 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1381 void HYDROGUI_CalculationOp::closePreview()
1383 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1384 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1385 QShortcut* aShortcut;
1386 foreach( aShortcut, aShortcuts )
1388 if ( aShortcut->key() ==
1389 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1390 SUIT_DataBrowser::RenameShortcut ) ) )
1392 aShortcut->setEnabled( true );
1397 if( myPreviewViewManager )
1399 // Hide all the displayed objects in the preview view
1400 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1402 size_t aViewId = (size_t)aViewer;
1403 HYDROData_Iterator anIterator( doc() );
1404 for( ; anIterator.More(); anIterator.Next() ) {
1405 Handle(HYDROData_Entity) anObject = anIterator.Current();
1406 if( !anObject.IsNull() ) {
1407 module()->setObjectVisible( aViewId, anObject, false );
1412 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1413 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1415 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1416 myPreviewViewManager = NULL;
1419 if( myActiveViewManager )
1421 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1422 myActiveViewManager = NULL;
1426 void HYDROGUI_CalculationOp::setAvailableGroups()
1428 HYDROGUI_CalculationDlg* aPanel =
1429 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1431 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1432 QStringList aList, anEntryList;
1433 getNamesAndEntries( aSeq, aList, anEntryList );
1435 QStringList aGroupsNames;
1437 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1438 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1440 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1441 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1442 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1444 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1445 aGroupsNames.append( aGroup->GetName() );
1448 if( myEditedObject->IsMustBeUpdated() ) {
1449 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1450 Handle(HYDROData_ShapesGroup) aGeomGroup =
1451 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1452 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1453 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1458 aPanel->setAvailableGroups( aGroupsNames );
1459 aPanel->includeGroups( aList );
1461 bool isUpdated = myEditedObject->IsMustBeUpdated();
1464 void HYDROGUI_CalculationOp::onAddGroups()
1466 HYDROGUI_CalculationDlg* aPanel =
1467 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1471 // Add geometry objects selected in the module browser to the calculation case
1472 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1473 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1476 QStringList anAddedList;
1477 for (int i = 0; i < aSelectedList.length(); i++)
1479 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1480 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1481 if ( aGroup.IsNull() )
1484 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1485 anAddedList.append( aGroup->GetName() );
1488 if ( !anAddedList.isEmpty() )
1490 aPanel->includeGroups( anAddedList );
1494 void HYDROGUI_CalculationOp::onRemoveGroups()
1496 // Remove selected objects from the calculation case
1497 HYDROGUI_CalculationDlg* aPanel =
1498 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1502 QStringList aSelectedList = aPanel->getSelectedGroups();
1503 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1506 for (int i = 0; i < aSelectedList.length(); i++)
1508 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1509 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1510 if ( aGroup.IsNull() )
1513 myEditedObject->RemoveGeometryGroup( aGroup );
1516 aPanel->excludeGroups( aSelectedList );
1519 void HYDROGUI_CalculationOp::onChangeLandCoverMode( int theMode )
1521 HYDROGUI_CalculationDlg* aPanel =
1522 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1526 if ( !confirmLandCoverModeChange() ) {
1527 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
1531 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1532 aPanel->setLandCoverMode( theMode );
1535 void HYDROGUI_CalculationOp::onAddLandCovers()
1537 HYDROGUI_CalculationDlg* aPanel =
1538 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1542 // Add land covers selected in the module browser to the calculation case
1543 QStringList aSelectedList = aPanel->getSelectedAvailableLandCovers();
1544 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1547 QStringList anAddedList;
1548 for (int i = 0; i < aSelectedList.length(); i++)
1550 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1551 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1552 if ( anObject.IsNull() )
1555 if ( myEditedObject->AddLandCover( anObject ) )
1556 anAddedList.append( anObject->GetName() );
1559 if ( !anAddedList.isEmpty() )
1561 aPanel->includeLandCovers( anAddedList, false );
1562 createPreview( true );
1566 void HYDROGUI_CalculationOp::onRemoveLandCovers()
1568 // Remove selected objects from the calculation case
1569 HYDROGUI_CalculationDlg* aPanel =
1570 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1574 QStringList aSelectedList = aPanel->getSelectedLandCovers();
1575 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1578 for (int i = 0; i < aSelectedList.length(); i++)
1580 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1581 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1582 if ( anObject.IsNull() )
1585 setObjectVisibility( anObject, false );
1586 myEditedObject->RemoveLandCover( anObject );
1589 module()->update( UF_OCCViewer );
1590 aPanel->excludeLandCovers( aSelectedList );
1593 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1595 HYDROGUI_CalculationDlg* aPanel =
1596 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1600 if ( !confirmModeChange() ) {
1601 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1605 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1606 aPanel->setMode( theMode );
1609 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1611 HYDROGUI_CalculationDlg* aPanel =
1612 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1616 isConfirmed = confirmOrderChange();
1618 myEditedObject->SetToUpdate( true );
1621 void HYDROGUI_CalculationOp::onOrderLandCoverChanged( bool& isConfirmed )
1623 HYDROGUI_CalculationDlg* aPanel =
1624 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1628 isConfirmed = confirmLandCoverOrderChange();
1630 myEditedObject->SetToUpdate( true );