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_ChannelOp.h"
21 #include "HYDROGUI_DataModel.h"
22 #include <HYDROGUI_DataObject.h>
23 #include "HYDROGUI_ChannelDlg.h"
24 #include "HYDROGUI_Module.h"
25 #include "HYDROGUI_Shape.h"
26 #include "HYDROGUI_Tool.h"
27 #include "HYDROGUI_Tool2.h"
28 #include "HYDROGUI_UpdateFlags.h"
30 #include <HYDROData_Iterator.h>
31 #include <HYDROData_Polyline3D.h>
32 #include <HYDROData_Profile.h>
34 #include <OCCViewer_ViewManager.h>
35 #include <OCCViewer_ViewModel.h>
37 #include <LightApp_Application.h>
38 #include <LightApp_UpdateFlags.h>
39 #include <HYDROData_ChannelAltitude.h>
43 HYDROGUI_ChannelOp::HYDROGUI_ChannelOp( HYDROGUI_Module* theModule,
44 const bool theIsEdit )
45 : HYDROGUI_Operation( theModule ),
46 myIsEdit( theIsEdit ),
49 setName( theIsEdit ? tr( "EDIT_CHANNEL" ) : tr( "CREATE_CHANNEL" ) );
52 HYDROGUI_ChannelOp::~HYDROGUI_ChannelOp()
57 void HYDROGUI_ChannelOp::startOperation()
59 HYDROGUI_Operation::startOperation();
61 HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
63 aPanel->blockSignals( true );
67 if ( isApplyAndClose() )
68 myEditedObject.Nullify();
70 QString aSelectedGuideLine, aSelectedProfile;
72 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CHANNEL_NAME" ) );
75 if ( isApplyAndClose() )
77 Handle(HYDROData_Channel)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
78 if ( !myEditedObject.IsNull() )
80 anObjectName = myEditedObject->GetName();
82 Handle(HYDROData_Polyline3D) aRefGuideLine = myEditedObject->GetGuideLine();
83 if ( !aRefGuideLine.IsNull() )
84 aSelectedGuideLine = aRefGuideLine->GetName();
86 Handle(HYDROData_Profile) aRefProfile = myEditedObject->GetProfile();
87 if ( !aRefProfile.IsNull() )
88 aSelectedProfile = aRefProfile->GetName();
92 // collect information about existing 3d polylines
93 QStringList aGuideLines;
94 HYDROData_Iterator aPolylinesIt( doc(), KIND_POLYLINE );
95 for ( ; aPolylinesIt.More(); aPolylinesIt.Next() )
97 Handle(HYDROData_Polyline3D) aPolyline3d =
98 Handle(HYDROData_Polyline3D)::DownCast( aPolylinesIt.Current() );
99 if( !aPolyline3d.IsNull() )
101 TopoDS_Shape aShape = aPolyline3d->GetShape3D();
102 if( aShape.ShapeType()==TopAbs_WIRE )
104 TopoDS_Wire aWire = TopoDS::Wire( aShape );
105 if( !aWire.Closed() )
106 aGuideLines.append( aPolyline3d->GetName() );
111 // collect information about existing profiles
112 QStringList aProfiles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_PROFILE, false );
114 aPanel->setObjectName( anObjectName );
116 aPanel->setGuideLineNames( aGuideLines );
117 aPanel->setProfileNames( aProfiles );
119 aPanel->setGuideLineName( aSelectedGuideLine );
120 aPanel->setProfileName( aSelectedProfile );
122 if( !myEditedObject.IsNull() )
123 aPanel->setEquiDistance( myEditedObject->GetEquiDistance() );
125 aPanel->setEquiDistance( 1.0 );
127 if( !myEditedObject.IsNull() )
129 bool invDirection = false;
130 Handle(HYDROData_IAltitudeObject) anObjAltitude = myEditedObject->GetAltitudeObject();
131 Handle(HYDROData_ChannelAltitude) aChannelAlt = Handle(HYDROData_ChannelAltitude)::DownCast(anObjAltitude);
132 if (!aChannelAlt.IsNull())
133 invDirection = aChannelAlt->GetInvertDirection();
134 aPanel->setInvertDirection( invDirection );
137 aPanel->setInvertDirection( false );
139 aPanel->blockSignals( false );
144 void HYDROGUI_ChannelOp::abortOperation()
147 HYDROGUI_Operation::abortOperation();
150 void HYDROGUI_ChannelOp::commitOperation()
153 HYDROGUI_Operation::commitOperation();
156 HYDROGUI_InputPanel* HYDROGUI_ChannelOp::createInputPanel() const
158 HYDROGUI_ChannelDlg* aPanel = new HYDROGUI_ChannelDlg( module(), getName() );
159 connect( aPanel, SIGNAL( CreatePreview() ), this, SLOT( onCreatePreview() ) );
163 bool HYDROGUI_ChannelOp::processApply( int& theUpdateFlags,
164 QString& theErrorMsg,
165 QStringList& theBrowseObjectsEntries )
167 HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
171 QString anObjectName = aPanel->getObjectName().simplified();
172 if ( anObjectName.isEmpty() )
174 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
178 if ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
180 // check that there are no other objects with the same name in the document
181 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
182 if( !anObject.IsNull() )
184 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
190 if ( myEditedObject.IsNull() )
191 myEditedObject = createNewObject(); // Create new data model object
193 myEditedObject->SetName( anObjectName );
197 myEditedObject->SetFillingColor( myEditedObject->DefaultFillingColor() );
198 myEditedObject->SetBorderColor( myEditedObject->DefaultBorderColor() );
201 QString aGuideLineName = aPanel->getGuideLineName();
203 bool profileMode = aPanel->getProfileMode();
204 QString aProfileName;
205 double lc=0, deltaz=0, cotez=0;
209 aProfileName = aPanel->getProfileName();
213 lc = aPanel->getLCValue();
214 deltaz = aPanel->getDeltaZValue();
215 cotez = aPanel->getCoteZValue();
219 /*if ( aGuideLineName.isEmpty() || aProfileName.isEmpty() )
221 myEditedObject->RemoveGuideLine();
222 myEditedObject->RemoveProfile();
226 Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast(
227 HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) );
228 if ( aGuideLine.IsNull() )
230 theErrorMsg = tr( "GUIDE_LINE_IS_NOT_SELECTED" );
234 myEditedObject->RemoveGuideLine();
235 myEditedObject->SetGuideLine( aGuideLine );
237 myEditedObject->SetProfileMode(profileMode);
241 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
242 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
243 if ( aProfile.IsNull() )
245 theErrorMsg = tr( "PROFILE_IS_NOT_SELECTED" );
248 myEditedObject->RemoveProfile();
249 myEditedObject->SetProfile( aProfile );
250 myEditedObject->SetLCValue(0);
251 myEditedObject->SetDeltaZValue(0);
252 myEditedObject->SetCoteZValue(0);
256 myEditedObject->RemoveProfile();
257 myEditedObject->SetLCValue(lc);
258 myEditedObject->SetDeltaZValue(deltaz);
259 myEditedObject->SetCoteZValue(cotez);
262 myEditedObject->SetEquiDistance( aPanel->getEquiDistance() );
264 Handle(HYDROData_IAltitudeObject) anObjAltitude = myEditedObject->GetAltitudeObject();
265 Handle(HYDROData_ChannelAltitude) aChannelAlt = Handle(HYDROData_ChannelAltitude)::DownCast(anObjAltitude);
266 if (!aChannelAlt.IsNull())
267 aChannelAlt->SetInvertDirection(aPanel->getInvertDirection());
270 if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) )
271 myEditedObject->Update();
277 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true );
278 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
279 theBrowseObjectsEntries.append( anEntry );
282 module()->setIsToUpdate( myEditedObject );
284 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
289 Handle(HYDROData_Channel) HYDROGUI_ChannelOp::createNewObject() const
291 return Handle(HYDROData_Channel)::DownCast( doc()->CreateObject( KIND_CHANNEL ) );
294 void HYDROGUI_ChannelOp::onCreatePreview()
296 HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
300 QString aGuideLineName = aPanel->getGuideLineName();
301 QString aProfileName = aPanel->getProfileName();
302 if ( aGuideLineName.isEmpty() || aProfileName.isEmpty() )
308 LightApp_Application* anApp = module()->getApp();
310 if ( !getPreviewManager() )
312 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
313 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
316 OCCViewer_ViewManager* aViewManager = getPreviewManager();
317 if ( aViewManager && !myPreviewPrs )
319 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
321 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
322 if ( !aCtx.IsNull() )
324 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
326 QColor aFillingColor = Qt::blue;
327 QColor aBorderColor = Qt::transparent;
328 if ( !myEditedObject.IsNull() )
330 aFillingColor = myEditedObject->GetFillingColor();
331 aBorderColor = myEditedObject->GetBorderColor();
334 myPreviewPrs->setFillingColor( aFillingColor, false, false );
335 myPreviewPrs->setBorderColor( aBorderColor, false, false );
340 if ( !aViewManager || !myPreviewPrs )
343 Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast(
344 HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) );
346 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
347 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
349 bool aProfMode = aPanel->getProfileMode();
350 HYDROData_Channel::PrsDefinition aPrsDef;
352 double eqDist = aPanel->getEquiDistance();
354 stat = HYDROData_Channel::CreatePresentations( aGuideLine, aProfile, aPrsDef, eqDist);
357 double lc = aPanel->getLCValue();
358 double deltaz = aPanel->getDeltaZValue();
359 double cotez = aPanel->getCoteZValue();
360 stat = HYDROData_Channel::CreatePresentations( aGuideLine, lc, deltaz, cotez, aPrsDef, eqDist);
368 myPreviewPrs->setShape( aPrsDef.myPrs2D );
371 void HYDROGUI_ChannelOp::erasePreview()