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 // #define DEB_GROUPS 1
75 #include <HYDROData_ShapesGroup.h>
78 static HYDROData_SequenceOfObjects myCopyingObjects;
80 HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
81 : LightApp_DataModel( theModule )
83 update( module()->application()->activeStudy()->id() );
86 HYDROGUI_DataModel::~HYDROGUI_DataModel()
90 bool HYDROGUI_DataModel::open( const QString& theURL,
92 QStringList theFileList )
94 LightApp_DataModel::open( theURL, theStudy, theFileList );
95 const int aStudyId = theStudy->id();
97 Data_DocError res = DocError_UnknownProblem;
98 if( theFileList.count() == 2 )
100 QString aTmpDir = theFileList[0];
101 QString aFileName = theFileList[1];
104 QString aFullPath = SUIT_Tools::addSlash( aTmpDir ) + aFileName;
108 res = HYDROData_Document::Load( (char*)aFullPath.toLatin1().constData(), aStudyId );
112 res = DocError_UnknownProblem;
114 if( res != DocError_OK )
116 module()->application()->putInfo( tr( "LOAD_ERROR" ) );
121 // if the document open was successful, the data model update happens
122 // in the set mode of the module
123 if( res == DocError_OK )
129 bool HYDROGUI_DataModel::save( QStringList& theFileList )
131 if( !module()->application()->activeStudy() )
134 LightApp_DataModel::save( theFileList );
138 SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
139 bool isMultiFile = false;
141 isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
143 // save data to temporary files
144 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
145 aTmpDir = aStudy->GetTmpDir( myStudyURL.toLatin1().constData(), isMultiFile ).c_str();
146 aFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf";
148 QString aFullPath = aTmpDir + aFileName;
149 Data_DocError res = getDocument()->Save( (char*)aFullPath.toLatin1().constData() );
150 if( res != DocError_OK )
152 module()->application()->putInfo( tr( "SAVE_ERROR" ) );
156 theFileList.append( aTmpDir );
157 theFileList.append( aFileName );
162 bool HYDROGUI_DataModel::saveAs( const QString& theURL,
164 QStringList& theFileList )
167 return save( theFileList );
170 bool HYDROGUI_DataModel::close()
175 bool HYDROGUI_DataModel::dumpPython( const QString& theURL,
178 QStringList& theListOfFiles )
180 LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
182 int aStudyId = theStudy->id();
184 LightApp_Study* aStudy = ::qobject_cast<LightApp_Study*>( theStudy );
185 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
186 if ( aDocument.IsNull() || !aStudy )
189 QString aFileToExport = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str();
190 aFileToExport += QString( QDir::separator() ) + "HYDRO.py";
192 bool aRes = aDocument->DumpToPython( aFileToExport );
196 theListOfFiles.append( aFileToExport );
202 bool HYDROGUI_DataModel::isModified() const
204 return getDocument()->IsModified();
207 bool HYDROGUI_DataModel::isSaved() const
212 void HYDROGUI_DataModel::update( const int theStudyId )
214 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
218 SUIT_DataObject* aStudyRoot = anApp->activeStudy()->root();
222 // create root object if not exist
223 CAM_DataObject* aRootObj = root();
225 aRootObj = createRootModuleObject( aStudyRoot );
230 DataObjectList aList;
231 aRootObj->children( aList );
232 QListIterator<SUIT_DataObject*> anIter( aList );
233 while( anIter.hasNext() )
234 removeChild( aRootObj, anIter.next() );
236 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theStudyId );
237 if( aDocument.IsNull() )
240 // Create root objects:
243 LightApp_DataObject* anImageRootObj = createObject( aRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
246 LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
248 // ARTIFICIAL OBJECTS
249 LightApp_DataObject* anArtificialObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
252 LightApp_DataObject* aNaturalObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
255 LightApp_DataObject* anObstaclesRootObj = createObject( aRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
258 LightApp_DataObject* aCalculRootObj = createObject( aRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
261 LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
264 LightApp_DataObject* aPolyline3DRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
267 LightApp_DataObject* aProfileRootObj = createObject( aRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
270 LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
272 HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN );
273 for( ; anIterator.More(); anIterator.Next() ) {
274 Handle(HYDROData_Entity) anObj = anIterator.Current();
276 if ( !anObj.IsNull() )
278 switch ( anObj->GetKind() ) {
281 Handle(HYDROData_Image) anImageObj =
282 Handle(HYDROData_Image)::DownCast( anObj );
283 if( !anImageObj.IsNull() ) {
284 createObject( anImageRootObj, anImageObj );
289 case KIND_BATHYMETRY:
291 Handle(HYDROData_Bathymetry) aBathymetryObj =
292 Handle(HYDROData_Bathymetry)::DownCast( anObj );
293 if( !aBathymetryObj.IsNull() ) {
294 createObject( aBathymetryRootObj, aBathymetryObj );
301 Handle(HYDROData_Channel) aChannelObj =
302 Handle(HYDROData_Channel)::DownCast( anObj );
303 if( !aChannelObj.IsNull() ) {
304 createObject( anArtificialObjectsRootObj, aChannelObj );
311 Handle(HYDROData_Digue) aDigueObj =
312 Handle(HYDROData_Digue)::DownCast( anObj );
313 if( !aDigueObj.IsNull() ) {
314 createObject( anArtificialObjectsRootObj, aDigueObj );
319 case KIND_IMMERSIBLE_ZONE:
321 Handle(HYDROData_ImmersibleZone) anImmersibleZoneObj =
322 Handle(HYDROData_ImmersibleZone)::DownCast( anObj );
323 if( !anImmersibleZoneObj.IsNull() ) {
324 createObject( aNaturalObjectsRootObj, anImmersibleZoneObj );
331 Handle(HYDROData_River) aRiverObj =
332 Handle(HYDROData_River)::DownCast( anObj );
333 if( !aRiverObj.IsNull() ) {
334 createObject( aNaturalObjectsRootObj, aRiverObj );
341 Handle(HYDROData_Stream) aStreamObj =
342 Handle(HYDROData_Stream)::DownCast( anObj );
343 if( !aStreamObj.IsNull() ) {
344 createObject( aNaturalObjectsRootObj, aStreamObj );
351 Handle(HYDROData_Obstacle) anObstacleObj =
352 Handle(HYDROData_Obstacle)::DownCast( anObj );
353 if( !anObstacleObj.IsNull() ) {
354 createObject( anObstaclesRootObj, anObstacleObj );
359 case KIND_CALCULATION:
361 Handle(HYDROData_CalculationCase) aCalculObj =
362 Handle(HYDROData_CalculationCase)::DownCast( anObj );
363 if( !aCalculObj.IsNull() ) {
364 createObject( aCalculRootObj, aCalculObj );
369 case KIND_POLYLINEXY:
371 Handle(HYDROData_PolylineXY) aPolylineObj =
372 Handle(HYDROData_PolylineXY)::DownCast( anObj );
373 if( !aPolylineObj.IsNull() ) {
374 createObject( aPolylineRootObj, aPolylineObj );
381 Handle(HYDROData_Polyline3D) aPolylineObj =
382 Handle(HYDROData_Polyline3D)::DownCast( anObj );
383 if( !aPolylineObj.IsNull() ) {
384 createObject( aPolyline3DRootObj, aPolylineObj );
391 Handle(HYDROData_Profile) aProfileObj =
392 Handle(HYDROData_Profile)::DownCast( anObj );
393 if( !aProfileObj.IsNull() ) {
394 createObject( aProfileRootObj, aProfileObj );
399 case KIND_VISUAL_STATE:
401 Handle(HYDROData_VisualState) aVisualStateObj =
402 Handle(HYDROData_VisualState)::DownCast( anObj );
403 if( !aVisualStateObj.IsNull() ) {
404 createObject( aVisualStateRootObj, aVisualStateObj );
413 if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
415 anObjectBrowser->setAutoOpenLevel( 3 );
416 anObjectBrowser->openLevels();
420 HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )
422 return NULL; // to do if necessary
425 HYDROGUI_DataObject* HYDROGUI_DataModel::getReferencedDataObject( HYDROGUI_DataObject* theObject )
427 return NULL; // to do if necessary
430 SUIT_DataObject* HYDROGUI_DataModel::findObject( const QString& theEntry ) const
432 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
433 return anApp ? anApp->findObject( theEntry ) : 0;
436 void HYDROGUI_DataModel::update( LightApp_DataObject* theObject,
437 LightApp_Study* theStudy )
440 theStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy()) ;
442 update( theStudy->id() );
445 CAM_DataObject* HYDROGUI_DataModel::createRootModuleObject( SUIT_DataObject* theParent )
447 CAM_ModuleObject* aRootObj = createModuleObject( theParent );
448 aRootObj->setDataModel( this );
453 void HYDROGUI_DataModel::updateModel()
455 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
457 update( aModule->getStudyId() );
460 Handle(HYDROData_Entity) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
461 const ObjectKind theObjectKind )
463 QString anEntry = theEntry;
464 if( anEntry.indexOf( "_" ) != -1 ) // reference object
465 anEntry = anEntry.section( "_", -1 );
467 Handle(HYDROData_Document) aDocument = getDocument();
468 if( !aDocument.IsNull() )
470 HYDROData_Iterator anIterator( aDocument, theObjectKind );
471 for( ; anIterator.More(); anIterator.Next() )
473 Handle(HYDROData_Entity) anObject = anIterator.Current();
474 if( !anObject.IsNull() )
476 QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
477 if( anEntryRef == anEntry )
485 bool HYDROGUI_DataModel::canUndo() const
487 return getDocument()->CanUndo();
490 bool HYDROGUI_DataModel::canRedo() const
492 return getDocument()->CanRedo();
495 QStringList HYDROGUI_DataModel::undoNames() const
498 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetUndos() ); anIter.More(); anIter.Next() )
499 aNames.prepend( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
503 QStringList HYDROGUI_DataModel::redoNames() const
506 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetRedos() ); anIter.More(); anIter.Next() )
507 aNames.append( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
511 void HYDROGUI_DataModel::clearUndos()
513 getDocument()->ClearUndos();
516 void HYDROGUI_DataModel::clearRedos()
518 getDocument()->ClearRedos();
521 bool HYDROGUI_DataModel::undo()
525 getDocument()->Undo();
527 catch ( Standard_Failure )
534 bool HYDROGUI_DataModel::redo()
538 getDocument()->Redo();
540 catch ( Standard_Failure )
547 bool HYDROGUI_DataModel::canCopy()
549 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
550 bool isCanCopy = !aSeq.IsEmpty();
552 for ( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
553 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
554 if( !anObject.IsNull() ) {
555 ObjectKind aKind = anObject->GetKind();
556 bool isUnrecognized = aKind <= KIND_UNKNOWN || aKind > KIND_LAST;
557 bool isChildObject = aKind == KIND_DUMMY_3D ||
558 aKind == KIND_ZONE ||
559 aKind == KIND_SHAPES_GROUP ||
560 aKind == KIND_SPLITTED_GROUP;
561 if ( isUnrecognized || isChildObject ) {
571 bool HYDROGUI_DataModel::canPaste()
573 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
575 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
576 if( !anObject.IsNull() && !anObject->IsRemoved() )
582 bool HYDROGUI_DataModel::copy()
584 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
585 changeCopyingObjects( aSeq );
589 bool HYDROGUI_DataModel::paste()
591 bool anIsChanged = false;
592 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
594 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
595 if( !anObject.IsNull() && !anObject->IsRemoved() )
597 ObjectKind aKind = anObject->GetKind();
598 Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind );
599 if( !aClone.IsNull() )
601 anObject->CopyTo( aClone );
604 // generate a new unique name for the clone object:
605 // case 1: Image_1 -> Image_2
606 // case 2: ImageObj -> ImageObj_1
607 QString aName = aClone->GetName();
608 QString aPrefix = aName;
609 if( aName.contains( '_' ) ) // case 1
611 QString aSuffix = aName.section( '_', -1 );
612 bool anIsInteger = false;
613 aSuffix.toInt( &anIsInteger );
615 aPrefix = aName.section( '_', 0, -2 );
619 aName = HYDROGUI_Tool::GenerateObjectName( (HYDROGUI_Module*)module(), aPrefix );
620 aClone->SetName( aName );
627 void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects& theSeq )
629 myCopyingObjects.Assign( theSeq );
632 QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind )
634 switch( theObjectKind )
636 case KIND_IMAGE: return "IMAGES";
637 case KIND_POLYLINE: return "POLYLINES_3D";
638 case KIND_POLYLINEXY: return "POLYLINES";
639 case KIND_PROFILE: return "PROFILES";
640 case KIND_VISUAL_STATE: return "VISUAL_STATES";
641 case KIND_BATHYMETRY: return "BATHYMETRIES";
642 case KIND_CALCULATION: return "CALCULATION_CASES";
643 case KIND_OBSTACLE: return "OBSTACLES";
644 case KIND_ARTIFICIAL_OBJECT: return "ARTIFICIAL_OBJECTS";
645 case KIND_NATURAL_OBJECT: return "NATURAL_OBJECTS";
651 Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
653 int aStudyId = module()->application()->activeStudy()->id();
654 return HYDROData_Document::Document( aStudyId );
657 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
658 Handle(HYDROData_Entity) theModelObject,
659 const QString& theParentEntry,
660 const bool theIsBuildTree )
662 HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
664 if ( theIsBuildTree )
666 buildObjectTree( theParent, aResObj, theParentEntry );
672 LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* theParent,
673 HYDROGUI_DataObject* theObject,
674 const QString& theParentEntry,
675 const bool theIsBuildTree,
676 const bool theIsInOperation )
678 if ( theIsBuildTree )
680 buildObjectTree( theParent, theObject, theParentEntry, theIsInOperation );
685 LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theParent,
686 Handle(HYDROData_Zone) theModelObject,
687 const QString& theParentEntry,
688 const bool theIsBuildTree,
689 const bool theIsInOperation )
691 return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation ),
692 theParentEntry, theIsBuildTree, theIsInOperation );
695 LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent,
696 Handle(HYDROData_Region) theModelObject,
697 const QString& theParentEntry,
698 const bool theIsBuildTree,
699 const bool theIsInOperation )
701 return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry, theIsInOperation ),
702 theParentEntry, theIsBuildTree, theIsInOperation );
705 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
706 const QString& theName,
707 const QString& theParentEntry )
709 return new HYDROGUI_NamedObject( theParent, theName, theParentEntry );
712 void HYDROGUI_DataModel::buildObjectPartition( SUIT_DataObject* theObject,
713 const HYDROData_SequenceOfObjects& theObjects,
714 const QString& thePartName,
715 const bool theIsCreateEmpty )
717 if ( theObjects.IsEmpty() && !theIsCreateEmpty )
720 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
724 LightApp_DataObject* aPartSect =
725 createObject( aGuiObj, thePartName, aGuiObj->entry() );
727 HYDROData_SequenceOfObjects::Iterator anIter( theObjects );
728 for ( ; anIter.More(); anIter.Next() )
730 Handle(HYDROData_Entity) anObj = anIter.Value();
731 if( !anObj.IsNull() && !anObj->IsRemoved() )
732 createObject( aPartSect, anObj, aGuiObj->entry(), false );
736 void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
737 SUIT_DataObject* theObject,
738 const QString& theParentEntry,
739 const bool theIsInOperation )
741 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
745 Handle(HYDROData_Entity) aDataObj = aGuiObj->modelObject();
746 if ( aDataObj.IsNull() )
749 if ( aDataObj->IsKind( STANDARD_TYPE(HYDROData_Object) ) )
751 Handle(HYDROData_Object) aGeomObj =
752 Handle(HYDROData_Object)::DownCast( aDataObj );
754 Handle(HYDROData_DummyObject3D) anObject3D = aGeomObj->GetObject3D();
755 if ( !anObject3D.IsNull() )
756 createObject( aGuiObj, anObject3D, "", false );
759 HYDROData_SequenceOfObjects anObjGroups = aGeomObj->GetGroups();
760 buildObjectPartition( aGuiObj, anObjGroups, tr( "OBJECT_GROUPS" ), false );
764 ObjectKind anObjectKind = aDataObj->GetKind();
766 if ( anObjectKind == KIND_IMAGE )
768 Handle(HYDROData_Image) anImageObj =
769 Handle(HYDROData_Image)::DownCast( aDataObj );
770 for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
772 Handle(HYDROData_Entity) aRefObj = anImageObj->Reference( anIndex );
773 if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
774 createObject( aGuiObj, aRefObj, aGuiObj->entry(), false );
777 else if ( anObjectKind == KIND_IMMERSIBLE_ZONE )
779 Handle(HYDROData_ImmersibleZone) aZoneObj =
780 Handle(HYDROData_ImmersibleZone)::DownCast( aDataObj );
782 LightApp_DataObject* aPolylineSect =
783 createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() );
785 Handle(HYDROData_PolylineXY) aPolyline = aZoneObj->GetPolyline();
786 if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
787 createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
789 LightApp_DataObject* aBathSect =
790 createObject( aGuiObj, tr( "ZONE_BATHYMETRY" ), aGuiObj->entry() );
792 Handle(HYDROData_IAltitudeObject) anAltitudeObj = aZoneObj->GetAltitudeObject();
793 if ( !anAltitudeObj.IsNull() && !anAltitudeObj->IsRemoved() )
794 createObject( aBathSect, anAltitudeObj, aGuiObj->entry(), false );
796 else if ( anObjectKind == KIND_POLYLINE )
798 Handle(HYDROData_Polyline3D) aPolyline3D =
799 Handle(HYDROData_Polyline3D)::DownCast( aDataObj );
801 LightApp_DataObject* aPolylineSect =
802 createObject( aGuiObj, tr( "POLYLINE3D_POLYLINE" ), aGuiObj->entry() );
804 Handle(HYDROData_PolylineXY) aPolylineXY = aPolyline3D->GetPolylineXY();
805 if ( !aPolylineXY.IsNull() && !aPolylineXY->IsRemoved() )
806 createObject( aPolylineSect, aPolylineXY, aGuiObj->entry(), false );
808 LightApp_DataObject* aProfileSect =
809 createObject( aGuiObj, tr( "POLYLINE3D_PROFILE" ), aGuiObj->entry() );
811 Handle(HYDROData_ProfileUZ) aProfileUZ = aPolyline3D->GetProfileUZ();
812 if ( aProfileUZ.IsNull() || aProfileUZ->IsRemoved() )
813 aProfileUZ = aPolyline3D->GetChildProfileUZ( false );
815 if ( !aProfileUZ.IsNull() && !aProfileUZ->IsRemoved() )
817 Handle(HYDROData_Profile) aProfile =
818 Handle(HYDROData_Profile)::DownCast( aProfileUZ->GetFatherObject() );
819 if ( !aProfile.IsNull() && !aProfile->IsRemoved() )
820 createObject( aProfileSect, aProfile, aGuiObj->entry(), false );
823 LightApp_DataObject* aBathSect =
824 createObject( aGuiObj, tr( "POLYLINE3D_BATHYMETRY" ), aGuiObj->entry() );
826 Handle(HYDROData_IAltitudeObject) anAltitudeObj = aPolyline3D->GetAltitudeObject();
827 if ( !anAltitudeObj.IsNull() && !anAltitudeObj->IsRemoved() )
828 createObject( aBathSect, anAltitudeObj, aGuiObj->entry(), false );
830 else if ( anObjectKind == KIND_CALCULATION )
832 Handle(HYDROData_CalculationCase) aCaseObj =
833 Handle(HYDROData_CalculationCase)::DownCast( aDataObj );
835 LightApp_DataObject* aCaseAOSect =
836 createObject( aGuiObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ),
838 LightApp_DataObject* aCaseNOSect =
839 createObject( aGuiObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ),
842 HYDROData_SequenceOfObjects aSeq = aCaseObj->GetGeometryObjects();
843 HYDROData_SequenceOfObjects::Iterator aGOIter( aSeq );
844 Handle(HYDROData_Entity) anEntity;
845 Handle(HYDROData_ArtificialObject) anAObject;
846 Handle(HYDROData_NaturalObject) aNObject;
847 for ( ; aGOIter.More(); aGOIter.Next() )
849 anEntity = aGOIter.Value();
850 if ( anEntity.IsNull() )
852 anAObject = Handle(HYDROData_ArtificialObject)::DownCast( anEntity );
853 if ( !anAObject.IsNull() )
854 createObject( aCaseAOSect, anAObject, aGuiObj->entry(), false );
857 aNObject = Handle(HYDROData_NaturalObject)::DownCast( anEntity );
858 if ( !aNObject.IsNull() )
859 createObject( aCaseNOSect, aNObject, aGuiObj->entry(), false );
862 LightApp_DataObject* aCaseRegionsSect =
863 createObject( aGuiObj, tr( "CASE_REGIONS" ), aGuiObj->entry() );
865 HYDROData_SequenceOfObjects aCaseRegions = aCaseObj->GetRegions();
866 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
867 for ( ; anIter.More(); anIter.Next() )
869 Handle(HYDROData_Region) aCaseRegion =
870 Handle(HYDROData_Region)::DownCast( anIter.Value() );
871 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
872 createRegion( aCaseRegionsSect, aCaseRegion, "", true, theIsInOperation );
876 HYDROData_SequenceOfObjects aCalcGroups = aCaseObj->GetSplittedGroups();
877 buildObjectPartition( aGuiObj, aCalcGroups, tr( "OBJECT_GROUPS" ), false );
879 HYDROData_SequenceOfObjects aCalcSplitGroups = aCaseObj->GetSplittedGroups();
880 buildObjectPartition( aGuiObj, aCalcSplitGroups, tr( "CASE_SPLITTED_GROUPS" ), false );
884 else if ( anObjectKind == KIND_REGION )
886 Handle(HYDROData_Region) aRegionObj =
887 Handle(HYDROData_Region)::DownCast( aDataObj );
889 HYDROData_SequenceOfObjects aRegionZones = aRegionObj->GetZones();
890 HYDROData_SequenceOfObjects::Iterator anIter( aRegionZones );
891 for ( ; anIter.More(); anIter.Next() )
893 Handle(HYDROData_Zone) aRegionZone =
894 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
895 if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() )
896 createZone( aGuiObj, aRegionZone, "", true, theIsInOperation );
899 else if ( anObjectKind == KIND_PROFILE )
901 Handle(HYDROData_Profile) aProfileObj =
902 Handle(HYDROData_Profile)::DownCast( aDataObj );
904 aGuiObj->setIsValid( aProfileObj->IsValid() );
906 else if ( anObjectKind == KIND_CHANNEL || anObjectKind == KIND_DIGUE )
908 Handle(HYDROData_Channel) aChannelObj =
909 Handle(HYDROData_Channel)::DownCast( aDataObj );
911 LightApp_DataObject* aGuideLineSect =
912 createObject( aGuiObj, tr( "CHANNEL_GUIDE_LINE" ), aGuiObj->entry() );
913 Handle(HYDROData_Polyline3D) aGuideLine = aChannelObj->GetGuideLine();
914 if ( !aGuideLine.IsNull() && !aGuideLine->IsRemoved() ) {
915 createObject( aGuideLineSect, aGuideLine, aGuiObj->entry(), false );
918 LightApp_DataObject* aProfileSect =
919 createObject( aGuiObj, tr( "CHANNEL_PROFILE" ), aGuiObj->entry() );
920 Handle(HYDROData_Profile) aProfile = aChannelObj->GetProfile();
921 if ( !aProfile.IsNull() && !aProfile->IsRemoved() ) {
922 createObject( aProfileSect, aProfile, aGuiObj->entry(), false );
925 else if ( anObjectKind == KIND_STREAM )
927 Handle(HYDROData_Stream) aStreamObj =
928 Handle(HYDROData_Stream)::DownCast( aDataObj );
930 LightApp_DataObject* aHydraulicAxisSect =
931 createObject( aGuiObj, tr( "STREAM_HYDRAULIC_AXIS" ), aGuiObj->entry() );
932 Handle(HYDROData_PolylineXY) aHydraulicAxis = aStreamObj->GetHydraulicAxis();
933 if ( !aHydraulicAxis.IsNull() && !aHydraulicAxis->IsRemoved() ) {
934 createObject( aHydraulicAxisSect, aHydraulicAxis, aGuiObj->entry(), false );
937 HYDROData_SequenceOfObjects aProfiles = aStreamObj->GetProfiles();
938 buildObjectPartition( aGuiObj, aProfiles, tr( "STREAM_PROFILES" ), true );
942 void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
944 if ( !theCase.IsNull() )
948 // Remove previous objects tree
949 DataObjectList aList;
950 theParent->children( aList );
951 QListIterator<SUIT_DataObject*> anIter( aList );
952 while( anIter.hasNext() )
953 removeChild( theParent, anIter.next() );
956 new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "", true );
958 HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions();
959 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
960 for ( ; anIter.More(); anIter.Next() )
962 Handle(HYDROData_Region) aCaseRegion =
963 Handle(HYDROData_Region)::DownCast( anIter.Value() );
964 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
965 createRegion( theParent, aCaseRegion, "", true, true );
970 void HYDROGUI_DataModel::updateObjectTree( Handle(HYDROData_Entity)& theObj )
972 if ( !theObj.IsNull() )
974 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>(
975 findObject( HYDROGUI_DataObject::dataObjectEntry( theObj ) ) );
978 // Remove previous objects tree
979 DataObjectList aList;
980 aGuiObj->children( aList );
981 QListIterator<SUIT_DataObject*> anIter( aList );
982 while( anIter.hasNext() )
983 removeChild( aGuiObj, anIter.next() );
985 // Rebuild the subtree
986 QString aParentEntry;
987 HYDROGUI_DataObject* aParent = dynamic_cast<HYDROGUI_DataObject*>( aGuiObj->parent() );
990 aParentEntry = aParent->entry();
992 buildObjectTree( aParent, aGuiObj, aParentEntry, aGuiObj->isInOperation() );
996 // workaround for the bug in SalomeApp_Study::findObjectByEntry - it can't find LightApp_DataObjects
997 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
1000 aModule->getApp()->updateObjectBrowser();
1006 void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent,
1007 SUIT_DataObject* theChild )
1009 SUIT_DataObject* aSubChild = theChild->firstChild();
1010 for( ; aSubChild; aSubChild = aSubChild->nextBrother() )
1011 removeChild( theChild, aSubChild );
1012 theParent->removeChild( theChild );
1015 SUIT_DataObject* HYDROGUI_DataModel::findChildByName( const SUIT_DataObject* theFather,
1016 const QString& theName )
1018 SUIT_DataObject* aChild = theFather->firstChild();
1021 if( aChild->name() == theName )
1022 return aChild; // found
1023 aChild = aChild->nextBrother();
1025 return NULL; // not found
1028 bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theCase,
1029 const QList<HYDROGUI_Zone*>& theZonesList )
1031 bool isOk = !theCase.IsNull();
1034 Handle(HYDROData_Region) aRegion;
1035 Handle(HYDROData_Zone) aZone;
1036 for (int i = 0; i < theZonesList.length(); i++ )
1038 aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() );
1039 if ( !aZone.IsNull() )
1041 if ( aRegion.IsNull() )
1043 aRegion = theCase->AddNewRegion( aZone );
1044 isOk = !aRegion.IsNull();
1048 if ( !( aRegion->AddZone( aZone ) ) )
1059 bool HYDROGUI_DataModel::rename( Handle(HYDROData_Entity) theEntity, const QString& theName )
1061 if ( theName.isEmpty() )
1066 getDocument()->StartOperation();
1067 theEntity->SetName( theName );
1068 getDocument()->CommitOperation( HYDROGUI_Tool::ToExtString( tr("RENAME_TO").arg( theName ) ) );
1069 module()->application()->activeStudy()->Modified();
1071 catch ( Standard_Failure )
1073 getDocument()->AbortOperation();