]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Fuse and Cut operations.
authorouv <ouv@opencascade.com>
Tue, 6 Aug 2013 12:52:21 +0000 (12:52 +0000)
committerouv <ouv@opencascade.com>
Tue, 6 Aug 2013 12:52:21 +0000 (12:52 +0000)
src/HYDROGUI/HYDROGUI_ImportImageOp.cxx
src/HYDROGUI/HYDROGUI_ImportImageOp.h
src/HYDROGUI/HYDROGUI_ObjSelector.cxx
src/HYDROGUI/HYDROGUI_Operation.cxx
src/HYDROGUI/HYDROGUI_Operation.h
src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx
src/HYDROGUI/HYDROGUI_TwoImagesDlg.h
src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx
src/HYDROGUI/HYDROGUI_TwoImagesOp.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index fbfe8d5fb581e4077a2314b334d93554a3668ec4..bcc97ca11b17097b51fec7808b05292d95cf46ee 100644 (file)
@@ -37,9 +37,6 @@
 #include <LightApp_Application.h>
 #include <LightApp_UpdateFlags.h>
 
-#include <SUIT_Desktop.h>
-#include <SUIT_MessageBox.h>
-
 HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule ),
   myActiveViewManager( 0 ),
@@ -72,19 +69,14 @@ HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
   return aPanel;
 }
 
-void HYDROGUI_ImportImageOp::onApply()
+bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags )
 {
   HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
 
   HYDROGUI_ImportImageDlg::TransformationDataMap aMap;
   bool anIsOk = aPanel->getTransformationDataMap( aMap );
   if( !anIsOk || !myPreviewPrs )
-  {
-    SUIT_MessageBox::critical( module()->getApp()->desktop(),
-                               tr( "INSUFFICIENT_INPUT_DATA" ),
-                               tr( "INPUT_VALID_DATA" ) ); 
-    return;
-  }
+    return false;
 
   double xa1 = aMap[ HYDROGUI_PrsImage::PointA ].first.x();
   double ya1 = aMap[ HYDROGUI_PrsImage::PointA ].first.y();
@@ -111,28 +103,27 @@ void HYDROGUI_ImportImageOp::onApply()
 
   int aStudyId = module()->getStudyId();
   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
-  if( !aDocument.IsNull() )
-  {
-    Handle(HYDROData_Image) anImageObj =
-      Handle(HYDROData_Image)::DownCast( aDocument->CreateObject( KIND_IMAGE ) );
-    if( !anImageObj.IsNull() )
-    {
-      static int ImageId = 0;
-      anImageObj->SetName( QString( "Image_%1" ).arg( QString::number( ++ImageId ) ) );
+  if( aDocument.IsNull() )
+    return false;
 
-      anImageObj->SetImage( anImage );
-      anImageObj->SetTrsf( aTransform );
+  Handle(HYDROData_Image) anImageObj =
+    Handle(HYDROData_Image)::DownCast( aDocument->CreateObject( KIND_IMAGE ) );
+  if( anImageObj.IsNull() )
+    return false;
 
-      module()->update( UF_Model | UF_Viewer );
-    }
-  }
-  HYDROGUI_Operation::onApply();
+  static int ImageId = 0;
+  anImageObj->SetName( QString( "Image_%1" ).arg( QString::number( ++ImageId ) ) );
+
+  anImageObj->SetImage( anImage );
+  anImageObj->SetTrsf( aTransform );
+
+  theUpdateFlags = UF_Model | UF_Viewer;
+  return true;
 }
 
-void HYDROGUI_ImportImageOp::onCancel()
+void HYDROGUI_ImportImageOp::processCancel()
 {
   closePreview();
-  HYDROGUI_Operation::onCancel();
 }
 
 void HYDROGUI_ImportImageOp::onCreatePreview( QString theFileName )
index 3e6964eb33d66485358e69d9ef653afb5ef22a2d..04a0f704d08afe86f3c477cc9ca421e38d36e4c0 100644 (file)
@@ -44,10 +44,10 @@ protected:
 
   virtual HYDROGUI_InputPanel* createInputPanel() const;
 
-protected slots:
-  virtual void               onApply();
-  virtual void               onCancel();
+  virtual bool               processApply( int& theUpdateFlags );
+  virtual void               processCancel();
 
+protected slots:
   void                       onCreatePreview( QString );
   void                       onActivatePointSelection( int );
   void                       onPointSelected();
index bbcc599bee90e98481b2f4874451948453175faf..f087c09dd135fc88aa89744c280e292c590cd83e 100644 (file)
 //
 
 #include "HYDROGUI_ObjSelector.h"
+
+#include "HYDROGUI_DataModel.h"
 #include "HYDROGUI_Module.h"
 
 #include <GraphicsView_Object.h>
+
 #include <LightApp_Application.h>
+#include <LightApp_DataOwner.h>
 #include <LightApp_GVSelector.h>
 #include <LightApp_SelectionMgr.h>
 
@@ -79,7 +83,6 @@ void HYDROGUI_ObjSelector::OnToggled( bool isChecked )
 
 void HYDROGUI_ObjSelector::OnSelectionChanged()
 {
-  /* ouv: to do
   if( !myBtn->isChecked() )
     return;
 
@@ -87,18 +90,24 @@ void HYDROGUI_ObjSelector::OnSelectionChanged()
   SUIT_DataOwnerPtrList anOwners;
   aSelMgr->selected( anOwners );
 
+  HYDROGUI_DataModel* aModel = myModule->getDataModel();
+
   QString anObjName;
   foreach( SUIT_DataOwner* anOwner, anOwners )
   {
-    LightApp_GVDataOwner* aGrDOwner = dynamic_cast<LightApp_GVDataOwner*>( anOwner );
+    LightApp_DataOwner* aGrDOwner = dynamic_cast<LightApp_DataOwner*>( anOwner );
     if( aGrDOwner )
     {
-      anObjName = aGrDOwner->object()->getName();
-      break;
+      QString anEntry = aGrDOwner->entry();
+      Handle(HYDROData_Object) anObject = aModel->objectByEntry( anEntry, KIND_IMAGE );
+      if( !anObject.IsNull() )
+      {
+        anObjName = anObject->GetName();
+        break;
+      }
     }
   }
   myObjName->setText( anObjName );
-  */
 }
 
 QString HYDROGUI_ObjSelector::GetName() const
index 5b1a90e94bd024c39fb09ccf75e9bf8a3fba0694..35705791c9c0e6c071ac873463e8e771444858bb 100644 (file)
@@ -33,6 +33,7 @@
 #include <LightApp_SelectionMgr.h>
 
 #include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
 #include <SUIT_Study.h>
 
 HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule )
@@ -56,6 +57,17 @@ const QString& HYDROGUI_Operation::getName() const
   return myName;
 }
 
+HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const
+{
+  if( !myPanel )
+  {
+    ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel();
+    connect( myPanel, SIGNAL( panelApply() ),  this, SLOT( onApply() ) );
+    connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( onCancel() ) );
+  }
+  return myPanel;
+}
+
 SUIT_SelectionMgr* HYDROGUI_Operation::selectionMgr() const
 {
   return myModule->getApp()->selectionMgr();
@@ -99,31 +111,19 @@ void HYDROGUI_Operation::commitOperation()
     inputPanel()->hide();
 }
 
-HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const
-{
-  if( !myPanel )
-  {
-    ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel();
-    connect( myPanel, SIGNAL( panelApply() ),  this, SLOT( onApply() ) );
-    connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( onCancel() ) );
-  }
-  return myPanel;
-}
-
-Handle_HYDROData_Document HYDROGUI_Operation::doc() const
+bool HYDROGUI_Operation::processApply( int& theUpdateFlags )
 {
-  int aStudyId = myModule->application()->activeStudy()->id();
-  return HYDROData_Document::Document( aStudyId );
+  return false;
 }
 
-void HYDROGUI_Operation::onApply()
+void HYDROGUI_Operation::processCancel()
 {
-  commit();
 }
 
-void HYDROGUI_Operation::onCancel()
+Handle_HYDROData_Document HYDROGUI_Operation::doc() const
 {
-  abort();
+  int aStudyId = myModule->application()->activeStudy()->id();
+  return HYDROData_Document::Document( aStudyId );
 }
 
 Handle_HYDROData_Object HYDROGUI_Operation::FindObjectByName( const QString& theName, int theKind ) const
@@ -136,3 +136,25 @@ Handle_HYDROData_Object HYDROGUI_Operation::FindObjectByName( const QString& the
   }
   return Handle_HYDROData_Object();
 }
+
+void HYDROGUI_Operation::onApply()
+{
+  int anUpdateFlags = 0;
+  if( processApply( anUpdateFlags ) )
+  {
+    module()->update( anUpdateFlags );
+    commit();
+  }
+  else
+  {
+    SUIT_MessageBox::critical( module()->getApp()->desktop(),
+                               tr( "INSUFFICIENT_INPUT_DATA" ),
+                               tr( "INPUT_VALID_DATA" ) ); 
+  }
+}
+
+void HYDROGUI_Operation::onCancel()
+{
+  processCancel();
+  abort();
+}
index 2f983751fbdf4ea08f7acf1e879ac48e1293e7b4..dd7bcaeea8f8c25c9f3c3b31d05b8dfdfaa40614 100644 (file)
@@ -53,6 +53,9 @@ protected:
 
   virtual HYDROGUI_InputPanel* createInputPanel() const = 0;
 
+  virtual bool processApply( int& theUpdateFlags );
+  virtual void processCancel();
+
   Handle_HYDROData_Document doc() const;
   Handle_HYDROData_Object FindObjectByName( const QString& theName, int theKind ) const;
 
index bca023a37ef3ee71ff29f1eeb4d08fcbb805c992..82fc2b7f745780d7ae2596aa44d3c7304591f5eb 100644 (file)
@@ -60,6 +60,11 @@ HYDROGUI_TwoImagesDlg::~HYDROGUI_TwoImagesDlg()
 {
 }
 
+QString HYDROGUI_TwoImagesDlg::GetName() const
+{
+  return myName->text();
+}
+
 void HYDROGUI_TwoImagesDlg::GetSelectedImages( QString& theName1, QString& theName2 ) const
 {
   theName1 = myImage1->GetName();
index faa0c06bccfccb76f26bc089cdaae3da8355fbb3..441a0ad6d40f2f5de9ada612bc06de3c764cd183 100644 (file)
@@ -33,10 +33,13 @@ class HYDROGUI_ObjSelector;
 
 class HYDROGUI_TwoImagesDlg : public HYDROGUI_InputPanel
 {
+  Q_OBJECT
+
 public:
   HYDROGUI_TwoImagesDlg( HYDROGUI_Module* theModule, const QString& theTitle );
   virtual ~HYDROGUI_TwoImagesDlg();
 
+  QString GetName() const;
   void GetSelectedImages( QString& theEntry1, QString& theEntry2 ) const;
 
 private:
index f91ca6cb342fd8f5629efcaa5b15a97198a72031..748da501760394934055afe2799a707af8a485bb 100644 (file)
 
 #include "HYDROGUI_TwoImagesOp.h"
 
+#include "HYDROGUI_Module.h"
 #include "HYDROGUI_TwoImagesDlg.h"
+#include "HYDROGUI_UpdateFlags.h"
 
 #include <HYDROData_Document.h>
 #include <HYDROData_Image.h>
 
 #include <HYDROOperations_Factory.h>
 
+#include <ImageComposer_CutOperator.h>
+#include <ImageComposer_FuseOperator.h>
+
 HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType )
 : HYDROGUI_Operation( theModule ),
   myType( theType )
@@ -38,6 +43,7 @@ HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const in
   {
     case Fuse: aName = tr( "FUSE" ); break;
     case Cut: aName = tr( "CUT" ); break;
+    default: break;
   }
   setName( aName );
 }
@@ -51,22 +57,46 @@ HYDROGUI_InputPanel* HYDROGUI_TwoImagesOp::createInputPanel() const
   return new HYDROGUI_TwoImagesDlg( module(), getName() );
 }
 
-void HYDROGUI_TwoImagesOp::onApply()
+bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags )
 {
   HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast<HYDROGUI_TwoImagesDlg*>( inputPanel() );
+
+  QString aNewName = aPanel->GetName();
+
   QString aName1, aName2;
   aPanel->GetSelectedImages( aName1, aName2 );
 
-  Handle_HYDROData_Image anImage1 = Handle_HYDROData_Image::DownCast(
+  if( aNewName.isEmpty() || aName1.isEmpty() || aName2.isEmpty() )
+    return false;
+
+  Handle(HYDROData_Image) anImage1 = Handle(HYDROData_Image)::DownCast(
     FindObjectByName( aName1, KIND_IMAGE ) );
-  Handle_HYDROData_Image anImage2 = Handle_HYDROData_Image::DownCast(
+  Handle(HYDROData_Image) anImage2 = Handle(HYDROData_Image)::DownCast(
     FindObjectByName( aName2, KIND_IMAGE ) );
+  if( anImage1.IsNull() || anImage2.IsNull() )
+    return false;
 
   HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
-  ImageComposer_Operator* anOperator = 0; //TODO
+  ImageComposer_Operator* anOperator = 0;
+  switch( myType )
+  {
+    case Fuse: anOperator = new ImageComposer_FuseOperator(); break;
+    case Cut: anOperator = new ImageComposer_CutOperator(); break;
+    default: break;
+  }
+
+  if( !anOperator )
+    return false;
 
   Handle(HYDROData_Image) aResult = aFactory->CreateImage( doc(), anOperator );
+  if( aResult.IsNull() )
+    return false;
+
+  aResult->SetName( aNewName );
   aResult->AppendReference( anImage1 );
   aResult->AppendReference( anImage2 );
   aFactory->UpdateImage( doc(), aResult );
+
+  theUpdateFlags = UF_Model | UF_Viewer;
+  return true;
 }
index 2fc1e0cc74a478bed870cf593b2d7132d434044a..8940d854e12ecdf33b4a102600746acd237a0047 100644 (file)
@@ -39,8 +39,7 @@ public:
 protected:
   virtual HYDROGUI_InputPanel* createInputPanel() const;
 
-protected slots:
-  virtual void onApply();
+  virtual bool processApply( int& theUpdateFlags );
 
 private:
   int myType;
index 0e20be6ebc165ff3c100f6d4590e31a7b6a36d31..5ef51a558b86589b930245257acb56cc85c6a91a 100644 (file)
       <translation>Undo</translation>
     </message>
   </context>
+  <context>
+    <name>HYDROGUI_TwoImagesDlg</name>
+    <message>
+      <source>BACKGROUND</source>
+      <translation>Background</translation>
+    </message>
+    <message>
+      <source>COLOR</source>
+      <translation>Color</translation>
+    </message>
+    <message>
+      <source>IMAGE_1</source>
+      <translation>Image 1</translation>
+    </message>
+    <message>
+      <source>IMAGE_2</source>
+      <translation>Image 2</translation>
+    </message>
+    <message>
+      <source>NAME</source>
+      <translation>Name</translation>
+    </message>
+    <message>
+      <source>TRANSPARENT</source>
+      <translation>Transparent</translation>
+    </message>
+  </context>
   <context>
     <name>HYDROGUI_TwoImagesOp</name>
     <message>