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_Image.h>
35 #include <HYDROData_ImmersibleZone.h>
36 #include <HYDROData_Iterator.h>
37 #include <HYDROData_PolylineXY.h>
38 #include <HYDROData_Profile.h>
39 #include <HYDROData_VisualState.h>
40 #include <HYDROData_Region.h>
41 #include <HYDROData_Zone.h>
42 #include <HYDROData_Obstacle.h>
43 #include <HYDROData_Channel.h>
44 #include <HYDROData_Digue.h>
45 #include <HYDROData_River.h>
47 #include <CAM_Application.h>
48 #include <CAM_DataObject.h>
49 #include <CAM_Module.h>
50 #include <CAM_Study.h>
52 #include <LightApp_Application.h>
53 #include <LightApp_DataObject.h>
54 #include <LightApp_Study.h>
56 #include <SUIT_DataObject.h>
57 #include <SUIT_DataBrowser.h>
58 #include <SUIT_ResourceMgr.h>
59 #include <SUIT_Study.h>
60 #include <SUIT_Tools.h>
62 #include <HYDROData_Document.h>
64 #include <TDF_Delta.hxx>
65 #include <TDF_ListIteratorOfDeltaList.hxx>
67 #include <QApplication>
70 static HYDROData_SequenceOfObjects myCopyingObjects;
72 HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
73 : LightApp_DataModel( theModule )
75 update( module()->application()->activeStudy()->id() );
78 HYDROGUI_DataModel::~HYDROGUI_DataModel()
82 bool HYDROGUI_DataModel::open( const QString& theURL,
84 QStringList theFileList )
86 LightApp_DataModel::open( theURL, theStudy, theFileList );
87 const int aStudyId = theStudy->id();
89 Data_DocError res = DocError_UnknownProblem;
90 if( theFileList.count() == 2 )
92 QString aTmpDir = theFileList[0];
93 QString aFileName = theFileList[1];
96 QString aFullPath = SUIT_Tools::addSlash( aTmpDir ) + aFileName;
100 res = HYDROData_Document::Load( (char*)aFullPath.toLatin1().constData(), aStudyId );
104 res = DocError_UnknownProblem;
106 if( res != DocError_OK )
108 module()->application()->putInfo( tr( "LOAD_ERROR" ) );
113 // if the document open was successful, the data model update happens
114 // in the set mode of the module
115 if( res == DocError_OK )
121 bool HYDROGUI_DataModel::save( QStringList& theFileList )
123 if( !module()->application()->activeStudy() )
126 LightApp_DataModel::save( theFileList );
130 SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
131 bool isMultiFile = false;
133 isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
135 // save data to temporary files
136 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
137 aTmpDir = aStudy->GetTmpDir( myStudyURL.toLatin1().constData(), isMultiFile ).c_str();
138 aFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf";
140 QString aFullPath = aTmpDir + aFileName;
141 Data_DocError res = getDocument()->Save( (char*)aFullPath.toLatin1().constData() );
142 if( res != DocError_OK )
144 module()->application()->putInfo( tr( "SAVE_ERROR" ) );
148 theFileList.append( aTmpDir );
149 theFileList.append( aFileName );
154 bool HYDROGUI_DataModel::saveAs( const QString& theURL,
156 QStringList& theFileList )
159 return save( theFileList );
162 bool HYDROGUI_DataModel::close()
167 bool HYDROGUI_DataModel::dumpPython( const QString& theURL,
170 QStringList& theListOfFiles )
172 LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
174 int aStudyId = theStudy->id();
176 LightApp_Study* aStudy = ::qobject_cast<LightApp_Study*>( theStudy );
177 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
178 if ( aDocument.IsNull() || !aStudy )
181 QString aFileToExport = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str();
182 aFileToExport += QString( QDir::separator() ) + "HYDRO.py";
184 bool aRes = aDocument->DumpToPython( aFileToExport );
188 theListOfFiles.append( aFileToExport );
194 bool HYDROGUI_DataModel::isModified() const
196 return getDocument()->IsModified();
199 bool HYDROGUI_DataModel::isSaved() const
204 void HYDROGUI_DataModel::update( const int theStudyId )
206 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
210 SUIT_DataObject* aStudyRoot = anApp->activeStudy()->root();
214 // create root object if not exist
215 CAM_DataObject* aRootObj = root();
217 aRootObj = createRootModuleObject( aStudyRoot );
222 DataObjectList aList;
223 aRootObj->children( aList );
224 QListIterator<SUIT_DataObject*> anIter( aList );
225 while( anIter.hasNext() )
226 removeChild( aRootObj, anIter.next() );
228 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theStudyId );
229 if( aDocument.IsNull() )
232 // Create root objects:
235 LightApp_DataObject* anImageRootObj = createObject( aRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
238 LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
240 // ARTIFICIAL OBJECTS
241 LightApp_DataObject* anArtificialObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
244 LightApp_DataObject* aNaturalObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
247 LightApp_DataObject* anObstaclesRootObj = createObject( aRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
250 LightApp_DataObject* aCalculRootObj = createObject( aRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
253 LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
256 LightApp_DataObject* aProfileRootObj = createObject( aRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
259 LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
261 HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN );
262 for( ; anIterator.More(); anIterator.Next() ) {
263 Handle(HYDROData_Entity) anObj = anIterator.Current();
265 if ( !anObj.IsNull() )
267 switch ( anObj->GetKind() ) {
270 Handle(HYDROData_Image) anImageObj =
271 Handle(HYDROData_Image)::DownCast( anObj );
272 if( !anImageObj.IsNull() ) {
273 createObject( anImageRootObj, anImageObj );
278 case KIND_BATHYMETRY:
280 Handle(HYDROData_Bathymetry) aBathymetryObj =
281 Handle(HYDROData_Bathymetry)::DownCast( anObj );
282 if( !aBathymetryObj.IsNull() ) {
283 createObject( aBathymetryRootObj, aBathymetryObj );
290 Handle(HYDROData_Channel) aChannelObj =
291 Handle(HYDROData_Channel)::DownCast( anObj );
292 if( !aChannelObj.IsNull() ) {
293 createObject( anArtificialObjectsRootObj, aChannelObj );
300 Handle(HYDROData_Digue) aDigueObj =
301 Handle(HYDROData_Digue)::DownCast( anObj );
302 if( !aDigueObj.IsNull() ) {
303 createObject( anArtificialObjectsRootObj, aDigueObj );
308 case KIND_IMMERSIBLE_ZONE:
310 Handle(HYDROData_ImmersibleZone) anImmersibleZoneObj =
311 Handle(HYDROData_ImmersibleZone)::DownCast( anObj );
312 if( !anImmersibleZoneObj.IsNull() ) {
313 createObject( aNaturalObjectsRootObj, anImmersibleZoneObj );
320 Handle(HYDROData_River) aRiverObj =
321 Handle(HYDROData_River)::DownCast( anObj );
322 if( !aRiverObj.IsNull() ) {
323 createObject( aNaturalObjectsRootObj, aRiverObj );
330 Handle(HYDROData_Obstacle) anObstacleObj =
331 Handle(HYDROData_Obstacle)::DownCast( anObj );
332 if( !anObstacleObj.IsNull() ) {
333 createObject( anObstaclesRootObj, anObstacleObj );
338 case KIND_CALCULATION:
340 Handle(HYDROData_CalculationCase) aCalculObj =
341 Handle(HYDROData_CalculationCase)::DownCast( anObj );
342 if( !aCalculObj.IsNull() ) {
343 createObject( aCalculRootObj, aCalculObj );
348 case KIND_POLYLINEXY:
350 Handle(HYDROData_PolylineXY) aPolylineObj =
351 Handle(HYDROData_PolylineXY)::DownCast( anObj );
352 if( !aPolylineObj.IsNull() ) {
353 createObject( aPolylineRootObj, aPolylineObj );
360 Handle(HYDROData_Profile) aProfileObj =
361 Handle(HYDROData_Profile)::DownCast( anObj );
362 if( !aProfileObj.IsNull() ) {
363 createObject( aProfileRootObj, aProfileObj );
368 case KIND_VISUAL_STATE:
370 Handle(HYDROData_VisualState) aVisualStateObj =
371 Handle(HYDROData_VisualState)::DownCast( anObj );
372 if( !aVisualStateObj.IsNull() ) {
373 createObject( aVisualStateRootObj, aVisualStateObj );
382 if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
384 anObjectBrowser->setAutoOpenLevel( 3 );
385 anObjectBrowser->openLevels();
389 HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )
391 return NULL; // to do if necessary
394 HYDROGUI_DataObject* HYDROGUI_DataModel::getReferencedDataObject( HYDROGUI_DataObject* theObject )
396 return NULL; // to do if necessary
399 SUIT_DataObject* HYDROGUI_DataModel::findObject( const QString& theEntry ) const
401 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
402 return anApp ? anApp->findObject( theEntry ) : 0;
405 void HYDROGUI_DataModel::update( LightApp_DataObject* theObject,
406 LightApp_Study* theStudy )
409 theStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy()) ;
411 update( theStudy->id() );
414 CAM_DataObject* HYDROGUI_DataModel::createRootModuleObject( SUIT_DataObject* theParent )
416 CAM_DataObject* aRootObj = createModuleObject( theParent );
421 void HYDROGUI_DataModel::updateModel()
423 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
425 update( aModule->getStudyId() );
428 Handle(HYDROData_Entity) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
429 const ObjectKind theObjectKind )
431 QString anEntry = theEntry;
432 if( anEntry.indexOf( "_" ) != -1 ) // reference object
433 anEntry = anEntry.section( "_", -1 );
435 Handle(HYDROData_Document) aDocument = getDocument();
436 if( !aDocument.IsNull() )
438 HYDROData_Iterator anIterator( aDocument, theObjectKind );
439 for( ; anIterator.More(); anIterator.Next() )
441 Handle(HYDROData_Entity) anObject = anIterator.Current();
442 if( !anObject.IsNull() )
444 QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
445 if( anEntryRef == anEntry )
453 bool HYDROGUI_DataModel::canUndo() const
455 return getDocument()->CanUndo();
458 bool HYDROGUI_DataModel::canRedo() const
460 return getDocument()->CanRedo();
463 QStringList HYDROGUI_DataModel::undoNames() const
466 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetUndos() ); anIter.More(); anIter.Next() )
467 aNames.prepend( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
471 QStringList HYDROGUI_DataModel::redoNames() const
474 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetRedos() ); anIter.More(); anIter.Next() )
475 aNames.append( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
479 void HYDROGUI_DataModel::clearUndos()
481 getDocument()->ClearUndos();
484 void HYDROGUI_DataModel::clearRedos()
486 getDocument()->ClearRedos();
489 bool HYDROGUI_DataModel::undo()
493 getDocument()->Undo();
495 catch ( Standard_Failure )
502 bool HYDROGUI_DataModel::redo()
506 getDocument()->Redo();
508 catch ( Standard_Failure )
515 bool HYDROGUI_DataModel::canCopy()
517 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
518 if( aSeq.Length() != 1 )
521 Handle(HYDROData_Entity) anObject = aSeq.First();
522 if( anObject.IsNull() )
525 ObjectKind aKind = anObject->GetKind();
526 if( aKind == KIND_IMAGE ||
527 aKind == KIND_POLYLINE ||
528 aKind == KIND_PROFILE ||
529 aKind == KIND_CALCULATION )
535 bool HYDROGUI_DataModel::canPaste()
537 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
539 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
540 if( !anObject.IsNull() && !anObject->IsRemoved() )
546 bool HYDROGUI_DataModel::copy()
548 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
549 changeCopyingObjects( aSeq );
553 bool HYDROGUI_DataModel::paste()
555 bool anIsChanged = false;
556 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
558 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
559 if( !anObject.IsNull() && !anObject->IsRemoved() )
561 ObjectKind aKind = anObject->GetKind();
562 Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind );
563 if( !aClone.IsNull() )
565 anObject->CopyTo( aClone );
568 // generate a new unique name for the clone object:
569 // case 1: Image_1 -> Image_2
570 // case 2: ImageObj -> ImageObj_1
571 QString aName = aClone->GetName();
572 QString aPrefix = aName;
573 if( aName.contains( '_' ) ) // case 1
575 QString aSuffix = aName.section( '_', -1 );
576 bool anIsInteger = false;
577 aSuffix.toInt( &anIsInteger );
579 aPrefix = aName.section( '_', 0, -2 );
583 aName = HYDROGUI_Tool::GenerateObjectName( (HYDROGUI_Module*)module(), aPrefix );
584 aClone->SetName( aName );
591 void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects& theSeq )
593 myCopyingObjects.Assign( theSeq );
596 QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind )
598 switch( theObjectKind )
600 case KIND_IMAGE: return "IMAGES";
601 case KIND_POLYLINEXY: return "POLYLINES";
602 case KIND_PROFILE: return "PROFILES";
603 case KIND_VISUAL_STATE: return "VISUAL_STATES";
604 case KIND_BATHYMETRY: return "BATHYMETRIES";
605 case KIND_CALCULATION: return "CALCULATION_CASES";
606 case KIND_OBSTACLE: return "OBSTACLES";
607 case KIND_ARTIFICIAL_OBJECT: return "ARTIFICIAL_OBJECTS";
608 case KIND_NATURAL_OBJECT: return "NATURAL_OBJECTS";
614 Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
616 int aStudyId = module()->application()->activeStudy()->id();
617 return HYDROData_Document::Document( aStudyId );
620 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
621 Handle(HYDROData_Entity) theModelObject,
622 const QString& theParentEntry,
623 const bool theIsBuildTree )
625 HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
627 if ( theIsBuildTree )
629 buildObjectTree( theParent, aResObj, theParentEntry );
635 LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* theParent,
636 HYDROGUI_DataObject* theObject,
637 const QString& theParentEntry,
638 const bool theIsBuildTree )
640 if ( theIsBuildTree )
642 buildObjectTree( theParent, theObject, theParentEntry );
647 LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theParent,
648 Handle(HYDROData_Zone) theModelObject,
649 const QString& theParentEntry,
650 const bool theIsBuildTree )
652 return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
655 LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent,
656 Handle(HYDROData_Region) theModelObject,
657 const QString& theParentEntry,
658 const bool theIsBuildTree )
660 return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
663 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
664 const QString& theName,
665 const QString& theParentEntry )
667 return new HYDROGUI_NamedObject( theParent, theName, theParentEntry );
670 void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
671 SUIT_DataObject* theObject,
672 const QString& theParentEntry )
674 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
678 Handle(HYDROData_Entity) aDataObj = aGuiObj->modelObject();
679 if ( aDataObj.IsNull() )
682 ObjectKind anObjectKind = aDataObj->GetKind();
684 if ( anObjectKind == KIND_IMAGE )
686 Handle(HYDROData_Image) anImageObj =
687 Handle(HYDROData_Image)::DownCast( aDataObj );
688 for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
690 Handle(HYDROData_Entity) aRefObj = anImageObj->Reference( anIndex );
691 if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
692 createObject( aGuiObj, aRefObj, aGuiObj->entry(), false );
695 else if ( anObjectKind == KIND_IMMERSIBLE_ZONE )
697 Handle(HYDROData_ImmersibleZone) aZoneObj =
698 Handle(HYDROData_ImmersibleZone)::DownCast( aDataObj );
700 LightApp_DataObject* aPolylineSect =
701 createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() );
703 Handle(HYDROData_PolylineXY) aPolyline = aZoneObj->GetPolyline();
704 if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
705 createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
707 LightApp_DataObject* aBathSect =
708 createObject( aGuiObj, tr( "ZONE_BATHYMETRY" ), aGuiObj->entry() );
710 Handle(HYDROData_Bathymetry) aBathymetry = aZoneObj->GetBathymetry();
711 if ( !aBathymetry.IsNull() && !aBathymetry->IsRemoved() )
712 createObject( aBathSect, aBathymetry, aGuiObj->entry(), false );
714 else if ( anObjectKind == KIND_CALCULATION )
716 Handle(HYDROData_CalculationCase) aCaseObj =
717 Handle(HYDROData_CalculationCase)::DownCast( aDataObj );
719 LightApp_DataObject* aCaseRegionsSect =
720 createObject( aGuiObj, tr( "CASE_REGIONS" ), aGuiObj->entry() );
722 HYDROData_SequenceOfObjects aCaseRegions = aCaseObj->GetRegions();
723 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
724 for ( ; anIter.More(); anIter.Next() )
726 Handle(HYDROData_Region) aCaseRegion =
727 Handle(HYDROData_Region)::DownCast( anIter.Value() );
728 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
729 createRegion( aCaseRegionsSect, aCaseRegion, "", true );
732 else if ( anObjectKind == KIND_REGION )
734 Handle(HYDROData_Region) aRegionObj =
735 Handle(HYDROData_Region)::DownCast( aDataObj );
737 HYDROData_SequenceOfObjects aRegionZones = aRegionObj->GetZones();
738 HYDROData_SequenceOfObjects::Iterator anIter( aRegionZones );
739 for ( ; anIter.More(); anIter.Next() )
741 Handle(HYDROData_Zone) aRegionZone =
742 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
743 if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() )
744 createZone( aGuiObj, aRegionZone, "", true );
747 else if ( anObjectKind == KIND_PROFILE )
749 Handle(HYDROData_Profile) aProfileObj =
750 Handle(HYDROData_Profile)::DownCast( aDataObj );
752 aGuiObj->setIsValid( aProfileObj->IsValid() );
756 void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
758 if ( !theCase.IsNull() )
760 new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "" );
762 HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions();
763 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
764 for ( ; anIter.More(); anIter.Next() )
766 Handle(HYDROData_Region) aCaseRegion =
767 Handle(HYDROData_Region)::DownCast( anIter.Value() );
768 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
769 createRegion( theParent, aCaseRegion, "", true );
774 void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent,
775 SUIT_DataObject* theChild )
777 SUIT_DataObject* aSubChild = theChild->firstChild();
778 for( ; aSubChild; aSubChild = aSubChild->nextBrother() )
779 removeChild( theChild, aSubChild );
780 theParent->removeChild( theChild );
783 SUIT_DataObject* HYDROGUI_DataModel::findChildByName( const SUIT_DataObject* theFather,
784 const QString& theName )
786 SUIT_DataObject* aChild = theFather->firstChild();
789 if( aChild->name() == theName )
790 return aChild; // found
791 aChild = aChild->nextBrother();
793 return NULL; // not found
796 bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theCase,
797 const QList<HYDROGUI_Zone*>& theZonesList )
799 bool isOk = !theCase.IsNull();
802 Handle(HYDROData_Region) aRegion;
803 Handle(HYDROData_Zone) aZone;
804 for (int i = 0; i < theZonesList.length(); i++ )
806 aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() );
807 if ( !aZone.IsNull() )
809 if ( aRegion.IsNull() )
811 aRegion = theCase->AddNewRegion( aZone );
812 isOk = !aRegion.IsNull();
816 if ( !( aRegion->AddZone( aZone ) ) )