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_Tool2.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 if ( isApplyAndClose() )
63 myEditedObject = Handle(HYDROData_Obstacle)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
64 if ( myEditedObject.IsNull() ) {
69 // Set the edited object name to the panel
70 aPanel->setName( myEditedObject->GetName() );
76 void HYDROGUI_TranslateObstacleOp::abortOperation()
81 HYDROGUI_Operation::abortOperation();
84 void HYDROGUI_TranslateObstacleOp::commitOperation()
88 HYDROGUI_Operation::commitOperation();
91 HYDROGUI_InputPanel* HYDROGUI_TranslateObstacleOp::createInputPanel() const
93 HYDROGUI_TranslateObstacleDlg* aPanel = new HYDROGUI_TranslateObstacleDlg( module(), getName() );
95 connect( aPanel, SIGNAL( argumentsChanged() ), this, SLOT( onArgumentsChanged() ) );
100 bool HYDROGUI_TranslateObstacleOp::processApply( int& theUpdateFlags,
101 QString& theErrorMsg,
102 QStringList& theBrowseObjectsEntries )
104 HYDROGUI_TranslateObstacleDlg* aPanel = ::qobject_cast<HYDROGUI_TranslateObstacleDlg*>( inputPanel() );
105 if ( !aPanel || myEditedObject.IsNull() ) {
112 // Get the translated shape
113 double aDx = aPanel->getDx();
114 double aDy = aPanel->getDy();
115 double aDz = aPanel->getDz();
117 // Translate the obstacle
118 myEditedObject->Translate( aDx, aDy, aDz );
119 myEditedObject->Update();
121 module()->setIsToUpdate( myEditedObject );
124 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
129 void HYDROGUI_TranslateObstacleOp::createPreview()
131 HYDROGUI_TranslateObstacleDlg* aPanel = (HYDROGUI_TranslateObstacleDlg*)inputPanel();
132 if ( myEditedObject.IsNull() || !aPanel )
135 // Create preview presentation if necessary
136 if ( !myPreviewPrs ) {
137 LightApp_Application* anApp = module()->getApp();
139 if ( !getPreviewManager() )
140 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
141 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
142 OCCViewer_ViewManager* aViewManager = getPreviewManager();
143 if ( aViewManager ) {
144 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
145 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
146 if ( !aCtx.IsNull() ) {
147 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
148 myPreviewPrs->setFillingColor( myEditedObject->GetFillingColor(), false, false );
149 myPreviewPrs->setBorderColor( myEditedObject->GetBorderColor(), false, false );
155 // Set the translated shape to the preview presentation
158 double aDx = aPanel->getDx();
159 double aDy = aPanel->getDy();
160 double aDz = aPanel->getDz();
161 TopoDS_Shape anOriShape = myEditedObject->GetShape3D();
163 TopoDS_Shape aTranslatedShape = HYDROData_ShapesTool::Translated( anOriShape, aDx, aDy, aDz );
164 myPreviewPrs->setShape( aTranslatedShape );
168 void HYDROGUI_TranslateObstacleOp::erasePreview()
176 void HYDROGUI_TranslateObstacleOp::onArgumentsChanged()