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
23 #include "HYDROGUI_StreamOp.h"
25 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_Shape.h"
27 #include "HYDROGUI_StreamDlg.h"
28 #include "HYDROGUI_Tool.h"
29 #include "HYDROGUI_UpdateFlags.h"
31 #include <HYDROData_Document.h>
32 #include <HYDROData_PolylineXY.h>
33 #include <HYDROData_Profile.h>
35 #include <LightApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
37 #include <LightApp_UpdateFlags.h>
39 #include <OCCViewer_ViewManager.h>
40 #include <OCCViewer_ViewModel.h>
41 #include <OCCViewer_ViewWindow.h>
43 HYDROGUI_StreamOp::HYDROGUI_StreamOp( HYDROGUI_Module* theModule, bool theIsEdit )
44 : HYDROGUI_Operation( theModule ),
45 myIsEdit( theIsEdit ),
46 myViewManager( NULL ),
49 setName( theIsEdit ? tr( "EDIT_STREAM" ) : tr( "CREATE_STREAM" ) );
52 HYDROGUI_StreamOp::~HYDROGUI_StreamOp()
57 void HYDROGUI_StreamOp::startOperation()
59 HYDROGUI_Operation::startOperation();
61 // We start operation in the document
64 HYDROGUI_StreamDlg* aPanel = (HYDROGUI_StreamDlg*)inputPanel();
66 aPanel->blockSignals( true );
71 myEditedObject = Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
73 myEditedObject = Handle(HYDROData_Stream)::DownCast( doc()->CreateObject( KIND_STREAM ) );
75 QString aSelectedAxis;
76 QStringList aSelectedProfiles;
78 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STREAM_NAME" ) );
79 if ( myIsEdit && !myEditedObject.IsNull() )
81 anObjectName = myEditedObject->GetName();
83 Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis();
84 if ( !aHydraulicAxis.IsNull() )
85 aSelectedAxis = aHydraulicAxis->GetName();
87 HYDROData_SequenceOfObjects aProfiles = myEditedObject->GetProfiles();
88 for ( int i = 1, n = aProfiles.Length(); i <= n; ++i )
90 Handle(HYDROData_Profile) aProfile =
91 Handle(HYDROData_Profile)::DownCast( aProfiles.Value( i ) );
92 if ( aProfile.IsNull() )
95 QString aProfileName = aProfile->GetName();
96 aSelectedProfiles << aProfileName;
100 QStringList anAxises = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY );
102 // Temporary, to be removed
103 if ( aSelectedProfiles.isEmpty() )
105 aSelectedProfiles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_PROFILE );
108 aPanel->setObjectName( anObjectName );
109 aPanel->setAxisNames( anAxises );
110 aPanel->setAxisName( aSelectedAxis );
111 aPanel->setSelectedProfiles( aSelectedProfiles );
113 aPanel->blockSignals( false );
118 void HYDROGUI_StreamOp::abortOperation()
123 HYDROGUI_Operation::abortOperation();
126 void HYDROGUI_StreamOp::commitOperation()
130 HYDROGUI_Operation::commitOperation();
133 HYDROGUI_InputPanel* HYDROGUI_StreamOp::createInputPanel() const
135 HYDROGUI_StreamDlg* aPanel = new HYDROGUI_StreamDlg( module(), getName() );
136 connect( aPanel, SIGNAL( CreatePreview() ), this, SLOT( onCreatePreview() ) );
140 bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags,
141 QString& theErrorMsg )
143 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
147 QString anObjectName = aPanel->getObjectName().simplified();
148 if ( anObjectName.isEmpty() )
150 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
154 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
156 // check that there are no other objects with the same name in the document
157 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
158 if( !anObject.IsNull() )
160 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
165 if ( myEditedObject.IsNull() )
168 myEditedObject->SetName( anObjectName );
173 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true );
175 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
180 void HYDROGUI_StreamOp::onCreatePreview()
182 HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
186 QString anAxisName = aPanel->getAxisName();
187 QStringList aProfiles = aPanel->getSelectedProfiles();
188 if ( anAxisName.isEmpty() || aProfiles.isEmpty() )
194 if ( myEditedObject.IsNull() )
197 // At first we remove all references from stream
198 myEditedObject->RemoveProfiles();
200 Handle(HYDROData_PolylineXY) anAxis = Handle(HYDROData_PolylineXY)::DownCast(
201 HYDROGUI_Tool::FindObjectByName( module(), anAxisName, KIND_POLYLINEXY ) );
202 myEditedObject->SetHydraulicAxis( anAxis );
204 HYDROData_SequenceOfObjects aProfileObjects =
205 HYDROGUI_Tool::FindObjectsByNames( module(), aProfiles, KIND_PROFILE );
206 for ( int i = 1, n = aProfileObjects.Length(); i <= n; ++i )
208 Handle(HYDROData_Profile) aProfile =
209 Handle(HYDROData_Profile)::DownCast( aProfileObjects.Value( i ) );
210 if ( aProfile.IsNull() )
213 myEditedObject->AddProfile( aProfile );
216 myEditedObject->Update();
219 LightApp_Application* anApp = module()->getApp();
220 if ( !myViewManager )
221 myViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
222 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
224 if ( myViewManager && !myPreviewPrs )
226 if ( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() )
228 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
229 if ( !aCtx.IsNull() )
230 myPreviewPrs = new HYDROGUI_Shape( aCtx, myEditedObject );
234 if ( !myViewManager || !myPreviewPrs )
237 myPreviewPrs->update();
240 void HYDROGUI_StreamOp::erasePreview()