]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
The code refactoring since the ImageComposer API has been changed (Feature #6).
authoradv <adv@opencascade.com>
Wed, 11 Sep 2013 12:43:23 +0000 (12:43 +0000)
committeradv <adv@opencascade.com>
Wed, 11 Sep 2013 12:43:23 +0000 (12:43 +0000)
13 files changed:
src/HYDROData/HYDROData_Image.cxx
src/HYDROData/HYDROData_Image.h
src/HYDROData/HYDROData_Object.cxx
src/HYDROData/HYDROData_Object.h
src/HYDROData/HYDROData_Polyline.cxx
src/HYDROData/HYDROData_Polyline.h
src/HYDROData/HYDROData_Tool.cxx
src/HYDROData/HYDROData_Tool.h
src/HYDROData/HYDROOperations_Factory.cxx
src/HYDROData/HYDROOperations_Factory.h
src/HYDROGUI/HYDROGUI_ImportImageOp.cxx
src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx
src/HYDROGUI/HYDROGUI_UpdateImageOp.cxx

index 88650062dc8ee423ba9f017cf6661675e6a386e5..cd63a215c6ee310b02af5e3cd7c1d649fea0c556 100644 (file)
@@ -1,7 +1,9 @@
-#include <HYDROData_Image.h>
-#include <HYDROData_Iterator.h>
 
-#include <HYDROOperations_Factory.h>
+#include "HYDROData_Image.h"
+
+#include "HYDROData_Iterator.h"
+#include "HYDROOperations_Factory.h"
+#include "HYDROData_Tool.h"
 
 #include <TDataStd_RealArray.hxx>
 #include <TDataStd_ByteArray.hxx>
@@ -13,6 +15,7 @@
 #include <TDF_ListIteratorOfLabelList.hxx>
 
 #include <ImageComposer_Operator.h>
+#include <ImageComposer_MetaTypes.h>
 
 #include <QStringList>
 
@@ -168,6 +171,69 @@ QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObject
   return aResList;
 }
 
+void HYDROData_Image::Update()
+{
+  HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
+
+  // Update image only if there is an operation
+  ImageComposer_Operator* anOp = aFactory->Operator( this );
+  if ( anOp ) 
+  {
+    // Fill by arguments and process the operation
+    QVariant anObj1, anObj2;
+    int aNbReferences = NbReferences();
+
+    if ( aNbReferences > 0 )
+    {
+      // First referenced object
+      Handle(HYDROData_Object) aRefObj = Reference( 0 );
+      if ( !aRefObj.IsNull() )
+      {
+        anObj1 = aRefObj->GetDataVariant();
+        if ( !anObj1.isNull() && anObj1.canConvert<ImageComposer_Image>() )
+        {
+          ImageComposer_Image anImage = anObj1.value<ImageComposer_Image>();
+          QTransform aTransform = anImage.transform();
+          SetTrsf( aTransform );
+        }
+      }
+    }
+
+    if ( aNbReferences > 1 )
+    {
+      // Second referenced object
+      Handle(HYDROData_Object) aRefObj = Reference( 1 );
+      if ( !aRefObj.IsNull() )
+        anObj2 = aRefObj->GetDataVariant();
+    }
+
+    ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
+    SetImage( aResImg );
+  }
+
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
+  if ( !aDocument.IsNull() )
+  {
+    // Change the states of this and all depended images
+    MustBeUpdated( true );
+    HYDROData_Tool::SetMustBeUpdatedImages( aDocument );
+    MustBeUpdated( false );
+  }
+}
+
+QVariant HYDROData_Image::GetDataVariant()
+{
+  QTransform aTransform = Trsf();
+
+  ImageComposer_Image anImage = Image();
+  anImage.setTransform( aTransform );
+
+  QVariant aVarData;
+  aVarData.setValue<ImageComposer_Image>( anImage );
+  
+  return aVarData;
+}
+
 void HYDROData_Image::SetImage(const QImage& theImage)
 {
   if (theImage.isNull()) {
index 4966616e7626a22b5349bfe9bc49d17960f392b4..0b92af773c0aef90e63a4b9f2a38f5169b19becc 100644 (file)
@@ -41,6 +41,21 @@ public:
    */
   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
 
+  /**
+   * Updates object state.
+   * Reimplemented to update an Image object in the data structure.
+   * Call this method whenever you made changes for operator or reference objects.
+   * If it is changed, sets "MustBeUpdated" flag to other depended images.
+   */
+  HYDRODATA_EXPORT virtual void Update();
+
+  /**
+   * Returns data of object wrapped to QVariant.
+   * Reimplemented to wrap and return saved image.
+   * Transformation are applied to result image.
+   */
+  HYDRODATA_EXPORT virtual QVariant GetDataVariant();
+
   /**
    * Stores the image
    * \param theImage new image
index 1b6337a0a0d5c410b915fb1aab016409ba24c66f..9b84cef2d03c1123b4b5c903b446b1e539de54ec 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <QString>
 #include <QStringList>
+#include <QVariant>
 
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
@@ -41,6 +42,15 @@ QStringList HYDROData_Object::DumpToPython( MapOfTreatedObjects& theTreatedObjec
   return anEmptyList;
 }
 
+void HYDROData_Object::Update()
+{
+}
+
+QVariant HYDROData_Object::GetDataVariant()
+{
+  return QVariant();
+}
+
 bool HYDROData_Object::IsRemoved() const
 {
   return !myLab.HasAttribute();
index 0c733954882b59e7ca4e37e1de40f2398a595f47..7ea49e6b1c46daa92c2d930981e8e4854a031190 100644 (file)
@@ -8,6 +8,7 @@
 #include <QMap>
 
 class QString;
+class QVariant;
 class QStringList;
 
 ///! Kind of an object in a document
@@ -68,6 +69,18 @@ public:
    */
   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
 
+  /**
+   * Updates object state.
+   * Base implementation dose nothing.
+   */
+  HYDRODATA_EXPORT virtual void Update();
+
+  /**
+   * Returns data of object wrapped to QVariant.
+   * Base implementation returns null value.
+   */
+  HYDRODATA_EXPORT virtual QVariant GetDataVariant();
+
   /**
    * Checks is object exists in the data structure.
    * \returns true is object is not exists in the data model
index 7db4062a086416dfdf5294cb1da2fc97f127bfbe..d80af2eb11ab0529b3ba95f3dbd62f6c2d6eb1f7 100755 (executable)
@@ -1,6 +1,8 @@
 #include <HYDROData_Polyline.h>
 #include <HYDROData_Iterator.h>
 
+#include <ImageComposer_MetaTypes.h>
+
 #include <TDataStd_Name.hxx>
 #include <TDataStd_Integer.hxx>
 #include <TDataStd_ByteArray.hxx>
@@ -11,7 +13,6 @@
 #include <TDataStd_UAttribute.hxx>
 #include <TDF_ListIteratorOfLabelList.hxx>
 
-#include <QPainterPath>
 #include <QStringList>
 
 // tage of the child of my label that contains information about the operator
@@ -104,6 +105,16 @@ QStringList HYDROData_Polyline::DumpToPython( MapOfTreatedObjects& theTreatedObj
   return aResList;
 }
 
+QVariant HYDROData_Polyline::GetDataVariant()
+{
+  QPainterPath aPath = painterPath();
+
+  QVariant aVarData;
+  aVarData.setValue<QPainterPath>( aPath );
+  
+  return aVarData;
+}
+
 /**
  * Return polyline dimension
  * \return polyline dimension. 2 or 3 is valid. 0 is invalid.
index 8dc6dcedfaa68fff15aa6beff97cff6b08b3c6a9..cd7928c873029e6f2cec984367a9675370ece2ba 100755 (executable)
@@ -61,6 +61,12 @@ public:
    */
   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
 
+  /**
+   * Returns data of object wrapped to QVariant.
+   * Reimplemented to wrap and return saved path.
+   */
+  HYDRODATA_EXPORT virtual QVariant GetDataVariant();
+
   /**
    * Replace current polyline data by new sections list
    * \param theSections the sections list
index 9cb932d340a7066442e860a91959c030c7002799..58511d16cea71b587a10df916512f4b35cc7e28b 100644 (file)
@@ -1,6 +1,9 @@
 
 #include "HYDROData_Tool.h"
 
+#include "HYDROData_Image.h"
+#include "HYDROData_Iterator.h"
+
 #include <QFile>
 #include <QStringList>
 #include <QTextStream>
@@ -19,3 +22,36 @@ void HYDROData_Tool::WriteStringsToFile( QFile&             theFile,
   QTextStream anOutStream( &theFile );
   anOutStream << aWriteStr << theSep << theSep;
 }
+
+void HYDROData_Tool::SetMustBeUpdatedImages(
+  Handle_HYDROData_Document theDoc)
+{
+  bool aChanged = true;
+
+  // iterate until there is no changes because images on all level of dependency must be updated
+  while ( aChanged )
+  {
+    aChanged = false;
+
+    HYDROData_Iterator anIter( theDoc, KIND_IMAGE );
+    for ( ; anIter.More(); anIter.Next() )
+    {
+      Handle(HYDROData_Image) anImage = 
+        Handle(HYDROData_Image)::DownCast( anIter.Current() );
+      if ( anImage.IsNull() || anImage->MustBeUpdated() )
+        continue;
+
+      for ( int i = 0, aNBRefs = anImage->NbReferences(); i < aNBRefs; ++i )
+      {
+        Handle(HYDROData_Image) aRefImage =
+          Handle(HYDROData_Image)::DownCast( anImage->Reference( i ) );
+        if ( !aRefImage.IsNull() && aRefImage->MustBeUpdated() )
+        {
+           // image references to updated => also must be updated
+           anImage->MustBeUpdated(true);
+           aChanged = true;
+        }
+      }
+    }
+  }
+}
index 5be4ba3ab2e65b366605a09a4e167b4ed4ec81c7..85824d6ef10f7cf5bec3358bf7b0ccfc0e0e8f62 100644 (file)
@@ -8,6 +8,7 @@
 
 class QFile;
 class QStringList;
+class Handle_HYDROData_Document;
 
 class HYDROData_Tool {
 
@@ -17,6 +18,12 @@ public:
                                                             const QStringList& theStrings,
                                                             const QString&     theSep = "\n" );
 
+  /**
+   * Enables "MustBeUpdated" flag for Images that are depended on "MustBeUpdated" images.
+   * \param theDoc document where this operation is performed
+   */
+  static void                           SetMustBeUpdatedImages( Handle_HYDROData_Document theDoc );
+
 };
 
 inline bool ValuesEquals( const double& theFirst, const double& theSecond )
index c9c069665e61d50a20800ad941c35bcc0a407787..ffe38aa0d7f341aaa28083fd53cfadfd2a0e35a3 100644 (file)
@@ -7,7 +7,6 @@
 #include<ImageComposer_CropOperator.h>
 #include<ImageComposer_CutOperator.h>
 #include<ImageComposer_FuseOperator.h>
-#include<ImageComposer_Image.h>
 
 #include <typeinfo>
 
@@ -27,14 +26,6 @@ HYDROOperations_Factory* HYDROOperations_Factory::Factory()
   return FACTORY;
 }
 
-ImageComposer_Operator* HYDROOperations_Factory::Operator(const QString theName) const
-{
-  if (myOps.contains(theName)) {
-    return myOps[theName];
-  }
-  return NULL;
-}
-
 void HYDROOperations_Factory::Register(
   ImageComposer_Operator* theOperator)
 {
@@ -49,18 +40,24 @@ HYDROOperations_Factory::HYDROOperations_Factory()
 }
 
 ImageComposer_Operator* HYDROOperations_Factory::Operator(
-  Handle(HYDROData_Image) theImage) const
+  Handle(HYDROData_Image) theImage ) const
 {
   // retreive operator instance by name
-  ImageComposer_Operator* anOp = Operator(theImage->OperatorName());
-  if (!anOp)
+  ImageComposer_Operator* anOp = Operator( theImage->OperatorName() );
+  if ( !anOp )
     return anOp;
+
   // fill arguments of the operator from theImage
-  theImage->Args();
-  anOp->setBinArgs(theImage->Args());
+  anOp->setBinArgs( theImage->Args() );
+
   return anOp;
 }
 
+ImageComposer_Operator* HYDROOperations_Factory::Operator(const QString theName) const
+{
+  return myOps.contains( theName ) ? myOps[ theName ] : NULL;
+}
+
 Handle(HYDROData_Image) HYDROOperations_Factory::CreateImage(
   Handle(HYDROData_Document) theDoc, const ImageComposer_Operator* theOperator)
 {
@@ -74,68 +71,3 @@ Handle(HYDROData_Image) HYDROOperations_Factory::CreateImage(
   }
   return anImage;
 }
-
-void HYDROOperations_Factory::UpdateImage(
-  Handle_HYDROData_Document theDoc, Handle(HYDROData_Image) theImage)
-{
-  // fill by arguments and process the operation
-  ImageComposer_Operator* anOp = Operator(theImage);
-  if (anOp) { // update image only if there is an operation
-    QTransform aTransform;
-    ImageComposer_Image anImage1; // first referenced image
-    if (theImage->NbReferences()) {
-      Handle(HYDROData_Image) anImage =
-        Handle(HYDROData_Image)::DownCast( theImage->Reference(0) );
-      if( !anImage.IsNull() )
-      {
-        anImage1 = anImage->Image();
-        anImage1.setTransform(anImage->Trsf());
-        aTransform = anImage1.transform();
-      }
-    }
-    ImageComposer_Image anImage2; // second referenced image
-    if (theImage->NbReferences() > 1) {
-      Handle(HYDROData_Image) anImage =
-        Handle(HYDROData_Image)::DownCast( theImage->Reference(1) );
-      if( !anImage.IsNull() )
-      {
-        anImage2 = anImage->Image();
-        anImage2.setTransform(anImage->Trsf());
-      }
-    }
-    ImageComposer_Image aResImg = anOp->process(anImage1, anImage2);
-    theImage->SetImage(aResImg);
-    theImage->SetTrsf(aTransform);
-  }
-  // change the states of this and all depended images
-  theImage->MustBeUpdated(true);
-  SetMustBeUpdatedImages(theDoc);
-  theImage->MustBeUpdated(false);
-}
-
-void HYDROOperations_Factory::SetMustBeUpdatedImages(
-  Handle_HYDROData_Document theDoc) const
-{
-  bool aChanged = true;
-  // iterate until there is no changes because images on all level of dependency must be updated
-  while(aChanged) {
-    aChanged = false;
-    HYDROData_Iterator anIter(theDoc, KIND_IMAGE);
-    for(; anIter.More(); anIter.Next()) {
-      Handle(HYDROData_Image) anImage = 
-        Handle(HYDROData_Image)::DownCast(anIter.Current());
-      if (!anImage->MustBeUpdated()) {
-        int a, aNBRefs = anImage->NbReferences();
-        for(a = 0; a < aNBRefs; a++) {
-          Handle(HYDROData_Image) aRefImage =
-            Handle(HYDROData_Image)::DownCast(anImage->Reference(a));
-          if (!aRefImage.IsNull() && aRefImage->MustBeUpdated()) {
-             // image references to updated => also must be updated
-             anImage->MustBeUpdated(true);
-             aChanged = true;
-          }
-        }
-      }
-    }
-  }
-}
index 7ef2c0e044431291cc23785862ab242c13036f42..310280a7df1c8ab8fb81a2025615abb481a483d1 100644 (file)
@@ -44,15 +44,6 @@ public:
   HYDRODATA_EXPORT Handle(HYDROData_Image) CreateImage(
     Handle_HYDROData_Document theDoc, const ImageComposer_Operator* theOperator);
 
-  /**
-   * Updates an Image object in the data structure. If it is changed, 
-   * sets "MustBeUpdated" flag to other depended images.
-   * \param theDoc document of this image (needed to update other images flags)
-   * \param theImage the updated image
-   */
-  HYDRODATA_EXPORT void UpdateImage(
-    Handle_HYDROData_Document theDoc, Handle(HYDROData_Image) theImage);
-
   /**
    * Returns the operator, initialized by the properties of theImage
    * \param theImage data structures object, that contains all arguments 
@@ -63,23 +54,17 @@ public:
     Handle(HYDROData_Image) theImage) const;
  
 
-protected:
-
-  //! Not public constructor that creates only one, global instance of this factory.
-  HYDROOperations_Factory();
-
   /**
    * Returns the appropriate operator by the name
    * \param theName name of the operator, equals to the operation_name constructor
    * \returns NULL if operator with such name is not registered yet
    */
-  ImageComposer_Operator* Operator(const QString theName) const;
-  
-  /**
-   * Enables "MustBeUpdated" flag for Images that are depended on "MustBeUpdated" images.
-   * \param theDoc document where this operation is performed
-   */
-  void SetMustBeUpdatedImages(Handle_HYDROData_Document theDoc) const;
+  HYDRODATA_EXPORT ImageComposer_Operator* Operator(const QString theName) const;
+
+protected:
+
+  //! Not public constructor that creates only one, global instance of this factory.
+  HYDROOperations_Factory();  
 
 private:
   //! Map that stores all operators, isentified by strings
index 86055e826db3dd3f7a4acb36a3dd9be0e4624ee3..3ad1959d30b56bcc2ae585a643639ca30b72fcab 100644 (file)
@@ -300,8 +300,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
     module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), anImageObj, true );
 
   if( myIsEdit )
-    if( HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory() )
-      aFactory->UpdateImage( doc(), anImageObj );
+    anImageObj->Update();
 
   theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced;
   return true;
index 19baa6a735c42a902779bedb56a32e215ddbed79..2e634382f1ceb9087742f3afddf13f33b924bf29 100644 (file)
@@ -160,54 +160,43 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
     return false;
 
   HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
-  Handle(HYDROData_Image) aResult = 0;
+
+  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 );
   }
 
-  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 )
   {
index 09d31a9defa64f5ad490befae522a5d590a70bfb..0ac92a748e520d4b67df3feab9247d96e22ea902 100644 (file)
@@ -29,8 +29,6 @@
 #include <HYDROData_Document.h>
 #include <HYDROData_Image.h>
 
-#include <HYDROOperations_Factory.h>
-
 HYDROGUI_UpdateImageOp::HYDROGUI_UpdateImageOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule )
 {
@@ -53,10 +51,7 @@ void HYDROGUI_UpdateImageOp::startOperation()
     Handle(HYDROData_Image) anImage =
       Handle(HYDROData_Image)::DownCast( aSeq.Value( anIndex ) );
     if( !anImage.IsNull() && anImage->MustBeUpdated() )
-    {
-      HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
-      aFactory->UpdateImage( doc(), anImage );
-    }
+      anImage->Update();
   }
 
   commitDocOperation();