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 CurveCreator::Coordinates aCurveCoords;
95 CurveCreator::SectionsMap aSectionsMap;
97 HYDROData_Profile::ProfilePoints aSectPointsList = myEditedObject->GetProfilePoints();
98 CurveCreator::PosPointsList aPoints;
99 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
101 const HYDROData_Profile::ProfilePoint& aSectPoint = aSectPointsList.Value( k );
102 aCurveCoords.clear();
103 aCurveCoords.push_back( aSectPoint.X() );
104 aCurveCoords.push_back( aSectPoint.Z() );
106 CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( k, aCurveCoords );
107 aPoints.push_back( aPosPoint );
109 aSectionsMap[0] = aPoints;
110 myProfile->addPointsInternal( aSectionsMap );
112 aProfileName = myEditedObject->GetName();
116 aProfileName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_PROFILE_NAME" ) );
119 aPanel->setProfileName( aProfileName );
120 aPanel->setProfile( myProfile );
124 void HYDROGUI_ProfileOp::abortOperation()
128 HYDROGUI_Operation::abortOperation();
131 void HYDROGUI_ProfileOp::commitOperation()
135 HYDROGUI_Operation::commitOperation();
138 HYDROGUI_InputPanel* HYDROGUI_ProfileOp::createInputPanel() const
140 HYDROGUI_ProfileDlg* aDlg = new HYDROGUI_ProfileDlg( module(), getName() );
144 bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
145 QString& theErrorMsg )
147 HYDROGUI_ProfileDlg* aPanel = ::qobject_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
151 QString aProfileName = aPanel->getProfileName().simplified();
152 if ( aProfileName.isEmpty() )
154 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
158 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aProfileName ) )
160 // check that there are no other objects with the same name in the document
161 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aProfileName );
162 if( !anObject.IsNull() )
164 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aProfileName );
169 Handle(HYDROData_Profile) aProfileObj;
171 aProfileObj = myEditedObject;
174 aProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) );
177 if( aProfileObj.IsNull() )
180 aProfileObj->SetName(aProfileName);
182 HYDROData_ProfileUZ::PointsList aProfileParamPoints;
184 CurveCreator::Coordinates aCurveCoords = myProfile->getPoints( 0 );
185 for ( int k = 0 ; k + 1 < aCurveCoords.size() ; k++ )
187 HYDROData_ProfileUZ::Point aProfileParamPoint;
189 aProfileParamPoint.SetX( aCurveCoords.at( k ) );
191 aProfileParamPoint.SetY( aCurveCoords.at( k ) );
193 aProfileParamPoints.Append( aProfileParamPoint );
195 aProfileObj->SetParametricPoints( aProfileParamPoints );
198 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aProfileObj, true );
200 theUpdateFlags = UF_Model;
204 void HYDROGUI_ProfileOp::displayPreview()
206 HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
209 Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
212 CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx );
213 myProfile->setDisplayer( aDisplayer );
214 aDisplayer->display( myProfile->constructWire(), true );
219 void HYDROGUI_ProfileOp::erasePreview()
221 HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
222 CurveCreator_Displayer* aDisplayer = myProfile ? myProfile->getDisplayer() : 0;
223 if( aPanel && aDisplayer )
225 Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
228 aDisplayer->erase( true );