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;
71 bool profile_mode = true;
74 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CHANNEL_NAME" ) );
77 if ( isApplyAndClose() )
79 Handle(HYDROData_Channel)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
80 if ( !myEditedObject.IsNull() )
82 anObjectName = myEditedObject->GetName();
84 Handle(HYDROData_Polyline3D) aRefGuideLine = myEditedObject->GetGuideLine();
85 if ( !aRefGuideLine.IsNull() )
86 aSelectedGuideLine = aRefGuideLine->GetName();
88 Handle(HYDROData_Profile) aRefProfile = myEditedObject->GetProfile();
89 if ( !aRefProfile.IsNull() )
90 aSelectedProfile = aRefProfile->GetName();
92 profile_mode = myEditedObject->GetProfileMode();
96 // collect information about existing 3d polylines
97 QStringList aGuideLines;
98 HYDROData_Iterator aPolylinesIt( doc(), KIND_POLYLINE );
99 for ( ; aPolylinesIt.More(); aPolylinesIt.Next() )
101 Handle(HYDROData_Polyline3D) aPolyline3d =
102 Handle(HYDROData_Polyline3D)::DownCast( aPolylinesIt.Current() );
103 if( !aPolyline3d.IsNull() )
105 TopoDS_Shape aShape = aPolyline3d->GetShape3D();
106 if( aShape.ShapeType()==TopAbs_WIRE )
108 TopoDS_Wire aWire = TopoDS::Wire( aShape );
109 if( !aWire.Closed() )
110 aGuideLines.append( aPolyline3d->GetName() );
115 // collect information about existing profiles
116 QStringList aProfiles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_PROFILE, false );
118 aPanel->setObjectName( anObjectName );
120 aPanel->setGuideLineNames( aGuideLines );
121 aPanel->setProfileNames( aProfiles );
123 aPanel->setGuideLineName( aSelectedGuideLine );
124 aPanel->setProfileName( aSelectedProfile );
126 if( !myEditedObject.IsNull() )
128 aPanel->setEquiDistance( myEditedObject->GetEquiDistance() );
129 if (!profile_mode) //predef
131 aPanel->setLCValue( myEditedObject->GetLCValue() );
132 aPanel->setCoteZValue( myEditedObject->GetCoteZValue() );
133 aPanel->setDeltaZValue( myEditedObject->GetDeltaZValue() );
137 aPanel->setEquiDistance( 1.0 );
139 if( !myEditedObject.IsNull() )
141 bool invDirection = false;
142 Handle(HYDROData_IAltitudeObject) anObjAltitude = myEditedObject->GetAltitudeObject();
143 Handle(HYDROData_ChannelAltitude) aChannelAlt = Handle(HYDROData_ChannelAltitude)::DownCast(anObjAltitude);
144 if (!aChannelAlt.IsNull())
145 invDirection = aChannelAlt->GetInvertDirection();
146 aPanel->setInvertDirection( invDirection );
149 aPanel->setInvertDirection( false );
151 aPanel->blockSignals( false );
152 aPanel->setProfileMode(profile_mode);
157 void HYDROGUI_ChannelOp::abortOperation()
160 HYDROGUI_Operation::abortOperation();
163 void HYDROGUI_ChannelOp::commitOperation()
166 HYDROGUI_Operation::commitOperation();
169 HYDROGUI_InputPanel* HYDROGUI_ChannelOp::createInputPanel() const
171 HYDROGUI_ChannelDlg* aPanel = new HYDROGUI_ChannelDlg( module(), getName() );
172 connect( aPanel, SIGNAL( CreatePreview() ), this, SLOT( onCreatePreview() ) );
176 bool HYDROGUI_ChannelOp::processApply( int& theUpdateFlags,
177 QString& theErrorMsg,
178 QStringList& theBrowseObjectsEntries )
180 HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
184 QString anObjectName = aPanel->getObjectName().simplified();
185 if ( anObjectName.isEmpty() )
187 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
191 if ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
193 // check that there are no other objects with the same name in the document
194 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
195 if( !anObject.IsNull() )
197 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
203 if ( myEditedObject.IsNull() )
204 myEditedObject = createNewObject(); // Create new data model object
206 myEditedObject->SetName( anObjectName );
210 myEditedObject->SetFillingColor( myEditedObject->DefaultFillingColor() );
211 myEditedObject->SetBorderColor( myEditedObject->DefaultBorderColor() );
214 QString aGuideLineName = aPanel->getGuideLineName();
216 bool profileMode = aPanel->getProfileMode();
217 QString aProfileName;
218 double lc=0, deltaz=0, cotez=0;
222 aProfileName = aPanel->getProfileName();
226 lc = aPanel->getLCValue();
227 deltaz = aPanel->getDeltaZValue();
228 cotez = aPanel->getCoteZValue();
232 /*if ( aGuideLineName.isEmpty() || aProfileName.isEmpty() )
234 myEditedObject->RemoveGuideLine();
235 myEditedObject->RemoveProfile();
239 Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast(
240 HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) );
241 if ( aGuideLine.IsNull() )
243 theErrorMsg = tr( "GUIDE_LINE_IS_NOT_SELECTED" );
247 myEditedObject->RemoveGuideLine();
248 myEditedObject->SetGuideLine( aGuideLine );
250 myEditedObject->SetProfileMode(profileMode);
254 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
255 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
256 if ( aProfile.IsNull() )
258 theErrorMsg = tr( "PROFILE_IS_NOT_SELECTED" );
261 myEditedObject->RemoveProfile();
262 myEditedObject->SetProfile( aProfile );
263 myEditedObject->SetLCValue(0);
264 myEditedObject->SetDeltaZValue(0);
265 myEditedObject->SetCoteZValue(0);
269 myEditedObject->RemoveProfile();
270 myEditedObject->SetLCValue(lc);
271 myEditedObject->SetDeltaZValue(deltaz);
272 myEditedObject->SetCoteZValue(cotez);
275 myEditedObject->SetEquiDistance( aPanel->getEquiDistance() );
277 Handle(HYDROData_IAltitudeObject) anObjAltitude = myEditedObject->GetAltitudeObject();
278 Handle(HYDROData_ChannelAltitude) aChannelAlt = Handle(HYDROData_ChannelAltitude)::DownCast(anObjAltitude);
279 if (!aChannelAlt.IsNull())
280 aChannelAlt->SetInvertDirection(aPanel->getInvertDirection());
283 if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) )
284 myEditedObject->Update();
290 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true );
291 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
292 theBrowseObjectsEntries.append( anEntry );
295 module()->setIsToUpdate( myEditedObject );
297 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
302 Handle(HYDROData_Channel) HYDROGUI_ChannelOp::createNewObject() const
304 return Handle(HYDROData_Channel)::DownCast( doc()->CreateObject( KIND_CHANNEL ) );
307 void HYDROGUI_ChannelOp::onCreatePreview()
309 HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
313 QString aGuideLineName = aPanel->getGuideLineName();
314 QString aProfileName = aPanel->getProfileName();
315 if ( aGuideLineName.isEmpty() || aProfileName.isEmpty() )
321 LightApp_Application* anApp = module()->getApp();
323 if ( !getPreviewManager() )
325 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
326 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
329 OCCViewer_ViewManager* aViewManager = getPreviewManager();
330 if ( aViewManager && !myPreviewPrs )
332 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
334 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
335 if ( !aCtx.IsNull() )
337 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
339 QColor aFillingColor = Qt::blue;
340 QColor aBorderColor = Qt::transparent;
341 if ( !myEditedObject.IsNull() )
343 aFillingColor = myEditedObject->GetFillingColor();
344 aBorderColor = myEditedObject->GetBorderColor();
347 myPreviewPrs->setFillingColor( aFillingColor, false, false );
348 myPreviewPrs->setBorderColor( aBorderColor, false, false );
353 if ( !aViewManager || !myPreviewPrs )
356 Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast(
357 HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) );
359 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
360 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
362 bool aProfMode = aPanel->getProfileMode();
363 HYDROData_Channel::PrsDefinition aPrsDef;
365 double eqDist = aPanel->getEquiDistance();
367 stat = HYDROData_Channel::CreatePresentations( aGuideLine, aProfile, aPrsDef, eqDist);
370 double lc = aPanel->getLCValue();
371 double deltaz = aPanel->getDeltaZValue();
372 double cotez = aPanel->getCoteZValue();
373 stat = HYDROData_Channel::CreatePresentations( aGuideLine, lc, deltaz, cotez, aPrsDef, eqDist);
381 myPreviewPrs->setShape( aPrsDef.myPrs2D );
384 void HYDROGUI_ChannelOp::erasePreview()