1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 for ( int anIndex = 0; ; 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;
172 aPanel->setRules( aRules );
178 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
179 myEditedObject->SetName( anObjectName );
180 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
183 aPanel->setObjectName( anObjectName );
184 aPanel->setEditedObject( myEditedObject );
189 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
190 QStringList& theNames, QStringList& theEntries ) const
195 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
196 for ( ; anIter.More(); anIter.Next() )
198 Handle(HYDROData_Entity) anEntity = anIter.Value();
199 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
202 theNames.append( anEntity->GetName() );
203 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
207 void HYDROGUI_CalculationOp::abortOperation()
212 HYDROGUI_Operation::abortOperation();
213 module()->getApp()->updateObjectBrowser();
216 void HYDROGUI_CalculationOp::commitOperation()
219 // Commit transaction
220 commitDocOperation();
221 HYDROGUI_Operation::commitOperation();
224 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
226 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
228 // Connect signals and slots
229 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
230 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
231 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
232 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
233 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
234 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
235 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) );
236 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
237 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
238 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
239 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
240 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
241 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
242 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
243 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
244 connect( aPanel, SIGNAL( objectsSelected() ),
245 SLOT( onObjectsSelected() ) );
246 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
247 SLOT( onBoundarySelected( const QString & ) ) );
252 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
254 bool anIsToUpdateViewer = false;
256 // Remove the old boundary from the operation viewer
257 Handle(HYDROData_PolylineXY) aPrevPolyline =
258 myEditedObject->GetBoundaryPolyline();
259 if ( !aPrevPolyline.IsNull() )
261 setObjectVisibility( aPrevPolyline, false );
262 anIsToUpdateViewer = true;
265 // Set the selected boundary polyline to the calculation case
266 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
267 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
268 myEditedObject->SetBoundaryPolyline( aNewPolyline );
270 if ( myPreviewViewManager )
272 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
275 if ( !aNewPolyline.IsNull() )
277 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
278 if ( !aCtx.IsNull() )
280 setObjectVisibility( aNewPolyline, true );
281 anIsToUpdateViewer = true;
285 if ( anIsToUpdateViewer )
286 module()->update( UF_OCCViewer );
291 void HYDROGUI_CalculationOp::onObjectsSelected()
293 HYDROGUI_CalculationDlg* aPanel =
294 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
296 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
297 QMap<QString, bool> aSelectedObjsMap;
298 foreach( QString aName, aSelectedObjs )
299 aSelectedObjsMap[aName] = true;
302 // Select the appropriate geometry object shape in the viewer
303 selectionMgr()->clearSelected();
305 // Unhighlight all objects except selected
306 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
307 Handle(HYDROData_Entity) anEntity;
308 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
309 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
312 for ( ; anIter.More(); anIter.Next() )
314 anEntity = anIter.Value();
315 if ( !anEntity.IsNull() )
317 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
320 aName = anEntity->GetName();
321 isSelected = aSelectedObjsMap.contains( aName );
322 aShape->highlight( isSelected, false );
323 aShape->update( false, false );
329 aLastShape->update( true, false );
332 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
334 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
335 HYDROGUI_Zone* aZoneItem;
336 selectionMgr()->clearSelected();
339 // Select a region in preview
340 SUIT_DataOwnerPtrList aList( true );
341 DataObjectList aZones = aRegionItem->children();
342 for ( int i = 0; i < aZones.length(); i++ )
344 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
347 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
350 selectionMgr()->setSelected( aList );
354 // select a single zone
355 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
358 SUIT_DataOwnerPtrList aList( true );
359 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
360 selectionMgr()->setSelected( aList );
365 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
367 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
370 QList<HYDROGUI_Zone*> aZonesList;
371 HYDROGUI_Zone* aZone;
372 // Get a list of dropped zones
373 for ( int i = 0; i < theZonesList.length(); i++ )
375 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
378 aZonesList.append( aZone );
381 if ( aZonesList.length() > 0 )
383 aRegion->addZones( aZonesList );
384 HYDROGUI_CalculationDlg* aPanel =
385 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
388 aPanel->refreshZonesBrowser();
395 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
397 QList<HYDROGUI_Zone*> aZonesList;
398 HYDROGUI_Zone* aZone;
399 // Get a list of dropped zones
400 for ( int i = 0; i < theZonesList.length(); i++ )
402 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
405 aZonesList.append( aZone );
408 if ( aZonesList.length() > 0 )
410 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
411 HYDROGUI_CalculationDlg* aPanel =
412 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
415 aPanel->refreshZonesBrowser();
421 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theAltitudeName )
423 HYDROGUI_CalculationDlg* aPanel =
424 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
427 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
430 aZone->setMergeType( theMergeType, theAltitudeName );
431 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
434 aShape->update( true, false );
437 aPanel->refreshZonesBrowser();
441 void HYDROGUI_CalculationOp::onAddObjects()
443 HYDROGUI_CalculationDlg* aPanel =
444 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
448 // Add geometry objects selected in the module browser to the calculation case
449 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
450 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
453 QStringList anAddedList;
454 for (int i = 0; i < aSelectedList.length(); i++)
456 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
457 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
458 if ( anObject.IsNull() )
461 if ( myEditedObject->AddGeometryObject( anObject ) )
462 anAddedList.append( anObject->GetName() );
465 if ( !anAddedList.isEmpty() )
467 aPanel->includeGeomObjects( anAddedList );
472 void HYDROGUI_CalculationOp::onRemoveObjects()
474 // Remove selected objects from the calculation case
475 HYDROGUI_CalculationDlg* aPanel =
476 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
480 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
481 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
484 for (int i = 0; i < aSelectedList.length(); i++)
486 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
487 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
488 if ( anObject.IsNull() )
491 setObjectVisibility( anObject, false );
492 myEditedObject->RemoveGeometryObject( anObject );
495 module()->update( UF_OCCViewer );
496 aPanel->excludeGeomObjects( aSelectedList );
499 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
501 // Check if the case is already modified or not
502 bool isConfirmed = myEditedObject->IsMustBeUpdated();
505 // If not modified check if the case has already defined regions with zones
506 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
507 if ( aSeq.Length() > 0 )
509 // If there are already defined zones then ask a user to confirm zones recalculation
510 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
511 tr( "REGIONS_CHANGED" ),
512 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
513 QMessageBox::Yes | QMessageBox::No,
514 QMessageBox::No ) == QMessageBox::Yes );
518 isConfirmed = true; // No regions - no zones - nothing to recalculate
524 bool HYDROGUI_CalculationOp::confirmModeChange() const
526 // Check if the case is already modified or not
527 bool isConfirmed = myEditedObject->IsMustBeUpdated();
530 // If not modified check if the case has already defined regions with zones
531 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
532 if ( aSeq.Length() > 0 )
534 // If there are already defined zones then ask a user to confirm zones recalculation
535 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
536 tr( "MODE_CHANGED" ),
537 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
538 QMessageBox::Yes | QMessageBox::No,
539 QMessageBox::No ) == QMessageBox::Yes );
543 isConfirmed = true; // No regions - no zones - nothing to recalculate
549 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
551 HYDROData_WarningType aType = theWarning.Type;
552 if ( aType == WARN_OK ) {
560 case WARN_EMPTY_REGIONS:
561 aTitle = tr( "EMPTY_REGIONS" );
562 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
565 aTitle = tr( "WARNING" );
566 aMsg = theWarning.Data;
570 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
572 QMessageBox::Yes | QMessageBox::No,
575 return ( anAnswer == QMessageBox::Yes );
578 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
579 QString& theErrorMsg,
580 QStringList& theBrowseObjectsEntries )
582 HYDROGUI_CalculationDlg* aPanel =
583 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
589 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
590 theBrowseObjectsEntries.append( anEntry );
593 // For manual mode priority rules are redundant
594 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
595 myEditedObject->ClearRules( false );
598 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
603 void HYDROGUI_CalculationOp::onApply()
606 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
607 if ( aWarning.Type != WARN_OK ) {
608 if ( !confirmContinueWithWarning( aWarning ) ) {
609 // Go back to the first page
610 HYDROGUI_CalculationDlg* aPanel =
611 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
613 aPanel->onFirstPage();
619 QApplication::setOverrideCursor( Qt::WaitCursor );
621 int anUpdateFlags = 0;
623 QStringList aBrowseObjectsEntries;
625 bool aResult = false;
629 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
631 catch ( Standard_Failure )
633 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
634 anErrorMsg = aFailure->GetMessageString();
642 QApplication::restoreOverrideCursor();
646 module()->update( anUpdateFlags );
648 browseObjects( aBrowseObjectsEntries );
653 QString aMsg = tr( "INPUT_VALID_DATA" );
654 if( !anErrorMsg.isEmpty() )
655 aMsg.prepend( anErrorMsg + "\n" );
656 SUIT_MessageBox::critical( module()->getApp()->desktop(),
657 tr( "INSUFFICIENT_INPUT_DATA" ),
662 void HYDROGUI_CalculationOp::onNext( const int theIndex )
666 setAvailableGroups();
668 else if( theIndex==2 )
670 HYDROGUI_CalculationDlg* aPanel =
671 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
675 QApplication::setOverrideCursor( Qt::WaitCursor );
677 QString aNewCaseName = aPanel->getObjectName();
678 QString anOldCaseName = myEditedObject->GetName();
679 bool isNameChanged = anOldCaseName != aNewCaseName;
681 bool anIsToUpdateOb = isNameChanged;
683 // At first we must to update the case name because of
684 // automatic names generation for regions and zones
685 myEditedObject->SetName( aNewCaseName );
687 // Set parameters for automatic mode
688 int aMode = aPanel->getMode();
689 if ( aMode == HYDROData_CalculationCase::AUTOMATIC ) {
690 // Set objects in the specified order
691 myEditedObject->RemoveGeometryObjects();
692 foreach ( const QString& aName, aPanel->getAllGeomObjects() ) {
693 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
694 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
695 if ( anObject.IsNull() ) {
699 myEditedObject->AddGeometryObject( anObject );
702 // Clear priority rules
703 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
704 myEditedObject->ClearRules( true );
706 // Set priority rules
707 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
708 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
709 aRule.Object2, aRule.MergeType );
712 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
714 if ( myEditedObject->IsMustBeUpdated() )
717 myEditedObject->Update();
719 //aPanel->setEditedObject( myEditedObject );
720 aPanel->refreshZonesBrowser();
725 anIsToUpdateOb = true;
729 setZonesVisible( true );
731 if ( isNameChanged ) {
732 module()->getDataModel()->updateObjectTree( myEditedObject );
736 if ( anIsToUpdateOb ) {
737 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
738 if ( anObjBrowser ) {
739 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
743 QApplication::restoreOverrideCursor();
747 void HYDROGUI_CalculationOp::onHideZones()
749 setZonesVisible( false );
752 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
754 myShowZones = theIsVisible;
755 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
756 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
757 HYDROData_SequenceOfObjects aZones;
758 Handle(HYDROData_Region) aRegion;
759 if ( myPreviewViewManager )
761 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
763 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
764 if ( !aCtx.IsNull() )
766 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
768 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
769 if ( !aRegion.IsNull() )
771 aZones = aRegion->GetZones();
772 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
773 for ( ; aZonesIter.More(); aZonesIter.Next() )
775 setObjectVisibility( aZonesIter.Value(), theIsVisible );
781 module()->update( UF_OCCViewer );
786 void HYDROGUI_CalculationOp::createPreview()
788 LightApp_Application* anApp = module()->getApp();
789 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
790 Handle(HYDROData_Entity) anEntity;
794 // Gather zones for displaying
795 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
796 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
797 HYDROData_SequenceOfObjects aZones;
798 Handle(HYDROData_Region) aRegion;
799 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
801 anEntity = aRegionsIter.Value();
802 if ( !anEntity.IsNull() )
804 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
805 if ( !aRegion.IsNull() )
807 aZones = aRegion->GetZones();
808 aSeq.Append( aZones );
814 // Get a boundary polyline if any
815 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
817 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
819 if ( !myActiveViewManager )
821 if ( aSeq.IsEmpty() )
824 myActiveViewManager = anApp->activeViewManager();
827 if ( !myPreviewViewManager )
829 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
830 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
831 if ( myPreviewViewManager )
833 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
834 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
836 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
837 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
841 if ( !myPreviewViewManager )
844 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
846 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
847 if ( !aCtx.IsNull() )
849 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
850 for ( ; anIter.More(); anIter.Next() )
852 setObjectVisibility( anIter.Value(), true );
855 //Process the draw events for viewer
856 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
857 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
861 module()->update( UF_OCCViewer | UF_FitAll );
865 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
867 if ( theEntity.IsNull() || !myPreviewViewManager ) {
871 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
873 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
877 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
882 void HYDROGUI_CalculationOp::closePreview()
884 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
885 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
886 QShortcut* aShortcut;
887 foreach( aShortcut, aShortcuts )
889 if ( aShortcut->key() ==
890 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
891 SUIT_DataBrowser::RenameShortcut ) ) )
893 aShortcut->setEnabled( true );
898 if( myPreviewViewManager )
900 // Hide all the displayed objects in the preview view
901 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
903 size_t aViewId = (size_t)aViewer;
904 HYDROData_Iterator anIterator( doc() );
905 for( ; anIterator.More(); anIterator.Next() ) {
906 Handle(HYDROData_Entity) anObject = anIterator.Current();
907 if( !anObject.IsNull() ) {
908 module()->setObjectVisible( aViewId, anObject, false );
913 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
914 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
916 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
917 myPreviewViewManager = NULL;
920 if( myActiveViewManager )
922 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
923 myActiveViewManager = NULL;
927 void HYDROGUI_CalculationOp::setAvailableGroups()
929 HYDROGUI_CalculationDlg* aPanel =
930 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
932 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
933 QStringList aList, anEntryList;
934 getNamesAndEntries( aSeq, aList, anEntryList );
936 QStringList aGroupsNames;
938 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
939 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
941 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
942 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
943 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
945 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
946 aGroupsNames.append( aGroup->GetName() );
949 if( myEditedObject->IsMustBeUpdated() ) {
950 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
951 Handle(HYDROData_ShapesGroup) aGeomGroup =
952 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
953 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
954 myEditedObject->RemoveGeometryGroup( aGeomGroup );
959 aPanel->setAvailableGroups( aGroupsNames );
960 aPanel->includeGroups( aList );
962 bool isUpdated = myEditedObject->IsMustBeUpdated();
965 void HYDROGUI_CalculationOp::onAddGroups()
967 HYDROGUI_CalculationDlg* aPanel =
968 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
972 // Add geometry objects selected in the module browser to the calculation case
973 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
974 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
977 QStringList anAddedList;
978 for (int i = 0; i < aSelectedList.length(); i++)
980 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
981 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
982 if ( aGroup.IsNull() )
985 if ( myEditedObject->AddGeometryGroup( aGroup ) )
986 anAddedList.append( aGroup->GetName() );
989 if ( !anAddedList.isEmpty() )
991 aPanel->includeGroups( anAddedList );
995 void HYDROGUI_CalculationOp::onRemoveGroups()
997 // Remove selected objects from the calculation case
998 HYDROGUI_CalculationDlg* aPanel =
999 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1003 QStringList aSelectedList = aPanel->getSelectedGroups();
1004 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1007 for (int i = 0; i < aSelectedList.length(); i++)
1009 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1010 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1011 if ( aGroup.IsNull() )
1014 myEditedObject->RemoveGeometryGroup( aGroup );
1017 aPanel->excludeGroups( aSelectedList );
1020 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1022 HYDROGUI_CalculationDlg* aPanel =
1023 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1027 if ( !confirmModeChange() ) {
1028 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1032 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1033 aPanel->setMode( theMode );