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>
55 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
56 : HYDROGUI_Operation( theModule ),
57 myIsEdit( theIsEdit ),
58 myActiveViewManager( NULL ),
59 myPreviewViewManager( NULL ),
60 myShowGeomObjects( true ),
61 myShowLandCoverMap( false ),
64 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
67 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
72 void HYDROGUI_CalculationOp::startOperation()
74 HYDROGUI_Operation::startOperation();
79 HYDROGUI_CalculationDlg* aPanel =
80 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
84 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
85 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
87 foreach( aShortcut, aShortcuts )
89 if ( aShortcut->key() ==
90 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
91 SUIT_DataBrowser::RenameShortcut ) ) )
93 aShortcut->setEnabled( false );
99 QStringList anEntryList;
100 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
101 getNamesAndEntries( aSeq, aList, anEntryList );
106 //add intersection polylines
107 AddInterPolylinesToList(aList, anEntryList);
109 aPanel->setAllGeomObjects( aList, anEntryList );
114 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
115 Handle(HYDROData_PolylineXY) aPolylineObj;
116 QString aPolylineName;
117 for ( ; anIter.More(); anIter.Next() )
119 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
121 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed(false) )
123 // // Check the polyline shape
124 // TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
125 // if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
126 aPolylineName = aPolylineObj->GetName();
127 if ( !aPolylineName.isEmpty() )
129 aList.append( aPolylineName );
130 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
135 aPanel->setPolylineNames( aList, anEntryList );
137 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
139 myEditedObject.Nullify();
142 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
143 if ( !myEditedObject.IsNull() )
145 aPanel->setMode( myEditedObject->GetAssignmentMode() );
146 anObjectName = myEditedObject->GetName();
147 aPolylineObj = myEditedObject->GetBoundaryPolyline();
148 if ( aPolylineObj.IsNull() )
150 aPanel->setBoundary( QString() );
154 aPolylineName = aPolylineObj->GetName();
155 aPanel->setBoundary( aPolylineName );
158 aSeq = myEditedObject->GetGeometryObjects();
159 HYDROData_SequenceOfObjects anInterPolyList = myEditedObject->GetInterPolyObjects();
160 aSeq.Append(anInterPolyList);
162 getNamesAndEntries( aSeq, aList, anEntryList );
163 aPanel->includeGeomObjects( aList );
166 setRules( HYDROData_CalculationCase::DataTag_CustomRules );
172 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
173 myEditedObject->SetName( anObjectName );
174 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
177 aPanel->setObjectName( anObjectName );
178 aPanel->setEditedObject( myEditedObject );
180 setGeomObjectsVisible( true );
182 createPreview( false );
185 void HYDROGUI_CalculationOp::AddInterPolylinesToList(QStringList& theList, QStringList& theEntryList)
187 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
188 Handle(HYDROData_PolylineXY) aPolylineObj;
189 QString aPolylineName;
190 for ( ; anIter.More(); anIter.Next() )
192 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
193 if ( !aPolylineObj.IsNull())
195 aPolylineName = aPolylineObj->GetName();
196 if ( !aPolylineName.isEmpty() && !theList.contains(aPolylineName) )
198 theList.append( aPolylineName );
199 theEntryList.append(HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ));
205 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
206 QStringList& theNames, QStringList& theEntries ) const
211 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
212 for ( ; anIter.More(); anIter.Next() )
214 Handle(HYDROData_Entity) anEntity = anIter.Value();
215 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
218 theNames.append( anEntity->GetName() );
219 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
223 void HYDROGUI_CalculationOp::abortOperation()
228 HYDROGUI_Operation::abortOperation();
229 module()->getApp()->updateObjectBrowser();
232 void HYDROGUI_CalculationOp::commitOperation()
235 // Commit transaction
236 commitDocOperation();
237 HYDROGUI_Operation::commitOperation();
240 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
242 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
244 // Connect signals and slots
245 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
246 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
247 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
248 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
249 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
251 connect( aPanel, SIGNAL( addBoundaryPolygons() ), SLOT( onAddBoundaryPolygons() ) );
252 connect( aPanel, SIGNAL( removeBoundaryPolygons() ), SLOT( onRemoveBoundaryPolygons() ) );
254 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
256 connect( aPanel, SIGNAL( ruleChanged( bool& ) ), SLOT( onRuleChanged( bool& ) ) );
258 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
259 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones( const int ) ) );
260 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
261 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
262 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
263 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
264 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
265 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
266 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
267 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
268 connect( aPanel, SIGNAL( objectsSelected() ),
269 SLOT( onObjectsSelected() ) );
270 connect( aPanel, SIGNAL( landCoverMapSelected( const QString & ) ),
271 SLOT( onLandCoverMapSelected( const QString & ) ) );
272 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
273 SLOT( onBoundarySelected( const QString & ) ) );
274 connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
275 SLOT( onStricklerTableSelected( const QString & ) ) );
277 connect( aPanel, SIGNAL( regenerateColors() ), this,
278 SLOT( onRegenerateColors() ) );
283 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
285 bool anIsToUpdateViewer = false;
287 // Remove the old boundary from the operation viewer
288 Handle(HYDROData_PolylineXY) aPrevPolyline =
289 myEditedObject->GetBoundaryPolyline();
290 if ( !aPrevPolyline.IsNull() )
292 setObjectVisibility( aPrevPolyline, false );
293 anIsToUpdateViewer = true;
296 // Set the selected boundary polyline to the calculation case
297 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
298 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
299 myEditedObject->SetBoundaryPolyline( aNewPolyline );
301 if ( myPreviewViewManager )
303 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
306 if ( !aNewPolyline.IsNull() )
308 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
309 if ( !aCtx.IsNull() )
311 setObjectVisibility( aNewPolyline, true );
312 anIsToUpdateViewer = true;
316 if ( anIsToUpdateViewer )
317 module()->update( UF_OCCViewer );
322 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
324 bool anIsToUpdateViewer = false;
326 // Remove old presentation of land cover map from the operation viewer
327 Handle(HYDROData_LandCoverMap) aLandCoverMap = myEditedObject->GetLandCoverMap();
328 if ( !aLandCoverMap.IsNull() )
330 setObjectVisibility( aLandCoverMap, false );
331 anIsToUpdateViewer = true;
334 // Set the selected Strickler table to the calculation case
335 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
336 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
337 myEditedObject->SetStricklerTable( aNewStricklerTable );
339 if ( myPreviewViewManager )
341 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
344 if ( !aNewStricklerTable.IsNull() )
346 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
347 if ( !aCtx.IsNull() )
349 if ( !aLandCoverMap.IsNull() )
351 setObjectVisibility( aLandCoverMap, true );
352 anIsToUpdateViewer = true;
357 if ( anIsToUpdateViewer )
358 module()->update( UF_OCCViewer );
363 void HYDROGUI_CalculationOp::onObjectsSelected()
365 HYDROGUI_CalculationDlg* aPanel =
366 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
368 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
369 QMap<QString, bool> aSelectedObjsMap;
370 foreach( QString aName, aSelectedObjs )
371 aSelectedObjsMap[aName] = true;
374 // Select the appropriate geometry object shape in the viewer
375 selectionMgr()->clearSelected();
377 // Unhighlight all objects except selected
378 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
379 Handle(HYDROData_Entity) anEntity;
380 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
381 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
384 for ( ; anIter.More(); anIter.Next() )
386 anEntity = anIter.Value();
387 if ( !anEntity.IsNull() )
389 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
392 aName = anEntity->GetName();
393 isSelected = aSelectedObjsMap.contains( aName );
394 aShape->highlight( isSelected, false );
395 aShape->update( false, false );
401 aLastShape->update( true, false );
404 void HYDROGUI_CalculationOp::onLandCoverMapSelected( const QString & theObjName )
406 bool anIsToUpdateViewer = false;
408 // Remove old presentation of land cover map from the operation viewer
409 Handle(HYDROData_LandCoverMap) aPrevLandCoverMap = myEditedObject->GetLandCoverMap();
410 if ( !aPrevLandCoverMap.IsNull() )
412 setObjectVisibility( aPrevLandCoverMap, false );
413 anIsToUpdateViewer = true;
416 // Select the appropriate land cover map shape in the viewer
417 selectionMgr()->clearSelected();
419 // Set the selected land cover map to the calculation case
420 Handle(HYDROData_LandCoverMap) aNewLandCoverMap = Handle(HYDROData_LandCoverMap)::DownCast(
421 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_LAND_COVER_MAP ) );
422 myEditedObject->SetLandCoverMap( aNewLandCoverMap );
424 createPreview( true );
427 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
429 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
430 HYDROGUI_Zone* aZoneItem;
431 selectionMgr()->clearSelected();
434 // Select a region in preview
435 SUIT_DataOwnerPtrList aList( true );
436 DataObjectList aZones = aRegionItem->children();
437 for ( int i = 0; i < aZones.length(); i++ )
439 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
442 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
445 selectionMgr()->setSelected( aList );
449 // select a single zone
450 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
453 SUIT_DataOwnerPtrList aList( true );
454 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
455 selectionMgr()->setSelected( aList );
460 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem,
461 const QList<SUIT_DataObject*>& theZonesList )
463 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
466 QList<HYDROGUI_Zone*> aZonesList;
467 HYDROGUI_Zone* aZone;
468 // Get a list of dropped zones
469 for ( int i = 0; i < theZonesList.length(); i++ )
471 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
474 aZonesList.append( aZone );
477 if ( aZonesList.length() > 0 )
479 aRegion->addZones( aZonesList );
480 HYDROGUI_CalculationDlg* aPanel =
481 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
483 aPanel->refreshZonesBrowser();
484 createPreview( false, false, false );
489 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
491 if ( createRegion( theZonesList ) )
493 HYDROGUI_CalculationDlg* aPanel =
494 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
497 aPanel->refreshZonesBrowser();
499 createPreview( false, false, false );
503 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theMergeObjectName )
505 HYDROGUI_CalculationDlg* aPanel =
506 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
509 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
512 aZone->setMergeType( theMergeType, theMergeObjectName );
513 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
516 aShape->update( true, false );
519 aPanel->refreshZonesBrowser();
523 void HYDROGUI_CalculationOp::onAddObjects()
525 HYDROGUI_CalculationDlg* aPanel =
526 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
530 // Add geometry objects selected in the module browser to the calculation case
531 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
532 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
535 QStringList anAddedList;
536 for (int i = 0; i < aSelectedList.length(); i++)
538 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
539 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
540 if ( anObject.IsNull() )
543 if ( myEditedObject->AddGeometryObject( anObject ) )
544 anAddedList.append( anObject->GetName() );
547 for (int i = 0; i < aSelectedList.length(); i++)
549 Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast(
550 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
551 if ( aPoly.IsNull() )
554 if ( myEditedObject->AddInterPoly( aPoly ) )
555 anAddedList.append( aPoly->GetName() );
558 if ( !anAddedList.isEmpty() )
560 aPanel->includeGeomObjects( anAddedList );
561 createPreview( false );
565 void HYDROGUI_CalculationOp::onRemoveObjects()
567 // Remove selected objects from the calculation case
568 HYDROGUI_CalculationDlg* aPanel =
569 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
573 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
574 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
577 for (int i = 0; i < aSelectedList.length(); i++)
579 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
580 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
581 if ( anObject.IsNull() )
584 setObjectVisibility( anObject, false );
585 myEditedObject->RemoveGeometryObject( anObject );
588 for (int i = 0; i < aSelectedList.length(); i++)
590 Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast(
591 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
592 if ( aPoly.IsNull() )
595 setObjectVisibility( aPoly, false );
596 myEditedObject->RemoveInterPolyObject ( aPoly );
599 module()->update( UF_OCCViewer );
600 aPanel->excludeGeomObjects( aSelectedList );
603 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
605 // Check if the case is already modified or not
606 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
609 // If not modified check if the case has already defined regions with zones
610 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
611 if ( aSeq.Length() > 0 )
613 // If there are already defined zones then ask a user to confirm zones recalculation
614 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
615 tr( "REGIONS_CHANGED" ),
616 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
617 QMessageBox::Yes | QMessageBox::No,
618 QMessageBox::No ) == QMessageBox::Yes );
622 isConfirmed = true; // No regions - no zones - nothing to recalculate
628 bool HYDROGUI_CalculationOp::confirmOrderChange() const
630 // Check if the case is already modified or not
631 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
634 // If not modified check if the case has already defined regions with zones
635 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
636 if ( aSeq.Length() > 0 )
638 // If there are already defined zones then ask a user to confirm zones recalculation
639 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
640 tr( "ORDER_CHANGED" ),
641 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
642 QMessageBox::Yes | QMessageBox::No,
643 QMessageBox::No ) == QMessageBox::Yes );
647 isConfirmed = true; // No regions - no zones - nothing to recalculate
653 bool HYDROGUI_CalculationOp::confirmRuleChange() const
655 // Check if the case is already modified or not
656 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
659 // If not modified check if the case has already defined regions with zones
660 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
661 if ( aSeq.Length() > 0 )
663 // If there are already defined zones then ask a user to confirm zones recalculation
664 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
665 tr( "RULE_CHANGED" ),
666 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
667 QMessageBox::Yes | QMessageBox::No,
668 QMessageBox::No ) == QMessageBox::Yes );
672 isConfirmed = true; // No regions - no zones - nothing to recalculate
678 bool HYDROGUI_CalculationOp::confirmModeChange() const
680 // Check if the case is already modified or not
681 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
684 // If not modified check if the case has already defined regions with zones
685 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
686 if ( aSeq.Length() > 0 )
688 // If there are already defined zones then ask a user to confirm zones recalculation
689 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
690 tr( "MODE_CHANGED" ),
691 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
692 QMessageBox::Yes | QMessageBox::No,
693 QMessageBox::No ) == QMessageBox::Yes );
697 isConfirmed = true; // No regions - no zones - nothing to recalculate
703 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
705 HYDROData_WarningType aType = theWarning.Type;
706 if ( aType == WARN_OK ) {
714 case WARN_EMPTY_REGIONS:
715 aTitle = tr( "EMPTY_REGIONS" );
716 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
719 aTitle = tr( "WARNING" );
720 aMsg = theWarning.Data;
724 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
726 QMessageBox::Yes | QMessageBox::No,
729 return ( anAnswer == QMessageBox::Yes );
732 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
733 QString& theErrorMsg,
734 QStringList& theBrowseObjectsEntries )
736 HYDROGUI_CalculationDlg* aPanel =
737 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
743 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
744 theBrowseObjectsEntries.append( anEntry );
747 // For manual mode priority rules are redundant
748 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
749 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
752 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
757 void HYDROGUI_CalculationOp::onApply()
760 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
761 if ( aWarning.Type != WARN_OK ) {
762 if ( !confirmContinueWithWarning( aWarning ) ) {
763 // Go back to the first page
764 HYDROGUI_CalculationDlg* aPanel =
765 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
767 aPanel->onFirstPage();
773 QApplication::setOverrideCursor( Qt::WaitCursor );
775 int anUpdateFlags = 0;
777 QStringList aBrowseObjectsEntries;
779 bool aResult = false;
783 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
785 catch ( Standard_Failure )
787 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
788 anErrorMsg = aFailure->GetMessageString();
796 QApplication::restoreOverrideCursor();
800 module()->update( anUpdateFlags );
802 browseObjects( aBrowseObjectsEntries );
807 QString aMsg = tr( "INPUT_VALID_DATA" );
808 if( !anErrorMsg.isEmpty() )
809 aMsg.prepend( anErrorMsg + "\n" );
810 SUIT_MessageBox::critical( module()->getApp()->desktop(),
811 tr( "INSUFFICIENT_INPUT_DATA" ),
816 void HYDROGUI_CalculationOp::onNext( const int theIndex )
820 setAvailableGroups();
822 else if( theIndex==2 )
824 setAvailableBoundaryPolygons();
826 else if( theIndex==3 )
828 // Land cover map panel
829 HYDROGUI_CalculationDlg* aPanel =
830 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
834 setLandCoverMapVisible( true );
837 QStringList anEntryList;
839 // Get all land cover map objects to fill in combo-box
840 Handle(HYDROData_LandCoverMap) aLandCoverMapObj;
841 QString aLandCoverMapName;
845 HYDROData_Iterator anIter( doc(), KIND_LAND_COVER_MAP );
846 for ( ; anIter.More(); anIter.Next() )
848 aLandCoverMapObj = Handle(HYDROData_LandCoverMap)::DownCast( anIter.Current() );
850 if ( !aLandCoverMapObj.IsNull() )
852 aLandCoverMapName = aLandCoverMapObj->GetName();
853 if ( !aLandCoverMapName.isEmpty() )
855 aList.append( aLandCoverMapName );
856 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aLandCoverMapObj ) );
860 aPanel->setLandCoverMapsNames( aList, anEntryList );
861 aLandCoverMapObj = myEditedObject->GetLandCoverMap();
862 if ( !aList.isEmpty() )
864 if ( aLandCoverMapObj.IsNull() )
865 aPanel->setLandCoverMap( aList.at( 0 ), false );
867 aPanel->setLandCoverMap( aList.at( 0 ), true );
869 aPanel->setLandCoverMap( aList.at( aList.indexOf( aLandCoverMapObj->GetName() ) ), true );
872 // Get all Strickler table objects to fill in combo-box
873 Handle(HYDROData_StricklerTable) aStricklerTableObj;
874 QString aStricklerTableName;
878 anIter = HYDROData_Iterator( doc(), KIND_STRICKLER_TABLE );
879 for ( ; anIter.More(); anIter.Next() )
881 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
883 if ( !aStricklerTableObj.IsNull() )
885 aStricklerTableName = aStricklerTableObj->GetName();
886 if ( !aStricklerTableName.isEmpty() )
888 aList.append( aStricklerTableName );
889 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
893 aPanel->setStricklerTableNames( aList, anEntryList );
894 //@ASL: bool anUpdateState = myEditedObject->IsMustBeUpdated();
895 if ( !aList.isEmpty() )
896 aPanel->setStricklerTable( aList.at( 0 ), false );
897 //@ASL: myEditedObject->SetToUpdate( anUpdateState );
899 if ( !myEditedObject.IsNull() )
903 // Select the certain Strickler table object in combo-box
904 aStricklerTableObj = myEditedObject->GetStricklerTable();
905 if ( aStricklerTableObj.IsNull() )
907 aPanel->setStricklerTable( QString() );
911 aStricklerTableName = aStricklerTableObj->GetName();
912 aPanel->setStricklerTable( aStricklerTableName );
915 // Select the certain land cover map object in combo-box
916 if ( aLandCoverMapObj.IsNull() )
918 aPanel->setLandCoverMap( QString() );
922 aLandCoverMapName = aLandCoverMapObj->GetName();
923 aPanel->setLandCoverMap( aLandCoverMapName );
928 closePreview( false );
929 createPreview( true );
931 else if( theIndex==4 )
933 HYDROGUI_CalculationDlg* aPanel =
934 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
938 QApplication::setOverrideCursor( Qt::WaitCursor );
940 setGeomObjectsVisible( false );
941 setLandCoverMapVisible( false );
943 QString aNewCaseName = aPanel->getObjectName();
944 QString anOldCaseName = myEditedObject->GetName();
945 bool isNameChanged = anOldCaseName != aNewCaseName;
947 bool anIsToUpdateOb = isNameChanged;
949 // At first we must to update the case name because of
950 // automatic names generation for regions and zones
951 myEditedObject->SetName( aNewCaseName );
953 // Zones: set parameters for automatic mode
954 int aMode = aPanel->getMode();
955 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
957 // Set objects in the specified order
958 if( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) )
960 myEditedObject->RemoveGeometryObjects();
961 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
963 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
964 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
965 if ( anObject.IsNull() )
969 myEditedObject->AddGeometryObject( anObject );
972 // Clear priority rules
973 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
974 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
976 // Set priority rules
977 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
978 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
979 aRule.Object2, aRule.MergeType,
980 HYDROData_CalculationCase::DataTag_CustomRules );
984 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
986 if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
989 myEditedObject->Update();
991 AssignDefaultZonesColors();
993 //aPanel->setEditedObject( myEditedObject );
994 aPanel->refreshZonesBrowser();
996 closePreview( false );
997 createPreview( false );
999 anIsToUpdateOb = true;
1004 setZonesVisible( true );
1006 if ( isNameChanged ) {
1007 module()->getDataModel()->updateObjectTree( myEditedObject );
1011 QApplication::restoreOverrideCursor();
1015 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
1019 setGeomObjectsVisible( true );
1021 closePreview( false );
1022 createPreview( false );
1026 setLandCoverMapVisible( true );
1028 closePreview( false );
1029 createPreview( true );
1032 setZonesVisible( false );
1034 else if( theIndex==4 )
1036 AssignDefaultZonesColors();
1038 closePreview( false );
1039 createPreview( false );
1042 setZonesVisible( true );
1046 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
1048 myShowZones = theIsVisible;
1049 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1050 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1051 HYDROData_SequenceOfObjects aZones;
1052 Handle(HYDROData_Region) aRegion;
1053 if ( myPreviewViewManager )
1055 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1057 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1058 if ( !aCtx.IsNull() )
1060 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1062 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1063 if ( !aRegion.IsNull() )
1065 aZones = aRegion->GetZones();
1066 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1067 for ( ; aZonesIter.More(); aZonesIter.Next() )
1069 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1075 module()->update( UF_OCCViewer );
1080 void HYDROGUI_CalculationOp::setGeomObjectsVisible( bool theIsVisible )
1082 myShowGeomObjects = theIsVisible;
1084 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
1086 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1087 for ( ; anIter.More(); anIter.Next() ) {
1088 setObjectVisibility( anIter.Value(), theIsVisible );
1092 void HYDROGUI_CalculationOp::setLandCoverMapVisible( bool theIsVisible )
1094 myShowLandCoverMap = theIsVisible;
1095 setObjectVisibility( myEditedObject->GetLandCoverMap(), theIsVisible );
1098 void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
1100 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1101 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1102 HYDROData_SequenceOfObjects aZones;
1103 Handle(HYDROData_Region) aRegion;
1104 if ( myPreviewViewManager )
1106 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1108 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1109 if ( !aCtx.IsNull() )
1111 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1113 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1114 if ( !aRegion.IsNull() )
1116 aZones = aRegion->GetZones();
1117 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1118 for ( ; aZonesIter.More(); aZonesIter.Next() )
1121 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1122 if ( !aZone.IsNull() )
1124 QColor aFillingColor = HYDROData_Tool::GenerateRandColor();
1125 while (aFillingColor == Qt::red)
1126 aFillingColor = HYDROData_Tool::GenerateRandColor();
1128 aZone->SetColor(aFillingColor);
1138 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1140 HYDROGUI_CalculationDlg* aPanel =
1141 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1145 HYDROData_ListOfRules aRules;
1146 Handle(HYDROData_Entity) anObject1, anObject2;
1147 HYDROData_PriorityType aPriority;
1148 HYDROData_Zone::MergeType aMergeType;
1149 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1150 for ( int anIndex = 0; ; anIndex++ )
1152 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1153 HYDROData_CustomRule aRule;
1154 aRule.Object1 = anObject1;
1155 aRule.Object2 = anObject2;
1156 aRule.Priority = aPriority;
1157 aRule.MergeType = aMergeType;
1165 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1166 aPanel->setRules( aRules );
1169 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList )
1171 bool aRetValue = false;
1173 QList<HYDROGUI_Zone*> aZonesList;
1174 HYDROGUI_Zone* aZone;
1175 // Get a list of dropped zones
1176 for ( int i = 0; i < theZonesList.length(); i++ )
1178 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1181 aZonesList.append( aZone );
1184 if ( aZonesList.length() > 0 )
1186 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
1193 void HYDROGUI_CalculationOp::createPreview( const bool theLandCoverMap, bool fitAllFlag, bool onTopViewAndFit )
1195 LightApp_Application* anApp = module()->getApp();
1196 HYDROData_SequenceOfObjects aSeq;
1197 if ( theLandCoverMap && myShowLandCoverMap )
1199 aSeq.Append( myEditedObject->GetLandCoverMap() );
1201 else if ( !theLandCoverMap && myShowGeomObjects )
1203 HYDROData_SequenceOfObjects aSeqGO = myEditedObject->GetGeometryObjects();
1204 HYDROData_SequenceOfObjects aSeqP = myEditedObject->GetInterPolyObjects();
1205 aSeq.Append( aSeqGO );
1206 aSeq.Append( aSeqP );
1209 Handle(HYDROData_Entity) anEntity;
1213 // Gather zones for displaying
1214 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1215 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1216 HYDROData_SequenceOfObjects aZones;
1217 Handle(HYDROData_Region) aRegion;
1218 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1220 anEntity = aRegionsIter.Value();
1221 if ( !anEntity.IsNull() )
1223 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1224 if ( !aRegion.IsNull() )
1226 aZones = aRegion->GetZones();
1227 aSeq.Append( aZones );
1233 // Get a boundary polyline if any
1234 if (Handle(HYDROData_PolylineXY) aBPoly = myEditedObject->GetBoundaryPolyline())
1235 aSeq.Append( aBPoly );
1237 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1239 if ( !myActiveViewManager )
1241 if ( aSeq.IsEmpty() )
1244 myActiveViewManager = anApp->activeViewManager();
1247 if ( !myPreviewViewManager )
1249 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1250 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1251 if ( myPreviewViewManager )
1253 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1254 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1256 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1257 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1261 if ( !myPreviewViewManager )
1264 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1266 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1267 if ( !aCtx.IsNull() )
1269 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1270 for ( ; anIter.More(); anIter.Next() )
1272 const Handle(HYDROData_Entity)& ent = anIter.Value();
1274 setObjectVisibility( ent, true );
1277 //Process the draw events for viewer
1278 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1281 int UpdateFlags = UF_OCCViewer;
1283 UpdateFlags |= UF_FitAll;
1284 module()->update( UpdateFlags );
1286 OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView();
1287 if ( onTopViewAndFit && vw )
1292 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1294 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1298 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1300 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1304 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1309 void HYDROGUI_CalculationOp::closePreview( bool theRemoveViewManager )
1311 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1312 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1313 QShortcut* aShortcut;
1314 foreach( aShortcut, aShortcuts )
1316 if ( aShortcut->key() ==
1317 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1318 SUIT_DataBrowser::RenameShortcut ) ) )
1320 aShortcut->setEnabled( true );
1325 if( myPreviewViewManager )
1327 // Hide all the displayed objects in the preview view
1328 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1330 size_t aViewId = (size_t)aViewer;
1331 HYDROData_Iterator anIterator( doc() );
1332 for( ; anIterator.More(); anIterator.Next() ) {
1333 Handle(HYDROData_Entity) anObject = anIterator.Current();
1334 if( !anObject.IsNull() ) {
1335 module()->setObjectVisible( aViewId, anObject, false );
1340 if ( theRemoveViewManager )
1342 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1343 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1345 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1346 myPreviewViewManager = NULL;
1350 if( myActiveViewManager && theRemoveViewManager )
1352 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1353 myActiveViewManager = NULL;
1357 void HYDROGUI_CalculationOp::setAvailableGroups()
1359 HYDROGUI_CalculationDlg* aPanel =
1360 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1362 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1363 QStringList aList, anEntryList;
1364 getNamesAndEntries( aSeq, aList, anEntryList );
1366 QStringList aGroupsNames;
1368 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1369 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1371 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anObjs.Value( anIndex ) );
1372 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1373 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1375 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( aGIndex ) );
1376 aGroupsNames.append( aGroup->GetName() );
1379 if( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) ) {
1380 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1381 Handle(HYDROData_ShapesGroup) aGeomGroup =
1382 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1383 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1384 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1389 aPanel->setAvailableGroups( aGroupsNames );
1390 aPanel->includeGroups( aList );
1392 //@ASL: bool isUpdated = myEditedObject->IsMustBeUpdated();
1395 void HYDROGUI_CalculationOp::onAddGroups()
1397 HYDROGUI_CalculationDlg* aPanel =
1398 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1402 // Add geometry objects selected in the module browser to the calculation case
1403 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1404 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1407 QStringList anAddedList;
1408 for (int i = 0; i < aSelectedList.length(); i++)
1410 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1411 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1412 if ( aGroup.IsNull() )
1415 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1416 anAddedList.append( aGroup->GetName() );
1419 if ( !anAddedList.isEmpty() )
1421 aPanel->includeGroups( anAddedList );
1425 void HYDROGUI_CalculationOp::onRemoveGroups()
1427 // Remove selected objects from the calculation case
1428 HYDROGUI_CalculationDlg* aPanel =
1429 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1433 QStringList aSelectedList = aPanel->getSelectedGroups();
1434 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1437 for (int i = 0; i < aSelectedList.length(); i++)
1439 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1440 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1441 if ( aGroup.IsNull() )
1444 myEditedObject->RemoveGeometryGroup( aGroup );
1447 aPanel->excludeGroups( aSelectedList );
1451 void HYDROGUI_CalculationOp::setAvailableBoundaryPolygons()
1453 HYDROGUI_CalculationDlg* aPanel = ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1455 HYDROData_Iterator anIter( doc(), KIND_BC_POLYGON );
1456 Handle(HYDROData_BCPolygon) aBCP;
1458 QVector<int> aTypes;
1459 for (;anIter.More(); anIter.Next())
1461 aBCP = Handle(HYDROData_BCPolygon)::DownCast( anIter.Current() );
1462 aNames.append(aBCP->GetName());
1463 aTypes.append(aBCP->GetBoundaryType());
1465 HYDROData_SequenceOfObjects aBCPSeq = myEditedObject->GetBoundaryPolygons();
1467 QStringList aListCut, aListIS;
1468 for (int i=1; i<=aBCPSeq.Size();i++)
1470 int type = Handle(HYDROData_BCPolygon)::DownCast(aBCPSeq(i))->GetBoundaryType();
1472 aListCut << aBCPSeq(i)->GetName();
1473 else if (type == 2 || type == 3)
1474 aListIS << aBCPSeq(i)->GetName();
1477 aPanel->setAvailableBoundaryPolygons( aNames, aTypes );
1478 aPanel->includeBoundaryPolygons( aListCut );
1479 aPanel->includeISBoundaryPolygons( aListIS );
1482 void HYDROGUI_CalculationOp::onRemoveBoundaryPolygons()
1484 HYDROGUI_CalculationDlg* aPanel =
1485 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1489 QStringList aSelectedListCut = aPanel->getSelectedBoundaryPolygons();
1490 QStringList aSelectedListIS = aPanel->getSelectedISBoundaryPolygons();
1492 if ( aSelectedListCut.isEmpty() && aSelectedListIS.isEmpty() )
1495 for (int i = 0; i < aSelectedListCut.length(); i++)
1497 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast(
1498 HYDROGUI_Tool::FindObjectByName( module(), aSelectedListCut.at(i) ) );
1499 if ( aBCPoly.IsNull() )
1501 myEditedObject->RemoveBoundaryPolygon( aBCPoly );
1504 for (int i = 0; i < aSelectedListIS.length(); i++)
1506 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast(
1507 HYDROGUI_Tool::FindObjectByName( module(), aSelectedListIS.at(i) ) );
1508 if ( aBCPoly.IsNull() )
1510 myEditedObject->RemoveBoundaryPolygon( aBCPoly );
1513 aPanel->excludeBoundaryPolygons( aSelectedListCut );
1514 aPanel->excludeISBoundaryPolygons( aSelectedListIS );
1518 void HYDROGUI_CalculationOp::onAddBoundaryPolygons()
1520 HYDROGUI_CalculationDlg* aPanel = ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1524 QStringList aSelectedList = aPanel->getSelectedAvailableBoundaryPolygons();
1525 if ( aSelectedList.isEmpty())
1528 QStringList anAddedListCut, anAddedListIS;
1529 for (int i = 0; i < aSelectedList.length(); i++)
1531 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast(
1532 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1533 if ( aBCPoly.IsNull() )
1536 if ( myEditedObject->AddBoundaryPolygon( aBCPoly ) )
1538 QString aName = aBCPoly->GetName();
1539 int type = aBCPoly->GetBoundaryType();
1541 anAddedListCut.append(aName);
1542 else if (type == 2 || type == 3)
1543 anAddedListIS.append(aName);
1548 if ( !anAddedListCut.isEmpty() )
1549 aPanel->includeBoundaryPolygons(anAddedListCut);
1550 if ( !anAddedListIS.isEmpty() )
1551 aPanel->includeISBoundaryPolygons(anAddedListIS);
1554 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1556 HYDROGUI_CalculationDlg* aPanel =
1557 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1561 if ( !confirmModeChange() ) {
1562 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1566 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1567 aPanel->setMode( theMode );
1570 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1572 HYDROGUI_CalculationDlg* aPanel =
1573 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1577 isConfirmed = confirmOrderChange();
1579 myEditedObject->Changed( HYDROData_Entity::Geom_2d );
1582 void HYDROGUI_CalculationOp::onRuleChanged( bool& isConfirmed )
1584 HYDROGUI_CalculationDlg* aPanel =
1585 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1589 isConfirmed = confirmRuleChange();
1591 myEditedObject->Changed( HYDROData_Entity::Geom_2d );
1594 void HYDROGUI_CalculationOp::onRegenerateColors()
1596 // For geometry zones
1597 AssignDefaultZonesColors();
1598 setZonesVisible( false );
1599 setZonesVisible( true );