1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_DataModel.h"
21 #include "HYDROGUI_DataObject.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_Tool.h"
24 #include "HYDROGUI_Zone.h"
25 #include "HYDROGUI_Region.h"
27 #include <HYDROData_Bathymetry.h>
28 #include <HYDROData_CalculationCase.h>
29 #include <HYDROGUI_DataModelSync.h>
30 #include <HYDROData_Document.h>
31 #include <HYDROData_DummyObject3D.h>
32 #include <HYDROData_Image.h>
33 #include <HYDROData_ImmersibleZone.h>
34 #include <HYDROData_Iterator.h>
35 #include <HYDROData_Polyline3D.h>
36 #include <HYDROData_PolylineXY.h>
37 #include <HYDROData_Profile.h>
38 #include <HYDROData_VisualState.h>
39 #include <HYDROData_Region.h>
40 #include <HYDROData_Zone.h>
41 #include <HYDROData_Obstacle.h>
42 #include <HYDROData_Channel.h>
43 #include <HYDROData_Digue.h>
44 #include <HYDROData_River.h>
45 #include <HYDROData_Stream.h>
47 #include <CAM_Module.h>
48 #include <CAM_Study.h>
50 #include <LightApp_Application.h>
51 #include <LightApp_DataObject.h>
52 #include <LightApp_Study.h>
54 #include <SUIT_DataBrowser.h>
55 #include <SUIT_ResourceMgr.h>
56 #include <SUIT_Study.h>
57 #include <SUIT_Tools.h>
58 #include <SUIT_TreeSync.h>
60 #include <HYDROData_Document.h>
62 #include <TDF_Delta.hxx>
63 #include <TDF_ListIteratorOfDeltaList.hxx>
65 #include <QApplication>
68 // #define DEB_GROUPS 1
70 #include <HYDROData_ShapesGroup.h>
73 static HYDROData_SequenceOfObjects myCopyingObjects;
75 const int ENTRY_COLUMN = 2;
78 HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
79 : LightApp_DataModel( theModule )
81 update( module()->application()->activeStudy()->id() );
84 HYDROGUI_DataModel::~HYDROGUI_DataModel()
88 bool HYDROGUI_DataModel::open( const QString& theURL,
90 QStringList theFileList )
92 LightApp_DataModel::open( theURL, theStudy, theFileList );
93 const int aStudyId = theStudy->id();
95 Data_DocError res = DocError_UnknownProblem;
96 if( theFileList.count() >= 2 )
98 QString aTmpDir = theFileList[0];
99 QString aDataFileName = theFileList[1];
100 QString aStatesFileName = theFileList.count() == 3 ? theFileList[2] : "";
103 QString aDataFullPath = SUIT_Tools::addSlash( aTmpDir ) + aDataFileName;
104 QString aStatesFullPath = aStatesFileName.isEmpty() ? "" : SUIT_Tools::addSlash( aTmpDir ) + aStatesFileName;
108 res = HYDROData_Document::Load( (char*)aDataFullPath.toLatin1().constData(), aStudyId );
112 res = DocError_UnknownProblem;
114 if( res != DocError_OK )
116 module()->application()->putInfo( tr( "LOAD_ERROR" ) );
120 if( !aStatesFullPath.isEmpty() )
122 QFile aFile( aStatesFullPath );
123 if( aFile.open( QFile::ReadOnly ) )
125 myStates = aFile.readAll();
131 // if the document open was successful, the data model update happens
132 // in the set mode of the module
133 if( res == DocError_OK )
139 bool HYDROGUI_DataModel::save( QStringList& theFileList )
141 if( !module()->application()->activeStudy() )
144 LightApp_DataModel::save( theFileList );
147 SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
148 bool isMultiFile = false;
150 isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
152 // save module data to temporary files
153 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
154 aTmpDir = aStudy->GetTmpDir( myStudyURL.toLatin1().constData(), isMultiFile ).c_str();
156 // save OCAF data to a temporary file
157 QString aDataFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf";
158 QString aDataFullPath = aTmpDir + aDataFileName;
159 Data_DocError res = getDocument()->Save( (char*)aDataFullPath.toLatin1().constData() );
160 if( res != DocError_OK )
162 module()->application()->putInfo( tr( "SAVE_ERROR" ) );
166 // save tree state data to a temporary file
167 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
168 QByteArray aStatesData = anApp->objectBrowser()->getOpenStates( ENTRY_COLUMN );
169 QString aStatesFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO_tree_states.txt";
170 QString aStatesFullPath = aTmpDir + aStatesFileName;
171 QFile aFile( aStatesFullPath );
172 if( aFile.open( QFile::WriteOnly ) )
174 aFile.write( aStatesData );
178 // add temporary files to the list
179 theFileList.append( aTmpDir );
180 theFileList.append( aDataFileName );
181 theFileList.append( aStatesFileName );
186 bool HYDROGUI_DataModel::saveAs( const QString& theURL,
188 QStringList& theFileList )
191 return save( theFileList );
194 bool HYDROGUI_DataModel::close()
199 bool HYDROGUI_DataModel::dumpPython( const QString& theURL,
202 QStringList& theListOfFiles )
204 LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
206 int aStudyId = theStudy->id();
208 LightApp_Study* aStudy = ::qobject_cast<LightApp_Study*>( theStudy );
209 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
210 if ( aDocument.IsNull() || !aStudy )
213 QString aDir = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str();
214 QString aFileToExport = aDir + QString( QDir::separator() ) + "HYDRO.py";
216 bool aRes = aDocument->DumpToPython( aFileToExport, isMultiFile );
219 theListOfFiles.append( aDir );
220 theListOfFiles.append( aFileToExport );
226 bool HYDROGUI_DataModel::isModified() const
228 return getDocument()->IsModified();
231 bool HYDROGUI_DataModel::isSaved() const
236 void HYDROGUI_DataModel::update( const int theStudyId )
238 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
242 SUIT_DataObject* aStudyRoot = anApp->activeStudy()->root();
246 // create a new root object
247 CAM_DataObject* aNewRootObj = new CAM_DataObject();
249 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theStudyId );
250 if( aDocument.IsNull() )
253 // Create root objects:
256 LightApp_DataObject* anImageRootObj = createObject( aNewRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
259 LightApp_DataObject* aBathymetryRootObj = createObject( aNewRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
261 // ARTIFICIAL OBJECTS
262 LightApp_DataObject* anArtificialObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
265 LightApp_DataObject* aNaturalObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
268 LightApp_DataObject* anObstaclesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
271 LightApp_DataObject* aCalculRootObj = createObject( aNewRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
274 LightApp_DataObject* aPolylineRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
277 LightApp_DataObject* aPolyline3DRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
280 LightApp_DataObject* aProfileRootObj = createObject( aNewRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
283 LightApp_DataObject* aVisualStateRootObj = createObject( aNewRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
285 HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN );
286 for( ; anIterator.More(); anIterator.Next() ) {
287 Handle(HYDROData_Entity) anObj = anIterator.Current();
289 if ( !anObj.IsNull() )
291 switch ( anObj->GetKind() ) {
294 Handle(HYDROData_Image) anImageObj =
295 Handle(HYDROData_Image)::DownCast( anObj );
296 if( !anImageObj.IsNull() ) {
297 createObject( anImageRootObj, anImageObj );
302 case KIND_BATHYMETRY:
304 Handle(HYDROData_Bathymetry) aBathymetryObj =
305 Handle(HYDROData_Bathymetry)::DownCast( anObj );
306 if( !aBathymetryObj.IsNull() ) {
307 createObject( aBathymetryRootObj, aBathymetryObj );
314 Handle(HYDROData_Channel) aChannelObj =
315 Handle(HYDROData_Channel)::DownCast( anObj );
316 if( !aChannelObj.IsNull() ) {
317 createObject( anArtificialObjectsRootObj, aChannelObj );
324 Handle(HYDROData_Digue) aDigueObj =
325 Handle(HYDROData_Digue)::DownCast( anObj );
326 if( !aDigueObj.IsNull() ) {
327 createObject( anArtificialObjectsRootObj, aDigueObj );
332 case KIND_IMMERSIBLE_ZONE:
334 Handle(HYDROData_ImmersibleZone) anImmersibleZoneObj =
335 Handle(HYDROData_ImmersibleZone)::DownCast( anObj );
336 if( !anImmersibleZoneObj.IsNull() ) {
337 createObject( aNaturalObjectsRootObj, anImmersibleZoneObj );
344 Handle(HYDROData_River) aRiverObj =
345 Handle(HYDROData_River)::DownCast( anObj );
346 if( !aRiverObj.IsNull() ) {
347 createObject( aNaturalObjectsRootObj, aRiverObj );
354 Handle(HYDROData_Stream) aStreamObj =
355 Handle(HYDROData_Stream)::DownCast( anObj );
356 if( !aStreamObj.IsNull() ) {
357 createObject( aNaturalObjectsRootObj, aStreamObj );
364 Handle(HYDROData_Obstacle) anObstacleObj =
365 Handle(HYDROData_Obstacle)::DownCast( anObj );
366 if( !anObstacleObj.IsNull() ) {
367 createObject( anObstaclesRootObj, anObstacleObj );
372 case KIND_CALCULATION:
374 Handle(HYDROData_CalculationCase) aCalculObj =
375 Handle(HYDROData_CalculationCase)::DownCast( anObj );
376 if( !aCalculObj.IsNull() ) {
377 createObject( aCalculRootObj, aCalculObj );
382 case KIND_POLYLINEXY:
384 Handle(HYDROData_PolylineXY) aPolylineObj =
385 Handle(HYDROData_PolylineXY)::DownCast( anObj );
386 if( !aPolylineObj.IsNull() ) {
387 createObject( aPolylineRootObj, aPolylineObj );
394 Handle(HYDROData_Polyline3D) aPolylineObj =
395 Handle(HYDROData_Polyline3D)::DownCast( anObj );
396 if( !aPolylineObj.IsNull() ) {
397 createObject( aPolyline3DRootObj, aPolylineObj );
404 Handle(HYDROData_Profile) aProfileObj =
405 Handle(HYDROData_Profile)::DownCast( anObj );
406 if( !aProfileObj.IsNull() ) {
407 createObject( aProfileRootObj, aProfileObj );
412 case KIND_VISUAL_STATE:
414 Handle(HYDROData_VisualState) aVisualStateObj =
415 Handle(HYDROData_VisualState)::DownCast( anObj );
416 if( !aVisualStateObj.IsNull() ) {
417 createObject( aVisualStateRootObj, aVisualStateObj );
426 //if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
428 // anObjectBrowser->setAutoOpenLevel( 3 );
429 // anObjectBrowser->openLevels();
432 HYDROGUI_DataModelSync aSync( aNewRootObj );
433 SUIT_DataObject* aRoot = root();
434 bool isNewDoc = aRoot==0;
436 aRoot = createRootModuleObject( aStudyRoot );
437 ::synchronize < suitPtr, suitPtr, HYDROGUI_DataModelSync >
438 ( aNewRootObj, aRoot, aSync );
441 if( !myStates.isEmpty() )
443 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
444 anApp->objectBrowser()->updateTree();
445 anApp->objectBrowser()->setOpenStates( myStates, ENTRY_COLUMN );
450 HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )
452 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>(
453 findObject( HYDROGUI_DataObject::dataObjectEntry( theModelObject ) ) );
457 HYDROGUI_DataObject* HYDROGUI_DataModel::getReferencedDataObject( HYDROGUI_DataObject* theObject )
459 return NULL; // to do if necessary
462 SUIT_DataObject* HYDROGUI_DataModel::findObject( const QString& theEntry ) const
464 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
465 return anApp ? anApp->findObject( theEntry ) : 0;
468 void HYDROGUI_DataModel::update( LightApp_DataObject* theObject,
469 LightApp_Study* theStudy )
472 theStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy()) ;
474 update( theStudy->id() );
477 CAM_DataObject* HYDROGUI_DataModel::createRootModuleObject( SUIT_DataObject* theParent )
479 CAM_ModuleObject* aRootObj = createModuleObject( theParent );
480 aRootObj->setDataModel( this );
485 void HYDROGUI_DataModel::updateModel()
487 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
489 update( aModule->getStudyId() );
492 Handle(HYDROData_Entity) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
493 const ObjectKind theObjectKind )
495 QString anEntry = theEntry;
496 if( anEntry.indexOf( "_" ) != -1 ) // reference object
497 anEntry = anEntry.section( "_", -1 );
499 Handle(HYDROData_Document) aDocument = getDocument();
500 if( !aDocument.IsNull() )
502 HYDROData_Iterator anIterator( aDocument, theObjectKind );
503 for( ; anIterator.More(); anIterator.Next() )
505 Handle(HYDROData_Entity) anObject = anIterator.Current();
506 if( !anObject.IsNull() )
508 QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
509 if( anEntryRef == anEntry )
517 bool HYDROGUI_DataModel::canUndo() const
519 return getDocument()->CanUndo();
522 bool HYDROGUI_DataModel::canRedo() const
524 return getDocument()->CanRedo();
527 QStringList HYDROGUI_DataModel::undoNames() const
530 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetUndos() ); anIter.More(); anIter.Next() )
531 aNames.prepend( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
535 QStringList HYDROGUI_DataModel::redoNames() const
538 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetRedos() ); anIter.More(); anIter.Next() )
539 aNames.append( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
543 void HYDROGUI_DataModel::clearUndos()
545 getDocument()->ClearUndos();
548 void HYDROGUI_DataModel::clearRedos()
550 getDocument()->ClearRedos();
553 bool HYDROGUI_DataModel::undo()
557 getDocument()->Undo();
559 catch ( Standard_Failure )
566 bool HYDROGUI_DataModel::redo()
570 getDocument()->Redo();
572 catch ( Standard_Failure )
579 bool HYDROGUI_DataModel::canCopy()
581 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
582 bool isCanCopy = !aSeq.IsEmpty();
584 for ( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
585 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
586 if( !anObject.IsNull() ) {
587 ObjectKind aKind = anObject->GetKind();
588 bool isUnrecognized = aKind <= KIND_UNKNOWN || aKind > KIND_LAST;
589 bool isChildObject = aKind == KIND_DUMMY_3D ||
590 aKind == KIND_ZONE ||
591 aKind == KIND_SHAPES_GROUP ||
592 aKind == KIND_SPLITTED_GROUP;
593 if ( isUnrecognized || isChildObject ) {
603 bool HYDROGUI_DataModel::canPaste()
605 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
607 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
608 if( !anObject.IsNull() && !anObject->IsRemoved() )
614 bool HYDROGUI_DataModel::copy()
616 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
617 changeCopyingObjects( aSeq );
621 bool HYDROGUI_DataModel::paste()
623 bool anIsChanged = false;
624 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
626 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
627 if( !anObject.IsNull() && !anObject->IsRemoved() )
629 ObjectKind aKind = anObject->GetKind();
630 Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind );
631 if( !aClone.IsNull() )
633 anObject->CopyTo( aClone );
637 aClone->RemoveZLevel();
644 void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects& theSeq )
646 myCopyingObjects.Assign( theSeq );
649 QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind )
651 switch( theObjectKind )
653 case KIND_IMAGE: return "IMAGES";
654 case KIND_POLYLINE: return "POLYLINES_3D";
655 case KIND_POLYLINEXY: return "POLYLINES";
656 case KIND_PROFILE: return "PROFILES";
657 case KIND_VISUAL_STATE: return "VISUAL_STATES";
658 case KIND_BATHYMETRY: return "BATHYMETRIES";
659 case KIND_CALCULATION: return "CALCULATION_CASES";
660 case KIND_OBSTACLE: return "OBSTACLES";
661 case KIND_ARTIFICIAL_OBJECT: return "ARTIFICIAL_OBJECTS";
662 case KIND_NATURAL_OBJECT: return "NATURAL_OBJECTS";
668 Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
670 int aStudyId = module()->application()->activeStudy()->id();
671 return HYDROData_Document::Document( aStudyId );
674 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
675 Handle(HYDROData_Entity) theModelObject,
676 const QString& theParentEntry,
677 const bool theIsBuildTree )
679 HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
681 if ( theIsBuildTree )
683 buildObjectTree( theParent, aResObj, theParentEntry );
689 LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* theParent,
690 HYDROGUI_DataObject* theObject,
691 const QString& theParentEntry,
692 const bool theIsBuildTree,
693 const bool theIsInOperation )
695 if ( theIsBuildTree )
697 buildObjectTree( theParent, theObject, theParentEntry, theIsInOperation );
702 LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theParent,
703 Handle(HYDROData_Zone) theModelObject,
704 const QString& theParentEntry,
705 const bool theIsBuildTree,
706 const bool theIsInOperation )
708 return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation ),
709 theParentEntry, theIsBuildTree, theIsInOperation );
712 LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent,
713 Handle(HYDROData_Region) theModelObject,
714 const QString& theParentEntry,
715 const bool theIsBuildTree,
716 const bool theIsInOperation )
718 return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry, theIsInOperation ),
719 theParentEntry, theIsBuildTree, theIsInOperation );
722 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
723 const QString& theName,
724 const QString& theParentEntry )
726 return new HYDROGUI_NamedObject( theParent, theName, theParentEntry );
729 void HYDROGUI_DataModel::buildObjectPartition( SUIT_DataObject* theObject,
730 const HYDROData_SequenceOfObjects& theObjects,
731 const QString& thePartName,
732 const bool theIsCreateEmpty )
734 if ( theObjects.IsEmpty() && !theIsCreateEmpty )
737 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
741 LightApp_DataObject* aPartSect =
742 createObject( aGuiObj, thePartName, aGuiObj->entry() );
744 HYDROData_SequenceOfObjects::Iterator anIter( theObjects );
745 for ( ; anIter.More(); anIter.Next() )
747 Handle(HYDROData_Entity) anObj = anIter.Value();
748 if( !anObj.IsNull() && !anObj->IsRemoved() )
749 createObject( aPartSect, anObj, aGuiObj->entry(), false );
753 void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
754 SUIT_DataObject* theObject,
755 const QString& theParentEntry,
756 const bool theIsInOperation )
758 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
762 Handle(HYDROData_Entity) aDataObj = aGuiObj->modelObject();
763 if ( aDataObj.IsNull() )
766 if ( aDataObj->IsKind( STANDARD_TYPE(HYDROData_Object) ) )
768 Handle(HYDROData_Object) aGeomObj =
769 Handle(HYDROData_Object)::DownCast( aDataObj );
771 Handle(HYDROData_DummyObject3D) anObject3D = aGeomObj->GetObject3D();
772 if ( !anObject3D.IsNull() )
773 createObject( aGuiObj, anObject3D, "", false );
776 HYDROData_SequenceOfObjects anObjGroups = aGeomObj->GetGroups();
777 buildObjectPartition( aGuiObj, anObjGroups, tr( "OBJECT_GROUPS" ), false );
781 ObjectKind anObjectKind = aDataObj->GetKind();
783 if ( anObjectKind == KIND_IMAGE )
785 Handle(HYDROData_Image) anImageObj =
786 Handle(HYDROData_Image)::DownCast( aDataObj );
787 for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
789 Handle(HYDROData_Entity) aRefObj = anImageObj->Reference( anIndex );
790 if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
791 createObject( aGuiObj, aRefObj, aGuiObj->entry(), false );
794 else if ( anObjectKind == KIND_IMMERSIBLE_ZONE )
796 Handle(HYDROData_ImmersibleZone) aZoneObj =
797 Handle(HYDROData_ImmersibleZone)::DownCast( aDataObj );
799 LightApp_DataObject* aPolylineSect =
800 createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() );
802 Handle(HYDROData_PolylineXY) aPolyline = aZoneObj->GetPolyline();
803 if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
804 createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
806 LightApp_DataObject* aBathSect =
807 createObject( aGuiObj, tr( "ZONE_BATHYMETRY" ), aGuiObj->entry() );
809 Handle(HYDROData_IAltitudeObject) anAltitudeObj = aZoneObj->GetAltitudeObject();
810 if ( !anAltitudeObj.IsNull() && !anAltitudeObj->IsRemoved() )
811 createObject( aBathSect, anAltitudeObj, aGuiObj->entry(), false );
813 else if ( anObjectKind == KIND_POLYLINE )
815 Handle(HYDROData_Polyline3D) aPolyline3D =
816 Handle(HYDROData_Polyline3D)::DownCast( aDataObj );
818 LightApp_DataObject* aPolylineSect =
819 createObject( aGuiObj, tr( "POLYLINE3D_POLYLINE" ), aGuiObj->entry() );
821 Handle(HYDROData_PolylineXY) aPolylineXY = aPolyline3D->GetPolylineXY();
822 if ( !aPolylineXY.IsNull() && !aPolylineXY->IsRemoved() )
823 createObject( aPolylineSect, aPolylineXY, aGuiObj->entry(), false );
825 LightApp_DataObject* aProfileSect =
826 createObject( aGuiObj, tr( "POLYLINE3D_PROFILE" ), aGuiObj->entry() );
828 Handle(HYDROData_ProfileUZ) aProfileUZ = aPolyline3D->GetProfileUZ();
829 if ( aProfileUZ.IsNull() || aProfileUZ->IsRemoved() )
830 aProfileUZ = aPolyline3D->GetChildProfileUZ( false );
832 if ( !aProfileUZ.IsNull() && !aProfileUZ->IsRemoved() )
834 Handle(HYDROData_Profile) aProfile =
835 Handle(HYDROData_Profile)::DownCast( aProfileUZ->GetFatherObject() );
836 if ( !aProfile.IsNull() && !aProfile->IsRemoved() )
837 createObject( aProfileSect, aProfile, aGuiObj->entry(), false );
840 LightApp_DataObject* aBathSect =
841 createObject( aGuiObj, tr( "POLYLINE3D_BATHYMETRY" ), aGuiObj->entry() );
843 Handle(HYDROData_IAltitudeObject) anAltitudeObj = aPolyline3D->GetAltitudeObject();
844 if ( !anAltitudeObj.IsNull() && !anAltitudeObj->IsRemoved() )
845 createObject( aBathSect, anAltitudeObj, aGuiObj->entry(), false );
847 else if ( anObjectKind == KIND_CALCULATION )
849 Handle(HYDROData_CalculationCase) aCaseObj =
850 Handle(HYDROData_CalculationCase)::DownCast( aDataObj );
852 LightApp_DataObject* aPolylineSect =
853 createObject( aGuiObj, tr( "CASE_BOUNDARY" ), aGuiObj->entry() );
855 Handle(HYDROData_PolylineXY) aPolyline = aCaseObj->GetBoundaryPolyline();
856 if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
857 createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
859 LightApp_DataObject* aCaseAOSect =
860 createObject( aGuiObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ),
862 LightApp_DataObject* aCaseNOSect =
863 createObject( aGuiObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ),
866 HYDROData_SequenceOfObjects aSeq = aCaseObj->GetGeometryObjects();
867 HYDROData_SequenceOfObjects::Iterator aGOIter( aSeq );
868 Handle(HYDROData_Entity) anEntity;
869 Handle(HYDROData_ArtificialObject) anAObject;
870 Handle(HYDROData_NaturalObject) aNObject;
871 for ( ; aGOIter.More(); aGOIter.Next() )
873 anEntity = aGOIter.Value();
874 if ( anEntity.IsNull() )
876 anAObject = Handle(HYDROData_ArtificialObject)::DownCast( anEntity );
877 if ( !anAObject.IsNull() )
878 createObject( aCaseAOSect, anAObject, aGuiObj->entry(), false );
881 aNObject = Handle(HYDROData_NaturalObject)::DownCast( anEntity );
882 if ( !aNObject.IsNull() )
883 createObject( aCaseNOSect, aNObject, aGuiObj->entry(), false );
886 LightApp_DataObject* aCaseRegionsSect =
887 createObject( aGuiObj, tr( "CASE_REGIONS" ), aGuiObj->entry() );
889 HYDROData_SequenceOfObjects aCaseRegions = aCaseObj->GetRegions();
890 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
891 for ( ; anIter.More(); anIter.Next() )
893 Handle(HYDROData_Region) aCaseRegion =
894 Handle(HYDROData_Region)::DownCast( anIter.Value() );
895 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
896 createRegion( aCaseRegionsSect, aCaseRegion, "", true, theIsInOperation );
900 HYDROData_SequenceOfObjects aCalcGroups = aCaseObj->GetGeometryGroups();
901 buildObjectPartition( aGuiObj, aCalcGroups, tr( "OBJECT_GROUPS" ), false );
903 HYDROData_SequenceOfObjects aCalcSplitGroups = aCaseObj->GetSplittedGroups();
904 buildObjectPartition( aGuiObj, aCalcSplitGroups, tr( "CASE_SPLITTED_GROUPS" ), false );
908 else if ( anObjectKind == KIND_REGION )
910 Handle(HYDROData_Region) aRegionObj =
911 Handle(HYDROData_Region)::DownCast( aDataObj );
913 HYDROData_SequenceOfObjects aRegionZones = aRegionObj->GetZones();
914 HYDROData_SequenceOfObjects::Iterator anIter( aRegionZones );
915 for ( ; anIter.More(); anIter.Next() )
917 Handle(HYDROData_Zone) aRegionZone =
918 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
919 if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() )
920 createZone( aGuiObj, aRegionZone, "", true, theIsInOperation );
923 else if ( anObjectKind == KIND_PROFILE )
925 Handle(HYDROData_Profile) aProfileObj =
926 Handle(HYDROData_Profile)::DownCast( aDataObj );
928 aGuiObj->setIsValid( aProfileObj->IsValid() );
930 else if ( anObjectKind == KIND_CHANNEL || anObjectKind == KIND_DIGUE )
932 Handle(HYDROData_Channel) aChannelObj =
933 Handle(HYDROData_Channel)::DownCast( aDataObj );
935 LightApp_DataObject* aGuideLineSect =
936 createObject( aGuiObj, tr( "CHANNEL_GUIDE_LINE" ), aGuiObj->entry() );
937 Handle(HYDROData_Polyline3D) aGuideLine = aChannelObj->GetGuideLine();
938 if ( !aGuideLine.IsNull() && !aGuideLine->IsRemoved() ) {
939 createObject( aGuideLineSect, aGuideLine, aGuiObj->entry(), false );
942 LightApp_DataObject* aProfileSect =
943 createObject( aGuiObj, tr( "CHANNEL_PROFILE" ), aGuiObj->entry() );
944 Handle(HYDROData_Profile) aProfile = aChannelObj->GetProfile();
945 if ( !aProfile.IsNull() && !aProfile->IsRemoved() ) {
946 createObject( aProfileSect, aProfile, aGuiObj->entry(), false );
949 else if ( anObjectKind == KIND_STREAM )
951 Handle(HYDROData_Stream) aStreamObj =
952 Handle(HYDROData_Stream)::DownCast( aDataObj );
954 LightApp_DataObject* aHydraulicAxisSect =
955 createObject( aGuiObj, tr( "STREAM_HYDRAULIC_AXIS" ), aGuiObj->entry() );
956 Handle(HYDROData_PolylineXY) aHydraulicAxis = aStreamObj->GetHydraulicAxis();
957 if ( !aHydraulicAxis.IsNull() && !aHydraulicAxis->IsRemoved() ) {
958 createObject( aHydraulicAxisSect, aHydraulicAxis, aGuiObj->entry(), false );
961 HYDROData_SequenceOfObjects aProfiles = aStreamObj->GetProfiles();
962 buildObjectPartition( aGuiObj, aProfiles, tr( "STREAM_PROFILES" ), true );
964 Handle(HYDROData_Polyline3D) aBottomPolyline = aStreamObj->GetBottomPolyline();
965 if ( !aBottomPolyline.IsNull() && !aBottomPolyline->IsRemoved() ) {
966 createObject( aGuiObj, aBottomPolyline, aGuiObj->entry(), false );
971 void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
973 if ( !theCase.IsNull() )
977 // Remove previous objects tree
978 DataObjectList aList;
979 theParent->children( aList );
980 QListIterator<SUIT_DataObject*> anIter( aList );
981 while( anIter.hasNext() )
982 removeChild( theParent, anIter.next() );
985 new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "", true );
987 HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions();
988 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
989 for ( ; anIter.More(); anIter.Next() )
991 Handle(HYDROData_Region) aCaseRegion =
992 Handle(HYDROData_Region)::DownCast( anIter.Value() );
993 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
994 createRegion( theParent, aCaseRegion, "", true, true );
999 void HYDROGUI_DataModel::updateObjectTree( Handle(HYDROData_Entity)& theObj )
1001 if ( !theObj.IsNull() )
1003 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>(
1004 findObject( HYDROGUI_DataObject::dataObjectEntry( theObj ) ) );
1007 // Remove previous objects tree
1008 DataObjectList aList;
1009 aGuiObj->children( aList );
1010 QListIterator<SUIT_DataObject*> anIter( aList );
1011 while( anIter.hasNext() )
1012 removeChild( aGuiObj, anIter.next() );
1014 // Rebuild the subtree
1015 QString aParentEntry;
1016 HYDROGUI_DataObject* aParent = dynamic_cast<HYDROGUI_DataObject*>( aGuiObj->parent() );
1019 aParentEntry = aParent->entry();
1021 buildObjectTree( aParent, aGuiObj, aParentEntry, aGuiObj->isInOperation() );
1025 // workaround for the bug in SalomeApp_Study::findObjectByEntry - it can't find LightApp_DataObjects
1026 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
1029 aModule->getApp()->updateObjectBrowser();
1035 void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent,
1036 SUIT_DataObject* theChild )
1038 SUIT_DataObject* aSubChild = theChild->firstChild();
1039 for( ; aSubChild; aSubChild = aSubChild->nextBrother() )
1040 removeChild( theChild, aSubChild );
1041 theParent->removeChild( theChild );
1044 SUIT_DataObject* HYDROGUI_DataModel::findChildByName( const SUIT_DataObject* theFather,
1045 const QString& theName )
1047 SUIT_DataObject* aChild = theFather->firstChild();
1050 if( aChild->name() == theName )
1051 return aChild; // found
1052 aChild = aChild->nextBrother();
1054 return NULL; // not found
1057 bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theCase,
1058 const QList<HYDROGUI_Zone*>& theZonesList )
1060 bool isOk = !theCase.IsNull();
1063 Handle(HYDROData_Region) aRegion;
1064 Handle(HYDROData_Zone) aZone;
1065 for (int i = 0; i < theZonesList.length(); i++ )
1067 aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() );
1068 if ( !aZone.IsNull() )
1070 if ( aRegion.IsNull() )
1072 aRegion = theCase->AddNewRegion( aZone );
1073 isOk = !aRegion.IsNull();
1077 if ( !( aRegion->AddZone( aZone ) ) )
1088 bool HYDROGUI_DataModel::rename( Handle(HYDROData_Entity) theEntity, const QString& theName )
1090 if ( theName.isEmpty() )
1095 getDocument()->StartOperation();
1096 theEntity->SetName( theName );
1097 getDocument()->CommitOperation( HYDROGUI_Tool::ToExtString( tr("RENAME_TO").arg( theName ) ) );
1098 module()->application()->activeStudy()->Modified();
1100 catch ( Standard_Failure )
1102 getDocument()->AbortOperation();