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_ChannelOp.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_ChannelDlg.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_Shape.h"
29 #include "HYDROGUI_Tool.h"
30 #include "HYDROGUI_UpdateFlags.h"
32 #include <HYDROData_Iterator.h>
33 #include <HYDROData_Polyline3D.h>
34 #include <HYDROData_Profile.h>
36 #include <OCCViewer_ViewManager.h>
37 #include <OCCViewer_ViewModel.h>
39 #include <LightApp_Application.h>
40 #include <LightApp_UpdateFlags.h>
43 HYDROGUI_ChannelOp::HYDROGUI_ChannelOp( HYDROGUI_Module* theModule,
44 const bool theIsEdit )
45 : HYDROGUI_Operation( theModule ),
46 myIsEdit( theIsEdit ),
50 setName( theIsEdit ? tr( "EDIT_CHANNEL" ) : tr( "CREATE_CHANNEL" ) );
53 HYDROGUI_ChannelOp::~HYDROGUI_ChannelOp()
58 void HYDROGUI_ChannelOp::startOperation()
60 HYDROGUI_Operation::startOperation();
62 // We start operation in the document
65 HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
67 aPanel->blockSignals( true );
72 myEditedObject = Handle(HYDROData_Channel)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
74 myEditedObject = Handle(HYDROData_Channel)::DownCast( doc()->CreateObject( KIND_CHANNEL ) );
76 QString aSelectedGuideLine, aSelectedProfile;
78 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CHANNEL_NAME" ) );
79 if ( myIsEdit && !myEditedObject.IsNull() )
81 anObjectName = myEditedObject->GetName();
83 Handle(HYDROData_Polyline3D) aRefGuideLine = myEditedObject->GetGuideLine();
84 if ( !aRefGuideLine.IsNull() )
85 aSelectedGuideLine = aRefGuideLine->GetName();
87 Handle(HYDROData_Profile) aRefProfile = myEditedObject->GetProfile();
88 if ( !aRefProfile.IsNull() )
89 aSelectedProfile = aRefProfile->GetName();
92 // collect information about existing 3d polylines
93 QStringList aGuideLines = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINE );
95 // collect information about existing profiles
96 QStringList aProfiles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_PROFILE );
98 aPanel->setObjectName( anObjectName );
100 aPanel->setGuideLineNames( aGuideLines );
101 aPanel->setProfileNames( aProfiles );
103 aPanel->setGuideLineName( aSelectedGuideLine );
104 aPanel->setProfileName( aSelectedProfile );
106 aPanel->blockSignals( false );
108 onCreatePreview( true );
111 void HYDROGUI_ChannelOp::abortOperation()
116 HYDROGUI_Operation::abortOperation();
119 void HYDROGUI_ChannelOp::commitOperation()
123 HYDROGUI_Operation::commitOperation();
126 HYDROGUI_InputPanel* HYDROGUI_ChannelOp::createInputPanel() const
128 HYDROGUI_ChannelDlg* aPanel = new HYDROGUI_ChannelDlg( module(), getName() );
129 connect( aPanel, SIGNAL( CreatePreview() ), this, SLOT( onCreatePreview() ) );
133 bool HYDROGUI_ChannelOp::processApply( int& theUpdateFlags,
134 QString& theErrorMsg )
136 HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
140 QString anObjectName = aPanel->getObjectName().simplified();
141 if ( anObjectName.isEmpty() )
143 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
147 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
149 // check that there are no other objects with the same name in the document
150 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
151 if( !anObject.IsNull() )
153 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
158 if ( myEditedObject.IsNull() )
161 myEditedObject->SetName( anObjectName );
164 myEditedObject->SetFillingColor( HYDROData_Channel::DefaultFillingColor() );
165 myEditedObject->SetBorderColor( HYDROData_Channel::DefaultBorderColor() );
171 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true );
173 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
178 void HYDROGUI_ChannelOp::onCreatePreview( const bool theIsInit )
180 HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
181 if ( !aPanel || myEditedObject.IsNull() )
184 QString aGuideLineName = aPanel->getGuideLineName();
185 QString aProfileName = aPanel->getProfileName();
186 if ( aGuideLineName.isEmpty() || aProfileName.isEmpty() )
190 myEditedObject->RemoveGuideLine();
191 myEditedObject->RemoveProfile();
192 myEditedObject->Update();
199 // Update channel data
202 Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast(
203 HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) );
204 myEditedObject->SetGuideLine( aGuideLine );
206 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
207 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
208 myEditedObject->SetProfile( aProfile );
210 if ( myEditedObject->IsMustBeUpdated() )
211 myEditedObject->Update();
214 LightApp_Application* anApp = module()->getApp();
215 if ( !myViewManager )
216 myViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
217 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
219 if ( myViewManager && !myPreviewPrs )
221 if ( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() )
223 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
224 if ( !aCtx.IsNull() )
225 myPreviewPrs = new HYDROGUI_Shape( aCtx, myEditedObject );
229 if ( !myViewManager || !myPreviewPrs )
232 myPreviewPrs->update();
235 void HYDROGUI_ChannelOp::erasePreview()