1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_TranslateObstacleOp.h"
21 #include "HYDROGUI_TranslateObstacleDlg.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_Shape.h"
24 #include "HYDROGUI_Tool.h"
25 #include "HYDROGUI_UpdateFlags.h"
27 #include <HYDROData_ShapesTool.h>
29 #include <LightApp_Application.h>
30 #include <LightApp_SelectionMgr.h>
31 #include <LightApp_UpdateFlags.h>
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_Desktop.h>
36 #include <OCCViewer_ViewManager.h>
37 #include <OCCViewer_ViewModel.h>
38 #include <OCCViewer_ViewWindow.h>
41 HYDROGUI_TranslateObstacleOp::HYDROGUI_TranslateObstacleOp( HYDROGUI_Module* theModule )
42 : HYDROGUI_Operation( theModule ),
45 setName( tr( "TRANSLATE_OBSTACLE" ) );
48 HYDROGUI_TranslateObstacleOp::~HYDROGUI_TranslateObstacleOp()
53 void HYDROGUI_TranslateObstacleOp::startOperation()
55 HYDROGUI_Operation::startOperation();
57 // Get panel and reset its state
58 HYDROGUI_TranslateObstacleDlg* aPanel = (HYDROGUI_TranslateObstacleDlg*)inputPanel();
61 // Get the edited object
62 myEditedObject = Handle(HYDROData_Obstacle)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
63 if ( myEditedObject.IsNull() ) {
68 // Set the edited object name to the panel
69 aPanel->setName( myEditedObject->GetName() );
75 void HYDROGUI_TranslateObstacleOp::abortOperation()
80 HYDROGUI_Operation::abortOperation();
83 void HYDROGUI_TranslateObstacleOp::commitOperation()
87 HYDROGUI_Operation::commitOperation();
90 HYDROGUI_InputPanel* HYDROGUI_TranslateObstacleOp::createInputPanel() const
92 HYDROGUI_TranslateObstacleDlg* aPanel = new HYDROGUI_TranslateObstacleDlg( module(), getName() );
94 connect( aPanel, SIGNAL( argumentsChanged() ), this, SLOT( onArgumentsChanged() ) );
99 bool HYDROGUI_TranslateObstacleOp::processApply( int& theUpdateFlags,
100 QString& theErrorMsg,
101 QStringList& theBrowseObjectsEntries )
103 HYDROGUI_TranslateObstacleDlg* aPanel = ::qobject_cast<HYDROGUI_TranslateObstacleDlg*>( inputPanel() );
104 if ( !aPanel || myEditedObject.IsNull() ) {
111 // Get the translated shape
112 double aDx = aPanel->getDx();
113 double aDy = aPanel->getDy();
114 double aDz = aPanel->getDz();
116 // Translate the obstacle
117 myEditedObject->Translate( aDx, aDy, aDz );
118 myEditedObject->Update();
120 module()->setIsToUpdate( myEditedObject );
123 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
128 void HYDROGUI_TranslateObstacleOp::createPreview()
130 HYDROGUI_TranslateObstacleDlg* aPanel = (HYDROGUI_TranslateObstacleDlg*)inputPanel();
131 if ( myEditedObject.IsNull() || !aPanel )
134 // Create preview presentation if necessary
135 if ( !myPreviewPrs ) {
136 LightApp_Application* anApp = module()->getApp();
138 if ( !getPreviewManager() )
139 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
140 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
141 OCCViewer_ViewManager* aViewManager = getPreviewManager();
142 if ( aViewManager ) {
143 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
144 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
145 if ( !aCtx.IsNull() ) {
146 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
147 myPreviewPrs->setFillingColor( myEditedObject->GetFillingColor(), false, false );
148 myPreviewPrs->setBorderColor( myEditedObject->GetBorderColor(), false, false );
154 // Set the translated shape to the preview presentation
157 double aDx = aPanel->getDx();
158 double aDy = aPanel->getDy();
159 double aDz = aPanel->getDz();
160 TopoDS_Shape anOriShape = myEditedObject->GetShape3D();
162 TopoDS_Shape aTranslatedShape = HYDROData_ShapesTool::Translated( anOriShape, aDx, aDy, aDz );
163 myPreviewPrs->setShape( aTranslatedShape );
167 void HYDROGUI_TranslateObstacleOp::erasePreview()
175 void HYDROGUI_TranslateObstacleOp::onArgumentsChanged()