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_Tool2.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>
36 #include <HYDROData_BCPolygon.h>
38 #include <OCCViewer_ViewManager.h>
39 #include <OCCViewer_ViewModel.h>
40 #include <OCCViewer_ViewWindow.h>
42 #include <LightApp_Application.h>
43 #include <LightApp_UpdateFlags.h>
44 #include <LightApp_SelectionMgr.h>
45 #include <LightApp_DataOwner.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_Desktop.h>
49 #include <SUIT_DataBrowser.h>
51 #include <QApplication>
52 #include <QKeySequence>
54 #include <QPushButton>
55 #include <BRep_Builder.hxx>
57 #include <TopTools_IndexedMapOfShape.hxx>
61 #include <HYDROData_CompleteCalcCase.h>
64 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit, bool IsComplete )
65 : HYDROGUI_Operation( theModule ),
66 myIsEdit( theIsEdit ),
67 myActiveViewManager( NULL ),
68 myPreviewViewManager( NULL ),
69 myShowGeomObjects( true ),
70 myShowLandCoverMap( false ),
72 myIsComplete (IsComplete)
76 aDlgName = tr( "COMPLETE_CALCULATION" );
78 aDlgName = myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" );
82 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
87 void HYDROGUI_CalculationOp::startOperation()
89 HYDROGUI_Operation::startOperation();
94 HYDROGUI_CalculationDlg* aPanel =
95 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
99 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
100 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
101 QShortcut* aShortcut;
102 foreach( aShortcut, aShortcuts )
104 if ( aShortcut->key() ==
105 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
106 SUIT_DataBrowser::RenameShortcut ) ) )
108 aShortcut->setEnabled( false );
114 QStringList anEntryList;
115 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
116 getNamesAndEntries( aSeq, aList, anEntryList );
121 //add intersection polylines
122 AddInterPolylinesToList(aList, anEntryList);
124 aPanel->setAllGeomObjects( aList, anEntryList );
129 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
130 Handle(HYDROData_PolylineXY) aPolylineObj;
131 QString aPolylineName;
132 for ( ; anIter.More(); anIter.Next() )
134 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
136 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed(false) )
138 // // Check the polyline shape
139 // TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
140 // if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
141 aPolylineName = aPolylineObj->GetName();
142 if ( !aPolylineName.isEmpty() )
144 aList.append( aPolylineName );
145 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
150 aPanel->setPolylineNames( aList, anEntryList );
152 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
154 myEditedObject.Nullify();
158 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
159 if ( !myEditedObject.IsNull() )
161 aPanel->setMode( myEditedObject->GetAssignmentMode() );
162 anObjectName = myEditedObject->GetName();
163 aPolylineObj = myEditedObject->GetBoundaryPolyline();
164 if ( aPolylineObj.IsNull() )
166 aPanel->setBoundary( QString() );
170 aPolylineName = aPolylineObj->GetName();
171 aPanel->setBoundary( aPolylineName );
174 aSeq = myEditedObject->GetGeometryObjects();
175 HYDROData_SequenceOfObjects anInterPolyList = myEditedObject->GetInterPolyObjects();
176 aSeq.Append(anInterPolyList);
178 getNamesAndEntries( aSeq, aList, anEntryList );
180 aPanel->includeGeomObjects( aList );
183 //aPanel->includeGeomObjects( aList );
184 aPanel->setAlreadyAddedGeomObjects( aList );
185 //myIncObjAtStart = aSeq;
186 aPanel->hideAvailableGeomObjects( aList );
187 aPanel->setGeomOrderingEnabled(true);
191 setRules( HYDROData_CalculationCase::DataTag_CustomRules );
197 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
198 myEditedObject->SetName( anObjectName );
199 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
202 aPanel->setObjectName( anObjectName );
203 aPanel->setEditedObject( myEditedObject );
205 setGeomObjectsVisible( true );
207 createPreview( false );
210 void HYDROGUI_CalculationOp::AddInterPolylinesToList(QStringList& theList, QStringList& theEntryList)
212 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
213 Handle(HYDROData_PolylineXY) aPolylineObj;
214 QString aPolylineName;
215 for ( ; anIter.More(); anIter.Next() )
217 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
218 if ( !aPolylineObj.IsNull())
220 aPolylineName = aPolylineObj->GetName();
221 if ( !aPolylineName.isEmpty() && !theList.contains(aPolylineName) )
223 theList.append( aPolylineName );
224 theEntryList.append(HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ));
230 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
231 QStringList& theNames, QStringList& theEntries ) const
236 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
237 for ( ; anIter.More(); anIter.Next() )
239 Handle(HYDROData_Entity) anEntity = anIter.Value();
240 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
243 theNames.append( anEntity->GetName() );
244 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
248 void HYDROGUI_CalculationOp::abortOperation()
253 HYDROGUI_Operation::abortOperation();
254 module()->getApp()->updateObjectBrowser();
257 void HYDROGUI_CalculationOp::commitOperation()
260 // Commit transaction
261 commitDocOperation();
262 HYDROGUI_Operation::commitOperation();
265 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
267 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName(), myIsComplete );
269 // Connect signals and slots
270 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
271 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
272 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
273 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
274 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
276 connect( aPanel, SIGNAL( addBoundaryPolygons() ), SLOT( onAddBoundaryPolygons() ) );
277 connect( aPanel, SIGNAL( removeBoundaryPolygons() ), SLOT( onRemoveBoundaryPolygons() ) );
279 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
281 connect( aPanel, SIGNAL( ruleChanged( bool& ) ), SLOT( onRuleChanged( bool& ) ) );
283 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
284 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones( const int ) ) );
285 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
286 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
287 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
288 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
289 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
290 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
291 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
292 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
293 connect( aPanel, SIGNAL( objectsSelected() ),
294 SLOT( onObjectsSelected() ) );
295 connect( aPanel, SIGNAL( landCoverMapSelected( const QString & ) ),
296 SLOT( onLandCoverMapSelected( const QString & ) ) );
297 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
298 SLOT( onBoundarySelected( const QString & ) ) );
299 connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
300 SLOT( onStricklerTableSelected( const QString & ) ) );
302 connect( aPanel, SIGNAL( regenerateColors() ), this,
303 SLOT( onRegenerateColors() ) );
308 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
310 bool anIsToUpdateViewer = false;
312 // Remove the old boundary from the operation viewer
313 Handle(HYDROData_PolylineXY) aPrevPolyline =
314 myEditedObject->GetBoundaryPolyline();
315 if ( !aPrevPolyline.IsNull() )
317 setObjectVisibility( aPrevPolyline, false );
318 anIsToUpdateViewer = true;
321 // Set the selected boundary polyline to the calculation case
322 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
323 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
324 myEditedObject->SetBoundaryPolyline( aNewPolyline );
326 if ( myPreviewViewManager )
328 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
331 if ( !aNewPolyline.IsNull() )
333 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
334 if ( !aCtx.IsNull() )
336 setObjectVisibility( aNewPolyline, true );
337 anIsToUpdateViewer = true;
341 if ( anIsToUpdateViewer )
342 module()->update( UF_OCCViewer );
347 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
349 bool anIsToUpdateViewer = false;
351 // Remove old presentation of land cover map from the operation viewer
352 Handle(HYDROData_LandCoverMap) aLandCoverMap = myEditedObject->GetLandCoverMap();
353 if ( !aLandCoverMap.IsNull() )
355 setObjectVisibility( aLandCoverMap, false );
356 anIsToUpdateViewer = true;
359 // Set the selected Strickler table to the calculation case
360 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
361 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
362 myEditedObject->SetStricklerTable( aNewStricklerTable );
364 if ( myPreviewViewManager )
366 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
369 if ( !aNewStricklerTable.IsNull() )
371 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
372 if ( !aCtx.IsNull() )
374 if ( !aLandCoverMap.IsNull() )
376 setObjectVisibility( aLandCoverMap, true );
377 anIsToUpdateViewer = true;
382 if ( anIsToUpdateViewer )
383 module()->update( UF_OCCViewer );
388 void HYDROGUI_CalculationOp::onObjectsSelected()
390 HYDROGUI_CalculationDlg* aPanel =
391 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
393 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
394 QMap<QString, bool> aSelectedObjsMap;
395 foreach( QString aName, aSelectedObjs )
396 aSelectedObjsMap[aName] = true;
399 // Select the appropriate geometry object shape in the viewer
400 selectionMgr()->clearSelected();
402 // Unhighlight all objects except selected
403 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
404 Handle(HYDROData_Entity) anEntity;
405 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
406 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
409 for ( ; anIter.More(); anIter.Next() )
411 anEntity = anIter.Value();
412 if ( !anEntity.IsNull() )
414 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
417 aName = anEntity->GetName();
418 isSelected = aSelectedObjsMap.contains( aName );
419 aShape->highlight( isSelected, false );
420 aShape->update( false, false );
426 aLastShape->update( true, false );
429 void HYDROGUI_CalculationOp::onLandCoverMapSelected( const QString & theObjName )
431 bool anIsToUpdateViewer = false;
433 // Remove old presentation of land cover map from the operation viewer
434 Handle(HYDROData_LandCoverMap) aPrevLandCoverMap = myEditedObject->GetLandCoverMap();
435 if ( !aPrevLandCoverMap.IsNull() )
437 setObjectVisibility( aPrevLandCoverMap, false );
438 anIsToUpdateViewer = true;
441 // Select the appropriate land cover map shape in the viewer
442 selectionMgr()->clearSelected();
444 // Set the selected land cover map to the calculation case
445 Handle(HYDROData_LandCoverMap) aNewLandCoverMap = Handle(HYDROData_LandCoverMap)::DownCast(
446 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_LAND_COVER_MAP ) );
447 myEditedObject->SetLandCoverMap( aNewLandCoverMap );
449 createPreview( true );
452 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
454 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
455 HYDROGUI_Zone* aZoneItem;
456 selectionMgr()->clearSelected();
459 // Select a region in preview
460 SUIT_DataOwnerPtrList aList( true );
461 DataObjectList aZones = aRegionItem->children();
462 for ( int i = 0; i < aZones.length(); i++ )
464 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
467 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
470 selectionMgr()->setSelected( aList );
474 // select a single zone
475 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
478 SUIT_DataOwnerPtrList aList( true );
479 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
480 selectionMgr()->setSelected( aList );
485 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem,
486 const QList<SUIT_DataObject*>& theZonesList )
488 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
491 QList<HYDROGUI_Zone*> aZonesList;
492 HYDROGUI_Zone* aZone;
493 // Get a list of dropped zones
494 for ( int i = 0; i < theZonesList.length(); i++ )
496 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
499 aZonesList.append( aZone );
502 if ( aZonesList.length() > 0 )
504 aRegion->addZones( aZonesList );
505 HYDROGUI_CalculationDlg* aPanel =
506 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
508 aPanel->refreshZonesBrowser();
509 createPreview( false, false, false );
514 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
516 if ( createRegion( theZonesList ) )
518 HYDROGUI_CalculationDlg* aPanel =
519 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
522 aPanel->refreshZonesBrowser();
524 createPreview( false, false, false );
528 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theMergeObjectName )
530 HYDROGUI_CalculationDlg* aPanel =
531 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
534 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
537 aZone->setMergeType( theMergeType, theMergeObjectName );
538 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
541 aShape->update( true, false );
544 aPanel->refreshZonesBrowser();
548 void HYDROGUI_CalculationOp::onAddObjects()
550 HYDROGUI_CalculationDlg* aPanel =
551 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
555 // Add geometry objects selected in the module browser to the calculation case
556 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
557 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
560 QStringList anAddedList;
561 for (int i = 0; i < aSelectedList.length(); i++)
563 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
564 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
565 if ( anObject.IsNull() )
568 if ( myEditedObject->AddGeometryObject( anObject ) )
569 anAddedList.append( anObject->GetName() );
572 for (int i = 0; i < aSelectedList.length(); i++)
574 Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast(
575 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
576 if ( aPoly.IsNull() )
579 if ( myEditedObject->AddInterPoly( aPoly ) )
580 anAddedList.append( aPoly->GetName() );
583 if ( !anAddedList.isEmpty() )
585 aPanel->includeGeomObjects( anAddedList );
586 createPreview( false );
590 void HYDROGUI_CalculationOp::onRemoveObjects()
592 // Remove selected objects from the calculation case
593 HYDROGUI_CalculationDlg* aPanel =
594 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
598 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
602 QSet<QString> selMap = aSelectedList.toSet();
606 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
609 for (int i = 0; i < aSelectedList.length(); i++)
611 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
612 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
613 if ( anObject.IsNull() )
616 setObjectVisibility( anObject, false );
617 myEditedObject->RemoveGeometryObject( anObject );
620 for (int i = 0; i < aSelectedList.length(); i++)
622 Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast(
623 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
624 if ( aPoly.IsNull() )
627 setObjectVisibility( aPoly, false );
628 myEditedObject->RemoveInterPolyObject ( aPoly );
631 module()->update( UF_OCCViewer );
632 aPanel->excludeGeomObjects( aSelectedList );
635 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
638 // Check if the case is already modified or not
639 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
646 //SUIT_MessageBox::information(module()->getApp()->desktop(),
647 // tr( "REGIONS_CHANGED" ),
648 // tr( "COMPLETE_OP_WILL_BE_PERFORMED" ));
652 // If not modified check if the case has already defined regions with zones
653 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
654 if ( aSeq.Length() > 0 )
656 // If there are already defined zones then ask a user to confirm zones recalculation
657 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
658 tr( "REGIONS_CHANGED" ),
659 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
660 QMessageBox::Yes | QMessageBox::No,
661 QMessageBox::No ) == QMessageBox::Yes );
665 isConfirmed = true; // No regions - no zones - nothing to recalculate
671 bool HYDROGUI_CalculationOp::confirmOrderChange() const
673 // Check if the case is already modified or not
674 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
677 // If not modified check if the case has already defined regions with zones
678 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
679 if ( aSeq.Length() > 0 )
681 // If there are already defined zones then ask a user to confirm zones recalculation
682 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
683 tr( "ORDER_CHANGED" ),
684 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
685 QMessageBox::Yes | QMessageBox::No,
686 QMessageBox::No ) == QMessageBox::Yes );
690 isConfirmed = true; // No regions - no zones - nothing to recalculate
696 bool HYDROGUI_CalculationOp::confirmRuleChange() const
698 // Check if the case is already modified or not
699 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
702 // If not modified check if the case has already defined regions with zones
703 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
704 if ( aSeq.Length() > 0 )
706 // If there are already defined zones then ask a user to confirm zones recalculation
707 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
708 tr( "RULE_CHANGED" ),
709 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
710 QMessageBox::Yes | QMessageBox::No,
711 QMessageBox::No ) == QMessageBox::Yes );
715 isConfirmed = true; // No regions - no zones - nothing to recalculate
721 bool HYDROGUI_CalculationOp::confirmModeChange() const
723 // Check if the case is already modified or not
724 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
727 // If not modified check if the case has already defined regions with zones
728 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
729 if ( aSeq.Length() > 0 )
731 // If there are already defined zones then ask a user to confirm zones recalculation
732 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
733 tr( "MODE_CHANGED" ),
734 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
735 QMessageBox::Yes | QMessageBox::No,
736 QMessageBox::No ) == QMessageBox::Yes );
740 isConfirmed = true; // No regions - no zones - nothing to recalculate
746 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
748 HYDROData_WarningType aType = theWarning.Type;
749 if ( aType == WARN_OK ) {
757 case WARN_EMPTY_REGIONS:
758 aTitle = tr( "EMPTY_REGIONS" );
759 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
762 aTitle = tr( "WARNING" );
763 aMsg = theWarning.Data;
767 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
769 QMessageBox::Yes | QMessageBox::No,
772 return ( anAnswer == QMessageBox::Yes );
775 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
776 QString& theErrorMsg,
777 QStringList& theBrowseObjectsEntries )
779 HYDROGUI_CalculationDlg* aPanel =
780 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
786 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
787 theBrowseObjectsEntries.append( anEntry );
790 // For manual mode priority rules are redundant
791 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
792 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
795 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
800 void HYDROGUI_CalculationOp::onApply()
803 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
804 if ( aWarning.Type != WARN_OK ) {
805 if ( !confirmContinueWithWarning( aWarning ) ) {
806 // Go back to the first page
807 HYDROGUI_CalculationDlg* aPanel =
808 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
810 aPanel->onFirstPage();
816 QApplication::setOverrideCursor( Qt::WaitCursor );
818 int anUpdateFlags = 0;
820 QStringList aBrowseObjectsEntries;
822 bool aResult = false;
826 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
828 catch ( Standard_Failure )
830 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
831 anErrorMsg = aFailure->GetMessageString();
839 QApplication::restoreOverrideCursor();
843 module()->update( anUpdateFlags );
845 browseObjects( aBrowseObjectsEntries );
850 QString aMsg = tr( "INPUT_VALID_DATA" );
851 if( !anErrorMsg.isEmpty() )
852 aMsg.prepend( anErrorMsg + "\n" );
853 SUIT_MessageBox::critical( module()->getApp()->desktop(),
854 tr( "INSUFFICIENT_INPUT_DATA" ),
858 #include <HYDROData_CompleteCalcCase.h>
859 void HYDROGUI_CalculationOp::onNext( const int theIndex )
861 if( theIndex==1 && !myIsComplete)
863 setAvailableGroups();
865 else if( theIndex==2 && !myIsComplete)
867 setAvailableBoundaryPolygons();
869 else if( theIndex==3 && !myIsComplete)
871 // Land cover map panel
872 HYDROGUI_CalculationDlg* aPanel =
873 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
877 setLandCoverMapVisible( true );
880 QStringList anEntryList;
882 // Get all land cover map objects to fill in combo-box
883 Handle(HYDROData_LandCoverMap) aLandCoverMapObj;
884 QString aLandCoverMapName;
888 HYDROData_Iterator anIter( doc(), KIND_LAND_COVER_MAP );
889 for ( ; anIter.More(); anIter.Next() )
891 aLandCoverMapObj = Handle(HYDROData_LandCoverMap)::DownCast( anIter.Current() );
893 if ( !aLandCoverMapObj.IsNull() )
895 aLandCoverMapName = aLandCoverMapObj->GetName();
896 if ( !aLandCoverMapName.isEmpty() )
898 aList.append( aLandCoverMapName );
899 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aLandCoverMapObj ) );
903 aPanel->setLandCoverMapsNames( aList, anEntryList );
904 aLandCoverMapObj = myEditedObject->GetLandCoverMap();
905 if ( !aList.isEmpty() )
907 if ( aLandCoverMapObj.IsNull() )
908 aPanel->setLandCoverMap( aList.at( 0 ), false );
910 aPanel->setLandCoverMap( aList.at( 0 ), true );
912 aPanel->setLandCoverMap( aList.at( aList.indexOf( aLandCoverMapObj->GetName() ) ), true );
915 // Get all Strickler table objects to fill in combo-box
916 Handle(HYDROData_StricklerTable) aStricklerTableObj;
917 QString aStricklerTableName;
921 anIter = HYDROData_Iterator( doc(), KIND_STRICKLER_TABLE );
922 for ( ; anIter.More(); anIter.Next() )
924 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
926 if ( !aStricklerTableObj.IsNull() )
928 aStricklerTableName = aStricklerTableObj->GetName();
929 if ( !aStricklerTableName.isEmpty() )
931 aList.append( aStricklerTableName );
932 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
936 aPanel->setStricklerTableNames( aList, anEntryList );
937 //@ASL: bool anUpdateState = myEditedObject->IsMustBeUpdated();
938 if ( !aList.isEmpty() )
939 aPanel->setStricklerTable( aList.at( 0 ), false );
940 //@ASL: myEditedObject->SetToUpdate( anUpdateState );
942 if ( !myEditedObject.IsNull() )
946 // Select the certain Strickler table object in combo-box
947 aStricklerTableObj = myEditedObject->GetStricklerTable();
948 if ( aStricklerTableObj.IsNull() )
950 aPanel->setStricklerTable( QString() );
954 aStricklerTableName = aStricklerTableObj->GetName();
955 aPanel->setStricklerTable( aStricklerTableName );
958 // Select the certain land cover map object in combo-box
959 if ( aLandCoverMapObj.IsNull() )
961 aPanel->setLandCoverMap( QString() );
965 aLandCoverMapName = aLandCoverMapObj->GetName();
966 aPanel->setLandCoverMap( aLandCoverMapName );
971 closePreview( false );
972 createPreview( true );
974 else if( theIndex==4 || myIsComplete)
976 HYDROGUI_CalculationDlg* aPanel =
977 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
981 QApplication::setOverrideCursor( Qt::WaitCursor );
983 setGeomObjectsVisible( false );
984 setLandCoverMapVisible( false );
986 QString aNewCaseName = aPanel->getObjectName();
987 QString anOldCaseName = myEditedObject->GetName();
988 bool isNameChanged = anOldCaseName != aNewCaseName;
990 bool anIsToUpdateOb = isNameChanged;
992 // At first we must to update the case name because of
993 // automatic names generation for regions and zones
994 myEditedObject->SetName( aNewCaseName );
996 // Zones: set parameters for automatic mode
997 int aMode = aPanel->getMode();
998 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1000 // Set objects in the specified order
1001 if( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) )
1003 myEditedObject->RemoveGeometryObjects();
1004 QStringList aGeomObjNames;
1005 if (myIsComplete) //erase objects ?
1006 aGeomObjNames << aPanel->getAlreadyAddedGeomObjects();
1007 aGeomObjNames << aPanel->getAllGeomObjects();
1008 foreach ( const QString& aName, aGeomObjNames )
1010 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
1011 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1012 if ( anObject.IsNull() )
1016 myEditedObject->AddGeometryObject( anObject );
1021 // Clear priority rules
1022 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
1023 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
1025 // Set priority rules
1026 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
1027 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1028 aRule.Object2, aRule.MergeType,
1029 HYDROData_CalculationCase::DataTag_CustomRules );
1034 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1037 aPanel->BackButton()->setEnabled(false); //force disable; to prevent moving to the first page
1039 if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
1045 //abortDocOperation();
1046 //module()->getApp()->updateObjectBrowser();
1047 QList<Handle(HYDROData_Entity)> newGeomObj = aPanel->getGeometryObjects(false);
1048 //QSet<Handle(HYDROData_Entity)> includedObjAtStartSet = myIncObjAtStart.toSet();
1049 NCollection_Sequence<Handle(HYDROData_Entity)> theNewObjects;
1050 foreach (Handle(HYDROData_Entity) obj, newGeomObj)
1051 theNewObjects.Append(obj);
1054 bool is_int = false;
1055 bool UseOrigNamingOfNewRegions = true;
1056 NCollection_Sequence<Handle(HYDROData_Region)> theNewRegions;
1057 QSet<QString> newRegionEntries;
1058 HYDROData_CompleteCalcCase::AddObjects(doc(), myEditedObject, theNewObjects, UseOrigNamingOfNewRegions, is_int, theNewRegions);
1060 SUIT_MessageBox::information(module()->getApp()->desktop(),
1061 tr( "COMPLETE_CASE" ),
1062 tr( "COMPLETE_CASE_INTERSECTION_DETECTED" ));
1064 myEditedObject->ClearChanged();
1065 for (int k=1;k<=theNewRegions.Size();k++)
1067 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theNewRegions(k) );
1068 newRegionEntries.insert(anEntry);
1070 AssignDefaultZonesColors(&newRegionEntries);
1074 myEditedObject->Update();
1075 AssignDefaultZonesColors(NULL);
1079 //aPanel->setEditedObject( myEditedObject );
1080 aPanel->refreshZonesBrowser();
1082 closePreview( false );
1083 createPreview( false );
1085 anIsToUpdateOb = true;
1090 setZonesVisible( true );
1092 if ( isNameChanged ) {
1093 module()->getDataModel()->updateObjectTree( myEditedObject );
1097 QApplication::restoreOverrideCursor();
1101 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
1106 // setGeomObjectsVisible( true );
1107 // // HYDROGUI_CalculationDlg* aPanel = ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1108 // // QList<Handle(HYDROData_Entity)> geomObjList = aPanel->getGeometryObjects(false);
1109 // // foreach ( Handle(HYDROData_Entity) geomObj, geomObjList)
1110 // // setObjectVisibility( geomObj, true );
1112 // setZonesVisible( false );
1113 // closePreview( false );
1114 // createPreview( false );
1120 setGeomObjectsVisible( true );
1122 closePreview( false );
1123 createPreview( false );
1127 setLandCoverMapVisible( true );
1129 closePreview( false );
1130 createPreview( true );
1133 setZonesVisible( false );
1135 else if( theIndex==4 )
1137 AssignDefaultZonesColors();
1139 closePreview( false );
1140 createPreview( false );
1143 setZonesVisible( true );
1148 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
1150 myShowZones = theIsVisible;
1151 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1152 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1153 HYDROData_SequenceOfObjects aZones;
1154 Handle(HYDROData_Region) aRegion;
1155 if ( myPreviewViewManager )
1157 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1159 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1160 if ( !aCtx.IsNull() )
1162 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1164 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1165 if ( !aRegion.IsNull() )
1167 aZones = aRegion->GetZones();
1168 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1169 for ( ; aZonesIter.More(); aZonesIter.Next() )
1171 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1177 module()->update( UF_OCCViewer );
1182 void HYDROGUI_CalculationOp::setGeomObjectsVisible( bool theIsVisible )
1184 myShowGeomObjects = theIsVisible;
1186 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
1188 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1189 for ( ; anIter.More(); anIter.Next() ) {
1190 setObjectVisibility( anIter.Value(), theIsVisible );
1194 void HYDROGUI_CalculationOp::setLandCoverMapVisible( bool theIsVisible )
1196 myShowLandCoverMap = theIsVisible;
1197 setObjectVisibility( myEditedObject->GetLandCoverMap(), theIsVisible );
1200 void HYDROGUI_CalculationOp::AssignDefaultZonesColors(const QSet<QString>* theRegionsEntriesToColored)
1202 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1203 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1204 HYDROData_SequenceOfObjects aZones;
1205 Handle(HYDROData_Region) aRegion;
1206 if ( myPreviewViewManager )
1208 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1210 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1211 if ( !aCtx.IsNull() )
1213 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1215 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1216 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aRegion );
1218 if (theRegionsEntriesToColored && !theRegionsEntriesToColored->contains(anEntry))
1221 if ( !aRegion.IsNull() )
1223 aZones = aRegion->GetZones();
1224 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1225 for ( ; aZonesIter.More(); aZonesIter.Next() )
1228 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1229 if ( !aZone.IsNull() )
1231 QColor aFillingColor = HYDROData_Tool::GenerateRandColor();
1232 while (aFillingColor == Qt::red)
1233 aFillingColor = HYDROData_Tool::GenerateRandColor();
1235 aZone->SetColor(aFillingColor);
1245 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1247 HYDROGUI_CalculationDlg* aPanel =
1248 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1252 HYDROData_ListOfRules aRules;
1253 Handle(HYDROData_Entity) anObject1, anObject2;
1254 HYDROData_PriorityType aPriority;
1255 HYDROData_Zone::MergeType aMergeType;
1256 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1257 for ( int anIndex = 0; ; anIndex++ )
1259 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1260 HYDROData_CustomRule aRule;
1261 aRule.Object1 = anObject1;
1262 aRule.Object2 = anObject2;
1263 aRule.Priority = aPriority;
1264 aRule.MergeType = aMergeType;
1272 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1273 aPanel->setRules( aRules );
1276 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList )
1278 bool aRetValue = false;
1280 QList<HYDROGUI_Zone*> aZonesList;
1281 HYDROGUI_Zone* aZone;
1282 // Get a list of dropped zones
1283 for ( int i = 0; i < theZonesList.length(); i++ )
1285 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1288 aZonesList.append( aZone );
1291 if ( aZonesList.length() > 0 )
1293 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
1300 void HYDROGUI_CalculationOp::createPreview( const bool theLandCoverMap, bool fitAllFlag, bool onTopViewAndFit )
1302 LightApp_Application* anApp = module()->getApp();
1303 HYDROData_SequenceOfObjects aSeq;
1304 if ( theLandCoverMap && myShowLandCoverMap )
1306 aSeq.Append( myEditedObject->GetLandCoverMap() );
1308 else if ( !theLandCoverMap && myShowGeomObjects )
1310 HYDROData_SequenceOfObjects aSeqGO = myEditedObject->GetGeometryObjects();
1311 HYDROData_SequenceOfObjects aSeqP = myEditedObject->GetInterPolyObjects();
1312 aSeq.Append( aSeqGO );
1313 aSeq.Append( aSeqP );
1316 Handle(HYDROData_Entity) anEntity;
1320 // Gather zones for displaying
1321 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1322 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1323 HYDROData_SequenceOfObjects aZones;
1324 Handle(HYDROData_Region) aRegion;
1325 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1327 anEntity = aRegionsIter.Value();
1328 if ( !anEntity.IsNull() )
1330 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1331 if ( !aRegion.IsNull() )
1333 aZones = aRegion->GetZones();
1334 aSeq.Append( aZones );
1340 // Get a boundary polyline if any
1341 if (Handle(HYDROData_PolylineXY) aBPoly = myEditedObject->GetBoundaryPolyline())
1342 aSeq.Append( aBPoly );
1344 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1346 if ( !myActiveViewManager )
1348 if ( aSeq.IsEmpty() )
1351 myActiveViewManager = anApp->activeViewManager();
1354 if ( !myPreviewViewManager )
1356 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1357 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1358 if ( myPreviewViewManager )
1360 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1361 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1363 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1364 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1368 if ( !myPreviewViewManager )
1371 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1373 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1374 if ( !aCtx.IsNull() )
1376 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1377 for ( ; anIter.More(); anIter.Next() )
1379 const Handle(HYDROData_Entity)& ent = anIter.Value();
1381 setObjectVisibility( ent, true );
1384 //Process the draw events for viewer
1385 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1388 int UpdateFlags = UF_OCCViewer;
1390 UpdateFlags |= UF_FitAll;
1391 module()->update( UpdateFlags );
1393 OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView();
1394 if ( onTopViewAndFit && vw )
1399 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1401 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1405 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1407 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1411 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1416 void HYDROGUI_CalculationOp::closePreview( bool theRemoveViewManager )
1418 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1419 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1420 QShortcut* aShortcut;
1421 foreach( aShortcut, aShortcuts )
1423 if ( aShortcut->key() ==
1424 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1425 SUIT_DataBrowser::RenameShortcut ) ) )
1427 aShortcut->setEnabled( true );
1432 if( myPreviewViewManager )
1434 // Hide all the displayed objects in the preview view
1435 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1437 size_t aViewId = (size_t)aViewer;
1438 HYDROData_Iterator anIterator( doc() );
1439 for( ; anIterator.More(); anIterator.Next() ) {
1440 Handle(HYDROData_Entity) anObject = anIterator.Current();
1441 if( !anObject.IsNull() ) {
1442 module()->setObjectVisible( aViewId, anObject, false );
1447 if ( theRemoveViewManager )
1449 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1450 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1452 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1453 myPreviewViewManager = NULL;
1457 if( myActiveViewManager && theRemoveViewManager )
1459 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1460 myActiveViewManager = NULL;
1464 void HYDROGUI_CalculationOp::setAvailableGroups()
1466 HYDROGUI_CalculationDlg* aPanel =
1467 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1469 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1470 QStringList aList, anEntryList;
1471 getNamesAndEntries( aSeq, aList, anEntryList );
1473 QStringList aGroupsNames;
1475 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1476 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1478 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anObjs.Value( anIndex ) );
1479 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1480 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1482 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( aGIndex ) );
1483 aGroupsNames.append( aGroup->GetName() );
1486 if( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) ) {
1487 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1488 Handle(HYDROData_ShapesGroup) aGeomGroup =
1489 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1490 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1491 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1496 aPanel->setAvailableGroups( aGroupsNames );
1497 aPanel->includeGroups( aList );
1499 //@ASL: bool isUpdated = myEditedObject->IsMustBeUpdated();
1502 void HYDROGUI_CalculationOp::onAddGroups()
1504 HYDROGUI_CalculationDlg* aPanel =
1505 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1509 // Add geometry objects selected in the module browser to the calculation case
1510 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1511 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1514 QStringList anAddedList;
1515 for (int i = 0; i < aSelectedList.length(); i++)
1517 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1518 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1519 if ( aGroup.IsNull() )
1522 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1523 anAddedList.append( aGroup->GetName() );
1526 if ( !anAddedList.isEmpty() )
1528 aPanel->includeGroups( anAddedList );
1532 void HYDROGUI_CalculationOp::onRemoveGroups()
1534 // Remove selected objects from the calculation case
1535 HYDROGUI_CalculationDlg* aPanel =
1536 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1540 QStringList aSelectedList = aPanel->getSelectedGroups();
1541 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1544 for (int i = 0; i < aSelectedList.length(); i++)
1546 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1547 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1548 if ( aGroup.IsNull() )
1551 myEditedObject->RemoveGeometryGroup( aGroup );
1554 aPanel->excludeGroups( aSelectedList );
1558 void HYDROGUI_CalculationOp::setAvailableBoundaryPolygons()
1560 HYDROGUI_CalculationDlg* aPanel = ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1562 HYDROData_Iterator anIter( doc(), KIND_BC_POLYGON );
1563 Handle(HYDROData_BCPolygon) aBCP;
1565 QVector<int> aTypes;
1566 for (;anIter.More(); anIter.Next())
1568 aBCP = Handle(HYDROData_BCPolygon)::DownCast( anIter.Current() );
1569 aNames.append(aBCP->GetName());
1570 aTypes.append(aBCP->GetBoundaryType());
1572 HYDROData_SequenceOfObjects aBCPSeq = myEditedObject->GetBoundaryPolygons();
1574 QStringList aListCut, aListIS;
1575 for (int i=1; i<=aBCPSeq.Size();i++)
1577 int type = Handle(HYDROData_BCPolygon)::DownCast(aBCPSeq(i))->GetBoundaryType();
1579 aListCut << aBCPSeq(i)->GetName();
1580 else if (type == 2 || type == 3)
1581 aListIS << aBCPSeq(i)->GetName();
1584 aPanel->setAvailableBoundaryPolygons( aNames, aTypes );
1585 aPanel->includeBoundaryPolygons( aListCut );
1586 aPanel->includeISBoundaryPolygons( aListIS );
1589 void HYDROGUI_CalculationOp::onRemoveBoundaryPolygons()
1591 HYDROGUI_CalculationDlg* aPanel =
1592 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1596 QStringList aSelectedListCut = aPanel->getSelectedBoundaryPolygons();
1597 QStringList aSelectedListIS = aPanel->getSelectedISBoundaryPolygons();
1599 if ( aSelectedListCut.isEmpty() && aSelectedListIS.isEmpty() )
1602 for (int i = 0; i < aSelectedListCut.length(); i++)
1604 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast(
1605 HYDROGUI_Tool::FindObjectByName( module(), aSelectedListCut.at(i) ) );
1606 if ( aBCPoly.IsNull() )
1608 myEditedObject->RemoveBoundaryPolygon( aBCPoly );
1611 for (int i = 0; i < aSelectedListIS.length(); i++)
1613 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast(
1614 HYDROGUI_Tool::FindObjectByName( module(), aSelectedListIS.at(i) ) );
1615 if ( aBCPoly.IsNull() )
1617 myEditedObject->RemoveBoundaryPolygon( aBCPoly );
1620 aPanel->excludeBoundaryPolygons( aSelectedListCut );
1621 aPanel->excludeISBoundaryPolygons( aSelectedListIS );
1625 void HYDROGUI_CalculationOp::onAddBoundaryPolygons()
1627 HYDROGUI_CalculationDlg* aPanel = ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1631 QStringList aSelectedList = aPanel->getSelectedAvailableBoundaryPolygons();
1632 if ( aSelectedList.isEmpty())
1635 QStringList anAddedListCut, anAddedListIS;
1636 for (int i = 0; i < aSelectedList.length(); i++)
1638 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast(
1639 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1640 if ( aBCPoly.IsNull() )
1643 if ( myEditedObject->AddBoundaryPolygon( aBCPoly ) )
1645 QString aName = aBCPoly->GetName();
1646 int type = aBCPoly->GetBoundaryType();
1648 anAddedListCut.append(aName);
1649 else if (type == 2 || type == 3)
1650 anAddedListIS.append(aName);
1655 if ( !anAddedListCut.isEmpty() )
1656 aPanel->includeBoundaryPolygons(anAddedListCut);
1657 if ( !anAddedListIS.isEmpty() )
1658 aPanel->includeISBoundaryPolygons(anAddedListIS);
1661 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1663 HYDROGUI_CalculationDlg* aPanel =
1664 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1668 if ( !confirmModeChange() ) {
1669 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1673 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1674 aPanel->setMode( theMode );
1677 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1679 HYDROGUI_CalculationDlg* aPanel =
1680 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1684 isConfirmed = confirmOrderChange();
1686 myEditedObject->Changed( HYDROData_Entity::Geom_2d );
1689 void HYDROGUI_CalculationOp::onRuleChanged( bool& isConfirmed )
1691 HYDROGUI_CalculationDlg* aPanel =
1692 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1696 isConfirmed = confirmRuleChange();
1698 myEditedObject->Changed( HYDROData_Entity::Geom_2d );
1701 void HYDROGUI_CalculationOp::onRegenerateColors()
1703 // For geometry zones
1704 AssignDefaultZonesColors();
1705 setZonesVisible( false );
1706 setZonesVisible( true );