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>
47 #include <HYDROData_Stream.h>
49 #include <CAM_Application.h>
50 #include <CAM_DataObject.h>
51 #include <CAM_Module.h>
52 #include <CAM_Study.h>
54 #include <LightApp_Application.h>
55 #include <LightApp_DataObject.h>
56 #include <LightApp_Study.h>
58 #include <SUIT_DataObject.h>
59 #include <SUIT_DataBrowser.h>
60 #include <SUIT_ResourceMgr.h>
61 #include <SUIT_Study.h>
62 #include <SUIT_Tools.h>
64 #include <HYDROData_Document.h>
66 #include <TDF_Delta.hxx>
67 #include <TDF_ListIteratorOfDeltaList.hxx>
69 #include <QApplication>
72 static HYDROData_SequenceOfObjects myCopyingObjects;
74 HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
75 : LightApp_DataModel( theModule )
77 update( module()->application()->activeStudy()->id() );
80 HYDROGUI_DataModel::~HYDROGUI_DataModel()
84 bool HYDROGUI_DataModel::open( const QString& theURL,
86 QStringList theFileList )
88 LightApp_DataModel::open( theURL, theStudy, theFileList );
89 const int aStudyId = theStudy->id();
91 Data_DocError res = DocError_UnknownProblem;
92 if( theFileList.count() == 2 )
94 QString aTmpDir = theFileList[0];
95 QString aFileName = theFileList[1];
98 QString aFullPath = SUIT_Tools::addSlash( aTmpDir ) + aFileName;
102 res = HYDROData_Document::Load( (char*)aFullPath.toLatin1().constData(), aStudyId );
106 res = DocError_UnknownProblem;
108 if( res != DocError_OK )
110 module()->application()->putInfo( tr( "LOAD_ERROR" ) );
115 // if the document open was successful, the data model update happens
116 // in the set mode of the module
117 if( res == DocError_OK )
123 bool HYDROGUI_DataModel::save( QStringList& theFileList )
125 if( !module()->application()->activeStudy() )
128 LightApp_DataModel::save( theFileList );
132 SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
133 bool isMultiFile = false;
135 isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
137 // save data to temporary files
138 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
139 aTmpDir = aStudy->GetTmpDir( myStudyURL.toLatin1().constData(), isMultiFile ).c_str();
140 aFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf";
142 QString aFullPath = aTmpDir + aFileName;
143 Data_DocError res = getDocument()->Save( (char*)aFullPath.toLatin1().constData() );
144 if( res != DocError_OK )
146 module()->application()->putInfo( tr( "SAVE_ERROR" ) );
150 theFileList.append( aTmpDir );
151 theFileList.append( aFileName );
156 bool HYDROGUI_DataModel::saveAs( const QString& theURL,
158 QStringList& theFileList )
161 return save( theFileList );
164 bool HYDROGUI_DataModel::close()
169 bool HYDROGUI_DataModel::dumpPython( const QString& theURL,
172 QStringList& theListOfFiles )
174 LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
176 int aStudyId = theStudy->id();
178 LightApp_Study* aStudy = ::qobject_cast<LightApp_Study*>( theStudy );
179 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
180 if ( aDocument.IsNull() || !aStudy )
183 QString aFileToExport = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str();
184 aFileToExport += QString( QDir::separator() ) + "HYDRO.py";
186 bool aRes = aDocument->DumpToPython( aFileToExport );
190 theListOfFiles.append( aFileToExport );
196 bool HYDROGUI_DataModel::isModified() const
198 return getDocument()->IsModified();
201 bool HYDROGUI_DataModel::isSaved() const
206 void HYDROGUI_DataModel::update( const int theStudyId )
208 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
212 SUIT_DataObject* aStudyRoot = anApp->activeStudy()->root();
216 // create root object if not exist
217 CAM_DataObject* aRootObj = root();
219 aRootObj = createRootModuleObject( aStudyRoot );
224 DataObjectList aList;
225 aRootObj->children( aList );
226 QListIterator<SUIT_DataObject*> anIter( aList );
227 while( anIter.hasNext() )
228 removeChild( aRootObj, anIter.next() );
230 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theStudyId );
231 if( aDocument.IsNull() )
234 // Create root objects:
237 LightApp_DataObject* anImageRootObj = createObject( aRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
240 LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
242 // ARTIFICIAL OBJECTS
243 LightApp_DataObject* anArtificialObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
246 LightApp_DataObject* aNaturalObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
249 LightApp_DataObject* anObstaclesRootObj = createObject( aRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
252 LightApp_DataObject* aCalculRootObj = createObject( aRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
255 LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
258 LightApp_DataObject* aPolyline3DRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
261 LightApp_DataObject* aProfileRootObj = createObject( aRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
264 LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
266 HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN );
267 for( ; anIterator.More(); anIterator.Next() ) {
268 Handle(HYDROData_Entity) anObj = anIterator.Current();
270 if ( !anObj.IsNull() )
272 switch ( anObj->GetKind() ) {
275 Handle(HYDROData_Image) anImageObj =
276 Handle(HYDROData_Image)::DownCast( anObj );
277 if( !anImageObj.IsNull() ) {
278 createObject( anImageRootObj, anImageObj );
283 case KIND_BATHYMETRY:
285 Handle(HYDROData_Bathymetry) aBathymetryObj =
286 Handle(HYDROData_Bathymetry)::DownCast( anObj );
287 if( !aBathymetryObj.IsNull() ) {
288 createObject( aBathymetryRootObj, aBathymetryObj );
295 Handle(HYDROData_Channel) aChannelObj =
296 Handle(HYDROData_Channel)::DownCast( anObj );
297 if( !aChannelObj.IsNull() ) {
298 createObject( anArtificialObjectsRootObj, aChannelObj );
305 Handle(HYDROData_Digue) aDigueObj =
306 Handle(HYDROData_Digue)::DownCast( anObj );
307 if( !aDigueObj.IsNull() ) {
308 createObject( anArtificialObjectsRootObj, aDigueObj );
313 case KIND_IMMERSIBLE_ZONE:
315 Handle(HYDROData_ImmersibleZone) anImmersibleZoneObj =
316 Handle(HYDROData_ImmersibleZone)::DownCast( anObj );
317 if( !anImmersibleZoneObj.IsNull() ) {
318 createObject( aNaturalObjectsRootObj, anImmersibleZoneObj );
325 Handle(HYDROData_River) aRiverObj =
326 Handle(HYDROData_River)::DownCast( anObj );
327 if( !aRiverObj.IsNull() ) {
328 createObject( aNaturalObjectsRootObj, aRiverObj );
335 Handle(HYDROData_Stream) aStreamObj =
336 Handle(HYDROData_Stream)::DownCast( anObj );
337 if( !aStreamObj.IsNull() ) {
338 createObject( aNaturalObjectsRootObj, aStreamObj );
345 Handle(HYDROData_Obstacle) anObstacleObj =
346 Handle(HYDROData_Obstacle)::DownCast( anObj );
347 if( !anObstacleObj.IsNull() ) {
348 createObject( anObstaclesRootObj, anObstacleObj );
353 case KIND_CALCULATION:
355 Handle(HYDROData_CalculationCase) aCalculObj =
356 Handle(HYDROData_CalculationCase)::DownCast( anObj );
357 if( !aCalculObj.IsNull() ) {
358 createObject( aCalculRootObj, aCalculObj );
363 case KIND_POLYLINEXY:
365 Handle(HYDROData_PolylineXY) aPolylineObj =
366 Handle(HYDROData_PolylineXY)::DownCast( anObj );
367 if( !aPolylineObj.IsNull() ) {
368 createObject( aPolylineRootObj, aPolylineObj );
375 Handle(HYDROData_Polyline3D) aPolylineObj =
376 Handle(HYDROData_Polyline3D)::DownCast( anObj );
377 if( !aPolylineObj.IsNull() ) {
378 createObject( aPolyline3DRootObj, aPolylineObj );
385 Handle(HYDROData_Profile) aProfileObj =
386 Handle(HYDROData_Profile)::DownCast( anObj );
387 if( !aProfileObj.IsNull() ) {
388 createObject( aProfileRootObj, aProfileObj );
393 case KIND_VISUAL_STATE:
395 Handle(HYDROData_VisualState) aVisualStateObj =
396 Handle(HYDROData_VisualState)::DownCast( anObj );
397 if( !aVisualStateObj.IsNull() ) {
398 createObject( aVisualStateRootObj, aVisualStateObj );
407 if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
409 anObjectBrowser->setAutoOpenLevel( 3 );
410 anObjectBrowser->openLevels();
414 HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )
416 return NULL; // to do if necessary
419 HYDROGUI_DataObject* HYDROGUI_DataModel::getReferencedDataObject( HYDROGUI_DataObject* theObject )
421 return NULL; // to do if necessary
424 SUIT_DataObject* HYDROGUI_DataModel::findObject( const QString& theEntry ) const
426 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
427 return anApp ? anApp->findObject( theEntry ) : 0;
430 void HYDROGUI_DataModel::update( LightApp_DataObject* theObject,
431 LightApp_Study* theStudy )
434 theStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy()) ;
436 update( theStudy->id() );
439 CAM_DataObject* HYDROGUI_DataModel::createRootModuleObject( SUIT_DataObject* theParent )
441 CAM_ModuleObject* aRootObj = createModuleObject( theParent );
442 aRootObj->setDataModel( this );
447 void HYDROGUI_DataModel::updateModel()
449 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
451 update( aModule->getStudyId() );
454 Handle(HYDROData_Entity) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
455 const ObjectKind theObjectKind )
457 QString anEntry = theEntry;
458 if( anEntry.indexOf( "_" ) != -1 ) // reference object
459 anEntry = anEntry.section( "_", -1 );
461 Handle(HYDROData_Document) aDocument = getDocument();
462 if( !aDocument.IsNull() )
464 HYDROData_Iterator anIterator( aDocument, theObjectKind );
465 for( ; anIterator.More(); anIterator.Next() )
467 Handle(HYDROData_Entity) anObject = anIterator.Current();
468 if( !anObject.IsNull() )
470 QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
471 if( anEntryRef == anEntry )
479 bool HYDROGUI_DataModel::canUndo() const
481 return getDocument()->CanUndo();
484 bool HYDROGUI_DataModel::canRedo() const
486 return getDocument()->CanRedo();
489 QStringList HYDROGUI_DataModel::undoNames() const
492 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetUndos() ); anIter.More(); anIter.Next() )
493 aNames.prepend( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
497 QStringList HYDROGUI_DataModel::redoNames() const
500 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetRedos() ); anIter.More(); anIter.Next() )
501 aNames.append( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
505 void HYDROGUI_DataModel::clearUndos()
507 getDocument()->ClearUndos();
510 void HYDROGUI_DataModel::clearRedos()
512 getDocument()->ClearRedos();
515 bool HYDROGUI_DataModel::undo()
519 getDocument()->Undo();
521 catch ( Standard_Failure )
528 bool HYDROGUI_DataModel::redo()
532 getDocument()->Redo();
534 catch ( Standard_Failure )
541 bool HYDROGUI_DataModel::canCopy()
543 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
544 if( aSeq.Length() != 1 )
547 Handle(HYDROData_Entity) anObject = aSeq.First();
548 if( anObject.IsNull() )
551 ObjectKind aKind = anObject->GetKind();
552 if( aKind == KIND_IMAGE ||
553 aKind == KIND_POLYLINE ||
554 aKind == KIND_PROFILE ||
555 aKind == KIND_CALCULATION )
561 bool HYDROGUI_DataModel::canPaste()
563 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
565 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
566 if( !anObject.IsNull() && !anObject->IsRemoved() )
572 bool HYDROGUI_DataModel::copy()
574 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
575 changeCopyingObjects( aSeq );
579 bool HYDROGUI_DataModel::paste()
581 bool anIsChanged = false;
582 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
584 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
585 if( !anObject.IsNull() && !anObject->IsRemoved() )
587 ObjectKind aKind = anObject->GetKind();
588 Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind );
589 if( !aClone.IsNull() )
591 anObject->CopyTo( aClone );
594 // generate a new unique name for the clone object:
595 // case 1: Image_1 -> Image_2
596 // case 2: ImageObj -> ImageObj_1
597 QString aName = aClone->GetName();
598 QString aPrefix = aName;
599 if( aName.contains( '_' ) ) // case 1
601 QString aSuffix = aName.section( '_', -1 );
602 bool anIsInteger = false;
603 aSuffix.toInt( &anIsInteger );
605 aPrefix = aName.section( '_', 0, -2 );
609 aName = HYDROGUI_Tool::GenerateObjectName( (HYDROGUI_Module*)module(), aPrefix );
610 aClone->SetName( aName );
617 void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects& theSeq )
619 myCopyingObjects.Assign( theSeq );
622 QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind )
624 switch( theObjectKind )
626 case KIND_IMAGE: return "IMAGES";
627 case KIND_POLYLINE: return "POLYLINES_3D";
628 case KIND_POLYLINEXY: return "POLYLINES";
629 case KIND_PROFILE: return "PROFILES";
630 case KIND_VISUAL_STATE: return "VISUAL_STATES";
631 case KIND_BATHYMETRY: return "BATHYMETRIES";
632 case KIND_CALCULATION: return "CALCULATION_CASES";
633 case KIND_OBSTACLE: return "OBSTACLES";
634 case KIND_ARTIFICIAL_OBJECT: return "ARTIFICIAL_OBJECTS";
635 case KIND_NATURAL_OBJECT: return "NATURAL_OBJECTS";
641 Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
643 int aStudyId = module()->application()->activeStudy()->id();
644 return HYDROData_Document::Document( aStudyId );
647 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
648 Handle(HYDROData_Entity) theModelObject,
649 const QString& theParentEntry,
650 const bool theIsBuildTree )
652 HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
654 if ( theIsBuildTree )
656 buildObjectTree( theParent, aResObj, theParentEntry );
662 LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* theParent,
663 HYDROGUI_DataObject* theObject,
664 const QString& theParentEntry,
665 const bool theIsBuildTree )
667 if ( theIsBuildTree )
669 buildObjectTree( theParent, theObject, theParentEntry );
674 LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theParent,
675 Handle(HYDROData_Zone) theModelObject,
676 const QString& theParentEntry,
677 const bool theIsBuildTree )
679 return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
682 LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent,
683 Handle(HYDROData_Region) theModelObject,
684 const QString& theParentEntry,
685 const bool theIsBuildTree )
687 return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
690 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
691 const QString& theName,
692 const QString& theParentEntry )
694 return new HYDROGUI_NamedObject( theParent, theName, theParentEntry );
697 void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
698 SUIT_DataObject* theObject,
699 const QString& theParentEntry )
701 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
705 Handle(HYDROData_Entity) aDataObj = aGuiObj->modelObject();
706 if ( aDataObj.IsNull() )
709 ObjectKind anObjectKind = aDataObj->GetKind();
711 if ( anObjectKind == KIND_IMAGE )
713 Handle(HYDROData_Image) anImageObj =
714 Handle(HYDROData_Image)::DownCast( aDataObj );
715 for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
717 Handle(HYDROData_Entity) aRefObj = anImageObj->Reference( anIndex );
718 if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
719 createObject( aGuiObj, aRefObj, aGuiObj->entry(), false );
722 else if ( anObjectKind == KIND_IMMERSIBLE_ZONE )
724 Handle(HYDROData_ImmersibleZone) aZoneObj =
725 Handle(HYDROData_ImmersibleZone)::DownCast( aDataObj );
727 LightApp_DataObject* aPolylineSect =
728 createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() );
730 Handle(HYDROData_PolylineXY) aPolyline = aZoneObj->GetPolyline();
731 if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
732 createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
734 LightApp_DataObject* aBathSect =
735 createObject( aGuiObj, tr( "ZONE_BATHYMETRY" ), aGuiObj->entry() );
737 Handle(HYDROData_Bathymetry) aBathymetry = aZoneObj->GetBathymetry();
738 if ( !aBathymetry.IsNull() && !aBathymetry->IsRemoved() )
739 createObject( aBathSect, aBathymetry, aGuiObj->entry(), false );
741 else if ( anObjectKind == KIND_CALCULATION )
743 Handle(HYDROData_CalculationCase) aCaseObj =
744 Handle(HYDROData_CalculationCase)::DownCast( aDataObj );
746 LightApp_DataObject* aCaseRegionsSect =
747 createObject( aGuiObj, tr( "CASE_REGIONS" ), aGuiObj->entry() );
749 HYDROData_SequenceOfObjects aCaseRegions = aCaseObj->GetRegions();
750 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
751 for ( ; anIter.More(); anIter.Next() )
753 Handle(HYDROData_Region) aCaseRegion =
754 Handle(HYDROData_Region)::DownCast( anIter.Value() );
755 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
756 createRegion( aCaseRegionsSect, aCaseRegion, "", true );
759 else if ( anObjectKind == KIND_REGION )
761 Handle(HYDROData_Region) aRegionObj =
762 Handle(HYDROData_Region)::DownCast( aDataObj );
764 HYDROData_SequenceOfObjects aRegionZones = aRegionObj->GetZones();
765 HYDROData_SequenceOfObjects::Iterator anIter( aRegionZones );
766 for ( ; anIter.More(); anIter.Next() )
768 Handle(HYDROData_Zone) aRegionZone =
769 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
770 if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() )
771 createZone( aGuiObj, aRegionZone, "", true );
774 else if ( anObjectKind == KIND_PROFILE )
776 Handle(HYDROData_Profile) aProfileObj =
777 Handle(HYDROData_Profile)::DownCast( aDataObj );
779 aGuiObj->setIsValid( aProfileObj->IsValid() );
783 void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
785 if ( !theCase.IsNull() )
787 new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "" );
789 HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions();
790 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
791 for ( ; anIter.More(); anIter.Next() )
793 Handle(HYDROData_Region) aCaseRegion =
794 Handle(HYDROData_Region)::DownCast( anIter.Value() );
795 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
796 createRegion( theParent, aCaseRegion, "", true );
801 void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent,
802 SUIT_DataObject* theChild )
804 SUIT_DataObject* aSubChild = theChild->firstChild();
805 for( ; aSubChild; aSubChild = aSubChild->nextBrother() )
806 removeChild( theChild, aSubChild );
807 theParent->removeChild( theChild );
810 SUIT_DataObject* HYDROGUI_DataModel::findChildByName( const SUIT_DataObject* theFather,
811 const QString& theName )
813 SUIT_DataObject* aChild = theFather->firstChild();
816 if( aChild->name() == theName )
817 return aChild; // found
818 aChild = aChild->nextBrother();
820 return NULL; // not found
823 bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theCase,
824 const QList<HYDROGUI_Zone*>& theZonesList )
826 bool isOk = !theCase.IsNull();
829 Handle(HYDROData_Region) aRegion;
830 Handle(HYDROData_Zone) aZone;
831 for (int i = 0; i < theZonesList.length(); i++ )
833 aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() );
834 if ( !aZone.IsNull() )
836 if ( aRegion.IsNull() )
838 aRegion = theCase->AddNewRegion( aZone );
839 isOk = !aRegion.IsNull();
843 if ( !( aRegion->AddZone( aZone ) ) )
854 bool HYDROGUI_DataModel::rename( Handle(HYDROData_Entity) theEntity, const QString& theName )
856 if ( theName.isEmpty() )
861 getDocument()->StartOperation();
862 theEntity->SetName( theName );
863 getDocument()->CommitOperation( HYDROGUI_Tool::ToExtString( tr("RENAME_TO").arg( theName ) ) );
864 module()->application()->activeStudy()->Modified();
866 catch ( Standard_Failure )
868 getDocument()->AbortOperation();