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
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_ProfileOp.h"
24 #include "HYDROGUI_ProfileDlg.h"
25 #include "HYDROGUI_Tool.h"
26 #include "HYDROGUI_UpdateFlags.h"
28 #include "HYDROData_Document.h"
29 #include "HYDROData_Profile.h"
30 #include "CurveCreator_Profile.hxx"
31 #include "CurveCreator_Displayer.h"
33 #include <LightApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
35 #include <LightApp_UpdateFlags.h>
37 #include <OCCViewer_ViewManager.h>
38 #include <OCCViewer_ViewModel.h>
39 #include <OCCViewer_ViewWindow.h>
41 #include <OCCViewer_AISSelector.h>
43 #include <Precision.hxx>
45 //static int ZValueIncrement = 0;
47 HYDROGUI_ProfileOp::HYDROGUI_ProfileOp( HYDROGUI_Module* theModule, bool theIsEdit )
48 : HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myProfile(NULL)
50 setName( theIsEdit ? tr( "EDIT_PROFILE" ) : tr( "CREATE_PROFILE" ) );
53 HYDROGUI_ProfileOp::~HYDROGUI_ProfileOp()
59 * Redirect the delete action to input panel
61 void HYDROGUI_ProfileOp::deleteSelected()
63 HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
64 aPanel->deleteSelected();
68 * Checks whether there are some to delete
70 bool HYDROGUI_ProfileOp::deleteEnabled()
72 HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
73 return aPanel->deleteEnabled();
76 void HYDROGUI_ProfileOp::startOperation()
81 myProfile = new CurveCreator_Profile();
83 HYDROGUI_Operation::startOperation();
85 HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
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()
141 HYDROGUI_Operation::abortOperation();
144 void HYDROGUI_ProfileOp::commitOperation()
148 HYDROGUI_Operation::commitOperation();
151 HYDROGUI_InputPanel* HYDROGUI_ProfileOp::createInputPanel() const
153 HYDROGUI_ProfileDlg* aDlg = new HYDROGUI_ProfileDlg( module(), getName() );
157 bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
158 QString& theErrorMsg )
160 HYDROGUI_ProfileDlg* aPanel = ::qobject_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
164 QString aProfileName = aPanel->getProfileName().simplified();
165 if ( aProfileName.isEmpty() )
167 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
171 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aProfileName ) )
173 // check that there are no other objects with the same name in the document
174 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aProfileName );
175 if( !anObject.IsNull() )
177 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aProfileName );
182 Handle(HYDROData_Profile) aProfileObj;
184 aProfileObj = myEditedObject;
187 aProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) );
190 if( aProfileObj.IsNull() )
193 Handle(HYDROData_ProfileUZ) aProfileUZ = aProfileObj->GetProfileUZ();
194 if ( aProfileUZ.IsNull() )
197 aProfileObj->SetName(aProfileName);
199 HYDROData_ProfileUZ::PointsList aProfileParamPoints;
201 CurveCreator::Coordinates aCurveCoords = myProfile->getPoints( 0 );
202 if ( aCurveCoords.size() <= 2 )
204 theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" );
208 for ( int k = 0 ; k + 1 < aCurveCoords.size() ; k++ )
210 HYDROData_ProfileUZ::Point aProfileParamPoint;
212 aProfileParamPoint.SetX( aCurveCoords.at( k ) );
214 aProfileParamPoint.SetY( aCurveCoords.at( k ) );
216 aProfileParamPoints.Append( aProfileParamPoint );
218 aProfileObj->SetParametricPoints( aProfileParamPoints );
220 HYDROData_ProfileUZ::SectionType aSectType = HYDROData_ProfileUZ::SECTION_POLYLINE;
221 if ( myProfile->getSectionType( 0 ) == CurveCreator::Spline )
222 aSectType = HYDROData_ProfileUZ::SECTION_SPLINE;
224 aProfileUZ->SetSectionType( 0, aSectType );
228 aProfileObj->SetBorderColor( HYDROData_Profile::DefaultBorderColor() );
231 // At first we update the child u,z profile object
232 aProfileUZ->SetToUpdate( true );
233 aProfileUZ->Update();
235 // And now we update our edited object
236 aProfileObj->Update();
238 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
242 void HYDROGUI_ProfileOp::displayPreview()
244 HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
247 Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
250 CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx );
251 myProfile->setDisplayer( aDisplayer );
252 aDisplayer->display( myProfile->getAISObject( true ), true );
257 void HYDROGUI_ProfileOp::erasePreview()
259 HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
260 CurveCreator_Displayer* aDisplayer = myProfile ? myProfile->getDisplayer() : 0;
261 if( aPanel && aDisplayer )
263 Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
266 aDisplayer->eraseAll( true );