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 = (HYDROGUI_ProfileDlg*)inputPanel();
149 int aStudyId = module()->getStudyId();
150 bool aHasDoc = HYDROData_Document::HasDocument(aStudyId);
151 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
152 if( aDocument.IsNull() )
155 Handle(HYDROData_Profile) aProfileObj;
157 aProfileObj = myEditedObject;
160 aProfileObj = Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
162 //double aZValue = double( ++ZValueIncrement ) * 1e-2; // empiric value, to be revised
163 //aProfileObj->SetZValue( aZValue );
166 if( aProfileObj.IsNull() )
169 QString aProfileName = aPanel->getProfileName();
170 aProfileObj->SetName(aProfileName);
172 HYDROData_ProfileUZ::PointsList aProfileParamPoints;
174 CurveCreator::Coordinates aCurveCoords = myProfile->getPoints( 0 );
175 for ( int k = 0 ; k + 1 < aCurveCoords.size() ; k++ )
177 HYDROData_ProfileUZ::Point aProfileParamPoint;
179 aProfileParamPoint.SetX( aCurveCoords.at( k ) );
181 aProfileParamPoint.SetY( aCurveCoords.at( k ) );
183 aProfileParamPoints.Append( aProfileParamPoint );
185 aProfileObj->SetParametricPoints( aProfileParamPoints );
188 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aProfileObj, true );
190 theUpdateFlags = UF_Model;
194 void HYDROGUI_ProfileOp::displayPreview()
196 HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
199 Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
202 CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx );
203 myProfile->setDisplayer( aDisplayer );
204 aDisplayer->display( myProfile->constructWire(), true );
209 void HYDROGUI_ProfileOp::erasePreview()
211 HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
212 CurveCreator_Displayer* aDisplayer = myProfile ? myProfile->getDisplayer() : 0;
213 if( aPanel && aDisplayer )
215 Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
218 aDisplayer->erase( true );