From 83ea0d4154c73d7368c8de9467410fafeac17d07 Mon Sep 17 00:00:00 2001 From: mzn Date: Mon, 25 May 2015 18:09:50 +0300 Subject: [PATCH] refs #524: add polyline transformation; reaction on Apply button. --- src/HYDROData/HYDROData_PolylineXY.cxx | 21 ++++++ src/HYDROData/HYDROData_PolylineXY.h | 6 ++ src/HYDROGUI/HYDROGUI_Operations.h | 2 +- .../HYDROGUI_RecognizeContoursDlg.cxx | 70 ++++++++++++++++++- src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.h | 7 +- src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx | 43 +++++++++--- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 10 ++- 7 files changed, 145 insertions(+), 14 deletions(-) diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index 6c188ac6..44076c82 100755 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -1142,5 +1142,26 @@ void HYDROData_PolylineXY::UpdateLocalCS( double theDx, double theDy ) SetToUpdate( true ); } +void HYDROData_PolylineXY::Transform( const QTransform& theTrsf ) +{ + NCollection_Sequence aSectNames; + NCollection_Sequence aSectTypes; + NCollection_Sequence aSectClosures; + GetSections( aSectNames, aSectTypes, aSectClosures ); + + for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ ) { + PointsList aPoints = GetPoints( i ); + for( int j = 1, n = aPoints.Size(); j <= n; ++j ) { + Point& aPoint = aPoints.ChangeValue( j ); + QPointF aTrsfPoint = theTrsf.map( QPointF( aPoint.X(), aPoint.Y() ) ); + + aPoint.SetX( aTrsfPoint.x() ); + aPoint.SetY( aTrsfPoint.y() ); + } + SetPoints( i, aPoints ); + } + + SetToUpdate( true ); +} diff --git a/src/HYDROData/HYDROData_PolylineXY.h b/src/HYDROData/HYDROData_PolylineXY.h index fa764067..ef710104 100644 --- a/src/HYDROData/HYDROData_PolylineXY.h +++ b/src/HYDROData/HYDROData_PolylineXY.h @@ -24,6 +24,7 @@ DEFINE_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline) class QPainterPath; +class QTransform; class TopoDS_Wire; class gp_XYZ; @@ -286,6 +287,11 @@ public: */ HYDRODATA_EXPORT virtual QPainterPath GetPainterPath() const; + /** + * Transform the polyline points. + * @param theTrsf the transformation + */ + HYDRODATA_EXPORT void Transform( const QTransform& theTrsf ); protected: diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index e040afc8..3e551e0d 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -107,7 +107,7 @@ enum OperationId RiverBottomContextId, ProfileInterpolateId, - RecognizeContoursId + RecognizeContoursId, SubmersibleId, ImportPolylineId, ExportPolylineId diff --git a/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.cxx b/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.cxx index bc12c51e..6840e2dd 100644 --- a/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.cxx @@ -19,13 +19,30 @@ #include "HYDROGUI_RecognizeContoursDlg.h" #include +#include +#include #include #include - +/** + * Constructor. + * \param theModule the module + * \param theTitle the panel title + */ HYDROGUI_RecognizeContoursDlg::HYDROGUI_RecognizeContoursDlg( HYDROGUI_Module* theModule, const QString& theTitle ) : HYDROGUI_InputPanel( theModule, theTitle ) { + // Original image + QGroupBox* anImageGroup = new QGroupBox( tr( "ORIGINAL_IMAGE" ), mainFrame() ); + QLabel* aNameLabel = new QLabel( tr("NAME") ); + myImageName = new QLineEdit; + myImageName->setReadOnly( true ); + + QHBoxLayout* anImageLayout = new QHBoxLayout(); + anImageLayout->addWidget( aNameLabel ); + anImageLayout->addWidget( myImageName ); + anImageGroup->setLayout( anImageLayout ); + // List of recognized polylines QGroupBox* aPolylinesGroup = new QGroupBox( tr( "RECOGNIZED_POLYLINES" ), mainFrame() ); myPolylines = new QListWidget( aPolylinesGroup ); @@ -35,33 +52,73 @@ HYDROGUI_RecognizeContoursDlg::HYDROGUI_RecognizeContoursDlg( HYDROGUI_Module* t myPolylines->setSortingEnabled( false ); QBoxLayout* aPolylinesLayout = new QVBoxLayout; - aPolylinesLayout->setMargin( 5 ); - aPolylinesLayout->setSpacing( 5 ); aPolylinesLayout->addWidget( myPolylines ); aPolylinesGroup->setLayout( aPolylinesLayout ); // Layout + addWidget( anImageGroup ); addWidget( aPolylinesGroup ); // Conections connect( myPolylines, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) ); } +/** + * Destructor. + */ HYDROGUI_RecognizeContoursDlg::~HYDROGUI_RecognizeContoursDlg() { } +/** + * Set the image name. + * \param theName the name + */ +void HYDROGUI_RecognizeContoursDlg::setImageName( const QString& theName ) +{ + myImageName->setText( theName ); +} + +/** + * Reset the panel. + */ void HYDROGUI_RecognizeContoursDlg::reset() { + myImageName->clear(); myPolylines->clear(); } +/** + * Refill the list of polylines names. + * \param theNames the list of names + */ void HYDROGUI_RecognizeContoursDlg::setPolylineNames( const QStringList& theNames ) { myPolylines->clear(); myPolylines->addItems( theNames ); } +/** + * Remove the given polyline names from the list. + * \param theNames the list of names + */ +void HYDROGUI_RecognizeContoursDlg::removePolylineNames( const QStringList& theNames ) +{ + QList aFoundItems; + + foreach ( const QString& aName, theNames ) { + aFoundItems = myPolylines->findItems( aName, Qt::MatchExactly ); + foreach ( QListWidgetItem* anItem, aFoundItems ) { + anItem = myPolylines->takeItem( myPolylines->row( anItem ) ); + delete anItem; + } + } +} + +/** + * Select the given polyline names in the list. + * \param theNames the list of names + */ void HYDROGUI_RecognizeContoursDlg::setSelectedPolylineNames( const QStringList& theNames ) { myPolylines->clearSelection(); @@ -74,11 +131,18 @@ void HYDROGUI_RecognizeContoursDlg::setSelectedPolylineNames( const QStringList& } } +/** + * Slot called when polyline names selection changed. + */ void HYDROGUI_RecognizeContoursDlg::onItemSelectionChanged() { emit selectionChanged( getSelectedtPolylineNames() ); } +/** + * Get the list of selected polyline names. + * \return the list of names + */ QStringList HYDROGUI_RecognizeContoursDlg::getSelectedtPolylineNames() const { QStringList aSelectedNames; diff --git a/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.h b/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.h index acfd53b4..f30d7db3 100644 --- a/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.h +++ b/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.h @@ -23,6 +23,7 @@ #include "HYDROGUI_InputPanel.h" class QListWidget; +class QLineEdit; class HYDROGUI_RecognizeContoursDlg : public HYDROGUI_InputPanel { @@ -34,14 +35,17 @@ public: HYDROGUI_RecognizeContoursDlg( HYDROGUI_Module* theModule, const QString& theTitle ); virtual ~HYDROGUI_RecognizeContoursDlg(); + void setImageName( const QString& theName ); + void reset(); void setPolylineNames( const QStringList& theNames ); + void removePolylineNames( const QStringList& theNames ); void setSelectedPolylineNames( const QStringList& theNames ); QStringList getSelectedtPolylineNames() const; - + signals: void selectionChanged( const QStringList& ); @@ -49,6 +53,7 @@ public slots: void onItemSelectionChanged(); private: + QLineEdit* myImageName; QListWidget* myPolylines; }; diff --git a/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx index bc912b8a..93989458 100644 --- a/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx +++ b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx @@ -74,16 +74,21 @@ void HYDROGUI_RecognizeContoursOp::startOperation() { HYDROGUI_Operation::startOperation(); + 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 +104,7 @@ void HYDROGUI_RecognizeContoursOp::startOperation() // Reset the panel aPanel->reset(); + aPanel->setImageName( anImageName ); // Get active study SalomeApp_Study* aStudy = @@ -114,8 +120,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 +168,9 @@ void HYDROGUI_RecognizeContoursOp::abortOperation() */ void HYDROGUI_RecognizeContoursOp::commitOperation() { - cleanup(); + if ( isApplyAndClose() ) { + cleanup(); + } HYDROGUI_Operation::commitOperation(); } @@ -173,6 +181,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 +199,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 +218,17 @@ 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 ); } + + // Remove the shape from the map + HYDROGUI_Shape* aShapeToDelete = myPolylineShapes.take( aName ); + delete aShapeToDelete; } - + theUpdateFlags = UF_Model; return true; @@ -319,18 +343,21 @@ void HYDROGUI_RecognizeContoursOp::updateRecognizedPolylines() } } + QStringList aNamesList; for ( int i = 1; i <= aSubShapes.Length(); i++ ) { const TopoDS_Shape& aSubShape = aSubShapes.Value( i ); HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); aShape->setShape( aSubShape, 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 + if ( !aCtx.IsNull() ) { aCtx->UpdateCurrentViewer(); } @@ -338,7 +365,7 @@ void HYDROGUI_RecognizeContoursOp::updateRecognizedPolylines() HYDROGUI_RecognizeContoursDlg* aPanel = ::qobject_cast( inputPanel() ); if ( aPanel ) { - aPanel->setPolylineNames( myPolylineShapes.keys() ); + aPanel->setPolylineNames( aNamesList ); } } } diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 26122a32..8f6432c3 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2440,9 +2440,17 @@ Polyline should consist from one not closed curve. HYDROGUI_RecognizeContoursDlg + + NAME + Name + + + ORIGINAL_IMAGE + Original image + RECOGNIZED_POLYLINES - Recognized polylines + Polylines -- 2.39.2