1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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_DataObject.h>
27 #include "HYDROGUI_ChannelDlg.h"
28 #include "HYDROGUI_Module.h"
29 #include "HYDROGUI_Shape.h"
30 #include "HYDROGUI_Tool.h"
31 #include "HYDROGUI_UpdateFlags.h"
33 #include <HYDROData_Iterator.h>
34 #include <HYDROData_Polyline3D.h>
35 #include <HYDROData_Profile.h>
37 #include <OCCViewer_ViewManager.h>
38 #include <OCCViewer_ViewModel.h>
40 #include <LightApp_Application.h>
41 #include <LightApp_UpdateFlags.h>
45 HYDROGUI_ChannelOp::HYDROGUI_ChannelOp( HYDROGUI_Module* theModule,
46 const bool theIsEdit )
47 : HYDROGUI_Operation( theModule ),
48 myIsEdit( theIsEdit ),
51 setName( theIsEdit ? tr( "EDIT_CHANNEL" ) : tr( "CREATE_CHANNEL" ) );
54 HYDROGUI_ChannelOp::~HYDROGUI_ChannelOp()
59 void HYDROGUI_ChannelOp::startOperation()
61 HYDROGUI_Operation::startOperation();
63 HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
65 aPanel->blockSignals( true );
69 myEditedObject.Nullify();
71 QString aSelectedGuideLine, aSelectedProfile;
73 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CHANNEL_NAME" ) );
77 Handle(HYDROData_Channel)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
78 if ( !myEditedObject.IsNull() )
80 anObjectName = myEditedObject->GetName();
82 Handle(HYDROData_Polyline3D) aRefGuideLine = myEditedObject->GetGuideLine();
83 if ( !aRefGuideLine.IsNull() )
84 aSelectedGuideLine = aRefGuideLine->GetName();
86 Handle(HYDROData_Profile) aRefProfile = myEditedObject->GetProfile();
87 if ( !aRefProfile.IsNull() )
88 aSelectedProfile = aRefProfile->GetName();
92 // collect information about existing 3d polylines
93 QStringList aGuideLines;
94 HYDROData_Iterator aPolylinesIt( doc(), KIND_POLYLINE );
95 for ( ; aPolylinesIt.More(); aPolylinesIt.Next() )
97 Handle(HYDROData_Polyline3D) aPolyline3d =
98 Handle(HYDROData_Polyline3D)::DownCast( aPolylinesIt.Current() );
99 if( !aPolyline3d.IsNull() )
101 TopoDS_Shape aShape = aPolyline3d->GetShape3D();
102 if( aShape.ShapeType()==TopAbs_WIRE )
104 TopoDS_Wire aWire = TopoDS::Wire( aShape );
105 if( !aWire.Closed() )
106 aGuideLines.append( aPolyline3d->GetName() );
111 // collect information about existing profiles
112 QStringList aProfiles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_PROFILE, true );
114 aPanel->setObjectName( anObjectName );
116 aPanel->setGuideLineNames( aGuideLines );
117 aPanel->setProfileNames( aProfiles );
119 aPanel->setGuideLineName( aSelectedGuideLine );
120 aPanel->setProfileName( aSelectedProfile );
122 aPanel->blockSignals( false );
127 void HYDROGUI_ChannelOp::abortOperation()
130 HYDROGUI_Operation::abortOperation();
133 void HYDROGUI_ChannelOp::commitOperation()
136 HYDROGUI_Operation::commitOperation();
139 HYDROGUI_InputPanel* HYDROGUI_ChannelOp::createInputPanel() const
141 HYDROGUI_ChannelDlg* aPanel = new HYDROGUI_ChannelDlg( module(), getName() );
142 connect( aPanel, SIGNAL( CreatePreview() ), this, SLOT( onCreatePreview() ) );
146 bool HYDROGUI_ChannelOp::processApply( int& theUpdateFlags,
147 QString& theErrorMsg,
148 QStringList& theBrowseObjectsEntries )
150 HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
154 QString anObjectName = aPanel->getObjectName().simplified();
155 if ( anObjectName.isEmpty() )
157 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
161 if ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
163 // check that there are no other objects with the same name in the document
164 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
165 if( !anObject.IsNull() )
167 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
173 if ( myEditedObject.IsNull() )
174 myEditedObject = createNewObject(); // Create new data model object
176 myEditedObject->SetName( anObjectName );
180 myEditedObject->SetFillingColor( getDefaultFillingColor() );
181 myEditedObject->SetBorderColor( getDefaultBorderColor() );
184 QString aGuideLineName = aPanel->getGuideLineName();
185 QString aProfileName = aPanel->getProfileName();
186 if ( aGuideLineName.isEmpty() || aProfileName.isEmpty() )
188 myEditedObject->RemoveGuideLine();
189 myEditedObject->RemoveProfile();
193 Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast(
194 HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) );
195 myEditedObject->SetGuideLine( aGuideLine );
197 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
198 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
199 myEditedObject->SetProfile( aProfile );
202 if ( myEditedObject->IsMustBeUpdated() )
203 myEditedObject->Update();
209 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true );
210 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
211 theBrowseObjectsEntries.append( anEntry );
214 module()->setIsToUpdate( myEditedObject );
216 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
221 Handle(HYDROData_Channel) HYDROGUI_ChannelOp::createNewObject() const
223 return Handle(HYDROData_Channel)::DownCast( doc()->CreateObject( KIND_CHANNEL ) );
226 QColor HYDROGUI_ChannelOp::getDefaultFillingColor() const
228 return HYDROData_Channel::DefaultFillingColor();
231 QColor HYDROGUI_ChannelOp::getDefaultBorderColor() const
233 return HYDROData_Channel::DefaultBorderColor();
236 void HYDROGUI_ChannelOp::onCreatePreview()
238 HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
242 QString aGuideLineName = aPanel->getGuideLineName();
243 QString aProfileName = aPanel->getProfileName();
244 if ( aGuideLineName.isEmpty() || aProfileName.isEmpty() )
250 LightApp_Application* anApp = module()->getApp();
252 if ( !getPreviewManager() )
254 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
255 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
258 OCCViewer_ViewManager* aViewManager = getPreviewManager();
259 if ( aViewManager && !myPreviewPrs )
261 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
263 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
264 if ( !aCtx.IsNull() )
266 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
268 QColor aFillingColor = getDefaultFillingColor();
269 QColor aBorderColor = getDefaultBorderColor();
270 if ( !myEditedObject.IsNull() )
272 aFillingColor = myEditedObject->GetFillingColor();
273 aBorderColor = myEditedObject->GetBorderColor();
276 myPreviewPrs->setFillingColor( aFillingColor, false, false );
277 myPreviewPrs->setBorderColor( aBorderColor, false, false );
282 if ( !aViewManager || !myPreviewPrs )
285 Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast(
286 HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) );
288 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
289 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
291 HYDROData_Channel::PrsDefinition aPrsDef;
292 if ( !HYDROData_Channel::CreatePresentations( aGuideLine, aProfile, aPrsDef ) )
298 myPreviewPrs->setShape( aPrsDef.myPrs2D );
301 void HYDROGUI_ChannelOp::erasePreview()