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"
32 #include <HYDROData_Bathymetry.h>
33 #include <HYDROData_Iterator.h>
34 #include <HYDROData_PolylineXY.h>
36 #include <OCCViewer_ViewManager.h>
37 #include <OCCViewer_ViewModel.h>
39 #include <LightApp_Application.h>
40 #include <LightApp_UpdateFlags.h>
43 #include <TopoDS_Wire.hxx>
45 HYDROGUI_ImmersibleZoneOp::HYDROGUI_ImmersibleZoneOp( HYDROGUI_Module* theModule,
46 const bool theIsEdit )
47 : HYDROGUI_Operation( theModule ),
48 myIsEdit( theIsEdit ),
52 setName( theIsEdit ? tr( "EDIT_IMMERSIBLE_ZONE" ) : tr( "CREATE_IMMERSIBLE_ZONE" ) );
55 HYDROGUI_ImmersibleZoneOp::~HYDROGUI_ImmersibleZoneOp()
60 void HYDROGUI_ImmersibleZoneOp::startOperation()
62 HYDROGUI_Operation::startOperation();
64 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
68 aPanel->blockSignals( true );
72 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMMERSIBLE_ZONE_NAME" ) );
74 QString aSelectedPolyline, aSelectedBathymetry;
75 QStringList aSelectedBathymetries;
79 myEditedObject = Handle(HYDROData_ImmersibleZone)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
80 if( !myEditedObject.IsNull() )
82 anObjectName = myEditedObject->GetName();
84 Handle(HYDROData_PolylineXY) aRefPolyline = myEditedObject->GetPolyline();
85 if ( !aRefPolyline.IsNull() )
86 aSelectedPolyline = aRefPolyline->GetName();
88 Handle(HYDROData_Bathymetry) aRefBathymetry = myEditedObject->GetBathymetry();
89 if ( !aRefBathymetry.IsNull() )
90 aSelectedBathymetry = aRefBathymetry->GetName();
94 // collect information about existing closed polylines
95 QStringList aPolylines;
97 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
98 for ( ; anIter.More(); anIter.Next() )
100 Handle(HYDROData_PolylineXY) aPolylineObj =
101 Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
102 if ( aPolylineObj.IsNull() || !aPolylineObj->IsClosed() )
105 QString aPolylineName = aPolylineObj->GetName();
106 if ( aPolylineName.isEmpty() )
109 aPolylines.append( aPolylineName );
112 // collect information about existing bathymetries
113 QStringList aBathymetries;
115 anIter = HYDROData_Iterator( doc(), KIND_BATHYMETRY );
116 for ( ; anIter.More(); anIter.Next() )
118 Handle(HYDROData_Bathymetry) aBathymetryObj =
119 Handle(HYDROData_Bathymetry)::DownCast( anIter.Current() );
120 if ( aBathymetryObj.IsNull() )
123 QString aBathymetryName = aBathymetryObj->GetName();
124 if ( aBathymetryName.isEmpty() )
127 aBathymetries.append( aBathymetryName );
130 aPanel->setObjectName( anObjectName );
132 aPanel->setPolylineNames( aPolylines );
133 aPanel->setBathymetryNames( aBathymetries );
135 aPanel->blockSignals( false );
137 aPanel->setPolylineName( aSelectedPolyline );
138 aPanel->setBathymetryName( aSelectedBathymetry );
141 void HYDROGUI_ImmersibleZoneOp::abortOperation()
145 HYDROGUI_Operation::abortOperation();
148 void HYDROGUI_ImmersibleZoneOp::commitOperation()
152 HYDROGUI_Operation::commitOperation();
155 HYDROGUI_InputPanel* HYDROGUI_ImmersibleZoneOp::createInputPanel() const
157 HYDROGUI_ImmersibleZoneDlg* aPanel = new HYDROGUI_ImmersibleZoneDlg( module(), getName() );
158 connect( aPanel, SIGNAL( CreatePreview( const QString& ) ),
159 this, SLOT( onCreatePreview( const QString& ) ) );
163 bool HYDROGUI_ImmersibleZoneOp::processApply( int& theUpdateFlags,
164 QString& theErrorMsg )
166 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
170 QString anObjectName = aPanel->getObjectName().simplified();
171 if ( anObjectName.isEmpty() )
173 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
177 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
179 // check that there are no other objects with the same name in the document
180 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
181 if( !anObject.IsNull() )
183 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
188 Handle(HYDROData_ImmersibleZone) aZoneObj = myIsEdit ? myEditedObject :
189 Handle(HYDROData_ImmersibleZone)::DownCast( doc()->CreateObject( KIND_IMMERSIBLE_ZONE ) );
190 if ( aZoneObj.IsNull() )
193 Handle(HYDROData_PolylineXY) aZonePolyline;
194 Handle(HYDROData_Bathymetry) aZoneBathymetry;
196 QString aPolylineName = aPanel->getPolylineName();
197 if ( !aPolylineName.isEmpty() )
199 aZonePolyline = Handle(HYDROData_PolylineXY)::DownCast(
200 HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINEXY ) );
203 QString aBathymetryName = aPanel->getBathymetryName();
204 if ( !aBathymetryName.isEmpty() )
206 aZoneBathymetry = Handle(HYDROData_Bathymetry)::DownCast(
207 HYDROGUI_Tool::FindObjectByName( module(), aBathymetryName, KIND_BATHYMETRY ) );
210 aZoneObj->SetName( anObjectName );
214 aZoneObj->SetFillingColor( HYDROData_ImmersibleZone::DefaultFillingColor() );
215 aZoneObj->SetBorderColor( HYDROData_ImmersibleZone::DefaultBorderColor() );
218 aZoneObj->SetPolyline( aZonePolyline );
219 aZoneObj->SetBathymetry( aZoneBathymetry );
225 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aZoneObj, true );
227 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
232 void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName )
234 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
241 Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast(
242 HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINEXY ) );
243 if ( !aPolyline.IsNull() )
245 aShape = aPolyline->GetShape();
246 if ( aShape.ShapeType() == TopAbs_WIRE ) {
247 aWire = TopoDS::Wire( aShape );
251 LightApp_Application* anApp = module()->getApp();
252 if ( !myViewManager )
253 myViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
254 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
256 if ( myViewManager && !myPreviewPrs )
258 if ( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() )
260 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
261 if ( !aCtx.IsNull() )
262 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL );
266 if ( !myViewManager || !myPreviewPrs )
269 QColor aFillingColor = HYDROData_ImmersibleZone::DefaultFillingColor();
270 QColor aBorderColor = HYDROData_ImmersibleZone::DefaultBorderColor();
271 if ( !myEditedObject.IsNull() ) {
272 aFillingColor = myEditedObject->GetFillingColor();
273 aBorderColor = myEditedObject->GetBorderColor();
276 myPreviewPrs->setFillingColor( aFillingColor, false, false );
277 myPreviewPrs->setBorderColor( aBorderColor, false, false );
278 if ( !aWire.IsNull() ) {
279 myPreviewPrs->setFace( aWire );
280 } else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND ) {
281 TopoDS_Compound aCompound = TopoDS::Compound( aShape );
282 if ( !aCompound.IsNull() ) {
283 myPreviewPrs->setFaces( aCompound );
288 void HYDROGUI_ImmersibleZoneOp::closePreview()