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_Curve.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), myCurve(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()
85 HYDROGUI_Operation::startOperation();
87 HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
90 //LightApp_Application* anApp = module()->getApp();
92 // dynamic_cast<OCCViewer_ViewManager*>( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
93 //aPanel->setOCCViewer( myViewManager ? myViewManager->getOCCViewer() : 0 );
96 myEditedObject = Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
97 if( !myEditedObject.IsNull() )
99 /*int anIntDim = myEditedObject->GetDimension();
100 CurveCreator::Dimension aDim = CurveCreator::Dim3d;
102 aDim = CurveCreator::Dim2d;
103 myCurve = new CurveCreator_Curve(aDim);
104 QList<PolylineSection> aPolylineData = myEditedObject->GetPolylineData();
106 for( int i = 0 ; i < aPolylineData.size() ; i++ ){
107 std::string aName = HYDROGUI_Tool::ToQString(aPolylineData[i].mySectionName).toStdString();
108 bool isClosed = aPolylineData[i].myIsClosed;
109 CurveCreator::SectionType aType = CurveCreator::Polyline;
110 if( aPolylineData[i].myType == PolylineSection::SECTION_SPLINE ){
111 aType = CurveCreator::Spline;
113 CurveCreator::Coordinates aCoords;
114 for( int j = 0 ; j < aPolylineData[i].myCoords.size() ; j++ ){
115 aCoords.push_back(aPolylineData[i].myCoords[j]);
117 myCurve->addSectionInternal( aName, aType, isClosed, aCoords );
119 aPanel->setProfileName( myEditedObject->GetName() );
123 /*myCurve = new CurveCreator_Curve(CurveCreator::Dim2d);*/
124 //aPanel->setCurve(myCurve);
125 QString aNewName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_PROFILE_NAME" ) );
126 aPanel->setProfileName(aNewName);
128 /*aPanel->setCurve(myCurve);*/
132 void HYDROGUI_ProfileOp::abortOperation()
134 //HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
136 // aPanel->setOCCViewer( 0 );
139 HYDROGUI_Operation::abortOperation();
142 void HYDROGUI_ProfileOp::commitOperation()
144 //HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
146 // aPanel->setOCCViewer( 0 );
149 HYDROGUI_Operation::commitOperation();
152 HYDROGUI_InputPanel* HYDROGUI_ProfileOp::createInputPanel() const
154 HYDROGUI_ProfileDlg* aDlg = new HYDROGUI_ProfileDlg( module(), getName() );
155 //connect( aDlg, SIGNAL( selectionChanged() ), this, SLOT( onEditorSelectionChanged() ) );
159 bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
160 QString& theErrorMsg )
162 HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
164 int aStudyId = module()->getStudyId();
165 bool aHasDoc = HYDROData_Document::HasDocument(aStudyId);
166 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
167 if( aDocument.IsNull() )
170 Handle(HYDROData_Profile) aProfileObj;
172 aProfileObj = myEditedObject;
175 aProfileObj = Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
177 //double aZValue = double( ++ZValueIncrement ) * 1e-2; // empiric value, to be revised
178 //aProfileObj->SetZValue( aZValue );
181 if( aProfileObj.IsNull() )
184 QString aProfileName = aPanel->getProfileName();
185 aProfileObj->SetName(aProfileName);
188 if( myCurve->getDimension() == CurveCreator::Dim2d )
190 aProfileObj->SetDimension(aDimInt);
191 QList<PolylineSection> aPolylineData;
192 for( int i=0 ; i < myCurve->getNbSections() ; i++ ){
193 PolylineSection aSect;
194 aSect.mySectionName = HYDROGUI_Tool::ToExtString( QString::fromLocal8Bit(myCurve->getSectionName(i).c_str()));
195 aSect.myIsClosed = myCurve->isClosed(i);
196 aSect.myType = PolylineSection::SECTION_POLYLINE;
197 if( myCurve->getSectionType(i) == CurveCreator::Spline ){
198 aSect.myType = PolylineSection::SECTION_SPLINE;
200 CurveCreator::Coordinates aCoords = myCurve->getPoints(i);
201 for( int j = 0 ; j < aCoords.size() ; j++ ){
202 aSect.myCoords << aCoords.at(j);
204 aPolylineData << aSect;
206 aProfileObj->SetPolylineData(aPolylineData);
208 // the viewer should be release from the widget before the module update it
209 // because it has an opened local context and updated presentation should not be displayed in it
211 // aPanel->setOCCViewer( 0 );
214 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aProfileObj, true );
216 theUpdateFlags = UF_Model;
220 /*void HYDROGUI_ProfileOp::onEditorSelectionChanged()
222 HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
227 CurveCreator_Displayer* aDisplayer = myCurve->getDisplayer();
230 QList<int> aSelSections = aPanel->getSelectedSections();
231 for( int i = 0 ; i < myCurve->getNbSections() ; i++ ){
233 if( aSelSections.contains(i) ){
234 aDisplayer->highlight( myCurve->constructSection(i), aIsHl );
239 /*void HYDROGUI_ProfileOp::displayPreview()
243 if( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() )
245 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
248 CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx );
249 myCurve->setDisplayer( aDisplayer );
250 aDisplayer->display( myCurve->constructWire() );
256 /*void HYDROGUI_ProfileOp::erasePreview()
258 CurveCreator_Displayer* aDisplayer = myCurve ? myCurve->getDisplayer() : 0;
259 if( myViewManager && aDisplayer )
261 if( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() )
263 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();