]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
ImageComposer API has been changed to support universal interface. (Feature #6)
authoradv <adv@opencascade.com>
Wed, 11 Sep 2013 12:28:31 +0000 (12:28 +0000)
committeradv <adv@opencascade.com>
Wed, 11 Sep 2013 12:28:31 +0000 (12:28 +0000)
15 files changed:
src/ImageComposer/CMakeLists.txt
src/ImageComposer/ImageComposer_ColorMaskOperator.cxx
src/ImageComposer/ImageComposer_ColorMaskOperator.h
src/ImageComposer/ImageComposer_CropOperator.cxx
src/ImageComposer/ImageComposer_CropOperator.h
src/ImageComposer/ImageComposer_CutOperator.cxx
src/ImageComposer/ImageComposer_CutOperator.h
src/ImageComposer/ImageComposer_FuseOperator.cxx
src/ImageComposer/ImageComposer_FuseOperator.h
src/ImageComposer/ImageComposer_Image.cxx
src/ImageComposer/ImageComposer_Image.h
src/ImageComposer/ImageComposer_MetaTypes.h [new file with mode: 0644]
src/ImageComposer/ImageComposer_Operator.cxx
src/ImageComposer/ImageComposer_Operator.h
src/ImageComposer/Makefile.am

index cda4cd568eab805d47a1192b4df712c40c65cf5f..1f1762f666b0d5b4c063382b733f6687493712e7 100755 (executable)
@@ -42,6 +42,7 @@ INSTALL(TARGETS ImageComposer DESTINATION ${GUI_salomelib_LIBS})
 
 SET(COMMON_HEADERS_H
   ImageComposer.h
+  ImageComposer_MetaTypes.h
   ImageComposer_ColorMaskOperator.h
   ImageComposer_CropOperator.h
   ImageComposer_CutOperator.h
index 3a788f54f6d99a0163bdb1df2e5e2a1fa62a69e1..d4aba21a36d24cca6844f2b701d2def9803b3dd7 100644 (file)
@@ -1,6 +1,6 @@
 
 #include "ImageComposer_ColorMaskOperator.h"
-#include "ImageComposer_Image.h"
+#include "ImageComposer_MetaTypes.h"
 #include <QRectF>
 #include <QRgb>
 #include <QPixmap>
@@ -78,19 +78,31 @@ QStringList ImageComposer_ColorMaskOperator::dumpArgsToPython( QString& theArray
 
 /**
 */
-QRectF ImageComposer_ColorMaskOperator::calcResultBoundingRect( const QRectF& theImage1Bounds
-                                                                const QRectF& ) const
+QRectF ImageComposer_ColorMaskOperator::calcResultBoundingRect( const QVariant& theObj1
+                                                                const QVariant& ) const
 {
-  return theImage1Bounds;
+  QRectF aResRect;
+  if ( !theObj1.isNull() && theObj1.canConvert<ImageComposer_Image>() )
+  {
+    ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+    aResRect = anImage1.boundingRect();
+  }
+  return aResRect;
 }
 
 /**
 */
-void ImageComposer_ColorMaskOperator::drawResult( QPainter& thePainter,
-                                                  const ImageComposer_Image& theImage1,
-                                                  const ImageComposer_Image& ) const
+void ImageComposer_ColorMaskOperator::drawResult( QPainter&       thePainter,
+                                                  const QVariant& theObj1,
+                                                  const QVariant& ) const
 {
-  QImage anImage = theImage1.convertToFormat( QImage::Format_ARGB32 );
+  if ( theObj1.isNull() || !theObj1.canConvert<ImageComposer_Image>() )
+    return;
+
+  ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+
+  QImage anImage = anImage1.convertToFormat( QImage::Format_ARGB32 );
+
   int aRMin = myRefColor.red()    - myRGBThreshold;
   int aRMax = myRefColor.red()    + myRGBThreshold;
   int aGMin = myRefColor.green()  - myRGBThreshold;
@@ -120,7 +132,7 @@ void ImageComposer_ColorMaskOperator::drawResult( QPainter& thePainter,
 
   ImageComposer_Image aResult;
   aResult = anImage;
-  aResult.setTransform( theImage1.transform() );
+  aResult.setTransform( anImage1.transform() );
   aResult.draw( thePainter );
 }
 
index d7903449134cb8747a6c88386cfc62bf87a595f5..8c078fbeeb56d578be6036124f3bc5c056873994 100644 (file)
@@ -32,10 +32,10 @@ public:
   QStringList dumpArgsToPython( QString& theArrayName ) const;
 
 protected:
-  virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds
-                                         const QRectF& theImage2Bounds ) const;
-  virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1,
-                                                 const ImageComposer_Image& theImage2 ) const;
+  virtual QRectF calcResultBoundingRect( const QVariant& theObj1
+                                         const QVariant& theObj2 ) const;
+  virtual void drawResult( QPainter& thePainter, const QVariant& theObj1,
+                                                 const QVariant& theObj2 ) const;
 
   virtual void storeArgs( QDataStream& theStream ) const;
   virtual void restoreArgs( QDataStream& theStream );
index 65aed89de5844d6545a97c010c3dea5b3eb4e605..08a10599ba097e336c35fc9f92f7b6cd4913f008 100644 (file)
@@ -1,6 +1,8 @@
 
 #include "ImageComposer_CropOperator.h"
 #include "ImageComposer_Image.h"
+#include "ImageComposer_MetaTypes.h"
+
 #include <QPixmap>
 #include <QPainter>
 
@@ -19,91 +21,73 @@ ImageComposer_CropOperator::~ImageComposer_CropOperator()
 }
 
 /**
-  Set operator arguments
-  @param theBackground the background color for result image
-  @param theRect the cropping rectangle (in the global CS)
 */
-void ImageComposer_CropOperator::setArgs( const QColor& theBackground, const QRect& theRect )
+QString ImageComposer_CropOperator::name() const
 {
-  ImageComposer_Operator::setArgs( theBackground );
-  myClipPath = QPainterPath();
-  myClipPath.addRect( theRect );
+  return Type();
 }
 
 /**
-  Set operator arguments
-  @param theBackground the background color for result image
-  @param thePath the cropping path (in the global CS)
 */
-void ImageComposer_CropOperator::setArgs( const QColor& theBackground, const QPainterPath& thePath )
+QRectF ImageComposer_CropOperator::calcResultBoundingRect( const QVariant&, 
+                                                           const QVariant& theObj2 ) const
 {
-  ImageComposer_Operator::setArgs( theBackground );
-  myClipPath = thePath;
+  QRectF aResRect;
+  if ( !theObj2.isNull() && theObj2.canConvert<QPainterPath>() )
+  {
+    QPainterPath aCropPath = theObj2.value<QPainterPath>();
+    aResRect = aCropPath.boundingRect();
+  }
+  return aResRect;
 }
 
 /**
-  Return clipping path
-  @return clipping path
 */
-QPainterPath ImageComposer_CropOperator::clipPath() const
+void ImageComposer_CropOperator::drawResult( QPainter&       thePainter,
+                                             const QVariant& theObj1,
+                                             const QVariant& theObj2 ) const
 {
-  return myClipPath;
-}
+  if ( theObj1.isNull() || !theObj1.canConvert<ImageComposer_Image>() ||
+       theObj2.isNull() || !theObj2.canConvert<QPainterPath>() )
+    return;
 
-/**
-*/
-QString ImageComposer_CropOperator::name() const
-{
-  return Type();
-}
+  ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+  QPainterPath anImgClipPath = theObj2.value<QPainterPath>();
 
-/**
-*/
-QRectF ImageComposer_CropOperator::calcResultBoundingRect( const QRectF&, const QRectF& ) const
-{
-  return myImgClipPath.boundingRect();
-}
+  QRectF aBounds = anImgClipPath.boundingRect();
 
-/**
-*/
-void ImageComposer_CropOperator::drawResult( QPainter& thePainter,
-                                             const ImageComposer_Image& theImage1,
-                                             const ImageComposer_Image& ) const
-{
-  QRectF aBounds = myImgClipPath.boundingRect();
   QTransform aTranslate;
   aTranslate.translate( -aBounds.left(), -aBounds.top() );
-  QPainterPath aClipPath = aTranslate.map( myImgClipPath );
+
+  QPainterPath aClipPath = aTranslate.map( anImgClipPath );
   thePainter.setClipPath( aClipPath );
-  theImage1.draw( thePainter );
+
+  anImage1.draw( thePainter );
   //thePainter.fillPath( aClipPath, Qt::red );
 }
 
 /**
 */
-ImageComposer_Image ImageComposer_CropOperator::process( const ImageComposer_Image& theImage1,
-                                                         const ImageComposer_Image& theImage2 ) const
+ImageComposer_Image ImageComposer_CropOperator::process( const QVariant& theObj1,
+                                                         const QVariant& theObj2 ) const
 {
-  QRect anImageRect( 0, 0, theImage1.width(), theImage1.height() );
-  QPainterPath anImageBoundsPath;
-  anImageBoundsPath.addPolygon( theImage1.transform().mapToPolygon( anImageRect ) );
+  ImageComposer_Image aResult;
+  if ( theObj1.isNull() || !theObj1.canConvert<ImageComposer_Image>() ||
+       theObj2.isNull() || !theObj2.canConvert<QPainterPath>() )
+    return aResult;
 
-  const_cast<ImageComposer_CropOperator*>( this )->myImgClipPath =
-    theImage1.transform().inverted().map( myClipPath.intersected( anImageBoundsPath ) );
+  ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+  QPainterPath aCropPath = theObj2.value<QPainterPath>();
 
-  return ImageComposer_Operator::process( theImage1, theImage2 );
-}
+  QRect anImageRect( 0, 0, anImage1.width(), anImage1.height() );
 
+  QPainterPath anImageBoundsPath;
+  anImageBoundsPath.addPolygon( anImage1.transform().mapToPolygon( anImageRect ) );
 
-void ImageComposer_CropOperator::storeArgs( QDataStream& theStream ) const
-{
-  ImageComposer_Operator::storeArgs( theStream );
-  theStream << myClipPath;
-}
+  // clipping path mapped to first image's local CS
+  QVariant anImgClipPath;
+  anImgClipPath.setValue<QPainterPath>( 
+    anImage1.transform().inverted().map( aCropPath.intersected( anImageBoundsPath ) ) );
 
-void ImageComposer_CropOperator::restoreArgs( QDataStream& theStream )
-{
-  ImageComposer_Operator::restoreArgs( theStream );
-  myClipPath = QPainterPath();
-  theStream >> myClipPath;
+  return ImageComposer_Operator::process( theObj1, anImgClipPath );
 }
index e1740c3327d79d032087f5f67c2e65a92c79afcc..20a5ee4ad8dc8f21088ddd0d1ee577b711a81f37 100644 (file)
@@ -16,32 +16,21 @@ public:
   ImageComposer_CropOperator();
   virtual ~ImageComposer_CropOperator();
 
-  void setArgs( const QColor& theBackground, const QRect& );
-  void setArgs( const QColor& theBackground, const QPainterPath& );
-
-  QPainterPath clipPath() const;
-
   static QString Type() { return "crop"; }
 
   virtual QString name() const;
 
-  virtual ImageComposer_Image process( const ImageComposer_Image& theImage1,
-                                       const ImageComposer_Image& theImage2 ) const;
+  virtual ImageComposer_Image process( const QVariant& theObj1,
+                                       const QVariant& theObj2 ) const;
 
 protected:
-  virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds, 
-                                         const QRectF& theImage2Bounds ) const;
-  virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1,
-                                                 const ImageComposer_Image& theImage2 ) const;
-
-  virtual void storeArgs( QDataStream& theStream ) const;
-  virtual void restoreArgs( QDataStream& theStream );
+  virtual QRectF calcResultBoundingRect( const QVariant& theObj1, 
+                                         const QVariant& theObj2 ) const;
+  virtual void drawResult( QPainter& thePainter, const QVariant& theObj1,
+                                                 const QVariant& theObj2 ) const;
 
 private:
   friend class ImageComposerTests_TestOperators;
-
-  QPainterPath myClipPath;     ///< the clipping path specified initially
-  QPainterPath myImgClipPath;  ///< the clipping path mapped to first image's local CS
 };
 
 #endif
index 25ceb4c83c040337198f0b0e9d46fdcadcb9c946..f0166bcf7e90ba2f24fa5700a06d65ca1a3d0b38 100644 (file)
@@ -1,6 +1,6 @@
 
 #include "ImageComposer_CutOperator.h"
-#include "ImageComposer_Image.h"
+#include "ImageComposer_MetaTypes.h"
 #include <QString>
 #include <QPixmap>
 #include <QPainter>
@@ -28,18 +28,33 @@ QString ImageComposer_CutOperator::name() const
 
 /**
 */
-QRectF ImageComposer_CutOperator::calcResultBoundingRect( const QRectF& theImage1Bounds
-                                                          const QRectF& ) const
+QRectF ImageComposer_CutOperator::calcResultBoundingRect( const QVariant& theObj1
+                                                          const QVariant& ) const
 {
-  return theImage1Bounds;
+  QRectF aResRect;
+  if ( !theObj1.isNull() && theObj1.canConvert<ImageComposer_Image>() )
+  {
+    ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+    aResRect = anImage1.boundingRect();
+  }
+  return aResRect;
 }
 
 /**
 */
-void ImageComposer_CutOperator::drawResult( QPainter& thePainter,
-                                            const ImageComposer_Image& theImage1,
-                                            const ImageComposer_Image& theImage2 ) const
+void ImageComposer_CutOperator::drawResult( QPainter&       thePainter,
+                                            const QVariant& theObj1,
+                                            const QVariant& theObj2 ) const
 {
-  theImage1.draw( thePainter );
-  theImage2.draw( thePainter );
+  if ( !theObj1.isNull() && theObj1.canConvert<ImageComposer_Image>() )
+  {
+    ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+    anImage1.draw( thePainter );
+  }
+
+  if ( !theObj2.isNull() && theObj2.canConvert<ImageComposer_Image>() )
+  {
+    ImageComposer_Image anImage2 = theObj2.value<ImageComposer_Image>();
+    anImage2.draw( thePainter );
+  }
 }
index 15026dc3c80be09ae10b4f278cc9a1b39ceca3ae..f88ea73bf4045bf517635c12e7e5c287058eab8b 100644 (file)
@@ -20,10 +20,10 @@ public:
   virtual QString name() const;
 
 protected:
-  virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds
-                                         const QRectF& theImage2Bounds ) const;
-  virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1,
-                                                 const ImageComposer_Image& theImage2 ) const;
+  virtual QRectF calcResultBoundingRect( const QVariant& theObj1
+                                         const QVariant& theObj2 ) const;
+  virtual void drawResult( QPainter& thePainter, const QVariant& theObj1,
+                                                 const QVariant& theObj2 ) const;
 };
 
 #endif
index e23d58296bb83ec34622fa303c0f741a90f715df..2106503f045a6c51e2ae728cd00587c9c5ebb69f 100644 (file)
@@ -1,6 +1,6 @@
 
 #include "ImageComposer_FuseOperator.h"
-#include "ImageComposer_Image.h"
+#include "ImageComposer_MetaTypes.h"
 #include <QString>
 #include <QPixmap>
 #include <QPainter>
@@ -28,18 +28,36 @@ QString ImageComposer_FuseOperator::name() const
 
 /**
 */
-QRectF ImageComposer_FuseOperator::calcResultBoundingRect( const QRectF& theImage1Bounds
-                                                           const QRectF& theImage2Bounds ) const
+QRectF ImageComposer_FuseOperator::calcResultBoundingRect( const QVariant& theObj1
+                                                           const QVariant& theObj2 ) const
 {
-  return theImage1Bounds.united( theImage2Bounds );
+  QRectF aResRect;
+  if ( !theObj1.isNull() && theObj1.canConvert<ImageComposer_Image>() &&
+       !theObj2.isNull() && theObj2.canConvert<ImageComposer_Image>() )
+  {
+    ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+    ImageComposer_Image anImage2 = theObj2.value<ImageComposer_Image>();
+
+    aResRect = anImage1.boundingRect().united( anImage2.boundingRect() );
+  }
+  return aResRect;
 }
 
 /**
 */
-void ImageComposer_FuseOperator::drawResult( QPainter& thePainter,
-                                             const ImageComposer_Image& theImage1,
-                                             const ImageComposer_Image& theImage2 ) const
+void ImageComposer_FuseOperator::drawResult( QPainter&       thePainter,
+                                             const QVariant& theObj1,
+                                             const QVariant& theObj2 ) const
 {
-  theImage1.draw( thePainter );
-  theImage2.draw( thePainter );
+  if ( !theObj1.isNull() && theObj1.canConvert<ImageComposer_Image>() )
+  {
+    ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+    anImage1.draw( thePainter );
+  }
+
+  if ( !theObj2.isNull() && theObj2.canConvert<ImageComposer_Image>() )
+  {
+    ImageComposer_Image anImage2 = theObj2.value<ImageComposer_Image>();
+    anImage2.draw( thePainter );
+  }
 }
index ac9c5f60b7f303b8d9f72774234a94252d459570..bdeb5e0f94b22deec7f73b6c27b21eadd35cbe24 100644 (file)
@@ -20,10 +20,10 @@ public:
   virtual QString name() const;
 
 protected:
-  virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds
-                                         const QRectF& theImage2Bounds ) const;
-  virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1,
-                                                 const ImageComposer_Image& theImage2 ) const;
+  virtual QRectF calcResultBoundingRect( const QVariant& theObj1
+                                         const QVariant& theObj2 ) const;
+  virtual void drawResult( QPainter& thePainter, const QVariant& theObj1,
+                                                 const QVariant& theObj2 ) const;
 };
 
 #endif
index a7b1a7e6f98dec1a75a7070233265fa53b444ed5..a0e20230a1cd032634bee390812e4b68da5bbc99 100644 (file)
@@ -3,6 +3,8 @@
 #include "ImageComposer_CropOperator.h"
 #include "ImageComposer_CutOperator.h"
 #include "ImageComposer_FuseOperator.h"
+#include "ImageComposer_MetaTypes.h"
+
 #include <QPainter>
 
 QColor ImageComposer_Image::myDefaultBackground = TRANSPARENT;
@@ -14,6 +16,23 @@ ImageComposer_Image::ImageComposer_Image()
 {
 }
 
+/**
+  Copy constructor
+*/
+ImageComposer_Image::ImageComposer_Image( const ImageComposer_Image& theImage )
+ : QImage( theImage ),
+   myTransform( theImage.myTransform )
+{
+}
+
+/**
+  Copy constructor
+*/
+ImageComposer_Image::ImageComposer_Image( const QImage& theImage )
+ : QImage( theImage )
+{
+}
+
 /**
   Destructor
 */
@@ -107,9 +126,12 @@ const QImage& ImageComposer_Image::operator = ( const QImage& theImage )
   @return the result image
 */
 ImageComposer_Image ImageComposer_Image::apply( const ImageComposer_Operator& theOperator,
-                                                const ImageComposer_Image& theImage ) const
+                                                const QVariant&               theOtherObj ) const
 {
-  return theOperator.process( *this, theImage );
+  QVariant aVarData;
+  aVarData.setValue<ImageComposer_Image>( *this );
+
+  return theOperator.process( aVarData, theOtherObj );
 }
 
 /**
@@ -137,9 +159,9 @@ void ImageComposer_Image::setDefaultBackground( const QColor& theDefaultBackgrou
 */
 ImageComposer_Image ImageComposer_Image::operator & ( const QRect& theRect ) const
 {
-  ImageComposer_CropOperator anOp;
-  anOp.setArgs( myDefaultBackground, theRect );
-  return apply( anOp );
+  QPainterPath aPath;
+  aPath.addRect( theRect );
+  return operator &( aPath );
 }
 
 /**
@@ -150,8 +172,12 @@ ImageComposer_Image ImageComposer_Image::operator & ( const QRect& theRect ) con
 ImageComposer_Image ImageComposer_Image::operator & ( const QPainterPath& thePath ) const
 {
   ImageComposer_CropOperator anOp;
-  anOp.setArgs( myDefaultBackground, thePath );
-  return apply( anOp );
+  anOp.setArgs( myDefaultBackground );
+
+  QVariant aVarData;
+  aVarData.setValue<QPainterPath>( thePath );
+
+  return apply( anOp, aVarData );
 }
 
 /**
@@ -163,7 +189,11 @@ ImageComposer_Image ImageComposer_Image::operator & ( const ImageComposer_Image&
 {
   ImageComposer_CutOperator anOp;
   anOp.setArgs( myDefaultBackground );
-  return apply( anOp, theImage );
+
+  QVariant aVarData;
+  aVarData.setValue<ImageComposer_Image>( theImage );
+
+  return apply( anOp, aVarData );
 }
 
 /**
@@ -175,5 +205,9 @@ ImageComposer_Image ImageComposer_Image::operator | ( const ImageComposer_Image&
 {
   ImageComposer_FuseOperator anOp;
   anOp.setArgs( myDefaultBackground );
-  return apply( anOp, theImage );
+
+  QVariant aVarData;
+  aVarData.setValue<ImageComposer_Image>( theImage );
+
+  return apply( anOp, aVarData );
 }
index fe3db0186aead11c22ece25116d4d5fdd8efbd6d..55799631daa1fff450d89371f6ec60718c4f18d3 100644 (file)
@@ -2,9 +2,11 @@
 #ifndef IMAGE_COMPOSER_IMAGE_HEADER
 #define IMAGE_COMPOSER_IMAGE_HEADER
 
-#include <QImage>
 #include "ImageComposer.h"
 
+#include <QImage>
+
+class QVariant;
 class ImageComposer_Operator;
 
 /**
@@ -15,6 +17,8 @@ class IMAGE_COMPOSER_API ImageComposer_Image : public QImage
 {
 public:
   ImageComposer_Image();
+  ImageComposer_Image( const ImageComposer_Image& theImage );
+  ImageComposer_Image( const QImage& theImage );
   ~ImageComposer_Image();
 
   void draw( QPainter& thePainter ) const;
@@ -29,7 +33,7 @@ public:
   const QImage& operator = ( const QImage& theImage );
 
   ImageComposer_Image apply( const ImageComposer_Operator& theOperator,
-                             const ImageComposer_Image& theImage = ImageComposer_Image() ) const;
+                             const QVariant&               theOtherObj ) const;
 
   static QColor defaultBackground();
   static void setDefaultBackground( const QColor& );
diff --git a/src/ImageComposer/ImageComposer_MetaTypes.h b/src/ImageComposer/ImageComposer_MetaTypes.h
new file mode 100644 (file)
index 0000000..1209669
--- /dev/null
@@ -0,0 +1,13 @@
+
+
+#include "ImageComposer_Image.h"
+
+#include <QVariant>
+#include <QPainterPath>
+
+// Here we declare the meta types for classes which used by
+// ImageComposer operators so that it could be wrapped to QVariant
+
+Q_DECLARE_METATYPE(QPainterPath)
+Q_DECLARE_METATYPE(ImageComposer_Image)
+
index e296b4d4dab40b0c05b7586b1a8faf74e70e0160..cb9a75eb0131bb2571188f6acfc3732382c4b78f 100644 (file)
@@ -1,6 +1,6 @@
 
 #include "ImageComposer_Operator.h"
-#include "ImageComposer_Image.h"
+#include "ImageComposer_MetaTypes.h"
 #include <QPixmap>
 #include <QPainter>
 
@@ -39,25 +39,33 @@ void ImageComposer_Operator::setArgs( const QColor& theBackground )
 
 /**
   Perform the composing of images
-  @param theImage1 the first image to compose
-  @param theImage2 the second image to compose
+  @param theObj1 the first object to compose
+  @param theObj2 the second object to compose
   @return the result image
 */
-ImageComposer_Image ImageComposer_Operator::process( const ImageComposer_Image& theImage1,
-                                                     const ImageComposer_Image& theImage2 ) const
+ImageComposer_Image ImageComposer_Operator::process( const QVariant& theObj1,
+                                                     const QVariant& theObj2 ) const
 {
-  ImageComposer_Image anImage1 = theImage1;
-  ImageComposer_Image anImage2 = theImage2;
+  ImageComposer_Image aResult;
+  if ( theObj1.isNull() || !theObj1.canConvert<ImageComposer_Image>() )
+    return aResult;
+
+  ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+
+  ImageComposer_Image anImage2;
+  if ( !theObj1.isNull() && theObj2.canConvert<ImageComposer_Image>() )
+    anImage2 = theObj2.value<ImageComposer_Image>();
+
   QTransform aInvTransform = anImage1.transform().inverted();
   anImage1.setTransform( anImage1.transform() * aInvTransform );
   if( !anImage2.isNull() )
     anImage2.setTransform( anImage2.transform() * aInvTransform );
   
-  QRectF aBounds1 = anImage1.boundingRect();
-  QRectF aBounds2;
-  if( !anImage2.isNull() )
-    aBounds2 = anImage2.boundingRect();
-  QRectF aBounds = calcResultBoundingRect( aBounds1, aBounds2 );
+  QVariant anImage1Var, anImage2Var;
+  anImage1Var.setValue<ImageComposer_Image>( anImage1 );
+  anImage2Var.setValue<ImageComposer_Image>( anImage2 );
+
+  QRectF aBounds = calcResultBoundingRect( anImage1Var, !anImage2.isNull() ? anImage2Var : theObj2 );
 
   QTransform aTranslate;
   aTranslate.translate( -aBounds.left(), -aBounds.top() );
@@ -72,13 +80,19 @@ ImageComposer_Image ImageComposer_Operator::process( const ImageComposer_Image&
   aPainter.setRenderHint( QPainter::Antialiasing, true );
   aPainter.setRenderHint( QPainter::HighQualityAntialiasing, true );
 
-  drawResult( aPainter, anImage1, anImage2 );
+  anImage1Var.setValue<ImageComposer_Image>( anImage1 );
+  anImage2Var.setValue<ImageComposer_Image>( anImage2 );
 
-  ImageComposer_Image aResult;
-  aResult = aResultImage.toImage();
-  QTransform aResultTransform = theImage1.transform();
+  drawResult( aPainter, anImage1Var, !anImage2.isNull() ? anImage2Var : theObj2 );
+
+  anImage1 = theObj1.value<ImageComposer_Image>();
+
+  QTransform aResultTransform = anImage1.transform();
   aResultTransform.translate( aBounds.left(), aBounds.top() );
+
+  aResult = aResultImage.toImage();
   aResult.setTransform( aResultTransform );
+
   return aResult;
 }
 
index ab29b6359819a7d29c88aa770096fe52e55d1fa4..b61a3e2f2f9ac8deeca51d6f0c98a4850e115533 100644 (file)
@@ -3,12 +3,14 @@
 #define IMAGE_COMPOSER_OPERATOR_HEADER
 
 #include "ImageComposer.h"
+
 #include <QColor>
 
 class QString;
 class QRectF;
 class QPainter;
 class QTransform;
+class QVariant;
 class ImageComposer_Image;
 
 const QColor TRANSPARENT( 255, 255, 255, 0 );
@@ -42,27 +44,27 @@ public:
   */
   virtual QString name() const = 0;
 
-  virtual ImageComposer_Image process( const ImageComposer_Image& theImage1,
-                                       const ImageComposer_Image& theImage2 ) const;
+  virtual ImageComposer_Image process( const QVariant& theObj1,
+                                       const QVariant& theObj2 ) const;
 
 protected:
   /**
     Calculate bounding rectangle for the result image
-    @param theImage1Bounds bounding rectangle of the first image
-    @param theImage2Bounds bounding rectangle of the second image
+    @param theObj1 first object to calculate
+    @param theObj2 second object to calculate
     @return calculated bounding rectangle
   */
-  virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds
-                                         const QRectF& theImage2Bounds ) const = 0;
+  virtual QRectF calcResultBoundingRect( const QVariant& theObj1
+                                         const QVariant& theObj2 ) const = 0;
 
   /**
     Draw result image using the given painter
     @param thePainter the painter on the result image
-    @param theImage1 the first image to compose
-    @param theImage2 the second image to compose
+    @param theObj1 the first object to compose
+    @param theObj2 the second object to compose
   */
-  virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1,
-                                                 const ImageComposer_Image& theImage2 ) const = 0;
+  virtual void drawResult( QPainter& thePainter, const QVariant& theObj1,
+                                                 const QVariant& theObj2 ) const = 0;
 
   virtual void storeArgs( QDataStream& theStream ) const;
   virtual void restoreArgs( QDataStream& theStream );
index 889c70cc5ce5813a4b1b3b4cbfce9ff8be741da3..df7e00d8e1f0e1a2efa06c53eead5806e6276cc9 100644 (file)
@@ -21,21 +21,22 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am
 
 lib_LTLIBRARIES = libImageComposer.la
 
-salomeinclude_HEADERS =                        \
-ImageComposer.h                                \
+salomeinclude_HEADERS =             \
+ImageComposer.h                     \
+ImageComposer_MetaTypes.h           \
 ImageComposer_ColorMaskOperator.h      \
-ImageComposer_CropOperator.h           \
-ImageComposer_CutOperator.h            \
-ImageComposer_FuseOperator.h           \
-ImageComposer_Image.h                  \
+ImageComposer_CropOperator.h        \
+ImageComposer_CutOperator.h         \
+ImageComposer_FuseOperator.h        \
+ImageComposer_Image.h               \
 ImageComposer_Operator.h
 
-dist_libImageComposer_la_SOURCES =     \
-ImageComposer_ColorMaskOperator.cxx    \
-ImageComposer_CropOperator.cxx         \
-ImageComposer_CutOperator.cxx          \
-ImageComposer_FuseOperator.cxx         \
-ImageComposer_Image.cxx                        \
+dist_libImageComposer_la_SOURCES =  \
+ImageComposer_ColorMaskOperator.cxx \
+ImageComposer_CropOperator.cxx      \
+ImageComposer_CutOperator.cxx       \
+ImageComposer_FuseOperator.cxx      \
+ImageComposer_Image.cxx             \
 ImageComposer_Operator.cxx
 
 libImageComposer_la_CPPFLAGS = $(QT_INCLUDES)