Salome HOME
refs #568: use ordered list view with selection synchronized with object browser...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_TranslateObstacleOp.cxx
index c677191061fc7962774eb52b7a77f51385d88828..11104c0b00f5c19e18dfa7771336e836c674b700 100644 (file)
@@ -1,12 +1,8 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -28,6 +24,8 @@
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_UpdateFlags.h"
 
+#include <HYDROData_ShapesTool.h>
+
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 #include <LightApp_UpdateFlags.h>
@@ -61,14 +59,12 @@ void HYDROGUI_TranslateObstacleOp::startOperation()
   aPanel->reset();
 
   // Get the edited object
-  myEditedObject = Handle(HYDROData_Obstacle)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+  if ( isApplyAndClose() )
+    myEditedObject = Handle(HYDROData_Obstacle)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
   if ( myEditedObject.IsNull() ) {
     abort();
     return;
   }
-  else if ( myEditedObject->IsMustBeUpdated() ) {
-    myEditedObject->Update();
-  }
 
   // Set the edited object name to the panel
   aPanel->setName( myEditedObject->GetName() );
@@ -102,24 +98,24 @@ HYDROGUI_InputPanel* HYDROGUI_TranslateObstacleOp::createInputPanel() const
 }
 
 bool HYDROGUI_TranslateObstacleOp::processApply( int& theUpdateFlags,
-                                                 QString& theErrorMsg )
+                                                 QString& theErrorMsg,
+                                                 QStringList& theBrowseObjectsEntries )
 {
   HYDROGUI_TranslateObstacleDlg* aPanel = ::qobject_cast<HYDROGUI_TranslateObstacleDlg*>( inputPanel() );
   if ( !aPanel || myEditedObject.IsNull() ) {
     return false;
   }
 
-  // Get the translated shape
-  TopoDS_Shape aTranslatedShape = getTranslatedShape();
-  if ( aTranslatedShape.IsNull() ) {
-    return false;
-  }
-
   // Erase preview
   erasePreview();
 
-  // Set the translated shape to the obstacle
-  myEditedObject->SetShape3D( aTranslatedShape ); 
+  // Get the translated shape
+  double aDx = aPanel->getDx();
+  double aDy = aPanel->getDy();
+  double aDz = aPanel->getDz();
+
+  // Translate the obstacle
+  myEditedObject->Translate( aDx, aDy, aDz );
   myEditedObject->Update();
 
   module()->setIsToUpdate( myEditedObject );
@@ -132,21 +128,23 @@ bool HYDROGUI_TranslateObstacleOp::processApply( int& theUpdateFlags,
 
 void HYDROGUI_TranslateObstacleOp::createPreview()
 {
-  if ( myEditedObject.IsNull() ) {
+  HYDROGUI_TranslateObstacleDlg* aPanel = (HYDROGUI_TranslateObstacleDlg*)inputPanel();
+  if ( myEditedObject.IsNull() || !aPanel )
     return;
-  }
 
   // Create preview presentation if necessary
   if ( !myPreviewPrs ) {
     LightApp_Application* anApp = module()->getApp();
-    OCCViewer_ViewManager* aViewManager = ::qobject_cast<OCCViewer_ViewManager*>( 
-      anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
-  
+
+    if ( !getPreviewManager() )
+      setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>( 
+                         anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
+    OCCViewer_ViewManager* aViewManager = getPreviewManager();
     if ( aViewManager ) {
       if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
         Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
         if ( !aCtx.IsNull() ) {
-          myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL );
+          myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
           myPreviewPrs->setFillingColor( myEditedObject->GetFillingColor(), false, false );
           myPreviewPrs->setBorderColor( myEditedObject->GetBorderColor(), false, false );
         }
@@ -154,11 +152,15 @@ void HYDROGUI_TranslateObstacleOp::createPreview()
     }
   }
   
-  // Get the translated shape
-  TopoDS_Shape aTranslatedShape = getTranslatedShape();
-
   // Set the translated shape to the preview presentation
-  if ( myPreviewPrs ) {
+  if ( myPreviewPrs )
+  {
+    double aDx = aPanel->getDx();
+    double aDy = aPanel->getDy();
+    double aDz = aPanel->getDz();
+    TopoDS_Shape anOriShape = myEditedObject->GetShape3D();
+
+    TopoDS_Shape aTranslatedShape = HYDROData_ShapesTool::Translated( anOriShape, aDx, aDy, aDz );
     myPreviewPrs->setShape( aTranslatedShape );
   }
 }
@@ -177,25 +179,3 @@ void HYDROGUI_TranslateObstacleOp::onArgumentsChanged()
   createPreview();
 }
 
-TopoDS_Shape HYDROGUI_TranslateObstacleOp::getTranslatedShape() const
-{
-  TopoDS_Shape aTranslatedShape;
-
-  HYDROGUI_TranslateObstacleDlg* aPanel = (HYDROGUI_TranslateObstacleDlg*)inputPanel();
-  if ( aPanel && !myEditedObject.IsNull() ) {
-    double aDx = aPanel->getDx();
-    double aDy = aPanel->getDy();
-    double aDz = aPanel->getDz();
-
-    TopoDS_Shape aShape = myEditedObject->GetShape3D();
-    gp_Trsf aTrsf;
-    gp_Vec aVec( aDx, aDy, aDz );
-    aTrsf.SetTranslation(aVec);
-    TopLoc_Location aLocOrig = aShape.Location();
-    gp_Trsf aTrsfOrig = aLocOrig.Transformation();
-    TopLoc_Location aLocRes( aTrsf * aTrsfOrig );
-    aTranslatedShape = aShape.Located( aLocRes );
-  }
-
-  return aTranslatedShape;
-}
\ No newline at end of file