#include <HYDROData_Bathymetry.h>
#include <HYDROData_CalculationCase.h>
#include <HYDROData_Document.h>
+#include <HYDROData_DummyObject3D.h>
#include <HYDROData_Image.h>
#include <HYDROData_ImmersibleZone.h>
#include <HYDROData_Iterator.h>
#include <QApplication>
#include <QDir>
+// #define DEB_GROUPS 1
+#ifdef DEB_GROUPS
+#include <HYDROData_ShapesGroup.h>
+#endif
+
static HYDROData_SequenceOfObjects myCopyingObjects;
HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
CAM_DataObject* HYDROGUI_DataModel::createRootModuleObject( SUIT_DataObject* theParent )
{
- CAM_DataObject* aRootObj = createModuleObject( theParent );
+ CAM_ModuleObject* aRootObj = createModuleObject( theParent );
+ aRootObj->setDataModel( this );
setRoot( aRootObj );
return aRootObj;
}
LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* theParent,
HYDROGUI_DataObject* theObject,
const QString& theParentEntry,
- const bool theIsBuildTree )
+ const bool theIsBuildTree,
+ const bool theIsInOperation )
{
if ( theIsBuildTree )
{
- buildObjectTree( theParent, theObject, theParentEntry );
+ buildObjectTree( theParent, theObject, theParentEntry, theIsInOperation );
}
return theObject;
}
LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theParent,
Handle(HYDROData_Zone) theModelObject,
const QString& theParentEntry,
- const bool theIsBuildTree )
+ const bool theIsBuildTree,
+ const bool theIsInOperation )
{
- return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
+ return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation ),
+ theParentEntry, theIsBuildTree, theIsInOperation );
}
LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent,
Handle(HYDROData_Region) theModelObject,
const QString& theParentEntry,
- const bool theIsBuildTree )
+ const bool theIsBuildTree,
+ const bool theIsInOperation )
{
- return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
+ return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry, theIsInOperation ),
+ theParentEntry, theIsBuildTree, theIsInOperation );
}
LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
SUIT_DataObject* theObject,
- const QString& theParentEntry )
+ const QString& theParentEntry,
+ const bool theIsInOperation )
{
HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
if ( !aGuiObj )
if ( aDataObj.IsNull() )
return;
+ if ( aDataObj->IsKind( STANDARD_TYPE(HYDROData_Object) ) )
+ {
+ Handle(HYDROData_Object) aGeomObj =
+ Handle(HYDROData_Object)::DownCast( aDataObj );
+
+ Handle(HYDROData_DummyObject3D) anObject3D = aGeomObj->GetObject3D();
+ if ( !anObject3D.IsNull() )
+ createObject( aGuiObj, anObject3D, aGuiObj->entry(), false );
+
+#ifdef DEB_GROUPS
+ LightApp_DataObject* aGroupsSect =
+ createObject( aGuiObj, tr( "OBJECT_GROUPS" ), aGuiObj->entry() );
+
+ HYDROData_SequenceOfObjects anObjGroups = aGeomObj->GetGroups();
+ HYDROData_SequenceOfObjects::Iterator anIter( anObjGroups );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ Handle(HYDROData_ShapesGroup) anObjGroup =
+ Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
+ if( !anObjGroup.IsNull() && !anObjGroup->IsRemoved() )
+ createObject( aGroupsSect, anObjGroup, aGuiObj->entry(), false );
+ }
+#endif
+ }
+
ObjectKind anObjectKind = aDataObj->GetKind();
if ( anObjectKind == KIND_IMAGE )
if ( !aBathymetry.IsNull() && !aBathymetry->IsRemoved() )
createObject( aBathSect, aBathymetry, aGuiObj->entry(), false );
}
+ else if ( anObjectKind == KIND_POLYLINE )
+ {
+ Handle(HYDROData_Polyline3D) aPolyline3D =
+ Handle(HYDROData_Polyline3D)::DownCast( aDataObj );
+
+ LightApp_DataObject* aPolylineSect =
+ createObject( aGuiObj, tr( "POLYLINE3D_POLYLINE" ), aGuiObj->entry() );
+
+ Handle(HYDROData_PolylineXY) aPolylineXY = aPolyline3D->GetPolylineXY();
+ if ( !aPolylineXY.IsNull() && !aPolylineXY->IsRemoved() )
+ createObject( aPolylineSect, aPolylineXY, aGuiObj->entry(), false );
+
+ LightApp_DataObject* aProfileSect =
+ createObject( aGuiObj, tr( "POLYLINE3D_PROFILE" ), aGuiObj->entry() );
+
+ Handle(HYDROData_ProfileUZ) aProfileUZ = aPolyline3D->GetProfileUZ();
+ if ( aProfileUZ.IsNull() || aProfileUZ->IsRemoved() )
+ aProfileUZ = aPolyline3D->GetChildProfileUZ( false );
+
+ if ( !aProfileUZ.IsNull() && !aProfileUZ->IsRemoved() )
+ {
+ Handle(HYDROData_Profile) aProfile =
+ Handle(HYDROData_Profile)::DownCast( aProfileUZ->GetFatherObject() );
+ if ( !aProfile.IsNull() && !aProfile->IsRemoved() )
+ createObject( aProfileSect, aProfile, aGuiObj->entry(), false );
+ }
+
+ LightApp_DataObject* aBathSect =
+ createObject( aGuiObj, tr( "POLYLINE3D_BATHYMETRY" ), aGuiObj->entry() );
+
+ Handle(HYDROData_Bathymetry) aBathymetry = aPolyline3D->GetBathymetry();
+ if ( !aBathymetry.IsNull() && !aBathymetry->IsRemoved() )
+ createObject( aBathSect, aBathymetry, aGuiObj->entry(), false );
+ }
else if ( anObjectKind == KIND_CALCULATION )
{
Handle(HYDROData_CalculationCase) aCaseObj =
Handle(HYDROData_Region) aCaseRegion =
Handle(HYDROData_Region)::DownCast( anIter.Value() );
if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
- createRegion( aCaseRegionsSect, aCaseRegion, "", true );
+ createRegion( aCaseRegionsSect, aCaseRegion, "", true, theIsInOperation );
}
}
else if ( anObjectKind == KIND_REGION )
Handle(HYDROData_Zone) aRegionZone =
Handle(HYDROData_Zone)::DownCast( anIter.Value() );
if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() )
- createZone( aGuiObj, aRegionZone, "", true );
+ createZone( aGuiObj, aRegionZone, "", true, theIsInOperation );
}
}
else if ( anObjectKind == KIND_PROFILE )
aGuiObj->setIsValid( aProfileObj->IsValid() );
}
+ else if ( anObjectKind == KIND_CHANNEL || anObjectKind == KIND_DIGUE )
+ {
+ Handle(HYDROData_Channel) aChannelObj =
+ Handle(HYDROData_Channel)::DownCast( aDataObj );
+
+ Handle(HYDROData_Profile) aProfile = aChannelObj->GetProfile();
+ Handle(HYDROData_Polyline3D) aGuideLine = aChannelObj->GetGuideLine();
+
+ createObject( aGuiObj, aProfile, aGuiObj->entry(), false );
+ createObject( aGuiObj, aGuideLine, aGuiObj->entry(), false );
+ }
}
void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
{
if ( !theCase.IsNull() )
{
- new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "" );
+ if ( theParent )
+ {
+ // Remove previous objects tree
+ DataObjectList aList;
+ theParent->children( aList );
+ QListIterator<SUIT_DataObject*> anIter( aList );
+ while( anIter.hasNext() )
+ removeChild( theParent, anIter.next() );
+ }
+
+ new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "", true );
HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions();
HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
Handle(HYDROData_Region) aCaseRegion =
Handle(HYDROData_Region)::DownCast( anIter.Value() );
if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
- createRegion( theParent, aCaseRegion, "", true );
+ createRegion( theParent, aCaseRegion, "", true, true );
+ }
+ }
+}
+
+void HYDROGUI_DataModel::updateObjectTree( Handle(HYDROData_Entity)& theObj )
+{
+ if ( !theObj.IsNull() )
+ {
+ HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>(
+ findObject( HYDROGUI_DataObject::dataObjectEntry( theObj ) ) );
+ if ( aGuiObj )
+ {
+ // Remove previous objects tree
+ DataObjectList aList;
+ aGuiObj->children( aList );
+ QListIterator<SUIT_DataObject*> anIter( aList );
+ while( anIter.hasNext() )
+ removeChild( aGuiObj, anIter.next() );
+
+ // Rebuild the subtree
+ QString aParentEntry;
+ HYDROGUI_DataObject* aParent = dynamic_cast<HYDROGUI_DataObject*>( aGuiObj->parent() );
+ if ( aParent )
+ {
+ aParentEntry = aParent->entry();
+ }
+ buildObjectTree( aParent, aGuiObj, aParentEntry, aGuiObj->isInOperation() );
+ }
+ else
+ {
+ // workaround for the bug in SalomeApp_Study::findObjectByEntry - it can't find LightApp_DataObjects
+ HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
+ if( aModule )
+ {
+ aModule->getApp()->updateObjectBrowser();
+ }
}
}
}
}
return isOk;
}
+
+bool HYDROGUI_DataModel::rename( Handle(HYDROData_Entity) theEntity, const QString& theName )
+{
+ if ( theName.isEmpty() )
+ return false;
+
+ try
+ {
+ getDocument()->StartOperation();
+ theEntity->SetName( theName );
+ getDocument()->CommitOperation( HYDROGUI_Tool::ToExtString( tr("RENAME_TO").arg( theName ) ) );
+ module()->application()->activeStudy()->Modified();
+ }
+ catch ( Standard_Failure )
+ {
+ getDocument()->AbortOperation();
+ return false;
+ }
+ return true;
+}
+