]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #524: apply transformation to TopoDS_Shape, not to polyline object
authormzn <mzn@opencascade.com>
Thu, 28 May 2015 07:31:03 +0000 (10:31 +0300)
committermzn <mzn@opencascade.com>
Thu, 28 May 2015 07:31:03 +0000 (10:31 +0300)
src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx

index 9398945850893f66204f39d113af86b80f0ffdc5..8dd8cbf602608a1fe5b81457e5482de11b720507 100644 (file)
@@ -23,6 +23,7 @@
 #include "HYDROGUI_Shape.h"
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_UpdateFlags.h"
+#include "HYDROGUI_OCCSelector.h"
 
 #include <HYDROData_Document.h>
 #include <HYDROData_GeomTool.h>
@@ -47,6 +48,9 @@
 #include <SUIT_Desktop.h>
 #include <SUIT_ViewManager.h>
 
+#include <BRepBuilderAPI_GTransform.hxx>
+#include <gp_GTrsf.hxx>
+
 #include <QDialog>
 #include <QTemporaryFile>
 
@@ -218,7 +222,6 @@ bool HYDROGUI_RecognizeContoursOp::processApply( int& theUpdateFlags,
       aPolylineObj->SetName( aName );
       aPolylineObj->ImportShape( aShape );
       aPolylineObj->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
-      aPolylineObj->Transform( myImage->Trsf() );
 
       aPolylineObj->Update();
       module()->setIsToUpdate( aPolylineObj );
@@ -338,15 +341,35 @@ void HYDROGUI_RecognizeContoursOp::updateRecognizedPolylines()
     OCCViewer_ViewManager* aViewManager = getPreviewManager();
     if ( aViewManager ) {
       if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
+        // aViewer->enablePreselection( true );
+        // aViewer->enableSelection( true );
         aCtx = aViewer->getAISContext();
         connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
       }
     }
 
+    QTransform aTrsf = myImage->Trsf();
+    gp_Mat aMat( aTrsf.m11(), aTrsf.m21(), 0, 
+                 aTrsf.m12(), -aTrsf.m22(), 0, 
+                 0,           0,           1 );
+    QImage anImage = myImage->Image();
+    QRectF aRect( QPointF( 0, 0 ), QPointF( anImage.width(), anImage.height() ) );
+    aRect = aTrsf.mapRect( aRect );
+    gp_XYZ aVec( aTrsf.m31() + aRect.width() * 0.5, 
+                 aTrsf.m32() - aRect.height() * 0.5, 0 );
+
+    BRepBuilderAPI_GTransform aBuilder( gp_GTrsf( aMat, aVec ) );
+
     QStringList aNamesList;
     for ( int i = 1; i <= aSubShapes.Length(); i++ ) {
-      const TopoDS_Shape& aSubShape = aSubShapes.Value( i );
+      TopoDS_Shape aSubShape = aSubShapes.Value( i );
 
+      // Transform the sub-shape
+      aBuilder.Perform( aSubShape, Standard_True );
+      if ( aBuilder.IsDone() ) {
+        aSubShape = aBuilder.Shape();
+      }
+      
       HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
       aShape->setShape( aSubShape, true, false );
       aShape->setBorderColor( HYDROData_PolylineXY::DefaultWireColor(), false, false );
@@ -387,9 +410,28 @@ void HYDROGUI_RecognizeContoursOp::erasePreview()
 */
 void HYDROGUI_RecognizeContoursOp::onSelectionChanged( const QStringList& theSelectedNames )
 {
-  foreach ( QString aName, myPolylineShapes.keys() ) {
-    bool isSelected = theSelectedNames.contains( aName );
-    myPolylineShapes[aName]->highlight( isSelected, true );
+  Handle(AIS_InteractiveContext) aCtx = NULL;
+
+  OCCViewer_ViewManager* aViewManager = getPreviewManager();
+  if ( aViewManager ) {
+    if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
+      aCtx = aViewer->getAISContext();
+    }
+  }
+
+  if ( !aCtx.IsNull() ) {
+    foreach ( QString aName, myPolylineShapes.keys() ) {
+      Handle(AIS_InteractiveObject) anObject = 
+        myPolylineShapes.value(aName)->getAISObject();
+
+      bool isSelected = theSelectedNames.contains( aName );
+      if ( ( isSelected && !aCtx->IsSelected( anObject) ) ||
+           ( !isSelected && aCtx->IsSelected( anObject) ) ) {
+        aCtx->AddOrRemoveSelected( anObject, Standard_False );
+      }
+      // myPolylineShapes[aName]->highlight( isSelected, true );
+    }
+    aCtx->UpdateCurrentViewer();
   }
 }
 
@@ -418,7 +460,7 @@ void HYDROGUI_RecognizeContoursOp::onViewerSelectionChanged()
     QStringList aSelectedNames;
 
     foreach ( QString aName, myPolylineShapes.keys() ) {
-      bool isSelected = aCtx->IsSelected( myPolylineShapes[aName]->getAISObject() );
+      bool isSelected = aCtx->IsSelected( myPolylineShapes.value(aName)->getAISObject() );
       if ( isSelected ) {
         aSelectedNames << aName;
       }