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 );
102 Handle(HYDROData_Calculation)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
105 aPanel->setObjectName( anObjectName );
106 aPanel->setEditedObject( myEditedObject );
107 aPanel->setSelectedGeomObjects( aSelectedObjects );
112 void HYDROGUI_CalculationOp::abortOperation()
116 HYDROGUI_Operation::abortOperation();
119 void HYDROGUI_CalculationOp::commitOperation()
123 HYDROGUI_Operation::commitOperation();
126 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
128 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
130 // Connect signals and slots
135 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
136 QString& theErrorMsg )
138 HYDROGUI_CalculationDlg* aPanel =
139 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
143 QString anObjectName = aPanel->getObjectName().simplified();
144 if ( anObjectName.isEmpty() )
146 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
150 // check that there are no other objects with the same name in the document
151 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
153 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
154 if ( !anObject.IsNull() )
156 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
161 Handle(HYDROData_Document) aDocument = doc();
163 Handle(HYDROData_Calculation) aCalculObj = myIsEdit ? myEditedObject :
164 Handle(HYDROData_Calculation)::DownCast( aDocument->CreateObject( KIND_CALCULATION ) );
165 if ( aCalculObj.IsNull() )
168 aCalculObj->SetName( anObjectName );
170 QStringList aRefObjectNames = aPanel->getSelectedGeomObjects();
171 HYDROData_SequenceOfObjects aGeomObjects =
172 HYDROGUI_Tool::FindObjectsByNames( module(), aRefObjectNames );
174 theUpdateFlags = UF_Model;
179 void HYDROGUI_CalculationOp::onSplitZones()
181 myRegionsList.clear();
183 HYDROGUI_CalculationDlg* aPanel =
184 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
188 QApplication::setOverrideCursor( Qt::WaitCursor );
190 QStringList aGeomObjectNames = aPanel->getSelectedGeomObjects();
191 HYDROData_SequenceOfObjects aGeomObjects =
192 HYDROGUI_Tool::FindObjectsByNames( module(), aGeomObjectNames );
194 QStringList aResSplittedZones;
196 HYDROData_SplitToZonesTool::SplitDataList aSplittedZones =
197 HYDROData_SplitToZonesTool::SplitToZones( aGeomObjects );
199 QStringList aUsedNames;
201 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplittedZones );
202 while( anIter.hasNext() )
205 aRegion.SplitData = anIter.next();
207 aRegion.FillingColor = HYDROGUI_Tool::GenerateFillingColor( module(), aRegion.SplitData.ObjectNames );
208 aRegion.BorderColor = QColor( HYDROData_ImmersibleZone::DefaultBorderColor() );
210 aRegion.RegionName = HYDROGUI_Tool::GenerateObjectName( module(), "Region", aUsedNames );
212 aUsedNames.append( aRegion.RegionName );
214 aResSplittedZones.append( aRegion.RegionName );
216 myRegionsList.append( aRegion );
221 QApplication::restoreOverrideCursor();
224 void HYDROGUI_CalculationOp::createPreview()
226 LightApp_Application* anApp = module()->getApp();
228 if ( !myActiveViewManager )
230 if ( myRegionsList.isEmpty() )
233 myActiveViewManager = anApp->activeViewManager();
236 if ( !myPreviewViewManager )
238 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
239 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
240 if ( myPreviewViewManager )
242 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
243 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
245 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
246 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
250 if ( !myPreviewViewManager )
253 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
255 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
256 if ( !aCtx.IsNull() )
258 RegionsList::iterator anIter = myRegionsList.begin();
259 for ( ; anIter != myRegionsList.end(); ++anIter )
261 Region& aRegion = *anIter;
264 aRegion.Shape->erase( false );
265 delete aRegion.Shape;
268 aRegion.Shape = new HYDROGUI_Shape( aCtx, NULL );
270 aRegion.Shape->setFillingColor( aRegion.FillingColor, false, false );
271 aRegion.Shape->setBorderColor( aRegion.BorderColor, false, false );
272 aRegion.Shape->setFace( aRegion.SplitData.Face(), true, false );
275 //Process the draw events for viewer
276 QApplication::processEvents();
277 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
283 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
288 void HYDROGUI_CalculationOp::closePreview()
290 RegionsList::iterator anIter= myRegionsList.begin();
291 for ( ; anIter != myRegionsList.end(); ++anIter )
293 Region& aRegion = *anIter;
296 aRegion.Shape->erase( false );
297 delete aRegion.Shape;
298 aRegion.Shape = NULL;
302 if( myPreviewViewManager )
304 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
305 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
307 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
308 myPreviewViewManager = NULL;
311 if( myActiveViewManager )
313 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
314 myActiveViewManager = NULL;