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 myEditedObject = Handle(HYDROData_ImmersibleZone)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
82 if( !myEditedObject.IsNull() )
84 anObjectName = myEditedObject->GetName();
86 Handle(HYDROData_PolylineXY) aRefPolyline = myEditedObject->GetPolyline();
87 if ( !aRefPolyline.IsNull() )
88 aSelectedPolyline = aRefPolyline->GetName();
90 Handle(HYDROData_IAltitudeObject) aRefAltitude = myEditedObject->GetAltitudeObject();
91 if ( !aRefAltitude.IsNull() )
92 aSelectedBathymetry = aRefAltitude->GetName();
96 aPanel->setObjectName( anObjectName );
97 aPanel->setPolylineNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
98 aPanel->setBathymetryNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_BATHYMETRY ) );
100 aPanel->blockSignals( false );
102 aPanel->setPolylineName( aSelectedPolyline );
103 aPanel->setBathymetryName( aSelectedBathymetry );
106 void HYDROGUI_ImmersibleZoneOp::abortOperation()
110 HYDROGUI_Operation::abortOperation();
113 void HYDROGUI_ImmersibleZoneOp::commitOperation()
117 HYDROGUI_Operation::commitOperation();
120 HYDROGUI_InputPanel* HYDROGUI_ImmersibleZoneOp::createInputPanel() const
122 HYDROGUI_ImmersibleZoneDlg* aPanel = new HYDROGUI_ImmersibleZoneDlg( module(), getName() );
123 connect( aPanel, SIGNAL( CreatePreview( const QString& ) ),
124 this, SLOT( onCreatePreview( const QString& ) ) );
128 bool HYDROGUI_ImmersibleZoneOp::processApply( int& theUpdateFlags,
129 QString& theErrorMsg,
130 QStringList& theBrowseObjectsEntries )
132 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
136 QString anObjectName = aPanel->getObjectName().simplified();
137 if ( anObjectName.isEmpty() )
139 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
143 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
145 // check that there are no other objects with the same name in the document
146 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
147 if( !anObject.IsNull() )
149 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
154 Handle(HYDROData_PolylineXY) aZonePolyline;
155 Handle(HYDROData_Bathymetry) aZoneBathymetry;
157 QString aPolylineName = aPanel->getPolylineName();
158 if ( !aPolylineName.isEmpty() )
160 aZonePolyline = Handle(HYDROData_PolylineXY)::DownCast(
161 HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINEXY ) );
164 QString aBathymetryName = aPanel->getBathymetryName();
165 if ( !aBathymetryName.isEmpty() )
167 aZoneBathymetry = Handle(HYDROData_Bathymetry)::DownCast(
168 HYDROGUI_Tool::FindObjectByName( module(), aBathymetryName, KIND_BATHYMETRY ) );
172 if ( HYDROData_ImmersibleZone::generateTopShape( aZonePolyline ).IsNull() )
174 theErrorMsg = tr( "ZONE_OBJECT_CANNOT_BE_CREATED" );
178 Handle(HYDROData_ImmersibleZone) aZoneObj = myIsEdit ? myEditedObject :
179 Handle(HYDROData_ImmersibleZone)::DownCast( doc()->CreateObject( KIND_IMMERSIBLE_ZONE ) );
181 aZoneObj->SetName( anObjectName );
185 aZoneObj->SetFillingColor( HYDROData_ImmersibleZone::DefaultFillingColor() );
186 aZoneObj->SetBorderColor( HYDROData_ImmersibleZone::DefaultBorderColor() );
189 aZoneObj->SetPolyline( aZonePolyline );
190 aZoneObj->SetAltitudeObject( aZoneBathymetry );
197 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aZoneObj, true );
198 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aZoneObj );
199 theBrowseObjectsEntries.append( anEntry );
202 module()->setIsToUpdate( aZoneObj );
204 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
209 void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName )
211 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
215 QApplication::setOverrideCursor( Qt::WaitCursor );
216 TopoDS_Shape aZoneShape;
218 Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast(
219 HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINEXY ) );
220 if ( !aPolyline.IsNull() )
222 aZoneShape = HYDROData_ImmersibleZone::generateTopShape( aPolyline );
223 if( aZoneShape.IsNull() )
224 printErrorMessage( tr( "ZONE_OBJECT_CANNOT_BE_CREATED" ) );
227 LightApp_Application* anApp = module()->getApp();
228 if ( !getPreviewManager() )
229 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
230 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
231 OCCViewer_ViewManager* aViewManager = getPreviewManager();
232 if ( aViewManager && !myPreviewPrs )
234 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
236 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
237 if ( !aCtx.IsNull() )
238 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
242 if ( aViewManager && myPreviewPrs )
244 QColor aFillingColor = HYDROData_ImmersibleZone::DefaultFillingColor();
245 QColor aBorderColor = HYDROData_ImmersibleZone::DefaultBorderColor();
246 if ( !myEditedObject.IsNull() ) {
247 aFillingColor = myEditedObject->GetFillingColor();
248 aBorderColor = myEditedObject->GetBorderColor();
251 myPreviewPrs->setFillingColor( aFillingColor, false, false );
252 myPreviewPrs->setBorderColor( aBorderColor, false, false );
254 if( !aZoneShape.IsNull() )
255 aFace = TopoDS::Face( aZoneShape );
256 myPreviewPrs->setFace( aFace, true, true, "" );
259 QApplication::restoreOverrideCursor();
262 void HYDROGUI_ImmersibleZoneOp::closePreview()