#include "HYDROGUI_Module.h"
#include "HYDROGUI_Tool.h"
+#include <HYDROData_Bathymetry.h>
+#include <HYDROData_Calculation.h>
#include <HYDROData_Document.h>
#include <HYDROData_Image.h>
#include <HYDROData_Iterator.h>
+#include <HYDROData_Polyline.h>
+#include <HYDROData_VisualState.h>
+#include <HYDROData_Zone.h>
#include <CAM_Application.h>
#include <CAM_DataObject.h>
#include <TDF_Delta.hxx>
#include <TDF_ListIteratorOfDeltaList.hxx>
+#include <QApplication>
+#include <QDir>
+
+static HYDROData_SequenceOfObjects myCopyingObjects;
+
HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
: LightApp_DataModel( theModule )
{
return true;
}
+bool HYDROGUI_DataModel::dumpPython( const QString& theURL,
+ CAM_Study* theStudy,
+ bool isMultiFile,
+ QStringList& theListOfFiles )
+{
+ LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
+
+ int aStudyId = theStudy->id();
+
+ LightApp_Study* aStudy = ::qobject_cast<LightApp_Study*>( theStudy );
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
+ if ( aDocument.IsNull() || !aStudy )
+ return false;
+
+ QString aFileToExport = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str();
+ aFileToExport += QString( QDir::separator() ) + "HYDRO.py";
+
+ bool aRes = aDocument->DumpToPython( aFileToExport );
+
+ if ( aRes )
+ {
+ theListOfFiles.append( aFileToExport );
+ }
+
+ return aRes;
+}
+
bool HYDROGUI_DataModel::isModified() const
{
- int aStudyId = module()->application()->activeStudy()->id();
- return HYDROData_Document::Document( aStudyId )->IsModified();
+ return getDocument()->IsModified();
}
bool HYDROGUI_DataModel::isSaved() const
if( aDocument.IsNull() )
return;
- LightApp_DataObject* anImageRootObj = createObject( aRootObj, "IMAGES" );
+ LightApp_DataObject* anImageRootObj = createObject( aRootObj, partitionName( KIND_IMAGE ) );
HYDROData_Iterator anIterator( aDocument, KIND_IMAGE );
for( ; anIterator.More(); anIterator.Next() )
createObject( anImageRootObj, anImageObj );
}
- LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, "POLYLINES" );
+ LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, partitionName( KIND_BATHYMETRY ) );
- HYDROData_Iterator aPolyIterator( aDocument, KIND_IMAGE );
- for( ; aPolyIterator.More(); aPolyIterator.Next() )
+ anIterator = HYDROData_Iterator( aDocument, KIND_BATHYMETRY );
+ for( ; anIterator.More(); anIterator.Next() )
{
- Handle(HYDROData_Image) aPolylineObj =
- Handle(HYDROData_Image)::DownCast( anIterator.Current() );
+ Handle(HYDROData_Bathymetry) aBathymetryObj =
+ Handle(HYDROData_Bathymetry)::DownCast( anIterator.Current() );
+ if( !aBathymetryObj.IsNull() )
+ createObject( aBathymetryRootObj, aBathymetryObj );
+ }
+
+ LightApp_DataObject* aCalculRootObj = createObject( aRootObj, partitionName( KIND_CALCULATION ) );
+
+ anIterator = HYDROData_Iterator( aDocument, KIND_CALCULATION );
+ for( ; anIterator.More(); anIterator.Next() )
+ {
+ Handle(HYDROData_Calculation) aCalculObj =
+ Handle(HYDROData_Calculation)::DownCast( anIterator.Current() );
+ if( !aCalculObj.IsNull() )
+ createObject( aCalculRootObj, aCalculObj );
+ }
+
+ LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, partitionName( KIND_POLYLINE ) );
+
+ anIterator = HYDROData_Iterator( aDocument, KIND_POLYLINE );
+ for( ; anIterator.More(); anIterator.Next() )
+ {
+ Handle(HYDROData_Polyline) aPolylineObj =
+ Handle(HYDROData_Polyline)::DownCast( anIterator.Current() );
if( !aPolylineObj.IsNull() )
createObject( aPolylineRootObj, aPolylineObj );
}
+ LightApp_DataObject* aZonesRootObj = createObject( aRootObj, partitionName( KIND_ZONE ) );
+
+ anIterator = HYDROData_Iterator( aDocument, KIND_ZONE );
+ for( ; anIterator.More(); anIterator.Next() )
+ {
+ Handle(HYDROData_Zone) aZoneObj =
+ Handle(HYDROData_Zone)::DownCast( anIterator.Current() );
+ if( !aZoneObj.IsNull() )
+ createObject( aZonesRootObj, aZoneObj );
+ }
+
+ LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, partitionName( KIND_VISUAL_STATE ) );
+
+ anIterator = HYDROData_Iterator( aDocument, KIND_VISUAL_STATE );
+ for( ; anIterator.More(); anIterator.Next() )
+ {
+ Handle(HYDROData_VisualState) aVisualStateObj =
+ Handle(HYDROData_VisualState)::DownCast( anIterator.Current() );
+ if( !aVisualStateObj.IsNull() )
+ createObject( aVisualStateRootObj, aVisualStateObj );
+ }
+
if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
{
anObjectBrowser->setAutoOpenLevel( 3 );
Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
const ObjectKind theObjectKind )
{
- const int aStudyId = module()->application()->activeStudy()->id();
- Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
+ QString anEntry = theEntry;
+ if( anEntry.indexOf( "_" ) != -1 ) // reference object
+ anEntry = anEntry.section( "_", -1 );
+
+ Handle(HYDROData_Document) aDocument = getDocument();
if( !aDocument.IsNull() )
{
HYDROData_Iterator anIterator( aDocument, theObjectKind );
Handle(HYDROData_Object) anObject = anIterator.Current();
if( !anObject.IsNull() )
{
- QString anEntry = HYDROGUI_DataObject::dataObjectEntry( anObject );
- if( anEntry == theEntry )
+ QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
+ if( anEntryRef == anEntry )
return anObject;
}
}
return true;
}
+bool HYDROGUI_DataModel::canCopy()
+{
+ HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
+ if( aSeq.Length() != 1 )
+ return false;
+
+ Handle(HYDROData_Object) anObject = aSeq.First();
+ if( anObject.IsNull() )
+ return false;
+
+ ObjectKind aKind = anObject->GetKind();
+ if( aKind == KIND_IMAGE ||
+ aKind == KIND_POLYLINE ||
+ aKind == KIND_CALCULATION )
+ return true;
+
+ return false;
+}
+
+bool HYDROGUI_DataModel::canPaste()
+{
+ for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
+ {
+ Handle(HYDROData_Object) anObject = myCopyingObjects.Value( anIndex );
+ if( !anObject.IsNull() && !anObject->IsRemoved() )
+ return true;
+ }
+ return false;
+}
+
+bool HYDROGUI_DataModel::copy()
+{
+ HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
+ changeCopyingObjects( aSeq );
+ return true;
+}
+
+bool HYDROGUI_DataModel::paste()
+{
+ bool anIsChanged = false;
+ for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
+ {
+ Handle(HYDROData_Object) anObject = myCopyingObjects.Value( anIndex );
+ if( !anObject.IsNull() && !anObject->IsRemoved() )
+ {
+ ObjectKind aKind = anObject->GetKind();
+ Handle(HYDROData_Object) aClone = getDocument()->CreateObject( aKind );
+ if( !aClone.IsNull() )
+ {
+ anObject->CopyTo( aClone );
+ anIsChanged = true;
+
+ // generate a new unique name for the clone object:
+ // case 1: Image_1 -> Image_2
+ // case 2: ImageObj -> ImageObj_1
+ QString aName = aClone->GetName();
+ QString aPrefix = aName;
+ if( aName.contains( '_' ) ) // case 1
+ {
+ QString aSuffix = aName.section( '_', -1 );
+ bool anIsInteger = false;
+ aSuffix.toInt( &anIsInteger );
+ if( anIsInteger )
+ aPrefix = aName.section( '_', 0, -2 );
+ }
+ else // case 2
+ aPrefix = aName;
+ aName = HYDROGUI_Tool::GenerateObjectName( (HYDROGUI_Module*)module(), aPrefix );
+ aClone->SetName( aName );
+ }
+ }
+ }
+ return anIsChanged;
+}
+
+void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects& theSeq )
+{
+ myCopyingObjects.Assign( theSeq );
+}
+
+QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind )
+{
+ switch( theObjectKind )
+ {
+ case KIND_IMAGE: return "IMAGES";
+ case KIND_POLYLINE: return "POLYLINES";
+ case KIND_VISUAL_STATE: return "VISUAL_STATES";
+ case KIND_BATHYMETRY: return "BATHYMETRIES";
+ case KIND_CALCULATION: return "CALCULATION_CASES";
+ case KIND_ZONE: return "ZONES";
+ default: break;
+ }
+ return QString();
+}
+
Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
{
int aStudyId = module()->application()->activeStudy()->id();
return HYDROData_Document::Document( aStudyId );
}
-LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
- Handle(HYDROData_Object) theModelObject )
+LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
+ Handle(HYDROData_Object) theModelObject,
+ const QString& theParentEntry )
{
- return new HYDROGUI_DataObject( theParent, theModelObject );
+ HYDROGUI_DataObject* aResObj =
+ new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
+ buildObjectTree( theParent, aResObj, theParentEntry );
+ return aResObj;
}
LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
- const QString& theName )
+ const QString& theName,
+ const QString& theParentEntry )
+{
+ return new HYDROGUI_NamedObject( theParent, theName, theParentEntry );
+}
+
+void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
+ SUIT_DataObject* theObject,
+ const QString& theParentEntry )
{
- return new HYDROGUI_NamedObject( theParent, theName );
+ HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
+ if ( !aGuiObj )
+ return;
+
+ Handle(HYDROData_Object) aDataObj = aGuiObj->modelObject();
+ if ( aDataObj.IsNull() )
+ return;
+
+ ObjectKind anObjectKind = aDataObj->GetKind();
+
+ if ( anObjectKind == KIND_IMAGE )
+ {
+ Handle(HYDROData_Image) anImageObj =
+ Handle(HYDROData_Image)::DownCast( aDataObj );
+ for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
+ {
+ Handle(HYDROData_Object) aRefObj = anImageObj->Reference( anIndex );
+ if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
+ createObject( aGuiObj, aRefObj, aGuiObj->entry() );
+ }
+ }
+ else if ( anObjectKind == KIND_ZONE )
+ {
+ Handle(HYDROData_Zone) aZoneObj =
+ Handle(HYDROData_Zone)::DownCast( aDataObj );
+
+ LightApp_DataObject* aPolylineSect = createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() );
+
+ Handle(HYDROData_Polyline) aPolyline = aZoneObj->GetPolyline();
+ if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
+ createObject( aPolylineSect, aPolyline, aGuiObj->entry() );
+
+ LightApp_DataObject* aBathsSect = createObject( aGuiObj, tr( "ZONE_BATHYMETRIES" ), aGuiObj->entry() );
+
+ HYDROData_SequenceOfObjects aZoneBaths = aZoneObj->GetBathymetries();
+ HYDROData_SequenceOfObjects::Iterator aBathsIter( aZoneBaths );
+ for ( ; aBathsIter.More(); aBathsIter.Next() )
+ {
+ Handle(HYDROData_Bathymetry) aRefBath =
+ Handle(HYDROData_Bathymetry)::DownCast( aBathsIter.Value() );
+ if( !aRefBath.IsNull() && !aRefBath->IsRemoved() )
+ createObject( aBathsSect, aRefBath, aGuiObj->entry() );
+ }
+ }
}
void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent,