// 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;
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 );
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,
#include <TopoDS_Shape.hxx>
+#include <BRepTools.hxx>
+
#include <SALOME_NamingService.hxx>
#include <SALOME_LifeCycleCORBA.hxx>
}
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;
+}
* \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
HYDROGUI_RiverBottomOp.h
HYDROGUI_ViewerDlg.h
HYDROGUI_ObjComboBox.h
+ HYDROGUI_RecognizeContoursDlg.h
+ HYDROGUI_RecognizeContoursOp.h
)
QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS})
HYDROGUI_RiverBottomOp.cxx
HYDROGUI_ViewerDlg.cxx
HYDROGUI_ObjComboBox.cxx
+ HYDROGUI_RecognizeContoursDlg.cxx
+ HYDROGUI_RecognizeContoursOp.cxx
)
add_definitions(
theMenu->addAction( action( CutImagesId ) );
theMenu->addAction( action( SplitImageId ) );
theMenu->addSeparator();
+ theMenu->addAction( action( RecognizeContoursId ) );
+ theMenu->addSeparator();
}
else if( anIsBathymetry )
{
#include "HYDROGUI_LocalCSOp.h"
#include "HYDROGUI_RiverBottomOp.h"
#include "HYDROGUI_ProfileInterpolateOp.h"
+#include "HYDROGUI_RecognizeContoursOp.h"
#include "HYDROGUI_SubmersibleOp.h"
#include <HYDROData_Document.h>
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,
case RiverBottomContextId:
anOp = new HYDROGUI_RiverBottomOp( aModule );
break;
+ case RecognizeContoursId:
+ anOp = new HYDROGUI_RecognizeContoursOp( aModule );
+ break;
case ShowId:
case ShowOnlyId:
case ShowAllId:
RiverBottomContextId,
ProfileInterpolateId,
+ RecognizeContoursId
SubmersibleId,
};
--- /dev/null
+// 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
--- /dev/null
+// 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
--- /dev/null
+// 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
--- /dev/null
+// 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
if ( myZLayer >= 0 )
myContext->SetZLayer( myShape, myZLayer );
- myContext->UpdateCurrentViewer();
+ if ( theIsUpdateViewer ) {
+ myContext->UpdateCurrentViewer();
+ }
}
QColor HYDROGUI_Shape::getActiveColor() const
#include <HYDROData_Tool.h>
#include <HYDROData_Profile.h>
+#include <GeometryGUI.h>
#include <GEOMBase.h>
#include <GraphicsView_Viewer.h>
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
* \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
* \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
<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>
<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>
<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>