]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Translation of obstacle (Bug #341).
authoradv <adv@opencascade.com>
Thu, 23 Jan 2014 09:57:19 +0000 (09:57 +0000)
committeradv <adv@opencascade.com>
Thu, 23 Jan 2014 09:57:19 +0000 (09:57 +0000)
src/HYDROData/HYDROData_Obstacle.cxx
src/HYDROData/HYDROData_Obstacle.h
src/HYDROData/HYDROData_ShapesTool.cxx
src/HYDROData/HYDROData_ShapesTool.h
src/HYDROGUI/HYDROGUI_TranslateObstacleOp.cxx
src/HYDROPy/HYDROData_Obstacle.sip

index 560d91e154eaebacd8f93509328c9c1cf8080521..bde8f4fceef74eb78226e47e30e7035b7a4553b0 100644 (file)
@@ -26,6 +26,7 @@
 #include <TopoDS_Edge.hxx>
 
 #include <TDataStd_AsciiString.hxx>
+#include <TDataStd_RealArray.hxx>
 
 #include <TColStd_SequenceOfAsciiString.hxx>
 
@@ -73,14 +74,23 @@ QStringList HYDROData_Obstacle::DumpToPython( MapOfTreatedObjects& theTreatedObj
 
     aResList << QString( "%1.SetGeomObjectEntry( \"%2\" );" )
                 .arg( anObstacleName ).arg( aGeomObjectEntry.ToCString() );
+    aResList << QString( "" );
   }
   else if ( !aFilePath.isEmpty() )
   {
     aResList << QString( "%1.ImportFromFile( \"%2\" );" )
                 .arg( anObstacleName ).arg( aFilePath );
+    aResList << QString( "" );
   }
 
-  aResList << QString( "" );
+  // Write the translation points
+  double aDx, aDy, aDz;
+  if ( getTranslation( aDx, aDy, aDz ) )
+  {
+    aResList << QString( "%1.Translate( %2, %3, %4 );" )
+                .arg( anObstacleName ).arg( aDx ).arg( aDy ).arg( aDz );
+    aResList << QString( "" );
+  }
 
   aResList << QString( "%1.Update();" ).arg( anObstacleName );
   aResList << QString( "" );
@@ -212,6 +222,21 @@ TCollection_AsciiString HYDROData_Obstacle::GetGeomObjectEntry() const
   return aRes;
 }
 
+void HYDROData_Obstacle::Translate( const double theDx,
+                                    const double theDy,
+                                    const double theDz )
+{
+  TopoDS_Shape aShape3D = GetShape3D();
+  
+  TopoDS_Shape aTranslatedShape3D = HYDROData_ShapesTool::Translated( aShape3D, theDx, theDy, theDz );
+  if ( aTranslatedShape3D.IsNull() )
+    return;
+
+  SetShape3D( aTranslatedShape3D );
+
+  setTranslation( theDx, theDy, theDz );
+}
+
 TopoDS_Shape HYDROData_Obstacle::ImportBREP( const QString& theFilePath ) const
 {
   TopoDS_Shape aResShape;
@@ -385,6 +410,11 @@ QColor HYDROData_Obstacle::getDefaultBorderColor() const
   return DefaultBorderColor();
 }
 
+ObjectKind HYDROData_Obstacle::getAltitudeObjectType() const
+{
+  return KIND_OBSTACLE_ALTITUDE;
+}
+
 void HYDROData_Obstacle::createGroupObjects()
 {
   TopoDS_Shape anObstacleShape = GetTopShape();
@@ -404,10 +434,46 @@ void HYDROData_Obstacle::createGroupObjects()
   }
 }
 
-ObjectKind HYDROData_Obstacle::getAltitudeObjectType() const
+void HYDROData_Obstacle::setTranslation( const double theDx, 
+                                         const double theDy, 
+                                         const double theDz )
 {
-  return KIND_OBSTACLE_ALTITUDE;
+  TDF_Label aLabel = myLab.FindChild( DataTag_Translation );
+
+  double aCurDx = theDx;
+  double aCurDy = theDy;
+  double aCurDz = theDz;
+
+  double aPrevDx, aPrevDy, aPrevDz;
+  if ( getTranslation( aPrevDx, aPrevDy, aPrevDz ) )
+  {
+    aCurDx += aPrevDx;
+    aCurDy += aPrevDy;
+    aCurDz += aPrevDz;
+  }
+  
+  Handle(TDataStd_RealArray) aCoeffsArray = TDataStd_RealArray::Set( aLabel, 1, 3 );
+  aCoeffsArray->SetValue( 1, aCurDx );
+  aCoeffsArray->SetValue( 2, aCurDy );
+  aCoeffsArray->SetValue( 3, aCurDz );
 }
 
+bool HYDROData_Obstacle::getTranslation( double& theDx, double& theDy, double& theDz ) const
+{
+  theDx = theDy = theDz = 0.0;
+
+  TDF_Label aLabel = myLab.FindChild( DataTag_Translation, false );
+  if ( aLabel.IsNull() )
+    return false;
+
+  Handle(TDataStd_RealArray) aCoeffsArray;
+  if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aCoeffsArray ) )
+    return false;
 
+  theDx = aCoeffsArray->Value( 1 );
+  theDy = aCoeffsArray->Value( 2 );
+  theDz = aCoeffsArray->Value( 3 );
+
+  return true;
+}
 
index 2e38854bed6dd5af379b38b7b09ec3d2a4381576..ccf1599d2605d1c8dd912b882462efe052bc313a 100644 (file)
@@ -20,7 +20,8 @@ protected:
   {
     DataTag_First = HYDROData_ArtificialObject::DataTag_First + 100, ///< first tag, to reserve
     DataTag_GeomObjectEntry, ///< study entry of the imported GEOM object
-    DataTag_FilePath ///< imported file path
+    DataTag_FilePath,        ///< imported file path
+    DataTag_Translation,     ///< translation coefficients
   };
 
 public:
@@ -113,6 +114,14 @@ public:
    */
   HYDRODATA_EXPORT TCollection_AsciiString GetGeomObjectEntry() const;
 
+
+  /**
+   * Translate the obstacle to the given distance.
+   */
+  HYDRODATA_EXPORT void Translate( const double theDx,
+                                   const double theDy,
+                                   const double theDz );
+
 protected:
 
   /**
@@ -133,27 +142,6 @@ protected:
 
 private:
 
-  /**
-   * Create all necessary child group objects.
-   */
-  HYDRODATA_EXPORT void createGroupObjects();
-
-protected:
-
-  friend class HYDROData_Iterator;
-
-  /**
-   * Creates new object in the internal data structure. Use higher level objects 
-   * to create objects with real content.
-   */
-  HYDRODATA_EXPORT HYDROData_Obstacle();
-
-  /**
-   * Destructs properties of the object and object itself, removes it from the document.
-   */
-  virtual HYDRODATA_EXPORT ~HYDROData_Obstacle();
-
-private:
   /**
    * Imports shape from the BREP file.
    * \param theFilePath the path to file
@@ -174,6 +162,37 @@ private:
    * \return shape as TopoDS_Shape (null shape if import was failed)
    */
   TopoDS_Shape ImportSTEP( const QString& theFilePath ) const;
+
+  /**
+   * Create all necessary child group objects.
+   */
+  void createGroupObjects();
+
+  /**
+   * Sets the translation coefficients.
+   */
+  void setTranslation( const double theDx, const double theDy, const double theDz );
+
+  /**
+   * Returns the translation coefficients.
+   */
+  bool getTranslation( double& theDx, double& theDy, double& theDz ) const;
+
+protected:
+
+  friend class HYDROData_Iterator;
+
+  /**
+   * Creates new object in the internal data structure. Use higher level objects 
+   * to create objects with real content.
+   */
+  HYDRODATA_EXPORT HYDROData_Obstacle();
+
+  /**
+   * Destructs properties of the object and object itself, removes it from the document.
+   */
+  virtual HYDRODATA_EXPORT ~HYDROData_Obstacle();
+
 };
 
 #endif
index d591c3a6a610d1f8702b20551dcb139ab940bd0c..d11b369168ddfac2bb90a472f71886eef06a5c13 100644 (file)
@@ -81,6 +81,29 @@ bool HYDROData_ShapesTool::IsVerticesEquals( const TopoDS_Vertex& theFirstVert,
   return aFirstPoint.IsEqual( aSecondPoint, Precision::Confusion() );
 }
 
+TopoDS_Shape HYDROData_ShapesTool::Translated( const TopoDS_Shape& theShape,
+                                               const double        theDx,
+                                               const double        theDy,
+                                               const double        theDz )
+{
+  TopoDS_Shape aTranslatedShape;
+  if ( theShape.IsNull() )
+    return aTranslatedShape;
+
+  gp_Vec aVec( theDx, theDy, theDz );
+
+  gp_Trsf aTrsf;
+  aTrsf.SetTranslation( aVec );
+
+  TopLoc_Location aLocOrig = theShape.Location();
+  gp_Trsf aTrsfOrig = aLocOrig.Transformation();
+
+  TopLoc_Location aLocRes( aTrsf * aTrsfOrig );
+  aTranslatedShape = theShape.Located( aLocRes );
+
+  return aTranslatedShape;
+}
+
 bool HYDROData_ShapesTool::IsEdgesEquals( const TopoDS_Edge& theFirstEdge,
                                           const TopoDS_Edge& theSecondEdge,
                                           const bool         theIs2D )
index 886b5808e029f90fc79bae6998aabb234e348d96..db50bb204f75979d22c1207566513f6ce69c7d77 100644 (file)
@@ -60,6 +60,19 @@ public:
                                                        const TopoDS_Edge& theSecondEdge,
                                                        const bool         theIs2D = false );
 
+  /**
+   * \brief Translate the shape to the given distance.
+   * \param theShape shape to translate
+   * \param theDx X vector component
+   * \param theDy Y vector component
+   * \param theDz Z vector component
+   * \return result translated shape
+   */
+  static TopoDS_Shape                   Translated( const TopoDS_Shape& theShape,
+                                                    const double        theDx,
+                                                    const double        theDy,
+                                                    const double        theDz );
+
   /**
    * \brief Adds the sequence of shapes to other sequence.
    * \param theShapes sequence to which the shapes will be added
index c677191061fc7962774eb52b7a77f51385d88828..952fe9fbdd908b91618c97751ae2687800e335b9 100644 (file)
@@ -28,6 +28,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>
@@ -109,17 +111,16 @@ bool HYDROGUI_TranslateObstacleOp::processApply( int& theUpdateFlags,
     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,9 +133,9 @@ 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 ) {
@@ -154,11 +155,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 );
   }
 }
index 14cce6d646566ea75a327179a812d8076592ea7e..f9eb1cf1d81b9868024893110a79c0cc22c6943c 100644 (file)
@@ -90,6 +90,14 @@ public:
   TCollection_AsciiString GetGeomObjectEntry() const;
 
 
+public:
+
+  /**
+   * Translate the obstacle to the given distance.
+   */
+  void Translate( const double theDx, const double theDy, const double theDz );
+
+
 protected:
 
   /**