Salome HOME
Fit All after was added stream selection and displaying in embedded viewer.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_TwoImagesOp.cxx
index 19baa6a735c42a902779bedb56a32e215ddbed79..50ecc0086a3e2640b75f4b4d2966da66cb225b4a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_TwoImagesDlg.h"
 #include "HYDROGUI_UpdateFlags.h"
+#include <HYDROGUI_DataObject.h>
 
 #include <HYDROData_Document.h>
 #include <HYDROData_Image.h>
-#include <HYDROData_Polyline.h>
 
-#include <HYDROOperations_Factory.h>
+#include <HYDROData_OperationsFactory.h>
 
 #include <ImageComposer_CutOperator.h>
 #include <ImageComposer_CropOperator.h>
 #include <ImageComposer_FuseOperator.h>
 
+#include <LightApp_Application.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
+
 HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule,
                                             const int theType,
                                             const bool theIsEdit )
@@ -72,10 +76,14 @@ void HYDROGUI_TwoImagesOp::startOperation()
   HYDROGUI_TwoImagesDlg* aPanel = (HYDROGUI_TwoImagesDlg*)inputPanel();
   aPanel->reset();
 
-  if( myType == Fuse || myType == Cut )
-    aPanel->setMode( HYDROGUI_TwoImagesDlg::TwoImages, myIsEdit );
+  int aMode;
+  if( myType == Fuse )
+    aMode = HYDROGUI_TwoImagesDlg::TwoFuseImage;
+  if ( myType == Cut )
+    aMode = HYDROGUI_TwoImagesDlg::TwoCutImage;
   else if( myType == Split )
-    aPanel->setMode( HYDROGUI_TwoImagesDlg::ImageAndPolyline, myIsEdit );
+    aMode = HYDROGUI_TwoImagesDlg::ImageAndPolyline;
+  aPanel->setMode( aMode, myIsEdit );
 
   QString anImageName;
   if( myIsEdit )
@@ -103,19 +111,19 @@ void HYDROGUI_TwoImagesOp::startOperation()
   {
     if( myEditedObject->NbReferences() > 0 )
     {
-      Handle(HYDROData_Object) anObject1 = myEditedObject->Reference( 0 );
+      Handle(HYDROData_Entity) anObject1 = myEditedObject->Reference( 0 );
       if( !anObject1.IsNull() )
         aSelectedName1 = anObject1->GetName();
     }
     if( myEditedObject->NbReferences() > 1 )
     {
-      Handle(HYDROData_Object) anObject2 = myEditedObject->Reference( 1 );
+      Handle(HYDROData_Entity) anObject2 = myEditedObject->Reference( 1 );
       if( !anObject2.IsNull() )
         aSelectedName2 = anObject2->GetName();
     }
     aPanel->setSelectedObjects( aSelectedName1, aSelectedName2 );
 
-    HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
+    HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
     if( ImageComposer_Operator* anOperator = aFactory->Operator( myEditedObject ) )
     {
       QColor aColor;
@@ -123,10 +131,29 @@ void HYDROGUI_TwoImagesOp::startOperation()
       aPanel->setColor( aColor );
     }
   }
+  else if( !myIsEdit )
+  {
+    Handle(HYDROData_Image) aSelectedImage =
+      Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+    if( !aSelectedImage.IsNull() )
+    {
+      QString aSelectedName = aSelectedImage->GetName();
+      aPanel->setPreselectedObject( aSelectedName );
+    }
+  }
+  connect( aPanel, SIGNAL( alreadySelected( const QString& ) ), SLOT( onAlreadySelected( const QString& ) ) );
+}
+
+void HYDROGUI_TwoImagesOp::onAlreadySelected( const QString& theName )
+{
+  QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
+  QString aMessage = tr( "OBJECT_ALREADY_SELECTED" ).arg( theName );
+  SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
 }
 
 bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
-                                         QString& theErrorMsg )
+                                         QString& theErrorMsg,
+                                         QStringList& theBrowseObjectsEntries )
 {
   HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast<HYDROGUI_TwoImagesDlg*>( inputPanel() );
 
@@ -144,7 +171,7 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
       ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) ) )
   {
     // check that there are no other objects with the same name in the document
-    Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
+    Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
     if( !anObject.IsNull() )
     {
       theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
@@ -152,62 +179,53 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
     }
   }
 
-  Handle(HYDROData_Object) anObject1 = Handle(HYDROData_Object)::DownCast(
-    HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_UNKNOWN ) );
-  Handle(HYDROData_Object) anObject2 = Handle(HYDROData_Object)::DownCast(
-    HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_UNKNOWN ) );
+  Handle(HYDROData_Entity) anObject1 =
+    HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_UNKNOWN ) ;
+  Handle(HYDROData_Entity) anObject2 =
+    HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_UNKNOWN );
   if( anObject1.IsNull() || anObject2.IsNull() )
     return false;
 
-  HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
-  Handle(HYDROData_Image) aResult = 0;
+  HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
+
+  Handle(HYDROData_Image) aResult;
+  ImageComposer_Operator* anOperator = 0;
   if( myIsEdit )
   {
     aResult = myEditedObject;
     aResult->ClearReferences();
+    anOperator = aFactory->Operator( aResult );
   }
   else
   {
-    ImageComposer_Operator* anOperator = 0;
+    QString anOperatorName;
     switch( myType )
     {
-      case Fuse: anOperator = new ImageComposer_FuseOperator(); break;
-      case Cut: anOperator = new ImageComposer_CutOperator(); break;
-      case Split: anOperator = new ImageComposer_CropOperator(); break;
+      case Fuse:  anOperatorName = ImageComposer_FuseOperator::Type(); break;
+      case Cut:   anOperatorName = ImageComposer_CutOperator::Type(); break;
+      case Split: anOperatorName = ImageComposer_CropOperator::Type(); break;
       default: break;
     }
 
-    if( !anOperator )
-      return false;
+    anOperator = aFactory->Operator( anOperatorName );
 
     aResult = aFactory->CreateImage( doc(), anOperator );
+    QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aResult );
+    theBrowseObjectsEntries.append( anEntry );
   }
 
-  if( aResult.IsNull() )
+  if( aResult.IsNull() || !anOperator )
     return false;
 
+  // Setting the operator arguments 
+  anOperator->setArgs( aPanel->getColor() );
+  aResult->SetArgs( anOperator->getBinArgs() );
+
   aResult->SetName( anImageName );
   aResult->AppendReference( anObject1 );
   aResult->AppendReference( anObject2 );
 
-  // Setting the operator arguments (probably, it should be done somewhere else).
-  // For Fuse and Cut operators: setting background color.
-  // For Crop operator: setting background color and polyline path to crop.
-  if( ImageComposer_Operator* anOperator = aFactory->Operator( aResult ) )
-  {
-    if( ImageComposer_CropOperator* aCropOperator =
-      dynamic_cast<ImageComposer_CropOperator*>( anOperator ) )
-    {
-      Handle(HYDROData_Polyline) aPolyline = Handle(HYDROData_Polyline)::DownCast( anObject2 );
-      if( !aPolyline.IsNull() )
-        aCropOperator->setArgs( aPanel->getColor(), aPolyline->painterPath() );
-    }
-    else
-      anOperator->setArgs( aPanel->getColor() );
-    aResult->SetArgs( anOperator->getBinArgs() );
-  }
-
-  aFactory->UpdateImage( doc(), aResult );
+  aResult->Update();
 
   if( anIsModifySelected )
   {
@@ -229,6 +247,6 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
     module()->setObjectVisible( aViewId, aResult, true );
   }
 
-  theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced;
+  theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;
   return true;
 }