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 ),
60 myShowLandCovers( false ),
63 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
66 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
71 void HYDROGUI_CalculationOp::startOperation()
73 HYDROGUI_Operation::startOperation();
78 HYDROGUI_CalculationDlg* aPanel =
79 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
83 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
84 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
86 foreach( aShortcut, aShortcuts )
88 if ( aShortcut->key() ==
89 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
90 SUIT_DataBrowser::RenameShortcut ) ) )
92 aShortcut->setEnabled( false );
98 QStringList anEntryList;
99 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
100 getNamesAndEntries( aSeq, aList, anEntryList );
101 aPanel->setAllGeomObjects( aList, anEntryList );
106 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
107 Handle(HYDROData_PolylineXY) aPolylineObj;
108 QString aPolylineName;
109 for ( ; anIter.More(); anIter.Next() )
111 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
113 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
115 // Check the polyline shape
116 TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
117 if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
118 aPolylineName = aPolylineObj->GetName();
119 if ( !aPolylineName.isEmpty() )
121 aList.append( aPolylineName );
122 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
127 aPanel->setPolylineNames( aList, anEntryList );
129 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
131 myEditedObject.Nullify();
134 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
135 if ( !myEditedObject.IsNull() )
137 aPanel->setMode( myEditedObject->GetAssignmentMode() );
138 anObjectName = myEditedObject->GetName();
139 aPolylineObj = myEditedObject->GetBoundaryPolyline();
140 if ( aPolylineObj.IsNull() )
142 aPanel->setBoundary( QString() );
146 aPolylineName = aPolylineObj->GetName();
147 aPanel->setBoundary( aPolylineName );
150 aSeq = myEditedObject->GetGeometryObjects();
151 getNamesAndEntries( aSeq, aList, anEntryList );
152 aPanel->includeGeomObjects( aList );
155 setRules( HYDROData_CalculationCase::DataTag_CustomRules );
161 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
162 myEditedObject->SetName( anObjectName );
163 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
166 aPanel->setObjectName( anObjectName );
167 aPanel->setEditedObject( myEditedObject );
169 createPreview( false );
172 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
173 QStringList& theNames, QStringList& theEntries ) const
178 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
179 for ( ; anIter.More(); anIter.Next() )
181 Handle(HYDROData_Entity) anEntity = anIter.Value();
182 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
185 theNames.append( anEntity->GetName() );
186 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
190 void HYDROGUI_CalculationOp::abortOperation()
195 HYDROGUI_Operation::abortOperation();
196 module()->getApp()->updateObjectBrowser();
199 void HYDROGUI_CalculationOp::commitOperation()
202 // Commit transaction
203 commitDocOperation();
204 HYDROGUI_Operation::commitOperation();
207 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
209 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
211 // Connect signals and slots
212 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
213 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
214 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
215 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
216 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
218 connect( aPanel, SIGNAL( changeLandCoverMode( int ) ), SLOT( onChangeLandCoverMode( int ) ) );
219 connect( aPanel, SIGNAL( addLandCovers() ), SLOT( onAddLandCovers() ) );
220 connect( aPanel, SIGNAL( removeLandCovers() ), SLOT( onRemoveLandCovers() ) );
222 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
223 connect( aPanel, SIGNAL( orderLandCoverChanged( bool& ) ), SLOT( onOrderLandCoverChanged( bool& ) ) );
225 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
226 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones( const int ) ) );
227 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
228 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
229 connect( aPanel, SIGNAL( setMergeStricklerType( int, QString& ) ), SLOT( onSetMergeStricklerType( int, QString& ) ) );
230 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>&, bool ) ),
231 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>&, bool ) ) );
232 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
233 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
234 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
235 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
236 connect( aPanel, SIGNAL( objectsSelected() ),
237 SLOT( onObjectsSelected() ) );
238 connect( aPanel, SIGNAL( landCoversSelected() ),
239 SLOT( onLandCoversSelected() ) );
240 connect( aPanel, SIGNAL( createLandCoverRegion( const QList<SUIT_DataObject*>& ) ),
241 SLOT( onCreateLandCoverRegion( const QList<SUIT_DataObject*>& ) ) );
242 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
243 SLOT( onBoundarySelected( const QString & ) ) );
244 connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
245 SLOT( onStricklerTableSelected( const QString & ) ) );
250 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
252 bool anIsToUpdateViewer = false;
254 // Remove the old boundary from the operation viewer
255 Handle(HYDROData_PolylineXY) aPrevPolyline =
256 myEditedObject->GetBoundaryPolyline();
257 if ( !aPrevPolyline.IsNull() )
259 setObjectVisibility( aPrevPolyline, false );
260 anIsToUpdateViewer = true;
263 // Set the selected boundary polyline to the calculation case
264 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
265 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
266 myEditedObject->SetBoundaryPolyline( aNewPolyline );
268 if ( myPreviewViewManager )
270 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
273 if ( !aNewPolyline.IsNull() )
275 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
276 if ( !aCtx.IsNull() )
278 setObjectVisibility( aNewPolyline, true );
279 anIsToUpdateViewer = true;
283 if ( anIsToUpdateViewer )
284 module()->update( UF_OCCViewer );
289 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
291 bool anIsToUpdateViewer = false;
293 // Remove old presentations of land covers from the operation viewer
294 Handle(HYDROData_Entity) anEntity;
295 Handle(HYDROData_LandCover) aLandCover;
296 HYDROData_SequenceOfObjects aLandCovers;
297 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
298 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
299 for ( ; anIter.More(); anIter.Next() )
301 anEntity = anIter.Value();
302 if ( !anEntity.IsNull() )
304 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
305 if ( !aLandCover.IsNull() )
307 aLandCovers.Append( aLandCover );
308 setObjectVisibility( aLandCover, false );
309 anIsToUpdateViewer = true;
314 // Set the selected Strickler table to the calculation case
315 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
316 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
317 myEditedObject->SetStricklerTable( aNewStricklerTable );
319 if ( myPreviewViewManager )
321 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
324 if ( !aNewStricklerTable.IsNull() )
326 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
327 if ( !aCtx.IsNull() )
329 HYDROData_SequenceOfObjects::Iterator anIter( aLandCovers );
330 for ( ; anIter.More(); anIter.Next() )
332 anEntity = anIter.Value();
333 if ( !anEntity.IsNull() )
335 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
336 if ( !aLandCover.IsNull() )
338 setObjectVisibility( aLandCover, true );
339 anIsToUpdateViewer = true;
346 if ( anIsToUpdateViewer )
347 module()->update( UF_OCCViewer );
352 void HYDROGUI_CalculationOp::onObjectsSelected()
354 HYDROGUI_CalculationDlg* aPanel =
355 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
357 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
358 QMap<QString, bool> aSelectedObjsMap;
359 foreach( QString aName, aSelectedObjs )
360 aSelectedObjsMap[aName] = true;
363 // Select the appropriate geometry object shape in the viewer
364 selectionMgr()->clearSelected();
366 // Unhighlight all objects except selected
367 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
368 Handle(HYDROData_Entity) anEntity;
369 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
370 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
373 for ( ; anIter.More(); anIter.Next() )
375 anEntity = anIter.Value();
376 if ( !anEntity.IsNull() )
378 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
381 aName = anEntity->GetName();
382 isSelected = aSelectedObjsMap.contains( aName );
383 aShape->highlight( isSelected, false );
384 aShape->update( false, false );
390 aLastShape->update( true, false );
393 void HYDROGUI_CalculationOp::onLandCoversSelected()
395 HYDROGUI_CalculationDlg* aPanel =
396 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
398 QStringList aSelectedObjs = aPanel->getSelectedLandCovers();
399 QMap<QString, bool> aSelectedObjsMap;
400 foreach( QString aName, aSelectedObjs )
401 aSelectedObjsMap[aName] = true;
404 // Select the appropriate land cover shape in the viewer
405 selectionMgr()->clearSelected();
407 // Unhighlight all land covers except selected
408 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
409 Handle(HYDROData_Entity) anEntity;
410 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
411 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
414 for ( ; anIter.More(); anIter.Next() )
416 anEntity = anIter.Value();
417 if ( !anEntity.IsNull() )
419 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
422 aName = anEntity->GetName();
423 isSelected = aSelectedObjsMap.contains( aName );
424 aShape->highlight( isSelected, false );
425 aShape->update( false, false );
431 aLastShape->update( true, false );
434 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
436 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
437 HYDROGUI_Zone* aZoneItem;
438 selectionMgr()->clearSelected();
441 // Select a region in preview
442 SUIT_DataOwnerPtrList aList( true );
443 DataObjectList aZones = aRegionItem->children();
444 for ( int i = 0; i < aZones.length(); i++ )
446 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
449 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
452 selectionMgr()->setSelected( aList );
456 // select a single zone
457 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
460 SUIT_DataOwnerPtrList aList( true );
461 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
462 selectionMgr()->setSelected( aList );
467 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem,
468 const QList<SUIT_DataObject*>& theZonesList,
471 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
474 QList<HYDROGUI_Zone*> aZonesList;
475 HYDROGUI_Zone* aZone;
476 // Get a list of dropped zones
477 for ( int i = 0; i < theZonesList.length(); i++ )
479 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
482 aZonesList.append( aZone );
485 if ( aZonesList.length() > 0 )
487 aRegion->addZones( aZonesList );
488 HYDROGUI_CalculationDlg* aPanel =
489 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
492 theLandCover ? aPanel->refreshLandCoverZonesBrowser(): aPanel->refreshZonesBrowser();
494 createPreview( theLandCover );
499 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
501 if ( createRegion( theZonesList, false ) )
503 HYDROGUI_CalculationDlg* aPanel =
504 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
507 aPanel->refreshZonesBrowser();
509 createPreview( false );
513 void HYDROGUI_CalculationOp::onCreateLandCoverRegion( const QList<SUIT_DataObject*>& theZonesList )
515 if ( createRegion( theZonesList, true ) )
517 HYDROGUI_CalculationDlg* aPanel =
518 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
521 aPanel->refreshLandCoverZonesBrowser();
523 createPreview( true );
527 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theMergeObjectName )
529 HYDROGUI_CalculationDlg* aPanel =
530 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
533 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
536 aZone->setMergeType( theMergeType, theMergeObjectName );
537 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
540 aShape->update( true, false );
543 aPanel->refreshZonesBrowser();
547 void HYDROGUI_CalculationOp::onSetMergeStricklerType( int theMergeType, QString& theStricklerTypeName )
549 HYDROGUI_CalculationDlg* aPanel =
550 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
553 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
556 aZone->setMergeType( theMergeType, theStricklerTypeName );
557 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
560 aShape->update( true, false );
563 aPanel->refreshLandCoverZonesBrowser();
567 void HYDROGUI_CalculationOp::onAddObjects()
569 HYDROGUI_CalculationDlg* aPanel =
570 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
574 // Add geometry objects selected in the module browser to the calculation case
575 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
576 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
579 QStringList anAddedList;
580 for (int i = 0; i < aSelectedList.length(); i++)
582 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
583 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
584 if ( anObject.IsNull() )
587 if ( myEditedObject->AddGeometryObject( anObject ) )
588 anAddedList.append( anObject->GetName() );
591 if ( !anAddedList.isEmpty() )
593 aPanel->includeGeomObjects( anAddedList );
594 createPreview( false );
598 void HYDROGUI_CalculationOp::onRemoveObjects()
600 // Remove selected objects from the calculation case
601 HYDROGUI_CalculationDlg* aPanel =
602 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
606 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
607 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
610 for (int i = 0; i < aSelectedList.length(); i++)
612 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
613 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
614 if ( anObject.IsNull() )
617 setObjectVisibility( anObject, false );
618 myEditedObject->RemoveGeometryObject( anObject );
621 module()->update( UF_OCCViewer );
622 aPanel->excludeGeomObjects( aSelectedList );
625 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
627 // Check if the case is already modified or not
628 bool isConfirmed = myEditedObject->IsMustBeUpdated();
631 // If not modified check if the case has already defined regions with zones
632 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
633 if ( aSeq.Length() > 0 )
635 // If there are already defined zones then ask a user to confirm zones recalculation
636 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
637 tr( "REGIONS_CHANGED" ),
638 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
639 QMessageBox::Yes | QMessageBox::No,
640 QMessageBox::No ) == QMessageBox::Yes );
644 isConfirmed = true; // No regions - no zones - nothing to recalculate
650 bool HYDROGUI_CalculationOp::confirmOrderChange() const
652 // Check if the case is already modified or not
653 bool isConfirmed = myEditedObject->IsMustBeUpdated();
656 // If not modified check if the case has already defined regions with zones
657 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
658 if ( aSeq.Length() > 0 )
660 // If there are already defined zones then ask a user to confirm zones recalculation
661 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
662 tr( "ORDER_CHANGED" ),
663 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
664 QMessageBox::Yes | QMessageBox::No,
665 QMessageBox::No ) == QMessageBox::Yes );
669 isConfirmed = true; // No regions - no zones - nothing to recalculate
675 bool HYDROGUI_CalculationOp::confirmModeChange() const
677 // Check if the case is already modified or not
678 bool isConfirmed = myEditedObject->IsMustBeUpdated();
681 // If not modified check if the case has already defined regions with zones
682 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
683 if ( aSeq.Length() > 0 )
685 // If there are already defined zones then ask a user to confirm zones recalculation
686 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
687 tr( "MODE_CHANGED" ),
688 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
689 QMessageBox::Yes | QMessageBox::No,
690 QMessageBox::No ) == QMessageBox::Yes );
694 isConfirmed = true; // No regions - no zones - nothing to recalculate
700 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
702 HYDROData_WarningType aType = theWarning.Type;
703 if ( aType == WARN_OK ) {
711 case WARN_EMPTY_REGIONS:
712 aTitle = tr( "EMPTY_REGIONS" );
713 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
716 aTitle = tr( "WARNING" );
717 aMsg = theWarning.Data;
721 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
723 QMessageBox::Yes | QMessageBox::No,
726 return ( anAnswer == QMessageBox::Yes );
729 bool HYDROGUI_CalculationOp::confirmLandCoverModeChange() const
731 // Check if the case is already modified or not
732 bool isConfirmed = myEditedObject->IsMustBeUpdated();
735 // If not modified check if the case has already defined regions with zones
736 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
737 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
738 if ( aSeq.Length() > 0 )
740 // If there are already defined zones then ask a user to confirm zones recalculation
741 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
742 tr( "MODE_CHANGED" ),
743 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_MODE" ),
744 QMessageBox::Yes | QMessageBox::No,
745 QMessageBox::No ) == QMessageBox::Yes );
749 isConfirmed = true; // No regions - no zones - nothing to recalculate
755 bool HYDROGUI_CalculationOp::confirmLandCoverOrderChange() const
757 // Check if the case is already modified or not
758 bool isConfirmed = myEditedObject->IsMustBeUpdated();
761 // If not modified check if the case has already defined regions with zones
762 // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers
763 /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions();
764 if ( aSeq.Length() > 0 )
766 // If there are already defined zones then ask a user to confirm zones recalculation
767 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
768 tr( "ORDER_CHANGED" ),
769 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
770 QMessageBox::Yes | QMessageBox::No,
771 QMessageBox::No ) == QMessageBox::Yes );
775 isConfirmed = true; // No regions - no zones - nothing to recalculate
781 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
782 QString& theErrorMsg,
783 QStringList& theBrowseObjectsEntries )
785 HYDROGUI_CalculationDlg* aPanel =
786 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
792 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
793 theBrowseObjectsEntries.append( anEntry );
796 // For manual mode priority rules are redundant
797 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
798 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
800 if ( aPanel->getLandCoverMode() == HYDROData_CalculationCase::MANUAL ) {
801 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, false );
804 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
809 void HYDROGUI_CalculationOp::onApply()
812 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
813 if ( aWarning.Type != WARN_OK ) {
814 if ( !confirmContinueWithWarning( aWarning ) ) {
815 // Go back to the first page
816 HYDROGUI_CalculationDlg* aPanel =
817 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
819 aPanel->onFirstPage();
825 QApplication::setOverrideCursor( Qt::WaitCursor );
827 int anUpdateFlags = 0;
829 QStringList aBrowseObjectsEntries;
831 bool aResult = false;
835 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
837 catch ( Standard_Failure )
839 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
840 anErrorMsg = aFailure->GetMessageString();
848 QApplication::restoreOverrideCursor();
852 module()->update( anUpdateFlags );
854 browseObjects( aBrowseObjectsEntries );
859 QString aMsg = tr( "INPUT_VALID_DATA" );
860 if( !anErrorMsg.isEmpty() )
861 aMsg.prepend( anErrorMsg + "\n" );
862 SUIT_MessageBox::critical( module()->getApp()->desktop(),
863 tr( "INSUFFICIENT_INPUT_DATA" ),
868 void HYDROGUI_CalculationOp::onNext( const int theIndex )
872 setAvailableGroups();
874 else if( theIndex==2 )
877 HYDROGUI_CalculationDlg* aPanel =
878 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
882 setLandCoversVisible( true );
885 QStringList anEntryList;
886 HYDROData_SequenceOfObjects aSeq;
888 Handle(HYDROData_StricklerTable) aStricklerTableObj;
889 QString aStricklerTableName;
891 // Get all Strickler table objects to fill in combo-box
894 HYDROData_Iterator anIter( doc(), KIND_STRICKLER_TABLE );
895 for ( ; anIter.More(); anIter.Next() )
897 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
899 if ( !aStricklerTableObj.IsNull() )
901 aStricklerTableName = aStricklerTableObj->GetName();
902 if ( !aStricklerTableName.isEmpty() )
904 aList.append( aStricklerTableName );
905 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
909 aPanel->setStricklerTableNames( aList, anEntryList );
910 if ( !aList.isEmpty() )
911 aPanel->setStricklerTable( aList.at( 0 ), false );
913 // Fill in list widget with all available land covers
914 aSeq = HYDROGUI_Tool::GetLandCovers( module() );
915 getNamesAndEntries( aSeq, aList, anEntryList );
916 aPanel->setAllLandCovers( aList, anEntryList );
918 // Set list of included land covers
919 aSeq = myEditedObject->GetLandCovers();
920 getNamesAndEntries( aSeq, aList, anEntryList );
921 aPanel->includeLandCovers( aList, true );
923 if ( !myEditedObject.IsNull() )
927 // Select the certain Strickler table object in combo-box
928 aStricklerTableObj = myEditedObject->GetStricklerTable();
929 if ( aStricklerTableObj.IsNull() )
931 aPanel->setStricklerTable( QString() );
935 aStricklerTableName = aStricklerTableObj->GetName();
936 aPanel->setStricklerTable( aStricklerTableName );
939 // Set mode (Auto or Manual) to defined priority of land covers
940 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
942 // Set rules defined on land covers
943 setRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
947 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getLandCoverMode() );
951 closePreview( false );
952 createPreview( true );
954 else if( theIndex==3 )
956 HYDROGUI_CalculationDlg* aPanel =
957 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
961 QApplication::setOverrideCursor( Qt::WaitCursor );
963 setGeomObjectsVisible( false );
964 setLandCoversVisible( false );
966 QString aNewCaseName = aPanel->getObjectName();
967 QString anOldCaseName = myEditedObject->GetName();
968 bool isNameChanged = anOldCaseName != aNewCaseName;
970 bool anIsToUpdateOb = isNameChanged;
972 // At first we must to update the case name because of
973 // automatic names generation for regions and zones
974 myEditedObject->SetName( aNewCaseName );
976 // Set parameters for automatic mode
977 int aMode = aPanel->getMode();
978 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
980 // Set objects in the specified order
981 if( myEditedObject->IsMustBeUpdated() )
983 myEditedObject->RemoveGeometryObjects();
984 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
986 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
987 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
988 if ( anObject.IsNull() )
992 myEditedObject->AddGeometryObject( anObject );
995 // Clear priority rules
996 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
997 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
999 // Set priority rules
1000 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
1001 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1002 aRule.Object2, aRule.MergeType,
1003 HYDROData_CalculationCase::DataTag_CustomRules );
1007 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1009 if ( myEditedObject->IsMustBeUpdated() )
1012 myEditedObject->Update();
1014 AssignDefaultZonesColors( false );
1016 //aPanel->setEditedObject( myEditedObject );
1017 aPanel->refreshZonesBrowser();
1019 closePreview( false );
1020 createPreview( false );
1022 anIsToUpdateOb = true;
1024 myEditedObject->SetToUpdate( true );
1029 setZonesVisible( true, false );
1031 if ( isNameChanged ) {
1032 module()->getDataModel()->updateObjectTree( myEditedObject );
1036 QApplication::restoreOverrideCursor();
1038 else if( theIndex==4 )
1040 // Partition of Land covers panel
1041 HYDROGUI_CalculationDlg* aPanel =
1042 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1046 QApplication::setOverrideCursor( Qt::WaitCursor );
1048 // Set parameters for automatic mode
1049 int aMode = aPanel->getLandCoverMode();
1050 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1052 // Set objects in the specified order
1053 if( myEditedObject->IsMustBeUpdated() )
1055 myEditedObject->RemoveLandCovers();
1056 foreach ( const QString& aName, aPanel->getAllLandCovers() )
1058 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast(
1059 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1060 if ( aLandCover.IsNull() )
1064 myEditedObject->AddLandCover( aLandCover );
1067 // Clear priority rules
1068 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true );
1069 // Set priority rules
1070 foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) {
1071 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1072 aRule.Object2, HYDROData_Zone::Merge_Object,
1073 HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
1077 aPanel->setEditLandCoverZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1079 bool anIsToUpdateOb = false;
1080 bool anIsToUpdate = myEditedObject->IsMustBeUpdated();
1084 myEditedObject->Update();
1086 AssignDefaultZonesColors( true );
1088 aPanel->refreshLandCoverZonesBrowser();
1090 anIsToUpdateOb = true;
1093 closePreview( false );
1094 createPreview( true );
1096 if ( !anIsToUpdate )
1099 setZonesVisible( false, false );
1100 // Show land cover zones
1101 setZonesVisible( true, true );
1104 if ( anIsToUpdateOb ) {
1105 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
1106 if ( anObjBrowser ) {
1107 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
1111 QApplication::restoreOverrideCursor();
1115 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
1119 setGeomObjectsVisible( true );
1121 closePreview( false );
1122 createPreview( false );
1126 setLandCoversVisible( true );
1128 closePreview( false );
1129 createPreview( true );
1132 setZonesVisible( false, false );
1134 setZonesVisible( false, true );
1136 else if( theIndex==3 )
1138 AssignDefaultZonesColors( false );
1140 closePreview( false );
1141 createPreview( false );
1143 // Hide land cover zones
1144 setZonesVisible( false, true );
1146 setZonesVisible( true, false );
1150 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible, const bool theLandCover )
1152 myShowZones = theIsVisible;
1153 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1154 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1155 HYDROData_SequenceOfObjects aZones;
1156 Handle(HYDROData_Region) aRegion;
1157 if ( myPreviewViewManager )
1159 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1161 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1162 if ( !aCtx.IsNull() )
1164 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1166 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1167 if ( !aRegion.IsNull() )
1169 aZones = aRegion->GetZones();
1170 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1171 for ( ; aZonesIter.More(); aZonesIter.Next() )
1173 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1179 module()->update( UF_OCCViewer );
1184 void HYDROGUI_CalculationOp::setGeomObjectsVisible( bool theIsVisible )
1186 myShowGeomObjects = theIsVisible;
1188 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
1190 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1191 for ( ; anIter.More(); anIter.Next() ) {
1192 setObjectVisibility( anIter.Value(), theIsVisible );
1196 void HYDROGUI_CalculationOp::setLandCoversVisible( bool theIsVisible )
1198 myShowLandCovers = theIsVisible;
1200 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
1202 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1203 for ( ; anIter.More(); anIter.Next() ) {
1204 setObjectVisibility( anIter.Value(), theIsVisible );
1208 void HYDROGUI_CalculationOp::AssignDefaultZonesColors( const bool theLandCover )
1210 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1211 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1212 HYDROData_SequenceOfObjects aZones;
1213 Handle(HYDROData_Region) aRegion;
1214 if ( myPreviewViewManager )
1216 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1218 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1219 if ( !aCtx.IsNull() )
1222 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1224 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1225 if ( !aRegion.IsNull() )
1227 aZones = aRegion->GetZones();
1228 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1229 for ( ; aZonesIter.More(); aZonesIter.Next() )
1232 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1233 if ( !aZone.IsNull() )
1235 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
1236 while (aFillingColor == Qt::red)
1237 aFillingColor = GenerateDefaultZonesColor(++aCounter);
1239 aZone->SetColor(aFillingColor);
1249 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
1250 float theSaturation/* = 0.5*/,
1251 float theValue/* = 0.95*/ ) const
1253 float aGoldenRatioConjugate = (float)(360./582.);
1254 float aHue = (float)(rand()%100);
1255 aHue += aGoldenRatioConjugate*theIndex;
1256 aHue -= floor(aHue);
1258 float aR = 0., aG = 0., aB = 0.;
1259 int aHueInt = (int)(aHue*6.);
1260 float aF = aHue*6. - aHueInt;
1261 float aP = theValue * (1. - theSaturation);
1262 float aQ = theValue * (1. - aF*theSaturation);
1263 float aT = theValue * (1. - (1. - aF) * theSaturation);
1266 case 0: { aR = theValue; aG = aT; aB = aP; break; }
1267 case 1: { aR = aQ; aG = theValue; aB = aP; break; }
1268 case 2: { aR = aP; aG = theValue; aB = aT; break; }
1269 case 3: { aR = aP; aG = aQ; aB = theValue; break; }
1270 case 4: { aR = aT; aG = aP; aB = theValue; break; }
1271 case 5: { aR = theValue; aG = aP; aB = aQ; break; }
1275 QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
1276 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
1279 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1281 HYDROGUI_CalculationDlg* aPanel =
1282 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1286 HYDROData_ListOfRules aRules;
1287 Handle(HYDROData_Entity) anObject1, anObject2;
1288 HYDROData_PriorityType aPriority;
1289 HYDROData_Zone::MergeType aMergeType;
1290 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1291 for ( int anIndex = 0; ; anIndex++ )
1293 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1294 HYDROData_CustomRule aRule;
1295 aRule.Object1 = anObject1;
1296 aRule.Object2 = anObject2;
1297 aRule.Priority = aPriority;
1298 aRule.MergeType = aMergeType;
1306 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1307 aPanel->setRules( aRules );
1308 else if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomLandCoverRules )
1309 aPanel->setLandCoverRules( aRules );
1312 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList,
1313 const bool theLandCover )
1315 bool aRetValue = false;
1317 QList<HYDROGUI_Zone*> aZonesList;
1318 HYDROGUI_Zone* aZone;
1319 // Get a list of dropped zones
1320 for ( int i = 0; i < theZonesList.length(); i++ )
1322 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1325 aZonesList.append( aZone );
1328 if ( aZonesList.length() > 0 )
1330 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList, theLandCover );
1337 void HYDROGUI_CalculationOp::createPreview( const bool theLandCover )
1339 LightApp_Application* anApp = module()->getApp();
1340 HYDROData_SequenceOfObjects aSeq;
1341 if ( theLandCover && myShowLandCovers )
1343 HYDROData_SequenceOfObjects aSeqLC = myEditedObject->GetLandCovers();
1344 aSeq.Append( aSeqLC );
1346 else if ( !theLandCover && myShowGeomObjects )
1348 HYDROData_SequenceOfObjects aSeqGO = myEditedObject->GetGeometryObjects();
1349 aSeq.Append( aSeqGO );
1352 Handle(HYDROData_Entity) anEntity;
1356 // Gather zones for displaying
1357 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1358 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1359 HYDROData_SequenceOfObjects aZones;
1360 Handle(HYDROData_Region) aRegion;
1361 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1363 anEntity = aRegionsIter.Value();
1364 if ( !anEntity.IsNull() )
1366 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1367 if ( !aRegion.IsNull() )
1369 aZones = aRegion->GetZones();
1370 aSeq.Append( aZones );
1376 // Get a boundary polyline if any
1377 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
1379 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1381 if ( !myActiveViewManager )
1383 if ( aSeq.IsEmpty() )
1386 myActiveViewManager = anApp->activeViewManager();
1389 if ( !myPreviewViewManager )
1391 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1392 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1393 if ( myPreviewViewManager )
1395 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1396 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1398 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1399 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1403 if ( !myPreviewViewManager )
1406 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1408 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1409 if ( !aCtx.IsNull() )
1411 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1412 for ( ; anIter.More(); anIter.Next() )
1414 setObjectVisibility( anIter.Value(), true );
1417 //Process the draw events for viewer
1418 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1419 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
1423 module()->update( UF_OCCViewer | UF_FitAll );
1427 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1429 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1433 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1435 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1439 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1444 void HYDROGUI_CalculationOp::closePreview( bool theRemoveViewManager )
1446 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1447 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1448 QShortcut* aShortcut;
1449 foreach( aShortcut, aShortcuts )
1451 if ( aShortcut->key() ==
1452 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1453 SUIT_DataBrowser::RenameShortcut ) ) )
1455 aShortcut->setEnabled( true );
1460 if( myPreviewViewManager )
1462 // Hide all the displayed objects in the preview view
1463 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1465 size_t aViewId = (size_t)aViewer;
1466 HYDROData_Iterator anIterator( doc() );
1467 for( ; anIterator.More(); anIterator.Next() ) {
1468 Handle(HYDROData_Entity) anObject = anIterator.Current();
1469 if( !anObject.IsNull() ) {
1470 module()->setObjectVisible( aViewId, anObject, false );
1475 if ( theRemoveViewManager )
1477 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1478 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1480 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1481 myPreviewViewManager = NULL;
1485 if( myActiveViewManager && theRemoveViewManager )
1487 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1488 myActiveViewManager = NULL;
1492 void HYDROGUI_CalculationOp::setAvailableGroups()
1494 HYDROGUI_CalculationDlg* aPanel =
1495 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1497 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1498 QStringList aList, anEntryList;
1499 getNamesAndEntries( aSeq, aList, anEntryList );
1501 QStringList aGroupsNames;
1503 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1504 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1506 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1507 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1508 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1510 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1511 aGroupsNames.append( aGroup->GetName() );
1514 if( myEditedObject->IsMustBeUpdated() ) {
1515 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1516 Handle(HYDROData_ShapesGroup) aGeomGroup =
1517 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1518 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1519 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1524 aPanel->setAvailableGroups( aGroupsNames );
1525 aPanel->includeGroups( aList );
1527 bool isUpdated = myEditedObject->IsMustBeUpdated();
1530 void HYDROGUI_CalculationOp::onAddGroups()
1532 HYDROGUI_CalculationDlg* aPanel =
1533 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1537 // Add geometry objects selected in the module browser to the calculation case
1538 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1539 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1542 QStringList anAddedList;
1543 for (int i = 0; i < aSelectedList.length(); i++)
1545 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1546 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1547 if ( aGroup.IsNull() )
1550 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1551 anAddedList.append( aGroup->GetName() );
1554 if ( !anAddedList.isEmpty() )
1556 aPanel->includeGroups( anAddedList );
1560 void HYDROGUI_CalculationOp::onRemoveGroups()
1562 // Remove selected objects from the calculation case
1563 HYDROGUI_CalculationDlg* aPanel =
1564 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1568 QStringList aSelectedList = aPanel->getSelectedGroups();
1569 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1572 for (int i = 0; i < aSelectedList.length(); i++)
1574 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1575 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1576 if ( aGroup.IsNull() )
1579 myEditedObject->RemoveGeometryGroup( aGroup );
1582 aPanel->excludeGroups( aSelectedList );
1585 void HYDROGUI_CalculationOp::onChangeLandCoverMode( int theMode )
1587 HYDROGUI_CalculationDlg* aPanel =
1588 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1592 if ( !confirmLandCoverModeChange() ) {
1593 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
1597 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1598 aPanel->setLandCoverMode( theMode );
1601 void HYDROGUI_CalculationOp::onAddLandCovers()
1603 HYDROGUI_CalculationDlg* aPanel =
1604 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1608 // Add land covers selected in the module browser to the calculation case
1609 QStringList aSelectedList = aPanel->getSelectedAvailableLandCovers();
1610 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1613 QStringList anAddedList;
1614 for (int i = 0; i < aSelectedList.length(); i++)
1616 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1617 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1618 if ( anObject.IsNull() )
1621 if ( myEditedObject->AddLandCover( anObject ) )
1622 anAddedList.append( anObject->GetName() );
1625 if ( !anAddedList.isEmpty() )
1627 aPanel->includeLandCovers( anAddedList, false );
1628 createPreview( true );
1632 void HYDROGUI_CalculationOp::onRemoveLandCovers()
1634 // Remove selected objects from the calculation case
1635 HYDROGUI_CalculationDlg* aPanel =
1636 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1640 QStringList aSelectedList = aPanel->getSelectedLandCovers();
1641 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1644 for (int i = 0; i < aSelectedList.length(); i++)
1646 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1647 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1648 if ( anObject.IsNull() )
1651 setObjectVisibility( anObject, false );
1652 myEditedObject->RemoveLandCover( anObject );
1655 module()->update( UF_OCCViewer );
1656 aPanel->excludeLandCovers( aSelectedList );
1659 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1661 HYDROGUI_CalculationDlg* aPanel =
1662 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1666 if ( !confirmModeChange() ) {
1667 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1671 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1672 aPanel->setMode( theMode );
1675 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1677 HYDROGUI_CalculationDlg* aPanel =
1678 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1682 isConfirmed = confirmOrderChange();
1684 myEditedObject->SetToUpdate( true );
1687 void HYDROGUI_CalculationOp::onOrderLandCoverChanged( bool& isConfirmed )
1689 HYDROGUI_CalculationDlg* aPanel =
1690 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1694 isConfirmed = confirmLandCoverOrderChange();
1696 myEditedObject->SetToUpdate( true );