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 <HYDROData_Document.h>
34 #include <HYDROData_DummyObject3D.h>
35 #include <HYDROData_Image.h>
36 #include <HYDROData_ImmersibleZone.h>
37 #include <HYDROData_Iterator.h>
38 #include <HYDROData_Polyline3D.h>
39 #include <HYDROData_PolylineXY.h>
40 #include <HYDROData_Profile.h>
41 #include <HYDROData_VisualState.h>
42 #include <HYDROData_Region.h>
43 #include <HYDROData_Zone.h>
44 #include <HYDROData_Obstacle.h>
45 #include <HYDROData_Channel.h>
46 #include <HYDROData_Digue.h>
47 #include <HYDROData_River.h>
48 #include <HYDROData_Stream.h>
50 #include <CAM_Application.h>
51 #include <CAM_DataObject.h>
52 #include <CAM_Module.h>
53 #include <CAM_Study.h>
55 #include <LightApp_Application.h>
56 #include <LightApp_DataObject.h>
57 #include <LightApp_Study.h>
59 #include <SUIT_DataObject.h>
60 #include <SUIT_DataBrowser.h>
61 #include <SUIT_ResourceMgr.h>
62 #include <SUIT_Study.h>
63 #include <SUIT_Tools.h>
65 #include <HYDROData_Document.h>
67 #include <TDF_Delta.hxx>
68 #include <TDF_ListIteratorOfDeltaList.hxx>
70 #include <QApplication>
73 static HYDROData_SequenceOfObjects myCopyingObjects;
75 HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
76 : LightApp_DataModel( theModule )
78 update( module()->application()->activeStudy()->id() );
81 HYDROGUI_DataModel::~HYDROGUI_DataModel()
85 bool HYDROGUI_DataModel::open( const QString& theURL,
87 QStringList theFileList )
89 LightApp_DataModel::open( theURL, theStudy, theFileList );
90 const int aStudyId = theStudy->id();
92 Data_DocError res = DocError_UnknownProblem;
93 if( theFileList.count() == 2 )
95 QString aTmpDir = theFileList[0];
96 QString aFileName = theFileList[1];
99 QString aFullPath = SUIT_Tools::addSlash( aTmpDir ) + aFileName;
103 res = HYDROData_Document::Load( (char*)aFullPath.toLatin1().constData(), aStudyId );
107 res = DocError_UnknownProblem;
109 if( res != DocError_OK )
111 module()->application()->putInfo( tr( "LOAD_ERROR" ) );
116 // if the document open was successful, the data model update happens
117 // in the set mode of the module
118 if( res == DocError_OK )
124 bool HYDROGUI_DataModel::save( QStringList& theFileList )
126 if( !module()->application()->activeStudy() )
129 LightApp_DataModel::save( theFileList );
133 SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
134 bool isMultiFile = false;
136 isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
138 // save data to temporary files
139 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
140 aTmpDir = aStudy->GetTmpDir( myStudyURL.toLatin1().constData(), isMultiFile ).c_str();
141 aFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf";
143 QString aFullPath = aTmpDir + aFileName;
144 Data_DocError res = getDocument()->Save( (char*)aFullPath.toLatin1().constData() );
145 if( res != DocError_OK )
147 module()->application()->putInfo( tr( "SAVE_ERROR" ) );
151 theFileList.append( aTmpDir );
152 theFileList.append( aFileName );
157 bool HYDROGUI_DataModel::saveAs( const QString& theURL,
159 QStringList& theFileList )
162 return save( theFileList );
165 bool HYDROGUI_DataModel::close()
170 bool HYDROGUI_DataModel::dumpPython( const QString& theURL,
173 QStringList& theListOfFiles )
175 LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
177 int aStudyId = theStudy->id();
179 LightApp_Study* aStudy = ::qobject_cast<LightApp_Study*>( theStudy );
180 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
181 if ( aDocument.IsNull() || !aStudy )
184 QString aFileToExport = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str();
185 aFileToExport += QString( QDir::separator() ) + "HYDRO.py";
187 bool aRes = aDocument->DumpToPython( aFileToExport );
191 theListOfFiles.append( aFileToExport );
197 bool HYDROGUI_DataModel::isModified() const
199 return getDocument()->IsModified();
202 bool HYDROGUI_DataModel::isSaved() const
207 void HYDROGUI_DataModel::update( const int theStudyId )
209 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
213 SUIT_DataObject* aStudyRoot = anApp->activeStudy()->root();
217 // create root object if not exist
218 CAM_DataObject* aRootObj = root();
220 aRootObj = createRootModuleObject( aStudyRoot );
225 DataObjectList aList;
226 aRootObj->children( aList );
227 QListIterator<SUIT_DataObject*> anIter( aList );
228 while( anIter.hasNext() )
229 removeChild( aRootObj, anIter.next() );
231 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theStudyId );
232 if( aDocument.IsNull() )
235 // Create root objects:
238 LightApp_DataObject* anImageRootObj = createObject( aRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
241 LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
243 // ARTIFICIAL OBJECTS
244 LightApp_DataObject* anArtificialObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
247 LightApp_DataObject* aNaturalObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
250 LightApp_DataObject* anObstaclesRootObj = createObject( aRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
253 LightApp_DataObject* aCalculRootObj = createObject( aRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
256 LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
259 LightApp_DataObject* aPolyline3DRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
262 LightApp_DataObject* aProfileRootObj = createObject( aRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
265 LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
267 HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN );
268 for( ; anIterator.More(); anIterator.Next() ) {
269 Handle(HYDROData_Entity) anObj = anIterator.Current();
271 if ( !anObj.IsNull() )
273 switch ( anObj->GetKind() ) {
276 Handle(HYDROData_Image) anImageObj =
277 Handle(HYDROData_Image)::DownCast( anObj );
278 if( !anImageObj.IsNull() ) {
279 createObject( anImageRootObj, anImageObj );
284 case KIND_BATHYMETRY:
286 Handle(HYDROData_Bathymetry) aBathymetryObj =
287 Handle(HYDROData_Bathymetry)::DownCast( anObj );
288 if( !aBathymetryObj.IsNull() ) {
289 createObject( aBathymetryRootObj, aBathymetryObj );
296 Handle(HYDROData_Channel) aChannelObj =
297 Handle(HYDROData_Channel)::DownCast( anObj );
298 if( !aChannelObj.IsNull() ) {
299 createObject( anArtificialObjectsRootObj, aChannelObj );
306 Handle(HYDROData_Digue) aDigueObj =
307 Handle(HYDROData_Digue)::DownCast( anObj );
308 if( !aDigueObj.IsNull() ) {
309 createObject( anArtificialObjectsRootObj, aDigueObj );
314 case KIND_IMMERSIBLE_ZONE:
316 Handle(HYDROData_ImmersibleZone) anImmersibleZoneObj =
317 Handle(HYDROData_ImmersibleZone)::DownCast( anObj );
318 if( !anImmersibleZoneObj.IsNull() ) {
319 createObject( aNaturalObjectsRootObj, anImmersibleZoneObj );
326 Handle(HYDROData_River) aRiverObj =
327 Handle(HYDROData_River)::DownCast( anObj );
328 if( !aRiverObj.IsNull() ) {
329 createObject( aNaturalObjectsRootObj, aRiverObj );
336 Handle(HYDROData_Stream) aStreamObj =
337 Handle(HYDROData_Stream)::DownCast( anObj );
338 if( !aStreamObj.IsNull() ) {
339 createObject( aNaturalObjectsRootObj, aStreamObj );
346 Handle(HYDROData_Obstacle) anObstacleObj =
347 Handle(HYDROData_Obstacle)::DownCast( anObj );
348 if( !anObstacleObj.IsNull() ) {
349 createObject( anObstaclesRootObj, anObstacleObj );
354 case KIND_CALCULATION:
356 Handle(HYDROData_CalculationCase) aCalculObj =
357 Handle(HYDROData_CalculationCase)::DownCast( anObj );
358 if( !aCalculObj.IsNull() ) {
359 createObject( aCalculRootObj, aCalculObj );
364 case KIND_POLYLINEXY:
366 Handle(HYDROData_PolylineXY) aPolylineObj =
367 Handle(HYDROData_PolylineXY)::DownCast( anObj );
368 if( !aPolylineObj.IsNull() ) {
369 createObject( aPolylineRootObj, aPolylineObj );
376 Handle(HYDROData_Polyline3D) aPolylineObj =
377 Handle(HYDROData_Polyline3D)::DownCast( anObj );
378 if( !aPolylineObj.IsNull() ) {
379 createObject( aPolyline3DRootObj, aPolylineObj );
386 Handle(HYDROData_Profile) aProfileObj =
387 Handle(HYDROData_Profile)::DownCast( anObj );
388 if( !aProfileObj.IsNull() ) {
389 createObject( aProfileRootObj, aProfileObj );
394 case KIND_VISUAL_STATE:
396 Handle(HYDROData_VisualState) aVisualStateObj =
397 Handle(HYDROData_VisualState)::DownCast( anObj );
398 if( !aVisualStateObj.IsNull() ) {
399 createObject( aVisualStateRootObj, aVisualStateObj );
408 if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
410 anObjectBrowser->setAutoOpenLevel( 3 );
411 anObjectBrowser->openLevels();
415 HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )
417 return NULL; // to do if necessary
420 HYDROGUI_DataObject* HYDROGUI_DataModel::getReferencedDataObject( HYDROGUI_DataObject* theObject )
422 return NULL; // to do if necessary
425 SUIT_DataObject* HYDROGUI_DataModel::findObject( const QString& theEntry ) const
427 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
428 return anApp ? anApp->findObject( theEntry ) : 0;
431 void HYDROGUI_DataModel::update( LightApp_DataObject* theObject,
432 LightApp_Study* theStudy )
435 theStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy()) ;
437 update( theStudy->id() );
440 CAM_DataObject* HYDROGUI_DataModel::createRootModuleObject( SUIT_DataObject* theParent )
442 CAM_ModuleObject* aRootObj = createModuleObject( theParent );
443 aRootObj->setDataModel( this );
448 void HYDROGUI_DataModel::updateModel()
450 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
452 update( aModule->getStudyId() );
455 Handle(HYDROData_Entity) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
456 const ObjectKind theObjectKind )
458 QString anEntry = theEntry;
459 if( anEntry.indexOf( "_" ) != -1 ) // reference object
460 anEntry = anEntry.section( "_", -1 );
462 Handle(HYDROData_Document) aDocument = getDocument();
463 if( !aDocument.IsNull() )
465 HYDROData_Iterator anIterator( aDocument, theObjectKind );
466 for( ; anIterator.More(); anIterator.Next() )
468 Handle(HYDROData_Entity) anObject = anIterator.Current();
469 if( !anObject.IsNull() )
471 QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
472 if( anEntryRef == anEntry )
480 bool HYDROGUI_DataModel::canUndo() const
482 return getDocument()->CanUndo();
485 bool HYDROGUI_DataModel::canRedo() const
487 return getDocument()->CanRedo();
490 QStringList HYDROGUI_DataModel::undoNames() const
493 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetUndos() ); anIter.More(); anIter.Next() )
494 aNames.prepend( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
498 QStringList HYDROGUI_DataModel::redoNames() const
501 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetRedos() ); anIter.More(); anIter.Next() )
502 aNames.append( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
506 void HYDROGUI_DataModel::clearUndos()
508 getDocument()->ClearUndos();
511 void HYDROGUI_DataModel::clearRedos()
513 getDocument()->ClearRedos();
516 bool HYDROGUI_DataModel::undo()
520 getDocument()->Undo();
522 catch ( Standard_Failure )
529 bool HYDROGUI_DataModel::redo()
533 getDocument()->Redo();
535 catch ( Standard_Failure )
542 bool HYDROGUI_DataModel::canCopy()
544 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
545 if( aSeq.Length() != 1 )
548 Handle(HYDROData_Entity) anObject = aSeq.First();
549 if( anObject.IsNull() )
552 ObjectKind aKind = anObject->GetKind();
553 if( aKind == KIND_IMAGE ||
554 aKind == KIND_POLYLINE ||
555 aKind == KIND_PROFILE ||
556 aKind == KIND_CALCULATION )
562 bool HYDROGUI_DataModel::canPaste()
564 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
566 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
567 if( !anObject.IsNull() && !anObject->IsRemoved() )
573 bool HYDROGUI_DataModel::copy()
575 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
576 changeCopyingObjects( aSeq );
580 bool HYDROGUI_DataModel::paste()
582 bool anIsChanged = false;
583 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
585 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
586 if( !anObject.IsNull() && !anObject->IsRemoved() )
588 ObjectKind aKind = anObject->GetKind();
589 Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind );
590 if( !aClone.IsNull() )
592 anObject->CopyTo( aClone );
595 // generate a new unique name for the clone object:
596 // case 1: Image_1 -> Image_2
597 // case 2: ImageObj -> ImageObj_1
598 QString aName = aClone->GetName();
599 QString aPrefix = aName;
600 if( aName.contains( '_' ) ) // case 1
602 QString aSuffix = aName.section( '_', -1 );
603 bool anIsInteger = false;
604 aSuffix.toInt( &anIsInteger );
606 aPrefix = aName.section( '_', 0, -2 );
610 aName = HYDROGUI_Tool::GenerateObjectName( (HYDROGUI_Module*)module(), aPrefix );
611 aClone->SetName( aName );
618 void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects& theSeq )
620 myCopyingObjects.Assign( theSeq );
623 QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind )
625 switch( theObjectKind )
627 case KIND_IMAGE: return "IMAGES";
628 case KIND_POLYLINE: return "POLYLINES_3D";
629 case KIND_POLYLINEXY: return "POLYLINES";
630 case KIND_PROFILE: return "PROFILES";
631 case KIND_VISUAL_STATE: return "VISUAL_STATES";
632 case KIND_BATHYMETRY: return "BATHYMETRIES";
633 case KIND_CALCULATION: return "CALCULATION_CASES";
634 case KIND_OBSTACLE: return "OBSTACLES";
635 case KIND_ARTIFICIAL_OBJECT: return "ARTIFICIAL_OBJECTS";
636 case KIND_NATURAL_OBJECT: return "NATURAL_OBJECTS";
642 Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
644 int aStudyId = module()->application()->activeStudy()->id();
645 return HYDROData_Document::Document( aStudyId );
648 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
649 Handle(HYDROData_Entity) theModelObject,
650 const QString& theParentEntry,
651 const bool theIsBuildTree )
653 HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
655 if ( theIsBuildTree )
657 buildObjectTree( theParent, aResObj, theParentEntry );
663 LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* theParent,
664 HYDROGUI_DataObject* theObject,
665 const QString& theParentEntry,
666 const bool theIsBuildTree )
668 if ( theIsBuildTree )
670 buildObjectTree( theParent, theObject, theParentEntry );
675 LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theParent,
676 Handle(HYDROData_Zone) theModelObject,
677 const QString& theParentEntry,
678 const bool theIsBuildTree )
680 return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
683 LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent,
684 Handle(HYDROData_Region) theModelObject,
685 const QString& theParentEntry,
686 const bool theIsBuildTree )
688 return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
691 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
692 const QString& theName,
693 const QString& theParentEntry )
695 return new HYDROGUI_NamedObject( theParent, theName, theParentEntry );
698 void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
699 SUIT_DataObject* theObject,
700 const QString& theParentEntry )
702 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
706 Handle(HYDROData_Entity) aDataObj = aGuiObj->modelObject();
707 if ( aDataObj.IsNull() )
710 if ( aDataObj->IsKind( STANDARD_TYPE(HYDROData_Object) ) )
712 Handle(HYDROData_Object) aGeomObj =
713 Handle(HYDROData_Object)::DownCast( aDataObj );
715 Handle(HYDROData_DummyObject3D) anObject3D = aGeomObj->GetObject3D();
716 if ( !anObject3D.IsNull() )
717 createObject( aGuiObj, anObject3D, aGuiObj->entry(), false );
720 ObjectKind anObjectKind = aDataObj->GetKind();
722 if ( anObjectKind == KIND_IMAGE )
724 Handle(HYDROData_Image) anImageObj =
725 Handle(HYDROData_Image)::DownCast( aDataObj );
726 for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
728 Handle(HYDROData_Entity) aRefObj = anImageObj->Reference( anIndex );
729 if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
730 createObject( aGuiObj, aRefObj, aGuiObj->entry(), false );
733 else if ( anObjectKind == KIND_IMMERSIBLE_ZONE )
735 Handle(HYDROData_ImmersibleZone) aZoneObj =
736 Handle(HYDROData_ImmersibleZone)::DownCast( aDataObj );
738 LightApp_DataObject* aPolylineSect =
739 createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() );
741 Handle(HYDROData_PolylineXY) aPolyline = aZoneObj->GetPolyline();
742 if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
743 createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
745 LightApp_DataObject* aBathSect =
746 createObject( aGuiObj, tr( "ZONE_BATHYMETRY" ), aGuiObj->entry() );
748 Handle(HYDROData_Bathymetry) aBathymetry = aZoneObj->GetBathymetry();
749 if ( !aBathymetry.IsNull() && !aBathymetry->IsRemoved() )
750 createObject( aBathSect, aBathymetry, aGuiObj->entry(), false );
752 else if ( anObjectKind == KIND_CALCULATION )
754 Handle(HYDROData_CalculationCase) aCaseObj =
755 Handle(HYDROData_CalculationCase)::DownCast( aDataObj );
757 LightApp_DataObject* aCaseRegionsSect =
758 createObject( aGuiObj, tr( "CASE_REGIONS" ), aGuiObj->entry() );
760 HYDROData_SequenceOfObjects aCaseRegions = aCaseObj->GetRegions();
761 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
762 for ( ; anIter.More(); anIter.Next() )
764 Handle(HYDROData_Region) aCaseRegion =
765 Handle(HYDROData_Region)::DownCast( anIter.Value() );
766 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
767 createRegion( aCaseRegionsSect, aCaseRegion, "", true );
770 else if ( anObjectKind == KIND_REGION )
772 Handle(HYDROData_Region) aRegionObj =
773 Handle(HYDROData_Region)::DownCast( aDataObj );
775 HYDROData_SequenceOfObjects aRegionZones = aRegionObj->GetZones();
776 HYDROData_SequenceOfObjects::Iterator anIter( aRegionZones );
777 for ( ; anIter.More(); anIter.Next() )
779 Handle(HYDROData_Zone) aRegionZone =
780 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
781 if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() )
782 createZone( aGuiObj, aRegionZone, "", true );
785 else if ( anObjectKind == KIND_PROFILE )
787 Handle(HYDROData_Profile) aProfileObj =
788 Handle(HYDROData_Profile)::DownCast( aDataObj );
790 aGuiObj->setIsValid( aProfileObj->IsValid() );
794 void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
796 if ( !theCase.IsNull() )
798 new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "" );
800 HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions();
801 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
802 for ( ; anIter.More(); anIter.Next() )
804 Handle(HYDROData_Region) aCaseRegion =
805 Handle(HYDROData_Region)::DownCast( anIter.Value() );
806 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
807 createRegion( theParent, aCaseRegion, "", true );
812 void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent,
813 SUIT_DataObject* theChild )
815 SUIT_DataObject* aSubChild = theChild->firstChild();
816 for( ; aSubChild; aSubChild = aSubChild->nextBrother() )
817 removeChild( theChild, aSubChild );
818 theParent->removeChild( theChild );
821 SUIT_DataObject* HYDROGUI_DataModel::findChildByName( const SUIT_DataObject* theFather,
822 const QString& theName )
824 SUIT_DataObject* aChild = theFather->firstChild();
827 if( aChild->name() == theName )
828 return aChild; // found
829 aChild = aChild->nextBrother();
831 return NULL; // not found
834 bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theCase,
835 const QList<HYDROGUI_Zone*>& theZonesList )
837 bool isOk = !theCase.IsNull();
840 Handle(HYDROData_Region) aRegion;
841 Handle(HYDROData_Zone) aZone;
842 for (int i = 0; i < theZonesList.length(); i++ )
844 aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() );
845 if ( !aZone.IsNull() )
847 if ( aRegion.IsNull() )
849 aRegion = theCase->AddNewRegion( aZone );
850 isOk = !aRegion.IsNull();
854 if ( !( aRegion->AddZone( aZone ) ) )
865 bool HYDROGUI_DataModel::rename( Handle(HYDROData_Entity) theEntity, const QString& theName )
867 if ( theName.isEmpty() )
872 getDocument()->StartOperation();
873 theEntity->SetName( theName );
874 getDocument()->CommitOperation( HYDROGUI_Tool::ToExtString( tr("RENAME_TO").arg( theName ) ) );
875 module()->application()->activeStudy()->Modified();
877 catch ( Standard_Failure )
879 getDocument()->AbortOperation();