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_ImmersibleZoneOp.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_ImmersibleZoneDlg.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_Shape.h"
29 #include "HYDROGUI_Tool.h"
30 #include "HYDROGUI_UpdateFlags.h"
32 #include <HYDROData_Bathymetry.h>
33 #include <HYDROData_Iterator.h>
34 #include <HYDROData_PolylineXY.h>
36 #include <OCCViewer_ViewManager.h>
37 #include <OCCViewer_ViewModel.h>
39 #include <LightApp_Application.h>
40 #include <LightApp_UpdateFlags.h>
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_Desktop.h>
46 #include <TopoDS_Wire.hxx>
48 #include <QApplication>
50 HYDROGUI_ImmersibleZoneOp::HYDROGUI_ImmersibleZoneOp( HYDROGUI_Module* theModule,
51 const bool theIsEdit )
52 : HYDROGUI_Operation( theModule ),
53 myIsEdit( theIsEdit ),
56 setName( theIsEdit ? tr( "EDIT_IMMERSIBLE_ZONE" ) : tr( "CREATE_IMMERSIBLE_ZONE" ) );
59 HYDROGUI_ImmersibleZoneOp::~HYDROGUI_ImmersibleZoneOp()
64 void HYDROGUI_ImmersibleZoneOp::startOperation()
66 HYDROGUI_Operation::startOperation();
68 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
72 aPanel->blockSignals( true );
76 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMMERSIBLE_ZONE_NAME" ) );
78 QString aSelectedPolyline, aSelectedBathymetry;
79 QStringList aSelectedBathymetries;
83 myEditedObject = Handle(HYDROData_ImmersibleZone)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
84 if( !myEditedObject.IsNull() )
86 anObjectName = myEditedObject->GetName();
88 Handle(HYDROData_PolylineXY) aRefPolyline = myEditedObject->GetPolyline();
89 if ( !aRefPolyline.IsNull() )
90 aSelectedPolyline = aRefPolyline->GetName();
92 Handle(HYDROData_IAltitudeObject) aRefAltitude = myEditedObject->GetAltitudeObject();
93 if ( !aRefAltitude.IsNull() )
94 aSelectedBathymetry = aRefAltitude->GetName();
98 aPanel->setObjectName( anObjectName );
99 aPanel->setPolylineNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
100 aPanel->setBathymetryNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_BATHYMETRY ) );
102 aPanel->blockSignals( false );
104 aPanel->setPolylineName( aSelectedPolyline );
105 aPanel->setBathymetryName( aSelectedBathymetry );
108 void HYDROGUI_ImmersibleZoneOp::abortOperation()
112 HYDROGUI_Operation::abortOperation();
115 void HYDROGUI_ImmersibleZoneOp::commitOperation()
119 HYDROGUI_Operation::commitOperation();
122 HYDROGUI_InputPanel* HYDROGUI_ImmersibleZoneOp::createInputPanel() const
124 HYDROGUI_ImmersibleZoneDlg* aPanel = new HYDROGUI_ImmersibleZoneDlg( module(), getName() );
125 connect( aPanel, SIGNAL( CreatePreview( const QString& ) ),
126 this, SLOT( onCreatePreview( const QString& ) ) );
130 bool HYDROGUI_ImmersibleZoneOp::processApply( int& theUpdateFlags,
131 QString& theErrorMsg )
133 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
137 QString anObjectName = aPanel->getObjectName().simplified();
138 if ( anObjectName.isEmpty() )
140 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
144 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
146 // check that there are no other objects with the same name in the document
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_PolylineXY) aZonePolyline;
156 Handle(HYDROData_Bathymetry) aZoneBathymetry;
158 QString aPolylineName = aPanel->getPolylineName();
159 if ( !aPolylineName.isEmpty() )
161 aZonePolyline = Handle(HYDROData_PolylineXY)::DownCast(
162 HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINEXY ) );
165 QString aBathymetryName = aPanel->getBathymetryName();
166 if ( !aBathymetryName.isEmpty() )
168 aZoneBathymetry = Handle(HYDROData_Bathymetry)::DownCast(
169 HYDROGUI_Tool::FindObjectByName( module(), aBathymetryName, KIND_BATHYMETRY ) );
173 if ( HYDROData_ImmersibleZone::generateTopShape( aZonePolyline ).IsNull() )
175 theErrorMsg = tr( "ZONE_OBJECT_CANNOT_BE_CREATED" );
179 Handle(HYDROData_ImmersibleZone) aZoneObj = myIsEdit ? myEditedObject :
180 Handle(HYDROData_ImmersibleZone)::DownCast( doc()->CreateObject( KIND_IMMERSIBLE_ZONE ) );
182 aZoneObj->SetName( anObjectName );
186 aZoneObj->SetFillingColor( HYDROData_ImmersibleZone::DefaultFillingColor() );
187 aZoneObj->SetBorderColor( HYDROData_ImmersibleZone::DefaultBorderColor() );
190 aZoneObj->SetPolyline( aZonePolyline );
191 aZoneObj->SetAltitudeObject( aZoneBathymetry );
197 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aZoneObj, true );
199 module()->setIsToUpdate( aZoneObj );
201 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
206 void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName )
208 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
212 QApplication::setOverrideCursor( Qt::WaitCursor );
213 TopoDS_Shape aZoneShape;
215 Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast(
216 HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINEXY ) );
217 if ( !aPolyline.IsNull() )
219 aZoneShape = HYDROData_ImmersibleZone::generateTopShape( aPolyline );
220 if( aZoneShape.IsNull() )
221 printErrorMessage( tr( "ZONE_OBJECT_CANNOT_BE_CREATED" ) );
224 LightApp_Application* anApp = module()->getApp();
225 if ( !getPreviewManager() )
226 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
227 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
228 OCCViewer_ViewManager* aViewManager = getPreviewManager();
229 if ( aViewManager && !myPreviewPrs )
231 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
233 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
234 if ( !aCtx.IsNull() )
235 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
239 if ( aViewManager && myPreviewPrs )
241 QColor aFillingColor = HYDROData_ImmersibleZone::DefaultFillingColor();
242 QColor aBorderColor = HYDROData_ImmersibleZone::DefaultBorderColor();
243 if ( !myEditedObject.IsNull() ) {
244 aFillingColor = myEditedObject->GetFillingColor();
245 aBorderColor = myEditedObject->GetBorderColor();
248 myPreviewPrs->setFillingColor( aFillingColor, false, false );
249 myPreviewPrs->setBorderColor( aBorderColor, false, false );
251 if( !aZoneShape.IsNull() )
252 aFace = TopoDS::Face( aZoneShape );
253 myPreviewPrs->setFace( aFace );
256 QApplication::restoreOverrideCursor();
259 void HYDROGUI_ImmersibleZoneOp::closePreview()