1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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_ProfileInterpolateOp.h>
25 #include "HYDROGUI_Tool.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_DataObject.h"
28 #include "HYDROGUI_UpdateFlags.h"
29 #include "HYDROGUI_ProfileInterpolateDlg.h"
31 #include <HYDROData_Stream.h>
32 #include <HYDROData_Profile.h>
34 #include <LightApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <LightApp_UpdateFlags.h>
38 #include <OCCViewer_ViewModel.h>
39 #include <OCCViewer_ViewManager.h>
40 #include <OCCViewer_ViewWindow.h>
41 #include <OCCViewer_AISSelector.h>
43 #include <AIS_ListOfInteractive.hxx>
44 #include <AIS_ListIteratorOfListOfInteractive.hxx>
46 HYDROGUI_ProfileInterpolateOp::HYDROGUI_ProfileInterpolateOp( HYDROGUI_Module* theModule )
47 : HYDROGUI_Operation( theModule )
49 setName( tr( "PROFILE_INTERPOLATION" ) );
52 HYDROGUI_ProfileInterpolateOp::~HYDROGUI_ProfileInterpolateOp()
56 void HYDROGUI_ProfileInterpolateOp::startOperation()
58 HYDROGUI_Operation::startOperation();
60 HYDROGUI_ProfileInterpolateDlg* aPanel = ::qobject_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
64 aPanel->setInterpolators( interpolators() );
69 myEditedObject = Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
72 if( !myEditedObject.IsNull() )
74 Handle(HYDROData_ProfileUZ) aProfileUZ = myEditedObject->GetProfileUZ( false );
75 if ( !aProfileUZ.IsNull() )
77 CurveCreator::Coordinates aCurveCoords;
78 CurveCreator::SectionsMap aSectionsMap;
80 HYDROData_ProfileUZ::PointsList aSectPointsList = aProfileUZ->GetPoints();
81 CurveCreator::PosPointsList aPoints;
82 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
84 const HYDROData_ProfileUZ::Point& aSectPoint = aSectPointsList.Value( k );
86 aCurveCoords.push_back( aSectPoint.X() );
87 aCurveCoords.push_back( aSectPoint.Y() );
89 CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( k, aCurveCoords );
90 aPoints.push_back( aPosPoint );
93 aSectionsMap[0] = aPoints;
94 myProfile->addPointsInternal( aSectionsMap );
96 HYDROData_ProfileUZ::SectionType aSectType = aProfileUZ->GetSectionType( 0 );
98 CurveCreator::SectionType aCurveType = CurveCreator::Polyline;
99 if( aSectType == HYDROData_ProfileUZ::SECTION_SPLINE )
100 aCurveType = CurveCreator::Spline;
102 myProfile->setSectionType( 0, aCurveType );
105 aProfileName = myEditedObject->GetName();
109 aProfileName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_PROFILE_NAME" ) );
112 aPanel->setProfileName( aProfileName );
113 aPanel->setProfile( myProfile );
118 void HYDROGUI_ProfileInterpolateOp::abortOperation()
120 HYDROGUI_Operation::abortOperation();
123 void HYDROGUI_ProfileInterpolateOp::commitOperation()
125 HYDROGUI_Operation::commitOperation();
128 HYDROGUI_InputPanel* HYDROGUI_ProfileInterpolateOp::createInputPanel() const
130 HYDROGUI_ProfileInterpolateDlg* aDlg = new HYDROGUI_ProfileInterpolateDlg( module(), getName() );
132 connect( aDlg, SIGNAL( riverChanged( const QString& ) ), this, SLOT( onRiverChanged( const QString& ) ) );
133 connect( aDlg, SIGNAL( interpolatorChanged( const QString& ) ), this, SLOT( onInterpolatorChanged( const QString& ) ) );
134 connect( aDlg, SIGNAL( interpolatorParametersChanged( const QString& ) ), this, SLOT( updatePreview() ) );
135 connect( aDlg, SIGNAL( profileNumberChanged( int ) ), this, SLOT( updatePreview() ) );
136 connect( aDlg, SIGNAL( profileStartChanged( const QString& ) ), this, SLOT( updatePreview() ) );
137 connect( aDlg, SIGNAL( profileFinishChanged( const QString& ) ), this, SLOT( updatePreview() ) );
142 bool HYDROGUI_ProfileInterpolateOp::processApply( int& theUpdateFlags, QString& theErrorMsg,
143 QStringList& theBrowseObjectsEntries )
145 HYDROGUI_ProfileInterpolateDlg* aPanel = ::qobject_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
149 QString aProfileName = aPanel->getProfileName().simplified();
150 if ( aProfileName.isEmpty() )
152 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
156 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aProfileName ) )
158 // check that there are no other objects with the same name in the document
159 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aProfileName );
160 if( !anObject.IsNull() )
162 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aProfileName );
167 Handle(HYDROData_Profile) aProfileObj;
169 aProfileObj = myEditedObject;
172 aProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) );
175 if( aProfileObj.IsNull() )
178 Handle(HYDROData_ProfileUZ) aProfileUZ = aProfileObj->GetProfileUZ();
179 if ( aProfileUZ.IsNull() )
182 aProfileObj->SetName(aProfileName);
184 HYDROData_ProfileUZ::PointsList aProfileParamPoints;
186 CurveCreator::Coordinates aCurveCoords = myProfile->getPoints( 0 );
187 if ( aCurveCoords.size() <= 2 )
189 theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" );
193 for ( int k = 0 ; k + 1 < aCurveCoords.size() ; k++ )
195 HYDROData_ProfileUZ::Point aProfileParamPoint;
197 aProfileParamPoint.SetX( aCurveCoords.at( k ) );
199 aProfileParamPoint.SetY( aCurveCoords.at( k ) );
201 aProfileParamPoints.Append( aProfileParamPoint );
203 aProfileObj->SetParametricPoints( aProfileParamPoints );
205 HYDROData_ProfileUZ::SectionType aSectType = HYDROData_ProfileUZ::SECTION_POLYLINE;
206 if ( myProfile->getSectionType( 0 ) == CurveCreator::Spline )
207 aSectType = HYDROData_ProfileUZ::SECTION_SPLINE;
209 aProfileUZ->SetSectionType( 0, aSectType );
213 aProfileObj->SetBorderColor( HYDROData_Profile::DefaultBorderColor() );
216 // At first we update the child u,z profile object
217 aProfileUZ->SetToUpdate( true );
218 aProfileUZ->Update();
220 // And now we update our edited object
221 aProfileObj->Update();
222 module()->setIsToUpdate( aProfileObj );
224 theUpdateFlags = UF_Model;
226 theUpdateFlags |= UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
229 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aProfileObj );
230 theBrowseObjectsEntries.append( anEntry );
237 void HYDROGUI_ProfileInterpolateOp::updatePreview()
239 HYDROGUI_ProfileInterpolateDlg* aDlg = ::qobject_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
243 Handle(AIS_InteractiveContext) aCtx = aDlg->getAISContext();
247 aCtx->UpdateCurrentViewer();
250 QStringList HYDROGUI_ProfileInterpolateOp::interpolators() const
252 return QStringList() << "Linear interpolator" << "Spline interpolator";
255 void HYDROGUI_ProfileInterpolateOp::onInterpolatorChanged( const QString& theInterpName )
257 HYDROGUI_ProfileInterpolateDlg* aPanel = dynamic_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
261 aPanel->setInterpolatorDescription( QString( "Profile will be calculated used %1" ).arg( theInterpName ) );
266 void HYDROGUI_ProfileInterpolateOp::onRiverChanged( const QString& theRiver )
268 HYDROGUI_ProfileInterpolateDlg* aDlg = ::qobject_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
272 Handle(AIS_InteractiveContext) aCtx = aDlg->getAISContext();
273 if ( !aCtx.IsNull() )
275 AIS_ListOfInteractive aList;
276 aCtx->DisplayedObjects( aList );
277 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
279 Handle(AIS_Shape) anObj = Handle(AIS_Shape)::DownCast( it.Value() );
280 if ( !anObj.IsNull() )
281 aCtx->Remove( anObj, false );
284 Handle(HYDROData_Stream) aStream = Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theRiver, KIND_STREAM ) );
285 if ( !aStream.IsNull() )
287 HYDROData_SequenceOfObjects aSeq = aStream->GetProfiles();
288 for ( int i = aSeq.Lower(); i <= aSeq.Upper(); i++ )
290 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aSeq.Value( i ) );
291 if ( !aProfile.IsNull() )
293 Handle(AIS_Shape) aPrs = new AIS_Shape( aProfile->GetShape3D() );
294 aPrs->SetOwner( aProfile );
295 aPrs->SetColor( Quantity_NOC_BLACK );
296 aCtx->Display( aPrs, 0, 0, false );