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 <HYDROData_Document.h>
20 #include <HYDROData_Application.h>
21 #include <HYDROData_Iterator.h>
22 #include <HYDROData_Tool.h>
23 #include <HYDROData_InterpolatorsFactory.h>
24 #include <HYDROData_StricklerTable.h>
25 #include <HYDROData_LandCoverMap.h>
27 #include <TDataStd_Real.hxx>
28 #include <TDataStd_Integer.hxx>
29 #include <TDataXtd_Position.hxx>
31 #include <TDF_Delta.hxx>
36 #include <QStringList>
37 #include <QTextStream>
40 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Document,MMgt_TShared)
42 #define PYTHON_DOC_NAME "hydro_doc"
44 static const int UNDO_LIMIT = 10; // number of possible undo operations in the module
46 static const int TAG_PROPS = 1; // general properties tag
47 static const int TAG_PROPS_NEW_ID = 1; // general properties: tag for storage of the new object ID
48 static const int TAG_OBJECTS = 2; // tag of the objects sub-tree
49 static const int TAG_HISTORY = 3; // tag of the history sub-tree (Root for History)
50 static const int TAG_LOCAL_CS = 4; // tag of local coordinate system information
51 static const int TAG_DEF_STRICKLER_COEFF = 5; // tag of default strickler coefficient
52 static const int TAG_COUNT_QUADTREE = 6; // tag of number of quadtrees created so far
53 static const int TAG_COUNT_DELAUNAY = 7; // tag of number of Delaunay triangulations created so far
54 static const gp_Pnt2d DEFAULT_LOCAL_CS( 0, 0 );
58 typedef QMap<Standard_Integer, Handle(HYDROData_Entity)> MapOfOrdered;
59 typedef QMap<QString, Handle(HYDROData_Entity)> MapOfUnordered;
61 Handle(HYDROData_Document) HYDROData_Document::Document(const int theStudyID)
63 Handle(HYDROData_Document) aResult =
64 HYDROData_Application::GetApplication()->GetDocument(theStudyID);
65 if (aResult.IsNull()) {
66 aResult = new HYDROData_Document();
67 HYDROData_Application::GetApplication()->AddDocument(theStudyID, aResult);
72 Handle(HYDROData_Document) HYDROData_Document::Document(
73 const TDF_Label& theObjectLabel )
75 Handle(HYDROData_Document) aResDoc;
76 if ( theObjectLabel.IsNull() )
79 Handle(TDocStd_Document) anObjDoc;
82 anObjDoc = TDocStd_Document::Get( theObjectLabel );
88 if ( anObjDoc.IsNull() )
91 HYDROData_Application* anApp = HYDROData_Application::GetApplication();
93 DataMapOfStudyIDDocument::Iterator aMapIt( anApp->myDocuments );
94 for ( ; aMapIt.More(); aMapIt.Next() )
96 Handle(HYDROData_Document) anAppDoc = aMapIt.Value();
97 if ( anAppDoc.IsNull() || anAppDoc->myDoc != anObjDoc )
107 bool HYDROData_Document::HasDocument(const int theStudyID)
109 Handle(HYDROData_Document) aResult =
110 HYDROData_Application::GetApplication()->GetDocument(theStudyID);
111 return !aResult.IsNull();
114 bool HYDROData_Document::DocumentId(const Handle(HYDROData_Document)& theDocument,
117 return HYDROData_Application::GetApplication()->GetDocumentId(theDocument, theDocId);
120 Data_DocError HYDROData_Document::Load(const char* theFileName, const int theStudyID)
122 Handle(TDocStd_Document) aResult;
123 TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
124 PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1;
127 aStatus = HYDROData_Application::GetApplication()->Open (aPath, aResult);
129 catch (Standard_Failure)
131 if (!aResult.IsNull()) {
132 aResult->SetUndoLimit(UNDO_LIMIT);
133 HYDROData_Application::GetApplication()->AddDocument(theStudyID, new HYDROData_Document(aResult));
136 Data_DocError anError;
139 anError = DocError_OK;
141 case PCDM_RS_NoDriver:
142 case PCDM_RS_UnknownFileDriver:
143 case PCDM_RS_NoSchema:
144 case PCDM_RS_DriverFailure:
145 case PCDM_RS_WrongResource:
146 anError = DocError_ResourcesProblem;
148 case PCDM_RS_OpenError:
149 case PCDM_RS_NoDocument:
150 case PCDM_RS_WrongStreamMode:
151 case PCDM_RS_PermissionDenied:
152 anError = DocError_CanNotOpen;
154 case PCDM_RS_NoVersion:
155 anError = DocError_InvalidVersion;
157 case PCDM_RS_ExtensionFailure:
158 case PCDM_RS_FormatFailure:
159 case PCDM_RS_TypeFailure:
160 case PCDM_RS_TypeNotFoundInSchema:
161 case PCDM_RS_UnrecognizedFileFormat:
162 anError = DocError_InvalidFormat;
164 case PCDM_RS_MakeFailure:
166 anError = DocError_UnknownProblem;
172 Data_DocError HYDROData_Document::Save(const char* theFileName)
174 TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
175 PCDM_StoreStatus aStatus;
177 aStatus = HYDROData_Application::GetApplication()->SaveAs (myDoc, aPath);
179 catch (Standard_Failure) {}
180 myTransactionsAfterSave = 0;
181 Standard::Purge(); // Release free memory
184 Data_DocError anError;
187 anError = DocError_OK;
189 case PCDM_SS_DriverFailure:
190 anError = DocError_ResourcesProblem;
192 case PCDM_SS_WriteFailure:
193 //case PCDM_SS_DiskWritingFailure:
194 //case PCDM_SS_UserRightsFailure:
195 anError = DocError_CanNotOpen;
198 anError = DocError_UnknownProblem;
204 void HYDROData_Document::Close()
207 HYDROData_Application::GetApplication()->RemoveDocument(this);
210 double HYDROData_Document::GetDefaultStricklerCoefficient() const
213 TDF_Label aLabel = myDoc->Main().FindChild(TAG_DEF_STRICKLER_COEFF, Standard_False);
214 if ( !aLabel.IsNull() )
216 Handle(TDataStd_Real) anAttr;
217 if ( aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
218 aRes = anAttr->Get();
224 void HYDROData_Document::SetDefaultStricklerCoefficient( double theCoeff ) const
226 TDF_Label aLabel = myDoc->Main().FindChild(TAG_DEF_STRICKLER_COEFF);
227 if ( !aLabel.IsNull() )
229 Handle(TDataStd_Real) anAttr;
230 if ( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
231 aLabel.AddAttribute( anAttr = new TDataStd_Real() );
232 anAttr->Set( theCoeff );
236 int HYDROData_Document::GetCountQuadtree() const
239 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_QUADTREE, Standard_False);
240 if ( !aLabel.IsNull() )
242 Handle(TDataStd_Integer) anAttr;
243 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
244 nbQuad = anAttr->Get();
249 void HYDROData_Document::SetCountQuadtree( int nbQuad) const
251 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_QUADTREE);
252 if ( !aLabel.IsNull() )
254 Handle(TDataStd_Integer) anAttr;
255 if ( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
256 aLabel.AddAttribute( anAttr = new TDataStd_Integer() );
257 anAttr->Set( nbQuad );
261 int HYDROData_Document::GetCountDelaunay() const
264 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_DELAUNAY, Standard_False);
265 if ( !aLabel.IsNull() )
267 Handle(TDataStd_Integer) anAttr;
268 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
269 nbDelaunay = anAttr->Get();
274 void HYDROData_Document::SetCountDelaunay( int nbDelaunay) const
276 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_DELAUNAY);
277 if ( !aLabel.IsNull() )
279 Handle(TDataStd_Integer) anAttr;
280 if ( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
281 aLabel.AddAttribute( anAttr = new TDataStd_Integer() );
282 anAttr->Set( nbDelaunay );
286 bool HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
287 const bool theIsMultiFile ) const
289 // Try to open the file
290 QFile aFile( thePyScriptPath );
291 if ( !aFile.open( QIODevice::WriteOnly | QFile::Text ) )
294 MapOfTreatedObjects aTreatedObjects;
296 // Dump header for python script
297 QStringList aHeaderDump = DumpToPython( thePyScriptPath, aTreatedObjects, theIsMultiFile );
298 if ( aHeaderDump.isEmpty() )
301 HYDROData_Tool::WriteStringsToFile( aFile, aHeaderDump );
305 // Dump the local CS data to Python
307 QString aLCS = QString( "%1.SetLocalCS( %2, %3 )" ).arg( GetDocPyName() ).arg( myLX, 0, 'f', 3 ).arg( myLY, 0, 'f', 3 );
310 HYDROData_Tool::WriteStringsToFile( aFile, QStringList() << aLCS );
312 // Dump all model objects to Python script
313 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMAGE );
314 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STRICKLER_TABLE );
315 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINEXY );
316 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_BATHYMETRY );
317 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_PROFILE );
318 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINE );
319 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMMERSIBLE_ZONE );
320 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STREAM );
321 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CHANNEL );
322 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_DIGUE );
323 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_OBSTACLE );
324 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_LAND_COVER_MAP );
325 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CALCULATION );
327 // Dump code to close python fuction
328 if ( aRes && theIsMultiFile )
330 QStringList aFooterScript;
331 aFooterScript << QString( "" );
332 aFooterScript << QString( " pass" );
333 HYDROData_Tool::WriteStringsToFile( aFile, aFooterScript );
339 QString HYDROData_Document::GetDocPyName() const
341 QString aDocName = PYTHON_DOC_NAME;
345 if ( DocumentId( this, aDocId ) )
346 aDocName += "_" + QString::number( aDocId );
352 QStringList HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
353 MapOfTreatedObjects& theTreatedObjects,
354 const bool theIsMultiFile ) const
356 QString aDocName = GetDocPyName();
358 // Append document in to the map of treated objects to prevent names overlaping
359 theTreatedObjects.insert( aDocName, this );
362 if ( !DocumentId( this, aDocId ) )
365 QStringList aResScript;
367 aResScript << QString( "from HYDROPy import *" );
368 aResScript << QString( "from PyQt5.QtCore import *" );
369 aResScript << QString( "from PyQt5.QtGui import *" );
371 if ( theIsMultiFile )
373 aResScript << QString( "import salome" );
374 aResScript << QString( "" );
375 aResScript << QString( "def RebuildData( theStudy ):" );
376 aResScript << QString( " %1 = HYDROData_Document.Document( theStudy._get_StudyId() )" ).arg( aDocName );
380 aResScript << QString( "" );
381 aResScript << QString( "%1 = HYDROData_Document.Document( theStudy._get_StudyId() )" ).arg( aDocName );
387 bool HYDROData_Document::dumpPartitionToPython( QFile& theFile,
388 const QString& thePyScriptPath,
389 const bool theIsMultiFile,
390 MapOfTreatedObjects& theTreatedObjects,
391 const ObjectKind& theObjectKind ) const
393 if ( !theFile.isOpen() )
396 QTextStream anOutStream( &theFile );
400 HYDROData_Iterator anIterator( this, theObjectKind );
401 for( ; anIterator.More(); anIterator.Next() )
403 Handle(HYDROData_Entity) anObject = anIterator.Current();
404 if ( anObject.IsNull() )
407 QString anObjName = anObject->GetName();
408 if ( theTreatedObjects.contains( anObjName ) )
411 theTreatedObjects.insert( anObjName, anObject );
413 QStringList anObjDump = anObject->DumpToPython( thePyScriptPath, theTreatedObjects );
415 if ( theIsMultiFile )
417 // For multifile dump we use the function, see the document dump header
418 QStringList::iterator anIt = anObjDump.begin();
419 for ( ; anIt != anObjDump.end(); ++anIt )
420 anIt->prepend( " " );
423 HYDROData_Tool::WriteStringsToFile( theFile, anObjDump );
429 bool takeLastDigits( QString& theStr, int& aRes )
434 for ( int i = theStr.length() - 1; i >= 0; --i )
436 const QChar& aChar = theStr.at( i );
437 if ( !aChar.isDigit() )
440 anStrNum.prepend( aChar );
443 if ( anStrNum.isEmpty() )
446 theStr.remove( theStr.length() - anStrNum.length(), anStrNum.length() );
447 aRes = anStrNum.toInt();
452 bool isObjectNameLessThan( const QString& theStr1, const QString& theStr2 )
454 QString aStr1 = theStr1, aStr2 = theStr2;
456 int aNum1 = -1, aNum2 = -1;
457 if ( takeLastDigits( aStr1, aNum1 ) && takeLastDigits( aStr2, aNum2 ) )
459 if ( aStr1 == aStr2 )
460 return aNum1 < aNum2;
463 return theStr1 < theStr2;
466 HYDROData_SequenceOfObjects HYDROData_Document::GetObjectsLayerOrder(
467 const Standard_Boolean theIsAll ) const
469 HYDROData_SequenceOfObjects anOrder;
471 MapOfOrdered aMapOfOrdered;
472 MapOfUnordered aMapOfUnordered;
474 HYDROData_Iterator anIter( this );
475 for ( ; anIter.More(); anIter.Next() )
477 Handle(HYDROData_Entity) anObject = anIter.Current();
478 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
481 Standard_Integer anObjZLevel = -1;
482 if ( anObject->GetZLevel( anObjZLevel ) )
484 aMapOfOrdered.insert( anObjZLevel, anObject );
488 QString anObjName = anObject->GetName();
489 if ( anObjName.isEmpty() )
492 aMapOfUnordered.insert( anObjName, anObject );
496 MapOfOrdered::const_iterator anOrderedMapIt = aMapOfOrdered.constBegin();
497 for ( ; anOrderedMapIt != aMapOfOrdered.constEnd(); anOrderedMapIt++ )
499 const Handle(HYDROData_Entity)& anObject = anOrderedMapIt.value();
500 anOrder.Prepend( anObject );
505 QStringList aSortedNames = aMapOfUnordered.keys();
506 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
508 for ( int i = 0; i < aSortedNames.length(); ++i )
510 QString anObjName = aSortedNames.value( i );
512 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
513 anOrder.Append( anObject );
520 void HYDROData_Document::SetObjectsLayerOrder( const HYDROData_SequenceOfObjects& theOrder )
522 // At first we remove previous model order
523 RemoveObjectsLayerOrder();
525 // Make new objects order
526 Standard_Integer aLevel = 0;
527 for ( int i = theOrder.Length(), n = 1; i >= n; --i )
529 const Handle(HYDROData_Entity)& anObject = theOrder.Value( i );
530 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
533 anObject->SetZLevel( aLevel++ );
537 void HYDROData_Document::Show( const Handle(HYDROData_Entity)& theObject )
539 HYDROData_SequenceOfObjects anOrder;
540 anOrder.Append( theObject );
544 void HYDROData_Document::Show( const HYDROData_SequenceOfObjects& theObjects )
546 MapOfUnordered aMapOfUnordered;
548 for ( int i = 1, n = theObjects.Length(); i <= n; ++i )
550 const Handle(HYDROData_Entity)& anObject = theObjects.Value( i );
551 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
554 Standard_Integer anObjZLevel = -1;
555 if ( anObject->GetZLevel( anObjZLevel ) )
557 continue; // Skip objects that already have the z-level
561 QString anObjName = anObject->GetName();
562 if ( anObjName.isEmpty() )
565 aMapOfUnordered.insert( anObjName, anObject );
569 if ( aMapOfUnordered.isEmpty() )
570 return; // Nothing to show
572 Standard_Integer aTopId = 0;
574 HYDROData_SequenceOfObjects aModelOrder = GetObjectsLayerOrder( Standard_False );
575 if ( !aModelOrder.IsEmpty() )
577 const Handle(HYDROData_Entity)& anObject = aModelOrder.First();
578 anObject->GetZLevel( aTopId );
582 aTopId += aMapOfUnordered.size() - 1;
584 QStringList aSortedNames = aMapOfUnordered.keys();
585 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
587 for ( int i = 0; i < aSortedNames.length(); ++i )
589 QString anObjName = aSortedNames.value( i );
591 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
592 anObject->SetZLevel( aTopId-- );
596 void HYDROData_Document::RemoveObjectsLayerOrder()
598 HYDROData_Iterator anIter( this );
599 for ( ; anIter.More(); anIter.Next() )
601 Handle(HYDROData_Entity) anObject = anIter.Current();
602 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
605 anObject->RemoveZLevel();
609 void HYDROData_Document::StartOperation()
614 void HYDROData_Document::CommitOperation(const TCollection_ExtendedString& theName)
616 if( !myDoc->CommitCommand() ) // it means that there were no modifications done
619 NewID(); // workaround: do something just to modify the document
620 myDoc->CommitCommand();
622 myTransactionsAfterSave++;
624 if( theName.Length() != 0 )
626 const TDF_DeltaList& aList = GetUndos();
627 if( !aList.IsEmpty() )
629 Handle(TDF_Delta) aDelta = aList.Last();
630 if( !aDelta.IsNull() )
631 aDelta->SetName( theName );
636 void HYDROData_Document::AbortOperation()
638 myDoc->AbortCommand();
641 bool HYDROData_Document::IsOperation()
643 return myDoc->HasOpenCommand() != 0;
646 bool HYDROData_Document::IsModified()
648 return myTransactionsAfterSave != 0;
651 bool HYDROData_Document::CanUndo()
653 return myDoc->GetAvailableUndos() > 0;
656 const TDF_DeltaList& HYDROData_Document::GetUndos()
658 return myDoc->GetUndos();
661 void HYDROData_Document::ClearUndos()
663 return myDoc->ClearUndos();
666 void HYDROData_Document::Undo()
669 myTransactionsAfterSave--;
672 bool HYDROData_Document::CanRedo()
674 return myDoc->GetAvailableRedos() > 0;
677 const TDF_DeltaList& HYDROData_Document::GetRedos()
679 return myDoc->GetRedos();
682 void HYDROData_Document::ClearRedos()
684 return myDoc->ClearRedos();
687 void HYDROData_Document::Redo()
690 myTransactionsAfterSave++;
693 Handle(HYDROData_Entity) HYDROData_Document::CreateObject( const ObjectKind theKind )
695 return HYDROData_Iterator::CreateObject( this, theKind );
698 Handle(HYDROData_Entity) HYDROData_Document::FindObjectByName(
699 const QString& theName,
700 const ObjectKind theObjectKind ) const
702 Handle(HYDROData_Entity) anObject;
703 if ( theName.isEmpty() )
706 QStringList aNamesList;
707 aNamesList << theName;
709 HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( aNamesList, theObjectKind );
710 if( aSeqOfObjs.IsEmpty() )
713 anObject = aSeqOfObjs.First();
717 HYDROData_SequenceOfObjects HYDROData_Document::FindObjectsByNames(
718 const QStringList& theNames,
719 const ObjectKind theObjectKind ) const
721 HYDROData_SequenceOfObjects aResSeq;
723 QStringList aNamesList = theNames;
725 HYDROData_Iterator anIter( this, theObjectKind );
726 for( ; anIter.More(); anIter.Next() )
728 Handle(HYDROData_Entity) anObject = anIter.Current();
729 if( anObject.IsNull() )
732 QString anObjName = anObject->GetName();
733 if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
736 aResSeq.Append( anObject );
738 aNamesList.removeAll( anObjName );
739 if ( aNamesList.isEmpty() )
746 HYDROData_Document::HYDROData_Document()
748 HYDROData_Application::GetApplication()->NewDocument("BinOcaf", myDoc);
749 myDoc->SetUndoLimit(UNDO_LIMIT);
750 NewID(); // needed to have at least one attribute in initial document to avoid errors
751 myTransactionsAfterSave = 0;
755 myInterpolatorsFactory = 0;
758 HYDROData_Document::HYDROData_Document(const Handle(TDocStd_Document)& theDoc)
761 myTransactionsAfterSave = 0;
765 myInterpolatorsFactory = 0;
768 HYDROData_Document::~HYDROData_Document()
772 int HYDROData_Document::NewID()
774 TDF_Label anIDLab = myDoc->Main().FindChild(TAG_PROPS).
775 FindChild(TAG_PROPS_NEW_ID);
776 Handle(TDataStd_Integer) anInt;
777 if (!anIDLab.FindAttribute(TDataStd_Integer::GetID(), anInt)) {
778 anInt = TDataStd_Integer::Set(anIDLab, 0);
780 // just increment value and return
781 anInt->Set(anInt->Get() + 1);
785 TDF_Label HYDROData_Document::LabelOfObjects()
787 return myDoc->Main().FindChild(TAG_OBJECTS);
790 TDF_Label HYDROData_Document::LabelOfLocalCS() const
792 return myDoc->Main().FindChild(TAG_LOCAL_CS);
795 void HYDROData_Document::GetLocalCS( double& theLX, double& theLY ) const
797 TDF_Label aLocalCSLab = LabelOfLocalCS();
799 Handle( TDataXtd_Position ) aLocalCS;
800 if( aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
802 gp_Pnt aLocalCS3d = aLocalCS->GetPosition();
803 theLX = aLocalCS3d.X();
804 theLY = aLocalCS3d.Y();
808 theLX = DEFAULT_LOCAL_CS.X();
809 theLY = DEFAULT_LOCAL_CS.Y();
813 void HYDROData_Document::SetLocalCS( double theLX, double theLY )
817 // update the local CS data in attribute
818 TDF_Label aLocalCSLab = LabelOfLocalCS();
819 Handle( TDataXtd_Position ) aLocalCS;
820 if( !aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
821 aLocalCS = TDataXtd_Position::Set( aLocalCSLab );
823 gp_Pnt aLocalCS3d( theLX, theLY, 0 );
824 aLocalCS->SetPosition( aLocalCS3d );
826 // calculate delta for coordinates
827 double aDX = myLX - theLX;
828 double aDY = myLY - theLY;
830 // update the local CS data in internal fields
834 //update all objects in the document
835 HYDROData_Iterator anIterator( this, KIND_UNKNOWN );
836 for( ; anIterator.More(); anIterator.Next() )
837 anIterator.Current()->UpdateLocalCS( aDX, aDY );
840 void HYDROData_Document::UpdateLCSFields() const
842 if( myLX >= 0 && myLY >= 0 )
846 GetLocalCS( aLX, aLY );
847 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
852 void HYDROData_Document::Transform( double& X, double& Y, bool IsToLocalCS ) const
867 void HYDROData_Document::Transform( gp_Pnt& thePnt, bool IsToLocalCS ) const
869 double X = thePnt.X();
870 double Y = thePnt.Y();
871 double Z = thePnt.Z();
872 Transform( X, Y, IsToLocalCS );
873 thePnt = gp_Pnt( X, Y, Z );
876 void HYDROData_Document::Transform( gp_XYZ& thePnt, bool IsToLocalCS ) const
878 double X = thePnt.X();
879 double Y = thePnt.Y();
880 double Z = thePnt.Z();
881 Transform( X, Y, IsToLocalCS );
882 thePnt = gp_XYZ( X, Y, Z );
885 void HYDROData_Document::Transform( double& X, double& Y, double& Z, bool IsToLocalCS ) const
887 Transform( X, Y, IsToLocalCS );
890 void HYDROData_Document::Transform( gp_XY& thePnt, bool IsToLocalCS ) const
892 double X = thePnt.X();
893 double Y = thePnt.Y();
894 Transform( X, Y, IsToLocalCS );
895 thePnt = gp_XY( X, Y );
898 HYDROData_InterpolatorsFactory* HYDROData_Document::GetInterpolatorsFactory()
900 if ( !myInterpolatorsFactory ) {
901 myInterpolatorsFactory = new HYDROData_InterpolatorsFactory();
904 return myInterpolatorsFactory;
907 HYDROData_IProfilesInterpolator* HYDROData_Document::GetInterpolator( const TCollection_AsciiString& theName ) const
909 HYDROData_IProfilesInterpolator* anInterpolator = NULL;
911 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
912 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
914 anInterpolator = aFactory->GetInterpolator( theName );
917 return anInterpolator;
920 NCollection_Sequence<TCollection_AsciiString> HYDROData_Document::GetInterpolatorNames() const
922 NCollection_Sequence<TCollection_AsciiString> aNames;
924 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
925 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
927 aNames = aFactory->GetInterpolatorNames();
933 QColor HYDROData_Document::GetAssociatedColor( const QString& theStricklerType, const Handle(HYDROData_StricklerTable)& theTable ) const
935 if( !theTable.IsNull() && theTable->HasType( theStricklerType ) )
936 return theTable->GetColor( theStricklerType );
938 HYDROData_Iterator anIt( this, KIND_STRICKLER_TABLE );
939 for( ; anIt.More(); anIt.Next() )
941 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
942 if( aTable->HasType( theStricklerType ) )
943 return aTable->GetColor( theStricklerType );
948 void HYDROData_Document::CollectQGISValues( const QString& theAttrName,
949 QStringList& theAttrValues,
950 QStringList& theStricklerTypes ) const
952 HYDROData_Iterator It( this, KIND_STRICKLER_TABLE );
953 for( ; It.More(); It.Next() )
955 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
956 if( !aTable.IsNull() && aTable->GetAttrName()==theAttrName )
958 theAttrValues.clear();
959 theStricklerTypes = aTable->GetTypes();
960 foreach( QString aType, theStricklerTypes )
962 QString anAttrValue = aTable->GetAttrValue( aType );
963 theAttrValues.append( anAttrValue );