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 ),
61 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
64 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
69 void HYDROGUI_CalculationOp::startOperation()
71 HYDROGUI_Operation::startOperation();
76 HYDROGUI_CalculationDlg* aPanel =
77 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
81 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
82 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
84 foreach( aShortcut, aShortcuts )
86 if ( aShortcut->key() ==
87 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
88 SUIT_DataBrowser::RenameShortcut ) ) )
90 aShortcut->setEnabled( false );
96 QStringList anEntryList;
97 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
98 getNamesAndEntries( aSeq, aList, anEntryList );
99 aPanel->setAllGeomObjects( aList, anEntryList );
104 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
105 Handle(HYDROData_PolylineXY) aPolylineObj;
106 QString aPolylineName;
107 for ( ; anIter.More(); anIter.Next() )
109 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
111 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
113 // Check the polyline shape
114 TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
115 if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
116 aPolylineName = aPolylineObj->GetName();
117 if ( !aPolylineName.isEmpty() )
119 aList.append( aPolylineName );
120 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
125 aPanel->setPolylineNames( aList, anEntryList );
127 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
129 myEditedObject.Nullify();
132 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
133 if ( !myEditedObject.IsNull() )
135 aPanel->setMode( myEditedObject->GetAssignmentMode() );
136 anObjectName = myEditedObject->GetName();
137 aPolylineObj = myEditedObject->GetBoundaryPolyline();
138 if ( aPolylineObj.IsNull() )
140 aPanel->setBoundary( QString() );
144 aPolylineName = aPolylineObj->GetName();
145 aPanel->setBoundary( aPolylineName );
148 aSeq = myEditedObject->GetGeometryObjects();
149 getNamesAndEntries( aSeq, aList, anEntryList );
150 aPanel->includeGeomObjects( aList );
153 setRules( HYDROData_CalculationCase::DataTag_CustomRules );
159 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
160 myEditedObject->SetName( anObjectName );
161 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
164 aPanel->setObjectName( anObjectName );
165 aPanel->setEditedObject( myEditedObject );
167 createPreview( false );
170 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
171 QStringList& theNames, QStringList& theEntries ) const
176 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
177 for ( ; anIter.More(); anIter.Next() )
179 Handle(HYDROData_Entity) anEntity = anIter.Value();
180 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
183 theNames.append( anEntity->GetName() );
184 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
188 void HYDROGUI_CalculationOp::abortOperation()
193 HYDROGUI_Operation::abortOperation();
194 module()->getApp()->updateObjectBrowser();
197 void HYDROGUI_CalculationOp::commitOperation()
200 // Commit transaction
201 commitDocOperation();
202 HYDROGUI_Operation::commitOperation();
205 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
207 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
209 // Connect signals and slots
210 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
211 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
212 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
213 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
214 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
216 connect( aPanel, SIGNAL( changeLandCoverMode( int ) ), SLOT( onChangeLandCoverMode( int ) ) );
217 connect( aPanel, SIGNAL( addLandCovers() ), SLOT( onAddLandCovers() ) );
218 connect( aPanel, SIGNAL( removeLandCovers() ), SLOT( onRemoveLandCovers() ) );
220 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
221 connect( aPanel, SIGNAL( orderLandCoverChanged( bool& ) ), SLOT( onOrderLandCoverChanged( bool& ) ) );
223 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
224 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones( const int ) ) );
225 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
226 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
227 connect( aPanel, SIGNAL( setMergeStricklerType( int, QString& ) ), SLOT( onSetMergeStricklerType( int, QString& ) ) );
228 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>&, bool ) ),
229 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>&, bool ) ) );
230 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
231 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
232 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
233 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
234 connect( aPanel, SIGNAL( objectsSelected() ),
235 SLOT( onObjectsSelected() ) );
236 connect( aPanel, SIGNAL( landCoversSelected() ),
237 SLOT( onLandCoversSelected() ) );
238 connect( aPanel, SIGNAL( createLandCoverRegion( const QList<SUIT_DataObject*>& ) ),
239 SLOT( onCreateLandCoverRegion( const QList<SUIT_DataObject*>& ) ) );
240 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
241 SLOT( onBoundarySelected( const QString & ) ) );
242 connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
243 SLOT( onStricklerTableSelected( const QString & ) ) );
248 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
250 bool anIsToUpdateViewer = false;
252 // Remove the old boundary from the operation viewer
253 Handle(HYDROData_PolylineXY) aPrevPolyline =
254 myEditedObject->GetBoundaryPolyline();
255 if ( !aPrevPolyline.IsNull() )
257 setObjectVisibility( aPrevPolyline, false );
258 anIsToUpdateViewer = true;
261 // Set the selected boundary polyline to the calculation case
262 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
263 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
264 myEditedObject->SetBoundaryPolyline( aNewPolyline );
266 if ( myPreviewViewManager )
268 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
271 if ( !aNewPolyline.IsNull() )
273 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
274 if ( !aCtx.IsNull() )
276 setObjectVisibility( aNewPolyline, true );
277 anIsToUpdateViewer = true;
281 if ( anIsToUpdateViewer )
282 module()->update( UF_OCCViewer );
287 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
289 bool anIsToUpdateViewer = false;
291 // Remove old presentations of land covers from the operation viewer
292 Handle(HYDROData_Entity) anEntity;
293 Handle(HYDROData_LandCover) aLandCover;
294 HYDROData_SequenceOfObjects aLandCovers;
295 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
296 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
297 for ( ; anIter.More(); anIter.Next() )
299 anEntity = anIter.Value();
300 if ( !anEntity.IsNull() )
302 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
303 if ( !aLandCover.IsNull() )
305 aLandCovers.Append( aLandCover );
306 setObjectVisibility( aLandCover, false );
307 anIsToUpdateViewer = true;
312 // Set the selected Strickler table to the calculation case
313 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
314 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
315 myEditedObject->SetStricklerTable( aNewStricklerTable );
317 if ( myPreviewViewManager )
319 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
322 if ( !aNewStricklerTable.IsNull() )
324 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
325 if ( !aCtx.IsNull() )
327 HYDROData_SequenceOfObjects::Iterator anIter( aLandCovers );
328 for ( ; anIter.More(); anIter.Next() )
330 anEntity = anIter.Value();
331 if ( !anEntity.IsNull() )
333 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
334 if ( !aLandCover.IsNull() )
336 setObjectVisibility( aLandCover, true );
337 anIsToUpdateViewer = true;
344 if ( anIsToUpdateViewer )
345 module()->update( UF_OCCViewer );
350 void HYDROGUI_CalculationOp::onObjectsSelected()
352 HYDROGUI_CalculationDlg* aPanel =
353 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
355 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
356 QMap<QString, bool> aSelectedObjsMap;
357 foreach( QString aName, aSelectedObjs )
358 aSelectedObjsMap[aName] = true;
361 // Select the appropriate geometry object shape in the viewer
362 selectionMgr()->clearSelected();
364 // Unhighlight all objects except selected
365 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
366 Handle(HYDROData_Entity) anEntity;
367 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
368 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
371 for ( ; anIter.More(); anIter.Next() )
373 anEntity = anIter.Value();
374 if ( !anEntity.IsNull() )
376 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
379 aName = anEntity->GetName();
380 isSelected = aSelectedObjsMap.contains( aName );
381 aShape->highlight( isSelected, false );
382 aShape->update( false, false );
388 aLastShape->update( true, false );
391 void HYDROGUI_CalculationOp::onLandCoversSelected()
393 HYDROGUI_CalculationDlg* aPanel =
394 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
396 QStringList aSelectedObjs = aPanel->getSelectedLandCovers();
397 QMap<QString, bool> aSelectedObjsMap;
398 foreach( QString aName, aSelectedObjs )
399 aSelectedObjsMap[aName] = true;
402 // Select the appropriate land cover shape in the viewer
403 selectionMgr()->clearSelected();
405 // Unhighlight all land covers except selected
406 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
407 Handle(HYDROData_Entity) anEntity;
408 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
409 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
412 for ( ; anIter.More(); anIter.Next() )
414 anEntity = anIter.Value();
415 if ( !anEntity.IsNull() )
417 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
420 aName = anEntity->GetName();
421 isSelected = aSelectedObjsMap.contains( aName );
422 aShape->highlight( isSelected, false );
423 aShape->update( false, false );
429 aLastShape->update( true, false );
432 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
434 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
435 HYDROGUI_Zone* aZoneItem;
436 selectionMgr()->clearSelected();
439 // Select a region in preview
440 SUIT_DataOwnerPtrList aList( true );
441 DataObjectList aZones = aRegionItem->children();
442 for ( int i = 0; i < aZones.length(); i++ )
444 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
447 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
450 selectionMgr()->setSelected( aList );
454 // select a single zone
455 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
458 SUIT_DataOwnerPtrList aList( true );
459 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
460 selectionMgr()->setSelected( aList );
465 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem,
466 const QList<SUIT_DataObject*>& theZonesList,
469 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
472 QList<HYDROGUI_Zone*> aZonesList;
473 HYDROGUI_Zone* aZone;
474 // Get a list of dropped zones
475 for ( int i = 0; i < theZonesList.length(); i++ )
477 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
480 aZonesList.append( aZone );
483 if ( aZonesList.length() > 0 )
485 aRegion->addZones( aZonesList );
486 HYDROGUI_CalculationDlg* aPanel =
487 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
490 theLandCover ? aPanel->refreshLandCoverZonesBrowser(): aPanel->refreshZonesBrowser();
492 createPreview( theLandCover );
497 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
499 if ( createRegion( theZonesList, false ) )
501 HYDROGUI_CalculationDlg* aPanel =
502 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
505 aPanel->refreshZonesBrowser();
507 createPreview( false );
511 void HYDROGUI_CalculationOp::onCreateLandCoverRegion( const QList<SUIT_DataObject*>& theZonesList )
513 if ( createRegion( theZonesList, true ) )
515 HYDROGUI_CalculationDlg* aPanel =
516 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
519 aPanel->refreshLandCoverZonesBrowser();
521 createPreview( true );
525 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theMergeObjectName )
527 HYDROGUI_CalculationDlg* aPanel =
528 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
531 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
534 aZone->setMergeType( theMergeType, theMergeObjectName );
535 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
538 aShape->update( true, false );
541 aPanel->refreshZonesBrowser();
545 void HYDROGUI_CalculationOp::onSetMergeStricklerType( int theMergeType, QString& theStricklerTypeName )
547 HYDROGUI_CalculationDlg* aPanel =
548 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
551 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
554 aZone->setMergeType( theMergeType, theStricklerTypeName );
555 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
558 aShape->update( true, false );
561 aPanel->refreshLandCoverZonesBrowser();
565 void HYDROGUI_CalculationOp::onAddObjects()
567 HYDROGUI_CalculationDlg* aPanel =
568 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
572 // Add geometry objects selected in the module browser to the calculation case
573 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
574 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
577 QStringList anAddedList;
578 for (int i = 0; i < aSelectedList.length(); i++)
580 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
581 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
582 if ( anObject.IsNull() )
585 if ( myEditedObject->AddGeometryObject( anObject ) )
586 anAddedList.append( anObject->GetName() );
589 if ( !anAddedList.isEmpty() )
591 aPanel->includeGeomObjects( anAddedList );
592 createPreview( false );
596 void HYDROGUI_CalculationOp::onRemoveObjects()
598 // Remove selected objects from the calculation case
599 HYDROGUI_CalculationDlg* aPanel =
600 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
604 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
605 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
608 for (int i = 0; i < aSelectedList.length(); i++)
610 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
611 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
612 if ( anObject.IsNull() )
615 setObjectVisibility( anObject, false );
616 myEditedObject->RemoveGeometryObject( anObject );
619 module()->update( UF_OCCViewer );
620 aPanel->excludeGeomObjects( aSelectedList );
623 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
625 // Check if the case is already modified or not
626 bool isConfirmed = myEditedObject->IsMustBeUpdated();
629 // If not modified check if the case has already defined regions with zones
630 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
631 if ( aSeq.Length() > 0 )
633 // If there are already defined zones then ask a user to confirm zones recalculation
634 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
635 tr( "REGIONS_CHANGED" ),
636 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
637 QMessageBox::Yes | QMessageBox::No,
638 QMessageBox::No ) == QMessageBox::Yes );
642 isConfirmed = true; // No regions - no zones - nothing to recalculate
648 bool HYDROGUI_CalculationOp::confirmOrderChange() const
650 // Check if the case is already modified or not
651 bool isConfirmed = myEditedObject->IsMustBeUpdated();
654 // If not modified check if the case has already defined regions with zones
655 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
656 if ( aSeq.Length() > 0 )
658 // If there are already defined zones then ask a user to confirm zones recalculation
659 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
660 tr( "ORDER_CHANGED" ),
661 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
662 QMessageBox::Yes | QMessageBox::No,
663 QMessageBox::No ) == QMessageBox::Yes );
667 isConfirmed = true; // No regions - no zones - nothing to recalculate
673 bool HYDROGUI_CalculationOp::confirmModeChange() const
675 // Check if the case is already modified or not
676 bool isConfirmed = myEditedObject->IsMustBeUpdated();
679 // If not modified check if the case has already defined regions with zones
680 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
681 if ( aSeq.Length() > 0 )
683 // If there are already defined zones then ask a user to confirm zones recalculation
684 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
685 tr( "MODE_CHANGED" ),
686 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
687 QMessageBox::Yes | QMessageBox::No,
688 QMessageBox::No ) == QMessageBox::Yes );
692 isConfirmed = true; // No regions - no zones - nothing to recalculate
698 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
700 HYDROData_WarningType aType = theWarning.Type;
701 if ( aType == WARN_OK ) {
709 case WARN_EMPTY_REGIONS:
710 aTitle = tr( "EMPTY_REGIONS" );
711 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
714 aTitle = tr( "WARNING" );
715 aMsg = theWarning.Data;
719 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
721 QMessageBox::Yes | QMessageBox::No,
724 return ( anAnswer == QMessageBox::Yes );
727 bool HYDROGUI_CalculationOp::confirmLandCoverModeChange() const
729 // Check if the case is already modified or not
730 bool isConfirmed = myEditedObject->IsMustBeUpdated();
733 // If not modified check if the case has already defined regions with zones
734 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
735 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
736 if ( aSeq.Length() > 0 )
738 // If there are already defined zones then ask a user to confirm zones recalculation
739 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
740 tr( "MODE_CHANGED" ),
741 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_MODE" ),
742 QMessageBox::Yes | QMessageBox::No,
743 QMessageBox::No ) == QMessageBox::Yes );
747 isConfirmed = true; // No regions - no zones - nothing to recalculate
753 bool HYDROGUI_CalculationOp::confirmLandCoverOrderChange() const
755 // Check if the case is already modified or not
756 bool isConfirmed = myEditedObject->IsMustBeUpdated();
759 // If not modified check if the case has already defined regions with zones
760 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
761 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
762 if ( aSeq.Length() > 0 )
764 // If there are already defined zones then ask a user to confirm zones recalculation
765 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
766 tr( "ORDER_CHANGED" ),
767 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
768 QMessageBox::Yes | QMessageBox::No,
769 QMessageBox::No ) == QMessageBox::Yes );
773 isConfirmed = true; // No regions - no zones - nothing to recalculate
779 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
780 QString& theErrorMsg,
781 QStringList& theBrowseObjectsEntries )
783 HYDROGUI_CalculationDlg* aPanel =
784 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
790 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
791 theBrowseObjectsEntries.append( anEntry );
794 // For manual mode priority rules are redundant
795 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
796 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
798 if ( aPanel->getLandCoverMode() == HYDROData_CalculationCase::MANUAL ) {
799 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, false );
802 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
807 void HYDROGUI_CalculationOp::onApply()
810 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
811 if ( aWarning.Type != WARN_OK ) {
812 if ( !confirmContinueWithWarning( aWarning ) ) {
813 // Go back to the first page
814 HYDROGUI_CalculationDlg* aPanel =
815 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
817 aPanel->onFirstPage();
823 QApplication::setOverrideCursor( Qt::WaitCursor );
825 int anUpdateFlags = 0;
827 QStringList aBrowseObjectsEntries;
829 bool aResult = false;
833 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
835 catch ( Standard_Failure )
837 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
838 anErrorMsg = aFailure->GetMessageString();
846 QApplication::restoreOverrideCursor();
850 module()->update( anUpdateFlags );
852 browseObjects( aBrowseObjectsEntries );
857 QString aMsg = tr( "INPUT_VALID_DATA" );
858 if( !anErrorMsg.isEmpty() )
859 aMsg.prepend( anErrorMsg + "\n" );
860 SUIT_MessageBox::critical( module()->getApp()->desktop(),
861 tr( "INSUFFICIENT_INPUT_DATA" ),
866 void HYDROGUI_CalculationOp::onNext( const int theIndex )
870 setAvailableGroups();
872 else if( theIndex==2 )
875 HYDROGUI_CalculationDlg* aPanel =
876 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
881 QStringList anEntryList;
882 HYDROData_SequenceOfObjects aSeq;
884 Handle(HYDROData_StricklerTable) aStricklerTableObj;
885 QString aStricklerTableName;
887 // Get all Strickler table objects to fill in combo-box
890 HYDROData_Iterator anIter( doc(), KIND_STRICKLER_TABLE );
891 for ( ; anIter.More(); anIter.Next() )
893 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
895 if ( !aStricklerTableObj.IsNull() )
897 aStricklerTableName = aStricklerTableObj->GetName();
898 if ( !aStricklerTableName.isEmpty() )
900 aList.append( aStricklerTableName );
901 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
905 aPanel->setStricklerTableNames( aList, anEntryList );
906 if ( !aList.isEmpty() )
907 aPanel->setStricklerTable( aList.at( 0 ), false );
909 // Fill in list widget with all available land covers
910 aSeq = HYDROGUI_Tool::GetLandCovers( module() );
911 getNamesAndEntries( aSeq, aList, anEntryList );
912 aPanel->setAllLandCovers( aList, anEntryList );
914 // Set list of included land covers
915 aSeq = myEditedObject->GetLandCovers();
916 getNamesAndEntries( aSeq, aList, anEntryList );
917 aPanel->includeLandCovers( aList, true );
919 if ( !myEditedObject.IsNull() )
923 // Select the certain Strickler table object in combo-box
924 aStricklerTableObj = myEditedObject->GetStricklerTable();
925 if ( aStricklerTableObj.IsNull() )
927 aPanel->setStricklerTable( QString() );
931 aStricklerTableName = aStricklerTableObj->GetName();
932 aPanel->setStricklerTable( aStricklerTableName );
935 // Set mode (Auto or Manual) to defined priority of land covers
936 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
938 // Set rules defined on land covers
939 setRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
943 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getLandCoverMode() );
947 closePreview( false );
948 createPreview( true );
950 else if( theIndex==3 )
952 HYDROGUI_CalculationDlg* aPanel =
953 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
957 QApplication::setOverrideCursor( Qt::WaitCursor );
959 QString aNewCaseName = aPanel->getObjectName();
960 QString anOldCaseName = myEditedObject->GetName();
961 bool isNameChanged = anOldCaseName != aNewCaseName;
963 bool anIsToUpdateOb = isNameChanged;
965 // At first we must to update the case name because of
966 // automatic names generation for regions and zones
967 myEditedObject->SetName( aNewCaseName );
969 // Set parameters for automatic mode
970 int aMode = aPanel->getMode();
971 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
973 // Set objects in the specified order
974 if( myEditedObject->IsMustBeUpdated() )
976 myEditedObject->RemoveGeometryObjects();
977 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
979 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
980 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
981 if ( anObject.IsNull() )
985 myEditedObject->AddGeometryObject( anObject );
988 // Clear priority rules
989 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
990 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
992 // Set priority rules
993 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
994 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
995 aRule.Object2, aRule.MergeType,
996 HYDROData_CalculationCase::DataTag_CustomRules );
1000 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1002 if ( myEditedObject->IsMustBeUpdated() )
1005 myEditedObject->Update();
1007 AssignDefaultZonesColors( false );
1009 //aPanel->setEditedObject( myEditedObject );
1010 aPanel->refreshZonesBrowser();
1012 closePreview( false );
1013 createPreview( false );
1015 anIsToUpdateOb = true;
1017 myEditedObject->SetToUpdate( true );
1022 setZonesVisible( true, false );
1024 if ( isNameChanged ) {
1025 module()->getDataModel()->updateObjectTree( myEditedObject );
1029 QApplication::restoreOverrideCursor();
1031 else if( theIndex==4 )
1033 // Partition of Land covers panel
1034 HYDROGUI_CalculationDlg* aPanel =
1035 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1039 QApplication::setOverrideCursor( Qt::WaitCursor );
1041 // Set parameters for automatic mode
1042 int aMode = aPanel->getLandCoverMode();
1043 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1045 // Set objects in the specified order
1046 if( myEditedObject->IsMustBeUpdated() )
1048 myEditedObject->RemoveLandCovers();
1049 foreach ( const QString& aName, aPanel->getAllLandCovers() )
1051 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast(
1052 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1053 if ( aLandCover.IsNull() )
1057 myEditedObject->AddLandCover( aLandCover );
1060 // Clear priority rules
1061 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true );
1062 // Set priority rules
1063 foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) {
1064 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1065 aRule.Object2, HYDROData_Zone::Merge_Object,
1066 HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
1070 aPanel->setEditLandCoverZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1072 bool anIsToUpdateOb = false;
1073 bool anIsToUpdate = myEditedObject->IsMustBeUpdated();
1077 myEditedObject->Update();
1079 AssignDefaultZonesColors( true );
1081 aPanel->refreshLandCoverZonesBrowser();
1083 anIsToUpdateOb = true;
1086 closePreview( false );
1087 createPreview( true );
1089 if ( !anIsToUpdate )
1092 setZonesVisible( false, false );
1093 // Show land cover zones
1094 setZonesVisible( true, true );
1097 if ( anIsToUpdateOb ) {
1098 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
1099 if ( anObjBrowser ) {
1100 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
1104 QApplication::restoreOverrideCursor();
1108 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
1112 closePreview( false );
1113 createPreview( false );
1117 closePreview( false );
1118 createPreview( true );
1121 setZonesVisible( false, false );
1123 setZonesVisible( false, true );
1125 else if( theIndex==3 )
1127 AssignDefaultZonesColors( false );
1129 closePreview( false );
1130 createPreview( false );
1132 // Hide land cover zones
1133 setZonesVisible( false, true );
1135 setZonesVisible( true, false );
1139 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible, const bool theLandCover )
1141 myShowZones = theIsVisible;
1142 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1143 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1144 HYDROData_SequenceOfObjects aZones;
1145 Handle(HYDROData_Region) aRegion;
1146 if ( myPreviewViewManager )
1148 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1150 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1151 if ( !aCtx.IsNull() )
1153 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1155 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1156 if ( !aRegion.IsNull() )
1158 aZones = aRegion->GetZones();
1159 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1160 for ( ; aZonesIter.More(); aZonesIter.Next() )
1162 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1168 module()->update( UF_OCCViewer );
1173 void HYDROGUI_CalculationOp::AssignDefaultZonesColors( const bool theLandCover )
1175 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1176 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1177 HYDROData_SequenceOfObjects aZones;
1178 Handle(HYDROData_Region) aRegion;
1179 if ( myPreviewViewManager )
1181 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1183 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1184 if ( !aCtx.IsNull() )
1187 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1189 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1190 if ( !aRegion.IsNull() )
1192 aZones = aRegion->GetZones();
1193 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1194 for ( ; aZonesIter.More(); aZonesIter.Next() )
1197 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1198 if ( !aZone.IsNull() )
1200 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
1201 while (aFillingColor == Qt::red)
1202 aFillingColor = GenerateDefaultZonesColor(++aCounter);
1204 aZone->SetColor(aFillingColor);
1214 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
1215 float theSaturation/* = 0.5*/,
1216 float theValue/* = 0.95*/ ) const
1218 float aGoldenRatioConjugate = (float)(360./582.);
1219 float aHue = (float)(rand()%100);
1220 aHue += aGoldenRatioConjugate*theIndex;
1221 aHue -= floor(aHue);
1223 float aR = 0., aG = 0., aB = 0.;
1224 int aHueInt = (int)(aHue*6.);
1225 float aF = aHue*6. - aHueInt;
1226 float aP = theValue * (1. - theSaturation);
1227 float aQ = theValue * (1. - aF*theSaturation);
1228 float aT = theValue * (1. - (1. - aF) * theSaturation);
1231 case 0: { aR = theValue; aG = aT; aB = aP; break; }
1232 case 1: { aR = aQ; aG = theValue; aB = aP; break; }
1233 case 2: { aR = aP; aG = theValue; aB = aT; break; }
1234 case 3: { aR = aP; aG = aQ; aB = theValue; break; }
1235 case 4: { aR = aT; aG = aP; aB = theValue; break; }
1236 case 5: { aR = theValue; aG = aP; aB = aQ; break; }
1240 QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
1241 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
1244 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1246 HYDROGUI_CalculationDlg* aPanel =
1247 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1251 HYDROData_ListOfRules aRules;
1252 Handle(HYDROData_Entity) anObject1, anObject2;
1253 HYDROData_PriorityType aPriority;
1254 HYDROData_Zone::MergeType aMergeType;
1255 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1256 for ( int anIndex = 0; ; anIndex++ )
1258 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1259 HYDROData_CustomRule aRule;
1260 aRule.Object1 = anObject1;
1261 aRule.Object2 = anObject2;
1262 aRule.Priority = aPriority;
1263 aRule.MergeType = aMergeType;
1271 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1272 aPanel->setRules( aRules );
1273 else if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomLandCoverRules )
1274 aPanel->setLandCoverRules( aRules );
1277 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList,
1278 const bool theLandCover )
1280 bool aRetValue = false;
1282 QList<HYDROGUI_Zone*> aZonesList;
1283 HYDROGUI_Zone* aZone;
1284 // Get a list of dropped zones
1285 for ( int i = 0; i < theZonesList.length(); i++ )
1287 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1290 aZonesList.append( aZone );
1293 if ( aZonesList.length() > 0 )
1295 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList, theLandCover );
1302 void HYDROGUI_CalculationOp::createPreview( const bool theLandCover )
1304 LightApp_Application* anApp = module()->getApp();
1305 HYDROData_SequenceOfObjects aSeq;
1307 aSeq = myEditedObject->GetLandCovers();
1309 aSeq = myEditedObject->GetGeometryObjects();
1311 Handle(HYDROData_Entity) anEntity;
1315 // Gather zones for displaying
1316 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1317 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1318 HYDROData_SequenceOfObjects aZones;
1319 Handle(HYDROData_Region) aRegion;
1320 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1322 anEntity = aRegionsIter.Value();
1323 if ( !anEntity.IsNull() )
1325 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1326 if ( !aRegion.IsNull() )
1328 aZones = aRegion->GetZones();
1329 aSeq.Append( aZones );
1335 // Get a boundary polyline if any
1336 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
1338 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1340 if ( !myActiveViewManager )
1342 if ( aSeq.IsEmpty() )
1345 myActiveViewManager = anApp->activeViewManager();
1348 if ( !myPreviewViewManager )
1350 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1351 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1352 if ( myPreviewViewManager )
1354 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1355 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1357 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1358 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1362 if ( !myPreviewViewManager )
1365 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1367 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1368 if ( !aCtx.IsNull() )
1370 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1371 for ( ; anIter.More(); anIter.Next() )
1373 setObjectVisibility( anIter.Value(), true );
1376 //Process the draw events for viewer
1377 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1378 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
1382 module()->update( UF_OCCViewer | UF_FitAll );
1386 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1388 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1392 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1394 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1398 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1403 void HYDROGUI_CalculationOp::closePreview( bool theRemoveViewManager )
1405 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1406 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1407 QShortcut* aShortcut;
1408 foreach( aShortcut, aShortcuts )
1410 if ( aShortcut->key() ==
1411 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1412 SUIT_DataBrowser::RenameShortcut ) ) )
1414 aShortcut->setEnabled( true );
1419 if( myPreviewViewManager )
1421 // Hide all the displayed objects in the preview view
1422 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1424 size_t aViewId = (size_t)aViewer;
1425 HYDROData_Iterator anIterator( doc() );
1426 for( ; anIterator.More(); anIterator.Next() ) {
1427 Handle(HYDROData_Entity) anObject = anIterator.Current();
1428 if( !anObject.IsNull() ) {
1429 module()->setObjectVisible( aViewId, anObject, false );
1434 if ( theRemoveViewManager )
1436 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1437 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1439 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1440 myPreviewViewManager = NULL;
1444 if( myActiveViewManager && theRemoveViewManager )
1446 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1447 myActiveViewManager = NULL;
1451 void HYDROGUI_CalculationOp::setAvailableGroups()
1453 HYDROGUI_CalculationDlg* aPanel =
1454 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1456 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1457 QStringList aList, anEntryList;
1458 getNamesAndEntries( aSeq, aList, anEntryList );
1460 QStringList aGroupsNames;
1462 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1463 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1465 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1466 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1467 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1469 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1470 aGroupsNames.append( aGroup->GetName() );
1473 if( myEditedObject->IsMustBeUpdated() ) {
1474 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1475 Handle(HYDROData_ShapesGroup) aGeomGroup =
1476 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1477 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1478 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1483 aPanel->setAvailableGroups( aGroupsNames );
1484 aPanel->includeGroups( aList );
1486 bool isUpdated = myEditedObject->IsMustBeUpdated();
1489 void HYDROGUI_CalculationOp::onAddGroups()
1491 HYDROGUI_CalculationDlg* aPanel =
1492 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1496 // Add geometry objects selected in the module browser to the calculation case
1497 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1498 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1501 QStringList anAddedList;
1502 for (int i = 0; i < aSelectedList.length(); i++)
1504 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1505 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1506 if ( aGroup.IsNull() )
1509 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1510 anAddedList.append( aGroup->GetName() );
1513 if ( !anAddedList.isEmpty() )
1515 aPanel->includeGroups( anAddedList );
1519 void HYDROGUI_CalculationOp::onRemoveGroups()
1521 // Remove selected objects from the calculation case
1522 HYDROGUI_CalculationDlg* aPanel =
1523 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1527 QStringList aSelectedList = aPanel->getSelectedGroups();
1528 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1531 for (int i = 0; i < aSelectedList.length(); i++)
1533 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1534 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1535 if ( aGroup.IsNull() )
1538 myEditedObject->RemoveGeometryGroup( aGroup );
1541 aPanel->excludeGroups( aSelectedList );
1544 void HYDROGUI_CalculationOp::onChangeLandCoverMode( int theMode )
1546 HYDROGUI_CalculationDlg* aPanel =
1547 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1551 if ( !confirmLandCoverModeChange() ) {
1552 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
1556 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1557 aPanel->setLandCoverMode( theMode );
1560 void HYDROGUI_CalculationOp::onAddLandCovers()
1562 HYDROGUI_CalculationDlg* aPanel =
1563 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1567 // Add land covers selected in the module browser to the calculation case
1568 QStringList aSelectedList = aPanel->getSelectedAvailableLandCovers();
1569 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1572 QStringList anAddedList;
1573 for (int i = 0; i < aSelectedList.length(); i++)
1575 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1576 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1577 if ( anObject.IsNull() )
1580 if ( myEditedObject->AddLandCover( anObject ) )
1581 anAddedList.append( anObject->GetName() );
1584 if ( !anAddedList.isEmpty() )
1586 aPanel->includeLandCovers( anAddedList, false );
1587 createPreview( true );
1591 void HYDROGUI_CalculationOp::onRemoveLandCovers()
1593 // Remove selected objects from the calculation case
1594 HYDROGUI_CalculationDlg* aPanel =
1595 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1599 QStringList aSelectedList = aPanel->getSelectedLandCovers();
1600 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1603 for (int i = 0; i < aSelectedList.length(); i++)
1605 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1606 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1607 if ( anObject.IsNull() )
1610 setObjectVisibility( anObject, false );
1611 myEditedObject->RemoveLandCover( anObject );
1614 module()->update( UF_OCCViewer );
1615 aPanel->excludeLandCovers( aSelectedList );
1618 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1620 HYDROGUI_CalculationDlg* aPanel =
1621 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1625 if ( !confirmModeChange() ) {
1626 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1630 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1631 aPanel->setMode( theMode );
1634 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1636 HYDROGUI_CalculationDlg* aPanel =
1637 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1641 isConfirmed = confirmOrderChange();
1643 myEditedObject->SetToUpdate( true );
1646 void HYDROGUI_CalculationOp::onOrderLandCoverChanged( bool& isConfirmed )
1648 HYDROGUI_CalculationDlg* aPanel =
1649 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1653 isConfirmed = confirmLandCoverOrderChange();
1655 myEditedObject->SetToUpdate( true );