#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 <HYDROOperations_Factory.h>
+#include <HYDROData_OperationsFactory.h>
#include <ImageComposer_CutOperator.h>
+#include <ImageComposer_CropOperator.h>
#include <ImageComposer_FuseOperator.h>
-HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType )
+#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 )
: HYDROGUI_Operation( theModule ),
myType( theType ),
- myIsEdit( false ),
+ myIsEdit( theIsEdit ),
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 )
{
- case Fuse: aName = tr( "FUSE" ); break;
- case Cut: aName = tr( "CUT" ); break;
+ case Fuse: aName = theIsEdit ? tr( "EDIT_FUSED_IMAGE" ) : tr( "FUSE_IMAGES" ); break;
+ case Cut: aName = theIsEdit ? tr( "EDIT_CUT_IMAGE" ) : tr( "CUT_IMAGES" ); break;
+ case Split: aName = theIsEdit ? tr( "EDIT_SPLITTED_IMAGE" ) : tr( "SPLIT_IMAGE" ); break;
default: break;
}
setName( aName );
HYDROGUI_TwoImagesDlg* aPanel = (HYDROGUI_TwoImagesDlg*)inputPanel();
aPanel->reset();
+ int aMode;
+ if( myType == Fuse )
+ aMode = HYDROGUI_TwoImagesDlg::TwoFuseImage;
+ if ( myType == Cut )
+ aMode = HYDROGUI_TwoImagesDlg::TwoCutImage;
+ else if( myType == Split )
+ aMode = HYDROGUI_TwoImagesDlg::ImageAndPolyline;
+ aPanel->setMode( aMode, myIsEdit );
+
QString anImageName;
if( myIsEdit )
{
+ myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
if( !myEditedObject.IsNull() )
anImageName = myEditedObject->GetName();
}
else
- anImageName = HYDROGUI_Tool::GenerateObjectName( module(), getName() );
+ {
+ QString aPrefix;
+ switch( myType )
+ {
+ case Fuse: aPrefix = tr( "FUSE" ); break;
+ case Cut: aPrefix = tr( "CUT" ); break;
+ case Split: aPrefix = tr( "SPLIT" ); break;
+ default: break;
+ }
+ anImageName = HYDROGUI_Tool::GenerateObjectName( module(), aPrefix );
+ }
aPanel->setImageName( anImageName );
QString aSelectedName1, aSelectedName2;
{
if( myEditedObject->NbReferences() > 0 )
{
- Handle(HYDROData_Image) anImage1 = myEditedObject->Reference( 0 );
- if( !anImage1.IsNull() )
- aSelectedName1 = anImage1->GetName();
+ Handle(HYDROData_Entity) anObject1 = myEditedObject->Reference( 0 );
+ if( !anObject1.IsNull() )
+ aSelectedName1 = anObject1->GetName();
}
if( myEditedObject->NbReferences() > 1 )
{
- Handle(HYDROData_Image) anImage2 = myEditedObject->Reference( 1 );
- if( !anImage2.IsNull() )
- aSelectedName2 = anImage2->GetName();
+ Handle(HYDROData_Entity) anObject2 = myEditedObject->Reference( 1 );
+ if( !anObject2.IsNull() )
+ aSelectedName2 = anObject2->GetName();
+ }
+ aPanel->setSelectedObjects( aSelectedName1, aSelectedName2 );
+
+ HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
+ if( ImageComposer_Operator* anOperator = aFactory->Operator( myEditedObject ) )
+ {
+ QColor aColor;
+ anOperator->getArgs( aColor );
+ aPanel->setColor( aColor );
}
- aPanel->setSelectedImages( aSelectedName1, aSelectedName2 );
}
+ 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() );
+ bool anIsModifySelected = myType == Split && aPanel->isModifySelected();
+
QString anImageName = aPanel->getImageName();
- if( anImageName.isEmpty() )
+ if( !anIsModifySelected && anImageName.isEmpty() )
return false;
QString aSelectedName1, aSelectedName2;
- if( !aPanel->getSelectedImages( aSelectedName1, aSelectedName2 ) )
+ if( !aPanel->getSelectedObjects( aSelectedName1, aSelectedName2 ) )
return false;
- if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) )
+ if( !anIsModifySelected &&
+ ( !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 );
}
}
- Handle(HYDROData_Image) anImage1 = Handle(HYDROData_Image)::DownCast(
- HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_IMAGE ) );
- Handle(HYDROData_Image) anImage2 = Handle(HYDROData_Image)::DownCast(
- HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_IMAGE ) );
- if( anImage1.IsNull() || anImage2.IsNull() )
+ 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 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( anImage1 );
- aResult->AppendReference( anImage2 );
- aFactory->UpdateImage( doc(), aResult );
+ aResult->AppendReference( anObject1 );
+ aResult->AppendReference( anObject2 );
+
+ aResult->Update();
- if( !myIsEdit )
+ if( anIsModifySelected )
+ {
+ Handle(HYDROData_Image) aSelectedImage = Handle(HYDROData_Image)::DownCast( anObject1 );
+ if( !aSelectedImage.IsNull() )
+ {
+ aSelectedImage->SetIsSelfSplitted( true );
+ aSelectedImage->SetImage( aResult->Image() );
+ aSelectedImage->SetTrsf( aResult->Trsf() );
+ aResult->Remove();
+ }
+ }
+
+ if( !myIsEdit && !anIsModifySelected )
{
size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
- module()->setObjectVisible( aViewId, anImage1, false );
- module()->setObjectVisible( aViewId, anImage2, false );
+ module()->setObjectVisible( aViewId, anObject1, false );
+ module()->setObjectVisible( aViewId, anObject2, false );
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;
}