1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ImmersibleZoneOp.h"
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_ImmersibleZoneDlg.h"
23 #include "HYDROGUI_Module.h"
24 #include "HYDROGUI_Shape.h"
25 #include "HYDROGUI_Tool.h"
26 #include "HYDROGUI_UpdateFlags.h"
27 #include "HYDROGUI_DataObject.h"
29 #include <HYDROData_Bathymetry.h>
30 #include <HYDROData_Iterator.h>
31 #include <HYDROData_PolylineXY.h>
33 #include <OCCViewer_ViewManager.h>
34 #include <OCCViewer_ViewModel.h>
36 #include <LightApp_Application.h>
37 #include <LightApp_UpdateFlags.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_Desktop.h>
43 #include <TopoDS_Face.hxx>
44 #include <TopoDS_Wire.hxx>
46 #include <QApplication>
48 HYDROGUI_ImmersibleZoneOp::HYDROGUI_ImmersibleZoneOp( HYDROGUI_Module* theModule,
49 const bool theIsEdit )
50 : HYDROGUI_Operation( theModule ),
51 myIsEdit( theIsEdit ),
54 setName( theIsEdit ? tr( "EDIT_IMMERSIBLE_ZONE" ) : tr( "CREATE_IMMERSIBLE_ZONE" ) );
57 HYDROGUI_ImmersibleZoneOp::~HYDROGUI_ImmersibleZoneOp()
62 void HYDROGUI_ImmersibleZoneOp::startOperation()
64 HYDROGUI_Operation::startOperation();
66 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
70 aPanel->blockSignals( true );
74 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMMERSIBLE_ZONE_NAME" ) );
76 QString aSelectedPolyline, aSelectedBathymetry;
77 QStringList aSelectedBathymetries;
81 if ( isApplyAndClose() )
82 myEditedObject = Handle(HYDROData_ImmersibleZone)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
83 if( !myEditedObject.IsNull() )
85 anObjectName = myEditedObject->GetName();
87 Handle(HYDROData_PolylineXY) aRefPolyline = myEditedObject->GetPolyline();
88 if ( !aRefPolyline.IsNull() )
89 aSelectedPolyline = aRefPolyline->GetName();
91 Handle(HYDROData_IAltitudeObject) aRefAltitude = myEditedObject->GetAltitudeObject();
92 if ( !aRefAltitude.IsNull() )
93 aSelectedBathymetry = aRefAltitude->GetName();
97 aPanel->setObjectName( anObjectName );
98 aPanel->setPolylineNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
99 aPanel->setAdditionalParams( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_BATHYMETRY ) );
101 aPanel->blockSignals( false );
103 aPanel->setPolylineName( aSelectedPolyline );
104 aPanel->setSelectedAdditionalParamName( aSelectedBathymetry );
107 void HYDROGUI_ImmersibleZoneOp::abortOperation()
111 HYDROGUI_Operation::abortOperation();
114 void HYDROGUI_ImmersibleZoneOp::commitOperation()
118 HYDROGUI_Operation::commitOperation();
121 HYDROGUI_InputPanel* HYDROGUI_ImmersibleZoneOp::createInputPanel() const
123 HYDROGUI_ImmersibleZoneDlg* aPanel = new HYDROGUI_ImmersibleZoneDlg( module(), getName() );
124 connect( aPanel, SIGNAL( CreatePreview( const QString& ) ),
125 this, SLOT( onCreatePreview( const QString& ) ) );
129 bool HYDROGUI_ImmersibleZoneOp::processApply( int& theUpdateFlags,
130 QString& theErrorMsg,
131 QStringList& theBrowseObjectsEntries )
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->getSelectedAdditionalParamName();
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 );
198 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aZoneObj, true );
199 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aZoneObj );
200 theBrowseObjectsEntries.append( anEntry );
203 module()->setIsToUpdate( aZoneObj );
205 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
210 void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName )
212 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
216 QApplication::setOverrideCursor( Qt::WaitCursor );
217 TopoDS_Shape aZoneShape;
219 Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast(
220 HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINEXY ) );
221 if ( !aPolyline.IsNull() )
223 aZoneShape = HYDROData_ImmersibleZone::generateTopShape( aPolyline );
224 if( aZoneShape.IsNull() )
225 printErrorMessage( tr( "ZONE_OBJECT_CANNOT_BE_CREATED" ) );
228 LightApp_Application* anApp = module()->getApp();
229 if ( !getPreviewManager() )
230 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
231 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
232 OCCViewer_ViewManager* aViewManager = getPreviewManager();
233 if ( aViewManager && !myPreviewPrs )
235 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
237 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
238 if ( !aCtx.IsNull() )
239 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
243 if ( aViewManager && myPreviewPrs )
245 QColor aFillingColor = HYDROData_ImmersibleZone::DefaultFillingColor();
246 QColor aBorderColor = HYDROData_ImmersibleZone::DefaultBorderColor();
247 if ( !myEditedObject.IsNull() ) {
248 aFillingColor = myEditedObject->GetFillingColor();
249 aBorderColor = myEditedObject->GetBorderColor();
252 myPreviewPrs->setFillingColor( aFillingColor, false, false );
253 myPreviewPrs->setBorderColor( aBorderColor, false, false );
255 if( !aZoneShape.IsNull() )
256 aFace = TopoDS::Face( aZoneShape );
257 myPreviewPrs->setFace( aFace, true, true, "" );
260 QApplication::restoreOverrideCursor();
263 void HYDROGUI_ImmersibleZoneOp::closePreview()