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"
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 myEditedObject = Handle(HYDROData_ImmersibleZone)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
86 if( !myEditedObject.IsNull() )
88 anObjectName = myEditedObject->GetName();
90 Handle(HYDROData_PolylineXY) aRefPolyline = myEditedObject->GetPolyline();
91 if ( !aRefPolyline.IsNull() )
92 aSelectedPolyline = aRefPolyline->GetName();
94 Handle(HYDROData_IAltitudeObject) aRefAltitude = myEditedObject->GetAltitudeObject();
95 if ( !aRefAltitude.IsNull() )
96 aSelectedBathymetry = aRefAltitude->GetName();
100 aPanel->setObjectName( anObjectName );
101 aPanel->setPolylineNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
102 aPanel->setBathymetryNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_BATHYMETRY ) );
104 aPanel->blockSignals( false );
106 aPanel->setPolylineName( aSelectedPolyline );
107 aPanel->setBathymetryName( aSelectedBathymetry );
110 void HYDROGUI_ImmersibleZoneOp::abortOperation()
114 HYDROGUI_Operation::abortOperation();
117 void HYDROGUI_ImmersibleZoneOp::commitOperation()
121 HYDROGUI_Operation::commitOperation();
124 HYDROGUI_InputPanel* HYDROGUI_ImmersibleZoneOp::createInputPanel() const
126 HYDROGUI_ImmersibleZoneDlg* aPanel = new HYDROGUI_ImmersibleZoneDlg( module(), getName() );
127 connect( aPanel, SIGNAL( CreatePreview( const QString& ) ),
128 this, SLOT( onCreatePreview( const QString& ) ) );
132 bool HYDROGUI_ImmersibleZoneOp::processApply( int& theUpdateFlags,
133 QString& theErrorMsg,
134 QStringList& theBrowseObjectsEntries )
136 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
140 QString anObjectName = aPanel->getObjectName().simplified();
141 if ( anObjectName.isEmpty() )
143 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
147 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
149 // check that there are no other objects with the same name in the document
150 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
151 if( !anObject.IsNull() )
153 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
158 Handle(HYDROData_PolylineXY) aZonePolyline;
159 Handle(HYDROData_Bathymetry) aZoneBathymetry;
161 QString aPolylineName = aPanel->getPolylineName();
162 if ( !aPolylineName.isEmpty() )
164 aZonePolyline = Handle(HYDROData_PolylineXY)::DownCast(
165 HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINEXY ) );
168 QString aBathymetryName = aPanel->getBathymetryName();
169 if ( !aBathymetryName.isEmpty() )
171 aZoneBathymetry = Handle(HYDROData_Bathymetry)::DownCast(
172 HYDROGUI_Tool::FindObjectByName( module(), aBathymetryName, KIND_BATHYMETRY ) );
176 if ( HYDROData_ImmersibleZone::generateTopShape( aZonePolyline ).IsNull() )
178 theErrorMsg = tr( "ZONE_OBJECT_CANNOT_BE_CREATED" );
182 Handle(HYDROData_ImmersibleZone) aZoneObj = myIsEdit ? myEditedObject :
183 Handle(HYDROData_ImmersibleZone)::DownCast( doc()->CreateObject( KIND_IMMERSIBLE_ZONE ) );
185 aZoneObj->SetName( anObjectName );
189 aZoneObj->SetFillingColor( HYDROData_ImmersibleZone::DefaultFillingColor() );
190 aZoneObj->SetBorderColor( HYDROData_ImmersibleZone::DefaultBorderColor() );
193 aZoneObj->SetPolyline( aZonePolyline );
194 aZoneObj->SetAltitudeObject( aZoneBathymetry );
201 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aZoneObj, true );
202 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aZoneObj );
203 theBrowseObjectsEntries.append( anEntry );
206 module()->setIsToUpdate( aZoneObj );
208 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
213 void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName )
215 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
219 QApplication::setOverrideCursor( Qt::WaitCursor );
220 TopoDS_Shape aZoneShape;
222 Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast(
223 HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINEXY ) );
224 if ( !aPolyline.IsNull() )
226 aZoneShape = HYDROData_ImmersibleZone::generateTopShape( aPolyline );
227 if( aZoneShape.IsNull() )
228 printErrorMessage( tr( "ZONE_OBJECT_CANNOT_BE_CREATED" ) );
231 LightApp_Application* anApp = module()->getApp();
232 if ( !getPreviewManager() )
233 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
234 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
235 OCCViewer_ViewManager* aViewManager = getPreviewManager();
236 if ( aViewManager && !myPreviewPrs )
238 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
240 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
241 if ( !aCtx.IsNull() )
242 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
246 if ( aViewManager && myPreviewPrs )
248 QColor aFillingColor = HYDROData_ImmersibleZone::DefaultFillingColor();
249 QColor aBorderColor = HYDROData_ImmersibleZone::DefaultBorderColor();
250 if ( !myEditedObject.IsNull() ) {
251 aFillingColor = myEditedObject->GetFillingColor();
252 aBorderColor = myEditedObject->GetBorderColor();
255 myPreviewPrs->setFillingColor( aFillingColor, false, false );
256 myPreviewPrs->setBorderColor( aBorderColor, false, false );
258 if( !aZoneShape.IsNull() )
259 aFace = TopoDS::Face( aZoneShape );
260 myPreviewPrs->setFace( aFace, true, true, "" );
263 QApplication::restoreOverrideCursor();
266 void HYDROGUI_ImmersibleZoneOp::closePreview()