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_Polyline3D.h>
38 #include <HYDROData_PolylineXY.h>
39 #include <HYDROData_Profile.h>
40 #include <HYDROData_VisualState.h>
41 #include <HYDROData_Region.h>
42 #include <HYDROData_Zone.h>
43 #include <HYDROData_Obstacle.h>
44 #include <HYDROData_Channel.h>
45 #include <HYDROData_Digue.h>
46 #include <HYDROData_River.h>
48 #include <CAM_Application.h>
49 #include <CAM_DataObject.h>
50 #include <CAM_Module.h>
51 #include <CAM_Study.h>
53 #include <LightApp_Application.h>
54 #include <LightApp_DataObject.h>
55 #include <LightApp_Study.h>
57 #include <SUIT_DataObject.h>
58 #include <SUIT_DataBrowser.h>
59 #include <SUIT_ResourceMgr.h>
60 #include <SUIT_Study.h>
61 #include <SUIT_Tools.h>
63 #include <HYDROData_Document.h>
65 #include <TDF_Delta.hxx>
66 #include <TDF_ListIteratorOfDeltaList.hxx>
68 #include <QApplication>
71 static HYDROData_SequenceOfObjects myCopyingObjects;
73 HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
74 : LightApp_DataModel( theModule )
76 update( module()->application()->activeStudy()->id() );
79 HYDROGUI_DataModel::~HYDROGUI_DataModel()
83 bool HYDROGUI_DataModel::open( const QString& theURL,
85 QStringList theFileList )
87 LightApp_DataModel::open( theURL, theStudy, theFileList );
88 const int aStudyId = theStudy->id();
90 Data_DocError res = DocError_UnknownProblem;
91 if( theFileList.count() == 2 )
93 QString aTmpDir = theFileList[0];
94 QString aFileName = theFileList[1];
97 QString aFullPath = SUIT_Tools::addSlash( aTmpDir ) + aFileName;
101 res = HYDROData_Document::Load( (char*)aFullPath.toLatin1().constData(), aStudyId );
105 res = DocError_UnknownProblem;
107 if( res != DocError_OK )
109 module()->application()->putInfo( tr( "LOAD_ERROR" ) );
114 // if the document open was successful, the data model update happens
115 // in the set mode of the module
116 if( res == DocError_OK )
122 bool HYDROGUI_DataModel::save( QStringList& theFileList )
124 if( !module()->application()->activeStudy() )
127 LightApp_DataModel::save( theFileList );
131 SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
132 bool isMultiFile = false;
134 isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
136 // save data to temporary files
137 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
138 aTmpDir = aStudy->GetTmpDir( myStudyURL.toLatin1().constData(), isMultiFile ).c_str();
139 aFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf";
141 QString aFullPath = aTmpDir + aFileName;
142 Data_DocError res = getDocument()->Save( (char*)aFullPath.toLatin1().constData() );
143 if( res != DocError_OK )
145 module()->application()->putInfo( tr( "SAVE_ERROR" ) );
149 theFileList.append( aTmpDir );
150 theFileList.append( aFileName );
155 bool HYDROGUI_DataModel::saveAs( const QString& theURL,
157 QStringList& theFileList )
160 return save( theFileList );
163 bool HYDROGUI_DataModel::close()
168 bool HYDROGUI_DataModel::dumpPython( const QString& theURL,
171 QStringList& theListOfFiles )
173 LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
175 int aStudyId = theStudy->id();
177 LightApp_Study* aStudy = ::qobject_cast<LightApp_Study*>( theStudy );
178 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
179 if ( aDocument.IsNull() || !aStudy )
182 QString aFileToExport = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str();
183 aFileToExport += QString( QDir::separator() ) + "HYDRO.py";
185 bool aRes = aDocument->DumpToPython( aFileToExport );
189 theListOfFiles.append( aFileToExport );
195 bool HYDROGUI_DataModel::isModified() const
197 return getDocument()->IsModified();
200 bool HYDROGUI_DataModel::isSaved() const
205 void HYDROGUI_DataModel::update( const int theStudyId )
207 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
211 SUIT_DataObject* aStudyRoot = anApp->activeStudy()->root();
215 // create root object if not exist
216 CAM_DataObject* aRootObj = root();
218 aRootObj = createRootModuleObject( aStudyRoot );
223 DataObjectList aList;
224 aRootObj->children( aList );
225 QListIterator<SUIT_DataObject*> anIter( aList );
226 while( anIter.hasNext() )
227 removeChild( aRootObj, anIter.next() );
229 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theStudyId );
230 if( aDocument.IsNull() )
233 // Create root objects:
236 LightApp_DataObject* anImageRootObj = createObject( aRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
239 LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
241 // ARTIFICIAL OBJECTS
242 LightApp_DataObject* anArtificialObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
245 LightApp_DataObject* aNaturalObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
248 LightApp_DataObject* anObstaclesRootObj = createObject( aRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
251 LightApp_DataObject* aCalculRootObj = createObject( aRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
254 LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
257 LightApp_DataObject* aPolyline3DRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
260 LightApp_DataObject* aProfileRootObj = createObject( aRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
263 LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
265 HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN );
266 for( ; anIterator.More(); anIterator.Next() ) {
267 Handle(HYDROData_Entity) anObj = anIterator.Current();
269 if ( !anObj.IsNull() )
271 switch ( anObj->GetKind() ) {
274 Handle(HYDROData_Image) anImageObj =
275 Handle(HYDROData_Image)::DownCast( anObj );
276 if( !anImageObj.IsNull() ) {
277 createObject( anImageRootObj, anImageObj );
282 case KIND_BATHYMETRY:
284 Handle(HYDROData_Bathymetry) aBathymetryObj =
285 Handle(HYDROData_Bathymetry)::DownCast( anObj );
286 if( !aBathymetryObj.IsNull() ) {
287 createObject( aBathymetryRootObj, aBathymetryObj );
294 Handle(HYDROData_Channel) aChannelObj =
295 Handle(HYDROData_Channel)::DownCast( anObj );
296 if( !aChannelObj.IsNull() ) {
297 createObject( anArtificialObjectsRootObj, aChannelObj );
304 Handle(HYDROData_Digue) aDigueObj =
305 Handle(HYDROData_Digue)::DownCast( anObj );
306 if( !aDigueObj.IsNull() ) {
307 createObject( anArtificialObjectsRootObj, aDigueObj );
312 case KIND_IMMERSIBLE_ZONE:
314 Handle(HYDROData_ImmersibleZone) anImmersibleZoneObj =
315 Handle(HYDROData_ImmersibleZone)::DownCast( anObj );
316 if( !anImmersibleZoneObj.IsNull() ) {
317 createObject( aNaturalObjectsRootObj, anImmersibleZoneObj );
324 Handle(HYDROData_River) aRiverObj =
325 Handle(HYDROData_River)::DownCast( anObj );
326 if( !aRiverObj.IsNull() ) {
327 createObject( aNaturalObjectsRootObj, aRiverObj );
334 Handle(HYDROData_Obstacle) anObstacleObj =
335 Handle(HYDROData_Obstacle)::DownCast( anObj );
336 if( !anObstacleObj.IsNull() ) {
337 createObject( anObstaclesRootObj, anObstacleObj );
342 case KIND_CALCULATION:
344 Handle(HYDROData_CalculationCase) aCalculObj =
345 Handle(HYDROData_CalculationCase)::DownCast( anObj );
346 if( !aCalculObj.IsNull() ) {
347 createObject( aCalculRootObj, aCalculObj );
352 case KIND_POLYLINEXY:
354 Handle(HYDROData_PolylineXY) aPolylineObj =
355 Handle(HYDROData_PolylineXY)::DownCast( anObj );
356 if( !aPolylineObj.IsNull() ) {
357 createObject( aPolylineRootObj, aPolylineObj );
364 Handle(HYDROData_Polyline3D) aPolylineObj =
365 Handle(HYDROData_Polyline3D)::DownCast( anObj );
366 if( !aPolylineObj.IsNull() ) {
367 createObject( aPolyline3DRootObj, aPolylineObj );
374 Handle(HYDROData_Profile) aProfileObj =
375 Handle(HYDROData_Profile)::DownCast( anObj );
376 if( !aProfileObj.IsNull() ) {
377 createObject( aProfileRootObj, aProfileObj );
382 case KIND_VISUAL_STATE:
384 Handle(HYDROData_VisualState) aVisualStateObj =
385 Handle(HYDROData_VisualState)::DownCast( anObj );
386 if( !aVisualStateObj.IsNull() ) {
387 createObject( aVisualStateRootObj, aVisualStateObj );
396 if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
398 anObjectBrowser->setAutoOpenLevel( 3 );
399 anObjectBrowser->openLevels();
403 HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )
405 return NULL; // to do if necessary
408 HYDROGUI_DataObject* HYDROGUI_DataModel::getReferencedDataObject( HYDROGUI_DataObject* theObject )
410 return NULL; // to do if necessary
413 SUIT_DataObject* HYDROGUI_DataModel::findObject( const QString& theEntry ) const
415 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
416 return anApp ? anApp->findObject( theEntry ) : 0;
419 void HYDROGUI_DataModel::update( LightApp_DataObject* theObject,
420 LightApp_Study* theStudy )
423 theStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy()) ;
425 update( theStudy->id() );
428 CAM_DataObject* HYDROGUI_DataModel::createRootModuleObject( SUIT_DataObject* theParent )
430 CAM_DataObject* aRootObj = createModuleObject( theParent );
435 void HYDROGUI_DataModel::updateModel()
437 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
439 update( aModule->getStudyId() );
442 Handle(HYDROData_Entity) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
443 const ObjectKind theObjectKind )
445 QString anEntry = theEntry;
446 if( anEntry.indexOf( "_" ) != -1 ) // reference object
447 anEntry = anEntry.section( "_", -1 );
449 Handle(HYDROData_Document) aDocument = getDocument();
450 if( !aDocument.IsNull() )
452 HYDROData_Iterator anIterator( aDocument, theObjectKind );
453 for( ; anIterator.More(); anIterator.Next() )
455 Handle(HYDROData_Entity) anObject = anIterator.Current();
456 if( !anObject.IsNull() )
458 QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
459 if( anEntryRef == anEntry )
467 bool HYDROGUI_DataModel::canUndo() const
469 return getDocument()->CanUndo();
472 bool HYDROGUI_DataModel::canRedo() const
474 return getDocument()->CanRedo();
477 QStringList HYDROGUI_DataModel::undoNames() const
480 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetUndos() ); anIter.More(); anIter.Next() )
481 aNames.prepend( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
485 QStringList HYDROGUI_DataModel::redoNames() const
488 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetRedos() ); anIter.More(); anIter.Next() )
489 aNames.append( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
493 void HYDROGUI_DataModel::clearUndos()
495 getDocument()->ClearUndos();
498 void HYDROGUI_DataModel::clearRedos()
500 getDocument()->ClearRedos();
503 bool HYDROGUI_DataModel::undo()
507 getDocument()->Undo();
509 catch ( Standard_Failure )
516 bool HYDROGUI_DataModel::redo()
520 getDocument()->Redo();
522 catch ( Standard_Failure )
529 bool HYDROGUI_DataModel::canCopy()
531 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
532 if( aSeq.Length() != 1 )
535 Handle(HYDROData_Entity) anObject = aSeq.First();
536 if( anObject.IsNull() )
539 ObjectKind aKind = anObject->GetKind();
540 if( aKind == KIND_IMAGE ||
541 aKind == KIND_POLYLINE ||
542 aKind == KIND_PROFILE ||
543 aKind == KIND_CALCULATION )
549 bool HYDROGUI_DataModel::canPaste()
551 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
553 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
554 if( !anObject.IsNull() && !anObject->IsRemoved() )
560 bool HYDROGUI_DataModel::copy()
562 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
563 changeCopyingObjects( aSeq );
567 bool HYDROGUI_DataModel::paste()
569 bool anIsChanged = false;
570 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
572 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
573 if( !anObject.IsNull() && !anObject->IsRemoved() )
575 ObjectKind aKind = anObject->GetKind();
576 Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind );
577 if( !aClone.IsNull() )
579 anObject->CopyTo( aClone );
582 // generate a new unique name for the clone object:
583 // case 1: Image_1 -> Image_2
584 // case 2: ImageObj -> ImageObj_1
585 QString aName = aClone->GetName();
586 QString aPrefix = aName;
587 if( aName.contains( '_' ) ) // case 1
589 QString aSuffix = aName.section( '_', -1 );
590 bool anIsInteger = false;
591 aSuffix.toInt( &anIsInteger );
593 aPrefix = aName.section( '_', 0, -2 );
597 aName = HYDROGUI_Tool::GenerateObjectName( (HYDROGUI_Module*)module(), aPrefix );
598 aClone->SetName( aName );
605 void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects& theSeq )
607 myCopyingObjects.Assign( theSeq );
610 QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind )
612 switch( theObjectKind )
614 case KIND_IMAGE: return "IMAGES";
615 case KIND_POLYLINE: return "POLYLINES 3D";
616 case KIND_POLYLINEXY: return "POLYLINES";
617 case KIND_PROFILE: return "PROFILES";
618 case KIND_VISUAL_STATE: return "VISUAL_STATES";
619 case KIND_BATHYMETRY: return "BATHYMETRIES";
620 case KIND_CALCULATION: return "CALCULATION_CASES";
621 case KIND_OBSTACLE: return "OBSTACLES";
622 case KIND_ARTIFICIAL_OBJECT: return "ARTIFICIAL_OBJECTS";
623 case KIND_NATURAL_OBJECT: return "NATURAL_OBJECTS";
629 Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
631 int aStudyId = module()->application()->activeStudy()->id();
632 return HYDROData_Document::Document( aStudyId );
635 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
636 Handle(HYDROData_Entity) theModelObject,
637 const QString& theParentEntry,
638 const bool theIsBuildTree )
640 HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
642 if ( theIsBuildTree )
644 buildObjectTree( theParent, aResObj, theParentEntry );
650 LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* theParent,
651 HYDROGUI_DataObject* theObject,
652 const QString& theParentEntry,
653 const bool theIsBuildTree )
655 if ( theIsBuildTree )
657 buildObjectTree( theParent, theObject, theParentEntry );
662 LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theParent,
663 Handle(HYDROData_Zone) theModelObject,
664 const QString& theParentEntry,
665 const bool theIsBuildTree )
667 return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
670 LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent,
671 Handle(HYDROData_Region) theModelObject,
672 const QString& theParentEntry,
673 const bool theIsBuildTree )
675 return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
678 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
679 const QString& theName,
680 const QString& theParentEntry )
682 return new HYDROGUI_NamedObject( theParent, theName, theParentEntry );
685 void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
686 SUIT_DataObject* theObject,
687 const QString& theParentEntry )
689 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
693 Handle(HYDROData_Entity) aDataObj = aGuiObj->modelObject();
694 if ( aDataObj.IsNull() )
697 ObjectKind anObjectKind = aDataObj->GetKind();
699 if ( anObjectKind == KIND_IMAGE )
701 Handle(HYDROData_Image) anImageObj =
702 Handle(HYDROData_Image)::DownCast( aDataObj );
703 for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
705 Handle(HYDROData_Entity) aRefObj = anImageObj->Reference( anIndex );
706 if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
707 createObject( aGuiObj, aRefObj, aGuiObj->entry(), false );
710 else if ( anObjectKind == KIND_IMMERSIBLE_ZONE )
712 Handle(HYDROData_ImmersibleZone) aZoneObj =
713 Handle(HYDROData_ImmersibleZone)::DownCast( aDataObj );
715 LightApp_DataObject* aPolylineSect =
716 createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() );
718 Handle(HYDROData_PolylineXY) aPolyline = aZoneObj->GetPolyline();
719 if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
720 createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
722 LightApp_DataObject* aBathSect =
723 createObject( aGuiObj, tr( "ZONE_BATHYMETRY" ), aGuiObj->entry() );
725 Handle(HYDROData_Bathymetry) aBathymetry = aZoneObj->GetBathymetry();
726 if ( !aBathymetry.IsNull() && !aBathymetry->IsRemoved() )
727 createObject( aBathSect, aBathymetry, aGuiObj->entry(), false );
729 else if ( anObjectKind == KIND_CALCULATION )
731 Handle(HYDROData_CalculationCase) aCaseObj =
732 Handle(HYDROData_CalculationCase)::DownCast( aDataObj );
734 LightApp_DataObject* aCaseRegionsSect =
735 createObject( aGuiObj, tr( "CASE_REGIONS" ), aGuiObj->entry() );
737 HYDROData_SequenceOfObjects aCaseRegions = aCaseObj->GetRegions();
738 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
739 for ( ; anIter.More(); anIter.Next() )
741 Handle(HYDROData_Region) aCaseRegion =
742 Handle(HYDROData_Region)::DownCast( anIter.Value() );
743 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
744 createRegion( aCaseRegionsSect, aCaseRegion, "", true );
747 else if ( anObjectKind == KIND_REGION )
749 Handle(HYDROData_Region) aRegionObj =
750 Handle(HYDROData_Region)::DownCast( aDataObj );
752 HYDROData_SequenceOfObjects aRegionZones = aRegionObj->GetZones();
753 HYDROData_SequenceOfObjects::Iterator anIter( aRegionZones );
754 for ( ; anIter.More(); anIter.Next() )
756 Handle(HYDROData_Zone) aRegionZone =
757 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
758 if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() )
759 createZone( aGuiObj, aRegionZone, "", true );
762 else if ( anObjectKind == KIND_PROFILE )
764 Handle(HYDROData_Profile) aProfileObj =
765 Handle(HYDROData_Profile)::DownCast( aDataObj );
767 aGuiObj->setIsValid( aProfileObj->IsValid() );
771 void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
773 if ( !theCase.IsNull() )
775 new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "" );
777 HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions();
778 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
779 for ( ; anIter.More(); anIter.Next() )
781 Handle(HYDROData_Region) aCaseRegion =
782 Handle(HYDROData_Region)::DownCast( anIter.Value() );
783 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
784 createRegion( theParent, aCaseRegion, "", true );
789 void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent,
790 SUIT_DataObject* theChild )
792 SUIT_DataObject* aSubChild = theChild->firstChild();
793 for( ; aSubChild; aSubChild = aSubChild->nextBrother() )
794 removeChild( theChild, aSubChild );
795 theParent->removeChild( theChild );
798 SUIT_DataObject* HYDROGUI_DataModel::findChildByName( const SUIT_DataObject* theFather,
799 const QString& theName )
801 SUIT_DataObject* aChild = theFather->firstChild();
804 if( aChild->name() == theName )
805 return aChild; // found
806 aChild = aChild->nextBrother();
808 return NULL; // not found
811 bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theCase,
812 const QList<HYDROGUI_Zone*>& theZonesList )
814 bool isOk = !theCase.IsNull();
817 Handle(HYDROData_Region) aRegion;
818 Handle(HYDROData_Zone) aZone;
819 for (int i = 0; i < theZonesList.length(); i++ )
821 aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() );
822 if ( !aZone.IsNull() )
824 if ( aRegion.IsNull() )
826 aRegion = theCase->AddNewRegion( aZone );
827 isOk = !aRegion.IsNull();
831 if ( !( aRegion->AddZone( aZone ) ) )