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"
31 #include <HYDROData_Polyline.h>
32 #include <HYDROData_Iterator.h>
33 #include <HYDROData_ImmersibleZone.h>
35 #include <OCCViewer_ViewManager.h>
36 #include <OCCViewer_ViewModel.h>
37 #include <OCCViewer_ViewWindow.h>
39 #include <LightApp_Application.h>
40 #include <LightApp_UpdateFlags.h>
42 #include <QApplication>
44 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
45 : HYDROGUI_Operation( theModule ),
46 myIsEdit( theIsEdit ),
47 myActiveViewManager( NULL ),
48 myPreviewViewManager( NULL )
50 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
53 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
58 void HYDROGUI_CalculationOp::startOperation()
60 HYDROGUI_Operation::startOperation();
62 HYDROGUI_CalculationDlg* aPanel =
63 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
67 myRegionsList.clear();
70 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Case" );
72 QStringList aSelectedObjects;
74 myEditedObject.Nullify();
77 myEditedObject = Handle(HYDROData_Calculation)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
78 if ( !myEditedObject.IsNull() )
80 anObjectName = myEditedObject->GetName();
82 HYDROData_SequenceOfObjects aRefObjects = myEditedObject->GetGeometryObjects();
83 HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
84 for ( ; anIter.More(); anIter.Next() )
86 Handle(HYDROData_Object) aRefbject =
87 Handle(HYDROData_Object)::DownCast( anIter.Value() );
88 if ( aRefbject.IsNull() )
91 QString aRefObjectName = aRefbject->GetName();
92 if ( aRefObjectName.isEmpty() )
95 aSelectedObjects.append( aRefObjectName );
100 aPanel->setObjectName( anObjectName );
101 aPanel->setSelectedGeomObjects( aSelectedObjects );
106 void HYDROGUI_CalculationOp::abortOperation()
110 HYDROGUI_Operation::abortOperation();
113 void HYDROGUI_CalculationOp::commitOperation()
117 HYDROGUI_Operation::commitOperation();
120 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
122 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
124 // Connect signals and slots
129 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
130 QString& theErrorMsg )
132 HYDROGUI_CalculationDlg* aPanel =
133 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
137 QString anObjectName = aPanel->getObjectName().simplified();
138 if ( anObjectName.isEmpty() )
140 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
144 // check that there are no other objects with the same name in the document
145 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
147 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
148 if ( !anObject.IsNull() )
150 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
155 Handle(HYDROData_Document) aDocument = doc();
157 Handle(HYDROData_Calculation) aCalculObj = myIsEdit ? myEditedObject :
158 Handle(HYDROData_Calculation)::DownCast( aDocument->CreateObject( KIND_CALCULATION ) );
159 if ( aCalculObj.IsNull() )
162 aCalculObj->SetName( anObjectName );
164 QStringList aRefObjectNames = aPanel->getSelectedGeomObjects();
165 HYDROData_SequenceOfObjects aGeomObjects =
166 HYDROGUI_Tool::FindObjectsByNames( module(), aRefObjectNames );
168 theUpdateFlags = UF_Model;
173 void HYDROGUI_CalculationOp::onSplitZones()
175 myRegionsList.clear();
177 HYDROGUI_CalculationDlg* aPanel =
178 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
182 QApplication::setOverrideCursor( Qt::WaitCursor );
184 QStringList aGeomObjectNames = aPanel->getSelectedGeomObjects();
185 HYDROData_SequenceOfObjects aGeomObjects =
186 HYDROGUI_Tool::FindObjectsByNames( module(), aGeomObjectNames );
188 QStringList aResSplittedZones;
190 HYDROData_SplitToZonesTool::SplitDataList aSplittedZones =
191 HYDROData_SplitToZonesTool::SplitToZones( aGeomObjects );
193 QStringList aUsedNames;
195 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplittedZones );
196 while( anIter.hasNext() )
199 aRegion.SplitData = anIter.next();
201 aRegion.FillingColor = HYDROGUI_Tool::GenerateFillingColor( module(), aRegion.SplitData.ObjectNames );
202 aRegion.BorderColor = QColor( HYDROData_ImmersibleZone::DefaultBorderColor() );
204 aRegion.RegionName = HYDROGUI_Tool::GenerateObjectName( module(), "Region", aUsedNames );
206 aUsedNames.append( aRegion.RegionName );
208 aResSplittedZones.append( aRegion.RegionName );
210 myRegionsList.append( aRegion );
215 QApplication::restoreOverrideCursor();
218 void HYDROGUI_CalculationOp::createPreview()
220 LightApp_Application* anApp = module()->getApp();
222 if ( !myActiveViewManager )
224 if ( myRegionsList.isEmpty() )
227 myActiveViewManager = anApp->activeViewManager();
230 if ( !myPreviewViewManager )
232 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
233 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
234 if ( myPreviewViewManager )
236 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
237 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
239 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
240 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
244 if ( !myPreviewViewManager )
247 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
249 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
250 if ( !aCtx.IsNull() )
252 RegionsList::iterator anIter = myRegionsList.begin();
253 for ( ; anIter != myRegionsList.end(); ++anIter )
255 Region& aRegion = *anIter;
258 aRegion.Shape->erase( false );
259 delete aRegion.Shape;
262 aRegion.Shape = new HYDROGUI_Shape( aCtx, NULL );
264 aRegion.Shape->setFillingColor( aRegion.FillingColor, false, false );
265 aRegion.Shape->setBorderColor( aRegion.BorderColor, false, false );
266 aRegion.Shape->setFace( aRegion.SplitData.Face(), true, false );
269 //Process the draw events for viewer
270 QApplication::processEvents();
271 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
277 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
282 void HYDROGUI_CalculationOp::closePreview()
284 RegionsList::iterator anIter= myRegionsList.begin();
285 for ( ; anIter != myRegionsList.end(); ++anIter )
287 Region& aRegion = *anIter;
290 aRegion.Shape->erase( false );
291 delete aRegion.Shape;
292 aRegion.Shape = NULL;
296 if( myPreviewViewManager )
298 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
299 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
301 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
302 myPreviewViewManager = NULL;
305 if( myActiveViewManager )
307 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
308 myActiveViewManager = NULL;