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_Tool2.h"
27 #include "HYDROGUI_UpdateFlags.h"
28 #include "HYDROGUI_DataObject.h"
30 #include <HYDROData_Bathymetry.h>
31 #include <HYDROData_Iterator.h>
32 #include <HYDROData_PolylineXY.h>
34 #include <OCCViewer_ViewManager.h>
35 #include <OCCViewer_ViewModel.h>
37 #include <LightApp_Application.h>
38 #include <LightApp_UpdateFlags.h>
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_Desktop.h>
44 #include <TopoDS_Face.hxx>
45 #include <TopoDS_Wire.hxx>
47 #include <QApplication>
49 HYDROGUI_ImmersibleZoneOp::HYDROGUI_ImmersibleZoneOp( HYDROGUI_Module* theModule,
50 const bool theIsEdit )
51 : HYDROGUI_Operation( theModule ),
52 myIsEdit( theIsEdit ),
55 setName( theIsEdit ? tr( "EDIT_IMMERSIBLE_ZONE" ) : tr( "CREATE_IMMERSIBLE_ZONE" ) );
58 HYDROGUI_ImmersibleZoneOp::~HYDROGUI_ImmersibleZoneOp()
63 void HYDROGUI_ImmersibleZoneOp::startOperation()
65 HYDROGUI_Operation::startOperation();
67 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
71 aPanel->blockSignals( true );
75 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMMERSIBLE_ZONE_NAME" ) );
77 QString aSelectedPolyline, aSelectedBathymetry;
78 QStringList aSelectedBathymetries;
82 if ( isApplyAndClose() )
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->setAdditionalParams( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_BATHYMETRY ) );
102 aPanel->blockSignals( false );
104 aPanel->setPolylineName( aSelectedPolyline );
105 aPanel->setSelectedAdditionalParamName( 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,
132 QStringList& theBrowseObjectsEntries )
134 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
138 QString anObjectName = aPanel->getObjectName().simplified();
139 if ( anObjectName.isEmpty() )
141 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
145 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
147 // check that there are no other objects with the same name in the document
148 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
149 if( !anObject.IsNull() )
151 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
156 Handle(HYDROData_PolylineXY) aZonePolyline;
157 Handle(HYDROData_Bathymetry) aZoneBathymetry;
159 QString aPolylineName = aPanel->getPolylineName();
160 if ( !aPolylineName.isEmpty() )
162 aZonePolyline = Handle(HYDROData_PolylineXY)::DownCast(
163 HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINEXY ) );
166 QString aBathymetryName = aPanel->getSelectedAdditionalParamName();
167 if ( !aBathymetryName.isEmpty() )
169 aZoneBathymetry = Handle(HYDROData_Bathymetry)::DownCast(
170 HYDROGUI_Tool::FindObjectByName( module(), aBathymetryName, KIND_BATHYMETRY ) );
174 if ( HYDROData_ImmersibleZone::generateTopShape( aZonePolyline ).IsNull() )
176 theErrorMsg = tr( "ZONE_OBJECT_CANNOT_BE_CREATED" );
180 Handle(HYDROData_ImmersibleZone) aZoneObj = myIsEdit ? myEditedObject :
181 Handle(HYDROData_ImmersibleZone)::DownCast( doc()->CreateObject( KIND_IMMERSIBLE_ZONE ) );
183 aZoneObj->SetName( anObjectName );
187 aZoneObj->SetFillingColor( aZoneObj->DefaultFillingColor() );
188 aZoneObj->SetBorderColor( aZoneObj->DefaultBorderColor() );
191 aZoneObj->SetPolyline( aZonePolyline );
192 aZoneObj->SetAltitudeObject( aZoneBathymetry );
199 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aZoneObj, true );
200 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aZoneObj );
201 theBrowseObjectsEntries.append( anEntry );
204 module()->setIsToUpdate( aZoneObj );
206 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
211 void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName )
213 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
217 QApplication::setOverrideCursor( Qt::WaitCursor );
218 TopoDS_Shape aZoneShape;
220 Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast(
221 HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINEXY ) );
222 if ( !aPolyline.IsNull() )
224 aZoneShape = HYDROData_ImmersibleZone::generateTopShape( aPolyline );
225 if( aZoneShape.IsNull() )
226 printErrorMessage( tr( "ZONE_OBJECT_CANNOT_BE_CREATED" ) );
229 LightApp_Application* anApp = module()->getApp();
230 if ( !getPreviewManager() )
231 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
232 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
233 OCCViewer_ViewManager* aViewManager = getPreviewManager();
234 if ( aViewManager && !myPreviewPrs )
236 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
238 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
239 if ( !aCtx.IsNull() )
240 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
244 if ( aViewManager && myPreviewPrs )
246 QColor aFillingColor = Qt::darkBlue;
247 QColor aBorderColor = Qt::transparent;
248 if ( !myEditedObject.IsNull() ) {
249 aFillingColor = myEditedObject->GetFillingColor();
250 aBorderColor = myEditedObject->GetBorderColor();
254 if( !aZoneShape.IsNull() )
255 aFace = TopoDS::Face( aZoneShape );
256 myPreviewPrs->setFace( aFace, true, true, "" );
257 myPreviewPrs->setFillingColor( aFillingColor, false, false );
258 myPreviewPrs->setBorderColor( aBorderColor, false, false );
261 QApplication::restoreOverrideCursor();
264 void HYDROGUI_ImmersibleZoneOp::closePreview()