]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Merge remote-tracking branch 'origin/BR_v14_rc' into BR_SHAPE_RECOGNITION
authormzn <mzn@opencascade.com>
Mon, 25 May 2015 12:24:40 +0000 (15:24 +0300)
committermzn <mzn@opencascade.com>
Mon, 25 May 2015 12:24:40 +0000 (15:24 +0300)
18 files changed:
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_CalculationCase.h
src/HYDROData/HYDROData_GeomTool.cxx
src/HYDROData/HYDROData_GeomTool.h
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_Operations.h
src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_RecognizeContoursOp.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_Shape.cxx
src/HYDROGUI/HYDROGUI_Tool.cxx
src/HYDROGUI/HYDROGUI_Tool.h
src/HYDROGUI/resources/HYDROGUI_images.ts
src/HYDROGUI/resources/HYDROGUI_msg_en.ts
src/HYDROGUI/resources/icon_recognize_contours.png [new file with mode: 0644]

index ec18b345c6c57d472b2b97551fca68849579cedf..56f5259ac9eb0f9b9e817026cd5804f27af0b224 100644 (file)
@@ -1029,7 +1029,7 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var
   // Publish the sewed shape
   QString aName = EXPORT_NAME;
   GEOM::GEOM_Object_ptr aMainShape = 
-    publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
+    HYDROData_GeomTool::publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
 
   if ( aMainShape->_is_nil() )  
     return false;
@@ -1126,52 +1126,6 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var
   return true;
 }
 
-GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM( 
-  GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
-  const TopoDS_Shape& theShape, const QString& theName,
-  QString& theGeomObjEntry ) const
-{
-  theGeomObjEntry = "";
-  GEOM::GEOM_Object_var aGeomObj;
-
-  if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
-       theShape.IsNull() ) {
-    return aGeomObj._retn();
-  }
-
-  std::ostringstream aStreamShape;
-  // Write TopoDS_Shape in ASCII format to the stream
-  BRepTools::Write( theShape, aStreamShape );
-  // Returns the number of bytes that have been stored in the stream's buffer.
-  int aSize = aStreamShape.str().size();
-  // Allocate octect buffer of required size
-  CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
-  // Copy ostrstream content to the octect buffer
-  memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
-  // Create TMPFile
-  SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
-
-  // Restore shape from the stream and get the GEOM object
-  GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
-  aGeomObj = anInsOp->RestoreShape( aSeqFile );
-  
-  // Puplish the GEOM object
-  if ( !aGeomObj->_is_nil() ) {
-    QString aName = HYDROData_GeomTool::GetFreeName( theStudy, theName );
-
-    SALOMEDS::SObject_var aResultSO = 
-      theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), 
-                                     aGeomObj, qPrintable( aName ) );
-    if ( aResultSO->_is_nil() ) {
-      aGeomObj = GEOM::GEOM_Object::_nil();
-    }
-    else
-      theGeomObjEntry = aResultSO->GetID();
-  }
-
-  return aGeomObj._retn();
-}
-
 void HYDROData_CalculationCase::ClearRules( const bool theIsSetToUpdate )
 {
   TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
index 35d51d10e4b182b084f560bdbdad26c1981b7c9b..b03806b1622733937d967f8cd829285838095cc9 100644 (file)
@@ -358,21 +358,7 @@ private:
                const TopTools_ListOfShape&                   theFaces,
                const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
                QString& theGeomObjEntry ) const;
-
-  /**
-   * Publish the given shape in GEOM as a GEOM object.
-   * \param theGeomEngine GEOM module engine
-   * \param theStudy SALOMEDS study, used for publishing of the shape
-   * \param theShape the shape to publish as a GEOM object
-   * \param theName the name of the published object
-   * \return the published GEOM object
-   */
-  GEOM::GEOM_Object_ptr publishShapeInGEOM( GEOM::GEOM_Gen_var  theGeomEngine,
-                                            SALOMEDS::Study_ptr theStudy,
-                                            const TopoDS_Shape& theShape, 
-                                            const QString&      theName,
-                                            QString& theGeomObjEntry ) const;
-
+  
   void CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
                          const HYDROData_SplitToZonesTool::SplitDataList& theZones );
   void CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
index 10c0bf4ca90b029ea409f5201125a0c3b8199ae6..a83258e61f7bff4b896da5ca198a886e923faee6 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <TopoDS_Shape.hxx>
 
+#include <BRepTools.hxx>
+
 #include <SALOME_NamingService.hxx>
 #include <SALOME_LifeCycleCORBA.hxx>
 
@@ -106,4 +108,90 @@ QString HYDROData_GeomTool::GetFreeName( SALOMEDS::Study_ptr theStudy, const QSt
   }
 
   return aName;
-}
\ No newline at end of file
+}
+
+GEOM::GEOM_Object_ptr HYDROData_GeomTool::publishShapeInGEOM( 
+  GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
+  const TopoDS_Shape& theShape, const QString& theName,
+  QString& theGeomObjEntry )
+{
+  theGeomObjEntry = "";
+  GEOM::GEOM_Object_var aGeomObj;
+
+  if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
+       theShape.IsNull() ) {
+    return aGeomObj._retn();
+  }
+
+  std::ostringstream aStreamShape;
+  // Write TopoDS_Shape in ASCII format to the stream
+  BRepTools::Write( theShape, aStreamShape );
+  // Returns the number of bytes that have been stored in the stream's buffer.
+  int aSize = aStreamShape.str().size();
+  // Allocate octect buffer of required size
+  CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
+  // Copy ostrstream content to the octect buffer
+  memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
+  // Create TMPFile
+  SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
+
+  // Restore shape from the stream and get the GEOM object
+  GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
+  aGeomObj = anInsOp->RestoreShape( aSeqFile );
+  
+  // Publish the GEOM object
+  theGeomObjEntry = publishGEOMObject( theGeomEngine, theStudy, aGeomObj, theName );
+  
+  return aGeomObj._retn();
+}
+
+ GEOM::GEOM_Object_ptr HYDROData_GeomTool::createFaceInGEOM( GEOM::GEOM_Gen_var theGeomEngine,
+                                                             SALOMEDS::Study_ptr theStudy,
+                                                             const int theWidth,
+                                                             const int theHeight,
+                                                             const QString& theName,
+                                                             QString& theFaceEntry )
+{
+  theFaceEntry = "";
+  GEOM::GEOM_Object_var aGeomObj;
+
+  if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ) {
+    return aGeomObj._retn();
+  }
+
+  GEOM::GEOM_IBasicOperations_var aBasicOperations = theGeomEngine->GetIBasicOperations( theStudy->StudyId() );
+  GEOM::GEOM_IBlocksOperations_var aBlocksOperations = theGeomEngine->GetIBlocksOperations( theStudy->StudyId() );
+         
+  GEOM::GEOM_Object_var P1 = aBasicOperations->MakePointXYZ( -0.5 * theWidth, -0.5 * theHeight, 0 );
+  GEOM::GEOM_Object_var P2 = aBasicOperations->MakePointXYZ(  0.5 * theWidth, -0.5 * theHeight, 0 );
+  GEOM::GEOM_Object_var P3 = aBasicOperations->MakePointXYZ(  0.5 * theWidth,  0.5 * theHeight, 0 );
+  GEOM::GEOM_Object_var P4 = aBasicOperations->MakePointXYZ( -0.5 * theWidth,  0.5 * theHeight, 0 );
+  
+  GEOM::GEOM_Object_var aFace = aBlocksOperations->MakeQuad4Vertices( P1, P2 ,P3, P4 );
+    
+  // Publish the face
+  theFaceEntry = publishGEOMObject( theGeomEngine, theStudy, aFace, theName );
+
+  return aFace._retn();
+}
+
+QString HYDROData_GeomTool::publishGEOMObject( GEOM::GEOM_Gen_var theGeomEngine,
+                                               SALOMEDS::Study_ptr theStudy,
+                                               GEOM::GEOM_Object_ptr theGeomObj,
+                                               const QString& theName )
+{
+  QString anEntry;
+
+  if ( !theGeomObj->_is_nil() ) {
+    QString aName = HYDROData_GeomTool::GetFreeName( theStudy, theName );
+
+    SALOMEDS::SObject_var aResultSO = 
+      theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), 
+                                     theGeomObj, qPrintable( aName ) );
+    if ( !aResultSO->_is_nil() ) {
+      anEntry = aResultSO->GetID();
+    }
+  }
+
+  return anEntry;
+}
index ea4cb95d39dad7d48fbecb721958a8cbc6418aea..554aede3c7e5b6209191433586af4deb31a66b5c 100644 (file)
@@ -58,6 +58,52 @@ public:
    * \return the default name
    */
   static QString GetFreeName( SALOMEDS::Study_ptr theStudy, const QString& theBaseName );
+
+  /**
+   * Publish the given shape in GEOM as a GEOM object.
+   * \param theGeomEngine GEOM module engine
+   * \param theStudy SALOMEDS study, used for publishing of the shape
+   * \param theShape the shape to publish as a GEOM object
+   * \param theName the name of the published object
+   * \param theGeomObjEntry the entry of the published object
+   * \return the published GEOM object
+   */
+  static GEOM::GEOM_Object_ptr publishShapeInGEOM( GEOM::GEOM_Gen_var  theGeomEngine,
+                                                   SALOMEDS::Study_ptr theStudy,
+                                                   const TopoDS_Shape& theShape, 
+                                                   const QString&      theName,
+                                                   QString& theGeomObjEntry );
+
+  /**
+   * Create and publish face in GEOM as a GEOM object.
+   * \param theGeomEngine GEOM module engine
+   * \param theStudy SALOMEDS study, used for publishing of the face
+   * \param theWidth the face width
+   * \param theHeight the face height
+   * \param theName the name of the published face
+   * \param theFaceEntry the entry of the published face
+   * \return the published GEOM object
+   */
+  static GEOM::GEOM_Object_ptr createFaceInGEOM( GEOM::GEOM_Gen_var theGeomEngine,
+                                                 SALOMEDS::Study_ptr theStudy,
+                                                 const int theWidth,
+                                                 const int theHeight,
+                                                 const QString& theName,
+                                                 QString& theFaceEntry );
+
+  /**
+   * Publish the given GEOM object in the study.
+   * \param theGeomEngine GEOM module engine
+   * \param theStudy SALOMEDS study, used for publishing of the object
+   * \param theGeomObj the GEOM object
+   * \param theName the object name
+   * \return the entry of the published object (empty string in case of fail)
+   */
+  static QString publishGEOMObject( GEOM::GEOM_Gen_var theGeomEngine,
+                                    SALOMEDS::Study_ptr theStudy,
+                                    GEOM::GEOM_Object_ptr theGeomObj,
+                                    const QString& theName );
+
 };
 
 #endif
index fdd046cdc8627bcf4beb0fe7c0d51de2890848ec..e6417fd98c1d682a02e47c359bda2c0905a3e66a 100644 (file)
@@ -111,6 +111,8 @@ set(PROJECT_HEADERS
     HYDROGUI_RiverBottomOp.h
     HYDROGUI_ViewerDlg.h
     HYDROGUI_ObjComboBox.h
+    HYDROGUI_RecognizeContoursDlg.h
+    HYDROGUI_RecognizeContoursOp.h
 )
 
 QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS})
@@ -225,6 +227,8 @@ set(PROJECT_SOURCES
     HYDROGUI_RiverBottomOp.cxx
     HYDROGUI_ViewerDlg.cxx
     HYDROGUI_ObjComboBox.cxx
+    HYDROGUI_RecognizeContoursDlg.cxx
+    HYDROGUI_RecognizeContoursOp.cxx
 )
 
 add_definitions(
index 283f361e77034b025de0ec4630f6b5fc4f06ba64..cbed2b66dc1943b3c443b75712ee31a944c3078e 100644 (file)
@@ -573,6 +573,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( CutImagesId ) );
         theMenu->addAction( action( SplitImageId ) );
         theMenu->addSeparator();
+        theMenu->addAction( action( RecognizeContoursId ) );
+        theMenu->addSeparator();
       }
       else if( anIsBathymetry )
       {
index 6170aca5055c9b0edc4b659cedecf294121664d4..7617747e95d2ee9bd85af1e567aa28083d6cfaeb 100644 (file)
@@ -56,6 +56,7 @@
 #include "HYDROGUI_LocalCSOp.h"
 #include "HYDROGUI_RiverBottomOp.h"
 #include "HYDROGUI_ProfileInterpolateOp.h"
+#include "HYDROGUI_RecognizeContoursOp.h"
 #include "HYDROGUI_SubmersibleOp.h"
 
 #include <HYDROData_Document.h>
@@ -168,6 +169,8 @@ void HYDROGUI_Module::createActions()
   createAction( SplitImageId, "SPLIT_IMAGE", "SPLIT_IMAGE_ICO" );
   createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE", "EDIT_SPLITTED_IMAGE_ICO" );
 
+  createAction( RecognizeContoursId, "RECOGNIZE_CONTOURS", "RECOGNIZE_CONTOURS_ICO" );
+
   createAction( CopyViewerPositionId, "COPY_VIEWER_POSITION", "" );
 
   createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
@@ -526,6 +529,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
   case RiverBottomContextId:
     anOp = new HYDROGUI_RiverBottomOp( aModule );
     break;
+  case RecognizeContoursId:
+    anOp = new HYDROGUI_RecognizeContoursOp( aModule );
+    break;
   case ShowId:
   case ShowOnlyId:
   case ShowAllId:
index 3eeebc14ffb196a0277b014880f074cb96bfc1a0..e040afc8c6b2fede747cd8e0355d758b0d9a769b 100644 (file)
@@ -107,6 +107,7 @@ enum OperationId
   RiverBottomContextId,
   ProfileInterpolateId,
 
+  RecognizeContoursId
   SubmersibleId,
   ImportPolylineId,
   ExportPolylineId
diff --git a/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.cxx b/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.cxx
new file mode 100644 (file)
index 0000000..bc12c51
--- /dev/null
@@ -0,0 +1,92 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_RecognizeContoursDlg.h"
+
+#include <QGroupBox>
+#include <QListWidget>
+#include <QVBoxLayout>
+
+
+HYDROGUI_RecognizeContoursDlg::HYDROGUI_RecognizeContoursDlg( HYDROGUI_Module* theModule, const QString& theTitle )
+: HYDROGUI_InputPanel( theModule, theTitle )
+{
+  // List of recognized polylines
+  QGroupBox* aPolylinesGroup = new QGroupBox( tr( "RECOGNIZED_POLYLINES" ), mainFrame() );
+  myPolylines = new QListWidget( aPolylinesGroup );
+  myPolylines->setSelectionMode( QListWidget::ExtendedSelection );
+  myPolylines->setEditTriggers( QListWidget::NoEditTriggers );
+  myPolylines->setViewMode( QListWidget::ListMode );
+  myPolylines->setSortingEnabled( false );
+
+  QBoxLayout* aPolylinesLayout = new QVBoxLayout;
+  aPolylinesLayout->setMargin( 5 );
+  aPolylinesLayout->setSpacing( 5 );
+  aPolylinesLayout->addWidget( myPolylines );
+  aPolylinesGroup->setLayout( aPolylinesLayout );
+
+  // Layout
+  addWidget( aPolylinesGroup );
+
+  // Conections
+  connect( myPolylines, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
+}
+
+HYDROGUI_RecognizeContoursDlg::~HYDROGUI_RecognizeContoursDlg()
+{
+}
+
+void HYDROGUI_RecognizeContoursDlg::reset()
+{
+  myPolylines->clear();
+}
+
+void HYDROGUI_RecognizeContoursDlg::setPolylineNames( const QStringList& theNames )
+{
+  myPolylines->clear();
+  myPolylines->addItems( theNames );
+}
+
+void HYDROGUI_RecognizeContoursDlg::setSelectedPolylineNames( const QStringList& theNames )
+{
+  myPolylines->clearSelection();
+
+  foreach( const QString aName, theNames ) {
+    QList<QListWidgetItem*> anItems = myPolylines->findItems( aName, Qt::MatchExactly );
+    if ( anItems.count() == 1 ) {
+      anItems.first()->setSelected( true );
+    }
+  }
+}
+
+void HYDROGUI_RecognizeContoursDlg::onItemSelectionChanged()
+{
+  emit selectionChanged( getSelectedtPolylineNames() );
+}
+
+QStringList HYDROGUI_RecognizeContoursDlg::getSelectedtPolylineNames() const
+{
+  QStringList aSelectedNames;
+
+  QList<QListWidgetItem*> aSelectedItems = myPolylines->selectedItems();
+  foreach( const QListWidgetItem* anItem, aSelectedItems ) {
+    aSelectedNames << anItem->text();
+  }
+
+  return aSelectedNames;
+}
\ No newline at end of file
diff --git a/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.h b/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.h
new file mode 100644 (file)
index 0000000..acfd53b
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+
+#ifndef HYDROGUI_RecognizeContoursDlg_H
+#define HYDROGUI_RecognizeContoursDlg_H
+
+#include "HYDROGUI_InputPanel.h"
+
+class QListWidget;
+
+class HYDROGUI_RecognizeContoursDlg : public HYDROGUI_InputPanel
+{
+  Q_OBJECT
+
+  enum CreationMode { CreateNewId, ModifyExistentId };
+
+public:
+  HYDROGUI_RecognizeContoursDlg( HYDROGUI_Module* theModule, const QString& theTitle );
+  virtual ~HYDROGUI_RecognizeContoursDlg();
+
+  void reset();
+
+  void setPolylineNames( const QStringList& theNames );
+
+  void setSelectedPolylineNames( const QStringList& theNames );
+
+  QStringList getSelectedtPolylineNames() const;
+
+signals:
+  void selectionChanged( const QStringList& );
+
+public slots:
+  void onItemSelectionChanged();
+
+private:
+  QListWidget* myPolylines;    
+};
+
+#endif
diff --git a/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx
new file mode 100644 (file)
index 0000000..bc912b8
--- /dev/null
@@ -0,0 +1,427 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_RecognizeContoursOp.h"
+
+#include "HYDROGUI_RecognizeContoursDlg.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_Shape.h"
+#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_UpdateFlags.h"
+
+#include <HYDROData_Document.h>
+#include <HYDROData_GeomTool.h>
+#include <HYDROData_ShapesTool.h>
+#include <HYDROData_PolylineXY.h>
+
+#include <GeometryGUI.h>
+#include <GeometryGUI_Operations.h>
+#include <GEOM_Constants.h>
+#include <GEOMBase.h>
+
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewModel.h>
+
+#include <SalomeApp_Study.h>
+
+#include <LightApp_Application.h>
+#include <LightApp_DataOwner.h>
+#include <LightApp_Displayer.h>
+#include <LightApp_SelectionMgr.h>
+
+#include <SUIT_Desktop.h>
+#include <SUIT_ViewManager.h>
+
+#include <QDialog>
+#include <QTemporaryFile>
+
+/**
+  Constructor.
+*/
+HYDROGUI_RecognizeContoursOp::HYDROGUI_RecognizeContoursOp( HYDROGUI_Module* theModule )
+: HYDROGUI_Operation( theModule ),
+  myGEOMOpName( "" )
+{
+  setName( tr( "CONTOURS_RECOGNITION" ) );
+}
+
+/**
+  Destructor.
+*/
+HYDROGUI_RecognizeContoursOp::~HYDROGUI_RecognizeContoursOp()
+{
+  cleanup();
+}
+
+/**
+*/
+void HYDROGUI_RecognizeContoursOp::startOperation()
+{
+  HYDROGUI_Operation::startOperation();
+  
+  // Get the selected image
+  myImage = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+  if ( myImage.IsNull() ) {
+    abort();
+    return;
+  }
+
+  // Create temporary graphics file
+  QImage aQImage = myImage->Image();
+  myTmpImageFile = new QTemporaryFile( myImage->GetName() );
+  if ( !myTmpImageFile->open() || 
+       !aQImage.save( myTmpImageFile->fileName(), "PNG", 100 ) ) {
+    abort();
+    return;
+  }
+
+  // Create the input panel
+  HYDROGUI_RecognizeContoursDlg* aPanel = 
+    ::qobject_cast<HYDROGUI_RecognizeContoursDlg*>( inputPanel() );
+  if ( !aPanel ) {
+    return;
+  }
+
+  // Reset the panel
+  aPanel->reset();
+
+  // Get active study
+  SalomeApp_Study* aStudy = 
+    dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
+
+  // Get active view manager
+  SUIT_ViewManager* aViewMgr = module()->getApp()->activeViewManager();
+
+  // Export the selected image to GEOM module
+  if ( aStudy && aViewMgr ) {
+    SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
+    GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
+
+    QString aGeomPictureEntry;
+
+    HYDROData_GeomTool::createFaceInGEOM( 
+      aGeomEngine, aDSStudy, aQImage.width(), aQImage.height(), myImage->GetName(), aGeomPictureEntry );
+    
+    if ( !aGeomPictureEntry.isEmpty() ) {
+      aStudy->setObjectProperty( aViewMgr->getGlobalId(), aGeomPictureEntry, 
+                                 GEOM::propertyName( GEOM::Texture ), myTmpImageFile->fileName() );
+    
+      // update the object browser
+      module()->getApp()->updateObjectBrowser( true );
+
+      // select the picture
+      SUIT_DataOwnerPtrList aList( true );
+      aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aGeomPictureEntry ) ) );
+      selectionMgr()->setSelected(aList );
+
+      // Add GEOM picture object entry to the list of temporary geom objects
+      myTmpGeomObjects << aGeomPictureEntry;
+    }
+  }
+
+  // Activate GEOM module operation
+  LightApp_Application* anApp = module()->getApp();
+  if ( anApp ) {
+    connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ), 
+             this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
+
+    module()->getApp()->activateOperation( "Geometry", GEOMOp::OpFeatureDetect );
+  }
+}
+
+/**
+*/
+void HYDROGUI_RecognizeContoursOp::abortOperation()
+{
+  LightApp_Application* anApp = module()->getApp();
+  if ( anApp ) {
+    anApp->disconnect( this );
+  }
+
+  cleanup();
+
+  HYDROGUI_Operation::abortOperation();
+}
+
+/**
+*/
+void HYDROGUI_RecognizeContoursOp::commitOperation()
+{
+  cleanup();
+
+  HYDROGUI_Operation::commitOperation();
+}
+
+/**
+*/
+bool HYDROGUI_RecognizeContoursOp::processApply( int& theUpdateFlags,
+                                                QString& theErrorMsg,
+                                                QStringList& theBrowseObjectsEntries )
+{
+  // Get panel
+  HYDROGUI_RecognizeContoursDlg* aPanel = 
+    ::qobject_cast<HYDROGUI_RecognizeContoursDlg*>( inputPanel() );
+  if ( !aPanel ) {
+    return false;
+  }
+  
+  // Check if contour GEOM object exists
+  if ( myGeomContourEntry.isEmpty() ) {
+    theErrorMsg = tr( "NO_DETECTED_CONTOURS" );
+    return false;
+  }
+
+  // Create polylines
+  foreach ( QString aName, aPanel->getSelectedtPolylineNames() ) {
+    TopoDS_Shape aShape = myPolylineShapes.value( aName )->getTopoShape();
+    if ( aShape.IsNull() ) {
+      continue;
+    }
+
+    Handle(HYDROData_PolylineXY) aPolylineObj =
+      Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) );
+
+    if( !aPolylineObj.IsNull() ) {
+      aPolylineObj->SetName( aName );
+      aPolylineObj->ImportShape( aShape );
+      aPolylineObj->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
+      aPolylineObj->Update();
+      module()->setIsToUpdate( aPolylineObj );
+    }
+  }
+  
+  theUpdateFlags = UF_Model;
+
+  return true;
+}
+
+/**
+*/
+HYDROGUI_InputPanel* HYDROGUI_RecognizeContoursOp::createInputPanel() const
+{
+  HYDROGUI_InputPanel* aPanel = new HYDROGUI_RecognizeContoursDlg( module(), getName() );
+
+  connect( aPanel, SIGNAL( selectionChanged( const QStringList& ) ), this, SLOT( onSelectionChanged( const QStringList& ) ) );
+
+  return aPanel;
+}
+
+/**
+ * Called when the operation perfomed by another module is finished.
+ * \param theModuleName the name of the module which perfomed the operation
+ * \param theOperationName the operation name
+ * \param theEntryList the list of the created objects entries
+ */
+void HYDROGUI_RecognizeContoursOp::onExternalOperationFinished( 
+  const QString& theModuleName, const QString& theOperationName,
+  const QStringList& theEntryList )
+{
+  // Process "Geometry" module operations only
+  if ( theModuleName != "Geometry" ) {
+    return;
+  }
+    
+  // Store the operation name
+  myGEOMOpName = theOperationName;
+
+  // Close the dialog corresponding to the external operation
+  closeExternalOperationDlg();
+  
+  // Erase the GEOM objects
+  LightApp_Displayer().Erase( theEntryList );
+
+  // Add GEOM object entries to the list of temporary GEOM objects
+  myTmpGeomObjects << theEntryList;
+
+  if ( theEntryList.count() == 1 ) {
+    myGeomContourEntry = theEntryList.first();
+
+    // Update the list of polylines
+    updateRecognizedPolylines();
+  }
+}
+
+/**
+  Close the GEOM contours detection dialog.
+*/
+void HYDROGUI_RecognizeContoursOp::closeExternalOperationDlg()
+{
+  if ( myGEOMOpName.isEmpty() ) {
+    return;
+  }
+
+  SUIT_Desktop* aDesktop = module()->getApp()->desktop();
+  if ( aDesktop ) {
+    QList<QDialog*> aDialogs = aDesktop->findChildren<QDialog*>();
+    foreach ( QDialog* aDlg, aDialogs ) {
+      if ( typeid(*aDlg).name() == myGEOMOpName ) {
+        aDlg->close();
+        break;
+      }
+    }
+  }
+}
+
+/**
+  Update the list of recognized polylines by exploding the GEOM contour object.
+*/
+void HYDROGUI_RecognizeContoursOp::updateRecognizedPolylines()
+{
+  // Erase the preview
+  erasePreview();
+
+  // Get active study
+  SalomeApp_Study* aStudy = 
+    dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
+  if ( !aStudy ) {
+    return;
+  }
+
+  // Explode the compound
+  _PTR(SObject) aSObject( aStudy->studyDS()->FindObjectID( qPrintable( myGeomContourEntry ) ) );
+  if ( aSObject ) {
+    TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( aSObject->GetIOR().c_str() );
+
+    TopTools_SequenceOfShape aSubShapes;
+    HYDROData_ShapesTool::ExploreShapeToShapes( aShape, TopAbs_WIRE, aSubShapes );
+    if ( aSubShapes.Length() < 1 ) {
+      HYDROData_ShapesTool::ExploreShapeToShapes( aShape, TopAbs_EDGE, aSubShapes );
+    }
+
+    Handle(AIS_InteractiveContext) aCtx = NULL;
+
+    // Display preview
+    if ( !getPreviewManager() ) {
+      setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>( 
+                          module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
+    }
+
+    OCCViewer_ViewManager* aViewManager = getPreviewManager();
+    if ( aViewManager ) {
+      if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
+        aCtx = aViewer->getAISContext();
+        connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
+      }
+    }
+
+    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 );
+
+      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);
+    }
+
+    if ( !aCtx.IsNull() ) { //@MZN
+      aCtx->UpdateCurrentViewer();
+    }
+
+    // Get panel
+    HYDROGUI_RecognizeContoursDlg* aPanel = 
+      ::qobject_cast<HYDROGUI_RecognizeContoursDlg*>( inputPanel() );
+    if ( aPanel ) {
+      aPanel->setPolylineNames( myPolylineShapes.keys() );
+    }
+  }
+}
+
+/**
+  Erase the preview.
+*/
+void HYDROGUI_RecognizeContoursOp::erasePreview()
+{
+  foreach ( HYDROGUI_Shape* aShape, myPolylineShapes ) {
+    delete aShape;
+  }
+
+  myPolylineShapes.clear();
+}
+
+/**
+  Called when selection of the recognized polylines is changed.
+*/
+void HYDROGUI_RecognizeContoursOp::onSelectionChanged( const QStringList& theSelectedNames )
+{
+  foreach ( QString aName, myPolylineShapes.keys() ) {
+    bool isSelected = theSelectedNames.contains( aName );
+    myPolylineShapes[aName]->highlight( isSelected, true );
+  }
+}
+
+/**
+  Called when selection in the viewer is changed.
+*/
+void HYDROGUI_RecognizeContoursOp::onViewerSelectionChanged()
+{
+  // Get panel
+  HYDROGUI_RecognizeContoursDlg* aPanel = 
+    ::qobject_cast<HYDROGUI_RecognizeContoursDlg*>( inputPanel() );
+  if ( !aPanel ) {
+    return;
+  }
+
+  Handle(AIS_InteractiveContext) aCtx = NULL;
+
+  OCCViewer_ViewManager* aViewManager = getPreviewManager();
+  if ( aViewManager ) {
+    if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
+      aCtx = aViewer->getAISContext();
+    }
+  }
+  
+  if ( !aCtx.IsNull() ) {
+    QStringList aSelectedNames;
+
+    foreach ( QString aName, myPolylineShapes.keys() ) {
+      bool isSelected = aCtx->IsSelected( myPolylineShapes[aName]->getAISObject() );
+      if ( isSelected ) {
+        aSelectedNames << aName;
+      }
+    }
+
+    aPanel->setSelectedPolylineNames( aSelectedNames );
+  }
+}
+
+/**
+  Do the operation data cleanup.
+*/
+void HYDROGUI_RecognizeContoursOp::cleanup()
+{
+  // Close the external operation dialog
+  closeExternalOperationDlg();
+
+  // Erase the preview 
+  erasePreview();
+
+  // Delete temporary image file
+  if ( myTmpImageFile ) {
+    delete myTmpImageFile;
+    myTmpImageFile = NULL;
+  }
+
+  // Delete temporary GEOM objects
+  if ( !myTmpGeomObjects.isEmpty() ) {
+    HYDROGUI_Tool::DeleteGeomObjects( module(), myTmpGeomObjects );
+    // update the object browser
+    module()->getApp()->updateObjectBrowser( true );
+  }
+}
\ No newline at end of file
diff --git a/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.h b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.h
new file mode 100644 (file)
index 0000000..dfe7b98
--- /dev/null
@@ -0,0 +1,78 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_RecognizeContoursOp_H
+#define HYDROGUI_RecognizeContoursOp_H
+
+#include "HYDROGUI_Operation.h"
+
+#include <HYDROData_Image.h>
+
+#include <QMap>
+#include <QStringList>
+
+class QTemporaryFile;
+
+
+class HYDROGUI_RecognizeContoursOp : public HYDROGUI_Operation
+{
+  Q_OBJECT
+
+public:
+  HYDROGUI_RecognizeContoursOp( HYDROGUI_Module* theModule );
+  virtual ~HYDROGUI_RecognizeContoursOp();
+
+protected:
+  virtual void startOperation();
+  virtual void abortOperation();
+  virtual void commitOperation();
+
+  virtual HYDROGUI_InputPanel* createInputPanel() const;
+
+  virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg,
+                             QStringList& theBrowseObjectsEntries );
+
+protected slots:
+  void onExternalOperationFinished( const QString&, const QString&, 
+                                    const QStringList& );
+
+  void onSelectionChanged( const QStringList& theSelectedNames );
+  void onViewerSelectionChanged();
+
+private:
+  void closeExternalOperationDlg();
+
+  void updateRecognizedPolylines();
+
+  void erasePreview();
+
+  void cleanup();
+
+private:
+  Handle(HYDROData_Image) myImage; ///< the image used for contours detection
+
+  QTemporaryFile* myTmpImageFile;  ///< the temporary graphics file
+
+  QStringList myTmpGeomObjects;    ///< the list of temporary GEOM objects entries
+  QString myGeomContourEntry;      ///< the GEOM contour object entry
+  QString myGEOMOpName;            ///< the name of the called GEOM module operation
+  
+  QMap<QString, HYDROGUI_Shape*> myPolylineShapes; ///< the detected polylines shapes map (key: name, value: shape)
+};
+
+#endif
\ No newline at end of file
index f9799da5530056ac4be7f9a127f7820cf30437a9..b837ec301447436f8472d89a0b2d9ab2ddf5f42e 100644 (file)
@@ -587,7 +587,9 @@ void HYDROGUI_Shape::displayShape( const bool theIsUpdateViewer )
   if ( myZLayer >= 0 )
     myContext->SetZLayer( myShape, myZLayer );
 
-  myContext->UpdateCurrentViewer();
+  if ( theIsUpdateViewer ) {
+    myContext->UpdateCurrentViewer();
+  }
 }
 
 QColor HYDROGUI_Shape::getActiveColor() const
index 568ffb1c18603d2d8860f7961dfbf5123e1396b2..7370fa3150755baf2c1dde3169fcd584ee5a335c 100644 (file)
@@ -29,6 +29,7 @@
 #include <HYDROData_Tool.h>
 #include <HYDROData_Profile.h>
 
+#include <GeometryGUI.h>
 #include <GEOMBase.h>
 
 #include <GraphicsView_Viewer.h>
@@ -773,3 +774,39 @@ Handle(Image_PixMap) HYDROGUI_Tool::Pixmap( const QImage& theImage )
 
     return pix;
 }
+
+void HYDROGUI_Tool::DeleteGeomObjects( HYDROGUI_Module* theModule, const QStringList& theEntries )
+{
+  QStringList anEntryList;
+
+  // Get active SalomeApp_Study
+  SalomeApp_Study* aStudy = NULL;
+  if ( theModule && theModule->getApp() ) {
+    aStudy = dynamic_cast<SalomeApp_Study*>( theModule->getApp()->activeStudy() );
+  }
+  if ( !aStudy ) {
+    return;
+  }
+  // Get GEOM engine
+  GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
+  if ( aGeomEngine->_is_nil() ) {
+    return;
+  }
+  
+  // Delete GEOM objects
+  _PTR(StudyBuilder) aStudyBuilder( aStudy->studyDS()->NewBuilder() );
+  foreach ( const QString anEntry, theEntries ) {
+    _PTR(SObject) aSObject( aStudy->studyDS()->FindObjectID( qPrintable(anEntry) ) );
+    if ( aSObject ) {
+      GEOM::GEOM_Object_var aGeomObj = 
+        GEOMBase::GetObjectFromIOR( aSObject->GetIOR().c_str() );
+
+      if ( !aGeomObj->_is_nil() ) {
+        aGeomEngine->RemoveObject( aGeomObj );
+      }
+
+      aStudyBuilder->RemoveObject( aSObject );
+    }
+  }
+}
\ No newline at end of file
index 60600a54bf5b51e4f7ba63e93fc3fcae5910b961..4ea4039edd77b2fec67829cf454ccb8205fad0db 100644 (file)
@@ -172,16 +172,7 @@ public:
    * \return object kind
    */
   static ObjectKind GetSelectedPartition( HYDROGUI_Module* theModule );
-
-  /**
-   * \brief Get the selected GEOM objects.
-   * \param theModule module
-   * \param theTypes the acceptable GEOM object types
-   * \return list of GEOM objects entries
-   */
-  static QStringList GetSelectedGeomObjects( HYDROGUI_Module* theModule,
-                                             QList<GEOM::shape_type> theTypes );
-
+  
   /**
    * \brief Find the data object with the specified name.
    * \param theModule module
@@ -349,6 +340,22 @@ public:
    * \return Image_PixMap object
    */
   static Handle(Image_PixMap)     Pixmap( const QImage& theImage );
+
+  /**
+   * \brief Get the selected GEOM objects.
+   * \param theModule the module
+   * \param theTypes the acceptable GEOM object types
+   * \return list of GEOM objects entries
+   */
+  static QStringList GetSelectedGeomObjects( HYDROGUI_Module* theModule,
+                                             QList<GEOM::shape_type> theTypes );
+
+  /**
+   * \brief Delete the GEOM objects.
+   * \param theModule the module
+   * \param theEntries the GEOM objects entries
+   */
+  static void DeleteGeomObjects( HYDROGUI_Module* theModule, const QStringList& theEntries );
 };
 
 #endif
index f6079f8ed6b72dd5685ef62af414ce7f74554a9f..573180dfad7981bc91c71a0cf5eaf576bc1593d9 100644 (file)
       <translation>icon_edit_splitted_image.png</translation>
     </message>
 
+    <message>
+      <source>RECOGNIZE_CONTOURS_ICO</source>
+      <translation>icon_recognize_contours.png</translation>
+    </message>
+
     <message>
       <source>CREATE_STREAM_BOTTOM_ICO</source>
       <translation>icon_stream_bottom_image.png</translation>
index f8b42f0ff41e81c65b4d6ceeedcd3fb727156326..26122a32e4657d3a2a47eb7494f837f0291dfbaf 100644 (file)
@@ -1434,6 +1434,19 @@ Would you like to remove all references from the image?</translation>
       <translation>Creates the new stream profiles using interpolation of selected ones</translation>
     </message>
 
+    <message>
+      <source>MEN_RECOGNIZE_CONTOURS</source>
+      <translation>Recognize contours</translation>
+    </message>
+    <message>
+      <source>DSK_RECOGNIZE_CONTOURS</source>
+      <translation>Recognize contours</translation>
+    </message>
+    <message>
+      <source>STB_RECOGNIZE_CONTOURS</source>
+      <translation>Recognize contours</translation>
+    </message>
+
   </context>
   
   <context>
@@ -2424,5 +2437,25 @@ Polyline should consist from one not closed curve.</translation>
       <translation>Can't obtain stream oject \"%1\"</translation>
     </message>
   </context>
+  
+  <context>
+    <name>HYDROGUI_RecognizeContoursDlg</name>
+    <message>
+      <source>RECOGNIZED_POLYLINES</source>
+      <translation>Recognized polylines</translation>
+    </message>
+  </context>
+
+  <context>
+    <name>HYDROGUI_RecognizeContoursOp</name>
+    <message>
+      <source>CONTOURS_RECOGNITION</source>
+      <translation>Contours recognition</translation>
+    </message>
+    <message>
+      <source>NO_DETECTED_CONTOURS</source>
+      <translation>No contours were detected.</translation>
+    </message>
+  </context>
 
 </TS>
diff --git a/src/HYDROGUI/resources/icon_recognize_contours.png b/src/HYDROGUI/resources/icon_recognize_contours.png
new file mode 100644 (file)
index 0000000..ea1e154
Binary files /dev/null and b/src/HYDROGUI/resources/icon_recognize_contours.png differ