1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_CalculationOp.h"
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_CalculationDlg.h"
23 #include "HYDROGUI_Module.h"
24 #include "HYDROGUI_Tool.h"
25 #include "HYDROGUI_UpdateFlags.h"
26 #include "HYDROGUI_Zone.h"
27 #include "HYDROGUI_Region.h"
29 #include <HYDROData_PolylineXY.h>
30 #include <HYDROData_ShapesGroup.h>
31 #include <HYDROData_Iterator.h>
32 #include <HYDROData_ImmersibleZone.h>
33 #include <HYDROData_Object.h>
34 #include <HYDROData_Tool.h>
35 #include <HYDROData_StricklerTable.h>
37 #include <OCCViewer_ViewManager.h>
38 #include <OCCViewer_ViewModel.h>
39 #include <OCCViewer_ViewWindow.h>
41 #include <LightApp_Application.h>
42 #include <LightApp_UpdateFlags.h>
43 #include <LightApp_SelectionMgr.h>
44 #include <LightApp_DataOwner.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_DataBrowser.h>
50 #include <QApplication>
51 #include <QKeySequence>
54 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
55 : HYDROGUI_Operation( theModule ),
56 myIsEdit( theIsEdit ),
57 myActiveViewManager( NULL ),
58 myPreviewViewManager( NULL ),
59 myShowGeomObjects( true ),
62 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
65 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
70 void HYDROGUI_CalculationOp::startOperation()
72 HYDROGUI_Operation::startOperation();
77 HYDROGUI_CalculationDlg* aPanel =
78 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
82 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
83 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
85 foreach( aShortcut, aShortcuts )
87 if ( aShortcut->key() ==
88 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
89 SUIT_DataBrowser::RenameShortcut ) ) )
91 aShortcut->setEnabled( false );
97 QStringList anEntryList;
98 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
99 getNamesAndEntries( aSeq, aList, anEntryList );
100 aPanel->setAllGeomObjects( aList, anEntryList );
105 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
106 Handle(HYDROData_PolylineXY) aPolylineObj;
107 QString aPolylineName;
108 for ( ; anIter.More(); anIter.Next() )
110 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
112 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
114 // Check the polyline shape
115 TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
116 if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
117 aPolylineName = aPolylineObj->GetName();
118 if ( !aPolylineName.isEmpty() )
120 aList.append( aPolylineName );
121 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
126 aPanel->setPolylineNames( aList, anEntryList );
128 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
130 myEditedObject.Nullify();
133 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
134 if ( !myEditedObject.IsNull() )
136 aPanel->setMode( myEditedObject->GetAssignmentMode() );
137 anObjectName = myEditedObject->GetName();
138 aPolylineObj = myEditedObject->GetBoundaryPolyline();
139 if ( aPolylineObj.IsNull() )
141 aPanel->setBoundary( QString() );
145 aPolylineName = aPolylineObj->GetName();
146 aPanel->setBoundary( aPolylineName );
149 aSeq = myEditedObject->GetGeometryObjects();
150 getNamesAndEntries( aSeq, aList, anEntryList );
151 aPanel->includeGeomObjects( aList );
154 setRules( HYDROData_CalculationCase::DataTag_CustomRules );
160 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
161 myEditedObject->SetName( anObjectName );
162 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
165 aPanel->setObjectName( anObjectName );
166 aPanel->setEditedObject( myEditedObject );
168 createPreview( false );
171 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
172 QStringList& theNames, QStringList& theEntries ) const
177 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
178 for ( ; anIter.More(); anIter.Next() )
180 Handle(HYDROData_Entity) anEntity = anIter.Value();
181 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
184 theNames.append( anEntity->GetName() );
185 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
189 void HYDROGUI_CalculationOp::abortOperation()
194 HYDROGUI_Operation::abortOperation();
195 module()->getApp()->updateObjectBrowser();
198 void HYDROGUI_CalculationOp::commitOperation()
201 // Commit transaction
202 commitDocOperation();
203 HYDROGUI_Operation::commitOperation();
206 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
208 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
210 // Connect signals and slots
211 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
212 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
213 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
214 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
215 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
217 connect( aPanel, SIGNAL( changeLandCoverMode( int ) ), SLOT( onChangeLandCoverMode( int ) ) );
218 connect( aPanel, SIGNAL( addLandCovers() ), SLOT( onAddLandCovers() ) );
219 connect( aPanel, SIGNAL( removeLandCovers() ), SLOT( onRemoveLandCovers() ) );
221 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
222 connect( aPanel, SIGNAL( orderLandCoverChanged( bool& ) ), SLOT( onOrderLandCoverChanged( bool& ) ) );
224 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
225 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones( const int ) ) );
226 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
227 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
228 connect( aPanel, SIGNAL( setMergeStricklerType( int, QString& ) ), SLOT( onSetMergeStricklerType( int, QString& ) ) );
229 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>&, bool ) ),
230 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>&, bool ) ) );
231 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
232 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
233 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
234 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
235 connect( aPanel, SIGNAL( objectsSelected() ),
236 SLOT( onObjectsSelected() ) );
237 connect( aPanel, SIGNAL( landCoversSelected() ),
238 SLOT( onLandCoversSelected() ) );
239 connect( aPanel, SIGNAL( createLandCoverRegion( const QList<SUIT_DataObject*>& ) ),
240 SLOT( onCreateLandCoverRegion( const QList<SUIT_DataObject*>& ) ) );
241 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
242 SLOT( onBoundarySelected( const QString & ) ) );
243 connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
244 SLOT( onStricklerTableSelected( const QString & ) ) );
249 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
251 bool anIsToUpdateViewer = false;
253 // Remove the old boundary from the operation viewer
254 Handle(HYDROData_PolylineXY) aPrevPolyline =
255 myEditedObject->GetBoundaryPolyline();
256 if ( !aPrevPolyline.IsNull() )
258 setObjectVisibility( aPrevPolyline, false );
259 anIsToUpdateViewer = true;
262 // Set the selected boundary polyline to the calculation case
263 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
264 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
265 myEditedObject->SetBoundaryPolyline( aNewPolyline );
267 if ( myPreviewViewManager )
269 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
272 if ( !aNewPolyline.IsNull() )
274 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
275 if ( !aCtx.IsNull() )
277 setObjectVisibility( aNewPolyline, true );
278 anIsToUpdateViewer = true;
282 if ( anIsToUpdateViewer )
283 module()->update( UF_OCCViewer );
288 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
290 bool anIsToUpdateViewer = false;
292 // Remove old presentations of land covers from the operation viewer
293 Handle(HYDROData_Entity) anEntity;
294 Handle(HYDROData_LandCover) aLandCover;
295 HYDROData_SequenceOfObjects aLandCovers;
296 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
297 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
298 for ( ; anIter.More(); anIter.Next() )
300 anEntity = anIter.Value();
301 if ( !anEntity.IsNull() )
303 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
304 if ( !aLandCover.IsNull() )
306 aLandCovers.Append( aLandCover );
307 setObjectVisibility( aLandCover, false );
308 anIsToUpdateViewer = true;
313 // Set the selected Strickler table to the calculation case
314 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
315 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
316 myEditedObject->SetStricklerTable( aNewStricklerTable );
318 if ( myPreviewViewManager )
320 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
323 if ( !aNewStricklerTable.IsNull() )
325 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
326 if ( !aCtx.IsNull() )
328 HYDROData_SequenceOfObjects::Iterator anIter( aLandCovers );
329 for ( ; anIter.More(); anIter.Next() )
331 anEntity = anIter.Value();
332 if ( !anEntity.IsNull() )
334 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
335 if ( !aLandCover.IsNull() )
337 setObjectVisibility( aLandCover, true );
338 anIsToUpdateViewer = true;
345 if ( anIsToUpdateViewer )
346 module()->update( UF_OCCViewer );
351 void HYDROGUI_CalculationOp::onObjectsSelected()
353 HYDROGUI_CalculationDlg* aPanel =
354 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
356 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
357 QMap<QString, bool> aSelectedObjsMap;
358 foreach( QString aName, aSelectedObjs )
359 aSelectedObjsMap[aName] = true;
362 // Select the appropriate geometry object shape in the viewer
363 selectionMgr()->clearSelected();
365 // Unhighlight all objects except selected
366 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
367 Handle(HYDROData_Entity) anEntity;
368 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
369 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
372 for ( ; anIter.More(); anIter.Next() )
374 anEntity = anIter.Value();
375 if ( !anEntity.IsNull() )
377 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
380 aName = anEntity->GetName();
381 isSelected = aSelectedObjsMap.contains( aName );
382 aShape->highlight( isSelected, false );
383 aShape->update( false, false );
389 aLastShape->update( true, false );
392 void HYDROGUI_CalculationOp::onLandCoversSelected()
394 HYDROGUI_CalculationDlg* aPanel =
395 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
397 QStringList aSelectedObjs = aPanel->getSelectedLandCovers();
398 QMap<QString, bool> aSelectedObjsMap;
399 foreach( QString aName, aSelectedObjs )
400 aSelectedObjsMap[aName] = true;
403 // Select the appropriate land cover shape in the viewer
404 selectionMgr()->clearSelected();
406 // Unhighlight all land covers except selected
407 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
408 Handle(HYDROData_Entity) anEntity;
409 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
410 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
413 for ( ; anIter.More(); anIter.Next() )
415 anEntity = anIter.Value();
416 if ( !anEntity.IsNull() )
418 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
421 aName = anEntity->GetName();
422 isSelected = aSelectedObjsMap.contains( aName );
423 aShape->highlight( isSelected, false );
424 aShape->update( false, false );
430 aLastShape->update( true, false );
433 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
435 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
436 HYDROGUI_Zone* aZoneItem;
437 selectionMgr()->clearSelected();
440 // Select a region in preview
441 SUIT_DataOwnerPtrList aList( true );
442 DataObjectList aZones = aRegionItem->children();
443 for ( int i = 0; i < aZones.length(); i++ )
445 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
448 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
451 selectionMgr()->setSelected( aList );
455 // select a single zone
456 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
459 SUIT_DataOwnerPtrList aList( true );
460 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
461 selectionMgr()->setSelected( aList );
466 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem,
467 const QList<SUIT_DataObject*>& theZonesList,
470 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
473 QList<HYDROGUI_Zone*> aZonesList;
474 HYDROGUI_Zone* aZone;
475 // Get a list of dropped zones
476 for ( int i = 0; i < theZonesList.length(); i++ )
478 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
481 aZonesList.append( aZone );
484 if ( aZonesList.length() > 0 )
486 aRegion->addZones( aZonesList );
487 HYDROGUI_CalculationDlg* aPanel =
488 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
491 theLandCover ? aPanel->refreshLandCoverZonesBrowser(): aPanel->refreshZonesBrowser();
493 createPreview( theLandCover );
498 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
500 if ( createRegion( theZonesList, false ) )
502 HYDROGUI_CalculationDlg* aPanel =
503 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
506 aPanel->refreshZonesBrowser();
508 createPreview( false );
512 void HYDROGUI_CalculationOp::onCreateLandCoverRegion( const QList<SUIT_DataObject*>& theZonesList )
514 if ( createRegion( theZonesList, true ) )
516 HYDROGUI_CalculationDlg* aPanel =
517 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
520 aPanel->refreshLandCoverZonesBrowser();
522 createPreview( true );
526 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theMergeObjectName )
528 HYDROGUI_CalculationDlg* aPanel =
529 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
532 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
535 aZone->setMergeType( theMergeType, theMergeObjectName );
536 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
539 aShape->update( true, false );
542 aPanel->refreshZonesBrowser();
546 void HYDROGUI_CalculationOp::onSetMergeStricklerType( int theMergeType, QString& theStricklerTypeName )
548 HYDROGUI_CalculationDlg* aPanel =
549 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
552 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
555 aZone->setMergeType( theMergeType, theStricklerTypeName );
556 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
559 aShape->update( true, false );
562 aPanel->refreshLandCoverZonesBrowser();
566 void HYDROGUI_CalculationOp::onAddObjects()
568 HYDROGUI_CalculationDlg* aPanel =
569 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
573 // Add geometry objects selected in the module browser to the calculation case
574 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
575 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
578 QStringList anAddedList;
579 for (int i = 0; i < aSelectedList.length(); i++)
581 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
582 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
583 if ( anObject.IsNull() )
586 if ( myEditedObject->AddGeometryObject( anObject ) )
587 anAddedList.append( anObject->GetName() );
590 if ( !anAddedList.isEmpty() )
592 aPanel->includeGeomObjects( anAddedList );
593 createPreview( false );
597 void HYDROGUI_CalculationOp::onRemoveObjects()
599 // Remove selected objects from the calculation case
600 HYDROGUI_CalculationDlg* aPanel =
601 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
605 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
606 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
609 for (int i = 0; i < aSelectedList.length(); i++)
611 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
612 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
613 if ( anObject.IsNull() )
616 setObjectVisibility( anObject, false );
617 myEditedObject->RemoveGeometryObject( anObject );
620 module()->update( UF_OCCViewer );
621 aPanel->excludeGeomObjects( aSelectedList );
624 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
626 // Check if the case is already modified or not
627 bool isConfirmed = myEditedObject->IsMustBeUpdated();
630 // If not modified check if the case has already defined regions with zones
631 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
632 if ( aSeq.Length() > 0 )
634 // If there are already defined zones then ask a user to confirm zones recalculation
635 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
636 tr( "REGIONS_CHANGED" ),
637 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
638 QMessageBox::Yes | QMessageBox::No,
639 QMessageBox::No ) == QMessageBox::Yes );
643 isConfirmed = true; // No regions - no zones - nothing to recalculate
649 bool HYDROGUI_CalculationOp::confirmOrderChange() const
651 // Check if the case is already modified or not
652 bool isConfirmed = myEditedObject->IsMustBeUpdated();
655 // If not modified check if the case has already defined regions with zones
656 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
657 if ( aSeq.Length() > 0 )
659 // If there are already defined zones then ask a user to confirm zones recalculation
660 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
661 tr( "ORDER_CHANGED" ),
662 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
663 QMessageBox::Yes | QMessageBox::No,
664 QMessageBox::No ) == QMessageBox::Yes );
668 isConfirmed = true; // No regions - no zones - nothing to recalculate
674 bool HYDROGUI_CalculationOp::confirmModeChange() const
676 // Check if the case is already modified or not
677 bool isConfirmed = myEditedObject->IsMustBeUpdated();
680 // If not modified check if the case has already defined regions with zones
681 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
682 if ( aSeq.Length() > 0 )
684 // If there are already defined zones then ask a user to confirm zones recalculation
685 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
686 tr( "MODE_CHANGED" ),
687 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
688 QMessageBox::Yes | QMessageBox::No,
689 QMessageBox::No ) == QMessageBox::Yes );
693 isConfirmed = true; // No regions - no zones - nothing to recalculate
699 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
701 HYDROData_WarningType aType = theWarning.Type;
702 if ( aType == WARN_OK ) {
710 case WARN_EMPTY_REGIONS:
711 aTitle = tr( "EMPTY_REGIONS" );
712 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
715 aTitle = tr( "WARNING" );
716 aMsg = theWarning.Data;
720 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
722 QMessageBox::Yes | QMessageBox::No,
725 return ( anAnswer == QMessageBox::Yes );
728 bool HYDROGUI_CalculationOp::confirmLandCoverModeChange() const
730 // Check if the case is already modified or not
731 bool isConfirmed = myEditedObject->IsMustBeUpdated();
734 // If not modified check if the case has already defined regions with zones
735 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
736 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
737 if ( aSeq.Length() > 0 )
739 // If there are already defined zones then ask a user to confirm zones recalculation
740 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
741 tr( "MODE_CHANGED" ),
742 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_MODE" ),
743 QMessageBox::Yes | QMessageBox::No,
744 QMessageBox::No ) == QMessageBox::Yes );
748 isConfirmed = true; // No regions - no zones - nothing to recalculate
754 bool HYDROGUI_CalculationOp::confirmLandCoverOrderChange() const
756 // Check if the case is already modified or not
757 bool isConfirmed = myEditedObject->IsMustBeUpdated();
760 // If not modified check if the case has already defined regions with zones
761 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
762 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
763 if ( aSeq.Length() > 0 )
765 // If there are already defined zones then ask a user to confirm zones recalculation
766 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
767 tr( "ORDER_CHANGED" ),
768 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
769 QMessageBox::Yes | QMessageBox::No,
770 QMessageBox::No ) == QMessageBox::Yes );
774 isConfirmed = true; // No regions - no zones - nothing to recalculate
780 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
781 QString& theErrorMsg,
782 QStringList& theBrowseObjectsEntries )
784 HYDROGUI_CalculationDlg* aPanel =
785 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
791 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
792 theBrowseObjectsEntries.append( anEntry );
795 // For manual mode priority rules are redundant
796 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
797 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
799 if ( aPanel->getLandCoverMode() == HYDROData_CalculationCase::MANUAL ) {
800 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, false );
803 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
808 void HYDROGUI_CalculationOp::onApply()
811 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
812 if ( aWarning.Type != WARN_OK ) {
813 if ( !confirmContinueWithWarning( aWarning ) ) {
814 // Go back to the first page
815 HYDROGUI_CalculationDlg* aPanel =
816 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
818 aPanel->onFirstPage();
824 QApplication::setOverrideCursor( Qt::WaitCursor );
826 int anUpdateFlags = 0;
828 QStringList aBrowseObjectsEntries;
830 bool aResult = false;
834 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
836 catch ( Standard_Failure )
838 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
839 anErrorMsg = aFailure->GetMessageString();
847 QApplication::restoreOverrideCursor();
851 module()->update( anUpdateFlags );
853 browseObjects( aBrowseObjectsEntries );
858 QString aMsg = tr( "INPUT_VALID_DATA" );
859 if( !anErrorMsg.isEmpty() )
860 aMsg.prepend( anErrorMsg + "\n" );
861 SUIT_MessageBox::critical( module()->getApp()->desktop(),
862 tr( "INSUFFICIENT_INPUT_DATA" ),
867 void HYDROGUI_CalculationOp::onNext( const int theIndex )
871 setAvailableGroups();
873 else if( theIndex==2 )
876 HYDROGUI_CalculationDlg* aPanel =
877 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
882 QStringList anEntryList;
883 HYDROData_SequenceOfObjects aSeq;
885 Handle(HYDROData_StricklerTable) aStricklerTableObj;
886 QString aStricklerTableName;
888 // Get all Strickler table objects to fill in combo-box
891 HYDROData_Iterator anIter( doc(), KIND_STRICKLER_TABLE );
892 for ( ; anIter.More(); anIter.Next() )
894 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
896 if ( !aStricklerTableObj.IsNull() )
898 aStricklerTableName = aStricklerTableObj->GetName();
899 if ( !aStricklerTableName.isEmpty() )
901 aList.append( aStricklerTableName );
902 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
906 aPanel->setStricklerTableNames( aList, anEntryList );
907 if ( !aList.isEmpty() )
908 aPanel->setStricklerTable( aList.at( 0 ), false );
910 // Fill in list widget with all available land covers
911 aSeq = HYDROGUI_Tool::GetLandCovers( module() );
912 getNamesAndEntries( aSeq, aList, anEntryList );
913 aPanel->setAllLandCovers( aList, anEntryList );
915 // Set list of included land covers
916 aSeq = myEditedObject->GetLandCovers();
917 getNamesAndEntries( aSeq, aList, anEntryList );
918 aPanel->includeLandCovers( aList, true );
920 if ( !myEditedObject.IsNull() )
924 // Select the certain Strickler table object in combo-box
925 aStricklerTableObj = myEditedObject->GetStricklerTable();
926 if ( aStricklerTableObj.IsNull() )
928 aPanel->setStricklerTable( QString() );
932 aStricklerTableName = aStricklerTableObj->GetName();
933 aPanel->setStricklerTable( aStricklerTableName );
936 // Set mode (Auto or Manual) to defined priority of land covers
937 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
939 // Set rules defined on land covers
940 setRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
944 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getLandCoverMode() );
948 closePreview( false );
949 createPreview( true );
951 else if( theIndex==3 )
953 HYDROGUI_CalculationDlg* aPanel =
954 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
958 QApplication::setOverrideCursor( Qt::WaitCursor );
960 setGeomObjectsVisible( false );
962 QString aNewCaseName = aPanel->getObjectName();
963 QString anOldCaseName = myEditedObject->GetName();
964 bool isNameChanged = anOldCaseName != aNewCaseName;
966 bool anIsToUpdateOb = isNameChanged;
968 // At first we must to update the case name because of
969 // automatic names generation for regions and zones
970 myEditedObject->SetName( aNewCaseName );
972 // Set parameters for automatic mode
973 int aMode = aPanel->getMode();
974 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
976 // Set objects in the specified order
977 if( myEditedObject->IsMustBeUpdated() )
979 myEditedObject->RemoveGeometryObjects();
980 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
982 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
983 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
984 if ( anObject.IsNull() )
988 myEditedObject->AddGeometryObject( anObject );
991 // Clear priority rules
992 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
993 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
995 // Set priority rules
996 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
997 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
998 aRule.Object2, aRule.MergeType,
999 HYDROData_CalculationCase::DataTag_CustomRules );
1003 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1005 if ( myEditedObject->IsMustBeUpdated() )
1008 myEditedObject->Update();
1010 AssignDefaultZonesColors( false );
1012 //aPanel->setEditedObject( myEditedObject );
1013 aPanel->refreshZonesBrowser();
1015 closePreview( false );
1016 createPreview( false );
1018 anIsToUpdateOb = true;
1020 myEditedObject->SetToUpdate( true );
1025 setZonesVisible( true, false );
1027 if ( isNameChanged ) {
1028 module()->getDataModel()->updateObjectTree( myEditedObject );
1032 QApplication::restoreOverrideCursor();
1034 else if( theIndex==4 )
1036 // Partition of Land covers panel
1037 HYDROGUI_CalculationDlg* aPanel =
1038 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1042 QApplication::setOverrideCursor( Qt::WaitCursor );
1044 // Set parameters for automatic mode
1045 int aMode = aPanel->getLandCoverMode();
1046 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1048 // Set objects in the specified order
1049 if( myEditedObject->IsMustBeUpdated() )
1051 myEditedObject->RemoveLandCovers();
1052 foreach ( const QString& aName, aPanel->getAllLandCovers() )
1054 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast(
1055 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1056 if ( aLandCover.IsNull() )
1060 myEditedObject->AddLandCover( aLandCover );
1063 // Clear priority rules
1064 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true );
1065 // Set priority rules
1066 foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) {
1067 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1068 aRule.Object2, HYDROData_Zone::Merge_Object,
1069 HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
1073 aPanel->setEditLandCoverZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1075 bool anIsToUpdateOb = false;
1076 bool anIsToUpdate = myEditedObject->IsMustBeUpdated();
1080 myEditedObject->Update();
1082 AssignDefaultZonesColors( true );
1084 aPanel->refreshLandCoverZonesBrowser();
1086 anIsToUpdateOb = true;
1089 closePreview( false );
1090 createPreview( true );
1092 if ( !anIsToUpdate )
1095 setZonesVisible( false, false );
1096 // Show land cover zones
1097 setZonesVisible( true, true );
1100 if ( anIsToUpdateOb ) {
1101 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
1102 if ( anObjBrowser ) {
1103 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
1107 QApplication::restoreOverrideCursor();
1111 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
1115 closePreview( false );
1116 createPreview( false );
1120 closePreview( false );
1121 createPreview( true );
1124 setZonesVisible( false, false );
1126 setZonesVisible( false, true );
1128 else if( theIndex==3 )
1130 AssignDefaultZonesColors( false );
1132 closePreview( false );
1133 createPreview( false );
1135 // Hide land cover zones
1136 setZonesVisible( false, true );
1138 setZonesVisible( true, false );
1142 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible, const bool theLandCover )
1144 myShowZones = theIsVisible;
1145 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1146 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1147 HYDROData_SequenceOfObjects aZones;
1148 Handle(HYDROData_Region) aRegion;
1149 if ( myPreviewViewManager )
1151 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1153 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1154 if ( !aCtx.IsNull() )
1156 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1158 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1159 if ( !aRegion.IsNull() )
1161 aZones = aRegion->GetZones();
1162 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1163 for ( ; aZonesIter.More(); aZonesIter.Next() )
1165 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1171 module()->update( UF_OCCViewer );
1176 void HYDROGUI_CalculationOp::AssignDefaultZonesColors( const bool theLandCover )
1178 myShowGeomObjects = theIsVisible;
1180 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
1182 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1183 for ( ; anIter.More(); anIter.Next() ) {
1184 setObjectVisibility( anIter.Value(), theIsVisible );
1189 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1190 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1191 HYDROData_SequenceOfObjects aZones;
1192 Handle(HYDROData_Region) aRegion;
1193 if ( myPreviewViewManager )
1195 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1197 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1198 if ( !aCtx.IsNull() )
1201 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1203 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1204 if ( !aRegion.IsNull() )
1206 aZones = aRegion->GetZones();
1207 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1208 for ( ; aZonesIter.More(); aZonesIter.Next() )
1211 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1212 if ( !aZone.IsNull() )
1214 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
1215 while (aFillingColor == Qt::red)
1216 aFillingColor = GenerateDefaultZonesColor(++aCounter);
1218 aZone->SetColor(aFillingColor);
1228 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
1229 float theSaturation/* = 0.5*/,
1230 float theValue/* = 0.95*/ ) const
1232 float aGoldenRatioConjugate = (float)(360./582.);
1233 float aHue = (float)(rand()%100);
1234 aHue += aGoldenRatioConjugate*theIndex;
1235 aHue -= floor(aHue);
1237 float aR = 0., aG = 0., aB = 0.;
1238 int aHueInt = (int)(aHue*6.);
1239 float aF = aHue*6. - aHueInt;
1240 float aP = theValue * (1. - theSaturation);
1241 float aQ = theValue * (1. - aF*theSaturation);
1242 float aT = theValue * (1. - (1. - aF) * theSaturation);
1245 case 0: { aR = theValue; aG = aT; aB = aP; break; }
1246 case 1: { aR = aQ; aG = theValue; aB = aP; break; }
1247 case 2: { aR = aP; aG = theValue; aB = aT; break; }
1248 case 3: { aR = aP; aG = aQ; aB = theValue; break; }
1249 case 4: { aR = aT; aG = aP; aB = theValue; break; }
1250 case 5: { aR = theValue; aG = aP; aB = aQ; break; }
1254 QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
1255 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
1258 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1260 HYDROGUI_CalculationDlg* aPanel =
1261 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1265 HYDROData_ListOfRules aRules;
1266 Handle(HYDROData_Entity) anObject1, anObject2;
1267 HYDROData_PriorityType aPriority;
1268 HYDROData_Zone::MergeType aMergeType;
1269 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1270 for ( int anIndex = 0; ; anIndex++ )
1272 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1273 HYDROData_CustomRule aRule;
1274 aRule.Object1 = anObject1;
1275 aRule.Object2 = anObject2;
1276 aRule.Priority = aPriority;
1277 aRule.MergeType = aMergeType;
1285 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1286 aPanel->setRules( aRules );
1287 else if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomLandCoverRules )
1288 aPanel->setLandCoverRules( aRules );
1291 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList,
1292 const bool theLandCover )
1294 bool aRetValue = false;
1296 QList<HYDROGUI_Zone*> aZonesList;
1297 HYDROGUI_Zone* aZone;
1298 // Get a list of dropped zones
1299 for ( int i = 0; i < theZonesList.length(); i++ )
1301 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1304 aZonesList.append( aZone );
1307 if ( aZonesList.length() > 0 )
1309 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList, theLandCover );
1316 void HYDROGUI_CalculationOp::createPreview( const bool theLandCover )
1318 LightApp_Application* anApp = module()->getApp();
1319 HYDROData_SequenceOfObjects aSeq;
1321 aSeq = myEditedObject->GetLandCovers();
1323 aSeq = myEditedObject->GetGeometryObjects();
1325 Handle(HYDROData_Entity) anEntity;
1329 // Gather zones for displaying
1330 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1331 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1332 HYDROData_SequenceOfObjects aZones;
1333 Handle(HYDROData_Region) aRegion;
1334 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1336 anEntity = aRegionsIter.Value();
1337 if ( !anEntity.IsNull() )
1339 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1340 if ( !aRegion.IsNull() )
1342 aZones = aRegion->GetZones();
1343 aSeq.Append( aZones );
1349 // Get a boundary polyline if any
1350 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
1352 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1354 if ( !myActiveViewManager )
1356 if ( aSeq.IsEmpty() )
1359 myActiveViewManager = anApp->activeViewManager();
1362 if ( !myPreviewViewManager )
1364 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1365 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1366 if ( myPreviewViewManager )
1368 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1369 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1371 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1372 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1376 if ( !myPreviewViewManager )
1379 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1381 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1382 if ( !aCtx.IsNull() )
1384 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1385 for ( ; anIter.More(); anIter.Next() )
1387 setObjectVisibility( anIter.Value(), true );
1390 //Process the draw events for viewer
1391 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1392 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
1396 module()->update( UF_OCCViewer | UF_FitAll );
1400 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1402 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1406 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1408 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1412 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1417 void HYDROGUI_CalculationOp::closePreview( bool theRemoveViewManager )
1419 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1420 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1421 QShortcut* aShortcut;
1422 foreach( aShortcut, aShortcuts )
1424 if ( aShortcut->key() ==
1425 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1426 SUIT_DataBrowser::RenameShortcut ) ) )
1428 aShortcut->setEnabled( true );
1433 if( myPreviewViewManager )
1435 // Hide all the displayed objects in the preview view
1436 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1438 size_t aViewId = (size_t)aViewer;
1439 HYDROData_Iterator anIterator( doc() );
1440 for( ; anIterator.More(); anIterator.Next() ) {
1441 Handle(HYDROData_Entity) anObject = anIterator.Current();
1442 if( !anObject.IsNull() ) {
1443 module()->setObjectVisible( aViewId, anObject, false );
1448 if ( theRemoveViewManager )
1450 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1451 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1453 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1454 myPreviewViewManager = NULL;
1458 if( myActiveViewManager && theRemoveViewManager )
1460 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1461 myActiveViewManager = NULL;
1465 void HYDROGUI_CalculationOp::setAvailableGroups()
1467 HYDROGUI_CalculationDlg* aPanel =
1468 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1470 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1471 QStringList aList, anEntryList;
1472 getNamesAndEntries( aSeq, aList, anEntryList );
1474 QStringList aGroupsNames;
1476 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1477 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1479 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1480 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1481 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1483 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1484 aGroupsNames.append( aGroup->GetName() );
1487 if( myEditedObject->IsMustBeUpdated() ) {
1488 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1489 Handle(HYDROData_ShapesGroup) aGeomGroup =
1490 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1491 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1492 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1497 aPanel->setAvailableGroups( aGroupsNames );
1498 aPanel->includeGroups( aList );
1500 bool isUpdated = myEditedObject->IsMustBeUpdated();
1503 void HYDROGUI_CalculationOp::onAddGroups()
1505 HYDROGUI_CalculationDlg* aPanel =
1506 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1510 // Add geometry objects selected in the module browser to the calculation case
1511 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1512 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1515 QStringList anAddedList;
1516 for (int i = 0; i < aSelectedList.length(); i++)
1518 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1519 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1520 if ( aGroup.IsNull() )
1523 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1524 anAddedList.append( aGroup->GetName() );
1527 if ( !anAddedList.isEmpty() )
1529 aPanel->includeGroups( anAddedList );
1533 void HYDROGUI_CalculationOp::onRemoveGroups()
1535 // Remove selected objects from the calculation case
1536 HYDROGUI_CalculationDlg* aPanel =
1537 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1541 QStringList aSelectedList = aPanel->getSelectedGroups();
1542 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1545 for (int i = 0; i < aSelectedList.length(); i++)
1547 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1548 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1549 if ( aGroup.IsNull() )
1552 myEditedObject->RemoveGeometryGroup( aGroup );
1555 aPanel->excludeGroups( aSelectedList );
1558 void HYDROGUI_CalculationOp::onChangeLandCoverMode( int theMode )
1560 HYDROGUI_CalculationDlg* aPanel =
1561 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1565 if ( !confirmLandCoverModeChange() ) {
1566 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
1570 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1571 aPanel->setLandCoverMode( theMode );
1574 void HYDROGUI_CalculationOp::onAddLandCovers()
1576 HYDROGUI_CalculationDlg* aPanel =
1577 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1581 // Add land covers selected in the module browser to the calculation case
1582 QStringList aSelectedList = aPanel->getSelectedAvailableLandCovers();
1583 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1586 QStringList anAddedList;
1587 for (int i = 0; i < aSelectedList.length(); i++)
1589 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1590 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1591 if ( anObject.IsNull() )
1594 if ( myEditedObject->AddLandCover( anObject ) )
1595 anAddedList.append( anObject->GetName() );
1598 if ( !anAddedList.isEmpty() )
1600 aPanel->includeLandCovers( anAddedList, false );
1601 createPreview( true );
1605 void HYDROGUI_CalculationOp::onRemoveLandCovers()
1607 // Remove selected objects from the calculation case
1608 HYDROGUI_CalculationDlg* aPanel =
1609 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1613 QStringList aSelectedList = aPanel->getSelectedLandCovers();
1614 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1617 for (int i = 0; i < aSelectedList.length(); i++)
1619 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1620 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1621 if ( anObject.IsNull() )
1624 setObjectVisibility( anObject, false );
1625 myEditedObject->RemoveLandCover( anObject );
1628 module()->update( UF_OCCViewer );
1629 aPanel->excludeLandCovers( aSelectedList );
1632 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1634 HYDROGUI_CalculationDlg* aPanel =
1635 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1639 if ( !confirmModeChange() ) {
1640 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1644 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1645 aPanel->setMode( theMode );
1648 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1650 HYDROGUI_CalculationDlg* aPanel =
1651 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1655 isConfirmed = confirmOrderChange();
1657 myEditedObject->SetToUpdate( true );
1660 void HYDROGUI_CalculationOp::onOrderLandCoverChanged( bool& isConfirmed )
1662 HYDROGUI_CalculationDlg* aPanel =
1663 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1667 isConfirmed = confirmLandCoverOrderChange();
1669 myEditedObject->SetToUpdate( true );