1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_DataModel.h"
21 #include "HYDROGUI_DataObject.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_Tool.h"
24 #include "HYDROGUI_Tool2.h"
25 #include "HYDROGUI_Zone.h"
26 #include "HYDROGUI_Region.h"
28 #include <HYDROData_Bathymetry.h>
29 #include <HYDROData_CalculationCase.h>
30 #include <HYDROGUI_DataModelSync.h>
31 #include <HYDROData_Document.h>
32 #include <HYDROData_DummyObject3D.h>
33 #include <HYDROData_Image.h>
34 #include <HYDROData_ImmersibleZone.h>
35 #include <HYDROData_Iterator.h>
36 #include <HYDROData_Polyline3D.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>
46 #include <HYDROData_Stream.h>
47 #include <HYDROData_StricklerTable.h>
48 #include <HYDROData_LandCoverMap.h>
49 #include <HYDROData_BCPolygon.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_DataBrowser.h>
59 #include <SUIT_ResourceMgr.h>
60 #include <SUIT_Study.h>
61 #include <SUIT_Tools.h>
62 #include <SUIT_TreeSync.h>
63 #include <SUIT_DataObjectIterator.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 const int ENTRY_COLUMN = 2;
83 HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
84 : LightApp_DataModel( theModule )
86 update( module()->application()->activeStudy()->id() );
89 HYDROGUI_DataModel::~HYDROGUI_DataModel()
93 bool HYDROGUI_DataModel::create( CAM_Study* theStudy )
95 bool status = LightApp_DataModel::create( theStudy );
101 bool HYDROGUI_DataModel::open( const QString& theURL,
103 QStringList theFileList )
105 LightApp_DataModel::open( theURL, theStudy, theFileList );
106 const int aStudyId = theStudy->id();
108 Data_DocError res = DocError_UnknownProblem;
109 if( theFileList.count() >= 2 )
111 QString aTmpDir = theFileList[0];
112 QString aDataFileName = theFileList[1];
113 QString aStatesFileName = theFileList.count() == 3 ? theFileList[2] : "";
116 QString aDataFullPath = SUIT_Tools::addSlash( aTmpDir ) + aDataFileName;
117 QString aStatesFullPath = aStatesFileName.isEmpty() ? "" : SUIT_Tools::addSlash( aTmpDir ) + aStatesFileName;
121 res = HYDROData_Document::Load( (char*)aDataFullPath.toLatin1().constData(), aStudyId );
125 res = DocError_UnknownProblem;
128 if ( res != DocError_OK )
130 module()->application()->putInfo( tr( "LOAD_ERROR" ) );
134 if ( !aStatesFullPath.isEmpty() )
136 QFile aFile( aStatesFullPath );
137 if( aFile.open( QFile::ReadOnly ) )
139 myStates = aFile.readAll();
147 // if the document open was successful, the data model update happens
148 // in the set mode of the module
149 if ( res == DocError_OK )
155 bool HYDROGUI_DataModel::save( QStringList& theFileList )
157 if( !module()->application()->activeStudy() )
160 LightApp_DataModel::save( theFileList );
163 SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
164 bool isMultiFile = false;
166 isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
168 // save module data to temporary files
169 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
170 aTmpDir = aStudy->GetTmpDir( myStudyURL.toLatin1().constData(), isMultiFile ).c_str();
172 // save OCAF data to a temporary file
173 QString aDataFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf";
174 QString aDataFullPath = aTmpDir + aDataFileName;
175 Data_DocError res = getDocument()->Save( (char*)aDataFullPath.toLatin1().constData() );
176 if( res != DocError_OK )
178 module()->application()->putInfo( tr( "SAVE_ERROR" ) );
182 // save tree state data to a temporary file
183 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
184 QByteArray aStatesData = anApp->objectBrowser()->getOpenStates( ENTRY_COLUMN );
185 QString aStatesFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO_tree_states.txt";
186 QString aStatesFullPath = aTmpDir + aStatesFileName;
187 QFile aFile( aStatesFullPath );
188 if( aFile.open( QFile::WriteOnly ) )
190 aFile.write( aStatesData );
194 // add temporary files to the list
195 theFileList.append( aTmpDir );
196 theFileList.append( aDataFileName );
197 theFileList.append( aStatesFileName );
202 bool HYDROGUI_DataModel::saveAs( const QString& theURL,
204 QStringList& theFileList )
207 return save( theFileList );
210 bool HYDROGUI_DataModel::close()
212 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
214 aModule->clearCache();
218 bool HYDROGUI_DataModel::dumpPython( const QString& theURL,
221 QStringList& theListOfFiles )
223 LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
225 int aStudyId = theStudy->id();
227 LightApp_Study* aStudy = ::qobject_cast<LightApp_Study*>( theStudy );
228 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
229 if ( aDocument.IsNull() || !aStudy )
232 QString aDir = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str();
233 QString aFileToExport = aDir + QString( QDir::separator() ) + "HYDRO.py";
235 bool aRes = aDocument->DumpToPython( aFileToExport, isMultiFile );
238 theListOfFiles.append( aDir );
239 theListOfFiles.append( aFileToExport );
245 bool HYDROGUI_DataModel::isModified() const
247 return getDocument()->IsModified();
250 bool HYDROGUI_DataModel::isSaved() const
255 void HYDROGUI_DataModel::update( const int theStudyId )
257 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
261 SUIT_DataObject* aStudyRoot = anApp->activeStudy()->root();
265 // create a new root object
266 CAM_DataObject* aNewRootObj = new CAM_DataObject();
268 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theStudyId );
269 if( aDocument.IsNull() )
272 // Create root objects:
275 LightApp_DataObject* anImageRootObj = createObject( aNewRootObj, tr( partitionName( KIND_IMAGE ).toLatin1() ) );
278 LightApp_DataObject* aBathymetryRootObj = createObject( aNewRootObj, tr( partitionName( KIND_BATHYMETRY ).toLatin1() ) );
281 LightApp_DataObject* aPolylineRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINEXY ).toLatin1() ) );
284 LightApp_DataObject* aProfileRootObj = createObject( aNewRootObj, tr( partitionName( KIND_PROFILE ).toLatin1() ) );
287 LightApp_DataObject* aPolyline3DRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINE ).toLatin1() ) );
290 LightApp_DataObject* aNaturalObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toLatin1() ) );
292 // ARTIFICIAL OBJECTS
293 LightApp_DataObject* anArtificialObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toLatin1() ) );
296 LightApp_DataObject* anObstaclesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_OBSTACLE ).toLatin1() ) );
299 LightApp_DataObject* aBCPolygonRootObj = createObject( aNewRootObj, tr( partitionName( KIND_BC_POLYGON ).toLatin1() ) );
302 LightApp_DataObject* aStricklerTablesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_STRICKLER_TABLE ).toLatin1() ) );
305 LightApp_DataObject* aLandCoversRootObj = createObject( aNewRootObj, tr( partitionName( KIND_LAND_COVER_MAP ).toLatin1() ) );
308 LightApp_DataObject* aCalculRootObj = createObject( aNewRootObj, tr( partitionName( KIND_CALCULATION ).toLatin1() ) );
311 LightApp_DataObject* aVisualStateRootObj = createObject( aNewRootObj, tr( partitionName( KIND_VISUAL_STATE ).toLatin1() ) );
314 int aNoStricklerTableObj = 0;
316 HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN );
317 std::vector<Handle(HYDROData_Entity)> ents;
319 for( ; anIterator.More(); anIterator.Next() )
320 ents.push_back(anIterator.Current());
322 for (int i = 0; i< ents.size();i++)
324 LightApp_DataObject* obj = 0;
325 Handle(HYDROData_Entity) anObj = ents[i];
327 if ( !anObj.IsNull() )
329 switch ( anObj->GetKind() ) {
332 Handle(HYDROData_Image) anImageObj =
333 Handle(HYDROData_Image)::DownCast( anObj );
334 if( !anImageObj.IsNull() ) {
335 obj = createObject( anImageRootObj, anImageObj );
340 case KIND_BATHYMETRY:
342 Handle(HYDROData_Bathymetry) aBathymetryObj =
343 Handle(HYDROData_Bathymetry)::DownCast( anObj );
344 if( !aBathymetryObj.IsNull() ) {
345 obj = createObject( aBathymetryRootObj, aBathymetryObj );
352 Handle(HYDROData_Channel) aChannelObj =
353 Handle(HYDROData_Channel)::DownCast( anObj );
354 if( !aChannelObj.IsNull() ) {
355 obj = createObject( anArtificialObjectsRootObj, aChannelObj );
362 Handle(HYDROData_Digue) aDigueObj =
363 Handle(HYDROData_Digue)::DownCast( anObj );
364 if( !aDigueObj.IsNull() ) {
365 obj = createObject( anArtificialObjectsRootObj, aDigueObj );
370 case KIND_IMMERSIBLE_ZONE:
372 Handle(HYDROData_ImmersibleZone) anImmersibleZoneObj =
373 Handle(HYDROData_ImmersibleZone)::DownCast( anObj );
374 if( !anImmersibleZoneObj.IsNull() ) {
375 obj = createObject( aNaturalObjectsRootObj, anImmersibleZoneObj );
382 Handle(HYDROData_River) aRiverObj =
383 Handle(HYDROData_River)::DownCast( anObj );
384 if( !aRiverObj.IsNull() ) {
385 obj = createObject( aNaturalObjectsRootObj, aRiverObj );
392 Handle(HYDROData_Stream) aStreamObj =
393 Handle(HYDROData_Stream)::DownCast( anObj );
394 if( !aStreamObj.IsNull() ) {
395 obj = createObject( aNaturalObjectsRootObj, aStreamObj );
402 Handle(HYDROData_Obstacle) anObstacleObj =
403 Handle(HYDROData_Obstacle)::DownCast( anObj );
404 if( !anObstacleObj.IsNull() ) {
405 obj = createObject( anObstaclesRootObj, anObstacleObj );
410 case KIND_STRICKLER_TABLE:
412 Handle(HYDROData_StricklerTable) aStricklerTableObj =
413 Handle(HYDROData_StricklerTable)::DownCast( anObj );
414 if( !aStricklerTableObj.IsNull() ) {
415 obj = createObject( aStricklerTablesRootObj, aStricklerTableObj );
417 aNoStricklerTableObj++;
421 case KIND_LAND_COVER_MAP:
423 Handle(HYDROData_LandCoverMap) aLandCoverMapObj =
424 Handle(HYDROData_LandCoverMap)::DownCast( anObj );
425 if( !aLandCoverMapObj.IsNull() ) {
426 obj = createObject( aLandCoversRootObj, aLandCoverMapObj );
431 case KIND_CALCULATION:
433 Handle(HYDROData_CalculationCase) aCalculObj =
434 Handle(HYDROData_CalculationCase)::DownCast( anObj );
435 if( !aCalculObj.IsNull() ) {
436 obj = createObject( aCalculRootObj, aCalculObj );
441 case KIND_POLYLINEXY:
443 Handle(HYDROData_PolylineXY) aPolylineObj =
444 Handle(HYDROData_PolylineXY)::DownCast( anObj );
445 if( !aPolylineObj.IsNull() ) {
446 obj = createObject( aPolylineRootObj, aPolylineObj );
453 Handle(HYDROData_Polyline3D) aPolylineObj =
454 Handle(HYDROData_Polyline3D)::DownCast( anObj );
455 if( !aPolylineObj.IsNull() ) {
456 obj = createObject( aPolyline3DRootObj, aPolylineObj );
463 Handle(HYDROData_Profile) aProfileObj =
464 Handle(HYDROData_Profile)::DownCast( anObj );
465 if( !aProfileObj.IsNull() ) {
466 obj = createObject( aProfileRootObj, aProfileObj );
471 case KIND_VISUAL_STATE:
473 Handle(HYDROData_VisualState) aVisualStateObj =
474 Handle(HYDROData_VisualState)::DownCast( anObj );
475 if( !aVisualStateObj.IsNull() ) {
476 obj = createObject( aVisualStateRootObj, aVisualStateObj );
481 case KIND_BC_POLYGON:
483 Handle(HYDROData_BCPolygon) aBCPolygonObj =
484 Handle(HYDROData_BCPolygon)::DownCast( anObj );
485 if( !aBCPolygonObj.IsNull() ) {
486 obj = createObject( aBCPolygonRootObj, aBCPolygonObj );
495 // Create default Strickler table object
496 if ( aNoStricklerTableObj == 0 )
497 createDefaultStricklerTable( aDocument, aStricklerTablesRootObj );
499 //if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
501 // anObjectBrowser->setAutoOpenLevel( 3 );
502 // anObjectBrowser->openLevels();
505 SUIT_DataObject* aRoot = root();
509 std::map<std::string, SUIT_DataObject*> entry2ObjNewRoot;
510 SUIT_DataObjectIterator::DetourType dt = SUIT_DataObjectIterator::DepthLeft;
511 for ( SUIT_DataObjectIterator it( aNewRootObj, dt ); it.current(); ++it )
513 LightApp_DataObject* aCurObjN = dynamic_cast<LightApp_DataObject*>(it.current());
515 entry2ObjNewRoot[aCurObjN->entry().toStdString()] = it.current();
518 for ( SUIT_DataObjectIterator it( aRoot, dt ); it.current(); ++it )
520 LightApp_DataObject* aCurObjO = dynamic_cast<LightApp_DataObject*>(it.current());
521 if (aCurObjO && aCurObjO->childCount() > 0)
523 std::string entry = aCurObjO->entry().toStdString();
524 SUIT_DataObject* newNode = entry2ObjNewRoot[entry];
525 if (newNode && aCurObjO->childCount() > 0)
527 DataObjectList newchildren;
528 newNode->children(newchildren);
529 //new root - remove children
530 std::map<std::string, SUIT_DataObject*> newNode2Entries;
531 for ( DataObjectList::const_iterator it = newchildren.begin(); it != newchildren.end(); ++it )
533 SUIT_DataObject* cc = *it;
534 LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>(cc);
535 newNode2Entries[obj->entry().toStdString()] = cc;
536 newNode->removeChild(cc);
539 std::set<SUIT_DataObject*> objtemp;
541 DataObjectList oldchildren;
542 aCurObjO->children(oldchildren);
543 for ( DataObjectList::const_iterator it = oldchildren.begin(); it != oldchildren.end(); ++it )
545 SUIT_DataObject* old_ch = *it;
546 std::string entr = dynamic_cast<LightApp_DataObject*>(old_ch)->entry().toStdString();
547 if (newNode2Entries.count(entr) > 0)
549 SUIT_DataObject* obj = newNode2Entries[entr];
550 newNode->appendChild(obj);
555 for ( DataObjectList::const_iterator it = newchildren.begin(); it != newchildren.end(); ++it )
557 SUIT_DataObject* ch = *it;
558 if (objtemp.count(ch) == 0)
559 newNode->appendChild(ch);
563 DataObjectList newchildren2;
564 newNode->children(newchildren2);
565 std::set<std::string> entries2, entries1;
566 for ( DataObjectList::const_iterator it = newchildren2.begin(); it != newchildren2.end(); ++it )
567 entries2.insert((dynamic_cast<LightApp_DataObject*>(*it))->entry().toStdString());
568 for ( DataObjectList::const_iterator it = newchildren.begin(); it != newchildren.end(); ++it )
569 entries1.insert((dynamic_cast<LightApp_DataObject*>(*it))->entry().toStdString());
570 assert(entries1 == entries2);
577 HYDROGUI_DataModelSync aSync( aNewRootObj );
578 bool isNewDoc = aRoot==0;
580 aRoot = createRootModuleObject( aStudyRoot );
581 ::synchronize < suitPtr, suitPtr, HYDROGUI_DataModelSync >
582 ( aNewRootObj, aRoot, aSync );
584 SUIT_DataBrowser* ob = anApp->objectBrowser();
586 if ( !myStates.isEmpty() )
589 ob->setAutoOpenLevel( 1 );
590 //ob->setOpenStates( myStates, ENTRY_COLUMN );
595 HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )
597 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>(
598 findObject( HYDROGUI_DataObject::dataObjectEntry( theModelObject ) ) );
602 HYDROGUI_DataObject* HYDROGUI_DataModel::getReferencedDataObject( HYDROGUI_DataObject* theObject )
604 return NULL; // to do if necessary
607 SUIT_DataObject* HYDROGUI_DataModel::findObject( const QString& theEntry ) const
609 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
610 return anApp ? anApp->findObject( theEntry ) : 0;
613 void HYDROGUI_DataModel::update( LightApp_DataObject* theObject,
614 LightApp_Study* theStudy )
617 theStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy()) ;
619 update( theStudy->id() );
622 CAM_DataObject* HYDROGUI_DataModel::createRootModuleObject( SUIT_DataObject* theParent )
624 CAM_ModuleObject* aRootObj = createModuleObject( theParent );
625 aRootObj->setDataModel( this );
630 void HYDROGUI_DataModel::updateModel()
632 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
634 update( aModule->getStudyId() );
637 Handle(HYDROData_Entity) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
638 const ObjectKind theObjectKind )
640 QString anEntry = theEntry;
641 if( anEntry.indexOf( "_" ) != -1 ) // reference object
642 anEntry = anEntry.section( "_", -1 );
644 Handle(HYDROData_Document) aDocument = getDocument();
645 if( !aDocument.IsNull() )
647 HYDROData_Iterator anIterator( aDocument, theObjectKind );
648 for( ; anIterator.More(); anIterator.Next() )
650 Handle(HYDROData_Entity) anObject = anIterator.Current();
651 if( !anObject.IsNull() )
653 QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
654 if( anEntryRef == anEntry )
662 bool HYDROGUI_DataModel::canUndo() const
664 return getDocument()->CanUndo();
667 bool HYDROGUI_DataModel::canRedo() const
669 return getDocument()->CanRedo();
672 QStringList HYDROGUI_DataModel::undoNames() const
675 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetUndos() ); anIter.More(); anIter.Next() )
676 aNames.prepend( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
680 QStringList HYDROGUI_DataModel::redoNames() const
683 for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetRedos() ); anIter.More(); anIter.Next() )
684 aNames.append( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
688 void HYDROGUI_DataModel::clearUndos()
690 getDocument()->ClearUndos();
693 void HYDROGUI_DataModel::clearRedos()
695 getDocument()->ClearRedos();
698 bool HYDROGUI_DataModel::undo()
702 getDocument()->Undo();
704 catch ( Standard_Failure )
711 bool HYDROGUI_DataModel::redo()
715 getDocument()->Redo();
717 catch ( Standard_Failure )
724 bool HYDROGUI_DataModel::canCopy()
726 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
727 bool isCanCopy = !aSeq.IsEmpty();
729 for ( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
730 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
731 if( !anObject.IsNull() ) {
732 ObjectKind aKind = anObject->GetKind();
733 bool isUnrecognized = aKind <= KIND_UNKNOWN || aKind > KIND_LAST;
734 bool isChildObject = aKind == KIND_DUMMY_3D ||
735 aKind == KIND_ZONE ||
736 aKind == KIND_SHAPES_GROUP ||
737 aKind == KIND_SPLIT_GROUP;
738 if ( isUnrecognized || isChildObject ) {
748 bool HYDROGUI_DataModel::canPaste()
750 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
752 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
753 if( !anObject.IsNull() && !anObject->IsRemoved() )
759 bool HYDROGUI_DataModel::copy()
761 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
762 changeCopyingObjects( aSeq );
766 bool HYDROGUI_DataModel::paste()
768 bool anIsChanged = false;
769 for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
771 Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
772 if( !anObject.IsNull() && !anObject->IsRemoved() )
774 ObjectKind aKind = anObject->GetKind();
775 Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind );
776 if( !aClone.IsNull() )
778 anObject->CopyTo( aClone, true );
782 aClone->RemoveZLevel();
789 void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects& theSeq )
791 myCopyingObjects.Assign( theSeq );
794 QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind )
796 switch( theObjectKind )
798 case KIND_IMAGE: return "IMAGES";
799 case KIND_POLYLINE: return "POLYLINES_3D";
800 case KIND_POLYLINEXY: return "POLYLINES";
801 case KIND_PROFILE: return "PROFILES";
802 case KIND_VISUAL_STATE: return "VISUAL_STATES";
803 case KIND_BATHYMETRY: return "BATHYMETRIES";
804 case KIND_CALCULATION: return "CALCULATION_CASES";
805 case KIND_OBSTACLE: return "OBSTACLES";
806 case KIND_ARTIFICIAL_OBJECT: return "ARTIFICIAL_OBJECTS";
807 case KIND_NATURAL_OBJECT: return "NATURAL_OBJECTS";
808 case KIND_STRICKLER_TABLE: return "STRICKLER_TABLES";
809 case KIND_LAND_COVER_MAP: return "LAND_COVER_MAPS";
810 case KIND_REGION: return "REGIONS";
811 case KIND_BC_POLYGON: return "BOUNDARY_POLYGONS";
817 Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
819 int aStudyId = module()->application()->activeStudy()->id();
820 return HYDROData_Document::Document( aStudyId );
823 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
824 Handle(HYDROData_Entity) theModelObject,
825 const QString& theParentEntry,
826 const bool theIsBuildTree )
828 HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
830 const ObjectKind aKind = theModelObject->GetKind();
831 bool visibility = aKind == KIND_IMAGE || aKind == KIND_POLYLINEXY || aKind == KIND_POLYLINE ||
832 aKind == KIND_SHAPES_GROUP || aKind == KIND_SPLIT_GROUP || aKind == KIND_ZONE ||
833 aKind == KIND_IMMERSIBLE_ZONE || aKind == KIND_REGION || aKind == KIND_BATHYMETRY ||
834 aKind == KIND_OBSTACLE || aKind == KIND_STREAM || aKind == KIND_CHANNEL ||
835 aKind == KIND_DIGUE || aKind == KIND_DUMMY_3D || aKind == KIND_LAND_COVER_MAP ||
836 aKind == KIND_BC_POLYGON;
839 Handle(HYDROData_Profile) aProfObj = Handle(HYDROData_Profile)::DownCast( theModelObject );
840 visibility = !aProfObj.IsNull() && aProfObj->IsValid();
843 if ( aKind == KIND_REGION )
845 QString an = aResObj->name();
851 setObjectVisibilityState( theModelObject, aResObj );
854 if ( theIsBuildTree )
856 buildObjectTree( theParent, aResObj, theParentEntry );
862 LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* theParent,
863 HYDROGUI_DataObject* theObject,
864 const QString& theParentEntry,
865 const bool theIsBuildTree,
866 const bool theIsInOperation )
868 if ( theIsBuildTree )
870 buildObjectTree( theParent, theObject, theParentEntry, theIsInOperation );
875 LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theParent,
876 Handle(HYDROData_Zone) theModelObject,
877 const QString& theParentEntry,
878 const bool theIsBuildTree,
879 const bool theIsInOperation )
881 HYDROGUI_Zone* aZone = new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation );
882 LightApp_DataObject* aDataObj = buildObject( theParent, aZone, theParentEntry, theIsBuildTree, theIsInOperation );
884 setObjectVisibilityState( theModelObject, aZone );
889 LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent,
890 Handle(HYDROData_Region) theModelObject,
891 const QString& theParentEntry,
892 const bool theIsBuildTree,
893 const bool theIsInOperation )
895 return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry, theIsInOperation ),
896 theParentEntry, theIsBuildTree, theIsInOperation );
899 void HYDROGUI_DataModel::createDefaultStricklerTable( const Handle(HYDROData_Document)& theDocument,
900 LightApp_DataObject* theParent )
902 // Create default Strickler table object
903 Handle(HYDROData_StricklerTable) aStricklerTableObj =
904 Handle(HYDROData_StricklerTable)::DownCast( theDocument->CreateObject(KIND_STRICKLER_TABLE) );
905 if ( !aStricklerTableObj.IsNull() )
907 SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
908 QString defTablePath = resMgr->path( "resources", module()->name(), tr( "DEFAULT_STRICKLER_TABLE_FILE" ) );
909 aStricklerTableObj->Import( defTablePath );
911 QString aStricklerTableName;
912 if ( aStricklerTableObj->GetName().isEmpty() )
914 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
916 aStricklerTableName = HYDROGUI_Tool::GenerateObjectName( aModule, tr( "DEFAULT_STRICKLER_TABLE_NAME" ) );
918 if ( aStricklerTableObj->GetName() != aStricklerTableName )
919 aStricklerTableObj->SetName( aStricklerTableName );
921 aStricklerTableObj->Update();
923 LightApp_DataObject* obj = createObject( theParent, aStricklerTableObj );
927 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
928 const QString& theName,
929 const QString& theParentEntry )
931 return new HYDROGUI_NamedObject( theParent, theName, theParentEntry );
934 void HYDROGUI_DataModel::buildObjectPartition( SUIT_DataObject* theObject,
935 const HYDROData_SequenceOfObjects& theObjects,
936 const QString& thePartName,
937 const bool theIsCreateEmpty )
939 if ( theObjects.IsEmpty() && !theIsCreateEmpty )
942 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
946 LightApp_DataObject* aPartSect =
947 createObject( aGuiObj, thePartName, aGuiObj->entry() );
949 HYDROData_SequenceOfObjects::Iterator anIter( theObjects );
950 for ( ; anIter.More(); anIter.Next() )
952 Handle(HYDROData_Entity) anObj = anIter.Value();
953 if( !anObj.IsNull() && !anObj->IsRemoved() )
954 createObject( aPartSect, anObj, aGuiObj->entry(), false );
958 void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
959 SUIT_DataObject* theObject,
960 const QString& theParentEntry,
961 const bool theIsInOperation )
963 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
967 Handle(HYDROData_Entity) aDataObj = aGuiObj->modelObject();
968 if ( aDataObj.IsNull() )
971 if ( aDataObj->IsKind( STANDARD_TYPE(HYDROData_Object) ) )
973 Handle(HYDROData_Object) aGeomObj =
974 Handle(HYDROData_Object)::DownCast( aDataObj );
976 Handle(HYDROData_DummyObject3D) anObject3D = aGeomObj->GetObject3D();
977 if ( !anObject3D.IsNull() )
978 createObject( aGuiObj, anObject3D, "", false );
981 HYDROData_SequenceOfObjects anObjGroups = aGeomObj->GetGroups();
982 buildObjectPartition( aGuiObj, anObjGroups, tr( "OBJECT_GROUPS" ), false );
986 ObjectKind anObjectKind = aDataObj->GetKind();
988 if ( anObjectKind == KIND_IMAGE )
990 Handle(HYDROData_Image) anImageObj =
991 Handle(HYDROData_Image)::DownCast( aDataObj );
992 for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
994 Handle(HYDROData_Entity) aRefObj = anImageObj->Reference( anIndex );
995 if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
996 createObject( aGuiObj, aRefObj, aGuiObj->entry(), false );
999 else if ( anObjectKind == KIND_IMMERSIBLE_ZONE )
1001 Handle(HYDROData_ImmersibleZone) aZoneObj =
1002 Handle(HYDROData_ImmersibleZone)::DownCast( aDataObj );
1004 LightApp_DataObject* aPolylineSect =
1005 createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() );
1007 Handle(HYDROData_PolylineXY) aPolyline = aZoneObj->GetPolyline();
1008 if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
1009 createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
1011 LightApp_DataObject* aBathSect =
1012 createObject( aGuiObj, tr( "ZONE_BATHYMETRY" ), aGuiObj->entry() );
1014 Handle(HYDROData_IAltitudeObject) anAltitudeObj = aZoneObj->GetAltitudeObject();
1015 if ( !anAltitudeObj.IsNull() && !anAltitudeObj->IsRemoved() )
1016 createObject( aBathSect, anAltitudeObj, aGuiObj->entry(), false );
1018 else if ( anObjectKind == KIND_POLYLINE )
1020 Handle(HYDROData_Polyline3D) aPolyline3D =
1021 Handle(HYDROData_Polyline3D)::DownCast( aDataObj );
1023 LightApp_DataObject* aPolylineSect =
1024 createObject( aGuiObj, tr( "POLYLINE3D_POLYLINE" ), aGuiObj->entry() );
1026 Handle(HYDROData_PolylineXY) aPolylineXY = aPolyline3D->GetPolylineXY();
1027 if ( !aPolylineXY.IsNull() && !aPolylineXY->IsRemoved() )
1028 createObject( aPolylineSect, aPolylineXY, aGuiObj->entry(), false );
1030 LightApp_DataObject* aProfileSect =
1031 createObject( aGuiObj, tr( "POLYLINE3D_PROFILE" ), aGuiObj->entry() );
1033 Handle(HYDROData_ProfileUZ) aProfileUZ = aPolyline3D->GetProfileUZ();
1034 if ( aProfileUZ.IsNull() || aProfileUZ->IsRemoved() )
1035 aProfileUZ = aPolyline3D->GetChildProfileUZ( false );
1037 if ( !aProfileUZ.IsNull() && !aProfileUZ->IsRemoved() )
1039 Handle(HYDROData_Profile) aProfile =
1040 Handle(HYDROData_Profile)::DownCast( aProfileUZ->GetFatherObject() );
1041 if ( !aProfile.IsNull() && !aProfile->IsRemoved() )
1042 createObject( aProfileSect, aProfile, aGuiObj->entry(), false );
1045 LightApp_DataObject* aBathSect =
1046 createObject( aGuiObj, tr( "POLYLINE3D_BATHYMETRY" ), aGuiObj->entry() );
1048 Handle(HYDROData_IAltitudeObject) anAltitudeObj = aPolyline3D->GetAltitudeObject();
1049 if ( !anAltitudeObj.IsNull() && !anAltitudeObj->IsRemoved() )
1050 createObject( aBathSect, anAltitudeObj, aGuiObj->entry(), false );
1052 else if ( anObjectKind == KIND_CALCULATION )
1054 Handle(HYDROData_CalculationCase) aCaseObj =
1055 Handle(HYDROData_CalculationCase)::DownCast( aDataObj );
1057 LightApp_DataObject* aPolylineSect =
1058 createObject( aGuiObj, tr( "CASE_BOUNDARY" ), aGuiObj->entry() );
1060 Handle(HYDROData_PolylineXY) aPolyline = aCaseObj->GetBoundaryPolyline();
1061 if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
1062 createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
1064 LightApp_DataObject* aCaseAOSect =
1065 createObject( aGuiObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toLatin1() ),
1067 LightApp_DataObject* aCaseNOSect =
1068 createObject( aGuiObj, tr( partitionName( KIND_NATURAL_OBJECT ).toLatin1() ),
1071 HYDROData_SequenceOfObjects aSeq = aCaseObj->GetGeometryObjects();
1072 HYDROData_SequenceOfObjects::Iterator aGOIter( aSeq );
1073 Handle(HYDROData_Entity) anEntity;
1074 Handle(HYDROData_ArtificialObject) anAObject;
1075 Handle(HYDROData_NaturalObject) aNObject;
1076 for ( ; aGOIter.More(); aGOIter.Next() )
1078 anEntity = aGOIter.Value();
1079 if ( anEntity.IsNull() )
1081 anAObject = Handle(HYDROData_ArtificialObject)::DownCast( anEntity );
1082 if ( !anAObject.IsNull() )
1083 createObject( aCaseAOSect, anAObject, aGuiObj->entry(), false );
1086 aNObject = Handle(HYDROData_NaturalObject)::DownCast( anEntity );
1087 if ( !aNObject.IsNull() )
1088 createObject( aCaseNOSect, aNObject, aGuiObj->entry(), false );
1092 LightApp_DataObject* aBoundaryPolygonSect =
1093 createObject( aGuiObj, tr( "CASE_BOUNDARY_POLYGONS" ), aGuiObj->entry() );
1094 HYDROData_SequenceOfObjects aBCPolygons = aCaseObj->GetBoundaryPolygons();
1095 for (int i = 1; i <= aBCPolygons.Size(); i++ )
1096 createObject( aBoundaryPolygonSect, aBCPolygons(i), aGuiObj->entry(), false );
1098 LightApp_DataObject* aLandCoverMapSect =
1099 createObject( aGuiObj, tr( "CASE_LAND_COVER_MAP" ), aGuiObj->entry() );
1101 Handle(HYDROData_LandCoverMap) aLandCoverMap = aCaseObj->GetLandCoverMap();
1102 if ( !aLandCoverMap.IsNull() && !aLandCoverMap->IsRemoved() )
1103 createObject( aLandCoverMapSect, aLandCoverMap, aGuiObj->entry(), false );
1105 LightApp_DataObject* aCaseRegionsSect =
1106 createObject( aGuiObj, tr( "CASE_REGIONS" ), aGuiObj->entry() );
1108 HYDROData_SequenceOfObjects aCaseRegions = aCaseObj->GetRegions();
1109 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
1110 for ( ; anIter.More(); anIter.Next() )
1112 Handle(HYDROData_Region) aCaseRegion =
1113 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1114 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
1115 createRegion( aCaseRegionsSect, aCaseRegion, "", true, theIsInOperation );
1119 HYDROData_SequenceOfObjects aCalcGroups = aCaseObj->GetGeometryGroups();
1120 buildObjectPartition( aGuiObj, aCalcGroups, tr( "OBJECT_GROUPS" ), false );
1122 HYDROData_SequenceOfObjects aCalcSplitGroups = aCaseObj->GetSplitGroups();
1123 buildObjectPartition( aGuiObj, aCalcSplitGroups, tr( "CASE_SPLIT_GROUPS" ), false );
1127 else if ( anObjectKind == KIND_REGION )
1129 Handle(HYDROData_Region) aRegionObj =
1130 Handle(HYDROData_Region)::DownCast( aDataObj );
1132 HYDROData_SequenceOfObjects aRegionZones = aRegionObj->GetZones();
1133 HYDROData_SequenceOfObjects::Iterator anIter( aRegionZones );
1134 for ( ; anIter.More(); anIter.Next() )
1136 Handle(HYDROData_Zone) aRegionZone =
1137 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1138 if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() )
1139 createZone( aGuiObj, aRegionZone, "", true, theIsInOperation );
1142 else if ( anObjectKind == KIND_PROFILE )
1144 Handle(HYDROData_Profile) aProfileObj =
1145 Handle(HYDROData_Profile)::DownCast( aDataObj );
1147 aGuiObj->setIsValid( aProfileObj->IsValid() );
1149 else if ( anObjectKind == KIND_CHANNEL || anObjectKind == KIND_DIGUE )
1151 Handle(HYDROData_Channel) aChannelObj =
1152 Handle(HYDROData_Channel)::DownCast( aDataObj );
1154 LightApp_DataObject* aGuideLineSect =
1155 createObject( aGuiObj, tr( "CHANNEL_GUIDE_LINE" ), aGuiObj->entry() );
1156 Handle(HYDROData_Polyline3D) aGuideLine = aChannelObj->GetGuideLine();
1157 if ( !aGuideLine.IsNull() && !aGuideLine->IsRemoved() ) {
1158 createObject( aGuideLineSect, aGuideLine, aGuiObj->entry(), false );
1161 LightApp_DataObject* aProfileSect =
1162 createObject( aGuiObj, tr( "CHANNEL_PROFILE" ), aGuiObj->entry() );
1163 Handle(HYDROData_Profile) aProfile = aChannelObj->GetProfile();
1164 if ( !aProfile.IsNull() && !aProfile->IsRemoved() ) {
1165 createObject( aProfileSect, aProfile, aGuiObj->entry(), false );
1168 else if ( anObjectKind == KIND_STREAM )
1170 Handle(HYDROData_Stream) aStreamObj =
1171 Handle(HYDROData_Stream)::DownCast( aDataObj );
1173 LightApp_DataObject* aHydraulicAxisSect =
1174 createObject( aGuiObj, tr( "STREAM_HYDRAULIC_AXIS" ), aGuiObj->entry() );
1175 Handle(HYDROData_PolylineXY) aHydraulicAxis = aStreamObj->GetHydraulicAxis();
1176 if ( !aHydraulicAxis.IsNull() && !aHydraulicAxis->IsRemoved() ) {
1177 createObject( aHydraulicAxisSect, aHydraulicAxis, aGuiObj->entry(), false );
1180 HYDROData_SequenceOfObjects aProfiles = aStreamObj->GetProfiles();
1181 buildObjectPartition( aGuiObj, aProfiles, tr( "STREAM_PROFILES" ), true );
1183 Handle(HYDROData_Polyline3D) aBottomPolyline = aStreamObj->GetBottomPolyline();
1184 if ( !aBottomPolyline.IsNull() && !aBottomPolyline->IsRemoved() ) {
1185 createObject( aGuiObj, aBottomPolyline, aGuiObj->entry(), false );
1188 else if ( anObjectKind == KIND_LAND_COVER_MAP )
1190 Handle(HYDROData_LandCoverMap) aLandCoverMapObj =
1191 Handle(HYDROData_LandCoverMap)::DownCast( aDataObj );
1193 /*TODO: reference objects of the land cover map
1194 HYDROData_SequenceOfObjects aPolylines = aLandCoverMapObj->GetPolylines();
1195 buildObjectPartition( aGuiObj, aPolylines, tr( "LAND_COVER_POLYLINES" ), true );*/
1197 else if ( anObjectKind == KIND_BC_POLYGON )
1199 Handle(HYDROData_BCPolygon) aBCObj =
1200 Handle(HYDROData_BCPolygon)::DownCast( aDataObj );
1202 LightApp_DataObject* aPolylineSect =
1203 createObject( aGuiObj, tr( "BC_POLYGON_POLYLINE" ), aGuiObj->entry() );
1205 Handle(HYDROData_PolylineXY) aPolyline = aBCObj->GetPolyline();
1206 if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
1207 createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
1209 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
1211 aModule->enableLCMActions();
1215 void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
1217 if ( !theCase.IsNull() )
1221 // Remove previous objects tree
1222 DataObjectList aList;
1223 theParent->children( aList );
1224 QListIterator<SUIT_DataObject*> anIter( aList );
1225 while( anIter.hasNext() )
1226 removeChild( theParent, anIter.next() );
1229 new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "", true );
1231 HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions();
1232 HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
1233 for ( ; anIter.More(); anIter.Next() )
1235 Handle(HYDROData_Region) aCaseRegion =
1236 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1237 if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
1238 createRegion( theParent, aCaseRegion, "", true, true );
1243 void HYDROGUI_DataModel::updateObjectTree( Handle(HYDROData_Entity)& theObj )
1245 if ( !theObj.IsNull() )
1247 HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>(
1248 findObject( HYDROGUI_DataObject::dataObjectEntry( theObj ) ) );
1251 // Remove previous objects tree
1252 DataObjectList aList;
1253 aGuiObj->children( aList );
1254 QListIterator<SUIT_DataObject*> anIter( aList );
1255 while( anIter.hasNext() )
1256 removeChild( aGuiObj, anIter.next() );
1258 // Rebuild the subtree
1259 QString aParentEntry;
1260 HYDROGUI_DataObject* aParent = dynamic_cast<HYDROGUI_DataObject*>( aGuiObj->parent() );
1263 aParentEntry = aParent->entry();
1265 buildObjectTree( aParent, aGuiObj, aParentEntry, aGuiObj->isInOperation() );
1269 // workaround for the bug in SalomeApp_Study::findObjectByEntry - it can't find LightApp_DataObjects
1270 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
1273 aModule->getApp()->updateObjectBrowser();
1279 void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent,
1280 SUIT_DataObject* theChild )
1282 SUIT_DataObject* aSubChild = theChild->firstChild();
1283 for( ; aSubChild; aSubChild = aSubChild->nextBrother() )
1284 removeChild( theChild, aSubChild );
1285 theParent->removeChild( theChild );
1288 SUIT_DataObject* HYDROGUI_DataModel::findChildByName( const SUIT_DataObject* theFather,
1289 const QString& theName )
1291 SUIT_DataObject* aChild = theFather->firstChild();
1294 if( aChild->name() == theName )
1295 return aChild; // found
1296 aChild = aChild->nextBrother();
1298 return NULL; // not found
1301 bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theCase,
1302 const QList<HYDROGUI_Zone*>& theZonesList )
1304 bool isOk = !theCase.IsNull();
1307 Handle(HYDROData_Region) aRegion;
1308 Handle(HYDROData_Zone) aZone;
1309 for (int i = 0; i < theZonesList.length(); i++ )
1311 aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() );
1312 if ( !aZone.IsNull() )
1314 if ( aRegion.IsNull() )
1316 aRegion = theCase->AddNewRegion( aZone );
1317 isOk = !aRegion.IsNull();
1321 if ( !( aRegion->AddZone( aZone ) ) )
1332 bool HYDROGUI_DataModel::rename( Handle(HYDROData_Entity) theEntity, const QString& theName )
1334 if ( theName.isEmpty() )
1339 getDocument()->StartOperation();
1340 theEntity->SetName( theName );
1341 getDocument()->CommitOperation( HYDROGUI_Tool::ToExtString( tr("RENAME_TO").arg( theName ) ) );
1342 module()->application()->activeStudy()->Modified();
1344 catch ( Standard_Failure )
1346 getDocument()->AbortOperation();
1352 void HYDROGUI_DataModel::updateDocument()
1354 // Sets the default strickler coefficient from preferences to document.
1355 Handle(HYDROData_Document) aDoc = getDocument();
1356 SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
1357 if ( resMgr && !aDoc.IsNull() )
1358 aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( "preferences", "default_strickler_coefficient", 0 ) );
1361 void HYDROGUI_DataModel::setObjectVisibilityState( Handle(HYDROData_Entity) theModelObject,
1362 HYDROGUI_DataObject* theObject )
1364 SUIT_AbstractModel* treeModel = 0;
1365 LightApp_Application* app = dynamic_cast<LightApp_Application*>( module()->application() );
1367 treeModel = dynamic_cast<SUIT_AbstractModel*>( app->objectBrowser()->model() );
1371 HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
1372 bool isVisible = aModule->isObjectVisible( -1, theModelObject );
1373 Qtx::VisibilityState aVisState = isVisible ? Qtx::ShownState : Qtx::HiddenState;
1374 treeModel->setVisibilityState( theObject->text( theObject->customData( Qtx::IdType ).toInt() ), aVisState, false );