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>
41 #include "HYDRO_trace.hxx"
43 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Document,Standard_Transient)
45 #define PYTHON_DOC_NAME "hydro_doc"
47 static const int UNDO_LIMIT = 10; // number of possible undo operations in the module
49 static const int TAG_PROPS = 1; // general properties tag
50 static const int TAG_PROPS_NEW_ID = 1; // general properties: tag for storage of the new object ID
51 static const int TAG_OBJECTS = 2; // tag of the objects sub-tree
52 static const int TAG_HISTORY = 3; // tag of the history sub-tree (Root for History)
53 static const int TAG_LOCAL_CS = 4; // tag of local coordinate system information
54 static const int TAG_DEF_STRICKLER_COEFF = 5; // tag of default strickler coefficient
55 static const int TAG_COUNT_QUADTREE = 6; // tag of number of quadtrees created so far
56 static const int TAG_COUNT_DELAUNAY = 7; // tag of number of Delaunay triangulations created so far
57 static const gp_Pnt2d DEFAULT_LOCAL_CS( 0, 0 );
61 typedef QMap<Standard_Integer, Handle(HYDROData_Entity)> MapOfOrdered;
62 typedef QMap<QString, Handle(HYDROData_Entity)> MapOfUnordered;
64 Handle(HYDROData_Document) HYDROData_Document::Document()
66 Handle(HYDROData_Document) aResult =
67 HYDROData_Application::GetApplication()->GetDocument();
68 if (aResult.IsNull()) {
69 DEBTRACE("new HYDROData_Document");
70 aResult = new HYDROData_Document();
71 HYDROData_Application::GetApplication()->AddDocument(aResult);
76 Handle(HYDROData_Document) HYDROData_Document::Document(
77 const TDF_Label& theObjectLabel )
79 Handle(HYDROData_Document) aResDoc;
80 if ( theObjectLabel.IsNull() )
83 Handle(TDocStd_Document) anObjDoc;
86 anObjDoc = TDocStd_Document::Get( theObjectLabel );
92 if ( anObjDoc.IsNull() )
95 HYDROData_Application* anApp = HYDROData_Application::GetApplication();
96 aResDoc = anApp->GetDocument();
101 bool HYDROData_Document::HasDocument()
103 Handle(HYDROData_Document) aResult =
104 HYDROData_Application::GetApplication()->GetDocument();
105 return !aResult.IsNull();
108 Data_DocError HYDROData_Document::Load(const char* theFileName)
111 Handle(TDocStd_Document) aResult;
112 TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
113 PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1;
116 aStatus = HYDROData_Application::GetApplication()->Open (aPath, aResult);
118 catch (Standard_Failure)
120 if (!aResult.IsNull()) {
121 aResult->SetUndoLimit(UNDO_LIMIT);
122 HYDROData_Application::GetApplication()->AddDocument(new HYDROData_Document(aResult));
125 Data_DocError anError;
128 anError = DocError_OK;
130 case PCDM_RS_NoDriver:
131 case PCDM_RS_UnknownFileDriver:
132 case PCDM_RS_NoSchema:
133 case PCDM_RS_DriverFailure:
134 case PCDM_RS_WrongResource:
135 anError = DocError_ResourcesProblem;
137 case PCDM_RS_OpenError:
138 case PCDM_RS_NoDocument:
139 case PCDM_RS_WrongStreamMode:
140 case PCDM_RS_PermissionDenied:
141 anError = DocError_CanNotOpen;
143 case PCDM_RS_NoVersion:
144 anError = DocError_InvalidVersion;
146 case PCDM_RS_ExtensionFailure:
147 case PCDM_RS_FormatFailure:
148 case PCDM_RS_TypeFailure:
149 case PCDM_RS_TypeNotFoundInSchema:
150 case PCDM_RS_UnrecognizedFileFormat:
151 anError = DocError_InvalidFormat;
153 case PCDM_RS_MakeFailure:
155 anError = DocError_UnknownProblem;
161 Data_DocError HYDROData_Document::Save(const char* theFileName)
164 TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
165 PCDM_StoreStatus aStatus;
167 aStatus = HYDROData_Application::GetApplication()->SaveAs (myDoc, aPath);
169 catch (Standard_Failure) {}
170 myTransactionsAfterSave = 0;
171 Standard::Purge(); // Release free memory
174 Data_DocError anError;
177 anError = DocError_OK;
179 case PCDM_SS_DriverFailure:
180 anError = DocError_ResourcesProblem;
182 case PCDM_SS_WriteFailure:
183 //case PCDM_SS_DiskWritingFailure:
184 //case PCDM_SS_UserRightsFailure:
185 anError = DocError_CanNotOpen;
188 anError = DocError_UnknownProblem;
194 void HYDROData_Document::Close()
198 HYDROData_Application::GetApplication()->RemoveDocument(this);
201 double HYDROData_Document::GetDefaultStricklerCoefficient() const
204 TDF_Label aLabel = myDoc->Main().FindChild(TAG_DEF_STRICKLER_COEFF, Standard_False);
205 if ( !aLabel.IsNull() )
207 Handle(TDataStd_Real) anAttr;
208 if ( aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
209 aRes = anAttr->Get();
215 void HYDROData_Document::SetDefaultStricklerCoefficient( double theCoeff ) const
217 TDF_Label aLabel = myDoc->Main().FindChild(TAG_DEF_STRICKLER_COEFF);
218 if ( !aLabel.IsNull() )
220 Handle(TDataStd_Real) anAttr;
221 if ( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
223 anAttr = new TDataStd_Real();
224 aLabel.AddAttribute(anAttr);
225 anAttr->SetID(TDataStd_Real::GetID());
227 anAttr->Set( theCoeff );
231 int HYDROData_Document::GetCountQuadtree() const
234 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_QUADTREE, Standard_False);
235 if ( !aLabel.IsNull() )
237 Handle(TDataStd_Integer) anAttr;
238 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
239 nbQuad = anAttr->Get();
244 void HYDROData_Document::SetCountQuadtree( int nbQuad) const
246 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_QUADTREE);
247 if ( !aLabel.IsNull() )
249 Handle(TDataStd_Integer) anAttr;
250 if ( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
252 anAttr = new TDataStd_Integer();
253 aLabel.AddAttribute(anAttr);
254 anAttr->SetID(TDataStd_Integer::GetID());
256 anAttr->Set( nbQuad );
260 int HYDROData_Document::GetCountDelaunay() const
263 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_DELAUNAY, Standard_False);
264 if ( !aLabel.IsNull() )
266 Handle(TDataStd_Integer) anAttr;
267 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
268 nbDelaunay = anAttr->Get();
273 void HYDROData_Document::SetCountDelaunay( int nbDelaunay) const
275 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_DELAUNAY);
276 if ( !aLabel.IsNull() )
278 Handle(TDataStd_Integer) anAttr;
279 if ( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
281 anAttr = new TDataStd_Integer();
282 aLabel.AddAttribute(anAttr);
283 anAttr->SetID(TDataStd_Integer::GetID());
285 anAttr->Set( nbDelaunay );
289 bool HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
290 const bool theIsMultiFile ) const
292 DEBTRACE("DumpToPython");
293 // Try to open the file
294 QFile aFile( thePyScriptPath );
295 if ( !aFile.open( QIODevice::WriteOnly | QFile::Text ) )
298 MapOfTreatedObjects aTreatedObjects;
300 // Dump header for python script
301 QStringList aHeaderDump = DumpToPython( thePyScriptPath, aTreatedObjects, theIsMultiFile );
302 if ( aHeaderDump.isEmpty() )
305 HYDROData_Tool::WriteStringsToFile( aFile, aHeaderDump );
309 // Dump the local CS data to Python
311 QString aLCS = QString( "%1.SetLocalCS( %2, %3 )" ).arg( GetDocPyName() ).arg( myLX, 0, 'f', 3 ).arg( myLY, 0, 'f', 3 );
314 HYDROData_Tool::WriteStringsToFile( aFile, QStringList() << aLCS );
316 // Dump all model objects to Python script
317 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMAGE );
318 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STRICKLER_TABLE );
319 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINEXY );
320 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_BATHYMETRY );
321 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_PROFILE );
322 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINE );
323 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMMERSIBLE_ZONE );
324 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STREAM );
325 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CHANNEL );
326 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_DIGUE );
327 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_OBSTACLE );
328 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_LAND_COVER_MAP );
329 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_BC_POLYGON );
330 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CALCULATION );
332 // Dump code to close python fuction
333 if ( aRes && theIsMultiFile )
335 QStringList aFooterScript;
336 aFooterScript << QString( "" );
337 aFooterScript << QString( " pass" );
338 HYDROData_Tool::WriteStringsToFile( aFile, aFooterScript );
344 QString HYDROData_Document::GetDocPyName() const
346 QString aDocName = PYTHON_DOC_NAME;
351 QStringList HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
352 MapOfTreatedObjects& theTreatedObjects,
353 const bool theIsMultiFile ) const
355 DEBTRACE("DumpToPython");
356 QString aDocName = GetDocPyName();
358 // Append document in to the map of treated objects to prevent names overlaping
359 theTreatedObjects.insert( aDocName, this );
361 QStringList aResScript;
363 aResScript << QString( "from HYDROPy import *" );
364 aResScript << QString( "from PyQt5.QtCore import *" );
365 aResScript << QString( "from PyQt5.QtGui import *" );
367 if ( theIsMultiFile )
369 aResScript << QString( "import salome" );
370 aResScript << QString( "" );
371 aResScript << QString( "def RebuildData():" );
372 aResScript << QString( " %1 = HYDROData_Document.Document()" ).arg( aDocName );
376 aResScript << QString( "" );
377 aResScript << QString( "%1 = HYDROData_Document.Document()" ).arg( aDocName );
383 bool HYDROData_Document::dumpPartitionToPython( QFile& theFile,
384 const QString& thePyScriptPath,
385 const bool theIsMultiFile,
386 MapOfTreatedObjects& theTreatedObjects,
387 const ObjectKind& theObjectKind ) const
389 DEBTRACE("dumpPartitionToPython");
390 if ( !theFile.isOpen() )
393 QTextStream anOutStream( &theFile );
397 HYDROData_Iterator anIterator( this, theObjectKind );
398 for( ; anIterator.More(); anIterator.Next() )
400 Handle(HYDROData_Entity) anObject = anIterator.Current();
401 if ( anObject.IsNull() )
404 QString anObjName = anObject->GetName();
405 if ( theTreatedObjects.contains( anObjName ) )
408 theTreatedObjects.insert( anObjName, anObject );
410 QStringList anObjDump = anObject->DumpToPython( thePyScriptPath, theTreatedObjects );
412 if ( theIsMultiFile )
414 // For multifile dump we use the function, see the document dump header
415 QStringList::iterator anIt = anObjDump.begin();
416 for ( ; anIt != anObjDump.end(); ++anIt )
417 anIt->prepend( " " );
420 HYDROData_Tool::WriteStringsToFile( theFile, anObjDump );
426 bool takeLastDigits( QString& theStr, int& aRes )
431 for ( int i = theStr.length() - 1; i >= 0; --i )
433 const QChar& aChar = theStr.at( i );
434 if ( !aChar.isDigit() )
437 anStrNum.prepend( aChar );
440 if ( anStrNum.isEmpty() )
443 theStr.remove( theStr.length() - anStrNum.length(), anStrNum.length() );
444 aRes = anStrNum.toInt();
449 bool isObjectNameLessThan( const QString& theStr1, const QString& theStr2 )
451 QString aStr1 = theStr1, aStr2 = theStr2;
453 int aNum1 = -1, aNum2 = -1;
454 if ( takeLastDigits( aStr1, aNum1 ) && takeLastDigits( aStr2, aNum2 ) )
456 if ( aStr1 == aStr2 )
457 return aNum1 < aNum2;
460 return theStr1 < theStr2;
463 HYDROData_SequenceOfObjects HYDROData_Document::GetObjectsLayerOrder(
464 const Standard_Boolean theIsAll ) const
466 HYDROData_SequenceOfObjects anOrder;
468 MapOfOrdered aMapOfOrdered;
469 MapOfUnordered aMapOfUnordered;
471 HYDROData_Iterator anIter( this );
472 for ( ; anIter.More(); anIter.Next() )
474 Handle(HYDROData_Entity) anObject = anIter.Current();
475 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
478 Standard_Integer anObjZLevel = -1;
479 if ( anObject->GetZLevel( anObjZLevel ) )
481 aMapOfOrdered.insert( anObjZLevel, anObject );
485 QString anObjName = anObject->GetName();
486 if ( anObjName.isEmpty() )
489 aMapOfUnordered.insert( anObjName, anObject );
493 MapOfOrdered::const_iterator anOrderedMapIt = aMapOfOrdered.constBegin();
494 for ( ; anOrderedMapIt != aMapOfOrdered.constEnd(); anOrderedMapIt++ )
496 const Handle(HYDROData_Entity)& anObject = anOrderedMapIt.value();
497 anOrder.Prepend( anObject );
502 QStringList aSortedNames = aMapOfUnordered.keys();
503 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
505 for ( int i = 0; i < aSortedNames.length(); ++i )
507 QString anObjName = aSortedNames.value( i );
509 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
510 anOrder.Append( anObject );
517 void HYDROData_Document::SetObjectsLayerOrder( const HYDROData_SequenceOfObjects& theOrder )
519 // At first we remove previous model order
520 RemoveObjectsLayerOrder();
522 // Make new objects order
523 Standard_Integer aLevel = 0;
524 for ( int i = theOrder.Length(), n = 1; i >= n; --i )
526 const Handle(HYDROData_Entity)& anObject = theOrder.Value( i );
527 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
530 anObject->SetZLevel( aLevel++ );
534 void HYDROData_Document::Show( const Handle(HYDROData_Entity)& theObject )
536 HYDROData_SequenceOfObjects anOrder;
537 anOrder.Append( theObject );
541 void HYDROData_Document::Show( const HYDROData_SequenceOfObjects& theObjects )
543 MapOfUnordered aMapOfUnordered;
545 for ( int i = 1, n = theObjects.Length(); i <= n; ++i )
547 const Handle(HYDROData_Entity)& anObject = theObjects.Value( i );
548 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
551 Standard_Integer anObjZLevel = -1;
552 if ( anObject->GetZLevel( anObjZLevel ) )
554 continue; // Skip objects that already have the z-level
558 QString anObjName = anObject->GetName();
559 if ( anObjName.isEmpty() )
562 aMapOfUnordered.insert( anObjName, anObject );
566 if ( aMapOfUnordered.isEmpty() )
567 return; // Nothing to show
569 Standard_Integer aTopId = 0;
571 HYDROData_SequenceOfObjects aModelOrder = GetObjectsLayerOrder( Standard_False );
572 if ( !aModelOrder.IsEmpty() )
574 const Handle(HYDROData_Entity)& anObject = aModelOrder.First();
575 anObject->GetZLevel( aTopId );
579 aTopId += aMapOfUnordered.size() - 1;
581 QStringList aSortedNames = aMapOfUnordered.keys();
582 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
584 for ( int i = 0; i < aSortedNames.length(); ++i )
586 QString anObjName = aSortedNames.value( i );
588 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
589 anObject->SetZLevel( aTopId-- );
593 void HYDROData_Document::RemoveObjectsLayerOrder()
595 HYDROData_Iterator anIter( this );
596 for ( ; anIter.More(); anIter.Next() )
598 Handle(HYDROData_Entity) anObject = anIter.Current();
599 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
602 anObject->RemoveZLevel();
606 void HYDROData_Document::StartOperation()
611 void HYDROData_Document::CommitOperation(const TCollection_ExtendedString& theName)
613 if( !myDoc->CommitCommand() ) // it means that there were no modifications done
616 NewID(); // workaround: do something just to modify the document
617 myDoc->CommitCommand();
619 myTransactionsAfterSave++;
621 if( theName.Length() != 0 )
623 const TDF_DeltaList& aList = GetUndos();
624 if( !aList.IsEmpty() )
626 Handle(TDF_Delta) aDelta = aList.Last();
627 if( !aDelta.IsNull() )
628 aDelta->SetName( theName );
633 void HYDROData_Document::AbortOperation()
635 myDoc->AbortCommand();
638 bool HYDROData_Document::IsOperation()
640 return myDoc->HasOpenCommand() != 0;
643 bool HYDROData_Document::IsModified()
645 return myTransactionsAfterSave != 0;
648 bool HYDROData_Document::CanUndo()
650 return myDoc->GetAvailableUndos() > 0;
653 const TDF_DeltaList& HYDROData_Document::GetUndos()
655 return myDoc->GetUndos();
658 void HYDROData_Document::ClearUndos()
660 return myDoc->ClearUndos();
663 void HYDROData_Document::Undo()
666 myTransactionsAfterSave--;
669 bool HYDROData_Document::CanRedo()
671 return myDoc->GetAvailableRedos() > 0;
674 const TDF_DeltaList& HYDROData_Document::GetRedos()
676 return myDoc->GetRedos();
679 void HYDROData_Document::ClearRedos()
681 return myDoc->ClearRedos();
684 void HYDROData_Document::Redo()
687 myTransactionsAfterSave++;
690 Handle(HYDROData_Entity) HYDROData_Document::CreateObject( const ObjectKind theKind )
692 return HYDROData_Iterator::CreateObject( this, theKind );
695 Handle(HYDROData_Entity) HYDROData_Document::FindObjectByName(
696 const QString& theName,
697 const ObjectKind theObjectKind ) const
699 Handle(HYDROData_Entity) anObject;
700 if ( theName.isEmpty() )
703 QStringList aNamesList;
704 aNamesList << theName;
706 HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( aNamesList, theObjectKind );
707 if( aSeqOfObjs.IsEmpty() )
710 anObject = aSeqOfObjs.First();
714 HYDROData_SequenceOfObjects HYDROData_Document::FindObjectsByNames(
715 const QStringList& theNames,
716 const ObjectKind theObjectKind ) const
718 HYDROData_SequenceOfObjects aResSeq;
720 QStringList aNamesList = theNames;
722 HYDROData_Iterator anIter( this, theObjectKind );
723 for( ; anIter.More(); anIter.Next() )
725 Handle(HYDROData_Entity) anObject = anIter.Current();
726 if( anObject.IsNull() )
729 QString anObjName = anObject->GetName();
730 if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
733 aResSeq.Append( anObject );
735 aNamesList.removeAll( anObjName );
736 if ( aNamesList.isEmpty() )
743 HYDROData_SequenceOfObjects HYDROData_Document::CollectAllObjects( const ObjectKind theObjectKind ) const
745 HYDROData_SequenceOfObjects aResSeq;
746 HYDROData_Iterator anIter( this, theObjectKind );
747 for( ; anIter.More(); anIter.Next() )
749 Handle(HYDROData_Entity) anObject = anIter.Current();
750 if( anObject.IsNull() )
752 aResSeq.Append( anObject );
757 HYDROData_Document::HYDROData_Document()
759 DEBTRACE("HYDROData_Document");
760 HYDROData_Application::GetApplication()->NewDocument("BinOcaf", myDoc);
761 myDoc->SetUndoLimit(UNDO_LIMIT);
762 NewID(); // needed to have at least one attribute in initial document to avoid errors
763 myTransactionsAfterSave = 0;
767 myInterpolatorsFactory = 0;
770 HYDROData_Document::HYDROData_Document(const Handle(TDocStd_Document)& theDoc)
772 DEBTRACE("HYDROData_Document");
774 myTransactionsAfterSave = 0;
778 myInterpolatorsFactory = 0;
781 HYDROData_Document::~HYDROData_Document()
783 DEBTRACE("~HYDROData_Document");
786 int HYDROData_Document::NewID()
788 TDF_Label anIDLab = myDoc->Main().FindChild(TAG_PROPS).
789 FindChild(TAG_PROPS_NEW_ID);
790 Handle(TDataStd_Integer) anInt;
791 if (!anIDLab.FindAttribute(TDataStd_Integer::GetID(), anInt)) {
792 anInt = TDataStd_Integer::Set(anIDLab, 0);
793 anInt->SetID(TDataStd_Integer::GetID());
795 // just increment value and return
796 anInt->Set(anInt->Get() + 1);
800 TDF_Label HYDROData_Document::LabelOfObjects()
802 return myDoc->Main().FindChild(TAG_OBJECTS);
805 TDF_Label HYDROData_Document::LabelOfLocalCS() const
807 return myDoc->Main().FindChild(TAG_LOCAL_CS);
810 void HYDROData_Document::GetLocalCS( double& theLX, double& theLY ) const
812 TDF_Label aLocalCSLab = LabelOfLocalCS();
814 Handle( TDataXtd_Position ) aLocalCS;
815 if( aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
817 gp_Pnt aLocalCS3d = aLocalCS->GetPosition();
818 theLX = aLocalCS3d.X();
819 theLY = aLocalCS3d.Y();
823 theLX = DEFAULT_LOCAL_CS.X();
824 theLY = DEFAULT_LOCAL_CS.Y();
828 void HYDROData_Document::SetLocalCS( double theLX, double theLY )
832 // update the local CS data in attribute
833 TDF_Label aLocalCSLab = LabelOfLocalCS();
834 Handle( TDataXtd_Position ) aLocalCS;
835 if( !aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
837 aLocalCS = TDataXtd_Position::Set( aLocalCSLab );
838 aLocalCS->SetID(TDataXtd_Position::GetID());
841 gp_Pnt aLocalCS3d( theLX, theLY, 0 );
842 aLocalCS->SetPosition( aLocalCS3d );
844 // calculate delta for coordinates
845 double aDX = myLX - theLX;
846 double aDY = myLY - theLY;
848 // update the local CS data in internal fields
852 //update all objects in the document
853 HYDROData_Iterator anIterator( this, KIND_UNKNOWN );
854 for( ; anIterator.More(); anIterator.Next() )
855 anIterator.Current()->UpdateLocalCS( aDX, aDY );
858 void HYDROData_Document::UpdateLCSFields() const
860 if( myLX >= 0 && myLY >= 0 )
864 GetLocalCS( aLX, aLY );
865 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
870 void HYDROData_Document::Transform( double& X, double& Y, bool IsToLocalCS ) const
885 void HYDROData_Document::Transform( gp_Pnt& thePnt, bool IsToLocalCS ) const
887 double X = thePnt.X();
888 double Y = thePnt.Y();
889 double Z = thePnt.Z();
890 Transform( X, Y, IsToLocalCS );
891 thePnt = gp_Pnt( X, Y, Z );
894 void HYDROData_Document::Transform( gp_XYZ& thePnt, bool IsToLocalCS ) const
896 double X = thePnt.X();
897 double Y = thePnt.Y();
898 double Z = thePnt.Z();
899 Transform( X, Y, IsToLocalCS );
900 thePnt = gp_XYZ( X, Y, Z );
903 void HYDROData_Document::Transform( double& X, double& Y, double& Z, bool IsToLocalCS ) const
905 Transform( X, Y, IsToLocalCS );
908 void HYDROData_Document::Transform( gp_XY& thePnt, bool IsToLocalCS ) const
910 double X = thePnt.X();
911 double Y = thePnt.Y();
912 Transform( X, Y, IsToLocalCS );
913 thePnt = gp_XY( X, Y );
916 HYDROData_InterpolatorsFactory* HYDROData_Document::GetInterpolatorsFactory()
918 if ( !myInterpolatorsFactory ) {
919 myInterpolatorsFactory = new HYDROData_InterpolatorsFactory();
922 return myInterpolatorsFactory;
925 HYDROData_IProfilesInterpolator* HYDROData_Document::GetInterpolator( const TCollection_AsciiString& theName ) const
927 HYDROData_IProfilesInterpolator* anInterpolator = NULL;
929 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
930 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
932 anInterpolator = aFactory->GetInterpolator( theName );
935 return anInterpolator;
938 NCollection_Sequence<TCollection_AsciiString> HYDROData_Document::GetInterpolatorNames() const
940 NCollection_Sequence<TCollection_AsciiString> aNames;
942 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
943 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
945 aNames = aFactory->GetInterpolatorNames();
951 QColor HYDROData_Document::GetAssociatedColor( const QString& theStricklerType, const Handle(HYDROData_StricklerTable)& theTable ) const
953 if( !theTable.IsNull() && theTable->HasType( theStricklerType ) )
954 return theTable->GetColor( theStricklerType );
956 HYDROData_Iterator anIt( this, KIND_STRICKLER_TABLE );
957 for( ; anIt.More(); anIt.Next() )
959 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
960 if( aTable->HasType( theStricklerType ) )
961 return aTable->GetColor( theStricklerType );
966 void HYDROData_Document::CollectQGISValues( const QString& theAttrName,
967 QStringList& theAttrValues,
968 QStringList& theStricklerTypes ) const
970 HYDROData_Iterator It( this, KIND_STRICKLER_TABLE );
971 for( ; It.More(); It.Next() )
973 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
974 if( !aTable.IsNull() && aTable->GetAttrName()==theAttrName )
976 theAttrValues.clear();
977 theStricklerTypes = aTable->GetTypes();
978 foreach( QString aType, theStricklerTypes )
980 QString anAttrValue = aTable->GetAttrValue( aType );
981 theAttrValues.append( anAttrValue );