- "New region" item is added in the regions tree in Calculation Case wizard.
if ( aRegionsRoot )
{
// Create a new region
+ emit createRegion( aZonesList );
}
else
{
HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
if ( aRegion )
{
- aRegion->addZones( );
+ emit moveZones( theTargetParent, aZonesList );
}
}
}
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();
void addObjects();
void removeObjects();
void splitZones();
- void setMergeType( int theMergeType, QString theBathymetryName );
+ void setMergeType( int theMergeType, QString& theBathymetryName );
+ void createRegion( const QList<SUIT_DataObject*>& theZonesList );
+ void moveZones( SUIT_DataObject* theRegion, const QList<SUIT_DataObject*>& theZonesList );
private:
#include "HYDROGUI_Tool.h"
#include "HYDROGUI_UpdateFlags.h"
#include "HYDROGUI_Zone.h"
+#include "HYDROGUI_Region.h"
#include <HYDROData_Polyline.h>
#include <HYDROData_Iterator.h>
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<SUIT_DataObject*>& ) ),
+ SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
+ connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
+ SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
return aPanel;
}
-void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString theBathymetryName )
+void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
+{
+ HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
+ if ( aRegion )
+ {
+ QList<HYDROGUI_Zone*> aZonesList;
+ HYDROGUI_Zone* aZone;
+ // Get a list of dropped zones
+ for ( int i = 0; i < theZonesList.length(); i++ )
+ {
+ aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
+ if ( aZone )
+ {
+ aZonesList.append( aZone );
+ }
+ }
+ if ( aZonesList.length() > 0 )
+ {
+ aRegion->addZones( aZonesList );
+ HYDROGUI_CalculationDlg* aPanel =
+ ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+ if ( aPanel )
+ {
+ aPanel->setEditedObject(myEditedObject);
+ }
+ }
+ }
+}
+
+void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
+{
+ QList<HYDROGUI_Zone*> aZonesList;
+ HYDROGUI_Zone* aZone;
+ // Get a list of dropped zones
+ for ( int i = 0; i < theZonesList.length(); i++ )
+ {
+ aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
+ if ( aZone )
+ {
+ aZonesList.append( aZone );
+ }
+ }
+ if ( aZonesList.length() > 0 )
+ {
+ module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
+ HYDROGUI_CalculationDlg* aPanel =
+ ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+ if ( aPanel )
+ {
+ aPanel->setEditedObject(myEditedObject);
+ }
+ }
+}
+
+void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theBathymetryName )
{
HYDROGUI_CalculationDlg* aPanel =
::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
class SUIT_ViewManager;
class OCCViewer_ViewManager;
class HYDROGUI_CalculationDlg;
+class SUIT_DataObject;
class HYDROGUI_CalculationOp : public HYDROGUI_Operation
{
/**
* 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<SUIT_DataObject*>& theZonesList );
+ void onCreateRegion( const QList<SUIT_DataObject*>& theZonesList );
void onSplitZones();
void onLastViewClosed( SUIT_ViewManager* );
}
}
+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 )
{
}
return NULL; // not found
}
+
+bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theCase,
+ const QList<HYDROGUI_Zone*>& 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;
+}
#include <HYDROData_Entity.h>
#include <HYDROData_Zone.h>
#include <HYDROData_Region.h>
+#include <HYDROData_CalculationCase.h>
#include <QMap>
+#include <QList>
#include <LightApp_DataModel.h>
#include <SUIT_TreeModel.h>
class CAM_DataObject;
class SUIT_DataObject;
class HYDROGUI_DataObject;
+class HYDROGUI_Zone;
/**
* \class HYDROGUI_DataModel
*/
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<HYDROGUI_Zone*>& theZonesList );
+
/**
* Correct an internal model object according to the current document mode
*/
*/
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
*/
*/
static QString partitionName( const ObjectKind theObjectKind );
+protected:
/**
* Returns the document for the current study
*/
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
{
return myName;
}
+
+HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
+ const QString& theName,
+ const QString& theParentEntry )
+: HYDROGUI_NamedObject( theParent, theName, theParentEntry ), CAM_DataObject( theParent )
+{
+}
+
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
{
}
-void HYDROGUI_Region::addZones( )
+bool HYDROGUI_Region::addZones( const QList<HYDROGUI_Zone*>& 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;
}
#include <QString>
#include <QColor>
+class HYDROGUI_Zone;
+
/**
* \class HYDROGUI_Region
* \brief Browser item presenting a zone, used for object browser tree creation.
/**
* Add zones to the region.
*/
- void addZones();
+ bool addZones( const QList<HYDROGUI_Zone*>& theZonesList );
};
#endif
<source>MERGE_ZMAX</source>
<translation>ZMAX</translation>
</message>
+ <message>
+ <source>NEW_REGION</source>
+ <translation><New region></translation>
+ </message>
</context>
<context>