// 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( HYDROData_CalculationCase::DataTag theDataTag,
const bool theIsSetToUpdate )
{
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
SetToUpdate( true );
}
+void HYDROData_PolylineXY::Transform( const QTransform& theTrsf )
+{
+ NCollection_Sequence<TCollection_AsciiString> aSectNames;
+ NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
+ NCollection_Sequence<bool> aSectClosures;
+ GetSections( aSectNames, aSectTypes, aSectClosures );
+
+ for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ ) {
+ PointsList aPoints = GetPoints( i );
+ for( int j = 1, n = aPoints.Size(); j <= n; ++j ) {
+ Point& aPoint = aPoints.ChangeValue( j );
+
+ QPointF aTrsfPoint = theTrsf.map( QPointF( aPoint.X(), aPoint.Y() ) );
+ aPoint.SetX( aTrsfPoint.x() );
+ aPoint.SetY( aTrsfPoint.y() );
+ }
+ SetPoints( i, aPoints );
+ }
+
+ Update();
+}
DEFINE_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline)
class QPainterPath;
+class QTransform;
class TopoDS_Wire;
class gp_XYZ;
*/
HYDRODATA_EXPORT virtual QPainterPath GetPainterPath() const;
+ /**
+ * Transform the polyline points.
+ * @param theTrsf the transformation
+ */
+ HYDRODATA_EXPORT void Transform( const QTransform& theTrsf );
protected:
HYDROGUI_DataModel.h
HYDROGUI_DataModelSync.h
HYDROGUI_DataObject.h
+ HYDROGUI_DataOwner.h
HYDROGUI_DeleteDlg.h
HYDROGUI_DeleteOp.h
HYDROGUI_DigueDlg.h
HYDROGUI_RiverBottomOp.h
HYDROGUI_ViewerDlg.h
HYDROGUI_ObjComboBox.h
+ HYDROGUI_RecognizeContoursDlg.h
+ HYDROGUI_RecognizeContoursOp.h
)
QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS})
HYDROGUI_DataModel.cxx
HYDROGUI_DataModelSync.cxx
HYDROGUI_DataObject.cxx
+ HYDROGUI_DataOwner.cxx
HYDROGUI_DeleteDlg.cxx
HYDROGUI_DeleteOp.cxx
HYDROGUI_DigueDlg.cxx
HYDROGUI_RiverBottomOp.cxx
HYDROGUI_ViewerDlg.cxx
HYDROGUI_ObjComboBox.cxx
+ HYDROGUI_RecognizeContoursDlg.cxx
+ HYDROGUI_RecognizeContoursOp.cxx
)
add_definitions(
: HYDROGUI_Operation( theModule ),
myIsEdit( theIsEdit ),
myActiveViewManager( NULL ),
- myPreviewViewManager( NULL )
+ myPreviewViewManager( NULL ),
+ myShowGeomObjects( true ),
+ myShowZones( false )
{
setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
}
connect( aPanel, SIGNAL( orderLandCoverChanged( bool& ) ), SLOT( onOrderLandCoverChanged( bool& ) ) );
connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
- connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) );
+ connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onBack( const int ) ) );
//connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
return;
QApplication::setOverrideCursor( Qt::WaitCursor );
+
+ setGeomObjectsVisible( false );
QString aNewCaseName = aPanel->getObjectName();
QString anOldCaseName = myEditedObject->GetName();
}
}
-void HYDROGUI_CalculationOp::onHideZones()
+void HYDROGUI_CalculationOp::onBack( const int theIndex )
{
+ setGeomObjectsVisible( theIndex != 2 );
setZonesVisible( false );
}
}
}
+void HYDROGUI_CalculationOp::setGeomObjectsVisible( bool theIsVisible )
+{
+ myShowGeomObjects = theIsVisible;
+
+ HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
+
+ HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
+ for ( ; anIter.More(); anIter.Next() ) {
+ setObjectVisibility( anIter.Value(), theIsVisible );
+ }
+}
+
void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
{
HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
void HYDROGUI_CalculationOp::createPreview()
{
LightApp_Application* anApp = module()->getApp();
- HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
+ HYDROData_SequenceOfObjects aSeq;
+ if ( myShowGeomObjects ) {
+ aSeq.Append( myEditedObject->GetGeometryObjects() );
+ }
Handle(HYDROData_Entity) anEntity;
if ( myShowZones )
*/
void onClickedInZonesBrowser( SUIT_DataObject* theItem );
/**
- * Hide zones in the viewer.
+ * Slot called on back button click.
*/
- void onHideZones();
+ void onBack( const int );
/**
* Geometry object is selected in the list on the first wizard page
*/
void closePreview();
void setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible );
void setZonesVisible( bool theIsVisible );
+ void setGeomObjectsVisible( bool theIsVisible );
void getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
QStringList& theNames, QStringList& theEntries ) const;
private:
bool myIsEdit;
bool myShowZones;
+ bool myShowGeomObjects;
Handle(HYDROData_CalculationCase) myEditedObject;
SUIT_ViewManager* myActiveViewManager;
if ( visibility )
{
- SUIT_AbstractModel* treeModel = 0;
- LightApp_Application* app = dynamic_cast<LightApp_Application*>( module()->application() );
- if ( app )
- treeModel = dynamic_cast<SUIT_AbstractModel*>( app->objectBrowser()->model() );
-
- if ( treeModel )
- {
- HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
- bool isVisible = aModule->isObjectVisible( -1, theModelObject );
- Qtx::VisibilityState aVisState = isVisible ? Qtx::ShownState : Qtx::HiddenState;
- treeModel->setVisibilityState( aResObj->text( aResObj->customData( Qtx::IdType ).toInt() ), aVisState, false );
- }
+ setObjectVisibilityState( theModelObject, aResObj );
}
if ( theIsBuildTree )
const bool theIsBuildTree,
const bool theIsInOperation )
{
- return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation ),
- theParentEntry, theIsBuildTree, theIsInOperation );
+ HYDROGUI_Zone* aZone = new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation );
+ LightApp_DataObject* aDataObj = buildObject( theParent, aZone, theParentEntry, theIsBuildTree, theIsInOperation );
+
+ setObjectVisibilityState( theModelObject, aZone );
+
+ return aDataObj;
}
LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent,
}
return true;
}
+
+void HYDROGUI_DataModel::setObjectVisibilityState( Handle(HYDROData_Entity) theModelObject,
+ HYDROGUI_DataObject* theObject )
+{
+ SUIT_AbstractModel* treeModel = 0;
+ LightApp_Application* app = dynamic_cast<LightApp_Application*>( module()->application() );
+ if ( app )
+ treeModel = dynamic_cast<SUIT_AbstractModel*>( app->objectBrowser()->model() );
+
+ if ( treeModel )
+ {
+ HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
+ bool isVisible = aModule->isObjectVisible( -1, theModelObject );
+ Qtx::VisibilityState aVisState = isVisible ? Qtx::ShownState : Qtx::HiddenState;
+ treeModel->setVisibilityState( theObject->text( theObject->customData( Qtx::IdType ).toInt() ), aVisState, false );
+ }
+}
static SUIT_DataObject* findChildByName( const SUIT_DataObject* theFather,
const QString& theName );
+ /**
+ * Set object visibility state.
+ * \param theModelObject the data model object
+ * \param theDataObject the GUI object
+ */
+ void setObjectVisibilityState( Handle(HYDROData_Entity) theModelObject,
+ HYDROGUI_DataObject* theObject );
+
+
protected:
QString myStudyURL; ///< the saved/opened document URL
QByteArray myStates;
--- /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_DataOwner.h"
+
+
+HYDROGUI_DataOwner::HYDROGUI_DataOwner()
+{
+}
+
+HYDROGUI_DataOwner::HYDROGUI_DataOwner( const Handle(AIS_InteractiveObject)& theIO ):
+ myIO(theIO)
+{
+}
+
+HYDROGUI_DataOwner::~HYDROGUI_DataOwner()
+{
+}
+
+QString HYDROGUI_DataOwner::keyString() const
+{
+ QString aKey;
+
+ if ( !myIO.IsNull() ) {
+ aKey = QString().sprintf( "%08p", myIO.operator->() );
+ }
+
+ return aKey;
+}
+
+const Handle(AIS_InteractiveObject)& HYDROGUI_DataOwner::IO() const
+{
+ return myIO;
+}
--- /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_DATAOWNER_H
+#define HYDROGUI_DATAOWNER_H
+
+#include <SUIT_DataOwner.h>
+
+#include <AIS_InteractiveObject.hxx>
+
+
+/*!
+ This class provide data owner objects.
+*/
+class HYDROGUI_DataOwner : public SUIT_DataOwner
+{
+public:
+ /**
+ * Constructor. Initialize by \a AIS_InteractiveObject.
+ */
+ HYDROGUI_DataOwner( const Handle(AIS_InteractiveObject)& theIO );
+
+ /**
+ * Constructor.
+ */
+ HYDROGUI_DataOwner();
+
+ /**
+ * Destructor.
+ */
+ virtual ~HYDROGUI_DataOwner();
+
+ /**
+ * Gets key string, used for data owners comparison.
+ * \return the empty string
+ */
+ virtual QString keyString() const;
+
+ /**
+ * Gets SALOME_InteractiveObject.
+ * \return the SALOME interactive object
+ */
+ const Handle(AIS_InteractiveObject)& IO() const;
+
+private:
+ Handle(AIS_InteractiveObject) myIO; ///< the AIS interactive object
+};
+
+typedef SMART(HYDROGUI_DataOwner) HYDROGUI_DataOwnerPtr;
+
+#endif
theMenu->addAction( action( CutImagesId ) );
theMenu->addAction( action( SplitImageId ) );
theMenu->addSeparator();
+ theMenu->addAction( action( RecognizeContoursId ) );
+ theMenu->addSeparator();
}
else if( anIsBathymetry )
{
#include "HYDROGUI_DataModel.h"
#include "HYDROGUI_DataObject.h"
+#include "HYDROGUI_DataOwner.h"
#include "HYDROGUI_Module.h"
#include <AIS_ListOfInteractive.hxx>
for ( AIS_ListIteratorOfListOfInteractive anIt( aSelList ); anIt.More(); anIt.Next() )
if ( !anIt.Value().IsNull() )
{
- if ( !isLocalContext )
- aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( entry( anIt.Value() ) ) ) );
+ if ( !isLocalContext ) {
+ QString anEntry = entry( anIt.Value() );
+ if ( !anEntry.isEmpty() ) {
+ aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( entry( anIt.Value() ) ) ) );
+ } else {
+ aList.append( SUIT_DataOwnerPtr( new HYDROGUI_DataOwner( anIt.Value() ) ) );
+ }
+ }
}
// add externally selected objects
SUIT_DataOwnerPtrList::const_iterator anExtIter;
return;
Handle(AIS_InteractiveContext) aContext = aViewer->getAISContext();
- if ( aContext->HasOpenedContext() ) {
+ if ( aContext.IsNull() || aContext->HasOpenedContext() ) {
return;
}
- LightApp_OCCSelector::setSelection( aList );
+ QMap<QString, Handle(AIS_InteractiveObject)> aDisplayed;
+ AIS_ListOfInteractive aDispList, aSelList;
+ aContext->DisplayedObjects( aDispList );
+
+ for ( AIS_ListIteratorOfListOfInteractive it( aDispList ); it.More(); it.Next() )
+ {
+ QString entryStr = entry( it.Value() );
+ if ( !entryStr.isEmpty() )
+ aDisplayed.insert( entryStr, it.Value() );
+ }
+
+ mySelectedExternals.clear();
+
+ for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
+ {
+ const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
+ if ( owner && aDisplayed.contains( owner->entry() ) )
+ aSelList.Append( aDisplayed[owner->entry()] );
+ else {
+ const HYDROGUI_DataOwner* hydroOwner = dynamic_cast<const HYDROGUI_DataOwner*>( (*itr).operator->() );
+ if ( hydroOwner && !hydroOwner->IO().IsNull() ) {
+ aSelList.Append( hydroOwner->IO() );
+ } else
+ mySelectedExternals.append(*itr);
+ }
+ }
+
+ aViewer->unHighlightAll( false );
+ aViewer->setObjectsSelected( aSelList );
}
QString HYDROGUI_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS ) const
#include "HYDROGUI_LocalCSOp.h"
#include "HYDROGUI_RiverBottomOp.h"
#include "HYDROGUI_ProfileInterpolateOp.h"
+#include "HYDROGUI_RecognizeContoursOp.h"
#include "HYDROGUI_SubmersibleOp.h"
#include "HYDROGUI_StricklerTableOp.h"
#include "HYDROGUI_DuplicateOp.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,
ImportPolylineId,
ExportPolylineId,
--- /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 <QLabel>
+#include <QLineEdit>
+#include <QListWidget>
+#include <QVBoxLayout>
+
+/**
+ * Constructor.
+ * \param theModule the module
+ * \param theTitle the panel title
+ */
+HYDROGUI_RecognizeContoursDlg::HYDROGUI_RecognizeContoursDlg( HYDROGUI_Module* theModule, const QString& theTitle )
+: HYDROGUI_InputPanel( theModule, theTitle )
+{
+ // Original image
+ QGroupBox* anImageGroup = new QGroupBox( tr( "ORIGINAL_IMAGE" ), mainFrame() );
+ QLabel* aNameLabel = new QLabel( tr("NAME") );
+ myImageName = new QLineEdit;
+ myImageName->setReadOnly( true );
+
+ QHBoxLayout* anImageLayout = new QHBoxLayout();
+ anImageLayout->addWidget( aNameLabel );
+ anImageLayout->addWidget( myImageName );
+ anImageGroup->setLayout( anImageLayout );
+
+ // List of recognized polylines
+ QGroupBox* aPolylinesGroup = new QGroupBox( tr( "RECOGNIZED_POLYLINES" ), mainFrame() );
+ myPolylines = new QListWidget( aPolylinesGroup );
+ myPolylines->setSelectionMode( QListWidget::ExtendedSelection );
+ myPolylines->setEditTriggers( QListWidget::NoEditTriggers );
+ myPolylines->setViewMode( QListWidget::ListMode );
+ myPolylines->setSortingEnabled( false );
+
+ QBoxLayout* aPolylinesLayout = new QVBoxLayout;
+ aPolylinesLayout->addWidget( myPolylines );
+ aPolylinesGroup->setLayout( aPolylinesLayout );
+
+ // Layout
+ addWidget( anImageGroup );
+ addWidget( aPolylinesGroup );
+
+ // Conections
+ connect( myPolylines, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
+}
+
+/**
+ * Destructor.
+ */
+HYDROGUI_RecognizeContoursDlg::~HYDROGUI_RecognizeContoursDlg()
+{
+}
+
+/**
+ * Set the image name.
+ * \param theName the name
+ */
+void HYDROGUI_RecognizeContoursDlg::setImageName( const QString& theName )
+{
+ myImageName->setText( theName );
+}
+
+/**
+ * Reset the panel.
+ */
+void HYDROGUI_RecognizeContoursDlg::reset()
+{
+ myImageName->clear();
+ myPolylines->clear();
+}
+
+/**
+ * Refill the list of polylines names.
+ * \param theNames the list of names
+ */
+void HYDROGUI_RecognizeContoursDlg::setPolylineNames( const QStringList& theNames )
+{
+ myPolylines->clear();
+ myPolylines->addItems( theNames );
+}
+
+/**
+ * Remove the given polyline names from the list.
+ * \param theNames the list of names
+ */
+void HYDROGUI_RecognizeContoursDlg::removePolylineNames( const QStringList& theNames )
+{
+ QList<QListWidgetItem*> aFoundItems;
+
+ foreach ( const QString& aName, theNames ) {
+ aFoundItems = myPolylines->findItems( aName, Qt::MatchExactly );
+ foreach ( QListWidgetItem* anItem, aFoundItems ) {
+ anItem = myPolylines->takeItem( myPolylines->row( anItem ) );
+ delete anItem;
+ }
+ }
+}
+
+/**
+ * Select the given polyline names in the list.
+ * \param theNames the list of names
+ */
+void HYDROGUI_RecognizeContoursDlg::setSelectedPolylineNames( const QStringList& theNames )
+{
+ myPolylines->clearSelection();
+
+ foreach( const QString aName, theNames ) {
+ QList<QListWidgetItem*> anItems = myPolylines->findItems( aName, Qt::MatchExactly );
+ if ( anItems.count() == 1 ) {
+ anItems.first()->setSelected( true );
+ }
+ }
+}
+
+/**
+ * Slot called when polyline names selection changed.
+ */
+void HYDROGUI_RecognizeContoursDlg::onItemSelectionChanged()
+{
+ emit selectionChanged( getSelectedtPolylineNames() );
+}
+
+/**
+ * Get the list of selected polyline names.
+ * \return the list of names
+ */
+QStringList HYDROGUI_RecognizeContoursDlg::getSelectedtPolylineNames() const
+{
+ QStringList aSelectedNames;
+
+ 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 QLineEdit;
+
+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 setImageName( const QString& theName );
+
+ void reset();
+
+ void setPolylineNames( const QStringList& theNames );
+ void removePolylineNames( const QStringList& theNames );
+
+ void setSelectedPolylineNames( const QStringList& theNames );
+
+ QStringList getSelectedtPolylineNames() const;
+
+signals:
+ void selectionChanged( const QStringList& );
+
+public slots:
+ void onItemSelectionChanged();
+
+private:
+ QLineEdit* myImageName;
+ 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 "HYDROGUI_OCCSelector.h"
+#include "HYDROGUI_ZLayers.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 <BRepBuilderAPI_GTransform.hxx>
+#include <gp_GTrsf.hxx>
+
+#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();
+
+ // Set preview view manager
+ if ( !getPreviewManager() ) {
+ setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
+ module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
+ }
+
+ if ( !isApplyAndClose() ) {
+ return;
+ }
+
+ // Get the selected image
+ myImage = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+ if ( myImage.IsNull() ) {
+ abort();
+ return;
+ }
+ QString anImageName = myImage->GetName();
+
+ // Create temporary graphics file
+ QImage aQImage = myImage->Image();
+ myTmpImageFile = new QTemporaryFile( anImageName );
+ 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();
+ aPanel->setImageName( anImageName );
+
+ // 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(),
+ anImageName, 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()
+{
+ if ( isApplyAndClose() ) {
+ cleanup();
+ }
+
+ HYDROGUI_Operation::commitOperation();
+}
+
+/**
+*/
+bool HYDROGUI_RecognizeContoursOp::processApply( int& theUpdateFlags,
+ QString& theErrorMsg,
+ QStringList& theBrowseObjectsEntries )
+{
+ // Check the original image
+ if ( myImage.IsNull() ) {
+ return false;
+ }
+
+ // Get panel
+ HYDROGUI_RecognizeContoursDlg* aPanel =
+ ::qobject_cast<HYDROGUI_RecognizeContoursDlg*>( inputPanel() );
+ if ( !aPanel ) {
+ return false;
+ }
+
+ // Check if contour GEOM object exists
+ if ( myGeomContourEntry.isEmpty() ) {
+ theErrorMsg = tr( "NO_DETECTED_CONTOURS" );
+ return false;
+ }
+
+ // Get selected polylines
+ QStringList aSelectedtPolylines = aPanel->getSelectedtPolylineNames();
+ // Remove the selected polylines from the panel
+ aPanel->removePolylineNames( aSelectedtPolylines );
+
+ // Create polylines
+ foreach ( QString aName, aSelectedtPolylines ) {
+ 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 );
+ }
+
+ // Remove the shape from the map
+ HYDROGUI_Shape* aShapeToDelete = myPolylineShapes.take( aName );
+ delete aShapeToDelete;
+ }
+
+ 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
+ OCCViewer_ViewManager* aViewManager = getPreviewManager();
+ if ( aViewManager ) {
+ if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
+ // aViewer->enablePreselection( true );
+ // aViewer->enableSelection( true );
+ aCtx = aViewer->getAISContext();
+ connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
+ }
+ }
+
+ QTransform aTrsf = myImage->Trsf();
+ QImage anImage = myImage->Image();
+ QRectF aRect( QPointF( 0, 0 ), QPointF( anImage.width(), anImage.height() ) );
+ aRect = aTrsf.mapRect( aRect );
+ aTrsf.setMatrix( aTrsf.m11(), aTrsf.m12(), aTrsf.m13(),
+ aTrsf.m21(), -aTrsf.m22(), aTrsf.m23(),
+ aTrsf.m31() + aRect.width() * 0.5, aTrsf.m32 () - aRect.height() * 0.5, aTrsf.m33() );
+
+ /*
+ QTransform aTrsf = myImage->Trsf();
+ gp_Mat aMat( aTrsf.m11(), aTrsf.m21(), 0,
+ aTrsf.m12(), -aTrsf.m22(), 0,
+ 0, 0, 1 );
+ QImage anImage = myImage->Image();
+ QRectF aRect( QPointF( 0, 0 ), QPointF( anImage.width(), anImage.height() ) );
+ aRect = aTrsf.mapRect( aRect );
+ gp_XYZ aVec( aTrsf.m31() + aRect.width() * 0.5,
+ aTrsf.m32() - aRect.height() * 0.5, 0 );
+
+ BRepBuilderAPI_GTransform aBuilder( gp_GTrsf( aMat, aVec ) );
+ */
+
+ Handle(HYDROData_PolylineXY) aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) );
+ QStringList aNamesList;
+ for ( int i = 1; i <= aSubShapes.Length(); i++ ) {
+ TopoDS_Shape aSubShape = aSubShapes.Value( i );
+
+ // Transform the sub-shape
+ aPolylineObj->ImportShape( aSubShape );
+ aPolylineObj->Transform( aTrsf );
+
+ /*
+ aBuilder.Perform( aSubShape, Standard_True );
+ if ( aBuilder.IsDone() ) {
+ aSubShape = aBuilder.Shape();
+ }*/
+
+ HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
+ aShape->setShape( aPolylineObj->GetShape(), true, false );
+ aShape->setBorderColor( HYDROData_PolylineXY::DefaultWireColor(), false, false );
+
+ QString aPrefix = QString("%1_%2_%3").arg( myImage->GetName(), "Contour", QString::number( i ) );
+ QString aName = HYDROGUI_Tool::GenerateObjectName( module(), aPrefix, QStringList(), true );
+ myPolylineShapes.insert( aName, aShape);
+ aNamesList << aName;
+ }
+
+ aPolylineObj->Remove();
+
+ if ( !aCtx.IsNull() ) {
+ UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, Graphic3d_ZLayerId_TopOSD );
+ aCtx->UpdateCurrentViewer();
+ }
+
+ // Get panel
+ HYDROGUI_RecognizeContoursDlg* aPanel =
+ ::qobject_cast<HYDROGUI_RecognizeContoursDlg*>( inputPanel() );
+ if ( aPanel ) {
+ aPanel->setPolylineNames( aNamesList );
+ }
+ }
+}
+
+/**
+ 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 )
+{
+ Handle(AIS_InteractiveContext) aCtx = NULL;
+
+ OCCViewer_ViewManager* aViewManager = getPreviewManager();
+ if ( aViewManager ) {
+ if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
+ aCtx = aViewer->getAISContext();
+ }
+ }
+
+ if ( !aCtx.IsNull() ) {
+ foreach ( QString aName, myPolylineShapes.keys() ) {
+ Handle(AIS_InteractiveObject) anObject =
+ myPolylineShapes.value(aName)->getAISObject();
+
+ bool isSelected = theSelectedNames.contains( aName );
+ if ( ( isSelected && !aCtx->IsSelected( anObject) ) ||
+ ( !isSelected && aCtx->IsSelected( anObject) ) ) {
+ aCtx->AddOrRemoveSelected( anObject, Standard_False );
+ }
+ // myPolylineShapes[aName]->highlight( isSelected, true );
+ }
+ aCtx->UpdateCurrentViewer();
+ }
+}
+
+/**
+ 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.value(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
void HYDROGUI_Shape::setBorderColor( const QColor& theColor,
const bool theToDisplay,
const bool theIsUpdateViewer )
-{
+{
myBorderColor = theColor;
updateShape( theToDisplay, theIsUpdateViewer );
}
Handle_AIS_InteractiveObject HYDROGUI_Shape::createShape() const
{
- if( myTopoShape.IsNull() )
+ if( myTopoShape.IsNull() ) {
return Handle_AIS_InteractiveObject();
-
+ }
+
TopAbs_ShapeEnum aShapeType = myTopoShape.ShapeType();
- if ( aShapeType==TopAbs_EDGE || aShapeType==TopAbs_WIRE ) {
+ bool IsWireEdgeCompound = aShapeType==TopAbs_COMPOUND;
+ if (IsWireEdgeCompound) {
+ TopoDS_Iterator itr(myTopoShape);
+ while (itr.More() && IsWireEdgeCompound) {
+ if (itr.Value().ShapeType() != TopAbs_WIRE && itr.Value().ShapeType() != TopAbs_EDGE)
+ IsWireEdgeCompound = false;
+ itr.Next();
+ }
+ }
+
+ if ( aShapeType==TopAbs_EDGE || aShapeType==TopAbs_WIRE || IsWireEdgeCompound) {
return new HYDROGUI_Polyline( myTopoShape );
} else {
return new AIS_Shape( myTopoShape );
if ( myZLayer >= 0 )
myContext->SetZLayer( myShape, myZLayer );
- myContext->UpdateCurrentViewer();
+ if ( theIsUpdateViewer ) {
+ myContext->UpdateCurrentViewer();
+ }
}
QColor HYDROGUI_Shape::getActiveColor() const
#include <HYDROData_Profile.h>
#include <HYDROData_LandCover.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 );
+ }
+ }
+}
* \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
theViewer->GetAllZLayers( anExistingZLayers );
int n = anExistingZLayers.Length();
- myZLayers.resize( n );
- for( int i=1; i<=n; i++ )
- myZLayers[i-1] = anExistingZLayers( i );
+ for( int i=1; i<=n; i++ ) {
+ int aLayerId = anExistingZLayers( i );
+ if ( aLayerId >= 0 ) {
+ myZLayers.push_back( aLayerId );
+ }
+ }
myIndex = 0;
}
#include <AIS_InteractiveObject.hxx>
#include <AIS_ListOfInteractive.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
+#include <AIS_Trihedron.hxx>
#include <PrsMgr_PresentationManager3d.hxx>
void UpdateZLayersOfHilightPresentationsOfDisplayedObjects( const Handle_AIS_InteractiveContext& theContext,
for ( ; aListIter.More(); aListIter.Next() )
{
Handle(AIS_InteractiveObject) aPrsObj = aListIter.Value();
- if( !aPrsObj.IsNull() )
+ if( !aPrsObj.IsNull() && !aPrsObj->IsKind( STANDARD_TYPE(AIS_Trihedron) ) )
{
int aMode = aPrsObj->HasHilightMode() ? aPrsObj->HilightMode() : 0;
theContext->MainPrsMgr()->Color( aPrsObj, Quantity_NOC_YELLOW, aMode );
<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>NAME</source>
+ <translation>Name</translation>
+ </message>
+ <message>
+ <source>ORIGINAL_IMAGE</source>
+ <translation>Original image</translation>
+ </message>
+ <message>
+ <source>RECOGNIZED_POLYLINES</source>
+ <translation>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>