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_TranslateObstacleOp.h"
25 #include "HYDROGUI_TranslateObstacleDlg.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_Shape.h"
28 #include "HYDROGUI_Tool.h"
29 #include "HYDROGUI_UpdateFlags.h"
31 #include <HYDROData_ShapesTool.h>
33 #include <LightApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
35 #include <LightApp_UpdateFlags.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_Desktop.h>
40 #include <OCCViewer_ViewManager.h>
41 #include <OCCViewer_ViewModel.h>
42 #include <OCCViewer_ViewWindow.h>
45 HYDROGUI_TranslateObstacleOp::HYDROGUI_TranslateObstacleOp( HYDROGUI_Module* theModule )
46 : HYDROGUI_Operation( theModule ),
49 setName( tr( "TRANSLATE_OBSTACLE" ) );
52 HYDROGUI_TranslateObstacleOp::~HYDROGUI_TranslateObstacleOp()
57 void HYDROGUI_TranslateObstacleOp::startOperation()
59 HYDROGUI_Operation::startOperation();
61 // Get panel and reset its state
62 HYDROGUI_TranslateObstacleDlg* aPanel = (HYDROGUI_TranslateObstacleDlg*)inputPanel();
65 // Get the edited object
66 myEditedObject = Handle(HYDROData_Obstacle)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
67 if ( myEditedObject.IsNull() ) {
71 else if ( myEditedObject->IsMustBeUpdated() ) {
72 myEditedObject->Update();
75 // Set the edited object name to the panel
76 aPanel->setName( myEditedObject->GetName() );
82 void HYDROGUI_TranslateObstacleOp::abortOperation()
87 HYDROGUI_Operation::abortOperation();
90 void HYDROGUI_TranslateObstacleOp::commitOperation()
94 HYDROGUI_Operation::commitOperation();
97 HYDROGUI_InputPanel* HYDROGUI_TranslateObstacleOp::createInputPanel() const
99 HYDROGUI_TranslateObstacleDlg* aPanel = new HYDROGUI_TranslateObstacleDlg( module(), getName() );
101 connect( aPanel, SIGNAL( argumentsChanged() ), this, SLOT( onArgumentsChanged() ) );
106 bool HYDROGUI_TranslateObstacleOp::processApply( int& theUpdateFlags,
107 QString& theErrorMsg )
109 HYDROGUI_TranslateObstacleDlg* aPanel = ::qobject_cast<HYDROGUI_TranslateObstacleDlg*>( inputPanel() );
110 if ( !aPanel || myEditedObject.IsNull() ) {
117 // Get the translated shape
118 double aDx = aPanel->getDx();
119 double aDy = aPanel->getDy();
120 double aDz = aPanel->getDz();
122 // Translate the obstacle
123 myEditedObject->Translate( aDx, aDy, aDz );
124 myEditedObject->Update();
126 module()->setIsToUpdate( myEditedObject );
129 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
134 void HYDROGUI_TranslateObstacleOp::createPreview()
136 HYDROGUI_TranslateObstacleDlg* aPanel = (HYDROGUI_TranslateObstacleDlg*)inputPanel();
137 if ( myEditedObject.IsNull() || !aPanel )
140 // Create preview presentation if necessary
141 if ( !myPreviewPrs ) {
142 LightApp_Application* anApp = module()->getApp();
144 if ( !getPreviewManager() )
145 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
146 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
147 OCCViewer_ViewManager* aViewManager = getPreviewManager();
148 if ( aViewManager ) {
149 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
150 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
151 if ( !aCtx.IsNull() ) {
152 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
153 myPreviewPrs->setFillingColor( myEditedObject->GetFillingColor(), false, false );
154 myPreviewPrs->setBorderColor( myEditedObject->GetBorderColor(), false, false );
160 // Set the translated shape to the preview presentation
163 double aDx = aPanel->getDx();
164 double aDy = aPanel->getDy();
165 double aDz = aPanel->getDz();
166 TopoDS_Shape anOriShape = myEditedObject->GetShape3D();
168 TopoDS_Shape aTranslatedShape = HYDROData_ShapesTool::Translated( anOriShape, aDx, aDy, aDz );
169 myPreviewPrs->setShape( aTranslatedShape );
173 void HYDROGUI_TranslateObstacleOp::erasePreview()
181 void HYDROGUI_TranslateObstacleOp::onArgumentsChanged()
187 TopoDS_Shape HYDROGUI_TranslateObstacleOp::getTranslatedShape() const
189 TopoDS_Shape aTranslatedShape;
191 HYDROGUI_TranslateObstacleDlg* aPanel = (HYDROGUI_TranslateObstacleDlg*)inputPanel();
192 if ( aPanel && !myEditedObject.IsNull() ) {
193 double aDx = aPanel->getDx();
194 double aDy = aPanel->getDy();
195 double aDz = aPanel->getDz();
197 TopoDS_Shape aShape = myEditedObject->GetShape3D();
199 gp_Vec aVec( aDx, aDy, aDz );
200 aTrsf.SetTranslation(aVec);
201 TopLoc_Location aLocOrig = aShape.Location();
202 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
203 TopLoc_Location aLocRes( aTrsf * aTrsfOrig );
204 aTranslatedShape = aShape.Located( aLocRes );
207 return aTranslatedShape;