-#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>
#include <TDF_ListIteratorOfLabelList.hxx>
#include <ImageComposer_Operator.h>
+#include <ImageComposer_MetaTypes.h>
#include <QStringList>
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()) {
*/
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
#include <QString>
#include <QStringList>
+#include <QVariant>
IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
return anEmptyList;
}
+void HYDROData_Object::Update()
+{
+}
+
+QVariant HYDROData_Object::GetDataVariant()
+{
+ return QVariant();
+}
+
bool HYDROData_Object::IsRemoved() const
{
return !myLab.HasAttribute();
#include <QMap>
class QString;
+class QVariant;
class QStringList;
///! Kind of an object in a document
*/
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
#include <HYDROData_Polyline.h>
#include <HYDROData_Iterator.h>
+#include <ImageComposer_MetaTypes.h>
+
#include <TDataStd_Name.hxx>
#include <TDataStd_Integer.hxx>
#include <TDataStd_ByteArray.hxx>
#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
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.
*/
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
#include "HYDROData_Tool.h"
+#include "HYDROData_Image.h"
+#include "HYDROData_Iterator.h"
+
#include <QFile>
#include <QStringList>
#include <QTextStream>
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;
+ }
+ }
+ }
+ }
+}
class QFile;
class QStringList;
+class Handle_HYDROData_Document;
class HYDROData_Tool {
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 )
#include<ImageComposer_CropOperator.h>
#include<ImageComposer_CutOperator.h>
#include<ImageComposer_FuseOperator.h>
-#include<ImageComposer_Image.h>
#include <typeinfo>
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)
{
}
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)
{
}
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;
- }
- }
- }
- }
- }
-}
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
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
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;
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 )
{
#include <HYDROData_Document.h>
#include <HYDROData_Image.h>
-#include <HYDROOperations_Factory.h>
-
HYDROGUI_UpdateImageOp::HYDROGUI_UpdateImageOp( HYDROGUI_Module* theModule )
: HYDROGUI_Operation( theModule )
{
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();