From: mzn Date: Mon, 25 May 2015 07:31:07 +0000 (+0300) Subject: refs #524: draft implementation of "Recognize contours" operation. X-Git-Tag: v1.4.1~7^2~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fdd7dcde36312e41d8ffb63ec58a77567e8592ef;p=modules%2Fhydro.git refs #524: draft implementation of "Recognize contours" operation. --- diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index ec18b345..56f5259a 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -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 ); diff --git a/src/HYDROData/HYDROData_CalculationCase.h b/src/HYDROData/HYDROData_CalculationCase.h index 35d51d10..b03806b1 100644 --- a/src/HYDROData/HYDROData_CalculationCase.h +++ b/src/HYDROData/HYDROData_CalculationCase.h @@ -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, diff --git a/src/HYDROData/HYDROData_GeomTool.cxx b/src/HYDROData/HYDROData_GeomTool.cxx index 10c0bf4c..a83258e6 100644 --- a/src/HYDROData/HYDROData_GeomTool.cxx +++ b/src/HYDROData/HYDROData_GeomTool.cxx @@ -20,6 +20,8 @@ #include +#include + #include #include @@ -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; +} diff --git a/src/HYDROData/HYDROData_GeomTool.h b/src/HYDROData/HYDROData_GeomTool.h index ea4cb95d..554aede3 100644 --- a/src/HYDROData/HYDROData_GeomTool.h +++ b/src/HYDROData/HYDROData_GeomTool.h @@ -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 diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 41311f79..18acca61 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -110,6 +110,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}) @@ -223,6 +225,8 @@ set(PROJECT_SOURCES HYDROGUI_RiverBottomOp.cxx HYDROGUI_ViewerDlg.cxx HYDROGUI_ObjComboBox.cxx + HYDROGUI_RecognizeContoursDlg.cxx + HYDROGUI_RecognizeContoursOp.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 1ed020f8..4147c74c 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -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 ) { diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index ce02c32f..0f30b561 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -55,6 +55,7 @@ #include "HYDROGUI_LocalCSOp.h" #include "HYDROGUI_RiverBottomOp.h" #include "HYDROGUI_ProfileInterpolateOp.h" +#include "HYDROGUI_RecognizeContoursOp.h" #include "HYDROGUI_SubmersibleOp.h" #include @@ -165,6 +166,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, @@ -518,6 +521,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: diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index 5362e538..b9f8ab9f 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -107,6 +107,7 @@ enum OperationId RiverBottomContextId, ProfileInterpolateId, + RecognizeContoursId SubmersibleId, }; diff --git a/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.cxx b/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.cxx new file mode 100644 index 00000000..bc12c51e --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.cxx @@ -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 +#include +#include + + +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 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 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 index 00000000..acfd53b4 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_RecognizeContoursDlg.h @@ -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 index 00000000..bc912b8a --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx @@ -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 +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +/** + 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( inputPanel() ); + if ( !aPanel ) { + return; + } + + // Reset the panel + aPanel->reset(); + + // Get active study + SalomeApp_Study* aStudy = + dynamic_cast( 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( 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 aDialogs = aDesktop->findChildren(); + 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( 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( + 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( 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( 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 index 00000000..dfe7b98f --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.h @@ -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 + +#include +#include + +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 myPolylineShapes; ///< the detected polylines shapes map (key: name, value: shape) +}; + +#endif \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index f9799da5..b837ec30 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -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 diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 568ffb1c..7370fa31 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -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( 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 diff --git a/src/HYDROGUI/HYDROGUI_Tool.h b/src/HYDROGUI/HYDROGUI_Tool.h index 60600a54..4ea4039e 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.h +++ b/src/HYDROGUI/HYDROGUI_Tool.h @@ -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 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 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 diff --git a/src/HYDROGUI/resources/HYDROGUI_images.ts b/src/HYDROGUI/resources/HYDROGUI_images.ts index f6079f8e..573180df 100644 --- a/src/HYDROGUI/resources/HYDROGUI_images.ts +++ b/src/HYDROGUI/resources/HYDROGUI_images.ts @@ -391,6 +391,11 @@ icon_edit_splitted_image.png + + RECOGNIZE_CONTOURS_ICO + icon_recognize_contours.png + + CREATE_STREAM_BOTTOM_ICO icon_stream_bottom_image.png diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 08446e0e..cf339712 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -1422,6 +1422,19 @@ Would you like to remove all references from the image? Creates the new stream profiles using interpolation of selected ones + + MEN_RECOGNIZE_CONTOURS + Recognize contours + + + DSK_RECOGNIZE_CONTOURS + Recognize contours + + + STB_RECOGNIZE_CONTOURS + Recognize contours + + @@ -2384,5 +2397,25 @@ Polyline should consist from one not closed curve. Can't obtain stream oject \"%1\" + + + HYDROGUI_RecognizeContoursDlg + + RECOGNIZED_POLYLINES + Recognized polylines + + + + + HYDROGUI_RecognizeContoursOp + + CONTOURS_RECOGNITION + Contours recognition + + + NO_DETECTED_CONTOURS + No contours were detected. + + diff --git a/src/HYDROGUI/resources/icon_recognize_contours.png b/src/HYDROGUI/resources/icon_recognize_contours.png new file mode 100644 index 00000000..ea1e1549 Binary files /dev/null and b/src/HYDROGUI/resources/icon_recognize_contours.png differ