1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_CalculationOp.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_CalculationDlg.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_Tool.h"
29 #include "HYDROGUI_UpdateFlags.h"
30 #include "HYDROGUI_Zone.h"
31 #include "HYDROGUI_Region.h"
33 #include <HYDROData_PolylineXY.h>
34 #include <HYDROData_ShapesGroup.h>
35 #include <HYDROData_Iterator.h>
36 #include <HYDROData_Object.h>
37 #include <HYDROData_Tool.h>
39 #include <OCCViewer_ViewManager.h>
40 #include <OCCViewer_ViewModel.h>
41 #include <OCCViewer_ViewWindow.h>
43 #include <LightApp_Application.h>
44 #include <LightApp_UpdateFlags.h>
45 #include <LightApp_SelectionMgr.h>
46 #include <LightApp_DataOwner.h>
48 #include <SUIT_MessageBox.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_DataBrowser.h>
52 #include <QApplication>
53 #include <QKeySequence>
56 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
57 : HYDROGUI_Operation( theModule ),
58 myIsEdit( theIsEdit ),
59 myActiveViewManager( NULL ),
60 myPreviewViewManager( NULL )
62 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
65 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
70 void HYDROGUI_CalculationOp::startOperation()
72 HYDROGUI_Operation::startOperation();
77 HYDROGUI_CalculationDlg* aPanel =
78 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
82 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
83 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
85 foreach( aShortcut, aShortcuts )
87 if ( aShortcut->key() ==
88 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
89 SUIT_DataBrowser::RenameShortcut ) ) )
91 aShortcut->setEnabled( false );
97 QStringList anEntryList;
98 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
99 getNamesAndEntries( aSeq, aList, anEntryList );
100 aPanel->setAllGeomObjects( aList, anEntryList );
105 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
106 Handle(HYDROData_PolylineXY) aPolylineObj;
107 QString aPolylineName;
108 for ( ; anIter.More(); anIter.Next() )
110 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
112 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
114 // Check the polyline shape
115 TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
116 if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
117 aPolylineName = aPolylineObj->GetName();
118 if ( !aPolylineName.isEmpty() )
120 aList.append( aPolylineName );
121 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
126 aPanel->setPolylineNames( aList, anEntryList );
128 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
130 myEditedObject.Nullify();
133 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
134 if ( !myEditedObject.IsNull() )
136 aPanel->setMode( myEditedObject->GetAssignmentMode() );
137 anObjectName = myEditedObject->GetName();
138 aPolylineObj = myEditedObject->GetBoundaryPolyline();
139 if ( aPolylineObj.IsNull() )
141 aPanel->setBoundary( QString() );
145 aPolylineName = aPolylineObj->GetName();
146 aPanel->setBoundary( aPolylineName );
149 aSeq = myEditedObject->GetGeometryObjects();
150 getNamesAndEntries( aSeq, aList, anEntryList );
151 aPanel->includeGeomObjects( aList );
154 HYDROData_ListOfRules aRules;
155 Handle(HYDROData_Object) anObject1, anObject2;
156 HYDROData_PriorityType aPriority;
157 HYDROData_Zone::MergeAltitudesType aMergeType;
158 int aRulesNb = myEditedObject->GetRulesCount();
159 for ( int anIndex = 0; anIndex < aRulesNb; anIndex++ ) {
160 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType ) ) {
161 HYDROData_CustomRule aRule;
162 aRule.Object1 = anObject1;
163 aRule.Object2 = anObject2;
164 aRule.Priority = aPriority;
165 aRule.MergeType = aMergeType;
170 aPanel->setRules( aRules );
176 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
177 myEditedObject->SetName( anObjectName );
178 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
181 aPanel->setObjectName( anObjectName );
182 aPanel->setEditedObject( myEditedObject );
187 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
188 QStringList& theNames, QStringList& theEntries ) const
193 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
194 for ( ; anIter.More(); anIter.Next() )
196 Handle(HYDROData_Entity) anEntity = anIter.Value();
197 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
200 theNames.append( anEntity->GetName() );
201 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
205 void HYDROGUI_CalculationOp::abortOperation()
210 HYDROGUI_Operation::abortOperation();
211 module()->getApp()->updateObjectBrowser();
214 void HYDROGUI_CalculationOp::commitOperation()
217 // Commit transaction
218 commitDocOperation();
219 HYDROGUI_Operation::commitOperation();
222 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
224 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
226 // Connect signals and slots
227 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
228 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
229 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
230 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
231 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
232 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
233 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) );
234 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
235 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
236 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
237 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
238 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
239 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
240 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
241 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
242 connect( aPanel, SIGNAL( objectsSelected() ),
243 SLOT( onObjectsSelected() ) );
244 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
245 SLOT( onBoundarySelected( 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::onObjectsSelected()
291 HYDROGUI_CalculationDlg* aPanel =
292 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
294 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
295 QMap<QString, bool> aSelectedObjsMap;
296 foreach( QString aName, aSelectedObjs )
297 aSelectedObjsMap[aName] = true;
300 // Select the appropriate geometry object shape in the viewer
301 selectionMgr()->clearSelected();
303 // Unhighlight all objects except selected
304 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
305 Handle(HYDROData_Entity) anEntity;
306 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
307 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
310 for ( ; anIter.More(); anIter.Next() )
312 anEntity = anIter.Value();
313 if ( !anEntity.IsNull() )
315 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
318 aName = anEntity->GetName();
319 isSelected = aSelectedObjsMap.contains( aName );
320 aShape->highlight( isSelected, false );
321 aShape->update( false, false );
327 aLastShape->update( true, false );
330 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
332 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
333 HYDROGUI_Zone* aZoneItem;
334 selectionMgr()->clearSelected();
337 // Select a region in preview
338 SUIT_DataOwnerPtrList aList( true );
339 DataObjectList aZones = aRegionItem->children();
340 for ( int i = 0; i < aZones.length(); i++ )
342 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
345 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
348 selectionMgr()->setSelected( aList );
352 // select a single zone
353 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
356 SUIT_DataOwnerPtrList aList( true );
357 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
358 selectionMgr()->setSelected( aList );
363 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
365 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
368 QList<HYDROGUI_Zone*> aZonesList;
369 HYDROGUI_Zone* aZone;
370 // Get a list of dropped zones
371 for ( int i = 0; i < theZonesList.length(); i++ )
373 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
376 aZonesList.append( aZone );
379 if ( aZonesList.length() > 0 )
381 aRegion->addZones( aZonesList );
382 HYDROGUI_CalculationDlg* aPanel =
383 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
386 aPanel->refreshZonesBrowser();
393 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
395 QList<HYDROGUI_Zone*> aZonesList;
396 HYDROGUI_Zone* aZone;
397 // Get a list of dropped zones
398 for ( int i = 0; i < theZonesList.length(); i++ )
400 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
403 aZonesList.append( aZone );
406 if ( aZonesList.length() > 0 )
408 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
409 HYDROGUI_CalculationDlg* aPanel =
410 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
413 aPanel->refreshZonesBrowser();
419 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theAltitudeName )
421 HYDROGUI_CalculationDlg* aPanel =
422 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
425 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
428 aZone->setMergeType( theMergeType, theAltitudeName );
429 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
432 aShape->update( true, false );
435 aPanel->refreshZonesBrowser();
439 void HYDROGUI_CalculationOp::onAddObjects()
441 HYDROGUI_CalculationDlg* aPanel =
442 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
446 // Add geometry objects selected in the module browser to the calculation case
447 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
448 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
451 QStringList anAddedList;
452 for (int i = 0; i < aSelectedList.length(); i++)
454 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
455 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
456 if ( anObject.IsNull() )
459 if ( myEditedObject->AddGeometryObject( anObject ) )
460 anAddedList.append( anObject->GetName() );
463 if ( !anAddedList.isEmpty() )
465 aPanel->includeGeomObjects( anAddedList );
470 void HYDROGUI_CalculationOp::onRemoveObjects()
472 // Remove selected objects from the calculation case
473 HYDROGUI_CalculationDlg* aPanel =
474 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
478 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
479 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
482 for (int i = 0; i < aSelectedList.length(); i++)
484 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
485 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
486 if ( anObject.IsNull() )
489 setObjectVisibility( anObject, false );
490 myEditedObject->RemoveGeometryObject( anObject );
493 module()->update( UF_OCCViewer );
494 aPanel->excludeGeomObjects( aSelectedList );
497 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
499 // Check if the case is already modified or not
500 bool isConfirmed = myEditedObject->IsMustBeUpdated();
503 // If not modified check if the case has already defined regions with zones
504 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
505 if ( aSeq.Length() > 0 )
507 // If there are already defined zones then ask a user to confirm zones recalculation
508 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
509 tr( "REGIONS_CHANGED" ),
510 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
511 QMessageBox::Yes | QMessageBox::No,
512 QMessageBox::No ) == QMessageBox::Yes );
516 isConfirmed = true; // No regions - no zones - nothing to recalculate
522 bool HYDROGUI_CalculationOp::confirmModeChange() const
524 // Check if the case is already modified or not
525 bool isConfirmed = myEditedObject->IsMustBeUpdated();
528 // If not modified check if the case has already defined regions with zones
529 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
530 if ( aSeq.Length() > 0 )
532 // If there are already defined zones then ask a user to confirm zones recalculation
533 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
534 tr( "MODE_CHANGED" ),
535 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
536 QMessageBox::Yes | QMessageBox::No,
537 QMessageBox::No ) == QMessageBox::Yes );
541 isConfirmed = true; // No regions - no zones - nothing to recalculate
547 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
549 HYDROData_WarningType aType = theWarning.Type;
550 if ( aType == WARN_OK ) {
558 case WARN_EMPTY_REGIONS:
559 aTitle = tr( "EMPTY_REGIONS" );
560 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
563 aTitle = tr( "WARNING" );
564 aMsg = theWarning.Data;
568 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
570 QMessageBox::Yes | QMessageBox::No,
573 return ( anAnswer == QMessageBox::Yes );
576 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
577 QString& theErrorMsg,
578 QStringList& theBrowseObjectsEntries )
580 HYDROGUI_CalculationDlg* aPanel =
581 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
587 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
588 theBrowseObjectsEntries.append( anEntry );
591 // For manual mode priority rules are redundant
592 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL &&
593 myEditedObject->GetRulesCount() > 0 ) {
594 myEditedObject->ClearRules( false );
597 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
602 void HYDROGUI_CalculationOp::onApply()
605 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
606 if ( aWarning.Type != WARN_OK ) {
607 if ( !confirmContinueWithWarning( aWarning ) ) {
608 // Go back to the first page
609 HYDROGUI_CalculationDlg* aPanel =
610 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
612 aPanel->onFirstPage();
618 QApplication::setOverrideCursor( Qt::WaitCursor );
620 int anUpdateFlags = 0;
622 QStringList aBrowseObjectsEntries;
624 bool aResult = false;
628 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
630 catch ( Standard_Failure )
632 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
633 anErrorMsg = aFailure->GetMessageString();
641 QApplication::restoreOverrideCursor();
645 module()->update( anUpdateFlags );
647 browseObjects( aBrowseObjectsEntries );
652 QString aMsg = tr( "INPUT_VALID_DATA" );
653 if( !anErrorMsg.isEmpty() )
654 aMsg.prepend( anErrorMsg + "\n" );
655 SUIT_MessageBox::critical( module()->getApp()->desktop(),
656 tr( "INSUFFICIENT_INPUT_DATA" ),
661 void HYDROGUI_CalculationOp::onNext( const int theIndex )
665 setAvailableGroups();
667 else if( theIndex==2 )
669 HYDROGUI_CalculationDlg* aPanel =
670 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
674 QApplication::setOverrideCursor( Qt::WaitCursor );
676 QString aNewCaseName = aPanel->getObjectName();
677 QString anOldCaseName = myEditedObject->GetName();
678 bool isNameChanged = anOldCaseName != aNewCaseName;
680 bool anIsToUpdateOb = isNameChanged;
682 // At first we must to update the case name because of
683 // automatic names generation for regions and zones
684 myEditedObject->SetName( aNewCaseName );
686 // Set parameters for automatic mode
687 int aMode = aPanel->getMode();
688 if ( aMode == HYDROData_CalculationCase::AUTOMATIC ) {
689 // Set objects in the specified order
690 myEditedObject->RemoveGeometryObjects();
691 foreach ( const QString& aName, aPanel->getAllGeomObjects() ) {
692 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
693 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
694 if ( anObject.IsNull() ) {
698 myEditedObject->AddGeometryObject( anObject );
701 // Clear priority rules
702 if ( myEditedObject->GetRulesCount() > 0 ) {
703 myEditedObject->ClearRules( true );
705 // Set priority rules
706 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
707 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
708 aRule.Object2, aRule.MergeType );
711 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
713 if ( myEditedObject->IsMustBeUpdated() )
716 myEditedObject->Update();
718 //aPanel->setEditedObject( myEditedObject );
719 aPanel->refreshZonesBrowser();
724 anIsToUpdateOb = true;
728 setZonesVisible( true );
730 if ( isNameChanged ) {
731 module()->getDataModel()->updateObjectTree( myEditedObject );
735 if ( anIsToUpdateOb ) {
736 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
737 if ( anObjBrowser ) {
738 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
742 QApplication::restoreOverrideCursor();
746 void HYDROGUI_CalculationOp::onHideZones()
748 setZonesVisible( false );
751 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
753 myShowZones = theIsVisible;
754 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
755 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
756 HYDROData_SequenceOfObjects aZones;
757 Handle(HYDROData_Region) aRegion;
758 if ( myPreviewViewManager )
760 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
762 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
763 if ( !aCtx.IsNull() )
765 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
767 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
768 if ( !aRegion.IsNull() )
770 aZones = aRegion->GetZones();
771 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
772 for ( ; aZonesIter.More(); aZonesIter.Next() )
774 setObjectVisibility( aZonesIter.Value(), theIsVisible );
780 module()->update( UF_OCCViewer );
785 void HYDROGUI_CalculationOp::createPreview()
787 LightApp_Application* anApp = module()->getApp();
788 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
789 Handle(HYDROData_Entity) anEntity;
793 // Gather zones for displaying
794 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
795 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
796 HYDROData_SequenceOfObjects aZones;
797 Handle(HYDROData_Region) aRegion;
798 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
800 anEntity = aRegionsIter.Value();
801 if ( !anEntity.IsNull() )
803 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
804 if ( !aRegion.IsNull() )
806 aZones = aRegion->GetZones();
807 aSeq.Append( aZones );
813 // Get a boundary polyline if any
814 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
816 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
818 if ( !myActiveViewManager )
820 if ( aSeq.IsEmpty() )
823 myActiveViewManager = anApp->activeViewManager();
826 if ( !myPreviewViewManager )
828 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
829 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
830 if ( myPreviewViewManager )
832 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
833 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
835 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
836 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
840 if ( !myPreviewViewManager )
843 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
845 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
846 if ( !aCtx.IsNull() )
848 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
849 for ( ; anIter.More(); anIter.Next() )
851 setObjectVisibility( anIter.Value(), true );
854 //Process the draw events for viewer
855 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
856 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
860 module()->update( UF_OCCViewer | UF_FitAll );
864 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
866 if ( theEntity.IsNull() || !myPreviewViewManager ) {
870 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
872 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
876 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
881 void HYDROGUI_CalculationOp::closePreview()
883 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
884 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
885 QShortcut* aShortcut;
886 foreach( aShortcut, aShortcuts )
888 if ( aShortcut->key() ==
889 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
890 SUIT_DataBrowser::RenameShortcut ) ) )
892 aShortcut->setEnabled( true );
897 if( myPreviewViewManager )
899 // Hide all the displayed objects in the preview view
900 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
902 size_t aViewId = (size_t)aViewer;
903 HYDROData_Iterator anIterator( doc() );
904 for( ; anIterator.More(); anIterator.Next() ) {
905 Handle(HYDROData_Entity) anObject = anIterator.Current();
906 if( !anObject.IsNull() ) {
907 module()->setObjectVisible( aViewId, anObject, false );
912 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
913 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
915 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
916 myPreviewViewManager = NULL;
919 if( myActiveViewManager )
921 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
922 myActiveViewManager = NULL;
926 void HYDROGUI_CalculationOp::setAvailableGroups()
928 HYDROGUI_CalculationDlg* aPanel =
929 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
931 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
932 QStringList aList, anEntryList;
933 getNamesAndEntries( aSeq, aList, anEntryList );
935 QStringList aGroupsNames;
937 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
938 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
940 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
941 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
942 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
944 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
945 aGroupsNames.append( aGroup->GetName() );
948 if( myEditedObject->IsMustBeUpdated() ) {
949 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
950 Handle(HYDROData_ShapesGroup) aGeomGroup =
951 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
952 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
953 myEditedObject->RemoveGeometryGroup( aGeomGroup );
958 aPanel->setAvailableGroups( aGroupsNames );
959 aPanel->includeGroups( aList );
961 bool isUpdated = myEditedObject->IsMustBeUpdated();
964 void HYDROGUI_CalculationOp::onAddGroups()
966 HYDROGUI_CalculationDlg* aPanel =
967 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
971 // Add geometry objects selected in the module browser to the calculation case
972 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
973 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
976 QStringList anAddedList;
977 for (int i = 0; i < aSelectedList.length(); i++)
979 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
980 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
981 if ( aGroup.IsNull() )
984 if ( myEditedObject->AddGeometryGroup( aGroup ) )
985 anAddedList.append( aGroup->GetName() );
988 if ( !anAddedList.isEmpty() )
990 aPanel->includeGroups( anAddedList );
994 void HYDROGUI_CalculationOp::onRemoveGroups()
996 // Remove selected objects from the calculation case
997 HYDROGUI_CalculationDlg* aPanel =
998 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1002 QStringList aSelectedList = aPanel->getSelectedGroups();
1003 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1006 for (int i = 0; i < aSelectedList.length(); i++)
1008 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1009 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1010 if ( aGroup.IsNull() )
1013 myEditedObject->RemoveGeometryGroup( aGroup );
1016 aPanel->excludeGroups( aSelectedList );
1019 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1021 HYDROGUI_CalculationDlg* aPanel =
1022 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1026 if ( !confirmModeChange() ) {
1027 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1031 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1032 aPanel->setMode( theMode );