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_Wire.hxx>
49 #include <QApplication>
51 HYDROGUI_ImmersibleZoneOp::HYDROGUI_ImmersibleZoneOp( HYDROGUI_Module* theModule,
52 const bool theIsEdit )
53 : HYDROGUI_Operation( theModule ),
54 myIsEdit( theIsEdit ),
57 setName( theIsEdit ? tr( "EDIT_IMMERSIBLE_ZONE" ) : tr( "CREATE_IMMERSIBLE_ZONE" ) );
60 HYDROGUI_ImmersibleZoneOp::~HYDROGUI_ImmersibleZoneOp()
65 void HYDROGUI_ImmersibleZoneOp::startOperation()
67 HYDROGUI_Operation::startOperation();
69 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
73 aPanel->blockSignals( true );
77 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMMERSIBLE_ZONE_NAME" ) );
79 QString aSelectedPolyline, aSelectedBathymetry;
80 QStringList aSelectedBathymetries;
84 myEditedObject = Handle(HYDROData_ImmersibleZone)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
85 if( !myEditedObject.IsNull() )
87 anObjectName = myEditedObject->GetName();
89 Handle(HYDROData_PolylineXY) aRefPolyline = myEditedObject->GetPolyline();
90 if ( !aRefPolyline.IsNull() )
91 aSelectedPolyline = aRefPolyline->GetName();
93 Handle(HYDROData_IAltitudeObject) aRefAltitude = myEditedObject->GetAltitudeObject();
94 if ( !aRefAltitude.IsNull() )
95 aSelectedBathymetry = aRefAltitude->GetName();
99 aPanel->setObjectName( anObjectName );
100 aPanel->setPolylineNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
101 aPanel->setBathymetryNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_BATHYMETRY ) );
103 aPanel->blockSignals( false );
105 aPanel->setPolylineName( aSelectedPolyline );
106 aPanel->setBathymetryName( aSelectedBathymetry );
109 void HYDROGUI_ImmersibleZoneOp::abortOperation()
113 HYDROGUI_Operation::abortOperation();
116 void HYDROGUI_ImmersibleZoneOp::commitOperation()
120 HYDROGUI_Operation::commitOperation();
123 HYDROGUI_InputPanel* HYDROGUI_ImmersibleZoneOp::createInputPanel() const
125 HYDROGUI_ImmersibleZoneDlg* aPanel = new HYDROGUI_ImmersibleZoneDlg( module(), getName() );
126 connect( aPanel, SIGNAL( CreatePreview( const QString& ) ),
127 this, SLOT( onCreatePreview( const QString& ) ) );
131 bool HYDROGUI_ImmersibleZoneOp::processApply( int& theUpdateFlags,
132 QString& theErrorMsg,
133 QStringList& theBrowseObjectsEntries )
135 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
139 QString anObjectName = aPanel->getObjectName().simplified();
140 if ( anObjectName.isEmpty() )
142 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
146 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
148 // check that there are no other objects with the same name in the document
149 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
150 if( !anObject.IsNull() )
152 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
157 Handle(HYDROData_PolylineXY) aZonePolyline;
158 Handle(HYDROData_Bathymetry) aZoneBathymetry;
160 QString aPolylineName = aPanel->getPolylineName();
161 if ( !aPolylineName.isEmpty() )
163 aZonePolyline = Handle(HYDROData_PolylineXY)::DownCast(
164 HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINEXY ) );
167 QString aBathymetryName = aPanel->getBathymetryName();
168 if ( !aBathymetryName.isEmpty() )
170 aZoneBathymetry = Handle(HYDROData_Bathymetry)::DownCast(
171 HYDROGUI_Tool::FindObjectByName( module(), aBathymetryName, KIND_BATHYMETRY ) );
175 if ( HYDROData_ImmersibleZone::generateTopShape( aZonePolyline ).IsNull() )
177 theErrorMsg = tr( "ZONE_OBJECT_CANNOT_BE_CREATED" );
181 Handle(HYDROData_ImmersibleZone) aZoneObj = myIsEdit ? myEditedObject :
182 Handle(HYDROData_ImmersibleZone)::DownCast( doc()->CreateObject( KIND_IMMERSIBLE_ZONE ) );
184 aZoneObj->SetName( anObjectName );
188 aZoneObj->SetFillingColor( HYDROData_ImmersibleZone::DefaultFillingColor() );
189 aZoneObj->SetBorderColor( HYDROData_ImmersibleZone::DefaultBorderColor() );
192 aZoneObj->SetPolyline( aZonePolyline );
193 aZoneObj->SetAltitudeObject( aZoneBathymetry );
200 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aZoneObj, true );
201 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aZoneObj );
202 theBrowseObjectsEntries.append( anEntry );
205 module()->setIsToUpdate( aZoneObj );
207 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
212 void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName )
214 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
218 QApplication::setOverrideCursor( Qt::WaitCursor );
219 TopoDS_Shape aZoneShape;
221 Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast(
222 HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINEXY ) );
223 if ( !aPolyline.IsNull() )
225 aZoneShape = HYDROData_ImmersibleZone::generateTopShape( aPolyline );
226 if( aZoneShape.IsNull() )
227 printErrorMessage( tr( "ZONE_OBJECT_CANNOT_BE_CREATED" ) );
230 LightApp_Application* anApp = module()->getApp();
231 if ( !getPreviewManager() )
232 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
233 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
234 OCCViewer_ViewManager* aViewManager = getPreviewManager();
235 if ( aViewManager && !myPreviewPrs )
237 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
239 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
240 if ( !aCtx.IsNull() )
241 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
245 if ( aViewManager && myPreviewPrs )
247 QColor aFillingColor = HYDROData_ImmersibleZone::DefaultFillingColor();
248 QColor aBorderColor = HYDROData_ImmersibleZone::DefaultBorderColor();
249 if ( !myEditedObject.IsNull() ) {
250 aFillingColor = myEditedObject->GetFillingColor();
251 aBorderColor = myEditedObject->GetBorderColor();
254 myPreviewPrs->setFillingColor( aFillingColor, false, false );
255 myPreviewPrs->setBorderColor( aBorderColor, false, false );
257 if( !aZoneShape.IsNull() )
258 aFace = TopoDS::Face( aZoneShape );
259 myPreviewPrs->setFace( aFace );
262 QApplication::restoreOverrideCursor();
265 void HYDROGUI_ImmersibleZoneOp::closePreview()