1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_DataModel.h"
25 #include "HYDROGUI_DataObject.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_Tool.h"
28 #include "HYDROGUI_Zone.h"
29 #include "HYDROGUI_Region.h"
31 #include <HYDROData_Bathymetry.h>
32 #include <HYDROData_CalculationCase.h>
33 #include <HYDROGUI_DataModelSync.h>
34 #include <HYDROData_Document.h>
35 #include <HYDROData_DummyObject3D.h>
36 #include <HYDROData_Image.h>
37 #include <HYDROData_ImmersibleZone.h>
38 #include <HYDROData_Iterator.h>
39 #include <HYDROData_Polyline3D.h>
40 #include <HYDROData_PolylineXY.h>
41 #include <HYDROData_Profile.h>
42 #include <HYDROData_VisualState.h>
43 #include <HYDROData_Region.h>
44 #include <HYDROData_Zone.h>
45 #include <HYDROData_Obstacle.h>
46 #include <HYDROData_Channel.h>
47 #include <HYDROData_Digue.h>
48 #include <HYDROData_River.h>
49 #include <HYDROData_Stream.h>
51 #include <CAM_Module.h>
52 #include <CAM_Study.h>
54 #include <LightApp_Application.h>
55 #include <LightApp_DataObject.h>
56 #include <LightApp_Study.h>
58 #include <SUIT_DataBrowser.h>
59 #include <SUIT_ResourceMgr.h>
60 #include <SUIT_Study.h>
61 #include <SUIT_Tools.h>
62 #include <SUIT_TreeSync.h>
64 #include <HYDROData_Document.h>
66 #include <TDF_Delta.hxx>
67 #include <TDF_ListIteratorOfDeltaList.hxx>
69 #include <QApplication>
72 // #define DEB_GROUPS 1
74 #include <HYDROData_ShapesGroup.h>
77 static HYDROData_SequenceOfObjects myCopyingObjects;
79 const int ENTRY_COLUMN = 2;
82 HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
83 : LightApp_DataModel( theModule )
85 update( module()->application()->activeStudy()->id() );
88 HYDROGUI_DataModel::~HYDROGUI_DataModel()
92 bool HYDROGUI_DataModel::open( const QString& theURL,
94 QStringList theFileList )
96 LightApp_DataModel::open( theURL, theStudy, theFileList );
97 const int aStudyId = theStudy->id();
99 Data_DocError res = DocError_UnknownProblem;
100 if( theFileList.count() >= 2 )
102 QString aTmpDir = theFileList[0];
103 QString aDataFileName = theFileList[1];
104 QString aStatesFileName = theFileList.count() == 3 ? theFileList[2] : "";
107 QString aDataFullPath = SUIT_Tools::addSlash( aTmpDir ) + aDataFileName;
108 QString aStatesFullPath = aStatesFileName.isEmpty() ? "" : SUIT_Tools::addSlash( aTmpDir ) + aStatesFileName;
112 res = HYDROData_Document::Load( (char*)aDataFullPath.toLatin1().constData(), aStudyId );
116 res = DocError_UnknownProblem;
118 if( res != DocError_OK )
120 module()->application()->putInfo( tr( "LOAD_ERROR" ) );
124 if( !aStatesFullPath.isEmpty() )
126 QFile aFile( aStatesFullPath );
127 if( aFile.open( QFile::ReadOnly ) )
129 myStates = aFile.readAll();
135 // if the document open was successful, the data model update happens
136 // in the set mode of the module
137 if( res == DocError_OK )
143 bool HYDROGUI_DataModel::save( QStringList& theFileList )
145 if( !module()->application()->activeStudy() )
148 LightApp_DataModel::save( theFileList );
151 SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
152 bool isMultiFile = false;
154 isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
156 // save module data to temporary files
157 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
158 aTmpDir = aStudy->GetTmpDir( myStudyURL.toLatin1().constData(), isMultiFile ).c_str();
160 // save OCAF data to a temporary file
161 QString aDataFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf";
162 QString aDataFullPath = aTmpDir + aDataFileName;
163 Data_DocError res = getDocument()->Save( (char*)aDataFullPath.toLatin1().constData() );
164 if( res != DocError_OK )
166 module()->application()->putInfo( tr( "SAVE_ERROR" ) );
170 // save tree state data to a temporary file
171 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
172 QByteArray aStatesData = anApp->objectBrowser()->getOpenStates( ENTRY_COLUMN );
173 QString aStatesFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO_tree_states.txt";
174 QString aStatesFullPath = aTmpDir + aStatesFileName;
175 QFile aFile( aStatesFullPath );
176 if( aFile.open( QFile::WriteOnly ) )
178 aFile.write( aStatesData );
182 // add temporary files to the list
183 theFileList.append( aTmpDir );
184 theFileList.append( aDataFileName );
185 theFileList.append( aStatesFileName );
190 bool HYDROGUI_DataModel::saveAs( const QString& theURL,
192 QStringList& theFileList )
195 return save( theFileList );
198 bool HYDROGUI_DataModel::close()
203 bool HYDROGUI_DataModel::dumpPython( const QString& theURL,
206 QStringList& theListOfFiles )
208 LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
210 int aStudyId = theStudy->id();
212 LightApp_Study* aStudy = ::qobject_cast<LightApp_Study*>( theStudy );
213 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
214 if ( aDocument.IsNull() || !aStudy )
217 QString aDir = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str();
218 QString aFileToExport = aDir + QString( QDir::separator() ) + "HYDRO.py";
220 bool aRes = aDocument->DumpToPython( aFileToExport, isMultiFile );
223 theListOfFiles.append( aDir );
224 theListOfFiles.append( aFileToExport );
230 bool HYDROGUI_DataModel::isModified() const
232 return getDocument()->IsModified();
235 bool HYDROGUI_DataModel::isSaved() const
240 void HYDROGUI_DataModel::update( const int theStudyId )
242 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
246 SUIT_DataObject* aStudyRoot = anApp->activeStudy()->root();
250 // create a new root object
251 CAM_DataObject* aNewRootObj = new CAM_DataObject();
253 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theStudyId );
254 if( aDocument.IsNull() )
257 // Create root objects:
260 LightApp_DataObject* anImageRootObj = createObject( aNewRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
263 LightApp_DataObject* aBathymetryRootObj = createObject( aNewRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
265 // ARTIFICIAL OBJECTS
266 LightApp_DataObject* anArtificialObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
269 LightApp_DataObject* aNaturalObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
272 LightApp_DataObject* anObstaclesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
275 LightApp_DataObject* aCalculRootObj = createObject( aNewRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
278 LightApp_DataObject* aPolylineRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
281 LightApp_DataObject* aPolyline3DRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
284 LightApp_DataObject* aProfileRootObj = createObject( aNewRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
287 LightApp_DataObject* aVisualStateRootObj = createObject( aNewRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
289 HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN );
290 for( ; anIterator.More(); anIterator.Next() ) {
291 Handle(HYDROData_Entity) anObj = anIterator.Current();
293 if ( !anObj.IsNull() )
295 switch ( anObj->GetKind() ) {
298 Handle(HYDROData_Image) anImageObj =
299 Handle(HYDROData_Image)::DownCast( anObj );
300 if( !anImageObj.IsNull() ) {
301 createObject( anImageRootObj, anImageObj );
306 case KIND_BATHYMETRY:
308 Handle(HYDROData_Bathymetry) aBathymetryObj =
309 Handle(HYDROData_Bathymetry)::DownCast( anObj );
310 if( !aBathymetryObj.IsNull() ) {
311 createObject( aBathymetryRootObj, aBathymetryObj );
318 Handle(HYDROData_Channel) aChannelObj =
319 Handle(HYDROData_Channel)::DownCast( anObj );
320 if( !aChannelObj.IsNull() ) {
321 createObject( anArtificialObjectsRootObj, aChannelObj );
328 Handle(HYDROData_Digue) aDigueObj =
329 Handle(HYDROData_Digue)::DownCast( anObj );
330 if( !aDigueObj.IsNull() ) {
331 createObject( anArtificialObjectsRootObj, aDigueObj );
336 case KIND_IMMERSIBLE_ZONE:
338 Handle(HYDROData_ImmersibleZone) anImmersibleZoneObj =
339 Handle(HYDROData_ImmersibleZone)::DownCast( anObj );
340 if( !anImmersibleZoneObj.IsNull() ) {
341 createObject( aNaturalObjectsRootObj, anImmersibleZoneObj );
348 Handle(HYDROData_River) aRiverObj =
349 Handle(HYDROData_River)::DownCast( anObj );
350 if( !aRiverObj.IsNull() ) {
351 createObject( aNaturalObjectsRootObj, aRiverObj );
358 Handle(HYDROData_Stream) aStreamObj =
359 Handle(HYDROData_Stream)::DownCast( anObj );
360 if( !aStreamObj.IsNull() ) {
361 createObject( aNaturalObjectsRootObj, aStreamObj );
368 Handle(HYDROData_Obstacle) anObstacleObj =
369 Handle(HYDROData_Obstacle)::DownCast( anObj );
370 if( !anObstacleObj.IsNull() ) {
371 createObject( anObstaclesRootObj, anObstacleObj );
376 case KIND_CALCULATION:
378 Handle(HYDROData_CalculationCase) aCalculObj =
379 Handle(HYDROData_CalculationCase)::DownCast( anObj );
380 if( !aCalculObj.IsNull() ) {
381 createObject( aCalculRootObj, aCalculObj );
386 case KIND_POLYLINEXY:
388 Handle(HYDROData_PolylineXY) aPolylineObj =
389 Handle(HYDROData_PolylineXY)::DownCast( anObj );
390 if( !aPolylineObj.IsNull() ) {
391 createObject( aPolylineRootObj, aPolylineObj );
398 Handle(HYDROData_Polyline3D) aPolylineObj =
399 Handle(HYDROData_Polyline3D)::DownCast( anObj );
400 if( !aPolylineObj.IsNull() ) {
401 createObject( aPolyline3DRootObj, aPolylineObj );
408 Handle(HYDROData_Profile) aProfileObj =
409 Handle(HYDROData_Profile)::DownCast( anObj );
410 if( !aProfileObj.IsNull() ) {
411 createObject( aProfileRootObj, aProfileObj );
416 case KIND_VISUAL_STATE:
418 Handle(HYDROData_VisualState) aVisualStateObj =
419 Handle(HYDROData_VisualState)::DownCast( anObj );
420 if( !aVisualStateObj.IsNull() ) {
421 createObject( aVisualStateRootObj, aVisualStateObj );
430 //if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
432 // anObjectBrowser->setAutoOpenLevel( 3 );
433 // anObjectBrowser->openLevels();
436 HYDROGUI_DataModelSync aSync( aNewRootObj );
437 SUIT_DataObject* aRoot = root();
438 bool isNewDoc = aRoot==0;
440 aRoot = createRootModuleObject( aStudyRoot );
441 ::synchronize < suitPtr, suitPtr, HYDROGUI_DataModelSync >
442 ( aNewRootObj, aRoot, aSync );
445 if( !myStates.isEmpty() )
447 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
448 anApp->objectBrowser()->updateTree();
449 anApp->objectBrowser()->setOpenStates( myStates, ENTRY_COLUMN );
454 HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )
456 return NULL; // to do if necessary
459 HYDROGUI_DataObject* HYDROGUI_DataModel::getReferencedDataObject( HYDROGUI_DataObject* theObject )
461 return NULL; // to do if necessary
464 SUIT_DataObject* HYDROGUI_DataModel::findObject( const QString& theEntry ) const
466 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
467 return anApp ? anApp->findObject( theEntry ) : 0;
470 void HYDROGUI_DataModel::update( LightApp_DataObject* theObject,
471 LightApp_Study* theStudy )
474 theStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy()) ;
476 update( theStudy->id() );
479 CAM_DataObject* HYDROGUI_DataModel::createRootModuleObject( SUIT_DataObject* theParent )
481 CAM_ModuleObject* aRootObj = createModuleObject( theParent );
482 aRootObj->setDataModel( this );
487 void HYDROGUI_DataModel::updateModel()
489 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
491 update( aModule->getStudyId() );
494 Handle(HYDROData_Entity) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
495 const ObjectKind theObjectKind )
497 QString anEntry = theEntry;
498 if( anEntry.indexOf( "_" ) != -1 ) // reference object
499 anEntry = anEntry.section( "_", -1 );
501 Handle(HYDROData_Document) aDocument = getDocument();
502 if( !aDocument.IsNull() )
504 HYDROData_Iterator anIterator( aDocument, theObjectKind );
505 for( ; anIterator.More(); anIterator.Next() )
507 Handle(HYDROData_Entity) anObject = anIterator.Current();
508 if( !anObject.IsNull() )
510 QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
511 if( anEntryRef == anEntry )
519 bool HYDROGUI_DataModel::canUndo() const
521 return getDocument()->CanUndo();
524 bool HYDROGUI_DataModel::canRedo() const
526 return getDocument()->CanRedo();
529 QStringList HYDROGUI_DataModel::undoNames() const
532 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetUndos() ); anIter.More(); anIter.Next() )
533 aNames.prepend( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
537 QStringList HYDROGUI_DataModel::redoNames() const
540 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetRedos() ); anIter.More(); anIter.Next() )
541 aNames.append( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
545 void HYDROGUI_DataModel::clearUndos()
547 getDocument()->ClearUndos();
550 void HYDROGUI_DataModel::clearRedos()
552 getDocument()->ClearRedos();
555 bool HYDROGUI_DataModel::undo()
559 getDocument()->Undo();
561 catch ( Standard_Failure )
568 bool HYDROGUI_DataModel::redo()
572 getDocument()->Redo();
574 catch ( Standard_Failure )
581 bool HYDROGUI_DataModel::canCopy()
583 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
584 bool isCanCopy = !aSeq.IsEmpty();
586 for ( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
587 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
588 if( !anObject.IsNull() ) {
589 ObjectKind aKind = anObject->GetKind();
590 bool isUnrecognized = aKind <= KIND_UNKNOWN || aKind > KIND_LAST;
591 bool isChildObject = aKind == KIND_DUMMY_3D ||
592 aKind == KIND_ZONE ||
593 aKind == KIND_SHAPES_GROUP ||
594 aKind == KIND_SPLITTED_GROUP;
595 if ( isUnrecognized || isChildObject ) {
605 bool HYDROGUI_DataModel::canPaste()
607 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
609 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
610 if( !anObject.IsNull() && !anObject->IsRemoved() )
616 bool HYDROGUI_DataModel::copy()
618 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
619 changeCopyingObjects( aSeq );
623 bool HYDROGUI_DataModel::paste()
625 bool anIsChanged = false;
626 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
628 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
629 if( !anObject.IsNull() && !anObject->IsRemoved() )
631 ObjectKind aKind = anObject->GetKind();
632 Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind );
633 if( !aClone.IsNull() )
635 anObject->CopyTo( aClone );
639 aClone->RemoveZLevel();
641 // generate a new unique name for the clone object:
642 // case 1: Image_1 -> Image_2
643 // case 2: ImageObj -> ImageObj_1
644 QString aName = aClone->GetName();
645 QString aPrefix = aName;
646 if( aName.contains( '_' ) ) // case 1
648 QString aSuffix = aName.section( '_', -1 );
649 bool anIsInteger = false;
650 aSuffix.toInt( &anIsInteger );
652 aPrefix = aName.section( '_', 0, -2 );
656 aName = HYDROGUI_Tool::GenerateObjectName( (HYDROGUI_Module*)module(), aPrefix );
657 aClone->SetName( aName );
664 void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects& theSeq )
666 myCopyingObjects.Assign( theSeq );
669 QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind )
671 switch( theObjectKind )
673 case KIND_IMAGE: return "IMAGES";
674 case KIND_POLYLINE: return "POLYLINES_3D";
675 case KIND_POLYLINEXY: return "POLYLINES";
676 case KIND_PROFILE: return "PROFILES";
677 case KIND_VISUAL_STATE: return "VISUAL_STATES";
678 case KIND_BATHYMETRY: return "BATHYMETRIES";
679 case KIND_CALCULATION: return "CALCULATION_CASES";
680 case KIND_OBSTACLE: return "OBSTACLES";
681 case KIND_ARTIFICIAL_OBJECT: return "ARTIFICIAL_OBJECTS";
682 case KIND_NATURAL_OBJECT: return "NATURAL_OBJECTS";
688 Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
690 int aStudyId = module()->application()->activeStudy()->id();
691 return HYDROData_Document::Document( aStudyId );
694 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
695 Handle(HYDROData_Entity) theModelObject,
696 const QString& theParentEntry,
697 const bool theIsBuildTree )
699 HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
701 if ( theIsBuildTree )
703 buildObjectTree( theParent, aResObj, theParentEntry );
709 LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* theParent,
710 HYDROGUI_DataObject* theObject,
711 const QString& theParentEntry,
712 const bool theIsBuildTree,
713 const bool theIsInOperation )
715 if ( theIsBuildTree )
717 buildObjectTree( theParent, theObject, theParentEntry, theIsInOperation );
722 LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theParent,
723 Handle(HYDROData_Zone) theModelObject,
724 const QString& theParentEntry,
725 const bool theIsBuildTree,
726 const bool theIsInOperation )
728 return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation ),
729 theParentEntry, theIsBuildTree, theIsInOperation );
732 LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent,
733 Handle(HYDROData_Region) theModelObject,
734 const QString& theParentEntry,
735 const bool theIsBuildTree,
736 const bool theIsInOperation )
738 return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry, theIsInOperation ),
739 theParentEntry, theIsBuildTree, theIsInOperation );
742 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
743 const QString& theName,
744 const QString& theParentEntry )
746 return new HYDROGUI_NamedObject( theParent, theName, theParentEntry );
749 void HYDROGUI_DataModel::buildObjectPartition( SUIT_DataObject* theObject,
750 const HYDROData_SequenceOfObjects& theObjects,
751 const QString& thePartName,
752 const bool theIsCreateEmpty )
754 if ( theObjects.IsEmpty() && !theIsCreateEmpty )
757 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
761 LightApp_DataObject* aPartSect =
762 createObject( aGuiObj, thePartName, aGuiObj->entry() );
764 HYDROData_SequenceOfObjects::Iterator anIter( theObjects );
765 for ( ; anIter.More(); anIter.Next() )
767 Handle(HYDROData_Entity) anObj = anIter.Value();
768 if( !anObj.IsNull() && !anObj->IsRemoved() )
769 createObject( aPartSect, anObj, aGuiObj->entry(), false );
773 void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
774 SUIT_DataObject* theObject,
775 const QString& theParentEntry,
776 const bool theIsInOperation )
778 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
782 Handle(HYDROData_Entity) aDataObj = aGuiObj->modelObject();
783 if ( aDataObj.IsNull() )
786 if ( aDataObj->IsKind( STANDARD_TYPE(HYDROData_Object) ) )
788 Handle(HYDROData_Object) aGeomObj =
789 Handle(HYDROData_Object)::DownCast( aDataObj );
791 Handle(HYDROData_DummyObject3D) anObject3D = aGeomObj->GetObject3D();
792 if ( !anObject3D.IsNull() )
793 createObject( aGuiObj, anObject3D, "", false );
796 HYDROData_SequenceOfObjects anObjGroups = aGeomObj->GetGroups();
797 buildObjectPartition( aGuiObj, anObjGroups, tr( "OBJECT_GROUPS" ), false );
801 ObjectKind anObjectKind = aDataObj->GetKind();
803 if ( anObjectKind == KIND_IMAGE )
805 Handle(HYDROData_Image) anImageObj =
806 Handle(HYDROData_Image)::DownCast( aDataObj );
807 for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
809 Handle(HYDROData_Entity) aRefObj = anImageObj->Reference( anIndex );
810 if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
811 createObject( aGuiObj, aRefObj, aGuiObj->entry(), false );
814 else if ( anObjectKind == KIND_IMMERSIBLE_ZONE )
816 Handle(HYDROData_ImmersibleZone) aZoneObj =
817 Handle(HYDROData_ImmersibleZone)::DownCast( aDataObj );
819 LightApp_DataObject* aPolylineSect =
820 createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() );
822 Handle(HYDROData_PolylineXY) aPolyline = aZoneObj->GetPolyline();
823 if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
824 createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
826 LightApp_DataObject* aBathSect =
827 createObject( aGuiObj, tr( "ZONE_BATHYMETRY" ), aGuiObj->entry() );
829 Handle(HYDROData_IAltitudeObject) anAltitudeObj = aZoneObj->GetAltitudeObject();
830 if ( !anAltitudeObj.IsNull() && !anAltitudeObj->IsRemoved() )
831 createObject( aBathSect, anAltitudeObj, aGuiObj->entry(), false );
833 else if ( anObjectKind == KIND_POLYLINE )
835 Handle(HYDROData_Polyline3D) aPolyline3D =
836 Handle(HYDROData_Polyline3D)::DownCast( aDataObj );
838 LightApp_DataObject* aPolylineSect =
839 createObject( aGuiObj, tr( "POLYLINE3D_POLYLINE" ), aGuiObj->entry() );
841 Handle(HYDROData_PolylineXY) aPolylineXY = aPolyline3D->GetPolylineXY();
842 if ( !aPolylineXY.IsNull() && !aPolylineXY->IsRemoved() )
843 createObject( aPolylineSect, aPolylineXY, aGuiObj->entry(), false );
845 LightApp_DataObject* aProfileSect =
846 createObject( aGuiObj, tr( "POLYLINE3D_PROFILE" ), aGuiObj->entry() );
848 Handle(HYDROData_ProfileUZ) aProfileUZ = aPolyline3D->GetProfileUZ();
849 if ( aProfileUZ.IsNull() || aProfileUZ->IsRemoved() )
850 aProfileUZ = aPolyline3D->GetChildProfileUZ( false );
852 if ( !aProfileUZ.IsNull() && !aProfileUZ->IsRemoved() )
854 Handle(HYDROData_Profile) aProfile =
855 Handle(HYDROData_Profile)::DownCast( aProfileUZ->GetFatherObject() );
856 if ( !aProfile.IsNull() && !aProfile->IsRemoved() )
857 createObject( aProfileSect, aProfile, aGuiObj->entry(), false );
860 LightApp_DataObject* aBathSect =
861 createObject( aGuiObj, tr( "POLYLINE3D_BATHYMETRY" ), aGuiObj->entry() );
863 Handle(HYDROData_IAltitudeObject) anAltitudeObj = aPolyline3D->GetAltitudeObject();
864 if ( !anAltitudeObj.IsNull() && !anAltitudeObj->IsRemoved() )
865 createObject( aBathSect, anAltitudeObj, aGuiObj->entry(), false );
867 else if ( anObjectKind == KIND_CALCULATION )
869 Handle(HYDROData_CalculationCase) aCaseObj =
870 Handle(HYDROData_CalculationCase)::DownCast( aDataObj );
872 LightApp_DataObject* aPolylineSect =
873 createObject( aGuiObj, tr( "CASE_BOUNDARY" ), aGuiObj->entry() );
875 Handle(HYDROData_PolylineXY) aPolyline = aCaseObj->GetBoundaryPolyline();
876 if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
877 createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
879 LightApp_DataObject* aCaseAOSect =
880 createObject( aGuiObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ),
882 LightApp_DataObject* aCaseNOSect =
883 createObject( aGuiObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ),
886 HYDROData_SequenceOfObjects aSeq = aCaseObj->GetGeometryObjects();
887 HYDROData_SequenceOfObjects::Iterator aGOIter( aSeq );
888 Handle(HYDROData_Entity) anEntity;
889 Handle(HYDROData_ArtificialObject) anAObject;
890 Handle(HYDROData_NaturalObject) aNObject;
891 for ( ; aGOIter.More(); aGOIter.Next() )
893 anEntity = aGOIter.Value();
894 if ( anEntity.IsNull() )
896 anAObject = Handle(HYDROData_ArtificialObject)::DownCast( anEntity );
897 if ( !anAObject.IsNull() )
898 createObject( aCaseAOSect, anAObject, aGuiObj->entry(), false );
901 aNObject = Handle(HYDROData_NaturalObject)::DownCast( anEntity );
902 if ( !aNObject.IsNull() )
903 createObject( aCaseNOSect, aNObject, aGuiObj->entry(), false );
906 LightApp_DataObject* aCaseRegionsSect =
907 createObject( aGuiObj, tr( "CASE_REGIONS" ), aGuiObj->entry() );
909 HYDROData_SequenceOfObjects aCaseRegions = aCaseObj->GetRegions();
910 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
911 for ( ; anIter.More(); anIter.Next() )
913 Handle(HYDROData_Region) aCaseRegion =
914 Handle(HYDROData_Region)::DownCast( anIter.Value() );
915 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
916 createRegion( aCaseRegionsSect, aCaseRegion, "", true, theIsInOperation );
920 HYDROData_SequenceOfObjects aCalcGroups = aCaseObj->GetGeometryGroups();
921 buildObjectPartition( aGuiObj, aCalcGroups, tr( "OBJECT_GROUPS" ), false );
923 HYDROData_SequenceOfObjects aCalcSplitGroups = aCaseObj->GetSplittedGroups();
924 buildObjectPartition( aGuiObj, aCalcSplitGroups, tr( "CASE_SPLITTED_GROUPS" ), false );
928 else if ( anObjectKind == KIND_REGION )
930 Handle(HYDROData_Region) aRegionObj =
931 Handle(HYDROData_Region)::DownCast( aDataObj );
933 HYDROData_SequenceOfObjects aRegionZones = aRegionObj->GetZones();
934 HYDROData_SequenceOfObjects::Iterator anIter( aRegionZones );
935 for ( ; anIter.More(); anIter.Next() )
937 Handle(HYDROData_Zone) aRegionZone =
938 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
939 if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() )
940 createZone( aGuiObj, aRegionZone, "", true, theIsInOperation );
943 else if ( anObjectKind == KIND_PROFILE )
945 Handle(HYDROData_Profile) aProfileObj =
946 Handle(HYDROData_Profile)::DownCast( aDataObj );
948 aGuiObj->setIsValid( aProfileObj->IsValid() );
950 else if ( anObjectKind == KIND_CHANNEL || anObjectKind == KIND_DIGUE )
952 Handle(HYDROData_Channel) aChannelObj =
953 Handle(HYDROData_Channel)::DownCast( aDataObj );
955 LightApp_DataObject* aGuideLineSect =
956 createObject( aGuiObj, tr( "CHANNEL_GUIDE_LINE" ), aGuiObj->entry() );
957 Handle(HYDROData_Polyline3D) aGuideLine = aChannelObj->GetGuideLine();
958 if ( !aGuideLine.IsNull() && !aGuideLine->IsRemoved() ) {
959 createObject( aGuideLineSect, aGuideLine, aGuiObj->entry(), false );
962 LightApp_DataObject* aProfileSect =
963 createObject( aGuiObj, tr( "CHANNEL_PROFILE" ), aGuiObj->entry() );
964 Handle(HYDROData_Profile) aProfile = aChannelObj->GetProfile();
965 if ( !aProfile.IsNull() && !aProfile->IsRemoved() ) {
966 createObject( aProfileSect, aProfile, aGuiObj->entry(), false );
969 else if ( anObjectKind == KIND_STREAM )
971 Handle(HYDROData_Stream) aStreamObj =
972 Handle(HYDROData_Stream)::DownCast( aDataObj );
974 LightApp_DataObject* aHydraulicAxisSect =
975 createObject( aGuiObj, tr( "STREAM_HYDRAULIC_AXIS" ), aGuiObj->entry() );
976 Handle(HYDROData_PolylineXY) aHydraulicAxis = aStreamObj->GetHydraulicAxis();
977 if ( !aHydraulicAxis.IsNull() && !aHydraulicAxis->IsRemoved() ) {
978 createObject( aHydraulicAxisSect, aHydraulicAxis, aGuiObj->entry(), false );
981 HYDROData_SequenceOfObjects aProfiles = aStreamObj->GetProfiles();
982 buildObjectPartition( aGuiObj, aProfiles, tr( "STREAM_PROFILES" ), true );
986 void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
988 if ( !theCase.IsNull() )
992 // Remove previous objects tree
993 DataObjectList aList;
994 theParent->children( aList );
995 QListIterator<SUIT_DataObject*> anIter( aList );
996 while( anIter.hasNext() )
997 removeChild( theParent, anIter.next() );
1000 new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "", true );
1002 HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions();
1003 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
1004 for ( ; anIter.More(); anIter.Next() )
1006 Handle(HYDROData_Region) aCaseRegion =
1007 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1008 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
1009 createRegion( theParent, aCaseRegion, "", true, true );
1014 void HYDROGUI_DataModel::updateObjectTree( Handle(HYDROData_Entity)& theObj )
1016 if ( !theObj.IsNull() )
1018 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>(
1019 findObject( HYDROGUI_DataObject::dataObjectEntry( theObj ) ) );
1022 // Remove previous objects tree
1023 DataObjectList aList;
1024 aGuiObj->children( aList );
1025 QListIterator<SUIT_DataObject*> anIter( aList );
1026 while( anIter.hasNext() )
1027 removeChild( aGuiObj, anIter.next() );
1029 // Rebuild the subtree
1030 QString aParentEntry;
1031 HYDROGUI_DataObject* aParent = dynamic_cast<HYDROGUI_DataObject*>( aGuiObj->parent() );
1034 aParentEntry = aParent->entry();
1036 buildObjectTree( aParent, aGuiObj, aParentEntry, aGuiObj->isInOperation() );
1040 // workaround for the bug in SalomeApp_Study::findObjectByEntry - it can't find LightApp_DataObjects
1041 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
1044 aModule->getApp()->updateObjectBrowser();
1050 void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent,
1051 SUIT_DataObject* theChild )
1053 SUIT_DataObject* aSubChild = theChild->firstChild();
1054 for( ; aSubChild; aSubChild = aSubChild->nextBrother() )
1055 removeChild( theChild, aSubChild );
1056 theParent->removeChild( theChild );
1059 SUIT_DataObject* HYDROGUI_DataModel::findChildByName( const SUIT_DataObject* theFather,
1060 const QString& theName )
1062 SUIT_DataObject* aChild = theFather->firstChild();
1065 if( aChild->name() == theName )
1066 return aChild; // found
1067 aChild = aChild->nextBrother();
1069 return NULL; // not found
1072 bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theCase,
1073 const QList<HYDROGUI_Zone*>& theZonesList )
1075 bool isOk = !theCase.IsNull();
1078 Handle(HYDROData_Region) aRegion;
1079 Handle(HYDROData_Zone) aZone;
1080 for (int i = 0; i < theZonesList.length(); i++ )
1082 aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() );
1083 if ( !aZone.IsNull() )
1085 if ( aRegion.IsNull() )
1087 aRegion = theCase->AddNewRegion( aZone );
1088 isOk = !aRegion.IsNull();
1092 if ( !( aRegion->AddZone( aZone ) ) )
1103 bool HYDROGUI_DataModel::rename( Handle(HYDROData_Entity) theEntity, const QString& theName )
1105 if ( theName.isEmpty() )
1110 getDocument()->StartOperation();
1111 theEntity->SetName( theName );
1112 getDocument()->CommitOperation( HYDROGUI_Tool::ToExtString( tr("RENAME_TO").arg( theName ) ) );
1113 module()->application()->activeStudy()->Modified();
1115 catch ( Standard_Failure )
1117 getDocument()->AbortOperation();