]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #524: add polyline transformation; reaction on Apply button.
authormzn <mzn@opencascade.com>
Mon, 25 May 2015 15:09:50 +0000 (18:09 +0300)
committermzn <mzn@opencascade.com>
Mon, 25 May 2015 15:09:50 +0000 (18:09 +0300)
src/HYDROData/HYDROData_PolylineXY.cxx
src/HYDROData/HYDROData_PolylineXY.h
src/HYDROGUI/HYDROGUI_Operations.h
src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.cxx
src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.h
src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index 6c188ac6b727552cd756e33ade5c3dd3a20f5a83..44076c82ad77fad66ca4d3d54d08e2cdbf6931d3 100755 (executable)
@@ -1142,5 +1142,26 @@ void HYDROData_PolylineXY::UpdateLocalCS( double theDx, double theDy )
   SetToUpdate( true );
 }
 
+void HYDROData_PolylineXY::Transform( const QTransform& theTrsf )
+{
+  NCollection_Sequence<TCollection_AsciiString>           aSectNames;
+  NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
+  NCollection_Sequence<bool>                              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 );
+}
 
index fa764067ac0a874b5f4c349370266042f5298684..ef7101048ef76aa9f003a624c8a0eb7d01908c3b 100644 (file)
@@ -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:
 
index e040afc8c6b2fede747cd8e0355d758b0d9a769b..3e551e0d2acce0c66adf28e1300ded19e84092ca 100644 (file)
@@ -107,7 +107,7 @@ enum OperationId
   RiverBottomContextId,
   ProfileInterpolateId,
 
-  RecognizeContoursId
+  RecognizeContoursId,
   SubmersibleId,
   ImportPolylineId,
   ExportPolylineId
index bc12c51e08fb3aa8f6f4b2ffca2e06878b80ee3d..6840e2dd5632ca356460b388b27e91cbeb8baff4 100644 (file)
 #include "HYDROGUI_RecognizeContoursDlg.h"
 
 #include <QGroupBox>
+#include <QLabel>
+#include <QLineEdit>
 #include <QListWidget>
 #include <QVBoxLayout>
 
-
+/**
+ * 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<QListWidgetItem*> 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;
index acfd53b498018693c5c59b7e2ee66a23730f27b5..f30d7db3b672d12e67351f120f91d98a253eae29 100644 (file)
@@ -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;    
 };
 
index bc912b8a30520bdb893bafef5b393a00f2196cdc..9398945850893f66204f39d113af86b80f0ffdc5 100644 (file)
@@ -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<HYDROGUI_RecognizeContoursDlg*>( 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<HYDROGUI_RecognizeContoursDlg*>( inputPanel() );
     if ( aPanel ) {
-      aPanel->setPolylineNames( myPolylineShapes.keys() );
+      aPanel->setPolylineNames( aNamesList );
     }
   }
 }
index 26122a32e4657d3a2a47eb7494f837f0291dfbaf..8f6432c3b62359f7eaefdc55403c51ff814ec7a2 100644 (file)
@@ -2440,9 +2440,17 @@ Polyline should consist from one not closed curve.</translation>
   
   <context>
     <name>HYDROGUI_RecognizeContoursDlg</name>
+    <message>
+      <source>NAME</source>
+      <translation>Name</translation>
+    </message>
+    <message>
+      <source>ORIGINAL_IMAGE</source>
+      <translation>Original image</translation>
+    </message>
     <message>
       <source>RECOGNIZED_POLYLINES</source>
-      <translation>Recognized polylines</translation>
+      <translation>Polylines</translation>
     </message>
   </context>