X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_RecognizeContoursOp.cxx;h=2bee9b76568d36e848f24979752ee160d8290baf;hb=7bc13643f345b813472c30c65307ea78c12df428;hp=bc912b8a30520bdb893bafef5b393a00f2196cdc;hpb=ed7a9d24abef6457c7eb94db703c57b0406df3d6;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx index bc912b8a..2bee9b76 100644 --- a/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx +++ b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx @@ -23,6 +23,8 @@ #include "HYDROGUI_Shape.h" #include "HYDROGUI_Tool.h" #include "HYDROGUI_UpdateFlags.h" +#include "HYDROGUI_OCCSelector.h" +#include "HYDROGUI_ZLayers.h" #include #include @@ -47,6 +49,9 @@ #include #include +#include +#include + #include #include @@ -74,16 +79,27 @@ void HYDROGUI_RecognizeContoursOp::startOperation() { HYDROGUI_Operation::startOperation(); + // Set preview view manager + if ( !getPreviewManager() ) { + setPreviewManager( ::qobject_cast( + module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) ) ); + } + + if ( !isApplyAndClose() ) { + return; + } + // Get the selected image myImage = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); if ( myImage.IsNull() ) { abort(); return; } + QString anImageName = myImage->GetName(); // Create temporary graphics file QImage aQImage = myImage->Image(); - myTmpImageFile = new QTemporaryFile( myImage->GetName() ); + myTmpImageFile = new QTemporaryFile( anImageName ); if ( !myTmpImageFile->open() || !aQImage.save( myTmpImageFile->fileName(), "PNG", 100 ) ) { abort(); @@ -99,6 +115,7 @@ void HYDROGUI_RecognizeContoursOp::startOperation() // Reset the panel aPanel->reset(); + aPanel->setImageName( anImageName ); // Get active study SalomeApp_Study* aStudy = @@ -114,8 +131,8 @@ void HYDROGUI_RecognizeContoursOp::startOperation() QString aGeomPictureEntry; - HYDROData_GeomTool::createFaceInGEOM( - aGeomEngine, aDSStudy, aQImage.width(), aQImage.height(), myImage->GetName(), aGeomPictureEntry ); + HYDROData_GeomTool::createFaceInGEOM( aGeomEngine, aDSStudy, aQImage.width(), aQImage.height(), + anImageName, aGeomPictureEntry ); if ( !aGeomPictureEntry.isEmpty() ) { aStudy->setObjectProperty( aViewMgr->getGlobalId(), aGeomPictureEntry, @@ -162,7 +179,9 @@ void HYDROGUI_RecognizeContoursOp::abortOperation() */ void HYDROGUI_RecognizeContoursOp::commitOperation() { - cleanup(); + if ( isApplyAndClose() ) { + cleanup(); + } HYDROGUI_Operation::commitOperation(); } @@ -173,6 +192,11 @@ bool HYDROGUI_RecognizeContoursOp::processApply( int& theUpdateFlags, QString& theErrorMsg, QStringList& theBrowseObjectsEntries ) { + // Check the original image + if ( myImage.IsNull() ) { + return false; + } + // Get panel HYDROGUI_RecognizeContoursDlg* aPanel = ::qobject_cast( inputPanel() ); @@ -186,8 +210,13 @@ bool HYDROGUI_RecognizeContoursOp::processApply( int& theUpdateFlags, return false; } + // Get selected polylines + QStringList aSelectedtPolylines = aPanel->getSelectedtPolylineNames(); + // Remove the selected polylines from the panel + aPanel->removePolylineNames( aSelectedtPolylines ); + // Create polylines - foreach ( QString aName, aPanel->getSelectedtPolylineNames() ) { + foreach ( QString aName, aSelectedtPolylines ) { TopoDS_Shape aShape = myPolylineShapes.value( aName )->getTopoShape(); if ( aShape.IsNull() ) { continue; @@ -200,11 +229,16 @@ bool HYDROGUI_RecognizeContoursOp::processApply( int& theUpdateFlags, aPolylineObj->SetName( aName ); aPolylineObj->ImportShape( aShape ); aPolylineObj->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() ); + aPolylineObj->Update(); module()->setIsToUpdate( aPolylineObj ); } + + // Remove the shape from the map + HYDROGUI_Shape* aShapeToDelete = myPolylineShapes.take( aName ); + delete aShapeToDelete; } - + theUpdateFlags = UF_Model; return true; @@ -306,31 +340,67 @@ void HYDROGUI_RecognizeContoursOp::updateRecognizedPolylines() Handle(AIS_InteractiveContext) aCtx = NULL; // Display preview - if ( !getPreviewManager() ) { - setPreviewManager( ::qobject_cast( - module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) ) ); - } - 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(); + QImage anImage = myImage->Image(); + QRectF aRect( QPointF( 0, 0 ), QPointF( anImage.width(), anImage.height() ) ); + aRect = aTrsf.mapRect( aRect ); + aTrsf.setMatrix( aTrsf.m11(), aTrsf.m12(), aTrsf.m13(), + aTrsf.m21(), -aTrsf.m22(), aTrsf.m23(), + aTrsf.m31() + aRect.width() * 0.5, aTrsf.m32 () - aRect.height() * 0.5, aTrsf.m33() ); + + /* + 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 ) ); + */ + + Handle(HYDROData_PolylineXY) aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) ); + 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 + aPolylineObj->ImportShape( aSubShape ); + aPolylineObj->Transform( aTrsf ); + + /* + 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->setShape( aPolylineObj->GetShape(), true, false ); + aShape->setBorderColor( HYDROData_PolylineXY::DefaultWireColor(), false, false ); + QString aPrefix = QString("%1_%2_%3").arg( myImage->GetName(), "Contour", QString::number( i ) ); QString aName = HYDROGUI_Tool::GenerateObjectName( module(), aPrefix, QStringList(), true ); myPolylineShapes.insert( aName, aShape); + aNamesList << aName; } - if ( !aCtx.IsNull() ) { //@MZN + aPolylineObj->Remove(); + + if ( !aCtx.IsNull() ) { + UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, Graphic3d_ZLayerId_TopOSD ); aCtx->UpdateCurrentViewer(); } @@ -338,7 +408,7 @@ void HYDROGUI_RecognizeContoursOp::updateRecognizedPolylines() HYDROGUI_RecognizeContoursDlg* aPanel = ::qobject_cast( inputPanel() ); if ( aPanel ) { - aPanel->setPolylineNames( myPolylineShapes.keys() ); + aPanel->setPolylineNames( aNamesList ); } } } @@ -360,9 +430,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(); } } @@ -391,7 +480,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; }