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_Polyline.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 QColor aFillingColor( HYDROData_ImmersibleZone::DefaultFillingColor() );
75 QColor aBorderColor( HYDROData_ImmersibleZone::DefaultBorderColor() );
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 aFillingColor = myEditedObject->GetFillingColor();
87 aBorderColor = myEditedObject->GetBorderColor();
89 Handle(HYDROData_Polyline) aRefPolyline = myEditedObject->GetPolyline();
90 if ( !aRefPolyline.IsNull() )
91 aSelectedPolyline = aRefPolyline->GetName();
93 Handle(HYDROData_Bathymetry) aRefBathymetry = myEditedObject->GetBathymetry();
94 if ( !aRefBathymetry.IsNull() )
95 aSelectedBathymetry = aRefBathymetry->GetName();
99 // collect information about existing closed polylines
100 QStringList aPolylines;
102 HYDROData_Iterator anIter( doc(), KIND_POLYLINE );
103 for ( ; anIter.More(); anIter.Next() )
105 Handle(HYDROData_Polyline) aPolylineObj =
106 Handle(HYDROData_Polyline)::DownCast( anIter.Current() );
107 if ( aPolylineObj.IsNull() || !aPolylineObj->IsClosed() )
110 QString aPolylineName = aPolylineObj->GetName();
111 if ( aPolylineName.isEmpty() )
114 aPolylines.append( aPolylineName );
117 // collect information about existing bathymetries
118 QStringList aBathymetries;
120 anIter = HYDROData_Iterator( doc(), KIND_BATHYMETRY );
121 for ( ; anIter.More(); anIter.Next() )
123 Handle(HYDROData_Bathymetry) aBathymetryObj =
124 Handle(HYDROData_Bathymetry)::DownCast( anIter.Current() );
125 if ( aBathymetryObj.IsNull() )
128 QString aBathymetryName = aBathymetryObj->GetName();
129 if ( aBathymetryName.isEmpty() )
132 aBathymetries.append( aBathymetryName );
135 aPanel->setObjectName( anObjectName );
137 aPanel->setFillingColor( aFillingColor );
138 aPanel->setBorderColor( aBorderColor );
140 aPanel->setPolylineNames( aPolylines );
141 aPanel->setBathymetryNames( aBathymetries );
143 aPanel->blockSignals( false );
145 aPanel->setPolylineName( aSelectedPolyline );
146 aPanel->setBathymetryName( aSelectedBathymetry );
149 void HYDROGUI_ImmersibleZoneOp::abortOperation()
153 HYDROGUI_Operation::abortOperation();
156 void HYDROGUI_ImmersibleZoneOp::commitOperation()
160 HYDROGUI_Operation::commitOperation();
163 HYDROGUI_InputPanel* HYDROGUI_ImmersibleZoneOp::createInputPanel() const
165 HYDROGUI_ImmersibleZoneDlg* aPanel = new HYDROGUI_ImmersibleZoneDlg( module(), getName() );
166 connect( aPanel, SIGNAL( CreatePreview( const QString& ) ),
167 this, SLOT( onCreatePreview( const QString& ) ) );
171 bool HYDROGUI_ImmersibleZoneOp::processApply( int& theUpdateFlags,
172 QString& theErrorMsg )
174 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
178 QString anObjectName = aPanel->getObjectName().simplified();
179 if ( anObjectName.isEmpty() )
181 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
185 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
187 // check that there are no other objects with the same name in the document
188 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
189 if( !anObject.IsNull() )
191 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
196 Handle(HYDROData_ImmersibleZone) aZoneObj = myIsEdit ? myEditedObject :
197 Handle(HYDROData_ImmersibleZone)::DownCast( doc()->CreateObject( KIND_IMMERSIBLE_ZONE ) );
198 if ( aZoneObj.IsNull() )
201 Handle(HYDROData_Polyline) aZonePolyline;
202 Handle(HYDROData_Bathymetry) aZoneBathymetry;
204 QString aPolylineName = aPanel->getPolylineName();
205 if ( !aPolylineName.isEmpty() )
207 aZonePolyline = Handle(HYDROData_Polyline)::DownCast(
208 HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINE ) );
211 QString aBathymetryName = aPanel->getBathymetryName();
212 if ( !aBathymetryName.isEmpty() )
214 aZoneBathymetry = Handle(HYDROData_Bathymetry)::DownCast(
215 HYDROGUI_Tool::FindObjectByName( module(), aBathymetryName, KIND_BATHYMETRY ) );
218 aZoneObj->SetName( anObjectName );
220 aZoneObj->SetFillingColor( aPanel->getFillingColor() );
221 aZoneObj->SetBorderColor( aPanel->getBorderColor() );
223 aZoneObj->SetPolyline( aZonePolyline );
224 aZoneObj->SetBathymetry( aZoneBathymetry );
229 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aZoneObj, true );
231 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
236 void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName )
238 HYDROGUI_ImmersibleZoneDlg* aPanel = ::qobject_cast<HYDROGUI_ImmersibleZoneDlg*>( inputPanel() );
244 Handle(HYDROData_Polyline) aPolyline = Handle(HYDROData_Polyline)::DownCast(
245 HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINE ) );
246 if ( !aPolyline.IsNull() )
248 aWire = TopoDS::Wire( aPolyline->GetTopShape() );
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 myPreviewPrs->setFillingColor( aPanel->getFillingColor(), false, false );
270 myPreviewPrs->setBorderColor( aPanel->getBorderColor(), false, false );
271 myPreviewPrs->setFace( aWire );
274 void HYDROGUI_ImmersibleZoneOp::closePreview()