From: rkv Date: Tue, 5 Nov 2013 08:20:15 +0000 (+0000) Subject: - Zones drag and drop in the Calculation Case wizard is implemented. X-Git-Tag: BR_hydro_v_0_3~50 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0676b7539aa0e59468673e1d3b44ea8a897aa9fc;p=modules%2Fhydro.git - Zones drag and drop in the Calculation Case wizard is implemented. - "New region" item is added in the regions tree in Calculation Case wizard. --- diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index c06ab638..0de08e8a 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -197,13 +197,14 @@ void HYDROGUI_CalculationDlg::onZonesDropped( const QList& the if ( aRegionsRoot ) { // Create a new region + emit createRegion( aZonesList ); } else { HYDROGUI_Region* aRegion = dynamic_cast(theTargetParent); if ( aRegion ) { - aRegion->addZones( ); + emit moveZones( theTargetParent, aZonesList ); } } } @@ -309,8 +310,7 @@ void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_Calculatio HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" ); myBrowser->setRoot(anobj); - LightApp_DataObject* aCaseItem = module()->getDataModel()->createObject( anobj, - myEditedObject, "", true ); + module()->getDataModel()->buildCaseTree( anobj, myEditedObject ); myBrowser->updateTree(); myBrowser->openLevels(); myBrowser->adjustColumnsWidth(); diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index e2791f21..627c9fe7 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -80,7 +80,9 @@ signals: void addObjects(); void removeObjects(); void splitZones(); - void setMergeType( int theMergeType, QString theBathymetryName ); + void setMergeType( int theMergeType, QString& theBathymetryName ); + void createRegion( const QList& theZonesList ); + void moveZones( SUIT_DataObject* theRegion, const QList& theZonesList ); private: diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 3dab9422..2e8744cb 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -28,6 +28,7 @@ #include "HYDROGUI_Tool.h" #include "HYDROGUI_UpdateFlags.h" #include "HYDROGUI_Zone.h" +#include "HYDROGUI_Region.h" #include #include @@ -151,12 +152,70 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) ); connect( aPanel, SIGNAL( splitZones() ), SLOT( onSplitZones() ) ); connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) ); - connect( aPanel, SIGNAL( setMergeType( int, QString ) ), SLOT( onSetMergeType( int, QString ) ) ); + connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) ); + connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList& ) ), + SLOT( onMoveZones( SUIT_DataObject*, const QList& ) ) ); + connect( aPanel, SIGNAL( createRegion( const QList& ) ), + SLOT( onCreateRegion( const QList& ) ) ); return aPanel; } -void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString theBathymetryName ) +void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList& theZonesList ) +{ + HYDROGUI_Region* aRegion = dynamic_cast(theRegionItem); + if ( aRegion ) + { + QList aZonesList; + HYDROGUI_Zone* aZone; + // Get a list of dropped zones + for ( int i = 0; i < theZonesList.length(); i++ ) + { + aZone = dynamic_cast( theZonesList.at( i ) ); + if ( aZone ) + { + aZonesList.append( aZone ); + } + } + if ( aZonesList.length() > 0 ) + { + aRegion->addZones( aZonesList ); + HYDROGUI_CalculationDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( aPanel ) + { + aPanel->setEditedObject(myEditedObject); + } + } + } +} + +void HYDROGUI_CalculationOp::onCreateRegion( const QList& theZonesList ) +{ + QList aZonesList; + HYDROGUI_Zone* aZone; + // Get a list of dropped zones + for ( int i = 0; i < theZonesList.length(); i++ ) + { + aZone = dynamic_cast( theZonesList.at( i ) ); + if ( aZone ) + { + aZonesList.append( aZone ); + } + } + if ( aZonesList.length() > 0 ) + { + module()->getDataModel()->createNewRegion( myEditedObject, aZonesList ); + HYDROGUI_CalculationDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( aPanel ) + { + aPanel->setEditedObject(myEditedObject); + } + } +} + +void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theBathymetryName ) { HYDROGUI_CalculationDlg* aPanel = ::qobject_cast( inputPanel() ); diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.h b/src/HYDROGUI/HYDROGUI_CalculationOp.h index 729db62e..3cf13988 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.h +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.h @@ -34,6 +34,7 @@ class SUIT_ViewManager; class OCCViewer_ViewManager; class HYDROGUI_CalculationDlg; +class SUIT_DataObject; class HYDROGUI_CalculationOp : public HYDROGUI_Operation { @@ -92,7 +93,10 @@ protected slots: /** * Set the given bathymetry merge type to the current zone. */ - void onSetMergeType( int theMergeType, QString theBathymetryName ); + void onSetMergeType( int theMergeType, QString& theBathymetryName ); + void onMoveZones( SUIT_DataObject* theRegionItem, + const QList& theZonesList ); + void onCreateRegion( const QList& theZonesList ); void onSplitZones(); void onLastViewClosed( SUIT_ViewManager* ); diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index dbe6cead..b15b99ac 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -653,6 +653,24 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, } } +void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase ) +{ + if ( !theCase.IsNull() ) + { + new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "" ); + + HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions(); + HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Region) aCaseRegion = + Handle(HYDROData_Region)::DownCast( anIter.Value() ); + if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() ) + createRegion( theParent, aCaseRegion, "", true ); + } + } +} + void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent, SUIT_DataObject* theChild ) { @@ -674,3 +692,34 @@ SUIT_DataObject* HYDROGUI_DataModel::findChildByName( const SUIT_DataObject* the } return NULL; // not found } + +bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theCase, + const QList& theZonesList ) +{ + bool isOk = !theCase.IsNull(); + if ( isOk ) + { + Handle(HYDROData_Region) aRegion; + Handle(HYDROData_Zone) aZone; + for (int i = 0; i < theZonesList.length(); i++ ) + { + aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() ); + if ( !aZone.IsNull() ) + { + if ( aRegion.IsNull() ) + { + aRegion = theCase->AddNewRegion( aZone ); + isOk = !aRegion.IsNull(); + } + else + { + if ( !( aRegion->AddZone( aZone ) ) ) + { + isOk = false; + } + } + } + } + } + return isOk; +} diff --git a/src/HYDROGUI/HYDROGUI_DataModel.h b/src/HYDROGUI/HYDROGUI_DataModel.h index bfc590e7..060a3db5 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.h +++ b/src/HYDROGUI/HYDROGUI_DataModel.h @@ -27,8 +27,10 @@ #include #include #include +#include #include +#include #include #include @@ -36,6 +38,7 @@ class CAM_DataObject; class SUIT_DataObject; class HYDROGUI_DataObject; +class HYDROGUI_Zone; /** * \class HYDROGUI_DataModel @@ -141,6 +144,11 @@ public: */ CAM_DataObject* createRootModuleObject( SUIT_DataObject* theParent ); + /** + * Create a new region in the given calculation case containing given zones. + */ + bool createNewRegion( Handle(HYDROData_CalculationCase) theCase, const QList& theZonesList ); + /** * Correct an internal model object according to the current document mode */ @@ -212,6 +220,15 @@ public: */ bool paste(); + /** + * Creates the GUI data object according to the model object. + * \param theParent a created object will be appended as a child of this object + * \param theModelObject model object + * \param theParentEntry entry of parent object + */ + void buildCaseTree( SUIT_DataObject* theParent, + Handle(HYDROData_CalculationCase) theCase ); + /** * Update the sequence of the objects to be copied */ @@ -224,6 +241,7 @@ public: */ static QString partitionName( const ObjectKind theObjectKind ); +protected: /** * Returns the document for the current study */ @@ -240,7 +258,6 @@ public: const QString& theParentEntry = QString(), const bool theIsBuildTree = true ); -protected: /** * Creates the GUI data object without corresponding model object: just by name * \param theParent a created object will be appended as a child of this object diff --git a/src/HYDROGUI/HYDROGUI_DataObject.cxx b/src/HYDROGUI/HYDROGUI_DataObject.cxx index b54120e1..532ae5f2 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.cxx +++ b/src/HYDROGUI/HYDROGUI_DataObject.cxx @@ -107,3 +107,11 @@ QString HYDROGUI_NamedObject::name() const { return myName; } + +HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent, + const QString& theName, + const QString& theParentEntry ) +: HYDROGUI_NamedObject( theParent, theName, theParentEntry ), CAM_DataObject( theParent ) +{ +} + diff --git a/src/HYDROGUI/HYDROGUI_DataObject.h b/src/HYDROGUI/HYDROGUI_DataObject.h index c48daaa0..a93963bd 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.h +++ b/src/HYDROGUI/HYDROGUI_DataObject.h @@ -142,4 +142,24 @@ private: QString myParentEntry; }; +/** + * \brief Module data object, used for dropping items in the object browser. + * + * It inherits NamedObject with only difference - it accepts dropping. + */ +class HYDROGUI_DropTargetObject : public HYDROGUI_NamedObject +{ +public: + /** + * Constructor. + * \param theParent parent data object + * \param theName displayed name + */ + HYDROGUI_DropTargetObject( SUIT_DataObject* theParent, + const QString& theName, + const QString& theParentEntry ); + + bool isDropAccepted() const override { return true; } +}; + #endif diff --git a/src/HYDROGUI/HYDROGUI_Region.cxx b/src/HYDROGUI/HYDROGUI_Region.cxx index 15722904..f9e1547b 100644 --- a/src/HYDROGUI/HYDROGUI_Region.cxx +++ b/src/HYDROGUI/HYDROGUI_Region.cxx @@ -37,12 +37,24 @@ HYDROGUI_Region::HYDROGUI_Region( SUIT_DataObject* theParent, { } -void HYDROGUI_Region::addZones( ) +bool HYDROGUI_Region::addZones( const QList& theZonesList ) { Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast( modelObject() ); - if ( !aRegion.IsNull() ) + bool isOk = !aRegion.IsNull(); + if ( isOk ) { - // TODO: Add zones - ; + Handle(HYDROData_Zone) aZone; + for (int i = 0; i < theZonesList.length(); i++ ) + { + aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() ); + if ( !aZone.IsNull() ) + { + if ( !( aRegion->AddZone( aZone ) ) ) + { + isOk = false; + } + } + } } + return isOk; } diff --git a/src/HYDROGUI/HYDROGUI_Region.h b/src/HYDROGUI/HYDROGUI_Region.h index c5b3ac70..e7fdf16d 100644 --- a/src/HYDROGUI/HYDROGUI_Region.h +++ b/src/HYDROGUI/HYDROGUI_Region.h @@ -30,6 +30,8 @@ #include #include +class HYDROGUI_Zone; + /** * \class HYDROGUI_Region * \brief Browser item presenting a zone, used for object browser tree creation. @@ -55,6 +57,6 @@ public: /** * Add zones to the region. */ - void addZones(); + bool addZones( const QList& theZonesList ); }; #endif diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 356f537c..85ec0921 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -72,6 +72,10 @@ does not exist or you have not enough permissions to open it. MERGE_ZMAX ZMAX + + NEW_REGION + <New region> +