refs #324 - Point C is shown in reference image, however it isn't checked Import image dockable panel
myImageName->clear();
myImageNameGroup->setEnabled( false );
myGeoFileName->clear();
+ bool isPBlocked = blockSignalsPoints( true );
+ bool isGBlocked = blockSignalsGeodesic( true );
+ bool isCBlocked = blockSignalsCartesian( true );
for( int aPointType = HYDROGUI_PrsImage::PointA;
aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
{
aBtn->setChecked( false );
aBtn->blockSignals( anIsBlocked );
- myPointXMap[ aPointType ]->clear();
- myPointYMap[ aPointType ]->clear();
- myPointXDegMap[ aPointType ]->clear();
- myPointYDegMap[ aPointType ]->clear();
- myPointXMinMap[ aPointType ]->clear();
- myPointYMinMap[ aPointType ]->clear();
- myPointXSecMap[ aPointType ]->clear();
- myPointYSecMap[ aPointType ]->clear();
+ clearSpins( myPointXMap[ aPointType ] );
+ clearSpins( myPointYMap[ aPointType ] );
+ clearSpins( myPointXDegMap[ aPointType ] );
+ clearSpins( myPointYDegMap[ aPointType ] );
+ clearSpins( myPointXMinMap[ aPointType ] );
+ clearSpins( myPointYMinMap[ aPointType ] );
+ clearSpins( myPointXSecMap[ aPointType ] );
+ clearSpins( myPointYSecMap[ aPointType ] );
- myRefPointXMap[ aPointType ]->clear();
- myRefPointYMap[ aPointType ]->clear();
+ clearSpins( myRefPointXMap[ aPointType ] );
+ clearSpins( myRefPointYMap[ aPointType ] );
- myCartPointXMap[ aPointType ]->clear();
- myCartPointYMap[ aPointType ]->clear();
+ clearSpins( myCartPointXMap[ aPointType ] );
+ clearSpins( myCartPointYMap[ aPointType ] );
}
+ blockSignalsPoints( isPBlocked );
+ blockSignalsGeodesic( isGBlocked );
+ blockSignalsCartesian( isCBlocked );
// Emulate turning off C point usage
myPointCEnabler->blockSignals( true );
return myFileName->text();
}
+void HYDROGUI_ImportImageDlg::setFileName( const QString& theName )
+{
+ myFileName->setText( theName );
+ myImageNameGroup->setEnabled( true );
+ myTransformGroup->setEnabled( true );
+}
+
QString HYDROGUI_ImportImageDlg::getGeoreferencementFileName() const
{
return myGeoFileName->text();
}
else
{
- myFileName->setText( aFileName );
+ setFileName( aFileName );
emit createPreview( anImage );
- myImageNameGroup->setEnabled( true );
- myTransformGroup->setEnabled( true );
}
}
}
blockSignalsGeodesic( false );
}
-void HYDROGUI_ImportImageDlg::blockSignalsGeodesic( const bool theState )
+void HYDROGUI_ImportImageDlg::clearSpins( QAbstractSpinBox* theSpin )
+{
+ if ( dynamic_cast<QtxIntSpinBox*>( theSpin ) )
+ {
+ QtxIntSpinBox* aSpin = dynamic_cast<QtxIntSpinBox*>( theSpin );
+ aSpin->setValue( aSpin->minimum() );
+ }
+ else if ( dynamic_cast<QtxIntSpinBox*>( theSpin ) )
+ {
+ QtxDoubleSpinBox* aDblSpin = dynamic_cast<QtxDoubleSpinBox*>( theSpin );
+ aDblSpin->setValue( aDblSpin->minimum() );
+ }
+
+ theSpin->clear();
+}
+
+bool HYDROGUI_ImportImageDlg::blockSignalsPoints( const bool theState )
+{
+ bool isBlocked = false;
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ isBlocked =
+ myPointXMap[ aPointType ]->blockSignals( theState ) || isBlocked;
+ myPointYMap[ aPointType ]->blockSignals( theState );
+
+ myRefPointXMap[ aPointType ]->blockSignals( theState );
+ myRefPointYMap[ aPointType ]->blockSignals( theState );
+ }
+ return isBlocked;
+}
+
+bool HYDROGUI_ImportImageDlg::blockSignalsGeodesic( const bool theState )
{
+ bool isBlocked = false;
for( int aPointType = HYDROGUI_PrsImage::PointA;
aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
{
- myPointXDegMap[ aPointType ]->blockSignals( theState );
+ isBlocked =
+ myPointXDegMap[ aPointType ]->blockSignals( theState ) || isBlocked;
myPointXMinMap[ aPointType ]->blockSignals( theState );
myPointXSecMap[ aPointType ]->blockSignals( theState );
myPointYDegMap[ aPointType ]->blockSignals( theState );
myPointYMinMap[ aPointType ]->blockSignals( theState );
myPointYSecMap[ aPointType ]->blockSignals( theState );
}
+ return isBlocked;
}
-void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
+bool HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
{
+ bool isBlocked = false;
for( int aPointType = HYDROGUI_PrsImage::PointA;
aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
{
- myCartPointXMap[ aPointType ]->blockSignals( theState );
+ isBlocked =
+ myCartPointXMap[ aPointType ]->blockSignals( theState ) || isBlocked;
myCartPointYMap[ aPointType ]->blockSignals( theState );
}
+ return isBlocked;
}
class QtxDoubleSpinBox;
class QtxIntSpinBox;
+class QAbstractSpinBox;
class HYDROGUI_ImportImageDlg : public HYDROGUI_InputPanel
{
QString getRefImageName() const;
QString getFileName() const;
+ void setFileName( const QString& theName );
QString getGeoreferencementFileName() const;
void setImageSize( const QSize& theSize,
void onCartesianCoordChanged( const int thePointType );
private:
- void blockSignalsGeodesic( const bool theState );
- void blockSignalsCartesian( const bool theState );
+ void clearSpins( QAbstractSpinBox* theSpin );
+ bool blockSignalsPoints( const bool theState );
+ bool blockSignalsGeodesic( const bool theState );
+ bool blockSignalsCartesian( const bool theState );
signals:
void createPreview( QImage );
}
}
- // Collect information about existing images and initialize the combobox
- // reference image selector in the dialog.
HYDROGUI_ImportImageDlg::PrsPointDataList aPrsPointDataList;
- HYDROData_Iterator anIterator( doc(), KIND_IMAGE );
- for( ; anIterator.More(); anIterator.Next() )
- {
- Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( anIterator.Current() );
- if( !anImageObj.IsNull() )
- {
- if( myIsEdit && IsEqual( anImageObj, myEditedObject ) )
- continue;
-
- QPoint aLocalPointA, aLocalPointB, aLocalPointC;
- anImageObj->GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC );
-
- HYDROData_Image::TransformationMode aImgTrsfMode;
- QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
- anImageObj->GetGlobalPoints( aImgTrsfMode,
- aTrsfPointA, aTrsfPointB, aTrsfPointC );
-
- HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
- computeTrsfData( aImgTrsfMode, false, aLocalPointA, aLocalPointB, aLocalPointC,
- aTrsfPointA, aTrsfPointB, aTrsfPointC, aDataMap );
-
- HYDROGUI_ImportImageDlg::PrsPointData aPrsPointData( anImageObj->GetName(), aDataMap );
- aPrsPointDataList.append( aPrsPointData );
- }
- }
-
- // Initialize the combobox in the dialog with the list of available reference images
+ getReferenceDataList( aPrsPointDataList );
aPanel->setPrsPointDataList( aPrsPointDataList );
// Select the current reference image in the dialog combobox
aPanel->setRefImageName( aRefImageName );
}
}
+void HYDROGUI_ImportImageOp::getReferenceDataList(
+ HYDROGUI_ImportImageDlg::PrsPointDataList& theList ) const
+{
+ // Collect information about existing images and initialize the combobox
+ // reference image selector in the dialog.
+ HYDROData_Iterator anIterator( doc(), KIND_IMAGE );
+ for( ; anIterator.More(); anIterator.Next() )
+ {
+ Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( anIterator.Current() );
+ if( !anImageObj.IsNull() )
+ {
+ if( myIsEdit && IsEqual( anImageObj, myEditedObject ) )
+ continue;
+
+ QPoint aLocalPointA, aLocalPointB, aLocalPointC;
+ anImageObj->GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC );
+
+ HYDROData_Image::TransformationMode aImgTrsfMode;
+ QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
+ anImageObj->GetGlobalPoints( aImgTrsfMode,
+ aTrsfPointA, aTrsfPointB, aTrsfPointC );
+
+ HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
+ computeTrsfData( aImgTrsfMode, false, aLocalPointA, aLocalPointB, aLocalPointC,
+ aTrsfPointA, aTrsfPointB, aTrsfPointC, aDataMap );
+
+ HYDROGUI_ImportImageDlg::PrsPointData aPrsPointData( anImageObj->GetName(), aDataMap );
+ theList.append( aPrsPointData );
+ }
+ }
+}
+
void HYDROGUI_ImportImageOp::computeTrsfData( HYDROData_Image::TransformationMode theTrsfMode,
bool theIsByTwoPoints,
const QPoint& theLocalPointA,
if( myPreviewPrs ) // if the image is changed by choosing another file
{
- myPreviewPrs->setImage( myImage );
- myPreviewPrs->compute();
-
+ myPreviewPrs->setImage( myImage, true );
+ if ( sender() ) // reset the previous presentation settings
+ {
+ QString aFileName = aPanel->getFileName();
+
+ aPanel->reset();
+ aPanel->setIsEdit( myIsEdit );
+ // restore the file name
+ aPanel->setFileName( aFileName );
+ // fill the reference list
+ HYDROGUI_ImportImageDlg::PrsPointDataList aPrsPointDataList;
+ getReferenceDataList( aPrsPointDataList );
+ aPanel->setPrsPointDataList( aPrsPointDataList );
+ }
if( myPreviewViewManager )
{
if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
myActiveViewManager = anApp->activeViewManager();
myPreviewPrs = new HYDROGUI_PrsImage( myIsEdit ? myEditedObject : 0 );
- myPreviewPrs->setImage( myImage );
- myPreviewPrs->compute();
+ myPreviewPrs->setImage( myImage, true );
myPreviewViewManager =
dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
this, SLOT( onPointSelected() ) );
}
}
+ }
- // Set the image name in the dialog
- QString anImageName = aPanel->getImageName().simplified();
- // If edit mode and the name was not set yet then get from the edited object
- if( myIsEdit && anImageName.isEmpty() )
- {
- if( !myEditedObject.IsNull() )
- anImageName = myEditedObject->GetName();
+ // Set the image name in the dialog
+ QString anImageName = aPanel->getImageName().simplified();
+ // If edit mode and the name was not set yet then get from the edited object
+ if( myIsEdit && anImageName.isEmpty() )
+ {
+ if( !myEditedObject.IsNull() )
+ anImageName = myEditedObject->GetName();
+ }
+ // If the name was not set then initialize it from the selected file name
+ if ( anImageName.isEmpty() )
+ {
+ anImageName = aPanel->getFileName();
+ if ( !anImageName.isEmpty() ) {
+ anImageName = QFileInfo( anImageName ).baseName();
}
- // If the name was not set then initialize it from the selected file name
- if ( anImageName.isEmpty() )
- {
- anImageName = aPanel->getFileName();
- if ( !anImageName.isEmpty() ) {
- anImageName = QFileInfo( anImageName ).baseName();
- }
- // If no file name then generate a new image name
- if ( anImageName.isEmpty() ) {
- anImageName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMAGE_NAME" ) );
- }
+ // If no file name then generate a new image name
+ if ( anImageName.isEmpty() ) {
+ anImageName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMAGE_NAME" ) );
}
-
- aPanel->setImageName( anImageName );
}
+ aPanel->setImageName( anImageName );
aPanel->setImageSize( myImage.size() );
void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName )
{
+ if( theName.isEmpty() ) {
+ if( myRefViewManager )
+ closeView( myRefViewManager );
+ return;
+ }
+
GraphicsView_ViewPort* aViewPort = 0;
LightApp_Application* anApp = module()->getApp();
///// Get a view port for the reference image preview
if( myRefViewManager )
{
- if( theName.isEmpty() )
- {
- closeView( myRefViewManager );
- }
- else if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() )
+ if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() )
{
aViewPort = aViewer->getActiveViewPort();
}
anImage = anImageObj->Image();
myRefPreviewPrs = new HYDROGUI_PrsImage( anImageObj );
- myRefPreviewPrs->setImage( anImage );
- myRefPreviewPrs->compute();
+ myRefPreviewPrs->setImage( anImage, true );
myRefPreviewPrs->setIsTransformationPointPreview( true );
myRefPreviewPrs->setTransformationPointType( myPointType );
const QPoint theLocalPointB,
const QPoint theLocalPointC );
+ /*
+ * Initialize the combobox in the dialog with the list of available reference images
+ */
+ void getReferenceDataList(
+ HYDROGUI_ImportImageDlg::PrsPointDataList& theList ) const;
+
private:
bool myIsEdit;
Handle(HYDROData_Image) myEditedObject;
// Function : setImage
// Purpose :
//================================================================
-void HYDROGUI_PrsImage::setImage( const QImage& theImage )
+void HYDROGUI_PrsImage::setImage( const QImage& theImage, const bool theCompute )
{
myImage = theImage;
+ if ( theCompute ) {
+ compute();
+ computeTransformationPoints( true );
+ }
}
//================================================================
// Function : computeTransformationPoints
// Purpose :
//================================================================
-void HYDROGUI_PrsImage::computeTransformationPoints()
+void HYDROGUI_PrsImage::computeTransformationPoints( const bool theObligatoryInit )
{
- if( myTransformationPointMap.isEmpty() )
{
- int aWidth = myImage.width();
- int aHeight = myImage.height();
-
- // Create presentations for transformation points A, B and C
for( int aPointType = PointA; aPointType <= PointC; aPointType++ )
{
- TransformationPoint aTransformationPoint;
-
- QPoint aPoint;
- QString aCaption;
- QColor aColor = Qt::black;
- switch( aPointType )
- {
- case PointA:
- aPoint = QPoint( 0, 0 );
- aCaption = "A";
- aColor = Qt::darkRed;
- break;
- case PointB:
- aPoint = QPoint( aWidth, 0 );
- aCaption = "B";
- aColor = Qt::darkGreen;
- break;
- case PointC:
- aPoint = QPoint( 0, aHeight );
- aCaption = "C";
- aColor = Qt::darkBlue;
- break;
- }
-
- aTransformationPoint.Point = aPoint;
- aTransformationPoint.Caption = aCaption;
-
- QGraphicsEllipseItem* aPointItem = new QGraphicsEllipseItem( this );
- aPointItem->setPen( QPen( aColor ) );
- aPointItem->setBrush( QBrush( aColor ) );
-
- double aRadius = 3;
- QRectF aRect( -QPointF( aRadius, aRadius ), QSizeF( aRadius * 2 + 1, aRadius * 2 + 1 ) );
- aPointItem->setRect( aRect );
- aPointItem->setPos( QPointF( 0, 0 ) );
-
- QGraphicsSimpleTextItem* aCaptionItem = aCaptionItem = new QGraphicsSimpleTextItem( aCaption, this );
- aCaptionItem->setPen( QPen( aColor ) );
- aCaptionItem->setBrush( QBrush( aColor ) );
- QFont aFont = aCaptionItem->font();
- aFont.setPointSize( qApp->font().pointSize() );
- aCaptionItem->setFont( aFont );
- aCaptionItem->setPos( QPointF( -aRadius * 2, aRadius * 2 ) );
-
- aTransformationPoint.GroupItem = new QGraphicsItemGroup( this );
- aTransformationPoint.GroupItem->addToGroup( aPointItem );
- aTransformationPoint.GroupItem->addToGroup( aCaptionItem );
- aTransformationPoint.GroupItem->setVisible( false );
- aTransformationPoint.GroupItem->setFlag( QGraphicsItem::ItemIgnoresTransformations );
- aTransformationPoint.GroupItem->setPos( aPoint );
-
- myTransformationPointMap[ aPointType ] = aTransformationPoint;
+ if( myTransformationPointMap.isEmpty() || theObligatoryInit )
+ initTrsfPoints( aPointType );
+ // Show/hide the point if necessary
+ updateTrsfPoint( aPointType );
+
}
}
+}
+
+QGraphicsItemGroup* HYDROGUI_PrsImage::createPointItem( const QString& theCaption,
+ const QColor& theColor )
+{
+ QGraphicsEllipseItem* aPointItem = new QGraphicsEllipseItem( this );
+ aPointItem->setPen( QPen( theColor ) );
+ aPointItem->setBrush( QBrush( theColor ) );
+
+ double aRadius = 3;
+ QRectF aRect( -QPointF( aRadius, aRadius ), QSizeF( aRadius * 2 + 1, aRadius * 2 + 1 ) );
+ aPointItem->setRect( aRect );
+ aPointItem->setPos( QPointF( 0, 0 ) );
+
+ QGraphicsSimpleTextItem* aCaptionItem = aCaptionItem = new QGraphicsSimpleTextItem( theCaption, this );
+ aCaptionItem->setPen( QPen( theColor ) );
+ aCaptionItem->setBrush( QBrush( theColor ) );
+ QFont aFont = aCaptionItem->font();
+ aFont.setPointSize( qApp->font().pointSize() );
+ aCaptionItem->setFont( aFont );
+ aCaptionItem->setPos( QPointF( -aRadius * 2, aRadius * 2 ) );
+
+ QGraphicsItemGroup* aGroupItem = new QGraphicsItemGroup( this );
+ aGroupItem->addToGroup( aPointItem );
+ aGroupItem->addToGroup( aCaptionItem );
+ aGroupItem->setVisible( false );
+ aGroupItem->setFlag( QGraphicsItem::ItemIgnoresTransformations );
+
+ return aGroupItem;
+}
+
+//================================================================
+// Function : initTrsfPoints
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImage::initTrsfPoints( const int thePointType )
+{
+ QPoint aPoint;
+ QString aCaption;
+ QColor aColor = Qt::black;
- for( int aPointType = PointA; aPointType <= PointC; aPointType++ )
+ int aWidth = myImage.width();
+ int aHeight = myImage.height();
+ switch( thePointType )
{
- // Show/hide the point if necessary
- updateTrsfPoint( aPointType );
+ case PointA:
+ aPoint = QPoint( 0, 0 );
+ aCaption = "A";
+ aColor = Qt::darkRed;
+ break;
+ case PointB:
+ aPoint = QPoint( aWidth, 0 );
+ aCaption = "B";
+ aColor = Qt::darkGreen;
+ break;
+ case PointC:
+ aPoint = QPoint( 0, aHeight );
+ aCaption = "C";
+ aColor = Qt::darkBlue;
+ break;
}
+
+ TransformationPoint aTransformationPoint;
+ if ( myTransformationPointMap.contains( thePointType ) )
+ aTransformationPoint = myTransformationPointMap[thePointType];
+
+ aTransformationPoint.Point = aPoint;
+ aTransformationPoint.Caption = aCaption;
+ if ( !aTransformationPoint.GroupItem )
+ aTransformationPoint.GroupItem = createPointItem( aCaption, aColor );
+ aTransformationPoint.GroupItem->setPos( aPoint );
+
+ myTransformationPointMap[ thePointType ] = aTransformationPoint;
}
//================================================================
enum TransformationPointType { None = 0, PointA, PointB, PointC };
struct TransformationPoint
{
+ TransformationPoint() : Point( 0, 0 ), Caption( "" ), GroupItem( 0 ) {}
+
QPoint Point;
QString Caption;
QGraphicsItemGroup* GroupItem;
virtual ~HYDROGUI_PrsImage();
public:
- void setImage( const QImage& theImage );
+ void setImage( const QImage& theImage,
+ const bool theCompute = false );
QImage getImage() const;
void setCaption( const QString& theCaption );
virtual void setSelected( bool theState );
protected:
- void computeTransformationPoints();
+ void computeTransformationPoints( const bool theObligatoryInit = false );
+
+ QGraphicsItemGroup* createPointItem( const QString& theCaption,
+ const QColor& theColor );
+
+ /**
+ * Create presentations for transformation points A, B and C or update the presentation
+ * parameters if it is already created
+ */
+ void initTrsfPoints( const int thePointType );
/**
* Show/hide a transformation point if necessary.
*/