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_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"
31 #include "HYDROGUI_DataObject.h"
33 #include <HYDROData_Bathymetry.h>
34 #include <HYDROData_Iterator.h>
35 #include <HYDROData_PolylineXY.h>
37 #include <OCCViewer_ViewManager.h>
38 #include <OCCViewer_ViewModel.h>
40 #include <LightApp_Application.h>
41 #include <LightApp_UpdateFlags.h>
43 #include <SUIT_MessageBox.h>
44 #include <SUIT_Desktop.h>
47 #include <TopoDS_Face.hxx>
48 #include <TopoDS_Wire.hxx>
50 #include <QApplication>
52 HYDROGUI_ImmersibleZoneOp::HYDROGUI_ImmersibleZoneOp( HYDROGUI_Module* theModule,
53 const bool theIsEdit )
54 : HYDROGUI_Operation( theModule ),
55 myIsEdit( theIsEdit ),
58 setName( theIsEdit ? tr( "EDIT_IMMERSIBLE_ZONE" ) : tr( "CREATE_IMMERSIBLE_ZONE" ) );
61 HYDROGUI_ImmersibleZoneOp::~HYDROGUI_ImmersibleZoneOp()
66 void HYDROGUI_ImmersibleZoneOp::startOperation()
68 HYDROGUI_Operation::startOperation();
70 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
74 aPanel->blockSignals( true );
78 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMMERSIBLE_ZONE_NAME" ) );
80 QString aSelectedPolyline, aSelectedBathymetry;
81 QStringList aSelectedBathymetries;
85 if ( isApplyAndClose() )
86 myEditedObject = Handle(HYDROData_ImmersibleZone)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
87 if( !myEditedObject.IsNull() )
89 anObjectName = myEditedObject->GetName();
91 Handle(HYDROData_PolylineXY) aRefPolyline = myEditedObject->GetPolyline();
92 if ( !aRefPolyline.IsNull() )
93 aSelectedPolyline = aRefPolyline->GetName();
95 Handle(HYDROData_IAltitudeObject) aRefAltitude = myEditedObject->GetAltitudeObject();
96 if ( !aRefAltitude.IsNull() )
97 aSelectedBathymetry = aRefAltitude->GetName();
101 aPanel->setObjectName( anObjectName );
102 aPanel->setPolylineNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
103 aPanel->setBathymetryNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_BATHYMETRY ) );
105 aPanel->blockSignals( false );
107 aPanel->setPolylineName( aSelectedPolyline );
108 aPanel->setBathymetryName( aSelectedBathymetry );
111 void HYDROGUI_ImmersibleZoneOp::abortOperation()
115 HYDROGUI_Operation::abortOperation();
118 void HYDROGUI_ImmersibleZoneOp::commitOperation()
122 HYDROGUI_Operation::commitOperation();
125 HYDROGUI_InputPanel* HYDROGUI_ImmersibleZoneOp::createInputPanel() const
127 HYDROGUI_ImmersibleZoneDlg* aPanel = new HYDROGUI_ImmersibleZoneDlg( module(), getName() );
128 connect( aPanel, SIGNAL( CreatePreview( const QString& ) ),
129 this, SLOT( onCreatePreview( const QString& ) ) );
133 bool HYDROGUI_ImmersibleZoneOp::processApply( int& theUpdateFlags,
134 QString& theErrorMsg,
135 QStringList& theBrowseObjectsEntries )
137 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
141 QString anObjectName = aPanel->getObjectName().simplified();
142 if ( anObjectName.isEmpty() )
144 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
148 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
150 // check that there are no other objects with the same name in the document
151 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
152 if( !anObject.IsNull() )
154 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
159 Handle(HYDROData_PolylineXY) aZonePolyline;
160 Handle(HYDROData_Bathymetry) aZoneBathymetry;
162 QString aPolylineName = aPanel->getPolylineName();
163 if ( !aPolylineName.isEmpty() )
165 aZonePolyline = Handle(HYDROData_PolylineXY)::DownCast(
166 HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINEXY ) );
169 QString aBathymetryName = aPanel->getBathymetryName();
170 if ( !aBathymetryName.isEmpty() )
172 aZoneBathymetry = Handle(HYDROData_Bathymetry)::DownCast(
173 HYDROGUI_Tool::FindObjectByName( module(), aBathymetryName, KIND_BATHYMETRY ) );
177 if ( HYDROData_ImmersibleZone::generateTopShape( aZonePolyline ).IsNull() )
179 theErrorMsg = tr( "ZONE_OBJECT_CANNOT_BE_CREATED" );
183 Handle(HYDROData_ImmersibleZone) aZoneObj = myIsEdit ? myEditedObject :
184 Handle(HYDROData_ImmersibleZone)::DownCast( doc()->CreateObject( KIND_IMMERSIBLE_ZONE ) );
186 aZoneObj->SetName( anObjectName );
190 aZoneObj->SetFillingColor( HYDROData_ImmersibleZone::DefaultFillingColor() );
191 aZoneObj->SetBorderColor( HYDROData_ImmersibleZone::DefaultBorderColor() );
194 aZoneObj->SetPolyline( aZonePolyline );
195 aZoneObj->SetAltitudeObject( aZoneBathymetry );
202 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aZoneObj, true );
203 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aZoneObj );
204 theBrowseObjectsEntries.append( anEntry );
207 module()->setIsToUpdate( aZoneObj );
209 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
214 void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName )
216 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
220 QApplication::setOverrideCursor( Qt::WaitCursor );
221 TopoDS_Shape aZoneShape;
223 Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast(
224 HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINEXY ) );
225 if ( !aPolyline.IsNull() )
227 aZoneShape = HYDROData_ImmersibleZone::generateTopShape( aPolyline );
228 if( aZoneShape.IsNull() )
229 printErrorMessage( tr( "ZONE_OBJECT_CANNOT_BE_CREATED" ) );
232 LightApp_Application* anApp = module()->getApp();
233 if ( !getPreviewManager() )
234 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
235 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
236 OCCViewer_ViewManager* aViewManager = getPreviewManager();
237 if ( aViewManager && !myPreviewPrs )
239 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
241 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
242 if ( !aCtx.IsNull() )
243 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
247 if ( aViewManager && myPreviewPrs )
249 QColor aFillingColor = HYDROData_ImmersibleZone::DefaultFillingColor();
250 QColor aBorderColor = HYDROData_ImmersibleZone::DefaultBorderColor();
251 if ( !myEditedObject.IsNull() ) {
252 aFillingColor = myEditedObject->GetFillingColor();
253 aBorderColor = myEditedObject->GetBorderColor();
256 myPreviewPrs->setFillingColor( aFillingColor, false, false );
257 myPreviewPrs->setBorderColor( aBorderColor, false, false );
259 if( !aZoneShape.IsNull() )
260 aFace = TopoDS::Face( aZoneShape );
261 myPreviewPrs->setFace( aFace, true, true, "" );
264 QApplication::restoreOverrideCursor();
267 void HYDROGUI_ImmersibleZoneOp::closePreview()