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_Module.h>
20 #include <HYDROGUI_ProfileOp.h>
21 #include <HYDROGUI_ProfileDlg.h>
22 #include <HYDROGUI_Tool.h>
23 #include <HYDROGUI_UpdateFlags.h>
24 #include <HYDROGUI_DataObject.h>
25 #include <HYDROData_Document.h>
26 #include <HYDROData_Profile.h>
27 #include <HYDROGUI_CurveCreatorProfile.h>
28 #include <CurveCreator_Displayer.hxx>
30 #include <LightApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32 #include <LightApp_UpdateFlags.h>
34 #include <OCCViewer_ViewManager.h>
35 #include <OCCViewer_ViewModel.h>
36 #include <OCCViewer_ViewWindow.h>
38 #include <OCCViewer_AISSelector.h>
40 #include <Precision.hxx>
42 //static int ZValueIncrement = 0;
44 HYDROGUI_ProfileOp::HYDROGUI_ProfileOp( HYDROGUI_Module* theModule, bool theIsEdit )
45 : HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myProfile(NULL)
47 setName( theIsEdit ? tr( "EDIT_PROFILE" ) : tr( "CREATE_PROFILE" ) );
50 HYDROGUI_ProfileOp::~HYDROGUI_ProfileOp()
56 * Redirect the delete action to input panel
58 void HYDROGUI_ProfileOp::deleteSelected()
60 HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
61 aPanel->deleteSelected();
65 * Checks whether there are some to delete
67 bool HYDROGUI_ProfileOp::deleteEnabled()
69 HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
70 return aPanel->deleteEnabled();
73 void HYDROGUI_ProfileOp::startOperation()
78 myProfile = new HYDROGUI_CurveCreatorProfile();
80 HYDROGUI_Operation::startOperation();
82 HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
84 setPreviewManager( aPanel->viewManager() );
88 if ( isApplyAndClose() )
89 myEditedObject = Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
92 if( !myEditedObject.IsNull() )
94 Handle(HYDROData_ProfileUZ) aProfileUZ = myEditedObject->GetProfileUZ( false );
95 if ( !aProfileUZ.IsNull() )
97 CurveCreator::Coordinates aCurveCoords;
98 CurveCreator::SectionsMap aSectionsMap;
100 HYDROData_ProfileUZ::PointsList aSectPointsList = aProfileUZ->GetPoints();
101 CurveCreator::PosPointsList aPoints;
102 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
104 const HYDROData_ProfileUZ::Point& aSectPoint = aSectPointsList.Value( k );
105 aCurveCoords.clear();
106 aCurveCoords.push_back( aSectPoint.X() );
107 aCurveCoords.push_back( aSectPoint.Y() );
109 CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( k, aCurveCoords );
110 aPoints.push_back( aPosPoint );
113 aSectionsMap[0] = aPoints;
114 myProfile->addPointsInternal( aSectionsMap );
116 HYDROData_ProfileUZ::SectionType aSectType = aProfileUZ->GetSectionType( 0 );
118 CurveCreator::SectionType aCurveType = CurveCreator::Polyline;
119 if( aSectType == HYDROData_ProfileUZ::SECTION_SPLINE )
120 aCurveType = CurveCreator::Spline;
122 myProfile->setSectionType( 0, aCurveType );
125 aProfileName = myEditedObject->GetName();
129 aProfileName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_PROFILE_NAME" ) );
132 aPanel->setProfileName( aProfileName );
133 aPanel->setProfile( myProfile );
137 void HYDROGUI_ProfileOp::abortOperation()
142 HYDROGUI_Operation::abortOperation();
145 void HYDROGUI_ProfileOp::commitOperation()
150 HYDROGUI_Operation::commitOperation();
153 HYDROGUI_InputPanel* HYDROGUI_ProfileOp::createInputPanel() const
155 HYDROGUI_ProfileDlg* aDlg = new HYDROGUI_ProfileDlg( module(), getName() );
159 bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
160 QString& theErrorMsg,
161 QStringList& theBrowseObjectsEntries )
163 HYDROGUI_ProfileDlg* aPanel = ::qobject_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
167 QString aProfileName = aPanel->getProfileName().simplified();
168 if ( aProfileName.isEmpty() )
170 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
174 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aProfileName ) )
176 // check that there are no other objects with the same name in the document
177 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aProfileName );
178 if( !anObject.IsNull() )
180 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aProfileName );
185 Handle(HYDROData_Profile) aProfileObj;
187 aProfileObj = myEditedObject;
190 aProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) );
193 if( aProfileObj.IsNull() )
196 Handle(HYDROData_ProfileUZ) aProfileUZ = aProfileObj->GetProfileUZ();
197 if ( aProfileUZ.IsNull() )
200 aProfileObj->SetName(aProfileName);
202 HYDROData_ProfileUZ::PointsList aProfileParamPoints;
204 CurveCreator::Coordinates aCurveCoords = myProfile->getPoints( 0 );
205 if ( aCurveCoords.size() <= 2 )
207 theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" );
211 for ( int k = 0 ; k + 1 < aCurveCoords.size() ; k++ )
213 HYDROData_ProfileUZ::Point aProfileParamPoint;
215 aProfileParamPoint.SetX( aCurveCoords.at( k ) );
217 aProfileParamPoint.SetY( aCurveCoords.at( k ) );
219 aProfileParamPoints.Append( aProfileParamPoint );
221 aProfileObj->SetParametricPoints( aProfileParamPoints );
223 HYDROData_ProfileUZ::SectionType aSectType = HYDROData_ProfileUZ::SECTION_POLYLINE;
224 if ( myProfile->getSectionType( 0 ) == CurveCreator::Spline )
225 aSectType = HYDROData_ProfileUZ::SECTION_SPLINE;
227 aProfileUZ->SetSectionType( 0, aSectType );
231 aProfileObj->SetBorderColor( HYDROData_Profile::DefaultBorderColor() );
234 // At first we update the child u,z profile object
235 aProfileUZ->SetToUpdate( true );
236 aProfileUZ->Update();
238 // And now we update our edited object
239 aProfileObj->Update();
240 module()->setIsToUpdate( aProfileObj );
242 theUpdateFlags = UF_Model;
244 theUpdateFlags |= UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
247 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aProfileObj );
248 theBrowseObjectsEntries.append( anEntry );
254 void HYDROGUI_ProfileOp::displayPreview()
256 HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
259 Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
262 CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx );
263 myProfile->setDisplayer( aDisplayer );
264 aDisplayer->display( myProfile->getAISObject( true ), true );
269 void HYDROGUI_ProfileOp::erasePreview()
271 HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
272 CurveCreator_Displayer* aDisplayer = myProfile ? myProfile->getDisplayer() : 0;
273 if( aPanel && aDisplayer )
275 Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
278 aDisplayer->eraseAll( true );