From: mzn Date: Thu, 28 May 2015 07:31:03 +0000 (+0300) Subject: refs #524: apply transformation to TopoDS_Shape, not to polyline object X-Git-Tag: v1.4.1~7^2~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4ef5c128e69b04174a72441ed0678ef29d0d183d;p=modules%2Fhydro.git refs #524: apply transformation to TopoDS_Shape, not to polyline object --- diff --git a/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx index 93989458..8dd8cbf6 100644 --- a/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx +++ b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx @@ -23,6 +23,7 @@ #include "HYDROGUI_Shape.h" #include "HYDROGUI_Tool.h" #include "HYDROGUI_UpdateFlags.h" +#include "HYDROGUI_OCCSelector.h" #include #include @@ -47,6 +48,9 @@ #include #include +#include +#include + #include #include @@ -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; }