SetToUpdate( true );
}
+void HYDROData_PolylineXY::Transform( const QTransform& theTrsf )
+{
+ NCollection_Sequence<TCollection_AsciiString> aSectNames;
+ NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
+ NCollection_Sequence<bool> aSectClosures;
+ GetSections( aSectNames, aSectTypes, aSectClosures );
+
+ for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ ) {
+ PointsList aPoints = GetPoints( i );
+ for( int j = 1, n = aPoints.Size(); j <= n; ++j ) {
+ Point& aPoint = aPoints.ChangeValue( j );
+ QPointF aTrsfPoint = theTrsf.map( QPointF( aPoint.X(), aPoint.Y() ) );
+
+ aPoint.SetX( aTrsfPoint.x() );
+ aPoint.SetY( aTrsfPoint.y() );
+ }
+ SetPoints( i, aPoints );
+ }
+
+ SetToUpdate( true );
+}
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:
RiverBottomContextId,
ProfileInterpolateId,
- RecognizeContoursId
+ RecognizeContoursId,
SubmersibleId,
ImportPolylineId,
ExportPolylineId
#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->setSortingEnabled( false );
QBoxLayout* aPolylinesLayout = new QVBoxLayout;
- aPolylinesLayout->setMargin( 5 );
- aPolylinesLayout->setSpacing( 5 );
aPolylinesLayout->addWidget( myPolylines );
aPolylinesGroup->setLayout( aPolylinesLayout );
// Layout
+ addWidget( anImageGroup );
addWidget( aPolylinesGroup );
// Conections
connect( myPolylines, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
}
+/**
+ * Destructor.
+ */
HYDROGUI_RecognizeContoursDlg::~HYDROGUI_RecognizeContoursDlg()
{
}
+/**
+ * Set the image name.
+ * \param theName the name
+ */
+void HYDROGUI_RecognizeContoursDlg::setImageName( const QString& theName )
+{
+ myImageName->setText( theName );
+}
+
+/**
+ * Reset the panel.
+ */
void HYDROGUI_RecognizeContoursDlg::reset()
{
+ myImageName->clear();
myPolylines->clear();
}
+/**
+ * Refill the list of polylines names.
+ * \param theNames the list of names
+ */
void HYDROGUI_RecognizeContoursDlg::setPolylineNames( const QStringList& theNames )
{
myPolylines->clear();
myPolylines->addItems( theNames );
}
+/**
+ * Remove the given polyline names from the list.
+ * \param theNames the list of names
+ */
+void HYDROGUI_RecognizeContoursDlg::removePolylineNames( const QStringList& theNames )
+{
+ QList<QListWidgetItem*> aFoundItems;
+
+ foreach ( const QString& aName, theNames ) {
+ aFoundItems = myPolylines->findItems( aName, Qt::MatchExactly );
+ foreach ( QListWidgetItem* anItem, aFoundItems ) {
+ anItem = myPolylines->takeItem( myPolylines->row( anItem ) );
+ delete anItem;
+ }
+ }
+}
+
+/**
+ * Select the given polyline names in the list.
+ * \param theNames the list of names
+ */
void HYDROGUI_RecognizeContoursDlg::setSelectedPolylineNames( const QStringList& theNames )
{
myPolylines->clearSelection();
}
}
+/**
+ * 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;
#include "HYDROGUI_InputPanel.h"
class QListWidget;
+class QLineEdit;
class HYDROGUI_RecognizeContoursDlg : public HYDROGUI_InputPanel
{
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& );
void onItemSelectionChanged();
private:
+ QLineEdit* myImageName;
QListWidget* myPolylines;
};
{
HYDROGUI_Operation::startOperation();
+ if ( !isApplyAndClose() ) {
+ return;
+ }
+
// Get the selected image
myImage = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
if ( myImage.IsNull() ) {
abort();
return;
}
+ QString anImageName = myImage->GetName();
// Create temporary graphics file
QImage aQImage = myImage->Image();
- myTmpImageFile = new QTemporaryFile( myImage->GetName() );
+ myTmpImageFile = new QTemporaryFile( anImageName );
if ( !myTmpImageFile->open() ||
!aQImage.save( myTmpImageFile->fileName(), "PNG", 100 ) ) {
abort();
// Reset the panel
aPanel->reset();
+ aPanel->setImageName( anImageName );
// Get active study
SalomeApp_Study* aStudy =
QString aGeomPictureEntry;
- HYDROData_GeomTool::createFaceInGEOM(
- aGeomEngine, aDSStudy, aQImage.width(), aQImage.height(), myImage->GetName(), aGeomPictureEntry );
+ HYDROData_GeomTool::createFaceInGEOM( aGeomEngine, aDSStudy, aQImage.width(), aQImage.height(),
+ anImageName, aGeomPictureEntry );
if ( !aGeomPictureEntry.isEmpty() ) {
aStudy->setObjectProperty( aViewMgr->getGlobalId(), aGeomPictureEntry,
*/
void HYDROGUI_RecognizeContoursOp::commitOperation()
{
- cleanup();
+ if ( isApplyAndClose() ) {
+ cleanup();
+ }
HYDROGUI_Operation::commitOperation();
}
QString& theErrorMsg,
QStringList& theBrowseObjectsEntries )
{
+ // Check the original image
+ if ( myImage.IsNull() ) {
+ return false;
+ }
+
// Get panel
HYDROGUI_RecognizeContoursDlg* aPanel =
::qobject_cast<HYDROGUI_RecognizeContoursDlg*>( inputPanel() );
return false;
}
+ // Get selected polylines
+ QStringList aSelectedtPolylines = aPanel->getSelectedtPolylineNames();
+ // Remove the selected polylines from the panel
+ aPanel->removePolylineNames( aSelectedtPolylines );
+
// Create polylines
- foreach ( QString aName, aPanel->getSelectedtPolylineNames() ) {
+ foreach ( QString aName, aSelectedtPolylines ) {
TopoDS_Shape aShape = myPolylineShapes.value( aName )->getTopoShape();
if ( aShape.IsNull() ) {
continue;
aPolylineObj->SetName( aName );
aPolylineObj->ImportShape( aShape );
aPolylineObj->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
+ aPolylineObj->Transform( myImage->Trsf() );
+
aPolylineObj->Update();
module()->setIsToUpdate( aPolylineObj );
}
+
+ // Remove the shape from the map
+ HYDROGUI_Shape* aShapeToDelete = myPolylineShapes.take( aName );
+ delete aShapeToDelete;
}
-
+
theUpdateFlags = UF_Model;
return true;
}
}
+ QStringList aNamesList;
for ( int i = 1; i <= aSubShapes.Length(); i++ ) {
const TopoDS_Shape& aSubShape = aSubShapes.Value( i );
HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
aShape->setShape( aSubShape, true, false );
+ aShape->setBorderColor( HYDROData_PolylineXY::DefaultWireColor(), false, false );
QString aPrefix = QString("%1_%2_%3").arg( myImage->GetName(), "Contour", QString::number( i ) );
QString aName = HYDROGUI_Tool::GenerateObjectName( module(), aPrefix, QStringList(), true );
myPolylineShapes.insert( aName, aShape);
+ aNamesList << aName;
}
- if ( !aCtx.IsNull() ) { //@MZN
+ if ( !aCtx.IsNull() ) {
aCtx->UpdateCurrentViewer();
}
HYDROGUI_RecognizeContoursDlg* aPanel =
::qobject_cast<HYDROGUI_RecognizeContoursDlg*>( inputPanel() );
if ( aPanel ) {
- aPanel->setPolylineNames( myPolylineShapes.keys() );
+ aPanel->setPolylineNames( aNamesList );
}
}
}
<context>
<name>HYDROGUI_RecognizeContoursDlg</name>
+ <message>
+ <source>NAME</source>
+ <translation>Name</translation>
+ </message>
+ <message>
+ <source>ORIGINAL_IMAGE</source>
+ <translation>Original image</translation>
+ </message>
<message>
<source>RECOGNIZED_POLYLINES</source>
- <translation>Recognized polylines</translation>
+ <translation>Polylines</translation>
</message>
</context>