]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Edit composite images.
authorouv <ouv@opencascade.com>
Wed, 28 Aug 2013 08:09:32 +0000 (08:09 +0000)
committerouv <ouv@opencascade.com>
Wed, 28 Aug 2013 08:09:32 +0000 (08:09 +0000)
src/HYDROGUI/HYDROGUI_ImportImageOp.cxx
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_ObjSelector.cxx
src/HYDROGUI/HYDROGUI_ObjSelector.h
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_Operations.h
src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx
src/HYDROGUI/HYDROGUI_TwoImagesDlg.h
src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx
src/HYDROGUI/HYDROGUI_TwoImagesOp.h

index 2b76bdb3af656030b0a2e8386ce1ad5aeda92d99..c31e50843f7eee8f5b0f31b781b9b5c1ad04c98d 100644 (file)
@@ -46,7 +46,7 @@ HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule,
   myPreviewPrs( 0 ),
   myPointType( HYDROGUI_PrsImage::None )
 {
-  setName( theIsEdit ? tr( "EDIT_IMAGE" ) : tr( "IMPORT_IMAGE" ) );
+  setName( theIsEdit ? tr( "EDIT_IMPORTED_IMAGE" ) : tr( "IMPORT_IMAGE" ) );
 }
 
 HYDROGUI_ImportImageOp::~HYDROGUI_ImportImageOp()
index 7d2197a1c64f54c60400a1b7255a0a459dc6f4c1..c355b2dfe9ea402d64e8b9364e441a9cb2ab3353 100644 (file)
@@ -33,6 +33,8 @@
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_UpdateFlags.h"
 
+#include <HYDROData_Image.h>
+
 #include <GraphicsView_ViewFrame.h>
 #include <GraphicsView_ViewManager.h>
 #include <GraphicsView_ViewPort.h>
@@ -146,6 +148,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   bool anIsHiddenInSelection = false;
 
   bool anIsImage = false;
+  bool anIsCompositeImage = false;
   bool anIsPolyline = false;
   bool anIsVisualState = false;
 
@@ -162,7 +165,12 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       anIsHiddenInSelection |= !aVisibility;
 
       if( anObject->GetKind() == KIND_IMAGE )
+      {
         anIsImage = true;
+        Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
+        if( !anImage.IsNull() )
+          anIsCompositeImage = anImage->NbReferences() > 0;
+      }
       else if( anObject->GetKind() == KIND_POLYLINE )
         anIsPolyline = true;
       else if( anObject->GetKind() == KIND_VISUAL_STATE )
@@ -179,7 +187,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   {
     if( anIsImage )
     {
-      theMenu->addAction( action( EditImageId ) );
+      theMenu->addAction( action( anIsCompositeImage ? EditCompositeImageId : EditImportedImageId ) );
       theMenu->addAction( action( ObserveImageId ) );
       theMenu->addAction( action( ExportImageId ) );
       theMenu->addSeparator();
index 3b7e1e5939c0787fdcaeaf12d2e8647b84d7f221..04bd20f0c0c4d67f5386a436cfe388b0278763d3 100644 (file)
@@ -99,7 +99,12 @@ void HYDROGUI_ObjSelector::OnSelectionChanged()
   if( !anObject.IsNull() )
     anObjName = anObject->GetName();
 
-  myObjName->setText( anObjName );
+  SetName( anObjName );
+}
+
+void HYDROGUI_ObjSelector::SetName( const QString& theName )
+{
+  myObjName->setText( theName );
 }
 
 QString HYDROGUI_ObjSelector::GetName() const
index 7327df516017f2cbb64f01df7297e69048297342..f3853d741e36cbc57b82c68f52eb36c7005b206b 100644 (file)
@@ -39,6 +39,7 @@ public:
 
   void Clear();
 
+  void SetName( const QString& );
   QString GetName() const;
 
 protected:
index a2b8286435eba691739d85c310e00f91eb00ea8a..77d054542e69df5fba289ad4527f98bd9e15c5b5 100644 (file)
@@ -69,7 +69,8 @@ void HYDROGUI_Module::createActions()
   createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
 
   createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
-  createAction( EditImageId, "EDIT_IMAGE" );
+  createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" );
+  createAction( EditCompositeImageId, "EDIT_COMPOSITE_IMAGE" );
   createAction( ObserveImageId, "OBSERVE_IMAGE" );
   createAction( ExportImageId, "EXPORT_IMAGE" );
   createAction( CreatePolylineId, "CREATE_POLYLINE" );
@@ -221,8 +222,8 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
     anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
     break;
   case ImportImageId:
-  case EditImageId:
-    anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImageId );
+  case EditImportedImageId:
+    anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
     break;
   case ObserveImageId:
     anOp = new HYDROGUI_ObserveImageOp( aModule );
@@ -240,6 +241,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
   case CutId:
     anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut );
     break;
+  case EditCompositeImageId:
+    anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Edit );
+    break;
   case DeleteId:
     anOp = new HYDROGUI_DeleteOp( aModule );
     break;
index 7c835e50550b97a484deabf0d5bd678fa21bc240..2e5015d102c9ecc3f810c5582aa271087a285e60 100644 (file)
@@ -31,7 +31,8 @@ enum OperationId
   UndoId,
   RedoId,
   ImportImageId,
-  EditImageId,
+  EditImportedImageId,
+  EditCompositeImageId,
   ObserveImageId,
   ExportImageId,
   CreatePolylineId,
index 8a313ec962575b95f7418d47b41bb9e169fa09bc..6cee6e2609ab1f02f2f8d8ca993bc50c072b2783 100644 (file)
@@ -108,6 +108,13 @@ QString HYDROGUI_TwoImagesDlg::getImageName() const
   return myImageName->text();
 }
 
+void HYDROGUI_TwoImagesDlg::setSelectedImages( const QString& theName1,
+                                               const QString& theName2 )
+{
+  myImage1->SetName( theName1 );
+  myImage2->SetName( theName2 );
+}
+
 bool HYDROGUI_TwoImagesDlg::getSelectedImages( QString& theName1,
                                                QString& theName2 ) const
 {
index e9d38d53a4d44ee49ded02396bd94a558b83fa6b..a1f5d5268881ab03697c279086232e12a2684e68 100644 (file)
@@ -44,6 +44,8 @@ public:
   void                       setImageName( const QString& theName );
   QString                    getImageName() const;
 
+  void                       setSelectedImages( const QString& theName1,
+                                                const QString& theName2 );
   bool                       getSelectedImages( QString& theName1,
                                                 QString& theName2 ) const;
 
index 704372635e11196ce05fdaafce27ec6401f21023..fd30943f2c16c312ce0f30400c86021f1b77cd3d 100644 (file)
 
 HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType )
 : HYDROGUI_Operation( theModule ),
-  myType( theType )
+  myType( theType ),
+  myIsEdit( false ),
+  myEditedObject( 0 )
 {
+  if( myType == Edit )
+  {
+    myIsEdit = true;
+    myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+    if( !myEditedObject.IsNull() )
+    {
+      if( HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory() )
+      {
+        if( ImageComposer_Operator* anOperator = aFactory->Operator( myEditedObject ) )
+        {
+          if( dynamic_cast<ImageComposer_FuseOperator*>( anOperator ) )
+            myType = Fuse;
+          else if( dynamic_cast<ImageComposer_CutOperator*>( anOperator ) )
+            myType = Cut;
+        }
+      }
+    }
+  }
+
   QString aName;
   switch( myType )
   {
@@ -65,8 +86,33 @@ void HYDROGUI_TwoImagesOp::startOperation()
   HYDROGUI_TwoImagesDlg* aPanel = (HYDROGUI_TwoImagesDlg*)inputPanel();
   aPanel->reset();
 
-  QString anImageName = HYDROGUI_Tool::GenerateObjectName( module(), getName() );
+  QString anImageName;
+  if( myIsEdit )
+  {
+    if( !myEditedObject.IsNull() )
+      anImageName = myEditedObject->GetName();
+  }
+  else
+    anImageName = HYDROGUI_Tool::GenerateObjectName( module(), getName() );
   aPanel->setImageName( anImageName );
+
+  QString aSelectedName1, aSelectedName2;
+  if( myIsEdit && !myEditedObject.IsNull() )
+  {
+    if( myEditedObject->NbReferences() > 0 )
+    {
+      Handle(HYDROData_Image) anImage1 = myEditedObject->Reference( 0 );
+      if( !anImage1.IsNull() )
+        aSelectedName1 = anImage1->GetName();
+    }
+    if( myEditedObject->NbReferences() > 1 )
+    {
+      Handle(HYDROData_Image) anImage2 = myEditedObject->Reference( 1 );
+      if( !anImage2.IsNull() )
+        aSelectedName2 = anImage2->GetName();
+    }
+    aPanel->setSelectedImages( aSelectedName1, aSelectedName2 );
+  }
 }
 
 bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
@@ -82,12 +128,15 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
   if( !aPanel->getSelectedImages( aSelectedName1, aSelectedName2 ) )
     return false;
 
-  // check that there are no other objects with the same name in the document
-  Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
-  if( !anObject.IsNull() )
+  if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) )
   {
-    theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
-    return false;
+    // check that there are no other objects with the same name in the document
+    Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
+    if( !anObject.IsNull() )
+    {
+      theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
+      return false;
+    }
   }
 
   Handle(HYDROData_Image) anImage1 = Handle(HYDROData_Image)::DownCast(
@@ -98,18 +147,28 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
     return false;
 
   HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
-  ImageComposer_Operator* anOperator = 0;
-  switch( myType )
+  Handle(HYDROData_Image) aResult = 0;
+  if( myIsEdit )
   {
-    case Fuse: anOperator = new ImageComposer_FuseOperator(); break;
-    case Cut: anOperator = new ImageComposer_CutOperator(); break;
-    default: break;
+    aResult = myEditedObject;
+    aResult->ClearReferences();
+  }
+  else
+  {
+    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;
+
+    aResult = aFactory->CreateImage( doc(), anOperator );
   }
 
-  if( !anOperator )
-    return false;
-
-  Handle(HYDROData_Image) aResult = aFactory->CreateImage( doc(), anOperator );
   if( aResult.IsNull() )
     return false;
 
@@ -123,6 +182,6 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
   anImage2->SetVisible( aViewId, false );
   aResult->SetVisible( aViewId, true );
 
-  theUpdateFlags = UF_Model | UF_Viewer;
+  theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced;
   return true;
 }
index ee3bbda7ce5652bce3a32808c86154fad114bbff..d537f4c6ef8ca8e42597e2ec31ec65fc2438e569 100644 (file)
 
 #include "HYDROGUI_Operation.h"
 
+#include <HYDROData_Image.h>
+
 class HYDROGUI_TwoImagesOp : public HYDROGUI_Operation
 {
   Q_OBJECT
 
 public:
-  enum OperationType { Fuse, Cut };
+  enum OperationType { Fuse, Cut, Edit };
 
 public:
   HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType );
@@ -44,7 +46,9 @@ protected:
   virtual bool               processApply( int& theUpdateFlags, QString& theErrorMsg );
 
 private:
-  int myType;
+  int                        myType;
+  bool                       myIsEdit;
+  Handle(HYDROData_Image)    myEditedObject;
 };
 
 #endif