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_Module.h>
24 #include <HYDROGUI_ProfileOp.h>
25 #include <HYDROGUI_ProfileDlg.h>
26 #include <HYDROGUI_Tool.h>
27 #include <HYDROGUI_UpdateFlags.h>
28 #include <HYDROGUI_DataObject.h>
29 #include <HYDROData_Document.h>
30 #include <HYDROData_Profile.h>
31 #include <HYDROGUI_CurveCreatorProfile.h>
32 #include <CurveCreator_Displayer.hxx>
34 #include <LightApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <LightApp_UpdateFlags.h>
38 #include <OCCViewer_ViewManager.h>
39 #include <OCCViewer_ViewModel.h>
40 #include <OCCViewer_ViewWindow.h>
42 #include <OCCViewer_AISSelector.h>
44 #include <Precision.hxx>
46 //static int ZValueIncrement = 0;
48 HYDROGUI_ProfileOp::HYDROGUI_ProfileOp( HYDROGUI_Module* theModule, bool theIsEdit )
49 : HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myProfile(NULL)
51 setName( theIsEdit ? tr( "EDIT_PROFILE" ) : tr( "CREATE_PROFILE" ) );
54 HYDROGUI_ProfileOp::~HYDROGUI_ProfileOp()
60 * Redirect the delete action to input panel
62 void HYDROGUI_ProfileOp::deleteSelected()
64 HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
65 aPanel->deleteSelected();
69 * Checks whether there are some to delete
71 bool HYDROGUI_ProfileOp::deleteEnabled()
73 HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
74 return aPanel->deleteEnabled();
77 void HYDROGUI_ProfileOp::startOperation()
82 myProfile = new HYDROGUI_CurveCreatorProfile();
84 HYDROGUI_Operation::startOperation();
86 HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
90 myEditedObject = Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
93 if( !myEditedObject.IsNull() )
95 Handle(HYDROData_ProfileUZ) aProfileUZ = myEditedObject->GetProfileUZ( false );
96 if ( !aProfileUZ.IsNull() )
98 CurveCreator::Coordinates aCurveCoords;
99 CurveCreator::SectionsMap aSectionsMap;
101 HYDROData_ProfileUZ::PointsList aSectPointsList = aProfileUZ->GetPoints();
102 CurveCreator::PosPointsList aPoints;
103 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
105 const HYDROData_ProfileUZ::Point& aSectPoint = aSectPointsList.Value( k );
106 aCurveCoords.clear();
107 aCurveCoords.push_back( aSectPoint.X() );
108 aCurveCoords.push_back( aSectPoint.Y() );
110 CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( k, aCurveCoords );
111 aPoints.push_back( aPosPoint );
114 aSectionsMap[0] = aPoints;
115 myProfile->addPointsInternal( aSectionsMap );
117 HYDROData_ProfileUZ::SectionType aSectType = aProfileUZ->GetSectionType( 0 );
119 CurveCreator::SectionType aCurveType = CurveCreator::Polyline;
120 if( aSectType == HYDROData_ProfileUZ::SECTION_SPLINE )
121 aCurveType = CurveCreator::Spline;
123 myProfile->setSectionType( 0, aCurveType );
126 aProfileName = myEditedObject->GetName();
130 aProfileName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_PROFILE_NAME" ) );
133 aPanel->setProfileName( aProfileName );
134 aPanel->setProfile( myProfile );
138 void HYDROGUI_ProfileOp::abortOperation()
142 HYDROGUI_Operation::abortOperation();
145 void HYDROGUI_ProfileOp::commitOperation()
149 HYDROGUI_Operation::commitOperation();
152 HYDROGUI_InputPanel* HYDROGUI_ProfileOp::createInputPanel() const
154 HYDROGUI_ProfileDlg* aDlg = new HYDROGUI_ProfileDlg( module(), getName() );
158 bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
159 QString& theErrorMsg,
160 QStringList& theBrowseObjectsEntries )
162 HYDROGUI_ProfileDlg* aPanel = ::qobject_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
166 QString aProfileName = aPanel->getProfileName().simplified();
167 if ( aProfileName.isEmpty() )
169 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
173 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aProfileName ) )
175 // check that there are no other objects with the same name in the document
176 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aProfileName );
177 if( !anObject.IsNull() )
179 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aProfileName );
184 Handle(HYDROData_Profile) aProfileObj;
186 aProfileObj = myEditedObject;
189 aProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) );
192 if( aProfileObj.IsNull() )
195 Handle(HYDROData_ProfileUZ) aProfileUZ = aProfileObj->GetProfileUZ();
196 if ( aProfileUZ.IsNull() )
199 aProfileObj->SetName(aProfileName);
201 HYDROData_ProfileUZ::PointsList aProfileParamPoints;
203 CurveCreator::Coordinates aCurveCoords = myProfile->getPoints( 0 );
204 if ( aCurveCoords.size() <= 2 )
206 theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" );
210 for ( int k = 0 ; k + 1 < aCurveCoords.size() ; k++ )
212 HYDROData_ProfileUZ::Point aProfileParamPoint;
214 aProfileParamPoint.SetX( aCurveCoords.at( k ) );
216 aProfileParamPoint.SetY( aCurveCoords.at( k ) );
218 aProfileParamPoints.Append( aProfileParamPoint );
220 aProfileObj->SetParametricPoints( aProfileParamPoints );
222 HYDROData_ProfileUZ::SectionType aSectType = HYDROData_ProfileUZ::SECTION_POLYLINE;
223 if ( myProfile->getSectionType( 0 ) == CurveCreator::Spline )
224 aSectType = HYDROData_ProfileUZ::SECTION_SPLINE;
226 aProfileUZ->SetSectionType( 0, aSectType );
230 aProfileObj->SetBorderColor( HYDROData_Profile::DefaultBorderColor() );
233 // At first we update the child u,z profile object
234 aProfileUZ->SetToUpdate( true );
235 aProfileUZ->Update();
237 // And now we update our edited object
238 aProfileObj->Update();
239 module()->setIsToUpdate( aProfileObj );
241 theUpdateFlags = UF_Model;
243 theUpdateFlags |= UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
246 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aProfileObj );
247 theBrowseObjectsEntries.append( anEntry );
253 void HYDROGUI_ProfileOp::displayPreview()
255 HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
258 Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
261 CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx );
262 myProfile->setDisplayer( aDisplayer );
263 aDisplayer->display( myProfile->getAISObject( true ), true );
268 void HYDROGUI_ProfileOp::erasePreview()
270 HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
271 CurveCreator_Displayer* aDisplayer = myProfile ? myProfile->getDisplayer() : 0;
272 if( aPanel && aDisplayer )
274 Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
277 aDisplayer->eraseAll( true );