]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
1) Image name
authorouv <ouv@opencascade.com>
Mon, 12 Aug 2013 13:33:50 +0000 (13:33 +0000)
committerouv <ouv@opencascade.com>
Mon, 12 Aug 2013 13:33:50 +0000 (13:33 +0000)
2) Error management

src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx
src/HYDROGUI/HYDROGUI_ImportImageDlg.h
src/HYDROGUI/HYDROGUI_ImportImageOp.cxx
src/HYDROGUI/HYDROGUI_ImportImageOp.h
src/HYDROGUI/HYDROGUI_Operation.cxx
src/HYDROGUI/HYDROGUI_Operation.h
src/HYDROGUI/HYDROGUI_PolylineOp.cxx
src/HYDROGUI/HYDROGUI_PolylineOp.h
src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx
src/HYDROGUI/HYDROGUI_TwoImagesOp.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index eb7a24b1727c9866451a69e83959b9e9a3f76e4e..9e3e173bfa54c83799ebb6629346d50f6e76beef 100644 (file)
@@ -46,22 +46,34 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
 
   // Import image from file
-  myFileGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ) );
+  myFileNameGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ) );
 
-  QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileGroup );
+  QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
 
-  myFileName = new QLineEdit( myFileGroup );
+  myFileName = new QLineEdit( myFileNameGroup );
   myFileName->setReadOnly( true );
 
-  QToolButton* aBrowseBtn = new QToolButton( myFileGroup );
+  QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
   aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
 
-  QBoxLayout* aFileLayout = new QHBoxLayout( myFileGroup );
-  aFileLayout->setMargin( 5 );
-  aFileLayout->setSpacing( 5 );
-  aFileLayout->addWidget( aFileNameLabel );
-  aFileLayout->addWidget( myFileName );
-  aFileLayout->addWidget( aBrowseBtn );
+  QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
+  aFileNameLayout->setMargin( 5 );
+  aFileNameLayout->setSpacing( 5 );
+  aFileNameLayout->addWidget( aFileNameLabel );
+  aFileNameLayout->addWidget( myFileName );
+  aFileNameLayout->addWidget( aBrowseBtn );
+
+  // Image name
+  myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ) );
+
+  QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myImageNameGroup );
+  myImageName = new QLineEdit( myImageNameGroup );
+
+  QBoxLayout* anImageNameLayout = new QHBoxLayout( myImageNameGroup );
+  anImageNameLayout->setMargin( 5 );
+  anImageNameLayout->setSpacing( 5 );
+  anImageNameLayout->addWidget( anImageNameLabel );
+  anImageNameLayout->addWidget( myImageName );
 
   // Mapping
   myMappingGroup = new QGroupBox( tr( "MAPPING" ) );
@@ -181,8 +193,9 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   aMappingLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
 
   // Common
-  addWidget( myFileGroup, 0, 0 );
-  addWidget( myMappingGroup, 1, 0 );
+  addWidget( myFileNameGroup, 0, 0 );
+  addWidget( myImageNameGroup, 1, 0 );
+  addWidget( myMappingGroup, 2, 0 );
 
   setRowStretch();
 
@@ -195,13 +208,16 @@ HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
 
 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
 {
-  myFileGroup->setVisible( !theIsEdit );
+  myFileNameGroup->setVisible( !theIsEdit );
+  myImageNameGroup->setEnabled( theIsEdit );
   myMappingGroup->setEnabled( theIsEdit );
 }
 
 void HYDROGUI_ImportImageDlg::reset()
 {
   myFileName->clear();
+  myImageName->clear();
+  myImageNameGroup->setEnabled( false );
   for( int aPointType = HYDROGUI_PrsImage::PointA;
        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
   {
@@ -222,6 +238,16 @@ void HYDROGUI_ImportImageDlg::reset()
   myMappingGroup->setEnabled( false );
 }
 
+void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
+{
+  myImageName->setText( theName );
+}
+
+QString HYDROGUI_ImportImageDlg::getImageName() const
+{
+  return myImageName->text();
+}
+
 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
                                                         const bool theIsOnlyInput )
 {
@@ -326,6 +352,7 @@ void HYDROGUI_ImportImageDlg::onBrowse()
     {
       myFileName->setText( aFileName );
       emit createPreview( anImage );
+      myImageNameGroup->setEnabled( true );
       myMappingGroup->setEnabled( true );
     }
   }
index a1dcbda55f2fde8a127b3dd1d827f2e10dfa33fc..752a520182bc83bf16e1b7bfd9a3579db9e932ae 100644 (file)
@@ -45,6 +45,9 @@ public:
   void                       setIsEdit( const bool theIsEdit );
   void                       reset();
 
+  void                       setImageName( const QString& theName );
+  QString                    getImageName() const;
+
   void                       setTransformationDataMap( const TransformationDataMap& theMap,
                                                        const bool theIsOnlyInput = false );
   bool                       getTransformationDataMap( TransformationDataMap& theMap ) const;
@@ -60,9 +63,12 @@ signals:
   void                       activatePointSelection( int );
 
 private:
-  QGroupBox*                 myFileGroup;
+  QGroupBox*                 myFileNameGroup;
   QLineEdit*                 myFileName;
 
+  QGroupBox*                 myImageNameGroup;
+  QLineEdit*                 myImageName;
+
   QGroupBox*                 myMappingGroup;
   QMap<int, QPushButton*>    myPointBtnMap;
   QMap<int, QLineEdit*>      myPointXMap;
index 2ab7cec68cf2b14e2520abbd4eecfdf4a3930a73..d86e4cfccfba84bea0b75fe9da9168f9514d26a6 100644 (file)
@@ -102,6 +102,20 @@ void HYDROGUI_ImportImageOp::startOperation()
   }
 }
 
+void HYDROGUI_ImportImageOp::abortOperation()
+{
+  closePreview();
+
+  HYDROGUI_Operation::abortOperation();
+}
+
+void HYDROGUI_ImportImageOp::commitOperation()
+{
+  closePreview();
+
+  HYDROGUI_Operation::commitOperation();
+}
+
 HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
 {
   HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportImageDlg( module(), getName() );
@@ -112,10 +126,28 @@ HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
   return aPanel;
 }
 
-bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags )
+bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
+                                           QString& theErrorMsg )
 {
   HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
 
+  QString anImageName = aPanel->getImageName();
+  if( anImageName.isEmpty() )
+    return false;
+
+  if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) )
+  {
+    // check that there are no other objects with the same name in the document
+    Handle(HYDROData_Object) anObject = findObjectByName( anImageName, KIND_UNKNOWN );
+    if( !anObject.IsNull() )
+    {
+      theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
+      return false;
+    }
+  }
+
+  QImage anImage = myPreviewPrs->getImage();
+
   HYDROGUI_ImportImageDlg::TransformationDataMap aMap;
   bool anIsOk = aPanel->getTransformationDataMap( aMap );
   if( !anIsOk || !myPreviewPrs )
@@ -129,12 +161,12 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags )
   QPointF aPointB2 = aMap[ HYDROGUI_PrsImage::PointB ].second;
   QPointF aPointC2 = aMap[ HYDROGUI_PrsImage::PointC ].second;
 
-  double xa1 = aPointA1.x();
-  double ya1 = aPointA1.y();
-  double xb1 = aPointB1.x();
-  double yb1 = aPointB1.y();
-  double xc1 = aPointC1.x();
-  double yc1 = aPointC1.y();
+  int xa1 = aPointA1.x();
+  int ya1 = aPointA1.y();
+  int xb1 = aPointB1.x();
+  int yb1 = aPointB1.y();
+  int xc1 = aPointC1.x();
+  int yc1 = aPointC1.y();
 
   double xa2 = aPointA2.x();
   double ya2 = aPointA2.y();
@@ -143,14 +175,23 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags )
   double xc2 = aPointC2.x();
   double yc2 = aPointC2.y();
 
+  // first, check that three input points don't belong to a single line
+  if( ( yb1 - ya1 ) * ( xc1 - xa1 ) == ( yc1 - ya1 ) * ( xb1 - xa1 ) )
+  {
+    theErrorMsg = tr( "POINTS_A_B_C_BELONG_TO_SINGLE_LINE" );
+    return false;
+  }
+
   QTransform aTransform1( xa1, ya1, 1, xb1, yb1, 1, xc1, yc1, 1 );
   QTransform aTransform2( xa2, ya2, 1, xb2, yb2, 1, xc2, yc2, 1 );
 
-  QTransform aTransform = aTransform1.inverted() * aTransform2;
-
-  QImage anImage = myPreviewPrs->getImage();
-
-  closePreview();
+  bool anIsInvertible = false;
+  QTransform aTransform = aTransform1.inverted( &anIsInvertible ) * aTransform2;
+  if( !anIsInvertible )
+  {
+    theErrorMsg = tr( "TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED" );
+    return false;
+  }
 
   Handle(HYDROData_Image) anImageObj;
   if( myIsEdit )
@@ -161,11 +202,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags )
   if( anImageObj.IsNull() )
     return false;
 
-  if( !myIsEdit )
-  {
-    static int ImageId = 0;
-    anImageObj->SetName( QString( "Image_%1" ).arg( QString::number( ++ImageId ) ) );
-  }
+  anImageObj->SetName( anImageName );
 
   anImageObj->SetImage( anImage );
   anImageObj->SetTrsf( aTransform );
@@ -179,11 +216,6 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags )
   return true;
 }
 
-void HYDROGUI_ImportImageOp::processCancel()
-{
-  closePreview();
-}
-
 void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
 {
   LightApp_Application* anApp = module()->getApp();
@@ -217,6 +249,27 @@ void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
 
   HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
 
+  QString anImageName;
+  if( myIsEdit )
+  {
+    if( !myEditedObject.IsNull() )
+      anImageName = myEditedObject->GetName();
+  }
+  else
+  {
+    int anImageId = 1;
+    while( anImageId < 100 )
+    {
+      anImageName = QString( "Image_%1" ).arg( QString::number( anImageId++ ) );
+
+      // check that there are no other objects with the same name in the document
+      Handle(HYDROData_Object) anObject = findObjectByName( anImageName, KIND_UNKNOWN );
+      if( anObject.IsNull() )
+        break;
+    }
+  }
+  aPanel->setImageName( anImageName );
+
   aPanel->initializePointSelection();
   onPointSelected();
 }
index bdb588671328b461a0e91263aa26d7fa56401301..fa4472e2a5bf061133e0a2bbcda1df2f828c30ec 100644 (file)
@@ -45,11 +45,12 @@ public:
 
 protected:
   virtual void               startOperation();
+  virtual void               abortOperation();
+  virtual void               commitOperation();
 
   virtual HYDROGUI_InputPanel* createInputPanel() const;
 
-  virtual bool               processApply( int& theUpdateFlags );
-  virtual void               processCancel();
+  virtual bool               processApply( int& theUpdateFlags, QString& theErrorMsg );
 
 protected slots:
   void                       onCreatePreview( QImage );
index b19684ab4b6fbed37f84bf2509419e76b7617a90..aacf5dfc377ed80cecbdffa0a656eba0189a94ef 100644 (file)
@@ -116,7 +116,8 @@ HYDROGUI_InputPanel* HYDROGUI_Operation::createInputPanel() const
   return NULL;
 }
 
-bool HYDROGUI_Operation::processApply( int& theUpdateFlags )
+bool HYDROGUI_Operation::processApply( int& theUpdateFlags,
+                                       QString& theErrorMsg )
 {
   return false;
 }
@@ -145,16 +146,20 @@ Handle_HYDROData_Object HYDROGUI_Operation::findObjectByName( const QString& the
 void HYDROGUI_Operation::onApply()
 {
   int anUpdateFlags = 0;
-  if( processApply( anUpdateFlags ) )
+  QString anErrorMsg;
+  if( processApply( anUpdateFlags, anErrorMsg ) )
   {
     module()->update( anUpdateFlags );
     commit();
   }
   else
   {
+    QString aMsg = tr( "INPUT_VALID_DATA" );
+    if( !anErrorMsg.isEmpty() )
+      aMsg.prepend( anErrorMsg + "\n" );
     SUIT_MessageBox::critical( module()->getApp()->desktop(),
                                tr( "INSUFFICIENT_INPUT_DATA" ),
-                               tr( "INPUT_VALID_DATA" ) ); 
+                               aMsg ); 
   }
 }
 
index 1f3ae1d54971e74d59f95827b18a6c63003a1665..6ab80bd16282b7240571bf9856a6cf94ca33eed8 100644 (file)
@@ -53,7 +53,7 @@ protected:
 
   virtual HYDROGUI_InputPanel* createInputPanel() const;
 
-  virtual bool processApply( int& theUpdateFlags );
+  virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg );
   virtual void processCancel();
 
   Handle_HYDROData_Document doc() const;
index 774f3c3646b0bb14566fdee388b2d2cf38da3914..b8a6982628d80714c7d5ea23b00324176c507847 100755 (executable)
@@ -46,7 +46,8 @@ HYDROGUI_InputPanel* HYDROGUI_PolylineOp::createInputPanel() const
   return new HYDROGUI_PolylineDlg( module(), getName() );
 }
 
-bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags )
+bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags,
+                                        QString& theErrorMsg )
 {
   HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
 
index d337760364507648d58021db0ba39a454e69aeb9..c56ec0a4937c8e5085b68422a32033f3156089b7 100755 (executable)
@@ -38,7 +38,7 @@ public:
 protected:
   virtual HYDROGUI_InputPanel* createInputPanel() const;
 
-  virtual bool processApply( int& theUpdateFlags );
+  virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg );
 
   virtual void startOperation();
 
index a91d4734465c3ef0f172cd95caa465e6901741d7..872a097773acb57a12309e527f72996d95881e16 100644 (file)
@@ -57,7 +57,8 @@ HYDROGUI_InputPanel* HYDROGUI_TwoImagesOp::createInputPanel() const
   return new HYDROGUI_TwoImagesDlg( module(), getName() );
 }
 
-bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags )
+bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
+                                         QString& theErrorMsg )
 {
   HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast<HYDROGUI_TwoImagesDlg*>( inputPanel() );
 
index 8940d854e12ecdf33b4a102600746acd237a0047..d5b3306d87a8390b2eadf9f90dc8778b988616a2 100644 (file)
@@ -39,7 +39,7 @@ public:
 protected:
   virtual HYDROGUI_InputPanel* createInputPanel() const;
 
-  virtual bool processApply( int& theUpdateFlags );
+  virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg );
 
 private:
   int myType;
index 30f70b53d7de08ca3e43223b10d1bac5c114cf83..e6ff1d24358eae7f31b0dc5b2c2ae4c7afa77e1c 100644 (file)
   </context>
   <context>
     <name>HYDROGUI_ImportImageDlg</name>
+    <message>
+      <source>ACTIVATE_POINT_A_SELECTION</source>
+      <translation>Activate point A selection</translation>
+    </message>
+    <message>
+      <source>ACTIVATE_POINT_B_SELECTION</source>
+      <translation>Activate point B selection</translation>
+    </message>
+    <message>
+      <source>ACTIVATE_POINT_C_SELECTION</source>
+      <translation>Activate point C selection</translation>
+    </message>
     <message>
       <source>BROWSE_IMAGE_FILE</source>
       <translation>Browse image file</translation>
       <source>IMAGE_FILTER</source>
       <translation>Image files (*.bmp *.jpg *.jpeg *.png);;All files (*.* *)</translation>
     </message>
+    <message>
+      <source>IMAGE_NAME</source>
+      <translation>Image name</translation>
+    </message>
     <message>
       <source>IMPORT_IMAGE_FROM_FILE</source>
       <translation>Import image from file</translation>
       <translation>Mapping</translation>
     </message>
     <message>
-      <source>ACTIVATE_POINT_A_SELECTION</source>
-      <translation>Activate point A selection</translation>
-    </message>
-    <message>
-      <source>ACTIVATE_POINT_B_SELECTION</source>
-      <translation>Activate point B selection</translation>
-    </message>
-    <message>
-      <source>ACTIVATE_POINT_C_SELECTION</source>
-      <translation>Activate point C selection</translation>
+      <source>NAME</source>
+      <translation>Name</translation>
     </message>
   </context>
   <context>
       <source>MAPPING</source>
       <translation>Mapping</translation>
     </message>
+    <message>
+      <source>OBJECT_EXISTS_IN_DOCUMENT</source>
+      <translation>Object with name '%1' already exists in the document.</translation>
+    </message>
+    <message>
+      <source>POINTS_A_B_C_BELONG_TO_SINGLE_LINE</source>
+      <translation>Points A, B, C belong to a single line.</translation>
+    </message>
+    <message>
+      <source>TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED</source>
+      <translation>Transformation matrix cannot be computed.</translation>
+    </message>
   </context>
   <context>
     <name>HYDROGUI_Module</name>