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_ImmersibleZone.h>
37 #include <HYDROData_Object.h>
38 #include <HYDROData_Tool.h>
40 #include <OCCViewer_ViewManager.h>
41 #include <OCCViewer_ViewModel.h>
42 #include <OCCViewer_ViewWindow.h>
44 #include <LightApp_Application.h>
45 #include <LightApp_UpdateFlags.h>
46 #include <LightApp_SelectionMgr.h>
47 #include <LightApp_DataOwner.h>
49 #include <SUIT_MessageBox.h>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_DataBrowser.h>
53 #include <QApplication>
54 #include <QKeySequence>
57 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
58 : HYDROGUI_Operation( theModule ),
59 myIsEdit( theIsEdit ),
60 myActiveViewManager( NULL ),
61 myPreviewViewManager( NULL )
63 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
66 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
71 void HYDROGUI_CalculationOp::startOperation()
73 HYDROGUI_Operation::startOperation();
78 HYDROGUI_CalculationDlg* aPanel =
79 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
83 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
84 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
86 foreach( aShortcut, aShortcuts )
88 if ( aShortcut->key() ==
89 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
90 SUIT_DataBrowser::RenameShortcut ) ) )
92 aShortcut->setEnabled( false );
98 QStringList anEntryList;
99 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
100 getNamesAndEntries( aSeq, aList, anEntryList );
101 aPanel->setAllGeomObjects( aList, anEntryList );
106 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
107 Handle(HYDROData_PolylineXY) aPolylineObj;
108 QString aPolylineName;
109 for ( ; anIter.More(); anIter.Next() )
111 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
113 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
115 // Check the polyline shape
116 TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
117 if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
118 aPolylineName = aPolylineObj->GetName();
119 if ( !aPolylineName.isEmpty() )
121 aList.append( aPolylineName );
122 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
127 aPanel->setPolylineNames( aList, anEntryList );
129 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
131 myEditedObject.Nullify();
134 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
135 if ( !myEditedObject.IsNull() )
137 aPanel->setMode( myEditedObject->GetAssignmentMode() );
138 anObjectName = myEditedObject->GetName();
139 aPolylineObj = myEditedObject->GetBoundaryPolyline();
140 if ( aPolylineObj.IsNull() )
142 aPanel->setBoundary( QString() );
146 aPolylineName = aPolylineObj->GetName();
147 aPanel->setBoundary( aPolylineName );
150 aSeq = myEditedObject->GetGeometryObjects();
151 getNamesAndEntries( aSeq, aList, anEntryList );
152 aPanel->includeGeomObjects( aList );
155 HYDROData_ListOfRules aRules;
156 Handle(HYDROData_Object) anObject1, anObject2;
157 HYDROData_PriorityType aPriority;
158 HYDROData_Zone::MergeAltitudesType aMergeType;
159 for ( int anIndex = 0; ; anIndex++ )
161 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType ) ) {
162 HYDROData_CustomRule aRule;
163 aRule.Object1 = anObject1;
164 aRule.Object2 = anObject2;
165 aRule.Priority = aPriority;
166 aRule.MergeType = aMergeType;
173 aPanel->setRules( aRules );
179 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
180 myEditedObject->SetName( anObjectName );
181 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
184 aPanel->setObjectName( anObjectName );
185 aPanel->setEditedObject( myEditedObject );
190 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
191 QStringList& theNames, QStringList& theEntries ) const
196 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
197 for ( ; anIter.More(); anIter.Next() )
199 Handle(HYDROData_Entity) anEntity = anIter.Value();
200 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
203 theNames.append( anEntity->GetName() );
204 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
208 void HYDROGUI_CalculationOp::abortOperation()
213 HYDROGUI_Operation::abortOperation();
214 module()->getApp()->updateObjectBrowser();
217 void HYDROGUI_CalculationOp::commitOperation()
220 // Commit transaction
221 commitDocOperation();
222 HYDROGUI_Operation::commitOperation();
225 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
227 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
229 // Connect signals and slots
230 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
231 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
232 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
233 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
234 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
235 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
236 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) );
237 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
238 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
239 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
240 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
241 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
242 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
243 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
244 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
245 connect( aPanel, SIGNAL( objectsSelected() ),
246 SLOT( onObjectsSelected() ) );
247 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
248 SLOT( onBoundarySelected( const QString & ) ) );
253 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
255 bool anIsToUpdateViewer = false;
257 // Remove the old boundary from the operation viewer
258 Handle(HYDROData_PolylineXY) aPrevPolyline =
259 myEditedObject->GetBoundaryPolyline();
260 if ( !aPrevPolyline.IsNull() )
262 setObjectVisibility( aPrevPolyline, false );
263 anIsToUpdateViewer = true;
266 // Set the selected boundary polyline to the calculation case
267 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
268 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
269 myEditedObject->SetBoundaryPolyline( aNewPolyline );
271 if ( myPreviewViewManager )
273 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
276 if ( !aNewPolyline.IsNull() )
278 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
279 if ( !aCtx.IsNull() )
281 setObjectVisibility( aNewPolyline, true );
282 anIsToUpdateViewer = true;
286 if ( anIsToUpdateViewer )
287 module()->update( UF_OCCViewer );
292 void HYDROGUI_CalculationOp::onObjectsSelected()
294 HYDROGUI_CalculationDlg* aPanel =
295 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
297 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
298 QMap<QString, bool> aSelectedObjsMap;
299 foreach( QString aName, aSelectedObjs )
300 aSelectedObjsMap[aName] = true;
303 // Select the appropriate geometry object shape in the viewer
304 selectionMgr()->clearSelected();
306 // Unhighlight all objects except selected
307 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
308 Handle(HYDROData_Entity) anEntity;
309 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
310 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
313 for ( ; anIter.More(); anIter.Next() )
315 anEntity = anIter.Value();
316 if ( !anEntity.IsNull() )
318 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
321 aName = anEntity->GetName();
322 isSelected = aSelectedObjsMap.contains( aName );
323 aShape->highlight( isSelected, false );
324 aShape->update( false, false );
330 aLastShape->update( true, false );
333 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
335 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
336 HYDROGUI_Zone* aZoneItem;
337 selectionMgr()->clearSelected();
340 // Select a region in preview
341 SUIT_DataOwnerPtrList aList( true );
342 DataObjectList aZones = aRegionItem->children();
343 for ( int i = 0; i < aZones.length(); i++ )
345 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
348 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
351 selectionMgr()->setSelected( aList );
355 // select a single zone
356 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
359 SUIT_DataOwnerPtrList aList( true );
360 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
361 selectionMgr()->setSelected( aList );
366 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
368 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
371 QList<HYDROGUI_Zone*> aZonesList;
372 HYDROGUI_Zone* aZone;
373 // Get a list of dropped zones
374 for ( int i = 0; i < theZonesList.length(); i++ )
376 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
379 aZonesList.append( aZone );
382 if ( aZonesList.length() > 0 )
384 aRegion->addZones( aZonesList );
385 HYDROGUI_CalculationDlg* aPanel =
386 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
389 aPanel->refreshZonesBrowser();
396 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
398 QList<HYDROGUI_Zone*> aZonesList;
399 HYDROGUI_Zone* aZone;
400 // Get a list of dropped zones
401 for ( int i = 0; i < theZonesList.length(); i++ )
403 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
406 aZonesList.append( aZone );
409 if ( aZonesList.length() > 0 )
411 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
412 HYDROGUI_CalculationDlg* aPanel =
413 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
416 aPanel->refreshZonesBrowser();
422 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theAltitudeName )
424 HYDROGUI_CalculationDlg* aPanel =
425 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
428 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
431 aZone->setMergeType( theMergeType, theAltitudeName );
432 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
435 aShape->update( true, false );
438 aPanel->refreshZonesBrowser();
442 void HYDROGUI_CalculationOp::onAddObjects()
444 HYDROGUI_CalculationDlg* aPanel =
445 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
449 // Add geometry objects selected in the module browser to the calculation case
450 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
451 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
454 QStringList anAddedList;
455 for (int i = 0; i < aSelectedList.length(); i++)
457 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
458 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
459 if ( anObject.IsNull() )
462 if ( myEditedObject->AddGeometryObject( anObject ) )
463 anAddedList.append( anObject->GetName() );
466 if ( !anAddedList.isEmpty() )
468 aPanel->includeGeomObjects( anAddedList );
473 void HYDROGUI_CalculationOp::onRemoveObjects()
475 // Remove selected objects from the calculation case
476 HYDROGUI_CalculationDlg* aPanel =
477 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
481 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
482 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
485 for (int i = 0; i < aSelectedList.length(); i++)
487 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
488 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
489 if ( anObject.IsNull() )
492 setObjectVisibility( anObject, false );
493 myEditedObject->RemoveGeometryObject( anObject );
496 module()->update( UF_OCCViewer );
497 aPanel->excludeGeomObjects( aSelectedList );
500 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
502 // Check if the case is already modified or not
503 bool isConfirmed = myEditedObject->IsMustBeUpdated();
506 // If not modified check if the case has already defined regions with zones
507 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
508 if ( aSeq.Length() > 0 )
510 // If there are already defined zones then ask a user to confirm zones recalculation
511 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
512 tr( "REGIONS_CHANGED" ),
513 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
514 QMessageBox::Yes | QMessageBox::No,
515 QMessageBox::No ) == QMessageBox::Yes );
519 isConfirmed = true; // No regions - no zones - nothing to recalculate
525 bool HYDROGUI_CalculationOp::confirmModeChange() const
527 // Check if the case is already modified or not
528 bool isConfirmed = myEditedObject->IsMustBeUpdated();
531 // If not modified check if the case has already defined regions with zones
532 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
533 if ( aSeq.Length() > 0 )
535 // If there are already defined zones then ask a user to confirm zones recalculation
536 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
537 tr( "MODE_CHANGED" ),
538 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
539 QMessageBox::Yes | QMessageBox::No,
540 QMessageBox::No ) == QMessageBox::Yes );
544 isConfirmed = true; // No regions - no zones - nothing to recalculate
550 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
552 HYDROData_WarningType aType = theWarning.Type;
553 if ( aType == WARN_OK ) {
561 case WARN_EMPTY_REGIONS:
562 aTitle = tr( "EMPTY_REGIONS" );
563 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
566 aTitle = tr( "WARNING" );
567 aMsg = theWarning.Data;
571 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
573 QMessageBox::Yes | QMessageBox::No,
576 return ( anAnswer == QMessageBox::Yes );
579 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
580 QString& theErrorMsg,
581 QStringList& theBrowseObjectsEntries )
583 HYDROGUI_CalculationDlg* aPanel =
584 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
590 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
591 theBrowseObjectsEntries.append( anEntry );
594 // For manual mode priority rules are redundant
595 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
596 myEditedObject->ClearRules( false );
599 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
604 void HYDROGUI_CalculationOp::onApply()
607 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
608 if ( aWarning.Type != WARN_OK ) {
609 if ( !confirmContinueWithWarning( aWarning ) ) {
610 // Go back to the first page
611 HYDROGUI_CalculationDlg* aPanel =
612 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
614 aPanel->onFirstPage();
620 QApplication::setOverrideCursor( Qt::WaitCursor );
622 int anUpdateFlags = 0;
624 QStringList aBrowseObjectsEntries;
626 bool aResult = false;
630 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
632 catch ( Standard_Failure )
634 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
635 anErrorMsg = aFailure->GetMessageString();
643 QApplication::restoreOverrideCursor();
647 module()->update( anUpdateFlags );
649 browseObjects( aBrowseObjectsEntries );
654 QString aMsg = tr( "INPUT_VALID_DATA" );
655 if( !anErrorMsg.isEmpty() )
656 aMsg.prepend( anErrorMsg + "\n" );
657 SUIT_MessageBox::critical( module()->getApp()->desktop(),
658 tr( "INSUFFICIENT_INPUT_DATA" ),
663 void HYDROGUI_CalculationOp::onNext( const int theIndex )
667 setAvailableGroups();
669 else if( theIndex==2 )
671 HYDROGUI_CalculationDlg* aPanel =
672 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
676 QApplication::setOverrideCursor( Qt::WaitCursor );
678 QString aNewCaseName = aPanel->getObjectName();
679 QString anOldCaseName = myEditedObject->GetName();
680 bool isNameChanged = anOldCaseName != aNewCaseName;
682 bool anIsToUpdateOb = isNameChanged;
684 // At first we must to update the case name because of
685 // automatic names generation for regions and zones
686 myEditedObject->SetName( aNewCaseName );
688 // Set parameters for automatic mode
689 int aMode = aPanel->getMode();
690 if ( aMode == HYDROData_CalculationCase::AUTOMATIC ) {
691 // Set objects in the specified order
692 myEditedObject->RemoveGeometryObjects();
693 foreach ( const QString& aName, aPanel->getAllGeomObjects() ) {
694 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
695 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
696 if ( anObject.IsNull() ) {
700 myEditedObject->AddGeometryObject( anObject );
703 // Clear priority rules
704 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
705 myEditedObject->ClearRules( true );
707 // Set priority rules
708 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
709 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
710 aRule.Object2, aRule.MergeType );
713 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
715 if ( myEditedObject->IsMustBeUpdated() )
718 myEditedObject->Update();
720 AssignDefaultZonesColors();
722 //aPanel->setEditedObject( myEditedObject );
723 aPanel->refreshZonesBrowser();
728 anIsToUpdateOb = true;
732 setZonesVisible( true );
734 if ( isNameChanged ) {
735 module()->getDataModel()->updateObjectTree( myEditedObject );
739 if ( anIsToUpdateOb ) {
740 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
741 if ( anObjBrowser ) {
742 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
746 QApplication::restoreOverrideCursor();
750 void HYDROGUI_CalculationOp::onHideZones()
752 setZonesVisible( false );
755 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
757 myShowZones = theIsVisible;
758 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
759 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
760 HYDROData_SequenceOfObjects aZones;
761 Handle(HYDROData_Region) aRegion;
762 if ( myPreviewViewManager )
764 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
766 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
767 if ( !aCtx.IsNull() )
769 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
771 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
772 if ( !aRegion.IsNull() )
774 aZones = aRegion->GetZones();
775 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
776 for ( ; aZonesIter.More(); aZonesIter.Next() )
778 setObjectVisibility( aZonesIter.Value(), theIsVisible );
784 module()->update( UF_OCCViewer );
789 void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
791 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
792 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
793 HYDROData_SequenceOfObjects aZones;
794 Handle(HYDROData_Region) aRegion;
795 if ( myPreviewViewManager )
797 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
799 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
800 if ( !aCtx.IsNull() )
803 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
805 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
806 if ( !aRegion.IsNull() )
808 aZones = aRegion->GetZones();
809 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
810 for ( ; aZonesIter.More(); aZonesIter.Next() )
813 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
814 if ( !aZone.IsNull() )
816 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
817 while (aFillingColor == Qt::red)
818 aFillingColor = GenerateDefaultZonesColor(++aCounter);
820 aZone->SetColor(aFillingColor);
830 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
831 float theSaturation/* = 0.5*/,
832 float theValue/* = 0.95*/ ) const
834 float aGoldenRatioConjugate = (float)(360./582.);
835 float aHue = (float)rand();
836 aHue += aGoldenRatioConjugate*theIndex;
839 float aR = 0., aG = 0., aB = 0.;
840 int aHueInt = (int)(aHue*6.);
841 float aF = aHue*6. - aHueInt;
842 float aP = theValue * (1. - theSaturation);
843 float aQ = theValue * (1. - aF*theSaturation);
844 float aT = theValue * (1. - (1. - aF) * theSaturation);
847 case 0: { aR = theValue; aG = aT; aB = aP; break; }
848 case 1: { aR = aQ; aG = theValue; aB = aP; break; }
849 case 2: { aR = aP; aG = theValue; aB = aT; break; }
850 case 3: { aR = aP; aG = aQ; aB = theValue; break; }
851 case 4: { aR = aT; aG = aP; aB = theValue; break; }
852 case 5: { aR = theValue; aG = aP; aB = aQ; break; }
856 QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
857 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
860 void HYDROGUI_CalculationOp::createPreview()
862 LightApp_Application* anApp = module()->getApp();
863 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
864 Handle(HYDROData_Entity) anEntity;
868 // Gather zones for displaying
869 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
870 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
871 HYDROData_SequenceOfObjects aZones;
872 Handle(HYDROData_Region) aRegion;
873 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
875 anEntity = aRegionsIter.Value();
876 if ( !anEntity.IsNull() )
878 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
879 if ( !aRegion.IsNull() )
881 aZones = aRegion->GetZones();
882 aSeq.Append( aZones );
888 // Get a boundary polyline if any
889 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
891 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
893 if ( !myActiveViewManager )
895 if ( aSeq.IsEmpty() )
898 myActiveViewManager = anApp->activeViewManager();
901 if ( !myPreviewViewManager )
903 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
904 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
905 if ( myPreviewViewManager )
907 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
908 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
910 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
911 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
915 if ( !myPreviewViewManager )
918 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
920 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
921 if ( !aCtx.IsNull() )
923 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
924 for ( ; anIter.More(); anIter.Next() )
926 setObjectVisibility( anIter.Value(), true );
929 //Process the draw events for viewer
930 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
931 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
935 module()->update( UF_OCCViewer | UF_FitAll );
939 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
941 if ( theEntity.IsNull() || !myPreviewViewManager ) {
945 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
947 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
951 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
956 void HYDROGUI_CalculationOp::closePreview()
958 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
959 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
960 QShortcut* aShortcut;
961 foreach( aShortcut, aShortcuts )
963 if ( aShortcut->key() ==
964 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
965 SUIT_DataBrowser::RenameShortcut ) ) )
967 aShortcut->setEnabled( true );
972 if( myPreviewViewManager )
974 // Hide all the displayed objects in the preview view
975 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
977 size_t aViewId = (size_t)aViewer;
978 HYDROData_Iterator anIterator( doc() );
979 for( ; anIterator.More(); anIterator.Next() ) {
980 Handle(HYDROData_Entity) anObject = anIterator.Current();
981 if( !anObject.IsNull() ) {
982 module()->setObjectVisible( aViewId, anObject, false );
987 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
988 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
990 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
991 myPreviewViewManager = NULL;
994 if( myActiveViewManager )
996 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
997 myActiveViewManager = NULL;
1001 void HYDROGUI_CalculationOp::setAvailableGroups()
1003 HYDROGUI_CalculationDlg* aPanel =
1004 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1006 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1007 QStringList aList, anEntryList;
1008 getNamesAndEntries( aSeq, aList, anEntryList );
1010 QStringList aGroupsNames;
1012 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1013 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1015 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1016 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1017 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1019 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1020 aGroupsNames.append( aGroup->GetName() );
1023 if( myEditedObject->IsMustBeUpdated() ) {
1024 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1025 Handle(HYDROData_ShapesGroup) aGeomGroup =
1026 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1027 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1028 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1033 aPanel->setAvailableGroups( aGroupsNames );
1034 aPanel->includeGroups( aList );
1036 bool isUpdated = myEditedObject->IsMustBeUpdated();
1039 void HYDROGUI_CalculationOp::onAddGroups()
1041 HYDROGUI_CalculationDlg* aPanel =
1042 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1046 // Add geometry objects selected in the module browser to the calculation case
1047 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1048 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1051 QStringList anAddedList;
1052 for (int i = 0; i < aSelectedList.length(); i++)
1054 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1055 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1056 if ( aGroup.IsNull() )
1059 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1060 anAddedList.append( aGroup->GetName() );
1063 if ( !anAddedList.isEmpty() )
1065 aPanel->includeGroups( anAddedList );
1069 void HYDROGUI_CalculationOp::onRemoveGroups()
1071 // Remove selected objects from the calculation case
1072 HYDROGUI_CalculationDlg* aPanel =
1073 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1077 QStringList aSelectedList = aPanel->getSelectedGroups();
1078 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1081 for (int i = 0; i < aSelectedList.length(); i++)
1083 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1084 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1085 if ( aGroup.IsNull() )
1088 myEditedObject->RemoveGeometryGroup( aGroup );
1091 aPanel->excludeGroups( aSelectedList );
1094 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1096 HYDROGUI_CalculationDlg* aPanel =
1097 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1101 if ( !confirmModeChange() ) {
1102 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1106 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1107 aPanel->setMode( theMode );